Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  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. /** \file
  20.  * Scrollbar widget (interface).
  21.  */
  22.  
  23. #ifndef _NETSURF_DESKTOP_SCROLLBAR_H_
  24. #define _NETSURF_DESKTOP_SCROLLBAR_H_
  25.  
  26. #include <stdbool.h>
  27. #include <limits.h>
  28.  
  29. #include "desktop/browser.h"
  30.  
  31. #define SCROLLBAR_WIDTH 16
  32.  
  33. /* Region dependent values for scrollbar_scroll function */
  34. #define SCROLL_TOP              INT_MIN
  35. #define SCROLL_PAGE_UP          INT_MIN + 1
  36. #define SCROLL_PAGE_DOWN        INT_MAX - 1
  37. #define SCROLL_BOTTOM           INT_MAX
  38.  
  39. struct scrollbar;
  40.  
  41. typedef enum {
  42.         SCROLLBAR_MSG_MOVED,            /* the scroll value has changed */
  43.         SCROLLBAR_MSG_SCROLL_START,     /* a scrollbar drag has started, all
  44.                                          * mouse events should be passed to
  45.                                          * the scrollbar regardless of the
  46.                                          * coordinates
  47.                                          */
  48.         SCROLLBAR_MSG_SCROLL_FINISHED,  /* cancel the above */
  49. } scrollbar_msg;
  50.  
  51. struct scrollbar_msg_data {
  52.         struct scrollbar *scrollbar;
  53.         scrollbar_msg msg;
  54.         int scroll_offset;
  55.         int x0, y0, x1, y1;
  56. };
  57.  
  58. /**
  59.  * Client callback for the scrollbar.
  60.  *
  61.  * \param client_data           user data passed at scroll creation
  62.  * \param scrollbar_data        scrollbar message data
  63.  */
  64. typedef void(*scrollbar_client_callback)(void *client_data,
  65.                 struct scrollbar_msg_data *scrollbar_data);
  66.  
  67.  
  68. /**
  69.  * Create a scrollbar.
  70.  *
  71.  * \param horizontal            true = horizontal scrollbar, false = vertical
  72.  * \param length                length of scrollbar widget
  73.  * \param full_size             length of contained scrollable area
  74.  * \param visible_size          length of visible part of scrollable area
  75.  * \param client_data           data for the client callback
  76.  * \param client_callback       client callback for scrollbar events
  77.  * \param s                     updated to point at the newly created scrollbar
  78.  * \return      true if scrollbar has been created succesfully or false on
  79.  *              memory exhaustion
  80.  */
  81. bool scrollbar_create(bool horizontal, int length, int full_size,
  82.                 int visible_size, void *client_data,
  83.                 scrollbar_client_callback client_callback,
  84.                 struct scrollbar **s);
  85.  
  86. /**
  87.  * Destroy a scrollbar.
  88.  *
  89.  * \param s     the scrollbar to be destroyed
  90.  */
  91. void scrollbar_destroy(struct scrollbar *s);
  92.  
  93. /**
  94.  * Redraw a part of the scrollbar.
  95.  *
  96.  * \param s     the scrollbar to be redrawn
  97.  * \param x     the X coordinate to draw the scrollbar at
  98.  * \param y     the Y coordinate to draw the scrollbar at
  99.  * \param clip  the clipping rectangle
  100.  * \param scale scale for the redraw
  101.  * \param ctx   current redraw context
  102.  * \return      true on succes false otherwise
  103.  */
  104. bool scrollbar_redraw(struct scrollbar *s, int x, int y,
  105.                 const struct rect *clip, float scale,
  106.                 const struct redraw_context *ctx);
  107.  
  108. /**
  109.  * Set the scroll value of the scrollbar.
  110.  *
  111.  * \param s             the scrollbar to have the value set
  112.  * \param value         the new value to be set
  113.  * \param bar_pos       true if the value is for the scrollbar indication bar
  114.  *                      position, false if it is for the scrolled area offset
  115.  */
  116. void scrollbar_set(struct scrollbar *s, int value, bool bar_pos);
  117.  
  118. /**
  119.  * Scroll the scrollbar by given amount.
  120.  *
  121.  * \param s             the scrollbar to be scrolled
  122.  * \param change        the change in scroll offset required (in px)
  123.  * \return true iff the scrollbar was moved.
  124.  */
  125. bool scrollbar_scroll(struct scrollbar *s, int change);
  126.  
  127. /**
  128.  * Get the current scroll offset to the visible part of the full area.
  129.  *
  130.  * \param s     the scrollbar to get the scroll offset value from
  131.  * \return      current scroll offset
  132.  */
  133. int scrollbar_get_offset(struct scrollbar *s);
  134.  
  135. /**
  136.  * Set the length of the scrollbar widget, the size of the visible area, and the
  137.  * size of the full area.
  138.  *
  139.  * \param s             the scrollbar to set the values for
  140.  * \param length        -1 or the new scrollbar widget length
  141.  * \param visible_size  -1 or the new size of the visible area
  142.  * \param full_size     -1 or the new size of the full contained area
  143.  */
  144. void scrollbar_set_extents(struct scrollbar *s, int length,
  145.                 int visible_size, int full_size);
  146.  
  147. /**
  148.  * Check orientation of the scrollbar.
  149.  *
  150.  * \param s     the scrollbar to check the orientation of
  151.  * \return      true for a horizontal scrollbar, else false (vertical)
  152.  */
  153. bool scrollbar_is_horizontal(struct scrollbar *s);
  154.  
  155. /**
  156.  * Handle mouse actions other then drag ends.
  157.  *
  158.  * \param s     the scrollbar which gets the mouse action
  159.  * \param mouse mouse state
  160.  * \param x     X coordinate of the mouse
  161.  * \param y     Y coordinate of the mouse
  162.  * \return      message for the status bar or NULL on failure
  163.  */
  164. const char *scrollbar_mouse_action(struct scrollbar *s,
  165.                 browser_mouse_state mouse, int x, int y);
  166.  
  167. /**
  168.  * Handle end of mouse drags.
  169.  *
  170.  * \param s     the scrollbar for which the drag ends
  171.  * \param mouse mouse state
  172.  * \param x     X coordinate of the mouse
  173.  * \param y     Y coordinate of the mouse
  174.  */
  175. void scrollbar_mouse_drag_end(struct scrollbar *s,
  176.                 browser_mouse_state mouse, int x, int y);
  177.  
  178. /**
  179.  * Called when the content is being dragged to the scrollbars have to adjust.
  180.  * If the content has both scrollbars, and scrollbar_make_pair has beed called
  181.  * before, only the one scroll which will receive further mouse events has to be
  182.  * passed.
  183.  *
  184.  * \param s     one of the the scrollbars owned by the dragged content
  185.  * \param x     X coordinate of mouse during drag start
  186.  * \param y     Y coordinate of mouse during drag start
  187.  */
  188. void scrollbar_start_content_drag(struct scrollbar *s, int x, int y);
  189.  
  190. /**
  191.  * Connect a horizontal and a vertical scrollbar into a pair so that they
  192.  * co-operate during 2D drags.
  193.  *
  194.  * \param horizontal    the scrollbar used for horizontal scrolling
  195.  * \param vertical      the scrollbar used for vertical scrolling
  196.  */
  197. void scrollbar_make_pair(struct scrollbar *horizontal,
  198.                 struct scrollbar *vertical);
  199.  
  200. /**
  201.  * Get the scrollbar's client data
  202.  *
  203.  * \param s     the scrollbar to get the client data from
  204.  * \return      client data
  205.  */
  206. void *scrollbar_get_data(struct scrollbar *s);
  207.  
  208. #endif
  209.