annotate src/dialog-msw.c @ 380:8626e4521993 r21-2-5

Import from CVS: tag r21-2-5
author cvs
date Mon, 13 Aug 2007 11:07:10 +0200
parents cc15677e0335
children 74fd4e045ea6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
1 /* Implements elisp-programmable dialog boxes -- MS Windows interface.
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
2 Copyright (C) 1998 Kirill M. Katsnelson <kkm@kis.ru>
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
3
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
4 This file is part of XEmacs.
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
5
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
6 XEmacs is free software; you can redistribute it and/or modify it
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
7 under the terms of the GNU General Public License as published by the
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
8 Free Software Foundation; either version 2, or (at your option) any
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
9 later version.
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
10
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
11 XEmacs is distributed in the hope that it will be useful, but WITHOUT
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
14 for more details.
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
15
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
16 You should have received a copy of the GNU General Public License
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
17 along with XEmacs; see the file COPYING. If not, write to
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
19 Boston, MA 02111-1307, USA. */
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
20
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
21 /* Synched up with: Not in FSF. */
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
22
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 371
diff changeset
23 /* Author:
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
24 Initially written by kkm, May 1998
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
25 */
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
26
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
27 #include <config.h>
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
28 #include "lisp.h"
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
29
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
30 #include "buffer.h"
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
31 #include "console-msw.h"
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
32 #include "frame.h"
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
33 #include "gui.h"
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
34 #include "opaque.h"
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
35
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
36 /* List containing all dialog data structures of currently popped up
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
37 dialogs. Each item is a cons of frame object and a vector of
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
38 callbacks for buttons in the dialog, in order */
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
39 static Lisp_Object Vdialog_data_list;
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
40
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
41 /* DLUs per character metrics */
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
42 #define X_DLU_PER_CHAR 4
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
43 #define Y_DLU_PER_CHAR 8
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
44
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
45 /*
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
46 Button metrics
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
47 --------------
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
48 All buttons have height of 15 DLU. The minimum width for a button is 32 DLU,
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 371
diff changeset
49 but it can be expanded to accommodate its text, so the width is calculated as
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
50 8 DLU per button plus 4 DLU per character.
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 371
diff changeset
51 max (32, 6 * text_length). The factor of six is rather empirical, but it
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
52 works better than 8 which comes from the definition of a DLU. Buttons are
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
53 spaced with 6 DLU gap. Minimum distance from the button to the left or right
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
54 dialog edges is 6 DLU, and the distance between the dialog bottom edge and
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
55 buttons is 7 DLU.
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
56 */
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
57
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
58 #define X_MIN_BUTTON 32
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
59 #define X_BUTTON_MARGIN 8
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
60 #define Y_BUTTON 15
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
61 #define X_BUTTON_SPACING 6
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
62 #define X_BUTTON_FROM_EDGE 6
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
63 #define Y_BUTTON_FROM_EDGE 7
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
64
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
65 /*
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
66 Text field metrics
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
67 ------------------
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 371
diff changeset
68 Text distance from left and right edges is the same as for buttons, and the
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
69 top margin is 11 DLU. The static control has height of 2 DLU per control
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
70 plus 8 DLU per each line of text. Distance between the bottom edge of the
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
71 control and the button row is 15 DLU. Minimum width of the static control
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 371
diff changeset
72 is 100 DLU, thus giving minimum dialog weight of 112 DLU. Maximum width is
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
73 300 DLU, and, if the text is wider than that, the text is wrapped on the
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
74 next line. Each character in the text is considered 4 DLU wide.
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
75 */
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
76
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
77 #define X_MIN_TEXT 100
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
78 #define X_AVE_TEXT 200
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
79 #define X_MAX_TEXT 300
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
80 #define X_TEXT_FROM_EDGE X_BUTTON_FROM_EDGE
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
81 #define Y_TEXT_FROM_EDGE 11
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
82 #define Y_TEXT_MARGIN 2
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
83 #define Y_TEXT_FROM_BUTTON 15
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
84
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
85 #define X_MIN_TEXT_CHAR (X_MIN_TEXT / X_DLU_PER_CHAR)
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
86 #define X_AVE_TEXT_CHAR (X_AVE_TEXT / X_DLU_PER_CHAR)
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
87 #define X_MAX_TEXT_CHAR (X_MAX_TEXT / X_DLU_PER_CHAR)
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
88
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
89 /*
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
90 Layout algorithm
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
91 ----------------
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
92 First we calculate the minimum width of the button row, excluding "from
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
93 edge" distances. Note that the static control text can be narrower than
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
94 X_AVE_TEXT only if both text and button row are narrower than that (so,
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
95 even if text *can* be wrapped into 2 rows narrower than ave width, it is not
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
96 done). Let WBR denote the width of the button row.
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
97
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
98 Next, the width of the static field is determined.
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
99 First, if all lines of text fit into max (WBR, X_MAX_TEXT), the width of the
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
100 control is the same as the width of the longest line.
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 371
diff changeset
101 Second, if all lines of text are narrower than X_MIN_TEXT, then width of
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
102 the control is set to X_MIN_TEXT.
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
103 Otherwise, width is set to max(WBR, X_AVE_TEXT). In this case, line wrapping will
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
104 happen.
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
105
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 371
diff changeset
106 If width of the text control is larger than that of the button row, then the
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 371
diff changeset
107 latter is centered across the dialog, by giving it extra edge
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
108 margins. Otherwise, minimal margins are given to the button row.
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
109 */
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
110
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
111 #define ID_ITEM_BIAS 32
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
112
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
113 typedef struct gui_item struct_gui_item;
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
114 typedef struct
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
115 {
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
116 Dynarr_declare (struct gui_item);
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
117 } struct_gui_item_dynarr;
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
118
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
119 /* Dialog procedure */
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
120 static BOOL CALLBACK
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
121 dialog_proc (HWND hwnd, UINT msg, WPARAM w_param, LPARAM l_param)
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
122 {
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
123 switch (msg)
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
124 {
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
125 case WM_INITDIALOG:
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
126 SetWindowLong (hwnd, DWL_USER, l_param);
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
127 break;
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
128
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
129 case WM_DESTROY:
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
130 {
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
131 Lisp_Object data;
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
132 VOID_TO_LISP (data, GetWindowLong (hwnd, DWL_USER));
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
133 Vdialog_data_list = delq_no_quit (data, Vdialog_data_list);
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
134 }
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
135 break;
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
136
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
137 case WM_COMMAND:
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
138 {
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
139 Lisp_Object fn, arg, data;
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
140 VOID_TO_LISP (data, GetWindowLong (hwnd, DWL_USER));
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
141
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
142 assert (w_param >= ID_ITEM_BIAS
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
143 && w_param < XVECTOR_LENGTH (XCDR (data)) + ID_ITEM_BIAS);
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
144
288
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
145 get_gui_callback (XVECTOR_DATA (XCDR (data)) [w_param - ID_ITEM_BIAS],
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
146 &fn, &arg);
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
147 mswindows_enqueue_misc_user_event (XCAR (data), fn, arg);
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
148
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
149 DestroyWindow (hwnd);
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
150 }
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
151 break;
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
152
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
153 default:
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
154 return FALSE;
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
155 }
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
156 return TRUE;
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
157 }
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
158
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
159 /* Helper function which converts the supplied string STRING into Unicode and
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
160 pushes it at the end of DYNARR */
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
161 static void
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
162 push_lisp_string_as_unicode (unsigned_char_dynarr* dynarr, Lisp_Object string)
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
163 {
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
164 Extbyte *mbcs_string;
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
165 Charcount length = XSTRING_CHAR_LENGTH (string);
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
166 LPWSTR uni_string;
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
167
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
168 GET_C_CHARPTR_EXT_DATA_ALLOCA (XSTRING_DATA (string),
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
169 FORMAT_OS, mbcs_string);
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
170 uni_string = alloca_array (WCHAR, length + 1);
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
171 length = MultiByteToWideChar (CP_ACP, 0, mbcs_string, -1,
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
172 uni_string, sizeof(WCHAR) * (length + 1));
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
173 Dynarr_add_many (dynarr, uni_string, sizeof(WCHAR) * length);
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
174 }
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
175
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
176 /* Given button TEXT, return button width in DLU */
290
c9fe270a4101 Import from CVS: tag r21-0b43
cvs
parents: 288
diff changeset
177 static unsigned int
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
178 button_width (Lisp_Object text)
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
179 {
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
180 unsigned int width = X_DLU_PER_CHAR * XSTRING_CHAR_LENGTH (text);
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
181 return max (X_MIN_BUTTON, width);
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
182 }
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
183
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
184 /* Unwind protection routine frees a dynarr opaqued into arg */
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
185 static Lisp_Object
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
186 free_dynarr_opaque_ptr (Lisp_Object arg)
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
187 {
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
188 Dynarr_free (get_opaque_ptr (arg));
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
189 return arg;
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
190 }
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
191
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
192
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
193 #define ALIGN_TEMPLATE \
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
194 { \
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
195 unsigned int slippage = Dynarr_length (template) & 3; \
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
196 if (slippage) \
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
197 Dynarr_add_many (template, &zeroes, slippage); \
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
198 }
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
199
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
200 static void
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
201 mswindows_popup_dialog_box (struct frame* f, Lisp_Object desc)
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
202 {
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
203 struct_gui_item_dynarr *dialog_items = Dynarr_new (struct_gui_item);
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
204 unsigned_char_dynarr *template = Dynarr_new (unsigned_char);
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
205 unsigned int button_row_width = 0;
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
206 unsigned int text_width, text_height;
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
207
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
208 int unbind_count = specpdl_depth ();
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
209 record_unwind_protect (free_dynarr_opaque_ptr,
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
210 make_opaque_ptr (dialog_items));
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
211 record_unwind_protect (free_dynarr_opaque_ptr,
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
212 make_opaque_ptr (template));
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
213
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
214 /* A big NO NEED to GCPRO gui_items stored in the array: they are just
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
215 pointers into DESC list, which is GC-protected by the caller */
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
216
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
217 /* Parse each item in the dialog into gui_item structs, and stuff a dynarr
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
218 of these. Calculate button row width in this loop too */
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
219 {
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
220 Lisp_Object item_cons;
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
221
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
222 EXTERNAL_LIST_LOOP (item_cons, XCDR (desc))
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
223 {
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
224 if (!NILP (XCAR (item_cons)))
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
225 {
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
226 struct gui_item gitem;
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
227 gui_item_init (&gitem);
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
228 gui_parse_item_keywords (XCAR (item_cons), &gitem);
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
229 Dynarr_add (dialog_items, gitem);
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
230 button_row_width += button_width (gitem.name) + X_BUTTON_MARGIN;
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
231 }
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
232 }
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
233 if (Dynarr_length (dialog_items) == 0)
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
234 signal_simple_error ("Dialog descriptor provides no active items", desc);
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
235 button_row_width -= X_BUTTON_MARGIN;
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
236 }
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
237
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
238 /* Determine the final width layout */
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
239 {
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
240 Bufbyte *p = XSTRING_DATA (XCAR (desc));
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
241 Charcount string_max = 0, this_length = 0;
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
242 while (1)
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
243 {
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
244 Emchar ch = charptr_emchar (p);
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
245 INC_CHARPTR (p);
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
246
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
247 if (ch == (Emchar)'\n' || ch == (Emchar)'\0')
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
248 {
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
249 string_max = max (this_length, string_max);
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
250 this_length = 0;
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
251 }
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
252 else
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
253 ++this_length;
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
254
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
255 if (ch == (Emchar)'\0')
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
256 break;
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
257 }
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
258
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
259 if (string_max * X_DLU_PER_CHAR > max (X_MAX_TEXT, button_row_width))
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
260 text_width = X_AVE_TEXT;
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
261 else if (string_max * X_DLU_PER_CHAR < X_MIN_TEXT)
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
262 text_width = X_MIN_TEXT;
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
263 else
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
264 text_width = string_max * X_DLU_PER_CHAR;
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
265 text_width = max (text_width, button_row_width);
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
266 }
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
267
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
268 /* Now calculate the height for the text control */
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
269 {
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
270 Bufbyte *p = XSTRING_DATA (XCAR (desc));
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
271 Charcount break_at = text_width / X_DLU_PER_CHAR;
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
272 Charcount char_pos = 0;
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
273 int num_lines = 1;
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
274 Emchar ch;
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
275
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
276 while ((ch = charptr_emchar (p)) != (Emchar)'\0')
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
277 {
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
278 INC_CHARPTR (p);
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
279 char_pos += ch != (Emchar)'\n';
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
280 if (ch == (Emchar)'\n' || char_pos == break_at)
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
281 {
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
282 ++num_lines;
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
283 char_pos = 0;
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
284 }
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
285 }
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
286 text_height = Y_TEXT_MARGIN + Y_DLU_PER_CHAR * num_lines;
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
287 }
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
288
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
289 /* Ok, now we are ready to stuff the dialog template and lay out controls */
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
290 {
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
291 DLGTEMPLATE dlg_tem;
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
292 DLGITEMTEMPLATE item_tem;
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
293 int i;
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
294 const unsigned int zeroes = 0;
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
295 const unsigned int ones = 0xFFFFFFFF;
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
296 const WORD static_class_id = 0x0082;
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
297 const WORD button_class_id = 0x0080;
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
298
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
299 /* Create and stuff in DLGTEMPLATE header */
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
300 dlg_tem.style = (DS_CENTER | DS_MODALFRAME | DS_SETFONT
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
301 | WS_CAPTION | WS_POPUP | WS_VISIBLE);
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
302 dlg_tem.dwExtendedStyle = 0;
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
303 dlg_tem.cdit = Dynarr_length (dialog_items) + 1;
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
304 dlg_tem.x = 0;
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
305 dlg_tem.y = 0;
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
306 dlg_tem.cx = text_width + 2 * X_TEXT_FROM_EDGE;
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
307 dlg_tem.cy = (Y_TEXT_FROM_EDGE + text_height + Y_TEXT_FROM_BUTTON
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
308 + Y_BUTTON + Y_BUTTON_FROM_EDGE);
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
309 Dynarr_add_many (template, &dlg_tem, sizeof (dlg_tem));
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
310
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
311 /* We want no menu and standard class */
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
312 Dynarr_add_many (template, &zeroes, 4);
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
313
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
314 /* And the third is the dialog title. "XEmacs" as long as we do not supply
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
315 one in descriptor. Note that the string must be in Unicode. */
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
316 Dynarr_add_many (template, L"XEmacs", 14);
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
317
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
318 /* We want standard dialog font */
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
319 Dynarr_add_many (template, L"\x08MS Shell Dlg", 28);
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
320
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
321 /* Next add text control. */
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
322 item_tem.style = WS_CHILD | WS_VISIBLE | SS_LEFT | SS_NOPREFIX;
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
323 item_tem.dwExtendedStyle = 0;
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
324 item_tem.x = X_TEXT_FROM_EDGE;
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
325 item_tem.y = Y_TEXT_FROM_EDGE;
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
326 item_tem.cx = text_width;
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
327 item_tem.cy = text_height;
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
328 item_tem.id = 0xFFFF;
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
329
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
330 ALIGN_TEMPLATE;
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
331 Dynarr_add_many (template, &item_tem, sizeof (item_tem));
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
332
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
333 /* Right after class id follows */
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
334 Dynarr_add_many (template, &ones, 2);
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
335 Dynarr_add_many (template, &static_class_id, sizeof (static_class_id));
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
336
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
337 /* Next thing to add is control text, as Unicode string */
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
338 push_lisp_string_as_unicode (template, XCAR (desc));
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
339
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
340 /* Specify 0 length creation data */
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
341 Dynarr_add_many (template, &zeroes, 2);
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
342
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
343 /* Now it's the button time */
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
344 item_tem.y = Y_TEXT_FROM_EDGE + text_height + Y_TEXT_FROM_BUTTON;
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
345 item_tem.x = X_BUTTON_FROM_EDGE + (button_row_width < text_width
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
346 ? (text_width - button_row_width) / 2
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
347 : 0);
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
348 item_tem.cy = Y_BUTTON;
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
349 item_tem.dwExtendedStyle = 0;
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
350
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
351 for (i = 0; i < Dynarr_length (dialog_items); ++i)
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
352 {
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
353 struct gui_item *pgui_item = Dynarr_atp (dialog_items, i);
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
354
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
355 item_tem.style = (WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_PUSHBUTTON
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
356 | (gui_item_active_p (pgui_item) ? 0 : WS_DISABLED));
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
357 item_tem.cx = button_width (pgui_item->name);
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
358 /* Item ids are indices into dialog_items plus offset, to avoid having
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
359 items by reserved ids (IDOK, IDCANCEL) */
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
360 item_tem.id = i + ID_ITEM_BIAS;
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
361
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
362 ALIGN_TEMPLATE;
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
363 Dynarr_add_many (template, &item_tem, sizeof (item_tem));
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
364
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
365 /* Right after 0xFFFF and class id atom follows */
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
366 Dynarr_add_many (template, &ones, 2);
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
367 Dynarr_add_many (template, &button_class_id, sizeof (button_class_id));
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
368
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
369 /* Next thing to add is control text, as Unicode string */
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
370 push_lisp_string_as_unicode (template, pgui_item->name);
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
371
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
372 /* Specify 0 length creation data. */
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
373 Dynarr_add_many (template, &zeroes, 2);
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
374
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
375 item_tem.x += item_tem.cx + X_BUTTON_SPACING;
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
376 }
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
377 }
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
378
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
379 /* Now the Windows dialog structure is ready. We need to prepare a
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
380 data structure for the new dialog, which will contain callbacks
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
381 and the frame for these callbacks. This structure has to be
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
382 GC-protected. The data structure itself is a cons of frame object
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
383 and a vector of callbacks; for the protection reasons it is put
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
384 into a statically protected list. */
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
385 {
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
386 Lisp_Object frame, vector, dialog_data;
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
387 int i;
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
388
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
389 XSETFRAME (frame, f);
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
390 vector = make_vector (Dynarr_length (dialog_items), Qunbound);
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
391 dialog_data = Fcons (frame, vector);
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
392 for (i = 0; i < Dynarr_length (dialog_items); i++)
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
393 XVECTOR_DATA (vector) [i] = Dynarr_atp (dialog_items, i)->callback;
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
394
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
395 /* Woof! Everything is ready. Pop pop pop in now! */
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
396 if (!CreateDialogIndirectParam (NULL,
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
397 (LPDLGTEMPLATE) Dynarr_atp (template, 0),
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
398 FRAME_MSWINDOWS_HANDLE (f), dialog_proc,
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
399 (LPARAM) LISP_TO_VOID (dialog_data)))
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
400 /* Something went wrong creating the dialog */
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
401 signal_simple_error ("System error creating dialog", desc);
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
402
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
403 Vdialog_data_list = Fcons (dialog_data, Vdialog_data_list);
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
404 }
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
405
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
406 /* Cease protection and free dynarrays */
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
407 unbind_to (unbind_count, Qnil);
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
408 }
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
409
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
410 void
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
411 console_type_create_dialog_mswindows (void)
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
412 {
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
413 CONSOLE_HAS_METHOD (mswindows, popup_dialog_box);
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
414 }
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
415
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
416 void
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
417 vars_of_dialog_mswindows (void)
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
418 {
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
419 Vdialog_data_list = Qnil;
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
420 staticpro (&Vdialog_data_list);
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents:
diff changeset
421 }