finalcut/src/include/final/fmenuitem.h

279 lines
8.8 KiB
C
Raw Normal View History

2017-11-04 07:03:53 +01:00
/***********************************************************************
* fmenuitem.h - Widget FMenuItem *
* *
* This file is part of the Final Cut widget toolkit *
* *
* 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/>. *
***********************************************************************/
/* Inheritance diagram
*
*
*
* FTerm
*
*
*
*
* FVTerm FObject
*
*
*
*
*
*
* FWidget
*
*
*
* * 1
* FMenuItem -- - - - FMenu
* :
* :
* : 1
* - - - - FMenuList
*
*/
#ifndef FMENUITEM_H
#define FMENUITEM_H
#if !defined (USE_FINAL_H) && !defined (COMPILE_FINAL_CUT)
#error "Only <final/final.h> can be included directly."
#endif
#include "final/fwidget.h"
namespace finalcut
{
// class forward declaration
class FDialog;
2015-08-16 20:05:39 +02:00
class FMenu;
class FMenuList;
//----------------------------------------------------------------------
// class FMenuItem
//----------------------------------------------------------------------
#pragma pack(push)
#pragma pack(1)
class FMenuItem : public FWidget
{
2017-09-11 03:06:02 +02:00
public:
// Using-declarations
using FWidget::addAccelerator;
using FWidget::delAccelerator;
using FWidget::setEnable;
// Constructor
explicit FMenuItem (FWidget* = 0);
FMenuItem (const FString&, FWidget* = 0);
FMenuItem (int, const FString&, FWidget* = 0);
// Destructor
virtual ~FMenuItem();
// Accessors
2018-09-24 04:02:35 +02:00
const char* getClassName() const;
int getHotkey() const;
FMenu* getMenu() const;
uInt getTextLength() const;
FString getText() const;
2017-09-11 03:06:02 +02:00
// Mutators
2018-09-24 04:02:35 +02:00
virtual bool setEnable (bool);
virtual bool setFocus (bool);
virtual bool setFocus();
virtual bool unsetFocus();
void setSelected();
void unsetSelected();
void setSeparator();
void unsetSeparator();
void setChecked();
void unsetChecked();
void setMenu (FMenu*);
void setText (const FString&);
2017-09-11 03:06:02 +02:00
// Inquiries
2018-09-24 04:02:35 +02:00
bool isSelected() const;
bool isSeparator() const;
bool isChecked() const;
bool hasHotkey() const;
bool hasMenu() const;
2017-09-11 03:06:02 +02:00
// Methods
2018-09-24 04:02:35 +02:00
virtual void addAccelerator (int, FWidget*);
virtual void delAccelerator (FWidget*);
void openMenu();
2017-09-11 03:06:02 +02:00
// Event handlers
2018-09-24 04:02:35 +02:00
virtual void onKeyPress (FKeyEvent*);
virtual void onMouseDoubleClick (FMouseEvent*);
virtual void onMouseDown (FMouseEvent*);
virtual void onMouseUp (FMouseEvent*);
virtual void onMouseMove (FMouseEvent*);
virtual void onAccel (FAccelEvent*);
virtual void onFocusIn (FFocusEvent*);
virtual void onFocusOut (FFocusEvent*);
2017-09-11 03:06:02 +02:00
protected:
// Accessor
2018-09-24 04:02:35 +02:00
FWidget* getSuperMenu() const;
2017-09-11 03:06:02 +02:00
// Mutator
2018-09-24 04:02:35 +02:00
void setSuperMenu (FWidget*);
2017-09-11 03:06:02 +02:00
// Inquiries
2018-09-24 04:02:35 +02:00
bool isWindowsMenu (FWidget*) const;
bool isMenuBar (FWidget*) const;
bool isMenu (FWidget*) const;
2017-09-11 03:06:02 +02:00
// Data Members
2018-09-24 04:02:35 +02:00
FString text;
bool selected;
bool separator;
bool checkable;
bool checked;
bool radio_button;
bool dialog_index;
uInt text_length;
int hotkey;
int accel_key;
FMenu* menu;
FWidget* super_menu;
FDialog* associated_window;
2017-09-11 03:06:02 +02:00
private:
// Disable copy constructor
FMenuItem (const FMenuItem&);
// Disable assignment operator (=)
FMenuItem& operator = (const FMenuItem&);
// Methods
2018-09-24 04:02:35 +02:00
void init (FWidget*);
uChar hotKey();
void processActivate();
void processDeactivate();
void createDialogList (FMenu*);
template<class T>
2018-09-24 04:02:35 +02:00
void passMouseEvent (T, FMouseEvent*, fc::events);
2017-09-11 03:06:02 +02:00
// Callback methods
2018-09-24 04:02:35 +02:00
void cb_switchToDialog (FWidget*, data_ptr);
void cb_destroyDialog (FWidget*, data_ptr);
2017-09-11 03:06:02 +02:00
virtual void processClicked();
// Friend classes
friend class FDialogListMenu;
friend class FMenuList;
friend class FMenuBar;
friend class FMenu;
};
#pragma pack(pop)
// FMenuItem inline functions
//----------------------------------------------------------------------
inline const char* FMenuItem::getClassName() const
{ return "FMenuItem"; }
2015-10-19 00:07:07 +02:00
//----------------------------------------------------------------------
inline int FMenuItem::getHotkey() const
{ return hotkey; }
2015-10-19 00:07:07 +02:00
//----------------------------------------------------------------------
inline FMenu* FMenuItem::getMenu() const
{ return menu; }
//----------------------------------------------------------------------
inline uInt FMenuItem::getTextLength() const
{ return text_length; }
//----------------------------------------------------------------------
inline FString FMenuItem::getText() const
{ return text; }
2015-10-19 00:07:07 +02:00
2015-08-16 20:05:39 +02:00
//----------------------------------------------------------------------
2015-10-29 21:10:50 +01:00
inline bool FMenuItem::setFocus()
{ return setFocus(true); }
//----------------------------------------------------------------------
2015-10-29 21:10:50 +01:00
inline bool FMenuItem::unsetFocus()
{ return setFocus(false); }
//----------------------------------------------------------------------
inline void FMenuItem::setSeparator()
2015-11-07 23:16:09 +01:00
{
separator = true;
unsetFocusable();
}
//----------------------------------------------------------------------
inline void FMenuItem::unsetSeparator()
2015-11-07 23:16:09 +01:00
{
separator = false;
setFocusable();
}
//----------------------------------------------------------------------
inline void FMenuItem::setChecked()
2015-09-22 04:18:20 +02:00
{ checked = true; }
//----------------------------------------------------------------------
inline void FMenuItem::unsetChecked()
2015-09-22 04:18:20 +02:00
{ checked = false; }
//----------------------------------------------------------------------
inline void FMenuItem::setMenu(FMenu* m)
{ menu = m; }
//----------------------------------------------------------------------
inline bool FMenuItem::isSelected() const
{ return selected; }
//----------------------------------------------------------------------
inline bool FMenuItem::isSeparator() const
{ return separator; }
2015-09-28 04:31:29 +02:00
//----------------------------------------------------------------------
inline bool FMenuItem::isChecked() const
{ return checked; }
2015-09-28 04:31:29 +02:00
//----------------------------------------------------------------------
inline bool FMenuItem::hasHotkey() const
{ return bool(hotkey != 0); }
//----------------------------------------------------------------------
2015-08-16 20:05:39 +02:00
inline bool FMenuItem::hasMenu() const
{ return bool(menu != 0); }
2015-09-28 04:31:29 +02:00
//----------------------------------------------------------------------
inline FWidget* FMenuItem::getSuperMenu() const
{ return super_menu; }
//----------------------------------------------------------------------
inline void FMenuItem::setSuperMenu (FWidget* smenu)
{ super_menu = smenu; }
} // namespace finalcut
#endif // FMENUITEM_H