home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / x / volume13 / xdtm / part02 < prev    next >
Internet Message Format  |  1991-05-18  |  30KB

  1. Path: uunet!cs.utexas.edu!sun-barr!newstop!exodus!cogs.sussex.ac.uk
  2. From: eddyg@cogs.sussex.ac.uk (EdwardJ. Groenendaal)
  3. Newsgroups: comp.sources.x
  4. Subject: v13i007: xdtm - X Desktop Manager for the X Window System, Part02/11
  5. Message-ID: <13571@exodus.Eng.Sun.COM>
  6. Date: 19 May 91 00:02:46 GMT
  7. References: <csx-13i006:xdtm@uunet.UU.NET>
  8. Sender: news@exodus.Eng.Sun.COM
  9. Lines: 829
  10. Approved: argv@sun.com
  11.  
  12. Submitted-by: Edward "J." Groenendaal <eddyg@cogs.sussex.ac.uk>
  13. Posting-number: Volume 13, Issue 7
  14. Archive-name: xdtm/part02
  15.  
  16. Submitted-by: eddyg@cste
  17. Archive-name: xdtm/part02
  18.  
  19. ---- Cut Here and feed the following to sh ----
  20. #!/bin/sh
  21. # This is part 02 of xdtm
  22. # ============= xdtm/Xedw/XedwForm.c ==============
  23. if test ! -d 'xdtm'; then
  24.     echo 'x - creating directory xdtm'
  25.     mkdir 'xdtm'
  26. fi
  27. if test ! -d 'xdtm/Xedw'; then
  28.     echo 'x - creating directory xdtm/Xedw'
  29.     mkdir 'xdtm/Xedw'
  30. fi
  31. if test -f 'xdtm/Xedw/XedwForm.c' -a X"$1" != X"-c"; then
  32.     echo 'x - skipping xdtm/Xedw/XedwForm.c (File already exists)'
  33. else
  34. echo 'x - extracting xdtm/Xedw/XedwForm.c (Text)'
  35. sed 's/^X//' << 'SHAR_EOF' > 'xdtm/Xedw/XedwForm.c' &&
  36. X#include <X11/copyright.h>
  37. X
  38. X/*****************************************************************************
  39. X * XedwForm is a modified version of the Athena Widget Form.
  40. X * Added capabilities :
  41. X *  1) Children may chose not to be resized in any particular plane.
  42. X *  2) Children may chose to extend their widths to the edge of the application.
  43. X *  3) Children may have linked widths and heights.
  44. X * The default is that these capabilities are turned off.
  45. X * See XedwForm.h for resource list.
  46. X *
  47. X * Edward Groenendaal, 20th Feb 1991.
  48. X *
  49. X * Changes to the original source :
  50. X *      1) Changed all references of Form to XedwForm and form to xedwForm.
  51. X *      2) Added resources
  52. X *      3) Rewrote Resize(), Layout() and LayoutChild().
  53. X *****************************************************************************/
  54. X
  55. X#include <X11/IntrinsicP.h>
  56. X#include <X11/StringDefs.h>
  57. X#include <X11/Xmu/Converters.h>
  58. X#include <X11/Xmu/CharSet.h>
  59. X#include <X11/Xaw/XawInit.h>
  60. X#include "XedwFormP.h"
  61. X
  62. X/* Private Definitions */
  63. X
  64. Xstatic int default_value = -99999;
  65. X
  66. X#define Offset(field) XtOffset(XedwFormWidget, xedwForm.field)
  67. Xstatic XtResource resources[] = {
  68. X    {XtNdefaultDistance, XtCThickness, XtRInt, sizeof(int),
  69. X        Offset(default_spacing), XtRImmediate, (caddr_t)4}
  70. X};
  71. X#undef Offset
  72. X
  73. Xstatic XtEdgeType defEdge = XtRubber;
  74. X
  75. X#define Offset(field) XtOffset(XedwFormConstraints, xedwForm.field)
  76. Xstatic XtResource xedwFormConstraintResources[] = {
  77. X  {XtNtop, XtCEdge, XtREdgeType, sizeof(XtEdgeType),
  78. X     Offset(top), XtREdgeType, (XtPointer)&defEdge},
  79. X  {XtNbottom, XtCEdge, XtREdgeType, sizeof(XtEdgeType),
  80. X     Offset(bottom), XtREdgeType, (XtPointer)&defEdge},
  81. X  {XtNleft, XtCEdge, XtREdgeType, sizeof(XtEdgeType),
  82. X     Offset(left), XtREdgeType, (XtPointer)&defEdge},
  83. X  {XtNright, XtCEdge, XtREdgeType, sizeof(XtEdgeType),
  84. X     Offset(right), XtREdgeType, (XtPointer)&defEdge},
  85. X  {XtNhorizDistance, XtCThickness, XtRInt, sizeof(int),
  86. X     Offset(dx), XtRInt, (XtPointer) &default_value},
  87. X  {XtNfromHoriz, XtCWidget, XtRWidget, sizeof(Widget),
  88. X     Offset(horiz_base), XtRWidget, (XtPointer)NULL},
  89. X  {XtNvertDistance, XtCThickness, XtRInt, sizeof(int),
  90. X     Offset(dy), XtRInt, (XtPointer) &default_value},
  91. X  {XtNfromVert, XtCWidget, XtRWidget, sizeof(Widget),
  92. X     Offset(vert_base), XtRWidget, (XtPointer)NULL},
  93. X  {XtNrubberWidth, XtCBoolean, XtRBoolean, sizeof(Boolean),    /* new */
  94. X     Offset(rubber_width), XtRImmediate, (XtPointer) True},
  95. X  {XtNrubberHeight, XtCBoolean, XtRBoolean, sizeof(Boolean),   /* new */
  96. X     Offset(rubber_height), XtRImmediate, (XtPointer) True},
  97. X  {XtNfullWidth, XtCBoolean, XtRBoolean, sizeof(Boolean),      /* new */
  98. X     Offset(full_width), XtRImmediate, (XtPointer) False},
  99. X  {XtNfullHeight, XtCBoolean, XtRBoolean, sizeof(Boolean),     /* new */
  100. X     Offset(full_height), XtRImmediate, (XtPointer) False},
  101. X  {XtNwidthLinked, XtCWidget, XtRWidget, sizeof(Widget),
  102. X     Offset(width_link), XtRWidget, (XtPointer)NULL},         /* new */
  103. X  {XtNheightLinked, XtCWidget, XtRWidget, sizeof(Widget),
  104. X     Offset(height_link), XtRWidget, (XtPointer)NULL},        /* new */
  105. X  {XtNresizable, XtCBoolean, XtRBoolean, sizeof(Boolean),
  106. X     Offset(allow_resize), XtRImmediate, (XtPointer) FALSE},
  107. X};
  108. X#undef Offset
  109. X
  110. Xstatic void ClassInitialize(), ClassPartInitialize(), Initialize(), Resize();
  111. Xstatic void ConstraintInitialize();
  112. Xstatic Boolean SetValues(), ConstraintSetValues();
  113. Xstatic XtGeometryResult GeometryManager(), PreferredGeometry();
  114. Xstatic void ChangeManaged();
  115. Xstatic Boolean Layout(XedwFormWidget, Dimension, Dimension);
  116. X
  117. XXedwFormClassRec xedwFormClassRec = {
  118. X  { /* core_class fields */
  119. X    /* superclass         */    (WidgetClass) &constraintClassRec,
  120. X    /* class_name         */    "XedwForm",
  121. X    /* widget_size        */    sizeof(XedwFormRec),
  122. X    /* class_initialize   */    ClassInitialize,
  123. X    /* class_part_init    */    ClassPartInitialize,
  124. X    /* class_inited       */    FALSE,
  125. X    /* initialize         */    Initialize,
  126. X    /* initialize_hook    */    NULL,
  127. X    /* realize            */    XtInheritRealize,
  128. X    /* actions            */    NULL,
  129. X    /* num_actions        */    0,
  130. X    /* resources          */    resources,
  131. X    /* num_resources      */    XtNumber(resources),
  132. X    /* xrm_class          */    NULLQUARK,
  133. X    /* compress_motion    */    TRUE,
  134. X    /* compress_exposure  */    TRUE,
  135. X    /* compress_enterleave*/    TRUE,
  136. X    /* visible_interest   */    FALSE,
  137. X    /* destroy            */    NULL,
  138. X    /* resize             */    Resize,                      /* new */
  139. X    /* expose             */    XtInheritExpose,
  140. X    /* set_values         */    SetValues,
  141. X    /* set_values_hook    */    NULL,
  142. X    /* set_values_almost  */    XtInheritSetValuesAlmost,
  143. X    /* get_values_hook    */    NULL,
  144. X    /* accept_focus       */    NULL,
  145. X    /* version            */    XtVersion,
  146. X    /* callback_private   */    NULL,
  147. X    /* tm_table           */    NULL,
  148. X    /* query_geometry     */    PreferredGeometry,
  149. X    /* display_accelerator*/    XtInheritDisplayAccelerator,
  150. X    /* extension          */    NULL
  151. X  },
  152. X  { /* composite_class fields */
  153. X    /* geometry_manager   */   GeometryManager,
  154. X    /* change_managed     */   ChangeManaged,
  155. X    /* insert_child       */   XtInheritInsertChild,
  156. X    /* delete_child       */   XtInheritDeleteChild,
  157. X    /* extension          */   NULL
  158. X  },
  159. X  { /* constraint_class fields */
  160. X    /* subresourses       */   xedwFormConstraintResources,
  161. X    /* subresource_count  */   XtNumber(xedwFormConstraintResources),
  162. X    /* constraint_size    */   sizeof(XedwFormConstraintsRec),
  163. X    /* initialize         */   ConstraintInitialize,
  164. X    /* destroy            */   NULL,
  165. X    /* set_values         */   ConstraintSetValues,
  166. X    /* extension          */   NULL
  167. X  },
  168. X  { /* xedwForm_class fields */
  169. X    /* layout             */   Layout                        
  170. X  }
  171. X};
  172. X
  173. XWidgetClass xedwFormWidgetClass = (WidgetClass)&xedwFormClassRec;
  174. X
  175. X/****************************************************************
  176. X *
  177. X * Private Procedures
  178. X *
  179. X ****************************************************************/
  180. X
  181. X
  182. Xstatic XrmQuark XtQChainLeft, XtQChainRight, XtQChainTop,
  183. X  XtQChainBottom, XtQRubber;
  184. X
  185. X#define done(address, type) \
  186. X{ toVal->size = sizeof(type); \
  187. X  toVal->addr = (caddr_t) address; \
  188. X  return; \
  189. X}
  190. X
  191. Xstatic void _CvtStringToEdgeType(XrmValuePtr args, 
  192. X                 Cardinal *num_args, 
  193. X                 XrmValuePtr fromVal, 
  194. X                 XrmValuePtr toVal)
  195. X{
  196. X  static XtEdgeType edgeType;
  197. X  XrmQuark q;
  198. X  char lowerName[1000];
  199. X
  200. X  XmuCopyISOLatin1Lowered (lowerName, (char*)fromVal->addr);
  201. X  q = XrmStringToQuark(lowerName);
  202. X  if (q == XtQChainLeft) {
  203. X    edgeType = XtChainLeft;
  204. X    done(&edgeType, XtEdgeType);
  205. X  }
  206. X  if (q == XtQChainRight) {
  207. X    edgeType = XtChainRight;
  208. X    done(&edgeType, XtEdgeType);
  209. X  }
  210. X  if (q == XtQChainTop) {
  211. X    edgeType = XtChainTop;
  212. X    done(&edgeType, XtEdgeType);
  213. X  }
  214. X  if (q == XtQChainBottom) {
  215. X    edgeType = XtChainBottom;
  216. X    done(&edgeType, XtEdgeType);
  217. X  }
  218. X  if (q == XtQRubber) {
  219. X    edgeType = XtRubber;
  220. X    done(&edgeType, XtEdgeType);
  221. X  }
  222. X  XtStringConversionWarning(fromVal->addr, "edgeType");
  223. X  toVal->addr = NULL;
  224. X  toVal->size = 0;
  225. X}
  226. X
  227. Xstatic void ClassInitialize(void)
  228. X{
  229. X  static XtConvertArgRec parentCvtArgs[] = {
  230. X    {XtBaseOffset, (caddr_t)XtOffset(Widget, core.parent), sizeof(Widget)}
  231. X  };
  232. X  XawInitializeWidgetSet();
  233. X  XtQChainLeft   = XrmStringToQuark("chainleft");
  234. X  XtQChainRight  = XrmStringToQuark("chainright");
  235. X  XtQChainTop    = XrmStringToQuark("chaintop");
  236. X  XtQChainBottom = XrmStringToQuark("chainbottom");
  237. X  XtQRubber      = XrmStringToQuark("rubber");
  238. X  
  239. X  XtAddConverter( XtRString, XtREdgeType, _CvtStringToEdgeType, NULL, 0 );
  240. X  XtAddConverter( XtRString, XtRWidget, XmuCvtStringToWidget,
  241. X         parentCvtArgs, XtNumber(parentCvtArgs) );
  242. X}
  243. X
  244. Xstatic void ClassPartInitialize(WidgetClass class)
  245. X{
  246. X  register XedwFormWidgetClass c = (XedwFormWidgetClass)class;
  247. X
  248. X  if (((Boolean (*)())c->xedwForm_class.layout) ==  XtInheritLayout)
  249. X    c->xedwForm_class.layout = Layout;
  250. X}
  251. X
  252. X
  253. Xstatic void Initialize(Widget request, Widget new)
  254. X{
  255. X  XedwFormWidget fw = (XedwFormWidget)new;
  256. X
  257. X  fw->xedwForm.old_width = fw->core.width;
  258. X  fw->xedwForm.old_height = fw->core.height;
  259. X  fw->xedwForm.no_refigure = False;
  260. X  fw->xedwForm.needs_relayout = False;
  261. X  fw->xedwForm.resize_in_layout = True;
  262. X}
  263. X
  264. X
  265. Xstatic void RefigureLocations(XedwFormWidget w)
  266. X{
  267. X  if (w->xedwForm.no_refigure) {
  268. X    w->xedwForm.needs_relayout = True;
  269. X  } else {
  270. X    (*((XedwFormWidgetClass)w->core.widget_class)->xedwForm_class.layout)
  271. X      ( w, w->core.width, w->core.height );
  272. X    w->xedwForm.needs_relayout = False;
  273. X  }
  274. X}
  275. X
  276. Xstatic Boolean Layout(XedwFormWidget fw, Dimension width, Dimension height)
  277. X{
  278. X  int num_children = fw->composite.num_children;
  279. X  WidgetList children = fw->composite.children;
  280. X  Widget *childP;
  281. X  Position maxx, maxy;
  282. X  static void LayoutChild();
  283. X  Boolean ret_val;
  284. X  
  285. X  for (childP = children; childP - children < num_children; childP++) {
  286. X    XedwFormConstraints xedwForm =
  287. X      (XedwFormConstraints)(*childP)->core.constraints;
  288. X    xedwForm->xedwForm.layout_state = LayoutPending;
  289. X  }
  290. X
  291. X  maxx = maxy = 1;
  292. X  for (childP = children; childP - children < num_children; childP++) {
  293. X    if (XtIsManaged(*childP)) {
  294. X      Position x, y;
  295. X      LayoutChild(*childP);
  296. X      x = (*childP)->core.x + (*childP)->core.width
  297. X    + ((*childP)->core.border_width << 1);
  298. X      y = (*childP)->core.y + (*childP)->core.height
  299. X    + ((*childP)->core.border_width << 1);
  300. X      if (maxx < x) maxx = x;  /* Track width  */
  301. X      if (maxy < y) maxy = y;  /* Track Height */
  302. X    }
  303. X  }
  304. X
  305. X  /* I want to be this big */
  306. X  fw->xedwForm.preferred_width = (maxx += fw->xedwForm.default_spacing);
  307. X  fw->xedwForm.preferred_height = (maxy += fw->xedwForm.default_spacing);
  308. X
  309. X  /* Go back and check to see if any widgets want to be full height or
  310. X   * full width, if so, do it, dont recalculate sizes, assume the programmer
  311. X   * didn't make any silly mistakes like putting another widget to the right
  312. X   * of a full width one. EG.
  313. X   * Should really do this in one pass. 
  314. X   */
  315. X
  316. X  for (childP = children; childP - children < num_children; childP++) {
  317. X    XedwFormConstraints form = (XedwFormConstraints)(*childP)->core.constraints;
  318. X    Position newwidth  = (Position)(*childP)->core.width;
  319. X    Position newheight = (Position)(*childP)->core.height;
  320. X    if (form->xedwForm.full_width == True)
  321. X      form->xedwForm.virtual_width = newwidth = 
  322. X    (maxx - ((form->xedwForm.dx) + 
  323. X         ((*childP)->core.border_width * 2) + 
  324. X         ((*childP)->core.x)));
  325. X    if (form->xedwForm.full_height == True)
  326. X      form->xedwForm.virtual_height = newheight = 
  327. X    (maxy - ((form->xedwForm.dy) + 
  328. X         ((*childP)->core.border_width * 2) +
  329. X         ((*childP)->core.y)));
  330. X    /* Resize the widget if it has been changed. XtResizeWidget does the checking */
  331. X    XtResizeWidget(*childP, newwidth, newheight, (*childP)->core.border_width);
  332. X  }
  333. X  
  334. X  if (fw->xedwForm.resize_in_layout
  335. X      && (maxx != fw->core.width || maxy != fw->core.height)) {
  336. X    XtGeometryResult result;
  337. X    result = XtMakeResizeRequest(fw, (Dimension)maxx, (Dimension)maxy,
  338. X                 (Dimension*)&maxx, (Dimension*)&maxy );
  339. X    if (result == XtGeometryAlmost)
  340. X      result = XtMakeResizeRequest(fw, (Dimension)maxx, (Dimension)maxy,
  341. X                   NULL, NULL );
  342. X    fw->xedwForm.old_width  = fw->core.width;
  343. X    fw->xedwForm.old_height = fw->core.height;
  344. X    ret_val = (result == XtGeometryYes);
  345. X  } else ret_val = False;
  346. X  
  347. X  return ret_val;
  348. X}
  349. X
  350. X
  351. Xstatic void LayoutChild(Widget w)
  352. X{
  353. X  XedwFormConstraints xedwForm = (XedwFormConstraints)w->core.constraints;
  354. X  Position x, y;
  355. X  Dimension width, height;
  356. X  Widget ref;
  357. X
  358. X  switch (xedwForm->xedwForm.layout_state) {
  359. X    
  360. X  case LayoutPending:
  361. X    xedwForm->xedwForm.layout_state = LayoutInProgress;
  362. X    break;
  363. X
  364. X  case LayoutDone:
  365. X    return;
  366. X
  367. X  case LayoutInProgress:
  368. X    {
  369. X      String subs[2];
  370. X      Cardinal num_subs = 2;
  371. X      subs[0] = w->core.name;
  372. X      subs[1] = w->core.parent->core.name;
  373. X      XtAppWarningMsg(XtWidgetToApplicationContext(w),
  374. X              "constraintLoop","XedwFormLayout","XawToolkitError",
  375. X              "constraint loop detected while laying out child '%s'"
  376. X              " in XedwFormWidget '%s'",
  377. X              subs, &num_subs);
  378. X      return;
  379. X    }
  380. X  }
  381. X  x = xedwForm->xedwForm.dx;
  382. X  y = xedwForm->xedwForm.dy;
  383. X  if ((ref = xedwForm->xedwForm.width_link) != (Widget)NULL) {
  384. X    LayoutChild(ref);
  385. X    width = xedwForm->xedwForm.virtual_width = ref->core.width;
  386. X    XtResizeWidget(w, width, w->core.height, w->core.border_width);
  387. X  }
  388. X  if ((ref = xedwForm->xedwForm.height_link) != (Widget)NULL) {
  389. X    LayoutChild(ref);
  390. X    height = xedwForm->xedwForm.virtual_height = ref->core.height;
  391. X    XtResizeWidget(w, w->core.width, height, w->core.border_width);
  392. X  }
  393. X  if ((ref = xedwForm->xedwForm.horiz_base) != (Widget)NULL) {
  394. X    LayoutChild(ref);
  395. X    x += ref->core.x + ref->core.width + (ref->core.border_width << 1);
  396. X  }
  397. X  if ((ref = xedwForm->xedwForm.vert_base) != (Widget)NULL) {
  398. X    LayoutChild(ref);
  399. X    y += ref->core.y + ref->core.height + (ref->core.border_width << 1);
  400. X  }
  401. X  XtMoveWidget( w, x, y );
  402. X  xedwForm->xedwForm.layout_state = LayoutDone;
  403. X}
  404. X
  405. X
  406. Xstatic Position TransformCoord(Position loc, 
  407. X                   Dimension old, Dimension new, 
  408. X                   XtEdgeType type)
  409. X{
  410. X  if (type == XtRubber) {
  411. X    if ( ((int) old) > 0)
  412. X      loc = (loc * new) / old;
  413. X  }
  414. X  else if (type == XtChainBottom || type == XtChainRight)
  415. X    loc += (Position)new - (Position)old;
  416. X
  417. X  /* I don't see any problem with returning values less than zero. */
  418. X
  419. X  return (loc);
  420. X}
  421. X
  422. X
  423. Xstatic void Resize(Widget w)
  424. X{
  425. X  XedwFormWidget fw = (XedwFormWidget)w;
  426. X  WidgetList children = fw->composite.children;
  427. X  int num_children = fw->composite.num_children;
  428. X  Widget *childP;
  429. X  Position x, y;
  430. X  Dimension width, height;
  431. X
  432. X  for (childP = children; childP - children < num_children; childP++) {
  433. X    XedwFormConstraints xedwForm = (XedwFormConstraints)(*childP)->core.constraints;
  434. X    if (!XtIsManaged(*childP)) continue;
  435. X    x = TransformCoord( (*childP)->core.x, fw->xedwForm.old_width,
  436. X               fw->core.width, xedwForm->xedwForm.left );
  437. X    y = TransformCoord( (*childP)->core.y, fw->xedwForm.old_height,
  438. X               fw->core.height, xedwForm->xedwForm.top );
  439. X    
  440. X    if (xedwForm->xedwForm.rubber_width)
  441. X      xedwForm->xedwForm.virtual_width =
  442. X    TransformCoord((Position)((*childP)->core.x
  443. X                  + xedwForm->xedwForm.virtual_width
  444. X                  + 2 * (*childP)->core.border_width),
  445. X               fw->xedwForm.old_width, fw->core.width,
  446. X               xedwForm->xedwForm.right )
  447. X      - (x + 2 * (*childP)->core.border_width);
  448. X
  449. X    if (xedwForm->xedwForm.rubber_height)
  450. X      xedwForm->xedwForm.virtual_height =
  451. X    TransformCoord((Position)((*childP)->core.y
  452. X                  + xedwForm->xedwForm.virtual_height
  453. X                  + 2 * (*childP)->core.border_width),
  454. X               fw->xedwForm.old_height, fw->core.height,
  455. X               xedwForm->xedwForm.bottom )
  456. X      - ( y + 2 * (*childP)->core.border_width);
  457. X    
  458. X    width = (Dimension)
  459. X      (xedwForm->xedwForm.virtual_width < 1) ? 1 : xedwForm->xedwForm.virtual_width;
  460. X    height = (Dimension)
  461. X      (xedwForm->xedwForm.virtual_height < 1) ? 1 : xedwForm->xedwForm.virtual_height;
  462. X    
  463. X    XtConfigureWidget( *childP, x, y, (Dimension)width, (Dimension)height,
  464. X              (*childP)->core.border_width );
  465. X  }
  466. X
  467. X  fw->xedwForm.old_width = fw->core.width;
  468. X  fw->xedwForm.old_height = fw->core.height;
  469. X}
  470. X
  471. X
  472. Xstatic XtGeometryResult GeometryManager(Widget w, 
  473. X                    XtWidgetGeometry *request, 
  474. X                    XtWidgetGeometry *reply)
  475. X{
  476. X  XedwFormConstraints xedwForm = (XedwFormConstraints)w->core.constraints;
  477. X  XtWidgetGeometry allowed;
  478. X
  479. X  if ((request->request_mode & ~(XtCWQueryOnly | CWWidth | CWHeight)) ||
  480. X      !xedwForm->xedwForm.allow_resize)
  481. X    return XtGeometryNo;
  482. X
  483. X  if (request->request_mode & CWWidth)
  484. X    allowed.width = request->width;
  485. X  else
  486. X    allowed.width = w->core.width;
  487. X  
  488. X  if (request->request_mode & CWHeight)
  489. X    allowed.height = request->height;
  490. X  else
  491. X    allowed.height = w->core.height;
  492. X
  493. X  if (allowed.width == w->core.width && allowed.height == w->core.height)
  494. X    return XtGeometryNo;
  495. X
  496. X  if (!(request->request_mode & XtCWQueryOnly)) {
  497. X    /* reset virtual width and height. */
  498. X    xedwForm->xedwForm.virtual_width = w->core.width = allowed.width;
  499. X    xedwForm->xedwForm.virtual_height = w->core.height = allowed.height;
  500. X    RefigureLocations( (XedwFormWidget)w->core.parent );
  501. X  }
  502. X  return XtGeometryYes;
  503. X}
  504. X
  505. X
  506. X
  507. Xstatic Boolean SetValues(Widget current, Widget request, Widget new)
  508. X{
  509. X  return( FALSE );
  510. X}
  511. X
  512. X
  513. Xstatic void ConstraintInitialize(Widget request, Widget new)
  514. X{
  515. X  XedwFormConstraints xedwForm = (XedwFormConstraints)new->core.constraints;
  516. X  XedwFormWidget fw = (XedwFormWidget)new->core.parent;
  517. X
  518. X  xedwForm->xedwForm.virtual_width = (int) new->core.width;
  519. X  xedwForm->xedwForm.virtual_height = (int) new->core.height;
  520. X
  521. X  if (xedwForm->xedwForm.dx == default_value)
  522. X    xedwForm->xedwForm.dx = fw->xedwForm.default_spacing;
  523. X
  524. X  if (xedwForm->xedwForm.dy == default_value)
  525. X    xedwForm->xedwForm.dy = fw->xedwForm.default_spacing;
  526. X}
  527. X
  528. Xstatic Boolean ConstraintSetValues(Widget current, Widget request, Widget new)
  529. X{
  530. X  return( FALSE );
  531. X}
  532. X
  533. Xstatic void ChangeManaged(Widget w)
  534. X{
  535. X  XedwFormWidget fw = (XedwFormWidget)w;
  536. X  XedwFormConstraints xedwForm;
  537. X  WidgetList children, childP;
  538. X  int num_children = fw->composite.num_children;
  539. X  Widget child;
  540. X
  541. X  /*
  542. X   * Reset virtual width and height for all children.
  543. X   */
  544. X
  545. X  for (children = childP = fw->composite.children ;
  546. X       childP - children < num_children; childP++) {
  547. X    child = *childP;
  548. X    if (XtIsManaged(child)) {
  549. X      xedwForm = (XedwFormConstraints)child->core.constraints;
  550. X      if ( child->core.width != 1)
  551. X        xedwForm->xedwForm.virtual_width = (int) child->core.width;
  552. X      if ( child->core.height != 1)
  553. X        xedwForm->xedwForm.virtual_height = (int) child->core.height;
  554. X    }
  555. X  }
  556. X  RefigureLocations( (XedwFormWidget)w );
  557. X}
  558. X
  559. X
  560. Xstatic XtGeometryResult PreferredGeometry(Widget widget, 
  561. X                      XtWidgetGeometry *request, 
  562. X                      XtWidgetGeometry *reply)
  563. X{
  564. X  XedwFormWidget w = (XedwFormWidget)widget;
  565. X
  566. X  reply->width = w->xedwForm.preferred_width;
  567. X  reply->height = w->xedwForm.preferred_height;
  568. X  reply->request_mode = CWWidth | CWHeight;
  569. X  if (  request->request_mode & (CWWidth | CWHeight) ==
  570. X      reply->request_mode & CWWidth | CWHeight
  571. X      && request->width == reply->width
  572. X      && request->height == reply->height)
  573. X    return XtGeometryYes;
  574. X  else if (reply->width == w->core.width && reply->height == w->core.height)
  575. X    return XtGeometryNo;
  576. X  else
  577. X    return XtGeometryAlmost;
  578. X}
  579. X
  580. X
  581. X/**********************************************************************
  582. X *
  583. X * Public routines
  584. X *
  585. X **********************************************************************/
  586. X
  587. X/*
  588. X * Set or reset figuring (ignored if not realized)
  589. X */
  590. X
  591. Xvoid XedwFormDoLayout(Widget w, Boolean doit)
  592. X{
  593. X  register XedwFormWidget fw = (XedwFormWidget)w;
  594. X
  595. X  fw->xedwForm.no_refigure = !doit;
  596. X
  597. X  if ( XtIsRealized(w) && fw->xedwForm.needs_relayout )
  598. X    RefigureLocations( fw );
  599. X}
  600. SHAR_EOF
  601. chmod 0644 xdtm/Xedw/XedwForm.c ||
  602. echo 'restore of xdtm/Xedw/XedwForm.c failed'
  603. Wc_c="`wc -c < 'xdtm/Xedw/XedwForm.c'`"
  604. test 18923 -eq "$Wc_c" ||
  605.     echo 'xdtm/Xedw/XedwForm.c: original size 18923, current size' "$Wc_c"
  606. fi
  607. # ============= xdtm/Xedw/XedwForm.h ==============
  608. if test -f 'xdtm/Xedw/XedwForm.h' -a X"$1" != X"-c"; then
  609.     echo 'x - skipping xdtm/Xedw/XedwForm.h (File already exists)'
  610. else
  611. echo 'x - extracting xdtm/Xedw/XedwForm.h (Text)'
  612. sed 's/^X//' << 'SHAR_EOF' > 'xdtm/Xedw/XedwForm.h' &&
  613. X/*****************************************************************************
  614. XCopyright 1987, 1988 by Digital Equipment Corporation, Maynard, Massachusetts,
  615. Xand the Massachusetts Institute of Technology, Cambridge, Massachusetts.
  616. X
  617. X                        All Rights Reserved
  618. X
  619. XPermission to use, copy, modify, and distribute this software and its
  620. Xdocumentation for any purpose and without fee is hereby granted,
  621. Xprovided that the above copyright notice appear in all copies and that
  622. Xboth that copyright notice and this permission notice appear in
  623. Xsupporting documentation, and that the names of Digital or MIT not be
  624. Xused in advertising or publicity pertaining to distribution of the
  625. Xsoftware without specific, written prior permission.
  626. X
  627. XDIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  628. XALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  629. XDIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  630. XANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  631. XWHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  632. XARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  633. XSOFTWARE.
  634. X
  635. X*****************************************************************************/
  636. X
  637. X#ifndef _XedwForm_h
  638. X#define _XedwForm_h
  639. X
  640. X#include <X11/Constraint.h>
  641. X#include <X11/Xaw/Form.h>
  642. X
  643. X/***********************************************************************
  644. X *
  645. X * XedwForm Widget
  646. X *
  647. X ***********************************************************************/
  648. X
  649. X/* Parameters:
  650. X
  651. X Name               Class               RepType     Default Value
  652. X ----               -----               -------     -------------
  653. X background         Background          Pixel       XtDefaultBackground
  654. X border             BorderColor         Pixel       XtDefaultForeground
  655. X borderWidth        BorderWidth         Dimension   1
  656. X defaultDistance    Thickness           int         4
  657. X destroyCallback    Callback            Pointer     NULL
  658. X height             Height              Dimension   computed at realize
  659. X mappedWhenManaged  MappedWhenManaged   Boolean     True
  660. X sensitive          Sensitive           Boolean     True
  661. X width              Width               Dimension   computed at realize
  662. X x                  Position            Position    0
  663. X y                  Position            Position    0
  664. X
  665. X*/
  666. X
  667. X/* Constraint parameters:
  668. X
  669. X Name               Class               RepType     Default Value
  670. X ----               -----               -------     -------------
  671. X bottom             Edge                XtEdgeType  XtRubber
  672. X fromHoriz          Widget              Widget      (left edge of xedwForm)
  673. X fromVert           Widget              Widget      (top of xedwForm)
  674. X fullHeight         Boolean             Boolean     False
  675. X fullWidth          Boolean             Boolean     False
  676. X horizDistance      Thickness           int         defaultDistance
  677. X left               Edge                XtEdgeType  XtRubber
  678. X resizable          Boolean             Boolean     False
  679. X right              Edge                XtEdgeType  XtRubber
  680. X rubberHeight       Boolean             Boolean     True
  681. X rubberWidth        Boolean             Boolean     True
  682. X top                Edge                XtEdgeType  XtRubber
  683. X vertDistance       Thickness           int         defaultDistance
  684. X widthLinked        Widget              Widget      NULL
  685. X heightLinked       Widget              Widget      NULL
  686. X
  687. X*/
  688. X
  689. X
  690. X
  691. X#define XtNfullHeight "fullHeight"
  692. X#define XtNfullWidth "fullWidth"
  693. X#define XtNrubberHeight "rubberHeight"
  694. X#define XtNrubberWidth "rubberWidth"
  695. X#define XtNwidthLinked "widthLinked"
  696. X#define XtNheightLinked "heightLinked"
  697. X
  698. Xtypedef struct _XedwFormClassRec    *XedwFormWidgetClass;
  699. Xtypedef struct _XedwFormRec     *XedwFormWidget;
  700. X
  701. Xextern WidgetClass xedwFormWidgetClass;
  702. X
  703. Xextern void XedwFormDoLayout(Widget, Boolean);     /* Boolean doit */
  704. X
  705. X
  706. X#endif /* _XedwForm_h */
  707. SHAR_EOF
  708. chmod 0644 xdtm/Xedw/XedwForm.h ||
  709. echo 'restore of xdtm/Xedw/XedwForm.h failed'
  710. Wc_c="`wc -c < 'xdtm/Xedw/XedwForm.h'`"
  711. test 3912 -eq "$Wc_c" ||
  712.     echo 'xdtm/Xedw/XedwForm.h: original size 3912, current size' "$Wc_c"
  713. fi
  714. # ============= xdtm/Xedw/XedwFormP.h ==============
  715. if test -f 'xdtm/Xedw/XedwFormP.h' -a X"$1" != X"-c"; then
  716.     echo 'x - skipping xdtm/Xedw/XedwFormP.h (File already exists)'
  717. else
  718. echo 'x - extracting xdtm/Xedw/XedwFormP.h (Text)'
  719. sed 's/^X//' << 'SHAR_EOF' > 'xdtm/Xedw/XedwFormP.h' &&
  720. X
  721. X/*****************************************************************************
  722. XCopyright 1987, 1988 by Digital Equipment Corporation, Maynard, Massachusetts,
  723. Xand the Massachusetts Institute of Technology, Cambridge, Massachusetts.
  724. X
  725. X                        All Rights Reserved
  726. X
  727. XPermission to use, copy, modify, and distribute this software and its
  728. Xdocumentation for any purpose and without fee is hereby granted,
  729. Xprovided that the above copyright notice appear in all copies and that
  730. Xboth that copyright notice and this permission notice appear in
  731. Xsupporting documentation, and that the names of Digital or MIT not be
  732. Xused in advertising or publicity pertaining to distribution of the
  733. Xsoftware without specific, written prior permission.
  734. X
  735. XDIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  736. XALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  737. XDIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  738. XANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  739. XWHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  740. XARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  741. XSOFTWARE.
  742. X
  743. X******************************************************************************/
  744. X
  745. X/* XedwForm widget private definitions. This Form is identical to the XawForm
  746. X * Widget except for a few added capabilities.
  747. X */
  748. X
  749. X#ifndef _XedwFormP_h
  750. X#define _XedwFormP_h
  751. X
  752. X#include "XedwForm.h"
  753. X#include <X11/Xaw/FormP.h>
  754. X#include <X11/ConstrainP.h>
  755. X
  756. Xtypedef struct {
  757. X    Boolean (*layout)(XedwFormWidget, Dimension, Dimension );
  758. X} XedwFormClassPart;
  759. X
  760. Xtypedef struct _XedwFormClassRec {
  761. X    CoreClassPart       core_class;
  762. X    CompositeClassPart  composite_class;
  763. X    ConstraintClassPart constraint_class;
  764. X    XedwFormClassPart   xedwForm_class;
  765. X} XedwFormClassRec;
  766. X
  767. Xextern XedwFormClassRec xedwFormClassRec;
  768. X
  769. Xtypedef struct _XedwFormPart {
  770. X    /* resources */
  771. X    int         default_spacing;    /* default distance between children */
  772. X
  773. X    /* private state */
  774. X    Dimension   old_width, old_height; /* last known dimensions      */
  775. X    int         no_refigure;        /* no re-layout while > 0        */
  776. X    Boolean     needs_relayout;     /* next time no_refigure == 0    */
  777. X    Boolean     resize_in_layout;   /* should layout() do geom request?  */
  778. X    Dimension   preferred_width, preferred_height; /* cached from layout */
  779. X} XedwFormPart;
  780. X
  781. Xtypedef struct _XedwFormRec {
  782. X    CorePart            core;
  783. X    CompositePart       composite;
  784. X    ConstraintPart      constraint;
  785. X    XedwFormPart        xedwForm;
  786. X} XedwFormRec;
  787. X
  788. Xtypedef struct _XedwFormConstraintsPart {
  789. X/*
  790. X * Constraint Resources.
  791. X */
  792. X    XtEdgeType  top, bottom,    /* where to drag edge on resize     */
  793. X                left, right;
  794. X    int         dx;             /* desired horiz offset         */
  795. X    int         dy;             /* desired vertical offset      */
  796. X    Widget      horiz_base;     /* measure dx from here if non-null */
  797. X    Widget      vert_base;      /* measure dy from here if non-null */
  798. X    Widget      width_link;     /* get width from this widget if non-null */
  799. X    Widget      height_link;    /* get height from this widget if non-null */
  800. X    Boolean     allow_resize;   /* True if child may request resize */
  801. X    Boolean     full_width;     /* True if child wants to be full width */
  802. X    Boolean     full_height;    /* True if child wants to be full height */
  803. X    Boolean     rubber_width;   /* True if the child may resize width */
  804. X    Boolean     rubber_height;  /* True if the child may resize height */
  805. X
  806. X/*
  807. X * Private contstraint resources.
  808. X */
  809. X
  810. X    int         virtual_width, virtual_height;
  811. X
  812. X/*
  813. X * What the size of this child would be if we did not impose the
  814. X * constraint the width and height must be greater than zero (0).
  815. X */
  816. X
  817. X    LayoutState layout_state;   /* temporary layout state       */
  818. X} XedwFormConstraintsPart;
  819. X
  820. Xtypedef struct _XedwFormConstraintsRec {
  821. X    XedwFormConstraintsPart xedwForm;
  822. X} XedwFormConstraintsRec, *XedwFormConstraints;
  823. X
  824. X#endif /* _XawXedwFormP_h */
  825. SHAR_EOF
  826. chmod 0644 xdtm/Xedw/XedwFormP.h ||
  827. echo 'restore of xdtm/Xedw/XedwFormP.h failed'
  828. Wc_c="`wc -c < 'xdtm/Xedw/XedwFormP.h'`"
  829. test 4040 -eq "$Wc_c" ||
  830.     echo 'xdtm/Xedw/XedwFormP.h: original size 4040, current size' "$Wc_c"
  831. fi
  832. true || echo 'restore of xdtm/Xedw/XedwList.c failed'
  833. echo End of part 2, continue with part 3
  834. exit 0
  835.  
  836. --
  837. Dan Heller
  838. O'Reilly && Associates       Z-Code Software    Comp-sources-x:
  839. Senior Writer                President          comp-sources-x@uunet.uu.net
  840. argv@ora.com                 argv@zipcode.com
  841.