462
|
1 /* Functions for the X window system.
|
|
2 Copyright (C) 1989, 1992-5, 1997 Free Software Foundation, Inc.
|
1346
|
3 Copyright (C) 1995, 1996, 2002, 2003 Ben Wing.
|
462
|
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
|
|
24 /* Substantially rewritten for XEmacs. */
|
|
25 /* Revamped to use Gdk/Gtk by William Perry */
|
|
26
|
|
27 #include <config.h>
|
|
28 #include "lisp.h"
|
|
29
|
872
|
30 #include "buffer.h"
|
|
31 #include "device-impl.h"
|
|
32 #include "events.h"
|
|
33 #include "extents.h"
|
|
34 #include "faces.h"
|
|
35 #include "frame-impl.h"
|
|
36 #include "window.h"
|
|
37
|
|
38 #ifdef HAVE_DRAGNDROP
|
|
39 #include "dragdrop.h"
|
|
40 #endif
|
|
41
|
|
42 #include "console-gtk-impl.h"
|
462
|
43 #include "glyphs-gtk.h"
|
872
|
44 #include "objects-gtk-impl.h"
|
462
|
45 #include "scrollbar-gtk.h"
|
872
|
46 #include "ui-gtk.h"
|
462
|
47
|
|
48 #include "gtk-xemacs.h"
|
|
49
|
|
50 #ifdef HAVE_GNOME
|
|
51 #include <libgnomeui/libgnomeui.h>
|
|
52 #endif
|
|
53
|
|
54 #define BORDER_WIDTH 0
|
|
55 #define INTERNAL_BORDER_WIDTH 0
|
|
56
|
|
57 #define TRANSIENT_DATA_IDENTIFIER "xemacs::transient_for"
|
|
58 #define FRAME_DATA_IDENTIFIER "xemacs::frame"
|
|
59 #define UNMAPPED_DATA_IDENTIFIER "xemacs::initially_unmapped"
|
|
60
|
|
61 #define STUPID_X_SPECIFIC_GTK_STUFF
|
|
62
|
|
63 #ifdef STUPID_X_SPECIFIC_GTK_STUFF
|
|
64 #include <gdk/gdkx.h>
|
|
65 #endif
|
|
66
|
|
67 /* Default properties to use when creating frames. */
|
|
68 Lisp_Object Vdefault_gtk_frame_plist;
|
|
69
|
|
70 Lisp_Object Qdetachable_menubar;
|
|
71 Lisp_Object Qtext_widget;
|
|
72 Lisp_Object Qcontainer_widget;
|
|
73 Lisp_Object Qshell_widget;
|
|
74
|
|
75 #ifdef STUPID_X_SPECIFIC_GTK_STUFF
|
|
76 EXFUN (Fgtk_window_id, 1);
|
|
77 #endif
|
|
78
|
|
79 #ifdef HAVE_DRAGNDROP
|
|
80 enum {
|
|
81 TARGET_TYPE_STRING,
|
|
82 TARGET_TYPE_URI_LIST,
|
|
83 };
|
|
84
|
|
85 static GtkTargetEntry dnd_target_table[] = {
|
|
86 { "STRING", 0, TARGET_TYPE_STRING },
|
|
87 { "text/plain", 0, TARGET_TYPE_STRING },
|
|
88 { "text/uri-list", 0, TARGET_TYPE_URI_LIST },
|
|
89 { "_NETSCAPE_URL", 0, TARGET_TYPE_STRING }
|
|
90 };
|
|
91
|
|
92 static guint dnd_n_targets = sizeof(dnd_target_table) / sizeof(dnd_target_table[0]);
|
|
93
|
|
94 #endif
|
|
95
|
1204
|
96 static const struct memory_description gtk_frame_data_description_1 [] = {
|
|
97 { XD_LISP_OBJECT, offsetof (struct gtk_frame, icon_pixmap) },
|
|
98 { XD_LISP_OBJECT, offsetof (struct gtk_frame, icon_pixmap_mask) },
|
|
99 { XD_LISP_OBJECT_ARRAY, offsetof (struct gtk_frame, lisp_visible_widgets),
|
|
100 3 },
|
1346
|
101 { XD_LISP_OBJECT, offsetof (struct gtk_frame, menubar_data) },
|
1204
|
102 { XD_END }
|
|
103 };
|
|
104
|
|
105 extern const struct sized_memory_description gtk_frame_data_description;
|
|
106
|
|
107 const struct sized_memory_description gtk_frame_data_description = {
|
|
108 sizeof (struct gtk_frame), gtk_frame_data_description_1
|
|
109 };
|
|
110
|
462
|
111
|
|
112 /************************************************************************/
|
|
113 /* helper functions */
|
|
114 /************************************************************************/
|
|
115
|
|
116 /* Return the Emacs frame-object corresponding to an X window */
|
|
117 struct frame *
|
|
118 gtk_window_to_frame (struct device *d, GdkWindow *wdesc)
|
|
119 {
|
|
120 Lisp_Object tail, frame;
|
|
121 struct frame *f;
|
|
122
|
|
123 /* This function was previously written to accept only a window argument
|
|
124 (and to loop over all devices looking for a matching window), but
|
|
125 that is incorrect because window ID's are not unique across displays. */
|
|
126
|
|
127 for (tail = DEVICE_FRAME_LIST (d); CONSP (tail); tail = XCDR (tail))
|
|
128 {
|
|
129 frame = XCAR (tail);
|
|
130 if (!FRAMEP (frame))
|
|
131 continue;
|
|
132 f = XFRAME (frame);
|
|
133 if (FRAME_GTK_P (f) && GET_GTK_WIDGET_WINDOW (FRAME_GTK_TEXT_WIDGET (f)) == wdesc)
|
|
134 return f;
|
|
135 }
|
|
136 return 0;
|
|
137 }
|
|
138
|
|
139 /* Like gtk_window_to_frame but also compares the window with the widget's
|
|
140 windows */
|
|
141 struct frame *
|
|
142 gtk_any_window_to_frame (struct device *d, GdkWindow *w)
|
|
143 {
|
|
144 do
|
|
145 {
|
|
146 Lisp_Object frmcons;
|
|
147
|
|
148 DEVICE_FRAME_LOOP (frmcons, d)
|
|
149 {
|
|
150 struct frame *fr = XFRAME (XCAR (frmcons));
|
|
151 if ((w == GET_GTK_WIDGET_WINDOW (FRAME_GTK_SHELL_WIDGET (fr))) ||
|
|
152 (w == GET_GTK_WIDGET_WINDOW (FRAME_GTK_CONTAINER_WIDGET (fr))) ||
|
|
153 #ifdef HAVE_MENUBARS
|
|
154 (w == GET_GTK_WIDGET_WINDOW (FRAME_GTK_MENUBAR_WIDGET (fr))) ||
|
|
155 #endif
|
|
156 (w == GET_GTK_WIDGET_WINDOW (FRAME_GTK_TEXT_WIDGET (fr))))
|
|
157 {
|
|
158 return (fr);
|
|
159 }
|
|
160 }
|
|
161 w = gdk_window_get_parent (w);
|
|
162 } while (w);
|
|
163
|
|
164 return (0);
|
|
165 }
|
|
166
|
|
167 struct frame *
|
|
168 gtk_any_widget_or_parent_to_frame (struct device *d, GtkWidget *widget)
|
|
169 {
|
|
170 return (gtk_any_window_to_frame (d, GET_GTK_WIDGET_WINDOW (widget)));
|
|
171 }
|
|
172
|
|
173 struct device *
|
|
174 gtk_any_window_to_device (GdkWindow *w)
|
|
175 {
|
|
176 struct device *d = NULL;
|
|
177 Lisp_Object devcons, concons;
|
|
178
|
|
179 DEVICE_LOOP_NO_BREAK (devcons, concons)
|
|
180 {
|
|
181 d = XDEVICE (XCAR (devcons));
|
|
182 if (!DEVICE_GTK_P (d)) continue;
|
|
183 if (gtk_any_window_to_frame (d, w))
|
|
184 return (d);
|
|
185 }
|
|
186 return (NULL);
|
|
187 }
|
|
188
|
|
189 struct frame *
|
|
190 decode_gtk_frame (Lisp_Object frame)
|
|
191 {
|
|
192 if (NILP (frame))
|
793
|
193 frame = wrap_frame (selected_frame ());
|
462
|
194 CHECK_LIVE_FRAME (frame);
|
|
195 /* this will also catch dead frames, but putting in the above check
|
|
196 results in a more useful error */
|
|
197 CHECK_GTK_FRAME (frame);
|
|
198 return XFRAME (frame);
|
|
199 }
|
|
200
|
|
201
|
|
202 /************************************************************************/
|
|
203 /* window-manager interactions */
|
|
204 /************************************************************************/
|
|
205 static int
|
|
206 gtk_frame_iconified_p (struct frame *f)
|
|
207 {
|
|
208 return (f->iconified);
|
|
209 }
|
|
210
|
|
211
|
|
212 /************************************************************************/
|
|
213 /* frame properties */
|
|
214 /************************************************************************/
|
|
215
|
|
216 static Lisp_Object
|
|
217 gtk_frame_property (struct frame *f, Lisp_Object property)
|
|
218 {
|
|
219 GtkWidget *shell = FRAME_GTK_SHELL_WIDGET (f);
|
|
220
|
|
221 if (EQ (Qleft, property) || EQ (Qtop, property))
|
|
222 {
|
|
223 gint x, y;
|
|
224 if (!GET_GTK_WIDGET_WINDOW(shell))
|
|
225 return Qzero;
|
|
226 gdk_window_get_deskrelative_origin (GET_GTK_WIDGET_WINDOW (shell), &x, &y);
|
|
227 if (EQ (Qleft, property)) return make_int (x);
|
|
228 if (EQ (Qtop, property)) return make_int (y);
|
|
229 }
|
|
230 if (EQ (Qshell_widget, property))
|
|
231 {
|
|
232 return (FRAME_GTK_LISP_WIDGETS (f)[0]);
|
|
233 }
|
|
234 if (EQ (Qcontainer_widget, property))
|
|
235 {
|
|
236 return (FRAME_GTK_LISP_WIDGETS (f)[1]);
|
|
237 }
|
|
238 if (EQ (Qtext_widget, property))
|
|
239 {
|
|
240 return (FRAME_GTK_LISP_WIDGETS (f)[2]);
|
|
241 }
|
|
242 #ifdef STUPID_X_SPECIFIC_GTK_STUFF
|
|
243 if (EQ (Qwindow_id, property))
|
771
|
244 return Fgtk_window_id (wrap_frame (f));
|
462
|
245 #endif
|
|
246
|
|
247 return Qunbound;
|
|
248 }
|
|
249
|
|
250 static int
|
|
251 gtk_internal_frame_property_p (struct frame *f, Lisp_Object property)
|
|
252 {
|
|
253 return EQ (property, Qleft)
|
|
254 || EQ (property, Qtop)
|
|
255 || EQ (Qshell_widget, property)
|
|
256 || EQ (Qcontainer_widget, property)
|
|
257 || EQ (Qtext_widget, property)
|
|
258 || EQ (property, Qwindow_id)
|
|
259 || STRINGP (property);
|
|
260 }
|
|
261
|
|
262 static Lisp_Object
|
|
263 gtk_frame_properties (struct frame *f)
|
|
264 {
|
|
265 Lisp_Object props = Qnil;
|
|
266 GtkWidget *shell = FRAME_GTK_SHELL_WIDGET (f);
|
|
267 gint x, y;
|
|
268
|
|
269 props = cons3 (Qshell_widget, FRAME_GTK_LISP_WIDGETS (f)[0], props);
|
|
270 props = cons3 (Qcontainer_widget, FRAME_GTK_LISP_WIDGETS (f)[1], props);
|
|
271 props = cons3 (Qtext_widget, FRAME_GTK_LISP_WIDGETS (f)[2], props);
|
|
272
|
|
273 #ifdef STUPID_X_SPECIFIC_GTK_STUFF
|
771
|
274 props = cons3 (Qwindow_id, Fgtk_window_id (wrap_frame (f)), props);
|
462
|
275 #endif
|
|
276
|
|
277 if (!GET_GTK_WIDGET_WINDOW (shell))
|
|
278 x = y = 0;
|
|
279 else
|
|
280 gdk_window_get_deskrelative_origin (GET_GTK_WIDGET_WINDOW (shell), &x, &y);
|
|
281
|
|
282 props = cons3 (Qtop, make_int (y), props);
|
|
283 props = cons3 (Qleft, make_int (x), props);
|
|
284
|
|
285 return props;
|
|
286 }
|
|
287
|
|
288
|
|
289 /* Functions called only from `gtk_set_frame_properties' to set
|
|
290 individual properties. */
|
|
291
|
|
292 static void
|
867
|
293 gtk_set_frame_text_value (struct frame *f, Ibyte *value,
|
462
|
294 void (*func) (gpointer, gchar *),
|
|
295 gpointer arg)
|
|
296 {
|
|
297 gchar *the_text = (gchar *) value;
|
|
298
|
|
299 /* Programmer fuckup or window is not realized yet. */
|
|
300 if (!func || !arg) return;
|
|
301
|
|
302 #ifdef MULE
|
|
303 {
|
867
|
304 Ibyte *ptr;
|
462
|
305
|
|
306 /* Optimize for common ASCII case */
|
|
307 for (ptr = value; *ptr; ptr++)
|
826
|
308 if (!byte_ascii_p (*ptr))
|
462
|
309 {
|
|
310 char *tmp;
|
|
311 C_STRING_TO_EXTERNAL (value, tmp, Qctext);
|
|
312 the_text = tmp;
|
|
313 break;
|
|
314 }
|
|
315 }
|
|
316 #endif /* MULE */
|
|
317
|
|
318 (*func) (arg, (gchar *) the_text);
|
|
319 }
|
|
320
|
|
321 static void
|
867
|
322 gtk_set_title_from_ibyte (struct frame *f, Ibyte *name)
|
462
|
323 {
|
|
324 if (GTK_IS_WINDOW (FRAME_GTK_SHELL_WIDGET (f)))
|
|
325 gtk_set_frame_text_value (f, name,
|
|
326 (void (*)(gpointer, gchar *))
|
|
327 gtk_window_set_title, FRAME_GTK_SHELL_WIDGET (f));
|
|
328 }
|
|
329
|
|
330 static void
|
867
|
331 gtk_set_icon_name_from_ibyte (struct frame *f, Ibyte *name)
|
462
|
332 {
|
|
333 gtk_set_frame_text_value (f, name,
|
|
334 (void (*)(gpointer, gchar *))
|
|
335 gdk_window_set_icon_name, FRAME_GTK_SHELL_WIDGET (f)->window);
|
|
336 }
|
|
337
|
|
338 /* Set the initial frame size as specified. This function is used
|
|
339 when the frame's widgets have not yet been realized.
|
|
340 */
|
|
341 static void
|
|
342 gtk_set_initial_frame_size (struct frame *f, int x, int y,
|
|
343 unsigned int w, unsigned int h)
|
|
344 {
|
|
345 GtkWidget *shell = FRAME_GTK_SHELL_WIDGET (f);
|
|
346 GdkGeometry geometry;
|
|
347
|
|
348 if (GTK_IS_WINDOW (shell))
|
|
349 {
|
2054
|
350 GdkWindowHints geometry_mask = GDK_HINT_RESIZE_INC;
|
462
|
351 /* Deal with the cell size */
|
771
|
352 default_face_height_and_width (wrap_frame (f), &geometry.height_inc, &geometry.width_inc);
|
462
|
353
|
|
354 gtk_window_set_geometry_hints (GTK_WINDOW (shell),
|
|
355 FRAME_GTK_TEXT_WIDGET (f), &geometry, geometry_mask);
|
|
356 gdk_window_set_hints (GET_GTK_WIDGET_WINDOW (shell), x, y, 0, 0, 0, 0, GDK_HINT_POS);
|
|
357 gtk_window_set_policy (GTK_WINDOW (shell), TRUE, TRUE, FALSE);
|
|
358 }
|
|
359
|
|
360 FRAME_HEIGHT (f) = h;
|
|
361 FRAME_WIDTH (f) = w;
|
|
362
|
|
363 change_frame_size (f, h, w, 0);
|
|
364 {
|
|
365 GtkRequisition req;
|
|
366
|
|
367 gtk_widget_size_request (FRAME_GTK_SHELL_WIDGET (f), &req);
|
|
368 gtk_widget_set_usize (FRAME_GTK_SHELL_WIDGET (f), req.width, req.height);
|
|
369 }
|
|
370 }
|
|
371
|
|
372 /* Report that a frame property of frame S is being set or changed.
|
|
373 If the property is not specially recognized, do nothing.
|
|
374 */
|
|
375
|
|
376 static void
|
|
377 gtk_set_frame_properties (struct frame *f, Lisp_Object plist)
|
|
378 {
|
|
379 gint x, y;
|
|
380 gint width = 0, height = 0;
|
|
381 gboolean width_specified_p = FALSE;
|
|
382 gboolean height_specified_p = FALSE;
|
|
383 gboolean x_position_specified_p = FALSE;
|
|
384 gboolean y_position_specified_p = FALSE;
|
|
385 Lisp_Object tail;
|
|
386
|
|
387 for (tail = plist; !NILP (tail); tail = Fcdr (Fcdr (tail)))
|
|
388 {
|
|
389 Lisp_Object prop = Fcar (tail);
|
|
390 Lisp_Object val = Fcar (Fcdr (tail));
|
|
391
|
|
392 if (SYMBOLP (prop))
|
|
393 {
|
|
394 if (EQ (prop, Qfont))
|
|
395 {
|
|
396 /* If the value is not a string we silently ignore it. */
|
|
397 if (STRINGP (val))
|
|
398 {
|
|
399 Lisp_Object frm, font_spec;
|
|
400
|
793
|
401 frm = wrap_frame (f);
|
462
|
402 font_spec = Fget (Fget_face (Qdefault), Qfont, Qnil);
|
|
403
|
|
404 Fadd_spec_to_specifier (font_spec, val, frm, Qnil, Qnil);
|
|
405 update_frame_face_values (f);
|
|
406 }
|
|
407 continue;
|
|
408 }
|
|
409 else if (EQ (prop, Qwidth))
|
|
410 {
|
|
411 CHECK_INT (val);
|
|
412 width = XINT (val);
|
|
413 width_specified_p = TRUE;
|
|
414 continue;
|
|
415 }
|
|
416 else if (EQ (prop, Qheight))
|
|
417 {
|
|
418 CHECK_INT (val);
|
|
419 height = XINT (val);
|
|
420 height_specified_p = TRUE;
|
|
421 continue;
|
|
422 }
|
|
423 /* Further kludge the x/y. */
|
|
424 else if (EQ (prop, Qx))
|
|
425 {
|
|
426 CHECK_INT (val);
|
|
427 x = (gint) XINT (val);
|
|
428 x_position_specified_p = TRUE;
|
|
429 continue;
|
|
430 }
|
|
431 else if (EQ (prop, Qy))
|
|
432 {
|
|
433 CHECK_INT (val);
|
|
434 y = (gint) XINT (val);
|
|
435 y_position_specified_p = TRUE;
|
|
436 continue;
|
|
437 }
|
|
438 }
|
|
439 }
|
|
440
|
|
441 /* Kludge kludge kludge. We need to deal with the size and position
|
|
442 specially. */
|
|
443 {
|
|
444 int size_specified_p = width_specified_p || height_specified_p;
|
|
445 int position_specified_p = x_position_specified_p || y_position_specified_p;
|
|
446
|
|
447 if (!width_specified_p)
|
|
448 width = 80;
|
|
449 if (!height_specified_p)
|
|
450 height = 30;
|
|
451
|
|
452 /* Kludge kludge kludge kludge. */
|
|
453 if (position_specified_p &&
|
|
454 (!x_position_specified_p || !y_position_specified_p))
|
|
455 {
|
|
456 gint dummy;
|
|
457 GtkWidget *shell = FRAME_GTK_SHELL_WIDGET (f);
|
|
458 gdk_window_get_deskrelative_origin (GET_GTK_WIDGET_WINDOW (shell),
|
|
459 (x_position_specified_p ? &dummy : &x),
|
|
460 (y_position_specified_p ? &dummy : &y));
|
|
461 }
|
|
462
|
|
463 if (!f->init_finished)
|
|
464 {
|
|
465 if (size_specified_p || position_specified_p)
|
|
466 gtk_set_initial_frame_size (f, x, y, width, height);
|
|
467 }
|
|
468 else
|
|
469 {
|
|
470 if (size_specified_p)
|
|
471 {
|
793
|
472 Lisp_Object frame = wrap_frame (f);
|
|
473
|
462
|
474 Fset_frame_size (frame, make_int (width), make_int (height), Qnil);
|
|
475 }
|
|
476 if (position_specified_p)
|
|
477 {
|
793
|
478 Lisp_Object frame = wrap_frame (f);
|
|
479
|
462
|
480 Fset_frame_position (frame, make_int (x), make_int (y));
|
|
481 }
|
|
482 }
|
|
483 }
|
|
484 }
|
|
485
|
|
486
|
|
487 /************************************************************************/
|
|
488 /* widget creation */
|
|
489 /************************************************************************/
|
|
490 /* Figure out what size the shell widget should initially be,
|
|
491 and set it. Should be called after the default font has been
|
|
492 determined but before the widget has been realized. */
|
|
493
|
|
494 extern Lisp_Object Vgtk_initial_geometry;
|
|
495
|
|
496 #ifndef HAVE_GNOME
|
|
497 static int
|
|
498 get_number (const char **geometry)
|
|
499 {
|
|
500 int value = 0;
|
|
501 int mult = 1;
|
|
502
|
|
503 if (**geometry == '-'){
|
|
504 mult = -1;
|
|
505 (*geometry)++;
|
|
506 }
|
|
507 while (**geometry && isdigit (**geometry)){
|
|
508 value = value * 10 + (**geometry - '0');
|
|
509 (*geometry)++;
|
|
510 }
|
|
511 return value * mult;
|
|
512 }
|
|
513
|
|
514 /*
|
|
515 */
|
|
516
|
|
517 /**
|
|
518 * gnome_parse_geometry
|
|
519 * @geometry: geometry string to be parsed
|
|
520 * @xpos: X position geometry component
|
|
521 * @ypos: Y position geometry component
|
|
522 * @width: pixel width geometry component
|
|
523 * @height: pixel height geometry component
|
|
524 *
|
|
525 * Description:
|
|
526 * Parses the geometry string passed in @geometry, and fills
|
|
527 * @xpos, @ypos, @width, and @height with
|
|
528 * the corresponding values upon completion of the parse.
|
|
529 * If the parse fails, it should be assumed that @xpos, @ypos, @width,
|
|
530 * and @height contain undefined values.
|
|
531 *
|
|
532 * Returns:
|
|
533 * %TRUE if the geometry was successfully parsed, %FALSE otherwise.
|
|
534 **/
|
|
535
|
|
536 static gboolean
|
|
537 gnome_parse_geometry (const gchar *geometry, gint *xpos,
|
|
538 gint *ypos, gint *width, gint *height)
|
|
539 {
|
|
540 int subtract;
|
|
541
|
|
542 g_return_val_if_fail (xpos != NULL, FALSE);
|
|
543 g_return_val_if_fail (ypos != NULL, FALSE);
|
|
544 g_return_val_if_fail (width != NULL, FALSE);
|
|
545 g_return_val_if_fail (height != NULL, FALSE);
|
|
546
|
|
547 *xpos = *ypos = *width = *height = -1;
|
|
548
|
|
549 if (!geometry)
|
|
550 return FALSE;
|
|
551
|
|
552 if (*geometry == '=')
|
|
553 geometry++;
|
|
554 if (!*geometry)
|
|
555 return FALSE;
|
|
556 if (isdigit (*geometry))
|
|
557 *width = get_number (&geometry);
|
|
558 if (!*geometry)
|
|
559 return TRUE;
|
|
560 if (*geometry == 'x' || *geometry == 'X'){
|
|
561 geometry++;
|
|
562 *height = get_number (&geometry);
|
|
563 }
|
|
564 if (!*geometry)
|
|
565 return 1;
|
|
566 if (*geometry == '+'){
|
|
567 subtract = 0;
|
|
568 geometry++;
|
|
569 } else if (*geometry == '-'){
|
|
570 subtract = gdk_screen_width ();
|
|
571 geometry++;
|
|
572 } else
|
|
573 return FALSE;
|
|
574 *xpos = get_number (&geometry);
|
|
575 if (subtract)
|
|
576 *xpos = subtract - *xpos;
|
|
577 if (!*geometry)
|
|
578 return TRUE;
|
|
579 if (*geometry == '+'){
|
|
580 subtract = 0;
|
|
581 geometry++;
|
|
582 } else if (*geometry == '-'){
|
|
583 subtract = gdk_screen_height ();
|
|
584 geometry++;
|
|
585 } else
|
|
586 return FALSE;
|
|
587 *ypos = get_number (&geometry);
|
|
588 if (subtract)
|
|
589 *ypos = subtract - *ypos;
|
|
590 return TRUE;
|
|
591 }
|
|
592 #endif
|
|
593
|
|
594 static void
|
|
595 gtk_initialize_frame_size (struct frame *f)
|
|
596 {
|
|
597 gint x = 10, y = 10, w = 80, h = 30;
|
|
598
|
|
599 if (STRINGP (Vgtk_initial_geometry))
|
|
600 {
|
2054
|
601 if (!gnome_parse_geometry ((char*) XSTRING_DATA (Vgtk_initial_geometry), &x,&y,&w,&h))
|
462
|
602 {
|
|
603 x = y = 10;
|
|
604 w = 80;
|
|
605 h = 30;
|
|
606 }
|
|
607 }
|
|
608
|
|
609 /* set the position of the frame's root window now. When the
|
|
610 frame was created, the position was initialized to (0,0). */
|
|
611 {
|
|
612 struct window *win = XWINDOW (f->root_window);
|
|
613
|
|
614 WINDOW_LEFT (win) = FRAME_LEFT_BORDER_END (f);
|
|
615 WINDOW_TOP (win) = FRAME_TOP_BORDER_END (f);
|
|
616
|
|
617 if (!NILP (f->minibuffer_window))
|
|
618 {
|
|
619 win = XWINDOW (f->minibuffer_window);
|
|
620 WINDOW_LEFT (win) = FRAME_LEFT_BORDER_END (f);
|
|
621 }
|
|
622 }
|
|
623
|
|
624 gtk_set_initial_frame_size (f, x, y, w, h);
|
|
625 }
|
|
626
|
|
627 static gboolean
|
|
628 resize_event_cb (GtkWidget *w, GtkAllocation *allocation, gpointer user_data)
|
|
629 {
|
|
630 struct frame *f = (struct frame *) user_data;
|
|
631
|
|
632 f->pixwidth = allocation->width;
|
|
633 f->pixheight = allocation->height;
|
|
634
|
|
635 if (FRAME_GTK_TEXT_WIDGET (f)->window)
|
|
636 {
|
793
|
637 Lisp_Object frame = wrap_frame (f);
|
|
638
|
462
|
639 Fredraw_frame (frame, Qt);
|
|
640 }
|
|
641
|
|
642 return (FALSE);
|
|
643 }
|
|
644
|
|
645 static gboolean
|
|
646 delete_event_cb (GtkWidget *w, GdkEvent *ev, gpointer user_data)
|
|
647 {
|
|
648 struct frame *f = (struct frame *) user_data;
|
793
|
649 Lisp_Object frame = wrap_frame (f);
|
462
|
650
|
|
651 enqueue_misc_user_event (frame, Qeval, list3 (Qdelete_frame, frame, Qt));
|
|
652
|
|
653 /* See if tickling the event queue helps us with our delays when
|
|
654 clicking 'close' */
|
|
655 signal_fake_event ();
|
|
656
|
|
657 return (TRUE);
|
|
658 }
|
|
659
|
|
660 extern gboolean emacs_shell_event_handler (GtkWidget *wid, GdkEvent *event, gpointer closure);
|
|
661 extern Lisp_Object build_gtk_object (GtkObject *obj);
|
|
662
|
|
663 #ifndef GNOME_IS_APP
|
|
664 #define GNOME_IS_APP(x) 0
|
|
665 #define gnome_app_set_contents(x,y) 0
|
|
666 #endif
|
|
667
|
|
668 static void
|
|
669 cleanup_deleted_frame (gpointer data)
|
|
670 {
|
|
671 struct frame *f = (struct frame *) data;
|
793
|
672 Lisp_Object frame = wrap_frame (f);
|
462
|
673
|
|
674 Fdelete_frame (frame, Qt);
|
|
675 }
|
|
676
|
|
677 #ifdef HAVE_DRAGNDROP
|
|
678 extern void
|
|
679 dragndrop_data_received (GtkWidget *widget,
|
|
680 GdkDragContext *context,
|
|
681 gint x,
|
|
682 gint y,
|
|
683 GtkSelectionData *data,
|
|
684 guint info,
|
|
685 guint time);
|
|
686
|
|
687 extern gboolean
|
|
688 dragndrop_dropped (GtkWidget *widget,
|
|
689 GdkDragContext *drag_context,
|
|
690 gint x,
|
|
691 gint y,
|
|
692 guint time,
|
|
693 gpointer user_data);
|
|
694
|
|
695 Lisp_Object Vcurrent_drag_object;
|
|
696
|
|
697 #define DRAG_SELECTION_DATA_ERROR "Error converting drag data to external format"
|
|
698 static void
|
|
699 dragndrop_get_drag (GtkWidget *widget,
|
|
700 GdkDragContext *drag_context,
|
|
701 GtkSelectionData *data,
|
|
702 guint info,
|
|
703 guint time,
|
|
704 gpointer user_data)
|
|
705 {
|
|
706 gtk_selection_data_set (data, GDK_SELECTION_TYPE_STRING, 8,
|
|
707 DRAG_SELECTION_DATA_ERROR,
|
|
708 strlen (DRAG_SELECTION_DATA_ERROR));
|
|
709
|
|
710 switch (info)
|
|
711 {
|
|
712 case TARGET_TYPE_STRING:
|
|
713 {
|
|
714 Lisp_Object string = Vcurrent_drag_object;
|
|
715
|
|
716 if (!STRINGP (Vcurrent_drag_object))
|
|
717 {
|
|
718 string = Fprin1_to_string (string, Qnil);
|
|
719 /* Convert to a string */
|
|
720 }
|
|
721
|
|
722 gtk_selection_data_set (data, GDK_SELECTION_TYPE_STRING,
|
|
723 8, XSTRING_DATA (string), XSTRING_LENGTH (string));
|
|
724 }
|
|
725 break;
|
|
726 case TARGET_TYPE_URI_LIST:
|
|
727 break;
|
|
728 default:
|
|
729 break;
|
|
730 }
|
|
731 Vcurrent_drag_object = Qnil;
|
|
732 }
|
|
733
|
|
734 DEFUN ("gtk-start-drag-internal", Fgtk_start_drag_internal, 2, 3, 0, /*
|
|
735 Start a GTK drag from a buffer.
|
|
736 First arg is the event that started the drag,
|
|
737 second arg should be some string, and the third
|
|
738 is the type of the data (this should be a MIME type as a string (ie: text/plain)).
|
|
739 The type defaults to text/plain.
|
|
740 */
|
|
741 (event, data, dtyp))
|
|
742 {
|
|
743 if (EVENTP(event))
|
|
744 {
|
|
745 struct frame *f = decode_gtk_frame (Fselected_frame (Qnil));
|
|
746 GtkWidget *wid = FRAME_GTK_TEXT_WIDGET (f);
|
|
747 struct Lisp_Event *lisp_event = XEVENT(event);
|
|
748 GdkAtom dnd_typ;
|
|
749 GtkTargetList *tl = gtk_target_list_new (dnd_target_table, dnd_n_targets);
|
|
750
|
|
751 /* only drag if this is really a press */
|
|
752 if (EVENT_TYPE(lisp_event) != button_press_event)
|
|
753 return Qnil;
|
|
754
|
|
755 /* get the desired type */
|
|
756 if (!NILP (dtyp) && STRINGP (dtyp))
|
|
757 dnd_typ = gdk_atom_intern (XSTRING_DATA (dtyp), FALSE);
|
|
758
|
1204
|
759 gtk_drag_begin (wid, tl, GDK_ACTION_COPY,
|
|
760 EVENT_BUTTON_BUTTON (lisp_event), NULL);
|
462
|
761
|
|
762 Vcurrent_drag_object = data;
|
|
763
|
|
764 gtk_target_list_unref (tl);
|
|
765 }
|
|
766 return Qnil;
|
|
767 }
|
|
768 #endif
|
|
769
|
|
770 /* Creates the widgets for a frame.
|
|
771 lisp_window_id is a Lisp description of an X window or Xt
|
|
772 widget to parse.
|
|
773
|
|
774 This function does not map the windows. (That is
|
|
775 done by gtk_popup_frame().)
|
|
776 */
|
|
777 static void
|
|
778 gtk_create_widgets (struct frame *f, Lisp_Object lisp_window_id, Lisp_Object parent)
|
|
779 {
|
|
780 const char *name;
|
|
781 GtkWidget *text, *container, *shell;
|
|
782 gboolean embedded_p = !NILP (lisp_window_id);
|
|
783 #ifdef HAVE_MENUBARS
|
|
784 int menubar_visible;
|
|
785 #endif
|
|
786
|
|
787 if (STRINGP (f->name))
|
|
788 TO_EXTERNAL_FORMAT (LISP_STRING, f->name, C_STRING_ALLOCA, name, Qctext);
|
|
789 else
|
|
790 name = "emacs";
|
|
791
|
|
792 FRAME_GTK_TOP_LEVEL_FRAME_P (f) = 1;
|
|
793
|
|
794 if (embedded_p)
|
|
795 {
|
|
796 CHECK_GTK_OBJECT (lisp_window_id);
|
|
797
|
|
798 if (!GTK_IS_CONTAINER (XGTK_OBJECT (lisp_window_id)->object))
|
|
799 {
|
563
|
800 invalid_argument ("Window ID must be a GtkContainer subclass", lisp_window_id);
|
462
|
801 }
|
|
802
|
|
803 shell = gtk_vbox_new (FALSE, 0);
|
|
804
|
|
805 gtk_object_weakref (GTK_OBJECT (shell), cleanup_deleted_frame, f);
|
|
806 gtk_container_add (GTK_CONTAINER (XGTK_OBJECT (lisp_window_id)->object), shell);
|
|
807 }
|
|
808 else
|
|
809 {
|
|
810 #ifdef HAVE_GNOME
|
|
811 shell = GTK_WIDGET (gnome_app_new ("XEmacs", "XEmacs/GNOME"));
|
|
812 #else
|
|
813 shell = GTK_WIDGET (gtk_window_new (GTK_WINDOW_TOPLEVEL));
|
|
814 #endif
|
|
815 }
|
|
816
|
|
817 if (!NILP (parent))
|
|
818 {
|
|
819 /* If this is a transient window, keep the parent info around */
|
|
820 GtkWidget *parentwid = FRAME_GTK_SHELL_WIDGET (XFRAME (parent));
|
|
821 gtk_object_set_data (GTK_OBJECT (shell), TRANSIENT_DATA_IDENTIFIER, parentwid);
|
|
822 gtk_window_set_transient_for (GTK_WINDOW (shell), GTK_WINDOW (parentwid));
|
|
823 }
|
|
824
|
|
825 gtk_container_set_border_width (GTK_CONTAINER (shell), 0);
|
|
826
|
|
827 gtk_object_set_data (GTK_OBJECT (shell), FRAME_DATA_IDENTIFIER, f);
|
|
828
|
|
829 FRAME_GTK_SHELL_WIDGET (f) = shell;
|
|
830
|
|
831 text = GTK_WIDGET (gtk_xemacs_new (f));
|
|
832
|
|
833 if (!GNOME_IS_APP (shell))
|
|
834 container = GTK_WIDGET (gtk_vbox_new (FALSE, INTERNAL_BORDER_WIDTH));
|
|
835 else
|
|
836 container = shell;
|
|
837
|
|
838 FRAME_GTK_CONTAINER_WIDGET (f) = container;
|
|
839 FRAME_GTK_TEXT_WIDGET (f) = text;
|
|
840
|
|
841 #ifdef HAVE_DRAGNDROP
|
|
842 gtk_drag_dest_set (text, GTK_DEST_DEFAULT_MOTION | GTK_DEST_DEFAULT_HIGHLIGHT,
|
|
843 dnd_target_table, dnd_n_targets,
|
|
844 GDK_ACTION_COPY | GDK_ACTION_LINK | GDK_ACTION_ASK);
|
|
845 gtk_signal_connect (GTK_OBJECT (text), "drag_drop",
|
|
846 GTK_SIGNAL_FUNC (dragndrop_dropped), text);
|
|
847 gtk_signal_connect (GTK_OBJECT (text), "drag_data_received",
|
|
848 GTK_SIGNAL_FUNC (dragndrop_data_received), text);
|
|
849 gtk_signal_connect (GTK_OBJECT (text), "drag_data_get",
|
|
850 GTK_SIGNAL_FUNC (dragndrop_get_drag), NULL);
|
|
851 #endif
|
|
852
|
|
853 #ifdef HAVE_MENUBARS
|
|
854 /* Create the initial menubar widget. */
|
|
855 menubar_visible = gtk_initialize_frame_menubar (f);
|
|
856
|
|
857 if (menubar_visible)
|
|
858 {
|
|
859 gtk_widget_show_all (FRAME_GTK_MENUBAR_WIDGET (f));
|
|
860 }
|
|
861 #endif /* HAVE_MENUBARS */
|
|
862
|
|
863 if (GNOME_IS_APP (shell))
|
|
864 gnome_app_set_contents (GNOME_APP (shell), text);
|
|
865 else
|
|
866 /* Now comes the drawing area, which should fill the rest of the
|
|
867 ** frame completely.
|
|
868 */
|
|
869 gtk_box_pack_end (GTK_BOX (container), text, TRUE, TRUE, 0);
|
|
870
|
|
871 /* Connect main event handler */
|
|
872 gtk_signal_connect (GTK_OBJECT (shell), "delete-event", GTK_SIGNAL_FUNC (delete_event_cb), f);
|
|
873
|
|
874 {
|
|
875 static char *events_to_frob[] = { "focus-in-event",
|
|
876 "focus-out-event",
|
|
877 "enter-notify-event",
|
|
878 "leave-notify-event",
|
|
879 "map-event",
|
|
880 "unmap-event",
|
|
881 "property-notify-event",
|
|
882 "selection-clear-event",
|
|
883 "selection-request-event",
|
|
884 "selection-notify-event",
|
|
885 "client-event",
|
|
886 /* "configure-event", */
|
|
887 "visibility-notify-event",
|
|
888 NULL };
|
|
889 int i;
|
|
890
|
|
891 for (i = 0; events_to_frob[i]; i++)
|
|
892 {
|
|
893 gtk_signal_connect (GTK_OBJECT (shell), events_to_frob[i],
|
|
894 GTK_SIGNAL_FUNC (emacs_shell_event_handler), f);
|
|
895 }
|
|
896 }
|
|
897
|
|
898 gtk_signal_connect (GTK_OBJECT (shell), "size-allocate", GTK_SIGNAL_FUNC (resize_event_cb), f);
|
|
899
|
|
900 /* This might be safe to call now... */
|
|
901 /* gtk_signal_connect (GTK_OBJECT (shell), "event", GTK_SIGNAL_FUNC (emacs_shell_event_handler), f); */
|
|
902
|
|
903 /* Let's make sure we get all the events we can */
|
|
904 gtk_widget_set_events (text, GDK_ALL_EVENTS_MASK);
|
|
905
|
|
906 if (shell != container)
|
|
907 gtk_container_add (GTK_CONTAINER (shell), container);
|
|
908
|
|
909 gtk_widget_set_name (shell, "XEmacs::shell");
|
|
910 gtk_widget_set_name (container, "XEmacs::container");
|
|
911 gtk_widget_set_name (text, "XEmacs::text");
|
|
912
|
|
913 FRAME_GTK_LISP_WIDGETS(f)[0] = build_gtk_object (GTK_OBJECT (shell));
|
|
914 FRAME_GTK_LISP_WIDGETS(f)[1] = build_gtk_object (GTK_OBJECT (container));
|
|
915 FRAME_GTK_LISP_WIDGETS(f)[2] = build_gtk_object (GTK_OBJECT (text));
|
|
916
|
|
917 gtk_widget_realize (shell);
|
|
918 }
|
|
919
|
|
920 /* create the windows for the specified frame and display them.
|
|
921 Note that the widgets have already been created, and any
|
|
922 necessary geometry calculations have already been done. */
|
|
923 static void
|
|
924 gtk_popup_frame (struct frame *f)
|
|
925 {
|
|
926 /* */
|
|
927
|
|
928 if (gtk_object_get_data (GTK_OBJECT (FRAME_GTK_SHELL_WIDGET (f)), UNMAPPED_DATA_IDENTIFIER))
|
|
929 {
|
|
930 FRAME_GTK_TOTALLY_VISIBLE_P (f) = 0;
|
|
931 f->visible = 0;
|
|
932 gtk_widget_realize (FRAME_GTK_SHELL_WIDGET (f));
|
|
933 gtk_widget_realize (FRAME_GTK_TEXT_WIDGET (f));
|
|
934 gtk_widget_hide_all (FRAME_GTK_SHELL_WIDGET (f));
|
|
935 }
|
|
936 else
|
|
937 {
|
|
938 gtk_widget_show_all (FRAME_GTK_SHELL_WIDGET (f));
|
|
939 }
|
|
940 }
|
|
941
|
|
942 static void
|
|
943 allocate_gtk_frame_struct (struct frame *f)
|
|
944 {
|
1346
|
945 int i;
|
|
946
|
462
|
947 /* zero out all slots. */
|
|
948 f->frame_data = xnew_and_zero (struct gtk_frame);
|
|
949
|
|
950 /* yeah, except the lisp ones */
|
|
951 FRAME_GTK_ICON_PIXMAP (f) = Qnil;
|
|
952 FRAME_GTK_ICON_PIXMAP_MASK (f) = Qnil;
|
1346
|
953 FRAME_GTK_MENUBAR_DATA (f) = Qnil;
|
|
954 for (i = 0; i < 3; i++)
|
|
955 FRAME_GTK_LISP_WIDGETS (f)[i] = Qnil;
|
462
|
956 }
|
|
957
|
|
958
|
|
959 /************************************************************************/
|
|
960 /* Lisp functions */
|
|
961 /************************************************************************/
|
|
962
|
|
963 static void
|
771
|
964 gtk_init_frame_1 (struct frame *f, Lisp_Object props,
|
|
965 int frame_name_is_defaulted)
|
462
|
966 {
|
|
967 /* This function can GC */
|
|
968 Lisp_Object initially_unmapped;
|
|
969 Lisp_Object device = FRAME_DEVICE (f);
|
|
970 Lisp_Object lisp_window_id = Fplist_get (props, Qwindow_id, Qnil);
|
|
971 Lisp_Object popup = Fplist_get (props, Qpopup, Qnil);
|
|
972
|
|
973 if (!NILP (popup))
|
|
974 {
|
|
975 if (EQ (popup, Qt))
|
|
976 popup = Fselected_frame (device);
|
|
977 CHECK_LIVE_FRAME (popup);
|
|
978 if (!EQ (device, FRAME_DEVICE (XFRAME (popup))))
|
563
|
979 invalid_argument_2 ("Parent must be on same device as frame",
|
|
980 device, popup);
|
462
|
981 }
|
|
982
|
|
983 initially_unmapped = Fplist_get (props, Qinitially_unmapped, Qnil);
|
|
984
|
|
985 /*
|
|
986 * Previously we set this only if NILP (DEVICE_SELECTED_FRAME (d))
|
|
987 * to make sure that messages were displayed as soon as possible
|
|
988 * if we're creating the first frame on a device. But it is
|
|
989 * better to just set this all the time, so that when a new frame
|
|
990 * is created that covers the selected frame, echo area status
|
|
991 * messages can still be seen. f->visible is reset later if the
|
|
992 * initially-unmapped property is found to be non-nil in the
|
|
993 * frame properties.
|
|
994 */
|
|
995 f->visible = 1;
|
|
996
|
|
997 allocate_gtk_frame_struct (f);
|
|
998 gtk_create_widgets (f, lisp_window_id, popup);
|
|
999
|
|
1000 if (!NILP (initially_unmapped))
|
|
1001 {
|
|
1002 gtk_object_set_data (GTK_OBJECT (FRAME_GTK_SHELL_WIDGET (f)),
|
|
1003 UNMAPPED_DATA_IDENTIFIER, (gpointer) 1);
|
|
1004 }
|
|
1005 }
|
|
1006
|
|
1007 static void
|
|
1008 gtk_init_frame_2 (struct frame *f, Lisp_Object props)
|
|
1009 {
|
|
1010 /* Set up the values of the widget/frame. A case could be made for putting
|
|
1011 this inside of the widget's initialize method. */
|
|
1012
|
|
1013 update_frame_face_values (f);
|
|
1014 gtk_initialize_frame_size (f);
|
|
1015 /* Kyle:
|
|
1016 * update_frame_title() can't be done here, because some of the
|
|
1017 * modeline specs depend on the frame's device having a selected
|
|
1018 * frame, and that may not have been set up yet. The redisplay
|
|
1019 * will update the frame title anyway, so nothing is lost.
|
|
1020 * JV:
|
|
1021 * It turns out it gives problems with FVWMs name based mapping.
|
|
1022 * We'll just need to be carefull in the modeline specs.
|
|
1023 */
|
|
1024 update_frame_title (f);
|
|
1025 }
|
|
1026
|
|
1027 static void
|
|
1028 gtk_init_frame_3 (struct frame *f)
|
|
1029 {
|
|
1030 /* Pop up the frame. */
|
|
1031 gtk_popup_frame (f);
|
|
1032 }
|
|
1033
|
|
1034 static void
|
|
1035 gtk_mark_frame (struct frame *f)
|
|
1036 {
|
|
1037 mark_object (FRAME_GTK_ICON_PIXMAP (f));
|
|
1038 mark_object (FRAME_GTK_ICON_PIXMAP_MASK (f));
|
1346
|
1039 mark_object (FRAME_GTK_MENUBAR_DATA (f));
|
462
|
1040 mark_object (FRAME_GTK_LISP_WIDGETS (f)[0]);
|
|
1041 mark_object (FRAME_GTK_LISP_WIDGETS (f)[1]);
|
|
1042 mark_object (FRAME_GTK_LISP_WIDGETS (f)[2]);
|
|
1043 }
|
|
1044
|
|
1045 static void
|
|
1046 gtk_set_frame_icon (struct frame *f)
|
|
1047 {
|
|
1048 GdkPixmap *gtk_pixmap = NULL, *gtk_mask = NULL;
|
|
1049
|
|
1050 if (IMAGE_INSTANCEP (f->icon)
|
|
1051 && IMAGE_INSTANCE_PIXMAP_TYPE_P (XIMAGE_INSTANCE (f->icon)))
|
|
1052 {
|
|
1053 gtk_pixmap = XIMAGE_INSTANCE_GTK_PIXMAP (f->icon);
|
|
1054 gtk_mask = XIMAGE_INSTANCE_GTK_MASK (f->icon);
|
|
1055 }
|
|
1056 else
|
|
1057 {
|
|
1058 gtk_pixmap = 0;
|
|
1059 gtk_mask = 0;
|
|
1060 }
|
|
1061
|
|
1062 gdk_window_set_icon (GET_GTK_WIDGET_WINDOW (FRAME_GTK_SHELL_WIDGET (f)), NULL, gtk_pixmap, gtk_mask);
|
|
1063 }
|
|
1064
|
|
1065 static void
|
|
1066 gtk_set_frame_pointer (struct frame *f)
|
|
1067 {
|
|
1068 GtkWidget *w = FRAME_GTK_TEXT_WIDGET (f);
|
|
1069 GdkCursor *c = XIMAGE_INSTANCE_GTK_CURSOR (f->pointer);
|
|
1070
|
|
1071 if (POINTER_IMAGE_INSTANCEP (f->pointer))
|
|
1072 {
|
|
1073 gdk_window_set_cursor (GET_GTK_WIDGET_WINDOW (w), c);
|
|
1074 gdk_flush ();
|
|
1075 }
|
|
1076 else
|
|
1077 {
|
|
1078 /* abort()? */
|
|
1079 stderr_out ("POINTER_IMAGE_INSTANCEP (f->pointer) failed!\n");
|
|
1080 }
|
|
1081 }
|
|
1082
|
|
1083 static Lisp_Object
|
|
1084 gtk_get_frame_parent (struct frame *f)
|
|
1085 {
|
2054
|
1086 GtkWidget *parentwid = (GtkWidget*) gtk_object_get_data (GTK_OBJECT (FRAME_GTK_SHELL_WIDGET (f)),
|
|
1087 TRANSIENT_DATA_IDENTIFIER);
|
462
|
1088
|
|
1089 /* find the frame whose wid is parentwid */
|
|
1090 if (parentwid)
|
|
1091 {
|
|
1092 Lisp_Object frmcons;
|
|
1093 DEVICE_FRAME_LOOP (frmcons, XDEVICE (FRAME_DEVICE (f)))
|
|
1094 {
|
|
1095 Lisp_Object frame = XCAR (frmcons);
|
|
1096 if (FRAME_GTK_SHELL_WIDGET (XFRAME (frame)) == parentwid)
|
|
1097 return frame;
|
|
1098 }
|
|
1099 }
|
|
1100 return Qnil;
|
|
1101 }
|
|
1102
|
|
1103 #ifdef STUPID_X_SPECIFIC_GTK_STUFF
|
|
1104 DEFUN ("gtk-window-id", Fgtk_window_id, 0, 1, 0, /*
|
|
1105 Get the ID of the Gtk window.
|
|
1106 This gives us a chance to manipulate the Emacs window from within a
|
|
1107 different program. Since the ID is an unsigned long, we return it as
|
|
1108 a string.
|
|
1109 */
|
|
1110 (frame))
|
|
1111 {
|
|
1112 char str[255];
|
|
1113 struct frame *f = decode_gtk_frame (frame);
|
|
1114
|
|
1115 /* Arrrrggghhh... this defeats the whole purpose of using Gdk... do we really need this? */
|
|
1116 sprintf (str, "%lu", GDK_WINDOW_XWINDOW( GET_GTK_WIDGET_WINDOW (FRAME_GTK_TEXT_WIDGET (f))));
|
|
1117 return build_string (str);
|
|
1118 }
|
|
1119 #endif
|
|
1120
|
|
1121
|
|
1122 /************************************************************************/
|
|
1123 /* manipulating the X window */
|
|
1124 /************************************************************************/
|
|
1125
|
|
1126 static void
|
|
1127 gtk_set_frame_position (struct frame *f, int xoff, int yoff)
|
|
1128 {
|
|
1129 gtk_widget_set_uposition (FRAME_GTK_SHELL_WIDGET (f), xoff, yoff);
|
|
1130 }
|
|
1131
|
|
1132 /* Call this to change the size of frame S's x-window. */
|
|
1133
|
|
1134 static void
|
|
1135 gtk_set_frame_size (struct frame *f, int cols, int rows)
|
|
1136 {
|
|
1137 GtkWidget *shell = FRAME_GTK_SHELL_WIDGET (f);
|
|
1138 GdkGeometry geometry;
|
|
1139
|
|
1140 if (GTK_IS_WINDOW (shell))
|
|
1141 {
|
2054
|
1142 GdkWindowHints geometry_mask = GDK_HINT_RESIZE_INC;
|
|
1143
|
462
|
1144 /* Update the cell size */
|
771
|
1145 default_face_height_and_width (wrap_frame (f), &geometry.height_inc, &geometry.width_inc);
|
462
|
1146
|
|
1147 gtk_window_set_geometry_hints (GTK_WINDOW (shell),
|
|
1148 FRAME_GTK_TEXT_WIDGET (f), &geometry, geometry_mask);
|
|
1149 }
|
|
1150
|
|
1151 change_frame_size (f, rows, cols, 0);
|
|
1152
|
|
1153 {
|
|
1154 GtkRequisition req;
|
|
1155
|
|
1156 gtk_widget_size_request (FRAME_GTK_SHELL_WIDGET (f), &req);
|
|
1157 gtk_widget_set_usize (FRAME_GTK_SHELL_WIDGET (f), req.width, req.height);
|
|
1158 }
|
|
1159 }
|
|
1160
|
|
1161 #ifdef STUPID_X_SPECIFIC_GTK_STUFF
|
|
1162 /* There is NO equivalent to XWarpPointer under Gtk */
|
|
1163 static void
|
|
1164 gtk_set_mouse_position (struct window *w, int x, int y)
|
|
1165 {
|
|
1166 struct frame *f = XFRAME (w->frame);
|
|
1167 Display *display = GDK_DISPLAY ();
|
|
1168 XWarpPointer (display, None,
|
|
1169 GDK_WINDOW_XWINDOW (GET_GTK_WIDGET_WINDOW (FRAME_GTK_TEXT_WIDGET (f))),
|
|
1170 0, 0, 0, 0, w->pixel_left + x, w->pixel_top + y);
|
|
1171 }
|
|
1172 #endif /* STUPID_X_SPECIFIC_GTK_STUFF */
|
|
1173
|
|
1174 static int
|
|
1175 gtk_get_mouse_position (struct device *d, Lisp_Object *frame, int *x, int *y)
|
|
1176 {
|
|
1177 /* Returns the pixel position within the editor text widget */
|
|
1178 gint win_x, win_y;
|
|
1179 GdkWindow *w = gdk_window_at_pointer (&win_x, &win_y);
|
|
1180 struct frame *f = NULL;
|
|
1181
|
|
1182 if (!w) return (0);
|
|
1183
|
|
1184 /* At this point, w is the innermost GdkWindow containing the
|
|
1185 ** pointer and win_x and win_y are the coordinates of that window.
|
|
1186 */
|
|
1187 f = gtk_any_window_to_frame (d, w);
|
|
1188
|
|
1189 if (!f) return (0);
|
|
1190
|
793
|
1191 *frame = wrap_frame (f);
|
462
|
1192
|
|
1193 gdk_window_get_pointer (GET_GTK_WIDGET_WINDOW (FRAME_GTK_TEXT_WIDGET (f)),
|
|
1194 &win_x, &win_y, NULL);
|
|
1195
|
|
1196 *x = win_x;
|
|
1197 *y = win_y;
|
|
1198
|
|
1199 return (1);
|
|
1200 }
|
|
1201
|
|
1202 static void
|
|
1203 gtk_cant_notify_wm_error (void)
|
|
1204 {
|
563
|
1205 signal_error (Qgui_error, "Can't notify window manager of iconification", Qunbound);
|
462
|
1206 }
|
|
1207
|
|
1208 /* Raise frame F. */
|
|
1209 static void
|
|
1210 gtk_raise_frame_1 (struct frame *f, int force)
|
|
1211 {
|
|
1212 if (FRAME_VISIBLE_P (f) || force)
|
|
1213 {
|
|
1214 GdkWindow *emacs_window = GET_GTK_WIDGET_WINDOW (FRAME_GTK_SHELL_WIDGET (f));
|
|
1215
|
|
1216 gdk_window_raise (emacs_window);
|
|
1217 }
|
|
1218 }
|
|
1219
|
|
1220 static void
|
|
1221 gtk_raise_frame (struct frame *f)
|
|
1222 {
|
|
1223 gtk_raise_frame_1 (f, 1);
|
|
1224 }
|
|
1225
|
|
1226 /* Lower frame F. */
|
|
1227 static void
|
|
1228 gtk_lower_frame (struct frame *f)
|
|
1229 {
|
|
1230 if (FRAME_VISIBLE_P (f))
|
|
1231 {
|
|
1232 gdk_window_lower (GET_GTK_WIDGET_WINDOW (FRAME_GTK_SHELL_WIDGET (f)));
|
|
1233 }
|
|
1234 }
|
|
1235
|
|
1236 /* Change from withdrawn state to mapped state. */
|
|
1237 static void
|
|
1238 gtk_make_frame_visible (struct frame *f)
|
|
1239 {
|
|
1240 gtk_widget_show_all (FRAME_GTK_SHELL_WIDGET (f));
|
|
1241 gtk_raise_frame_1 (f, 0);
|
|
1242 }
|
|
1243
|
|
1244 /* Change from mapped state to withdrawn state. */
|
|
1245 static void
|
|
1246 gtk_make_frame_invisible (struct frame *f)
|
|
1247 {
|
|
1248 gtk_widget_hide (FRAME_GTK_SHELL_WIDGET (f));
|
|
1249 }
|
|
1250
|
|
1251 static int
|
|
1252 gtk_frame_visible_p (struct frame *f)
|
|
1253 {
|
|
1254 GtkWidget *w = FRAME_GTK_SHELL_WIDGET (f);
|
|
1255
|
|
1256 f->visible = (GTK_OBJECT_FLAGS (w) & GTK_VISIBLE);
|
|
1257
|
|
1258 return f->visible;
|
|
1259 }
|
|
1260
|
|
1261 static int
|
|
1262 gtk_frame_totally_visible_p (struct frame *f)
|
|
1263 {
|
|
1264 return FRAME_GTK_TOTALLY_VISIBLE_P (f);
|
|
1265 }
|
|
1266
|
|
1267 /* Change window state from mapped to iconified. */
|
|
1268 static void
|
|
1269 gtk_iconify_frame (struct frame *f)
|
|
1270 {
|
|
1271 GdkWindow *w = GET_GTK_WIDGET_WINDOW (FRAME_GTK_SHELL_WIDGET (f));
|
|
1272
|
|
1273 /* There is no equivalent to XIconifyWindow in Gtk/Gdk. */
|
|
1274 if (!XIconifyWindow (GDK_WINDOW_XDISPLAY (w),
|
|
1275 GDK_WINDOW_XWINDOW (w),
|
|
1276 DefaultScreen (GDK_WINDOW_XDISPLAY (w))))
|
|
1277 gtk_cant_notify_wm_error ();
|
|
1278
|
|
1279 f->iconified = 1;
|
|
1280 }
|
|
1281
|
|
1282 /* Sets the X focus to frame f. */
|
|
1283 static void
|
|
1284 gtk_focus_on_frame (struct frame *f)
|
|
1285 {
|
|
1286 GtkWidget *shell_widget;
|
|
1287
|
|
1288 assert (FRAME_GTK_P (f));
|
|
1289
|
|
1290 shell_widget = FRAME_GTK_SHELL_WIDGET (f);
|
|
1291 if (!GET_GTK_WIDGET_WINDOW (shell_widget))
|
|
1292 return;
|
|
1293
|
|
1294 gtk_widget_grab_focus (shell_widget);
|
|
1295 }
|
|
1296
|
|
1297 /* Destroy the window of frame S. */
|
|
1298 static void
|
|
1299 gtk_delete_frame (struct frame *f)
|
|
1300 {
|
|
1301 GtkWidget *w = FRAME_GTK_SHELL_WIDGET (f);
|
|
1302
|
|
1303 gtk_widget_destroy (w);
|
|
1304
|
|
1305 if (FRAME_GTK_GEOM_FREE_ME_PLEASE (f))
|
1726
|
1306 xfree (FRAME_GTK_GEOM_FREE_ME_PLEASE (f), char *);
|
|
1307 xfree (f->frame_data, void *);
|
462
|
1308 f->frame_data = 0;
|
|
1309 }
|
|
1310
|
|
1311 static void
|
|
1312 gtk_recompute_cell_sizes (struct frame *frm)
|
|
1313 {
|
|
1314 if (GTK_IS_WINDOW (FRAME_GTK_SHELL_WIDGET (frm)))
|
|
1315 {
|
|
1316 GtkWindow *w = GTK_WINDOW (FRAME_GTK_SHELL_WIDGET (frm));
|
|
1317 GdkGeometry geometry;
|
|
1318 GdkWindowHints geometry_mask;
|
|
1319 gint width_inc = 10;
|
|
1320 gint height_inc = 10;
|
|
1321
|
771
|
1322 default_face_height_and_width (wrap_frame (frm), &height_inc, &width_inc);
|
462
|
1323 geometry_mask = GDK_HINT_RESIZE_INC;
|
|
1324 geometry.width_inc = width_inc;
|
|
1325 geometry.height_inc = height_inc;
|
|
1326
|
|
1327 gtk_window_set_geometry_hints (w, FRAME_GTK_TEXT_WIDGET (frm), &geometry, geometry_mask);
|
|
1328 }
|
|
1329 }
|
|
1330
|
|
1331 static void
|
|
1332 gtk_update_frame_external_traits (struct frame* frm, Lisp_Object name)
|
|
1333 {
|
|
1334 Lisp_Object frame = Qnil;
|
|
1335
|
793
|
1336 frame = wrap_frame (frm);
|
462
|
1337
|
|
1338 if (EQ (name, Qforeground))
|
|
1339 {
|
|
1340 Lisp_Object color = FACE_FOREGROUND (Vdefault_face, frame);
|
|
1341 GdkColor *fgc;
|
|
1342
|
|
1343 if (!EQ (color, Vthe_null_color_instance))
|
|
1344 {
|
|
1345 fgc = COLOR_INSTANCE_GTK_COLOR (XCOLOR_INSTANCE (color));
|
|
1346 /* #### BILL!!! The X code set the XtNforeground property of
|
|
1347 the text widget here. Why did they bother? All that type
|
|
1348 of thing is done down in the guts of the redisplay code,
|
|
1349 not in the Emacs* widgets. */
|
|
1350 }
|
|
1351 }
|
|
1352 else if (EQ (name, Qbackground))
|
|
1353 {
|
|
1354 Lisp_Object color = FACE_BACKGROUND (Vdefault_face, frame);
|
|
1355 GdkColor *bgc;
|
|
1356
|
|
1357 if (!EQ (color, Vthe_null_color_instance))
|
|
1358 {
|
|
1359 bgc = COLOR_INSTANCE_GTK_COLOR (XCOLOR_INSTANCE (color));
|
|
1360 if (FRAME_GTK_SHELL_WIDGET (frm)->window)
|
|
1361 {
|
|
1362 gdk_window_set_background (FRAME_GTK_SHELL_WIDGET (frm)->window, bgc);
|
|
1363 }
|
|
1364 if (FRAME_GTK_TEXT_WIDGET (frm)->window)
|
|
1365 {
|
|
1366 gdk_window_set_background (FRAME_GTK_TEXT_WIDGET (frm)->window, bgc);
|
|
1367 }
|
|
1368 }
|
|
1369
|
|
1370 /* Really crappy way to force the modeline shadows to be
|
|
1371 redrawn. But effective. */
|
|
1372 MARK_FRAME_WINDOWS_STRUCTURE_CHANGED (frm);
|
|
1373 MARK_FRAME_CHANGED (frm);
|
|
1374 }
|
|
1375 else if (EQ (name, Qfont))
|
|
1376 {
|
|
1377 Lisp_Object font = FACE_FONT (Vdefault_face, frame, Vcharset_ascii);
|
|
1378
|
|
1379 if (!EQ (font, Vthe_null_font_instance))
|
|
1380 {
|
|
1381 /* #### BILL!!! The X code set the XtNfont property of the
|
|
1382 text widget here. Why did they bother? All that type of
|
|
1383 thing is done down in the guts of the redisplay code, not
|
|
1384 in the Emacs* widgets. */
|
|
1385 }
|
|
1386 }
|
|
1387 else
|
|
1388 abort ();
|
|
1389
|
|
1390 #ifdef HAVE_TOOLBARS
|
|
1391 /* Setting the background clears the entire frame area
|
|
1392 including the toolbar so we force an immediate redraw of
|
|
1393 it. */
|
|
1394 if (EQ (name, Qbackground))
|
|
1395 MAYBE_DEVMETH (XDEVICE (frm->device), redraw_frame_toolbars, (frm));
|
|
1396 #endif /* HAVE_TOOLBARS */
|
|
1397
|
|
1398 /* Set window manager resize increment hints according to
|
|
1399 the new character size */
|
|
1400 if (EQ (name, Qfont) && FRAME_GTK_TOP_LEVEL_FRAME_P (frm))
|
|
1401 gtk_recompute_cell_sizes (frm);
|
|
1402 }
|
|
1403
|
|
1404
|
|
1405 /************************************************************************/
|
|
1406 /* initialization */
|
|
1407 /************************************************************************/
|
|
1408
|
|
1409 void
|
|
1410 syms_of_frame_gtk (void)
|
|
1411 {
|
563
|
1412 DEFSYMBOL (Qtext_widget);
|
|
1413 DEFSYMBOL (Qcontainer_widget);
|
|
1414 DEFSYMBOL (Qshell_widget);
|
|
1415 DEFSYMBOL (Qdetachable_menubar);
|
462
|
1416
|
|
1417 #ifdef HAVE_DRAGNDROP
|
|
1418 staticpro (&Vcurrent_drag_object);
|
|
1419 Vcurrent_drag_object = Qnil;
|
|
1420 DEFSUBR (Fgtk_start_drag_internal);
|
|
1421 #endif
|
|
1422 #ifdef STUPID_X_SPECIFIC_GTK_STUFF
|
|
1423 DEFSUBR (Fgtk_window_id);
|
|
1424 #endif
|
|
1425 }
|
|
1426
|
|
1427 void
|
|
1428 console_type_create_frame_gtk (void)
|
|
1429 {
|
|
1430 /* frame methods */
|
|
1431 CONSOLE_HAS_METHOD (gtk, init_frame_1);
|
|
1432 CONSOLE_HAS_METHOD (gtk, init_frame_2);
|
|
1433 CONSOLE_HAS_METHOD (gtk, init_frame_3);
|
|
1434 CONSOLE_HAS_METHOD (gtk, mark_frame);
|
|
1435 CONSOLE_HAS_METHOD (gtk, focus_on_frame);
|
|
1436 CONSOLE_HAS_METHOD (gtk, delete_frame);
|
|
1437 CONSOLE_HAS_METHOD (gtk, get_mouse_position);
|
|
1438 #ifdef STUPID_X_SPECIFIC_GTK_STUFF
|
|
1439 CONSOLE_HAS_METHOD (gtk, set_mouse_position);
|
|
1440 #endif
|
|
1441 CONSOLE_HAS_METHOD (gtk, raise_frame);
|
|
1442 CONSOLE_HAS_METHOD (gtk, lower_frame);
|
|
1443 CONSOLE_HAS_METHOD (gtk, make_frame_visible);
|
|
1444 CONSOLE_HAS_METHOD (gtk, make_frame_invisible);
|
|
1445 CONSOLE_HAS_METHOD (gtk, iconify_frame);
|
|
1446 CONSOLE_HAS_METHOD (gtk, set_frame_size);
|
|
1447 CONSOLE_HAS_METHOD (gtk, set_frame_position);
|
|
1448 CONSOLE_HAS_METHOD (gtk, frame_property);
|
|
1449 CONSOLE_HAS_METHOD (gtk, internal_frame_property_p);
|
|
1450 CONSOLE_HAS_METHOD (gtk, frame_properties);
|
|
1451 CONSOLE_HAS_METHOD (gtk, set_frame_properties);
|
867
|
1452 CONSOLE_HAS_METHOD (gtk, set_title_from_ibyte);
|
|
1453 CONSOLE_HAS_METHOD (gtk, set_icon_name_from_ibyte);
|
462
|
1454 CONSOLE_HAS_METHOD (gtk, frame_visible_p);
|
|
1455 CONSOLE_HAS_METHOD (gtk, frame_totally_visible_p);
|
|
1456 CONSOLE_HAS_METHOD (gtk, frame_iconified_p);
|
|
1457 CONSOLE_HAS_METHOD (gtk, set_frame_pointer);
|
|
1458 CONSOLE_HAS_METHOD (gtk, set_frame_icon);
|
|
1459 CONSOLE_HAS_METHOD (gtk, get_frame_parent);
|
|
1460 CONSOLE_HAS_METHOD (gtk, update_frame_external_traits);
|
|
1461 }
|
|
1462
|
|
1463 void
|
|
1464 vars_of_frame_gtk (void)
|
|
1465 {
|
|
1466 DEFVAR_LISP ("default-gtk-frame-plist", &Vdefault_gtk_frame_plist /*
|
|
1467 Plist of default frame-creation properties for Gtk frames.
|
|
1468 These override what is specified in the resource database and in
|
|
1469 `default-frame-plist', but are overridden by the arguments to the
|
|
1470 particular call to `make-frame'.
|
|
1471
|
|
1472 Note: In many cases, properties of a frame are available as specifiers
|
|
1473 instead of through the frame-properties mechanism.
|
|
1474
|
|
1475 Here is a list of recognized frame properties, other than those
|
|
1476 documented in `set-frame-properties' (they can be queried and
|
|
1477 set at any time, except as otherwise noted):
|
|
1478
|
|
1479 initially-unmapped If non-nil, the frame will not be visible
|
|
1480 when it is created. In this case, you
|
|
1481 need to call `make-frame-visible' to make
|
|
1482 the frame appear.
|
|
1483 popup If non-nil, it should be a frame, and this
|
|
1484 frame will be created as a "popup" frame
|
|
1485 whose parent is the given frame. This
|
|
1486 will make the window manager treat the
|
|
1487 frame as a dialog box, which may entail
|
|
1488 doing different things (e.g. not asking
|
|
1489 for positioning, and not iconifying
|
|
1490 separate from its parent).
|
|
1491 inter-line-space Not currently implemented.
|
|
1492 toolbar-shadow-thickness Thickness of toolbar shadows.
|
|
1493 background-toolbar-color Color of toolbar background.
|
|
1494 bottom-toolbar-shadow-color Color of bottom shadows on toolbars.
|
|
1495 (*Not* specific to the bottom-toolbar.)
|
|
1496 top-toolbar-shadow-color Color of top shadows on toolbars.
|
|
1497 (*Not* specific to the top-toolbar.)
|
|
1498 internal-border-width Width of internal border around text area.
|
|
1499 border-width Width of external border around text area.
|
|
1500 top Y position (in pixels) of the upper-left
|
|
1501 outermost corner of the frame (i.e. the
|
|
1502 upper-left of the window-manager
|
|
1503 decorations).
|
|
1504 left X position (in pixels) of the upper-left
|
|
1505 outermost corner of the frame (i.e. the
|
|
1506 upper-left of the window-manager
|
|
1507 decorations).
|
|
1508 border-color Color of external border around text area.
|
|
1509 cursor-color Color of text cursor.
|
|
1510
|
|
1511 See also `default-frame-plist', which specifies properties which apply
|
|
1512 to all frames, not just Gtk frames.
|
|
1513 */ );
|
|
1514 Vdefault_gtk_frame_plist = Qnil;
|
|
1515
|
|
1516 gtk_console_methods->device_specific_frame_props = &Vdefault_gtk_frame_plist;
|
|
1517 }
|