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