| 1 |
/*======================================================================*\ |
| 2 |
|
| 3 |
Copyright (c) 1990-2019 Paul Vojta and others |
| 4 |
|
| 5 |
Permission is hereby granted, free of charge, to any person obtaining a copy |
| 6 |
of this software and associated documentation files (the "Software"), to |
| 7 |
deal in the Software without restriction, including without limitation the |
| 8 |
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
| 9 |
sell copies of the Software, and to permit persons to whom the Software is |
| 10 |
furnished to do so, subject to the following conditions: |
| 11 |
|
| 12 |
The above copyright notice and this permission notice shall be included in |
| 13 |
all copies or substantial portions of the Software. |
| 14 |
|
| 15 |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 |
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 |
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 18 |
PAUL VOJTA OR ANY OTHER AUTHOR OF THIS SOFTWARE BE LIABLE FOR ANY CLAIM, |
| 19 |
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
| 20 |
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 21 |
OTHER DEALINGS IN THE SOFTWARE. |
| 22 |
|
| 23 |
NOTE: |
| 24 |
xdvi is based on prior work, as noted in the modification history |
| 25 |
in xdvi.c. |
| 26 |
|
| 27 |
\*========================================================================*/ |
| 28 |
|
| 29 |
#include "xdvi-config.h" |
| 30 |
|
| 31 |
#ifdef STDC_HEADERS |
| 32 |
# include <unistd.h> |
| 33 |
# include <fcntl.h> |
| 34 |
#endif |
| 35 |
#include <signal.h> |
| 36 |
#include <sys/file.h> /* this defines FASYNC */ |
| 37 |
#ifdef HAVE_SYS_FCNTL_H |
| 38 |
# include <sys/fcntl.h> /* Or this might define FASYNC */ |
| 39 |
#endif |
| 40 |
#include <sys/ioctl.h> /* this defines SIOCSPGRP and FIOASYNC */ |
| 41 |
#include <sys/wait.h> /* ignore HAVE_SYS_WAIT_H -- we always need WNOHANG */ |
| 42 |
|
| 43 |
#include "xdvi.h" /* this includes Xlib and Xutil are already included */ |
| 44 |
#include "xdvi-debug.h" |
| 45 |
|
| 46 |
|
| 47 |
#ifndef MOTIF |
| 48 |
#include <X11/Xaw/Form.h> /* for XtNresizable */ |
| 49 |
#endif |
| 50 |
|
| 51 |
#include <setjmp.h> |
| 52 |
#include <sys/time.h> /* for gettimeofday */ |
| 53 |
|
| 54 |
#include <X11/IntrinsicP.h> |
| 55 |
|
| 56 |
#include <X11/Xatom.h> |
| 57 |
#include <X11/StringDefs.h> |
| 58 |
#include <X11/Shell.h> /* needed for def. of XtNiconX(??) */ |
| 59 |
|
| 60 |
#include "pagesel.h" |
| 61 |
#include "filehist.h" |
| 62 |
#include "special.h" |
| 63 |
#include "psgs.h" |
| 64 |
|
| 65 |
|
| 66 |
#include <errno.h> |
| 67 |
|
| 68 |
#include <ctype.h> |
| 69 |
|
| 70 |
#include "util.h" |
| 71 |
#include "x_util.h" |
| 72 |
#include "string-utils.h" |
| 73 |
#include "print-dialog.h" |
| 74 |
#include "search-dialog.h" |
| 75 |
#include "sfSelFile.h" |
| 76 |
#include "mag.h" |
| 77 |
#include "help-window.h" |
| 78 |
#include "message-window.h" |
| 79 |
#include "dvi-draw.h" |
| 80 |
#include "statusline.h" |
| 81 |
#include "hypertex.h" |
| 82 |
#include "dvi-init.h" |
| 83 |
#include "exit-handlers.h" |
| 84 |
#include "Tip.h" |
| 85 |
#include "browser.h" |
| 86 |
#include "search-internal.h" |
| 87 |
#include "my-snprintf.h" |
| 88 |
|
| 89 |
#include "events.h" |
| 90 |
#include "selection.h" |
| 91 |
#include "encodings.h" |
| 92 |
#include "pagehist.h" |
| 93 |
#include "xm_colorsel.h" |
| 94 |
#include "xm_toolbar.h" |
| 95 |
#include "xaw_menu.h" |
| 96 |
#include "xm_menu.h" |
| 97 |
#include "xm_prefs.h" |
| 98 |
|
| 99 |
#include "xm_prefs_appearance.h" /* for update_preferences_expert() */ |
| 100 |
#include "xm_prefs_fonts.h" /* for update_preferences_color() */ |
| 101 |
#include "xm_prefs_page.h" /* for update_preferences_shrink() */ |
| 102 |
|
| 103 |
#ifdef X_NOT_STDC_ENV |
| 104 |
extern int errno; |
| 105 |
#endif /* X_NOT_STDC_ENV */ |
| 106 |
|
| 107 |
#if HAVE_X11_INTRINSICI_H |
| 108 |
# include <X11/IntrinsicI.h> |
| 109 |
#else |
| 110 |
|
| 111 |
/* Taken from <X11/TranslateI.h> in libXt-1.1.3 (June 2012) */ |
| 112 |
typedef struct _LateBindings { |
| 113 |
unsigned int knot:1; |
| 114 |
unsigned int pair:1; |
| 115 |
unsigned short ref_count; /* garbage collection */ |
| 116 |
KeySym keysym; |
| 117 |
} LateBindings, *LateBindingsPtr; |
| 118 |
|
| 119 |
extern Boolean _XtComputeLateBindings( |
| 120 |
Display* /* dpy */, |
| 121 |
LateBindingsPtr /* lateModifiers */, |
| 122 |
Modifiers* /* computed */, |
| 123 |
Modifiers* /* computedMask */ |
| 124 |
); |
| 125 |
|
| 126 |
#endif /* not HAVE_X11_INTRINSICI_H */ |
| 127 |
|
| 128 |
#if HAVE_XKB_BELL_EXT |
| 129 |
# include <X11/XKBlib.h> |
| 130 |
# define XdviBell(display, window, percent) \ |
| 131 |
XkbBell(display, window, percent, (Atom) None) |
| 132 |
#else |
| 133 |
# define XdviBell(display, window, percent) XBell(display, percent) |
| 134 |
#endif |
| 135 |
|
| 136 |
/* Linux prefers O_ASYNC over FASYNC; SGI IRIX does the opposite. */ |
| 137 |
#if !defined(FASYNC) && defined(O_ASYNC) |
| 138 |
# define FASYNC O_ASYNC |
| 139 |
#endif |
| 140 |
|
| 141 |
#if !defined(FLAKY_SIGPOLL) && !HAVE_STREAMS && !defined(FASYNC) |
| 142 |
# if !defined(SIOCSPGRP) || !defined(FIOASYNC) |
| 143 |
# define FLAKY_SIGPOLL 1 |
| 144 |
# endif |
| 145 |
#endif |
| 146 |
|
| 147 |
#ifndef FLAKY_SIGPOLL |
| 148 |
|
| 149 |
# ifndef SIGPOLL |
| 150 |
# define SIGPOLL SIGIO |
| 151 |
# endif |
| 152 |
|
| 153 |
# ifndef SA_RESTART |
| 154 |
# define SA_RESTART 0 |
| 155 |
# endif |
| 156 |
|
| 157 |
# if HAVE_STREAMS |
| 158 |
# include <stropts.h> |
| 159 |
|
| 160 |
# ifndef S_RDNORM |
| 161 |
# define S_RDNORM S_INPUT |
| 162 |
# endif |
| 163 |
|
| 164 |
# ifndef S_RDBAND |
| 165 |
# define S_RDBAND 0 |
| 166 |
# endif |
| 167 |
|
| 168 |
# ifndef S_HANGUP |
| 169 |
# define S_HANGUP 0 |
| 170 |
# endif |
| 171 |
|
| 172 |
# ifndef S_WRNORM |
| 173 |
# define S_WRNORM S_OUTPUT |
| 174 |
# endif |
| 175 |
# endif /* HAVE_STREAMS */ |
| 176 |
|
| 177 |
#endif /* not FLAKY_SIGPOLL */ |
| 178 |
|
| 179 |
#if HAVE_SIGACTION && !defined SA_RESETHAND |
| 180 |
# ifdef SA_ONESHOT |
| 181 |
# define SA_RESETHAND SA_ONESHOT |
| 182 |
# else |
| 183 |
# undef HAVE_SIGACTION /* Needed for Mac OS X < 10.2 (9/2002) */ |
| 184 |
# endif |
| 185 |
#endif |
| 186 |
|
| 187 |
#if HAVE_POLL |
| 188 |
# include <poll.h> |
| 189 |
#else |
| 190 |
# if HAVE_SYS_SELECT_H |
| 191 |
# include <sys/select.h> |
| 192 |
# else |
| 193 |
# if HAVE_SELECT_H |
| 194 |
# include <select.h> |
| 195 |
# endif |
| 196 |
# endif |
| 197 |
# define XIO_IN 1 |
| 198 |
# define XIO_OUT 2 |
| 199 |
#endif /* HAVE_POLL */ |
| 200 |
|
| 201 |
/* cannot be const since Strings in Action routines aren't either */ |
| 202 |
static char *Act_true_retval = "true"; |
| 203 |
static char *Act_false_retval = "false"; |
| 204 |
|
| 205 |
|
| 206 |
#if HAVE_XI21 |
| 207 |
|
| 208 |
int xi2_opcode; |
| 209 |
Boolean xi2_active = False; |
| 210 |
struct xi2_master *xi2_masters; /* linked list of master devs */ |
| 211 |
struct xi2_master *xi2_current; /* current master device */ |
| 212 |
struct xi2_slave *xi2_slaves; /* linked list of slave devs */ |
| 213 |
|
| 214 |
struct xi2_slave xi2_no_slave; /* if no slave assigned yet */ |
| 215 |
|
| 216 |
/* |
| 217 |
* XInput 2.1 creates spurious enter/leave events around the time it |
| 218 |
* creates fake wheel button events. So, we keep track of the last |
| 219 |
* such fake button event, and if an enter/leave occurs too soon after |
| 220 |
* that event, then we ignore the enter event. |
| 221 |
* I've managed to get rid of this (by making sure that the relevant |
| 222 |
* events come from the drawing window if possible), but I left the code |
| 223 |
* here just in case. |
| 224 |
*/ |
| 225 |
|
| 226 |
static Time xi2_ign_time; /* time of last XI 2.1 wheel button event */ |
| 227 |
|
| 228 |
#endif |
| 229 |
|
| 230 |
|
| 231 |
static sigset_t all_signals; |
| 232 |
|
| 233 |
/* |
| 234 |
* Interrupt system for receiving events. The program sets a flag |
| 235 |
* whenever an event comes in, so that at the proper time (i.e., when |
| 236 |
* reading a new dvi item), we can check incoming events to see if we |
| 237 |
* still want to go on printing this page. This way, one can stop |
| 238 |
* displaying a page if it is about to be erased anyway. We try to read |
| 239 |
* as many events as possible before doing anything and base the next |
| 240 |
* action on all events read. |
| 241 |
* Note that the Xlib and Xt routines are not reentrant, so the most we |
| 242 |
* can do is set a flag in the interrupt routine and check it later. |
| 243 |
* Also, sometimes the interrupts are not generated (some systems only |
| 244 |
* guarantee that SIGIO is generated for terminal files, and on the system |
| 245 |
* I use, the interrupts are not generated if I use "(xdvi foo &)" instead |
| 246 |
* of "xdvi foo"). Therefore, there is also a mechanism to check the |
| 247 |
* event queue every 70 drawing operations or so. This mechanism is |
| 248 |
* disabled if it turns out that the interrupts do work. |
| 249 |
* For a fuller discussion of some of the above, see xlife in |
| 250 |
* comp.sources.x. |
| 251 |
*/ |
| 252 |
|
| 253 |
/* |
| 254 |
* Signal flags |
| 255 |
*/ |
| 256 |
|
| 257 |
/* This could be static volatile, but we want to avoid any optimizer bugs. */ |
| 258 |
VOLATILE unsigned int sig_flags = 0; |
| 259 |
|
| 260 |
#define SF_USR 1 |
| 261 |
#define SF_ALRM 2 |
| 262 |
#define SF_POLL 4 |
| 263 |
#define SF_CHLD 8 |
| 264 |
#define SF_TERM 16 |
| 265 |
#define SF_SEGV 32 |
| 266 |
|
| 267 |
static void do_sigusr(void); |
| 268 |
static void do_sigalrm(void); |
| 269 |
static void do_sigpoll(void); |
| 270 |
static void do_sigchld(void); |
| 271 |
static void do_sigterm(void); |
| 272 |
static void do_sigsegv(void); |
| 273 |
|
| 274 |
/* these must be in the same order as SF_*. |
| 275 |
The higher flags have higher priority, since these are |
| 276 |
checked first when resolving flags_to_sigproc[sig_flags]. |
| 277 |
|
| 278 |
Example: flag := SF_TERM | SF_CHLD = 24 |
| 279 |
|
| 280 |
flags_to_sigproc[24] => |
| 281 |
do_sigterm, which sets flag to 24 & ~SF_TERM == 8 |
| 282 |
then, in next check: |
| 283 |
flags_to_sigproc[8] => |
| 284 |
do_sigchld, which sets flag 8 & ~SF_CHLD == 0. |
| 285 |
*/ |
| 286 |
#define SP0 do_sigusr |
| 287 |
#define SP1 do_sigalrm |
| 288 |
#define SP2 do_sigpoll |
| 289 |
#define SP3 do_sigchld |
| 290 |
#define SP4 do_sigterm |
| 291 |
#define SP5 do_sigsegv |
| 292 |
|
| 293 |
typedef void (*signalproc)(void); |
| 294 |
|
| 295 |
static const signalproc flags_to_sigproc[64] = { |
| 296 |
NULL, |
| 297 |
/* 1 */ |
| 298 |
SP0, |
| 299 |
/* 2 - 3 */ |
| 300 |
SP1, SP1, |
| 301 |
/* 4 - 7 */ |
| 302 |
SP2, SP2, SP2, SP2, |
| 303 |
/* 8 - 15 */ |
| 304 |
SP3, SP3, SP3, SP3, SP3, SP3, SP3, SP3, |
| 305 |
/* 16 - 31 */ |
| 306 |
SP4, SP4, SP4, SP4, SP4, SP4, SP4, SP4, |
| 307 |
SP4, SP4, SP4, SP4, SP4, SP4, SP4, SP4, |
| 308 |
/* 32 - 63 */ |
| 309 |
SP5, SP5, SP5, SP5, SP5, SP5, SP5, SP5, |
| 310 |
SP5, SP5, SP5, SP5, SP5, SP5, SP5, SP5, |
| 311 |
SP5, SP5, SP5, SP5, SP5, SP5, SP5, SP5, |
| 312 |
SP5, SP5, SP5, SP5, SP5, SP5, SP5, SP5 |
| 313 |
}; |
| 314 |
|
| 315 |
#undef SP0 |
| 316 |
#undef SP2 |
| 317 |
#undef SP3 |
| 318 |
#undef SP4 |
| 319 |
#undef SP5 |
| 320 |
|
| 321 |
/* file-static variables for prefix argument mechanism */ |
| 322 |
static Boolean m_have_arg = False; /* flag whether we have a possible prefix arg */ |
| 323 |
static int m_number = 0; /* prefix arg value, without the sign */ |
| 324 |
static int m_sign = 1; /* is prefix arg negative? */ |
| 325 |
|
| 326 |
|
| 327 |
/* to remember the scrollbar positions so that we can restore them |
| 328 |
when `keep position' is active and window is resized to full size |
| 329 |
(removing scrollbars) and then back (#810501) */ |
| 330 |
static int m_x_scroll = 0, m_y_scroll = 0; |
| 331 |
|
| 332 |
static int source_reverse_x, source_reverse_y; |
| 333 |
static int source_show_all; |
| 334 |
|
| 335 |
/* globals for color stuff */ |
| 336 |
Pixel plane_masks[4]; |
| 337 |
XColor color_data[2]; |
| 338 |
struct pagecolor_info page_colors = { 0, NULL }; |
| 339 |
|
| 340 |
struct rgb *color_bottom; |
| 341 |
unsigned int color_bot_size; /* number of entries */ |
| 342 |
struct colorframe *rcs_top; |
| 343 |
struct rgb fg_initial; /* Initial fg (from command line) */ |
| 344 |
struct rgb bg_initial; /* Initial bg */ |
| 345 |
struct bgrec *bg_head = NULL; /* head of list */ |
| 346 |
struct bgrec *bg_current = NULL; /* current bg value */ |
| 347 |
struct fgrec *fg_current; /* current fg value */ |
| 348 |
struct fgrec *fg_active = NULL; /* where the GCs are */ |
| 349 |
Pixel *color_list; /* list of colors */ |
| 350 |
unsigned int color_list_len = 0; /* current len of list*/ |
| 351 |
unsigned int color_list_max = 0; /* allocated size */ |
| 352 |
Boolean color_warned = False; |
| 353 |
|
| 354 |
void null_mouse(XEvent *event) |
| 355 |
{ |
| 356 |
UNUSED(event); |
| 357 |
} |
| 358 |
|
| 359 |
mouse_proc mouse_motion = null_mouse; |
| 360 |
mouse_proc mouse_release = null_mouse; |
| 361 |
|
| 362 |
static void Act_digit(Widget, XEvent *, String *, Cardinal *); |
| 363 |
static void Act_find(Widget, XEvent *, String *, Cardinal *); |
| 364 |
static void Act_incremental_find(Widget, XEvent *, String *, Cardinal *); |
| 365 |
static void Act_find_next(Widget, XEvent *, String *, Cardinal *); |
| 366 |
static void Act_minus(Widget, XEvent *, String *, Cardinal *); |
| 367 |
static void Act_quit(Widget, XEvent *, String *, Cardinal *); |
| 368 |
static void Act_quit_confirm(Widget, XEvent *, String *, Cardinal *); |
| 369 |
static void Act_print(Widget, XEvent *, String *, Cardinal *); |
| 370 |
static void Act_save(Widget, XEvent *, String *, Cardinal *); |
| 371 |
static void Act_help(Widget, XEvent *, String *, Cardinal *); |
| 372 |
static void Act_goto_page(Widget, XEvent *, String *, Cardinal *); |
| 373 |
static void Act_declare_page_number(Widget, XEvent *, String *, Cardinal *); |
| 374 |
static void Act_toggle_mark(Widget, XEvent *, String *, Cardinal *); |
| 375 |
static void Act_home(Widget, XEvent *, String *, Cardinal *); |
| 376 |
static void Act_home_or_top(Widget, XEvent *, String *, Cardinal *); |
| 377 |
static void Act_end_or_bottom(Widget, XEvent *, String *, Cardinal *); |
| 378 |
static void Act_center(Widget, XEvent *, String *, Cardinal *); |
| 379 |
static void Act_left(Widget, XEvent *, String *, Cardinal *); |
| 380 |
static void Act_right(Widget, XEvent *, String *, Cardinal *); |
| 381 |
static void Act_up(Widget, XEvent *, String *, Cardinal *); |
| 382 |
static void Act_down(Widget, XEvent *, String *, Cardinal *); |
| 383 |
static void Act_up_or_previous(Widget, XEvent *, String *, Cardinal *); |
| 384 |
static void Act_down_or_next(Widget, XEvent *, String *, Cardinal *); |
| 385 |
static void Act_set_margins(Widget, XEvent *, String *, Cardinal *); |
| 386 |
static void Act_show_display_attributes(Widget, XEvent *, String *, Cardinal *); |
| 387 |
static void Act_set_density(Widget, XEvent *, String *, Cardinal *); |
| 388 |
static void Act_change_density(Widget, XEvent *, String *, Cardinal *); |
| 389 |
static void Act_fullscreen(Widget, XEvent *, String *, Cardinal *); |
| 390 |
#ifdef GREY |
| 391 |
static void Act_set_greyscaling(Widget, XEvent *, String *, Cardinal *); |
| 392 |
#endif |
| 393 |
#if COLOR |
| 394 |
static void Act_set_color(Widget, XEvent *, String *, Cardinal *); |
| 395 |
#endif |
| 396 |
|
| 397 |
static void Act_htex_anchorinfo(Widget, XEvent *, String *, Cardinal *); |
| 398 |
|
| 399 |
static void Act_reread_dvi_file(Widget, XEvent *, String *, Cardinal *); |
| 400 |
static void Act_select_dvi_file(Widget, XEvent *, String *, Cardinal *); |
| 401 |
static void Act_discard_number(Widget, XEvent *, String *, Cardinal *); |
| 402 |
static void Act_drag(Widget, XEvent *, String *, Cardinal *); |
| 403 |
static void Act_wheel(Widget, XEvent *, String *, Cardinal *); |
| 404 |
static void Act_hwheel(Widget, XEvent *, String *, Cardinal *); |
| 405 |
static void Act_press(Widget, XEvent *, String *, Cardinal *); |
| 406 |
static void Act_motion(Widget, XEvent *, String *, Cardinal *); |
| 407 |
static void Act_release(Widget, XEvent *, String *, Cardinal *); |
| 408 |
static void Act_toggle_grid_mode(Widget, XEvent *, String *, Cardinal *); |
| 409 |
static void Act_source_special(Widget, XEvent *, String *, Cardinal *); |
| 410 |
static void Act_show_source_specials(Widget, XEvent *, String *, Cardinal *); |
| 411 |
static void Act_source_what_special(Widget, XEvent *, String *, Cardinal *); |
| 412 |
static void Act_unpause_or_next(Widget, XEvent *, String *, Cardinal *); |
| 413 |
static void Act_user_exec(Widget, XEvent *, String *, Cardinal *); |
| 414 |
static void Act_ruler_snap_origin(Widget w, XEvent *event, String *params, Cardinal *num_params); |
| 415 |
static void Act_load_url(Widget w, XEvent *event, String *params, Cardinal *num_params); |
| 416 |
#ifdef MOTIF |
| 417 |
static void Act_prefs_dialog(Widget w, XEvent *event, String *params, Cardinal *num_params); |
| 418 |
#endif |
| 419 |
|
| 420 |
static XtActionsRec m_actions[] = { |
| 421 |
{"digit", Act_digit}, |
| 422 |
{"mouse-modes", Act_mouse_modes}, |
| 423 |
{"switch-mode", Act_switch_mode}, |
| 424 |
{"minus", Act_minus}, |
| 425 |
{"recent-files", Act_recent_files}, |
| 426 |
{"quit", Act_quit}, |
| 427 |
{"quit-confirm", Act_quit_confirm}, |
| 428 |
{"print", Act_print}, |
| 429 |
{"save", Act_save}, |
| 430 |
{"find", Act_find}, |
| 431 |
{"incremental-find", Act_incremental_find}, |
| 432 |
{"find-next", Act_find_next}, |
| 433 |
{"help", Act_help}, |
| 434 |
{"goto-page", Act_goto_page}, |
| 435 |
{"use-tex-pages", Act_use_tex_pages}, |
| 436 |
{"forward-page", Act_forward_page}, |
| 437 |
{"back-page", Act_back_page}, |
| 438 |
{"toggle-mark", Act_toggle_mark}, |
| 439 |
{"declare-page-number", Act_declare_page_number}, |
| 440 |
{"home", Act_home}, |
| 441 |
{"home-or-top", Act_home_or_top}, |
| 442 |
{"end-or-bottom", Act_end_or_bottom}, |
| 443 |
{"center", Act_center}, |
| 444 |
{"set-keep-flag", Act_set_keep_flag}, |
| 445 |
{"left", Act_left}, |
| 446 |
{"right", Act_right}, |
| 447 |
{"up", Act_up}, |
| 448 |
{"down", Act_down}, |
| 449 |
{"up-or-previous", Act_up_or_previous}, |
| 450 |
{"down-or-next", Act_down_or_next}, |
| 451 |
{"set-margins", Act_set_margins}, |
| 452 |
{"show-display-attributes", Act_show_display_attributes}, |
| 453 |
{"set-shrink-factor", Act_set_shrink_factor}, |
| 454 |
{"shrink-to-dpi", Act_shrink_to_dpi}, |
| 455 |
{"set-density", Act_set_density}, |
| 456 |
{"change-density", Act_change_density}, |
| 457 |
{"fullscreen", Act_fullscreen}, |
| 458 |
#ifdef GREY |
| 459 |
{"set-greyscaling", Act_set_greyscaling}, |
| 460 |
#endif |
| 461 |
#if COLOR |
| 462 |
{"set-color", Act_set_color}, |
| 463 |
#endif |
| 464 |
#ifdef PS |
| 465 |
{"set-ps", Act_set_ps}, |
| 466 |
#endif |
| 467 |
{"htex-back", Act_htex_back}, |
| 468 |
{"htex-forward", Act_htex_forward}, |
| 469 |
{"htex-anchorinfo", Act_htex_anchorinfo}, |
| 470 |
#ifdef PS_GS |
| 471 |
{"set-gs-alpha", Act_set_gs_alpha}, |
| 472 |
#endif |
| 473 |
{"set-expert-mode", Act_set_expert_mode}, |
| 474 |
{"reread-dvi-file", Act_reread_dvi_file}, |
| 475 |
{"select-dvi-file", Act_select_dvi_file}, |
| 476 |
{"discard-number", Act_discard_number}, |
| 477 |
{"drag", Act_drag}, |
| 478 |
{"wheel", Act_wheel}, |
| 479 |
{"hwheel", Act_hwheel}, |
| 480 |
{"press", Act_press}, |
| 481 |
{"motion", Act_motion}, |
| 482 |
{"release", Act_release}, |
| 483 |
{"toggle-grid-mode", Act_toggle_grid_mode}, |
| 484 |
{"source-special", Act_source_special}, |
| 485 |
{"show-source-specials", Act_show_source_specials}, |
| 486 |
{"source-what-special", Act_source_what_special}, |
| 487 |
{"unpause-or-next", Act_unpause_or_next}, |
| 488 |
{"user-exec", Act_user_exec}, |
| 489 |
#if 0 /* not implemented yet */ |
| 490 |
{"set-papersize", Act_set_papersize}, |
| 491 |
{"set-paper-landscape", Act_set_paper_landscape}, |
| 492 |
#endif |
| 493 |
{"load-url", Act_load_url}, |
| 494 |
{"scroll-list-up", Act_scroll_list_up}, |
| 495 |
{"scroll-list-down", Act_scroll_list_down}, |
| 496 |
{"pagehistory-clear", Act_pagehistory_clear}, |
| 497 |
{"pagehistory-back", Act_pagehistory_back}, |
| 498 |
{"pagehistory-forward", Act_pagehistory_forward}, |
| 499 |
{"pagehistory-delete-backward", Act_pagehistory_delete_backward}, |
| 500 |
{"pagehistory-delete-forward", Act_pagehistory_delete_forward}, |
| 501 |
#ifdef MOTIF |
| 502 |
{"prefs-dialog", Act_prefs_dialog}, |
| 503 |
#endif |
| 504 |
{"magnifier", Act_magnifier}, |
| 505 |
{"ruler", Act_ruler}, |
| 506 |
{"ruler-snap-origin", Act_ruler_snap_origin}, |
| 507 |
{"text-selection", Act_text_selection}, |
| 508 |
{"do-href", Act_href}, |
| 509 |
{"do-href-newwindow", Act_href_newwindow}, |
| 510 |
{"switch-magnifier-units", Act_switch_magnifier_units}, |
| 511 |
}; |
| 512 |
|
| 513 |
|
| 514 |
Boolean |
| 515 |
compile_action(const char *str, struct xdvi_action **app) |
| 516 |
{ |
| 517 |
const char *p, *p1, *p2, *end_cmd; |
| 518 |
XtActionsRec *actp; |
| 519 |
struct xdvi_action *ap; |
| 520 |
String *params; |
| 521 |
Cardinal num_params; |
| 522 |
|
| 523 |
for (;;) { |
| 524 |
|
| 525 |
while (*str == ' ' || *str == '\t') |
| 526 |
++str; |
| 527 |
|
| 528 |
if (*str == '\0' || *str == '\n') |
| 529 |
break; |
| 530 |
|
| 531 |
p = str; |
| 532 |
|
| 533 |
/* find end of command name */ |
| 534 |
while (isalnum((int)*p) || *p == '-' || *p == '_') |
| 535 |
++p; |
| 536 |
|
| 537 |
end_cmd = p; |
| 538 |
|
| 539 |
for (actp = m_actions; ; ++actp) { |
| 540 |
if (actp >= m_actions + XtNumber(m_actions)) { |
| 541 |
const char *tmp = strchr(str, '\0'); |
| 542 |
if (tmp == NULL) { |
| 543 |
tmp = p; |
| 544 |
} |
| 545 |
XDVI_WARNING((stderr, "Cannot compile action \"%.*s\".", |
| 546 |
(int) (tmp - str), str)); |
| 547 |
*app = NULL; |
| 548 |
return False; |
| 549 |
} |
| 550 |
if (memcmp(str, actp->string, p - str) == 0 |
| 551 |
&& actp->string[p - str] == '\0') |
| 552 |
break; |
| 553 |
} |
| 554 |
|
| 555 |
while (*p == ' ' || *p == '\t') |
| 556 |
++p; |
| 557 |
if (*p != '(') { |
| 558 |
while (*p != '\0' && *p != '\n') |
| 559 |
++p; |
| 560 |
XDVI_WARNING((stderr, "Syntax error in action %.*s.", |
| 561 |
(int) (p - str), str)); |
| 562 |
*app = NULL; |
| 563 |
return False; |
| 564 |
} |
| 565 |
|
| 566 |
do {++p;} |
| 567 |
while (*p == ' ' || *p == '\t'); |
| 568 |
|
| 569 |
num_params = 0; |
| 570 |
if (*p == ')') |
| 571 |
params = NULL; |
| 572 |
else { |
| 573 |
Cardinal max_params = 4; |
| 574 |
|
| 575 |
params = xmalloc(max_params * sizeof (String)); |
| 576 |
|
| 577 |
for (;;) { /* loop over params */ |
| 578 |
if (*p == '"') { |
| 579 |
++p; |
| 580 |
p1 = strchr(p, '"'); |
| 581 |
if (p1 == NULL) { |
| 582 |
p1 = strchr(p, '\n'); |
| 583 |
if (p1 == NULL) |
| 584 |
p1 = p + strlen(p); |
| 585 |
XDVI_WARNING((stderr, "Syntax error in action %.*s.", |
| 586 |
(int) (p1 - str), str)); |
| 587 |
while (num_params > 0) { |
| 588 |
--num_params; |
| 589 |
free(params[num_params]); |
| 590 |
} |
| 591 |
free(params); |
| 592 |
*app = NULL; |
| 593 |
return False; |
| 594 |
} |
| 595 |
params[num_params++] = xstrndup(p, p1 - p); |
| 596 |
|
| 597 |
do {++p1;} |
| 598 |
while (*p1 == ' ' || *p1 == '\t'); |
| 599 |
|
| 600 |
if (*p1 != ')' && *p1 != ',') { |
| 601 |
p2 = strchr(p1, '\n'); |
| 602 |
if (p2 == NULL) |
| 603 |
p2 = p1 + strlen(p1); |
| 604 |
XDVI_WARNING((stderr, "Syntax error in action %.*s.", |
| 605 |
(int) (p2 - str), str)); |
| 606 |
while (num_params > 0) { |
| 607 |
--num_params; |
| 608 |
free(params[num_params]); |
| 609 |
} |
| 610 |
free(params); |
| 611 |
*app = NULL; |
| 612 |
return False; |
| 613 |
} |
| 614 |
} |
| 615 |
else { /* param is not quoted */ |
| 616 |
for (p1 = p;; ++p1) { |
| 617 |
if (*p1 == '\0' || *p1 == '\n') { |
| 618 |
XDVI_WARNING((stderr, |
| 619 |
"Syntax error in action %.*s.", |
| 620 |
(int) (p1 - str), str)); |
| 621 |
while (num_params > 0) { |
| 622 |
--num_params; |
| 623 |
free(params[num_params]); |
| 624 |
} |
| 625 |
free(params); |
| 626 |
*app = NULL; |
| 627 |
return False; |
| 628 |
} |
| 629 |
if (*p1 == ')' || *p1 == ',') |
| 630 |
break; |
| 631 |
} |
| 632 |
p2 = p1; |
| 633 |
while (p2 > p && (p2[-1] == ' ' || p2[-1] == '\t')) |
| 634 |
--p2; |
| 635 |
params[num_params++] = xstrndup(p, p2 - p); |
| 636 |
} |
| 637 |
|
| 638 |
p = p1; |
| 639 |
if (*p == ')') |
| 640 |
break; |
| 641 |
|
| 642 |
do {++p;} |
| 643 |
while (*p == ' ' || *p == '\t'); |
| 644 |
|
| 645 |
if (num_params >= max_params) { |
| 646 |
max_params *= 2; |
| 647 |
params = xrealloc(params, max_params * sizeof (String)); |
| 648 |
} |
| 649 |
} |
| 650 |
} /* end if */ |
| 651 |
|
| 652 |
ap = xmalloc(sizeof *ap); |
| 653 |
ap->proc = actp->proc; |
| 654 |
ap->command = xstrndup(str, end_cmd - str); |
| 655 |
ap->params = params; |
| 656 |
ap->num_params = num_params; |
| 657 |
|
| 658 |
*app = ap; |
| 659 |
app = &ap->next; |
| 660 |
|
| 661 |
str = p + 1; |
| 662 |
} |
| 663 |
|
| 664 |
*app = NULL; |
| 665 |
return True; |
| 666 |
} |
| 667 |
|
| 668 |
/* |
| 669 |
* cached_compile_action does the same as compile_action, but retains |
| 670 |
* the compiled actions. It is used only in Act_mouse_modes(), which |
| 671 |
* otherwise would recompile the same actions over and over again. |
| 672 |
*/ |
| 673 |
|
| 674 |
struct avl_cached_action { |
| 675 |
AVL_COMMON; |
| 676 |
struct xdvi_action *ap; |
| 677 |
}; |
| 678 |
|
| 679 |
|
| 680 |
static void |
| 681 |
cached_compile_action(const char *str, struct xdvi_action **app) |
| 682 |
{ |
| 683 |
static struct avl_cached_action *avl_ca_head = NULL; |
| 684 |
struct avl_cached_action *avl_ca; |
| 685 |
|
| 686 |
avl_ca = (struct avl_cached_action *) |
| 687 |
avladd(str, strlen(str), (struct avl **) &avl_ca_head, |
| 688 |
sizeof (struct avl_cached_action)); |
| 689 |
|
| 690 |
if (avl_ca->key == str) { /* if new record */ |
| 691 |
avl_ca->key = xstrdup(str); /* copy string to new storage */ |
| 692 |
compile_action(str, &avl_ca->ap); |
| 693 |
} |
| 694 |
*app = avl_ca->ap; |
| 695 |
} |
| 696 |
|
| 697 |
|
| 698 |
/* |
| 699 |
* Access to m_actions |
| 700 |
*/ |
| 701 |
int get_num_actions(void) |
| 702 |
{ |
| 703 |
return XtNumber(m_actions); |
| 704 |
} |
| 705 |
|
| 706 |
XtActionsRec *get_actions(void) |
| 707 |
{ |
| 708 |
return m_actions; |
| 709 |
} |
| 710 |
|
| 711 |
/* |
| 712 |
* Data for buffered events. |
| 713 |
*/ |
| 714 |
|
| 715 |
#ifndef FLAKY_SIGPOLL |
| 716 |
static VOLATILE int event_freq = 70; |
| 717 |
#else |
| 718 |
#define event_freq 70 |
| 719 |
#endif |
| 720 |
|
| 721 |
static void can_exposures(struct WindowRec *windowrec); |
| 722 |
|
| 723 |
|
| 724 |
/* |
| 725 |
* Set the flag so that termination occurs, via the above routine. |
| 726 |
* This should be used in place of xdvi_exit() when there may be a |
| 727 |
* non-killable process running (e.g., anytime within read_events()). |
| 728 |
*/ |
| 729 |
|
| 730 |
static void |
| 731 |
xdvi_normal_exit(void) |
| 732 |
{ |
| 733 |
sig_flags |= SF_TERM; |
| 734 |
} |
| 735 |
|
| 736 |
static void |
| 737 |
xdvi_normal_exit_cb(XtPointer arg) |
| 738 |
{ |
| 739 |
UNUSED(arg); |
| 740 |
sig_flags |= SF_TERM; |
| 741 |
} |
| 742 |
|
| 743 |
void |
| 744 |
xdvi_exit_callback(Widget w, XtPointer client_data, XtPointer call_data) |
| 745 |
{ |
| 746 |
UNUSED(w); |
| 747 |
UNUSED(client_data); |
| 748 |
UNUSED(call_data); |
| 749 |
|
| 750 |
sig_flags |= SF_TERM; |
| 751 |
} |
| 752 |
|
| 753 |
/* |
| 754 |
* Event-handling routines. |
| 755 |
*/ |
| 756 |
|
| 757 |
|
| 758 |
void |
| 759 |
expose(struct WindowRec *windowrec, |
| 760 |
int x, int y, |
| 761 |
unsigned int w, unsigned int h) |
| 762 |
{ |
| 763 |
if (windowrec->min_x > x) |
| 764 |
windowrec->min_x = x; |
| 765 |
if (windowrec->max_x < (int)(x + w)) |
| 766 |
windowrec->max_x = x + w; |
| 767 |
if (windowrec->min_y > y) |
| 768 |
windowrec->min_y = y; |
| 769 |
if (windowrec->max_y < (int)(y + h)) |
| 770 |
windowrec->max_y = y + h; |
| 771 |
|
| 772 |
globals.ev.flags |= EV_EXPOSE; |
| 773 |
} |
| 774 |
|
| 775 |
void |
| 776 |
clearexpose(struct WindowRec *windowrec, |
| 777 |
int x, int y, |
| 778 |
unsigned w, unsigned h) |
| 779 |
{ |
| 780 |
XClearArea(DISP, windowrec->win, x, y, w, h, False); |
| 781 |
expose(windowrec, x, y, w, h); |
| 782 |
} |
| 783 |
|
| 784 |
/* |
| 785 |
* Routines for X11 toolkit. |
| 786 |
*/ |
| 787 |
|
| 788 |
static Position m_window_x, m_window_y; |
| 789 |
static Arg arg_xy[] = { |
| 790 |
{XtNx, (XtArgVal) &m_window_x}, |
| 791 |
{XtNy, (XtArgVal) &m_window_y}, |
| 792 |
}; |
| 793 |
|
| 794 |
#define get_xy() XtGetValues(globals.widgets.draw_widget, arg_xy, XtNumber(arg_xy)) |
| 795 |
|
| 796 |
|
| 797 |
static void |
| 798 |
warn_num_params(const char *act_name, String *params, int num_params, int max_params) |
| 799 |
{ |
| 800 |
if (num_params > max_params) { |
| 801 |
XDVI_WARNING((stderr, "Too many parameters (%d) for action \"%s\", ignoring all after \"%s\"", |
| 802 |
num_params, act_name, params[max_params - 1])); |
| 803 |
} |
| 804 |
} |
| 805 |
|
| 806 |
|
| 807 |
void |
| 808 |
handle_command(Widget widget, XtPointer client_data, XtPointer call_data) |
| 809 |
{ |
| 810 |
struct xdvi_action *actp; |
| 811 |
|
| 812 |
UNUSED(call_data); |
| 813 |
|
| 814 |
/* call all actions registered for this event */ |
| 815 |
for (actp = (struct xdvi_action *)client_data; actp != NULL; actp = actp->next) { |
| 816 |
if (globals.debug & DBG_EVENT) |
| 817 |
fprintf(stderr, "calling action with param: %s\n", |
| 818 |
actp->num_params ? actp->params[0] : "(null)"); |
| 819 |
(actp->proc)(widget, NULL, actp->params, &actp->num_params); |
| 820 |
} |
| 821 |
} |
| 822 |
|
| 823 |
#ifdef MOTIF |
| 824 |
int |
| 825 |
set_bar_value(Widget bar, int value, int max) |
| 826 |
{ |
| 827 |
XmScrollBarCallbackStruct call_data; |
| 828 |
|
| 829 |
#ifdef TEST_SCROLLING |
| 830 |
fprintf(stderr, "set_bar_value: val %d, max %d\n", value, max); |
| 831 |
#endif |
| 832 |
if (value > max) |
| 833 |
value = max; |
| 834 |
if (value < 0) |
| 835 |
value = 0; |
| 836 |
call_data.value = value; |
| 837 |
XtVaSetValues(bar, XmNvalue, value, NULL); |
| 838 |
XtCallCallbacks(bar, XmNvalueChangedCallback, &call_data); |
| 839 |
return value; |
| 840 |
} |
| 841 |
#endif |
| 842 |
|
| 843 |
void |
| 844 |
home(wide_bool scrl) |
| 845 |
{ |
| 846 |
if (!scrl) |
| 847 |
XUnmapWindow(DISP, mane.win); |
| 848 |
# ifdef MOTIF |
| 849 |
{ |
| 850 |
int value; |
| 851 |
|
| 852 |
if (!resource.keep_flag) { |
| 853 |
value = (globals.page.w - mane.width) / 2; |
| 854 |
if (value > resource.sidemargin_int / mane.shrinkfactor) |
| 855 |
value = resource.sidemargin_int / mane.shrinkfactor; |
| 856 |
(void)set_bar_value(globals.widgets.x_bar, value, (int)(globals.page.w - mane.width)); |
| 857 |
} |
| 858 |
|
| 859 |
value = (globals.page.h - mane.height) / 2; |
| 860 |
if (value > resource.topmargin_int / mane.shrinkfactor) |
| 861 |
value = resource.topmargin_int / mane.shrinkfactor; |
| 862 |
(void)set_bar_value(globals.widgets.y_bar, value, (int)(globals.page.h - mane.height)); |
| 863 |
} |
| 864 |
# else |
| 865 |
get_xy(); |
| 866 |
if (!resource.keep_flag && globals.widgets.x_bar != NULL) { |
| 867 |
int coord = (globals.page.w - mane.width) / 2; |
| 868 |
|
| 869 |
if (coord > resource.sidemargin_int / mane.shrinkfactor) |
| 870 |
coord = resource.sidemargin_int / mane.shrinkfactor; |
| 871 |
XtCallCallbacks(globals.widgets.x_bar, XtNscrollProc, cast_int_to_XtPointer(m_window_x + coord)); |
| 872 |
} |
| 873 |
if (globals.widgets.y_bar != NULL) { |
| 874 |
int coord = (globals.page.h - mane.height) / 2; |
| 875 |
|
| 876 |
if (coord > resource.topmargin_int / mane.shrinkfactor) |
| 877 |
coord = resource.topmargin_int / mane.shrinkfactor; |
| 878 |
XtCallCallbacks(globals.widgets.y_bar, XtNscrollProc, cast_int_to_XtPointer(m_window_y + coord)); |
| 879 |
} |
| 880 |
# endif /* MOTIF */ |
| 881 |
if (!scrl) { |
| 882 |
XMapWindow(DISP, mane.win); |
| 883 |
/* Wait for the server to catch up---this eliminates flicker. */ |
| 884 |
XSync(DISP, False); |
| 885 |
} |
| 886 |
#ifdef USE_PANNER |
| 887 |
handle_x_scroll(NULL, NULL, NULL, NULL); |
| 888 |
handle_y_scroll(NULL, NULL, NULL, NULL); |
| 889 |
#endif |
| 890 |
} |
| 891 |
|
| 892 |
/* |
| 893 |
* Same as home(), except move to the bottom of the page. |
| 894 |
*/ |
| 895 |
|
| 896 |
static void |
| 897 |
home_bottom(wide_bool scrl) |
| 898 |
{ |
| 899 |
UNUSED(scrl); |
| 900 |
XUnmapWindow(DISP, mane.win); |
| 901 |
#ifdef MOTIF |
| 902 |
{ |
| 903 |
int value; |
| 904 |
|
| 905 |
if (!resource.keep_flag) { |
| 906 |
value = (globals.page.w - mane.width) / 2; |
| 907 |
if (value > resource.sidemargin_int / mane.shrinkfactor) |
| 908 |
value = resource.sidemargin_int / mane.shrinkfactor; |
| 909 |
(void)set_bar_value(globals.widgets.x_bar, value, (int)(globals.page.w - mane.width)); |
| 910 |
} |
| 911 |
|
| 912 |
(void)set_bar_value(globals.widgets.y_bar, (int)(globals.page.h - mane.height), (int)(globals.page.h - mane.height)); |
| 913 |
} |
| 914 |
#else /* MOTIF */ |
| 915 |
get_xy(); |
| 916 |
if (!resource.keep_flag && globals.widgets.x_bar != NULL) { |
| 917 |
int coord = (globals.page.w - mane.width) / 2; |
| 918 |
|
| 919 |
if (coord > resource.sidemargin_int / mane.shrinkfactor) |
| 920 |
coord = resource.sidemargin_int / mane.shrinkfactor; |
| 921 |
XtCallCallbacks(globals.widgets.x_bar, XtNscrollProc, cast_int_to_XtPointer(m_window_x + coord)); |
| 922 |
} |
| 923 |
if (globals.widgets.y_bar != NULL) |
| 924 |
XtCallCallbacks(globals.widgets.y_bar, XtNscrollProc, cast_int_to_XtPointer(m_window_y + (globals.page.h - mane.height))); |
| 925 |
#endif /* MOTIF */ |
| 926 |
XMapWindow(DISP, mane.win); |
| 927 |
/* Wait for the server to catch up---this eliminates flicker. */ |
| 928 |
XSync(DISP, False); |
| 929 |
|
| 930 |
#ifdef USE_PANNER |
| 931 |
handle_x_scroll(NULL, NULL, NULL, NULL); |
| 932 |
handle_y_scroll(NULL, NULL, NULL, NULL); |
| 933 |
#endif |
| 934 |
} |
| 935 |
|
| 936 |
|
| 937 |
#ifndef MOTIF |
| 938 |
static void |
| 939 |
handle_destroy_bar(Widget w, XtPointer client_data, XtPointer call_data) |
| 940 |
{ |
| 941 |
UNUSED(w); |
| 942 |
UNUSED(call_data); |
| 943 |
*(Widget *) client_data = NULL; |
| 944 |
} |
| 945 |
#endif |
| 946 |
|
| 947 |
static Boolean resized = False; |
| 948 |
|
| 949 |
static void |
| 950 |
get_geom(void) |
| 951 |
{ |
| 952 |
static Dimension new_clip_w, new_clip_h; |
| 953 |
|
| 954 |
static Arg arg_wh_clip[] = { |
| 955 |
{XtNwidth, (XtArgVal) &new_clip_w}, |
| 956 |
{XtNheight, (XtArgVal) &new_clip_h}, |
| 957 |
}; |
| 958 |
|
| 959 |
static Dimension window_w, window_h; |
| 960 |
|
| 961 |
static Arg arg_wh[] = { |
| 962 |
{XtNwidth, (XtArgVal) &window_w}, |
| 963 |
{XtNheight, (XtArgVal) &window_h}, |
| 964 |
}; |
| 965 |
|
| 966 |
|
| 967 |
int old_clip_w; |
| 968 |
|
| 969 |
#ifdef MOTIF |
| 970 |
/* event handlers for Motif scrollbars have already been added |
| 971 |
in create_initialize_widgets(), xdvi.c */ |
| 972 |
XtGetValues(globals.widgets.main_window, arg_wh, XtNumber(arg_wh)); |
| 973 |
#else |
| 974 |
XtGetValues(globals.widgets.vport_widget, arg_wh, XtNumber(arg_wh)); |
| 975 |
/* Note: widgets may be destroyed but not forgotten */ |
| 976 |
if (globals.widgets.x_bar == NULL) { |
| 977 |
globals.widgets.x_bar = XtNameToWidget(globals.widgets.vport_widget, "horizontal"); |
| 978 |
if (globals.widgets.x_bar != NULL) { |
| 979 |
XtAddCallback(globals.widgets.x_bar, XtNdestroyCallback, handle_destroy_bar, |
| 980 |
(XtPointer)&globals.widgets.x_bar); |
| 981 |
#ifdef USE_PANNER |
| 982 |
XtAddEventHandler(globals.widgets.x_bar, ButtonMotionMask | ButtonPressMask | ButtonReleaseMask, |
| 983 |
False, handle_x_scroll, NULL); |
| 984 |
#endif |
| 985 |
} |
| 986 |
} |
| 987 |
if (globals.widgets.y_bar == NULL) { |
| 988 |
globals.widgets.y_bar = XtNameToWidget(globals.widgets.vport_widget, "vertical"); |
| 989 |
if (globals.widgets.y_bar != NULL) { |
| 990 |
XtAddCallback(globals.widgets.y_bar, XtNdestroyCallback, handle_destroy_bar, |
| 991 |
(XtPointer)&globals.widgets.y_bar); |
| 992 |
#ifdef USE_PANNER |
| 993 |
XtAddEventHandler(globals.widgets.y_bar, ButtonMotionMask | ButtonPressMask | ButtonReleaseMask, |
| 994 |
False, handle_y_scroll, NULL); |
| 995 |
#endif |
| 996 |
} |
| 997 |
} |
| 998 |
#endif |
| 999 |
XtGetValues(globals.widgets.clip_widget, arg_wh_clip, XtNumber(arg_wh_clip)); |
| 1000 |
|
| 1001 |
old_clip_w = mane.width; |
| 1002 |
|
| 1003 |
/* we need to do this because |
| 1004 |
sizeof(Dimension) != sizeof(int) |
| 1005 |
*/ |
| 1006 |
mane.width = new_clip_w; |
| 1007 |
mane.height = new_clip_h; |
| 1008 |
if (old_clip_w == 0) { |
| 1009 |
globals.ev.flags |= EV_NEWPAGE; |
| 1010 |
} |
| 1011 |
|
| 1012 |
if (resource.keep_flag) { |
| 1013 |
#ifndef MOTIF |
| 1014 |
Dimension d; |
| 1015 |
int curr_scroll; |
| 1016 |
if ((globals.widgets.x_bar != NULL && m_x_scroll != 0) || (globals.widgets.y_bar != NULL && m_y_scroll != 0)) { |
| 1017 |
get_xy(); |
| 1018 |
} |
| 1019 |
#endif |
| 1020 |
if (globals.widgets.x_bar != NULL && m_x_scroll != 0) { |
| 1021 |
#ifdef MOTIF |
| 1022 |
if (m_x_scroll > 0) |
| 1023 |
(void)set_bar_value(globals.widgets.x_bar, m_x_scroll, (int)(globals.page.w - mane.width)); |
| 1024 |
#else |
| 1025 |
XtVaGetValues(globals.widgets.clip_widget, XtNy, &d, NULL); |
| 1026 |
curr_scroll = d - m_window_x; |
| 1027 |
if (m_x_scroll > curr_scroll) { |
| 1028 |
TRACE_GUI((stderr, "======== diff: %d", m_x_scroll - curr_scroll)); |
| 1029 |
XtCallCallbacks(globals.widgets.x_bar, XtNscrollProc, cast_int_to_XtPointer(m_x_scroll - curr_scroll)); |
| 1030 |
} |
| 1031 |
#endif |
| 1032 |
} |
| 1033 |
if (globals.widgets.y_bar != NULL && m_y_scroll != 0) { |
| 1034 |
#ifdef MOTIF |
| 1035 |
if (m_y_scroll > 0) |
| 1036 |
(void)set_bar_value(globals.widgets.y_bar, m_y_scroll, (int)(globals.page.h - mane.height)); |
| 1037 |
#else |
| 1038 |
XtVaGetValues(globals.widgets.clip_widget, XtNy, &d, NULL); |
| 1039 |
curr_scroll = d - m_window_y; |
| 1040 |
if (m_y_scroll > curr_scroll) { |
| 1041 |
TRACE_GUI((stderr, "======== diff: %d", m_y_scroll - curr_scroll)); |
| 1042 |
XtCallCallbacks(globals.widgets.y_bar, XtNscrollProc, cast_int_to_XtPointer(m_y_scroll - curr_scroll)); |
| 1043 |
} |
| 1044 |
#endif |
| 1045 |
} |
| 1046 |
} |
| 1047 |
/* home(False); */ |
| 1048 |
resized = False; |
| 1049 |
} |
| 1050 |
|
| 1051 |
/* |
| 1052 |
* Callback routines |
| 1053 |
*/ |
| 1054 |
|
| 1055 |
void |
| 1056 |
handle_resize(Widget widget, XtPointer junk, XEvent *event, Boolean *cont) |
| 1057 |
{ |
| 1058 |
UNUSED(widget); |
| 1059 |
UNUSED(junk); |
| 1060 |
UNUSED(event); |
| 1061 |
UNUSED(cont); |
| 1062 |
|
| 1063 |
resized = True; |
| 1064 |
#ifndef MOTIF |
| 1065 |
handle_statusline_resize(); |
| 1066 |
handle_pagelist_resize(); |
| 1067 |
#endif |
| 1068 |
} |
| 1069 |
|
| 1070 |
void |
| 1071 |
reconfig(void) |
| 1072 |
{ |
| 1073 |
/* Dimension x, y; */ |
| 1074 |
|
| 1075 |
if (globals.dvi_file.bak_fp == NULL) |
| 1076 |
return; |
| 1077 |
|
| 1078 |
#ifndef MOTIF |
| 1079 |
XtVaSetValues(globals.widgets.vport_widget, XtNresizable, (XtArgVal)False, NULL); |
| 1080 |
#endif |
| 1081 |
TRACE_GUI((stderr, "globals.widgets.draw_widget: w %d, h %d", globals.page.w, globals.page.h)); |
| 1082 |
XtVaSetValues(globals.widgets.draw_widget, XtNwidth, (XtArgVal)globals.page.w, XtNheight, (XtArgVal)globals.page.h, NULL); |
| 1083 |
|
| 1084 |
#ifdef TEST_SCROLLING |
| 1085 |
/* XtVaSetValues(globals.widgets.draw_background, XtNwidth, (XtArgVal)globals.page.w, XtNheight, (XtArgVal)globals.page.h, NULL); */ |
| 1086 |
#endif |
| 1087 |
|
| 1088 |
#ifndef MOTIF |
| 1089 |
handle_statusline_resize(); /* without this, statusline will disappear */ |
| 1090 |
/* following not needed? */ |
| 1091 |
/* handle_pagelist_resize(); */ |
| 1092 |
#endif |
| 1093 |
|
| 1094 |
get_geom(); |
| 1095 |
|
| 1096 |
/* set_windowsize(&x, &y */ |
| 1097 |
/* #ifndef MOTIF */ |
| 1098 |
/* , get_panel_width() */ |
| 1099 |
/* #endif */ |
| 1100 |
/* ); */ |
| 1101 |
/* XResizeWindow(DISP, XtWindow(globals.widgets.top_level), x, y); */ |
| 1102 |
/* reconfigure_window(False, x, y, True); */ |
| 1103 |
/* reconfig_window(); */ |
| 1104 |
} |
| 1105 |
|
| 1106 |
|
| 1107 |
int |
| 1108 |
check_goto_page(int pageno, Boolean insert_into_pagehist) |
| 1109 |
{ |
| 1110 |
int retval; |
| 1111 |
if (pageno < 0) { |
| 1112 |
xdvi_bell(); |
| 1113 |
/* statusline_info(STATUS_SHORT, "Can't go to page %d, going to first page instead", pageno + 1); */ |
| 1114 |
retval = 0; |
| 1115 |
} |
| 1116 |
else if (pageno >= total_pages) { |
| 1117 |
xdvi_bell(); |
| 1118 |
/* statusline_info(STATUS_SHORT, */ |
| 1119 |
/* "Can't go to page %d, going to last page (%d) instead", */ |
| 1120 |
/* pageno + 1, total_pages); */ |
| 1121 |
retval = total_pages - 1; |
| 1122 |
} |
| 1123 |
else |
| 1124 |
retval = pageno; |
| 1125 |
|
| 1126 |
if (insert_into_pagehist) { |
| 1127 |
page_history_insert(retval); |
| 1128 |
} |
| 1129 |
return retval; |
| 1130 |
} |
| 1131 |
|
| 1132 |
|
| 1133 |
static int |
| 1134 |
check_goto_tex_page(int pageno) |
| 1135 |
{ |
| 1136 |
/* |
| 1137 |
Translate from TeX page number to `real' page number if |
| 1138 |
needed. Note that pageno is a C-style 0-based number, hence we |
| 1139 |
add 1 for the argument of pageinfo_get_index_of_number(). |
| 1140 |
*/ |
| 1141 |
int retval; |
| 1142 |
if (resource.use_tex_pages) { |
| 1143 |
int res = pageinfo_get_index_of_number(pageno + 1); |
| 1144 |
if (res >= 0) |
| 1145 |
retval = res; |
| 1146 |
else { |
| 1147 |
xdvi_bell(); |
| 1148 |
if (pageno < 1) { |
| 1149 |
/* statusline_info(STATUS_SHORT, "Can't go to page %d, going to first page instead", pageno + 1); */ |
| 1150 |
retval = 0; |
| 1151 |
} |
| 1152 |
else { |
| 1153 |
/* there is no quick way to determine the last page number in the TeX page index */ |
| 1154 |
/* statusline_info(STATUS_SHORT, */ |
| 1155 |
/* "Can't go to page %d, going to last page instead", */ |
| 1156 |
/* pageno + 1); */ |
| 1157 |
retval = total_pages - 1; |
| 1158 |
} |
| 1159 |
} |
| 1160 |
page_history_insert(retval); |
| 1161 |
} |
| 1162 |
else { |
| 1163 |
retval = check_goto_page(pageno, True); |
| 1164 |
} |
| 1165 |
return retval; |
| 1166 |
} |
| 1167 |
|
| 1168 |
/* ||| |
| 1169 |
* Currently the event handler does not coordinate XCopyArea requests |
| 1170 |
* with GraphicsExpose events. This can lead to problems if the window |
| 1171 |
* is partially obscured and one, for example, drags a scrollbar. |
| 1172 |
*/ |
| 1173 |
|
| 1174 |
/* |
| 1175 |
* Actions for the translation mechanism. |
| 1176 |
*/ |
| 1177 |
|
| 1178 |
/* if there are global prefixes, return them in res and reset them to defaults */ |
| 1179 |
static Boolean |
| 1180 |
get_prefix_arg(int *res) |
| 1181 |
{ |
| 1182 |
Boolean ret; |
| 1183 |
|
| 1184 |
*res = m_sign * m_number; |
| 1185 |
ret = m_have_arg; |
| 1186 |
/* reset global flags */ |
| 1187 |
m_have_arg = False; |
| 1188 |
m_number = 0; |
| 1189 |
m_sign = 1; |
| 1190 |
return ret; |
| 1191 |
} |
| 1192 |
|
| 1193 |
Boolean |
| 1194 |
get_int_arg(String *param, Cardinal *num_params, int *res) |
| 1195 |
{ |
| 1196 |
if (*num_params > 0) { |
| 1197 |
*res = atoi(*param); |
| 1198 |
return True; |
| 1199 |
} |
| 1200 |
else { |
| 1201 |
if (get_prefix_arg(res)) { /* prefix argument? */ |
| 1202 |
return True; |
| 1203 |
} |
| 1204 |
} |
| 1205 |
return False; |
| 1206 |
} |
| 1207 |
|
| 1208 |
|
| 1209 |
Boolean |
| 1210 |
toggle_arg(int arg, String *param, Cardinal *num_params) |
| 1211 |
{ |
| 1212 |
if (*num_params > 0) { |
| 1213 |
if (**param != 't' && (atoi(*param) != 0) == arg) |
| 1214 |
return False; |
| 1215 |
} |
| 1216 |
else { |
| 1217 |
if (m_have_arg) { |
| 1218 |
int tmparg = m_number; |
| 1219 |
|
| 1220 |
m_have_arg = False; |
| 1221 |
m_number = 0; |
| 1222 |
m_sign = 1; |
| 1223 |
|
| 1224 |
if ((tmparg != 0) == arg) |
| 1225 |
return False; |
| 1226 |
} |
| 1227 |
} |
| 1228 |
return True; |
| 1229 |
} |
| 1230 |
|
| 1231 |
Boolean |
| 1232 |
check_resource_expert(void *val, const char *param) |
| 1233 |
{ |
| 1234 |
int j = strtol(param, (char **)NULL, 10); |
| 1235 |
/* check if the j-1th bit is set: */ |
| 1236 |
return (*(int *)val >> (j - 1)) & 1; |
| 1237 |
} |
| 1238 |
|
| 1239 |
Boolean |
| 1240 |
check_papersize(void *val, const char *param) |
| 1241 |
{ |
| 1242 |
UNUSED(val); |
| 1243 |
UNUSED(param); |
| 1244 |
return False; /* TODO */ |
| 1245 |
} |
| 1246 |
|
| 1247 |
Boolean |
| 1248 |
check_paper_landscape(void *val, const char *param) |
| 1249 |
{ |
| 1250 |
UNUSED(val); |
| 1251 |
UNUSED(param); |
| 1252 |
return False; /* TODO */ |
| 1253 |
} |
| 1254 |
|
| 1255 |
/* comparison functions for the menu setting code */ |
| 1256 |
Boolean |
| 1257 |
check_toggle(void *val, const char *param) |
| 1258 |
{ |
| 1259 |
Boolean *on = val; |
| 1260 |
if (strcmp(param, "toggle") == 0) { |
| 1261 |
return *on; |
| 1262 |
} |
| 1263 |
else { |
| 1264 |
fprintf(stderr, "TODO: check_toggle: arg |%s|, curr: %d\n", param, *(int *)val); |
| 1265 |
return *on; |
| 1266 |
} |
| 1267 |
} |
| 1268 |
|
| 1269 |
Boolean |
| 1270 |
check_int(void *val, const char *param) |
| 1271 |
{ |
| 1272 |
int i = strtol(param, (char **)NULL, 10); |
| 1273 |
return i == *(int *)val; |
| 1274 |
} |
| 1275 |
|
| 1276 |
void |
| 1277 |
Act_ruler(Widget w, XEvent *event, |
| 1278 |
String *params, Cardinal *num_params) |
| 1279 |
{ |
| 1280 |
UNUSED(w); |
| 1281 |
UNUSED(params); |
| 1282 |
UNUSED(num_params); |
| 1283 |
|
| 1284 |
MYTRACE((stderr, "ruler!\n")); |
| 1285 |
|
| 1286 |
if (dvi_file_changed()) { |
| 1287 |
globals.ev.flags |= EV_RELOAD; |
| 1288 |
return; |
| 1289 |
} |
| 1290 |
|
| 1291 |
#ifdef MOTIF |
| 1292 |
/* see xm_menu.c for an explanation of this */ |
| 1293 |
if (event && pulldown_menu_active(event->xany.serial)) { |
| 1294 |
return; |
| 1295 |
} |
| 1296 |
#endif |
| 1297 |
|
| 1298 |
if (bg_current == NULL) { |
| 1299 |
/* |
| 1300 |
HACK ALERT: we can arrive here after loading a new file via the file selector |
| 1301 |
for which not all fonts have been generated. In that case, dereferencing |
| 1302 |
bg_current would bomb. Try to recover by simply returning here. |
| 1303 |
*/ |
| 1304 |
return; |
| 1305 |
} |
| 1306 |
|
| 1307 |
show_ruler(event); |
| 1308 |
globals.curr_mode = RULER_MODE_ACTIVE; |
| 1309 |
globals.ev.flags |= EV_CURSOR; |
| 1310 |
XFlush(DISP); |
| 1311 |
show_distance_from_ruler(event, False); |
| 1312 |
} |
| 1313 |
|
| 1314 |
void |
| 1315 |
Act_text_selection(Widget w, XEvent *event, |
| 1316 |
String *params, Cardinal *num_params) |
| 1317 |
{ |
| 1318 |
UNUSED(w); |
| 1319 |
UNUSED(params); |
| 1320 |
UNUSED(num_params); |
| 1321 |
|
| 1322 |
MYTRACE((stderr, "text selection!\n")); |
| 1323 |
|
| 1324 |
if (dvi_file_changed()) { |
| 1325 |
globals.ev.flags |= EV_RELOAD; |
| 1326 |
return; |
| 1327 |
} |
| 1328 |
|
| 1329 |
#ifdef MOTIF |
| 1330 |
/* see xm_menu.c for an explanation of this */ |
| 1331 |
if (pulldown_menu_active(event->xany.serial)) { |
| 1332 |
return; |
| 1333 |
} |
| 1334 |
#endif |
| 1335 |
|
| 1336 |
if (bg_current == NULL) { |
| 1337 |
/* |
| 1338 |
HACK ALERT: we can arrive here after loading a new file via the file selector |
| 1339 |
for which not all fonts have been generated. In that case, dereferencing |
| 1340 |
bg_current would bomb. Try to recover by simply returning here. |
| 1341 |
*/ |
| 1342 |
return; |
| 1343 |
} |
| 1344 |
|
| 1345 |
globals.curr_mode = TEXT_MODE_ACTIVE; |
| 1346 |
globals.ev.flags |= EV_CURSOR; |
| 1347 |
XFlush(DISP); |
| 1348 |
text_selection_start(event); |
| 1349 |
text_motion(event); |
| 1350 |
} |
| 1351 |
|
| 1352 |
/**************************************************************************** |
| 1353 |
* Actions specific to the handling of the magnifier |
| 1354 |
*/ |
| 1355 |
|
| 1356 |
void |
| 1357 |
Act_magnifier(Widget w, XEvent *event, |
| 1358 |
String *params, Cardinal *num_params) |
| 1359 |
{ |
| 1360 |
UNUSED(w); |
| 1361 |
|
| 1362 |
MYTRACE((stderr, "magnifier!\n")); |
| 1363 |
|
| 1364 |
if (dvi_file_changed()) { |
| 1365 |
globals.ev.flags |= EV_RELOAD; |
| 1366 |
return; |
| 1367 |
} |
| 1368 |
|
| 1369 |
#ifdef MOTIF |
| 1370 |
/* see xm_menu.c for an explanation of this */ |
| 1371 |
if (pulldown_menu_active(event->xany.serial)) { |
| 1372 |
return; |
| 1373 |
} |
| 1374 |
#endif |
| 1375 |
|
| 1376 |
if (bg_current == NULL) { |
| 1377 |
/* |
| 1378 |
HACK ALERT: we can arrive here after loading a new file via the file selector |
| 1379 |
for which not all fonts have been generated. In that case, dereferencing |
| 1380 |
bg_current would bomb. Try to recover by simply returning here. |
| 1381 |
*/ |
| 1382 |
return; |
| 1383 |
} |
| 1384 |
|
| 1385 |
if (event->type != ButtonPress || mouse_release != null_mouse |
| 1386 |
|| MAGNIFIER_ACTIVE || mane.shrinkfactor == 1 || *num_params != 1) { |
| 1387 |
XdviBell(DISP, event->xany.window, 0); |
| 1388 |
if (mane.shrinkfactor == 1) { |
| 1389 |
statusline_info(STATUS_SHORT, |
| 1390 |
"No magnification available at shrink factor 1"); |
| 1391 |
} |
| 1392 |
return; |
| 1393 |
} |
| 1394 |
|
| 1395 |
magnifier_move(*params, event); |
| 1396 |
} |
| 1397 |
|
| 1398 |
void |
| 1399 |
Act_switch_magnifier_units(Widget w, XEvent *event, |
| 1400 |
String *params, Cardinal *num_params) |
| 1401 |
{ |
| 1402 |
size_t k = 0; |
| 1403 |
static char *TeX_units[] = { |
| 1404 |
"mm", "pt", "in", "sp", "bp", "cc", "dd", "pc", "px", |
| 1405 |
}; |
| 1406 |
|
| 1407 |
UNUSED(w); |
| 1408 |
UNUSED(event); |
| 1409 |
UNUSED(params); |
| 1410 |
UNUSED(num_params); |
| 1411 |
|
| 1412 |
for (k = 0; k < XtNumber(TeX_units); ++k) |
| 1413 |
if (strcmp(resource.tick_units, TeX_units[k]) == 0) |
| 1414 |
break; |
| 1415 |
k++; |
| 1416 |
if (k >= XtNumber(TeX_units)) |
| 1417 |
k = 0; |
| 1418 |
resource.tick_units = TeX_units[k]; |
| 1419 |
if (globals.curr_mode == RULER_MODE_ACTIVE) { |
| 1420 |
show_distance_from_ruler(event, False); |
| 1421 |
} |
| 1422 |
else { |
| 1423 |
statusline_info(STATUS_SHORT, "Ruler units: %s\n", resource.tick_units); |
| 1424 |
} |
| 1425 |
} |
| 1426 |
|
| 1427 |
void |
| 1428 |
Act_href(Widget w, XEvent *event, |
| 1429 |
String *params, Cardinal *num_params) |
| 1430 |
{ |
| 1431 |
int x, y; |
| 1432 |
Window dummy; |
| 1433 |
|
| 1434 |
UNUSED(w); |
| 1435 |
UNUSED(num_params); |
| 1436 |
|
| 1437 |
(void)XTranslateCoordinates(DISP, event->xkey.window, mane.win, |
| 1438 |
event->xkey.x, event->xkey.y, &x, &y, &dummy); |
| 1439 |
|
| 1440 |
if (params) { |
| 1441 |
if (htex_handleref(x, y, False)) |
| 1442 |
*params = Act_true_retval; |
| 1443 |
else |
| 1444 |
*params = Act_false_retval; |
| 1445 |
} |
| 1446 |
} |
| 1447 |
|
| 1448 |
void |
| 1449 |
Act_href_newwindow(Widget w, XEvent *event, |
| 1450 |
String *params, Cardinal *num_params) |
| 1451 |
{ |
| 1452 |
int x, y; |
| 1453 |
Window dummy; |
| 1454 |
|
| 1455 |
UNUSED(w); |
| 1456 |
UNUSED(num_params); |
| 1457 |
|
| 1458 |
(void)XTranslateCoordinates(DISP, event->xkey.window, mane.win, |
| 1459 |
event->xkey.x, event->xkey.y, &x, &y, &dummy); |
| 1460 |
|
| 1461 |
if (params) { |
| 1462 |
if (htex_handleref(x, y, True)) |
| 1463 |
*params = Act_true_retval; |
| 1464 |
else |
| 1465 |
*params = Act_false_retval; |
| 1466 |
} |
| 1467 |
} |
| 1468 |
|
| 1469 |
static void |
| 1470 |
Act_digit(Widget w, XEvent *event, |
| 1471 |
String *params, Cardinal *num_params) |
| 1472 |
{ |
| 1473 |
int digit; |
| 1474 |
/* for overflow checks */ |
| 1475 |
static const int MAXINT_QUOT = INT_MAX / 10; |
| 1476 |
static const int MAXINT_MOD = INT_MAX % 10; |
| 1477 |
|
| 1478 |
|
| 1479 |
UNUSED(w); |
| 1480 |
UNUSED(event); |
| 1481 |
|
| 1482 |
if (*num_params != 1 || (digit = **params - '0') > 9) { |
| 1483 |
xdvi_bell(); |
| 1484 |
return; |
| 1485 |
} |
| 1486 |
m_have_arg = True; |
| 1487 |
|
| 1488 |
/* don't increment m_number if it would overflow */ |
| 1489 |
if (m_number < MAXINT_QUOT || (m_number == MAXINT_QUOT && digit <= MAXINT_MOD)) { |
| 1490 |
m_number = m_number * 10 + digit; |
| 1491 |
if (resource.expert_mode & XPRT_SHOW_STATUSLINE) /* too distracting for stdout */ |
| 1492 |
statusline_info(STATUS_SHORT, "numerical prefix: %s%d", m_sign < 0 ? "-" : "", m_number); |
| 1493 |
} |
| 1494 |
else { |
| 1495 |
xdvi_bell(); |
| 1496 |
statusline_info(STATUS_SHORT, "numerical prefix: %s%d: no larger value possible", m_sign < 0 ? "-" : "", m_number); |
| 1497 |
} |
| 1498 |
} |
| 1499 |
|
| 1500 |
static void |
| 1501 |
Act_minus(Widget w, XEvent *event, |
| 1502 |
String *params, Cardinal *num_params) |
| 1503 |
{ |
| 1504 |
UNUSED(w); |
| 1505 |
UNUSED(event); |
| 1506 |
UNUSED(params); |
| 1507 |
UNUSED(num_params); |
| 1508 |
|
| 1509 |
m_have_arg = True; |
| 1510 |
m_sign = -m_sign; |
| 1511 |
if (m_number > 0) { |
| 1512 |
if (resource.expert_mode & XPRT_SHOW_STATUSLINE) /* too distracting for stdout */ |
| 1513 |
statusline_info(STATUS_SHORT, "numerical prefix: %s%d", m_sign < 0 ? "-" : "", m_number); |
| 1514 |
} |
| 1515 |
else { |
| 1516 |
if (resource.expert_mode & XPRT_SHOW_STATUSLINE) /* too distracting for stdout */ |
| 1517 |
statusline_info(STATUS_SHORT, "numerical prefix: %s", m_sign < 0 ? "-" : ""); |
| 1518 |
} |
| 1519 |
} |
| 1520 |
|
| 1521 |
static void |
| 1522 |
Act_quit(Widget w, XEvent *event, |
| 1523 |
String *params, Cardinal *num_params) |
| 1524 |
{ |
| 1525 |
UNUSED(w); |
| 1526 |
UNUSED(event); |
| 1527 |
UNUSED(params); |
| 1528 |
UNUSED(num_params); |
| 1529 |
|
| 1530 |
#ifndef FLAKY_SIGPOLL |
| 1531 |
if (globals.debug & DBG_EVENT) |
| 1532 |
puts(event_freq < 0 |
| 1533 |
? "SIGPOLL is working" |
| 1534 |
: "no SIGPOLL signals received"); |
| 1535 |
#endif |
| 1536 |
xdvi_normal_exit(); |
| 1537 |
} |
| 1538 |
|
| 1539 |
static void |
| 1540 |
Act_quit_confirm(Widget w, XEvent *event, |
| 1541 |
String *params, Cardinal *num_params) |
| 1542 |
{ |
| 1543 |
static Widget dialog = 0; |
| 1544 |
|
| 1545 |
UNUSED(w); |
| 1546 |
UNUSED(event); |
| 1547 |
UNUSED(params); |
| 1548 |
UNUSED(num_params); |
| 1549 |
|
| 1550 |
#ifndef FLAKY_SIGPOLL |
| 1551 |
if (globals.debug & DBG_EVENT) |
| 1552 |
puts(event_freq < 0 |
| 1553 |
? "SIGPOLL is working" |
| 1554 |
: "no SIGPOLL signals received"); |
| 1555 |
#endif |
| 1556 |
|
| 1557 |
/* already a quit dialog open? */ |
| 1558 |
if (dialog != 0) { |
| 1559 |
/* HACK ALERT: use brute force, since tests for XtIsRealized() |
| 1560 |
or XtIsMapped() don't work?? Grabbing the server apparently |
| 1561 |
has problems with Xaw, and it's not a nice solution anyway ... */ |
| 1562 |
if (kill_message_window(dialog)) |
| 1563 |
xdvi_bell(); |
| 1564 |
} |
| 1565 |
|
| 1566 |
dialog = choice_dialog_sized(globals.widgets.top_level, |
| 1567 |
MSG_QUESTION, |
| 1568 |
SIZE_SMALL, |
| 1569 |
NULL, |
| 1570 |
#ifndef MOTIF |
| 1571 |
"quit", |
| 1572 |
#endif |
| 1573 |
NULL, NULL, /* no pre_callbacks */ |
| 1574 |
"OK", xdvi_normal_exit_cb, NULL, |
| 1575 |
"Cancel", NULL, NULL, |
| 1576 |
"Really quit xdvi?"); |
| 1577 |
} |
| 1578 |
|
| 1579 |
static void |
| 1580 |
Act_load_url(Widget w, XEvent *event, String *params, Cardinal *num_params) |
| 1581 |
{ |
| 1582 |
UNUSED(w); |
| 1583 |
UNUSED(event); |
| 1584 |
UNUSED(num_params); |
| 1585 |
launch_browser(*params); |
| 1586 |
} |
| 1587 |
|
| 1588 |
static void |
| 1589 |
Act_print(Widget w, XEvent *event, String *params, Cardinal *num_params) |
| 1590 |
{ |
| 1591 |
/* static so that we can pass them around to callbacks etc. */ |
| 1592 |
static struct save_or_print_info info; |
| 1593 |
static struct select_pages_info pinfo = { |
| 1594 |
0, 0, check_marked, { 0, NULL }, NO_ERROR |
| 1595 |
}; |
| 1596 |
static struct file_info finfo = { |
| 1597 |
NULL, NULL, |
| 1598 |
NULL, NULL, |
| 1599 |
NULL |
| 1600 |
}; |
| 1601 |
static Boolean first_time = True; |
| 1602 |
|
| 1603 |
UNUSED(w); |
| 1604 |
UNUSED(event); |
| 1605 |
UNUSED(params); |
| 1606 |
UNUSED(num_params); |
| 1607 |
|
| 1608 |
if (first_time) { |
| 1609 |
info.shell = info.printlog = NULL; |
| 1610 |
info.act = FILE_PRINT; |
| 1611 |
info.pinfo = &pinfo; |
| 1612 |
info.finfo = &finfo; |
| 1613 |
info.callbacks = NULL; |
| 1614 |
first_time = False; |
| 1615 |
} |
| 1616 |
save_or_print_callback(&info); |
| 1617 |
} |
| 1618 |
|
| 1619 |
static void |
| 1620 |
Act_save(Widget w, XEvent *event, String *params, Cardinal *num_params) |
| 1621 |
{ |
| 1622 |
/* static so that we can pass them around to callbacks etc. */ |
| 1623 |
static struct save_or_print_info info; |
| 1624 |
static struct select_pages_info pinfo = { |
| 1625 |
0, 0, check_marked, { 0, NULL }, NO_ERROR |
| 1626 |
}; |
| 1627 |
static struct file_info finfo = { |
| 1628 |
NULL, NULL, |
| 1629 |
NULL, NULL, |
| 1630 |
NULL |
| 1631 |
}; |
| 1632 |
static Boolean first_time = True; |
| 1633 |
|
| 1634 |
UNUSED(w); |
| 1635 |
UNUSED(event); |
| 1636 |
UNUSED(params); |
| 1637 |
UNUSED(num_params); |
| 1638 |
|
| 1639 |
if (first_time) { |
| 1640 |
info.shell = info.printlog = NULL; |
| 1641 |
info.act = FILE_SAVE; |
| 1642 |
info.pinfo = &pinfo; |
| 1643 |
info.finfo = &finfo; |
| 1644 |
info.callbacks = NULL; |
| 1645 |
first_time = False; |
| 1646 |
} |
| 1647 |
save_or_print_callback(&info); |
| 1648 |
} |
| 1649 |
|
| 1650 |
static void |
| 1651 |
Act_find(Widget w, XEvent *event, String *params, Cardinal *num_params) |
| 1652 |
{ |
| 1653 |
UNUSED(w); |
| 1654 |
UNUSED(event); |
| 1655 |
UNUSED(params); |
| 1656 |
UNUSED(num_params); |
| 1657 |
dvi_find_string(NULL, False); |
| 1658 |
} |
| 1659 |
|
| 1660 |
static void |
| 1661 |
Act_incremental_find(Widget w, XEvent *event, String *params, Cardinal *num_params) |
| 1662 |
{ |
| 1663 |
UNUSED(w); |
| 1664 |
UNUSED(event); |
| 1665 |
UNUSED(params); |
| 1666 |
UNUSED(num_params); |
| 1667 |
isearch_start(); |
| 1668 |
} |
| 1669 |
|
| 1670 |
static void |
| 1671 |
Act_find_next(Widget w, XEvent *event, String *params, Cardinal *num_params) |
| 1672 |
{ |
| 1673 |
UNUSED(w); |
| 1674 |
UNUSED(event); |
| 1675 |
UNUSED(params); |
| 1676 |
UNUSED(num_params); |
| 1677 |
dvi_find_string(NULL, True); |
| 1678 |
} |
| 1679 |
|
| 1680 |
static void |
| 1681 |
Act_help(Widget w, XEvent *event, |
| 1682 |
String *params, Cardinal *num_params) |
| 1683 |
{ |
| 1684 |
char *arg = NULL; |
| 1685 |
|
| 1686 |
UNUSED(w); |
| 1687 |
UNUSED(event); |
| 1688 |
|
| 1689 |
if (*num_params > 0) |
| 1690 |
arg = *params; |
| 1691 |
|
| 1692 |
show_help(globals.widgets.top_level, arg); |
| 1693 |
} |
| 1694 |
|
| 1695 |
static home_proc home_action = NULL; |
| 1696 |
|
| 1697 |
void |
| 1698 |
goto_page(int new_page, home_proc proc, Boolean force) |
| 1699 |
{ |
| 1700 |
/* SU: added clearing the window here, otherwise old window content |
| 1701 |
will survive switching pages as long as globals.pausing.flag is active |
| 1702 |
(i.e. when accidentally changing page instead of unpausing) |
| 1703 |
*/ |
| 1704 |
if (globals.pausing.flag) { |
| 1705 |
#if PS_GS |
| 1706 |
gs_erase_page(); |
| 1707 |
#endif |
| 1708 |
XClearWindow(DISP, mane.win); |
| 1709 |
} |
| 1710 |
|
| 1711 |
if (globals.dvi_file.bak_fp == NULL) { |
| 1712 |
current_page = new_page; /* so that xdvi gets the page change */ |
| 1713 |
return; |
| 1714 |
} |
| 1715 |
|
| 1716 |
xdvi_assert(XDVI_VERSION_INFO, __FILE__, __LINE__, |
| 1717 |
new_page >= 0 && new_page < total_pages, |
| 1718 |
"%d >= 0 && %d < %d", new_page, new_page, total_pages); |
| 1719 |
|
| 1720 |
if (current_page != new_page || force) { |
| 1721 |
globals.cursor.flags &= ~CURSOR_LINK; /* disable link cursor if needed */ |
| 1722 |
|
| 1723 |
current_page = new_page; |
| 1724 |
home_action = proc; |
| 1725 |
globals.warn_spec_now = resource.warn_spec; |
| 1726 |
/* this seems unneccessary */ |
| 1727 |
/* if (!resource.keep_flag) */ |
| 1728 |
/* home(False); */ |
| 1729 |
#if defined(MOTIF) && HAVE_XPM |
| 1730 |
tb_check_navigation_sensitivity(current_page); |
| 1731 |
/* page_history_update_toolbar_navigation(); */ |
| 1732 |
#endif |
| 1733 |
maybe_scroll_pagelist(current_page, False); |
| 1734 |
|
| 1735 |
if (globals.pausing.num_save) |
| 1736 |
globals.pausing.num = globals.pausing.num_save[new_page]; |
| 1737 |
else |
| 1738 |
globals.pausing.num = 0; |
| 1739 |
/* Control-L (and changing the page) clears this box */ |
| 1740 |
globals.src.fwd_box_page = -1; |
| 1741 |
|
| 1742 |
globals.ev.flags |= EV_NEWPAGE; |
| 1743 |
XFlush(DISP); |
| 1744 |
} |
| 1745 |
} |
| 1746 |
|
| 1747 |
|
| 1748 |
static void |
| 1749 |
Act_goto_page(Widget w, XEvent *event, |
| 1750 |
String *params, Cardinal *num_params) |
| 1751 |
{ |
| 1752 |
int arg; |
| 1753 |
Boolean clear_statusline = False; |
| 1754 |
|
| 1755 |
UNUSED(w); |
| 1756 |
UNUSED(event); |
| 1757 |
|
| 1758 |
warn_num_params("goto-page()", params, *num_params, 1); |
| 1759 |
|
| 1760 |
if (*num_params > 0) { |
| 1761 |
if (**params == 'e') { |
| 1762 |
arg = total_pages - 1; |
| 1763 |
} |
| 1764 |
else |
| 1765 |
arg = atoi(*params) - globals.pageno_correct; |
| 1766 |
} |
| 1767 |
else { |
| 1768 |
if (get_prefix_arg(&arg)) { |
| 1769 |
clear_statusline = True; |
| 1770 |
arg -= globals.pageno_correct; |
| 1771 |
} |
| 1772 |
else { |
| 1773 |
arg = total_pages - 1; |
| 1774 |
} |
| 1775 |
} |
| 1776 |
if (arg == total_pages - 1) { |
| 1777 |
/* with TeX numbers, total_pages - 1 might not be found in the page list, |
| 1778 |
so don't use check_goto_tex_page() in this case */ |
| 1779 |
goto_page(check_goto_page(arg, True), resource.keep_flag ? NULL : home, False); |
| 1780 |
} |
| 1781 |
else { |
| 1782 |
goto_page(check_goto_tex_page(arg), resource.keep_flag ? NULL : home, False); |
| 1783 |
} |
| 1784 |
search_signal_page_changed(); |
| 1785 |
if (clear_statusline) |
| 1786 |
statusline_clear(); |
| 1787 |
statusline_erase("Page history:"); |
| 1788 |
} |
| 1789 |
|
| 1790 |
void |
| 1791 |
Act_recent_files(Widget w, XEvent *event, |
| 1792 |
String *params, Cardinal *num_params) |
| 1793 |
{ |
| 1794 |
UNUSED(w); |
| 1795 |
UNUSED(event); |
| 1796 |
UNUSED(params); |
| 1797 |
UNUSED(num_params); |
| 1798 |
} |
| 1799 |
|
| 1800 |
void |
| 1801 |
Act_use_tex_pages(Widget w, XEvent *event, |
| 1802 |
String *params, Cardinal *num_params) |
| 1803 |
{ |
| 1804 |
UNUSED(w); |
| 1805 |
UNUSED(event); |
| 1806 |
|
| 1807 |
|
| 1808 |
if (*num_params == 0) { |
| 1809 |
if (m_have_arg) { |
| 1810 |
resource.use_tex_pages = (m_number != 0); |
| 1811 |
m_have_arg = False; |
| 1812 |
m_number = 0; |
| 1813 |
m_sign = 1; |
| 1814 |
} |
| 1815 |
else { |
| 1816 |
resource.use_tex_pages = !resource.use_tex_pages; |
| 1817 |
} |
| 1818 |
} |
| 1819 |
else |
| 1820 |
resource.use_tex_pages = (**params == 't' ? !resource.use_tex_pages : atoi(*params)); |
| 1821 |
|
| 1822 |
if (resource.use_tex_pages) { |
| 1823 |
statusline_info(STATUS_SHORT, "Using TeX page numbers for \"g\", goto-page()"); |
| 1824 |
} |
| 1825 |
else { |
| 1826 |
statusline_info(STATUS_SHORT, "Using physical page numbers for \"g\", goto-page()"); |
| 1827 |
} |
| 1828 |
|
| 1829 |
store_preference(NULL, "useTeXPages", "%s", resource.use_tex_pages ? "True" : "False"); |
| 1830 |
|
| 1831 |
set_menu(&resource.use_tex_pages, Act_use_tex_pages, check_toggle); |
| 1832 |
|
| 1833 |
refresh_pagelist(total_pages, current_page); |
| 1834 |
} |
| 1835 |
|
| 1836 |
void |
| 1837 |
Act_forward_page(Widget w, XEvent *event, |
| 1838 |
String *params, Cardinal *num_params) |
| 1839 |
{ |
| 1840 |
int arg; |
| 1841 |
Boolean clear_statusline = False; |
| 1842 |
|
| 1843 |
UNUSED(w); |
| 1844 |
UNUSED(event); |
| 1845 |
|
| 1846 |
if (!get_int_arg(params, num_params, &arg)) |
| 1847 |
arg = 1; |
| 1848 |
else |
| 1849 |
clear_statusline = True; |
| 1850 |
|
| 1851 |
arg += current_page; |
| 1852 |
|
| 1853 |
if (arg == current_page) { /* zero argument -> redraw page */ |
| 1854 |
globals.src.fwd_box_page = -1; |
| 1855 |
search_reset_info(); |
| 1856 |
globals.ev.flags |= EV_NEWPAGE; |
| 1857 |
XFlush(DISP); |
| 1858 |
statusline_info(STATUS_SHORT, "Page redrawn."); |
| 1859 |
return; |
| 1860 |
} |
| 1861 |
else if (current_page >= total_pages - 1) { |
| 1862 |
xdvi_bell(); |
| 1863 |
/* statusline_info(STATUS_SHORT, "Last page of DVI file"); */ |
| 1864 |
return; |
| 1865 |
} |
| 1866 |
|
| 1867 |
goto_page(check_goto_page(arg, True), resource.keep_flag ? NULL : home, False); |
| 1868 |
if (clear_statusline) |
| 1869 |
statusline_clear(); |
| 1870 |
statusline_erase("Page history:"); |
| 1871 |
search_signal_page_changed(); |
| 1872 |
} |
| 1873 |
|
| 1874 |
void |
| 1875 |
Act_back_page(Widget w, XEvent *event, |
| 1876 |
String *params, Cardinal *num_params) |
| 1877 |
{ |
| 1878 |
int arg; |
| 1879 |
Boolean clear_statusline = False; |
| 1880 |
|
| 1881 |
UNUSED(w); |
| 1882 |
UNUSED(event); |
| 1883 |
|
| 1884 |
if (!get_int_arg(params, num_params, &arg)) |
| 1885 |
arg = 1; |
| 1886 |
else |
| 1887 |
clear_statusline = True; |
| 1888 |
|
| 1889 |
arg = current_page - arg; |
| 1890 |
|
| 1891 |
if (current_page == 0) { |
| 1892 |
xdvi_bell(); |
| 1893 |
/* statusline_info(STATUS_SHORT, "First page of DVI file"); */ |
| 1894 |
return; |
| 1895 |
} |
| 1896 |
|
| 1897 |
goto_page(check_goto_page(arg, True), resource.keep_flag ? NULL : home, False); |
| 1898 |
if (clear_statusline) |
| 1899 |
statusline_clear(); |
| 1900 |
statusline_erase("Page history:"); |
| 1901 |
search_signal_page_changed(); |
| 1902 |
} |
| 1903 |
|
| 1904 |
static void |
| 1905 |
Act_declare_page_number(Widget w, XEvent *event, |
| 1906 |
String *params, Cardinal *num_params) |
| 1907 |
{ |
| 1908 |
int arg; |
| 1909 |
|
| 1910 |
UNUSED(w); |
| 1911 |
UNUSED(event); |
| 1912 |
|
| 1913 |
if (globals.curr_mode == RULER_MODE_ACTIVE) { |
| 1914 |
show_distance_from_ruler(event, True); |
| 1915 |
return; |
| 1916 |
} |
| 1917 |
|
| 1918 |
if (!get_int_arg(params, num_params, &arg)) { |
| 1919 |
arg = 0; |
| 1920 |
} |
| 1921 |
globals.pageno_correct = arg - current_page; |
| 1922 |
statusline_info(STATUS_SHORT, "Current page number set to %d", arg); |
| 1923 |
} |
| 1924 |
|
| 1925 |
static void |
| 1926 |
Act_toggle_mark(Widget w, XEvent *event, |
| 1927 |
String *params, Cardinal *num_params) |
| 1928 |
{ |
| 1929 |
int arg; |
| 1930 |
|
| 1931 |
UNUSED(w); |
| 1932 |
UNUSED(event); |
| 1933 |
|
| 1934 |
if (globals.dvi_file.bak_fp == NULL) |
| 1935 |
return; |
| 1936 |
|
| 1937 |
if ( |
| 1938 |
#ifdef MOTIF |
| 1939 |
(resource.expert_mode & XPRT_SHOW_PAGELIST) == 0 |
| 1940 |
#else |
| 1941 |
(resource.expert_mode & XPRT_SHOW_BUTTONS) == 0 |
| 1942 |
#endif |
| 1943 |
) { |
| 1944 |
xdvi_bell(); |
| 1945 |
statusline_info(STATUS_SHORT, |
| 1946 |
"Expert mode: Page list not available."); |
| 1947 |
return; |
| 1948 |
} |
| 1949 |
|
| 1950 |
if (*num_params > 0) { |
| 1951 |
arg = atoi(*params); |
| 1952 |
if (arg < -1 || arg > 2) { |
| 1953 |
xdvi_bell(); |
| 1954 |
statusline_error(STATUS_SHORT, |
| 1955 |
"Possible arguments: none (toggle current), " |
| 1956 |
"-1 (mark all), 0 (unmark all), 1 (toggle odd), 2 (toggle even)"); |
| 1957 |
} |
| 1958 |
list_toggle_marks(arg); |
| 1959 |
} |
| 1960 |
else if (get_prefix_arg(&arg)) { |
| 1961 |
list_toggle_marks(arg); |
| 1962 |
statusline_clear(); |
| 1963 |
} |
| 1964 |
else { |
| 1965 |
arg = current_page; |
| 1966 |
list_toggle_current(arg); |
| 1967 |
} |
| 1968 |
} |
| 1969 |
|
| 1970 |
static void |
| 1971 |
Act_home(Widget w, XEvent *event, |
| 1972 |
String *params, Cardinal *num_params) |
| 1973 |
{ |
| 1974 |
UNUSED(w); |
| 1975 |
UNUSED(event); |
| 1976 |
UNUSED(params); |
| 1977 |
UNUSED(num_params); |
| 1978 |
|
| 1979 |
home(True); |
| 1980 |
} |
| 1981 |
|
| 1982 |
static void |
| 1983 |
Act_home_or_top(Widget w, XEvent *event, |
| 1984 |
String *params, Cardinal *num_params) |
| 1985 |
{ |
| 1986 |
UNUSED(w); |
| 1987 |
UNUSED(event); |
| 1988 |
UNUSED(params); |
| 1989 |
UNUSED(num_params); |
| 1990 |
|
| 1991 |
if (resource.keep_flag) { |
| 1992 |
String args[1]; |
| 1993 |
args[0] = "10"; /* should be large enough ... */ |
| 1994 |
XtCallActionProc(globals.widgets.top_level, "up", NULL, args, 1); |
| 1995 |
} |
| 1996 |
else { |
| 1997 |
home(True); |
| 1998 |
} |
| 1999 |
} |
| 2000 |
|
| 2001 |
static void |
| 2002 |
Act_end_or_bottom(Widget w, XEvent *event, |
| 2003 |
String *params, Cardinal *num_params) |
| 2004 |
{ |
| 2005 |
String args[1]; |
| 2006 |
|
| 2007 |
UNUSED(w); |
| 2008 |
UNUSED(event); |
| 2009 |
UNUSED(params); |
| 2010 |
UNUSED(num_params); |
| 2011 |
|
| 2012 |
args[0] = "10"; /* should be large enough ... */ |
| 2013 |
XtCallActionProc(globals.widgets.top_level, "down", NULL, args, 1); |
| 2014 |
|
| 2015 |
if (!resource.keep_flag |
| 2016 |
#ifndef MOTIF |
| 2017 |
&& globals.widgets.x_bar != NULL |
| 2018 |
#endif |
| 2019 |
) { |
| 2020 |
XtCallActionProc(globals.widgets.top_level, "right", NULL, args, 1); |
| 2021 |
} |
| 2022 |
} |
| 2023 |
|
| 2024 |
static void |
| 2025 |
Act_center(Widget w, XEvent *event, |
| 2026 |
String *params, Cardinal *num_params) |
| 2027 |
{ |
| 2028 |
int x, y; |
| 2029 |
|
| 2030 |
UNUSED(w); |
| 2031 |
UNUSED(params); |
| 2032 |
UNUSED(num_params); |
| 2033 |
|
| 2034 |
#ifdef MOTIF |
| 2035 |
/* The clip widget gives a more exact value. */ |
| 2036 |
x = event->xkey.x - mane.width / 2; |
| 2037 |
y = event->xkey.y - mane.height / 2; |
| 2038 |
|
| 2039 |
x = set_bar_value(globals.widgets.x_bar, x, (int)(globals.page.w - mane.width)); |
| 2040 |
y = set_bar_value(globals.widgets.y_bar, y, (int)(globals.page.h - mane.height)); |
| 2041 |
get_xy(); |
| 2042 |
XWarpPointer(DISP, None, None, 0, 0, 0, 0, -x - m_window_x, -y - m_window_y); |
| 2043 |
#else |
| 2044 |
|
| 2045 |
if (event == NULL) |
| 2046 |
return; /* button actions do not provide events */ |
| 2047 |
|
| 2048 |
x = event->xkey.x - mane.width / 2; |
| 2049 |
y = event->xkey.y - mane.height / 2; |
| 2050 |
/* The clip widget gives a more exact value. */ |
| 2051 |
if (globals.widgets.x_bar != NULL) |
| 2052 |
XtCallCallbacks(globals.widgets.x_bar, XtNscrollProc, cast_int_to_XtPointer(x)); |
| 2053 |
if (globals.widgets.y_bar != NULL) |
| 2054 |
XtCallCallbacks(globals.widgets.y_bar, XtNscrollProc, cast_int_to_XtPointer(y)); |
| 2055 |
XWarpPointer(DISP, None, None, 0, 0, 0, 0, -x, -y); |
| 2056 |
#endif |
| 2057 |
#ifdef USE_PANNER |
| 2058 |
handle_x_scroll(NULL, NULL, NULL, NULL); |
| 2059 |
handle_y_scroll(NULL, NULL, NULL, NULL); |
| 2060 |
#endif |
| 2061 |
} |
| 2062 |
|
| 2063 |
void |
| 2064 |
Act_ruler_snap_origin(Widget w, XEvent *event, |
| 2065 |
String *params, Cardinal *num_params) |
| 2066 |
{ |
| 2067 |
UNUSED(w); |
| 2068 |
UNUSED(params); |
| 2069 |
UNUSED(num_params); |
| 2070 |
|
| 2071 |
if (globals.curr_mode == RULER_MODE_ACTIVE) |
| 2072 |
ruler_snap_origin(event); |
| 2073 |
} |
| 2074 |
|
| 2075 |
#if 0 |
| 2076 |
void |
| 2077 |
Act_set_papersize(Widget w, XEvent *event, |
| 2078 |
String *params, Cardinal *num_params) |
| 2079 |
{ |
| 2080 |
UNUSED(w); |
| 2081 |
UNUSED(event); |
| 2082 |
UNUSED(num_params); |
| 2083 |
|
| 2084 |
fprintf(stderr, "set_paperformat: %s\n", *params); |
| 2085 |
resource.paper = *params; |
| 2086 |
set_menu((void *)resource.paper, Act_set_papersize, check_papersize); |
| 2087 |
} |
| 2088 |
|
| 2089 |
void |
| 2090 |
Act_set_paper_landscape(Widget w, XEvent *event, |
| 2091 |
String *params, Cardinal *num_params) |
| 2092 |
{ |
| 2093 |
UNUSED(w); |
| 2094 |
UNUSED(event); |
| 2095 |
UNUSED(num_params); |
| 2096 |
|
| 2097 |
resource.paper_landscape = !resource.paper_landscape; |
| 2098 |
fprintf(stderr, "set_paper_landscape: %s\n", *params); |
| 2099 |
|
| 2100 |
set_menu((char *)resource.paper, Act_set_paper_landscape, check_paper_landscape); |
| 2101 |
} |
| 2102 |
#endif /* 0 */ |
| 2103 |
|
| 2104 |
|
| 2105 |
void |
| 2106 |
Act_set_keep_flag(Widget w, XEvent *event, |
| 2107 |
String *params, Cardinal *num_params) |
| 2108 |
{ |
| 2109 |
UNUSED(event); |
| 2110 |
UNUSED(w); |
| 2111 |
|
| 2112 |
if (*num_params == 0) { |
| 2113 |
if (m_have_arg) { |
| 2114 |
resource.keep_flag = (m_number != 0); |
| 2115 |
m_have_arg = False; |
| 2116 |
m_number = 0; |
| 2117 |
m_sign = 1; |
| 2118 |
} |
| 2119 |
else { |
| 2120 |
resource.keep_flag = !resource.keep_flag; |
| 2121 |
} |
| 2122 |
} |
| 2123 |
else |
| 2124 |
resource.keep_flag = (**params == 't' |
| 2125 |
? !resource.keep_flag : atoi(*params)); |
| 2126 |
if (resource.keep_flag) { |
| 2127 |
statusline_info(STATUS_SHORT, "Keeping position when switching pages"); |
| 2128 |
} |
| 2129 |
else { |
| 2130 |
statusline_info(STATUS_SHORT, |
| 2131 |
"Not keeping position when switching pages"); |
| 2132 |
} |
| 2133 |
|
| 2134 |
store_preference(NULL, "keepPosition", "%s", resource.keep_flag ? "True" : "False"); |
| 2135 |
|
| 2136 |
set_menu(&resource.keep_flag, Act_set_keep_flag, check_toggle); |
| 2137 |
} |
| 2138 |
|
| 2139 |
static void |
| 2140 |
Act_left(Widget w, XEvent *event, |
| 2141 |
String *params, Cardinal *num_params) |
| 2142 |
{ |
| 2143 |
UNUSED(w); |
| 2144 |
UNUSED(event); |
| 2145 |
|
| 2146 |
do_autoscroll = False; |
| 2147 |
|
| 2148 |
warn_num_params("left()", params, *num_params, 1); |
| 2149 |
|
| 2150 |
#ifdef MOTIF |
| 2151 |
get_xy(); |
| 2152 |
#ifdef TEST_SCROLLING |
| 2153 |
fprintf(stderr, "left for %p\n", (void *)w); |
| 2154 |
fprintf(stderr, "window x: %d, y: %d\n", m_window_x, m_window_y); |
| 2155 |
#endif |
| 2156 |
|
| 2157 |
(void)set_bar_value(globals.widgets.x_bar, (*num_params == 0 ? (-2 * (int)mane.width / 3) |
| 2158 |
: (int)(-my_atof(*params) * mane.width)) - m_window_x, |
| 2159 |
(int)(globals.page.w - mane.width)); |
| 2160 |
#else |
| 2161 |
if (globals.widgets.x_bar != NULL) |
| 2162 |
XtCallCallbacks(globals.widgets.x_bar, XtNscrollProc, |
| 2163 |
cast_int_to_XtPointer(*num_params == 0 ? (-2 * (int)mane.width / 3) |
| 2164 |
: (int)(-my_atof(*params) * mane.width))); |
| 2165 |
else { |
| 2166 |
xdvi_bell(); |
| 2167 |
/* statusline_info(STATUS_SHORT, "Horizontal scrolling not possible"); */ |
| 2168 |
} |
| 2169 |
#endif |
| 2170 |
#ifdef USE_PANNER |
| 2171 |
handle_x_scroll(NULL, NULL, NULL, NULL); |
| 2172 |
#endif |
| 2173 |
} |
| 2174 |
|
| 2175 |
static void |
| 2176 |
Act_right(Widget w, XEvent *event, |
| 2177 |
String *params, Cardinal *num_params) |
| 2178 |
{ |
| 2179 |
UNUSED(w); |
| 2180 |
UNUSED(event); |
| 2181 |
|
| 2182 |
do_autoscroll = False; |
| 2183 |
|
| 2184 |
warn_num_params("right()", params, *num_params, 1); |
| 2185 |
|
| 2186 |
#ifdef MOTIF |
| 2187 |
get_xy(); |
| 2188 |
#ifdef TEST_SCROLLING |
| 2189 |
fprintf(stderr, "right for %p\n", (void *)w); |
| 2190 |
fprintf(stderr, "window x: %d, y: %d\n", m_window_x, m_window_y); |
| 2191 |
#endif |
| 2192 |
|
| 2193 |
(void)set_bar_value(globals.widgets.x_bar, (*num_params == 0 ? (2 * (int)mane.width / 3) |
| 2194 |
: (int)(my_atof(*params) * mane.width)) - m_window_x, |
| 2195 |
(int)(globals.page.w - mane.width)); |
| 2196 |
#else |
| 2197 |
if (globals.widgets.x_bar != NULL) |
| 2198 |
XtCallCallbacks(globals.widgets.x_bar, XtNscrollProc, |
| 2199 |
cast_int_to_XtPointer(*num_params == 0 ? (2 * (int)mane.width / 3) |
| 2200 |
: (int)(my_atof(*params) * mane.width))); |
| 2201 |
else { |
| 2202 |
xdvi_bell(); |
| 2203 |
/* statusline_info(STATUS_SHORT, "Horizontal scrolling not possible"); */ |
| 2204 |
} |
| 2205 |
#endif |
| 2206 |
#ifdef USE_PANNER |
| 2207 |
handle_x_scroll(NULL, NULL, NULL, NULL); |
| 2208 |
#endif |
| 2209 |
} |
| 2210 |
|
| 2211 |
static void |
| 2212 |
Act_up(Widget w, XEvent *event, |
| 2213 |
String *params, Cardinal *num_params) |
| 2214 |
{ |
| 2215 |
UNUSED(w); |
| 2216 |
UNUSED(event); |
| 2217 |
|
| 2218 |
do_autoscroll = False; |
| 2219 |
|
| 2220 |
warn_num_params("up()", params, *num_params, 1); |
| 2221 |
|
| 2222 |
#ifdef MOTIF |
| 2223 |
#ifdef TEST_SCROLLING |
| 2224 |
fprintf(stderr, "up for %p\n", (void *)w); |
| 2225 |
#endif |
| 2226 |
get_xy(); |
| 2227 |
(void)set_bar_value(globals.widgets.y_bar, (*num_params == 0 ? (-2 * (int)mane.height / 3) |
| 2228 |
: (int)(-my_atof(*params) * mane.height)) - m_window_y, |
| 2229 |
(int)(globals.page.h - mane.height)); |
| 2230 |
#else |
| 2231 |
if (globals.widgets.y_bar != NULL) |
| 2232 |
XtCallCallbacks(globals.widgets.y_bar, XtNscrollProc, |
| 2233 |
cast_int_to_XtPointer(*num_params == 0 ? (-2 * (int)mane.height / 3) |
| 2234 |
: (int)(-my_atof(*params) * mane.height))); |
| 2235 |
else { |
| 2236 |
xdvi_bell(); |
| 2237 |
/* statusline_info(STATUS_SHORT, "Vertical scrolling not possible"); */ |
| 2238 |
} |
| 2239 |
#endif |
| 2240 |
#ifdef USE_PANNER |
| 2241 |
handle_y_scroll(NULL, NULL, NULL, NULL); |
| 2242 |
#endif |
| 2243 |
} |
| 2244 |
|
| 2245 |
static void |
| 2246 |
Act_down(Widget w, XEvent *event, |
| 2247 |
String *params, Cardinal *num_params) |
| 2248 |
{ |
| 2249 |
UNUSED(w); |
| 2250 |
UNUSED(event); |
| 2251 |
|
| 2252 |
do_autoscroll = False; |
| 2253 |
|
| 2254 |
warn_num_params("down()", params, *num_params, 1); |
| 2255 |
|
| 2256 |
#ifdef MOTIF |
| 2257 |
#ifdef TEST_SCROLLING |
| 2258 |
fprintf(stderr, "down for %p\n", (void *)w); |
| 2259 |
#endif |
| 2260 |
get_xy(); |
| 2261 |
(void)set_bar_value(globals.widgets.y_bar, (*num_params == 0 ? (2 * (int)mane.height / 3) |
| 2262 |
: (int)(my_atof(*params) * mane.height)) - m_window_y, |
| 2263 |
(int)(globals.page.h - mane.height)); |
| 2264 |
#else |
| 2265 |
if (globals.widgets.y_bar != NULL) |
| 2266 |
XtCallCallbacks(globals.widgets.y_bar, XtNscrollProc, |
| 2267 |
cast_int_to_XtPointer(*num_params == 0 ? (2 * (int)mane.height / 3) |
| 2268 |
: (int)(my_atof(*params) * mane.height))); |
| 2269 |
else { |
| 2270 |
xdvi_bell(); |
| 2271 |
/* statusline_info(STATUS_SHORT, "Vertical scrolling not possible"); */ |
| 2272 |
} |
| 2273 |
#endif |
| 2274 |
#ifdef USE_PANNER |
| 2275 |
handle_y_scroll(NULL, NULL, NULL, NULL); |
| 2276 |
#endif |
| 2277 |
} |
| 2278 |
|
| 2279 |
static void |
| 2280 |
Act_down_or_next(Widget w, XEvent *event, |
| 2281 |
String *params, Cardinal *num_params) |
| 2282 |
{ |
| 2283 |
UNUSED(w); |
| 2284 |
UNUSED(event); |
| 2285 |
|
| 2286 |
do_autoscroll = False; |
| 2287 |
|
| 2288 |
warn_num_params("down-or-next()", params, *num_params, 1); |
| 2289 |
|
| 2290 |
#ifdef TEST_SCROLLING |
| 2291 |
fprintf(stderr, "down-or-next for %p\n", (void *)w); |
| 2292 |
#endif |
| 2293 |
|
| 2294 |
#ifdef MOTIF |
| 2295 |
get_xy(); |
| 2296 |
if (m_window_y > (int)mane.height - (int)globals.page.h) { |
| 2297 |
(void)set_bar_value(globals.widgets.y_bar, (*num_params == 0 ? (2 * (int)mane.height / 3) |
| 2298 |
: (int)(my_atof(*params) * mane.height)) - |
| 2299 |
m_window_y, (int)(globals.page.h - mane.height)); |
| 2300 |
return; |
| 2301 |
} |
| 2302 |
#else |
| 2303 |
if (globals.widgets.y_bar != NULL) { |
| 2304 |
get_xy(); |
| 2305 |
if (m_window_y > (int)mane.height - (int)globals.page.h) { |
| 2306 |
XtCallCallbacks(globals.widgets.y_bar, XtNscrollProc, |
| 2307 |
cast_int_to_XtPointer(*num_params == |
| 2308 |
0 ? (2 * (int)mane.height / 3) |
| 2309 |
: (int)(my_atof(*params) * mane.height))); |
| 2310 |
return; |
| 2311 |
} |
| 2312 |
} |
| 2313 |
#endif |
| 2314 |
|
| 2315 |
if (current_page < total_pages - 1) { |
| 2316 |
goto_page(current_page + 1, home, False); |
| 2317 |
search_signal_page_changed(); |
| 2318 |
} |
| 2319 |
else { |
| 2320 |
xdvi_bell(); |
| 2321 |
/* statusline_info(STATUS_SHORT, "At bottom of last page"); */ |
| 2322 |
} |
| 2323 |
#ifdef USE_PANNER |
| 2324 |
handle_y_scroll(NULL, NULL, NULL, NULL); |
| 2325 |
#endif |
| 2326 |
statusline_erase("Page history:"); |
| 2327 |
} |
| 2328 |
|
| 2329 |
|
| 2330 |
static void |
| 2331 |
Act_up_or_previous(Widget w, XEvent *event, |
| 2332 |
String *params, Cardinal *num_params) |
| 2333 |
{ |
| 2334 |
UNUSED(w); |
| 2335 |
UNUSED(event); |
| 2336 |
|
| 2337 |
do_autoscroll = False; |
| 2338 |
|
| 2339 |
warn_num_params("up-or-previous()", params, *num_params, 1); |
| 2340 |
|
| 2341 |
#ifdef TEST_SCROLLING |
| 2342 |
fprintf(stderr, "up-or-previous for %p\n", (void *)w); |
| 2343 |
#endif |
| 2344 |
#ifdef MOTIF |
| 2345 |
get_xy(); |
| 2346 |
if (m_window_y < 0) { |
| 2347 |
(void)set_bar_value(globals.widgets.y_bar, |
| 2348 |
(*num_params == 0 ? (-2 * (int)mane.height / 3) |
| 2349 |
: (int)(-my_atof(*params) * mane.height)) - m_window_y, |
| 2350 |
(int)(globals.page.h - mane.height)); |
| 2351 |
return; |
| 2352 |
} |
| 2353 |
#else |
| 2354 |
if (globals.widgets.y_bar != NULL) { |
| 2355 |
get_xy(); |
| 2356 |
if (m_window_y < 0) { |
| 2357 |
XtCallCallbacks(globals.widgets.y_bar, XtNscrollProc, |
| 2358 |
cast_int_to_XtPointer(*num_params == |
| 2359 |
0 ? (-2 * (int)mane.height / 3) |
| 2360 |
: (int)(-my_atof(*params) * mane.height))); |
| 2361 |
return; |
| 2362 |
} |
| 2363 |
} |
| 2364 |
#endif |
| 2365 |
|
| 2366 |
if (current_page > 0) { |
| 2367 |
goto_page(current_page - 1, home_bottom, False); |
| 2368 |
search_signal_page_changed(); |
| 2369 |
} |
| 2370 |
else { |
| 2371 |
xdvi_bell(); |
| 2372 |
/* statusline_info(STATUS_SHORT, "At top of first page"); */ |
| 2373 |
} |
| 2374 |
statusline_erase("Page history:"); |
| 2375 |
#ifdef USE_PANNER |
| 2376 |
handle_y_scroll(NULL, NULL, NULL, NULL); |
| 2377 |
#endif |
| 2378 |
} |
| 2379 |
|
| 2380 |
|
| 2381 |
static void |
| 2382 |
Act_set_margins(Widget w, XEvent *event, |
| 2383 |
String *params, Cardinal *num_params) |
| 2384 |
{ |
| 2385 |
Window dummy; |
| 2386 |
|
| 2387 |
UNUSED(w); |
| 2388 |
UNUSED(params); |
| 2389 |
UNUSED(num_params); |
| 2390 |
|
| 2391 |
#ifndef MOTIF |
| 2392 |
if (event == NULL) |
| 2393 |
return; /* button actions do not provide events */ |
| 2394 |
#endif |
| 2395 |
|
| 2396 |
(void)XTranslateCoordinates(DISP, event->xkey.window, mane.win, |
| 2397 |
event->xkey.x, event->xkey.y, &resource.sidemargin_int, &resource.topmargin_int, &dummy); /* throw away last argument */ |
| 2398 |
statusline_info(STATUS_SHORT, "Margins set to cursor position (%d, %d)", resource.sidemargin_int, resource.topmargin_int); |
| 2399 |
resource.sidemargin_int *= mane.shrinkfactor; |
| 2400 |
resource.topmargin_int *= mane.shrinkfactor; |
| 2401 |
} |
| 2402 |
|
| 2403 |
static void |
| 2404 |
Act_show_display_attributes(Widget w, XEvent *event, |
| 2405 |
String *params, Cardinal *num_params) |
| 2406 |
{ |
| 2407 |
UNUSED(w); |
| 2408 |
UNUSED(event); |
| 2409 |
UNUSED(params); |
| 2410 |
UNUSED(num_params); |
| 2411 |
|
| 2412 |
statusline_error(STATUS_SHORT, "Unit = %d, bitord = %d, byteord = %d", |
| 2413 |
BitmapUnit(DISP), BitmapBitOrder(DISP), |
| 2414 |
ImageByteOrder(DISP)); |
| 2415 |
} |
| 2416 |
|
| 2417 |
int |
| 2418 |
shrink_to_fit(void) |
| 2419 |
{ |
| 2420 |
int value1; |
| 2421 |
int value2; |
| 2422 |
static Dimension window_w; |
| 2423 |
#ifndef MOTIF |
| 2424 |
static Dimension window_h; |
| 2425 |
#endif |
| 2426 |
|
| 2427 |
static Arg arg_wh[] = { |
| 2428 |
{XtNwidth, (XtArgVal) &window_w} |
| 2429 |
#ifndef MOTIF |
| 2430 |
, {XtNheight, (XtArgVal) &window_h} |
| 2431 |
#endif |
| 2432 |
}; |
| 2433 |
|
| 2434 |
|
| 2435 |
#ifdef MOTIF |
| 2436 |
XtGetValues(globals.widgets.main_window, arg_wh, XtNumber(arg_wh)); |
| 2437 |
#else |
| 2438 |
XtGetValues(globals.widgets.vport_widget, arg_wh, XtNumber(arg_wh)); |
| 2439 |
#endif |
| 2440 |
|
| 2441 |
value1 = ROUNDUP(globals.page.unshrunk_w, window_w - 2); |
| 2442 |
|
| 2443 |
#ifdef MOTIF |
| 2444 |
{ /* account for menubar */ |
| 2445 |
static Dimension new_h; |
| 2446 |
|
| 2447 |
/* get rid of scrollbar */ |
| 2448 |
XtVaSetValues(globals.widgets.draw_widget, XtNwidth, (XtArgVal)1, XtNheight, (XtArgVal)1, NULL); |
| 2449 |
XtVaGetValues(globals.widgets.clip_widget, XtNheight, &new_h, NULL); |
| 2450 |
value2 = ROUNDUP(globals.page.unshrunk_h, new_h - 2); |
| 2451 |
} |
| 2452 |
#else |
| 2453 |
/* FIXME: value seems too small here! */ |
| 2454 |
value2 = ROUNDUP(globals.page.unshrunk_h, window_h - 2); |
| 2455 |
#endif |
| 2456 |
|
| 2457 |
return value1 > value2 ? value1 : value2; |
| 2458 |
} |
| 2459 |
|
| 2460 |
void |
| 2461 |
do_set_shrinkfactor(int arg, Boolean set_resource) |
| 2462 |
{ |
| 2463 |
static int shrink_bak = -1; |
| 2464 |
|
| 2465 |
/* We don't store this as preference since it may affect initial window geometry. */ |
| 2466 |
/* store_preference(NULL, "shrinkFactor", "%d", arg); */ |
| 2467 |
|
| 2468 |
if (globals.curr_mode == TEXT_MODE_ACTIVE) { |
| 2469 |
text_change_region(TEXT_SEL_CLEAR, NULL); |
| 2470 |
} |
| 2471 |
|
| 2472 |
mane.shrinkfactor = arg; |
| 2473 |
if (set_resource) |
| 2474 |
resource.shrinkfactor = mane.shrinkfactor; |
| 2475 |
|
| 2476 |
set_menu(&arg, Act_set_shrink_factor, check_int); |
| 2477 |
#if HAVE_XMP |
| 2478 |
tb_set_zoom_sensitivity(arg != 1); |
| 2479 |
#endif |
| 2480 |
|
| 2481 |
if (arg != 1 && arg != shrink_bak) { |
| 2482 |
shrink_bak = arg; |
| 2483 |
#if GREY |
| 2484 |
#if COLOR |
| 2485 |
if (resource.use_grey) |
| 2486 |
fg_active = NULL; |
| 2487 |
#else |
| 2488 |
if (resource.use_grey) |
| 2489 |
init_pix(); |
| 2490 |
#endif |
| 2491 |
#endif /* GREY */ |
| 2492 |
reset_fonts(); |
| 2493 |
} |
| 2494 |
init_page(); |
| 2495 |
reconfig(); |
| 2496 |
|
| 2497 |
htex_resize_page(); |
| 2498 |
|
| 2499 |
/* this seems unneccessary */ |
| 2500 |
/* if (!resource.keep_flag) */ |
| 2501 |
/* home(False); */ |
| 2502 |
|
| 2503 |
globals.ev.flags |= EV_NEWPAGE; |
| 2504 |
XFlush(DISP); |
| 2505 |
} |
| 2506 |
|
| 2507 |
|
| 2508 |
/* A 'meta' action that is bound to mouse buttons and invokes actions depending on current mouse mode */ |
| 2509 |
void |
| 2510 |
Act_mouse_modes(Widget w, XEvent *event, |
| 2511 |
String *params, Cardinal *num_params) |
| 2512 |
{ |
| 2513 |
int i; |
| 2514 |
size_t mode_idx = 0; /* default: one action for all modes */ |
| 2515 |
struct xdvi_action *my_action = NULL, *ap = NULL; |
| 2516 |
|
| 2517 |
if (*num_params > 1) { /* different actions */ |
| 2518 |
if (resource.mouse_mode >= *num_params) { |
| 2519 |
size_t k; |
| 2520 |
XDVI_WARNING((stderr, "Only %d parameters in X resource 'mouse-modes', should be %d", |
| 2521 |
*num_params, resource.mouse_mode + 1)); |
| 2522 |
for (k = 0; k < *num_params; k++) { |
| 2523 |
XDVI_WARNING((stderr, "Param %d: `%s'", (int)(k + 1), params[k])); |
| 2524 |
} |
| 2525 |
return; |
| 2526 |
} |
| 2527 |
mode_idx = resource.mouse_mode; |
| 2528 |
} |
| 2529 |
|
| 2530 |
cached_compile_action(params[mode_idx], &my_action); |
| 2531 |
for (i = 0, ap = my_action; ap; ap = ap->next, i++) { |
| 2532 |
String *args; |
| 2533 |
String retval; |
| 2534 |
|
| 2535 |
TRACE_EVENTS((stderr, "Action %d for mode %lu: '%s', %d args |%s| maps to proc |%p|", |
| 2536 |
i, (unsigned long) mode_idx, ap->command, ap->num_params, |
| 2537 |
ap->num_params > 0 ? ap->params[0] : "(none)", |
| 2538 |
ap->proc)); |
| 2539 |
|
| 2540 |
/* copy args because the action proc may modify them (see below) */ |
| 2541 |
if (ap->num_params) { |
| 2542 |
args = xmalloc(ap->num_params * sizeof (String)); |
| 2543 |
memcpy(args, ap->params, ap->num_params * sizeof (String)); |
| 2544 |
} |
| 2545 |
else args = xmalloc(sizeof (String)); |
| 2546 |
|
| 2547 |
/* now call the action proc directly */ |
| 2548 |
XtCallActionProc(w, ap->command, event, args, ap->num_params); |
| 2549 |
|
| 2550 |
retval = args[0]; |
| 2551 |
free(args); |
| 2552 |
if (retval == Act_true_retval) { /* we may compare the pointers here */ |
| 2553 |
/* Special case: Only invoke first action, not subsequent ones; |
| 2554 |
* e.g. if mouse is over a link and action is Act_href or |
| 2555 |
* Act_href_newwindow (currently the only cases where this is used). |
| 2556 |
*/ |
| 2557 |
break; |
| 2558 |
} |
| 2559 |
} |
| 2560 |
} |
| 2561 |
|
| 2562 |
|
| 2563 |
void |
| 2564 |
Act_set_shrink_factor(Widget w, XEvent *event, |
| 2565 |
String *params, Cardinal *num_params) |
| 2566 |
{ |
| 2567 |
int arg; |
| 2568 |
/* Set a limit to the shrink factors allowed; otherwise xdvi may |
| 2569 |
consume a lot of memory (even run out of memory in malloc) in |
| 2570 |
the allocation for the subpixel lookup table pixeltbl, |
| 2571 |
dvi-draw.c. The `correct' solution would be to recognize that at a |
| 2572 |
certain shrink, the only pixel for a character will be always |
| 2573 |
set to `on' anyway, so that we could do without the lookup table for |
| 2574 |
very large shrink factors ... */ |
| 2575 |
static const int SHRINK_MAX = 999; |
| 2576 |
|
| 2577 |
UNUSED(w); |
| 2578 |
UNUSED(event); |
| 2579 |
|
| 2580 |
warn_num_params("set-shrink-factor()", params, *num_params, 1); |
| 2581 |
|
| 2582 |
if (*num_params > 0) { |
| 2583 |
if (**params == 'a') |
| 2584 |
arg = shrink_to_fit(); |
| 2585 |
else if (**params == '-') |
| 2586 |
arg = mane.shrinkfactor + 1; |
| 2587 |
else if (**params == '+') |
| 2588 |
arg = mane.shrinkfactor - 1; |
| 2589 |
else |
| 2590 |
arg = atoi(*params); |
| 2591 |
} |
| 2592 |
else if (!get_prefix_arg(&arg)) { |
| 2593 |
arg = shrink_to_fit(); |
| 2594 |
} |
| 2595 |
|
| 2596 |
if (arg <= 0) { |
| 2597 |
xdvi_bell(); |
| 2598 |
/* statusline_info(STATUS_SHORT, */ |
| 2599 |
/* "No more enlarging possible"); */ |
| 2600 |
return; |
| 2601 |
} |
| 2602 |
|
| 2603 |
if (arg > SHRINK_MAX) { |
| 2604 |
xdvi_bell(); |
| 2605 |
statusline_info(STATUS_SHORT, |
| 2606 |
"Shrink factor %d too large (maximum: %d)", arg, SHRINK_MAX); |
| 2607 |
return; |
| 2608 |
} |
| 2609 |
|
| 2610 |
/* SU: added clearing the window here, else old window content |
| 2611 |
will survive changing shrink |
| 2612 |
*/ |
| 2613 |
if (globals.pausing.flag) { |
| 2614 |
#if PS_GS |
| 2615 |
gs_erase_page(); |
| 2616 |
#endif |
| 2617 |
XClearWindow(DISP, mane.win); |
| 2618 |
} |
| 2619 |
|
| 2620 |
statusline_info(STATUS_SHORT, "shrink factor: %d", arg); |
| 2621 |
#if 0 |
| 2622 |
/* Uncommented this, otherwise selecting `shrink to fit' with same value as |
| 2623 |
current mane.shrinkfactor will clear the canvas (only fixed by changing shrink |
| 2624 |
factor again). That bug is also present in xdvik-22.48-alpha3. */ |
| 2625 |
if (arg == mane.shrinkfactor) { |
| 2626 |
return; |
| 2627 |
} |
| 2628 |
#endif |
| 2629 |
|
| 2630 |
do_set_shrinkfactor(arg, True); |
| 2631 |
|
| 2632 |
#if MOTIF |
| 2633 |
/* note: mustn't do that inside do_set_shrinkfactor(), |
| 2634 |
or we get into an endless loop! */ |
| 2635 |
update_preferences_shrink(); |
| 2636 |
#endif |
| 2637 |
} |
| 2638 |
|
| 2639 |
void |
| 2640 |
Act_shrink_to_dpi(Widget w, XEvent *event, |
| 2641 |
String *params, Cardinal *num_params) |
| 2642 |
{ |
| 2643 |
int arg; |
| 2644 |
|
| 2645 |
UNUSED(w); |
| 2646 |
UNUSED(event); |
| 2647 |
|
| 2648 |
warn_num_params("shrink-to-dpi()", params, *num_params, 1); |
| 2649 |
|
| 2650 |
if (!get_int_arg(params, num_params, &arg)) |
| 2651 |
arg = 0; |
| 2652 |
|
| 2653 |
if (arg > 0) |
| 2654 |
arg = (double)resource.pixels_per_inch / arg + 0.5; |
| 2655 |
|
| 2656 |
if (arg <= 0) { |
| 2657 |
xdvi_bell(); |
| 2658 |
statusline_info(STATUS_SHORT, |
| 2659 |
"shrink-to-dpi requires a positive argument"); |
| 2660 |
return; |
| 2661 |
} |
| 2662 |
|
| 2663 |
/* like elsewhere */ |
| 2664 |
if (globals.pausing.flag) { |
| 2665 |
#if PS_GS |
| 2666 |
gs_erase_page(); |
| 2667 |
#endif |
| 2668 |
XClearWindow(DISP, mane.win); |
| 2669 |
} |
| 2670 |
#if 0 |
| 2671 |
/* Uncommented this, otherwise selecting `shrink to fit' with same value as |
| 2672 |
current mane.shrinkfactor will clear the canvas (only fixed by changing shrink |
| 2673 |
factor again). That bug is also present in xdvik-22.48-alpha3. */ |
| 2674 |
if (arg == mane.shrinkfactor) |
| 2675 |
return; |
| 2676 |
#endif |
| 2677 |
do_set_shrinkfactor(arg, True); |
| 2678 |
|
| 2679 |
#if MOTIF |
| 2680 |
/* note: mustn't do that inside do_set_shrinkfactor(), |
| 2681 |
or we get into an endless loop! */ |
| 2682 |
update_preferences_shrink(); |
| 2683 |
#endif |
| 2684 |
} |
| 2685 |
|
| 2686 |
void |
| 2687 |
do_set_density(double newgamma, Boolean force, Boolean update_resource) |
| 2688 |
{ |
| 2689 |
|
| 2690 |
/* like elsewhere */ |
| 2691 |
if (globals.pausing.flag) { |
| 2692 |
XClearWindow(DISP, mane.win); |
| 2693 |
} |
| 2694 |
|
| 2695 |
#ifdef GREY |
| 2696 |
if (resource.use_grey) { |
| 2697 |
if (newgamma == resource.gamma && !force) { |
| 2698 |
statusline_info(STATUS_SHORT, "density value: %.3f", newgamma); |
| 2699 |
return; |
| 2700 |
} |
| 2701 |
resource.gamma = newgamma; |
| 2702 |
if (update_resource) |
| 2703 |
globals.curr_gamma = resource.gamma; |
| 2704 |
|
| 2705 |
#if COLOR |
| 2706 |
fg_active = NULL; |
| 2707 |
reset_colors(); |
| 2708 |
#else |
| 2709 |
init_pix(); |
| 2710 |
if (G_visual->class != TrueColor) { |
| 2711 |
return; |
| 2712 |
} |
| 2713 |
reset_fonts(); |
| 2714 |
#endif /* COLOR */ |
| 2715 |
statusline_info(STATUS_SHORT, "density value: %.3f", newgamma); |
| 2716 |
} else |
| 2717 |
#endif /* GREY */ |
| 2718 |
{ |
| 2719 |
reset_fonts(); |
| 2720 |
if (mane.shrinkfactor == 1) { |
| 2721 |
statusline_info(STATUS_SHORT, |
| 2722 |
"set-density ignored at magnification 1"); |
| 2723 |
return; |
| 2724 |
} |
| 2725 |
statusline_info(STATUS_SHORT, "density value: %.3f", newgamma); |
| 2726 |
} |
| 2727 |
|
| 2728 |
store_preference(NULL, "gamma", "%f", resource.gamma); |
| 2729 |
|
| 2730 |
globals.ev.flags |= EV_NEWPAGE; |
| 2731 |
XFlush(DISP); |
| 2732 |
} |
| 2733 |
|
| 2734 |
static void |
| 2735 |
Act_set_density(Widget w, XEvent *event, |
| 2736 |
String *params, Cardinal *num_params) |
| 2737 |
{ |
| 2738 |
int arg; |
| 2739 |
|
| 2740 |
UNUSED(w); |
| 2741 |
UNUSED(event); |
| 2742 |
|
| 2743 |
warn_num_params("set-density()", params, *num_params, 1); |
| 2744 |
|
| 2745 |
if (!get_int_arg(params, num_params, &arg)) { |
| 2746 |
xdvi_bell(); |
| 2747 |
return; |
| 2748 |
} |
| 2749 |
/* if (arg < 0) { */ |
| 2750 |
/* XBell(DISP, 0); */ |
| 2751 |
/* statusline_info(STATUS_SHORT, */ |
| 2752 |
/* "set-density requires a positive value"); */ |
| 2753 |
/* return; */ |
| 2754 |
/* } */ |
| 2755 |
do_set_density(arg != 0 ? arg / 100.0 : 1.0, False, True); |
| 2756 |
#if MOTIF |
| 2757 |
update_preferences_darkness(); |
| 2758 |
#else |
| 2759 |
store_preference(NULL, "gamma", "%f", resource.gamma); |
| 2760 |
#endif |
| 2761 |
} |
| 2762 |
|
| 2763 |
|
| 2764 |
static void |
| 2765 |
Act_change_density(Widget w, XEvent *event, |
| 2766 |
String *params, Cardinal *num_params) |
| 2767 |
{ |
| 2768 |
int arg; |
| 2769 |
double diff; |
| 2770 |
double oldgamma = resource.gamma; |
| 2771 |
UNUSED(w); |
| 2772 |
UNUSED(event); |
| 2773 |
|
| 2774 |
warn_num_params("change-density()", params, *num_params, 1); |
| 2775 |
|
| 2776 |
if (!get_int_arg(params, num_params, &arg)) { |
| 2777 |
xdvi_bell(); |
| 2778 |
return; |
| 2779 |
} |
| 2780 |
diff = oldgamma / arg; |
| 2781 |
if (oldgamma + diff <= 0.0) |
| 2782 |
oldgamma = 0.0; |
| 2783 |
else |
| 2784 |
oldgamma += diff; |
| 2785 |
do_set_density(oldgamma, False, True); |
| 2786 |
#if MOTIF |
| 2787 |
update_preferences_darkness(); |
| 2788 |
#endif |
| 2789 |
} |
| 2790 |
|
| 2791 |
static void h_restore_scroll_position(int orig_pos, |
| 2792 |
#ifndef MOTIF |
| 2793 |
Dimension *get_pos, |
| 2794 |
#endif |
| 2795 |
Widget scrollbar) |
| 2796 |
{ |
| 2797 |
if (resource.keep_flag && orig_pos != 0 && scrollbar != NULL) { |
| 2798 |
#ifdef MOTIF |
| 2799 |
if (!resource.fullscreen) { |
| 2800 |
/* only scroll back in non-fullscreen mode */ |
| 2801 |
(void)set_bar_value(scrollbar, orig_pos, INT_MAX); |
| 2802 |
} |
| 2803 |
#else |
| 2804 |
int curr_pos; |
| 2805 |
get_xy(); |
| 2806 |
XtVaGetValues(globals.widgets.clip_widget, XtNx, get_pos, NULL); |
| 2807 |
curr_pos = -((*get_pos) - m_window_x); |
| 2808 |
if (curr_pos - orig_pos > 0) { |
| 2809 |
XtCallCallbacks(scrollbar, XtNscrollProc, cast_int_to_XtPointer(curr_pos - orig_pos)); |
| 2810 |
} |
| 2811 |
#endif /* MOTIF */ |
| 2812 |
} |
| 2813 |
} |
| 2814 |
|
| 2815 |
static void |
| 2816 |
Act_fullscreen(Widget w, XEvent *event, |
| 2817 |
String *params, Cardinal *num_params) |
| 2818 |
{ |
| 2819 |
Dimension main_win_w, main_win_h; |
| 2820 |
static int orig_x = 0, orig_y = 0; |
| 2821 |
#ifndef MOTIF |
| 2822 |
static Dimension get_x, get_y; |
| 2823 |
#endif |
| 2824 |
static Dimension old_w = 0, old_h = 0; |
| 2825 |
Dimension panel_width = 0; |
| 2826 |
#if 0 |
| 2827 |
static Dimension w_old = 0, h_old = 0; |
| 2828 |
#endif |
| 2829 |
|
| 2830 |
UNUSED(w); |
| 2831 |
UNUSED(event); |
| 2832 |
|
| 2833 |
if (!toggle_arg(resource.fullscreen, params, num_params)) { |
| 2834 |
return; |
| 2835 |
} |
| 2836 |
|
| 2837 |
resource.fullscreen = !resource.fullscreen; |
| 2838 |
|
| 2839 |
#ifndef MOTIF |
| 2840 |
panel_width = get_panel_width(); |
| 2841 |
#endif |
| 2842 |
|
| 2843 |
if (resource.fullscreen) { |
| 2844 |
/* when toggling to fullscreen, save current scrollbar values |
| 2845 |
and window geometry */ |
| 2846 |
XtVaGetValues(globals.widgets.top_level, XtNwidth, &old_w, XtNheight, &old_h, NULL); |
| 2847 |
/* fprintf(stderr, "saved geometry: %dx%d\n", old_w, old_h); */ |
| 2848 |
#ifdef MOTIF |
| 2849 |
if (globals.widgets.x_bar != NULL) |
| 2850 |
XtVaGetValues(globals.widgets.x_bar, XmNvalue, &orig_x, NULL); |
| 2851 |
if (globals.widgets.y_bar != NULL) |
| 2852 |
XtVaGetValues(globals.widgets.y_bar, XmNvalue, &orig_y, NULL); |
| 2853 |
#else |
| 2854 |
get_xy(); |
| 2855 |
if (globals.widgets.x_bar != NULL) |
| 2856 |
XtVaGetValues(globals.widgets.clip_widget, XtNx, &get_x, NULL); |
| 2857 |
if (globals.widgets.y_bar != NULL) |
| 2858 |
XtVaGetValues(globals.widgets.clip_widget, XtNy, &get_y, NULL); |
| 2859 |
orig_x = -(get_x - m_window_x); |
| 2860 |
orig_y = -(get_y - m_window_y); |
| 2861 |
#endif /* MOTIF */ |
| 2862 |
/* fprintf(stderr, "Current offsets: %d, %d, %d, %d\n", orig_x, m_window_x, orig_y, m_window_y); */ |
| 2863 |
} |
| 2864 |
if (resource.fullscreen) { |
| 2865 |
set_windowsize(&main_win_w, &main_win_h, panel_width, 0, False); |
| 2866 |
} |
| 2867 |
else { /* re-use old window sizes, or initialize them if started in fullscreen mode */ |
| 2868 |
if (old_w == 0 || old_h == 0) /* started in fullscreen mode */ |
| 2869 |
set_windowsize(&old_w, &old_h, panel_width, 0, False); |
| 2870 |
else |
| 2871 |
set_windowsize(&old_w, &old_h, panel_width, 0, True); |
| 2872 |
} |
| 2873 |
|
| 2874 |
/* fprintf(stderr, "reconfigure window!\n"); */ |
| 2875 |
if (resource.fullscreen) |
| 2876 |
reconfigure_window(resource.fullscreen, main_win_w, main_win_h, True); |
| 2877 |
else { |
| 2878 |
reconfigure_window(resource.fullscreen, old_w, old_h, True); |
| 2879 |
} |
| 2880 |
|
| 2881 |
/* restore horizontal/vertical scroll positions */ |
| 2882 |
h_restore_scroll_position(orig_x, |
| 2883 |
#ifndef MOTIF |
| 2884 |
&get_x, |
| 2885 |
#endif |
| 2886 |
globals.widgets.x_bar); |
| 2887 |
h_restore_scroll_position(orig_y, |
| 2888 |
#ifndef MOTIF |
| 2889 |
&get_y, |
| 2890 |
#endif |
| 2891 |
globals.widgets.y_bar); |
| 2892 |
|
| 2893 |
#ifdef USE_PANNER |
| 2894 |
handle_x_scroll(NULL, NULL, NULL, NULL); |
| 2895 |
handle_y_scroll(NULL, NULL, NULL, NULL); |
| 2896 |
#endif |
| 2897 |
} |
| 2898 |
|
| 2899 |
#ifdef GREY |
| 2900 |
|
| 2901 |
static void |
| 2902 |
Act_set_greyscaling(Widget w, XEvent *event, |
| 2903 |
String *params, Cardinal *num_params) |
| 2904 |
{ |
| 2905 |
int arg; |
| 2906 |
|
| 2907 |
UNUSED(w); |
| 2908 |
UNUSED(event); |
| 2909 |
|
| 2910 |
warn_num_params("set-greyscaling()", params, *num_params, 1); |
| 2911 |
|
| 2912 |
if (!get_int_arg(params, num_params, &arg)) { /* no arg, toggle */ |
| 2913 |
if (!toggle_arg(resource.use_grey, params, num_params)) { |
| 2914 |
return; |
| 2915 |
} |
| 2916 |
resource.use_grey = !resource.use_grey; |
| 2917 |
if (resource.use_grey) { |
| 2918 |
statusline_info(STATUS_SHORT, "greyscaling on"); |
| 2919 |
} |
| 2920 |
else { |
| 2921 |
statusline_info(STATUS_SHORT, "greyscaling off"); |
| 2922 |
} |
| 2923 |
globals.ev.flags |= EV_NEWPAGE; |
| 2924 |
XFlush(DISP); |
| 2925 |
return; |
| 2926 |
} |
| 2927 |
|
| 2928 |
switch (arg) { |
| 2929 |
case 0: |
| 2930 |
resource.use_grey = False; |
| 2931 |
statusline_info(STATUS_SHORT, "greyscaling off"); |
| 2932 |
break; |
| 2933 |
case 1: |
| 2934 |
resource.use_grey = True; |
| 2935 |
statusline_info(STATUS_SHORT, "greyscaling on"); |
| 2936 |
break; |
| 2937 |
default: |
| 2938 |
{ |
| 2939 |
float newgamma = arg != 0 ? arg / 100.0 : 1.0; |
| 2940 |
resource.use_grey = newgamma; |
| 2941 |
statusline_info(STATUS_SHORT, "greyscale value: %.1f", newgamma); |
| 2942 |
} |
| 2943 |
} |
| 2944 |
|
| 2945 |
/* like elsewhere */ |
| 2946 |
if (globals.pausing.flag) { |
| 2947 |
XClearWindow(DISP, mane.win); |
| 2948 |
} |
| 2949 |
|
| 2950 |
if (resource.use_grey) { |
| 2951 |
if (G_visual->class != TrueColor) |
| 2952 |
init_plane_masks(); |
| 2953 |
#if COLOR |
| 2954 |
fg_active = NULL; |
| 2955 |
#else |
| 2956 |
init_pix(); |
| 2957 |
#endif |
| 2958 |
} |
| 2959 |
reset_fonts(); |
| 2960 |
globals.ev.flags |= EV_NEWPAGE; |
| 2961 |
XFlush(DISP); |
| 2962 |
} |
| 2963 |
|
| 2964 |
#endif |
| 2965 |
|
| 2966 |
#if COLOR |
| 2967 |
|
| 2968 |
void |
| 2969 |
do_toggle_color(Boolean update_resource) |
| 2970 |
{ |
| 2971 |
if (resource.use_color) { |
| 2972 |
resource.use_color = False; |
| 2973 |
full_reset_colors(); |
| 2974 |
scanned_page_color = total_pages; |
| 2975 |
#if PS |
| 2976 |
if (ignore_papersize_specials || scanned_page_ps <= total_pages) { |
| 2977 |
scanned_page = scanned_page_ps; |
| 2978 |
} |
| 2979 |
#endif |
| 2980 |
statusline_info(STATUS_SHORT, "color specials off"); |
| 2981 |
} |
| 2982 |
else { |
| 2983 |
resource.use_color = True; |
| 2984 |
scanned_page = scanned_page_color = scanned_page_reset; |
| 2985 |
statusline_info(STATUS_SHORT, "color specials on"); |
| 2986 |
} |
| 2987 |
if (update_resource) |
| 2988 |
globals.curr_use_color = resource.use_color; |
| 2989 |
|
| 2990 |
#ifdef MOTIF |
| 2991 |
update_preferences_color(); |
| 2992 |
#endif |
| 2993 |
globals.ev.flags |= EV_NEWPAGE; |
| 2994 |
} |
| 2995 |
|
| 2996 |
static void |
| 2997 |
Act_set_color(Widget w, XEvent *event, |
| 2998 |
String *params, Cardinal *num_params) |
| 2999 |
{ |
| 3000 |
UNUSED(w); |
| 3001 |
UNUSED(event); |
| 3002 |
|
| 3003 |
if (!toggle_arg(resource.use_color, params, num_params)) { |
| 3004 |
return; |
| 3005 |
}; |
| 3006 |
|
| 3007 |
/* like elsewhere */ |
| 3008 |
if (globals.pausing.flag) { |
| 3009 |
XClearWindow(DISP, mane.win); |
| 3010 |
} |
| 3011 |
|
| 3012 |
do_toggle_color(True); |
| 3013 |
} |
| 3014 |
|
| 3015 |
#endif /* COLOR */ |
| 3016 |
|
| 3017 |
#if PS |
| 3018 |
|
| 3019 |
void |
| 3020 |
Act_set_ps(Widget w, XEvent *event, |
| 3021 |
String *params, Cardinal *num_params) |
| 3022 |
{ |
| 3023 |
int arg; |
| 3024 |
|
| 3025 |
UNUSED(event); |
| 3026 |
UNUSED(w); |
| 3027 |
|
| 3028 |
if (!get_int_arg(params, num_params, &arg)) |
| 3029 |
resource.postscript++; |
| 3030 |
else |
| 3031 |
resource.postscript = arg; |
| 3032 |
|
| 3033 |
if (resource.postscript > 2) |
| 3034 |
resource.postscript = 0; |
| 3035 |
|
| 3036 |
#ifdef PS_GS |
| 3037 |
if (!resource.useGS) { |
| 3038 |
if (resource.postscript > 0) { |
| 3039 |
popup_message(globals.widgets.top_level, |
| 3040 |
MSG_WARN, |
| 3041 |
"This version of xdvi depends on ghostscript for rendering Postscript images. " |
| 3042 |
"Postscript rendering cannot be activated if the option ``-noghostscript'' is used " |
| 3043 |
"or if the resource ``Ghostscript'' is set to false.", |
| 3044 |
/* message */ |
| 3045 |
"Option ``-noghostscript'' is active; " |
| 3046 |
"cannot enable Postscript rendering without ghostscript."); |
| 3047 |
} |
| 3048 |
resource.postscript = 0; |
| 3049 |
} |
| 3050 |
#endif |
| 3051 |
if (resource.postscript > 0) { |
| 3052 |
scanned_page_ps = scanned_page_ps_bak; |
| 3053 |
if (scanned_page > scanned_page_ps) |
| 3054 |
scanned_page = scanned_page_ps; |
| 3055 |
if (resource.postscript == 1) { |
| 3056 |
statusline_info(STATUS_SHORT, "Postscript rendering on"); |
| 3057 |
} |
| 3058 |
else { |
| 3059 |
statusline_info(STATUS_SHORT, "Postscript rendering on (with bounding box)"); |
| 3060 |
} |
| 3061 |
} |
| 3062 |
else { |
| 3063 |
scanned_page_ps_bak = scanned_page_ps; |
| 3064 |
scanned_page_ps = total_pages; |
| 3065 |
#if COLOR |
| 3066 |
if (ignore_papersize_specials || scanned_page_color <= total_pages) { |
| 3067 |
scanned_page = scanned_page_color; |
| 3068 |
} |
| 3069 |
#endif |
| 3070 |
statusline_info(STATUS_SHORT, "Postscript rendering off; displaying bounding box instead"); |
| 3071 |
} |
| 3072 |
|
| 3073 |
store_preference(NULL, "postscript", "%d", resource.postscript); |
| 3074 |
|
| 3075 |
psp.toggle(resource.postscript); |
| 3076 |
|
| 3077 |
set_menu(&resource.postscript, Act_set_ps, check_int); |
| 3078 |
|
| 3079 |
/* like elsewhere */ |
| 3080 |
if (globals.pausing.flag) { |
| 3081 |
XClearWindow(DISP, mane.win); |
| 3082 |
} |
| 3083 |
|
| 3084 |
globals.ev.flags |= EV_PS_TOGGLE; |
| 3085 |
XFlush(DISP); |
| 3086 |
} |
| 3087 |
|
| 3088 |
#endif /* PS */ |
| 3089 |
|
| 3090 |
void |
| 3091 |
Act_htex_back(Widget w, XEvent *event, |
| 3092 |
String *params, Cardinal *num_params) |
| 3093 |
{ |
| 3094 |
UNUSED(w); |
| 3095 |
UNUSED(event); |
| 3096 |
UNUSED(params); |
| 3097 |
UNUSED(num_params); |
| 3098 |
|
| 3099 |
htex_back(); |
| 3100 |
} |
| 3101 |
|
| 3102 |
void |
| 3103 |
Act_htex_forward(Widget w, XEvent *event, |
| 3104 |
String *params, Cardinal *num_params) |
| 3105 |
{ |
| 3106 |
UNUSED(w); |
| 3107 |
UNUSED(event); |
| 3108 |
UNUSED(params); |
| 3109 |
UNUSED(num_params); |
| 3110 |
|
| 3111 |
htex_forward(); |
| 3112 |
} |
| 3113 |
|
| 3114 |
static void |
| 3115 |
Act_htex_anchorinfo(Widget w, XEvent *event, |
| 3116 |
String *params, Cardinal *num_params) |
| 3117 |
{ |
| 3118 |
int x, y; |
| 3119 |
Window dummy; |
| 3120 |
|
| 3121 |
UNUSED(w); |
| 3122 |
UNUSED(params); |
| 3123 |
UNUSED(num_params); |
| 3124 |
|
| 3125 |
(void)XTranslateCoordinates(DISP, event->xkey.window, mane.win, |
| 3126 |
event->xkey.x, event->xkey.y, &x, &y, &dummy); |
| 3127 |
htex_displayanchor(x, y); |
| 3128 |
} |
| 3129 |
|
| 3130 |
#ifdef PS_GS |
| 3131 |
void |
| 3132 |
Act_set_gs_alpha(Widget w, XEvent *event, |
| 3133 |
String *params, Cardinal *num_params) |
| 3134 |
{ |
| 3135 |
UNUSED(w); |
| 3136 |
UNUSED(event); |
| 3137 |
|
| 3138 |
if (!toggle_arg(resource.gs_alpha, params, num_params)) { |
| 3139 |
return; |
| 3140 |
} |
| 3141 |
resource.gs_alpha = !resource.gs_alpha; |
| 3142 |
|
| 3143 |
if (resource.gs_alpha) { |
| 3144 |
statusline_info(STATUS_SHORT, "ghostscript alpha active"); |
| 3145 |
} |
| 3146 |
else { |
| 3147 |
statusline_info(STATUS_SHORT, "ghostscript alpha inactive"); |
| 3148 |
} |
| 3149 |
|
| 3150 |
store_preference(NULL, "gsAlpha", "%s", resource.gs_alpha ? "True" : "False"); |
| 3151 |
|
| 3152 |
set_menu(&resource.gs_alpha, Act_set_gs_alpha, check_toggle); |
| 3153 |
|
| 3154 |
/* like elsewhere */ |
| 3155 |
if (globals.pausing.flag) { |
| 3156 |
#if PS_GS |
| 3157 |
gs_erase_page(); |
| 3158 |
#endif |
| 3159 |
XClearWindow(DISP, mane.win); |
| 3160 |
} |
| 3161 |
|
| 3162 |
globals.ev.flags |= EV_PS_TOGGLE; |
| 3163 |
XFlush(DISP); |
| 3164 |
} |
| 3165 |
#endif |
| 3166 |
|
| 3167 |
static void |
| 3168 |
Act_reread_dvi_file(Widget w, XEvent *event, |
| 3169 |
String *params, Cardinal *num_params) |
| 3170 |
{ |
| 3171 |
UNUSED(w); |
| 3172 |
UNUSED(event); |
| 3173 |
UNUSED(params); |
| 3174 |
UNUSED(num_params); |
| 3175 |
|
| 3176 |
/* fprintf(stderr, "reread file!\n"); */ |
| 3177 |
globals.ev.flags |= EV_RELOAD; |
| 3178 |
} |
| 3179 |
|
| 3180 |
static void |
| 3181 |
Act_discard_number(Widget w, XEvent *event, |
| 3182 |
String *params, Cardinal *num_params) |
| 3183 |
{ |
| 3184 |
UNUSED(w); |
| 3185 |
UNUSED(event); |
| 3186 |
UNUSED(params); |
| 3187 |
UNUSED(num_params); |
| 3188 |
|
| 3189 |
m_have_arg = False; |
| 3190 |
m_number = 0; |
| 3191 |
m_sign = 1; |
| 3192 |
|
| 3193 |
statusline_info(STATUS_SHORT, "numerical prefix discarded"); |
| 3194 |
} |
| 3195 |
|
| 3196 |
/* |
| 3197 |
* Actions to support dragging the image. |
| 3198 |
*/ |
| 3199 |
|
| 3200 |
static int drag_last_x, drag_last_y; /* last position of cursor */ |
| 3201 |
|
| 3202 |
static int text_last_x = -1; |
| 3203 |
static int text_last_y = -1; |
| 3204 |
static int text_last_page = -1; |
| 3205 |
|
| 3206 |
static void drag_motion(XEvent *); |
| 3207 |
static void drag_release(XEvent *); |
| 3208 |
|
| 3209 |
static void |
| 3210 |
text_release(XEvent * event) |
| 3211 |
{ |
| 3212 |
int ulx, uly, w, h; |
| 3213 |
static char *text; |
| 3214 |
int text_len = 0; |
| 3215 |
|
| 3216 |
UNUSED(event); |
| 3217 |
|
| 3218 |
MYTRACE((stderr, "text_release!\n")); |
| 3219 |
|
| 3220 |
if (mouse_motion == null_mouse) |
| 3221 |
return; |
| 3222 |
mouse_motion = mouse_release = null_mouse; |
| 3223 |
|
| 3224 |
w = text_last_x - drag_last_x; |
| 3225 |
h = text_last_y - drag_last_y; |
| 3226 |
|
| 3227 |
if (w == 0 || h == 0) { |
| 3228 |
text_last_x = text_last_y = -1; |
| 3229 |
drag_last_x = drag_last_y = -1; |
| 3230 |
text_last_page = -1; |
| 3231 |
return; |
| 3232 |
} |
| 3233 |
|
| 3234 |
if (w < 0) { |
| 3235 |
ulx = drag_last_x + w; |
| 3236 |
w = -w; |
| 3237 |
} |
| 3238 |
else |
| 3239 |
ulx = drag_last_x; |
| 3240 |
|
| 3241 |
if (h < 0) { |
| 3242 |
uly = drag_last_y + h; |
| 3243 |
h = -h; |
| 3244 |
} |
| 3245 |
else |
| 3246 |
uly = drag_last_y; |
| 3247 |
|
| 3248 |
free(text); |
| 3249 |
/* this allocates text */ |
| 3250 |
text = get_text_selection(&text_len, |
| 3251 |
ulx * currwin.shrinkfactor, |
| 3252 |
uly * currwin.shrinkfactor, |
| 3253 |
(ulx + w) * currwin.shrinkfactor, |
| 3254 |
(uly + h) * currwin.shrinkfactor); |
| 3255 |
if (text[0] == '\0') { |
| 3256 |
/* fprintf(stdout, "Text selection empty.\n"); */ |
| 3257 |
return; |
| 3258 |
} |
| 3259 |
|
| 3260 |
TRACE_GUI((stderr, "Selected `%s'", text)); |
| 3261 |
|
| 3262 |
if (text_len > 4 * XMaxRequestSize(DISP) - 32) { |
| 3263 |
xdvi_bell(); |
| 3264 |
statusline_error(STATUS_MEDIUM, "Selection too large (%d bytes, maximum %d bytes)", |
| 3265 |
text_len, 4 * XMaxRequestSize(DISP) - 32); |
| 3266 |
return; |
| 3267 |
} |
| 3268 |
|
| 3269 |
if (!set_selection(text, globals.widgets.top_level)) { |
| 3270 |
xdvi_bell(); |
| 3271 |
statusline_error(STATUS_MEDIUM, "Could not set primary selection!"); |
| 3272 |
text_change_region(TEXT_SEL_CLEAR, NULL); |
| 3273 |
} |
| 3274 |
} |
| 3275 |
|
| 3276 |
void |
| 3277 |
text_motion(XEvent *event) |
| 3278 |
{ |
| 3279 |
MYTRACE((stderr, "motion!\n")); |
| 3280 |
text_change_region(TEXT_SEL_MOVE, event); |
| 3281 |
} |
| 3282 |
|
| 3283 |
static void |
| 3284 |
get_rectangle(XRectangle *rect, int x, int y, int last_x, int last_y) |
| 3285 |
{ |
| 3286 |
rect->width = ABS(x - last_x); |
| 3287 |
rect->height = ABS(y - last_y); |
| 3288 |
rect->x = (x < last_x) ? x : last_x; |
| 3289 |
rect->y = (y < last_y) ? y : last_y; |
| 3290 |
} |
| 3291 |
|
| 3292 |
static void |
| 3293 |
crop_to_window(int *x, int *y) |
| 3294 |
{ |
| 3295 |
if (*x < -currwin.base_x + 1) |
| 3296 |
*x = -currwin.base_x + 1; |
| 3297 |
else if (*x > -currwin.base_x + (int)ROUNDUP(pageinfo_get_page_width(current_page), currwin.shrinkfactor) + 1) |
| 3298 |
*x = -currwin.base_x + ROUNDUP(pageinfo_get_page_width(current_page), currwin.shrinkfactor) + 1; |
| 3299 |
|
| 3300 |
if (*y < -currwin.base_y + 1) |
| 3301 |
*y = -currwin.base_y + 1; |
| 3302 |
else if (*y > -currwin.base_y + (int)ROUNDUP(pageinfo_get_page_height(current_page), currwin.shrinkfactor) + 1) |
| 3303 |
*y = -currwin.base_y + (int)ROUNDUP(pageinfo_get_page_height(current_page), currwin.shrinkfactor) + 1; |
| 3304 |
} |
| 3305 |
|
| 3306 |
void |
| 3307 |
text_change_region(textSelectionT mode, XEvent *event) |
| 3308 |
{ |
| 3309 |
static GC bboxGC = 0; |
| 3310 |
static GC redrawGC = 0; /* needed since bboxGC is clipped to diff of old and new region */ |
| 3311 |
|
| 3312 |
if (bboxGC == 0) { |
| 3313 |
XGCValues values; |
| 3314 |
unsigned long valuemask; |
| 3315 |
|
| 3316 |
values.function = GXinvert; /* as in search code */ |
| 3317 |
if (values.function == GXinvert) { |
| 3318 |
valuemask = GCFunction; |
| 3319 |
} |
| 3320 |
else { |
| 3321 |
values.foreground = WhitePixelOfScreen(SCRN) ^ BlackPixelOfScreen(SCRN); |
| 3322 |
/* fprintf(stderr, "foreground: 0x%lx, white pixel: 0x%lx, black pixel: 0x%lx\n", */ |
| 3323 |
/* values.foreground, WhitePixelOfScreen(SCRN), BlackPixelOfScreen(SCRN)); */ |
| 3324 |
valuemask = GCFunction | GCForeground; |
| 3325 |
} |
| 3326 |
values.line_width = 1; |
| 3327 |
valuemask |= GCLineWidth; |
| 3328 |
bboxGC = XCreateGC(DISP, XtWindow(globals.widgets.top_level), valuemask, &values); |
| 3329 |
redrawGC = XCreateGC(DISP, XtWindow(globals.widgets.top_level), valuemask, &values); |
| 3330 |
} |
| 3331 |
|
| 3332 |
MYTRACE((stderr, "mode: %d\n", mode)); |
| 3333 |
switch (mode) { |
| 3334 |
case TEXT_SEL_MOVE: |
| 3335 |
{ |
| 3336 |
int x, y; |
| 3337 |
|
| 3338 |
Window dummy; |
| 3339 |
|
| 3340 |
XRectangle redraw = { -1, -1, 0, 0 }; |
| 3341 |
|
| 3342 |
ASSERT(event != NULL, "event in text_change_region() musn't be NULL for TEXT_SEL_MOVE"); |
| 3343 |
|
| 3344 |
(void)XTranslateCoordinates(DISP, event->xkey.window, mane.win, |
| 3345 |
event->xkey.x, event->xkey.y, |
| 3346 |
&x, &y, |
| 3347 |
&dummy); |
| 3348 |
|
| 3349 |
crop_to_window(&x, &y); |
| 3350 |
|
| 3351 |
get_rectangle(&redraw, x, y, drag_last_x, drag_last_y); |
| 3352 |
|
| 3353 |
/* |
| 3354 |
* If we have an old region, we want to clip the GC to the area: |
| 3355 |
* |
| 3356 |
* (clip \cup redraw) - (clip \cap redraw) |
| 3357 |
* |
| 3358 |
* and redraw both rectangle areas; otherwise, just draw the redraw area. |
| 3359 |
*/ |
| 3360 |
|
| 3361 |
if (text_last_x != -1 && text_last_y != -1) { |
| 3362 |
|
| 3363 |
XRectangle clip = { -1, -1, 0, 0 }; |
| 3364 |
|
| 3365 |
Region clip_region = XCreateRegion(); |
| 3366 |
Region redraw_region = XCreateRegion(); |
| 3367 |
Region union_region = XCreateRegion(); |
| 3368 |
Region intersect_region = XCreateRegion(); |
| 3369 |
|
| 3370 |
get_rectangle(&clip, text_last_x, text_last_y, drag_last_x, drag_last_y); |
| 3371 |
|
| 3372 |
XUnionRectWithRegion(&clip, clip_region, clip_region); |
| 3373 |
XUnionRectWithRegion(&redraw, redraw_region, redraw_region); |
| 3374 |
|
| 3375 |
XUnionRegion(clip_region, redraw_region, union_region); |
| 3376 |
XIntersectRegion(clip_region, redraw_region, intersect_region); |
| 3377 |
|
| 3378 |
XSubtractRegion(union_region, intersect_region, redraw_region); |
| 3379 |
|
| 3380 |
XSetRegion(DISP, bboxGC, redraw_region); |
| 3381 |
|
| 3382 |
XDestroyRegion(clip_region); |
| 3383 |
XDestroyRegion(redraw_region); |
| 3384 |
XDestroyRegion(union_region); |
| 3385 |
XDestroyRegion(intersect_region); |
| 3386 |
|
| 3387 |
XFillRectangle(DISP, mane.win, bboxGC, clip.x, clip.y, clip.width, clip.height); |
| 3388 |
} |
| 3389 |
|
| 3390 |
XFillRectangle(DISP, mane.win, bboxGC, redraw.x, redraw.y, redraw.width, redraw.height); |
| 3391 |
|
| 3392 |
text_last_x = x; |
| 3393 |
text_last_y = y; |
| 3394 |
text_last_page = current_page; |
| 3395 |
} |
| 3396 |
break; |
| 3397 |
case TEXT_SEL_CLEAR: |
| 3398 |
unset_selection(globals.widgets.top_level); |
| 3399 |
case TEXT_SEL_ERASE: |
| 3400 |
case TEXT_SEL_REDRAW: |
| 3401 |
if (text_last_page == current_page |
| 3402 |
&& text_last_x != -1 && text_last_y != -1 |
| 3403 |
&& drag_last_x != -1 && drag_last_y != -1) { |
| 3404 |
|
| 3405 |
XRectangle clear = { -1, -1, 0, 0 }; |
| 3406 |
|
| 3407 |
get_rectangle(&clear, text_last_x, text_last_y, drag_last_x, drag_last_y); |
| 3408 |
|
| 3409 |
if (mode == TEXT_SEL_CLEAR) { |
| 3410 |
text_last_x = text_last_y = drag_last_x = drag_last_y = -1; |
| 3411 |
text_last_page = -1; |
| 3412 |
/* Note ZLB: the region is erased instead of inverted to avoid |
| 3413 |
* multiple inverting problem. An exposure is generated to |
| 3414 |
* make the region redrawn */ |
| 3415 |
clearexpose(&mane, clear.x, clear.y, clear.width, clear.height); |
| 3416 |
} |
| 3417 |
else if (clip_region_to_rect(&clear)) { |
| 3418 |
if (mode == TEXT_SEL_ERASE) { |
| 3419 |
/* If width or height are 0, XClearArea will clear entire window |
| 3420 |
* from coordinates x, y, so check for that: */ |
| 3421 |
if (clear.width > 0 && clear.height > 0) |
| 3422 |
XClearArea(DISP, mane.win, clear.x, clear.y, clear.width, clear.height, False); |
| 3423 |
} |
| 3424 |
else |
| 3425 |
XFillRectangle(DISP, mane.win, redrawGC, clear.x, clear.y, clear.width, clear.height); |
| 3426 |
} |
| 3427 |
} |
| 3428 |
break; |
| 3429 |
} |
| 3430 |
} |
| 3431 |
|
| 3432 |
void |
| 3433 |
text_selection_start(XEvent *event) |
| 3434 |
{ |
| 3435 |
int x, y; |
| 3436 |
Window dummy; |
| 3437 |
|
| 3438 |
/* erase existing region */ |
| 3439 |
text_change_region(TEXT_SEL_CLEAR, NULL); |
| 3440 |
|
| 3441 |
(void)XTranslateCoordinates(DISP, event->xkey.window, mane.win, |
| 3442 |
event->xkey.x, event->xkey.y, |
| 3443 |
&x, &y, |
| 3444 |
&dummy); /* throw away last argument */ |
| 3445 |
|
| 3446 |
crop_to_window(&x, &y); |
| 3447 |
|
| 3448 |
drag_last_x = x; |
| 3449 |
drag_last_y = y; |
| 3450 |
|
| 3451 |
text_last_x = text_last_y = -1; |
| 3452 |
|
| 3453 |
MYTRACE((stderr, "selection start; mouse_release: %p; null: %p!\n", mouse_release, null_mouse)); |
| 3454 |
if (mouse_release == null_mouse) { |
| 3455 |
MYTRACE((stderr, "init text_motion!\n")); |
| 3456 |
mouse_motion = text_motion; |
| 3457 |
mouse_release = text_release; |
| 3458 |
} |
| 3459 |
/* resource.mouse_mode_text_selection_active = True; */ |
| 3460 |
} |
| 3461 |
|
| 3462 |
void |
| 3463 |
Act_switch_mode(Widget w, XEvent *event, |
| 3464 |
String *params, Cardinal *num_params) |
| 3465 |
{ |
| 3466 |
/* mouseModeT prev_mode = resource.mouse_mode; */ |
| 3467 |
int arg = -1; |
| 3468 |
/* char *ptr; */ |
| 3469 |
const char *mode_name = NULL; |
| 3470 |
const char *mode_description = NULL; |
| 3471 |
/* XEvent ev; */ |
| 3472 |
|
| 3473 |
/* if called the first time from main(), this is only used |
| 3474 |
* to initialize the menu according to the mode. |
| 3475 |
*/ |
| 3476 |
Boolean initialization = (w == globals.widgets.top_level); |
| 3477 |
|
| 3478 |
UNUSED(event); |
| 3479 |
|
| 3480 |
if (get_int_arg(params, num_params, &arg)) { |
| 3481 |
if (arg < MOUSE_MODE1 || arg >= MOUSE_MODE_MAX) { |
| 3482 |
statusline_info(STATUS_SHORT, "Argument for Act_switch_mode outside of range from %d to %d", |
| 3483 |
MOUSE_MODE1, MOUSE_MODE_MAX - 1); |
| 3484 |
resource.mouse_mode++; |
| 3485 |
} |
| 3486 |
else |
| 3487 |
resource.mouse_mode = (mouseModeT)arg; |
| 3488 |
} |
| 3489 |
else |
| 3490 |
resource.mouse_mode++; |
| 3491 |
|
| 3492 |
/* check if wrapped */ |
| 3493 |
if (resource.mouse_mode >= MOUSE_MODE_MAX) |
| 3494 |
resource.mouse_mode = MOUSE_MODE1; |
| 3495 |
|
| 3496 |
if (globals.curr_mode == RULER_MODE_ACTIVE) { |
| 3497 |
clear_ruler(); |
| 3498 |
mouse_motion = mouse_release = null_mouse; |
| 3499 |
} |
| 3500 |
else if (globals.curr_mode == TEXT_MODE_ACTIVE) { |
| 3501 |
text_change_region(TEXT_SEL_CLEAR, NULL); |
| 3502 |
mouse_motion = mouse_release = null_mouse; |
| 3503 |
} |
| 3504 |
globals.curr_mode = NO_MODE_ACTIVE; |
| 3505 |
|
| 3506 |
switch(resource.mouse_mode) { |
| 3507 |
case MOUSE_MODE1: |
| 3508 |
mode_name = resource.mouse_mode1_name; |
| 3509 |
mode_description = resource.mouse_mode1_description; |
| 3510 |
break; |
| 3511 |
case MOUSE_MODE2: |
| 3512 |
mode_name = resource.mouse_mode2_name; |
| 3513 |
mode_description = resource.mouse_mode2_description; |
| 3514 |
/* globals.cursor.flags |= CURSOR_TEXT; /\*XXX FIXME: don't hardcode flag here; instead, have Act_text_selection set it *\/ */ |
| 3515 |
break; |
| 3516 |
case MOUSE_MODE3: |
| 3517 |
mode_name = resource.mouse_mode3_name; |
| 3518 |
mode_description = resource.mouse_mode3_description; |
| 3519 |
/* globals.cursor.flags |= CURSOR_RULER; */ |
| 3520 |
break; |
| 3521 |
default: /* can't happen */ |
| 3522 |
XDVI_WARNING((stderr, "resource.mouse_mode larger than %d!", resource.mouse_mode)); |
| 3523 |
break; |
| 3524 |
} |
| 3525 |
|
| 3526 |
globals.ev.flags |= EV_CURSOR; |
| 3527 |
XFlush(DISP); |
| 3528 |
|
| 3529 |
if (!initialization) { |
| 3530 |
statusline_info(STATUS_SHORT, "%s mode; %s", mode_name, mode_description); |
| 3531 |
store_preference(NULL, "mouseMode", "%d", resource.mouse_mode); |
| 3532 |
} |
| 3533 |
set_menu(&resource.mouse_mode, Act_switch_mode, check_int); |
| 3534 |
|
| 3535 |
|
| 3536 |
/*XXX FIXME: Activate mode by synthesizing a mouse event??? */ |
| 3537 |
/* synthesize_event(&ev, globals.widgets.draw_widget); */ |
| 3538 |
/* Act_mouse_modes(w, event, params, num_params); */ |
| 3539 |
} |
| 3540 |
|
| 3541 |
static void |
| 3542 |
Act_drag(Widget w, XEvent *event, |
| 3543 |
String *params, Cardinal *num_params) |
| 3544 |
{ |
| 3545 |
UNUSED(w); |
| 3546 |
|
| 3547 |
if (mouse_release != null_mouse && mouse_release != drag_release) |
| 3548 |
return; |
| 3549 |
|
| 3550 |
if ((globals.curr_mode == TEXT_MODE_ACTIVE) && text_last_page != -1 |
| 3551 |
/* this was: |
| 3552 |
&& (text_last_x != drag_last_x || text_last_y != drag_last_y) |
| 3553 |
but that isn't restrictive enough */ |
| 3554 |
) { /* dragging would mess up region drawing */ |
| 3555 |
xdvi_bell(); |
| 3556 |
statusline_info(STATUS_SHORT, "Cannot drag page when selection is active"); |
| 3557 |
return; |
| 3558 |
} |
| 3559 |
|
| 3560 |
if (*num_params != 1) { |
| 3561 |
XDVI_WARNING((stderr, "drag() requires 1 argument (got %d)", *num_params)); |
| 3562 |
return; |
| 3563 |
} |
| 3564 |
switch (**params) { |
| 3565 |
case '|': |
| 3566 |
globals.cursor.flags |= CURSOR_DRAG_V; |
| 3567 |
break; |
| 3568 |
case '-': |
| 3569 |
globals.cursor.flags |= CURSOR_DRAG_H; |
| 3570 |
break; |
| 3571 |
case '+': |
| 3572 |
globals.cursor.flags |= CURSOR_DRAG_A; |
| 3573 |
break; |
| 3574 |
default: |
| 3575 |
XDVI_WARNING((stderr, "drag(): Valid arguments are `+', `|' or `-'")); |
| 3576 |
} |
| 3577 |
|
| 3578 |
globals.ev.flags |= EV_CURSOR; |
| 3579 |
|
| 3580 |
if (mouse_release == null_mouse) { |
| 3581 |
mouse_motion = drag_motion; |
| 3582 |
mouse_release = drag_release; |
| 3583 |
drag_last_x = event->xbutton.x_root; |
| 3584 |
drag_last_y = event->xbutton.y_root; |
| 3585 |
} |
| 3586 |
else |
| 3587 |
drag_motion(event); |
| 3588 |
|
| 3589 |
XFlush(DISP); |
| 3590 |
} |
| 3591 |
|
| 3592 |
|
| 3593 |
static void |
| 3594 |
drag_motion(XEvent * event) |
| 3595 |
{ |
| 3596 |
#ifdef MOTIF |
| 3597 |
get_xy(); |
| 3598 |
#endif |
| 3599 |
|
| 3600 |
if (globals.cursor.flags & (CURSOR_DRAG_H | CURSOR_DRAG_A)) { /* horizontal motion */ |
| 3601 |
#ifdef MOTIF |
| 3602 |
(void)set_bar_value(globals.widgets.x_bar, |
| 3603 |
drag_last_x - event->xbutton.x_root - m_window_x, |
| 3604 |
(int)(globals.page.w - mane.width)); |
| 3605 |
#else |
| 3606 |
if (globals.widgets.x_bar != NULL) { |
| 3607 |
XtCallCallbacks(globals.widgets.x_bar, XtNscrollProc, |
| 3608 |
cast_int_to_XtPointer(drag_last_x - event->xbutton.x_root)); |
| 3609 |
} |
| 3610 |
#endif |
| 3611 |
drag_last_x = event->xbutton.x_root; |
| 3612 |
} |
| 3613 |
|
| 3614 |
if (globals.cursor.flags & (CURSOR_DRAG_V | CURSOR_DRAG_A)) { /* vertical motion */ |
| 3615 |
#ifdef MOTIF |
| 3616 |
(void)set_bar_value(globals.widgets.y_bar, |
| 3617 |
drag_last_y - event->xbutton.y_root - m_window_y, |
| 3618 |
(int)(globals.page.h - mane.height)); |
| 3619 |
#else |
| 3620 |
if (globals.widgets.y_bar != NULL) { |
| 3621 |
XtCallCallbacks(globals.widgets.y_bar, XtNscrollProc, |
| 3622 |
cast_int_to_XtPointer(drag_last_y - event->xbutton.y_root)); |
| 3623 |
} |
| 3624 |
#endif |
| 3625 |
drag_last_y = event->xbutton.y_root; |
| 3626 |
} |
| 3627 |
#ifdef USE_PANNER |
| 3628 |
handle_x_scroll(NULL, NULL, NULL, NULL); |
| 3629 |
handle_y_scroll(NULL, NULL, NULL, NULL); |
| 3630 |
#endif |
| 3631 |
} |
| 3632 |
|
| 3633 |
|
| 3634 |
static void |
| 3635 |
drag_release(XEvent * event) |
| 3636 |
{ |
| 3637 |
drag_motion(event); |
| 3638 |
mouse_motion = mouse_release = null_mouse; |
| 3639 |
|
| 3640 |
globals.cursor.flags &= ~(CURSOR_DRAG_H | CURSOR_DRAG_V | CURSOR_DRAG_A); |
| 3641 |
globals.ev.flags |= EV_CURSOR; |
| 3642 |
XFlush(DISP); |
| 3643 |
} |
| 3644 |
|
| 3645 |
|
| 3646 |
|
| 3647 |
/* Wheel mouse support. */ |
| 3648 |
|
| 3649 |
static int wheel_button = -1; |
| 3650 |
|
| 3651 |
static void |
| 3652 |
Act_wheel(Widget w, XEvent *event, |
| 3653 |
String *params, Cardinal *num_params) |
| 3654 |
{ |
| 3655 |
int dist; |
| 3656 |
|
| 3657 |
UNUSED(w); |
| 3658 |
|
| 3659 |
if (*num_params != 1) { |
| 3660 |
XDVI_WARNING((stderr, "wheel() requires 1 argument (got %d)", *num_params)); |
| 3661 |
return; |
| 3662 |
} |
| 3663 |
dist = (strchr(*params, '.') == NULL) ? atoi(*params) |
| 3664 |
: (int)(my_atof(*params) * resource.wheel_unit); |
| 3665 |
#ifdef MOTIF |
| 3666 |
get_xy(); |
| 3667 |
set_bar_value(globals.widgets.y_bar, dist - m_window_y, (int)(globals.page.h - mane.height)); |
| 3668 |
#else |
| 3669 |
if (globals.widgets.y_bar != NULL) |
| 3670 |
XtCallCallbacks(globals.widgets.y_bar, XtNscrollProc, cast_int_to_XtPointer(dist)); |
| 3671 |
#endif |
| 3672 |
|
| 3673 |
if (event != NULL) |
| 3674 |
wheel_button = event->xbutton.button; |
| 3675 |
|
| 3676 |
#ifdef USE_PANNER |
| 3677 |
handle_y_scroll(NULL, NULL, NULL, NULL); |
| 3678 |
#endif |
| 3679 |
} |
| 3680 |
|
| 3681 |
static int wheel_h_button = -1; |
| 3682 |
|
| 3683 |
static void |
| 3684 |
Act_hwheel(Widget w, XEvent *event, |
| 3685 |
String *params, Cardinal *num_params) |
| 3686 |
{ |
| 3687 |
int dist; |
| 3688 |
|
| 3689 |
UNUSED(w); |
| 3690 |
|
| 3691 |
if (*num_params != 1) { |
| 3692 |
XDVI_WARNING((stderr, "wheel() requires 1 argument (got %d)", *num_params)); |
| 3693 |
return; |
| 3694 |
} |
| 3695 |
dist = (strchr(*params, '.') == NULL) ? atoi(*params) |
| 3696 |
: (int)(my_atof(*params) * resource.wheel_unit); |
| 3697 |
#ifdef MOTIF |
| 3698 |
get_xy(); |
| 3699 |
set_bar_value(globals.widgets.x_bar, dist - m_window_x, |
| 3700 |
(int) (globals.page.w - mane.width)); |
| 3701 |
#else |
| 3702 |
if (globals.widgets.x_bar != NULL) |
| 3703 |
XtCallCallbacks(globals.widgets.x_bar, XtNscrollProc, |
| 3704 |
cast_int_to_XtPointer(dist)); |
| 3705 |
#endif |
| 3706 |
|
| 3707 |
if (event != NULL) |
| 3708 |
wheel_h_button = event->xbutton.button; |
| 3709 |
|
| 3710 |
#ifdef USE_PANNER |
| 3711 |
handle_x_scroll(NULL, NULL, NULL, NULL); |
| 3712 |
#endif |
| 3713 |
} |
| 3714 |
|
| 3715 |
|
| 3716 |
/* Internal mouse actions. */ |
| 3717 |
|
| 3718 |
/* |
| 3719 |
* Here xdvi does its own parsing and processing of translations for mouse |
| 3720 |
* button presses. This is necessary because the X Toolkit does not recognize |
| 3721 |
* <Btn6Down> or <Btn7Down> event types. |
| 3722 |
*/ |
| 3723 |
|
| 3724 |
#if HAVE_X11_INTRINSICI_H |
| 3725 |
# include <X11/IntrinsicI.h> |
| 3726 |
#else |
| 3727 |
|
| 3728 |
/* From <X11/TranslateI.h> */ |
| 3729 |
extern Boolean _XtComputeLateBindings( |
| 3730 |
Display* /* dpy */, |
| 3731 |
struct _LateBindings* /* lateModifiers */, |
| 3732 |
Modifiers* /* computed */, |
| 3733 |
Modifiers* /* computedMask */ |
| 3734 |
); |
| 3735 |
|
| 3736 |
#endif /* HAVE_X11_INTRINSICI_H */ |
| 3737 |
|
| 3738 |
|
| 3739 |
static void |
| 3740 |
Act_press(Widget w, XEvent *event, |
| 3741 |
String *params, Cardinal *num_params) |
| 3742 |
{ |
| 3743 |
struct mouse_acts *mactp; |
| 3744 |
struct xdvi_action *actp; |
| 3745 |
|
| 3746 |
#if HAVE_XI21 |
| 3747 |
if (xi2_active |
| 3748 |
&& (xi2_current->slave->btn_mask & (1 << event->xbutton.button))) { |
| 3749 |
TRACE_EVENTS((stderr, "Ignoring button %d press (XI 2.1 active)", |
| 3750 |
event->xbutton.button)); |
| 3751 |
if (event->xbutton.button <= 5) |
| 3752 |
wheel_button = event->xbutton.button; |
| 3753 |
else |
| 3754 |
wheel_h_button = event->xbutton.button; |
| 3755 |
xi2_ign_time = event->xbutton.time; |
| 3756 |
return; |
| 3757 |
} |
| 3758 |
#endif |
| 3759 |
|
| 3760 |
for (mactp = mouse_actions; mactp != NULL; mactp = mactp->next) { |
| 3761 |
if (event->xbutton.button == mactp->button || mactp->button == 0) { |
| 3762 |
Modifiers mask = 0; |
| 3763 |
Modifiers value = 0; |
| 3764 |
|
| 3765 |
if (mactp->late_bindings == NULL |
| 3766 |
|| _XtComputeLateBindings(DISP, mactp->late_bindings, |
| 3767 |
&value, &mask)) { |
| 3768 |
mask |= mactp->mask; |
| 3769 |
value |= mactp->value; |
| 3770 |
if (((value ^ event->xbutton.state) & mask) == 0) { |
| 3771 |
for (actp = mactp->action; actp != NULL; |
| 3772 |
actp = actp->next) |
| 3773 |
(actp->proc)(w, event, actp->params, &actp->num_params); |
| 3774 |
return; |
| 3775 |
} |
| 3776 |
} |
| 3777 |
} |
| 3778 |
} |
| 3779 |
} |
| 3780 |
|
| 3781 |
|
| 3782 |
static void |
| 3783 |
Act_motion(Widget w, XEvent *event, |
| 3784 |
String *params, Cardinal *num_params) |
| 3785 |
{ |
| 3786 |
/* remember last position, to do this only when pointer is actually moved */ |
| 3787 |
static int old_x = -1, old_y = -1; |
| 3788 |
int x, y; |
| 3789 |
|
| 3790 |
UNUSED(w); |
| 3791 |
UNUSED(params); |
| 3792 |
UNUSED(num_params); |
| 3793 |
|
| 3794 |
MYTRACE((stderr, "act_motion!\n")); |
| 3795 |
|
| 3796 |
if (globals.curr_mode == RULER_MODE_ACTIVE) { |
| 3797 |
show_distance_from_ruler(event, False); |
| 3798 |
} |
| 3799 |
/* This used to be: |
| 3800 |
(abs(x - old_x) > x_threshold || abs(y - old_y) > y_threshold)) |
| 3801 |
but that didn't work too well either. Just change it whenever user |
| 3802 |
moves the mouse. */ |
| 3803 |
if (!MAGNIFIER_ACTIVE && !(globals.curr_mode == RULER_MODE_ACTIVE) |
| 3804 |
&& pointerlocate(&x, &y) && (x != old_x || y != old_y)) { |
| 3805 |
htex_displayanchor(x, y); |
| 3806 |
old_x = x; |
| 3807 |
old_y = y; |
| 3808 |
} |
| 3809 |
|
| 3810 |
if ((int)(event->xbutton.button) != wheel_button |
| 3811 |
&& ((int) (event->xbutton.button) != wheel_h_button)) { |
| 3812 |
MYTRACE((stderr, "mouse_motion!\n")); |
| 3813 |
mouse_motion(event); |
| 3814 |
} |
| 3815 |
} |
| 3816 |
|
| 3817 |
|
| 3818 |
static void |
| 3819 |
Act_release(Widget w, XEvent *event, |
| 3820 |
String *params, Cardinal *num_params) |
| 3821 |
{ |
| 3822 |
UNUSED(w); |
| 3823 |
UNUSED(params); |
| 3824 |
UNUSED(num_params); |
| 3825 |
|
| 3826 |
if ((int)(event->xbutton.button) == wheel_button) { |
| 3827 |
wheel_button = -1; |
| 3828 |
return; |
| 3829 |
} |
| 3830 |
|
| 3831 |
if ((int)(event->xbutton.button) == wheel_h_button) { |
| 3832 |
wheel_h_button = -1; |
| 3833 |
return; |
| 3834 |
} |
| 3835 |
|
| 3836 |
mouse_release(event); |
| 3837 |
} |
| 3838 |
|
| 3839 |
static void |
| 3840 |
Act_toggle_grid_mode(Widget w, XEvent *event, |
| 3841 |
String *params, Cardinal *num_params) |
| 3842 |
{ |
| 3843 |
int arg; |
| 3844 |
|
| 3845 |
UNUSED(w); |
| 3846 |
UNUSED(event); |
| 3847 |
|
| 3848 |
if (!get_int_arg(params, num_params, &arg)) { |
| 3849 |
arg = -1; |
| 3850 |
} |
| 3851 |
switch (arg) { |
| 3852 |
case -1: |
| 3853 |
resource.grid_mode = !resource.grid_mode; |
| 3854 |
if (resource.grid_mode) { |
| 3855 |
statusline_info(STATUS_SHORT, "Grid mode on"); |
| 3856 |
} |
| 3857 |
else { |
| 3858 |
statusline_info(STATUS_SHORT, "Grid mode off"); |
| 3859 |
} |
| 3860 |
break; |
| 3861 |
case 1: /* fall through */ |
| 3862 |
case 2: /* fall through */ |
| 3863 |
case 3: |
| 3864 |
resource.grid_mode = arg; |
| 3865 |
statusline_info(STATUS_SHORT, "Grid mode %d", arg); |
| 3866 |
break; |
| 3867 |
default: |
| 3868 |
xdvi_bell(); |
| 3869 |
statusline_info(STATUS_SHORT, |
| 3870 |
"Valid arguments for grid mode are: none (toggles), 1, 2, 3"); |
| 3871 |
return; |
| 3872 |
} |
| 3873 |
init_page(); |
| 3874 |
reconfig(); |
| 3875 |
globals.ev.flags |= EV_NEWPAGE; |
| 3876 |
XFlush(DISP); |
| 3877 |
} |
| 3878 |
|
| 3879 |
|
| 3880 |
/* Actions for source specials. */ |
| 3881 |
|
| 3882 |
void |
| 3883 |
Act_source_special(Widget w, XEvent *event, |
| 3884 |
String *params, Cardinal *num_params) |
| 3885 |
{ |
| 3886 |
Window dummy; |
| 3887 |
|
| 3888 |
UNUSED(w); |
| 3889 |
UNUSED(params); |
| 3890 |
UNUSED(num_params); |
| 3891 |
|
| 3892 |
if ((event->type == ButtonPress && mouse_release != null_mouse) |
| 3893 |
|| MAGNIFIER_ACTIVE) { |
| 3894 |
xdvi_bell(); |
| 3895 |
return; |
| 3896 |
} |
| 3897 |
|
| 3898 |
source_reverse_x = event->xbutton.x; |
| 3899 |
source_reverse_y = event->xbutton.y; |
| 3900 |
if (event->xbutton.window != mane.win) |
| 3901 |
(void)XTranslateCoordinates(DISP, |
| 3902 |
RootWindowOfScreen(SCRN), mane.win, |
| 3903 |
event->xbutton.x_root, |
| 3904 |
event->xbutton.y_root, |
| 3905 |
&source_reverse_x, |
| 3906 |
&source_reverse_y, |
| 3907 |
&dummy); /* throw away last argument */ |
| 3908 |
|
| 3909 |
source_reverse_x = (source_reverse_x + mane_base_x) * mane.shrinkfactor; |
| 3910 |
source_reverse_y = (source_reverse_y + mane_base_y) * mane.shrinkfactor; |
| 3911 |
|
| 3912 |
globals.ev.flags |= EV_SRC; |
| 3913 |
} |
| 3914 |
|
| 3915 |
void |
| 3916 |
Act_show_source_specials(Widget w, XEvent *event, |
| 3917 |
String *params, Cardinal *num_params) |
| 3918 |
{ |
| 3919 |
int arg; |
| 3920 |
Boolean clear_statusline = False; |
| 3921 |
|
| 3922 |
UNUSED(w); |
| 3923 |
|
| 3924 |
if (!get_int_arg(params, num_params, &arg)) |
| 3925 |
arg = -1; |
| 3926 |
else |
| 3927 |
clear_statusline = True; |
| 3928 |
|
| 3929 |
if ((event->type == ButtonPress && mouse_release != null_mouse) |
| 3930 |
|| MAGNIFIER_ACTIVE) { |
| 3931 |
xdvi_bell(); |
| 3932 |
return; |
| 3933 |
} |
| 3934 |
|
| 3935 |
if (!(globals.ev.flags & EV_SRC)) { |
| 3936 |
source_reverse_x = -1; |
| 3937 |
source_show_all = (arg == 1 ? True : False); |
| 3938 |
|
| 3939 |
globals.ev.flags |= EV_SRC; |
| 3940 |
} |
| 3941 |
if (clear_statusline) |
| 3942 |
statusline_clear(); |
| 3943 |
} |
| 3944 |
|
| 3945 |
void |
| 3946 |
Act_source_what_special(Widget w, XEvent *event, |
| 3947 |
String *params, Cardinal *num_params) |
| 3948 |
{ |
| 3949 |
int my_x, my_y; |
| 3950 |
Window dummy; |
| 3951 |
|
| 3952 |
UNUSED(w); |
| 3953 |
UNUSED(params); |
| 3954 |
UNUSED(num_params); |
| 3955 |
|
| 3956 |
(void)XTranslateCoordinates(DISP, event->xkey.window, mane.win, |
| 3957 |
event->xkey.x, event->xkey.y, &my_x, &my_y, &dummy); /* throw away last argument */ |
| 3958 |
my_x = (my_x + mane_base_x) * mane.shrinkfactor; |
| 3959 |
my_y = (my_y + mane_base_y) * mane.shrinkfactor; |
| 3960 |
source_reverse_search(my_x, my_y, False); |
| 3961 |
} |
| 3962 |
|
| 3963 |
static const char *user_exec_help = |
| 3964 |
"The user-exec() action lets you run a child process. " |
| 3965 |
"It takes a single string, which is tokenized on whitespace."; |
| 3966 |
|
| 3967 |
void |
| 3968 |
Act_user_exec(Widget w, XEvent *event, |
| 3969 |
String *params, Cardinal *num_params) |
| 3970 |
{ |
| 3971 |
char **argv; |
| 3972 |
int i; |
| 3973 |
char *errmsg = NULL; |
| 3974 |
|
| 3975 |
if (*num_params == 0) |
| 3976 |
errmsg = "No arguments supplied to the user-exec() action."; |
| 3977 |
else if (*num_params > 1) |
| 3978 |
errmsg = "Too many arguments supplied to the user-exec() action."; |
| 3979 |
else if (setenv("XDVI_FILE", globals.dvi_name, 1) == -1) |
| 3980 |
errmsg = strerror(errno); |
| 3981 |
|
| 3982 |
if (errmsg) { |
| 3983 |
popup_message(globals.widgets.top_level, |
| 3984 |
MSG_ERR, |
| 3985 |
/* helptext */ |
| 3986 |
user_exec_help, |
| 3987 |
/* popup */ |
| 3988 |
errmsg); |
| 3989 |
return; |
| 3990 |
} |
| 3991 |
|
| 3992 |
argv = get_separated_list(params[0], " \t", True); |
| 3993 |
fork_process(argv[0], False, NULL, NULL, NULL, 0, argv); |
| 3994 |
for (i = 0; argv[i] != NULL; i++) |
| 3995 |
free(argv[i]); |
| 3996 |
free(argv); |
| 3997 |
} |
| 3998 |
|
| 3999 |
static void |
| 4000 |
select_cb(const char *filename, void *data) |
| 4001 |
{ |
| 4002 |
UNUSED(data); |
| 4003 |
if (filename != NULL) { |
| 4004 |
TRACE_FILES((stderr, "new filename: |%s|", filename)); |
| 4005 |
|
| 4006 |
if (resource.filesel_open_new_window) { |
| 4007 |
/* char *fname = expand_filename_append_dvi(filename); */ |
| 4008 |
launch_xdvi(filename, NULL); |
| 4009 |
} |
| 4010 |
else { |
| 4011 |
/* the filename should be complete already, so don't append .dvi */ |
| 4012 |
set_dvi_name(expand_filename(filename, USE_CWD_PATH)); |
| 4013 |
current_page = 0; /* switch to first page */ |
| 4014 |
close_old_filep(); |
| 4015 |
globals.ev.flags |= EV_NEWDOC; |
| 4016 |
globals.ev.flags |= EV_PAGEHIST_INSERT; |
| 4017 |
} |
| 4018 |
} |
| 4019 |
} |
| 4020 |
|
| 4021 |
static void |
| 4022 |
Act_select_dvi_file(Widget w, XEvent *event, |
| 4023 |
String *params, Cardinal *num_params) |
| 4024 |
{ |
| 4025 |
/* static so that we can pass its address */ |
| 4026 |
static struct filesel_callback cb = { |
| 4027 |
NULL, NULL, "xdvik: Open File", "Open file:", "OK", "Cancel", |
| 4028 |
NULL, "*.dvi", True, False, NULL, NULL |
| 4029 |
}; |
| 4030 |
int arg = -1; |
| 4031 |
|
| 4032 |
UNUSED(w); |
| 4033 |
UNUSED(event); |
| 4034 |
|
| 4035 |
if (get_int_arg(params, num_params, &arg)) { /* try item from file history */ |
| 4036 |
char *fname; |
| 4037 |
int dummy_page; |
| 4038 |
|
| 4039 |
if (arg < 1) { |
| 4040 |
xdvi_bell(); |
| 4041 |
statusline_info(STATUS_MEDIUM, "Error: File history number must be >= 1"); |
| 4042 |
} |
| 4043 |
else if ((fname = file_history_get_elem(arg - 1, &dummy_page)) == NULL) { |
| 4044 |
statusline_info(STATUS_MEDIUM, "No file number %d in history (history size: %lu)", |
| 4045 |
arg, (unsigned long)file_history_size()); |
| 4046 |
} |
| 4047 |
else { |
| 4048 |
file_history_open(fname); |
| 4049 |
} |
| 4050 |
return; |
| 4051 |
} |
| 4052 |
|
| 4053 |
file_history_set_page(current_page); |
| 4054 |
|
| 4055 |
cb.func_ptr = select_cb; |
| 4056 |
cb.init_path = globals.dvi_file.dirname; |
| 4057 |
if (cb.shell == NULL) |
| 4058 |
cb.shell = XsraSelFile(globals.widgets.top_level, &cb); |
| 4059 |
XsraSelFilePopup(&cb); |
| 4060 |
} |
| 4061 |
|
| 4062 |
/* |
| 4063 |
* If all GUI elements have been turned on/off, make this synonymous |
| 4064 |
* with expert mode off/on, so that next `x' keystroke does something |
| 4065 |
* reasonable. |
| 4066 |
*/ |
| 4067 |
void |
| 4068 |
update_expert_mode(void) |
| 4069 |
{ |
| 4070 |
if ((resource.expert_mode & (XPRT_SHOW_STATUSLINE | XPRT_SHOW_SCROLLBARS |
| 4071 |
#ifdef MOTIF |
| 4072 |
| XPRT_SHOW_PAGELIST | XPRT_SHOW_TOOLBAR | XPRT_SHOW_MENUBAR |
| 4073 |
#else |
| 4074 |
| XPRT_SHOW_BUTTONS |
| 4075 |
#endif |
| 4076 |
)) == XPRT_SHOW_ALL) { |
| 4077 |
resource.expert = False; |
| 4078 |
} |
| 4079 |
else if ((resource.expert_mode & (XPRT_SHOW_STATUSLINE |
| 4080 |
#ifdef MOTIF |
| 4081 |
| XPRT_SHOW_SCROLLBARS | XPRT_SHOW_PAGELIST |
| 4082 |
| XPRT_SHOW_TOOLBAR | XPRT_SHOW_MENUBAR |
| 4083 |
#else |
| 4084 |
| BROKEN_RECONFIG ? 0 : XPRT_SHOW_SCROLLBARS | XPRT_SHOW_BUTTONS |
| 4085 |
#endif |
| 4086 |
)) == XPRT_SHOW_NONE) { |
| 4087 |
resource.expert = True; |
| 4088 |
} |
| 4089 |
} |
| 4090 |
|
| 4091 |
void |
| 4092 |
Act_set_expert_mode(Widget w, XEvent *event, |
| 4093 |
String *params, Cardinal *num_params) |
| 4094 |
{ |
| 4095 |
int arg; |
| 4096 |
Boolean clear_statusline = False; |
| 4097 |
|
| 4098 |
UNUSED(w); |
| 4099 |
UNUSED(event); |
| 4100 |
|
| 4101 |
if (!get_int_arg(params, num_params, &arg)) |
| 4102 |
arg = -1; |
| 4103 |
else |
| 4104 |
clear_statusline = True; |
| 4105 |
|
| 4106 |
switch(arg) { |
| 4107 |
case 1: |
| 4108 |
resource.expert_mode ^= XPRT_SHOW_STATUSLINE; |
| 4109 |
toggle_statusline(); |
| 4110 |
update_expert_mode(); |
| 4111 |
break; |
| 4112 |
case 2: |
| 4113 |
#ifndef MOTIF |
| 4114 |
/* show this warning only when not toggling global expert mode |
| 4115 |
(that's why it can't be inside toggle_scrollbars) */ |
| 4116 |
if (BROKEN_RECONFIG) { |
| 4117 |
popup_message(globals.widgets.top_level, |
| 4118 |
MSG_WARN, |
| 4119 |
NULL, |
| 4120 |
"Sorry - cannot toggle scrollbars with this X Version.\n" |
| 4121 |
"This version of XFree has a broken implementation of the viewportWidget, " |
| 4122 |
"which would break the layout if the scrollbars are toggled. " |
| 4123 |
"Versions that are known to work have a VendorRelease version below 4000 or above 4002. " |
| 4124 |
"You will need to update your XFree server to fix this."); |
| 4125 |
return; |
| 4126 |
} |
| 4127 |
#endif |
| 4128 |
resource.expert_mode ^= XPRT_SHOW_SCROLLBARS; |
| 4129 |
toggle_scrollbars(); |
| 4130 |
update_expert_mode(); |
| 4131 |
break; |
| 4132 |
|
| 4133 |
#ifdef MOTIF |
| 4134 |
case 3: |
| 4135 |
resource.expert_mode ^= XPRT_SHOW_PAGELIST; |
| 4136 |
toggle_pagelist(); |
| 4137 |
update_expert_mode(); |
| 4138 |
break; |
| 4139 |
|
| 4140 |
case 4: /* toolbar */ |
| 4141 |
resource.expert_mode ^= XPRT_SHOW_TOOLBAR; |
| 4142 |
toggle_toolbar(); |
| 4143 |
update_expert_mode(); |
| 4144 |
break; |
| 4145 |
|
| 4146 |
case 5: |
| 4147 |
resource.expert_mode ^= XPRT_SHOW_MENUBAR; |
| 4148 |
toggle_menubar(); |
| 4149 |
update_expert_mode(); |
| 4150 |
break; |
| 4151 |
#else |
| 4152 |
case 3: |
| 4153 |
/* fprintf(stderr, "sidebar\n"); */ |
| 4154 |
resource.expert_mode ^= XPRT_SHOW_BUTTONS; |
| 4155 |
toggle_buttons(); |
| 4156 |
update_expert_mode(); |
| 4157 |
break; |
| 4158 |
#endif |
| 4159 |
default: |
| 4160 |
/* warn 'em */ |
| 4161 |
if ( |
| 4162 |
#ifdef MOTIF |
| 4163 |
arg > 5 |
| 4164 |
#else |
| 4165 |
arg > 3 |
| 4166 |
#endif |
| 4167 |
) { |
| 4168 |
statusline_info(STATUS_SHORT, "Number %d too large for `set-expert-mode', using 0 (= toggle) instead.", |
| 4169 |
arg); |
| 4170 |
} |
| 4171 |
/* toggle all items */ |
| 4172 |
resource.expert = !resource.expert; |
| 4173 |
if (resource.expert) |
| 4174 |
resource.expert_mode = XPRT_SHOW_NONE; |
| 4175 |
else |
| 4176 |
resource.expert_mode = XPRT_SHOW_ALL; |
| 4177 |
|
| 4178 |
toggle_statusline(); |
| 4179 |
#ifndef MOTIF |
| 4180 |
if (!BROKEN_RECONFIG) |
| 4181 |
toggle_scrollbars(); |
| 4182 |
#else |
| 4183 |
toggle_scrollbars(); |
| 4184 |
#endif |
| 4185 |
|
| 4186 |
#ifdef MOTIF |
| 4187 |
toggle_pagelist(); |
| 4188 |
toggle_toolbar(); |
| 4189 |
toggle_menubar(); |
| 4190 |
#else |
| 4191 |
toggle_buttons(); |
| 4192 |
#endif |
| 4193 |
} |
| 4194 |
|
| 4195 |
#ifdef MOTIF |
| 4196 |
update_preferences_expert(); |
| 4197 |
#endif |
| 4198 |
|
| 4199 |
store_preference(NULL, "expertMode", "%d", resource.expert_mode); |
| 4200 |
|
| 4201 |
if (clear_statusline) |
| 4202 |
statusline_clear(); |
| 4203 |
} |
| 4204 |
|
| 4205 |
Boolean have_src_specials = False; |
| 4206 |
static Boolean do_update_property = False; |
| 4207 |
|
| 4208 |
#ifdef USE_PANNER |
| 4209 |
void |
| 4210 |
handle_x_scroll(Widget w, XtPointer closure, XEvent *ev, Boolean *cont) |
| 4211 |
{ |
| 4212 |
#if !defined(MOTIF) |
| 4213 |
Dimension get_x = 0; |
| 4214 |
#endif |
| 4215 |
|
| 4216 |
UNUSED(w); |
| 4217 |
UNUSED(closure); |
| 4218 |
UNUSED(ev); |
| 4219 |
UNUSED(cont); |
| 4220 |
|
| 4221 |
if (/* !resource.keep_flag || */ globals.widgets.x_bar == NULL) |
| 4222 |
return; |
| 4223 |
|
| 4224 |
#ifdef MOTIF |
| 4225 |
XtVaGetValues(globals.widgets.x_bar, XmNvalue, &m_x_scroll, NULL); |
| 4226 |
#else |
| 4227 |
get_xy(); |
| 4228 |
XtVaGetValues(globals.widgets.clip_widget, XtNx, &get_x, NULL); |
| 4229 |
m_x_scroll = get_x - m_window_x; |
| 4230 |
scroll_x_panner(m_x_scroll); |
| 4231 |
#endif /* MOTIF */ |
| 4232 |
} |
| 4233 |
|
| 4234 |
void |
| 4235 |
handle_y_scroll(Widget w, XtPointer closure, XEvent *ev, Boolean *cont) |
| 4236 |
{ |
| 4237 |
#if !defined(MOTIF) |
| 4238 |
Dimension get_y = 0; |
| 4239 |
#endif |
| 4240 |
|
| 4241 |
UNUSED(w); |
| 4242 |
UNUSED(closure); |
| 4243 |
UNUSED(ev); |
| 4244 |
UNUSED(cont); |
| 4245 |
|
| 4246 |
if (/* !resource.keep_flag || */ globals.widgets.y_bar == NULL) |
| 4247 |
return; |
| 4248 |
|
| 4249 |
#ifdef MOTIF |
| 4250 |
XtVaGetValues(globals.widgets.y_bar, XmNvalue, &m_y_scroll, NULL); |
| 4251 |
#else |
| 4252 |
get_xy(); |
| 4253 |
XtVaGetValues(globals.widgets.clip_widget, XtNy, &get_y, NULL); |
| 4254 |
m_y_scroll = get_y - m_window_y; |
| 4255 |
scroll_y_panner(m_y_scroll); |
| 4256 |
#endif /* MOTIF */ |
| 4257 |
} |
| 4258 |
#endif /* USE_PANNER */ |
| 4259 |
|
| 4260 |
void |
| 4261 |
handle_expose(Widget w, XtPointer closure, XEvent *ev, Boolean *cont) |
| 4262 |
{ |
| 4263 |
struct WindowRec *windowrec = (struct WindowRec *)closure; |
| 4264 |
|
| 4265 |
UNUSED(w); |
| 4266 |
UNUSED(cont); |
| 4267 |
|
| 4268 |
if (windowrec == &magnifier) { |
| 4269 |
if (magnifier_stat < 0) { /* destroy upon exposure */ |
| 4270 |
magnifier_stat = 0; |
| 4271 |
mag_release(ev); |
| 4272 |
return; |
| 4273 |
} |
| 4274 |
else |
| 4275 |
magnifier_stat = 0; |
| 4276 |
} |
| 4277 |
|
| 4278 |
do_update_property = False; |
| 4279 |
|
| 4280 |
if (have_src_specials && !MAGNIFIER_ACTIVE) { |
| 4281 |
do_update_property = True; |
| 4282 |
} |
| 4283 |
|
| 4284 |
expose(windowrec, (&(ev->xexpose))->x, (&(ev->xexpose))->y, |
| 4285 |
(unsigned int)(&(ev->xexpose))->width, (unsigned int)(&(ev->xexpose))->height); |
| 4286 |
} |
| 4287 |
|
| 4288 |
|
| 4289 |
void |
| 4290 |
handle_property_change(Widget w, XtPointer junk, |
| 4291 |
XEvent *ev, Boolean *cont) |
| 4292 |
{ |
| 4293 |
char *prop_ret; |
| 4294 |
size_t prop_len; |
| 4295 |
|
| 4296 |
UNUSED(w); |
| 4297 |
UNUSED(junk); |
| 4298 |
UNUSED(cont); |
| 4299 |
|
| 4300 |
if ((&(ev->xproperty))->window != XtWindow(globals.widgets.top_level)) /* if spurious event */ |
| 4301 |
return; |
| 4302 |
|
| 4303 |
if ((&(ev->xproperty))->atom == atom_src_goto()) { |
| 4304 |
/* forward search requested */ |
| 4305 |
if ((prop_len = property_get_data(XtWindow(globals.widgets.top_level), atom_src_goto(), |
| 4306 |
&prop_ret, |
| 4307 |
XGetWindowProperty)) == 0) { |
| 4308 |
TRACE_CLIENT((stderr, "property_get_data() failed for atom_src_goto()!")); |
| 4309 |
return; |
| 4310 |
} |
| 4311 |
TRACE_CLIENT((stderr, "got back atom_src_goto: |%s|", prop_ret)); |
| 4312 |
globals.src.fwd_string = prop_ret; |
| 4313 |
globals.ev.flags |= EV_SRC; |
| 4314 |
} |
| 4315 |
else if ((&(ev->xproperty))->atom == atom_find_string()) { |
| 4316 |
/* string search requested */ |
| 4317 |
if ((prop_len = property_get_data(XtWindow(globals.widgets.top_level), atom_find_string(), |
| 4318 |
&prop_ret, |
| 4319 |
XGetWindowProperty)) == 0) { |
| 4320 |
TRACE_CLIENT((stderr, "property_get_data() failed for atom_find_string()!")); |
| 4321 |
return; |
| 4322 |
} |
| 4323 |
TRACE_FIND((stderr, "got back atom_find_string: |%s|", prop_ret)); |
| 4324 |
resource.find_string = prop_ret; |
| 4325 |
globals.ev.flags |= EV_FIND; |
| 4326 |
} |
| 4327 |
else if ((&(ev->xproperty))->atom == atom_reload()) { |
| 4328 |
/* like do_sigusr(); there's no data in this case. */ |
| 4329 |
TRACE_CLIENT((stderr, "atom_reload()")); |
| 4330 |
globals.ev.flags |= EV_RELOAD; |
| 4331 |
} |
| 4332 |
else if ((&(ev->xproperty))->atom == atom_newdoc()) { |
| 4333 |
/* loading a new file */ |
| 4334 |
FILE *new_fp; |
| 4335 |
if ((prop_len = property_get_data(XtWindow(globals.widgets.top_level), atom_newdoc(), |
| 4336 |
&prop_ret, |
| 4337 |
XGetWindowProperty)) == 0) { |
| 4338 |
TRACE_CLIENT((stderr, "property_get_data() returned zero length for atom_newdoc()")); |
| 4339 |
/* just raise it in this case */ |
| 4340 |
XMapRaised(XtDisplay(globals.widgets.top_level), XtWindow(globals.widgets.top_level)); |
| 4341 |
raise_message_windows(); |
| 4342 |
return; |
| 4343 |
} |
| 4344 |
TRACE_CLIENT((stderr, "got back atom_newdoc: |%s|", prop_ret)); |
| 4345 |
if ((new_fp = XFOPEN(prop_ret, "r")) == NULL) { |
| 4346 |
popup_message(globals.widgets.top_level, |
| 4347 |
MSG_ERR, NULL, "Loading %s failed: %s", |
| 4348 |
prop_ret, strerror(errno)); |
| 4349 |
return; |
| 4350 |
} |
| 4351 |
set_dvi_name_expand(prop_ret); |
| 4352 |
|
| 4353 |
globals.ev.flags |= EV_NEWDOC; |
| 4354 |
} |
| 4355 |
else if ((&(ev->xproperty))->atom == atom_newpage()) { |
| 4356 |
/* jumping to a different page */ |
| 4357 |
int newpage; |
| 4358 |
char *testptr; |
| 4359 |
if ((prop_len = property_get_data(XtWindow(globals.widgets.top_level), atom_newpage(), |
| 4360 |
&prop_ret, |
| 4361 |
XGetWindowProperty)) == 0) { |
| 4362 |
TRACE_CLIENT((stderr, "property_get_data() failed for atom_newpage(): |%s|", prop_ret)); |
| 4363 |
return; |
| 4364 |
} |
| 4365 |
TRACE_CLIENT((stderr, "got back atom_newpage: |%s|", prop_ret)); |
| 4366 |
if (strcmp(prop_ret, "+") == 0) { /* special case: treat `+' as last page */ |
| 4367 |
newpage = total_pages - 1; |
| 4368 |
} |
| 4369 |
else { |
| 4370 |
newpage = strtol(prop_ret, &testptr, 10) - 1; |
| 4371 |
if (*testptr != '\0') { |
| 4372 |
XDVI_FATAL((stderr, "Invalid page number: `%s'.", prop_ret)); |
| 4373 |
} |
| 4374 |
} |
| 4375 |
|
| 4376 |
if (newpage == total_pages - 1) { /* as in Act_goto_page() */ |
| 4377 |
goto_page(check_goto_page(newpage, True), resource.keep_flag ? NULL : home, False); |
| 4378 |
search_signal_page_changed(); |
| 4379 |
} |
| 4380 |
else { |
| 4381 |
goto_page(check_goto_tex_page(newpage), resource.keep_flag ? NULL : home, False); |
| 4382 |
search_signal_page_changed(); |
| 4383 |
} |
| 4384 |
} |
| 4385 |
else if ((&(ev->xproperty))->atom == atom_raise()) { |
| 4386 |
XMapRaised(XtDisplay(globals.widgets.top_level), XtWindow(globals.widgets.top_level)); |
| 4387 |
raise_message_windows(); |
| 4388 |
} |
| 4389 |
else if ((&(ev->xproperty))->atom == atom_reread_prefs()) { |
| 4390 |
read_user_preferences(globals.widgets.top_level, ".xdvirc.tmp"); |
| 4391 |
} |
| 4392 |
} |
| 4393 |
|
| 4394 |
|
| 4395 |
/* |
| 4396 |
* Signal routines. At the signal level, all we do is set flags. |
| 4397 |
*/ |
| 4398 |
|
| 4399 |
#ifndef FLAKY_SIGPOLL |
| 4400 |
static RETSIGTYPE |
| 4401 |
handle_sigpoll(int signo) |
| 4402 |
{ |
| 4403 |
UNUSED(signo); |
| 4404 |
|
| 4405 |
globals.ev.ctr = 1; |
| 4406 |
event_freq = -1; /* forget Plan B */ |
| 4407 |
sig_flags |= SF_POLL; |
| 4408 |
# ifndef HAVE_SIGACTION |
| 4409 |
(void) signal(SIGPOLL, handle_sigpoll); /* reset the signal */ |
| 4410 |
# endif |
| 4411 |
} |
| 4412 |
#endif |
| 4413 |
|
| 4414 |
static RETSIGTYPE |
| 4415 |
handle_sigterm(int signo) |
| 4416 |
{ |
| 4417 |
UNUSED(signo); |
| 4418 |
|
| 4419 |
sig_flags |= SF_TERM; |
| 4420 |
} |
| 4421 |
|
| 4422 |
static RETSIGTYPE |
| 4423 |
handle_sigchld(int signo) |
| 4424 |
{ |
| 4425 |
UNUSED(signo); |
| 4426 |
|
| 4427 |
sig_flags |= SF_CHLD; |
| 4428 |
} |
| 4429 |
|
| 4430 |
static RETSIGTYPE |
| 4431 |
handle_sigalrm(int signo) |
| 4432 |
{ |
| 4433 |
UNUSED(signo); |
| 4434 |
|
| 4435 |
sig_flags |= SF_ALRM; |
| 4436 |
} |
| 4437 |
|
| 4438 |
static RETSIGTYPE |
| 4439 |
ignore_sigusr(int signo) |
| 4440 |
{ |
| 4441 |
UNUSED(signo); |
| 4442 |
fprintf(stderr, "IGNORE SIGUSR1!\n"); |
| 4443 |
} |
| 4444 |
|
| 4445 |
static RETSIGTYPE |
| 4446 |
handle_sigusr(int signo) |
| 4447 |
{ |
| 4448 |
UNUSED(signo); |
| 4449 |
|
| 4450 |
globals.ev.ctr = 1; |
| 4451 |
sig_flags |= SF_USR; |
| 4452 |
} |
| 4453 |
|
| 4454 |
static RETSIGTYPE |
| 4455 |
handle_sigsegv(int signo) |
| 4456 |
{ |
| 4457 |
UNUSED(signo); |
| 4458 |
|
| 4459 |
XDVI_ABORT((stderr, "Segmentation fault - trying to clean up and aborting ...")); |
| 4460 |
} |
| 4461 |
|
| 4462 |
static Boolean sigalarm_initialized = False; |
| 4463 |
|
| 4464 |
void |
| 4465 |
setup_sigalarm(void) |
| 4466 |
{ |
| 4467 |
#if HAVE_SIGACTION |
| 4468 |
struct sigaction a; |
| 4469 |
|
| 4470 |
a.sa_handler = handle_sigalrm; |
| 4471 |
(void) sigemptyset(&a.sa_mask); |
| 4472 |
(void) sigaddset(&a.sa_mask, SIGALRM); |
| 4473 |
a.sa_flags = 0; |
| 4474 |
sigaction(SIGALRM, &a, NULL); |
| 4475 |
#else /* not HAVE_SIGACTION */ |
| 4476 |
(void) signal(SIGALRM, handle_sigalrm); |
| 4477 |
#endif /* not HAVE_SIGACTION */ |
| 4478 |
|
| 4479 |
sigalarm_initialized = True; |
| 4480 |
} |
| 4481 |
|
| 4482 |
/* |
| 4483 |
* Called from main to set up the signal handlers. |
| 4484 |
*/ |
| 4485 |
void |
| 4486 |
setup_signal_handlers(Boolean early) |
| 4487 |
{ |
| 4488 |
#ifndef FLAKY_SIGPOLL |
| 4489 |
int sock_fd = 0; |
| 4490 |
#endif |
| 4491 |
#if HAVE_SIGACTION |
| 4492 |
struct sigaction a; |
| 4493 |
#endif |
| 4494 |
|
| 4495 |
if (early) { |
| 4496 |
#if HAVE_SIGACTION |
| 4497 |
a.sa_handler = ignore_sigusr; |
| 4498 |
(void) sigemptyset(&a.sa_mask); |
| 4499 |
(void) sigaddset(&a.sa_mask, SIGUSR1); |
| 4500 |
a.sa_flags = 0; |
| 4501 |
sigaction(SIGUSR1, &a, NULL); |
| 4502 |
#else /* not HAVE_SIGACTION */ |
| 4503 |
(void) signal(SIGUSR1, ignore_sigusr); |
| 4504 |
#endif /* not HAVE_SIGACTION */ |
| 4505 |
|
| 4506 |
(void)sigemptyset(&all_signals); |
| 4507 |
(void)sigaddset(&all_signals, SIGUSR1); |
| 4508 |
return; |
| 4509 |
} |
| 4510 |
|
| 4511 |
|
| 4512 |
#if HAVE_SIGACTION |
| 4513 |
a.sa_handler = handle_sigusr; |
| 4514 |
(void) sigemptyset(&a.sa_mask); |
| 4515 |
(void) sigaddset(&a.sa_mask, SIGUSR1); |
| 4516 |
a.sa_flags = 0; |
| 4517 |
sigaction(SIGUSR1, &a, NULL); |
| 4518 |
#else /* not HAVE_SIGACTION */ |
| 4519 |
(void) signal(SIGUSR1, handle_sigusr); |
| 4520 |
#endif /* not HAVE_SIGACTION */ |
| 4521 |
|
| 4522 |
#ifndef FLAKY_SIGPOLL |
| 4523 |
#if HAVE_SIGACTION |
| 4524 |
/* Subprocess handling, e.g., MakeTeXPK, fails on the Alpha without |
| 4525 |
this, because SIGPOLL interrupts the call of system(3), since OSF/1 |
| 4526 |
doesn't retry interrupted wait calls by default. From code by |
| 4527 |
[email protected]. */ |
| 4528 |
a.sa_handler = handle_sigpoll; |
| 4529 |
(void) sigemptyset(&a.sa_mask); |
| 4530 |
(void) sigaddset(&a.sa_mask, SIGPOLL); |
| 4531 |
a.sa_flags = SA_RESTART; |
| 4532 |
sigaction(SIGPOLL, &a, NULL); |
| 4533 |
#else /* not HAVE_SIGACTION */ |
| 4534 |
(void) signal(SIGPOLL, handle_sigpoll); |
| 4535 |
#endif /* not HAVE_SIGACTION */ |
| 4536 |
|
| 4537 |
sock_fd = ConnectionNumber(DISP); |
| 4538 |
prep_fd(sock_fd, False); |
| 4539 |
#endif /* not FLAKY_SIGPOLL */ |
| 4540 |
|
| 4541 |
#if HAVE_SIGACTION |
| 4542 |
a.sa_handler = handle_sigterm; |
| 4543 |
(void) sigemptyset(&a.sa_mask); |
| 4544 |
(void) sigaddset(&a.sa_mask, SIGINT); |
| 4545 |
(void) sigaddset(&a.sa_mask, SIGQUIT); |
| 4546 |
(void) sigaddset(&a.sa_mask, SIGTERM); |
| 4547 |
(void) sigaddset(&a.sa_mask, SIGHUP); |
| 4548 |
a.sa_flags = SA_RESETHAND; |
| 4549 |
sigaction(SIGINT, &a, NULL); |
| 4550 |
sigaction(SIGQUIT, &a, NULL); |
| 4551 |
sigaction(SIGTERM, &a, NULL); |
| 4552 |
sigaction(SIGHUP, &a, NULL); |
| 4553 |
a.sa_handler = handle_sigsegv; |
| 4554 |
(void)sigemptyset(&a.sa_mask); |
| 4555 |
(void)sigaddset(&a.sa_mask, SIGSEGV); |
| 4556 |
a.sa_flags = 0; |
| 4557 |
sigaction(SIGSEGV, &a, NULL); |
| 4558 |
#else /* not HAVE_SIGACTION */ |
| 4559 |
(void) signal(SIGINT, handle_sigterm); |
| 4560 |
(void) signal(SIGQUIT, handle_sigterm); |
| 4561 |
(void) signal(SIGTERM, handle_sigterm); |
| 4562 |
(void) signal(SIGHUP, handle_sigterm); |
| 4563 |
(void)signal(SIGSEGV, handle_sigsegv); |
| 4564 |
#endif /* not HAVE_SIGACTION */ |
| 4565 |
|
| 4566 |
#if HAVE_SIGACTION |
| 4567 |
a.sa_handler = handle_sigchld; |
| 4568 |
(void) sigemptyset(&a.sa_mask); |
| 4569 |
(void) sigaddset(&a.sa_mask, SIGCHLD); |
| 4570 |
a.sa_flags = 0; |
| 4571 |
sigaction(SIGCHLD, &a, NULL); |
| 4572 |
#else /* not HAVE_SIGACTION */ |
| 4573 |
(void) signal(SIGCHLD, handle_sigchld); |
| 4574 |
#endif /* not HAVE_SIGACTION */ |
| 4575 |
|
| 4576 |
(void)sigemptyset(&all_signals); |
| 4577 |
(void)sigaddset(&all_signals, SIGPOLL); |
| 4578 |
(void)sigaddset(&all_signals, SIGINT); |
| 4579 |
(void)sigaddset(&all_signals, SIGQUIT); |
| 4580 |
(void)sigaddset(&all_signals, SIGTERM); |
| 4581 |
(void)sigaddset(&all_signals, SIGHUP); |
| 4582 |
(void)sigaddset(&all_signals, SIGCHLD); |
| 4583 |
(void)sigaddset(&all_signals, SIGALRM); |
| 4584 |
(void)sigaddset(&all_signals, SIGUSR1); |
| 4585 |
(void)sigaddset(&all_signals, SIGSEGV); |
| 4586 |
|
| 4587 |
} |
| 4588 |
|
| 4589 |
|
| 4590 |
/* |
| 4591 |
* Mid-level signal handlers. These are called from within read_events(), |
| 4592 |
* and do the actual work appropriate for the given signal. |
| 4593 |
*/ |
| 4594 |
|
| 4595 |
/* |
| 4596 |
* Process-related routines. Call set_chld(xchild *) to indicate |
| 4597 |
* that a given child process should be watched for when it |
| 4598 |
* terminates. Call clear_chld() to remove the process from the |
| 4599 |
* list. When the child terminates, the record is removed from |
| 4600 |
* the list and xchild->proc is called. |
| 4601 |
* The caller can set the `io' member in xchild to a pointer to |
| 4602 |
* an xio structure for reading from the file descriptor; see |
| 4603 |
* psgs.c and util.c for examples. |
| 4604 |
*/ |
| 4605 |
|
| 4606 |
static struct xchild *child_recs = NULL; /* head of child process list */ |
| 4607 |
|
| 4608 |
void |
| 4609 |
set_chld(struct xchild *cp) |
| 4610 |
{ |
| 4611 |
cp->next = child_recs; |
| 4612 |
child_recs = cp; |
| 4613 |
} |
| 4614 |
|
| 4615 |
void |
| 4616 |
clear_chld(struct xchild *cp) |
| 4617 |
{ |
| 4618 |
struct xchild **cpp; |
| 4619 |
struct xchild *cp2; |
| 4620 |
|
| 4621 |
if (child_recs == NULL) { |
| 4622 |
if (globals.debug & DBG_EVENT) |
| 4623 |
fprintf(stderr, "child_recs: %p\n", (void *)child_recs); |
| 4624 |
return; |
| 4625 |
} |
| 4626 |
for (cpp = &child_recs;;) { |
| 4627 |
cp2 = *cpp; |
| 4628 |
if (cp2 == cp) |
| 4629 |
break; |
| 4630 |
cpp = &cp2->next; |
| 4631 |
} |
| 4632 |
*cpp = cp->next; |
| 4633 |
} |
| 4634 |
|
| 4635 |
static void |
| 4636 |
do_sigchld(void) |
| 4637 |
{ |
| 4638 |
pid_t pid; |
| 4639 |
int status; |
| 4640 |
|
| 4641 |
sig_flags &= ~SF_CHLD; |
| 4642 |
|
| 4643 |
#if ! HAVE_SIGACTION |
| 4644 |
(void) signal(SIGCHLD, handle_sigchld); /* reset the signal */ |
| 4645 |
#endif |
| 4646 |
for (;;) { |
| 4647 |
#if HAVE_WAITPID |
| 4648 |
pid = waitpid(-1, &status, WNOHANG); |
| 4649 |
#else |
| 4650 |
pid = wait3(&status, WNOHANG, NULL); |
| 4651 |
#endif |
| 4652 |
if (pid == 0) break; |
| 4653 |
|
| 4654 |
if (pid != -1) { |
| 4655 |
struct xchild **cpp; |
| 4656 |
struct xchild *cp; |
| 4657 |
|
| 4658 |
for (cpp = &child_recs;;) { |
| 4659 |
cp = *cpp; |
| 4660 |
if (cp == NULL) |
| 4661 |
break; |
| 4662 |
if (cp->pid == pid) { |
| 4663 |
*cpp = cp->next; /* unlink it */ |
| 4664 |
/* call exit reporting procedure for this child */ |
| 4665 |
(cp->proc)(status, cp); |
| 4666 |
break; |
| 4667 |
} |
| 4668 |
cpp = &cp->next; |
| 4669 |
} |
| 4670 |
break; |
| 4671 |
} |
| 4672 |
|
| 4673 |
if (errno == EINTR) continue; |
| 4674 |
if (errno == ECHILD) break; |
| 4675 |
#if HAVE_WAITPID |
| 4676 |
perror("xdvi: waitpid"); |
| 4677 |
#else |
| 4678 |
perror("xdvi: wait3"); |
| 4679 |
#endif |
| 4680 |
break; |
| 4681 |
} |
| 4682 |
} |
| 4683 |
|
| 4684 |
|
| 4685 |
/* |
| 4686 |
* File-related routines. Call set_io() to indicate that a given fd |
| 4687 |
* should be watched for ability to input or output data. Call clear_io() |
| 4688 |
* to remove it from the list. When poll()/select() indicates that the fd |
| 4689 |
* is available for the indicated type of i/o, the corresponding routine |
| 4690 |
* is called. Call clear_io() to remove an fd from the list. |
| 4691 |
* Both set_io() and clear_io() can be called from within read_proc or |
| 4692 |
* write_proc (although turning an io descriptor on or off is better |
| 4693 |
* accomplished by setting the events flag in the xio structure, and |
| 4694 |
* in the corresponding pollfd structure if the pfd pointer is not NULL |
| 4695 |
* (it is always non-NULL when read_proc and write_proc are called)). |
| 4696 |
* We allocate space for one additional record in the pollfd array, to |
| 4697 |
* accommodate the fd for the X connection; this is done by initializing |
| 4698 |
* num_fds to 1 instead of zero. |
| 4699 |
*/ |
| 4700 |
|
| 4701 |
static struct xio *iorecs = NULL; /* head of xio list */ |
| 4702 |
|
| 4703 |
#if HAVE_POLL |
| 4704 |
static struct pollfd *fds = NULL; |
| 4705 |
static int num_fds = 1; /* current number of fds */ |
| 4706 |
static int max_fds = 0; /* max allocated number of fds */ |
| 4707 |
static Boolean io_dirty= True; /* need to recompute fds[] array */ |
| 4708 |
#else |
| 4709 |
static int numfds = 0; |
| 4710 |
static fd_set readfds; |
| 4711 |
static fd_set writefds; |
| 4712 |
#endif |
| 4713 |
|
| 4714 |
void |
| 4715 |
set_io(struct xio *ip) |
| 4716 |
{ |
| 4717 |
ip->next = iorecs; |
| 4718 |
iorecs = ip; |
| 4719 |
|
| 4720 |
#if HAVE_POLL |
| 4721 |
++num_fds; |
| 4722 |
if (!io_dirty && num_fds <= max_fds) { |
| 4723 |
fds[num_fds - 1].fd = ip->fd; |
| 4724 |
fds[num_fds - 1].events = ip->xio_events; |
| 4725 |
ip->pfd = &fds[num_fds - 1]; |
| 4726 |
} |
| 4727 |
else { |
| 4728 |
ip->pfd = NULL; |
| 4729 |
io_dirty = True; |
| 4730 |
} |
| 4731 |
#else |
| 4732 |
if (numfds <= ip->fd) numfds = ip->fd + 1; |
| 4733 |
#endif |
| 4734 |
} |
| 4735 |
|
| 4736 |
void |
| 4737 |
clear_io(struct xio *ip) |
| 4738 |
{ |
| 4739 |
struct xio **ipp; |
| 4740 |
|
| 4741 |
for (ipp = &iorecs;;) { |
| 4742 |
struct xio *ip2; |
| 4743 |
|
| 4744 |
ip2 = *ipp; |
| 4745 |
if (ip2 == ip) break; |
| 4746 |
ipp = &ip2->next; |
| 4747 |
} |
| 4748 |
*ipp = ip->next; |
| 4749 |
|
| 4750 |
#if HAVE_POLL |
| 4751 |
--num_fds; |
| 4752 |
io_dirty = True; |
| 4753 |
#else |
| 4754 |
# if FLAKY_SIGPOLL |
| 4755 |
numfds = ConnectionNumber(DISP); |
| 4756 |
# else |
| 4757 |
numfds = (event_freq < 0 ? -1 : ConnectionNumber(DISP)); |
| 4758 |
# endif |
| 4759 |
for (ip = iorecs; ip != NULL; ip = ip->next) |
| 4760 |
if (ip->fd > numfds) |
| 4761 |
numfds = ip->fd; |
| 4762 |
++numfds; |
| 4763 |
#endif /* !HAVE_POLL */ |
| 4764 |
} |
| 4765 |
|
| 4766 |
static void |
| 4767 |
do_sigpoll(void) |
| 4768 |
{ |
| 4769 |
#if FLAKY_SIGPOLL |
| 4770 |
sig_flags &= ~SF_POLL; |
| 4771 |
#else |
| 4772 |
struct xio *ip; |
| 4773 |
|
| 4774 |
sig_flags &= ~SF_POLL; |
| 4775 |
|
| 4776 |
# if HAVE_POLL |
| 4777 |
|
| 4778 |
if (io_dirty) { |
| 4779 |
struct pollfd *fp; |
| 4780 |
|
| 4781 |
if (num_fds > max_fds) { |
| 4782 |
if (fds != NULL) free(fds); |
| 4783 |
fds = xmalloc(num_fds * sizeof *fds); |
| 4784 |
memset(fds, 0, num_fds * sizeof *fds); |
| 4785 |
max_fds = num_fds; |
| 4786 |
fds->fd = ConnectionNumber(DISP); |
| 4787 |
fds->events = POLLIN; |
| 4788 |
} |
| 4789 |
fp = fds + 1; |
| 4790 |
for (ip = iorecs; ip != NULL; ip = ip->next) { |
| 4791 |
fp->fd = ip->fd; |
| 4792 |
fp->events = ip->xio_events; |
| 4793 |
ip->pfd = fp; |
| 4794 |
++fp; |
| 4795 |
} |
| 4796 |
io_dirty = False; |
| 4797 |
} |
| 4798 |
|
| 4799 |
for (;;) { |
| 4800 |
if (poll(fds + 1, num_fds - 1, 0) >= 0) |
| 4801 |
break; |
| 4802 |
|
| 4803 |
if (errno != EAGAIN && errno != EINTR) { |
| 4804 |
perror("xdvi: poll"); |
| 4805 |
return; |
| 4806 |
} |
| 4807 |
} |
| 4808 |
|
| 4809 |
for (ip = iorecs; ip != NULL; ip = ip->next) { |
| 4810 |
int revents = ip->pfd->revents; |
| 4811 |
if (revents & POLLIN && ip->read_proc != NULL) |
| 4812 |
(void)(ip->read_proc)(ip->fd, ip->data); |
| 4813 |
if (revents & POLLOUT && ip->write_proc != NULL) |
| 4814 |
(ip->write_proc)(ip->fd, ip->data); |
| 4815 |
} |
| 4816 |
|
| 4817 |
# else |
| 4818 |
|
| 4819 |
FD_ZERO(&readfds); |
| 4820 |
FD_ZERO(&writefds); |
| 4821 |
for (ip = iorecs; ip != NULL; ip = ip->next) { |
| 4822 |
if (ip->xio_events & XIO_IN) |
| 4823 |
FD_SET(ip->fd, &readfds); |
| 4824 |
if (ip->xio_events & XIO_OUT) |
| 4825 |
FD_SET(ip->fd, &writefds); |
| 4826 |
} |
| 4827 |
|
| 4828 |
for (;;) { |
| 4829 |
struct timeval tv; |
| 4830 |
|
| 4831 |
tv.tv_sec = tv.tv_usec = 0; |
| 4832 |
if (select(numfds, &readfds, &writefds, (fd_set *) NULL, &tv) >= 0) |
| 4833 |
break; |
| 4834 |
|
| 4835 |
if (errno != EAGAIN && errno != EINTR) { |
| 4836 |
perror("select (xdvi read_events)"); |
| 4837 |
return; |
| 4838 |
} |
| 4839 |
} |
| 4840 |
|
| 4841 |
for (ip = iorecs; ip != NULL; ip = ip->next) { |
| 4842 |
if (FD_ISSET(ip->fd, &readfds) && ip->read_proc != NULL) |
| 4843 |
(void)(ip->read_proc)(ip->fd, ip->data); |
| 4844 |
if (FD_ISSET(ip->fd, &writefds) && ip->write_proc != NULL) |
| 4845 |
(ip->write_proc)(ip->fd, ip->data); |
| 4846 |
} |
| 4847 |
|
| 4848 |
# endif |
| 4849 |
#endif /* not FLAKY_SIGPOLL */ |
| 4850 |
} |
| 4851 |
|
| 4852 |
|
| 4853 |
/* |
| 4854 |
* Timer-related routines. Call set_timer() to set a timer a given number |
| 4855 |
* of milliseconds in the future. At that time, the timer will be cleared |
| 4856 |
* and the given procedure will be called with argument set to the struct |
| 4857 |
* passed to set_timer(). The timer routine may call set_timer() or |
| 4858 |
* cancel_timer(). |
| 4859 |
*/ |
| 4860 |
|
| 4861 |
|
| 4862 |
static struct xtimer *timers = NULL; /* head of timer list */ |
| 4863 |
|
| 4864 |
static struct itimerval itv = {{0, 0}, {0, 0}}; |
| 4865 |
|
| 4866 |
#ifndef timercmp |
| 4867 |
#define timercmp(a, b, OP) (((a)->tv_sec OP (b)->tv_sec || \ |
| 4868 |
((a)->tv_sec == (b)->tv_sec && (a)->tv_usec OP (b)->tv_usec))) |
| 4869 |
#endif /* timercmp */ |
| 4870 |
|
| 4871 |
|
| 4872 |
static void |
| 4873 |
show_timers(const char *what) |
| 4874 |
{ |
| 4875 |
struct xtimer *tp; |
| 4876 |
fprintf(stderr, "=======%s; timers:\n", what); |
| 4877 |
for (tp = timers; tp != NULL; tp = tp->next) { |
| 4878 |
fprintf(stderr, "timer %p: %lu\n", (void *)tp, (unsigned long)tp->when.tv_sec); |
| 4879 |
} |
| 4880 |
fprintf(stderr, "=======\n"); |
| 4881 |
} |
| 4882 |
|
| 4883 |
void |
| 4884 |
set_timer(struct xtimer *tp, int ms) |
| 4885 |
{ |
| 4886 |
struct xtimer **tpp; |
| 4887 |
struct xtimer *tp2; |
| 4888 |
|
| 4889 |
if (globals.debug & DBG_EVENT) |
| 4890 |
fprintf(stderr, "%s:%d: set_timer\n", __FILE__, __LINE__); |
| 4891 |
|
| 4892 |
gettimeofday(&tp->when, NULL); |
| 4893 |
itv.it_value.tv_sec = ms / 1000; |
| 4894 |
itv.it_value.tv_usec = (ms % 1000) * 1000; |
| 4895 |
tp->when.tv_sec += itv.it_value.tv_sec; |
| 4896 |
tp->when.tv_usec += itv.it_value.tv_usec; |
| 4897 |
if (tp->when.tv_usec >= 1000000) { |
| 4898 |
tp->when.tv_usec -= 1000000; |
| 4899 |
++tp->when.tv_sec; |
| 4900 |
} |
| 4901 |
|
| 4902 |
for (tpp = &timers;;) { /* add timer to list */ |
| 4903 |
tp2 = *tpp; |
| 4904 |
if (tp2 == NULL || timercmp(&tp->when, &tp2->when, <)) |
| 4905 |
break; |
| 4906 |
tpp = &tp2->next; |
| 4907 |
} |
| 4908 |
tp->next = tp2; |
| 4909 |
*tpp = tp; |
| 4910 |
|
| 4911 |
if (tpp == &timers) { |
| 4912 |
setitimer(ITIMER_REAL, &itv, NULL); |
| 4913 |
if (ms == 0) |
| 4914 |
sig_flags |= SF_ALRM; |
| 4915 |
} |
| 4916 |
if (globals.debug & DBG_EVENT) |
| 4917 |
show_timers("after set_timer"); |
| 4918 |
} |
| 4919 |
|
| 4920 |
void |
| 4921 |
cancel_timer(struct xtimer *tp) |
| 4922 |
{ |
| 4923 |
struct xtimer **tpp; |
| 4924 |
|
| 4925 |
if (globals.debug & DBG_EVENT) |
| 4926 |
show_timers("beginning of cancel_timer"); |
| 4927 |
|
| 4928 |
if (timers == NULL) { |
| 4929 |
fprintf(stderr, "%s:%d: BUG? timers == NULL!\n", __FILE__, __LINE__); |
| 4930 |
return; |
| 4931 |
} |
| 4932 |
|
| 4933 |
if (globals.debug & DBG_EVENT) |
| 4934 |
fprintf(stderr, "%s:%d: cancel_timer %p from %p\n", __FILE__, __LINE__, (void *)&timers, (void *)tp); |
| 4935 |
|
| 4936 |
ASSERT(timers != NULL, "timers in cancel_timer() mustn't be NULL"); |
| 4937 |
for (tpp = &timers; ; ) { /* remove from list */ |
| 4938 |
if (*tpp == tp) |
| 4939 |
break; |
| 4940 |
tpp = &(*tpp)->next; |
| 4941 |
} |
| 4942 |
|
| 4943 |
*tpp = (*tpp)->next; /* unlink it */ |
| 4944 |
|
| 4945 |
if (timers == NULL) { /* cancel SIGALRM */ |
| 4946 |
itv.it_value.tv_sec = itv.it_value.tv_usec = 0; |
| 4947 |
setitimer(ITIMER_REAL, &itv, NULL); |
| 4948 |
} |
| 4949 |
} |
| 4950 |
|
| 4951 |
#if XDVI_XT_TIMER_HACK |
| 4952 |
/* |
| 4953 |
* Original comment by Paul: |
| 4954 |
* Newer versions of the Motif toolkit use the timer facility |
| 4955 |
* (XtAppAddTimeOut(), etc.) in the X Toolkit. Proper functioning of |
| 4956 |
* this mechanism, however, requires that the X Toolkit be in charge of |
| 4957 |
* blocking. Since xdvi does its own blocking, this means that we need |
| 4958 |
* to provide working alternatives to these X Toolkit routines (by |
| 4959 |
* redefining them ...). |
| 4960 |
* One symptom of the above-mentioned bug is that the printlog window |
| 4961 |
* eventually stops showing dvips progress until you move the mouse. |
| 4962 |
* |
| 4963 |
* Comment SU: |
| 4964 |
* Xdvik also uses XtAppAddTimeOut() in other places (hyperref/statusline/...), |
| 4965 |
* so we also need these redefinitions also in the Xaw version. |
| 4966 |
* |
| 4967 |
*/ |
| 4968 |
|
| 4969 |
static void xt_alarm(struct xtimer *this, void *data); |
| 4970 |
|
| 4971 |
static struct xtimer *xt_free_timers = NULL; |
| 4972 |
|
| 4973 |
XtIntervalId |
| 4974 |
XtAddTimeOut(unsigned long interval, XtTimerCallbackProc proc, XtPointer closure) |
| 4975 |
{ |
| 4976 |
return XtAppAddTimeOut(NULL, interval, proc, closure); |
| 4977 |
} |
| 4978 |
|
| 4979 |
XtIntervalId |
| 4980 |
XtAppAddTimeOut(XtAppContext app, unsigned long interval, XtTimerCallbackProc proc, XtPointer closure) |
| 4981 |
{ |
| 4982 |
struct xtimer *tp; |
| 4983 |
|
| 4984 |
UNUSED(app); |
| 4985 |
|
| 4986 |
/* FIXME: better way of checking this instead of static boolean sigalarm_initialized? |
| 4987 |
The following doesn't work, even after |
| 4988 |
sigaddset(&all_signals, SIGALRM); |
| 4989 |
|
| 4990 |
static sigset_t sig_set; |
| 4991 |
(void)sigprocmask(0, NULL, &sig_set); |
| 4992 |
if (sigismember(&sig_set, SIGALRM)) |
| 4993 |
... OK ... |
| 4994 |
else |
| 4995 |
... NOT OK ... |
| 4996 |
*/ |
| 4997 |
ASSERT(sigalarm_initialized, "Shouldn't invoke XtAppAddTimeOut() before setup_sigalarm()"); |
| 4998 |
|
| 4999 |
if (globals.debug & DBG_EVENT) |
| 5000 |
fprintf(stderr, "XtAppAddTimeOut: %lu msecs\n", interval); |
| 5001 |
|
| 5002 |
if (xt_free_timers == NULL) |
| 5003 |
tp = xmalloc(sizeof *tp); |
| 5004 |
else { |
| 5005 |
tp = xt_free_timers; |
| 5006 |
xt_free_timers = xt_free_timers->next; |
| 5007 |
} |
| 5008 |
|
| 5009 |
tp->proc = xt_alarm; |
| 5010 |
tp->data = closure; |
| 5011 |
tp->xt_proc = proc; |
| 5012 |
tp->closure = closure; |
| 5013 |
|
| 5014 |
set_timer(tp, interval); |
| 5015 |
|
| 5016 |
if (globals.debug & DBG_EVENT) |
| 5017 |
show_timers("XtAppAddTimeOut"); |
| 5018 |
|
| 5019 |
return (XtIntervalId)tp; |
| 5020 |
} |
| 5021 |
|
| 5022 |
void |
| 5023 |
XtRemoveTimeOut(XtIntervalId id) |
| 5024 |
{ |
| 5025 |
struct xtimer *tp; |
| 5026 |
|
| 5027 |
ASSERT(id != 0, "XtIntervalId argument in XtRemoveTimeOut() mustn't be NULL"); |
| 5028 |
tp = (struct xtimer *)id; |
| 5029 |
|
| 5030 |
/* Motif (2.1 on Solaris 9, 2003) sometimes calls XtRemoveTimeOut() after |
| 5031 |
the timer event has occurred, so we need to be sure not to remove |
| 5032 |
the timer record twice. */ |
| 5033 |
if (tp->proc == NULL) |
| 5034 |
return; |
| 5035 |
|
| 5036 |
cancel_timer(tp); |
| 5037 |
|
| 5038 |
tp->next = xt_free_timers; |
| 5039 |
xt_free_timers = tp; |
| 5040 |
|
| 5041 |
if (globals.debug & DBG_EVENT) |
| 5042 |
show_timers("XtRemoveTimeOut"); |
| 5043 |
} |
| 5044 |
|
| 5045 |
void |
| 5046 |
xt_alarm(struct xtimer *tp, void *data) |
| 5047 |
{ |
| 5048 |
XtIntervalId id; |
| 5049 |
UNUSED(data); |
| 5050 |
|
| 5051 |
tp->proc = NULL; /* flag timer as used-up */ |
| 5052 |
id = (XtIntervalId)tp; |
| 5053 |
(tp->xt_proc)(tp->closure, &id); |
| 5054 |
|
| 5055 |
tp->next = xt_free_timers; |
| 5056 |
xt_free_timers = tp; |
| 5057 |
|
| 5058 |
if (globals.debug & DBG_EVENT) |
| 5059 |
show_timers("xt_alarm"); |
| 5060 |
} |
| 5061 |
#endif /* XDVI_XT_TIMER_HACK */ |
| 5062 |
|
| 5063 |
static void |
| 5064 |
do_sigalrm(void) |
| 5065 |
{ |
| 5066 |
struct timeval now; |
| 5067 |
|
| 5068 |
sig_flags &= ~SF_ALRM; |
| 5069 |
#ifndef HAVE_SIGACTION |
| 5070 |
(void) signal(SIGALRM, handle_sigalrm); /* reset the signal */ |
| 5071 |
#endif |
| 5072 |
|
| 5073 |
gettimeofday(&now, NULL); |
| 5074 |
|
| 5075 |
while (timers != NULL && timercmp(&timers->when, &now, <=)) { |
| 5076 |
struct xtimer *tp = timers; |
| 5077 |
timers = timers->next; /* unlink it _first_ */ |
| 5078 |
(tp->proc)(tp, tp->data); |
| 5079 |
} |
| 5080 |
|
| 5081 |
if (timers != NULL) { /* set next timer */ |
| 5082 |
int i; |
| 5083 |
itv.it_value.tv_sec = timers->when.tv_sec - now.tv_sec; |
| 5084 |
i = timers->when.tv_usec - now.tv_usec; |
| 5085 |
if (i < 0) { |
| 5086 |
--itv.it_value.tv_sec; |
| 5087 |
i += 1000000; |
| 5088 |
} |
| 5089 |
itv.it_value.tv_usec = i; |
| 5090 |
|
| 5091 |
setitimer(ITIMER_REAL, &itv, NULL); |
| 5092 |
} |
| 5093 |
} |
| 5094 |
|
| 5095 |
|
| 5096 |
|
| 5097 |
/* |
| 5098 |
* Handle SIGUSR1 signal. Pretty straightforward. |
| 5099 |
*/ |
| 5100 |
|
| 5101 |
static void |
| 5102 |
do_sigusr(void) |
| 5103 |
{ |
| 5104 |
sig_flags &= ~SF_USR; |
| 5105 |
#ifndef HAVE_SIGACTION |
| 5106 |
(void) signal(SIGUSR1, handle_sigusr); /* reset the signal */ |
| 5107 |
#endif |
| 5108 |
globals.ev.flags |= EV_RELOAD; |
| 5109 |
} |
| 5110 |
|
| 5111 |
|
| 5112 |
static void |
| 5113 |
do_sigsegv(void) |
| 5114 |
{ |
| 5115 |
sig_flags &= ~SF_SEGV; |
| 5116 |
#ifndef HAVE_SIGACTION |
| 5117 |
(void) signal(SIGSEGV, handle_sigsegv); /* reset the signal */ |
| 5118 |
#endif |
| 5119 |
handle_sigsegv(SIGSEGV); |
| 5120 |
} |
| 5121 |
|
| 5122 |
|
| 5123 |
/* |
| 5124 |
* Handle termination signals. Just call xdvi_exit, which does all the |
| 5125 |
* work, since that is the common exit point. |
| 5126 |
*/ |
| 5127 |
|
| 5128 |
static void |
| 5129 |
do_sigterm(void) |
| 5130 |
{ |
| 5131 |
sig_flags &= ~SF_TERM; |
| 5132 |
|
| 5133 |
xdvi_exit(EXIT_SUCCESS); |
| 5134 |
} |
| 5135 |
|
| 5136 |
/* |
| 5137 |
* This routine should be used for all exits. (SU: This is different |
| 5138 |
* from non-k xdvi, where it's only used for `non-early' exits; all |
| 5139 |
* routines called here should be aware of their own state and either |
| 5140 |
* perform cleanup or just return, unless xdvi_exit() itself checks for |
| 5141 |
* the status). |
| 5142 |
*/ |
| 5143 |
|
| 5144 |
void |
| 5145 |
xdvi_exit(int status) |
| 5146 |
{ |
| 5147 |
struct xchild *cp; |
| 5148 |
|
| 5149 |
/* do the following only if the window has been opened: */ |
| 5150 |
if (globals.widgets.top_level != 0 && XtIsRealized(globals.widgets.top_level)) { |
| 5151 |
char *filehist; |
| 5152 |
file_history_set_page(current_page); |
| 5153 |
filehist = file_history_get_list(); |
| 5154 |
store_preference(NULL, "fileHistory", "%s", filehist); |
| 5155 |
free(filehist); |
| 5156 |
|
| 5157 |
#if MOTIF |
| 5158 |
if (preferences_changed()) { |
| 5159 |
return; |
| 5160 |
} |
| 5161 |
/* else { */ |
| 5162 |
/* fprintf(stderr, "Preferences not changed.\n"); */ |
| 5163 |
/* } */ |
| 5164 |
#endif |
| 5165 |
/* try to save user preferences, unless we're exiting with an error */ |
| 5166 |
if (status == EXIT_SUCCESS && !save_user_preferences(True)) |
| 5167 |
return; |
| 5168 |
|
| 5169 |
/* Clean up the "xdvi windows" property in the root window. */ |
| 5170 |
update_window_property(XtWindow(globals.widgets.top_level), False); |
| 5171 |
} |
| 5172 |
|
| 5173 |
#if PS |
| 5174 |
ps_destroy_nofree(); |
| 5175 |
#endif |
| 5176 |
|
| 5177 |
/* loop through child processes */ |
| 5178 |
for (cp = child_recs; cp != NULL; cp = cp->next) { |
| 5179 |
if (cp->killsig > 0) |
| 5180 |
kill(cp->pid, cp->killsig); |
| 5181 |
else if (cp->killsig < 0) |
| 5182 |
kill(-cp->pid, -cp->killsig); |
| 5183 |
} |
| 5184 |
|
| 5185 |
call_exit_handlers(); |
| 5186 |
|
| 5187 |
exit(status); |
| 5188 |
} |
| 5189 |
|
| 5190 |
|
| 5191 |
#if HAVE_XI21 |
| 5192 |
|
| 5193 |
/* |
| 5194 |
* XInput 2.1 event processing. |
| 5195 |
* |
| 5196 |
* The XInput system has (virtual) "master" devices, including a master |
| 5197 |
* pointer and master keyboard (and maybe others), and "slave" devices |
| 5198 |
* that can be assigned to a master. Each master can have only one slave |
| 5199 |
* at a time. If you have two mice plugged in, for example, each is a |
| 5200 |
* separate slave device, and the one assigned to the master pointer device |
| 5201 |
* is whichever one was moved or clicked most recently. Moving or clicking |
| 5202 |
* the other mouse would then cause an XInput SlaveSwitch event, which |
| 5203 |
* notifies the X client that a different pointer is now active (and the |
| 5204 |
* previously active mouse would then become inactive). |
| 5205 |
* |
| 5206 |
* The code here looks not just at events from the master pointer, it also |
| 5207 |
* tracks events from the slave pointer devices. This is because the |
| 5208 |
* valuators for each slave pointer may have different scales. |
| 5209 |
* |
| 5210 |
* The XI_Motion events contain the master and slave ids of the device |
| 5211 |
* sending the event, so in principle it wouldn't be necessary to track |
| 5212 |
* SlaveSwitch events. However, we do track these events, because we need |
| 5213 |
* to know the valuator values at the time of the switch (otherwise, e.g., |
| 5214 |
* the first click of a wheel mouse would be lost). |
| 5215 |
* |
| 5216 |
* It is also possible that a valuator may change while the pointer is |
| 5217 |
* outside of the drawing window. So, we need to reset the valuator |
| 5218 |
* values upon XI_Enter events. For some strange reason, we get extra |
| 5219 |
* XI_Enter events when using a traditional wheel mouse, and so the code |
| 5220 |
* takes care to ignore those. This only happens with the Xaw toolkit. |
| 5221 |
* |
| 5222 |
* Slave devices have events that notify clients when they are (i) added |
| 5223 |
* or removed, (ii) attached or detached, and (iii) enabled or disabled. |
| 5224 |
* We only worry about (iii), and for disabled devices we don't bother to |
| 5225 |
* delete the data structure. |
| 5226 |
* |
| 5227 |
*/ |
| 5228 |
|
| 5229 |
/* |
| 5230 |
* xi2_find_master: set xi2_current to record for given device id |
| 5231 |
* Return True if found, False if not. |
| 5232 |
*/ |
| 5233 |
|
| 5234 |
static Boolean |
| 5235 |
xi2_find_master(int id) |
| 5236 |
{ |
| 5237 |
struct xi2_master *mp; |
| 5238 |
|
| 5239 |
for (mp = xi2_masters; mp != NULL; mp = mp->next) |
| 5240 |
if (mp->id == id) { |
| 5241 |
xi2_current = mp; |
| 5242 |
return True; |
| 5243 |
} |
| 5244 |
return False; |
| 5245 |
} |
| 5246 |
|
| 5247 |
/* |
| 5248 |
* xi2_find_slave: set xi2_current->slave to record for given slave device |
| 5249 |
* Return True if found, False if not. |
| 5250 |
*/ |
| 5251 |
|
| 5252 |
static Boolean |
| 5253 |
xi2_find_slave(int id) |
| 5254 |
{ |
| 5255 |
struct xi2_slave *sp; |
| 5256 |
|
| 5257 |
for (sp = xi2_slaves; sp != NULL; sp = sp->next) |
| 5258 |
if (sp->id == id) { |
| 5259 |
xi2_current->slave = sp; |
| 5260 |
return True; |
| 5261 |
} |
| 5262 |
return False; |
| 5263 |
} |
| 5264 |
|
| 5265 |
/* |
| 5266 |
* Handle XI2 Enter event. We need to look at these events because if the |
| 5267 |
* user scrolls in some other window, then the valuator will be changed |
| 5268 |
* by a large amount, and that scrolling should not occur also in the |
| 5269 |
* main xdvi window when the user resumes scrolling here. |
| 5270 |
*/ |
| 5271 |
|
| 5272 |
static void |
| 5273 |
xi2_ev_enter(XIEnterEvent *xi_event) |
| 5274 |
{ |
| 5275 |
XIDeviceInfo *info; |
| 5276 |
int ndevices; |
| 5277 |
int i; |
| 5278 |
|
| 5279 |
if (xi_event->time < xi2_ign_time + 5) { |
| 5280 |
TRACE_EVENTS((stderr, "Ignoring XI_Enter event as spurious.")); |
| 5281 |
return; |
| 5282 |
} |
| 5283 |
|
| 5284 |
if (xi2_current->id != xi_event->deviceid |
| 5285 |
&& !xi2_find_master(xi_event->deviceid)) { |
| 5286 |
TRACE_EVENTS((stderr, |
| 5287 |
"Ignoring XI_Enter event: master device %d not found", |
| 5288 |
xi_event->deviceid)); |
| 5289 |
return; |
| 5290 |
} |
| 5291 |
|
| 5292 |
if (xi_event->sourceid == xi2_current->id) { |
| 5293 |
TRACE_EVENTS((stderr, |
| 5294 |
"Ignoring XI_Enter event for master device.")); |
| 5295 |
return; |
| 5296 |
} |
| 5297 |
else if (xi_event->sourceid != xi2_current->slave->id) { |
| 5298 |
struct xi2_slave *prev_slave = xi2_current->slave; |
| 5299 |
|
| 5300 |
if (!xi2_find_slave(xi_event->sourceid)) { |
| 5301 |
TRACE_EVENTS((stderr, |
| 5302 |
"Ignoring XI_Enter event: device %d->%d not found.", |
| 5303 |
xi_event->deviceid, xi_event->sourceid)); |
| 5304 |
return; |
| 5305 |
} |
| 5306 |
TRACE_EVENTS((stderr, |
| 5307 |
"%s %d->%d", |
| 5308 |
prev_slave == &xi2_no_slave |
| 5309 |
? "Implicit switch in XI_Enter to" |
| 5310 |
: "Received out-of-turn XI_Enter event for", |
| 5311 |
xi_event->deviceid, xi_event->sourceid)); |
| 5312 |
if (!xi2_current->slave->enabled) |
| 5313 |
TRACE_EVENTS((stderr, "Caution: slave is not enabled.")); |
| 5314 |
} |
| 5315 |
else { |
| 5316 |
TRACE_EVENTS((stderr, "Received XI_Enter event")); |
| 5317 |
} |
| 5318 |
|
| 5319 |
info = XIQueryDevice(DISP, xi_event->sourceid, &ndevices); |
| 5320 |
if (info == NULL || ndevices != 1) { |
| 5321 |
TRACE_EVENTS((stderr, "xi2_ev_enter: XIQueryDevice failed for %d", |
| 5322 |
xi_event->sourceid)); |
| 5323 |
return; |
| 5324 |
} |
| 5325 |
|
| 5326 |
for (i = 0; i < info->num_classes; ++i) |
| 5327 |
if (info->classes[i]->type == XIValuatorClass) { |
| 5328 |
XIValuatorClassInfo *valuator; |
| 5329 |
|
| 5330 |
valuator = (XIValuatorClassInfo *) info->classes[i]; |
| 5331 |
if (valuator->number == xi2_current->slave->vert.number) { |
| 5332 |
xi2_current->slave->vert.lastexact = |
| 5333 |
xi2_current->slave->vert.lastval = valuator->value; |
| 5334 |
xi2_current->slave->vert.serial = |
| 5335 |
LastKnownRequestProcessed(DISP); |
| 5336 |
} |
| 5337 |
else if (valuator->number == xi2_current->slave->horiz.number) { |
| 5338 |
xi2_current->slave->horiz.lastexact = |
| 5339 |
xi2_current->slave->horiz.lastval = valuator->value; |
| 5340 |
xi2_current->slave->horiz.serial = |
| 5341 |
LastKnownRequestProcessed(DISP); |
| 5342 |
} |
| 5343 |
} |
| 5344 |
XIFreeDeviceInfo(info); |
| 5345 |
} |
| 5346 |
|
| 5347 |
static void |
| 5348 |
xi2_emulate_action(struct xdvi_action *actp, struct xi2_valinfo *valinfo, |
| 5349 |
double value) |
| 5350 |
{ |
| 5351 |
double factor; |
| 5352 |
int dist; |
| 5353 |
|
| 5354 |
for (; actp != NULL; actp = actp->next) { |
| 5355 |
if (actp->proc == Act_wheel || actp->proc == Act_hwheel) { |
| 5356 |
if (actp->num_params == 0) |
| 5357 |
factor = resource.wheel_unit; |
| 5358 |
else if (index(actp->params[0], '.') == NULL) |
| 5359 |
factor = atoi(actp->params[0]); |
| 5360 |
else |
| 5361 |
factor = atof(actp->params[0]) * resource.wheel_unit; |
| 5362 |
factor /= valinfo->increment; |
| 5363 |
|
| 5364 |
if (valinfo->factor != fabs(factor)) { |
| 5365 |
valinfo->lastval = valinfo->lastexact; |
| 5366 |
valinfo->factor = fabs(factor); |
| 5367 |
} |
| 5368 |
|
| 5369 |
/* |
| 5370 |
* In extreme cases, the server may reset the valuator to zero |
| 5371 |
* to avoid large values. The next few lines avoid the extreme |
| 5372 |
* scrolling event that would otherwise occur in this event. |
| 5373 |
*/ |
| 5374 |
if (fabs(value - valinfo->lastval) > INT_MAX / 2) { |
| 5375 |
valinfo->lastval += |
| 5376 |
value > valinfo->lastval ? INT_MAX : -INT_MAX; |
| 5377 |
TRACE_EVENTS((stderr, |
| 5378 |
"Adjusted for pointer overflow; lastval = %g, new = %g\n", |
| 5379 |
valinfo->lastval, value)); |
| 5380 |
} |
| 5381 |
|
| 5382 |
dist = (value - valinfo->lastval) * factor; |
| 5383 |
if (dist == 0) { |
| 5384 |
valinfo->lastexact = value; |
| 5385 |
continue; |
| 5386 |
} |
| 5387 |
|
| 5388 |
if (actp->proc == Act_wheel) { |
| 5389 |
# if !MOTIF |
| 5390 |
if (globals.widgets.y_bar != NULL) |
| 5391 |
XtCallCallbacks(globals.widgets.y_bar, XtNscrollProc, |
| 5392 |
cast_int_to_XtPointer(dist)); |
| 5393 |
# else /* MOTIF */ |
| 5394 |
get_xy(); |
| 5395 |
set_bar_value(globals.widgets.y_bar, |
| 5396 |
dist - m_window_y, (int) (globals.page.h - mane.height)); |
| 5397 |
# endif /* MOTIF */ |
| 5398 |
} |
| 5399 |
else { /* Act_hwheel */ |
| 5400 |
# if !MOTIF |
| 5401 |
if (globals.widgets.x_bar != NULL) |
| 5402 |
XtCallCallbacks(globals.widgets.x_bar, XtNscrollProc, |
| 5403 |
cast_int_to_XtPointer(dist)); |
| 5404 |
# else /* MOTIF */ |
| 5405 |
get_xy(); |
| 5406 |
set_bar_value(globals.widgets.x_bar, |
| 5407 |
dist - m_window_x, (int) (globals.page.w - mane.width)); |
| 5408 |
# endif /* MOTIF */ |
| 5409 |
} |
| 5410 |
/* The next line puts back any rounding error */ |
| 5411 |
valinfo->lastval += dist / factor; |
| 5412 |
valinfo->lastexact = value; |
| 5413 |
} |
| 5414 |
else if (actp->proc == Act_mouse_modes) { |
| 5415 |
size_t mode_idx = 0; /* default: one action for all modes */ |
| 5416 |
struct xdvi_action *my_action = NULL; |
| 5417 |
|
| 5418 |
if (actp->num_params > 1) { /* if different actions */ |
| 5419 |
if (resource.mouse_mode >= actp->num_params) { |
| 5420 |
size_t k; |
| 5421 |
|
| 5422 |
XDVI_WARNING((stderr, "X action 'mouse-modes' called " |
| 5423 |
"with only %d parameters, should be %d", |
| 5424 |
actp->num_params, resource.mouse_mode + 1)); |
| 5425 |
for (k = 0; k < actp->num_params; k++) { |
| 5426 |
XDVI_WARNING((stderr, " Param %d: `%s'", |
| 5427 |
(int)(k + 1), actp->params[k])); |
| 5428 |
} |
| 5429 |
return; |
| 5430 |
} |
| 5431 |
mode_idx = resource.mouse_mode; |
| 5432 |
} |
| 5433 |
|
| 5434 |
cached_compile_action(actp->params[mode_idx], &my_action); |
| 5435 |
xi2_emulate_action(my_action, valinfo, value); |
| 5436 |
} |
| 5437 |
else |
| 5438 |
TRACE_EVENTS((stderr, "Mouse_translations action is neither " |
| 5439 |
"wheel() nor hwheel(); ignoring.")); |
| 5440 |
} |
| 5441 |
} |
| 5442 |
|
| 5443 |
static void |
| 5444 |
xi2_do_valuator(XIDeviceEvent *xi_event, struct xi2_valinfo *valinfo, |
| 5445 |
int button, double value) |
| 5446 |
{ |
| 5447 |
struct mouse_acts *mactp; |
| 5448 |
Modifiers state; |
| 5449 |
|
| 5450 |
state = xi_event->buttons.mask[0]; |
| 5451 |
if (xi_event->buttons.mask_len >= 2) { |
| 5452 |
state |= xi_event->buttons.mask[1] << 8; |
| 5453 |
if (xi_event->buttons.mask_len >= 3) { |
| 5454 |
state |= xi_event->buttons.mask[2] << 16; |
| 5455 |
if (xi_event->buttons.mask_len >= 4) |
| 5456 |
state |= xi_event->buttons.mask[3] << 24; |
| 5457 |
} |
| 5458 |
} |
| 5459 |
|
| 5460 |
for (mactp = mouse_actions; mactp != NULL; mactp = mactp->next) |
| 5461 |
if (mactp->button == button || mactp->button == 0) { |
| 5462 |
Modifiers mask = 0; |
| 5463 |
Modifiers mods_value = 0; |
| 5464 |
|
| 5465 |
if (mactp->late_bindings == NULL |
| 5466 |
|| _XtComputeLateBindings(DISP, mactp->late_bindings, |
| 5467 |
&mods_value, &mask)) { |
| 5468 |
mask |= mactp->mask; |
| 5469 |
mods_value |= mactp->value; |
| 5470 |
if (((mods_value ^ state) & mask) == 0) { |
| 5471 |
xi2_emulate_action(mactp->action, valinfo, value); |
| 5472 |
return; |
| 5473 |
} |
| 5474 |
} |
| 5475 |
} |
| 5476 |
} |
| 5477 |
|
| 5478 |
static void |
| 5479 |
xi2_ev_motion(XIDeviceEvent *xi_event) |
| 5480 |
{ |
| 5481 |
double *val; |
| 5482 |
int i; |
| 5483 |
XEvent event; |
| 5484 |
|
| 5485 |
if (xi2_current->id != xi_event->deviceid |
| 5486 |
&& !xi2_find_master(xi_event->deviceid)) { |
| 5487 |
TRACE_EVENTS((stderr, |
| 5488 |
"Ignoring XI_Motion event: master device %d not found", |
| 5489 |
xi_event->deviceid)); |
| 5490 |
return; |
| 5491 |
} |
| 5492 |
|
| 5493 |
if (xi2_current->slave->id != xi_event->sourceid) { |
| 5494 |
struct xi2_slave *prev_slave = xi2_current->slave; |
| 5495 |
|
| 5496 |
if (!xi2_find_slave(xi_event->sourceid)) { |
| 5497 |
TRACE_EVENTS((stderr, |
| 5498 |
"Ignoring XI_Motion event: device %d->%d not found.", |
| 5499 |
xi_event->deviceid, xi_event->sourceid)); |
| 5500 |
return; |
| 5501 |
} |
| 5502 |
TRACE_EVENTS((stderr, "%s %d->%d\n", |
| 5503 |
prev_slave == &xi2_no_slave |
| 5504 |
? "Implicit switch in XI_Motion to" |
| 5505 |
: "Received out-of-turn XI_Motion event for", |
| 5506 |
xi_event->deviceid, xi_event->sourceid)); |
| 5507 |
if (!xi2_current->slave->enabled) |
| 5508 |
TRACE_EVENTS((stderr, "Caution: slave is not enabled.")); |
| 5509 |
} |
| 5510 |
|
| 5511 |
val = xi_event->valuators.values; |
| 5512 |
for (i = 0; i < xi_event->valuators.mask_len * 8; ++i) |
| 5513 |
if (XIMaskIsSet(xi_event->valuators.mask, i)) { |
| 5514 |
if (i == xi2_current->slave->vert.number) { |
| 5515 |
if ((long) (xi_event->serial |
| 5516 |
- xi2_current->slave->vert.serial) < 0) { |
| 5517 |
TRACE_EVENTS((stderr, |
| 5518 |
"Vertical valuator in EnterEvent was outdated " |
| 5519 |
"(%lu < %lu)", |
| 5520 |
xi_event->serial, xi2_current->slave->vert.serial)); |
| 5521 |
xi2_current->slave->vert.serial = xi_event->serial; |
| 5522 |
xi2_current->slave->vert.lastexact = |
| 5523 |
xi2_current->slave->vert.lastval = *val; |
| 5524 |
} |
| 5525 |
else |
| 5526 |
xi2_do_valuator(xi_event, &xi2_current->slave->vert, 5, |
| 5527 |
*val); |
| 5528 |
} |
| 5529 |
else if (i == xi2_current->slave->horiz.number) { |
| 5530 |
if ((long) (xi_event->serial |
| 5531 |
- xi2_current->slave->horiz.serial) < 0) { |
| 5532 |
TRACE_EVENTS((stderr, |
| 5533 |
"Horizontal valuator in EnterEvent was outdated")); |
| 5534 |
xi2_current->slave->horiz.serial = xi_event->serial; |
| 5535 |
xi2_current->slave->horiz.lastexact = |
| 5536 |
xi2_current->slave->horiz.lastval = *val; |
| 5537 |
} |
| 5538 |
else |
| 5539 |
xi2_do_valuator(xi_event, &xi2_current->slave->horiz, 7, |
| 5540 |
*val); |
| 5541 |
} |
| 5542 |
++val; |
| 5543 |
} |
| 5544 |
|
| 5545 |
/* For some reason the X server doesn't want to send a core motion |
| 5546 |
* event if an XInput motion event is already being sent. |
| 5547 |
* So we need to fake it. The routines called from Act_motion() |
| 5548 |
* should be sure to use only the fields provided here. */ |
| 5549 |
event.xmotion.window = xi_event->event; |
| 5550 |
event.xmotion.x = xi_event->event_x; |
| 5551 |
event.xmotion.y = xi_event->event_y; |
| 5552 |
event.xmotion.x_root = xi_event->root_x; |
| 5553 |
event.xmotion.y_root = xi_event->root_y; |
| 5554 |
Act_motion(NULL, &event, NULL, NULL); |
| 5555 |
} |
| 5556 |
|
| 5557 |
static void |
| 5558 |
xi2_ev_devchange(XIDeviceChangedEvent *xi_event) |
| 5559 |
{ |
| 5560 |
struct xi2_slave *sp; |
| 5561 |
|
| 5562 |
if (xi_event->reason == XISlaveSwitch) { |
| 5563 |
struct xi2_master *mp; |
| 5564 |
|
| 5565 |
TRACE_EVENTS((stderr, |
| 5566 |
"Received XI_DeviceChanged event, XISlaveSwitch, device = %d->%d", |
| 5567 |
xi_event->deviceid, xi_event->sourceid)); |
| 5568 |
|
| 5569 |
for (sp = xi2_slaves;; sp = sp->next) { |
| 5570 |
if (sp == NULL) { |
| 5571 |
TRACE_EVENTS((stderr, "ignoring (device not found)")); |
| 5572 |
return; |
| 5573 |
} |
| 5574 |
if (sp->id == xi_event->sourceid) |
| 5575 |
break; |
| 5576 |
} |
| 5577 |
|
| 5578 |
for (mp = xi2_masters;; mp = mp->next) { |
| 5579 |
if (mp == NULL) { |
| 5580 |
TRACE_EVENTS((stderr, |
| 5581 |
"Cannot switch slave (master device not found)")); |
| 5582 |
return; |
| 5583 |
} |
| 5584 |
if (mp->id == xi_event->deviceid) |
| 5585 |
break; |
| 5586 |
} |
| 5587 |
mp->slave = sp; |
| 5588 |
|
| 5589 |
/* A valuator may change when a slave is switched off */ |
| 5590 |
xi2_init_valuators(sp, xi_event->classes, xi_event->num_classes); |
| 5591 |
|
| 5592 |
if (!sp->enabled) |
| 5593 |
TRACE_EVENTS((stderr, "Caution: slave device is not enabled.")); |
| 5594 |
} |
| 5595 |
else if (xi_event->reason == XIDeviceChange) { |
| 5596 |
/* In principle, this will add any device, but there's no "use" */ |
| 5597 |
/* field, so no easy way to check if it's a suitable slave device.*/ |
| 5598 |
TRACE_EVENTS((stderr, |
| 5599 |
"Received XI_DeviceChanged event, XIDeviceChange, device = %d->%d", |
| 5600 |
xi_event->deviceid, xi_event->sourceid)); |
| 5601 |
|
| 5602 |
for (sp = xi2_slaves;; sp = sp->next) { |
| 5603 |
if (sp == NULL) { |
| 5604 |
TRACE_EVENTS((stderr, " (new device)")); |
| 5605 |
sp = xmalloc(sizeof (struct xi2_slave)); |
| 5606 |
sp->id = xi_event->sourceid; |
| 5607 |
sp->enabled = 0; |
| 5608 |
sp->next = xi2_slaves; |
| 5609 |
xi2_slaves = sp; |
| 5610 |
break; |
| 5611 |
} |
| 5612 |
if (sp->id == xi_event->sourceid) |
| 5613 |
break; |
| 5614 |
} |
| 5615 |
|
| 5616 |
xi2_init_valuators(sp, xi_event->classes, xi_event->num_classes); |
| 5617 |
|
| 5618 |
if (!xi2_active && sp->btn_mask) { |
| 5619 |
TRACE_EVENTS((stderr, "Activating XI2 now.")); |
| 5620 |
xi2_activate(); |
| 5621 |
} |
| 5622 |
} |
| 5623 |
else { |
| 5624 |
TRACE_EVENTS((stderr, |
| 5625 |
"Ignoring XI_DeviceChanged event with unknown reason %x, " |
| 5626 |
"device = %d->%d", |
| 5627 |
xi_event->reason, xi_event->deviceid, xi_event->sourceid)); |
| 5628 |
} |
| 5629 |
} |
| 5630 |
|
| 5631 |
|
| 5632 |
static void |
| 5633 |
xi2_ev_hierchange(XIHierarchyEvent *xi_event) |
| 5634 |
{ |
| 5635 |
XIHierarchyInfo *infp, *inf_end; |
| 5636 |
|
| 5637 |
if (globals.debug & DBG_EVENT) { |
| 5638 |
fprintf(stderr, "%s:%d: XI_HierarchyChanged event: ", |
| 5639 |
__FILE__, __LINE__); |
| 5640 |
if (xi_event->flags & XIMasterAdded) |
| 5641 |
fputs(" XIMasterAdded", stderr); |
| 5642 |
if (xi_event->flags & XIMasterRemoved) |
| 5643 |
fputs(" XIMasterRemoved", stderr); |
| 5644 |
if (xi_event->flags & XISlaveAdded) |
| 5645 |
fputs(" XISlaveAdded", stderr); |
| 5646 |
if (xi_event->flags & XISlaveRemoved) |
| 5647 |
fputs(" XISlaveRemoved", stderr); |
| 5648 |
if (xi_event->flags & XISlaveAttached) |
| 5649 |
fputs(" XISlaveAttached", stderr); |
| 5650 |
if (xi_event->flags & XISlaveDetached) |
| 5651 |
fputs(" XISlaveDetached", stderr); |
| 5652 |
if (xi_event->flags & XIDeviceEnabled) |
| 5653 |
fputs(" XIDeviceEnabled", stderr); |
| 5654 |
if (xi_event->flags & XIDeviceDisabled) |
| 5655 |
fputs(" XIDeviceDisabled", stderr); |
| 5656 |
if (!xi_event->flags) |
| 5657 |
fputs("no flags(?)", stderr); |
| 5658 |
fputc('\n', stderr); |
| 5659 |
} |
| 5660 |
|
| 5661 |
if (!(xi_event->flags & (XIDeviceEnabled | XIDeviceDisabled))) |
| 5662 |
return; |
| 5663 |
|
| 5664 |
inf_end = xi_event->info + (xi_event->num_info - 1); |
| 5665 |
for (infp = xi_event->info; infp <= inf_end; ++infp) { |
| 5666 |
struct xi2_slave *sp; |
| 5667 |
|
| 5668 |
if (infp->use != XISlavePointer && infp->use != XIFloatingSlave) |
| 5669 |
continue; |
| 5670 |
|
| 5671 |
for (sp = xi2_slaves;; sp = sp->next) { |
| 5672 |
if (sp == NULL) { |
| 5673 |
if (infp->enabled) |
| 5674 |
TRACE_EVENTS((stderr, |
| 5675 |
" Ignoring enable request for %d->%d (not found)", |
| 5676 |
infp->attachment, infp->deviceid)); |
| 5677 |
break; |
| 5678 |
} |
| 5679 |
if (sp->id == infp->deviceid) { |
| 5680 |
if (infp->enabled != sp->enabled) { |
| 5681 |
TRACE_EVENTS((stderr, " %s %d->%d", |
| 5682 |
infp->enabled ? "Enabling" : "Disabling", |
| 5683 |
infp->attachment, infp->deviceid)); |
| 5684 |
sp->enabled = infp->enabled; |
| 5685 |
if (!sp->enabled && xi2_current->slave == sp) { |
| 5686 |
TRACE_EVENTS((stderr, |
| 5687 |
" Removing from master device")); |
| 5688 |
xi2_current->slave = &xi2_no_slave; |
| 5689 |
} |
| 5690 |
} |
| 5691 |
break; |
| 5692 |
} |
| 5693 |
} |
| 5694 |
} |
| 5695 |
} |
| 5696 |
|
| 5697 |
#endif /* HAVE_XI21 */ |
| 5698 |
|
| 5699 |
|
| 5700 |
/* |
| 5701 |
* Since redrawing the screen is (potentially) a slow task, xdvi checks |
| 5702 |
* for incoming events while this is occurring. It does not register |
| 5703 |
* a work proc that draws and returns every so often, as the toolkit |
| 5704 |
* documentation suggests. Instead, it checks for events periodically |
| 5705 |
* (or not, if SIGPOLL can be used instead) and processes them in |
| 5706 |
* a subroutine called by the page drawing routine. This routine (below) |
| 5707 |
* checks to see if anything has happened and processes those events and |
| 5708 |
* signals. (Or, if it is called when there is no redrawing that needs |
| 5709 |
* to be done, it blocks until something happens.) |
| 5710 |
* |
| 5711 |
* Ultimately, the goal is to have this be the only place in xdvi where |
| 5712 |
* blocking occurs. |
| 5713 |
* |
| 5714 |
* The argument to this function should be a mask of event types (EV_*) |
| 5715 |
* indicating which event types should cause read_events to return instead |
| 5716 |
* of waiting for more events. This function will always process all |
| 5717 |
* pending events and signals before returning. |
| 5718 |
* The return value is the value of globals.ev.flags. |
| 5719 |
*/ |
| 5720 |
|
| 5721 |
unsigned int |
| 5722 |
read_events(unsigned int ret_mask) |
| 5723 |
{ |
| 5724 |
XEvent event; |
| 5725 |
|
| 5726 |
#if !HAVE_POLL |
| 5727 |
if (numfds == 0) |
| 5728 |
numfds = ConnectionNumber(DISP) + 1; |
| 5729 |
#endif |
| 5730 |
|
| 5731 |
if (globals.debug & DBG_EVENT) |
| 5732 |
fprintf(stderr, "%s:%d: read_events %u\n", __FILE__, __LINE__, ret_mask); |
| 5733 |
for (;;) { |
| 5734 |
globals.ev.ctr = event_freq; |
| 5735 |
/* |
| 5736 |
* The above line clears the flag indicating that an event is |
| 5737 |
* pending. So if an event comes in right now, the flag will be |
| 5738 |
* set again needlessly, but we just end up making an extra call. |
| 5739 |
* Also, be careful about destroying the magnifying glass while |
| 5740 |
* drawing on it. |
| 5741 |
*/ |
| 5742 |
|
| 5743 |
#if !FLAKY_SIGPOLL |
| 5744 |
|
| 5745 |
if (event_freq < 0) { /* if SIGPOLL works */ |
| 5746 |
if (!XtPending()) { |
| 5747 |
sigset_t oldsig; |
| 5748 |
|
| 5749 |
(void) sigprocmask(SIG_BLOCK, &all_signals, &oldsig); |
| 5750 |
for (;;) { |
| 5751 |
#ifdef SHOW_SIG_FLAGS |
| 5752 |
/* this gives HUGE output ... */ |
| 5753 |
if (globals.debug & DBG_EVENT) |
| 5754 |
fprintf(stderr, "%s:%d: sig_flags = %d\n", |
| 5755 |
__FILE__, __LINE__, sig_flags); |
| 5756 |
#endif |
| 5757 |
while (sig_flags) { |
| 5758 |
flags_to_sigproc[sig_flags](); |
| 5759 |
} |
| 5760 |
|
| 5761 |
if (XtPending()) |
| 5762 |
break; |
| 5763 |
|
| 5764 |
if (globals.ev.flags & ret_mask) { |
| 5765 |
(void) sigprocmask(SIG_SETMASK, &oldsig, (sigset_t *) NULL); |
| 5766 |
return globals.ev.flags; |
| 5767 |
} |
| 5768 |
(void) sigsuspend(&oldsig); |
| 5769 |
} |
| 5770 |
(void) sigprocmask(SIG_SETMASK, &oldsig, (sigset_t *) NULL); |
| 5771 |
} |
| 5772 |
} |
| 5773 |
else |
| 5774 |
|
| 5775 |
#endif /* not FLAKY_SIGPOLL */ |
| 5776 |
|
| 5777 |
{ |
| 5778 |
for (;;) { |
| 5779 |
struct xio *ip; |
| 5780 |
|
| 5781 |
if (globals.debug & DBG_EVENT) |
| 5782 |
fprintf(stderr, "%s:%d: (flaky) sig_flags = %d\n", |
| 5783 |
__FILE__, __LINE__, sig_flags); |
| 5784 |
while (sig_flags) { |
| 5785 |
sigset_t oldsig; |
| 5786 |
|
| 5787 |
(void) sigprocmask(SIG_BLOCK, &all_signals, &oldsig); |
| 5788 |
|
| 5789 |
while (sig_flags) { |
| 5790 |
flags_to_sigproc[sig_flags](); |
| 5791 |
} |
| 5792 |
|
| 5793 |
(void) sigprocmask(SIG_SETMASK, &oldsig, |
| 5794 |
(sigset_t *) NULL); |
| 5795 |
} |
| 5796 |
|
| 5797 |
if (XtPending()) |
| 5798 |
break; |
| 5799 |
|
| 5800 |
if (globals.ev.flags & ret_mask) |
| 5801 |
return globals.ev.flags; |
| 5802 |
|
| 5803 |
/* If a SIGUSR1 signal comes right now, then it will wait |
| 5804 |
until an X event or another SIGUSR1 signal arrives. */ |
| 5805 |
|
| 5806 |
#if HAVE_POLL |
| 5807 |
if (globals.debug & DBG_EVENT) |
| 5808 |
fprintf(stderr, "%s:%d: have_poll!\n", |
| 5809 |
__FILE__, __LINE__); |
| 5810 |
if (io_dirty) { |
| 5811 |
struct pollfd *fp; |
| 5812 |
|
| 5813 |
if (num_fds > max_fds) { |
| 5814 |
if (fds != NULL) free(fds); |
| 5815 |
fds = xmalloc(num_fds * sizeof *fds); |
| 5816 |
max_fds = num_fds; |
| 5817 |
fds->fd = ConnectionNumber(DISP); |
| 5818 |
fds->events = POLLIN; |
| 5819 |
} |
| 5820 |
fp = fds + 1; |
| 5821 |
for (ip = iorecs; ip != NULL; ip = ip->next) { |
| 5822 |
fp->fd = ip->fd; |
| 5823 |
fp->events = ip->xio_events; |
| 5824 |
ip->pfd = fp; |
| 5825 |
++fp; |
| 5826 |
} |
| 5827 |
io_dirty = False; |
| 5828 |
} |
| 5829 |
|
| 5830 |
for (;;) { |
| 5831 |
if (poll(fds, num_fds, -1) >= 0) { |
| 5832 |
for (ip = iorecs; ip != NULL; ip = ip->next) { |
| 5833 |
int revents = ip->pfd->revents; |
| 5834 |
|
| 5835 |
if (revents & POLLIN && ip->read_proc != NULL) |
| 5836 |
(ip->read_proc)(ip->fd, ip->data); |
| 5837 |
if (revents & POLLOUT && ip->write_proc != NULL) |
| 5838 |
(ip->write_proc)(ip->fd, ip->data); |
| 5839 |
} |
| 5840 |
break; |
| 5841 |
} |
| 5842 |
|
| 5843 |
if (errno == EINTR) |
| 5844 |
break; |
| 5845 |
|
| 5846 |
if (errno != EAGAIN) { |
| 5847 |
perror("xdvi: poll"); |
| 5848 |
break; |
| 5849 |
} |
| 5850 |
} |
| 5851 |
#else /* HAVE_POLL */ |
| 5852 |
if (globals.debug & DBG_EVENT) |
| 5853 |
fprintf(stderr, "%s:%d: NOT have_poll!\n", |
| 5854 |
__FILE__, __LINE__); |
| 5855 |
FD_ZERO(&readfds); |
| 5856 |
FD_ZERO(&writefds); |
| 5857 |
FD_SET(ConnectionNumber(DISP), &readfds); |
| 5858 |
for (ip = iorecs; ip != NULL; ip = ip->next) { |
| 5859 |
if (ip->xio_events & XIO_IN) |
| 5860 |
FD_SET(ip->fd, &readfds); |
| 5861 |
if (ip->xio_events & XIO_OUT) |
| 5862 |
FD_SET(ip->fd, &writefds); |
| 5863 |
} |
| 5864 |
|
| 5865 |
for (;;) { |
| 5866 |
if (select(numfds, &readfds, &writefds, (fd_set *) NULL, |
| 5867 |
(struct timeval *) NULL) >= 0) { |
| 5868 |
for (ip = iorecs; ip != NULL; ip = ip->next) { |
| 5869 |
if (FD_ISSET(ip->fd, &readfds) && ip->read_proc != NULL) { |
| 5870 |
if (globals.debug & DBG_EVENT) |
| 5871 |
fprintf(stderr, "%s:%d: reading from %d\n", |
| 5872 |
__FILE__, __LINE__, ip->fd); |
| 5873 |
(ip->read_proc)(ip->fd, ip->data); |
| 5874 |
} |
| 5875 |
if (FD_ISSET(ip->fd, &writefds) && ip->write_proc != NULL) { |
| 5876 |
if (globals.debug & DBG_EVENT) |
| 5877 |
fprintf(stderr, "%s:%d: writing to %d\n", |
| 5878 |
__FILE__, __LINE__, ip->fd); |
| 5879 |
(ip->write_proc)(ip->fd, ip->data); |
| 5880 |
} |
| 5881 |
} |
| 5882 |
break; |
| 5883 |
} |
| 5884 |
|
| 5885 |
if (errno == EINTR) |
| 5886 |
break; |
| 5887 |
|
| 5888 |
if (errno != EAGAIN) { |
| 5889 |
perror("xdvi: select"); |
| 5890 |
break; |
| 5891 |
} |
| 5892 |
} |
| 5893 |
#endif /* HAVE_POLL */ |
| 5894 |
} |
| 5895 |
} |
| 5896 |
|
| 5897 |
XtAppNextEvent(globals.app, &event); |
| 5898 |
|
| 5899 |
#ifdef MOTIF |
| 5900 |
if ((resource.expert_mode & XPRT_SHOW_TOOLBAR) != 0) |
| 5901 |
TipAppHandle(globals.app, &event); |
| 5902 |
#endif |
| 5903 |
|
| 5904 |
#if HAVE_XI21 |
| 5905 |
if (event.xany.type == GenericEvent |
| 5906 |
&& event.xcookie.extension == xi2_opcode) { |
| 5907 |
if (!XGetEventData(DISP, &event.xcookie)) { |
| 5908 |
TRACE_EVENTS((stderr, |
| 5909 |
"Received XI2 event, of type %d, with no cookie", |
| 5910 |
event.xcookie.evtype)); |
| 5911 |
} |
| 5912 |
else { |
| 5913 |
switch (event.xcookie.evtype) { |
| 5914 |
|
| 5915 |
case XI_HierarchyChanged: |
| 5916 |
xi2_ev_hierchange(event.xcookie.data); |
| 5917 |
break; |
| 5918 |
|
| 5919 |
case XI_DeviceChanged: |
| 5920 |
xi2_ev_devchange(event.xcookie.data); |
| 5921 |
break; |
| 5922 |
|
| 5923 |
case XI_Enter: |
| 5924 |
xi2_ev_enter(event.xcookie.data); |
| 5925 |
break; |
| 5926 |
|
| 5927 |
case XI_Motion: |
| 5928 |
/* This needs to be filled in by the client */ |
| 5929 |
((XIDeviceEvent *) event.xcookie.data)->serial |
| 5930 |
= event.xany.serial; |
| 5931 |
xi2_ev_motion(event.xcookie.data); |
| 5932 |
break; |
| 5933 |
|
| 5934 |
default: |
| 5935 |
TRACE_EVENTS((stderr, |
| 5936 |
"Received XI2 event of unknown type %d", |
| 5937 |
event.xcookie.evtype)); |
| 5938 |
|
| 5939 |
} |
| 5940 |
XFreeEventData(DISP, &event.xcookie); |
| 5941 |
} |
| 5942 |
continue; |
| 5943 |
} |
| 5944 |
#endif /* HAVE_XI21 */ |
| 5945 |
|
| 5946 |
if (resized) |
| 5947 |
get_geom(); |
| 5948 |
|
| 5949 |
if (event.xany.window == magnifier.win && event.type == Expose) { |
| 5950 |
handle_expose((Widget) NULL, (XtPointer)&magnifier, &event, |
| 5951 |
(Boolean *) NULL); |
| 5952 |
continue; |
| 5953 |
} |
| 5954 |
else if (globals.broken_motif_event_handling && |
| 5955 |
(globals.cursor.flags & (CURSOR_RULER | CURSOR_TEXT))) { |
| 5956 |
/* In this case, Act_motion() and Act_release() are not called properly |
| 5957 |
* for updating the ruler/text selection (it works with the magnifier though), |
| 5958 |
* so we need to invoke them ourselves here: */ |
| 5959 |
if (event.type == MotionNotify) |
| 5960 |
Act_motion(NULL, &event, NULL, NULL); |
| 5961 |
else if (event.type == ButtonRelease) |
| 5962 |
Act_release(NULL, &event, NULL, NULL); |
| 5963 |
} |
| 5964 |
|
| 5965 |
#ifdef MOTIF |
| 5966 |
if (XtIsRealized(globals.widgets.top_level) |
| 5967 |
&& event.xany.window == XtWindow(globals.widgets.clip_widget) |
| 5968 |
&& event.type == KeyPress) { /* workaround for #610206 */ |
| 5969 |
motif_translations_hack(); |
| 5970 |
} |
| 5971 |
#else |
| 5972 |
if (resource.expert_mode & XPRT_SHOW_BUTTONS) |
| 5973 |
SubMenuHandleEvent(globals.app, &event); |
| 5974 |
#endif |
| 5975 |
XtDispatchEvent(&event); |
| 5976 |
} |
| 5977 |
} |
| 5978 |
|
| 5979 |
|
| 5980 |
/* |
| 5981 |
* Higher-level routines for managing events. |
| 5982 |
*/ |
| 5983 |
|
| 5984 |
static void |
| 5985 |
can_exposures(struct WindowRec *windowrec) |
| 5986 |
{ |
| 5987 |
windowrec->min_x = windowrec->min_y = MAXDIM; |
| 5988 |
windowrec->max_x = windowrec->max_y = 0; |
| 5989 |
} |
| 5990 |
|
| 5991 |
void |
| 5992 |
redraw(struct WindowRec *windowrec) |
| 5993 |
{ |
| 5994 |
currwin = *windowrec; |
| 5995 |
globals.win_expose.min_x = currwin.min_x + currwin.base_x; |
| 5996 |
globals.win_expose.min_y = currwin.min_y + currwin.base_y; |
| 5997 |
globals.win_expose.max_x = currwin.max_x + currwin.base_x; |
| 5998 |
globals.win_expose.max_y = currwin.max_y + currwin.base_y; |
| 5999 |
can_exposures(windowrec); |
| 6000 |
|
| 6001 |
/* fix for bug #619070 - the complicated flags (and do_update_property) |
| 6002 |
are needed to avoid too many updates at exposures, especially for |
| 6003 |
a window of another xdvi instance when the magnifier intersects with |
| 6004 |
that window. |
| 6005 |
*/ |
| 6006 |
if (have_src_specials && do_update_property |
| 6007 |
&& globals.win_expose.min_x != 1 |
| 6008 |
&& globals.win_expose.max_y - globals.win_expose.min_y != 1 |
| 6009 |
&& currwin.base_x == 0 && currwin.base_y == 0) { |
| 6010 |
update_window_property(XtWindow(globals.widgets.top_level), True); |
| 6011 |
} |
| 6012 |
|
| 6013 |
TRACE_EVENTS((stderr, "Redraw %d x %d at (%d, %d) (base=%d,%d)", |
| 6014 |
globals.win_expose.max_x - globals.win_expose.min_x, |
| 6015 |
globals.win_expose.max_y - globals.win_expose.min_y, |
| 6016 |
globals.win_expose.min_x, globals.win_expose.min_y, |
| 6017 |
currwin.base_x, currwin.base_y)); |
| 6018 |
|
| 6019 |
/* can't use ev_cursor here, since the event loop might not see this change quick enough */ |
| 6020 |
if (!(globals.ev.flags & EV_CURSOR)) { |
| 6021 |
TRACE_EVENTS((stderr, "Cursor: %ld", globals.cursor.flags)); |
| 6022 |
if (!(globals.cursor.flags & (CURSOR_MAG | CURSOR_DRAG_H | CURSOR_DRAG_V | CURSOR_DRAG_A))) { |
| 6023 |
if (resource.mouse_mode == MOUSE_MODE3) |
| 6024 |
XDefineCursor(DISP, CURSORWIN, globals.cursor.mode3); |
| 6025 |
else |
| 6026 |
XDefineCursor(DISP, CURSORWIN, globals.cursor.wait); |
| 6027 |
XFlush(DISP); |
| 6028 |
} |
| 6029 |
globals.ev.flags |= EV_CURSOR; |
| 6030 |
} |
| 6031 |
|
| 6032 |
/* No longer needed since windows are correctly transient now */ |
| 6033 |
/* raise_message_windows(); */ |
| 6034 |
raise_file_selector(); |
| 6035 |
draw_page(); |
| 6036 |
globals.warn_spec_now = False; |
| 6037 |
} |
| 6038 |
|
| 6039 |
|
| 6040 |
void |
| 6041 |
redraw_page(void) |
| 6042 |
{ |
| 6043 |
#if COLOR |
| 6044 |
const struct rgb *rgbp; |
| 6045 |
#endif |
| 6046 |
TRACE_FILES((stderr, "Redraw page on %p", (void *)globals.dvi_file.bak_fp)); |
| 6047 |
|
| 6048 |
if (globals.dvi_file.bak_fp == NULL) |
| 6049 |
return; |
| 6050 |
|
| 6051 |
if (scanned_page < current_page) { |
| 6052 |
TRACE_FILES((stderr, "redraw_page: scanned_page = %d, current_page = %d, prescanning %p\n", |
| 6053 |
scanned_page, current_page, (void *)globals.dvi_file.bak_fp)); |
| 6054 |
|
| 6055 |
prescan(globals.dvi_file.bak_fp); |
| 6056 |
|
| 6057 |
if (globals.ev.flags & EV_GE_NEWPAGE) { /* if we need to re-prescan */ |
| 6058 |
return; |
| 6059 |
} |
| 6060 |
} |
| 6061 |
|
| 6062 |
TRACE_FILES((stderr, "redraw_page: current_page = %d", current_page)); |
| 6063 |
if (pageinfo_get_window_width(current_page) != globals.page.unshrunk_w |
| 6064 |
|| pageinfo_get_window_height(current_page) != globals.page.unshrunk_h) { |
| 6065 |
TRACE_FILES((stderr, "NEW SIZE: %dx%d", |
| 6066 |
pageinfo_get_window_width(current_page), pageinfo_get_window_height(current_page))); |
| 6067 |
init_page(); |
| 6068 |
reconfig(); |
| 6069 |
} |
| 6070 |
|
| 6071 |
/* We can't call home() without proper unshrunk_page_*, which requires |
| 6072 |
* prescan(), which can't be done from within read_events() */ |
| 6073 |
|
| 6074 |
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!! BUG ALERT !!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 6075 |
There's some complicated interaction with Postscript specials |
| 6076 |
here: if home_action check comes before the gs stuff, psp.drawfile |
| 6077 |
might not get initialized correctly, resulting in empty PS figures |
| 6078 |
(bounding box instead of figure). This is different in xdvi, due to |
| 6079 |
different handling of the home_action stuff, but at the moment I can't |
| 6080 |
remember the reason for this ... |
| 6081 |
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! BUG ALERT !!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 6082 |
*/ |
| 6083 |
#if PS_GS |
| 6084 |
if (gs_postpone_prescan) { |
| 6085 |
if (!setjmp(globals.ev.canit)) { |
| 6086 |
gs_resume_prescan(); |
| 6087 |
} |
| 6088 |
else |
| 6089 |
return; |
| 6090 |
} |
| 6091 |
#endif |
| 6092 |
if (home_action != NULL) { |
| 6093 |
home_action(False); |
| 6094 |
home_action = NULL; |
| 6095 |
/* This discards the expose event generated by home() |
| 6096 |
(1 for each page) */ |
| 6097 |
if (read_events(EV_NOWAIT) & EV_GE_NEWPAGE) { |
| 6098 |
return; |
| 6099 |
} |
| 6100 |
|
| 6101 |
can_exposures(&mane); |
| 6102 |
} |
| 6103 |
|
| 6104 |
#if COLOR |
| 6105 |
rgbp = &bg_initial; |
| 6106 |
if (page_colors.stack != NULL) { |
| 6107 |
ASSERT(current_page < (int)page_colors.size, "page_colors.size too small"); |
| 6108 |
rgbp = &page_colors.stack[current_page].bg; |
| 6109 |
} |
| 6110 |
|
| 6111 |
/* Set background color */ |
| 6112 |
if (bg_current == NULL |
| 6113 |
|| rgbp->r != bg_current->color.r |
| 6114 |
|| rgbp->g != bg_current->color.g |
| 6115 |
|| rgbp->b != bg_current->color.b) { |
| 6116 |
struct bgrec **bgpp; |
| 6117 |
|
| 6118 |
for (bgpp = &bg_head;;) { |
| 6119 |
bg_current = *bgpp; |
| 6120 |
if (bg_current == NULL) { /* if bg is not in list */ |
| 6121 |
bg_current = *bgpp = xmalloc(sizeof *bg_current); |
| 6122 |
bg_current->next = NULL; |
| 6123 |
bg_current->color = *rgbp; |
| 6124 |
bg_current->fg_head = NULL; |
| 6125 |
bg_current->pixel_good = False; |
| 6126 |
break; |
| 6127 |
} |
| 6128 |
if (bg_current->color.r == rgbp->r |
| 6129 |
&& bg_current->color.g == rgbp->g |
| 6130 |
&& bg_current->color.b == rgbp->b) |
| 6131 |
break; |
| 6132 |
bgpp = &bg_current->next; |
| 6133 |
} |
| 6134 |
fg_current = NULL; /* force change of foreground color */ |
| 6135 |
/* globals.gc.high is only used in XDrawRectangle, so its background color |
| 6136 |
doesn't need to be changed. */ |
| 6137 |
if (globals.debug & DBG_DVI) |
| 6138 |
printf("Changing background color to %5d %5d %5d\n", |
| 6139 |
bg_current->color.r, bg_current->color.g, |
| 6140 |
bg_current->color.b); |
| 6141 |
|
| 6142 |
if (!bg_current->pixel_good) { |
| 6143 |
bg_current->pixel = alloc_color(&bg_current->color, |
| 6144 |
color_data[1].pixel); |
| 6145 |
bg_current->pixel_good = True; |
| 6146 |
} |
| 6147 |
XSetWindowBackground(DISP, mane.win, bg_current->pixel); |
| 6148 |
#if MOTIF && !FIXED_FLUSHING_PAGING |
| 6149 |
XtVaSetValues(XtParent(globals.widgets.draw_widget), XtNbackground, bg_current->pixel, NULL); |
| 6150 |
#endif |
| 6151 |
/* XSetWindowBackground(DISP, mane.win, bg_current->pixel); */ |
| 6152 |
/* XClearWindow(DISP, mane.win); */ |
| 6153 |
#if 0 /* don't recolor the cursor - gives too low contrast on color backgrounds, |
| 6154 |
and bad appearance when part of the background is white and cursor mask |
| 6155 |
is colored */ |
| 6156 |
{ |
| 6157 |
XColor bg_Color; |
| 6158 |
bg_Color.pixel = bg_current->pixel; |
| 6159 |
XQueryColor(DISP, G_colormap, &bg_Color); |
| 6160 |
XRecolorCursor(DISP, globals.cursor.ready, &globals.cr_color, &bg_Color); |
| 6161 |
XRecolorCursor(DISP, globals.cursor.wait, &globals.cr_color, &bg_Color); |
| 6162 |
} |
| 6163 |
#endif |
| 6164 |
} |
| 6165 |
#endif /* COLOR */ |
| 6166 |
|
| 6167 |
if (!globals.pausing.flag) { |
| 6168 |
#if PS_GS |
| 6169 |
gs_erase_page(); |
| 6170 |
#endif |
| 6171 |
XClearWindow(DISP, mane.win); |
| 6172 |
} |
| 6173 |
|
| 6174 |
if (G_backing_store != NotUseful) { |
| 6175 |
mane.min_x = mane.min_y = 0; |
| 6176 |
mane.max_x = globals.page.w; |
| 6177 |
mane.max_y = globals.page.h; |
| 6178 |
} |
| 6179 |
else { |
| 6180 |
get_xy(); |
| 6181 |
mane.min_x = -m_window_x; |
| 6182 |
mane.max_x = -m_window_x + mane.width; |
| 6183 |
mane.min_y = -m_window_y; |
| 6184 |
mane.max_y = -m_window_y + mane.height; |
| 6185 |
} |
| 6186 |
|
| 6187 |
/* update_TOC(); */ |
| 6188 |
redraw(&mane); |
| 6189 |
} |
| 6190 |
|
| 6191 |
void |
| 6192 |
do_pages(void) |
| 6193 |
{ |
| 6194 |
if (globals.debug & DBG_BATCH) { |
| 6195 |
|
| 6196 |
(void)read_events(EV_GT_IDLE); |
| 6197 |
for (current_page = 0; current_page < total_pages; ++current_page) { |
| 6198 |
if (resource.keep_flag) { |
| 6199 |
home_action = NULL; |
| 6200 |
} |
| 6201 |
else { |
| 6202 |
home_action = home; |
| 6203 |
} |
| 6204 |
globals.warn_spec_now = resource.warn_spec; |
| 6205 |
#if PS_GS |
| 6206 |
for (;;) { |
| 6207 |
redraw_page(); |
| 6208 |
(void) read_events(EV_NOWAIT); |
| 6209 |
if (!(globals.ev.flags & (EV_NEWPAGE | EV_NEWDOC | EV_RELOAD))) |
| 6210 |
break; |
| 6211 |
globals.ev.flags = EV_IDLE; |
| 6212 |
} |
| 6213 |
#else |
| 6214 |
redraw_page(); |
| 6215 |
#endif |
| 6216 |
} |
| 6217 |
xdvi_exit(EXIT_SUCCESS); |
| 6218 |
} |
| 6219 |
else { |
| 6220 |
for (;;) { /* normal operation */ |
| 6221 |
(void) read_events(EV_GT_IDLE); |
| 6222 |
TRACE_EVENTS((stderr, "globals.ev.flags: %d; ev_newpage: %d, ev_newdoc: %d, ev_reload: %d\n", |
| 6223 |
globals.ev.flags, EV_NEWPAGE, EV_NEWDOC, EV_RELOAD)); |
| 6224 |
/* NOTE: reloading must be checked first! */ |
| 6225 |
if (globals.ev.flags & (EV_NEWPAGE | EV_NEWDOC | EV_RELOAD | EV_PS_TOGGLE)) { |
| 6226 |
TRACE_EVENTS((stderr, "EV_NEWPAGE | ...")); |
| 6227 |
globals.ev.flags &= ~(EV_NEWPAGE | EV_EXPOSE | EV_PS_TOGGLE); |
| 6228 |
if (globals.ev.flags & EV_RELOAD) { |
| 6229 |
dviErrFlagT errflag; |
| 6230 |
|
| 6231 |
globals.ev.flags &= ~EV_RELOAD; |
| 6232 |
if (load_dvi_file( |
| 6233 |
#if !DELAYED_MKTEXPK |
| 6234 |
True, |
| 6235 |
#endif |
| 6236 |
&errflag)) { |
| 6237 |
statusline_info(STATUS_SHORT, "File reloaded."); |
| 6238 |
} |
| 6239 |
/* else { */ |
| 6240 |
/* statusline_info(STATUS_MEDIUM, "File corrupted, not reloading."); */ |
| 6241 |
/* } */ |
| 6242 |
} |
| 6243 |
if (globals.ev.flags & EV_NEWDOC) { |
| 6244 |
dviErrFlagT errflag; |
| 6245 |
TRACE_EVENTS((stderr, "EV_NEWDOC!")); |
| 6246 |
/* fprintf(stderr, "newdoc!\n"); */ |
| 6247 |
TRACE_FILES((stderr, "current page: %d", current_page)); |
| 6248 |
/* file_history_set_page(current_page); */ |
| 6249 |
globals.ev.flags &= ~EV_NEWDOC; |
| 6250 |
if (load_dvi_file( |
| 6251 |
#if !DELAYED_MKTEXPK |
| 6252 |
True, |
| 6253 |
#endif |
| 6254 |
&errflag)) { |
| 6255 |
statusline_append(STATUS_SHORT, "Opened ", "Opened \"%s\"", globals.dvi_name); |
| 6256 |
/* statusline_info(STATUS_SHORT, "Opened \"%s\"", globals.dvi_name); */ |
| 6257 |
TRACE_FILES((stderr, "Adding to history: |%s|\n", globals.dvi_name)); |
| 6258 |
if (file_history_push(globals.dvi_name)) { /* it's a new file, add to history */ |
| 6259 |
TRACE_FILES((stderr, "New entry!")); |
| 6260 |
filehist_menu_add_entry(globals.dvi_name); |
| 6261 |
} |
| 6262 |
else { /* only need to move existing elements to new positions */ |
| 6263 |
TRACE_FILES((stderr, "Existing entry!\n")); |
| 6264 |
filehist_menu_refresh(); |
| 6265 |
} |
| 6266 |
} |
| 6267 |
} |
| 6268 |
|
| 6269 |
can_exposures(&mane); |
| 6270 |
can_exposures(&magnifier); |
| 6271 |
|
| 6272 |
if (globals.dvi_file.bak_fp != NULL) { |
| 6273 |
TRACE_EVENTS((stderr, "redraw_page()")); |
| 6274 |
redraw_page(); |
| 6275 |
} |
| 6276 |
else { |
| 6277 |
TRACE_EVENTS((stderr, "dvi_file_changed()")); |
| 6278 |
(void)dvi_file_changed(); |
| 6279 |
} |
| 6280 |
} |
| 6281 |
else if (globals.ev.flags & EV_PAGEHIST_GOTO_PAGE) { |
| 6282 |
int pageno; |
| 6283 |
globals.ev.flags &= ~EV_PAGEHIST_GOTO_PAGE; |
| 6284 |
pageno = check_goto_page(page_history_get_page(), False); |
| 6285 |
goto_page(pageno, resource.keep_flag ? NULL : home, False); |
| 6286 |
TRACE_FILES((stderr, "got page: %d", pageno)); |
| 6287 |
} |
| 6288 |
else if (globals.ev.flags & EV_FILEHIST_GOTO_PAGE) { |
| 6289 |
int pageno; |
| 6290 |
globals.ev.flags &= ~EV_FILEHIST_GOTO_PAGE; |
| 6291 |
pageno = check_goto_page(file_history_get_page(), True); |
| 6292 |
goto_page(pageno, resource.keep_flag ? NULL : home, False); |
| 6293 |
TRACE_FILES((stderr, "got page: %d", pageno)); |
| 6294 |
} |
| 6295 |
else if (globals.ev.flags & EV_PAGEHIST_INSERT) { |
| 6296 |
globals.ev.flags &= ~EV_PAGEHIST_INSERT; |
| 6297 |
page_history_insert(current_page); |
| 6298 |
} |
| 6299 |
else if (globals.ev.flags & EV_FIND_CANCEL) { |
| 6300 |
/* NOTE: This must be done before checking for expose() */ |
| 6301 |
globals.ev.flags &= ~EV_FIND_CANCEL; |
| 6302 |
} |
| 6303 |
else if (globals.ev.flags & EV_ANCHOR) { |
| 6304 |
/* |
| 6305 |
* Similar to forward search: search for a htex anchor. |
| 6306 |
* This needs to come before the next case which does the redraw_page(), |
| 6307 |
* otherwise anchors for the current page might not be drawn at all: |
| 6308 |
* anchor_search() sets the info later used by htex_draw_anchormarkers(), |
| 6309 |
* which is invoked by redraw_page(). |
| 6310 |
*/ |
| 6311 |
|
| 6312 |
/* switch off the link cursor */ |
| 6313 |
globals.cursor.flags &= ~CURSOR_LINK; |
| 6314 |
|
| 6315 |
if (dvi_file_changed()) |
| 6316 |
continue; |
| 6317 |
|
| 6318 |
anchor_search(g_anchor_pos); |
| 6319 |
|
| 6320 |
/* added, otherwise anchors on same page may not be drawn */ |
| 6321 |
/* NOTE: This caused a crash when clicking on link "Langer" on p3 of diss.dvi |
| 6322 |
since the color stack wasn't allocated for the target pages. Removed for the |
| 6323 |
time being, since I can't reproduce the problem for which it was introduced. |
| 6324 |
CVS commit message was: |
| 6325 |
"fix anchor drawing for other window" |
| 6326 |
*/ |
| 6327 |
/* redraw(&mane); */ |
| 6328 |
|
| 6329 |
globals.ev.flags &= ~EV_ANCHOR; |
| 6330 |
} |
| 6331 |
else if (globals.ev.flags & EV_SRC) { |
| 6332 |
/* |
| 6333 |
* Source special operations are deferred to here because |
| 6334 |
* they call geom_scan(), which may call define_font(), |
| 6335 |
* which may call makefont(), which may call read_events() |
| 6336 |
* recursively. |
| 6337 |
*/ |
| 6338 |
if (globals.src.fwd_string != NULL) { |
| 6339 |
const char *s = globals.src.fwd_string; |
| 6340 |
|
| 6341 |
if (dvi_file_changed()) |
| 6342 |
continue; |
| 6343 |
|
| 6344 |
source_forward_search(s); |
| 6345 |
globals.ev.flags &= ~EV_SRC; |
| 6346 |
globals.src.fwd_string = NULL; |
| 6347 |
|
| 6348 |
/* de-iconify window if needed, and raise it */ |
| 6349 |
XMapRaised(XtDisplay(globals.widgets.top_level), XtWindow(globals.widgets.top_level)); |
| 6350 |
raise_message_windows(); |
| 6351 |
} |
| 6352 |
else if (source_reverse_x != -1) { |
| 6353 |
if (dvi_file_changed()) |
| 6354 |
continue; |
| 6355 |
|
| 6356 |
source_reverse_search(source_reverse_x, source_reverse_y, True); |
| 6357 |
globals.ev.flags &= ~EV_SRC; |
| 6358 |
} |
| 6359 |
else { |
| 6360 |
source_special_show(source_show_all); |
| 6361 |
globals.ev.flags &= ~EV_SRC; |
| 6362 |
} |
| 6363 |
} |
| 6364 |
/* support for `-findstring' */ |
| 6365 |
else if (globals.ev.flags & EV_FIND) { |
| 6366 |
if (dvi_file_changed()) |
| 6367 |
continue; |
| 6368 |
|
| 6369 |
if (resource.find_string != NULL) { /* not first call */ |
| 6370 |
dvi_find_string(resource.find_string, False); |
| 6371 |
resource.find_string = NULL; |
| 6372 |
} |
| 6373 |
else { /* actually should never arrive here?? */ |
| 6374 |
dvi_find_string(NULL, True); |
| 6375 |
} |
| 6376 |
globals.ev.flags &= ~EV_FIND; |
| 6377 |
} |
| 6378 |
else if (globals.ev.flags & EV_MAG_MOVE) { |
| 6379 |
MYTRACE((stderr, "moving mag!\n")); |
| 6380 |
move_magnifier(); |
| 6381 |
} |
| 6382 |
else if (globals.ev.flags & EV_EXPOSE) { |
| 6383 |
if (magnifier.min_x < MAXDIM) { |
| 6384 |
/* fprintf(stderr, "magnifier < maxdim!\n"); */ |
| 6385 |
if (mane.min_x >= MAXDIM) { |
| 6386 |
/* fprintf(stderr, "mane >= maxdim!\n"); */ |
| 6387 |
globals.ev.flags &= ~EV_EXPOSE; |
| 6388 |
} |
| 6389 |
redraw(&magnifier); |
| 6390 |
} |
| 6391 |
else { |
| 6392 |
/* see comment in mag.c */ |
| 6393 |
globals.ev.flags &= ~EV_EXPOSE; |
| 6394 |
if (mane.min_x < MAXDIM) { |
| 6395 |
redraw(&mane); |
| 6396 |
} |
| 6397 |
} |
| 6398 |
} |
| 6399 |
else if (globals.ev.flags & EV_CURSOR) { |
| 6400 |
/* |
| 6401 |
* This code eliminates unnecessary calls to XDefineCursor, |
| 6402 |
* since this is a slow operation on some hardware (e.g., S3 |
| 6403 |
* chips). |
| 6404 |
*/ |
| 6405 |
XSync(DISP, False); |
| 6406 |
if (!XtPending()) { |
| 6407 |
Cursor curr; |
| 6408 |
|
| 6409 |
if (globals.cursor.flags & CURSOR_DRAG_V) |
| 6410 |
curr = globals.cursor.drag_v; |
| 6411 |
else if (globals.cursor.flags & CURSOR_DRAG_H) |
| 6412 |
curr = globals.cursor.drag_h; |
| 6413 |
else if (globals.cursor.flags & CURSOR_DRAG_A) |
| 6414 |
curr = globals.cursor.drag_a; |
| 6415 |
else if (resource.mouse_mode == MOUSE_MODE3) |
| 6416 |
curr = globals.cursor.mode3; |
| 6417 |
else if (resource.mouse_mode == MOUSE_MODE2) |
| 6418 |
curr = globals.cursor.mode2; |
| 6419 |
else if (globals.cursor.flags & CURSOR_LINK) |
| 6420 |
curr = globals.cursor.link; |
| 6421 |
else if (globals.cursor.flags & CURSOR_MAG) |
| 6422 |
curr = globals.cursor.empty; |
| 6423 |
else if (globals.cursor.flags & CURSOR_CORRUPTED) |
| 6424 |
curr = globals.cursor.corrupted; |
| 6425 |
else if (globals.pausing.flag) |
| 6426 |
curr = globals.cursor.pause; |
| 6427 |
else |
| 6428 |
curr = globals.cursor.mode1; |
| 6429 |
XDefineCursor(DISP, CURSORWIN, curr); |
| 6430 |
globals.ev.flags &= ~EV_CURSOR; |
| 6431 |
} |
| 6432 |
} |
| 6433 |
XFlush(DISP); |
| 6434 |
} |
| 6435 |
} |
| 6436 |
} |
| 6437 |
|
| 6438 |
static void |
| 6439 |
Act_unpause_or_next(Widget w, XEvent *event, |
| 6440 |
String *params, Cardinal *num_params) |
| 6441 |
{ |
| 6442 |
if (globals.pausing.flag) { |
| 6443 |
globals.pausing.num++; |
| 6444 |
if (globals.pausing.num_save) |
| 6445 |
globals.pausing.num_save[current_page] = globals.pausing.num; |
| 6446 |
redraw_page(); |
| 6447 |
} |
| 6448 |
else { |
| 6449 |
Act_down_or_next(w, event, params, num_params); |
| 6450 |
} |
| 6451 |
} |
| 6452 |
|
| 6453 |
/* |
| 6454 |
* timer callback for watching the DVI file. |
| 6455 |
*/ |
| 6456 |
void |
| 6457 |
watch_file_cb(XtPointer client_data, XtIntervalId *id) |
| 6458 |
{ |
| 6459 |
static XtIntervalId timer = 0; |
| 6460 |
|
| 6461 |
UNUSED(client_data); |
| 6462 |
UNUSED(id); |
| 6463 |
|
| 6464 |
if (resource.watch_file > 0.0) { |
| 6465 |
unsigned long watch_time_ms; |
| 6466 |
|
| 6467 |
(void)dvi_file_changed(); |
| 6468 |
|
| 6469 |
if (timer) { |
| 6470 |
XtRemoveTimeOut(timer); |
| 6471 |
timer = (XtIntervalId)(XtIntervalId)0; |
| 6472 |
} |
| 6473 |
|
| 6474 |
watch_time_ms = (unsigned long)(resource.watch_file * 1000); |
| 6475 |
timer = XtAppAddTimeOut(globals.app, watch_time_ms, watch_file_cb, (XtPointer)NULL); |
| 6476 |
} |
| 6477 |
} |
| 6478 |
|
| 6479 |
void |
| 6480 |
Act_scroll_list_up(Widget w, XEvent *event, String *params, |
| 6481 |
Cardinal *num_params) |
| 6482 |
{ |
| 6483 |
UNUSED(w); |
| 6484 |
UNUSED(event); |
| 6485 |
UNUSED(params); |
| 6486 |
UNUSED(num_params); |
| 6487 |
|
| 6488 |
if (current_page == 0) { |
| 6489 |
xdvi_bell(); |
| 6490 |
/* statusline_info(STATUS_SHORT, "First page of DVI file"); */ |
| 6491 |
return; |
| 6492 |
} |
| 6493 |
goto_page(check_goto_page(current_page - 1, True), |
| 6494 |
resource.keep_flag ? NULL : home, False); |
| 6495 |
search_signal_page_changed(); |
| 6496 |
statusline_erase("Page history:"); |
| 6497 |
} |
| 6498 |
|
| 6499 |
void |
| 6500 |
Act_scroll_list_down(Widget w, XEvent *event, String *params, |
| 6501 |
Cardinal *num_params) |
| 6502 |
{ |
| 6503 |
UNUSED(w); |
| 6504 |
UNUSED(event); |
| 6505 |
UNUSED(params); |
| 6506 |
UNUSED(num_params); |
| 6507 |
|
| 6508 |
if (current_page >= total_pages - 1) { |
| 6509 |
xdvi_bell(); |
| 6510 |
/* statusline_info(STATUS_SHORT, "Last page of DVI file"); */ |
| 6511 |
return; |
| 6512 |
} |
| 6513 |
goto_page(check_goto_page(current_page + 1, True), |
| 6514 |
resource.keep_flag ? NULL : home, False); |
| 6515 |
search_signal_page_changed(); |
| 6516 |
statusline_erase("Page history:"); |
| 6517 |
} |
| 6518 |
|
| 6519 |
void Act_pagehistory_back(Widget w, XEvent *event, String *params, Cardinal *num_params) |
| 6520 |
{ |
| 6521 |
int arg; |
| 6522 |
|
| 6523 |
UNUSED(w); |
| 6524 |
UNUSED(event); |
| 6525 |
|
| 6526 |
if (!get_int_arg(params, num_params, &arg)) { |
| 6527 |
arg = 1; |
| 6528 |
} |
| 6529 |
page_history_move(-arg); |
| 6530 |
} |
| 6531 |
|
| 6532 |
void Act_pagehistory_forward(Widget w, XEvent *event, String *params, Cardinal *num_params) |
| 6533 |
{ |
| 6534 |
int arg; |
| 6535 |
|
| 6536 |
UNUSED(w); |
| 6537 |
UNUSED(event); |
| 6538 |
|
| 6539 |
if (!get_int_arg(params, num_params, &arg)) { |
| 6540 |
arg = 1; |
| 6541 |
} |
| 6542 |
page_history_move(arg); |
| 6543 |
} |
| 6544 |
|
| 6545 |
void Act_pagehistory_clear(Widget w, XEvent *event, String *params, Cardinal *num_params) |
| 6546 |
{ |
| 6547 |
UNUSED(w); |
| 6548 |
UNUSED(event); |
| 6549 |
UNUSED(params); |
| 6550 |
UNUSED(num_params); |
| 6551 |
|
| 6552 |
page_history_clear(); |
| 6553 |
} |
| 6554 |
|
| 6555 |
void Act_pagehistory_delete_backward(Widget w, XEvent *event, String *params, Cardinal *num_params) |
| 6556 |
{ |
| 6557 |
int arg; |
| 6558 |
|
| 6559 |
UNUSED(w); |
| 6560 |
UNUSED(event); |
| 6561 |
|
| 6562 |
if (!get_int_arg(params, num_params, &arg)) { |
| 6563 |
arg = 1; |
| 6564 |
} |
| 6565 |
page_history_delete(-arg); |
| 6566 |
} |
| 6567 |
|
| 6568 |
void Act_pagehistory_delete_forward(Widget w, XEvent *event, String *params, Cardinal *num_params) |
| 6569 |
{ |
| 6570 |
int arg; |
| 6571 |
|
| 6572 |
UNUSED(w); |
| 6573 |
UNUSED(event); |
| 6574 |
|
| 6575 |
if (!get_int_arg(params, num_params, &arg)) { |
| 6576 |
arg = 1; |
| 6577 |
} |
| 6578 |
page_history_delete(arg); |
| 6579 |
} |
| 6580 |
|
| 6581 |
#ifdef MOTIF |
| 6582 |
void Act_prefs_dialog(Widget w, XEvent *event, String *params, Cardinal *num_params) |
| 6583 |
{ |
| 6584 |
int arg; |
| 6585 |
|
| 6586 |
UNUSED(w); |
| 6587 |
UNUSED(event); |
| 6588 |
|
| 6589 |
if (!get_int_arg(params, num_params, &arg)) { |
| 6590 |
arg = -1; |
| 6591 |
} |
| 6592 |
|
| 6593 |
popup_preferences_dialog(globals.widgets.top_level, arg); |
| 6594 |
} |
| 6595 |
#endif /* MOTIF */ |
| 6596 |
|