summaryrefslogtreecommitdiff
path: root/src/Fl_Menu.cxx
diff options
context:
space:
mode:
authorMatthias Melcher <fltk@matthiasm.com>2010-02-26 13:28:36 +0000
committerMatthias Melcher <fltk@matthiasm.com>2010-02-26 13:28:36 +0000
commit056cd02b10934d5aab3126e7022b3442d1dcee37 (patch)
treeab7bcd4995cc0c3d72e30cdda66ae5a5d2676e88 /src/Fl_Menu.cxx
parent4a802a315952a1392a82e3dc42c7316b540320f9 (diff)
Attempt at a better menubar shortct alignment.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@7151 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src/Fl_Menu.cxx')
-rw-r--r--src/Fl_Menu.cxx32
1 files changed, 25 insertions, 7 deletions
diff --git a/src/Fl_Menu.cxx b/src/Fl_Menu.cxx
index 91c5086ef..21df2dc95 100644
--- a/src/Fl_Menu.cxx
+++ b/src/Fl_Menu.cxx
@@ -330,12 +330,24 @@ menuwindow::menuwindow(const Fl_Menu_Item* m, int X, int Y, int Wp, int Hp,
if (hh+LEADING>itemheight) itemheight = hh+LEADING;
if (m->flags&(FL_SUBMENU|FL_SUBMENU_POINTER)) w1 += 14;
if (w1 > W) W = w1;
+ // calculate the maximum width of all shortcuts
if (m->shortcut_) {
+ // s is a pointerto the utf8 string for the entire shortcut
+ // k points only to the key part (minus the modifier keys)
const char *k, *s = fl_shortcut_label(m->shortcut_, &k);
- w1 = int(fl_width(s, k-s));
- if (w1 > hotModsw) hotModsw = w1;
- w1 = int(fl_width(k))+4;
- if (w1 > hotKeysw) hotKeysw = w1;
+ if (fl_utf_nb_char((const unsigned char*)k, strlen(k))<=4) {
+ // a regular shortcut has a right-justified modifier followed by a left-justified key
+ w1 = int(fl_width(s, k-s));
+ if (w1 > hotModsw) hotModsw = w1;
+ w1 = int(fl_width(k))+4;
+ if (w1 > hotKeysw) hotKeysw = w1;
+ } else {
+ // a shortcut with a long modifier is right-justified to the menu
+ w1 = int(fl_width(s))+4;
+ if (w1 > (hotModsw+hotKeysw)) {
+ hotModsw = w1-hotKeysw;
+ }
+ }
}
if (m->labelcolor_ || Fl::scheme() || m->labeltype_ > FL_NO_LABEL) clear_overlay();
}
@@ -446,9 +458,15 @@ void menuwindow::drawentry(const Fl_Menu_Item* m, int n, int eraseit) {
fl_font(f, m->labelsize_ ? m->labelsize_ :
button ? button->textsize() : FL_NORMAL_SIZE);
const char *k, *s = fl_shortcut_label(m->shortcut_, &k);
- char buf[32]; strcpy(buf, s); buf[k-s] = 0;
- fl_draw(buf, xx, yy, ww-shortcutWidth, hh, FL_ALIGN_RIGHT);
- fl_draw( k, xx+ww-shortcutWidth, yy, shortcutWidth, hh, FL_ALIGN_LEFT);
+ if (fl_utf_nb_char((const unsigned char*)k, strlen(k))<=4) {
+ // righ-align the modifiers and left-align the key
+ char buf[32]; strcpy(buf, s); buf[k-s] = 0;
+ fl_draw(buf, xx, yy, ww-shortcutWidth, hh, FL_ALIGN_RIGHT);
+ fl_draw( k, xx+ww-shortcutWidth, yy, shortcutWidth, hh, FL_ALIGN_LEFT);
+ } else {
+ // right-align to the menu
+ fl_draw(s, xx, yy, ww-4, hh, FL_ALIGN_RIGHT);
+ }
}
if (m->flags & FL_MENU_DIVIDER) {