aboutsummaryrefslogtreecommitdiff
path: root/src/FbTk/MenuItem.cc
diff options
context:
space:
mode:
authorMark Tiefenbruck <mark@fluxbox.org>2008-01-05 01:39:19 (GMT)
committerMark Tiefenbruck <mark@fluxbox.org>2008-01-05 01:39:19 (GMT)
commitac1bd7e0981222bf340ce7defb2bb8307d42a0a2 (patch)
treec8fb9c618184e7ac44f6138409cab3fab86b23e4 /src/FbTk/MenuItem.cc
parent60ba709c2f47cc2c7b877aef1b0f297b097853e5 (diff)
downloadfluxbox-ac1bd7e0981222bf340ce7defb2bb8307d42a0a2.zip
fluxbox-ac1bd7e0981222bf340ce7defb2bb8307d42a0a2.tar.bz2
update code to use ThemeProxy
Diffstat (limited to 'src/FbTk/MenuItem.cc')
-rw-r--r--src/FbTk/MenuItem.cc103
1 files changed, 52 insertions, 51 deletions
diff --git a/src/FbTk/MenuItem.cc b/src/FbTk/MenuItem.cc
index ce3846a..1e8c8e9 100644
--- a/src/FbTk/MenuItem.cc
+++ b/src/FbTk/MenuItem.cc
@@ -42,26 +42,27 @@ void MenuItem::click(int button, int time, unsigned int mods) {
42 } 42 }
43} 43}
44 44
45void MenuItem::drawLine(FbDrawable &draw, const MenuTheme &theme, size_t size, 45void MenuItem::drawLine(FbDrawable &draw,
46 const FbTk::ThemeProxy<MenuTheme> &theme, size_t size,
46 int text_x, int text_y, unsigned int width) const { 47 int text_x, int text_y, unsigned int width) const {
47 48
48 unsigned int height = theme.itemHeight(); 49 unsigned int height = theme->itemHeight();
49 int bevelW = theme.bevelWidth(); 50 int bevelW = theme->bevelWidth();
50 51
51 int font_top = (height - theme.frameFont().height())/2; 52 int font_top = (height - theme->frameFont().height())/2;
52 int underline_height = font_top + theme.frameFont().ascent() + 2; 53 int underline_height = font_top + theme->frameFont().ascent() + 2;
53 int bottom = height - bevelW - 1; 54 int bottom = height - bevelW - 1;
54 55
55 text_y += bottom > underline_height ? underline_height : bottom; 56 text_y += bottom > underline_height ? underline_height : bottom;
56 int text_w = theme.frameFont().textWidth(m_label.c_str(), m_label.size()); 57 int text_w = theme->frameFont().textWidth(m_label.c_str(), m_label.size());
57 58
58 // width of the searchstring 59 // width of the searchstring
59 size = size > m_label.length() ? m_label.length() : size; 60 size = size > m_label.length() ? m_label.length() : size;
60 std::string search_string = m_label.substr(0,size); 61 std::string search_string = m_label.substr(0,size);
61 int search_string_w = theme.frameFont().textWidth(search_string.c_str(), size); 62 int search_string_w = theme->frameFont().textWidth(search_string.c_str(), size);
62 63
63 // pay attention to the text justification 64 // pay attention to the text justification
64 switch(theme.frameFontJustify()) { 65 switch(theme->frameFontJustify()) {
65 case FbTk::LEFT: 66 case FbTk::LEFT:
66 text_x += bevelW + height + 1; 67 text_x += bevelW + height + 1;
67 break; 68 break;
@@ -75,13 +76,13 @@ void MenuItem::drawLine(FbDrawable &draw, const MenuTheme &theme, size_t size,
75 76
76 // avoid drawing an ugly dot 77 // avoid drawing an ugly dot
77 if (size != 0) 78 if (size != 0)
78 draw.drawLine(theme.frameUnderlineGC().gc(), 79 draw.drawLine(theme->frameUnderlineGC().gc(),
79 text_x, text_y, text_x + search_string_w, text_y); 80 text_x, text_y, text_x + search_string_w, text_y);
80 81
81} 82}
82 83
83void MenuItem::draw(FbDrawable &draw, 84void MenuItem::draw(FbDrawable &draw,
84 const MenuTheme &theme, 85 const FbTk::ThemeProxy<MenuTheme> &theme,
85 bool highlight, bool draw_foreground, bool draw_background, 86 bool highlight, bool draw_foreground, bool draw_background,
86 int x, int y, 87 int x, int y,
87 unsigned int width, unsigned int height) const { 88 unsigned int width, unsigned int height) const {
@@ -101,16 +102,16 @@ void MenuItem::draw(FbDrawable &draw,
101 tmp_mask.copy(icon()->mask()); 102 tmp_mask.copy(icon()->mask());
102 103
103 // scale pixmap to right size 104 // scale pixmap to right size
104 if (height - 2*theme.bevelWidth() != tmp_pixmap.height()) { 105 if (height - 2*theme->bevelWidth() != tmp_pixmap.height()) {
105 unsigned int scale_size = height - 2*theme.bevelWidth(); 106 unsigned int scale_size = height - 2*theme->bevelWidth();
106 tmp_pixmap.scale(scale_size, scale_size); 107 tmp_pixmap.scale(scale_size, scale_size);
107 tmp_mask.scale(scale_size, scale_size); 108 tmp_mask.scale(scale_size, scale_size);
108 } 109 }
109 110
110 if (tmp_pixmap.drawable() != 0) { 111 if (tmp_pixmap.drawable() != 0) {
111 GC gc = theme.frameTextGC().gc(); 112 GC gc = theme->frameTextGC().gc();
112 int icon_x = x + theme.bevelWidth(); 113 int icon_x = x + theme->bevelWidth();
113 int icon_y = y + theme.bevelWidth(); 114 int icon_y = y + theme->bevelWidth();
114 // enable clip mask 115 // enable clip mask
115 XSetClipMask(disp, gc, tmp_mask.drawable()); 116 XSetClipMask(disp, gc, tmp_mask.drawable());
116 XSetClipOrigin(disp, gc, icon_x, icon_y); 117 XSetClipOrigin(disp, gc, icon_x, icon_y);
@@ -126,9 +127,9 @@ void MenuItem::draw(FbDrawable &draw,
126 XGetGCValues(draw.display(), gc, GCForeground|GCBackground, 127 XGetGCValues(draw.display(), gc, GCForeground|GCBackground,
127 &backup); 128 &backup);
128 XSetForeground(draw.display(), gc, 129 XSetForeground(draw.display(), gc,
129 Color("black", theme.screenNum()).pixel()); 130 Color("black", theme->screenNum()).pixel());
130 XSetBackground(draw.display(), gc, 131 XSetBackground(draw.display(), gc,
131 Color("white", theme.screenNum()).pixel()); 132 Color("white", theme->screenNum()).pixel());
132 XCopyPlane(draw.display(), tmp_pixmap.drawable(), 133 XCopyPlane(draw.display(), tmp_pixmap.drawable(),
133 draw.drawable(), gc, 134 draw.drawable(), gc,
134 0, 0, tmp_pixmap.width(), tmp_pixmap.height(), 135 0, 0, tmp_pixmap.width(), tmp_pixmap.height(),
@@ -149,46 +150,46 @@ void MenuItem::draw(FbDrawable &draw,
149 // text is background 150 // text is background
150 if (draw_background) { 151 if (draw_background) {
151 const GContext &tgc = 152 const GContext &tgc =
152 (highlight ? theme.hiliteTextGC() : 153 (highlight ? theme->hiliteTextGC() :
153 (isEnabled() ? theme.frameTextGC() : theme.disableTextGC() ) ); 154 (isEnabled() ? theme->frameTextGC() : theme->disableTextGC() ) );
154 // 155 //
155 // Text 156 // Text
156 // 157 //
157 int text_y = y, text_x = x; 158 int text_y = y, text_x = x;
158 159
159 int text_w = theme.frameFont().textWidth(label().c_str(), label().size()); 160 int text_w = theme->frameFont().textWidth(label().c_str(), label().size());
160 161
161 int height_offset = theme.itemHeight() - (theme.frameFont().height() + 2*theme.bevelWidth()); 162 int height_offset = theme->itemHeight() - (theme->frameFont().height() + 2*theme->bevelWidth());
162 text_y = y + theme.bevelWidth() + theme.frameFont().ascent() + height_offset/2; 163 text_y = y + theme->bevelWidth() + theme->frameFont().ascent() + height_offset/2;
163 164
164 switch(theme.frameFontJustify()) { 165 switch(theme->frameFontJustify()) {
165 case FbTk::LEFT: 166 case FbTk::LEFT:
166 text_x = x + theme.bevelWidth() + height + 1; 167 text_x = x + theme->bevelWidth() + height + 1;
167 break; 168 break;
168 169
169 case FbTk::RIGHT: 170 case FbTk::RIGHT:
170 text_x = x + width - (height + theme.bevelWidth() + text_w); 171 text_x = x + width - (height + theme->bevelWidth() + text_w);
171 break; 172 break;
172 default: //center 173 default: //center
173 text_x = x + ((width + 1 - text_w) / 2); 174 text_x = x + ((width + 1 - text_w) / 2);
174 break; 175 break;
175 } 176 }
176 177
177 theme.frameFont().drawText(draw, // drawable 178 theme->frameFont().drawText(draw, // drawable
178 theme.screenNum(), 179 theme->screenNum(),
179 tgc.gc(), 180 tgc.gc(),
180 label().c_str(), label().size(), // text string and lenght 181 label().c_str(), label().size(), // text string and lenght
181 text_x, text_y); // position 182 text_x, text_y); // position
182 } 183 }
183 184
184 GC gc = (highlight) ? theme.hiliteTextGC().gc() : 185 GC gc = (highlight) ? theme->hiliteTextGC().gc() :
185 theme.frameTextGC().gc(); 186 theme->frameTextGC().gc();
186 int sel_x = x; 187 int sel_x = x;
187 int sel_y = y; 188 int sel_y = y;
188 unsigned int item_pm_height = theme.itemHeight(); 189 unsigned int item_pm_height = theme->itemHeight();
189 190
190 if (theme.bulletPos() == FbTk::RIGHT) 191 if (theme->bulletPos() == FbTk::RIGHT)
191 sel_x += width - height - theme.bevelWidth(); 192 sel_x += width - height - theme->bevelWidth();
192 193
193 // selected pixmap is foreground 194 // selected pixmap is foreground
194 if (draw_foreground && isToggleItem()) { 195 if (draw_foreground && isToggleItem()) {
@@ -199,15 +200,15 @@ void MenuItem::draw(FbDrawable &draw,
199 const PixmapWithMask *pm = 0; 200 const PixmapWithMask *pm = 0;
200 201
201 if (isSelected()) { 202 if (isSelected()) {
202 if (highlight && theme.highlightSelectedPixmap().pixmap().drawable() != 0) 203 if (highlight && theme->highlightSelectedPixmap().pixmap().drawable() != 0)
203 pm = &theme.highlightSelectedPixmap(); 204 pm = &theme->highlightSelectedPixmap();
204 else 205 else
205 pm = &theme.selectedPixmap(); 206 pm = &theme->selectedPixmap();
206 } else { 207 } else {
207 if (highlight && theme.highlightUnselectedPixmap().pixmap().drawable() != 0) 208 if (highlight && theme->highlightUnselectedPixmap().pixmap().drawable() != 0)
208 pm = &theme.highlightUnselectedPixmap(); 209 pm = &theme->highlightUnselectedPixmap();
209 else 210 else
210 pm = &theme.unselectedPixmap(); 211 pm = &theme->unselectedPixmap();
211 } 212 }
212 if (pm != 0 && pm->pixmap().drawable() != 0) { 213 if (pm != 0 && pm->pixmap().drawable() != 0) {
213 unsigned int selw = pm->width(); 214 unsigned int selw = pm->width();
@@ -231,7 +232,7 @@ void MenuItem::draw(FbDrawable &draw,
231 // disable clip mask 232 // disable clip mask
232 XSetClipMask(disp, gc, None); 233 XSetClipMask(disp, gc, None);
233 } else if (isSelected()) { 234 } else if (isSelected()) {
234 draw.fillRectangle(theme.hiliteGC().gc(), 235 draw.fillRectangle(theme->hiliteGC().gc(),
235 sel_x+item_pm_height/4, sel_y+item_pm_height/4, item_pm_height/2, item_pm_height/2); 236 sel_x+item_pm_height/4, sel_y+item_pm_height/4, item_pm_height/2, item_pm_height/2);
236 } 237 }
237 } 238 }
@@ -243,10 +244,10 @@ void MenuItem::draw(FbDrawable &draw,
243 244
244 const PixmapWithMask *pm = 0; 245 const PixmapWithMask *pm = 0;
245 246
246 if (highlight && theme.highlightBulletPixmap().pixmap().drawable() != 0) 247 if (highlight && theme->highlightBulletPixmap().pixmap().drawable() != 0)
247 pm = &theme.highlightBulletPixmap(); 248 pm = &theme->highlightBulletPixmap();
248 else 249 else
249 pm = &theme.bulletPixmap(); 250 pm = &theme->bulletPixmap();
250 251
251 if (pm && pm->pixmap().drawable() != 0) { 252 if (pm && pm->pixmap().drawable() != 0) {
252 unsigned int selw = pm->width(); 253 unsigned int selw = pm->width();
@@ -273,13 +274,13 @@ void MenuItem::draw(FbDrawable &draw,
273 274
274 } else { 275 } else {
275 unsigned int half_w = item_pm_height / 2, quarter_w = item_pm_height / 4; 276 unsigned int half_w = item_pm_height / 2, quarter_w = item_pm_height / 4;
276 switch (theme.bullet()) { 277 switch (theme->bullet()) {
277 case MenuTheme::SQUARE: 278 case MenuTheme::SQUARE:
278 draw.drawRectangle(gc, sel_x+quarter_w, y+quarter_w, half_w, half_w); 279 draw.drawRectangle(gc, sel_x+quarter_w, y+quarter_w, half_w, half_w);
279 break; 280 break;
280 281
281 case MenuTheme::TRIANGLE: 282 case MenuTheme::TRIANGLE:
282 draw.drawTriangle(gc, ((theme.bulletPos() == FbTk::RIGHT)? 283 draw.drawTriangle(gc, ((theme->bulletPos() == FbTk::RIGHT)?
283 FbTk::FbDrawable::RIGHT: 284 FbTk::FbDrawable::RIGHT:
284 FbTk::FbDrawable::LEFT), 285 FbTk::FbDrawable::LEFT),
285 sel_x, sel_y, 286 sel_x, sel_y,
@@ -327,23 +328,23 @@ void MenuItem::setIcon(const std::string &filename, int screen_num) {
327 screen_num)); 328 screen_num));
328} 329}
329 330
330unsigned int MenuItem::height(const MenuTheme &theme) const { 331unsigned int MenuItem::height(const FbTk::ThemeProxy<MenuTheme> &theme) const {
331 return std::max(theme.frameFont().height() + 2*theme.bevelWidth(), theme.itemHeight()); 332 return std::max(theme->frameFont().height() + 2*theme->bevelWidth(), theme->itemHeight());
332} 333}
333 334
334unsigned int MenuItem::width(const MenuTheme &theme) const { 335unsigned int MenuItem::width(const FbTk::ThemeProxy<MenuTheme> &theme) const {
335 // textwidth + bevel width on each side of the text 336 // textwidth + bevel width on each side of the text
336 const unsigned int icon_width = height(theme); 337 const unsigned int icon_width = height(theme);
337 const unsigned int normal = theme.frameFont().textWidth(label(), label().size()) + 338 const unsigned int normal = theme->frameFont().textWidth(label(), label().size()) +
338 2 * (theme.bevelWidth() + icon_width); 339 2 * (theme->bevelWidth() + icon_width);
339 return m_icon.get() == 0 ? normal : normal + icon_width; 340 return m_icon.get() == 0 ? normal : normal + icon_width;
340} 341}
341 342
342void MenuItem::updateTheme(const MenuTheme &theme) { 343void MenuItem::updateTheme(const FbTk::ThemeProxy<MenuTheme> &theme) {
343 if (m_icon.get() == 0) 344 if (m_icon.get() == 0)
344 return; 345 return;
345 346
346 m_icon->pixmap.reset(Image::load(m_icon->filename.c_str(), theme.screenNum())); 347 m_icon->pixmap.reset(Image::load(m_icon->filename.c_str(), theme->screenNum()));
347 348
348 349
349} 350}