]> git.saurik.com Git - wxWidgets.git/commitdiff
Implement wxCocoa wxRadioBox event.
authorDavid Elliott <dfe@tgwbd.org>
Thu, 19 Jul 2007 18:52:12 +0000 (18:52 +0000)
committerDavid Elliott <dfe@tgwbd.org>
Thu, 19 Jul 2007 18:52:12 +0000 (18:52 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@47569 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/cocoa/radiobox.h
src/cocoa/radiobox.mm

index d775800331da5f81ff5f88759dc7cbd97ba529ce..e1928c22eb77f0bfe7bb27d9c68521f9a273a2e0 100644 (file)
@@ -22,6 +22,8 @@ class WXDLLEXPORT wxRadioBox: public wxControl, public wxRadioBoxBase// , protec
 {
     DECLARE_DYNAMIC_CLASS(wxRadioBox)
     DECLARE_EVENT_TABLE()
+    // NOTE: We explicitly skip NSControl because our primary cocoa view is
+    // the NSBox but we want to receive action messages from the NSMatrix.
     WX_DECLARE_COCOA_OWNER(NSBox,NSView,NSView)
 // ------------------------------------------------------------------------
 // initialization
@@ -93,6 +95,7 @@ public:
 protected:
     // Static boxes cannot be enabled/disabled
     virtual void CocoaSetEnabled(bool enable) { }
+    virtual void CocoaTarget_action(void);
 // ------------------------------------------------------------------------
 // Implementation
 // ------------------------------------------------------------------------
@@ -107,7 +110,12 @@ public:
     virtual void SetString(unsigned int n, const wxString& label);
     // change the individual radio button state
 protected:
+    // We don't want the typical wxCocoaNSBox behavior because our real
+    // implementation is by using an NSMatrix as the NSBox's contentView.
     WX_NSMatrix GetNSMatrix() const;
+    void AssociateNSBox(WX_NSBox theBox);
+    void DisassociateNSBox(WX_NSBox theBox);
+
     virtual wxSize DoGetBestSize() const;
 
     int GetRowForIndex(int n) const
index 2eacb188f99482a17e67a5f9db3ddf52df16fa5c..4319dcfb387ebc5d01ffea231f3744f46b66993d 100644 (file)
 IMPLEMENT_DYNAMIC_CLASS(wxRadioBox, wxControl)
 BEGIN_EVENT_TABLE(wxRadioBox, wxControl)
 END_EVENT_TABLE()
-// WX_IMPLEMENT_COCOA_OWNER(wxRadioBox,NSTextField,NSControl,NSView)
+
+void wxRadioBox::AssociateNSBox(WX_NSBox cocoaObjcClass)
+{
+    NSMatrix *radioBox = [(WX_NSBox)cocoaObjcClass contentView];
+    // Associate the NSMatrix (the NSBox's contentView) with the wxCocoaNSControl MI base class.
+    AssociateNSControl(radioBox);
+    // Set the target/action.. we don't really need to unset these
+    [radioBox setTarget:wxCocoaNSControl::sm_cocoaTarget];
+    [radioBox setAction:@selector(wxNSControlAction:)];
+}
+
+void wxRadioBox::DisassociateNSBox(WX_NSBox cocoaObjcClass)
+{
+    DisassociateNSControl([(WX_NSBox)cocoaObjcClass contentView]);
+}
+
+WX_IMPLEMENT_COCOA_OWNER(wxRadioBox,NSBox,NSView,NSView)
 
 bool wxRadioBox::Create(wxWindow *parent, wxWindowID winid,
             const wxString& title,
@@ -134,14 +150,17 @@ bool wxRadioBox::Create(wxWindow *parent, wxWindowID winid,
             withObject:[allCells subarrayWithRange:NSMakeRange(i*majorDim, majorDim)]];
     }
 
-    //make and set up an NSBox (TODO: Just derive from wxStaticBox)
-    SetNSView([[NSBox alloc] initWithFrame:MakeDefaultNSRect(size)]);
-    [m_cocoaNSView release];
+    NSBox *theBox = [[NSBox alloc] initWithFrame:MakeDefaultNSRect(size)];
 
     // Replace the box's content view with the NSMatrix we just created
-    [GetNSBox() setContentView:radioBox];
+    // IMPORTANT: This must be done before calling SetNSBox.
+    [theBox setContentView:radioBox];
     [radioBox release]; // The NSBox retains it for us.
 
+    SetNSBox(theBox);
+    [theBox release];
+
+
     [GetNSBox() setTitle:wxNSStringWithWxString(wxStripMenuCodes(title, wxStrip_Mnemonics))];
 //    [GetNSBox() setBorderType:NSLineBorder]; // why??
 
@@ -159,6 +178,7 @@ bool wxRadioBox::Create(wxWindow *parent, wxWindowID winid,
 
 wxRadioBox::~wxRadioBox()
 {
+    DisassociateNSBox(GetNSBox());
 }
 
 WX_NSMatrix wxRadioBox::GetNSMatrix() const
@@ -240,4 +260,12 @@ wxSize wxRadioBox::DoGetBestSize() const
     return wxControl::DoGetBestSize();
 }
 
+void wxRadioBox::CocoaTarget_action(void)
+{
+    wxCommandEvent event(wxEVT_COMMAND_RADIOBOX_SELECTED, GetId());
+    InitCommandEvent(event);
+    event.SetInt(GetSelection()); // i.e. SetSelection.
+    Command(event);
+}
+
 #endif