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