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