Add initial support for layable children resource.

This commit is contained in:
ramiro 1998-05-22 06:50:41 +00:00
parent 25e35658ed
commit 4cb2e40aa6
17 changed files with 362 additions and 123 deletions

View File

@ -356,6 +356,8 @@ _XFE_WIDGET_CLASS_RECORD(chrome,Chrome) =
NULL, /* draw_background */
XfeInheritDrawShadow, /* draw_shadow */
NULL, /* draw_components */
False, /* count_layable_children*/
NULL, /* child_is_layable */
NULL, /* extension */
},

View File

@ -575,6 +575,8 @@ _XFE_WIDGET_CLASS_RECORD(combobox,ComboBox) =
NULL, /* draw_background */
DrawShadow, /* draw_shadow */
DrawComponents, /* draw_components */
False, /* count_layable_children*/
NULL, /* child_is_layable */
NULL, /* extension */
},

View File

@ -364,6 +364,8 @@ _XFE_WIDGET_CLASS_RECORD(dashboard,DashBoard) =
NULL, /* draw_background */
XfeInheritDrawShadow, /* draw_shadow */
NULL, /* draw_components */
False, /* count_layable_children*/
NULL, /* child_is_layable */
NULL, /* extension */
},

View File

@ -531,6 +531,8 @@ _XFE_WIDGET_CLASS_RECORD(fancybox,FancyBox) =
NULL, /* draw_background */
XfeInheritDrawShadow, /* draw_shadow */
XfeInheritDrawComponents, /* draw_components */
False, /* count_layable_children*/
NULL, /* child_is_layable */
NULL, /* extension */
},

View File

@ -29,7 +29,7 @@
#include <Xfe/PrimitiveP.h>
#include <Xfe/ManagerP.h>
#if 1
#if 0
#ifdef DEBUG_ramiro
#define DEBUG_DIMENSIONS 1
#endif
@ -345,11 +345,12 @@ _XfeConfigureWidget(Widget w,int x,int y,int width,int height)
*
* These assertions help me find such problems.
*/
#if 0
#ifdef DEBUG_ramiro
assert( width >= 0 );
assert( height >= 0 );
#endif
#endif
/* Ignore this request if width or height are 0.
*
* The right thing would be for the above asserts to catch 0 as well.

View File

@ -45,6 +45,8 @@
#define MESSAGE13 "The XmNborderWidth of a child cannot be set explicitly."
#define MESSAGE14 "Cannot accept new child '%s'."
#define MESSAGE15 "XmNnumPrivateComponents is a read-only resource."
#define MESSAGE16 "XmNlayableChildren is a read-only resource."
#define MESSAGE17 "XmNnumLayableChildren is a read-only resource."
#define MIN_LAYOUT_WIDTH 10
#define MIN_LAYOUT_HEIGHT 10
@ -312,6 +314,26 @@ static XtResource resources[] =
(XtPointer) 0
},
/* Layable children resources */
{
XmNnumLayableChildren,
XmCReadOnly,
XmRCardinal,
sizeof(Cardinal),
XtOffsetOf(XfeManagerRec , xfe_manager . num_layable_children),
XmRImmediate,
(XtPointer) 0
},
{
XmNlayableChildren,
XmCReadOnly,
XmRWidgetList,
sizeof(WidgetList),
XtOffsetOf(XfeManagerRec , xfe_manager . layable_children),
XmRImmediate,
(XtPointer) NULL
},
/* Popup children resources */
{
XmNnumPopupChildren,
@ -538,7 +560,9 @@ _XFE_WIDGET_CLASS_RECORD(manager,Manager) =
NULL, /* draw_background */
DrawShadow, /* draw_shadow */
NULL, /* draw_components */
NULL /* extension */
False, /* count_layable_children*/
NULL, /* child_is_layable */
NULL, /* extension */
},
};
@ -608,6 +632,12 @@ ClassPartInit(WidgetClass wc)
_XfeResolve(cc,sc,xfe_manager_class,draw_components,
XfeInheritDrawComponents);
_XfeResolve(cc,sc,xfe_manager_class,count_layable_children,
XfeInheritCountLayableChildren);
_XfeResolve(cc,sc,xfe_manager_class,child_is_layable,
XfeInheritChildIsLayable);
}
/*----------------------------------------------------------------------*/
static void
@ -653,6 +683,12 @@ Destroy(Widget w)
/* XtRemoveAllCallbacks(w,XmNlayoutCallback); */
/* XtRemoveAllCallbacks(w,XmNresizeCallback); */
/* XtRemoveAllCallbacks(w,XmNexposeCallback); */
/* Free the layable children list */
if (_XfemLayableChildren(w) != NULL)
{
XtFree((char *) _XfemLayableChildren(w));
}
}
/*----------------------------------------------------------------------*/
static void
@ -757,6 +793,22 @@ SetValues(Widget ow,Widget rw,Widget nw,ArgList args,Cardinal *nargs)
_XfeWarning(nw,MESSAGE15);
}
/* num_layable_children */
if (_XfemNumLayableChildren(nw) != _XfemNumLayableChildren(ow))
{
_XfemNumLayableChildren(nw) = _XfemNumLayableChildren(ow);
_XfeWarning(nw,MESSAGE17);
}
/* layable_children */
if (_XfemLayableChildren(nw) != _XfemLayableChildren(ow))
{
_XfemLayableChildren(nw) = _XfemLayableChildren(ow);
_XfeWarning(nw,MESSAGE16);
}
/* height */
if (_XfeHeight(nw) != _XfeHeight(ow))
{
@ -1834,132 +1886,21 @@ _XfeManagerDrawShadow(Widget w,
}
}
/*----------------------------------------------------------------------*/
/* Public Functions */
/*----------------------------------------------------------------------*/
void
XfeManagerLayout(Widget w)
/* extern */ Boolean
_XfeManagerChildIsLayable(Widget child)
{
assert( _XfeIsAlive(w) );
assert( XfeIsManager(w) );
Widget w = _XfeParent(child);
XfeManagerWidgetClass mc = (XfeManagerWidgetClass) XtClass(w);
Boolean filter = True;
XfeResize(w);
#if 0
/* Setup the max children dimensions */
_XfeManagerChildrenInfo(w,
&_XfemMaxChildWidth(w),
&_XfemMaxChildHeight(w),
&_XfemTotalChildrenWidth(w),
&_XfemTotalChildrenHeight(w),
&_XfemNumManaged(w),
&_XfemNumComponents(w));
/* Make sure some components exist */
if (!_XfemNumComponents(w))
if (mc->xfe_manager_class.delete_child != NULL)
{
return;
filter = (*mc->xfe_manager_class.delete_child)(child);
}
/* Layout the components */
_XfeManagerLayoutComponents(w);
/* Layout the children */
_XfeManagerLayoutChildren(w);
#endif
return (filter && _XfeChildIsShown(child) && _XfeIsRealized(child));
}
/*----------------------------------------------------------------------*/
void
XfeManagerSetChildrenValues(Widget w,
ArgList args,
Cardinal count,
Boolean only_managed)
{
Cardinal i;
assert(w != NULL);
/* Make sure its a Manager */
if (!XfeIsManager(w))
{
_XfeWarning(w,MESSAGE5);
return;
}
_XfemIgnoreConfigure(w) = True;
/* Iterate through all the items */
for (i = 0; i < _XfemNumChildren(w); i++)
{
Widget obj = _XfemChildren(w)[i];
if (_XfeIsAlive(obj))
{
if (only_managed && XtIsManaged(obj))
{
XtSetValues(obj,args,count);
}
else
{
XtSetValues(obj,args,count);
}
}
}
_XfemIgnoreConfigure(w) = False;
/* XfeConfigure(w); */
}
/*----------------------------------------------------------------------*/
void
XfeManagerApply(Widget w,
XfeManagerApplyProc proc,
XtPointer data,
Boolean only_managed)
{
Cardinal i;
assert(w != NULL);
/* Make sure its a Manager */
if (!XfeIsManager(w))
{
_XfeWarning(w,MESSAGE5);
return;
}
/* Show the action button as needed */
_XfemIgnoreConfigure(w) = True;
/* Iterate through all the items */
for (i = 0; i < _XfemNumChildren(w); i++)
{
Widget child = _XfemChildren(w)[i];
if (child &&
_XfeIsAlive(child) &&
!_XfeManagerPrivateComponent(child))
{
if (only_managed)
{
if (XtIsManaged(child))
{
proc(w,child,data);
}
}
else
{
proc(w,child,data);
}
}
}
_XfemIgnoreConfigure(w) = False;
XfeManagerLayout(w);
}
/*----------------------------------------------------------------------*/
@ -2218,3 +2159,206 @@ _XfeManagerComponentInfo(Widget w,
}
}
/*----------------------------------------------------------------------*/
/*----------------------------------------------------------------------*/
/* */
/* Name: _XfeManagerGetLayableChildren() */
/* */
/* Purpose: Obtain a list of layable children */
/* */
/* Ret Val: void */
/* */
/* Args in: w The manager widget. */
/* */
/* Args out: layable_children_out Array of layable children */
/* num_layable_children_out Size of the array */
/* */
/*----------------------------------------------------------------------*/
/* extern */ void
layable_children(Widget w,
WidgetList * layable_children_out,
Cardinal * num_layable_children_out)
{
Widget child;
Cardinal i;
WidgetList layable_children = NULL;
Cardinal num_layable_children = 0;
assert( XfeIsManager(w) );
assert( layable_children_out != NULL );
assert( num_layable_children_out != NULL );
assert( XfeIsManager(w) );
*layable_children_out = layable_children;
*num_layable_children_out = num_layable_children;
#if 0
/* Iterate through all the items */
for (i = 0; i < _XfemNumChildren(w); i++)
{
child = _XfemChildren(w)[i];
/* Check for private components */
if (_XfeManagerPrivateComponent(child) &&
XtIsManaged(child) &&
_XfeIsAlive(child))
{
/* Keep track of largest width */
if (_XfeWidth(child) > max_width)
{
max_width = _XfeWidth(child);
}
/* Keep track of largest height */
if (_XfeHeight(child) > max_height)
{
max_height = _XfeHeight(child);
}
}
}
/* Assign only required arguments */
if (max_width_out)
{
*max_width_out = max_width;
}
if (max_height_out)
{
*max_height_out = max_height;
}
#endif
}
/*----------------------------------------------------------------------*/
/*----------------------------------------------------------------------*/
/* */
/* XfeManager public functions */
/* */
/*----------------------------------------------------------------------*/
void
XfeManagerLayout(Widget w)
{
assert( _XfeIsAlive(w) );
assert( XfeIsManager(w) );
XfeResize(w);
#if 0
/* Setup the max children dimensions */
_XfeManagerChildrenInfo(w,
&_XfemMaxChildWidth(w),
&_XfemMaxChildHeight(w),
&_XfemTotalChildrenWidth(w),
&_XfemTotalChildrenHeight(w),
&_XfemNumManaged(w),
&_XfemNumComponents(w));
/* Make sure some components exist */
if (!_XfemNumComponents(w))
{
return;
}
/* Layout the components */
_XfeManagerLayoutComponents(w);
/* Layout the children */
_XfeManagerLayoutChildren(w);
#endif
}
/*----------------------------------------------------------------------*/
void
XfeManagerSetChildrenValues(Widget w,
ArgList args,
Cardinal count,
Boolean only_managed)
{
Cardinal i;
assert(w != NULL);
/* Make sure its a Manager */
if (!XfeIsManager(w))
{
_XfeWarning(w,MESSAGE5);
return;
}
_XfemIgnoreConfigure(w) = True;
/* Iterate through all the items */
for (i = 0; i < _XfemNumChildren(w); i++)
{
Widget obj = _XfemChildren(w)[i];
if (_XfeIsAlive(obj))
{
if (only_managed && XtIsManaged(obj))
{
XtSetValues(obj,args,count);
}
else
{
XtSetValues(obj,args,count);
}
}
}
_XfemIgnoreConfigure(w) = False;
/* XfeConfigure(w); */
}
/*----------------------------------------------------------------------*/
void
XfeManagerApply(Widget w,
XfeManagerApplyProc proc,
XtPointer data,
Boolean only_managed)
{
Cardinal i;
assert(w != NULL);
/* Make sure its a Manager */
if (!XfeIsManager(w))
{
_XfeWarning(w,MESSAGE5);
return;
}
/* Show the action button as needed */
_XfemIgnoreConfigure(w) = True;
/* Iterate through all the items */
for (i = 0; i < _XfemNumChildren(w); i++)
{
Widget child = _XfemChildren(w)[i];
if (child &&
_XfeIsAlive(child) &&
!_XfeManagerPrivateComponent(child))
{
if (only_managed)
{
if (XtIsManaged(child))
{
proc(w,child,data);
}
}
else
{
proc(w,child,data);
}
}
}
_XfemIgnoreConfigure(w) = False;
XfeManagerLayout(w);
}
/*----------------------------------------------------------------------*/

View File

@ -46,19 +46,62 @@ extern "C" {
typedef struct
{
XfeBitGravityType bit_gravity; /* bit_gravity */
XfeGeometryProc preferred_geometry; /* preferred_geometry */
XfeGeometryProc minimum_geometry; /* minimum_geometry */
XtWidgetProc update_rect; /* update_rect */
XfeChildFunc accept_child; /* accept_child */
XfeChildFunc insert_child; /* insert_child */
XfeChildFunc delete_child; /* delete_child */
XtWidgetProc change_managed; /* change_managed */
XfePrepareProc prepare_components; /* prepare_components */
XtWidgetProc layout_components; /* layout_components */
XtWidgetProc layout_children; /* layout_children */
XfeExposeProc draw_background; /* draw_background */
XfeExposeProc draw_shadow; /* draw_shadow */
XfeExposeProc draw_components; /* draw_components */
/*
* Layable children support.
*
* If the widget class sets the 'count_layable_children' field to
* 'True', then a read-only list of layable children will be allocated
* and maintained by the XfeManager super class. This list can be
* accessed via the XmNlayableChildren and XmNnumLayableChildren.
*
* The purpose of these two fields is to give the sub class widget
* writer the ability to control children layout in detail. The feature
* is optional so that sub classes of XfeManager that don't need detailed
* layout control will not suffer a runtime resource and performance
* penalty.
*
* The 'child_is_layable' is used to determine whether a child is
* layable. By default all children that comply with the following
* are considered layable:
*
* 1. _XfeIsAlive(child)
* 2. _XfeIsRealized(child)
* 3. _XfeIsManaged(child)
* 4. !_XfemNumPrivateComponents(child)
*
* The XfeManager class does not define an 'child_is_layable' method
* by default. Thus, all children that comply with the above
* conditions are considered layable.
*
* A sub class can further filter which children are layable by
* defining an 'child_is_layable' method. If defined, this method
* will be invoked as needed by the XfeManager class. If should
* return 'True' if the given child is layable, or 'False' otherwise.
*
*/
Boolean count_layable_children;
XfeChildFunc child_is_layable;
XtPointer extension; /* extension */
} XfeManagerClassPart;
@ -120,6 +163,10 @@ typedef struct _XfeManagerPart
/* Private Component resources */
Cardinal num_private_components; /* Num private components*/
/* Layable children resources */
Cardinal num_layable_children; /* Num layable children */
WidgetList layable_children; /* Layable children */
/* Private Data Members */
int config_flags; /* Require Geometry */
int prepare_flags; /* Require Geometry */
@ -245,6 +292,9 @@ _XfeManagerDrawShadow (Widget w,
Region region,
XRectangle * clip_rect);
/*----------------------------------------------------------------------*/
extern Boolean
_XfeManagerChildIsLayable (Widget child);
/*----------------------------------------------------------------------*/
/*----------------------------------------------------------------------*/
/* */
@ -272,7 +322,15 @@ _XfeManagerComponentInfo (Widget w,
/* */
/*----------------------------------------------------------------------*/
#define _XfeManagerAccessBitGravity(w) \
(((XfeManagerWidgetClass) XtClass(w))->xfe_manager_class.bit_gravity)
(((XfeManagerWidgetClass) XtClass(w))->xfe_manager_class . bit_gravity)
/*----------------------------------------------------------------------*/
/* */
/* XfeManagerWidgetClass bit_gravity access macro */
/* */
/*----------------------------------------------------------------------*/
#define _XfeManagerTrackLayableChildren(w) \
(((XfeManagerWidgetClass) XtClass(w))->xfe_manager_class . count_layable_children)
/*----------------------------------------------------------------------*/
/* */
@ -475,6 +533,12 @@ _XfeManagerComponentInfo (Widget w,
#define _XfemNumPrivateComponents(w) \
(((XfeManagerWidget) (w))->xfe_manager . num_private_components)
/*----------------------------------------------------------------------*/
#define _XfemLayableChildren(w) \
(((XfeManagerWidget) (w))->xfe_manager . layable_children)
/*----------------------------------------------------------------------*/
#define _XfemNumLayableChildren(w) \
(((XfeManagerWidget) (w))->xfe_manager . num_layable_children)
/*----------------------------------------------------------------------*/
/*----------------------------------------------------------------------*/
/* */

View File

@ -306,6 +306,8 @@ _XFE_WIDGET_CLASS_RECORD(oriented,Oriented) =
NULL, /* draw_background */
XfeInheritDrawShadow, /* draw_shadow */
NULL, /* draw_components */
False, /* count_layable_children*/
NULL, /* child_is_layable */
NULL, /* extension */
},

View File

@ -639,6 +639,8 @@ _XFE_WIDGET_CLASS_RECORD(pane,Pane) =
NULL, /* draw_background */
XfeInheritDrawShadow, /* draw_shadow */
DrawComponents, /* draw_components */
False, /* count_layable_children*/
NULL, /* child_is_layable */
NULL, /* extension */
},

View File

@ -198,6 +198,7 @@
#define XmNlabelAlignment "labelAlignment"
#define XmNlabelDirection "labelDirection"
#define XmNlabelPixmapMask "labelPixmapMask"
#define XmNlayableChildren "layableChildren"
#define XmNleftPixmap "leftPixmap"
#define XmNleftRaisedPixmap "leftRaisedPixmap"
#define XmNleftView "leftView"
@ -211,6 +212,7 @@
#define XmNmaxNumRows "maxNumRows"
#define XmNnumAnimationPixmaps "numAnimationPixmaps"
#define XmNnumFontItems "numFontItems"
#define XmNnumLayableChildren "numLayableChildren"
#define XmNnumPopupChildren "numPopupChildren"
#define XmNnumPrivateComponents "numPrivateComponents"
#define XmNnumRows "numRows"
@ -400,6 +402,7 @@
#define XmCLabelAlignment "LabelAlignment"
#define XmCLabelDirection "LabelDirection"
#define XmCLabelPixmapMask "LabelPixmapMask"
#define XmCLayableChildren "LayableChildren"
#define XmCLeftPixmap "LeftPixmap"
#define XmCLeftRaisedPixmap "LeftRaisedPixmap"
#define XmCListFontList "ListFontList"
@ -408,6 +411,7 @@
#define XmCMaxNumRows "MaxNumRows"
#define XmCNumAnimationPixmaps "NumAnimationPixmaps"
#define XmCNumFontItems "NumFontItems"
#define XmCNumLayableChildren "NumLayableChildren"
#define XmCNumLogoPixmaps "NumLogoPixmaps"
#define XmCNumRows "NumRows"
#define XmCOpen "Open"

View File

@ -265,6 +265,8 @@ _XFE_WIDGET_CLASS_RECORD(taskbar,TaskBar) =
NULL, /* draw_background */
XfeInheritDrawShadow, /* draw_shadow */
XfeInheritDrawComponents, /* draw_components */
False, /* count_layable_children*/
NULL, /* child_is_layable */
NULL, /* extension */
},

View File

@ -463,6 +463,8 @@ _XFE_WIDGET_CLASS_RECORD(temptwo,TempTwo) =
NULL, /* draw_background */
XfeInheritDrawShadow, /* draw_shadow */
DrawComponents, /* draw_components */
False, /* count_layable_children*/
NULL, /* child_is_layable */
NULL, /* extension */
},

View File

@ -539,6 +539,8 @@ _XFE_WIDGET_CLASS_RECORD(toolbar,ToolBar) =
NULL, /* draw_background */
XfeInheritDrawShadow, /* draw_shadow */
DrawComponents, /* draw_components */
True, /* count_layable_children*/
NULL, /* child_is_layable */
NULL, /* extension */
},

View File

@ -649,6 +649,8 @@ _XFE_WIDGET_CLASS_RECORD(toolbox,ToolBox) =
NULL, /* draw_background */
XfeInheritDrawShadow, /* draw_shadow */
NULL, /* draw_components */
False, /* count_layable_children*/
NULL, /* child_is_layable */
NULL, /* extension */
},

View File

@ -197,6 +197,8 @@ _XFE_WIDGET_CLASS_RECORD(toolitem,ToolItem) =
NULL, /* draw_background */
XfeInheritDrawShadow, /* draw_shadow */
NULL, /* draw_components */
False, /* count_layable_children*/
NULL, /* child_is_layable */
NULL, /* extension */
},

View File

@ -311,6 +311,8 @@ _XFE_WIDGET_CLASS_RECORD(toolscroll,ToolScroll) =
NULL, /* draw_background */
XfeInheritDrawShadow, /* draw_shadow */
DrawComponents, /* draw_components */
False, /* count_layable_children*/
NULL, /* child_is_layable */
NULL, /* extension */
},

View File

@ -114,6 +114,7 @@ typedef int XfeBitGravityType;
#define XfeInheritArmTimeout ((XtTimerCallbackProc) _XtInherit)
#define XfeInheritBitGravity ((XfeBitGravityType) _XtInherit)
#define XfeInheritChangeManaged ((XtWidgetProc) _XtInherit)
#define XfeInheritChildIsLayable ((XfeChildFunc) _XtInherit)
#define XfeInheritClickTimeout ((XtTimerCallbackProc) _XtInherit)
#define XfeInheritDeleteChild ((XfeChildFunc) _XtInherit)
#define XfeInheritDescendantDragEnd ((XfeOrientedProc) _XtInherit)
@ -152,6 +153,7 @@ typedef int XfeBitGravityType;
#define XfeInheritMotion ((XfeOrientedProc) _XtInherit)
#define XfeInheritPreferredGeometry ((XfeGeometryProc) _XtInherit)
#define XfeInheritToggleSelection ((XtWidgetProc) _XtInherit)
#define XfeInheritCountLayableChildren ((Boolean) _XtInherit)
#define XfeInheritUpdateRect ((XtWidgetProc) _XtInherit)
/*----------------------------------------------------------------------*/