RE: Progress bar on front NSPanel is grey not blue??

  • [This is an old thread, posting for the archives.]

    Synopsis:  using a NSPanel to show a message and a determinate
    progress indicator results in the progress bar drawing in grey
    instead of Aqua.

    This happens if the window is not key.

    PGM in the original thread had the solution, and it's also touched on
    in NSWindow's class description:

    Returns YES if the receiver can become the key window, NO if it can't.

    - (BOOL)canBecomeKeyWindow
    Attempts to make the receiver the key window are abandoned if this
    method returns NO. NSWindow's implementation returns YES if the
    receiver has a title bar or a resize bar, NO otherwise.

    Now, my custom panel had a single overridden method:

    - (id) initWithContentRect:(NSRect)contentRect styleMask:(unsigned
    int)styleMask backing:(NSBackingStoreType)bufferingType
      return [ super initWithContentRect:contentRect
    styleMask:NSBorderlessWindowMask backing:bufferingType

    to set the style to borderless, so of course it then cannot normally
    become key.

    What I ended up doing is use a single additional override (alluded to by PGM):

    - (BOOL) isKeyWindow
      return YES;

    Once added, the panel now displays an Aqua colored progress bar.

  • Am 19.10.2007 um 22:24 schrieb David Hoerl:
    > - (BOOL) isKeyWindow
    > {
    > return YES;
    > }
    > Once added, the panel now displays an Aqua colored progress bar.

      I haven't tested this, but I think you'd really want to override
    canBecomeKeyWindow, not isKeyWindow. The former means your window can
    become the key view when the user designates it as such (by clicking
    or using Cmd-~ or whatever). If you override the latter, you're
    effectively lying to everyone about your window.

      So, in general, you want to override canBecomeMain or canBecomeKey,
    not isMainWindow or isKeyWindow.

    -- M. Uli Kusterer
  • I stand corrected by Uli!

    What also works, and is probably a much better solution, is to return
    YES in your NSPanel subclass' "canBecomeKey" method, then command the
    panel with [myPanel makeKeyAndOrderFront]. I just tested this
    (without the -isKeyWindow hack) and it works just fine (progress bar
    has an Aqua tint).

previous month october 2007 next month
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