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

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