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
This commit is contained in:
Stefan Csomor
2009-10-08 18:38:43 +00:00
parent c579ac6280
commit 411a1c35ff
8 changed files with 74 additions and 2 deletions

View File

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

View File

@@ -261,6 +261,7 @@ protected :
@interface wxNSButton : NSButton
{
NSTrackingRectTag rectTag;
}
@end

View File

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

View File

@@ -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<wxBitmapButtonImpl*> (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

View File

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

View File

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

View File

@@ -82,6 +82,16 @@ wxSize wxButton::GetDefaultSize()
}
}
- (void) setTrackingTag: (NSTrackingRectTag)tag
{
rectTag = tag;
}
- (NSTrackingRectTag) trackingTag
{
return rectTag;
}
@end
namespace

View File

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