/[gnustep]/gnustep/usr-apps/gworkspace/GWorkspace/Preferences/DeskTopPref.m
ViewVC logotype

Contents of /gnustep/usr-apps/gworkspace/GWorkspace/Preferences/DeskTopPref.m

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.5 - (show annotations) (download)
Tue Sep 30 15:38:05 2003 UTC (20 years, 6 months ago) by esersale
Branch: MAIN
Changes since 1.4: +2 -0 lines
*** empty log message ***

1 /* DeskTopPref.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 "GWLib.h"
30 #include "GWFunctions.h"
31 #include "GWNotifications.h"
32 #else
33 #include <GWorkspace/GWLib.h>
34 #include <GWorkspace/GWFunctions.h>
35 #include <GWorkspace/GWNotifications.h>
36 #endif
37 #include "DeskTopPref.h"
38 #include "GWorkspace.h"
39 #include "GNUstep.h"
40
41 static NSString *nibName = @"DeskTopPref";
42
43 @implementation ColorView
44
45 - (void)dealloc
46 {
47 TEST_RELEASE (color);
48 [super dealloc];
49 }
50
51 - (id)init
52 {
53 self = [super init];
54 color = nil;
55 return self;
56 }
57
58 - (void)setColor:(NSColor *)c
59 {
60 ASSIGN (color, c);
61 }
62
63 - (void)drawRect:(NSRect)rect
64 {
65 NSRect bounds = [self bounds];
66 float x = rect.origin.x + 2;
67 float y = rect.origin.y + 2;
68 float w = rect.size.width - 4;
69 float h = rect.size.height - 4;
70 NSRect colorRect = NSMakeRect(x, y, w, h);
71
72 [super drawRect: rect];
73
74 NSDrawGrayBezel(bounds, rect);
75
76 if (color != nil) {
77 [color set];
78 NSRectFill(colorRect);
79 }
80 }
81
82 @end
83
84 @implementation DeskTopPref
85
86 - (void)dealloc
87 {
88 TEST_RELEASE (prefbox);
89 RELEASE (colorsView);
90 TEST_RELEASE (color);
91 [super dealloc];
92 }
93
94 - (id)init
95 {
96 self = [super init];
97
98 if (self) {
99 if ([NSBundle loadNibNamed: nibName owner: self] == NO) {
100 NSLog(@"failed to load %@!", nibName);
101 } else {
102 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
103 NSDictionary *desktopViewPrefs = [defaults dictionaryForKey: @"desktopviewprefs"];
104 NSString *imagePath = nil;
105
106 RETAIN (prefbox);
107 RELEASE (win);
108
109 gw = [GWorkspace gworkspace];
110
111 deskactive = [defaults boolForKey: @"desktop"];
112
113 if (desktopViewPrefs != nil) {
114 id dictEntry = [desktopViewPrefs objectForKey: @"backcolor"];
115
116 imagePath = [desktopViewPrefs objectForKey: @"imagepath"];
117
118 if(dictEntry == nil) {
119 ASSIGN (color, [NSColor windowBackgroundColor]);
120 } else {
121 NSString *cs;
122
123 cs = [dictEntry objectForKey: @"red"];
124 [redField setStringValue: cs];
125 r = [cs floatValue];
126 [redSlider setFloatValue: r];
127 cs = [dictEntry objectForKey: @"green"];
128 [greenField setStringValue: cs];
129 g = [cs floatValue];
130 [greenSlider setFloatValue: g];
131 cs = [dictEntry objectForKey: @"blue"];
132 [blueField setStringValue: cs];
133 b = [cs floatValue];
134 [blueSlider setFloatValue: b];
135 alpha = [[dictEntry objectForKey: @"alpha"] floatValue];
136 ASSIGN (color, [NSColor colorWithCalibratedRed: r green: g blue: b alpha: alpha]);
137 }
138 } else {
139 imagePath = nil;
140 ASSIGN (color, [NSColor windowBackgroundColor]);
141 }
142
143 colorsView = [[ColorView alloc] init];
144 [colorsView setFrame: NSMakeRect(0, 0, 64, 64)];
145 [colorsView setColor: color];
146 [colorsBox addSubview: colorsView];
147
148 if(imagePath != nil) {
149 [setImageButt setTitle: NSLocalizedString(@"Unset Image", @"")];
150 [setImageButt setAction: @selector(unsetImage:)];
151 } else {
152 [setImageButt setTitle: NSLocalizedString(@"Set Image", @"")];
153 [setImageButt setAction: @selector(chooseImage:)];
154 }
155
156 /* Internationalization */
157 [controlsbox setTitle: NSLocalizedString(@"Desktop Color", @"")];
158 [setColorButt setTitle: NSLocalizedString(@"Set", @"")];
159 [redlabel setStringValue: NSLocalizedString(@"red", @"")];
160 [greenlabel setStringValue: NSLocalizedString(@"green", @"")];
161 [bluelabel setStringValue: NSLocalizedString(@"blue", @"")];
162
163 [(NSButton *)chooseDeskButt setState: deskactive];
164 [self setDeskState: chooseDeskButt];
165 }
166 }
167
168 return self;
169 }
170
171 - (NSView *)prefView
172 {
173 return prefbox;
174 }
175
176 - (NSString *)prefName
177 {
178 return NSLocalizedString(@"Desktop", @"");
179 }
180
181 - (IBAction)setDeskState:(id)sender
182 {
183 if ([sender state] == NSOnState) {
184 deskactive = YES;
185 [chooseDeskButt setTitle: NSLocalizedString(@"Deactivate desktop", @"")];
186 [redSlider setEnabled: YES];
187 [greenSlider setEnabled: YES];
188 [blueSlider setEnabled: YES];
189 [colorsView setColor: color];
190 [colorsView setNeedsDisplay: YES];
191 [setColorButt setEnabled: YES];
192 [setImageButt setEnabled: YES];
193 } else {
194 deskactive = NO;
195 [chooseDeskButt setTitle: NSLocalizedString(@"Activate desktop", @"")];
196 [redSlider setEnabled: NO];
197 [greenSlider setEnabled: NO];
198 [blueSlider setEnabled: NO];
199 [colorsView setColor: [NSColor windowBackgroundColor]];
200 [colorsView setNeedsDisplay: YES];
201 [setColorButt setEnabled: NO];
202 [setImageButt setEnabled: NO];
203 }
204
205 [gw showHideDesktop: deskactive];
206 }
207
208 - (IBAction)makeColor:(id)sender
209 {
210 if (sender == redSlider) {
211 r = [sender floatValue];
212 [redField setStringValue: [NSString stringWithFormat: @"%.2f", r]];
213 } else if (sender == greenSlider) {
214 g = [sender floatValue];
215 [greenField setStringValue: [NSString stringWithFormat: @"%.2f", g]];
216 } else if (sender == blueSlider) {
217 b = [sender floatValue];
218 [blueField setStringValue: [NSString stringWithFormat: @"%.2f", b]];
219 }
220
221 ASSIGN (color, [NSColor colorWithCalibratedRed: r green: g blue: b alpha: 1]);
222 [colorsView setColor: color];
223 [colorsView setNeedsDisplay: YES];
224 }
225
226 - (IBAction)setColor:(id)sender
227 {
228 NSUserDefaults *defaults;
229 NSMutableDictionary *desktopViewPrefs, *colorDict;
230 id dictEntry;
231
232 defaults = [NSUserDefaults standardUserDefaults];
233
234 dictEntry = [defaults dictionaryForKey: @"desktopviewprefs"];
235 if (dictEntry == nil) {
236 desktopViewPrefs = [[NSMutableDictionary alloc] initWithCapacity: 1];
237 } else {
238 desktopViewPrefs = [dictEntry mutableCopy];
239 }
240
241 colorDict = [NSMutableDictionary dictionaryWithCapacity: 1];
242 [colorDict setObject: [NSString stringWithFormat: @"%f", r] forKey: @"red"];
243 [colorDict setObject: [NSString stringWithFormat: @"%f", g] forKey: @"green"];
244 [colorDict setObject: [NSString stringWithFormat: @"%f", b] forKey: @"blue"];
245 [colorDict setObject: @"1.0" forKey: @"alpha"];
246
247 [desktopViewPrefs setObject: colorDict forKey: @"backcolor"];
248 [defaults setObject: desktopViewPrefs forKey: @"desktopviewprefs"];
249 [defaults synchronize];
250 RELEASE (desktopViewPrefs);
251
252 [[NSNotificationCenter defaultCenter]
253 postNotificationName: GWDesktopViewColorChangedNotification
254 object: colorDict];
255 }
256
257 - (IBAction)chooseImage:(id)sender
258 {
259 NSOpenPanel *openPanel;
260 NSArray *fileTypes;
261 NSString *imagePath;
262 int result;
263 NSUserDefaults *defaults;
264 NSMutableDictionary *desktopViewPrefs;
265 id dictEntry;
266
267 fileTypes = [NSArray arrayWithObjects: @"tiff", @"tif", @"TIFF", @"TIFF", @"jpeg", @"jpg", @"JPEG", @"JPG", nil];
268
269 openPanel = [NSOpenPanel openPanel];
270 [openPanel setTitle: @"open"];
271 [openPanel setAllowsMultipleSelection: NO];
272 [openPanel setCanChooseFiles: YES];
273 [openPanel setCanChooseDirectories: NO];
274
275 result = [openPanel runModalForDirectory: NSHomeDirectory() file: nil types: fileTypes];
276 if(result != NSOKButton) {
277 return;
278 }
279
280 imagePath = [NSString stringWithString: [openPanel filename]];
281 [setImageButt setTitle: @"Unset Image"];
282 [setImageButt setAction: @selector(unsetImage:)];
283 [setImageButt setNeedsDisplay: YES];
284
285 defaults = [NSUserDefaults standardUserDefaults];
286 dictEntry = [defaults dictionaryForKey: @"desktopviewprefs"];
287 if (dictEntry == nil) {
288 desktopViewPrefs = [[NSMutableDictionary alloc] initWithCapacity: 1];
289 } else {
290 desktopViewPrefs = [dictEntry mutableCopy];
291 }
292 [desktopViewPrefs setObject: imagePath forKey: @"imagepath"];
293 [defaults setObject: desktopViewPrefs forKey: @"desktopviewprefs"];
294 [defaults synchronize];
295 RELEASE (desktopViewPrefs);
296
297 [[NSNotificationCenter defaultCenter]
298 postNotificationName: GWDesktopViewImageChangedNotification
299 object: imagePath];
300 }
301
302 - (IBAction)unsetImage:(id)sender
303 {
304 NSUserDefaults *defaults;
305 NSMutableDictionary *desktopViewPrefs;
306 NSString *imagePath;
307 id dictEntry;
308
309 defaults = [NSUserDefaults standardUserDefaults];
310
311 dictEntry = [defaults dictionaryForKey: @"desktopviewprefs"];
312 if (dictEntry != nil) {
313 desktopViewPrefs = [dictEntry mutableCopy];
314 imagePath = [desktopViewPrefs objectForKey: @"imagepath"];
315 if(imagePath != nil) {
316 [desktopViewPrefs removeObjectForKey: @"imagepath"];
317 [defaults setObject: desktopViewPrefs forKey: @"desktopviewprefs"];
318 [defaults synchronize];
319 }
320 RELEASE (desktopViewPrefs);
321 }
322
323 [setImageButt setTitle: @"Set Image"];
324 [setImageButt setAction: @selector(chooseImage:)];
325 [setImageButt setNeedsDisplay: YES];
326
327 [[NSNotificationCenter defaultCenter]
328 postNotificationName: GWDesktopViewUnsetImageNotification
329 object: nil];
330 }
331
332 @end

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