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
|
/* CoordinateCheck-test.m: checking coordinate sanity in other windows
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"
/* The checking categories */
@implementation NSView (CheckCoordinates)
- (NSString *) checkCoordinates
{
NSRect rect1, rect2;
rect1 = [self convertRect: _bounds toView: nil];
rect2 = [[self superview] convertRect: _frame toView: nil];
if (NSEqualRects (rect1, rect2) != YES)
{
NSMutableString *string;
string = AUTORELEASE ([NSMutableString new]);
[string appendFormat: @"%@: INVALID - \n", self];
[string appendFormat: @" bounds in window space are: `%@'\n",
NSStringFromRect (rect1)];
[string appendFormat: @" frame in window space is: `%@'\n",
NSStringFromRect (rect2)];
return string;
}
else
{
return [NSString stringWithFormat: @"%@: Ok\n", self];
}
}
- (NSString *) recursivelyCheckCoordinates
{
int i, count;
NSMutableString *string;
string = AUTORELEASE ([NSMutableString new]);
[string appendString: [self checkCoordinates]];
count = [[self subviews] count];
for (i = 0; i < count; i++)
{
NSView *v;
v = [[self subviews] objectAtIndex: i];
[string appendString: [v recursivelyCheckCoordinates]];
}
return string;
}
@end
@interface NSView (CheckCoordinates)
- (NSString *) checkCoordinates;
@end
@implementation NSWindow (CheckCoordinates)
- (NSString *) checkCoordinates
{
return [[self contentView] recursivelyCheckCoordinates];
}
@end
@interface NSWindow (CheckCoordinates)
- (NSString *) checkCoordinates;
@end
/* Now the test itself */
@interface CoordinateCheckTest: NSObject <GSTest>
{
NSTextField *windowName;
NSTextView *text;
NSWindow *win;
NSWindow *winToCheck;
}
-(void) restart;
-(void) check: (id)sender;
-(void) choose: (id)sender;
-(void) reset: (id)sender;
@end
@implementation CoordinateCheckTest: NSObject
{
// for instance variables see above
}
-(id) init
{
GSHbox *hbox;
GSVbox *vbox;
NSButton *button;
NSScrollView *scrollView;
NSRect winFrame;
vbox = [GSVbox new];
[vbox setDefaultMinYMargin: 5];
[vbox setBorder: 5];
scrollView = [[NSScrollView alloc] initWithFrame:
NSMakeRect (0, 0, 300, 300)];
[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);
windowName = [NSTextField new];
[windowName setEditable: NO];
[windowName setSelectable: NO];
[windowName setBezeled: NO];
[windowName setDrawsBackground: NO];
[windowName setAutoresizingMask: NSViewMaxXMargin];
[windowName setStringValue: @"Window Title: (null)"];
[windowName sizeToFit];
[vbox addView: windowName enablingYResizing: NO];
RELEASE (windowName);
[vbox addSeparator];
hbox = [GSHbox new];
[hbox setDefaultMinXMargin: 5];
[hbox setBorder: 0];
button = [NSButton new];
[button setFrame: NSMakeRect (0, 0, 64, 64)];
[button setTitle: @"Choose\nWindow"];
[button setAutoresizingMask: NSViewMaxXMargin];
[button setTarget: self];
[button setAction: @selector (choose:)];
[hbox addView: button];
RELEASE (button);
button = [NSButton new];
[button setFrame: NSMakeRect (0, 0, 64, 64)];
[button setTitle: @"Check\nWindow"];
[button setAutoresizingMask: NSViewMaxXMargin];
[button setTarget: self];
[button setAction: @selector (check:)];
[hbox addView: button];
RELEASE (button);
button = [NSButton new];
[button setFrame: NSMakeRect (0, 0, 64, 64)];
[button setTitle: @"Reset"];
[button setAutoresizingMask: NSViewMaxXMargin];
[button setTarget: self];
[button setAction: @selector (reset:)];
[hbox addView: button];
RELEASE (button);
[hbox setAutoresizingMask: NSViewNotSizable];
[vbox addView: hbox enablingYResizing: NO];
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];
RELEASE (vbox);
[win setTitle: @"Coordinate Check Test"];
[text setString: @"To select the window to check -\npress `Choose Window' and then click\ninside the window you want to choose\n"];
[self restart];
return self;
}
-(void) restart
{
[win orderFront: nil];
[[NSApplication sharedApplication] addWindowsItem: win
title: @"Coordinate Check Test"
filename: NO];
}
- (void) dealloc
{
RELEASE (win);
RELEASE (winToCheck);
[super dealloc];
}
- (void) choose: (id)sender
{
NSEvent *event;
event = [NSApp nextEventMatchingMask: NSLeftMouseDownMask
untilDate: nil
inMode: NSEventTrackingRunLoopMode
dequeue: YES];
ASSIGN (winToCheck, [event window]);
[windowName setStringValue: [NSString stringWithFormat: @"Window Title: %@",
[winToCheck title]]];
[windowName sizeToFit];
}
- (void) check: (id)sender
{
if (winToCheck == nil)
{
[text replaceCharactersInRange:
NSMakeRange ([[text textStorage] length], 0)
withString: @"Please select a window first -\nby pressing `Choose Window'\nand then clicking inside the window\nyou want to select\n"];
}
else
{
NSString *newCheck = [winToCheck checkCoordinates];
[text replaceCharactersInRange:
NSMakeRange ([[text textStorage] length], 0)
withString: [NSString stringWithFormat: @" - %@ -\n",
[winToCheck title]]];
[text replaceCharactersInRange:
NSMakeRange ([[text textStorage] length], 0)
withString: newCheck];
[text replaceCharactersInRange:
NSMakeRange ([[text textStorage] length], 0)
withString: [NSString stringWithFormat: @"\n",
[winToCheck title]]];
}
}
- (void) reset: (id)sender
{
[text setString: @""];
}
@end
|