[comp.sys.mac.programmer] How to hilite

kk@mcnc.org (Krzysztof Kozminski) (07/16/90)

The subject says it almost all: I want to make the OK button inactive
in the standard file dialogs, in which I have sevaral additional
items.  Some values of these items make it illegal to save or open a
selected file.  Due to other considerations, I cannot just remove the
file name from the list, so I tried to hilite the Open/Save button to
255 from the dialog hook, but the SF package promptly reactivates it
with the resulting wild blinking.  So for now I just hide the button
and display a short explanation at the bottom of the dialog, but I
would like to do it more elegantly, i.e., keep the button where it is,
only inactive.  Any hints how to tell the SF package to keep off the
hiliting status of the default button?

Thanx in advance for any suggestions.

KK
-- 
Kris Kozminski   kk@mcnc.org
"The party was a masquerade; the guests were all wearing their faces."

tim@efi.com (Tim Maroney) (07/18/90)

In article <2418@speedy.mcnc.org> kk@mcnc.org.UUCP (Krzysztof Kozminski) writes:
>The subject says it almost all: I want to make the OK button inactive
>in the standard file dialogs, in which I have sevaral additional
>items.  Some values of these items make it illegal to save or open a
>selected file.  Due to other considerations, I cannot just remove the
>file name from the list, so I tried to hilite the Open/Save button to
>255 from the dialog hook, but the SF package promptly reactivates it
>with the resulting wild blinking.  So for now I just hide the button
>and display a short explanation at the bottom of the dialog, but I
>would like to do it more elegantly, i.e., keep the button where it is,
>only inactive.  Any hints how to tell the SF package to keep off the
>hiliting status of the default button?

You're almost there.  Hide the real OK button and trap return and enter
in your event filter.  Then put up a button called Open or Save in the
same place as the ordinary button, and control it yourself as desired.
If you want it enabled, then use the dialog item hook to turn clicks
on it into clicks on the hidden button.

Note that disabling can be confusing to the user, and if you can provide
(as you seem to be doing already) a brief explanation of why a particular
file can't be opened, you should.  Even better is to use the file filter
to exclude files you can't open, but this may not be general enough for
all applications.

oster@well.sf.ca.us (David Phillip Oster) (07/18/90)

Here is an example of disabling the OK button. See IM on SFGetFile for
more info.

#define INITPITEM	-1
#define DISABLE 255

/* GetCIHandle - return handle value of dialog item
 */
ControlHandle GetCIHandle(i)Integer i;{
	Integer theType;
	Handle theHandle;
	Rect theRect;

	GetDItem(thePort, i, &theType, &theHandle, &theRect);
	return (ControlHandle) theHandle;
}

/* OpenFilter - act on an item before SFPGetFile sees it.
 */
pascal Integer OpenFilter(i, dp)Integer i; DialogPtr dp;{
	GrafPtr savePort;
	Str255	s;

	switch(i){
	case INITPITEM :
		GetPort(&savePort);
		SetPort(dp);
		HilteControl(GetCIHandle(OK), DISABLE);
		SetPort(savePort);
		break;
	}
 	return i;
}

	SFGetFile(SFWhere(getDlgID), (StringPtr) "", NIL, 
		sizeof(types)/sizeof(OSType), (SFTypeList *) types, 
		(ProcPtr) OpenFilter, &reply);
-- 
-- David Phillip Oster - Note new address. Old one has gone Bye Bye.
-- oster@well.sf.ca.us = {backbone}!well!oster