X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/423939b29aab373e5da156c857265d7a5604f613..c37dd6dad7f53b8f5f4c4a8d6434c2851cd2b9e4:/src/osx/cocoa/button.mm diff --git a/src/osx/cocoa/button.mm b/src/osx/cocoa/button.mm index 97fd9450ca..9efc79667e 100644 --- a/src/osx/cocoa/button.mm +++ b/src/osx/cocoa/button.mm @@ -166,13 +166,13 @@ wxSize wxButton::GetDefaultSize() wxWidgetImplType* wxWidgetImpl::CreateButton( wxWindowMac* wxpeer, - wxWindowMac* parent, + wxWindowMac* WXUNUSED(parent), wxWindowID id, - const wxString& label, + const wxString& WXUNUSED(label), const wxPoint& pos, const wxSize& size, - long style, - long extraStyle) + long WXUNUSED(style), + long WXUNUSED(extraStyle)) { NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ; wxNSButton* v = [[wxNSButton alloc] initWithFrame:r]; @@ -252,21 +252,152 @@ void wxWidgetCocoaImpl::PerformClick() { } +// +// 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]; + [self setBezelStyle:NSSmallSquareBezelStyle]; + 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()] ); + } + + 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; +} + +@end + +class wxDisclosureTriangleCocoaImpl : public wxWidgetCocoaImpl +{ +public : + wxDisclosureTriangleCocoaImpl(wxWindowMac* peer , WXWidget w) : + wxWidgetCocoaImpl(peer, w) + { + } + + ~wxDisclosureTriangleCocoaImpl() + { + } + + virtual void controlAction(WXWidget slf, void* _cmd, void *sender) + { + wxDisclosureNSButton* db = (wxDisclosureNSButton*)m_osxView; + [db toggle]; + wxWidgetCocoaImpl::controlAction(slf, _cmd, sender ); + } +}; + wxWidgetImplType* wxWidgetImpl::CreateDisclosureTriangle( wxWindowMac* wxpeer, - wxWindowMac* parent, - wxWindowID id, + wxWindowMac* WXUNUSED(parent), + wxWindowID WXUNUSED(id), const wxString& label, const wxPoint& pos, const wxSize& size, - long style, - long extraStyle) + long WXUNUSED(style), + long WXUNUSED(extraStyle)) { NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ; - wxNSButton* v = [[wxNSButton alloc] initWithFrame:r]; - [v setBezelStyle:NSDisclosureBezelStyle]; - [v setButtonType:NSOnOffButton]; + wxDisclosureNSButton* v = [[wxDisclosureNSButton alloc] initWithFrame:r]; [v setTitle:wxCFStringRef( label).AsNSString()]; - [v setImagePosition:NSImageRight]; - wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v ); + wxDisclosureTriangleCocoaImpl* c = new wxDisclosureTriangleCocoaImpl( wxpeer, v ); return c; }