add classes FMenu

This commit is contained in:
Markus Gans 2015-08-16 20:05:39 +02:00
parent b94cbfa01a
commit adfcd29ee2
11 changed files with 666 additions and 107 deletions

View File

@ -23,6 +23,7 @@ libfinal_la_SOURCES = \
fswitch.cpp \ fswitch.cpp \
flabel.cpp \ flabel.cpp \
flistbox.cpp \ flistbox.cpp \
fmenu.cpp \
fmenubar.cpp \ fmenubar.cpp \
fmenuitem.cpp \ fmenuitem.cpp \
fmenulist.cpp \ fmenulist.cpp \
@ -59,6 +60,7 @@ finalcutinclude_HEADERS = \
flabel.h \ flabel.h \
flineedit.h \ flineedit.h \
flistbox.h \ flistbox.h \
fmenu.h \
fmenubar.h \ fmenubar.h \
fmenuitem.h \ fmenuitem.h \
fmenulist.h \ fmenulist.h \

View File

@ -130,10 +130,10 @@ libfinal_la_LIBADD =
am_libfinal_la_OBJECTS = fstring.lo fpoint.lo frect.lo fscrollbar.lo \ am_libfinal_la_OBJECTS = fstring.lo fpoint.lo frect.lo fscrollbar.lo \
fprogressbar.lo flineedit.lo fbutton.lo fbuttongroup.lo \ fprogressbar.lo flineedit.lo fbutton.lo fbuttongroup.lo \
ftogglebutton.lo fradiobutton.lo fcheckbox.lo fswitch.lo \ ftogglebutton.lo fradiobutton.lo fcheckbox.lo fswitch.lo \
flabel.lo flistbox.lo fmenubar.lo fmenuitem.lo fmenulist.lo \ flabel.lo flistbox.lo fmenu.lo fmenubar.lo fmenuitem.lo \
fdialog.lo fwindow.lo fmessagebox.lo ffiledialog.lo \ fmenulist.lo fdialog.lo fwindow.lo fmessagebox.lo \
ftextview.lo fstatusbar.lo fterm.lo fevent.lo foptimove.lo \ ffiledialog.lo ftextview.lo fstatusbar.lo fterm.lo fevent.lo \
fapp.lo fwidget.lo fobject.lo foptimove.lo fapp.lo fwidget.lo fobject.lo
libfinal_la_OBJECTS = $(am_libfinal_la_OBJECTS) libfinal_la_OBJECTS = $(am_libfinal_la_OBJECTS)
AM_V_lt = $(am__v_lt_@AM_V@) AM_V_lt = $(am__v_lt_@AM_V@)
am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@) am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@)
@ -385,6 +385,7 @@ libfinal_la_SOURCES = \
fswitch.cpp \ fswitch.cpp \
flabel.cpp \ flabel.cpp \
flistbox.cpp \ flistbox.cpp \
fmenu.cpp \
fmenubar.cpp \ fmenubar.cpp \
fmenuitem.cpp \ fmenuitem.cpp \
fmenulist.cpp \ fmenulist.cpp \
@ -419,6 +420,7 @@ finalcutinclude_HEADERS = \
flabel.h \ flabel.h \
flineedit.h \ flineedit.h \
flistbox.h \ flistbox.h \
fmenu.h \
fmenubar.h \ fmenubar.h \
fmenuitem.h \ fmenuitem.h \
fmenulist.h \ fmenulist.h \
@ -528,6 +530,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/flabel.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/flabel.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/flineedit.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/flineedit.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/flistbox.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/flistbox.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fmenu.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fmenubar.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fmenubar.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fmenuitem.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fmenuitem.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fmenulist.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fmenulist.Plo@am__quote@

View File

@ -19,6 +19,7 @@
#include "flistbox.h" #include "flistbox.h"
#include "ftextview.h" #include "ftextview.h"
#include "flineedit.h" #include "flineedit.h"
#include "fmenu.h"
#include "fmenubar.h" #include "fmenubar.h"
#include "fmenuitem.h" #include "fmenuitem.h"
#include "fstatusbar.h" #include "fstatusbar.h"

366
src/fmenu.cpp Normal file
View File

@ -0,0 +1,366 @@
// fmenu.cpp
// class FMenu
#include "fmenu.h"
//----------------------------------------------------------------------
// class FMenu
//----------------------------------------------------------------------
// constructor and destructor
//----------------------------------------------------------------------
FMenu::FMenu(FWidget* parent) : FWindow(parent)
{
item = 0;
this->init();
}
//----------------------------------------------------------------------
FMenu::FMenu (FString& txt, FWidget* parent) : FWindow(parent)
{
item = new FMenuItem(txt, parent);
this->init();
}
//----------------------------------------------------------------------
FMenu::FMenu (const std::string& txt, FWidget* parent) : FWindow(parent)
{
item = new FMenuItem(txt, parent);
this->init();
}
//----------------------------------------------------------------------
FMenu::FMenu (const char* txt, FWidget* parent) : FWindow(parent)
{
item = new FMenuItem(txt, parent);
this->init();
}
//----------------------------------------------------------------------
FMenu::~FMenu()
{
}
// private methods of FMenu
//----------------------------------------------------------------------
void FMenu::init()
{
item->setMenu(this);
setGeometry (1,1,1,1);
}
//----------------------------------------------------------------------
bool FMenu::isMenuBar (FWidget* w) const
{
return bool ( strcmp ( w->getClassName(),
const_cast<char*>("FMenuBar") ) == 0 );
}
//----------------------------------------------------------------------
FMenuList* FMenu::superMenu() const
{
return super_menu;
}
//----------------------------------------------------------------------
void FMenu::setSuperMenu (FMenuList* smenu)
{
super_menu = smenu;
}
//----------------------------------------------------------------------
int FMenu::getHotkeyPos (wchar_t*& src, wchar_t*& dest, uInt length)
{
// find hotkey position in string
// + generate a new string without the '&'-sign
int hotkeypos = -1;
wchar_t* txt = src;
for (uInt i=0; i < length; i++)
{
if ( (i < length) && (txt[i] == L'&') && (hotkeypos == -1) )
{
hotkeypos = int(i);
i++;
src++;
}
*dest++ = *src++;
}
return hotkeypos;
}
//----------------------------------------------------------------------
void FMenu::draw()
{
drawItems();
}
//----------------------------------------------------------------------
void FMenu::drawItems()
{
std::vector<FMenuItem*>::const_iterator iter, end;
int y = 1;
if ( itemlist.empty() )
return;
setUpdateVTerm(false);
iter = itemlist.begin();
end = itemlist.end();
while ( iter != end )
{
wchar_t* src;
wchar_t* dest;
wchar_t* item_text;
FString txt;
uInt txt_length;
int hotkeypos, to_char;
bool isActive = (*iter)->isActivated();
bool isSelected = (*iter)->isSelected();
bool isNoUnderline = (((*iter)->getFlags() & NO_UNDERLINE) != 0);
if ( isActive )
{
if ( isSelected )
{
foregroundColor = wc.menu_active_focus_fg;
backgroundColor = wc.menu_active_focus_bg;
if ( isMonochron() )
setReverse(false);
}
else
{
foregroundColor = wc.menu_active_fg;
backgroundColor = wc.menu_active_bg;
}
}
else
{
foregroundColor = wc.menu_inactive_fg;
backgroundColor = wc.menu_inactive_bg;
}
gotoxy (xpos+xmin+1, ypos+ymin+y);
setColor (foregroundColor, backgroundColor);
print (vmenubar, ' ');
txt = (*iter)->getText();
txt_length = int(txt.getLength());
item_text = new wchar_t[txt_length+1];
src = const_cast<wchar_t*>(txt.wc_str());
dest = const_cast<wchar_t*>(item_text);
to_char = int(txt_length);
hotkeypos = getHotkeyPos (src, dest, txt_length);
if ( hotkeypos != -1 )
{
txt_length--;
to_char--;
}
for (int z=0; z < to_char; z++)
{
if ( ! iswprint(wint_t(item_text[z])) )
item_text[z] = L' ';
if ( (z == hotkeypos) && isActive && ! isSelected )
{
setColor (wc.menu_hotkey_fg, wc.menu_hotkey_bg);
if ( ! isNoUnderline )
setUnderline();
print (vmenubar, item_text[z]);
if ( ! isNoUnderline )
unsetUnderline();
setColor (foregroundColor, backgroundColor);
}
else
print (vmenubar, item_text[z]);
}
if ( isActive && isSelected )
setReverse(false);
delete[] item_text;
++iter;
y++;
}
setUpdateVTerm(true);
}
//----------------------------------------------------------------------
void FMenu::processActivate()
{
emitCallback("activate");
}
// public methods of FMenu
//----------------------------------------------------------------------
void FMenu::onMouseDown (FMouseEvent* event)
{
if ( event->getButton() != LeftButton )
{
mouse_down = false;
if ( ! itemlist.empty() )
{
std::vector<FMenuItem*>::const_iterator iter, end;
iter = itemlist.begin();
end = itemlist.end();
while ( iter != end )
{
(*iter)->unsetSelected();
++iter;
}
}
this->redraw();
return;
}
if ( mouse_down )
return;
mouse_down = true;
if ( ! itemlist.empty() )
{
std::vector<FMenuItem*>::const_iterator iter, end;
int X = 1;
iter = itemlist.begin();
end = itemlist.end();
while ( iter != end )
{
int x1, x2, mouse_x, mouse_y, txt_length;
x1 = X;
txt_length = int((*iter)->getText().getLength());
x2 = x1 + txt_length + 1;
mouse_x = event->getX();
mouse_y = event->getY();
if ( mouse_x >= x1
&& mouse_x <= x2
&& mouse_y == 1
&& ! (*iter)->isSelected() )
{
(*iter)->setSelected();
this->redraw();
}
X = x2 + 2;
++iter;
}
}
}
//----------------------------------------------------------------------
void FMenu::onMouseUp (FMouseEvent* event)
{
if ( event->getButton() != LeftButton )
return;
if ( mouse_down )
{
mouse_down = false;
if ( ! itemlist.empty() )
{
std::vector<FMenuItem*>::const_iterator iter, end;
int X = 1;
iter = itemlist.begin();
end = itemlist.end();
while ( iter != end )
{
int x1 = X;
int txt_length = int((*iter)->getText().getLength());
int x2 = x1 + txt_length + 1;
if ( (*iter)->isSelected() )
{
int mouse_x = event->getX();
int mouse_y = event->getY();
if ( mouse_x < x1 || mouse_x > x2 || mouse_y != 1 )
(*iter)->unsetSelected();
this->redraw();
}
X = x2 + 2;
++iter;
}
}
}
}
//----------------------------------------------------------------------
void FMenu::onMouseMove (FMouseEvent* event)
{
if ( event->getButton() != LeftButton )
return;
if ( mouse_down && ! itemlist.empty() )
{
std::vector<FMenuItem*>::const_iterator iter, end;
bool focus_changed = false;
int X=1;
iter = itemlist.begin();
end = itemlist.end();
while ( iter != end )
{
int x1 = X;
int txt_length = int((*iter)->getText().getLength());
int x2 = x1 + txt_length + 1;
int mouse_x = event->getX();
int mouse_y = event->getY();
if ( mouse_x >= x1
&& mouse_x <= x2
&& mouse_y == 1 )
{
if ( ! (*iter)->isSelected() )
{
(*iter)->setSelected();
focus_changed = true;
}
}
else
{
if ( (*iter)->isSelected() )
{
(*iter)->unsetSelected();
focus_changed = true;
}
}
X = x2 + 2;
++iter;
}
if ( focus_changed )
this->redraw();
}
}
//----------------------------------------------------------------------
void FMenu::hide()
{
}
//----------------------------------------------------------------------
void FMenu::setGeometry (int xx, int yy, int ww, int hh, bool adjust)
{
int old_width = width;
int old_height = height;
FWidget::setGeometry (xx, yy, ww, hh, adjust);
if ( vmenubar && (width != old_width || height != old_height) )
resizeArea (vmenubar);
}
//----------------------------------------------------------------------
void FMenu::cb_menuitem_activated (FWidget* widget, void*)
{
FMenuItem* menuitem = static_cast<FMenuItem*>(widget);
if ( menuitem->hasMenu() )
{
beep();
}
}

137
src/fmenu.h Normal file
View File

@ -0,0 +1,137 @@
// fmenubar.h
// class FMenu
#ifndef _FMENU_H
#define _FMENU_H
#include "fwindow.h"
#include "fmenulist.h"
#include "fmenuitem.h"
//----------------------------------------------------------------------
// class FMenu
//----------------------------------------------------------------------
#pragma pack(push)
#pragma pack(1)
class FMenu : public FWindow, public FMenuList
{
private:
FMenuItem* item;
FMenuList* super_menu;
bool mouse_down;
private:
FMenu (const FMenu&);
FMenu& operator = (const FMenu&);
void init();
bool isMenuBar (FWidget*) const;
FMenuList* superMenu() const;
void setSuperMenu (FMenuList*);
int getHotkeyPos (wchar_t*&, wchar_t*&, uInt);
void draw();
void drawItems();
void processActivate();
public:
explicit FMenu (FWidget* parent=0); // constructor
FMenu (FString&, FWidget* parent=0);
FMenu (const std::string&, FWidget* parent=0);
FMenu (const char*, FWidget* parent=0);
virtual ~FMenu(); // destructor
virtual const char* getClassName() const;
void onMouseDown (FMouseEvent*);
void onMouseUp (FMouseEvent*);
void onMouseMove (FMouseEvent*);
void hide();
void setGeometry (int, int, int, int, bool adjust=true);
FMenuItem* getItem() const;
void onAccel (FAccelEvent*);
FString getText() const;
void setActive();
void unsetActive();
bool isActivated() const;
void setSelected();
void unsetSelected();
bool isSelected() const;
bool hasHotkey() const;
void setMenu (FMenu*);
bool hasMenu() const;
void setText (FString&);
void setText (const std::string&);
void setText (const char*);
void cb_menuitem_activated (FWidget*, void*);
};
#pragma pack(pop)
// FMenu inline functions
//----------------------------------------------------------------------
inline const char* FMenu::getClassName() const
{ return "FMenu"; }
//----------------------------------------------------------------------
inline void FMenu::onAccel (FAccelEvent* event)
{ item->onAccel(event); }
//----------------------------------------------------------------------
inline FMenuItem* FMenu::getItem() const
{ return item; }
//----------------------------------------------------------------------
inline FString FMenu::getText() const
{ return item->getText(); }
//----------------------------------------------------------------------
inline void FMenu::setActive()
{ item->setActive(); }
//----------------------------------------------------------------------
inline void FMenu::unsetActive()
{ item->unsetActive(); }
//----------------------------------------------------------------------
inline bool FMenu::isActivated() const
{ return item->isActivated(); }
//----------------------------------------------------------------------
inline void FMenu::setSelected()
{ item->setSelected(); }
//----------------------------------------------------------------------
inline void FMenu::unsetSelected()
{ item->unsetSelected(); }
//----------------------------------------------------------------------
inline bool FMenu::isSelected() const
{ return item->isSelected(); }
//----------------------------------------------------------------------
inline bool FMenu::hasHotkey() const
{ return item->hasHotkey(); }
//----------------------------------------------------------------------
inline void FMenu::setMenu (FMenu* m)
{ item->setMenu(m); }
//----------------------------------------------------------------------
inline bool FMenu::hasMenu() const
{ return item->hasMenu(); }
//----------------------------------------------------------------------
inline void FMenu::setText (FString& txt)
{ item->setText(txt); }
//----------------------------------------------------------------------
inline void FMenu::setText (const std::string& txt)
{ item->setText(txt); }
//----------------------------------------------------------------------
inline void FMenu::setText (const char* txt)
{ item->setText(txt); }
#endif // _FMENU_H

View File

@ -50,6 +50,12 @@ void FMenuBar::init()
unsetFocusable(); unsetFocusable();
} }
//----------------------------------------------------------------------
bool FMenuBar::isMenu (FMenuItem* mi) const
{
return mi->hasMenu();
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
int FMenuBar::getHotkeyPos (wchar_t*& src, wchar_t*& dest, uInt length) int FMenuBar::getHotkeyPos (wchar_t*& src, wchar_t*& dest, uInt length)
{ {
@ -83,6 +89,9 @@ void FMenuBar::draw()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FMenuBar::drawItems() void FMenuBar::drawItems()
{ {
bool isActive;
bool isSelected;
bool isNoUnderline;
std::vector<FMenuItem*>::const_iterator iter, end; std::vector<FMenuItem*>::const_iterator iter, end;
int screenWidth; int screenWidth;
@ -108,9 +117,10 @@ void FMenuBar::drawItems()
FString txt; FString txt;
uInt txt_length; uInt txt_length;
int hotkeypos, to_char; int hotkeypos, to_char;
bool isActive = (*iter)->isActivated();
bool isSelected = (*iter)->isSelected(); isActive = (*iter)->isActivated();
bool isNoUnderline = (((*iter)->getFlags() & NO_UNDERLINE) != 0); isSelected = (*iter)->isSelected();
isNoUnderline = (((*iter)->getFlags() & NO_UNDERLINE) != 0);
if ( isActive ) if ( isActive )
{ {
@ -255,7 +265,9 @@ void FMenuBar::onMouseDown (FMouseEvent* event)
x1 = X; x1 = X;
txt_length = int((*iter)->getText().getLength()); txt_length = int((*iter)->getText().getLength());
x2 = x1 + txt_length + 1; if ( (*iter)->hasHotkey() )
txt_length--;
x2 = x1 + txt_length;
mouse_x = event->getX(); mouse_x = event->getX();
mouse_y = event->getY(); mouse_y = event->getY();
@ -267,7 +279,12 @@ void FMenuBar::onMouseDown (FMouseEvent* event)
(*iter)->setSelected(); (*iter)->setSelected();
this->redraw(); this->redraw();
} }
X = x2 + 2; else
{
(*iter)->unsetSelected();
this->redraw();
}
X = x2 + 1;
++iter; ++iter;
} }
} }
@ -294,7 +311,9 @@ void FMenuBar::onMouseUp (FMouseEvent* event)
{ {
int x1 = X; int x1 = X;
int txt_length = int((*iter)->getText().getLength()); int txt_length = int((*iter)->getText().getLength());
int x2 = x1 + txt_length + 1; if ( (*iter)->hasHotkey() )
txt_length--;
int x2 = x1 + txt_length;
if ( (*iter)->isSelected() ) if ( (*iter)->isSelected() )
{ {
@ -304,7 +323,7 @@ void FMenuBar::onMouseUp (FMouseEvent* event)
(*iter)->unsetSelected(); (*iter)->unsetSelected();
this->redraw(); this->redraw();
} }
X = x2 + 2; X = x2 + 1;
++iter; ++iter;
} }
} }
@ -330,7 +349,9 @@ void FMenuBar::onMouseMove (FMouseEvent* event)
{ {
int x1 = X; int x1 = X;
int txt_length = int((*iter)->getText().getLength()); int txt_length = int((*iter)->getText().getLength());
int x2 = x1 + txt_length + 1; if ( (*iter)->hasHotkey() )
txt_length--;
int x2 = x1 + txt_length;
int mouse_x = event->getX(); int mouse_x = event->getX();
int mouse_y = event->getY(); int mouse_y = event->getY();
@ -352,7 +373,7 @@ void FMenuBar::onMouseMove (FMouseEvent* event)
focus_changed = true; focus_changed = true;
} }
} }
X = x2 + 2; X = x2 + 1;
++iter; ++iter;
} }
if ( focus_changed ) if ( focus_changed )
@ -393,27 +414,12 @@ void FMenuBar::setGeometry (int xx, int yy, int ww, int hh, bool adjust)
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
/* void FMenuBar::cb_item_activated (FWidget* widget, void*)
void FMenuBar::cb_menuitem_activated (FWidget* widget, void*)
{ {
if ( ! itemlist.empty() )
{
std::vector<FMenuItem*>::const_iterator iter, end;
FMenuItem* menuitem = static_cast<FMenuItem*>(widget); FMenuItem* menuitem = static_cast<FMenuItem*>(widget);
iter = itemlist.begin(); if ( menuitem->hasMenu() )
end = itemlist.end();
while ( iter != end )
{ {
if ( (*iter) != menuitem && (*iter)->isSelected() ) beep();
(*iter)->unsetSelected();
++iter;
} }
} }
if ( isVisible() && isShown() )
redraw();
if ( ! isHiddenCursor() )
hideCursor();
}
*/

View File

@ -24,6 +24,7 @@ class FMenuBar : public FWindow, public FMenuList
FMenuBar (const FMenuBar&); FMenuBar (const FMenuBar&);
FMenuBar& operator = (const FMenuBar&); FMenuBar& operator = (const FMenuBar&);
void init(); void init();
bool isMenu (FMenuItem*) const;
int getHotkeyPos (wchar_t*&, wchar_t*&, uInt); int getHotkeyPos (wchar_t*&, wchar_t*&, uInt);
void draw(); void draw();
void drawItems(); void drawItems();
@ -40,8 +41,7 @@ class FMenuBar : public FWindow, public FMenuList
void onMouseMove (FMouseEvent*); void onMouseMove (FMouseEvent*);
void hide(); void hide();
void setGeometry (int, int, int, int, bool adjust=true); void setGeometry (int, int, int, int, bool adjust=true);
void cb_item_activated (FWidget*, void*);
//void cb_menuitem_activated (FWidget*, void*);
}; };
#pragma pack(pop) #pragma pack(pop)

View File

@ -1,6 +1,7 @@
// fmenuitem.cpp // fmenuitem.cpp
// class FMenuItem // class FMenuItem
#include "fmenubar.h"
#include "fmenuitem.h" #include "fmenuitem.h"
#include "fmenulist.h" #include "fmenulist.h"
@ -16,7 +17,7 @@ FMenuItem::FMenuItem (FWidget* parent) : FWidget(parent)
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FMenuItem::FMenuItem (FString& txt, FWidget* parent) FMenuItem::FMenuItem (FString& txt, FWidget* parent) : FWidget(parent)
{ {
setText(txt); setText(txt);
init (parent); init (parent);
@ -50,16 +51,43 @@ void FMenuItem::init (FWidget* parent)
selected = false; selected = false;
separator = false; separator = false;
checked = false; checked = false;
//menu = 0 hotkey = 0;
menu = 0;
setGeometry (1,1,1,1); setGeometry (1,1,1,1);
if ( parent && isMenuBar(parent) ) if ( parent && isMenuBar(parent) )
{ {
setSuperMenu( dynamic_cast<FMenuList*>(parent) ); setSuperMenu( dynamic_cast<FMenuList*>(parent) );
superMenu()->insert(this); superMenu()->insert(this);
//addAccelerator (item->getKey(), item);
this->addCallback
(
"activate",
(FWidget*)superMenu(),
reinterpret_cast<FWidget::FMemberCallback>(&FMenuBar::cb_item_activated),
null
);
} }
} }
//----------------------------------------------------------------------
uChar FMenuItem::getHotkey()
{
uInt length;
if ( text.isEmpty() )
return 0;
length = text.getLength();
for (uInt i=0; i < length; i++)
if ( (i+1 < length) && (text[i] == '&') )
return uChar(text[++i]);
return 0;
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
bool FMenuItem::isMenuBar (FWidget* w) const bool FMenuItem::isMenuBar (FWidget* w) const
{ {
@ -67,11 +95,24 @@ bool FMenuItem::isMenuBar (FWidget* w) const
const_cast<char*>("FMenuBar") ) == 0 ); const_cast<char*>("FMenuBar") ) == 0 );
} }
//----------------------------------------------------------------------
FMenuList* FMenuItem::superMenu() const
{
return super_menu;
}
//----------------------------------------------------------------------
void FMenuItem::setSuperMenu (FMenuList* smenu)
{
super_menu = smenu;
}
// protected methods of FMenuItem // protected methods of FMenuItem
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FMenuItem::processActivate() void FMenuItem::processActivate()
{ {
emitCallback("activate");
} }
// public methods of FMenuItem // public methods of FMenuItem
@ -89,20 +130,29 @@ void FMenuItem::onAccel (FAccelEvent* event)
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FMenuList* FMenuItem::superMenu() const void FMenuItem::setSelected()
{ {
return super_menu; this->selected = true;
}
//----------------------------------------------------------------------
void FMenuItem::setSuperMenu (FMenuList* smenu)
{
super_menu = smenu;
}
//----------------------------------------------------------------------
inline void FMenuItem::setActive()
{
this->active = true;
processActivate(); processActivate();
} }
//----------------------------------------------------------------------
inline void FMenuItem::setText (FString& txt)
{
this->text = txt;
this->hotkey = getHotkey();
}
//----------------------------------------------------------------------
inline void FMenuItem::setText (const std::string& txt)
{
this->text = txt;
this->hotkey = getHotkey();
}
//----------------------------------------------------------------------
inline void FMenuItem::setText (const char* txt)
{
this->text = txt;
this->hotkey = getHotkey();
}

View File

@ -6,6 +6,7 @@
#include "fwidget.h" #include "fwidget.h"
class FMenu;
class FMenuList; class FMenuList;
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -23,20 +24,20 @@ class FMenuItem : public FWidget
bool selected; bool selected;
bool separator; bool separator;
bool checked; bool checked;
int hotkey;
//int accel_key; //int accel_key;
//FPopupMenu* menu; FMenu* menu;
FMenuList* super_menu; FMenuList* super_menu;
private: private:
FMenuItem (const FMenuItem&); FMenuItem (const FMenuItem&);
FMenuItem& operator = (const FMenuItem&); FMenuItem& operator = (const FMenuItem&);
void init (FWidget*); void init (FWidget*);
uChar getHotkey();
bool isMenuBar (FWidget*) const; bool isMenuBar (FWidget*) const;
FMenuList* superMenu() const; FMenuList* superMenu() const;
void setSuperMenu (FMenuList*); void setSuperMenu (FMenuList*);
void processActivate();
protected:
virtual void processActivate();
public: public:
explicit FMenuItem (FWidget* parent=0); explicit FMenuItem (FWidget* parent=0);
@ -59,9 +60,9 @@ class FMenuItem : public FWidget
void setChecked(); void setChecked();
void unsetChecked(); void unsetChecked();
bool isChecked() const; bool isChecked() const;
bool hasHotkey() const;
void setMenu(FMenu*);
bool hasMenu() const; bool hasMenu() const;
protected:
void setText (FString&); void setText (FString&);
void setText (const std::string&); void setText (const std::string&);
void setText (const char*); void setText (const char*);
@ -77,6 +78,10 @@ class FMenuItem : public FWidget
inline FString FMenuItem::getText() const inline FString FMenuItem::getText() const
{ return this->text; } { return this->text; }
//----------------------------------------------------------------------
inline void FMenuItem::setActive()
{ this->active = true; }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline void FMenuItem::unsetActive() inline void FMenuItem::unsetActive()
{ this->active = false; } { this->active = false; }
@ -85,10 +90,6 @@ inline void FMenuItem::unsetActive()
inline bool FMenuItem::isActivated() const inline bool FMenuItem::isActivated() const
{ return active; } { return active; }
//----------------------------------------------------------------------
inline void FMenuItem::setSelected()
{ this->selected = true; }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline void FMenuItem::unsetSelected() inline void FMenuItem::unsetSelected()
{ this->selected = false; } { this->selected = false; }
@ -122,20 +123,16 @@ inline bool FMenuItem::isChecked() const
{ return checked; } { return checked; }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
//inline bool FMenuItem::hasMenu() const; inline bool FMenuItem::hasHotkey() const
//{ return bool(menu != 0); } { return bool(hotkey != 0); }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline void FMenuItem::setText (FString& txt) inline void FMenuItem::setMenu(FMenu* m)
{ this->text = txt; } { menu = m; }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline void FMenuItem::setText (const std::string& txt) inline bool FMenuItem::hasMenu() const
{ this->text = txt; } { return bool(menu != 0); }
//----------------------------------------------------------------------
inline void FMenuItem::setText (const char* txt)
{ this->text = txt; }
#endif // _FMENUITEM_H #endif // _FMENUITEM_H

View File

@ -58,28 +58,17 @@ bool FMenuList::hasSelectedItem()
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FMenuList::insert (FMenuItem* obj) void FMenuList::insert (FMenuItem* item)
{ {
itemlist.push_back(obj); itemlist.push_back(item);
//addAccelerator (obj->getKey(), obj);
/*
obj->addCallback
(
"activate",
this,
reinterpret_cast<FWidget::FMemberCallback>(&FMenuBar::cb_statuskey_activated),
null
);
*/
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FMenuList::remove (FMenuItem* obj) void FMenuList::remove (FMenuItem* item)
{ {
std::vector<FMenuItem*>::iterator iter; std::vector<FMenuItem*>::iterator iter;
//delAccelerator (obj); //delAccelerator (item);
if ( itemlist.empty() ) if ( itemlist.empty() )
return; return;
@ -87,10 +76,10 @@ void FMenuList::remove (FMenuItem* obj)
iter = itemlist.begin(); iter = itemlist.begin();
while ( iter != itemlist.end() ) while ( iter != itemlist.end() )
{ {
if ( (*iter) == obj ) if ( (*iter) == item )
{ {
iter = itemlist.erase(iter); iter = itemlist.erase(iter);
obj->setSuperMenu(0); item->setSuperMenu(0);
break; break;
} }
else else
@ -112,3 +101,10 @@ void FMenuList::clear()
{ {
itemlist.clear(); itemlist.clear();
} }
// protected methods of FMenuList
//----------------------------------------------------------------------
/*void FMenuList::cb_item_activated (FWidget*, void*)
{
}*/

View File

@ -4,8 +4,8 @@
#ifndef _FMENULIST_H #ifndef _FMENULIST_H
#define _FMENULIST_H #define _FMENULIST_H
#include "fwidget.h"
#include "fmenuitem.h" #include "fmenuitem.h"
#include "fwidget.h"
/* /*
@ -13,12 +13,13 @@
FMenuList ------- FMenuItem FMenuList ------- FMenuItem
FWidget FPopupMenu FWidget FMenu
*/ */
//---------------------------------------------------------------------- //----------------------------------------------------------------------
// class FMenuList // class FMenuList
//---------------------------------------------------------------------- //----------------------------------------------------------------------