2017-11-04 07:03:53 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* fmenu.h - Widget FMenu *
|
|
|
|
* *
|
|
|
|
* This file is part of the Final Cut widget toolkit *
|
|
|
|
* *
|
2018-09-20 23:59:01 +02:00
|
|
|
* Copyright 2015-2018 Markus Gans *
|
2017-11-04 07:03:53 +01:00
|
|
|
* *
|
|
|
|
* The Final Cut is free software; you can redistribute it and/or *
|
|
|
|
* modify it under the terms of the GNU Lesser General Public License *
|
|
|
|
* as published by the Free Software Foundation; either version 3 of *
|
|
|
|
* the License, or (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* The Final Cut is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU Lesser General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU Lesser General Public *
|
|
|
|
* License along with this program. If not, see *
|
|
|
|
* <http://www.gnu.org/licenses/>. *
|
|
|
|
***********************************************************************/
|
2017-10-02 07:32:33 +02:00
|
|
|
|
|
|
|
/* Inheritance diagram
|
|
|
|
* ═══════════════════
|
|
|
|
*
|
2017-10-29 14:27:50 +01:00
|
|
|
* ▕▔▔▔▔▔▔▔▔▔▏
|
|
|
|
* ▕ FTerm ▏
|
|
|
|
* ▕▁▁▁▁▁▁▁▁▁▏
|
|
|
|
* ▲
|
|
|
|
* │
|
2017-10-02 07:32:33 +02:00
|
|
|
* ▕▔▔▔▔▔▔▔▔▔▏ ▕▔▔▔▔▔▔▔▔▔▏
|
2017-10-29 14:27:50 +01:00
|
|
|
* ▕ FVTerm ▏ ▕ FObject ▏
|
2017-10-02 07:32:33 +02:00
|
|
|
* ▕▁▁▁▁▁▁▁▁▁▏ ▕▁▁▁▁▁▁▁▁▁▏
|
|
|
|
* ▲ ▲
|
2017-10-29 14:27:50 +01:00
|
|
|
* │ │ *▕▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▏
|
|
|
|
* └─────┬─────┘ ┌ - -▕ FRadioMenuItem ▏
|
2017-10-02 07:32:33 +02:00
|
|
|
* │ : ▕▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▏
|
|
|
|
* ▕▔▔▔▔▔▔▔▔▔▏ :
|
|
|
|
* ▕ FWidget ▏ : *▕▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▏
|
|
|
|
* ▕▁▁▁▁▁▁▁▁▁▏ ├ - -▕ FCheckMenuItem ▏
|
|
|
|
* ▲ : ▕▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▏
|
|
|
|
* │ 1 :
|
|
|
|
* ▕▔▔▔▔▔▔▔▔▔▏ ▕▔▔▔▔▔▔▔▔▔▔▔▏- ┘ ▕▔▔▔▔▔▔▔▔▔▔▔▏
|
|
|
|
* ▕ FWindow ▏ ▕ FMenuList ▏- - - -▕ FMenuItem ▏
|
|
|
|
* ▕▁▁▁▁▁▁▁▁▁▏ ▕▁▁▁▁▁▁▁▁▁▁▁▏1 *▕▁▁▁▁▁▁▁▁▁▁▁▏
|
|
|
|
* ▲ ▲ 1:
|
|
|
|
* │ │ :
|
|
|
|
* └─────┬─────┘ :
|
|
|
|
* │ 1 :
|
|
|
|
* ▕▔▔▔▔▔▔▔▏- - - ┘ ▕▔▔▔▔▔▔▔▔▔▔▔▏
|
|
|
|
* ▕ FMenu ▏- - - - - - - -▕ FMenuItem ▏
|
|
|
|
* ▕▁▁▁▁▁▁▁▏1 1▕▁▁▁▁▁▁▁▁▁▁▁▏
|
|
|
|
*/
|
2015-08-16 20:05:39 +02:00
|
|
|
|
2017-04-09 20:08:53 +02:00
|
|
|
#ifndef FMENU_H
|
|
|
|
#define FMENU_H
|
2015-08-16 20:05:39 +02:00
|
|
|
|
2017-10-31 00:41:59 +01:00
|
|
|
#if !defined (USE_FINAL_H) && !defined (COMPILE_FINAL_CUT)
|
|
|
|
#error "Only <final/final.h> can be included directly."
|
|
|
|
#endif
|
|
|
|
|
2017-09-17 21:32:46 +02:00
|
|
|
#include "final/fwindow.h"
|
|
|
|
#include "final/fmenubar.h"
|
|
|
|
#include "final/fmenulist.h"
|
|
|
|
#include "final/fmenuitem.h"
|
2015-08-16 20:05:39 +02:00
|
|
|
|
2018-09-20 23:59:01 +02:00
|
|
|
namespace finalcut
|
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
|
2015-08-16 20:05:39 +02:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// class FMenu
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
#pragma pack(push)
|
|
|
|
#pragma pack(1)
|
|
|
|
|
|
|
|
class FMenu : public FWindow, public FMenuList
|
|
|
|
{
|
2017-09-11 03:06:02 +02:00
|
|
|
public:
|
|
|
|
// Constructor
|
|
|
|
explicit FMenu (FWidget* = 0);
|
|
|
|
FMenu (const FString&, FWidget* = 0);
|
|
|
|
|
|
|
|
// Destructor
|
|
|
|
virtual ~FMenu();
|
|
|
|
|
|
|
|
// Accessors
|
|
|
|
virtual const char* getClassName() const;
|
|
|
|
FString getText() const;
|
|
|
|
FMenuItem* getItem() const;
|
|
|
|
|
|
|
|
// Mutators
|
|
|
|
bool setEnable(bool);
|
|
|
|
bool setEnable();
|
|
|
|
bool unsetEnable();
|
|
|
|
bool setDisable();
|
|
|
|
void setSelected();
|
|
|
|
void unsetSelected();
|
|
|
|
bool setMenuWidget (bool);
|
|
|
|
bool setMenuWidget();
|
|
|
|
bool unsetMenuWidget();
|
|
|
|
void setStatusbarMessage (const FString&);
|
|
|
|
void setMenu (FMenu*);
|
|
|
|
void setText (const FString&);
|
|
|
|
|
|
|
|
// Inquiries
|
|
|
|
bool isEnabled() const;
|
|
|
|
bool isSelected() const;
|
|
|
|
bool hasHotkey() const;
|
|
|
|
bool hasMenu() const;
|
|
|
|
|
|
|
|
// Methods
|
|
|
|
void show();
|
|
|
|
void hide();
|
|
|
|
|
|
|
|
// Event handlers
|
|
|
|
void onKeyPress (FKeyEvent*);
|
|
|
|
void onMouseDown (FMouseEvent*);
|
|
|
|
void onMouseUp (FMouseEvent*);
|
|
|
|
void onMouseMove (FMouseEvent*);
|
|
|
|
void onAccel (FAccelEvent*);
|
|
|
|
|
|
|
|
// Callback method
|
|
|
|
void cb_menuitem_toggled (FWidget*, data_ptr);
|
|
|
|
|
|
|
|
private:
|
2017-12-10 15:36:02 +01:00
|
|
|
// Typedef
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
uChar focus_changed : 1;
|
|
|
|
uChar hide_sub_menu : 1;
|
|
|
|
uChar mouse_over_menu : 1;
|
|
|
|
uChar mouse_over_submenu : 1;
|
|
|
|
uChar mouse_over_supermenu : 1;
|
|
|
|
uChar mouse_over_menubar : 1;
|
|
|
|
uChar : 2; // padding bits
|
|
|
|
} mouseStates;
|
|
|
|
|
2017-12-19 02:06:27 +01:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
wchar_t* text;
|
|
|
|
int length;
|
|
|
|
int hotkeypos;
|
|
|
|
bool no_underline;
|
|
|
|
} menuText;
|
|
|
|
|
2017-12-10 15:36:02 +01:00
|
|
|
// Constants
|
|
|
|
static const bool SELECT_ITEM = true;
|
|
|
|
|
2017-09-11 03:06:02 +02:00
|
|
|
// Disable copy constructor
|
|
|
|
FMenu (const FMenu&);
|
|
|
|
|
|
|
|
// Disable assignment operator (=)
|
|
|
|
FMenu& operator = (const FMenu&);
|
|
|
|
|
|
|
|
// Accessors
|
|
|
|
FWidget* getSuperMenu() const;
|
|
|
|
|
|
|
|
// Mutators
|
|
|
|
void setSuperMenu (FWidget*);
|
|
|
|
|
|
|
|
// Inquiries
|
|
|
|
bool isWindowsMenu (FWidget*) const;
|
|
|
|
bool isMenuBar (FWidget*) const;
|
|
|
|
bool isMenu (FWidget*) const;
|
|
|
|
bool isRadioMenuItem (FWidget*) const;
|
|
|
|
bool isSubMenu() const;
|
2017-12-10 15:36:02 +01:00
|
|
|
bool isMouseOverMenu (const FPoint&);
|
2017-12-19 02:06:27 +01:00
|
|
|
bool isMouseOverSubMenu (const FPoint&);
|
2017-12-10 15:36:02 +01:00
|
|
|
bool isMouseOverSuperMenu (const FPoint&);
|
|
|
|
bool isMouseOverMenuBar (const FPoint&);
|
2017-09-11 03:06:02 +02:00
|
|
|
|
|
|
|
// Methods
|
|
|
|
void init(FWidget*);
|
|
|
|
void calculateDimensions();
|
|
|
|
void adjustItems();
|
|
|
|
int adjustX(int);
|
2017-12-10 15:36:02 +01:00
|
|
|
void openSubMenu (FMenu*, bool = false);
|
|
|
|
void closeOpenedSubMenu();
|
2017-09-11 03:06:02 +02:00
|
|
|
void hideSubMenus();
|
|
|
|
void hideSuperMenus();
|
2017-12-10 15:36:02 +01:00
|
|
|
bool mouseDownOverList (FPoint);
|
2018-02-24 18:13:42 +01:00
|
|
|
void mouseDownSubmenu (FMenuItem*);
|
|
|
|
void mouseDownSelection (FMenuItem*, bool&);
|
2017-12-10 15:36:02 +01:00
|
|
|
bool mouseUpOverList (FPoint);
|
2018-02-24 18:13:42 +01:00
|
|
|
void mouseMoveOverList (FPoint, mouseStates&);
|
|
|
|
void mouseMoveSelection (FMenuItem*, mouseStates&);
|
|
|
|
void mouseMoveDeselection (FMenuItem*, mouseStates&);
|
2017-12-10 15:36:02 +01:00
|
|
|
void mouseUpOverBorder();
|
|
|
|
void mouseMoveOverBorder (mouseStates&);
|
2018-02-24 18:13:42 +01:00
|
|
|
void passEventToSubMenu (FMouseEvent*&);
|
|
|
|
void passEventToSuperMenu (FMouseEvent*&);
|
|
|
|
void passEventToMenuBar (FMouseEvent*&);
|
2017-09-11 03:06:02 +02:00
|
|
|
bool containsMenuStructure (const FPoint&);
|
|
|
|
bool containsMenuStructure (int, int);
|
|
|
|
FMenu* superMenuAt (const FPoint&);
|
|
|
|
FMenu* superMenuAt (int, int);
|
|
|
|
bool selectNextItem();
|
|
|
|
bool selectPrevItem();
|
2017-12-27 01:38:28 +01:00
|
|
|
void keypressMenuBar (FKeyEvent*);
|
|
|
|
bool hotkeyMenu (FKeyEvent*);
|
2017-12-19 02:06:27 +01:00
|
|
|
int getHotkeyPos (wchar_t[], wchar_t[], uInt);
|
2017-09-11 03:06:02 +02:00
|
|
|
void draw();
|
|
|
|
void drawItems();
|
2017-12-21 00:25:58 +01:00
|
|
|
void drawSeparator (int);
|
2017-12-19 02:06:27 +01:00
|
|
|
void drawMenuLine (FMenuItem*, int);
|
|
|
|
void drawCheckMarkPrefix (FMenuItem*);
|
|
|
|
void drawMenuText (menuText&);
|
|
|
|
void drawSubMenuIndicator (int&);
|
|
|
|
void drawAcceleratorKey (int&, int);
|
|
|
|
void drawTrailingSpaces (int);
|
|
|
|
void setLineAttributes (FMenuItem*, int);
|
2017-12-25 21:17:08 +01:00
|
|
|
void setCursorToHotkeyPosition (FMenuItem*);
|
2017-12-27 01:38:28 +01:00
|
|
|
void keyUp();
|
|
|
|
void keyDown();
|
|
|
|
void keyLeft (FKeyEvent*);
|
|
|
|
void keyRight (FKeyEvent*);
|
|
|
|
void keyEnter();
|
|
|
|
void keyEscape();
|
2017-09-11 03:06:02 +02:00
|
|
|
void processActivate();
|
|
|
|
|
|
|
|
// Friend classes
|
|
|
|
friend class FApplication;
|
|
|
|
friend class FCheckMenuItem;
|
|
|
|
friend class FDialog;
|
|
|
|
friend class FMenuBar;
|
|
|
|
friend class FMenuItem;
|
|
|
|
friend class FRadioMenuItem;
|
|
|
|
|
|
|
|
// Data Members
|
|
|
|
FMenuItem* item;
|
|
|
|
FWidget* super_menu;
|
2017-12-10 15:36:02 +01:00
|
|
|
FMenu* opened_sub_menu;
|
|
|
|
FMenu* shown_sub_menu;
|
2017-09-11 03:06:02 +02:00
|
|
|
uInt max_item_width;
|
2017-12-25 21:17:08 +01:00
|
|
|
int hotkeypos;
|
2017-09-11 03:06:02 +02:00
|
|
|
bool mouse_down;
|
|
|
|
bool has_checkable_items;
|
2015-08-16 20:05:39 +02:00
|
|
|
};
|
|
|
|
#pragma pack(pop)
|
|
|
|
|
|
|
|
|
|
|
|
// FMenu inline functions
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline const char* FMenu::getClassName() const
|
|
|
|
{ return "FMenu"; }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2016-11-02 00:37:58 +01:00
|
|
|
inline FString FMenu::getText() const
|
|
|
|
{ return item->getText(); }
|
2015-08-16 20:05:39 +02:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline FMenuItem* FMenu::getItem() const
|
|
|
|
{ return item; }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
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
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline void FMenu::setSelected()
|
|
|
|
{ item->setSelected(); }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline void FMenu::unsetSelected()
|
|
|
|
{ item->unsetSelected(); }
|
|
|
|
|
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 void FMenu::setMenu (FMenu* m)
|
|
|
|
{ item->setMenu(m); }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2017-03-17 22:59:06 +01:00
|
|
|
inline void FMenu::setText (const FString& txt)
|
2015-08-16 20:05:39 +02:00
|
|
|
{ item->setText(txt); }
|
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline bool FMenu::isEnabled() const
|
|
|
|
{ return item->isEnabled(); }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline bool FMenu::isSelected() const
|
|
|
|
{ return item->isSelected(); }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline bool FMenu::hasHotkey() const
|
|
|
|
{ return item->hasHotkey(); }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline bool FMenu::hasMenu() const
|
|
|
|
{ return item->hasMenu(); }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline FWidget* FMenu::getSuperMenu() const
|
|
|
|
{ return super_menu; }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline void FMenu::setSuperMenu (FWidget* smenu)
|
|
|
|
{ super_menu = smenu; }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline bool FMenu::containsMenuStructure (const FPoint& p)
|
|
|
|
{ return containsMenuStructure (p.getX(), p.getY()); }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline FMenu* FMenu::superMenuAt (const FPoint& p)
|
|
|
|
{ return superMenuAt (p.getX(), p.getY()); }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline void FMenu::onAccel (FAccelEvent* ev)
|
|
|
|
{ item->onAccel(ev); }
|
|
|
|
|
2018-09-20 23:59:01 +02:00
|
|
|
} // namespace finalcut
|
2015-08-16 20:05:39 +02:00
|
|
|
|
2017-04-09 20:08:53 +02:00
|
|
|
#endif // FMENU_H
|