Re: Help to understand how do events work
Re: Help to understand how do events work
- Subject: Re: Help to understand how do events work
- From: Raleigh Ledet <email@hidden>
- Date: Thu, 7 Oct 2010 10:53:48 -0700
On Oct 6, 2010, at 4:39 AM, eveningnick eveningnick wrote:
> Hello!
> I have created a cocoa application that has unusual behavior: it has a
> window (NSPanel), which does not activate the application, when it's
> clicked. This window is ordered always on top of the other windows. So
> it's like a "tooltip" window (basically it is a popup thing, that
> drops down when a user types some combination of symols in another
> application - which is a texteditor).
> Anyway, i did it as following:
> NSPanel *popupWindow = [[NSPanel alloc]
> initWithContentRect:NSMakeRect(100,100,300,100)
> styleMask:NSNonactivatingPanelMask | NSTitledWindowMask
> backing:NSBackingStoreBuffered defer:NO];
> [popupWindow setLevel:NSPopupMenuWindowLevel];
>
> then i am showing it:
> [popupWindow makeKeyAndOrderFront:nil];
>
> This "window" behaves as expected: it is displayed on top of all
> others, even if it's Application (in Dock, for ex) is not active. It
> also dispatches all the clicks on controls (like NSPushButton's) to
> these controls.
>
> The problem for me is that i want to receive keyDown events with it.
> But i am not sure if it is possible: in Apple documentation i found
> that NSWindow (and NSPanel therefore) have keyDown method (that i
> tried to override, having created a child class from NSPanel). But in
> vain - this method is never called.
> Neither is called mouseDown. How do buttons on this "panel"
> successfully receive mouseDowns then, for example? Or, after i placed
> on this panel an NSPushButton, i have seen that its dropdown list's
> cursor is positioned according to the key pressed on a keyboard - this
> means it processes keyDowns as well. But how? Could i process these
> events (keyDown) too? Maybe i should make a child class of
> NSApplication and rewrite -run method, watching for keydowns? What is
> the "route" that events go in my case?
> Thanks for the help
Since you are explicitly making your window key, it your subclass should be having sendEvent called. Of course, there are some key equivalent checks that occur before the event is routed to the window. This is why key assignments on the buttons should work without you getting a sendEvent. If you put a NSTextField in your panel, can you type in it?
-raleigh
_______________________________________________
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