From 31c9d86dbacce88d7ede53f5a4f2f529901cba63 Mon Sep 17 00:00:00 2001 From: Markus Gans Date: Sun, 9 Aug 2015 23:47:08 +0200 Subject: [PATCH] add classes FMenuBar, FMenuList and FMenuItem --- src/Makefile.am | 6 + src/Makefile.in | 16 +- src/final.h | 2 + src/fmenubar.cpp | 419 ++++++++++++++++++++++++++++++++++++++++++++++ src/fmenubar.h | 54 ++++++ src/fmenuitem.cpp | 108 ++++++++++++ src/fmenuitem.h | 141 ++++++++++++++++ src/fmenulist.cpp | 114 +++++++++++++ src/fmenulist.h | 84 ++++++++++ 9 files changed, 941 insertions(+), 3 deletions(-) create mode 100644 src/fmenubar.cpp create mode 100644 src/fmenubar.h create mode 100644 src/fmenuitem.cpp create mode 100644 src/fmenuitem.h create mode 100644 src/fmenulist.cpp create mode 100644 src/fmenulist.h diff --git a/src/Makefile.am b/src/Makefile.am index 800b5b39..89d1929e 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -23,6 +23,9 @@ libfinal_la_SOURCES = \ fswitch.cpp \ flabel.cpp \ flistbox.cpp \ + fmenubar.cpp \ + fmenuitem.cpp \ + fmenulist.cpp \ fdialog.cpp \ fwindow.cpp \ fmessagebox.cpp \ @@ -56,6 +59,9 @@ finalcutinclude_HEADERS = \ flabel.h \ flineedit.h \ flistbox.h \ + fmenubar.h \ + fmenuitem.h \ + fmenulist.h \ fmessagebox.h \ fobject.h \ foptimove.h \ diff --git a/src/Makefile.in b/src/Makefile.in index 86cb85c1..4d8094bf 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -130,9 +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 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 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@) @@ -384,6 +385,9 @@ libfinal_la_SOURCES = \ fswitch.cpp \ flabel.cpp \ flistbox.cpp \ + fmenubar.cpp \ + fmenuitem.cpp \ + fmenulist.cpp \ fdialog.cpp \ fwindow.cpp \ fmessagebox.cpp \ @@ -415,6 +419,9 @@ finalcutinclude_HEADERS = \ flabel.h \ flineedit.h \ flistbox.h \ + fmenubar.h \ + fmenuitem.h \ + fmenulist.h \ fmessagebox.h \ fobject.h \ foptimove.h \ @@ -521,6 +528,9 @@ 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)/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@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fmessagebox.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fobject.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/foptimove.Plo@am__quote@ diff --git a/src/final.h b/src/final.h index 66216567..da7c0913 100644 --- a/src/final.h +++ b/src/final.h @@ -19,6 +19,8 @@ #include "flistbox.h" #include "ftextview.h" #include "flineedit.h" +#include "fmenubar.h" +#include "fmenuitem.h" #include "fstatusbar.h" #include "fscrollbar.h" #include "fprogressbar.h" diff --git a/src/fmenubar.cpp b/src/fmenubar.cpp new file mode 100644 index 00000000..172ef9bf --- /dev/null +++ b/src/fmenubar.cpp @@ -0,0 +1,419 @@ +// fmenubar.cpp +// class FMenuBar + +#include "fmenubar.h" + +//---------------------------------------------------------------------- +// class FMenuBar +//---------------------------------------------------------------------- + +// constructor and destructor +//---------------------------------------------------------------------- +FMenuBar::FMenuBar(FWidget* parent) : FWindow(parent) +{ + this->init(); +} + +//---------------------------------------------------------------------- +FMenuBar::~FMenuBar() +{ + if ( vmenubar != 0 ) + { + if ( vmenubar->changes != 0 ) + delete[] vmenubar->changes; + if ( vmenubar->text != 0 ) + delete[] vmenubar->text; + delete vmenubar; + } + vmenubar = 0; +} + + +// private methods of FMenuBar +//---------------------------------------------------------------------- +void FMenuBar::init() +{ + xmin = ymin = 1; + xpos = 1; + ypos = 1; + createArea (vmenubar); + // initialize geometry values + setGeometry (1, 1, getColumnNumber(), 1, false); + getRootWidget()->setTopPadding(1, true); + x = -1; + setMenuBar(this); + foregroundColor = wc.statusbar_fg; + backgroundColor = wc.statusbar_bg; + window_object = true; + mouse_down = false; + ignore_padding = true; + unsetFocusable(); +} + +//---------------------------------------------------------------------- +int FMenuBar::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 FMenuBar::draw() +{ + xmin = ymin = 1; + height = 1; + xpos = 1; + drawItems(); +} + +//---------------------------------------------------------------------- +void FMenuBar::drawItems() +{ + std::vector::const_iterator iter, end; + int screenWidth; + + x = 1; + screenWidth = getColumnNumber(); + width = screenWidth; + ypos = 1; + + if ( itemlist.empty() ) + return; + + setUpdateVTerm(false); + gotoxy (1,1); + + 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; + } + setColor (foregroundColor, backgroundColor); + x++; + print (vmenubar, ' '); + + txt = (*iter)->getText(); + txt_length = int(txt.getLength()); + item_text = new wchar_t[txt_length+1]; + src = const_cast(txt.wc_str()); + dest = const_cast(item_text); + + if ( x-1 <= screenWidth ) + to_char = int(txt_length); + else + to_char = txt_length - (screenWidth-x-1); + + hotkeypos = getHotkeyPos (src, dest, txt_length); + + if ( hotkeypos != -1 ) + { + txt_length--; + to_char--; + } + x += txt_length; + + 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 ( x > screenWidth ) + { + print ( vmenubar, + txt.left(uInt(txt_length+screenWidth-x-1)) ); + print ( vmenubar, ".." ); + } + else + { + x++; + print (vmenubar, ' '); + } + + if ( isActive && isSelected ) + setReverse(false); + delete[] item_text; + + ++iter; + } + for (; x <= screenWidth; x++) + print (vmenubar, ' '); + + setUpdateVTerm(true); +} + +//---------------------------------------------------------------------- +void FMenuBar::adjustSize() +{ + xmin = ymin = 1; + height = 1; + xpos = 1; + width = getColumnNumber(); + ypos = 1; + FWidget::adjustSize(); +} + +//---------------------------------------------------------------------- +void FMenuBar::processActivate() +{ + emitCallback("activate"); +} + +// public methods of FMenuBar +//---------------------------------------------------------------------- +void FMenuBar::onMouseDown (FMouseEvent* event) +{ + if ( event->getButton() != LeftButton ) + { + mouse_down = false; + if ( ! itemlist.empty() ) + { + std::vector::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::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 FMenuBar::onMouseUp (FMouseEvent* event) +{ + if ( event->getButton() != LeftButton ) + return; + + if ( mouse_down ) + { + mouse_down = false; + if ( ! itemlist.empty() ) + { + std::vector::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 FMenuBar::onMouseMove (FMouseEvent* event) +{ + if ( event->getButton() != LeftButton ) + return; + + if ( mouse_down && ! itemlist.empty() ) + { + std::vector::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 FMenuBar::hide() +{ + int fg, bg, screenWidth; + char* blank; + + FWidget::hide(); + + fg = wc.term_fg; + bg = wc.term_bg; + setColor (fg, bg); + + screenWidth = getColumnNumber(); + blank = new char[screenWidth+1]; + memset(blank, ' ', uLong(screenWidth)); + blank[screenWidth] = '\0'; + + gotoxy (1, 1); + print (vmenubar, blank); + delete[] blank; +} + +//---------------------------------------------------------------------- +void FMenuBar::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 FMenuBar::cb_menuitem_activated (FWidget* widget, void*) +{ + if ( ! itemlist.empty() ) + { + std::vector::const_iterator iter, end; + FMenuItem* menuitem = static_cast(widget); + + iter = itemlist.begin(); + end = itemlist.end(); + + while ( iter != end ) + { + if ( (*iter) != menuitem && (*iter)->isSelected() ) + (*iter)->unsetSelected(); + ++iter; + } + } + if ( isVisible() && isShown() ) + redraw(); + if ( ! isHiddenCursor() ) + hideCursor(); +} +*/ diff --git a/src/fmenubar.h b/src/fmenubar.h new file mode 100644 index 00000000..d2f1d98e --- /dev/null +++ b/src/fmenubar.h @@ -0,0 +1,54 @@ +// fmenubar.h +// class FMenuBar + +#ifndef _FMENUBAR_H +#define _FMENUBAR_H + +#include "fwindow.h" +#include "fmenulist.h" + +//---------------------------------------------------------------------- +// class FMenuBar +//---------------------------------------------------------------------- + +#pragma pack(push) +#pragma pack(1) + +class FMenuBar : public FWindow, public FMenuList +{ + private: + bool mouse_down; + int x; + + private: + FMenuBar (const FMenuBar&); + FMenuBar& operator = (const FMenuBar&); + void init(); + int getHotkeyPos (wchar_t*&, wchar_t*&, uInt); + void draw(); + void drawItems(); + void adjustSize(); + void processActivate(); + + public: + explicit FMenuBar (FWidget* parent=0); // constructor + virtual ~FMenuBar(); // 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); + + //void cb_menuitem_activated (FWidget*, void*); +}; +#pragma pack(pop) + + +// FMenuBar inline functions +//---------------------------------------------------------------------- +inline const char* FMenuBar::getClassName() const +{ return "FMenuBar"; } + +#endif // _FMENUBAR_H diff --git a/src/fmenuitem.cpp b/src/fmenuitem.cpp new file mode 100644 index 00000000..95cde171 --- /dev/null +++ b/src/fmenuitem.cpp @@ -0,0 +1,108 @@ +// fmenuitem.cpp +// class FMenuItem + +#include "fmenuitem.h" +#include "fmenulist.h" + +//---------------------------------------------------------------------- +// class FMenuItem +//---------------------------------------------------------------------- + +// constructor and destructor +//---------------------------------------------------------------------- +FMenuItem::FMenuItem (FWidget* parent) : FWidget(parent) +{ + init (parent); +} + +//---------------------------------------------------------------------- +FMenuItem::FMenuItem (FString& txt, FWidget* parent) +{ + setText(txt); + init (parent); +} + +//---------------------------------------------------------------------- +FMenuItem::FMenuItem (const std::string& txt, FWidget* parent) : FWidget(parent) +{ + setText(txt); + init (parent); +} + +//---------------------------------------------------------------------- +FMenuItem::FMenuItem (const char* txt, FWidget* parent) : FWidget(parent) +{ + setText(txt); + init (parent); +} + +//---------------------------------------------------------------------- +FMenuItem::~FMenuItem() // destructor +{ +} + + +// private methods of FMenuItem +//---------------------------------------------------------------------- +void FMenuItem::init (FWidget* parent) +{ + active = true; + selected = false; + separator = false; + checked = false; + //menu = 0 + setGeometry (1,1,1,1); + + if ( parent && isMenuBar(parent) ) + { + setSuperMenu( dynamic_cast(parent) ); + superMenu()->insert(this); + } +} + +//---------------------------------------------------------------------- +bool FMenuItem::isMenuBar (FWidget* w) const +{ + return bool ( strcmp ( w->getClassName(), + const_cast("FMenuBar") ) == 0 ); +} + + +// protected methods of FMenuItem +//---------------------------------------------------------------------- +void FMenuItem::processActivate() +{ +} + +// public methods of FMenuItem +//---------------------------------------------------------------------- +void FMenuItem::onAccel (FAccelEvent* event) +{ + if ( isSelected() ) + { + unsetSelected(); + FWidget* w = reinterpret_cast(superMenu()); + if ( isMenuBar(w) ) + w->redraw(); + event->accept(); + } +} + +//---------------------------------------------------------------------- +FMenuList* FMenuItem::superMenu() const +{ + return super_menu; +} + +//---------------------------------------------------------------------- +void FMenuItem::setSuperMenu (FMenuList* smenu) +{ + super_menu = smenu; +} + +//---------------------------------------------------------------------- +inline void FMenuItem::setActive() +{ + this->active = true; + processActivate(); +} diff --git a/src/fmenuitem.h b/src/fmenuitem.h new file mode 100644 index 00000000..48a410ab --- /dev/null +++ b/src/fmenuitem.h @@ -0,0 +1,141 @@ +// fmenuitem.h +// class FMenuItem + +#ifndef _FMENUITEM_H +#define _FMENUITEM_H + +#include "fwidget.h" + +class FMenuList; + +//---------------------------------------------------------------------- +// class FMenuItem +//---------------------------------------------------------------------- + +#pragma pack(push) +#pragma pack(1) + +class FMenuItem : public FWidget +{ + private: + FString text; + bool active; + bool selected; + bool separator; + bool checked; + //int accel_key; + //FPopupMenu* menu; + FMenuList* super_menu; + + private: + FMenuItem (const FMenuItem&); + FMenuItem& operator = (const FMenuItem&); + void init (FWidget*); + bool isMenuBar (FWidget*) const; + FMenuList* superMenu() const; + void setSuperMenu (FMenuList*); + + protected: + virtual void processActivate(); + + public: + explicit FMenuItem(FWidget* parent=0); + FMenuItem (FString&, FWidget* parent=0); + FMenuItem (const std::string&, FWidget* parent=0); + FMenuItem (const char*, FWidget* parent=0); + virtual ~FMenuItem(); + + void onAccel (FAccelEvent*); + FString getText() const; + void setActive(); + void unsetActive(); + bool isActivated() const; + void setSelected(); + void unsetSelected(); + bool isSelected() const; + void setSeparator(); + void unsetSeparator(); + bool isSeparator() const; + void setChecked(); + void unsetChecked(); + bool isChecked() const; + bool hasMenu() const; + + protected: + void setText (FString&); + void setText (const std::string&); + void setText (const char*); + + private: + friend class FMenuList; +}; +#pragma pack(pop) + + +// FMenuItem inline functions +//---------------------------------------------------------------------- +inline FString FMenuItem::getText() const +{ return this->text; } + +//---------------------------------------------------------------------- +inline void FMenuItem::unsetActive() +{ this->active = false; } + +//---------------------------------------------------------------------- +inline bool FMenuItem::isActivated() const +{ return active; } + +//---------------------------------------------------------------------- +inline void FMenuItem::setSelected() +{ this->selected = true; } + +//---------------------------------------------------------------------- +inline void FMenuItem::unsetSelected() +{ this->selected = false; } + +//---------------------------------------------------------------------- +inline bool FMenuItem::isSelected() const +{ return selected; } + +//---------------------------------------------------------------------- +inline void FMenuItem::setSeparator() +{ this->separator = true; } + +//---------------------------------------------------------------------- +inline void FMenuItem::unsetSeparator() +{ this->separator = false; } + +//---------------------------------------------------------------------- +inline bool FMenuItem::isSeparator() const +{ return separator; } + +//---------------------------------------------------------------------- +inline void FMenuItem::setChecked() +{ this->checked = true; } + +//---------------------------------------------------------------------- +inline void FMenuItem::unsetChecked() +{ this->checked = false; } + +//---------------------------------------------------------------------- +inline bool FMenuItem::isChecked() const +{ return checked; } + +//---------------------------------------------------------------------- +//inline bool FMenuItem::hasMenu() const; +//{ return bool(menu != 0); } + +//---------------------------------------------------------------------- +inline void FMenuItem::setText (FString& txt) +{ this->text = txt; } + +//---------------------------------------------------------------------- +inline void FMenuItem::setText (const std::string& txt) +{ this->text = txt; } + +//---------------------------------------------------------------------- +inline void FMenuItem::setText (const char* txt) +{ this->text = txt; } + + +#endif // _FMENUITEM_H diff --git a/src/fmenulist.cpp b/src/fmenulist.cpp new file mode 100644 index 00000000..caa8de56 --- /dev/null +++ b/src/fmenulist.cpp @@ -0,0 +1,114 @@ +// fmenulist.cpp +// class FMenuList + +#include "fmenulist.h" + +//---------------------------------------------------------------------- +// class FMenuList +//---------------------------------------------------------------------- + +// constructor and destructor +//---------------------------------------------------------------------- +FMenuList::FMenuList() +{ +} + +//---------------------------------------------------------------------- +FMenuList::~FMenuList() // destructor +{ + // delete all items + if ( ! itemlist.empty() ) + { + std::vector::iterator iter; + iter = itemlist.begin(); + + while ( iter != itemlist.end() ) + { + (*iter)->setSuperMenu(0); + //delAccelerator (*iter); + iter = itemlist.erase(iter); + } + } +} + + +// private methods of FMenuList +//---------------------------------------------------------------------- + + + +// public methods of FMenuList +//---------------------------------------------------------------------- +bool FMenuList::hasSelectedItem() +{ + if ( ! itemlist.empty() ) + { + std::vector::const_iterator iter, end; + iter = itemlist.begin(); + end = itemlist.end(); + + while ( iter != end ) + { + if ( (*iter)->isSelected() ) + return true; + ++iter; + } + } + return false; +} + +//---------------------------------------------------------------------- +void FMenuList::insert (FMenuItem* obj) +{ + itemlist.push_back(obj); + + //addAccelerator (obj->getKey(), obj); +/* + obj->addCallback + ( + "activate", + this, + reinterpret_cast(&FMenuBar::cb_statuskey_activated), + null + ); +*/ +} + +//---------------------------------------------------------------------- +void FMenuList::remove (FMenuItem* obj) +{ + std::vector::iterator iter; + + //delAccelerator (obj); + + if ( itemlist.empty() ) + return; + + iter = itemlist.begin(); + while ( iter != itemlist.end() ) + { + if ( (*iter) == obj ) + { + iter = itemlist.erase(iter); + obj->setSuperMenu(0); + break; + } + else + ++iter; + } +} + +//---------------------------------------------------------------------- +void FMenuList::remove (int pos) +{ + if ( int(count()) < pos ) + return; + + itemlist.erase (itemlist.begin()+pos-1); +} + +//---------------------------------------------------------------------- +void FMenuList::clear() +{ + itemlist.clear(); +} diff --git a/src/fmenulist.h b/src/fmenulist.h new file mode 100644 index 00000000..35169878 --- /dev/null +++ b/src/fmenulist.h @@ -0,0 +1,84 @@ +// fmenulist.h +// class FMenuList + +#ifndef _FMENULIST_H +#define _FMENULIST_H + +#include "fwidget.h" +#include "fmenuitem.h" + +/* + ┌─────────┐ ┌──────────┐ + │ FWindow │◄───┬──┤ FMenuBar │ + └─────────┘ │ └──────────┘ + ┌───────────┐◄───┘ ┌───────────┐ + │ FMenuList ├-------┤ FMenuItem │ + └───────────┘◄───┐ └───────────┘ + ┌─────────┐ │ ┌────────────┐ + │ FWidget │◄───┴──┤ FPopupMenu │ + └─────────┘ └────────────┘ +*/ + +//---------------------------------------------------------------------- +// class FMenuList +//---------------------------------------------------------------------- + +#pragma pack(push) +#pragma pack(1) + +class FMenuList +{ + protected: + std::vector itemlist; + + private: + FMenuList (const FMenuList&); + FMenuList& operator = (const FMenuList&); + + public: + explicit FMenuList(); + virtual ~FMenuList(); + virtual const char* getClassName() const; + + uInt count() const; + FMenuItem* item (int) const; + void activateItem (int); + void deactivateItem (int); + bool isSelected (int) const; + bool hasSelectedItem(); + + void insert (FMenuItem*); + void remove (FMenuItem*); + void remove (int); + void clear(); +}; +#pragma pack(pop) + + +// FMenuList inline functions +//---------------------------------------------------------------------- +inline const char* FMenuList::getClassName() const +{ return "FMenuList"; } + +//---------------------------------------------------------------------- +inline uInt FMenuList::count() const +{ return uInt(itemlist.size()); } + +//---------------------------------------------------------------------- +inline FMenuItem* FMenuList::item(int index) const +{ return itemlist[uInt(index-1)]; } + +//---------------------------------------------------------------------- +inline void FMenuList::activateItem (int index) +{ itemlist[uInt(index-1)]->setActive(); } + +//---------------------------------------------------------------------- +inline void FMenuList::deactivateItem (int index) +{ itemlist[uInt(index-1)]->unsetActive(); } + +//---------------------------------------------------------------------- +inline bool FMenuList::isSelected(int index) const +{ return itemlist[uInt(index-1)]->isSelected(); } + + +#endif // _FMENULIST_H