Deleted Added
full compact
SectionEdit.cpp (42b3a11f) SectionEdit.cpp (fd7c0c2e)
1#include <Bitmap.h>
2#include <Window.h>
1/*
2 * Copyright 2004-2007, Haiku, Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
4 *
5 * Authors:
6 * probably Mike Berg <mike@agamemnon.homelinux.net>
7 * Julun <host.haiku@gmx.de>
8 *
9 */
3
10
4#include "Bitmaps.h"
5#include "SectionEdit.h"
11#include "SectionEdit.h"
12#include "Bitmaps.h"
6#include "TimeMessages.h"
7
13#include "TimeMessages.h"
14
8const uint32 kArrowAreaWidth = 16;
9const uint32 kSeperatorWidth = 8;
10
15
16#include <Bitmap.h>
17#include <List.h>
18#include <Window.h>
11
19
12TSection::TSection(BRect frame)
13 : f_frame(frame)
14{
15}
16
20
21const uint32 kArrowAreaWidth = 16;
22const uint32 kSeperatorWidth = 8;
17
23
18void
19TSection::SetBounds(BRect frame)
20{
21 f_frame = frame;
22}
23
24
24
25 BRect
26TSection::Bounds() const
27{
28 BRect bounds(f_frame);
29 return bounds.OffsetByCopy(B_ORIGIN);
30}
31
32
33 BRect
34TSection::Frame() const
35{
36 return f_frame;
37}
38
39
40
41TSectionEdit::TSectionEdit(BRect frame, const char *name, uint32 sections)
25TSectionEdit::TSectionEdit(BRect frame, const char *name, uint32 sections)
42 : BControl(frame, name, NULL, NULL, B_FOLLOW_NONE, B_NAVIGABLE|B_WILL_DRAW)
43 , f_focus(-1)
26 : BControl(frame, name, NULL, NULL, B_FOLLOW_NONE, B_NAVIGABLE | B_WILL_DRAW),
27 fUpArrow(NULL),
28 fDownArrow(NULL),
29 fSectionList(NULL),
30 fFocus(-1),
31 fSectionCount(sections)
44{
32{
45 f_sectioncount = sections;
46 InitView();
47}
48
49
50TSectionEdit::~TSectionEdit()
51{
33 InitView();
34}
35
36
37TSectionEdit::~TSectionEdit()
38{
39 delete fUpArrow;
40 delete fDownArrow;
41
42 int32 count = fSectionList->CountItems();
43 if (count > 0) {
44 for (int32 index = 0; index < count; index++)
45 delete (TSection*)fSectionList->ItemAt(index);
46 }
47 delete fSectionList;
52}
53
54
55void
56TSectionEdit::AttachedToWindow()
57{
58 if (Parent()) {
59 SetViewColor(Parent()->ViewColor());
48}
49
50
51void
52TSectionEdit::AttachedToWindow()
53{
54 if (Parent()) {
55 SetViewColor(Parent()->ViewColor());
60 ReplaceTransparentColor(f_up, ViewColor());
61 ReplaceTransparentColor(f_down, ViewColor());
56 ReplaceTransparentColor(fUpArrow, ViewColor());
57 ReplaceTransparentColor(fDownArrow, ViewColor());
62 }
63}
64
65
66void
67TSectionEdit::Draw(BRect updaterect)
68{
69 DrawBorder();
58 }
59}
60
61
62void
63TSectionEdit::Draw(BRect updaterect)
64{
65 DrawBorder();
70 for (uint32 idx = 0; idx < f_sectioncount; idx++)
66 for (uint32 idx = 0; idx < fSectionCount; idx++)
71 {
67 {
72 DrawSection(idx, ((uint32)f_focus == idx) && IsFocus());
73 if (idx <f_sectioncount -1)
68 DrawSection(idx, ((uint32)fFocus == idx) && IsFocus());
69 if (idx <fSectionCount -1)
74 DrawSeperator(idx);
75 }
76}
77
78
79void
80TSectionEdit::MouseDown(BPoint where)
81{
82 MakeFocus(true);
70 DrawSeperator(idx);
71 }
72}
73
74
75void
76TSectionEdit::MouseDown(BPoint where)
77{
78 MakeFocus(true);
83 if (f_uprect.Contains(where))
79 if (fUpRect.Contains(where))
84 DoUpPress();
80 DoUpPress();
85 else if (f_downrect.Contains(where))
81 else if (fDownRect.Contains(where))
86 DoDownPress();
82 DoDownPress();
87 else if (f_sections->CountItems()> 0) {
83 else if (fSectionList->CountItems()> 0) {
88 TSection *section;
84 TSection *section;
89 for (uint32 idx = 0; idx < f_sectioncount; idx++) {
90 section = (TSection *)f_sections->ItemAt(idx);
85 for (uint32 idx = 0; idx < fSectionCount; idx++) {
86 section = (TSection *)fSectionList->ItemAt(idx);
91 if (section->Frame().Contains(where)) {
92 SectionFocus(idx);
93 return;
94 }
95 }
96 }
97}
98
99
100void
101TSectionEdit::KeyDown(const char *bytes, int32 numbytes)
102{
87 if (section->Frame().Contains(where)) {
88 SectionFocus(idx);
89 return;
90 }
91 }
92 }
93}
94
95
96void
97TSectionEdit::KeyDown(const char *bytes, int32 numbytes)
98{
103 if (f_focus == -1)
99 if (fFocus == -1)
104 SectionFocus(0);
105
106 switch (bytes[0]) {
107 case B_LEFT_ARROW:
100 SectionFocus(0);
101
102 switch (bytes[0]) {
103 case B_LEFT_ARROW:
108 f_focus -= 1;
109 if (f_focus < 0)
110 f_focus = f_sectioncount -1;
111 SectionFocus(f_focus);
104 fFocus -= 1;
105 if (fFocus < 0)
106 fFocus = fSectionCount -1;
107 SectionFocus(fFocus);
112 break;
113
114 case B_RIGHT_ARROW:
108 break;
109
110 case B_RIGHT_ARROW:
115 f_focus += 1;
116 if ((uint32)f_focus >= f_sectioncount)
117 f_focus = 0;
118 SectionFocus(f_focus);
111 fFocus += 1;
112 if ((uint32)fFocus >= fSectionCount)
113 fFocus = 0;
114 SectionFocus(fFocus);
119 break;
120
121 case B_UP_ARROW:
122 DoUpPress();
123 break;
124
125 case B_DOWN_ARROW:
126 DoDownPress();

--- 14 unchanged lines hidden (view full) ---

141 BuildDispatch(msg);
142 Window()->PostMessage(msg);
143}
144
145
146uint32
147TSectionEdit::CountSections() const
148{
115 break;
116
117 case B_UP_ARROW:
118 DoUpPress();
119 break;
120
121 case B_DOWN_ARROW:
122 DoDownPress();

--- 14 unchanged lines hidden (view full) ---

137 BuildDispatch(msg);
138 Window()->PostMessage(msg);
139}
140
141
142uint32
143TSectionEdit::CountSections() const
144{
149 return f_sections->CountItems();
145 return fSectionList->CountItems();
150}
151
152
153int32
154TSectionEdit::FocusIndex() const
155{
146}
147
148
149int32
150TSectionEdit::FocusIndex() const
151{
156 return f_focus;
152 return fFocus;
157}
158
159
160void
161TSectionEdit::InitView()
162{
163 // create arrow bitmaps
164
153}
154
155
156void
157TSectionEdit::InitView()
158{
159 // create arrow bitmaps
160
165 f_up = new BBitmap(BRect(0, 0, kUpArrowWidth -1, kUpArrowHeight -1), kUpArrowColorSpace);
166 f_up->SetBits(kUpArrowBits, (kUpArrowWidth) *(kUpArrowHeight+1), 0, kUpArrowColorSpace);
161 fUpArrow = new BBitmap(BRect(0, 0, kUpArrowWidth -1, kUpArrowHeight -1), kUpArrowColorSpace);
162 fUpArrow->SetBits(kUpArrowBits, (kUpArrowWidth) *(kUpArrowHeight+1), 0, kUpArrowColorSpace);
167
163
168 f_down = new BBitmap(BRect(0, 0, kDownArrowWidth -1, kDownArrowHeight -2), kDownArrowColorSpace);
169 f_down->SetBits(kDownArrowBits, (kDownArrowWidth) *(kDownArrowHeight), 0, kDownArrowColorSpace);
164 fDownArrow = new BBitmap(BRect(0, 0, kDownArrowWidth -1, kDownArrowHeight -2), kDownArrowColorSpace);
165 fDownArrow->SetBits(kDownArrowBits, (kDownArrowWidth) *(kDownArrowHeight), 0, kDownArrowColorSpace);
170
171
172 // setup sections
166
167
168 // setup sections
173 f_sections = new BList(f_sectioncount);
174 f_sectionsarea = Bounds().InsetByCopy(2, 2);
175 f_sectionsarea.right -= (kArrowAreaWidth);
169 fSectionList = new BList(fSectionCount);
170 fSectionArea = Bounds().InsetByCopy(2, 2);
171 fSectionArea.right -= kArrowAreaWidth;
176}
177
178
179void
180TSectionEdit::Draw3DFrame(BRect frame, bool inset)
181{
172}
173
174
175void
176TSectionEdit::Draw3DFrame(BRect frame, bool inset)
177{
182 rgb_color color1, color2;
178 rgb_color color1 = LowColor();
179 rgb_color color2 = HighColor();
183
184 if (inset) {
185 color1 = HighColor();
186 color2 = LowColor();
180
181 if (inset) {
182 color1 = HighColor();
183 color2 = LowColor();
187 } else {
188 color1 = LowColor();
189 color2 = HighColor();
190 }
184 }
191
185
192 BeginLineArray(4);
193 // left side
194 AddLine(frame.LeftBottom(), frame.LeftTop(), color2);
195 // right side
196 AddLine(frame.RightTop(), frame.RightBottom(), color1);
197 // bottom side
198 AddLine(frame.RightBottom(), frame.LeftBottom(), color1);
199 // top side

--- 5 unchanged lines hidden (view full) ---

205void
206TSectionEdit::DrawBorder()
207{
208 rgb_color bgcolor = ViewColor();
209 rgb_color light = tint_color(bgcolor, B_LIGHTEN_MAX_TINT);
210 rgb_color dark = tint_color(bgcolor, B_DARKEN_1_TINT);
211 rgb_color darker = tint_color(bgcolor, B_DARKEN_3_TINT);
212
186 BeginLineArray(4);
187 // left side
188 AddLine(frame.LeftBottom(), frame.LeftTop(), color2);
189 // right side
190 AddLine(frame.RightTop(), frame.RightBottom(), color1);
191 // bottom side
192 AddLine(frame.RightBottom(), frame.LeftBottom(), color1);
193 // top side

--- 5 unchanged lines hidden (view full) ---

199void
200TSectionEdit::DrawBorder()
201{
202 rgb_color bgcolor = ViewColor();
203 rgb_color light = tint_color(bgcolor, B_LIGHTEN_MAX_TINT);
204 rgb_color dark = tint_color(bgcolor, B_DARKEN_1_TINT);
205 rgb_color darker = tint_color(bgcolor, B_DARKEN_3_TINT);
206
213 BRect bounds(Bounds());
214 SetHighColor(light);
215 SetLowColor(dark);
207 SetHighColor(light);
208 SetLowColor(dark);
209
210 BRect bounds(Bounds());
216 Draw3DFrame(bounds, true);
217 StrokeLine(bounds.LeftBottom(), bounds.LeftBottom(), B_SOLID_LOW);
218
219 bounds.InsetBy(1, 1);
220 bounds.right -= kArrowAreaWidth;
221
211 Draw3DFrame(bounds, true);
212 StrokeLine(bounds.LeftBottom(), bounds.LeftBottom(), B_SOLID_LOW);
213
214 bounds.InsetBy(1, 1);
215 bounds.right -= kArrowAreaWidth;
216
222 f_showfocus = (IsFocus() && Window() && Window()->IsActive());
223 if (f_showfocus) {
217 fShowFocus = (IsFocus() && Window() && Window()->IsActive());
218 if (fShowFocus) {
224 rgb_color navcolor = keyboard_navigation_color();
225
226 SetHighColor(navcolor);
227 StrokeRect(bounds);
228 } else {
229 // draw border thickening (erase focus)
230 SetHighColor(darker);
231 SetLowColor(bgcolor);
232 Draw3DFrame(bounds, false);
233 }
234
235 // draw up/down control
236 SetHighColor(light);
219 rgb_color navcolor = keyboard_navigation_color();
220
221 SetHighColor(navcolor);
222 StrokeRect(bounds);
223 } else {
224 // draw border thickening (erase focus)
225 SetHighColor(darker);
226 SetLowColor(bgcolor);
227 Draw3DFrame(bounds, false);
228 }
229
230 // draw up/down control
231 SetHighColor(light);
237 bounds.left = bounds.right +1;// -kArrowAreaWidth;
232 bounds.left = bounds.right +1;
238 bounds.right = Bounds().right -1;
233 bounds.right = Bounds().right -1;
239 f_uprect.Set(bounds.left +3, bounds.top +2, bounds.right, bounds.bottom /2.0);
240 f_downrect = f_uprect.OffsetByCopy(0, f_uprect.Height()+2);
234 fUpRect.Set(bounds.left +3, bounds.top +2, bounds.right, bounds.bottom /2.0);
235 fDownRect = fUpRect.OffsetByCopy(0, fUpRect.Height()+2);
241
236
242 DrawBitmap(f_up, f_uprect.LeftTop());
243 DrawBitmap(f_down, f_downrect.LeftTop());
237 if (fUpArrow)
238 DrawBitmap(fUpArrow, fUpRect.LeftTop());
244
239
240 if (fDownArrow)
241 DrawBitmap(fDownArrow, fDownRect.LeftTop());
242
245 Draw3DFrame(bounds, false);
246 SetHighColor(dark);
247 StrokeLine(bounds.LeftBottom(), bounds.RightBottom());
248 StrokeLine(bounds.RightBottom(), bounds.RightTop());
249 SetHighColor(light);
250 StrokeLine(bounds.RightTop(), bounds.RightTop());
251}
252
253
243 Draw3DFrame(bounds, false);
244 SetHighColor(dark);
245 StrokeLine(bounds.LeftBottom(), bounds.RightBottom());
246 StrokeLine(bounds.RightBottom(), bounds.RightTop());
247 SetHighColor(light);
248 StrokeLine(bounds.RightTop(), bounds.RightTop());
249}
250
251
254void
255TSectionEdit::SetSections(BRect)
252float
253TSectionEdit::SeperatorWidth() const
256{
254{
255 return 0.0f;
257}
258
256}
257
259
260void
261TSectionEdit::GetSeperatorWidth(uint32 *width)
262{
263 *width = 0;
264}
265
266
267void
268TSectionEdit::DrawSection(uint32 index, bool isfocus)
269{
270}
271
272
273void
274TSectionEdit::DrawSeperator(uint32 index)
275{
276}
277
278
279void
280TSectionEdit::SectionFocus(uint32 index)
281{
282}
283
284
285void
286TSectionEdit::SectionChange(uint32 section, uint32 value)
287{
288}
289
290
291void
292TSectionEdit::DoUpPress()
293{
294}
295
296
297void
298TSectionEdit::DoDownPress()
299{
300}
301