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);
|
|
223 /* #### need to error-protect! will do so when i merge in
|
771
|
224 my stderr-proc ws */
|
442
|
225 va_run_hook_with_args (Qdelete_dialog_box_hook, 1, data);
|
428
|
226
|
|
227 DestroyWindow (hwnd);
|
|
228 }
|
|
229 break;
|
|
230
|
|
231 default:
|
|
232 return FALSE;
|
|
233 }
|
|
234 return TRUE;
|
|
235 }
|
|
236
|
|
237 /* Helper function which converts the supplied string STRING into Unicode and
|
|
238 pushes it at the end of DYNARR */
|
|
239 static void
|
771
|
240 push_lisp_string_as_unicode (unsigned_char_dynarr *dynarr, Lisp_Object string)
|
428
|
241 {
|
771
|
242 int length;
|
|
243 Extbyte *uni_string;
|
428
|
244
|
440
|
245 TO_EXTERNAL_FORMAT (LISP_STRING, string,
|
771
|
246 ALLOCA, (uni_string, length),
|
|
247 Qmswindows_unicode);
|
|
248 Dynarr_add_many (dynarr, uni_string, length);
|
|
249 Dynarr_add (dynarr, '\0');
|
|
250 Dynarr_add (dynarr, '\0');
|
442
|
251 }
|
|
252
|
428
|
253 /* Given button TEXT, return button width in DLU */
|
647
|
254 static int
|
428
|
255 button_width (Lisp_Object text)
|
|
256 {
|
771
|
257 /* !!#### do Japanese chars count as two? */
|
|
258 int width =
|
|
259 X_DLU_PER_CHAR *
|
|
260 intbyte_string_displayed_columns (XSTRING_DATA (text),
|
|
261 XSTRING_LENGTH (text));
|
428
|
262 return max (X_MIN_BUTTON, width);
|
|
263 }
|
|
264
|
|
265 /* Unwind protection routine frees a dynarr opaqued into arg */
|
|
266 static Lisp_Object
|
|
267 free_dynarr_opaque_ptr (Lisp_Object arg)
|
|
268 {
|
|
269 Dynarr_free (get_opaque_ptr (arg));
|
|
270 return arg;
|
|
271 }
|
|
272
|
707
|
273 /* Unwind protection decrements dialog count */
|
|
274 static Lisp_Object
|
|
275 dialog_popped_down (Lisp_Object arg)
|
|
276 {
|
|
277 popup_up_p--;
|
771
|
278 return Qnil;
|
707
|
279 }
|
|
280
|
428
|
281
|
647
|
282 #define ALIGN_TEMPLATE \
|
|
283 { \
|
|
284 int slippage = Dynarr_length (template_) & 3; \
|
|
285 if (slippage) \
|
|
286 Dynarr_add_many (template_, &zeroes, slippage); \
|
428
|
287 }
|
|
288
|
442
|
289 static struct
|
|
290 {
|
647
|
291 DWORD errmess;
|
771
|
292 Char_ASCII *errname;
|
442
|
293 } common_dialog_errors[] =
|
|
294 {
|
|
295 { CDERR_DIALOGFAILURE, "CDERR_DIALOGFAILURE" },
|
|
296 { CDERR_FINDRESFAILURE, "CDERR_FINDRESFAILURE" },
|
|
297 { CDERR_INITIALIZATION, "CDERR_INITIALIZATION" },
|
|
298 { CDERR_LOADRESFAILURE, "CDERR_LOADRESFAILURE" },
|
|
299 { CDERR_LOADSTRFAILURE, "CDERR_LOADSTRFAILURE" },
|
|
300 { CDERR_LOCKRESFAILURE, "CDERR_LOCKRESFAILURE" },
|
|
301 { CDERR_MEMALLOCFAILURE, "CDERR_MEMALLOCFAILURE" },
|
|
302 { CDERR_MEMLOCKFAILURE, "CDERR_MEMLOCKFAILURE" },
|
|
303 { CDERR_NOHINSTANCE, "CDERR_NOHINSTANCE" },
|
|
304 { CDERR_NOHOOK, "CDERR_NOHOOK" },
|
|
305 { CDERR_NOTEMPLATE, "CDERR_NOTEMPLATE" },
|
|
306 { CDERR_REGISTERMSGFAIL, "CDERR_REGISTERMSGFAIL" },
|
|
307 { CDERR_STRUCTSIZE, "CDERR_STRUCTSIZE" },
|
|
308 { PDERR_CREATEICFAILURE, "PDERR_CREATEICFAILURE" },
|
|
309 { PDERR_DEFAULTDIFFERENT, "PDERR_DEFAULTDIFFERENT" },
|
|
310 { PDERR_DNDMMISMATCH, "PDERR_DNDMMISMATCH" },
|
|
311 { PDERR_GETDEVMODEFAIL, "PDERR_GETDEVMODEFAIL" },
|
|
312 { PDERR_INITFAILURE, "PDERR_INITFAILURE" },
|
|
313 { PDERR_LOADDRVFAILURE, "PDERR_LOADDRVFAILURE" },
|
|
314 { PDERR_NODEFAULTPRN, "PDERR_NODEFAULTPRN" },
|
|
315 { PDERR_NODEVICES, "PDERR_NODEVICES" },
|
|
316 { PDERR_PARSEFAILURE, "PDERR_PARSEFAILURE" },
|
|
317 { PDERR_PRINTERNOTFOUND, "PDERR_PRINTERNOTFOUND" },
|
|
318 { PDERR_RETDEFFAILURE, "PDERR_RETDEFFAILURE" },
|
|
319 { PDERR_SETUPFAILURE, "PDERR_SETUPFAILURE" },
|
|
320 { CFERR_MAXLESSTHANMIN, "CFERR_MAXLESSTHANMIN" },
|
|
321 { CFERR_NOFONTS, "CFERR_NOFONTS" },
|
|
322 { FNERR_BUFFERTOOSMALL, "FNERR_BUFFERTOOSMALL" },
|
|
323 { FNERR_INVALIDFILENAME, "FNERR_INVALIDFILENAME" },
|
|
324 { FNERR_SUBCLASSFAILURE, "FNERR_SUBCLASSFAILURE" },
|
|
325 { FRERR_BUFFERLENGTHZERO, "FRERR_BUFFERLENGTHZERO" },
|
|
326 };
|
|
327
|
771
|
328 struct param_data
|
|
329 {
|
|
330 Extbyte *fname;
|
|
331 Extbyte *unknown_fname;
|
673
|
332 int validate;
|
|
333 };
|
|
334
|
|
335 static int
|
|
336 CALLBACK handle_directory_proc (HWND hwnd, UINT msg,
|
|
337 LPARAM lParam, LPARAM lpData)
|
|
338 {
|
771
|
339 Extbyte szDir[MAX_PATH * MAX_XETCHAR_SIZE];
|
|
340 struct param_data *pd = (struct param_data *) lpData;
|
673
|
341
|
771
|
342 switch (msg)
|
|
343 {
|
|
344 case BFFM_INITIALIZED:
|
|
345 /* WParam is TRUE since you are passing a path.
|
|
346 It would be FALSE if you were passing a pidl. */
|
|
347 qxeSendMessage (hwnd, BFFM_SETSELECTION, TRUE, (LPARAM) pd->fname);
|
|
348 break;
|
|
349
|
|
350 case BFFM_SELCHANGED:
|
|
351 /* Set the status window to the currently selected path. */
|
|
352 if (qxeSHGetPathFromIDList ((LPITEMIDLIST) lParam, szDir))
|
|
353 qxeSendMessage (hwnd, BFFM_SETSTATUSTEXT, 0, (LPARAM) szDir);
|
|
354 break;
|
|
355
|
|
356 case BFFM_VALIDATEFAILED:
|
|
357 if (pd->validate)
|
|
358 return TRUE;
|
|
359 else
|
|
360 pd->unknown_fname = xetcsdup ((Extbyte *) lParam);
|
|
361 break;
|
|
362
|
|
363 default:
|
|
364 break;
|
673
|
365 }
|
|
366 return 0;
|
|
367 }
|
|
368
|
|
369 static Lisp_Object
|
|
370 handle_directory_dialog_box (struct frame *f, Lisp_Object keys)
|
|
371 {
|
|
372 Lisp_Object ret = Qnil;
|
771
|
373 BROWSEINFOW bi;
|
673
|
374 LPITEMIDLIST pidl;
|
|
375 LPMALLOC pMalloc;
|
|
376 struct param_data pd;
|
771
|
377
|
|
378 xzero (pd);
|
|
379 xzero (bi);
|
|
380
|
|
381 bi.lParam = (LPARAM) &pd;
|
673
|
382 bi.hwndOwner = FRAME_MSWINDOWS_HANDLE (f);
|
|
383 bi.pszDisplayName = 0;
|
|
384 bi.pidlRoot = 0;
|
771
|
385 bi.ulFlags =
|
|
386 BIF_RETURNONLYFSDIRS | BIF_STATUSTEXT | BIF_EDITBOX | BIF_NEWDIALOGSTYLE;
|
673
|
387 bi.lpfn = handle_directory_proc;
|
771
|
388
|
673
|
389 LOCAL_FILE_FORMAT_TO_TSTR (Fexpand_file_name (build_string (""), Qnil),
|
771
|
390 pd.fname);
|
|
391
|
673
|
392 {
|
|
393 EXTERNAL_PROPERTY_LIST_LOOP_3 (key, value, keys)
|
|
394 {
|
|
395 if (EQ (key, Q_title))
|
|
396 {
|
|
397 CHECK_STRING (value);
|
|
398 LISP_STRING_TO_EXTERNAL (value, bi.lpszTitle, Qmswindows_tstr);
|
|
399 }
|
|
400 else if (EQ (key, Q_initial_directory))
|
|
401 LOCAL_FILE_FORMAT_TO_TSTR (Fexpand_file_name (value, Qnil),
|
|
402 pd.fname);
|
|
403 else if (EQ (key, Q_initial_filename))
|
|
404 ; /* do nothing */
|
|
405 else if (EQ (key, Q_file_must_exist))
|
|
406 {
|
771
|
407 if (!NILP (value))
|
|
408 {
|
|
409 pd.validate = TRUE;
|
|
410 bi.ulFlags |= BIF_VALIDATE;
|
|
411 }
|
673
|
412 else
|
|
413 bi.ulFlags &= ~BIF_VALIDATE;
|
|
414 }
|
|
415 else
|
|
416 invalid_constant ("Unrecognized directory-dialog keyword", key);
|
|
417 }
|
|
418 }
|
771
|
419
|
|
420 if (SHGetMalloc (&pMalloc) == NOERROR)
|
673
|
421 {
|
771
|
422 pidl = qxeSHBrowseForFolder (&bi);
|
|
423 if (pidl)
|
|
424 {
|
|
425 Extbyte *szDir = alloca_extbytes (MAX_PATH * MAX_XETCHAR_SIZE);
|
|
426
|
|
427 if (qxeSHGetPathFromIDList (pidl, szDir))
|
|
428 ret = tstr_to_local_file_format (szDir);
|
|
429
|
|
430 XECOMCALL1 (pMalloc, Free, pidl);
|
|
431 XECOMCALL0 (pMalloc, Release);
|
|
432 return ret;
|
673
|
433 }
|
771
|
434 else if (pd.unknown_fname != 0)
|
|
435 {
|
|
436 ret = tstr_to_local_file_format (pd.unknown_fname);
|
|
437 xfree (pd.unknown_fname);
|
|
438 }
|
707
|
439 else while (1)
|
|
440 signal_quit ();
|
673
|
441 }
|
|
442 else
|
|
443 signal_error (Qdialog_box_error,
|
|
444 "Unable to create folder browser",
|
|
445 make_int (0));
|
|
446 return ret;
|
|
447 }
|
|
448
|
442
|
449 static Lisp_Object
|
|
450 handle_file_dialog_box (struct frame *f, Lisp_Object keys)
|
|
451 {
|
771
|
452 OPENFILENAMEW ofn;
|
|
453 Extbyte fnbuf[8000];
|
673
|
454
|
442
|
455 xzero (ofn);
|
|
456 ofn.lStructSize = sizeof (ofn);
|
673
|
457 ofn.Flags = OFN_EXPLORER;
|
442
|
458 ofn.hwndOwner = FRAME_MSWINDOWS_HANDLE (f);
|
771
|
459 ofn.lpstrFile = (XELPTSTR) fnbuf;
|
442
|
460 ofn.nMaxFile = sizeof (fnbuf) / XETCHAR_SIZE;
|
|
461 xetcscpy (fnbuf, XETEXT (""));
|
771
|
462
|
442
|
463 LOCAL_FILE_FORMAT_TO_TSTR (Fexpand_file_name (build_string (""), Qnil),
|
|
464 ofn.lpstrInitialDir);
|
771
|
465
|
442
|
466 {
|
|
467 EXTERNAL_PROPERTY_LIST_LOOP_3 (key, value, keys)
|
|
468 {
|
|
469 if (EQ (key, Q_initial_filename))
|
|
470 {
|
|
471 Extbyte *fnout;
|
771
|
472
|
442
|
473 CHECK_STRING (value);
|
|
474 LOCAL_FILE_FORMAT_TO_TSTR (value, fnout);
|
|
475 xetcscpy (fnbuf, fnout);
|
|
476 }
|
|
477 else if (EQ (key, Q_title))
|
|
478 {
|
|
479 CHECK_STRING (value);
|
771
|
480 LISP_STRING_TO_TSTR (value, ofn.lpstrTitle);
|
442
|
481 }
|
|
482 else if (EQ (key, Q_initial_directory))
|
|
483 LOCAL_FILE_FORMAT_TO_TSTR (Fexpand_file_name (value, Qnil),
|
|
484 ofn.lpstrInitialDir);
|
|
485 else if (EQ (key, Q_file_must_exist))
|
|
486 {
|
|
487 if (!NILP (value))
|
|
488 ofn.Flags |= OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST;
|
|
489 else
|
|
490 ofn.Flags &= ~(OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST);
|
|
491 }
|
|
492 else
|
563
|
493 invalid_constant ("Unrecognized file-dialog keyword", key);
|
442
|
494 }
|
|
495 }
|
771
|
496
|
|
497 if (!qxeGetOpenFileName (&ofn))
|
442
|
498 {
|
|
499 DWORD err = CommDlgExtendedError ();
|
|
500 if (!err)
|
|
501 {
|
|
502 while (1)
|
|
503 signal_quit ();
|
|
504 }
|
|
505 else
|
|
506 {
|
|
507 int i;
|
771
|
508
|
442
|
509 for (i = 0; i < countof (common_dialog_errors); i++)
|
|
510 {
|
|
511 if (common_dialog_errors[i].errmess == err)
|
563
|
512 signal_error (Qdialog_box_error,
|
|
513 "Creating file-dialog-box",
|
771
|
514 build_msg_string
|
563
|
515 (common_dialog_errors[i].errname));
|
442
|
516 }
|
771
|
517
|
563
|
518 signal_error (Qdialog_box_error,
|
|
519 "Unknown common dialog box error???",
|
|
520 make_int (err));
|
442
|
521 }
|
|
522 }
|
771
|
523
|
|
524 return tstr_to_local_file_format ((Extbyte *) ofn.lpstrFile);
|
442
|
525 }
|
|
526
|
|
527 static Lisp_Object
|
|
528 handle_question_dialog_box (struct frame *f, Lisp_Object keys)
|
428
|
529 {
|
|
530 Lisp_Object_dynarr *dialog_items = Dynarr_new (Lisp_Object);
|
593
|
531 unsigned_char_dynarr *template_ = Dynarr_new (unsigned_char);
|
647
|
532 int button_row_width = 0;
|
|
533 int text_width, text_height;
|
442
|
534 Lisp_Object question = Qnil, title = Qnil;
|
771
|
535
|
428
|
536 int unbind_count = specpdl_depth ();
|
|
537 record_unwind_protect (free_dynarr_opaque_ptr,
|
|
538 make_opaque_ptr (dialog_items));
|
|
539 record_unwind_protect (free_dynarr_opaque_ptr,
|
593
|
540 make_opaque_ptr (template_));
|
771
|
541
|
428
|
542 /* A big NO NEED to GCPRO gui_items stored in the array: they are just
|
442
|
543 pointers into KEYS list, which is GC-protected by the caller */
|
771
|
544
|
428
|
545 {
|
442
|
546 EXTERNAL_PROPERTY_LIST_LOOP_3 (key, value, keys)
|
428
|
547 {
|
442
|
548 if (EQ (key, Q_question))
|
|
549 {
|
|
550 CHECK_STRING (value);
|
|
551 question = value;
|
|
552 }
|
|
553 else if (EQ (key, Q_title))
|
|
554 {
|
|
555 CHECK_STRING (value);
|
|
556 title = value;
|
|
557 }
|
|
558 else if (EQ (key, Q_buttons))
|
428
|
559 {
|
442
|
560 Lisp_Object item_cons;
|
771
|
561
|
442
|
562 /* Parse each item in the dialog into gui_item structs,
|
|
563 and stuff a dynarr of these. Calculate button row width
|
|
564 in this loop too */
|
|
565 EXTERNAL_LIST_LOOP (item_cons, value)
|
|
566 {
|
|
567 if (!NILP (XCAR (item_cons)))
|
|
568 {
|
|
569 Lisp_Object gitem =
|
|
570 gui_parse_item_keywords (XCAR (item_cons));
|
|
571 Dynarr_add (dialog_items, gitem);
|
|
572 button_row_width += button_width (XGUI_ITEM (gitem)->name)
|
|
573 + X_BUTTON_MARGIN;
|
|
574 }
|
|
575 }
|
771
|
576
|
442
|
577 button_row_width -= X_BUTTON_MARGIN;
|
428
|
578 }
|
442
|
579 else
|
563
|
580 invalid_constant ("Unrecognized question-dialog keyword", key);
|
428
|
581 }
|
|
582 }
|
771
|
583
|
442
|
584 if (Dynarr_length (dialog_items) == 0)
|
563
|
585 sferror ("Dialog descriptor provides no buttons", keys);
|
771
|
586
|
442
|
587 if (NILP (question))
|
563
|
588 sferror ("Dialog descriptor provides no question", keys);
|
771
|
589
|
428
|
590 /* Determine the final width layout */
|
|
591 {
|
665
|
592 Intbyte *p = XSTRING_DATA (question);
|
428
|
593 Charcount string_max = 0, this_length = 0;
|
|
594 while (1)
|
|
595 {
|
|
596 Emchar ch = charptr_emchar (p);
|
|
597 INC_CHARPTR (p);
|
|
598
|
|
599 if (ch == (Emchar)'\n' || ch == (Emchar)'\0')
|
|
600 {
|
|
601 string_max = max (this_length, string_max);
|
|
602 this_length = 0;
|
|
603 }
|
|
604 else
|
|
605 ++this_length;
|
771
|
606
|
428
|
607 if (ch == (Emchar)'\0')
|
|
608 break;
|
|
609 }
|
771
|
610
|
428
|
611 if (string_max * X_DLU_PER_CHAR > max (X_MAX_TEXT, button_row_width))
|
|
612 text_width = X_AVE_TEXT;
|
|
613 else if (string_max * X_DLU_PER_CHAR < X_MIN_TEXT)
|
|
614 text_width = X_MIN_TEXT;
|
|
615 else
|
|
616 text_width = string_max * X_DLU_PER_CHAR;
|
|
617 text_width = max (text_width, button_row_width);
|
|
618 }
|
|
619
|
|
620 /* Now calculate the height for the text control */
|
|
621 {
|
665
|
622 Intbyte *p = XSTRING_DATA (question);
|
428
|
623 Charcount break_at = text_width / X_DLU_PER_CHAR;
|
|
624 Charcount char_pos = 0;
|
|
625 int num_lines = 1;
|
|
626 Emchar ch;
|
|
627
|
442
|
628 while ((ch = charptr_emchar (p)) != (Emchar) '\0')
|
428
|
629 {
|
|
630 INC_CHARPTR (p);
|
442
|
631 char_pos += ch != (Emchar) '\n';
|
|
632 if (ch == (Emchar) '\n' || char_pos == break_at)
|
428
|
633 {
|
|
634 ++num_lines;
|
|
635 char_pos = 0;
|
|
636 }
|
|
637 }
|
|
638 text_height = Y_TEXT_MARGIN + Y_DLU_PER_CHAR * num_lines;
|
|
639 }
|
771
|
640
|
428
|
641 /* Ok, now we are ready to stuff the dialog template and lay out controls */
|
|
642 {
|
|
643 DLGTEMPLATE dlg_tem;
|
|
644 DLGITEMTEMPLATE item_tem;
|
|
645 int i;
|
|
646 const unsigned int zeroes = 0;
|
|
647 const unsigned int ones = 0xFFFFFFFF;
|
|
648 const WORD static_class_id = 0x0082;
|
|
649 const WORD button_class_id = 0x0080;
|
771
|
650
|
428
|
651 /* Create and stuff in DLGTEMPLATE header */
|
771
|
652 dlg_tem.style = (DS_CENTER | DS_MODALFRAME
|
428
|
653 | WS_CAPTION | WS_POPUP | WS_VISIBLE);
|
|
654 dlg_tem.dwExtendedStyle = 0;
|
|
655 dlg_tem.cdit = Dynarr_length (dialog_items) + 1;
|
|
656 dlg_tem.x = 0;
|
|
657 dlg_tem.y = 0;
|
|
658 dlg_tem.cx = text_width + 2 * X_TEXT_FROM_EDGE;
|
|
659 dlg_tem.cy = (Y_TEXT_FROM_EDGE + text_height + Y_TEXT_FROM_BUTTON
|
|
660 + Y_BUTTON + Y_BUTTON_FROM_EDGE);
|
593
|
661 Dynarr_add_many (template_, &dlg_tem, sizeof (dlg_tem));
|
771
|
662
|
428
|
663 /* We want no menu and standard class */
|
593
|
664 Dynarr_add_many (template_, &zeroes, 4);
|
771
|
665
|
442
|
666 /* And the third is the dialog title. "XEmacs" unless one is supplied.
|
|
667 Note that the string must be in Unicode. */
|
|
668 if (NILP (title))
|
593
|
669 Dynarr_add_many (template_, L"XEmacs", 14);
|
442
|
670 else
|
593
|
671 push_lisp_string_as_unicode (template_, title);
|
771
|
672
|
428
|
673 /* Next add text control. */
|
|
674 item_tem.style = WS_CHILD | WS_VISIBLE | SS_LEFT | SS_NOPREFIX;
|
|
675 item_tem.dwExtendedStyle = 0;
|
|
676 item_tem.x = X_TEXT_FROM_EDGE;
|
|
677 item_tem.y = Y_TEXT_FROM_EDGE;
|
|
678 item_tem.cx = text_width;
|
|
679 item_tem.cy = text_height;
|
|
680 item_tem.id = 0xFFFF;
|
771
|
681
|
428
|
682 ALIGN_TEMPLATE;
|
593
|
683 Dynarr_add_many (template_, &item_tem, sizeof (item_tem));
|
771
|
684
|
428
|
685 /* Right after class id follows */
|
593
|
686 Dynarr_add_many (template_, &ones, 2);
|
|
687 Dynarr_add_many (template_, &static_class_id, sizeof (static_class_id));
|
771
|
688
|
428
|
689 /* Next thing to add is control text, as Unicode string */
|
593
|
690 push_lisp_string_as_unicode (template_, question);
|
771
|
691
|
428
|
692 /* Specify 0 length creation data */
|
593
|
693 Dynarr_add_many (template_, &zeroes, 2);
|
771
|
694
|
428
|
695 /* Now it's the button time */
|
|
696 item_tem.y = Y_TEXT_FROM_EDGE + text_height + Y_TEXT_FROM_BUTTON;
|
|
697 item_tem.x = X_BUTTON_FROM_EDGE + (button_row_width < text_width
|
|
698 ? (text_width - button_row_width) / 2
|
|
699 : 0);
|
|
700 item_tem.cy = Y_BUTTON;
|
|
701 item_tem.dwExtendedStyle = 0;
|
771
|
702
|
428
|
703 for (i = 0; i < Dynarr_length (dialog_items); ++i)
|
|
704 {
|
771
|
705 Lisp_Object *gui_item = Dynarr_atp (dialog_items, i);
|
440
|
706 Lisp_Gui_Item *pgui_item = XGUI_ITEM (*gui_item);
|
771
|
707
|
428
|
708 item_tem.style = (WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_PUSHBUTTON
|
|
709 | (gui_item_active_p (*gui_item) ? 0 : WS_DISABLED));
|
|
710 item_tem.cx = button_width (pgui_item->name);
|
|
711 /* Item ids are indices into dialog_items plus offset, to avoid having
|
|
712 items by reserved ids (IDOK, IDCANCEL) */
|
|
713 item_tem.id = i + ID_ITEM_BIAS;
|
771
|
714
|
428
|
715 ALIGN_TEMPLATE;
|
593
|
716 Dynarr_add_many (template_, &item_tem, sizeof (item_tem));
|
771
|
717
|
428
|
718 /* Right after 0xFFFF and class id atom follows */
|
593
|
719 Dynarr_add_many (template_, &ones, 2);
|
|
720 Dynarr_add_many (template_, &button_class_id,
|
|
721 sizeof (button_class_id));
|
771
|
722
|
428
|
723 /* Next thing to add is control text, as Unicode string */
|
442
|
724 {
|
|
725 Emchar accel_unused;
|
771
|
726
|
|
727 push_lisp_string_as_unicode
|
|
728 (template_,
|
|
729 mswindows_translate_menu_or_dialog_item
|
|
730 (pgui_item->name, &accel_unused));
|
442
|
731 }
|
771
|
732
|
428
|
733 /* Specify 0 length creation data. */
|
593
|
734 Dynarr_add_many (template_, &zeroes, 2);
|
771
|
735
|
428
|
736 item_tem.x += item_tem.cx + X_BUTTON_SPACING;
|
|
737 }
|
|
738 }
|
771
|
739
|
428
|
740 /* Now the Windows dialog structure is ready. We need to prepare a
|
|
741 data structure for the new dialog, which will contain callbacks
|
442
|
742 and the frame for these callbacks. This structure has to be
|
|
743 GC-protected and thus it is put into a statically protected
|
|
744 list. */
|
428
|
745 {
|
442
|
746 Lisp_Object dialog_data;
|
428
|
747 int i;
|
442
|
748 struct mswindows_dialog_id *did =
|
|
749 alloc_lcrecord_type (struct mswindows_dialog_id,
|
|
750 &lrecord_mswindows_dialog_id);
|
771
|
751
|
793
|
752 dialog_data = wrap_mswindows_dialog_id (did);
|
771
|
753
|
442
|
754 did->frame = wrap_frame (f);
|
|
755 did->callbacks = make_vector (Dynarr_length (dialog_items), Qunbound);
|
|
756 for (i = 0; i < Dynarr_length (dialog_items); i++)
|
|
757 XVECTOR_DATA (did->callbacks) [i] =
|
|
758 XGUI_ITEM (*Dynarr_atp (dialog_items, i))->callback;
|
428
|
759
|
|
760 /* Woof! Everything is ready. Pop pop pop in now! */
|
442
|
761 did->hwnd =
|
771
|
762 qxeCreateDialogIndirectParam (NULL,
|
|
763 (LPDLGTEMPLATE) Dynarr_atp (template_, 0),
|
|
764 FRAME_MSWINDOWS_HANDLE (f), dialog_proc,
|
|
765 (LPARAM) LISP_TO_VOID (dialog_data));
|
442
|
766 if (!did->hwnd)
|
428
|
767 /* Something went wrong creating the dialog */
|
563
|
768 signal_error (Qdialog_box_error, "Creating dialog", keys);
|
771
|
769
|
428
|
770 Vdialog_data_list = Fcons (dialog_data, Vdialog_data_list);
|
771
|
771
|
442
|
772 /* Cease protection and free dynarrays */
|
771
|
773 unbind_to (unbind_count);
|
442
|
774 return dialog_data;
|
428
|
775 }
|
442
|
776 }
|
428
|
777
|
442
|
778 static Lisp_Object
|
|
779 mswindows_make_dialog_box_internal (struct frame* f, Lisp_Object type,
|
|
780 Lisp_Object keys)
|
|
781 {
|
707
|
782 int unbind_count = specpdl_depth ();
|
|
783 record_unwind_protect (dialog_popped_down, Qnil);
|
|
784 popup_up_p++;
|
819
|
785
|
442
|
786 if (EQ (type, Qfile))
|
771
|
787 return unbind_to_1 (unbind_count, handle_file_dialog_box (f, keys));
|
673
|
788 else if (EQ (type, Qdirectory))
|
771
|
789 return unbind_to_1 (unbind_count, handle_directory_dialog_box (f, keys));
|
442
|
790 else if (EQ (type, Qquestion))
|
771
|
791 return unbind_to_1 (unbind_count, handle_question_dialog_box (f, keys));
|
442
|
792 else if (EQ (type, Qprint))
|
771
|
793 return unbind_to_1 (unbind_count,
|
|
794 mswindows_handle_print_dialog_box (f, keys));
|
442
|
795 else if (EQ (type, Qpage_setup))
|
771
|
796 return unbind_to_1 (unbind_count,
|
|
797 mswindows_handle_page_setup_dialog_box (f, keys));
|
442
|
798 else
|
563
|
799 signal_error (Qunimplemented, "Dialog box type", type);
|
442
|
800 return Qnil;
|
428
|
801 }
|
|
802
|
|
803 void
|
|
804 console_type_create_dialog_mswindows (void)
|
|
805 {
|
442
|
806 CONSOLE_HAS_METHOD (mswindows, make_dialog_box_internal);
|
|
807 }
|
|
808
|
|
809 void
|
|
810 syms_of_dialog_mswindows (void)
|
|
811 {
|
|
812 INIT_LRECORD_IMPLEMENTATION (mswindows_dialog_id);
|
771
|
813
|
442
|
814 DEFKEYWORD (Q_initial_directory);
|
|
815 DEFKEYWORD (Q_initial_filename);
|
|
816 DEFKEYWORD (Q_filter_list);
|
|
817 DEFKEYWORD (Q_title);
|
|
818 DEFKEYWORD (Q_allow_multi_select);
|
|
819 DEFKEYWORD (Q_create_prompt_on_nonexistent);
|
|
820 DEFKEYWORD (Q_overwrite_prompt);
|
|
821 DEFKEYWORD (Q_file_must_exist);
|
|
822 DEFKEYWORD (Q_no_network_button);
|
|
823 DEFKEYWORD (Q_no_read_only_return);
|
771
|
824
|
442
|
825 /* Errors */
|
563
|
826 DEFERROR_STANDARD (Qdialog_box_error, Qgui_error);
|
428
|
827 }
|
|
828
|
|
829 void
|
|
830 vars_of_dialog_mswindows (void)
|
|
831 {
|
442
|
832 Vpopup_frame_list = Qnil;
|
|
833 staticpro (&Vpopup_frame_list);
|
771
|
834
|
428
|
835 Vdialog_data_list = Qnil;
|
|
836 staticpro (&Vdialog_data_list);
|
771
|
837
|
442
|
838 DEFVAR_LISP ("default-file-dialog-filter-alist",
|
|
839 &Vdefault_file_dialog_filter_alist /*
|
771
|
840 */ );
|
442
|
841 Vdefault_file_dialog_filter_alist =
|
771
|
842 list5 (Fcons (build_msg_string ("Text Files"), build_string ("*.txt")),
|
|
843 Fcons (build_msg_string ("C Files"), build_string ("*.c;*.h")),
|
|
844 Fcons (build_msg_string ("Elisp Files"), build_string ("*.el")),
|
|
845 Fcons (build_msg_string ("HTML Files"), build_string ("*.html;*.html")),
|
|
846 Fcons (build_msg_string ("All Files"), build_string ("*.*")));
|
428
|
847 }
|