NSOpenPanel over fullscreen NSWindow?

I open a window with the following:

NSRect screenRect = [[NSScreen mainScreen] frame];
[super initWithContentRect:screenRect 
               styleMask:NSBorderlessWindowMask 
                 backing:NSBackingStoreBuffered 
                   defer:NO]; 
int windowLevel = CGShieldingWindowLevel();
[self setLevel:windowLevel];

... therefore the window is full-screen and, above all, other window levels (including modal windows). Later, I want to display an open panel, however the following opens a dialog box below the window that I created above (it seems that the runModal element overrides the requested level of the window that I am trying to set):

  NSOpenPanel *OP = [NSOpenPanel openPanel];      
  int windowLevel = CGShieldingWindowLevel();
  [OP setLevel:windowLevel];
  int returnCode = [OP runModal];

... and the following opens the sheet in the window created above (good), however, it also completes the display of the menu bar that I previously hid (not what I want):

  NSOpenPanel *OP = [NSOpenPanel openPanel];      
  [OP beginSheetModalForWindow:[self window]
             completionHandler:^(NSInteger returnCode) {
               NSLog(@"completionHandler called with %d", returnCode);
             }];

... so my questions are:

  • Does anyone know how to open a modal window above CGShieldingWindowLevel?
  • Is there a way to make the menu bar not appear on the sheet solution I'm trying to do above?

Thanks to everyone :-)

+3
3

, - , :

NSOpenPanel *OP = [NSOpenPanel openPanel];
[OP setLevel:CGShieldingWindowLevel()];
[OP beginWithCompletionHandler:^(NSInteger returnCode) {
  NSLog(@"completionHandler called with %d", returnCode);
}];

... ie: , , (duh!)

+3

NSSavePanel :

@implementation NSSavePanel (SavePanelSetLevel)

- (void)setLevel:(NSInteger)newLevel
{
    [super setLevel:CGShieldingWindowLevel()] ; // NSWindow implementation call
}

@end

runModal reset !

+3

, 5 , - , , CGShieldingWindowLevel, , - , , , , , . :

  NSOpenPanel *OP = [NSOpenPanel openPanel];

  // this is the new bit - make the window 1x1 @ the location of your liking
  NSRect windowRect = NSMakeRect(0, 1000, 1, 1);
  NSWindow *OPW = [[NSWindow alloc] initWithContentRect:windowRect 
                                              styleMask:NSBorderlessWindowMask 
                                                backing:NSBackingStoreBuffered 
                                                  defer:NO];  
  int windowLevel = CGShieldingWindowLevel();
  [OPW setLevel:windowLevel];
  [OPW makeKeyAndOrderFront:nil];
  // end of new bit, apart from passing OPW for beginSheetModalForWindow
  // instead of [self window]

  [OP beginSheetModalForWindow:OPW
             completionHandler:^(NSInteger returnCode) {
               NSLog(@"completionHandler called with %d", returnCode);
             }];

... the only thing to consider is that below you can open several open dialog boxes, since the sheet is modal for a window other than the main window - the main window can still accept a mouse click of the event ...

+2
source

Source: https://habr.com/ru/post/1726267/


All Articles