From 7c81707a7ea730f1d2c97a12b3768c8ab02d71b1 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 12 Apr 2014 22:56:21 +0000 Subject: [PATCH 01/17] Add error handling to wxSound under wxOSX. Don't assume that we can open any file as a sound, check for the return value from AudioServicesCreateSystemSoundID(). (this is a backport of ba4d3d31a63afc4054347d5125ef0abccbfa4faf from master) --- src/osx/core/sound.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/osx/core/sound.cpp b/src/osx/core/sound.cpp index 0f84638e29..120a807545 100644 --- a/src/osx/core/sound.cpp +++ b/src/osx/core/sound.cpp @@ -112,7 +112,13 @@ bool wxOSXAudioToolboxSoundData::Play(unsigned flags) CFStringNormalize(cfMutableString,kCFStringNormalizationFormD); wxCFRef url(CFURLCreateWithFileSystemPath(kCFAllocatorDefault, cfMutableString , kCFURLPOSIXPathStyle, false)); - AudioServicesCreateSystemSoundID(url, &m_soundID); + OSStatus err = AudioServicesCreateSystemSoundID(url, &m_soundID); + if ( err != 0 ) + { + wxLogError(_("Failed to load sound from \"%s\" (error %d)."), m_sndname, err); + return false; + } + AudioServicesAddSystemSoundCompletion( m_soundID, CFRunLoopGetCurrent(), NULL, wxOSXAudioToolboxSoundData::CompletionCallback, (void *) this ); bool sync = !(flags & wxSOUND_ASYNC); From 7d15904e1ab80c81adaad69054789b398998eeaa Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 18 Jul 2015 00:29:19 +0200 Subject: [PATCH 02/17] Fix wxSound::Create() and IsOk() return values in wxOSX. Don't pretend that we created wxSound object successfully without actually doing it: this means that now passing an invalid (e.g. non-existent or using wrong format) file to wxSound::Create()/ctor will return false/result in IsOk() returning false later, just as in the other ports. It also means that playing a successfully created wxSound object won't give any error messages, as unexpectedly happened before. (this is a backport of a6a3ad0d66f819d54359137d7313fea31bb02e4e from master) --- docs/changes.txt | 1 + src/osx/core/sound.cpp | 36 ++++++++++++++++++------------------ 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index 1a7c6ca584..fc0acbdba4 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -637,6 +637,7 @@ wxOSX: - Fix using wxHTTP and wxFTP from worker thread. - Fix wxFileDialog::GetFilterIndex() for file open dialogs (phsilva). - Fix custom paper support (tijsv). +- Return false from wxSound::Create()/IsOk() if the file doesn't exist. 3.0.2: (released 2014-10-06) diff --git a/src/osx/core/sound.cpp b/src/osx/core/sound.cpp index 120a807545..327de35cde 100644 --- a/src/osx/core/sound.cpp +++ b/src/osx/core/sound.cpp @@ -34,9 +34,9 @@ class wxOSXAudioToolboxSoundData : public wxSoundData { public: - wxOSXAudioToolboxSoundData(const wxString& fileName); + explicit wxOSXAudioToolboxSoundData(SystemSoundID soundID); - ~wxOSXAudioToolboxSoundData(); + virtual ~wxOSXAudioToolboxSoundData(); virtual bool Play(unsigned flags); @@ -46,14 +46,12 @@ protected: void SoundCompleted(); SystemSoundID m_soundID; - wxString m_sndname; //file path bool m_playing; }; -wxOSXAudioToolboxSoundData::wxOSXAudioToolboxSoundData(const wxString& fileName) : - m_soundID(0) +wxOSXAudioToolboxSoundData::wxOSXAudioToolboxSoundData(SystemSoundID soundID) : + m_soundID(soundID) { - m_sndname = fileName; m_playing = false; } @@ -108,17 +106,6 @@ bool wxOSXAudioToolboxSoundData::Play(unsigned flags) m_flags = flags; - wxCFRef cfMutableString(CFStringCreateMutableCopy(NULL, 0, wxCFStringRef(m_sndname))); - CFStringNormalize(cfMutableString,kCFStringNormalizationFormD); - wxCFRef url(CFURLCreateWithFileSystemPath(kCFAllocatorDefault, cfMutableString , kCFURLPOSIXPathStyle, false)); - - OSStatus err = AudioServicesCreateSystemSoundID(url, &m_soundID); - if ( err != 0 ) - { - wxLogError(_("Failed to load sound from \"%s\" (error %d)."), m_sndname, err); - return false; - } - AudioServicesAddSystemSoundCompletion( m_soundID, CFRunLoopGetCurrent(), NULL, wxOSXAudioToolboxSoundData::CompletionCallback, (void *) this ); bool sync = !(flags & wxSOUND_ASYNC); @@ -149,7 +136,20 @@ bool wxSound::Create(const wxString& fileName, bool isResource) { wxCHECK_MSG( !isResource, false, "not implemented" ); - m_data = new wxOSXAudioToolboxSoundData(fileName); + wxCFRef cfMutableString(CFStringCreateMutableCopy(NULL, 0, wxCFStringRef(fileName))); + CFStringNormalize(cfMutableString,kCFStringNormalizationFormD); + wxCFRef url(CFURLCreateWithFileSystemPath(kCFAllocatorDefault, cfMutableString , kCFURLPOSIXPathStyle, false)); + + SystemSoundID soundID; + OSStatus err = AudioServicesCreateSystemSoundID(url, &soundID); + if ( err != 0 ) + { + wxLogError(_("Failed to load sound from \"%s\" (error %d)."), fileName, err); + return false; + } + + m_data = new wxOSXAudioToolboxSoundData(soundID); + return true; } From 37f97729c6a772743e3092e213ea0f29754a7cbc Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 18 Jul 2015 00:32:15 +0200 Subject: [PATCH 03/17] No real changes, just get rid of a variable in wxOSX wxSound code. Don't define a variable which is used exactly once, testing for the async flag directly is just as, or even more, readable and shorter. (this is a backport of 605149ed07a377d471845c6d7f0a81191d29ce99 from master) --- src/osx/core/sound.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/osx/core/sound.cpp b/src/osx/core/sound.cpp index 327de35cde..d96ca0f9a3 100644 --- a/src/osx/core/sound.cpp +++ b/src/osx/core/sound.cpp @@ -108,13 +108,11 @@ bool wxOSXAudioToolboxSoundData::Play(unsigned flags) AudioServicesAddSystemSoundCompletion( m_soundID, CFRunLoopGetCurrent(), NULL, wxOSXAudioToolboxSoundData::CompletionCallback, (void *) this ); - bool sync = !(flags & wxSOUND_ASYNC); - m_playing = true; AudioServicesPlaySystemSound(m_soundID); - if ( sync ) + if ( !(flags & wxSOUND_ASYNC) ) { while ( m_playing ) { From 2eb5cb50bb923bd4d714db74e3aa5f001f666aca Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 18 Jul 2015 00:32:56 +0200 Subject: [PATCH 04/17] Don't keep using invalid wxSound object in the sound sample. If creating a sound object fails, delete it to ensure that it is recreated later. This fixes a minor bug: previously, if an invalid file was used as sound file, only the first attempt to play it resulted in an error and all the subsequent ones were just silently ignored. Now every attempt to play an invalid file results in an error message, as expected. (this is a backport of a788351eb6ecaa45f1fe91fb64b6e2b070e29697 from master) --- samples/sound/sound.cpp | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/samples/sound/sound.cpp b/samples/sound/sound.cpp index de18ca59cf..85dca32f96 100644 --- a/samples/sound/sound.cpp +++ b/samples/sound/sound.cpp @@ -81,6 +81,7 @@ public: private: bool CreateSound(wxSound& snd) const; + wxSound* TryCreateSound() const; wxSound* m_sound; wxString m_soundFile; @@ -975,6 +976,17 @@ bool MyFrame::CreateSound(wxSound& snd) const return snd.Create(m_soundFile); } +wxSound* MyFrame::TryCreateSound() const +{ + wxSound* const sound = new wxSound; + if ( !CreateSound(*sound) ) + { + delete sound; + return NULL; + } + + return sound; +} void MyFrame::NotifyUsingFile(const wxString& name) { @@ -1054,12 +1066,9 @@ void MyFrame::OnPlaySync(wxCommandEvent& WXUNUSED(event)) { wxBusyCursor busy; if ( !m_sound ) - { - m_sound = new wxSound; - CreateSound(*m_sound); - } + m_sound = TryCreateSound(); - if (m_sound->IsOk()) + if (m_sound) m_sound->Play(wxSOUND_SYNC); } @@ -1067,12 +1076,9 @@ void MyFrame::OnPlayAsync(wxCommandEvent& WXUNUSED(event)) { wxBusyCursor busy; if ( !m_sound ) - { - m_sound = new wxSound; - CreateSound(*m_sound); - } + m_sound = TryCreateSound(); - if (m_sound->IsOk()) + if (m_sound) m_sound->Play(wxSOUND_ASYNC); } @@ -1089,10 +1095,7 @@ void MyFrame::OnPlayLoop(wxCommandEvent& WXUNUSED(event)) { wxBusyCursor busy; if ( !m_sound ) - { - m_sound = new wxSound; - CreateSound(*m_sound); - } + m_sound = TryCreateSound(); if (m_sound->IsOk()) m_sound->Play(wxSOUND_ASYNC | wxSOUND_LOOP); From acec4b363b2ff519967940bf637c69c7fd18732a Mon Sep 17 00:00:00 2001 From: John Roberts Date: Sat, 18 Jul 2015 00:59:24 +0200 Subject: [PATCH 05/17] Fix printing all pages without dialog prompt in wxOSX. Do set from and to pages if we're not asking the user to choose them, otherwise nothing is printed at all. Closes #16294. (this is a backport of 896e148da5281ba31b158895faa0a826b0beb426 from master) --- docs/changes.txt | 1 + src/osx/core/printmac.cpp | 13 ++++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/docs/changes.txt b/docs/changes.txt index fc0acbdba4..1356f4cf58 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -636,6 +636,7 @@ wxOSX: - Fix length of text in wxTextDataObject. - Fix using wxHTTP and wxFTP from worker thread. - Fix wxFileDialog::GetFilterIndex() for file open dialogs (phsilva). +- Fix printing all pages non-interactively (John Roberts). - Fix custom paper support (tijsv). - Return false from wxSound::Create()/IsOk() if the file doesn't exist. diff --git a/src/osx/core/printmac.cpp b/src/osx/core/printmac.cpp index be3eb63aaa..5f33c3ccc3 100644 --- a/src/osx/core/printmac.cpp +++ b/src/osx/core/printmac.cpp @@ -637,10 +637,21 @@ bool wxMacPrinter::Print(wxWindow *parent, wxPrintout *printout, bool prompt) } // Only set min and max, because from and to will be - // set by the user + // set by the user if prompted for the print dialog above m_printDialogData.SetMinPage(minPage); m_printDialogData.SetMaxPage(maxPage); + // Set from and to pages if bypassing the print dialog + if ( !prompt ) + { + m_printDialogData.SetFromPage(fromPage); + + if( m_printDialogData.GetAllPages() ) + m_printDialogData.SetToPage(maxPage); + else + m_printDialogData.SetToPage(toPage); + } + printout->OnBeginPrinting(); bool keepGoing = true; From 9fe3c3f774dab92bdce965d2c877561080ba20e1 Mon Sep 17 00:00:00 2001 From: John Roberts Date: Sat, 18 Jul 2015 01:02:00 +0200 Subject: [PATCH 06/17] Handle WXK_NUMPAD_ENTER correctly in wxOSX wxTextCtrl. Basically just do the same thing for it as for WXK_RETURN. See #16415. (this is a backport of a79a2c0c8acbb7d743dc1257a9de1f3faa56a11e from master) --- docs/changes.txt | 1 + src/osx/textctrl_osx.cpp | 11 ++++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index 1356f4cf58..db62d3f192 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -637,6 +637,7 @@ wxOSX: - Fix using wxHTTP and wxFTP from worker thread. - Fix wxFileDialog::GetFilterIndex() for file open dialogs (phsilva). - Fix printing all pages non-interactively (John Roberts). +- Fix handling of WXK_NUMPAD_ENTER in wxTextCtrl (John Roberts). - Fix custom paper support (tijsv). - Return false from wxSound::Create()/IsOk() if the file doesn't exist. diff --git a/src/osx/textctrl_osx.cpp b/src/osx/textctrl_osx.cpp index 08346e5adb..7b42796c4d 100644 --- a/src/osx/textctrl_osx.cpp +++ b/src/osx/textctrl_osx.cpp @@ -366,8 +366,10 @@ void wxTextCtrl::OnChar(wxKeyEvent& event) bool eat_key = false ; long from, to; - if ( !IsEditable() && !event.IsKeyInCategory(WXK_CATEGORY_ARROW | WXK_CATEGORY_TAB) && - !( key == WXK_RETURN && ( (m_windowStyle & wxTE_PROCESS_ENTER) || (m_windowStyle & wxTE_MULTILINE) ) ) + if ( !IsEditable() && + !event.IsKeyInCategory(WXK_CATEGORY_ARROW | WXK_CATEGORY_TAB) && + !( (key == WXK_RETURN || key == WXK_NUMPAD_ENTER) && + ( (m_windowStyle & wxTE_PROCESS_ENTER) || (m_windowStyle & wxTE_MULTILINE) ) ) // && key != WXK_PAGEUP && key != WXK_PAGEDOWN && key != WXK_HOME && key != WXK_END ) { @@ -382,7 +384,8 @@ void wxTextCtrl::OnChar(wxKeyEvent& event) GetSelection( &from, &to ); if ( !IsMultiLine() && m_maxLength && GetValue().length() >= m_maxLength && !event.IsKeyInCategory(WXK_CATEGORY_ARROW | WXK_CATEGORY_TAB | WXK_CATEGORY_CUT) && - !( key == WXK_RETURN && (m_windowStyle & wxTE_PROCESS_ENTER) ) && + !( (key == WXK_RETURN || key == WXK_NUMPAD_ENTER) && + (m_windowStyle & wxTE_PROCESS_ENTER) ) && from == to ) { // eat it, we don't want to add more than allowed # of characters @@ -398,6 +401,7 @@ void wxTextCtrl::OnChar(wxKeyEvent& event) switch ( key ) { case WXK_RETURN: + case WXK_NUMPAD_ENTER: if (m_windowStyle & wxTE_PROCESS_ENTER) { wxCommandEvent event(wxEVT_TEXT_ENTER, m_windowId); @@ -466,6 +470,7 @@ void wxTextCtrl::OnChar(wxKeyEvent& event) ( key >= WXK_NUMPAD0 && key <= WXK_DIVIDE ) || key == WXK_RETURN || key == WXK_DELETE || + key == WXK_NUMPAD_ENTER || key == WXK_BACK) { wxCommandEvent event1(wxEVT_TEXT, m_windowId); From 38e410a273d6cca49b2ce170c459c7c2c10c6910 Mon Sep 17 00:00:00 2001 From: John Roberts Date: Sat, 18 Jul 2015 01:03:08 +0200 Subject: [PATCH 07/17] Fix generating events for WXK_NUMPAD_ENTER in wxOSX. This allows to properly detected numeric keypad "Enter" key in the code, notably in wxTextCtrl inside wxWidgets itself. Closes #16415. (this is a backport of 4f69410cd8329e2f9f2ce741491c33ae04470ec3 from master) --- docs/changes.txt | 3 ++- src/osx/cocoa/window.mm | 7 ++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index db62d3f192..caef19bec6 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -636,8 +636,9 @@ wxOSX: - Fix length of text in wxTextDataObject. - Fix using wxHTTP and wxFTP from worker thread. - Fix wxFileDialog::GetFilterIndex() for file open dialogs (phsilva). -- Fix printing all pages non-interactively (John Roberts). +- Generate correct events for WXK_NUMPAD_ENTER (John Roberts). - Fix handling of WXK_NUMPAD_ENTER in wxTextCtrl (John Roberts). +- Fix printing all pages non-interactively (John Roberts). - Fix custom paper support (tijsv). - Return false from wxSound::Create()/IsOk() if the file doesn't exist. diff --git a/src/osx/cocoa/window.mm b/src/osx/cocoa/window.mm index 517ae4a53a..2b56a1b529 100644 --- a/src/osx/cocoa/window.mm +++ b/src/osx/cocoa/window.mm @@ -232,6 +232,10 @@ long wxOSXTranslateCocoaKey( NSEvent* event, int eventType ) { switch ( [s characterAtIndex:0] ) { + // numpad enter key End-of-text character ETX U+0003 + case 3: + retval = WXK_NUMPAD_ENTER; + break; // backspace key case 0x7F : case 8 : @@ -345,9 +349,6 @@ long wxOSXTranslateCocoaKey( NSEvent* event, int eventType ) case 69: // + retval = WXK_NUMPAD_ADD; break; - case 76: // Enter - retval = WXK_NUMPAD_ENTER; - break; case 65: // . retval = WXK_NUMPAD_DECIMAL; break; From f313ecf9b69c389290cb231a7841941aceed631b Mon Sep 17 00:00:00 2001 From: John Roberts Date: Sat, 18 Jul 2015 01:06:44 +0200 Subject: [PATCH 08/17] Fix wxSearchCtrl appearance under OS X 10.10 Yosemite. Avoid centered look which renders the control unusable under this version. Closes #16871. (this is a backport of 563329f89f57018031b98ff76c32e3d51db03502 from master) --- docs/changes.txt | 1 + src/osx/cocoa/srchctrl.mm | 21 ++++++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/docs/changes.txt b/docs/changes.txt index caef19bec6..31c1f2d6a8 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -636,6 +636,7 @@ wxOSX: - Fix length of text in wxTextDataObject. - Fix using wxHTTP and wxFTP from worker thread. - Fix wxFileDialog::GetFilterIndex() for file open dialogs (phsilva). +- Fix wxSearchCtrl appearance under 10.10 (John Roberts). - Generate correct events for WXK_NUMPAD_ENTER (John Roberts). - Fix handling of WXK_NUMPAD_ENTER in wxTextCtrl (John Roberts). - Fix printing all pages non-interactively (John Roberts). diff --git a/src/osx/cocoa/srchctrl.mm b/src/osx/cocoa/srchctrl.mm index 880d590773..2525391bef 100644 --- a/src/osx/cocoa/srchctrl.mm +++ b/src/osx/cocoa/srchctrl.mm @@ -165,7 +165,25 @@ public : } } } - + + virtual void SetCentredLook( bool centre ) + { + SEL sel = @selector(setCenteredLook:); + if ( [m_searchFieldCell respondsToSelector: sel] ) + { + // all this avoids xcode parsing warnings when using + // [m_searchFieldCell setCenteredLook:NO]; + NSMethodSignature* signature = + [NSSearchFieldCell instanceMethodSignatureForSelector:sel]; + NSInvocation* invocation = + [NSInvocation invocationWithMethodSignature: signature]; + [invocation setTarget: m_searchFieldCell]; + [invocation setSelector:sel]; + [invocation setArgument:¢re atIndex:2]; + [invocation invoke]; + } + } + private: wxNSSearchField* m_searchField; NSSearchFieldCell* m_searchFieldCell; @@ -192,6 +210,7 @@ wxWidgetImplType* wxWidgetImpl::CreateSearchControl( wxSearchCtrl* wxpeer, wxNSSearchFieldControl* c = new wxNSSearchFieldControl( wxpeer, v ); c->SetNeedsFrame( false ); + c->SetCentredLook( false ); c->SetStringValue( str ); return c; } From 76ee2fa0a050dff262863d4b3d20c7b91fbdd39e Mon Sep 17 00:00:00 2001 From: Rob Krakora Date: Sat, 18 Jul 2015 01:15:29 +0200 Subject: [PATCH 09/17] Implement sending wxIconizeEvent in wxOSX. Translate windowDid{Miniaturize,Deminiaturize} callbacks to calls to SendIconizeEvent(). Closes #16718. (this is a backport of 31e1387541b8d2431232c25a31524f3e2991978d from master) --- docs/changes.txt | 1 + include/wx/osx/nonownedwnd.h | 4 +++- include/wx/osx/toplevel.h | 3 +++ interface/wx/event.h | 2 -- src/osx/cocoa/nonownedwnd.mm | 24 ++++++++++++++++++++++++ src/osx/nonownedwnd_osx.cpp | 8 ++++++++ src/osx/toplevel_osx.cpp | 9 +++++++++ 7 files changed, 48 insertions(+), 3 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index 31c1f2d6a8..29b83430d1 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -639,6 +639,7 @@ wxOSX: - Fix wxSearchCtrl appearance under 10.10 (John Roberts). - Generate correct events for WXK_NUMPAD_ENTER (John Roberts). - Fix handling of WXK_NUMPAD_ENTER in wxTextCtrl (John Roberts). +- Send wxIconizeEvent when a window is iconized/restore (Rob Krakora). - Fix printing all pages non-interactively (John Roberts). - Fix custom paper support (tijsv). - Return false from wxSound::Create()/IsOk() if the file doesn't exist. diff --git a/include/wx/osx/nonownedwnd.h b/include/wx/osx/nonownedwnd.h index edc3f04e62..9b0d3bea4e 100644 --- a/include/wx/osx/nonownedwnd.h +++ b/include/wx/osx/nonownedwnd.h @@ -113,7 +113,9 @@ public: virtual void HandleResized( double timestampsec ); virtual void HandleMoved( double timestampsec ); virtual void HandleResizing( double timestampsec, wxRect* rect ); - + + void OSXHandleMiniaturize(double WXUNUSED(timestampsec), bool miniaturized); + void WindowWasPainted(); virtual bool Destroy(); diff --git a/include/wx/osx/toplevel.h b/include/wx/osx/toplevel.h index 73b218fe75..d162b4121f 100644 --- a/include/wx/osx/toplevel.h +++ b/include/wx/osx/toplevel.h @@ -81,6 +81,9 @@ public: virtual void SetRepresentedFilename(const wxString& filename); + // do *not* call this to iconize the frame, this is a private function! + void OSXSetIconizeState(bool iconic); + protected: // common part of all ctors void Init(); diff --git a/interface/wx/event.h b/interface/wx/event.h index 52bb60970b..37eeae6093 100644 --- a/interface/wx/event.h +++ b/interface/wx/event.h @@ -4210,8 +4210,6 @@ public: An event being sent when the frame is iconized (minimized) or restored. - Currently only wxMSW and wxGTK generate such events. - @onlyfor{wxmsw,wxgtk} @beginEventTable{wxIconizeEvent} diff --git a/src/osx/cocoa/nonownedwnd.mm b/src/osx/cocoa/nonownedwnd.mm index 666c63c6a7..465e52be18 100644 --- a/src/osx/cocoa/nonownedwnd.mm +++ b/src/osx/cocoa/nonownedwnd.mm @@ -309,6 +309,8 @@ static NSResponder* s_formerFirstResponder = NULL; - (void)windowDidResignKey:(NSNotification *)notification; - (void)windowDidBecomeKey:(NSNotification *)notification; - (void)windowDidMove:(NSNotification *)notification; +- (void)windowDidMiniaturize:(NSNotification *)notification; +- (void)windowDidDeminiaturize:(NSNotification *)notification; - (BOOL)windowShouldClose:(id)window; - (BOOL)windowShouldZoom:(NSWindow *)window toFrame:(NSRect)newFrame; @@ -397,6 +399,28 @@ extern int wxOSXGetIdFromSelector(SEL action ); [self triggerMenu:_cmd]; } +- (void)windowDidMiniaturize:(NSNotification *)notification +{ + NSWindow* window = (NSWindow*) [notification object]; + wxNonOwnedWindowCocoaImpl* windowimpl = [window WX_implementation]; + if ( windowimpl ) + { + if ( wxNonOwnedWindow* wxpeer = windowimpl->GetWXPeer() ) + wxpeer->OSXHandleMiniaturize(0, [window isMiniaturized]); + } +} + +- (void)windowDidDeminiaturize:(NSNotification *)notification +{ + NSWindow* window = (NSWindow*) [notification object]; + wxNonOwnedWindowCocoaImpl* windowimpl = [window WX_implementation]; + if ( windowimpl ) + { + if ( wxNonOwnedWindow* wxpeer = windowimpl->GetWXPeer() ) + wxpeer->OSXHandleMiniaturize(0, [window isMiniaturized]); + } +} + - (BOOL)windowShouldClose:(id)nwindow { wxNonOwnedWindowCocoaImpl* windowimpl = [(NSWindow*) nwindow WX_implementation]; diff --git a/src/osx/nonownedwnd_osx.cpp b/src/osx/nonownedwnd_osx.cpp index 0e57c7f9f9..d70ebfe2b9 100644 --- a/src/osx/nonownedwnd_osx.cpp +++ b/src/osx/nonownedwnd_osx.cpp @@ -552,4 +552,12 @@ bool wxNonOwnedWindow::DoSetPathShape(const wxGraphicsPath& path) return DoSetRegionShape(wxRegion(bmp)); } +void +wxNonOwnedWindow::OSXHandleMiniaturize(double WXUNUSED(timestampsec), + bool miniaturized) +{ + if ( wxTopLevelWindowMac* top = (wxTopLevelWindowMac*) MacGetTopLevelWindow() ) + top->OSXSetIconizeState(miniaturized); +} + #endif // wxUSE_GRAPHICS_CONTEXT diff --git a/src/osx/toplevel_osx.cpp b/src/osx/toplevel_osx.cpp index b0dc820904..548c6431a3 100644 --- a/src/osx/toplevel_osx.cpp +++ b/src/osx/toplevel_osx.cpp @@ -224,3 +224,12 @@ void wxTopLevelWindowMac::SetRepresentedFilename(const wxString& filename) { m_nowpeer->SetRepresentedFilename(filename); } + +void wxTopLevelWindowMac::OSXSetIconizeState(bool iconize) +{ + if ( iconize != m_iconized ) + { + m_iconized = iconize; + (void)SendIconizeEvent(iconize); + } +} From 1b4a7cd671500dfda973d656b9a9f51fe8ce3096 Mon Sep 17 00:00:00 2001 From: John Roberts Date: Sat, 18 Jul 2015 01:19:18 +0200 Subject: [PATCH 10/17] Fix handling of "Cancel" button in wxSearchCtrl under OS X. Pressing it results in a control action with an empty, but not null, string. Recognize it correctly. Closes #16869. (this is a backport of 7065e26fb3a6eb698e49e4aaf911b0656f466efd from master) --- docs/changes.txt | 1 + src/osx/cocoa/srchctrl.mm | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/changes.txt b/docs/changes.txt index 29b83430d1..fd70022aac 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -637,6 +637,7 @@ wxOSX: - Fix using wxHTTP and wxFTP from worker thread. - Fix wxFileDialog::GetFilterIndex() for file open dialogs (phsilva). - Fix wxSearchCtrl appearance under 10.10 (John Roberts). +- Fix handling of "Cancel" button in wxSearchCtrl (John Roberts). - Generate correct events for WXK_NUMPAD_ENTER (John Roberts). - Fix handling of WXK_NUMPAD_ENTER in wxTextCtrl (John Roberts). - Send wxIconizeEvent when a window is iconized/restore (Rob Krakora). diff --git a/src/osx/cocoa/srchctrl.mm b/src/osx/cocoa/srchctrl.mm index 2525391bef..8549d8d944 100644 --- a/src/osx/cocoa/srchctrl.mm +++ b/src/osx/cocoa/srchctrl.mm @@ -155,7 +155,7 @@ public : if ( wxpeer ) { NSString *searchString = [m_searchField stringValue]; - if ( searchString == nil ) + if ( searchString == nil || !searchString.length ) { wxpeer->HandleSearchFieldCancelHit(); } From 53269a7cbac3b3da546a2989631019662aecf2e0 Mon Sep 17 00:00:00 2001 From: sbrowne Date: Sat, 18 Jul 2015 01:35:29 +0200 Subject: [PATCH 11/17] Do use disabled control text color for wxStaticText in OS X. Contrary to an old comment, using it seems to work, while using secondarySelectedControlColor results in incorrect appearance, different from the other disabled controls and, worse, makes the labels unreadable as their colour is too close to that of the background inside nested panels. Closes #10524. (this is a backport of c26939858867314d182207dddafa14a91e2dd8f4 and e7327959e06ae051a85622cbde9d0a6b7b1fba53 from master) --- docs/changes.txt | 1 + src/osx/cocoa/stattext.mm | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/changes.txt b/docs/changes.txt index fd70022aac..08e874af0e 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -641,6 +641,7 @@ wxOSX: - Generate correct events for WXK_NUMPAD_ENTER (John Roberts). - Fix handling of WXK_NUMPAD_ENTER in wxTextCtrl (John Roberts). - Send wxIconizeEvent when a window is iconized/restore (Rob Krakora). +- Use correct colour for disabled wxStaticText (sbrowne). - Fix printing all pages non-interactively (John Roberts). - Fix custom paper support (tijsv). - Return false from wxSound::Create()/IsOk() if the file doesn't exist. diff --git a/src/osx/cocoa/stattext.mm b/src/osx/cocoa/stattext.mm index f64b589f12..755bddfdc8 100644 --- a/src/osx/cocoa/stattext.mm +++ b/src/osx/cocoa/stattext.mm @@ -76,7 +76,7 @@ [m_textColor release]; m_textColor = [[self textColor] retain]; } - [self setTextColor: [NSColor secondarySelectedControlColor]]; + [self setTextColor: [NSColor disabledControlTextColor]]; } } } From aefc0ecf827527d916a520be3c0c58ddd49967ff Mon Sep 17 00:00:00 2001 From: mj_smoker Date: Sat, 18 Jul 2015 01:45:12 +0200 Subject: [PATCH 12/17] Handle wxTE_PROCESS_ENTER with wxTE_PASSWORD correctly in wxOSX. Controls with wxTE_PASSWORD style didn't send wxEVT_TEXT_ENTER even if they also had wxTE_PROCESS_ENTER. Fix this by checking for the latter style before mapping the enter presses to default button activation. Closes #14930. (this is a backport of 8e0799e3e52b8b34f6fb10912dd12df4ee825a75 from master) --- docs/changes.txt | 1 + src/osx/cocoa/textctrl.mm | 30 +++++++++++++++++++++--------- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index 08e874af0e..6a89aa0139 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -640,6 +640,7 @@ wxOSX: - Fix handling of "Cancel" button in wxSearchCtrl (John Roberts). - Generate correct events for WXK_NUMPAD_ENTER (John Roberts). - Fix handling of WXK_NUMPAD_ENTER in wxTextCtrl (John Roberts). +- Generate wxEVT_TEXT_ENTER for wxTE_PASSWORD controls too (mj_smoker). - Send wxIconizeEvent when a window is iconized/restore (Rob Krakora). - Use correct colour for disabled wxStaticText (sbrowne). - Fix printing all pages non-interactively (John Roberts). diff --git a/src/osx/cocoa/textctrl.mm b/src/osx/cocoa/textctrl.mm index a16023b024..c5bfb88958 100644 --- a/src/osx/cocoa/textctrl.mm +++ b/src/osx/cocoa/textctrl.mm @@ -213,17 +213,29 @@ NSView* wxMacEditHelper::ms_viewCurrentlyEdited = nil; { if (commandSelector == @selector(insertNewline:)) { - wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent(wxpeer), wxTopLevelWindow); - if ( tlw && tlw->GetDefaultItem() ) + if ( wxpeer->GetWindowStyle() & wxTE_PROCESS_ENTER ) { - wxButton *def = wxDynamicCast(tlw->GetDefaultItem(), wxButton); - if ( def && def->IsEnabled() ) + wxCommandEvent event(wxEVT_TEXT_ENTER, wxpeer->GetId()); + event.SetEventObject( wxpeer ); + wxTextWidgetImpl* impl = (wxNSTextFieldControl * ) wxWidgetImpl::FindFromWXWidget( self ); + wxTextEntry * const entry = impl->GetTextEntry(); + event.SetString( entry->GetValue() ); + handled = wxpeer->HandleWindowEvent( event ); + } + else + { + wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent(wxpeer), wxTopLevelWindow); + if ( tlw && tlw->GetDefaultItem() ) { - wxCommandEvent event(wxEVT_BUTTON, def->GetId() ); - event.SetEventObject(def); - def->Command(event); - handled = YES; - } + wxButton *def = wxDynamicCast(tlw->GetDefaultItem(), wxButton); + if ( def && def->IsEnabled() ) + { + wxCommandEvent event(wxEVT_BUTTON, def->GetId() ); + event.SetEventObject(def); + def->Command(event); + handled = YES; + } + } } } } From 0329fe3e0a54d4554d5fad6b66cc3af990fa1e35 Mon Sep 17 00:00:00 2001 From: Tim Kosse Date: Sat, 18 Jul 2015 02:17:38 +0200 Subject: [PATCH 13/17] Fix initial position of controls with layout insets in wxOSX. For such controls (e.g. wxButton, wxChoice, wxGauge), their initial position was different from the one specified when creating them, even though calling SetPosition() later did position them at exactly the position passed as argument. Closes #16780. (this is a backport of a4681572cc04e89e02743999897051c5442533e6 from master) --- docs/changes.txt | 1 + src/osx/window_osx.cpp | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/docs/changes.txt b/docs/changes.txt index 6a89aa0139..0f856e8653 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -643,6 +643,7 @@ wxOSX: - Generate wxEVT_TEXT_ENTER for wxTE_PASSWORD controls too (mj_smoker). - Send wxIconizeEvent when a window is iconized/restore (Rob Krakora). - Use correct colour for disabled wxStaticText (sbrowne). +- Fix initial position of controls with layout insets (Tim Kosse). - Fix printing all pages non-interactively (John Roberts). - Fix custom paper support (tijsv). - Return false from wxSound::Create()/IsOk() if the file doesn't exist. diff --git a/src/osx/window_osx.cpp b/src/osx/window_osx.cpp index 6bfe8e2a17..5148658209 100644 --- a/src/osx/window_osx.cpp +++ b/src/osx/window_osx.cpp @@ -457,9 +457,16 @@ void wxWindowMac::MacChildAdded() #endif } -void wxWindowMac::MacPostControlCreate(const wxPoint& WXUNUSED(pos), +void wxWindowMac::MacPostControlCreate(const wxPoint& pos, const wxSize& WXUNUSED(size)) { + // Some controls may have a nonzero layout inset, + // so we may need to adjust control position. + if ( pos.IsFullySpecified() && GetPosition() != pos ) + { + SetPosition(pos); + } + // todo remove if refactoring works correctly #if 0 wxASSERT_MSG( GetPeer() != NULL && GetPeer()->IsOk() , wxT("No valid mac control") ) ; From 3379b053bda79ffeedca1e84c2780736f5354108 Mon Sep 17 00:00:00 2001 From: Tim Kosse Date: Sat, 18 Jul 2015 02:24:39 +0200 Subject: [PATCH 14/17] Don't allow rich text content in non-rich wxTextCtrl in wxOSX. Explicitly disable rich text content and automatic quotation marks replacement in normal multiline text controls to make them behave closer to single line ones and also multiline ones on other platforms. Closes #16805. (this is a backport of 262ed2c1335e481ca72646246ccdef81f3825d9e and 3465d659fee0313a6dc650074432c3c435e4a83e from master) --- docs/changes.txt | 1 + src/osx/cocoa/textctrl.mm | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/docs/changes.txt b/docs/changes.txt index 0f856e8653..cbb2b368f0 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -644,6 +644,7 @@ wxOSX: - Send wxIconizeEvent when a window is iconized/restore (Rob Krakora). - Use correct colour for disabled wxStaticText (sbrowne). - Fix initial position of controls with layout insets (Tim Kosse). +- Don't allow pasting rich text in non-wxTE_RICH text controls (Tim Kosse). - Fix printing all pages non-interactively (John Roberts). - Fix custom paper support (tijsv). - Return false from wxSound::Create()/IsOk() if the file doesn't exist. diff --git a/src/osx/cocoa/textctrl.mm b/src/osx/cocoa/textctrl.mm index c5bfb88958..a2caa6e71a 100644 --- a/src/osx/cocoa/textctrl.mm +++ b/src/osx/cocoa/textctrl.mm @@ -580,6 +580,11 @@ wxNSTextViewControl::wxNSTextViewControl( wxTextCtrl *wxPeer, WXWidget w ) [tv setHorizontallyResizable:NO]; [tv setAutoresizingMask:NSViewWidthSizable]; + if ( !wxPeer->HasFlag(wxTE_RICH | wxTE_RICH2) ) + { + [tv setRichText:NO]; + } + [m_scrollView setDocumentView: tv]; [tv setDelegate: tv]; From 723e61a4b572e93b7731e22d7f7d7f7982f94bc3 Mon Sep 17 00:00:00 2001 From: sbrowne Date: Sat, 18 Jul 2015 14:46:53 +0200 Subject: [PATCH 15/17] Adjust inset border values for OS X >= 10.6. The bottom border was off by one pixel, use the values tested to work for OS X 10.[6789]. See #16808. (this is a backport of cb0625b9d9b96b751eb748463f3aa60697bbf5ce from master) --- docs/changes.txt | 1 + src/osx/cocoa/button.mm | 6 +++--- src/osx/cocoa/choice.mm | 4 ++-- src/osx/cocoa/gauge.mm | 4 ++-- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index cbb2b368f0..db09133f7a 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -643,6 +643,7 @@ wxOSX: - Generate wxEVT_TEXT_ENTER for wxTE_PASSWORD controls too (mj_smoker). - Send wxIconizeEvent when a window is iconized/restore (Rob Krakora). - Use correct colour for disabled wxStaticText (sbrowne). +- Fix bottom margins sizes for several controls (sbrowne). - Fix initial position of controls with layout insets (Tim Kosse). - Don't allow pasting rich text in non-wxTE_RICH text controls (Tim Kosse). - Fix printing all pages non-interactively (John Roberts). diff --git a/src/osx/cocoa/button.mm b/src/osx/cocoa/button.mm index d10797440e..f38947d96f 100644 --- a/src/osx/cocoa/button.mm +++ b/src/osx/cocoa/button.mm @@ -159,17 +159,17 @@ void wxButtonCocoaImpl::GetLayoutInset(int &left , int &top , int &right, int &b case NSRegularControlSize: left = right = 6; top = 4; - bottom = 8; + bottom = 7; break; case NSSmallControlSize: left = right = 5; top = 4; - bottom = 7; + bottom = 6; break; case NSMiniControlSize: left = right = 1; top = 0; - bottom = 2; + bottom = 1; break; } } diff --git a/src/osx/cocoa/choice.mm b/src/osx/cocoa/choice.mm index 0068d5d31d..52c12b7b6b 100644 --- a/src/osx/cocoa/choice.mm +++ b/src/osx/cocoa/choice.mm @@ -81,12 +81,12 @@ public: case NSRegularControlSize: left = right = 3; top = 2; - bottom = 4; + bottom = 3; break; case NSSmallControlSize: left = right = 3; top = 1; - bottom = 4; + bottom = 3; break; case NSMiniControlSize: left = 1; diff --git a/src/osx/cocoa/gauge.mm b/src/osx/cocoa/gauge.mm index fe15e849a5..24f9bedc01 100644 --- a/src/osx/cocoa/gauge.mm +++ b/src/osx/cocoa/gauge.mm @@ -81,13 +81,13 @@ public : case NSRegularControlSize: left = right = 2; top = 0; - bottom = 4; + bottom = 3; break; case NSMiniControlSize: case NSSmallControlSize: left = right = 1; top = 0; - bottom = 2; + bottom = 1; break; } } From 9153da02e75e73f0876c23f7399f980eb93f3772 Mon Sep 17 00:00:00 2001 From: sbrowne Date: Sat, 18 Jul 2015 14:48:19 +0200 Subject: [PATCH 16/17] Don't use extra margins around content of wxStaticBox in wxOSX. This makes top and left borders for the controls inside the box the same as right and bottom ones. Closes #16808. (this is a backport of bd177b0635063e1bdcca8d3ebb8f267650b03671 from master) --- docs/changes.txt | 1 + src/osx/cocoa/statbox.mm | 3 +++ 2 files changed, 4 insertions(+) diff --git a/docs/changes.txt b/docs/changes.txt index db09133f7a..bbe75517be 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -643,6 +643,7 @@ wxOSX: - Generate wxEVT_TEXT_ENTER for wxTE_PASSWORD controls too (mj_smoker). - Send wxIconizeEvent when a window is iconized/restore (Rob Krakora). - Use correct colour for disabled wxStaticText (sbrowne). +- Fix too large top and left margins inside wxStaticBox (sbrowne). - Fix bottom margins sizes for several controls (sbrowne). - Fix initial position of controls with layout insets (Tim Kosse). - Don't allow pasting rich text in non-wxTE_RICH text controls (Tim Kosse). diff --git a/src/osx/cocoa/statbox.mm b/src/osx/cocoa/statbox.mm index 1a346a4d75..95852e7f7b 100644 --- a/src/osx/cocoa/statbox.mm +++ b/src/osx/cocoa/statbox.mm @@ -71,6 +71,9 @@ wxWidgetImplType* wxWidgetImpl::CreateGroupBox( wxWindowMac* wxpeer, { NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ; wxNSBox* v = [[wxNSBox alloc] initWithFrame:r]; + NSSize margin = { 0.0, 0.0 }; + [v setContentViewMargins: margin]; + [v sizeToFit]; wxStaticBoxCocoaImpl* c = new wxStaticBoxCocoaImpl( wxpeer, v ); #if !wxOSX_USE_NATIVE_FLIPPED c->SetFlipped(false); From 3cae6b0b8261eaa8b798d53bb29e0f547c7579a7 Mon Sep 17 00:00:00 2001 From: John Roberts Date: Sat, 18 Jul 2015 15:15:51 +0200 Subject: [PATCH 17/17] Don't show wxDatePickerCtrl as being disabled when it isn't in wxOSX. Use setDrawsBackground: to fix the background colour and adjust the text colour whenever the control is enabled or disabled. Closes #16807. (this is a backport of 9bedba0bf3065617f3498d3ef8430f50b6b29edb from master) --- docs/changes.txt | 1 + src/osx/cocoa/datetimectrl.mm | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/docs/changes.txt b/docs/changes.txt index bbe75517be..d6a6dae76f 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -640,6 +640,7 @@ wxOSX: - Fix handling of "Cancel" button in wxSearchCtrl (John Roberts). - Generate correct events for WXK_NUMPAD_ENTER (John Roberts). - Fix handling of WXK_NUMPAD_ENTER in wxTextCtrl (John Roberts). +- Don't show wxDatePickerCtrl as being disabled when it isn't (John Roberts). - Generate wxEVT_TEXT_ENTER for wxTE_PASSWORD controls too (mj_smoker). - Send wxIconizeEvent when a window is iconized/restore (Rob Krakora). - Use correct colour for disabled wxStaticText (sbrowne). diff --git a/src/osx/cocoa/datetimectrl.mm b/src/osx/cocoa/datetimectrl.mm index 575a8a2b48..edee2965a4 100644 --- a/src/osx/cocoa/datetimectrl.mm +++ b/src/osx/cocoa/datetimectrl.mm @@ -128,6 +128,26 @@ public: } } + virtual void Enable(bool enable = true) + { + wxNSDatePicker* const nsdatePicker = View(); + + [nsdatePicker setEnabled: enable]; + + if ( enable ) + { + wxWindow* const wxpeer = GetWXPeer(); + if ( wxpeer ) + [nsdatePicker setTextColor: wxpeer->GetForegroundColour().OSXGetNSColor()]; + else + [nsdatePicker setTextColor: [NSColor controlTextColor]]; + } + else + { + [nsdatePicker setTextColor: [NSColor disabledControlTextColor]]; + } + } + private: wxNSDatePicker* View() const { @@ -170,6 +190,9 @@ wxDateTimeWidgetImpl::CreateDateTimePicker(wxDateTimePickerCtrl* wxpeer, [v setDatePickerStyle: NSTextFieldAndStepperDatePickerStyle]; + // Avoid a disabled looking transparent background for the text cells. + [v setDrawsBackground: YES]; + if ( dt.IsValid() ) { [v setDateValue: NSDateFromWX(dt)];