Avoid to show menus outside of the screen

This commit is contained in:
Markus Gans 2015-12-16 23:57:14 +01:00
parent 8099c16b57
commit cc58f61480
15 changed files with 156 additions and 58 deletions

View File

@ -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>
* Improve sub-sub-menu handling

View File

@ -32,7 +32,7 @@ static uInt character[][fc::NUM_OF_ENCODINGS] =
{0x02e3, '~', 0xfc, '~'}, // ˣ - Modifier letter small x
{0x00b0, 'f', 0xb0, 'o'}, // ° - Degree
{0x2022, '`', 0x04, '*'}, // • - Bullet
{0x00b7, '`', 0xf9, '*'}, // · - small Bullet
{0x00b7, '`', 0xf9, '.'}, // · - small Bullet
{0x25c6, '`', 0x04, '*'}, // ◆ - BlackDiamond
{0x2424, 'h', ' ', ' '}, // ␤ - SymbolForNewline
{0x240b, 'i', ' ', ' '}, // ␋ - SymbolForVerticalTab

View File

@ -168,8 +168,7 @@ class fc
NF_shadow_box_right = 0x1af5, // ]
NF_Bullet = 0x1af9, // ●
NF_check_mark = 0x1afb, // ✓
SquareRoot = 0x221a, // √
BlackCircle = 0x25CF // ●
SquareRoot = 0x221a // √
};
// keyboard - single keys

View File

@ -137,7 +137,7 @@ void FMenu::init(FWidget* parent)
//----------------------------------------------------------------------
void FMenu::menu_dimension()
{
int item_X, item_Y;
int item_X, item_Y, adjust_X;
std::vector<FMenuItem*>::const_iterator iter, end;
iter = itemlist.begin();
end = itemlist.end();
@ -169,8 +169,10 @@ void FMenu::menu_dimension()
++iter;
}
adjust_X = adjustX(xpos);
// 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
iter = itemlist.begin();
@ -182,8 +184,8 @@ void FMenu::menu_dimension()
(*iter)->setGeometry (item_X, item_Y, int(maxItemWidth), 1);
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;
// set sub-menu position
(*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
{
@ -643,22 +698,25 @@ void FMenu::drawItems()
if ( is_radio_btn )
{
if ( isNewFont() )
print (fc::NF_Bullet);
print (fc::NF_Bullet); // NF_Bullet ●
else
print (fc::BlackCircle); // BlackCircle ●
print (fc::Bullet); // Bullet
}
else
{
if ( isNewFont() )
print (fc::NF_check_mark);
print (fc::NF_check_mark); // NF_check_mark ✓
else
print (fc::SquareRoot); // SquareRoot √
print (fc::SquareRoot); // SquareRoot √
}
}
else
{
setColor (wc.menu_inactive_fg, backgroundColor);
print ('-');
if ( getEncoding() == "ASCII" )
print ('-');
else
print (fc::SmallBullet);
setColor (foregroundColor, backgroundColor);
}
}
@ -1043,28 +1101,14 @@ void FMenu::onMouseUp (FMouseEvent* ev)
openSubMenu (sub_menu);
else if ( open_sub_menu )
{
/*if ( open_sub_menu->hasSelectedItem() )
{
FMenuItem* sel_item = getSelectedItem();
hideSubMenus();
sel_item->setFocus();
redraw();
if ( statusBar() )
statusBar()->drawMessage();
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();
}
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;
}

View File

@ -58,6 +58,9 @@ class FMenu : public FWindow, public FMenuList
FMenu& operator = (const FMenu&);
void init(FWidget*);
void menu_dimension();
void adjustItems();
int adjustX(int);
void adjustSize();
bool isMenuBar (FWidget*) const;
bool isMenu (FWidget*) const;
bool isRadioMenuItem (FWidget*) const;

View File

@ -432,14 +432,33 @@ void FMenuBar::drawItems()
}
//----------------------------------------------------------------------
void FMenuBar::adjustSize()
void FMenuBar::adjustItems()
{
xmin = ymin = 1;
height = 1;
xpos = 1;
width = getColumnNumber();
ypos = 1;
FWidget::adjustSize();
int item_X = 1;
int item_Y = 1;
std::vector<FMenuItem*>::const_iterator end, iter;
iter = itemlist.begin();
end = itemlist.end();
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();
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& p = menu->globalToLocalPos(g);
@ -830,6 +850,17 @@ void FMenuBar::resetMenu()
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)
{

View File

@ -60,7 +60,7 @@ class FMenuBar : public FWindow, public FMenuList
int getHotkeyPos (wchar_t*&, wchar_t*&, uInt);
void draw();
void drawItems();
void adjustSize();
void adjustItems();
void leaveMenuBar();
public:
@ -75,6 +75,7 @@ class FMenuBar : public FWindow, public FMenuList
void onAccel (FAccelEvent*);
void hide();
void resetMenu();
void adjustSize();
// make every setGeometry from FWidget available
using FWidget::setGeometry;
void setGeometry (int, int, int, int, bool = true);

View File

@ -1,5 +1,5 @@
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
FONTBOUNDINGBOX 8 16 0 -4
STARTPROPERTIES 6

Binary file not shown.

View File

@ -70,7 +70,7 @@ void FRadioButton::drawRadioButton()
else
{
print ('(');
print (fc::BlackCircle); // BlackCircle ●
print (fc::Bullet); // Bullet
print (')');
}
}

View File

@ -635,6 +635,26 @@ void FStatusBar::drawMessage()
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)
{

View File

@ -181,7 +181,9 @@ class FStatusBar : public FWindow
bool hasActivatedKey();
void drawMessage();
void setMessage (const FString);
void setMessage (FString&);
void setMessage (const std::string&);
void setMessage (const char*);
FString getMessage() const;
void clearMessage();
@ -220,10 +222,6 @@ inline void FStatusBar::deactivateKey (int index)
inline bool FStatusBar::isActivated(int index) const
{ return keylist[uInt(index-1)]->isActivated(); }
//----------------------------------------------------------------------
inline void FStatusBar::setMessage (FString mgs)
{ text = mgs; }
//----------------------------------------------------------------------
inline FString FStatusBar::getMessage() const
{ return text; }

View File

@ -1224,6 +1224,7 @@ void FWidget::resize()
menubar->setGeometry(1, 1, width, 1, false);
if ( vmenubar )
resizeArea(vmenubar);
menubar->adjustSize();
}
if ( statusbar )
{
@ -1239,8 +1240,7 @@ void FWidget::resize()
while ( iter != end )
{
if ( (*iter)->isVisible() )
(*iter)->adjustSize();
(*iter)->adjustSize();
++iter;
}
}

View File

@ -422,8 +422,8 @@ class FWidget : public FObject, public FTerm
void setBackgroundColor (int);
void setX (int, bool = true);
void setY (int, bool = true);
void setPos (const FPoint&, bool = true);
void setPos (int, int, bool = true);
virtual void setPos (const FPoint&, bool = true);
virtual void setPos (int, int, bool = true);
void setWidth (int, bool = true);
void setHeight (int, bool = true);
void setTopPadding (int, bool = true);

View File

@ -2,8 +2,6 @@
#include "final.h"
// You have chosen "Cola".
//----------------------------------------------------------------------
// class Menu
//----------------------------------------------------------------------
@ -154,6 +152,7 @@ Menu::Menu (FWidget* parent)
"clicked",
_METHOD_CALLBACK (this, &Menu::cb_message)
);
Quit->addCallback
(
"clicked",
@ -232,8 +231,8 @@ void Menu::onClose (FCloseEvent* ev)
//----------------------------------------------------------------------
void Menu::cb_message (FWidget* widget, void*)
{
FButton* button = static_cast<FButton*>(widget);
FString text = button->getText();
FMenuItem* menuitem = static_cast<FMenuItem*>(widget);
FString text = menuitem->getText();
text = text.replace('&', "");
FMessageBox::info (this, "Info", "You have chosen \"" + text + "\"");
}