| 1 |
/* |
| 2 |
* Motif |
| 3 |
* |
| 4 |
* Copyright (c) 1987-2012, The Open Group. All rights reserved. |
| 5 |
* |
| 6 |
* These libraries and programs are free software; you can |
| 7 |
* redistribute them and/or modify them under the terms of the GNU |
| 8 |
* Lesser General Public License as published by the Free Software |
| 9 |
* Foundation; either version 2 of the License, or (at your option) |
| 10 |
* any later version. |
| 11 |
* |
| 12 |
* These libraries and programs are distributed in the hope that |
| 13 |
* they will be useful, but WITHOUT ANY WARRANTY; without even the |
| 14 |
* implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 15 |
* PURPOSE. See the GNU Lesser General Public License for more |
| 16 |
* details. |
| 17 |
* |
| 18 |
* You should have received a copy of the GNU Lesser General Public |
| 19 |
* License along with these librararies and programs; if not, write |
| 20 |
* to the Free Software Foundation, Inc., 51 Franklin Street, Fifth |
| 21 |
* Floor, Boston, MA 02110-1301 USA |
| 22 |
*/ |
| 23 |
/* |
| 24 |
* HISTORY |
| 25 |
*/ |
| 26 |
#ifdef REV_INFO |
| 27 |
#ifndef lint |
| 28 |
static char rcsid[] = "$TOG: Square.c /main/6 1998/03/25 18:18:13 csn $" |
| 29 |
#endif |
| 30 |
#endif |
| 31 |
|
| 32 |
/***************************************************************************** |
| 33 |
* |
| 34 |
* Square.c - widget source file |
| 35 |
* |
| 36 |
******************************************************************************/ |
| 37 |
|
| 38 |
#include <stdio.h> |
| 39 |
#include <Xm/Xm.h> |
| 40 |
#include <Mrm/MrmPublic.h> |
| 41 |
#include <Xm/BulletinBP.h> |
| 42 |
#include "SquareP.h" |
| 43 |
|
| 44 |
#define Width(w) XmField((w),square_offsets,Core,width,Dimension) |
| 45 |
#define Height(w) XmField((w),square_offsets,Core,height,Dimension) |
| 46 |
#define BorderWidth(w) XmField((w),square_offsets,Core,border_width,Dimension) |
| 47 |
#define MajorDimension(w) XmField((w),square_offsets,Square,major_dimension,int) |
| 48 |
|
| 49 |
#define MakeSquare(w) XmConstraintField((w),square_constraint_offsets, \ |
| 50 |
Square,make_square, Boolean) |
| 51 |
|
| 52 |
static void ClassInitialize(); |
| 53 |
static void Initialize(); |
| 54 |
static Boolean SetValues(); |
| 55 |
static void ConstraintInitialize(); |
| 56 |
static Boolean ConstraintSetValues(); |
| 57 |
|
| 58 |
static XmPartResource resources[] = { |
| 59 |
{ |
| 60 |
SquareNmajorDimension, SquareCMajorDimension, XmRInt, sizeof(int), |
| 61 |
XmPartOffset(Square,major_dimension), XmRImmediate, (caddr_t)SquareWIDTH |
| 62 |
} |
| 63 |
}; |
| 64 |
|
| 65 |
static XmPartResource constraints[] = { |
| 66 |
{ |
| 67 |
SquareNmakeSquare, SquareCMakeSquare, XmRBoolean, sizeof(Boolean), |
| 68 |
XmConstraintPartOffset(Square,make_square), |
| 69 |
XmRImmediate, (caddr_t)False |
| 70 |
} |
| 71 |
}; |
| 72 |
|
| 73 |
|
| 74 |
externaldef(squareclassrec) SquareClassRec squareClassRec = |
| 75 |
{ |
| 76 |
{ /* core_class fields */ |
| 77 |
(WidgetClass) &xmBulletinBoardClassRec, /* superclass */ |
| 78 |
"Square", /* class_name */ |
| 79 |
sizeof(SquarePart), /* widget_size */ |
| 80 |
ClassInitialize, /* class_initialize */ |
| 81 |
NULL, /* class init part proc */ |
| 82 |
False, /* class_inited */ |
| 83 |
Initialize, /* initialize */ |
| 84 |
NULL, /* initialize_notify */ |
| 85 |
XtInheritRealize, /* realize */ |
| 86 |
NULL, /* actions */ |
| 87 |
0, /* num_actions */ |
| 88 |
(XtResourceList)resources,/* resources */ |
| 89 |
XtNumber(resources), /* num_resources */ |
| 90 |
NULLQUARK, /* xrm_class */ |
| 91 |
False, /* compress_motion */ |
| 92 |
XtExposeCompressMaximal, /* compress_exposure */ |
| 93 |
False, /* compress_enterleave */ |
| 94 |
False, /* visible_interest */ |
| 95 |
NULL, /* destroy */ |
| 96 |
XtInheritResize, /* resize */ |
| 97 |
XtInheritExpose, /* expose */ |
| 98 |
SetValues, /* set_values */ |
| 99 |
NULL, /* set_values_hook */ |
| 100 |
XtInheritSetValuesAlmost, /* set_values_almost */ |
| 101 |
NULL, /* get_values_hook */ |
| 102 |
NULL, /* accept_focus */ |
| 103 |
XtVersionDontCheck, /* version */ |
| 104 |
NULL, /* callback_private */ |
| 105 |
XtInheritTranslations, /* tm_table */ |
| 106 |
XtInheritQueryGeometry, /* Query Geometry proc */ |
| 107 |
NULL, /* disp accelerator */ |
| 108 |
NULL, /* extension */ |
| 109 |
}, |
| 110 |
|
| 111 |
{ /* composite_class fields */ |
| 112 |
XtInheritGeometryManager, /* geometry_manager */ |
| 113 |
XtInheritChangeManaged, /* change_managed */ |
| 114 |
XtInheritInsertChild, /* insert_child */ |
| 115 |
XtInheritDeleteChild, /* delete_child */ |
| 116 |
NULL, /* extension */ |
| 117 |
}, |
| 118 |
|
| 119 |
{ /* constraint_class fields */ |
| 120 |
(XtResourceList)constraints, /* constraint resource */ |
| 121 |
XtNumber(constraints), /* number of constraints */ |
| 122 |
sizeof(SquareConstraintRec), /* size of constraint */ |
| 123 |
ConstraintInitialize, /* initialization */ |
| 124 |
NULL, /* destroy proc */ |
| 125 |
ConstraintSetValues, /* set_values proc */ |
| 126 |
NULL, /* extension */ |
| 127 |
}, |
| 128 |
|
| 129 |
{ /* manager_class fields */ |
| 130 |
XtInheritTranslations, /* translations */ |
| 131 |
NULL, /* syn_resources */ |
| 132 |
0, /* num_syn_resources */ |
| 133 |
NULL, /* syn_cont_resources */ |
| 134 |
0, /* num_syn_cont_resources */ |
| 135 |
XmInheritParentProcess, /* parent_process */ |
| 136 |
NULL, /* extension */ |
| 137 |
}, |
| 138 |
|
| 139 |
{ /* bulletin_board_class fields */ |
| 140 |
FALSE, /* always_install_accelerators */ |
| 141 |
NULL, /* geo_matrix_create */ |
| 142 |
XmInheritFocusMovedProc, /* focus_moved_proc */ |
| 143 |
NULL, /* extension */ |
| 144 |
}, |
| 145 |
|
| 146 |
{ /* square_class fields */ |
| 147 |
NULL, /* extension */ |
| 148 |
} |
| 149 |
}; |
| 150 |
|
| 151 |
externaldef(squarewidgetclass) WidgetClass |
| 152 |
squareWidgetClass = (WidgetClass) &squareClassRec; |
| 153 |
|
| 154 |
static XmOffsetPtr square_offsets; /* Part offsets table */ |
| 155 |
static XmOffsetPtr square_constraint_offsets; /* Constraint offsets table */ |
| 156 |
|
| 157 |
/********************************************************************** |
| 158 |
* |
| 159 |
* SquareCreate - Convenience routine, used by Uil/Mrm. |
| 160 |
* |
| 161 |
*********************************************************************/ |
| 162 |
|
| 163 |
Widget SquareCreate(parent, name, arglist, nargs) |
| 164 |
Widget parent; |
| 165 |
char *name; |
| 166 |
Arg *arglist; |
| 167 |
int nargs; |
| 168 |
{ |
| 169 |
return(XtCreateWidget (name, squareWidgetClass, parent, arglist, nargs)); |
| 170 |
} |
| 171 |
|
| 172 |
/********************************************************************** |
| 173 |
* |
| 174 |
* SquareMrmInitialize - register Square widget class with Mrm |
| 175 |
* |
| 176 |
*********************************************************************/ |
| 177 |
|
| 178 |
int SquareMrmInitialize() |
| 179 |
{ |
| 180 |
return(MrmRegisterClass (MrmwcUnknown, "Square", "SquareCreate", |
| 181 |
SquareCreate, (WidgetClass)&squareClassRec)); |
| 182 |
} |
| 183 |
|
| 184 |
/********************************************************************** |
| 185 |
* |
| 186 |
* Class methods |
| 187 |
* |
| 188 |
*********************************************************************/ |
| 189 |
|
| 190 |
static void ClassInitialize() |
| 191 |
{ |
| 192 |
XmResolveAllPartOffsets(squareWidgetClass, &square_offsets, |
| 193 |
&square_constraint_offsets); |
| 194 |
} |
| 195 |
|
| 196 |
static void Initialize(req, new) |
| 197 |
SquareWidget req; |
| 198 |
SquareWidget new; |
| 199 |
{ |
| 200 |
if (MajorDimension(new) != SquareWIDTH && |
| 201 |
MajorDimension(new) != SquareHEIGHT) { |
| 202 |
XtWarning("Square: invalid majorDimension"); |
| 203 |
MajorDimension(new) = SquareWIDTH; |
| 204 |
} |
| 205 |
} |
| 206 |
|
| 207 |
static Boolean SetValues(curr, req, new) |
| 208 |
SquareWidget curr; |
| 209 |
SquareWidget req; |
| 210 |
SquareWidget new; |
| 211 |
{ |
| 212 |
if (MajorDimension(new) != SquareWIDTH && |
| 213 |
MajorDimension(new) != SquareHEIGHT) { |
| 214 |
XtWarning("Square: invalid majorDimension"); |
| 215 |
MajorDimension(new) = MajorDimension(curr); |
| 216 |
} |
| 217 |
return (False); |
| 218 |
} |
| 219 |
|
| 220 |
static void ConstraintInitialize (req, new) |
| 221 |
Widget req; |
| 222 |
Widget new; |
| 223 |
{ |
| 224 |
Dimension m; |
| 225 |
|
| 226 |
if(MakeSquare(new) == True) { |
| 227 |
if (MajorDimension(XtParent(new))==SquareWIDTH) |
| 228 |
m = Width(new); |
| 229 |
else |
| 230 |
m = Height(new); |
| 231 |
|
| 232 |
XtResizeWidget(new, m, m, BorderWidth(new)); |
| 233 |
} |
| 234 |
} |
| 235 |
|
| 236 |
static Boolean ConstraintSetValues (old, ref, new) |
| 237 |
Widget old; |
| 238 |
Widget ref; |
| 239 |
Widget new; |
| 240 |
{ |
| 241 |
Boolean redraw = False; |
| 242 |
|
| 243 |
if (MakeSquare(new) != MakeSquare(old)) { |
| 244 |
if(MakeSquare(new)==True) { |
| 245 |
if (MajorDimension(XtParent(new))==SquareWIDTH) |
| 246 |
Height(new) = Width(new); |
| 247 |
else |
| 248 |
Width(new) = Height(new); |
| 249 |
} |
| 250 |
else { |
| 251 |
XtWidgetGeometry gi; |
| 252 |
XtWidgetGeometry gp; |
| 253 |
|
| 254 |
if (MajorDimension(XtParent(new))==SquareWIDTH) |
| 255 |
Height(new) = Height(new)/2; |
| 256 |
else |
| 257 |
Width(new) = Width(new)/2; |
| 258 |
|
| 259 |
gi.request_mode = CWWidth | CWHeight; |
| 260 |
gi.width = Width(new); |
| 261 |
gi.height = Height(new); |
| 262 |
if (XtQueryGeometry(new, &gi, &gp) == XtGeometryAlmost) { |
| 263 |
if (gp.request_mode && CWWidth != 0) Width(new) = gp.width; |
| 264 |
if (gp.request_mode && CWHeight != 0) Height(new) = gp.height; |
| 265 |
} |
| 266 |
} |
| 267 |
redraw = True; |
| 268 |
} |
| 269 |
return (redraw); |
| 270 |
} |
| 271 |
|