428
+ − 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)
440
+ − 40 { XtNresizeCallback, XtCCallback,
+ − 41 XtRCallback, sizeof (XtCallbackList),
+ − 42 offset(resize_callback), XtRImmediate, (XtPointer) 0 },
+ − 43 { XtNqueryGeometryCallback, XtCCallback,
+ − 44 XtRCallback, sizeof (XtCallbackList),
+ − 45 offset(query_geometry_callback), XtRImmediate, (XtPointer) 0 },
+ − 46 { XtNuserData, XtCUserData,
+ − 47 XtRPointer, sizeof (XtPointer),
+ − 48 offset(user_data), XtRImmediate, (XtPointer) 0 },
428
+ − 49 };
+ − 50
+ − 51 /****************************************************************
+ − 52 *
+ − 53 * Full class record constant
+ − 54 *
+ − 55 ****************************************************************/
+ − 56
+ − 57 static XtGeometryResult QueryGeometry (Widget wid,
+ − 58 XtWidgetGeometry *request,
+ − 59 XtWidgetGeometry *reply);
+ − 60 static void Resize (Widget w);
+ − 61 static XtGeometryResult GeometryManager (Widget w, XtWidgetGeometry *request,
+ − 62 XtWidgetGeometry *reply);
+ − 63 static void ChangeManaged (Widget w);
+ − 64 static void Realize (Widget w, Mask *valueMask,
+ − 65 XSetWindowAttributes *attributes);
+ − 66 static void ClassInitialize (void);
+ − 67
+ − 68 EmacsManagerClassRec emacsManagerClassRec = {
+ − 69 {
+ − 70 /* core_class fields */
+ − 71 #ifdef LWLIB_USES_MOTIF
+ − 72 /* superclass */ (WidgetClass) &xmManagerClassRec,
+ − 73 #else
+ − 74 /* superclass */ (WidgetClass) &compositeClassRec,
+ − 75 #endif
+ − 76 /* class_name */ "EmacsManager",
440
+ − 77 /* widget_size */ sizeof (EmacsManagerRec),
428
+ − 78 /* class_initialize */ ClassInitialize,
+ − 79 /* class_part_init */ NULL,
+ − 80 /* class_inited */ FALSE,
+ − 81 /* initialize */ NULL,
+ − 82 /* initialize_hook */ NULL,
+ − 83 /* realize */ Realize,
+ − 84 /* actions */ NULL,
+ − 85 /* num_actions */ 0,
+ − 86 /* resources */ resources,
+ − 87 /* num_resources */ XtNumber(resources),
+ − 88 /* xrm_class */ NULLQUARK,
+ − 89 /* compress_motion */ TRUE,
+ − 90 /* compress_exposure */ TRUE,
+ − 91 /* compress_enterleave*/ TRUE,
+ − 92 /* visible_interest */ FALSE,
+ − 93 /* destroy */ NULL,
+ − 94 /* resize */ Resize,
+ − 95 /* expose */ NULL,
+ − 96 /* set_values */ NULL,
+ − 97 /* set_values_hook */ NULL,
+ − 98 /* set_values_almost */ XtInheritSetValuesAlmost,
+ − 99 /* get_values_hook */ NULL,
+ − 100 /* accept_focus */ NULL,
+ − 101 /* version */ XtVersion,
+ − 102 /* callback_private */ NULL,
+ − 103 /* tm_table */ XtInheritTranslations,
+ − 104 /* query_geometry */ QueryGeometry,
+ − 105 /* display_accelerator*/ XtInheritDisplayAccelerator,
+ − 106 /* extension */ NULL
+ − 107 },
+ − 108 {
+ − 109 /* composite_class fields */
+ − 110 /* geometry_manager */ GeometryManager,
+ − 111 /* change_managed */ ChangeManaged,
+ − 112 /* insert_child */ XtInheritInsertChild,
+ − 113 /* delete_child */ XtInheritDeleteChild,
+ − 114 /* extension */ NULL
+ − 115 },
+ − 116 #ifdef LWLIB_USES_MOTIF
+ − 117 {
+ − 118 /* constraint_class fields */
+ − 119 NULL, /* resource list */
+ − 120 0, /* num resources */
+ − 121 0, /* constraint size */
+ − 122 (XtInitProc)NULL, /* init proc */
+ − 123 (XtWidgetProc)NULL, /* destroy proc */
+ − 124 (XtSetValuesFunc)NULL, /* set values proc */
+ − 125 NULL, /* extension */
+ − 126 },
+ − 127 {
+ − 128 /* manager_class fields */
+ − 129 XtInheritTranslations, /* translations */
+ − 130 NULL, /* syn_resources */
+ − 131 0, /* num_syn_resources */
+ − 132 NULL, /* syn_cont_resources */
+ − 133 0, /* num_syn_cont_resources */
+ − 134 XmInheritParentProcess, /* parent_process */
+ − 135 NULL, /* extension */
+ − 136 },
+ − 137 #endif
+ − 138 {
+ − 139 /* emacs_manager_class fields */
+ − 140 /* empty */ 0,
+ − 141 }
+ − 142 };
+ − 143
+ − 144 WidgetClass emacsManagerWidgetClass = (WidgetClass)&emacsManagerClassRec;
+ − 145
+ − 146 /* What is my preferred size? A suggested size may be given. */
+ − 147
+ − 148 static XtGeometryResult
+ − 149 QueryGeometry (Widget w, XtWidgetGeometry *request, XtWidgetGeometry *reply)
+ − 150 {
+ − 151 EmacsManagerWidget emw = (EmacsManagerWidget) w;
+ − 152 EmacsManagerQueryGeometryStruct struc;
440
+ − 153 int request_mode = request->request_mode;
428
+ − 154
440
+ − 155 struc.request_mode = request_mode;
+ − 156 struc.proposed_width = (request_mode & CWWidth) ? request->width : 0;
+ − 157 struc.proposed_height = (request_mode & CWHeight) ? request->height : 0;
428
+ − 158 XtCallCallbackList (w, emw->emacs_manager.query_geometry_callback, &struc);
+ − 159 reply->request_mode = CWWidth | CWHeight;
+ − 160 reply->width = struc.proposed_width;
+ − 161 reply->height = struc.proposed_height;
440
+ − 162 if (((request_mode & CWWidth) && (request->width != reply->width)) ||
+ − 163 ((request_mode & CWHeight) && (request->height != reply->height)))
428
+ − 164 return XtGeometryAlmost;
+ − 165 return XtGeometryYes;
+ − 166 }
+ − 167
+ − 168 static void
+ − 169 Resize (Widget w)
+ − 170 {
+ − 171 EmacsManagerWidget emw = (EmacsManagerWidget) w;
+ − 172 EmacsManagerResizeStruct struc;
+ − 173
+ − 174 struc.width = w->core.width;
+ − 175 struc.height = w->core.height;
+ − 176 XtCallCallbackList (w, emw->emacs_manager.resize_callback, &struc);
+ − 177 }
+ − 178
+ − 179 static XtGeometryResult
+ − 180 GeometryManager (Widget w, XtWidgetGeometry *request, XtWidgetGeometry *reply)
+ − 181 {
+ − 182 /* Sure, any changes are fine. */
+ − 183
440
+ − 184 #ifdef LWLIB_MENUBARS_MOTIF
428
+ − 185 /* The Motif menubar will merrily request a new size every time a
+ − 186 child is added or deleted. Blow it off because it doesn't know
+ − 187 what it's talking about. */
440
+ − 188 if (XtClass (w) != xmRowColumnWidgetClass)
428
+ − 189 #endif /* LWLIB_MENUBARS_MOTIF */
+ − 190 {
440
+ − 191 if (request->request_mode & CWWidth) w->core.width = request->width;
+ − 192 if (request->request_mode & CWHeight) w->core.height = request->height;
428
+ − 193 }
440
+ − 194 if (request->request_mode & CWBorderWidth)
+ − 195 w->core.border_width = request->border_width;
+ − 196 if (request->request_mode & CWX) w->core.x = request->x;
+ − 197 if (request->request_mode & CWY) w->core.y = request->y;
428
+ − 198
+ − 199 return XtGeometryYes;
+ − 200 }
+ − 201
+ − 202 static void
+ − 203 ChangeManaged (Widget w)
+ − 204 {
+ − 205 if (!XtIsRealized (w))
+ − 206 {
440
+ − 207 XtWidgetGeometry request, reply;
428
+ − 208
+ − 209 /* find out how big we'd like to be ... */
+ − 210
440
+ − 211 request.request_mode = 0;
+ − 212 XtQueryGeometry (w, &request, &reply);
+ − 213 EmacsManagerChangeSize (w, reply.width, reply.height);
428
+ − 214 }
+ − 215 }
+ − 216
+ − 217 static void
+ − 218 Realize (Widget w, Mask *valueMask, XSetWindowAttributes *attributes)
+ − 219 {
+ − 220 attributes->bit_gravity = NorthWestGravity;
+ − 221 *valueMask |= CWBitGravity;
+ − 222
+ − 223 XtCreateWindow (w, (unsigned) InputOutput, (Visual *) CopyFromParent,
+ − 224 *valueMask, attributes);
+ − 225 }
+ − 226
+ − 227 static void
+ − 228 ClassInitialize (void)
+ − 229 {
+ − 230 return;
+ − 231 }
+ − 232
+ − 233 void
+ − 234 EmacsManagerChangeSize (Widget w, Dimension width, Dimension height)
+ − 235 {
+ − 236 if (width == 0)
+ − 237 width = w->core.width;
+ − 238 if (height == 0)
+ − 239 height = w->core.height;
+ − 240
+ − 241 /* do nothing if we're already that size */
+ − 242 if (w->core.width != width || w->core.height != height)
+ − 243 if (XtMakeResizeRequest (w, width, height, &w->core.width, &w->core.height)
+ − 244 == XtGeometryAlmost)
+ − 245 XtMakeResizeRequest (w, w->core.width, w->core.height, NULL, NULL);
+ − 246
+ − 247 Resize (w);
+ − 248 }
+ − 249
+ − 250