aboutsummaryrefslogtreecommitdiff
path: root/src/FbTk/MenuItem.cc
diff options
context:
space:
mode:
authorMathias Gumz <akira at fluxbox dot org>2010-09-08 18:17:21 (GMT)
committerMathias Gumz <akira at fluxbox dot org>2010-09-08 18:17:21 (GMT)
commit690d926ac444243611cd875fb84fabb4e6db2cf2 (patch)
treec8ef84056b295071f9a9207ffea5393c6cf4ad4d /src/FbTk/MenuItem.cc
parent1e8fe2bc14856fa16508686a28a85e72cb0e422c (diff)
downloadfluxbox-690d926ac444243611cd875fb84fabb4e6db2cf2.zip
fluxbox-690d926ac444243611cd875fb84fabb4e6db2cf2.tar.bz2
introduced FbTk::BidiString
a 'BidiString' holds both the logical content and the visual reordered version of the content of a string. this helps to reduce the number of calls to reorder the string before drawing it (as introduced in the patch from Ken Bloom) and to be more consistent in menus and textboxes (drawing cursors and underlining text).
Diffstat (limited to 'src/FbTk/MenuItem.cc')
-rw-r--r--src/FbTk/MenuItem.cc31
1 files changed, 13 insertions, 18 deletions
diff --git a/src/FbTk/MenuItem.cc b/src/FbTk/MenuItem.cc
index f995666..c1357fb 100644
--- a/src/FbTk/MenuItem.cc
+++ b/src/FbTk/MenuItem.cc
@@ -52,14 +52,14 @@ void MenuItem::drawLine(FbDrawable &draw,
52 int font_top = (height - theme->frameFont().height())/2; 52 int font_top = (height - theme->frameFont().height())/2;
53 int underline_height = font_top + theme->frameFont().ascent() + 2; 53 int underline_height = font_top + theme->frameFont().ascent() + 2;
54 int bottom = height - bevelW - 1; 54 int bottom = height - bevelW - 1;
55 55
56 text_y += bottom > underline_height ? underline_height : bottom; 56 text_y += bottom > underline_height ? underline_height : bottom;
57 int text_w = theme->frameFont().textWidth(m_label, m_label.size());
58 57
59 // width of the searchstring 58 int text_w = theme->frameFont().textWidth(label());
60 size = size > m_label.length() ? m_label.length() : size; 59
61 std::string search_string = m_label.substr(0,size); 60 const FbString& visual = m_label.visual();
62 int search_string_w = theme->frameFont().textWidth(search_string, size); 61 BiDiString search_string(FbString(visual, 0, size > visual.size() ? visual.size() : size));
62 int search_string_w = theme->frameFont().textWidth(search_string);
63 63
64 // pay attention to the text justification 64 // pay attention to the text justification
65 switch(theme->frameFontJustify()) { 65 switch(theme->frameFontJustify()) {
@@ -144,7 +144,7 @@ void MenuItem::draw(FbDrawable &draw,
144 } 144 }
145 } 145 }
146 146
147 if (label().empty()) 147 if (label().logical().empty())
148 return; 148 return;
149 149
150 // text is background 150 // text is background
@@ -156,8 +156,7 @@ void MenuItem::draw(FbDrawable &draw,
156 // Text 156 // Text
157 // 157 //
158 int text_y = y, text_x = x; 158 int text_y = y, text_x = x;
159 159 int text_w = theme->frameFont().textWidth(label());
160 int text_w = theme->frameFont().textWidth(label(), label().size());
161 160
162 int height_offset = theme->itemHeight() - (theme->frameFont().height() + 2*theme->bevelWidth()); 161 int height_offset = theme->itemHeight() - (theme->frameFont().height() + 2*theme->bevelWidth());
163 text_y = y + theme->bevelWidth() + theme->frameFont().ascent() + height_offset/2; 162 text_y = y + theme->bevelWidth() + theme->frameFont().ascent() + height_offset/2;
@@ -175,11 +174,7 @@ void MenuItem::draw(FbDrawable &draw,
175 break; 174 break;
176 } 175 }
177 176
178 theme->frameFont().drawText(draw, // drawable 177 theme->frameFont().drawText(draw, theme->screenNum(), tgc.gc(), label(), text_x, text_y);
179 theme->screenNum(),
180 tgc.gc(),
181 label().c_str(), label().size(), // text string and lenght
182 text_x, text_y); // position
183 } 178 }
184 179
185 GC gc = (highlight) ? theme->hiliteTextGC().gc() : 180 GC gc = (highlight) ? theme->hiliteTextGC().gc() :
@@ -335,7 +330,7 @@ unsigned int MenuItem::height(const FbTk::ThemeProxy<MenuTheme> &theme) const {
335unsigned int MenuItem::width(const FbTk::ThemeProxy<MenuTheme> &theme) const { 330unsigned int MenuItem::width(const FbTk::ThemeProxy<MenuTheme> &theme) const {
336 // textwidth + bevel width on each side of the text 331 // textwidth + bevel width on each side of the text
337 const unsigned int icon_width = height(theme); 332 const unsigned int icon_width = height(theme);
338 const unsigned int normal = theme->frameFont().textWidth(label(), label().size()) + 333 const unsigned int normal = theme->frameFont().textWidth(label()) +
339 2 * (theme->bevelWidth() + icon_width); 334 2 * (theme->bevelWidth() + icon_width);
340 return m_icon.get() == 0 ? normal : normal + icon_width; 335 return m_icon.get() == 0 ? normal : normal + icon_width;
341} 336}
@@ -349,9 +344,9 @@ void MenuItem::updateTheme(const FbTk::ThemeProxy<MenuTheme> &theme) {
349 344
350} 345}
351 346
352void MenuItem::showSubmenu() { 347void MenuItem::showSubmenu() {
353 if (submenu() != 0) 348 if (submenu() != 0)
354 submenu()->show(); 349 submenu()->show();
355} 350}
356 351
357} // end namespace FbTk 352} // end namespace FbTk