+
+ 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; i<n; ++i)
+ {
+ CocoaSetLabelForObject(choices[i], currCell);
+ [allCells addObject: currCell];
+ [currCell release];
+ // NOTE: We can still safely message currCell as the array has retained it.
+ currCell = [currCell copy];
+ }
+ [currCell release];
+
+ // NOTE: Although an image cell with no image is documented to return NSZeroSize from
+ // the cellSize method, the documentation is WRONG. It will actually return a huge size
+ // (thousands) which makes every cell in the matrix that big. Not good.
+ // Be safe and initialize a text cell with an empty string. That always works.
+ currCell = [[NSCell alloc] initTextCell:@""];
+ [currCell setEnabled:NO]; // Don't allow user to select this cell
+ for(int i=n; i < majorDim * minorDim; ++i)
+ {
+ [allCells addObject: currCell];
+ // NOTE: Use the same instance.. this should work and save some heap allocations.
+#if 0
+ [currCell release];
+ currCell = [currCell copy];
+#endif
+ }
+ [currCell release];
+ currCell = NULL;
+
+ // Although the documentation on addColumnWithCells:/addRowWithCells: explicitly
+ // states that it will determine the initial dimension upon the first call if
+ // the initial size is 0x0 it LIES. It will fail an assertion in the code
+ // if you use the simpler initWithFrame: initializer.
+ // Therefore, we specify the major dimension and leave the minor dimension as 0
+ // so that we can add the rows/columns without failing the assertion.
+ NSMatrix* radioBox = [[NSMatrix alloc]
+ initWithFrame:NSZeroRect
+ mode:NSRadioModeMatrix
+ cellClass:nil
+ numberOfRows:style&wxRA_SPECIFY_COLS?0:majorDim
+ numberOfColumns:style&wxRA_SPECIFY_COLS?majorDim:0
+ ];
+
+ SEL addMajorWithCellsSelector;
+ // If column count is the major dimension then we add by row
+ if( style & wxRA_SPECIFY_COLS )
+ addMajorWithCellsSelector = @selector(addRowWithCells:);
+ // If row count is the major dimension then we add by column
+ else
+ addMajorWithCellsSelector = @selector(addColumnWithCells:);
+
+ for(int i=0; i<minorDim; ++i)
+ {
+ [radioBox
+ performSelector:addMajorWithCellsSelector
+ withObject:[allCells subarrayWithRange:NSMakeRange(i*majorDim, majorDim)]];
+ }
+
+ NSBox *theBox = [[NSBox alloc] initWithFrame:MakeDefaultNSRect(size)];
+
+ // Replace the box's content view with the NSMatrix we just created
+ // IMPORTANT: This must be done before calling SetNSBox.
+ [theBox setContentView:radioBox];
+ [radioBox release]; // The NSBox retains it for us.
+
+ SetNSBox(theBox);
+ [theBox release];
+
+
+ CocoaSetLabelForObject(title, GetNSBox());
+// [GetNSBox() setBorderType:NSLineBorder]; // why??
+
+ SetMajorDim(majorDim, style);
+
+ // Set the selection to the first item if we have any items.
+ // This is for parity with other wx ports which do the same thing.
+ if(n > 0)
+ SetSelection(0);
+