| 1 |
/* |
| 2 |
* Copyright (c) 2004 Stefan Ulrich |
| 3 |
* |
| 4 |
* Permission is hereby granted, free of charge, to any person obtaining a copy |
| 5 |
* of this software and associated documentation files (the "Software"), to |
| 6 |
* deal in the Software without restriction, including without limitation the |
| 7 |
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
| 8 |
* sell copies of the Software, and to permit persons to whom the Software is |
| 9 |
* furnished to do so, subject to the following conditions: |
| 10 |
* |
| 11 |
* The above copyright notice and this permission notice shall be included in |
| 12 |
* all copies or substantial portions of the Software. |
| 13 |
* |
| 14 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 15 |
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 16 |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 17 |
* PAUL VOJTA OR ANY OTHER AUTHOR OF THIS SOFTWARE BE LIABLE FOR ANY CLAIM, |
| 18 |
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
| 19 |
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 20 |
* OTHER DEALINGS IN THE SOFTWARE. |
| 21 |
* |
| 22 |
*/ |
| 23 |
|
| 24 |
/* |
| 25 |
* Panel 4 (Paper size) for xdvik preferences dialog. |
| 26 |
*/ |
| 27 |
|
| 28 |
#include "xdvi-config.h" |
| 29 |
#include "xdvi.h" |
| 30 |
|
| 31 |
#include "x_util.h" |
| 32 |
#include "xm_colorsel.h" |
| 33 |
#include "topic-window.h" |
| 34 |
#include "util.h" |
| 35 |
#include "events.h" |
| 36 |
#include "statusline.h" |
| 37 |
|
| 38 |
#include "xm_prefsP.h" |
| 39 |
#include "xm_prefs_page.h" |
| 40 |
#include "my-snprintf.h" |
| 41 |
|
| 42 |
#ifdef MOTIF /* entire file */ |
| 43 |
|
| 44 |
#include <X11/Xatom.h> |
| 45 |
|
| 46 |
#include <Xm/Xm.h> |
| 47 |
#include <Xm/Protocols.h> |
| 48 |
#include <Xm/DialogS.h> |
| 49 |
#include <Xm/LabelG.h> |
| 50 |
#include <Xm/PushB.h> |
| 51 |
#include <Xm/PushBG.h> |
| 52 |
#include <Xm/Form.h> |
| 53 |
#include <Xm/Frame.h> |
| 54 |
#include <Xm/PanedW.h> |
| 55 |
#include <Xm/DrawnB.h> |
| 56 |
#include <Xm/RowColumn.h> |
| 57 |
#include <Xm/Scale.h> |
| 58 |
#include <Xm/ToggleBG.h> |
| 59 |
#include <Xm/Text.h> |
| 60 |
#include <Xm/TextF.h> |
| 61 |
#include <Xm/CascadeBG.h> |
| 62 |
|
| 63 |
#if USE_SPINBOX |
| 64 |
#include <Xm/SpinB.h> |
| 65 |
#endif |
| 66 |
|
| 67 |
/* |
| 68 |
* Handy defaults |
| 69 |
*/ |
| 70 |
static Arg one_of_many = { XmNindicatorType, XmONE_OF_MANY }; |
| 71 |
static Arg n_of_many = { XmNindicatorType, XmN_OF_MANY }; |
| 72 |
static Arg frame_title = { XmNchildType, XmFRAME_TITLE_CHILD }; |
| 73 |
static Arg one_col[] = { |
| 74 |
{ XmNpacking, XmPACK_TIGHT }, |
| 75 |
{ XmNnumColumns, 1 }, |
| 76 |
{ XmNorientation, XmVERTICAL } |
| 77 |
}; |
| 78 |
|
| 79 |
|
| 80 |
/* this is a small selection from the paper types in xdvi.c |
| 81 |
* (only the more frequenlty used ones) |
| 82 |
*/ |
| 83 |
static struct paper_info { |
| 84 |
const char *format; |
| 85 |
const char *resource_format; |
| 86 |
const char *size; |
| 87 |
const char *landscape_size; |
| 88 |
} papersizes[] = { |
| 89 |
{ "US (Letter)", "us", "8.5x11in", "11x8.5in" }, |
| 90 |
{ "Tabloid", "tabloid", "11x17in", "17x11in" }, /* dvips compatibility */ |
| 91 |
{ "Legal", "legal", "8.5x14in", "14x8.5in" }, |
| 92 |
{ "A0", "a0", "841x1189mm", "1189x841mm" }, |
| 93 |
{ "A1", "a1", "594x841mm", "841x594mm" }, |
| 94 |
{ "A2", "a2", "420x594mm", "594x420mm" }, |
| 95 |
{ "A3", "a3", "297x420mm", "420x297mm" }, |
| 96 |
{ "A4", "a4", "210x297mm", "297x210mm" }, |
| 97 |
{ "A5", "a5", "148x210mm", "210x148mm" }, |
| 98 |
{ "B5", "b5", "176x250mm", "250x176mm" }, |
| 99 |
{ "B6", "b6", "125x176mm", "176x125mm" }, |
| 100 |
{ "B7", "b7", "88x125mm", "125x88mm" }, |
| 101 |
{ NULL, NULL, NULL, NULL } /* terminate */ |
| 102 |
}; |
| 103 |
|
| 104 |
void update_preferences_windowsize(void) |
| 105 |
{ |
| 106 |
Widget shell, button; |
| 107 |
|
| 108 |
/* it's not an error if the prefs dialog doesn't exist yet */ |
| 109 |
if (get_widget_by_name(&shell, globals.widgets.top_level, Xdvi_PREFS_DIALOG_NAME, False) |
| 110 |
&& get_widget_by_name(&button, shell, Xdvi_REMEMBER_WINDOWSIZE_STR, True)) { |
| 111 |
XmToggleButtonGadgetSetState(button, resource.remember_windowsize, False); |
| 112 |
} |
| 113 |
} |
| 114 |
|
| 115 |
void update_preferences_shrink(void) |
| 116 |
{ |
| 117 |
Widget shell, text; |
| 118 |
|
| 119 |
if (get_widget_by_name(&shell, globals.widgets.top_level, Xdvi_PREFS_DIALOG_NAME, False) |
| 120 |
&& get_widget_by_name(&text, shell, Xdvi_SHRINK_TEXT, True)) { |
| 121 |
char buf[LENGTH_OF_INT]; |
| 122 |
SNPRINTF(buf, LENGTH_OF_INT, "%d", resource.shrinkfactor); |
| 123 |
#if USE_SPINBOX |
| 124 |
XmTextFieldSetString(text, buf); |
| 125 |
XtVaSetValues(text, XmNposition, resource.shrinkfactor, NULL); |
| 126 |
#else |
| 127 |
XtVaSetValues(text, XmNvalue, buf, NULL); |
| 128 |
#endif |
| 129 |
} |
| 130 |
} |
| 131 |
|
| 132 |
static void |
| 133 |
landscape_cb(Widget w, XtPointer client_data, XtPointer call_data) |
| 134 |
{ |
| 135 |
struct topic_info *tinfo = (struct topic_info *)client_data; |
| 136 |
struct prefs_choice *prefs = (struct prefs_choice *)tinfo->data; |
| 137 |
Widget portrait_b, landscape_b; |
| 138 |
Boolean landscape = False, is_set; |
| 139 |
static char *paper_option = NULL; |
| 140 |
Boolean match = False; |
| 141 |
int i; |
| 142 |
|
| 143 |
UNUSED(call_data); |
| 144 |
|
| 145 |
for (i = 0; papersizes[i].format != NULL; i++) { |
| 146 |
/* ignore final `r' when comparing */ |
| 147 |
if (strncmp(resource.paper, |
| 148 |
papersizes[i].resource_format, |
| 149 |
strlen(papersizes[i].resource_format)) == 0) { |
| 150 |
const char *ptr; |
| 151 |
match = True; |
| 152 |
if (strcmp(resource.paper, "letter") == 0) /* special case */ |
| 153 |
ptr = "us"; |
| 154 |
else |
| 155 |
ptr = papersizes[i].resource_format; |
| 156 |
free(paper_option); |
| 157 |
paper_option = xstrdup(ptr); |
| 158 |
break; |
| 159 |
} |
| 160 |
} |
| 161 |
|
| 162 |
if (!match) { |
| 163 |
XDVI_ERROR((stderr, "paper resource `%s' not found in list!\n", resource.paper)); |
| 164 |
return; |
| 165 |
} |
| 166 |
|
| 167 |
if (get_widget_by_name(&portrait_b, tinfo->shell, Xdvi_PAPER_PORTRAIT_STR, True) |
| 168 |
&& get_widget_by_name(&landscape_b, tinfo->shell, Xdvi_PAPER_LANDSCAPE_STR, True)) { |
| 169 |
|
| 170 |
if (w == portrait_b) { |
| 171 |
XtVaGetValues(portrait_b, XmNset, &is_set, NULL); |
| 172 |
landscape = !is_set; |
| 173 |
} |
| 174 |
else { |
| 175 |
XtVaGetValues(landscape_b, XmNset, &is_set, NULL); |
| 176 |
landscape = is_set; |
| 177 |
} |
| 178 |
|
| 179 |
/* fprintf(stderr, "++++++++ CALLBACK: setting portrait to %s, landscape to %s\n", */ |
| 180 |
/* landscape ? "False" : "True", */ |
| 181 |
/* landscape ? "True" : "False"); */ |
| 182 |
|
| 183 |
XmToggleButtonGadgetSetState(portrait_b, !landscape, False); |
| 184 |
XmToggleButtonGadgetSetState(landscape_b, landscape, False); |
| 185 |
} |
| 186 |
|
| 187 |
if (landscape) { |
| 188 |
paper_option = xstrcat(paper_option, "r"); |
| 189 |
} |
| 190 |
|
| 191 |
resource.paper = paper_option; |
| 192 |
store_preference(&(prefs->db), "paper", "%s", paper_option); |
| 193 |
} |
| 194 |
|
| 195 |
static void |
| 196 |
select_cb(Widget w, XtPointer client_data, XtPointer call_data) |
| 197 |
{ |
| 198 |
struct topic_info *tinfo = (struct topic_info *)client_data; |
| 199 |
struct prefs_choice *prefs = (struct prefs_choice *)tinfo->data; |
| 200 |
|
| 201 |
XmString str; |
| 202 |
char *choice; |
| 203 |
int i; |
| 204 |
static char *curr_choice= NULL; |
| 205 |
Boolean landscape = False; |
| 206 |
|
| 207 |
UNUSED(call_data); |
| 208 |
|
| 209 |
XtVaGetValues(w, XmNlabelString, &str, NULL); |
| 210 |
XmStringGetLtoR(str, G_charset, &choice); |
| 211 |
|
| 212 |
if (strlen(resource.paper) > 0 && |
| 213 |
strcmp(resource.paper, "letter") != 0 && |
| 214 |
resource.paper[strlen(resource.paper) - 1] == 'r') |
| 215 |
landscape = True; |
| 216 |
|
| 217 |
free(curr_choice); |
| 218 |
curr_choice = NULL; |
| 219 |
for (i = 0; papersizes[i].format != NULL; i++) { |
| 220 |
if (strcmp(choice, papersizes[i].format) == 0) { |
| 221 |
curr_choice = xstrdup(papersizes[i].resource_format); |
| 222 |
} |
| 223 |
} |
| 224 |
if (curr_choice == NULL) { |
| 225 |
XDVI_ERROR((stderr, "choice`%s' not found in list!\n", choice)); |
| 226 |
return; |
| 227 |
} |
| 228 |
|
| 229 |
if (landscape) { |
| 230 |
curr_choice = xstrcat(curr_choice, "r"); |
| 231 |
} |
| 232 |
|
| 233 |
resource.paper = curr_choice; |
| 234 |
store_preference(&(prefs->db), "paper", "%s", curr_choice); |
| 235 |
} |
| 236 |
|
| 237 |
void |
| 238 |
update_preferences_paper(void) |
| 239 |
{ |
| 240 |
Widget shell, portrait_button, landscape_button, sizes_menu, sizes_cascade; |
| 241 |
Boolean landscape = False; |
| 242 |
|
| 243 |
/* it's not an error if the prefs dialog doesn't exist yet */ |
| 244 |
if (get_widget_by_name(&shell, globals.widgets.top_level, Xdvi_PREFS_DIALOG_NAME, False) |
| 245 |
&& get_widget_by_name(&portrait_button, shell, Xdvi_PAPER_PORTRAIT_STR, True) |
| 246 |
&& get_widget_by_name(&landscape_button, shell, Xdvi_PAPER_LANDSCAPE_STR, True) |
| 247 |
&& get_widget_by_name(&sizes_menu, shell, Xdvi_PAPER_MENU, True) |
| 248 |
&& get_widget_by_name(&sizes_cascade, shell, Xdvi_PAPER_CASCADE, True)) { |
| 249 |
|
| 250 |
int i; |
| 251 |
Widget sizes_button; |
| 252 |
|
| 253 |
if (strlen(resource.paper) > 0 && |
| 254 |
strcmp(resource.paper, "letter") != 0 && |
| 255 |
resource.paper[strlen(resource.paper) - 1] == 'r') { |
| 256 |
|
| 257 |
landscape = True; |
| 258 |
} |
| 259 |
|
| 260 |
#if 0 |
| 261 |
XtVaGetValues(portrait_button, XmNset, &test1, NULL); |
| 262 |
XtVaGetValues(landscape_button, XmNset, &test2, NULL); |
| 263 |
|
| 264 |
fprintf(stderr, "+++++++ old state of portrait: %d, landscape: %d\n", |
| 265 |
test1, test2); |
| 266 |
|
| 267 |
fprintf(stderr, "+++++++ setting portrait to %s, landscape to %s\n", |
| 268 |
landscape ? "False" : "True", |
| 269 |
landscape ? "True" : "False"); |
| 270 |
#endif /* 0 */ |
| 271 |
|
| 272 |
/* |
| 273 |
Apparently there's a bug in Motif (OpenMotif 2.1) in that the button |
| 274 |
is not properly updated in all cases. |
| 275 |
|
| 276 |
To reproduce: |
| 277 |
|
| 278 |
Open Preferences dialog, change `landscape' option, click |
| 279 |
`OK'. Now open the dialog again, change the option again, |
| 280 |
but click `Cancel'. This correctly reverts the visible |
| 281 |
state of the buttons, but when opening the dialog again, |
| 282 |
the button's internal state is not consistent with the |
| 283 |
visual appearance: when clicking on the unset button, its |
| 284 |
ValueChanged callback is not invoked, so nothing happens; |
| 285 |
but after clicking on another(!) button in the preferences |
| 286 |
dialog, it works again. |
| 287 |
|
| 288 |
As a workaround, we destroy the buttons and re-create them from scratch - yuck! |
| 289 |
*/ |
| 290 |
{ |
| 291 |
Widget form = XtParent(portrait_button); |
| 292 |
Widget cascade; |
| 293 |
struct topic_info *info; |
| 294 |
|
| 295 |
XtVaGetValues(portrait_button, |
| 296 |
XmNleftWidget, &cascade, |
| 297 |
XmNuserData, &info, |
| 298 |
NULL); |
| 299 |
XtDestroyWidget(portrait_button); |
| 300 |
XtDestroyWidget(landscape_button); |
| 301 |
|
| 302 |
portrait_button = XmCreateToggleButtonGadget(form, Xdvi_PAPER_PORTRAIT_STR, &one_of_many, 1); |
| 303 |
XmToggleButtonGadgetSetState(portrait_button, !landscape, False); |
| 304 |
XtVaSetValues(portrait_button, |
| 305 |
XmNtopAttachment, XmATTACH_FORM, |
| 306 |
XmNbottomAttachment, XmATTACH_FORM, |
| 307 |
XmNleftAttachment, XmATTACH_WIDGET, |
| 308 |
XmNleftWidget, cascade, |
| 309 |
XmNleftOffset, 10, |
| 310 |
XmNuserData, (XtPointer)info, |
| 311 |
NULL); |
| 312 |
landscape_button = XmCreateToggleButtonGadget(form, Xdvi_PAPER_LANDSCAPE_STR, &one_of_many, 1); |
| 313 |
XmToggleButtonGadgetSetState(landscape_button, landscape, False); |
| 314 |
XtVaSetValues(landscape_button, |
| 315 |
XmNtopAttachment, XmATTACH_FORM, |
| 316 |
XmNbottomAttachment, XmATTACH_FORM, |
| 317 |
XmNleftAttachment, XmATTACH_WIDGET, |
| 318 |
XmNleftWidget, portrait_button, |
| 319 |
XmNleftOffset, 10, |
| 320 |
XmNuserData, (XtPointer)info, |
| 321 |
NULL); |
| 322 |
XtManageChild(portrait_button); |
| 323 |
XtManageChild(landscape_button); |
| 324 |
XtAddCallback(portrait_button, XmNvalueChangedCallback, landscape_cb, (XtPointer)info); |
| 325 |
XtAddCallback(landscape_button, XmNvalueChangedCallback, landscape_cb, (XtPointer)info); |
| 326 |
} |
| 327 |
#if 0 |
| 328 |
XtVaGetValues(portrait_button, XmNset, &test1, NULL); |
| 329 |
XtVaGetValues(landscape_button, XmNset, &test2, NULL); |
| 330 |
|
| 331 |
fprintf(stderr, "+++++++ new state of portrait: %d, landscape: %d\n", |
| 332 |
test1, test2); |
| 333 |
#endif /* 0 */ |
| 334 |
|
| 335 |
for (i = 0; papersizes[i].format != NULL; i++) { |
| 336 |
if (strncmp(resource.paper, |
| 337 |
papersizes[i].resource_format, |
| 338 |
strlen(papersizes[i].resource_format)) == 0 |
| 339 |
&& get_widget_by_name(&sizes_button, sizes_menu, papersizes[i].format, True)) { |
| 340 |
|
| 341 |
XtVaSetValues(sizes_cascade, XmNmenuHistory, sizes_button, NULL); |
| 342 |
} |
| 343 |
} |
| 344 |
} |
| 345 |
} |
| 346 |
|
| 347 |
#if 0 /* currently unused */ |
| 348 |
static void |
| 349 |
shrinkfactor_spinbox_cb(Widget w, XtPointer client_data, XtPointer call_data) |
| 350 |
{ |
| 351 |
int val; |
| 352 |
/* static Boolean first_time = True; */ |
| 353 |
struct topic_info *info = (struct topic_info *)client_data; |
| 354 |
struct prefs_choice *prefs = (struct prefs_choice *)(info->data); |
| 355 |
UNUSED(call_data); |
| 356 |
|
| 357 |
XtVaGetValues(w, XmNposition, &val, NULL); |
| 358 |
|
| 359 |
/* return if value not changed yet; else the first invocation of the |
| 360 |
window may actually reset the shrink factor to the default. |
| 361 |
*/ |
| 362 |
/* if (val != resource.shrinkfactor) { */ |
| 363 |
/* first_time = False; */ |
| 364 |
/* } */ |
| 365 |
|
| 366 |
if (XtIsRealized(w)) { |
| 367 |
/* don't set the resource.shrinkfactor here so that we can revert it from there if needed */ |
| 368 |
do_set_shrinkfactor(val, False); |
| 369 |
store_preference(&(prefs->db), "shrinkFactor", "%d", val); |
| 370 |
} |
| 371 |
} |
| 372 |
#endif /* currently unused */ |
| 373 |
|
| 374 |
static void |
| 375 |
set_shrinkfactor_cb(Widget w, XtPointer client_data, XtPointer call_data) |
| 376 |
{ |
| 377 |
char *text; |
| 378 |
int val; |
| 379 |
struct topic_info *info = (struct topic_info *)client_data; |
| 380 |
struct prefs_choice *prefs = (struct prefs_choice *)(info->data); |
| 381 |
|
| 382 |
#if USE_SPINBOX |
| 383 |
XmTextPosition pos; |
| 384 |
UNUSED(call_data); |
| 385 |
text = XmTextFieldGetString(w); |
| 386 |
val = strtol(text, (char **)NULL, 10); |
| 387 |
#else |
| 388 |
Widget text_field; |
| 389 |
UNUSED(call_data); |
| 390 |
XtVaGetValues(w, XmNuserData, &text_field, NULL); |
| 391 |
ASSERT(text_field != 0, "Expected text field in XmNuserData, set_shrinkfactor_cb()"); |
| 392 |
XtVaGetValues(text_field, XmNvalue, &text, NULL); |
| 393 |
val = strtol(text, (char **)NULL, 10); |
| 394 |
/* fprintf(stderr, "spinbox value: |%s|\n", text); */ |
| 395 |
#endif |
| 396 |
|
| 397 |
if (!XtIsRealized(w)) |
| 398 |
return; |
| 399 |
|
| 400 |
/* verify values in case of direct text input */ |
| 401 |
if (val > 100 || val <= 0) { |
| 402 |
if (val > 100) |
| 403 |
statusline_info(STATUS_MEDIUM, "Shrink factor larger than maximum 100"); |
| 404 |
else if (val <= 0) |
| 405 |
statusline_info(STATUS_MEDIUM, "Shrink factor smaller than minimum 1"); |
| 406 |
return; |
| 407 |
} |
| 408 |
#if USE_SPINBOX |
| 409 |
/* synchronize internal spinbox value */ |
| 410 |
pos = XmTextFieldGetInsertionPosition(w); |
| 411 |
XtVaSetValues(w, XmNposition, val, NULL); |
| 412 |
XmTextFieldSetInsertionPosition(w, pos); |
| 413 |
#endif |
| 414 |
/* don't set the resource.shrinkfactor here so that we can revert it from there if needed */ |
| 415 |
do_set_shrinkfactor(val, False); |
| 416 |
store_preference(&(prefs->db), "shrinkFactor", "%d", val); |
| 417 |
|
| 418 |
XtFree(text); |
| 419 |
} |
| 420 |
|
| 421 |
static Widget |
| 422 |
h_create_shrink_frame(Widget top, struct topic_info *info) |
| 423 |
{ |
| 424 |
Widget shrink_form, shrink_label; |
| 425 |
|
| 426 |
UNUSED(info); |
| 427 |
|
| 428 |
shrink_form = XmCreateForm(top, "shrink_form", NULL, 0); |
| 429 |
XtVaSetValues(shrink_form, |
| 430 |
/* XmNverticalSpacing, 10, */ |
| 431 |
/* XmNhorizontalSpacing, 10, */ |
| 432 |
NULL); |
| 433 |
|
| 434 |
|
| 435 |
shrink_label = XmCreateLabelGadget(shrink_form, "Default Shrink Factor: ", NULL, 0); |
| 436 |
XtVaSetValues(shrink_label, |
| 437 |
XmNtopAttachment, XmATTACH_FORM, |
| 438 |
XmNleftAttachment, XmATTACH_FORM, |
| 439 |
XmNbottomAttachment, XmATTACH_FORM, |
| 440 |
/* TODO XmNleftOffset, 10, */ |
| 441 |
NULL); |
| 442 |
XtManageChild(shrink_label); |
| 443 |
{ |
| 444 |
Widget shrink_text; |
| 445 |
#if USE_SPINBOX |
| 446 |
Widget shrink_spinbox = |
| 447 |
XtVaCreateManagedWidget(Xdvi_SHRINK_SPINBOX, xmSpinBoxWidgetClass, shrink_form, |
| 448 |
XmNtopAttachment, XmATTACH_FORM, |
| 449 |
XmNleftAttachment, XmATTACH_WIDGET, |
| 450 |
XmNleftWidget, shrink_label, |
| 451 |
XmNinitialDelay, 200, |
| 452 |
XmNrepeatDelay, 50, |
| 453 |
NULL); |
| 454 |
shrink_text = |
| 455 |
XtVaCreateManagedWidget(Xdvi_SHRINK_TEXT, xmTextFieldWidgetClass, shrink_spinbox, |
| 456 |
XmNspinBoxChildType, XmNUMERIC, |
| 457 |
XmNminimumValue, 1, |
| 458 |
XmNmaximumValue, 100, |
| 459 |
XmNeditable, True, |
| 460 |
XmNcolumns, 3, |
| 461 |
XmNincrementValue, 1, |
| 462 |
XmNwrap, False, /* too confusing */ |
| 463 |
/* NOTE: use resource.shrinkfactor here, not current setting, |
| 464 |
otherwise the current setting will sneak into ~/.xdvirc */ |
| 465 |
XmNposition, (int)(resource.shrinkfactor), |
| 466 |
NULL); |
| 467 |
|
| 468 |
XtAddCallback(shrink_text, XmNactivateCallback, set_shrinkfactor_cb, (XtPointer)info); |
| 469 |
XtAddCallback(shrink_text, XmNvalueChangedCallback, set_shrinkfactor_cb, (XtPointer)info); |
| 470 |
|
| 471 |
adjust_heights(shrink_spinbox, shrink_text, shrink_label, NULL); |
| 472 |
|
| 473 |
#else |
| 474 |
char buf[LENGTH_OF_INT]; |
| 475 |
Widget shrink_button; |
| 476 |
shrink_text = XmCreateTextField(shrink_form, Xdvi_SHRINK_TEXT, NULL, 0); |
| 477 |
SNPRINTF(buf, LENGTH_OF_INT, "%d", resource.shrinkfactor); |
| 478 |
XtVaSetValues(shrink_text, |
| 479 |
XmNtopAttachment, XmATTACH_FORM, |
| 480 |
XmNleftAttachment, XmATTACH_WIDGET, |
| 481 |
XmNleftWidget, shrink_label, |
| 482 |
XmNcolumns, 4, |
| 483 |
XmNvalue, buf, |
| 484 |
XmNuserData, shrink_text, |
| 485 |
NULL); |
| 486 |
XtOverrideTranslations(shrink_text, XtParseTranslationTable("<Key>Return:activate()")); |
| 487 |
XtAddCallback(shrink_text, XmNactivateCallback, set_shrinkfactor_cb, (XtPointer)info); |
| 488 |
|
| 489 |
shrink_button = XmCreatePushButton(shrink_form, Xdvi_APPLY_STR, NULL, 0); |
| 490 |
XtVaSetValues(shrink_button, |
| 491 |
XmNtopAttachment, XmATTACH_FORM, |
| 492 |
XmNleftAttachment, XmATTACH_WIDGET, |
| 493 |
XmNleftOffset, 10, |
| 494 |
XmNleftWidget, shrink_text, |
| 495 |
XmNuserData, shrink_text, |
| 496 |
NULL); |
| 497 |
XtAddCallback(shrink_button, XmNactivateCallback, set_shrinkfactor_cb, (XtPointer)info); |
| 498 |
|
| 499 |
adjust_heights(shrink_label, shrink_text, shrink_button, NULL); |
| 500 |
XtManageChild(shrink_text); |
| 501 |
XtManageChild(shrink_button); |
| 502 |
#endif |
| 503 |
} |
| 504 |
|
| 505 |
/* XtManageChild(shrink_form); */ |
| 506 |
|
| 507 |
return shrink_form; |
| 508 |
} |
| 509 |
|
| 510 |
static void |
| 511 |
remember_windowsize_cb(Widget w, XtPointer client_data, XtPointer call_data) |
| 512 |
{ |
| 513 |
struct topic_info *info = (struct topic_info *)client_data; |
| 514 |
struct prefs_choice *prefs = (struct prefs_choice *)(info->data); |
| 515 |
|
| 516 |
UNUSED(w); |
| 517 |
UNUSED(call_data); |
| 518 |
|
| 519 |
resource.remember_windowsize = !resource.remember_windowsize; |
| 520 |
|
| 521 |
store_preference(&(prefs->db), "rememberWindowSize", "%s", resource.remember_windowsize ? "True" : "False"); |
| 522 |
} |
| 523 |
|
| 524 |
|
| 525 |
|
| 526 |
static Widget |
| 527 |
h_create_papersize_form(Widget parent, struct topic_info *info) |
| 528 |
{ |
| 529 |
Widget form, menu, cascade, portrait_option, landscape_option; |
| 530 |
XmString str; |
| 531 |
Arg args[8]; |
| 532 |
int n; |
| 533 |
size_t i; |
| 534 |
Boolean landscape = False; |
| 535 |
|
| 536 |
form = XmCreateForm(parent, "paper_form", NULL, 0); |
| 537 |
|
| 538 |
menu = XmCreatePulldownMenu(form, Xdvi_PAPER_MENU, NULL, 0); |
| 539 |
|
| 540 |
if (strcmp(resource.paper, "letter") != 0 && /* exceptions: these have no landscape format */ |
| 541 |
strcmp(resource.paper, "ledger") != 0 && |
| 542 |
strlen(resource.paper) > 0 && |
| 543 |
resource.paper[strlen(resource.paper) - 1] == 'r') { /* landscape format */ |
| 544 |
landscape = True; |
| 545 |
} |
| 546 |
|
| 547 |
str = XmStringCreateLocalized("Paper Size:"); |
| 548 |
|
| 549 |
n = 0; |
| 550 |
XtSetArg(args[n], XmNsubMenuId, menu); n++; |
| 551 |
XtSetArg(args[n], XmNlabelString, str); n++; |
| 552 |
XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++; |
| 553 |
XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++; |
| 554 |
XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++; |
| 555 |
|
| 556 |
cascade = XmCreateOptionMenu(form, Xdvi_PAPER_CASCADE, args, n); |
| 557 |
XmStringFree(str); |
| 558 |
|
| 559 |
portrait_option = XmCreateToggleButtonGadget(form, Xdvi_PAPER_PORTRAIT_STR, &one_of_many, 1); |
| 560 |
XmToggleButtonGadgetSetState(portrait_option, !landscape, False); |
| 561 |
XtVaSetValues(portrait_option, |
| 562 |
XmNtopAttachment, XmATTACH_FORM, |
| 563 |
XmNbottomAttachment, XmATTACH_FORM, |
| 564 |
XmNleftAttachment, XmATTACH_WIDGET, |
| 565 |
XmNleftWidget, cascade, |
| 566 |
XmNleftOffset, 10, |
| 567 |
XmNuserData, (XtPointer)info, |
| 568 |
NULL); |
| 569 |
|
| 570 |
landscape_option = XmCreateToggleButtonGadget(form, Xdvi_PAPER_LANDSCAPE_STR, &one_of_many, 1); |
| 571 |
XmToggleButtonGadgetSetState(landscape_option, landscape, False); |
| 572 |
XtVaSetValues(landscape_option, |
| 573 |
XmNtopAttachment, XmATTACH_FORM, |
| 574 |
XmNbottomAttachment, XmATTACH_FORM, |
| 575 |
XmNleftAttachment, XmATTACH_WIDGET, |
| 576 |
XmNleftWidget, portrait_option, |
| 577 |
XmNleftOffset, 10, |
| 578 |
XmNuserData, (XtPointer)info, |
| 579 |
NULL); |
| 580 |
/* adjust_heights(landscape_option, menu, cascade, NULL); */ |
| 581 |
XtAddCallback(portrait_option, XmNvalueChangedCallback, landscape_cb, (XtPointer)info); |
| 582 |
XtAddCallback(landscape_option, XmNvalueChangedCallback, landscape_cb, (XtPointer)info); |
| 583 |
/* XtAddCallback(portrait_option, XmNarmCallback, test_cb, (XtPointer)info); */ |
| 584 |
/* XtAddCallback(landscape_option, XmNarmCallback, test_cb, (XtPointer)info); */ |
| 585 |
|
| 586 |
XtManageChild(portrait_option); |
| 587 |
XtManageChild(landscape_option); |
| 588 |
|
| 589 |
for (i = 0; papersizes[i].format != NULL; i++) { |
| 590 |
Widget w = XtVaCreateManagedWidget(papersizes[i].format, xmPushButtonGadgetClass, menu, |
| 591 |
XmNuserData, landscape_option, |
| 592 |
NULL); |
| 593 |
/* fprintf(stderr, "Created button: %p for %s\n", w, papersizes[i].format); */ |
| 594 |
|
| 595 |
/* select default value */ |
| 596 |
if (strncmp(resource.paper, |
| 597 |
papersizes[i].resource_format, |
| 598 |
strlen(papersizes[i].resource_format)) == 0) { |
| 599 |
XtVaSetValues(cascade, XmNmenuHistory, w, NULL); |
| 600 |
} |
| 601 |
XtAddCallback(w, XmNactivateCallback, select_cb, (XtPointer)info); |
| 602 |
} |
| 603 |
XtManageChild(cascade); |
| 604 |
|
| 605 |
return form; |
| 606 |
} |
| 607 |
|
| 608 |
Widget |
| 609 |
prefs_paper(struct topic_info *info) |
| 610 |
{ |
| 611 |
Widget form; |
| 612 |
Widget geometry_frame, geometry_label, geometry_rowcol, shrink_frame, geometry_button; |
| 613 |
Widget paper_frame, paper_label; |
| 614 |
Arg args[10]; |
| 615 |
int n = 0; |
| 616 |
Widget rowcol; |
| 617 |
#if !defined(LESSTIF_VERSION) |
| 618 |
Widget paper_text; |
| 619 |
#endif |
| 620 |
Widget paper_size_form; |
| 621 |
|
| 622 |
form = XtVaCreateWidget("form", xmFormWidgetClass, |
| 623 |
info->right_form, |
| 624 |
XmNtopAttachment, XmATTACH_FORM, |
| 625 |
XmNleftAttachment, XmATTACH_FORM, |
| 626 |
XmNrightAttachment, XmATTACH_FORM, |
| 627 |
XmNbottomAttachment, XmATTACH_FORM, |
| 628 |
NULL); |
| 629 |
|
| 630 |
n = 0; |
| 631 |
XtSetArg(args[n], XmNmarginWidth, 8); n++; |
| 632 |
XtSetArg(args[n], XmNmarginHeight, 4); n++; |
| 633 |
geometry_frame = XmCreateFrame(form, "geometry_frame", args, n); |
| 634 |
h_attach_below(geometry_frame, NULL); |
| 635 |
|
| 636 |
geometry_label = XmCreateLabelGadget(geometry_frame, "Window Size and Shrink Factor", &frame_title, 1); |
| 637 |
XtManageChild(geometry_label); |
| 638 |
|
| 639 |
geometry_rowcol = XmCreateRowColumn(geometry_frame, "geometry_rowcol", one_col, XtNumber(one_col)); |
| 640 |
|
| 641 |
geometry_button = XmCreateToggleButtonGadget(geometry_rowcol, Xdvi_REMEMBER_WINDOWSIZE_STR, &n_of_many, 1); |
| 642 |
XmToggleButtonGadgetSetState(geometry_button, resource.remember_windowsize, False); |
| 643 |
XtAddCallback(geometry_button, XmNvalueChangedCallback, remember_windowsize_cb, (XtPointer)info); |
| 644 |
XtManageChild(geometry_button); |
| 645 |
|
| 646 |
shrink_frame = h_create_shrink_frame(geometry_rowcol, info); |
| 647 |
XtManageChild(shrink_frame); |
| 648 |
|
| 649 |
XtManageChild(geometry_rowcol); |
| 650 |
|
| 651 |
n = 0; |
| 652 |
XtSetArg(args[n], XmNmarginWidth, 8); n++; |
| 653 |
XtSetArg(args[n], XmNmarginHeight, 4); n++; |
| 654 |
XtSetArg(args[n], XmNtopOffset, 10); n++; |
| 655 |
paper_frame = XmCreateFrame(form, "paper_frame", args, n); |
| 656 |
h_attach_below(paper_frame, geometry_frame); |
| 657 |
|
| 658 |
paper_label = XmCreateLabelGadget(paper_frame, "Default Paper Size", &frame_title, 1); |
| 659 |
XtManageChild(paper_label); |
| 660 |
|
| 661 |
rowcol = XmCreateRowColumn(paper_frame, "papersize_rowcol", NULL, 0); |
| 662 |
|
| 663 |
#if !defined(LESSTIF_VERSION) /* stupid LessTif doesn't wrap Labels at '\n' */ |
| 664 |
paper_text = XmCreateLabelGadget(rowcol, |
| 665 |
"Used if the DVI file does not specify the paper size, e.g. via\n" |
| 666 |
"\\usepackage[dvips]{geometry}. This setting will only take effect\n" |
| 667 |
"after restarting xdvi.", NULL, 0); |
| 668 |
XtVaSetValues(paper_text, |
| 669 |
XmNalignment, XmALIGNMENT_BEGINNING, |
| 670 |
NULL); |
| 671 |
XtManageChild(paper_text); |
| 672 |
#endif |
| 673 |
|
| 674 |
paper_size_form = h_create_papersize_form(rowcol, info); |
| 675 |
XtManageChild(paper_size_form); |
| 676 |
|
| 677 |
XtManageChild(rowcol); |
| 678 |
|
| 679 |
XtManageChild(geometry_frame); |
| 680 |
XtManageChild(paper_frame); |
| 681 |
|
| 682 |
XtManageChild(form); |
| 683 |
|
| 684 |
return form; |
| 685 |
} |
| 686 |
|
| 687 |
#else |
| 688 |
/* silence `empty compilation unit' warnings */ |
| 689 |
static void bar(void); static void foo(void) { bar(); } static void bar(void) { foo(); } |
| 690 |
#endif /* MOTIF */ |
| 691 |
|