/*----------------------------------------------------------------------*/ 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); }
/*----------------------------------------------------------------------*/ static void DrawHighlight(Widget w,XEvent * event,Region region,XRectangle * clip_rect) { XfeComboBoxPart * cp = _XfeComboBoxPart(w); /* Make sure the highlight is needed */ if (!cp->highlight_thickness || !_XfeIsRealized(w)) { return; } if (cp->highlighted) { _XmDrawSimpleHighlight(XtDisplay(w), _XfeWindow(w), _XfemHighlightGC(w), 0,0, _XfeWidth(w),_XfeHeight(w), cp->highlight_thickness); } else { assert( XmIsManager(_XfeParent(w)) ); _XmDrawSimpleHighlight(XtDisplay(w), _XfeWindow(w), _XfemBackgroundGC(_XfeParent(w)), 0,0, _XfeWidth(w),_XfeHeight(w), cp->highlight_thickness); } }
/*----------------------------------------------------------------------*/ 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); */ }
/*----------------------------------------------------------------------*/ 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; }
/*----------------------------------------------------------------------*/ static void ActionPopdown(Widget item,XEvent * event,char ** params,Cardinal * nparams) { Widget w = XfeIsComboBox(item) ? item : _XfeParent(item); XfeComboBoxPart * cp = _XfeComboBoxPart(w); #if 1 printf("ActionPopdown(%s)\n",XtName(w)); #endif if (cp->delay_timer_id) { StickRemoveTimeout(w); } else { ListUnmanage(w); } XtVaSetValues(cp->arrow,XmNarmed,False,NULL); /* if (!cp->remain_popped_up) */ /* { */ /* XtPopdown(cp->shell); */ /* } */ /* cp->remain_popped_up = False; */ /* ListUnmanage(w); */ /* XUnmapWindow(XtDisplay(w),_XfeWindow(cp->shell)); */ }
/*----------------------------------------------------------------------*/ static void ShellPopdown(Widget w) { XfeComboBoxPart * cp = _XfeComboBoxPart(w); assert( _XfeIsAlive(cp->shell) ); _XmPopdown(cp->shell); }
/*----------------------------------------------------------------------*/ static void ActionPopup(Widget item,XEvent * event,char ** params,Cardinal * nparams) { Widget w = XfeIsComboBox(item) ? item : _XfeParent(item); XfeComboBoxPart * cp = _XfeComboBoxPart(w); int space_below = ScreenGetSpaceBelow(w); int space_above = ScreenGetSpaceAbove(w); #if 1 printf("ActionPopup(%s,above = %d,below = %d)\n", XtName(w), space_above, space_below); #endif /* Check if we are already popped up */ if (cp->popped_up) { printf("already popped up\n"); StickRemoveTimeout(w); ListUnmanage(w); XtVaSetValues(cp->arrow,XmNarmed,False,NULL); return; } space_below = 200; _XfeConfigureWidget(cp->shell, XfeRootX(w), XfeRootY(w) + _XfeHeight(w), _XfeWidth(w), space_below); /* XtVaSetValues(cp->list, */ /* XmNlistMarginWidth, 100, */ /* NULL); */ /* XtVaSetValues(cp->arrow,XmCArmed,True,NULL); */ /* XtPopup(cp->shell,XtGrabNone); */ /* XMapRaised(XtDisplay(w),_XfeWindow(cp->shell)); */ /* XMapRaised(XtDisplay(w),_XfeWindow(cp->shell)); */ cp->remain_popped_up = False; #if 1 StickAddTimeout(w); #endif XtVaSetValues(cp->arrow,XmNarmed,True,NULL); ListManage(w); }
/*----------------------------------------------------------------------*/ static void StickAddTimeout(Widget w) { XfeComboBoxPart * cp = _XfeComboBoxPart(w); cp->delay_timer_id = XtAppAddTimeOut(XtWidgetToApplicationContext(w), STICK_DELAY, StickTimeout, (XtPointer) w); }
/*----------------------------------------------------------------------*/ static void ShellPopup(Widget w) { XfeComboBoxPart * cp = _XfeComboBoxPart(w); assert( _XfeIsAlive(cp->shell) ); /* _XmPopupSpringLoaded(cp->shell); */ _XmPopup(cp->shell,XtGrabNone); }
/*----------------------------------------------------------------------*/ static void TextLosingFocusCB(Widget text,XtPointer client_data,XtPointer call_data) { Widget w = (Widget) client_data; XfeComboBoxPart * cp = _XfeComboBoxPart(w); cp->highlighted = False; DrawHighlight(w,NULL,NULL,&_XfemWidgetRect(w)); }
/*----------------------------------------------------------------------*/ static void ArrowActivateCB(Widget text,XtPointer client_data,XtPointer call_data) { Widget w = (Widget) client_data; XfeComboBoxPart * cp = _XfeComboBoxPart(w); #if 0 printf("ArrowActivate(%s)\n",XtName(w)); #endif /* cp->remain_popped_up = True; */ }
/*----------------------------------------------------------------------*/ static void StickRemoveTimeout(Widget w) { XfeComboBoxPart * cp = _XfeComboBoxPart(w); /* Remove the timer if its still has not triggered */ if (cp->delay_timer_id) { XtRemoveTimeOut(cp->delay_timer_id); } /* Reset the timer */ cp->delay_timer_id = 0; }
/*----------------------------------------------------------------------*/ static void StickTimeout(XtPointer client_data,XtIntervalId * id) { Widget w = (Widget) client_data; XfeComboBoxPart * cp = _XfeComboBoxPart(w); cp->delay_timer_id = 0; cp->remain_popped_up = True; #if 1 printf("StickTimeout(%s)\n",XtName(w)); #endif }
/*----------------------------------------------------------------------*/ static void DrawTitleShadow(Widget w,XEvent * event,Region region,XRectangle * clip_rect) { XfeFancyBoxPart * fp = _XfeFancyBoxPart(w); XfeComboBoxPart * cp = _XfeComboBoxPart(w); /* Make sure the shadow is needed */ if (!cp->title_shadow_thickness) { return; } if (_XfeIsAlive(fp->icon)) { Dimension icon_x1 = _XfeX(fp->icon) - cp->spacing; Dimension title_x2 = _XfeX(cp->title) + _XfeWidth(cp->title); /* Draw the shadow around the icon and text */ _XmDrawShadows(XtDisplay(w), _XfeWindow(w), _XfemTopShadowGC(w),_XfemBottomShadowGC(w), CB_OFFSET_LEFT(w,cp), _XfeY(cp->title) - cp->title_shadow_thickness, (title_x2 - icon_x1) + 2 * cp->title_shadow_thickness, _XfeHeight(cp->title) + 2 * cp->title_shadow_thickness, cp->title_shadow_thickness, cp->title_shadow_type); } else { /* Draw the shadow around the text only */ XfeDrawShadowsAroundWidget(w, cp->title, _XfemTopShadowGC(w), _XfemBottomShadowGC(w), 0, cp->title_shadow_thickness, cp->title_shadow_type); } }
/*----------------------------------------------------------------------*/ 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); }
/*----------------------------------------------------------------------*/ static Widget TitleCreate(Widget w) { XfeComboBoxPart * cp = _XfeComboBoxPart(w); Widget title = NULL; if (cp->combo_box_type == XmCOMBO_BOX_EDITABLE) { title = TitleTextCreate(w); } else { title = TitleLabelCreate(w); } return title; }
/*----------------------------------------------------------------------*/ static void LayoutArrow(Widget w) { XfeComboBoxPart * cp = _XfeComboBoxPart(w); _XfeConfigureWidget(cp->arrow, _XfeWidth(w) - CB_OFFSET_RIGHT(w,cp) - _XfeWidth(cp->arrow), (_XfeHeight(w) - _XfeHeight(cp->arrow)) / 2, _XfeWidth(cp->arrow), _XfeHeight(cp->arrow)); }
/*----------------------------------------------------------------------*/ static void PreferredGeometry(Widget w,Dimension * width,Dimension * height) { XfeFancyBoxPart * fp = _XfeFancyBoxPart(w); XfeComboBoxPart * cp = _XfeComboBoxPart(w); /* Invoke the super class' preferred_geometry method */ (*xfeComboBoxClassRec.xfe_manager_class.preferred_geometry)(w, width, height); /* Add the icon widht if needed */ if (_XfeChildIsShown(fp->icon)) { *width += (cp->spacing + _XfeWidth(fp->icon)); } }
/*----------------------------------------------------------------------*/ /* extern */ void XfeComboBoxAddItem(Widget w,XmString item,int position) { XfeComboBoxPart * cp = _XfeComboBoxPart(w); /* XmListPart * lp = _XfeXmListPart(w); */ assert( _XfeIsAlive(w) ); assert( XfeIsComboBox(w) ); XmListAddItem(cp->list,item,position); #if 0 DtComboBoxWidget combo = (DtComboBoxWidget)combo_w; DtComboBoxPart *combo_p = (DtComboBoxPart*)&(combo->combo_box); XmStringTable list_items = ((XmListWidget)combo_p->list)->list.items; int i; if (item && ((XmListWidget)combo_p->list)->list.itemCount) { for (i = 0; i < combo_p->item_count; i++) if (XmStringCompare(item, list_items[i])) break; if ((i < combo_p->item_count) && unique) return; } XmListAddItem(combo_p->list, item, pos); SyncWithList(combo_p); if (combo_p->label) { SetMaximumLabelSize(combo_p); if (combo_p->type == XmDROP_DOWN_LIST_BOX) { ClearShadow(combo, TRUE); if (combo_p->recompute_size) SetComboBoxSize(combo); LayoutChildren(combo); DrawShadow(combo); } } if (combo_p->type == XmDROP_DOWN_COMBO_BOX) SetTextFieldData(combo_p, NULL); else SetLabelData(combo_p, NULL, FALSE); #endif }
/*----------------------------------------------------------------------*/ static void PreferredGeometry(Widget w,Dimension * width,Dimension * height) { XfeComboBoxPart * cp = _XfeComboBoxPart(w); *height = CB_OFFSET_TOP(w,cp) + CB_OFFSET_BOTTOM(w,cp) + XfeMax(_XfeHeight(cp->title),_XfeHeight(cp->arrow)) + 2 * cp->title_shadow_thickness; *width = CB_OFFSET_LEFT(w,cp) + CB_OFFSET_RIGHT(w,cp) + _XfeWidth(cp->title) + cp->spacing + _XfeWidth(cp->arrow) + 2 * cp->title_shadow_thickness; }
/*----------------------------------------------------------------------*/ static void DefaultTitleShadowThickness(Widget w,int offset,XrmValue * value) { XfeComboBoxPart * cp = _XfeComboBoxPart(w); static Dimension shadow_thickness; if (cp->combo_box_type == XmCOMBO_BOX_EDITABLE) { shadow_thickness = _XfemShadowThickness(w); } else { shadow_thickness = 0; } value->addr = (XPointer) &shadow_thickness; value->size = sizeof(shadow_thickness); }
/*----------------------------------------------------------------------*/ static void LayoutTitle(Widget w) { XfeComboBoxPart * cp = _XfeComboBoxPart(w); _XfeConfigureWidget(cp->title, CB_OFFSET_LEFT(w,cp) + cp->title_shadow_thickness, (_XfeHeight(w) - _XfeHeight(cp->title)) / 2, CB_RECT_WIDTH(w,cp) - cp->spacing - _XfeWidth(cp->arrow) - 2 * cp->title_shadow_thickness, CB_RECT_HEIGHT(w,cp) - 2 * cp->title_shadow_thickness); }
/*----------------------------------------------------------------------*/ static void DrawTitleShadow(Widget w,XEvent * event,Region region,XRectangle * clip_rect) { XfeComboBoxPart * cp = _XfeComboBoxPart(w); /* Make sure the shadow is needed */ if (!cp->title_shadow_thickness) { return; } /* Draw the shadow around the text only */ XfeDrawShadowsAroundWidget(w, cp->title, _XfemTopShadowGC(w), _XfemBottomShadowGC(w), 0, cp->title_shadow_thickness, cp->title_shadow_type); }
/*----------------------------------------------------------------------*/ static void DrawShadow(Widget w,XEvent * event,Region region,XRectangle * clip_rect) { XfeComboBoxPart * cp = _XfeComboBoxPart(w); if (!_XfemShadowThickness(w)) { return; } /* Draw the shadow */ _XmDrawShadows(XtDisplay(w), _XfeWindow(w), _XfemTopShadowGC(w),_XfemBottomShadowGC(w), cp->highlight_thickness, cp->highlight_thickness, _XfeWidth(w) - 2 * cp->highlight_thickness, _XfeHeight(w) - 2 * cp->highlight_thickness, _XfemShadowThickness(w), _XfemShadowType(w)); }
/*----------------------------------------------------------------------*/ static void IconLayout(Widget w) { XfeFancyBoxPart * fp = _XfeFancyBoxPart(w); XfeComboBoxPart * cp = _XfeComboBoxPart(w); if (!_XfeIsAlive(fp->icon)) { return; } _XfeConfigureWidget(fp->icon, CB_OFFSET_LEFT(w,cp) + cp->title_shadow_thickness + cp->spacing, (_XfeHeight(w) - _XfeHeight(fp->icon)) / 2, _XfeWidth(fp->icon), _XfeHeight(fp->icon)); }
/*----------------------------------------------------------------------*/ static Boolean SetValues(Widget ow,Widget rw,Widget nw,ArgList args,Cardinal *nargs) { XfeComboBoxPart * np = _XfeComboBoxPart(nw); XfeComboBoxPart * op = _XfeComboBoxPart(ow); /* title */ if (np->title != op->title) { _XmWarning(nw,MESSAGE2); np->title = op->title; } /* list */ if (np->list != op->list) { _XmWarning(nw,MESSAGE3); np->list = op->list; } /* shell */ if (np->shell != op->shell) { _XmWarning(nw,MESSAGE4); np->shell = op->shell; } /* combo_box_type */ if (np->combo_box_type != op->combo_box_type) { TitleConfigure(nw); _XfemConfigFlags(nw) |= XfeConfigExpose; #if 0 _XmWarning(nw,MESSAGE6); np->combo_box_type = op->combo_box_type; #endif } /* title_shadow_thickness */ if (np->title_shadow_thickness != op->title_shadow_thickness) { _XfemConfigFlags(nw) |= XfeConfigGLE; } /* title_shadow_type */ if (np->title_shadow_type != op->title_shadow_type) { /* Make sure the new shadow type is ok */ XfeRepTypeCheck(nw,XmRShadowType,&np->title_shadow_type,XmSHADOW_IN); _XfemConfigFlags(nw) |= XfeConfigExpose; } return _XfeManagerChainSetValues(ow,rw,nw,xfeComboBoxWidgetClass); }
/*----------------------------------------------------------------------*/ static void Initialize(Widget rw,Widget nw,ArgList args,Cardinal *nargs) { XfeComboBoxPart * cp = _XfeComboBoxPart(nw); /* Make sure rep types are ok */ XfeRepTypeCheck(nw,XmRShadowType,&cp->title_shadow_type, XmSHADOW_IN); XfeRepTypeCheck(nw,XmRComboBoxType,&cp->combo_box_type, XmCOMBO_BOX_READ_ONLY); /* Make sure read-only resources aren't set */ if (cp->title) { _XmWarning(nw,MESSAGE2); cp->title = NULL; } if (cp->list) { _XmWarning(nw,MESSAGE3); cp->list = NULL; } if (cp->shell) { _XmWarning(nw,MESSAGE4); cp->shell = NULL; } if (cp->arrow) { _XmWarning(nw,MESSAGE5); cp->arrow = NULL; } /* Create components */ cp->arrow = ArrowCreate(nw); cp->title = TitleCreate(nw); cp->shell = ShellCreate(nw); cp->list = ListCreate(nw); /* Configure the title */ TitleConfigure(nw); /* Initialize private members */ cp->highlighted = False; cp->delay_timer_id = 0; /* Manage the children */ XtManageChild(cp->title); XtManageChild(cp->list); XtManageChild(cp->arrow); XfeOverrideTranslations(nw,_XfeComboBoxExtraTranslations); /* Finish of initialization */ _XfeManagerChainInitialize(rw,nw,xfeComboBoxWidgetClass); }