added support for bitmaps in wxButton to wxOSX/Cocoa
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@61158 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -349,6 +349,7 @@ All:
|
|||||||
|
|
||||||
All (GUI):
|
All (GUI):
|
||||||
|
|
||||||
|
- Added support for showing bitmaps in wxButton.
|
||||||
- wxWindow::SetAutoLayout() now works for all windows, not just panels.
|
- wxWindow::SetAutoLayout() now works for all windows, not just panels.
|
||||||
- Support wxListCtrl columns, items and image lists in XRC (Kinaou Herv<72>).
|
- Support wxListCtrl columns, items and image lists in XRC (Kinaou Herv<72>).
|
||||||
- Added support for wxFileCtrl to XRC (Kinaou Herv<72>).
|
- Added support for wxFileCtrl to XRC (Kinaou Herv<72>).
|
||||||
|
@@ -9,16 +9,14 @@
|
|||||||
// Licence: wxWindows licence
|
// Licence: wxWindows licence
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#ifndef _WX_BUTTON_H_
|
#ifndef _WX_OSX_BUTTON_H_
|
||||||
#define _WX_BUTTON_H_
|
#define _WX_OSX_BUTTON_H_
|
||||||
|
|
||||||
#include "wx/control.h"
|
#include "wx/control.h"
|
||||||
#include "wx/gdicmn.h"
|
#include "wx/gdicmn.h"
|
||||||
|
|
||||||
WXDLLIMPEXP_DATA_CORE(extern const char) wxButtonNameStr[];
|
|
||||||
|
|
||||||
// Pushbutton
|
// Pushbutton
|
||||||
class WXDLLIMPEXP_CORE wxButton: public wxButtonBase
|
class WXDLLIMPEXP_CORE wxButton : public wxButtonBase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
wxButton() {}
|
wxButton() {}
|
||||||
@@ -50,16 +48,23 @@ public:
|
|||||||
virtual void Command(wxCommandEvent& event);
|
virtual void Command(wxCommandEvent& event);
|
||||||
|
|
||||||
// osx specific event handling common for all osx-ports
|
// osx specific event handling common for all osx-ports
|
||||||
|
|
||||||
virtual bool OSXHandleClicked( double timestampsec );
|
virtual bool OSXHandleClicked( double timestampsec );
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual wxSize DoGetBestSize() const ;
|
virtual wxSize DoGetBestSize() const ;
|
||||||
|
|
||||||
|
#if wxOSX_USE_COCOA
|
||||||
|
virtual wxBitmap DoGetBitmap(State which) const;
|
||||||
|
virtual void DoSetBitmap(const wxBitmap& bitmap, State which);
|
||||||
|
virtual void DoSetBitmapPosition(wxDirection dir);
|
||||||
|
#endif // wxOSX_USE_COCOA
|
||||||
|
|
||||||
DECLARE_DYNAMIC_CLASS(wxButton)
|
DECLARE_DYNAMIC_CLASS(wxButton)
|
||||||
};
|
};
|
||||||
|
|
||||||
class WXDLLIMPEXP_CORE wxDisclosureTriangle: public wxControl
|
// OS X specific class, not part of public wx API
|
||||||
|
class WXDLLIMPEXP_CORE wxDisclosureTriangle : public wxControl
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
wxDisclosureTriangle(wxWindow *parent,
|
wxDisclosureTriangle(wxWindow *parent,
|
||||||
@@ -87,13 +92,12 @@ public:
|
|||||||
bool IsOpen() const;
|
bool IsOpen() const;
|
||||||
|
|
||||||
// osx specific event handling common for all osx-ports
|
// osx specific event handling common for all osx-ports
|
||||||
|
|
||||||
virtual bool OSXHandleClicked( double timestampsec );
|
virtual bool OSXHandleClicked( double timestampsec );
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual wxSize DoGetBestSize() const ;
|
virtual wxSize DoGetBestSize() const ;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif // _WX_OSX_BUTTON_H_
|
||||||
// _WX_BUTTON_H_
|
|
||||||
|
@@ -335,7 +335,9 @@ public :
|
|||||||
|
|
||||||
wxInt32 GetValue() const;
|
wxInt32 GetValue() const;
|
||||||
void SetValue( wxInt32 v );
|
void SetValue( wxInt32 v );
|
||||||
|
wxBitmap GetBitmap() const;
|
||||||
void SetBitmap( const wxBitmap& bitmap );
|
void SetBitmap( const wxBitmap& bitmap );
|
||||||
|
void SetBitmapPosition( wxDirection dir );
|
||||||
void SetupTabs( const wxNotebook ¬ebook );
|
void SetupTabs( const wxNotebook ¬ebook );
|
||||||
|
|
||||||
void GetBestRect( wxRect *r ) const;
|
void GetBestRect( wxRect *r ) const;
|
||||||
|
@@ -106,7 +106,9 @@ public :
|
|||||||
|
|
||||||
wxInt32 GetValue() const;
|
wxInt32 GetValue() const;
|
||||||
void SetValue( wxInt32 v );
|
void SetValue( wxInt32 v );
|
||||||
|
wxBitmap GetBitmap() const;
|
||||||
void SetBitmap( const wxBitmap& bitmap );
|
void SetBitmap( const wxBitmap& bitmap );
|
||||||
|
void SetBitmapPosition( wxDirection dir );
|
||||||
void SetupTabs( const wxNotebook ¬ebook );
|
void SetupTabs( const wxNotebook ¬ebook );
|
||||||
void GetBestRect( wxRect *r ) const;
|
void GetBestRect( wxRect *r ) const;
|
||||||
bool IsEnabled() const;
|
bool IsEnabled() const;
|
||||||
|
@@ -235,7 +235,9 @@ public :
|
|||||||
|
|
||||||
virtual wxInt32 GetValue() const = 0;
|
virtual wxInt32 GetValue() const = 0;
|
||||||
virtual void SetValue( wxInt32 v ) = 0;
|
virtual void SetValue( wxInt32 v ) = 0;
|
||||||
|
virtual wxBitmap GetBitmap() const = 0;
|
||||||
virtual void SetBitmap( const wxBitmap& bitmap ) = 0;
|
virtual void SetBitmap( const wxBitmap& bitmap ) = 0;
|
||||||
|
virtual void SetBitmapPosition( wxDirection dir ) = 0;
|
||||||
virtual void SetupTabs( const wxNotebook ¬ebook ) =0;
|
virtual void SetupTabs( const wxNotebook ¬ebook ) =0;
|
||||||
virtual void GetBestRect( wxRect *r ) const = 0;
|
virtual void GetBestRect( wxRect *r ) const = 0;
|
||||||
virtual bool IsEnabled() const = 0;
|
virtual bool IsEnabled() const = 0;
|
||||||
|
@@ -34,8 +34,8 @@
|
|||||||
bitmap but uses a standard id would display a label too.
|
bitmap but uses a standard id would display a label too.
|
||||||
@style{wxBORDER_NONE}
|
@style{wxBORDER_NONE}
|
||||||
Creates a button without border. This is currently implemented in MSW,
|
Creates a button without border. This is currently implemented in MSW,
|
||||||
GTK2 and OSX ports but in the latter only applies to buttons with
|
GTK2 and OSX/Carbon ports but in the latter only applies to buttons
|
||||||
bitmaps and using bitmap of one of the standard sizes only, namely
|
with bitmaps and using bitmap of one of the standard sizes only, namely
|
||||||
128*128, 48*48, 24*24 or 16*16. In all the other cases wxBORDER_NONE is
|
128*128, 48*48, 24*24 or 16*16. In all the other cases wxBORDER_NONE is
|
||||||
ignored under OSX.
|
ignored under OSX.
|
||||||
@endStyleTable
|
@endStyleTable
|
||||||
@@ -54,14 +54,16 @@
|
|||||||
@endEventTable
|
@endEventTable
|
||||||
|
|
||||||
|
|
||||||
Since version 2.9.1 wxButton supports showing both text and an image, see
|
Since version 2.9.1 wxButton supports showing both text and an image
|
||||||
|
(currently only when using wxMSW, wxGTK or wxOSX/Cocoa ports), see
|
||||||
SetBitmap() and SetBitmapLabel(), SetBitmapDisabled() &c methods. In the
|
SetBitmap() and SetBitmapLabel(), SetBitmapDisabled() &c methods. In the
|
||||||
previous wxWidgets versions this functionality was only available in (the
|
previous wxWidgets versions this functionality was only available in (the
|
||||||
now trivial) wxBitmapButton class which was only capable of showing an
|
now trivial) wxBitmapButton class which was only capable of showing an
|
||||||
image without text.
|
image without text.
|
||||||
|
|
||||||
A button may have either a single image for all states or different images
|
A button may have either a single image for all states or different images
|
||||||
for the following states:
|
for the following states (different images are not currently supported
|
||||||
|
under OS X where the normal image is used for all states):
|
||||||
@li @b normal: the default state
|
@li @b normal: the default state
|
||||||
@li @b disabled: bitmap shown when the button is disabled.
|
@li @b disabled: bitmap shown when the button is disabled.
|
||||||
@li @b pressed: bitmap shown when the button is pushed (e.g. while the user
|
@li @b pressed: bitmap shown when the button is pushed (e.g. while the user
|
||||||
|
@@ -67,6 +67,28 @@ 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
|
||||||
|
{
|
||||||
|
return which == State_Normal ? m_peer->GetBitmap() : wxBitmap();
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxButton::DoSetBitmap(const wxBitmap& bitmap, State which)
|
||||||
|
{
|
||||||
|
if ( which == State_Normal )
|
||||||
|
m_peer->SetBitmap(bitmap);
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxButton::DoSetBitmapPosition(wxDirection dir)
|
||||||
|
{
|
||||||
|
m_peer->SetBitmapPosition(dir);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // wxOSX_USE_COCOA
|
||||||
|
|
||||||
wxWindow *wxButton::SetDefault()
|
wxWindow *wxButton::SetDefault()
|
||||||
{
|
{
|
||||||
wxWindow *btnOldDefault = wxButtonBase::SetDefault();
|
wxWindow *btnOldDefault = wxButtonBase::SetDefault();
|
||||||
|
@@ -1467,11 +1467,21 @@ wxMacControl* wxMacControl::GetReferenceFromNativeControl(ControlRef control)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wxBitmap wxMacControl::GetBitmap() const
|
||||||
|
{
|
||||||
|
return wxNullBitmap;
|
||||||
|
}
|
||||||
|
|
||||||
void wxMacControl::SetBitmap( const wxBitmap& WXUNUSED(bmp) )
|
void wxMacControl::SetBitmap( const wxBitmap& WXUNUSED(bmp) )
|
||||||
{
|
{
|
||||||
// implemented in the respective subclasses
|
// implemented in the respective subclasses
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void wxMacControl::SetBitmapPosition( wxDirection WXUNUSED(dir) )
|
||||||
|
{
|
||||||
|
// implemented in the same subclasses that implement SetBitmap()
|
||||||
|
}
|
||||||
|
|
||||||
void wxMacControl::SetScrollThumb( wxInt32 WXUNUSED(pos), wxInt32 WXUNUSED(viewsize) )
|
void wxMacControl::SetScrollThumb( wxInt32 WXUNUSED(pos), wxInt32 WXUNUSED(viewsize) )
|
||||||
{
|
{
|
||||||
// implemented in respective subclass
|
// implemented in respective subclass
|
||||||
|
@@ -164,6 +164,35 @@ wxSize wxButton::GetDefaultSize()
|
|||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
|
||||||
|
class wxButtonCocoaImpl : public wxWidgetCocoaImpl
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
wxButtonCocoaImpl(wxWindowMac *wxpeer, wxNSButton *v)
|
||||||
|
: wxWidgetCocoaImpl(wxpeer, v)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void SetBitmap(const wxBitmap& bitmap)
|
||||||
|
{
|
||||||
|
[GetNSButton() setBezelStyle:bitmap.IsOk() ? NSRegularSquareBezelStyle
|
||||||
|
: NSRoundedBezelStyle];
|
||||||
|
|
||||||
|
wxWidgetCocoaImpl::SetBitmap(bitmap);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
NSButton *GetNSButton() const
|
||||||
|
{
|
||||||
|
wxASSERT( [m_osxView isKindOfClass:[NSButton class]] );
|
||||||
|
|
||||||
|
return static_cast<NSButton *>(m_osxView);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
} // anonymous namespace
|
||||||
|
|
||||||
wxWidgetImplType* wxWidgetImpl::CreateButton( wxWindowMac* wxpeer,
|
wxWidgetImplType* wxWidgetImpl::CreateButton( wxWindowMac* wxpeer,
|
||||||
wxWindowMac* WXUNUSED(parent),
|
wxWindowMac* WXUNUSED(parent),
|
||||||
@@ -187,8 +216,7 @@ wxWidgetImplType* wxWidgetImpl::CreateButton( wxWindowMac* wxpeer,
|
|||||||
}
|
}
|
||||||
|
|
||||||
[v setButtonType:NSMomentaryPushInButton];
|
[v setButtonType:NSMomentaryPushInButton];
|
||||||
wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v );
|
return new wxButtonCocoaImpl( wxpeer, v );
|
||||||
return c;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxWidgetCocoaImpl::SetDefaultButton( bool isDefault )
|
void wxWidgetCocoaImpl::SetDefaultButton( bool isDefault )
|
||||||
|
@@ -1387,6 +1387,19 @@ wxInt32 wxWidgetCocoaImpl::GetMaximum() const
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wxBitmap wxWidgetCocoaImpl::GetBitmap() const
|
||||||
|
{
|
||||||
|
wxBitmap bmp;
|
||||||
|
|
||||||
|
// TODO: how to create a wxBitmap from NSImage?
|
||||||
|
#if 0
|
||||||
|
if ( [m_osxView respondsToSelector:@selector(image:)] )
|
||||||
|
bmp = [m_osxView image];
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return bmp;
|
||||||
|
}
|
||||||
|
|
||||||
void wxWidgetCocoaImpl::SetBitmap( const wxBitmap& bitmap )
|
void wxWidgetCocoaImpl::SetBitmap( const wxBitmap& bitmap )
|
||||||
{
|
{
|
||||||
if ( [m_osxView respondsToSelector:@selector(setImage:)] )
|
if ( [m_osxView respondsToSelector:@selector(setImage:)] )
|
||||||
@@ -1395,6 +1408,38 @@ void wxWidgetCocoaImpl::SetBitmap( const wxBitmap& bitmap )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void wxWidgetCocoaImpl::SetBitmapPosition( wxDirection dir )
|
||||||
|
{
|
||||||
|
if ( [m_osxView respondsToSelector:@selector(setImagePosition:)] )
|
||||||
|
{
|
||||||
|
NSCellImagePosition pos;
|
||||||
|
switch ( dir )
|
||||||
|
{
|
||||||
|
case wxLEFT:
|
||||||
|
pos = NSImageLeft;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case wxRIGHT:
|
||||||
|
pos = NSImageRight;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case wxTOP:
|
||||||
|
pos = NSImageAbove;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case wxBOTTOM:
|
||||||
|
pos = NSImageBelow;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
wxFAIL_MSG( "invalid image position" );
|
||||||
|
pos = NSNoImage;
|
||||||
|
}
|
||||||
|
|
||||||
|
[m_osxView setImagePosition:pos];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void wxWidgetCocoaImpl::SetupTabs( const wxNotebook& WXUNUSED(notebook))
|
void wxWidgetCocoaImpl::SetupTabs( const wxNotebook& WXUNUSED(notebook))
|
||||||
{
|
{
|
||||||
// implementation in subclass
|
// implementation in subclass
|
||||||
|
Reference in New Issue
Block a user