FROM : Daniel Jalkut
DATE : Sat Nov 05 07:42:44 2005
Hi Justin. I face a similar situation in FastScripts: putting up UI
is not sufficient for gaining "frontmost" status.
What I do is very carefully acquire frontmost status and then give it
back when I'm done. Since for your app it seems like you need it
every time the user invokes the "menu" item, it shouldn't be too
complicated. In FastScripts since I only steal frontmost status when
a dialog needs to be displayed, I have a set of convenience methods I
use:
- (void) activateGracefully
{
// First, do we even need to activate?
if ([NSApp isActive] == NO)
{
GetFrontProcess(&_activeApp);
_interruptedOtherApp = YES;
// Make ourselves frontmost!
[NSApp activateIgnoringOtherApps:YES];
}
}
- (void) deactivateGracefully
{
// Always deactivate ourself if we are active
if ([NSApp isActive] == YES)
{
[NSApp deactivate];
// If we interrupted somebody when we last activated, then
// kindly reactivate them
if (_interruptedOtherApp == YES)
{
SetFrontProcess(&_activeApp);
}
}
_interruptedOtherApp = NO;
}
If you called "activateGracefully" just before displaying your
window, and "deactivateGracefully" just after, you might see a very
satisfactory behavior. (You'll need to define the instance variables
_activeApp and _interruptedOtherApp).
Daniel
On Nov 5, 2005, at 1:17 AM, Justin Williams wrote:
> Greetings,
>
> I am adding keyboard access to my menu bar based to-do list
> application so that users can bring the application forward no
> matter what application they are in.
>
> When the user presses their hot key or clicks the menu bar icon to
> launch the application, the application launches as it should and
> posts a notification letting me know that the window has
> application's main window has dropped down.
>
> From here the user should be able to use the arrow keys to navigate
> the outline view and manipulate data. Unfortunately, the previous
> application they were working in still has the focus of the keyboard.
>
> When the notification posts letting me know the main window has
> dropped this code is executed:
>
> -(IBAction)checkOffActivated:(id)sender {
> [oWindow makeKeyAndOrderFront:self];
> [oOutlineView selectRow:1 byExtendingSelection:YES];
> }
>
> While the row is selected in my column view, the oWindow window
> still doesn't have the focus of the keyboard until I click the
> mouse on it. If you would like to see this in action (its
> somewhat difficult to explain) you can download this beta of the
> application:
>
> http://www.carpeaqua.com/co35a1.zip
>
> To summarize, I don't understand why calling makeKeyAndOrderFront
> isn't giving my window the focus as it should.
>
> Any suggestions are welcomed. Thanks.
>
> __________________________________________________
> Justin Williams <email_removed>
> work: www.maczealots.com play: www.carpeaqua.com
>
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Cocoa-dev mailing list (<email_removed>)
> Help/Unsubscribe/Update your Subscription:
> http://lists.apple.com/mailman/options/cocoa-dev/<email_removed>-
> sweater.com
>
> This email sent to <email_removed>
DATE : Sat Nov 05 07:42:44 2005
Hi Justin. I face a similar situation in FastScripts: putting up UI
is not sufficient for gaining "frontmost" status.
What I do is very carefully acquire frontmost status and then give it
back when I'm done. Since for your app it seems like you need it
every time the user invokes the "menu" item, it shouldn't be too
complicated. In FastScripts since I only steal frontmost status when
a dialog needs to be displayed, I have a set of convenience methods I
use:
- (void) activateGracefully
{
// First, do we even need to activate?
if ([NSApp isActive] == NO)
{
GetFrontProcess(&_activeApp);
_interruptedOtherApp = YES;
// Make ourselves frontmost!
[NSApp activateIgnoringOtherApps:YES];
}
}
- (void) deactivateGracefully
{
// Always deactivate ourself if we are active
if ([NSApp isActive] == YES)
{
[NSApp deactivate];
// If we interrupted somebody when we last activated, then
// kindly reactivate them
if (_interruptedOtherApp == YES)
{
SetFrontProcess(&_activeApp);
}
}
_interruptedOtherApp = NO;
}
If you called "activateGracefully" just before displaying your
window, and "deactivateGracefully" just after, you might see a very
satisfactory behavior. (You'll need to define the instance variables
_activeApp and _interruptedOtherApp).
Daniel
On Nov 5, 2005, at 1:17 AM, Justin Williams wrote:
> Greetings,
>
> I am adding keyboard access to my menu bar based to-do list
> application so that users can bring the application forward no
> matter what application they are in.
>
> When the user presses their hot key or clicks the menu bar icon to
> launch the application, the application launches as it should and
> posts a notification letting me know that the window has
> application's main window has dropped down.
>
> From here the user should be able to use the arrow keys to navigate
> the outline view and manipulate data. Unfortunately, the previous
> application they were working in still has the focus of the keyboard.
>
> When the notification posts letting me know the main window has
> dropped this code is executed:
>
> -(IBAction)checkOffActivated:(id)sender {
> [oWindow makeKeyAndOrderFront:self];
> [oOutlineView selectRow:1 byExtendingSelection:YES];
> }
>
> While the row is selected in my column view, the oWindow window
> still doesn't have the focus of the keyboard until I click the
> mouse on it. If you would like to see this in action (its
> somewhat difficult to explain) you can download this beta of the
> application:
>
> http://www.carpeaqua.com/co35a1.zip
>
> To summarize, I don't understand why calling makeKeyAndOrderFront
> isn't giving my window the focus as it should.
>
> Any suggestions are welcomed. Thanks.
>
> __________________________________________________
> Justin Williams <email_removed>
> work: www.maczealots.com play: www.carpeaqua.com
>
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Cocoa-dev mailing list (<email_removed>)
> Help/Unsubscribe/Update your Subscription:
> http://lists.apple.com/mailman/options/cocoa-dev/<email_removed>-
> sweater.com
>
> This email sent to <email_removed>
| Related mails | Author | Date |
|---|---|---|
| Justin Williams | Nov 5, 07:17 | |
| Daniel Jalkut | Nov 5, 07:42 | |
| Daniel Jalkut | Nov 5, 07:54 | |
| Justin Williams | Nov 5, 16:02 | |
| John Stiles | Nov 6, 01:28 | |
| Daniel Jalkut | Nov 6, 01:33 | |
| John Stiles | Nov 6, 06:38 | |
| Daniel Jalkut | Nov 6, 08:19 |






Cocoa mail archive

