/[gnustep]/gnustep/usr-apps/gworkspace/GWorkspace/Recycler/RecyclerViews.m
ViewVC logotype

Contents of /gnustep/usr-apps/gworkspace/GWorkspace/Recycler/RecyclerViews.m

Parent Directory Parent Directory | Revision Log Revision Log


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

1 /* RecyclerViews.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 "RecyclerViews.h"
38 #include "RecyclerIcon.h"
39 #include "Recycler.h"
40 #include "GWorkspace.h"
41 #include "GNUstep.h"
42
43 @implementation LogoView
44
45 - (void)dealloc
46 {
47 RELEASE (emptyImg);
48 RELEASE (fullImg);
49 [super dealloc];
50 }
51
52 - (id)init
53 {
54 self = [super init];
55 ASSIGN (emptyImg, [NSImage imageNamed: @"Recycler.tiff"]);
56 ASSIGN (fullImg, [NSImage imageNamed: @"RecyclerFull.tiff"]);
57 isFull = NO;
58 return self;
59 }
60
61 - (void)setIsFull:(BOOL)value
62 {
63 isFull = value;
64 [self setNeedsDisplay: YES];
65 }
66
67 - (void)drawRect:(NSRect)rect
68 {
69 [self lockFocus];
70
71 STROKE_LINE (darkGrayColor, 90, 0, 90, 100);
72 STROKE_LINE (whiteColor, 91, 0, 91, 100);
73
74 if (isFull) {
75 [fullImg compositeToPoint: NSMakePoint(21, 21) operation: NSCompositeSourceOver];
76 } else {
77 [emptyImg compositeToPoint: NSMakePoint(21, 21) operation: NSCompositeSourceOver];
78 }
79 [self unlockFocus];
80 }
81
82 @end
83
84
85 @implementation IconsView
86
87 - (void)dealloc
88 {
89 [[NSNotificationCenter defaultCenter] removeObserver: self];
90 RELEASE (icons);
91 [super dealloc];
92 }
93
94 - (id)initForRecycler:(Recycler *)rec
95 {
96 self = [super init];
97
98 if (self) {
99 recicler = rec;
100
101 fm = [NSFileManager defaultManager];
102 gw = [GWorkspace gworkspace];
103
104 cellsWidth = [gw shelfCellsWidth];
105
106 icons = [[NSMutableArray alloc] initWithCapacity: 1];
107
108 [[NSNotificationCenter defaultCenter] addObserver: self
109 selector: @selector(cellsWidthChanged:)
110 name: GWShelfCellsWidthChangedNotification
111 object: nil];
112 }
113
114 return self;
115 }
116
117 - (void)addIcon:(RecyclerIcon *)icon
118 {
119 [icons addObject: icon];
120 [self addSubview: icon];
121 [self addSubview: [icon label]];
122 [self resizeWithOldSuperviewSize: [self frame].size];
123 [self setLabelRectOfIcon: icon];
124 }
125
126 - (void)removeIcon:(RecyclerIcon *)icon
127 {
128 [[icon label] removeFromSuperview];
129 [icon removeFromSuperview];
130 [icons removeObject: icon];
131 [self resizeWithOldSuperviewSize: [self frame].size];
132 }
133
134 - (void)setLabelRectOfIcon:(RecyclerIcon *)icon
135 {
136 NSTextField *label;
137 float iconwidth, labwidth, labxpos;
138 NSRect labelRect;
139
140 label = [icon label];
141
142 iconwidth = [icon frame].size.width;
143 labwidth = [label frame].size.width;
144
145 if(iconwidth > labwidth) {
146 labxpos = [icon frame].origin.x + ((iconwidth - labwidth) / 2);
147 } else {
148 labxpos = [icon frame].origin.x - ((labwidth - iconwidth) / 2);
149 }
150
151 labelRect = NSMakeRect(labxpos, [icon frame].origin.y - 15, labwidth, 14);
152 [label setFrame: labelRect];
153 }
154
155 - (void)unselectOtherIcons:(id)icon
156 {
157 int i;
158
159 for (i = 0; i < [icons count]; i++) {
160 RecyclerIcon *icn = [icons objectAtIndex: i];
161 if (icn != icon) {
162 [icn unselect];
163 }
164 }
165 }
166
167 - (void)setCurrentSelection:(NSString *)path
168 {
169 [recicler setCurrentSelection: path];
170 }
171
172 - (NSArray *)icons
173 {
174 return icons;
175 }
176
177 - (int)cellsWidth
178 {
179 return cellsWidth;
180 }
181
182 - (void)cellsWidthChanged:(NSNotification *)notification
183 {
184 int i;
185
186 cellsWidth = [gw shelfCellsWidth];
187 for (i = 0; i < [icons count]; i++) {
188 [[icons objectAtIndex: i] setLabelWidth];
189 }
190 [self resizeWithOldSuperviewSize: [self frame].size];
191 }
192
193 - (void)mouseDown:(NSEvent *)theEvent
194 {
195 [self unselectOtherIcons: nil];
196 [self setCurrentSelection: nil];
197 }
198
199 - (void)resizeWithOldSuperviewSize:(NSSize)oldFrameSize
200 {
201 float posx = 0.0;
202 int i;
203
204 for (i = 0; i < [icons count]; i++) {
205 RecyclerIcon *icon = [icons objectAtIndex: i];
206 [icon setFrame: NSMakeRect(posx, 18, cellsWidth, 52)];
207 [icon setNeedsDisplay: YES];
208 posx += cellsWidth;
209 }
210
211 if (posx != [self frame].size.width) {
212 [self setFrame: NSMakeRect(0, 0, posx, 70)];
213 }
214
215 [self setNeedsDisplay: YES];
216 }
217
218 @end
219
220
221 @implementation RecyclerView
222
223 - (void)resizeWithOldSuperviewSize:(NSSize)oldFrameSize
224 {
225 NSRect frame;
226 NSView *view;
227
228 [super resizeWithOldSuperviewSize: oldFrameSize];
229 frame = [self frame];
230 view = [[self subviews] objectAtIndex: 0];
231 [view setFrame: NSMakeRect(0, 0, 92, 100)];
232 view = [[self subviews] objectAtIndex: 1];
233 [view setFrame: NSMakeRect(92, 0, frame.size.width - 92, 100)];
234 [self setNeedsDisplay: YES];
235 }
236
237 @end
238

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