From a8634fc36167c2a65c9216b175d2abc960127df8 Mon Sep 17 00:00:00 2001 From: David Elliott Date: Fri, 20 Jul 2007 22:11:16 +0000 Subject: [PATCH] wxCocoa: Implement wxControl::GetLabel/SetLabel by stowing the label in the wxNonControlNSControl instance used when the wxControl is a non-native subclass (e.g. a generic control). Not needed in trunk since there is now m_labelOrig. Copyright 2007 Software 2000 Ltd. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_8_BRANCH@47603 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/cocoa/control.h | 3 +++ src/cocoa/control.mm | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/include/wx/cocoa/control.h b/include/wx/cocoa/control.h index ce13947692..99a2db572e 100644 --- a/include/wx/cocoa/control.h +++ b/include/wx/cocoa/control.h @@ -61,6 +61,9 @@ public: // Enables the control virtual void CocoaSetEnabled(bool enable); + + wxString GetLabel() const; + void SetLabel(const wxString& label); protected: virtual wxSize DoGetBestSize() const; }; diff --git a/src/cocoa/control.mm b/src/cocoa/control.mm index 7fbca38027..2392fb3a7a 100644 --- a/src/cocoa/control.mm +++ b/src/cocoa/control.mm @@ -17,6 +17,7 @@ #include "wx/log.h" #endif +#include "wx/cocoa/string.h" #include "wx/cocoa/autorelease.h" #include "wx/cocoa/objc/objc_uniquifying.h" @@ -30,6 +31,7 @@ { } +- (id)initWithFrame: (NSRect)frameRect; - (void)drawRect: (NSRect)rect; - (void)mouseDown:(NSEvent *)theEvent; - (void)mouseDragged:(NSEvent *)theEvent; @@ -49,6 +51,19 @@ WX_DECLARE_GET_OBJC_CLASS(wxNonControlNSControl,NSControl) @implementation wxNonControlNSControl : NSControl +- (id)initWithFrame: (NSRect)frameRect +{ + if( (self = [super initWithFrame:frameRect]) == nil) + return nil; + // NSControl by default has no cell as it is semi-abstract. + // Provide a normal NSCell for the sole purpose of making + // setStringValue/stringValue work for labels in 2.8. + NSCell *newCell = [[NSCell alloc] initTextCell:@""]; + [self setCell:newCell]; + [newCell release]; + return self; +} + - (BOOL)acceptsFirstMouse:(NSEvent *)theEvent { bool acceptsFirstMouse = false; @@ -233,3 +248,25 @@ void wxControl::CocoaSetEnabled(bool enable) { [GetNSControl() setEnabled: enable]; } + +wxString wxControl::GetLabel() const +{ + if([GetNSControl() isKindOfClass:[WX_GET_OBJC_CLASS(wxNonControlNSControl) class]]) + { + return wxStringWithNSString([GetNSControl() stringValue]); + } + else + return wxControlBase::GetLabel(); +} + +void wxControl::SetLabel(const wxString& label) +{ + wxControlBase::SetLabel(label); + // wx 2.8 hack: we need somewhere to stuff the label for + // platform-independent subclasses of wxControl. + if([GetNSControl() isKindOfClass:[WX_GET_OBJC_CLASS(wxNonControlNSControl) class]]) + { + [GetNSControl() setStringValue:wxNSStringWithWxString(label)]; + } +} +