/*----------------------------------------------------------------------*/ /* extern */ void XfeChildrenRemoveEventHandler(Widget w, EventMask event_mask, Boolean nonmaskable, XtEventHandler proc, XtPointer data) { Widget * children; Cardinal num_children; Cardinal i; assert( _XfeIsAlive(w) ); assert( XtIsComposite(w) ); XfeChildrenGet(w,&children,&num_children); for (i = 0; i < num_children; i++) { if (_XfeIsAlive(w)) { XtRemoveEventHandler(children[i],event_mask,nonmaskable,proc,data); } XtRemoveEventHandler(children[i],event_mask,nonmaskable,proc,data); } }
/*----------------------------------------------------------------------*/ static Widget ShellCreate(Widget w) { Widget shell = NULL; Widget frame_shell; /* Look for a XfeFrameShell ancestor */ frame_shell = XfeAncestorFindByClass(w, xfeFrameShellWidgetClass, XfeFIND_ANY); /* If found, use it */ if (_XfeIsAlive(frame_shell)) { shell = XfeFrameShellGetBypassShell(frame_shell); } else { shell = XfeCreateBypassShell(w,SHELL_NAME,NULL,0); XtRealizeWidget(shell); } assert( _XfeIsAlive(shell) ); if (!_XfeIsRealized(shell)) { XtRealizeWidget(shell); } return shell; }
/*----------------------------------------------------------------------*/ /* extern */ void _XfeConfigureOrHideWidget(Widget w,int x,int y,int width,int height) { assert( _XfeIsAlive(w) ); /* Make sure the widget is alive */ if (!_XfeIsAlive(w)) { return; } /* Make sure the positions and dimensions are different */ if ((_XfeX(w) == x) && (_XfeY(w) == y) && (_XfeWidth(w) == width) && (_XfeHeight(w) == height)) { return; } /* Hide the widget if its dimensions are less thanb zero */ if (!width || !height) { _XfeSetMappedWhenManaged(w,False); return; } _XfeConfigureWidget(w,x,y,width,height); /* Show the widget */ _XfeSetMappedWhenManaged(w,True); }
/*----------------------------------------------------------------------*/ /* extern */ Widget XfeMenuFindLastMoreMenu(Widget menu,String more_button_name) { Widget more_button; Widget submenu; assert( _XfeIsAlive(menu) ); assert( XmIsRowColumn(menu) ); assert( more_button_name != NULL ); /* First check if this menu is not full */ if (!XfeMenuIsFull(menu)) { return menu; } /* Look for the "More..." button */ more_button = XfeMenuGetMoreButton(menu,more_button_name); /* If no more button is found, then this menu is the last one */ if (!more_button) { return menu; } /* Get the submenu for the more button */ submenu = XfeCascadeGetSubMenu(more_button); assert( _XfeIsAlive(submenu) ); /* Recurse into the submenu */ return XfeMenuFindLastMoreMenu(submenu,more_button_name); }
/*----------------------------------------------------------------------*/ /* extern */ void XfeDrawShadowsAroundWidget(Widget parent, Widget child, GC top_gc, GC bottom_gc, Dimension offset, Dimension shadow_thickness, unsigned char shadow_type) { assert( _XfeIsAlive(parent) ); assert( _XfeIsAlive(child) ); assert( shadow_thickness > 0 ); assert( XmIsManager(parent) ); _XmDrawShadows(XtDisplay(parent), _XfeWindow(parent), _XfemTopShadowGC(parent), _XfemBottomShadowGC(parent), _XfeX(child) - shadow_thickness - offset, _XfeY(child) - shadow_thickness - offset, _XfeWidth(child) + 2 * shadow_thickness + 2 * offset, _XfeHeight(child) + 2 * shadow_thickness + 2 * offset, shadow_thickness, shadow_type); }
/*----------------------------------------------------------------------*/ static void ListManage(Widget w) { XfeComboBoxPart * cp = _XfeComboBoxPart(w); assert( _XfeIsAlive(cp->shell) ); assert( _XfeIsAlive(cp->list) ); printf("ListManage(%s)\n",XtName(w)); /* cp->remain_popped_up = True; */ /* popped up */ cp->popped_up = True; /* Manage the scrolled window */ XtManageChild(_XfeParent(cp->list)); ShellPopup(w); #if 0 XmUpdateDisplay(w); XFlush(XtDisplay(w)); #endif /* _XmPopupSpringLoaded(w); */ }
/*----------------------------------------------------------------------*/ /* 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 */ Position XfeY(Widget w) { assert( _XfeIsAlive(w) ); if (!_XfeIsAlive(w)) { return 0; } return _XfeY(w); }
/*----------------------------------------------------------------------*/ /* extern */ Dimension XfeScreenWidth(Widget w) { assert( _XfeIsAlive(w) ); if (!_XfeIsAlive(w)) { return 0; } return DisplayWidth(XtDisplay(w),XScreenNumberOfScreen(_XfeScreen(w))); }
/*----------------------------------------------------------------------*/ /* extern */ Dimension _XfeWidthCenter(Widget one,Widget two) { assert( one != NULL ); assert( _XfeIsAlive(one) ); assert( two != NULL ); assert( _XfeIsAlive(two) ); return (_XfeWidth(one) > _XfeWidth(two)) ? ((_XfeWidth(one) - _XfeWidth(two)) / 2) : 0; }
/*----------------------------------------------------------------------*/ /* extern */ Position XfeRootY(Widget w) { Position root_y; assert( _XfeIsAlive(w) ); if (!_XfeIsAlive(w)) { return 0; } XtTranslateCoords(w,0,0,NULL,&root_y); return root_y; }
/*----------------------------------------------------------------------*/ /* extern */ void _XfeBmActionWithoutDrawing(Widget w, XtActionProc proc, XEvent * event, char ** params, Cardinal * nparams) { Widget shell; Window window; assert( _XfeIsAlive(w) ); assert( proc != NULL ); shell = XfeAncestorFindByClass(w,shellWidgetClass,XfeFIND_ANY); window = _XfeWindow(w); /* * We change the width to 0, so that the real Enter() * action does not draw anything in the cascade button so that * we can draw the accent lines. */ _XfeWindow(w) = _XfeWindow(shell); (*proc)(w,event,params,nparams); _XfeWindow(w) = window; }
/*----------------------------------------------------------------------*/ /* extern */ void XfeShellSetIconicState(Widget shell,Boolean state) { /* Because of weirdness in Xt/Shell.c, one can't change the "iconic" flag of a shell after it has been created but before it has been realized. That resource is only checked when the shell is Initialized (ie, when XtCreatePopupShell is called) instead of the more obvious times like: when it is Realized (before the window is created) or when it is Managed (before window is mapped). The Shell class's SetValues method does not modify wm_hints.initial_state if the widget has not yet been realized - it ignores the request until afterward, when it's too late. */ assert( XtIsWMShell(shell) ); if (_XfeIsAlive(shell)) { WMShellWidget wms = (WMShellWidget) shell; XtVaSetValues(shell,XtNiconic,state,NULL); wms->wm.wm_hints.flags |= StateHint; wms->wm.wm_hints.initial_state = (state ? IconicState : NormalState); } }
/*----------------------------------------------------------------------*/ /* extern */ void _XfeBmProcWithoutDrawing(Widget w,XtWidgetProc proc) { Widget shell; Window window; assert( _XfeIsAlive(w) ); assert( proc != NULL ); /* * We pretend that the closest shell's window is the button's. This is * a hack so that the widget procedure 'proc' does not draw anything. */ shell = XfeAncestorFindByClass(w,shellWidgetClass,XfeFIND_ANY); window = _XfeWindow(w); /* * We change the width to 0, so that the real Enter() * action does not draw anything in the cascade button so that * we can draw the accent lines. */ _XfeWindow(w) = _XfeWindow(shell); (*proc)(w); _XfeWindow(w) = window; }
/*----------------------------------------------------------------------*/ static void ListUnmanage(Widget w) { XfeComboBoxPart * cp = _XfeComboBoxPart(w); assert( _XfeIsAlive(cp->shell) ); assert( _XfeIsAlive(cp->list) ); /* not popped up */ cp->popped_up = False; /* Unmanage the scrolled window */ XtUnmanageChild(_XfeParent(cp->list)); ShellPopdown(w); }
/*----------------------------------------------------------------------*/ /* extern */ Widget XfeBiggestWidget(Boolean horizontal,WidgetList widgets,Cardinal n) { Dimension biggest_dim = 0; Dimension dim; Widget max_widget = NULL; Widget widget; Cardinal i; assert( widgets != NULL ); if (!widgets) { return NULL; } for (i = 0; i < n; i++) { widget = widgets[i]; assert( _XfeIsAlive(widget) ); dim = (horizontal ? _XfeWidth(widget) : _XfeHeight(widget)); if (dim > biggest_dim) { biggest_dim = dim; max_widget = widget; } } return max_widget; }
/*----------------------------------------------------------------------*/ static void LayoutTitle(Widget w) { XfeFancyBoxPart * fp = _XfeFancyBoxPart(w); XfeComboBoxPart * cp = _XfeComboBoxPart(w); int x; int total_icon_width = 0; if (_XfeIsAlive(fp->icon)) { x = _XfeX(fp->icon) + _XfeWidth(fp->icon); total_icon_width = _XfeWidth(fp->icon) + cp->spacing; } else { x = CB_OFFSET_LEFT(w,cp) + cp->title_shadow_thickness; } _XfeConfigureWidget(cp->title, x, (_XfeHeight(w) - _XfeHeight(cp->title)) / 2, CB_RECT_WIDTH(w,cp) - cp->spacing - _XfeWidth(cp->arrow) - total_icon_width - 2 * cp->title_shadow_thickness, CB_RECT_HEIGHT(w,cp) - 2 * cp->title_shadow_thickness); }
/*----------------------------------------------------------------------*/ static Widget ListCreate(Widget w) { XfeComboBoxPart * cp = _XfeComboBoxPart(w); Widget list = NULL; Arg av[10]; Cardinal ac = 0; assert( _XfeIsAlive(cp->shell) ); XtSetArg(av[ac],XmNbackground, _XfeBackgroundPixel(w)); ac++; XtSetArg(av[ac],XmNforeground, _XfemForeground(w)); ac++; XtSetArg(av[ac],XmNshadowThickness, _XfemShadowThickness(w)); ac++; list = XmCreateScrolledList(cp->shell,LIST_NAME,av,ac); XtManageChild(list); XtUnmanageChild(_XfeParent(list)); /* _XfeResizeWidget(list,400,500); */ /* _XfeResizeWidget(cp->shell,400,500); */ return list; }
/*----------------------------------------------------------------------*/ /* 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 */ void XfeMenuItemEraseAccent(Widget item, unsigned char accent_type, Dimension offset_left, Dimension offset_right, Dimension shadow_thickness, Dimension accent_thickness) { Widget pw; GC gc; XGCValues values; int subwindow_mode; /* duh */ if (accent_type == XmACCENT_NONE) { return; } assert( _XfeIsAlive(item) ); assert( XmIsPushButton(item) || XmIsCascadeButton(item) ); pw = _XfeParent(item); assert( XmIsRowColumn(pw) ); gc = _XfemBackgroundGC(pw); /* Remember the old wubwindow mode values */ XGetGCValues(XtDisplay(item),gc,GCSubwindowMode,&values); subwindow_mode = values.subwindow_mode; /* Force the subwindow mode to IncludeInferiors */ XSetSubwindowMode(XtDisplay(item),gc,IncludeInferiors); switch(accent_type) { case XmACCENT_BOTTOM: AccentBottom(item,gc,None,offset_left,offset_right, shadow_thickness,accent_thickness,ACCENT_ERASE); break; case XmACCENT_ALL: AccentAll(item,gc,None,offset_left,offset_right, shadow_thickness,accent_thickness,ACCENT_ERASE); break; case XmACCENT_TOP: AccentTop(item,gc,None,offset_left,offset_right, shadow_thickness,accent_thickness,ACCENT_ERASE); break; default: break; } /* Restore the old subwindow mode */ XSetSubwindowMode(XtDisplay(item),gc,subwindow_mode); }
/*----------------------------------------------------------------------*/ /* extern */ Boolean XfeMenuIsFull(Widget menu) { Dimension screen_height; Widget last; assert( _XfeIsAlive(menu) ); assert( XmIsRowColumn(menu) ); screen_height = XfeScreenHeight(menu); last = XfeChildrenGetLast(menu); if (!last) { return False; } /* * The menu is "full" if its height plus that of a potential new child * are longer than the screen height. Assume the new child will be * the same height as the last child in the menu. */ if ((_XfeHeight(menu) + (3 * _XfeHeight(last))) > XfeScreenHeight(menu)) { return True; } return False; }
/*----------------------------------------------------------------------*/ /* 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 */ void _XfeMoveWidget(Widget w,int x,int y) { assert( _XfeIsAlive(w) ); #if 0 printf("_XfeMoveWidget(%s,%d,%d)\n",XtName(w),width,height); #endif #if 0 assert( x >= 0 ); assert( y >= 0 ); #endif /* Make sure the positions are different */ if ((_XfeX(w) == x) && (_XfeY(w) == y)) { return; } /* Configure XfePrimitive or XfeManager classes */ if (XfeIsPrimitive(w) || XfeIsManager(w)) { XtMoveWidget(w,x,y); } /* Configure any other class */ else { _XmMoveObject(w,x,y); } }
/*----------------------------------------------------------------------*/ /* extern */ void _XfeResizeWidget(Widget w,int width,int height) { assert( _XfeIsAlive(w) ); #if 0 printf("_XfeResizeWidget(%s,%d,%d)\n",XtName(w),width,height); #endif #if 0 assert( width > 0 ); assert( height > 0 ); #endif /* Ignore this request if width or height are 0 */ if (!width || !height) { return; } /* Make sure the dimension are different */ if ((_XfeWidth(w) == width) && (_XfeHeight(w) == height)) { return; } _XfeConfigureWidget(w,_XfeX(w),_XfeY(w),width,height); }
/*----------------------------------------------------------------------*/ static void TitleConfigure(Widget w) { XfeComboBoxPart * cp = _XfeComboBoxPart(w); Arg av[10]; Cardinal ac = 0; assert( _XfeIsAlive(cp->title) ); if (cp->combo_box_type == XmCOMBO_BOX_EDITABLE) { XfeOverrideTranslations(cp->title, _XfeComboBoxTextEditableTranslations); XtSetArg(av[ac],XmNeditable,True); ac++; XtSetArg(av[ac],XmNcursorPositionVisible,True); ac++; } else { XfeOverrideTranslations(cp->title, _XfeComboBoxTextReadOnlyTranslations); XtSetArg(av[ac],XmNeditable,False); ac++; XtSetArg(av[ac],XmNcursorPositionVisible,False); ac++; } XtSetValues(cp->title,av,ac); }
/*----------------------------------------------------------------------*/ /* extern */ unsigned char XfeMenuType(Widget menu) { assert( _XfeIsAlive(menu) ); assert( XmIsRowColumn(menu) ); return RC_Type(menu); }
/*----------------------------------------------------------------------*/ static Boolean AcceptChild(Widget child) { Widget w = _XfeParent(child); XfeFancyBoxPart * fp = _XfeFancyBoxPart(w); return (!_XfeIsAlive(fp->icon) && XfeIsButton(child)); }
/*----------------------------------------------------------------------*/ /* extern */ void XfeComboBoxAddItemUnique(Widget w,XmString item,int position) { /* XfeComboBoxPart * cp = _XfeComboBoxPart(w); */ assert( _XfeIsAlive(w) ); assert( XfeIsComboBox(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); } } }
/*----------------------------------------------------------------------*/ Visual * XfeVisual(Widget w) { Widget shell; assert( w != NULL ); shell = XfeAncestorFindByClass(w,shellWidgetClass,XfeFIND_ANY); assert( _XfeIsAlive(shell) ); if (!_XfeIsAlive(w)) { return NULL; } return ((ShellWidget) shell) -> shell . visual; }