/[gnustep]/gnustep/usr-apps/gworkspace/ContentViewers/ImageViewer/ImageViewer.m
ViewVC logotype

Contents of /gnustep/usr-apps/gworkspace/ContentViewers/ImageViewer/ImageViewer.m

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (show annotations) (download)
Mon Aug 25 17:19:13 2003 UTC (20 years, 8 months ago) by esersale
Branch: MAIN
Changes since 1.1: +19 -18 lines
*** empty log message ***

1 /* ImageViewer.m
2 *
3 * Copyright (C) 2003 Free Software Foundation, Inc.
4 *
5 * Author: Enrico Sersale <enrico@imago.ro>
6 * Date: August 2001
7 *
8 * This file is part of the GNUstep GWorkspace application
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 */
24
25
26 #include <Foundation/Foundation.h>
27 #include <AppKit/AppKit.h>
28 #ifdef GNUSTEP
29 #include "GWProtocol.h"
30 #include "InspectorsProtocol.h"
31 #include "GWLib.h"
32 #else
33 #include <GWorkspace/GWProtocol.h>
34 #include <GWorkspace/InspectorsProtocol.h>
35 #include <GWorkspace/GWLib.h>
36 #endif
37 #include "ImageViewer.h"
38 #include "GNUstep.h"
39 #include <math.h>
40
41 @implementation ImageViewer
42
43 - (void)dealloc
44 {
45 RELEASE (extsarr);
46 TEST_RELEASE (imview);
47 TEST_RELEASE (widthResult);
48 TEST_RELEASE (heightResult);
49 RELEASE (label);
50 TEST_RELEASE (editPath);
51 RELEASE (bundlePath);
52 [super dealloc];
53 }
54
55 - (id)initInPanel:(id)apanel withFrame:(NSRect)frame index:(int)idx
56 {
57 self = [super init];
58
59 if(self) {
60 #ifdef GNUSTEP
61 Class gwclass = [[NSBundle mainBundle] principalClass];
62 #else
63 Class gwclass = [[NSBundle mainBundle] classNamed: @"GWorkspace"];
64 #endif
65 NSTextField *widthLabel, *heightLabel;
66
67 gworkspace = (id<GWProtocol>)[gwclass gworkspace];
68
69 [self setFrame: frame];
70 panel = (id<InspectorsProtocol>)apanel;
71 fm = [NSFileManager defaultManager];
72 ws = [NSWorkspace sharedWorkspace];
73
74 index = idx;
75
76 ASSIGN (extsarr, [gworkspace imageExtensions]);
77
78 imrect = NSMakeRect(0, 30, 257, 215);
79 imview = [[NSImageView alloc] initWithFrame: imrect];
80 [imview setImageFrameStyle: NSImageFrameGrayBezel];
81 [imview setImageAlignment: NSImageAlignCenter];
82 [self addSubview: imview];
83
84 widthLabel = [[NSTextField alloc] initWithFrame: NSMakeRect(5,2,40, 20)];
85 [widthLabel setAlignment: NSRightTextAlignment];
86 [widthLabel setBackgroundColor: [NSColor windowBackgroundColor]];
87 [widthLabel setBezeled: NO];
88 [widthLabel setEditable: NO];
89 [widthLabel setSelectable: NO];
90 [widthLabel setStringValue: @"Width :"];
91 [self addSubview: widthLabel];
92 RELEASE(widthLabel);
93
94 widthResult = [[NSTextField alloc] initWithFrame: NSMakeRect(45,2,40, 20)];
95 [widthResult setAlignment: NSRightTextAlignment];
96 [widthResult setBackgroundColor: [NSColor windowBackgroundColor]];
97 [widthResult setBezeled: NO];
98 [widthResult setEditable: NO];
99 [widthResult setSelectable: NO];
100 [widthResult setStringValue: @""];
101 [self addSubview: widthResult];
102
103 heightLabel = [[NSTextField alloc] initWithFrame: NSMakeRect(160,2,40, 20)];
104 [heightLabel setAlignment: NSRightTextAlignment];
105 [heightLabel setBackgroundColor: [NSColor windowBackgroundColor]];
106 [heightLabel setBezeled: NO];
107 [heightLabel setEditable: NO];
108 [heightLabel setSelectable: NO];
109 [heightLabel setStringValue: @"Height :"];
110 [self addSubview: heightLabel];
111 RELEASE(heightLabel);
112
113 heightResult = [[NSTextField alloc] initWithFrame: NSMakeRect(200,2,40, 20)];
114 [heightResult setAlignment: NSRightTextAlignment];
115 [heightResult setBackgroundColor: [NSColor windowBackgroundColor]];
116 [heightResult setBezeled: NO];
117 [heightResult setEditable: NO];
118 [heightResult setSelectable: NO];
119 [heightResult setStringValue: @""];
120 [self addSubview:heightResult];
121
122 //label if error
123 label = [[NSTextField alloc] initWithFrame: NSMakeRect(2, 133, 255, 25)];
124 [label setFont: [NSFont systemFontOfSize: 18]];
125 [label setAlignment: NSCenterTextAlignment];
126 [label setBackgroundColor: [NSColor windowBackgroundColor]];
127 [label setTextColor: [NSColor grayColor]];
128 [label setBezeled: NO];
129 [label setEditable: NO];
130 [label setSelectable: NO];
131 [label setStringValue: @"Invalid Contents"];
132
133 valid = YES;
134 }
135
136 return self;
137 }
138
139 - (void)setBundlePath:(NSString *)path
140 {
141 ASSIGN (bundlePath, path);
142 }
143
144 - (NSString *)bundlePath
145 {
146 return bundlePath;
147 }
148
149 - (void)setIndex:(int)idx
150 {
151 index = idx;
152 }
153
154 - (void)activateForPath:(NSString *)path
155 {
156 NSImage *image = [[NSImage alloc] initWithContentsOfFile: path];
157
158 buttOk = [panel okButton];
159 if (buttOk) {
160 [buttOk setTarget: self];
161 [buttOk setAction: @selector(editFile:)];
162 }
163
164 if (image != nil) {
165 NSSize is = [image size];
166 NSSize rs = imrect.size;
167 NSSize size;
168
169 ASSIGN (editPath, path);
170
171 if (valid == NO) {
172 valid = YES;
173 [label removeFromSuperview];
174 [self addSubview: imview];
175 }
176
177 if ((is.width <= rs.width) && (is.height <= rs.height)) {
178 [imview setImageScaling: NSScaleNone];
179 }
180 else {
181 [imview setImageScaling: NSScaleProportionally];
182 }
183
184 [imview setImage: image];
185 size = [image size];
186 [widthResult setStringValue: [[NSNumber numberWithInt: size.width] stringValue]];
187 [heightResult setStringValue:[[NSNumber numberWithInt: size.height] stringValue]];
188
189 RELEASE (image);
190 [buttOk setEnabled: YES];
191 } else {
192 if (valid == YES) {
193 valid = NO;
194 [imview removeFromSuperview];
195 [self addSubview: label];
196 [buttOk setEnabled: NO];
197 }
198 }
199 }
200
201 - (BOOL)stopTasks
202 {
203 return YES;
204 }
205
206 - (void)deactivate
207 {
208 [self removeFromSuperview];
209 }
210
211 - (BOOL)canDisplayFileAtPath:(NSString *)path
212 {
213 NSDictionary *attributes;
214 NSString *defApp, *fileType, *extension;
215
216 attributes = [[NSFileManager defaultManager] fileAttributesAtPath: path
217 traverseLink: YES];
218 if ([attributes objectForKey: NSFileType] == NSFileTypeDirectory) {
219 return NO;
220 }
221
222 [ws getInfoForFile: path application: &defApp type: &fileType];
223 extension = [path pathExtension];
224
225 if(([fileType isEqual: NSPlainFileType] == NO)
226 && ([fileType isEqual: NSShellCommandFileType] == NO)) {
227 return NO;
228 }
229
230 if ([extsarr containsObject: extension]) {
231 return YES;
232 }
233
234 return NO;
235 }
236
237 - (int)index
238 {
239 return index;
240 }
241
242 - (NSString *)winname
243 {
244 return NSLocalizedString(@"Image Inspector", @"");
245 }
246
247 - (void)editFile:(id)sender
248 {
249 NSString *appName;
250 NSString *type;
251
252 [ws getInfoForFile: editPath application: &appName type: &type];
253
254 if (appName != nil) {
255 [ws openFile: editPath withApplication: appName];
256 }
257 }
258
259 @end

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26