| 1 |
/* |
| 2 |
* Copyright (c) 2002-2004 Paul Vojta and the xdvik development team |
| 3 |
* |
| 4 |
* Permission is hereby granted, free of charge, to any person obtaining a copy |
| 5 |
* of this software and associated documentation files (the "Software"), to |
| 6 |
* deal in the Software without restriction, including without limitation the |
| 7 |
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
| 8 |
* sell copies of the Software, and to permit persons to whom the Software is |
| 9 |
* furnished to do so, subject to the following conditions: |
| 10 |
* |
| 11 |
* The above copyright notice and this permission notice shall be included in |
| 12 |
* all copies or substantial portions of the Software. |
| 13 |
* |
| 14 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 15 |
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 16 |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 17 |
* PAUL VOJTA OR ANY OTHER AUTHOR OF THIS SOFTWARE BE LIABLE FOR ANY CLAIM, |
| 18 |
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
| 19 |
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 20 |
* OTHER DEALINGS IN THE SOFTWARE. |
| 21 |
*/ |
| 22 |
|
| 23 |
|
| 24 |
/* |
| 25 |
FIXME: The printlog presents too much detail and is confusing for users. |
| 26 |
Re-implement it using an `printing page n of m' message, |
| 27 |
i.e. according to the spec on: |
| 28 |
http://xdvi.sourceforge.net/gui.html#file-print |
| 29 |
Possible save the detailed log to a different window that can be viewed |
| 30 |
via `File -> logs', as described on: |
| 31 |
http://xdvi.sourceforge.net/gui.html#file-logs |
| 32 |
*/ |
| 33 |
|
| 34 |
#include "xdvi-config.h" |
| 35 |
#include <string.h> |
| 36 |
#include "xdvi.h" |
| 37 |
|
| 38 |
#include "xdvi-debug.h" |
| 39 |
#include "print-dialog.h" |
| 40 |
#include "print-internal.h" |
| 41 |
#include "print-log.h" /* for adjust_vertically() */ |
| 42 |
#include "util.h" |
| 43 |
#include "string-utils.h" |
| 44 |
#include "x_util.h" |
| 45 |
#include "xlwradio.h" |
| 46 |
|
| 47 |
#include <X11/Xatom.h> |
| 48 |
#include <X11/StringDefs.h> |
| 49 |
|
| 50 |
#ifdef MOTIF |
| 51 |
# include <Xm/BulletinB.h> |
| 52 |
# include <Xm/DialogS.h> |
| 53 |
# include <Xm/MessageB.h> |
| 54 |
# include <Xm/LabelG.h> |
| 55 |
# include <Xm/Form.h> |
| 56 |
# include <Xm/Frame.h> |
| 57 |
# include <Xm/ToggleBG.h> |
| 58 |
# include <Xm/PanedW.h> |
| 59 |
# include <Xm/Text.h> |
| 60 |
# include <Xm/TextF.h> |
| 61 |
# include <Xm/PushB.h> |
| 62 |
# include <Xm/Protocols.h> |
| 63 |
# include <Xm/AtomMgr.h> |
| 64 |
#else |
| 65 |
# include <X11/Shell.h> |
| 66 |
# include <X11/Xaw/Paned.h> |
| 67 |
# include <X11/Xaw/Box.h> |
| 68 |
# include <X11/Xaw/Form.h> |
| 69 |
# include <X11/Xaw/Label.h> |
| 70 |
# include <X11/Xaw/Command.h> |
| 71 |
# include <X11/Xaw/Toggle.h> |
| 72 |
# include <X11/Xaw/AsciiText.h> |
| 73 |
|
| 74 |
/* XawFmt8Bit is only available starting with X11R6: */ |
| 75 |
# if XtSpecificationRelease < 6 |
| 76 |
# define XawFmt8Bit FMT8BIT |
| 77 |
# endif |
| 78 |
|
| 79 |
#endif /* MOTIF */ |
| 80 |
|
| 81 |
|
| 82 |
static void printlog_act_close(Widget, XEvent *, String *, Cardinal *); |
| 83 |
static void printlog_act_keep(Widget, XEvent *, String *, Cardinal *); |
| 84 |
static void printlog_act_unkeep(Widget, XEvent *, String *, Cardinal *); |
| 85 |
static void printlog_act_cancel(Widget, XEvent *, String *, Cardinal *); |
| 86 |
static void printlog_act_cancel_or_destroy(Widget, XEvent *, String *, Cardinal *); |
| 87 |
|
| 88 |
static Atom WM_DELETE_WINDOW; |
| 89 |
|
| 90 |
static XtActionsRec printlog_actions[] = { |
| 91 |
{"printlogIntClose", printlog_act_close}, |
| 92 |
{"printlogIntKeep", printlog_act_keep}, |
| 93 |
{"printlogIntUnkeep", printlog_act_unkeep}, |
| 94 |
{"printlogIntCancel", printlog_act_cancel}, |
| 95 |
{"WM_cancel_or_destroy", printlog_act_cancel_or_destroy }, |
| 96 |
}; |
| 97 |
|
| 98 |
static const char *const PRINTLOG_WINDOW_TRANSLATIONS = |
| 99 |
#ifdef MOTIF |
| 100 |
"<Key>osfCancel:WM_cancel_or_destroy(%p)" |
| 101 |
#else |
| 102 |
"<Key>Escape:WM_cancel_or_destroy(%p)" |
| 103 |
#endif |
| 104 |
; |
| 105 |
|
| 106 |
#ifdef MOTIF |
| 107 |
static const char *const PRINTLOG_WINDOW_OVERRIDE_TRANSLATIONS = |
| 108 |
"#override\n" |
| 109 |
"<Key>osfCancel:WM_cancel_or_destroy(%p)"; |
| 110 |
#endif |
| 111 |
|
| 112 |
|
| 113 |
static const char *const PRINTLOG_TEXT_TRANSLATIONS = |
| 114 |
#ifdef MOTIF |
| 115 |
"<Key>osfCancel:WM_cancel_or_destroy(%p)\n" |
| 116 |
#else |
| 117 |
"<Key>Escape:WM_cancel_or_destroy(%p)\n" |
| 118 |
#endif |
| 119 |
"<Key>Return:printlogIntClose(%p)\n" |
| 120 |
"^<Key>c:printlogIntCancel(%p)\n" |
| 121 |
"^<Key>s:printlogIntKeep(%p)\n" |
| 122 |
"^<Key>q:printlogIntUnkeep(%p)\n" |
| 123 |
"<Key>q:printlogIntClose(%p)"; |
| 124 |
|
| 125 |
#define Xdvi_PRINTLOG_TEXT_NAME "text" |
| 126 |
#define Xdvi_PRINTLOG_CLOSE_NAME "close" |
| 127 |
#define Xdvi_PRINTLOG_KEEP_NAME "keep" |
| 128 |
#define Xdvi_PRINTLOG_CANCEL_NAME "cancel" |
| 129 |
|
| 130 |
static void |
| 131 |
cb_printlog_act_cancel_or_destroy(Widget w, XtPointer client_data, XtPointer call_data) |
| 132 |
{ |
| 133 |
struct save_or_print_info *info = (struct save_or_print_info *)client_data; |
| 134 |
Widget cancel_button = NULL; |
| 135 |
|
| 136 |
UNUSED(w); |
| 137 |
UNUSED(call_data); |
| 138 |
|
| 139 |
ASSERT(info->callbacks != NULL && info->callbacks->cb_destroy != NULL, "Callback not initialized"); |
| 140 |
|
| 141 |
/* If the `Cancel' button is still active, cancel printing, else close the window. */ |
| 142 |
if (get_widget_by_name(&cancel_button, info->printlog, Xdvi_PRINTLOG_CANCEL_NAME, True)) { |
| 143 |
Boolean sensitive = False; |
| 144 |
|
| 145 |
XtVaGetValues(cancel_button, |
| 146 |
#ifdef MOTIF |
| 147 |
XmNsensitive, |
| 148 |
#else |
| 149 |
XtNsensitive, |
| 150 |
#endif |
| 151 |
&sensitive, |
| 152 |
NULL); |
| 153 |
fprintf(stderr, "Sensitive: %d\n", sensitive); |
| 154 |
if (sensitive) |
| 155 |
info->callbacks->cb_cancel(w, info, NULL); |
| 156 |
else |
| 157 |
info->callbacks->cb_destroy(w, info, NULL); |
| 158 |
} |
| 159 |
} |
| 160 |
|
| 161 |
|
| 162 |
Boolean |
| 163 |
printlog_raise_active(struct save_or_print_info *info) |
| 164 |
{ |
| 165 |
Widget w = info->printlog; |
| 166 |
if (w != NULL && window_is_mapped(XtWindow(w), DISP)) { |
| 167 |
XRaiseWindow(DISP, XtWindow(w)); |
| 168 |
return True; |
| 169 |
} |
| 170 |
return False; |
| 171 |
} |
| 172 |
|
| 173 |
void |
| 174 |
printlog_popup(struct save_or_print_info *info) |
| 175 |
{ |
| 176 |
Widget w = info->printlog; |
| 177 |
#ifdef MOTIF |
| 178 |
Widget cancel, text; |
| 179 |
#endif |
| 180 |
|
| 181 |
#ifdef MOTIF |
| 182 |
char *text_translations = get_string_va(PRINTLOG_TEXT_TRANSLATIONS, info, info, info, info, info, info); |
| 183 |
char *window_translations = get_string_va(PRINTLOG_WINDOW_TRANSLATIONS, info); |
| 184 |
#endif |
| 185 |
|
| 186 |
printlog_reset(info); |
| 187 |
|
| 188 |
center_window(w, globals.widgets.top_level); |
| 189 |
XtMapWidget(w); |
| 190 |
/* XtPopup(w, XtGrabNone); */ |
| 191 |
#ifndef MOTIF |
| 192 |
XSetWMProtocols(XtDisplay(w), XtWindow(w), &WM_DELETE_WINDOW, 1); |
| 193 |
#else |
| 194 |
XtOverrideTranslations(w, XtParseTranslationTable(window_translations)); |
| 195 |
|
| 196 |
if (get_widget_by_name(&cancel, w, Xdvi_PRINTLOG_CANCEL_NAME, True) |
| 197 |
&& get_widget_by_name(&text, w, Xdvi_PRINTLOG_TEXT_NAME, True)) { |
| 198 |
|
| 199 |
/* This breaks PRINTLOG_WINDOW_OVERRIDE_TRANSLATIONS?? |
| 200 |
* We don't want it activated on Return anyway ... |
| 201 |
*/ |
| 202 |
/* XmProcessTraversal(cancel, XmTRAVERSE_CURRENT); */ |
| 203 |
XtOverrideTranslations(text, XtParseTranslationTable(text_translations)); |
| 204 |
XtOverrideTranslations(text, XtParseTranslationTable(window_translations)); |
| 205 |
free(text_translations); |
| 206 |
free(window_translations); |
| 207 |
} |
| 208 |
#endif |
| 209 |
} |
| 210 |
|
| 211 |
void |
| 212 |
printlog_reset(struct save_or_print_info *info) |
| 213 |
{ |
| 214 |
Widget w = info->printlog; |
| 215 |
Widget text; |
| 216 |
|
| 217 |
if (get_widget_by_name(&text, w, Xdvi_PRINTLOG_TEXT_NAME, True)) { |
| 218 |
#ifndef MOTIF |
| 219 |
XtVaSetValues(text, XtNstring, "", NULL); |
| 220 |
XawTextSetInsertionPoint(text, 0); |
| 221 |
#else |
| 222 |
XmTextSetString(text, ""); |
| 223 |
XtVaSetValues(text, XmNcursorPosition, 0, NULL); |
| 224 |
#endif |
| 225 |
} |
| 226 |
} |
| 227 |
|
| 228 |
|
| 229 |
void |
| 230 |
printlog_create(struct save_or_print_info *info, |
| 231 |
const char *title, |
| 232 |
const char *close_label) |
| 233 |
{ |
| 234 |
Widget printlog_text, printlog_close, printlog_keep, printlog_cancel; |
| 235 |
Widget form, paned, box; |
| 236 |
char *window_translation_str; |
| 237 |
|
| 238 |
#ifdef MOTIF |
| 239 |
XmString str; |
| 240 |
XtTranslations window_override_translations; |
| 241 |
#else |
| 242 |
char *text_translation_str = NULL; |
| 243 |
XtTranslations wm_translations; |
| 244 |
XtTranslations window_translations; |
| 245 |
#endif |
| 246 |
|
| 247 |
#ifdef MOTIF |
| 248 |
window_translation_str = get_string_va(PRINTLOG_WINDOW_OVERRIDE_TRANSLATIONS, info); |
| 249 |
window_override_translations = XtParseTranslationTable(window_translation_str); |
| 250 |
free(window_translation_str); |
| 251 |
#else |
| 252 |
window_translation_str = get_string_va(PRINTLOG_WINDOW_TRANSLATIONS, info); |
| 253 |
window_translations = XtParseTranslationTable(window_translation_str); |
| 254 |
free(window_translation_str); |
| 255 |
#endif |
| 256 |
|
| 257 |
XtAddActions(printlog_actions, XtNumber(printlog_actions)); |
| 258 |
|
| 259 |
#ifndef MOTIF |
| 260 |
|
| 261 |
wm_translations = XtParseTranslationTable("<Message>WM_PROTOCOLS: WM_cancel_or_destroy()"); |
| 262 |
info->printlog = XtVaCreatePopupShell("printlog", |
| 263 |
transientShellWidgetClass, globals.widgets.top_level, |
| 264 |
XtNtitle, title, |
| 265 |
XtNtransientFor, globals.widgets.top_level, |
| 266 |
XtNmappedWhenManaged, False, |
| 267 |
XtNtranslations, wm_translations, |
| 268 |
XtNtransientFor, globals.widgets.top_level, |
| 269 |
NULL); |
| 270 |
|
| 271 |
WM_DELETE_WINDOW = XInternAtom(XtDisplay(info->printlog), "WM_DELETE_WINDOW", False); |
| 272 |
|
| 273 |
XtOverrideTranslations(info->printlog, window_translations); |
| 274 |
|
| 275 |
paned = XtVaCreateManagedWidget("paned", panedWidgetClass, info->printlog, NULL); |
| 276 |
|
| 277 |
form = XtVaCreateManagedWidget("form", formWidgetClass, |
| 278 |
paned, |
| 279 |
XtNdefaultDistance, 6, |
| 280 |
NULL); |
| 281 |
printlog_text = XtVaCreateManagedWidget(Xdvi_PRINTLOG_TEXT_NAME, |
| 282 |
asciiTextWidgetClass, form, |
| 283 |
XtNstring, "", |
| 284 |
XtNdataCompression, False, |
| 285 |
XtNeditType, XawtextAppend, |
| 286 |
XtNscrollHorizontal, XawtextScrollAlways, |
| 287 |
XtNscrollVertical, XawtextScrollAlways, |
| 288 |
XtNwidth, 600, |
| 289 |
XtNheight, 400, |
| 290 |
XtNleft, XawChainLeft, |
| 291 |
XtNright, XawChainRight, |
| 292 |
XtNtop, XawChainTop, |
| 293 |
XtNbottom, XawChainBottom, |
| 294 |
NULL); |
| 295 |
text_translation_str = get_string_va(PRINTLOG_TEXT_TRANSLATIONS, info, info, info, info, info, info); |
| 296 |
XtOverrideTranslations(printlog_text, XtParseTranslationTable(text_translation_str)); |
| 297 |
free(text_translation_str); |
| 298 |
|
| 299 |
printlog_keep = XtVaCreateManagedWidget(Xdvi_PRINTLOG_KEEP_NAME, |
| 300 |
#ifdef XAW |
| 301 |
radioWidgetClass, |
| 302 |
#else |
| 303 |
toggleWidgetClass, |
| 304 |
#endif |
| 305 |
form, |
| 306 |
XtNlabel, close_label, |
| 307 |
XtNborderWidth, 0, |
| 308 |
#ifdef XAW |
| 309 |
XtNisRadio, False, |
| 310 |
#endif |
| 311 |
XtNhighlightThickness, 1, |
| 312 |
XtNfromVert, printlog_text, |
| 313 |
XtNleft, XawChainLeft, |
| 314 |
XtNright, XawChainLeft, |
| 315 |
XtNtop, XawChainBottom, |
| 316 |
XtNbottom, XawChainBottom, |
| 317 |
NULL); |
| 318 |
XtVaSetValues(printlog_keep, |
| 319 |
XtNstate, resource.dvips_hang > 0 && resource.dvips_fail_hang > 0, |
| 320 |
NULL); |
| 321 |
XtAddCallback(printlog_keep, XtNcallback, info->callbacks->cb_keep, (XtPointer)info); |
| 322 |
|
| 323 |
/* box for the Close/Cancel button */ |
| 324 |
box = XtVaCreateManagedWidget("box", formWidgetClass, |
| 325 |
paned, |
| 326 |
/* resizing by user isn't needed */ |
| 327 |
XtNshowGrip, False, |
| 328 |
XtNdefaultDistance, 6, /* some padding */ |
| 329 |
/* resizing the window shouldn't influence this box, |
| 330 |
* but only the pane widget |
| 331 |
*/ |
| 332 |
XtNskipAdjust, True, |
| 333 |
XtNaccelerators, G_accels_cr, |
| 334 |
NULL); |
| 335 |
|
| 336 |
printlog_close = XtVaCreateManagedWidget(Xdvi_PRINTLOG_CLOSE_NAME, |
| 337 |
commandWidgetClass, box, |
| 338 |
XtNlabel, "Close", |
| 339 |
XtNsensitive, False, |
| 340 |
XtNleft, XawChainLeft, |
| 341 |
XtNright, XawChainLeft, |
| 342 |
XtNtop, XawChainBottom, |
| 343 |
XtNbottom, XawChainBottom, |
| 344 |
NULL); |
| 345 |
XtAddCallback(printlog_close, XtNcallback, info->callbacks->cb_close, (XtPointer)info); |
| 346 |
|
| 347 |
printlog_cancel = XtVaCreateManagedWidget(Xdvi_PRINTLOG_CANCEL_NAME, |
| 348 |
commandWidgetClass, box, |
| 349 |
XtNlabel, "Cancel", |
| 350 |
XtNfromHoriz, printlog_keep, |
| 351 |
XtNleft, XawChainRight, |
| 352 |
XtNright, XawChainRight, |
| 353 |
XtNtop, XawChainBottom, |
| 354 |
XtNbottom, XawChainBottom, |
| 355 |
NULL); |
| 356 |
XtAddCallback(printlog_cancel, XtNcallback, info->callbacks->cb_cancel, (XtPointer)info); |
| 357 |
XtManageChild(info->printlog); |
| 358 |
|
| 359 |
printlog_enable_cancelbutton(info); |
| 360 |
|
| 361 |
#else /* MOTIF */ |
| 362 |
info->printlog = XtVaCreatePopupShell("printlog", |
| 363 |
xmDialogShellWidgetClass, globals.widgets.top_level, |
| 364 |
XmNdeleteResponse, XmDO_NOTHING, /* we'll take care of that ourselves */ |
| 365 |
XmNtitle, title, |
| 366 |
XtNmappedWhenManaged, False, |
| 367 |
XmNtranslations, window_override_translations, |
| 368 |
NULL); |
| 369 |
|
| 370 |
WM_DELETE_WINDOW = XmInternAtom(XtDisplay(info->printlog), "WM_DELETE_WINDOW", False); |
| 371 |
XmAddWMProtocolCallback(info->printlog, WM_DELETE_WINDOW, cb_printlog_act_cancel_or_destroy, (XtPointer)info); |
| 372 |
|
| 373 |
paned = XtVaCreateWidget("printlog_pane", xmPanedWindowWidgetClass, info->printlog, |
| 374 |
/* make sashes invisible */ |
| 375 |
XmNsashWidth, 1, |
| 376 |
XmNsashHeight, 1, |
| 377 |
XmNtranslations, window_override_translations, |
| 378 |
NULL); |
| 379 |
|
| 380 |
form = XtVaCreateWidget("form", xmFormWidgetClass, paned, |
| 381 |
XmNhorizontalSpacing, DDIST, |
| 382 |
XmNverticalSpacing, DDIST, |
| 383 |
XmNautoUnmanage, False, |
| 384 |
XmNtranslations, window_override_translations, |
| 385 |
NULL); |
| 386 |
/* force vertical scrollbars. Under Motif 2.x (2.1.0 and 2.2.2 at least), |
| 387 |
XmNeditMode must be set early in order to have an effect. */ |
| 388 |
{ |
| 389 |
Arg args[10]; |
| 390 |
int n = 0; |
| 391 |
XtSetArg(args[n], XmNeditMode, XmMULTI_LINE_EDIT); n++; |
| 392 |
XtSetArg(args[n], XmNeditable, False); n++; |
| 393 |
XtSetArg(args[n], XmNrows, 24); n++; |
| 394 |
XtSetArg(args[n], XmNcolumns, 80); n++; |
| 395 |
|
| 396 |
printlog_text = XmCreateScrolledText(form, Xdvi_PRINTLOG_TEXT_NAME, args, n); |
| 397 |
} |
| 398 |
|
| 399 |
XtVaSetValues(XtParent(printlog_text), |
| 400 |
XmNtopAttachment, XmATTACH_FORM, |
| 401 |
XmNleftAttachment, XmATTACH_FORM, |
| 402 |
XmNrightAttachment, XmATTACH_FORM, |
| 403 |
XmNtranslations, window_override_translations, |
| 404 |
NULL); |
| 405 |
|
| 406 |
XtManageChild(printlog_text); |
| 407 |
|
| 408 |
str = XmStringCreateLocalized((char *)close_label); |
| 409 |
printlog_keep = XtVaCreateManagedWidget(Xdvi_PRINTLOG_KEEP_NAME, |
| 410 |
xmToggleButtonGadgetClass, form, |
| 411 |
XmNlabelString, str, |
| 412 |
XmNindicatorType, XmN_OF_MANY, |
| 413 |
XmNnavigationType, XmTAB_GROUP, |
| 414 |
XmNtopAttachment, XmATTACH_WIDGET, |
| 415 |
XmNtopWidget, XtParent(printlog_text), |
| 416 |
XmNleftAttachment, XmATTACH_FORM, |
| 417 |
XmNtranslations, window_override_translations, |
| 418 |
NULL); |
| 419 |
XmStringFree(str); |
| 420 |
XtAddCallback(printlog_keep, XmNvalueChangedCallback, info->callbacks->cb_keep, (XtPointer)info); |
| 421 |
XmToggleButtonGadgetSetState(printlog_keep, resource.dvips_hang > 0 && resource.dvips_fail_hang > 0, False); |
| 422 |
|
| 423 |
/* box for Close/Cancel button */ |
| 424 |
box = XtVaCreateManagedWidget("box", xmFormWidgetClass, |
| 425 |
paned, |
| 426 |
NULL); |
| 427 |
|
| 428 |
str = XmStringCreateLocalized("Close"); |
| 429 |
printlog_close = XtVaCreateManagedWidget(Xdvi_PRINTLOG_CLOSE_NAME, |
| 430 |
xmPushButtonWidgetClass, box, |
| 431 |
XmNlabelString, str, |
| 432 |
XmNshowAsDefault, True, |
| 433 |
XmNsensitive, False, |
| 434 |
XmNdefaultButtonShadowThickness, 1, |
| 435 |
XmNtopAttachment, XmATTACH_FORM, |
| 436 |
XmNbottomAttachment, XmATTACH_FORM, |
| 437 |
XmNleftAttachment, XmATTACH_FORM, |
| 438 |
/* mimick appearance of native dialog buttons (better way would be |
| 439 |
to extend existing dialog with custom widgets, as in search-dialog.c) */ |
| 440 |
XmNmarginWidth, 6, |
| 441 |
XmNmarginHeight, 4, |
| 442 |
XmNtopOffset, 10, |
| 443 |
XmNbottomOffset, 10, |
| 444 |
XmNleftOffset, 10, |
| 445 |
XmNtranslations, window_override_translations, |
| 446 |
NULL); |
| 447 |
XmStringFree(str); |
| 448 |
XtAddCallback(printlog_close, XmNactivateCallback, info->callbacks->cb_close, (XtPointer)info); |
| 449 |
XtOverrideTranslations(printlog_close, XtParseTranslationTable("<Key>Return:ArmAndActivate()\n")); |
| 450 |
|
| 451 |
|
| 452 |
str = XmStringCreateLocalized("Cancel"); |
| 453 |
printlog_cancel = XtVaCreateManagedWidget(Xdvi_PRINTLOG_CANCEL_NAME, |
| 454 |
xmPushButtonWidgetClass, box, |
| 455 |
XmNlabelString, str, |
| 456 |
XmNdefaultButtonShadowThickness, 1, |
| 457 |
XmNtopAttachment, XmATTACH_FORM, |
| 458 |
XmNbottomAttachment, XmATTACH_FORM, |
| 459 |
XmNrightAttachment, XmATTACH_FORM, |
| 460 |
/* to mimick appearance of native dialog buttons: */ |
| 461 |
XmNmarginWidth, 6, |
| 462 |
XmNmarginHeight, 4, |
| 463 |
XmNtopOffset, 10, |
| 464 |
XmNbottomOffset, 10, |
| 465 |
XmNrightOffset, 10, |
| 466 |
XmNtranslations, window_override_translations, |
| 467 |
NULL); |
| 468 |
XmStringFree(str); |
| 469 |
XtAddCallback(printlog_cancel, XmNactivateCallback, info->callbacks->cb_cancel, (XtPointer)info); |
| 470 |
XtOverrideTranslations(printlog_close, XtParseTranslationTable("<Key>Return:ArmAndActivate()\n")); |
| 471 |
|
| 472 |
XtManageChild(box); |
| 473 |
XtManageChild(form); |
| 474 |
XtManageChild(paned); |
| 475 |
/* center_window(info->printlog, globals.widgets.top_level); */ |
| 476 |
/* XtMapWidget(info->printlog); */ |
| 477 |
/* this doesn't help */ |
| 478 |
/* XtOverrideTranslations(form, XtParseTranslationTable(text_translation_str)); */ |
| 479 |
/* XtOverrideTranslations(paned, XtParseTranslationTable(text_translation_str)); */ |
| 480 |
|
| 481 |
printlog_enable_cancelbutton(info); |
| 482 |
|
| 483 |
#endif |
| 484 |
adjust_width(printlog_close, printlog_cancel); |
| 485 |
} |
| 486 |
|
| 487 |
void |
| 488 |
printlog_append(struct save_or_print_info *info, const char *str, size_t len) |
| 489 |
{ |
| 490 |
Widget text; |
| 491 |
Widget w = info->printlog; |
| 492 |
|
| 493 |
if (!get_widget_by_name(&text, w, Xdvi_PRINTLOG_TEXT_NAME, True)) |
| 494 |
return; |
| 495 |
|
| 496 |
#ifndef MOTIF |
| 497 |
{ |
| 498 |
XawTextPosition point; |
| 499 |
static XawTextBlock block = {0, 0, NULL, 0}; |
| 500 |
|
| 501 |
block.ptr = (char *) str; |
| 502 |
block.length = len; |
| 503 |
block.format = XawFmt8Bit; |
| 504 |
|
| 505 |
point = XawTextGetInsertionPoint(text); |
| 506 |
while (XawTextReplace(text, point, point, &block) != XawEditDone) { |
| 507 |
int length; |
| 508 |
|
| 509 |
XtVaGetValues(text, XtNlength, &length, NULL); |
| 510 |
point = length; |
| 511 |
} |
| 512 |
point += len; |
| 513 |
XawTextSetInsertionPoint(text, point); |
| 514 |
} |
| 515 |
#else /* MOTIF */ |
| 516 |
{ |
| 517 |
XmTextPosition point = XmTextGetInsertionPosition(text); |
| 518 |
XmTextInsert(text, point, (char *) str); |
| 519 |
point += len; |
| 520 |
XtVaSetValues(text, XmNcursorPosition, point, NULL); |
| 521 |
XmTextShowPosition(text, point); |
| 522 |
} |
| 523 |
#endif /* MOTIF */ |
| 524 |
} |
| 525 |
|
| 526 |
void |
| 527 |
printlog_append_str(struct save_or_print_info *info, const char *str) |
| 528 |
{ |
| 529 |
printlog_append(info, str, strlen(str)); |
| 530 |
} |
| 531 |
|
| 532 |
/* enable cancel button, disable close button */ |
| 533 |
void |
| 534 |
printlog_enable_cancelbutton(struct save_or_print_info *info) |
| 535 |
{ |
| 536 |
Widget w = info->printlog; |
| 537 |
Widget close, cancel; |
| 538 |
|
| 539 |
if (get_widget_by_name(&cancel, w, Xdvi_PRINTLOG_CANCEL_NAME, True) |
| 540 |
&& get_widget_by_name(&close, w, Xdvi_PRINTLOG_CLOSE_NAME, True)) { |
| 541 |
|
| 542 |
XtSetSensitive(close, False); |
| 543 |
XtSetSensitive(cancel, True); |
| 544 |
#if MOTIF |
| 545 |
/* This breaks PRINTLOG_WINDOW_OVERRIDE_TRANSLATIONS?? |
| 546 |
* We don't want it activated on Return anyway ... |
| 547 |
*/ |
| 548 |
/* XmProcessTraversal(cancel, XmTRAVERSE_CURRENT); */ |
| 549 |
#endif |
| 550 |
} |
| 551 |
} |
| 552 |
|
| 553 |
/* disable cancel button, enable close button */ |
| 554 |
void |
| 555 |
printlog_enable_closebutton(struct save_or_print_info *info) |
| 556 |
{ |
| 557 |
Widget w = info->printlog; |
| 558 |
Widget close, cancel; |
| 559 |
|
| 560 |
if (get_widget_by_name(&cancel, w, Xdvi_PRINTLOG_CANCEL_NAME, True) |
| 561 |
&& get_widget_by_name(&close, w, Xdvi_PRINTLOG_CLOSE_NAME, True)) { |
| 562 |
#if MOTIF |
| 563 |
char *window_translations = get_string_va(PRINTLOG_WINDOW_TRANSLATIONS, info); |
| 564 |
#endif |
| 565 |
XtSetSensitive(close, True); |
| 566 |
XtSetSensitive(cancel, False); |
| 567 |
#if MOTIF |
| 568 |
XmProcessTraversal(close, XmTRAVERSE_CURRENT); |
| 569 |
XtOverrideTranslations(close, XtParseTranslationTable(window_translations)); |
| 570 |
free(window_translations); |
| 571 |
#endif |
| 572 |
} |
| 573 |
} |
| 574 |
|
| 575 |
static void |
| 576 |
printlog_internal_close(struct save_or_print_info *info) |
| 577 |
{ |
| 578 |
Widget w = info->printlog; |
| 579 |
Widget text; |
| 580 |
|
| 581 |
XtUnmapWidget(w); |
| 582 |
|
| 583 |
if (get_widget_by_name(&text, w, Xdvi_PRINTLOG_TEXT_NAME, True)) { |
| 584 |
#ifndef MOTIF |
| 585 |
XtVaSetValues(text, XtNstring, "", NULL); |
| 586 |
#else |
| 587 |
XmTextSetString(text, ""); |
| 588 |
#endif |
| 589 |
} |
| 590 |
} |
| 591 |
|
| 592 |
void |
| 593 |
printlog_popdown(struct save_or_print_info *info, Boolean force) |
| 594 |
{ |
| 595 |
Widget w = info->printlog; |
| 596 |
Widget keep; |
| 597 |
|
| 598 |
if (force) { /* user clicked on `Close' */ |
| 599 |
printlog_internal_close(info); |
| 600 |
} |
| 601 |
else if (get_widget_by_name(&keep, w, Xdvi_PRINTLOG_KEEP_NAME, True)) { /* timer elapsed */ |
| 602 |
#ifndef MOTIF |
| 603 |
Boolean state; |
| 604 |
XtVaGetValues(keep, XtNstate, &state, NULL); |
| 605 |
if (state) { |
| 606 |
printlog_internal_close(info); |
| 607 |
} |
| 608 |
#else |
| 609 |
if (XmToggleButtonGadgetGetState(keep)) { |
| 610 |
printlog_internal_close(info); |
| 611 |
} |
| 612 |
#endif |
| 613 |
} |
| 614 |
} |
| 615 |
|
| 616 |
|
| 617 |
static void |
| 618 |
printlog_act_close(Widget w, XEvent *event, String *params, Cardinal *num_params) |
| 619 |
{ |
| 620 |
void *ptr; |
| 621 |
struct save_or_print_info *info; |
| 622 |
|
| 623 |
UNUSED(w); |
| 624 |
UNUSED(event); |
| 625 |
|
| 626 |
if (*num_params < 1) { |
| 627 |
XDVI_WARNING((stderr, "Wrong argument number (%d) in callback!", *num_params)); |
| 628 |
return; |
| 629 |
} |
| 630 |
sscanf(*params, "%p", &ptr); |
| 631 |
info = (struct save_or_print_info *)ptr; |
| 632 |
|
| 633 |
ASSERT(info->callbacks != NULL && info->callbacks->cb_close != NULL, "Callback not initialized"); |
| 634 |
info->callbacks->cb_close(w, info, NULL); |
| 635 |
} |
| 636 |
|
| 637 |
static void |
| 638 |
printlog_act_keep(Widget w, XEvent *event, String *params, Cardinal *num_params) |
| 639 |
{ |
| 640 |
void *ptr; |
| 641 |
struct save_or_print_info *info; |
| 642 |
Widget keep; |
| 643 |
|
| 644 |
UNUSED(w); |
| 645 |
UNUSED(event); |
| 646 |
|
| 647 |
if (*num_params < 1) { |
| 648 |
XDVI_WARNING((stderr, "Wrong argument number (%d) in callback!", *num_params)); |
| 649 |
return; |
| 650 |
} |
| 651 |
sscanf(*params, "%p", &ptr); |
| 652 |
info = (struct save_or_print_info *)ptr; |
| 653 |
|
| 654 |
ASSERT(info->callbacks != NULL && info->callbacks->cb_keep != NULL, "Callback not initialized"); |
| 655 |
info->callbacks->cb_keep(w, info, NULL); |
| 656 |
|
| 657 |
if (get_widget_by_name(&keep, info->printlog, Xdvi_PRINTLOG_KEEP_NAME, True)) { |
| 658 |
#ifdef MOTIF |
| 659 |
XmToggleButtonGadgetSetState(keep, False, False); |
| 660 |
#else |
| 661 |
XtVaSetValues(keep, XtNstate, False, NULL); |
| 662 |
#endif |
| 663 |
} |
| 664 |
} |
| 665 |
|
| 666 |
|
| 667 |
static void |
| 668 |
printlog_act_unkeep(Widget w, XEvent *event, String *params, Cardinal *num_params) |
| 669 |
{ |
| 670 |
void *ptr; |
| 671 |
struct save_or_print_info *info; |
| 672 |
Widget keep; |
| 673 |
|
| 674 |
UNUSED(w); |
| 675 |
UNUSED(event); |
| 676 |
|
| 677 |
if (*num_params < 1) { |
| 678 |
XDVI_WARNING((stderr, "Wrong argument number (%d) in callback!", *num_params)); |
| 679 |
return; |
| 680 |
} |
| 681 |
sscanf(*params, "%p", &ptr); |
| 682 |
info = (struct save_or_print_info *)ptr; |
| 683 |
|
| 684 |
if (get_widget_by_name(&keep, info->printlog, Xdvi_PRINTLOG_KEEP_NAME, True)) { |
| 685 |
#ifdef MOTIF |
| 686 |
XmToggleButtonGadgetSetState(keep, True, False); |
| 687 |
#else |
| 688 |
XtVaSetValues(keep, XtNstate, True, NULL); |
| 689 |
#endif |
| 690 |
} |
| 691 |
} |
| 692 |
|
| 693 |
|
| 694 |
static void |
| 695 |
printlog_act_cancel(Widget w, XEvent *event, String *params, Cardinal *num_params) |
| 696 |
{ |
| 697 |
void *ptr; |
| 698 |
struct save_or_print_info *info; |
| 699 |
|
| 700 |
UNUSED(w); |
| 701 |
UNUSED(event); |
| 702 |
|
| 703 |
if (*num_params < 1) { |
| 704 |
XDVI_WARNING((stderr, "Wrong argument number (%d) in callback!", *num_params)); |
| 705 |
return; |
| 706 |
} |
| 707 |
sscanf(*params, "%p", &ptr); |
| 708 |
info = (struct save_or_print_info *)ptr; |
| 709 |
|
| 710 |
ASSERT(info->callbacks != NULL && info->callbacks->cb_cancel != NULL, "Callback not initialized"); |
| 711 |
info->callbacks->cb_cancel(w, info, NULL); |
| 712 |
} |
| 713 |
|
| 714 |
|
| 715 |
static void |
| 716 |
printlog_act_cancel_or_destroy(Widget w, XEvent *event, String *params, Cardinal *num_params) |
| 717 |
{ |
| 718 |
void *ptr; |
| 719 |
|
| 720 |
UNUSED(w); |
| 721 |
UNUSED(event); |
| 722 |
|
| 723 |
if (*num_params < 1) { |
| 724 |
XDVI_WARNING((stderr, "Wrong argument number (%d) in callback!", *num_params)); |
| 725 |
return; |
| 726 |
} |
| 727 |
sscanf(*params, "%p", &ptr); |
| 728 |
|
| 729 |
cb_printlog_act_cancel_or_destroy(w, (XtPointer)ptr, NULL); |
| 730 |
|
| 731 |
/* ASSERT(info->callbacks != NULL && info->callbacks->cb_cancel != NULL, "Callback not initialized"); */ |
| 732 |
/* info->callbacks->cb_cancel(w, info, NULL); */ |
| 733 |
} |