Mercurial > hg > xemacs-beta
annotate src/frame-x.c @ 4982:3c3c1d139863
Automatic merge
author | Ben Wing <ben@xemacs.org> |
---|---|
date | Fri, 05 Feb 2010 11:25:00 -0600 |
parents | 4aebb0131297 16112448d484 |
children | 6f2158fa75ed b5df3737028a |
rev | line source |
---|---|
428 | 1 /* Functions for the X window system. |
2 Copyright (C) 1989, 1992-5, 1997 Free Software Foundation, Inc. | |
2367 | 3 Copyright (C) 1995, 1996, 2001, 2002, 2004 Ben Wing. |
428 | 4 |
5 This file is part of XEmacs. | |
6 | |
7 XEmacs is free software; you can redistribute it and/or modify it | |
8 under the terms of the GNU General Public License as published by the | |
9 Free Software Foundation; either version 2, or (at your option) any | |
10 later version. | |
11 | |
12 XEmacs is distributed in the hope that it will be useful, but WITHOUT | |
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 for more details. | |
16 | |
17 You should have received a copy of the GNU General Public License | |
18 along with XEmacs; see the file COPYING. If not, write to | |
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
20 Boston, MA 02111-1307, USA. */ | |
21 | |
22 /* Synched up with: Not synched with FSF. */ | |
23 | |
2367 | 24 /* This file has been Mule-ized, Ben Wing, 10-14-04. */ |
25 | |
428 | 26 /* Substantially rewritten for XEmacs. */ |
27 | |
28 #include <config.h> | |
29 #include "lisp.h" | |
30 | |
800 | 31 #include "buffer.h" |
872 | 32 #include "device-impl.h" |
800 | 33 #include "events.h" |
34 #include "extents.h" | |
35 #include "faces.h" | |
872 | 36 #include "frame-impl.h" |
800 | 37 #include "gutter.h" |
872 | 38 #include "window.h" |
39 | |
40 #include "console-x-impl.h" | |
800 | 41 #include "glyphs-x.h" |
872 | 42 #include "objects-x-impl.h" |
800 | 43 #include "scrollbar-x.h" |
44 | |
428 | 45 #include "xintrinsicp.h" /* CoreP.h needs this */ |
46 #include <X11/CoreP.h> /* Numerous places access the fields of | |
47 a core widget directly. We could | |
48 use XtGetValues(), but ... */ | |
49 #include <X11/Shell.h> | |
50 #include <X11/ShellP.h> | |
4769
5460287a3327
Remove support for pre-X11R5 systems, including systems without Xmu. See
Jerry James <james@xemacs.org>
parents:
4706
diff
changeset
|
51 #include <X11/Xmu/Editres.h> |
428 | 52 #include "EmacsManager.h" |
53 #include "EmacsFrameP.h" | |
54 #include "EmacsShell.h" | |
55 #ifdef EXTERNAL_WIDGET | |
56 #include "ExternalShell.h" | |
57 #endif | |
58 | |
59 #ifdef HAVE_DRAGNDROP | |
60 #include "dragdrop.h" | |
61 #endif | |
62 | |
63 /* Default properties to use when creating frames. */ | |
64 Lisp_Object Vdefault_x_frame_plist; | |
65 | |
2747 | 66 Lisp_Object Qoverride_redirect; |
428 | 67 Lisp_Object Qx_resource_name; |
68 | |
1204 | 69 static const struct memory_description x_frame_data_description_1 [] = { |
1346 | 70 { XD_LISP_OBJECT, offsetof (struct x_frame, last_menubar_buffer) }, |
1204 | 71 { XD_LISP_OBJECT, offsetof (struct x_frame, icon_pixmap) }, |
72 { XD_LISP_OBJECT, offsetof (struct x_frame, icon_pixmap_mask) }, | |
73 { XD_END } | |
74 }; | |
75 | |
3092 | 76 #ifdef NEW_GC |
77 DEFINE_LRECORD_IMPLEMENTATION ("x-frame", x_frame, | |
78 1, /*dumpable-flag*/ | |
79 0, 0, 0, 0, 0, | |
80 x_frame_data_description_1, | |
81 Lisp_X_Frame); | |
82 #else /* not NEW_GC */ | |
1204 | 83 extern const struct sized_memory_description x_frame_data_description; |
84 | |
85 const struct sized_memory_description x_frame_data_description = { | |
86 sizeof (struct x_frame), x_frame_data_description_1 | |
87 }; | |
3092 | 88 #endif /* not NEW_GC */ |
1204 | 89 |
428 | 90 EXFUN (Fx_window_id, 1); |
91 | |
92 | |
93 /************************************************************************/ | |
94 /* helper functions */ | |
95 /************************************************************************/ | |
96 | |
97 /* Return the Emacs frame-object corresponding to an X window */ | |
98 struct frame * | |
99 x_window_to_frame (struct device *d, Window wdesc) | |
100 { | |
101 Lisp_Object tail, frame; | |
102 struct frame *f; | |
103 | |
104 /* This function was previously written to accept only a window argument | |
105 (and to loop over all devices looking for a matching window), but | |
106 that is incorrect because window ID's are not unique across displays. */ | |
107 | |
108 for (tail = DEVICE_FRAME_LIST (d); CONSP (tail); tail = XCDR (tail)) | |
109 { | |
110 frame = XCAR (tail); | |
111 if (!FRAMEP (frame)) | |
112 continue; | |
113 f = XFRAME (frame); | |
114 if (FRAME_X_P (f) && XtWindow (FRAME_X_TEXT_WIDGET (f)) == wdesc) | |
115 return f; | |
116 } | |
117 return 0; | |
118 } | |
119 | |
120 /* Like x_window_to_frame but also compares the window with the widget's | |
121 windows */ | |
122 struct frame * | |
123 x_any_window_to_frame (struct device *d, Window wdesc) | |
124 { | |
125 Widget w; | |
126 assert (DEVICE_X_P (d)); | |
127 | |
128 w = XtWindowToWidget (DEVICE_X_DISPLAY (d), wdesc); | |
129 | |
130 if (!w) | |
131 return 0; | |
132 | |
133 /* We used to map over all frames here and then map over all widgets | |
134 belonging to that frame. However it turns out that this was very fragile | |
442 | 135 as it requires our display structures to be in sync _and_ that the |
428 | 136 loop is told about every new widget somebody adds. Therefore we |
137 now let Xt find it for us (which does a bottom-up search which | |
138 could even be faster) */ | |
139 return x_any_widget_or_parent_to_frame (d, w); | |
140 } | |
141 | |
142 static struct frame * | |
143 x_find_frame_for_window (struct device *d, Window wdesc) | |
144 { | |
145 Lisp_Object tail, frame; | |
146 struct frame *f; | |
147 /* This function was previously written to accept only a window argument | |
148 (and to loop over all devices looking for a matching window), but | |
149 that is incorrect because window ID's are not unique across displays. */ | |
150 | |
151 for (tail = DEVICE_FRAME_LIST (d); CONSP (tail); tail = XCDR (tail)) | |
152 { | |
153 frame = XCAR (tail); | |
154 f = XFRAME (frame); | |
155 /* This frame matches if the window is any of its widgets. */ | |
156 if (wdesc == XtWindow (FRAME_X_SHELL_WIDGET (f)) || | |
157 wdesc == XtWindow (FRAME_X_CONTAINER_WIDGET (f)) || | |
158 wdesc == XtWindow (FRAME_X_TEXT_WIDGET (f))) | |
159 return f; | |
160 | |
161 /* Match if the window is one of the widgets at the top of the frame | |
162 (menubar, Energize psheets). */ | |
163 | |
164 /* Note: Jamie once said | |
165 | |
166 "Do *not* match if the window is this frame's psheet." | |
167 | |
168 But this is wrong and will screw up some functions that expect | |
169 x_any_window_to_frame() to work as advertised. I think the reason | |
170 for this statement is that, in the old (broken) event loop, where | |
171 not all events went through XtDispatchEvent(), psheet events | |
172 would incorrectly get sucked away by Emacs if this function matched | |
173 on psheet widgets. */ | |
174 | |
175 /* Note: that this called only from | |
176 x_any_widget_or_parent_to_frame it is unnecessary to iterate | |
177 over the top level widgets. */ | |
178 | |
179 /* Note: we use to special case scrollbars but this turns out to be a bad idea | |
180 because | |
181 1. We sometimes get events for _unmapped_ scrollbars and our | |
182 callers don't want us to fail. | |
183 2. Starting with the 21.2 widget stuff there are now loads of | |
184 widgets to check and it is easy to forget adding them in a loop here. | |
185 See x_any_window_to_frame | |
186 3. We pick up all widgets now anyway. */ | |
187 } | |
188 | |
189 return 0; | |
190 } | |
191 | |
192 struct frame * | |
193 x_any_widget_or_parent_to_frame (struct device *d, Widget widget) | |
194 { | |
195 while (widget) | |
196 { | |
197 struct frame *f = x_find_frame_for_window (d, XtWindow (widget)); | |
198 if (f) | |
199 return f; | |
200 widget = XtParent (widget); | |
201 } | |
202 | |
203 return 0; | |
204 } | |
205 | |
206 struct frame * | |
207 decode_x_frame (Lisp_Object frame) | |
208 { | |
209 if (NILP (frame)) | |
793 | 210 frame = wrap_frame (selected_frame ()); |
428 | 211 CHECK_LIVE_FRAME (frame); |
212 /* this will also catch dead frames, but putting in the above check | |
213 results in a more useful error */ | |
214 CHECK_X_FRAME (frame); | |
215 return XFRAME (frame); | |
216 } | |
217 | |
218 | |
219 /************************************************************************/ | |
220 /* window-manager interactions */ | |
221 /************************************************************************/ | |
222 | |
223 #if 0 | |
224 /* Not currently used. */ | |
225 | |
226 void | |
227 x_wm_mark_shell_size_user_specified (Widget wmshell) | |
228 { | |
2500 | 229 if (! XtIsWMShell (wmshell)) ABORT (); |
428 | 230 EmacsShellSetSizeUserSpecified (wmshell); |
231 } | |
232 | |
233 void | |
234 x_wm_mark_shell_position_user_specified (Widget wmshell) | |
235 { | |
2500 | 236 if (! XtIsWMShell (wmshell)) ABORT (); |
428 | 237 EmacsShellSetPositionUserSpecified (wmshell); |
238 } | |
239 | |
240 #endif | |
241 | |
242 void | |
243 x_wm_set_shell_iconic_p (Widget shell, int iconic_p) | |
244 { | |
2500 | 245 if (! XtIsWMShell (shell)) ABORT (); |
428 | 246 |
247 /* Because of questionable logic in Shell.c, this sequence can't work: | |
248 | |
249 w = XtCreatePopupShell (...); | |
250 Xt_SET_VALUE (w, XtNiconic, True); | |
251 XtRealizeWidget (w); | |
252 | |
253 The iconic resource is only consulted at initialization time (when | |
254 XtCreatePopupShell is called) instead of at realization time (just | |
255 before the window gets created, which would be more sensible) or | |
256 at management-time (just before the window gets mapped, which would | |
257 be most sensible of all). | |
258 | |
259 The bug is that Shell's SetValues method doesn't do anything to | |
260 w->wm.wm_hints.initial_state until after the widget has been realized. | |
261 Calls to XtSetValues are ignored in the window between creation and | |
262 realization. This is true of MIT X11R5 patch level 25, at least. | |
263 (Apparently some other versions of Xt don't have this bug?) | |
264 */ | |
265 Xt_SET_VALUE (shell, XtNiconic, iconic_p); | |
266 EmacsShellSmashIconicHint (shell, iconic_p); | |
267 } | |
268 | |
269 void | |
270 x_wm_set_cell_size (Widget wmshell, int cw, int ch) | |
271 { | |
272 Arg al [2]; | |
273 | |
274 if (!XtIsWMShell (wmshell)) | |
2500 | 275 ABORT (); |
428 | 276 if (cw <= 0 || ch <= 0) |
2500 | 277 ABORT (); |
428 | 278 |
4528
726060ee587c
First draft of g++ 4.3 warning removal patch. Builds. *Needs ChangeLogs.*
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4522
diff
changeset
|
279 Xt_SET_ARG (al[0], XtNwidthInc, cw); |
726060ee587c
First draft of g++ 4.3 warning removal patch. Builds. *Needs ChangeLogs.*
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4522
diff
changeset
|
280 Xt_SET_ARG (al[1], XtNheightInc, ch); |
428 | 281 XtSetValues (wmshell, al, 2); |
282 } | |
283 | |
284 void | |
285 x_wm_set_variable_size (Widget wmshell, int width, int height) | |
286 { | |
287 Arg al [2]; | |
288 | |
289 if (!XtIsWMShell (wmshell)) | |
2500 | 290 ABORT (); |
428 | 291 #ifdef DEBUG_GEOMETRY_MANAGEMENT |
292 /* See comment in EmacsShell.c */ | |
293 printf ("x_wm_set_variable_size: %d %d\n", width, height); | |
294 fflush (stdout); | |
295 #endif | |
296 | |
4528
726060ee587c
First draft of g++ 4.3 warning removal patch. Builds. *Needs ChangeLogs.*
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4522
diff
changeset
|
297 Xt_SET_ARG (al[0], XtNwidthCells, width); |
726060ee587c
First draft of g++ 4.3 warning removal patch. Builds. *Needs ChangeLogs.*
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4522
diff
changeset
|
298 Xt_SET_ARG (al[1], XtNheightCells, height); |
428 | 299 XtSetValues (wmshell, al, 2); |
300 } | |
301 | |
302 /* If the WM_PROTOCOLS property does not already contain WM_TAKE_FOCUS | |
303 and WM_DELETE_WINDOW, then add them. (They may already be present | |
304 because of the toolkit (Motif adds them, for example, but Xt doesn't). | |
305 */ | |
306 static void | |
307 x_wm_hack_wm_protocols (Widget widget) | |
308 { | |
309 Display *dpy = XtDisplay (widget); | |
310 struct device *d = get_device_from_display (dpy); | |
311 Window w = XtWindow (widget); | |
312 int need_delete = 1; | |
313 int need_focus = 1; | |
314 | |
315 assert (XtIsWMShell (widget)); | |
316 | |
317 { | |
1885 | 318 Atom type; |
428 | 319 int format = 0; |
320 unsigned long nitems = 0; | |
321 unsigned long bytes_after; | |
2367 | 322 Rawbyte *prop_return = 0; /* semantically a void* */ |
428 | 323 |
324 if (Success == XGetWindowProperty (dpy, w, DEVICE_XATOM_WM_PROTOCOLS (d), | |
325 0, 100, False, XA_ATOM, | |
326 &type, &format, &nitems, &bytes_after, | |
1885 | 327 &prop_return) |
428 | 328 && format == 32 && type == XA_ATOM) |
329 while (nitems > 0) | |
330 { | |
1885 | 331 Atom *atoms = (Atom *) prop_return; |
428 | 332 nitems--; |
1885 | 333 if (atoms[nitems] == DEVICE_XATOM_WM_DELETE_WINDOW (d)) |
428 | 334 need_delete = 0; |
1885 | 335 else if (atoms[nitems] == DEVICE_XATOM_WM_TAKE_FOCUS (d)) |
428 | 336 need_focus = 0; |
337 } | |
2367 | 338 if (prop_return) XFree ((CRawbyte *) prop_return); |
428 | 339 } |
340 { | |
341 Atom props [10]; | |
342 int count = 0; | |
343 if (need_delete) props[count++] = DEVICE_XATOM_WM_DELETE_WINDOW (d); | |
344 if (need_focus) props[count++] = DEVICE_XATOM_WM_TAKE_FOCUS (d); | |
345 if (count) | |
346 XChangeProperty (dpy, w, DEVICE_XATOM_WM_PROTOCOLS (d), XA_ATOM, 32, | |
2367 | 347 PropModeAppend, (Rawbyte *) props, count); |
428 | 348 } |
349 } | |
350 | |
351 static void | |
2367 | 352 x_wm_store_class_hints (Widget shell, Extbyte *frame_name) |
428 | 353 { |
354 Display *dpy = XtDisplay (shell); | |
2367 | 355 Extbyte *app_name, *app_class; |
428 | 356 XClassHint classhint; |
357 | |
358 if (!XtIsWMShell (shell)) | |
2500 | 359 ABORT (); |
428 | 360 |
361 XtGetApplicationNameAndClass (dpy, &app_name, &app_class); | |
362 classhint.res_name = frame_name; | |
363 classhint.res_class = app_class; | |
364 XSetClassHint (dpy, XtWindow (shell), &classhint); | |
365 } | |
366 | |
367 #ifndef HAVE_WMCOMMAND | |
2367 | 368 |
428 | 369 static void |
370 x_wm_maybe_store_wm_command (struct frame *f) | |
371 { | |
372 Widget w = FRAME_X_SHELL_WIDGET (f); | |
373 struct device *d = XDEVICE (FRAME_DEVICE (f)); | |
374 | |
375 if (!XtIsWMShell (w)) | |
2500 | 376 ABORT (); |
428 | 377 |
378 if (NILP (DEVICE_X_WM_COMMAND_FRAME (d))) | |
379 { | |
380 int argc; | |
2367 | 381 Wexttext **argv; |
428 | 382 make_argc_argv (Vcommand_line_args, &argc, &argv); |
383 XSetCommand (XtDisplay (w), XtWindow (w), argv, argc); | |
384 free_argc_argv (argv); | |
793 | 385 DEVICE_X_WM_COMMAND_FRAME (d) = wrap_frame (f); |
428 | 386 } |
387 } | |
388 | |
389 /* If we're deleting the frame on which the WM_COMMAND property has been | |
390 set, then move that property to another frame so that there is exactly | |
391 one frame that has that property set. | |
392 */ | |
393 static void | |
394 x_wm_maybe_move_wm_command (struct frame *f) | |
395 { | |
396 struct device *d = XDEVICE (FRAME_DEVICE (f)); | |
397 | |
398 /* There may not be a frame in DEVICE_X_WM_COMMAND_FRAME() | |
399 if we C-c'ed at startup at the right time. */ | |
400 if (FRAMEP (DEVICE_X_WM_COMMAND_FRAME (d)) | |
401 && f == XFRAME (DEVICE_X_WM_COMMAND_FRAME (d))) | |
402 { | |
403 Lisp_Object rest = DEVICE_FRAME_LIST (d); | |
404 DEVICE_X_WM_COMMAND_FRAME (d) = Qnil; | |
405 /* find some random other X frame that is not this one, or give up */ | |
406 /* skip non-top-level (ExternalClient) frames */ | |
407 while (!NILP (rest) && | |
408 (f == XFRAME (XCAR (rest)) || | |
409 !FRAME_X_TOP_LEVEL_FRAME_P (XFRAME (XCAR (rest))))) | |
410 rest = XCDR (rest); | |
411 if (NILP (rest)) | |
412 return; | |
413 f = XFRAME (XCAR (rest)); | |
414 | |
415 x_wm_maybe_store_wm_command (f); | |
416 | |
417 } | |
418 } | |
2367 | 419 |
428 | 420 #endif /* !HAVE_WMCOMMAND */ |
421 | |
593 | 422 int |
423 x_frame_window_state (struct frame *f) | |
428 | 424 { |
425 Atom actual_type; | |
426 int actual_format; | |
427 unsigned long nitems, bytesafter; | |
2367 | 428 Rawbyte *datap = 0; |
428 | 429 Widget widget; |
593 | 430 int result = -1; |
428 | 431 struct device *d = XDEVICE (FRAME_DEVICE (f)); |
432 | |
433 widget = FRAME_X_SHELL_WIDGET (f); | |
434 if (Success == XGetWindowProperty (XtDisplay (widget), XtWindow (widget), | |
435 DEVICE_XATOM_WM_STATE (d), 0, 2, False, | |
436 DEVICE_XATOM_WM_STATE (d), &actual_type, | |
437 &actual_format, &nitems, &bytesafter, | |
1885 | 438 &datap) |
428 | 439 && datap) |
440 { | |
1885 | 441 unsigned long *ul_result_ptr = (unsigned long *) datap; |
593 | 442 if (nitems <= 2) /* "suggested" by ICCCM version 1 */ |
1885 | 443 result = (int) ul_result_ptr[0]; |
2367 | 444 XFree ((CRawbyte *) datap); |
428 | 445 } |
593 | 446 |
428 | 447 return result; |
448 } | |
449 | |
593 | 450 static int |
451 x_frame_iconified_p (struct frame *f) | |
452 { | |
453 return x_frame_window_state (f) == IconicState; | |
454 } | |
455 | |
428 | 456 |
457 /************************************************************************/ | |
458 /* frame properties */ | |
459 /************************************************************************/ | |
460 | |
461 /* Connect the frame-property names (symbols) to the corresponding | |
462 X Resource Manager names. The name of a property, as a Lisp symbol, | |
793 | 463 has an `x-resource-name' property which is a Lisp string. */ |
428 | 464 |
465 static void | |
466 init_x_prop_symbols (void) | |
467 { | |
468 #define def(sym, rsrc) \ | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4790
diff
changeset
|
469 Fput (sym, Qx_resource_name, build_ascstring (rsrc)) |
428 | 470 #define defi(sym,rsrc) \ |
471 def (sym, rsrc); Fput (sym, Qintegerp, Qt) | |
472 | |
473 #if 0 /* this interferes with things. #### fix this right */ | |
474 def (Qminibuffer, XtNminibuffer); | |
475 def (Qunsplittable, XtNunsplittable); | |
476 #endif | |
477 defi(Qinternal_border_width, XtNinternalBorderWidth); | |
478 def (Qscrollbar_placement, XtNscrollBarPlacement); | |
479 defi(Qinter_line_space, XtNinterline); | |
480 /* font, foreground */ | |
481 def (Qiconic, XtNiconic); | |
482 def (Qbar_cursor, XtNbarCursor); | |
483 def (Qvisual_bell, XtNvisualBell); | |
484 defi(Qbell_volume, XtNbellVolume); | |
485 def (Qpointer_background, XtNpointerBackground); | |
486 def (Qpointer_color, XtNpointerColor); | |
487 def (Qtext_pointer, XtNtextPointer); | |
488 def (Qspace_pointer, XtNspacePointer); | |
489 def (Qmodeline_pointer, XtNmodeLinePointer); | |
490 def (Qgc_pointer, XtNgcPointer); | |
491 /* geometry, initial_geometry */ | |
492 def (Qinitially_unmapped, XtNinitiallyUnmapped); | |
493 /* preferred_width, preferred_height */ | |
494 def (Quse_backing_store, XtNuseBackingStore); | |
495 | |
496 /* inherited: */ | |
497 | |
498 def (Qborder_color, XtNborderColor); | |
499 defi(Qborder_width, XtNborderWidth); | |
500 defi(Qwidth, XtNwidth); | |
501 defi(Qheight, XtNheight); | |
502 defi(Qleft, XtNx); | |
503 defi(Qtop, XtNy); | |
504 | |
505 #undef def | |
3381 | 506 #undef defi |
428 | 507 } |
508 | |
509 static Lisp_Object | |
510 color_to_string (Widget w, unsigned long pixel) | |
511 { | |
867 | 512 Ibyte buf[255]; |
428 | 513 |
514 XColor color; | |
515 color.pixel = pixel; | |
516 XQueryColor (XtDisplay (w), w->core.colormap, &color); | |
771 | 517 qxesprintf (buf, "#%04x%04x%04x", color.red, color.green, color.blue); |
4953
304aebb79cd3
function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
518 return build_istring (buf); |
428 | 519 } |
520 | |
521 static void | |
522 x_get_top_level_position (Display *d, Window w, Position *x, Position *y) | |
523 { | |
524 Window root, parent = w, *children; | |
525 unsigned int nchildren; | |
526 XWindowAttributes xwa; | |
527 | |
528 do | |
529 { | |
530 w = parent; | |
531 if (!XQueryTree (d, w, &root, &parent, &children, &nchildren)) | |
532 { | |
533 *x = 0; | |
534 *y = 0; | |
535 return; | |
536 } | |
537 XFree (children); | |
538 } | |
539 while (root != parent); | |
540 XGetWindowAttributes (d, w, &xwa); | |
541 *x = xwa.x; | |
542 *y = xwa.y; | |
543 } | |
544 | |
545 #if 0 | |
546 static void | |
547 x_smash_bastardly_shell_position (Widget shell) | |
548 { | |
549 /* Naturally those bastards who wrote Xt couldn't be bothered | |
550 to learn about race conditions and such. We can't trust | |
551 the X and Y values to have any semblance of correctness, | |
552 so we smash the right values in place. */ | |
553 | |
554 /* We might be called before we've actually realized the window (if | |
555 we're checking for the minibuffer resource). This will bomb in | |
556 that case so we don't bother calling it. */ | |
557 if (XtWindow (shell)) | |
558 x_get_top_level_position (XtDisplay (shell), XtWindow (shell), | |
559 &shell->core.x, &shell->core.y); | |
560 } | |
561 #endif /* 0 */ | |
562 | |
563 static Lisp_Object | |
564 x_frame_property (struct frame *f, Lisp_Object property) | |
565 { | |
566 Widget shell = FRAME_X_SHELL_WIDGET (f); | |
567 EmacsFrame w = (EmacsFrame) FRAME_X_TEXT_WIDGET (f); | |
568 Widget gw = (Widget) w; | |
569 | |
570 if (EQ (Qleft, property) || EQ (Qtop, property)) | |
571 { | |
572 Position x, y; | |
573 if (!XtWindow(shell)) | |
574 return Qzero; | |
575 x_get_top_level_position (XtDisplay (shell), XtWindow (shell), &x, &y); | |
576 if (EQ (Qleft, property)) return make_int (x); | |
577 if (EQ (Qtop, property)) return make_int (y); | |
578 } | |
579 if (EQ (Qborder_width, property)) | |
580 return make_int (w->core.border_width); | |
581 if (EQ (Qinternal_border_width, property)) | |
582 return make_int (w->emacs_frame.internal_border_width); | |
583 if (EQ (Qborder_color, property)) | |
584 return color_to_string (gw, w->core.border_pixel); | |
585 if (EQ (Qinter_line_space, property)) | |
586 return make_int (w->emacs_frame.interline); | |
587 if (EQ (Qwindow_id, property)) | |
771 | 588 return Fx_window_id (wrap_frame (f)); |
428 | 589 |
590 return Qunbound; | |
591 } | |
592 | |
593 static int | |
2286 | 594 x_internal_frame_property_p (struct frame *UNUSED (f), Lisp_Object property) |
428 | 595 { |
596 return EQ (property, Qleft) | |
597 || EQ (property, Qtop) | |
598 || EQ (property, Qborder_width) | |
599 || EQ (property, Qinternal_border_width) | |
600 || EQ (property, Qborder_color) | |
601 || EQ (property, Qinter_line_space) | |
602 || EQ (property, Qwindow_id) | |
603 || STRINGP (property); | |
604 } | |
605 | |
606 static Lisp_Object | |
607 x_frame_properties (struct frame *f) | |
608 { | |
609 Lisp_Object props = Qnil; | |
610 Widget shell = FRAME_X_SHELL_WIDGET (f); | |
611 EmacsFrame w = (EmacsFrame) FRAME_X_TEXT_WIDGET (f); | |
612 Widget gw = (Widget) w; | |
613 Position x, y; | |
614 | |
771 | 615 props = cons3 (Qwindow_id, Fx_window_id (wrap_frame (f)), props); |
428 | 616 props = cons3 (Qinter_line_space, make_int (w->emacs_frame.interline), props); |
617 | |
618 props = cons3 (Qborder_color, | |
619 color_to_string (gw, w->core.border_pixel), props); | |
620 props = cons3 (Qinternal_border_width, | |
621 make_int (w->emacs_frame.internal_border_width), props); | |
622 props = cons3 (Qborder_width, make_int (w->core.border_width), props); | |
623 | |
624 if (!XtWindow(shell)) | |
625 x = y = 0; | |
626 else | |
627 x_get_top_level_position (XtDisplay (shell), XtWindow (shell), &x, &y); | |
628 | |
629 props = cons3 (Qtop, make_int (y), props); | |
630 props = cons3 (Qleft, make_int (x), props); | |
631 | |
632 return props; | |
633 } | |
634 | |
635 | |
636 /* Functions called only from `x_set_frame_properties' to set | |
637 individual properties. */ | |
638 | |
639 static void | |
867 | 640 x_set_frame_text_value (struct frame *f, Ibyte *value, |
428 | 641 String Xt_resource_name, |
642 String Xt_resource_encoding_name) | |
643 { | |
644 Atom encoding = XA_STRING; | |
645 String new_XtValue = (String) value; | |
646 String old_XtValue = NULL; | |
647 | |
648 #ifdef MULE | |
867 | 649 Ibyte *ptr; |
428 | 650 /* Optimize for common ASCII case */ |
651 for (ptr = value; *ptr; ptr++) | |
826 | 652 if (!byte_ascii_p (*ptr)) |
428 | 653 { |
654 encoding = DEVICE_XATOM_COMPOUND_TEXT (XDEVICE (FRAME_DEVICE (f))); | |
4981
4aebb0131297
Cleanups/renaming of EXTERNAL_TO_C_STRING and friends
Ben Wing <ben@xemacs.org>
parents:
4969
diff
changeset
|
655 new_XtValue = (String) ITEXT_TO_EXTERNAL (value, Qctext); |
428 | 656 break; |
657 } | |
658 #endif /* MULE */ | |
659 | |
440 | 660 /* #### Caching is device-independent - belongs in update_frame_title. */ |
428 | 661 Xt_GET_VALUE (FRAME_X_SHELL_WIDGET (f), Xt_resource_name, &old_XtValue); |
662 if (!old_XtValue || strcmp (new_XtValue, old_XtValue)) | |
663 { | |
664 Arg al[2]; | |
4528
726060ee587c
First draft of g++ 4.3 warning removal patch. Builds. *Needs ChangeLogs.*
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4522
diff
changeset
|
665 Xt_SET_ARG (al[0], Xt_resource_name, new_XtValue); |
726060ee587c
First draft of g++ 4.3 warning removal patch. Builds. *Needs ChangeLogs.*
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4522
diff
changeset
|
666 Xt_SET_ARG (al[1], Xt_resource_encoding_name, encoding); |
428 | 667 XtSetValues (FRAME_X_SHELL_WIDGET (f), al, 2); |
668 } | |
669 } | |
670 | |
671 static void | |
867 | 672 x_set_title_from_ibyte (struct frame *f, Ibyte *name) |
428 | 673 { |
674 x_set_frame_text_value (f, name, XtNtitle, XtNtitleEncoding); | |
675 } | |
676 | |
677 static void | |
867 | 678 x_set_icon_name_from_ibyte (struct frame *f, Ibyte *name) |
428 | 679 { |
680 x_set_frame_text_value (f, name, XtNiconName, XtNiconNameEncoding); | |
681 } | |
682 | |
683 /* Set the initial frame size as specified. This function is used | |
684 when the frame's widgets have not yet been realized. In this | |
685 case, it is not sufficient just to set the width and height of | |
686 the EmacsFrame widget, because they will be ignored when the | |
687 widget is realized (instead, the shell's geometry resource is | |
688 used). */ | |
689 | |
690 static void | |
691 x_set_initial_frame_size (struct frame *f, int flags, int x, int y, | |
647 | 692 int w, int h) |
428 | 693 { |
2367 | 694 Ascbyte shell_geom[255]; |
428 | 695 int xval, yval; |
2367 | 696 Ascbyte xsign, ysign; |
697 Boolbyte uspos = !!(flags & (XValue | YValue)); | |
698 Boolbyte ussize = !!(flags & (WidthValue | HeightValue)); | |
699 Ascbyte *temp; | |
428 | 700 |
701 /* assign the correct size to the EmacsFrame widget ... */ | |
702 EmacsFrameSetCharSize (FRAME_X_TEXT_WIDGET (f), w, h); | |
703 | |
704 /* and also set the WMShell's geometry */ | |
705 (flags & XNegative) ? (xval = -x, xsign = '-') : (xval = x, xsign = '+'); | |
706 (flags & YNegative) ? (yval = -y, ysign = '-') : (yval = y, ysign = '+'); | |
707 | |
708 if (uspos && ussize) | |
709 sprintf (shell_geom, "=%dx%d%c%d%c%d", w, h, xsign, xval, ysign, yval); | |
710 else if (uspos) | |
711 sprintf (shell_geom, "=%c%d%c%d", xsign, xval, ysign, yval); | |
712 else if (ussize) | |
713 sprintf (shell_geom, "=%dx%d", w, h); | |
714 | |
715 if (uspos || ussize) | |
716 { | |
2367 | 717 temp = xnew_ascbytes (1 + strlen (shell_geom)); |
428 | 718 strcpy (temp, shell_geom); |
719 FRAME_X_GEOM_FREE_ME_PLEASE (f) = temp; | |
720 } | |
721 else | |
722 temp = NULL; | |
723 | |
724 Xt_SET_VALUE (FRAME_X_SHELL_WIDGET (f), XtNgeometry, temp); | |
725 } | |
726 | |
727 /* Report to X that a frame property of frame S is being set or changed. | |
728 If the property is not specially recognized, do nothing. | |
729 */ | |
730 | |
731 static void | |
732 x_set_frame_properties (struct frame *f, Lisp_Object plist) | |
733 { | |
734 Position x, y; | |
735 Dimension width = 0, height = 0; | |
736 Bool width_specified_p = False; | |
737 Bool height_specified_p = False; | |
738 Bool x_position_specified_p = False; | |
739 Bool y_position_specified_p = False; | |
740 Bool internal_border_width_specified = False; | |
741 Lisp_Object tail; | |
3415 | 742 Widget w; |
743 | |
744 /* We can be called after the X IO error handler has seen a broken pipe on | |
745 the relevant display. Don't do anything in that case. */ | |
746 if (!FRAME_LIVE_P (f) || DEVICE_X_BEING_DELETED (XDEVICE (FRAME_DEVICE (f)))) | |
747 return; | |
748 | |
749 w = FRAME_X_TEXT_WIDGET (f); | |
428 | 750 |
751 for (tail = plist; !NILP (tail); tail = Fcdr (Fcdr (tail))) | |
752 { | |
753 Lisp_Object prop = Fcar (tail); | |
754 Lisp_Object val = Fcar (Fcdr (tail)); | |
755 | |
756 if (STRINGP (prop)) | |
757 { | |
2367 | 758 const Extbyte *extprop; |
428 | 759 |
760 if (XSTRING_LENGTH (prop) == 0) | |
761 continue; | |
762 | |
4981
4aebb0131297
Cleanups/renaming of EXTERNAL_TO_C_STRING and friends
Ben Wing <ben@xemacs.org>
parents:
4969
diff
changeset
|
763 extprop = LISP_STRING_TO_EXTERNAL (prop, Qxt_widget_arg_encoding); |
428 | 764 if (STRINGP (val)) |
765 { | |
442 | 766 const Extbyte *extval; |
665 | 767 Bytecount extvallen; |
428 | 768 |
2367 | 769 /* !!#### I seriously doubt there is a single external format |
770 for the value of a widget argument; it depends on the | |
771 semantics of the argument. So use of | |
772 Qxt_widget_arg_encoding is totally bogus. --ben */ | |
4981
4aebb0131297
Cleanups/renaming of EXTERNAL_TO_C_STRING and friends
Ben Wing <ben@xemacs.org>
parents:
4969
diff
changeset
|
773 LISP_STRING_TO_SIZED_EXTERNAL (val, extval, extvallen, |
4aebb0131297
Cleanups/renaming of EXTERNAL_TO_C_STRING and friends
Ben Wing <ben@xemacs.org>
parents:
4969
diff
changeset
|
774 Qxt_widget_arg_encoding); |
428 | 775 XtVaSetValues (w, XtVaTypedArg, extprop, |
2367 | 776 /* !!#### Verify this + 1 and document |
777 as zero-termination */ | |
428 | 778 XtRString, extval, extvallen + 1, |
3463 | 779 NULL); |
428 | 780 } |
781 else | |
782 XtVaSetValues (w, XtVaTypedArg, extprop, XtRInt, | |
783 XINT (val), sizeof (int), | |
3463 | 784 NULL); |
428 | 785 } |
786 else if (SYMBOLP (prop)) | |
787 { | |
788 Lisp_Object str = Fget (prop, Qx_resource_name, Qnil); | |
789 int int_p = !NILP (Fget (prop, Qintegerp, Qnil)); | |
2367 | 790 Extbyte *strext; |
428 | 791 |
792 if (NILP (prop) || NILP (str)) | |
793 { | |
794 /* Kludge to handle the font property. */ | |
795 if (EQ (prop, Qfont)) | |
796 { | |
797 /* If the value is not a string we silently ignore it. */ | |
798 if (STRINGP (val)) | |
799 { | |
800 Lisp_Object frm, font_spec; | |
801 | |
793 | 802 frm = wrap_frame (f); |
428 | 803 font_spec = Fget (Fget_face (Qdefault), Qfont, Qnil); |
804 | |
805 Fadd_spec_to_specifier (font_spec, val, frm, Qnil, Qnil); | |
806 update_frame_face_values (f); | |
807 } | |
808 | |
809 continue; | |
810 } | |
811 else | |
812 continue; | |
813 } | |
814 CHECK_STRING (str); | |
815 | |
816 /* Kludge the width/height so that we interpret them in characters | |
817 instead of pixels. Yuck yuck yuck. */ | |
2367 | 818 if (!qxestrcmp_ascii (XSTRING_DATA (str), "width")) |
428 | 819 { |
820 CHECK_INT (val); | |
821 width = XINT (val); | |
822 width_specified_p = True; | |
823 continue; | |
824 } | |
2367 | 825 if (!qxestrcmp_ascii (XSTRING_DATA (str), "height")) |
428 | 826 { |
827 CHECK_INT (val); | |
828 height = XINT (val); | |
829 height_specified_p = True; | |
830 continue; | |
831 } | |
832 /* Further kludge the x/y. */ | |
2367 | 833 if (!qxestrcmp_ascii (XSTRING_DATA (str), "x")) |
428 | 834 { |
835 CHECK_INT (val); | |
836 x = (Position) XINT (val); | |
837 x_position_specified_p = True; | |
838 continue; | |
839 } | |
2367 | 840 if (!qxestrcmp_ascii (XSTRING_DATA (str), "y")) |
428 | 841 { |
842 CHECK_INT (val); | |
843 y = (Position) XINT (val); | |
844 y_position_specified_p = True; | |
845 continue; | |
846 } | |
847 /* Have you figured out by now that this entire function is | |
848 one gigantic kludge? */ | |
2367 | 849 if (!qxestrcmp_ascii (XSTRING_DATA (str), "internalBorderWidth")) |
428 | 850 { |
851 internal_border_width_specified = True; | |
852 } | |
853 | |
4981
4aebb0131297
Cleanups/renaming of EXTERNAL_TO_C_STRING and friends
Ben Wing <ben@xemacs.org>
parents:
4969
diff
changeset
|
854 strext = LISP_STRING_TO_EXTERNAL (str, Qxt_widget_arg_encoding); |
428 | 855 if (int_p) |
856 { | |
857 CHECK_INT (val); | |
2367 | 858 Xt_SET_VALUE (w, strext, XINT (val)); |
428 | 859 } |
860 else if (EQ (val, Qt)) | |
861 { | |
2367 | 862 Xt_SET_VALUE (w, strext, True); /* XtN...*/ |
428 | 863 } |
864 else if (EQ (val, Qnil)) | |
865 { | |
2367 | 866 Xt_SET_VALUE (w, strext, False); /* XtN...*/ |
428 | 867 } |
868 else | |
869 { | |
2367 | 870 const Extbyte *extval; |
871 Bytecount extvallen; | |
2372 | 872 CHECK_STRING (val); |
2367 | 873 |
4981
4aebb0131297
Cleanups/renaming of EXTERNAL_TO_C_STRING and friends
Ben Wing <ben@xemacs.org>
parents:
4969
diff
changeset
|
874 LISP_STRING_TO_SIZED_EXTERNAL (val, extval, extvallen, |
4aebb0131297
Cleanups/renaming of EXTERNAL_TO_C_STRING and friends
Ben Wing <ben@xemacs.org>
parents:
4969
diff
changeset
|
875 Qxt_widget_arg_encoding); |
428 | 876 XtVaSetValues (w, XtVaTypedArg, |
877 /* XtN... */ | |
2367 | 878 strext, |
879 /* !!#### Verify this + 1 and document | |
880 as zero-termination */ | |
881 XtRString, extval, extvallen + 1, | |
3463 | 882 NULL); |
428 | 883 } |
884 | |
885 #ifdef HAVE_SCROLLBARS | |
2367 | 886 if (!qxestrcmp_ascii (XSTRING_DATA (str), "scrollBarWidth") |
887 || !qxestrcmp_ascii (XSTRING_DATA (str), "scrollBarHeight")) | |
428 | 888 { |
889 x_update_frame_scrollbars (f); | |
890 } | |
891 #endif /* HAVE_SCROLLBARS */ | |
892 } | |
893 } | |
894 | |
895 /* Kludge kludge kludge. We need to deal with the size and position | |
896 specially. */ | |
897 { | |
898 int size_specified_p = width_specified_p || height_specified_p; | |
899 int position_specified_p = x_position_specified_p || | |
900 y_position_specified_p; | |
901 | |
902 if (!width_specified_p) | |
903 width = FRAME_WIDTH (f); | |
904 if (!height_specified_p) | |
905 height = FRAME_HEIGHT (f); | |
906 | |
907 /* Kludge kludge kludge kludge. */ | |
908 if (position_specified_p && | |
909 (!x_position_specified_p || !y_position_specified_p)) | |
910 { | |
911 Position dummy; | |
912 Widget shell = FRAME_X_SHELL_WIDGET (f); | |
913 x_get_top_level_position (XtDisplay (shell), XtWindow (shell), | |
914 (x_position_specified_p ? &dummy : &x), | |
915 (y_position_specified_p ? &dummy : &y)); | |
916 #if 0 | |
917 x = (int) (FRAME_X_SHELL_WIDGET (f)->core.x); | |
918 y = (int) (FRAME_X_SHELL_WIDGET (f)->core.y); | |
919 #endif | |
920 } | |
921 | |
922 if (!f->init_finished) | |
923 { | |
924 int flags = (size_specified_p ? WidthValue | HeightValue : 0) | | |
925 (position_specified_p ? | |
926 XValue | YValue | (x < 0 ? XNegative : 0) | (y < 0 ? YNegative : 0) | |
927 : 0); | |
928 if (size_specified_p | |
929 || position_specified_p | |
930 || internal_border_width_specified) | |
931 x_set_initial_frame_size (f, flags, x, y, width, height); | |
932 } | |
933 else | |
934 { | |
935 if (size_specified_p || internal_border_width_specified) | |
936 { | |
793 | 937 Lisp_Object frame = wrap_frame (f); |
938 | |
428 | 939 Fset_frame_size (frame, make_int (width), |
940 make_int (height), Qnil); | |
941 } | |
942 if (position_specified_p) | |
943 { | |
793 | 944 Lisp_Object frame = wrap_frame (f); |
945 | |
428 | 946 Fset_frame_position (frame, make_int (x), make_int (y)); |
947 } | |
948 } | |
949 } | |
950 } | |
951 | |
952 static int frame_title_format_already_set; | |
953 | |
954 static void | |
955 maybe_set_frame_title_format (Widget shell) | |
956 { | |
957 | |
958 /* Only do this if this is the first X frame we're creating. | |
959 | |
960 If the *title resource (or -title option) was specified, then | |
961 set frame-title-format to its value. | |
962 */ | |
963 | |
964 if (!frame_title_format_already_set) | |
965 { | |
966 /* No doubt there's a less stupid way to do this. */ | |
2367 | 967 Extbyte *results[2]; |
968 XtResource resources[2]; | |
969 results[0] = results[1] = 0; | |
970 resources[0].resource_name = XtNtitle; | |
971 resources[0].resource_class = XtCTitle; | |
972 resources[0].resource_type = XtRString; | |
973 resources[0].resource_size = sizeof (String); | |
974 resources[0].resource_offset = 0; | |
975 resources[0].default_type = XtRString; | |
976 resources[0].default_addr = 0; | |
977 resources[1].resource_name = XtNiconName; | |
978 resources[1].resource_class = XtCIconName; | |
979 resources[1].resource_type = XtRString; | |
980 resources[1].resource_size = sizeof (String); | |
981 resources[1].resource_offset = sizeof (Extbyte *); | |
982 resources[1].default_type = XtRString; | |
983 resources[1].default_addr = 0; | |
428 | 984 XtGetSubresources (XtParent (shell), (XtPointer) results, |
985 shell->core.name, | |
986 shell->core.widget_class->core_class.class_name, | |
987 resources, XtNumber (resources), 0, 0); | |
988 if (results[0]) | |
4953
304aebb79cd3
function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
989 Vframe_title_format = build_extstring (results[0], Qctext); |
428 | 990 if (results[1]) |
4953
304aebb79cd3
function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
991 Vframe_icon_title_format = build_extstring (results[1], Qctext); |
428 | 992 } |
993 | |
994 frame_title_format_already_set = 1; | |
995 } | |
996 | |
4790
bc4f2511bbea
Remove support for the OffiX drag-and-drop protocol. See xemacs-patches
Jerry James <james@xemacs.org>
parents:
4769
diff
changeset
|
997 #if defined (HAVE_CDE) |
2367 | 998 |
999 static Extbyte * | |
1000 start_drag_internal_1 (Lisp_Object event, Lisp_Object data, | |
1001 Lisp_Object encoding, XEvent *x_event, int listp, | |
1002 Widget *wid_out, Bytecount *len_out, | |
1003 int *num_items_out) | |
1004 { | |
1005 struct frame *f; | |
1006 Widget wid; | |
1007 struct device *d; | |
1008 struct x_device *xd; | |
1009 XWindowAttributes win_attrib; | |
1010 int modifier = 0, state = 0; | |
1011 Extbyte *dnd_data; | |
1012 Lisp_Event *lisp_event; | |
1013 | |
1014 CHECK_EVENT (event); | |
1015 lisp_event = XEVENT (event); | |
1016 if (EVENT_TYPE (lisp_event) != button_press_event) | |
1017 invalid_argument ("Need button-press event for drag", event); | |
1018 f = decode_x_frame (FW_FRAME (EVENT_CHANNEL (lisp_event))); | |
1019 wid = FRAME_X_TEXT_WIDGET (f); | |
1020 d = XDEVICE (FRAME_DEVICE (f)); | |
1021 xd = DEVICE_X_DATA (d); | |
1022 *num_items_out = 0; | |
1023 | |
1024 if (listp) | |
1025 { | |
1026 DECLARE_EISTRING (ei); | |
1027 | |
1028 EXTERNAL_LIST_LOOP_2 (elt, data) | |
1029 { | |
1030 CHECK_STRING (elt); | |
1031 eicat_lstr (ei, elt); | |
1032 eicat_ch (ei, '\0'); | |
1033 (*num_items_out)++; | |
1034 } | |
1035 eicat_ch (ei, '\0'); | |
4981
4aebb0131297
Cleanups/renaming of EXTERNAL_TO_C_STRING and friends
Ben Wing <ben@xemacs.org>
parents:
4969
diff
changeset
|
1036 TO_EXTERNAL_FORMAT (DATA, (eidata (ei), eilen (ei)), |
4aebb0131297
Cleanups/renaming of EXTERNAL_TO_C_STRING and friends
Ben Wing <ben@xemacs.org>
parents:
4969
diff
changeset
|
1037 MALLOC, (dnd_data, *len_out), |
4aebb0131297
Cleanups/renaming of EXTERNAL_TO_C_STRING and friends
Ben Wing <ben@xemacs.org>
parents:
4969
diff
changeset
|
1038 encoding); |
2367 | 1039 } |
1040 else | |
1041 { | |
1042 CHECK_STRING (data); | |
1043 LISP_STRING_TO_SIZED_EXTERNAL_MALLOC (data, dnd_data, *len_out, | |
1044 encoding); | |
1045 *len_out += EXTTEXT_ZTERM_SIZE; | |
1046 (*num_items_out)++; | |
1047 } | |
1048 | |
1049 /* not so gross hack that converts an emacs event back to a XEvent */ | |
1050 | |
1051 x_event->xbutton.type = ButtonPress; | |
1052 x_event->xbutton.send_event = False; | |
1053 x_event->xbutton.display = XtDisplayOfObject (wid); | |
1054 x_event->xbutton.window = XtWindowOfObject (wid); | |
1055 x_event->xbutton.root = XRootWindow (x_event->xbutton.display, 0); | |
1056 x_event->xbutton.subwindow = 0; | |
1057 x_event->xbutton.time = lisp_event->timestamp; | |
1058 x_event->xbutton.x = EVENT_BUTTON_X (lisp_event); | |
1059 x_event->xbutton.y = EVENT_BUTTON_Y (lisp_event); | |
1060 if (Success == XGetWindowAttributes (x_event->xbutton.display, | |
1061 x_event->xbutton.window, | |
1062 &win_attrib)) | |
1063 { | |
1064 x_event->xbutton.x_root = win_attrib.x + EVENT_BUTTON_X (lisp_event); | |
1065 x_event->xbutton.y_root = win_attrib.y + EVENT_BUTTON_Y (lisp_event); | |
1066 } | |
1067 else | |
1068 { | |
1069 x_event->xbutton.x_root = EVENT_BUTTON_X (lisp_event); /* this is wrong */ | |
1070 x_event->xbutton.y_root = EVENT_BUTTON_Y (lisp_event); | |
1071 } | |
1072 | |
1073 modifier = EVENT_BUTTON_MODIFIERS (lisp_event); | |
1074 if (modifier & XEMACS_MOD_SHIFT) state |= ShiftMask; | |
1075 if (modifier & XEMACS_MOD_CONTROL) state |= ControlMask; | |
1076 if (modifier & XEMACS_MOD_META) state |= xd->MetaMask; | |
1077 if (modifier & XEMACS_MOD_SUPER) state |= xd->SuperMask; | |
1078 if (modifier & XEMACS_MOD_HYPER) state |= xd->HyperMask; | |
1079 if (modifier & XEMACS_MOD_ALT) state |= xd->AltMask; | |
1080 state |= Button1Mask << (EVENT_BUTTON_BUTTON (lisp_event) - 1); | |
1081 | |
1082 x_event->xbutton.state = state; | |
1083 x_event->xbutton.button = EVENT_BUTTON_BUTTON (lisp_event); | |
1084 x_event->xbutton.same_screen = True; | |
1085 | |
1086 *wid_out = wid; | |
1087 return dnd_data; | |
1088 } | |
1089 | |
4790
bc4f2511bbea
Remove support for the OffiX drag-and-drop protocol. See xemacs-patches
Jerry James <james@xemacs.org>
parents:
4769
diff
changeset
|
1090 #endif /* defined (HAVE_CDE) */ |
2367 | 1091 |
428 | 1092 #ifdef HAVE_CDE |
1093 #include <Dt/Dt.h> | |
1094 #include <Dt/Dnd.h> | |
1095 | |
1096 static Widget CurrentDragWidget = NULL; | |
1097 static XtCallbackRec dnd_convert_cb_rec[2]; | |
1098 static XtCallbackRec dnd_destroy_cb_rec[2]; | |
1099 static int drag_not_done = 0; | |
1100 | |
1101 static void | |
1102 x_cde_destroy_callback (Widget widget, XtPointer clientData, | |
1103 XtPointer callData) | |
1104 { | |
1105 DtDndDragFinishCallbackStruct *dragFinishInfo = | |
2367 | 1106 (DtDndDragFinishCallbackStruct *) callData; |
428 | 1107 DtDndContext *dragData = dragFinishInfo->dragData; |
1108 int i; | |
1109 | |
1110 /* free the items */ | |
1111 if (callData != NULL && dragData != NULL) | |
1112 { | |
1113 if (dragData->protocol == DtDND_BUFFER_TRANSFER) | |
1114 { | |
1115 for (i = 0; i < dragData->numItems; i++) | |
1116 { | |
2367 | 1117 XtFree ((CRawbyte *) dragData->data.buffers[i].bp); |
428 | 1118 if (dragData->data.buffers[i].name) |
1119 XtFree(dragData->data.buffers[i].name); | |
1120 } | |
1121 } | |
1122 else | |
1123 { | |
1124 for (i = 0; i < dragData->numItems; i++) | |
1125 XtFree(dragData->data.files[i]); | |
1126 } | |
1127 } | |
1128 | |
1129 /* free the data string */ | |
4976
16112448d484
Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents:
4969
diff
changeset
|
1130 xfree (clientData); |
428 | 1131 |
1132 CurrentDragWidget = NULL; | |
1133 } | |
1134 | |
1135 static void | |
1136 x_cde_convert_callback (Widget widget, XtPointer clientData, | |
1137 XtPointer callData) | |
1138 { | |
1139 DtDndConvertCallbackStruct *convertInfo = | |
1140 (DtDndConvertCallbackStruct *) callData; | |
2367 | 1141 Extbyte *textdata = (Extbyte *) clientData; |
1142 Extbyte *textptr = NULL; | |
428 | 1143 int i; |
1144 | |
1145 if (convertInfo == NULL) | |
1146 { | |
1147 return; | |
1148 } | |
1149 | |
1150 if ((convertInfo->dragData->protocol != DtDND_BUFFER_TRANSFER | |
1151 && convertInfo->dragData->protocol != DtDND_FILENAME_TRANSFER) || | |
1152 (convertInfo->reason != DtCR_DND_CONVERT_DATA)) | |
1153 { | |
1154 return; | |
1155 } | |
1156 | |
2367 | 1157 for (textptr = textdata, i = 0; |
1158 i < convertInfo->dragData->numItems; | |
1159 textptr += strlen (textptr) + 1, i++) | |
428 | 1160 { |
1161 if (convertInfo->dragData->protocol == DtDND_BUFFER_TRANSFER) | |
1162 { | |
2367 | 1163 convertInfo->dragData->data.buffers[i].bp = XtNewString (textptr); |
1164 convertInfo->dragData->data.buffers[i].size = strlen (textptr); | |
428 | 1165 convertInfo->dragData->data.buffers[i].name = NULL; |
1166 } | |
1167 else | |
1168 { | |
2367 | 1169 convertInfo->dragData->data.files[i] = XtNewString (textptr); |
428 | 1170 } |
1171 } | |
1172 | |
1173 convertInfo->status = DtDND_SUCCESS; | |
1174 } | |
1175 | |
1176 static Lisp_Object | |
2367 | 1177 abort_current_drag (Lisp_Object arg) |
428 | 1178 { |
1179 if (CurrentDragWidget && drag_not_done) | |
1180 { | |
1181 XmDragCancel(CurrentDragWidget); | |
1182 CurrentDragWidget = NULL; | |
1183 } | |
1184 return arg; | |
1185 } | |
1186 | |
1187 DEFUN ("cde-start-drag-internal", Fcde_start_drag_internal, 3, 3, 0, /* | |
1188 Start a CDE drag from a buffer. | |
1189 First argument is the event that started the drag (must be a | |
1190 button-press-event), | |
1191 second arg defines if the data should be treated as a buffer or | |
1192 a filename transfer (set to nil for buffer transfer), | |
1193 and the third argument is a list of data strings. | |
1194 WARNING: can only handle plain/text and file: transfers! | |
1195 */ | |
1196 (event, dragtype, dragdata)) | |
1197 { | |
2367 | 1198 Extbyte *dnd_data; |
1199 XEvent x_event; | |
1200 Bytecount dnd_len; | |
1201 Widget wid; | |
1202 int num_items; | |
1203 | |
1204 dnd_data = start_drag_internal_1 (event, dragdata, Qdt_dnd_encoding, | |
1205 &x_event, 1, | |
1206 &wid, &dnd_len, &num_items); | |
1207 | |
1208 dnd_convert_cb_rec[0].callback = x_cde_convert_callback; | |
1209 dnd_convert_cb_rec[0].closure = (XtPointer) dnd_data; | |
1210 dnd_convert_cb_rec[1].callback = NULL; | |
1211 dnd_convert_cb_rec[1].closure = NULL; | |
1212 | |
1213 dnd_destroy_cb_rec[0].callback = x_cde_destroy_callback; | |
1214 dnd_destroy_cb_rec[0].closure = (XtPointer) dnd_data; | |
1215 dnd_destroy_cb_rec[1].callback = NULL; | |
1216 dnd_destroy_cb_rec[1].closure = NULL; | |
1217 | |
1218 CurrentDragWidget = | |
1219 DtDndDragStart (wid, &x_event, | |
1220 (NILP (dragtype) ? DtDND_BUFFER_TRANSFER : | |
1221 DtDND_FILENAME_TRANSFER), | |
1222 num_items, | |
1223 XmDROP_COPY, | |
1224 dnd_convert_cb_rec, | |
1225 dnd_destroy_cb_rec, | |
1226 NULL, 0); | |
1227 | |
4976
16112448d484
Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents:
4969
diff
changeset
|
1228 xfree (dnd_data); |
2367 | 1229 |
1230 return num_items ? Qt : Qnil; | |
428 | 1231 } |
1232 | |
1233 static void | |
1234 x_cde_transfer_callback (Widget widget, XtPointer clientData, | |
1235 XtPointer callData) | |
1236 { | |
2367 | 1237 int ii, enqueue = 1; |
428 | 1238 Lisp_Object frame = Qnil; |
1239 Lisp_Object l_type = Qnil; | |
1240 Lisp_Object l_data = Qnil; | |
1241 DtDndTransferCallbackStruct *transferInfo = NULL; | |
1242 struct gcpro gcpro1, gcpro2, gcpro3; | |
1243 | |
1244 /* | |
1245 this needs to be changed to the new protocol: | |
1246 - we need the button, modifier and pointer states to create a | |
1247 correct misc_user_event | |
1248 - the data must be converted to the new format (URL/MIME) | |
1249 */ | |
1250 /* return; */ | |
1251 | |
1252 transferInfo = (DtDndTransferCallbackStruct *) callData; | |
1253 if (transferInfo == NULL) | |
1254 return; | |
1255 | |
1256 GCPRO3 (frame, l_type, l_data); | |
1257 | |
771 | 1258 frame = wrap_frame ((struct frame *) clientData); |
428 | 1259 |
1260 if (transferInfo->dropData->protocol == DtDND_FILENAME_TRANSFER) | |
1261 { | |
1262 l_type = Qdragdrop_URL; | |
1263 | |
1264 for (ii = 0; ii < transferInfo->dropData->numItems; ii++) | |
1265 { | |
2367 | 1266 Ibyte *fileint; |
1267 Ibyte *hurl; | |
1268 | |
4981
4aebb0131297
Cleanups/renaming of EXTERNAL_TO_C_STRING and friends
Ben Wing <ben@xemacs.org>
parents:
4969
diff
changeset
|
1269 fileint = |
4aebb0131297
Cleanups/renaming of EXTERNAL_TO_C_STRING and friends
Ben Wing <ben@xemacs.org>
parents:
4969
diff
changeset
|
1270 EXTERNAL_TO_ITEXT (transferInfo->dropData->data.files[ii], |
4aebb0131297
Cleanups/renaming of EXTERNAL_TO_C_STRING and friends
Ben Wing <ben@xemacs.org>
parents:
4969
diff
changeset
|
1271 Qfile_name); |
2367 | 1272 |
1273 hurl = dnd_url_hexify_string (fileint, "file:"); | |
4953
304aebb79cd3
function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
1274 l_data = Fcons (build_istring (hurl), l_data); |
4976
16112448d484
Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents:
4969
diff
changeset
|
1275 xfree (hurl); |
428 | 1276 } |
1277 } | |
1278 else if (transferInfo->dropData->protocol == DtDND_BUFFER_TRANSFER) | |
1279 { | |
2367 | 1280 int speccount = specpdl_depth (); |
1281 | |
1282 /* !!#### Problem: all buffers a treated as text/plain!!! | |
1283 Not appropriate for intl text. Note that there is a function | |
1284 DtDtsBufferToDataType(), but I don't know what the possible | |
1285 return values are. | |
1286 Solution (?): Also support DtDND_TEXT_TRANSFER (compound text) | |
428 | 1287 perhaps implementation of the Motif protocol |
1288 (which is the base of CDE) will clear this */ | |
1289 l_type = Qdragdrop_MIME; | |
2367 | 1290 record_unwind_protect (abort_current_drag, Qnil); |
428 | 1291 drag_not_done = 1; |
1292 for (ii = 0; ii < transferInfo->dropData->numItems; ii++) | |
1293 { | |
1294 /* let us forget this name thing for now... */ | |
1295 /* filePath = transferInfo->dropData->data.buffers[ii].name; | |
1296 path = (filePath == NULL) ? Qnil | |
4953
304aebb79cd3
function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
1297 : build_extstring (filePath, Q???); */ |
428 | 1298 /* what, if the data is no text, and how can I tell it? */ |
2367 | 1299 l_data = |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4790
diff
changeset
|
1300 Fcons (list3 (list1 (build_ascstring ("text/plain")), |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4790
diff
changeset
|
1301 build_ascstring ("8bit"), |
4953
304aebb79cd3
function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
1302 make_extstring |
2367 | 1303 (transferInfo->dropData->data.buffers[ii].bp, |
1304 transferInfo->dropData->data.buffers[ii].size, | |
1305 /* !!#### what goes here? */ | |
1306 Qdt_dnd_encoding)), | |
1307 l_data); | |
428 | 1308 } |
1309 drag_not_done = 0; | |
771 | 1310 unbind_to (speccount); |
428 | 1311 } |
1312 else /* the other cases: NOOP_TRANSFER */ | |
2367 | 1313 enqueue = 0; |
428 | 1314 |
1315 /* The Problem: no button and mods from CDE... */ | |
1316 if (enqueue) | |
2367 | 1317 enqueue_misc_user_event_pos (frame, Qdragdrop_drop_dispatch, |
1318 Fcons (l_type, l_data), | |
1319 0 /* this is the button */, | |
1320 0 /* these are the mods */, | |
1321 transferInfo->x, | |
1322 transferInfo->y); | |
428 | 1323 |
1324 UNGCPRO; | |
1325 return; | |
1326 } | |
1327 #endif /* HAVE_CDE */ | |
1328 | |
1329 | |
1330 /************************************************************************/ | |
1331 /* widget creation */ | |
1332 /************************************************************************/ | |
1333 | |
1334 /* The widget hierarchy is | |
1335 | |
1336 argv[0] shell container FRAME-NAME | |
1337 ApplicationShell EmacsShell EmacsManager EmacsFrame | |
1338 | |
1339 We accept geometry specs in this order: | |
1340 | |
1341 *FRAME-NAME.geometry | |
1342 *EmacsFrame.geometry | |
1343 Emacs.geometry | |
1344 | |
1345 Other possibilities for widget hierarchies might be | |
1346 | |
1347 argv[0] frame container FRAME-NAME | |
1348 ApplicationShell EmacsShell EmacsManager EmacsFrame | |
1349 or | |
1350 argv[0] FRAME-NAME container FRAME-NAME | |
1351 ApplicationShell EmacsShell EmacsManager EmacsFrame | |
1352 or | |
1353 argv[0] FRAME-NAME container emacsTextPane | |
1354 ApplicationShell EmacsShell EmacsManager EmacsFrame | |
1355 | |
1356 #ifdef EXTERNAL_WIDGET | |
1357 The ExternalShell widget is simply a replacement for the Shell widget | |
1358 which is able to deal with using an externally-supplied window instead | |
1359 of always creating its own. | |
1360 #endif | |
1361 | |
1362 */ | |
1363 | |
1364 #ifdef EXTERNAL_WIDGET | |
1365 | |
1366 static int | |
1367 is_valid_window (Window w, struct device *d) | |
1368 { | |
1369 XWindowAttributes xwa; | |
1370 Display *dpy = DEVICE_X_DISPLAY (d); | |
1371 | |
1372 expect_x_error (dpy); | |
1373 XGetWindowAttributes (dpy, w, &xwa); | |
1374 return !x_error_occurred_p (dpy); | |
1375 } | |
1376 | |
1377 #endif /* EXTERNAL_WIDGET */ | |
1378 | |
1379 /* This sends a synthetic mouse-motion event to the frame, if the mouse | |
1380 is over the frame. This ensures that the cursor gets set properly | |
1381 before the user moves the mouse for the first time. */ | |
1382 | |
1383 static void | |
2286 | 1384 x_send_synthetic_mouse_event (struct frame *UNUSED (f)) |
428 | 1385 { |
1386 /* #### write this function. */ | |
1387 } | |
1388 | |
1389 static int | |
1390 first_x_frame_p (struct frame *f) | |
1391 { | |
1392 Lisp_Object rest = DEVICE_FRAME_LIST (XDEVICE (f->device)); | |
1393 while (!NILP (rest) && | |
1394 (f == XFRAME (XCAR (rest)) || | |
1395 !FRAME_X_P (XFRAME (XCAR (rest))))) | |
1396 rest = XCDR (rest); | |
1397 return NILP (rest); | |
1398 } | |
1399 | |
1400 /* Figure out what size the EmacsFrame widget should initially be, | |
1401 and set it. Should be called after the default font has been | |
1402 determined but before the widget has been realized. */ | |
1403 | |
1404 static void | |
1405 x_initialize_frame_size (struct frame *f) | |
1406 { | |
1407 /* Geometry of the AppShell */ | |
1408 int app_flags = 0; | |
1409 int app_x = 0; | |
1410 int app_y = 0; | |
1411 unsigned int app_w = 0; | |
1412 unsigned int app_h = 0; | |
1413 | |
1414 /* Geometry of the EmacsFrame */ | |
1415 int frame_flags = 0; | |
1416 int frame_x = 0; | |
1417 int frame_y = 0; | |
1418 unsigned int frame_w = 0; | |
1419 unsigned int frame_h = 0; | |
1420 | |
1421 /* Hairily merged geometry */ | |
1422 int x = 0; | |
1423 int y = 0; | |
1424 unsigned int w = 80; | |
1425 unsigned int h = 40; | |
1426 int flags = 0; | |
1427 | |
2367 | 1428 Ascbyte *geom = 0, *ew_geom = 0; |
428 | 1429 Boolean iconic_p = False, ew_iconic_p = False; |
1430 | |
1431 Widget wmshell = FRAME_X_SHELL_WIDGET (f); | |
1432 /* #### This may not be an ApplicationShell any more, with the 'popup | |
1433 frame property. */ | |
1434 Widget app_shell = XtParent (wmshell); | |
1435 Widget ew = FRAME_X_TEXT_WIDGET (f); | |
1436 | |
2747 | 1437 /* set the position of the frame's root window now. When the |
1438 frame was created, the position was initialized to (0,0). */ | |
428 | 1439 { |
1440 struct window *win = XWINDOW (f->root_window); | |
1441 | |
442 | 1442 WINDOW_LEFT (win) = FRAME_LEFT_BORDER_END (f) |
1443 + FRAME_LEFT_GUTTER_BOUNDS (f); | |
1444 WINDOW_TOP (win) = FRAME_TOP_BORDER_END (f) | |
1445 + FRAME_TOP_GUTTER_BOUNDS (f); | |
428 | 1446 |
1447 if (!NILP (f->minibuffer_window)) | |
1448 { | |
1449 win = XWINDOW (f->minibuffer_window); | |
442 | 1450 WINDOW_LEFT (win) = FRAME_LEFT_BORDER_END (f) |
1451 + FRAME_LEFT_GUTTER_BOUNDS (f); | |
428 | 1452 } |
1453 } | |
1454 | |
1455 #ifdef EXTERNAL_WIDGET | |
1456 /* If we're an external widget, then the size of the frame is predetermined | |
1457 (by the client) and is not our decision to make. */ | |
1458 if (FRAME_X_EXTERNAL_WINDOW_P (f)) | |
1459 return; | |
1460 #endif | |
1461 | |
1462 #if 0 | |
1463 /* #### this junk has not been tested; therefore it's | |
1464 probably wrong. Doesn't really matter at this point because | |
1465 currently all frames are either top-level or external widgets. */ | |
1466 | |
1467 /* If we're not our own top-level window, then we shouldn't go messing around | |
1468 with top-level shells or "Emacs.geometry" or any such stuff. Therefore, | |
1469 we do as follows to determine the size of the frame: | |
1470 | |
1471 1) If a value for the frame's "geometry" resource was specified, then | |
1472 use it. (This specifies a size in characters.) | |
1473 2) Else, if the "width" and "height" resources were specified, then | |
1474 leave them alone. (This is a value in pixels. Sorry, we can't break | |
1475 Xt conventions here.) | |
1476 3) Else, assume a size of 64x12. (This is somewhat arbitrary, but | |
1477 it's unlikely that a size of 80x40 is desirable because we're probably | |
1478 inside of a dialog box.) | |
1479 | |
1480 Set the widget's x, y, height, and width as determined. Don't set the | |
1481 top-level container widget, because we don't necessarily know what it | |
1482 is. (Assume it is smart and pays attention to our values.) | |
1483 */ | |
1484 | |
1485 if (!FRAME_X_TOP_LEVEL_FRAME_P (f)) | |
1486 { | |
1487 Xt_GET_VALUE (ew, XtNgeometry, &ew_geom); | |
1488 if (ew_geom) | |
1489 frame_flags = XParseGeometry (ew_geom, | |
1490 &frame_x, &frame_y, | |
1491 &frame_w, &frame_h); | |
1492 if (! (frame_flags & (WidthValue | HeightValue))) | |
1493 { | |
1494 Arg al[2]; | |
4528
726060ee587c
First draft of g++ 4.3 warning removal patch. Builds. *Needs ChangeLogs.*
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4522
diff
changeset
|
1495 Xt_SET_ARG (al [0], XtNwidth, &frame_w); |
726060ee587c
First draft of g++ 4.3 warning removal patch. Builds. *Needs ChangeLogs.*
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4522
diff
changeset
|
1496 Xt_SET_ARG (al [1], XtNheight, &frame_h); |
428 | 1497 XtGetValues (ew, al, 2); |
1498 if (!frame_w && !frame_h) | |
1499 { | |
1500 frame_w = 64; | |
1501 frame_h = 12; | |
1502 frame_flags |= WidthValue | HeightValue; | |
1503 } | |
1504 } | |
1505 if (frame_flags & (WidthValue | HeightValue)) | |
1506 EmacsFrameSetCharSize (ew, frame_w, frame_h); | |
1507 if (frame_flags & (XValue | YValue)) | |
1508 { | |
1509 Arg al[2]; | |
4528
726060ee587c
First draft of g++ 4.3 warning removal patch. Builds. *Needs ChangeLogs.*
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4522
diff
changeset
|
1510 Xt_SET_ARG (al [0], XtNwidth, &frame_w); |
726060ee587c
First draft of g++ 4.3 warning removal patch. Builds. *Needs ChangeLogs.*
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4522
diff
changeset
|
1511 Xt_SET_ARG (al [1], XtNheight, &frame_h); |
428 | 1512 XtGetValues (ew, al, 2); |
1513 | |
1514 if (frame_flags & XNegative) | |
1515 frame_x += frame_w; | |
1516 if (frame_flags & YNegative) | |
1517 frame_y += frame_h; | |
1518 | |
4528
726060ee587c
First draft of g++ 4.3 warning removal patch. Builds. *Needs ChangeLogs.*
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4522
diff
changeset
|
1519 Xt_SET_ARG (al [0], XtNx, frame_x); |
726060ee587c
First draft of g++ 4.3 warning removal patch. Builds. *Needs ChangeLogs.*
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4522
diff
changeset
|
1520 Xt_SET_ARG (al [1], XtNy, frame_y); |
428 | 1521 XtSetValues (ew, al, 2); |
1522 } | |
1523 return; | |
1524 } | |
1525 #endif | |
1526 | |
1527 /* OK, we're a top-level shell. */ | |
1528 | |
1529 if (!XtIsWMShell (wmshell)) | |
2500 | 1530 ABORT (); |
428 | 1531 |
1532 /* If the EmacsFrame doesn't have a geometry but the shell does, | |
1533 treat that as the geometry of the frame. | |
1534 (Is this bogus? I'm not sure.) */ | |
1535 | |
1536 Xt_GET_VALUE (ew, XtNgeometry, &ew_geom); | |
1537 if (!ew_geom) | |
1538 { | |
1539 Xt_GET_VALUE (wmshell, XtNgeometry, &geom); | |
1540 if (geom) | |
1541 { | |
1542 ew_geom = geom; | |
1543 Xt_SET_VALUE (ew, XtNgeometry, ew_geom); | |
1544 } | |
1545 } | |
1546 | |
1547 /* If the Shell is iconic, then the EmacsFrame is iconic. | |
1548 (Is this bogus? I'm not sure.) */ | |
1549 Xt_GET_VALUE (ew, XtNiconic, &ew_iconic_p); | |
1550 if (!ew_iconic_p) | |
1551 { | |
1552 Xt_GET_VALUE (wmshell, XtNiconic, &iconic_p); | |
1553 if (iconic_p) | |
1554 { | |
1555 ew_iconic_p = iconic_p; | |
1556 Xt_SET_VALUE (ew, XtNiconic, iconic_p); | |
1557 } | |
1558 } | |
1559 | |
1560 Xt_GET_VALUE (app_shell, XtNgeometry, &geom); | |
1561 if (geom) | |
1562 app_flags = XParseGeometry (geom, &app_x, &app_y, &app_w, &app_h); | |
1563 | |
1564 if (ew_geom) | |
1565 frame_flags = XParseGeometry (ew_geom, | |
1566 &frame_x, &frame_y, | |
1567 &frame_w, &frame_h); | |
1568 | |
1569 if (first_x_frame_p (f)) | |
1570 { | |
1571 /* If this is the first frame created: | |
1572 ==================================== | |
1573 | |
1574 - Use the ApplicationShell's size/position, if specified. | |
1575 (This is "Emacs.geometry", or the "-geometry" command line arg.) | |
1576 - Else use the EmacsFrame's size/position. | |
1577 (This is "*FRAME-NAME.geometry") | |
1578 | |
1579 - If the AppShell is iconic, the frame should be iconic. | |
1580 | |
1581 AppShell comes first so that -geometry always applies to the first | |
1582 frame created, even if there is an "every frame" entry in the | |
1583 resource database. | |
1584 */ | |
1585 if (app_flags & (XValue | YValue)) | |
1586 { | |
1587 x = app_x; y = app_y; | |
1588 flags |= (app_flags & (XValue | YValue | XNegative | YNegative)); | |
1589 } | |
1590 else if (frame_flags & (XValue | YValue)) | |
1591 { | |
1592 x = frame_x; y = frame_y; | |
1593 flags |= (frame_flags & (XValue | YValue | XNegative | YNegative)); | |
1594 } | |
1595 | |
1596 if (app_flags & (WidthValue | HeightValue)) | |
1597 { | |
1598 w = app_w; h = app_h; | |
1599 flags |= (app_flags & (WidthValue | HeightValue)); | |
1600 } | |
1601 else if (frame_flags & (WidthValue | HeightValue)) | |
1602 { | |
1603 w = frame_w; h = frame_h; | |
1604 flags |= (frame_flags & (WidthValue | HeightValue)); | |
1605 } | |
1606 | |
1607 /* If the AppShell is iconic, then the EmacsFrame is iconic. */ | |
1608 if (!ew_iconic_p) | |
1609 { | |
1610 Xt_GET_VALUE (app_shell, XtNiconic, &iconic_p); | |
1611 if (iconic_p) | |
1612 { | |
1613 ew_iconic_p = iconic_p; | |
1614 Xt_SET_VALUE (ew, XtNiconic, iconic_p); | |
1615 } | |
1616 } | |
1617 } | |
1618 else | |
1619 { | |
1620 /* If this is not the first frame created: | |
1621 ======================================== | |
1622 | |
1623 - use the EmacsFrame's size/position if specified | |
1624 - Otherwise, use the ApplicationShell's size, but not position. | |
1625 | |
1626 So that means that one can specify the position of the first frame | |
1627 with "Emacs.geometry" or `-geometry'; but can only specify the | |
1628 position of subsequent frames with "*FRAME-NAME.geometry". | |
1629 | |
1630 AppShell comes second so that -geometry does not apply to subsequent | |
1631 frames when there is an "every frame" entry in the resource db, | |
1632 but does apply to the first frame. | |
1633 */ | |
1634 if (frame_flags & (XValue | YValue)) | |
1635 { | |
1636 x = frame_x; y = frame_y; | |
1637 flags |= (frame_flags & (XValue | YValue | XNegative | YNegative)); | |
1638 } | |
1639 | |
1640 if (frame_flags & (WidthValue | HeightValue)) | |
1641 { | |
1642 w = frame_w; h = frame_h; | |
1643 flags |= (frame_flags & (WidthValue | HeightValue)); | |
1644 } | |
1645 else if (app_flags & (WidthValue | HeightValue)) | |
1646 { | |
1647 w = app_w; | |
1648 h = app_h; | |
1649 flags |= (app_flags & (WidthValue | HeightValue)); | |
1650 } | |
1651 } | |
1652 | |
1653 x_set_initial_frame_size (f, flags, x, y, w, h); | |
1654 } | |
1655 | |
1656 static void | |
1657 x_get_layout_sizes (struct frame *f, Dimension *topbreadth) | |
1658 { | |
1659 int i; | |
1660 | |
1661 /* compute height of all top-area widgets */ | |
1662 for (i=0, *topbreadth = 0; i<FRAME_X_NUM_TOP_WIDGETS (f); i++) | |
1663 { | |
1664 Widget wid = FRAME_X_TOP_WIDGETS (f)[i]; | |
1665 if (wid && XtIsManaged (wid)) | |
1666 *topbreadth += wid->core.height + 2*wid->core.border_width; | |
1667 } | |
1668 } | |
1669 | |
1670 static void | |
2286 | 1671 x_layout_widgets (Widget UNUSED (w), XtPointer client_data, |
1672 XtPointer call_data) | |
428 | 1673 { |
1674 struct frame *f = (struct frame *) client_data; | |
1675 EmacsManagerResizeStruct *emst = (EmacsManagerResizeStruct *) call_data; | |
1676 Dimension width = emst->width; | |
1677 Dimension height = emst->height; | |
1678 Widget text = FRAME_X_TEXT_WIDGET (f); | |
1679 Dimension textbord = text->core.border_width; | |
1680 Dimension topbreadth; | |
1681 Position text_x = 0, text_y = 0; | |
1682 int i; | |
1683 | |
1684 x_get_layout_sizes (f, &topbreadth); | |
1685 | |
1686 /* first the menubar and psheets ... */ | |
1687 for (i=0; i<FRAME_X_NUM_TOP_WIDGETS (f); i++) | |
1688 { | |
1689 Widget wid = FRAME_X_TOP_WIDGETS (f)[i]; | |
1690 if (wid && XtIsManaged (wid)) | |
1691 { | |
1692 Dimension bord = wid->core.border_width; | |
1693 XtConfigureWidget (wid, 0, text_y, | |
1694 width - 2*bord, wid->core.height, | |
1695 bord); | |
1696 text_y += wid->core.height + 2*bord; | |
1697 } | |
1698 } | |
1699 | |
1700 #ifdef HAVE_SCROLLBARS | |
1701 f->scrollbar_y_offset = topbreadth + textbord; | |
1702 #endif | |
1703 | |
1704 /* finally the text area */ | |
1705 XtConfigureWidget (text, text_x, text_y, | |
1706 width - 2*textbord, | |
1707 height - text_y - 2*textbord, | |
1708 textbord); | |
1709 } | |
1710 | |
1711 static void | |
2286 | 1712 x_do_query_geometry (Widget UNUSED (w), XtPointer client_data, |
1713 XtPointer call_data) | |
428 | 1714 { |
1715 struct frame *f = (struct frame *) client_data; | |
1716 EmacsManagerQueryGeometryStruct *emst = | |
1717 (EmacsManagerQueryGeometryStruct *) call_data; | |
1718 Widget text = FRAME_X_TEXT_WIDGET (f); | |
1719 Dimension textbord = text->core.border_width; | |
1720 Dimension topbreadth; | |
1721 XtWidgetGeometry req, repl; | |
1722 int mask = emst->request_mode & (CWWidth | CWHeight); | |
1723 | |
1724 x_get_layout_sizes (f, &topbreadth); | |
1725 | |
1726 /* Strip away menubar from suggested size, and ask the text widget | |
1727 what size it wants to be. */ | |
1728 req.request_mode = mask; | |
1729 if (mask & CWWidth) | |
1730 req.width = emst->proposed_width - 2*textbord; | |
1731 if (mask & CWHeight) | |
1732 req.height = emst->proposed_height - topbreadth - 2*textbord; | |
1733 XtQueryGeometry (text, &req, &repl); | |
1734 | |
1735 /* Now add the menubar back again */ | |
1736 emst->proposed_width = repl.width + 2*textbord; | |
1737 emst->proposed_height = repl.height + topbreadth + 2*textbord; | |
1738 } | |
1739 | |
1740 /* Creates the widgets for a frame. | |
1741 lisp_window_id is a Lisp description of an X window or Xt | |
1742 widget to parse. | |
2747 | 1743 parent is a frame to use as the parent. |
1744 overridep if non-nil says to set the override-redirect setting. | |
428 | 1745 |
1746 This function does not create or map the windows. (That is | |
1747 done by x_popup_frame().) | |
1748 */ | |
1749 static void | |
1750 x_create_widgets (struct frame *f, Lisp_Object lisp_window_id, | |
2747 | 1751 Lisp_Object parent, Lisp_Object overridep) |
428 | 1752 { |
1753 struct device *d = XDEVICE (f->device); | |
1754 Visual *visual = DEVICE_X_VISUAL (d); | |
1755 int depth = DEVICE_X_DEPTH (d); | |
1756 Colormap cmap = DEVICE_X_COLORMAP (d); | |
1757 #ifdef EXTERNAL_WIDGET | |
1758 Window window_id = 0; | |
1759 #endif | |
2367 | 1760 const Extbyte *name; |
1761 Arg al[25]; | |
428 | 1762 int ac = 0; |
1763 Widget text, container, shell; | |
1764 Widget parentwid = 0; | |
1765 #ifdef HAVE_MENUBARS | |
1766 int menubar_visible; | |
1767 Widget menubar; | |
1768 #endif | |
1769 | |
1770 if (STRINGP (f->name)) | |
4981
4aebb0131297
Cleanups/renaming of EXTERNAL_TO_C_STRING and friends
Ben Wing <ben@xemacs.org>
parents:
4969
diff
changeset
|
1771 name = LISP_STRING_TO_EXTERNAL (f->name, Qctext); |
428 | 1772 else |
1773 name = "emacs"; | |
1774 | |
1775 /* The widget hierarchy is | |
1776 | |
1777 argv[0] shell pane FRAME-NAME | |
1778 ApplicationShell EmacsShell EmacsManager EmacsFrame | |
1779 | |
1780 (the type of the shell is ExternalShell if this frame is running | |
1781 in another client's window) | |
1782 | |
1783 However the EmacsShell widget has WM_CLASS of FRAME-NAME/Emacs. | |
1784 Normally such shells have name/class shellname/appclass, which in this | |
1785 case would be "shell/Emacs" instead of "frame-name/Emacs". We could | |
1786 also get around this by naming the shell "frame-name", but that would | |
1787 be confusing because the text area (the EmacsFrame widget inferior of | |
1788 the shell) is also called that. So we just set the WM_CLASS property. | |
1789 */ | |
1790 | |
1791 #ifndef EXTERNAL_WIDGET | |
1792 if (!NILP (lisp_window_id)) | |
2367 | 1793 signal_error |
1794 (Qunimplemented, | |
1795 "support for external widgets was not enabled at compile-time", | |
1796 Qunbound); | |
428 | 1797 #else |
1798 if (!NILP (lisp_window_id)) | |
1799 { | |
2367 | 1800 Ibyte *string; |
428 | 1801 |
1802 CHECK_STRING (lisp_window_id); | |
2367 | 1803 string = XSTRING_DATA (lisp_window_id); |
428 | 1804 if (string[0] == '0' && (string[1] == 'x' || string[1] == 'X')) |
2367 | 1805 qxesscanf_ascii_1 (string + 2, "%lxu", &window_id); |
428 | 1806 #if 0 |
1807 else if (string[0] == 'w') | |
1808 { | |
2367 | 1809 qxesscanf_ascii (string + 1, "%x", &parent_widget); |
428 | 1810 if (parent_widget) |
1811 window_id = XtWindow (parent_widget); | |
1812 } | |
1813 #endif | |
1814 else | |
2367 | 1815 qxesscanf_ascii_1 (string, "%lu", &window_id); |
428 | 1816 if (!is_valid_window (window_id, d)) |
563 | 1817 signal_ferror (Qinvalid_argument, "Invalid window %lu", |
1818 (unsigned long) window_id); | |
428 | 1819 FRAME_X_EXTERNAL_WINDOW_P (f) = 1; |
1820 } else | |
1821 #endif /* EXTERNAL_WIDGET */ | |
1822 FRAME_X_TOP_LEVEL_FRAME_P (f) = 1; | |
1823 | |
1824 ac = 0; | |
4528
726060ee587c
First draft of g++ 4.3 warning removal patch. Builds. *Needs ChangeLogs.*
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4522
diff
changeset
|
1825 Xt_SET_ARG (al[ac], XtNallowShellResize, True); ac++; |
428 | 1826 #ifdef LWLIB_USES_MOTIF |
1827 /* Motif sucks beans. Without this in here, it will delete the window | |
1828 out from under us when it receives a WM_DESTROY_WINDOW message | |
1829 from the WM. */ | |
4528
726060ee587c
First draft of g++ 4.3 warning removal patch. Builds. *Needs ChangeLogs.*
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4522
diff
changeset
|
1830 Xt_SET_ARG (al[ac], XmNdeleteResponse, XmDO_NOTHING); ac++; |
428 | 1831 #endif |
1832 | |
1833 #ifdef EXTERNAL_WIDGET | |
1834 if (window_id) | |
1835 { | |
4528
726060ee587c
First draft of g++ 4.3 warning removal patch. Builds. *Needs ChangeLogs.*
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4522
diff
changeset
|
1836 Xt_SET_ARG (al[ac], XtNwindow, window_id); ac++; |
428 | 1837 } |
1838 else | |
1839 #endif /* EXTERNAL_WIDGET */ | |
1840 { | |
4528
726060ee587c
First draft of g++ 4.3 warning removal patch. Builds. *Needs ChangeLogs.*
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4522
diff
changeset
|
1841 Xt_SET_ARG (al[ac], XtNinput, True); ac++; |
726060ee587c
First draft of g++ 4.3 warning removal patch. Builds. *Needs ChangeLogs.*
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4522
diff
changeset
|
1842 Xt_SET_ARG (al[ac], XtNminWidthCells, 10); ac++; |
726060ee587c
First draft of g++ 4.3 warning removal patch. Builds. *Needs ChangeLogs.*
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4522
diff
changeset
|
1843 Xt_SET_ARG (al[ac], XtNminHeightCells, 1); ac++; |
726060ee587c
First draft of g++ 4.3 warning removal patch. Builds. *Needs ChangeLogs.*
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4522
diff
changeset
|
1844 Xt_SET_ARG (al[ac], XtNvisual, visual); ac++; |
726060ee587c
First draft of g++ 4.3 warning removal patch. Builds. *Needs ChangeLogs.*
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4522
diff
changeset
|
1845 Xt_SET_ARG (al[ac], XtNdepth, depth); ac++; |
726060ee587c
First draft of g++ 4.3 warning removal patch. Builds. *Needs ChangeLogs.*
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4522
diff
changeset
|
1846 Xt_SET_ARG (al[ac], XtNcolormap, cmap); ac++; |
428 | 1847 } |
1848 | |
2747 | 1849 if (!NILP (overridep)) |
1850 { | |
4528
726060ee587c
First draft of g++ 4.3 warning removal patch. Builds. *Needs ChangeLogs.*
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4522
diff
changeset
|
1851 Xt_SET_ARG (al[ac], XtNoverrideRedirect, True); ac++; |
2747 | 1852 } |
1853 | |
1854 /* #### maybe we should check for FRAMEP instead? */ | |
428 | 1855 if (!NILP (parent)) |
1856 { | |
1857 parentwid = FRAME_X_SHELL_WIDGET (XFRAME (parent)); | |
4528
726060ee587c
First draft of g++ 4.3 warning removal patch. Builds. *Needs ChangeLogs.*
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4522
diff
changeset
|
1858 Xt_SET_ARG (al[ac], XtNtransientFor, parentwid); ac++; |
428 | 1859 } |
1860 | |
1861 shell = XtCreatePopupShell ("shell", | |
1862 ( | |
1863 #ifdef EXTERNAL_WIDGET | |
1864 window_id ? externalShellWidgetClass : | |
1865 #endif | |
1866 parentwid ? transientEmacsShellWidgetClass : | |
1867 topLevelEmacsShellWidgetClass | |
1868 ), | |
1869 parentwid ? parentwid : | |
1870 DEVICE_XT_APP_SHELL (d), | |
1871 al, ac); | |
1872 FRAME_X_SHELL_WIDGET (f) = shell; | |
1873 maybe_set_frame_title_format (shell); | |
1874 | |
1875 /* Create the manager widget */ | |
1876 ac = 0; | |
4528
726060ee587c
First draft of g++ 4.3 warning removal patch. Builds. *Needs ChangeLogs.*
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4522
diff
changeset
|
1877 Xt_SET_ARG (al[ac], XtNvisual, visual); ac++; |
726060ee587c
First draft of g++ 4.3 warning removal patch. Builds. *Needs ChangeLogs.*
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4522
diff
changeset
|
1878 Xt_SET_ARG (al[ac], XtNdepth, depth); ac++; |
726060ee587c
First draft of g++ 4.3 warning removal patch. Builds. *Needs ChangeLogs.*
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4522
diff
changeset
|
1879 Xt_SET_ARG (al[ac], XtNcolormap, cmap); ac++; |
428 | 1880 |
1881 container = XtCreateWidget ("container", | |
1882 emacsManagerWidgetClass, shell, al, ac); | |
1883 FRAME_X_CONTAINER_WIDGET (f) = container; | |
1884 XtAddCallback (container, XtNresizeCallback, x_layout_widgets, | |
1885 (XtPointer) f); | |
1886 XtAddCallback (container, XtNqueryGeometryCallback, x_do_query_geometry, | |
1887 (XtPointer) f); | |
1888 | |
1889 /* Create the text area */ | |
1890 ac = 0; | |
4528
726060ee587c
First draft of g++ 4.3 warning removal patch. Builds. *Needs ChangeLogs.*
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4522
diff
changeset
|
1891 Xt_SET_ARG (al[ac], XtNvisual, visual); ac++; |
726060ee587c
First draft of g++ 4.3 warning removal patch. Builds. *Needs ChangeLogs.*
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4522
diff
changeset
|
1892 Xt_SET_ARG (al[ac], XtNdepth, depth); ac++; |
726060ee587c
First draft of g++ 4.3 warning removal patch. Builds. *Needs ChangeLogs.*
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4522
diff
changeset
|
1893 Xt_SET_ARG (al[ac], XtNcolormap, cmap); ac++; |
726060ee587c
First draft of g++ 4.3 warning removal patch. Builds. *Needs ChangeLogs.*
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4522
diff
changeset
|
1894 Xt_SET_ARG (al[ac], XtNborderWidth, 0); ac++; /* should this be settable? */ |
726060ee587c
First draft of g++ 4.3 warning removal patch. Builds. *Needs ChangeLogs.*
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4522
diff
changeset
|
1895 Xt_SET_ARG (al[ac], XtNemacsFrame, f); ac++; |
428 | 1896 text = XtCreateWidget (name, emacsFrameClass, container, al, ac); |
1897 FRAME_X_TEXT_WIDGET (f) = text; | |
1898 | |
1899 #ifdef HAVE_MENUBARS | |
1900 /* Create the initial menubar widget. */ | |
1901 menubar_visible = x_initialize_frame_menubar (f); | |
1902 FRAME_X_TOP_WIDGETS (f)[0] = menubar = FRAME_X_MENUBAR_WIDGET (f); | |
1903 FRAME_X_NUM_TOP_WIDGETS (f) = 1; | |
1904 | |
1905 if (menubar_visible) | |
1906 XtManageChild (menubar); | |
1907 #endif /* HAVE_MENUBARS */ | |
1908 XtManageChild (text); | |
1909 XtManageChild (container); | |
1910 } | |
1911 | |
1912 /* We used to call XtPopup() in x_popup_frame, but that doesn't give | |
1913 you control over whether the widget is initially mapped or not | |
1914 because XtPopup() makes an unconditional call to XMapRaised(). | |
1915 Boy, those Xt designers were clever. | |
1916 | |
1917 When we first removed it we only kept the XtRealizeWidget call in | |
1918 XtPopup. For everything except HP's that was enough. For HP's, | |
1919 though, the failure to call the popup callbacks resulted in XEmacs | |
1920 not accepting any input. Bizarre but true. Stupid but true. | |
1921 | |
1922 So, in case there are any other gotchas floating out there along | |
1923 the same lines I've duplicated the majority of XtPopup here. It | |
1924 assumes no grabs and that the widget is not already popped up, both | |
1925 valid assumptions for the one place this is called from. */ | |
1926 static void | |
1927 xemacs_XtPopup (Widget widget) | |
1928 { | |
1929 ShellWidget shell_widget = (ShellWidget) widget; | |
1930 XtGrabKind call_data = XtGrabNone; | |
1931 | |
2367 | 1932 XtCallCallbacks (widget, XtNpopupCallback, (XtPointer) &call_data); |
428 | 1933 |
1934 shell_widget->shell.popped_up = TRUE; | |
1935 shell_widget->shell.grab_kind = XtGrabNone; | |
1936 shell_widget->shell.spring_loaded = False; | |
1937 | |
1938 if (shell_widget->shell.create_popup_child_proc != NULL) | |
2367 | 1939 (*(shell_widget->shell.create_popup_child_proc)) (widget); |
428 | 1940 |
1941 /* The XtSetValues below are not in XtPopup menu. We just want to | |
1942 make absolutely sure... */ | |
1943 Xt_SET_VALUE (widget, XtNmappedWhenManaged, False); | |
1944 XtRealizeWidget (widget); | |
1945 Xt_SET_VALUE (widget, XtNmappedWhenManaged, True); | |
1946 } | |
1947 | |
1948 /* create the windows for the specified frame and display them. | |
1949 Note that the widgets have already been created, and any | |
1950 necessary geometry calculations have already been done. */ | |
1951 static void | |
1952 x_popup_frame (struct frame *f) | |
1953 { | |
1954 Widget shell_widget = FRAME_X_SHELL_WIDGET (f); | |
1955 Widget frame_widget = FRAME_X_TEXT_WIDGET (f); | |
1956 struct device *d = XDEVICE (FRAME_DEVICE (f)); | |
1957 | |
1958 /* Before mapping the window, make sure that the WMShell's notion of | |
1959 whether it should be iconified is synchronized with the EmacsFrame's | |
1960 notion. | |
1961 */ | |
1962 if (FRAME_X_TOP_LEVEL_FRAME_P (f)) | |
1963 x_wm_set_shell_iconic_p (shell_widget, | |
1964 ((EmacsFrame) frame_widget) | |
1965 ->emacs_frame.iconic); | |
1966 | |
1967 xemacs_XtPopup (shell_widget); | |
1968 | |
1969 if (!((EmacsFrame) frame_widget)->emacs_frame.initially_unmapped) | |
1970 XtMapWidget (shell_widget); | |
1971 else | |
1972 { | |
1973 /* We may have set f->visible to 1 in x_init_frame(), so undo | |
1974 that now. */ | |
1975 FRAME_X_TOTALLY_VISIBLE_P (f) = 0; | |
1976 f->visible = 0; | |
1977 } | |
1978 | |
1979 #ifdef EXTERNAL_WIDGET | |
1980 if (FRAME_X_EXTERNAL_WINDOW_P (f)) | |
1981 ExternalShellReady (shell_widget, XtWindow (frame_widget), KeyPressMask); | |
1982 else | |
1983 #endif | |
1984 if (FRAME_X_TOP_LEVEL_FRAME_P (f)) | |
1985 { | |
1986 /* tell the window manager about us. */ | |
1987 x_wm_store_class_hints (shell_widget, XtName (frame_widget)); | |
1988 | |
1989 #ifndef HAVE_WMCOMMAND | |
1990 x_wm_maybe_store_wm_command (f); | |
1991 #endif /* HAVE_WMCOMMAND */ | |
1992 | |
1993 x_wm_hack_wm_protocols (shell_widget); | |
1994 } | |
1995 | |
1996 #ifdef HAVE_XIM | |
1997 XIM_init_frame (f); | |
1998 #endif /* HAVE_XIM */ | |
1999 | |
2000 /* Allow XEmacs to respond to EditRes requests. See the O'Reilly Xt */ | |
2001 /* Intrinsics Programming Manual, Motif Edition, Aug 1993, Sect 14.14, */ | |
2002 /* pp. 483-493. */ | |
2003 XtAddEventHandler (shell_widget, /* the shell widget in question */ | |
2004 (EventMask) NoEventMask,/* OR with existing mask */ | |
2005 True, /* called on non-maskable events? */ | |
2006 (XtEventHandler) _XEditResCheckMessages, /* the handler */ | |
2007 NULL); | |
2008 | |
2009 #ifdef HAVE_CDE | |
2010 { | |
2011 XtCallbackRec dnd_transfer_cb_rec[2]; | |
2012 | |
2013 dnd_transfer_cb_rec[0].callback = x_cde_transfer_callback; | |
2014 dnd_transfer_cb_rec[0].closure = (XtPointer) f; | |
2015 dnd_transfer_cb_rec[1].callback = NULL; | |
2016 dnd_transfer_cb_rec[1].closure = NULL; | |
2017 | |
2018 DtDndVaDropRegister (FRAME_X_TEXT_WIDGET (f), | |
2019 DtDND_FILENAME_TRANSFER | DtDND_BUFFER_TRANSFER, | |
2020 XmDROP_COPY, dnd_transfer_cb_rec, | |
2021 DtNtextIsBuffer, True, | |
2022 DtNregisterChildren, True, | |
2023 DtNpreserveRegistration, False, | |
2024 NULL); | |
2025 } | |
2026 #endif /* HAVE_CDE */ | |
2027 | |
2028 /* Do a stupid property change to force the server to generate a | |
2029 propertyNotify event so that the event_stream server timestamp will | |
2030 be initialized to something relevant to the time we created the window. | |
2031 */ | |
2032 XChangeProperty (XtDisplay (frame_widget), XtWindow (frame_widget), | |
2033 DEVICE_XATOM_WM_PROTOCOLS (d), XA_ATOM, 32, PropModeAppend, | |
2367 | 2034 (Rawbyte *) NULL, 0); |
428 | 2035 |
2036 x_send_synthetic_mouse_event (f); | |
2037 } | |
2038 | |
2039 static void | |
2040 allocate_x_frame_struct (struct frame *f) | |
2041 { | |
2042 /* zero out all slots. */ | |
3092 | 2043 #ifdef NEW_GC |
2044 f->frame_data = alloc_lrecord_type (struct x_frame, &lrecord_x_frame); | |
2045 #else /* not NEW_GC */ | |
428 | 2046 f->frame_data = xnew_and_zero (struct x_frame); |
3092 | 2047 #endif /* not NEW_GC */ |
428 | 2048 |
2049 /* yeah, except the lisp ones */ | |
1346 | 2050 FRAME_X_LAST_MENUBAR_BUFFER (f) = Qnil; |
428 | 2051 FRAME_X_ICON_PIXMAP (f) = Qnil; |
2052 FRAME_X_ICON_PIXMAP_MASK (f) = Qnil; | |
2053 } | |
2054 | |
2055 | |
2056 /************************************************************************/ | |
2057 /* Lisp functions */ | |
2058 /************************************************************************/ | |
2059 | |
2060 static void | |
771 | 2061 x_init_frame_1 (struct frame *f, Lisp_Object props, |
2286 | 2062 int UNUSED (frame_name_is_defaulted)) |
428 | 2063 { |
2064 /* This function can GC */ | |
2065 Lisp_Object device = FRAME_DEVICE (f); | |
2066 Lisp_Object lisp_window_id = Fplist_get (props, Qwindow_id, Qnil); | |
2067 Lisp_Object popup = Fplist_get (props, Qpopup, Qnil); | |
2747 | 2068 Lisp_Object overridep = Fplist_get (props, Qoverride_redirect, Qnil); |
428 | 2069 |
2070 if (!NILP (popup)) | |
2071 { | |
2072 if (EQ (popup, Qt)) | |
2073 popup = Fselected_frame (device); | |
2074 CHECK_LIVE_FRAME (popup); | |
2075 if (!EQ (device, FRAME_DEVICE (XFRAME (popup)))) | |
563 | 2076 invalid_argument_2 ("Parent must be on same device as frame", |
2077 device, popup); | |
428 | 2078 } |
2079 | |
2080 /* | |
2081 * Previously we set this only if NILP (DEVICE_SELECTED_FRAME (d)) | |
2082 * to make sure that messages were displayed as soon as possible | |
2083 * if we're creating the first frame on a device. But it is | |
2084 * better to just set this all the time, so that when a new frame | |
2085 * is created that covers the selected frame, echo area status | |
2086 * messages can still be seen. f->visible is reset later if the | |
2087 * initially-unmapped property is found to be non-nil in the | |
2088 * frame properties. | |
2089 */ | |
2090 f->visible = 1; | |
2091 | |
2092 allocate_x_frame_struct (f); | |
2747 | 2093 x_create_widgets (f, lisp_window_id, popup, overridep); |
428 | 2094 } |
2095 | |
2096 static void | |
2286 | 2097 x_init_frame_2 (struct frame *f, Lisp_Object UNUSED (props)) |
428 | 2098 { |
2099 /* Set up the values of the widget/frame. A case could be made for putting | |
2100 this inside of the widget's initialize method. */ | |
2101 | |
2102 update_frame_face_values (f); | |
2103 x_initialize_frame_size (f); | |
2104 /* Kyle: | |
2105 * update_frame_title() can't be done here, because some of the | |
2106 * modeline specs depend on the frame's device having a selected | |
2107 * frame, and that may not have been set up yet. The redisplay | |
2108 * will update the frame title anyway, so nothing is lost. | |
2109 * JV: | |
2110 * It turns out it gives problems with FVWMs name based mapping. | |
2111 * We'll just need to be careful in the modeline specs. | |
2112 */ | |
2113 update_frame_title (f); | |
4593
3623446b34bc
Set icon resource on frame early enough for openbox to find it.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4528
diff
changeset
|
2114 /* Henry S. Thompson: |
3623446b34bc
Set icon resource on frame early enough for openbox to find it.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4528
diff
changeset
|
2115 * Must set icon resource before mapping frame, or some WMs may |
3623446b34bc
Set icon resource on frame early enough for openbox to find it.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4528
diff
changeset
|
2116 * lose the icon (openbox). See <f5bhc3efb17@hildegard.inf.ed.ac.uk>. |
3623446b34bc
Set icon resource on frame early enough for openbox to find it.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4528
diff
changeset
|
2117 * SJT: |
3623446b34bc
Set icon resource on frame early enough for openbox to find it.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4528
diff
changeset
|
2118 * This probably means that the frame-icon library won't work with |
4594 | 2119 * that WM. Late breaking news: it *does* work, so possibly the |
2120 * problem at initialization is due to a race condition. | |
4593
3623446b34bc
Set icon resource on frame early enough for openbox to find it.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4528
diff
changeset
|
2121 */ |
3623446b34bc
Set icon resource on frame early enough for openbox to find it.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4528
diff
changeset
|
2122 update_frame_icon (f); |
428 | 2123 } |
2124 | |
2125 static void | |
2126 x_init_frame_3 (struct frame *f) | |
2127 { | |
2128 /* Pop up the frame. */ | |
2129 | |
2130 x_popup_frame (f); | |
2131 } | |
2132 | |
2133 static void | |
2134 x_mark_frame (struct frame *f) | |
2135 { | |
1346 | 2136 mark_object (FRAME_X_LAST_MENUBAR_BUFFER (f)); |
428 | 2137 mark_object (FRAME_X_ICON_PIXMAP (f)); |
2138 mark_object (FRAME_X_ICON_PIXMAP_MASK (f)); | |
2139 } | |
2140 | |
2141 static void | |
2142 x_set_frame_icon (struct frame *f) | |
2143 { | |
2144 Pixmap x_pixmap, x_mask; | |
2145 | |
2146 if (IMAGE_INSTANCEP (f->icon) | |
2147 && IMAGE_INSTANCE_PIXMAP_TYPE_P (XIMAGE_INSTANCE (f->icon))) | |
2148 { | |
2149 x_pixmap = XIMAGE_INSTANCE_X_PIXMAP (f->icon); | |
2150 x_mask = XIMAGE_INSTANCE_X_MASK (f->icon); | |
2151 } | |
2152 else | |
2153 { | |
2154 x_pixmap = 0; | |
2155 x_mask = 0; | |
2156 } | |
2157 | |
2158 /* Store the X data into the widget. */ | |
2159 { | |
2367 | 2160 Arg al[2]; |
4528
726060ee587c
First draft of g++ 4.3 warning removal patch. Builds. *Needs ChangeLogs.*
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4522
diff
changeset
|
2161 Xt_SET_ARG (al[0], XtNiconPixmap, x_pixmap); |
726060ee587c
First draft of g++ 4.3 warning removal patch. Builds. *Needs ChangeLogs.*
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4522
diff
changeset
|
2162 Xt_SET_ARG (al[1], XtNiconMask, x_mask); |
428 | 2163 XtSetValues (FRAME_X_SHELL_WIDGET (f), al, 2); |
2164 } | |
2165 } | |
2166 | |
2167 static void | |
2168 x_set_frame_pointer (struct frame *f) | |
2169 { | |
2170 XDefineCursor (XtDisplay (FRAME_X_TEXT_WIDGET (f)), | |
2171 XtWindow (FRAME_X_TEXT_WIDGET (f)), | |
2172 XIMAGE_INSTANCE_X_CURSOR (f->pointer)); | |
2173 XSync (XtDisplay (FRAME_X_TEXT_WIDGET (f)), 0); | |
2174 } | |
2175 | |
2176 static Lisp_Object | |
2177 x_get_frame_parent (struct frame *f) | |
2178 { | |
2179 Widget parentwid = 0; | |
2180 | |
2181 Xt_GET_VALUE (FRAME_X_SHELL_WIDGET (f), XtNtransientFor, &parentwid); | |
2182 /* find the frame whose wid is parentwid */ | |
2183 if (parentwid) | |
2184 { | |
2185 Lisp_Object frmcons; | |
2186 DEVICE_FRAME_LOOP (frmcons, XDEVICE (FRAME_DEVICE (f))) | |
2187 { | |
2188 Lisp_Object frame = XCAR (frmcons); | |
2189 if (FRAME_X_SHELL_WIDGET (XFRAME (frame)) == parentwid) | |
2190 return frame; | |
2191 } | |
2192 } | |
2193 return Qnil; | |
2194 } | |
2195 | |
2196 DEFUN ("x-window-id", Fx_window_id, 0, 1, 0, /* | |
2197 Get the ID of the X11 window. | |
2198 This gives us a chance to manipulate the Emacs window from within a | |
2199 different program. Since the ID is an unsigned long, we return it as | |
2200 a string. | |
2201 */ | |
2202 (frame)) | |
2203 { | |
867 | 2204 Ibyte str[255]; |
428 | 2205 struct frame *f = decode_x_frame (frame); |
2206 | |
771 | 2207 qxesprintf (str, "%lu", XtWindow (FRAME_X_TEXT_WIDGET (f))); |
4953
304aebb79cd3
function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
2208 return build_istring (str); |
428 | 2209 } |
2210 | |
2211 | |
2212 /************************************************************************/ | |
2213 /* manipulating the X window */ | |
2214 /************************************************************************/ | |
2215 | |
2216 static void | |
2217 x_set_frame_position (struct frame *f, int xoff, int yoff) | |
2218 { | |
2219 Widget w = FRAME_X_SHELL_WIDGET (f); | |
2220 Display *dpy = XtDisplay (w); | |
2221 Dimension frame_w = DisplayWidth (dpy, DefaultScreen (dpy)); | |
2222 Dimension frame_h = DisplayHeight (dpy, DefaultScreen (dpy)); | |
2223 Dimension shell_w, shell_h, shell_bord; | |
2224 int win_gravity; | |
2367 | 2225 Arg al[3]; |
2226 | |
4528
726060ee587c
First draft of g++ 4.3 warning removal patch. Builds. *Needs ChangeLogs.*
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4522
diff
changeset
|
2227 Xt_SET_ARG (al[0], XtNwidth, &shell_w); |
726060ee587c
First draft of g++ 4.3 warning removal patch. Builds. *Needs ChangeLogs.*
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4522
diff
changeset
|
2228 Xt_SET_ARG (al[1], XtNheight, &shell_h); |
726060ee587c
First draft of g++ 4.3 warning removal patch. Builds. *Needs ChangeLogs.*
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4522
diff
changeset
|
2229 Xt_SET_ARG (al[2], XtNborderWidth, &shell_bord); |
428 | 2230 XtGetValues (w, al, 3); |
2231 | |
2232 win_gravity = | |
2233 xoff >= 0 && yoff >= 0 ? NorthWestGravity : | |
2234 xoff >= 0 ? SouthWestGravity : | |
2235 yoff >= 0 ? NorthEastGravity : | |
2236 SouthEastGravity; | |
2237 if (xoff < 0) | |
2238 xoff += frame_w - shell_w - 2*shell_bord; | |
2239 if (yoff < 0) | |
2240 yoff += frame_h - shell_h - 2*shell_bord; | |
2241 | |
2242 /* Update the hints so that, if this window is currently iconified, it will | |
2243 come back at the right place. We can't look at s->visible to determine | |
2244 whether it is iconified because it might not be up-to-date yet (the queue | |
2245 might not be processed). */ | |
4528
726060ee587c
First draft of g++ 4.3 warning removal patch. Builds. *Needs ChangeLogs.*
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4522
diff
changeset
|
2246 Xt_SET_ARG (al[0], XtNwinGravity, win_gravity); |
726060ee587c
First draft of g++ 4.3 warning removal patch. Builds. *Needs ChangeLogs.*
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4522
diff
changeset
|
2247 Xt_SET_ARG (al[1], XtNx, xoff); |
726060ee587c
First draft of g++ 4.3 warning removal patch. Builds. *Needs ChangeLogs.*
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4522
diff
changeset
|
2248 Xt_SET_ARG (al[2], XtNy, yoff); |
428 | 2249 XtSetValues (w, al, 3); |
2250 | |
2251 /* Sometimes you will find that | |
2252 | |
2253 (set-frame-position (selected-frame) -50 -50) | |
2254 | |
2255 doesn't put the frame where you expect it to: i.e. it's closer to | |
2256 the lower-right corner than it should be, and it appears that the | |
2257 size of the WM decorations was not taken into account. This is | |
2258 *not* a problem with this function. Both mwm and twm have bugs | |
2259 in handling this situation. (mwm ignores the window gravity and | |
2260 always assumes NorthWest, except the first time you map the | |
2261 window; twm gets things almost right, but forgets to account for | |
2262 the border width of the top-level window.) This function does | |
2263 what it's supposed to according to the ICCCM, and I'm not about | |
2264 to hack around window-manager bugs. */ | |
2265 | |
2266 #if 0 | |
2267 /* This is not necessary under either mwm or twm */ | |
2268 x_wm_mark_shell_position_user_specified (w); | |
2269 #endif | |
2270 } | |
2271 | |
2272 /* Call this to change the size of frame S's x-window. */ | |
2273 | |
2274 static void | |
2275 x_set_frame_size (struct frame *f, int cols, int rows) | |
2276 { | |
2277 EmacsFrameSetCharSize (FRAME_X_TEXT_WIDGET (f), cols, rows); | |
3381 | 2278 |
2279 if (!wedge_metacity) /* cf. EmacsFrameResize */ | |
2280 { | |
2281 /* Kick the manager so that it knows we've changed size. */ | |
2282 XtWidgetGeometry req, repl; | |
2283 req.request_mode = 0; | |
2284 XtQueryGeometry (FRAME_X_CONTAINER_WIDGET (f), &req, &repl); | |
2285 EmacsManagerChangeSize (FRAME_X_CONTAINER_WIDGET (f), | |
2286 repl.width, repl.height); | |
2287 } | |
2288 | |
428 | 2289 #if 0 |
2290 /* this is not correct. x_set_frame_size() is called from | |
2291 Fset_frame_size(), which may or may not have been called | |
2292 by the user (e.g. update_EmacsFrame() calls it when the font | |
2293 changes). For now, don't bother with getting this right. */ | |
2294 x_wm_mark_shell_size_user_specified (FRAME_X_SHELL_WIDGET (f)); | |
2295 #endif | |
2296 } | |
2297 | |
2298 static void | |
2299 x_set_mouse_position (struct window *w, int x, int y) | |
2300 { | |
2301 struct frame *f = XFRAME (w->frame); | |
2302 | |
2303 Display *display = DEVICE_X_DISPLAY (XDEVICE (f->device)); | |
2304 XWarpPointer (display, None, XtWindow (FRAME_X_TEXT_WIDGET (f)), | |
2305 0, 0, 0, 0, w->pixel_left + x, w->pixel_top + y); | |
2306 } | |
2307 | |
2308 static int | |
2309 x_get_mouse_position (struct device *d, Lisp_Object *frame, int *x, int *y) | |
2310 { | |
2311 Display *display = DEVICE_X_DISPLAY (d); | |
2312 Window child_window; | |
2313 Window root_window; | |
2314 Window win; | |
2315 int root_x, root_y; | |
2316 int win_x, win_y; | |
2317 unsigned int keys_and_buttons; | |
2318 struct frame *f; | |
2319 | |
2320 if (XQueryPointer (display, RootWindow (display, DefaultScreen (display)), | |
2321 &root_window, &child_window, &root_x, &root_y, | |
2322 &win_x, &win_y, &keys_and_buttons) == False) | |
2323 return 0; | |
2324 | |
2325 if (child_window == None) | |
2326 return 0; /* not over any window. */ | |
2327 | |
2328 while (1) | |
2329 { | |
2330 win = child_window; | |
2331 if (XTranslateCoordinates (display, root_window, win, root_x, root_y, | |
2332 &win_x, &win_y, &child_window) == False) | |
2333 /* Huh? */ | |
2334 return 0; | |
2335 | |
2336 if (child_window == None) | |
2337 break; | |
2338 } | |
2339 | |
2340 /* At this point, win is the innermost window containing the pointer | |
2341 and win_x and win_y are the coordinates of that window. */ | |
2342 f = x_any_window_to_frame (d, win); | |
2343 if (!f) | |
2344 return 0; | |
793 | 2345 *frame = wrap_frame (f); |
428 | 2346 |
2347 if (XTranslateCoordinates (display, win, | |
2348 XtWindow (FRAME_X_TEXT_WIDGET (f)), | |
2349 win_x, win_y, x, y, &child_window) == False) | |
2350 /* Huh? */ | |
2351 return 0; | |
2352 | |
2353 return 1; | |
2354 } | |
2355 | |
2268 | 2356 static DECLARE_DOESNT_RETURN (x_cant_notify_wm_error (void)); |
2357 | |
2358 static DOESNT_RETURN | |
2359 x_cant_notify_wm_error () | |
428 | 2360 { |
563 | 2361 signal_error (Qgui_error, "Can't notify window manager of iconification", Qunbound); |
428 | 2362 } |
2363 | |
2364 /* Raise frame F. */ | |
2365 static void | |
2366 x_raise_frame_1 (struct frame *f, int force) | |
2367 { | |
2368 if (FRAME_VISIBLE_P (f) || force) | |
2369 { | |
2370 Widget bottom_dialog; | |
2371 XWindowChanges xwc; | |
2372 unsigned int flags; | |
2373 Display *display = DEVICE_X_DISPLAY (XDEVICE (f->device)); | |
2374 Window emacs_window = XtWindow (FRAME_X_SHELL_WIDGET (f)); | |
2375 | |
2376 /* first raises all the dialog boxes, then put emacs just below the | |
2377 * bottom most dialog box */ | |
2378 bottom_dialog = lw_raise_all_pop_up_widgets (); | |
2379 if (bottom_dialog && XtWindow (bottom_dialog)) | |
2380 { | |
2381 xwc.sibling = XtWindow (bottom_dialog); | |
2382 xwc.stack_mode = Below; | |
2383 flags = CWSibling | CWStackMode; | |
2384 } | |
2385 else | |
2386 { | |
2387 xwc.stack_mode = Above; | |
2388 flags = CWStackMode; | |
2389 } | |
2390 | |
2391 if (!XReconfigureWMWindow (display, emacs_window, | |
2392 DefaultScreen (display), | |
2393 flags, &xwc)) | |
2394 x_cant_notify_wm_error (); | |
2395 } | |
2396 } | |
2397 | |
2398 static void | |
2399 x_raise_frame (struct frame *f) | |
2400 { | |
2401 x_raise_frame_1 (f, 1); | |
2402 } | |
2403 | |
2404 /* Lower frame F. */ | |
2405 static void | |
2406 x_lower_frame (struct frame *f) | |
2407 { | |
2408 if (FRAME_VISIBLE_P (f)) | |
2409 { | |
2410 Display *display = DEVICE_X_DISPLAY (XDEVICE (f->device)); | |
2411 XWindowChanges xwc; | |
2412 unsigned int flags = CWStackMode; | |
2413 | |
2414 xwc.stack_mode = Below; | |
2415 if (!XReconfigureWMWindow (display, XtWindow (FRAME_X_SHELL_WIDGET (f)), | |
2416 DefaultScreen (display), flags, &xwc)) | |
2417 x_cant_notify_wm_error (); | |
2418 } | |
2419 } | |
2420 | |
442 | 2421 static void |
2422 x_enable_frame (struct frame *f) | |
2423 { | |
2424 XtSetSensitive (FRAME_X_SHELL_WIDGET (f), True); | |
2425 } | |
2426 | |
2427 static void | |
2428 x_disable_frame (struct frame *f) | |
2429 { | |
2430 XtSetSensitive (FRAME_X_SHELL_WIDGET (f), False); | |
2431 } | |
2432 | |
428 | 2433 /* Change from withdrawn state to mapped state. */ |
2434 static void | |
2435 x_make_frame_visible (struct frame *f) | |
2436 { | |
2437 Display *display = DEVICE_X_DISPLAY (XDEVICE (f->device)); | |
2438 | |
2439 if (!FRAME_VISIBLE_P(f)) | |
2440 XMapRaised (display, XtWindow (FRAME_X_SHELL_WIDGET (f))); | |
2441 else | |
2442 x_raise_frame_1 (f, 0); | |
2443 } | |
2444 | |
2445 /* Change from mapped state to withdrawn state. */ | |
2446 static void | |
2447 x_make_frame_invisible (struct frame *f) | |
2448 { | |
2449 Display *display = DEVICE_X_DISPLAY (XDEVICE (f->device)); | |
2450 | |
2451 if (!FRAME_VISIBLE_P(f)) | |
2452 return; | |
2453 | |
2454 if (!XWithdrawWindow (display, | |
2455 XtWindow (FRAME_X_SHELL_WIDGET (f)), | |
2456 DefaultScreen (display))) | |
2457 x_cant_notify_wm_error (); | |
2458 } | |
2459 | |
2460 static int | |
2461 x_frame_visible_p (struct frame *f) | |
2462 { | |
2463 #if 0 | |
593 | 2464 |
2465 /* #### Ben suggests using x_frame_window_state (f) == NormalState. */ | |
2466 | |
428 | 2467 Display *display = DEVICE_X_DISPLAY (XDEVICE (f->device)); |
2468 XWindowAttributes xwa; | |
2469 int result; | |
2470 | |
2471 /* JV: | |
2472 This is bad, very bad :-( | |
2473 It is not compatible with our tristate visible and | |
2474 it should never ever change the visibility for us, this leads to | |
2475 the frame-freeze problem under fvwm because with the pager | |
2476 | |
2477 Mappedness != Viewability != Visibility != Emacs f->visible | |
2478 | |
2479 This first unequalness is the reason for the frame freezing problem | |
2480 under fvwm (it happens when the frame is another fvwm-page) | |
2481 | |
2482 The second unequalness happen when it is on the same fvwm-page | |
2483 but in an invisible part of the visible screen. | |
2484 | |
2485 For now we just return the XEmacs internal value --- which might not be up | |
2486 to date. Is that a problem? ---. Otherwise we should | |
2487 use async visibility like in standard Emacs. | |
2488 */ | |
2489 | |
2490 if (!XGetWindowAttributes (display, | |
2491 XtWindow (FRAME_X_SHELL_WIDGET (f)), | |
2492 &xwa)) | |
2493 result = 0; | |
2494 else | |
2495 result = xwa.map_state == IsViewable; | |
2496 /* In this implementation it should at least be != IsUnmapped | |
2497 JV */ | |
2498 | |
2499 f->visible = result; | |
2500 return result; | |
2501 #endif /* 0 */ | |
2502 | |
2503 return f->visible; | |
2504 } | |
2505 | |
2506 static int | |
2507 x_frame_totally_visible_p (struct frame *f) | |
2508 { | |
2509 return FRAME_X_TOTALLY_VISIBLE_P (f); | |
2510 } | |
2511 | |
2512 /* Change window state from mapped to iconified. */ | |
2513 static void | |
2514 x_iconify_frame (struct frame *f) | |
2515 { | |
2516 Display *display = DEVICE_X_DISPLAY (XDEVICE (f->device)); | |
2517 | |
2518 if (!XIconifyWindow (display, | |
2519 XtWindow (FRAME_X_SHELL_WIDGET (f)), | |
2520 DefaultScreen (display))) | |
2521 x_cant_notify_wm_error (); | |
2522 | |
2523 f->iconified = 1; | |
2524 } | |
2525 | |
2526 /* Sets the X focus to frame f. */ | |
2527 static void | |
2528 x_focus_on_frame (struct frame *f) | |
2529 { | |
2530 XWindowAttributes xwa; | |
2531 Widget shell_widget; | |
2532 int viewable = 0; | |
2533 | |
2534 assert (FRAME_X_P (f)); | |
2535 | |
2536 shell_widget = FRAME_X_SHELL_WIDGET (f); | |
2537 if (!XtWindow (shell_widget)) | |
2538 return; | |
2539 | |
2540 #ifdef EXTERNAL_WIDGET | |
2541 if (FRAME_X_EXTERNAL_WINDOW_P (f)) | |
2542 ExternalShellSetFocus (shell_widget); | |
2543 #endif /* EXTERNAL_WIDGET */ | |
2544 | |
2545 /* Do the ICCCM focus change if the window is still visible. | |
2546 The s->visible flag might not be up-to-date, because we might | |
2547 not have processed magic events recently. So make a server | |
2548 round-trip to find out whether it's really mapped right now. | |
2549 We grab the server to do this, because that's the only way to | |
2550 eliminate the race condition. | |
2551 */ | |
2552 XGrabServer (XtDisplay (shell_widget)); | |
2553 if (XGetWindowAttributes (XtDisplay (shell_widget), | |
2554 XtWindow (shell_widget), | |
2555 &xwa)) | |
2556 /* JV: it is bad to change the visibility like this, so we don't for the | |
2557 moment, at least change_frame_visibility should be called | |
2558 Note also that under fvwm a frame can be Viewable (and thus Mapped) | |
2559 but still X-invisible | |
2560 f->visible = xwa.map_state == IsViewable; */ | |
2561 viewable = xwa.map_state == IsViewable; | |
2562 | |
2563 | |
2564 if (viewable) | |
2565 { | |
2566 Window focus; | |
2567 int revert_to; | |
2568 XGetInputFocus (XtDisplay (shell_widget), &focus, &revert_to); | |
2569 /* Don't explicitly set the focus on this window unless the focus | |
2570 was on some other window (not PointerRoot). Note that, even when | |
2571 running a point-to-type window manager like *twm, there is always | |
2572 a focus window; the window manager maintains that based on the | |
2573 mouse position. If you set the "NoTitleFocus" option in these | |
2574 window managers, then the server itself maintains the focus via | |
2575 PointerRoot, and changing that to focus on the window would make | |
2576 the window grab the focus. Very bad. | |
2577 */ | |
2578 if (focus != PointerRoot) | |
2579 { | |
2580 XSetInputFocus (XtDisplay (shell_widget), | |
2581 XtWindow (shell_widget), | |
2582 RevertToParent, | |
4706 | 2583 CurrentTime); |
428 | 2584 XFlush (XtDisplay (shell_widget)); |
2585 } | |
2586 } | |
2587 XUngrabServer (XtDisplay (shell_widget)); | |
2588 XFlush (XtDisplay (shell_widget)); /* hey, I'd like to DEBUG this... */ | |
2589 } | |
2590 | |
450 | 2591 /* Destroy the X window of frame F. */ |
428 | 2592 static void |
2593 x_delete_frame (struct frame *f) | |
2594 { | |
2595 Display *dpy; | |
2596 | |
2597 #ifndef HAVE_WMCOMMAND | |
2598 if (FRAME_X_TOP_LEVEL_FRAME_P (f)) | |
2599 x_wm_maybe_move_wm_command (f); | |
2600 #endif /* HAVE_WMCOMMAND */ | |
2601 | |
2602 #ifdef HAVE_CDE | |
2603 DtDndDropUnregister (FRAME_X_TEXT_WIDGET (f)); | |
2604 #endif /* HAVE_CDE */ | |
2605 | |
4916
a6c778975d7d
split USE_XFT into HAVE_XFT/USE_XFT
Ben Wing <ben@xemacs.org>
parents:
4790
diff
changeset
|
2606 #ifdef HAVE_XFT |
3094 | 2607 /* If we have an XftDraw structure, we need to free it here. |
2608 We can't ever have an XftDraw without a Display, so we are safe | |
2609 to free it in here, and we avoid too much playing around with the | |
2610 malloc checking hooks this way. */ | |
2611 if (FRAME_X_XFTDRAW (f)) | |
2612 { | |
2613 XftDrawDestroy (FRAME_X_XFTDRAW (f)); | |
2614 FRAME_X_XFTDRAW (f) = NULL; | |
2615 } | |
2616 #endif | |
2617 | |
2618 | |
428 | 2619 assert (FRAME_X_SHELL_WIDGET (f) != 0); |
2620 dpy = XtDisplay (FRAME_X_SHELL_WIDGET (f)); | |
2621 | |
2622 #ifdef EXTERNAL_WIDGET | |
1024 | 2623 expect_x_error (dpy); |
428 | 2624 /* for obscure reasons having (I think) to do with the internal |
2625 window-to-widget hierarchy maintained by Xt, we have to call | |
2626 XtUnrealizeWidget() here. Xt can really suck. */ | |
2627 if (f->being_deleted) | |
2628 XtUnrealizeWidget (FRAME_X_SHELL_WIDGET (f)); | |
2629 XtDestroyWidget (FRAME_X_SHELL_WIDGET (f)); | |
1024 | 2630 x_error_occurred_p (dpy); |
428 | 2631 #else |
2632 XtDestroyWidget (FRAME_X_SHELL_WIDGET (f)); | |
2633 /* make sure the windows are really gone! */ | |
440 | 2634 /* #### Is this REALLY necessary? */ |
428 | 2635 XFlush (dpy); |
2636 #endif /* EXTERNAL_WIDGET */ | |
2637 | |
2638 FRAME_X_SHELL_WIDGET (f) = 0; | |
2639 | |
2640 if (FRAME_X_GEOM_FREE_ME_PLEASE (f)) | |
2641 { | |
4976
16112448d484
Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents:
4969
diff
changeset
|
2642 xfree (FRAME_X_GEOM_FREE_ME_PLEASE (f)); |
428 | 2643 FRAME_X_GEOM_FREE_ME_PLEASE (f) = 0; |
2644 } | |
2645 | |
2646 if (f->frame_data) | |
2647 { | |
4117 | 2648 #ifndef NEW_GC |
4976
16112448d484
Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents:
4969
diff
changeset
|
2649 xfree (f->frame_data); |
3092 | 2650 #endif /* not NEW_GC */ |
428 | 2651 f->frame_data = 0; |
2652 } | |
2653 } | |
2654 | |
2655 static void | |
2367 | 2656 x_update_frame_external_traits (struct frame *frm, Lisp_Object name) |
428 | 2657 { |
2658 Arg al[10]; | |
2659 int ac = 0; | |
793 | 2660 Lisp_Object frame = wrap_frame (frm); |
2661 | |
428 | 2662 |
2663 if (EQ (name, Qforeground)) | |
2664 { | |
2665 Lisp_Object color = FACE_FOREGROUND (Vdefault_face, frame); | |
2666 XColor fgc; | |
2667 | |
2668 if (!EQ (color, Vthe_null_color_instance)) | |
2669 { | |
2670 fgc = COLOR_INSTANCE_X_COLOR (XCOLOR_INSTANCE (color)); | |
4528
726060ee587c
First draft of g++ 4.3 warning removal patch. Builds. *Needs ChangeLogs.*
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4522
diff
changeset
|
2671 Xt_SET_ARG (al[ac], XtNforeground, (void *) fgc.pixel); ac++; |
428 | 2672 } |
2673 } | |
2674 else if (EQ (name, Qbackground)) | |
2675 { | |
2676 Lisp_Object color = FACE_BACKGROUND (Vdefault_face, frame); | |
2677 XColor bgc; | |
2678 | |
2679 if (!EQ (color, Vthe_null_color_instance)) | |
2680 { | |
2681 bgc = COLOR_INSTANCE_X_COLOR (XCOLOR_INSTANCE (color)); | |
4528
726060ee587c
First draft of g++ 4.3 warning removal patch. Builds. *Needs ChangeLogs.*
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4522
diff
changeset
|
2682 Xt_SET_ARG (al[ac], XtNbackground, (void *) bgc.pixel); ac++; |
428 | 2683 } |
2684 | |
2685 /* Really crappy way to force the modeline shadows to be | |
2686 redrawn. But effective. */ | |
2687 MARK_FRAME_WINDOWS_STRUCTURE_CHANGED (frm); | |
2688 MARK_FRAME_CHANGED (frm); | |
2689 } | |
2690 else if (EQ (name, Qfont)) | |
2691 { | |
2692 Lisp_Object font = FACE_FONT (Vdefault_face, frame, Vcharset_ascii); | |
2693 | |
3676 | 2694 /* It may be that instantiating the font has deleted the frame (will |
2695 happen if the user has specified a charset registry for ASCII that | |
2696 isn't available on the server, and our fallback of iso8859-1 isn't | |
2697 available; something vanishingly rare.) In that case, return from | |
2698 this function without further manipulation of the dead frame. */ | |
2699 | |
2700 if (!FRAME_LIVE_P(frm)) | |
2701 { | |
2702 return; | |
2703 } | |
2704 | |
3094 | 2705 /* #### what to do about Xft? I don't think the font is actually used |
2706 to compute cell size for computing frame pixel dimensions (see call | |
2707 to EmacsFrameRecomputeCellSize() below); where is it used? -- sjt | |
2708 What does XtSetValues() do if that resource isn't present? */ | |
428 | 2709 if (!EQ (font, Vthe_null_font_instance)) |
1746 | 2710 { |
3094 | 2711 if (0) |
2712 ; | |
4916
a6c778975d7d
split USE_XFT into HAVE_XFT/USE_XFT
Ben Wing <ben@xemacs.org>
parents:
4790
diff
changeset
|
2713 #ifdef HAVE_XFT |
3094 | 2714 else if (FONT_INSTANCE_X_XFTFONT (XFONT_INSTANCE (font))) |
2715 { | |
4528
726060ee587c
First draft of g++ 4.3 warning removal patch. Builds. *Needs ChangeLogs.*
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4522
diff
changeset
|
2716 Xt_SET_ARG (al[ac], XtNxftFont, |
3094 | 2717 (void *) FONT_INSTANCE_X_XFTFONT (XFONT_INSTANCE (font))); |
2718 ac++; | |
2719 } | |
2720 #endif | |
2721 else if (FONT_INSTANCE_X_FONT (XFONT_INSTANCE (font))) | |
2722 { | |
4528
726060ee587c
First draft of g++ 4.3 warning removal patch. Builds. *Needs ChangeLogs.*
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4522
diff
changeset
|
2723 Xt_SET_ARG (al[ac], XtNfont, |
726060ee587c
First draft of g++ 4.3 warning removal patch. Builds. *Needs ChangeLogs.*
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4522
diff
changeset
|
2724 (void *) FONT_INSTANCE_X_FONT (XFONT_INSTANCE (font))); |
3094 | 2725 ac++; |
2726 } | |
1746 | 2727 } |
428 | 2728 } |
2729 else | |
2500 | 2730 ABORT (); |
428 | 2731 |
2732 XtSetValues (FRAME_X_TEXT_WIDGET (frm), al, ac); | |
2733 | |
2734 #ifdef HAVE_TOOLBARS | |
2735 /* Setting the background clears the entire frame area | |
2736 including the toolbar so we force an immediate redraw of | |
2737 it. */ | |
2738 if (EQ (name, Qbackground)) | |
2739 MAYBE_DEVMETH (XDEVICE (frm->device), redraw_frame_toolbars, (frm)); | |
2740 #endif /* HAVE_TOOLBARS */ | |
2741 | |
2742 /* Set window manager resize increment hints according to | |
2743 the new character size */ | |
2744 if (EQ (name, Qfont)) | |
2745 EmacsFrameRecomputeCellSize (FRAME_X_TEXT_WIDGET (frm)); | |
2746 } | |
2747 | |
2748 | |
2749 /************************************************************************/ | |
2750 /* initialization */ | |
2751 /************************************************************************/ | |
2752 | |
2753 void | |
2754 syms_of_frame_x (void) | |
2755 { | |
3092 | 2756 #ifdef NEW_GC |
2757 INIT_LRECORD_IMPLEMENTATION (x_frame); | |
2758 #endif /* NEW_GC */ | |
2759 | |
2747 | 2760 DEFSYMBOL (Qoverride_redirect); |
563 | 2761 DEFSYMBOL (Qx_resource_name); |
428 | 2762 |
2763 DEFSUBR (Fx_window_id); | |
2764 #ifdef HAVE_CDE | |
2765 DEFSUBR (Fcde_start_drag_internal); | |
2766 #endif | |
2767 } | |
2768 | |
2769 void | |
2770 console_type_create_frame_x (void) | |
2771 { | |
2772 /* frame methods */ | |
2773 CONSOLE_HAS_METHOD (x, init_frame_1); | |
2774 CONSOLE_HAS_METHOD (x, init_frame_2); | |
2775 CONSOLE_HAS_METHOD (x, init_frame_3); | |
2776 CONSOLE_HAS_METHOD (x, mark_frame); | |
2777 CONSOLE_HAS_METHOD (x, focus_on_frame); | |
2778 CONSOLE_HAS_METHOD (x, delete_frame); | |
2779 CONSOLE_HAS_METHOD (x, get_mouse_position); | |
2780 CONSOLE_HAS_METHOD (x, set_mouse_position); | |
2781 CONSOLE_HAS_METHOD (x, raise_frame); | |
2782 CONSOLE_HAS_METHOD (x, lower_frame); | |
442 | 2783 CONSOLE_HAS_METHOD (x, enable_frame); |
2784 CONSOLE_HAS_METHOD (x, disable_frame); | |
428 | 2785 CONSOLE_HAS_METHOD (x, make_frame_visible); |
2786 CONSOLE_HAS_METHOD (x, make_frame_invisible); | |
2787 CONSOLE_HAS_METHOD (x, iconify_frame); | |
2788 CONSOLE_HAS_METHOD (x, set_frame_size); | |
2789 CONSOLE_HAS_METHOD (x, set_frame_position); | |
2790 CONSOLE_HAS_METHOD (x, frame_property); | |
2791 CONSOLE_HAS_METHOD (x, internal_frame_property_p); | |
2792 CONSOLE_HAS_METHOD (x, frame_properties); | |
2793 CONSOLE_HAS_METHOD (x, set_frame_properties); | |
867 | 2794 CONSOLE_HAS_METHOD (x, set_title_from_ibyte); |
2795 CONSOLE_HAS_METHOD (x, set_icon_name_from_ibyte); | |
428 | 2796 CONSOLE_HAS_METHOD (x, frame_visible_p); |
2797 CONSOLE_HAS_METHOD (x, frame_totally_visible_p); | |
2798 CONSOLE_HAS_METHOD (x, frame_iconified_p); | |
2799 CONSOLE_HAS_METHOD (x, set_frame_pointer); | |
2800 CONSOLE_HAS_METHOD (x, set_frame_icon); | |
2801 CONSOLE_HAS_METHOD (x, get_frame_parent); | |
2802 CONSOLE_HAS_METHOD (x, update_frame_external_traits); | |
2803 } | |
2804 | |
2805 void | |
2806 vars_of_frame_x (void) | |
2807 { | |
2808 #ifdef EXTERNAL_WIDGET | |
2809 Fprovide (intern ("external-widget")); | |
2810 #endif | |
2811 | |
2812 /* this call uses only safe functions from emacs.c */ | |
2813 init_x_prop_symbols (); | |
2814 | |
2815 DEFVAR_LISP ("default-x-frame-plist", &Vdefault_x_frame_plist /* | |
2816 Plist of default frame-creation properties for X frames. | |
2817 These override what is specified in the resource database and in | |
2818 `default-frame-plist', but are overridden by the arguments to the | |
2819 particular call to `make-frame'. | |
2820 | |
2821 Note: In many cases, properties of a frame are available as specifiers | |
2822 instead of through the frame-properties mechanism. | |
2823 | |
2824 Here is a list of recognized frame properties, other than those | |
2825 documented in `set-frame-properties' (they can be queried and | |
2826 set at any time, except as otherwise noted): | |
2827 | |
2828 window-id The X window ID corresponding to the | |
2829 frame. May be set only at startup, and | |
2830 only if external widget support was | |
2831 compiled in; doing so causes the frame | |
2832 to be created as an "external widget" | |
2833 in another program that uses an existing | |
2834 window in the program rather than creating | |
2835 a new one. | |
2836 initially-unmapped If non-nil, the frame will not be visible | |
2837 when it is created. In this case, you | |
2838 need to call `make-frame-visible' to make | |
2839 the frame appear. | |
2840 popup If non-nil, it should be a frame, and this | |
2841 frame will be created as a "popup" frame | |
2842 whose parent is the given frame. This | |
2843 will make the window manager treat the | |
2844 frame as a dialog box, which may entail | |
2845 doing different things (e.g. not asking | |
2846 for positioning, and not iconifying | |
2847 separate from its parent). | |
2747 | 2848 override-redirect If non-nil, the frame will not be subject to |
2849 window-manager control. In particular, it | |
2850 will lack decorations, for more attractive | |
2851 appearance of balloon help, aka tooltips. | |
428 | 2852 inter-line-space Not currently implemented. |
2853 toolbar-shadow-thickness Thickness of toolbar shadows. | |
2854 background-toolbar-color Color of toolbar background. | |
2855 bottom-toolbar-shadow-color Color of bottom shadows on toolbars. | |
2856 (*Not* specific to the bottom-toolbar.) | |
2857 top-toolbar-shadow-color Color of top shadows on toolbars. | |
2858 (*Not* specific to the top-toolbar.) | |
2859 internal-border-width Width of internal border around text area. | |
2860 border-width Width of external border around text area. | |
2861 top Y position (in pixels) of the upper-left | |
2862 outermost corner of the frame (i.e. the | |
2863 upper-left of the window-manager | |
2864 decorations). | |
2865 left X position (in pixels) of the upper-left | |
2866 outermost corner of the frame (i.e. the | |
2867 upper-left of the window-manager | |
2868 decorations). | |
2869 border-color Color of external border around text area. | |
2870 cursor-color Color of text cursor. | |
2871 | |
2872 See also `default-frame-plist', which specifies properties which apply | |
2873 to all frames, not just X frames. | |
2874 */ ); | |
2875 Vdefault_x_frame_plist = Qnil; | |
2876 | |
2877 x_console_methods->device_specific_frame_props = &Vdefault_x_frame_plist; | |
2878 } |