From 60812b2ecc615a5ce40fa9a4c93c170c06f4282e Mon Sep 17 00:00:00 2001 From: Matthias Melcher Date: Sun, 25 Sep 2005 19:04:04 +0000 Subject: STR #973: popup menus now pop up fully visible in the current screen if possible and useful. In detail, menus in a menubar will pop up above the title if they would cut into the screen bottom. Submenus will show the *last* item to the right of the parent instead of the first. Finally, Pulldowns with title will simply apppera over the title instead of under the title. There are two exceptions: Menus that have a selected item will not be modified, so the selected item is visible. Hence an Fl_Choice will never have a 'fixed' menu. If putting the menu high would intersect the top frame of the screen, we leave the menu at the bottom. git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@4584 ea41ed52-d2ee-0310-a9c1-e6b18d33e121 --- src/Fl_Menu.cxx | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/Fl_Menu.cxx b/src/Fl_Menu.cxx index 16ea170f2..533811c72 100644 --- a/src/Fl_Menu.cxx +++ b/src/Fl_Menu.cxx @@ -306,8 +306,24 @@ menuwindow::menuwindow(const Fl_Menu_Item* m, int X, int Y, int Wp, int Hp, h((numitems ? itemheight*numitems-LEADING : 0)+2*BW+3); if (selected >= 0) Y = Y+(Hp-itemheight)/2-selected*itemheight-BW; - else + else { Y = Y+Hp; + // if the menu hits the bottom of the screen, we try to draw + // it above the menubar instead. We will not adjust any menu + // that has a selected item. + if (Y+h()>scr_y+scr_h && Y-h()>=scr_y) { + if (Hp>1) + // if we know the height of the Fl_Menu_, use it + Y = Y-Hp-h(); + else if (t) + // assume that the menubar item height relates to the first + // menuitem as well + Y = Y-itemheight-h()-Fl::box_dh(box()); + else + // draw the menu to the right + Y = Y-h()+itemheight+Fl::box_dy(box()); + } + } if (m) y(Y); else {y(Y-2); w(1); h(1);} if (t) { -- cgit v1.2.3