Subversion Repositories Kolibri OS

Rev

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

  1. /*
  2.  * Copyright 2010 Vincent Sanders <vince@simtec.co.uk>
  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. #ifndef NETSURF_FB_FBTK_WIDGET_H
  20. #define NETSURF_FB_FBTK_WIDGET_H
  21.  
  22. #include <stdbool.h>
  23.  
  24. enum fbtk_widgettype_e {
  25.         FB_WIDGET_TYPE_ROOT = 0,
  26.         FB_WIDGET_TYPE_WINDOW,
  27.         FB_WIDGET_TYPE_BITMAP,
  28.         FB_WIDGET_TYPE_FILL,
  29.         FB_WIDGET_TYPE_TEXT,
  30.         FB_WIDGET_TYPE_HSCROLL,
  31.         FB_WIDGET_TYPE_VSCROLL,
  32.         FB_WIDGET_TYPE_USER,
  33. };
  34.  
  35.  
  36. /** Widget description.
  37.  *
  38.  * A widget is an entry in a tree structure which represents a
  39.  * rectangular area with co-ordinates relative to its parent widget.
  40.  * This area has a distinct set of callback operations for handling
  41.  * events which occour within its boundries. A widget may have an
  42.  * arbitrary number of child widgets. The order within the tree
  43.  * determines a widgets z order.
  44.  *
  45.  *                                         ---
  46.  *                                          A
  47.  *                                          |
  48.  *                                  +----------+
  49.  *                             +--->| Button 3 |
  50.  *                             |    +----------+
  51.  *                             |       |    A
  52.  *                             |       V    |
  53.  *                             |    +----------+
  54.  *                             |    | Button 2 |
  55.  *                             |    +----------+
  56.  *                             |       |    A
  57.  *                             |       V    |
  58.  *                             |    +----------+
  59.  *                             |    | Button 1 |
  60.  *                             |    +----------+
  61.  *                             |       |    A
  62.  *                             |       V    |
  63.  *                      ---    |    +----------+
  64.  *                       A     | +->|  Filled  |
  65.  *                       |     | |  +----------+
  66.  *                +----------+ | |     |
  67.  *          +---->|          |-+ |     V
  68.  *          |     | Window 1 |   |    ---  ---
  69.  *          |     |          |---+          A
  70.  *          |     +----------+              |
  71.  *          |        |    A         +----------+               ---
  72.  *          |        |    |    +--->| Button 2 |                A
  73.  *          |        |    |    |    +----------+                |
  74.  *          |        |    |    |       |    A         +-------------+
  75.  *          |        |    |    |       |    |    +--->|  Button Up  |
  76.  *          |        |    |    |       |    |    |    +-------------+
  77.  *          |        |    |    |       |    |    |        |     A
  78.  *          |        |    |    |       |    |    |        V     |
  79.  *          |        |    |    |       |    |    |    +-------------+
  80.  *          |        |    |    |       |    |    |    | Button Down |
  81.  *          |        |    |    |       |    |    |    +-------------+
  82.  *          |        |    |    |       |    |    |        |     A
  83.  *          |        |    |    |       |    |    |        V     |
  84.  *          |        |    |    |       |    |    |    +-------------+
  85.  *          |        |    |    |       |    |    | +->|   Scroller  |
  86.  *          |        |    |    |       V    |    | |  +-------------+
  87.  *          |        |    |    |    +----------+ | |      |
  88.  *          |        |    |    |    |          |-+ |      V
  89.  *          |        |    |    |    | V Scroll |   |     ---
  90.  *          |        |    |    |    |          |---+
  91.  *          |        |    |    |    +----------+
  92.  *          |        |    |    |       |    A
  93.  *          |        |    |    |       V    |
  94.  *          |        |    |    |    +----------+
  95.  *          |        |    |    | +->| Button 1 |
  96.  *          |        |    |    | |  +----------+
  97.  *          |     +----------+ | |     |
  98.  *          |     |          |-+ |     V
  99.  *          |     | Window 2 |   |    ---
  100.  *          |     |          |---+
  101.  *          |     +----------+
  102.  *          |        |    A
  103.  *          |        V    |
  104.  *          |    +------------+
  105.  *     ---  |    | Background |
  106.  *      A   | +->|   Bitmap   |
  107.  *      |   | |  +------------+
  108.  * +------+ | |      |
  109.  * |      |-+ |      V
  110.  * | Root |   |     ---
  111.  * |      |---+
  112.  * +------+
  113.  *   |
  114.  *   V
  115.  *  ---
  116.  *
  117.  * Every widget is contained within this generic wrapper. The
  118.  * integrated union provides for data specific to a widget type.
  119.  */
  120. struct fbtk_widget_s {
  121.         struct fbtk_widget_s *next; /* next lower z ordered widget in tree */
  122.         struct fbtk_widget_s *prev; /* next higher z ordered widget in tree */
  123.  
  124.         struct fbtk_widget_s *parent; /* parent widget */
  125.  
  126.         struct fbtk_widget_s *first_child; /* first child widget */
  127.         struct fbtk_widget_s *last_child; /* last child widget */
  128.  
  129.         /* flags */
  130.         bool mapped; /**< The widget is mapped/visible . */
  131.  
  132.         /* Generic properties */
  133.         int x;
  134.         int y;
  135.         int width;
  136.         int height;
  137.         colour bg;
  138.         colour fg;
  139.  
  140.         /* event callback handlers */
  141.         fbtk_callback callback[FBTK_CBT_END];
  142.         void *callback_context[FBTK_CBT_END];
  143.  
  144.         /* widget redraw */
  145.         struct {
  146.                 bool child; /* A child of this widget requires redrawing */
  147.                 bool needed; /* the widget requires redrawing */
  148.                 int x;
  149.                 int y;
  150.                 int width;
  151.                 int height;
  152.         } redraw;
  153.  
  154.         enum fbtk_widgettype_e type; /**< The type of the widget */
  155.  
  156.  
  157.         union {
  158.                 /* toolkit base handle */
  159.                 struct {
  160.                         nsfb_t *fb;
  161.                         struct fbtk_widget_s *prev; /* previous widget pointer wasin */
  162.                         struct fbtk_widget_s *grabbed; /* widget that has grabbed pointer movement. */
  163.                         struct fbtk_widget_s *input;
  164.  
  165.                         /* caret */
  166.                         struct {
  167.                                 struct fbtk_widget_s *owner; /* widget / NULL */
  168.                                 int x; /* relative to owner */
  169.                                 int y; /* relative to owner */
  170.                                 int height;
  171.                                 void (*remove_cb)(fbtk_widget_t *widget);
  172.                         } caret;
  173.                 } root;
  174.  
  175.                 /* bitmap */
  176.                 struct {
  177.                         struct fbtk_bitmap *bitmap;
  178.                 } bitmap;
  179.  
  180.                 /* text */
  181.                 struct {
  182.                         char* text;
  183.                         bool outline;
  184.                         fbtk_enter_t enter;
  185.                         void *pw;
  186.                         int idx; /* caret pos in text */
  187.                         int len; /* text length */
  188.                         int width; /* text width in px */
  189.                         int idx_offset; /* caret pos in pixels */
  190.                 } text;
  191.  
  192.                 /* application driven widget */
  193.                 struct {
  194.                         void *pw; /* private data for user widget */
  195.                 } user;
  196.  
  197.                 struct {
  198.                         int minimum; /* lowest value of scrollbar */
  199.                         int maximum; /* highest value of scrollbar */
  200.                         int thumb; /* size of bar representing a page */
  201.                         int page; /* amount to page document */
  202.                         int position; /* position of bar */
  203.                         int drag; /* offset to start of drag */
  204.                         int drag_position; /* indicator bar pos at drag start */
  205.                         struct fbtk_widget_s *btnul; /* scroll button up/left */
  206.                         struct fbtk_widget_s *btndr; /* scroll button down/right*/
  207.                 } scroll;
  208.  
  209.         } u;
  210. };
  211.  
  212.  
  213. /* These functions are not considered part of the public API but are
  214.  * not static as they are used by the higher level widget provision
  215.  * routines
  216.  */
  217.  
  218.  
  219. /** creates a new widget and insert it into to hierachy.
  220.  *
  221.  * The widget is set to defaults of false, 0 or NULL.
  222.  *
  223.  * @param parent The parent widget. The new widget will be added with
  224.  *               the shallowest z order relative to its siblings.
  225.  * @param type The type of the widget.
  226.  * @param x The x co-ordinate relative to the parent widget.
  227.  * @param y The y co-ordinate relative to the parent widget.
  228.  * @param width the widgets width. This will be clipped to the parent, if
  229.  *          the value is 0 the largest extent which can fit within the parent
  230.  *          is used, if the value is negative the largest value that will fit
  231.  *          within the parent less the value given will be used.
  232.  * @param height the widgets width. This will be clipped to the parent, if
  233.  *          the value is 0 the largest extent which can fit within the parent
  234.  *          is used, if the value is negative the largest value that will fit
  235.  *          within the parent less the value given will be used.
  236.  */
  237. fbtk_widget_t *fbtk_widget_new(fbtk_widget_t *parent, enum fbtk_widgettype_e type, int x, int y, int width, int height);
  238.  
  239. /** find the root widget from any widget in the toolkit hierarchy.
  240.  *
  241.  * @param widget Any widget.
  242.  * @return The root widget or NULL if \a widget was not valid.
  243.  */
  244. fbtk_widget_t *fbtk_get_root_widget(fbtk_widget_t *widget);
  245.  
  246. /** set pointer to bitmap in context.
  247.  *
  248.  * widget helper callback to set cursor image to the bitmap passed in
  249.  * the callbacks private data.
  250.  */
  251. int fbtk_set_ptr(fbtk_widget_t *widget, fbtk_callback_info *cbi);
  252.  
  253. #endif
  254.  
  255. /*
  256.  * Local Variables:
  257.  * c-basic-offset:8
  258.  * End:
  259.  */
  260.