Re: Two sheets related questions
Re: Two sheets related questions
- Subject: Re: Two sheets related questions
- From: Huibert Aalbers <email@hidden>
- Date: Mon, 11 Jul 2005 19:29:01 -0500
Erick,
First let me thank you for replying so quickly and taking the time to
find a solution to my problem.
Regarding my first problem, I thought that it would be more elegant to
send an event because it would be processed independently of the
double-click event. However, your solution seems simple enough.
Regarding the second problem, I could not test your solution because
my day job requires me to use another OS, but I will test it later
today. I am not sure however that it will work. Have you tried your
solution with two or more documents opened at the same time (each with
their own sheet)?
Regards,
Huibert
On 7/11/05, Erik Buck <email@hidden> wrote:
> > I am writing an application that behaves like Keynote or Pages. When
> > the app starts a new document is opened whit a sheet that allows the
> > user to select a template from a list. Everything works fine except:
> >
> > 1) When a a template icon receives a double-click I can detect it but
> > I would like to simulate a click on the default button. I guess that
> > the bes way to do that is to use NSEvent's (NSEvent
> > *)keyEventWithType:(NSEventType)type... however there are so many
> > parameters in this function that I have not ben able to successfully
> > use it. Does anyone have a working example?
> >
> Please don't create fake events just to press a button! Call the
> action that the button calls. If worst comes to worst, use -
> performClick:
>
> NSControl
> "- (void)performClick:(id)sender
>
> Can be used to simulate a single mouse click on the receiver. sender
> is ignored. This method calls performClick: on the receiver's cell
> with the sender being the control itself. Raises an exception if the
> action message cannot be successfully sent."
>
>
> > 2) I have noticed that when I have a document with an open sheet in
> > Keynote I can press Cmd-Q to quit the app but in my case the Sheet
> > seems to consume the event. How can I pass it to the application?
> >
>
> First, let be say that I did not immediately know how to do this
> either. I just spent 15 minutes experimenting and this is what I
> came up with :)
>
> Add the following code (that I copied verbatim from http://
> developer.apple.com/documentation/Cocoa/Conceptual/Sheets/Tasks/
> UsingCustomSheets.html) to your document:
>
> - (void)showCustomSheet: (NSWindow *)window
> // User has asked to see the custom display. Display it.
> {
> if (!myCustomSheet)
> [NSBundle loadNibNamed: @"MyCustomSheet" owner: self];
>
> [NSApp beginSheet: myCustomSheet
> modalForWindow: window
> modalDelegate: self
> didEndSelector: @selector(didEndSheet:returnCode:contextInfo:)
> contextInfo: nil];
>
> // Sheet is up here.
> // Return processing to the event loop
> }
>
>
> - (IBAction)closeMyCustomSheet: (id)sender
> {
> [NSApp endSheet:myCustomSheet];
> }
>
>
> - (void)didEndSheet:(NSWindow *)sheet returnCode:(int)returnCode
> contextInfo:(void *)contextInfo
> {
> [sheet orderOut:self];
> }
>
>
> Also add this to your document:
>
> - (void)terminate:(id)dummy
> {
> [self closeMyCustomSheet:nil];
> [NSApp terminate:dummy];
> }
>
>
> In MyCustomSheet.nib, make sure file's owner is you document class.
> Make sure file's owner is the window's (sheet's) delegate. In
> MainMenu.nib, discoonect the quit menu item from NSApp terminate: and
> instead connect it to first responder terminate:
>
> Now, when the sheet is visible, the quit menu's action, terminate:,
> is sent down the responder chain. My virtue of being the sheet's
> delegate, your document will get a chance to handle the -terminate:
> and the code that closes the sheet and quits the application is called.
>
> I have a working sample project that I will email to anyone who
> requests it.
>
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Cocoa-dev mailing list (email@hidden)
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden
>
--
Viisit my home page at http://www.huibert-aalbers.com
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden