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