?? frame.c
字號:
break ; case Trough: Draw3dBox(w, 0,sy+0, sw,sh, 2, botGC, topGC) ; Draw3dBox(w, s-2, sy+s-2, sw-s*2+4, sh-s*2+4, 2, topGC, botGC) ; break ; }} /* Called when any Frame widget resources are changed. *//* ARGSUSED */static BooleanFrameSetValues(current, request, new, args, num_args) Widget current, request, new; ArgList args; Cardinal *num_args;{ FrameWidget curfw = (FrameWidget) current ; FrameWidget fw = (FrameWidget) new ; Boolean needRedraw = False ; if( fw->frame.title != curfw->frame.title || fw->frame.shadowWidth != curfw->frame.shadowWidth || fw->frame.marginWidth != curfw->frame.marginWidth || fw->frame.marginHeight != curfw->frame.marginHeight ) { needRedraw = True ; fw->frame.needs_layout = True ; } /* TODO: if any color changes, need to recompute GCs and redraw */ if( fw->core.background_pixel != curfw->core.background_pixel || fw->core.background_pixmap != curfw->core.background_pixmap || fw->frame.foreground != curfw->frame.foreground || fw->frame.be_nice_to_cmap != curfw->frame.be_nice_to_cmap || fw->frame.top_shadow_contrast != curfw->frame.top_shadow_contrast || fw->frame.bot_shadow_contrast != curfw->frame.bot_shadow_contrast ) { FrameFreeGCs(fw) ; FrameAllocGCs(fw) ; needRedraw = True ; } else if( fw->core.sensitive != curfw->core.sensitive || fw->frame.type != curfw->frame.type || fw->frame.justify != curfw->frame.justify ) needRedraw = True ; return needRedraw ;}/* * Return preferred size. */static XtGeometryResultFrameQueryGeometry(w, intended, preferred) Widget w; XtWidgetGeometry *intended, *preferred;{register FrameWidget fw = (FrameWidget)w ; Dimension cw,ch ; /* child width, height */ Dimension tw,th ; /* title width, height */ XtWidgetGeometry c_intended, c_preferred ; Widget child = FrameChild(fw) ; Widget ttl = fw->frame.title ; Dimension sw = fw->frame.shadowWidth ; Dimension mw = fw->frame.marginWidth ; Dimension mh = fw->frame.marginHeight ; /* Take intended size; subtract shadow width, margin, child border * size and forward the offer to the child. Take child response, * add border size, margin, shadow width and return that result * to parent. * * Somewhat more complicated if there's a title widget. */ /* First, get title size. */ if( ttl != NULL && XtIsManaged(ttl) ) { XtQueryGeometry(ttl, NULL, &c_preferred) ; tw = c_preferred.width + 2*c_preferred.border_width + 2*max(mw, TTL_MARGIN) ; th = c_preferred.height + 2*c_preferred.border_width ; } else tw = th = 0 ; /* title height will be used in place of top shadow width */ th = max(sw,th) ; if( child != NULL && XtIsManaged(child) ) { if( intended != NULL ) { c_intended = *intended ; c_intended.request_mode &= CWWidth | CWHeight ; c_intended.width -= 2*sw + 2*mw + 2*child->core.border_width ; c_intended.width = max(c_intended.width,1) ; c_intended.height -= th+sw + 2*mh + 2*child->core.border_width ; c_intended.height = max(c_intended.height,1) ; } else c_intended.request_mode = 0 ; XtQueryGeometry(child, &c_intended, &c_preferred) ; cw = c_preferred.width + 2*c_preferred.border_width + 2*sw + 2*mw ; ch = c_preferred.height + 2*c_preferred.border_width ; /* I dunno if this is the right semantics, but I prefer it! - Mark */ if (!fw->frame.allowResize) { /* don't allow initial request... */ if (child->core.width) { cw = child->core.width + 2*child->core.border_width + 2*sw + 2*mw; } if (child->core.height) { ch = child->core.height + 2*child->core.border_width; } } } else cw = ch = MIN_SIZE ; preferred->request_mode = CWWidth | CWHeight ; preferred->width = max(cw,tw) /* + 2*sw BUGBUG - was adding sw twice! Mark */ ; preferred->height = th+sw + 2*mh + ch ; if( intended == NULL ) return XtGeometryYes ; if( intended->width == w->core.width && intended->height == w->core.height ) return XtGeometryNo ; if( (!(intended->request_mode & CWWidth) || intended->width >= preferred->width) && (!(intended->request_mode & CWHeight) || intended->height >= preferred->height) ) return XtGeometryYes; else return XtGeometryAlmost;}/* * Geometry Manager; called when a child wants to be resized. */static XtGeometryResultFrameGeometryManager(w, req, reply) Widget w; XtWidgetGeometry *req; XtWidgetGeometry *reply; /* RETURN */{ FrameWidget fw = (FrameWidget) XtParent(w); XtGeometryResult result ; /* Position request always denied */ if( !fw->frame.allowResize || (req->request_mode & CWX) && req->x != w->core.x || (req->request_mode & CWY) && req->y != w->core.y ) return XtGeometryNo ; /* Make all three fields in the request valid */ if( !(req->request_mode & CWWidth) ) req->width = w->core.width; if( !(req->request_mode & CWHeight) ) req->height = w->core.height; if( !(req->request_mode & CWBorderWidth) ) req->border_width = w->core.border_width; if( req->width == w->core.width && req->height == w->core.height && req->border_width == w->core.border_width ) return XtGeometryNo ; /* Size changes must see if the new size can be accomodated. * A request to resize will be accepted only if the Frame can be * resized to accomodate. */ if (req->request_mode & (CWWidth | CWHeight | CWBorderWidth)) { XtWidgetGeometry myrequest, myreply ; Dimension cw,ch ; /* child size, including borders */ Dimension tw,th ; /* title size, including borders */ Dimension wid,hgt ; /* Frame widget size */ Dimension oldWid = fw->core.width, oldHgt = fw->core.height ; Widget child = FrameChild(fw) ; Widget ttl = fw->frame.title ; Dimension sw = fw->frame.shadowWidth ; Dimension mw = fw->frame.marginWidth ; Dimension mh = fw->frame.marginHeight ; Dimension margin = sw + req->border_width ; if( w == child ) { cw = req->width + req->border_width*2 ; ch = req->height + req->border_width*2 ; } else if( child != NULL ) { cw = child->core.width + child->core.border_width*2 ; ch = child->core.height + child->core.border_width*2 ; } else cw = ch = 0 ; if( w == ttl ) { tw = req->width + req->border_width*2 ; th = req->height + req->border_width*2 ; } else if( ttl != NULL ) { tw = ttl->core.width + ttl->core.border_width*2 ; th = ttl->core.height + ttl->core.border_width*2 ; } else tw = th = 0 ; PreferredSize3(fw, cw,ch, tw,th, &wid, &hgt) ; /* Ask to be resized to accomodate. */ myrequest.width = wid ; myrequest.height = hgt ; myrequest.request_mode = CWWidth | CWHeight ; myrequest.request_mode |= req->request_mode & XtCWQueryOnly ; result = XtMakeGeometryRequest((Widget)fw, &myrequest, &myreply) ; /* !$@# Box widget changes the core size even if QueryOnly * is set. I'm convinced this is a bug. At any rate, to work * around the bug, we need to restore the core size after every * query geometry request. This is only partly effective, * as there may be other boxes further up the tree. */ if( myrequest.request_mode & XtCWQueryOnly ) { fw->core.width = oldWid ; fw->core.height = oldHgt ; } /* If parent offers a compromise, we do the same. */ if( result == XtGeometryAlmost ) { reply->width = myreply.width - (margin + mw) * 2 ; reply->width = min(reply->width, req->width) ; reply->height = myreply.height- (margin+mh)*2; reply->height = min(reply->height, req->height) ; reply->border_width = req->border_width ; if( reply->width < 1 || reply->height < 1 ) result = XtGeometryNo ; } else if( result == XtGeometryYes && !(req->request_mode & XtCWQueryOnly) ) { w->core.width = req->width ; w->core.height = req->height ; w->core.border_width = req->border_width ; } return result ; } return XtGeometryNo ;} /* The number of children we manage has changed; recompute * size from scratch. */static voidFrameChangeManaged(w) Widget w;{ FrameWidget fw = (FrameWidget)w ; XtWidgetGeometry request, reply ; request.request_mode = CWWidth | CWHeight ; PreferredSize(fw, &request.width, &request.height) ; (void) XtMakeGeometryRequest(w, &request, &reply) ; /* TODO: is this needed? */ XtClass(w)->core_class.resize(w) ;}/**************************************************************** * * Private Procedures * * TODO: Somehow make these shared. * ****************************************************************/static voidFrameAllocGCs(fw) FrameWidget fw ;{ Widget w = (Widget)fw ; fw->frame.foregroundGC = AllocFgGC(w, fw->frame.foreground, None ) ; fw->frame.topGC = AllocTopShadowGC(w, fw->frame.top_shadow_contrast, fw->frame.be_nice_to_cmap) ; fw->frame.botGC = AllocBotShadowGC(w, fw->frame.bot_shadow_contrast, fw->frame.be_nice_to_cmap) ;}static voidFrameFreeGCs(fw) FrameWidget fw ;{ Widget w = (Widget) fw; XtReleaseGC(w, fw->frame.foregroundGC) ; XtReleaseGC(w, fw->frame.topGC) ; XtReleaseGC(w, fw->frame.botGC) ;} /* GEOMETRY UTILITIES */ /* find preferred size. Ask child, add room for frame & return. */static voidPreferredSize(fw, reply_width, reply_height) FrameWidget fw; Dimension *reply_width, *reply_height; /* total widget size */{ XtWidgetGeometry preferred ; (void) FrameQueryGeometry((Widget)fw, NULL, &preferred) ; *reply_width = preferred.width ; *reply_height = preferred.height ;} /* Find preferred size, given child and title's preferred sizes. */static voidPreferredSize3(fw, cw,ch, tw,th, reply_width, reply_height) FrameWidget fw; int cw,ch ; /* child width, height */ int tw,th ; /* title width, height */ Dimension *reply_width, *reply_height; /* total widget size */{ Dimension sw = fw->frame.shadowWidth ; cw += 2*fw->frame.marginWidth ; tw += 2*max(fw->frame.marginWidth, TTL_MARGIN) ; *reply_width = max(cw,tw) + 2*sw ; *reply_height = max(sw,th) + ch + 2*fw->frame.marginHeight + sw ;}static WidgetFrameChild(fw) FrameWidget fw ;{ Widget *childP = NULL ; Widget ttl = fw->frame.title ; int i ; if( (childP = fw->composite.children) != NULL ) for(i=fw->composite.num_children; --i >= 0; ++childP ) if( *childP != ttl ) return *childP ; return NULL ;} /* RESOURCES *//* ARGSUSED */static void_CvtStringToShadowType(args, num_args, fromVal, toVal) XrmValuePtr args; /* unused */ Cardinal *num_args; /* unused */ XrmValuePtr fromVal ; XrmValuePtr toVal ;{ String str = (String)fromVal->addr ; int i ; static XtShadowType type; static struct {char *name; XtShadowType type;} types[] = { {"blank", Blank}, {"none", Blank}, {"solid", Solid}, {"raised", Raised}, {"shadow_out", Raised}, {"lowered", Lowered}, {"shadow_in", Lowered}, {"ridge", Ridge}, {"shadow_etched_out", Ridge}, {"groove", Groove}, {"shadow_etched_in", Groove}, {"plateau", Plateau}, {"trough", Trough}, } ; for(i=0; i<XtNumber(types); ++i) if( XmuCompareISOLatin1(str, types[i].name) == 0 ) { type = types[i].type ; break ; } if( i > XtNumber(types) ) { XtStringConversionWarning(fromVal->addr, XtRShadowType); toVal->size = 0 ; toVal->addr = NULL ; return ; } toVal->size = sizeof(type) ; toVal->addr = (XPointer) &type;}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -