NetSurf
Data Structures | Functions
scrollbar.c File Reference

implementation of scrollbar widget. More...

#include <stdbool.h>
#include <stdlib.h>
#include "utils/log.h"
#include "utils/messages.h"
#include "utils/utils.h"
#include "utils/nscolour.h"
#include "utils/nsoption.h"
#include "netsurf/browser_window.h"
#include "netsurf/mouse.h"
#include "netsurf/plotters.h"
#include "desktop/system_colour.h"
#include "desktop/scrollbar.h"
Include dependency graph for scrollbar.c:

Go to the source code of this file.

Data Structures

struct  scrollbar
 Scrollbar context. More...
 

Functions

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. More...
 
void scrollbar_destroy (struct scrollbar *s)
 Destroy a scrollbar. More...
 
static nserror scrollbar_rectangle (const struct redraw_context *ctx, struct rect *area, colour c, bool inset)
 Draw an outline rectangle common to several scrollbar elements. More...
 
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. More...
 
void scrollbar_set (struct scrollbar *s, int value, bool bar_pos)
 Set the scroll value of the scrollbar. More...
 
bool scrollbar_scroll (struct scrollbar *s, int change)
 Scroll the scrollbar by given amount. More...
 
int scrollbar_get_offset (struct scrollbar *s)
 Get the current scroll offset to the visible part of the full area. More...
 
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. More...
 
bool scrollbar_is_horizontal (struct scrollbar *s)
 Check orientation of the scrollbar. More...
 
static void scrollbar_drag_start_internal (struct scrollbar *s, int x, int y, bool content_drag, bool pair)
 Internal procedure used for starting a drag scroll for a scrollbar. More...
 
scrollbar_mouse_status scrollbar_mouse_action (struct scrollbar *s, browser_mouse_state mouse, int x, int y)
 Handle mouse actions other then drag ends. More...
 
const char * scrollbar_mouse_status_to_message (scrollbar_mouse_status status)
 Get a status bar message from a scrollbar mouse input status. More...
 
void scrollbar_mouse_drag_end (struct scrollbar *s, browser_mouse_state mouse, int x, int y)
 Handle end of mouse drags. More...
 
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. More...
 
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. More...
 
void * scrollbar_get_data (struct scrollbar *s)
 Get the scrollbar's client data. More...
 

Detailed Description

implementation of scrollbar widget.

Definition in file scrollbar.c.

Function Documentation

◆ scrollbar_create()

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.

Parameters
horizontaltrue = horizontal scrollbar, false = vertical
lengthlength of scrollbar widget
full_sizelength of contained scrollable area
visible_sizelength of visible part of scrollable area
client_datadata for the client callback
client_callbackclient callback for scrollbar events
supdated to point at the newly created scrollbar
Returns
NSERROR_OK and s updated if scrollbar has been created succesfully or eror code and s set to NULL on faliure;

Definition at line 93 of file scrollbar.c.

References scrollbar::bar_len, scrollbar::bar_pos, scrollbar::client_callback, scrollbar::client_data, scrollbar::drag_content, scrollbar::dragging, scrollbar::full_size, scrollbar::horizontal, scrollbar::length, NSERROR_NOMEM, NSERROR_OK, scrollbar::offset, scrollbar::pair, scrollbar::pair_drag, SCROLLBAR_WIDTH, and scrollbar::visible_size.

Referenced by box_handle_scrollbars(), browser_window_handle_scrollbars(), form_open_select_menu(), and textarea_reflow_multiline().

Here is the caller graph for this function:

◆ scrollbar_destroy()

void scrollbar_destroy ( struct scrollbar s)

Destroy a scrollbar.

Parameters
sthe scrollbar to be destroyed

Definition at line 138 of file scrollbar.c.

References scrollbar::pair.

Referenced by box_free_box(), box_handle_scrollbars(), box_talloc_destructor(), browser_window_destroy_internal(), browser_window_handle_scrollbars(), form_free_select_menu(), textarea_destroy(), and textarea_reflow_multiline().

Here is the caller graph for this function:

◆ scrollbar_drag_start_internal()

static void scrollbar_drag_start_internal ( struct scrollbar s,
int  x,
int  y,
bool  content_drag,
bool  pair 
)
static

Internal procedure used for starting a drag scroll for a scrollbar.

Parameters
sthe scrollbar to start the drag for
xthe X coordinate of the drag start
ythe Y coordinate of the drag start
content_dragwhether this should be a reverse drag (used when the user drags the content area, rather than the scrollbar)
pairwhether the drag is a '2D' scroll
Todo:
some proper numbers please!

Definition at line 712 of file scrollbar.c.

References scrollbar::bar_pos, scrollbar::client_callback, scrollbar::client_data, scrollbar::drag_content, scrollbar::drag_start_coord, scrollbar::drag_start_pos, scrollbar::dragging, scrollbar::horizontal, scrollbar_msg_data::msg, scrollbar::offset, scrollbar::pair, scrollbar::pair_drag, and SCROLLBAR_MSG_SCROLL_START.

Referenced by scrollbar_mouse_action(), and scrollbar_start_content_drag().

Here is the caller graph for this function:

◆ scrollbar_get_data()

void * scrollbar_get_data ( struct scrollbar s)

Get the scrollbar's client data.

Parameters
sthe scrollbar to get the client data from
Returns
client data

Definition at line 1004 of file scrollbar.c.

References scrollbar::client_data.

Referenced by box_handle_scrollbars(), box_talloc_destructor(), html_overflow_scroll_drag_end(), and mouse_action_drag_scrollbar().

Here is the caller graph for this function:

◆ scrollbar_get_offset()

int scrollbar_get_offset ( struct scrollbar s)

◆ scrollbar_is_horizontal()

bool scrollbar_is_horizontal ( struct scrollbar s)

Check orientation of the scrollbar.

Parameters
sthe scrollbar to check the orientation of
Returns
true for a horizontal scrollbar, else false (vertical)

Definition at line 695 of file scrollbar.c.

References scrollbar::horizontal.

Referenced by browser_window_scroll_callback(), html_overflow_scroll_drag_end(), and mouse_action_drag_scrollbar().

Here is the caller graph for this function:

◆ scrollbar_make_pair()

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.

Parameters
horizontalthe scrollbar used for horizontal scrolling
verticalthe scrollbar used for vertical scrolling

Definition at line 990 of file scrollbar.c.

References scrollbar::horizontal, and scrollbar::pair.

Referenced by box_handle_scrollbars(), browser_window_handle_scrollbars(), and textarea_reflow_multiline().

Here is the caller graph for this function:

◆ scrollbar_mouse_action()

scrollbar_mouse_status scrollbar_mouse_action ( struct scrollbar s,
browser_mouse_state  mouse,
int  x,
int  y 
)

Handle mouse actions other then drag ends.

Parameters
sthe scrollbar which gets the mouse action
mousemouse state
xX coordinate of the mouse
yY coordinate of the mouse
Returns
the scrollbar mouse status

Definition at line 769 of file scrollbar.c.

References scrollbar::bar_len, scrollbar::bar_pos, BROWSER_MOUSE_DRAG_1, BROWSER_MOUSE_DRAG_2, BROWSER_MOUSE_DRAG_ON, BROWSER_MOUSE_HOLDING_1, BROWSER_MOUSE_HOLDING_2, BROWSER_MOUSE_PRESS_1, BROWSER_MOUSE_PRESS_2, scrollbar::drag_content, scrollbar::drag_start_coord, scrollbar::drag_start_pos, scrollbar::dragging, scrollbar::horizontal, scrollbar::length, scrollbar::offset, scrollbar::pair, scrollbar::pair_drag, scrollbar_drag_start_internal(), scrollbar_mouse_action(), SCROLLBAR_MOUSE_BOTH, SCROLLBAR_MOUSE_DWN, SCROLLBAR_MOUSE_HRZ, SCROLLBAR_MOUSE_LFT, SCROLLBAR_MOUSE_NONE, SCROLLBAR_MOUSE_PDWN, SCROLLBAR_MOUSE_PLFT, SCROLLBAR_MOUSE_PRGT, SCROLLBAR_MOUSE_PUP, SCROLLBAR_MOUSE_RGT, SCROLLBAR_MOUSE_UP, SCROLLBAR_MOUSE_VRT, scrollbar_set(), SCROLLBAR_WIDTH, scrollbar_msg_data::x0, scrollbar_msg_data::x1, scrollbar_msg_data::y0, and scrollbar_msg_data::y1.

Referenced by browser_window_mouse_click_internal(), browser_window_mouse_track_internal(), form_select_mouse_action(), mouse_action_drag_none(), mouse_action_drag_scrollbar(), scrollbar_mouse_action(), and textarea_mouse_scrollbar_action().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ scrollbar_mouse_drag_end()

void scrollbar_mouse_drag_end ( struct scrollbar s,
browser_mouse_state  mouse,
int  x,
int  y 
)

Handle end of mouse drags.

Parameters
sthe scrollbar for which the drag ends
mousemouse state
xX coordinate of the mouse
yY coordinate of the mouse

Definition at line 933 of file scrollbar.c.

References scrollbar::client_callback, scrollbar::client_data, scrollbar::drag_content, scrollbar::drag_start_coord, scrollbar::drag_start_pos, scrollbar::dragging, scrollbar::horizontal, scrollbar_msg_data::msg, scrollbar::pair, scrollbar::pair_drag, SCROLLBAR_MSG_SCROLL_FINISHED, and scrollbar_set().

Referenced by browser_window_mouse_drag_end(), form_select_mouse_drag_end(), html_overflow_scroll_drag_end(), and textarea_drag_end().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ scrollbar_mouse_status_to_message()

const char * scrollbar_mouse_status_to_message ( scrollbar_mouse_status  status)

Get a status bar message from a scrollbar mouse input status.

Parameters
statusStatus to convert to message
Returns
Message for the status bar or NULL on failure

Definition at line 889 of file scrollbar.c.

References messages_get(), SCROLLBAR_MOUSE_DWN, SCROLLBAR_MOUSE_HRZ, SCROLLBAR_MOUSE_LFT, SCROLLBAR_MOUSE_PDWN, SCROLLBAR_MOUSE_PLFT, SCROLLBAR_MOUSE_PRGT, SCROLLBAR_MOUSE_PUP, SCROLLBAR_MOUSE_RGT, SCROLLBAR_MOUSE_UP, SCROLLBAR_MOUSE_USED, and SCROLLBAR_MOUSE_VRT.

Referenced by browser_window_mouse_click_internal(), browser_window_mouse_track_internal(), form_select_mouse_action(), gadget_mouse_action(), mouse_action_drag_none(), and mouse_action_drag_scrollbar().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ scrollbar_rectangle()

static nserror scrollbar_rectangle ( const struct redraw_context ctx,
struct rect area,
colour  c,
bool  inset 
)
inlinestatic

Draw an outline rectangle common to several scrollbar elements.

Parameters
ctxcurrent redraw context
areathe area of the scrollbar
cbase colour of the outline, the other colours are created by lightening or darkening this one
insettrue for inset outline, false for an outset one
Returns
NSERROR_OK on success else error code

Definition at line 158 of file scrollbar.c.

References blend_colour, darken_colour, lighten_colour, line(), plotter_table::line, NSERROR_OK, redraw_context::plot, PLOT_OP_TYPE_SOLID, plot_style_int_to_fixed, plot_style_s::stroke_colour, plot_style_s::stroke_type, rect::x0, rect::x1, rect::y0, and rect::y1.

Referenced by scrollbar_redraw().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ scrollbar_redraw()

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.

Parameters
sthe scrollbar to be redrawn
xthe X coordinate to draw the scrollbar at
ythe Y coordinate to draw the scrollbar at
clipthe clipping rectangle
scalescale for the redraw
ctxcurrent redraw context
Returns
NSERROR_OK on success otherwise error code

Definition at line 239 of file scrollbar.c.

References scrollbar::bar_len, scrollbar::bar_pos, clip(), plot_style_s::fill_colour, plot_style_s::fill_type, scrollbar::horizontal, scrollbar::length, NSCOLOUR_BUTTON_BG, NSCOLOUR_BUTTON_FG, NSCOLOUR_SCROLL_WELL, nscolours, NSERROR_OK, redraw_context::plot, PLOT_OP_TYPE_SOLID, plotter_table::polygon, plotter_table::rectangle, scrollbar_rectangle(), SCROLLBAR_WIDTH, rect::x0, rect::x1, rect::y0, and rect::y1.

Referenced by browser_window_redraw(), form_redraw_select_menu(), html_redraw_box(), and textarea_redraw().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ scrollbar_scroll()

bool scrollbar_scroll ( struct scrollbar s,
int  change 
)

Scroll the scrollbar by given amount.

Parameters
sthe scrollbar to be scrolled
changethe change in scroll offset required (in px)
Returns
true iff the scrollbar was moved.

Definition at line 562 of file scrollbar.c.

References scrollbar::bar_pos, scrollbar::client_callback, scrollbar::client_data, scrollbar::full_size, scrollbar::length, scrollbar_msg_data::msg, scrollbar::offset, SCROLL_BOTTOM, SCROLL_PAGE_DOWN, SCROLL_PAGE_UP, SCROLL_TOP, SCROLLBAR_MSG_MOVED, SCROLLBAR_WIDTH, and scrollbar::visible_size.

Referenced by browser_window_scroll_at_point_internal(), html_scroll_at_point(), and textarea_scroll().

Here is the caller graph for this function:

◆ scrollbar_set()

void scrollbar_set ( struct scrollbar s,
int  value,
bool  bar_pos 
)

Set the scroll value of the scrollbar.

Parameters
sthe scrollbar to have the value set
valuethe new value to be set
bar_postrue if the value is for the scrollbar indication bar position, false if it is for the scrolled area offset

Definition at line 512 of file scrollbar.c.

References scrollbar::bar_len, scrollbar::bar_pos, scrollbar::client_callback, scrollbar::client_data, scrollbar::full_size, scrollbar::length, scrollbar_msg_data::msg, scrollbar::offset, SCROLLBAR_MSG_MOVED, SCROLLBAR_WIDTH, and scrollbar::visible_size.

Referenced by browser_window_set_scroll(), html_object_callback(), scrollbar_mouse_action(), scrollbar_mouse_drag_end(), and textarea_scroll_visible().

Here is the caller graph for this function:

◆ scrollbar_set_extents()

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.

Parameters
sthe scrollbar to set the values for
length-1 or the new scrollbar widget length
visible_size-1 or the new size of the visible area
full_size-1 or the new size of the full contained area

Definition at line 640 of file scrollbar.c.

References scrollbar::bar_len, scrollbar::bar_pos, scrollbar::client_callback, scrollbar::client_data, scrollbar::full_size, scrollbar::length, scrollbar_msg_data::msg, scrollbar::offset, SCROLLBAR_MSG_MOVED, SCROLLBAR_WIDTH, and scrollbar::visible_size.

Referenced by box_handle_scrollbars(), browser_window_handle_scrollbars(), and textarea_reflow_multiline().

Here is the caller graph for this function:

◆ scrollbar_start_content_drag()

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.

If the content has both scrollbars, and scrollbar_make_pair has beed called before, only the one scroll which will receive further mouse events has to be passed.

Parameters
sone of the the scrollbars owned by the dragged content
xX coordinate of mouse during drag start
yY coordinate of mouse during drag start

Definition at line 981 of file scrollbar.c.

References scrollbar_drag_start_internal().

Referenced by html_box_drag_start().

Here is the call graph for this function:
Here is the caller graph for this function: