PCL
TreeBox.h
Go to the documentation of this file.
1 // ____ ______ __
2 // / __ \ / ____// /
3 // / /_/ // / / /
4 // / ____// /___ / /___ PixInsight Class Library
5 // /_/ \____//_____/ PCL 2.7.0
6 // ----------------------------------------------------------------------------
7 // pcl/TreeBox.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_TreeBox_h
53 #define __PCL_TreeBox_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/Font.h>
64 #include <pcl/IndirectArray.h>
65 #include <pcl/ScrollBox.h>
66 #include <pcl/SortedArray.h>
67 #include <pcl/TextAlign.h>
68 
69 namespace pcl
70 {
71 
72 // ----------------------------------------------------------------------------
73 
80 class PCL_CLASS TreeBox : public ScrollBox
81 {
82 public:
83 
90  class PCL_CLASS Node : public UIObject
91  {
92  public:
93 
97  Node();
98 
99  /*
100  * ### N.B.: If we define a default parameter value index=-1 for the
101  * following constructor (as expected), the static member function Null()
102  * cannot be compiled with g++ 4.9.x. The compiler issues the error:
103  *
104  * no matching function for call to
105  * 'pcl::TreeBox::Node::Node(pcl::TreeBox::Node)'
106  *
107  * which is obviously incorrect and looks like an obscure compiler bug.
108  * Note that the same problem exists with g++ 4.8.x (at least).
109  */
114  Node( Node& parent, int index );
115 
122  Node( TreeBox& parent, int index = -1 );
123 
127  ~Node() override;
128 
131  static Node Null()
132  {
133  // ### See note above for Node::Node( Node&, int ).
134  return Node( nullptr );
135  }
136 
139  const TreeBox& ParentTree() const;
140 
144 
147  const Node* Parent() const;
148 
152 
155  int NumberOfChildren() const;
156 
159  const Node* Child( int idx ) const;
160 
163  Node* Child( int idx );
164 
167  const Node* operator []( int idx ) const
168  {
169  return Child( idx );
170  }
171 
174  Node* operator []( int idx )
175  {
176  return Child( idx );
177  }
178 
181  int ChildIndex( const Node* ) const;
182 
185  void Insert( int idx, Node* );
186 
189  void Add( Node* node )
190  {
191  Insert( NumberOfChildren(), node );
192  }
193 
196  void Remove( int idx );
197 
200  bool IsEnabled() const;
201 
204  void Enable( bool = true );
205 
208  void Disable( bool disable = true )
209  {
210  Enable( !disable );
211  }
212 
215  bool IsExpanded() const;
216 
219  bool IsCollapsed() const
220  {
221  return !IsExpanded();
222  }
223 
226  void Expand( bool expand = true );
227 
230  void Collapse( bool collapse = true )
231  {
232  Expand( !collapse );
233  }
234 
237  bool IsSelectable() const;
238 
241  void SetSelectable( bool = true );
242 
245  bool IsSelected() const;
246 
249  void Select( bool = true );
250 
253  void Unselect( bool unselect = true )
254  {
255  Select( !unselect );
256  }
257 
260  bool IsCheckable() const;
261 
264  void SetCheckable( bool = true );
265 
268  bool IsChecked() const;
269 
272  void Check( bool = true );
273 
276  void Uncheck( bool uncheck = true )
277  {
278  Check( !uncheck );
279  }
280 
283  String Text( int col ) const;
284 
287  void SetText( int col, const String& );
288 
291  Bitmap Icon( int col ) const;
292 
295  void SetIcon( int col, const Bitmap& );
296 
299  int Alignment( int col ) const;
300 
303  void SetAlignment( int col, int align );
304 
307  String ToolTip( int col ) const;
308 
311  void SetToolTip( int col, const String& );
312 
315  pcl::Font Font( int col ) const;
316 
319  void SetFont( int col, const pcl::Font& );
320 
323  RGBA BackgroundColor( int col ) const;
324 
327  void SetBackgroundColor( int col, RGBA );
328 
331  RGBA TextColor( int col ) const;
332 
335  void SetTextColor( int col, RGBA );
336 
337  protected:
338 
342  Node( void* h )
343  : UIObject( h )
344  {
345  }
346 
350  Node( std::nullptr_t )
351  : UIObject( nullptr )
352  {
353  }
354 
358  void* CloneHandle() const override;
359 
360  private:
361 
362  using child_node_list = SortedArray<Node*>;
363  child_node_list m_children;
364  bool m_removed = false;
365 
366  friend class TreeBox;
367  };
368 
369  // -------------------------------------------------------------------------
370 
374  TreeBox( Control& parent = Control::Null() );
375 
379  ~TreeBox() override;
380 
383  static TreeBox& NullTree();
384 
385  //
386 
389  int NumberOfChildren() const;
390 
393  const Node* Child( int idx ) const;
394 
397  Node* Child( int idx );
398 
401  const Node* operator []( int idx ) const
402  {
403  return Child( idx );
404  }
405 
408  Node* operator []( int idx )
409  {
410  return Child( idx );
411  }
412 
415  int ChildIndex( const Node* ) const;
416 
419  void Insert( int idx, Node* );
420 
423  void Add( Node* n )
424  {
425  Insert( NumberOfChildren(), n );
426  }
427 
430  void Remove( int idx );
431 
434  void Clear();
435 
436  //
437 
440  const Node* CurrentNode() const;
441 
445 
449 
450  //
451 
455 
459  {
460  return !AreMultipleSelectionsEnabled();
461  }
462 
465  void EnableMultipleSelections( bool enable = true );
466 
469  void DisableMultipleSelections( bool disable = true )
470  {
471  EnableMultipleSelections( !disable );
472  }
473 
482 
487 
493 
494  //
495 
498  const Node* NodeByPosition( const pcl::Point& p ) const
499  {
500  return NodeByPosition( p.x, p.y ); // in client coordinates
501  }
502 
506  {
507  return NodeByPosition( p.x, p.y );
508  }
509 
512  const Node* NodeByPosition( int x, int y ) const;
513 
516  Node* NodeByPosition( int x, int y );
517 
521 
524  pcl::Rect NodeRect( const Node* ) const;
525 
526  //
527 
530  int NumberOfColumns() const;
531 
534  void SetNumberOfColumns( int nCols );
535 
536  // Visibility
537 
540  bool IsColumnVisible( int col ) const;
541 
544  void ShowColumn( int col, bool show = true );
545 
548  void HideColumn( int col, bool hide = true )
549  {
550  ShowColumn( col, !hide );
551  }
552 
553  //
554 
557  int ColumnWidth( int col ) const;
558 
561  void SetColumnWidth( int col, int width );
562 
565  int ScaledColumnWidth( int col ) const
566  {
567  return PhysicalPixelsToLogical( ColumnWidth( col ) );
568  }
569 
572  void SetScaledColumnWidth( int col, int width )
573  {
574  SetColumnWidth( col, LogicalPixelsToPhysical( width ) );
575  }
576 
580 
581  //
582 
585  String HeaderText( int col ) const;
586 
589  void SetHeaderText( int col, const String& );
590 
591  //
592 
595  Bitmap HeaderIcon( int col ) const;
596 
599  void SetHeaderIcon( int col, const Bitmap& );
600 
601  //
602 
605  int HeaderAlignment( int col ) const;
606 
609  void SetHeaderAlignment( int col, int align );
610 
613  bool IsHeaderVisible() const;
614 
617  void ShowHeader( bool show = true );
618 
621  void HideHeader( bool hide = true )
622  {
623  ShowHeader( !hide );
624  }
625 
626  //
627 
630  int IndentSize() const;
631 
634  void SetIndentSize( int );
635 
638  int ScaledIndentSize() const
639  {
640  return PhysicalPixelsToLogical( IndentSize() );
641  }
642 
645  void SetScaledIndentSize( int size )
646  {
647  SetIndentSize( LogicalPixelsToPhysical( size ) );
648  }
649 
650  //
651 
655 
658  void EnableNodeExpansion( bool = true );
659 
662  void DisableNodeExpansion( bool disable = true )
663  {
664  EnableNodeExpansion( !disable );
665  }
666 
667  //
668 
672 
675  void EnableRootDecoration( bool = true );
676 
679  void DisableRootDecoration( bool disable = true )
680  {
681  EnableRootDecoration( !disable );
682  }
683 
684  // Alternating row colors
685  // Even row color is Control::CanvasColor()
686  // Odd row color is Control::AlternateCanvasColor()
687 
691 
694  void EnableAlternateRowColor( bool = true );
695 
698  void DisableAlternateRowColor( bool disable = true )
699  {
700  EnableAlternateRowColor( !disable );
701  }
702 
703  //
704 
708 
711  void EnableUniformRowHeight( bool = true );
712 
715  void DisableUniformRowHeight( bool disable = true )
716  {
717  EnableUniformRowHeight( !disable );
718  }
719 
720  //
721 
724  void GetIconSize( int& width, int& height ) const;
725 
728  int IconWidth() const
729  {
730  int w, dum; GetIconSize( w, dum ); return w;
731  }
732 
735  int IconHeight() const
736  {
737  int dum, h; GetIconSize( dum, h ); return h;
738  }
739 
742  void SetIconSize( int width, int height );
743 
746  void SetIconSize( int size )
747  {
748  SetIconSize( size, size );
749  }
750 
753  void GetScaledIconSize( int& width, int& height ) const
754  {
755  GetIconSize( width, height ); width = PhysicalPixelsToLogical( width ); height = PhysicalPixelsToLogical( height );
756  }
757 
760  int ScaledIconWidth() const
761  {
762  int width, dum; GetIconSize( width, dum ); return PhysicalPixelsToLogical( width );
763  }
764 
767  int ScaledIconHeight() const
768  {
769  int dum, height; GetIconSize( dum, height ); return PhysicalPixelsToLogical( height );
770  }
771 
774  void SetScaledIconSize( int width, int height )
775  {
776  SetIconSize( LogicalPixelsToPhysical( width ), LogicalPixelsToPhysical( height ) );
777  }
778 
781  void SetScaledIconSize( int size )
782  {
783  size = LogicalPixelsToPhysical( size );
784  SetIconSize( size, size );
785  }
786 
787  //
788 
792 
795  void EnableHeaderSorting( bool = true );
796 
799  void DisableHeaderSorting( bool disable = true )
800  {
801  EnableHeaderSorting( !disable );
802  }
803 
806  void Sort( int col = 0, bool ascending = true );
807 
808  //
809 
812  bool IsNodeDraggingEnabled() const;
813 
816  void EnableNodeDragging( bool = true );
817 
820  void DisableNodeDragging( bool disable = true )
821  {
822  EnableNodeDragging( !disable );
823  }
824 
825  // -------------------------------------------------------------------------
826  // Event handlers
827  //
828  // void OnCurrentNodeUpdated( TreeBox& sender, TreeBox::Node& current, TreeBox::Node& oldCurrent );
829  // void OnNodeActivated( TreeBox& sender, TreeBox::Node& node, int col );
830  // void OnNodeUpdated( TreeBox& sender, TreeBox::Node& node, int col );
831  // void OnNodeEntered( TreeBox& sender, TreeBox::Node& node, int col );
832  // void OnNodeClicked( TreeBox& sender, TreeBox::Node& node, int col );
833  // void OnNodeDoubleClicked( TreeBox& sender, TreeBox::Node& node, int col );
834  // void OnNodeExpanded( TreeBox& sender, TreeBox::Node& node );
835  // void OnNodeCollapsed( TreeBox& sender, TreeBox::Node& node );
836  // void OnNodeSelectionUpdated( TreeBox& sender );
837 
845  using tree_event_handler = void (Control::*)( TreeBox& );
846 
850  using node_event_handler = void (Control::*)( TreeBox&, TreeBox::Node&, int );
851 
856 
861 
866 
871 
876 
881 
886 
891 
896 
901 
906 
907 private:
908 
909  struct EventHandlers
910  {
911  node_navigation_event_handler onCurrentNodeUpdated = nullptr;
912  node_event_handler onNodeActivated = nullptr;
913  node_event_handler onNodeUpdated = nullptr;
914  node_event_handler onNodeEntered = nullptr;
915  node_event_handler onNodeClicked = nullptr;
916  node_event_handler onNodeDoubleClicked = nullptr;
917  node_expand_event_handler onNodeExpanded = nullptr;
918  node_expand_event_handler onNodeCollapsed = nullptr;
919  tree_event_handler onNodeSelectionUpdated = nullptr;
920 
921  EventHandlers() = default;
922  EventHandlers( const EventHandlers& ) = default;
923  EventHandlers& operator =( const EventHandlers& ) = default;
924  };
925 
926  AutoPointer<EventHandlers> m_handlers;
927 
928  using child_node_list = SortedArray<Node*>;
929  child_node_list m_children;
930 
931  static pcl::Font FontFromHandle( void* h )
932  {
933  return pcl::Font( h );
934  }
935 
936  static const void* HandleFromFont( const pcl::Font& f )
937  {
938  return f.handle;
939  }
940 
941  static Bitmap BitmapFromHandle( void* h )
942  {
943  return Bitmap( h );
944  }
945 
946  static const void* HandleFromBitmap( const Bitmap& p )
947  {
948  return p.handle;
949  }
950 
951 protected:
952 
956  TreeBox( void* );
957 
958  friend class Node;
959  friend class TreeBoxEventDispatcher;
960 };
961 
962 // ----------------------------------------------------------------------------
963 
964 } // pcl
965 
966 #endif // __PCL_BUILDING_PIXINSIGHT_APPLICATION
967 
968 #endif // __PCL_TreeBox_h
969 
970 // ----------------------------------------------------------------------------
971 // EOF pcl/TreeBox.h - Released 2024-06-18T15:48:54Z
Client-side interface to a PixInsight Bitmap object.
Definition: Bitmap.h:204
Client-side interface to a PixInsight Control object.
Definition: Control.h:126
static Control & Null()
Client-side interface to a PixInsight Font object.
Definition: Font.h:207
A generic point in the two-dimensional space.
Definition: Point.h:100
component x
Abscissa (horizontal, or X-axis coordinate).
Definition: Point.h:111
component y
Ordinate (vertical, or Y-axis coordinate).
Definition: Point.h:112
A generic rectangle in the two-dimensional space.
Definition: Rectangle.h:314
Generic dynamic array of pointers to objects.
Definition: IndirectArray.h:92
Client-side interface to a PixInsight ScrollBox control.
Definition: ScrollBox.h:76
Unicode (UTF-16) string.
Definition: String.h:8113
Client-side interface to a PixInsight TreeBox node.
Definition: TreeBox.h:91
void Select(bool=true)
RGBA BackgroundColor(int col) const
static Node Null()
Definition: TreeBox.h:131
void Remove(int idx)
bool IsChecked() const
Node(TreeBox &parent, int index=-1)
void Disable(bool disable=true)
Definition: TreeBox.h:208
void Collapse(bool collapse=true)
Definition: TreeBox.h:230
bool IsCheckable() const
RGBA TextColor(int col) const
void SetCheckable(bool=true)
const TreeBox & ParentTree() const
Node * Child(int idx)
int Alignment(int col) const
void SetFont(int col, const pcl::Font &)
pcl::Font Font(int col) const
void Unselect(bool unselect=true)
Definition: TreeBox.h:253
bool IsEnabled() const
void SetBackgroundColor(int col, RGBA)
TreeBox & ParentTree()
void SetAlignment(int col, int align)
Node(Node &parent, int index)
void Check(bool=true)
void Expand(bool expand=true)
void Add(Node *node)
Definition: TreeBox.h:189
Bitmap Icon(int col) const
int NumberOfChildren() const
void Insert(int idx, Node *)
const Node * Child(int idx) const
bool IsSelected() const
void Uncheck(bool uncheck=true)
Definition: TreeBox.h:276
int ChildIndex(const Node *) const
void Enable(bool=true)
void SetText(int col, const String &)
const Node * Parent() const
void SetSelectable(bool=true)
bool IsExpanded() const
void SetIcon(int col, const Bitmap &)
String Text(int col) const
bool IsSelectable() const
String ToolTip(int col) const
void SetToolTip(int col, const String &)
bool IsCollapsed() const
Definition: TreeBox.h:219
void SetTextColor(int col, RGBA)
Client-side interface to a PixInsight TreeBox control.
Definition: TreeBox.h:81
int ScaledColumnWidth(int col) const
Definition: TreeBox.h:565
void SetHeaderText(int col, const String &)
void EnableRootDecoration(bool=true)
void SetIndentSize(int)
void Remove(int idx)
void EnableNodeExpansion(bool=true)
void DisableMultipleSelections(bool disable=true)
Definition: TreeBox.h:469
void SetNumberOfColumns(int nCols)
~TreeBox() override
bool IsUniformRowHeightEnabled() const
bool IsNodeExpansionEnabled() const
int IndentSize() const
bool IsAlternateRowColorEnabled() const
int ChildIndex(const Node *) const
int ScaledIndentSize() const
Definition: TreeBox.h:638
String HeaderText(int col) const
IndirectArray< Node > SelectedNodes() const
bool IsNodeDraggingEnabled() const
void DisableUniformRowHeight(bool disable=true)
Definition: TreeBox.h:715
void SetNodeIntoView(Node *)
pcl::Rect NodeRect(const Node *) const
const Node * NodeByPosition(int x, int y) const
int HeaderAlignment(int col) const
void SetCurrentNode(Node *)
Node * CurrentNode()
const Node * Child(int idx) const
void SetScaledIndentSize(int size)
Definition: TreeBox.h:645
void SetScaledIconSize(int size)
Definition: TreeBox.h:781
void SelectAllNodes()
void AdjustColumnWidthToContents(int col)
int IconWidth() const
Definition: TreeBox.h:728
void EnableNodeDragging(bool=true)
void Add(Node *n)
Definition: TreeBox.h:423
int ColumnWidth(int col) const
bool IsColumnVisible(int col) const
const Node * NodeByPosition(const pcl::Point &p) const
Definition: TreeBox.h:498
void SetIconSize(int size)
Definition: TreeBox.h:746
void GetIconSize(int &width, int &height) const
void DisableNodeDragging(bool disable=true)
Definition: TreeBox.h:820
void DisableAlternateRowColor(bool disable=true)
Definition: TreeBox.h:698
Node * NodeByPosition(const pcl::Point &p)
Definition: TreeBox.h:505
void EnableHeaderSorting(bool=true)
void HideHeader(bool hide=true)
Definition: TreeBox.h:621
const Node * CurrentNode() const
bool IsHeaderSortingEnabled() const
int ScaledIconHeight() const
Definition: TreeBox.h:767
void SetColumnWidth(int col, int width)
void DisableRootDecoration(bool disable=true)
Definition: TreeBox.h:679
Node * NodeByPosition(int x, int y)
void DisableHeaderSorting(bool disable=true)
Definition: TreeBox.h:799
bool AreMultipleSelectionsEnabled() const
void ShowColumn(int col, bool show=true)
int NumberOfChildren() const
void EnableUniformRowHeight(bool=true)
void Sort(int col=0, bool ascending=true)
void SetScaledColumnWidth(int col, int width)
Definition: TreeBox.h:572
Bitmap HeaderIcon(int col) const
int NumberOfColumns() const
bool IsRootDecorationEnabled() const
void HideColumn(int col, bool hide=true)
Definition: TreeBox.h:548
bool HasSelectedTopLevelNodes() const
void EnableMultipleSelections(bool enable=true)
void EnableAlternateRowColor(bool=true)
bool IsHeaderVisible() const
void ShowHeader(bool show=true)
Node * Child(int idx)
void SetHeaderAlignment(int col, int align)
void SetScaledIconSize(int width, int height)
Definition: TreeBox.h:774
TreeBox(Control &parent=Control::Null())
void Insert(int idx, Node *)
void SetIconSize(int width, int height)
int ScaledIconWidth() const
Definition: TreeBox.h:760
int IconHeight() const
Definition: TreeBox.h:735
void SetHeaderIcon(int col, const Bitmap &)
void GetScaledIconSize(int &width, int &height) const
Definition: TreeBox.h:753
void DisableNodeExpansion(bool disable=true)
Definition: TreeBox.h:662
static TreeBox & NullTree()
bool AreMultipleSelectionsDisabled() const
Definition: TreeBox.h:458
Root base class for all user interface objects.
Definition: UIObject.h:95
uint32 RGBA
Definition: Color.h:92
RI Select(RI i, RI j, distance_type k)
Definition: Selection.h:165
void OnNodeEntered(node_event_handler, Control &)
void(Control::*)(TreeBox &) tree_event_handler
Definition: TreeBox.h:845
void OnNodeSelectionUpdated(tree_event_handler, Control &)
void OnNodeActivated(node_event_handler, Control &)
void OnNodeCollapsed(node_expand_event_handler, Control &)
void OnNodeClicked(node_event_handler, Control &)
void OnCurrentNodeUpdated(node_navigation_event_handler, Control &)
void(Control::*)(TreeBox &, TreeBox::Node &) node_expand_event_handler
Definition: TreeBox.h:855
void OnNodeDoubleClicked(node_event_handler, Control &)
void OnNodeExpanded(node_expand_event_handler, Control &)
void OnNodeUpdated(node_event_handler, Control &)
void(Control::*)(TreeBox &, TreeBox::Node &, int) node_event_handler
Definition: TreeBox.h:850
void(Control::*)(TreeBox &, TreeBox::Node &, TreeBox::Node &) node_navigation_event_handler
Definition: TreeBox.h:860
PCL root namespace.
Definition: AbstractImage.h:77