finalcut/src/include/final/flineedit.h

296 lines
10 KiB
C
Raw Normal View History

2017-11-04 07:03:53 +01:00
/***********************************************************************
* flineedit.h - Widget FLineEdit *
* *
* This file is part of the Final Cut widget toolkit *
* *
2019-02-24 00:25:36 +01:00
* Copyright 2012-2019 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
*
*
*
*
* FLineEdit
*
*/
2015-05-23 13:35:12 +02:00
#ifndef FLINEEDIT_H
#define FLINEEDIT_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
2019-08-06 23:45:28 +02:00
#include <limits>
2019-10-05 23:20:07 +02:00
#include <utility>
#include "final/fwidget.h"
2015-05-23 13:35:12 +02:00
namespace finalcut
{
// class forward declaration
class FLabel;
2015-05-23 13:35:12 +02:00
//----------------------------------------------------------------------
// class FLineEdit
//----------------------------------------------------------------------
class FLineEdit : public FWidget
{
2017-09-11 03:06:02 +02:00
public:
// Enumerations
2017-09-11 03:06:02 +02:00
enum label_o
{
label_above = 0,
label_left = 1
};
enum inputType
{
textfield = 0,
password = 1
2017-09-11 03:06:02 +02:00
};
// Using-declaration
using FWidget::setGeometry;
2017-09-11 03:06:02 +02:00
// Constructor
explicit FLineEdit (FWidget* = nullptr);
explicit FLineEdit (const FString&, FWidget* = nullptr);
// Disable copy constructor
FLineEdit (const FLineEdit&) = delete;
2017-09-11 03:06:02 +02:00
// Destructor
virtual ~FLineEdit();
// Disable assignment operator (=)
FLineEdit& operator = (const FLineEdit&) = delete;
// Overloaded operators
FLineEdit& operator = (const FString&);
FLineEdit& operator << (const FString&);
FLineEdit& operator << (fc::SpecialCharacter);
FLineEdit& operator << (const wchar_t);
FLineEdit& operator << (const uInt);
FLineEdit& operator << (const int);
FLineEdit& operator << (const uLong);
FLineEdit& operator << (const long);
FLineEdit& operator << (const float);
FLineEdit& operator << (const double);
FLineEdit& operator << (const lDouble);
const FLineEdit& operator >> (FString&);
2017-09-11 03:06:02 +02:00
// Accessors
2019-10-05 23:20:07 +02:00
const FString getClassName() const override;
2018-12-31 06:18:39 +01:00
FString getText() const;
2019-02-24 00:25:36 +01:00
std::size_t getMaxLength() const;
std::size_t getCursorPosition() const;
2018-12-31 06:18:39 +01:00
int getLabelOrientation();
2017-09-11 03:06:02 +02:00
// Mutators
2018-12-31 06:18:39 +01:00
void setText (const FString&);
2019-02-24 00:25:36 +01:00
void setInputFilter (const FString&);
void clearInputFilter();
void setMaxLength (std::size_t);
void setCursorPosition (std::size_t);
2018-12-31 06:18:39 +01:00
void setLabelText (const FString&);
void setInputType (const inputType);
void setLabelOrientation (const label_o);
2019-08-06 23:45:28 +02:00
void setGeometry ( const FPoint&, const FSize&
, bool = true ) override;
2019-08-06 23:45:28 +02:00
bool setEnable(bool) override;
bool setEnable() override;
bool unsetEnable() override;
bool setDisable() override;
bool setFocus(bool) override;
bool setFocus() override;
bool unsetFocus() override;
2018-12-31 06:18:39 +01:00
bool setShadow(bool);
bool setShadow();
bool unsetShadow();
2017-09-11 03:06:02 +02:00
// Inquiry
2018-12-31 06:18:39 +01:00
bool hasShadow();
2017-09-11 03:06:02 +02:00
// Methods
2019-08-06 23:45:28 +02:00
void hide() override;
2018-12-31 06:18:39 +01:00
void clear();
2017-09-11 03:06:02 +02:00
// Event handlers
2019-08-06 23:45:28 +02:00
void onKeyPress (FKeyEvent*) override;
void onMouseDown (FMouseEvent*) override;
void onMouseUp (FMouseEvent*) override;
void onMouseMove (FMouseEvent*) override;
void onTimer (FTimerEvent*) override;
void onAccel (FAccelEvent*) override;
void onHide (FHideEvent*) override;
void onFocusIn (FFocusEvent*) override;
void onFocusOut (FFocusEvent*) override;
2017-09-11 03:06:02 +02:00
protected:
2018-12-31 06:18:39 +01:00
void adjustLabel();
2019-08-06 23:45:28 +02:00
void adjustSize() override;
2017-09-11 03:06:02 +02:00
private:
// Typedef
typedef std::pair<std::size_t, std::size_t> offsetPair;
2017-09-11 03:06:02 +02:00
// Enumeration
enum dragScroll
{
noScroll = 0,
scrollLeft = 1,
scrollRight = 2
};
// Constants
static constexpr std::size_t NOT_SET = static_cast<std::size_t>(-1);
2017-09-11 03:06:02 +02:00
// Methods
2018-12-31 06:18:39 +01:00
void init();
bool hasHotkey();
2019-08-06 23:45:28 +02:00
void draw() override;
2018-12-31 06:18:39 +01:00
void drawInputField();
std::size_t printTextField();
std::size_t printPassword();
std::size_t getCursorColumnPos();
const FString getPasswordText() const;
bool isPasswordField() const;
offsetPair endPosToOffset (std::size_t);
std::size_t clickPosToCursorPos (std::size_t);
void adjustTextOffset();
void cursorLeft();
void cursorRight();
void cursorHome();
void cursorEnd();
void deleteCurrentCharacter();
void deletePreviousCharacter();
void switchInsertMode();
void acceptInput();
2018-12-31 06:18:39 +01:00
bool keyInput (FKey);
2019-02-24 00:25:36 +01:00
wchar_t characterFilter (const wchar_t);
2018-12-31 06:18:39 +01:00
void processActivate();
void processChanged();
2017-09-11 03:06:02 +02:00
// Data members
FString text{""};
FString print_text{""};
FString label_text{""};
FLabel* label{};
2019-02-24 00:25:36 +01:00
std::wstring input_filter{};
dragScroll drag_scroll{FLineEdit::noScroll};
2019-09-08 02:04:24 +02:00
label_o label_orientation{FLineEdit::label_left};
inputType input_type{FLineEdit::textfield};
int scroll_repeat{100};
2019-09-08 02:04:24 +02:00
bool scroll_timer{false};
bool insert_mode{true};
std::size_t cursor_pos{NOT_SET};
std::size_t text_offset{0};
std::size_t char_width_offset{0};
std::size_t x_pos{0};
2019-02-24 00:25:36 +01:00
std::size_t max_length{std::numeric_limits<std::size_t>::max()};
2015-05-23 13:35:12 +02:00
};
// FLineEdit inline functions
//----------------------------------------------------------------------
2019-10-05 23:20:07 +02:00
inline const FString FLineEdit::getClassName() const
2015-05-23 13:35:12 +02:00
{ return "FLineEdit"; }
//----------------------------------------------------------------------
inline FString FLineEdit::getText() const
{ return text; }
2019-02-24 00:25:36 +01:00
//----------------------------------------------------------------------
inline std::size_t FLineEdit::getMaxLength() const
{ return max_length; }
//----------------------------------------------------------------------
inline std::size_t FLineEdit::getCursorPosition() const
{ return cursor_pos; }
//----------------------------------------------------------------------
inline int FLineEdit::getLabelOrientation()
{ return int(label_orientation); }
2019-02-24 00:25:36 +01:00
//----------------------------------------------------------------------
inline void FLineEdit::setInputFilter (const FString& regex_string)
{ input_filter = regex_string.wc_str(); }
//----------------------------------------------------------------------
inline void FLineEdit::clearInputFilter()
{ input_filter.clear(); }
//----------------------------------------------------------------------
inline void FLineEdit::setInputType (const inputType type)
{ input_type = type; }
2015-05-23 13:35:12 +02:00
//----------------------------------------------------------------------
inline bool FLineEdit::setEnable()
{ return setEnable(true); }
//----------------------------------------------------------------------
inline bool FLineEdit::unsetEnable()
{ return setEnable(false); }
//----------------------------------------------------------------------
inline bool FLineEdit::setDisable()
{ return setEnable(false); }
//----------------------------------------------------------------------
inline bool FLineEdit::setFocus()
{ return setFocus(true); }
//----------------------------------------------------------------------
inline bool FLineEdit::unsetFocus()
{ return setFocus(false); }
//----------------------------------------------------------------------
inline bool FLineEdit::setShadow()
{ return setShadow(true); }
//----------------------------------------------------------------------
inline bool FLineEdit::unsetShadow()
{ return setShadow(false); }
//----------------------------------------------------------------------
inline bool FLineEdit::hasShadow()
{ return getFlags().shadow; }
2015-05-23 13:35:12 +02:00
} // namespace finalcut
#endif // FLINEEDIT_H