blob: 04996efece236f5a90b055f8db410a8aadee35e1 [file] [log] [blame]
Bram Moolenaaredf3f972016-08-29 22:49:24 +02001/* vi:set ts=8 sts=4 sw=4 noet:
Bram Moolenaardfccaf02004-12-31 20:56:11 +00002 *
3 * VIM - Vi IMproved by Bram Moolenaar
Bram Moolenaardfccaf02004-12-31 20:56:11 +00004 *
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/*
Bram Moolenaarb78b0b02005-01-02 11:32:29 +000011 * (C) 2001,2005 by Marcin Dalecki <martin@dalecki.de>
Bram Moolenaardfccaf02004-12-31 20:56:11 +000012 *
Bram Moolenaar0af561d2009-11-03 11:53:55 +000013 * Implementation of dialog functions for the Motif GUI variant.
Bram Moolenaarb78b0b02005-01-02 11:32:29 +000014 *
Bram Moolenaar2c7a7632007-05-10 18:19:11 +000015 * Note about Lesstif: Apparently lesstif doesn't get the widget layout right,
Bram Moolenaarb78b0b02005-01-02 11:32:29 +000016 * when using a dynamic scrollbar policy.
Bram Moolenaardfccaf02004-12-31 20:56:11 +000017 */
18
Bram Moolenaarf7506ca2017-02-25 16:01:49 +010019#include "vim.h"
20
Bram Moolenaardfccaf02004-12-31 20:56:11 +000021#include <Xm/Form.h>
22#include <Xm/PushBG.h>
23#include <Xm/Text.h>
24#include <Xm/TextF.h>
25#include <Xm/Label.h>
26#include <Xm/Frame.h>
27#include <Xm/LabelG.h>
28#include <Xm/ToggleBG.h>
29#include <Xm/SeparatoG.h>
30#include <Xm/DialogS.h>
31#include <Xm/List.h>
32#include <Xm/RowColumn.h>
33#include <Xm/AtomMgr.h>
34#include <Xm/Protocols.h>
35
36#include <X11/keysym.h>
37#include <X11/Xatom.h>
38#include <X11/StringDefs.h>
39#include <X11/Intrinsic.h>
40
Bram Moolenaardfccaf02004-12-31 20:56:11 +000041extern 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
Bram Moolenaar734a8672019-12-02 22:49:38 +010049/////////////////////////////////////////////////////////////////////////////
50// Font selection dialogue implementation.
Bram Moolenaardfccaf02004-12-31 20:56:11 +000051
52static char wild[3] = "*";
53
54/*
55 * FIXME: This is a generic function, which should be used throughout the whole
56 * application.
57 *
58 * Add close_callback, which will be called when the user selects close from
59 * the window menu. The close menu item usually activates f.kill which sends a
60 * WM_DELETE_WINDOW protocol request for the window.
61 */
62
63 static void
64add_cancel_action(Widget shell, XtCallbackProc close_callback, void *arg)
65{
66 static Atom wmp_atom = 0;
67 static Atom dw_atom = 0;
68 Display *display = XtDisplay(shell);
69
Bram Moolenaar734a8672019-12-02 22:49:38 +010070 // deactivate the built-in delete response of killing the application
Bram Moolenaar446cb832008-06-24 21:56:24 +000071 XtVaSetValues(shell, XmNdeleteResponse, XmDO_NOTHING, NULL);
Bram Moolenaardfccaf02004-12-31 20:56:11 +000072
Bram Moolenaar734a8672019-12-02 22:49:38 +010073 // add a delete window protocol callback instead
Bram Moolenaardfccaf02004-12-31 20:56:11 +000074 if (!dw_atom)
75 {
76 wmp_atom = XmInternAtom(display, "WM_PROTOCOLS", True);
77 dw_atom = XmInternAtom(display, "WM_DELETE_WINDOW", True);
78 }
79 XmAddProtocolCallback(shell, wmp_atom, dw_atom, close_callback, arg);
80}
81
82#define MAX_FONTS 65535
83#define MAX_FONT_NAME_LEN 256
84#define MAX_ENTRIES_IN_LIST 5000
85#define MAX_DISPLAY_SIZE 150
86#define TEMP_BUF_SIZE 256
87
88enum ListSpecifier
89{
90 ENCODING,
91 NAME,
92 STYLE,
93 SIZE,
94 NONE
95};
96
97typedef struct _SharedFontSelData
98{
99 Widget dialog;
100 Widget ok;
101 Widget cancel;
102 Widget encoding_pulldown;
103 Widget encoding_menu;
104 Widget list[NONE];
105 Widget name;
106 Widget sample;
Bram Moolenaar734a8672019-12-02 22:49:38 +0100107 char **names; // font name array of arrays
108 int num; // number of font names
109 String sel[NONE]; // selection category
110 Boolean in_pixels; // toggle state - size in pixels
111 char *font_name; // current font name
112 XFontStruct *old; // font data structure for sample display
113 XmFontList old_list; // font data structure for sample display
114 Boolean exit; // used for program exit control
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000115} SharedFontSelData;
116
117/*
118 * Checking access to the font name array for validity.
119 */
120 static char *
121fn(SharedFontSelData *data, int i)
122{
Bram Moolenaar734a8672019-12-02 22:49:38 +0100123 // Assertion checks:
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000124 if (data->num < 0)
125 abort();
126 if (i >= data->num)
127 i = data->num - 1;
128 if (i < 0)
129 i = 0;
130
131 return data->names[i];
132}
133
134/*
135 * Get a specific substring from a font name.
136 */
137 static void
138get_part(char *in, int pos, char *out)
139{
140 int i;
141 int j;
142
143 *out = '\0';
144
145 for (i = 0; (pos > 0) && (in[i] != '\0'); ++i)
146 if (in[i] == '-')
147 pos--;
148
149 if (in[i] == '\0')
150 return;
151
152 for (j = 0; (in[i] != '-') && (in[i] != '\0'); ++i, ++j)
153 out[j] = in[i];
154 out[j] = '\0';
155}
156
157/*
158 * Given a font name this function returns the part used in the first
159 * scroll list.
160 */
161 static void
162name_part(char *font, char *buf)
163{
164 char buf2[TEMP_BUF_SIZE];
165 char buf3[TEMP_BUF_SIZE];
166
167 get_part(font, 2, buf2);
168 get_part(font, 1, buf3);
169
Bram Moolenaar64404472010-06-26 06:24:45 +0200170 if (*buf3 != NUL)
Bram Moolenaar051b7822005-05-19 21:00:46 +0000171 vim_snprintf(buf, TEMP_BUF_SIZE, "%s (%s)", buf2, buf3);
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000172 else
Bram Moolenaar051b7822005-05-19 21:00:46 +0000173 vim_snprintf(buf, TEMP_BUF_SIZE, "%s", buf2);
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000174}
175
176/*
177 * Given a font name this function returns the part used in the second scroll list.
178 */
179 static void
180style_part(char *font, char *buf)
181{
182 char buf2[TEMP_BUF_SIZE];
183 char buf3[TEMP_BUF_SIZE];
184
185 get_part(font, 3, buf3);
186 get_part(font, 5, buf2);
187
188 if (!strcmp(buf2, "normal") && !strcmp(buf2, "Normal")
189 && !strcmp(buf2, "NORMAL"))
Bram Moolenaar051b7822005-05-19 21:00:46 +0000190 vim_snprintf(buf, TEMP_BUF_SIZE, "%s %s", buf3, buf2);
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000191 else
192 strcpy(buf, buf3);
193
194 get_part(font, 6, buf2);
195
196 if (buf2[0] != '\0')
Bram Moolenaar051b7822005-05-19 21:00:46 +0000197 vim_snprintf(buf3, TEMP_BUF_SIZE, "%s %s", buf, buf2);
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000198 else
199 strcpy(buf3, buf);
200
201 get_part(font, 4, buf2);
202
203 if (!strcmp(buf2, "o") || !strcmp(buf2, "O"))
Bram Moolenaar051b7822005-05-19 21:00:46 +0000204 vim_snprintf(buf, TEMP_BUF_SIZE, "%s oblique", buf3);
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000205 else if (!strcmp(buf2, "i") || !strcmp(buf2, "I"))
Bram Moolenaar051b7822005-05-19 21:00:46 +0000206 vim_snprintf(buf, TEMP_BUF_SIZE, "%s italic", buf3);
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000207
208 if (!strcmp(buf, " "))
209 strcpy(buf, "-");
210}
211
212/*
213 * Given a font name this function returns the part used in the third
214 * scroll list.
215 */
216 static void
217size_part(char *font, char *buf, int inPixels)
218{
219 int size;
220 float temp;
221
222 *buf = '\0';
223
224 if (inPixels)
225 {
226 get_part(font, 7, buf);
Bram Moolenaar64404472010-06-26 06:24:45 +0200227 if (*buf != NUL)
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000228 {
229 size = atoi(buf);
230 sprintf(buf, "%3d", size);
231 }
232 }
233 else
234 {
235 get_part(font, 8, buf);
Bram Moolenaar64404472010-06-26 06:24:45 +0200236 if (*buf != NUL)
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000237 {
238 size = atoi(buf);
239 temp = (float)size / 10.0;
240 size = temp;
241 if (buf[strlen(buf) - 1] == '0')
242 sprintf(buf, "%3d", size);
243 else
244 sprintf(buf, "%4.1f", temp);
245 }
246 }
247}
248
249/*
250 * Given a font name this function returns the part used in the choice menu.
251 */
252 static void
253encoding_part(char *font, char *buf)
254{
255 char buf1[TEMP_BUF_SIZE];
256 char buf2[TEMP_BUF_SIZE];
257
258 *buf = '\0';
259
260 get_part(font, 13, buf1);
261 get_part(font, 14, buf2);
262
Bram Moolenaar64404472010-06-26 06:24:45 +0200263 if (*buf1 != NUL && *buf2 != NUL)
Bram Moolenaar051b7822005-05-19 21:00:46 +0000264 vim_snprintf(buf, TEMP_BUF_SIZE, "%s-%s", buf1, buf2);
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000265 if (!strcmp(buf, " "))
266 strcpy(buf, "-");
267}
268
269/*
270 * Inserts a string into correct sorted position in a list.
271 */
272 static void
273add_to_list(char **buf, char *item, int *count)
274{
275 int i;
276 int j;
277
278 if (*count == MAX_ENTRIES_IN_LIST)
279 return;
280
Bram Moolenaar734a8672019-12-02 22:49:38 +0100281 // avoid duplication
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000282 for (i = 0; i < *count; ++i)
283 {
284 if (!strcmp(buf[i], item))
285 return;
286 }
287
Bram Moolenaar734a8672019-12-02 22:49:38 +0100288 // find order place, but make sure that wild card comes first
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000289 if (!strcmp(item, wild))
290 i = 0;
291 else
292 for (i = 0; i < *count; ++i)
293 if (strcmp(buf[i], item) > 0 && strcmp(buf[i], wild))
294 break;
295
Bram Moolenaar734a8672019-12-02 22:49:38 +0100296 // now insert the item
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000297 for (j = *count; j > i; --j)
298 buf[j] = buf[j-1];
299 buf[i] = XtNewString(item);
300
301 ++(*count);
302}
303
304/*
305 * True if the font matches some field.
306 */
307 static Boolean
308match(SharedFontSelData *data, enum ListSpecifier l, int i)
309{
310 char buf[TEMP_BUF_SIZE];
311
Bram Moolenaar734a8672019-12-02 22:49:38 +0100312 // An empty selection or a wild card matches anything.
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000313 if (!data->sel[l] || !strcmp(data->sel[l], wild))
314 return True;
315
Bram Moolenaar734a8672019-12-02 22:49:38 +0100316 // chunk out the desired part...
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000317 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
Bram Moolenaar734a8672019-12-02 22:49:38 +0100338 // ...and chew it now
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000339
340 return !strcmp(buf, data->sel[l]);
341}
342
343 static Boolean
344proportional(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
354static 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
363fill_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;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +0000370 int idx;
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000371
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +0000372 for (idx = (int)ENCODING; idx < (int)NONE; ++idx)
373 count[idx] = 0;
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000374
Bram Moolenaar734a8672019-12-02 22:49:38 +0100375 // First we insert the wild char into every single list.
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000376 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
Bram Moolenaar734a8672019-12-02 22:49:38 +0100437 // Get and update the current button list.
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000438 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
Bram Moolenaar4bdbbf72009-05-21 21:27:43 +0000449 if (i < (int)n_items)
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000450 {
Bram Moolenaar734a8672019-12-02 22:49:38 +0100451 // recycle old button
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000452 XtVaSetValues(children[i],
453 XmNlabelString, items[i],
454 XmNuserData, i,
455 NULL);
456 button = children[i];
457 }
458 else
459 {
Bram Moolenaar734a8672019-12-02 22:49:38 +0100460 // create a new button
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000461 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
Bram Moolenaar734a8672019-12-02 22:49:38 +0100480 // Destroy all the outstanding menu items.
Bram Moolenaar4bdbbf72009-05-21 21:27:43 +0000481 for (i = count[ENCODING]; i < (int)n_items; ++i)
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000482 {
483 XtUnmanageChild(children[i]);
484 XtDestroyWidget(children[i]);
485 }
486
Bram Moolenaar734a8672019-12-02 22:49:38 +0100487 // Preserve the current selection visually.
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000488 if (selected_button)
489 {
490 XtVaSetValues(data->encoding_menu,
491 XmNmenuHistory, selected_button,
492 NULL);
493 }
494
495 for (i = 0; i < count[ENCODING]; ++i)
496 XmStringFree(items[i]);
497 }
498
499 /*
500 * Now loop trough the remaining lists and set them up.
501 */
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +0000502 for (idx = (int)NAME; idx < (int)NONE; ++idx)
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000503 {
504 Widget w;
505
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +0000506 if (fix == (enum ListSpecifier)idx)
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000507 continue;
508
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +0000509 switch ((enum ListSpecifier)idx)
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000510 {
511 case NAME:
512 w = data->list[NAME];
513 break;
514 case STYLE:
515 w = data->list[STYLE];
516 break;
517 case SIZE:
518 w = data->list[SIZE];
519 break;
520 default:
Bram Moolenaar734a8672019-12-02 22:49:38 +0100521 w = (Widget)0; // for lint
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000522 }
523
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +0000524 for (i = 0; i < count[idx]; ++i)
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000525 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +0000526 items[i] = XmStringCreateLocalized(list[idx][i]);
527 XtFree(list[idx][i]);
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000528 }
529 XmListDeleteAllItems(w);
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +0000530 XmListAddItems(w, items, count[idx], 1);
531 if (data->sel[idx])
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000532 {
533 XmStringFree(items[0]);
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +0000534 items[0] = XmStringCreateLocalized(data->sel[idx]);
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000535 XmListSelectItem(w, items[0], False);
536 XmListSetBottomItem(w, items[0]);
537 }
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +0000538 for (i = 0; i < count[idx]; ++i)
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000539 XmStringFree(items[i]);
540 }
541}
542
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000543 static void
Bram Moolenaar4bdbbf72009-05-21 21:27:43 +0000544stoggle_callback(Widget w UNUSED,
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000545 SharedFontSelData *data,
546 XmToggleButtonCallbackStruct *call_data)
547{
548 int i, do_sel;
Bram Moolenaar051b7822005-05-19 21:00:46 +0000549 char newSize[TEMP_BUF_SIZE];
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000550 XmString str;
551
552 if (call_data->reason != (int)XmCR_VALUE_CHANGED)
553 return;
554
555 do_sel = (data->sel[SIZE] != NULL) && strcmp(data->sel[SIZE], wild);
556
557 for (i = 0; do_sel && (i < data->num); i++)
558 if (match(data, ENCODING, i)
559 && match(data, NAME, i)
560 && match(data, STYLE, i)
561 && match(data, SIZE, i))
562 {
563 size_part(fn(data, i), newSize, !data->in_pixels);
564 break;
565 }
566
567 data->in_pixels = !data->in_pixels;
568
569 if (data->sel[SIZE])
570 XtFree(data->sel[SIZE]);
571 data->sel[SIZE] = NULL;
572 fill_lists(NONE, data);
573
574 if (do_sel)
575 {
576 str = XmStringCreateLocalized(newSize);
577 XmListSelectItem(data->list[SIZE], str, True);
578 XmListSetBottomItem(data->list[SIZE], str);
579 XmStringFree(str);
580 }
581}
582
583/*
584 * Show the currently selected font in the sample text label.
585 */
586 static void
587display_sample(SharedFontSelData *data)
588{
589 Arg args[2];
590 int n;
591 XFontStruct * font;
592 XmFontList font_list;
593 Display * display;
594 XmString str;
595
596 display = XtDisplay(data->dialog);
597 font = XLoadQueryFont(display, data->font_name);
598 font_list = gui_motif_create_fontlist(font);
599
600 n = 0;
601 str = XmStringCreateLocalized("AaBbZzYy 0123456789");
602 XtSetArg(args[n], XmNlabelString, str); n++;
603 XtSetArg(args[n], XmNfontList, font_list); n++;
604
605 XtSetValues(data->sample, args, n);
606 XmStringFree(str);
607
608 if (data->old)
609 {
610 XFreeFont(display, data->old);
611 XmFontListFree(data->old_list);
612 }
613 data->old = font;
614 data->old_list = font_list;
615}
616
617
618 static Boolean
619do_choice(Widget w,
620 SharedFontSelData *data,
621 XmListCallbackStruct *call_data,
622 enum ListSpecifier which)
623{
624 char *sel;
625
626 XmStringGetLtoR(call_data->item, XmSTRING_DEFAULT_CHARSET, &sel);
627
628 if (!data->sel[which])
629 data->sel[which] = XtNewString(sel);
630 else
631 {
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000632 if (!strcmp(data->sel[which], sel))
633 {
Bram Moolenaar734a8672019-12-02 22:49:38 +0100634 // unselecting current selection
Bram Moolenaar0af561d2009-11-03 11:53:55 +0000635 XtFree(data->sel[which]);
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000636 data->sel[which] = NULL;
637 if (w)
638 XmListDeselectItem(w, call_data->item);
639 }
640 else
Bram Moolenaar0af561d2009-11-03 11:53:55 +0000641 {
642 XtFree(data->sel[which]);
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000643 data->sel[which] = XtNewString(sel);
Bram Moolenaar0af561d2009-11-03 11:53:55 +0000644 }
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000645 }
646 XtFree(sel);
647
648 fill_lists(which, data);
649
Bram Moolenaar734a8672019-12-02 22:49:38 +0100650 // If there is a font selection, we display it.
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000651 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"),
Bram Moolenaard2c340a2011-01-17 20:08:11 +0100687 (char_u *)_("&Dismiss"), 1, NULL, FALSE);
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000688
689 return True;
690 }
691 else
692 {
693 int n;
694 XmString str;
695 Arg args[4];
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +0000696 char *nomatch_msg = _("no specific match");
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000697
698 n = 0;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +0000699 str = XmStringCreateLocalized(nomatch_msg);
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000700 XtSetArg(args[n], XmNlabelString, str); ++n;
701 XtSetValues(data->sample, args, n);
702 apply_fontlist(data->sample);
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +0000703 XmTextSetString(data->name, nomatch_msg);
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000704 XmStringFree(str);
705
706 return False;
707 }
708}
709
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000710 static void
711encoding_callback(Widget w,
712 SharedFontSelData *data,
Bram Moolenaar4bdbbf72009-05-21 21:27:43 +0000713 XtPointer dummy UNUSED)
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000714{
715 XmString str;
716 XmListCallbackStruct fake_data;
717
718 XtVaGetValues(w, XmNlabelString, &str, NULL);
719
720 if (!str)
721 return;
722
723 fake_data.item = str;
724
725 do_choice(0, data, &fake_data, ENCODING);
726}
727
728 static void
729name_callback(Widget w,
730 SharedFontSelData *data,
731 XmListCallbackStruct *call_data)
732{
733 do_choice(w, data, call_data, NAME);
734}
735
736 static void
737style_callback(Widget w,
738 SharedFontSelData *data,
739 XmListCallbackStruct *call_data)
740{
741 do_choice(w, data, call_data, STYLE);
742}
743
744 static void
745size_callback(Widget w,
746 SharedFontSelData *data,
747 XmListCallbackStruct *call_data)
748{
749 do_choice(w, data, call_data, SIZE);
750}
751
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000752 static void
Bram Moolenaar4bdbbf72009-05-21 21:27:43 +0000753cancel_callback(Widget w UNUSED,
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000754 SharedFontSelData *data,
Bram Moolenaar4bdbbf72009-05-21 21:27:43 +0000755 XmListCallbackStruct *call_data UNUSED)
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000756{
757 if (data->sel[ENCODING])
758 {
759 XtFree(data->sel[ENCODING]);
760 data->sel[ENCODING] = NULL;
761 }
762 if (data->sel[NAME])
763 {
764 XtFree(data->sel[NAME]);
765 data->sel[NAME] = NULL;
766 }
767 if (data->sel[STYLE])
768 {
769 XtFree(data->sel[STYLE]);
770 data->sel[STYLE] = NULL;
771 }
772 if (data->sel[SIZE])
773 {
774 XtFree(data->sel[SIZE]);
775 data->sel[SIZE] = NULL;
776 }
777
778 if (data->font_name)
779 XtFree(data->font_name);
780 data->font_name = NULL;
781
782 data->num = 0;
783 XFreeFontNames(data->names);
784 data->names = NULL;
785 data->exit = True;
786}
787
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000788 static void
Bram Moolenaar4bdbbf72009-05-21 21:27:43 +0000789ok_callback(Widget w UNUSED,
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000790 SharedFontSelData *data,
Bram Moolenaar4bdbbf72009-05-21 21:27:43 +0000791 XmPushButtonCallbackStruct *call_data UNUSED)
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000792{
793 char *pattern;
794 char **name;
795 int i;
796
797 pattern = XmTextGetString(data->name);
798 name = XListFonts(XtDisplay(data->dialog), pattern, 1, &i);
799 XtFree(pattern);
800
801 if (i != 1)
802 {
803 do_dialog(VIM_ERROR,
804 (char_u *)_("Error"),
805 (char_u *)_("Invalid font specification"),
Bram Moolenaard2c340a2011-01-17 20:08:11 +0100806 (char_u *)_("&Dismiss"), 1, NULL, FALSE);
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000807 XFreeFontNames(name);
808 }
809 else
810 {
811 if (data->font_name)
812 XtFree(data->font_name);
813 data->font_name = XtNewString(name[0]);
814
815 if (data->sel[ENCODING])
816 {
817 XtFree(data->sel[ENCODING]);
818 data->sel[ENCODING] = NULL;
819 }
820 if (data->sel[NAME])
821 {
822 XtFree(data->sel[NAME]);
823 data->sel[NAME] = NULL;
824 }
825 if (data->sel[STYLE])
826 {
827 XtFree(data->sel[STYLE]);
828 data->sel[STYLE] = NULL;
829 }
830 if (data->sel[SIZE])
831 {
832 XtFree(data->sel[SIZE]);
833 data->sel[SIZE] = NULL;
834 }
835
836 XFreeFontNames(name);
837
838 data->num = 0;
839 XFreeFontNames(data->names);
840 data->names = NULL;
841 data->exit = True;
842 }
843}
844
845/*
846 * Returns pointer to an ASCII character string that contains the name of the
847 * selected font (in X format for naming fonts); it is the users responsibility
848 * to free the space allocated to this string.
849 */
850 char_u *
851gui_xm_select_font(char_u *current)
852{
853 static SharedFontSelData _data;
854
855 Widget parent;
856 Widget form;
857 Widget separator;
858 Widget sub_form;
859 Widget size_toggle;
860 Widget name;
861 Widget disp_frame;
862 Widget frame;
863 Arg args[64];
864 int n;
865 XmString str;
866 char big_font[MAX_FONT_NAME_LEN];
867 SharedFontSelData *data;
868
869 data = &_data;
870
871 parent = vimShell;
872 data->names = XListFonts(XtDisplay(parent), "-*-*-*-*-*-*-*-*-*-*-*-*-*-*",
873 MAX_FONTS, &data->num);
874
875 /*
876 * Find the name of the biggest font less than the given limit
877 * MAX_DISPLAY_SIZE used to set up the initial height of the display
878 * widget.
879 */
880
881 {
882 int i;
883 int max;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +0000884 int idx = 0;
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000885 int size;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +0000886 char buf[128];
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000887
888 for (i = 0, max = 0; i < data->num; i++)
889 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +0000890 get_part(fn(data, i), 7, buf);
891 size = atoi(buf);
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000892 if ((size > max) && (size < MAX_DISPLAY_SIZE))
893 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +0000894 idx = i;
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000895 max = size;
896 }
897 }
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +0000898 strcpy(big_font, fn(data, idx));
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000899 }
900 data->old = XLoadQueryFont(XtDisplay(parent), big_font);
901 data->old_list = gui_motif_create_fontlist(data->old);
902
Bram Moolenaar734a8672019-12-02 22:49:38 +0100903 // Set the title of the Dialog window.
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000904 data->dialog = XmCreateDialogShell(parent, "fontSelector", NULL, 0);
905 str = XmStringCreateLocalized(_("Vim - Font Selector"));
906
Bram Moolenaar734a8672019-12-02 22:49:38 +0100907 // Create form popup dialog widget.
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000908 form = XtVaCreateWidget("form",
909 xmFormWidgetClass, data->dialog,
910 XmNdialogTitle, str,
911 XmNautoUnmanage, False,
912 XmNdialogStyle, XmDIALOG_FULL_APPLICATION_MODAL,
913 NULL);
914 XmStringFree(str);
915
916 sub_form = XtVaCreateManagedWidget("subForm",
917 xmFormWidgetClass, form,
918 XmNbottomAttachment, XmATTACH_FORM,
919 XmNbottomOffset, 4,
920 XmNrightAttachment, XmATTACH_FORM,
921 XmNrightOffset, 4,
922 XmNtopAttachment, XmATTACH_FORM,
923 XmNtopOffset, 4,
924 XmNorientation, XmVERTICAL,
925 NULL);
926
927 data->ok = XtVaCreateManagedWidget(_("OK"),
928 xmPushButtonGadgetClass, sub_form,
929 XmNleftAttachment, XmATTACH_FORM,
930 XmNrightAttachment, XmATTACH_FORM,
931 XmNtopAttachment, XmATTACH_FORM,
932 XmNtopOffset, 4,
933 NULL);
934 apply_fontlist(data->ok);
935
936 data->cancel = XtVaCreateManagedWidget(_("Cancel"),
937 xmPushButtonGadgetClass, sub_form,
938 XmNrightAttachment, XmATTACH_FORM,
939 XmNleftAttachment, XmATTACH_FORM,
940 XmNtopAttachment, XmATTACH_WIDGET,
941 XmNtopWidget, data->ok,
942 XmNtopOffset, 4,
943 XmNshowAsDefault, True,
944 NULL);
945 apply_fontlist(data->cancel);
946
Bram Moolenaar734a8672019-12-02 22:49:38 +0100947 // Create the separator for beauty.
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000948 n = 0;
949 XtSetArg(args[n], XmNorientation, XmVERTICAL); n++;
950 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
951 XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
952 XtSetArg(args[n], XmNrightAttachment, XmATTACH_WIDGET); n++;
953 XtSetArg(args[n], XmNrightWidget, sub_form); n++;
954 XtSetArg(args[n], XmNrightOffset, 4); n++;
955 separator = XmCreateSeparatorGadget(form, "separator", args, n);
956 XtManageChild(separator);
957
Bram Moolenaar734a8672019-12-02 22:49:38 +0100958 // Create font name text widget and the corresponding label.
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000959 data->name = XtVaCreateManagedWidget("fontName",
960 xmTextWidgetClass, form,
961 XmNbottomAttachment, XmATTACH_FORM,
962 XmNbottomOffset, 4,
963 XmNleftAttachment, XmATTACH_FORM,
964 XmNleftOffset, 4,
965 XmNrightAttachment, XmATTACH_WIDGET,
966 XmNrightWidget, separator,
967 XmNrightOffset, 4,
968 XmNeditable, False,
969 XmNeditMode, XmSINGLE_LINE_EDIT,
970 XmNmaxLength, MAX_FONT_NAME_LEN,
971 XmNcolumns, 60,
972 NULL);
973
974 str = XmStringCreateLocalized(_("Name:"));
975 name = XtVaCreateManagedWidget("fontNameLabel",
976 xmLabelGadgetClass, form,
977 XmNlabelString, str,
978 XmNuserData, data->name,
979 XmNleftAttachment, XmATTACH_OPPOSITE_WIDGET,
980 XmNleftWidget, data->name,
981 XmNbottomAttachment, XmATTACH_WIDGET,
982 XmNbottomWidget, data->name,
983 XmNtopOffset, 1,
984 NULL);
985 XmStringFree(str);
986 apply_fontlist(name);
987
Bram Moolenaar734a8672019-12-02 22:49:38 +0100988 // create sample display label widget
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000989 disp_frame = XtVaCreateManagedWidget("sampleFrame",
990 xmFrameWidgetClass, form,
991 XmNshadowType, XmSHADOW_ETCHED_IN,
992 XmNleftAttachment, XmATTACH_FORM,
993 XmNleftOffset, 4,
994 XmNbottomAttachment, XmATTACH_WIDGET,
995 XmNbottomWidget, name,
996 XmNrightAttachment, XmATTACH_WIDGET,
997 XmNrightWidget, separator,
998 XmNrightOffset, 4,
999 XmNalignment, XmALIGNMENT_BEGINNING,
1000 NULL);
1001
1002 data->sample = XtVaCreateManagedWidget("sampleLabel",
1003 xmLabelWidgetClass, disp_frame,
1004 XmNleftAttachment, XmATTACH_FORM,
1005 XmNtopAttachment, XmATTACH_FORM,
1006 XmNbottomAttachment, XmATTACH_FORM,
1007 XmNrightAttachment, XmATTACH_FORM,
1008 XmNalignment, XmALIGNMENT_BEGINNING,
1009 XmNrecomputeSize, False,
1010 XmNfontList, data->old_list,
1011 NULL);
1012
Bram Moolenaar734a8672019-12-02 22:49:38 +01001013 // create toggle button
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001014 str = XmStringCreateLocalized(_("Show size in Points"));
1015 size_toggle = XtVaCreateManagedWidget("sizeToggle",
1016 xmToggleButtonGadgetClass, form,
1017 XmNlabelString, str,
1018 XmNleftAttachment, XmATTACH_FORM,
1019 XmNleftOffset, 4,
1020 XmNbottomAttachment, XmATTACH_WIDGET,
1021 XmNbottomWidget, disp_frame,
1022 XmNbottomOffset, 4,
1023 NULL);
1024 XmStringFree(str);
1025 apply_fontlist(size_toggle);
1026 XtManageChild(size_toggle);
1027
Bram Moolenaar734a8672019-12-02 22:49:38 +01001028 // Encoding pulldown menu.
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001029
1030 data->encoding_pulldown = XmCreatePulldownMenu(form,
1031 "encodingPulldown", NULL, 0);
1032 str = XmStringCreateLocalized(_("Encoding:"));
1033 n = 0;
1034 XtSetArg(args[n], XmNsubMenuId, data->encoding_pulldown); ++n;
1035 XtSetArg(args[n], XmNlabelString, str); ++n;
1036 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); ++n;
1037 XtSetArg(args[n], XmNleftOffset, 4); ++n;
1038 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_WIDGET); ++n;
1039 XtSetArg(args[n], XmNbottomWidget, size_toggle); ++n;
1040 XtSetArg(args[n], XmNbottomOffset, 4); ++n;
1041 XtSetArg(args[n], XmNrightAttachment, XmATTACH_WIDGET); ++n;
1042 XtSetArg(args[n], XmNrightWidget, separator); ++n;
1043 XtSetArg(args[n], XmNrightOffset, 4); ++n;
1044 data->encoding_menu = XmCreateOptionMenu(form, "encodingMenu", args, n);
1045 XmStringFree(str);
1046 XmAddTabGroup(data->encoding_menu);
1047
1048 /*
1049 * Create scroll list widgets in a separate subform used to manage the
1050 * different sizes of the lists.
1051 */
1052
1053 sub_form = XtVaCreateManagedWidget("subForm",
1054 xmFormWidgetClass, form,
1055 XmNbottomAttachment, XmATTACH_WIDGET,
1056 XmNbottomWidget, data->encoding_menu,
1057 XmNbottomOffset, 4,
1058 XmNleftAttachment, XmATTACH_FORM,
1059 XmNleftOffset, 4,
1060 XmNrightAttachment, XmATTACH_WIDGET,
1061 XmNrightWidget, separator,
1062 XmNrightOffset, 4,
1063 XmNtopAttachment, XmATTACH_FORM,
1064 XmNtopOffset, 2,
1065 XmNorientation, XmVERTICAL,
1066 NULL);
1067
Bram Moolenaar734a8672019-12-02 22:49:38 +01001068 // font list
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001069 frame = XtVaCreateManagedWidget("frame", xmFrameWidgetClass, sub_form,
1070 XmNshadowThickness, 0,
1071 XmNtopAttachment, XmATTACH_FORM,
1072 XmNbottomAttachment, XmATTACH_FORM,
1073 XmNleftAttachment, XmATTACH_FORM,
1074 XmNrightAttachment, XmATTACH_POSITION,
1075 XmNrightPosition, 50,
1076 NULL);
1077
1078 str = XmStringCreateLocalized(_("Font:"));
1079 name = XtVaCreateManagedWidget("nameListLabel", xmLabelGadgetClass, frame,
1080 XmNchildType, XmFRAME_TITLE_CHILD,
1081 XmNchildVerticalAlignment, XmALIGNMENT_CENTER,
1082 XmNchildHorizontalAlignment, XmALIGNMENT_BEGINNING,
1083 XmNlabelString, str,
1084 NULL);
1085 XmStringFree(str);
1086 apply_fontlist(name);
1087
1088 n = 0;
1089 XtSetArg(args[n], XmNvisibleItemCount, 8); ++n;
1090 XtSetArg(args[n], XmNresizable, True); ++n;
1091 XtSetArg(args[n], XmNlistSizePolicy, XmCONSTANT); ++n;
1092 XtSetArg(args[n], XmNvisualPolicy, XmVARIABLE); ++n;
1093#ifdef LESSTIF_VERSION
1094 XtSetArg(args[n], XmNscrollBarDisplayPolicy, XmSTATIC); ++n;
1095#endif
1096 data->list[NAME] = XmCreateScrolledList(frame, "fontList", args, n);
1097 XtVaSetValues(name, XmNuserData, data->list[NAME], NULL);
1098
Bram Moolenaar734a8672019-12-02 22:49:38 +01001099 // style list
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001100 frame = XtVaCreateManagedWidget("frame", xmFrameWidgetClass, sub_form,
1101 XmNshadowThickness, 0,
1102 XmNtopAttachment, XmATTACH_FORM,
1103 XmNbottomAttachment, XmATTACH_FORM,
1104 XmNleftAttachment, XmATTACH_POSITION,
1105 XmNleftPosition, 50,
1106 XmNleftOffset, 4,
1107 XmNrightAttachment, XmATTACH_POSITION,
1108 XmNrightPosition, 80,
1109 NULL);
1110
1111 str = XmStringCreateLocalized(_("Style:"));
1112 name = XtVaCreateManagedWidget("styleListLabel", xmLabelWidgetClass, frame,
1113 XmNchildType, XmFRAME_TITLE_CHILD,
1114 XmNchildVerticalAlignment, XmALIGNMENT_CENTER,
1115 XmNchildHorizontalAlignment, XmALIGNMENT_BEGINNING,
1116 XmNlabelString, str,
1117 NULL);
1118 XmStringFree(str);
1119 apply_fontlist(name);
1120
1121 n = 0;
1122 XtSetArg(args[n], XmNvisibleItemCount, 8); ++n;
1123 XtSetArg(args[n], XmNresizable, True); ++n;
1124 XtSetArg(args[n], XmNlistSizePolicy, XmCONSTANT); ++n;
1125 XtSetArg(args[n], XmNvisualPolicy, XmVARIABLE); ++n;
1126#ifdef LESSTIF_VERSION
1127 XtSetArg(args[n], XmNscrollBarDisplayPolicy, XmSTATIC); ++n;
1128#endif
1129 data->list[STYLE] = XmCreateScrolledList(frame, "styleList", args, n);
1130 XtVaSetValues(name, XmNuserData, data->list[STYLE], NULL);
1131
Bram Moolenaar734a8672019-12-02 22:49:38 +01001132 // size list
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001133 frame = XtVaCreateManagedWidget("frame", xmFrameWidgetClass, sub_form,
1134 XmNshadowThickness, 0,
1135 XmNtopAttachment, XmATTACH_FORM,
1136 XmNbottomAttachment, XmATTACH_FORM,
1137 XmNleftAttachment, XmATTACH_POSITION,
1138 XmNleftPosition, 80,
1139 XmNleftOffset, 4,
1140 XmNrightAttachment, XmATTACH_FORM,
1141 NULL);
1142
1143 str = XmStringCreateLocalized(_("Size:"));
1144 name = XtVaCreateManagedWidget("sizeListLabel", xmLabelGadgetClass, frame,
1145 XmNchildType, XmFRAME_TITLE_CHILD,
1146 XmNchildVerticalAlignment, XmALIGNMENT_CENTER,
1147 XmNchildHorizontalAlignment, XmALIGNMENT_BEGINNING,
1148 XmNlabelString, str,
1149 NULL);
1150 XmStringFree(str);
1151 apply_fontlist(name);
1152
1153 n = 0;
1154 XtSetArg(args[n], XmNvisibleItemCount, 8); ++n;
1155 XtSetArg(args[n], XmNresizable, True); ++n;
1156 XtSetArg(args[n], XmNlistSizePolicy, XmCONSTANT); ++n;
1157 XtSetArg(args[n], XmNvisualPolicy, XmVARIABLE); ++n;
1158#ifdef LESSTIF_VERSION
1159 XtSetArg(args[n], XmNscrollBarDisplayPolicy, XmSTATIC); ++n;
1160#endif
1161 data->list[SIZE] = XmCreateScrolledList(frame, "sizeList", args, n);
1162 XtVaSetValues(name, XmNuserData, data->list[SIZE], NULL);
1163
Bram Moolenaar734a8672019-12-02 22:49:38 +01001164 // update form widgets cancel button
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001165 XtVaSetValues(form, XmNcancelButton, data->cancel, NULL);
1166
1167 XtAddCallback(size_toggle, XmNvalueChangedCallback,
1168 (XtCallbackProc)stoggle_callback, (XtPointer)data);
1169 XtAddCallback(data->list[NAME], XmNbrowseSelectionCallback,
1170 (XtCallbackProc)name_callback, (XtPointer)data);
1171 XtAddCallback(data->list[STYLE], XmNbrowseSelectionCallback,
1172 (XtCallbackProc)style_callback, (XtPointer)data);
1173 XtAddCallback(data->list[SIZE], XmNbrowseSelectionCallback,
1174 (XtCallbackProc)size_callback, (XtPointer)data);
1175 XtAddCallback(data->ok, XmNactivateCallback,
1176 (XtCallbackProc)ok_callback, (XtPointer)data);
1177 XtAddCallback(data->cancel, XmNactivateCallback,
1178 (XtCallbackProc)cancel_callback, (XtPointer)data);
1179
1180 XmProcessTraversal(data->list[NAME], XmTRAVERSE_CURRENT);
1181
Bram Moolenaar734a8672019-12-02 22:49:38 +01001182 // setup tabgroups
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001183
1184 XmAddTabGroup(data->list[NAME]);
1185 XmAddTabGroup(data->list[STYLE]);
1186 XmAddTabGroup(data->list[SIZE]);
1187 XmAddTabGroup(size_toggle);
1188 XmAddTabGroup(data->name);
1189 XmAddTabGroup(data->ok);
1190 XmAddTabGroup(data->cancel);
1191
1192 add_cancel_action(data->dialog, (XtCallbackProc)cancel_callback, data);
1193
Bram Moolenaar734a8672019-12-02 22:49:38 +01001194 // Preset selection data.
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001195
1196 data->exit = False;
1197 data->in_pixels= True;
1198 data->sel[ENCODING] = NULL;
1199 data->sel[NAME] = NULL;
1200 data->sel[STYLE] = NULL;
1201 data->sel[SIZE] = NULL;
1202 data->font_name = NULL;
1203
Bram Moolenaar734a8672019-12-02 22:49:38 +01001204 // set up current font parameters
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001205 if (current && current[0] != '\0')
1206 {
1207 int i;
1208 char **names;
1209
1210 names = XListFonts(XtDisplay(form), (char *) current, 1, &i);
1211
1212 if (i != 0)
1213 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00001214 char namebuf[TEMP_BUF_SIZE];
1215 char stylebuf[TEMP_BUF_SIZE];
1216 char sizebuf[TEMP_BUF_SIZE];
1217 char encodingbuf[TEMP_BUF_SIZE];
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001218 char *found;
1219
1220 found = names[0];
1221
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00001222 name_part(found, namebuf);
1223 style_part(found, stylebuf);
1224 size_part(found, sizebuf, data->in_pixels);
1225 encoding_part(found, encodingbuf);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001226
Bram Moolenaar64404472010-06-26 06:24:45 +02001227 if (*namebuf != NUL
1228 && *stylebuf != NUL
1229 && *sizebuf != NUL
1230 && *encodingbuf != NUL)
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001231 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00001232 data->sel[NAME] = XtNewString(namebuf);
1233 data->sel[STYLE] = XtNewString(stylebuf);
1234 data->sel[SIZE] = XtNewString(sizebuf);
1235 data->sel[ENCODING] = XtNewString(encodingbuf);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001236 data->font_name = XtNewString(names[0]);
1237 display_sample(data);
1238 XmTextSetString(data->name, data->font_name);
1239 }
1240 else
1241 {
Bram Moolenaar734a8672019-12-02 22:49:38 +01001242 // We can't preset a symbolic name, which isn't a full font
1243 // description. Therefore we just behave the same way as if the
1244 // user didn't have selected anything thus far.
1245 //
1246 // Unfortunately there is no known way to expand an abbreviated
1247 // font name.
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001248 data->font_name = NULL;
1249 }
1250 }
1251 XFreeFontNames(names);
1252 }
1253
1254 fill_lists(NONE, data);
1255
Bram Moolenaar734a8672019-12-02 22:49:38 +01001256 // Unfortunately LessTif doesn't align the list widget's properly. I don't
1257 // have currently any idea how to fix this problem.
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001258 XtManageChild(data->list[NAME]);
1259 XtManageChild(data->list[STYLE]);
1260 XtManageChild(data->list[SIZE]);
1261 XtManageChild(data->encoding_menu);
1262 manage_centered(form);
1263
Bram Moolenaar734a8672019-12-02 22:49:38 +01001264 // modal event loop
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001265 while (!data->exit)
1266 XtAppProcessEvent(XtWidgetToApplicationContext(data->dialog),
1267 (XtInputMask)XtIMAll);
1268
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001269 if (data->old)
1270 {
1271 XFreeFont(XtDisplay(data->dialog), data->old);
1272 XmFontListFree(data->old_list);
1273 }
Bram Moolenaar088598d2009-12-16 17:49:39 +00001274 XtDestroyWidget(data->dialog);
Bram Moolenaardfccaf02004-12-31 20:56:11 +00001275
1276 gui_motif_synch_fonts();
1277
1278 return (char_u *) data->font_name;
1279}