Subversion Repositories Kolibri OS

Rev

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

  1. /*
  2.  * Copyright 2004 Richard Wilson <not_ginger_matt@users.sourceforge.net>
  3.  * Copyright 2009 Paul Blokus <paul_pl@users.sourceforge.net>
  4.  *
  5.  * This file is part of NetSurf, http://www.netsurf-browser.org/
  6.  *
  7.  * NetSurf is free software; you can redistribute it and/or modify
  8.  * it under the terms of the GNU General Public License as published by
  9.  * the Free Software Foundation; version 2 of the License.
  10.  *
  11.  * NetSurf is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  18.  */
  19.  
  20. /** \file
  21.  * Generic tree handling (interface).
  22.  */
  23.  
  24. #ifndef _NETSURF_DESKTOP_TREE_H_
  25. #define _NETSURF_DESKTOP_TREE_H_
  26.  
  27. #include <stdbool.h>
  28. #include <stdint.h>
  29.  
  30. #include "desktop/browser.h"
  31. #include "image/bitmap.h"
  32.  
  33. struct hlcache_handle;
  34.  
  35. /* Tree flags */
  36. enum tree_flags {
  37.         TREE_NO_FLAGS = 0,
  38.         TREE_NO_DRAGS = 1,
  39.         TREE_NO_FURNITURE = 2,
  40.         TREE_SINGLE_SELECT = 4,
  41.         TREE_NO_SELECT = 8,
  42.         TREE_MOVABLE = 16,
  43.         TREE_DELETE_EMPTY_DIRS = 32, /**< if the last child of a
  44.                                       * directory is deleted the
  45.                                       * directory will be deleted
  46.                                       * too.
  47.                                       */
  48. };
  49.  
  50. /** A "flag" value to indicate the element data contains title
  51.  * text. This value should be the first node_element in every
  52.  * node. All other values should be different than this one. The term
  53.  * flag is misused as it is actually a value used by the API consumer
  54.  * to indicate teh type of data a node element contains.
  55.  */
  56. #define TREE_ELEMENT_TITLE      0x00
  57. #define TREE_ELEMENT_LAUNCH_IN_TABS     0x05 /* Launch in tabs instead of windows */
  58.  
  59. struct tree;
  60. struct node;
  61. struct node_element;
  62.  
  63. typedef enum {
  64.         TREE_NO_DRAG = 0,
  65.         TREE_SELECT_DRAG,
  66.         TREE_MOVE_DRAG,
  67.         TREE_TEXTAREA_DRAG,     /** < A drag that is passed to a textarea */
  68.         TREE_UNKNOWN_DRAG       /** < A drag the tree itself won't handle */
  69. } tree_drag_type;
  70.  
  71. typedef enum {
  72.         NODE_ELEMENT_TEXT,              /**< Text only */
  73.         NODE_ELEMENT_TEXT_PLUS_ICON,    /**< Text and icon */
  74.         NODE_ELEMENT_BITMAP             /**< Bitmap only */
  75. } node_element_type;
  76.  
  77. typedef enum {
  78.         NODE_DELETE_ELEMENT_TXT, /**< The text of an element of the
  79.                                   * node is being deleted */
  80.         NODE_DELETE_ELEMENT_IMG, /**< The bitmap or icon of a node is
  81.                                   * being deleted */
  82.         NODE_LAUNCH, /**< The node has been launched */
  83.         NODE_ELEMENT_EDIT_CANCELLED, /**< Editing opperation cancelled.  */
  84.         NODE_ELEMENT_EDIT_FINISHING, /**< New text has to be accepted
  85.                                       * or rejected.  */
  86.         NODE_ELEMENT_EDIT_FINISHED /**< Editing of a node_element has
  87.                                     * been finished. */
  88. } node_msg;
  89.  
  90. typedef enum {
  91.         NODE_CALLBACK_HANDLED,
  92.         NODE_CALLBACK_NOT_HANDLED,
  93.         NODE_CALLBACK_REJECT, /**< reject new text for node element
  94.                                * and leave editing mode. */
  95.         NODE_CALLBACK_CONTINUE /**< don't leave editig mode. */
  96. } node_callback_resp;
  97.  
  98. /** Internal node message. */
  99. struct node_msg_data {
  100.         node_msg msg; /**< The type of message. */
  101.         unsigned int flag; /**< message flags. */
  102.         struct node *node; /**< tree node messsage concerns. */
  103.         union {
  104.                 char *text; /**< textural data. */
  105.                 void *bitmap; /**< bitmap data. */
  106.                 struct browser_window *bw; /**< clone browser_window. */
  107.         } data; /**< The message data. */
  108. };
  109.  
  110. /** callbacks to perform necessary operations on treeview. */
  111. struct treeview_table {
  112.         void (*redraw_request)(int x, int y, int width, int height,
  113.                                void *data); /**< request a redraw. */
  114.         void (*resized)(struct tree *tree, int width, int height,
  115.                         void *data); /**< resize treeview area. */
  116.         void (*scroll_visible)(int y, int height, void *data); /**< scroll visible treeview area. */
  117.         void (*get_window_dimensions)(int *width, int *height, void *data); /**< get dimensions of window */
  118. };
  119.  
  120. /**
  121.  * Informs the client about any events requiring his action
  122.  *
  123.  * \param user_data     the user data which was passed at tree creation
  124.  * \param msg_data      structure containing all the message information
  125.  * \return              the appropriate node_callback_resp response
  126.  */
  127. typedef node_callback_resp (*tree_node_user_callback)(void *user_data,
  128.                 struct node_msg_data *msg_data);
  129.  
  130. /* Non-platform specific code */
  131.  
  132. void tree_set_icon_dir(char *icon_dir);
  133. void tree_setup_colours(void);
  134.  
  135. /* Functions for creating/deleting tree primitives and for tree structure
  136.    manipulation */
  137. struct tree *tree_create(unsigned int flags,
  138.                 const struct treeview_table *callbacks,
  139.                 void *client_data);
  140. struct node *tree_create_folder_node(struct tree *tree, struct node *parent,
  141.                 const char *title, bool editable, bool retain_in_memory,
  142.                 bool deleted);
  143. struct node *tree_create_leaf_node(struct tree *tree, struct node *parent,
  144.                 const char *title, bool editable, bool retain_in_memory,
  145.                 bool deleted);
  146. struct node_element *tree_create_node_element(struct node *parent,
  147.                 node_element_type type, unsigned int flag, bool editable);
  148. void tree_link_node(struct tree *tree, struct node *link, struct node *node,
  149.                 bool before);
  150. void tree_delink_node(struct tree *tree, struct node *node);
  151. void tree_delete(struct tree *tree);
  152. void tree_delete_node(struct tree *tree, struct node *node, bool siblings);
  153.  
  154. /* setters and getters for properties and data */
  155. void tree_set_node_icon(struct tree *tree, struct node *node,
  156.                 struct hlcache_handle *icon);
  157. void tree_set_node_expanded(struct tree *tree, struct node *node, bool expanded,
  158.                 bool folder, bool leaf);
  159. void tree_set_node_selected(struct tree *tree, struct node *node, bool all,
  160.                 bool selected);
  161. void tree_set_node_selected_at(struct tree *tree, int x, int y, bool selected);
  162. void tree_set_node_sort_function(struct tree *tree, struct node *node,
  163.                 int (*sort) (struct node *, struct node *));
  164. void tree_set_node_user_callback(struct node *node,
  165.                 tree_node_user_callback callback, void *data);
  166. void tree_set_redraw(struct tree *tree, bool redraw);
  167. bool tree_get_redraw(struct tree *tree);
  168. bool tree_node_has_selection(struct node *node);
  169. bool tree_node_is_deleted(struct node *node);
  170. bool tree_node_is_folder(struct node *node);
  171. bool tree_node_is_default(struct node *node);
  172. void tree_update_node_element(struct tree *tree, struct node_element *element,
  173.                 const char *text, void *bitmap);
  174. bool tree_update_element_text(struct tree *tree, struct node_element *element, char *text);
  175. const char *tree_node_element_get_text(struct node_element *element);
  176. struct node *tree_get_root(struct tree *tree);
  177. bool tree_is_edited(struct tree *tree);
  178. tree_drag_type tree_drag_status(struct tree *tree);
  179.  
  180. struct node *tree_get_default_folder_node(struct tree *tree);
  181. bool tree_set_default_folder_node(struct tree *tree, struct node *node);
  182. void tree_clear_default_folder_node(struct tree *tree);
  183.  
  184. /* functions for traversing the tree */
  185. struct node *tree_node_get_parent(struct node *node);
  186. struct node *tree_node_get_child(struct node *node);
  187. struct node *tree_node_get_next(struct node *node);
  188.  
  189. void tree_draw(struct tree *tree, int x, int y,
  190.                 int clip_x, int clip_y, int clip_width, int clip_height,
  191.                 const struct redraw_context *ctx);
  192.  
  193. struct node_element *tree_node_find_element(struct node *node,
  194.                 unsigned int flag, struct node_element *after);
  195. void tree_delete_selected_nodes(struct tree *tree, struct node *node);
  196. struct node *tree_get_selected_node(struct node *node);
  197. struct node *tree_get_link_details(struct tree *tree, int x, int y,
  198.                 bool *before);
  199. void tree_launch_selected(struct tree *tree, bool tabs);
  200.  
  201. bool tree_mouse_action(struct tree *tree, browser_mouse_state mouse,
  202.                 int x, int y);
  203. void tree_drag_end(struct tree *tree, browser_mouse_state mouse, int x0, int y0,
  204.                 int x1, int y1);
  205. bool tree_keypress(struct tree *tree, uint32_t key);
  206.  
  207. int tree_alphabetical_sort(struct node *, struct node *);
  208. void tree_start_edit(struct tree *tree, struct node_element *element);
  209. struct hlcache_handle *tree_load_icon(const char *name);
  210.  
  211. #endif
  212.