Optimize menu example
This commit is contained in:
parent
6074c78516
commit
9cc95d952b
|
@ -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>
|
||||
* Avoid to show menus outside of the screen
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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
|
||||
//----------------------------------------------------------------------
|
||||
|
|
27
test/ui.cpp
27
test/ui.cpp
|
@ -5,6 +5,7 @@
|
|||
|
||||
#include "final.h"
|
||||
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// class ProgressDialog
|
||||
//----------------------------------------------------------------------
|
||||
|
@ -15,34 +16,34 @@
|
|||
class ProgressDialog : public FDialog
|
||||
{
|
||||
private:
|
||||
ProgressDialog (const ProgressDialog&); // Disabled copy constructor
|
||||
ProgressDialog& operator = (const ProgressDialog&); // and operator '='
|
||||
|
||||
public:
|
||||
FProgressbar* progressBar;
|
||||
FButton* reset;
|
||||
FButton* more;
|
||||
FButton* quit;
|
||||
FProgressbar* progressBar;
|
||||
|
||||
public:
|
||||
explicit ProgressDialog (FWidget* = 0); // constructor
|
||||
~ProgressDialog(); // destructor
|
||||
private:
|
||||
ProgressDialog (const ProgressDialog&); // Disabled copy constructor
|
||||
ProgressDialog& operator = (const ProgressDialog&); // and operator '='
|
||||
|
||||
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");
|
||||
|
@ -168,9 +169,6 @@ class MyDialog : public FDialog
|
|||
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)
|
||||
|
||||
|
|
Loading…
Reference in New Issue