annotate src/menubar-gtk.c @ 5084:6afe991b8135

Add a PARSE_KEYWORDS macro, use it in #'make-hash-table. lisp/ChangeLog addition: 2010-03-01 Aidan Kehoe <kehoea@parhasard.net> * cl-seq.el (cl-parsing-keywords): * cl-macs.el (cl-do-arglist): Use the new invalid-keyword-argument error here. src/ChangeLog addition: 2010-03-01 Aidan Kehoe <kehoea@parhasard.net> * lisp.h (PARSE_KEYWORDS): New macro, for parsing keyword arguments from C subrs. * elhash.c (Fmake_hash_table): Use it. * general-slots.h (Q_allow_other_keys): Add this symbol. * eval.c (non_nil_allow_other_keys_p): (invalid_keyword_argument): New functions, called from the keyword argument parsing code. * data.c (init_errors_once_early): Add the new invalid-keyword-argument error here.
author Aidan Kehoe <kehoea@parhasard.net>
date Mon, 01 Mar 2010 21:05:33 +0000
parents ae48681c47fa
children 3889ef128488 308d34e9f07d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2081
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
1 /* Implements an elisp-programmable menubar -- Gtk interface.
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2 Copyright (C) 1993, 1994 Free Software Foundation, Inc.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
3 Copyright (C) 1995 Tinker Systems and INS Engineering Corp.
1346
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1242
diff changeset
4 Copyright (C) 2002, 2003 Ben Wing.
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
5
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
6 This file is part of XEmacs.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
7
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
8 XEmacs is free software; you can redistribute it and/or modify it
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
9 under the terms of the GNU General Public License as published by the
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
10 Free Software Foundation; either version 2, or (at your option) any
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
11 later version.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
12
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
13 XEmacs is distributed in the hope that it will be useful, but WITHOUT
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
16 for more details.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
17
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
18 You should have received a copy of the GNU General Public License
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
19 along with XEmacs; see the file COPYING. If not, write to
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
20 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
21 Boston, MA 02111-1307, USA. */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
22
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
23 /* Synched up with: Not in FSF. */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
24
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
25 /* created 16-dec-91 by jwz */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
26
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
27 #include <config.h>
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
28 #include "lisp.h"
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
29
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
30 #include "buffer.h"
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
31 #include "commands.h" /* zmacs_regions */
1346
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1242
diff changeset
32 #include "device-impl.h"
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
33 #include "events.h"
872
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 851
diff changeset
34 #include "frame-impl.h"
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 851
diff changeset
35 #include "gui.h"
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
36 #include "opaque.h"
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
37 #include "window.h"
876
890f3cafe600 [xemacs-hg @ 2002-06-23 09:25:11 by stephent]
stephent
parents: 872
diff changeset
38 #include "window-impl.h"
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
39
872
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 851
diff changeset
40 #include "console-gtk-impl.h"
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 851
diff changeset
41 #include "ui-gtk.h"
876
890f3cafe600 [xemacs-hg @ 2002-06-23 09:25:11 by stephent]
stephent
parents: 872
diff changeset
42 #include "menubar.h"
872
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 851
diff changeset
43
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
44 #ifdef HAVE_GNOME
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
45 #include <libgnomeui/libgnomeui.h>
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
46 #endif
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
47
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
48 #define MENUBAR_TYPE 0
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
49 #define SUBMENU_TYPE 1
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
50 #define POPUP_TYPE 2
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
51
2081
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
52 static GtkWidget *menu_descriptor_to_widget_1 (Lisp_Object descr, GtkAccelGroup* accel_group);
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
53
1346
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1242
diff changeset
54 #define FRAME_GTK_MENUBAR_DATA(f) (FRAME_GTK_DATA (f)->menubar_data)
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1242
diff changeset
55 #define XFRAME_GTK_MENUBAR_DATA_LASTBUFF(f) XCAR (FRAME_GTK_MENUBAR_DATA (f))
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1242
diff changeset
56 #define XFRAME_GTK_MENUBAR_DATA_UPTODATE(f) XCDR (FRAME_GTK_MENUBAR_DATA (f))
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
57
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
58
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
59 /* This is a bogus subclass of GtkMenuBar so that the menu never tries
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
60 ** to be bigger than the text widget. This prevents weird resizing
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
61 ** when jumping around between buffers with radically different menu
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
62 ** sizes.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
63 */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
64
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
65 #define GTK_XEMACS_MENUBAR(obj) GTK_CHECK_CAST (obj, gtk_xemacs_menubar_get_type (), GtkXEmacsMenubar)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
66 #define GTK_XEMACS_MENUBAR_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, gtk_xemacs_menubar_get_type (), GtkXEmacsMenubarClass)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
67 #define GTK_IS_XEMACS_MENUBAR(obj) GTK_CHECK_TYPE (obj, gtk_xemacs_menubar_get_type ())
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
68 #define GTK_XEMACS_MENUBAR_FRAME(obj) GTK_XEMACS_MENUBAR (obj)->f
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
69
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
70 typedef struct _GtkXEmacsMenubar GtkXEmacsMenubar;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
71 typedef struct _GtkXEmacsMenubarClass GtkXEmacsMenubarClass;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
72
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
73 struct _GtkXEmacsMenubar
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
74 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
75 GtkMenuBar menu;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
76 struct frame *frame;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
77 };
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
78
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
79 struct _GtkXEmacsMenubarClass
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
80 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
81 GtkMenuBarClass parent_class;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
82 };
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
83
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
84 guint gtk_xemacs_menubar_get_type (void);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
85 GtkWidget *gtk_xemacs_menubar_new (struct frame *f);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
86
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
87 static void gtk_xemacs_menubar_class_init (GtkXEmacsMenubarClass *klass);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
88 static void gtk_xemacs_menubar_init (GtkXEmacsMenubar *xemacs);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
89 static void gtk_xemacs_menubar_size_request (GtkWidget *widget, GtkRequisition *requisition);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
90
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
91 guint
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
92 gtk_xemacs_menubar_get_type (void)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
93 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
94 static guint xemacs_menubar_type;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
95
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
96 if (!xemacs_menubar_type)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
97 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
98 static const GtkTypeInfo xemacs_menubar_info =
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
99 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
100 "GtkXEmacsMenubar",
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
101 sizeof (GtkXEmacsMenubar),
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
102 sizeof (GtkXEmacsMenubarClass),
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
103 (GtkClassInitFunc) gtk_xemacs_menubar_class_init,
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
104 (GtkObjectInitFunc) gtk_xemacs_menubar_init,
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
105 /* reserved_1 */ NULL,
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
106 /* reserved_2 */ NULL,
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
107 (GtkClassInitFunc) NULL,
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
108 };
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
109
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
110 xemacs_menubar_type = gtk_type_unique (gtk_menu_bar_get_type (), &xemacs_menubar_info);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
111 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
112
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
113 return xemacs_menubar_type;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
114 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
115
2081
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
116 static GtkWidgetClass *menubar_parent_class;
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
117
1416
b0c1d9dc4b08 [xemacs-hg @ 2003-04-15 17:21:34 by stephent]
stephent
parents: 1346
diff changeset
118 static void
b0c1d9dc4b08 [xemacs-hg @ 2003-04-15 17:21:34 by stephent]
stephent
parents: 1346
diff changeset
119 gtk_xemacs_menubar_class_init (GtkXEmacsMenubarClass *klass)
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
120 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
121 GtkWidgetClass *widget_class;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
122
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
123 widget_class = (GtkWidgetClass*) klass;
2081
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
124 menubar_parent_class = (GtkWidgetClass *) gtk_type_class (gtk_menu_bar_get_type ());
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
125
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
126 widget_class->size_request = gtk_xemacs_menubar_size_request;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
127 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
128
1416
b0c1d9dc4b08 [xemacs-hg @ 2003-04-15 17:21:34 by stephent]
stephent
parents: 1346
diff changeset
129 static void
2286
04bc9d2f42c7 [xemacs-hg @ 2004-09-20 19:18:55 by james]
james
parents: 2168
diff changeset
130 gtk_xemacs_menubar_init (GtkXEmacsMenubar *UNUSED (xemacs))
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
131 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
132 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
133
1416
b0c1d9dc4b08 [xemacs-hg @ 2003-04-15 17:21:34 by stephent]
stephent
parents: 1346
diff changeset
134 static void
b0c1d9dc4b08 [xemacs-hg @ 2003-04-15 17:21:34 by stephent]
stephent
parents: 1346
diff changeset
135 gtk_xemacs_menubar_size_request (GtkWidget *widget, GtkRequisition *requisition)
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
136 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
137 GtkXEmacsMenubar *x = GTK_XEMACS_MENUBAR (widget);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
138 GtkRequisition frame_size;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
139
2081
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
140 menubar_parent_class->size_request (widget, requisition);
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
141
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
142 /* #### BILL!
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
143 ** We should really only do this if the menu has not been detached!
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
144 **
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
145 ** WMP 9/9/2000
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
146 */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
147
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
148 gtk_widget_size_request (FRAME_GTK_TEXT_WIDGET (x->frame), &frame_size);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
149
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
150 requisition->width = frame_size.width;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
151 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
152
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
153 GtkWidget *
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
154 gtk_xemacs_menubar_new (struct frame *f)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
155 {
2054
91d4c8c65a0f [xemacs-hg @ 2004-05-02 04:06:51 by malcolmp]
malcolmp
parents: 1416
diff changeset
156 GtkXEmacsMenubar *menubar = (GtkXEmacsMenubar*) gtk_type_new (gtk_xemacs_menubar_get_type ());
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
157
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
158 menubar->frame = f;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
159
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
160 return (GTK_WIDGET (menubar));
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
161 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
162
2081
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
163 /*
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
164 * Label with XEmacs accelerator character support.
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
165 *
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
166 * The default interfaces to GtkAccelLabel does not understand XEmacs
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
167 * keystroke printing conventions, nor is it convenient in the places where is
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
168 * it needed. This subclass provides an alternative interface more suited to
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
169 * XEmacs needs but does not add new functionality.
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
170 */
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
171 #define GTK_TYPE_XEMACS_ACCEL_LABEL (gtk_xemacs_accel_label_get_type ())
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
172 #define GTK_XEMACS_ACCEL_LABEL(obj) (GTK_CHECK_CAST ((obj), GTK_TYPE_ACCEL_LABEL, GtkXEmacsAccelLabel))
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
173 #define GTK_XEMACS_ACCEL_LABEL_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), GTK_TYPE_ACCEL_LABEL, GtkXEmacsAccelLabelClass))
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
174 #define GTK_IS_XEMACS_ACCEL_LABEL(obj) (GTK_CHECK_TYPE ((obj), GTK_TYPE_XEMACS_ACCEL_LABEL))
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
175 #define GTK_IS_XEMACS_ACCEL_LABEL_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), GTK_TYPE_XEMACS_ACCEL_LABEL))
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
176
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
177 typedef struct _GtkXEmacsAccelLabel GtkXEmacsAccelLabel;
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
178 typedef struct _GtkXEmacsAccelLabelClass GtkXEmacsAccelLabelClass;
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
179
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
180 /* Instance structure. No additional fields required. */
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
181 struct _GtkXEmacsAccelLabel
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
182 {
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
183 GtkAccelLabel label;
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
184 };
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
185
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
186 /* Class structure. No additional fields required. */
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
187 struct _GtkXEmacsAccelLabelClass
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
188 {
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
189 GtkAccelLabelClass parent_class;
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
190 };
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
191
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
192 static GtkType gtk_xemacs_accel_label_get_type(void);
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
193 static GtkWidget* gtk_xemacs_accel_label_new(const gchar *string);
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
194 static void gtk_xemacs_set_accel_keys(GtkXEmacsAccelLabel* l,
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
195 Lisp_Object keys);
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
196 static void gtk_xemacs_accel_label_class_init(GtkXEmacsAccelLabelClass *klass);
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
197 static void gtk_xemacs_accel_label_init(GtkXEmacsAccelLabel *xemacs);
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
198
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
199 static GtkType
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
200 gtk_xemacs_accel_label_get_type(void)
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
201 {
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
202 static GtkType xemacs_accel_label_type = 0;
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
203
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
204 if (!xemacs_accel_label_type)
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
205 {
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
206 static const GtkTypeInfo xemacs_accel_label_info =
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
207 {
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
208 "GtkXEmacsAccelLabel",
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
209 sizeof (GtkXEmacsAccelLabel),
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
210 sizeof (GtkXEmacsAccelLabelClass),
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
211 (GtkClassInitFunc) gtk_xemacs_accel_label_class_init,
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
212 (GtkObjectInitFunc) gtk_xemacs_accel_label_init,
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
213 /* reserved_1 */ NULL,
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
214 /* reserved_2 */ NULL,
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
215 (GtkClassInitFunc) NULL,
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
216 };
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
217
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
218 xemacs_accel_label_type = gtk_type_unique (gtk_accel_label_get_type(), &xemacs_accel_label_info);
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
219 }
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
220
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
221 return xemacs_accel_label_type;
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
222 }
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
223
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
224 static void
2286
04bc9d2f42c7 [xemacs-hg @ 2004-09-20 19:18:55 by james]
james
parents: 2168
diff changeset
225 gtk_xemacs_accel_label_class_init(GtkXEmacsAccelLabelClass *UNUSED (klass))
2081
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
226 {
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
227 /* Nothing to do. */
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
228 }
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
229
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
230 static void
2286
04bc9d2f42c7 [xemacs-hg @ 2004-09-20 19:18:55 by james]
james
parents: 2168
diff changeset
231 gtk_xemacs_accel_label_init(GtkXEmacsAccelLabel *UNUSED (xemacs))
2081
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
232 {
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
233 /* Nothing to do. */
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
234 }
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
235
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
236 static GtkWidget*
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
237 gtk_xemacs_accel_label_new (const gchar *string)
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
238 {
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
239 GtkXEmacsAccelLabel *xemacs_accel_label;
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
240
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
241 xemacs_accel_label = (GtkXEmacsAccelLabel*) gtk_type_new (GTK_TYPE_XEMACS_ACCEL_LABEL);
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
242
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
243 if (string && *string)
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
244 gtk_label_set_text (GTK_LABEL (xemacs_accel_label), string);
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
245
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
246 return GTK_WIDGET (xemacs_accel_label);
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
247 }
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
248
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
249 /* Make the string <keys> the accelerator string for the label. */
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
250 static void
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
251 gtk_xemacs_set_accel_keys(GtkXEmacsAccelLabel* l, Lisp_Object keys)
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
252 {
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
253 g_return_if_fail (l != NULL);
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
254 g_return_if_fail (GTK_IS_XEMACS_ACCEL_LABEL (l));
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
255
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
256 /* Disable the standard way of finding the accelerator string for the
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
257 label. */
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
258 gtk_accel_label_set_accel_widget (GTK_ACCEL_LABEL(l), NULL);
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
259
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
260 /* Set the string straight from the object. */
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
261 if (STRINGP (keys) && XSTRING_LENGTH (keys))
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
262 {
4981
4aebb0131297 Cleanups/renaming of EXTERNAL_TO_C_STRING and friends
Ben Wing <ben@xemacs.org>
parents: 4677
diff changeset
263 l->label.accel_string = ITEXT_TO_EXTERNAL_MALLOC (XSTRING_DATA (keys), Qctext);
2081
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
264 }
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
265 else
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
266 {
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
267 /* l->label.accel_string = NULL;*/
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
268 }
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
269 }
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
270
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
271
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
272 /* We now return you to your regularly scheduled menus... */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
273
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
274 int dockable_menubar;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
275
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
276 /* #define TEAR_OFF_MENUS */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
277
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
278 #ifdef TEAR_OFF_MENUS
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
279 int tear_off_menus;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
280 #endif
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
281
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
282
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
283 /* Converting from XEmacs to GTK representation */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
284 static Lisp_Object
2054
91d4c8c65a0f [xemacs-hg @ 2004-05-02 04:06:51 by malcolmp]
malcolmp
parents: 1416
diff changeset
285 menu_name_to_accelerator (Ibyte *name)
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
286 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
287 while (*name) {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
288 if (*name=='%') {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
289 ++name;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
290 if (!(*name))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
291 return Qnil;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
292 if (*name=='_' && *(name+1))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
293 {
2054
91d4c8c65a0f [xemacs-hg @ 2004-05-02 04:06:51 by malcolmp]
malcolmp
parents: 1416
diff changeset
294 int accelerator = (int) (*(name+1));
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
295 return make_char (tolower (accelerator));
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
296 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
297 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
298 ++name;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
299 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
300 return Qnil;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
301 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
302
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
303 #define XEMACS_MENU_DESCR_TAG "xemacs::menu::description"
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
304 #define XEMACS_MENU_FILTER_TAG "xemacs::menu::filter"
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
305 #define XEMACS_MENU_GUIID_TAG "xemacs::menu::gui_id"
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
306 #define XEMACS_MENU_FIRSTTIME_TAG "xemacs::menu::first_time"
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
307
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
308 static void __activate_menu(GtkMenuItem *, gpointer);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
309
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
310 #ifdef TEAR_OFF_MENUS
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
311 static void
2286
04bc9d2f42c7 [xemacs-hg @ 2004-09-20 19:18:55 by james]
james
parents: 2168
diff changeset
312 __torn_off_sir(GtkMenuItem *UNUSED (item), gpointer user_data)
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
313 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
314 GtkWidget *menu_item = GTK_WIDGET (user_data);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
315
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
316 if (GTK_TEAROFF_MENU_ITEM (item)->torn_off)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
317 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
318 /* Menu was just torn off */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
319 GUI_ID id = new_gui_id ();
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
320 Lisp_Object menu_desc = Qnil;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
321 GtkWidget *old_submenu = GTK_MENU_ITEM (menu_item)->submenu;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
322
5013
ae48681c47fa changes to VOID_TO_LISP et al.
Ben Wing <ben@xemacs.org>
parents: 4981
diff changeset
323 menu_desc = GET_LISP_FROM_VOID (gtk_object_get_data (GTK_OBJECT (menu_item), XEMACS_MENU_DESCR_TAG));
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
324
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
325 /* GCPRO all of our very own */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
326 gcpro_popup_callbacks (id, menu_desc);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
327
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
328 /* Hide the now detached menu from the attentions of
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
329 __activate_menu destroying the old submenu */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
330 #if 0
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
331 gtk_widget_ref (old_submenu);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
332 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menu_item), gtk_menu_new ());
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
333 gtk_widget_show_all (old_submenu);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
334 #endif
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
335 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
336 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
337 #endif
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
338
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
339 /* This is called when a menu is about to be shown... this is what
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
340 does the delayed creation of the menu items. We populate the
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
341 submenu and away we go. */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
342 static void
2286
04bc9d2f42c7 [xemacs-hg @ 2004-09-20 19:18:55 by james]
james
parents: 2168
diff changeset
343 __maybe_destroy (GtkWidget *child, GtkWidget *UNUSED (precious))
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
344 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
345 if (GTK_IS_MENU_ITEM (child) && !GTK_IS_TEAROFF_MENU_ITEM (child))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
346 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
347 if (GTK_WIDGET_VISIBLE (child))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
348 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
349 /* If we delete the menu item that was 'active' when the
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
350 menu was cancelled, GTK gets upset because it tries to
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
351 remove the focus rectangle from a (now) dead widget.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
352
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
353 This widget will eventually get killed because it will
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
354 not be visible the next time the window is shown.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
355 */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
356 gtk_widget_set_sensitive (child, FALSE);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
357 gtk_widget_hide_all (child);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
358 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
359 else
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
360 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
361 gtk_widget_destroy (child);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
362 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
363 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
364 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
365
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
366 /* If user_data != 0x00 then we are using a hook to build the menu. */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
367 static void
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
368 __activate_menu(GtkMenuItem *item, gpointer user_data)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
369 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
370 Lisp_Object desc;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
371 gpointer force_clear = gtk_object_get_data (GTK_OBJECT (item), XEMACS_MENU_FIRSTTIME_TAG);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
372
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
373 gtk_object_set_data (GTK_OBJECT (item), XEMACS_MENU_FIRSTTIME_TAG, 0x00);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
374
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
375 /* Delete the old contents of the menu if we are the top level menubar */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
376 if (GTK_IS_MENU_BAR (GTK_WIDGET (item)->parent) || force_clear)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
377 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
378 GtkWidget *selected = gtk_menu_get_active (GTK_MENU (item->submenu));
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
379
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
380 gtk_container_foreach (GTK_CONTAINER (item->submenu),(GtkCallback) __maybe_destroy,
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
381 selected);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
382 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
383 else if (gtk_container_children (GTK_CONTAINER (item->submenu)))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
384 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
385 return;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
386 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
387
5013
ae48681c47fa changes to VOID_TO_LISP et al.
Ben Wing <ben@xemacs.org>
parents: 4981
diff changeset
388 desc = GET_LISP_FROM_VOID (gtk_object_get_data (GTK_OBJECT (item), XEMACS_MENU_DESCR_TAG));
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
389
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
390 #ifdef TEAR_OFF_MENUS
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
391 /* Lets stick in a detacher just for giggles */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
392 if (tear_off_menus && !gtk_container_children (GTK_CONTAINER (item->submenu)))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
393 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
394 GtkWidget *w = gtk_tearoff_menu_item_new ();
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
395 gtk_widget_show (w);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
396 gtk_menu_append (GTK_MENU (item->submenu), w);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
397 gtk_signal_connect (GTK_OBJECT (w), "activate", GTK_SIGNAL_FUNC (__torn_off_sir), item);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
398 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
399 #endif
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
400
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
401 if (user_data)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
402 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
403 GUI_ID id = (GUI_ID) gtk_object_get_data (GTK_OBJECT (item), XEMACS_MENU_GUIID_TAG);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
404 Lisp_Object hook_fn;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
405 struct gcpro gcpro1, gcpro2;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
406
5013
ae48681c47fa changes to VOID_TO_LISP et al.
Ben Wing <ben@xemacs.org>
parents: 4981
diff changeset
407 hook_fn = GET_LISP_FROM_VOID (gtk_object_get_data (GTK_OBJECT (item), XEMACS_MENU_FILTER_TAG));
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
408
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
409 GCPRO2 (desc, hook_fn);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
410
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
411 desc = call1 (hook_fn, desc);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
412
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
413 UNGCPRO;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
414
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
415 ungcpro_popup_callbacks (id);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
416 gcpro_popup_callbacks (id, desc);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
417 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
418
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
419 /* Build the child widgets */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
420 for (; !NILP (desc); desc = Fcdr (desc))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
421 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
422 GtkWidget *next = NULL;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
423 Lisp_Object child = Fcar (desc);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
424
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
425 if (NILP (child)) /* the partition */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
426 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
427 /* Signal an error here? The NILP handling is handled a
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
428 layer higher where appropriate */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
429 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
430 else
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
431 {
2081
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
432 next = menu_descriptor_to_widget_1 (child,
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
433 gtk_menu_ensure_uline_accel_group (GTK_MENU (item->submenu)));
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
434 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
435
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
436 if (!next)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
437 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
438 continue;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
439 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
440
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
441 gtk_widget_show_all (next);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
442 gtk_menu_append (GTK_MENU (item->submenu), next);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
443 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
444 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
445
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
446 /* This is called whenever an item with a GUI_ID associated with it is
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
447 destroyed. This allows us to remove the references in gui-gtk.c
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
448 that made sure callbacks and such were GCPRO-ed
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
449 */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
450 static void
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
451 __remove_gcpro_by_id (gpointer user_data)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
452 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
453 ungcpro_popup_callbacks ((GUI_ID) user_data);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
454 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
455
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
456 static void
2286
04bc9d2f42c7 [xemacs-hg @ 2004-09-20 19:18:55 by james]
james
parents: 2168
diff changeset
457 __kill_stupid_gtk_timer (GtkObject *obj, gpointer UNUSED (user_data))
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
458 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
459 GtkMenuItem *mi = GTK_MENU_ITEM (obj);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
460
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
461 if (mi->timer)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
462 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
463 gtk_timeout_remove (mi->timer);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
464 mi->timer = 0;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
465 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
466 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
467
2081
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
468 /* Convert the XEmacs menu accelerator representation to Gtk mnemonic form. If
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
469 no accelerator has been provided, put one at the start of the string (this
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
470 mirrors the behaviour under X). This algorithm is also found in
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
471 dialog-gtk.el:gtk-popup-convert-underscores.
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
472 */
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
473 static char *
2081
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
474 convert_underscores(const Ibyte *name)
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
475 {
2081
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
476 char *rval;
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
477 int i,j;
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
478 int found_accel = FALSE;
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
479 int underscores = 0;
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
480
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
481 for (i = 0; name[i]; ++i)
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
482 if (name[i] == '%' && name[i+1] == '_')
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
483 {
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
484 found_accel = TRUE;
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
485 }
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
486 else if (name[i] == '_')
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
487 {
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
488 underscores++;
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
489 }
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
490
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
491 /* Allocate space for the original string, plus zero byte plus extra space
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
492 for all quoted underscores plus possible additional leading accelerator. */
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
493 rval = (char*) xmalloc_and_zero (qxestrlen(name) + 1 + underscores
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
494 + (found_accel ? 0 : 1));
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
495
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
496 if (!found_accel)
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
497 rval[0] = '_';
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
498
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
499 for (i = 0, j = (found_accel ? 0 : 1); name[i]; i++)
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
500 {
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
501 if (name[i]=='%')
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
502 {
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
503 i++;
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
504 if (!(name[i]))
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
505 continue;
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
506
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
507 if ((name[i] != '_') && (name[i] != '%'))
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
508 i--;
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
509
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
510 found_accel = TRUE;
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
511 }
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
512 else if (name[i] == '_')
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
513 {
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
514 rval[j++] = '_';
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
515 }
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
516
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
517 rval[j++] = name[i];
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
518 }
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
519
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
520 return rval;
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
521 }
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
522
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
523 /* Remove the XEmacs menu accellerator representation from a string. */
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
524 static char *
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
525 remove_underscores(const Ibyte *name)
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
526 {
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
527 char *rval = (char*) xmalloc_and_zero (qxestrlen(name) + 1);
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
528 int i,j;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
529
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
530 for (i = 0, j = 0; name[i]; i++)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
531 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
532 if (name[i]=='%') {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
533 i++;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
534 if (!(name[i]))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
535 continue;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
536
2081
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
537 if ((name[i] != '_') && (name[i] != '%'))
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
538 i--;
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
539 else
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
540 continue;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
541 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
542 rval[j++] = name[i];
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
543 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
544 return rval;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
545 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
546
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
547 /* This converts an entire menu into a GtkMenuItem (with an attached
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
548 submenu). A menu is a list of (STRING [:keyword value]+ [DESCR]+)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
549 DESCR is either a list (meaning a submenu), a vector, or nil (if
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
550 you include a :filter keyword) */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
551 static GtkWidget *
2081
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
552 menu_convert (Lisp_Object desc, GtkWidget *reuse,
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
553 GtkAccelGroup* menubar_accel_group)
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
554 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
555 GtkWidget *menu_item = NULL;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
556 GtkWidget *submenu = NULL;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
557 Lisp_Object key, val;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
558 Lisp_Object include_p = Qnil, hook_fn = Qnil, config_tag = Qnil;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
559 Lisp_Object active_p = Qt;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
560 Lisp_Object accel;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
561 int included_spec = 0;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
562 int active_spec = 0;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
563
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
564 if (STRINGP (XCAR (desc)))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
565 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
566 accel = menu_name_to_accelerator (XSTRING_DATA (XCAR (desc)));
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
567
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
568 if (!reuse)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
569 {
2081
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
570 char *temp_menu_name = convert_underscores (XSTRING_DATA (XCAR (desc)));
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
571 GtkWidget* accel_label = gtk_xemacs_accel_label_new(NULL);
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
572 guint accel_key;
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
573
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
574 gtk_misc_set_alignment (GTK_MISC (accel_label), 0.0, 0.5);
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
575 accel_key = gtk_label_parse_uline (GTK_LABEL (accel_label), temp_menu_name);
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
576
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
577 menu_item = gtk_menu_item_new ();
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
578 gtk_container_add (GTK_CONTAINER (menu_item), accel_label);
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
579 gtk_widget_show (accel_label);
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
580
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
581 if (menubar_accel_group)
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
582 gtk_widget_add_accelerator (menu_item,
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
583 "activate_item",
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
584 menubar_accel_group,
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
585 accel_key, GDK_MOD1_MASK,
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
586 GTK_ACCEL_LOCKED);
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
587 free (temp_menu_name);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
588 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
589 else
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
590 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
591 menu_item = reuse;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
592 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
593
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
594 submenu = gtk_menu_new ();
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
595 gtk_widget_show (menu_item);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
596 gtk_widget_show (submenu);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
597
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
598 if (!reuse)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
599 gtk_signal_connect (GTK_OBJECT (menu_item), "destroy",
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
600 GTK_SIGNAL_FUNC (__kill_stupid_gtk_timer), NULL);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
601
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
602 /* Without this sometimes a submenu gets left on the screen -
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
603 ** urk
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
604 */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
605 if (GTK_MENU_ITEM (menu_item)->submenu)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
606 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
607 gtk_widget_destroy (GTK_MENU_ITEM (menu_item)->submenu);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
608 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
609
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
610 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menu_item), submenu);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
611
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
612 /* We put this bogus menu item in so that GTK does the right
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
613 ** thing when the menu is near the screen border.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
614 **
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
615 ** Aug 29, 2000
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
616 */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
617 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
618 GtkWidget *bogus_item = gtk_menu_item_new_with_label ("A suitably long label here...");
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
619
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
620 gtk_object_set_data (GTK_OBJECT (menu_item), XEMACS_MENU_FIRSTTIME_TAG, (gpointer)0x01);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
621 gtk_widget_show_all (bogus_item);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
622 gtk_menu_append (GTK_MENU (submenu), bogus_item);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
623 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
624
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
625 desc = Fcdr (desc);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
626
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
627 while (key = Fcar (desc), KEYWORDP (key))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
628 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
629 Lisp_Object cascade = desc;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
630 desc = Fcdr (desc);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
631 if (NILP (desc))
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 462
diff changeset
632 sferror ("keyword in menu lacks a value",
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
633 cascade);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
634 val = Fcar (desc);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
635 desc = Fcdr (desc);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
636 if (EQ (key, Q_included))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
637 include_p = val, included_spec = 1;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
638 else if (EQ (key, Q_config))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
639 config_tag = val;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
640 else if (EQ (key, Q_filter))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
641 hook_fn = val;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
642 else if (EQ (key, Q_active))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
643 active_p = val, active_spec = 1;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
644 else if (EQ (key, Q_accelerator))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
645 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
646 #if 0
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
647 if ( SYMBOLP (val)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
648 || CHARP (val))
5013
ae48681c47fa changes to VOID_TO_LISP et al.
Ben Wing <ben@xemacs.org>
parents: 4981
diff changeset
649 wv->accel = STORE_LISP_IN_VOID (val);
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
650 else
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 462
diff changeset
651 invalid_argument ("bad keyboard accelerator", val);
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
652 #endif
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
653 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
654 else if (EQ (key, Q_label))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
655 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
656 /* implement in 21.2 */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
657 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
658 else
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 462
diff changeset
659 invalid_argument ("unknown menu cascade keyword", cascade);
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
660 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
661
5013
ae48681c47fa changes to VOID_TO_LISP et al.
Ben Wing <ben@xemacs.org>
parents: 4981
diff changeset
662 gtk_object_set_data (GTK_OBJECT (menu_item), XEMACS_MENU_DESCR_TAG, STORE_LISP_IN_VOID (desc));
ae48681c47fa changes to VOID_TO_LISP et al.
Ben Wing <ben@xemacs.org>
parents: 4981
diff changeset
663 gtk_object_set_data (GTK_OBJECT (menu_item), XEMACS_MENU_FILTER_TAG, STORE_LISP_IN_VOID (hook_fn));
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
664
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
665 if ((!NILP (config_tag)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
666 && NILP (Fmemq (config_tag, Vmenubar_configuration)))
4677
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 2500
diff changeset
667 || (included_spec &&
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 2500
diff changeset
668 NILP (IGNORE_MULTIPLE_VALUES (Feval (include_p)))))
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
669 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
670 return (NULL);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
671 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
672
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
673 if (active_spec)
4677
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 2500
diff changeset
674 active_p = IGNORE_MULTIPLE_VALUES (Feval (active_p));
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
675
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
676 gtk_widget_set_sensitive (GTK_WIDGET (menu_item), ! NILP (active_p));
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
677 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
678 else
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
679 {
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 462
diff changeset
680 invalid_argument ("menu name (first element) must be a string",
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
681 desc);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
682 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
683
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
684 /* If we are reusing a widget, we need to make sure we clean
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
685 ** everything up.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
686 */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
687 if (reuse)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
688 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
689 gpointer id = gtk_object_get_data (GTK_OBJECT (reuse), XEMACS_MENU_GUIID_TAG);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
690
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
691 if (id)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
692 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
693 /* If the menu item had a GUI_ID that means it was a filter menu */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
694 __remove_gcpro_by_id (id);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
695 gtk_signal_disconnect_by_func (GTK_OBJECT (reuse),
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
696 GTK_SIGNAL_FUNC (__activate_menu),
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
697 (gpointer) 0x01 );
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
698 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
699 else
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
700 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
701 gtk_signal_disconnect_by_func (GTK_OBJECT (reuse),
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
702 GTK_SIGNAL_FUNC (__activate_menu),
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
703 NULL);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
704 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
705
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
706 GTK_MENU_ITEM (reuse)->right_justify = 0;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
707 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
708
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
709 if (NILP (hook_fn))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
710 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
711 /* Generic menu builder */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
712 gtk_signal_connect (GTK_OBJECT (menu_item), "activate",
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
713 GTK_SIGNAL_FUNC (__activate_menu),
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
714 NULL);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
715 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
716 else
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
717 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
718 GUI_ID id = new_gui_id ();
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
719
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
720 gtk_object_set_data (GTK_OBJECT (menu_item), XEMACS_MENU_GUIID_TAG,
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
721 (gpointer) id);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
722
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
723 /* Make sure we gcpro the menu descriptions */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
724 gcpro_popup_callbacks (id, desc);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
725 gtk_object_weakref (GTK_OBJECT (menu_item), __remove_gcpro_by_id,
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
726 (gpointer) id);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
727
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
728 gtk_signal_connect (GTK_OBJECT (menu_item), "activate",
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
729 GTK_SIGNAL_FUNC (__activate_menu),
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
730 (gpointer) 0x01);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
731 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
732
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
733 return (menu_item);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
734 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
735
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
736 /* Called whenever a button, radio, or toggle is selected in the menu */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
737 static void
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
738 __generic_button_callback (GtkMenuItem *item, gpointer user_data)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
739 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
740 Lisp_Object callback, function, data, channel;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
741
2168
95fee4a1420e [xemacs-hg @ 2004-07-07 12:00:58 by malcolmp]
malcolmp
parents: 2081
diff changeset
742 channel = wrap_frame (gtk_widget_to_frame (GTK_WIDGET (item)));
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
743
5013
ae48681c47fa changes to VOID_TO_LISP et al.
Ben Wing <ben@xemacs.org>
parents: 4981
diff changeset
744 callback = GET_LISP_FROM_VOID (user_data);
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
745
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
746 get_gui_callback (callback, &function, &data);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
747
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
748 signal_special_gtk_user_event (channel, function, data);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
749 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
750
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
751 /* Convert a single menu item descriptor to a suitable GtkMenuItem */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
752 /* This function cannot GC.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
753 It is only called from menu_item_descriptor_to_widget_value, which
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
754 prohibits GC. */
1416
b0c1d9dc4b08 [xemacs-hg @ 2003-04-15 17:21:34 by stephent]
stephent
parents: 1346
diff changeset
755 static GtkWidget *
2081
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
756 menu_descriptor_to_widget_1 (Lisp_Object descr, GtkAccelGroup* accel_group)
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
757 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
758 if (STRINGP (descr))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
759 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
760 /* It is a separator. Unfortunately GTK does not allow us to
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
761 specify what our separators look like, so we can't do all the
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
762 fancy stuff that the X code does.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
763 */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
764 return (gtk_menu_item_new ());
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
765 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
766 else if (LISTP (descr))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
767 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
768 /* It is a submenu */
2081
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
769 return (menu_convert (descr, NULL, accel_group));
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
770 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
771 else if (VECTORP (descr))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
772 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
773 /* An actual menu item description! This gets yucky. */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
774 Lisp_Object name = Qnil;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
775 Lisp_Object callback = Qnil;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
776 Lisp_Object suffix = Qnil;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
777 Lisp_Object active_p = Qt;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
778 Lisp_Object include_p = Qt;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
779 Lisp_Object selected_p = Qnil;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
780 Lisp_Object keys = Qnil;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
781 Lisp_Object style = Qnil;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
782 Lisp_Object config_tag = Qnil;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
783 Lisp_Object accel = Qnil;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
784 GtkWidget *main_label = NULL;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
785 int length = XVECTOR_LENGTH (descr);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
786 Lisp_Object *contents = XVECTOR_DATA (descr);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
787 int plist_p;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
788 int selected_spec = 0, included_spec = 0;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
789 GtkWidget *widget = NULL;
2081
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
790 guint accel_key;
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
791
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
792 if (length < 2)
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 462
diff changeset
793 sferror ("button descriptors must be at least 2 long", descr);
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
794
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
795 /* length 2: [ "name" callback ]
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
796 length 3: [ "name" callback active-p ]
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
797 length 4: [ "name" callback active-p suffix ]
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
798 or [ "name" callback keyword value ]
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
799 length 5+: [ "name" callback [ keyword value ]+ ]
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
800 */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
801 plist_p = (length >= 5 || (length > 2 && KEYWORDP (contents [2])));
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
802
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
803 if (!plist_p && length > 2)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
804 /* the old way */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
805 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
806 name = contents [0];
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
807 callback = contents [1];
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
808 active_p = contents [2];
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
809 if (length == 4)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
810 suffix = contents [3];
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
811 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
812 else
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
813 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
814 /* the new way */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
815 int i;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
816 if (length & 1)
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 462
diff changeset
817 sferror (
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
818 "button descriptor has an odd number of keywords and values",
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
819 descr);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
820
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
821 name = contents [0];
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
822 callback = contents [1];
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
823 for (i = 2; i < length;)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
824 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
825 Lisp_Object key = contents [i++];
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
826 Lisp_Object val = contents [i++];
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
827 if (!KEYWORDP (key))
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 462
diff changeset
828 invalid_argument_2 ("not a keyword", key, descr);
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
829
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
830 if (EQ (key, Q_active)) active_p = val;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
831 else if (EQ (key, Q_suffix)) suffix = val;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
832 else if (EQ (key, Q_keys)) keys = val;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
833 else if (EQ (key, Q_key_sequence)) ; /* ignored for FSF compat */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
834 else if (EQ (key, Q_label)) ; /* implement for 21.0 */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
835 else if (EQ (key, Q_style)) style = val;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
836 else if (EQ (key, Q_selected)) selected_p = val, selected_spec = 1;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
837 else if (EQ (key, Q_included)) include_p = val, included_spec = 1;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
838 else if (EQ (key, Q_config)) config_tag = val;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
839 else if (EQ (key, Q_accelerator))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
840 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
841 if ( SYMBOLP (val) || CHARP (val))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
842 accel = val;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
843 else
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 462
diff changeset
844 invalid_argument ("bad keyboard accelerator", val);
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
845 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
846 else if (EQ (key, Q_filter))
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 462
diff changeset
847 sferror(":filter keyword not permitted on leaf nodes", descr);
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
848 else
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 462
diff changeset
849 invalid_argument_2 ("unknown menu item keyword", key, descr);
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
850 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
851 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
852
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
853 #ifdef HAVE_MENUBARS
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
854 if ((!NILP (config_tag) && NILP (Fmemq (config_tag, Vmenubar_configuration)))
4677
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 2500
diff changeset
855 || (included_spec && NILP (IGNORE_MULTIPLE_VALUES (Feval (include_p)))))
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 2500
diff changeset
856
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
857 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
858 /* the include specification says to ignore this item. */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
859 return 0;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
860 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
861 #endif /* HAVE_MENUBARS */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
862
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
863 CHECK_STRING (name);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
864
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
865 if (NILP (accel))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
866 accel = menu_name_to_accelerator (XSTRING_DATA (name));
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
867
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
868 if (!NILP (suffix))
4677
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 2500
diff changeset
869 suffix = IGNORE_MULTIPLE_VALUES (Feval (suffix));
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 2500
diff changeset
870
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
871
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
872 if (!separator_string_p (XSTRING_DATA (name)))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
873 {
2054
91d4c8c65a0f [xemacs-hg @ 2004-05-02 04:06:51 by malcolmp]
malcolmp
parents: 1416
diff changeset
874 Ibyte *label_buffer = NULL;
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
875 char *temp_label = NULL;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
876
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
877 if (STRINGP (suffix) && XSTRING_LENGTH (suffix))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
878 {
2367
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
879 /* !!#### */
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
880 label_buffer = alloca_ibytes (XSTRING_LENGTH (name) + 15 + XSTRING_LENGTH (suffix));
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
881 qxesprintf (label_buffer, "%s %s ", XSTRING_DATA (name),
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
882 XSTRING_DATA (suffix));
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
883 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
884 else
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
885 {
2367
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
886 label_buffer = alloca_ibytes (XSTRING_LENGTH (name) + 15);
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
887 qxesprintf (label_buffer, "%s ", XSTRING_DATA (name));
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
888 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
889
2081
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
890 temp_label = convert_underscores (label_buffer);
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
891 main_label = gtk_xemacs_accel_label_new (NULL);
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
892 accel_key = gtk_label_parse_uline (GTK_LABEL (main_label), temp_label);
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
893 free (temp_label);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
894 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
895
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
896 /* Evaluate the selected and active items now */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
897 if (selected_spec)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
898 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
899 if (NILP (selected_p) || EQ (selected_p, Qt))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
900 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
901 /* Do nothing */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
902 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
903 else
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
904 {
4677
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 2500
diff changeset
905 selected_p = IGNORE_MULTIPLE_VALUES (Feval (selected_p));
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
906 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
907 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
908
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
909 if (NILP (active_p) || EQ (active_p, Qt))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
910 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
911 /* Do Nothing */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
912 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
913 else
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
914 {
4677
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 2500
diff changeset
915 active_p = IGNORE_MULTIPLE_VALUES (Feval (active_p));
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
916 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
917
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
918 if (0 ||
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
919 #ifdef HAVE_MENUBARS
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
920 menubar_show_keybindings
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
921 #endif
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
922 )
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
923 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
924 /* Need to get keybindings */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
925 if (!NILP (keys))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
926 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
927 /* User-specified string to generate key bindings with */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
928 CHECK_STRING (keys);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
929
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
930 keys = Fsubstitute_command_keys (keys);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
931 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
932 else if (SYMBOLP (callback))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
933 {
793
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 771
diff changeset
934 DECLARE_EISTRING_MALLOC (buf);
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
935
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
936 /* #### Warning, dependency here on current_buffer and point */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
937 where_is_to_char (callback, buf);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
938
833
ee2d33cfc3c1 [xemacs-hg @ 2002-05-09 13:49:39 by wmperry]
wmperry
parents: 826
diff changeset
939 if (eilen (buf) > 0)
ee2d33cfc3c1 [xemacs-hg @ 2002-05-09 13:49:39 by wmperry]
wmperry
parents: 826
diff changeset
940 keys = eimake_string (buf);
ee2d33cfc3c1 [xemacs-hg @ 2002-05-09 13:49:39 by wmperry]
wmperry
parents: 826
diff changeset
941 else
ee2d33cfc3c1 [xemacs-hg @ 2002-05-09 13:49:39 by wmperry]
wmperry
parents: 826
diff changeset
942 {
ee2d33cfc3c1 [xemacs-hg @ 2002-05-09 13:49:39 by wmperry]
wmperry
parents: 826
diff changeset
943
ee2d33cfc3c1 [xemacs-hg @ 2002-05-09 13:49:39 by wmperry]
wmperry
parents: 826
diff changeset
944 keys = Qnil;
ee2d33cfc3c1 [xemacs-hg @ 2002-05-09 13:49:39 by wmperry]
wmperry
parents: 826
diff changeset
945 }
ee2d33cfc3c1 [xemacs-hg @ 2002-05-09 13:49:39 by wmperry]
wmperry
parents: 826
diff changeset
946
793
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 771
diff changeset
947 eifree (buf);
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
948 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
949 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
950
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
951 /* Now we get down to the dirty business of creating the widgets */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
952 if (NILP (style) || EQ (style, Qtext) || EQ (style, Qbutton))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
953 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
954 /* A normal menu item */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
955 widget = gtk_menu_item_new ();
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
956 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
957 else if (EQ (style, Qtoggle) || EQ (style, Qradio))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
958 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
959 /* They are radio or toggle buttons.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
960
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
961 XEmacs' menu descriptions are fairly lame in that they do
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
962 not have the idea of a 'group' of radio buttons. They
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
963 are exactly like toggle buttons except that they get
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
964 drawn differently.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
965
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
966 GTK rips us a new one again. If you have a radio button
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
967 in a group by itself, it always draws it as highlighted.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
968 So we dummy up and create a second radio button that does
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
969 not get added to the menu, but gets invisibly set/unset
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
970 when the other gets unset/set. *sigh*
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
971
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
972 */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
973 if (EQ (style, Qradio))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
974 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
975 GtkWidget *dummy_sibling = NULL;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
976 GSList *group = NULL;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
977
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
978 dummy_sibling = gtk_radio_menu_item_new (group);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
979 group = gtk_radio_menu_item_group (GTK_RADIO_MENU_ITEM (dummy_sibling));
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
980 widget = gtk_radio_menu_item_new (group);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
981
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
982 /* We need to notice when the 'real' one gets destroyed
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
983 so we can clean up the dummy as well. */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
984 gtk_object_weakref (GTK_OBJECT (widget),
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
985 (GtkDestroyNotify) gtk_widget_destroy,
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
986 dummy_sibling);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
987 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
988 else
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
989 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
990 widget = gtk_check_menu_item_new ();
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
991 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
992
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
993 /* What horrible defaults you have GTK dear! The default
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
994 for a toggle menu item is to not show the toggle unless it
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
995 is turned on or actively highlighted. How absolutely
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
996 hideous. */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
997 gtk_check_menu_item_set_show_toggle (GTK_CHECK_MENU_ITEM (widget), TRUE);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
998 gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (widget),
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
999 NILP (selected_p) ? FALSE : TRUE);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1000 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1001 else
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1002 {
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 462
diff changeset
1003 invalid_argument_2 ("unknown style", style, descr);
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1004 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1005
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1006 gtk_widget_set_sensitive (widget, ! NILP (active_p));
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1007
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1008 gtk_signal_connect (GTK_OBJECT (widget), "activate-item",
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1009 GTK_SIGNAL_FUNC (__generic_button_callback),
5013
ae48681c47fa changes to VOID_TO_LISP et al.
Ben Wing <ben@xemacs.org>
parents: 4981
diff changeset
1010 STORE_LISP_IN_VOID (callback));
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1011
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1012 gtk_signal_connect (GTK_OBJECT (widget), "activate",
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1013 GTK_SIGNAL_FUNC (__generic_button_callback),
5013
ae48681c47fa changes to VOID_TO_LISP et al.
Ben Wing <ben@xemacs.org>
parents: 4981
diff changeset
1014 STORE_LISP_IN_VOID (callback));
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1015
2081
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
1016 /* Now that all the information about the menu item is know, set the
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
1017 remaining properties.
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1018 */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1019
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1020 if (main_label)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1021 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1022 gtk_container_add (GTK_CONTAINER (widget), main_label);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1023
2081
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
1024 gtk_misc_set_alignment (GTK_MISC (main_label), 0.0, 0.5);
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
1025 gtk_xemacs_set_accel_keys(GTK_XEMACS_ACCEL_LABEL(main_label), keys);
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1026
2081
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
1027 if (accel_group)
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
1028 gtk_widget_add_accelerator (widget,
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
1029 "activate_item",
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
1030 accel_group,
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
1031 accel_key, 0,
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
1032 GTK_ACCEL_LOCKED);
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1033 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1034
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1035 return (widget);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1036 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1037 else
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1038 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1039 return (NULL);
2500
3d8143fc88e1 [xemacs-hg @ 2005-01-24 23:33:30 by ben]
ben
parents: 2367
diff changeset
1040 /* ABORT (); ???? */
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1041 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1042 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1043
1416
b0c1d9dc4b08 [xemacs-hg @ 2003-04-15 17:21:34 by stephent]
stephent
parents: 1346
diff changeset
1044 static GtkWidget *
2081
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
1045 menu_descriptor_to_widget (Lisp_Object descr, GtkAccelGroup* accel_group)
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1046 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1047 GtkWidget *rval = NULL;
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 714
diff changeset
1048 int count = begin_gc_forbidden ();
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1049
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1050 /* Cannot GC from here on out... */
2081
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
1051 rval = menu_descriptor_to_widget_1 (descr, accel_group);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 714
diff changeset
1052 unbind_to (count);
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1053 return (rval);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1054
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1055 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1056
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1057 static gboolean
2054
91d4c8c65a0f [xemacs-hg @ 2004-05-02 04:06:51 by malcolmp]
malcolmp
parents: 1416
diff changeset
1058 menu_can_reuse_widget (GtkWidget *child, const Ibyte *label)
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1059 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1060 /* Everything up at the top level was done using
2081
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
1061 ** gtk_xemacs_accel_label_new(), but we still double check to make
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1062 ** sure we don't seriously foobar ourselves.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1063 */
2081
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
1064 gpointer possible_child =
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
1065 g_list_nth_data (gtk_container_children (GTK_CONTAINER (child)), 0);
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
1066 gboolean ret_val = FALSE;
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1067
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1068 if (possible_child && GTK_IS_LABEL (possible_child))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1069 {
2081
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
1070 char *temp_label = remove_underscores (label);
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
1071
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1072 if (!strcmp (GTK_LABEL (possible_child)->label, temp_label))
2081
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
1073 ret_val = TRUE;
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
1074
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
1075 free (temp_label);
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1076 }
2081
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
1077
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
1078 return ret_val;
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1079 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1080
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1081 /* Converts a menubar description into a GtkMenuBar... a menubar is a
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1082 list of menus or buttons
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1083 */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1084 static void
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1085 menu_create_menubar (struct frame *f, Lisp_Object descr)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1086 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1087 gboolean right_justify = FALSE;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1088 Lisp_Object value = descr;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1089 GtkWidget *menubar = FRAME_GTK_MENUBAR_WIDGET (f);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1090 GUI_ID id = (GUI_ID) gtk_object_get_data (GTK_OBJECT (menubar), XEMACS_MENU_GUIID_TAG);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1091 guint menu_position = 0;
2081
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
1092 GtkAccelGroup *menubar_accel_group;
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1093
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1094 /* Remove any existing protection for old menu items */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1095 ungcpro_popup_callbacks (id);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1096
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1097 /* GCPRO the whole damn thing */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1098 gcpro_popup_callbacks (id, descr);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1099
2081
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
1100 menubar_accel_group = gtk_accel_group_new();
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
1101
2367
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
1102 {
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
1103 EXTERNAL_LIST_LOOP_2 (item_descr, value)
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
1104 {
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
1105 gpointer current_child = g_list_nth_data (GTK_MENU_SHELL (menubar)->children, menu_position);
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1106
2367
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
1107 if (NILP (item_descr))
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
1108 {
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
1109 /* Need to start right-justifying menus */
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
1110 right_justify = TRUE;
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
1111 menu_position--;
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
1112 }
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
1113 else if (VECTORP (item_descr))
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
1114 {
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
1115 /* It is a button description */
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
1116 GtkWidget *item;
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1117
2367
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
1118 item = menu_descriptor_to_widget (item_descr, menubar_accel_group);
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
1119 gtk_widget_set_name (item, "XEmacsMenuButton");
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
1120
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
1121 if (!item)
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
1122 {
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
1123 item = gtk_menu_item_new_with_label ("ITEM CREATION ERROR");
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
1124 }
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1125
2367
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
1126 gtk_widget_show_all (item);
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
1127 if (current_child) gtk_widget_destroy (GTK_WIDGET (current_child));
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
1128 gtk_menu_bar_insert (GTK_MENU_BAR (menubar), item, menu_position);
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
1129 }
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
1130 else if (LISTP (item_descr))
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
1131 {
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
1132 /* Need to actually convert it into a menu and slap it in */
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
1133 GtkWidget *widget;
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
1134 gboolean reused_p = FALSE;
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1135
2367
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
1136 /* We may be able to reuse the widget, let's at least check. */
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
1137 if (current_child && menu_can_reuse_widget (GTK_WIDGET (current_child),
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
1138 XSTRING_DATA (XCAR (item_descr))))
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
1139 {
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
1140 widget = menu_convert (item_descr, GTK_WIDGET (current_child),
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
1141 menubar_accel_group);
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
1142 reused_p = TRUE;
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
1143 }
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
1144 else
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
1145 {
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
1146 widget = menu_convert (item_descr, NULL, menubar_accel_group);
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
1147 if (current_child) gtk_widget_destroy (GTK_WIDGET (current_child));
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
1148 gtk_menu_bar_insert (GTK_MENU_BAR (menubar), widget, menu_position);
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
1149 }
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1150
2367
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
1151 if (widget)
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
1152 {
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
1153 if (right_justify) gtk_menu_item_right_justify (GTK_MENU_ITEM (widget));
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
1154 }
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
1155 else
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
1156 {
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
1157 widget = gtk_menu_item_new_with_label ("ERROR");
2500
3d8143fc88e1 [xemacs-hg @ 2005-01-24 23:33:30 by ben]
ben
parents: 2367
diff changeset
1158 /* ABORT() */
2367
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
1159 }
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
1160 gtk_widget_show_all (widget);
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
1161 }
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
1162 else if (STRINGP (item_descr))
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
1163 {
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
1164 /* Do I really want to be this careful? Anything else in a
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
1165 menubar description is illegal */
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
1166 }
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
1167 menu_position++;
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
1168 }
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
1169 }
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1170
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1171 /* Need to delete any menu items that were past the bounds of the new one */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1172 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1173 GList *l = NULL;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1174
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1175 while ((l = g_list_nth (GTK_MENU_SHELL (menubar)->children, menu_position)))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1176 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1177 gpointer data = l->data;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1178 g_list_remove_link (GTK_MENU_SHELL (menubar)->children, l);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1179
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1180 if (data)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1181 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1182 gtk_widget_destroy (GTK_WIDGET (data));
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1183 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1184 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1185 }
2081
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
1186
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
1187 /* Attach the new accelerator group to the frame. */
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
1188 gtk_window_add_accel_group (GTK_WINDOW (FRAME_GTK_SHELL_WIDGET(f)),
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
1189 menubar_accel_group);
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1190 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1191
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1192
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1193 /* Deal with getting/setting the menubar */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1194 #ifndef GNOME_IS_APP
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1195 #define GNOME_IS_APP(x) 0
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1196 #define gnome_app_set_menus(x,y)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1197 #endif
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1198
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1199 static gboolean
2286
04bc9d2f42c7 [xemacs-hg @ 2004-09-20 19:18:55 by james]
james
parents: 2168
diff changeset
1200 run_menubar_hook (GtkWidget *widget, GdkEventButton *UNUSED (event),
04bc9d2f42c7 [xemacs-hg @ 2004-09-20 19:18:55 by james]
james
parents: 2168
diff changeset
1201 gpointer UNUSED (user_data))
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1202 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1203 if (!GTK_MENU_SHELL(widget)->active)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1204 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1205 run_hook (Qactivate_menubar_hook);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1206 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1207 return(FALSE);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1208 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1209
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1210 static void
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1211 create_menubar_widget (struct frame *f)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1212 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1213 GUI_ID id = new_gui_id ();
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1214 GtkWidget *handlebox = NULL;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1215 GtkWidget *menubar = gtk_xemacs_menubar_new (f);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1216
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1217 if (GNOME_IS_APP (FRAME_GTK_SHELL_WIDGET (f)))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1218 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1219 gnome_app_set_menus (GNOME_APP (FRAME_GTK_SHELL_WIDGET (f)), GTK_MENU_BAR (menubar));
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1220 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1221 else if (dockable_menubar)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1222 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1223 handlebox = gtk_handle_box_new ();
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1224 gtk_handle_box_set_handle_position (GTK_HANDLE_BOX (handlebox), GTK_POS_LEFT);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1225 gtk_container_add (GTK_CONTAINER (handlebox), menubar);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1226 gtk_box_pack_start (GTK_BOX (FRAME_GTK_CONTAINER_WIDGET (f)), handlebox, FALSE, FALSE, 0);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1227 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1228 else
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1229 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1230 gtk_box_pack_start (GTK_BOX (FRAME_GTK_CONTAINER_WIDGET (f)), menubar, FALSE, FALSE, 0);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1231 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1232
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1233 gtk_signal_connect (GTK_OBJECT (menubar), "button-press-event",
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1234 GTK_SIGNAL_FUNC (run_menubar_hook), NULL);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1235
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1236 FRAME_GTK_MENUBAR_WIDGET (f) = menubar;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1237 gtk_object_set_data (GTK_OBJECT (menubar), XEMACS_MENU_GUIID_TAG, (gpointer) id);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1238 gtk_object_weakref (GTK_OBJECT (menubar), __remove_gcpro_by_id, (gpointer) id);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1239 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1240
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1241 static int
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1242 set_frame_menubar (struct frame *f, int first_time_p)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1243 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1244 Lisp_Object menubar;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1245 int menubar_visible;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1246 /* As for the toolbar, the minibuffer does not have its own menubar. */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1247 struct window *w = XWINDOW (FRAME_LAST_NONMINIBUF_WINDOW (f));
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1248
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1249 if (! FRAME_GTK_P (f))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1250 return 0;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1251
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1252 /***** first compute the contents of the menubar *****/
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1253
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1254 if (! first_time_p)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1255 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1256 /* evaluate `current-menubar' in the buffer of the selected window
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1257 of the frame in question. */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1258 menubar = symbol_value_in_buffer (Qcurrent_menubar, w->buffer);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1259 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1260 else
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1261 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1262 /* That's a little tricky the first time since the frame isn't
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1263 fully initialized yet. */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1264 menubar = Fsymbol_value (Qcurrent_menubar);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1265 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1266
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1267 if (NILP (menubar))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1268 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1269 menubar = Vblank_menubar;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1270 menubar_visible = 0;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1271 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1272 else
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1273 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1274 menubar_visible = !NILP (w->menubar_visible_p);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1275 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1276
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1277 if (!FRAME_GTK_MENUBAR_WIDGET (f))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1278 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1279 create_menubar_widget (f);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1280 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1281
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1282 /* Populate the menubar, but nothing is shown yet */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1283 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1284 Lisp_Object old_buffer;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1285 int count = specpdl_depth ();
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1286
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1287 old_buffer = Fcurrent_buffer ();
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1288 record_unwind_protect (Fset_buffer, old_buffer);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1289 Fset_buffer (XWINDOW (FRAME_SELECTED_WINDOW (f))->buffer);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1290
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1291 menu_create_menubar (f, menubar);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1292
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1293 Fset_buffer (old_buffer);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 714
diff changeset
1294 unbind_to (count);
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1295 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1296
1346
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1242
diff changeset
1297 FRAME_GTK_MENUBAR_DATA (f) = Fcons (XWINDOW (FRAME_LAST_NONMINIBUF_WINDOW (f))->buffer, Qt);
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1298
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1299 return (menubar_visible);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1300 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1301
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1302 /* Called from gtk_create_widgets() to create the inital menubar of a frame
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1303 before it is mapped, so that the window is mapped with the menubar already
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1304 there instead of us tacking it on later and thrashing the window after it
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1305 is visible. */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1306 int
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1307 gtk_initialize_frame_menubar (struct frame *f)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1308 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1309 create_menubar_widget (f);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1310 return set_frame_menubar (f, 1);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1311 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1312
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1313
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1314 static void
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1315 gtk_update_frame_menubar_internal (struct frame *f)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1316 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1317 /* We assume the menubar contents has changed if the global flag is set,
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1318 or if the current buffer has changed, or if the menubar has never
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1319 been updated before.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1320 */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1321 int menubar_contents_changed =
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1322 (f->menubar_changed
1346
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1242
diff changeset
1323 || NILP (FRAME_GTK_MENUBAR_DATA (f))
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1242
diff changeset
1324 || (!EQ (XFRAME_GTK_MENUBAR_DATA_LASTBUFF (f),
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1325 XWINDOW (FRAME_LAST_NONMINIBUF_WINDOW (f))->buffer)));
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1326
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1327 gboolean menubar_was_visible = GTK_WIDGET_VISIBLE (FRAME_GTK_MENUBAR_WIDGET (f));
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1328 gboolean menubar_will_be_visible = menubar_was_visible;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1329 gboolean menubar_visibility_changed;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1330
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1331 if (menubar_contents_changed)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1332 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1333 menubar_will_be_visible = set_frame_menubar (f, 0);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1334 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1335
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1336 menubar_visibility_changed = menubar_was_visible != menubar_will_be_visible;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1337
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1338 if (!menubar_visibility_changed)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1339 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1340 return;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1341 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1342
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1343 /* We hide and show the menubar's parent (which is actually the
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1344 GtkHandleBox)... this is to simplify the code that destroys old
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1345 menu items, etc. There is no easy way to get the child out of a
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1346 handle box, and I didn't want to add yet another stupid widget
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1347 slot to struct gtk_frame. */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1348 if (menubar_will_be_visible)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1349 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1350 gtk_widget_show_all (FRAME_GTK_MENUBAR_WIDGET (f)->parent);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1351 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1352 else
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1353 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1354 gtk_widget_hide_all (FRAME_GTK_MENUBAR_WIDGET (f)->parent);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1355 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1356
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1357 MARK_FRAME_SIZE_SLIPPED (f);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1358 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1359
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1360 static void
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1361 gtk_update_frame_menubars (struct frame *f)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1362 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1363 GtkWidget *menubar = NULL;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1364
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1365 assert (FRAME_GTK_P (f));
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1366
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1367 menubar = FRAME_GTK_MENUBAR_WIDGET (f);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1368
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1369 if ((GTK_MENU_SHELL (menubar)->active) ||
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1370 (GTK_MENU_SHELL (menubar)->have_grab) ||
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1371 (GTK_MENU_SHELL (menubar)->have_xgrab))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1372 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1373 return;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1374 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1375
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1376 gtk_update_frame_menubar_internal (f);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1377 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1378
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1379 static void
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1380 gtk_free_frame_menubars (struct frame *f)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1381 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1382 GtkWidget *menubar_widget;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1383
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1384 assert (FRAME_GTK_P (f));
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1385
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1386 menubar_widget = FRAME_GTK_MENUBAR_WIDGET (f);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1387 if (menubar_widget)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1388 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1389 gtk_widget_destroy (menubar_widget);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1390 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1391 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1392
1416
b0c1d9dc4b08 [xemacs-hg @ 2003-04-15 17:21:34 by stephent]
stephent
parents: 1346
diff changeset
1393 static void
2286
04bc9d2f42c7 [xemacs-hg @ 2004-09-20 19:18:55 by james]
james
parents: 2168
diff changeset
1394 popdown_menu_cb (GtkMenuShell *UNUSED (menu), gpointer UNUSED (user_data))
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1395 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1396 popup_up_p--;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1397 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1398
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1399 static void
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1400 gtk_popup_menu (Lisp_Object menu_desc, Lisp_Object event)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1401 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1402 struct Lisp_Event *eev = NULL;
714
02339d4ebed4 [xemacs-hg @ 2001-12-23 20:28:19 by wmperry]
wmperry
parents: 563
diff changeset
1403 GtkWidget *widget = NULL;
02339d4ebed4 [xemacs-hg @ 2001-12-23 20:28:19 by wmperry]
wmperry
parents: 563
diff changeset
1404 GtkWidget *menu = NULL;
02339d4ebed4 [xemacs-hg @ 2001-12-23 20:28:19 by wmperry]
wmperry
parents: 563
diff changeset
1405 gpointer id = NULL;
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1406
714
02339d4ebed4 [xemacs-hg @ 2001-12-23 20:28:19 by wmperry]
wmperry
parents: 563
diff changeset
1407 /* Do basic error checking first... */
02339d4ebed4 [xemacs-hg @ 2001-12-23 20:28:19 by wmperry]
wmperry
parents: 563
diff changeset
1408 if (SYMBOLP (menu_desc))
02339d4ebed4 [xemacs-hg @ 2001-12-23 20:28:19 by wmperry]
wmperry
parents: 563
diff changeset
1409 menu_desc = Fsymbol_value (menu_desc);
02339d4ebed4 [xemacs-hg @ 2001-12-23 20:28:19 by wmperry]
wmperry
parents: 563
diff changeset
1410 CHECK_CONS (menu_desc);
02339d4ebed4 [xemacs-hg @ 2001-12-23 20:28:19 by wmperry]
wmperry
parents: 563
diff changeset
1411 CHECK_STRING (XCAR (menu_desc));
02339d4ebed4 [xemacs-hg @ 2001-12-23 20:28:19 by wmperry]
wmperry
parents: 563
diff changeset
1412
02339d4ebed4 [xemacs-hg @ 2001-12-23 20:28:19 by wmperry]
wmperry
parents: 563
diff changeset
1413 /* Now lets get down to business... */
2081
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
1414 widget = menu_descriptor_to_widget (menu_desc, NULL);
714
02339d4ebed4 [xemacs-hg @ 2001-12-23 20:28:19 by wmperry]
wmperry
parents: 563
diff changeset
1415 menu = GTK_MENU_ITEM (widget)->submenu;
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1416 gtk_widget_set_name (widget, "XEmacsPopupMenu");
714
02339d4ebed4 [xemacs-hg @ 2001-12-23 20:28:19 by wmperry]
wmperry
parents: 563
diff changeset
1417 id = gtk_object_get_data (GTK_OBJECT (widget), XEMACS_MENU_GUIID_TAG);
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1418
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1419 __activate_menu (GTK_MENU_ITEM (widget), id);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1420
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1421 if (!NILP (event))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1422 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1423 CHECK_LIVE_EVENT (event);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1424 eev = XEVENT (event);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1425
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1426 if ((eev->event_type != button_press_event) &&
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1427 (eev->event_type != button_release_event))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1428 wrong_type_argument (Qmouse_event_p, event);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1429 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1430 else if (!NILP (Vthis_command_keys))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1431 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1432 /* If an event wasn't passed, use the last event of the event
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1433 sequence currently being executed, if that event is a mouse
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1434 event. */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1435 eev = XEVENT (Vthis_command_keys);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1436 if ((eev->event_type != button_press_event) &&
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1437 (eev->event_type != button_release_event))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1438 eev = NULL;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1439 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1440
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1441 gtk_widget_show (menu);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1442
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1443 popup_up_p++;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1444 gtk_signal_connect (GTK_OBJECT (menu), "deactivate",
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1445 GTK_SIGNAL_FUNC (popdown_menu_cb), NULL);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1446
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1447 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
1204
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 876
diff changeset
1448 eev ? EVENT_BUTTON_BUTTON (eev) : 0,
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1449 eev ? eev->timestamp : GDK_CURRENT_TIME);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1450 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1451
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1452 DEFUN ("gtk-build-xemacs-menu", Fgtk_build_xemacs_menu, 1, 1, 0, /*
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1453 Returns a GTK menu item from MENU, a standard XEmacs menu description.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1454 See the definition of `popup-menu' for more information on the format of MENU.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1455 */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1456 (menu))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1457 {
2081
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
1458 GtkWidget *w = menu_descriptor_to_widget (menu, NULL);
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1459
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1460 return (w ? build_gtk_object (GTK_OBJECT (w)) : Qnil);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1461 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1463
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1464 void
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1465 syms_of_menubar_gtk (void)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1466 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1467 DEFSUBR (Fgtk_build_xemacs_menu);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1468 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1469
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1470 void
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1471 console_type_create_menubar_gtk (void)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1472 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1473 CONSOLE_HAS_METHOD (gtk, update_frame_menubars);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1474 CONSOLE_HAS_METHOD (gtk, free_frame_menubars);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1475 CONSOLE_HAS_METHOD (gtk, popup_menu);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1476 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1477
1416
b0c1d9dc4b08 [xemacs-hg @ 2003-04-15 17:21:34 by stephent]
stephent
parents: 1346
diff changeset
1478 void
b0c1d9dc4b08 [xemacs-hg @ 2003-04-15 17:21:34 by stephent]
stephent
parents: 1346
diff changeset
1479 reinit_vars_of_menubar_gtk (void)
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1480 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1481 dockable_menubar = 1;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1482 #ifdef TEAR_OFF_MENUS
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1483 tear_off_menus = 1;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1484 #endif
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1485 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1486
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1487 void
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1488 vars_of_menubar_gtk (void)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1489 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1490 Fprovide (intern ("gtk-menubars"));
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1491 DEFVAR_BOOL ("menubar-dockable-p", &dockable_menubar /*
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1492 If non-nil, the frame menubar can be detached into its own top-level window.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1493 */ );
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1494 #ifdef TEAR_OFF_MENUS
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1495 DEFVAR_BOOL ("menubar-tearable-p", &tear_off_menus /*
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1496 If non-nil, menus can be torn off into their own top-level windows.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1497 */ );
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1498 #endif
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1499 }
2081
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
1500
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
1501 /*---------------------------------------------------------------------------*/
e8db6a10ad42 [xemacs-hg @ 2004-05-15 07:31:43 by malcolmp]
malcolmp
parents: 2054
diff changeset
1502