finalcut/src/include/final/fmenubar.h

177 lines
5.9 KiB
C
Raw Normal View History

2017-11-04 07:03:53 +01:00
/***********************************************************************
* fmenubar.h - Widget FMenuBar *
* *
* 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 *
* FWindow FMenuList - - - - FMenuItem
*
*
*
*
*
*
* FMenuBar
*
*/
#ifndef FMENUBAR_H
#define FMENUBAR_H
#if !defined (USE_FINAL_H) && !defined (COMPILE_FINAL_CUT)
#error "Only <final/final.h> can be included directly."
#endif
#include "final/fmenu.h"
#include "final/fmenulist.h"
#include "final/fwindow.h"
namespace finalcut
{
//----------------------------------------------------------------------
// class FMenuBar
//----------------------------------------------------------------------
#pragma pack(push)
#pragma pack(1)
class FMenuBar : public FWindow, public FMenuList
{
2017-09-11 03:06:02 +02:00
public:
// Constructor
explicit FMenuBar (FWidget* = 0);
// Destructor
virtual ~FMenuBar();
// Accessors
virtual const char* getClassName() const;
// Methods
2018-09-24 04:02:35 +02:00
void resetMenu();
virtual void hide();
virtual void adjustSize();
2017-09-11 03:06:02 +02:00
// Event handlers
2018-09-24 04:02:35 +02:00
virtual void onKeyPress (FKeyEvent*);
virtual void onMouseDown (FMouseEvent*);
virtual void onMouseUp (FMouseEvent*);
virtual void onMouseMove (FMouseEvent*);
virtual void onAccel (FAccelEvent*);
2017-09-11 03:06:02 +02:00
// Callback methods
2018-09-24 04:02:35 +02:00
void cb_item_deactivated (FWidget*, data_ptr);
2017-09-11 03:06:02 +02:00
private:
// Constants
static const std::size_t NOT_SET = static_cast<std::size_t>(-1);
2017-12-21 00:25:58 +01:00
// Typedef
typedef struct
{
wchar_t* text;
std::size_t length;
std::size_t startpos;
std::size_t hotkeypos;
2017-12-21 00:25:58 +01:00
bool no_underline;
} menuText;
2017-09-11 03:06:02 +02:00
// Disable copy constructor
FMenuBar (const FMenuBar&);
// Disable assignment operator (=)
2018-09-24 04:02:35 +02:00
FMenuBar& operator = (const FMenuBar&);
2017-09-11 03:06:02 +02:00
// Inquiry
2018-09-24 04:02:35 +02:00
bool isMenu (FMenuItem*) const;
2017-09-11 03:06:02 +02:00
// Methods
2018-09-24 04:02:35 +02:00
void init();
void calculateDimensions();
bool selectNextItem();
bool selectPrevItem();
bool hotkeyMenu (FKeyEvent*&);
std::size_t getHotkeyPos (wchar_t[], wchar_t[], std::size_t);
2018-09-24 04:02:35 +02:00
virtual void draw();
void drawItems();
void drawItem (FMenuItem*, std::size_t&);
2018-09-24 04:02:35 +02:00
void setLineAttributes (FMenuItem*);
void drawMenuText (menuText&);
void drawEllipsis (menuText&, std::size_t);
void drawLeadingSpace (std::size_t&);
void drawTrailingSpace (std::size_t&);
2018-09-24 04:02:35 +02:00
void adjustItems();
bool activateMenu (FMenuItem*);
bool clickItem (FMenuItem*);
void unselectMenuItem (FMenuItem*);
void selectMenuItem (FMenuItem*);
void mouseDownOverList (FMouseEvent*);
void mouseUpOverList (FMouseEvent*);
void mouseMoveOverList (FMouseEvent*);
void passEventToMenu (FMouseEvent*&);
void leaveMenuBar();
2017-09-11 03:06:02 +02:00
// Friend classes
friend class FMenu;
friend class FMenuItem;
// Data Members
bool mouse_down;
bool drop_down;
bool focus_changed;
std::size_t screenWidth;
};
#pragma pack(pop)
// FMenuBar inline functions
//----------------------------------------------------------------------
inline const char* FMenuBar::getClassName() const
{ return "FMenuBar"; }
//----------------------------------------------------------------------
inline bool FMenuBar::isMenu (FMenuItem* mi) const
{ return mi->hasMenu(); }
} // namespace finalcut
#endif // FMENUBAR_H