428
|
1 /* Implements elisp-programmable dialog boxes -- MS Windows interface.
|
|
2 Copyright (C) 1998 Kirill M. Katsnelson <kkm@kis.ru>
|
771
|
3 Copyright (C) 2000, 2001, 2002 Ben Wing.
|
428
|
4
|
|
5 This file is part of XEmacs.
|
|
6
|
|
7 XEmacs is free software; you can redistribute it and/or modify it
|
|
8 under the terms of the GNU General Public License as published by the
|
|
9 Free Software Foundation; either version 2, or (at your option) any
|
|
10 later version.
|
|
11
|
|
12 XEmacs is distributed in the hope that it will be useful, but WITHOUT
|
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
15 for more details.
|
|
16
|
|
17 You should have received a copy of the GNU General Public License
|
|
18 along with XEmacs; see the file COPYING. If not, write to
|
|
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
20 Boston, MA 02111-1307, USA. */
|
|
21
|
|
22 /* Synched up with: Not in FSF. */
|
|
23
|
771
|
24 /* This file essentially Mule-ized (except perhaps some Unicode splitting).
|
|
25 5-2000. */
|
|
26
|
428
|
27 /* Author:
|
|
28 Initially written by kkm, May 1998
|
|
29 */
|
|
30
|
|
31 #include <config.h>
|
|
32 #include "lisp.h"
|
|
33
|
|
34 #include "buffer.h"
|
|
35 #include "console-msw.h"
|
|
36 #include "frame.h"
|
|
37 #include "gui.h"
|
|
38 #include "opaque.h"
|
|
39
|
771
|
40 #include "sysfile.h"
|
442
|
41
|
|
42 Lisp_Object Qdialog_box_error;
|
|
43
|
|
44 static Lisp_Object Q_initial_directory;
|
|
45 static Lisp_Object Q_initial_filename;
|
|
46 static Lisp_Object Q_filter_list;
|
|
47 static Lisp_Object Q_allow_multi_select;
|
|
48 static Lisp_Object Q_create_prompt_on_nonexistent;
|
|
49 static Lisp_Object Q_overwrite_prompt;
|
|
50 static Lisp_Object Q_file_must_exist;
|
|
51 static Lisp_Object Q_no_network_button;
|
|
52 static Lisp_Object Q_no_read_only_return;
|
|
53
|
428
|
54 /* List containing all dialog data structures of currently popped up
|
442
|
55 dialogs. */
|
428
|
56 static Lisp_Object Vdialog_data_list;
|
|
57
|
442
|
58 /* List of popup frames wanting keyboard traversal handled */
|
|
59 static Lisp_Object Vpopup_frame_list;
|
|
60
|
|
61 Lisp_Object Vdefault_file_dialog_filter_alist;
|
|
62
|
428
|
63 /* DLUs per character metrics */
|
|
64 #define X_DLU_PER_CHAR 4
|
|
65 #define Y_DLU_PER_CHAR 8
|
|
66
|
|
67 /*
|
|
68 Button metrics
|
|
69 --------------
|
|
70 All buttons have height of 15 DLU. The minimum width for a button is 32 DLU,
|
|
71 but it can be expanded to accommodate its text, so the width is calculated as
|
|
72 8 DLU per button plus 4 DLU per character.
|
|
73 max (32, 6 * text_length). The factor of six is rather empirical, but it
|
|
74 works better than 8 which comes from the definition of a DLU. Buttons are
|
|
75 spaced with 6 DLU gap. Minimum distance from the button to the left or right
|
|
76 dialog edges is 6 DLU, and the distance between the dialog bottom edge and
|
|
77 buttons is 7 DLU.
|
|
78 */
|
|
79
|
|
80 #define X_MIN_BUTTON 32
|
|
81 #define X_BUTTON_MARGIN 8
|
|
82 #define Y_BUTTON 15
|
|
83 #define X_BUTTON_SPACING 6
|
|
84 #define X_BUTTON_FROM_EDGE 6
|
|
85 #define Y_BUTTON_FROM_EDGE 7
|
|
86
|
|
87 /*
|
|
88 Text field metrics
|
|
89 ------------------
|
|
90 Text distance from left and right edges is the same as for buttons, and the
|
|
91 top margin is 11 DLU. The static control has height of 2 DLU per control
|
|
92 plus 8 DLU per each line of text. Distance between the bottom edge of the
|
|
93 control and the button row is 15 DLU. Minimum width of the static control
|
|
94 is 100 DLU, thus giving minimum dialog weight of 112 DLU. Maximum width is
|
|
95 300 DLU, and, if the text is wider than that, the text is wrapped on the
|
|
96 next line. Each character in the text is considered 4 DLU wide.
|
|
97 */
|
|
98
|
|
99 #define X_MIN_TEXT 100
|
|
100 #define X_AVE_TEXT 200
|
|
101 #define X_MAX_TEXT 300
|
|
102 #define X_TEXT_FROM_EDGE X_BUTTON_FROM_EDGE
|
|
103 #define Y_TEXT_FROM_EDGE 11
|
|
104 #define Y_TEXT_MARGIN 2
|
|
105 #define Y_TEXT_FROM_BUTTON 15
|
|
106
|
|
107 #define X_MIN_TEXT_CHAR (X_MIN_TEXT / X_DLU_PER_CHAR)
|
|
108 #define X_AVE_TEXT_CHAR (X_AVE_TEXT / X_DLU_PER_CHAR)
|
|
109 #define X_MAX_TEXT_CHAR (X_MAX_TEXT / X_DLU_PER_CHAR)
|
|
110
|
|
111 /*
|
|
112 Layout algorithm
|
|
113 ----------------
|
|
114 First we calculate the minimum width of the button row, excluding "from
|
|
115 edge" distances. Note that the static control text can be narrower than
|
|
116 X_AVE_TEXT only if both text and button row are narrower than that (so,
|
|
117 even if text *can* be wrapped into 2 rows narrower than ave width, it is not
|
|
118 done). Let WBR denote the width of the button row.
|
|
119
|
|
120 Next, the width of the static field is determined.
|
|
121 First, if all lines of text fit into max (WBR, X_MAX_TEXT), the width of the
|
|
122 control is the same as the width of the longest line.
|
|
123 Second, if all lines of text are narrower than X_MIN_TEXT, then width of
|
|
124 the control is set to X_MIN_TEXT.
|
|
125 Otherwise, width is set to max(WBR, X_AVE_TEXT). In this case, line wrapping will
|
|
126 happen.
|
|
127
|
|
128 If width of the text control is larger than that of the button row, then the
|
|
129 latter is centered across the dialog, by giving it extra edge
|
|
130 margins. Otherwise, minimal margins are given to the button row.
|
|
131 */
|
|
132
|
|
133 #define ID_ITEM_BIAS 32
|
|
134
|
442
|
135 void
|
|
136 mswindows_register_popup_frame (Lisp_Object frame)
|
|
137 {
|
|
138 Vpopup_frame_list = Fcons (frame, Vpopup_frame_list);
|
|
139 }
|
|
140
|
|
141 void
|
|
142 mswindows_unregister_popup_frame (Lisp_Object frame)
|
|
143 {
|
|
144 Vpopup_frame_list = delq_no_quit (frame, Vpopup_frame_list);
|
|
145 }
|
|
146
|
|
147 /* Dispatch message to any dialog boxes. Return non-zero if dispatched. */
|
|
148 int
|
|
149 mswindows_is_dialog_msg (MSG *msg)
|
|
150 {
|
|
151 LIST_LOOP_2 (data, Vdialog_data_list)
|
|
152 {
|
771
|
153 if (qxeIsDialogMessage (XMSWINDOWS_DIALOG_ID (data)->hwnd, msg))
|
442
|
154 return 1;
|
|
155 }
|
|
156
|
|
157 {
|
|
158 LIST_LOOP_2 (popup, Vpopup_frame_list)
|
|
159 {
|
|
160 HWND hwnd = FRAME_MSWINDOWS_HANDLE (XFRAME (popup));
|
444
|
161 /* This is a windows feature that allows dialog type
|
|
162 processing to be applied to standard windows containing
|
|
163 controls. */
|
771
|
164 if (qxeIsDialogMessage (hwnd, msg))
|
442
|
165 return 1;
|
|
166 }
|
|
167 }
|
|
168 return 0;
|
|
169 }
|
|
170
|
|
171 static Lisp_Object
|
|
172 mark_mswindows_dialog_id (Lisp_Object obj)
|
|
173 {
|
|
174 struct mswindows_dialog_id *data = XMSWINDOWS_DIALOG_ID (obj);
|
|
175 mark_object (data->frame);
|
|
176 return data->callbacks;
|
|
177 }
|
|
178
|
|
179 DEFINE_LRECORD_IMPLEMENTATION ("mswindows-dialog-id", mswindows_dialog_id,
|
617
|
180 mark_mswindows_dialog_id,
|
|
181 internal_object_printer, 0, 0, 0, 0,
|
442
|
182 struct mswindows_dialog_id);
|
|
183
|
428
|
184 /* Dialog procedure */
|
|
185 static BOOL CALLBACK
|
|
186 dialog_proc (HWND hwnd, UINT msg, WPARAM w_param, LPARAM l_param)
|
|
187 {
|
|
188 switch (msg)
|
|
189 {
|
|
190 case WM_INITDIALOG:
|
771
|
191 qxeSetWindowLong (hwnd, DWL_USER, l_param);
|
428
|
192 break;
|
|
193
|
|
194 case WM_DESTROY:
|
|
195 {
|
|
196 Lisp_Object data;
|
826
|
197 data = VOID_TO_LISP ((void *) qxeGetWindowLong (hwnd, DWL_USER));
|
428
|
198 Vdialog_data_list = delq_no_quit (data, Vdialog_data_list);
|
|
199 }
|
|
200 break;
|
|
201
|
|
202 case WM_COMMAND:
|
|
203 {
|
|
204 Lisp_Object fn, arg, data;
|
442
|
205 struct mswindows_dialog_id *did;
|
|
206
|
826
|
207 data = VOID_TO_LISP ((void *) qxeGetWindowLong (hwnd, DWL_USER));
|
442
|
208 did = XMSWINDOWS_DIALOG_ID (data);
|
|
209 if (w_param != IDCANCEL) /* user pressed escape */
|
|
210 {
|
|
211 assert (w_param >= ID_ITEM_BIAS
|
647
|
212 && (EMACS_INT) w_param
|
442
|
213 < XVECTOR_LENGTH (did->callbacks) + ID_ITEM_BIAS);
|
|
214
|
|
215 get_gui_callback (XVECTOR_DATA (did->callbacks)
|
|
216 [w_param - ID_ITEM_BIAS],
|
|
217 &fn, &arg);
|
|
218 mswindows_enqueue_misc_user_event (did->frame, fn, arg);
|
|
219 }
|
|
220 else
|
|
221 mswindows_enqueue_misc_user_event (did->frame, Qrun_hooks,
|
|
222 Qmenu_no_selection_hook);
|
853
|
223 va_run_hook_with_args_trapping_problems
|
|
224 (0, Qdelete_dialog_box_hook, 1, data, 0);
|
428
|
225
|
|
226 DestroyWindow (hwnd);
|
|
227 }
|
|
228 break;
|
|
229
|
|
230 default:
|
|
231 return FALSE;
|
|
232 }
|
|
233 return TRUE;
|
|
234 }
|
|
235
|
|
236 /* Helper function which converts the supplied string STRING into Unicode and
|
|
237 pushes it at the end of DYNARR */
|
|
238 static void
|
771
|
239 push_lisp_string_as_unicode (unsigned_char_dynarr *dynarr, Lisp_Object string)
|
428
|
240 {
|
771
|
241 int length;
|
|
242 Extbyte *uni_string;
|
428
|
243
|
440
|
244 TO_EXTERNAL_FORMAT (LISP_STRING, string,
|
771
|
245 ALLOCA, (uni_string, length),
|
|
246 Qmswindows_unicode);
|
|
247 Dynarr_add_many (dynarr, uni_string, length);
|
|
248 Dynarr_add (dynarr, '\0');
|
|
249 Dynarr_add (dynarr, '\0');
|
442
|
250 }
|
|
251
|
428
|
252 /* Given button TEXT, return button width in DLU */
|
647
|
253 static int
|
428
|
254 button_width (Lisp_Object text)
|
|
255 {
|
771
|
256 /* !!#### do Japanese chars count as two? */
|
|
257 int width =
|
|
258 X_DLU_PER_CHAR *
|
867
|
259 ibyte_string_displayed_columns (XSTRING_DATA (text),
|
771
|
260 XSTRING_LENGTH (text));
|
428
|
261 return max (X_MIN_BUTTON, width);
|
|
262 }
|
|
263
|
|
264 /* Unwind protection routine frees a dynarr opaqued into arg */
|
|
265 static Lisp_Object
|
|
266 free_dynarr_opaque_ptr (Lisp_Object arg)
|
|
267 {
|
|
268 Dynarr_free (get_opaque_ptr (arg));
|
|
269 return arg;
|
|
270 }
|
|
271
|
707
|
272 /* Unwind protection decrements dialog count */
|
|
273 static Lisp_Object
|
|
274 dialog_popped_down (Lisp_Object arg)
|
|
275 {
|
|
276 popup_up_p--;
|
771
|
277 return Qnil;
|
707
|
278 }
|
|
279
|
428
|
280
|
647
|
281 #define ALIGN_TEMPLATE \
|
|
282 { \
|
|
283 int slippage = Dynarr_length (template_) & 3; \
|
|
284 if (slippage) \
|
|
285 Dynarr_add_many (template_, &zeroes, slippage); \
|
428
|
286 }
|
|
287
|
442
|
288 static struct
|
|
289 {
|
647
|
290 DWORD errmess;
|
771
|
291 Char_ASCII *errname;
|
442
|
292 } common_dialog_errors[] =
|
|
293 {
|
|
294 { CDERR_DIALOGFAILURE, "CDERR_DIALOGFAILURE" },
|
|
295 { CDERR_FINDRESFAILURE, "CDERR_FINDRESFAILURE" },
|
|
296 { CDERR_INITIALIZATION, "CDERR_INITIALIZATION" },
|
|
297 { CDERR_LOADRESFAILURE, "CDERR_LOADRESFAILURE" },
|
|
298 { CDERR_LOADSTRFAILURE, "CDERR_LOADSTRFAILURE" },
|
|
299 { CDERR_LOCKRESFAILURE, "CDERR_LOCKRESFAILURE" },
|
|
300 { CDERR_MEMALLOCFAILURE, "CDERR_MEMALLOCFAILURE" },
|
|
301 { CDERR_MEMLOCKFAILURE, "CDERR_MEMLOCKFAILURE" },
|
|
302 { CDERR_NOHINSTANCE, "CDERR_NOHINSTANCE" },
|
|
303 { CDERR_NOHOOK, "CDERR_NOHOOK" },
|
|
304 { CDERR_NOTEMPLATE, "CDERR_NOTEMPLATE" },
|
|
305 { CDERR_REGISTERMSGFAIL, "CDERR_REGISTERMSGFAIL" },
|
|
306 { CDERR_STRUCTSIZE, "CDERR_STRUCTSIZE" },
|
|
307 { PDERR_CREATEICFAILURE, "PDERR_CREATEICFAILURE" },
|
|
308 { PDERR_DEFAULTDIFFERENT, "PDERR_DEFAULTDIFFERENT" },
|
|
309 { PDERR_DNDMMISMATCH, "PDERR_DNDMMISMATCH" },
|
|
310 { PDERR_GETDEVMODEFAIL, "PDERR_GETDEVMODEFAIL" },
|
|
311 { PDERR_INITFAILURE, "PDERR_INITFAILURE" },
|
|
312 { PDERR_LOADDRVFAILURE, "PDERR_LOADDRVFAILURE" },
|
|
313 { PDERR_NODEFAULTPRN, "PDERR_NODEFAULTPRN" },
|
|
314 { PDERR_NODEVICES, "PDERR_NODEVICES" },
|
|
315 { PDERR_PARSEFAILURE, "PDERR_PARSEFAILURE" },
|
|
316 { PDERR_PRINTERNOTFOUND, "PDERR_PRINTERNOTFOUND" },
|
|
317 { PDERR_RETDEFFAILURE, "PDERR_RETDEFFAILURE" },
|
|
318 { PDERR_SETUPFAILURE, "PDERR_SETUPFAILURE" },
|
|
319 { CFERR_MAXLESSTHANMIN, "CFERR_MAXLESSTHANMIN" },
|
|
320 { CFERR_NOFONTS, "CFERR_NOFONTS" },
|
|
321 { FNERR_BUFFERTOOSMALL, "FNERR_BUFFERTOOSMALL" },
|
|
322 { FNERR_INVALIDFILENAME, "FNERR_INVALIDFILENAME" },
|
|
323 { FNERR_SUBCLASSFAILURE, "FNERR_SUBCLASSFAILURE" },
|
|
324 { FRERR_BUFFERLENGTHZERO, "FRERR_BUFFERLENGTHZERO" },
|
|
325 };
|
|
326
|
771
|
327 struct param_data
|
|
328 {
|
|
329 Extbyte *fname;
|
|
330 Extbyte *unknown_fname;
|
673
|
331 int validate;
|
|
332 };
|
|
333
|
|
334 static int
|
|
335 CALLBACK handle_directory_proc (HWND hwnd, UINT msg,
|
|
336 LPARAM lParam, LPARAM lpData)
|
|
337 {
|
771
|
338 Extbyte szDir[MAX_PATH * MAX_XETCHAR_SIZE];
|
|
339 struct param_data *pd = (struct param_data *) lpData;
|
673
|
340
|
771
|
341 switch (msg)
|
|
342 {
|
|
343 case BFFM_INITIALIZED:
|
|
344 /* WParam is TRUE since you are passing a path.
|
|
345 It would be FALSE if you were passing a pidl. */
|
|
346 qxeSendMessage (hwnd, BFFM_SETSELECTION, TRUE, (LPARAM) pd->fname);
|
|
347 break;
|
|
348
|
|
349 case BFFM_SELCHANGED:
|
|
350 /* Set the status window to the currently selected path. */
|
|
351 if (qxeSHGetPathFromIDList ((LPITEMIDLIST) lParam, szDir))
|
|
352 qxeSendMessage (hwnd, BFFM_SETSTATUSTEXT, 0, (LPARAM) szDir);
|
|
353 break;
|
|
354
|
|
355 case BFFM_VALIDATEFAILED:
|
|
356 if (pd->validate)
|
|
357 return TRUE;
|
|
358 else
|
|
359 pd->unknown_fname = xetcsdup ((Extbyte *) lParam);
|
|
360 break;
|
|
361
|
|
362 default:
|
|
363 break;
|
673
|
364 }
|
|
365 return 0;
|
|
366 }
|
|
367
|
|
368 static Lisp_Object
|
|
369 handle_directory_dialog_box (struct frame *f, Lisp_Object keys)
|
|
370 {
|
|
371 Lisp_Object ret = Qnil;
|
771
|
372 BROWSEINFOW bi;
|
673
|
373 LPITEMIDLIST pidl;
|
|
374 LPMALLOC pMalloc;
|
|
375 struct param_data pd;
|
771
|
376
|
|
377 xzero (pd);
|
|
378 xzero (bi);
|
|
379
|
|
380 bi.lParam = (LPARAM) &pd;
|
673
|
381 bi.hwndOwner = FRAME_MSWINDOWS_HANDLE (f);
|
|
382 bi.pszDisplayName = 0;
|
|
383 bi.pidlRoot = 0;
|
771
|
384 bi.ulFlags =
|
|
385 BIF_RETURNONLYFSDIRS | BIF_STATUSTEXT | BIF_EDITBOX | BIF_NEWDIALOGSTYLE;
|
673
|
386 bi.lpfn = handle_directory_proc;
|
771
|
387
|
673
|
388 LOCAL_FILE_FORMAT_TO_TSTR (Fexpand_file_name (build_string (""), Qnil),
|
771
|
389 pd.fname);
|
|
390
|
673
|
391 {
|
|
392 EXTERNAL_PROPERTY_LIST_LOOP_3 (key, value, keys)
|
|
393 {
|
|
394 if (EQ (key, Q_title))
|
|
395 {
|
|
396 CHECK_STRING (value);
|
|
397 LISP_STRING_TO_EXTERNAL (value, bi.lpszTitle, Qmswindows_tstr);
|
|
398 }
|
|
399 else if (EQ (key, Q_initial_directory))
|
|
400 LOCAL_FILE_FORMAT_TO_TSTR (Fexpand_file_name (value, Qnil),
|
|
401 pd.fname);
|
|
402 else if (EQ (key, Q_initial_filename))
|
|
403 ; /* do nothing */
|
|
404 else if (EQ (key, Q_file_must_exist))
|
|
405 {
|
771
|
406 if (!NILP (value))
|
|
407 {
|
|
408 pd.validate = TRUE;
|
|
409 bi.ulFlags |= BIF_VALIDATE;
|
|
410 }
|
673
|
411 else
|
|
412 bi.ulFlags &= ~BIF_VALIDATE;
|
|
413 }
|
|
414 else
|
|
415 invalid_constant ("Unrecognized directory-dialog keyword", key);
|
|
416 }
|
|
417 }
|
771
|
418
|
|
419 if (SHGetMalloc (&pMalloc) == NOERROR)
|
673
|
420 {
|
771
|
421 pidl = qxeSHBrowseForFolder (&bi);
|
|
422 if (pidl)
|
|
423 {
|
|
424 Extbyte *szDir = alloca_extbytes (MAX_PATH * MAX_XETCHAR_SIZE);
|
|
425
|
|
426 if (qxeSHGetPathFromIDList (pidl, szDir))
|
|
427 ret = tstr_to_local_file_format (szDir);
|
|
428
|
|
429 XECOMCALL1 (pMalloc, Free, pidl);
|
|
430 XECOMCALL0 (pMalloc, Release);
|
|
431 return ret;
|
673
|
432 }
|
771
|
433 else if (pd.unknown_fname != 0)
|
|
434 {
|
|
435 ret = tstr_to_local_file_format (pd.unknown_fname);
|
|
436 xfree (pd.unknown_fname);
|
|
437 }
|
707
|
438 else while (1)
|
|
439 signal_quit ();
|
673
|
440 }
|
|
441 else
|
|
442 signal_error (Qdialog_box_error,
|
|
443 "Unable to create folder browser",
|
|
444 make_int (0));
|
|
445 return ret;
|
|
446 }
|
|
447
|
442
|
448 static Lisp_Object
|
|
449 handle_file_dialog_box (struct frame *f, Lisp_Object keys)
|
|
450 {
|
771
|
451 OPENFILENAMEW ofn;
|
|
452 Extbyte fnbuf[8000];
|
673
|
453
|
442
|
454 xzero (ofn);
|
|
455 ofn.lStructSize = sizeof (ofn);
|
673
|
456 ofn.Flags = OFN_EXPLORER;
|
442
|
457 ofn.hwndOwner = FRAME_MSWINDOWS_HANDLE (f);
|
771
|
458 ofn.lpstrFile = (XELPTSTR) fnbuf;
|
442
|
459 ofn.nMaxFile = sizeof (fnbuf) / XETCHAR_SIZE;
|
|
460 xetcscpy (fnbuf, XETEXT (""));
|
771
|
461
|
442
|
462 LOCAL_FILE_FORMAT_TO_TSTR (Fexpand_file_name (build_string (""), Qnil),
|
|
463 ofn.lpstrInitialDir);
|
771
|
464
|
442
|
465 {
|
|
466 EXTERNAL_PROPERTY_LIST_LOOP_3 (key, value, keys)
|
|
467 {
|
|
468 if (EQ (key, Q_initial_filename))
|
|
469 {
|
|
470 Extbyte *fnout;
|
771
|
471
|
442
|
472 CHECK_STRING (value);
|
|
473 LOCAL_FILE_FORMAT_TO_TSTR (value, fnout);
|
|
474 xetcscpy (fnbuf, fnout);
|
|
475 }
|
|
476 else if (EQ (key, Q_title))
|
|
477 {
|
|
478 CHECK_STRING (value);
|
771
|
479 LISP_STRING_TO_TSTR (value, ofn.lpstrTitle);
|
442
|
480 }
|
|
481 else if (EQ (key, Q_initial_directory))
|
|
482 LOCAL_FILE_FORMAT_TO_TSTR (Fexpand_file_name (value, Qnil),
|
|
483 ofn.lpstrInitialDir);
|
|
484 else if (EQ (key, Q_file_must_exist))
|
|
485 {
|
|
486 if (!NILP (value))
|
|
487 ofn.Flags |= OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST;
|
|
488 else
|
|
489 ofn.Flags &= ~(OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST);
|
|
490 }
|
|
491 else
|
563
|
492 invalid_constant ("Unrecognized file-dialog keyword", key);
|
442
|
493 }
|
|
494 }
|
771
|
495
|
|
496 if (!qxeGetOpenFileName (&ofn))
|
442
|
497 {
|
|
498 DWORD err = CommDlgExtendedError ();
|
|
499 if (!err)
|
|
500 {
|
|
501 while (1)
|
|
502 signal_quit ();
|
|
503 }
|
|
504 else
|
|
505 {
|
|
506 int i;
|
771
|
507
|
442
|
508 for (i = 0; i < countof (common_dialog_errors); i++)
|
|
509 {
|
|
510 if (common_dialog_errors[i].errmess == err)
|
563
|
511 signal_error (Qdialog_box_error,
|
|
512 "Creating file-dialog-box",
|
771
|
513 build_msg_string
|
563
|
514 (common_dialog_errors[i].errname));
|
442
|
515 }
|
771
|
516
|
563
|
517 signal_error (Qdialog_box_error,
|
|
518 "Unknown common dialog box error???",
|
|
519 make_int (err));
|
442
|
520 }
|
|
521 }
|
771
|
522
|
|
523 return tstr_to_local_file_format ((Extbyte *) ofn.lpstrFile);
|
442
|
524 }
|
|
525
|
|
526 static Lisp_Object
|
|
527 handle_question_dialog_box (struct frame *f, Lisp_Object keys)
|
428
|
528 {
|
|
529 Lisp_Object_dynarr *dialog_items = Dynarr_new (Lisp_Object);
|
593
|
530 unsigned_char_dynarr *template_ = Dynarr_new (unsigned_char);
|
647
|
531 int button_row_width = 0;
|
|
532 int text_width, text_height;
|
442
|
533 Lisp_Object question = Qnil, title = Qnil;
|
771
|
534
|
428
|
535 int unbind_count = specpdl_depth ();
|
|
536 record_unwind_protect (free_dynarr_opaque_ptr,
|
|
537 make_opaque_ptr (dialog_items));
|
|
538 record_unwind_protect (free_dynarr_opaque_ptr,
|
593
|
539 make_opaque_ptr (template_));
|
771
|
540
|
428
|
541 /* A big NO NEED to GCPRO gui_items stored in the array: they are just
|
442
|
542 pointers into KEYS list, which is GC-protected by the caller */
|
771
|
543
|
428
|
544 {
|
442
|
545 EXTERNAL_PROPERTY_LIST_LOOP_3 (key, value, keys)
|
428
|
546 {
|
442
|
547 if (EQ (key, Q_question))
|
|
548 {
|
|
549 CHECK_STRING (value);
|
|
550 question = value;
|
|
551 }
|
|
552 else if (EQ (key, Q_title))
|
|
553 {
|
|
554 CHECK_STRING (value);
|
|
555 title = value;
|
|
556 }
|
|
557 else if (EQ (key, Q_buttons))
|
428
|
558 {
|
442
|
559 Lisp_Object item_cons;
|
771
|
560
|
442
|
561 /* Parse each item in the dialog into gui_item structs,
|
|
562 and stuff a dynarr of these. Calculate button row width
|
|
563 in this loop too */
|
|
564 EXTERNAL_LIST_LOOP (item_cons, value)
|
|
565 {
|
|
566 if (!NILP (XCAR (item_cons)))
|
|
567 {
|
|
568 Lisp_Object gitem =
|
|
569 gui_parse_item_keywords (XCAR (item_cons));
|
|
570 Dynarr_add (dialog_items, gitem);
|
|
571 button_row_width += button_width (XGUI_ITEM (gitem)->name)
|
|
572 + X_BUTTON_MARGIN;
|
|
573 }
|
|
574 }
|
771
|
575
|
442
|
576 button_row_width -= X_BUTTON_MARGIN;
|
428
|
577 }
|
442
|
578 else
|
563
|
579 invalid_constant ("Unrecognized question-dialog keyword", key);
|
428
|
580 }
|
|
581 }
|
771
|
582
|
442
|
583 if (Dynarr_length (dialog_items) == 0)
|
563
|
584 sferror ("Dialog descriptor provides no buttons", keys);
|
771
|
585
|
442
|
586 if (NILP (question))
|
563
|
587 sferror ("Dialog descriptor provides no question", keys);
|
771
|
588
|
428
|
589 /* Determine the final width layout */
|
|
590 {
|
867
|
591 Ibyte *p = XSTRING_DATA (question);
|
428
|
592 Charcount string_max = 0, this_length = 0;
|
|
593 while (1)
|
|
594 {
|
867
|
595 Ichar ch = itext_ichar (p);
|
|
596 INC_IBYTEPTR (p);
|
428
|
597
|
867
|
598 if (ch == (Ichar)'\n' || ch == (Ichar)'\0')
|
428
|
599 {
|
|
600 string_max = max (this_length, string_max);
|
|
601 this_length = 0;
|
|
602 }
|
|
603 else
|
|
604 ++this_length;
|
771
|
605
|
867
|
606 if (ch == (Ichar)'\0')
|
428
|
607 break;
|
|
608 }
|
771
|
609
|
428
|
610 if (string_max * X_DLU_PER_CHAR > max (X_MAX_TEXT, button_row_width))
|
|
611 text_width = X_AVE_TEXT;
|
|
612 else if (string_max * X_DLU_PER_CHAR < X_MIN_TEXT)
|
|
613 text_width = X_MIN_TEXT;
|
|
614 else
|
|
615 text_width = string_max * X_DLU_PER_CHAR;
|
|
616 text_width = max (text_width, button_row_width);
|
|
617 }
|
|
618
|
|
619 /* Now calculate the height for the text control */
|
|
620 {
|
867
|
621 Ibyte *p = XSTRING_DATA (question);
|
428
|
622 Charcount break_at = text_width / X_DLU_PER_CHAR;
|
|
623 Charcount char_pos = 0;
|
|
624 int num_lines = 1;
|
867
|
625 Ichar ch;
|
428
|
626
|
867
|
627 while ((ch = itext_ichar (p)) != (Ichar) '\0')
|
428
|
628 {
|
867
|
629 INC_IBYTEPTR (p);
|
|
630 char_pos += ch != (Ichar) '\n';
|
|
631 if (ch == (Ichar) '\n' || char_pos == break_at)
|
428
|
632 {
|
|
633 ++num_lines;
|
|
634 char_pos = 0;
|
|
635 }
|
|
636 }
|
|
637 text_height = Y_TEXT_MARGIN + Y_DLU_PER_CHAR * num_lines;
|
|
638 }
|
771
|
639
|
428
|
640 /* Ok, now we are ready to stuff the dialog template and lay out controls */
|
|
641 {
|
|
642 DLGTEMPLATE dlg_tem;
|
|
643 DLGITEMTEMPLATE item_tem;
|
|
644 int i;
|
|
645 const unsigned int zeroes = 0;
|
|
646 const unsigned int ones = 0xFFFFFFFF;
|
|
647 const WORD static_class_id = 0x0082;
|
|
648 const WORD button_class_id = 0x0080;
|
771
|
649
|
428
|
650 /* Create and stuff in DLGTEMPLATE header */
|
771
|
651 dlg_tem.style = (DS_CENTER | DS_MODALFRAME
|
428
|
652 | WS_CAPTION | WS_POPUP | WS_VISIBLE);
|
|
653 dlg_tem.dwExtendedStyle = 0;
|
|
654 dlg_tem.cdit = Dynarr_length (dialog_items) + 1;
|
|
655 dlg_tem.x = 0;
|
|
656 dlg_tem.y = 0;
|
|
657 dlg_tem.cx = text_width + 2 * X_TEXT_FROM_EDGE;
|
|
658 dlg_tem.cy = (Y_TEXT_FROM_EDGE + text_height + Y_TEXT_FROM_BUTTON
|
|
659 + Y_BUTTON + Y_BUTTON_FROM_EDGE);
|
593
|
660 Dynarr_add_many (template_, &dlg_tem, sizeof (dlg_tem));
|
771
|
661
|
428
|
662 /* We want no menu and standard class */
|
593
|
663 Dynarr_add_many (template_, &zeroes, 4);
|
771
|
664
|
442
|
665 /* And the third is the dialog title. "XEmacs" unless one is supplied.
|
|
666 Note that the string must be in Unicode. */
|
|
667 if (NILP (title))
|
593
|
668 Dynarr_add_many (template_, L"XEmacs", 14);
|
442
|
669 else
|
593
|
670 push_lisp_string_as_unicode (template_, title);
|
771
|
671
|
428
|
672 /* Next add text control. */
|
|
673 item_tem.style = WS_CHILD | WS_VISIBLE | SS_LEFT | SS_NOPREFIX;
|
|
674 item_tem.dwExtendedStyle = 0;
|
|
675 item_tem.x = X_TEXT_FROM_EDGE;
|
|
676 item_tem.y = Y_TEXT_FROM_EDGE;
|
|
677 item_tem.cx = text_width;
|
|
678 item_tem.cy = text_height;
|
|
679 item_tem.id = 0xFFFF;
|
771
|
680
|
428
|
681 ALIGN_TEMPLATE;
|
593
|
682 Dynarr_add_many (template_, &item_tem, sizeof (item_tem));
|
771
|
683
|
428
|
684 /* Right after class id follows */
|
593
|
685 Dynarr_add_many (template_, &ones, 2);
|
|
686 Dynarr_add_many (template_, &static_class_id, sizeof (static_class_id));
|
771
|
687
|
428
|
688 /* Next thing to add is control text, as Unicode string */
|
593
|
689 push_lisp_string_as_unicode (template_, question);
|
771
|
690
|
428
|
691 /* Specify 0 length creation data */
|
593
|
692 Dynarr_add_many (template_, &zeroes, 2);
|
771
|
693
|
428
|
694 /* Now it's the button time */
|
|
695 item_tem.y = Y_TEXT_FROM_EDGE + text_height + Y_TEXT_FROM_BUTTON;
|
|
696 item_tem.x = X_BUTTON_FROM_EDGE + (button_row_width < text_width
|
|
697 ? (text_width - button_row_width) / 2
|
|
698 : 0);
|
|
699 item_tem.cy = Y_BUTTON;
|
|
700 item_tem.dwExtendedStyle = 0;
|
771
|
701
|
428
|
702 for (i = 0; i < Dynarr_length (dialog_items); ++i)
|
|
703 {
|
771
|
704 Lisp_Object *gui_item = Dynarr_atp (dialog_items, i);
|
440
|
705 Lisp_Gui_Item *pgui_item = XGUI_ITEM (*gui_item);
|
771
|
706
|
428
|
707 item_tem.style = (WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_PUSHBUTTON
|
|
708 | (gui_item_active_p (*gui_item) ? 0 : WS_DISABLED));
|
|
709 item_tem.cx = button_width (pgui_item->name);
|
|
710 /* Item ids are indices into dialog_items plus offset, to avoid having
|
|
711 items by reserved ids (IDOK, IDCANCEL) */
|
|
712 item_tem.id = i + ID_ITEM_BIAS;
|
771
|
713
|
428
|
714 ALIGN_TEMPLATE;
|
593
|
715 Dynarr_add_many (template_, &item_tem, sizeof (item_tem));
|
771
|
716
|
428
|
717 /* Right after 0xFFFF and class id atom follows */
|
593
|
718 Dynarr_add_many (template_, &ones, 2);
|
|
719 Dynarr_add_many (template_, &button_class_id,
|
|
720 sizeof (button_class_id));
|
771
|
721
|
428
|
722 /* Next thing to add is control text, as Unicode string */
|
442
|
723 {
|
867
|
724 Ichar accel_unused;
|
771
|
725
|
|
726 push_lisp_string_as_unicode
|
|
727 (template_,
|
|
728 mswindows_translate_menu_or_dialog_item
|
|
729 (pgui_item->name, &accel_unused));
|
442
|
730 }
|
771
|
731
|
428
|
732 /* Specify 0 length creation data. */
|
593
|
733 Dynarr_add_many (template_, &zeroes, 2);
|
771
|
734
|
428
|
735 item_tem.x += item_tem.cx + X_BUTTON_SPACING;
|
|
736 }
|
|
737 }
|
771
|
738
|
428
|
739 /* Now the Windows dialog structure is ready. We need to prepare a
|
|
740 data structure for the new dialog, which will contain callbacks
|
442
|
741 and the frame for these callbacks. This structure has to be
|
|
742 GC-protected and thus it is put into a statically protected
|
|
743 list. */
|
428
|
744 {
|
442
|
745 Lisp_Object dialog_data;
|
428
|
746 int i;
|
442
|
747 struct mswindows_dialog_id *did =
|
|
748 alloc_lcrecord_type (struct mswindows_dialog_id,
|
|
749 &lrecord_mswindows_dialog_id);
|
771
|
750
|
793
|
751 dialog_data = wrap_mswindows_dialog_id (did);
|
771
|
752
|
442
|
753 did->frame = wrap_frame (f);
|
|
754 did->callbacks = make_vector (Dynarr_length (dialog_items), Qunbound);
|
|
755 for (i = 0; i < Dynarr_length (dialog_items); i++)
|
|
756 XVECTOR_DATA (did->callbacks) [i] =
|
|
757 XGUI_ITEM (*Dynarr_atp (dialog_items, i))->callback;
|
428
|
758
|
|
759 /* Woof! Everything is ready. Pop pop pop in now! */
|
442
|
760 did->hwnd =
|
771
|
761 qxeCreateDialogIndirectParam (NULL,
|
|
762 (LPDLGTEMPLATE) Dynarr_atp (template_, 0),
|
|
763 FRAME_MSWINDOWS_HANDLE (f), dialog_proc,
|
|
764 (LPARAM) LISP_TO_VOID (dialog_data));
|
442
|
765 if (!did->hwnd)
|
428
|
766 /* Something went wrong creating the dialog */
|
563
|
767 signal_error (Qdialog_box_error, "Creating dialog", keys);
|
771
|
768
|
428
|
769 Vdialog_data_list = Fcons (dialog_data, Vdialog_data_list);
|
771
|
770
|
442
|
771 /* Cease protection and free dynarrays */
|
771
|
772 unbind_to (unbind_count);
|
442
|
773 return dialog_data;
|
428
|
774 }
|
442
|
775 }
|
428
|
776
|
442
|
777 static Lisp_Object
|
|
778 mswindows_make_dialog_box_internal (struct frame* f, Lisp_Object type,
|
|
779 Lisp_Object keys)
|
|
780 {
|
707
|
781 int unbind_count = specpdl_depth ();
|
|
782 record_unwind_protect (dialog_popped_down, Qnil);
|
|
783 popup_up_p++;
|
819
|
784
|
442
|
785 if (EQ (type, Qfile))
|
771
|
786 return unbind_to_1 (unbind_count, handle_file_dialog_box (f, keys));
|
673
|
787 else if (EQ (type, Qdirectory))
|
771
|
788 return unbind_to_1 (unbind_count, handle_directory_dialog_box (f, keys));
|
442
|
789 else if (EQ (type, Qquestion))
|
771
|
790 return unbind_to_1 (unbind_count, handle_question_dialog_box (f, keys));
|
442
|
791 else if (EQ (type, Qprint))
|
771
|
792 return unbind_to_1 (unbind_count,
|
|
793 mswindows_handle_print_dialog_box (f, keys));
|
442
|
794 else if (EQ (type, Qpage_setup))
|
771
|
795 return unbind_to_1 (unbind_count,
|
|
796 mswindows_handle_page_setup_dialog_box (f, keys));
|
442
|
797 else
|
563
|
798 signal_error (Qunimplemented, "Dialog box type", type);
|
442
|
799 return Qnil;
|
428
|
800 }
|
|
801
|
|
802 void
|
|
803 console_type_create_dialog_mswindows (void)
|
|
804 {
|
442
|
805 CONSOLE_HAS_METHOD (mswindows, make_dialog_box_internal);
|
|
806 }
|
|
807
|
|
808 void
|
|
809 syms_of_dialog_mswindows (void)
|
|
810 {
|
|
811 INIT_LRECORD_IMPLEMENTATION (mswindows_dialog_id);
|
771
|
812
|
442
|
813 DEFKEYWORD (Q_initial_directory);
|
|
814 DEFKEYWORD (Q_initial_filename);
|
|
815 DEFKEYWORD (Q_filter_list);
|
|
816 DEFKEYWORD (Q_title);
|
|
817 DEFKEYWORD (Q_allow_multi_select);
|
|
818 DEFKEYWORD (Q_create_prompt_on_nonexistent);
|
|
819 DEFKEYWORD (Q_overwrite_prompt);
|
|
820 DEFKEYWORD (Q_file_must_exist);
|
|
821 DEFKEYWORD (Q_no_network_button);
|
|
822 DEFKEYWORD (Q_no_read_only_return);
|
771
|
823
|
442
|
824 /* Errors */
|
563
|
825 DEFERROR_STANDARD (Qdialog_box_error, Qgui_error);
|
428
|
826 }
|
|
827
|
|
828 void
|
|
829 vars_of_dialog_mswindows (void)
|
|
830 {
|
442
|
831 Vpopup_frame_list = Qnil;
|
|
832 staticpro (&Vpopup_frame_list);
|
771
|
833
|
428
|
834 Vdialog_data_list = Qnil;
|
|
835 staticpro (&Vdialog_data_list);
|
771
|
836
|
442
|
837 DEFVAR_LISP ("default-file-dialog-filter-alist",
|
|
838 &Vdefault_file_dialog_filter_alist /*
|
771
|
839 */ );
|
442
|
840 Vdefault_file_dialog_filter_alist =
|
771
|
841 list5 (Fcons (build_msg_string ("Text Files"), build_string ("*.txt")),
|
|
842 Fcons (build_msg_string ("C Files"), build_string ("*.c;*.h")),
|
|
843 Fcons (build_msg_string ("Elisp Files"), build_string ("*.el")),
|
|
844 Fcons (build_msg_string ("HTML Files"), build_string ("*.html;*.html")),
|
|
845 Fcons (build_msg_string ("All Files"), build_string ("*.*")));
|
428
|
846 }
|