| 1 |
/* |
| 2 |
* Copyright (c) 2003-2004 Stefan Ulrich |
| 3 |
* |
| 4 |
* Permission is hereby granted, free of charge, to any person obtaining a copy |
| 5 |
* of this software and associated documentation files (the "Software"), to |
| 6 |
* deal in the Software without restriction, including without limitation the |
| 7 |
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
| 8 |
* sell copies of the Software, and to permit persons to whom the Software is |
| 9 |
* furnished to do so, subject to the following conditions: |
| 10 |
* |
| 11 |
* The above copyright notice and this permission notice shall be included in |
| 12 |
* all copies or substantial portions of the Software. |
| 13 |
* |
| 14 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 15 |
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 16 |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 17 |
* PAUL VOJTA OR ANY OTHER AUTHOR OF THIS SOFTWARE BE LIABLE FOR ANY CLAIM, |
| 18 |
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
| 19 |
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 20 |
* OTHER DEALINGS IN THE SOFTWARE. |
| 21 |
*/ |
| 22 |
|
| 23 |
#include "xdvi-config.h" |
| 24 |
#include "xdvi.h" |
| 25 |
|
| 26 |
#include "events.h" |
| 27 |
#include "dvi-init.h" |
| 28 |
#include "search-dialog.h" |
| 29 |
#include "search-internal.h" |
| 30 |
#include "xlwradio.h" |
| 31 |
#include "statusline.h" |
| 32 |
#include "string-utils.h" |
| 33 |
#include "string_list.h" |
| 34 |
#include "util.h" |
| 35 |
#include "message-window.h" |
| 36 |
#include "x_util.h" |
| 37 |
#include "xm_menu.h" /* for popdown_callback() */ |
| 38 |
|
| 39 |
#include <X11/Xatom.h> |
| 40 |
#include <X11/StringDefs.h> |
| 41 |
|
| 42 |
#ifdef MOTIF |
| 43 |
# include <Xm/BulletinB.h> |
| 44 |
# include <Xm/DialogS.h> |
| 45 |
# include <Xm/PanedW.h> |
| 46 |
# include <Xm/MessageB.h> |
| 47 |
# include <Xm/LabelG.h> |
| 48 |
# include <Xm/Form.h> |
| 49 |
# include <Xm/Frame.h> |
| 50 |
# include <Xm/ToggleBG.h> |
| 51 |
# include <Xm/Text.h> |
| 52 |
# include <Xm/TextF.h> |
| 53 |
# include <Xm/PushB.h> |
| 54 |
# include <Xm/Protocols.h> |
| 55 |
# include <Xm/AtomMgr.h> |
| 56 |
# if USE_COMBOBOX |
| 57 |
# include <Xm/ComboBox.h> |
| 58 |
# include <Xm/List.h> |
| 59 |
# endif /* USE_COMBOBOX */ |
| 60 |
#else /* MOTIF */ |
| 61 |
# include <X11/Shell.h> |
| 62 |
# include <X11/Xaw/Paned.h> |
| 63 |
# include <X11/Xaw/Box.h> |
| 64 |
# include <X11/Xaw/Form.h> |
| 65 |
# include <X11/Xaw/Label.h> |
| 66 |
# include <X11/Xaw/Command.h> |
| 67 |
# include <X11/Xaw/Toggle.h> |
| 68 |
# include <X11/Xaw/AsciiText.h> |
| 69 |
#endif /* MOTIF */ |
| 70 |
|
| 71 |
/* #defines for widgets that are used in common code */ |
| 72 |
#ifdef MOTIF |
| 73 |
# define SHELL_WIDGET xmDialogShellWidgetClass |
| 74 |
# define PANED_WIDGET xmPanedWindowWidgetClass |
| 75 |
# define FORM_WIDGET xmFormWidgetClass |
| 76 |
# define LABEL_WIDGET xmLabelGadgetClass |
| 77 |
# define TEXT_WIDGET xmTextFieldWidgetClass |
| 78 |
# define CHECKBOX_WIDGET xmToggleButtonGadgetClass |
| 79 |
# define CHECKBUTTON_IS_SET XmNset |
| 80 |
# define PUSHBUTTON_WIDGET xmPushButtonWidgetClass |
| 81 |
# define VALUE_CALLBACK_NAME XmNvalueChangedCallback |
| 82 |
# define ACTIVATE_CALLBACK_NAME XmNactivateCallback |
| 83 |
#else /* MOTIF */ |
| 84 |
# define SHELL_WIDGET transientShellWidgetClass |
| 85 |
# define PANED_WIDGET panedWidgetClass |
| 86 |
# define FORM_WIDGET formWidgetClass |
| 87 |
# define LABEL_WIDGET labelWidgetClass |
| 88 |
# define TEXT_WIDGET asciiTextWidgetClass |
| 89 |
# ifdef XAW |
| 90 |
# define CHECKBOX_WIDGET radioWidgetClass |
| 91 |
# else /* XAW */ |
| 92 |
# define CHECKBOX_WIDGET toggleWidgetClass |
| 93 |
# endif /* XAW */ |
| 94 |
# define CHECKBUTTON_IS_SET XtNstate |
| 95 |
# define PUSHBUTTON_WIDGET commandWidgetClass |
| 96 |
# define VALUE_CALLBACK_NAME XtNcallback |
| 97 |
# define ACTIVATE_CALLBACK_NAME XtNcallback |
| 98 |
#endif /* MOTIF */ |
| 99 |
|
| 100 |
#if defined(MOTIF) && USE_COMBOBOX |
| 101 |
struct search_history { |
| 102 |
char **char_items; |
| 103 |
size_t item_cnt; |
| 104 |
Boolean empty; |
| 105 |
}; |
| 106 |
|
| 107 |
#define Xdvi_HISTORY_EMPTY_MARKER "<History empty>" |
| 108 |
|
| 109 |
static void |
| 110 |
search_history_init(struct search_history *hist) |
| 111 |
{ |
| 112 |
if (resource.search_history == NULL) { |
| 113 |
hist->empty = True; |
| 114 |
hist->char_items = xmalloc(1 * sizeof *(hist->char_items)); |
| 115 |
hist->char_items[0] = NULL; |
| 116 |
hist->item_cnt = 0; |
| 117 |
} |
| 118 |
else { |
| 119 |
hist->char_items = get_separated_list(resource.search_history, "\n", False); |
| 120 |
hist->empty = False; |
| 121 |
/* count number of items and save to hist->item_cnt */ |
| 122 |
for (hist->item_cnt = 0; hist->char_items[hist->item_cnt] != NULL; hist->item_cnt++) { ; } |
| 123 |
} |
| 124 |
} |
| 125 |
|
| 126 |
|
| 127 |
static void |
| 128 |
search_history_update(struct search_history *hist, Widget w, const char *str) |
| 129 |
{ |
| 130 |
size_t i; |
| 131 |
char *tmp; |
| 132 |
XmString tmp_str = XmStringCreateLocalized((char *)str); |
| 133 |
Boolean found = False; |
| 134 |
Widget textfield = NULL; |
| 135 |
|
| 136 |
TRACE_FIND((stderr, "search_history_update for: |%s|\n", str)); |
| 137 |
|
| 138 |
/* special case if Xdvi_HISTORY_EMPTY_MARKER is present: Replace it with `str' */ |
| 139 |
if (hist->empty) { |
| 140 |
XmComboBoxDeletePos(w, 0); |
| 141 |
hist->empty = False; |
| 142 |
hist->char_items = string_list_prepend(hist->char_items, str); |
| 143 |
XmComboBoxAddItem(w, tmp_str, 0, True); |
| 144 |
hist->item_cnt++; |
| 145 |
XmStringFree(tmp_str); |
| 146 |
return; |
| 147 |
} |
| 148 |
|
| 149 |
XtVaGetValues(w, XmNtextField, &textfield, NULL); |
| 150 |
if (textfield == NULL) { |
| 151 |
XDVI_ERROR((stderr, "Could not get text field from combo box!")); |
| 152 |
XmStringFree(tmp_str); |
| 153 |
return; |
| 154 |
} |
| 155 |
|
| 156 |
/* if str is already in the history, just move it to the first position */ |
| 157 |
for (i = 0; hist->char_items[i] != NULL; i++) { |
| 158 |
if (strcmp(hist->char_items[i], str) == 0) { |
| 159 |
found = True; |
| 160 |
break; |
| 161 |
} |
| 162 |
} |
| 163 |
if (found) { |
| 164 |
hist->char_items = string_list_move_to_start(hist->char_items, i); |
| 165 |
XmComboBoxDeletePos(w, i + 1); |
| 166 |
XmComboBoxAddItem(w, tmp_str, 1, True); |
| 167 |
XmComboBoxSelectItem(w, tmp_str); |
| 168 |
XtVaSetValues(textfield, XmNcursorPosition, strlen(hist->char_items[0]), NULL); |
| 169 |
XmStringFree(tmp_str); |
| 170 |
return; |
| 171 |
} |
| 172 |
|
| 173 |
if ((int)hist->item_cnt >= resource.search_history_size) { |
| 174 |
/* history has reached its max size, delete the oldest element and |
| 175 |
put the new element at the beginning */ |
| 176 |
|
| 177 |
XmComboBoxDeletePos(w, hist->item_cnt); |
| 178 |
|
| 179 |
free(hist->char_items[hist->item_cnt - 1]); |
| 180 |
hist->char_items[hist->item_cnt - 1] = xstrdup(str); |
| 181 |
hist->char_items = string_list_rotate_up(hist->char_items); |
| 182 |
|
| 183 |
XmComboBoxAddItem(w, tmp_str, 1, False); |
| 184 |
XmComboBoxSelectItem(w, tmp_str); |
| 185 |
XtVaSetValues(textfield, XmNcursorPosition, strlen(str), NULL); |
| 186 |
} |
| 187 |
else { /* add item */ |
| 188 |
hist->char_items = string_list_prepend(hist->char_items, str); |
| 189 |
XmComboBoxAddItem(w, tmp_str, 1, False); |
| 190 |
XmComboBoxSelectItem(w, tmp_str); |
| 191 |
XtVaSetValues(textfield, XmNcursorPosition, strlen(str), NULL); |
| 192 |
|
| 193 |
hist->item_cnt++; |
| 194 |
} |
| 195 |
|
| 196 |
tmp = string_list_to_str(hist->char_items, "\n"); |
| 197 |
TRACE_FIND((stderr, "Saving search history: |%s|\n", tmp)); |
| 198 |
store_preference(NULL, "searchHistory", "%s", tmp); |
| 199 |
free(tmp); |
| 200 |
|
| 201 |
|
| 202 |
XmStringFree(tmp_str); |
| 203 |
} |
| 204 |
|
| 205 |
|
| 206 |
/* |
| 207 |
* User selected an item from seach history list |
| 208 |
*/ |
| 209 |
static void |
| 210 |
cb_search_history_select(Widget w, XtPointer client_data, XtPointer call_data) |
| 211 |
{ |
| 212 |
XmComboBoxCallbackStruct *cb = (XmComboBoxCallbackStruct *)call_data; |
| 213 |
struct search_history *hist = NULL; |
| 214 |
Widget textfield; |
| 215 |
int pos; |
| 216 |
int idx; |
| 217 |
|
| 218 |
UNUSED(client_data); |
| 219 |
|
| 220 |
if (cb->event == NULL) /* only browsing, no selection */ |
| 221 |
return; |
| 222 |
|
| 223 |
pos = cb->item_position; |
| 224 |
TRACE_FIND((stderr, "POS: %d; reason: %d, event type: %d\n", pos, cb->reason, cb->event->type)); |
| 225 |
|
| 226 |
/* Return if user didn't select from menu, but entered text directly. |
| 227 |
Strangely, `pos == 0' doesn't indicate this, contrary to what the docs say |
| 228 |
about XmONE_BASED. */ |
| 229 |
if (pos == 0 || cb->event->type != ButtonRelease) |
| 230 |
return; |
| 231 |
|
| 232 |
|
| 233 |
XtVaGetValues(w, |
| 234 |
XmNuserData, &hist, |
| 235 |
XmNtextField, &textfield, |
| 236 |
NULL); |
| 237 |
|
| 238 |
if (hist == NULL || textfield == NULL) { |
| 239 |
XDVI_ERROR((stderr, "Couldn't get XmNuserData or XmNtextField from combo box widget!\n")); |
| 240 |
return; |
| 241 |
} |
| 242 |
|
| 243 |
idx = pos - 1; |
| 244 |
|
| 245 |
if (idx == 0 && hist->char_items[0] == NULL) { /* Xdvi_HISTORY_EMPTY_MARKER selected, do nothing */ |
| 246 |
XtVaSetValues(textfield, XmNvalue, "", NULL); |
| 247 |
} |
| 248 |
else { |
| 249 |
XmString tmp_str; |
| 250 |
|
| 251 |
TRACE_FIND((stderr, "moving item %d, %s to pos 0\n", idx, hist->char_items[idx])); |
| 252 |
hist->char_items = string_list_move_to_start(hist->char_items, idx); |
| 253 |
|
| 254 |
/* same for list in combo box */ |
| 255 |
tmp_str = XmStringCreateLocalized(hist->char_items[0]); |
| 256 |
XmComboBoxDeletePos(w, pos); |
| 257 |
XmComboBoxAddItem(w, tmp_str, 1, True); |
| 258 |
XmComboBoxSelectItem(w, tmp_str); |
| 259 |
XtVaSetValues(textfield, XmNcursorPosition, strlen(hist->char_items[0]), NULL); |
| 260 |
XmStringFree(tmp_str); |
| 261 |
} |
| 262 |
} |
| 263 |
|
| 264 |
#endif /* defined(MOTIF) && USE_COMBOBOX */ |
| 265 |
|
| 266 |
static Boolean m_find_popup_active = False; |
| 267 |
|
| 268 |
/* flags for setting single bits in resource.search_window_defaults */ |
| 269 |
static const int SETTINGS_USE_REGEXP_FLAG = 1; |
| 270 |
static const int SETTINGS_CASE_SENSITIVE_FLAG = 2; |
| 271 |
static const int SETTINGS_BACKWARDS_FLAG = 4; |
| 272 |
static const int SETTINGS_IGNORE_LINEBREAKS_FLAG = 8; |
| 273 |
static const int SETTINGS_WRAP_FLAG = 16; |
| 274 |
|
| 275 |
|
| 276 |
static void |
| 277 |
cb_search_go(Widget w, XtPointer client_data, XtPointer call_data) |
| 278 |
{ |
| 279 |
struct search_settings *settings = (struct search_settings *)client_data; |
| 280 |
Widget find_popup; |
| 281 |
Position x = 0, y = 0; |
| 282 |
|
| 283 |
ASSERT(settings != NULL, "client_data cb_search_go mustn't be NULL!"); |
| 284 |
UNUSED(call_data); |
| 285 |
|
| 286 |
TRACE_FIND((stderr, "cb_search_go: settings: searchterm=|%s|, down = %d, re = %d, case = %d, wrap = %d", |
| 287 |
settings->term, settings->direction, settings->use_regexp, settings->case_sensitive, settings->wrap)); |
| 288 |
|
| 289 |
if (!get_widget_by_name(&find_popup, globals.widgets.top_level, "find_popup", True)) |
| 290 |
return; |
| 291 |
|
| 292 |
XtVaGetValues(find_popup, XtNx, &x, XtNy, &y, NULL); |
| 293 |
/* add some offsets */ |
| 294 |
settings->x_pos = x + 10; |
| 295 |
settings->y_pos = y + 10; |
| 296 |
TRACE_GUI((stderr, "SHELL: %ld; x: %d, y: %d", (unsigned long)w, x, y)); |
| 297 |
|
| 298 |
settings->from_page = current_page; |
| 299 |
settings->message_window = 0; |
| 300 |
settings->wrapcnt = 0; |
| 301 |
TRACE_FIND((stderr, "starting search from page: %d", settings->from_page)); |
| 302 |
search_dvi((XtPointer)settings); |
| 303 |
} |
| 304 |
|
| 305 |
static void |
| 306 |
show_settings(const char *func_name, struct search_settings *settings) |
| 307 |
{ |
| 308 |
TRACE_FIND((stderr, "%s: settings: str=|%s|, down = %d, re = %d, " |
| 309 |
"case = %d, ignore_hyphens = %d, ignore_linebreaks = %d, wrap = %d\n", |
| 310 |
func_name, |
| 311 |
settings->term, |
| 312 |
settings->direction, |
| 313 |
settings->use_regexp, |
| 314 |
settings->case_sensitive, |
| 315 |
settings->ignore_hyphens, |
| 316 |
settings->ignore_linebreaks, |
| 317 |
settings->wrap)); |
| 318 |
|
| 319 |
} |
| 320 |
|
| 321 |
|
| 322 |
static void |
| 323 |
cb_regexp_search(Widget w, XtPointer client_data, XtPointer call_data) |
| 324 |
{ |
| 325 |
struct search_settings *settings = (struct search_settings *)client_data; |
| 326 |
/* Hack: Since XawToggleUnsetCurrent() will invoke this callback again, |
| 327 |
return every second time to avoid multiple popups. This is done by |
| 328 |
setting the flag `do_return'. |
| 329 |
*/ |
| 330 |
#if !HAVE_REGEX_H |
| 331 |
static Boolean do_return = False; |
| 332 |
#endif |
| 333 |
ASSERT(settings != NULL, "client_data cb_search_go mustn't be NULL!"); |
| 334 |
UNUSED(call_data); |
| 335 |
|
| 336 |
#if !HAVE_REGEX_H |
| 337 |
if (do_return) { |
| 338 |
do_return = False; |
| 339 |
return; |
| 340 |
} |
| 341 |
|
| 342 |
xdvi_bell(); |
| 343 |
popup_message(get_matching_parent(w, globals.widgets.top_level, "find_popup", NULL), |
| 344 |
MSG_ERR, |
| 345 |
NULL, |
| 346 |
"Sorry, regular expression support (regex.h) is not available on this platform."); |
| 347 |
do_return = True; |
| 348 |
#ifdef MOTIF |
| 349 |
XmToggleButtonGadgetSetState(w, True, False); |
| 350 |
#else |
| 351 |
XawToggleUnsetCurrent(w); |
| 352 |
#endif |
| 353 |
|
| 354 |
#else |
| 355 |
UNUSED(w); |
| 356 |
settings->use_regexp = !(settings->use_regexp); |
| 357 |
|
| 358 |
/* force re-initialization of search term by resetting utf8_term: */ |
| 359 |
free(settings->utf8_term); |
| 360 |
settings->utf8_term = NULL; |
| 361 |
|
| 362 |
show_settings("cb_regexp_search", settings); |
| 363 |
#endif |
| 364 |
|
| 365 |
if (settings->use_regexp) |
| 366 |
resource.search_window_defaults |= SETTINGS_USE_REGEXP_FLAG; |
| 367 |
else |
| 368 |
resource.search_window_defaults &= ~SETTINGS_USE_REGEXP_FLAG; |
| 369 |
store_preference(NULL, "searchWindowDefaults", "%u", resource.search_window_defaults); |
| 370 |
} |
| 371 |
|
| 372 |
static void |
| 373 |
cb_backwards_search(Widget w, XtPointer client_data, XtPointer call_data) |
| 374 |
{ |
| 375 |
struct search_settings *settings = (struct search_settings *)client_data; |
| 376 |
ASSERT(settings != NULL, "client_data cb_search_go mustn't be NULL!"); |
| 377 |
UNUSED(w); |
| 378 |
UNUSED(call_data); |
| 379 |
|
| 380 |
switch (settings->direction) { |
| 381 |
case SEARCH_UP: settings->direction = SEARCH_DOWN; break; |
| 382 |
case SEARCH_DOWN: settings->direction = SEARCH_UP; break; |
| 383 |
default: ASSERT(0, "shouldn't happen: settings->direction is neither SEARCH_UP nor SEARCH_DOWN!"); break; |
| 384 |
} |
| 385 |
|
| 386 |
show_settings("cb_backwards_search", settings); |
| 387 |
|
| 388 |
if (settings->direction == SEARCH_UP) |
| 389 |
resource.search_window_defaults |= SETTINGS_BACKWARDS_FLAG; |
| 390 |
else |
| 391 |
resource.search_window_defaults &= ~SETTINGS_BACKWARDS_FLAG; |
| 392 |
store_preference(NULL, "searchWindowDefaults", "%u", resource.search_window_defaults); |
| 393 |
} |
| 394 |
|
| 395 |
static void |
| 396 |
cb_wrap_search(Widget w, XtPointer client_data, XtPointer call_data) |
| 397 |
{ |
| 398 |
struct search_settings *settings = (struct search_settings *)client_data; |
| 399 |
ASSERT(settings != NULL, "client_data cb_search_go mustn't be NULL!"); |
| 400 |
UNUSED(w); |
| 401 |
UNUSED(call_data); |
| 402 |
|
| 403 |
settings->wrap = !settings->wrap; |
| 404 |
|
| 405 |
show_settings("cb_wrap_search", settings); |
| 406 |
|
| 407 |
if (settings->wrap) |
| 408 |
resource.search_window_defaults |= SETTINGS_WRAP_FLAG; |
| 409 |
else |
| 410 |
resource.search_window_defaults &= ~SETTINGS_WRAP_FLAG; |
| 411 |
|
| 412 |
store_preference(NULL, "searchWindowDefaults", "%u", resource.search_window_defaults); |
| 413 |
} |
| 414 |
|
| 415 |
static void |
| 416 |
cb_match_case(Widget w, XtPointer client_data, XtPointer call_data) |
| 417 |
{ |
| 418 |
struct search_settings *settings = (struct search_settings *)client_data; |
| 419 |
ASSERT(settings != NULL, "client_data cb_search_go mustn't be NULL!"); |
| 420 |
UNUSED(w); |
| 421 |
UNUSED(call_data); |
| 422 |
|
| 423 |
settings->case_sensitive = !(settings->case_sensitive); |
| 424 |
|
| 425 |
show_settings("cb_match_case", settings); |
| 426 |
|
| 427 |
if (settings->case_sensitive) |
| 428 |
resource.search_window_defaults |= SETTINGS_CASE_SENSITIVE_FLAG; |
| 429 |
else |
| 430 |
resource.search_window_defaults &= ~SETTINGS_CASE_SENSITIVE_FLAG; |
| 431 |
store_preference(NULL, "searchWindowDefaults", "%u", resource.search_window_defaults); |
| 432 |
} |
| 433 |
|
| 434 |
static void |
| 435 |
cb_linebreaks(Widget w, XtPointer client_data, XtPointer call_data) |
| 436 |
{ |
| 437 |
struct search_settings *settings = (struct search_settings *)client_data; |
| 438 |
ASSERT(settings != NULL, "client_data cb_search_go mustn't be NULL!"); |
| 439 |
UNUSED(w); |
| 440 |
UNUSED(call_data); |
| 441 |
|
| 442 |
settings->ignore_linebreaks = !(settings->ignore_linebreaks); |
| 443 |
settings->ignore_hyphens = !(settings->ignore_hyphens); |
| 444 |
|
| 445 |
show_settings("cb_linebreaks", settings); |
| 446 |
|
| 447 |
if (settings->ignore_linebreaks) |
| 448 |
resource.search_window_defaults |= SETTINGS_IGNORE_LINEBREAKS_FLAG; |
| 449 |
else |
| 450 |
resource.search_window_defaults &= ~SETTINGS_IGNORE_LINEBREAKS_FLAG; |
| 451 |
store_preference(NULL, "searchWindowDefaults", "%u", resource.search_window_defaults); |
| 452 |
} |
| 453 |
|
| 454 |
|
| 455 |
static void |
| 456 |
cb_search_cancel(Widget w, XtPointer client_data, XtPointer call_data) |
| 457 |
{ |
| 458 |
Widget find_popup; |
| 459 |
struct search_settings *settings = (struct search_settings *)client_data; |
| 460 |
|
| 461 |
UNUSED(w); |
| 462 |
UNUSED(call_data); |
| 463 |
|
| 464 |
if (!get_widget_by_name(&find_popup, globals.widgets.top_level, "find_popup", True)) |
| 465 |
return; |
| 466 |
|
| 467 |
/* This flag is checked in the scanning routines, and |
| 468 |
will be eventually reset by do_pages() in events.c. |
| 469 |
(The scanning routines musn't reset it, since they |
| 470 |
might not be called again after this point!) */ |
| 471 |
globals.ev.flags |= EV_FIND_CANCEL; |
| 472 |
|
| 473 |
search_signal_page_changed(); /* Hack to make search restart anew */ |
| 474 |
search_erase_highlighting(True); |
| 475 |
if (settings->message_window != 0) { |
| 476 |
TRACE_GUI((stderr, "kill_message_window: %p\n", (void *)settings->message_window)); |
| 477 |
kill_message_window(settings->message_window); |
| 478 |
} |
| 479 |
XtPopdown(find_popup); |
| 480 |
m_find_popup_active = False; |
| 481 |
} |
| 482 |
|
| 483 |
static void |
| 484 |
cb_search_get_term_button(Widget w, XtPointer client_data, XtPointer call_data) |
| 485 |
{ |
| 486 |
struct search_settings *settings = (struct search_settings *)client_data; |
| 487 |
char *searchterm = NULL; |
| 488 |
|
| 489 |
#if defined(MOTIF) && USE_COMBOBOX |
| 490 |
struct search_history *hist = NULL; |
| 491 |
#endif |
| 492 |
|
| 493 |
Widget searchbox_input, paned, box; |
| 494 |
UNUSED(call_data); |
| 495 |
|
| 496 |
box = XtParent(w); |
| 497 |
ASSERT(box != 0, "Parent of button widget mustn't be NULL!"); |
| 498 |
paned = XtParent(box); |
| 499 |
ASSERT(paned != 0, "Parent of box widget mustn't be NULL!"); |
| 500 |
|
| 501 |
if (!get_widget_by_name(&searchbox_input, paned, Xdvi_SEARCHBOX_INPUT_NAME, True)) |
| 502 |
return; |
| 503 |
|
| 504 |
#ifdef MOTIF |
| 505 |
# if USE_COMBOBOX |
| 506 |
{ |
| 507 |
Widget textfield = NULL; |
| 508 |
XtVaGetValues(searchbox_input, |
| 509 |
XmNtextField, &textfield, |
| 510 |
XmNuserData, &hist, |
| 511 |
NULL); |
| 512 |
if (textfield == NULL || hist == NULL) { |
| 513 |
XDVI_ERROR((stderr, "Couldn't get XmNtextField or XmNuserData from combo box widget!\n")); |
| 514 |
return; |
| 515 |
} |
| 516 |
XtVaGetValues(textfield, XmNvalue, &searchterm, NULL); |
| 517 |
} |
| 518 |
# else |
| 519 |
XtVaGetValues(searchbox_input, XmNvalue, &searchterm, NULL); |
| 520 |
# endif |
| 521 |
#else |
| 522 |
XtVaGetValues(searchbox_input, XtNstring, &searchterm, NULL); |
| 523 |
#endif |
| 524 |
if (searchterm == NULL) { |
| 525 |
XDVI_WARNING((stderr, "Searchterm in cb_search_get_term callback shouldn't be NULL!")); |
| 526 |
return; |
| 527 |
} |
| 528 |
TRACE_FIND((stderr, "searchterm1: |%s|", searchterm)); |
| 529 |
settings->term = searchterm; |
| 530 |
|
| 531 |
#if defined(MOTIF) && USE_COMBOBOX |
| 532 |
search_history_update(hist, searchbox_input, searchterm); |
| 533 |
#endif |
| 534 |
|
| 535 |
cb_search_go(w, settings, NULL); |
| 536 |
} |
| 537 |
|
| 538 |
static void |
| 539 |
search_cancel(Widget w, XEvent *event, String *params, Cardinal *num_params) |
| 540 |
{ |
| 541 |
struct search_settings *settings = NULL; |
| 542 |
void *ptr; |
| 543 |
UNUSED(event); |
| 544 |
|
| 545 |
ASSERT(*num_params > 0, "params in search_cancel must be > 0!"); |
| 546 |
ASSERT(*params != NULL, "params in search_cancel mustn't be NULL!"); |
| 547 |
|
| 548 |
/* |
| 549 |
* the *params char pointer contains the pointer value (address) of `settings'; |
| 550 |
* convert it back to a pointer: |
| 551 |
*/ |
| 552 |
TRACE_GUI((stderr, "Pointer string value: |%s|", *params)); |
| 553 |
sscanf(*params, "%p", &ptr); |
| 554 |
settings = (struct search_settings *)ptr; |
| 555 |
TRACE_GUI((stderr, "Pointer address: |%p|", (void *)settings)); |
| 556 |
ASSERT(settings != NULL, "Shouldn't happen: Couldn't get string representation of argument pointer."); |
| 557 |
|
| 558 |
cb_search_cancel(w, settings, NULL); |
| 559 |
} |
| 560 |
|
| 561 |
#ifdef MOTIF |
| 562 |
|
| 563 |
static void |
| 564 |
cb_search_get_term(Widget w, XtPointer client_data, XtPointer call_data) |
| 565 |
{ |
| 566 |
struct search_settings *settings = (struct search_settings *)client_data; |
| 567 |
char *searchterm = NULL; |
| 568 |
Widget popup, button, textfield; |
| 569 |
XEvent ev; |
| 570 |
UNUSED(call_data); |
| 571 |
|
| 572 |
TRACE_FIND((stderr, "cb_search_get_term!\n")); |
| 573 |
|
| 574 |
#if USE_COMBOBOX |
| 575 |
UNUSED(w); |
| 576 |
{ |
| 577 |
Widget combobox; |
| 578 |
if (!get_widget_by_name(&combobox, globals.widgets.top_level, Xdvi_SEARCHBOX_INPUT_NAME, True) |
| 579 |
|| !get_widget_by_name(&textfield, globals.widgets.top_level, "Text", True)) |
| 580 |
return; |
| 581 |
} |
| 582 |
#else |
| 583 |
textfield = w; |
| 584 |
#endif |
| 585 |
|
| 586 |
/* retrieve the `Find' button widget */ |
| 587 |
if (!get_widget_by_name(&popup, globals.widgets.top_level, Xdvi_SEARCH_POPUP_NAME, True) |
| 588 |
|| !get_widget_by_name(&button, popup, "find_button", True)) |
| 589 |
return; |
| 590 |
|
| 591 |
if (settings != NULL) { |
| 592 |
/* retrieve search term from text input field */ |
| 593 |
XtVaGetValues(textfield, XmNvalue, &searchterm, NULL); |
| 594 |
if (searchterm == NULL) { |
| 595 |
XDVI_WARNING((stderr, "Searchterm in cb_search_get_term callback shouldn't be NULL!")); |
| 596 |
return; |
| 597 |
} |
| 598 |
|
| 599 |
TRACE_FIND((stderr, "searchterm2: |%s|", searchterm)); |
| 600 |
settings->term = (const char *)searchterm; |
| 601 |
} |
| 602 |
|
| 603 |
/* make the `Find' button think it got pushed. |
| 604 |
Also synthesize an event, just to be sure ... */ |
| 605 |
synthesize_event(&ev, button); |
| 606 |
|
| 607 |
XtCallActionProc(button, "ArmAndActivate", &ev, NULL, 0); |
| 608 |
/* the following don't make the button appear visually pressed: */ |
| 609 |
/* XtCallCallbacks(button, XmNarmCallback, NULL); */ |
| 610 |
/* XtCallCallbacks(button, XmNactivateCallback, NULL); */ |
| 611 |
} |
| 612 |
|
| 613 |
static void |
| 614 |
xm_search_go(Widget w, XEvent *event, String *params, Cardinal *num_params) |
| 615 |
{ |
| 616 |
struct search_settings *settings = NULL; |
| 617 |
void *ptr; |
| 618 |
Widget input; |
| 619 |
|
| 620 |
UNUSED(w); |
| 621 |
UNUSED(event); |
| 622 |
|
| 623 |
if (params != NULL) { /* re-initialize search term */ |
| 624 |
ASSERT(*num_params == 1, "num_params in xm_search_go should be 1 if *params != NULL"); |
| 625 |
/* |
| 626 |
* the *params char pointer contains the pointer value (address) of `settings' as a string; |
| 627 |
* convert it back to a pointer: |
| 628 |
*/ |
| 629 |
TRACE_GUI((stderr, "Pointer string value: |%s|", *params)); |
| 630 |
sscanf(*params, "%p", &ptr); |
| 631 |
settings = (struct search_settings *)ptr; |
| 632 |
TRACE_GUI((stderr, "Pointer address: |%p|", (void *)settings)); |
| 633 |
ASSERT(settings != NULL, "Shouldn't happen: Couldn't get string representation of argument pointer."); |
| 634 |
} |
| 635 |
|
| 636 |
if (get_widget_by_name(&input, globals.widgets.top_level, "searchbox_input", True)) { |
| 637 |
cb_search_get_term(input, settings, NULL); |
| 638 |
} |
| 639 |
} |
| 640 |
|
| 641 |
#else /* MOTIF */ |
| 642 |
|
| 643 |
static void |
| 644 |
xaw_unset_button(XtPointer client_data, XtIntervalId *id) |
| 645 |
{ |
| 646 |
XEvent ev; |
| 647 |
Widget button = (Widget)client_data; |
| 648 |
|
| 649 |
UNUSED(id); |
| 650 |
|
| 651 |
synthesize_event(&ev, button); |
| 652 |
XtCallActionProc(button, "unset", &ev, NULL, 0); |
| 653 |
} |
| 654 |
|
| 655 |
static void |
| 656 |
xaw_search_go(Widget w, XEvent *event, String *params, Cardinal *num_params) |
| 657 |
{ |
| 658 |
struct search_settings *settings = NULL; |
| 659 |
void *ptr; |
| 660 |
char *searchterm = NULL; |
| 661 |
Widget button, input; |
| 662 |
|
| 663 |
UNUSED(w); |
| 664 |
|
| 665 |
if (!get_widget_by_name(&button, globals.widgets.top_level, "find_button", True) |
| 666 |
|| !get_widget_by_name(&input, globals.widgets.top_level, "searchbox_input", True)) |
| 667 |
return; |
| 668 |
|
| 669 |
XtVaGetValues(input, XtNstring, &searchterm, NULL); |
| 670 |
if (searchterm == NULL) { |
| 671 |
XDVI_WARNING((stderr, "Searchterm in xaw_search_go callback shouldn't be NULL!")); |
| 672 |
return; |
| 673 |
} |
| 674 |
|
| 675 |
if (params != NULL) { /* re-initialize search term */ |
| 676 |
ASSERT(*num_params == 1, "num_params in xaw_search_go should be 1 if *params != NULL"); |
| 677 |
/* |
| 678 |
* the *params char pointer contains the pointer value (address) of `settings'; |
| 679 |
* convert it back to a pointer: |
| 680 |
*/ |
| 681 |
TRACE_GUI((stderr, "Pointer string value: |%s|", *params)); |
| 682 |
sscanf(*params, "%p", &ptr); |
| 683 |
settings = (struct search_settings *)ptr; |
| 684 |
TRACE_GUI((stderr, "Pointer address: |%p|", (void *)settings)); |
| 685 |
ASSERT(settings != NULL, "Shouldn't happen: Couldn't get string representation of argument pointer."); |
| 686 |
|
| 687 |
settings->term = (const char *)searchterm; |
| 688 |
} |
| 689 |
|
| 690 |
/* |
| 691 |
* Again, we want the button to appear activated when <RETURN> is pressed. |
| 692 |
* For this, we explicitly invoke set()notify(), and unset() after a timeout |
| 693 |
* of 150 milliseconds, which seems to correspond to the Motif default. |
| 694 |
*/ |
| 695 |
XtCallActionProc(button, "set", event, NULL, 0); |
| 696 |
XtCallActionProc(button, "notify", event, NULL, 0); |
| 697 |
XSync(DISP, False); |
| 698 |
XtAppAddTimeOut(globals.app, 150, xaw_unset_button, (XtPointer)button); |
| 699 |
} |
| 700 |
|
| 701 |
|
| 702 |
/* |
| 703 |
* Restart search from within another popup (confirmation) window. |
| 704 |
*/ |
| 705 |
static void |
| 706 |
xaw_search_restart(Widget w, XEvent *event, String *params, Cardinal *num_params) |
| 707 |
{ |
| 708 |
void *ptr; |
| 709 |
struct search_settings *settings; |
| 710 |
|
| 711 |
UNUSED(event); |
| 712 |
UNUSED(w); |
| 713 |
|
| 714 |
ASSERT(*num_params > 0, "params in xaw_search_restart must be > 0!"); |
| 715 |
ASSERT(*params != NULL, "params in xaw_search_restart mustn't be NULL!"); |
| 716 |
|
| 717 |
TRACE_GUI((stderr, "Pointer string value: |%s|", *params)); |
| 718 |
sscanf(*params, "%p", &ptr); |
| 719 |
settings = (struct search_settings *)ptr; |
| 720 |
|
| 721 |
search_restart((XtPointer)settings); |
| 722 |
} |
| 723 |
|
| 724 |
static XtActionsRec xaw_search_actions[] = { |
| 725 |
{ "do-search-restart", xaw_search_restart }, |
| 726 |
{ "do-search", xaw_search_go }, |
| 727 |
}; |
| 728 |
#endif /* MOTIF */ |
| 729 |
|
| 730 |
static XtActionsRec search_actions[] = { |
| 731 |
{ "do-search", |
| 732 |
#ifdef MOTIF |
| 733 |
xm_search_go |
| 734 |
#else |
| 735 |
xaw_search_go |
| 736 |
#endif |
| 737 |
}, |
| 738 |
{ "cancel-search", search_cancel }, |
| 739 |
}; |
| 740 |
|
| 741 |
|
| 742 |
|
| 743 |
static Widget |
| 744 |
create_search_window(struct search_settings *settings) |
| 745 |
{ |
| 746 |
Widget top_level_shell; |
| 747 |
Atom WM_DELETE_WINDOW; |
| 748 |
Widget form, find_paned, box; |
| 749 |
unsigned char curr_state; |
| 750 |
|
| 751 |
#if defined(MOTIF) && USE_COMBOBOX |
| 752 |
static struct search_history hist = { NULL, 0, True }; |
| 753 |
#endif |
| 754 |
|
| 755 |
Widget searchbox_form, searchbox_label, searchbox_input; |
| 756 |
/* left and right column */ |
| 757 |
Widget options_left_form, options_right_form; |
| 758 |
/* checkboxes in left column */ |
| 759 |
Widget regexp_checkbox, matchcase_checkbox, backwards_checkbox, wrap_checkbox; |
| 760 |
/* checkboxes in right column */ |
| 761 |
Widget linebreaks_checkbox; |
| 762 |
Widget find_button, cancel_button; |
| 763 |
|
| 764 |
XtTranslations xlats; |
| 765 |
char *translation_str = NULL; |
| 766 |
#ifdef MOTIF |
| 767 |
XmString str; |
| 768 |
#else /* MOTIF */ |
| 769 |
XtTranslations wm_translations; |
| 770 |
int ddist; |
| 771 |
#endif |
| 772 |
|
| 773 |
XtAddActions(search_actions, XtNumber(search_actions)); |
| 774 |
|
| 775 |
#ifndef MOTIF |
| 776 |
|
| 777 |
XtAddActions(xaw_search_actions, XtNumber(xaw_search_actions)); |
| 778 |
#define HORIZONTAL_RESIZING_NO XtNleft, XtChainLeft, XtNright, XtChainLeft |
| 779 |
#define HORIZONTAL_RESIZING_YES XtNleft, XtChainLeft, XtNright, XtChainRight |
| 780 |
#define VERTICAL_RESIZING_NO XtNtop, XtChainTop, XtNbottom, XtChainTop |
| 781 |
|
| 782 |
/* |
| 783 |
* hacky: Since translations can only contain strings, pass |
| 784 |
* the pointer address as string in the callback. But the only |
| 785 |
* portability problem should be the size of the pointer |
| 786 |
* representation, and we deal with that by using VSNPRINTF(). |
| 787 |
*/ |
| 788 |
translation_str = get_string_va("<Message>WM_PROTOCOLS: cancel-search(%p)\nCtrl<Key>g:find-next()", |
| 789 |
(void *)settings); |
| 790 |
wm_translations = XtParseTranslationTable(translation_str); |
| 791 |
free(translation_str); |
| 792 |
translation_str = NULL; |
| 793 |
#endif /* not MOTIF */ |
| 794 |
|
| 795 |
translation_str = get_string_va( |
| 796 |
#ifdef MOTIF |
| 797 |
"<Key>osfCancel:cancel-search(%p)\n" |
| 798 |
#else |
| 799 |
"<Key>Escape:cancel-search(%p)\n" |
| 800 |
#endif |
| 801 |
"<Key>Return:do-search(%p)\n" |
| 802 |
"Ctrl<Key>g:find-next()", |
| 803 |
(void *)settings, (void *)settings); |
| 804 |
|
| 805 |
xlats = XtParseTranslationTable(translation_str); |
| 806 |
free(translation_str); |
| 807 |
|
| 808 |
top_level_shell = XtVaCreatePopupShell("find_popup", |
| 809 |
SHELL_WIDGET, |
| 810 |
globals.widgets.top_level, |
| 811 |
XtNtitle, "xdvik: Find in File", |
| 812 |
XtNmappedWhenManaged, False, /* so that we can center it first */ |
| 813 |
XtNtransientFor, globals.widgets.top_level, |
| 814 |
XtNallowShellResize, True, |
| 815 |
#ifdef MOTIF |
| 816 |
XmNdeleteResponse, XmDO_NOTHING, /* we'll take care of that ourselves */ |
| 817 |
#else |
| 818 |
XtNtranslations, wm_translations, |
| 819 |
#endif |
| 820 |
NULL); |
| 821 |
|
| 822 |
TRACE_GUI((stderr, "toplevel: %ld", (unsigned long)top_level_shell)); |
| 823 |
|
| 824 |
WM_DELETE_WINDOW = XInternAtom(XtDisplay(top_level_shell), "WM_DELETE_WINDOW", False); |
| 825 |
#ifdef MOTIF |
| 826 |
XmAddWMProtocolCallback(top_level_shell, WM_DELETE_WINDOW, cb_search_cancel, settings); |
| 827 |
#endif |
| 828 |
|
| 829 |
find_paned = XtVaCreateWidget("find_paned", |
| 830 |
PANED_WIDGET, |
| 831 |
top_level_shell, |
| 832 |
#ifdef MOTIF |
| 833 |
/* make sashes invisible */ |
| 834 |
XmNsashWidth, 1, |
| 835 |
XmNsashHeight, 1, |
| 836 |
#endif |
| 837 |
NULL); |
| 838 |
|
| 839 |
form = XtVaCreateWidget("form", |
| 840 |
FORM_WIDGET, |
| 841 |
find_paned, |
| 842 |
#ifdef MOTIF |
| 843 |
XmNhorizontalSpacing, DDIST_MAJOR, |
| 844 |
XmNverticalSpacing, DDIST_MAJOR, |
| 845 |
XmNautoUnmanage, False, |
| 846 |
#else |
| 847 |
XtNallowResize, True, |
| 848 |
#endif |
| 849 |
NULL); |
| 850 |
|
| 851 |
#ifdef MOTIF |
| 852 |
str = XmStringCreateLocalized("Find:"); |
| 853 |
#else |
| 854 |
XtVaGetValues(form, XtNdefaultDistance, &ddist, NULL); |
| 855 |
#endif |
| 856 |
|
| 857 |
/* search term input field */ |
| 858 |
searchbox_form = XtVaCreateWidget("searchbox_form", |
| 859 |
FORM_WIDGET, |
| 860 |
form, |
| 861 |
#ifdef MOTIF |
| 862 |
XmNleftAttachment, XmATTACH_FORM, |
| 863 |
XmNrightAttachment, XmATTACH_FORM, |
| 864 |
XmNhorizontalSpacing, DDIST, |
| 865 |
XmNverticalSpacing, DDIST, |
| 866 |
#else |
| 867 |
XtNborderWidth, 0, |
| 868 |
HORIZONTAL_RESIZING_YES, |
| 869 |
#endif |
| 870 |
NULL); |
| 871 |
searchbox_label = XtVaCreateManagedWidget("searchbox_label", |
| 872 |
LABEL_WIDGET, |
| 873 |
searchbox_form, |
| 874 |
#ifdef MOTIF |
| 875 |
XmNlabelString, str, |
| 876 |
XmNtopAttachment, XmATTACH_FORM, |
| 877 |
XmNleftAttachment, XmATTACH_FORM, |
| 878 |
XmNbottomAttachment, XmATTACH_FORM, |
| 879 |
XmNalignment, XmALIGNMENT_BEGINNING, |
| 880 |
#else |
| 881 |
XtNlabel, "Find:", |
| 882 |
XtNborderWidth, 0, |
| 883 |
HORIZONTAL_RESIZING_NO, |
| 884 |
VERTICAL_RESIZING_NO, |
| 885 |
#endif |
| 886 |
NULL); |
| 887 |
|
| 888 |
#if defined(MOTIF) && USE_COMBOBOX |
| 889 |
|
| 890 |
{ |
| 891 |
Widget textfield = NULL; |
| 892 |
Widget grab_shell = NULL; |
| 893 |
size_t n; |
| 894 |
XmStringTable items; |
| 895 |
|
| 896 |
search_history_init(&hist); |
| 897 |
|
| 898 |
/* initialize Motif string list */ |
| 899 |
n = hist.item_cnt == 0 ? 1 : hist.item_cnt; |
| 900 |
items = (XmStringTable)XtMalloc(n * sizeof(XmString *)); |
| 901 |
|
| 902 |
if (hist.item_cnt == 0) |
| 903 |
items[0] = XmStringCreateLocalized(Xdvi_HISTORY_EMPTY_MARKER); |
| 904 |
else { |
| 905 |
for (n = 0; hist.char_items[n] != NULL; n++) |
| 906 |
items[n] = XmStringCreateLocalized(hist.char_items[n]); |
| 907 |
} |
| 908 |
|
| 909 |
searchbox_input = XtVaCreateManagedWidget(Xdvi_SEARCHBOX_INPUT_NAME, xmComboBoxWidgetClass, |
| 910 |
searchbox_form, |
| 911 |
XmNtopAttachment, XmATTACH_FORM, |
| 912 |
XmNrightAttachment, XmATTACH_FORM, |
| 913 |
XmNleftAttachment, XmATTACH_WIDGET, |
| 914 |
XmNleftWidget, searchbox_label, |
| 915 |
XmNbottomAttachment, XmATTACH_FORM, |
| 916 |
XmNcomboBoxType, XmDROP_DOWN_COMBO_BOX, |
| 917 |
XmNitems, items, |
| 918 |
XmNitemCount, n, |
| 919 |
/* XmONE_BASED so that we can distinguish between |
| 920 |
keyboard entry and selection from popdown list */ |
| 921 |
XmNpositionMode, XmONE_BASED, |
| 922 |
/* XmNitemCount, hist.item_cnt, */ |
| 923 |
/* XmNvisibleItemCount, hist.item_cnt, */ |
| 924 |
XmNuserData, &hist, |
| 925 |
XmNarrowSize, Xdvi_COMBO_BOX_ARROW_SIZE, |
| 926 |
NULL); |
| 927 |
if (resource.search_history_size < 10) { |
| 928 |
/* usually the dropdown list shows 10 entries */ |
| 929 |
XtVaSetValues(searchbox_input, XmNvisibleItemCount, resource.search_history_size, NULL); |
| 930 |
} |
| 931 |
|
| 932 |
/* free Motif strings */ |
| 933 |
if (hist.item_cnt == 0) |
| 934 |
XmStringFree(items[0]); |
| 935 |
else { |
| 936 |
for (n = 0; hist.char_items[n] != NULL; n++) |
| 937 |
XmStringFree(items[n]); |
| 938 |
} |
| 939 |
XtFree((XtPointer)items); |
| 940 |
|
| 941 |
/* start with empty search field */ |
| 942 |
XtVaGetValues(searchbox_input, XmNtextField, &textfield, NULL); |
| 943 |
if (textfield == NULL) |
| 944 |
XDVI_ERROR((stderr, "Couldn't get textfield from combo box widget!\n")); |
| 945 |
|
| 946 |
if (settings->term != NULL) { |
| 947 |
XtVaSetValues(textfield, XmNvalue, settings->term, NULL); |
| 948 |
} |
| 949 |
else { |
| 950 |
XtVaSetValues(textfield, XmNvalue, "", NULL); |
| 951 |
} |
| 952 |
XtAddCallback(textfield, XmNactivateCallback, cb_search_get_term, settings); |
| 953 |
XtAddCallback(searchbox_input, XmNselectionCallback, cb_search_history_select, (XtPointer)settings); |
| 954 |
|
| 955 |
XtOverrideTranslations(textfield, xlats); |
| 956 |
/* workaround for pointer grabbing bug (see xm_menu.c) */ |
| 957 |
if (get_widget_by_name(&grab_shell, searchbox_input, "GrabShell", True)) { |
| 958 |
XtAddCallback(grab_shell, XtNpopdownCallback, popdown_callback, NULL); |
| 959 |
} |
| 960 |
|
| 961 |
} |
| 962 |
#else /* defined(MOTIF) && USE_COMBOBOX */ |
| 963 |
|
| 964 |
searchbox_input = XtVaCreateManagedWidget(Xdvi_SEARCHBOX_INPUT_NAME, |
| 965 |
TEXT_WIDGET, |
| 966 |
searchbox_form, |
| 967 |
#ifdef MOTIF |
| 968 |
XmNtopAttachment, XmATTACH_FORM, |
| 969 |
XmNrightAttachment, XmATTACH_FORM, |
| 970 |
XmNleftAttachment, XmATTACH_WIDGET, |
| 971 |
XmNleftWidget, searchbox_label, |
| 972 |
XmNbottomAttachment, XmATTACH_FORM, |
| 973 |
#else |
| 974 |
XtNwidth, 260, |
| 975 |
XtNdataCompression, False, |
| 976 |
XtNeditType, XawtextEdit, |
| 977 |
XtNfromHoriz, searchbox_label, |
| 978 |
HORIZONTAL_RESIZING_YES, |
| 979 |
VERTICAL_RESIZING_NO, |
| 980 |
#endif |
| 981 |
NULL); |
| 982 |
#ifdef MOTIF |
| 983 |
XtAddCallback(searchbox_input, XmNactivateCallback, cb_search_get_term, settings); |
| 984 |
#endif |
| 985 |
|
| 986 |
if (settings->term != NULL) { |
| 987 |
XtVaSetValues(searchbox_input, |
| 988 |
#ifdef MOTIF |
| 989 |
XmNvalue, |
| 990 |
#else |
| 991 |
XtNstring, |
| 992 |
#endif |
| 993 |
settings->term, NULL); |
| 994 |
} |
| 995 |
|
| 996 |
#endif /* defined(MOTIF) && USE_COMBOBOX */ |
| 997 |
|
| 998 |
|
| 999 |
XtManageChild(searchbox_form); |
| 1000 |
|
| 1001 |
/* Fix for #1499566: Force input focus for text input field */ |
| 1002 |
#ifndef MOTIF |
| 1003 |
XtSetKeyboardFocus(find_paned, searchbox_input); |
| 1004 |
#endif |
| 1005 |
|
| 1006 |
/* |
| 1007 |
* form for left row of options checkbuttons |
| 1008 |
*/ |
| 1009 |
options_left_form = XtVaCreateManagedWidget("options_left_form", |
| 1010 |
FORM_WIDGET, |
| 1011 |
form, |
| 1012 |
#ifdef MOTIF |
| 1013 |
XmNhorizontalSpacing, DDIST, |
| 1014 |
XmNverticalSpacing, DDIST, |
| 1015 |
XmNresizable, True, |
| 1016 |
XmNtopAttachment, XmATTACH_WIDGET, |
| 1017 |
XmNtopWidget, searchbox_form, |
| 1018 |
XmNleftAttachment, XmATTACH_FORM, |
| 1019 |
/* XmNrightAttachment, XmATTACH_FORM, */ |
| 1020 |
/* XmNbottomAttachment, XmATTACH_FORM, */ |
| 1021 |
#else |
| 1022 |
XtNborderWidth, 0, |
| 1023 |
XtNfromVert, searchbox_form, |
| 1024 |
HORIZONTAL_RESIZING_NO, |
| 1025 |
#endif |
| 1026 |
NULL); |
| 1027 |
/* |
| 1028 |
* form for right row of options checkbuttons |
| 1029 |
*/ |
| 1030 |
options_right_form = XtVaCreateManagedWidget("options_right_form", |
| 1031 |
FORM_WIDGET, |
| 1032 |
form, |
| 1033 |
#ifdef MOTIF |
| 1034 |
XmNhorizontalSpacing, DDIST, |
| 1035 |
XmNverticalSpacing, DDIST, |
| 1036 |
XmNresizable, True, |
| 1037 |
XmNtopAttachment, XmATTACH_WIDGET, |
| 1038 |
XmNtopWidget, searchbox_form, |
| 1039 |
XmNleftAttachment, XmATTACH_WIDGET, |
| 1040 |
XmNleftWidget, options_left_form, |
| 1041 |
XmNrightAttachment, XmATTACH_FORM, |
| 1042 |
/* XmNbottomAttachment, XmATTACH_FORM, */ |
| 1043 |
#else |
| 1044 |
XtNborderWidth, 0, |
| 1045 |
XtNfromVert, searchbox_form, |
| 1046 |
XtNfromHoriz, options_left_form, |
| 1047 |
HORIZONTAL_RESIZING_NO, |
| 1048 |
#endif |
| 1049 |
NULL); |
| 1050 |
#ifdef MOTIF |
| 1051 |
XmStringFree(str); |
| 1052 |
str = XmStringCreateLocalized("Regular expression"); |
| 1053 |
#endif |
| 1054 |
|
| 1055 |
regexp_checkbox = XtVaCreateManagedWidget("regexp_checkbox", |
| 1056 |
CHECKBOX_WIDGET, |
| 1057 |
options_left_form, |
| 1058 |
#ifdef MOTIF |
| 1059 |
XmNlabelString, str, |
| 1060 |
XmNindicatorType, XmN_OF_MANY, |
| 1061 |
XmNtopAttachment, XmATTACH_FORM, |
| 1062 |
XmNleftAttachment, XmATTACH_FORM, |
| 1063 |
#else |
| 1064 |
XtNlabel, "Regular expression", |
| 1065 |
XtNborderWidth, 0, |
| 1066 |
XtNisRadio, False, |
| 1067 |
XtNhighlightThickness, 1, |
| 1068 |
HORIZONTAL_RESIZING_NO, |
| 1069 |
VERTICAL_RESIZING_NO, |
| 1070 |
#endif |
| 1071 |
NULL); |
| 1072 |
|
| 1073 |
XtAddCallback(regexp_checkbox, VALUE_CALLBACK_NAME, cb_regexp_search, settings); |
| 1074 |
|
| 1075 |
#ifdef MOTIF |
| 1076 |
XmStringFree(str); |
| 1077 |
str = XmStringCreateLocalized("Find backwards"); |
| 1078 |
#endif |
| 1079 |
|
| 1080 |
backwards_checkbox = XtVaCreateManagedWidget("backwards_checkbox", |
| 1081 |
CHECKBOX_WIDGET, |
| 1082 |
options_left_form, |
| 1083 |
#ifdef MOTIF |
| 1084 |
XmNlabelString, str, |
| 1085 |
XmNindicatorType, XmN_OF_MANY, |
| 1086 |
XmNtopAttachment, XmATTACH_WIDGET, |
| 1087 |
XmNtopWidget, regexp_checkbox, |
| 1088 |
XmNleftAttachment, XmATTACH_FORM, |
| 1089 |
#else |
| 1090 |
XtNlabel, "Find backwards", |
| 1091 |
XtNfromVert, regexp_checkbox, |
| 1092 |
XtNborderWidth, 0, |
| 1093 |
XtNisRadio, False, |
| 1094 |
XtNhighlightThickness, 1, |
| 1095 |
HORIZONTAL_RESIZING_NO, |
| 1096 |
VERTICAL_RESIZING_NO, |
| 1097 |
#endif |
| 1098 |
NULL); |
| 1099 |
|
| 1100 |
XtAddCallback(backwards_checkbox, VALUE_CALLBACK_NAME, cb_backwards_search, settings); |
| 1101 |
|
| 1102 |
#ifdef MOTIF |
| 1103 |
XmStringFree(str); |
| 1104 |
str = XmStringCreateLocalized("Wrap search"); |
| 1105 |
#endif |
| 1106 |
|
| 1107 |
wrap_checkbox = XtVaCreateManagedWidget("backwards_checkbox", |
| 1108 |
CHECKBOX_WIDGET, |
| 1109 |
options_left_form, |
| 1110 |
#ifdef MOTIF |
| 1111 |
XmNlabelString, str, |
| 1112 |
XmNindicatorType, XmN_OF_MANY, |
| 1113 |
XmNtopAttachment, XmATTACH_WIDGET, |
| 1114 |
XmNtopWidget, backwards_checkbox, |
| 1115 |
XmNleftAttachment, XmATTACH_FORM, |
| 1116 |
XmNbottomAttachment, XmATTACH_FORM, |
| 1117 |
#else |
| 1118 |
XtNlabel, "Wrap search", |
| 1119 |
XtNfromVert, backwards_checkbox, |
| 1120 |
XtNborderWidth, 0, |
| 1121 |
XtNisRadio, False, |
| 1122 |
XtNhighlightThickness, 1, |
| 1123 |
HORIZONTAL_RESIZING_NO, |
| 1124 |
VERTICAL_RESIZING_NO, |
| 1125 |
#endif |
| 1126 |
NULL); |
| 1127 |
|
| 1128 |
XtAddCallback(wrap_checkbox, VALUE_CALLBACK_NAME, cb_wrap_search, settings); |
| 1129 |
|
| 1130 |
#ifdef MOTIF |
| 1131 |
XmStringFree(str); |
| 1132 |
str = XmStringCreateLocalized("Case sensitive"); |
| 1133 |
#endif |
| 1134 |
|
| 1135 |
matchcase_checkbox = XtVaCreateManagedWidget("matchcase_checkbox", |
| 1136 |
CHECKBOX_WIDGET, |
| 1137 |
options_right_form, |
| 1138 |
#ifdef MOTIF |
| 1139 |
XmNlabelString, str, |
| 1140 |
XmNindicatorType, XmN_OF_MANY, |
| 1141 |
XmNtopAttachment, XmATTACH_FORM, |
| 1142 |
XmNleftAttachment, XmATTACH_FORM, |
| 1143 |
#else |
| 1144 |
XtNlabel, "Case sensitive", |
| 1145 |
XtNborderWidth, 0, |
| 1146 |
XtNisRadio, False, |
| 1147 |
XtNhighlightThickness, 1, |
| 1148 |
HORIZONTAL_RESIZING_NO, |
| 1149 |
VERTICAL_RESIZING_NO, |
| 1150 |
#endif |
| 1151 |
NULL); |
| 1152 |
|
| 1153 |
XtAddCallback(matchcase_checkbox, VALUE_CALLBACK_NAME, cb_match_case, settings); |
| 1154 |
|
| 1155 |
#ifdef MOTIF |
| 1156 |
XmStringFree(str); |
| 1157 |
str = XmStringCreateLocalized("Ignore newlines/hyphens"); |
| 1158 |
#endif |
| 1159 |
|
| 1160 |
linebreaks_checkbox = XtVaCreateManagedWidget("linebreaks_checkbox", |
| 1161 |
CHECKBOX_WIDGET, |
| 1162 |
options_right_form, |
| 1163 |
#ifdef MOTIF |
| 1164 |
XmNlabelString, str, |
| 1165 |
XmNindicatorType, XmN_OF_MANY, |
| 1166 |
XmNtopAttachment, XmATTACH_WIDGET, |
| 1167 |
XmNtopWidget, matchcase_checkbox, |
| 1168 |
XmNleftAttachment, XmATTACH_FORM, |
| 1169 |
#else |
| 1170 |
XtNlabel, "Ignore newlines/hyphens", |
| 1171 |
XtNfromVert, matchcase_checkbox, |
| 1172 |
XtNborderWidth, 0, |
| 1173 |
XtNisRadio, False, |
| 1174 |
XtNhighlightThickness, 1, |
| 1175 |
HORIZONTAL_RESIZING_NO, |
| 1176 |
VERTICAL_RESIZING_NO, |
| 1177 |
#endif |
| 1178 |
NULL); |
| 1179 |
|
| 1180 |
XtAddCallback(linebreaks_checkbox, VALUE_CALLBACK_NAME, cb_linebreaks, settings); |
| 1181 |
|
| 1182 |
/* |
| 1183 |
* box for Find/Cancel buttons |
| 1184 |
*/ |
| 1185 |
box = XtVaCreateManagedWidget("box", |
| 1186 |
FORM_WIDGET, |
| 1187 |
find_paned, |
| 1188 |
#ifdef MOTIF |
| 1189 |
XmNskipAdjust, True, /* don't resize this area */ |
| 1190 |
#else |
| 1191 |
/* resizing by user isn't needed */ |
| 1192 |
XtNshowGrip, False, |
| 1193 |
XtNdefaultDistance, 6, /* some padding */ |
| 1194 |
/* resizing the window shouldn't influence this box, |
| 1195 |
* but only the pane widget |
| 1196 |
*/ |
| 1197 |
XtNskipAdjust, True, |
| 1198 |
XtNaccelerators, G_accels_cr, |
| 1199 |
#endif |
| 1200 |
NULL); |
| 1201 |
|
| 1202 |
#ifdef MOTIF |
| 1203 |
XmStringFree(str); |
| 1204 |
str = XmStringCreateLocalized("Find"); |
| 1205 |
#endif |
| 1206 |
|
| 1207 |
find_button = XtVaCreateManagedWidget("find_button", |
| 1208 |
PUSHBUTTON_WIDGET, |
| 1209 |
box, |
| 1210 |
#ifdef MOTIF |
| 1211 |
XmNlabelString, str, |
| 1212 |
XmNshowAsDefault, True, |
| 1213 |
XmNdefaultButtonShadowThickness, 1, |
| 1214 |
XmNtopAttachment, XmATTACH_FORM, |
| 1215 |
XmNbottomAttachment, XmATTACH_FORM, |
| 1216 |
XmNleftAttachment, XmATTACH_FORM, |
| 1217 |
/* to mimick appearance of native dialog buttons: */ |
| 1218 |
XmNmarginWidth, 6, |
| 1219 |
XmNmarginHeight, 4, |
| 1220 |
XmNtopOffset, 10, |
| 1221 |
XmNbottomOffset, 10, |
| 1222 |
XmNleftOffset, 10, |
| 1223 |
#else |
| 1224 |
XtNlabel, "Find", |
| 1225 |
XtNaccelerators, G_accels_cr, |
| 1226 |
XtNtop, XtChainTop, |
| 1227 |
XtNbottom, XtChainBottom, |
| 1228 |
HORIZONTAL_RESIZING_NO, |
| 1229 |
#endif |
| 1230 |
NULL); |
| 1231 |
#ifdef MOTIF |
| 1232 |
XmStringFree(str); |
| 1233 |
str = XmStringCreateLocalized("Cancel"); |
| 1234 |
#endif |
| 1235 |
|
| 1236 |
cancel_button = XtVaCreateManagedWidget("cancel_button", |
| 1237 |
PUSHBUTTON_WIDGET, |
| 1238 |
box, |
| 1239 |
#ifdef MOTIF |
| 1240 |
XmNlabelString, str, |
| 1241 |
XmNdefaultButtonShadowThickness, 1, |
| 1242 |
XmNtopAttachment, XmATTACH_FORM, |
| 1243 |
XmNbottomAttachment, XmATTACH_FORM, |
| 1244 |
XmNrightAttachment, XmATTACH_FORM, |
| 1245 |
/* to mimick appearance of native dialog buttons: */ |
| 1246 |
XmNmarginWidth, 6, |
| 1247 |
XmNmarginHeight, 4, |
| 1248 |
XmNtopOffset, 10, |
| 1249 |
XmNbottomOffset, 10, |
| 1250 |
XmNrightOffset, 10, |
| 1251 |
#else |
| 1252 |
XtNlabel, "Cancel", |
| 1253 |
XtNfromHoriz, find_button, |
| 1254 |
XtNbottom, XtChainBottom, |
| 1255 |
XtNjustify, XtJustifyRight, |
| 1256 |
XtNleft, XtChainRight, |
| 1257 |
XtNright, XtChainRight, |
| 1258 |
#endif |
| 1259 |
NULL); |
| 1260 |
|
| 1261 |
#ifdef MOTIF |
| 1262 |
XmStringFree(str); |
| 1263 |
#endif |
| 1264 |
|
| 1265 |
XtAddCallback(cancel_button, ACTIVATE_CALLBACK_NAME, cb_search_cancel, settings); |
| 1266 |
XtAddCallback(find_button, ACTIVATE_CALLBACK_NAME, cb_search_get_term_button, settings); |
| 1267 |
|
| 1268 |
XtOverrideTranslations(searchbox_form, xlats); |
| 1269 |
XtOverrideTranslations(options_left_form, xlats); |
| 1270 |
XtOverrideTranslations(options_right_form, xlats); |
| 1271 |
XtOverrideTranslations(regexp_checkbox, xlats); |
| 1272 |
XtOverrideTranslations(matchcase_checkbox, xlats); |
| 1273 |
XtOverrideTranslations(backwards_checkbox, xlats); |
| 1274 |
XtOverrideTranslations(box, xlats); |
| 1275 |
XtOverrideTranslations(find_button, xlats); |
| 1276 |
XtOverrideTranslations(cancel_button, xlats); |
| 1277 |
XtOverrideTranslations(searchbox_input, xlats); |
| 1278 |
|
| 1279 |
/* following doesn't help to force input to textbox in xaw: */ |
| 1280 |
/* XtInstallAllAccelerators(find_paned, find_paned); */ |
| 1281 |
/* XtInstallAllAccelerators(searchbox_input, find_paned); */ |
| 1282 |
|
| 1283 |
XtManageChild(form); |
| 1284 |
XtManageChild(find_paned); |
| 1285 |
|
| 1286 |
{ /* set all buttons to same size */ |
| 1287 |
Dimension w1, w2, max; |
| 1288 |
XtVaGetValues(find_button, XtNwidth, &w1, NULL); |
| 1289 |
XtVaGetValues(cancel_button, XtNwidth, &w2, NULL); |
| 1290 |
max = MAX(w1, w2); |
| 1291 |
XtVaSetValues(find_button, XtNwidth, max, NULL); |
| 1292 |
XtVaSetValues(cancel_button, XtNwidth, max, NULL); |
| 1293 |
} |
| 1294 |
|
| 1295 |
XtManageChild(top_level_shell); |
| 1296 |
/* don't center this one - would just get in the way in this case. */ |
| 1297 |
/* center_window(top_level_shell, globals.widgets.top_level); */ |
| 1298 |
XtPopup(top_level_shell, XtGrabNone); |
| 1299 |
m_find_popup_active = True; |
| 1300 |
|
| 1301 |
#ifdef MOTIF |
| 1302 |
XmProcessTraversal(searchbox_input, XmTRAVERSE_CURRENT); |
| 1303 |
/* XmProcessTraversal(find_button, XmTRAVERSE_CURRENT); */ |
| 1304 |
#endif |
| 1305 |
XSetWMProtocols(XtDisplay(top_level_shell), XtWindow(top_level_shell), &WM_DELETE_WINDOW, 1); |
| 1306 |
|
| 1307 |
/* check if we have default values from resource.search_window_defaults */ |
| 1308 |
if (resource.search_window_defaults & SETTINGS_USE_REGEXP_FLAG) |
| 1309 |
XtVaSetValues(regexp_checkbox, CHECKBUTTON_IS_SET, True, NULL); |
| 1310 |
if (resource.search_window_defaults & SETTINGS_CASE_SENSITIVE_FLAG) |
| 1311 |
XtVaSetValues(matchcase_checkbox, CHECKBUTTON_IS_SET, True, NULL); |
| 1312 |
if (resource.search_window_defaults & SETTINGS_BACKWARDS_FLAG) |
| 1313 |
XtVaSetValues(backwards_checkbox, CHECKBUTTON_IS_SET, True, NULL); |
| 1314 |
if (resource.search_window_defaults & SETTINGS_IGNORE_LINEBREAKS_FLAG) |
| 1315 |
XtVaSetValues(linebreaks_checkbox, CHECKBUTTON_IS_SET, True, NULL); |
| 1316 |
if (resource.search_window_defaults & SETTINGS_WRAP_FLAG) |
| 1317 |
XtVaSetValues(wrap_checkbox, CHECKBUTTON_IS_SET, True, NULL); |
| 1318 |
|
| 1319 |
/* initialize `settings' values according to the checkbox states |
| 1320 |
(in case user has assigned values via X defaults): */ |
| 1321 |
XtVaGetValues(regexp_checkbox, CHECKBUTTON_IS_SET, &curr_state, NULL); |
| 1322 |
settings->use_regexp = curr_state; |
| 1323 |
XtVaGetValues(matchcase_checkbox, CHECKBUTTON_IS_SET, &curr_state, NULL); |
| 1324 |
settings->case_sensitive = curr_state; |
| 1325 |
XtVaGetValues(wrap_checkbox, CHECKBUTTON_IS_SET, &curr_state, NULL); |
| 1326 |
settings->wrap = curr_state; |
| 1327 |
XtVaGetValues(backwards_checkbox, CHECKBUTTON_IS_SET, &curr_state, NULL); |
| 1328 |
settings->direction = curr_state ? SEARCH_UP : SEARCH_DOWN; |
| 1329 |
XtVaGetValues(linebreaks_checkbox, CHECKBUTTON_IS_SET, &curr_state, NULL); |
| 1330 |
settings->ignore_hyphens = settings->ignore_linebreaks = curr_state; |
| 1331 |
|
| 1332 |
#ifndef MOTIF |
| 1333 |
|
| 1334 |
#undef HORIZONTAL_RESIZING_NO |
| 1335 |
#undef HORIZONTAL_RESIZING_YES |
| 1336 |
#undef VERTICAL_RESIZING_NO |
| 1337 |
|
| 1338 |
#endif /* MOTIF */ |
| 1339 |
return top_level_shell; |
| 1340 |
} |
| 1341 |
|
| 1342 |
void |
| 1343 |
dvi_find_string(const char *str, Boolean find_next) |
| 1344 |
{ |
| 1345 |
/* Synthesize a RET keystroke for the find dialog. |
| 1346 |
* Also pops up the find dialog, to make it easier for user to |
| 1347 |
* edit options, change direction etc. */ |
| 1348 |
Widget find_popup; |
| 1349 |
if (!get_widget_by_name(&find_popup, globals.widgets.top_level, "find_popup", False)) { |
| 1350 |
static struct search_settings settings; |
| 1351 |
static struct search_info searchinfo = { False, False, False, 0, 0, 0, 0 }; |
| 1352 |
settings.term = str; |
| 1353 |
settings.use_regexp = False; |
| 1354 |
settings.case_sensitive = False; |
| 1355 |
settings.direction = SEARCH_DOWN; |
| 1356 |
settings.ignore_hyphens = False; |
| 1357 |
settings.ignore_linebreaks = False; |
| 1358 |
settings.wrap = False; |
| 1359 |
settings.isearchterm = NULL; |
| 1360 |
settings.wrapcnt = 0; |
| 1361 |
settings.x_pos = -1; |
| 1362 |
settings.y_pos = -1; |
| 1363 |
settings.searchinfo = &searchinfo; |
| 1364 |
settings.hyphen_delta = 0; |
| 1365 |
|
| 1366 |
find_popup = create_search_window(&settings); |
| 1367 |
|
| 1368 |
if (find_next) |
| 1369 |
return; |
| 1370 |
} |
| 1371 |
else if (str != NULL) { /* change the search term */ |
| 1372 |
Widget searchbox_input; |
| 1373 |
if (!get_widget_by_name(&searchbox_input, find_popup, "searchbox_input", True)) |
| 1374 |
return; |
| 1375 |
XtVaSetValues(searchbox_input, |
| 1376 |
#ifdef MOTIF |
| 1377 |
XmNvalue, |
| 1378 |
#else |
| 1379 |
XtNstring, |
| 1380 |
#endif |
| 1381 |
str, NULL); |
| 1382 |
} |
| 1383 |
if (m_find_popup_active) { |
| 1384 |
XRaiseWindow(DISP, XtWindow(find_popup)); |
| 1385 |
} |
| 1386 |
else { |
| 1387 |
XtPopup(find_popup, XtGrabNone); |
| 1388 |
m_find_popup_active = True; |
| 1389 |
} |
| 1390 |
|
| 1391 |
if (str != NULL || find_next) { |
| 1392 |
#ifdef MOTIF |
| 1393 |
xm_search_go(NULL, NULL, NULL, NULL); |
| 1394 |
#else |
| 1395 |
xaw_search_go(NULL, NULL, NULL, NULL); |
| 1396 |
#endif |
| 1397 |
} |
| 1398 |
} |
| 1399 |
|