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 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351
|
/* NSButton-test.m: check continuous buttons
Copyright (C) 2001 Free Software Foundation, Inc.
Author: Nicola Pero <n.pero@mi.flashnet.it>
Date: 2001
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 <GNUstepGUI/GSVbox.h>
#include "../GSTestProtocol.h"
@interface NSButtonTest: NSObject <GSTest>
{
NSWindow *win;
NSTextView *text;
}
-(void) restart;
-(void) action: (id)sender;
@end
@implementation NSButtonTest: NSObject
- (NSTextField *) addLabel: (NSString *)label to: (id)box
{
NSTextField *labelView = [NSTextField new];
[labelView setStringValue: label];
[labelView setFrame: NSMakeRect (0, 0, 250, 16)];
[labelView setEditable: NO];
[labelView setSelectable: NO];
[labelView setBezeled: NO];
[labelView setDrawsBackground: NO];
[box addView: labelView];
return [labelView autorelease];
}
- (NSButton *) addButtonWithLabel: (NSString *)label to: (id)box
{
NSButton *button = [NSButton new];
[button setFrame: NSMakeRect (0, 0, 200, 32)];
[button setTitle: label];
[button setAutoresizingMask: NSViewMaxXMargin];
[button setTarget: self];
[button setContinuous: YES];
[button setAction: @selector (action:)];
[button setToolTip: label];
[box addView: button];
return [button autorelease];
}
- (NSButton *) addButtonWithLabel: (NSString *)label bezel: (NSBezelStyle)bezel to: (id)box
{
NSButton *button = [self addButtonWithLabel: label to: box];
[button setBezelStyle: bezel];
return button;
}
- (NSSegmentedControl *) addSegmentedControlWithLabel: (NSString *)label style: (NSSegmentStyle)style to: (id)box
{
NSSegmentedControl *segmented = [NSSegmentedControl new];
[segmented setFrame: NSMakeRect (0, 0, 200, 32)];
[segmented setAutoresizingMask: NSViewMaxXMargin];
[segmented setSegmentCount: 3];
[segmented setSegmentStyle: style];
[segmented setLabel: @"First" forSegment: 0];
[segmented setLabel: @"Second" forSegment: 1];
[segmented setLabel: @"Third" forSegment: 2];
[segmented setTarget: self];
[segmented setAction: @selector (action:)];
[segmented setToolTip: label];
[box addView: segmented];
[self addLabel: label to: box];
return [segmented autorelease];
}
- (NSComboBox *) addComboBoxWithLabel: (NSString *)label buttonBordered: (BOOL)button to: (id)box
{
NSComboBox *combo = [NSComboBox new];
[combo setFrame: NSMakeRect (0, 0, 200, 32)];
[combo setAutoresizingMask: NSViewMaxXMargin];
[combo setButtonBordered: button];
[combo addItemWithObjectValue: @"First"];
[combo addItemWithObjectValue: @"Second"];
[combo addItemWithObjectValue: @"Third"];
[combo setTarget: self];
[combo setAction: @selector (action:)];
[combo setToolTip: label];
[box addView: combo];
[self addLabel: label to: box];
return [combo autorelease];
}
- (NSPopUpButton *) addPopUpButtonWithLabel: (NSString *)label pullsDown:(BOOL)pullsDown to: (id)box andItems:(NSArray *)items;
{
NSUInteger i;
NSPopUpButton *button = [NSPopUpButton new];
[button setFrame: NSMakeRect (0, 0, 200, 32)];
[button setPullsDown: pullsDown];
[button setAutoresizingMask: NSViewMaxXMargin];
for (i = 0; i < [items count]; i++)
[button addItemWithTitle: [items objectAtIndex:i]];
[button setTarget: self];
[button setAction: @selector (action:)];
[button setToolTip: label];
[box addView: button];
[self addLabel: label to: box];
return [button autorelease];
}
- (NSPopUpButton *) addPopUpButtonWithLabel: (NSString *)label pullsDown:(BOOL)pullsDown to: (id)box
{
NSMutableArray *arr;
NSPopUpButton *button;
arr = [NSMutableArray arrayWithCapacity:3];
[arr addObject: @"First"];
[arr addObject: @"Second"];
[arr addObject: @"Third"];
button = [self addPopUpButtonWithLabel: label pullsDown:pullsDown to:box andItems:arr];
return button;
}
- (NSPopUpButton *) addPopUpButtonWithLabel: (NSString *)label pullsDown:(BOOL)pullsDown bezel:(NSBezelStyle)bezel to: (id)box
{
NSPopUpButton *button = [self addPopUpButtonWithLabel: label pullsDown: pullsDown to: box];
[button setBezelStyle: bezel];
return button;
}
- (NSPopUpButton *) addPopUpButtonWithLabel: (NSString *)label pullsDown:(BOOL)pullsDown to: (id)box withItemCount:(NSUInteger)itemNum
{
NSMutableArray *arr;
NSPopUpButton *button;
NSUInteger c;
arr = [NSMutableArray arrayWithCapacity:itemNum];
for (c = 0; c < itemNum; c++)
{
NSString *str;
str = [NSString stringWithFormat:@"Item N. %lu", (unsigned long)c];
[arr addObject: str];
}
button = [self addPopUpButtonWithLabel: label pullsDown:pullsDown to:box andItems:arr];
return button;
}
-(id) init
{
NSScrollView *scrollView;
NSRect winFrame;
GSVbox *vbox, *column;
GSHbox *hbox;
NSButton *button;
vbox = [GSVbox new];
[vbox setDefaultMinYMargin: 1];
[vbox setBorder: 5];
scrollView = [[NSScrollView alloc] initWithFrame:
NSMakeRect (0, 0, 300, 100)];
[scrollView setHasHorizontalScroller: NO];
[scrollView setHasVerticalScroller: YES];
[scrollView setAutoresizingMask: NSViewHeightSizable | NSViewWidthSizable];
text = [[NSText alloc] initWithFrame: [[scrollView contentView] frame]];
[text setEditable: NO];
[text setRichText: YES];
[text setDelegate: self];
[text setHorizontallyResizable: NO];
[text setVerticallyResizable: YES];
[text setMinSize: NSMakeSize (0, 0)];
[text setMaxSize: NSMakeSize (1E7, 1E7)];
[text setAutoresizingMask: NSViewHeightSizable | NSViewWidthSizable];
[[text textContainer] setContainerSize: NSMakeSize ([text frame].size.width,
1e7)];
[[text textContainer] setWidthTracksTextView: YES];
[scrollView setDocumentView: text];
RELEASE(text);
[vbox addView: scrollView];
RELEASE (scrollView);
[vbox addSeparator];
hbox = [GSHbox new];
[hbox setDefaultMinXMargin: 5];
column = [GSVbox new];
[column setDefaultMinYMargin: 2];
[self addButtonWithLabel: @"NSButton" to: column];
[self addButtonWithLabel: @"NSRoundedBezelStyle" bezel: NSRoundedBezelStyle to: column];
[self addButtonWithLabel: @"NSRegularSquareBezelStyle" bezel: NSRegularSquareBezelStyle to: column];
[self addButtonWithLabel: @"NSThickSquareBezelStyle" bezel: NSThickSquareBezelStyle to: column];
[self addButtonWithLabel: @"NSThickerSquareBezelStyle" bezel: NSThickerSquareBezelStyle to: column];
[self addButtonWithLabel: @"NSDisclosureBezelStyle" bezel: NSDisclosureBezelStyle to: column];
[self addButtonWithLabel: @"NSShadowlessSquareBezelStyle" bezel: NSShadowlessSquareBezelStyle to: column];
[self addButtonWithLabel: @"NSCircularBezelStyle" bezel: NSCircularBezelStyle to: column];
[self addButtonWithLabel: @"NSTexturedSquareBezelStyle" bezel: NSTexturedSquareBezelStyle to: column];
[self addButtonWithLabel: @"NSHelpButtonBezelStyle" bezel: NSHelpButtonBezelStyle to: column];
[self addButtonWithLabel: @"NSSmallSquareBezelStyle" bezel: NSSmallSquareBezelStyle to: column];
[self addButtonWithLabel: @"NSTexturedRoundedBezelStyle" bezel: NSTexturedRoundedBezelStyle to: column];
[self addButtonWithLabel: @"NSRoundRectBezelStyle" bezel: NSRoundRectBezelStyle to: column];
[self addButtonWithLabel: @"NSRecessedBezelStyle" bezel: NSRecessedBezelStyle to: column];
[self addButtonWithLabel: @"NSRoundedDisclosureBezelStyle" bezel: NSRoundedDisclosureBezelStyle to: column];
[hbox addView: column];
RELEASE(column);
column = [GSVbox new];
[column setDefaultMinYMargin: 2];
[self addSegmentedControlWithLabel: @"NSSegmentStyleAutomatic" style: NSSegmentStyleAutomatic to: column];
[self addSegmentedControlWithLabel: @"NSSegmentStyleRounded" style: NSSegmentStyleRounded to: column];
[self addSegmentedControlWithLabel: @"NSSegmentStyleTexturedRounded" style: NSSegmentStyleTexturedRounded to: column];
[self addSegmentedControlWithLabel: @"NSSegmentStyleRoundRect" style: NSSegmentStyleRoundRect to: column];
[self addSegmentedControlWithLabel: @"NSSegmentStyleTexturedSquare" style: NSSegmentStyleTexturedSquare to: column];
[self addSegmentedControlWithLabel: @"NSSegmentStyleCapsule" style: NSSegmentStyleCapsule to: column];
[self addSegmentedControlWithLabel: @"NSSegmentStyleSmallSquare" style: NSSegmentStyleSmallSquare to: column];
[column addSeparator];
button = [self addButtonWithLabel: @"Disabled Button" to: column];
[button setEnabled: NO];
button = [self addButtonWithLabel: @"PushOnPushOff Button" to: column];
[button setButtonType: NSPushOnPushOffButton];
button = [self addButtonWithLabel: @"Disabled PushOnPushOff Button" to: column];
[button setButtonType: NSPushOnPushOffButton];
[button setState: NSOnState];
[button setEnabled: NO];
[hbox addView: column];
RELEASE(column);
column = [GSVbox new];
[column setDefaultMinYMargin: 2];
[self addPopUpButtonWithLabel: @"NSPopUpButton" pullsDown:NO to: column];
[self addPopUpButtonWithLabel: @"NSPopUpButton pullsDown" pullsDown:YES to: column];
[self addPopUpButtonWithLabel: @"NSPopUpButton pullsDown NSRoundedBezelStyle" pullsDown:YES bezel: NSRoundedBezelStyle to: column];
[self addPopUpButtonWithLabel: @"NSPopUpButton NSRoundedBezelStyle" pullsDown:NO bezel: NSRoundedBezelStyle to: column];
[self addPopUpButtonWithLabel: @"NSPopUpButton 500 items" pullsDown:NO to: column withItemCount:500];
[self addPopUpButtonWithLabel: @"NSPopUpButton 100 items" pullsDown:NO to: column withItemCount:100];
[hbox addView: column];
RELEASE(column);
column = [GSVbox new];
[column setDefaultMinYMargin: 2];
[self addComboBoxWithLabel: @"NSComboBox" buttonBordered: NO to: column];
[self addComboBoxWithLabel: @"NSComboBox buttonBordered" buttonBordered: YES to: column];
[hbox addView: column];
RELEASE(column);
[vbox addView: hbox];
RELEASE(hbox);
[vbox setAutoresizingMask: NSViewHeightSizable | NSViewWidthSizable];
winFrame.size = [vbox frame].size;
winFrame.origin = NSMakePoint (100, 100);
win = [[NSWindow alloc] initWithContentRect: winFrame
styleMask: (NSTitledWindowMask
| NSClosableWindowMask
| NSMiniaturizableWindowMask
| NSResizableWindowMask)
backing: NSBackingStoreBuffered
defer: NO];
[win setReleasedWhenClosed: NO];
[win setContentView: vbox];
[win setMinSize: [win frame].size];
[win setTitle: @"Continuous button test"];
[self restart];
return self;
}
-(void) restart
{
[win orderFront: nil];
[[NSApplication sharedApplication] addWindowsItem: win
title: @"Continuous button test"
filename: NO];
}
- (void) dealloc
{
RELEASE (win);
[super dealloc];
}
- (void) action: (id)sender
{
[text replaceCharactersInRange:
NSMakeRange ([[text textStorage] length], 0)
withString: [NSString stringWithFormat: @"Action sent from %@!\n", sender]];
}
@end
|