[comp.sys.mac.programmer] How do you highlight a default button?

brownh@unioncs.UUCP (H. Brown) (03/31/88)

Can someone tell me how to specify a DLOG or ALRT button to be a
highlighted default button (I have ResEdit v1.d4).  According to Mac
Revealed 2 this is done automatically to if the button is first in the
item list, this is true except that it doesn't get highlighted.

What's the latest word about version 3 of LightspeedC? I haven't seen anything
on the net recently about it.  Is it out yet?  How do I get an upgrade?

Thanks in advance.
Alex Brown and the Secret Chimps

!uunet!steinmetz!unioncs!brownh

ephraim@think.COM (ephraim vishniac) (03/31/88)

In article <618@unioncs.UUCP> brownh@unioncs.UUCP (H. Brown) writes:
>Can someone tell me how to specify a DLOG or ALRT button to be a
>highlighted default button (I have ResEdit v1.d4).  According to Mac
>Revealed 2 this is done automatically to if the button is first in the
>item list, this is true except that it doesn't get highlighted.

The first item in the DITL will be highlighted when an ALRT is drawn
using the system call for alerts.  There's no special treatment for
the first DITL item under a DLOG.  The highlighting is not there when
the ALRT is drawn in ResEdit, because it's not really an alert - it's
just a drawing of the DITL items.




Ephraim Vishniac					  ephraim@think.com
Thinking Machines Corporation / 245 First Street / Cambridge, MA 02142-1214

     On two occasions I have been asked, "Pray, Mr. Babbage, if you put
     into the machine wrong figures, will the right answers come out?"

dalea@cerebus.UUCP (Dale M. Arends X5706) (04/01/88)

Hilighting the default button in an alert box is automatically done
for you if the button is the first item in the DITL list.

To hilight a default button in a Dialog box, you will have to do the
hilighting yourself.  The simplest way is to use GetDItem (...) to
get the Rect that the button is positioned at; InSet that rect about
negative 5 (-5) pixels (that actually makes it larger); set the pen
width to 3 pixels and draw a roundRect.  This will draw the heavy border
around the button.  Reset the pen width and the box, and you're done.

A few points:  make the DLOG invisible in the resource and put the 
hilighting routine immediately after the call to retrieve the DLOG.
Then use ShowWindow to draw the dialog before calling ModalDialog.
Otherwise, the drawing of the hilighting will be out of sync with
the appearing of the window.

Also: unless this is for your own use only, please make the default
button be the least disasterous option to data already saved unless
the dialog is confirmation for updating saved data.

I'm sorry I don't have actual code segments here at work.  If you
have problems and need help, email to me at the address below.

-- 
--
		Dale M. Arends  (Fujitsu America Inc., San Jose, Calif.)
		{...}!amdahl!cerebus!dalea

The opinions expressed herein do not necessarily reflect those of my employer.
They are entirely my own if they make sense and I disavow them if they don't.

jas@cadre.dsl.PITTSBURGH.EDU (Jeffrey A. Sullivan) (04/01/88)

In article <618@unioncs.UUCP>, brownh@unioncs.UUCP (H. Brown) writes:
> Can someone tell me how to specify a DLOG or ALRT button to be a
> highlighted default button (I have ResEdit v1.d4).  According to Mac
> Revealed 2 this is done automatically to if the button is first in the
> item list, this is true except that it doesn't get highlighted.
According to IM V1 (P. 407), here is the way to highlight the default button
so thast it looks like the normal highlit default button:

PenSize(3,3);
InsetRect(displayRect,-4,-4);
FrameRoundRect(displayRect,16,16);

where displayRect is the rect of the button.

According to AUG, if you don't do this, then you shouldn't support the
return and enter key as default substitutes in your DLOG.


-- 
..........................................................................
Jeffrey Sullivan			  | University of Pittsburgh
jas@cadre.dsl.pittsburgh.edu		  | Intelligent Systems Studies Program
jasper@PittVMS.BITNET, jasst3@cisunx.UUCP | Graduate Student

levin@bbn.com (Joel B Levin) (04/02/88)

In article <1107@cadre.dsl.PITTSBURGH.EDU> jas@cadre.dsl.PITTSBURGH.EDU (Jeffrey A. Sullivan) writes:
|According to IM V1 (P. 407), here is the way to highlight the default button
|so thast it looks like the normal highlit default button:
|
|PenSize(3,3);
|InsetRect(displayRect,-4,-4);
|FrameRoundRect(displayRect,16,16);
|
|where displayRect is the rect of the button.

I have a feeling I read somewhere a year ago that you have to do more
than this; if an alert comes up in front of the dialog (or if it is a
modeless dialog?) your new rectangle will not be properly updated with
just the code shown above.  I couldn't find a tech note on the
subject, but someone from Apple described somewhere how to do this
right, maybe with a userItem.

	/JBL

UUCP: {backbone}!bbn!levin     USPS: BBN Communications Corporation
ARPA: levin@bbn.com                  50 Moulton Street
POTS: (617) 873-3463                 Cambridge, MA  02238

lampson@chgv04.dec.com (Mike Lampson, Central Area Prove-It Delivery Specialist) (04/03/88)

One thing IUve noticed about hilighting default buttons is that most 
dialog default buttons lose their hilighting when the dialog is updated.  
You can see this in most applications when the screen is updated after 
restoring from a screen saver or when switching back to the application
under MultiFinder or Switcher.  To "fix" this you need to create a fake 
userItem and call SetDItem to set the procedure below as the MyItem 
procedure for this fake userItem.  I'm still a novice Mac Programmer, 
so if anyone sees any problems with this routine, please let me know.
The following is used in my LSP programs:

{----------------------------------------------------------------- }
{ Put a frame around the specified Dialog button - usually 1       }
{ This procedure has two parameters.  The second parameter is      } 
{ essentially a dummy parameter so that this routine may be        }
{ specified as a MyItem routine                                    }
{----------------------------------------------------------------- }

 PROCEDURE DLOGFrameDefault(DLOGptr:dialogPtr,itemNo:integer);
   VAR
    curPen : PenState;
    theItemType : integer;
    theItemHandle : Handle;
    theRect : rect;
    DLOGdata : DialogPeek;
 BEGIN
   DLOGdata := DialogPeek(DLOGptr);
   GetDItem(DLOGptr, DLOGdata^.aDefItem, theItemType, theItemHandle, theRect);
   IF theItemType = (ctrlItem + btnCtrl) THEN
    BEGIN
     GetPenState(curPen);
     PenSize(3, 3);
     InsetRect(theRect, -4, -4);
     FrameRoundRect(theRect, 16, 16);
     SetPenState(curPen)
    END
  END;
-- 
        Mike                           .
                                      /|
                                     / |\
                                    /__|_\
  -------------.^^^^^^^^^^^^^^^^^^^\_____/^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^. ----
  Mike Lampson  `--------.                                             /
  Digital Equipment Corp. \                  .                        /
  Arlington Heights, IL    \                 .                       /
                            `----------------^----------------------'
  UUCP:  {allegra,decvax,hplabs,ihnp4,ucbvax,...}!decwrl!chgv04.dec.com!lampson
  ARPA:  Lampson@CHGV04.DEC.COM  -or-  Lampson%CHGV04.dec@DECWRL.DEC.COM 
  GEnie: M.LAMPSON
  ----                                                                    ----

rs4u+@andrew.cmu.edu (Richard Siegel) (04/06/88)

I handle the issue of highlighting default button by implementing my
own library of standard dialog-filters that I use for all of my dialogs.
In the standard dialog filtering, part of the update code highlights
d^.aDefItem if it's a button. The code also mimics the ROM routines in
that a press of the Return or Enter key dismisses the dialog and returns
d^.aDefItem if the default button is enabled. This way, I can
have standard bold default button and Return-key highlighting of
things like Standard File boxes (by using SFP{Get, Put}File), as 
well as my own custom dialog boxes....

		--Rich

===================================================================
Rich Siegel
Confused Undergrad, Carnegie-Mellon University

The opinions stated here do not represent the policies
of Carnegie-Mellon University.

Arpa: rich.siegel@andrew.cmu.edu
UUCP: {decvax,ucbvax,sun}!andrew.cmu.edu!rich.siegel
==================================================================

oster@dewey.soe.berkeley.edu (David Phillip Oster) (04/10/88)

if you are doing your own filter proc, remember:
1.) <return> and <enter> should be synonyms for OK
2.) <Clear> <Escape> and <Cmd>-. should be synonyms for Cancel.
3.) <Cmd>-? should get you help
4.) <Cmd>-x, <Cmd>-X, <cmd>-c, <cmd>-C, <Cmd>-v, and <Cmd>-V should
do cut, copy, and paste repsectively,
5.) <Cmd>-z should do undo.

I wish Apple would get on the ball and augment their own standard filter
proc to meet their own user interface guidlines.


--- David Phillip Oster            --A Sun 3/60 makes a poor Macintosh II.
Arpa: oster@dewey.soe.berkeley.edu --A Macintosh II makes a poor Sun 3/60.
Uucp: {uwvax,decvax,ihnp4}!ucbvax!oster%dewey.soe.berkeley.edu