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é).
// 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() {}
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,
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_
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;
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;
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;
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
@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
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();
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
@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),
}
[v setButtonType:NSMomentaryPushInButton];
- wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v );
- return c;
+ return new wxButtonCocoaImpl( wxpeer, v );
}
void wxWidgetCocoaImpl::SetDefaultButton( bool isDefault )
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:)] )
}
}
+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