[comp.sys.mac.programmer] dialogs with ModalDialog

trajmar@oahu.cs.ucla.edu (Peter Trajmar) (07/28/90)

I have two questions about dialogs (using ModalDialog()).

1) How can I dim a static text item? I know I can make it a control
such as a check box and then do it. The problem is I don't want the
check box part to be drawn. Covering this with a user item does not
work very well since you can briefly see the box when ModalDialog()
redraws. I could also make a custom control but that seems like more
trouble than it's worth.

2) Is there a good way to right align the text in an editText item?
I was able to do this using the DialogPeek handle. The problem is
that the text ends up being outside of the viewing area. I have not
seen any application that does not have its text left aligned.
Perhaps this is also more trouble than its worth. What I would ideally
like do do is decimal align floating point numbers that are in a
column of editText items.

I would appreciate any pointers you can give me.

Peter Trajmar
(trajmar@cs.ucla.edu)

dwal@midway.uchicago.edu (David Walton) (07/28/90)

In article <37353@shemp.CS.UCLA.EDU> trajmar@oahu.cs.ucla.edu (Peter Trajmar) writes:
>
>I have two questions about dialogs (using ModalDialog()).

I can answer the first, but not the second.

>1) How can I dim a static text item? I know I can make it a control
>such as a check box and then do it. The problem is I don't want the
>check box part to be drawn. Covering this with a user item does not
>work very well since you can briefly see the box when ModalDialog()
>redraws. I could also make a custom control but that seems like more
>trouble than it's worth.

You don't need to make it a control permanently; you can get an 
itemhandle to the item and then coerce that handle to a controlhandle
to set the controlhilite.  I don't have IM in front of me, but here's
my best recollection of a code fragment:


	GetDItem(myDialog, myItem, myType, myItemHandle, myItemRect);
	SetCtlHilite(controlhandle(myItemHandle), 255);

Again, these calls may be wrong in order of parameters, spelling, etc.,
but they should give you the general idea.  Using type coercion means
you don't actually have to change the item's type.  There may also be
more approved ways of dimming the text, as well.


>I would appreciate any pointers you can give me.

@thePort (and it comes free with every Macintosh application :-).

>Peter Trajmar
>(trajmar@cs.ucla.edu)

P.S.  I just noticed you were using C, not pascal; the fragment above
      (obviously) is in Pascal.
-- 

David Walton		Internet: dwal@midway.uchicago.edu
University of Chicago   {  Any opinions found herein are mine, not  }
Computing Organizations {  those of my employers (or anybody else). }

t-alexc@microsoft.UUCP (Alex CHAFFEE) (08/02/90)

In article <37353@shemp.CS.UCLA.EDU> trajmar@oahu.cs.ucla.edu (Peter Trajmar) writes:
>
>2) Is there a good way to right align the text in an editText item?

The problem with this is for inputting - how do you right align text
as it's being typed and make it look nice?  What I'd do is keep it a
normal editText item while it's the active item, but as soon as the
user tabs/clicks away from it, redraw its text using

	GetDItem ( theDialog, itemNo, &itemType, &itemHandle,
		&itemRect ); 
	GetIText ( itemHandle, st ); 
	TextBox( st+1, *st, &itemRect, teJustRight );

Of course, you'd have to do this again for update events.  To be
really slick, you could save the text in a global and change it to a
userItem whose draw procedure TextBox()s that saved text.  Then when
it's selected again, change it back.

Disclaimer: I just made that up, so it's probably wrong.

>Peter Trajmar
>(trajmar@cs.ucla.edu)

- Alex Chaffee
  ...!microsoft!t-alexc	(->Aug.10)
  chaffee@reed.bitnet	(Aug.10->)

minich@d.cs.okstate.edu (Robert Minich) (08/03/90)

> 2) Is there a good way to right align the text in an editText item?
 
| The problem with this is for inputting - how do you right align text
| as it's being typed and make it look nice?  What I'd do is keep it a
| normal editText item while it's the active item, but as soon as the
| user tabs/clicks away from it, redraw its text using
| 
| 	GetDItem ( theDialog, itemNo, &itemType, &itemHandle,
| 		&itemRect ); 
| 	GetIText ( itemHandle, st ); 
| 	TextBox( st+1, *st, &itemRect, teJustRight );
| 
| Of course, you'd have to do this again for update events.  To be
| really slick, you could save the text in a global and change it to a
| userItem whose draw procedure TextBox()s that saved text.  Then when
| it's selected again, change it back.
 
  This is completely speculation, but how about handling the text
yourself in an offscreen bitmap and just CopyBits() to the screen after
every character/delete? It may be more work than it's worth, but I think
it wouldn't be as disturbing as watching something flop back and forth
as you tab through the items.

| Disclaimer: I just made that up, so it's probably wrong.

Same here. :-)
-- 
|_    /| | Robert Minich            |
|\'o.O'  | Oklahoma State University| There are no heroes --
|=(___)= | minich@a.cs.okstate.edu  |   We all wear gray hats.
|   U    | - Ackphtth               |

RESHEF1@BGUVM.BITNET (Eran Reshef) (08/07/90)

In article <37353@shemp.CS.UCLA.EDU>, trajmar@oahu.cs.ucla.edu (Peter Trajmar) says:
>
>I have two questions about dialogs (using ModalDialog()).
>
>1) How can I dim a static text item? I know I can make it a control
>        [ ... MORE ... ]

Why would you want to use a control? Why not putting a user item over
the static text item, and set the routine which draws the user item to
do the following:

procedure dim_text  (dlg: WindowPtr; Item : INTEGER);

VAR
 the_rect : Rect; the_handle: handle; the_type: INTEGER;
 save_state: PenState;
BEGIN
GetDItem (dlg,item,the_type,the_handle,the_type);
GetPenState (save_state);
PenMode (patBic);
PenPat(gray);
PaintRect (the_rect);
SetPenState (save_state);
END;

Make sure that the user item is getting drawn AFTER the static text!

>2) Is there a good way to right align the text in an editText item?
>     [ ... MORE ....]

This seems too easy, and maybe I am wrong, but why not doing this :


with DialogPeek (the_dialog)^.textH^^ do begin
  just:=teJustRight;
  destRect:=the_rect; { the item rect }
  viewRect:=the_rect;
END; { of WITH }

Note that you will have to call this code whenever the user selects a new
TE or types in it.


-------

Eran Reshef,
Micro Department, Computation Center,
Ben-Gurion University of the Negev,
Beer - Sheva, Israel.

Bitnet : RESHEF1@BGUVM.BITNET

                    "Vanity of vanities, all is vanity"