moving bitmapbutton functionality up to button for OSX
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@62347 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -18,10 +18,10 @@
|
|||||||
|
|
||||||
#include "wx/button.h"
|
#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
|
// itself, this shouldn't be used for the other platforms neither
|
||||||
// when all of them do it
|
// 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
|
#define wxHAS_BUTTON_BITMAP
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@@ -40,15 +40,10 @@ public:
|
|||||||
const wxString& name = wxButtonNameStr);
|
const wxString& name = wxButtonNameStr);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void OnEnterWindow( wxMouseEvent& event);
|
|
||||||
void OnLeaveWindow( wxMouseEvent& event);
|
|
||||||
|
|
||||||
virtual wxSize DoGetBestSize() const;
|
virtual wxSize DoGetBestSize() const;
|
||||||
|
|
||||||
virtual void DoSetBitmap(const wxBitmap& bitmap, State which);
|
|
||||||
|
|
||||||
DECLARE_DYNAMIC_CLASS(wxBitmapButton)
|
DECLARE_DYNAMIC_CLASS(wxBitmapButton)
|
||||||
DECLARE_EVENT_TABLE()
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // _WX_OSX_BMPBUTTN_H_
|
#endif // _WX_OSX_BMPBUTTN_H_
|
||||||
|
@@ -54,13 +54,30 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
virtual wxSize DoGetBestSize() const ;
|
virtual wxSize DoGetBestSize() const ;
|
||||||
|
|
||||||
#if wxOSX_USE_COCOA
|
void OnEnterWindow( wxMouseEvent& event);
|
||||||
|
void OnLeaveWindow( wxMouseEvent& event);
|
||||||
|
|
||||||
virtual wxBitmap DoGetBitmap(State which) const;
|
virtual wxBitmap DoGetBitmap(State which) const;
|
||||||
virtual void DoSetBitmap(const wxBitmap& bitmap, State which);
|
virtual void DoSetBitmap(const wxBitmap& bitmap, State which);
|
||||||
virtual void DoSetBitmapPosition(wxDirection dir);
|
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_DYNAMIC_CLASS(wxButton)
|
||||||
|
DECLARE_EVENT_TABLE()
|
||||||
};
|
};
|
||||||
|
|
||||||
// OS X specific class, not part of public wx API
|
// OS X specific class, not part of public wx API
|
||||||
@@ -97,7 +114,6 @@ public:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual wxSize DoGetBestSize() const ;
|
virtual wxSize DoGetBestSize() const ;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // _WX_OSX_BUTTON_H_
|
#endif // _WX_OSX_BUTTON_H_
|
||||||
|
@@ -588,14 +588,14 @@ public :
|
|||||||
};
|
};
|
||||||
|
|
||||||
//
|
//
|
||||||
// common interface bitmapbuttons
|
// common interface for buttons
|
||||||
//
|
//
|
||||||
|
|
||||||
class wxBitmapButtonImpl
|
class wxButtonImpl
|
||||||
{
|
{
|
||||||
public :
|
public :
|
||||||
wxBitmapButtonImpl(){}
|
wxButtonImpl(){}
|
||||||
virtual ~wxBitmapButtonImpl(){}
|
virtual ~wxButtonImpl(){}
|
||||||
|
|
||||||
virtual void SetPressedBitmap( const wxBitmap& bitmap ) = 0;
|
virtual void SetPressedBitmap( const wxBitmap& bitmap ) = 0;
|
||||||
} ;
|
} ;
|
||||||
|
@@ -22,10 +22,6 @@
|
|||||||
|
|
||||||
IMPLEMENT_DYNAMIC_CLASS(wxBitmapButton, wxButton)
|
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"
|
#include "wx/osx/private.h"
|
||||||
|
|
||||||
@@ -66,23 +62,6 @@ bool wxBitmapButton::Create( wxWindow *parent,
|
|||||||
return true;
|
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 wxBitmapButton::DoGetBestSize() const
|
||||||
{
|
{
|
||||||
wxSize best(m_marginX, m_marginY);
|
wxSize best(m_marginX, m_marginY);
|
||||||
@@ -97,16 +76,4 @@ wxSize wxBitmapButton::DoGetBestSize() const
|
|||||||
return best;
|
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
|
#endif // wxUSE_BMPBUTTON
|
||||||
|
@@ -25,6 +25,11 @@
|
|||||||
|
|
||||||
IMPLEMENT_DYNAMIC_CLASS(wxButton, wxControl)
|
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,
|
bool wxButton::Create(wxWindow *parent,
|
||||||
wxWindowID id,
|
wxWindowID id,
|
||||||
const wxString& lbl,
|
const wxString& lbl,
|
||||||
@@ -34,6 +39,9 @@ bool wxButton::Create(wxWindow *parent,
|
|||||||
const wxValidator& validator,
|
const wxValidator& validator,
|
||||||
const wxString& name)
|
const wxString& name)
|
||||||
{
|
{
|
||||||
|
m_marginX =
|
||||||
|
m_marginY = 0;
|
||||||
|
|
||||||
// FIXME: this hack is needed because we're called from
|
// FIXME: this hack is needed because we're called from
|
||||||
// wxBitmapButton::Create() with this style and we currently use a
|
// wxBitmapButton::Create() with this style and we currently use a
|
||||||
// different wxWidgetImpl method (CreateBitmapButton() rather than
|
// different wxWidgetImpl method (CreateBitmapButton() rather than
|
||||||
@@ -79,19 +87,23 @@ void wxButton::SetLabel(const wxString& label)
|
|||||||
wxButtonBase::SetLabel(label);
|
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
|
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)
|
void wxButton::DoSetBitmap(const wxBitmap& bitmap, State which)
|
||||||
{
|
{
|
||||||
|
m_bitmaps[which] = bitmap;
|
||||||
|
|
||||||
if ( which == State_Normal )
|
if ( which == State_Normal )
|
||||||
m_peer->SetBitmap(bitmap);
|
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)
|
void wxButton::DoSetBitmapPosition(wxDirection dir)
|
||||||
@@ -99,8 +111,6 @@ void wxButton::DoSetBitmapPosition(wxDirection dir)
|
|||||||
m_peer->SetBitmapPosition(dir);
|
m_peer->SetBitmapPosition(dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // wxOSX_USE_COCOA
|
|
||||||
|
|
||||||
wxWindow *wxButton::SetDefault()
|
wxWindow *wxButton::SetDefault()
|
||||||
{
|
{
|
||||||
wxWindow *btnOldDefault = wxButtonBase::SetDefault();
|
wxWindow *btnOldDefault = wxButtonBase::SetDefault();
|
||||||
@@ -121,6 +131,18 @@ void wxButton::Command (wxCommandEvent & WXUNUSED(event))
|
|||||||
// ProcessCommand(event);
|
// 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) )
|
bool wxButton::OSXHandleClicked( double WXUNUSED(timestampsec) )
|
||||||
{
|
{
|
||||||
wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, m_windowId);
|
wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, m_windowId);
|
||||||
|
@@ -27,7 +27,7 @@ namespace
|
|||||||
|
|
||||||
// define a derived class to override SetBitmap() and also to provide
|
// define a derived class to override SetBitmap() and also to provide
|
||||||
// InitButtonContentInfo() helper used by CreateBitmapButton()
|
// InitButtonContentInfo() helper used by CreateBitmapButton()
|
||||||
class wxMacBitmapButton : public wxMacControl, public wxBitmapButtonImpl
|
class wxMacBitmapButton : public wxMacControl, public wxButtonImpl
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
wxMacBitmapButton(wxWindowMac* peer, const wxBitmap& bitmap, int style)
|
wxMacBitmapButton(wxWindowMac* peer, const wxBitmap& bitmap, int style)
|
||||||
|
@@ -9,69 +9,4 @@
|
|||||||
// Licence: wxWindows licence
|
// Licence: wxWindows licence
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#include "wx/wxprec.h"
|
// everything is done in button.mm now
|
||||||
|
|
||||||
#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
|
|
@@ -97,7 +97,7 @@ wxSize wxButton::GetDefaultSize()
|
|||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
|
|
||||||
class wxButtonCocoaImpl : public wxWidgetCocoaImpl
|
class wxButtonCocoaImpl : public wxWidgetCocoaImpl, public wxButtonImpl
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
wxButtonCocoaImpl(wxWindowMac *wxpeer, wxNSButton *v)
|
wxButtonCocoaImpl(wxWindowMac *wxpeer, wxNSButton *v)
|
||||||
@@ -107,12 +107,20 @@ public:
|
|||||||
|
|
||||||
virtual void SetBitmap(const wxBitmap& bitmap)
|
virtual void SetBitmap(const wxBitmap& bitmap)
|
||||||
{
|
{
|
||||||
[GetNSButton() setBezelStyle:bitmap.IsOk() ? NSRegularSquareBezelStyle
|
// switch bezel style for plain pushbuttons
|
||||||
: NSRoundedBezelStyle];
|
if ( bitmap.IsOk() && [GetNSButton() bezelStyle] == NSRoundedBezelStyle )
|
||||||
|
[GetNSButton() setBezelStyle:NSRegularSquareBezelStyle ];
|
||||||
|
|
||||||
wxWidgetCocoaImpl::SetBitmap(bitmap);
|
wxWidgetCocoaImpl::SetBitmap(bitmap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SetPressedBitmap( const wxBitmap& bitmap )
|
||||||
|
{
|
||||||
|
NSButton* button = GetNSButton();
|
||||||
|
[button setAlternateImage: bitmap.GetNSImage()];
|
||||||
|
[button setButtonType:NSMomentaryChangeButton];
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
NSButton *GetNSButton() const
|
NSButton *GetNSButton() const
|
||||||
{
|
{
|
||||||
@@ -163,6 +171,47 @@ void wxWidgetCocoaImpl::PerformClick()
|
|||||||
[(NSControl*)m_osxView performClick:nil];
|
[(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
|
// wxDisclosureButton implementation
|
||||||
//
|
//
|
||||||
|
Reference in New Issue
Block a user