From a02efd1fc7eeffcf3ab2fc9805da03c98c5cd051 Mon Sep 17 00:00:00 2001 From: Vitaly Stakhovsky Date: Mon, 30 Jul 2018 15:04:36 +0200 Subject: [PATCH] Implement wxFontDialog::SetTitle() in wxMSW Base class SetTitle() implementation didnd't work for this class as it used the (invalid) HWND of not yet existing dialog, so add a hook procedure for the common font dialog, similar to the existing one for wxColourDialog, which allows us to set the dialog title when the dialog is really created. Closes https://github.com/wxWidgets/wxWidgets/pull/865 Closes #18177. --- docs/changes.txt | 1 + include/wx/msw/fontdlg.h | 4 ++++ src/msw/fontdlg.cpp | 44 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+) diff --git a/docs/changes.txt b/docs/changes.txt index 74ef379423..53be80064f 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -124,6 +124,7 @@ wxMSW: - Fix positioning windows at positions >= SHORT_MAX (Cătălin Răceanu). - Honour alignment flags for multiline buttons using custom colours too. - Support MSVC auto-linking when using monolithic build too (PB). +- Implement wxFontDialog::SetTitle() (Vitaly Stakhovsky). - Fix build in ANSI (non-Unicode) mode. wxOSX: diff --git a/include/wx/msw/fontdlg.h b/include/wx/msw/fontdlg.h index 24b608e716..38d0d463bc 100644 --- a/include/wx/msw/fontdlg.h +++ b/include/wx/msw/fontdlg.h @@ -25,8 +25,12 @@ public: : wxFontDialogBase(parent, data) { Create(parent, data); } virtual int ShowModal() wxOVERRIDE; + virtual void SetTitle(const wxString& title) wxOVERRIDE; + virtual wxString GetTitle() const wxOVERRIDE; protected: + wxString m_title; + wxDECLARE_DYNAMIC_CLASS_NO_COPY(wxFontDialog); }; diff --git a/src/msw/fontdlg.cpp b/src/msw/fontdlg.cpp index 749272eea6..2f7e6bb8d5 100644 --- a/src/msw/fontdlg.cpp +++ b/src/msw/fontdlg.cpp @@ -49,10 +49,45 @@ wxIMPLEMENT_DYNAMIC_CLASS(wxFontDialog, wxDialog); // implementation // ============================================================================ +// ---------------------------------------------------------------------------- +// font dialog hook proc used for setting the dialog title if necessary +// ---------------------------------------------------------------------------- + +static +UINT_PTR CALLBACK +wxFontDialogHookProc(HWND hwnd, + UINT uiMsg, + WPARAM WXUNUSED(wParam), + LPARAM lParam) +{ + if ( uiMsg == WM_INITDIALOG ) + { + CHOOSEFONT *pCH = (CHOOSEFONT *)lParam; + wxFontDialog * const + dialog = reinterpret_cast(pCH->lCustData); + + ::SetWindowText(hwnd, dialog->GetTitle().t_str()); + } + + return 0; +} + // ---------------------------------------------------------------------------- // wxFontDialog // ---------------------------------------------------------------------------- +void wxFontDialog::SetTitle(const wxString& title) +{ + // Just store the title here, we can't set it right now because the dialog + // doesn't exist yet -- it will be created only when ShowModal() is called. + m_title = title; +} + +wxString wxFontDialog::GetTitle() const +{ + return m_title; +} + int wxFontDialog::ShowModal() { WX_HOOK_MODAL_DIALOG(); @@ -71,6 +106,15 @@ int wxFontDialog::ShowModal() chooseFontStruct.hwndOwner = hWndParent; chooseFontStruct.lpLogFont = &logFont; + // Currently we only use the hook to set the title, so only set it up if + // we really need to do this. + if ( !m_title.empty() ) + { + flags |= CF_ENABLEHOOK; + chooseFontStruct.lCustData = (LPARAM)this; + chooseFontStruct.lpfnHook = wxFontDialogHookProc; + } + if ( m_fontData.m_initialFont.IsOk() ) { flags |= CF_INITTOLOGFONTSTRUCT;