/[gnustep]/gnustep/usr-apps/gworkspace/GWLib/BCell.m
ViewVC logotype

Contents of /gnustep/usr-apps/gworkspace/GWLib/BCell.m

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (show annotations) (download)
Fri Sep 26 15:57:24 2003 UTC (20 years, 7 months ago) by esersale
Branch: MAIN
Changes since 1.2: +0 -1 lines
*** empty log message ***

1 /* BCell.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 #include "GWProtocol.h"
29 #include "GWFunctions.h"
30 #include "BCell.h"
31 #include "GNUstep.h"
32
33 @implementation BCell
34
35 - (void)dealloc
36 {
37 TEST_RELEASE (paths);
38 TEST_RELEASE (path);
39 TEST_RELEASE (icon);
40 TEST_RELEASE (highlight);
41 [super dealloc];
42 }
43
44 - (id)init
45 {
46 self = [super init];
47
48 if (self) {
49 icon = nil;
50 highlight = nil;
51 [self setAllowsMixedState: NO];
52 }
53
54 return self;
55 }
56
57 - (id)initIconCell
58 {
59 self = [super init];
60
61 if (self) {
62 #ifdef GNUSTEP
63 Class gwclass = [[NSBundle mainBundle] principalClass];
64 #else
65 Class gwclass = [[NSBundle mainBundle] classNamed: @"GWorkspace"];
66 #endif
67
68 gworkspace = (id<GWProtocol>)[gwclass gworkspace];
69 paths = nil;
70 path = nil;
71 icon = nil;
72 highlight = nil;
73 iconSelected = NO;
74 [self setAllowsMixedState: NO];
75 }
76
77 return self;
78 }
79
80 - (void)setPaths:(NSArray *)p
81 {
82 ASSIGN (paths, p);
83
84 if ([paths count] == 1) {
85 ASSIGN (path, [paths objectAtIndex: 0]);
86 [self setStringValue: [path lastPathComponent]];
87 ASSIGN (icon, [gworkspace smallIconForFile: path]);
88 iconSelected = NO;
89 } else {
90 DESTROY (path);
91 ASSIGN (icon, [gworkspace smallIconForFiles: paths]);
92 }
93
94 ASSIGN (highlight, [gworkspace smallHighlightIcon]);
95 }
96
97 - (NSArray *)paths
98 {
99 return paths;
100 }
101
102 - (BOOL)selectIcon
103 {
104 if (iconSelected) {
105 return NO;
106 }
107
108 iconSelected = YES;
109 return YES;
110 }
111
112 - (BOOL)unSelectIcon
113 {
114 if (iconSelected == NO) {
115 return NO;
116 }
117
118 iconSelected = NO;
119 return YES;
120 }
121
122 - (NSSize)cellSize
123 {
124 NSSize s = [super cellSize];
125
126 if (highlight) {
127 s.height = [highlight size].height + 2;
128 }
129
130 return s;
131 }
132
133 - (NSSize)iconSize
134 {
135 if (highlight) {
136 return [highlight size];
137 }
138
139 return NSZeroSize;
140 }
141
142 - (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView *)controlView
143 {
144 NSWindow *cvWin = [controlView window];
145 NSRect title_rect = cellFrame;
146 NSString *title;
147 NSString *cuttitle;
148 float textlenght;
149 NSSize size;
150
151 if (!cvWin) {
152 return;
153 }
154
155 title = [[self stringValue] copy];
156 size = [controlView frame].size;
157
158 textlenght = size.width;
159
160 if (icon) {
161 textlenght -= [highlight size].width + 4;
162 }
163
164 if ([self isLeaf] == YES) {
165 textlenght -= 20;
166 } else {
167 textlenght -= 35;
168 }
169 cuttitle = cutFileLabelText(title, self, textlenght);
170 [self setStringValue: cuttitle];
171
172 if (icon == nil) {
173 [super drawInteriorWithFrame: title_rect inView: controlView];
174 [self setStringValue: title];
175 RELEASE (title);
176 return;
177
178 } else {
179 NSRect icon_rect;
180 NSRect highlight_rect;
181 NSColor *backColor;
182 BOOL showsFirstResponder;
183
184 [controlView lockFocus];
185
186 if ([self isHighlighted] || [self state]) {
187 backColor = [self highlightColorInView: controlView];
188 } else {
189 backColor = [cvWin backgroundColor];
190 }
191 [backColor set];
192 NSRectFill(cellFrame);
193
194 showsFirstResponder = [self showsFirstResponder];
195 [self setShowsFirstResponder: NO];
196
197 highlight_rect.origin = cellFrame.origin;
198 highlight_rect.size = [highlight size];
199 highlight_rect.origin.x += 1;
200 highlight_rect.origin.y += (cellFrame.size.height - highlight_rect.size.height) / 2.0;
201 if ([controlView isFlipped]) {
202 highlight_rect.origin.y += highlight_rect.size.height;
203 }
204
205 icon_rect.origin = cellFrame.origin;
206 icon_rect.size = [icon size];
207 icon_rect.origin.x += (highlight_rect.size.width - icon_rect.size.width) / 2.0;
208 icon_rect.origin.y += (cellFrame.size.height - icon_rect.size.height) / 2.0;
209 if ([controlView isFlipped]) {
210 icon_rect.origin.y += icon_rect.size.height;
211 }
212
213 title_rect.origin.x += highlight_rect.size.width + 1;
214 title_rect.size.width -= highlight_rect.size.width + 1;
215
216 [super drawInteriorWithFrame: title_rect inView: controlView];
217
218 if (iconSelected) {
219 // [highlight setBackgroundColor: backColor];
220 [highlight compositeToPoint: highlight_rect.origin
221 operation: NSCompositeSourceOver];
222 }
223
224 if (iconSelected == NO) {
225 // [icon setBackgroundColor: backColor];
226 }
227
228 if ([self isEnabled]) {
229 [icon compositeToPoint: icon_rect.origin
230 operation: NSCompositeSourceOver];
231 } else {
232 [icon dissolveToPoint: icon_rect.origin fraction: 0.3];
233 }
234
235 if (showsFirstResponder == YES) {
236 [self setShowsFirstResponder: showsFirstResponder];
237 NSDottedFrameRect(cellFrame);
238 }
239
240 [controlView unlockFocus];
241
242 [self setStringValue: title];
243 RELEASE (title);
244 }
245 }
246
247 @end

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