Dillo v3.1.1-46-g8a360e32
Loading...
Searching...
No Matches
findbar.cc
Go to the documentation of this file.
1/*
2 * File: findbar.cc
3 *
4 * Copyright (C) 2005-2007 Jorge Arellano Cid <jcid@dillo.org>
5 *
6 * This program 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; either version 3 of the License, or
9 * (at your option) any later version.
10 */
11
12#include <FL/Fl.H>
13#include <FL/Fl_Window.H>
14#include "findbar.hh"
15
16#include "msg.h"
17#include "pixmaps.h"
18#include "uicmd.hh"
19#include "bw.h"
20
21/*
22 * Local sub class
23 * (Used to handle escape in the findbar, may also avoid some shortcuts).
24 */
25class MyInput : public Fl_Input {
26public:
27 MyInput (int x, int y, int w, int h, const char* l=0) :
28 Fl_Input(x,y,w,h,l) {};
29 int handle(int e);
30};
31
32int MyInput::handle(int e)
33{
34 _MSG("findbar MyInput::handle()\n");
35 int ret = 1, k = Fl::event_key();
36 unsigned modifier = Fl::event_state() & (FL_SHIFT| FL_CTRL| FL_ALT|FL_META);
37
38 if (e == FL_KEYBOARD) {
39 if (k == FL_Page_Down || k == FL_Page_Up || k == FL_Up || k == FL_Down) {
40 // Let them through for key commands and viewport motion.
41 return 0;
42 }
43 if (modifier == FL_SHIFT) {
44 if (k == FL_Left || k == FL_Right) {
45 // Let these keys get to the UI
46 return 0;
47 }
48 } else if (modifier == FL_CTRL) {
49 if (k == 'a' || k == 'e') {
50 position(k == 'a' ? 0 : size());
51 return 1;
52 } else if (k == 'k') {
53 cut(position(), size());
54 return 1;
55 } else if (k == 'd') {
56 cut(position(), position()+1);
57 return 1;
58 } else if (k == 'h' || k == 'i' || k == 'j' || k == 'l' || k == 'm') {
59 // Fl_Input wants to use ^H as backspace, and also "insert a few
60 // selected control characters literally", but this gets in the way
61 // of key commands.
62 return 0;
63 }
64 } else if (k == FL_Escape && modifier == 0) {
65 // Avoid clearing the text with Esc, just hide the findbar.
66 return 0;
67 }
68 }
69
70 if (ret)
71 ret = Fl_Input::handle(e);
72 return ret;
73}
74
78void Findbar::search_cb(Fl_Widget *, void *vfb)
79{
80 Findbar *fb = (Findbar *)vfb;
81 const char *key = fb->i->value();
82 bool case_sens = fb->check_btn->value();
83
84 if (key[0] != '\0')
86 key, case_sens, false);
87}
88
92void Findbar::searchBackwards_cb(Fl_Widget *, void *vfb)
93{
94 Findbar *fb = (Findbar *)vfb;
95 const char *key = fb->i->value();
96 bool case_sens = fb->check_btn->value();
97
98 if (key[0] != '\0') {
100 key, case_sens, true);
101 }
102}
103
107void Findbar::hide_cb(Fl_Widget *, void *vfb)
108{
110}
111
115Findbar::Findbar(int width, int height) :
116 Fl_Group(0, 0, width, height)
117{
118 int button_width = 70;
119 int gap = 2;
120 int border = 2;
121 int input_width = width - (2 * border + 4 * (button_width + gap));
122 int x = 0;
123
124 Fl_Group::current(0);
125
126 height -= 2 * border;
127
128 box(FL_THIN_UP_BOX);
129
130 hide_btn = new CustButton(x, border, 16, height, 0);
131 hideImg = new Fl_Pixmap(new_s_xpm);
132 hide_btn->image(hideImg);
133 x += 16 + gap;
134 hide_btn->callback(hide_cb, this);
135 hide_btn->clear_visible_focus();
136 hide_btn->box(FL_THIN_UP_BOX);
137 hide_btn->set_tooltip("Hide");
138 add(hide_btn);
139
140 i = new MyInput(x, border, input_width, height);
141 x += input_width + gap;
142 resizable(i);
143 i->when(FL_WHEN_NEVER);
144 add(i);
145
146 next_btn = new CustButton(x, border, button_width, height, "Next");
147 x += button_width + gap;
148 next_btn->shortcut(FL_Enter);
149 next_btn->callback(search_cb, this);
150 next_btn->clear_visible_focus();
151 next_btn->box(FL_THIN_UP_BOX);
152 next_btn->set_tooltip("Find next occurrence of the search phrase\n"
153 "shortcut: Enter");
154 add(next_btn);
155
156 prev_btn= new CustButton(x, border, button_width, height, "Previous");
157 x += button_width + gap;
158 prev_btn->shortcut(FL_SHIFT+FL_Enter);
159 prev_btn->callback(searchBackwards_cb, this);
160 prev_btn->clear_visible_focus();
161 prev_btn->box(FL_THIN_UP_BOX);
162 prev_btn->set_tooltip("Find previous occurrence of the search phrase\n"
163 "shortcut: Shift+Enter");
164 add(prev_btn);
165
166 check_btn = new Fl_Check_Button(x, border, 2*button_width, height,
167 "Case-sensitive");
168 x += 2 * button_width + gap;
169 check_btn->clear_visible_focus();
170 add(check_btn);
171
172}
173
175{
176 delete hideImg;
177}
178
182int Findbar::handle(int event)
183{
184 int k = Fl::event_key();
185 unsigned modifier = Fl::event_state() & (FL_SHIFT| FL_CTRL| FL_ALT|FL_META);
186
187 if (event == FL_KEYBOARD && modifier == 0 && k == FL_Escape) {
188 /* let the UI handle it */
189 return 0;
190 }
191
192 return Fl_Group::handle(event);
193}
194
199{
201 dReturn_if (bw == NULL);
202
203 // It takes more than just calling show() to do the trick
204 Fl_Group::show();
205
206 /* select text even if already focused */
207 i->take_focus();
208 i->position(i->size(), 0);
209}
210
#define _MSG(...)
Definition bookmarks.c:45
A button that highlights on mouse over.
Definition tipwin.hh:49
Searchbar to find text in page.
Definition findbar.hh:16
static void hide_cb(Fl_Widget *, void *)
Hide the search bar.
Definition findbar.cc:107
int handle(int event)
Handle events.
Definition findbar.cc:182
Fl_Pixmap * hideImg
Definition findbar.hh:19
CustButton * hide_btn
Definition findbar.hh:17
void show()
Show the findbar and focus the input field.
Definition findbar.cc:198
Fl_Check_Button * check_btn
Definition findbar.hh:18
static void searchBackwards_cb(Fl_Widget *, void *)
Find previous occurrence of input key.
Definition findbar.cc:92
~Findbar()
Definition findbar.cc:174
CustButton * next_btn
Definition findbar.hh:17
static void search_cb(Fl_Widget *, void *)
Find next occurrence of input key.
Definition findbar.cc:78
CustButton * prev_btn
Definition findbar.hh:17
Fl_Input * i
Definition findbar.hh:20
Findbar(int width, int height)
Construct text search bar.
Definition findbar.cc:115
void set_tooltip(const char *s)
Definition tipwin.cc:162
#define dReturn_if(expr)
Definition dlib.h:64
static const char *const new_s_xpm[]
Definition pixmaps.h:1413
Contains the specific data for a single window.
Definition bw.h:27
void a_UIcmd_findtext_search(BrowserWindow *bw, const char *key, int case_sens, int backward)
Definition uicmd.cc:1554
BrowserWindow * a_UIcmd_get_bw_by_widget(void *v_wid)
Definition uicmd.cc:534
void a_UIcmd_findbar_toggle(BrowserWindow *bw, int on)
Definition uicmd.cc:1587