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
|
/*
nsbrowsercell.m
Copyright (C) 1996 Free Software Foundation, Inc.
Author: Scott Christley <scottc@net-community.com>
Date: October 1997
Author: Felipe A. Rodriguez <far@ix.netcom.com>
Date: July 1998
This file is part of the GNUstep GUI X/RAW Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library 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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02111, USA.
*/
#import <Foundation/NSAutoreleasePool.h>
#import <AppKit/AppKit.h>
#import <AppKit/NSTabView.h>
#include "TestView.h"
#include "GSImageTabViewItem.h"
@interface myTabViewDelegate : NSObject
{
NSTabView *ourView;
NSMatrix *matrix;
}
- (BOOL)tabView:(NSTabView *)tabView shouldSelectTabViewItem:(NSTabViewItem *)tabViewItem;
- (void)tabView:(NSTabView *)tabView willSelectTabViewItem:(NSTabViewItem *)tabViewItem;
- (void)tabView:(NSTabView *)tabView didSelectTabViewItem:(NSTabViewItem *)tabViewItem;
- (void)tabViewDidChangeNumberOfTabViewItems:(NSTabView *)TabView;
@end
@implementation myTabViewDelegate
- (BOOL)tabView:(NSTabView *)tabView shouldSelectTabViewItem:(NSTabViewItem *)tabViewItem
{
NSLog(@"shouldSelectTabViewItem: %@", [tabViewItem label]);
/*
* This is a test to see if the delegate is doing its job.
*/
/*
if ([[tabViewItem label] isEqual:@"Me"])
return NO;
*/
return YES;
}
- (void)tabView:(NSTabView *)tabView willSelectTabViewItem:(NSTabViewItem *)tabViewItem
{
NSLog(@"willSelectTabViewItem: %@", [tabViewItem label]);
}
- (void)tabView:(NSTabView *)tabView didSelectTabViewItem:(NSTabViewItem *)tabViewItem
{
NSLog(@"didSelectTabViewItem: %@", [tabViewItem label]);
}
- (void)tabViewDidChangeNumberOfTabViewItems:(NSTabView *)TabView
{
NSLog(@"tabViewDidChangeNumberOfTabViewItems: %d", [TabView numberOfTabViewItems]);
}
- (void)setTabView:(NSTabView *)tabView
{
ourView = tabView;
}
- (void)buttonNext:(id)sender
{
[ourView selectNextTabViewItem:sender];
}
- (void)buttonPrevious:(id)sender
{
[ourView selectPreviousTabViewItem:sender];
}
- (void) setMatrix: (NSMatrix*)anObject
{
matrix = anObject;
}
- (NSMatrix *) aMatrixToAddAsAView
{
NSRect matrixRect = {{10, 42}, {260, 228}};
NSMatrix *theMatrix;
NSSize cellSize = {64, 75};
NSImageCell *imageCell;
id handler = self;
imageCell = [[NSImageCell new] autorelease];
[imageCell setImageFrameStyle: NSImageFrameGrayBezel];
[imageCell setImageScaling: NSScaleNone];
[imageCell setImage: [NSImage imageNamed: @"NSRadioButton"]];
theMatrix = [[[NSMatrix alloc] initWithFrame: matrixRect
mode: NSRadioModeMatrix
prototype: imageCell
numberOfRows: 3
numberOfColumns: 4]
autorelease];
[theMatrix setCellSize: cellSize];
[self setMatrix: theMatrix];
imageCell = [theMatrix cellAtRow: 0 column: 0];
[imageCell setImageAlignment: NSImageAlignTopLeft];
imageCell = [theMatrix cellAtRow: 0 column: 1];
[imageCell setImageAlignment: NSImageAlignTop];
imageCell = [theMatrix cellAtRow: 0 column: 2];
[imageCell setImageAlignment: NSImageAlignTopRight];
imageCell = [theMatrix cellAtRow: 0 column: 3];
[imageCell setImageScaling: NSScaleProportionally];
imageCell = [theMatrix cellAtRow: 1 column: 0];
[imageCell setImageAlignment: NSImageAlignLeft];
imageCell = [theMatrix cellAtRow: 1 column: 1];
[imageCell setImageAlignment: NSImageAlignCenter];
imageCell = [theMatrix cellAtRow: 1 column: 2];
[imageCell setImageAlignment: NSImageAlignRight];
imageCell = [theMatrix cellAtRow: 1 column: 3];
[imageCell setImageScaling: NSScaleToFit];
imageCell = [theMatrix cellAtRow: 2 column: 0];
[imageCell setImageAlignment: NSImageAlignBottomLeft];
imageCell = [theMatrix cellAtRow: 2 column: 1];
[imageCell setImageAlignment: NSImageAlignBottom];
imageCell = [theMatrix cellAtRow: 2 column: 2];
[imageCell setImageAlignment: NSImageAlignBottomRight];
imageCell = [theMatrix cellAtRow: 2 column: 3];
[imageCell setImageScaling: NSScaleNone];
return theMatrix;
}
@end
int
main(int argc, char **argv, char** env)
{
NSApplication *theApp;
NSWindow *window;
NSTabView *tabView;
NSTabViewItem *item;
NSRect winRect = {{100, 100}, {300, 350}};
NSRect tabViewRect = {{10, 10}, {280, 280}};
NSBox *slash;
id pool = [NSAutoreleasePool new];
id aView;
id label;
NSButton *button;
id delegate = [myTabViewDelegate new];
id scrollView;
#if LIB_FOUNDATION_LIBRARY
[NSProcessInfo initializeWithArguments:argv count:argc environment:env];
#endif
#ifndef NX_CURRENT_COMPILER_RELEASE
initialize_gnustep_backend();
#endif
theApp = [NSApplication sharedApplication];
window = [[NSWindow alloc] init];
tabView = [[NSTabView alloc] initWithFrame:tabViewRect];
[tabView setTabViewType:NSNoTabsBezelBorder];
[tabView setDelegate:delegate];
[delegate setTabView:tabView];
[[window contentView] addSubview:tabView];
aView = [[NSView alloc] initWithFrame:[tabView contentRect]];
label = [[NSTextField alloc] initWithFrame:[aView frame]];
[label setEditable:NO];
[label setSelectable:NO];
[label setBezeled:NO];
[label setBordered:NO];
[label setBackgroundColor:[NSColor lightGrayColor]];
[label setAlignment:NSCenterTextAlignment];
[label setStringValue:[NSString stringWithCString:"Press next to
install."]];
[aView addSubview:label];
[label release];
slash = [[NSBox alloc] initWithFrame:NSMakeRect(10,37,260,2)];
[slash setTitlePosition: NSNoTitle];
[slash setBorderType: NSGrooveBorder];
[aView addSubview:slash];
[slash release];
button = [[NSButton alloc] initWithFrame:NSMakeRect(10,10,72,22)];
[button setTitle: @"Previous..."];
[button setTarget:delegate];
[button setAction:@selector(buttonPrevious:)];
[button setEnabled:NO];
[aView addSubview:button];
[button release];
button = [[NSButton alloc] initWithFrame:NSMakeRect(85,10,72,22)];
[button setTitle: @"Next..."];
[button setTarget:delegate];
[button setAction:@selector(buttonNext:)];
[aView addSubview:button];
[button release];
item = [[NSTabViewItem alloc] initWithIdentifier:@"Urph"];
[item setLabel:@"Natalie"];
[item setView:aView];
[tabView addTabViewItem:item];
[aView release];
aView = [[NSView alloc] initWithFrame:[tabView contentRect]];
[aView addSubview:[delegate aMatrixToAddAsAView]];
/*
label = [[NSTextField alloc] initWithFrame:[aView frame]];
[label setEditable:NO];
[label setSelectable:NO];
[label setBezeled:NO];
[label setBordered:NO];
[label setBackgroundColor:[NSColor lightGrayColor]];
[label setAlignment:NSCenterTextAlignment];
[label setStringValue:[NSString stringWithCString: "Previous, or Next?"]];
[aView addSubview:label];
[label release];
*/
slash = [[NSBox alloc] initWithFrame:NSMakeRect(10,37,260,2)];
[slash setTitlePosition: NSNoTitle];
[slash setBorderType: NSGrooveBorder];
[aView addSubview:slash];
[slash release];
button = [[NSButton alloc] initWithFrame:NSMakeRect(10,10,72,22)];
[button setTitle: @"Previous..."];
[button setTarget:delegate];
[button setAction:@selector(buttonPrevious:)];
[aView addSubview:button];
[button release];
button = [[NSButton alloc] initWithFrame:NSMakeRect(85,10,72,22)];
[button setTitle: @"Next..."];
[button setTarget:delegate];
[button setAction:@selector(buttonNext:)];
[aView addSubview:button];
[button release];
item = [[NSTabViewItem alloc] initWithIdentifier:@"Urph2"];
[item setLabel:@"Natalia Conquistadori"];
[item setView:aView];
[tabView addTabViewItem:item];
[aView release];
aView = [[NSView alloc] initWithFrame:[tabView contentRect]];
scrollView = [[NSScrollView alloc]
initWithFrame:NSMakeRect(10,42,260,228)];
[scrollView setDocumentView:[[TestView alloc]
initWithFrame:NSMakeRect(0,0,500,700)]];
[scrollView setHasHorizontalScroller:YES];
[scrollView setHasVerticalScroller:YES];
[aView addSubview:scrollView];
/*
label = [[NSTextField alloc] initWithFrame:[aView frame]];
[label setEditable:NO];
[label setSelectable:NO];
[label setBezeled:NO];
[label setBordered:NO];
[label setBackgroundColor:[NSColor lightGrayColor]];
[label setAlignment:NSCenterTextAlignment];
[label setStringValue:[NSString stringWithCString:"Well, no install.
Sorry. :-)"]];
[aView addSubview:label];
[label release];
*/
slash = [[NSBox alloc] initWithFrame:NSMakeRect(10,37,260,2)];
[slash setTitlePosition: NSNoTitle];
[slash setBorderType: NSGrooveBorder];
[aView addSubview:slash];
[slash release];
button = [[NSButton alloc] initWithFrame:NSMakeRect(10,10,72,22)];
[button setTitle: @"Previous..."];
[button setTarget:delegate];
[button setAction:@selector(buttonPrevious:)];
[aView addSubview:button];
[button release];
button = [[NSButton alloc] initWithFrame:NSMakeRect(85,10,72,22)];
[button setTitle: @"Next..."];
[button setTarget:delegate];
[button setEnabled:NO];
[button setAction:@selector(buttonNext:)];
[aView addSubview:button];
[button release];
item = [[GSImageTabViewItem alloc] initWithIdentifier:@"Urph3"];
[item setImage:[NSImage imageNamed:@"Smiley"]];
[item setLabel:@"Me"];
[item setView:aView];
[tabView addTabViewItem:item];
[aView release];
[window setTitle:@"NSTabView without Tabs"];
[window setFrame:winRect display:YES];
[window orderFrontRegardless];
{
NSMenu *menu = [NSMenu new];
[menu addItemWithTitle: @"Quit"
action: @selector(terminate:)
keyEquivalent: @"q"];
[NSApp setMainMenu: menu];
}
[theApp run];
[pool release];
return 0;
}
|