[comp.sys.mac.programmer] Basic DLOG/DITL question

dave@PRC.Unisys.COM (David Lee Matuszek) (04/15/91)

OK, I'm missing something really fundamental here.

I have a very simple application, with a DLOG 128 whose DITL ID is set
to 128.  It's initially visible and is purgeable.  This is my only
window.

I have a DITL 128.  It has three static texts, two editable texts, 11
radio buttons, an OK button, and an icon.  It's purgeable.  Both these
resources were created with ResEdit 2.1.

In THINK Pascal 3.0 I call

	myDialog := GetNewDialog(128, nil, WindowPtr(-1));

and the DLOG window appears.  But nothing appears in the window.

When I call

	GetDItem(myDialog, editText1, itemType, itemHandle, itemRect);
	SetIText(itemHandle, myString);

the appropriate editable text item appears.  For the radio buttons,
when I call

	GetDItem(myDialog, radioButton4, itemType, itemHandle, itemRect);
	SetCtlValue(ControlHandle(itemHandle), 1)

the radio button appears, but if I call SetCtlValue with 0 instead of
1, it doesn't.

If I call

	DrawControls(myDialog);

this makes all the radio buttons and the one button appear, but does
not make the static or editable text items or the icon appear.

Here's where it gets weird.  If the radio buttons are visible and I call

	HideDItem(myDialog, radioButton4)

then the indicated radio button disappears; and when I call

	ShowDItem(myDialog, radioButton4)

it stays gone.  (DrawControls will bring it back, though.)

(Note:  editText1 and radioButton4 are small integers, in the range
1..18, corresponding to the DITL item numbers.)

Enabling or disabling the various controls should have no effect, and
in fact it does not.

I know I'm doing something really stupid here; I recognize the
symptoms of a dumb mistake.  Unfortunately the fact does not help me
figure out what it is.  As near as I can tell, the connection between
the DLOG and the DITL is not being made properly, but it sure looks OK
in ResEdit 2.1.

Help?  [PLEASE don't assume someone else will answer; I don't mind
getting lots of e-mail, but I dread getting none.]

P.S.  MacIIsi, System 6.0.7.


-- Dave Matuszek (dave@prc.unisys.com)  I don't speak for my employer. --
-------------------------------------------------------------------------
|   When I was young, my family bought a color TV.  Our neigbors, who   |
| were poorer, had only a black-and-white set.  They bought a piece of  |
| cellophane, red on top, yellow in the middle, and blue on the bottom, |
| and taped it over their screen, so they could claim that they had a   |
| color TV, too.                                                        |
|   Now there's Windows 3.0.                                            |
-------------------------------------------------------------------------

stevec@Apple.COM (Steve Christensen) (04/17/91)

dave@PRC.Unisys.COM (David Lee Matuszek) writes:
>OK, I'm missing something really fundamental here.
>
>[...explains that he has a DLOG and a DITL with buttons and stuff...]
>
>In THINK Pascal 3.0 I call
>
>	myDialog := GetNewDialog(128, nil, WindowPtr(-1));
>
>and the DLOG window appears.  But nothing appears in the window.
>
>[...talks about changing text items and drawing buttons and only they show
>  up...]

What you're missing is that just because you now have a dialog, it's not
going to automatically draw all the stuff in the window.  Calling GetNewDialog
just causes the dialog's window to appear (if it's visible).  To cause the
items to be drawn and to handle clicking on buttons, you need to call
ModalDialog() or IsDialogEvent()/DialogSelect(), depending on if your dialog
is modal or not.  For the modal case, you could do something like this:

	myDialog := GetNewDialog(128, nil, WindowPtr(-1));
	IF myDialog <> nil THEN BEGIN
	  REPEAT
	    ModalDialog(nil, itemHit);
	    CASE itemHit OF
	      ...  {handle any enabled items as you wish}
	    END;
	  UNTIL itemHit = OK;
	  DisposDialog(myDialog);
	END;

This is the kind of thing you'd do when someone selects a menu item, for
example, and you want to let them tweak some stuff, click OK, and let the
changes take effect.  If you want to have a moveable dialog where you can
click on menus, other windows, etc., you need to do something like this:

	REPEAT
	  IF GetNextEvent(EveryEvent, myEvent) THEN BEGIN
	    ...  {do any pre-processing here, i.e., clicks in the menu bar}
	    IF IsDialogEvent(myEvent) THEN
	      IF DialogSelect(myEvent, theDialog, itemHit) THEN
	        CASE itemHit OF
	          ...  {handle any enabled items as you wish}
	        END;
	  END;
	UNTIL FALSE;

ModalDialog essentially has this code built into it, but you're stuck there
until the user does something.  Check out the Dialog Manager chapter of
Inside Macintosh, volume 1 for more detailed info...

steve

-- 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  Steve Christensen			Never hit a man with glasses.
  stevec@apple.com			Hit him with a baseball bat.