annotate src/dialog-msw.c @ 440:8de8e3f6228a r21-2-28

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