File: NSBox-test.m

package info (click to toggle)
gnustep-examples 1%3A1.4.0%2Bgit20210703-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,164 kB
  • sloc: objc: 17,202; makefile: 56
file content (264 lines) | stat: -rw-r--r-- 7,693 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
/* NSBox-test.m: NSBox class demo/test

   Copyright (C) 1999 Free Software Foundation, Inc.

   Author:  Nicola Pero <n.pero@mi.flashnet.it>
   Date: 1999
   
   This file is part of GNUstep.
   
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.
   
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
   
   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#include <Foundation/Foundation.h>
#include <AppKit/AppKit.h>
#include <GNUstepGUI/GSHbox.h>
#include "../GSTestProtocol.h"

@interface NSBoxTest: NSObject <GSTest>
{
  NSWindow *win;
  NSBox *box;
}
-(void) restart;
-(void) setNSNoBorder: (id)sender;
-(void) setNSLineBorder: (id)sender;
-(void) setNSBezelBorder: (id)sender;
-(void) setNSGrooveBorder: (id)sender;
-(void) setNSNoTitle: (id)sender;
-(void) setNSAboveTop: (id)sender;
-(void) setNSAtTop: (id)sender;
-(void) setNSBelowTop: (id)sender;
-(void) setNSAboveBottom: (id)sender;
-(void) setNSAtBottom: (id)sender;
-(void) setNSBelowBottom: (id)sender;
@end

@implementation NSBoxTest: NSObject
{
  // for instance variables see above
}
-(id) init 
{
  GSHbox *hbox;
  NSMatrix *borderMatrix;
  NSMatrix *titleMatrix;
  NSButtonCell *cell;
  NSTextField *boxContents;
  NSRect winFrame;
  NSBox *tmp_box;

  boxContents = [NSTextField new];
  [boxContents setDrawsBackground: YES];
  [boxContents setBackgroundColor: [NSColor redColor]];
  [boxContents setEditable: NO];
  [boxContents setSelectable: NO];
  [boxContents setBezeled: NO];
  [boxContents setBordered: YES];
  [boxContents setAlignment: NSCenterTextAlignment];
  [boxContents setStringValue: @"Box Contents"];
  [boxContents setFrameSize: NSMakeSize (140, 140)];
  [boxContents setAutoresizingMask: NSViewWidthSizable | NSViewHeightSizable];
  
  box = [NSBox new];
  [box setTitle: @"Box Title"];
  [box setTitlePosition: NSAtTop];
  [box setBorderType: NSGrooveBorder];
  [box addSubview: boxContents];
  [boxContents release];
  [box sizeToFit];
  [box setAutoresizingMask: (NSViewWidthSizable | NSViewHeightSizable)];
  
  cell = [[NSButtonCell alloc] init];
  [cell setButtonType: NSRadioButton];
  [cell setBordered: NO];
  [cell setImagePosition: NSImageLeft]; 
  
  borderMatrix = [[NSMatrix alloc] initWithFrame: NSZeroRect
				   mode: NSRadioModeMatrix
				   prototype: cell
				   numberOfRows: 4
				   numberOfColumns: 1];   
  
  titleMatrix = [[NSMatrix alloc] initWithFrame: NSZeroRect
				  mode: NSRadioModeMatrix
				  prototype: cell
				  numberOfRows: 7
				  numberOfColumns: 1];   
  [cell release];
  
  [borderMatrix setIntercellSpacing: NSMakeSize (0, 4) ];
  [borderMatrix setTarget: self];
  [borderMatrix setAutosizesCells: NO];
  
  cell = [borderMatrix cellAtRow: 0 column: 0];
  [cell setTitle: @"NSNoBorder"];
  [cell setAction: @selector (setNSNoBorder:)];	
  
  cell = [borderMatrix cellAtRow: 1 column: 0];
  [cell setTitle: @"NSLineBorder"];
  [cell setAction: @selector (setNSLineBorder:)];	
  
  cell = [borderMatrix cellAtRow: 2 column: 0];
  [cell setTitle: @"NSBezelBorder"];
  [cell setAction: @selector (setNSBezelBorder:)];	
  
  cell = [borderMatrix cellAtRow: 3 column: 0];
  [cell setTitle: @"NSGrooveBorder"];
  [cell setAction: @selector (setNSGrooveBorder:)];
  
  [borderMatrix selectCellAtRow: 3 column: 0];
  [borderMatrix setAutoresizingMask: (NSViewMinXMargin | NSViewMaxXMargin)];
  [borderMatrix sizeToFit];
  
  [titleMatrix setIntercellSpacing: NSMakeSize (0, 4) ];
  [titleMatrix setTarget: self];
  cell = [titleMatrix cellAtRow: 0 column: 0];
  [cell setTitle: @"NSNoTitle"];
  [cell setAction: @selector (setNSNoTitle:)];
  
  cell = [titleMatrix cellAtRow: 1 column: 0];
  [cell setTitle: @"NSAboveTop"];
  [cell setAction: @selector (setNSAboveTop:)];
  
  cell = [titleMatrix cellAtRow: 2 column: 0];
  [cell setTitle: @"NSAtTop"];
  [cell setAction: @selector (setNSAtTop:)];
  
  cell = [titleMatrix cellAtRow: 3 column: 0];
  [cell setTitle: @"NSBelowTop"];
  [cell setAction: @selector (setNSBelowTop:)];	
  
  cell = [titleMatrix cellAtRow: 4 column: 0];
  [cell setTitle: @"NSAboveBottom"];
  [cell setAction: @selector (setNSAboveBottom:)];	
  
  cell = [titleMatrix cellAtRow: 5 column: 0];
  [cell setTitle: @"NSAtBottom"];
  [cell setAction: @selector (setNSAtBottom:)];
  
  cell = [titleMatrix cellAtRow: 6 column: 0];
  [cell setTitle: @"NSBelowBottom"];
  [cell setAction: @selector (setNSBelowBottom:)];	
  
  [titleMatrix selectCellAtRow: 2 column: 0];
  [titleMatrix setAutoresizingMask: (NSViewMinXMargin | NSViewMaxXMargin)];
  [titleMatrix sizeToFit];
  
  hbox = [GSHbox new];
  [hbox setDefaultMinXMargin: 10];
  [hbox setBorder: 10];
  [hbox addView: box];
  [box release];

  tmp_box = [NSBox new];
  [tmp_box setTitle: @"setBorderType:"];
  [tmp_box setTitlePosition: NSAtTop];
  [tmp_box setBorderType: NSGrooveBorder];
  [tmp_box addSubview: borderMatrix];
  [borderMatrix release];
  [tmp_box sizeToFit];
  [tmp_box setAutoresizingMask: (NSViewMinYMargin | NSViewWidthSizable)];
  [hbox addView: tmp_box];
  [tmp_box release];

  tmp_box = [NSBox new];
  [tmp_box setTitle: @"setTitlePosition:"];
  [tmp_box setTitlePosition: NSAtTop];
  [tmp_box setBorderType: NSGrooveBorder];
  [tmp_box addSubview: titleMatrix];
  [titleMatrix release];
  [tmp_box sizeToFit];
  [tmp_box setAutoresizingMask: (NSViewMinYMargin | NSViewWidthSizable)];
  [hbox addView: tmp_box];
  [tmp_box release];
  [hbox setAutoresizingMask: (NSViewWidthSizable | NSViewHeightSizable)];

  winFrame.size = [hbox frame].size;
  winFrame.origin = NSMakePoint (100, 100);

  // Now we can make the window of the exact size 
  win = [[NSWindow alloc] initWithContentRect: winFrame
			  styleMask: (NSTitledWindowMask 
				      | NSClosableWindowMask 
				      | NSMiniaturizableWindowMask
				      | NSResizableWindowMask)
			  backing: NSBackingStoreBuffered
			  defer: YES];
  [win setTitle:@"NSBox Test"];
  [win setReleasedWhenClosed: NO];
  [win setContentView: hbox];
  [hbox release];
  [win setMinSize: [NSWindow frameRectForContentRect: winFrame
			     styleMask: [win styleMask]].size];
  [self restart];
  return self;
}
- (void) dealloc
{
  RELEASE(win);
  [super dealloc];
}
- (void) restart
{
  [win orderFront: nil]; 
  [[NSApplication sharedApplication] addWindowsItem: win
				     title: @"NSBox Test"
				     filename: NO];
}
-(void) setNSNoBorder: (id)sender
{
  [box setBorderType: NSNoBorder];
}
-(void) setNSLineBorder: (id)sender
{
  [box setBorderType: NSLineBorder];
}
-(void) setNSBezelBorder: (id)sender
{
  [box setBorderType: NSBezelBorder];
}
-(void) setNSGrooveBorder: (id)sender
{
  [box setBorderType: NSGrooveBorder];
}
-(void) setNSNoTitle: (id)sender
{
  [box setTitlePosition: NSNoTitle];
}
-(void) setNSAboveTop: (id)sender
{
  [box setTitlePosition: NSAboveTop];
}
-(void) setNSAtTop: (id)sender
{
  [box setTitlePosition: NSAtTop];
}
-(void) setNSBelowTop: (id)sender
{
  [box setTitlePosition: NSBelowTop];
}
-(void) setNSAboveBottom: (id)sender
{
  [box setTitlePosition: NSAboveBottom];
}
-(void) setNSAtBottom: (id)sender
{
  [box setTitlePosition: NSAtBottom];
}
-(void) setNSBelowBottom: (id)sender
{
  [box setTitlePosition: NSBelowBottom];
}
@end