PCL
ScrollBox.h
Go to the documentation of this file.
1 // ____ ______ __
2 // / __ \ / ____// /
3 // / /_/ // / / /
4 // / ____// /___ / /___ PixInsight Class Library
5 // /_/ \____//_____/ PCL 2.7.0
6 // ----------------------------------------------------------------------------
7 // pcl/ScrollBox.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_ScrollBox_h
53 #define __PCL_ScrollBox_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 ScrollBox : public Frame
76 {
77 public:
78 
83 
87  ~ScrollBox() override
88  {
89  }
90 
96 
102 
109  void ShowScrollBars( bool showHorz = true, bool showVert = true );
110 
117  void HideScrollBars( bool hideHorz = true, bool hideVert = true )
118  {
119  ShowScrollBars( !hideHorz, !hideVert );
120  }
121 
128  void ShowHorizontalScrollBar( bool show = true )
129  {
130  ShowScrollBars( show, IsVerticalScrollBarVisible() );
131  }
132 
139  void HideHorizontalScrollBar( bool hide = true )
140  {
141  ShowHorizontalScrollBar( !hide );
142  }
143 
150  void ShowVerticalScrollBar( bool show = true )
151  {
152  ShowScrollBars( IsHorizontalScrollBarVisible(), show );
153  }
154 
161  void HideVerticalScrollBar( bool hide = true )
162  {
163  ShowVerticalScrollBar( !hide );
164  }
165 
175 
185 
196  void EnableAutoScroll( bool enableHorz = true, bool enableVert = true );
197 
204  void DisableAutoScroll( bool disableHorz = true, bool disableVert = true )
205  {
206  EnableAutoScroll( !disableHorz, !disableVert );
207  }
208 
218  void GetHorizontalScrollRange( int& minPos, int& maxPos ) const;
219 
229  void GetVerticalScrollRange( int& minPos, int& maxPos ) const;
230 
235  {
236  int minPos, dum; GetHorizontalScrollRange( minPos, dum ); return minPos;
237  }
238 
243  {
244  int dum, maxPos; GetHorizontalScrollRange( dum, maxPos ); return maxPos;
245  }
246 
251  {
252  int minPos, dum; GetVerticalScrollRange( minPos, dum ); return minPos;
253  }
254 
259  {
260  int dum, maxPos; GetVerticalScrollRange( dum, maxPos ); return maxPos;
261  }
262 
272  void SetHorizontalScrollRange( int minPos, int maxPos );
273 
283  void SetVerticalScrollRange( int minPos, int maxPos );
284 
291  int PageWidth() const;
292 
300  int PageHeight() const;
301 
308  void SetPageSize( int width, int height );
309 
313  void SetPageWidth( int width )
314  {
315  SetPageSize( width, PageHeight() );
316  }
317 
321  void SetPageHeight( int height )
322  {
323  SetPageSize( PageWidth(), height );
324  }
325 
332  int LineWidth() const;
333 
340  int LineHeight() const;
341 
348  void SetLineSize( int width, int height );
349 
353  void SetLineWidth( int width )
354  {
355  SetLineSize( width, LineHeight() );
356  }
357 
361  void SetLineHeight( int height )
362  {
363  SetLineSize( LineWidth(), height );
364  }
365 
371 
376  {
377  pcl::Point pos = ScrollPosition(); return pos.x;
378  }
379 
384  {
385  pcl::Point pos = ScrollPosition(); return pos.y;
386  }
387 
391  void SetScrollPosition( const pcl::Point& pos )
392  {
393  SetScrollPosition( pos.x, pos.y );
394  }
395 
400  void SetScrollPosition( int horzPos, int vertPos );
401 
405  void SetHorizontalScrollPosition( int horzPos )
406  {
407  SetScrollPosition( horzPos, VerticalScrollPosition() );
408  }
409 
413  void SetVerticalScrollPosition( int vertPos )
414  {
415  SetScrollPosition( HorizontalScrollPosition(), vertPos );
416  }
417 
423 
429 
445  void EnableTracking( bool enableHorz = true, bool enableVert = true );
446 
454  void EnableHorizontalTracking( bool enableHorz = true )
455  {
456  EnableTracking( enableHorz, IsVerticalTrackingEnabled() );
457  }
458 
466  void EnableVerticalTracking( bool enableVert = true )
467  {
468  EnableTracking( IsHorizontalTrackingEnabled(), enableVert );
469  }
470 
478  void DisableTracking( bool disableHorz = true, bool disableVert = true )
479  {
480  EnableTracking( !disableHorz, !disableVert );
481  }
482 
490  void DisableHorizontalTracking( bool disableHorz = true )
491  {
492  EnableTracking( !disableHorz, IsVerticalTrackingEnabled() );
493  }
494 
502  void DisableVerticalTracking( bool disableVert = true )
503  {
504  EnableTracking( IsHorizontalTrackingEnabled(), !disableVert );
505  }
506 
514  const Control& Viewport() const
515  {
516  return m_viewport;
517  }
518 
526  {
527  return m_viewport;
528  }
529 
530  // -------------------------------------------------------------------------
531  // Event handlers
532  //
533  // void OnHorizontalScrollPosUpdated( ScrollBox& sender, int horzPos );
534  // void OnVerticalScrollPosUpdated( ScrollBox& sender, int vertPos );
535  // void OnHorizontalScrollRangeUpdated( ScrollBox& sender, int minHorzPos, int maxHorzPos );
536  // void OnVerticalScrollRangeUpdated( ScrollBox& sender, int minVertPos, int maxVertPos );
537 
554  using pos_event_handler = void (Control::*)( ScrollBox& sender, int pos );
555 
568  using range_event_handler = void (Control::*)( ScrollBox& sender, int minValue, int maxValue );
569 
582 
595 
608 
621 
622 private:
623 
624  struct EventHandlers
625  {
626  pos_event_handler onHorizontalScrollPosUpdated = nullptr;
627  pos_event_handler onVerticalScrollPosUpdated = nullptr;
628  range_event_handler onHorizontalScrollRangeUpdated = nullptr;
629  range_event_handler onVerticalScrollRangeUpdated = nullptr;
630 
631  EventHandlers() = default;
632  EventHandlers( const EventHandlers& ) = default;
633  EventHandlers& operator =( const EventHandlers& ) = default;
634  };
635 
636  AutoPointer<EventHandlers> m_handlers;
637 
638 protected:
639 
640  Control m_viewport;
641 
645  ScrollBox( void* );
646 
650  ScrollBox( void*, void* );
651 
652  friend class ScrollBoxEventDispatcher;
653 };
654 
655 // ----------------------------------------------------------------------------
656 
657 } // pcl
658 
659 #endif // __PCL_BUILDING_PIXINSIGHT_APPLICATION
660 
661 #endif // __PCL_ScrollBox_h
662 
663 // ----------------------------------------------------------------------------
664 // EOF pcl/ScrollBox.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
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
Client-side interface to a PixInsight ScrollBox control.
Definition: ScrollBox.h:76
int MinHorizontalScrollPosition() const
Definition: ScrollBox.h:234
void SetPageHeight(int height)
Definition: ScrollBox.h:321
bool IsHorizontalScrollBarVisible() const
bool IsVerticalScrollBarVisible() const
void SetPageWidth(int width)
Definition: ScrollBox.h:313
int VerticalScrollPosition() const
Definition: ScrollBox.h:383
void SetPageSize(int width, int height)
void DisableHorizontalTracking(bool disableHorz=true)
Definition: ScrollBox.h:490
const Control & Viewport() const
Definition: ScrollBox.h:514
void HideScrollBars(bool hideHorz=true, bool hideVert=true)
Definition: ScrollBox.h:117
bool IsHorizontalTrackingEnabled() const
void ShowHorizontalScrollBar(bool show=true)
Definition: ScrollBox.h:128
ScrollBox(Control &parent=Control::Null())
void SetLineWidth(int width)
Definition: ScrollBox.h:353
void SetScrollPosition(int horzPos, int vertPos)
int MinVerticalScrollPosition() const
Definition: ScrollBox.h:250
Control & Viewport()
Definition: ScrollBox.h:525
bool IsVerticalAutoScrollEnabled() const
void HideVerticalScrollBar(bool hide=true)
Definition: ScrollBox.h:161
pcl::Point ScrollPosition() const
void SetLineHeight(int height)
Definition: ScrollBox.h:361
bool IsVerticalTrackingEnabled() const
void SetVerticalScrollPosition(int vertPos)
Definition: ScrollBox.h:413
void DisableTracking(bool disableHorz=true, bool disableVert=true)
Definition: ScrollBox.h:478
void SetHorizontalScrollPosition(int horzPos)
Definition: ScrollBox.h:405
void GetHorizontalScrollRange(int &minPos, int &maxPos) const
int MaxHorizontalScrollPosition() const
Definition: ScrollBox.h:242
void EnableTracking(bool enableHorz=true, bool enableVert=true)
int PageWidth() const
void DisableVerticalTracking(bool disableVert=true)
Definition: ScrollBox.h:502
~ScrollBox() override
Definition: ScrollBox.h:87
void SetHorizontalScrollRange(int minPos, int maxPos)
int LineWidth() const
int LineHeight() const
void ShowVerticalScrollBar(bool show=true)
Definition: ScrollBox.h:150
int PageHeight() const
bool IsHorizontalAutoScrollEnabled() const
void HideHorizontalScrollBar(bool hide=true)
Definition: ScrollBox.h:139
void EnableAutoScroll(bool enableHorz=true, bool enableVert=true)
void GetVerticalScrollRange(int &minPos, int &maxPos) const
void EnableVerticalTracking(bool enableVert=true)
Definition: ScrollBox.h:466
void SetVerticalScrollRange(int minPos, int maxPos)
void SetScrollPosition(const pcl::Point &pos)
Definition: ScrollBox.h:391
void SetLineSize(int width, int height)
void DisableAutoScroll(bool disableHorz=true, bool disableVert=true)
Definition: ScrollBox.h:204
int HorizontalScrollPosition() const
Definition: ScrollBox.h:375
void ShowScrollBars(bool showHorz=true, bool showVert=true)
int MaxVerticalScrollPosition() const
Definition: ScrollBox.h:258
void EnableHorizontalTracking(bool enableHorz=true)
Definition: ScrollBox.h:454
void OnVerticalScrollPosUpdated(pos_event_handler handler, Control &receiver)
void OnVerticalScrollRangeUpdated(range_event_handler handler, Control &receiver)
void(Control::*)(ScrollBox &sender, int minValue, int maxValue) range_event_handler
Definition: ScrollBox.h:568
void(Control::*)(ScrollBox &sender, int pos) pos_event_handler
Definition: ScrollBox.h:554
void OnHorizontalScrollRangeUpdated(range_event_handler handler, Control &receiver)
void OnHorizontalScrollPosUpdated(pos_event_handler handler, Control &receiver)
PCL root namespace.
Definition: AbstractImage.h:77