/[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.4 - (show annotations) (download)
Tue Sep 30 15:38:04 2003 UTC (20 years, 7 months ago) by esersale
Branch: MAIN
Changes since 1.3: +4 -11 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 "GWLib.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 paths = nil;
63 path = nil;
64 icon = nil;
65 highlight = nil;
66 iconSelected = NO;
67 [self setAllowsMixedState: NO];
68 }
69
70 return self;
71 }
72
73 - (void)setPaths:(NSArray *)p
74 {
75 ASSIGN (paths, p);
76
77 if ([paths count] == 1) {
78 ASSIGN (path, [paths objectAtIndex: 0]);
79 [self setStringValue: [path lastPathComponent]];
80 ASSIGN (icon, [GWLib smallIconForFile: path]);
81 iconSelected = NO;
82 } else {
83 DESTROY (path);
84 ASSIGN (icon, [GWLib smallIconForFiles: paths]);
85 }
86
87 ASSIGN (highlight, [GWLib smallHighlightIcon]);
88 }
89
90 - (NSArray *)paths
91 {
92 return paths;
93 }
94
95 - (BOOL)selectIcon
96 {
97 if (iconSelected) {
98 return NO;
99 }
100
101 iconSelected = YES;
102 return YES;
103 }
104
105 - (BOOL)unSelectIcon
106 {
107 if (iconSelected == NO) {
108 return NO;
109 }
110
111 iconSelected = NO;
112 return YES;
113 }
114
115 - (NSSize)cellSize
116 {
117 NSSize s = [super cellSize];
118
119 if (highlight) {
120 s.height = [highlight size].height + 2;
121 }
122
123 return s;
124 }
125
126 - (NSSize)iconSize
127 {
128 if (highlight) {
129 return [highlight size];
130 }
131
132 return NSZeroSize;
133 }
134
135 - (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView *)controlView
136 {
137 NSWindow *cvWin = [controlView window];
138 NSRect title_rect = cellFrame;
139 NSString *title;
140 NSString *cuttitle;
141 float textlenght;
142 NSSize size;
143
144 if (!cvWin) {
145 return;
146 }
147
148 title = [[self stringValue] copy];
149 size = [controlView frame].size;
150
151 textlenght = size.width;
152
153 if (icon) {
154 textlenght -= [highlight size].width + 4;
155 }
156
157 if ([self isLeaf] == YES) {
158 textlenght -= 20;
159 } else {
160 textlenght -= 35;
161 }
162 cuttitle = cutFileLabelText(title, self, textlenght);
163 [self setStringValue: cuttitle];
164
165 if (icon == nil) {
166 [super drawInteriorWithFrame: title_rect inView: controlView];
167 [self setStringValue: title];
168 RELEASE (title);
169 return;
170
171 } else {
172 NSRect icon_rect;
173 NSRect highlight_rect;
174 NSColor *backColor;
175 BOOL showsFirstResponder;
176
177 [controlView lockFocus];
178
179 if ([self isHighlighted] || [self state]) {
180 backColor = [self highlightColorInView: controlView];
181 } else {
182 backColor = [cvWin backgroundColor];
183 }
184 [backColor set];
185 NSRectFill(cellFrame);
186
187 showsFirstResponder = [self showsFirstResponder];
188 [self setShowsFirstResponder: NO];
189
190 highlight_rect.origin = cellFrame.origin;
191 highlight_rect.size = [highlight size];
192 highlight_rect.origin.x += 1;
193 highlight_rect.origin.y += (cellFrame.size.height - highlight_rect.size.height) / 2.0;
194 if ([controlView isFlipped]) {
195 highlight_rect.origin.y += highlight_rect.size.height;
196 }
197
198 icon_rect.origin = cellFrame.origin;
199 icon_rect.size = [icon size];
200 icon_rect.origin.x += (highlight_rect.size.width - icon_rect.size.width) / 2.0;
201 icon_rect.origin.y += (cellFrame.size.height - icon_rect.size.height) / 2.0;
202 if ([controlView isFlipped]) {
203 icon_rect.origin.y += icon_rect.size.height;
204 }
205
206 title_rect.origin.x += highlight_rect.size.width + 1;
207 title_rect.size.width -= highlight_rect.size.width + 1;
208
209 [super drawInteriorWithFrame: title_rect inView: controlView];
210
211 if (iconSelected) {
212 // [highlight setBackgroundColor: backColor];
213 [highlight compositeToPoint: highlight_rect.origin
214 operation: NSCompositeSourceOver];
215 }
216
217 if (iconSelected == NO) {
218 // [icon setBackgroundColor: backColor];
219 }
220
221 if ([self isEnabled]) {
222 [icon compositeToPoint: icon_rect.origin
223 operation: NSCompositeSourceOver];
224 } else {
225 [icon dissolveToPoint: icon_rect.origin fraction: 0.3];
226 }
227
228 if (showsFirstResponder == YES) {
229 [self setShowsFirstResponder: showsFirstResponder];
230 NSDottedFrameRect(cellFrame);
231 }
232
233 [controlView unlockFocus];
234
235 [self setStringValue: title];
236 RELEASE (title);
237 }
238 }
239
240 @end

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