finalcut/src/include/final/fstatusbar.h

296 lines
9.8 KiB
C
Raw Normal View History

2017-11-04 07:03:53 +01:00
/***********************************************************************
* fstatusbar.h - Widget FStatusBar and FStatusKey *
* *
* This file is part of the Final Cut widget toolkit *
* *
* Copyright 2014-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
*
*
*
*
*
*
* FWindow
*
*
*
* 1 *
* FStatusBar - - - - FStatusKey
*
*/
2015-05-23 13:35:12 +02:00
#ifndef FSTATUSBAR_H
#define FSTATUSBAR_H
2015-05-23 13:35:12 +02:00
#if !defined (USE_FINAL_H) && !defined (COMPILE_FINAL_CUT)
#error "Only <final/final.h> can be included directly."
#endif
2017-09-11 03:06:02 +02:00
#include <vector>
#include "final/fwindow.h"
2015-05-23 13:35:12 +02:00
namespace finalcut
{
// class forward declaration
2015-05-23 13:35:12 +02:00
class FStatusBar;
//----------------------------------------------------------------------
// class FStatusKey
//----------------------------------------------------------------------
#pragma pack(push)
#pragma pack(1)
class FStatusKey : public FWidget
{
2017-09-11 03:06:02 +02:00
public:
// Constructors
explicit FStatusKey (FWidget* = nullptr);
FStatusKey (FKey, const FString&, FWidget* = nullptr);
// Disable copy constructor
FStatusKey (const FStatusKey&) = delete;
2017-09-11 03:06:02 +02:00
// Destructor
virtual ~FStatusKey();
// Disable assignment operator (=)
FStatusKey& operator = (const FStatusKey&) = delete;
2017-09-11 03:06:02 +02:00
// Accessors
virtual const char* getClassName() const;
2018-11-21 20:07:08 +01:00
virtual FKey getKey() const;
2017-09-11 03:06:02 +02:00
virtual FString getText() const;
// Mutators
2018-11-21 20:07:08 +01:00
void setKey (FKey);
void setText (const FString&);
2017-09-11 03:06:02 +02:00
void setActive();
void unsetActive();
bool setMouseFocus(bool);
bool setMouseFocus();
bool unsetMouseFocus();
// Inquiry
bool isActivated() const;
bool hasMouseFocus() const;
// Event handler
2018-09-24 04:02:35 +02:00
virtual void onAccel (FAccelEvent*);
2017-09-11 03:06:02 +02:00
private:
// Methods
void init (FWidget*);
void processActivate();
FStatusBar* getConnectedStatusbar() const;
void setConnectedStatusbar (FStatusBar*);
// Friend class
friend class FStatusBar;
// Data Members
FKey key{0};
FString text{};
bool active{false};
bool mouse_focus{false};
FStatusBar* bar{nullptr};
2015-05-23 13:35:12 +02:00
};
#pragma pack(pop)
// FStatusKey inline functions
//----------------------------------------------------------------------
inline const char* FStatusKey::getClassName() const
{ return "FStatusKey"; }
2015-05-23 13:35:12 +02:00
//----------------------------------------------------------------------
2018-11-21 20:07:08 +01:00
inline FKey FStatusKey::getKey() const
{ return key; }
//----------------------------------------------------------------------
inline FString FStatusKey::getText() const
{ return text; }
//----------------------------------------------------------------------
2018-11-21 20:07:08 +01:00
inline void FStatusKey::setKey (FKey k)
{ key = k; }
//----------------------------------------------------------------------
inline void FStatusKey::setText (const FString& txt)
{ text = txt; }
//----------------------------------------------------------------------
inline void FStatusKey::unsetActive()
{ active = false; }
2015-05-23 13:35:12 +02:00
//----------------------------------------------------------------------
inline bool FStatusKey::setMouseFocus()
{ return setMouseFocus(true); }
//----------------------------------------------------------------------
inline bool FStatusKey::unsetMouseFocus()
{ return setMouseFocus(false); }
//----------------------------------------------------------------------
inline bool FStatusKey::isActivated() const
{ return active; }
2015-05-23 13:35:12 +02:00
//----------------------------------------------------------------------
inline bool FStatusKey::hasMouseFocus() const
{ return mouse_focus; }
2015-05-23 13:35:12 +02:00
//----------------------------------------------------------------------
inline FStatusBar* FStatusKey::getConnectedStatusbar() const
{ return bar; }
//----------------------------------------------------------------------
inline void FStatusKey::setConnectedStatusbar (FStatusBar* sb)
{ bar = sb; }
2015-05-23 13:35:12 +02:00
//----------------------------------------------------------------------
// class FStatusBar
//----------------------------------------------------------------------
#pragma pack(push)
#pragma pack(1)
class FStatusBar : public FWindow
{
2017-09-11 03:06:02 +02:00
public:
// Constructor
explicit FStatusBar (FWidget* = nullptr);
// Disable copy constructor
FStatusBar (const FStatusBar&) = delete;
2017-09-11 03:06:02 +02:00
// Destructor
virtual ~FStatusBar();
// Disable assignment operator (=)
FStatusBar& operator = (const FStatusBar&) = delete;
2017-09-11 03:06:02 +02:00
// Accessors
virtual const char* getClassName() const;
FStatusKey* getStatusKey (int) const;
FString getMessage() const;
std::size_t getCount() const;
2017-09-11 03:06:02 +02:00
// Mutators
void activateKey (int);
void deactivateKey (int);
void setMessage (const FString&);
// Inquiries
bool isActivated (int) const;
bool hasActivatedKey();
// Methods
2018-09-24 04:02:35 +02:00
virtual void hide();
2017-09-11 03:06:02 +02:00
void drawMessage();
void clearMessage();
void insert (FStatusKey*);
void remove (FStatusKey*);
void remove (int);
void clear();
2018-09-24 04:02:35 +02:00
virtual void adjustSize();
2017-09-11 03:06:02 +02:00
// Event handlers
2018-09-24 04:02:35 +02:00
virtual void onMouseDown (FMouseEvent*);
virtual void onMouseUp (FMouseEvent*);
virtual void onMouseMove (FMouseEvent*);
2017-09-11 03:06:02 +02:00
// Callback method
void cb_statuskey_activated (FWidget*, data_ptr);
private:
// Typedef
typedef std::vector<FStatusKey*> keyList;
// Methods
void init();
2018-09-24 04:02:35 +02:00
virtual void draw();
2017-09-11 03:06:02 +02:00
void drawKeys();
void drawKey (keyList::const_iterator);
void drawActiveKey (keyList::const_iterator);
2017-09-11 03:06:02 +02:00
// Data Members
keyList key_list{};
FString text{""};
bool mouse_down{};
std::size_t screenWidth{80};
int keyname_len{0};
int x{-1};
int x_msg{-1};
2015-05-23 13:35:12 +02:00
};
#pragma pack(pop)
// FStatusBar inline functions
//----------------------------------------------------------------------
inline const char* FStatusBar::getClassName() const
{ return "FStatusBar"; }
//----------------------------------------------------------------------
inline FStatusKey* FStatusBar::getStatusKey (int index) const
2017-09-15 01:31:02 +02:00
{ return key_list[uInt(index - 1)]; }
2015-05-23 13:35:12 +02:00
//----------------------------------------------------------------------
inline std::size_t FStatusBar::getCount() const
{ return key_list.size(); }
2015-05-23 13:35:12 +02:00
//----------------------------------------------------------------------
inline void FStatusBar::activateKey (int index)
2017-09-15 01:31:02 +02:00
{ key_list[uInt(index - 1)]->setActive(); }
2015-05-23 13:35:12 +02:00
//----------------------------------------------------------------------
inline void FStatusBar::deactivateKey (int index)
2017-09-15 01:31:02 +02:00
{ key_list[uInt(index - 1)]->unsetActive(); }
2015-05-23 13:35:12 +02:00
//----------------------------------------------------------------------
inline bool FStatusBar::isActivated(int index) const
2017-09-15 01:31:02 +02:00
{ return key_list[uInt(index - 1)]->isActivated(); }
2015-05-23 13:35:12 +02:00
//----------------------------------------------------------------------
inline FString FStatusBar::getMessage() const
{ return text; }
//----------------------------------------------------------------------
inline void FStatusBar::clearMessage()
{ text.clear(); }
} // namespace finalcut
#endif // FSTATUSBAR_H