Debian Codegraph @

src/tools/dlgedit/gui_scrollable.h

raw
1 /*
2 Copyright (C) 2009 Kai Sterker <[email protected]>
3 Part of the Adonthell Project <http://adonthell.nongnu.org>
4
5 Dlgedit is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 Dlgedit is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with Dlgedit. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 /**
20 * @file common/gui_scrollable.h
21 *
22 * @author Kai Sterker
23 * @brief Basic functionality for automated scolling.
24 */
25
26 #ifndef COMMON_SCROLLING_H
27 #define COMMON_SCROLLING_H
28
29 #include <gdk/gdk.h>
30
31 /**
32 * Implements scrolling that is triggered by the mouse pointer
33 * near the border of the widget.
34 */
35 class Scrollable
36 {
37 public:
38 /**
39 * Constructor.
40 */
41 Scrollable();
42
43 /**
44 * Destructor.
45 */
46 virtual ~Scrollable();
47
48 /**
49 * @name Auto-Scrolling (TM) ;) functionality.
50 */
51 //@{
52 /**
53 * Method deciding whether to start with scrolling. The cursor has to
54 * remain in the outer 20 pixel of the view to enable scrolling.
55 * @param point The current cursor position.
56 */
57 void prepareScrolling (const GdkPoint & point);
58 /**
59 * Moves the view in the desired direction.
60 */
61 virtual void scroll () = 0;
62 /**
63 * Check whether we are currently scrolling
64 * @return <b>true</b> if that is the case, <b>false</b> otherwise.
65 */
66 bool isScrolling () const;
67 /**
68 * Finish scrolling.
69 */
70 void stopScrolling ();
71 //@}
72
73 /**
74 * @name Program-Initiated Scrolling
75 */
76 void setScrollOffset (const int & x, const int & y)
77 {
78 scroll_offset.x = x;
79 scroll_offset.y = y;
80 }
81
82 /**
83 * @name Hooks into users of auto-scrolling.
84 */
85 //@{
86 /**
87 * Return a pointer to the drawing area
88 * @return the GtkDrawingArea widget
89 */
90 virtual GtkWidget *drawingArea () const = 0;
91 /**
92 * Check whether it is allowed to initiate
93 * scrolling.
94 * @return false if scrolling is forbidden, true otherwise.
95 */
96 virtual bool scrollingAllowed () const = 0;
97 //@}
98
99 protected:
100 /// Offset by which the view moves during scrolling
101 GdkPoint scroll_offset;
102
103 private:
104 /// create the cursor to display when scrolling is active
105 void createScrollCursor ();
106 /// Cursor to indicate scrolling
107 GdkCursor *scrollCursor;
108
109 /// Indicates whether autoscrolling is active
110 bool scrolling;
111 };
112
113 #endif // COMMON_SCROLLING_H