Mercurial > emacs
annotate src/gtkutil.c @ 55213:a911edb6dadf
(thumbs-delete-images): Fix formatting of prompt.
(thumbs-show-image-num): Move assignment of
`thumbs-current-image-filename' within dynamic scope of `i'.
(thumbs-emboss-image): Don't use `evenp'.
author | John Paul Wallington <jpw@pobox.com> |
---|---|
date | Wed, 28 Apr 2004 16:56:08 +0000 |
parents | a07a0bae1990 |
children | 44d086f5e08a |
rev | line source |
---|---|
49323 | 1 /* Functions for creating and updating GTK widgets. |
2 Copyright (C) 2003 | |
3 Free Software Foundation, Inc. | |
4 | |
5 This file is part of GNU Emacs. | |
6 | |
7 GNU Emacs is free software; you can redistribute it and/or modify | |
8 it under the terms of the GNU General Public License as published by | |
9 the Free Software Foundation; either version 2, or (at your option) | |
10 any later version. | |
11 | |
12 GNU Emacs is distributed in the hope that it will be useful, | |
13 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 GNU General Public License for more details. | |
16 | |
17 You should have received a copy of the GNU General Public License | |
18 along with GNU Emacs; 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 #include "config.h" | |
23 | |
24 #ifdef USE_GTK | |
49359
14cf50ecf91a
gtkutil.c: Must include stdio.h before termhooks.h
Jan Djärv <jan.h.d@swipnet.se>
parents:
49325
diff
changeset
|
25 #include <string.h> |
14cf50ecf91a
gtkutil.c: Must include stdio.h before termhooks.h
Jan Djärv <jan.h.d@swipnet.se>
parents:
49325
diff
changeset
|
26 #include <stdio.h> |
49323 | 27 #include "lisp.h" |
28 #include "xterm.h" | |
29 #include "blockinput.h" | |
30 #include "window.h" | |
31 #include "atimer.h" | |
32 #include "gtkutil.h" | |
33 #include "termhooks.h" | |
51408
8f1bed1dee3c
Include keyboard.h, charset.h, coding.h.
Dave Love <fx@gnu.org>
parents:
51211
diff
changeset
|
34 #include "keyboard.h" |
8f1bed1dee3c
Include keyboard.h, charset.h, coding.h.
Dave Love <fx@gnu.org>
parents:
51211
diff
changeset
|
35 #include "charset.h" |
8f1bed1dee3c
Include keyboard.h, charset.h, coding.h.
Dave Love <fx@gnu.org>
parents:
51211
diff
changeset
|
36 #include "coding.h" |
49323 | 37 #include <gdk/gdkkeysyms.h> |
38 | |
53069
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
39 |
49323 | 40 #define FRAME_TOTAL_PIXEL_HEIGHT(f) \ |
51211
28ea05de2dc5
Make (many) trivial substitutions for renamed and
Kim F. Storm <storm@cua.dk>
parents:
50778
diff
changeset
|
41 (FRAME_PIXEL_HEIGHT (f) + FRAME_MENUBAR_HEIGHT (f) + FRAME_TOOLBAR_HEIGHT (f)) |
50129
d0142038feaa
Reduce flicker in GTK scrollbars.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50112
diff
changeset
|
42 |
53069
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
43 |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
44 /*********************************************************************** |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
45 Display handling functions |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
46 ***********************************************************************/ |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
47 |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
48 #ifdef HAVE_GTK_MULTIDISPLAY |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
49 |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
50 /* Return the GdkDisplay that corresponds to the X display DPY. */ |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
51 static GdkDisplay * |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
52 xg_get_gdk_display (dpy) |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
53 Display *dpy; |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
54 { |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
55 return gdk_x11_lookup_xdisplay (dpy); |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
56 } |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
57 |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
58 /* When the GTK widget W is to be created on a display for F that |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
59 is not the default display, set the display for W. |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
60 W can be a GtkMenu or a GtkWindow widget. */ |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
61 static void |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
62 xg_set_screen (w, f) |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
63 GtkWidget *w; |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
64 FRAME_PTR f; |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
65 { |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
66 if (FRAME_X_DISPLAY (f) != GDK_DISPLAY ()) |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
67 { |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
68 GdkDisplay *gdpy = gdk_x11_lookup_xdisplay (FRAME_X_DISPLAY (f)); |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
69 GdkScreen *gscreen = gdk_display_get_default_screen (gdpy); |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
70 |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
71 if (GTK_IS_MENU (w)) |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
72 gtk_menu_set_screen (GTK_MENU (w), gscreen); |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
73 else |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
74 gtk_window_set_screen (GTK_WINDOW (w), gscreen); |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
75 } |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
76 } |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
77 |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
78 |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
79 #else /* not HAVE_GTK_MULTIDISPLAY */ |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
80 |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
81 /* Make some defines so we can use the GTK 2.2 functions when |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
82 compiling with GTK 2.0. */ |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
83 #define xg_set_screen(w, f) |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
84 #define gdk_xid_table_lookup_for_display(dpy, w) gdk_xid_table_lookup (w) |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
85 #define gdk_pixmap_foreign_new_for_display(dpy, p) gdk_pixmap_foreign_new (p) |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
86 #define gdk_cursor_new_for_display(dpy, c) gdk_cursor_new (c) |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
87 #define gdk_x11_lookup_xdisplay(dpy) 0 |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
88 #define GdkDisplay void |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
89 |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
90 #endif /* not HAVE_GTK_MULTIDISPLAY */ |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
91 |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
92 /* Open a display named by DISPLAY_NAME. The display is returned in *DPY. |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
93 *DPY is set to NULL if the display can't be opened. |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
94 |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
95 Returns non-zero if display could be opened, zero if display could not |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
96 be opened, and less than zero if the GTK version doesn't support |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
97 multipe displays. */ |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
98 int |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
99 xg_display_open (display_name, dpy) |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
100 char *display_name; |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
101 Display **dpy; |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
102 { |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
103 #ifdef HAVE_GTK_MULTIDISPLAY |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
104 GdkDisplay *gdpy; |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
105 |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
106 gdpy = gdk_display_open (display_name); |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
107 *dpy = gdpy ? GDK_DISPLAY_XDISPLAY (gdpy) : NULL; |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
108 |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
109 return gdpy != NULL; |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
110 |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
111 #else /* not HAVE_GTK_MULTIDISPLAY */ |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
112 |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
113 return -1; |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
114 #endif /* not HAVE_GTK_MULTIDISPLAY */ |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
115 } |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
116 |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
117 |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
118 void |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
119 xg_display_close (Display *dpy) |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
120 { |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
121 #ifdef HAVE_GTK_MULTIDISPLAY |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
122 GdkDisplay *gdpy = gdk_x11_lookup_xdisplay (dpy); |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
123 |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
124 /* GTK 2.2 has a bug that makes gdk_display_close crash (bug |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
125 http://bugzilla.gnome.org/show_bug.cgi?id=85715). This way |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
126 we can continue running, but there will be memory leaks. */ |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
127 |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
128 #if GTK_MAJOR_VERSION == 2 && GTK_MINOR_VERSION < 4 |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
129 |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
130 /* If this is the default display, we must change it before calling |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
131 dispose, otherwise it will crash. */ |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
132 if (gdk_display_get_default () == gdpy) |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
133 { |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
134 struct x_display_info *dpyinfo; |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
135 Display *new_dpy = 0; |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
136 GdkDisplay *gdpy_new; |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
137 |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
138 /* Find another display. */ |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
139 for (dpyinfo = x_display_list; dpyinfo; dpyinfo = dpyinfo->next) |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
140 if (dpyinfo->display != dpy) |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
141 { |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
142 new_dpy = dpyinfo->display; |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
143 break; |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
144 } |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
145 |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
146 if (! new_dpy) return; /* Emacs will exit anyway. */ |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
147 |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
148 gdpy_new = gdk_x11_lookup_xdisplay (new_dpy); |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
149 gdk_display_manager_set_default_display (gdk_display_manager_get (), |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
150 gdpy_new); |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
151 } |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
152 |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
153 g_object_run_dispose (G_OBJECT (gdpy)); |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
154 |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
155 #else |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
156 /* I hope this will be fixed in GTK 2.4. It is what bug 85715 says. */ |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
157 gdk_display_close (gdpy); |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
158 #endif |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
159 #endif /* HAVE_GTK_MULTIDISPLAY */ |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
160 } |
50129
d0142038feaa
Reduce flicker in GTK scrollbars.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50112
diff
changeset
|
161 |
49323 | 162 |
163 /*********************************************************************** | |
164 Utility functions | |
165 ***********************************************************************/ | |
166 /* The timer for scroll bar repetition and menu bar timeouts. | |
167 NULL if no timer is started. */ | |
168 static struct atimer *xg_timer; | |
169 | |
170 | |
171 /* The next two variables and functions are taken from lwlib. */ | |
172 static widget_value *widget_value_free_list; | |
173 static int malloc_cpt; | |
174 | |
175 /* Allocate a widget_value structure, either by taking one from the | |
176 widget_value_free_list or by malloc:ing a new one. | |
177 | |
178 Return a pointer to the allocated structure. */ | |
179 widget_value * | |
180 malloc_widget_value () | |
181 { | |
182 widget_value *wv; | |
183 if (widget_value_free_list) | |
184 { | |
185 wv = widget_value_free_list; | |
186 widget_value_free_list = wv->free_list; | |
187 wv->free_list = 0; | |
188 } | |
189 else | |
190 { | |
191 wv = (widget_value *) malloc (sizeof (widget_value)); | |
192 malloc_cpt++; | |
193 } | |
194 memset (wv, 0, sizeof (widget_value)); | |
195 return wv; | |
196 } | |
197 | |
198 /* This is analogous to free. It frees only what was allocated | |
199 by malloc_widget_value, and no substructures. */ | |
200 void | |
201 free_widget_value (wv) | |
202 widget_value *wv; | |
203 { | |
204 if (wv->free_list) | |
205 abort (); | |
206 | |
207 if (malloc_cpt > 25) | |
208 { | |
209 /* When the number of already allocated cells is too big, | |
210 We free it. */ | |
211 free (wv); | |
212 malloc_cpt--; | |
213 } | |
214 else | |
215 { | |
216 wv->free_list = widget_value_free_list; | |
217 widget_value_free_list = wv; | |
218 } | |
219 } | |
220 | |
53069
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
221 |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
222 /* Create and return the cursor to be used for popup menus and |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
223 scroll bars on display DPY. */ |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
224 GdkCursor * |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
225 xg_create_default_cursor (dpy) |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
226 Display *dpy; |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
227 { |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
228 GdkDisplay *gdpy = gdk_x11_lookup_xdisplay (dpy); |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
229 return gdk_cursor_new_for_display (gdpy, GDK_LEFT_PTR); |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
230 } |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
231 |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
232 /* For the image defined in IMG, make and return a GdkPixmap for |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
233 the pixmap in *GPIX, and a GdkBitmap for the mask in *GMASK. |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
234 If IMG has no mask, *GMASK is set to NULL. |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
235 The image is defined on the display where frame F is. */ |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
236 static void |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
237 xg_get_gdk_pixmap_and_mask (f, img, gpix, gmask) |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
238 FRAME_PTR f; |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
239 struct image *img; |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
240 GdkPixmap **gpix; |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
241 GdkBitmap **gmask; |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
242 { |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
243 GdkDisplay *gdpy = gdk_x11_lookup_xdisplay (FRAME_X_DISPLAY (f)); |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
244 |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
245 *gpix = gdk_pixmap_foreign_new_for_display (gdpy, img->pixmap); |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
246 *gmask = img->mask ? |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
247 (GdkBitmap*) gdk_pixmap_foreign_new_for_display (gdpy, img->mask) |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
248 : 0; |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
249 } |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
250 |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
251 |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
252 /* Set CURSOR on W and all widgets W contain. We must do like this |
49323 | 253 for scroll bars and menu because they create widgets internally, |
53069
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
254 and it is those widgets that are visible. */ |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
255 static void |
49323 | 256 xg_set_cursor (w, cursor) |
257 GtkWidget *w; | |
53069
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
258 GdkCursor *cursor; |
49323 | 259 { |
260 GList *children = gdk_window_peek_children (w->window); | |
261 | |
53069
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
262 gdk_window_set_cursor (w->window, cursor); |
49323 | 263 |
264 /* The scroll bar widget has more than one GDK window (had to look at | |
265 the source to figure this out), and there is no way to set cursor | |
266 on widgets in GTK. So we must set the cursor for all GDK windows. | |
267 Ditto for menus. */ | |
268 | |
269 for ( ; children; children = g_list_next (children)) | |
53069
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
270 gdk_window_set_cursor (GDK_WINDOW (children->data), cursor); |
49323 | 271 } |
272 | |
273 /* Timer function called when a timeout occurs for xg_timer. | |
274 This function processes all GTK events in a recursive event loop. | |
275 This is done because GTK timer events are not seen by Emacs event | |
276 detection, Emacs only looks for X events. When a scroll bar has the | |
277 pointer (detected by button press/release events below) an Emacs | |
278 timer is started, and this function can then check if the GTK timer | |
279 has expired by calling the GTK event loop. | |
280 Also, when a menu is active, it has a small timeout before it | |
281 pops down the sub menu under it. */ | |
282 static void | |
283 xg_process_timeouts (timer) | |
284 struct atimer *timer; | |
285 { | |
286 BLOCK_INPUT; | |
287 /* Ideally we would like to just handle timer events, like the Xt version | |
288 of this does in xterm.c, but there is no such feature in GTK. */ | |
289 while (gtk_events_pending ()) | |
290 gtk_main_iteration (); | |
291 UNBLOCK_INPUT; | |
292 } | |
293 | |
294 /* Start the xg_timer with an interval of 0.1 seconds, if not already started. | |
295 xg_process_timeouts is called when the timer expires. The timer | |
50270
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
296 started is continuous, i.e. runs until xg_stop_timer is called. */ |
49323 | 297 static void |
298 xg_start_timer () | |
299 { | |
300 if (! xg_timer) | |
301 { | |
302 EMACS_TIME interval; | |
303 EMACS_SET_SECS_USECS (interval, 0, 100000); | |
304 xg_timer = start_atimer (ATIMER_CONTINUOUS, | |
305 interval, | |
306 xg_process_timeouts, | |
307 0); | |
308 } | |
309 } | |
310 | |
311 /* Stop the xg_timer if started. */ | |
312 static void | |
313 xg_stop_timer () | |
314 { | |
315 if (xg_timer) | |
316 { | |
317 cancel_atimer (xg_timer); | |
318 xg_timer = 0; | |
319 } | |
320 } | |
321 | |
322 /* Insert NODE into linked LIST. */ | |
323 static void | |
324 xg_list_insert (xg_list_node *list, xg_list_node *node) | |
325 { | |
326 xg_list_node *list_start = list->next; | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
327 |
49323 | 328 if (list_start) list_start->prev = node; |
329 node->next = list_start; | |
330 node->prev = 0; | |
331 list->next = node; | |
332 } | |
333 | |
334 /* Remove NODE from linked LIST. */ | |
335 static void | |
336 xg_list_remove (xg_list_node *list, xg_list_node *node) | |
337 { | |
338 xg_list_node *list_start = list->next; | |
339 if (node == list_start) | |
340 { | |
341 list->next = node->next; | |
342 if (list->next) list->next->prev = 0; | |
343 } | |
344 else | |
345 { | |
346 node->prev->next = node->next; | |
347 if (node->next) node->next->prev = node->prev; | |
348 } | |
349 } | |
350 | |
351 /* Allocate and return a utf8 version of STR. If STR is already | |
352 utf8 or NULL, just return STR. | |
353 If not, a new string is allocated and the caller must free the result | |
354 with g_free. */ | |
355 static char * | |
356 get_utf8_string (str) | |
357 char *str; | |
358 { | |
359 char *utf8_str = str; | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
360 |
49323 | 361 /* If not UTF-8, try current locale. */ |
362 if (str && !g_utf8_validate (str, -1, NULL)) | |
363 utf8_str = g_locale_to_utf8 (str, -1, 0, 0, 0); | |
364 | |
365 return utf8_str; | |
366 } | |
367 | |
368 | |
369 | |
370 /*********************************************************************** | |
371 General functions for creating widgets, resizing, events, e.t.c. | |
372 ***********************************************************************/ | |
373 | |
374 /* Make a geometry string and pass that to GTK. It seems this is the | |
375 only way to get geometry position right if the user explicitly | |
376 asked for a position when starting Emacs. | |
377 F is the frame we shall set geometry for. */ | |
378 static void | |
379 xg_set_geometry (f) | |
380 FRAME_PTR f; | |
381 { | |
51211
28ea05de2dc5
Make (many) trivial substitutions for renamed and
Kim F. Storm <storm@cua.dk>
parents:
50778
diff
changeset
|
382 if (f->size_hint_flags & USPosition) |
49323 | 383 { |
51211
28ea05de2dc5
Make (many) trivial substitutions for renamed and
Kim F. Storm <storm@cua.dk>
parents:
50778
diff
changeset
|
384 int left = f->left_pos; |
28ea05de2dc5
Make (many) trivial substitutions for renamed and
Kim F. Storm <storm@cua.dk>
parents:
50778
diff
changeset
|
385 int xneg = f->size_hint_flags & XNegative; |
28ea05de2dc5
Make (many) trivial substitutions for renamed and
Kim F. Storm <storm@cua.dk>
parents:
50778
diff
changeset
|
386 int top = f->top_pos; |
28ea05de2dc5
Make (many) trivial substitutions for renamed and
Kim F. Storm <storm@cua.dk>
parents:
50778
diff
changeset
|
387 int yneg = f->size_hint_flags & YNegative; |
49323 | 388 char geom_str[32]; |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
389 |
49323 | 390 if (xneg) |
391 left = -left; | |
392 if (yneg) | |
393 top = -top; | |
394 | |
395 sprintf (geom_str, "=%dx%d%c%d%c%d", | |
51211
28ea05de2dc5
Make (many) trivial substitutions for renamed and
Kim F. Storm <storm@cua.dk>
parents:
50778
diff
changeset
|
396 FRAME_PIXEL_WIDTH (f), |
49323 | 397 FRAME_TOTAL_PIXEL_HEIGHT (f), |
398 (xneg ? '-' : '+'), left, | |
399 (yneg ? '-' : '+'), top); | |
400 | |
401 if (!gtk_window_parse_geometry (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f)), | |
402 geom_str)) | |
403 fprintf (stderr, "Failed to parse: '%s'\n", geom_str); | |
404 } | |
405 } | |
406 | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
407 |
49323 | 408 /* Resize the outer window of frame F after chainging the height. |
409 This happend when the menu bar or the tool bar is added or removed. | |
410 COLUMNS/ROWS is the size the edit area shall have after the resize. */ | |
411 static void | |
412 xg_resize_outer_widget (f, columns, rows) | |
413 FRAME_PTR f; | |
414 int columns; | |
415 int rows; | |
416 { | |
417 gtk_window_resize (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f)), | |
51211
28ea05de2dc5
Make (many) trivial substitutions for renamed and
Kim F. Storm <storm@cua.dk>
parents:
50778
diff
changeset
|
418 FRAME_PIXEL_WIDTH (f), FRAME_TOTAL_PIXEL_HEIGHT (f)); |
49323 | 419 |
420 /* base_height is now changed. */ | |
421 x_wm_set_size_hint (f, 0, 0); | |
422 | |
423 /* If we are not mapped yet, set geometry once again, as window | |
424 height now have changed. */ | |
425 if (! GTK_WIDGET_MAPPED (FRAME_GTK_OUTER_WIDGET (f))) | |
426 xg_set_geometry (f); | |
427 | |
428 xg_frame_set_char_size (f, columns, rows); | |
429 gdk_window_process_all_updates (); | |
430 } | |
431 | |
50130
66a7f2850b56
Clear frame didn't redraw scrollbars, fixed that.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50129
diff
changeset
|
432 /* This gets called after the frame F has been cleared. Since that is |
66a7f2850b56
Clear frame didn't redraw scrollbars, fixed that.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50129
diff
changeset
|
433 done with X calls, we need to redraw GTK widget (scroll bars). */ |
66a7f2850b56
Clear frame didn't redraw scrollbars, fixed that.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50129
diff
changeset
|
434 void |
66a7f2850b56
Clear frame didn't redraw scrollbars, fixed that.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50129
diff
changeset
|
435 xg_frame_cleared (f) |
66a7f2850b56
Clear frame didn't redraw scrollbars, fixed that.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50129
diff
changeset
|
436 FRAME_PTR f; |
66a7f2850b56
Clear frame didn't redraw scrollbars, fixed that.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50129
diff
changeset
|
437 { |
50192
c8111b6d2b32
* gtkutil.c (xg_frame_cleared): Call gtk_widget_queue_draw for
Jan Djärv <jan.h.d@swipnet.se>
parents:
50178
diff
changeset
|
438 GtkWidget *w = f->output_data.x->widget; |
c8111b6d2b32
* gtkutil.c (xg_frame_cleared): Call gtk_widget_queue_draw for
Jan Djärv <jan.h.d@swipnet.se>
parents:
50178
diff
changeset
|
439 |
c8111b6d2b32
* gtkutil.c (xg_frame_cleared): Call gtk_widget_queue_draw for
Jan Djärv <jan.h.d@swipnet.se>
parents:
50178
diff
changeset
|
440 if (w) |
50130
66a7f2850b56
Clear frame didn't redraw scrollbars, fixed that.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50129
diff
changeset
|
441 { |
50192
c8111b6d2b32
* gtkutil.c (xg_frame_cleared): Call gtk_widget_queue_draw for
Jan Djärv <jan.h.d@swipnet.se>
parents:
50178
diff
changeset
|
442 gtk_container_set_reallocate_redraws (GTK_CONTAINER (w), TRUE); |
c8111b6d2b32
* gtkutil.c (xg_frame_cleared): Call gtk_widget_queue_draw for
Jan Djärv <jan.h.d@swipnet.se>
parents:
50178
diff
changeset
|
443 gtk_container_foreach (GTK_CONTAINER (w), |
c8111b6d2b32
* gtkutil.c (xg_frame_cleared): Call gtk_widget_queue_draw for
Jan Djärv <jan.h.d@swipnet.se>
parents:
50178
diff
changeset
|
444 (GtkCallback) gtk_widget_queue_draw, |
c8111b6d2b32
* gtkutil.c (xg_frame_cleared): Call gtk_widget_queue_draw for
Jan Djärv <jan.h.d@swipnet.se>
parents:
50178
diff
changeset
|
445 0); |
50130
66a7f2850b56
Clear frame didn't redraw scrollbars, fixed that.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50129
diff
changeset
|
446 gdk_window_process_all_updates (); |
66a7f2850b56
Clear frame didn't redraw scrollbars, fixed that.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50129
diff
changeset
|
447 } |
66a7f2850b56
Clear frame didn't redraw scrollbars, fixed that.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50129
diff
changeset
|
448 } |
66a7f2850b56
Clear frame didn't redraw scrollbars, fixed that.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50129
diff
changeset
|
449 |
49323 | 450 /* Function to handle resize of our widgets. Since Emacs has some layouts |
451 that does not fit well with GTK standard containers, we do most layout | |
452 manually. | |
453 F is the frame to resize. | |
454 PIXELWIDTH, PIXELHEIGHT is the new size in pixels. */ | |
455 void | |
456 xg_resize_widgets (f, pixelwidth, pixelheight) | |
457 FRAME_PTR f; | |
458 int pixelwidth, pixelheight; | |
459 { | |
460 int mbheight = FRAME_MENUBAR_HEIGHT (f); | |
461 int tbheight = FRAME_TOOLBAR_HEIGHT (f); | |
51211
28ea05de2dc5
Make (many) trivial substitutions for renamed and
Kim F. Storm <storm@cua.dk>
parents:
50778
diff
changeset
|
462 int rows = FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f, (pixelheight |
28ea05de2dc5
Make (many) trivial substitutions for renamed and
Kim F. Storm <storm@cua.dk>
parents:
50778
diff
changeset
|
463 - mbheight - tbheight)); |
28ea05de2dc5
Make (many) trivial substitutions for renamed and
Kim F. Storm <storm@cua.dk>
parents:
50778
diff
changeset
|
464 int columns = FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f, pixelwidth); |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
465 |
49323 | 466 if (FRAME_GTK_WIDGET (f) |
51211
28ea05de2dc5
Make (many) trivial substitutions for renamed and
Kim F. Storm <storm@cua.dk>
parents:
50778
diff
changeset
|
467 && (columns != FRAME_COLS (f) || rows != FRAME_LINES (f) |
28ea05de2dc5
Make (many) trivial substitutions for renamed and
Kim F. Storm <storm@cua.dk>
parents:
50778
diff
changeset
|
468 || pixelwidth != FRAME_PIXEL_WIDTH (f) || pixelheight != FRAME_PIXEL_HEIGHT (f))) |
49323 | 469 { |
470 struct x_output *x = f->output_data.x; | |
471 GtkAllocation all; | |
472 | |
473 all.y = mbheight + tbheight; | |
474 all.x = 0; | |
475 | |
476 all.width = pixelwidth; | |
477 all.height = pixelheight - mbheight - tbheight; | |
478 | |
479 gtk_widget_size_allocate (x->edit_widget, &all); | |
50129
d0142038feaa
Reduce flicker in GTK scrollbars.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50112
diff
changeset
|
480 |
49323 | 481 change_frame_size (f, rows, columns, 0, 1, 0); |
482 SET_FRAME_GARBAGED (f); | |
483 cancel_mouse_face (f); | |
484 } | |
485 } | |
486 | |
487 | |
488 /* Update our widget size to be COLS/ROWS characters for frame F. */ | |
489 void | |
490 xg_frame_set_char_size (f, cols, rows) | |
491 FRAME_PTR f; | |
492 int cols; | |
493 int rows; | |
494 { | |
51211
28ea05de2dc5
Make (many) trivial substitutions for renamed and
Kim F. Storm <storm@cua.dk>
parents:
50778
diff
changeset
|
495 int pixelheight = FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f, rows) |
49323 | 496 + FRAME_MENUBAR_HEIGHT (f) + FRAME_TOOLBAR_HEIGHT (f); |
50318
5b50d76d9211
* gtkutil.c (xg_resize_widgets): Don't call xg_frame_cleared.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50272
diff
changeset
|
497 int pixelwidth; |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
498 |
49323 | 499 /* Take into account the size of the scroll bar. Always use the |
500 number of columns occupied by the scroll bar here otherwise we | |
501 might end up with a frame width that is not a multiple of the | |
502 frame's character width which is bad for vertically split | |
503 windows. */ | |
51211
28ea05de2dc5
Make (many) trivial substitutions for renamed and
Kim F. Storm <storm@cua.dk>
parents:
50778
diff
changeset
|
504 f->scroll_bar_actual_width |
28ea05de2dc5
Make (many) trivial substitutions for renamed and
Kim F. Storm <storm@cua.dk>
parents:
50778
diff
changeset
|
505 = FRAME_SCROLL_BAR_COLS (f) * FRAME_COLUMN_WIDTH (f); |
49323 | 506 |
50099
a62497b91c74
Use generic compute_fringe_widths.
Kim F. Storm <storm@cua.dk>
parents:
50063
diff
changeset
|
507 compute_fringe_widths (f, 0); |
49323 | 508 |
51211
28ea05de2dc5
Make (many) trivial substitutions for renamed and
Kim F. Storm <storm@cua.dk>
parents:
50778
diff
changeset
|
509 /* FRAME_TEXT_COLS_TO_PIXEL_WIDTH uses scroll_bar_actual_width, so call it |
50318
5b50d76d9211
* gtkutil.c (xg_resize_widgets): Don't call xg_frame_cleared.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50272
diff
changeset
|
510 after calculating that value. */ |
51211
28ea05de2dc5
Make (many) trivial substitutions for renamed and
Kim F. Storm <storm@cua.dk>
parents:
50778
diff
changeset
|
511 pixelwidth = FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f, cols); |
50318
5b50d76d9211
* gtkutil.c (xg_resize_widgets): Don't call xg_frame_cleared.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50272
diff
changeset
|
512 |
49323 | 513 /* Must resize our top level widget. Font size may have changed, |
514 but not rows/cols. */ | |
515 gtk_window_resize (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f)), | |
516 pixelwidth, pixelheight); | |
517 xg_resize_widgets (f, pixelwidth, pixelheight); | |
53275
a07a0bae1990
* gtkutil.c (xg_frame_set_char_size): Call x_wm_set_size_hint.
Jan Djärv <jan.h.d@swipnet.se>
parents:
53069
diff
changeset
|
518 x_wm_set_size_hint (f, 0, 0); |
50318
5b50d76d9211
* gtkutil.c (xg_resize_widgets): Don't call xg_frame_cleared.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50272
diff
changeset
|
519 SET_FRAME_GARBAGED (f); |
5b50d76d9211
* gtkutil.c (xg_resize_widgets): Don't call xg_frame_cleared.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50272
diff
changeset
|
520 cancel_mouse_face (f); |
49323 | 521 } |
522 | |
53069
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
523 /* Convert an X Window WSESC on display DPY to its corresponding GtkWidget. |
49323 | 524 Must be done like this, because GtkWidget:s can have "hidden" |
525 X Window that aren't accessible. | |
526 | |
527 Return 0 if no widget match WDESC. */ | |
528 GtkWidget * | |
53069
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
529 xg_win_to_widget (dpy, wdesc) |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
530 Display *dpy; |
49323 | 531 Window wdesc; |
532 { | |
533 gpointer gdkwin; | |
534 GtkWidget *gwdesc = 0; | |
535 | |
536 BLOCK_INPUT; | |
53069
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
537 |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
538 gdkwin = gdk_xid_table_lookup_for_display (gdk_x11_lookup_xdisplay (dpy), |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
539 wdesc); |
49323 | 540 if (gdkwin) |
541 { | |
542 GdkEvent event; | |
543 event.any.window = gdkwin; | |
544 gwdesc = gtk_get_event_widget (&event); | |
545 } | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
546 |
49323 | 547 UNBLOCK_INPUT; |
548 return gwdesc; | |
549 } | |
550 | |
551 /* Fill in the GdkColor C so that it represents PIXEL. | |
552 W is the widget that color will be used for. Used to find colormap. */ | |
553 static void | |
554 xg_pix_to_gcolor (w, pixel, c) | |
555 GtkWidget *w; | |
556 unsigned long pixel; | |
557 GdkColor *c; | |
558 { | |
559 GdkColormap *map = gtk_widget_get_colormap (w); | |
560 gdk_colormap_query_color (map, pixel, c); | |
561 } | |
562 | |
50270
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
563 /* Turning off double buffering for our GtkFixed widget has the side |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
564 effect of turning it off also for its children (scroll bars). |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
565 But we want those to be double buffered to not flicker so handle |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
566 expose manually here. |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
567 WIDGET is the GtkFixed widget that gets exposed. |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
568 EVENT is the expose event. |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
569 USER_DATA is unused. |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
570 |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
571 Return TRUE to tell GTK that this expose event has been fully handeled |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
572 and that GTK shall do nothing more with it. */ |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
573 static gboolean |
53069
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
574 xg_fixed_handle_expose (GtkWidget *widget, |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
575 GdkEventExpose *event, |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
576 gpointer user_data) |
50270
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
577 { |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
578 GList *iter; |
50318
5b50d76d9211
* gtkutil.c (xg_resize_widgets): Don't call xg_frame_cleared.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50272
diff
changeset
|
579 |
50270
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
580 for (iter = GTK_FIXED (widget)->children; iter; iter = g_list_next (iter)) |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
581 { |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
582 GtkFixedChild *child_data = (GtkFixedChild *) iter->data; |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
583 GtkWidget *child = child_data->widget; |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
584 GdkWindow *window = child->window; |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
585 GdkRegion *region = gtk_widget_region_intersect (child, event->region); |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
586 |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
587 if (! gdk_region_empty (region)) |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
588 { |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
589 GdkEvent child_event; |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
590 child_event.expose = *event; |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
591 child_event.expose.region = region; |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
592 |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
593 /* Turn on double buffering, i.e. draw to an off screen area. */ |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
594 gdk_window_begin_paint_region (window, region); |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
595 |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
596 /* Tell child to redraw itself. */ |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
597 gdk_region_get_clipbox (region, &child_event.expose.area); |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
598 gtk_widget_send_expose (child, &child_event); |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
599 gdk_window_process_updates (window, TRUE); |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
600 |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
601 /* Copy off screen area to the window. */ |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
602 gdk_window_end_paint (window); |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
603 } |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
604 |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
605 gdk_region_destroy (region); |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
606 } |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
607 |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
608 return TRUE; |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
609 } |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
610 |
49323 | 611 /* Create and set up the GTK widgets for frame F. |
612 Return 0 if creation failed, non-zero otherwise. */ | |
613 int | |
614 xg_create_frame_widgets (f) | |
615 FRAME_PTR f; | |
616 { | |
617 GtkWidget *wtop; | |
618 GtkWidget *wvbox; | |
619 GtkWidget *wfixed; | |
620 GdkColor bg; | |
621 GtkRcStyle *style; | |
622 int i; | |
623 char *title = 0; | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
624 |
49323 | 625 BLOCK_INPUT; |
626 | |
627 wtop = gtk_window_new (GTK_WINDOW_TOPLEVEL); | |
53069
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
628 xg_set_screen (wtop, f); |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
629 |
49323 | 630 wvbox = gtk_vbox_new (FALSE, 0); |
631 wfixed = gtk_fixed_new (); /* Must have this to place scroll bars */ | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
632 |
49323 | 633 if (! wtop || ! wvbox || ! wfixed) |
634 { | |
635 if (wtop) gtk_widget_destroy (wtop); | |
636 if (wvbox) gtk_widget_destroy (wvbox); | |
637 if (wfixed) gtk_widget_destroy (wfixed); | |
638 | |
639 return 0; | |
640 } | |
641 | |
642 /* Use same names as the Xt port does. I.e. Emacs.pane.emacs by default */ | |
643 gtk_widget_set_name (wtop, EMACS_CLASS); | |
644 gtk_widget_set_name (wvbox, "pane"); | |
645 gtk_widget_set_name (wfixed, SDATA (Vx_resource_name)); | |
646 | |
647 /* If this frame has a title or name, set it in the title bar. */ | |
51408
8f1bed1dee3c
Include keyboard.h, charset.h, coding.h.
Dave Love <fx@gnu.org>
parents:
51211
diff
changeset
|
648 if (! NILP (f->title)) title = SDATA (ENCODE_UTF_8 (f->title)); |
8f1bed1dee3c
Include keyboard.h, charset.h, coding.h.
Dave Love <fx@gnu.org>
parents:
51211
diff
changeset
|
649 else if (! NILP (f->name)) title = SDATA (ENCODE_UTF_8 (f->name)); |
49323 | 650 |
651 if (title) gtk_window_set_title (GTK_WINDOW (wtop), title); | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
652 |
49323 | 653 FRAME_GTK_OUTER_WIDGET (f) = wtop; |
654 FRAME_GTK_WIDGET (f) = wfixed; | |
655 f->output_data.x->vbox_widget = wvbox; | |
656 | |
657 gtk_fixed_set_has_window (GTK_FIXED (wfixed), TRUE); | |
658 | |
53069
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
659 gtk_widget_set_size_request (wfixed, FRAME_PIXEL_WIDTH (f), |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
660 FRAME_PIXEL_HEIGHT (f)); |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
661 |
49323 | 662 gtk_container_add (GTK_CONTAINER (wtop), wvbox); |
663 gtk_box_pack_end (GTK_BOX (wvbox), wfixed, TRUE, TRUE, 0); | |
664 | |
665 if (FRAME_EXTERNAL_TOOL_BAR (f)) | |
666 update_frame_tool_bar (f); | |
667 | |
668 /* The tool bar is created but first there are no items in it. | |
669 This causes it to be zero height. Later items are added, but then | |
670 the frame is already mapped, so there is a "jumping" resize. | |
671 This makes geometry handling difficult, for example -0-0 will end | |
672 up in the wrong place as tool bar height has not been taken into account. | |
673 So we cheat a bit by setting a height that is what it will have | |
674 later on when tool bar items are added. */ | |
49325 | 675 if (FRAME_EXTERNAL_TOOL_BAR (f) && FRAME_TOOLBAR_HEIGHT (f) == 0) |
49323 | 676 FRAME_TOOLBAR_HEIGHT (f) = 34; |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
677 |
50270
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
678 |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
679 /* We don't want this widget double buffered, because we draw on it |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
680 with regular X drawing primitives, so from a GTK/GDK point of |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
681 view, the widget is totally blank. When an expose comes, this |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
682 will make the widget blank, and then Emacs redraws it. This flickers |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
683 a lot, so we turn off double buffering. */ |
49323 | 684 gtk_widget_set_double_buffered (wfixed, FALSE); |
50270
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
685 |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
686 /* Turning off double buffering above has the side effect of turning |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
687 it off also for its children (scroll bars). But we want those |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
688 to be double buffered to not flicker so handle expose manually. */ |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
689 g_signal_connect (G_OBJECT (wfixed), "expose-event", |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
690 G_CALLBACK (xg_fixed_handle_expose), 0); |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
691 |
49323 | 692 /* GTK documents says use gtk_window_set_resizable. But then a user |
693 can't shrink the window from its starting size. */ | |
694 gtk_window_set_policy (GTK_WINDOW (wtop), TRUE, TRUE, TRUE); | |
695 gtk_window_set_wmclass (GTK_WINDOW (wtop), | |
696 SDATA (Vx_resource_name), | |
697 SDATA (Vx_resource_class)); | |
698 | |
699 /* Add callback to do nothing on WM_DELETE_WINDOW. The default in | |
700 GTK is to destroy the widget. We want Emacs to do that instead. */ | |
701 g_signal_connect (G_OBJECT (wtop), "delete-event", | |
702 G_CALLBACK (gtk_true), 0); | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
703 |
49323 | 704 /* Convert our geometry parameters into a geometry string |
705 and specify it. | |
706 GTK will itself handle calculating the real position this way. */ | |
707 xg_set_geometry (f); | |
708 | |
709 gtk_widget_add_events (wfixed, | |
710 GDK_POINTER_MOTION_MASK | |
711 | GDK_EXPOSURE_MASK | |
712 | GDK_BUTTON_PRESS_MASK | |
713 | GDK_BUTTON_RELEASE_MASK | |
714 | GDK_KEY_PRESS_MASK | |
715 | GDK_ENTER_NOTIFY_MASK | |
716 | GDK_LEAVE_NOTIFY_MASK | |
717 | GDK_FOCUS_CHANGE_MASK | |
718 | GDK_STRUCTURE_MASK | |
719 | GDK_VISIBILITY_NOTIFY_MASK); | |
720 | |
721 /* Must realize the windows so the X window gets created. It is used | |
722 by callers of this function. */ | |
723 gtk_widget_realize (wfixed); | |
724 FRAME_X_WINDOW (f) = GTK_WIDGET_TO_X_WIN (wfixed); | |
725 | |
726 /* Since GTK clears its window by filling with the background color, | |
727 we must keep X and GTK background in sync. */ | |
728 xg_pix_to_gcolor (wfixed, f->output_data.x->background_pixel, &bg); | |
729 gtk_widget_modify_bg (wfixed, GTK_STATE_NORMAL, &bg); | |
730 | |
731 /* Also, do not let any background pixmap to be set, this looks very | |
732 bad as Emacs overwrites the background pixmap with its own idea | |
733 of background color. */ | |
734 style = gtk_widget_get_modifier_style (wfixed); | |
735 | |
736 /* Must use g_strdup because gtk_widget_modify_style does g_free. */ | |
737 style->bg_pixmap_name[GTK_STATE_NORMAL] = g_strdup ("<none>"); | |
738 gtk_widget_modify_style (wfixed, style); | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
739 |
49323 | 740 /* GTK does not set any border, and they look bad with GTK. */ |
51211
28ea05de2dc5
Make (many) trivial substitutions for renamed and
Kim F. Storm <storm@cua.dk>
parents:
50778
diff
changeset
|
741 f->border_width = 0; |
28ea05de2dc5
Make (many) trivial substitutions for renamed and
Kim F. Storm <storm@cua.dk>
parents:
50778
diff
changeset
|
742 f->internal_border_width = 0; |
49323 | 743 |
744 UNBLOCK_INPUT; | |
745 | |
746 return 1; | |
747 } | |
748 | |
749 /* Set the normal size hints for the window manager, for frame F. | |
750 FLAGS is the flags word to use--or 0 meaning preserve the flags | |
751 that the window now has. | |
752 If USER_POSITION is nonzero, we set the User Position | |
753 flag (this is useful when FLAGS is 0). */ | |
754 void | |
755 x_wm_set_size_hint (f, flags, user_position) | |
756 FRAME_PTR f; | |
757 long flags; | |
758 int user_position; | |
759 { | |
760 if (FRAME_GTK_OUTER_WIDGET (f)) | |
761 { | |
762 /* Must use GTK routines here, otherwise GTK resets the size hints | |
763 to its own defaults. */ | |
764 GdkGeometry size_hints; | |
765 gint hint_flags = 0; | |
766 int base_width, base_height; | |
767 int min_rows = 0, min_cols = 0; | |
51211
28ea05de2dc5
Make (many) trivial substitutions for renamed and
Kim F. Storm <storm@cua.dk>
parents:
50778
diff
changeset
|
768 int win_gravity = f->win_gravity; |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
769 |
49323 | 770 if (flags) |
771 { | |
772 memset (&size_hints, 0, sizeof (size_hints)); | |
773 f->output_data.x->size_hints = size_hints; | |
774 f->output_data.x->hint_flags = hint_flags; | |
775 } | |
776 else | |
51211
28ea05de2dc5
Make (many) trivial substitutions for renamed and
Kim F. Storm <storm@cua.dk>
parents:
50778
diff
changeset
|
777 flags = f->size_hint_flags; |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
778 |
49323 | 779 size_hints = f->output_data.x->size_hints; |
780 hint_flags = f->output_data.x->hint_flags; | |
781 | |
782 hint_flags |= GDK_HINT_RESIZE_INC | GDK_HINT_MIN_SIZE; | |
51211
28ea05de2dc5
Make (many) trivial substitutions for renamed and
Kim F. Storm <storm@cua.dk>
parents:
50778
diff
changeset
|
783 size_hints.width_inc = FRAME_COLUMN_WIDTH (f); |
28ea05de2dc5
Make (many) trivial substitutions for renamed and
Kim F. Storm <storm@cua.dk>
parents:
50778
diff
changeset
|
784 size_hints.height_inc = FRAME_LINE_HEIGHT (f); |
49323 | 785 |
786 hint_flags |= GDK_HINT_BASE_SIZE; | |
51211
28ea05de2dc5
Make (many) trivial substitutions for renamed and
Kim F. Storm <storm@cua.dk>
parents:
50778
diff
changeset
|
787 base_width = FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f, 0); |
28ea05de2dc5
Make (many) trivial substitutions for renamed and
Kim F. Storm <storm@cua.dk>
parents:
50778
diff
changeset
|
788 base_height = FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f, 0) |
49323 | 789 + FRAME_MENUBAR_HEIGHT (f) + FRAME_TOOLBAR_HEIGHT (f); |
790 | |
791 check_frame_size (f, &min_rows, &min_cols); | |
792 | |
793 size_hints.base_width = base_width; | |
794 size_hints.base_height = base_height; | |
795 size_hints.min_width = base_width + min_cols * size_hints.width_inc; | |
796 size_hints.min_height = base_height + min_rows * size_hints.height_inc; | |
797 | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
798 |
49323 | 799 /* These currently have a one to one mapping with the X values, but I |
800 don't think we should rely on that. */ | |
801 hint_flags |= GDK_HINT_WIN_GRAVITY; | |
802 size_hints.win_gravity = 0; | |
803 if (win_gravity == NorthWestGravity) | |
804 size_hints.win_gravity = GDK_GRAVITY_NORTH_WEST; | |
805 else if (win_gravity == NorthGravity) | |
806 size_hints.win_gravity = GDK_GRAVITY_NORTH; | |
807 else if (win_gravity == NorthEastGravity) | |
808 size_hints.win_gravity = GDK_GRAVITY_NORTH_EAST; | |
809 else if (win_gravity == WestGravity) | |
810 size_hints.win_gravity = GDK_GRAVITY_WEST; | |
811 else if (win_gravity == CenterGravity) | |
812 size_hints.win_gravity = GDK_GRAVITY_CENTER; | |
813 else if (win_gravity == EastGravity) | |
814 size_hints.win_gravity = GDK_GRAVITY_EAST; | |
815 else if (win_gravity == SouthWestGravity) | |
816 size_hints.win_gravity = GDK_GRAVITY_SOUTH_WEST; | |
817 else if (win_gravity == SouthGravity) | |
818 size_hints.win_gravity = GDK_GRAVITY_SOUTH; | |
819 else if (win_gravity == SouthEastGravity) | |
820 size_hints.win_gravity = GDK_GRAVITY_SOUTH_EAST; | |
821 else if (win_gravity == StaticGravity) | |
822 size_hints.win_gravity = GDK_GRAVITY_STATIC; | |
823 | |
824 if (flags & PPosition) hint_flags |= GDK_HINT_POS; | |
825 if (flags & USPosition) hint_flags |= GDK_HINT_USER_POS; | |
826 if (flags & USSize) hint_flags |= GDK_HINT_USER_SIZE; | |
827 | |
828 if (user_position) | |
829 { | |
830 hint_flags &= ~GDK_HINT_POS; | |
831 hint_flags |= GDK_HINT_USER_POS; | |
832 } | |
833 | |
834 BLOCK_INPUT; | |
835 | |
836 gtk_window_set_geometry_hints (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f)), | |
837 FRAME_GTK_OUTER_WIDGET (f), | |
838 &size_hints, | |
839 hint_flags); | |
840 | |
841 f->output_data.x->size_hints = size_hints; | |
842 f->output_data.x->hint_flags = hint_flags; | |
843 UNBLOCK_INPUT; | |
844 } | |
845 } | |
846 | |
847 /* Change background color of a frame. | |
848 Since GTK uses the background colour to clear the window, we must | |
849 keep the GTK and X colors in sync. | |
850 F is the frame to change, | |
851 BG is the pixel value to change to. */ | |
852 void | |
853 xg_set_background_color (f, bg) | |
854 FRAME_PTR f; | |
855 unsigned long bg; | |
856 { | |
857 if (FRAME_GTK_WIDGET (f)) | |
858 { | |
859 GdkColor gdk_bg; | |
860 | |
861 BLOCK_INPUT; | |
862 xg_pix_to_gcolor (FRAME_GTK_WIDGET (f), bg, &gdk_bg); | |
863 gtk_widget_modify_bg (FRAME_GTK_WIDGET (f), GTK_STATE_NORMAL, &gdk_bg); | |
864 UNBLOCK_INPUT; | |
865 } | |
866 } | |
867 | |
868 | |
869 | |
870 /*********************************************************************** | |
871 Dialog functions | |
872 ***********************************************************************/ | |
873 /* Return the dialog title to use for a dialog of type KEY. | |
874 This is the encoding used by lwlib. We use the same for GTK. */ | |
875 static char * | |
876 get_dialog_title (char key) | |
877 { | |
878 char *title = ""; | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
879 |
49323 | 880 switch (key) { |
881 case 'E': case 'e': | |
882 title = "Error"; | |
883 break; | |
884 | |
885 case 'I': case 'i': | |
886 title = "Information"; | |
887 break; | |
888 | |
889 case 'L': case 'l': | |
890 title = "Prompt"; | |
891 break; | |
892 | |
893 case 'P': case 'p': | |
894 title = "Prompt"; | |
895 break; | |
896 | |
897 case 'Q': case 'q': | |
898 title = "Question"; | |
899 break; | |
900 } | |
901 | |
902 return title; | |
903 } | |
904 | |
905 /* Callback for dialogs that get WM_DELETE_WINDOW. We pop down | |
906 the dialog, but return TRUE so the event does not propagate further | |
907 in GTK. This prevents GTK from destroying the dialog widget automatically | |
908 and we can always destrou the widget manually, regardles of how | |
909 it was popped down (button press or WM_DELETE_WINDOW). | |
910 W is the dialog widget. | |
911 EVENT is the GdkEvent that represents WM_DELETE_WINDOW (not used). | |
912 user_data is NULL (not used). | |
913 | |
914 Returns TRUE to end propagation of event. */ | |
915 static gboolean | |
916 dialog_delete_callback (w, event, user_data) | |
917 GtkWidget *w; | |
918 GdkEvent *event; | |
919 gpointer user_data; | |
920 { | |
921 gtk_widget_unmap (w); | |
922 return TRUE; | |
923 } | |
924 | |
925 /* Create a popup dialog window. See also xg_create_widget below. | |
926 WV is a widget_value describing the dialog. | |
927 SELECT_CB is the callback to use when a button has been pressed. | |
928 DEACTIVATE_CB is the callback to use when the dialog pops down. | |
929 | |
930 Returns the GTK dialog widget. */ | |
931 static GtkWidget * | |
932 create_dialog (wv, select_cb, deactivate_cb) | |
933 widget_value *wv; | |
934 GCallback select_cb; | |
935 GCallback deactivate_cb; | |
936 { | |
937 char *title = get_dialog_title (wv->name[0]); | |
938 int total_buttons = wv->name[1] - '0'; | |
939 int right_buttons = wv->name[4] - '0'; | |
940 int left_buttons; | |
941 int button_nr = 0; | |
942 int button_spacing = 10; | |
943 GtkWidget *wdialog = gtk_dialog_new (); | |
944 widget_value *item; | |
945 GtkBox *cur_box; | |
946 GtkWidget *wvbox; | |
947 GtkWidget *whbox_up; | |
948 GtkWidget *whbox_down; | |
949 | |
950 /* If the number of buttons is greater than 4, make two rows of buttons | |
951 instead. This looks better. */ | |
952 int make_two_rows = total_buttons > 4; | |
953 | |
954 if (right_buttons == 0) right_buttons = total_buttons/2; | |
955 left_buttons = total_buttons - right_buttons; | |
956 | |
957 gtk_window_set_title (GTK_WINDOW (wdialog), title); | |
958 gtk_widget_set_name (wdialog, "emacs-dialog"); | |
959 | |
960 cur_box = GTK_BOX (GTK_DIALOG (wdialog)->action_area); | |
961 | |
962 if (make_two_rows) | |
963 { | |
964 wvbox = gtk_vbox_new (TRUE, button_spacing); | |
965 whbox_up = gtk_hbox_new (FALSE, 0); | |
966 whbox_down = gtk_hbox_new (FALSE, 0); | |
967 | |
968 gtk_box_pack_start (cur_box, wvbox, FALSE, FALSE, 0); | |
969 gtk_box_pack_start (GTK_BOX (wvbox), whbox_up, FALSE, FALSE, 0); | |
970 gtk_box_pack_start (GTK_BOX (wvbox), whbox_down, FALSE, FALSE, 0); | |
971 | |
972 cur_box = GTK_BOX (whbox_up); | |
973 } | |
974 | |
975 g_signal_connect (G_OBJECT (wdialog), "delete-event", | |
976 G_CALLBACK (dialog_delete_callback), 0); | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
977 |
49323 | 978 if (deactivate_cb) |
979 { | |
980 g_signal_connect (G_OBJECT (wdialog), "close", deactivate_cb, 0); | |
981 g_signal_connect (G_OBJECT (wdialog), "response", deactivate_cb, 0); | |
982 } | |
983 | |
984 for (item = wv->contents; item; item = item->next) | |
985 { | |
986 char *utf8_label = get_utf8_string (item->value); | |
987 GtkWidget *w; | |
988 GtkRequisition req; | |
989 | |
49488
da6abcaef15c
gtkutil.c: Check for NULL string before calling strcmp or strlen.
Jan Djärv <jan.h.d@swipnet.se>
parents:
49468
diff
changeset
|
990 if (item->name && strcmp (item->name, "message") == 0) |
49323 | 991 { |
992 /* This is the text part of the dialog. */ | |
993 w = gtk_label_new (utf8_label); | |
994 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (wdialog)->vbox), | |
995 gtk_label_new (""), | |
996 FALSE, FALSE, 0); | |
997 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (wdialog)->vbox), w, | |
998 TRUE, TRUE, 0); | |
999 gtk_misc_set_alignment (GTK_MISC (w), 0.1, 0.5); | |
1000 | |
1001 /* Try to make dialog look better. Must realize first so | |
1002 the widget can calculate the size it needs. */ | |
1003 gtk_widget_realize (w); | |
1004 gtk_widget_size_request (w, &req); | |
1005 gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (wdialog)->vbox), | |
1006 req.height); | |
49488
da6abcaef15c
gtkutil.c: Check for NULL string before calling strcmp or strlen.
Jan Djärv <jan.h.d@swipnet.se>
parents:
49468
diff
changeset
|
1007 if (item->value && strlen (item->value) > 0) |
49323 | 1008 button_spacing = 2*req.width/strlen (item->value); |
1009 } | |
1010 else | |
1011 { | |
1012 /* This is one button to add to the dialog. */ | |
50778
f30e6f029d65
* gtkutil.c (create_dialog, make_widget_for_menu_item)
Jan Djärv <jan.h.d@swipnet.se>
parents:
50521
diff
changeset
|
1013 w = gtk_button_new_with_label (utf8_label); |
49323 | 1014 if (! item->enabled) |
1015 gtk_widget_set_sensitive (w, FALSE); | |
1016 if (select_cb) | |
1017 g_signal_connect (G_OBJECT (w), "clicked", | |
1018 select_cb, item->call_data); | |
1019 | |
1020 gtk_box_pack_start (cur_box, w, TRUE, TRUE, button_spacing); | |
1021 if (++button_nr == left_buttons) | |
1022 { | |
1023 if (make_two_rows) | |
1024 cur_box = GTK_BOX (whbox_down); | |
1025 else | |
1026 gtk_box_pack_start (cur_box, | |
1027 gtk_label_new (""), | |
1028 TRUE, TRUE, | |
1029 button_spacing); | |
1030 } | |
1031 } | |
1032 | |
1033 if (utf8_label && utf8_label != item->value) | |
1034 g_free (utf8_label); | |
1035 } | |
1036 | |
1037 return wdialog; | |
1038 } | |
1039 | |
1040 | |
1041 enum | |
1042 { | |
1043 XG_FILE_NOT_DONE, | |
1044 XG_FILE_OK, | |
1045 XG_FILE_CANCEL, | |
1046 XG_FILE_DESTROYED, | |
1047 }; | |
1048 | |
1049 /* Callback function invoked when the Ok button is pressed in | |
1050 a file dialog. | |
1051 W is the file dialog widget, | |
1052 ARG points to an integer where we record what has happend. */ | |
1053 static void | |
1054 xg_file_sel_ok (w, arg) | |
1055 GtkWidget *w; | |
1056 gpointer arg; | |
1057 { | |
1058 *(int*)arg = XG_FILE_OK; | |
1059 } | |
1060 | |
1061 /* Callback function invoked when the Cancel button is pressed in | |
1062 a file dialog. | |
1063 W is the file dialog widget, | |
1064 ARG points to an integer where we record what has happend. */ | |
1065 static void | |
1066 xg_file_sel_cancel (w, arg) | |
1067 GtkWidget *w; | |
1068 gpointer arg; | |
1069 { | |
1070 *(int*)arg = XG_FILE_CANCEL; | |
1071 } | |
1072 | |
1073 /* Callback function invoked when the file dialog is destroyed (i.e. | |
1074 popped down). We must keep track of this, because if this | |
1075 happens, GTK destroys the widget. But if for example, Ok is pressed, | |
1076 the dialog is popped down, but the dialog widget is not destroyed. | |
1077 W is the file dialog widget, | |
1078 ARG points to an integer where we record what has happend. */ | |
1079 static void | |
1080 xg_file_sel_destroy (w, arg) | |
1081 GtkWidget *w; | |
1082 gpointer arg; | |
1083 { | |
1084 *(int*)arg = XG_FILE_DESTROYED; | |
1085 } | |
1086 | |
1087 /* Read a file name from the user using a file dialog. | |
1088 F is the current frame. | |
1089 PROMPT is a prompt to show to the user. May not be NULL. | |
1090 DEFAULT_FILENAME is a default selection to be displayed. May be NULL. | |
1091 If MUSTMATCH_P is non-zero, the returned file name must be an existing | |
1092 file. | |
1093 | |
1094 Returns a file name or NULL if no file was selected. | |
1095 The returned string must be freed by the caller. */ | |
1096 char * | |
1097 xg_get_file_name (f, prompt, default_filename, mustmatch_p) | |
1098 FRAME_PTR f; | |
1099 char *prompt; | |
1100 char *default_filename; | |
1101 int mustmatch_p; | |
1102 { | |
1103 GtkWidget *filewin; | |
1104 GtkFileSelection *filesel; | |
1105 int filesel_done = XG_FILE_NOT_DONE; | |
1106 char *fn = 0; | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
1107 |
49323 | 1108 filewin = gtk_file_selection_new (prompt); |
1109 filesel = GTK_FILE_SELECTION (filewin); | |
1110 | |
53069
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
1111 xg_set_screen (filewin, f); |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
1112 |
49323 | 1113 gtk_widget_set_name (filewin, "emacs-filedialog"); |
1114 | |
1115 gtk_window_set_transient_for (GTK_WINDOW (filewin), | |
1116 GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f))); | |
1117 gtk_window_set_destroy_with_parent (GTK_WINDOW (filewin), TRUE); | |
1118 | |
1119 g_signal_connect (G_OBJECT (filesel->ok_button), | |
1120 "clicked", | |
1121 G_CALLBACK (xg_file_sel_ok), | |
1122 &filesel_done); | |
1123 g_signal_connect (G_OBJECT (filesel->cancel_button), | |
1124 "clicked", | |
1125 G_CALLBACK (xg_file_sel_cancel), | |
1126 &filesel_done); | |
1127 g_signal_connect (G_OBJECT (filesel), | |
1128 "destroy", | |
1129 G_CALLBACK (xg_file_sel_destroy), | |
1130 &filesel_done); | |
1131 | |
1132 if (default_filename) | |
1133 gtk_file_selection_set_filename (filesel, default_filename); | |
1134 | |
1135 if (mustmatch_p) | |
1136 { | |
1137 /* The selection_entry part of filesel is not documented. */ | |
1138 gtk_widget_set_sensitive (filesel->selection_entry, FALSE); | |
1139 gtk_file_selection_hide_fileop_buttons (filesel); | |
1140 } | |
1141 | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
1142 |
49323 | 1143 gtk_widget_show_all (filewin); |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
1144 |
49323 | 1145 while (filesel_done == XG_FILE_NOT_DONE) |
1146 gtk_main_iteration (); | |
1147 | |
1148 if (filesel_done == XG_FILE_OK) | |
1149 fn = xstrdup ((char*) gtk_file_selection_get_filename (filesel)); | |
1150 | |
1151 if (filesel_done != XG_FILE_DESTROYED) | |
1152 gtk_widget_destroy (filewin); | |
1153 | |
1154 return fn; | |
1155 } | |
1156 | |
1157 | |
1158 /*********************************************************************** | |
1159 Menu functions. | |
1160 ***********************************************************************/ | |
1161 | |
1162 /* The name of menu items that can be used for citomization. Since GTK | |
1163 RC files are very crude and primitive, we have to set this on all | |
1164 menu item names so a user can easily cutomize menu items. */ | |
1165 | |
1166 #define MENU_ITEM_NAME "emacs-menuitem" | |
1167 | |
1168 | |
1169 /* Linked list of all allocated struct xg_menu_cb_data. Used for marking | |
1170 during GC. The next member points to the items. */ | |
1171 static xg_list_node xg_menu_cb_list; | |
1172 | |
1173 /* Linked list of all allocated struct xg_menu_item_cb_data. Used for marking | |
1174 during GC. The next member points to the items. */ | |
1175 static xg_list_node xg_menu_item_cb_list; | |
1176 | |
1177 /* Allocate and initialize CL_DATA if NULL, otherwise increase ref_count. | |
1178 F is the frame CL_DATA will be initialized for. | |
1179 HIGHLIGHT_CB is the callback to call when entering/leaving menu items. | |
1180 | |
1181 The menu bar and all sub menus under the menu bar in a frame | |
1182 share the same structure, hence the reference count. | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
1183 |
49323 | 1184 Returns CL_DATA if CL_DATA is not NULL, or a pointer to a newly |
1185 allocated xg_menu_cb_data if CL_DATA is NULL. */ | |
1186 static xg_menu_cb_data * | |
1187 make_cl_data (cl_data, f, highlight_cb) | |
1188 xg_menu_cb_data *cl_data; | |
1189 FRAME_PTR f; | |
1190 GCallback highlight_cb; | |
1191 { | |
1192 if (! cl_data) | |
1193 { | |
1194 cl_data = (xg_menu_cb_data*) xmalloc (sizeof (*cl_data)); | |
1195 cl_data->f = f; | |
1196 cl_data->menu_bar_vector = f->menu_bar_vector; | |
1197 cl_data->menu_bar_items_used = f->menu_bar_items_used; | |
1198 cl_data->highlight_cb = highlight_cb; | |
1199 cl_data->ref_count = 0; | |
1200 | |
1201 xg_list_insert (&xg_menu_cb_list, &cl_data->ptrs); | |
1202 } | |
1203 | |
1204 cl_data->ref_count++; | |
1205 | |
1206 return cl_data; | |
1207 } | |
1208 | |
1209 /* Update CL_DATA with values from frame F and with HIGHLIGHT_CB. | |
1210 HIGHLIGHT_CB is the callback to call when entering/leaving menu items. | |
1211 | |
1212 When the menu bar is updated, menu items may have been added and/or | |
1213 removed, so menu_bar_vector and menu_bar_items_used change. We must | |
1214 then update CL_DATA since it is used to determine which menu | |
1215 item that is invoked in the menu. | |
1216 HIGHLIGHT_CB could change, there is no check that the same | |
1217 function is given when modifying a menu bar as was given when | |
1218 creating the menu bar. */ | |
1219 static void | |
1220 update_cl_data (cl_data, f, highlight_cb) | |
1221 xg_menu_cb_data *cl_data; | |
1222 FRAME_PTR f; | |
1223 GCallback highlight_cb; | |
1224 { | |
1225 if (cl_data) | |
1226 { | |
1227 cl_data->f = f; | |
1228 cl_data->menu_bar_vector = f->menu_bar_vector; | |
1229 cl_data->menu_bar_items_used = f->menu_bar_items_used; | |
1230 cl_data->highlight_cb = highlight_cb; | |
1231 } | |
1232 } | |
1233 | |
1234 /* Decrease reference count for CL_DATA. | |
1235 If reference count is zero, free CL_DATA. */ | |
1236 static void | |
1237 unref_cl_data (cl_data) | |
1238 xg_menu_cb_data *cl_data; | |
1239 { | |
1240 if (cl_data && cl_data->ref_count > 0) | |
1241 { | |
1242 cl_data->ref_count--; | |
1243 if (cl_data->ref_count == 0) | |
1244 { | |
1245 xg_list_remove (&xg_menu_cb_list, &cl_data->ptrs); | |
1246 xfree (cl_data); | |
1247 } | |
1248 } | |
1249 } | |
1250 | |
1251 /* Function that marks all lisp data during GC. */ | |
1252 void | |
1253 xg_mark_data () | |
1254 { | |
1255 xg_list_node *iter; | |
1256 | |
1257 for (iter = xg_menu_cb_list.next; iter; iter = iter->next) | |
52080
c150d4a7aa36
gtkutil.c (xg_mark_data): Update calls to mark_object.
Jan Djärv <jan.h.d@swipnet.se>
parents:
51569
diff
changeset
|
1258 mark_object (((xg_menu_cb_data *) iter)->menu_bar_vector); |
49323 | 1259 |
1260 for (iter = xg_menu_item_cb_list.next; iter; iter = iter->next) | |
1261 { | |
1262 xg_menu_item_cb_data *cb_data = (xg_menu_item_cb_data *) iter; | |
1263 | |
1264 if (! NILP (cb_data->help)) | |
52080
c150d4a7aa36
gtkutil.c (xg_mark_data): Update calls to mark_object.
Jan Djärv <jan.h.d@swipnet.se>
parents:
51569
diff
changeset
|
1265 mark_object (cb_data->help); |
49323 | 1266 } |
1267 } | |
1268 | |
1269 | |
1270 /* Callback called when a menu item is destroyed. Used to free data. | |
1271 W is the widget that is being destroyed (not used). | |
1272 CLIENT_DATA points to the xg_menu_item_cb_data associated with the W. */ | |
1273 static void | |
1274 menuitem_destroy_callback (w, client_data) | |
1275 GtkWidget *w; | |
1276 gpointer client_data; | |
1277 { | |
1278 if (client_data) | |
1279 { | |
1280 xg_menu_item_cb_data *data = (xg_menu_item_cb_data*) client_data; | |
1281 xg_list_remove (&xg_menu_item_cb_list, &data->ptrs); | |
1282 xfree (data); | |
1283 } | |
1284 } | |
1285 | |
1286 /* Callback called when the pointer enters/leaves a menu item. | |
1287 W is the menu item. | |
1288 EVENT is either an enter event or leave event. | |
1289 CLIENT_DATA points to the xg_menu_item_cb_data associated with the W. | |
1290 | |
1291 Returns FALSE to tell GTK to keep processing this event. */ | |
1292 static gboolean | |
1293 menuitem_highlight_callback (w, event, client_data) | |
1294 GtkWidget *w; | |
1295 GdkEventCrossing *event; | |
1296 gpointer client_data; | |
1297 { | |
1298 if (client_data) | |
1299 { | |
1300 xg_menu_item_cb_data *data = (xg_menu_item_cb_data*) client_data; | |
1301 gpointer call_data = event->type == GDK_LEAVE_NOTIFY ? 0 : client_data; | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
1302 |
49323 | 1303 if (! NILP (data->help) && data->cl_data->highlight_cb) |
1304 { | |
1305 GtkCallback func = (GtkCallback) data->cl_data->highlight_cb; | |
1306 (*func) (w, call_data); | |
1307 } | |
1308 } | |
1309 | |
1310 return FALSE; | |
1311 } | |
1312 | |
1313 /* Callback called when a menu is destroyed. Used to free data. | |
1314 W is the widget that is being destroyed (not used). | |
1315 CLIENT_DATA points to the xg_menu_cb_data associated with W. */ | |
1316 static void | |
1317 menu_destroy_callback (w, client_data) | |
1318 GtkWidget *w; | |
1319 gpointer client_data; | |
1320 { | |
1321 unref_cl_data ((xg_menu_cb_data*) client_data); | |
1322 } | |
1323 | |
1324 /* Callback called when a menu does a grab or ungrab. That means the | |
1325 menu has been activated or deactivated. | |
1326 Used to start a timer so the small timeout the menus in GTK uses before | |
1327 popping down a menu is seen by Emacs (see xg_process_timeouts above). | |
1328 W is the widget that does the grab (not used). | |
1329 UNGRAB_P is TRUE if this is an ungrab, FALSE if it is a grab. | |
1330 CLIENT_DATA is NULL (not used). */ | |
1331 static void | |
1332 menu_grab_callback (GtkWidget *widget, | |
1333 gboolean ungrab_p, | |
1334 gpointer client_data) | |
1335 { | |
1336 /* Keep track of total number of grabs. */ | |
1337 static int cnt; | |
1338 | |
1339 if (ungrab_p) cnt--; | |
1340 else cnt++; | |
1341 | |
1342 if (cnt > 0 && ! xg_timer) xg_start_timer (); | |
1343 else if (cnt == 0 && xg_timer) xg_stop_timer (); | |
1344 } | |
1345 | |
1346 /* Make a GTK widget that contains both UTF8_LABEL and UTF8_KEY (both | |
1347 must be non-NULL) and can be inserted into a menu item. | |
1348 | |
1349 Returns the GtkHBox. */ | |
1350 static GtkWidget * | |
1351 make_widget_for_menu_item (utf8_label, utf8_key) | |
1352 char *utf8_label; | |
1353 char *utf8_key; | |
1354 { | |
1355 GtkWidget *wlbl; | |
1356 GtkWidget *wkey; | |
1357 GtkWidget *wbox; | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
1358 |
49323 | 1359 wbox = gtk_hbox_new (FALSE, 0); |
50778
f30e6f029d65
* gtkutil.c (create_dialog, make_widget_for_menu_item)
Jan Djärv <jan.h.d@swipnet.se>
parents:
50521
diff
changeset
|
1360 wlbl = gtk_label_new (utf8_label); |
49323 | 1361 wkey = gtk_label_new (utf8_key); |
1362 | |
1363 gtk_misc_set_alignment (GTK_MISC (wlbl), 0.0, 0.5); | |
1364 gtk_misc_set_alignment (GTK_MISC (wkey), 0.0, 0.5); | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
1365 |
49323 | 1366 gtk_box_pack_start (GTK_BOX (wbox), wlbl, TRUE, TRUE, 0); |
1367 gtk_box_pack_start (GTK_BOX (wbox), wkey, FALSE, FALSE, 0); | |
1368 | |
1369 gtk_widget_set_name (wlbl, MENU_ITEM_NAME); | |
1370 gtk_widget_set_name (wkey, MENU_ITEM_NAME); | |
50270
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
1371 gtk_widget_set_name (wbox, MENU_ITEM_NAME); |
49323 | 1372 |
1373 return wbox; | |
1374 } | |
1375 | |
1376 /* Make and return a menu item widget with the key to the right. | |
1377 UTF8_LABEL is the text for the menu item (GTK uses UTF8 internally). | |
1378 UTF8_KEY is the text representing the key binding. | |
1379 ITEM is the widget_value describing the menu item. | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
1380 |
49323 | 1381 GROUP is an in/out parameter. If the menu item to be created is not |
1382 part of any radio menu group, *GROUP contains NULL on entry and exit. | |
1383 If the menu item to be created is part of a radio menu group, on entry | |
1384 *GROUP contains the group to use, or NULL if this is the first item | |
1385 in the group. On exit, *GROUP contains the radio item group. | |
1386 | |
1387 Unfortunately, keys don't line up as nicely as in Motif, | |
1388 but the MacOS X version doesn't either, so I guess that is OK. */ | |
1389 static GtkWidget * | |
1390 make_menu_item (utf8_label, utf8_key, item, group) | |
1391 char *utf8_label; | |
1392 char *utf8_key; | |
1393 widget_value *item; | |
1394 GSList **group; | |
1395 { | |
1396 GtkWidget *w; | |
1397 GtkWidget *wtoadd = 0; | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
1398 |
51432
6db55492aca9
* gtkutil.c (make_menu_item): Make sure we don't crash on a NULL
Jan Djärv <jan.h.d@swipnet.se>
parents:
51408
diff
changeset
|
1399 /* It has been observed that some menu items have a NULL name field. |
6db55492aca9
* gtkutil.c (make_menu_item): Make sure we don't crash on a NULL
Jan Djärv <jan.h.d@swipnet.se>
parents:
51408
diff
changeset
|
1400 This will lead to this function being called with a NULL utf8_label. |
6db55492aca9
* gtkutil.c (make_menu_item): Make sure we don't crash on a NULL
Jan Djärv <jan.h.d@swipnet.se>
parents:
51408
diff
changeset
|
1401 GTK crashes on that so we set a blank label. Why there is a NULL |
6db55492aca9
* gtkutil.c (make_menu_item): Make sure we don't crash on a NULL
Jan Djärv <jan.h.d@swipnet.se>
parents:
51408
diff
changeset
|
1402 name remains to be investigated. */ |
6db55492aca9
* gtkutil.c (make_menu_item): Make sure we don't crash on a NULL
Jan Djärv <jan.h.d@swipnet.se>
parents:
51408
diff
changeset
|
1403 if (! utf8_label) utf8_label = " "; |
6db55492aca9
* gtkutil.c (make_menu_item): Make sure we don't crash on a NULL
Jan Djärv <jan.h.d@swipnet.se>
parents:
51408
diff
changeset
|
1404 |
49323 | 1405 if (utf8_key) |
1406 wtoadd = make_widget_for_menu_item (utf8_label, utf8_key); | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
1407 |
49323 | 1408 if (item->button_type == BUTTON_TYPE_TOGGLE) |
1409 { | |
1410 *group = NULL; | |
1411 if (utf8_key) w = gtk_check_menu_item_new (); | |
50778
f30e6f029d65
* gtkutil.c (create_dialog, make_widget_for_menu_item)
Jan Djärv <jan.h.d@swipnet.se>
parents:
50521
diff
changeset
|
1412 else w = gtk_check_menu_item_new_with_label (utf8_label); |
49323 | 1413 gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (w), item->selected); |
1414 } | |
1415 else if (item->button_type == BUTTON_TYPE_RADIO) | |
1416 { | |
1417 if (utf8_key) w = gtk_radio_menu_item_new (*group); | |
50778
f30e6f029d65
* gtkutil.c (create_dialog, make_widget_for_menu_item)
Jan Djärv <jan.h.d@swipnet.se>
parents:
50521
diff
changeset
|
1418 else w = gtk_radio_menu_item_new_with_label (*group, utf8_label); |
49323 | 1419 *group = gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (w)); |
1420 if (item->selected) | |
1421 gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (w), TRUE); | |
1422 } | |
1423 else | |
1424 { | |
1425 *group = NULL; | |
1426 if (utf8_key) w = gtk_menu_item_new (); | |
50778
f30e6f029d65
* gtkutil.c (create_dialog, make_widget_for_menu_item)
Jan Djärv <jan.h.d@swipnet.se>
parents:
50521
diff
changeset
|
1427 else w = gtk_menu_item_new_with_label (utf8_label); |
49323 | 1428 } |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
1429 |
49323 | 1430 if (wtoadd) gtk_container_add (GTK_CONTAINER (w), wtoadd); |
1431 if (! item->enabled) gtk_widget_set_sensitive (w, FALSE); | |
1432 | |
1433 return w; | |
1434 } | |
1435 | |
50318
5b50d76d9211
* gtkutil.c (xg_resize_widgets): Don't call xg_frame_cleared.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50272
diff
changeset
|
1436 /* Return non-zero if LABEL specifies a separator (GTK only has one |
49323 | 1437 separator type) */ |
1438 static int | |
50318
5b50d76d9211
* gtkutil.c (xg_resize_widgets): Don't call xg_frame_cleared.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50272
diff
changeset
|
1439 xg_separator_p (char *label) |
49323 | 1440 { |
50318
5b50d76d9211
* gtkutil.c (xg_resize_widgets): Don't call xg_frame_cleared.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50272
diff
changeset
|
1441 if (! label) return 0; |
5b50d76d9211
* gtkutil.c (xg_resize_widgets): Don't call xg_frame_cleared.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50272
diff
changeset
|
1442 else if (strlen (label) > 3 |
5b50d76d9211
* gtkutil.c (xg_resize_widgets): Don't call xg_frame_cleared.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50272
diff
changeset
|
1443 && strncmp (label, "--", 2) == 0 |
5b50d76d9211
* gtkutil.c (xg_resize_widgets): Don't call xg_frame_cleared.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50272
diff
changeset
|
1444 && label[2] != '-') |
5b50d76d9211
* gtkutil.c (xg_resize_widgets): Don't call xg_frame_cleared.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50272
diff
changeset
|
1445 { |
5b50d76d9211
* gtkutil.c (xg_resize_widgets): Don't call xg_frame_cleared.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50272
diff
changeset
|
1446 static char* separator_names[] = { |
5b50d76d9211
* gtkutil.c (xg_resize_widgets): Don't call xg_frame_cleared.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50272
diff
changeset
|
1447 "space", |
5b50d76d9211
* gtkutil.c (xg_resize_widgets): Don't call xg_frame_cleared.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50272
diff
changeset
|
1448 "no-line", |
5b50d76d9211
* gtkutil.c (xg_resize_widgets): Don't call xg_frame_cleared.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50272
diff
changeset
|
1449 "single-line", |
5b50d76d9211
* gtkutil.c (xg_resize_widgets): Don't call xg_frame_cleared.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50272
diff
changeset
|
1450 "double-line", |
5b50d76d9211
* gtkutil.c (xg_resize_widgets): Don't call xg_frame_cleared.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50272
diff
changeset
|
1451 "single-dashed-line", |
5b50d76d9211
* gtkutil.c (xg_resize_widgets): Don't call xg_frame_cleared.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50272
diff
changeset
|
1452 "double-dashed-line", |
5b50d76d9211
* gtkutil.c (xg_resize_widgets): Don't call xg_frame_cleared.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50272
diff
changeset
|
1453 "shadow-etched-in", |
5b50d76d9211
* gtkutil.c (xg_resize_widgets): Don't call xg_frame_cleared.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50272
diff
changeset
|
1454 "shadow-etched-out", |
5b50d76d9211
* gtkutil.c (xg_resize_widgets): Don't call xg_frame_cleared.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50272
diff
changeset
|
1455 "shadow-etched-in-dash", |
5b50d76d9211
* gtkutil.c (xg_resize_widgets): Don't call xg_frame_cleared.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50272
diff
changeset
|
1456 "shadow-etched-out-dash", |
5b50d76d9211
* gtkutil.c (xg_resize_widgets): Don't call xg_frame_cleared.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50272
diff
changeset
|
1457 "shadow-double-etched-in", |
5b50d76d9211
* gtkutil.c (xg_resize_widgets): Don't call xg_frame_cleared.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50272
diff
changeset
|
1458 "shadow-double-etched-out", |
5b50d76d9211
* gtkutil.c (xg_resize_widgets): Don't call xg_frame_cleared.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50272
diff
changeset
|
1459 "shadow-double-etched-in-dash", |
5b50d76d9211
* gtkutil.c (xg_resize_widgets): Don't call xg_frame_cleared.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50272
diff
changeset
|
1460 "shadow-double-etched-out-dash", |
5b50d76d9211
* gtkutil.c (xg_resize_widgets): Don't call xg_frame_cleared.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50272
diff
changeset
|
1461 0, |
5b50d76d9211
* gtkutil.c (xg_resize_widgets): Don't call xg_frame_cleared.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50272
diff
changeset
|
1462 }; |
5b50d76d9211
* gtkutil.c (xg_resize_widgets): Don't call xg_frame_cleared.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50272
diff
changeset
|
1463 |
5b50d76d9211
* gtkutil.c (xg_resize_widgets): Don't call xg_frame_cleared.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50272
diff
changeset
|
1464 int i; |
5b50d76d9211
* gtkutil.c (xg_resize_widgets): Don't call xg_frame_cleared.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50272
diff
changeset
|
1465 |
5b50d76d9211
* gtkutil.c (xg_resize_widgets): Don't call xg_frame_cleared.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50272
diff
changeset
|
1466 label += 2; |
5b50d76d9211
* gtkutil.c (xg_resize_widgets): Don't call xg_frame_cleared.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50272
diff
changeset
|
1467 for (i = 0; separator_names[i]; ++i) |
5b50d76d9211
* gtkutil.c (xg_resize_widgets): Don't call xg_frame_cleared.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50272
diff
changeset
|
1468 if (strcmp (label, separator_names[i]) == 0) |
5b50d76d9211
* gtkutil.c (xg_resize_widgets): Don't call xg_frame_cleared.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50272
diff
changeset
|
1469 return 1; |
5b50d76d9211
* gtkutil.c (xg_resize_widgets): Don't call xg_frame_cleared.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50272
diff
changeset
|
1470 } |
5b50d76d9211
* gtkutil.c (xg_resize_widgets): Don't call xg_frame_cleared.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50272
diff
changeset
|
1471 else |
5b50d76d9211
* gtkutil.c (xg_resize_widgets): Don't call xg_frame_cleared.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50272
diff
changeset
|
1472 { |
5b50d76d9211
* gtkutil.c (xg_resize_widgets): Don't call xg_frame_cleared.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50272
diff
changeset
|
1473 /* Old-style separator, maybe. It's a separator if it contains |
5b50d76d9211
* gtkutil.c (xg_resize_widgets): Don't call xg_frame_cleared.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50272
diff
changeset
|
1474 only dashes. */ |
5b50d76d9211
* gtkutil.c (xg_resize_widgets): Don't call xg_frame_cleared.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50272
diff
changeset
|
1475 while (*label == '-') |
5b50d76d9211
* gtkutil.c (xg_resize_widgets): Don't call xg_frame_cleared.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50272
diff
changeset
|
1476 ++label; |
5b50d76d9211
* gtkutil.c (xg_resize_widgets): Don't call xg_frame_cleared.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50272
diff
changeset
|
1477 if (*label == 0) return 1; |
5b50d76d9211
* gtkutil.c (xg_resize_widgets): Don't call xg_frame_cleared.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50272
diff
changeset
|
1478 } |
5b50d76d9211
* gtkutil.c (xg_resize_widgets): Don't call xg_frame_cleared.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50272
diff
changeset
|
1479 |
5b50d76d9211
* gtkutil.c (xg_resize_widgets): Don't call xg_frame_cleared.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50272
diff
changeset
|
1480 return 0; |
49323 | 1481 } |
1482 | |
52981
54482f5ea7be
Remove tear off capability for GTK popup menus.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52401
diff
changeset
|
1483 static int xg_detached_menus; |
54482f5ea7be
Remove tear off capability for GTK popup menus.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52401
diff
changeset
|
1484 |
54482f5ea7be
Remove tear off capability for GTK popup menus.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52401
diff
changeset
|
1485 /* Returns non-zero if there are detached menus. */ |
54482f5ea7be
Remove tear off capability for GTK popup menus.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52401
diff
changeset
|
1486 int |
54482f5ea7be
Remove tear off capability for GTK popup menus.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52401
diff
changeset
|
1487 xg_have_tear_offs () |
54482f5ea7be
Remove tear off capability for GTK popup menus.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52401
diff
changeset
|
1488 { |
54482f5ea7be
Remove tear off capability for GTK popup menus.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52401
diff
changeset
|
1489 return xg_detached_menus > 0; |
54482f5ea7be
Remove tear off capability for GTK popup menus.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52401
diff
changeset
|
1490 } |
49323 | 1491 |
1492 /* Callback invoked when a detached menu window is removed. Here we | |
52981
54482f5ea7be
Remove tear off capability for GTK popup menus.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52401
diff
changeset
|
1493 decrease the xg_detached_menus count. |
49323 | 1494 WIDGET is the top level window that is removed (the parent of the menu). |
52981
54482f5ea7be
Remove tear off capability for GTK popup menus.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52401
diff
changeset
|
1495 CLIENT_DATA is not used. */ |
54482f5ea7be
Remove tear off capability for GTK popup menus.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52401
diff
changeset
|
1496 static void |
54482f5ea7be
Remove tear off capability for GTK popup menus.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52401
diff
changeset
|
1497 tearoff_remove (widget, client_data) |
49323 | 1498 GtkWidget *widget; |
1499 gpointer client_data; | |
1500 { | |
52981
54482f5ea7be
Remove tear off capability for GTK popup menus.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52401
diff
changeset
|
1501 if (xg_detached_menus > 0) --xg_detached_menus; |
49323 | 1502 } |
1503 | |
52981
54482f5ea7be
Remove tear off capability for GTK popup menus.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52401
diff
changeset
|
1504 /* Callback invoked when a menu is detached. It increases the |
54482f5ea7be
Remove tear off capability for GTK popup menus.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52401
diff
changeset
|
1505 xg_detached_menus count. |
49323 | 1506 WIDGET is the GtkTearoffMenuItem. |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
1507 CLIENT_DATA is not used. */ |
49323 | 1508 static void |
1509 tearoff_activate (widget, client_data) | |
1510 GtkWidget *widget; | |
1511 gpointer client_data; | |
1512 { | |
1513 GtkWidget *menu = gtk_widget_get_parent (widget); | |
52981
54482f5ea7be
Remove tear off capability for GTK popup menus.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52401
diff
changeset
|
1514 if (gtk_menu_get_tearoff_state (GTK_MENU (menu))) |
54482f5ea7be
Remove tear off capability for GTK popup menus.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52401
diff
changeset
|
1515 { |
54482f5ea7be
Remove tear off capability for GTK popup menus.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52401
diff
changeset
|
1516 ++xg_detached_menus; |
54482f5ea7be
Remove tear off capability for GTK popup menus.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52401
diff
changeset
|
1517 g_signal_connect (G_OBJECT (gtk_widget_get_toplevel (widget)), |
54482f5ea7be
Remove tear off capability for GTK popup menus.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52401
diff
changeset
|
1518 "destroy", |
54482f5ea7be
Remove tear off capability for GTK popup menus.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52401
diff
changeset
|
1519 G_CALLBACK (tearoff_remove), 0); |
54482f5ea7be
Remove tear off capability for GTK popup menus.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52401
diff
changeset
|
1520 } |
49323 | 1521 } |
1522 | |
1523 | |
1524 /* Create a menu item widget, and connect the callbacks. | |
1525 ITEM decribes the menu item. | |
1526 F is the frame the created menu belongs to. | |
1527 SELECT_CB is the callback to use when a menu item is selected. | |
1528 HIGHLIGHT_CB is the callback to call when entering/leaving menu items. | |
1529 CL_DATA points to the callback data to be used for this menu. | |
1530 GROUP is an in/out parameter. If the menu item to be created is not | |
1531 part of any radio menu group, *GROUP contains NULL on entry and exit. | |
1532 If the menu item to be created is part of a radio menu group, on entry | |
1533 *GROUP contains the group to use, or NULL if this is the first item | |
1534 in the group. On exit, *GROUP contains the radio item group. | |
1535 | |
1536 Returns the created GtkWidget. */ | |
1537 static GtkWidget * | |
1538 xg_create_one_menuitem (item, f, select_cb, highlight_cb, cl_data, group) | |
1539 widget_value *item; | |
1540 FRAME_PTR f; | |
1541 GCallback select_cb; | |
1542 GCallback highlight_cb; | |
1543 xg_menu_cb_data *cl_data; | |
1544 GSList **group; | |
1545 { | |
1546 char *utf8_label; | |
1547 char *utf8_key; | |
1548 GtkWidget *w; | |
1549 xg_menu_item_cb_data *cb_data; | |
1550 | |
1551 utf8_label = get_utf8_string (item->name); | |
1552 utf8_key = get_utf8_string (item->key); | |
1553 | |
1554 w = make_menu_item (utf8_label, utf8_key, item, group); | |
1555 | |
1556 if (utf8_label && utf8_label != item->name) g_free (utf8_label); | |
1557 if (utf8_key && utf8_key != item->key) g_free (utf8_key); | |
1558 | |
1559 cb_data = xmalloc (sizeof (xg_menu_item_cb_data)); | |
1560 | |
1561 xg_list_insert (&xg_menu_item_cb_list, &cb_data->ptrs); | |
1562 | |
1563 cb_data->unhighlight_id = cb_data->highlight_id = cb_data->select_id = 0; | |
1564 cb_data->help = item->help; | |
1565 cb_data->cl_data = cl_data; | |
1566 cb_data->call_data = item->call_data; | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
1567 |
49323 | 1568 g_signal_connect (G_OBJECT (w), |
1569 "destroy", | |
1570 G_CALLBACK (menuitem_destroy_callback), | |
1571 cb_data); | |
1572 | |
1573 /* Put cb_data in widget, so we can get at it when modifying menubar */ | |
1574 g_object_set_data (G_OBJECT (w), XG_ITEM_DATA, cb_data); | |
1575 | |
1576 /* final item, not a submenu */ | |
1577 if (item->call_data && ! item->contents) | |
1578 { | |
1579 if (select_cb) | |
1580 cb_data->select_id | |
1581 = g_signal_connect (G_OBJECT (w), "activate", select_cb, cb_data); | |
1582 } | |
1583 | |
1584 if (! NILP (item->help) && highlight_cb) | |
1585 { | |
1586 /* We use enter/leave notify instead of select/deselect because | |
1587 select/deselect doesn't go well with detached menus. */ | |
1588 cb_data->highlight_id | |
1589 = g_signal_connect (G_OBJECT (w), | |
1590 "enter-notify-event", | |
1591 G_CALLBACK (menuitem_highlight_callback), | |
1592 cb_data); | |
1593 cb_data->unhighlight_id | |
1594 = g_signal_connect (G_OBJECT (w), | |
1595 "leave-notify-event", | |
1596 G_CALLBACK (menuitem_highlight_callback), | |
1597 cb_data); | |
1598 } | |
1599 | |
1600 return w; | |
1601 } | |
1602 | |
50112
50df9e41f1a3
Add prototype for create_menus.
Andreas Schwab <schwab@suse.de>
parents:
50108
diff
changeset
|
1603 static GtkWidget *create_menus P_ ((widget_value *, FRAME_PTR, GCallback, |
50df9e41f1a3
Add prototype for create_menus.
Andreas Schwab <schwab@suse.de>
parents:
50108
diff
changeset
|
1604 GCallback, GCallback, int, int, int, |
50df9e41f1a3
Add prototype for create_menus.
Andreas Schwab <schwab@suse.de>
parents:
50108
diff
changeset
|
1605 GtkWidget *, xg_menu_cb_data *, char *)); |
50df9e41f1a3
Add prototype for create_menus.
Andreas Schwab <schwab@suse.de>
parents:
50108
diff
changeset
|
1606 |
49323 | 1607 /* Create a full menu tree specified by DATA. |
1608 F is the frame the created menu belongs to. | |
1609 SELECT_CB is the callback to use when a menu item is selected. | |
1610 DEACTIVATE_CB is the callback to use when a sub menu is not shown anymore. | |
1611 HIGHLIGHT_CB is the callback to call when entering/leaving menu items. | |
1612 POP_UP_P is non-zero if we shall create a popup menu. | |
1613 MENU_BAR_P is non-zero if we shall create a menu bar. | |
1614 ADD_TEAROFF_P is non-zero if we shall add a teroff menu item. Ignored | |
1615 if MENU_BAR_P is non-zero. | |
1616 TOPMENU is the topmost GtkWidget that others shall be placed under. | |
1617 It may be NULL, in that case we create the appropriate widget | |
1618 (menu bar or menu item depending on POP_UP_P and MENU_BAR_P) | |
1619 CL_DATA is the callback data we shall use for this menu, or NULL | |
1620 if we haven't set the first callback yet. | |
1621 NAME is the name to give to the top level menu if this function | |
1622 creates it. May be NULL to not set any name. | |
1623 | |
1624 Returns the top level GtkWidget. This is TOPLEVEL if TOPLEVEL is | |
1625 not NULL. | |
1626 | |
1627 This function calls itself to create submenus. */ | |
1628 | |
1629 static GtkWidget * | |
1630 create_menus (data, f, select_cb, deactivate_cb, highlight_cb, | |
1631 pop_up_p, menu_bar_p, add_tearoff_p, topmenu, cl_data, name) | |
1632 widget_value *data; | |
1633 FRAME_PTR f; | |
1634 GCallback select_cb; | |
1635 GCallback deactivate_cb; | |
1636 GCallback highlight_cb; | |
1637 int pop_up_p; | |
1638 int menu_bar_p; | |
1639 int add_tearoff_p; | |
1640 GtkWidget *topmenu; | |
1641 xg_menu_cb_data *cl_data; | |
1642 char *name; | |
1643 { | |
1644 widget_value *item; | |
1645 GtkWidget *wmenu = topmenu; | |
1646 GSList *group = NULL; | |
1647 | |
1648 if (! topmenu) | |
1649 { | |
53069
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
1650 if (! menu_bar_p) |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
1651 { |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
1652 wmenu = gtk_menu_new (); |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
1653 xg_set_screen (wmenu, f); |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
1654 } |
49323 | 1655 else wmenu = gtk_menu_bar_new (); |
1656 | |
1657 /* Put cl_data on the top menu for easier access. */ | |
1658 cl_data = make_cl_data (cl_data, f, highlight_cb); | |
1659 g_object_set_data (G_OBJECT (wmenu), XG_FRAME_DATA, (gpointer)cl_data); | |
1660 g_signal_connect (G_OBJECT (wmenu), "destroy", | |
1661 G_CALLBACK (menu_destroy_callback), cl_data); | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
1662 |
49323 | 1663 if (name) |
1664 gtk_widget_set_name (wmenu, name); | |
1665 | |
1666 if (deactivate_cb) | |
1667 g_signal_connect (G_OBJECT (wmenu), | |
1668 "deactivate", deactivate_cb, 0); | |
1669 | |
1670 g_signal_connect (G_OBJECT (wmenu), | |
1671 "grab-notify", G_CALLBACK (menu_grab_callback), 0); | |
1672 } | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
1673 |
49323 | 1674 if (! menu_bar_p && add_tearoff_p) |
1675 { | |
1676 GtkWidget *tearoff = gtk_tearoff_menu_item_new (); | |
1677 gtk_menu_shell_append (GTK_MENU_SHELL (wmenu), tearoff); | |
1678 | |
1679 g_signal_connect (G_OBJECT (tearoff), "activate", | |
1680 G_CALLBACK (tearoff_activate), 0); | |
1681 } | |
1682 | |
1683 for (item = data; item; item = item->next) | |
1684 { | |
1685 GtkWidget *w; | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
1686 |
49323 | 1687 if (pop_up_p && !item->contents && !item->call_data |
1688 && !xg_separator_p (item->name)) | |
1689 { | |
1690 char *utf8_label; | |
1691 /* A title for a popup. We do the same as GTK does when | |
1692 creating titles, but it does not look good. */ | |
1693 group = NULL; | |
1694 utf8_label = get_utf8_string (item->name); | |
1695 | |
1696 gtk_menu_set_title (GTK_MENU (wmenu), utf8_label); | |
50778
f30e6f029d65
* gtkutil.c (create_dialog, make_widget_for_menu_item)
Jan Djärv <jan.h.d@swipnet.se>
parents:
50521
diff
changeset
|
1697 w = gtk_menu_item_new_with_label (utf8_label); |
49323 | 1698 gtk_widget_set_sensitive (w, FALSE); |
1699 if (utf8_label && utf8_label != item->name) g_free (utf8_label); | |
1700 } | |
1701 else if (xg_separator_p (item->name)) | |
1702 { | |
1703 group = NULL; | |
1704 /* GTK only have one separator type. */ | |
1705 w = gtk_separator_menu_item_new (); | |
1706 } | |
1707 else | |
1708 { | |
1709 w = xg_create_one_menuitem (item, | |
1710 f, | |
1711 item->contents ? 0 : select_cb, | |
1712 highlight_cb, | |
1713 cl_data, | |
1714 &group); | |
1715 | |
1716 if (item->contents) | |
1717 { | |
1718 GtkWidget *submenu = create_menus (item->contents, | |
1719 f, | |
1720 select_cb, | |
1721 deactivate_cb, | |
1722 highlight_cb, | |
1723 0, | |
1724 0, | |
52981
54482f5ea7be
Remove tear off capability for GTK popup menus.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52401
diff
changeset
|
1725 add_tearoff_p, |
49323 | 1726 0, |
1727 cl_data, | |
1728 0); | |
1729 gtk_menu_item_set_submenu (GTK_MENU_ITEM (w), submenu); | |
1730 } | |
1731 } | |
1732 | |
1733 gtk_menu_shell_append (GTK_MENU_SHELL (wmenu), w); | |
1734 gtk_widget_set_name (w, MENU_ITEM_NAME); | |
1735 } | |
1736 | |
1737 return wmenu; | |
1738 } | |
1739 | |
1740 /* Create a menubar, popup menu or dialog, depending on the TYPE argument. | |
1741 TYPE can be "menubar", "popup" for popup menu, or "dialog" for a dialog | |
1742 with some text and buttons. | |
1743 F is the frame the created item belongs to. | |
1744 NAME is the name to use for the top widget. | |
1745 VAL is a widget_value structure describing items to be created. | |
1746 SELECT_CB is the callback to use when a menu item is selected or | |
1747 a dialog button is pressed. | |
1748 DEACTIVATE_CB is the callback to use when an item is deactivated. | |
1749 For a menu, when a sub menu is not shown anymore, for a dialog it is | |
1750 called when the dialog is popped down. | |
1751 HIGHLIGHT_CB is the callback to call when entering/leaving menu items. | |
1752 | |
1753 Returns the widget created. */ | |
1754 GtkWidget * | |
1755 xg_create_widget (type, name, f, val, | |
1756 select_cb, deactivate_cb, highlight_cb) | |
1757 char *type; | |
1758 char *name; | |
1759 FRAME_PTR f; | |
1760 widget_value *val; | |
1761 GCallback select_cb; | |
1762 GCallback deactivate_cb; | |
1763 GCallback highlight_cb; | |
1764 { | |
1765 GtkWidget *w = 0; | |
52981
54482f5ea7be
Remove tear off capability for GTK popup menus.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52401
diff
changeset
|
1766 int menu_bar_p = strcmp (type, "menubar") == 0; |
54482f5ea7be
Remove tear off capability for GTK popup menus.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52401
diff
changeset
|
1767 int pop_up_p = strcmp (type, "popup") == 0; |
54482f5ea7be
Remove tear off capability for GTK popup menus.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52401
diff
changeset
|
1768 |
49323 | 1769 if (strcmp (type, "dialog") == 0) |
1770 { | |
1771 w = create_dialog (val, select_cb, deactivate_cb); | |
53069
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
1772 xg_set_screen (w, f); |
49323 | 1773 gtk_window_set_transient_for (GTK_WINDOW (w), |
1774 GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f))); | |
1775 gtk_window_set_destroy_with_parent (GTK_WINDOW (w), TRUE); | |
53069
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
1776 gtk_widget_set_name (w, "emacs-dialog"); |
49323 | 1777 } |
52981
54482f5ea7be
Remove tear off capability for GTK popup menus.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52401
diff
changeset
|
1778 else if (menu_bar_p || pop_up_p) |
49323 | 1779 { |
1780 w = create_menus (val->contents, | |
1781 f, | |
1782 select_cb, | |
1783 deactivate_cb, | |
1784 highlight_cb, | |
52981
54482f5ea7be
Remove tear off capability for GTK popup menus.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52401
diff
changeset
|
1785 pop_up_p, |
54482f5ea7be
Remove tear off capability for GTK popup menus.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52401
diff
changeset
|
1786 menu_bar_p, |
54482f5ea7be
Remove tear off capability for GTK popup menus.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52401
diff
changeset
|
1787 menu_bar_p, |
49323 | 1788 0, |
1789 0, | |
1790 name); | |
1791 | |
1792 /* Set the cursor to an arrow for popup menus when they are mapped. | |
1793 This is done by default for menu bar menus. */ | |
52981
54482f5ea7be
Remove tear off capability for GTK popup menus.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52401
diff
changeset
|
1794 if (pop_up_p) |
49323 | 1795 { |
1796 /* Must realize so the GdkWindow inside the widget is created. */ | |
1797 gtk_widget_realize (w); | |
53069
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
1798 xg_set_cursor (w, FRAME_X_DISPLAY_INFO (f)->xg_cursor); |
49323 | 1799 } |
1800 } | |
1801 else | |
1802 { | |
1803 fprintf (stderr, "bad type in xg_create_widget: %s, doing nothing\n", | |
1804 type); | |
1805 } | |
1806 | |
1807 return w; | |
1808 } | |
1809 | |
49488
da6abcaef15c
gtkutil.c: Check for NULL string before calling strcmp or strlen.
Jan Djärv <jan.h.d@swipnet.se>
parents:
49468
diff
changeset
|
1810 /* Return the label for menu item WITEM. */ |
49323 | 1811 static const char * |
1812 xg_get_menu_item_label (witem) | |
1813 GtkMenuItem *witem; | |
1814 { | |
1815 GtkLabel *wlabel = GTK_LABEL (gtk_bin_get_child (GTK_BIN (witem))); | |
1816 return gtk_label_get_label (wlabel); | |
1817 } | |
1818 | |
49488
da6abcaef15c
gtkutil.c: Check for NULL string before calling strcmp or strlen.
Jan Djärv <jan.h.d@swipnet.se>
parents:
49468
diff
changeset
|
1819 /* Return non-zero if the menu item WITEM has the text LABEL. */ |
49323 | 1820 static int |
1821 xg_item_label_same_p (witem, label) | |
1822 GtkMenuItem *witem; | |
1823 char *label; | |
1824 { | |
49488
da6abcaef15c
gtkutil.c: Check for NULL string before calling strcmp or strlen.
Jan Djärv <jan.h.d@swipnet.se>
parents:
49468
diff
changeset
|
1825 int is_same = 0; |
49323 | 1826 char *utf8_label = get_utf8_string (label); |
49488
da6abcaef15c
gtkutil.c: Check for NULL string before calling strcmp or strlen.
Jan Djärv <jan.h.d@swipnet.se>
parents:
49468
diff
changeset
|
1827 const char *old_label = witem ? xg_get_menu_item_label (witem) : 0; |
da6abcaef15c
gtkutil.c: Check for NULL string before calling strcmp or strlen.
Jan Djärv <jan.h.d@swipnet.se>
parents:
49468
diff
changeset
|
1828 |
da6abcaef15c
gtkutil.c: Check for NULL string before calling strcmp or strlen.
Jan Djärv <jan.h.d@swipnet.se>
parents:
49468
diff
changeset
|
1829 if (! old_label && ! utf8_label) |
da6abcaef15c
gtkutil.c: Check for NULL string before calling strcmp or strlen.
Jan Djärv <jan.h.d@swipnet.se>
parents:
49468
diff
changeset
|
1830 is_same = 1; |
da6abcaef15c
gtkutil.c: Check for NULL string before calling strcmp or strlen.
Jan Djärv <jan.h.d@swipnet.se>
parents:
49468
diff
changeset
|
1831 else if (old_label && utf8_label) |
da6abcaef15c
gtkutil.c: Check for NULL string before calling strcmp or strlen.
Jan Djärv <jan.h.d@swipnet.se>
parents:
49468
diff
changeset
|
1832 is_same = strcmp (utf8_label, old_label) == 0; |
da6abcaef15c
gtkutil.c: Check for NULL string before calling strcmp or strlen.
Jan Djärv <jan.h.d@swipnet.se>
parents:
49468
diff
changeset
|
1833 |
da6abcaef15c
gtkutil.c: Check for NULL string before calling strcmp or strlen.
Jan Djärv <jan.h.d@swipnet.se>
parents:
49468
diff
changeset
|
1834 if (utf8_label && utf8_label != label) g_free (utf8_label); |
49323 | 1835 |
1836 return is_same; | |
1837 } | |
1838 | |
1839 /* Remove widgets in LIST from container WCONT. */ | |
1840 static void | |
1841 remove_from_container (wcont, list) | |
1842 GtkWidget *wcont; | |
1843 GList *list; | |
1844 { | |
1845 GList *iter; | |
1846 | |
49572 | 1847 for (iter = list; iter; iter = g_list_next (iter)) |
49323 | 1848 { |
1849 GtkWidget *w = GTK_WIDGET (iter->data); | |
1850 | |
1851 /* Add a ref to w so we can explicitly destroy it later. */ | |
1852 gtk_widget_ref (w); | |
1853 gtk_container_remove (GTK_CONTAINER (wcont), w); | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
1854 |
49323 | 1855 /* If there is a menu under this widget that has been detached, |
1856 there is a reference to it, and just removing w from the | |
1857 container does not destroy the submenu. By explicitly | |
1858 destroying w we make sure the submenu is destroyed, thus | |
1859 removing the detached window also if there was one. */ | |
1860 gtk_widget_destroy (w); | |
1861 } | |
1862 } | |
1863 | |
1864 /* Update the top level names in MENUBAR (i.e. not submenus). | |
1865 F is the frame the menu bar belongs to. | |
49572 | 1866 *LIST is a list with the current menu bar names (menu item widgets). |
1867 ITER is the item within *LIST that shall be updated. | |
1868 POS is the numerical position, starting at 0, of ITER in *LIST. | |
49323 | 1869 VAL describes what the menu bar shall look like after the update. |
1870 SELECT_CB is the callback to use when a menu item is selected. | |
1871 HIGHLIGHT_CB is the callback to call when entering/leaving menu items. | |
49572 | 1872 CL_DATA points to the callback data to be used for this menu bar. |
49323 | 1873 |
1874 This function calls itself to walk through the menu bar names. */ | |
1875 static void | |
49572 | 1876 xg_update_menubar (menubar, f, list, iter, pos, val, |
1877 select_cb, highlight_cb, cl_data) | |
49323 | 1878 GtkWidget *menubar; |
1879 FRAME_PTR f; | |
49572 | 1880 GList **list; |
1881 GList *iter; | |
1882 int pos; | |
49323 | 1883 widget_value *val; |
1884 GCallback select_cb; | |
1885 GCallback highlight_cb; | |
1886 xg_menu_cb_data *cl_data; | |
1887 { | |
49572 | 1888 if (! iter && ! val) |
49323 | 1889 return; |
49572 | 1890 else if (iter && ! val) |
49323 | 1891 { |
49572 | 1892 /* Item(s) have been removed. Remove all remaining items. */ |
1893 remove_from_container (menubar, iter); | |
49323 | 1894 |
1895 /* All updated. */ | |
1896 val = 0; | |
49572 | 1897 iter = 0; |
49323 | 1898 } |
49572 | 1899 else if (! iter && val) |
49323 | 1900 { |
1901 /* Item(s) added. Add all new items in one call. */ | |
1902 create_menus (val, f, select_cb, 0, highlight_cb, | |
1903 0, 1, 0, menubar, cl_data, 0); | |
1904 | |
1905 /* All updated. */ | |
1906 val = 0; | |
49572 | 1907 iter = 0; |
49323 | 1908 } |
49572 | 1909 /* Below this neither iter or val is NULL */ |
1910 else if (xg_item_label_same_p (GTK_MENU_ITEM (iter->data), val->name)) | |
49323 | 1911 { |
1912 /* This item is still the same, check next item. */ | |
1913 val = val->next; | |
49572 | 1914 iter = g_list_next (iter); |
1915 ++pos; | |
49323 | 1916 } |
1917 else /* This item is changed. */ | |
1918 { | |
49572 | 1919 GtkMenuItem *witem = GTK_MENU_ITEM (iter->data); |
49323 | 1920 GtkMenuItem *witem2 = 0; |
1921 int val_in_menubar = 0; | |
49572 | 1922 int iter_in_new_menubar = 0; |
1923 GList *iter2; | |
49323 | 1924 widget_value *cur; |
1925 | |
1926 /* See if the changed entry (val) is present later in the menu bar */ | |
49572 | 1927 for (iter2 = iter; |
1928 iter2 && ! val_in_menubar; | |
1929 iter2 = g_list_next (iter2)) | |
49323 | 1930 { |
49572 | 1931 witem2 = GTK_MENU_ITEM (iter2->data); |
49323 | 1932 val_in_menubar = xg_item_label_same_p (witem2, val->name); |
1933 } | |
1934 | |
49572 | 1935 /* See if the current entry (iter) is present later in the |
49323 | 1936 specification for the new menu bar. */ |
49572 | 1937 for (cur = val; cur && ! iter_in_new_menubar; cur = cur->next) |
1938 iter_in_new_menubar = xg_item_label_same_p (witem, cur->name); | |
1939 | |
1940 if (val_in_menubar && ! iter_in_new_menubar) | |
49323 | 1941 { |
49572 | 1942 int nr = pos; |
1943 | |
49323 | 1944 /* This corresponds to: |
1945 Current: A B C | |
1946 New: A C | |
1947 Remove B. */ | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
1948 |
49323 | 1949 gtk_widget_ref (GTK_WIDGET (witem)); |
1950 gtk_container_remove (GTK_CONTAINER (menubar), GTK_WIDGET (witem)); | |
1951 gtk_widget_destroy (GTK_WIDGET (witem)); | |
1952 | |
1953 /* Must get new list since the old changed. */ | |
49572 | 1954 g_list_free (*list); |
1955 *list = iter = gtk_container_get_children (GTK_CONTAINER (menubar)); | |
1956 while (nr-- > 0) iter = g_list_next (iter); | |
49323 | 1957 } |
49572 | 1958 else if (! val_in_menubar && ! iter_in_new_menubar) |
49323 | 1959 { |
1960 /* This corresponds to: | |
1961 Current: A B C | |
1962 New: A X C | |
1963 Rename B to X. This might seem to be a strange thing to do, | |
1964 since if there is a menu under B it will be totally wrong for X. | |
1965 But consider editing a C file. Then there is a C-mode menu | |
1966 (corresponds to B above). | |
1967 If then doing C-x C-f the minibuf menu (X above) replaces the | |
1968 C-mode menu. When returning from the minibuffer, we get | |
1969 back the C-mode menu. Thus we do: | |
1970 Rename B to X (C-mode to minibuf menu) | |
1971 Rename X to B (minibuf to C-mode menu). | |
1972 If the X menu hasn't been invoked, the menu under B | |
1973 is up to date when leaving the minibuffer. */ | |
1974 GtkLabel *wlabel = GTK_LABEL (gtk_bin_get_child (GTK_BIN (witem))); | |
1975 char *utf8_label = get_utf8_string (val->name); | |
52981
54482f5ea7be
Remove tear off capability for GTK popup menus.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52401
diff
changeset
|
1976 GtkWidget *submenu = gtk_menu_item_get_submenu (witem); |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
1977 |
50778
f30e6f029d65
* gtkutil.c (create_dialog, make_widget_for_menu_item)
Jan Djärv <jan.h.d@swipnet.se>
parents:
50521
diff
changeset
|
1978 gtk_label_set_text (wlabel, utf8_label); |
49323 | 1979 |
52981
54482f5ea7be
Remove tear off capability for GTK popup menus.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52401
diff
changeset
|
1980 /* If this item has a submenu that has been detached, change |
54482f5ea7be
Remove tear off capability for GTK popup menus.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52401
diff
changeset
|
1981 the title in the WM decorations also. */ |
54482f5ea7be
Remove tear off capability for GTK popup menus.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52401
diff
changeset
|
1982 if (submenu && gtk_menu_get_tearoff_state (GTK_MENU (submenu))) |
54482f5ea7be
Remove tear off capability for GTK popup menus.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52401
diff
changeset
|
1983 /* Set the title of the detached window. */ |
54482f5ea7be
Remove tear off capability for GTK popup menus.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52401
diff
changeset
|
1984 gtk_menu_set_title (GTK_MENU (submenu), utf8_label); |
54482f5ea7be
Remove tear off capability for GTK popup menus.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52401
diff
changeset
|
1985 |
49572 | 1986 iter = g_list_next (iter); |
49323 | 1987 val = val->next; |
49572 | 1988 ++pos; |
49323 | 1989 } |
49572 | 1990 else if (! val_in_menubar && iter_in_new_menubar) |
49323 | 1991 { |
1992 /* This corresponds to: | |
1993 Current: A B C | |
1994 New: A X B C | |
1995 Insert X. */ | |
1996 | |
49572 | 1997 int nr = pos; |
49323 | 1998 GList *group = 0; |
1999 GtkWidget *w = xg_create_one_menuitem (val, | |
2000 f, | |
2001 select_cb, | |
2002 highlight_cb, | |
2003 cl_data, | |
2004 &group); | |
2005 | |
2006 gtk_widget_set_name (w, MENU_ITEM_NAME); | |
2007 gtk_menu_shell_insert (GTK_MENU_SHELL (menubar), w, pos); | |
2008 | |
49572 | 2009 g_list_free (*list); |
2010 *list = iter = gtk_container_get_children (GTK_CONTAINER (menubar)); | |
2011 while (nr-- > 0) iter = g_list_next (iter); | |
2012 iter = g_list_next (iter); | |
49323 | 2013 val = val->next; |
49572 | 2014 ++pos; |
49323 | 2015 } |
49572 | 2016 else /* if (val_in_menubar && iter_in_new_menubar) */ |
49323 | 2017 { |
49572 | 2018 int nr = pos; |
49323 | 2019 /* This corresponds to: |
2020 Current: A B C | |
2021 New: A C B | |
2022 Move C before B */ | |
2023 | |
2024 gtk_widget_ref (GTK_WIDGET (witem2)); | |
2025 gtk_container_remove (GTK_CONTAINER (menubar), GTK_WIDGET (witem2)); | |
2026 gtk_menu_shell_insert (GTK_MENU_SHELL (menubar), | |
2027 GTK_WIDGET (witem2), pos); | |
2028 gtk_widget_unref (GTK_WIDGET (witem2)); | |
2029 | |
49572 | 2030 g_list_free (*list); |
2031 *list = iter = gtk_container_get_children (GTK_CONTAINER (menubar)); | |
2032 while (nr-- > 0) iter = g_list_next (iter); | |
49323 | 2033 val = val->next; |
49572 | 2034 ++pos; |
49323 | 2035 } |
2036 } | |
2037 | |
2038 /* Update the rest of the menu bar. */ | |
49572 | 2039 xg_update_menubar (menubar, f, list, iter, pos, val, |
2040 select_cb, highlight_cb, cl_data); | |
49323 | 2041 } |
2042 | |
2043 /* Update the menu item W so it corresponds to VAL. | |
2044 SELECT_CB is the callback to use when a menu item is selected. | |
2045 HIGHLIGHT_CB is the callback to call when entering/leaving menu items. | |
2046 CL_DATA is the data to set in the widget for menu invokation. */ | |
2047 static void | |
2048 xg_update_menu_item (val, w, select_cb, highlight_cb, cl_data) | |
2049 widget_value *val; | |
2050 GtkWidget *w; | |
2051 GCallback select_cb; | |
2052 GCallback highlight_cb; | |
2053 xg_menu_cb_data *cl_data; | |
2054 { | |
2055 GtkWidget *wchild; | |
2056 GtkLabel *wlbl = 0; | |
2057 GtkLabel *wkey = 0; | |
2058 char *utf8_label; | |
2059 char *utf8_key; | |
49488
da6abcaef15c
gtkutil.c: Check for NULL string before calling strcmp or strlen.
Jan Djärv <jan.h.d@swipnet.se>
parents:
49468
diff
changeset
|
2060 const char *old_label = 0; |
da6abcaef15c
gtkutil.c: Check for NULL string before calling strcmp or strlen.
Jan Djärv <jan.h.d@swipnet.se>
parents:
49468
diff
changeset
|
2061 const char *old_key = 0; |
49323 | 2062 xg_menu_item_cb_data *cb_data; |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
2063 |
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
2064 wchild = gtk_bin_get_child (GTK_BIN (w)); |
49323 | 2065 utf8_label = get_utf8_string (val->name); |
2066 utf8_key = get_utf8_string (val->key); | |
2067 | |
2068 /* See if W is a menu item with a key. See make_menu_item above. */ | |
2069 if (GTK_IS_HBOX (wchild)) | |
2070 { | |
2071 GList *list = gtk_container_get_children (GTK_CONTAINER (wchild)); | |
2072 | |
2073 wlbl = GTK_LABEL (list->data); | |
2074 wkey = GTK_LABEL (list->next->data); | |
49572 | 2075 g_list_free (list); |
2076 | |
49323 | 2077 if (! utf8_key) |
2078 { | |
2079 /* Remove the key and keep just the label. */ | |
2080 gtk_widget_ref (GTK_WIDGET (wlbl)); | |
2081 gtk_container_remove (GTK_CONTAINER (w), wchild); | |
2082 gtk_container_add (GTK_CONTAINER (w), GTK_WIDGET (wlbl)); | |
2083 wkey = 0; | |
2084 } | |
49572 | 2085 |
49323 | 2086 } |
2087 else /* Just a label. */ | |
2088 { | |
2089 wlbl = GTK_LABEL (wchild); | |
2090 | |
2091 /* Check if there is now a key. */ | |
2092 if (utf8_key) | |
2093 { | |
2094 GtkWidget *wtoadd = make_widget_for_menu_item (utf8_label, utf8_key); | |
2095 GList *list = gtk_container_get_children (GTK_CONTAINER (wtoadd)); | |
49572 | 2096 |
49323 | 2097 wlbl = GTK_LABEL (list->data); |
2098 wkey = GTK_LABEL (list->next->data); | |
49572 | 2099 g_list_free (list); |
49323 | 2100 |
2101 gtk_container_remove (GTK_CONTAINER (w), wchild); | |
2102 gtk_container_add (GTK_CONTAINER (w), wtoadd); | |
2103 } | |
2104 } | |
2105 | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
2106 |
49488
da6abcaef15c
gtkutil.c: Check for NULL string before calling strcmp or strlen.
Jan Djärv <jan.h.d@swipnet.se>
parents:
49468
diff
changeset
|
2107 if (wkey) old_key = gtk_label_get_label (wkey); |
da6abcaef15c
gtkutil.c: Check for NULL string before calling strcmp or strlen.
Jan Djärv <jan.h.d@swipnet.se>
parents:
49468
diff
changeset
|
2108 if (wlbl) old_label = gtk_label_get_label (wlbl); |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
2109 |
49488
da6abcaef15c
gtkutil.c: Check for NULL string before calling strcmp or strlen.
Jan Djärv <jan.h.d@swipnet.se>
parents:
49468
diff
changeset
|
2110 if (wkey && utf8_key && (! old_key || strcmp (utf8_key, old_key) != 0)) |
49323 | 2111 gtk_label_set_text (wkey, utf8_key); |
2112 | |
49488
da6abcaef15c
gtkutil.c: Check for NULL string before calling strcmp or strlen.
Jan Djärv <jan.h.d@swipnet.se>
parents:
49468
diff
changeset
|
2113 if (! old_label || strcmp (utf8_label, old_label) != 0) |
50778
f30e6f029d65
* gtkutil.c (create_dialog, make_widget_for_menu_item)
Jan Djärv <jan.h.d@swipnet.se>
parents:
50521
diff
changeset
|
2114 gtk_label_set_text (wlbl, utf8_label); |
49323 | 2115 |
49488
da6abcaef15c
gtkutil.c: Check for NULL string before calling strcmp or strlen.
Jan Djärv <jan.h.d@swipnet.se>
parents:
49468
diff
changeset
|
2116 if (utf8_key && utf8_key != val->key) g_free (utf8_key); |
da6abcaef15c
gtkutil.c: Check for NULL string before calling strcmp or strlen.
Jan Djärv <jan.h.d@swipnet.se>
parents:
49468
diff
changeset
|
2117 if (utf8_label && utf8_label != val->name) g_free (utf8_label); |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
2118 |
49323 | 2119 if (! val->enabled && GTK_WIDGET_SENSITIVE (w)) |
2120 gtk_widget_set_sensitive (w, FALSE); | |
2121 else if (val->enabled && ! GTK_WIDGET_SENSITIVE (w)) | |
2122 gtk_widget_set_sensitive (w, TRUE); | |
2123 | |
2124 cb_data = (xg_menu_item_cb_data*) g_object_get_data (G_OBJECT (w), | |
2125 XG_ITEM_DATA); | |
2126 if (cb_data) | |
2127 { | |
2128 cb_data->call_data = val->call_data; | |
2129 cb_data->help = val->help; | |
2130 cb_data->cl_data = cl_data; | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
2131 |
49323 | 2132 /* We assume the callback functions don't change. */ |
2133 if (val->call_data && ! val->contents) | |
2134 { | |
2135 /* This item shall have a select callback. */ | |
2136 if (! cb_data->select_id) | |
2137 cb_data->select_id | |
2138 = g_signal_connect (G_OBJECT (w), "activate", | |
2139 select_cb, cb_data); | |
2140 } | |
2141 else if (cb_data->select_id) | |
2142 { | |
2143 g_signal_handler_disconnect (w, cb_data->select_id); | |
2144 cb_data->select_id = 0; | |
2145 } | |
2146 | |
2147 if (NILP (cb_data->help)) | |
2148 { | |
2149 /* Shall not have help. Remove if any existed previously. */ | |
2150 if (cb_data->highlight_id) | |
2151 { | |
2152 g_signal_handler_disconnect (G_OBJECT (w), | |
2153 cb_data->highlight_id); | |
2154 cb_data->highlight_id = 0; | |
2155 } | |
2156 if (cb_data->unhighlight_id) | |
2157 { | |
2158 g_signal_handler_disconnect (G_OBJECT (w), | |
2159 cb_data->unhighlight_id); | |
2160 cb_data->unhighlight_id = 0; | |
2161 } | |
2162 } | |
2163 else if (! cb_data->highlight_id && highlight_cb) | |
2164 { | |
2165 /* Have help now, but didn't previously. Add callback. */ | |
2166 cb_data->highlight_id | |
2167 = g_signal_connect (G_OBJECT (w), | |
2168 "enter-notify-event", | |
2169 G_CALLBACK (menuitem_highlight_callback), | |
2170 cb_data); | |
2171 cb_data->unhighlight_id | |
2172 = g_signal_connect (G_OBJECT (w), | |
2173 "leave-notify-event", | |
2174 G_CALLBACK (menuitem_highlight_callback), | |
2175 cb_data); | |
2176 } | |
2177 } | |
2178 } | |
2179 | |
2180 /* Update the toggle menu item W so it corresponds to VAL. */ | |
2181 static void | |
2182 xg_update_toggle_item (val, w) | |
2183 widget_value *val; | |
2184 GtkWidget *w; | |
2185 { | |
2186 gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (w), val->selected); | |
2187 } | |
2188 | |
2189 /* Update the radio menu item W so it corresponds to VAL. */ | |
2190 static void | |
2191 xg_update_radio_item (val, w) | |
2192 widget_value *val; | |
2193 GtkWidget *w; | |
2194 { | |
2195 gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (w), val->selected); | |
2196 } | |
2197 | |
2198 /* Update the sub menu SUBMENU and all its children so it corresponds to VAL. | |
2199 SUBMENU may be NULL, in that case a new menu is created. | |
2200 F is the frame the menu bar belongs to. | |
2201 VAL describes the contents of the menu bar. | |
2202 SELECT_CB is the callback to use when a menu item is selected. | |
2203 DEACTIVATE_CB is the callback to use when a sub menu is not shown anymore. | |
2204 HIGHLIGHT_CB is the callback to call when entering/leaving menu items. | |
2205 CL_DATA is the call back data to use for any newly created items. | |
2206 | |
2207 Returns the updated submenu widget, that is SUBMENU unless SUBMENU | |
2208 was NULL. */ | |
2209 | |
2210 static GtkWidget * | |
2211 xg_update_submenu (submenu, f, val, | |
2212 select_cb, deactivate_cb, highlight_cb, cl_data) | |
2213 GtkWidget *submenu; | |
2214 FRAME_PTR f; | |
2215 widget_value *val; | |
2216 GCallback select_cb; | |
2217 GCallback deactivate_cb; | |
2218 GCallback highlight_cb; | |
2219 xg_menu_cb_data *cl_data; | |
2220 { | |
2221 GtkWidget *newsub = submenu; | |
2222 GList *list = 0; | |
2223 GList *iter; | |
2224 widget_value *cur; | |
2225 int has_tearoff_p = 0; | |
2226 GList *first_radio = 0; | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
2227 |
49323 | 2228 if (submenu) |
2229 list = gtk_container_get_children (GTK_CONTAINER (submenu)); | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
2230 |
49323 | 2231 for (cur = val, iter = list; |
2232 cur && iter; | |
2233 iter = g_list_next (iter), cur = cur->next) | |
2234 { | |
2235 GtkWidget *w = GTK_WIDGET (iter->data); | |
2236 | |
2237 /* Skip tearoff items, they have no counterpart in val. */ | |
2238 if (GTK_IS_TEAROFF_MENU_ITEM (w)) | |
2239 { | |
2240 has_tearoff_p = 1; | |
2241 iter = g_list_next (iter); | |
2242 if (iter) w = GTK_WIDGET (iter->data); | |
2243 else break; | |
2244 } | |
2245 | |
2246 /* Remember first radio button in a group. If we get a mismatch in | |
2247 a radio group we must rebuild the whole group so that the connections | |
2248 in GTK becomes correct. */ | |
2249 if (cur->button_type == BUTTON_TYPE_RADIO && ! first_radio) | |
2250 first_radio = iter; | |
2251 else if (cur->button_type != BUTTON_TYPE_RADIO | |
2252 && ! GTK_IS_RADIO_MENU_ITEM (w)) | |
2253 first_radio = 0; | |
2254 | |
2255 if (GTK_IS_SEPARATOR_MENU_ITEM (w)) | |
2256 { | |
2257 if (! xg_separator_p (cur->name)) | |
2258 break; | |
2259 } | |
2260 else if (GTK_IS_CHECK_MENU_ITEM (w)) | |
2261 { | |
2262 if (cur->button_type != BUTTON_TYPE_TOGGLE) | |
2263 break; | |
2264 xg_update_toggle_item (cur, w); | |
2265 xg_update_menu_item (cur, w, select_cb, highlight_cb, cl_data); | |
2266 } | |
2267 else if (GTK_IS_RADIO_MENU_ITEM (w)) | |
2268 { | |
2269 if (cur->button_type != BUTTON_TYPE_RADIO) | |
2270 break; | |
2271 xg_update_radio_item (cur, w); | |
2272 xg_update_menu_item (cur, w, select_cb, highlight_cb, cl_data); | |
2273 } | |
2274 else if (GTK_IS_MENU_ITEM (w)) | |
2275 { | |
2276 GtkMenuItem *witem = GTK_MENU_ITEM (w); | |
2277 GtkWidget *sub; | |
2278 | |
2279 if (cur->button_type != BUTTON_TYPE_NONE || | |
2280 xg_separator_p (cur->name)) | |
2281 break; | |
2282 | |
2283 xg_update_menu_item (cur, w, select_cb, highlight_cb, cl_data); | |
2284 | |
2285 sub = gtk_menu_item_get_submenu (witem); | |
2286 if (sub && ! cur->contents) | |
2287 { | |
2288 /* Not a submenu anymore. */ | |
2289 gtk_widget_ref (sub); | |
2290 gtk_menu_item_remove_submenu (witem); | |
2291 gtk_widget_destroy (sub); | |
2292 } | |
2293 else if (cur->contents) | |
2294 { | |
2295 GtkWidget *nsub; | |
2296 | |
2297 nsub = xg_update_submenu (sub, f, cur->contents, | |
2298 select_cb, deactivate_cb, | |
2299 highlight_cb, cl_data); | |
2300 | |
2301 /* If this item just became a submenu, we must set it. */ | |
2302 if (nsub != sub) | |
2303 gtk_menu_item_set_submenu (witem, nsub); | |
2304 } | |
2305 } | |
2306 else | |
2307 { | |
2308 /* Structural difference. Remove everything from here and down | |
2309 in SUBMENU. */ | |
2310 break; | |
2311 } | |
2312 } | |
2313 | |
2314 /* Remove widgets from first structual change. */ | |
2315 if (iter) | |
2316 { | |
2317 /* If we are adding new menu items below, we must remove from | |
2318 first radio button so that radio groups become correct. */ | |
2319 if (cur && first_radio) remove_from_container (submenu, first_radio); | |
2320 else remove_from_container (submenu, iter); | |
2321 } | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
2322 |
49323 | 2323 if (cur) |
2324 { | |
2325 /* More items added. Create them. */ | |
2326 newsub = create_menus (cur, | |
2327 f, | |
2328 select_cb, | |
2329 deactivate_cb, | |
2330 highlight_cb, | |
2331 0, | |
2332 0, | |
2333 ! has_tearoff_p, | |
2334 submenu, | |
2335 cl_data, | |
2336 0); | |
2337 } | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
2338 |
49572 | 2339 if (list) g_list_free (list); |
2340 | |
49323 | 2341 return newsub; |
2342 } | |
2343 | |
2344 /* Update the MENUBAR. | |
2345 F is the frame the menu bar belongs to. | |
2346 VAL describes the contents of the menu bar. | |
2347 If DEEP_P is non-zero, rebuild all but the top level menu names in | |
2348 the MENUBAR. If DEEP_P is zero, just rebuild the names in the menubar. | |
2349 SELECT_CB is the callback to use when a menu item is selected. | |
2350 DEACTIVATE_CB is the callback to use when a sub menu is not shown anymore. | |
2351 HIGHLIGHT_CB is the callback to call when entering/leaving menu items. */ | |
2352 void | |
2353 xg_modify_menubar_widgets (menubar, f, val, deep_p, | |
2354 select_cb, deactivate_cb, highlight_cb) | |
2355 GtkWidget *menubar; | |
2356 FRAME_PTR f; | |
2357 widget_value *val; | |
2358 int deep_p; | |
2359 GCallback select_cb; | |
2360 GCallback deactivate_cb; | |
2361 GCallback highlight_cb; | |
2362 { | |
2363 xg_menu_cb_data *cl_data; | |
2364 GList *list = gtk_container_get_children (GTK_CONTAINER (menubar)); | |
2365 | |
2366 if (! list) return; | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
2367 |
49323 | 2368 cl_data = (xg_menu_cb_data*) g_object_get_data (G_OBJECT (menubar), |
2369 XG_FRAME_DATA); | |
2370 | |
52981
54482f5ea7be
Remove tear off capability for GTK popup menus.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52401
diff
changeset
|
2371 xg_update_menubar (menubar, f, &list, list, 0, val->contents, |
54482f5ea7be
Remove tear off capability for GTK popup menus.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52401
diff
changeset
|
2372 select_cb, highlight_cb, cl_data); |
54482f5ea7be
Remove tear off capability for GTK popup menus.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52401
diff
changeset
|
2373 |
54482f5ea7be
Remove tear off capability for GTK popup menus.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52401
diff
changeset
|
2374 if (deep_p); |
49323 | 2375 { |
2376 widget_value *cur; | |
2377 | |
2378 /* Update all sub menus. | |
52981
54482f5ea7be
Remove tear off capability for GTK popup menus.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52401
diff
changeset
|
2379 We must keep the submenus (GTK menu item widgets) since the |
49323 | 2380 X Window in the XEvent that activates the menu are those widgets. */ |
2381 | |
2382 /* Update cl_data, menu_item things in F may have changed. */ | |
2383 update_cl_data (cl_data, f, highlight_cb); | |
2384 | |
2385 for (cur = val->contents; cur; cur = cur->next) | |
2386 { | |
49572 | 2387 GList *iter; |
49323 | 2388 GtkWidget *sub = 0; |
2389 GtkWidget *newsub; | |
2390 GtkMenuItem *witem; | |
2391 | |
2392 /* Find sub menu that corresponds to val and update it. */ | |
2393 for (iter = list ; iter; iter = g_list_next (iter)) | |
2394 { | |
2395 witem = GTK_MENU_ITEM (iter->data); | |
2396 if (xg_item_label_same_p (witem, cur->name)) | |
2397 { | |
2398 sub = gtk_menu_item_get_submenu (witem); | |
2399 break; | |
2400 } | |
2401 } | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
2402 |
49323 | 2403 newsub = xg_update_submenu (sub, |
2404 f, | |
2405 cur->contents, | |
2406 select_cb, | |
2407 deactivate_cb, | |
2408 highlight_cb, | |
2409 cl_data); | |
2410 /* sub may still be NULL. If we just updated non deep and added | |
2411 a new menu bar item, it has no sub menu yet. So we set the | |
2412 newly created sub menu under witem. */ | |
2413 if (newsub != sub) | |
53069
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
2414 { |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
2415 xg_set_screen (newsub, f); |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
2416 gtk_menu_item_set_submenu (witem, newsub); |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
2417 } |
49323 | 2418 } |
2419 } | |
2420 | |
49572 | 2421 g_list_free (list); |
49323 | 2422 gtk_widget_show_all (menubar); |
2423 } | |
2424 | |
2425 /* Recompute all the widgets of frame F, when the menu bar has been | |
2426 changed. Value is non-zero if widgets were updated. */ | |
2427 | |
2428 int | |
2429 xg_update_frame_menubar (f) | |
2430 FRAME_PTR f; | |
2431 { | |
2432 struct x_output *x = f->output_data.x; | |
2433 GtkRequisition req; | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
2434 |
49323 | 2435 if (!x->menubar_widget || GTK_WIDGET_MAPPED (x->menubar_widget)) |
2436 return 0; | |
2437 | |
2438 BLOCK_INPUT; | |
2439 | |
2440 gtk_box_pack_start (GTK_BOX (x->vbox_widget), x->menubar_widget, | |
2441 FALSE, FALSE, 0); | |
2442 gtk_box_reorder_child (GTK_BOX (x->vbox_widget), x->menubar_widget, 0); | |
2443 | |
2444 gtk_widget_show_all (x->menubar_widget); | |
2445 gtk_widget_size_request (x->menubar_widget, &req); | |
2446 | |
2447 FRAME_MENUBAR_HEIGHT (f) = req.height; | |
2448 | |
2449 /* The height has changed, resize outer widget and set columns | |
2450 rows to what we had before adding the menu bar. */ | |
51211
28ea05de2dc5
Make (many) trivial substitutions for renamed and
Kim F. Storm <storm@cua.dk>
parents:
50778
diff
changeset
|
2451 xg_resize_outer_widget (f, FRAME_COLS (f), FRAME_LINES (f)); |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
2452 |
49323 | 2453 SET_FRAME_GARBAGED (f); |
2454 UNBLOCK_INPUT; | |
50106
5675d6a0080c
(xg_update_frame_menubar): Add missing return value.
Andreas Schwab <schwab@suse.de>
parents:
50099
diff
changeset
|
2455 |
5675d6a0080c
(xg_update_frame_menubar): Add missing return value.
Andreas Schwab <schwab@suse.de>
parents:
50099
diff
changeset
|
2456 return 1; |
49323 | 2457 } |
2458 | |
2459 /* Get rid of the menu bar of frame F, and free its storage. | |
2460 This is used when deleting a frame, and when turning off the menu bar. */ | |
2461 | |
2462 void | |
2463 free_frame_menubar (f) | |
2464 FRAME_PTR f; | |
2465 { | |
2466 struct x_output *x = f->output_data.x; | |
2467 | |
2468 if (x->menubar_widget) | |
2469 { | |
2470 BLOCK_INPUT; | |
2471 | |
2472 gtk_container_remove (GTK_CONTAINER (x->vbox_widget), x->menubar_widget); | |
2473 /* The menubar and its children shall be deleted when removed from | |
2474 the container. */ | |
2475 x->menubar_widget = 0; | |
2476 FRAME_MENUBAR_HEIGHT (f) = 0; | |
2477 | |
2478 /* The height has changed, resize outer widget and set columns | |
2479 rows to what we had before removing the menu bar. */ | |
51211
28ea05de2dc5
Make (many) trivial substitutions for renamed and
Kim F. Storm <storm@cua.dk>
parents:
50778
diff
changeset
|
2480 xg_resize_outer_widget (f, FRAME_COLS (f), FRAME_LINES (f)); |
49323 | 2481 |
2482 SET_FRAME_GARBAGED (f); | |
2483 UNBLOCK_INPUT; | |
2484 } | |
2485 } | |
2486 | |
2487 | |
2488 | |
2489 /*********************************************************************** | |
2490 Scroll bar functions | |
2491 ***********************************************************************/ | |
2492 | |
2493 | |
2494 /* Setting scroll bar values invokes the callback. Use this variable | |
2495 to indicate that callback should do nothing. */ | |
2496 int xg_ignore_gtk_scrollbar; | |
2497 | |
2498 /* SET_SCROLL_BAR_X_WINDOW assumes the second argument fits in | |
2499 32 bits. But we want to store pointers, and they may be larger | |
2500 than 32 bits. Keep a mapping from integer index to widget pointers | |
2501 to get around the 32 bit limitation. */ | |
2502 static struct | |
2503 { | |
2504 GtkWidget **widgets; | |
2505 int max_size; | |
2506 int used; | |
49419
6562bb5f04aa
gtkutil.c (xg_initialize): Initialize id_to_widget here instead
Jan Djärv <jan.h.d@swipnet.se>
parents:
49359
diff
changeset
|
2507 } id_to_widget; |
49323 | 2508 |
2509 /* Grow this much every time we need to allocate more */ | |
2510 #define ID_TO_WIDGET_INCR 32 | |
2511 | |
2512 /* Store the widget pointer W in id_to_widget and return the integer index. */ | |
2513 static int | |
2514 xg_store_widget_in_map (w) | |
2515 GtkWidget *w; | |
2516 { | |
2517 int i; | |
2518 | |
2519 if (id_to_widget.max_size == id_to_widget.used) | |
2520 { | |
2521 int new_size = id_to_widget.max_size + ID_TO_WIDGET_INCR; | |
2522 | |
2523 id_to_widget.widgets = xrealloc (id_to_widget.widgets, | |
2524 sizeof (GtkWidget *)*new_size); | |
2525 | |
2526 for (i = id_to_widget.max_size; i < new_size; ++i) | |
2527 id_to_widget.widgets[i] = 0; | |
2528 id_to_widget.max_size = new_size; | |
2529 } | |
2530 | |
2531 /* Just loop over the array and find a free place. After all, | |
2532 how many scroll bars are we creating? Should be a small number. | |
2533 The check above guarantees we will find a free place. */ | |
2534 for (i = 0; i < id_to_widget.max_size; ++i) | |
2535 { | |
2536 if (! id_to_widget.widgets[i]) | |
2537 { | |
2538 id_to_widget.widgets[i] = w; | |
2539 ++id_to_widget.used; | |
2540 | |
2541 return i; | |
2542 } | |
2543 } | |
2544 | |
2545 /* Should never end up here */ | |
2546 abort (); | |
2547 } | |
2548 | |
2549 /* Remove pointer at IDX from id_to_widget. | |
2550 Called when scroll bar is destroyed. */ | |
2551 static void | |
2552 xg_remove_widget_from_map (idx) | |
2553 int idx; | |
2554 { | |
2555 if (idx < id_to_widget.max_size && id_to_widget.widgets[idx] != 0) | |
2556 { | |
2557 id_to_widget.widgets[idx] = 0; | |
2558 --id_to_widget.used; | |
2559 } | |
2560 } | |
2561 | |
2562 /* Get the widget pointer at IDX from id_to_widget. */ | |
2563 static GtkWidget * | |
2564 xg_get_widget_from_map (idx) | |
2565 int idx; | |
2566 { | |
2567 if (idx < id_to_widget.max_size && id_to_widget.widgets[idx] != 0) | |
2568 return id_to_widget.widgets[idx]; | |
2569 | |
2570 return 0; | |
2571 } | |
2572 | |
53069
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
2573 /* Return the scrollbar id for X Window WID on display DPY. |
50063 | 2574 Return -1 if WID not in id_to_widget. */ |
2575 int | |
53069
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
2576 xg_get_scroll_id_for_window (dpy, wid) |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
2577 Display *dpy; |
50063 | 2578 Window wid; |
2579 { | |
2580 int idx; | |
2581 GtkWidget *w; | |
2582 | |
53069
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
2583 w = xg_win_to_widget (dpy, wid); |
50063 | 2584 |
2585 if (w) | |
2586 { | |
2587 for (idx = 0; idx < id_to_widget.max_size; ++idx) | |
2588 if (id_to_widget.widgets[idx] == w) | |
2589 return idx; | |
2590 } | |
2591 | |
2592 return -1; | |
2593 } | |
2594 | |
49323 | 2595 /* Callback invoked when scroll bar WIDGET is destroyed. |
2596 DATA is the index into id_to_widget for WIDGET. | |
50129
d0142038feaa
Reduce flicker in GTK scrollbars.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50112
diff
changeset
|
2597 We free pointer to last scroll bar values here and remove the index. */ |
49323 | 2598 static void |
2599 xg_gtk_scroll_destroy (widget, data) | |
2600 GtkWidget *widget; | |
2601 gpointer data; | |
2602 { | |
2603 gpointer p; | |
2604 int id = (int)data; | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
2605 |
49323 | 2606 p = g_object_get_data (G_OBJECT (widget), XG_LAST_SB_DATA); |
2607 if (p) xfree (p); | |
2608 xg_remove_widget_from_map (id); | |
2609 } | |
2610 | |
2611 /* Callback for button press/release events. Used to start timer so that | |
2612 the scroll bar repetition timer in GTK gets handeled. | |
50177
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2613 Also, sets bar->dragging to Qnil when dragging (button release) is done. |
49323 | 2614 WIDGET is the scroll bar widget the event is for (not used). |
2615 EVENT contains the event. | |
50177
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2616 USER_DATA points to the struct scrollbar structure. |
49323 | 2617 |
2618 Returns FALSE to tell GTK that it shall continue propagate the event | |
2619 to widgets. */ | |
2620 static gboolean | |
2621 scroll_bar_button_cb (widget, event, user_data) | |
2622 GtkWidget *widget; | |
2623 GdkEventButton *event; | |
2624 gpointer user_data; | |
2625 { | |
2626 if (event->type == GDK_BUTTON_PRESS && ! xg_timer) | |
2627 xg_start_timer (); | |
50177
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2628 else if (event->type == GDK_BUTTON_RELEASE) |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2629 { |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2630 struct scroll_bar *bar = (struct scroll_bar *) user_data; |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2631 if (xg_timer) xg_stop_timer (); |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2632 bar->dragging = Qnil; |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2633 } |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2634 |
49323 | 2635 return FALSE; |
2636 } | |
2637 | |
2638 /* Create a scroll bar widget for frame F. Store the scroll bar | |
2639 in BAR. | |
2640 SCROLL_CALLBACK is the callback to invoke when the value of the | |
2641 bar changes. | |
2642 SCROLL_BAR_NAME is the name we use for the scroll bar. Can be used | |
2643 to set resources for the widget. */ | |
2644 void | |
2645 xg_create_scroll_bar (f, bar, scroll_callback, scroll_bar_name) | |
2646 FRAME_PTR f; | |
2647 struct scroll_bar *bar; | |
2648 GCallback scroll_callback; | |
2649 char *scroll_bar_name; | |
2650 { | |
2651 GtkWidget *wscroll; | |
2652 GtkObject *vadj; | |
2653 int scroll_id; | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
2654 |
49323 | 2655 /* Page, step increment values are not so important here, they |
2656 will be corrected in x_set_toolkit_scroll_bar_thumb. */ | |
2657 vadj = gtk_adjustment_new (XG_SB_MIN, XG_SB_MIN, XG_SB_MAX, | |
2658 0.1, 0.1, 0.1); | |
2659 | |
2660 wscroll = gtk_vscrollbar_new (GTK_ADJUSTMENT (vadj)); | |
2661 gtk_widget_set_name (wscroll, scroll_bar_name); | |
2662 gtk_range_set_update_policy (GTK_RANGE (wscroll), GTK_UPDATE_CONTINUOUS); | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
2663 |
49323 | 2664 scroll_id = xg_store_widget_in_map (wscroll); |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
2665 |
50521
3b4cda88d7ef
* xterm.c (xg_scroll_callback): Call gtk_range_get_adjustment to
Jan Djärv <jan.h.d@swipnet.se>
parents:
50333
diff
changeset
|
2666 g_signal_connect (G_OBJECT (wscroll), |
49323 | 2667 "value-changed", |
2668 scroll_callback, | |
50521
3b4cda88d7ef
* xterm.c (xg_scroll_callback): Call gtk_range_get_adjustment to
Jan Djärv <jan.h.d@swipnet.se>
parents:
50333
diff
changeset
|
2669 (gpointer) bar); |
49323 | 2670 g_signal_connect (G_OBJECT (wscroll), |
2671 "destroy", | |
2672 G_CALLBACK (xg_gtk_scroll_destroy), | |
50521
3b4cda88d7ef
* xterm.c (xg_scroll_callback): Call gtk_range_get_adjustment to
Jan Djärv <jan.h.d@swipnet.se>
parents:
50333
diff
changeset
|
2673 (gpointer) scroll_id); |
49323 | 2674 |
2675 /* Connect to button press and button release to detect if any scroll bar | |
2676 has the pointer. */ | |
2677 g_signal_connect (G_OBJECT (wscroll), | |
2678 "button-press-event", | |
2679 G_CALLBACK (scroll_bar_button_cb), | |
50521
3b4cda88d7ef
* xterm.c (xg_scroll_callback): Call gtk_range_get_adjustment to
Jan Djärv <jan.h.d@swipnet.se>
parents:
50333
diff
changeset
|
2680 (gpointer) bar); |
49323 | 2681 g_signal_connect (G_OBJECT (wscroll), |
2682 "button-release-event", | |
2683 G_CALLBACK (scroll_bar_button_cb), | |
50521
3b4cda88d7ef
* xterm.c (xg_scroll_callback): Call gtk_range_get_adjustment to
Jan Djärv <jan.h.d@swipnet.se>
parents:
50333
diff
changeset
|
2684 (gpointer) bar); |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
2685 |
49323 | 2686 gtk_fixed_put (GTK_FIXED (f->output_data.x->edit_widget), |
50177
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2687 wscroll, -1, -1); |
49323 | 2688 |
2689 /* Set the cursor to an arrow. */ | |
53069
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
2690 xg_set_cursor (wscroll, FRAME_X_DISPLAY_INFO (f)->xg_cursor); |
49323 | 2691 |
2692 SET_SCROLL_BAR_X_WINDOW (bar, scroll_id); | |
2693 } | |
2694 | |
2695 /* Make the scroll bar represented by SCROLLBAR_ID visible. */ | |
2696 void | |
2697 xg_show_scroll_bar (scrollbar_id) | |
2698 int scrollbar_id; | |
2699 { | |
2700 GtkWidget *w = xg_get_widget_from_map (scrollbar_id); | |
2701 if (w) | |
2702 gtk_widget_show (w); | |
2703 } | |
2704 | |
2705 /* Remove the scroll bar represented by SCROLLBAR_ID from the frame F. */ | |
2706 void | |
2707 xg_remove_scroll_bar (f, scrollbar_id) | |
2708 FRAME_PTR f; | |
2709 int scrollbar_id; | |
2710 { | |
2711 GtkWidget *w = xg_get_widget_from_map (scrollbar_id); | |
2712 if (w) | |
2713 { | |
2714 gtk_widget_destroy (w); | |
2715 SET_FRAME_GARBAGED (f); | |
2716 } | |
2717 } | |
2718 | |
50177
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2719 /* Find left/top for widget W in GtkFixed widget WFIXED. */ |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2720 static void |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2721 xg_find_top_left_in_fixed (w, wfixed, left, top) |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2722 GtkWidget *w, *wfixed; |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2723 int *left, *top; |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2724 { |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2725 GList *iter; |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2726 |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2727 for (iter = GTK_FIXED (wfixed)->children; iter; iter = g_list_next (iter)) |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2728 { |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2729 GtkFixedChild *child = (GtkFixedChild *) iter->data; |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2730 |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2731 if (child->widget == w) |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2732 { |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2733 *left = child->x; |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2734 *top = child->y; |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2735 return; |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2736 } |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2737 } |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2738 |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2739 /* Shall never end up here. */ |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2740 abort (); |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2741 } |
49323 | 2742 |
2743 /* Update the position of the vertical scroll bar represented by SCROLLBAR_ID | |
2744 in frame F. | |
2745 TOP/LEFT are the new pixel positions where the bar shall appear. | |
2746 WIDTH, HEIGHT is the size in pixels the bar shall have. */ | |
2747 void | |
50270
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2748 xg_update_scrollbar_pos (f, scrollbar_id, top, left, width, height, |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2749 real_left, canon_width) |
49323 | 2750 FRAME_PTR f; |
2751 int scrollbar_id; | |
2752 int top; | |
2753 int left; | |
2754 int width; | |
2755 int height; | |
2756 { | |
49572 | 2757 |
2758 GtkWidget *wscroll = xg_get_widget_from_map (scrollbar_id); | |
50270
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2759 |
49572 | 2760 if (wscroll) |
2761 { | |
50177
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2762 GtkWidget *wfixed = f->output_data.x->edit_widget; |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2763 int winextra = canon_width > width ? (canon_width - width) / 2 : 0; |
50318
5b50d76d9211
* gtkutil.c (xg_resize_widgets): Don't call xg_frame_cleared.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50272
diff
changeset
|
2764 int bottom = top + height; |
50177
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2765 |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2766 gint slider_width; |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2767 int oldtop, oldleft, oldbottom; |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2768 GtkRequisition req; |
50270
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2769 |
50177
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2770 /* Get old values. */ |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2771 xg_find_top_left_in_fixed (wscroll, wfixed, &oldleft, &oldtop); |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2772 gtk_widget_size_request (wscroll, &req); |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2773 oldbottom = oldtop + req.height; |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2774 |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2775 /* Scroll bars in GTK has a fixed width, so if we say width 16, it |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2776 will only be its fixed width (14 is default) anyway, the rest is |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2777 blank. We are drawing the mode line across scroll bars when |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2778 the frame is split: |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2779 |bar| |fringe| |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2780 ---------------- |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2781 mode line |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2782 ---------------- |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2783 |bar| |fringe| |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2784 |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2785 When we "unsplit" the frame: |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2786 |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2787 |bar| |fringe| |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2788 -| |-| | |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2789 m¦ |i| | |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2790 -| |-| | |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2791 | | | | |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2792 |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2793 |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2794 the remains of the mode line can be seen in these blank spaces. |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2795 So we must clear them explicitly. |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2796 GTK scroll bars should do that, but they don't. |
50270
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2797 Also, the canonical width may be wider than the width for the |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2798 scroll bar so that there is some space (typically 1 pixel) between |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2799 the scroll bar and the edge of the window and between the scroll |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2800 bar and the fringe. */ |
50177
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2801 |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2802 if (oldtop != -1 && oldleft != -1) |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2803 { |
50270
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2804 int gtkextral, gtkextrah; |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2805 int xl, xr, wbl, wbr; |
50177
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2806 int bottomdiff, topdiff; |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2807 |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2808 gtk_widget_style_get (wscroll, "slider_width", &slider_width, NULL); |
50270
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2809 gtkextral = width > slider_width ? (width - slider_width) / 2 : 0; |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2810 gtkextrah = gtkextral ? (width - slider_width - gtkextral) : 0; |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2811 |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2812 xl = real_left; |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2813 wbl = gtkextral + winextra; |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2814 wbr = gtkextrah + winextra; |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2815 xr = left + gtkextral + slider_width; |
50177
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2816 bottomdiff = abs (oldbottom - bottom); |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2817 topdiff = abs (oldtop - top); |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2818 |
50270
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2819 if (oldleft != left) |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2820 { |
50318
5b50d76d9211
* gtkutil.c (xg_resize_widgets): Don't call xg_frame_cleared.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50272
diff
changeset
|
2821 gdk_window_clear_area (wfixed->window, xl, top, wbl, height); |
5b50d76d9211
* gtkutil.c (xg_resize_widgets): Don't call xg_frame_cleared.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50272
diff
changeset
|
2822 gdk_window_clear_area (wfixed->window, xr, top, wbr, height); |
50270
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2823 } |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2824 |
50177
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2825 if (oldtop > top) |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2826 { |
50270
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2827 gdk_window_clear_area (wfixed->window, xl, top, wbl, topdiff); |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2828 gdk_window_clear_area (wfixed->window, xr, top, wbr, topdiff); |
50177
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2829 } |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2830 else if (oldtop < top) |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2831 { |
50270
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2832 gdk_window_clear_area (wfixed->window, xl, oldtop, wbl, topdiff); |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2833 gdk_window_clear_area (wfixed->window, xr, oldtop, wbr, topdiff); |
50177
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2834 } |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2835 |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2836 if (oldbottom > bottom) |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2837 { |
50270
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2838 gdk_window_clear_area (wfixed->window, xl, bottom, wbl, |
50177
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2839 bottomdiff); |
50270
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2840 gdk_window_clear_area (wfixed->window, xr, bottom, wbr, |
50177
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2841 bottomdiff); |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2842 } |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2843 else if (oldbottom < bottom) |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2844 { |
50270
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2845 gdk_window_clear_area (wfixed->window, xl, oldbottom, wbl, |
50177
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2846 bottomdiff); |
50270
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2847 gdk_window_clear_area (wfixed->window, xr, oldbottom, wbr, |
50177
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2848 bottomdiff); |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2849 } |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2850 } |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2851 |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2852 /* Move and resize to new values. */ |
50129
d0142038feaa
Reduce flicker in GTK scrollbars.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50112
diff
changeset
|
2853 gtk_fixed_move (GTK_FIXED (wfixed), wscroll, left, top); |
50318
5b50d76d9211
* gtkutil.c (xg_resize_widgets): Don't call xg_frame_cleared.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50272
diff
changeset
|
2854 gtk_widget_set_size_request (wscroll, width, height); |
5b50d76d9211
* gtkutil.c (xg_resize_widgets): Don't call xg_frame_cleared.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50272
diff
changeset
|
2855 |
50272 | 2856 /* Must force out update so changed scroll bars gets redrawn. */ |
2857 gdk_window_process_all_updates (); | |
2858 | |
49572 | 2859 SET_FRAME_GARBAGED (f); |
2860 cancel_mouse_face (f); | |
2861 } | |
49323 | 2862 } |
2863 | |
2864 /* Set the thumb size and position of scroll bar BAR. We are currently | |
2865 displaying PORTION out of a whole WHOLE, and our position POSITION. */ | |
2866 void | |
2867 xg_set_toolkit_scroll_bar_thumb (bar, portion, position, whole) | |
2868 struct scroll_bar *bar; | |
2869 int portion, position, whole; | |
2870 { | |
2871 GtkWidget *wscroll = xg_get_widget_from_map (SCROLL_BAR_X_WINDOW (bar)); | |
2872 | |
2873 FRAME_PTR f = XFRAME (WINDOW_FRAME (XWINDOW (bar->window))); | |
2874 | |
50177
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2875 if (wscroll && NILP (bar->dragging)) |
49323 | 2876 { |
2877 GtkAdjustment *adj; | |
2878 gdouble shown; | |
2879 gdouble top; | |
2880 int size, value; | |
50270
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2881 int new_step; |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2882 int changed = 0; |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
2883 |
49323 | 2884 adj = gtk_range_get_adjustment (GTK_RANGE (wscroll)); |
2885 | |
50177
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2886 /* We do the same as for MOTIF in xterm.c, assume 30 chars per line |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2887 rather than the real portion value. This makes the thumb less likely |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2888 to resize and that looks better. */ |
51211
28ea05de2dc5
Make (many) trivial substitutions for renamed and
Kim F. Storm <storm@cua.dk>
parents:
50778
diff
changeset
|
2889 portion = WINDOW_TOTAL_LINES (XWINDOW (bar->window)) * 30; |
50177
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2890 /* When the thumb is at the bottom, position == whole. |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2891 So we need to increase `whole' to make space for the thumb. */ |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2892 whole += portion; |
297925dd73b1
New approach to scrolling and scroll bars for better redraw and smoother
Jan Djärv <jan.h.d@swipnet.se>
parents:
50130
diff
changeset
|
2893 |
49323 | 2894 if (whole <= 0) |
2895 top = 0, shown = 1; | |
2896 else | |
2897 { | |
50270
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2898 top = (gdouble) position / whole; |
49323 | 2899 shown = (gdouble) portion / whole; |
2900 } | |
2901 | |
50270
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2902 size = shown * XG_SB_RANGE; |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2903 size = min (size, XG_SB_RANGE); |
49323 | 2904 size = max (size, 1); |
2905 | |
50270
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2906 value = top * XG_SB_RANGE; |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2907 value = min (value, XG_SB_MAX - size); |
49323 | 2908 value = max (value, XG_SB_MIN); |
2909 | |
50270
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2910 /* Assume all lines are of equal size. */ |
51211
28ea05de2dc5
Make (many) trivial substitutions for renamed and
Kim F. Storm <storm@cua.dk>
parents:
50778
diff
changeset
|
2911 new_step = size / max (1, FRAME_LINES (f)); |
50178
61194aef8668
* gtkutil.c (xg_set_toolkit_scroll_bar_thumb): Check if new values
Jan Djärv <jan.h.d@swipnet.se>
parents:
50177
diff
changeset
|
2912 |
61194aef8668
* gtkutil.c (xg_set_toolkit_scroll_bar_thumb): Check if new values
Jan Djärv <jan.h.d@swipnet.se>
parents:
50177
diff
changeset
|
2913 if ((int) adj->page_size != size |
61194aef8668
* gtkutil.c (xg_set_toolkit_scroll_bar_thumb): Check if new values
Jan Djärv <jan.h.d@swipnet.se>
parents:
50177
diff
changeset
|
2914 || (int) adj->step_increment != new_step) |
61194aef8668
* gtkutil.c (xg_set_toolkit_scroll_bar_thumb): Check if new values
Jan Djärv <jan.h.d@swipnet.se>
parents:
50177
diff
changeset
|
2915 { |
50270
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2916 adj->page_size = size; |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2917 adj->step_increment = new_step; |
50178
61194aef8668
* gtkutil.c (xg_set_toolkit_scroll_bar_thumb): Check if new values
Jan Djärv <jan.h.d@swipnet.se>
parents:
50177
diff
changeset
|
2918 /* Assume a page increment is about 95% of the page size */ |
50270
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2919 adj->page_increment = (int) (0.95*adj->page_size); |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2920 changed = 1; |
50178
61194aef8668
* gtkutil.c (xg_set_toolkit_scroll_bar_thumb): Check if new values
Jan Djärv <jan.h.d@swipnet.se>
parents:
50177
diff
changeset
|
2921 } |
61194aef8668
* gtkutil.c (xg_set_toolkit_scroll_bar_thumb): Check if new values
Jan Djärv <jan.h.d@swipnet.se>
parents:
50177
diff
changeset
|
2922 |
50270
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2923 if (changed || (int) gtk_range_get_value (GTK_RANGE (wscroll)) != value) |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2924 { |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2925 GtkWidget *wfixed = f->output_data.x->edit_widget; |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2926 |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2927 BLOCK_INPUT; |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2928 |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2929 /* gtk_range_set_value invokes the callback. Set |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2930 ignore_gtk_scrollbar to make the callback do nothing */ |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2931 xg_ignore_gtk_scrollbar = 1; |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2932 |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2933 if ((int) gtk_range_get_value (GTK_RANGE (wscroll)) != value) |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2934 gtk_range_set_value (GTK_RANGE (wscroll), (gdouble)value); |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2935 else if (changed) |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2936 gtk_adjustment_changed (adj); |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2937 |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2938 xg_ignore_gtk_scrollbar = 0; |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2939 |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2940 UNBLOCK_INPUT; |
fa50953c02dc
Finally (?) fix flicker in scroll bar.
Jan Djärv <jan.h.d@swipnet.se>
parents:
50192
diff
changeset
|
2941 } |
49323 | 2942 } |
2943 } | |
2944 | |
2945 | |
2946 /*********************************************************************** | |
2947 Tool bar functions | |
2948 ***********************************************************************/ | |
2949 /* The key for the data we put in the GtkImage widgets. The data is | |
2950 the image used by Emacs. We use this to see if we need to update | |
2951 the GtkImage with a new image. */ | |
2952 #define XG_TOOL_BAR_IMAGE_DATA "emacs-tool-bar-image" | |
2953 | |
2954 /* Callback function invoked when a tool bar item is pressed. | |
2955 W is the button widget in the tool bar that got pressed, | |
2956 CLIENT_DATA is an integer that is the index of the button in the | |
2957 tool bar. 0 is the first button. */ | |
2958 static void | |
2959 xg_tool_bar_callback (w, client_data) | |
2960 GtkWidget *w; | |
2961 gpointer client_data; | |
2962 { | |
2963 int idx = (int)client_data; | |
2964 FRAME_PTR f = (FRAME_PTR) g_object_get_data (G_OBJECT (w), XG_FRAME_DATA); | |
2965 Lisp_Object key, frame; | |
2966 struct input_event event; | |
51569
e7bd8581e306
(xg_tool_bar_callback): Don't pass uninitialized
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
51432
diff
changeset
|
2967 EVENT_INIT (event); |
49323 | 2968 |
2969 if (! f || ! f->n_tool_bar_items || NILP (f->tool_bar_items)) | |
2970 return; | |
2971 | |
2972 idx *= TOOL_BAR_ITEM_NSLOTS; | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
2973 |
49323 | 2974 key = AREF (f->tool_bar_items, idx + TOOL_BAR_ITEM_KEY); |
2975 XSETFRAME (frame, f); | |
2976 event.kind = TOOL_BAR_EVENT; | |
2977 event.frame_or_window = frame; | |
2978 event.arg = frame; | |
2979 kbd_buffer_store_event (&event); | |
2980 | |
2981 event.kind = TOOL_BAR_EVENT; | |
2982 event.frame_or_window = frame; | |
2983 event.arg = key; | |
2984 event.modifiers = 0; /* These are not available. */ | |
2985 kbd_buffer_store_event (&event); | |
2986 } | |
2987 | |
2988 /* This callback is called when a tool bar is detached. We must set | |
2989 the height of the tool bar to zero when this happens so frame sizes | |
2990 are correctly calculated. | |
2991 WBOX is the handle box widget that enables detach/attach of the tool bar. | |
2992 W is the tool bar widget. | |
2993 CLIENT_DATA is a pointer to the frame the tool bar belongs to. */ | |
2994 static void | |
2995 xg_tool_bar_detach_callback (wbox, w, client_data) | |
2996 GtkHandleBox *wbox; | |
2997 GtkWidget *w; | |
2998 gpointer client_data; | |
2999 { | |
3000 FRAME_PTR f = (FRAME_PTR) client_data; | |
3001 | |
3002 if (f) | |
3003 { | |
3004 /* When detaching a tool bar, not everything dissapear. There are | |
3005 a few pixels left that are used to drop the tool bar back into | |
3006 place. */ | |
3007 int bw = gtk_container_get_border_width (GTK_CONTAINER (wbox)); | |
3008 FRAME_TOOLBAR_HEIGHT (f) = 2; | |
3009 | |
3010 /* The height has changed, resize outer widget and set columns | |
3011 rows to what we had before detaching the tool bar. */ | |
51211
28ea05de2dc5
Make (many) trivial substitutions for renamed and
Kim F. Storm <storm@cua.dk>
parents:
50778
diff
changeset
|
3012 xg_resize_outer_widget (f, FRAME_COLS (f), FRAME_LINES (f)); |
49323 | 3013 } |
3014 } | |
3015 | |
3016 /* This callback is called when a tool bar is reattached. We must set | |
3017 the height of the tool bar when this happens so frame sizes | |
3018 are correctly calculated. | |
3019 WBOX is the handle box widget that enables detach/attach of the tool bar. | |
3020 W is the tool bar widget. | |
3021 CLIENT_DATA is a pointer to the frame the tool bar belongs to. */ | |
3022 static void | |
3023 xg_tool_bar_attach_callback (wbox, w, client_data) | |
3024 GtkHandleBox *wbox; | |
3025 GtkWidget *w; | |
3026 gpointer client_data; | |
3027 { | |
3028 FRAME_PTR f = (FRAME_PTR) client_data; | |
3029 | |
3030 if (f) | |
3031 { | |
3032 GtkRequisition req; | |
3033 | |
3034 gtk_widget_size_request (w, &req); | |
3035 FRAME_TOOLBAR_HEIGHT (f) = req.height; | |
3036 | |
3037 /* The height has changed, resize outer widget and set columns | |
3038 rows to what we had before detaching the tool bar. */ | |
51211
28ea05de2dc5
Make (many) trivial substitutions for renamed and
Kim F. Storm <storm@cua.dk>
parents:
50778
diff
changeset
|
3039 xg_resize_outer_widget (f, FRAME_COLS (f), FRAME_LINES (f)); |
49323 | 3040 } |
3041 } | |
3042 | |
3043 /* This callback is called when the mouse enters or leaves a tool bar item. | |
3044 It is used for displaying and hiding the help text. | |
3045 W is the tool bar item, a button. | |
3046 EVENT is either an enter event or leave event. | |
3047 CLIENT_DATA is an integer that is the index of the button in the | |
3048 tool bar. 0 is the first button. | |
3049 | |
3050 Returns FALSE to tell GTK to keep processing this event. */ | |
3051 static gboolean | |
3052 xg_tool_bar_help_callback (w, event, client_data) | |
3053 GtkWidget *w; | |
3054 GdkEventCrossing *event; | |
3055 gpointer client_data; | |
3056 { | |
3057 int idx = (int)client_data; | |
3058 FRAME_PTR f = (FRAME_PTR) g_object_get_data (G_OBJECT (w), XG_FRAME_DATA); | |
3059 Lisp_Object help, frame; | |
3060 | |
3061 if (! GTK_IS_BUTTON (w)) | |
3062 { | |
3063 return FALSE; | |
3064 } | |
3065 | |
3066 if (! f || ! f->n_tool_bar_items || NILP (f->tool_bar_items)) | |
50108
a9ff586d3d09
(xg_tool_bar_help_callback): Add missing return value.
Andreas Schwab <schwab@suse.de>
parents:
50106
diff
changeset
|
3067 return FALSE; |
49323 | 3068 |
3069 if (event->type == GDK_ENTER_NOTIFY) | |
3070 { | |
3071 idx *= TOOL_BAR_ITEM_NSLOTS; | |
3072 help = AREF (f->tool_bar_items, idx + TOOL_BAR_ITEM_HELP); | |
3073 | |
3074 if (NILP (help)) | |
3075 help = AREF (f->tool_bar_items, idx + TOOL_BAR_ITEM_CAPTION); | |
3076 } | |
3077 else | |
3078 help = Qnil; | |
3079 | |
3080 XSETFRAME (frame, f); | |
3081 kbd_buffer_store_help_event (frame, help); | |
3082 | |
3083 return FALSE; | |
3084 } | |
3085 | |
3086 | |
49826
e99f1a981a3b
* gtkutil.c (xg_tool_bar_expose_callback): New function.
Jan Djärv <jan.h.d@swipnet.se>
parents:
49600
diff
changeset
|
3087 /* This callback is called when a tool bar item shall be redrawn. |
e99f1a981a3b
* gtkutil.c (xg_tool_bar_expose_callback): New function.
Jan Djärv <jan.h.d@swipnet.se>
parents:
49600
diff
changeset
|
3088 It modifies the expose event so that the GtkImage widget redraws the |
e99f1a981a3b
* gtkutil.c (xg_tool_bar_expose_callback): New function.
Jan Djärv <jan.h.d@swipnet.se>
parents:
49600
diff
changeset
|
3089 whole image. This to overcome a bug that makes GtkImage draw the image |
e99f1a981a3b
* gtkutil.c (xg_tool_bar_expose_callback): New function.
Jan Djärv <jan.h.d@swipnet.se>
parents:
49600
diff
changeset
|
3090 in the wrong place when it tries to redraw just a part of the image. |
e99f1a981a3b
* gtkutil.c (xg_tool_bar_expose_callback): New function.
Jan Djärv <jan.h.d@swipnet.se>
parents:
49600
diff
changeset
|
3091 W is the GtkImage to be redrawn. |
e99f1a981a3b
* gtkutil.c (xg_tool_bar_expose_callback): New function.
Jan Djärv <jan.h.d@swipnet.se>
parents:
49600
diff
changeset
|
3092 EVENT is the expose event for W. |
e99f1a981a3b
* gtkutil.c (xg_tool_bar_expose_callback): New function.
Jan Djärv <jan.h.d@swipnet.se>
parents:
49600
diff
changeset
|
3093 CLIENT_DATA is unused. |
e99f1a981a3b
* gtkutil.c (xg_tool_bar_expose_callback): New function.
Jan Djärv <jan.h.d@swipnet.se>
parents:
49600
diff
changeset
|
3094 |
e99f1a981a3b
* gtkutil.c (xg_tool_bar_expose_callback): New function.
Jan Djärv <jan.h.d@swipnet.se>
parents:
49600
diff
changeset
|
3095 Returns FALSE to tell GTK to keep processing this event. */ |
e99f1a981a3b
* gtkutil.c (xg_tool_bar_expose_callback): New function.
Jan Djärv <jan.h.d@swipnet.se>
parents:
49600
diff
changeset
|
3096 static gboolean |
50063 | 3097 xg_tool_bar_item_expose_callback (w, event, client_data) |
49826
e99f1a981a3b
* gtkutil.c (xg_tool_bar_expose_callback): New function.
Jan Djärv <jan.h.d@swipnet.se>
parents:
49600
diff
changeset
|
3098 GtkWidget *w; |
e99f1a981a3b
* gtkutil.c (xg_tool_bar_expose_callback): New function.
Jan Djärv <jan.h.d@swipnet.se>
parents:
49600
diff
changeset
|
3099 GdkEventExpose *event; |
e99f1a981a3b
* gtkutil.c (xg_tool_bar_expose_callback): New function.
Jan Djärv <jan.h.d@swipnet.se>
parents:
49600
diff
changeset
|
3100 gpointer client_data; |
e99f1a981a3b
* gtkutil.c (xg_tool_bar_expose_callback): New function.
Jan Djärv <jan.h.d@swipnet.se>
parents:
49600
diff
changeset
|
3101 { |
50333
60da21fd968b
* gtkutil.c (xg_tool_bar_item_expose_callback): Reduce size
Jan Djärv <jan.h.d@swipnet.se>
parents:
50318
diff
changeset
|
3102 gint width, height; |
60da21fd968b
* gtkutil.c (xg_tool_bar_item_expose_callback): Reduce size
Jan Djärv <jan.h.d@swipnet.se>
parents:
50318
diff
changeset
|
3103 |
60da21fd968b
* gtkutil.c (xg_tool_bar_item_expose_callback): Reduce size
Jan Djärv <jan.h.d@swipnet.se>
parents:
50318
diff
changeset
|
3104 gdk_drawable_get_size (event->window, &width, &height); |
60da21fd968b
* gtkutil.c (xg_tool_bar_item_expose_callback): Reduce size
Jan Djärv <jan.h.d@swipnet.se>
parents:
50318
diff
changeset
|
3105 |
60da21fd968b
* gtkutil.c (xg_tool_bar_item_expose_callback): Reduce size
Jan Djärv <jan.h.d@swipnet.se>
parents:
50318
diff
changeset
|
3106 event->area.x -= width > event->area.width ? width-event->area.width : 0; |
60da21fd968b
* gtkutil.c (xg_tool_bar_item_expose_callback): Reduce size
Jan Djärv <jan.h.d@swipnet.se>
parents:
50318
diff
changeset
|
3107 event->area.y -= height > event->area.height ? height-event->area.height : 0; |
60da21fd968b
* gtkutil.c (xg_tool_bar_item_expose_callback): Reduce size
Jan Djärv <jan.h.d@swipnet.se>
parents:
50318
diff
changeset
|
3108 |
53069
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
3109 event->area.x = max (0, event->area.x); |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
3110 event->area.y = max (0, event->area.y); |
50333
60da21fd968b
* gtkutil.c (xg_tool_bar_item_expose_callback): Reduce size
Jan Djärv <jan.h.d@swipnet.se>
parents:
50318
diff
changeset
|
3111 |
60da21fd968b
* gtkutil.c (xg_tool_bar_item_expose_callback): Reduce size
Jan Djärv <jan.h.d@swipnet.se>
parents:
50318
diff
changeset
|
3112 event->area.width = max (width, event->area.width); |
60da21fd968b
* gtkutil.c (xg_tool_bar_item_expose_callback): Reduce size
Jan Djärv <jan.h.d@swipnet.se>
parents:
50318
diff
changeset
|
3113 event->area.height = max (height, event->area.height); |
60da21fd968b
* gtkutil.c (xg_tool_bar_item_expose_callback): Reduce size
Jan Djärv <jan.h.d@swipnet.se>
parents:
50318
diff
changeset
|
3114 |
49826
e99f1a981a3b
* gtkutil.c (xg_tool_bar_expose_callback): New function.
Jan Djärv <jan.h.d@swipnet.se>
parents:
49600
diff
changeset
|
3115 return FALSE; |
e99f1a981a3b
* gtkutil.c (xg_tool_bar_expose_callback): New function.
Jan Djärv <jan.h.d@swipnet.se>
parents:
49600
diff
changeset
|
3116 } |
e99f1a981a3b
* gtkutil.c (xg_tool_bar_expose_callback): New function.
Jan Djärv <jan.h.d@swipnet.se>
parents:
49600
diff
changeset
|
3117 |
50063 | 3118 /* This callback is called when a tool bar shall be redrawn. |
3119 We need to update the tool bar from here in case the image cache | |
3120 has deleted the pixmaps used in the tool bar. | |
3121 W is the GtkToolbar to be redrawn. | |
3122 EVENT is the expose event for W. | |
3123 CLIENT_DATA is pointing to the frame for this tool bar. | |
3124 | |
3125 Returns FALSE to tell GTK to keep processing this event. */ | |
3126 static gboolean | |
3127 xg_tool_bar_expose_callback (w, event, client_data) | |
3128 GtkWidget *w; | |
3129 GdkEventExpose *event; | |
3130 gpointer client_data; | |
3131 { | |
53069
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
3132 update_frame_tool_bar ((FRAME_PTR) client_data); |
50063 | 3133 return FALSE; |
3134 } | |
3135 | |
49323 | 3136 static void |
3137 xg_create_tool_bar (f) | |
3138 FRAME_PTR f; | |
3139 { | |
3140 struct x_output *x = f->output_data.x; | |
3141 GtkRequisition req; | |
3142 int vbox_pos = x->menubar_widget ? 1 : 0; | |
3143 | |
3144 x->toolbar_widget = gtk_toolbar_new (); | |
3145 x->handlebox_widget = gtk_handle_box_new (); | |
3146 gtk_container_add (GTK_CONTAINER (x->handlebox_widget), | |
3147 x->toolbar_widget); | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
3148 |
49323 | 3149 gtk_box_pack_start (GTK_BOX (x->vbox_widget), x->handlebox_widget, |
3150 FALSE, FALSE, 0); | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
3151 |
49323 | 3152 gtk_box_reorder_child (GTK_BOX (x->vbox_widget), x->handlebox_widget, |
3153 vbox_pos); | |
3154 | |
49826
e99f1a981a3b
* gtkutil.c (xg_tool_bar_expose_callback): New function.
Jan Djärv <jan.h.d@swipnet.se>
parents:
49600
diff
changeset
|
3155 gtk_widget_set_name (x->toolbar_widget, "emacs-toolbar"); |
e99f1a981a3b
* gtkutil.c (xg_tool_bar_expose_callback): New function.
Jan Djärv <jan.h.d@swipnet.se>
parents:
49600
diff
changeset
|
3156 |
e99f1a981a3b
* gtkutil.c (xg_tool_bar_expose_callback): New function.
Jan Djärv <jan.h.d@swipnet.se>
parents:
49600
diff
changeset
|
3157 /* We only have icons, so override any user setting. We could |
e99f1a981a3b
* gtkutil.c (xg_tool_bar_expose_callback): New function.
Jan Djärv <jan.h.d@swipnet.se>
parents:
49600
diff
changeset
|
3158 use the caption property of the toolbar item (see update_frame_tool_bar |
e99f1a981a3b
* gtkutil.c (xg_tool_bar_expose_callback): New function.
Jan Djärv <jan.h.d@swipnet.se>
parents:
49600
diff
changeset
|
3159 below), but some of those strings are long, making the toolbar so |
e99f1a981a3b
* gtkutil.c (xg_tool_bar_expose_callback): New function.
Jan Djärv <jan.h.d@swipnet.se>
parents:
49600
diff
changeset
|
3160 long it does not fit on the screen. The GtkToolbar widget makes every |
e99f1a981a3b
* gtkutil.c (xg_tool_bar_expose_callback): New function.
Jan Djärv <jan.h.d@swipnet.se>
parents:
49600
diff
changeset
|
3161 item equal size, so the longest caption determine the size of every |
e99f1a981a3b
* gtkutil.c (xg_tool_bar_expose_callback): New function.
Jan Djärv <jan.h.d@swipnet.se>
parents:
49600
diff
changeset
|
3162 tool bar item. I think the creators of the GtkToolbar widget |
e99f1a981a3b
* gtkutil.c (xg_tool_bar_expose_callback): New function.
Jan Djärv <jan.h.d@swipnet.se>
parents:
49600
diff
changeset
|
3163 counted on 4 or 5 character long strings. */ |
e99f1a981a3b
* gtkutil.c (xg_tool_bar_expose_callback): New function.
Jan Djärv <jan.h.d@swipnet.se>
parents:
49600
diff
changeset
|
3164 gtk_toolbar_set_style (GTK_TOOLBAR (x->toolbar_widget), GTK_TOOLBAR_ICONS); |
e99f1a981a3b
* gtkutil.c (xg_tool_bar_expose_callback): New function.
Jan Djärv <jan.h.d@swipnet.se>
parents:
49600
diff
changeset
|
3165 gtk_toolbar_set_orientation (GTK_TOOLBAR (x->toolbar_widget), |
e99f1a981a3b
* gtkutil.c (xg_tool_bar_expose_callback): New function.
Jan Djärv <jan.h.d@swipnet.se>
parents:
49600
diff
changeset
|
3166 GTK_ORIENTATION_HORIZONTAL); |
e99f1a981a3b
* gtkutil.c (xg_tool_bar_expose_callback): New function.
Jan Djärv <jan.h.d@swipnet.se>
parents:
49600
diff
changeset
|
3167 |
49323 | 3168 g_signal_connect (G_OBJECT (x->handlebox_widget), "child-detached", |
3169 G_CALLBACK (xg_tool_bar_detach_callback), f); | |
3170 g_signal_connect (G_OBJECT (x->handlebox_widget), "child-attached", | |
3171 G_CALLBACK (xg_tool_bar_attach_callback), f); | |
50063 | 3172 g_signal_connect (G_OBJECT (x->toolbar_widget), |
3173 "expose-event", | |
3174 G_CALLBACK (xg_tool_bar_expose_callback), | |
3175 f); | |
49323 | 3176 |
3177 gtk_widget_show_all (x->handlebox_widget); | |
3178 | |
3179 gtk_widget_size_request (x->toolbar_widget, &req); | |
3180 FRAME_TOOLBAR_HEIGHT (f) = req.height; | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
3181 |
49323 | 3182 /* The height has changed, resize outer widget and set columns |
3183 rows to what we had before adding the tool bar. */ | |
51211
28ea05de2dc5
Make (many) trivial substitutions for renamed and
Kim F. Storm <storm@cua.dk>
parents:
50778
diff
changeset
|
3184 xg_resize_outer_widget (f, FRAME_COLS (f), FRAME_LINES (f)); |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
3185 |
49323 | 3186 SET_FRAME_GARBAGED (f); |
3187 } | |
3188 | |
3189 void | |
3190 update_frame_tool_bar (f) | |
3191 FRAME_PTR f; | |
3192 { | |
3193 int i; | |
3194 GtkRequisition old_req, new_req; | |
3195 GList *icon_list; | |
49572 | 3196 GList *iter; |
49323 | 3197 struct x_output *x = f->output_data.x; |
3198 | |
3199 if (! FRAME_GTK_WIDGET (f)) | |
3200 return; | |
3201 | |
3202 BLOCK_INPUT; | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
3203 |
49323 | 3204 if (! x->toolbar_widget) |
3205 xg_create_tool_bar (f); | |
3206 | |
3207 gtk_widget_size_request (x->toolbar_widget, &old_req); | |
3208 | |
3209 icon_list = gtk_container_get_children (GTK_CONTAINER (x->toolbar_widget)); | |
49572 | 3210 iter = icon_list; |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
3211 |
49323 | 3212 for (i = 0; i < f->n_tool_bar_items; ++i) |
3213 { | |
3214 #define PROP(IDX) AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX)) | |
3215 | |
3216 int enabled_p = !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P)); | |
3217 int selected_p = !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P)); | |
3218 int idx; | |
3219 int img_id; | |
3220 struct image *img; | |
3221 Lisp_Object image; | |
49572 | 3222 GtkWidget *wicon = iter ? GTK_WIDGET (iter->data) : 0; |
50059
ffb4a4dbe4c0
* gtkutil.c (update_frame_tool_bar): Compare pixmap ID instead of
Jan Djärv <jan.h.d@swipnet.se>
parents:
49826
diff
changeset
|
3223 |
49572 | 3224 if (iter) iter = g_list_next (iter); |
49323 | 3225 |
3226 /* If image is a vector, choose the image according to the | |
3227 button state. */ | |
3228 image = PROP (TOOL_BAR_ITEM_IMAGES); | |
3229 if (VECTORP (image)) | |
3230 { | |
3231 if (enabled_p) | |
3232 idx = (selected_p | |
3233 ? TOOL_BAR_IMAGE_ENABLED_SELECTED | |
3234 : TOOL_BAR_IMAGE_ENABLED_DESELECTED); | |
3235 else | |
3236 idx = (selected_p | |
3237 ? TOOL_BAR_IMAGE_DISABLED_SELECTED | |
3238 : TOOL_BAR_IMAGE_DISABLED_DESELECTED); | |
3239 | |
3240 xassert (ASIZE (image) >= idx); | |
3241 image = AREF (image, idx); | |
3242 } | |
3243 else | |
3244 idx = -1; | |
3245 | |
3246 /* Ignore invalid image specifications. */ | |
3247 if (!valid_image_p (image)) | |
3248 { | |
3249 if (wicon) gtk_widget_hide (wicon); | |
3250 continue; | |
3251 } | |
3252 | |
3253 img_id = lookup_image (f, image); | |
3254 img = IMAGE_FROM_ID (f, img_id); | |
49468
f2be5cd8262f
gtkutil.c (update_frame_tool_bar): Call prepare_image_for_display
Jan Djärv <jan.h.d@swipnet.se>
parents:
49434
diff
changeset
|
3255 prepare_image_for_display (f, img); |
f2be5cd8262f
gtkutil.c (update_frame_tool_bar): Call prepare_image_for_display
Jan Djärv <jan.h.d@swipnet.se>
parents:
49434
diff
changeset
|
3256 |
f2be5cd8262f
gtkutil.c (update_frame_tool_bar): Call prepare_image_for_display
Jan Djärv <jan.h.d@swipnet.se>
parents:
49434
diff
changeset
|
3257 if (img->load_failed_p || img->pixmap == None) |
f2be5cd8262f
gtkutil.c (update_frame_tool_bar): Call prepare_image_for_display
Jan Djärv <jan.h.d@swipnet.se>
parents:
49434
diff
changeset
|
3258 { |
f2be5cd8262f
gtkutil.c (update_frame_tool_bar): Call prepare_image_for_display
Jan Djärv <jan.h.d@swipnet.se>
parents:
49434
diff
changeset
|
3259 if (wicon) gtk_widget_hide (wicon); |
f2be5cd8262f
gtkutil.c (update_frame_tool_bar): Call prepare_image_for_display
Jan Djärv <jan.h.d@swipnet.se>
parents:
49434
diff
changeset
|
3260 continue; |
f2be5cd8262f
gtkutil.c (update_frame_tool_bar): Call prepare_image_for_display
Jan Djärv <jan.h.d@swipnet.se>
parents:
49434
diff
changeset
|
3261 } |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
3262 |
49323 | 3263 if (! wicon) |
3264 { | |
53069
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
3265 GdkPixmap *gpix; |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
3266 GdkBitmap *gmask; |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
3267 GtkWidget *w; |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
3268 |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
3269 xg_get_gdk_pixmap_and_mask (f, img, &gpix, &gmask); |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
3270 w = gtk_image_new_from_pixmap (gpix, gmask); |
49323 | 3271 gtk_toolbar_append_item (GTK_TOOLBAR (x->toolbar_widget), |
3272 0, 0, 0, | |
3273 w, | |
3274 GTK_SIGNAL_FUNC (xg_tool_bar_callback), | |
3275 (gpointer)i); | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
3276 |
49323 | 3277 /* Save the image so we can see if an update is needed when |
3278 this function is called again. */ | |
3279 g_object_set_data (G_OBJECT (w), XG_TOOL_BAR_IMAGE_DATA, | |
50059
ffb4a4dbe4c0
* gtkutil.c (update_frame_tool_bar): Compare pixmap ID instead of
Jan Djärv <jan.h.d@swipnet.se>
parents:
49826
diff
changeset
|
3280 (gpointer)img->pixmap); |
49323 | 3281 |
49826
e99f1a981a3b
* gtkutil.c (xg_tool_bar_expose_callback): New function.
Jan Djärv <jan.h.d@swipnet.se>
parents:
49600
diff
changeset
|
3282 /* Catch expose events to overcome an annoying redraw bug, see |
50063 | 3283 comment for xg_tool_bar_item_expose_callback. */ |
49826
e99f1a981a3b
* gtkutil.c (xg_tool_bar_expose_callback): New function.
Jan Djärv <jan.h.d@swipnet.se>
parents:
49600
diff
changeset
|
3284 g_signal_connect (G_OBJECT (w), |
e99f1a981a3b
* gtkutil.c (xg_tool_bar_expose_callback): New function.
Jan Djärv <jan.h.d@swipnet.se>
parents:
49600
diff
changeset
|
3285 "expose-event", |
50063 | 3286 G_CALLBACK (xg_tool_bar_item_expose_callback), |
49826
e99f1a981a3b
* gtkutil.c (xg_tool_bar_expose_callback): New function.
Jan Djärv <jan.h.d@swipnet.se>
parents:
49600
diff
changeset
|
3287 0); |
e99f1a981a3b
* gtkutil.c (xg_tool_bar_expose_callback): New function.
Jan Djärv <jan.h.d@swipnet.se>
parents:
49600
diff
changeset
|
3288 |
49323 | 3289 /* We must set sensitive on the button that is the parent |
3290 of the GtkImage parent. Go upwards until we find the button. */ | |
3291 while (! GTK_IS_BUTTON (w)) | |
3292 w = gtk_widget_get_parent (w); | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
3293 |
49323 | 3294 if (w) |
3295 { | |
3296 /* Save the frame in the button so the xg_tool_bar_callback | |
3297 can get at it. */ | |
3298 g_object_set_data (G_OBJECT (w), XG_FRAME_DATA, (gpointer)f); | |
3299 gtk_widget_set_sensitive (w, enabled_p); | |
3300 | |
3301 /* Use enter/leave notify to show help. We use the events | |
3302 rather than the GtkButton specific signals "enter" and | |
3303 "leave", so we can have only one callback. The event | |
3304 will tell us what kind of event it is. */ | |
3305 g_signal_connect (G_OBJECT (w), | |
3306 "enter-notify-event", | |
3307 G_CALLBACK (xg_tool_bar_help_callback), | |
3308 (gpointer)i); | |
3309 g_signal_connect (G_OBJECT (w), | |
3310 "leave-notify-event", | |
3311 G_CALLBACK (xg_tool_bar_help_callback), | |
3312 (gpointer)i); | |
3313 } | |
3314 } | |
3315 else | |
3316 { | |
3317 /* The child of the tool bar is a button. Inside that button | |
3318 is a vbox. Inside that vbox is the GtkImage. */ | |
3319 GtkWidget *wvbox = gtk_bin_get_child (GTK_BIN (wicon)); | |
49572 | 3320 GList *chlist = gtk_container_get_children (GTK_CONTAINER (wvbox)); |
3321 GtkImage *wimage = GTK_IMAGE (chlist->data); | |
50059
ffb4a4dbe4c0
* gtkutil.c (update_frame_tool_bar): Compare pixmap ID instead of
Jan Djärv <jan.h.d@swipnet.se>
parents:
49826
diff
changeset
|
3322 Pixmap old_img = (Pixmap)g_object_get_data (G_OBJECT (wimage), |
ffb4a4dbe4c0
* gtkutil.c (update_frame_tool_bar): Compare pixmap ID instead of
Jan Djärv <jan.h.d@swipnet.se>
parents:
49826
diff
changeset
|
3323 XG_TOOL_BAR_IMAGE_DATA); |
49572 | 3324 g_list_free (chlist); |
49323 | 3325 |
50059
ffb4a4dbe4c0
* gtkutil.c (update_frame_tool_bar): Compare pixmap ID instead of
Jan Djärv <jan.h.d@swipnet.se>
parents:
49826
diff
changeset
|
3326 if (old_img != img->pixmap) |
49323 | 3327 { |
53069
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
3328 GdkPixmap *gpix; |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
3329 GdkBitmap *gmask; |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
3330 |
1218a42792ea
Implement multiple display handling for GTK.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52981
diff
changeset
|
3331 xg_get_gdk_pixmap_and_mask (f, img, &gpix, &gmask); |
49323 | 3332 gtk_image_set_from_pixmap (wimage, gpix, gmask); |
3333 } | |
3334 | |
3335 g_object_set_data (G_OBJECT (wimage), XG_TOOL_BAR_IMAGE_DATA, | |
50059
ffb4a4dbe4c0
* gtkutil.c (update_frame_tool_bar): Compare pixmap ID instead of
Jan Djärv <jan.h.d@swipnet.se>
parents:
49826
diff
changeset
|
3336 (gpointer)img->pixmap); |
49323 | 3337 |
3338 gtk_widget_set_sensitive (wicon, enabled_p); | |
3339 gtk_widget_show (wicon); | |
3340 } | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49572
diff
changeset
|
3341 |
49323 | 3342 #undef PROP |
3343 } | |
3344 | |
3345 /* Remove buttons not longer needed. We just hide them so they | |
3346 can be reused later on. */ | |
49572 | 3347 while (iter) |
49323 | 3348 { |
49572 | 3349 GtkWidget *w = GTK_WIDGET (iter->data); |
49323 | 3350 gtk_widget_hide (w); |
49572 | 3351 iter = g_list_next (iter); |
49323 | 3352 } |
3353 | |
3354 gtk_widget_size_request (x->toolbar_widget, &new_req); | |
3355 if (old_req.height != new_req.height) | |
3356 { | |
3357 FRAME_TOOLBAR_HEIGHT (f) = new_req.height; | |
51211
28ea05de2dc5
Make (many) trivial substitutions for renamed and
Kim F. Storm <storm@cua.dk>
parents:
50778
diff
changeset
|
3358 xg_resize_outer_widget (f, FRAME_COLS (f), FRAME_LINES (f)); |
49323 | 3359 } |
3360 | |
49572 | 3361 if (icon_list) g_list_free (icon_list); |
3362 | |
49323 | 3363 UNBLOCK_INPUT; |
3364 } | |
3365 | |
3366 void | |
3367 free_frame_tool_bar (f) | |
3368 FRAME_PTR f; | |
3369 { | |
3370 struct x_output *x = f->output_data.x; | |
3371 | |
3372 if (x->toolbar_widget) | |
3373 { | |
3374 BLOCK_INPUT; | |
3375 gtk_container_remove (GTK_CONTAINER (x->vbox_widget), | |
3376 x->handlebox_widget); | |
3377 x->toolbar_widget = 0; | |
3378 x->handlebox_widget = 0; | |
3379 FRAME_TOOLBAR_HEIGHT (f) = 0; | |
3380 | |
3381 /* The height has changed, resize outer widget and set columns | |
3382 rows to what we had before removing the tool bar. */ | |
51211
28ea05de2dc5
Make (many) trivial substitutions for renamed and
Kim F. Storm <storm@cua.dk>
parents:
50778
diff
changeset
|
3383 xg_resize_outer_widget (f, FRAME_COLS (f), FRAME_LINES (f)); |
49323 | 3384 |
3385 SET_FRAME_GARBAGED (f); | |
3386 UNBLOCK_INPUT; | |
3387 } | |
3388 } | |
3389 | |
3390 | |
3391 | |
3392 /*********************************************************************** | |
3393 Initializing | |
3394 ***********************************************************************/ | |
3395 void | |
3396 xg_initialize () | |
3397 { | |
3398 xg_ignore_gtk_scrollbar = 0; | |
52981
54482f5ea7be
Remove tear off capability for GTK popup menus.
Jan Djärv <jan.h.d@swipnet.se>
parents:
52401
diff
changeset
|
3399 xg_detached_menus = 0; |
49323 | 3400 xg_menu_cb_list.prev = xg_menu_cb_list.next = |
3401 xg_menu_item_cb_list.prev = xg_menu_item_cb_list.next = 0; | |
3402 | |
49419
6562bb5f04aa
gtkutil.c (xg_initialize): Initialize id_to_widget here instead
Jan Djärv <jan.h.d@swipnet.se>
parents:
49359
diff
changeset
|
3403 id_to_widget.max_size = id_to_widget.used = 0; |
6562bb5f04aa
gtkutil.c (xg_initialize): Initialize id_to_widget here instead
Jan Djärv <jan.h.d@swipnet.se>
parents:
49359
diff
changeset
|
3404 id_to_widget.widgets = 0; |
6562bb5f04aa
gtkutil.c (xg_initialize): Initialize id_to_widget here instead
Jan Djärv <jan.h.d@swipnet.se>
parents:
49359
diff
changeset
|
3405 |
49323 | 3406 /* Remove F10 as a menu accelerator, it does not mix well with Emacs key |
3407 bindings. It doesn't seem to be any way to remove properties, | |
3408 so we set it to VoidSymbol which in X means "no key". */ | |
3409 gtk_settings_set_string_property (gtk_settings_get_default (), | |
3410 "gtk-menu-bar-accel", | |
3411 "VoidSymbol", | |
3412 EMACS_CLASS); | |
49419
6562bb5f04aa
gtkutil.c (xg_initialize): Initialize id_to_widget here instead
Jan Djärv <jan.h.d@swipnet.se>
parents:
49359
diff
changeset
|
3413 |
6562bb5f04aa
gtkutil.c (xg_initialize): Initialize id_to_widget here instead
Jan Djärv <jan.h.d@swipnet.se>
parents:
49359
diff
changeset
|
3414 /* Make GTK text input widgets use Emacs style keybindings. This is |
6562bb5f04aa
gtkutil.c (xg_initialize): Initialize id_to_widget here instead
Jan Djärv <jan.h.d@swipnet.se>
parents:
49359
diff
changeset
|
3415 Emacs after all. */ |
6562bb5f04aa
gtkutil.c (xg_initialize): Initialize id_to_widget here instead
Jan Djärv <jan.h.d@swipnet.se>
parents:
49359
diff
changeset
|
3416 gtk_settings_set_string_property (gtk_settings_get_default (), |
6562bb5f04aa
gtkutil.c (xg_initialize): Initialize id_to_widget here instead
Jan Djärv <jan.h.d@swipnet.se>
parents:
49359
diff
changeset
|
3417 "gtk-key-theme-name", |
6562bb5f04aa
gtkutil.c (xg_initialize): Initialize id_to_widget here instead
Jan Djärv <jan.h.d@swipnet.se>
parents:
49359
diff
changeset
|
3418 "Emacs", |
6562bb5f04aa
gtkutil.c (xg_initialize): Initialize id_to_widget here instead
Jan Djärv <jan.h.d@swipnet.se>
parents:
49359
diff
changeset
|
3419 EMACS_CLASS); |
49323 | 3420 } |
3421 | |
3422 #endif /* USE_GTK */ | |
52401 | 3423 |
3424 /* arch-tag: fe7104da-bc1e-4aba-9bd1-f349c528f7e3 | |
3425 (do not change this comment) */ |