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