PCL
ComboBox.h
Go to the documentation of this file.
1 // ____ ______ __
2 // / __ \ / ____// /
3 // / /_/ // / / /
4 // / ____// /___ / /___ PixInsight Class Library
5 // /_/ \____//_____/ PCL 2.7.0
6 // ----------------------------------------------------------------------------
7 // pcl/ComboBox.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_ComboBox_h
53 #define __PCL_ComboBox_h
54 
56 
57 #ifndef __PCL_BUILDING_PIXINSIGHT_APPLICATION
58 
59 #include <pcl/Defs.h>
60 
61 #include <pcl/AutoPointer.h>
62 #include <pcl/Bitmap.h>
63 #include <pcl/Control.h>
64 
65 namespace pcl
66 {
67 
68 // ----------------------------------------------------------------------------
69 
76 class PCL_CLASS ComboBox : public Control
77 {
78 public:
79 
83  ComboBox( Control& parent = Control::Null() );
84 
88  ~ComboBox() override
89  {
90  }
91 
95  int NumberOfItems() const;
96 
101  int CurrentItem() const;
102 
106  void SetCurrentItem( int index );
107 
121  int FindItem( const String& text, int fromIdx = 0, bool exactMatch = false, bool caseSensitive = false ) const;
122 
136  void InsertItem( int index, const String& text, const Bitmap& icon = Bitmap::Null() );
137 
144  void AddItem( const String& text, const Bitmap& icon = Bitmap::Null() )
145  {
146  InsertItem( NumberOfItems(), text, icon );
147  }
148 
162  template <class FI>
163  void InsertItems( int index, FI i, FI j )
164  {
165  if ( i != j )
166  {
167  DisableUpdates();
168  do
169  InsertItem( index++, *i );
170  while ( ++i != j );
171  EnableUpdates();
172  Update();
173  }
174  }
175 
182  template <class FI>
183  void AddItems( FI i, FI j )
184  {
185  InsertItems( NumberOfItems(), i, j );
186  }
187 
203  template <class C>
204  void InsertItems( int index, const C& c )
205  {
206  InsertItems( index, c.Begin(), c.End() );
207  }
208 
218  template <class C>
219  void AddItems( const C& c )
220  {
221  InsertItems( NumberOfItems(), c );
222  }
223 
229  void RemoveItem( int index );
230 
234  void Clear();
235 
239  String ItemText( int index ) const;
240 
244  void SetItemText( int index, const String& );
245 
249  void ClearItemText( int index )
250  {
251  SetItemText( index, String() );
252  }
253 
257  Bitmap ItemIcon( int index ) const;
258 
263  void SetItemIcon( int index, const Bitmap& );
264 
271  void ClearItemIcon( int index )
272  {
273  SetItemIcon( index, Bitmap::Null() );
274  }
275 
280  bool IsEditEnabled() const;
281 
285  void EnableEdit( bool = true );
286 
293  void DisableEdit( bool disable = true )
294  {
295  EnableEdit( !disable );
296  }
297 
301  String EditText() const;
302 
306  void SetEditText( const String& );
307 
312  {
313  SetEditText( String() );
314  }
315 
321 
325  void EnableAutoCompletion( bool = true );
326 
333  void DisableAutoCompletion( bool disable = true )
334  {
335  EnableAutoCompletion( !disable );
336  }
337 
343  void GetIconSize( int& width, int& height ) const;
344 
348  int IconWidth() const
349  {
350  int w, dum; GetIconSize( w, dum ); return w;
351  }
352 
356  int IconHeight() const
357  {
358  int dum, h; GetIconSize( dum, h ); return h;
359  }
360 
364  void SetIconSize( int width, int height );
365 
372  void SetIconSize( int size )
373  {
374  SetIconSize( size, size );
375  }
376 
379  void GetScaledIconSize( int& width, int& height ) const
380  {
381  GetIconSize( width, height ); width = PhysicalPixelsToLogical( width ); height = PhysicalPixelsToLogical( height );
382  }
383 
386  int ScaledIconWidth() const
387  {
388  int width, dum; GetIconSize( width, dum ); return PhysicalPixelsToLogical( width );
389  }
390 
393  int ScaledIconHeight() const
394  {
395  int dum, height; GetIconSize( dum, height ); return PhysicalPixelsToLogical( height );
396  }
397 
400  void SetScaledIconSize( int width, int height )
401  {
402  SetIconSize( LogicalPixelsToPhysical( width ), LogicalPixelsToPhysical( height ) );
403  }
404 
407  void SetScaledIconSize( int size )
408  {
409  size = LogicalPixelsToPhysical( size );
410  SetIconSize( size, size );
411  }
412 
417  int MaxVisibleItemCount() const;
418 
425 
430  int MinItemCharWidth() const;
431 
437  void SetMinItemCharWidth( int );
438 
439  //
440  // Drop-down items list
441  //
442 
448  void ShowList();
449 
454  void HideList();
455 
456  // -------------------------------------------------------------------------
457  // Event handlers
458  //
459  // void OnItemSelected( ComboBox& sender, int itemIndex );
460  // void OnItemHighlighted( ComboBox& sender, int itemIndex );
461  // void OnEditTextUpdated( ComboBox& sender );
462 
481  using item_event_handler = void (Control::*)( ComboBox& sender, int itemIndex );
482 
493  using edit_event_handler = void (Control::*)( ComboBox& sender );
494 
508  void OnItemSelected( item_event_handler handler, Control& receiver );
509 
523  void OnItemHighlighted( item_event_handler handler, Control& receiver );
524 
538  void OnEditTextUpdated( edit_event_handler handler, Control& receiver );
539 
540 private:
541 
542  struct EventHandlers
543  {
544  item_event_handler onItemSelected = nullptr;
545  item_event_handler onItemHighlighted = nullptr;
546  edit_event_handler onEditTextUpdated = nullptr;
547 
548  EventHandlers() = default;
549  EventHandlers( const EventHandlers& ) = default;
550  EventHandlers& operator =( const EventHandlers& ) = default;
551  };
552 
553  AutoPointer<EventHandlers> m_handlers;
554 
555  friend class ComboBoxEventDispatcher;
556 };
557 
558 // ----------------------------------------------------------------------------
559 
560 } // pcl
561 
562 #endif // __PCL_BUILDING_PIXINSIGHT_APPLICATION
563 
564 #endif // __PCL_ComboBox_h
565 
566 // ----------------------------------------------------------------------------
567 // EOF pcl/ComboBox.h - Released 2024-06-18T15:48:54Z
Client-side interface to a PixInsight Bitmap object.
Definition: Bitmap.h:204
static Bitmap & Null()
Client-side interface to a PixInsight ComboBox control.
Definition: ComboBox.h:77
~ComboBox() override
Definition: ComboBox.h:88
int NumberOfItems() const
void EnableAutoCompletion(bool=true)
int IconWidth() const
Definition: ComboBox.h:348
int MaxVisibleItemCount() const
void SetIconSize(int width, int height)
void DisableAutoCompletion(bool disable=true)
Definition: ComboBox.h:333
void ClearItemIcon(int index)
Definition: ComboBox.h:271
int ScaledIconWidth() const
Definition: ComboBox.h:386
void SetScaledIconSize(int width, int height)
Definition: ComboBox.h:400
String EditText() const
int CurrentItem() const
void InsertItems(int index, FI i, FI j)
Definition: ComboBox.h:163
ComboBox(Control &parent=Control::Null())
void EnableEdit(bool=true)
void InsertItem(int index, const String &text, const Bitmap &icon=Bitmap::Null())
int IconHeight() const
Definition: ComboBox.h:356
void GetIconSize(int &width, int &height) const
bool IsEditEnabled() const
void RemoveItem(int index)
void DisableEdit(bool disable=true)
Definition: ComboBox.h:293
void AddItem(const String &text, const Bitmap &icon=Bitmap::Null())
Definition: ComboBox.h:144
void SetScaledIconSize(int size)
Definition: ComboBox.h:407
void SetMaxVisibleItemCount(int)
void InsertItems(int index, const C &c)
Definition: ComboBox.h:204
int FindItem(const String &text, int fromIdx=0, bool exactMatch=false, bool caseSensitive=false) const
void SetItemIcon(int index, const Bitmap &)
void SetEditText(const String &)
void SetIconSize(int size)
Definition: ComboBox.h:372
void SetItemText(int index, const String &)
void AddItems(const C &c)
Definition: ComboBox.h:219
Bitmap ItemIcon(int index) const
void SetMinItemCharWidth(int)
bool IsAutoCompletionEnabled() const
String ItemText(int index) const
void AddItems(FI i, FI j)
Definition: ComboBox.h:183
void GetScaledIconSize(int &width, int &height) const
Definition: ComboBox.h:379
int ScaledIconHeight() const
Definition: ComboBox.h:393
void ClearItemText(int index)
Definition: ComboBox.h:249
void SetCurrentItem(int index)
void ClearEditText()
Definition: ComboBox.h:311
int MinItemCharWidth() const
Client-side interface to a PixInsight Control object.
Definition: Control.h:126
static Control & Null()
Unicode (UTF-16) string.
Definition: String.h:8113
void OnItemHighlighted(item_event_handler handler, Control &receiver)
void(Control::*)(ComboBox &sender, int itemIndex) item_event_handler
Definition: ComboBox.h:481
void OnItemSelected(item_event_handler handler, Control &receiver)
void(Control::*)(ComboBox &sender) edit_event_handler
Definition: ComboBox.h:493
void OnEditTextUpdated(edit_event_handler handler, Control &receiver)
PCL root namespace.
Definition: AbstractImage.h:77