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