Difference between revisions of "Cocoa Internals/Forms"

From Lazarus wiki
Jump to navigationJump to search
m
Line 11: Line 11:
 
Keep in mind, that Cocoa design guidelines suggest the Icon to define a type of the document opened in the Window.
 
Keep in mind, that Cocoa design guidelines suggest the Icon to define a type of the document opened in the Window.
 
Where in LCL the icon typically defines the Application itself. That icon use contradiction is left to LCL developer to resolve.
 
Where in LCL the icon typically defines the Application itself. That icon use contradiction is left to LCL developer to resolve.
The LCL can behavior be turned off globally for an project by enabling CocoaIconsUse variable
+
The LCL can behavior be turned off globally for an project by enabling '''CocoaIconsUse''' variable
  
 
<source lang="delphi">
 
<source lang="delphi">

Revision as of 15:57, 14 June 2019

Forms are based on NSWindow (or NSPanel) + a special sub-class of NSView (TCocoaContentWindow) in order to provide the ability of embedding forms one into another.

Icons

Form icon is based on NSWindowDocumentIconButton - a special form button that is used to show the document icon. The button is automatically generated and placed by Cocoa, if NSWindow has representedURL assigned (to a non-nil value). The URL doesn't have to point to an existing location. If it points to a non-existing location a button with a generic icon would still be generated.

If representedURL is not assigned, then the DocumentIcon button could be created manually by using standardWindowButton:forStyleMask: method. However, the placement of the button should also be handled manually (every time the title changes). As well as both the title and the button would not be aligned in the same manner as if they were automatically with representedURL assigned.

Since automatically managed representedURL icon provides a better user experience LCL assigns representedURL to the bundle URL. (The bundle is likely to exist, since the application has been launched).

Keep in mind, that Cocoa design guidelines suggest the Icon to define a type of the document opened in the Window. Where in LCL the icon typically defines the Application itself. That icon use contradiction is left to LCL developer to resolve. The LCL can behavior be turned off globally for an project by enabling CocoaIconsUse variable

uses
  {$IFDEF UNIX}{$IFDEF UseCThreads}
  cthreads,
  {$ENDIF}{$ENDIF}
  Interfaces, // this includes the LCL widgetset
  Forms, Unit1
  { you can add units after this }

  // CocoaIconUse is a global variable defined in CocoaInt
  {$ifdef LCLCocoa}, CocoaInt{$endif}
  ;

{$R *.res}

begin
  {$ifdef LCLCocoa}
  CocoaInt.CocoaIconUse:=true;
  {$endif}
  RequireDerivedFormResource:=True;
  Application.Scaled:=True;
  Application.Initialize;
  Application.CreateForm(TForm1, Form1);
  Application.Run;
end.

See Also