Lazarus

Programming => Operating Systems => macOS / Mac OS X => Topic started by: ling on April 13, 2021, 11:58:05 am

Title: Is it possible to replace the Full Screen button with the Maximized button?
Post by: ling on April 13, 2021, 11:58:05 am
I don't want my project enter full screen mode, is it possible to replace the Full Screen button with the Maximized button?
Title: Re: Is it possible to replace the Full Screen button with the Maximized button?
Post by: Gustavo 'Gus' Carreno on April 13, 2021, 12:14:36 pm
Hey Ling,

I don't want my project enter full screen mode, is it possible to replace the Full Screen button with the Maximized button?

What do you mean by Full Screen button? I know only of Maximize, Minimize and Close(x).
Have you set your Form's border style to bsNone?

Cheers,
Gus
Title: Re: Is it possible to replace the Full Screen button with the Maximized button?
Post by: lucamar on April 13, 2021, 12:19:29 pm
What do you mean by Full Screen button?

It's probably some Mac OS thing, I guess ...
Title: Re: Is it possible to replace the Full Screen button with the Maximized button?
Post by: Gustavo 'Gus' Carreno on April 13, 2021, 12:24:07 pm
Hey Lucamar,

It's probably some Mac OS thing, I guess ...

Arghhh, I always forget about those guys/gals. Thanks for reminding me ;)

And if it's the case, I'm out of ideas for this one :)

Cheers,
Gus
Title: Re: Is it possible to replace the Full Screen button with the Maximized button?
Post by: ling on April 13, 2021, 12:30:04 pm
Sorry, I didn't make my question clear. Yes, I'm working on macOS.
Title: Re: Is it possible to replace the Full Screen button with the Maximized button?
Post by: Hansaplast on April 13, 2021, 01:00:07 pm
I'm not an expert, but I was curious if I could find a soilution (I do not like how Apple implemented this either).
The example below worked for me. I based some of the code on this example (https://wiki.freepascal.org/macOS_Programming_Tips#Show_application_in_all_desktop_spaces).
The maximize button will now be the classical maximize button (and not the "full screen" button).



Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3.  
  4. {$mode objfpc}{$H+}
  5. {$modeswitch objectivec1}
  6.  
  7.  
  8. interface
  9.  
  10.  
  11. uses
  12.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, CocoaAll;
  13.  
  14.  
  15. type
  16.  
  17.  
  18.   { TForm1 }
  19.  
  20.  
  21.   TForm1 = class(TForm)
  22.     procedure FormCreate(Sender: TObject);
  23.   private
  24.  
  25.  
  26.   public
  27.  
  28.  
  29.   end;
  30.  
  31.  
  32. var
  33.   Form1: TForm1;
  34.  
  35.  
  36. implementation
  37.  
  38.  
  39. {$R *.lfm}
  40.  
  41.  
  42. { TForm1 }
  43.  
  44.  
  45. procedure TForm1.FormCreate(Sender: TObject);
  46. var
  47.   theWindow: NSWindow;
  48. begin
  49.   theWindow := NSView(Form1.Handle).window;      
  50.   theWindow.setCollectionBehavior(theWindow.collectionBehavior or NSWindowCollectionBehaviorFullScreenAuxiliary);
  51. end;
  52.  
  53.  
  54. end.
Title: Re: Is it possible to replace the Full Screen button with the Maximized button?
Post by: trev on April 13, 2021, 01:10:02 pm
For the uninitiated:

Clicking the Green Dot takes the application full screen (ie obliterates the menu bar and the dock and uses the FULL screen real estate).

Double-clicking on the title bar of an application maximizes it provided System Preferences -> Dock "Double-click a window's title bar to minimize" is unchecked =OR= holding down the Option key and clicking the Green Dot (ie it constrains the application between the menu bar and the dock).

I really doubt that Apple would sanction messing with its standard GUI design (aka human interface guidelines).

Title: Re: Is it possible to replace the Full Screen button with the Maximized button?
Post by: Hansaplast on April 13, 2021, 01:19:25 pm
I agree with you Trev ... however, since NSWindowCollectionBehaviorFullScreenAuxiliary is documented in the Apple documentation (https://developer.apple.com/documentation/appkit/nswindowcollectionbehavior/nswindowcollectionbehaviorfullscreenauxiliary) (with a very confusing description), I'd carefully assume this to be acceptable to use ... (although I do agree that Apple can have some special considerations at times)
Title: Re: Is it possible to replace the Full Screen button with the Maximized button?
Post by: madref on April 14, 2021, 07:32:38 am
If you want to prevent the form/program to go to full screen then set the properties correctly.
Set the BorderStyle to bsSingle and set the BorderIcons biHelp, biMaximize & biMinimize to False. BUT biSystemMenu MUST BE TRUE otherwise you can not close your form if there is no exit button or so.


See attachment
Title: Re: Is it possible to replace the Full Screen button with the Maximized button?
Post by: ling on April 14, 2021, 11:31:49 am
@Hansaplast Thanks, there is no setCollectionBehavior property in the NSWindow in my environment, I'm using fpc 3.2.0.
@madref I've tried it, the Full Screen button is still there.
@trev I agree with you, my application's UI flow probably doesn't fit Apple design principle, so when the form enters full screen it is not user-friendly.

I have several forms in my application:

Main Form
Editor Form A, B, C ...

The Main Form shows data list, user can open Editor Form to edit data, and they would open multiple Editor Form to do cross check. If the form enters full screen mode, switching between forms becomes difficult to use, that is why I want to replace Full Screen Button with Maximized Button.

I found an alternative way:
If form's PopupParent is set, the border icon will be Zoom (Maximized) not Full Screen.
I set Editor Form's PopupParent to Main Form on form activate, remove PopupParent on form deactivate to prevent Editor Form blocks Main Form.
Title: Re: Is it possible to replace the Full Screen button with the Maximized button?
Post by: Hansaplast on April 14, 2021, 05:10:34 pm

Thanks, there is no setCollectionBehavior property in the NSWindow in my environment, I'm using fpc 3.2.0.


Sorry, I forgot about that ... I'm using Lazarus 2.1.0 r64688 FPC 3.3.1 x86_64-darwin-cocoa
Not sure if the following is relevant or useful ...


setCollectionBehavior is declared (in the version I'm running) in NSWindow.inc line 414 as
( fpcsrc/packages/cocoaint/src/appkit/NSWindow.inc )


Code: Pascal  [Select][+][-]
  1. procedure setCollectionBehavior(newValue: NSWindowCollectionBehavior); message 'setCollectionBehavior:';


and NSWindowCollectionBehaviorFullScreenAuxiliary (line 64 of NSWindow.inc) as


Code: Pascal  [Select][+][-]
  1. NSWindowCollectionBehaviorFullScreenAuxiliary = 1 shl 8 { available in 10_7 };
TinyPortal © 2005-2018