[comp.sys.mac.programmer] Query: Double lines on default button...How?

myoung@joker.sgi.com (Mark Young) (07/03/90)

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?

	...myoung@joker.asd.sgi.com

anderson@Apple.COM (Clark Anderson) (07/03/90)

From: myoung@joker.sgi.com (Mark Young)
Subject: Query:  Double lines on default button...How?

>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?

On an Alert box, it's done automatically. In a dialog box, you have
to draw the surrounding box to create the 'double line' effect.

GetDItem(RecordPtr, 1, ItemType, ItemHandle, ItemRect);
PenSize(3, 3);
InsetRect(ItemRect, -4, -4);
FrameRoundRect(ItemRect, 16, 16);

(You'll have to declare ItemType, ItemHandle and ItemRect, but you'll
have to anyway, if you ever do anything extensive with dialogs)

                                        --clark

-- 
-----------------------------------------------------------
Clark Anderson                  InterNet:  anderson@apple.com
CPU Engineering                 AppleLink: C.ANDERSON
Apple Computer, Inc             BellNet:   408-974-4593

"I speak only for myself, much to my employer's relief..."
-------------------------------------------------------------

jwwalker@usceast.UUCP (Jim Walker) (07/03/90)

There is a small freeware file called "Default CDEF" that helps with this.
You paste the CDEF resource into your program's resource fork, and put an
at sign at the end of the default button's name, e.g., "OK@".  The at sign
doesn't actually appear on the button, it just tells the CDEF which button
to outline.
-- 

   Jim Walker  jwwalker@cs.scarolina.edu  76367.2271@compuserve.com

hawley@adobe.COM (Steve Hawley) (07/03/90)

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.

Happy Trails.

Steve Hawley
hawley@adobe.com
-- 
"A blow on the head is... ...worth two in the bush." -Basil Fawlty

lippin@brahms.berkeley.edu (The Apathist) (07/03/90)

I find that an inactive PICT item does a wonderful job of highlighting
the default button.  It has two advantages over drawing the ring "by
hand" -- it uses no code, and it updates whenever necessary.

I even use this method in alerts -- although the dialog manager draws
the outline for you, it doesn't update it if your window gets covered
(by MultiFinder or a screen saver).  A similar problem applies to the
icons for NoteAlert, CautionAlert, and StopAlert, and in this case can
be solved with an appropriate ICON item.

					--Tom Lippincott
					  lippin@math.berkeley.edu

		"It's a multi-purpose shape: a box"
					--David Byrne, "True Stories"

keith@Apple.COM (Keith Rollin) (07/04/90)

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

engber@gumball.ils.nwu.edu (Mike Engber) (07/05/90)

You can make the bold outline a PICT item and locate it over the default
button. All the drawings and updates will be handled for you and you
don`t have to write a single line of code.  I just used SuperPaint`s
rounded rect tool to create the PICT.

The obvious disadvantage is that different size default buttons 
can`t share PICTs, but 90% of my default buttons are of the "OK"
variety.

-ME