From 9ed97552373524bb54b71cd967b2df135e81ee51 Mon Sep 17 00:00:00 2001 From: David Elliott Date: Tue, 17 Jul 2007 05:41:35 +0000 Subject: [PATCH] Partially implement wxRadioBox for wxCocoa. Copyright 2007 Software 2000 Ltd. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@47523 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/cocoa/radiobox.h | 4 +- src/cocoa/radiobox.mm | 116 ++++++++++++++++++++++++++++++++++-- 2 files changed, 115 insertions(+), 5 deletions(-) diff --git a/include/wx/cocoa/radiobox.h b/include/wx/cocoa/radiobox.h index d2712281b5..e628f593df 100644 --- a/include/wx/cocoa/radiobox.h +++ b/include/wx/cocoa/radiobox.h @@ -13,6 +13,7 @@ #define __WX_COCOA_RADIOBOX_H__ // #include "wx/cocoa/NSButton.h" +DECLARE_WXCOCOA_OBJC_CLASS(NSMatrix); // ======================================================================== // wxRadioBox @@ -21,7 +22,7 @@ class WXDLLEXPORT wxRadioBox: public wxControl, public wxRadioBoxBase// , protec { DECLARE_DYNAMIC_CLASS(wxRadioBox) DECLARE_EVENT_TABLE() -// WX_DECLARE_COCOA_OWNER(NSButton,NSControl,NSView) + WX_DECLARE_COCOA_OWNER(NSBox,NSView,NSView) // ------------------------------------------------------------------------ // initialization // ------------------------------------------------------------------------ @@ -106,6 +107,7 @@ public: virtual void SetString(unsigned int n, const wxString& label); // change the individual radio button state protected: + WX_NSMatrix GetNSMatrix() const; virtual wxSize DoGetBestSize() const; }; diff --git a/src/cocoa/radiobox.mm b/src/cocoa/radiobox.mm index 8cf200fb4d..c67639ccf1 100644 --- a/src/cocoa/radiobox.mm +++ b/src/cocoa/radiobox.mm @@ -6,6 +6,7 @@ // Created: 2003/02/15 // RCS-ID: $Id$ // Copyright: (c) 2003 David Elliott +// (c) 2007 Software 2000 Ltd. // Licence: wxWidgets licence ///////////////////////////////////////////////////////////////////////////// @@ -20,7 +21,13 @@ #include "wx/arrstr.h" #endif //WX_PRECOMP +#include "wx/cocoa/string.h" +#include "wx/cocoa/autorelease.h" + #include "wx/cocoa/objc/NSView.h" +#import +#import +#import IMPLEMENT_DYNAMIC_CLASS(wxRadioBox, wxControl) BEGIN_EVENT_TABLE(wxRadioBox, wxControl) @@ -51,13 +58,102 @@ bool wxRadioBox::Create(wxWindow *parent, wxWindowID winid, long style, const wxValidator& validator, const wxString& name) { + // We autorelease heavily so we want our own pool + wxAutoNSAutoreleasePool pool; + if(!CreateControl(parent,winid,pos,size,style,validator,name)) return false; - SetNSView([[WX_GET_OBJC_CLASS(WXNSView) alloc] initWithFrame: MakeDefaultNSRect(size)]); + + majorDim = majorDim == 0 ? n : majorDim; + // TODO: Don't forget to call SetMajorDim + // We can't yet as we can't implement GetCount() until after + // we make the NSMatrix. + int minorDim = (n + majorDim - 1) / majorDim; + + + // Create a prototype cell for use with the NSMatrix build + NSCell *currCell = [[NSButtonCell alloc] initTextCell:@""]; + [(NSButtonCell*)currCell setButtonType:NSRadioButton]; + + // Build up an array of all cells plus any extra empty cells + NSMutableArray *allCells = [NSMutableArray arrayWithCapacity:n]; + for(int i=0; iCocoaAddChild(this); - SetInitialFrameRect(pos,size); + + // Do the sizer dance + [GetNSBox() sizeToFit]; + SetInitialFrameRect(pos, size); return true; } @@ -66,6 +162,11 @@ wxRadioBox::~wxRadioBox() { } +WX_NSMatrix wxRadioBox::GetNSMatrix() const +{ + return (NSMatrix*)[(NSBox*)m_cocoaNSView contentView]; +} + // selection void wxRadioBox::SetSelection(int n) { @@ -79,7 +180,12 @@ int wxRadioBox::GetSelection() const // string access unsigned int wxRadioBox::GetCount() const { - return 0; + NSMatrix *radioBox = GetNSMatrix(); + NSInteger rowCount, columnCount; + [radioBox getNumberOfRows:&rowCount columns:&columnCount]; + + // FIXME: This is wrong if padding cells were made + return rowCount * columnCount; } wxString wxRadioBox::GetString(unsigned int n) const @@ -106,7 +212,9 @@ bool wxRadioBox::Show(unsigned int n, bool show) wxSize wxRadioBox::DoGetBestSize() const { - return wxSize(50,50); + // The NSBox responds to sizeToFit by sending sizeToFit to its contentView + // which is the NSMatrix and does the right thing. + return wxControl::DoGetBestSize(); } #endif -- 2.45.2