PCL
TextBox.h
Go to the documentation of this file.
1 // ____ ______ __
2 // / __ \ / ____// /
3 // / /_/ // / / /
4 // / ____// /___ / /___ PixInsight Class Library
5 // /_/ \____//_____/ PCL 2.7.0
6 // ----------------------------------------------------------------------------
7 // pcl/TextBox.h - Released 2024-06-18T15:48:54Z
8 // ----------------------------------------------------------------------------
9 // This file is part of the PixInsight Class Library (PCL).
10 // PCL is a multiplatform C++ framework for development of PixInsight modules.
11 //
12 // Copyright (c) 2003-2024 Pleiades Astrophoto S.L. All Rights Reserved.
13 //
14 // Redistribution and use in both source and binary forms, with or without
15 // modification, is permitted provided that the following conditions are met:
16 //
17 // 1. All redistributions of source code must retain the above copyright
18 // notice, this list of conditions and the following disclaimer.
19 //
20 // 2. All redistributions in binary form must reproduce the above copyright
21 // notice, this list of conditions and the following disclaimer in the
22 // documentation and/or other materials provided with the distribution.
23 //
24 // 3. Neither the names "PixInsight" and "Pleiades Astrophoto", nor the names
25 // of their contributors, may be used to endorse or promote products derived
26 // from this software without specific prior written permission. For written
27 // permission, please contact info@pixinsight.com.
28 //
29 // 4. All products derived from this software, in any form whatsoever, must
30 // reproduce the following acknowledgment in the end-user documentation
31 // and/or other materials provided with the product:
32 //
33 // "This product is based on software from the PixInsight project, developed
34 // by Pleiades Astrophoto and its contributors (https://pixinsight.com/)."
35 //
36 // Alternatively, if that is where third-party acknowledgments normally
37 // appear, this acknowledgment must be reproduced in the product itself.
38 //
39 // THIS SOFTWARE IS PROVIDED BY PLEIADES ASTROPHOTO AND ITS CONTRIBUTORS
40 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
41 // TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL PLEIADES ASTROPHOTO OR ITS
43 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
44 // EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, BUSINESS
45 // INTERRUPTION; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; AND LOSS OF USE,
46 // DATA OR PROFITS) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
47 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
49 // POSSIBILITY OF SUCH DAMAGE.
50 // ----------------------------------------------------------------------------
51 
52 #ifndef __PCL_TextBox_h
53 #define __PCL_TextBox_h
54 
56 
57 #ifndef __PCL_BUILDING_PIXINSIGHT_APPLICATION
58 
59 #include <pcl/Defs.h>
60 
61 #include <pcl/AutoPointer.h>
62 #include <pcl/Frame.h>
63 
64 namespace pcl
65 {
66 
67 // ----------------------------------------------------------------------------
68 
80 class PCL_CLASS TextBox : public Frame
81 {
82 public:
83 
88  TextBox( const String& text = String(), Control& parent = Control::Null() );
89 
93  ~TextBox() override
94  {
95  }
96 
100  String Text() const;
101 
105  void SetText( const String& );
106 
112  template <class S>
113  static S PlainText( const S& text )
114  {
115  return "<raw>" + text + "</raw>";
116  }
117 
123  template <class S>
124  void SetPlainText( const S& text )
125  {
126  SetText( PlainText( text ) );
127  }
128 
132  void Clear()
133  {
134  SetText( String() );
135  }
136 
142  bool IsReadOnly() const;
143 
149  void SetReadOnly( bool ro = true );
150 
159  void SetReadWrite( bool rw = true )
160  {
161  SetReadOnly( !rw );
162  }
163 
169  void SelectAll( bool = true );
170 
179  void Unselect( bool unsel = true )
180  {
181  SelectAll( !unsel );
182  }
183 
195  void GetSelection( int& selStart, int& selEnd ) const;
196 
208  void SetSelection( int selStart, int selEnd );
209 
213  bool HasSelection() const
214  {
215  int s0, s1;
216  GetSelection( s0, s1 );
217  return s0 != s1;
218  }
219 
227 
230  int CaretPosition() const;
231 
234  void SetCaretPosition( int );
235 
238  void Home()
239  {
240  SetCaretPosition( 0 );
241  }
242 
245  void End()
246  {
247  SetCaretPosition( int_max );
248  }
249 
252  void Insert( const String& text );
253 
256  void Delete();
257 
258  // -------------------------------------------------------------------------
259  // Event handlers
260  //
261  // void OnTextUpdated( TextBox& sender, const String& text );
262  // void OnCaretPositionUpdated( TextBox& sender, int oldPos, int newPos );
263  // void OnSelectionUpdated( TextBox& sender, int newStart, int newEnd );
264 
267  using unicode_event_handler = void (Control::*)( TextBox& sender, const String& );
268 
271  using caret_event_handler = void (Control::*)( TextBox& sender, int oldPos, int newPos );
272 
275  using selection_event_handler = void (Control::*)( TextBox& sender, int newStart, int newEnd );
276 
280 
284 
288 
289 private:
290 
291  struct EventHandlers
292  {
293  unicode_event_handler onTextUpdated = nullptr;
294  caret_event_handler onCaretPositionUpdated = nullptr;
295  selection_event_handler onSelectionUpdated = nullptr;
296 
297  EventHandlers() = default;
298  EventHandlers( const EventHandlers& ) = default;
299  EventHandlers& operator =( const EventHandlers& ) = default;
300  };
301 
302  AutoPointer<EventHandlers> m_handlers;
303 
304  friend class TextBoxEventDispatcher;
305 };
306 
307 // ----------------------------------------------------------------------------
308 
309 } // pcl
310 
311 #endif // __PCL_BUILDING_PIXINSIGHT_APPLICATION
312 
313 #endif // __PCL_TextBox_h
314 
315 // ----------------------------------------------------------------------------
316 // EOF pcl/TextBox.h - Released 2024-06-18T15:48:54Z
Client-side interface to a PixInsight Control object.
Definition: Control.h:126
static Control & Null()
Client-side interface to a PixInsight Frame control.
Definition: Frame.h:107
Unicode (UTF-16) string.
Definition: String.h:8113
Client-side interface to a PixInsight TextBox control.
Definition: TextBox.h:81
void SetText(const String &)
void(Control::*)(TextBox &sender, int newStart, int newEnd) selection_event_handler
Definition: TextBox.h:275
void SetReadOnly(bool ro=true)
void End()
Definition: TextBox.h:245
int CaretPosition() const
void OnCaretPositionUpdated(caret_event_handler, Control &)
void SetPlainText(const S &text)
Definition: TextBox.h:124
bool IsReadOnly() const
void(Control::*)(TextBox &sender, int oldPos, int newPos) caret_event_handler
Definition: TextBox.h:271
void GetSelection(int &selStart, int &selEnd) const
String SelectedText() const
void SetSelection(int selStart, int selEnd)
TextBox(const String &text=String(), Control &parent=Control::Null())
void SetReadWrite(bool rw=true)
Definition: TextBox.h:159
void Clear()
Definition: TextBox.h:132
void Unselect(bool unsel=true)
Definition: TextBox.h:179
~TextBox() override
Definition: TextBox.h:93
void OnTextUpdated(unicode_event_handler, Control &)
void SelectAll(bool=true)
void Insert(const String &text)
bool HasSelection() const
Definition: TextBox.h:213
void SetCaretPosition(int)
String Text() const
void OnSelectionUpdated(selection_event_handler, Control &)
void(Control::*)(TextBox &sender, const String &) unicode_event_handler
Definition: TextBox.h:267
void Home()
Definition: TextBox.h:238
PCL root namespace.
Definition: AbstractImage.h:77