NetSurf
selection.h
Go to the documentation of this file.
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 "netsurf/mouse.h"
28
29struct box;
30struct browser_window;
31struct plot_font_style;
32struct selection_string;
33struct selection;
34struct content;
35
36/**
37 * determine if a selecion is active
38 */
39bool selection_active(struct selection *s);
40
41bool selection_dragging(struct selection *s);
42
44
45/**
46 * Handles completion of a drag operation
47 */
48void selection_drag_end(struct selection *s);
49
50/**
51 * Creates a new selection object associated with a browser window.
52 *
53 * Used from text and html content handlers
54 *
55 * \return new selection context
56 */
57struct selection *selection_create(struct content *c);
58
59/**
60 * Destroys a selection object clearing it if nesessary
61 *
62 * Used from content textsearch
63 *
64 * \param s selection object
65 */
66void selection_destroy(struct selection *s);
67
68/**
69 * Initialise the selection object to use the given box subtree as its root,
70 * ie. selections are confined to that subtree.
71 *
72 * Used from text and html content handlers
73 *
74 * \param s selection object
75 */
76void selection_init(struct selection *s);
77
78/**
79 * Initialise the selection object to use the given box subtree as its root,
80 * ie. selections are confined to that subtree, whilst maintaining the current
81 * selection whenever possible because, for example, it's just the page being
82 * resized causing the layout to change.
83 *
84 * Used from html content handler
85 *
86 * \param s selection object
87 */
88void selection_reinit(struct selection *s);
89
90/**
91 * Clears the current selection, optionally causing the screen to be updated.
92 *
93 * Used from text and html content handlers
94 *
95 * \param s selection object
96 * \param redraw true iff the previously selected region of the browser
97 * window should be redrawn
98 * \return true if selection was cleared false if not
99 */
100bool selection_clear(struct selection *s, bool redraw);
101
102/**
103 * Selects all the text within the box subtree controlled by
104 * this selection object, updating the screen accordingly.
105 *
106 * Used from text and html content handlers
107 *
108 * \param s selection object
109 */
110void selection_select_all(struct selection *s);
111
112/**
113 * Set the position of the current selection, updating the screen.
114 *
115 * Used from content textsearch
116 *
117 * \param s selection object
118 * \param start byte offset within textual representation
119 * \param end byte offset within textual representation
120 */
121void selection_set_position(struct selection *s, unsigned start, unsigned end);
122
123/**
124 * Handles mouse clicks (including drag starts) in or near a selection
125 *
126 * Used from text and html content handlers
127 *
128 * \param s selection object
129 * \param mouse state of mouse buttons and modifier keys
130 * \param idx byte offset within textual representation
131 * \return true iff the click has been handled by the selection code
132 */
133bool selection_click(struct selection *s, struct browser_window *top, browser_mouse_state mouse, unsigned idx);
134
135/**
136 * Handles movements related to the selection, eg. dragging of start and
137 * end points.
138 *
139 * Used from text and html content handlers
140 *
141 * \param s selection object
142 * \param mouse state of mouse buttons and modifier keys
143 * \param idx byte offset within text representation
144 */
145void selection_track(struct selection *s, browser_mouse_state mouse, unsigned idx);
146
147/**
148 * Copy the selected contents to the clipboard
149 *
150 * Used from text and html content handlers
151 *
152 * \param s selection
153 * \return true iff successful
154 */
156
157/**
158 * Get copy of selection as string
159 *
160 * Used from text and html content handlers
161 *
162 * \param s selection
163 * \return string of selected text, or NULL. Ownership passed to caller.
164 */
165char *selection_get_copy(struct selection *s);
166
167
168/**
169 * Tests whether a text range lies partially within the selection, if there is
170 * a selection defined, returning the start and end indexes of the bytes
171 * that should be selected.
172 *
173 * Used from text and html content handlers, content textsearch
174 *
175 * \param s the selection object
176 * \param start byte offset of start of text
177 * \param end byte offset of end of text
178 * \param start_idx receives the start index (in bytes) of the highlighted portion
179 * \param end_idx receives the end index (in bytes)
180 * \return true iff part of the given box lies within the selection
181 */
182bool selection_highlighted(const struct selection *s, unsigned start, unsigned end, unsigned *start_idx, unsigned *end_idx);
183
184bool
185selection_string_append(const char *text,
186 size_t length,
187 bool space,
188 struct plot_font_style *style,
189 struct selection_string *sel_string);
190
191#endif
void selection_drag_end(struct selection *s)
Handles completion of a drag operation.
Definition: selection.c:601
bool selection_click(struct selection *s, struct browser_window *top, browser_mouse_state mouse, unsigned idx)
Handles mouse clicks (including drag starts) in or near a selection.
Definition: selection.c:319
void selection_reinit(struct selection *s)
Initialise the selection object to use the given box subtree as its root, ie.
Definition: selection.c:281
bool selection_highlighted(const struct selection *s, unsigned start, unsigned end, unsigned *start_idx, unsigned *end_idx)
Tests whether a text range lies partially within the selection, if there is a selection defined,...
Definition: selection.c:562
bool selection_clear(struct selection *s, bool redraw)
Clears the current selection, optionally causing the screen to be updated.
Definition: selection.c:518
struct selection * selection_create(struct content *c)
Creates a new selection object associated with a browser window.
Definition: selection.c:253
void selection_init(struct selection *s)
Initialise the selection object to use the given box subtree as its root, ie.
Definition: selection.c:302
bool selection_copy_to_clipboard(struct selection *s)
Copy the selected contents to the clipboard.
Definition: selection.c:484
bool selection_dragging_start(struct selection *s)
Definition: selection.c:596
void selection_track(struct selection *s, browser_mouse_state mouse, unsigned idx)
Handles movements related to the selection, eg.
Definition: selection.c:420
bool selection_active(struct selection *s)
determine if a selecion is active
Definition: selection.c:586
bool selection_dragging(struct selection *s)
Definition: selection.c:591
void selection_set_position(struct selection *s, unsigned start, unsigned end)
Set the position of the current selection, updating the screen.
Definition: selection.c:553
void selection_destroy(struct selection *s)
Destroys a selection object clearing it if nesessary.
Definition: selection.c:269
bool selection_string_append(const char *text, size_t length, bool space, struct plot_font_style *style, struct selection_string *sel_string)
Append text to selection string.
Definition: selection.c:191
void selection_select_all(struct selection *s)
Selects all the text within the box subtree controlled by this selection object, updating the screen ...
Definition: selection.c:542
char * selection_get_copy(struct selection *s)
Get copy of selection as string.
Definition: selection.c:457
Core mouse and pointer states.
browser_mouse_state
Mouse state: 1 is primary mouse button.
Definition: mouse.h:52
Node in box tree.
Definition: box.h:177
Browser window data.
Content which corresponds to a single URL.
Font style for plotting.
Definition: plot_style.h:111
struct content * c
Definition: selection.c:56
unsigned start_idx
Definition: selection.c:60
unsigned end_idx
Definition: selection.c:61
static nserror text(const struct redraw_context *ctx, const struct plot_font_style *fstyle, int x, int y, const char *text, size_t length)
Text plotting.
Definition: plot.c:978