add classes FMenu
This commit is contained in:
parent
b94cbfa01a
commit
adfcd29ee2
|
@ -23,6 +23,7 @@ libfinal_la_SOURCES = \
|
|||
fswitch.cpp \
|
||||
flabel.cpp \
|
||||
flistbox.cpp \
|
||||
fmenu.cpp \
|
||||
fmenubar.cpp \
|
||||
fmenuitem.cpp \
|
||||
fmenulist.cpp \
|
||||
|
@ -59,6 +60,7 @@ finalcutinclude_HEADERS = \
|
|||
flabel.h \
|
||||
flineedit.h \
|
||||
flistbox.h \
|
||||
fmenu.h \
|
||||
fmenubar.h \
|
||||
fmenuitem.h \
|
||||
fmenulist.h \
|
||||
|
|
|
@ -130,10 +130,10 @@ libfinal_la_LIBADD =
|
|||
am_libfinal_la_OBJECTS = fstring.lo fpoint.lo frect.lo fscrollbar.lo \
|
||||
fprogressbar.lo flineedit.lo fbutton.lo fbuttongroup.lo \
|
||||
ftogglebutton.lo fradiobutton.lo fcheckbox.lo fswitch.lo \
|
||||
flabel.lo flistbox.lo fmenubar.lo fmenuitem.lo fmenulist.lo \
|
||||
fdialog.lo fwindow.lo fmessagebox.lo ffiledialog.lo \
|
||||
ftextview.lo fstatusbar.lo fterm.lo fevent.lo foptimove.lo \
|
||||
fapp.lo fwidget.lo fobject.lo
|
||||
flabel.lo flistbox.lo fmenu.lo fmenubar.lo fmenuitem.lo \
|
||||
fmenulist.lo fdialog.lo fwindow.lo fmessagebox.lo \
|
||||
ffiledialog.lo ftextview.lo fstatusbar.lo fterm.lo fevent.lo \
|
||||
foptimove.lo fapp.lo fwidget.lo fobject.lo
|
||||
libfinal_la_OBJECTS = $(am_libfinal_la_OBJECTS)
|
||||
AM_V_lt = $(am__v_lt_@AM_V@)
|
||||
am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@)
|
||||
|
@ -385,6 +385,7 @@ libfinal_la_SOURCES = \
|
|||
fswitch.cpp \
|
||||
flabel.cpp \
|
||||
flistbox.cpp \
|
||||
fmenu.cpp \
|
||||
fmenubar.cpp \
|
||||
fmenuitem.cpp \
|
||||
fmenulist.cpp \
|
||||
|
@ -419,6 +420,7 @@ finalcutinclude_HEADERS = \
|
|||
flabel.h \
|
||||
flineedit.h \
|
||||
flistbox.h \
|
||||
fmenu.h \
|
||||
fmenubar.h \
|
||||
fmenuitem.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)/flineedit.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)/fmenuitem.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fmenulist.Plo@am__quote@
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#include "flistbox.h"
|
||||
#include "ftextview.h"
|
||||
#include "flineedit.h"
|
||||
#include "fmenu.h"
|
||||
#include "fmenubar.h"
|
||||
#include "fmenuitem.h"
|
||||
#include "fstatusbar.h"
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -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
|
|
@ -50,6 +50,12 @@ void FMenuBar::init()
|
|||
unsetFocusable();
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
bool FMenuBar::isMenu (FMenuItem* mi) const
|
||||
{
|
||||
return mi->hasMenu();
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
int FMenuBar::getHotkeyPos (wchar_t*& src, wchar_t*& dest, uInt length)
|
||||
{
|
||||
|
@ -83,6 +89,9 @@ void FMenuBar::draw()
|
|||
//----------------------------------------------------------------------
|
||||
void FMenuBar::drawItems()
|
||||
{
|
||||
bool isActive;
|
||||
bool isSelected;
|
||||
bool isNoUnderline;
|
||||
std::vector<FMenuItem*>::const_iterator iter, end;
|
||||
int screenWidth;
|
||||
|
||||
|
@ -108,9 +117,10 @@ void FMenuBar::drawItems()
|
|||
FString txt;
|
||||
uInt txt_length;
|
||||
int hotkeypos, to_char;
|
||||
bool isActive = (*iter)->isActivated();
|
||||
bool isSelected = (*iter)->isSelected();
|
||||
bool isNoUnderline = (((*iter)->getFlags() & NO_UNDERLINE) != 0);
|
||||
|
||||
isActive = (*iter)->isActivated();
|
||||
isSelected = (*iter)->isSelected();
|
||||
isNoUnderline = (((*iter)->getFlags() & NO_UNDERLINE) != 0);
|
||||
|
||||
if ( isActive )
|
||||
{
|
||||
|
@ -255,7 +265,9 @@ void FMenuBar::onMouseDown (FMouseEvent* event)
|
|||
|
||||
x1 = X;
|
||||
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_y = event->getY();
|
||||
|
||||
|
@ -267,7 +279,12 @@ void FMenuBar::onMouseDown (FMouseEvent* event)
|
|||
(*iter)->setSelected();
|
||||
this->redraw();
|
||||
}
|
||||
X = x2 + 2;
|
||||
else
|
||||
{
|
||||
(*iter)->unsetSelected();
|
||||
this->redraw();
|
||||
}
|
||||
X = x2 + 1;
|
||||
++iter;
|
||||
}
|
||||
}
|
||||
|
@ -294,7 +311,9 @@ void FMenuBar::onMouseUp (FMouseEvent* event)
|
|||
{
|
||||
int x1 = X;
|
||||
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() )
|
||||
{
|
||||
|
@ -304,7 +323,7 @@ void FMenuBar::onMouseUp (FMouseEvent* event)
|
|||
(*iter)->unsetSelected();
|
||||
this->redraw();
|
||||
}
|
||||
X = x2 + 2;
|
||||
X = x2 + 1;
|
||||
++iter;
|
||||
}
|
||||
}
|
||||
|
@ -330,7 +349,9 @@ void FMenuBar::onMouseMove (FMouseEvent* event)
|
|||
{
|
||||
int x1 = X;
|
||||
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_y = event->getY();
|
||||
|
@ -352,7 +373,7 @@ void FMenuBar::onMouseMove (FMouseEvent* event)
|
|||
focus_changed = true;
|
||||
}
|
||||
}
|
||||
X = x2 + 2;
|
||||
X = x2 + 1;
|
||||
++iter;
|
||||
}
|
||||
if ( focus_changed )
|
||||
|
@ -393,27 +414,12 @@ void FMenuBar::setGeometry (int xx, int yy, int ww, int hh, bool adjust)
|
|||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
/*
|
||||
void FMenuBar::cb_menuitem_activated (FWidget* widget, void*)
|
||||
void FMenuBar::cb_item_activated (FWidget* widget, void*)
|
||||
{
|
||||
if ( ! itemlist.empty() )
|
||||
FMenuItem* menuitem = static_cast<FMenuItem*>(widget);
|
||||
|
||||
if ( menuitem->hasMenu() )
|
||||
{
|
||||
std::vector<FMenuItem*>::const_iterator iter, end;
|
||||
FMenuItem* menuitem = static_cast<FMenuItem*>(widget);
|
||||
|
||||
iter = itemlist.begin();
|
||||
end = itemlist.end();
|
||||
|
||||
while ( iter != end )
|
||||
{
|
||||
if ( (*iter) != menuitem && (*iter)->isSelected() )
|
||||
(*iter)->unsetSelected();
|
||||
++iter;
|
||||
}
|
||||
beep();
|
||||
}
|
||||
if ( isVisible() && isShown() )
|
||||
redraw();
|
||||
if ( ! isHiddenCursor() )
|
||||
hideCursor();
|
||||
}
|
||||
*/
|
||||
|
|
|
@ -24,7 +24,8 @@ class FMenuBar : public FWindow, public FMenuList
|
|||
FMenuBar (const FMenuBar&);
|
||||
FMenuBar& operator = (const FMenuBar&);
|
||||
void init();
|
||||
int getHotkeyPos (wchar_t*&, wchar_t*&, uInt);
|
||||
bool isMenu (FMenuItem*) const;
|
||||
int getHotkeyPos (wchar_t*&, wchar_t*&, uInt);
|
||||
void draw();
|
||||
void drawItems();
|
||||
void adjustSize();
|
||||
|
@ -40,8 +41,7 @@ class FMenuBar : public FWindow, public FMenuList
|
|||
void onMouseMove (FMouseEvent*);
|
||||
void hide();
|
||||
void setGeometry (int, int, int, int, bool adjust=true);
|
||||
|
||||
//void cb_menuitem_activated (FWidget*, void*);
|
||||
void cb_item_activated (FWidget*, void*);
|
||||
};
|
||||
#pragma pack(pop)
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
// fmenuitem.cpp
|
||||
// class FMenuItem
|
||||
|
||||
#include "fmenubar.h"
|
||||
#include "fmenuitem.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);
|
||||
init (parent);
|
||||
|
@ -50,16 +51,43 @@ void FMenuItem::init (FWidget* parent)
|
|||
selected = false;
|
||||
separator = false;
|
||||
checked = false;
|
||||
//menu = 0
|
||||
hotkey = 0;
|
||||
menu = 0;
|
||||
setGeometry (1,1,1,1);
|
||||
|
||||
if ( parent && isMenuBar(parent) )
|
||||
{
|
||||
setSuperMenu( dynamic_cast<FMenuList*>(parent) );
|
||||
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
|
||||
{
|
||||
|
@ -67,11 +95,24 @@ bool FMenuItem::isMenuBar (FWidget* w) const
|
|||
const_cast<char*>("FMenuBar") ) == 0 );
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
FMenuList* FMenuItem::superMenu() const
|
||||
{
|
||||
return super_menu;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
void FMenuItem::setSuperMenu (FMenuList* smenu)
|
||||
{
|
||||
super_menu = smenu;
|
||||
}
|
||||
|
||||
|
||||
// protected methods of FMenuItem
|
||||
//----------------------------------------------------------------------
|
||||
void FMenuItem::processActivate()
|
||||
{
|
||||
emitCallback("activate");
|
||||
}
|
||||
|
||||
// public methods of FMenuItem
|
||||
|
@ -89,20 +130,29 @@ void FMenuItem::onAccel (FAccelEvent* event)
|
|||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
FMenuList* FMenuItem::superMenu() const
|
||||
void FMenuItem::setSelected()
|
||||
{
|
||||
return super_menu;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
void FMenuItem::setSuperMenu (FMenuList* smenu)
|
||||
{
|
||||
super_menu = smenu;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
inline void FMenuItem::setActive()
|
||||
{
|
||||
this->active = true;
|
||||
this->selected = true;
|
||||
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();
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
#include "fwidget.h"
|
||||
|
||||
class FMenu;
|
||||
class FMenuList;
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
@ -23,23 +24,23 @@ class FMenuItem : public FWidget
|
|||
bool selected;
|
||||
bool separator;
|
||||
bool checked;
|
||||
int hotkey;
|
||||
//int accel_key;
|
||||
//FPopupMenu* menu;
|
||||
FMenu* menu;
|
||||
FMenuList* super_menu;
|
||||
|
||||
private:
|
||||
FMenuItem (const FMenuItem&);
|
||||
FMenuItem& operator = (const FMenuItem&);
|
||||
void init (FWidget*);
|
||||
uChar getHotkey();
|
||||
bool isMenuBar (FWidget*) const;
|
||||
FMenuList* superMenu() const;
|
||||
void setSuperMenu (FMenuList*);
|
||||
|
||||
protected:
|
||||
virtual void processActivate();
|
||||
void processActivate();
|
||||
|
||||
public:
|
||||
explicit FMenuItem(FWidget* parent=0);
|
||||
explicit FMenuItem (FWidget* parent=0);
|
||||
FMenuItem (FString&, FWidget* parent=0);
|
||||
FMenuItem (const std::string&, FWidget* parent=0);
|
||||
FMenuItem (const char*, FWidget* parent=0);
|
||||
|
@ -59,12 +60,12 @@ class FMenuItem : public FWidget
|
|||
void setChecked();
|
||||
void unsetChecked();
|
||||
bool isChecked() const;
|
||||
bool hasHotkey() const;
|
||||
void setMenu(FMenu*);
|
||||
bool hasMenu() const;
|
||||
|
||||
protected:
|
||||
void setText (FString&);
|
||||
void setText (const std::string&);
|
||||
void setText (const char*);
|
||||
void setText (FString&);
|
||||
void setText (const std::string&);
|
||||
void setText (const char*);
|
||||
|
||||
private:
|
||||
friend class FMenuList;
|
||||
|
@ -77,6 +78,10 @@ class FMenuItem : public FWidget
|
|||
inline FString FMenuItem::getText() const
|
||||
{ return this->text; }
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
inline void FMenuItem::setActive()
|
||||
{ this->active = true; }
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
inline void FMenuItem::unsetActive()
|
||||
{ this->active = false; }
|
||||
|
@ -85,10 +90,6 @@ inline void FMenuItem::unsetActive()
|
|||
inline bool FMenuItem::isActivated() const
|
||||
{ return active; }
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
inline void FMenuItem::setSelected()
|
||||
{ this->selected = true; }
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
inline void FMenuItem::unsetSelected()
|
||||
{ this->selected = false; }
|
||||
|
@ -122,20 +123,16 @@ inline bool FMenuItem::isChecked() const
|
|||
{ return checked; }
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
//inline bool FMenuItem::hasMenu() const;
|
||||
//{ return bool(menu != 0); }
|
||||
inline bool FMenuItem::hasHotkey() const
|
||||
{ return bool(hotkey != 0); }
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
inline void FMenuItem::setText (FString& txt)
|
||||
{ this->text = txt; }
|
||||
inline void FMenuItem::setMenu(FMenu* m)
|
||||
{ menu = m; }
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
inline void FMenuItem::setText (const std::string& txt)
|
||||
{ this->text = txt; }
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
inline void FMenuItem::setText (const char* txt)
|
||||
{ this->text = txt; }
|
||||
inline bool FMenuItem::hasMenu() const
|
||||
{ return bool(menu != 0); }
|
||||
|
||||
|
||||
#endif // _FMENUITEM_H
|
||||
|
|
|
@ -58,28 +58,17 @@ bool FMenuList::hasSelectedItem()
|
|||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
void FMenuList::insert (FMenuItem* obj)
|
||||
void FMenuList::insert (FMenuItem* item)
|
||||
{
|
||||
itemlist.push_back(obj);
|
||||
|
||||
//addAccelerator (obj->getKey(), obj);
|
||||
/*
|
||||
obj->addCallback
|
||||
(
|
||||
"activate",
|
||||
this,
|
||||
reinterpret_cast<FWidget::FMemberCallback>(&FMenuBar::cb_statuskey_activated),
|
||||
null
|
||||
);
|
||||
*/
|
||||
itemlist.push_back(item);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
void FMenuList::remove (FMenuItem* obj)
|
||||
void FMenuList::remove (FMenuItem* item)
|
||||
{
|
||||
std::vector<FMenuItem*>::iterator iter;
|
||||
|
||||
//delAccelerator (obj);
|
||||
//delAccelerator (item);
|
||||
|
||||
if ( itemlist.empty() )
|
||||
return;
|
||||
|
@ -87,10 +76,10 @@ void FMenuList::remove (FMenuItem* obj)
|
|||
iter = itemlist.begin();
|
||||
while ( iter != itemlist.end() )
|
||||
{
|
||||
if ( (*iter) == obj )
|
||||
if ( (*iter) == item )
|
||||
{
|
||||
iter = itemlist.erase(iter);
|
||||
obj->setSuperMenu(0);
|
||||
item->setSuperMenu(0);
|
||||
break;
|
||||
}
|
||||
else
|
||||
|
@ -112,3 +101,10 @@ void FMenuList::clear()
|
|||
{
|
||||
itemlist.clear();
|
||||
}
|
||||
|
||||
|
||||
// protected methods of FMenuList
|
||||
//----------------------------------------------------------------------
|
||||
/*void FMenuList::cb_item_activated (FWidget*, void*)
|
||||
{
|
||||
}*/
|
||||
|
|
|
@ -4,8 +4,8 @@
|
|||
#ifndef _FMENULIST_H
|
||||
#define _FMENULIST_H
|
||||
|
||||
#include "fwidget.h"
|
||||
#include "fmenuitem.h"
|
||||
#include "fwidget.h"
|
||||
|
||||
/*
|
||||
┌─────────┐ ┌──────────┐
|
||||
|
@ -13,12 +13,13 @@
|
|||
└─────────┘ │ └──────────┘
|
||||
┌───────────┐◄───┘ ┌───────────┐
|
||||
│ FMenuList ├-------┤ FMenuItem │
|
||||
└───────────┘◄───┐ └───────────┘
|
||||
┌─────────┐ │ ┌────────────┐
|
||||
│ FWidget │◄───┴──┤ FPopupMenu │
|
||||
└─────────┘ └────────────┘
|
||||
└───────────┘◄───┐ └───┬───────┘
|
||||
┌─────────┐ │ ┌───┴───┐
|
||||
│ FWidget │◄───┴──┤ FMenu │
|
||||
└─────────┘ └───────┘
|
||||
*/
|
||||
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// class FMenuList
|
||||
//----------------------------------------------------------------------
|
||||
|
@ -40,17 +41,17 @@ class FMenuList
|
|||
virtual ~FMenuList();
|
||||
virtual const char* getClassName() const;
|
||||
|
||||
uInt count() const;
|
||||
uInt count() const;
|
||||
FMenuItem* item (int) const;
|
||||
void activateItem (int);
|
||||
void deactivateItem (int);
|
||||
bool isSelected (int) const;
|
||||
bool hasSelectedItem();
|
||||
void activateItem (int);
|
||||
void deactivateItem (int);
|
||||
bool isSelected (int) const;
|
||||
bool hasSelectedItem();
|
||||
|
||||
void insert (FMenuItem*);
|
||||
void remove (FMenuItem*);
|
||||
void remove (int);
|
||||
void clear();
|
||||
void insert (FMenuItem*);
|
||||
void remove (FMenuItem*);
|
||||
void remove (int);
|
||||
void clear();
|
||||
};
|
||||
#pragma pack(pop)
|
||||
|
||||
|
|
Loading…
Reference in New Issue