• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Two sheets related questions
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Two sheets related questions


  • Subject: Re: Two sheets related questions
  • From: Erik Buck <email@hidden>
  • Date: Mon, 11 Jul 2005 20:13:26 -0400

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


  • Follow-Ups:
    • Re: Two sheets related questions
      • From: Huibert Aalbers <email@hidden>
  • Prev by Date: Re: SOAP Handler question
  • Next by Date: Re: Two sheets related questions
  • Previous by thread: Two sheets related questions
  • Next by thread: Re: Two sheets related questions
  • Index(es):
    • Date
    • Thread