Skip to content

Commit 4c61e77

Browse files
committed
NSMatrix: no cell class when a prototype is used
-cellClass returned the prototype cell's class when the matrix was set up with a prototype. OS X returns nil in that case (the cell class and the prototype are alternatives). Return Nil while a prototype is set. The stored class is left untouched, so the coder and cell creation are unaffected.
1 parent a6390a8 commit 4c61e77

4 files changed

Lines changed: 80 additions & 0 deletions

File tree

ChangeLog

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
2026-07-12 Todd White <todd.white@thalion.global>
2+
3+
* Source/NSMatrix.m (-[NSMatrix cellClass]): Return Nil when the matrix
4+
uses a cell prototype, as OS X does, rather than the prototype cell's
5+
class.
6+
* Tests/gui/NSMatrix/cellClassPrototype.m:
7+
* Tests/gui/NSMatrix/TestInfo:
8+
New test for the cell class / prototype relationship.
9+
110
2026-07-12 Todd White <todd.white@thalion.global>
211

312
* Tests/gui/NSTableHeaderCell/headerCell.m:

Source/NSMatrix.m

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3009,6 +3009,11 @@ - (void) setCellClass: (Class)classId
30093009
*/
30103010
- (Class) cellClass
30113011
{
3012+
/* A matrix that uses a cell prototype has no cell class, as on OS X. */
3013+
if (_cellPrototype != nil)
3014+
{
3015+
return Nil;
3016+
}
30123017
return _cellClass;
30133018
}
30143019

Tests/gui/NSMatrix/TestInfo

Whitespace-only changes.
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/* A matrix that uses a cell prototype has no cell class, as on OS X:
2+
-cellClass returns Nil while a prototype is set, and returns the class
3+
again once a cell class is set (which clears the prototype). */
4+
#include "Testing.h"
5+
6+
#include <Foundation/NSAutoreleasePool.h>
7+
#include <Foundation/NSGeometry.h>
8+
9+
#include <AppKit/NSApplication.h>
10+
#include <AppKit/NSButtonCell.h>
11+
#include <AppKit/NSMatrix.h>
12+
13+
int
14+
main(int argc, char **argv)
15+
{
16+
CREATE_AUTORELEASE_POOL(arp);
17+
18+
START_SET("NSMatrix cell class vs prototype")
19+
20+
NS_DURING
21+
{
22+
[NSApplication sharedApplication];
23+
}
24+
NS_HANDLER
25+
{
26+
if ([[localException name] isEqualToString: NSInternalInconsistencyException])
27+
SKIP("It looks like GNUstep backend is not yet installed")
28+
}
29+
NS_ENDHANDLER
30+
31+
/* Built with a prototype: no cell class. */
32+
{
33+
NSButtonCell *proto = AUTORELEASE([[NSButtonCell alloc] init]);
34+
NSMatrix *m = AUTORELEASE([[NSMatrix alloc] initWithFrame: NSMakeRect(0, 0, 100, 100)
35+
mode: NSListModeMatrix
36+
prototype: proto
37+
numberOfRows: 1
38+
numberOfColumns: 1]);
39+
40+
pass([m prototype] != nil, "the prototype is set");
41+
pass([m cellClass] == Nil, "a matrix with a prototype has no cell class");
42+
}
43+
44+
/* Setting a cell class clears the prototype and reports the class. */
45+
{
46+
NSMatrix *m = AUTORELEASE([[NSMatrix alloc] initWithFrame: NSMakeRect(0, 0, 100, 100)]);
47+
48+
[m setCellClass: [NSButtonCell class]];
49+
pass([m cellClass] == [NSButtonCell class], "setCellClass: reports the cell class");
50+
pass([m prototype] == nil, "setCellClass: clears the prototype");
51+
}
52+
53+
/* Setting a prototype on that matrix hides the cell class again. */
54+
{
55+
NSMatrix *m = AUTORELEASE([[NSMatrix alloc] initWithFrame: NSMakeRect(0, 0, 100, 100)]);
56+
57+
[m setCellClass: [NSButtonCell class]];
58+
[m setPrototype: AUTORELEASE([[NSButtonCell alloc] init])];
59+
pass([m cellClass] == Nil, "setPrototype: makes the cell class Nil again");
60+
}
61+
62+
END_SET("NSMatrix cell class vs prototype")
63+
64+
DESTROY(arp);
65+
return 0;
66+
}

0 commit comments

Comments
 (0)