diff options
Diffstat (limited to 'src/Viewport.c')
-rw-r--r-- | src/Viewport.c | 1184 |
1 files changed, 600 insertions, 584 deletions
diff --git a/src/Viewport.c b/src/Viewport.c index 02182e0..eafc00c 100644 --- a/src/Viewport.c +++ b/src/Viewport.c @@ -46,141 +46,223 @@ ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ******************************************************************/ +/* $XFree86: xc/lib/Xaw/Viewport.c,v 1.11 2001/12/14 19:54:45 dawes Exp $ */ #include <X11/IntrinsicP.h> #include <X11/StringDefs.h> - -#include <X11/Xaw/XawInit.h> #include <X11/Xmu/Misc.h> #include <X11/Xaw/Scrollbar.h> #include <X11/Xaw/ViewportP.h> +#include <X11/Xaw/XawInit.h> +#include "Private.h" -static void ScrollUpDownProc(), ThumbProc(); -static Boolean GetGeometry(); +/* + * Class Methods + */ +static Boolean Layout(FormWidget, unsigned int, unsigned int, Bool); +static void XawViewportChangeManaged(Widget); +static void XawViewportInitialize(Widget, Widget, ArgList, Cardinal*); +static void +XawViewportConstraintInitialize(Widget, Widget, ArgList, Cardinal*); +static XtGeometryResult XawViewportGeometryManager(Widget, XtWidgetGeometry*, + XtWidgetGeometry*); +static XtGeometryResult XawViewportQueryGeometry(Widget, + XtWidgetGeometry*, + XtWidgetGeometry*); +static void XawViewportRealize(Widget, XtValueMask*, XSetWindowAttributes*); +static void XawViewportResize(Widget); +static Boolean XawViewportSetValues(Widget, Widget, Widget, + ArgList, Cardinal*); -static void ComputeWithForceBars(); +/* + * Prototypes + */ +static void ComputeLayout(Widget, Bool, Bool); +static void ComputeWithForceBars(Widget, Bool, XtWidgetGeometry*, + int*, int*); +static Widget CreateScrollbar(ViewportWidget, Bool); +static XtGeometryResult GeometryRequestPlusScrollbar(ViewportWidget, Bool, + XtWidgetGeometry*, + XtWidgetGeometry*); +static Bool GetGeometry(Widget, unsigned int, unsigned int); +static void MoveChild(ViewportWidget, int, int); +static XtGeometryResult QueryGeometry(ViewportWidget, XtWidgetGeometry*, + XtWidgetGeometry*); +static void RedrawThumbs(ViewportWidget); +static void ScrollUpDownProc(Widget, XtPointer, XtPointer); +static void SendReport(ViewportWidget, unsigned int); +static void SetBar(Widget, int, unsigned int, unsigned int); +static XtGeometryResult TestSmaller(ViewportWidget, XtWidgetGeometry*, + XtWidgetGeometry*); +static void ThumbProc(Widget, XtPointer, XtPointer); +/* + * Initialization + */ #define offset(field) XtOffsetOf(ViewportRec, viewport.field) static XtResource resources[] = { - {XtNforceBars, XtCBoolean, XtRBoolean, sizeof(Boolean), - offset(forcebars), XtRImmediate, (XtPointer)False}, - {XtNallowHoriz, XtCBoolean, XtRBoolean, sizeof(Boolean), - offset(allowhoriz), XtRImmediate, (XtPointer)False}, - {XtNallowVert, XtCBoolean, XtRBoolean, sizeof(Boolean), - offset(allowvert), XtRImmediate, (XtPointer)False}, - {XtNuseBottom, XtCBoolean, XtRBoolean, sizeof(Boolean), - offset(usebottom), XtRImmediate, (XtPointer)False}, - {XtNuseRight, XtCBoolean, XtRBoolean, sizeof(Boolean), - offset(useright), XtRImmediate, (XtPointer)False}, - {XtNreportCallback, XtCReportCallback, XtRCallback, sizeof(XtPointer), - offset(report_callbacks), XtRImmediate, (XtPointer) NULL}, + { + XtNforceBars, + XtCBoolean, + XtRBoolean, + sizeof(Boolean), + offset(forcebars), + XtRImmediate, + (XtPointer)False + }, + { + XtNallowHoriz, + XtCBoolean, + XtRBoolean, + sizeof(Boolean), + offset(allowhoriz), + XtRImmediate, + (XtPointer)False + }, + { + XtNallowVert, + XtCBoolean, + XtRBoolean, + sizeof(Boolean), + offset(allowvert), + XtRImmediate, + (XtPointer)False + }, + { + XtNuseBottom, + XtCBoolean, + XtRBoolean, + sizeof(Boolean), + offset(usebottom), + XtRImmediate, + (XtPointer)False + }, + { + XtNuseRight, + XtCBoolean, + XtRBoolean, + sizeof(Boolean), + offset(useright), + XtRImmediate, + (XtPointer)False + }, + { + XtNreportCallback, + XtCReportCallback, + XtRCallback, + sizeof(XtPointer), + offset(report_callbacks), + XtRImmediate, + NULL + }, }; #undef offset -static void Initialize(), ConstraintInitialize(), - Realize(), Resize(), ChangeManaged(); -static Boolean SetValues(), Layout(); -static XtGeometryResult GeometryManager(), PreferredGeometry(); - -#define superclass (&formClassRec) +#define Superclass (&formClassRec) ViewportClassRec viewportClassRec = { - { /* core_class fields */ - /* superclass */ (WidgetClass) superclass, - /* class_name */ "Viewport", - /* widget_size */ sizeof(ViewportRec), - /* class_initialize */ XawInitializeWidgetSet, - /* class_part_init */ NULL, - /* class_inited */ FALSE, - /* initialize */ Initialize, - /* initialize_hook */ NULL, - /* realize */ Realize, - /* actions */ NULL, - /* num_actions */ 0, - /* resources */ resources, - /* num_resources */ XtNumber(resources), - /* xrm_class */ NULLQUARK, - /* compress_motion */ TRUE, - /* compress_exposure */ TRUE, - /* compress_enterleave*/ TRUE, - /* visible_interest */ FALSE, - /* destroy */ NULL, - /* resize */ Resize, - /* expose */ XtInheritExpose, - /* set_values */ SetValues, - /* set_values_hook */ NULL, - /* set_values_almost */ XtInheritSetValuesAlmost, - /* get_values_hook */ NULL, - /* accept_focus */ NULL, - /* version */ XtVersion, - /* callback_private */ NULL, - /* tm_table */ NULL, - /* query_geometry */ PreferredGeometry, - /* display_accelerator*/ XtInheritDisplayAccelerator, - /* extension */ NULL + /* core */ + { + (WidgetClass)Superclass, /* superclass */ + "Viewport", /* class_name */ + sizeof(ViewportRec), /* widget_size */ + XawInitializeWidgetSet, /* class_initialize */ + NULL, /* class_part_init */ + False, /* class_inited */ + XawViewportInitialize, /* initialize */ + NULL, /* initialize_hook */ + XawViewportRealize, /* realize */ + NULL, /* actions */ + 0, /* num_actions */ + resources, /* resources */ + XtNumber(resources), /* num_resources */ + NULLQUARK, /* xrm_class */ + True, /* compress_motion */ + True, /* compress_exposure */ + True, /* compress_enterleave */ + False, /* visible_interest */ + NULL, /* destroy */ + XawViewportResize, /* resize */ + XtInheritExpose, /* expose */ + XawViewportSetValues, /* set_values */ + NULL, /* set_values_hook */ + XtInheritSetValuesAlmost, /* set_values_almost */ + NULL, /* get_values_hook */ + NULL, /* accept_focus */ + XtVersion, /* version */ + NULL, /* callback_private */ + NULL, /* tm_table */ + XawViewportQueryGeometry, /* query_geometry */ + XtInheritDisplayAccelerator, /* display_accelerator */ + NULL, /* extension */ }, - { /* composite_class fields */ - /* geometry_manager */ GeometryManager, - /* change_managed */ ChangeManaged, - /* insert_child */ XtInheritInsertChild, - /* delete_child */ XtInheritDeleteChild, - /* extension */ NULL + /* composite */ + { + XawViewportGeometryManager, /* geometry_manager */ + XawViewportChangeManaged, /* change_managed */ + XtInheritInsertChild, /* insert_child */ + XtInheritDeleteChild, /* delete_child */ + NULL, /* extension */ }, - { /* constraint_class fields */ - /* subresourses */ NULL, - /* subresource_count */ 0, - /* constraint_size */ sizeof(ViewportConstraintsRec), - /* initialize */ ConstraintInitialize, - /* destroy */ NULL, - /* set_values */ NULL, - /* extension */ NULL + /* constraint */ + { + NULL, /* subresourses */ + 0, /* subresource_count */ + sizeof(ViewportConstraintsRec), /* constraint_size */ + XawViewportConstraintInitialize, /* initialize */ + NULL, /* destroy */ + NULL, /* set_values */ + NULL, /* extension */ }, - { /* form_class fields */ - /* layout */ Layout + /* form */ + { + Layout, /* layout */ + }, + /* viewport */ + { + NULL, /* extension */ }, - { /* viewport_class fields */ - /* empty */ 0 - } }; - WidgetClass viewportWidgetClass = (WidgetClass)&viewportClassRec; -static Widget CreateScrollbar(w, horizontal) - ViewportWidget w; - Boolean horizontal; +/* + * Implementation + */ +static Widget +CreateScrollbar(ViewportWidget w, Bool horizontal) { + static Arg barArgs[] = { + {XtNorientation, 0}, + {XtNlength, 0}, + {XtNleft, 0}, + {XtNright, 0}, + {XtNtop, 0}, + {XtNbottom, 0}, + {XtNmappedWhenManaged, False}, + }; Widget clip = w->viewport.clip; ViewportConstraints constraints = (ViewportConstraints)clip->core.constraints; - static Arg barArgs[] = { - {XtNorientation, (XtArgVal) 0}, - {XtNlength, (XtArgVal) 0}, - {XtNleft, (XtArgVal) 0}, - {XtNright, (XtArgVal) 0}, - {XtNtop, (XtArgVal) 0}, - {XtNbottom, (XtArgVal) 0}, - {XtNmappedWhenManaged, (XtArgVal) False}, - }; Widget bar; XtSetArg(barArgs[0], XtNorientation, - horizontal ? XtorientHorizontal : XtorientVertical ); + horizontal ? XtorientHorizontal : XtorientVertical); XtSetArg(barArgs[1], XtNlength, - horizontal ? clip->core.width : clip->core.height); + horizontal ? XtWidth(clip) : XtHeight(clip)); XtSetArg(barArgs[2], XtNleft, - (!horizontal && w->viewport.useright) ? XtChainRight : XtChainLeft); + !horizontal && w->viewport.useright ? XtChainRight : XtChainLeft); XtSetArg(barArgs[3], XtNright, - (!horizontal && !w->viewport.useright) ? XtChainLeft : XtChainRight); + !horizontal && !w->viewport.useright ? XtChainLeft : XtChainRight); XtSetArg(barArgs[4], XtNtop, - (horizontal && w->viewport.usebottom) ? XtChainBottom: XtChainTop); + horizontal && w->viewport.usebottom ? XtChainBottom: XtChainTop); XtSetArg(barArgs[5], XtNbottom, - (horizontal && !w->viewport.usebottom) ? XtChainTop: XtChainBottom); + horizontal && !w->viewport.usebottom ? XtChainTop: XtChainBottom); - bar = XtCreateWidget((horizontal ? "horizontal" : "vertical"), - scrollbarWidgetClass, (Widget)w, - barArgs, XtNumber(barArgs) ); - XtAddCallback( bar, XtNscrollProc, ScrollUpDownProc, (XtPointer)w ); - XtAddCallback( bar, XtNjumpProc, ThumbProc, (XtPointer)w ); + bar = XtCreateWidget(horizontal ? "horizontal" : "vertical", + scrollbarWidgetClass, (Widget)w, + barArgs, XtNumber(barArgs)); + XtAddCallback(bar, XtNscrollProc, ScrollUpDownProc, (XtPointer)w); + XtAddCallback(bar, XtNjumpProc, ThumbProc, (XtPointer)w); if (horizontal) { w->viewport.horiz_bar = bar; @@ -191,77 +273,68 @@ static Widget CreateScrollbar(w, horizontal) constraints->form.horiz_base = bar; } - XtManageChild( bar ); + XtManageChild(bar); - return bar; + return (bar); } -/* ARGSUSED */ -static void Initialize(request, new, args, num_args) - Widget request, new; - ArgList args; - Cardinal *num_args; +/*ARGSUSED*/ +static void +XawViewportInitialize(Widget request, Widget cnew, + ArgList args, Cardinal *num_args) { - ViewportWidget w = (ViewportWidget)new; + ViewportWidget w = (ViewportWidget)cnew; static Arg clip_args[8]; Cardinal arg_cnt; Widget h_bar, v_bar; Dimension clip_height, clip_width; - w->form.default_spacing = 0; /* Reset the default spacing to 0 pixels. */ + w->form.default_spacing = 0; /* Reset the default spacing to 0 pixels */ + /* + * Initialize all widget pointers to NULL + */ + w->viewport.child = NULL; + w->viewport.horiz_bar = w->viewport.vert_bar = NULL; -/* - * Initialize all widget pointers to NULL. - */ - - w->viewport.child = (Widget) NULL; - w->viewport.horiz_bar = w->viewport.vert_bar = (Widget)NULL; - -/* - * Create Clip Widget. - */ - + /* + * Create Clip Widget + */ arg_cnt = 0; - XtSetArg(clip_args[arg_cnt], XtNbackgroundPixmap, None); arg_cnt++; - XtSetArg(clip_args[arg_cnt], XtNborderWidth, 0); arg_cnt++; - XtSetArg(clip_args[arg_cnt], XtNleft, XtChainLeft); arg_cnt++; - XtSetArg(clip_args[arg_cnt], XtNright, XtChainRight); arg_cnt++; - XtSetArg(clip_args[arg_cnt], XtNtop, XtChainTop); arg_cnt++; - XtSetArg(clip_args[arg_cnt], XtNbottom, XtChainBottom); arg_cnt++; - XtSetArg(clip_args[arg_cnt], XtNwidth, w->core.width); arg_cnt++; - XtSetArg(clip_args[arg_cnt], XtNheight, w->core.height); arg_cnt++; - - w->viewport.clip = XtCreateManagedWidget("clip", widgetClass, new, + XtSetArg(clip_args[arg_cnt], XtNbackgroundPixmap, None); arg_cnt++; + XtSetArg(clip_args[arg_cnt], XtNborderWidth, 0); arg_cnt++; + XtSetArg(clip_args[arg_cnt], XtNleft, XtChainLeft); arg_cnt++; + XtSetArg(clip_args[arg_cnt], XtNright, XtChainRight); arg_cnt++; + XtSetArg(clip_args[arg_cnt], XtNtop, XtChainTop); arg_cnt++; + XtSetArg(clip_args[arg_cnt], XtNbottom, XtChainBottom); arg_cnt++; + XtSetArg(clip_args[arg_cnt], XtNwidth, XtWidth(w)); arg_cnt++; + XtSetArg(clip_args[arg_cnt], XtNheight, XtHeight(w)); arg_cnt++; + + w->viewport.clip = XtCreateManagedWidget("clip", widgetClass, cnew, clip_args, arg_cnt); if (!w->viewport.forcebars) - return; /* If we are not forcing the bars then we are done. */ + return; /* If we are not forcing the bars then we are done */ if (w->viewport.allowhoriz) - (void) CreateScrollbar(w, True); + (void)CreateScrollbar(w, True); if (w->viewport.allowvert) - (void) CreateScrollbar(w, False); + (void)CreateScrollbar(w, False); h_bar = w->viewport.horiz_bar; v_bar = w->viewport.vert_bar; -/* - * Set the clip widget to the correct height. - */ + /* + * Set the clip widget to the correct height + */ + clip_width = XtWidth(w); + clip_height = XtHeight(w); - clip_width = w->core.width; - clip_height = w->core.height; + if (h_bar != NULL && XtWidth(w) > XtWidth(h_bar) + XtBorderWidth(h_bar)) + clip_width -= XtWidth(h_bar) + XtBorderWidth(h_bar); - if ( (h_bar != NULL) && - ((int)w->core.width > - (int)(h_bar->core.width + h_bar->core.border_width)) ) - clip_width -= h_bar->core.width + h_bar->core.border_width; - - if ( (v_bar != NULL) && - ((int)w->core.height > - (int)(v_bar->core.height + v_bar->core.border_width)) ) - clip_height -= v_bar->core.height + v_bar->core.border_width; + if (v_bar != NULL && XtHeight(w) > XtHeight(v_bar) + XtBorderWidth(v_bar)) + clip_height -= XtHeight(v_bar) + XtBorderWidth(v_bar); arg_cnt = 0; XtSetArg(clip_args[arg_cnt], XtNwidth, clip_width); arg_cnt++; @@ -269,19 +342,17 @@ static void Initialize(request, new, args, num_args) XtSetValues(w->viewport.clip, clip_args, arg_cnt); } -/* ARGSUSED */ -static void ConstraintInitialize(request, new, args, num_args) - Widget request, new; - ArgList args; - Cardinal *num_args; +/*ARGSUSED*/ +static void +XawViewportConstraintInitialize(Widget request, Widget cnew, + ArgList args, Cardinal *num_args) { - ((ViewportConstraints)new->core.constraints)->viewport.reparented = False; + ((ViewportConstraints)cnew->core.constraints)->viewport.reparented = False; } -static void Realize(widget, value_mask, attributes) - Widget widget; - XtValueMask *value_mask; - XSetWindowAttributes *attributes; +static void +XawViewportRealize(Widget widget, XtValueMask *value_mask, + XSetWindowAttributes *attributes) { ViewportWidget w = (ViewportWidget)widget; Widget child = w->viewport.child; @@ -289,57 +360,53 @@ static void Realize(widget, value_mask, attributes) *value_mask |= CWBitGravity; attributes->bit_gravity = NorthWestGravity; - (*superclass->core_class.realize)(widget, value_mask, attributes); + (*Superclass->core_class.realize)(widget, value_mask, attributes); (*w->core.widget_class->core_class.resize)(widget); /* turn on bars */ - if (child != (Widget)NULL) { - XtMoveWidget( child, (Position)0, (Position)0 ); - XtRealizeWidget( clip ); - XtRealizeWidget( child ); - XReparentWindow( XtDisplay(w), XtWindow(child), XtWindow(clip), - (Position)0, (Position)0 ); - XtMapWidget( child ); + if (child != NULL) { + XtMoveWidget(child, 0, 0); + XtRealizeWidget(clip); + XtRealizeWidget(child); + XReparentWindow(XtDisplay(w), XtWindow(child), XtWindow(clip), 0, 0); + XtMapWidget(child); } } -/* ARGSUSED */ -static Boolean SetValues(current, request, new, args, num_args) - Widget current, request, new; - ArgList args; - Cardinal *num_args; +/*ARGSUSED*/ +static Boolean +XawViewportSetValues(Widget current, Widget request, Widget cnew, + ArgList args, Cardinal *num_args) { - ViewportWidget w = (ViewportWidget)new; + ViewportWidget w = (ViewportWidget)cnew; ViewportWidget cw = (ViewportWidget)current; - if ( (w->viewport.forcebars != cw->viewport.forcebars) || - (w->viewport.allowvert != cw->viewport.allowvert) || - (w->viewport.allowhoriz != cw->viewport.allowhoriz) || - (w->viewport.useright != cw->viewport.useright) || - (w->viewport.usebottom != cw->viewport.usebottom) ) - { - (*w->core.widget_class->core_class.resize)(new); /* Recompute layout.*/ - } + if (w->viewport.forcebars != cw->viewport.forcebars + || w->viewport.allowvert != cw->viewport.allowvert + || w->viewport.allowhoriz != cw->viewport.allowhoriz + || w->viewport.useright != cw->viewport.useright + || w->viewport.usebottom != cw->viewport.usebottom) + (*w->core.widget_class->core_class.resize)(cnew); /* Recompute layout */ - return False; + return (False); } - -static void ChangeManaged(widget) - Widget widget; +static void +XawViewportChangeManaged(Widget widget) { ViewportWidget w = (ViewportWidget)widget; int num_children = w->composite.num_children; Widget child, *childP; int i; - child = (Widget)NULL; - for (childP=w->composite.children, i=0; i < num_children; childP++, i++) { + child = NULL; + for (childP = w->composite.children, + i = 0; i < num_children; + childP++, i++) { if (XtIsManaged(*childP) && *childP != w->viewport.clip && *childP != w->viewport.horiz_bar - && *childP != w->viewport.vert_bar) - { + && *childP != w->viewport.vert_bar) { child = *childP; break; } @@ -347,81 +414,63 @@ static void ChangeManaged(widget) if (child != w->viewport.child) { w->viewport.child = child; - if (child != (Widget)NULL) { - XtResizeWidget( child, child->core.width, - child->core.height, (Dimension)0 ); + if (child != NULL) { + XtResizeWidget(child, XtWidth(child), XtHeight(child), 0); if (XtIsRealized(widget)) { ViewportConstraints constraints = (ViewportConstraints)child->core.constraints; if (!XtIsRealized(child)) { Window window = XtWindow(w); - XtMoveWidget( child, (Position)0, (Position)0 ); -#ifdef notdef - /* this is dirty, but it saves the following code: */ - XtRealizeWidget( child ); - XReparentWindow( XtDisplay(w), XtWindow(child), - XtWindow(w->viewport.clip), - (Position)0, (Position)0 ); - if (child->core.mapped_when_managed) - XtMapWidget( child ); -#else + + XtMoveWidget(child, 0, 0); w->core.window = XtWindow(w->viewport.clip); - XtRealizeWidget( child ); + XtRealizeWidget(child); w->core.window = window; -#endif /* notdef */ constraints->viewport.reparented = True; } else if (!constraints->viewport.reparented) { - XReparentWindow( XtDisplay(w), XtWindow(child), - XtWindow(w->viewport.clip), - (Position)0, (Position)0 ); + XReparentWindow(XtDisplay(w), XtWindow(child), + XtWindow(w->viewport.clip), 0, 0); constraints->viewport.reparented = True; if (child->core.mapped_when_managed) - XtMapWidget( child ); + XtMapWidget(child); } } - GetGeometry( widget, child->core.width, child->core.height ); + GetGeometry(widget, XtWidth(child), XtHeight(child)); (*((ViewportWidgetClass)w->core.widget_class)->form_class.layout) - ( (FormWidget)w, w->core.width, w->core.height ); - /* %%% do we need to hide this child from Form? */ + ((FormWidget)w, XtWidth(w), XtHeight(w), True /* True? */); } } #ifdef notdef - (*superclass->composite_class.change_managed)( widget ); + (*Superclass->composite_class.change_managed)(widget); #endif } - -static void SetBar(w, top, length, total) - Widget w; - Position top; - Dimension length, total; +static void +SetBar(Widget w, int top, unsigned int length, unsigned int total) { - XawScrollbarSetThumb(w, (float)top/(float)total, - (float)length/(float)total); + XawScrollbarSetThumb(w, (float)top / (float)total, + (float)length / (float)total); } -static void RedrawThumbs(w) - ViewportWidget w; +static void +RedrawThumbs(ViewportWidget w) { Widget child = w->viewport.child; Widget clip = w->viewport.clip; - if (w->viewport.horiz_bar != (Widget)NULL) - SetBar( w->viewport.horiz_bar, -(child->core.x), - clip->core.width, child->core.width ); + if (w->viewport.horiz_bar != NULL) + SetBar(w->viewport.horiz_bar, -(int)XtX(child), + XtWidth(clip), XtWidth(child)); - if (w->viewport.vert_bar != (Widget)NULL) - SetBar( w->viewport.vert_bar, -(child->core.y), - clip->core.height, child->core.height ); + if (w->viewport.vert_bar != NULL) + SetBar(w->viewport.vert_bar, -(int)XtY(child), + XtHeight(clip), XtHeight(child)); } - - -static void SendReport (w, changed) - ViewportWidget w; - unsigned int changed; +static void +SendReport(ViewportWidget w, unsigned int changed) { XawPannerReport rep; @@ -430,72 +479,70 @@ static void SendReport (w, changed) Widget clip = w->viewport.clip; rep.changed = changed; - rep.slider_x = -child->core.x; /* child is canvas */ - rep.slider_y = -child->core.y; /* clip is slider */ - rep.slider_width = clip->core.width; - rep.slider_height = clip->core.height; - rep.canvas_width = child->core.width; - rep.canvas_height = child->core.height; - XtCallCallbackList ((Widget) w, w->viewport.report_callbacks, - (XtPointer) &rep); + rep.slider_x = -XtX(child); /* child is canvas */ + rep.slider_y = -XtY(child); /* clip is slider */ + rep.slider_width = XtWidth(clip); + rep.slider_height = XtHeight(clip); + rep.canvas_width = XtWidth(child); + rep.canvas_height = XtHeight(child); + XtCallCallbackList((Widget)w, w->viewport.report_callbacks, + (XtPointer)&rep); } } - -static void MoveChild(w, x, y) - ViewportWidget w; - Position x, y; +static void +MoveChild(ViewportWidget w, int x, int y) { Widget child = w->viewport.child; Widget clip = w->viewport.clip; /* make sure we never move past right/bottom borders */ - if (-x + (int)clip->core.width > (int)child->core.width) - x = -(child->core.width - clip->core.width); + if (-x + (int)XtWidth(clip) > XtWidth(child)) + x = -(int)(XtWidth(child) - XtWidth(clip)); - if (-y + (int)clip->core.height > (int)child->core.height) - y = -(child->core.height - clip->core.height); + if (-y + (int)XtHeight(clip) > XtHeight(child)) + y = -(int)(XtHeight(child) - XtHeight(clip)); /* make sure we never move past left/top borders */ - if (x >= 0) x = 0; - if (y >= 0) y = 0; + if (x >= 0) + x = 0; + if (y >= 0) + y = 0; XtMoveWidget(child, x, y); - SendReport (w, (XawPRSliderX | XawPRSliderY)); + SendReport(w, (XawPRSliderX | XawPRSliderY)); RedrawThumbs(w); } - -static void ComputeLayout(widget, query, destroy_scrollbars) - Widget widget; /* Viewport */ - Boolean query; /* query child's preferred geom? */ - Boolean destroy_scrollbars; /* destroy un-needed scrollbars? */ +static void +ComputeLayout(Widget widget, Bool query, Bool destroy_scrollbars) { ViewportWidget w = (ViewportWidget)widget; Widget child = w->viewport.child; Widget clip = w->viewport.clip; - ViewportConstraints constraints - = (ViewportConstraints)clip->core.constraints; - Boolean needshoriz, needsvert; + ViewportConstraints constraints = + (ViewportConstraints)clip->core.constraints; + Bool needshoriz, needsvert; int clip_width, clip_height; XtWidgetGeometry intended; - if (child == (Widget) NULL) return; + if (child == NULL) + return; - clip_width = w->core.width; - clip_height = w->core.height; + clip_width = XtWidth(w); + clip_height = XtHeight(w); intended.request_mode = CWBorderWidth; intended.border_width = 0; if (w->viewport.forcebars) { - needsvert = w->viewport.allowvert; - needshoriz = w->viewport.allowhoriz; - ComputeWithForceBars(widget, query, &intended, + needsvert = w->viewport.allowvert; + needshoriz = w->viewport.allowhoriz; + ComputeWithForceBars(widget, query, &intended, &clip_width, &clip_height); } else { - Dimension prev_width, prev_height; + Dimension prev_width, prev_height; XtGeometryMask prev_mode; XtWidgetGeometry preferred; @@ -504,36 +551,34 @@ static void ComputeLayout(widget, query, destroy_scrollbars) /* * intended.{width,height} caches the eventual child dimensions, * but we don't set the mode bits until after we decide that the - * child's preferences are not acceptable. + * child's preferences are not acceptable */ - if (!w->viewport.allowhoriz) intended.request_mode |= CWWidth; - if ((int)child->core.width < clip_width) + if (XtWidth(child) < clip_width) intended.width = clip_width; else - intended.width = child->core.width; + intended.width = XtWidth(child); - if ((int)child->core.height < clip_height) + if (XtHeight(child) < clip_height) intended.height = clip_height; else - intended.height = child->core.height; + intended.height = XtHeight(child); if (!w->viewport.allowvert) intended.request_mode |= CWHeight; if (!query) { - preferred.width = child->core.width; - preferred.height = child->core.height; + preferred.width = XtWidth(child); + preferred.height = XtHeight(child); } do { /* while intended != prev */ - if (query) { - (void) XtQueryGeometry( child, &intended, &preferred ); - if ( !(preferred.request_mode & CWWidth) ) + (void)XtQueryGeometry(child, &intended, &preferred); + if (!(preferred.request_mode & CWWidth)) preferred.width = intended.width; - if ( !(preferred.request_mode & CWHeight) ) + if (!(preferred.request_mode & CWHeight)) preferred.height = intended.height; } prev_width = intended.width; @@ -542,44 +587,44 @@ static void ComputeLayout(widget, query, destroy_scrollbars) /* * note that having once decided to turn on either bar * we'll not change our mind until we're next resized, - * thus avoiding potential oscillations. + * thus avoiding potential oscillations */ -#define CheckHoriz() \ - if ( w->viewport.allowhoriz && \ - (int)preferred.width > clip_width) { \ - if (!needshoriz) { \ - Widget bar; \ - needshoriz = True; \ - if ((bar = w->viewport.horiz_bar) == (Widget)NULL) \ - bar = CreateScrollbar(w, True); \ - clip_height -= bar->core.height + \ - bar->core.border_width; \ - if (clip_height < 1) clip_height = 1; \ - } \ - intended.width = preferred.width; \ +#define CheckHoriz() \ + if (w->viewport.allowhoriz && \ + preferred.width > clip_width) { \ + if (!needshoriz) { \ + Widget bar; \ + \ + needshoriz = True; \ + if ((bar = w->viewport.horiz_bar) == NULL) \ + bar = CreateScrollbar(w, True); \ + clip_height -= XtHeight(bar) + XtBorderWidth(bar); \ + if (clip_height < 1) \ + clip_height = 1; \ + } \ + intended.width = preferred.width; \ } -/*enddef*/ + CheckHoriz(); - if (w->viewport.allowvert && (int)preferred.height > clip_height) { - if (!needsvert) { + if (w->viewport.allowvert && preferred.height > clip_height) { + if (!needsvert) { Widget bar; needsvert = True; - if ((bar = w->viewport.vert_bar) == (Widget)NULL) - bar = CreateScrollbar(w, False); - clip_width -= bar->core.width + bar->core.border_width; - if (clip_width < 1) clip_width = 1; + if ((bar = w->viewport.vert_bar) == NULL) + bar = CreateScrollbar(w, False); + clip_width -= XtWidth(bar) + XtBorderWidth(bar); + if (clip_width < 1) + clip_width = 1; CheckHoriz(); } intended.height = preferred.height; } - if ( !w->viewport.allowhoriz || - (int)preferred.width < clip_width) { - intended.width = clip_width; + if (!w->viewport.allowhoriz || preferred.width < clip_width) { + intended.width = clip_width; intended.request_mode |= CWWidth; } - if ( !w->viewport.allowvert || - (int)preferred.height < clip_height) { - intended.height = clip_height; + if (!w->viewport.allowvert || preferred.height < clip_height) { + intended.height = clip_height; intended.request_mode |= CWHeight; } } while (intended.request_mode != prev_mode @@ -590,152 +635,150 @@ static void ComputeLayout(widget, query, destroy_scrollbars) } if (XtIsRealized(clip)) - XRaiseWindow( XtDisplay(clip), XtWindow(clip) ); - - XtMoveWidget( clip, - (Position) (needsvert ? (w->viewport.useright ? 0 : - w->viewport.vert_bar->core.width + - w->viewport.vert_bar->core.border_width) : 0), - (Position) (needshoriz ? (w->viewport.usebottom ? 0 : - w->viewport.horiz_bar->core.height + - w->viewport.horiz_bar->core.border_width) : 0)); - XtResizeWidget( clip, (Dimension)clip_width, - (Dimension)clip_height, (Dimension)0 ); + XRaiseWindow(XtDisplay(clip), XtWindow(clip)); + + XtMoveWidget(clip, + needsvert ? w->viewport.useright ? 0 : + XtWidth(w->viewport.vert_bar) + + XtBorderWidth(w->viewport.vert_bar) : 0, + needshoriz ? w->viewport.usebottom ? 0 : + XtHeight(w->viewport.horiz_bar) + + XtBorderWidth(w->viewport.horiz_bar) : 0); + XtResizeWidget(clip, clip_width, clip_height, 0); - if (w->viewport.horiz_bar != (Widget)NULL) { + if (w->viewport.horiz_bar != NULL) { Widget bar = w->viewport.horiz_bar; + if (!needshoriz) { - constraints->form.vert_base = (Widget)NULL; + constraints->form.vert_base = NULL; if (destroy_scrollbars) { - XtDestroyWidget( bar ); - w->viewport.horiz_bar = (Widget)NULL; + XtDestroyWidget(bar); + w->viewport.horiz_bar = NULL; } } else { - int bw = bar->core.border_width; - XtResizeWidget( bar, (Dimension) clip_width, bar->core.height, (Dimension) bw ); - XtMoveWidget( bar, - (Position)((needsvert && !w->viewport.useright) - ? w->viewport.vert_bar->core.width - : -bw), - (Position)(w->viewport.usebottom - ? w->core.height - bar->core.height - bw - : -bw) ); - XtSetMappedWhenManaged( bar, True ); + int bw = XtBorderWidth(bar); + + XtResizeWidget(bar, clip_width, XtHeight(bar), bw); + XtMoveWidget(bar, + needsvert && !w->viewport.useright + ? XtWidth(w->viewport.vert_bar) : -bw, + w->viewport.usebottom + ? XtHeight(w) - XtHeight(bar) - bw : -bw); + XtSetMappedWhenManaged(bar, True); } } - if (w->viewport.vert_bar != (Widget)NULL) { + if (w->viewport.vert_bar != NULL) { Widget bar = w->viewport.vert_bar; - if (!needsvert) { - constraints->form.horiz_base = (Widget)NULL; + + if (!needsvert) { + constraints->form.horiz_base = NULL; if (destroy_scrollbars) { - XtDestroyWidget( bar ); - w->viewport.vert_bar = (Widget)NULL; + XtDestroyWidget(bar); + w->viewport.vert_bar = NULL; } } else { int bw = bar->core.border_width; - XtResizeWidget( bar, bar->core.width, (Dimension)clip_height, (Dimension)bw ); - XtMoveWidget( bar, - (Position)(w->viewport.useright - ? w->core.width - bar->core.width - bw - : -bw), - (Position)((needshoriz && !w->viewport.usebottom) - ? w->viewport.horiz_bar->core.height - : -bw) ); - XtSetMappedWhenManaged( bar, True ); + + XtResizeWidget(bar, XtWidth(bar), clip_height, bw); + XtMoveWidget(bar, + w->viewport.useright + ? XtWidth(w) - XtWidth(bar) - bw : -bw, + needshoriz && !w->viewport.usebottom + ? XtHeight(w->viewport.horiz_bar) : -bw); + XtSetMappedWhenManaged(bar, True); } } - if (child != (Widget)NULL) { - XtResizeWidget( child, (Dimension)intended.width, - (Dimension)intended.height, (Dimension)0 ); - MoveChild(w, - needshoriz ? child->core.x : 0, - needsvert ? child->core.y : 0); + if (child != NULL) { + XtResizeWidget(child, intended.width, intended.height, 0); + MoveChild(w, needshoriz ? XtX(child) : 0, needsvert ? XtY(child) : 0); } SendReport (w, XawPRAll); } -/* Function Name: ComputeWithForceBars - * Description: Computes the layout give forcebars is set. - * Arguments: widget - the viewport widget. - * query - whether or not to query the child. - * intended - the cache of the childs height is - * stored here ( USED AND RETURNED ). - * clip_width, clip_height - size of clip window. - * (USED AND RETURNED ). - * Returns: none. +/* + * Function: + * ComputeWithForceBars + * + * Parameters: + * widget - viewport widget + * query - whether or not to query the child + * intended - cache of the childs height is stored here + * (used and returned) + * clip_width - size of clip window (used and returned) + * clip_height - "" + * + * Description: + * Computes the layout give forcebars is set. */ - static void -ComputeWithForceBars(widget, query, intended, clip_width, clip_height) -Widget widget; -Boolean query; -XtWidgetGeometry * intended; -int *clip_width, *clip_height; +ComputeWithForceBars(Widget widget, Bool query, XtWidgetGeometry *intended, + int *clip_width, int *clip_height) { ViewportWidget w = (ViewportWidget)widget; Widget child = w->viewport.child; XtWidgetGeometry preferred; -/* - * If forcebars then needs = allows = has. - * Thus if needsvert is set it MUST have a scrollbar. - */ - + /* + * If forcebars then needs = allows = has + * Thus if needsvert is set it MUST have a scrollbar + */ if (w->viewport.allowvert) { if (w->viewport.vert_bar == NULL) w->viewport.vert_bar = CreateScrollbar(w, False); - *clip_width -= w->viewport.vert_bar->core.width + - w->viewport.vert_bar->core.border_width; + *clip_width -= XtWidth(w->viewport.vert_bar) + + XtBorderWidth(w->viewport.vert_bar); } if (w->viewport.allowhoriz) { if (w->viewport.horiz_bar == NULL) w->viewport.horiz_bar = CreateScrollbar(w, True); - *clip_height -= w->viewport.horiz_bar->core.height + - w->viewport.horiz_bar->core.border_width; + *clip_height -= XtHeight(w->viewport.horiz_bar) + + XtBorderWidth(w->viewport.horiz_bar); } - AssignMax( *clip_width, 1 ); - AssignMax( *clip_height, 1 ); + AssignMax(*clip_width, 1); + AssignMax(*clip_height, 1); if (!w->viewport.allowvert) { - intended->height = *clip_height; - intended->request_mode = CWHeight; + intended->height = *clip_height; + intended->request_mode = CWHeight; } if (!w->viewport.allowhoriz) { - intended->width = *clip_width; - intended->request_mode = CWWidth; + intended->width = *clip_width; + intended->request_mode = CWWidth; } - if ( query ) { - if ( (w->viewport.allowvert || w->viewport.allowhoriz) ) { - XtQueryGeometry( child, intended, &preferred ); + if (query) { + if (w->viewport.allowvert || w->viewport.allowhoriz) { + XtQueryGeometry(child, intended, &preferred); - if ( !(intended->request_mode & CWWidth) ) - if ( preferred.request_mode & CWWidth ) + if (!(intended->request_mode & CWWidth)) { + if (preferred.request_mode & CWWidth) intended->width = preferred.width; else - intended->width = child->core.width; + intended->width = XtWidth(child); + } - if ( !(intended->request_mode & CWHeight) ) - if ( preferred.request_mode & CWHeight ) + if (!(intended->request_mode & CWHeight)) { + if (preferred.request_mode & CWHeight) intended->height = preferred.height; else - intended->height = child->core.height; + intended->height = XtHeight(child); + } } } else { - if (w->viewport.allowvert) - intended->height = child->core.height; + if (w->viewport.allowvert) + intended->height = XtHeight(child); if (w->viewport.allowhoriz) - intended->width = child->core.width; + intended->width = XtWidth(child); } if (*clip_width > (int)intended->width) @@ -744,210 +787,192 @@ int *clip_width, *clip_height; intended->height = *clip_height; } -static void Resize(widget) - Widget widget; +static void +XawViewportResize(Widget widget) { - ComputeLayout( widget, /*query=*/True, /*destroy=*/True ); + ComputeLayout(widget, True, True); } - -/* ARGSUSED */ -static Boolean Layout(w, width, height) - FormWidget w; - Dimension width, height; +/*ARGSUSED*/ +static Boolean +Layout(FormWidget w, unsigned int width, unsigned int height, Bool force) { - ComputeLayout( (Widget)w, /*query=*/True, /*destroy=*/True ); - w->form.preferred_width = w->core.width; - w->form.preferred_height = w->core.height; - return False; -} + ComputeLayout((Widget)w, True, True); + w->form.preferred_width = XtWidth(w); + w->form.preferred_height = XtHeight(w); + return (False); +} -static void ScrollUpDownProc(widget, closure, call_data) - Widget widget; - XtPointer closure; - XtPointer call_data; +static void +ScrollUpDownProc(Widget widget, XtPointer closure, XtPointer call_data) { ViewportWidget w = (ViewportWidget)closure; Widget child = w->viewport.child; - int pix = (int)call_data; - Position x, y; + int pix = (long)call_data; + int x, y; - if (child == NULL) return; /* no child to scroll. */ + if (child == NULL) + return; - x = child->core.x - ((widget == w->viewport.horiz_bar) ? pix : 0); - y = child->core.y - ((widget == w->viewport.vert_bar) ? pix : 0); + x = XtX(child) - (widget == w->viewport.horiz_bar ? pix : 0); + y = XtY(child) - (widget == w->viewport.vert_bar ? pix : 0); MoveChild(w, x, y); } - -/* ARGSUSED */ -static void ThumbProc(widget, closure, call_data) - Widget widget; - XtPointer closure; - XtPointer call_data; +/*ARGSUSED*/ +static void +ThumbProc(Widget widget, XtPointer closure, XtPointer call_data) { ViewportWidget w = (ViewportWidget)closure; Widget child = w->viewport.child; - float *percent = (float *) call_data; - Position x, y; + float percent = *(float *)call_data; + int x, y; - if (child == NULL) return; /* no child to scroll. */ + if (child == NULL) + return; if (widget == w->viewport.horiz_bar) -#ifdef macII /* bug in the macII A/UX 1.0 cc */ - x = (int)(-*percent * child->core.width); -#else /* else not macII */ - x = -(int)(*percent * child->core.width); -#endif /* macII */ + x = -percent * XtWidth(child); else - x = child->core.x; + x = XtX(child); if (widget == w->viewport.vert_bar) -#ifdef macII /* bug in the macII A/UX 1.0 cc */ - y = (int)(-*percent * child->core.height); -#else /* else not macII */ - y = -(int)(*percent * child->core.height); -#endif /* macII */ + y = -percent * XtHeight(child); else - y = child->core.y; + y = XtY(child); MoveChild(w, x, y); } static XtGeometryResult -TestSmaller(w, request, reply_return) - ViewportWidget w; XtWidgetGeometry *request, *reply_return; +TestSmaller(ViewportWidget w, XtWidgetGeometry *request, + XtWidgetGeometry *reply_return) { - if (request->width < w->core.width || request->height < w->core.height) - return XtMakeGeometryRequest((Widget)w, request, reply_return); - else - return XtGeometryYes; + if (request->width < XtWidth(w) || request->height < XtHeight(w)) + return (XtMakeGeometryRequest((Widget)w, request, reply_return)); + + return (XtGeometryYes); } static XtGeometryResult -GeometryRequestPlusScrollbar(w, horizontal, request, reply_return) - Boolean horizontal; - ViewportWidget w; - XtWidgetGeometry *request, *reply_return; +GeometryRequestPlusScrollbar(ViewportWidget w, Bool horizontal, + XtWidgetGeometry *request, + XtWidgetGeometry *reply_return) { - Widget sb; - XtWidgetGeometry plusScrollbars; - plusScrollbars = *request; - if ((sb = w->viewport.horiz_bar) == (Widget)NULL) - sb = CreateScrollbar( w, horizontal); - request->width += sb->core.width; - request->height += sb->core.height; - XtDestroyWidget(sb); - return XtMakeGeometryRequest((Widget) w, &plusScrollbars, reply_return); - } - -#define WidthChange() (request->width != w->core.width) -#define HeightChange() (request->height != w->core.height) + Widget sb; + XtWidgetGeometry plusScrollbars; + + plusScrollbars = *request; + if ((sb = w->viewport.horiz_bar) == NULL) + sb = CreateScrollbar(w, horizontal); + request->width += XtWidth(sb); + request->height += XtHeight(sb); + XtDestroyWidget(sb); + return (XtMakeGeometryRequest((Widget)w, &plusScrollbars, reply_return)); +} +#define WidthChange() (request->width != XtWidth(w)) +#define HeightChange() (request->height != XtHeight(w)) static XtGeometryResult -QueryGeometry(w, request, reply_return) - ViewportWidget w; XtWidgetGeometry *request, *reply_return; +QueryGeometry(ViewportWidget w, XtWidgetGeometry *request, + XtWidgetGeometry *reply_return) { - if (w->viewport.allowhoriz && w->viewport.allowvert) - return TestSmaller(w, request, reply_return); - - else if (w->viewport.allowhoriz && !w->viewport.allowvert) { - if (WidthChange() && !HeightChange()) - return TestSmaller(w, request, reply_return); - else if (!WidthChange() && HeightChange()) - return XtMakeGeometryRequest((Widget) w, request, reply_return); - else if (WidthChange() && HeightChange()) /* hard part */ - return GeometryRequestPlusScrollbar(w, True, request, reply_return); - else /* !WidthChange() && !HeightChange() */ - return XtGeometryYes; - } - else if (!w->viewport.allowhoriz && w->viewport.allowvert) { - if (!WidthChange() && HeightChange()) - return TestSmaller(w, request, reply_return); - else if (WidthChange() && !HeightChange()) - return XtMakeGeometryRequest((Widget)w, request, reply_return); - else if (WidthChange() && HeightChange()) /* hard part */ - return GeometryRequestPlusScrollbar(w, False, request, reply_return); - else /* !WidthChange() && !HeightChange() */ - return XtGeometryYes; - } - else /* (!w->viewport.allowhoriz && !w->viewport.allowvert) */ - return XtMakeGeometryRequest((Widget) w, request, reply_return); + if (w->viewport.allowhoriz && w->viewport.allowvert) + return (TestSmaller(w, request, reply_return)); + + else if (w->viewport.allowhoriz && !w->viewport.allowvert) { + if (WidthChange() && !HeightChange()) + return (TestSmaller(w, request, reply_return)); + else if (!WidthChange() && HeightChange()) + return (XtMakeGeometryRequest((Widget)w, request, reply_return)); + else if (WidthChange() && HeightChange()) + return (GeometryRequestPlusScrollbar(w, True, request, reply_return)); + else /* !WidthChange() && !HeightChange() */ + return (XtGeometryYes); + } + else if (!w->viewport.allowhoriz && w->viewport.allowvert) { + if (!WidthChange() && HeightChange()) + return (TestSmaller(w, request, reply_return)); + else if (WidthChange() && !HeightChange()) + return (XtMakeGeometryRequest((Widget)w, request, reply_return)); + else if (WidthChange() && HeightChange()) + return (GeometryRequestPlusScrollbar(w, False, request, reply_return)); + else /* !WidthChange() && !HeightChange() */ + return (XtGeometryYes); + } + else /* (!w->viewport.allowhoriz && !w->viewport.allowvert) */ + return (XtMakeGeometryRequest((Widget)w, request, reply_return)); } - #undef WidthChange #undef HeightChange -static XtGeometryResult GeometryManager(child, request, reply) - Widget child; - XtWidgetGeometry *request, *reply; +static XtGeometryResult +XawViewportGeometryManager(Widget child, XtWidgetGeometry *request, + XtWidgetGeometry *reply) { ViewportWidget w = (ViewportWidget)child->core.parent; - Boolean rWidth = (Boolean)(request->request_mode & CWWidth); - Boolean rHeight = (Boolean)(request->request_mode & CWHeight); + Bool rWidth = (request->request_mode & CWWidth) != 0; + Bool rHeight = (request->request_mode & CWHeight) != 0; XtWidgetGeometry allowed; XtGeometryResult result; - Boolean reconfigured; - Boolean child_changed_size; - Dimension height_remaining; + Bool reconfigured; + Bool child_changed_size; + unsigned int height_remaining; if (request->request_mode & XtCWQueryOnly) - return QueryGeometry(w, request, reply); + return (QueryGeometry(w, request, reply)); if (child != w->viewport.child - || request->request_mode & ~(CWWidth | CWHeight - | CWBorderWidth) + || request->request_mode & ~(CWWidth | CWHeight | CWBorderWidth) || ((request->request_mode & CWBorderWidth) && request->border_width > 0)) - return XtGeometryNo; + return (XtGeometryNo); allowed = *request; - reconfigured = GetGeometry( (Widget)w, - (rWidth ? request->width : w->core.width), - (rHeight ? request->height : w->core.height) - ); + reconfigured = GetGeometry((Widget)w, + rWidth ? request->width : XtWidth(w), + rHeight ? request->height : XtHeight(w)); - child_changed_size = ((rWidth && child->core.width != request->width) || - (rHeight && child->core.height != request->height)); + child_changed_size = (rWidth && XtWidth(child) != request->width) || + (rHeight && XtHeight(child) != request->height); - height_remaining = w->core.height; - if (rWidth && w->core.width != request->width) { - if (w->viewport.allowhoriz && request->width > w->core.width) { + height_remaining = XtHeight(w); + if (rWidth && XtWidth(w) != request->width) { + if (w->viewport.allowhoriz && request->width > XtWidth(w)) { /* horizontal scrollbar will be needed so possibly reduce height */ Widget bar; - if ((bar = w->viewport.horiz_bar) == (Widget)NULL) - bar = CreateScrollbar( w, True ); - height_remaining -= bar->core.height + bar->core.border_width; + + if ((bar = w->viewport.horiz_bar) == NULL) + bar = CreateScrollbar(w, True); + height_remaining -= XtHeight(bar) + XtBorderWidth(bar); reconfigured = True; } - else { - allowed.width = w->core.width; - } + else + allowed.width = XtWidth(w); } if (rHeight && height_remaining != request->height) { if (w->viewport.allowvert && request->height > height_remaining) { /* vertical scrollbar will be needed, so possibly reduce width */ - if (!w->viewport.allowhoriz || request->width < w->core.width) { + if (!w->viewport.allowhoriz || request->width < XtWidth(w)) { Widget bar; - if ((bar = w->viewport.vert_bar) == (Widget)NULL) - bar = CreateScrollbar( w, False ); + + if ((bar = w->viewport.vert_bar) == NULL) + bar = CreateScrollbar(w, False); if (!rWidth) { - allowed.width = w->core.width; + allowed.width = XtWidth(w); allowed.request_mode |= CWWidth; } - if ( (int)allowed.width > - (int)(bar->core.width + bar->core.border_width) ) - allowed.width -= bar->core.width + bar->core.border_width; + if (allowed.width > XtWidth(bar) + XtBorderWidth(bar)) + allowed.width -= XtWidth(bar) + XtBorderWidth(bar); else allowed.width = 1; reconfigured = True; } } - else { + else allowed.height = height_remaining; - } } if (allowed.width != request->width || allowed.height != request->height) { @@ -955,129 +980,120 @@ static XtGeometryResult GeometryManager(child, request, reply) result = XtGeometryAlmost; } else { - if (rWidth) child->core.width = request->width; - if (rHeight) child->core.height = request->height; + if (rWidth) + XtWidth(child) = request->width; + if (rHeight) + XtHeight(child) = request->height; result = XtGeometryYes; } if (reconfigured || child_changed_size) - ComputeLayout( (Widget)w, - /*query=*/ False, - /*destroy=*/ (result == XtGeometryYes) ? True : False ); - - return result; - } + ComputeLayout((Widget)w, False, result == XtGeometryYes); + return (result); +} -static Boolean GetGeometry(w, width, height) - Widget w; - Dimension width, height; +static Bool +GetGeometry(Widget w, unsigned int width, unsigned int height) { XtWidgetGeometry geometry, return_geom; XtGeometryResult result; - if (width == w->core.width && height == w->core.height) - return False; + if (width == XtWidth(w) && height == XtHeight(w)) + return (False); geometry.request_mode = CWWidth | CWHeight; geometry.width = width; geometry.height = height; if (XtIsRealized(w)) { - if (((ViewportWidget)w)->viewport.allowhoriz && width > w->core.width) - geometry.width = w->core.width; - if (((ViewportWidget)w)->viewport.allowvert && height > w->core.height) - geometry.height = w->core.height; - } else { + if (((ViewportWidget)w)->viewport.allowhoriz && width > XtWidth(w)) + geometry.width = XtWidth(w); + if (((ViewportWidget)w)->viewport.allowvert && height > XtHeight(w)) + geometry.height = XtHeight(w); + } + else { /* This is the Realize call; we'll inherit a w&h iff none currently */ - if (w->core.width != 0) { - if (w->core.height != 0) return False; - geometry.width = w->core.width; + if (XtWidth(w) != 0) { + if (XtHeight(w) != 0) + return (False); + geometry.width = XtWidth(w); } - if (w->core.height != 0) geometry.height = w->core.height; + if (XtHeight(w) != 0) + geometry.height = XtHeight(w); } result = XtMakeGeometryRequest(w, &geometry, &return_geom); if (result == XtGeometryAlmost) - result = XtMakeGeometryRequest(w, &return_geom, (XtWidgetGeometry *)NULL); + result = XtMakeGeometryRequest(w, &return_geom, NULL); return (result == XtGeometryYes); } -static XtGeometryResult PreferredGeometry(w, constraints, reply) - Widget w; - XtWidgetGeometry *constraints, *reply; +static XtGeometryResult +XawViewportQueryGeometry(Widget w, XtWidgetGeometry *constraints, + XtWidgetGeometry *reply) { if (((ViewportWidget)w)->viewport.child != NULL) - return XtQueryGeometry( ((ViewportWidget)w)->viewport.child, - constraints, reply ); - else - return XtGeometryYes; -} + return (XtQueryGeometry(((ViewportWidget)w)->viewport.child, + constraints, reply)); + return (XtGeometryYes); +} void -#if NeedFunctionPrototypes -XawViewportSetLocation (Widget gw, +XawViewportSetLocation +( + Widget gw, #if NeedWidePrototypes - double xoff, double yoff) -#else - float xoff, float yoff) -#endif + double xoff, double yoff #else -XawViewportSetLocation (gw, xoff, yoff) - Widget gw; - float xoff,yoff; + float xoff, float yoff #endif + ) { - ViewportWidget w = (ViewportWidget) gw; + ViewportWidget w = (ViewportWidget)gw; Widget child = w->viewport.child; - Position x, y; + int x, y; if (xoff > 1.0) /* scroll to right */ - x = child->core.width; + x = XtWidth(child); else if (xoff < 0.0) /* if the offset is < 0.0 nothing */ - x = child->core.x; + x = XtX(child); else - x = (Position) (((float) child->core.width) * xoff); + x = (float)XtWidth(child) * xoff; if (yoff > 1.0) - y = child->core.height; + y = XtHeight(child); else if (yoff < 0.0) - y = child->core.y; + y = XtY(child); else - y = (Position) (((float) child->core.height) * yoff); + y = (float)XtHeight(child) * yoff; MoveChild (w, -x, -y); } void -#if NeedFunctionPrototypes -XawViewportSetCoordinates (Widget gw, +XawViewportSetCoordinates(Widget gw, #if NeedWidePrototypes - int x, int y) + int x, int y #else - Position x, Position y) -#endif -#else -XawViewportSetCoordinates (gw, x, y) - Widget gw; - Position x, y; + Position x, Position y #endif +) { - ViewportWidget w = (ViewportWidget) gw; + ViewportWidget w = (ViewportWidget)gw; Widget child = w->viewport.child; - if (x > (int)child->core.width) - x = child->core.width; + if (x > XtWidth(child)) + x = XtWidth(child); else if (x < 0) - x = child->core.x; + x = XtX(child); - if (y > (int)child->core.height) - y = child->core.height; + if (y > XtHeight(child)) + y = XtHeight(child); else if (y < 0) - y = child->core.y; + y = XtY(child); MoveChild (w, -x, -y); } - |