Bram Moolenaar | dfccaf0 | 2004-12-31 20:56:11 +0000 | [diff] [blame] | 1 | /* vi:set ts=8 sts=4 sw=4: |
| 2 | * |
| 3 | * VIM - Vi IMproved by Bram Moolenaar |
| 4 | * GUI/Motif support by Robert Webb |
| 5 | * |
| 6 | * Do ":help uganda" in Vim to read copying and usage conditions. |
| 7 | * Do ":help credits" in Vim to see a list of people who contributed. |
| 8 | * See README.txt for an overview of the Vim source code. |
| 9 | */ |
| 10 | |
| 11 | /* |
| 12 | * (C) 2001 by Marcin Dalecki <dalecki@evision.ag> |
| 13 | * |
| 14 | * Implementation of dialogue functions for the Motif GUI variant. |
| 15 | */ |
| 16 | |
| 17 | #include <Xm/Form.h> |
| 18 | #include <Xm/PushBG.h> |
| 19 | #include <Xm/Text.h> |
| 20 | #include <Xm/TextF.h> |
| 21 | #include <Xm/Label.h> |
| 22 | #include <Xm/Frame.h> |
| 23 | #include <Xm/LabelG.h> |
| 24 | #include <Xm/ToggleBG.h> |
| 25 | #include <Xm/SeparatoG.h> |
| 26 | #include <Xm/DialogS.h> |
| 27 | #include <Xm/List.h> |
| 28 | #include <Xm/RowColumn.h> |
| 29 | #include <Xm/AtomMgr.h> |
| 30 | #include <Xm/Protocols.h> |
| 31 | |
| 32 | #include <X11/keysym.h> |
| 33 | #include <X11/Xatom.h> |
| 34 | #include <X11/StringDefs.h> |
| 35 | #include <X11/Intrinsic.h> |
| 36 | |
| 37 | #include "vim.h" |
| 38 | |
| 39 | extern Widget vimShell; |
| 40 | |
| 41 | #ifdef FEAT_MENU |
| 42 | # define apply_fontlist(w) gui_motif_menu_fontlist(w) |
| 43 | #else |
| 44 | # define apply_fontlist(w) |
| 45 | #endif |
| 46 | |
| 47 | /**************************************************************************** |
| 48 | * Font selection dialogue implementation. |
| 49 | */ |
| 50 | |
| 51 | static char wild[3] = "*"; |
| 52 | |
| 53 | /* |
| 54 | * FIXME: This is a generic function, which should be used throughout the whole |
| 55 | * application. |
| 56 | * |
| 57 | * Add close_callback, which will be called when the user selects close from |
| 58 | * the window menu. The close menu item usually activates f.kill which sends a |
| 59 | * WM_DELETE_WINDOW protocol request for the window. |
| 60 | */ |
| 61 | |
| 62 | static void |
| 63 | add_cancel_action(Widget shell, XtCallbackProc close_callback, void *arg) |
| 64 | { |
| 65 | static Atom wmp_atom = 0; |
| 66 | static Atom dw_atom = 0; |
| 67 | Display *display = XtDisplay(shell); |
| 68 | |
| 69 | /* deactivate the built-in delete response of killing the application */ |
| 70 | XtVaSetValues(shell, XmNdeleteResponse, XmDO_NOTHING, 0); |
| 71 | |
| 72 | /* add a delete window protocol callback instead */ |
| 73 | if (!dw_atom) |
| 74 | { |
| 75 | wmp_atom = XmInternAtom(display, "WM_PROTOCOLS", True); |
| 76 | dw_atom = XmInternAtom(display, "WM_DELETE_WINDOW", True); |
| 77 | } |
| 78 | XmAddProtocolCallback(shell, wmp_atom, dw_atom, close_callback, arg); |
| 79 | } |
| 80 | |
| 81 | #define MAX_FONTS 65535 |
| 82 | #define MAX_FONT_NAME_LEN 256 |
| 83 | #define MAX_ENTRIES_IN_LIST 5000 |
| 84 | #define MAX_DISPLAY_SIZE 150 |
| 85 | #define TEMP_BUF_SIZE 256 |
| 86 | |
| 87 | enum ListSpecifier |
| 88 | { |
| 89 | ENCODING, |
| 90 | NAME, |
| 91 | STYLE, |
| 92 | SIZE, |
| 93 | NONE |
| 94 | }; |
| 95 | |
| 96 | typedef struct _SharedFontSelData |
| 97 | { |
| 98 | Widget dialog; |
| 99 | Widget ok; |
| 100 | Widget cancel; |
| 101 | Widget encoding_pulldown; |
| 102 | Widget encoding_menu; |
| 103 | Widget list[NONE]; |
| 104 | Widget name; |
| 105 | Widget sample; |
| 106 | char **names; /* font name array of arrays */ |
| 107 | int num; /* number of font names */ |
| 108 | String sel[NONE]; /* selection category */ |
| 109 | Boolean in_pixels; /* toggle state - size in pixels */ |
| 110 | char *font_name; /* current font name */ |
| 111 | XFontStruct *old; /* font data structure for sample display */ |
| 112 | XmFontList old_list; /* font data structure for sample display */ |
| 113 | Boolean exit; /* used for program exit control */ |
| 114 | } SharedFontSelData; |
| 115 | |
| 116 | /* |
| 117 | * Checking access to the font name array for validity. |
| 118 | */ |
| 119 | static char * |
| 120 | fn(SharedFontSelData *data, int i) |
| 121 | { |
| 122 | /* Assertion checks: */ |
| 123 | if (data->num < 0) |
| 124 | abort(); |
| 125 | if (i >= data->num) |
| 126 | i = data->num - 1; |
| 127 | if (i < 0) |
| 128 | i = 0; |
| 129 | |
| 130 | return data->names[i]; |
| 131 | } |
| 132 | |
| 133 | /* |
| 134 | * Get a specific substring from a font name. |
| 135 | */ |
| 136 | static void |
| 137 | get_part(char *in, int pos, char *out) |
| 138 | { |
| 139 | int i; |
| 140 | int j; |
| 141 | |
| 142 | *out = '\0'; |
| 143 | |
| 144 | for (i = 0; (pos > 0) && (in[i] != '\0'); ++i) |
| 145 | if (in[i] == '-') |
| 146 | pos--; |
| 147 | |
| 148 | if (in[i] == '\0') |
| 149 | return; |
| 150 | |
| 151 | for (j = 0; (in[i] != '-') && (in[i] != '\0'); ++i, ++j) |
| 152 | out[j] = in[i]; |
| 153 | out[j] = '\0'; |
| 154 | } |
| 155 | |
| 156 | /* |
| 157 | * Given a font name this function returns the part used in the first |
| 158 | * scroll list. |
| 159 | */ |
| 160 | static void |
| 161 | name_part(char *font, char *buf) |
| 162 | { |
| 163 | char buf2[TEMP_BUF_SIZE]; |
| 164 | char buf3[TEMP_BUF_SIZE]; |
| 165 | |
| 166 | get_part(font, 2, buf2); |
| 167 | get_part(font, 1, buf3); |
| 168 | |
| 169 | if (strlen(buf3)) |
| 170 | sprintf(buf, "%s (%s)", buf2, buf3); |
| 171 | else |
| 172 | sprintf(buf, "%s", buf2); |
| 173 | } |
| 174 | |
| 175 | /* |
| 176 | * Given a font name this function returns the part used in the second scroll list. |
| 177 | */ |
| 178 | static void |
| 179 | style_part(char *font, char *buf) |
| 180 | { |
| 181 | char buf2[TEMP_BUF_SIZE]; |
| 182 | char buf3[TEMP_BUF_SIZE]; |
| 183 | |
| 184 | get_part(font, 3, buf3); |
| 185 | get_part(font, 5, buf2); |
| 186 | |
| 187 | if (!strcmp(buf2, "normal") && !strcmp(buf2, "Normal") |
| 188 | && !strcmp(buf2, "NORMAL")) |
| 189 | sprintf(buf, "%s %s", buf3, buf2); |
| 190 | else |
| 191 | strcpy(buf, buf3); |
| 192 | |
| 193 | get_part(font, 6, buf2); |
| 194 | |
| 195 | if (buf2[0] != '\0') |
| 196 | sprintf(buf3, "%s %s", buf, buf2); |
| 197 | else |
| 198 | strcpy(buf3, buf); |
| 199 | |
| 200 | get_part(font, 4, buf2); |
| 201 | |
| 202 | if (!strcmp(buf2, "o") || !strcmp(buf2, "O")) |
| 203 | sprintf(buf, "%s oblique", buf3); |
| 204 | else if (!strcmp(buf2, "i") || !strcmp(buf2, "I")) |
| 205 | sprintf(buf, "%s italic", buf3); |
| 206 | |
| 207 | if (!strcmp(buf, " ")) |
| 208 | strcpy(buf, "-"); |
| 209 | } |
| 210 | |
| 211 | /* |
| 212 | * Given a font name this function returns the part used in the third |
| 213 | * scroll list. |
| 214 | */ |
| 215 | static void |
| 216 | size_part(char *font, char *buf, int inPixels) |
| 217 | { |
| 218 | int size; |
| 219 | float temp; |
| 220 | |
| 221 | *buf = '\0'; |
| 222 | |
| 223 | if (inPixels) |
| 224 | { |
| 225 | get_part(font, 7, buf); |
| 226 | if (strlen(buf) > 0) |
| 227 | { |
| 228 | size = atoi(buf); |
| 229 | sprintf(buf, "%3d", size); |
| 230 | } |
| 231 | } |
| 232 | else |
| 233 | { |
| 234 | get_part(font, 8, buf); |
| 235 | if (strlen(buf) > 0) |
| 236 | { |
| 237 | size = atoi(buf); |
| 238 | temp = (float)size / 10.0; |
| 239 | size = temp; |
| 240 | if (buf[strlen(buf) - 1] == '0') |
| 241 | sprintf(buf, "%3d", size); |
| 242 | else |
| 243 | sprintf(buf, "%4.1f", temp); |
| 244 | } |
| 245 | } |
| 246 | } |
| 247 | |
| 248 | /* |
| 249 | * Given a font name this function returns the part used in the choice menu. |
| 250 | */ |
| 251 | static void |
| 252 | encoding_part(char *font, char *buf) |
| 253 | { |
| 254 | char buf1[TEMP_BUF_SIZE]; |
| 255 | char buf2[TEMP_BUF_SIZE]; |
| 256 | |
| 257 | *buf = '\0'; |
| 258 | |
| 259 | get_part(font, 13, buf1); |
| 260 | get_part(font, 14, buf2); |
| 261 | |
| 262 | if (strlen(buf1) > 0 && strlen(buf2)) |
| 263 | sprintf(buf, "%s-%s", buf1, buf2); |
| 264 | if (!strcmp(buf, " ")) |
| 265 | strcpy(buf, "-"); |
| 266 | } |
| 267 | |
| 268 | /* |
| 269 | * Inserts a string into correct sorted position in a list. |
| 270 | */ |
| 271 | static void |
| 272 | add_to_list(char **buf, char *item, int *count) |
| 273 | { |
| 274 | int i; |
| 275 | int j; |
| 276 | |
| 277 | if (*count == MAX_ENTRIES_IN_LIST) |
| 278 | return; |
| 279 | |
| 280 | /* avoid duplication */ |
| 281 | for (i = 0; i < *count; ++i) |
| 282 | { |
| 283 | if (!strcmp(buf[i], item)) |
| 284 | return; |
| 285 | } |
| 286 | |
| 287 | /* find order place, but make sure that wild card comes first */ |
| 288 | if (!strcmp(item, wild)) |
| 289 | i = 0; |
| 290 | else |
| 291 | for (i = 0; i < *count; ++i) |
| 292 | if (strcmp(buf[i], item) > 0 && strcmp(buf[i], wild)) |
| 293 | break; |
| 294 | |
| 295 | /* now insert the item */ |
| 296 | for (j = *count; j > i; --j) |
| 297 | buf[j] = buf[j-1]; |
| 298 | buf[i] = XtNewString(item); |
| 299 | |
| 300 | ++(*count); |
| 301 | } |
| 302 | |
| 303 | /* |
| 304 | * True if the font matches some field. |
| 305 | */ |
| 306 | static Boolean |
| 307 | match(SharedFontSelData *data, enum ListSpecifier l, int i) |
| 308 | { |
| 309 | char buf[TEMP_BUF_SIZE]; |
| 310 | |
| 311 | /* An empty selection or a wild card matches anything. |
| 312 | */ |
| 313 | if (!data->sel[l] || !strcmp(data->sel[l], wild)) |
| 314 | return True; |
| 315 | |
| 316 | /* chunk out the desired part... */ |
| 317 | switch (l) |
| 318 | { |
| 319 | case ENCODING: |
| 320 | encoding_part(fn(data, i), buf); |
| 321 | break; |
| 322 | |
| 323 | case NAME: |
| 324 | name_part(fn(data, i), buf); |
| 325 | break; |
| 326 | |
| 327 | case STYLE: |
| 328 | style_part(fn(data, i), buf); |
| 329 | break; |
| 330 | |
| 331 | case SIZE: |
| 332 | size_part(fn(data, i), buf, data->in_pixels); |
| 333 | break; |
| 334 | default: |
| 335 | ; |
| 336 | } |
| 337 | |
| 338 | /* ...and chew it now */ |
| 339 | |
| 340 | return !strcmp(buf, data->sel[l]); |
| 341 | } |
| 342 | |
| 343 | static Boolean |
| 344 | proportional(char *font) |
| 345 | { |
| 346 | char buf[TEMP_BUF_SIZE]; |
| 347 | |
| 348 | get_part(font, 11, buf); |
| 349 | |
| 350 | return !strcmp(buf, "p") || !strcmp(buf, "P"); |
| 351 | } |
| 352 | |
| 353 | |
| 354 | static void encoding_callback(Widget w, SharedFontSelData *data, |
| 355 | XtPointer dummy); |
| 356 | |
| 357 | /* |
| 358 | * Parse through the fontlist data and set up the three scroll lists. The fix |
| 359 | * parameter can be used to exclude a list from any changes. This is used for |
| 360 | * updates after selections caused by the users actions. |
| 361 | */ |
| 362 | static void |
| 363 | fill_lists(enum ListSpecifier fix, SharedFontSelData *data) |
| 364 | { |
| 365 | char *list[NONE][MAX_ENTRIES_IN_LIST]; |
| 366 | int count[NONE]; |
| 367 | char buf[TEMP_BUF_SIZE]; |
| 368 | XmString items[MAX_ENTRIES_IN_LIST]; |
| 369 | int i; |
| 370 | int index; |
| 371 | |
| 372 | for (index = (int)ENCODING; index < (int)NONE; ++index) |
| 373 | count[index] = 0; |
| 374 | |
| 375 | /* First we insert the wild char into every single list. */ |
| 376 | if (fix != ENCODING) |
| 377 | add_to_list(list[ENCODING], wild, &count[ENCODING]); |
| 378 | if (fix != NAME) |
| 379 | add_to_list(list[NAME], wild, &count[NAME]); |
| 380 | if (fix != STYLE) |
| 381 | add_to_list(list[STYLE], wild, &count[STYLE]); |
| 382 | if (fix != SIZE) |
| 383 | add_to_list(list[SIZE], wild, &count[SIZE]); |
| 384 | |
| 385 | for (i = 0; i < data->num && i < MAX_ENTRIES_IN_LIST; i++) |
| 386 | { |
| 387 | if (proportional(fn(data, i))) |
| 388 | continue; |
| 389 | |
| 390 | if (fix != ENCODING |
| 391 | && match(data, NAME, i) |
| 392 | && match(data, STYLE, i) |
| 393 | && match(data, SIZE, i)) |
| 394 | { |
| 395 | encoding_part(fn(data, i), buf); |
| 396 | add_to_list(list[ENCODING], buf, &count[ENCODING]); |
| 397 | } |
| 398 | |
| 399 | if (fix != NAME |
| 400 | && match(data, ENCODING, i) |
| 401 | && match(data, STYLE, i) |
| 402 | && match(data, SIZE, i)) |
| 403 | { |
| 404 | name_part(fn(data, i), buf); |
| 405 | add_to_list(list[NAME], buf, &count[NAME]); |
| 406 | } |
| 407 | |
| 408 | if (fix != STYLE |
| 409 | && match(data, ENCODING, i) |
| 410 | && match(data, NAME, i) |
| 411 | && match(data, SIZE, i)) |
| 412 | { |
| 413 | style_part(fn(data, i), buf); |
| 414 | add_to_list(list[STYLE], buf, &count[STYLE]); |
| 415 | } |
| 416 | |
| 417 | if (fix != SIZE |
| 418 | && match(data, ENCODING, i) |
| 419 | && match(data, NAME, i) |
| 420 | && match(data, STYLE, i)) |
| 421 | { |
| 422 | size_part(fn(data, i), buf, data->in_pixels); |
| 423 | add_to_list(list[SIZE], buf, &count[SIZE]); |
| 424 | } |
| 425 | } |
| 426 | |
| 427 | /* |
| 428 | * And now do the preselection in all lists where there was one: |
| 429 | */ |
| 430 | |
| 431 | if (fix != ENCODING) |
| 432 | { |
| 433 | Cardinal n_items; |
| 434 | WidgetList children; |
| 435 | Widget selected_button = 0; |
| 436 | |
| 437 | /* Get and update the current button list. */ |
| 438 | XtVaGetValues(data->encoding_pulldown, |
| 439 | XmNchildren, &children, |
| 440 | XmNnumChildren, &n_items, |
| 441 | NULL); |
| 442 | |
| 443 | for (i = 0; i < count[ENCODING]; ++i) |
| 444 | { |
| 445 | Widget button; |
| 446 | |
| 447 | items[i] = XmStringCreateLocalized(list[ENCODING][i]); |
| 448 | |
| 449 | if (i < n_items) |
| 450 | { |
| 451 | /* recycle old button */ |
| 452 | XtVaSetValues(children[i], |
| 453 | XmNlabelString, items[i], |
| 454 | XmNuserData, i, |
| 455 | NULL); |
| 456 | button = children[i]; |
| 457 | } |
| 458 | else |
| 459 | { |
| 460 | /* create a new button */ |
| 461 | button = XtVaCreateManagedWidget("button", |
| 462 | xmPushButtonGadgetClass, |
| 463 | data->encoding_pulldown, |
| 464 | XmNlabelString, items[i], |
| 465 | XmNuserData, i, |
| 466 | NULL); |
| 467 | XtAddCallback(button, XmNactivateCallback, |
| 468 | (XtCallbackProc) encoding_callback, (XtPointer) data); |
| 469 | XtManageChild(button); |
| 470 | } |
| 471 | |
| 472 | if (data->sel[ENCODING]) |
| 473 | { |
| 474 | if (!strcmp(data->sel[ENCODING], list[ENCODING][i])) |
| 475 | selected_button = button; |
| 476 | } |
| 477 | XtFree(list[ENCODING][i]); |
| 478 | } |
| 479 | |
| 480 | /* Destroy all the outstandig menu items. |
| 481 | */ |
| 482 | for (i = count[ENCODING]; i < n_items; ++i) |
| 483 | { |
| 484 | XtUnmanageChild(children[i]); |
| 485 | XtDestroyWidget(children[i]); |
| 486 | } |
| 487 | |
| 488 | /* Preserve the current selection visually. |
| 489 | */ |
| 490 | if (selected_button) |
| 491 | { |
| 492 | XtVaSetValues(data->encoding_menu, |
| 493 | XmNmenuHistory, selected_button, |
| 494 | NULL); |
| 495 | } |
| 496 | |
| 497 | for (i = 0; i < count[ENCODING]; ++i) |
| 498 | XmStringFree(items[i]); |
| 499 | } |
| 500 | |
| 501 | /* |
| 502 | * Now loop trough the remaining lists and set them up. |
| 503 | */ |
| 504 | for (index = (int)NAME; index < (int)NONE; ++index) |
| 505 | { |
| 506 | Widget w; |
| 507 | |
| 508 | if (fix == (enum ListSpecifier)index) |
| 509 | continue; |
| 510 | |
| 511 | switch ((enum ListSpecifier)index) |
| 512 | { |
| 513 | case NAME: |
| 514 | w = data->list[NAME]; |
| 515 | break; |
| 516 | case STYLE: |
| 517 | w = data->list[STYLE]; |
| 518 | break; |
| 519 | case SIZE: |
| 520 | w = data->list[SIZE]; |
| 521 | break; |
| 522 | default: |
| 523 | w = (Widget)0; /* for lint */ |
| 524 | } |
| 525 | |
| 526 | for (i = 0; i < count[index]; ++i) |
| 527 | { |
| 528 | items[i] = XmStringCreateLocalized(list[index][i]); |
| 529 | XtFree(list[index][i]); |
| 530 | } |
| 531 | XmListDeleteAllItems(w); |
| 532 | XmListAddItems(w, items, count[index], 1); |
| 533 | if (data->sel[index]) |
| 534 | { |
| 535 | XmStringFree(items[0]); |
| 536 | items[0] = XmStringCreateLocalized(data->sel[index]); |
| 537 | XmListSelectItem(w, items[0], False); |
| 538 | XmListSetBottomItem(w, items[0]); |
| 539 | } |
| 540 | for (i = 0; i < count[index]; ++i) |
| 541 | XmStringFree(items[i]); |
| 542 | } |
| 543 | } |
| 544 | |
| 545 | /*ARGSUSED*/ |
| 546 | static void |
| 547 | stoggle_callback(Widget w, |
| 548 | SharedFontSelData *data, |
| 549 | XmToggleButtonCallbackStruct *call_data) |
| 550 | { |
| 551 | int i, do_sel; |
| 552 | char newSize[10]; |
| 553 | XmString str; |
| 554 | |
| 555 | if (call_data->reason != (int)XmCR_VALUE_CHANGED) |
| 556 | return; |
| 557 | |
| 558 | do_sel = (data->sel[SIZE] != NULL) && strcmp(data->sel[SIZE], wild); |
| 559 | |
| 560 | for (i = 0; do_sel && (i < data->num); i++) |
| 561 | if (match(data, ENCODING, i) |
| 562 | && match(data, NAME, i) |
| 563 | && match(data, STYLE, i) |
| 564 | && match(data, SIZE, i)) |
| 565 | { |
| 566 | size_part(fn(data, i), newSize, !data->in_pixels); |
| 567 | break; |
| 568 | } |
| 569 | |
| 570 | data->in_pixels = !data->in_pixels; |
| 571 | |
| 572 | if (data->sel[SIZE]) |
| 573 | XtFree(data->sel[SIZE]); |
| 574 | data->sel[SIZE] = NULL; |
| 575 | fill_lists(NONE, data); |
| 576 | |
| 577 | if (do_sel) |
| 578 | { |
| 579 | str = XmStringCreateLocalized(newSize); |
| 580 | XmListSelectItem(data->list[SIZE], str, True); |
| 581 | XmListSetBottomItem(data->list[SIZE], str); |
| 582 | XmStringFree(str); |
| 583 | } |
| 584 | } |
| 585 | |
| 586 | /* |
| 587 | * Show the currently selected font in the sample text label. |
| 588 | */ |
| 589 | static void |
| 590 | display_sample(SharedFontSelData *data) |
| 591 | { |
| 592 | Arg args[2]; |
| 593 | int n; |
| 594 | XFontStruct * font; |
| 595 | XmFontList font_list; |
| 596 | Display * display; |
| 597 | XmString str; |
| 598 | |
| 599 | display = XtDisplay(data->dialog); |
| 600 | font = XLoadQueryFont(display, data->font_name); |
| 601 | font_list = gui_motif_create_fontlist(font); |
| 602 | |
| 603 | n = 0; |
| 604 | str = XmStringCreateLocalized("AaBbZzYy 0123456789"); |
| 605 | XtSetArg(args[n], XmNlabelString, str); n++; |
| 606 | XtSetArg(args[n], XmNfontList, font_list); n++; |
| 607 | |
| 608 | XtSetValues(data->sample, args, n); |
| 609 | XmStringFree(str); |
| 610 | |
| 611 | if (data->old) |
| 612 | { |
| 613 | XFreeFont(display, data->old); |
| 614 | XmFontListFree(data->old_list); |
| 615 | } |
| 616 | data->old = font; |
| 617 | data->old_list = font_list; |
| 618 | } |
| 619 | |
| 620 | |
| 621 | static Boolean |
| 622 | do_choice(Widget w, |
| 623 | SharedFontSelData *data, |
| 624 | XmListCallbackStruct *call_data, |
| 625 | enum ListSpecifier which) |
| 626 | { |
| 627 | char *sel; |
| 628 | |
| 629 | XmStringGetLtoR(call_data->item, XmSTRING_DEFAULT_CHARSET, &sel); |
| 630 | |
| 631 | if (!data->sel[which]) |
| 632 | data->sel[which] = XtNewString(sel); |
| 633 | else |
| 634 | { |
| 635 | XtFree(data->sel[which]); |
| 636 | if (!strcmp(data->sel[which], sel)) |
| 637 | { |
| 638 | /* unselecting current selection */ |
| 639 | data->sel[which] = NULL; |
| 640 | if (w) |
| 641 | XmListDeselectItem(w, call_data->item); |
| 642 | } |
| 643 | else |
| 644 | data->sel[which] = XtNewString(sel); |
| 645 | } |
| 646 | XtFree(sel); |
| 647 | |
| 648 | fill_lists(which, data); |
| 649 | |
| 650 | /* If there is a font selection, we display it. */ |
| 651 | if (data->sel[ENCODING] |
| 652 | && data->sel[NAME] |
| 653 | && data->sel[STYLE] |
| 654 | && data->sel[SIZE] |
| 655 | && strcmp(data->sel[ENCODING], wild) |
| 656 | && strcmp(data->sel[NAME], wild) |
| 657 | && strcmp(data->sel[STYLE], wild) |
| 658 | && strcmp(data->sel[SIZE], wild)) |
| 659 | { |
| 660 | int i; |
| 661 | |
| 662 | if (data->font_name) |
| 663 | XtFree(data->font_name); |
| 664 | data->font_name = NULL; |
| 665 | |
| 666 | for (i = 0; i < data->num; i++) |
| 667 | { |
| 668 | if (match(data, ENCODING, i) |
| 669 | && match(data, NAME, i) |
| 670 | && match(data, STYLE, i) |
| 671 | && match(data, SIZE, i)) |
| 672 | { |
| 673 | data->font_name = XtNewString(fn(data, i)); |
| 674 | break; |
| 675 | } |
| 676 | } |
| 677 | |
| 678 | if (data->font_name) |
| 679 | { |
| 680 | XmTextSetString(data->name, data->font_name); |
| 681 | display_sample(data); |
| 682 | } |
| 683 | else |
| 684 | do_dialog(VIM_ERROR, |
| 685 | (char_u *)_("Error"), |
| 686 | (char_u *)_("Invalid font specification"), |
| 687 | (char_u *)_("&Dismiss"), 1, NULL); |
| 688 | |
| 689 | return True; |
| 690 | } |
| 691 | else |
| 692 | { |
| 693 | int n; |
| 694 | XmString str; |
| 695 | Arg args[4]; |
| 696 | char *msg = _("no specific match"); |
| 697 | |
| 698 | n = 0; |
| 699 | str = XmStringCreateLocalized(msg); |
| 700 | XtSetArg(args[n], XmNlabelString, str); ++n; |
| 701 | XtSetValues(data->sample, args, n); |
| 702 | apply_fontlist(data->sample); |
| 703 | XmTextSetString(data->name, msg); |
| 704 | XmStringFree(str); |
| 705 | |
| 706 | return False; |
| 707 | } |
| 708 | } |
| 709 | |
| 710 | /*ARGSUSED*/ |
| 711 | static void |
| 712 | encoding_callback(Widget w, |
| 713 | SharedFontSelData *data, |
| 714 | XtPointer dummy) |
| 715 | { |
| 716 | XmString str; |
| 717 | XmListCallbackStruct fake_data; |
| 718 | |
| 719 | XtVaGetValues(w, XmNlabelString, &str, NULL); |
| 720 | |
| 721 | if (!str) |
| 722 | return; |
| 723 | |
| 724 | fake_data.item = str; |
| 725 | |
| 726 | do_choice(0, data, &fake_data, ENCODING); |
| 727 | } |
| 728 | |
| 729 | static void |
| 730 | name_callback(Widget w, |
| 731 | SharedFontSelData *data, |
| 732 | XmListCallbackStruct *call_data) |
| 733 | { |
| 734 | do_choice(w, data, call_data, NAME); |
| 735 | } |
| 736 | |
| 737 | static void |
| 738 | style_callback(Widget w, |
| 739 | SharedFontSelData *data, |
| 740 | XmListCallbackStruct *call_data) |
| 741 | { |
| 742 | do_choice(w, data, call_data, STYLE); |
| 743 | } |
| 744 | |
| 745 | static void |
| 746 | size_callback(Widget w, |
| 747 | SharedFontSelData *data, |
| 748 | XmListCallbackStruct *call_data) |
| 749 | { |
| 750 | do_choice(w, data, call_data, SIZE); |
| 751 | } |
| 752 | |
| 753 | /*ARGSUSED*/ |
| 754 | static void |
| 755 | cancel_callback(Widget w, |
| 756 | SharedFontSelData *data, |
| 757 | XmListCallbackStruct *call_data) |
| 758 | { |
| 759 | if (data->sel[ENCODING]) |
| 760 | { |
| 761 | XtFree(data->sel[ENCODING]); |
| 762 | data->sel[ENCODING] = NULL; |
| 763 | } |
| 764 | if (data->sel[NAME]) |
| 765 | { |
| 766 | XtFree(data->sel[NAME]); |
| 767 | data->sel[NAME] = NULL; |
| 768 | } |
| 769 | if (data->sel[STYLE]) |
| 770 | { |
| 771 | XtFree(data->sel[STYLE]); |
| 772 | data->sel[STYLE] = NULL; |
| 773 | } |
| 774 | if (data->sel[SIZE]) |
| 775 | { |
| 776 | XtFree(data->sel[SIZE]); |
| 777 | data->sel[SIZE] = NULL; |
| 778 | } |
| 779 | |
| 780 | if (data->font_name) |
| 781 | XtFree(data->font_name); |
| 782 | data->font_name = NULL; |
| 783 | |
| 784 | data->num = 0; |
| 785 | XFreeFontNames(data->names); |
| 786 | data->names = NULL; |
| 787 | data->exit = True; |
| 788 | } |
| 789 | |
| 790 | /*ARGSUSED*/ |
| 791 | static void |
| 792 | ok_callback(Widget w, |
| 793 | SharedFontSelData *data, |
| 794 | XmPushButtonCallbackStruct *call_data) |
| 795 | { |
| 796 | char *pattern; |
| 797 | char **name; |
| 798 | int i; |
| 799 | |
| 800 | pattern = XmTextGetString(data->name); |
| 801 | name = XListFonts(XtDisplay(data->dialog), pattern, 1, &i); |
| 802 | XtFree(pattern); |
| 803 | |
| 804 | if (i != 1) |
| 805 | { |
| 806 | do_dialog(VIM_ERROR, |
| 807 | (char_u *)_("Error"), |
| 808 | (char_u *)_("Invalid font specification"), |
| 809 | (char_u *)_("&Dismiss"), 1, NULL); |
| 810 | XFreeFontNames(name); |
| 811 | } |
| 812 | else |
| 813 | { |
| 814 | if (data->font_name) |
| 815 | XtFree(data->font_name); |
| 816 | data->font_name = XtNewString(name[0]); |
| 817 | |
| 818 | if (data->sel[ENCODING]) |
| 819 | { |
| 820 | XtFree(data->sel[ENCODING]); |
| 821 | data->sel[ENCODING] = NULL; |
| 822 | } |
| 823 | if (data->sel[NAME]) |
| 824 | { |
| 825 | XtFree(data->sel[NAME]); |
| 826 | data->sel[NAME] = NULL; |
| 827 | } |
| 828 | if (data->sel[STYLE]) |
| 829 | { |
| 830 | XtFree(data->sel[STYLE]); |
| 831 | data->sel[STYLE] = NULL; |
| 832 | } |
| 833 | if (data->sel[SIZE]) |
| 834 | { |
| 835 | XtFree(data->sel[SIZE]); |
| 836 | data->sel[SIZE] = NULL; |
| 837 | } |
| 838 | |
| 839 | XFreeFontNames(name); |
| 840 | |
| 841 | data->num = 0; |
| 842 | XFreeFontNames(data->names); |
| 843 | data->names = NULL; |
| 844 | data->exit = True; |
| 845 | } |
| 846 | } |
| 847 | |
| 848 | /* |
| 849 | * Returns pointer to an ASCII character string that contains the name of the |
| 850 | * selected font (in X format for naming fonts); it is the users responsibility |
| 851 | * to free the space allocated to this string. |
| 852 | */ |
| 853 | char_u * |
| 854 | gui_xm_select_font(char_u *current) |
| 855 | { |
| 856 | static SharedFontSelData _data; |
| 857 | |
| 858 | Widget parent; |
| 859 | Widget form; |
| 860 | Widget separator; |
| 861 | Widget sub_form; |
| 862 | Widget size_toggle; |
| 863 | Widget name; |
| 864 | Widget disp_frame; |
| 865 | Widget frame; |
| 866 | Arg args[64]; |
| 867 | int n; |
| 868 | XmString str; |
| 869 | char big_font[MAX_FONT_NAME_LEN]; |
| 870 | SharedFontSelData *data; |
| 871 | |
| 872 | data = &_data; |
| 873 | |
| 874 | parent = vimShell; |
| 875 | data->names = XListFonts(XtDisplay(parent), "-*-*-*-*-*-*-*-*-*-*-*-*-*-*", |
| 876 | MAX_FONTS, &data->num); |
| 877 | |
| 878 | /* |
| 879 | * Find the name of the biggest font less than the given limit |
| 880 | * MAX_DISPLAY_SIZE used to set up the initial height of the display |
| 881 | * widget. |
| 882 | */ |
| 883 | |
| 884 | { |
| 885 | int i; |
| 886 | int max; |
| 887 | int index = 0; |
| 888 | int size; |
| 889 | char str[128]; |
| 890 | |
| 891 | for (i = 0, max = 0; i < data->num; i++) |
| 892 | { |
| 893 | get_part(fn(data, i), 7, str); |
| 894 | size = atoi(str); |
| 895 | if ((size > max) && (size < MAX_DISPLAY_SIZE)) |
| 896 | { |
| 897 | index = i; |
| 898 | max = size; |
| 899 | } |
| 900 | } |
| 901 | strcpy(big_font, fn(data, index)); |
| 902 | } |
| 903 | data->old = XLoadQueryFont(XtDisplay(parent), big_font); |
| 904 | data->old_list = gui_motif_create_fontlist(data->old); |
| 905 | |
| 906 | /* Set the title of the Dialog window. */ |
| 907 | data->dialog = XmCreateDialogShell(parent, "fontSelector", NULL, 0); |
| 908 | str = XmStringCreateLocalized(_("Vim - Font Selector")); |
| 909 | |
| 910 | /* Create form popup dialog widget. */ |
| 911 | form = XtVaCreateWidget("form", |
| 912 | xmFormWidgetClass, data->dialog, |
| 913 | XmNdialogTitle, str, |
| 914 | XmNautoUnmanage, False, |
| 915 | XmNdialogStyle, XmDIALOG_FULL_APPLICATION_MODAL, |
| 916 | NULL); |
| 917 | XmStringFree(str); |
| 918 | |
| 919 | sub_form = XtVaCreateManagedWidget("subForm", |
| 920 | xmFormWidgetClass, form, |
| 921 | XmNbottomAttachment, XmATTACH_FORM, |
| 922 | XmNbottomOffset, 4, |
| 923 | XmNrightAttachment, XmATTACH_FORM, |
| 924 | XmNrightOffset, 4, |
| 925 | XmNtopAttachment, XmATTACH_FORM, |
| 926 | XmNtopOffset, 4, |
| 927 | XmNorientation, XmVERTICAL, |
| 928 | NULL); |
| 929 | |
| 930 | data->ok = XtVaCreateManagedWidget(_("OK"), |
| 931 | xmPushButtonGadgetClass, sub_form, |
| 932 | XmNleftAttachment, XmATTACH_FORM, |
| 933 | XmNrightAttachment, XmATTACH_FORM, |
| 934 | XmNtopAttachment, XmATTACH_FORM, |
| 935 | XmNtopOffset, 4, |
| 936 | NULL); |
| 937 | apply_fontlist(data->ok); |
| 938 | |
| 939 | data->cancel = XtVaCreateManagedWidget(_("Cancel"), |
| 940 | xmPushButtonGadgetClass, sub_form, |
| 941 | XmNrightAttachment, XmATTACH_FORM, |
| 942 | XmNleftAttachment, XmATTACH_FORM, |
| 943 | XmNtopAttachment, XmATTACH_WIDGET, |
| 944 | XmNtopWidget, data->ok, |
| 945 | XmNtopOffset, 4, |
| 946 | XmNshowAsDefault, True, |
| 947 | NULL); |
| 948 | apply_fontlist(data->cancel); |
| 949 | |
| 950 | /* Create the separator for beauty. */ |
| 951 | n = 0; |
| 952 | XtSetArg(args[n], XmNorientation, XmVERTICAL); n++; |
| 953 | XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++; |
| 954 | XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++; |
| 955 | XtSetArg(args[n], XmNrightAttachment, XmATTACH_WIDGET); n++; |
| 956 | XtSetArg(args[n], XmNrightWidget, sub_form); n++; |
| 957 | XtSetArg(args[n], XmNrightOffset, 4); n++; |
| 958 | separator = XmCreateSeparatorGadget(form, "separator", args, n); |
| 959 | XtManageChild(separator); |
| 960 | |
| 961 | /* Create font name text widget and the corresponding label. */ |
| 962 | data->name = XtVaCreateManagedWidget("fontName", |
| 963 | xmTextWidgetClass, form, |
| 964 | XmNbottomAttachment, XmATTACH_FORM, |
| 965 | XmNbottomOffset, 4, |
| 966 | XmNleftAttachment, XmATTACH_FORM, |
| 967 | XmNleftOffset, 4, |
| 968 | XmNrightAttachment, XmATTACH_WIDGET, |
| 969 | XmNrightWidget, separator, |
| 970 | XmNrightOffset, 4, |
| 971 | XmNeditable, False, |
| 972 | XmNeditMode, XmSINGLE_LINE_EDIT, |
| 973 | XmNmaxLength, MAX_FONT_NAME_LEN, |
| 974 | XmNcolumns, 60, |
| 975 | NULL); |
| 976 | |
| 977 | str = XmStringCreateLocalized(_("Name:")); |
| 978 | name = XtVaCreateManagedWidget("fontNameLabel", |
| 979 | xmLabelGadgetClass, form, |
| 980 | XmNlabelString, str, |
| 981 | XmNuserData, data->name, |
| 982 | XmNleftAttachment, XmATTACH_OPPOSITE_WIDGET, |
| 983 | XmNleftWidget, data->name, |
| 984 | XmNbottomAttachment, XmATTACH_WIDGET, |
| 985 | XmNbottomWidget, data->name, |
| 986 | XmNtopOffset, 1, |
| 987 | NULL); |
| 988 | XmStringFree(str); |
| 989 | apply_fontlist(name); |
| 990 | |
| 991 | /* create sample display label widget */ |
| 992 | disp_frame = XtVaCreateManagedWidget("sampleFrame", |
| 993 | xmFrameWidgetClass, form, |
| 994 | XmNshadowType, XmSHADOW_ETCHED_IN, |
| 995 | XmNleftAttachment, XmATTACH_FORM, |
| 996 | XmNleftOffset, 4, |
| 997 | XmNbottomAttachment, XmATTACH_WIDGET, |
| 998 | XmNbottomWidget, name, |
| 999 | XmNrightAttachment, XmATTACH_WIDGET, |
| 1000 | XmNrightWidget, separator, |
| 1001 | XmNrightOffset, 4, |
| 1002 | XmNalignment, XmALIGNMENT_BEGINNING, |
| 1003 | NULL); |
| 1004 | |
| 1005 | data->sample = XtVaCreateManagedWidget("sampleLabel", |
| 1006 | xmLabelWidgetClass, disp_frame, |
| 1007 | XmNleftAttachment, XmATTACH_FORM, |
| 1008 | XmNtopAttachment, XmATTACH_FORM, |
| 1009 | XmNbottomAttachment, XmATTACH_FORM, |
| 1010 | XmNrightAttachment, XmATTACH_FORM, |
| 1011 | XmNalignment, XmALIGNMENT_BEGINNING, |
| 1012 | XmNrecomputeSize, False, |
| 1013 | XmNfontList, data->old_list, |
| 1014 | NULL); |
| 1015 | |
| 1016 | /* create toggle button */ |
| 1017 | str = XmStringCreateLocalized(_("Show size in Points")); |
| 1018 | size_toggle = XtVaCreateManagedWidget("sizeToggle", |
| 1019 | xmToggleButtonGadgetClass, form, |
| 1020 | XmNlabelString, str, |
| 1021 | XmNleftAttachment, XmATTACH_FORM, |
| 1022 | XmNleftOffset, 4, |
| 1023 | XmNbottomAttachment, XmATTACH_WIDGET, |
| 1024 | XmNbottomWidget, disp_frame, |
| 1025 | XmNbottomOffset, 4, |
| 1026 | NULL); |
| 1027 | XmStringFree(str); |
| 1028 | apply_fontlist(size_toggle); |
| 1029 | XtManageChild(size_toggle); |
| 1030 | |
| 1031 | /* Encoding pulldown menu. |
| 1032 | */ |
| 1033 | |
| 1034 | data->encoding_pulldown = XmCreatePulldownMenu(form, |
| 1035 | "encodingPulldown", NULL, 0); |
| 1036 | str = XmStringCreateLocalized(_("Encoding:")); |
| 1037 | n = 0; |
| 1038 | XtSetArg(args[n], XmNsubMenuId, data->encoding_pulldown); ++n; |
| 1039 | XtSetArg(args[n], XmNlabelString, str); ++n; |
| 1040 | XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); ++n; |
| 1041 | XtSetArg(args[n], XmNleftOffset, 4); ++n; |
| 1042 | XtSetArg(args[n], XmNbottomAttachment, XmATTACH_WIDGET); ++n; |
| 1043 | XtSetArg(args[n], XmNbottomWidget, size_toggle); ++n; |
| 1044 | XtSetArg(args[n], XmNbottomOffset, 4); ++n; |
| 1045 | XtSetArg(args[n], XmNrightAttachment, XmATTACH_WIDGET); ++n; |
| 1046 | XtSetArg(args[n], XmNrightWidget, separator); ++n; |
| 1047 | XtSetArg(args[n], XmNrightOffset, 4); ++n; |
| 1048 | data->encoding_menu = XmCreateOptionMenu(form, "encodingMenu", args, n); |
| 1049 | XmStringFree(str); |
| 1050 | XmAddTabGroup(data->encoding_menu); |
| 1051 | |
| 1052 | /* |
| 1053 | * Create scroll list widgets in a separate subform used to manage the |
| 1054 | * different sizes of the lists. |
| 1055 | */ |
| 1056 | |
| 1057 | sub_form = XtVaCreateManagedWidget("subForm", |
| 1058 | xmFormWidgetClass, form, |
| 1059 | XmNbottomAttachment, XmATTACH_WIDGET, |
| 1060 | XmNbottomWidget, data->encoding_menu, |
| 1061 | XmNbottomOffset, 4, |
| 1062 | XmNleftAttachment, XmATTACH_FORM, |
| 1063 | XmNleftOffset, 4, |
| 1064 | XmNrightAttachment, XmATTACH_WIDGET, |
| 1065 | XmNrightWidget, separator, |
| 1066 | XmNrightOffset, 4, |
| 1067 | XmNtopAttachment, XmATTACH_FORM, |
| 1068 | XmNtopOffset, 2, |
| 1069 | XmNorientation, XmVERTICAL, |
| 1070 | NULL); |
| 1071 | |
| 1072 | /* font list */ |
| 1073 | frame = XtVaCreateManagedWidget("frame", xmFrameWidgetClass, sub_form, |
| 1074 | XmNshadowThickness, 0, |
| 1075 | XmNtopAttachment, XmATTACH_FORM, |
| 1076 | XmNbottomAttachment, XmATTACH_FORM, |
| 1077 | XmNleftAttachment, XmATTACH_FORM, |
| 1078 | XmNrightAttachment, XmATTACH_POSITION, |
| 1079 | XmNrightPosition, 50, |
| 1080 | NULL); |
| 1081 | |
| 1082 | str = XmStringCreateLocalized(_("Font:")); |
| 1083 | name = XtVaCreateManagedWidget("nameListLabel", xmLabelGadgetClass, frame, |
| 1084 | XmNchildType, XmFRAME_TITLE_CHILD, |
| 1085 | XmNchildVerticalAlignment, XmALIGNMENT_CENTER, |
| 1086 | XmNchildHorizontalAlignment, XmALIGNMENT_BEGINNING, |
| 1087 | XmNlabelString, str, |
| 1088 | NULL); |
| 1089 | XmStringFree(str); |
| 1090 | apply_fontlist(name); |
| 1091 | |
| 1092 | n = 0; |
| 1093 | XtSetArg(args[n], XmNvisibleItemCount, 8); ++n; |
| 1094 | XtSetArg(args[n], XmNresizable, True); ++n; |
| 1095 | XtSetArg(args[n], XmNlistSizePolicy, XmCONSTANT); ++n; |
| 1096 | XtSetArg(args[n], XmNvisualPolicy, XmVARIABLE); ++n; |
| 1097 | #ifdef LESSTIF_VERSION |
| 1098 | XtSetArg(args[n], XmNscrollBarDisplayPolicy, XmSTATIC); ++n; |
| 1099 | #endif |
| 1100 | data->list[NAME] = XmCreateScrolledList(frame, "fontList", args, n); |
| 1101 | XtVaSetValues(name, XmNuserData, data->list[NAME], NULL); |
| 1102 | |
| 1103 | /* style list */ |
| 1104 | frame = XtVaCreateManagedWidget("frame", xmFrameWidgetClass, sub_form, |
| 1105 | XmNshadowThickness, 0, |
| 1106 | XmNtopAttachment, XmATTACH_FORM, |
| 1107 | XmNbottomAttachment, XmATTACH_FORM, |
| 1108 | XmNleftAttachment, XmATTACH_POSITION, |
| 1109 | XmNleftPosition, 50, |
| 1110 | XmNleftOffset, 4, |
| 1111 | XmNrightAttachment, XmATTACH_POSITION, |
| 1112 | XmNrightPosition, 80, |
| 1113 | NULL); |
| 1114 | |
| 1115 | str = XmStringCreateLocalized(_("Style:")); |
| 1116 | name = XtVaCreateManagedWidget("styleListLabel", xmLabelWidgetClass, frame, |
| 1117 | XmNchildType, XmFRAME_TITLE_CHILD, |
| 1118 | XmNchildVerticalAlignment, XmALIGNMENT_CENTER, |
| 1119 | XmNchildHorizontalAlignment, XmALIGNMENT_BEGINNING, |
| 1120 | XmNlabelString, str, |
| 1121 | NULL); |
| 1122 | XmStringFree(str); |
| 1123 | apply_fontlist(name); |
| 1124 | |
| 1125 | n = 0; |
| 1126 | XtSetArg(args[n], XmNvisibleItemCount, 8); ++n; |
| 1127 | XtSetArg(args[n], XmNresizable, True); ++n; |
| 1128 | XtSetArg(args[n], XmNlistSizePolicy, XmCONSTANT); ++n; |
| 1129 | XtSetArg(args[n], XmNvisualPolicy, XmVARIABLE); ++n; |
| 1130 | #ifdef LESSTIF_VERSION |
| 1131 | XtSetArg(args[n], XmNscrollBarDisplayPolicy, XmSTATIC); ++n; |
| 1132 | #endif |
| 1133 | data->list[STYLE] = XmCreateScrolledList(frame, "styleList", args, n); |
| 1134 | XtVaSetValues(name, XmNuserData, data->list[STYLE], NULL); |
| 1135 | |
| 1136 | /* size list */ |
| 1137 | frame = XtVaCreateManagedWidget("frame", xmFrameWidgetClass, sub_form, |
| 1138 | XmNshadowThickness, 0, |
| 1139 | XmNtopAttachment, XmATTACH_FORM, |
| 1140 | XmNbottomAttachment, XmATTACH_FORM, |
| 1141 | XmNleftAttachment, XmATTACH_POSITION, |
| 1142 | XmNleftPosition, 80, |
| 1143 | XmNleftOffset, 4, |
| 1144 | XmNrightAttachment, XmATTACH_FORM, |
| 1145 | NULL); |
| 1146 | |
| 1147 | str = XmStringCreateLocalized(_("Size:")); |
| 1148 | name = XtVaCreateManagedWidget("sizeListLabel", xmLabelGadgetClass, frame, |
| 1149 | XmNchildType, XmFRAME_TITLE_CHILD, |
| 1150 | XmNchildVerticalAlignment, XmALIGNMENT_CENTER, |
| 1151 | XmNchildHorizontalAlignment, XmALIGNMENT_BEGINNING, |
| 1152 | XmNlabelString, str, |
| 1153 | NULL); |
| 1154 | XmStringFree(str); |
| 1155 | apply_fontlist(name); |
| 1156 | |
| 1157 | n = 0; |
| 1158 | XtSetArg(args[n], XmNvisibleItemCount, 8); ++n; |
| 1159 | XtSetArg(args[n], XmNresizable, True); ++n; |
| 1160 | XtSetArg(args[n], XmNlistSizePolicy, XmCONSTANT); ++n; |
| 1161 | XtSetArg(args[n], XmNvisualPolicy, XmVARIABLE); ++n; |
| 1162 | #ifdef LESSTIF_VERSION |
| 1163 | XtSetArg(args[n], XmNscrollBarDisplayPolicy, XmSTATIC); ++n; |
| 1164 | #endif |
| 1165 | data->list[SIZE] = XmCreateScrolledList(frame, "sizeList", args, n); |
| 1166 | XtVaSetValues(name, XmNuserData, data->list[SIZE], NULL); |
| 1167 | |
| 1168 | /* update form widgets cancel button */ |
| 1169 | XtVaSetValues(form, XmNcancelButton, data->cancel, NULL); |
| 1170 | |
| 1171 | XtAddCallback(size_toggle, XmNvalueChangedCallback, |
| 1172 | (XtCallbackProc)stoggle_callback, (XtPointer)data); |
| 1173 | XtAddCallback(data->list[NAME], XmNbrowseSelectionCallback, |
| 1174 | (XtCallbackProc)name_callback, (XtPointer)data); |
| 1175 | XtAddCallback(data->list[STYLE], XmNbrowseSelectionCallback, |
| 1176 | (XtCallbackProc)style_callback, (XtPointer)data); |
| 1177 | XtAddCallback(data->list[SIZE], XmNbrowseSelectionCallback, |
| 1178 | (XtCallbackProc)size_callback, (XtPointer)data); |
| 1179 | XtAddCallback(data->ok, XmNactivateCallback, |
| 1180 | (XtCallbackProc)ok_callback, (XtPointer)data); |
| 1181 | XtAddCallback(data->cancel, XmNactivateCallback, |
| 1182 | (XtCallbackProc)cancel_callback, (XtPointer)data); |
| 1183 | |
| 1184 | XmProcessTraversal(data->list[NAME], XmTRAVERSE_CURRENT); |
| 1185 | |
| 1186 | /* setup tabgroups */ |
| 1187 | |
| 1188 | XmAddTabGroup(data->list[NAME]); |
| 1189 | XmAddTabGroup(data->list[STYLE]); |
| 1190 | XmAddTabGroup(data->list[SIZE]); |
| 1191 | XmAddTabGroup(size_toggle); |
| 1192 | XmAddTabGroup(data->name); |
| 1193 | XmAddTabGroup(data->ok); |
| 1194 | XmAddTabGroup(data->cancel); |
| 1195 | |
| 1196 | add_cancel_action(data->dialog, (XtCallbackProc)cancel_callback, data); |
| 1197 | |
| 1198 | /* Preset selection data. */ |
| 1199 | |
| 1200 | data->exit = False; |
| 1201 | data->in_pixels= True; |
| 1202 | data->sel[ENCODING] = NULL; |
| 1203 | data->sel[NAME] = NULL; |
| 1204 | data->sel[STYLE] = NULL; |
| 1205 | data->sel[SIZE] = NULL; |
| 1206 | data->font_name = NULL; |
| 1207 | |
| 1208 | /* set up current font parameters */ |
| 1209 | if (current && current[0] != '\0') |
| 1210 | { |
| 1211 | int i; |
| 1212 | char **names; |
| 1213 | |
| 1214 | names = XListFonts(XtDisplay(form), (char *) current, 1, &i); |
| 1215 | |
| 1216 | if (i != 0) |
| 1217 | { |
| 1218 | char name[TEMP_BUF_SIZE]; |
| 1219 | char style[TEMP_BUF_SIZE]; |
| 1220 | char size[TEMP_BUF_SIZE]; |
| 1221 | char encoding[TEMP_BUF_SIZE]; |
| 1222 | char *found; |
| 1223 | |
| 1224 | found = names[0]; |
| 1225 | |
| 1226 | name_part(found, name); |
| 1227 | style_part(found, style); |
| 1228 | size_part(found, size, data->in_pixels); |
| 1229 | encoding_part(found, encoding); |
| 1230 | |
| 1231 | if (strlen(name) > 0 |
| 1232 | && strlen(style) > 0 |
| 1233 | && strlen(size) > 0 |
| 1234 | && strlen(encoding) > 0) |
| 1235 | { |
| 1236 | data->sel[NAME] = XtNewString(name); |
| 1237 | data->sel[STYLE] = XtNewString(style); |
| 1238 | data->sel[SIZE] = XtNewString(size); |
| 1239 | data->sel[ENCODING] = XtNewString(encoding); |
| 1240 | data->font_name = XtNewString(names[0]); |
| 1241 | display_sample(data); |
| 1242 | XmTextSetString(data->name, data->font_name); |
| 1243 | } |
| 1244 | else |
| 1245 | { |
| 1246 | /* We can't preset a symbolic name, which isn't a full font |
| 1247 | * description. Therefore we just behave the same way as if the |
| 1248 | * user didn't have selected anything thus far. |
| 1249 | * |
| 1250 | * Unfortunately there is no known way to expand an abbreviated |
| 1251 | * font name. |
| 1252 | */ |
| 1253 | |
| 1254 | data->font_name = NULL; |
| 1255 | } |
| 1256 | } |
| 1257 | XFreeFontNames(names); |
| 1258 | } |
| 1259 | |
| 1260 | fill_lists(NONE, data); |
| 1261 | |
| 1262 | /* Unfortunately LessTif doesn't align the list widget's properly. I don't |
| 1263 | * have currently any idea how to fix this problem. |
| 1264 | */ |
| 1265 | XtManageChild(data->list[NAME]); |
| 1266 | XtManageChild(data->list[STYLE]); |
| 1267 | XtManageChild(data->list[SIZE]); |
| 1268 | XtManageChild(data->encoding_menu); |
| 1269 | manage_centered(form); |
| 1270 | |
| 1271 | /* modal event loop */ |
| 1272 | while (!data->exit) |
| 1273 | XtAppProcessEvent(XtWidgetToApplicationContext(data->dialog), |
| 1274 | (XtInputMask)XtIMAll); |
| 1275 | |
| 1276 | XtDestroyWidget(data->dialog); |
| 1277 | |
| 1278 | if (data->old) |
| 1279 | { |
| 1280 | XFreeFont(XtDisplay(data->dialog), data->old); |
| 1281 | XmFontListFree(data->old_list); |
| 1282 | } |
| 1283 | |
| 1284 | gui_motif_synch_fonts(); |
| 1285 | |
| 1286 | return (char_u *) data->font_name; |
| 1287 | } |