#include "wx/button.h"
-// FIXME: right now only wxMSW and wxGTK implement bitmap support in wxButton
+// FIXME: right now only wxMSW, wxGTK and wxOSX implement bitmap support in wxButton
// itself, this shouldn't be used for the other platforms neither
// when all of them do it
-#if (defined(__WXMSW__) || defined(__WXGTK20__)) && !defined(__WXUNIVERSAL__)
+#if (defined(__WXMSW__) || defined(__WXGTK20__) || defined(__WXOSX__)) && !defined(__WXUNIVERSAL__)
#define wxHAS_BUTTON_BITMAP
#endif
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_
protected:
virtual wxSize DoGetBestSize() const ;
-#if wxOSX_USE_COCOA
+ void OnEnterWindow( wxMouseEvent& event);
+ void OnLeaveWindow( wxMouseEvent& event);
+
virtual wxBitmap DoGetBitmap(State which) const;
virtual void DoSetBitmap(const wxBitmap& bitmap, State which);
virtual void DoSetBitmapPosition(wxDirection dir);
-#endif // wxOSX_USE_COCOA
+ virtual void DoSetBitmapMargins(int x, int y)
+ {
+ m_marginX = x;
+ m_marginY = y;
+ }
+
+ // the margins around the bitmap
+ int m_marginX;
+ int m_marginY;
+
+ // the bitmaps for the different state of the buttons, all of them may be
+ // invalid and the button only shows a bitmap at all if State_Normal bitmap
+ // is valid
+ wxBitmap m_bitmaps[State_Max];
+
DECLARE_DYNAMIC_CLASS(wxButton)
+ DECLARE_EVENT_TABLE()
};
// OS X specific class, not part of public wx API
protected:
virtual wxSize DoGetBestSize() const ;
-
};
#endif // _WX_OSX_BUTTON_H_
};
//
-// common interface bitmapbuttons
+// common interface for buttons
//
-class wxBitmapButtonImpl
+class wxButtonImpl
{
public :
- wxBitmapButtonImpl(){}
- virtual ~wxBitmapButtonImpl(){}
+ wxButtonImpl(){}
+ virtual ~wxButtonImpl(){}
virtual void SetPressedBitmap( const wxBitmap& bitmap ) = 0;
} ;
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"
return true;
}
-void wxBitmapButton::DoSetBitmap(const wxBitmap& bitmap, State which)
-{
- wxBitmapButtonBase::DoSetBitmap(bitmap, which);
-
- // we don't support any other states currently
- if ( which == State_Normal )
- {
- 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
{
wxSize best(m_marginX, m_marginY);
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
IMPLEMENT_DYNAMIC_CLASS(wxButton, wxControl)
+BEGIN_EVENT_TABLE(wxButton, wxControl)
+ EVT_ENTER_WINDOW(wxButton::OnEnterWindow)
+ EVT_LEAVE_WINDOW(wxButton::OnLeaveWindow)
+END_EVENT_TABLE()
+
bool wxButton::Create(wxWindow *parent,
wxWindowID id,
const wxString& lbl,
const wxValidator& validator,
const wxString& name)
{
+ m_marginX =
+ m_marginY = 0;
+
// FIXME: this hack is needed because we're called from
// wxBitmapButton::Create() with this style and we currently use a
// different wxWidgetImpl method (CreateBitmapButton() rather than
wxButtonBase::SetLabel(label);
}
-// there is no support for button bitmaps in wxOSX/Carbon so there is no need
-// for these methods there
-#if wxOSX_USE_COCOA
-
wxBitmap wxButton::DoGetBitmap(State which) const
{
- return which == State_Normal ? m_peer->GetBitmap() : wxBitmap();
+ return m_bitmaps[which];
}
void wxButton::DoSetBitmap(const wxBitmap& bitmap, State which)
{
+ m_bitmaps[which] = bitmap;
+
if ( which == State_Normal )
m_peer->SetBitmap(bitmap);
+ else if ( which == State_Pressed )
+ {
+ wxButtonImpl* bi = dynamic_cast<wxButtonImpl*> (m_peer);
+ if ( bi )
+ bi->SetPressedBitmap(bitmap);
+ }
}
void wxButton::DoSetBitmapPosition(wxDirection dir)
m_peer->SetBitmapPosition(dir);
}
-#endif // wxOSX_USE_COCOA
-
wxWindow *wxButton::SetDefault()
{
wxWindow *btnOldDefault = wxButtonBase::SetDefault();
// ProcessCommand(event);
}
+void wxButton::OnEnterWindow( wxMouseEvent& WXUNUSED(event))
+{
+ if ( DoGetBitmap( State_Current ).IsOk() )
+ m_peer->SetBitmap( DoGetBitmap( State_Current ) );
+}
+
+void wxButton::OnLeaveWindow( wxMouseEvent& WXUNUSED(event))
+{
+ if ( DoGetBitmap( State_Current ).IsOk() )
+ m_peer->SetBitmap( DoGetBitmap( State_Normal ) );
+}
+
bool wxButton::OSXHandleClicked( double WXUNUSED(timestampsec) )
{
wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, m_windowId);
// define a derived class to override SetBitmap() and also to provide
// InitButtonContentInfo() helper used by CreateBitmapButton()
-class wxMacBitmapButton : public wxMacControl, public wxBitmapButtonImpl
+class wxMacBitmapButton : public wxMacControl, public wxButtonImpl
{
public:
wxMacBitmapButton(wxWindowMac* peer, const wxBitmap& bitmap, int style)
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
-#include "wx/wxprec.h"
-
-#if wxUSE_BMPBUTTON
-
-#include "wx/bmpbuttn.h"
-#include "wx/image.h"
-
-#ifndef WX_PRECOMP
- #include "wx/dcmemory.h"
-#endif
-
-#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),
- const wxBitmap& bitmap,
- const wxPoint& pos,
- const wxSize& size,
- long style,
- long WXUNUSED(extraStyle))
-{
- NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
- wxNSButton* v = [[wxNSButton alloc] initWithFrame:r];
-
- // trying to get as close as possible to flags
- if ( style & wxBORDER_NONE )
- {
- [v setBezelStyle:NSShadowlessSquareBezelStyle];
- [v setBordered:NO];
- }
- else
- {
- // see trac #11128 for a thorough discussion
- if ( (style & wxBORDER_MASK) == wxBORDER_RAISED )
- [v setBezelStyle:NSRegularSquareBezelStyle];
- else if ( (style & wxBORDER_MASK) == wxBORDER_SUNKEN )
- [v setBezelStyle:NSSmallSquareBezelStyle];
- else
- [v setBezelStyle:NSShadowlessSquareBezelStyle];
- }
-
- if (bitmap.Ok())
- [v setImage:bitmap.GetNSImage() ];
-
- [v setButtonType:NSMomentaryPushInButton];
- wxWidgetCocoaImpl* c = new wxBitmapButtonCocoaImpl( wxpeer, v );
- return c;
-}
-
-#endif
+// everything is done in button.mm now
\ No newline at end of file
namespace
{
-class wxButtonCocoaImpl : public wxWidgetCocoaImpl
+class wxButtonCocoaImpl : public wxWidgetCocoaImpl, public wxButtonImpl
{
public:
wxButtonCocoaImpl(wxWindowMac *wxpeer, wxNSButton *v)
virtual void SetBitmap(const wxBitmap& bitmap)
{
- [GetNSButton() setBezelStyle:bitmap.IsOk() ? NSRegularSquareBezelStyle
- : NSRoundedBezelStyle];
+ // switch bezel style for plain pushbuttons
+ if ( bitmap.IsOk() && [GetNSButton() bezelStyle] == NSRoundedBezelStyle )
+ [GetNSButton() setBezelStyle:NSRegularSquareBezelStyle ];
wxWidgetCocoaImpl::SetBitmap(bitmap);
}
+ void SetPressedBitmap( const wxBitmap& bitmap )
+ {
+ NSButton* button = GetNSButton();
+ [button setAlternateImage: bitmap.GetNSImage()];
+ [button setButtonType:NSMomentaryChangeButton];
+ }
+
private:
NSButton *GetNSButton() const
{
[(NSControl*)m_osxView performClick:nil];
}
+#if wxUSE_BMPBUTTON
+
+wxWidgetImplType* wxWidgetImpl::CreateBitmapButton( wxWindowMac* wxpeer,
+ wxWindowMac* WXUNUSED(parent),
+ wxWindowID WXUNUSED(id),
+ const wxBitmap& bitmap,
+ const wxPoint& pos,
+ const wxSize& size,
+ long style,
+ long WXUNUSED(extraStyle))
+{
+ NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
+ wxNSButton* v = [[wxNSButton alloc] initWithFrame:r];
+
+ // trying to get as close as possible to flags
+ if ( style & wxBORDER_NONE )
+ {
+ [v setBezelStyle:NSShadowlessSquareBezelStyle];
+ [v setBordered:NO];
+ }
+ else
+ {
+ // see trac #11128 for a thorough discussion
+ if ( (style & wxBORDER_MASK) == wxBORDER_RAISED )
+ [v setBezelStyle:NSRegularSquareBezelStyle];
+ else if ( (style & wxBORDER_MASK) == wxBORDER_SUNKEN )
+ [v setBezelStyle:NSSmallSquareBezelStyle];
+ else
+ [v setBezelStyle:NSShadowlessSquareBezelStyle];
+ }
+
+ if (bitmap.Ok())
+ [v setImage:bitmap.GetNSImage() ];
+
+ [v setButtonType:NSMomentaryPushInButton];
+ wxWidgetCocoaImpl* c = new wxButtonCocoaImpl( wxpeer, v );
+ return c;
+}
+
+#endif
+
//
// wxDisclosureButton implementation
//