RE: Modal Window for NSTextField
RE: Modal Window for NSTextField
- Subject: RE: Modal Window for NSTextField
- From: Dany Golubitsky <email@hidden>
- Date: Mon, 02 Jan 2012 10:22:58 -0500
- Acceptlanguage: en-US
- Thread-topic: Modal Window for NSTextField
Thank you!
As for field editor - can it appear and disappear during runtime? Indeed, I do not familiar with this approach.
About beginSheetModalForWindow - indeed, I tried to do the following either:
[textField beginSheet:[textField window] ModalForWindow:[superView window] modalDelegate:superView didEndSelector:0 contextInfo:0];
and yes, I implemented endSheet. I tried to call endSheet from mouseDown event. I saw this function being called, however still, the white window was not closed and I was stuck in beginSheet (The code after it was unreachable).
Can you suggest why?
-----Original Message-----
From: Michael Babin [mailto:email@hidden]
Sent: Monday, January 02, 2012 16:10
To: Dany Golubitsky
Cc: email@hidden
Subject: Re: Modal Window for NSTextField
On Jan 2, 2012, at 6:02 AM, Dany Golubitsky wrote:
> I need to implement the following thing:
> There is a control displaying numeric value. When you Double-Click on a control small white window appears where you can enter the value, and when you press enter the value will be updated.
> You can see this screenshot (Ignore the fact it is from Windows 7):
>
> http://i31.fastpic.ru/big/2012/0102/5e/3d39b295e3dc2642ff1d0f240da0c95
> e.png
What you are trying to implement sounds very similar to the standard field editor used in Cocoa (http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/TextEditing/Tasks/FieldEditor.html).
If you aren't familiar with it, I'd advise taking some time to investigate it and see if you can adapt it to your needs. Even if not, the description of how it works (integration with responder chain, delegate methods) should prove useful. I would recommend it over the approach of trying to force application or window modal operation.
> Here is the code. I do it not within the main view but from the side function. The superView is the main view.
>
> NSRect textRect = NSMakeRect(in_location.m_x, in_location.m_y, in_size.m_x, in_size.m_y);
> NSTextField* textField = [[NSTextField alloc] initWithFrame:textRect];
>
> // Configure the text field
> [textField setEditable:YES];
> [textField setSelectable:YES];
> [textField setWantsLayer:YES];
> [textField setImportsGraphics:NO];
> [textField setBordered:NO];
> [textField setBezeled:NO];
> [textField setBackgroundColor:[NSColor whiteColor]]; [textField
> setDrawsBackground:YES]; [textField setTextColor:[NSColor
> blackColor]]; [textField setAllowsEditingTextAttributes:NO];
> [textField setAutoresizingMask:(NSUInteger)(NSViewWidthSizable +
> NSViewHeightSizable)];
>
> // Embed the text field in our plug-in view.
> [superView addSubview:textField];
> [superView setAutoresizesSubviews:YES];
>
> // Make the text field "in focus", and start an editing session on it
> [textField becomeFirstResponder];
>
> Now I tried 2 approaches:
>
> 1)
>
> *out_dismissedKey = [NSApp runModalForWindow:[textField window]];
> [textField removeFromSuperview]; [textField release];
>
> This one works. The text window gets all the events and I can get what I want. However, the windows order get screwed, meaning if there are couple of windows open in the same application the superView gets beyond other windows and I can not get it on front again.
Given the code, it looks like you're trying to force the window with the text field into an application modal "mode". Don't do this.
> So I tried the second approach - sheets:
>
> 2)
>
> [textField beginSheetModalForWindow:[superView window]
> modalDelegate:superView didEndSelector:0 contextInfo:0]; [textField
> removeFromSuperview]; [textField release];
>
> Now the problem here is that I am getting stuck in this function. The
> window is opened but neither Enter nor Escape do not close it. So the caller function can not continue, meaning I can not reach [textField removeFromSuperview].
So textField is an NSSavePanel or NSAlert? Those seem to be the only objects (other than more obscure objects like ABIdentityPicker) with beginSheetModalForWindow:modalDelegate:didEndSelector:contextInfo: methods.
I'll assume you meant - [NSApplication beginSheet:modalForWindow:modalDelegate:didEndSelector:contextInfo:]. It requires an endSheet call (delegate method? notification?) to exit. In any case, I would not recommend this approach either.
_______________________________________________
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