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
|
/*
nsscroller.m
Simple application to test NSScroller class.
Copyright (C) 1997 Free Software Foundation, Inc.
Author: Scott Christley <scottc@net-community.com>
Date: February 1997
This file is part of the GNUstep GUI X/RAW Backend.
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; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <Foundation/NSAutoreleasePool.h>
#include <AppKit/AppKit.h>
@interface MyObject : NSObject
@end
@implementation MyObject
- (void)scrollerAction: (id)sender
{
float pos = [sender floatValue];
float knob = [sender knobProportion];
switch ([sender hitPart])
{
case NSScrollerKnob:
NSLog (@"NSScrollerKnob");
NSLog (@"scroller value = %f", pos);
break;
case NSScrollerKnobSlot:
NSLog (@"NSScrollerKnobSlot");
break;
case NSScrollerDecrementLine:
NSLog (@"NSScrollerDecrementLine");
[sender setFloatValue: pos - 0.05 knobProportion: knob];
break;
case NSScrollerDecrementPage:
NSLog (@"NSScrollerDecrementPage");
[sender setFloatValue: pos - 0.2 knobProportion: knob];
break;
case NSScrollerIncrementLine:
NSLog (@"NSScrollerIncrementLine");
[sender setFloatValue: pos + 0.05 knobProportion: knob];
break;
case NSScrollerIncrementPage:
NSLog (@"NSScrollerIncrementPage");
[sender setFloatValue: pos + 0.2 knobProportion: knob];
break;
case NSScrollerNoPart:
NSLog (@"NSScrollerNoPart");
break;
}
}
@end
int
main(int argc, char **argv, char** env)
{
NSApplication *theApp;
NSWindow *window;
NSRect winRect = {{100, 400}, {300, 200}};
NSRect wf0 = {{0, 0}, {300, 300}};
NSView *v;
NSScroller *s0, *s1, *s2, *s3, *s4, *s5;
NSRect sf0 = {{10, 10}, {150, 20}};
NSRect sf1 = {{10, 40}, {150, 20}};
NSRect sf2 = {{10, 70}, {150, 20}};
NSRect sf3 = {{10, 100}, {20, 150}};
NSRect sf4 = {{40, 100}, {20, 150}};
NSRect sf5 = {{70, 100}, {20, 150}};
id object;
id pool;
unsigned int style = NSTitledWindowMask | NSClosableWindowMask
| NSMiniaturizableWindowMask | NSResizableWindowMask;
#if LIB_FOUNDATION_LIBRARY
[NSProcessInfo initializeWithArguments: argv count: argc environment: env];
#endif
pool = [NSAutoreleasePool new];
theApp = [NSApplication sharedApplication];
object = [[MyObject new] autorelease];
#if 0
window = [[NSWindow alloc] initWithContentRect: winRect
styleMask: style
backing: NSBackingStoreNonretained
defer: NO];
#else
window = [[NSWindow alloc] init];
#endif
v = [window contentView];
s0 = [[NSScroller alloc] initWithFrame: sf0];
[s0 setArrowsPosition: NSScrollerArrowsMaxEnd];
[s0 setEnabled: YES];
[s0 setTarget: object];
[s0 setAction: @selector(scrollerAction:)];
[v addSubview: s0];
s1 = [[NSScroller alloc] initWithFrame: sf1];
[s1 setArrowsPosition: NSScrollerArrowsMinEnd];
[s1 setEnabled: YES];
[s1 setTarget: object];
[s1 setAction: @selector(scrollerAction:)];
[v addSubview: s1];
s2 = [[NSScroller alloc] initWithFrame: sf2];
[s2 setArrowsPosition: NSScrollerArrowsNone];
[s2 setEnabled: YES];
[s2 setTarget: object];
[s2 setAction: @selector(scrollerAction:)];
[v addSubview: s2];
s3 = [[NSScroller alloc] initWithFrame: sf3];
[s3 setArrowsPosition: NSScrollerArrowsMaxEnd];
[s3 setEnabled: YES];
[s3 setFloatValue: 0.5 knobProportion: 0.4];
[s3 setTarget: object];
[s3 setAction: @selector(scrollerAction:)];
[v addSubview: s3];
s4 = [[NSScroller alloc] initWithFrame: sf4];
[s4 setArrowsPosition: NSScrollerArrowsMinEnd];
[s4 setEnabled: YES];
[s4 setTarget: object];
[s4 setAction: @selector(scrollerAction:)];
[v addSubview: s4];
s5 = [[NSScroller alloc] initWithFrame: sf5];
[s5 setArrowsPosition: NSScrollerArrowsNone];
[s5 setEnabled: YES];
[s5 setTarget: object];
[s5 setAction: @selector(scrollerAction:)];
[v addSubview: s5];
[window setFrame: wf0 display: YES];
[window setTitle: @"GNUstep NSScroller"];
[window orderFrontRegardless];
{
NSMenu *menu = [NSMenu new];
[menu addItemWithTitle: @"Quit"
action: @selector(terminate:)
keyEquivalent: @"q"];
[NSApp setMainMenu: menu];
}
[theApp run];
[pool release];
return 0;
}
|