Add "menu" example
This commit is contained in:
parent
ae62812335
commit
7207eaa0ff
|
@ -28,6 +28,7 @@ test/dialog
|
||||||
test/string-operations
|
test/string-operations
|
||||||
test/hello
|
test/hello
|
||||||
test/watch
|
test/watch
|
||||||
|
test/menu
|
||||||
test/input-dialog
|
test/input-dialog
|
||||||
test/mandelbrot
|
test/mandelbrot
|
||||||
test/keyboard
|
test/keyboard
|
||||||
|
|
|
@ -1,3 +1,8 @@
|
||||||
|
2015-12-08 Markus Gans <guru.mail@muenster.de>
|
||||||
|
* Add "menu" example to demonstrate the behavior from FMenuBar,
|
||||||
|
FMenu, FMenuItem, FCheckMenuItem and FRadioMenuItem widgets.
|
||||||
|
* Show status bar messages, if no keys are available.
|
||||||
|
|
||||||
2015-11-29 Markus Gans <guru.mail@muenster.de>
|
2015-11-29 Markus Gans <guru.mail@muenster.de>
|
||||||
* Better handling of empty strings in FLineEdit and FButton
|
* Better handling of empty strings in FLineEdit and FButton
|
||||||
* Add a sub-menu to the "ui.cpp" example
|
* Add a sub-menu to the "ui.cpp" example
|
||||||
|
|
|
@ -976,12 +976,15 @@ void FApplication::processMouseEvent()
|
||||||
menu->hide();
|
menu->hide();
|
||||||
menu->hideSubMenus();
|
menu->hideSubMenus();
|
||||||
menu->hideSuperMenus();
|
menu->hideSuperMenus();
|
||||||
|
if ( statusBar() )
|
||||||
|
statusBar()->clearMessage();
|
||||||
|
|
||||||
// No widget was been clicked
|
// No widget was been clicked
|
||||||
if ( ! clicked_widget )
|
if ( ! clicked_widget )
|
||||||
{
|
{
|
||||||
// activate previous window
|
// activate previous window
|
||||||
FWindow::activatePrevWindow();
|
FWindow::activatePrevWindow();
|
||||||
|
FWindow::raiseWindow (FWindow::getActiveWindow());
|
||||||
FWindow::getActiveWindow()->getFocusWidget()->setFocus();
|
FWindow::getActiveWindow()->getFocusWidget()->setFocus();
|
||||||
FWindow::getActiveWindow()->redraw();
|
FWindow::getActiveWindow()->redraw();
|
||||||
if ( statusBar() )
|
if ( statusBar() )
|
||||||
|
|
|
@ -233,7 +233,8 @@ void FDialog::drawTitleBar()
|
||||||
print (' ');
|
print (' ');
|
||||||
|
|
||||||
// the title bar text
|
// the title bar text
|
||||||
print (tb_text);
|
if ( tb_text )
|
||||||
|
print (tb_text);
|
||||||
|
|
||||||
// fill the rest of the bar
|
// fill the rest of the bar
|
||||||
for (; x+1+int(length) < width-1; x++)
|
for (; x+1+int(length) < width-1; x++)
|
||||||
|
|
|
@ -123,6 +123,12 @@ void FMenu::init(FWidget* parent)
|
||||||
if ( mbar )
|
if ( mbar )
|
||||||
mbar->menu_dimension();
|
mbar->menu_dimension();
|
||||||
}
|
}
|
||||||
|
else if ( isMenu(parent) )
|
||||||
|
{
|
||||||
|
FMenu* smenu = dynamic_cast<FMenu*>(parent);
|
||||||
|
if ( smenu )
|
||||||
|
smenu->menu_dimension();
|
||||||
|
}
|
||||||
setSuperMenu(parent);
|
setSuperMenu(parent);
|
||||||
}
|
}
|
||||||
menu_dimension();
|
menu_dimension();
|
||||||
|
@ -176,9 +182,9 @@ 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)->getX() + int(maxItemWidth) + 1;
|
int menu_X = (*iter)->getGlobalX() + int(maxItemWidth);
|
||||||
int menu_Y = (*iter)->getY();
|
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);
|
||||||
}
|
}
|
||||||
|
@ -227,7 +233,8 @@ void FMenu::openSubMenu (FMenu* sub_menu)
|
||||||
|
|
||||||
// open sub menu
|
// open sub menu
|
||||||
sub_menu->selectFirstItem();
|
sub_menu->selectFirstItem();
|
||||||
sub_menu->getSelectedItem()->setFocus();
|
if ( sub_menu->hasSelectedItem() )
|
||||||
|
sub_menu->getSelectedItem()->setFocus();
|
||||||
sub_menu->setVisible();
|
sub_menu->setVisible();
|
||||||
sub_menu->show();
|
sub_menu->show();
|
||||||
open_sub_menu = sub_menu;
|
open_sub_menu = sub_menu;
|
||||||
|
@ -865,6 +872,7 @@ void FMenu::onKeyPress (FKeyEvent* ev)
|
||||||
{
|
{
|
||||||
hideSuperMenus();
|
hideSuperMenus();
|
||||||
activatePrevWindow();
|
activatePrevWindow();
|
||||||
|
raiseWindow (getActiveWindow());
|
||||||
getActiveWindow()->getFocusWidget()->setFocus();
|
getActiveWindow()->getFocusWidget()->setFocus();
|
||||||
getActiveWindow()->redraw();
|
getActiveWindow()->redraw();
|
||||||
}
|
}
|
||||||
|
@ -1031,7 +1039,7 @@ 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() )
|
/*if ( open_sub_menu->hasSelectedItem() )
|
||||||
{
|
{
|
||||||
FMenuItem* sel_item = getSelectedItem();
|
FMenuItem* sel_item = getSelectedItem();
|
||||||
hideSubMenus();
|
hideSubMenus();
|
||||||
|
@ -1042,10 +1050,11 @@ void FMenu::onMouseUp (FMouseEvent* ev)
|
||||||
updateTerminal();
|
updateTerminal();
|
||||||
flush_out();
|
flush_out();
|
||||||
}
|
}
|
||||||
else
|
else*/
|
||||||
{
|
{
|
||||||
open_sub_menu->selectFirstItem();
|
open_sub_menu->selectFirstItem();
|
||||||
open_sub_menu->getSelectedItem()->setFocus();
|
if ( open_sub_menu->hasSelectedItem() )
|
||||||
|
open_sub_menu->getSelectedItem()->setFocus();
|
||||||
open_sub_menu->redraw();
|
open_sub_menu->redraw();
|
||||||
if ( statusBar() )
|
if ( statusBar() )
|
||||||
statusBar()->drawMessage();
|
statusBar()->drawMessage();
|
||||||
|
@ -1154,6 +1163,7 @@ void FMenu::onMouseMove (FMouseEvent* ev)
|
||||||
focused_widget->redraw();
|
focused_widget->redraw();
|
||||||
if ( statusBar() )
|
if ( statusBar() )
|
||||||
statusBar()->drawMessage();
|
statusBar()->drawMessage();
|
||||||
|
// sub menu handling
|
||||||
if ( (*iter)->hasMenu() )
|
if ( (*iter)->hasMenu() )
|
||||||
{
|
{
|
||||||
FMenu* sub_menu = (*iter)->getMenu();
|
FMenu* sub_menu = (*iter)->getMenu();
|
||||||
|
@ -1239,6 +1249,12 @@ void FMenu::onMouseMove (FMouseEvent* ev)
|
||||||
|
|
||||||
if ( show_sub_menu )
|
if ( show_sub_menu )
|
||||||
{
|
{
|
||||||
|
// close open sub menu
|
||||||
|
if ( open_sub_menu )
|
||||||
|
{
|
||||||
|
open_sub_menu->hideSubMenus();
|
||||||
|
open_sub_menu->hide();
|
||||||
|
}
|
||||||
// open sub menu
|
// open sub menu
|
||||||
show_sub_menu->setVisible();
|
show_sub_menu->setVisible();
|
||||||
show_sub_menu->show();
|
show_sub_menu->show();
|
||||||
|
|
|
@ -566,22 +566,22 @@ void FMenuBar::onMouseDown (FMouseEvent* ev)
|
||||||
FApplication::queueEvent(focused_widget, &out);
|
FApplication::queueEvent(focused_widget, &out);
|
||||||
(*iter)->setSelected();
|
(*iter)->setSelected();
|
||||||
(*iter)->setFocus();
|
(*iter)->setFocus();
|
||||||
|
if ( focused_widget )
|
||||||
|
focused_widget->redraw();
|
||||||
(*iter)->openMenu();
|
(*iter)->openMenu();
|
||||||
setSelectedItem(*iter);
|
setSelectedItem(*iter);
|
||||||
focus_changed = true;
|
focus_changed = true;
|
||||||
if ( focused_widget )
|
|
||||||
focused_widget->redraw();
|
if ( (*iter)->hasMenu() )
|
||||||
}
|
{
|
||||||
if ( (*iter)->hasMenu() )
|
FMenu* menu = (*iter)->getMenu();
|
||||||
{
|
if ( menu->hasSelectedItem() )
|
||||||
FMenu* menu = (*iter)->getMenu();
|
{
|
||||||
if ( menu->hasSelectedItem() )
|
menu->unselectItem();
|
||||||
{
|
menu->redraw();
|
||||||
menu->unselectItem();
|
drop_down = true;
|
||||||
menu->redraw();
|
}
|
||||||
focus_changed = true;
|
}
|
||||||
drop_down = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -728,11 +728,11 @@ void FMenuBar::onMouseMove (FMouseEvent* ev)
|
||||||
FApplication::queueEvent(focused_widget, &out);
|
FApplication::queueEvent(focused_widget, &out);
|
||||||
(*iter)->setSelected();
|
(*iter)->setSelected();
|
||||||
(*iter)->setFocus();
|
(*iter)->setFocus();
|
||||||
|
if ( focused_widget )
|
||||||
|
focused_widget->redraw();
|
||||||
(*iter)->openMenu();
|
(*iter)->openMenu();
|
||||||
setSelectedItem(*iter);
|
setSelectedItem(*iter);
|
||||||
focus_changed = true;
|
focus_changed = true;
|
||||||
if ( focused_widget )
|
|
||||||
focused_widget->redraw();
|
|
||||||
|
|
||||||
if ( (*iter)->hasMenu() )
|
if ( (*iter)->hasMenu() )
|
||||||
{
|
{
|
||||||
|
|
|
@ -221,7 +221,10 @@ void FStatusBar::drawKeys()
|
||||||
ypos = lastLine;
|
ypos = lastLine;
|
||||||
|
|
||||||
if ( keylist.empty() )
|
if ( keylist.empty() )
|
||||||
|
{
|
||||||
|
x_msg = 1;
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
setUpdateVTerm(false);
|
setUpdateVTerm(false);
|
||||||
gotoxy (1, lastLine);
|
gotoxy (1, lastLine);
|
||||||
|
@ -565,7 +568,7 @@ bool FStatusBar::hasActivatedKey()
|
||||||
void FStatusBar::drawMessage()
|
void FStatusBar::drawMessage()
|
||||||
{
|
{
|
||||||
int termWidth, lastLine, space_offset;
|
int termWidth, lastLine, space_offset;
|
||||||
bool isLastActiveFocus;
|
bool isLastActiveFocus, hasKeys;
|
||||||
|
|
||||||
if ( ! isVisible() )
|
if ( ! isVisible() )
|
||||||
return;
|
return;
|
||||||
|
@ -576,8 +579,9 @@ void FStatusBar::drawMessage()
|
||||||
termWidth = getColumnNumber();
|
termWidth = getColumnNumber();
|
||||||
lastLine = getLineNumber();
|
lastLine = getLineNumber();
|
||||||
space_offset = 1;
|
space_offset = 1;
|
||||||
|
hasKeys = bool(! keylist.empty());
|
||||||
|
|
||||||
if ( ! keylist.empty() )
|
if ( hasKeys )
|
||||||
{
|
{
|
||||||
std::vector<FStatusKey*>::const_iterator iter = keylist.end();
|
std::vector<FStatusKey*>::const_iterator iter = keylist.end();
|
||||||
isLastActiveFocus = bool( (*(iter-1))->isActivated()
|
isLastActiveFocus = bool( (*(iter-1))->isActivated()
|
||||||
|
@ -598,14 +602,17 @@ void FStatusBar::drawMessage()
|
||||||
{
|
{
|
||||||
if ( text )
|
if ( text )
|
||||||
{
|
{
|
||||||
x += 2;
|
|
||||||
if ( ! isLastActiveFocus )
|
if ( ! isLastActiveFocus )
|
||||||
{
|
{
|
||||||
x++;
|
x++;
|
||||||
print (vstatusbar, ' ');
|
print (vstatusbar, ' ');
|
||||||
}
|
}
|
||||||
print (vstatusbar, fc::BoxDrawingsVertical); // │
|
if ( hasKeys )
|
||||||
print (vstatusbar, ' ');
|
{
|
||||||
|
x += 2;
|
||||||
|
print (vstatusbar, fc::BoxDrawingsVertical); // │
|
||||||
|
print (vstatusbar, ' ');
|
||||||
|
}
|
||||||
|
|
||||||
int msg_length = int(getMessage().getLength());
|
int msg_length = int(getMessage().getLength());
|
||||||
x += msg_length;
|
x += msg_length;
|
||||||
|
|
|
@ -685,7 +685,8 @@ bool FWidget::focusNextChild(void)
|
||||||
{
|
{
|
||||||
if ( hasParent() )
|
if ( hasParent() )
|
||||||
{
|
{
|
||||||
if ( getParent()->hasChildren() )
|
FWidget* parent = static_cast<FWidget*>(getParent());
|
||||||
|
if ( parent->hasChildren() && parent->numOfFocusableChildren() > 1 )
|
||||||
{
|
{
|
||||||
FObject::object_list children;
|
FObject::object_list children;
|
||||||
FObject::object_list::iterator iter, end;
|
FObject::object_list::iterator iter, end;
|
||||||
|
@ -746,7 +747,8 @@ bool FWidget::focusPrevChild(void)
|
||||||
{
|
{
|
||||||
if ( hasParent() )
|
if ( hasParent() )
|
||||||
{
|
{
|
||||||
if ( getParent()->hasChildren() )
|
FWidget* parent = static_cast<FWidget*>(getParent());
|
||||||
|
if ( parent->hasChildren() && parent->numOfFocusableChildren() > 1 )
|
||||||
{
|
{
|
||||||
FObject::object_list children;
|
FObject::object_list children;
|
||||||
FObject::object_list::iterator iter, begin;
|
FObject::object_list::iterator iter, begin;
|
||||||
|
|
|
@ -15,6 +15,7 @@ noinst_PROGRAMS = \
|
||||||
watch \
|
watch \
|
||||||
keyboard \
|
keyboard \
|
||||||
timer \
|
timer \
|
||||||
|
menu \
|
||||||
ui
|
ui
|
||||||
|
|
||||||
hello_SOURCES = hello.cpp
|
hello_SOURCES = hello.cpp
|
||||||
|
@ -26,5 +27,5 @@ calculator_SOURCES = calculator.cpp
|
||||||
watch_SOURCES = watch.cpp
|
watch_SOURCES = watch.cpp
|
||||||
keyboard_SOURCES = keyboard.cpp
|
keyboard_SOURCES = keyboard.cpp
|
||||||
timer_SOURCES = timer.cpp
|
timer_SOURCES = timer.cpp
|
||||||
|
menu_SOURCES = menu.cpp
|
||||||
ui_SOURCES = ui.cpp
|
ui_SOURCES = ui.cpp
|
||||||
|
|
||||||
|
|
|
@ -85,7 +85,7 @@ host_triplet = @host@
|
||||||
noinst_PROGRAMS = hello$(EXEEXT) dialog$(EXEEXT) input-dialog$(EXEEXT) \
|
noinst_PROGRAMS = hello$(EXEEXT) dialog$(EXEEXT) input-dialog$(EXEEXT) \
|
||||||
string-operations$(EXEEXT) mandelbrot$(EXEEXT) \
|
string-operations$(EXEEXT) mandelbrot$(EXEEXT) \
|
||||||
calculator$(EXEEXT) watch$(EXEEXT) keyboard$(EXEEXT) \
|
calculator$(EXEEXT) watch$(EXEEXT) keyboard$(EXEEXT) \
|
||||||
timer$(EXEEXT) ui$(EXEEXT)
|
timer$(EXEEXT) menu$(EXEEXT) ui$(EXEEXT)
|
||||||
subdir = test
|
subdir = test
|
||||||
DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am \
|
DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am \
|
||||||
$(top_srcdir)/depcomp
|
$(top_srcdir)/depcomp
|
||||||
|
@ -123,6 +123,9 @@ keyboard_LDADD = $(LDADD)
|
||||||
am_mandelbrot_OBJECTS = mandelbrot.$(OBJEXT)
|
am_mandelbrot_OBJECTS = mandelbrot.$(OBJEXT)
|
||||||
mandelbrot_OBJECTS = $(am_mandelbrot_OBJECTS)
|
mandelbrot_OBJECTS = $(am_mandelbrot_OBJECTS)
|
||||||
mandelbrot_LDADD = $(LDADD)
|
mandelbrot_LDADD = $(LDADD)
|
||||||
|
am_menu_OBJECTS = menu.$(OBJEXT)
|
||||||
|
menu_OBJECTS = $(am_menu_OBJECTS)
|
||||||
|
menu_LDADD = $(LDADD)
|
||||||
am_string_operations_OBJECTS = string-operations.$(OBJEXT)
|
am_string_operations_OBJECTS = string-operations.$(OBJEXT)
|
||||||
string_operations_OBJECTS = $(am_string_operations_OBJECTS)
|
string_operations_OBJECTS = $(am_string_operations_OBJECTS)
|
||||||
string_operations_LDADD = $(LDADD)
|
string_operations_LDADD = $(LDADD)
|
||||||
|
@ -171,12 +174,14 @@ am__v_CXXLD_0 = @echo " CXXLD " $@;
|
||||||
am__v_CXXLD_1 =
|
am__v_CXXLD_1 =
|
||||||
SOURCES = $(calculator_SOURCES) $(dialog_SOURCES) $(hello_SOURCES) \
|
SOURCES = $(calculator_SOURCES) $(dialog_SOURCES) $(hello_SOURCES) \
|
||||||
$(input_dialog_SOURCES) $(keyboard_SOURCES) \
|
$(input_dialog_SOURCES) $(keyboard_SOURCES) \
|
||||||
$(mandelbrot_SOURCES) $(string_operations_SOURCES) \
|
$(mandelbrot_SOURCES) $(menu_SOURCES) \
|
||||||
$(timer_SOURCES) $(ui_SOURCES) $(watch_SOURCES)
|
$(string_operations_SOURCES) $(timer_SOURCES) $(ui_SOURCES) \
|
||||||
|
$(watch_SOURCES)
|
||||||
DIST_SOURCES = $(calculator_SOURCES) $(dialog_SOURCES) \
|
DIST_SOURCES = $(calculator_SOURCES) $(dialog_SOURCES) \
|
||||||
$(hello_SOURCES) $(input_dialog_SOURCES) $(keyboard_SOURCES) \
|
$(hello_SOURCES) $(input_dialog_SOURCES) $(keyboard_SOURCES) \
|
||||||
$(mandelbrot_SOURCES) $(string_operations_SOURCES) \
|
$(mandelbrot_SOURCES) $(menu_SOURCES) \
|
||||||
$(timer_SOURCES) $(ui_SOURCES) $(watch_SOURCES)
|
$(string_operations_SOURCES) $(timer_SOURCES) $(ui_SOURCES) \
|
||||||
|
$(watch_SOURCES)
|
||||||
am__can_run_installinfo = \
|
am__can_run_installinfo = \
|
||||||
case $$AM_UPDATE_INFO_DIR in \
|
case $$AM_UPDATE_INFO_DIR in \
|
||||||
n|no|NO) false;; \
|
n|no|NO) false;; \
|
||||||
|
@ -334,6 +339,7 @@ calculator_SOURCES = calculator.cpp
|
||||||
watch_SOURCES = watch.cpp
|
watch_SOURCES = watch.cpp
|
||||||
keyboard_SOURCES = keyboard.cpp
|
keyboard_SOURCES = keyboard.cpp
|
||||||
timer_SOURCES = timer.cpp
|
timer_SOURCES = timer.cpp
|
||||||
|
menu_SOURCES = menu.cpp
|
||||||
ui_SOURCES = ui.cpp
|
ui_SOURCES = ui.cpp
|
||||||
all: all-am
|
all: all-am
|
||||||
|
|
||||||
|
@ -403,6 +409,10 @@ mandelbrot$(EXEEXT): $(mandelbrot_OBJECTS) $(mandelbrot_DEPENDENCIES) $(EXTRA_ma
|
||||||
@rm -f mandelbrot$(EXEEXT)
|
@rm -f mandelbrot$(EXEEXT)
|
||||||
$(AM_V_CXXLD)$(CXXLINK) $(mandelbrot_OBJECTS) $(mandelbrot_LDADD) $(LIBS)
|
$(AM_V_CXXLD)$(CXXLINK) $(mandelbrot_OBJECTS) $(mandelbrot_LDADD) $(LIBS)
|
||||||
|
|
||||||
|
menu$(EXEEXT): $(menu_OBJECTS) $(menu_DEPENDENCIES) $(EXTRA_menu_DEPENDENCIES)
|
||||||
|
@rm -f menu$(EXEEXT)
|
||||||
|
$(AM_V_CXXLD)$(CXXLINK) $(menu_OBJECTS) $(menu_LDADD) $(LIBS)
|
||||||
|
|
||||||
string-operations$(EXEEXT): $(string_operations_OBJECTS) $(string_operations_DEPENDENCIES) $(EXTRA_string_operations_DEPENDENCIES)
|
string-operations$(EXEEXT): $(string_operations_OBJECTS) $(string_operations_DEPENDENCIES) $(EXTRA_string_operations_DEPENDENCIES)
|
||||||
@rm -f string-operations$(EXEEXT)
|
@rm -f string-operations$(EXEEXT)
|
||||||
$(AM_V_CXXLD)$(CXXLINK) $(string_operations_OBJECTS) $(string_operations_LDADD) $(LIBS)
|
$(AM_V_CXXLD)$(CXXLINK) $(string_operations_OBJECTS) $(string_operations_LDADD) $(LIBS)
|
||||||
|
@ -431,6 +441,7 @@ distclean-compile:
|
||||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/input-dialog.Po@am__quote@
|
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/input-dialog.Po@am__quote@
|
||||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/keyboard.Po@am__quote@
|
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/keyboard.Po@am__quote@
|
||||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mandelbrot.Po@am__quote@
|
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mandelbrot.Po@am__quote@
|
||||||
|
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/menu.Po@am__quote@
|
||||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/string-operations.Po@am__quote@
|
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/string-operations.Po@am__quote@
|
||||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/timer.Po@am__quote@
|
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/timer.Po@am__quote@
|
||||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ui.Po@am__quote@
|
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ui.Po@am__quote@
|
||||||
|
|
|
@ -0,0 +1,283 @@
|
||||||
|
// File: menu.cpp
|
||||||
|
|
||||||
|
#include "final.h"
|
||||||
|
|
||||||
|
// You have chosen "Cola".
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------
|
||||||
|
// class Menu
|
||||||
|
//----------------------------------------------------------------------
|
||||||
|
|
||||||
|
#pragma pack(push)
|
||||||
|
#pragma pack(1)
|
||||||
|
|
||||||
|
class Menu : public FDialog
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
Menu (const Menu&); // Disabled copy constructor
|
||||||
|
Menu& operator = (const Menu&); // and operator '='
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit Menu (FWidget* = 0); // constructor
|
||||||
|
~Menu(); // destructor
|
||||||
|
void onClose (FCloseEvent*);
|
||||||
|
void cb_message (FWidget*, void*);
|
||||||
|
void cb_exitApp (FWidget*, void*);
|
||||||
|
protected:
|
||||||
|
void adjustSize();
|
||||||
|
};
|
||||||
|
#pragma pack(pop)
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------
|
||||||
|
Menu::Menu (FWidget* parent)
|
||||||
|
: FDialog(parent)
|
||||||
|
{
|
||||||
|
// menu bar
|
||||||
|
FMenuBar* Menubar = new FMenuBar (this);
|
||||||
|
|
||||||
|
// menu bar items
|
||||||
|
FMenu* File = new FMenu ("&File", Menubar);
|
||||||
|
File->setStatusbarMessage ("File management commands");
|
||||||
|
FMenu* Edit = new FMenu ("&Edit", Menubar);
|
||||||
|
Edit->setStatusbarMessage ("Cut-and-paste editing commands");
|
||||||
|
FMenu* Choice = new FMenu ("&Choice", Menubar);
|
||||||
|
Choice->setStatusbarMessage ("Choice menu");
|
||||||
|
FMenuItem* Window = new FMenuItem ("&Window", Menubar);
|
||||||
|
Window->setDisable();
|
||||||
|
FMenuItem* Help = new FMenuItem ("&Help", Menubar);
|
||||||
|
Help->setStatusbarMessage ("Show version and copyright information");
|
||||||
|
|
||||||
|
// "File" menu items
|
||||||
|
FMenuItem* New = new FMenuItem ("&New", File);
|
||||||
|
New->addAccelerator (fc::Fckey_n); // Ctrl + N
|
||||||
|
New->setStatusbarMessage ("Create a new file");
|
||||||
|
FMenuItem* Open = new FMenuItem ("&Open...", File);
|
||||||
|
Open->addAccelerator (fc::Fckey_o); // Ctrl + O
|
||||||
|
Open->setStatusbarMessage ("Locate and open a text file");
|
||||||
|
FMenuItem* Save = new FMenuItem ("&Save", File);
|
||||||
|
Save->addAccelerator (fc::Fckey_s); // Ctrl + S
|
||||||
|
Save->setStatusbarMessage ("Save the file");
|
||||||
|
FMenuItem* SaveAs = new FMenuItem ("&Save as...", File);
|
||||||
|
SaveAs->setStatusbarMessage ("Save the current file under a different name");
|
||||||
|
FMenuItem* Close = new FMenuItem ("&Close", File);
|
||||||
|
Close->addAccelerator (fc::Fckey_w); // Ctrl + W
|
||||||
|
Close->setStatusbarMessage ("Close the current file");
|
||||||
|
FMenuItem* Line1 = new FMenuItem (File);
|
||||||
|
Line1->setSeparator();
|
||||||
|
FMenuItem* Print = new FMenuItem ("&Print", File);
|
||||||
|
Print->addAccelerator (fc::Fckey_p); // Ctrl + P
|
||||||
|
Print->setStatusbarMessage ("Print the current file");
|
||||||
|
FMenuItem* Line2 = new FMenuItem (File);
|
||||||
|
Line2->setSeparator();
|
||||||
|
FMenuItem* Quit = new FMenuItem ("&Quit", File);
|
||||||
|
Quit->addAccelerator (fc::Fmkey_x); // Meta/Alt + X
|
||||||
|
Quit->setStatusbarMessage ("Exit the program");
|
||||||
|
|
||||||
|
// "Edit" menu items
|
||||||
|
FMenuItem* Undo = new FMenuItem (fc::Fckey_z, "&Undo", Edit);
|
||||||
|
Undo->setStatusbarMessage ("Undo the previous operation");
|
||||||
|
FMenuItem* Redo = new FMenuItem (fc::Fckey_y, "&Redo", Edit);
|
||||||
|
Redo->setDisable();
|
||||||
|
FMenuItem* Line3 = new FMenuItem (Edit);
|
||||||
|
Line3->setSeparator();
|
||||||
|
FMenuItem* Cut = new FMenuItem (fc::Fckey_x, "Cu&t", Edit);
|
||||||
|
Cut->setStatusbarMessage ("Remove the input text and put it in the clipboard");
|
||||||
|
FMenuItem* Copy = new FMenuItem (fc::Fckey_c, "&Copy", Edit);
|
||||||
|
Copy->setStatusbarMessage ("Copy the input text into the clipboad");
|
||||||
|
FMenuItem* Paste = new FMenuItem (fc::Fckey_v, "&Paste", Edit);
|
||||||
|
Paste->setStatusbarMessage ("Insert text form clipboard");
|
||||||
|
FMenuItem* Line4 = new FMenuItem (Edit);
|
||||||
|
Line4->setSeparator();
|
||||||
|
FMenuItem* Search = new FMenuItem (fc::Fckey_f, "&Search", Edit);
|
||||||
|
Search->setStatusbarMessage ("Search for text");
|
||||||
|
FMenuItem* Next = new FMenuItem (fc::Fkey_f3, "Search &next", Edit);
|
||||||
|
Next->setStatusbarMessage ("Repeat the last search command");
|
||||||
|
FMenuItem* Line5 = new FMenuItem (Edit);
|
||||||
|
Line5->setSeparator();
|
||||||
|
FMenuItem* SelectAll = new FMenuItem (fc::Fckey_a, "Select &all", Edit);
|
||||||
|
SelectAll->setStatusbarMessage ("Select the whole text");
|
||||||
|
|
||||||
|
// "Choice" menu items
|
||||||
|
FMenu* Color = new FMenu ("&Color", Choice);
|
||||||
|
Color->setStatusbarMessage ("Choose a color");
|
||||||
|
FMenu* Style = new FMenu ("&Style", Choice);
|
||||||
|
Style->setStatusbarMessage ("Choose a Style");
|
||||||
|
FMenu* Border = new FMenu ("&Border", Choice);
|
||||||
|
Border->setStatusbarMessage ("Choose Border");
|
||||||
|
|
||||||
|
// "Color" menu items
|
||||||
|
FRadioMenuItem* Color1 = new FRadioMenuItem ("Red", Color);
|
||||||
|
Color1->setStatusbarMessage ("Set text red");
|
||||||
|
FRadioMenuItem* Color2 = new FRadioMenuItem ("Green", Color);
|
||||||
|
Color2->setStatusbarMessage ("Set text green");
|
||||||
|
FRadioMenuItem* Color3 = new FRadioMenuItem ("Yellow", Color);
|
||||||
|
Color3->setStatusbarMessage ("Set text yellow");
|
||||||
|
FRadioMenuItem* Color4 = new FRadioMenuItem ("Brue", Color);
|
||||||
|
Color4->setStatusbarMessage ("Set text brue");
|
||||||
|
FRadioMenuItem* Color5 = new FRadioMenuItem ("Black", Color);
|
||||||
|
Color5->setStatusbarMessage ("Set text black");
|
||||||
|
Color5->setChecked();
|
||||||
|
|
||||||
|
// "Style" menu items
|
||||||
|
FCheckMenuItem* Bold = new FCheckMenuItem ("Bold", Style);
|
||||||
|
Bold->setStatusbarMessage ("Set text bold");
|
||||||
|
FCheckMenuItem* Italic = new FCheckMenuItem ("Italic", Style);
|
||||||
|
Italic->setStatusbarMessage ("Set text italic");
|
||||||
|
|
||||||
|
// "Border" menu items
|
||||||
|
FMenu* BColor = new FMenu ("&Color", Border);
|
||||||
|
BColor->setStatusbarMessage ("Choose the border color");
|
||||||
|
FMenu* BStyle = new FMenu ("&Style", Border);
|
||||||
|
BStyle->setStatusbarMessage ("Choose the border Style");
|
||||||
|
|
||||||
|
// "BColor" menu items
|
||||||
|
FRadioMenuItem* BColor1 = new FRadioMenuItem ("Red", BColor);
|
||||||
|
BColor1->setStatusbarMessage ("Set red border");
|
||||||
|
FRadioMenuItem* BColor2 = new FRadioMenuItem ("Blue", BColor);
|
||||||
|
BColor2->setStatusbarMessage ("Set blue border");
|
||||||
|
|
||||||
|
// "BStyle" menu items
|
||||||
|
FString line(13, wchar_t(fc::BoxDrawingsHorizontal));
|
||||||
|
FRadioMenuItem* BStyle1 = new FRadioMenuItem (line, BStyle);
|
||||||
|
BStyle1->setChecked();
|
||||||
|
BStyle1->setStatusbarMessage ("Set border 1");
|
||||||
|
FRadioMenuItem* BStyle2 = new FRadioMenuItem ("-------------", BStyle);
|
||||||
|
BStyle2->setStatusbarMessage ("Set border 2");
|
||||||
|
FRadioMenuItem* BStyle3 = new FRadioMenuItem ("- - - - - - -", BStyle);
|
||||||
|
BStyle3->setStatusbarMessage ("Set border 3");
|
||||||
|
FRadioMenuItem* BStyle4 = new FRadioMenuItem ("- - - - -", BStyle);
|
||||||
|
BStyle4->setStatusbarMessage ("Set border 4");
|
||||||
|
|
||||||
|
// Menu function callbacks
|
||||||
|
Open->addCallback
|
||||||
|
(
|
||||||
|
"clicked",
|
||||||
|
_METHOD_CALLBACK (this, &Menu::cb_message)
|
||||||
|
);
|
||||||
|
Quit->addCallback
|
||||||
|
(
|
||||||
|
"clicked",
|
||||||
|
_METHOD_CALLBACK (this, &Menu::cb_exitApp)
|
||||||
|
);
|
||||||
|
Undo->addCallback
|
||||||
|
(
|
||||||
|
"clicked",
|
||||||
|
_METHOD_CALLBACK (this, &Menu::cb_message)
|
||||||
|
);
|
||||||
|
Cut->addCallback
|
||||||
|
(
|
||||||
|
"clicked",
|
||||||
|
_METHOD_CALLBACK (this, &Menu::cb_message)
|
||||||
|
);
|
||||||
|
Copy->addCallback
|
||||||
|
(
|
||||||
|
"clicked",
|
||||||
|
_METHOD_CALLBACK (this, &Menu::cb_message)
|
||||||
|
);
|
||||||
|
Paste->addCallback
|
||||||
|
(
|
||||||
|
"clicked",
|
||||||
|
_METHOD_CALLBACK (this, &Menu::cb_message)
|
||||||
|
);
|
||||||
|
SelectAll->addCallback
|
||||||
|
(
|
||||||
|
"clicked",
|
||||||
|
_METHOD_CALLBACK (this, &Menu::cb_message)
|
||||||
|
);
|
||||||
|
Help->addCallback
|
||||||
|
(
|
||||||
|
"clicked",
|
||||||
|
_METHOD_CALLBACK (this, &Menu::cb_message)
|
||||||
|
);
|
||||||
|
|
||||||
|
// Statusbar at the bottom
|
||||||
|
FStatusBar* statusbar = new FStatusBar (this);
|
||||||
|
statusbar->setMessage("Status bar message");
|
||||||
|
|
||||||
|
// Headline labels
|
||||||
|
FLabel* Headline1 = new FLabel(" Key ", this);
|
||||||
|
Headline1->ignorePadding();
|
||||||
|
Headline1->setGeometry(3,2,5,1);
|
||||||
|
Headline1->setEmphasis();
|
||||||
|
|
||||||
|
FLabel* Headline2 = new FLabel(" Function ", this);
|
||||||
|
Headline2->ignorePadding();
|
||||||
|
Headline2->setGeometry(15,2,10,1);
|
||||||
|
Headline2->setEmphasis();
|
||||||
|
|
||||||
|
// Info label
|
||||||
|
FLabel* Info = new FLabel("<F10> Activate menu bar\n"
|
||||||
|
"<Meta>+<X> Exit", this);
|
||||||
|
Info->setGeometry(2,1,32,2);
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------
|
||||||
|
Menu::~Menu()
|
||||||
|
{ }
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------
|
||||||
|
void Menu::onClose (FCloseEvent* ev)
|
||||||
|
{
|
||||||
|
int ret = FMessageBox::info ( this, "Quit"
|
||||||
|
, "Do you really want\n"
|
||||||
|
"to quit the program ?"
|
||||||
|
, FMessageBox::Yes
|
||||||
|
, FMessageBox::No );
|
||||||
|
if ( ret == FMessageBox::Yes )
|
||||||
|
ev->accept();
|
||||||
|
else
|
||||||
|
ev->ignore();
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------
|
||||||
|
void Menu::cb_message (FWidget* widget, void*)
|
||||||
|
{
|
||||||
|
FButton* button = static_cast<FButton*>(widget);
|
||||||
|
FString text = button->getText();
|
||||||
|
text = text.replace('&', "");
|
||||||
|
FMessageBox::info (this, "Info", "You have chosen \"" + text + "\"");
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------
|
||||||
|
void Menu::cb_exitApp (FWidget*, void*)
|
||||||
|
{
|
||||||
|
close();
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------
|
||||||
|
void Menu::adjustSize()
|
||||||
|
{
|
||||||
|
int pw = parentWidget()->getWidth();
|
||||||
|
int ph = parentWidget()->getHeight();
|
||||||
|
setX (1 + (pw - getWidth()) / 2, false);
|
||||||
|
setY (1 + (ph - getHeight()) / 4, false);
|
||||||
|
FDialog::adjustSize();
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------
|
||||||
|
// main part
|
||||||
|
//----------------------------------------------------------------------
|
||||||
|
|
||||||
|
int main (int argc, char* argv[])
|
||||||
|
{
|
||||||
|
if ( argv[1] && ( strcmp(argv[1], "--help") == 0
|
||||||
|
|| strcmp(argv[1], "-h") == 0 ) )
|
||||||
|
{
|
||||||
|
std::cout << "Generic options:" << std::endl
|
||||||
|
<< " -h, --help "
|
||||||
|
<< "Display this help and exit" << std::endl;
|
||||||
|
FApplication::print_cmd_Options();
|
||||||
|
exit(EXIT_SUCCESS);
|
||||||
|
}
|
||||||
|
|
||||||
|
FApplication app (argc, argv);
|
||||||
|
|
||||||
|
Menu main_dlg (&app);
|
||||||
|
main_dlg.setText ("Menu example");
|
||||||
|
main_dlg.setGeometry (int(1+(app.getWidth()-36)/2), 2, 36, 5);
|
||||||
|
main_dlg.setShadow();
|
||||||
|
|
||||||
|
app.setMainWidget (&main_dlg);
|
||||||
|
main_dlg.show();
|
||||||
|
return app.exec();
|
||||||
|
}
|
26
test/ui.cpp
26
test/ui.cpp
|
@ -221,7 +221,7 @@ MyDialog::MyDialog (FWidget* parent)
|
||||||
FMenuItem* Open = new FMenuItem ("&Open...", File);
|
FMenuItem* Open = new FMenuItem ("&Open...", File);
|
||||||
Open->addAccelerator (fc::Fckey_o); // Ctrl + O
|
Open->addAccelerator (fc::Fckey_o); // Ctrl + O
|
||||||
Open->setStatusbarMessage ("Locate and open a text file");
|
Open->setStatusbarMessage ("Locate and open a text file");
|
||||||
FMenu* Recent = new FMenu ("System files", File);
|
FMenu* Recent = new FMenu ("&System files", File);
|
||||||
Recent->setStatusbarMessage ("View text file");
|
Recent->setStatusbarMessage ("View text file");
|
||||||
|
|
||||||
FMenuItem* Line1 = new FMenuItem (File);
|
FMenuItem* Line1 = new FMenuItem (File);
|
||||||
|
@ -315,17 +315,20 @@ MyDialog::MyDialog (FWidget* parent)
|
||||||
File1->addCallback
|
File1->addCallback
|
||||||
(
|
(
|
||||||
"clicked",
|
"clicked",
|
||||||
_METHOD_CALLBACK (this, &MyDialog::cb_view)
|
_METHOD_CALLBACK (this, &MyDialog::cb_view),
|
||||||
|
dynamic_cast<FWidget::data_ptr>(File1)
|
||||||
);
|
);
|
||||||
File2->addCallback
|
File2->addCallback
|
||||||
(
|
(
|
||||||
"clicked",
|
"clicked",
|
||||||
_METHOD_CALLBACK (this, &MyDialog::cb_view)
|
_METHOD_CALLBACK (this, &MyDialog::cb_view),
|
||||||
|
dynamic_cast<FWidget::data_ptr>(File2)
|
||||||
);
|
);
|
||||||
File3->addCallback
|
File3->addCallback
|
||||||
(
|
(
|
||||||
"clicked",
|
"clicked",
|
||||||
_METHOD_CALLBACK (this, &MyDialog::cb_view)
|
_METHOD_CALLBACK (this, &MyDialog::cb_view),
|
||||||
|
dynamic_cast<FWidget::data_ptr>(File3)
|
||||||
);
|
);
|
||||||
|
|
||||||
// Buttons
|
// Buttons
|
||||||
|
@ -635,7 +638,7 @@ void MyDialog::cb_drives (FWidget*, void*)
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
void MyDialog::cb_cutClipboard (FWidget*, void*)
|
void MyDialog::cb_cutClipboard (FWidget*, void*)
|
||||||
{
|
{
|
||||||
if ( ! myLineEdit )
|
if ( ! myLineEdit )
|
||||||
return;
|
return;
|
||||||
|
@ -645,7 +648,7 @@ void MyDialog::cb_cutClipboard (FWidget*, void*)
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
void MyDialog::cb_copyClipboard (FWidget*, void*)
|
void MyDialog::cb_copyClipboard (FWidget*, void*)
|
||||||
{
|
{
|
||||||
if ( ! myLineEdit )
|
if ( ! myLineEdit )
|
||||||
return;
|
return;
|
||||||
|
@ -653,7 +656,7 @@ void MyDialog::cb_copyClipboard (FWidget*, void*)
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
void MyDialog::cb_pasteClipboard (FWidget*, void*)
|
void MyDialog::cb_pasteClipboard (FWidget*, void*)
|
||||||
{
|
{
|
||||||
if ( ! myLineEdit )
|
if ( ! myLineEdit )
|
||||||
return;
|
return;
|
||||||
|
@ -662,7 +665,7 @@ void MyDialog::cb_pasteClipboard (FWidget*, void*)
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
void MyDialog::cb_clearInput (FWidget*, void*)
|
void MyDialog::cb_clearInput (FWidget*, void*)
|
||||||
{
|
{
|
||||||
if ( ! myLineEdit )
|
if ( ! myLineEdit )
|
||||||
return;
|
return;
|
||||||
|
@ -723,11 +726,12 @@ void MyDialog::cb_activateButton (FWidget* widget, void* data_ptr)
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
void MyDialog::cb_view (FWidget* widget, void*)
|
void MyDialog::cb_view (FWidget*, void* data_ptr)
|
||||||
{
|
{
|
||||||
FString file;
|
FString file;
|
||||||
FMenuItem* item = static_cast<FMenuItem*>(widget);
|
FMenuItem* item = static_cast<FMenuItem*>(data_ptr);
|
||||||
if ( item->getText() )
|
|
||||||
|
if ( item && item->getText() )
|
||||||
file = item->getText();
|
file = item->getText();
|
||||||
else
|
else
|
||||||
file = FFileDialog::fileOpenChooser (this);
|
file = FFileDialog::fileOpenChooser (this);
|
||||||
|
|
Loading…
Reference in New Issue