Forum > Cocoa

[Solved] menu not accessible after window creation osx

(1/3) > >>

Key-Real:
I create a window:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} --- var   window:NSWindow;   screenwidth,screenheight:dword; type     TCocoaAppDelegate = objcclass (NSObject, NSApplicationDelegateProtocol)    end;     TCocoaApp = objcclass (NSApplication)      procedure poll; message 'poll';  end;    TCocoaWindow = objcclass (NSWindow)        function initWithContentRect_styleMask_backing_defer (contentRect: NSRect; aStyle: NSUInteger; bufferingType: NSBackingStoreType; flag: boolean): id; message 'initWithContentRect:styleMask:backing:defer:';    procedure dealloc; override;      function windowShouldClose (notification: NSNotification):boolean; message 'windowShouldClose:';    procedure screenParametersChanged (notification: NSNotification); message 'screenParametersChanged:';    end;    procedure TCocoaWindow.screenParametersChanged (notification: NSNotification);var theframe:NSRect;begin   theframe := NSMakeRect(0,0,screenwidth,screenheight); // NSScreen.mainScreen.frame;    setFrame_display(theframe, true);end; function TCocoaWindow.windowShouldClose (notification: NSNotification):boolean;begin  gfxDone:=true;  result:=true;end;  procedure TCocoaWindow.dealloc;begin  NSNotificationCenter.defaultCenter.removeObserver(self);  inherited dealloc;end;  function TCocoaWindow.initWithContentRect_styleMask_backing_defer (contentRect: NSRect; aStyle: NSUInteger; bufferingType: NSBackingStoreType; flag: boolean): id;begin  result := inherited initWithContentRect_styleMask_backing_defer(contentRect, aStyle, bufferingType, flag);  if result <> nil then    NSNotificationCenter(NSNotificationCenter.defaultCenter).addObserver_selector_name_object(result, objcselector('screenParametersChanged:'), NSApplicationDidChangeScreenParametersNotification, nil);end;   procedure TCocoaApp.poll;var  event: NSEvent;  pool: NSAutoreleasePool;  myType:longint;  mySendEvent : boolean;  myKeyCode:longint;  myMouseX,myMouseY:longint;begin  pool := NSAutoreleasePool.alloc.init;  event := nextEventMatchingMask_untilDate_inMode_dequeue(NSAnyEventMask, {NSDate.distantPast}nil, NSDefaultRunLoopMode, true);    if event<>nil then begin      fillchar(gfxMessanger^,sizeof(longint)*4,0);       myType:=event.type_;       mySendEvent:=true;       if (myType = NSKeyDown) or (myType = NSKeyUp) then begin myKeyCode:=event.keycode; mySendEvent:=false; end;      if myType = NSMouseMoved then myMouseX:=round(event.locationInWindow.x);      if myType = NSMouseMoved then myMouseY:=round(vscreen.height-event.locationInWindow.y);       system.move(myType,gfxMessanger^,sizeof(longint));      system.move(myKeyCode,(gfxMessanger+sizeof(longint))^,sizeof(longint));      system.move(myMouseX,(gfxMessanger+sizeof(longint)*2)^,sizeof(longint));      system.move(myMouseY,(gfxMessanger+sizeof(longint)*3)^,sizeof(longint));       if mySendEvent then begin        sendEvent(event);        updateWindows;      end;     end;    pool.release;end;      procedure cocoaCreateWindow(width,height:dword;title:string;fullscreen:boolean);var  windowFlags: NSUInteger = 0;  frame:NSRect;   bar : NSMenu;  appmenu:NSMenu;  menuItem: NSMenuItem;begin screenwidth:=width;screenheight:=height;  // frame := NSMakeRect(0,0,NSScreen.mainScreen.frame.size.width,NSScreen.mainScreen.frame.size.height); frame := NSMakeRect(0,0,screenwidth,screenheight);  if fullscreen then windowFlags:=NSBorderlessWindowMask;if not fullscreen then windowFlags:=NSTitledWindowMask or NSClosableWindowMask; // or NSMiniaturizableWindowMask; //or NSResizableWindowMask;   window := TCocoaWindow.alloc.initWithContentRect_styleMask_backing_defer(frame,windowFlags,NSBackingStoreBuffered,false);    window.setTitle(NSSTR(title));   if fullscreen then window.setCollectionBehavior(NSWindowCollectionBehaviorStationary or NSWindowCollectionBehaviorCanJoinAllSpaces or NSWindowCollectionBehaviorFullScreenPrimary  );if not fullscreen then window.setCollectionBehavior(NSWindowCollectionBehaviorManaged);  if fullscreen then window.toggleFullscreen(nil);  if fullscreen then NSApp.setPresentationOptions(NSApplicationPresentationFullScreen or  NSApplicationPresentationHideDock or NSApplicationPresentationHideMenuBar);if not fullscreen then NSApp.setPresentationOptions(NSApplicationPresentationDefault);     window.makeKeyAndOrderFront(nil); window.setAcceptsMouseMovedEvents(true); end;   procedure Cocoa_PollEvents;begin  TCocoaApp(TCocoaApp.sharedApplication).poll;  //NSApp.performSelectorOnMainThread_withObject_waitUntilDone(objcselector('poll'), nil, true);end;    procedure CocoaInit;var  app: TCocoaApp;  delegate: TCocoaAppDelegate;begin  app := TCocoaApp(TCocoaApp.sharedApplication);  delegate := TCocoaAppDelegate.alloc.init;  app.setDelegate(delegate);   NSApp.setActivationPolicy(NSApplicationActivationPolicyRegular);  NSApp.activateIgnoringOtherApps(true);  NSApp.finishLaunching;end;     procedure CocoaClose;begin window.close; Cocoa_PollEvents;end;  It is possible to switch in fullscreen mode with this code, but i mean window mode.

The window ist shown. But If i click on the menu (the apple menu at the top of the Screen) it does not react. I have to click away from my created window or click on another App, and when i select my window again now i can access the menu.

What to do?

trev:
Can you attach a minimal compilable project showing the issue? (Use Lazarus > Project > Publish Project).

Key-Real:
Here the minimal compilable program:


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---{$MODE OBJFPC}{$modeswitch objectivec1}uses CocoaAll, ctypes, MacOSAll, sysutils; var   window:NSWindow;   done:boolean = false;  type     TCocoaAppDelegate = objcclass (NSObject, NSApplicationDelegateProtocol)    end;     TCocoaApp = objcclass (NSApplication)      procedure poll; message 'poll';    end;      TCocoaWindow = objcclass (NSWindow)      function initWithContentRect_styleMask_backing_defer (contentRect: NSRect; aStyle: NSUInteger; bufferingType: NSBackingStoreType; flag: boolean): id; message 'initWithContentRect:styleMask:backing:defer:';      procedure dealloc; override;        function windowShouldClose (notification: NSNotification):boolean; message 'windowShouldClose:';    end;  function TCocoaWindow.windowShouldClose (notification: NSNotification):boolean;begin  done:=true;  result:=true;end;  procedure TCocoaWindow.dealloc;begin  NSNotificationCenter.defaultCenter.removeObserver(self);  inherited dealloc;end;  function TCocoaWindow.initWithContentRect_styleMask_backing_defer (contentRect: NSRect; aStyle: NSUInteger; bufferingType: NSBackingStoreType; flag: boolean): id;begin  result := inherited initWithContentRect_styleMask_backing_defer(contentRect, aStyle, bufferingType, flag);  if result <> nil then    NSNotificationCenter(NSNotificationCenter.defaultCenter).addObserver_selector_name_object(result, objcselector('screenParametersChanged:'), NSApplicationDidChangeScreenParametersNotification, nil);end;  procedure TCocoaApp.poll;var  event: NSEvent;  pool: NSAutoreleasePool;begin  pool := NSAutoreleasePool.alloc.init;  event := nextEventMatchingMask_untilDate_inMode_dequeue(NSAnyEventMask, {NSDate.distantPast}nil, NSDefaultRunLoopMode, true);   if event<>nil then begin      sendEvent(event);      updateWindows;  end;   pool.release;end;  procedure CocoaCreateWindow(width,height:dword;title:string);var  windowFlags: NSUInteger = 0;  frame:NSRect;begin frame := NSMakeRect(0,0,width,height);  windowFlags:=NSTitledWindowMask or NSClosableWindowMask; // or NSMiniaturizableWindowMask; //or NSResizableWindowMask; window := TCocoaWindow.alloc.initWithContentRect_styleMask_backing_defer(frame,windowFlags,NSBackingStoreBuffered,false);  window.setTitle(NSSTR(title));  window.setCollectionBehavior(NSWindowCollectionBehaviorManaged); NSApp.setPresentationOptions(NSApplicationPresentationDefault);  window.makeKeyAndOrderFront(nil); window.setAcceptsMouseMovedEvents(true);end;  procedure CocoaPollEvents;begin  TCocoaApp(TCocoaApp.sharedApplication).poll;end;  procedure CocoaInit;var  app: TCocoaApp;  delegate: TCocoaAppDelegate;begin  app := TCocoaApp(TCocoaApp.sharedApplication);  delegate := TCocoaAppDelegate.alloc.init;  app.setDelegate(delegate);   NSApp.setActivationPolicy(NSApplicationActivationPolicyRegular);  NSApp.activateIgnoringOtherApps(true);  NSApp.finishLaunching;end;  procedure CocoaClose;begin window.close; CocoaPollEvents;end;    begin CocoaInit; CocoaCreateWindow(640,480,'test');  repeat  CocoaPollEvents; until done;  CocoaClose;end. 

Key-Real:
I tested whis Code on
MacOS 10.13.4 (Intel)
MacOS 11.6 (Aarch64)
MacOS 12.2.1 (Intel)
All Same behaviour.

Is this an Apple Bug?
Or is the code wrong?

trev:
Your program does not compile:


--- Quote ---Free Pascal Compiler version 3.3.1 [2022/01/07] for aarch64
Copyright (c) 1993-2021 by Florian Klaempfl and others
Target OS: Darwin for AArch64
Compiling project1.pas
project1.pas(21,16) Error: Inherited methods can only be overridden in Objective-C and Java, add "override" (inherited method defined in NSWindow)
project1.pas(128) Fatal: There were 1 errors compiling module, stopping
Fatal: Compilation aborted
Error: /usr/local/bin/ppca64 returned an error exitcode
--- End quote ---

Navigation

[0] Message Index

[#] Next page

Go to full version