Avoid to show menus outside of the screen
This commit is contained in:
parent
8099c16b57
commit
cc58f61480
|
@ -1,3 +1,6 @@
|
||||||
|
2015-12-16 Markus Gans <guru.mail@muenster.de>
|
||||||
|
* Avoid to show menus outside of the screen
|
||||||
|
|
||||||
2015-12-12 Markus Gans <guru.mail@muenster.de>
|
2015-12-12 Markus Gans <guru.mail@muenster.de>
|
||||||
* Improve sub-sub-menu handling
|
* Improve sub-sub-menu handling
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,7 @@ static uInt character[][fc::NUM_OF_ENCODINGS] =
|
||||||
{0x02e3, '~', 0xfc, '~'}, // ˣ - Modifier letter small x
|
{0x02e3, '~', 0xfc, '~'}, // ˣ - Modifier letter small x
|
||||||
{0x00b0, 'f', 0xb0, 'o'}, // ° - Degree
|
{0x00b0, 'f', 0xb0, 'o'}, // ° - Degree
|
||||||
{0x2022, '`', 0x04, '*'}, // • - Bullet
|
{0x2022, '`', 0x04, '*'}, // • - Bullet
|
||||||
{0x00b7, '`', 0xf9, '*'}, // · - small Bullet
|
{0x00b7, '`', 0xf9, '.'}, // · - small Bullet
|
||||||
{0x25c6, '`', 0x04, '*'}, // ◆ - BlackDiamond
|
{0x25c6, '`', 0x04, '*'}, // ◆ - BlackDiamond
|
||||||
{0x2424, 'h', ' ', ' '}, //  - SymbolForNewline
|
{0x2424, 'h', ' ', ' '}, //  - SymbolForNewline
|
||||||
{0x240b, 'i', ' ', ' '}, // ␋ - SymbolForVerticalTab
|
{0x240b, 'i', ' ', ' '}, // ␋ - SymbolForVerticalTab
|
||||||
|
|
|
@ -168,8 +168,7 @@ class fc
|
||||||
NF_shadow_box_right = 0x1af5, // ]
|
NF_shadow_box_right = 0x1af5, // ]
|
||||||
NF_Bullet = 0x1af9, // ●
|
NF_Bullet = 0x1af9, // ●
|
||||||
NF_check_mark = 0x1afb, // ✓
|
NF_check_mark = 0x1afb, // ✓
|
||||||
SquareRoot = 0x221a, // √
|
SquareRoot = 0x221a // √
|
||||||
BlackCircle = 0x25CF // ●
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// keyboard - single keys
|
// keyboard - single keys
|
||||||
|
|
106
src/fmenu.cpp
106
src/fmenu.cpp
|
@ -137,7 +137,7 @@ void FMenu::init(FWidget* parent)
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
void FMenu::menu_dimension()
|
void FMenu::menu_dimension()
|
||||||
{
|
{
|
||||||
int item_X, item_Y;
|
int item_X, item_Y, adjust_X;
|
||||||
std::vector<FMenuItem*>::const_iterator iter, end;
|
std::vector<FMenuItem*>::const_iterator iter, end;
|
||||||
iter = itemlist.begin();
|
iter = itemlist.begin();
|
||||||
end = itemlist.end();
|
end = itemlist.end();
|
||||||
|
@ -169,8 +169,10 @@ void FMenu::menu_dimension()
|
||||||
++iter;
|
++iter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
adjust_X = adjustX(xpos);
|
||||||
|
|
||||||
// set widget geometry
|
// set widget geometry
|
||||||
setGeometry (xpos, ypos, int(maxItemWidth + 2), int(count() + 2));
|
setGeometry (adjust_X, ypos, int(maxItemWidth + 2), int(count() + 2));
|
||||||
|
|
||||||
// set geometry of all items
|
// set geometry of all items
|
||||||
iter = itemlist.begin();
|
iter = itemlist.begin();
|
||||||
|
@ -182,8 +184,8 @@ void FMenu::menu_dimension()
|
||||||
(*iter)->setGeometry (item_X, item_Y, int(maxItemWidth), 1);
|
(*iter)->setGeometry (item_X, item_Y, int(maxItemWidth), 1);
|
||||||
|
|
||||||
if ( (*iter)->hasMenu() )
|
if ( (*iter)->hasMenu() )
|
||||||
{//(*iter)->setText( FString().setNumber(itemlist.size()) );
|
{
|
||||||
int menu_X = (*iter)->getGlobalX() + int(maxItemWidth);
|
int menu_X = getGlobalX() + int(maxItemWidth) + 1;
|
||||||
int menu_Y = (*iter)->getGlobalY() - 2;
|
int menu_Y = (*iter)->getGlobalY() - 2;
|
||||||
// set sub-menu position
|
// set sub-menu position
|
||||||
(*iter)->getMenu()->setPos (menu_X, menu_Y, false);
|
(*iter)->getMenu()->setPos (menu_X, menu_Y, false);
|
||||||
|
@ -194,6 +196,59 @@ void FMenu::menu_dimension()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------
|
||||||
|
void FMenu::adjustItems()
|
||||||
|
{
|
||||||
|
std::vector<FMenuItem*>::const_iterator end, iter;
|
||||||
|
iter = itemlist.begin();
|
||||||
|
end = itemlist.end();
|
||||||
|
|
||||||
|
while ( iter != end )
|
||||||
|
{
|
||||||
|
if ( (*iter)->hasMenu() )
|
||||||
|
{
|
||||||
|
int menu_X, menu_Y;
|
||||||
|
FMenu* menu = (*iter)->getMenu();
|
||||||
|
|
||||||
|
menu_X = getGlobalX() + int(maxItemWidth) + 1;
|
||||||
|
menu_X = menu->adjustX(menu_X);
|
||||||
|
menu_Y = (*iter)->getGlobalY() - 2;
|
||||||
|
|
||||||
|
// set sub-menu position
|
||||||
|
menu->move (menu_X, menu_Y);
|
||||||
|
|
||||||
|
// call sub-menu adjustItems()
|
||||||
|
if ( menu->count() > 0 )
|
||||||
|
menu->adjustItems();
|
||||||
|
}
|
||||||
|
++iter;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------
|
||||||
|
int FMenu::adjustX (int x_pos)
|
||||||
|
{
|
||||||
|
// Is menu outside on the right of the screen?
|
||||||
|
if ( x_pos+int(maxItemWidth)+2 > getColumnNumber() )
|
||||||
|
{
|
||||||
|
x_pos = getColumnNumber() - int(maxItemWidth + 1);
|
||||||
|
// Menu to large for the screen
|
||||||
|
if ( x_pos < 1 )
|
||||||
|
x_pos = 1;
|
||||||
|
}
|
||||||
|
return x_pos;
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------
|
||||||
|
void FMenu::adjustSize()
|
||||||
|
{
|
||||||
|
//int adjust_X = adjustX(xpos);
|
||||||
|
|
||||||
|
FWidget::adjustSize();
|
||||||
|
|
||||||
|
//move (adjust_X, ypos);
|
||||||
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
bool FMenu::isMenuBar (FWidget* w) const
|
bool FMenu::isMenuBar (FWidget* w) const
|
||||||
{
|
{
|
||||||
|
@ -643,22 +698,25 @@ void FMenu::drawItems()
|
||||||
if ( is_radio_btn )
|
if ( is_radio_btn )
|
||||||
{
|
{
|
||||||
if ( isNewFont() )
|
if ( isNewFont() )
|
||||||
print (fc::NF_Bullet);
|
print (fc::NF_Bullet); // NF_Bullet ●
|
||||||
else
|
else
|
||||||
print (fc::BlackCircle); // BlackCircle ●
|
print (fc::Bullet); // Bullet ●
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if ( isNewFont() )
|
if ( isNewFont() )
|
||||||
print (fc::NF_check_mark);
|
print (fc::NF_check_mark); // NF_check_mark ✓
|
||||||
else
|
else
|
||||||
print (fc::SquareRoot); // SquareRoot √
|
print (fc::SquareRoot); // SquareRoot √
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
setColor (wc.menu_inactive_fg, backgroundColor);
|
setColor (wc.menu_inactive_fg, backgroundColor);
|
||||||
print ('-');
|
if ( getEncoding() == "ASCII" )
|
||||||
|
print ('-');
|
||||||
|
else
|
||||||
|
print (fc::SmallBullet);
|
||||||
setColor (foregroundColor, backgroundColor);
|
setColor (foregroundColor, backgroundColor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1043,28 +1101,14 @@ void FMenu::onMouseUp (FMouseEvent* ev)
|
||||||
openSubMenu (sub_menu);
|
openSubMenu (sub_menu);
|
||||||
else if ( open_sub_menu )
|
else if ( open_sub_menu )
|
||||||
{
|
{
|
||||||
/*if ( open_sub_menu->hasSelectedItem() )
|
open_sub_menu->selectFirstItem();
|
||||||
{
|
if ( open_sub_menu->hasSelectedItem() )
|
||||||
FMenuItem* sel_item = getSelectedItem();
|
open_sub_menu->getSelectedItem()->setFocus();
|
||||||
hideSubMenus();
|
open_sub_menu->redraw();
|
||||||
sel_item->setFocus();
|
if ( statusBar() )
|
||||||
redraw();
|
statusBar()->drawMessage();
|
||||||
if ( statusBar() )
|
updateTerminal();
|
||||||
statusBar()->drawMessage();
|
flush_out();
|
||||||
updateTerminal();
|
|
||||||
flush_out();
|
|
||||||
}
|
|
||||||
else*/
|
|
||||||
{
|
|
||||||
open_sub_menu->selectFirstItem();
|
|
||||||
if ( open_sub_menu->hasSelectedItem() )
|
|
||||||
open_sub_menu->getSelectedItem()->setFocus();
|
|
||||||
open_sub_menu->redraw();
|
|
||||||
if ( statusBar() )
|
|
||||||
statusBar()->drawMessage();
|
|
||||||
updateTerminal();
|
|
||||||
flush_out();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,6 +58,9 @@ class FMenu : public FWindow, public FMenuList
|
||||||
FMenu& operator = (const FMenu&);
|
FMenu& operator = (const FMenu&);
|
||||||
void init(FWidget*);
|
void init(FWidget*);
|
||||||
void menu_dimension();
|
void menu_dimension();
|
||||||
|
void adjustItems();
|
||||||
|
int adjustX(int);
|
||||||
|
void adjustSize();
|
||||||
bool isMenuBar (FWidget*) const;
|
bool isMenuBar (FWidget*) const;
|
||||||
bool isMenu (FWidget*) const;
|
bool isMenu (FWidget*) const;
|
||||||
bool isRadioMenuItem (FWidget*) const;
|
bool isRadioMenuItem (FWidget*) const;
|
||||||
|
|
|
@ -432,14 +432,33 @@ void FMenuBar::drawItems()
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
void FMenuBar::adjustSize()
|
void FMenuBar::adjustItems()
|
||||||
{
|
{
|
||||||
xmin = ymin = 1;
|
int item_X = 1;
|
||||||
height = 1;
|
int item_Y = 1;
|
||||||
xpos = 1;
|
std::vector<FMenuItem*>::const_iterator end, iter;
|
||||||
width = getColumnNumber();
|
iter = itemlist.begin();
|
||||||
ypos = 1;
|
end = itemlist.end();
|
||||||
FWidget::adjustSize();
|
|
||||||
|
while ( iter != end )
|
||||||
|
{
|
||||||
|
// get item width
|
||||||
|
int item_width = (*iter)->getWidth();
|
||||||
|
|
||||||
|
if ( (*iter)->hasMenu() )
|
||||||
|
{
|
||||||
|
FMenu* menu = (*iter)->getMenu();
|
||||||
|
|
||||||
|
// set menu position
|
||||||
|
menu->move (menu->adjustX(item_X), item_Y);
|
||||||
|
|
||||||
|
// call menu adjustItems()
|
||||||
|
menu->adjustItems();
|
||||||
|
}
|
||||||
|
item_X += item_width;
|
||||||
|
|
||||||
|
++iter;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
|
@ -767,7 +786,8 @@ void FMenuBar::onMouseMove (FMouseEvent* ev)
|
||||||
FMenu* menu = getSelectedItem()->getMenu();
|
FMenu* menu = getSelectedItem()->getMenu();
|
||||||
const FRect& menu_geometry = menu->getGeometryGlobal();
|
const FRect& menu_geometry = menu->getGeometryGlobal();
|
||||||
|
|
||||||
if ( menu_geometry.contains(ev->getGlobalPos()) )
|
if ( menu->count() > 0
|
||||||
|
&& menu_geometry.contains(ev->getGlobalPos()) )
|
||||||
{
|
{
|
||||||
const FPoint& g = ev->getGlobalPos();
|
const FPoint& g = ev->getGlobalPos();
|
||||||
const FPoint& p = menu->globalToLocalPos(g);
|
const FPoint& p = menu->globalToLocalPos(g);
|
||||||
|
@ -830,6 +850,17 @@ void FMenuBar::resetMenu()
|
||||||
drop_down = false;
|
drop_down = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------
|
||||||
|
void FMenuBar::adjustSize()
|
||||||
|
{
|
||||||
|
xmin = ymin = 1;
|
||||||
|
height = 1;
|
||||||
|
xpos = 1;
|
||||||
|
width = getColumnNumber();
|
||||||
|
ypos = 1;
|
||||||
|
adjustItems();
|
||||||
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
void FMenuBar::setGeometry (int xx, int yy, int ww, int hh, bool adjust)
|
void FMenuBar::setGeometry (int xx, int yy, int ww, int hh, bool adjust)
|
||||||
{
|
{
|
||||||
|
|
|
@ -60,7 +60,7 @@ class FMenuBar : public FWindow, public FMenuList
|
||||||
int getHotkeyPos (wchar_t*&, wchar_t*&, uInt);
|
int getHotkeyPos (wchar_t*&, wchar_t*&, uInt);
|
||||||
void draw();
|
void draw();
|
||||||
void drawItems();
|
void drawItems();
|
||||||
void adjustSize();
|
void adjustItems();
|
||||||
void leaveMenuBar();
|
void leaveMenuBar();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -75,6 +75,7 @@ class FMenuBar : public FWindow, public FMenuList
|
||||||
void onAccel (FAccelEvent*);
|
void onAccel (FAccelEvent*);
|
||||||
void hide();
|
void hide();
|
||||||
void resetMenu();
|
void resetMenu();
|
||||||
|
void adjustSize();
|
||||||
// make every setGeometry from FWidget available
|
// make every setGeometry from FWidget available
|
||||||
using FWidget::setGeometry;
|
using FWidget::setGeometry;
|
||||||
void setGeometry (int, int, int, int, bool = true);
|
void setGeometry (int, int, int, int, bool = true);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
STARTFONT 2.1
|
STARTFONT 2.1
|
||||||
FONT -misc-8x16graph-medium-r-normal--16-160-75-75-C-80-iso8859-1
|
FONT -misc-8x16graph-medium-r-normal--17-160-75-75-C-80-iso8859-1
|
||||||
SIZE 16 75 75
|
SIZE 16 75 75
|
||||||
FONTBOUNDINGBOX 8 16 0 -4
|
FONTBOUNDINGBOX 8 16 0 -4
|
||||||
STARTPROPERTIES 6
|
STARTPROPERTIES 6
|
||||||
|
|
Binary file not shown.
|
@ -70,7 +70,7 @@ void FRadioButton::drawRadioButton()
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
print ('(');
|
print ('(');
|
||||||
print (fc::BlackCircle); // BlackCircle ●
|
print (fc::Bullet); // Bullet ●
|
||||||
print (')');
|
print (')');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -635,6 +635,26 @@ void FStatusBar::drawMessage()
|
||||||
setUpdateVTerm(true);
|
setUpdateVTerm(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------
|
||||||
|
void FStatusBar::setMessage (FString& mgs)
|
||||||
|
{
|
||||||
|
text = mgs;
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------
|
||||||
|
void FStatusBar::setMessage (const std::string& mgs)
|
||||||
|
{
|
||||||
|
FString s = FString(mgs);
|
||||||
|
setMessage (s);
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------
|
||||||
|
void FStatusBar::setMessage (const char* mgs)
|
||||||
|
{
|
||||||
|
FString s = FString(mgs);
|
||||||
|
setMessage (s);
|
||||||
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
void FStatusBar::insert (FStatusKey* skey)
|
void FStatusBar::insert (FStatusKey* skey)
|
||||||
{
|
{
|
||||||
|
|
|
@ -181,7 +181,9 @@ class FStatusBar : public FWindow
|
||||||
bool hasActivatedKey();
|
bool hasActivatedKey();
|
||||||
|
|
||||||
void drawMessage();
|
void drawMessage();
|
||||||
void setMessage (const FString);
|
void setMessage (FString&);
|
||||||
|
void setMessage (const std::string&);
|
||||||
|
void setMessage (const char*);
|
||||||
FString getMessage() const;
|
FString getMessage() const;
|
||||||
void clearMessage();
|
void clearMessage();
|
||||||
|
|
||||||
|
@ -220,10 +222,6 @@ inline void FStatusBar::deactivateKey (int index)
|
||||||
inline bool FStatusBar::isActivated(int index) const
|
inline bool FStatusBar::isActivated(int index) const
|
||||||
{ return keylist[uInt(index-1)]->isActivated(); }
|
{ return keylist[uInt(index-1)]->isActivated(); }
|
||||||
|
|
||||||
//----------------------------------------------------------------------
|
|
||||||
inline void FStatusBar::setMessage (FString mgs)
|
|
||||||
{ text = mgs; }
|
|
||||||
|
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
inline FString FStatusBar::getMessage() const
|
inline FString FStatusBar::getMessage() const
|
||||||
{ return text; }
|
{ return text; }
|
||||||
|
|
|
@ -1224,6 +1224,7 @@ void FWidget::resize()
|
||||||
menubar->setGeometry(1, 1, width, 1, false);
|
menubar->setGeometry(1, 1, width, 1, false);
|
||||||
if ( vmenubar )
|
if ( vmenubar )
|
||||||
resizeArea(vmenubar);
|
resizeArea(vmenubar);
|
||||||
|
menubar->adjustSize();
|
||||||
}
|
}
|
||||||
if ( statusbar )
|
if ( statusbar )
|
||||||
{
|
{
|
||||||
|
@ -1239,8 +1240,7 @@ void FWidget::resize()
|
||||||
|
|
||||||
while ( iter != end )
|
while ( iter != end )
|
||||||
{
|
{
|
||||||
if ( (*iter)->isVisible() )
|
(*iter)->adjustSize();
|
||||||
(*iter)->adjustSize();
|
|
||||||
++iter;
|
++iter;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -422,8 +422,8 @@ class FWidget : public FObject, public FTerm
|
||||||
void setBackgroundColor (int);
|
void setBackgroundColor (int);
|
||||||
void setX (int, bool = true);
|
void setX (int, bool = true);
|
||||||
void setY (int, bool = true);
|
void setY (int, bool = true);
|
||||||
void setPos (const FPoint&, bool = true);
|
virtual void setPos (const FPoint&, bool = true);
|
||||||
void setPos (int, int, bool = true);
|
virtual void setPos (int, int, bool = true);
|
||||||
void setWidth (int, bool = true);
|
void setWidth (int, bool = true);
|
||||||
void setHeight (int, bool = true);
|
void setHeight (int, bool = true);
|
||||||
void setTopPadding (int, bool = true);
|
void setTopPadding (int, bool = true);
|
||||||
|
|
|
@ -2,8 +2,6 @@
|
||||||
|
|
||||||
#include "final.h"
|
#include "final.h"
|
||||||
|
|
||||||
// You have chosen "Cola".
|
|
||||||
|
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
// class Menu
|
// class Menu
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
|
@ -154,6 +152,7 @@ Menu::Menu (FWidget* parent)
|
||||||
"clicked",
|
"clicked",
|
||||||
_METHOD_CALLBACK (this, &Menu::cb_message)
|
_METHOD_CALLBACK (this, &Menu::cb_message)
|
||||||
);
|
);
|
||||||
|
|
||||||
Quit->addCallback
|
Quit->addCallback
|
||||||
(
|
(
|
||||||
"clicked",
|
"clicked",
|
||||||
|
@ -232,8 +231,8 @@ void Menu::onClose (FCloseEvent* ev)
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
void Menu::cb_message (FWidget* widget, void*)
|
void Menu::cb_message (FWidget* widget, void*)
|
||||||
{
|
{
|
||||||
FButton* button = static_cast<FButton*>(widget);
|
FMenuItem* menuitem = static_cast<FMenuItem*>(widget);
|
||||||
FString text = button->getText();
|
FString text = menuitem->getText();
|
||||||
text = text.replace('&', "");
|
text = text.replace('&', "");
|
||||||
FMessageBox::info (this, "Info", "You have chosen \"" + text + "\"");
|
FMessageBox::info (this, "Info", "You have chosen \"" + text + "\"");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue