/*********************************************************************** * flineedit.h - Widget FLineEdit * * * * This file is part of the Final Cut widget toolkit * * * * Copyright 2012-2019 Markus Gans * * * * 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 * * . * ***********************************************************************/ /* Inheritance diagram * ═══════════════════ * * ▕▔▔▔▔▔▔▔▔▔▏ * ▕ FTerm ▏ * ▕▁▁▁▁▁▁▁▁▁▏ * ▲ * │ * ▕▔▔▔▔▔▔▔▔▔▏ ▕▔▔▔▔▔▔▔▔▔▏ * ▕ FVTerm ▏ ▕ FObject ▏ * ▕▁▁▁▁▁▁▁▁▁▏ ▕▁▁▁▁▁▁▁▁▁▏ * ▲ ▲ * │ │ * └─────┬─────┘ * │ * ▕▔▔▔▔▔▔▔▔▔▏ * ▕ FWidget ▏ * ▕▁▁▁▁▁▁▁▁▁▏ * ▲ * │ * ▕▔▔▔▔▔▔▔▔▔▔▔▏ * ▕ FLineEdit ▏ * ▕▁▁▁▁▁▁▁▁▁▁▁▏ */ #ifndef FLINEEDIT_H #define FLINEEDIT_H #if !defined (USE_FINAL_H) && !defined (COMPILE_FINAL_CUT) #error "Only can be included directly." #endif #include "final/fwidget.h" #include "final/flabel.h" namespace finalcut { //---------------------------------------------------------------------- // class FLineEdit //---------------------------------------------------------------------- #pragma pack(push) #pragma pack(1) class FLineEdit : public FWidget { public: // Enumeration enum label_o { label_above = 0, label_left = 1 }; // Constructor explicit FLineEdit (FWidget* = nullptr); explicit FLineEdit (const FString&, FWidget* = nullptr); // Disable copy constructor FLineEdit (const FLineEdit&) = delete; // 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&); // Accessors virtual const char* getClassName() const override; FString getText() const; std::size_t getMaxLength() const; std::size_t getCursorPosition() const; int getLabelOrientation(); // Mutators void setText (const FString&); void setInputFilter (const FString&); void clearInputFilter(); void setMaxLength (std::size_t); void setCursorPosition (std::size_t); void setLabelText (const FString&); void setLabelOrientation(const label_o); virtual bool setEnable(bool) override; virtual bool setEnable() override; virtual bool unsetEnable() override; virtual bool setDisable() override; virtual bool setFocus(bool) override; virtual bool setFocus() override; virtual bool unsetFocus() override; bool setShadow(bool); bool setShadow(); bool unsetShadow(); // Inquiry bool hasShadow(); // Methods virtual void hide() override; void clear(); // Event handlers virtual void onKeyPress (FKeyEvent*) override; virtual void onMouseDown (FMouseEvent*) override; virtual void onMouseUp (FMouseEvent*) override; virtual void onMouseMove (FMouseEvent*) override; virtual void onTimer (FTimerEvent*) override; virtual void onAccel (FAccelEvent*) override; virtual void onHide (FHideEvent*) override; virtual void onFocusIn (FFocusEvent*) override; virtual void onFocusOut (FFocusEvent*) override; protected: void adjustLabel(); virtual void adjustSize() override; private: // Enumeration enum dragScroll { noScroll = 0, scrollLeft = 1, scrollRight = 2 }; // Methods void init(); bool hasHotkey(); virtual void draw() override; void drawInputField(); void keyLeft(); void keyRight(); void keyHome(); void keyEnd(); void keyDel(); void keyBackspace(); void keyInsert(); void keyEnter(); bool keyInput (FKey); wchar_t characterFilter (const wchar_t); void processActivate(); void processChanged(); // Data Members FString text{""}; FString label_text{""}; FLabel* label{}; label_o label_orientation{FLineEdit::label_left}; std::wstring input_filter{}; dragScroll drag_scroll{FLineEdit::noScroll}; bool scroll_timer{false}; int scroll_repeat{100}; bool insert_mode{true}; std::size_t cursor_pos{0}; std::size_t text_offset{0}; std::size_t max_length{std::numeric_limits::max()}; }; #pragma pack(pop) // FLineEdit inline functions //---------------------------------------------------------------------- inline const char* FLineEdit::getClassName() const { return "FLineEdit"; } //---------------------------------------------------------------------- inline FString FLineEdit::getText() const { return text; } //---------------------------------------------------------------------- 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); } //---------------------------------------------------------------------- inline void FLineEdit::setInputFilter (const FString& regex_string) { input_filter = regex_string.wc_str(); } //---------------------------------------------------------------------- inline void FLineEdit::clearInputFilter() { input_filter.clear(); } //---------------------------------------------------------------------- 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 flags.shadow; } } // namespace finalcut #endif // FLINEEDIT_H