NetSurf
scrollbar.h
Go to the documentation of this file.
1/*
2 * Copyright 2009 Paul Blokus <paul_pl@users.sourceforge.net>
3 *
4 * This file is part of NetSurf, http://www.netsurf-browser.org/
5 *
6 * NetSurf is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * NetSurf 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 this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19/**
20 * \file
21 * Scrollbar widget interface.
22 *
23 * Scrollbar widgets used in frames code, not for frontend use
24 */
25
26#ifndef NETSURF_DESKTOP_SCROLLBAR_H
27#define NETSURF_DESKTOP_SCROLLBAR_H
28
29#include <stdbool.h>
30#include <limits.h>
31
32#define SCROLLBAR_WIDTH 16
33
34/* Region dependent values for scrollbar_scroll function */
35#define SCROLL_TOP INT_MIN
36#define SCROLL_PAGE_UP (INT_MIN + 1)
37#define SCROLL_PAGE_DOWN (INT_MAX - 1)
38#define SCROLL_BOTTOM INT_MAX
39
40struct scrollbar;
41struct redraw_context;
42
43/**
44 * scrollbar message types
45 */
46typedef enum {
47 SCROLLBAR_MSG_MOVED, /**< the scroll value has changed */
48 SCROLLBAR_MSG_SCROLL_START, /**< a scrollbar drag has started, all
49 * mouse events should be passed to
50 * the scrollbar regardless of the
51 * coordinates
52 */
53 SCROLLBAR_MSG_SCROLL_FINISHED, /**< cancel a scrollbar drag */
55
56/**
57 * scrollbar message context data
58 */
63 int x0, y0, x1, y1;
64};
65
66
67/**
68 * Scrollbar mouse input status flags
69 */
70typedef enum {
71 SCROLLBAR_MOUSE_NONE = 0, /**< Not relevant */
72 SCROLLBAR_MOUSE_USED = (1 << 0), /**< Took action with input */
73 SCROLLBAR_MOUSE_BOTH = (1 << 1), /**< Scrolling both bars */
74 SCROLLBAR_MOUSE_UP = (1 << 2), /**< Hover: scroll up */
75 SCROLLBAR_MOUSE_PUP = (1 << 3), /**< Hover: scroll page up */
76 SCROLLBAR_MOUSE_VRT = (1 << 4), /**< Hover: vert. drag bar */
77 SCROLLBAR_MOUSE_PDWN = (1 << 5), /**< Hover: scroll page down */
78 SCROLLBAR_MOUSE_DWN = (1 << 6), /**< Hover: scroll down */
79 SCROLLBAR_MOUSE_LFT = (1 << 7), /**< Hover: scroll left */
80 SCROLLBAR_MOUSE_PLFT = (1 << 8), /**< Hover: scroll page left */
81 SCROLLBAR_MOUSE_HRZ = (1 << 9), /**< Hover: horiz. drag bar */
82 SCROLLBAR_MOUSE_PRGT = (1 << 10), /**< Hover: scroll page right */
83 SCROLLBAR_MOUSE_RGT = (1 << 11) /**< Hover: scroll right */
85
86
87/**
88 * Client callback for the scrollbar.
89 *
90 * \param client_data user data passed at scroll creation
91 * \param scrollbar_data scrollbar message data
92 */
94 struct scrollbar_msg_data *scrollbar_data);
95
96
97/**
98 * Create a scrollbar.
99 *
100 * \param horizontal true = horizontal scrollbar, false = vertical
101 * \param length length of scrollbar widget
102 * \param full_size length of contained scrollable area
103 * \param visible_size length of visible part of scrollable area
104 * \param client_data data for the client callback
105 * \param client_callback client callback for scrollbar events
106 * \param s updated to point at the newly created scrollbar
107 * \return NSERROR_OK and s updated if scrollbar has been created
108 * succesfully or eror code and s set to NULL on faliure;
109 */
110nserror scrollbar_create(bool horizontal, int length, int full_size,
111 int visible_size, void *client_data,
112 scrollbar_client_callback client_callback,
113 struct scrollbar **s);
114
115/**
116 * Destroy a scrollbar.
117 *
118 * \param s the scrollbar to be destroyed
119 */
120void scrollbar_destroy(struct scrollbar *s);
121
122/**
123 * Redraw a part of the scrollbar.
124 *
125 * \param s the scrollbar to be redrawn
126 * \param x the X coordinate to draw the scrollbar at
127 * \param y the Y coordinate to draw the scrollbar at
128 * \param clip the clipping rectangle
129 * \param scale scale for the redraw
130 * \param ctx current redraw context
131 * \return NSERROR_OK on success otherwise error code
132 */
133nserror scrollbar_redraw(struct scrollbar *s, int x, int y,
134 const struct rect *clip, float scale,
135 const struct redraw_context *ctx);
136
137/**
138 * Set the scroll value of the scrollbar.
139 *
140 * \param s the scrollbar to have the value set
141 * \param value the new value to be set
142 * \param bar_pos true if the value is for the scrollbar indication bar
143 * position, false if it is for the scrolled area offset
144 */
145void scrollbar_set(struct scrollbar *s, int value, bool bar_pos);
146
147/**
148 * Scroll the scrollbar by given amount.
149 *
150 * \param s the scrollbar to be scrolled
151 * \param change the change in scroll offset required (in px)
152 * \return true iff the scrollbar was moved.
153 */
154bool scrollbar_scroll(struct scrollbar *s, int change);
155
156/**
157 * Get the current scroll offset to the visible part of the full area.
158 *
159 * \param s the scrollbar to get the scroll offset value from
160 * \return current scroll offset
161 */
162int scrollbar_get_offset(struct scrollbar *s);
163
164/**
165 * Set the length of the scrollbar widget, the size of the visible area, and the
166 * size of the full area.
167 *
168 * \param s the scrollbar to set the values for
169 * \param length -1 or the new scrollbar widget length
170 * \param visible_size -1 or the new size of the visible area
171 * \param full_size -1 or the new size of the full contained area
172 */
173void scrollbar_set_extents(struct scrollbar *s, int length,
174 int visible_size, int full_size);
175
176/**
177 * Check orientation of the scrollbar.
178 *
179 * \param s the scrollbar to check the orientation of
180 * \return true for a horizontal scrollbar, else false (vertical)
181 */
182bool scrollbar_is_horizontal(struct scrollbar *s);
183
184
185/**
186 * Handle mouse actions other then drag ends.
187 *
188 * \param s the scrollbar which gets the mouse action
189 * \param mouse mouse state
190 * \param x X coordinate of the mouse
191 * \param y Y coordinate of the mouse
192 * \return the scrollbar mouse status
193 */
195 browser_mouse_state mouse, int x, int y);
196
197
198/**
199 * Get a status bar message from a scrollbar mouse input status.
200 *
201 * \param status Status to convert to message
202 * \return Message for the status bar or NULL on failure
203 */
205
206
207/**
208 * Handle end of mouse drags.
209 *
210 * \param s the scrollbar for which the drag ends
211 * \param mouse mouse state
212 * \param x X coordinate of the mouse
213 * \param y Y coordinate of the mouse
214 */
216 browser_mouse_state mouse, int x, int y);
217
218
219/**
220 * Called when the content is being dragged to the scrollbars have to adjust.
221 *
222 * If the content has both scrollbars, and scrollbar_make_pair has beed called
223 * before, only the one scroll which will receive further mouse events has to be
224 * passed.
225 *
226 * \param s one of the the scrollbars owned by the dragged content
227 * \param x X coordinate of mouse during drag start
228 * \param y Y coordinate of mouse during drag start
229 */
230void scrollbar_start_content_drag(struct scrollbar *s, int x, int y);
231
232
233/**
234 * Connect a horizontal and a vertical scrollbar into a pair so that they
235 * co-operate during 2D drags.
236 *
237 * \param horizontal the scrollbar used for horizontal scrolling
238 * \param vertical the scrollbar used for vertical scrolling
239 */
240void scrollbar_make_pair(struct scrollbar *horizontal,
241 struct scrollbar *vertical);
242
243
244/**
245 * Get the scrollbar's client data
246 *
247 * \param s the scrollbar to get the client data from
248 * \return client data
249 */
250void *scrollbar_get_data(struct scrollbar *s);
251
252#endif
nserror
Enumeration of error codes.
Definition: errors.h:29
browser_mouse_state
Mouse state.
Definition: mouse.h:43
scrollbar_mouse_status
Scrollbar mouse input status flags.
Definition: scrollbar.h:70
@ SCROLLBAR_MOUSE_PLFT
Hover: scroll page left.
Definition: scrollbar.h:80
@ SCROLLBAR_MOUSE_UP
Hover: scroll up.
Definition: scrollbar.h:74
@ SCROLLBAR_MOUSE_PUP
Hover: scroll page up.
Definition: scrollbar.h:75
@ SCROLLBAR_MOUSE_RGT
Hover: scroll right.
Definition: scrollbar.h:83
@ SCROLLBAR_MOUSE_PDWN
Hover: scroll page down.
Definition: scrollbar.h:77
@ SCROLLBAR_MOUSE_DWN
Hover: scroll down.
Definition: scrollbar.h:78
@ SCROLLBAR_MOUSE_BOTH
Scrolling both bars.
Definition: scrollbar.h:73
@ SCROLLBAR_MOUSE_PRGT
Hover: scroll page right.
Definition: scrollbar.h:82
@ SCROLLBAR_MOUSE_NONE
Not relevant.
Definition: scrollbar.h:71
@ SCROLLBAR_MOUSE_LFT
Hover: scroll left.
Definition: scrollbar.h:79
@ SCROLLBAR_MOUSE_USED
Took action with input.
Definition: scrollbar.h:72
@ SCROLLBAR_MOUSE_HRZ
Hover: horiz.
Definition: scrollbar.h:81
@ SCROLLBAR_MOUSE_VRT
Hover: vert.
Definition: scrollbar.h:76
bool scrollbar_is_horizontal(struct scrollbar *s)
Check orientation of the scrollbar.
Definition: scrollbar.c:695
const char * scrollbar_mouse_status_to_message(scrollbar_mouse_status status)
Get a status bar message from a scrollbar mouse input status.
Definition: scrollbar.c:889
scrollbar_mouse_status scrollbar_mouse_action(struct scrollbar *s, browser_mouse_state mouse, int x, int y)
Handle mouse actions other then drag ends.
Definition: scrollbar.c:769
scrollbar_msg
scrollbar message types
Definition: scrollbar.h:46
@ SCROLLBAR_MSG_MOVED
the scroll value has changed
Definition: scrollbar.h:47
@ SCROLLBAR_MSG_SCROLL_START
a scrollbar drag has started, all mouse events should be passed to the scrollbar regardless of the co...
Definition: scrollbar.h:48
@ SCROLLBAR_MSG_SCROLL_FINISHED
cancel a scrollbar drag
Definition: scrollbar.h:53
void scrollbar_make_pair(struct scrollbar *horizontal, struct scrollbar *vertical)
Connect a horizontal and a vertical scrollbar into a pair so that they co-operate during 2D drags.
Definition: scrollbar.c:990
int scrollbar_get_offset(struct scrollbar *s)
Get the current scroll offset to the visible part of the full area.
Definition: scrollbar.c:628
nserror scrollbar_create(bool horizontal, int length, int full_size, int visible_size, void *client_data, scrollbar_client_callback client_callback, struct scrollbar **s)
Create a scrollbar.
Definition: scrollbar.c:93
nserror scrollbar_redraw(struct scrollbar *s, int x, int y, const struct rect *clip, float scale, const struct redraw_context *ctx)
Redraw a part of the scrollbar.
Definition: scrollbar.c:239
void(* scrollbar_client_callback)(void *client_data, struct scrollbar_msg_data *scrollbar_data)
Client callback for the scrollbar.
Definition: scrollbar.h:93
void * scrollbar_get_data(struct scrollbar *s)
Get the scrollbar's client data.
Definition: scrollbar.c:1004
bool scrollbar_scroll(struct scrollbar *s, int change)
Scroll the scrollbar by given amount.
Definition: scrollbar.c:562
void scrollbar_destroy(struct scrollbar *s)
Destroy a scrollbar.
Definition: scrollbar.c:138
void scrollbar_set(struct scrollbar *s, int value, bool bar_pos)
Set the scroll value of the scrollbar.
Definition: scrollbar.c:512
void scrollbar_start_content_drag(struct scrollbar *s, int x, int y)
Called when the content is being dragged to the scrollbars have to adjust.
Definition: scrollbar.c:981
void scrollbar_set_extents(struct scrollbar *s, int length, int visible_size, int full_size)
Set the length of the scrollbar widget, the size of the visible area, and the size of the full area.
Definition: scrollbar.c:640
void scrollbar_mouse_drag_end(struct scrollbar *s, browser_mouse_state mouse, int x, int y)
Handle end of mouse drags.
Definition: scrollbar.c:933
Rectangle coordinates.
Definition: types.h:40
Redraw context.
Definition: plotters.h:51
scrollbar message context data
Definition: scrollbar.h:59
struct scrollbar * scrollbar
Definition: scrollbar.h:60
scrollbar_msg msg
Definition: scrollbar.h:61
Scrollbar context.
Definition: scrollbar.c:44
void * client_data
User data passed to the callback.
Definition: scrollbar.c:66
static nserror clip(const struct redraw_context *ctx, const struct rect *clip)
Sets a clip rectangle for subsequent plot operations.
Definition: plot.c:357