/[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.3 - (show annotations) (download)
Tue Sep 30 15:38:04 2003 UTC (20 years, 7 months ago) by esersale
Branch: MAIN
Changes since 1.2: +1 -8 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 NSTextField *widthLabel, *heightLabel;
61
62 [self setFrame: frame];
63 panel = (id<InspectorsProtocol>)apanel;
64 fm = [NSFileManager defaultManager];
65 ws = [NSWorkspace sharedWorkspace];
66
67 index = idx;
68
69 ASSIGN (extsarr, [GWLib imageExtensions]);
70
71 imrect = NSMakeRect(0, 30, 257, 215);
72 imview = [[NSImageView alloc] initWithFrame: imrect];
73 [imview setImageFrameStyle: NSImageFrameGrayBezel];
74 [imview setImageAlignment: NSImageAlignCenter];
75 [self addSubview: imview];
76
77 widthLabel = [[NSTextField alloc] initWithFrame: NSMakeRect(5,2,40, 20)];
78 [widthLabel setAlignment: NSRightTextAlignment];
79 [widthLabel setBackgroundColor: [NSColor windowBackgroundColor]];
80 [widthLabel setBezeled: NO];
81 [widthLabel setEditable: NO];
82 [widthLabel setSelectable: NO];
83 [widthLabel setStringValue: @"Width :"];
84 [self addSubview: widthLabel];
85 RELEASE(widthLabel);
86
87 widthResult = [[NSTextField alloc] initWithFrame: NSMakeRect(45,2,40, 20)];
88 [widthResult setAlignment: NSRightTextAlignment];
89 [widthResult setBackgroundColor: [NSColor windowBackgroundColor]];
90 [widthResult setBezeled: NO];
91 [widthResult setEditable: NO];
92 [widthResult setSelectable: NO];
93 [widthResult setStringValue: @""];
94 [self addSubview: widthResult];
95
96 heightLabel = [[NSTextField alloc] initWithFrame: NSMakeRect(160,2,40, 20)];
97 [heightLabel setAlignment: NSRightTextAlignment];
98 [heightLabel setBackgroundColor: [NSColor windowBackgroundColor]];
99 [heightLabel setBezeled: NO];
100 [heightLabel setEditable: NO];
101 [heightLabel setSelectable: NO];
102 [heightLabel setStringValue: @"Height :"];
103 [self addSubview: heightLabel];
104 RELEASE(heightLabel);
105
106 heightResult = [[NSTextField alloc] initWithFrame: NSMakeRect(200,2,40, 20)];
107 [heightResult setAlignment: NSRightTextAlignment];
108 [heightResult setBackgroundColor: [NSColor windowBackgroundColor]];
109 [heightResult setBezeled: NO];
110 [heightResult setEditable: NO];
111 [heightResult setSelectable: NO];
112 [heightResult setStringValue: @""];
113 [self addSubview:heightResult];
114
115 //label if error
116 label = [[NSTextField alloc] initWithFrame: NSMakeRect(2, 133, 255, 25)];
117 [label setFont: [NSFont systemFontOfSize: 18]];
118 [label setAlignment: NSCenterTextAlignment];
119 [label setBackgroundColor: [NSColor windowBackgroundColor]];
120 [label setTextColor: [NSColor grayColor]];
121 [label setBezeled: NO];
122 [label setEditable: NO];
123 [label setSelectable: NO];
124 [label setStringValue: @"Invalid Contents"];
125
126 valid = YES;
127 }
128
129 return self;
130 }
131
132 - (void)setBundlePath:(NSString *)path
133 {
134 ASSIGN (bundlePath, path);
135 }
136
137 - (NSString *)bundlePath
138 {
139 return bundlePath;
140 }
141
142 - (void)setIndex:(int)idx
143 {
144 index = idx;
145 }
146
147 - (void)activateForPath:(NSString *)path
148 {
149 NSImage *image = [[NSImage alloc] initWithContentsOfFile: path];
150
151 buttOk = [panel okButton];
152 if (buttOk) {
153 [buttOk setTarget: self];
154 [buttOk setAction: @selector(editFile:)];
155 }
156
157 if (image != nil) {
158 NSSize is = [image size];
159 NSSize rs = imrect.size;
160 NSSize size;
161
162 ASSIGN (editPath, path);
163
164 if (valid == NO) {
165 valid = YES;
166 [label removeFromSuperview];
167 [self addSubview: imview];
168 }
169
170 if ((is.width <= rs.width) && (is.height <= rs.height)) {
171 [imview setImageScaling: NSScaleNone];
172 }
173 else {
174 [imview setImageScaling: NSScaleProportionally];
175 }
176
177 [imview setImage: image];
178 size = [image size];
179 [widthResult setStringValue: [[NSNumber numberWithInt: size.width] stringValue]];
180 [heightResult setStringValue:[[NSNumber numberWithInt: size.height] stringValue]];
181
182 RELEASE (image);
183 [buttOk setEnabled: YES];
184 } else {
185 if (valid == YES) {
186 valid = NO;
187 [imview removeFromSuperview];
188 [self addSubview: label];
189 [buttOk setEnabled: NO];
190 }
191 }
192 }
193
194 - (BOOL)stopTasks
195 {
196 return YES;
197 }
198
199 - (void)deactivate
200 {
201 [self removeFromSuperview];
202 }
203
204 - (BOOL)canDisplayFileAtPath:(NSString *)path
205 {
206 NSDictionary *attributes;
207 NSString *defApp, *fileType, *extension;
208
209 attributes = [[NSFileManager defaultManager] fileAttributesAtPath: path
210 traverseLink: YES];
211 if ([attributes objectForKey: NSFileType] == NSFileTypeDirectory) {
212 return NO;
213 }
214
215 [ws getInfoForFile: path application: &defApp type: &fileType];
216 extension = [path pathExtension];
217
218 if(([fileType isEqual: NSPlainFileType] == NO)
219 && ([fileType isEqual: NSShellCommandFileType] == NO)) {
220 return NO;
221 }
222
223 if ([extsarr containsObject: extension]) {
224 return YES;
225 }
226
227 return NO;
228 }
229
230 - (int)index
231 {
232 return index;
233 }
234
235 - (NSString *)winname
236 {
237 return NSLocalizedString(@"Image Inspector", @"");
238 }
239
240 - (void)editFile:(id)sender
241 {
242 NSString *appName;
243 NSString *type;
244
245 [ws getInfoForFile: editPath application: &appName type: &type];
246
247 if (appName != nil) {
248 [ws openFile: editPath withApplication: appName];
249 }
250 }
251
252 @end

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