PCL
TreeBox.h
Go to the documentation of this file.
1 // ____ ______ __
2 // / __ \ / ____// /
3 // / /_/ // / / /
4 // / ____// /___ / /___ PixInsight Class Library
5 // /_/ \____//_____/ PCL 2.8.5
6 // ----------------------------------------------------------------------------
7 // pcl/TreeBox.h - Released 2024-12-28T16:53:48Z
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  bool IsFirstColumnSpanned() const;
284 
287  void SetFirstColumnSpanned( bool spanned = true );
288 
291  String Text( int col ) const;
292 
295  void SetText( int col, const String& );
296 
299  Bitmap Icon( int col ) const;
300 
303  void SetIcon( int col, const Bitmap& );
304 
307  int Alignment( int col ) const;
308 
311  void SetAlignment( int col, int align );
312 
315  String ToolTip( int col ) const;
316 
319  void SetToolTip( int col, const String& );
320 
323  pcl::Font Font( int col ) const;
324 
327  void SetFont( int col, const pcl::Font& );
328 
331  RGBA BackgroundColor( int col ) const;
332 
335  void SetBackgroundColor( int col, RGBA );
336 
339  RGBA TextColor( int col ) const;
340 
343  void SetTextColor( int col, RGBA );
344 
345  protected:
346 
350  Node( void* h )
351  : UIObject( h )
352  {
353  }
354 
358  Node( std::nullptr_t )
359  : UIObject( nullptr )
360  {
361  }
362 
366  void* CloneHandle() const override;
367 
368  private:
369 
370  using child_node_list = SortedArray<Node*>;
371  child_node_list m_children;
372  bool m_removed = false;
373 
374  friend class TreeBox;
375  };
376 
377  // -------------------------------------------------------------------------
378 
382  TreeBox( Control& parent = Control::Null() );
383 
387  ~TreeBox() override;
388 
391  static TreeBox& NullTree();
392 
393  //
394 
397  int NumberOfChildren() const;
398 
401  const Node* Child( int idx ) const;
402 
405  Node* Child( int idx );
406 
409  const Node* operator []( int idx ) const
410  {
411  return Child( idx );
412  }
413 
416  Node* operator []( int idx )
417  {
418  return Child( idx );
419  }
420 
423  int ChildIndex( const Node* ) const;
424 
427  void Insert( int idx, Node* );
428 
431  void Add( Node* n )
432  {
433  Insert( NumberOfChildren(), n );
434  }
435 
438  void Remove( int idx );
439 
442  void Clear();
443 
444  //
445 
448  const Node* CurrentNode() const;
449 
453 
457 
458  //
459 
463 
467  {
468  return !AreMultipleSelectionsEnabled();
469  }
470 
473  void EnableMultipleSelections( bool enable = true );
474 
477  void DisableMultipleSelections( bool disable = true )
478  {
479  EnableMultipleSelections( !disable );
480  }
481 
490 
495 
501 
502  //
503 
506  const Node* NodeByPosition( const pcl::Point& p ) const
507  {
508  return NodeByPosition( p.x, p.y ); // in client coordinates
509  }
510 
514  {
515  return NodeByPosition( p.x, p.y );
516  }
517 
520  const Node* NodeByPosition( int x, int y ) const;
521 
524  Node* NodeByPosition( int x, int y );
525 
529 
532  pcl::Rect NodeRect( const Node* ) const;
533 
534  //
535 
538  int NumberOfColumns() const;
539 
542  void SetNumberOfColumns( int nCols );
543 
544  // Visibility
545 
548  bool IsColumnVisible( int col ) const;
549 
552  void ShowColumn( int col, bool show = true );
553 
556  void HideColumn( int col, bool hide = true )
557  {
558  ShowColumn( col, !hide );
559  }
560 
561  //
562 
565  int ColumnWidth( int col ) const;
566 
569  void SetColumnWidth( int col, int width );
570 
573  int ScaledColumnWidth( int col ) const
574  {
575  return PhysicalPixelsToLogical( ColumnWidth( col ) );
576  }
577 
580  void SetScaledColumnWidth( int col, int width )
581  {
582  SetColumnWidth( col, LogicalPixelsToPhysical( width ) );
583  }
584 
588 
589  //
590 
593  String HeaderText( int col ) const;
594 
597  void SetHeaderText( int col, const String& );
598 
599  //
600 
603  Bitmap HeaderIcon( int col ) const;
604 
607  void SetHeaderIcon( int col, const Bitmap& );
608 
609  //
610 
613  int HeaderAlignment( int col ) const;
614 
617  void SetHeaderAlignment( int col, int align );
618 
621  bool IsHeaderVisible() const;
622 
625  void ShowHeader( bool show = true );
626 
629  void HideHeader( bool hide = true )
630  {
631  ShowHeader( !hide );
632  }
633 
634  //
635 
638  int IndentSize() const;
639 
642  void SetIndentSize( int );
643 
646  int ScaledIndentSize() const
647  {
648  return PhysicalPixelsToLogical( IndentSize() );
649  }
650 
653  void SetScaledIndentSize( int size )
654  {
655  SetIndentSize( LogicalPixelsToPhysical( size ) );
656  }
657 
658  //
659 
663 
666  void EnableNodeExpansion( bool = true );
667 
670  void DisableNodeExpansion( bool disable = true )
671  {
672  EnableNodeExpansion( !disable );
673  }
674 
675  //
676 
680 
683  void EnableRootDecoration( bool = true );
684 
687  void DisableRootDecoration( bool disable = true )
688  {
689  EnableRootDecoration( !disable );
690  }
691 
692  // Alternating row colors
693  // Even row color is Control::CanvasColor()
694  // Odd row color is Control::AlternateCanvasColor()
695 
699 
702  void EnableAlternateRowColor( bool = true );
703 
706  void DisableAlternateRowColor( bool disable = true )
707  {
708  EnableAlternateRowColor( !disable );
709  }
710 
711  //
712 
716 
719  void EnableUniformRowHeight( bool = true );
720 
723  void DisableUniformRowHeight( bool disable = true )
724  {
725  EnableUniformRowHeight( !disable );
726  }
727 
728  //
729 
732  void GetIconSize( int& width, int& height ) const;
733 
736  int IconWidth() const
737  {
738  int w, dum; GetIconSize( w, dum ); return w;
739  }
740 
743  int IconHeight() const
744  {
745  int dum, h; GetIconSize( dum, h ); return h;
746  }
747 
750  void SetIconSize( int width, int height );
751 
754  void SetIconSize( int size )
755  {
756  SetIconSize( size, size );
757  }
758 
761  void GetScaledIconSize( int& width, int& height ) const
762  {
763  GetIconSize( width, height ); width = PhysicalPixelsToLogical( width ); height = PhysicalPixelsToLogical( height );
764  }
765 
768  int ScaledIconWidth() const
769  {
770  int width, dum; GetIconSize( width, dum ); return PhysicalPixelsToLogical( width );
771  }
772 
775  int ScaledIconHeight() const
776  {
777  int dum, height; GetIconSize( dum, height ); return PhysicalPixelsToLogical( height );
778  }
779 
782  void SetScaledIconSize( int width, int height )
783  {
784  SetIconSize( LogicalPixelsToPhysical( width ), LogicalPixelsToPhysical( height ) );
785  }
786 
789  void SetScaledIconSize( int size )
790  {
791  size = LogicalPixelsToPhysical( size );
792  SetIconSize( size, size );
793  }
794 
795  //
796 
800 
803  void EnableHeaderSorting( bool = true );
804 
807  void DisableHeaderSorting( bool disable = true )
808  {
809  EnableHeaderSorting( !disable );
810  }
811 
814  void Sort( int col = 0, bool ascending = true );
815 
816  //
817 
820  bool IsNodeDraggingEnabled() const;
821 
824  void EnableNodeDragging( bool = true );
825 
828  void DisableNodeDragging( bool disable = true )
829  {
830  EnableNodeDragging( !disable );
831  }
832 
833  // -------------------------------------------------------------------------
834  // Event handlers
835  //
836  // void OnCurrentNodeUpdated( TreeBox& sender, TreeBox::Node& current, TreeBox::Node& oldCurrent );
837  // void OnNodeActivated( TreeBox& sender, TreeBox::Node& node, int col );
838  // void OnNodeUpdated( TreeBox& sender, TreeBox::Node& node, int col );
839  // void OnNodeEntered( TreeBox& sender, TreeBox::Node& node, int col );
840  // void OnNodeClicked( TreeBox& sender, TreeBox::Node& node, int col );
841  // void OnNodeDoubleClicked( TreeBox& sender, TreeBox::Node& node, int col );
842  // void OnNodeExpanded( TreeBox& sender, TreeBox::Node& node );
843  // void OnNodeCollapsed( TreeBox& sender, TreeBox::Node& node );
844  // void OnNodeSelectionUpdated( TreeBox& sender );
845 
853  using tree_event_handler = void (Control::*)( TreeBox& );
854 
858  using node_event_handler = void (Control::*)( TreeBox&, TreeBox::Node&, int );
859 
864 
869 
874 
879 
884 
889 
894 
899 
904 
909 
914 
915 private:
916 
917  struct EventHandlers
918  {
919  node_navigation_event_handler onCurrentNodeUpdated = nullptr;
920  node_event_handler onNodeActivated = nullptr;
921  node_event_handler onNodeUpdated = nullptr;
922  node_event_handler onNodeEntered = nullptr;
923  node_event_handler onNodeClicked = nullptr;
924  node_event_handler onNodeDoubleClicked = nullptr;
925  node_expand_event_handler onNodeExpanded = nullptr;
926  node_expand_event_handler onNodeCollapsed = nullptr;
927  tree_event_handler onNodeSelectionUpdated = nullptr;
928 
929  EventHandlers() = default;
930  EventHandlers( const EventHandlers& ) = default;
931  EventHandlers& operator =( const EventHandlers& ) = default;
932  };
933 
934  AutoPointer<EventHandlers> m_handlers;
935 
936  using child_node_list = SortedArray<Node*>;
937  child_node_list m_children;
938 
939  static pcl::Font FontFromHandle( void* h )
940  {
941  return pcl::Font( h );
942  }
943 
944  static const void* HandleFromFont( const pcl::Font& f )
945  {
946  return f.handle;
947  }
948 
949  static Bitmap BitmapFromHandle( void* h )
950  {
951  return Bitmap( h );
952  }
953 
954  static const void* HandleFromBitmap( const Bitmap& p )
955  {
956  return p.handle;
957  }
958 
959 protected:
960 
964  TreeBox( void* );
965 
966  friend class Node;
967  friend class TreeBoxEventDispatcher;
968 };
969 
970 // ----------------------------------------------------------------------------
971 
972 } // pcl
973 
974 #endif // __PCL_BUILDING_PIXINSIGHT_APPLICATION
975 
976 #endif // __PCL_TreeBox_h
977 
978 // ----------------------------------------------------------------------------
979 // EOF pcl/TreeBox.h - Released 2024-12-28T16:53:48Z
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:316
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:8146
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)
bool IsFirstColumnSpanned() const
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:573
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:477
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:646
String HeaderText(int col) const
IndirectArray< Node > SelectedNodes() const
bool IsNodeDraggingEnabled() const
void DisableUniformRowHeight(bool disable=true)
Definition: TreeBox.h:723
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:653
void SetScaledIconSize(int size)
Definition: TreeBox.h:789
void SelectAllNodes()
void AdjustColumnWidthToContents(int col)
int IconWidth() const
Definition: TreeBox.h:736
void EnableNodeDragging(bool=true)
void Add(Node *n)
Definition: TreeBox.h:431
int ColumnWidth(int col) const
bool IsColumnVisible(int col) const
const Node * NodeByPosition(const pcl::Point &p) const
Definition: TreeBox.h:506
void SetIconSize(int size)
Definition: TreeBox.h:754
void GetIconSize(int &width, int &height) const
void DisableNodeDragging(bool disable=true)
Definition: TreeBox.h:828
void DisableAlternateRowColor(bool disable=true)
Definition: TreeBox.h:706
Node * NodeByPosition(const pcl::Point &p)
Definition: TreeBox.h:513
void EnableHeaderSorting(bool=true)
void HideHeader(bool hide=true)
Definition: TreeBox.h:629
const Node * CurrentNode() const
bool IsHeaderSortingEnabled() const
int ScaledIconHeight() const
Definition: TreeBox.h:775
void SetColumnWidth(int col, int width)
void DisableRootDecoration(bool disable=true)
Definition: TreeBox.h:687
Node * NodeByPosition(int x, int y)
void DisableHeaderSorting(bool disable=true)
Definition: TreeBox.h:807
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:580
Bitmap HeaderIcon(int col) const
int NumberOfColumns() const
bool IsRootDecorationEnabled() const
void HideColumn(int col, bool hide=true)
Definition: TreeBox.h:556
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:782
TreeBox(Control &parent=Control::Null())
void Insert(int idx, Node *)
void SetIconSize(int width, int height)
int ScaledIconWidth() const
Definition: TreeBox.h:768
int IconHeight() const
Definition: TreeBox.h:743
void SetHeaderIcon(int col, const Bitmap &)
void GetScaledIconSize(int &width, int &height) const
Definition: TreeBox.h:761
void DisableNodeExpansion(bool disable=true)
Definition: TreeBox.h:670
static TreeBox & NullTree()
bool AreMultipleSelectionsDisabled() const
Definition: TreeBox.h:466
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:853
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:863
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:858
void(Control::*)(TreeBox &, TreeBox::Node &, TreeBox::Node &) node_navigation_event_handler
Definition: TreeBox.h:868
PCL root namespace.
Definition: AbstractImage.h:77