From: Stefan Csomor Date: Thu, 8 Oct 2009 18:38:43 +0000 (+0000) Subject: implementing rollover and pressed image for bitmapbutton on osx_cocoa X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/411a1c35ff2e9be0bef6e2997f00dded357f2906 implementing rollover and pressed image for bitmapbutton on osx_cocoa git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@62335 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/include/wx/osx/bmpbuttn.h b/include/wx/osx/bmpbuttn.h index 9cb9bb70ce..94c97608b5 100644 --- a/include/wx/osx/bmpbuttn.h +++ b/include/wx/osx/bmpbuttn.h @@ -40,11 +40,15 @@ public: const wxString& name = wxButtonNameStr); protected: + void OnEnterWindow( wxMouseEvent& event); + void OnLeaveWindow( wxMouseEvent& event); + virtual wxSize DoGetBestSize() const; virtual void DoSetBitmap(const wxBitmap& bitmap, State which); DECLARE_DYNAMIC_CLASS(wxBitmapButton) + DECLARE_EVENT_TABLE() }; #endif // _WX_OSX_BMPBUTTN_H_ diff --git a/include/wx/osx/cocoa/private.h b/include/wx/osx/cocoa/private.h index a6ac933584..d9bf8338d1 100644 --- a/include/wx/osx/cocoa/private.h +++ b/include/wx/osx/cocoa/private.h @@ -261,6 +261,7 @@ protected : @interface wxNSButton : NSButton { + NSTrackingRectTag rectTag; } @end diff --git a/include/wx/osx/core/private.h b/include/wx/osx/core/private.h index 418b6f8e4a..a011a3d5a9 100644 --- a/include/wx/osx/core/private.h +++ b/include/wx/osx/core/private.h @@ -587,6 +587,19 @@ public : virtual void CheckSpelling(bool WXUNUSED(check)) { } }; +// +// common interface bitmapbuttons +// + +class wxBitmapButtonImpl +{ + public : + wxBitmapButtonImpl(){} + virtual ~wxBitmapButtonImpl(){} + + virtual void SetPressedBitmap( const wxBitmap& bitmap ) = 0; +} ; + // // common interface for search controls // diff --git a/src/osx/bmpbuttn_osx.cpp b/src/osx/bmpbuttn_osx.cpp index d22411f27e..6264a9baa8 100644 --- a/src/osx/bmpbuttn_osx.cpp +++ b/src/osx/bmpbuttn_osx.cpp @@ -22,6 +22,11 @@ IMPLEMENT_DYNAMIC_CLASS(wxBitmapButton, wxButton) +BEGIN_EVENT_TABLE(wxBitmapButton, wxButton) + EVT_ENTER_WINDOW(wxBitmapButton::OnEnterWindow) + EVT_LEAVE_WINDOW(wxBitmapButton::OnLeaveWindow) +END_EVENT_TABLE() + #include "wx/osx/private.h" //--------------------------------------------------------------------------- @@ -70,6 +75,12 @@ void wxBitmapButton::DoSetBitmap(const wxBitmap& bitmap, State which) { m_peer->SetBitmap( bitmap ); } + else if ( which == State_Pressed ) + { + wxBitmapButtonImpl* bi = dynamic_cast (m_peer); + if ( bi ) + bi->SetPressedBitmap(bitmap); + } } wxSize wxBitmapButton::DoGetBestSize() const @@ -86,4 +97,16 @@ wxSize wxBitmapButton::DoGetBestSize() const return best; } +void wxBitmapButton::OnEnterWindow( wxMouseEvent& WXUNUSED(event)) +{ + if ( DoGetBitmap( State_Current ).IsOk() ) + m_peer->SetBitmap( DoGetBitmap( State_Current ) ); +} + +void wxBitmapButton::OnLeaveWindow( wxMouseEvent& WXUNUSED(event)) +{ + if ( DoGetBitmap( State_Current ).IsOk() ) + m_peer->SetBitmap( DoGetBitmap( State_Normal ) ); +} + #endif // wxUSE_BMPBUTTON diff --git a/src/osx/carbon/bmpbuttn.cpp b/src/osx/carbon/bmpbuttn.cpp index cde7745150..55147f94e4 100644 --- a/src/osx/carbon/bmpbuttn.cpp +++ b/src/osx/carbon/bmpbuttn.cpp @@ -27,7 +27,7 @@ namespace // define a derived class to override SetBitmap() and also to provide // InitButtonContentInfo() helper used by CreateBitmapButton() -class wxMacBitmapButton : public wxMacControl +class wxMacBitmapButton : public wxMacControl, public wxBitmapButtonImpl { public: wxMacBitmapButton(wxWindowMac* peer, const wxBitmap& bitmap, int style) @@ -70,6 +70,11 @@ public: m_isIcon ? kControlContentIconRef : 0); } + void SetPressedBitmap( const wxBitmap& WXUNUSED(bitmap) ) + { + // not implemented under Carbon + } + private: // helper function: returns true if the given bitmap is of one of standard // sizes supported by OS X icons diff --git a/src/osx/cocoa/bmpbuttn.mm b/src/osx/cocoa/bmpbuttn.mm index d3c0092ba0..ccfc8c9881 100644 --- a/src/osx/cocoa/bmpbuttn.mm +++ b/src/osx/cocoa/bmpbuttn.mm @@ -22,6 +22,21 @@ #include "wx/osx/private.h" +class wxBitmapButtonCocoaImpl : public wxWidgetCocoaImpl, public wxBitmapButtonImpl +{ + public : + wxBitmapButtonCocoaImpl( wxWindowMac* peer , WXWidget w) : wxWidgetCocoaImpl(peer,w) + { + } + + void SetPressedBitmap( const wxBitmap& bitmap ) + { + wxNSButton* button = (wxNSButton*) m_osxView; + [button setAlternateImage: bitmap.GetNSImage()]; + [button setButtonType:NSMomentaryChangeButton]; + } +} ; + wxWidgetImplType* wxWidgetImpl::CreateBitmapButton( wxWindowMac* wxpeer, wxWindowMac* WXUNUSED(parent), wxWindowID WXUNUSED(id), @@ -55,7 +70,7 @@ wxWidgetImplType* wxWidgetImpl::CreateBitmapButton( wxWindowMac* wxpeer, [v setImage:bitmap.GetNSImage() ]; [v setButtonType:NSMomentaryPushInButton]; - wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v ); + wxWidgetCocoaImpl* c = new wxBitmapButtonCocoaImpl( wxpeer, v ); return c; } diff --git a/src/osx/cocoa/button.mm b/src/osx/cocoa/button.mm index 57512e1ccb..f83027bf6b 100644 --- a/src/osx/cocoa/button.mm +++ b/src/osx/cocoa/button.mm @@ -82,6 +82,16 @@ wxSize wxButton::GetDefaultSize() } } +- (void) setTrackingTag: (NSTrackingRectTag)tag +{ + rectTag = tag; +} + +- (NSTrackingRectTag) trackingTag +{ + return rectTag; +} + @end namespace diff --git a/src/osx/cocoa/window.mm b/src/osx/cocoa/window.mm index 26d42af3f6..59b06c142f 100644 --- a/src/osx/cocoa/window.mm +++ b/src/osx/cocoa/window.mm @@ -1683,6 +1683,7 @@ void wxWidgetCocoaImpl::SetBitmap( const wxBitmap& bitmap ) if ( [m_osxView respondsToSelector:@selector(setImage:)] ) { [m_osxView setImage:bitmap.GetNSImage()]; + [m_osxView setNeedsDisplay:YES]; } }