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