Optimize menu example

This commit is contained in:
Markus Gans 2015-12-18 21:48:27 +01:00
parent 6074c78516
commit 9cc95d952b
5 changed files with 73 additions and 61 deletions

View File

@ -1,3 +1,7 @@
2015-12-18 Markus Gans <guru.mail@muenster.de>
* Optimize menu example
* More string types for FString relational operators
2015-12-16 Markus Gans <guru.mail@muenster.de> 2015-12-16 Markus Gans <guru.mail@muenster.de>
* Avoid to show menus outside of the screen * Avoid to show menus outside of the screen

View File

@ -74,8 +74,8 @@ inline uInt FMenuList::count() const
{ return uInt(itemlist.size()); } { return uInt(itemlist.size()); }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline FMenuItem* FMenuList::item(int index) const inline FMenuItem* FMenuList::item (int index) const
{ return itemlist[uInt(index-1)]; } { return (index > 0) ? itemlist[uInt(index-1)] : 0; }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline void FMenuList::enableItem (int index) inline void FMenuList::enableItem (int index)
@ -87,7 +87,7 @@ inline void FMenuList::disableItem (int index)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline bool FMenuList::isSelected(int index) const 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 inline FMenuItem* FMenuList::getSelectedItem() const

View File

@ -4261,7 +4261,7 @@ int FTerm::putchar_PC (register int c)
if ( uChar(ch) < 0x20 ) // Character 0x00..0x1f if ( uChar(ch) < 0x20 ) // Character 0x00..0x1f
{ {
Encoding = fc::ASCII; Encoding = fc::ASCII;
ch = uChar(charEncode(uInt(c))); ch = char(charEncode(uInt(c)));
Encoding = fc::PC; Encoding = fc::PC;
ret = putchar(ch); ret = putchar(ch);
} }

View File

@ -1,6 +1,15 @@
// File: menu.cpp // 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 // class Menu
@ -14,13 +23,15 @@ class Menu : public FDialog
private: private:
Menu (const Menu&); // Disabled copy constructor Menu (const Menu&); // Disabled copy constructor
Menu& operator = (const Menu&); // and operator '=' Menu& operator = (const Menu&); // and operator '='
void defaultCallback (FMenuList*);
void onClose (FCloseEvent*);
void cb_message (FWidget*, void*);
void cb_exitApp (FWidget*, void*);
public: public:
explicit Menu (FWidget* = 0); // constructor explicit Menu (FWidget* = 0); // constructor
~Menu(); // destructor ~Menu(); // destructor
void onClose (FCloseEvent*);
void cb_message (FWidget*, void*);
void cb_exitApp (FWidget*, void*);
protected: protected:
void adjustSize(); void adjustSize();
}; };
@ -146,48 +157,15 @@ Menu::Menu (FWidget* parent)
FRadioMenuItem* BStyle4 = new FRadioMenuItem ("- - - - -", BStyle); FRadioMenuItem* BStyle4 = new FRadioMenuItem ("- - - - -", BStyle);
BStyle4->setStatusbarMessage ("Set border 4"); BStyle4->setStatusbarMessage ("Set border 4");
// Menu function callbacks // Add default menu item callback
Open->addCallback defaultCallback (Menubar);
(
"clicked",
_METHOD_CALLBACK (this, &Menu::cb_message)
);
// Add quit menu item callback
Quit->addCallback Quit->addCallback
( (
"clicked", "clicked",
_METHOD_CALLBACK (this, &Menu::cb_exitApp) _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 // Statusbar at the bottom
FStatusBar* statusbar = new FStatusBar (this); FStatusBar* statusbar = new FStatusBar (this);
@ -214,6 +192,34 @@ Menu::Menu (FWidget* parent)
Menu::~Menu() 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) void Menu::onClose (FCloseEvent* ev)
{ {
@ -253,6 +259,7 @@ void Menu::adjustSize()
FDialog::adjustSize(); FDialog::adjustSize();
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
// main part // main part
//---------------------------------------------------------------------- //----------------------------------------------------------------------

View File

@ -5,6 +5,7 @@
#include "final.h" #include "final.h"
//---------------------------------------------------------------------- //----------------------------------------------------------------------
// class ProgressDialog // class ProgressDialog
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -14,35 +15,35 @@
class ProgressDialog : public FDialog class ProgressDialog : public FDialog
{ {
private:
FProgressbar* progressBar;
FButton* reset;
FButton* more;
FButton* quit;
private: private:
ProgressDialog (const ProgressDialog&); // Disabled copy constructor ProgressDialog (const ProgressDialog&); // Disabled copy constructor
ProgressDialog& operator = (const ProgressDialog&); // and operator '=' 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 onShow (FShowEvent*);
void onTimer (FTimerEvent*); void onTimer (FTimerEvent*);
void cb_reset_bar (FWidget*, void*); void cb_reset_bar (FWidget*, void*);
void cb_more_bar (FWidget*, void*); void cb_more_bar (FWidget*, void*);
void cb_exit_bar (FWidget*, void*); void cb_exit_bar (FWidget*, void*);
public:
explicit ProgressDialog (FWidget* = 0); // constructor
~ProgressDialog(); // destructor
}; };
#pragma pack(pop) #pragma pack(pop)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
ProgressDialog::ProgressDialog (FWidget* parent) ProgressDialog::ProgressDialog (FWidget* parent)
: FDialog(parent) : FDialog(parent)
, progressBar()
, reset() , reset()
, more() , more()
, quit() , quit()
, progressBar()
{ {
setGeometry (int((this->parentWidget()->getWidth()-40)/2), 7, 40, 10); setGeometry (int((this->parentWidget()->getWidth()-40)/2), 7, 40, 10);
setText("Progress bar"); setText("Progress bar");
@ -161,16 +162,13 @@ class MyDialog : public FDialog
{ {
private: private:
FLineEdit* myLineEdit; FLineEdit* myLineEdit;
FListBox* myList; FListBox* myList;
FString clipboard; FString clipboard;
private: private:
MyDialog (const MyDialog&); // Disabled copy constructor MyDialog (const MyDialog&); // Disabled copy constructor
MyDialog& operator = (const MyDialog&); // and operator '=' MyDialog& operator = (const MyDialog&); // and operator '='
public:
explicit MyDialog (FWidget* = 0); // constructor
~MyDialog(); // destructor
void onClose (FCloseEvent*); void onClose (FCloseEvent*);
void cb_noFunctionMsg (FWidget*, void*); void cb_noFunctionMsg (FWidget*, void*);
void cb_about (FWidget*, void*); void cb_about (FWidget*, void*);
@ -188,8 +186,11 @@ class MyDialog : public FDialog
void cb_view (FWidget*, void*); void cb_view (FWidget*, void*);
void cb_setInput (FWidget*, void*); void cb_setInput (FWidget*, void*);
void cb_exitApp (FWidget*, void*); void cb_exitApp (FWidget*, void*);
protected:
void adjustSize(); void adjustSize();
public:
explicit MyDialog (FWidget* = 0); // constructor
~MyDialog(); // destructor
}; };
#pragma pack(pop) #pragma pack(pop)