Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: how to "flash" the default OK button in a dialog?



hey Bryan,

thanks for the info. unfortunately i'm in the late stages of Carbonizing
a Classic app and the Dialog Manager is much too integrated into the
overall codebase to consider making this kind of drastic change at this
point (i don't want to break anything! =) so i'm going to be stuck w/
Dialog Manager for this release...i'm just working on cleaning up the
few remaining minor issues that are left to look into.

so, is the general idea then that i will NOT be able to get the default
button to flash when i use my own ModalFilterUPP? i.e. is switching to
the Carbon Event Manager the ONLY way that i will be able to get this to
work? if that is the case, then i guess it is not going to become a very
critical issue for me on this release.

TIA. -phil.

On Wednesday, February 27, 2002, at 11:20 PM, Bryan Pietrzak wrote:

> On Wednesday, February 27, 2002, at 10:41 PM, Phillip A. Kavan wrote:
>
>> well...that's already being done (in my dialogs, OK is always #1,
>> Cancel is always #2...i think those item #'s are assumed by default in
>> the Dialog Manager anyway...yes?). just calling SetDialogDefaultItem()
>> explicitly does not seem to fix this.
>>
>> to test, i set up a simple ModalFilterUPP to look like this:
>>
>> pascal Boolean myModalFilterProc( DialogRef dialog, EventRecord
>> *theEvent, SInt16 *itemHit )
>
>
> One recommendation...and forgive me if you're already familiar with all
> of this...
>
> If you have the luxury, dump the dialog manager and just use windows
> and controls. The only challenge here is instantiating windows and
> controls, but you can use NIBs to do that, or AuntieDialog to read in a
> DLOG and DITL and create a window and controls. Then you can use the
> modern Carbon Event method of dialog processing. It works really well,
> it's easy and it doesn't suffer the limitations of dialogs which are a
> dying breed and not as well supported by Carbon.
>
> To give you an idea of just how easy this is, here's some code:
>
>
> OSStatus DoSampleDialog(void)
> {
> GrafPtr savePort;
> WindowRef window;
>
> GetPort(&savePort);
>
> OSStatus error =
> CreateWindowFromDLOGResource(kMovableModalWindowClass,
> kWindowStandardHandlerAttribute, kSampleDialogID, &window);
>
> if (window != NULL)
> {
> GetNewControls(window, kSampleDialogControlsID);
>
> InstallEventHandlers(window);
>
> RepositionWindow(window, NULL,
> kWindowAlertPositionOnParentWindowScreen);
>
> ShowWindow(window);
> RunAppModalLoopForWindow(window);
>
> ReleaseWindow(window);
> }
>
> SetPort(savePort);
>
> return error;
> }
>
> static void InstallEventHandlers(WindowRef window)
> {
> static EventHandlerUPP controlUPP = NULL;
> static const EventTypeSpec controlEvents[] = { { kEventClassControl,
> kEventControlHit } };
>
>
> if (controlUPP == NULL)
> controlUPP = NewEventHandlerUPP(EventHandler);
>
> InstallControlEventHandler(GetControlByID(window,
> kSampleOKControlID), controlUPP, GetEventTypeCount(controlEvents),
> controlEvents, 0, NULL);
> }
>
> static pascal OSStatus EventHandler(EventHandlerCallRef handler,
> EventRef event, void* userData)
> {
> #pragma unused (handler, userData)
> ControlRef control;
>
> // only installed for the ok button, so we can just quit the modal
> window loop
>
> // we need to get the control, so we can get the window the control
> lives in
> GetEventParameter(event, kEventParamDirectObject, typeControlRef,
> NULL, sizeof(control), NULL, &control);
>
> QuitAppModalLoopForWindow(GetControlOwner(control));
>
> return noErr;
> }
>
> Now, I simplified the code down to just displaying the "dialog".
> Normally you might have to set some control data when creating the
> window and maybe get some data out when clicking the OK button, but
> that's trivial once you have the basic loop worked out.
>
> As I said, the only tricky thing is instantiating your window and
> control. In my cases, I use an approach I developed quite a while ago,
> long before Carbon. I layout my dialogs in Resourcerer using DLOG. But,
> I only use dialog item controls in the dialog, no "built-in" dialog
> items. I use this dialog to visually lay things out. Then I have a
> control list resource 'CTL#' that is simply a list of shorts
> representing the resource IDs of the controls used in the dialog.
>
> At runtime, I create a window by loading the DLOG resource and grabbing
> its bounds and title and then using CreateNewWindow to create the
> window.
>
> I then have a function (GetNewControls) that knows how to load a CTL#
> resource and calls GetNewControl on each resource ID. (There's some
> other stuff in GetNewControls to deal with control embedding and
> whatnot, but that's not relevant here).
>
>
> Regardless, if you make the move to windows and controls I guarantee
> once you figure out how you want to instantiate them, you'll never
> again want to use the dialog manager and "real" dialogs and dialog
> items.
>
>
> Bryan
>
---
Phillip A. Kavan <mailto:email@hidden>
_______________________________________________
carbon-development mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/carbon-development
Do not post admin requests to the list. They will be ignored.

References: 
 >Re: how to "flash" the default OK button in a dialog? (From: Bryan Pietrzak <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.