/*----------------------------------------------------------------------*/ /* extern */ int XfeChildGetIndex(Widget w) { Widget parent = XtParent(w); assert( _XfeIsAlive(w) ); parent = XtParent(w); assert( _XfeIsAlive(parent) ); if (_XfemNumChildren(parent) && _XfemChildren(parent)) { Cardinal i = 0; for (i = 0; i < _XfemNumChildren(parent); i++) { if (_XfemChildren(parent)[i] == w) { return i; } } } return -1; }
/*----------------------------------------------------------------------*/ /* extern */ Widget XfeChildrenGetLast(Widget w) { assert( _XfeIsAlive(w) ); assert( XtIsComposite(w) ); if (_XfemChildren(w) && _XfemNumChildren(w)) { return _XfemChildren(w)[ _XfemNumChildren(w) - 1 ]; } return NULL; }
/*----------------------------------------------------------------------*/ /* extern */ Widget XfeMenuItemPreviousItem(Widget item) { int position_index; Widget parent; Cardinal num_children; Widget previous = NULL; assert( _XfeIsAlive(item) ); assert( XtIsObject(item) ); parent = _XfeParent(item); assert( XmIsRowColumn(_XfeParent(item)) ); position_index = XfeMenuItemPositionIndex(item); num_children = _XfemNumChildren(parent); if (position_index > 0) { previous = _XfeChildrenIndex(parent,position_index - 1); } return previous; }
/*----------------------------------------------------------------------*/ /* extern */ Widget XfeMenuItemNextItem(Widget item) { int position_index; Widget parent; Cardinal num_children; Widget next = NULL; assert( _XfeIsAlive(item) ); assert( XtIsObject(item) ); parent = _XfeParent(item); assert( XmIsRowColumn(_XfeParent(item)) ); position_index = XfeMenuItemPositionIndex(item); num_children = _XfemNumChildren(parent); if (position_index < (num_children - 1)) { next = _XfeChildrenIndex(parent,position_index + 1); } return next; }
/*----------------------------------------------------------------------*/ /* extern */ Cardinal XfeNumChildren(Widget w) { assert( XtIsComposite(w) ); return _XfemNumChildren(w); }
/*----------------------------------------------------------------------*/ /* extern */ void XfeChildrenDestroy(Widget w) { Widget * children; Cardinal i; assert( _XfeIsAlive(w) ); assert( XtIsComposite(w) ); /* Make sure the widget has children */ if (!_XfemNumChildren(w)) { return; } /* Allocate space for a temporary children array */ children = (Widget *) XtMalloc(sizeof(Widget) * _XfemNumChildren(w)); /* Copy the widget ids */ for (i = 0; i < _XfemNumChildren(w); i++) { children[i] = _XfemChildren(w)[i]; } /* Destroy the children */ for (i = 0; i < _XfemNumChildren(w); i++) { if (_XfeIsAlive(children[i])) { XtDestroyWidget(children[i]); } } XtFree((char *) children); /* Update an flush in case the destruction takes a long time */ XmUpdateDisplay(w); XFlush(XtDisplay(w)); }
/*----------------------------------------------------------------------*/ static void AccentBottom(Widget w, GC top_gc, GC bottom_gc, Dimension offset_left, Dimension offset_right, Dimension shadow_thickness, Dimension accent_thickness, int code) { Widget pw = _XfeParent(w); int position_index = XfeMenuItemPositionIndex(w); Cardinal num_children = _XfemNumChildren(pw); Position x; Position y; Dimension width; Dimension height = 2 * shadow_thickness + accent_thickness; assert( code == ACCENT_DRAW || code == ACCENT_ERASE ); /* Last item */ if (position_index == (num_children - 1)) { x = _XfeX(w) + offset_left; y = _XfeY(w) + _XfeHeight(w) - height; width = _XfeWidth(w) - offset_left - offset_right; } /* Any other item */ else { x = _XfeX(w) + offset_left; y = _XfeY(w) + _XfeHeight(w) - height / 2; width = _XfeWidth(w) - offset_left - offset_right; } if (code == ACCENT_DRAW) { /* Draw accent */ _XmDrawShadows(XtDisplay(pw),_XfeWindow(pw),top_gc,bottom_gc, x,y,width,height,shadow_thickness,XmSHADOW_IN); } else { /* Erase accent */ XfeDrawRectangle(XtDisplay(pw),_XfeWindow(pw),top_gc, x,y,width,height,shadow_thickness); } }
/*----------------------------------------------------------------------*/ /* extern */ void XfeChildrenGet(Widget w,WidgetList * children,Cardinal * num_children) { assert( _XfeIsAlive(w) ); assert( XtIsComposite(w) ); assert( (children != NULL) || (num_children != NULL) ); if (children) { *children = _XfemChildren(w); } if (num_children) { *num_children = _XfemNumChildren(w); } }
/*----------------------------------------------------------------------*/ /* extern */ void XfeOptionMenuSetItem(Widget menu,Cardinal i) { Widget submenu; assert( _XfeIsAlive(menu) ); assert( XfeMenuIsOptionMenu(menu) ); submenu = RC_OptionSubMenu(menu); if (_XfeIsAlive(submenu)) { if ((i >= 0) && (i < _XfemNumChildren(submenu))) { XtVaSetValues(menu,XmNmenuHistory,_XfeChildrenIndex(submenu,i),NULL); } } }
/*----------------------------------------------------------------------*/ /* extern */ Cardinal XfeChildrenCountAlive(Widget w) { Cardinal num_alive = 0; Cardinal i; assert( w != NULL ); for (i = 0; i < _XfemNumChildren(w); i ++) { if (_XfeIsAlive(_XfeChildrenIndex(w,i))) { num_alive++; } } return num_alive; }
/*----------------------------------------------------------------------*/ /* extern */ Cardinal XfeChildrenGetNumManaged(Widget w) { Cardinal i; Cardinal num_managed = 0; assert( _XfeIsAlive(w) ); assert( XtIsComposite(w) ); for (i = 0; i < _XfemNumChildren(w); i++) { if (_XfeIsManaged(_XfeChildrenIndex(w,i))) { num_managed++; } } return num_managed; }
/*----------------------------------------------------------------------*/ /* extern */ int XfeOptionMenuGetItem(Widget menu) { Cardinal i; Widget submenu; assert( _XfeIsAlive(menu) ); assert( XfeMenuIsOptionMenu(menu) ); submenu = RC_OptionSubMenu(menu); if (_XfeIsAlive(submenu)) { for (i = 0; i < _XfemNumChildren(submenu); i++) { if (_XfeChildrenIndex(submenu,i) == RC_MemWidget(menu)) { return (int) i; } } } return -1; }
/*----------------------------------------------------------------------*/ static void AccentAll(Widget w, GC top_gc, GC bottom_gc, Dimension offset_left, Dimension offset_right, Dimension shadow_thickness, Dimension accent_thickness, int code) { #if 1 if (code == ACCENT_DRAW) { /* Draw accent */ _XmDrawShadows(XtDisplay(w),_XfeWindow(w), top_gc,bottom_gc, _XfeHighlightThickness(w), _XfeHighlightThickness(w), _XfeWidth(w) - 2 * _XfeHighlightThickness(w), _XfeHeight(w) - 2 * _XfeHighlightThickness(w), _XfeShadowThickness(w), XmSHADOW_OUT); } else { /* Erase accent */ XfeDrawRectangle(XtDisplay(w),_XfeWindow(w),top_gc, _XfeHighlightThickness(w), _XfeHighlightThickness(w), _XfeWidth(w) - 2 * _XfeHighlightThickness(w), _XfeHeight(w) - 2 * _XfeHighlightThickness(w), _XfeShadowThickness(w)); } #else Widget pw = _XfeParent(w); int position_index = XfeMenuItemPositionIndex(w); Cardinal num_children = _XfemNumChildren(pw); Position x; Position y; Dimension width; Dimension height; Dimension total_thickness = shadow_thickness + accent_thickness; assert( code == ACCENT_DRAW || code == ACCENT_ERASE ); /* One and only */ if (num_children == 1) { x = _XfeX(w) + offset_left; y = _XfeY(w); width = _XfeWidth(w) - offset_left - offset_right; height = _XfeHeight(w); } else { Dimension overlap = (2 * shadow_thickness + accent_thickness) / 2; /* First item */ if (position_index == 0) { x = _XfeX(w) + offset_left; y = _XfeY(w); width = _XfeWidth(w) - offset_left - offset_right; height = _XfeHeight(w) + overlap; } /* Last item */ else if (position_index == (num_children - 1)) { x = _XfeX(w) + offset_left; y = _XfeY(w) - overlap; width = _XfeWidth(w) - offset_left - offset_right; height = _XfeHeight(w) + overlap; } /* In between two others */ else { x = _XfeX(w) + offset_left; y = _XfeY(w) - overlap; width = _XfeWidth(w) - offset_left - offset_right; height = _XfeHeight(w) + 2 * total_thickness; } } if (code == ACCENT_DRAW) { /* Draw accent */ _XmDrawShadows(XtDisplay(pw),_XfeWindow(pw),top_gc,bottom_gc, x,y,width,height,shadow_thickness,XmSHADOW_IN); x += total_thickness; y += total_thickness; width -= (2 * total_thickness); height -= (2 * total_thickness); _XmDrawShadows(XtDisplay(pw),_XfeWindow(pw),top_gc,bottom_gc, x,y,width,height,shadow_thickness,XmSHADOW_OUT); } else { /* Erase accent */ XfeDrawRectangle(XtDisplay(pw),_XfeWindow(pw),top_gc, x,y,width,height,shadow_thickness); x += total_thickness; y += total_thickness; width -= (2 * total_thickness); height -= (2 * total_thickness); XfeDrawRectangle(XtDisplay(pw),_XfeWindow(pw),top_gc, x,y,width,height,shadow_thickness); } #endif }