NetSurf
search.c
Go to the documentation of this file.
1/*
2 * Copyright 2004 John M Bell <jmb202@ecs.soton.ac.uk>
3 * Copyright 2005 Adrian Lees <adrianl@users.sourceforge.net>
4 * Copyright 2008 Chris Young <chris@unsatisfactorysoftware.co.uk>
5 *
6 * This file is part of NetSurf, http://www.netsurf-browser.org/
7 *
8 * NetSurf is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; version 2 of the License.
11 *
12 * NetSurf is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21/** \file
22 * Free text search (implementation)
23 */
24
25#include "amiga/os3support.h"
26
27#include "utils/config.h"
28#include <ctype.h>
29#include <string.h>
30#include <stdlib.h>
31
32#include <proto/intuition.h>
33#include <proto/exec.h>
34#include <proto/window.h>
35#include <proto/layout.h>
36#include <proto/string.h>
37#include <proto/button.h>
38#include <proto/label.h>
39#include <proto/checkbox.h>
40#include <classes/window.h>
41#include <gadgets/layout.h>
42#include <gadgets/string.h>
43#include <gadgets/button.h>
44#include <gadgets/checkbox.h>
45#include <images/label.h>
46#include <reaction/reaction_macros.h>
47
48#include "utils/log.h"
49#include "utils/messages.h"
50#include "utils/utils.h"
51#include "content/content.h"
53#include "desktop/search.h"
54#include "netsurf/mouse.h"
55#include "netsurf/window.h"
56#include "netsurf/search.h"
57
58#include "amiga/libs.h"
59#include "amiga/gui.h"
60#include "amiga/memory.h"
61#include "amiga/search.h"
62#include "amiga/object.h"
63#include "amiga/theme.h"
64#include "amiga/utf8.h"
65
66#ifndef NOF_ELEMENTS
67#define NOF_ELEMENTS(array) (sizeof(array)/sizeof(*(array)))
68#endif
69
70static bool search_insert;
71
72enum
73{
82};
83
84enum {
91};
92
95 struct Window *win;
99};
100
101static struct find_window *fwin = NULL;
102
104char *ami_search_string(void);
105static void ami_search_set_status(bool found, void *p);
106static void ami_search_set_hourglass(bool active, void *p);
107static void ami_search_add_recent(const char *string, void *p);
108static void ami_search_set_forward_state(bool active, void *p);
109static void ami_search_set_back_state(bool active, void *p);
110static BOOL ami_search_event(void *w);
111
118};
119
122 NULL, /* we don't explicitly close the search window on quit */
123};
124
126
128{
129 if (fw != NULL) {
130 return fw->gwin;
131 }
132 return NULL;
133}
134
135/**
136 * Change the displayed search status.
137 *
138 * \param gwin gui window to open search for.
139 */
140void ami_search_open(struct gui_window *gwin)
141{
142 search_insert = true;
143
144 if(fwin)
145 {
148 fwin->gwin = gwin;
150 WindowToFront(fwin->win);
151 ActivateWindow(fwin->win);
152 return;
153 }
154
155 fwin = calloc(1, sizeof(struct find_window));
156
157 /* Get local charset messages. If any of these are NULL it doesn't matter */
163
165 WA_ScreenTitle, ami_gui_get_screen_title(),
166 WA_Title, fwin->message[SSTR_TITLE],
167 WA_Activate, TRUE,
168 WA_DepthGadget, TRUE,
169 WA_DragBar, TRUE,
170 WA_CloseGadget, TRUE,
171 WA_SizeGadget, TRUE,
172 WA_PubScreen, ami_gui_get_screen(),
173 WINDOW_SharedPort, ami_gui_get_shared_msgport(),
174 WINDOW_UserData, fwin,
175 WINDOW_IconifyGadget, FALSE,
176 WINDOW_LockHeight, TRUE,
177 WINDOW_Position, WPOS_CENTERSCREEN,
178 WINDOW_ParentGroup, fwin->objects[GID_S_MAIN] = LayoutVObj,
179 LAYOUT_AddChild, fwin->objects[GID_S_SEARCHSTRING] = StringObj,
180 GA_ID, GID_S_SEARCHSTRING,
181 GA_TabCycle, TRUE,
182 GA_RelVerify, TRUE,
183 StringEnd,
184 CHILD_WeightedHeight, 0,
185 LAYOUT_AddChild, fwin->objects[GID_S_CASE] = CheckBoxObj,
186 GA_ID, GID_S_CASE,
187 GA_Text, fwin->message[SSTR_CASE],
188 GA_Selected, FALSE,
189 GA_TabCycle, TRUE,
190 GA_RelVerify, TRUE,
191 CheckBoxEnd,
192 LAYOUT_AddChild, fwin->objects[GID_S_SHOWALL] = CheckBoxObj,
193 GA_ID,GID_S_SHOWALL,
194 GA_Text, fwin->message[SSTR_SHOWALL],
195 GA_Selected, FALSE,
196 GA_TabCycle, TRUE,
197 GA_RelVerify, TRUE,
198 CheckBoxEnd,
199 LAYOUT_AddChild, LayoutHObj,
200 LAYOUT_AddChild, fwin->objects[GID_S_PREV] = ButtonObj,
201 GA_ID, GID_S_PREV,
202 GA_RelVerify, TRUE,
203 GA_Text, fwin->message[SSTR_PREV],
204 GA_TabCycle, TRUE,
205 GA_Disabled, TRUE,
206 ButtonEnd,
207 CHILD_WeightedHeight, 0,
208 LAYOUT_AddChild, fwin->objects[GID_S_NEXT] = ButtonObj,
209 GA_ID, GID_S_NEXT,
210 GA_RelVerify, TRUE,
211 GA_Text, fwin->message[SSTR_NEXT],
212 GA_TabCycle, TRUE,
213 GA_Disabled, TRUE,
214 ButtonEnd,
215 LayoutEnd,
216 CHILD_WeightedHeight,0,
217 EndGroup,
218 EndWindow;
219
220 fwin->win = (struct Window *)RA_OpenWindow(fwin->objects[OID_S_MAIN]);
221 fwin->gwin = gwin;
224
225 ActivateLayoutGadget((struct Gadget *)fwin->objects[GID_S_MAIN], fwin->win,
226 NULL, (ULONG)fwin->objects[GID_S_SEARCHSTRING]);
227}
228
230{
233 DisposeObject(fwin->objects[OID_S_MAIN]);
234
235 /* Free local charset version of messages */
236 for(int i = 0; i < SSTR_LAST; i++) {
238 }
239
241 fwin = NULL;
242}
243
244static BOOL ami_search_event(void *w)
245{
246 /* return TRUE if window destroyed */
247 ULONG result;
248 uint16 code;
249 search_flags_t flags;
250
251 while((result = RA_HandleInput(fwin->objects[OID_S_MAIN],&code)) != WMHI_LASTMSG)
252 {
253 switch(result & WMHI_CLASSMASK) // class
254 {
255 case WMHI_GADGETUP:
256 switch(result & WMHI_GADGETMASK)
257 {
260
261 RefreshSetGadgetAttrs((struct Gadget *)fwin->objects[GID_S_PREV],
262 fwin->win, NULL,
263 GA_Disabled, FALSE,
264 TAG_DONE);
265
266 RefreshSetGadgetAttrs((struct Gadget *)fwin->objects[GID_S_NEXT],
267 fwin->win, NULL,
268 GA_Disabled, FALSE,
269 TAG_DONE);
270
271 /* fall through */
272
273 case GID_S_NEXT:
274 search_insert = true;
275 flags = SEARCH_FLAG_FORWARDS |
279 NULL,
280 flags, ami_search_string());
281 ActivateWindow(ami_gui_get_window(fwin->gwin));
282 break;
283
284 case GID_S_PREV:
285 search_insert = true;
286 flags = ~SEARCH_FLAG_FORWARDS &
290 NULL,
291 flags, ami_search_string());
292 ActivateWindow(ami_gui_get_window(fwin->gwin));
293 break;
294 }
295 break;
296
297 case WMHI_CLOSEWINDOW:
299 return TRUE;
300 break;
301 }
302 }
303 return FALSE;
304}
305
306/**
307* Change the displayed search status.
308* \param found search pattern matched in text
309* \param p the pointer sent to search_verify_new() / search_create_context()
310*/
311
312void ami_search_set_status(bool found, void *p)
313{
314}
315
316/**
317* display hourglass while searching
318* \param active start/stop indicator
319* \param p the pointer sent to search_verify_new() / search_create_context()
320*/
321
322void ami_search_set_hourglass(bool active, void *p)
323{
324 if(active)
326 else
328}
329
330/**
331* retrieve string being searched for from gui
332*/
333
335{
336 char *text;
337 GetAttr(STRINGA_TextVal,fwin->objects[GID_S_SEARCHSTRING],(ULONG *)&text);
338 return text;
339
340}
341
342/**
343* add search string to recent searches list
344* front is at liberty how to implement the bare notification
345* should normally store a strdup() of the string;
346* core gives no guarantee of the integrity of the const char *
347* \param string search pattern
348* \param p the pointer sent to search_verify_new() / search_create_context()
349*/
350
351void ami_search_add_recent(const char *string, void *p)
352{
353}
354
355/**
356* activate search forwards button in gui
357* \param active activate/inactivate
358* \param p the pointer sent to search_verify_new() / search_create_context()
359*/
360
361void ami_search_set_forward_state(bool active, void *p)
362{
363 RefreshSetGadgetAttrs((struct Gadget *)fwin->objects[GID_S_NEXT],
364 fwin->win, NULL,
365 GA_Disabled, active ? FALSE : TRUE, TAG_DONE);
366
367}
368
369/**
370* activate search forwards button in gui
371* \param active activate/inactivate
372* \param p the pointer sent to search_verify_new() / search_create_context()
373*/
374
375void ami_search_set_back_state(bool active, void *p)
376{
377 RefreshSetGadgetAttrs((struct Gadget *)fwin->objects[GID_S_PREV],
378 fwin->win, NULL,
379 GA_Disabled, active ? FALSE : TRUE, TAG_DONE);
380}
381
382/**
383* retrieve state of 'case sensitive', 'show all' checks in gui
384*/
385
387{
388 ULONG case_sensitive, showall;
389 search_flags_t flags;
390 GetAttr(GA_Selected,fwin->objects[GID_S_CASE],(ULONG *)&case_sensitive);
391 GetAttr(GA_Selected,fwin->objects[GID_S_SHOWALL],(ULONG *)&showall);
392 flags = 0 | (case_sensitive ? SEARCH_FLAG_CASE_SENSITIVE : 0) |
393 (showall ? SEARCH_FLAG_SHOWALL : 0);
394 return flags;
395}
396
struct Window * ami_gui_get_window(struct gui_window *gw)
Get window from gui_window.
Definition: gui.c:578
void ami_gui_set_find_window(struct gui_window *gw, struct find_window *fw)
Set search window in gui_window.
Definition: gui.c:500
struct Screen * ami_gui_get_screen(void)
Get a pointer to the screen NetSurf is running on.
Definition: gui.c:405
nserror ami_gui_win_list_add(void *win, int type, const struct ami_win_event_table *table)
Add a window to the NetSurf window list (to enable event processing)
Definition: gui.c:4685
STRPTR ami_gui_get_screen_title(void)
Get the string for NetSurf's screen titlebar.
Definition: gui.c:976
void ami_gui_win_list_remove(void *win)
Remove a window from the NetSurf window list.
Definition: gui.c:4699
struct browser_window * ami_gui_get_browser_window(struct gui_window *gw)
Get browser window from gui_window.
Definition: gui.c:421
struct MsgPort * ami_gui_get_shared_msgport(void)
Get shared message port.
void ami_update_pointer(struct Window *win, gui_pointer_shape shape)
Definition: theme.c:221
STATIC char result[100]
Definition: arexx.c:77
Browser window creation and manipulation interface.
Content handling interface.
void browser_window_search(struct browser_window *bw, void *context, search_flags_t flags, const char *string)
Starts or continues an existing search.
Definition: search.c:37
void browser_window_search_clear(struct browser_window *bw)
Clear up a search.
Definition: search.c:47
Browseing window text search interface.
search_flags_t
Definition: search.h:29
@ SEARCH_FLAG_CASE_SENSITIVE
Definition: search.h:31
@ SEARCH_FLAG_SHOWALL
Definition: search.h:34
@ SEARCH_FLAG_FORWARDS
Definition: search.h:32
@ AMINS_FINDWINDOW
Definition: object.h:32
static void ami_search_set_back_state(bool active, void *p)
activate search forwards button in gui
Definition: search.c:375
static struct find_window * fwin
Definition: search.c:101
search_flags_t ami_search_flags(void)
retrieve state of 'case sensitive', 'show all' checks in gui
Definition: search.c:386
static void ami_search_set_hourglass(bool active, void *p)
display hourglass while searching
Definition: search.c:322
static BOOL ami_search_event(void *w)
Definition: search.c:244
void ami_search_open(struct gui_window *gwin)
Change the displayed search status.
Definition: search.c:140
static void ami_search_add_recent(const char *string, void *p)
add search string to recent searches list front is at liberty how to implement the bare notification ...
Definition: search.c:351
@ OID_S_MAIN
Definition: search.c:74
@ GID_S_PREV
Definition: search.c:77
@ GID_S_NEXT
Definition: search.c:76
@ GID_S_SHOWALL
Definition: search.c:79
@ GID_S_CASE
Definition: search.c:80
@ GID_S_SEARCHSTRING
Definition: search.c:78
@ GID_S_MAIN
Definition: search.c:75
@ GID_S_LAST
Definition: search.c:81
static const struct ami_win_event_table ami_search_table
Definition: search.c:120
static void ami_search_set_forward_state(bool active, void *p)
activate search forwards button in gui
Definition: search.c:361
static bool search_insert
Definition: search.c:70
static void ami_search_set_status(bool found, void *p)
Change the displayed search status.
Definition: search.c:312
@ SSTR_CASE
Definition: search.c:86
@ SSTR_LAST
Definition: search.c:90
@ SSTR_SHOWALL
Definition: search.c:87
@ SSTR_PREV
Definition: search.c:88
@ SSTR_TITLE
Definition: search.c:85
@ SSTR_NEXT
Definition: search.c:89
struct gui_window * ami_search_get_gwin(struct find_window *fw)
Obtain gui window associated with find window.
Definition: search.c:127
struct gui_search_table * amiga_search_table
Definition: search.c:125
char * ami_search_string(void)
retrieve string being searched for from gui
Definition: search.c:334
void ami_search_close(void)
Close search.
Definition: search.c:229
static struct gui_search_table search_table
Definition: search.c:112
void ami_utf8_free(char *ptr)
Definition: utf8.c:104
char * ami_utf8_easy(const char *string)
Definition: utf8.c:109
Core mouse and pointer states.
@ GUI_POINTER_WAIT
Definition: mouse.h:127
@ GUI_POINTER_DEFAULT
Definition: mouse.h:113
Interface to platform-specific search operations.
Interface to platform-specific graphical user interface window operations.
#define LayoutHObj
Definition: libs.h:64
#define CheckBoxObj
Definition: libs.h:55
#define WindowObj
Definition: libs.h:77
#define LayoutVObj
Definition: libs.h:65
#define ButtonObj
Definition: libs.h:54
#define StringObj
Definition: libs.h:76
const char * messages_get(const char *key)
Fast lookup of a message by key from the standard Messages hash.
Definition: messages.c:241
Localised message support (interface).
ULONG RefreshSetGadgetAttrs(struct Gadget *g, struct Window *w, struct Requester *r, Tag tag1,...)
Definition: os3support.c:429
Minimal compatibility header for AmigaOS 3.
uint16_t uint16
Definition: os3support.h:182
Interface to utility string handling.
struct Window * win
Definition: search.c:95
struct gui_window * gwin
Definition: search.c:97
Object * objects[GID_S_LAST]
Definition: search.c:96
struct ami_generic_window w
Definition: search.c:94
char * message[SSTR_LAST]
Definition: search.c:98
function table for page text search.
Definition: search.h:31
first entry in window list
Definition: gui.c:298
Interface to a number of general purpose functionality.
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