newbie:how to get the frontmost window but a key window

  • Hi,

    I'd like to know how to get the most front window below a key window
    (e.g.Find dialog).

    I've tried the following things but failed.

    1. call currentDocument of the sharedDocumentController and tried to
    get the window from the document.
        But the document returned by currentDocument was nil.

    2. call mainWindow of the sharedApplication. But the return object was
    nil.

    Thanks in advance.
    Norio Ota
  • Hi,

    What is the problem that you're really trying to solve here? Why do
    you need to find a window behind the key window that's not the main
    window? I suspect that we will be able to give you a better answer if
    we can understand what you're really trying to do.

    As an example, your real problem might not be that you need the
    ability to find a non-main window, but rather that the window you're
    trying to find *should* be main, but isn't. It's important to identify
    the correct problem to solve before attempting to find a solution.

    j o a r

    On Jan 10, 2008, at 8:15 PM, norio wrote:

    > Hi,
    >
    > I'd like to know how to get the most front window below a key window
    > (e.g.Find dialog).
    >
    >
    > I've tried the following things but failed.
    >
    > 1. call currentDocument of the sharedDocumentController and tried to
    > get the window from the document.
    > But the document returned by currentDocument was nil.
    >
    > 2. call mainWindow of the sharedApplication. But the return object
    > was nil.
    >
    >
    > Thanks in advance.
    > Norio Ota
  • Joar, thanks for your quick response.

    What I want to do is to search text from the window just below
    "Find..." dialog, like almost every text editor do.

    My app opens a window which doesn't have text input field at launch
    time. The window just displays something.

    Then open a document by selecting Open... from File menu. So you can
    open several windows. I thought they were main windows.

    And open Find.. window and when you press Find button on the window,
    text is being searched from the document of the window just below the
    Find window.

    With these steps, currentDocument and mainWindow return nil as I told
    in the previous mail.
    Who sets a window to main window? I went to see the inspector window
    of the window in IB but I couldn't get.

    I wish I could explain more clearly.

    Norio Ota

    On 2008/01/11, at 14:53, j o a r wrote:

    > Hi,
    >
    > What is the problem that you're really trying to solve here? Why do
    > you need to find a window behind the key window that's not the main
    > window? I suspect that we will be able to give you a better answer
    > if we can understand what you're really trying to do.
    >
    > As an example, your real problem might not be that you need the
    > ability to find a non-main window, but rather that the window you're
    > trying to find *should* be main, but isn't. It's important to
    > identify the correct problem to solve before attempting to find a
    > solution.
    >
    > j o a r
    >
    >
    > On Jan 10, 2008, at 8:15 PM, norio wrote:
    >
    >> Hi,
    >>
    >> I'd like to know how to get the most front window below a key
    >> window (e.g.Find dialog).
    >>
    >>
    >> I've tried the following things but failed.
    >>
    >> 1. call currentDocument of the sharedDocumentController and tried
    >> to get the window from the document.
    >> But the document returned by currentDocument was nil.
    >>
    >> 2. call mainWindow of the sharedApplication. But the return object
    >> was nil.
    >>
    >>
    >> Thanks in advance.
    >> Norio Ota
    >
  • On Jan 11, 2008, at 2:58 AM, norio wrote:

    > What I want to do is to search text from the window just below
    > "Find..." dialog, like almost every text editor do.

    This should be a standard key window <-> main window relationship
    between your document window and the find panel.

    > My app opens a window which doesn't have text input field at launch
    > time. The window just displays something.
    >
    > Then open a document by selecting Open... from File menu. So you can
    > open several windows. I thought they were main windows.

    And they typically would be. Or to be more precise, at any given time
    _one_ of them would be the main window of your application:

    <http://developer.apple.com/documentation/Cocoa/Conceptual/WinPanel/Concepts
    /ChangingMainKeyWindow.html
    >

    > And open Find.. window and when you press Find button on the window,
    > text is being searched from the document of the window just below
    > the Find window.
    >
    > With these steps, currentDocument and mainWindow return nil as I
    > told in the previous mail.
    > Who sets a window to main window? I went to see the inspector window
    > of the window in IB but I couldn't get.

    The main window is set automatically by AppKit as the user opens or
    switches between document windows. The same goes for the key window.
    This should work correctly out of the box.

    Some troubleshooting steps:

    * The basic requirement for this to work is that your document window
    is a type of window that assumes main status - typically NSWindow and
    subclasses thereof, but not including NSPanel. Likewise, your panels
    should be of a type that doesn't assume main window status, like
    NSPanel (or subclasses thereof).

    * Sign up for and log the NSWindow key / main notifications to track
    how key & main window status changes while you work with your
    application. To do this, add notification registration to one of your
    shared controller objects:

               [[NSNotificationCenter notificationCenter] addObserver: self
                                                selector:
    @selector(windowDidBecomeKey:)
                                                    name:
    NSWindowDidBecomeKeyNotification
                                                  object: nil];

    A good place for signing up for notifications is "awakeFromNib". Also
    implement the corresponding callback method:

    - (void) windowDidBecomeKey:(NSNotification *) notification
    {
      NSWindow *window = [notification object];
      NSLog(@"WindowDidBecomeKey: %@, (Title: \"%@\", Delegate: %@)",
    window, [window title], [window delegate]);
    }

    ...and repeat for all relevant notifications:

    (NSWindowDidBecomeKeyNotification)
    NSWindowDidBecomeMainNotification
    NSWindowDidResignKeyNotification
    NSWindowDidResignMainNotification

    Try opening, closing and switching between your application windows
    and panels and verify that the key and main status changes as you
    would expect.

    j o a r
previous month january 2008 next month
MTWTFSS
  1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31      
Go to today