ASPiK SDK
ctextedit.h
1 // This file is part of VSTGUI. It is subject to the license terms
2 // in the LICENSE file found in the top-level directory of this
3 // distribution and at http://github.com/steinbergmedia/vstgui/LICENSE
4 
5 #ifndef __ctextedit__
6 #define __ctextedit__
7 
8 #include "ctextlabel.h"
9 #include "../platform/iplatformtextedit.h"
10 #include <functional>
11 
12 namespace VSTGUI {
13 
14 using CTextEditStringToValueProc = bool (*) (UTF8StringPtr txt, float& result, void* userData);
15 
16 //-----------------------------------------------------------------------------
17 // CTextEdit Declaration
20 //-----------------------------------------------------------------------------
21 class CTextEdit : public CTextLabel, public IPlatformTextEditCallback
22 {
23 public:
25 
26  CTextEdit (const CRect& size, IControlListener* listener, int32_t tag, UTF8StringPtr txt = nullptr, CBitmap* background = nullptr, const int32_t style = 0);
27  CTextEdit (const CTextEdit& textEdit);
28 
29  //-----------------------------------------------------------------------------
31  //-----------------------------------------------------------------------------
34 
35  using StringToValueFunction = std::function<bool(UTF8StringPtr txt, float& result, CTextEdit* textEdit)>;
36 
37  void setStringToValueFunction (const StringToValueFunction& stringToValueFunc);
38  void setStringToValueFunction (StringToValueFunction&& stringToValueFunc);
39 
40  virtual void setImmediateTextChange (bool state);
41  bool getImmediateTextChange () const { return immediateTextChange; }
42 
43  void setSecureStyle (bool state);
44  bool getSecureStyle () const;
45 
46  virtual void setPlaceholderString (const UTF8String& str);
47  const UTF8String& getPlaceholderString () const { return placeholderString; }
49 
50  // overrides
51  void setText (const UTF8String& txt) override;
52  void valueChanged () override;
53  void setValue (float val) override;
54  void setTextRotation (double angle) override { return; }
55 
56  void draw (CDrawContext* pContext) override;
57  CMouseEventResult onMouseDown (CPoint& where, const CButtonState& buttons) override;
58  int32_t onKeyDown (VstKeyCode& keyCode) override;
59 
60  void takeFocus () override;
61  void looseFocus () override;
62  bool wantsFocus () const override;
63 
64  void setViewSize (const CRect& newSize, bool invalid = true) override;
65  void parentSizeChanged () override;
66 
67  bool bWasReturnPressed {false};
68 
69  PlatformTextEditPtr getPlatformTextEdit () const { return platformControl; }
70 
71  CLASS_METHODS(CTextEdit, CParamDisplay)
72 protected:
73  ~CTextEdit () noexcept override;
74 
75  void createPlatformTextEdit ();
76  void updateText (IPlatformTextEdit* pte);
77 
78  CColor platformGetBackColor () const override { return getBackColor (); }
79  CColor platformGetFontColor () const override { return getFontColor (); }
80  CFontRef platformGetFont () const override;
81  CHoriTxtAlign platformGetHoriTxtAlign () const override { return getHoriAlign (); }
82  const UTF8String& platformGetText () const override { return text; }
83  const UTF8String& platformGetPlaceholderText () const override { return placeholderString; }
84  CRect platformGetSize () const override;
85  CRect platformGetVisibleSize () const override;
86  CPoint platformGetTextInset () const override { return getTextInset (); }
87  void platformLooseFocus (bool returnPressed) override;
88  bool platformOnKeyDown (const VstKeyCode& key) override;
89  void platformTextDidChange () override;
90  bool platformIsSecureTextEdit () override;
91 
92  PlatformTextEditPtr platformControl;
93 
94  StringToValueFunction stringToValueFunction;
95 
96  bool immediateTextChange {false};
97  bool secureStyle {false};
98  mutable SharedPointer<CFontDesc> platformFont;
99  UTF8String placeholderString;
100 };
101 
102 } // namespace
103 
104 #endif
void setSecureStyle(bool state)
enable/disable secure style
Definition: ctextedit.cpp:79
bool getSecureStyle() const
get secure style
Definition: ctextedit.cpp:92
void draw(CDrawContext *pContext) override
called if the view should draw itself
Definition: ctextedit.cpp:165
bool wantsFocus() const override
check if view supports focus
Definition: ctextedit.cpp:333
Rect structure.
Definition: crect.h:17
a text label
Definition: ctextlabel.h:18
Definition: xmlparse.c:181
Definition: vstkeycode.h:12
A drawing context encapsulates the drawing context of the underlying OS.
Definition: cdrawcontext.h:29
CMouseEventResult onMouseDown(CPoint &where, const CButtonState &buttons) override
called when a mouse down event occurs
Definition: ctextedit.cpp:198
CTextEdit(const CRect &size, IControlListener *listener, int32_t tag, UTF8StringPtr txt=nullptr, CBitmap *background=nullptr, const int32_t style=0)
Definition: ctextedit.cpp:31
void setTextRotation(double angle) override
not supported
Definition: ctextedit.h:54
bool getImmediateTextChange() const
get immediate text change behaviour
Definition: ctextedit.h:41
virtual void setImmediateTextChange(bool state)
enable/disable immediate text change behaviour.
Definition: ctextedit.cpp:73
Encapsulates various platform depended kinds of bitmaps.
Definition: cbitmap.h:21
Definition: customcontrols.cpp:8
Button and Modifier state.
Definition: cbuttonstate.h:34
void looseFocus() override
called if view should loose focus
Definition: ctextedit.cpp:353
void takeFocus() override
called if view should take focus
Definition: ctextedit.cpp:341
int32_t onKeyDown(VstKeyCode &keyCode) override
called if a key down event occurs and this view has focus
Definition: ctextedit.cpp:218
void valueChanged() override
notifies listener and dependent objects
Definition: ctextedit.cpp:150
holds an UTF8 encoded string and a platform representation of it
Definition: cstring.h:56
void setViewSize(const CRect &newSize, bool invalid=true) override
set views size
Definition: ctextedit.cpp:315
virtual void invalid()
mark whole view as invalid
Definition: cview.h:63
void parentSizeChanged() override
notification that one of the views parent has changed its size
Definition: ctextedit.cpp:308
void setText(const UTF8String &txt) override
set text
Definition: ctextedit.cpp:125
Point structure.
Definition: cpoint.h:17
a text edit control
Definition: ctextedit.h:21
Definition: icontrollistener.h:14