PCL
Edit.h
Go to the documentation of this file.
1 // ____ ______ __
2 // / __ \ / ____// /
3 // / /_/ // / / /
4 // / ____// /___ / /___ PixInsight Class Library
5 // /_/ \____//_____/ PCL 2.7.0
6 // ----------------------------------------------------------------------------
7 // pcl/Edit.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_Edit_h
53 #define __PCL_Edit_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 
75 class PCL_CLASS Edit : public Frame
76 {
77 public:
78 
83  Edit( const String& text = String(), Control& parent = Control::Null() );
84 
88  ~Edit() override
89  {
90  }
91 
95  String Text() const;
96 
100  void SetText( const String& );
101 
105  void Clear()
106  {
107  SetText( String() );
108  }
109 
113  bool IsReadOnly() const;
114 
118  void SetReadOnly( bool = true );
119 
126  void SetReadWrite( bool rw = true )
127  {
128  SetReadOnly( !rw );
129  }
130 
134  bool IsModified() const;
135 
139  void SetModified( bool = true );
140 
147  void ClearModified( bool clear = true )
148  {
149  SetModified( !clear );
150  }
151 
161  bool IsPasswordMode() const;
162 
168  void EnablePasswordMode( bool = true );
169 
178  void DisablePasswordMode( bool disable = true )
179  {
180  EnablePasswordMode( !disable );
181  }
182 
191 
203  String ValidatingRegExp( bool& caseSensitive ) const;
204 
234  void SetValidatingRegExp( const String& rx, bool caseSensitive = true );
235 
246  {
247  SetValidatingRegExp( String() );
248  }
249 
259  bool IsValid() const;
260 
264  int MaxLength() const;
265 
272  void SetMaxLength( int );
273 
281  {
282  SetMaxLength( int_max );
283  }
284 
288  void SelectAll( bool = true );
289 
296  void Unselect( bool unsel = true )
297  {
298  SelectAll( !unsel );
299  }
300 
310  void GetSelection( int& selStart, int& selEnd ) const;
311 
321  void SetSelection( int selStart, int selEnd );
322 
327  bool HasSelection() const
328  {
329  int s0, s1;
330  GetSelection( s0, s1 );
331  return s0 != s1;
332  }
333 
339 
343  int CaretPosition() const;
344 
348  void SetCaretPosition( int );
349 
353  void Home()
354  {
355  SetCaretPosition( 0 );
356  }
357 
361  void End()
362  {
363  SetCaretPosition( int_max );
364  }
365 
369  bool IsRightAligned() const;
370 
374  bool IsLeftAligned() const
375  {
376  return !IsRightAligned();
377  }
378 
382  void SetRightAlignment( bool right = true );
383 
390  void SetLeftAlignment( bool left = true )
391  {
392  SetRightAlignment( !left );
393  }
394 
395  // -------------------------------------------------------------------------
396  // Event handlers
397  //
398  // void OnEditCompleted( Edit& sender );
399  // void OnReturnPressed( Edit& sender );
400  // void OnTextUpdated( Edit& sender, const String& text );
401  // void OnCaretPositionUpdated( Edit& sender, int oldPos, int newPos );
402  // void OnSelectionUpdated( Edit& sender, int newStart, int newEnd );
403 
406  using edit_event_handler = void (Control::*)( Edit& sender );
407 
410  using text_event_handler = void (Control::*)( Edit& sender, const String& );
411 
414  using caret_event_handler = void (Control::*)( Edit& sender, int oldPos, int newPos );
415 
418  using selection_event_handler = void (Control::*)( Edit& sender, int newStart, int newEnd );
419 
423 
427 
431 
435 
439 
440 private:
441 
442  struct EventHandlers
443  {
444  edit_event_handler onEditCompleted = nullptr;
445  edit_event_handler onReturnPressed = nullptr;
446  text_event_handler onTextUpdated = nullptr;
447  caret_event_handler onCaretPositionUpdated = nullptr;
448  selection_event_handler onSelectionUpdated = nullptr;
449 
450  EventHandlers() = default;
451  EventHandlers( const EventHandlers& ) = default;
452  EventHandlers& operator =( const EventHandlers& ) = default;
453  };
454 
455  AutoPointer<EventHandlers> m_handlers;
456 
457  friend class EditEventDispatcher;
458 };
459 
460 // ----------------------------------------------------------------------------
461 
462 } // pcl
463 
464 #endif // __PCL_BUILDING_PIXINSIGHT_APPLICATION
465 
466 #endif // __PCL_Edit_h
467 
468 // ----------------------------------------------------------------------------
469 // EOF pcl/Edit.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 Edit control.
Definition: Edit.h:76
bool IsValid() const
void SetReadWrite(bool rw=true)
Definition: Edit.h:126
void(Control::*)(Edit &sender) edit_event_handler
Definition: Edit.h:406
void SetMaxLength(int)
void EnablePasswordMode(bool=true)
void SetModified(bool=true)
bool IsModified() const
void DisableValidatingRegExp()
Definition: Edit.h:245
void ClearModified(bool clear=true)
Definition: Edit.h:147
bool IsLeftAligned() const
Definition: Edit.h:374
void Clear()
Definition: Edit.h:105
Edit(const String &text=String(), Control &parent=Control::Null())
void SetCaretPosition(int)
void SetReadOnly(bool=true)
String SelectedText() const
String ValidatingRegExp(bool &caseSensitive) const
void SetLeftAlignment(bool left=true)
Definition: Edit.h:390
bool HasSelection() const
Definition: Edit.h:327
void Home()
Definition: Edit.h:353
void End()
Definition: Edit.h:361
bool IsRightAligned() const
void(Control::*)(Edit &sender, int oldPos, int newPos) caret_event_handler
Definition: Edit.h:414
bool IsReadOnly() const
void SelectAll(bool=true)
void OnCaretPositionUpdated(caret_event_handler, Control &)
void OnSelectionUpdated(selection_event_handler, Control &)
int CaretPosition() const
void(Control::*)(Edit &sender, int newStart, int newEnd) selection_event_handler
Definition: Edit.h:418
~Edit() override
Definition: Edit.h:88
String Text() const
void Unselect(bool unsel=true)
Definition: Edit.h:296
void SetRightAlignment(bool right=true)
void(Control::*)(Edit &sender, const String &) text_event_handler
Definition: Edit.h:410
void GetSelection(int &selStart, int &selEnd) const
void SetSelection(int selStart, int selEnd)
void OnTextUpdated(text_event_handler, Control &)
void DisablePasswordMode(bool disable=true)
Definition: Edit.h:178
void SetText(const String &)
void OnEditCompleted(edit_event_handler, Control &)
void SetUnlimitedLength()
Definition: Edit.h:280
void SetValidatingRegExp(const String &rx, bool caseSensitive=true)
String ValidatingRegExp() const
bool IsPasswordMode() const
void OnReturnPressed(edit_event_handler, Control &)
int MaxLength() const
Client-side interface to a PixInsight Frame control.
Definition: Frame.h:107
Unicode (UTF-16) string.
Definition: String.h:8113
PCL root namespace.
Definition: AbstractImage.h:77