finalcut/src/include/final/fbutton.h

285 lines
9.3 KiB
C
Raw Normal View History

2017-11-04 07:03:53 +01:00
/***********************************************************************
* fbutton.h - Widget FButton *
* *
* This file is part of the Final Cut widget toolkit *
* *
* Copyright 2012-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
*
*
*
*
* FButton
*
*/
2015-05-23 13:35:12 +02:00
#ifndef FBUTTON_H
#define FBUTTON_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
#include "final/fwidget.h"
2015-05-23 13:35:12 +02:00
namespace finalcut
{
2015-05-23 13:35:12 +02:00
//----------------------------------------------------------------------
// class FButton
//----------------------------------------------------------------------
#pragma pack(push)
#pragma pack(1)
class FButton : public FWidget
{
2017-09-11 03:06:02 +02:00
public:
// Constructors
explicit FButton (FWidget* = 0);
FButton (const FString&, FWidget* = 0);
// Destructor
virtual ~FButton();
// Accessors
const char* getClassName() const;
FString& getText();
// Mutators
void setForegroundColor (short);
void setBackgroundColor (short);
void setHotkeyForegroundColor (short);
void setFocusForegroundColor (short);
void setFocusBackgroundColor (short);
void setInactiveForegroundColor (short);
void setInactiveBackgroundColor (short);
bool setNoUnderline(bool);
bool setNoUnderline();
bool unsetNoUnderline();
2018-09-24 04:02:35 +02:00
virtual bool setEnable(bool);
virtual bool setEnable();
virtual bool unsetEnable();
virtual bool setDisable();
virtual bool setFocus(bool);
virtual bool setFocus();
virtual bool unsetFocus();
2017-09-11 03:06:02 +02:00
bool setFlat(bool);
bool setFlat();
bool unsetFlat();
bool setShadow(bool);
bool setShadow();
bool unsetShadow();
bool setDown(bool);
bool setDown();
bool setUp();
bool setClickAnimation(bool);
bool setClickAnimation();
bool unsetClickAnimation();
void setText (const FString&);
// Inquiries
bool isFlat() const;
bool isDown() const;
bool hasShadow() const;
bool hasClickAnimation();
// Methods
2018-09-24 04:02:35 +02:00
virtual void hide();
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 onTimer (FTimerEvent*);
virtual void onAccel (FAccelEvent*);
virtual void onFocusIn (FFocusEvent*);
virtual void onFocusOut (FFocusEvent*);
2017-09-11 03:06:02 +02:00
private:
// Constants
static const std::size_t NOT_FOUND = static_cast<std::size_t>(-1);
2017-09-11 03:06:02 +02:00
// Disable copy constructor
FButton (const FButton&);
// Disable assignment operator (=)
FButton& operator = (const FButton&);
// Methods
void init();
void getButtonState();
2017-09-11 03:06:02 +02:00
uChar getHotkey();
void setHotkeyAccelerator();
void detectHotkey();
std::size_t getHotkeyPos (wchar_t[], wchar_t[], std::size_t);
std::size_t clickAnimationIndent (FWidget*);
void clearRightMargin (FWidget*);
void drawMarginLeft();
void drawMarginRight();
void drawTopBottomBackground();
void drawButtonTextLine (wchar_t[]);
2018-09-24 04:02:35 +02:00
virtual void draw();
void updateStatusBar();
2017-09-11 03:06:02 +02:00
void updateButtonColor();
void processClick();
// Data Members
FString text;
bool button_down;
bool click_animation;
int click_time;
int space_char;
std::size_t hotkeypos;
std::size_t indent;
std::size_t center_offset;
std::size_t vcenter_offset;
std::size_t txtlength;
2017-09-11 03:06:02 +02:00
short button_fg;
short button_bg;
short button_hotkey_fg;
short button_focus_fg;
short button_focus_bg;
short button_inactive_fg;
short button_inactive_bg;
struct state
{
uChar focus : 1;
uChar active_focus : 1;
uChar active : 1;
uChar flat : 1;
uChar non_flat_shadow : 1;
uChar no_underline : 1;
uChar : 2; // padding bits
} is;
2015-05-23 13:35:12 +02:00
};
#pragma pack(pop)
// FButton inline functions
//----------------------------------------------------------------------
inline const char* FButton::getClassName() const
{ return "FButton"; }
//----------------------------------------------------------------------
inline FString& FButton::getText()
{ return text; }
2015-05-23 13:35:12 +02:00
//----------------------------------------------------------------------
inline bool FButton::setNoUnderline()
{ return setNoUnderline(true); }
//----------------------------------------------------------------------
inline bool FButton::unsetNoUnderline()
{ return setNoUnderline(false); }
//----------------------------------------------------------------------
inline bool FButton::setEnable()
{ return setEnable(true); }
//----------------------------------------------------------------------
inline bool FButton::unsetEnable()
{ return setEnable(false); }
//----------------------------------------------------------------------
inline bool FButton::setDisable()
{ return setEnable(false); }
//----------------------------------------------------------------------
inline bool FButton::setFocus()
{ return setFocus(true); }
//----------------------------------------------------------------------
inline bool FButton::unsetFocus()
{ return setFocus(false); }
//----------------------------------------------------------------------
inline bool FButton::setFlat()
{ return setFlat(true); }
//----------------------------------------------------------------------
inline bool FButton::unsetFlat()
{ return setFlat(false); }
//----------------------------------------------------------------------
inline bool FButton::setShadow()
{ return setShadow(true); }
//----------------------------------------------------------------------
inline bool FButton::unsetShadow()
{ return setShadow(false); }
//----------------------------------------------------------------------
inline bool FButton::setDown()
{ return setDown(true); }
//----------------------------------------------------------------------
inline bool FButton::setUp()
{ return setDown(false); }
//----------------------------------------------------------------------
inline bool FButton::setClickAnimation(bool on)
{ return click_animation = on; }
//----------------------------------------------------------------------
inline bool FButton::setClickAnimation()
{ return setClickAnimation(true); }
//----------------------------------------------------------------------
inline bool FButton::unsetClickAnimation()
{ return setClickAnimation(false); }
//----------------------------------------------------------------------
inline bool FButton::isFlat() const
{ return ((flags & fc::flat) != 0); }
2015-05-23 13:35:12 +02:00
//----------------------------------------------------------------------
inline bool FButton::isDown() const
{ return button_down; }
//----------------------------------------------------------------------
inline bool FButton::hasShadow() const
{ return ((flags & fc::shadow) != 0); }
//----------------------------------------------------------------------
inline bool FButton::hasClickAnimation()
{ return click_animation; }
2015-05-23 13:35:12 +02:00
} // namespace finalcut
#endif // FBUTTON_H