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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

1 /* ShelfPref.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 #include <Foundation/Foundation.h>
26 #include <AppKit/AppKit.h>
27 #ifdef GNUSTEP
28 #include "GWLib.h"
29 #include "GWFunctions.h"
30 #include "GWNotifications.h"
31 #else
32 #include <GWorkspace/GWLib.h>
33 #include <GWorkspace/GWFunctions.h>
34 #include <GWorkspace/GWNotifications.h>
35 #endif
36 #include "ShelfPref.h"
37 #include "GWorkspace.h"
38 #include "GNUstep.h"
39
40 #ifdef GNUSTEP
41 #define BOX_W 197
42 #define NAME_OR_Y 5
43 #define NAME_W 16
44 #define NAME_MARGIN 6
45 #else
46 #define BOX_W 197
47 #define NAME_OR_Y 5
48 #define NAME_W 16
49 #define NAME_MARGIN 6
50 #endif
51
52 #ifndef max
53 #define max(a,b) ((a) > (b) ? (a):(b))
54 #endif
55
56 #ifndef min
57 #define min(a,b) ((a) < (b) ? (a):(b))
58 #endif
59
60 static NSString *nibName = @"ShelfPref";
61
62 @implementation ArrResizer
63
64 - (void)dealloc
65 {
66 RELEASE (arrow);
67 [super dealloc];
68 }
69
70 - (id)initForController:(id)acontroller
71 withPosition:(ArrowPosition)pos
72 {
73 self = [super init];
74 [self setFrame: NSMakeRect(0, 0, 16, 16)];
75 position = pos;
76 controller = acontroller;
77
78 if (position == leftarrow) {
79 ASSIGN (arrow, [NSImage imageNamed: @"LeftArr.tiff"]);
80 } else {
81 ASSIGN (arrow, [NSImage imageNamed: @"RightArr.tiff"]);
82 }
83
84 return self;
85 }
86
87 - (ArrowPosition)position
88 {
89 return position;
90 }
91
92 - (void)mouseDown:(NSEvent *)e
93 {
94 [controller startMouseEvent: e onResizer: self];
95 }
96
97 - (void)drawRect:(NSRect)rect
98 {
99 [super drawRect: rect];
100 [arrow compositeToPoint: NSZeroPoint operation: NSCompositeSourceOver];
101 }
102
103 @end
104
105
106 @implementation ShelfPref
107
108 - (void)dealloc
109 {
110 [[NSNotificationCenter defaultCenter] removeObserver: self];
111 TEST_RELEASE (prefbox);
112 RELEASE (leftResizer);
113 RELEASE (rightResizer);
114 RELEASE (fname);
115 [super dealloc];
116 }
117
118 - (id)init
119 {
120 self = [super init];
121
122 if (self) {
123 if ([NSBundle loadNibNamed: nibName owner: self] == NO) {
124 NSLog(@"failed to load %@!", nibName);
125 } else {
126 NSArray *selPaths;
127 int orx, count;
128
129 RETAIN (prefbox);
130 RELEASE (win);
131
132 gw = [GWorkspace gworkspace];
133 ws = [NSWorkspace sharedWorkspace];
134
135 [imView setImageScaling: NSScaleProportionally];
136
137 selPaths = [gw selectedPaths];
138 count = [selPaths count];
139 if (count == 1) {
140 NSString *fpath = [selPaths objectAtIndex: 0];
141 NSString *defApp;
142 NSString *type;
143
144 ASSIGN (fname, [fpath lastPathComponent]);
145
146 [ws getInfoForFile: fpath application: &defApp type: &type];
147 [imView setImage: [GWLib iconForFile: fpath ofType: type]];
148 } else {
149 fname = [[NSString alloc] initWithFormat: @"%i items", count];
150 [imView setImage: [NSImage imageNamed: @"MultipleSelection.tiff"]];
151 }
152
153 cellsWidth = [gw shelfCellsWidth];
154
155 orx = (int)((BOX_W - cellsWidth) / 2);
156
157 leftResizer = [[ArrResizer alloc] initForController: self
158 withPosition: leftarrow];
159 [leftResizer setFrame: NSMakeRect(0, 0, NAME_W, NAME_W)];
160 [(NSBox *)leftResBox setContentView: leftResizer];
161 [leftResBox setFrame: NSMakeRect(orx - NAME_W, NAME_OR_Y, NAME_W, NAME_W)];
162
163 rightResizer = [[ArrResizer alloc] initForController: self
164 withPosition: rightarrow];
165 [rightResizer setFrame: NSMakeRect(0, 0, NAME_W, NAME_W)];
166 [(NSBox *)rightResBox setContentView: rightResizer];
167 [rightResBox setFrame: NSMakeRect(orx + cellsWidth, NAME_OR_Y, NAME_W, NAME_W)];
168
169 [nameField setFrame: NSMakeRect(orx, NAME_OR_Y, cellsWidth, NAME_W)];
170 [nameField setStringValue: cutFileLabelText(fname, nameField, cellsWidth -NAME_MARGIN)];
171
172 [[NSNotificationCenter defaultCenter] addObserver: self
173 selector: @selector(selectionChanged:)
174 name: GWCurrentSelectionChangedNotification
175 object: nil];
176
177 /* Internationalization */
178 [setButt setTitle: NSLocalizedString(@"Default", @"")];
179 [iconbox setTitle: NSLocalizedString(@"Title Width", @"")];
180 }
181 }
182
183 return self;
184 }
185
186 - (NSView *)prefView
187 {
188 return prefbox;
189 }
190
191 - (NSString *)prefName
192 {
193 return NSLocalizedString(@"Shelf", @"");
194 }
195
196 - (void)tile
197 {
198 int orx = (int)((BOX_W - cellsWidth) / 2);
199
200 [nameField setFrame: NSMakeRect(orx, NAME_OR_Y, cellsWidth, NAME_W)];
201 [nameField setStringValue: cutFileLabelText(fname, nameField, cellsWidth -NAME_MARGIN)];
202
203 [leftResBox setFrame: NSMakeRect(orx - NAME_W, NAME_OR_Y, NAME_W, NAME_W)];
204 [rightResBox setFrame: NSMakeRect(orx + cellsWidth, NAME_OR_Y, NAME_W, NAME_W)];
205
206 [iconbox setNeedsDisplay: YES];
207 }
208
209 - (void)selectionChanged:(NSNotification *)n
210 {
211 NSArray *selPaths = [gw selectedPaths];
212 int count = [selPaths count];
213
214 if (count == 1) {
215 NSString *fpath = [selPaths objectAtIndex: 0];
216 NSString *defApp;
217 NSString *type;
218
219 ASSIGN (fname, [fpath lastPathComponent]);
220 [ws getInfoForFile: fpath application: &defApp type: &type];
221 [imView setImage: [GWLib iconForFile: fpath ofType: type]];
222 } else {
223 fname = [[NSString alloc] initWithFormat: @"%i items", count];
224 [imView setImage: [NSImage imageNamed: @"MultipleSelection.tiff"]];
225 }
226
227 cellsWidth = [gw shelfCellsWidth];
228 [self tile];
229 }
230
231 - (void)startMouseEvent:(NSEvent *)event onResizer:(ArrResizer *)resizer
232 {
233 NSApplication *app = [NSApplication sharedApplication];
234 NSDate *farAway = [NSDate distantFuture];
235 ArrowPosition pos = [resizer position];
236 int orx = (int)[prefbox convertPoint: [event locationInWindow] fromView: nil].x;
237 NSView *resbox1 = (pos == leftarrow) ? leftResBox : rightResBox;
238 NSView *resbox2 = (pos == leftarrow) ? rightResBox : leftResBox;
239 unsigned int eventMask = NSLeftMouseUpMask | NSLeftMouseDraggedMask;
240 NSEvent *e;
241
242 [prefbox lockFocus];
243 [[NSRunLoop currentRunLoop] limitDateForMode: NSEventTrackingRunLoopMode];
244
245 e = [app nextEventMatchingMask: eventMask
246 untilDate: farAway
247 inMode: NSEventTrackingRunLoopMode
248 dequeue: YES];
249
250 while ([e type] != NSLeftMouseUp) {
251 int x = (int)[prefbox convertPoint: [e locationInWindow] fromView: nil].x;
252 int diff = x - orx;
253 int orx1 = (int)[resbox1 frame].origin.x;
254 int orx2 = (int)[resbox2 frame].origin.x;
255
256 if ((max(orx1 + diff, orx2 - diff) - min(orx1 + diff, orx2 - diff)) < 160
257 && (max(orx1 + diff, orx2 - diff) - min(orx1 + diff, orx2 - diff)) > 70) {
258 int fieldwdt = max(orx1 + diff, orx2 - diff) - min(orx1 + diff, orx2 - diff) - NAME_W;
259 int nameforx = (int)((BOX_W - fieldwdt) / 2);
260
261 [resbox1 setFrameOrigin: NSMakePoint(orx1 + diff, NAME_OR_Y)];
262 [resbox2 setFrameOrigin: NSMakePoint(orx2 - diff, NAME_OR_Y)];
263
264 [nameField setFrame: NSMakeRect(nameforx, NAME_OR_Y, fieldwdt, NAME_W)];
265 [nameField setStringValue: cutFileLabelText(fname, nameField, fieldwdt -NAME_MARGIN)];
266
267 [iconbox setNeedsDisplay: YES];
268
269 orx = x;
270 }
271 e = [app nextEventMatchingMask: eventMask
272 untilDate: farAway
273 inMode: NSEventTrackingRunLoopMode
274 dequeue: YES];
275 }
276 [prefbox unlockFocus];
277
278 [self setNewWidth: (int)[nameField frame].size.width];
279
280 [setButt setEnabled: YES];
281 }
282
283 - (void)setNewWidth:(int)w
284 {
285 [gw setShelfCellsWidth: w];
286 }
287
288 - (void)setDefaultWidth:(id)sender
289 {
290 cellsWidth = [gw defaultShelfCellsWidth];
291 [self tile];
292 [setButt setEnabled: NO];
293 }
294
295 @end

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