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