1
- /*
1
+ /*
2
2
* ImageWindow.m
3
3
*/
4
4
@@ -25,29 +25,28 @@ - (void)setScaleView:(NSView *)scale
25
25
- (void )tile
26
26
{
27
27
NSScroller *hScroller = [self horizontalScroller ];
28
- NSRect hsFrame;
28
+ NSRect hsFrame;
29
29
30
30
[super tile ];
31
31
32
32
hsFrame = [hScroller frame ];
33
- hsFrame.size .width -= [scaleBtn frame ].size .width + 2 ;
33
+ hsFrame.size .width -= [scaleBtn frame ].size .width + 2 ;
34
34
[hScroller setFrame: hsFrame];
35
35
}
36
36
37
37
- (void )drawRect : (NSRect )rect
38
38
{
39
- NSRect hsFrame = [[self horizontalScroller ] frame ];
40
- NSPoint lineStart, lineEnd;
39
+ NSRect hsFrame = [[self horizontalScroller ] frame ];
40
+ NSPoint lineStart, lineEnd;
41
41
NSGraphicsContext *ctxt = GSCurrentContext ();
42
42
43
43
[super drawRect: rect];
44
44
45
- if (_rFlags.flipped_view )
46
- {
47
- lineStart.x = hsFrame.origin .x + hsFrame.size .width ;
48
- lineStart.y = hsFrame.origin .y - 1 ;
49
- lineEnd.y = lineStart.y + hsFrame.size .height + 1 ;
50
- }
45
+ if ([self isFlipped ] != NO ) {
46
+ lineStart.x = hsFrame.origin .x + hsFrame.size .width ;
47
+ lineStart.y = hsFrame.origin .y - 1 ;
48
+ lineEnd.y = lineStart.y + hsFrame.size .height + 1 ;
49
+ }
51
50
52
51
DPSsetgray (ctxt, 0.0 );
53
52
DPSsetlinewidth (ctxt, 1.0 );
@@ -70,137 +69,129 @@ @implementation ImageWindow
70
69
71
70
- (id )initWithContentsOfFile : (NSString *)path
72
71
{
73
- NSAssert (path,@" No path specified!" );
74
-
75
- if ((self = [super init ]))
76
- {
77
- NSRect frame = NSMakeRect (0 ,0 ,0 ,0 );
78
- RScrollView *scrollView = nil ;
79
- NSImageView *imageView = nil ;
80
- NSImage *image;
81
- NSArray *array;
82
- int wMask = (NSTitledWindowMask
83
- | NSClosableWindowMask
84
- | NSMiniaturizableWindowMask
85
- | NSResizableWindowMask );
86
-
87
- attr = [[NSFileManager defaultManager ] fileAttributesAtPath: path
88
- traverseLink: NO ];
89
- RETAIN (attr);
90
-
91
- // Image loading
92
- imagePath = [path copy ];
93
- if (!(image = [[NSImage alloc ] initWithContentsOfFile: path]))
94
- {
95
- NSRunAlertPanel (@" Open file" ,
96
- @" File %@ doesn't contain image %@ " ,
97
- @" Dismiss" , nil , nil , path, image);
98
- return nil ;
99
- }
100
-
101
- // Image
102
- [image setBackgroundColor: [NSColor lightGrayColor ]];
103
- array = [image representations ];
104
- reps = [array count ];
105
- rep = [array objectAtIndex: 0 ];
106
-
107
- if (rep == nil )
108
- {
109
- return nil ;
110
- }
111
- [rep retain ];
112
-
113
- imageSize = [image size ];
114
- frame.size = imageSize;
115
-
116
- // ImageView and ScrollView
117
- imageView = [[NSImageView alloc ] initWithFrame: frame];
118
- [imageView setEditable: NO ];
119
- [imageView setImage: image];
120
- RELEASE (image);
121
-
122
- frame.size = [NSScrollView frameSizeForContentSize: [imageView frame ].size
123
- hasHorizontalScroller: YES
124
- hasVerticalScroller: YES
125
- borderType: NSNoBorder];
126
- scrollView = [[RScrollView alloc ] initWithFrame: frame];
127
- [scrollView setHasVerticalScroller: YES ];
128
- [scrollView setHasHorizontalScroller: YES ];
129
- [scrollView setBorderType: NSNoBorder];
130
- [scrollView setDocumentView: imageView];
131
- RELEASE (imageView);
132
- [scrollView setAutoresizingMask: (NSViewWidthSizable |
133
- NSViewHeightSizable)];
134
- // Content view
135
- box = [[NSBox alloc ] init ];
136
- [box setTitlePosition: NSNoTitle];
137
- [box setBorderType: NSNoBorder];
138
- [box setAutoresizingMask: NSViewWidthSizable | NSViewHeightSizable];
139
- [box setContentViewMargins: NSMakeSize (0.0 , 0.0 )];
140
- [box setFrameFromContentFrame: frame];
141
-
142
- // Popup
143
- scalePopup = [[NSPopUpButton alloc ]
144
- initWithFrame: NSMakeRect ([box frame ].size.width-57 , 0 , 57 , 17 )];
145
- [scalePopup setRefusesFirstResponder: YES ];
146
- [scalePopup addItemWithTitle: @" 10%" ];
147
- [scalePopup addItemWithTitle: @" 20%" ];
148
- [scalePopup addItemWithTitle: @" 30%" ];
149
- [scalePopup addItemWithTitle: @" 40%" ];
150
- [scalePopup addItemWithTitle: @" 50%" ];
151
- [scalePopup addItemWithTitle: @" 60%" ];
152
- [scalePopup addItemWithTitle: @" 70%" ];
153
- [scalePopup addItemWithTitle: @" 80%" ];
154
- [scalePopup addItemWithTitle: @" 90%" ];
155
- [scalePopup addItemWithTitle: @" 100%" ];
156
- [scalePopup addItemWithTitle: @" 200%" ];
157
- [scalePopup addItemWithTitle: @" 300%" ];
158
- [scalePopup addItemWithTitle: @" 400%" ];
159
- [scalePopup addItemWithTitle: @" 500%" ];
160
- [scalePopup addItemWithTitle: @" 600%" ];
161
- [scalePopup addItemWithTitle: @" 700%" ];
162
- [scalePopup setAutoresizingMask: (NSViewMaxYMargin | NSViewMinXMargin)];
163
- [scalePopup selectItemWithTitle: @" 100%" ];
164
- [scrollView setScaleView: scalePopup];
165
- [scrollView tile ];
166
-
167
- [box addSubview: scrollView];
168
- RELEASE (scrollView);
169
- [box addSubview: scalePopup];
170
- RELEASE (scalePopup);
171
-
172
- // Window
173
- frame = [NSWindow frameRectForContentRect: frame styleMask: wMask];
174
- if (imageSize.width > ([[NSScreen mainScreen ] frame ].size .width -64 ))
175
- {
176
- frame.size .width = [[NSScreen mainScreen ] frame ].size .width -164 ;
177
- }
178
- if (imageSize.height > ([[NSScreen mainScreen ] frame ].size .height -64 ))
179
- {
180
- frame.size .height = [[NSScreen mainScreen ] frame ].size .height -64 ;
181
- }
182
- if (frame.size .width < 100 ) frame.size .width = 100 ;
183
- if (frame.size .height < 100 ) frame.size .height = 100 ;
184
-
185
- window = [[NSWindow alloc ] initWithContentRect: frame
186
- styleMask: wMask
187
- backing: NSBackingStoreRetained
188
- defer: YES ];
189
- [window setReleasedWhenClosed: YES ];
190
- [window setDelegate: self ];
191
- [window setFrame: frame display: YES ];
192
- [window setMaxSize: frame.size];
193
- [window setMinSize: NSMakeSize (100 ,100 )];
194
- [window setContentView: box];
195
- RELEASE (box);
196
- [window setTitleWithRepresentedFilename: path];
197
- [window setReleasedWhenClosed: YES ];
198
-
199
- [window center ];
200
- [window makeKeyAndOrderFront: nil ];
201
- [window display ];
72
+ NSAssert (path, @" No path specified!" );
73
+
74
+ if ((self = [super init ])) {
75
+ NSRect frame = NSMakeRect (0 , 0 , 0 , 0 );
76
+ RScrollView *scrollView = nil ;
77
+ NSImageView *imageView = nil ;
78
+ NSImage *image;
79
+ NSArray *array;
80
+ int wMask = (NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask |
81
+ NSResizableWindowMask );
82
+
83
+ attr = [[NSFileManager defaultManager ] fileAttributesAtPath: path traverseLink: NO ];
84
+ RETAIN (attr);
85
+
86
+ // Image loading
87
+ imagePath = [path copy ];
88
+ if (!(image = [[NSImage alloc ] initWithContentsOfFile: path])) {
89
+ NSRunAlertPanel (@" Open file" , @" File %@ doesn't contain image %@ " , @" Dismiss" , nil , nil , path,
90
+ image);
91
+ return nil ;
202
92
}
203
93
94
+ // Image
95
+ [image setBackgroundColor: [NSColor lightGrayColor ]];
96
+ array = [image representations ];
97
+ reps = [array count ];
98
+ rep = [array objectAtIndex: 0 ];
99
+
100
+ if (rep == nil ) {
101
+ return nil ;
102
+ }
103
+ [rep retain ];
104
+
105
+ imageSize = [image size ];
106
+ frame.size = imageSize;
107
+
108
+ // ImageView and ScrollView
109
+ imageView = [[NSImageView alloc ] initWithFrame: frame];
110
+ [imageView setEditable: NO ];
111
+ [imageView setImage: image];
112
+ RELEASE (image);
113
+
114
+ frame.size = [NSScrollView frameSizeForContentSize: [imageView frame ].size
115
+ hasHorizontalScroller: YES
116
+ hasVerticalScroller: YES
117
+ borderType: NSNoBorder];
118
+ scrollView = [[RScrollView alloc ] initWithFrame: frame];
119
+ [scrollView setHasVerticalScroller: YES ];
120
+ [scrollView setHasHorizontalScroller: YES ];
121
+ [scrollView setBorderType: NSNoBorder];
122
+ [scrollView setDocumentView: imageView];
123
+ RELEASE (imageView);
124
+ [scrollView setAutoresizingMask: (NSViewWidthSizable | NSViewHeightSizable)];
125
+ // Content view
126
+ box = [[NSBox alloc ] init ];
127
+ [box setTitlePosition: NSNoTitle];
128
+ [box setBorderType: NSNoBorder];
129
+ [box setAutoresizingMask: NSViewWidthSizable | NSViewHeightSizable];
130
+ [box setContentViewMargins: NSMakeSize (0.0 , 0.0 )];
131
+ [box setFrameFromContentFrame: frame];
132
+
133
+ // Popup
134
+ scalePopup =
135
+ [[NSPopUpButton alloc ] initWithFrame: NSMakeRect ([box frame ].size.width - 57 , 0 , 57 , 17 )];
136
+ [scalePopup setRefusesFirstResponder: YES ];
137
+ [scalePopup addItemWithTitle: @" 10%" ];
138
+ [scalePopup addItemWithTitle: @" 20%" ];
139
+ [scalePopup addItemWithTitle: @" 30%" ];
140
+ [scalePopup addItemWithTitle: @" 40%" ];
141
+ [scalePopup addItemWithTitle: @" 50%" ];
142
+ [scalePopup addItemWithTitle: @" 60%" ];
143
+ [scalePopup addItemWithTitle: @" 70%" ];
144
+ [scalePopup addItemWithTitle: @" 80%" ];
145
+ [scalePopup addItemWithTitle: @" 90%" ];
146
+ [scalePopup addItemWithTitle: @" 100%" ];
147
+ [scalePopup addItemWithTitle: @" 200%" ];
148
+ [scalePopup addItemWithTitle: @" 300%" ];
149
+ [scalePopup addItemWithTitle: @" 400%" ];
150
+ [scalePopup addItemWithTitle: @" 500%" ];
151
+ [scalePopup addItemWithTitle: @" 600%" ];
152
+ [scalePopup addItemWithTitle: @" 700%" ];
153
+ [scalePopup setAutoresizingMask: (NSViewMaxYMargin | NSViewMinXMargin)];
154
+ [scalePopup selectItemWithTitle: @" 100%" ];
155
+ [scrollView setScaleView: scalePopup];
156
+ [scrollView tile ];
157
+
158
+ [box addSubview: scrollView];
159
+ RELEASE (scrollView);
160
+ [box addSubview: scalePopup];
161
+ RELEASE (scalePopup);
162
+
163
+ // Window
164
+ frame = [NSWindow frameRectForContentRect: frame styleMask: wMask];
165
+ if (imageSize.width > ([[NSScreen mainScreen ] frame ].size .width - 64 )) {
166
+ frame.size .width = [[NSScreen mainScreen ] frame ].size .width - 164 ;
167
+ }
168
+ if (imageSize.height > ([[NSScreen mainScreen ] frame ].size .height - 64 )) {
169
+ frame.size .height = [[NSScreen mainScreen ] frame ].size .height - 64 ;
170
+ }
171
+ if (frame.size .width < 100 )
172
+ frame.size .width = 100 ;
173
+ if (frame.size .height < 100 )
174
+ frame.size .height = 100 ;
175
+
176
+ window = [[NSWindow alloc ] initWithContentRect: frame
177
+ styleMask: wMask
178
+ backing: NSBackingStoreRetained
179
+ defer: YES ];
180
+ [window setReleasedWhenClosed: YES ];
181
+ [window setDelegate: self ];
182
+ [window setFrame: frame display: YES ];
183
+ [window setMaxSize: frame.size];
184
+ [window setMinSize: NSMakeSize (100 , 100 )];
185
+ [window setContentView: box];
186
+ RELEASE (box);
187
+ [window setTitleWithRepresentedFilename: path];
188
+ [window setReleasedWhenClosed: YES ];
189
+
190
+ [window center ];
191
+ [window makeKeyAndOrderFront: nil ];
192
+ [window display ];
193
+ }
194
+
204
195
return self;
205
196
}
206
197
@@ -226,24 +217,20 @@ - (void)setDelegate:(id)aDelegate
226
217
227
218
- (void )windowWillClose : (NSNotification *)notif
228
219
{
229
- if ([[notif object ] isEqual: window])
230
- {
231
- if (delegate &&
232
- [delegate respondsToSelector: @selector (imageWindowWillClose: )])
233
- {
234
- [delegate imageWindowWillClose: self ];
235
- [window setDelegate: nil ];
236
- window = nil ;
237
- }
238
- }
220
+ if ([[notif object ] isEqual: window]) {
221
+ if (delegate && [delegate respondsToSelector: @selector (imageWindowWillClose: )]) {
222
+ [delegate imageWindowWillClose: self ];
223
+ [window setDelegate: nil ];
224
+ window = nil ;
225
+ }
226
+ }
239
227
}
240
228
241
229
- (void )windowDidBecomeKey : (NSNotification *)aNotification
242
230
{
243
- if ( [[aNotification object ] isEqual: window] )
244
- {
245
- [[Inspector sharedInspector ] imageWindowDidBecomeActive: self ];
246
- }
231
+ if ([[aNotification object ] isEqual: window]) {
232
+ [[Inspector sharedInspector ] imageWindowDidBecomeActive: self ];
233
+ }
247
234
}
248
235
249
236
- (NSString *)path
@@ -270,7 +257,7 @@ - (NSString *)imageSize
270
257
{
271
258
int bytes = [[attr objectForKey: @" NSFileSize" ] intValue ];
272
259
273
- return [NSString stringWithFormat: @" %d Bytes" ,bytes];
260
+ return [NSString stringWithFormat: @" %d Bytes" , bytes];
274
261
}
275
262
276
263
- (NSString *)imageFileModificationDate
@@ -296,12 +283,12 @@ - (NSString *)imageFileOwner
296
283
297
284
- (NSString *)imageResolution
298
285
{
299
- return [NSString stringWithFormat: @" %.1f x %.1f " ,imageSize.width,imageSize.height];
286
+ return [NSString stringWithFormat: @" %.1f x %.1f " , imageSize.width, imageSize.height];
300
287
}
301
288
302
289
- (NSString *)bitsPerSample
303
290
{
304
- return [NSString stringWithFormat: @" %ld " ,[rep bitsPerSample ]];
291
+ return [NSString stringWithFormat: @" %ld " , [rep bitsPerSample ]];
305
292
}
306
293
307
294
- (NSString *)colorSpaceName
@@ -311,12 +298,12 @@ - (NSString *)colorSpaceName
311
298
312
299
- (NSString *)hasAlpha
313
300
{
314
- return [NSString stringWithFormat: @" %@ " ,[rep hasAlpha ]? @" Yes" : @" No" ];
301
+ return [NSString stringWithFormat: @" %@ " , [rep hasAlpha ] ? @" Yes" : @" No" ];
315
302
}
316
303
317
304
- (NSString *)imageReps
318
305
{
319
- return [NSString stringWithFormat: @" %d " ,reps];
306
+ return [NSString stringWithFormat: @" %d " , reps];
320
307
}
321
308
322
309
@end
0 commit comments