2015-09-25 21:37:19 +02:00
|
|
|
// File: fmenubar.h
|
|
|
|
// Provides: class FMenu
|
|
|
|
//
|
|
|
|
// Inheritance diagram
|
|
|
|
// ═══════════════════
|
|
|
|
//
|
|
|
|
// ▕▔▔▔▔▔▔▔▔▔▏ ▕▔▔▔▔▔▔▔▔▔▏
|
|
|
|
// ▕ FObject ▏ ▕ FTerm ▏
|
|
|
|
// ▕▁▁▁▁▁▁▁▁▁▏ ▕▁▁▁▁▁▁▁▁▁▏
|
|
|
|
// ▲ ▲
|
2015-11-15 19:46:33 +01:00
|
|
|
// │ │ *▕▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▏
|
|
|
|
// └─────┬─────┘ ┌ - -▕ FRadioMenuItem ▏
|
|
|
|
// │ : ▕▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▏
|
|
|
|
// ▕▔▔▔▔▔▔▔▔▔▏ :
|
|
|
|
// ▕ FWidget ▏ : *▕▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▏
|
|
|
|
// ▕▁▁▁▁▁▁▁▁▁▏ ├ - -▕ FCheckMenuItem ▏
|
|
|
|
// ▲ : ▕▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▏
|
|
|
|
// │ 1 :
|
|
|
|
// ▕▔▔▔▔▔▔▔▔▔▏ ▕▔▔▔▔▔▔▔▔▔▔▔▏- ┘ ▕▔▔▔▔▔▔▔▔▔▔▔▏
|
2015-09-25 21:37:19 +02:00
|
|
|
// ▕ FWindow ▏ ▕ FMenuList ▏- - - -▕ FMenuItem ▏
|
2015-09-27 16:00:13 +02:00
|
|
|
// ▕▁▁▁▁▁▁▁▁▁▏ ▕▁▁▁▁▁▁▁▁▁▁▁▏1 *▕▁▁▁▁▁▁▁▁▁▁▁▏
|
|
|
|
// ▲ ▲ 1:
|
|
|
|
// │ │ :
|
|
|
|
// └─────┬─────┘ :
|
|
|
|
// │ 1 :
|
|
|
|
// ▕▔▔▔▔▔▔▔▏- - - ┘ ▕▔▔▔▔▔▔▔▔▔▔▔▏
|
|
|
|
// ▕ FMenu ▏- - - - - - - -▕ FMenuItem ▏
|
|
|
|
// ▕▁▁▁▁▁▁▁▏1 1▕▁▁▁▁▁▁▁▁▁▁▁▏
|
2015-08-16 20:05:39 +02:00
|
|
|
|
|
|
|
#ifndef _FMENU_H
|
|
|
|
#define _FMENU_H
|
|
|
|
|
|
|
|
#include "fwindow.h"
|
2015-10-10 03:14:14 +02:00
|
|
|
#include "fmenubar.h"
|
2015-08-16 20:05:39 +02:00
|
|
|
#include "fmenulist.h"
|
|
|
|
#include "fmenuitem.h"
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// class FMenu
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
#pragma pack(push)
|
|
|
|
#pragma pack(1)
|
|
|
|
|
|
|
|
class FMenu : public FWindow, public FMenuList
|
|
|
|
{
|
|
|
|
private:
|
2016-09-25 23:53:48 +02:00
|
|
|
FMenuItem* item;
|
|
|
|
FWidget* super_menu;
|
|
|
|
FMenu* open_sub_menu;
|
2016-09-27 00:46:05 +02:00
|
|
|
uInt max_item_width;
|
2016-09-25 23:53:48 +02:00
|
|
|
bool mouse_down;
|
|
|
|
bool has_checkable_items;
|
2015-08-16 20:05:39 +02:00
|
|
|
|
|
|
|
private:
|
2016-09-30 04:55:28 +02:00
|
|
|
// Disable copy constructor
|
2015-08-16 20:05:39 +02:00
|
|
|
FMenu (const FMenu&);
|
2016-09-30 04:55:28 +02:00
|
|
|
// Disable assignment operator (=)
|
2015-08-16 20:05:39 +02:00
|
|
|
FMenu& operator = (const FMenu&);
|
2016-09-30 04:55:28 +02:00
|
|
|
|
2016-09-25 23:53:48 +02:00
|
|
|
void init(FWidget*);
|
2016-09-27 00:46:05 +02:00
|
|
|
void calculateDimensions();
|
2016-09-25 23:53:48 +02:00
|
|
|
void adjustItems();
|
|
|
|
int adjustX(int);
|
|
|
|
bool isWindowsMenu (FWidget*) const;
|
|
|
|
bool isMenuBar (FWidget*) const;
|
|
|
|
bool isMenu (FWidget*) const;
|
|
|
|
bool isRadioMenuItem (FWidget*) const;
|
|
|
|
FWidget* getSuperMenu() const;
|
|
|
|
void setSuperMenu (FWidget*);
|
|
|
|
bool isSubMenu() const;
|
|
|
|
void openSubMenu (FMenu*);
|
|
|
|
void hideSubMenus();
|
|
|
|
void hideSuperMenus();
|
|
|
|
bool containsMenuStructure (const FPoint&);
|
|
|
|
bool containsMenuStructure (int, int);
|
|
|
|
FMenu* superMenuAt (const FPoint&);
|
|
|
|
FMenu* superMenuAt (int, int);
|
|
|
|
bool selectNextItem();
|
|
|
|
bool selectPrevItem();
|
|
|
|
void keypressMenuBar (FKeyEvent*&);
|
|
|
|
bool hotkeyMenu (FKeyEvent*&);
|
|
|
|
int getHotkeyPos (wchar_t*&, wchar_t*&, uInt);
|
|
|
|
void draw();
|
|
|
|
void drawItems();
|
|
|
|
void drawSeparator(int);
|
|
|
|
void processActivate();
|
2015-08-16 20:05:39 +02:00
|
|
|
|
|
|
|
public:
|
2016-09-30 04:55:28 +02:00
|
|
|
// Constructor
|
|
|
|
explicit FMenu (FWidget* = 0);
|
2015-09-27 16:45:28 +02:00
|
|
|
FMenu (FString&, FWidget* = 0);
|
|
|
|
FMenu (const std::string&, FWidget* = 0);
|
|
|
|
FMenu (const char*, FWidget* = 0);
|
2016-09-30 04:55:28 +02:00
|
|
|
// Destructor
|
|
|
|
virtual ~FMenu();
|
|
|
|
|
2015-08-16 20:05:39 +02:00
|
|
|
virtual const char* getClassName() const;
|
|
|
|
|
2016-09-30 04:55:28 +02:00
|
|
|
// Event handlers
|
2015-10-29 21:10:50 +01:00
|
|
|
void onKeyPress (FKeyEvent*);
|
2015-08-16 20:05:39 +02:00
|
|
|
void onMouseDown (FMouseEvent*);
|
|
|
|
void onMouseUp (FMouseEvent*);
|
|
|
|
void onMouseMove (FMouseEvent*);
|
2015-10-29 21:10:50 +01:00
|
|
|
void onAccel (FAccelEvent*);
|
2016-09-30 04:55:28 +02:00
|
|
|
|
2015-09-30 22:39:02 +02:00
|
|
|
void show();
|
2015-08-16 20:05:39 +02:00
|
|
|
void hide();
|
2015-11-01 22:45:23 +01:00
|
|
|
void setStatusbarMessage (FString);
|
2015-08-16 20:05:39 +02:00
|
|
|
FMenuItem* getItem() const;
|
|
|
|
FString getText() const;
|
2015-10-29 21:10:50 +01:00
|
|
|
bool setEnable(bool);
|
|
|
|
bool setEnable();
|
|
|
|
bool unsetEnable();
|
|
|
|
bool setDisable();
|
|
|
|
bool isEnabled() const;
|
2015-08-16 20:05:39 +02:00
|
|
|
void setSelected();
|
|
|
|
void unsetSelected();
|
|
|
|
bool isSelected() const;
|
2016-09-25 23:53:48 +02:00
|
|
|
bool setMenuWidget (bool);
|
|
|
|
bool setMenuWidget();
|
|
|
|
bool unsetMenuWidget();
|
2015-08-16 20:05:39 +02:00
|
|
|
bool hasHotkey() const;
|
|
|
|
void setMenu (FMenu*);
|
|
|
|
bool hasMenu() const;
|
|
|
|
void setText (FString&);
|
|
|
|
void setText (const std::string&);
|
|
|
|
void setText (const char*);
|
2016-09-30 04:55:28 +02:00
|
|
|
|
|
|
|
// Callback method
|
2015-11-15 19:46:33 +01:00
|
|
|
void cb_menuitem_toggled (FWidget*, void*);
|
2015-09-30 22:39:02 +02:00
|
|
|
|
|
|
|
private:
|
2015-10-23 00:24:20 +02:00
|
|
|
friend class FApplication;
|
2015-11-15 19:46:33 +01:00
|
|
|
friend class FCheckMenuItem;
|
2016-06-12 23:06:58 +02:00
|
|
|
friend class FDialog;
|
2015-11-07 23:16:09 +01:00
|
|
|
friend class FMenuBar;
|
2015-09-30 22:39:02 +02:00
|
|
|
friend class FMenuItem;
|
2015-11-15 19:46:33 +01:00
|
|
|
friend class FRadioMenuItem;
|
2015-08-16 20:05:39 +02:00
|
|
|
};
|
|
|
|
#pragma pack(pop)
|
|
|
|
|
|
|
|
|
|
|
|
// FMenu inline functions
|
2015-10-19 00:07:07 +02:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline FWidget* FMenu::getSuperMenu() const
|
|
|
|
{ return super_menu; }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline void FMenu::setSuperMenu (FWidget* smenu)
|
|
|
|
{ super_menu = smenu; }
|
|
|
|
|
2015-10-23 00:24:20 +02:00
|
|
|
//----------------------------------------------------------------------
|
2016-09-25 23:53:48 +02:00
|
|
|
inline bool FMenu::containsMenuStructure (const FPoint& p)
|
2015-10-23 00:24:20 +02:00
|
|
|
{ return containsMenuStructure (p.getX(), p.getY()); }
|
|
|
|
|
2015-11-24 23:40:41 +01:00
|
|
|
//----------------------------------------------------------------------
|
2016-09-25 23:53:48 +02:00
|
|
|
inline FMenu* FMenu::superMenuAt (const FPoint& p)
|
2015-11-24 23:40:41 +01:00
|
|
|
{ return superMenuAt (p.getX(), p.getY()); }
|
|
|
|
|
2015-08-16 20:05:39 +02:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline const char* FMenu::getClassName() const
|
|
|
|
{ return "FMenu"; }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2015-09-20 05:44:50 +02:00
|
|
|
inline void FMenu::onAccel (FAccelEvent* ev)
|
|
|
|
{ item->onAccel(ev); }
|
2015-08-16 20:05:39 +02:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline FMenuItem* FMenu::getItem() const
|
|
|
|
{ return item; }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline FString FMenu::getText() const
|
|
|
|
{ return item->getText(); }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2015-10-29 21:10:50 +01:00
|
|
|
inline bool FMenu::setEnable(bool on)
|
|
|
|
{ return item->setEnable(on); }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline bool FMenu::setEnable()
|
|
|
|
{ return item->setEnable(); }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline bool FMenu::unsetEnable()
|
|
|
|
{ return item->unsetEnable(); }
|
2015-08-16 20:05:39 +02:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2015-10-29 21:10:50 +01:00
|
|
|
inline bool FMenu::setDisable()
|
|
|
|
{ return item->setDisable(); }
|
2015-08-16 20:05:39 +02:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2015-10-29 21:10:50 +01:00
|
|
|
inline bool FMenu::isEnabled() const
|
|
|
|
{ return item->isEnabled(); }
|
2015-08-16 20:05:39 +02:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline void FMenu::setSelected()
|
|
|
|
{ item->setSelected(); }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline void FMenu::unsetSelected()
|
|
|
|
{ item->unsetSelected(); }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline bool FMenu::isSelected() const
|
|
|
|
{ return item->isSelected(); }
|
2016-09-25 23:53:48 +02:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline bool FMenu::setMenuWidget()
|
|
|
|
{ return setMenuWidget(true); }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline bool FMenu::unsetMenuWidget()
|
|
|
|
{ return setMenuWidget(false); }
|
2015-08-16 20:05:39 +02:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
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
|