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