File: NSWindow-test.m

package info (click to toggle)
gnustep-examples 1%3A1.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, stretch
  • size: 3,208 kB
  • ctags: 310
  • sloc: objc: 17,195; makefile: 50
file content (249 lines) | stat: -rw-r--r-- 7,557 bytes parent folder | download | duplicates (3)
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
/* NSWindow-test.m: test that fills/strokes line up on the desired
   pixel boundaries.

   Copyright (C) 2011 Free Software Foundation, Inc.

   Author:  Eric Wasylishen <ewasylishen@gmail.com>
   Date: 2011
   
   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 "../GSTestProtocol.h"

@interface NSWindowTest : NSObject <GSTest>
{
  NSWindow *testWindow;
  NSPanel *panel;
  NSTextView *tv;
}
- (void) restart;
- (void) setupTextView;
@end


static void AddLabel(NSString *text, NSRect frame, NSView *dest)
{
  NSTextField *labelView = [[NSTextField alloc] initWithFrame: frame];
  [labelView setStringValue: text];
  [labelView setEditable: NO];
  [labelView setSelectable: NO];
  [labelView setBezeled: NO];
  [labelView setFont: [NSFont labelFontOfSize: 10]];
  [dest addSubview: labelView];
  [labelView release];
}


@implementation NSWindowTest

-(id) init
{
  testWindow = [[NSWindow alloc] initWithContentRect: NSMakeRect(0,0,200, 200)
					   styleMask: (NSTitledWindowMask 
						       | NSClosableWindowMask 
						       | NSMiniaturizableWindowMask 
						       | NSResizableWindowMask)
					     backing: NSBackingStoreBuffered
					       defer: NO];
  [testWindow setReleasedWhenClosed: NO];
  [testWindow setTitle: @"Test Window"];

  panel = [[NSPanel alloc] initWithContentRect: NSMakeRect(0,0,200, 400)
					   styleMask: (NSTitledWindowMask 
						       | NSUtilityWindowMask
						       | NSClosableWindowMask 
						       | NSResizableWindowMask)
					     backing: NSBackingStoreBuffered
					       defer: NO];
  [panel setReleasedWhenClosed: NO];
  [panel setTitle: @"NSWindow Test"];

  [self setupTextView];

  [testWindow setDelegate: self];

  [self restart];
  return self;
}

- (void) setupTextView
{
  NSScrollView *sv = [[[NSScrollView alloc] initWithFrame: [[panel contentView] bounds]] autorelease];
  [sv setBorderType: NSNoBorder];
  [sv setHasVerticalScroller: YES];
  [sv setHasHorizontalScroller: NO];
  [sv setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];

  tv = [[NSTextView alloc] initWithFrame:
			     NSMakeRect(0, 0,
					[sv contentSize].width, 
					[sv contentSize].height)];
  [tv setMinSize: NSMakeSize(0.0, [sv contentSize].height)];
  [tv setMaxSize: NSMakeSize(FLT_MAX, FLT_MAX)];
  [tv setVerticallyResizable:YES];
  [tv setHorizontallyResizable:NO];
  [tv setAutoresizingMask:NSViewWidthSizable];
  
  [[tv textContainer]
            setContainerSize:NSMakeSize([sv contentSize].width, FLT_MAX)];
  [[tv textContainer] setWidthTracksTextView:YES];

  [sv setDocumentView: tv];

  [[panel contentView] addSubview: sv];
}

-(void) restart
{
  [testWindow orderFront: nil]; 
  [panel orderFront: nil];
}

- (void) dealloc
{
  RELEASE (testWindow);
  RELEASE (panel);
  [super dealloc];
}

- (void) log: (NSString*)message
{
  NSLog(@" logging");

  if ([[tv string] length] > 10000)
    {
      [[[tv textStorage] mutableString] deleteCharactersInRange: NSMakeRange(0, [[tv string] length] - 10000)];
    }

  [[[tv textStorage] mutableString] appendString: 
		      [NSString stringWithFormat: @"%@\n", message]];
  NSLog(@"done appending");

  [tv scrollRangeToVisible: NSMakeRange([[tv string] length], 0)];
  NSLog(@"done scrolling. len %d", (int)[[tv string] length]);
}

/** NSWindowDelegate */

- (BOOL) windowShouldClose: (id)sender
{
  [self log: @"windowShouldClose"];
  return YES;
}
- (void) windowWillBeginSheet: (NSNotification*)aNotification
{
  [self log: [NSString stringWithFormat: @"windowWillBeginSheet %@", aNotification]];
}
- (void) windowDidEndSheet: (NSNotification*)aNotification
{
  [self log: [NSString stringWithFormat: @"windowDidEndSheet %@", aNotification]];
}
- (BOOL) windowShouldZoom: (NSWindow*)sender
                  toFrame: (NSRect)aFrame
{
  [self log: [NSString stringWithFormat: @"windowShouldZoom:toFrame: %@", NSStringFromRect(aFrame)]];
  return YES;
}
/*
- (NSUndoManager*) windowWillReturnUndoManager: (NSWindow*)sender
{
}
- (NSRect) windowWillUseStandardFrame: (NSWindow*)sender
                         defaultFrame: (NSRect)aFrame;
- (NSRect) window: (NSWindow *)window 
willPositionSheet: (NSWindow *)sheet
        usingRect: (NSRect)rect;
- (NSWindow *) attachedSheet;
*/
- (NSSize) windowWillResize: (NSWindow*)sender
		     toSize: (NSSize)frameSize
{
  [self log: [NSString stringWithFormat: @"windowWillReize:toSize: %@", NSStringFromSize(frameSize)]];
  return frameSize;
}
/*
- (id) windowWillReturnFieldEditor: (NSWindow*)sender
			  toObject: (id)client;
*/
- (void) windowDidBecomeKey: (NSNotification*)aNotification
{
  [self log: [NSString stringWithFormat: @"windowDidBecomeKey %@", aNotification]];
}
- (void) windowDidBecomeMain: (NSNotification*)aNotification
{
  [self log: [NSString stringWithFormat: @"windowDidBecomeMain %@", aNotification]];
}
- (void) windowDidChangeScreen: (NSNotification*)aNotification
{
  [self log: [NSString stringWithFormat: @"windowDidChangeScreen %@", aNotification]];
}
- (void) windowDidChangeScreenProfile: (NSNotification *)aNotification
{
  [self log: [NSString stringWithFormat: @"windowDidChangeScreenProfile %@", aNotification]];
}
- (void) windowDidDeminiaturize: (NSNotification*)aNotification
{
  [self log: [NSString stringWithFormat: @"windowDidDeminiaturize %@", aNotification]];
}
- (void) windowDidExpose: (NSNotification*)aNotification
{
  [self log: [NSString stringWithFormat: @"windowDidExpose %@", aNotification]];
}
- (void) windowDidMiniaturize: (NSNotification*)aNotification
{
  [self log: [NSString stringWithFormat: @"windowDidMiniaturize %@", aNotification]];
}
- (void) windowDidMove: (NSNotification*)aNotification
{
  [self log: [NSString stringWithFormat: @"windowDidMove. frame: %@ %@", 
		       NSStringFromRect([testWindow frame]), aNotification]];
}
- (void) windowDidResignKey: (NSNotification*)aNotification
{
  [self log: [NSString stringWithFormat: @"windowDidResignKey %@", aNotification]];
}
- (void) windowDidResignMain: (NSNotification*)aNotification
{
  [self log: [NSString stringWithFormat: @"windowDidResignMain %@", aNotification]];
}
- (void) windowDidResize: (NSNotification*)aNotification
{
  [self log: [NSString stringWithFormat: @"windowDidResize %@", aNotification]];
}
/*
- (void) windowDidUpdate: (NSNotification*)aNotification
{
  [self log: [NSString stringWithFormat: @"windowDidUpdate %@", aNotification]];
}
*/
- (void) windowWillClose: (NSNotification*)aNotification
{
  [self log: [NSString stringWithFormat: @"windowWillClose %@", aNotification]];
}
- (void) windowWillMiniaturize: (NSNotification*)aNotification
{
  [self log: [NSString stringWithFormat: @"windowWillMiniaturize %@", aNotification]];
}
- (void) windowWillMove: (NSNotification*)aNotification
{
  [self log: [NSString stringWithFormat: @"windowWillMove %@", aNotification]];
}

@end