Subversion Repositories Kolibri OS

Rev

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

  1. /*
  2.  * Copyright 2005 Adrian Lees <adrianl@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.   * Text selection within browser windows (interface).
  21.   */
  22.  
  23. #ifndef _NETSURF_DESKTOP_SELECTION_H_
  24. #define _NETSURF_DESKTOP_SELECTION_H_
  25.  
  26. #include <stdbool.h>
  27. #include "desktop/mouse.h"
  28.  
  29. struct box;
  30.  
  31. typedef enum {
  32.         DRAG_NONE,
  33.         DRAG_START,
  34.         DRAG_END
  35. } seln_drag_state;
  36.  
  37.  
  38. /* this structure should be treated as opaque outside selection.c
  39.    (it's defined here to accelerate selection_defined(s) for reduced
  40.    impact on redraw code) */
  41.  
  42. struct selection
  43. {
  44.         struct content *c;
  45.         struct box *root;
  46.  
  47.         unsigned max_idx;  /* total bytes in text representation */
  48.  
  49.         unsigned start_idx;  /* offset in bytes within text representation */
  50.         unsigned end_idx;
  51.  
  52.         bool defined;
  53.         bool is_html;
  54.  
  55.         seln_drag_state drag_state;
  56. };
  57.  
  58.  
  59. struct selection *selection_create(struct content *c, bool is_html);
  60. void selection_prepare(struct selection *s, struct content *c, bool is_html);
  61. void selection_destroy(struct selection *s);
  62.  
  63. void selection_init(struct selection *s, struct box *root);
  64. void selection_reinit(struct selection *s, struct box *root);
  65.  
  66. /* struct box *selection_root(struct selection *s); */
  67. #define selection_root(s) ((s)->root)
  68.  
  69. /* bool selection_defined(struct selection *s); */
  70. #define selection_defined(s) ((s)->defined)
  71.  
  72. /* bool selection_dragging(struct selection *s); */
  73. #define selection_dragging(s) ((s)->drag_state != DRAG_NONE)
  74.  
  75. /* bool selection_dragging_start(struct selection *s); */
  76. #define selection_dragging_start(s) ((s)->drag_state == DRAG_START)
  77.  
  78. bool selection_read_only(struct selection *s);
  79.  
  80. void selection_clear(struct selection *s, bool redraw);
  81. void selection_select_all(struct selection *s);
  82.  
  83. void selection_set_start(struct selection *s, unsigned idx);
  84. void selection_set_end(struct selection *s, unsigned idx);
  85.  
  86. struct box *selection_get_start(struct selection *s, size_t *pidx);
  87. struct box *selection_get_end(struct selection *s, size_t *pidx);
  88.  
  89. bool selection_click(struct selection *s, browser_mouse_state mouse,
  90.                 unsigned idx);
  91. void selection_track(struct selection *s, browser_mouse_state mouse,
  92.                 unsigned idx);
  93.  
  94. bool selection_copy_to_clipboard(struct selection *s);
  95. char * selection_get_copy(struct selection *s);
  96.  
  97. /** Handles completion of a drag operation */
  98. /* void selection_drag_end(struct selection *s); */
  99. #define selection_drag_end(s) ((s)->drag_state = DRAG_NONE)
  100.  
  101. bool selection_highlighted(const struct selection *s,
  102.                 unsigned start, unsigned end,
  103.                 unsigned *start_idx, unsigned *end_idx);
  104.  
  105. bool selection_save_text(struct selection *s, const char *path);
  106.  
  107. void selection_update(struct selection *s, size_t byte_offset, int change,
  108.                 bool redraw);  
  109.                
  110. unsigned selection_label_subtree(struct box *box, unsigned idx);
  111.  
  112. #endif
  113.