From 7230acd110a465f9718526d2b8f134d04eb6d7a3 Mon Sep 17 00:00:00 2001 From: Ian McInerney Date: Fri, 17 Jan 2020 00:59:16 +0000 Subject: [PATCH] Fix setting the title for the wxDirDialog on OSX OSX 10.11+ doesn't actually display the title, so update documentation to reference SetMessage instead. For pre-10.11 override the SetTitle method to set the title of the NSOpenPanel instead of the window. Also change so the directory is not updated unless it is provided. Closes #15143. --- include/wx/osx/dirdlg.h | 5 +++++ interface/wx/dirdlg.h | 5 +++++ src/osx/cocoa/dirdlg.mm | 12 ++++++++++++ 3 files changed, 22 insertions(+) diff --git a/include/wx/osx/dirdlg.h b/include/wx/osx/dirdlg.h index cf22b6ad4d..ea95b70c5a 100644 --- a/include/wx/osx/dirdlg.h +++ b/include/wx/osx/dirdlg.h @@ -47,6 +47,10 @@ public: virtual int ShowModal() wxOVERRIDE; + // MacOS 10.11 has removed the titlebar from the dialog, so this is provided + // only for compatibility with older versions + virtual void SetTitle(const wxString& title) wxOVERRIDE; + virtual wxString GetPath() const wxOVERRIDE; virtual void GetPaths(wxArrayString& paths) const wxOVERRIDE; @@ -69,6 +73,7 @@ private: void Init(); wxArrayString m_paths; + wxString m_title; wxDECLARE_DYNAMIC_CLASS(wxDirDialog); }; diff --git a/interface/wx/dirdlg.h b/interface/wx/dirdlg.h index d4f6c6eaa6..c8f5b29728 100644 --- a/interface/wx/dirdlg.h +++ b/interface/wx/dirdlg.h @@ -71,6 +71,11 @@ const char wxDirDialogNameStr[] = "wxDirCtrl"; @endcode instead of just using @c wxDD_DIR_MUST_EXIST style alone. + @remarks MacOS 10.11+ does not display a title bar on the dialog. Use SetMessage() + to change the string displayed to the user at the top of the dialog after creation. + The SetTitle() method is provided for compatibility with pre-10.11 MacOS versions + that do still support displaying the title bar. + @library{wxcore} @category{cmndlg} diff --git a/src/osx/cocoa/dirdlg.mm b/src/osx/cocoa/dirdlg.mm index 93bb4ad6bb..9c21b7ea95 100644 --- a/src/osx/cocoa/dirdlg.mm +++ b/src/osx/cocoa/dirdlg.mm @@ -73,6 +73,12 @@ WX_NSOpenPanel wxDirDialog::OSXCreatePanel() const wxCFStringRef cf( m_message ); [oPanel setMessage:cf.AsNSString()]; + if ( !m_title.empty() ) + { + wxCFStringRef cfTitle(m_title); + [oPanel setTitle:cfTitle.AsNSString()]; + } + if ( !HasFlag(wxDD_DIR_MUST_EXIST) ) [oPanel setCanCreateDirectories:YES]; @@ -159,6 +165,12 @@ void wxDirDialog::ModalFinishedCallback(void* panel, int returnCode) SendWindowModalDialogEvent ( wxEVT_WINDOW_MODAL_DIALOG_CLOSED ); } +void wxDirDialog::SetTitle(const wxString &title) +{ + m_title = title; + wxDialog::SetTitle(title); +} + wxString wxDirDialog::GetPath() const { return m_paths.Last();