diff --git a/ChangeLog b/ChangeLog index d6d2d66e..1d3a5642 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2015-12-18 Markus Gans + * Optimize menu example + * More string types for FString relational operators + 2015-12-16 Markus Gans * Avoid to show menus outside of the screen diff --git a/src/fmenulist.h b/src/fmenulist.h index dcc0f4b6..c7621ccf 100644 --- a/src/fmenulist.h +++ b/src/fmenulist.h @@ -74,8 +74,8 @@ inline uInt FMenuList::count() const { return uInt(itemlist.size()); } //---------------------------------------------------------------------- -inline FMenuItem* FMenuList::item(int index) const -{ return itemlist[uInt(index-1)]; } +inline FMenuItem* FMenuList::item (int index) const +{ return (index > 0) ? itemlist[uInt(index-1)] : 0; } //---------------------------------------------------------------------- inline void FMenuList::enableItem (int index) @@ -87,7 +87,7 @@ inline void FMenuList::disableItem (int index) //---------------------------------------------------------------------- inline bool FMenuList::isSelected(int index) const -{ return itemlist[uInt(index-1)]->isSelected(); } +{ return (index > 0) ? itemlist[uInt(index-1)]->isSelected() : false; } //---------------------------------------------------------------------- inline FMenuItem* FMenuList::getSelectedItem() const diff --git a/src/fterm.cpp b/src/fterm.cpp index 60380c84..5d231a1f 100644 --- a/src/fterm.cpp +++ b/src/fterm.cpp @@ -4261,7 +4261,7 @@ int FTerm::putchar_PC (register int c) if ( uChar(ch) < 0x20 ) // Character 0x00..0x1f { Encoding = fc::ASCII; - ch = uChar(charEncode(uInt(c))); + ch = char(charEncode(uInt(c))); Encoding = fc::PC; ret = putchar(ch); } diff --git a/test/menu.cpp b/test/menu.cpp index 272ed72b..f8ce0877 100644 --- a/test/menu.cpp +++ b/test/menu.cpp @@ -1,6 +1,15 @@ // File: menu.cpp -#include "final.h" +#include "fapp.h" +#include "fcheckmenuitem.h" +#include "fdialog.h" +#include "flabel.h" +#include "fmenubar.h" +#include "fmenu.h" +#include "fmessagebox.h" +#include "fradiomenuitem.h" +#include "fstatusbar.h" + //---------------------------------------------------------------------- // class Menu @@ -14,13 +23,15 @@ class Menu : public FDialog private: Menu (const Menu&); // Disabled copy constructor Menu& operator = (const Menu&); // and operator '=' + void defaultCallback (FMenuList*); + void onClose (FCloseEvent*); + void cb_message (FWidget*, void*); + void cb_exitApp (FWidget*, void*); public: explicit Menu (FWidget* = 0); // constructor ~Menu(); // destructor - void onClose (FCloseEvent*); - void cb_message (FWidget*, void*); - void cb_exitApp (FWidget*, void*); + protected: void adjustSize(); }; @@ -146,48 +157,15 @@ Menu::Menu (FWidget* parent) FRadioMenuItem* BStyle4 = new FRadioMenuItem ("- - - - -", BStyle); BStyle4->setStatusbarMessage ("Set border 4"); - // Menu function callbacks - Open->addCallback - ( - "clicked", - _METHOD_CALLBACK (this, &Menu::cb_message) - ); + // Add default menu item callback + defaultCallback (Menubar); + // Add quit menu item callback 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); @@ -214,6 +192,34 @@ Menu::Menu (FWidget* parent) Menu::~Menu() { } +//---------------------------------------------------------------------- +void Menu::defaultCallback (FMenuList* mb) +{ + for (uInt i=1; i <= mb->count(); i++) + { + FMenuItem* item = mb->item(i); + + if ( item + && item->isEnabled() + && item->acceptFocus() + && item->isVisible() + && ! item->isSeparator() + && item->getText() != "&Quit" ) + { + // Add the callback function + item->addCallback + ( + "clicked", + _METHOD_CALLBACK (this, &Menu::cb_message) + ); + + // Call sub-menu + if ( item->hasMenu() ) + defaultCallback (item->getMenu()); + } + } +} + //---------------------------------------------------------------------- void Menu::onClose (FCloseEvent* ev) { @@ -253,6 +259,7 @@ void Menu::adjustSize() FDialog::adjustSize(); } + //---------------------------------------------------------------------- // main part //---------------------------------------------------------------------- diff --git a/test/ui.cpp b/test/ui.cpp index b29a6d12..9842810d 100644 --- a/test/ui.cpp +++ b/test/ui.cpp @@ -5,6 +5,7 @@ #include "final.h" + //---------------------------------------------------------------------- // class ProgressDialog //---------------------------------------------------------------------- @@ -14,35 +15,35 @@ class ProgressDialog : public FDialog { + private: + FProgressbar* progressBar; + FButton* reset; + FButton* more; + FButton* quit; + private: ProgressDialog (const ProgressDialog&); // Disabled copy constructor ProgressDialog& operator = (const ProgressDialog&); // and operator '=' - public: - FButton* reset; - FButton* more; - FButton* quit; - FProgressbar* progressBar; - - public: - explicit ProgressDialog (FWidget* = 0); // constructor - ~ProgressDialog(); // destructor - void onShow (FShowEvent*); void onTimer (FTimerEvent*); void cb_reset_bar (FWidget*, void*); void cb_more_bar (FWidget*, void*); void cb_exit_bar (FWidget*, void*); + + public: + explicit ProgressDialog (FWidget* = 0); // constructor + ~ProgressDialog(); // destructor }; #pragma pack(pop) //---------------------------------------------------------------------- ProgressDialog::ProgressDialog (FWidget* parent) : FDialog(parent) + , progressBar() , reset() , more() , quit() - , progressBar() { setGeometry (int((this->parentWidget()->getWidth()-40)/2), 7, 40, 10); setText("Progress bar"); @@ -161,16 +162,13 @@ class MyDialog : public FDialog { private: FLineEdit* myLineEdit; - FListBox* myList; - FString clipboard; + FListBox* myList; + FString clipboard; private: MyDialog (const MyDialog&); // Disabled copy constructor MyDialog& operator = (const MyDialog&); // and operator '=' - public: - explicit MyDialog (FWidget* = 0); // constructor - ~MyDialog(); // destructor void onClose (FCloseEvent*); void cb_noFunctionMsg (FWidget*, void*); void cb_about (FWidget*, void*); @@ -188,8 +186,11 @@ class MyDialog : public FDialog void cb_view (FWidget*, void*); void cb_setInput (FWidget*, void*); void cb_exitApp (FWidget*, void*); - protected: void adjustSize(); + + public: + explicit MyDialog (FWidget* = 0); // constructor + ~MyDialog(); // destructor }; #pragma pack(pop)