diff --git a/include/wx/generic/collpaneg.h b/include/wx/generic/collpaneg.h index 515e195ceb..c0e9365eb5 100644 --- a/include/wx/generic/collpaneg.h +++ b/include/wx/generic/collpaneg.h @@ -14,9 +14,6 @@ // forward declared class WXDLLIMPEXP_FWD_CORE wxCollapsibleHeaderCtrl; class WXDLLIMPEXP_FWD_CORE wxStaticLine; -#if defined( __WXMAC__ ) && !defined(__WXUNIVERSAL__) -class WXDLLIMPEXP_FWD_CORE wxDisclosureTriangle; -#endif #include "wx/containr.h" @@ -82,11 +79,7 @@ protected: int GetBorder() const; // child controls -#if defined( __WXMAC__ ) && !defined(__WXUNIVERSAL__) - wxDisclosureTriangle *m_pButton; -#else wxCollapsibleHeaderCtrl *m_pButton; -#endif wxStaticLine *m_pStaticLine; wxWindow *m_pPane; wxSizer *m_sz; diff --git a/include/wx/osx/button.h b/include/wx/osx/button.h index a845513197..5726b211b9 100644 --- a/include/wx/osx/button.h +++ b/include/wx/osx/button.h @@ -56,40 +56,4 @@ protected: wxDECLARE_DYNAMIC_CLASS(wxButton); }; -// OS X specific class, not part of public wx API -class WXDLLIMPEXP_CORE wxDisclosureTriangle : public wxControl -{ -public: - wxDisclosureTriangle(wxWindow *parent, - wxWindowID id, - const wxString& label = wxEmptyString, - const wxPoint& pos = wxDefaultPosition, - const wxSize& size = wxDefaultSize, - long style = wxBORDER_NONE, - const wxValidator& validator = wxDefaultValidator, - const wxString& name = wxButtonNameStr) - { - Create(parent, id, label, pos, size, style, validator, name); - } - - bool Create(wxWindow *parent, - wxWindowID id, - const wxString& label = wxEmptyString, - const wxPoint& pos = wxDefaultPosition, - const wxSize& size = wxDefaultSize, - long style = wxBORDER_NONE, - const wxValidator& validator = wxDefaultValidator, - const wxString& name = wxButtonNameStr); - - void SetOpen( bool open ); - bool IsOpen() const; - - // osx specific event handling common for all osx-ports - - virtual bool OSXHandleClicked( double timestampsec ); - -protected: - virtual wxSize DoGetBestSize() const ; -}; - #endif // _WX_OSX_BUTTON_H_ diff --git a/src/generic/collpaneg.cpp b/src/generic/collpaneg.cpp index b58e4722af..ce91488e67 100644 --- a/src/generic/collpaneg.cpp +++ b/src/generic/collpaneg.cpp @@ -81,20 +81,16 @@ bool wxGenericCollapsiblePane::Create(wxWindow *parent, // sizer containing the expand button and possibly a static line m_sz = new wxBoxSizer(wxVERTICAL); -#if defined( __WXMAC__ ) && !defined(__WXUNIVERSAL__) - // on Mac we use the special disclosure triangle button - m_pStaticLine = NULL; - m_pButton = new wxDisclosureTriangle(this, wxID_ANY, label); - m_sz->Add(m_pButton); -#else // create children and lay them out using a wxBoxSizer // (so that we automatically get RTL features) m_pButton = new wxCollapsibleHeaderCtrl(this, wxID_ANY, label, wxPoint(0, 0), wxDefaultSize); - m_pStaticLine = new wxStaticLine(this, wxID_ANY); // on other platforms we put the static line and the button horizontally m_sz->Add(m_pButton, 0, wxLEFT|wxTOP|wxBOTTOM, GetBorder()); + +#if !defined( __WXMAC__ ) || defined(__WXUNIVERSAL__) + m_pStaticLine = new wxStaticLine(this, wxID_ANY); m_sz->Add(m_pStaticLine, 0, wxEXPAND, GetBorder()); m_pStaticLine->Hide(); #endif @@ -183,14 +179,11 @@ void wxGenericCollapsiblePane::Collapse(bool collapse) // update our state m_pPane->Show(!collapse); - // update button label -#if defined( __WXMAC__ ) && !defined(__WXUNIVERSAL__) - m_pButton->SetOpen( !collapse ); -#else + // update button // NB: this must be done after updating our "state" m_pButton->SetCollapsed(collapse); - m_pStaticLine->Show(!collapse); -#endif + if ( m_pStaticLine ) + m_pStaticLine->Show(!collapse); OnStateChange(GetBestSize()); @@ -198,12 +191,8 @@ void wxGenericCollapsiblePane::Collapse(bool collapse) void wxGenericCollapsiblePane::SetLabel(const wxString &label) { -#ifdef __WXMAC__ - m_pButton->SetLabel(label); -#else m_pButton->SetLabel(label); m_pButton->SetInitialSize(); -#endif Layout(); } diff --git a/src/osx/button_osx.cpp b/src/osx/button_osx.cpp index e604d21483..4ca954edeb 100644 --- a/src/osx/button_osx.cpp +++ b/src/osx/button_osx.cpp @@ -138,57 +138,3 @@ wxSize wxButtonBase::GetDefaultSize() { return wxAnyButton::GetDefaultSize(); } - -//------------------------------------------------------- -// wxDisclosureTriangle -//------------------------------------------------------- - -bool wxDisclosureTriangle::Create(wxWindow *parent, wxWindowID id, const wxString& label, - const wxPoint& pos, const wxSize& size, long style,const wxValidator& validator, const wxString& name ) -{ - DontCreatePeer(); - if ( !wxControl::Create(parent, id, pos, size, style, validator, name) ) - return false; - - SetPeer(wxWidgetImpl::CreateDisclosureTriangle(this, parent, id, label, pos, size, style, GetExtraStyle() )); - - MacPostControlCreate( pos, size ); - // passing the text in the param doesn't seem to work, so let's do it again - SetLabel( label ); - - return true; -} - -void wxDisclosureTriangle::SetOpen( bool open ) -{ - GetPeer()->SetValue( open ? 1 : 0 ); -} - -bool wxDisclosureTriangle::IsOpen() const -{ - return GetPeer()->GetValue() == 1; -} - -bool wxDisclosureTriangle::OSXHandleClicked( double WXUNUSED(timestampsec) ) -{ - // Just emit button event for now - wxCommandEvent event(wxEVT_BUTTON, m_windowId); - event.SetEventObject(this); - ProcessCommand(event); - - return true; -} - -wxSize wxDisclosureTriangle::DoGetBestSize() const -{ - wxSize size = wxWindow::DoGetBestSize(); - - // under Carbon the base class GetBestSize() implementation doesn't seem to - // take the label into account at all, correct for it here -#if wxOSX_USE_CARBON - size.x += GetTextExtent(GetLabel()).x; -#endif // wxOSX_USE_CARBON - - return size; -} - diff --git a/src/osx/cocoa/button.mm b/src/osx/cocoa/button.mm index 0d28e306cc..a0cfe24a6c 100644 --- a/src/osx/cocoa/button.mm +++ b/src/osx/cocoa/button.mm @@ -361,155 +361,3 @@ wxWidgetImplType* wxWidgetImpl::CreateBitmapButton( wxWindowMac* wxpeer, } #endif // wxUSE_BMPBUTTON - -// -// wxDisclosureButton implementation -// - -@interface wxDisclosureNSButton : NSButton -{ - - BOOL isOpen; -} - -- (void) updateImage; - -- (void) toggle; - -+ (NSImage *)rotateImage: (NSImage *)image; - -@end - -static const char * disc_triangle_xpm[] = { -"10 9 4 1", -" c None", -". c #737373", -"+ c #989898", -"- c #c6c6c6", -" .- ", -" ..+- ", -" ....+ ", -" ......- ", -" .......- ", -" ......- ", -" ....+ ", -" ..+- ", -" .- ", -}; - -@implementation wxDisclosureNSButton - -+ (void)initialize -{ - static BOOL initialized = NO; - if (!initialized) - { - initialized = YES; - wxOSXCocoaClassAddWXMethods( self ); - } -} - -- (id) initWithFrame:(NSRect) frame -{ - self = [super initWithFrame:frame]; - isOpen = NO; - [self setImagePosition:NSImageLeft]; - [self updateImage]; - return self; -} - -- (int) intValue -{ - return isOpen ? 1 : 0; -} - -- (void) setIntValue: (int) v -{ - isOpen = ( v != 0 ); - [self updateImage]; -} - -- (void) toggle -{ - isOpen = !isOpen; - [self updateImage]; -} - -wxCFRef downArray ; - -- (void) updateImage -{ - static wxBitmap trianglebm(disc_triangle_xpm); - if ( downArray.get() == NULL ) - { - downArray.reset( [[wxDisclosureNSButton rotateImage:trianglebm.GetNSImage()] retain] ); - } - - if ( isOpen ) - [self setImage:(NSImage*)downArray.get()]; - else - [self setImage:trianglebm.GetNSImage()]; -} - -+ (NSImage *)rotateImage: (NSImage *)image -{ - NSSize imageSize = [image size]; - NSSize newImageSize = NSMakeSize(imageSize.height, imageSize.width); - NSImage* newImage = [[NSImage alloc] initWithSize: newImageSize]; - - [newImage lockFocus]; - - NSAffineTransform* tm = [NSAffineTransform transform]; - [tm translateXBy:newImageSize.width/2 yBy:newImageSize.height/2]; - [tm rotateByDegrees:-90]; - [tm translateXBy:-newImageSize.width/2 yBy:-newImageSize.height/2]; - [tm concat]; - - - [image drawInRect:NSMakeRect(0,0,newImageSize.width, newImageSize.height) - fromRect:NSZeroRect operation:NSCompositeCopy fraction:1.0]; - - [newImage unlockFocus]; - return [newImage autorelease]; -} - -@end - -class wxDisclosureTriangleCocoaImpl : public wxWidgetCocoaImpl -{ -public : - wxDisclosureTriangleCocoaImpl(wxWindowMac* peer , WXWidget w) : - wxWidgetCocoaImpl(peer, w) - { - } - - ~wxDisclosureTriangleCocoaImpl() - { - } - - virtual void controlAction(WXWidget slf, void* _cmd, void *sender) wxOVERRIDE - { - wxDisclosureNSButton* db = (wxDisclosureNSButton*)m_osxView; - [db toggle]; - wxWidgetCocoaImpl::controlAction(slf, _cmd, sender ); - } -}; - -wxWidgetImplType* wxWidgetImpl::CreateDisclosureTriangle( wxWindowMac* wxpeer, - wxWindowMac* WXUNUSED(parent), - wxWindowID winid, - const wxString& label, - const wxPoint& pos, - const wxSize& size, - long style, - long WXUNUSED(extraStyle)) -{ - NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ; - wxDisclosureNSButton* v = [[wxDisclosureNSButton alloc] initWithFrame:r]; - if ( !label.empty() ) - [v setTitle:wxCFStringRef(label).AsNSString()]; - - SetBezelStyleFromBorderFlags(v, style, winid, label); - - return new wxDisclosureTriangleCocoaImpl( wxpeer, v ); -}