comparison src/dialog-msw.c @ 412:697ef44129c6 r21-2-14

Import from CVS: tag r21-2-14
author cvs
date Mon, 13 Aug 2007 11:20:41 +0200
parents de805c49cfc1
children e804706bfb8c
comparison
equal deleted inserted replaced
411:12e008d41344 412:697ef44129c6
108 margins. Otherwise, minimal margins are given to the button row. 108 margins. Otherwise, minimal margins are given to the button row.
109 */ 109 */
110 110
111 #define ID_ITEM_BIAS 32 111 #define ID_ITEM_BIAS 32
112 112
113 typedef struct gui_item struct_gui_item;
114 typedef struct
115 {
116 Dynarr_declare (struct gui_item);
117 } struct_gui_item_dynarr;
118
113 /* Dialog procedure */ 119 /* Dialog procedure */
114 static BOOL CALLBACK 120 static BOOL CALLBACK
115 dialog_proc (HWND hwnd, UINT msg, WPARAM w_param, LPARAM l_param) 121 dialog_proc (HWND hwnd, UINT msg, WPARAM w_param, LPARAM l_param)
116 { 122 {
117 switch (msg) 123 switch (msg)
157 { 163 {
158 Extbyte *mbcs_string; 164 Extbyte *mbcs_string;
159 Charcount length = XSTRING_CHAR_LENGTH (string); 165 Charcount length = XSTRING_CHAR_LENGTH (string);
160 LPWSTR uni_string; 166 LPWSTR uni_string;
161 167
162 TO_EXTERNAL_FORMAT (LISP_STRING, string, 168 GET_C_CHARPTR_EXT_DATA_ALLOCA (XSTRING_DATA (string),
163 C_STRING_ALLOCA, mbcs_string, 169 FORMAT_OS, mbcs_string);
164 Qnative);
165 uni_string = alloca_array (WCHAR, length + 1);
166 length = MultiByteToWideChar (CP_ACP, 0, mbcs_string, -1,
167 uni_string, sizeof(WCHAR) * (length + 1));
168 Dynarr_add_many (dynarr, uni_string, sizeof(WCHAR) * length);
169 }
170
171 /* Helper function which converts the supplied string STRING into Unicode and
172 pushes it at the end of DYNARR */
173 static void
174 push_bufbyte_string_as_unicode (unsigned_char_dynarr* dynarr, Bufbyte *string,
175 Bytecount len)
176 {
177 Extbyte *mbcs_string;
178 Charcount length = bytecount_to_charcount (string, len);
179 LPWSTR uni_string;
180
181 TO_EXTERNAL_FORMAT (C_STRING, string,
182 C_STRING_ALLOCA, mbcs_string,
183 Qnative);
184 uni_string = alloca_array (WCHAR, length + 1); 170 uni_string = alloca_array (WCHAR, length + 1);
185 length = MultiByteToWideChar (CP_ACP, 0, mbcs_string, -1, 171 length = MultiByteToWideChar (CP_ACP, 0, mbcs_string, -1,
186 uni_string, sizeof(WCHAR) * (length + 1)); 172 uni_string, sizeof(WCHAR) * (length + 1));
187 Dynarr_add_many (dynarr, uni_string, sizeof(WCHAR) * length); 173 Dynarr_add_many (dynarr, uni_string, sizeof(WCHAR) * length);
188 } 174 }
212 } 198 }
213 199
214 static void 200 static void
215 mswindows_popup_dialog_box (struct frame* f, Lisp_Object desc) 201 mswindows_popup_dialog_box (struct frame* f, Lisp_Object desc)
216 { 202 {
217 Lisp_Object_dynarr *dialog_items = Dynarr_new (Lisp_Object); 203 struct_gui_item_dynarr *dialog_items = Dynarr_new (struct_gui_item);
218 unsigned_char_dynarr *template = Dynarr_new (unsigned_char); 204 unsigned_char_dynarr *template = Dynarr_new (unsigned_char);
219 unsigned int button_row_width = 0; 205 unsigned int button_row_width = 0;
220 unsigned int text_width, text_height; 206 unsigned int text_width, text_height;
221 207
222 int unbind_count = specpdl_depth (); 208 int unbind_count = specpdl_depth ();
235 221
236 EXTERNAL_LIST_LOOP (item_cons, XCDR (desc)) 222 EXTERNAL_LIST_LOOP (item_cons, XCDR (desc))
237 { 223 {
238 if (!NILP (XCAR (item_cons))) 224 if (!NILP (XCAR (item_cons)))
239 { 225 {
240 Lisp_Object gitem = gui_parse_item_keywords (XCAR (item_cons)); 226 struct gui_item gitem;
227 gui_item_init (&gitem);
228 gui_parse_item_keywords (XCAR (item_cons), &gitem);
241 Dynarr_add (dialog_items, gitem); 229 Dynarr_add (dialog_items, gitem);
242 button_row_width += button_width (XGUI_ITEM (gitem)->name) 230 button_row_width += button_width (gitem.name) + X_BUTTON_MARGIN;
243 + X_BUTTON_MARGIN;
244 } 231 }
245 } 232 }
246 if (Dynarr_length (dialog_items) == 0) 233 if (Dynarr_length (dialog_items) == 0)
247 signal_simple_error ("Dialog descriptor provides no active items", desc); 234 signal_simple_error ("Dialog descriptor provides no active items", desc);
248 button_row_width -= X_BUTTON_MARGIN; 235 button_row_width -= X_BUTTON_MARGIN;
361 item_tem.cy = Y_BUTTON; 348 item_tem.cy = Y_BUTTON;
362 item_tem.dwExtendedStyle = 0; 349 item_tem.dwExtendedStyle = 0;
363 350
364 for (i = 0; i < Dynarr_length (dialog_items); ++i) 351 for (i = 0; i < Dynarr_length (dialog_items); ++i)
365 { 352 {
366 Lisp_Object* gui_item = Dynarr_atp (dialog_items, i); 353 struct gui_item *pgui_item = Dynarr_atp (dialog_items, i);
367 Lisp_Gui_Item *pgui_item = XGUI_ITEM (*gui_item);
368 354
369 item_tem.style = (WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_PUSHBUTTON 355 item_tem.style = (WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_PUSHBUTTON
370 | (gui_item_active_p (*gui_item) ? 0 : WS_DISABLED)); 356 | (gui_item_active_p (pgui_item) ? 0 : WS_DISABLED));
371 item_tem.cx = button_width (pgui_item->name); 357 item_tem.cx = button_width (pgui_item->name);
372 /* Item ids are indices into dialog_items plus offset, to avoid having 358 /* Item ids are indices into dialog_items plus offset, to avoid having
373 items by reserved ids (IDOK, IDCANCEL) */ 359 items by reserved ids (IDOK, IDCANCEL) */
374 item_tem.id = i + ID_ITEM_BIAS; 360 item_tem.id = i + ID_ITEM_BIAS;
375 361
379 /* Right after 0xFFFF and class id atom follows */ 365 /* Right after 0xFFFF and class id atom follows */
380 Dynarr_add_many (template, &ones, 2); 366 Dynarr_add_many (template, &ones, 2);
381 Dynarr_add_many (template, &button_class_id, sizeof (button_class_id)); 367 Dynarr_add_many (template, &button_class_id, sizeof (button_class_id));
382 368
383 /* Next thing to add is control text, as Unicode string */ 369 /* Next thing to add is control text, as Unicode string */
384 { 370 push_lisp_string_as_unicode (template, pgui_item->name);
385 Lisp_Object ctext = pgui_item->name;
386 Emchar accel_unused;
387 Bufbyte *trans = (Bufbyte *) alloca (2 * XSTRING_LENGTH (ctext) + 3);
388 Bytecount translen;
389
390 memcpy (trans, XSTRING_DATA (ctext), XSTRING_LENGTH (ctext) + 1);
391 translen =
392 mswindows_translate_menu_or_dialog_item (trans,
393 XSTRING_LENGTH (ctext),
394 2 * XSTRING_LENGTH (ctext) + 3,
395 &accel_unused,
396 ctext);
397 push_bufbyte_string_as_unicode (template, trans, translen);
398 }
399 371
400 /* Specify 0 length creation data. */ 372 /* Specify 0 length creation data. */
401 Dynarr_add_many (template, &zeroes, 2); 373 Dynarr_add_many (template, &zeroes, 2);
402 374
403 item_tem.x += item_tem.cx + X_BUTTON_SPACING; 375 item_tem.x += item_tem.cx + X_BUTTON_SPACING;
416 388
417 XSETFRAME (frame, f); 389 XSETFRAME (frame, f);
418 vector = make_vector (Dynarr_length (dialog_items), Qunbound); 390 vector = make_vector (Dynarr_length (dialog_items), Qunbound);
419 dialog_data = Fcons (frame, vector); 391 dialog_data = Fcons (frame, vector);
420 for (i = 0; i < Dynarr_length (dialog_items); i++) 392 for (i = 0; i < Dynarr_length (dialog_items); i++)
421 XVECTOR_DATA (vector) [i] = 393 XVECTOR_DATA (vector) [i] = Dynarr_atp (dialog_items, i)->callback;
422 XGUI_ITEM (*Dynarr_atp (dialog_items, i))->callback;
423 394
424 /* Woof! Everything is ready. Pop pop pop in now! */ 395 /* Woof! Everything is ready. Pop pop pop in now! */
425 if (!CreateDialogIndirectParam (NULL, 396 if (!CreateDialogIndirectParam (NULL,
426 (LPDLGTEMPLATE) Dynarr_atp (template, 0), 397 (LPDLGTEMPLATE) Dynarr_atp (template, 0),
427 FRAME_MSWINDOWS_HANDLE (f), dialog_proc, 398 FRAME_MSWINDOWS_HANDLE (f), dialog_proc,