Path: utzoo!attcan!uunet!cs.utexas.edu!sdd.hp.com!usc!apple!keith From: keith@Apple.COM (Keith Rollin) Newsgroups: comp.sys.mac.programmer Subject: Re: Query: Double lines on default button...How? Message-ID: <42613@apple.Apple.COM> Date: 3 Jul 90 19:01:39 GMT References: <9883@odin.corp.sgi.com> <3486@adobe.UUCP> Organization: Apple Computer Inc, Cupertino, CA Lines: 89 In article <3486@adobe.UUCP> hawley@adobe.UUCP (Steve Hawley) writes: >In article <9883@odin.corp.sgi.com> myoung@joker.sgi.com (Mark Young) writes: >>that describes how to make a button with the double lines that indicates >>the default selection. I found a comment indicating that item #1 was the >>default selection, but my "ok" button, which is item #1 doesn't appear with >>the telltale double lines? >> >>any clues? > >Bad news: The bold outline does NOT get drawn for you. You must do that >yourself. > >Inside Macintosh Volume I has some code to do that. It boils down to getting >the bounding rect of the item, InsetRect(&boundingRect, -4, -4), PenSize(2, 2), >and then calling FrameRoundRect(...) to draw it. > >The bad news is that you have to do the updates yourself. This can be a real >pain in modeless dialog boxes, in particular. Since this is likely to be >something you'll want to do fairly often, you may want to write a function >like "EmboldenButton()" that takes a ControlHandle as an argument and does >all the nitty-gritty. The reason for using a ControlHandle instead of a >handle to a dialog item is that you can always get a ControlHandle from a >dialog item, but not the reverse. Remember, you may want to call this from >another section of your code, say for use in a plain window not a dialog box. > >To get around the update problem in dialog boxes, you may wish to define the >bold outline as a user item that draws itself around item #1. Some people >implement this as a separate control definition as well. > Following is the routine that DTS will be using in future versions of our sample code. Note that it DOES NOT use the (16, 16) method recommended by Inside Mac, which is why I'm posting it here. PROCEDURE OutlineButton(button: UNIV ControlHandle); {Given any control handle, this will draw an outline around it. This is used for the default button of a window. The extra nice feature here is that I'll erase the outline for buttons that are inactive. Seems like there should be a Toolbox call for getting a control's hilite state. Since there isn't, I have to look into the control record myself. This should be called for update and activate events. The method for determining the oval diameters for the roundrect is a little different than that recommended by Inside Mac. IM I-407 suggests that you use a hardcoded (16,16) for the diameters. However, this only looks good for small roundrects. For larger ones, the outline doesn't follow the inner roundrect because the CDEF for simply buttons doesn't use (16,16). Instead, it uses half the height of the button as the diameter. By using this formula, too, our outlines look better. WARNING: This will set the current port to the control's window.} CONST kButtonFrameSize= 3; { button frameUs pen size } kButtonFrameInset= - 4;{ inset rectangle adjustment around button } VAR theRect: Rect; curPen: PenState; buttonOval: integer; BEGIN IF button <> NIL THEN BEGIN SetPort(button^^.contrlOwner); GetPenState(curPen); PenNormal; theRect := button^^.contrlRect; InsetRect(theRect, kButtonFrameInset, kButtonFrameInset); buttonOval := (theRect.bottom - theRect.top) DIV 2; IF (button^^.contrlHilite = kCntlActivate) THEN PenPat(black) ELSE PenPat(gray); PenSize(kButtonFrameSize, kButtonFrameSize); FrameRoundRect(theRect, buttonOval, buttonOval); SetPenState(curPen); END; END; -- ------------------------------------------------------------------------------ Keith Rollin --- Apple Computer, Inc. --- Developer Technical Support INTERNET: keith@apple.com UUCP: {decwrl, hoptoad, nsc, sun, amdahl}!apple!keith "Argue for your Apple, and sure enough, it's yours" - Keith Rollin, Contusions