• 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: Modal dialog without NSApplication
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Modal dialog without NSApplication


  • Subject: Re: Modal dialog without NSApplication
  • From: Rob Keniger <email@hidden>
  • Date: Sat, 20 Sep 2008 11:44:22 +1000


On 19/09/2008, at 2:41 AM, brodhage wrote:

I allready do. And then I call this function (within subclass of NSWindowController):

- (void)showModalDialog
{
	NSApplication *_app;
	NSWindow *_window;

	[self showWindow:nil];
	_app = [NSApplication sharedApplication];
	_window = [self window];
	[_app runModalForWindow:_window];
}

The modal dialog (displayed this way) blocks everything - it is not possible to close the modal dialog, hit any button or something else.

For me it seems that the NSApplication:: runModalForWindow blocks all.
So what I am searching for is to display the modal dialog without NSApplication.


I am successfully using modal Cocoa windows in a plugin inside a Carbon application.

Others have already spoken about the need for NSApplicationLoad() and setting up an autorelease pool, you definitely have to do both these things.

To display the window I do this:

//show the window
[window makeKeyAndOrderFront:nil];

//start a modal session and wait for a response
NSModalSession session = [NSApp beginModalSessionForWindow:window];
NSInteger response;
for (;;) {
	response=[NSApp runModalSession:session];
	if (response != NSRunContinuesResponse)
		break;
	//
}

//when the user exits the window, hide the window
[NSApp endModalSession:session];
[window close];

You can hook up your OK/cancel buttons something like this:

-(IBAction) ok: (id)sender
{
	[NSApp stopModal];
}
-(IBAction) cancel: (id)sender
{
	[NSApp abortModal];
}

You can then test for the return value of the NSModalSession and do whatever you want with the results.

--
Rob Keniger



_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Modal dialog without NSApplication
      • From: brodhage <email@hidden>
References: 
 >Re: Modal dialog without NSApplication (From: brodhage <email@hidden>)

  • Prev by Date: Re: NSOperationQueue
  • Next by Date: Re: Modal dialog without NSApplication
  • Previous by thread: Re: Modal dialog without NSApplication
  • Next by thread: Re: Modal dialog without NSApplication
  • Index(es):
    • Date
    • Thread