Print support for wxTextCtrl (Issue #25158)

40 views
Skip to first unread message

Blake-Madden

unread,
Feb 12, 2025, 6:45:05 AM2/12/25
to wx-...@googlegroups.com, Subscribed

I have some printing code for wxTextCtrl under MSW, macOS, and GTK. It has the following features:

  • It accepts a wxPrintData* object to use an application's printer settings (i.e., paper size, orientation).
  • Supports left, center, and top headers and footers.
  • Watermark support under MSW and GTK. I'm still trying to see if I can add that to macOS.

Would there be interest in a PR for this? If so, I was going to redesign my API for it. I was thinking of the following:

  • Having a Print function that takes a single argument with all the options.
  • Having a similar PrintPreview function, but only under MSW. macOS's and GTK's print dialogs have built-in previews already, but MSW doesn't.
  • The argument to these functions would be a builder object named wxPrintInfo with the following fields:
    • wxPrintInfo::PrintData(wxPrintData*) - this would be an in & out parameter for print preview, where the user may change the settings.
    • wxPrintInfo::wxPrintInfo(wxPrintData*) - CTOR that can also accept a wxPrintData.
    • wxPrintInfo::LeftHeader(const wxString&)
    • wxPrintInfo::CenterHeader(const wxString&)
    • wxPrintInfo::RightHeader(const wxString&)
    • wxPrintInfo::LeftFooter(const wxString&)
    • wxPrintInfo::CenterFooter(const wxString&)
    • wxPrintInfo::RightFooter(const wxString&)
    • wxPrintInfo::WaterMark(const wxString&) (if I can get this to work on macOS. This can always be added later.)

Thoughts?


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/issues/25158@github.com>

VZ

unread,
Feb 12, 2025, 9:53:48 AM2/12/25
to wx-...@googlegroups.com, Subscribed

I'm not sure how common is it going to be to just print the wxTextCtrl contents. To me it would be more useful to allow rendering it to any wxDC (including wxPrinterDC, of course), but I guess this is going to be more difficult? FWIW, under MSW it could be done using WM_PRINTCLIENT, I think.


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/issues/25158/2653949167@github.com>

Blake-Madden

unread,
Feb 12, 2025, 2:27:04 PM2/12/25
to wx-...@googlegroups.com, Subscribed

For MSW and am rendering to a wxDC, but under macOS you have to use a NSPrintOperation to print. With NSPrintOperation, it handles all the rendering and pagination for you; it's a surprisingly simple process. But because of that, I'm limited to using a high-level API.

Anyway, IMHO it is a really nice feature to have; I can imagine other programs benefiting from built-in text control printing. And having to write this code for every platform is...a production to say the least.

Ultimately, I could see a similar print API added to wxListCtrl, but I am getting way ahead of myself there.


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/issues/25158/2654652113@github.com>

VZ

unread,
Feb 13, 2025, 9:57:54 AM2/13/25
to wx-...@googlegroups.com, Subscribed

AFAICS NSPrintOperation is supposed to work with any NSView, so it's similar to WM_PRINTCLIENT from this point of view and it could make sense to provide this at wxWindow or wxControl level.

I don't think GTK provides anything similar, unfortunately, please let me know if I'm missing something.


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/issues/25158/2656862698@github.com>

vadzvadz left a comment (wxWidgets/wxWidgets#25158)

AFAICS NSPrintOperation is supposed to work with any NSView, so it's similar to WM_PRINTCLIENT from this point of view and it could make sense to provide this at wxWindow or wxControl level.

I don't think GTK provides anything similar, unfortunately, please let me know if I'm missing something.


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/issues/25158/2656862698@github.com>

Blake-Madden

unread,
Feb 17, 2025, 12:24:25 PM2/17/25
to wx-...@googlegroups.com, Subscribed

For MSW, I use the EM_FORMATRANGE message, which formats and paginates RTF content from the text control. So, a DC is involved, but the process is still very specific to the text control (and its RTF content in particular).

For GTK, I use the gtk_print_operation* API. The _GtkPrintData object in there involves taking Pango markup from the text control. So GTK requires text control specific logic too, at least to have most rich output.


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/issues/25158/2663720930@github.com>

Blake-MaddenBlake-Madden left a comment (wxWidgets/wxWidgets#25158)

For MSW, I use the EM_FORMATRANGE message, which formats and paginates RTF content from the text control. So, a DC is involved, but the process is still very specific to the text control (and its RTF content in particular).

For GTK, I use the gtk_print_operation* API. The _GtkPrintData object in there involves taking Pango markup from the text control. So GTK requires text control specific logic too, at least to have most rich output.


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/issues/25158/2663720930@github.com>

VZ

unread,
Feb 17, 2025, 5:41:22 PM2/17/25
to wx-...@googlegroups.com, Subscribed

OK, so this will indeed have to be wxTextCtrl-specific. I guess we should have some wxTextEasyPrinting similar to the existing wxHtmlEasyPrinting?


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/issues/25158/2664179920@github.com>

vadzvadz left a comment (wxWidgets/wxWidgets#25158)

OK, so this will indeed have to be wxTextCtrl-specific. I guess we should have some wxTextEasyPrinting similar to the existing wxHtmlEasyPrinting?


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/issues/25158/2664179920@github.com>

Blake-Madden

unread,
Feb 17, 2025, 6:35:31 PM2/17/25
to wx-...@googlegroups.com, Subscribed

I was originally thinking that too, but then noticed that wxWebView has a Print() function and wasn't sure if I should go with a print API connected to the text control.

With the wxTextEasyPrinting approach, it could have similar options like wxHtmlEasyPrinting and have print functions that take a reference to a text control. I'll go with the wxTextEasyPrinting approach if you prefer that.


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/issues/25158/2664230298@github.com>

Blake-MaddenBlake-Madden left a comment (wxWidgets/wxWidgets#25158)

I was originally thinking that too, but then noticed that wxWebView has a Print() function and wasn't sure if I should go with a print API connected to the text control.

With the wxTextEasyPrinting approach, it could have similar options like wxHtmlEasyPrinting and have print functions that take a reference to a text control. I'll go with the wxTextEasyPrinting approach if you prefer that.


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/issues/25158/2664230298@github.com>

VZ

unread,
Feb 17, 2025, 6:52:48 PM2/17/25
to wx-...@googlegroups.com, Subscribed

I don't have strong opinions about it, but mimicking wxHtmlEasyPrinting seems to make sense. And I'd definitely avoid having Print() as a member function, this just doesn't seem right.


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/issues/25158/2664245139@github.com>

vadzvadz left a comment (wxWidgets/wxWidgets#25158)

I don't have strong opinions about it, but mimicking wxHtmlEasyPrinting seems to make sense. And I'd definitely avoid having Print() as a member function, this just doesn't seem right.


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/issues/25158/2664245139@github.com>

Blake-Madden

unread,
Jul 12, 2026, 4:39:43 PM (2 days ago) Jul 12
to wx-...@googlegroups.com, Subscribed

Closed #25158 as completed.


Reply to this email directly, view it on GitHub, or unsubscribe.

Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS and Android. Download it today!
You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/issue/25158/issue_event/27880915178@github.com>

Reply all
Reply to author
Forward
0 new messages