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:
parent
b727fcd3ad
commit
e5d05b907c
@ -349,6 +349,7 @@ All:
|
||||
|
||||
All (GUI):
|
||||
|
||||
- Added support for showing bitmaps in wxButton.
|
||||
- wxWindow::SetAutoLayout() now works for all windows, not just panels.
|
||||
- Support wxListCtrl columns, items and image lists in XRC (Kinaou Hervé).
|
||||
- Added support for wxFileCtrl to XRC (Kinaou Hervé).
|
||||
|
@ -9,16 +9,14 @@
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _WX_BUTTON_H_
|
||||
#define _WX_BUTTON_H_
|
||||
#ifndef _WX_OSX_BUTTON_H_
|
||||
#define _WX_OSX_BUTTON_H_
|
||||
|
||||
#include "wx/control.h"
|
||||
#include "wx/gdicmn.h"
|
||||
|
||||
WXDLLIMPEXP_DATA_CORE(extern const char) wxButtonNameStr[];
|
||||
|
||||
// Pushbutton
|
||||
class WXDLLIMPEXP_CORE wxButton: public wxButtonBase
|
||||
class WXDLLIMPEXP_CORE wxButton : public wxButtonBase
|
||||
{
|
||||
public:
|
||||
wxButton() {}
|
||||
@ -50,16 +48,23 @@ public:
|
||||
virtual void Command(wxCommandEvent& event);
|
||||
|
||||
// osx specific event handling common for all osx-ports
|
||||
|
||||
|
||||
virtual bool OSXHandleClicked( double timestampsec );
|
||||
|
||||
protected:
|
||||
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)
|
||||
};
|
||||
|
||||
class WXDLLIMPEXP_CORE wxDisclosureTriangle: public wxControl
|
||||
// OS X specific class, not part of public wx API
|
||||
class WXDLLIMPEXP_CORE wxDisclosureTriangle : public wxControl
|
||||
{
|
||||
public:
|
||||
wxDisclosureTriangle(wxWindow *parent,
|
||||
@ -87,13 +92,12 @@ public:
|
||||
bool IsOpen() const;
|
||||
|
||||
// osx specific event handling common for all osx-ports
|
||||
|
||||
|
||||
virtual bool OSXHandleClicked( double timestampsec );
|
||||
|
||||
protected:
|
||||
virtual wxSize DoGetBestSize() const ;
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
// _WX_BUTTON_H_
|
||||
#endif // _WX_OSX_BUTTON_H_
|
||||
|
@ -335,7 +335,9 @@ public :
|
||||
|
||||
wxInt32 GetValue() const;
|
||||
void SetValue( wxInt32 v );
|
||||
wxBitmap GetBitmap() const;
|
||||
void SetBitmap( const wxBitmap& bitmap );
|
||||
void SetBitmapPosition( wxDirection dir );
|
||||
void SetupTabs( const wxNotebook ¬ebook );
|
||||
|
||||
void GetBestRect( wxRect *r ) const;
|
||||
|
@ -106,7 +106,9 @@ public :
|
||||
|
||||
wxInt32 GetValue() const;
|
||||
void SetValue( wxInt32 v );
|
||||
wxBitmap GetBitmap() const;
|
||||
void SetBitmap( const wxBitmap& bitmap );
|
||||
void SetBitmapPosition( wxDirection dir );
|
||||
void SetupTabs( const wxNotebook ¬ebook );
|
||||
void GetBestRect( wxRect *r ) const;
|
||||
bool IsEnabled() const;
|
||||
|
@ -235,7 +235,9 @@ public :
|
||||
|
||||
virtual wxInt32 GetValue() const = 0;
|
||||
virtual void SetValue( wxInt32 v ) = 0;
|
||||
virtual wxBitmap GetBitmap() const = 0;
|
||||
virtual void SetBitmap( const wxBitmap& bitmap ) = 0;
|
||||
virtual void SetBitmapPosition( wxDirection dir ) = 0;
|
||||
virtual void SetupTabs( const wxNotebook ¬ebook ) =0;
|
||||
virtual void GetBestRect( wxRect *r ) const = 0;
|
||||
virtual bool IsEnabled() const = 0;
|
||||
|
@ -34,8 +34,8 @@
|
||||
bitmap but uses a standard id would display a label too.
|
||||
@style{wxBORDER_NONE}
|
||||
Creates a button without border. This is currently implemented in MSW,
|
||||
GTK2 and OSX ports but in the latter only applies to buttons with
|
||||
bitmaps and using bitmap of one of the standard sizes only, namely
|
||||
GTK2 and OSX/Carbon ports but in the latter only applies to buttons
|
||||
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
|
||||
ignored under OSX.
|
||||
@endStyleTable
|
||||
@ -54,14 +54,16 @@
|
||||
@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
|
||||
previous wxWidgets versions this functionality was only available in (the
|
||||
now trivial) wxBitmapButton class which was only capable of showing an
|
||||
image without text.
|
||||
|
||||
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 disabled: bitmap shown when the button is disabled.
|
||||
@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);
|
||||
}
|
||||
|
||||
// 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 *btnOldDefault = wxButtonBase::SetDefault();
|
||||
|
@ -1467,11 +1467,21 @@ wxMacControl* wxMacControl::GetReferenceFromNativeControl(ControlRef control)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
wxBitmap wxMacControl::GetBitmap() const
|
||||
{
|
||||
return wxNullBitmap;
|
||||
}
|
||||
|
||||
void wxMacControl::SetBitmap( const wxBitmap& WXUNUSED(bmp) )
|
||||
{
|
||||
// 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) )
|
||||
{
|
||||
// implemented in respective subclass
|
||||
|
@ -164,6 +164,35 @@ wxSize wxButton::GetDefaultSize()
|
||||
|
||||
@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,
|
||||
wxWindowMac* WXUNUSED(parent),
|
||||
@ -187,8 +216,7 @@ wxWidgetImplType* wxWidgetImpl::CreateButton( wxWindowMac* wxpeer,
|
||||
}
|
||||
|
||||
[v setButtonType:NSMomentaryPushInButton];
|
||||
wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v );
|
||||
return c;
|
||||
return new wxButtonCocoaImpl( wxpeer, v );
|
||||
}
|
||||
|
||||
void wxWidgetCocoaImpl::SetDefaultButton( bool isDefault )
|
||||
|
@ -1387,6 +1387,19 @@ wxInt32 wxWidgetCocoaImpl::GetMaximum() const
|
||||
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 )
|
||||
{
|
||||
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))
|
||||
{
|
||||
// implementation in subclass
|
||||
|
Loading…
Reference in New Issue
Block a user