Merge branch '3.0-osx-fixes' into 3.0

Various fixes for wxOSX back ported from master.
This commit is contained in:
Vadim Zeitlin
2015-09-11 14:22:42 +02:00
21 changed files with 210 additions and 59 deletions

View File

@@ -637,7 +637,21 @@ 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).
- 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).
- 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).
- 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.
3.0.2: (released 2014-10-06)

View File

@@ -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();

View File

@@ -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();

View File

@@ -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}

View File

@@ -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);

View File

@@ -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;
}
}

View File

@@ -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;

View File

@@ -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)];

View File

@@ -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;
}
}

View File

@@ -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];

View File

@@ -155,7 +155,7 @@ public :
if ( wxpeer )
{
NSString *searchString = [m_searchField stringValue];
if ( searchString == nil )
if ( searchString == nil || !searchString.length )
{
wxpeer->HandleSearchFieldCancelHit();
}
@@ -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:&centre 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;
}

View File

@@ -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);

View File

@@ -76,7 +76,7 @@
[m_textColor release];
m_textColor = [[self textColor] retain];
}
[self setTextColor: [NSColor secondarySelectedControlColor]];
[self setTextColor: [NSColor disabledControlTextColor]];
}
}
}

View File

@@ -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;
}
}
}
}
}
@@ -568,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];

View File

@@ -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;

View File

@@ -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;

View File

@@ -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,20 +106,13 @@ bool wxOSXAudioToolboxSoundData::Play(unsigned flags)
m_flags = flags;
wxCFRef<CFMutableStringRef> cfMutableString(CFStringCreateMutableCopy(NULL, 0, wxCFStringRef(m_sndname)));
CFStringNormalize(cfMutableString,kCFStringNormalizationFormD);
wxCFRef<CFURLRef> url(CFURLCreateWithFileSystemPath(kCFAllocatorDefault, cfMutableString , kCFURLPOSIXPathStyle, false));
AudioServicesCreateSystemSoundID(url, &m_soundID);
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 )
{
@@ -143,7 +134,20 @@ bool wxSound::Create(const wxString& fileName, bool isResource)
{
wxCHECK_MSG( !isResource, false, "not implemented" );
m_data = new wxOSXAudioToolboxSoundData(fileName);
wxCFRef<CFMutableStringRef> cfMutableString(CFStringCreateMutableCopy(NULL, 0, wxCFStringRef(fileName)));
CFStringNormalize(cfMutableString,kCFStringNormalizationFormD);
wxCFRef<CFURLRef> 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;
}

View File

@@ -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

View File

@@ -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);

View File

@@ -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);
}
}

View File

@@ -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") ) ;