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