0
|
1 /* Emacs manager widget.
|
|
2 Copyright (C) 1993-1995 Sun Microsystems, Inc.
|
|
3 Copyright (C) 1995 Ben Wing.
|
|
4
|
|
5 This file is part of XEmacs.
|
|
6
|
|
7 XEmacs is free software; you can redistribute it and/or modify it
|
|
8 under the terms of the GNU General Public License as published by the
|
|
9 Free Software Foundation; either version 2, or (at your option) any
|
|
10 later version.
|
|
11
|
|
12 XEmacs is distributed in the hope that it will be useful, but WITHOUT
|
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
15 for more details.
|
|
16
|
|
17 You should have received a copy of the GNU General Public License
|
|
18 along with XEmacs; see the file COPYING. If not, write to
|
|
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
20 Boston, MA 02111-1307, USA. */
|
|
21
|
|
22 /* Synched up with: Not in FSF. */
|
|
23
|
|
24 /* Written by Ben Wing, May, 1994. */
|
|
25
|
|
26 #include <config.h>
|
|
27
|
|
28 #include <X11/StringDefs.h>
|
|
29 #include "EmacsManagerP.h"
|
|
30 #ifdef LWLIB_MENUBARS_MOTIF
|
|
31 #include <Xm/RowColumn.h>
|
|
32 #endif /* LWLIB_MENUBARS_MOTIF */
|
|
33
|
|
34 /* For I, Emacs, am a kind god. Unlike the goddess Athena and the
|
|
35 Titan Motif, I require no ritual sacrifices to placate the lesser
|
|
36 daemons of geometry management. */
|
|
37
|
|
38 static XtResource resources[] = {
|
|
39 #define offset(field) XtOffset(EmacsManagerWidget, emacs_manager.field)
|
|
40 { XtNresizeCallback, XtCCallback, XtRCallback, sizeof(XtCallbackList),
|
|
41 offset(resize_callback), XtRImmediate, (XtPointer) 0 },
|
|
42 { XtNqueryGeometryCallback, XtCCallback, XtRCallback, sizeof(XtCallbackList),
|
|
43 offset(query_geometry_callback), XtRImmediate, (XtPointer) 0 },
|
|
44 { XtNuserData, XtCUserData, XtRPointer, sizeof(XtPointer),
|
|
45 offset(user_data), XtRImmediate, (XtPointer) 0 },
|
|
46 };
|
|
47
|
|
48 /****************************************************************
|
|
49 *
|
|
50 * Full class record constant
|
|
51 *
|
|
52 ****************************************************************/
|
|
53
|
|
54 static XtGeometryResult QueryGeometry (Widget wid,
|
|
55 XtWidgetGeometry *request,
|
|
56 XtWidgetGeometry *reply);
|
|
57 static void Resize (Widget w);
|
|
58 static XtGeometryResult GeometryManager (Widget w, XtWidgetGeometry *request,
|
|
59 XtWidgetGeometry *reply);
|
|
60 static void ChangeManaged (Widget w);
|
|
61 static void Realize (Widget w, Mask *valueMask,
|
|
62 XSetWindowAttributes *attributes);
|
|
63 static void ClassInitialize (void);
|
|
64
|
|
65 EmacsManagerClassRec emacsManagerClassRec = {
|
|
66 {
|
|
67 /* core_class fields */
|
|
68 #ifdef LWLIB_USES_MOTIF
|
|
69 /* superclass */ (WidgetClass) &xmManagerClassRec,
|
|
70 #else
|
|
71 /* superclass */ (WidgetClass) &compositeClassRec,
|
|
72 #endif
|
183
|
73 /* class_name */ "EmacsManager",
|
0
|
74 /* widget_size */ sizeof(EmacsManagerRec),
|
|
75 /* class_initialize */ ClassInitialize,
|
|
76 /* class_part_init */ NULL,
|
|
77 /* class_inited */ FALSE,
|
|
78 /* initialize */ NULL,
|
|
79 /* initialize_hook */ NULL,
|
|
80 /* realize */ Realize,
|
|
81 /* actions */ NULL,
|
|
82 /* num_actions */ 0,
|
|
83 /* resources */ resources,
|
|
84 /* num_resources */ XtNumber(resources),
|
|
85 /* xrm_class */ NULLQUARK,
|
|
86 /* compress_motion */ TRUE,
|
|
87 /* compress_exposure */ TRUE,
|
|
88 /* compress_enterleave*/ TRUE,
|
|
89 /* visible_interest */ FALSE,
|
|
90 /* destroy */ NULL,
|
|
91 /* resize */ Resize,
|
|
92 /* expose */ NULL,
|
|
93 /* set_values */ NULL,
|
|
94 /* set_values_hook */ NULL,
|
|
95 /* set_values_almost */ XtInheritSetValuesAlmost,
|
|
96 /* get_values_hook */ NULL,
|
|
97 /* accept_focus */ NULL,
|
|
98 /* version */ XtVersion,
|
|
99 /* callback_private */ NULL,
|
|
100 /* tm_table */ XtInheritTranslations,
|
|
101 /* query_geometry */ QueryGeometry,
|
|
102 /* display_accelerator*/ XtInheritDisplayAccelerator,
|
|
103 /* extension */ NULL
|
|
104 },
|
|
105 {
|
|
106 /* composite_class fields */
|
|
107 /* geometry_manager */ GeometryManager,
|
|
108 /* change_managed */ ChangeManaged,
|
|
109 /* insert_child */ XtInheritInsertChild,
|
|
110 /* delete_child */ XtInheritDeleteChild,
|
|
111 /* extension */ NULL
|
|
112 },
|
|
113 #ifdef LWLIB_USES_MOTIF
|
|
114 {
|
|
115 /* constraint_class fields */
|
183
|
116 NULL, /* resource list */
|
|
117 0, /* num resources */
|
|
118 0, /* constraint size */
|
|
119 (XtInitProc)NULL, /* init proc */
|
|
120 (XtWidgetProc)NULL, /* destroy proc */
|
|
121 (XtSetValuesFunc)NULL, /* set values proc */
|
0
|
122 NULL, /* extension */
|
|
123 },
|
|
124 {
|
|
125 /* manager_class fields */
|
|
126 XtInheritTranslations, /* translations */
|
|
127 NULL, /* syn_resources */
|
|
128 0, /* num_syn_resources */
|
|
129 NULL, /* syn_cont_resources */
|
|
130 0, /* num_syn_cont_resources */
|
|
131 XmInheritParentProcess, /* parent_process */
|
|
132 NULL, /* extension */
|
|
133 },
|
|
134 #endif
|
|
135 {
|
|
136 /* emacs_manager_class fields */
|
|
137 /* empty */ 0,
|
|
138 }
|
|
139 };
|
|
140
|
|
141 WidgetClass emacsManagerWidgetClass = (WidgetClass)&emacsManagerClassRec;
|
|
142
|
|
143 /* What is my preferred size? A suggested size may be given. */
|
|
144
|
|
145 static XtGeometryResult
|
|
146 QueryGeometry (Widget w, XtWidgetGeometry *request, XtWidgetGeometry *reply)
|
|
147 {
|
|
148 EmacsManagerWidget emw = (EmacsManagerWidget) w;
|
|
149 EmacsManagerQueryGeometryStruct struc;
|
|
150 int mask = request->request_mode & (CWWidth | CWHeight);
|
|
151
|
|
152 struc.request_mode = mask;
|
16
|
153 if (mask & CWWidth) struc.proposed_width = request->width;
|
|
154 if (mask & CWHeight) struc.proposed_height = request->height;
|
0
|
155 XtCallCallbackList (w, emw->emacs_manager.query_geometry_callback, &struc);
|
|
156 reply->request_mode = CWWidth | CWHeight;
|
16
|
157 reply->width = struc.proposed_width;
|
0
|
158 reply->height = struc.proposed_height;
|
16
|
159 if (((mask & CWWidth) && (request->width != reply->width)) ||
|
|
160 ((mask & CWHeight) && (request->height != reply->height)))
|
0
|
161 return XtGeometryAlmost;
|
|
162 return XtGeometryYes;
|
|
163 }
|
|
164
|
|
165 static void
|
|
166 Resize (Widget w)
|
|
167 {
|
|
168 EmacsManagerWidget emw = (EmacsManagerWidget) w;
|
|
169 EmacsManagerResizeStruct struc;
|
|
170
|
16
|
171 struc.width = w->core.width;
|
0
|
172 struc.height = w->core.height;
|
|
173 XtCallCallbackList (w, emw->emacs_manager.resize_callback, &struc);
|
|
174 }
|
|
175
|
|
176 static XtGeometryResult
|
|
177 GeometryManager (Widget w, XtWidgetGeometry *request, XtWidgetGeometry *reply)
|
|
178 {
|
|
179 /* Sure, any changes are fine. */
|
|
180 #define COPY(field, mask) \
|
|
181 if (request->request_mode & mask) w->core.field = request->field
|
|
182
|
|
183 /* The Motif menubar will merrily request a new size every time a
|
|
184 child is added or deleted. Blow it off because it doesn't know
|
|
185 what it's talking about. */
|
|
186 #ifdef LWLIB_MENUBARS_MOTIF
|
|
187 if (!(XtClass (w) == xmRowColumnWidgetClass))
|
|
188 #endif /* LWLIB_MENUBARS_MOTIF */
|
|
189 {
|
|
190 COPY (width, CWWidth);
|
|
191 COPY (height, CWHeight);
|
|
192 }
|
|
193 COPY (border_width, CWBorderWidth);
|
|
194 COPY (x, CWX);
|
|
195 COPY (y, CWY);
|
|
196 #undef COPY
|
|
197
|
|
198 return XtGeometryYes;
|
|
199 }
|
|
200
|
|
201 static void
|
|
202 ChangeManaged (Widget w)
|
|
203 {
|
|
204 if (!XtIsRealized (w))
|
|
205 {
|
|
206 XtWidgetGeometry req, repl;
|
|
207
|
|
208 /* find out how big we'd like to be ... */
|
|
209
|
|
210 req.request_mode = 0;
|
|
211 XtQueryGeometry (w, &req, &repl);
|
|
212 EmacsManagerChangeSize (w, repl.width, repl.height);
|
|
213 }
|
|
214 }
|
|
215
|
|
216 static void
|
|
217 Realize (Widget w, Mask *valueMask, XSetWindowAttributes *attributes)
|
|
218 {
|
|
219 attributes->bit_gravity = NorthWestGravity;
|
|
220 *valueMask |= CWBitGravity;
|
183
|
221
|
0
|
222 XtCreateWindow (w, (unsigned) InputOutput, (Visual *) CopyFromParent,
|
|
223 *valueMask, attributes);
|
|
224 }
|
|
225
|
|
226 static void
|
|
227 ClassInitialize (void)
|
|
228 {
|
|
229 return;
|
|
230 }
|
|
231
|
|
232 void
|
|
233 EmacsManagerChangeSize (Widget w, Dimension width, Dimension height)
|
|
234 {
|
|
235 if (width == 0)
|
|
236 width = w->core.width;
|
|
237 if (height == 0)
|
|
238 height = w->core.height;
|
|
239
|
|
240 /* do nothing if we're already that size */
|
|
241 if (w->core.width != width || w->core.height != height)
|
16
|
242 if (XtMakeResizeRequest (w, width, height, &w->core.width, &w->core.height)
|
|
243 == XtGeometryAlmost)
|
|
244 XtMakeResizeRequest (w, w->core.width, w->core.height, NULL, NULL);
|
0
|
245
|
|
246 Resize (w);
|
|
247 }
|
|
248
|
|
249
|