mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-17 02:29:21 +02:00
cocoa: Fixes tab sheet positioning (bug #28489) and starts improving main menu code
git-svn-id: trunk@49626 -
This commit is contained in:
parent
4eaea7c197
commit
2bd8349602
@ -36,7 +36,7 @@ uses
|
|||||||
CocoaProc,
|
CocoaProc,
|
||||||
// LCL
|
// LCL
|
||||||
LCLStrConsts, LMessages, LCLMessageGlue, LCLProc, LCLIntf, LCLType,
|
LCLStrConsts, LMessages, LCLMessageGlue, LCLProc, LCLIntf, LCLType,
|
||||||
Controls, Forms, Themes,
|
Controls, Forms, Themes, Menus,
|
||||||
IntfGraphics, Graphics, CocoaWSFactory;
|
IntfGraphics, Graphics, CocoaWSFactory;
|
||||||
|
|
||||||
type
|
type
|
||||||
@ -59,6 +59,11 @@ type
|
|||||||
constructor Create(AMimeType: string; ACocoaFormat: NSString; ADataType: TCocoaClipboardDataType);
|
constructor Create(AMimeType: string; ACocoaFormat: NSString; ADataType: TCocoaClipboardDataType);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
{// private since 10.5, doesn't seam to do anything in 10.10
|
||||||
|
NSApplicationSetAppleMenu = objccategory external(NSApplication)
|
||||||
|
procedure setAppleMenu(AMenu: NSMenu); message 'setAppleMenu:';
|
||||||
|
end;}
|
||||||
|
|
||||||
{ TCocoaWidgetSet }
|
{ TCocoaWidgetSet }
|
||||||
|
|
||||||
TCocoaWidgetSet = class(TWidgetSet)
|
TCocoaWidgetSet = class(TWidgetSet)
|
||||||
@ -129,7 +134,7 @@ type
|
|||||||
procedure FreeStockItems;
|
procedure FreeStockItems;
|
||||||
procedure FreeSysColorBrushes;
|
procedure FreeSysColorBrushes;
|
||||||
|
|
||||||
procedure SetMainMenu(const AMenu: HMENU);
|
procedure SetMainMenu(const AMenu: HMENU; const ALCLMenu: TMenu);
|
||||||
|
|
||||||
{todo:}
|
{todo:}
|
||||||
function DCGetPixel(CanvasHandle: HDC; X, Y: integer): TGraphicsColor; override;
|
function DCGetPixel(CanvasHandle: HDC; X, Y: integer): TGraphicsColor; override;
|
||||||
|
@ -418,10 +418,39 @@ begin
|
|||||||
DeleteAndNilObject(FSysColorBrushes[i]);
|
DeleteAndNilObject(FSysColorBrushes[i]);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCocoaWidgetSet.SetMainMenu(const AMenu: HMENU);
|
procedure TCocoaWidgetSet.SetMainMenu(const AMenu: HMENU; const ALCLMenu: TMenu);
|
||||||
|
var
|
||||||
|
i: Integer;
|
||||||
|
lCurItem: TMenuItem;
|
||||||
|
lMenuObj: NSObject;
|
||||||
begin
|
begin
|
||||||
if AMenu<>0 then
|
if AMenu<>0 then
|
||||||
|
begin
|
||||||
NSApp.setMainMenu(NSMenu(AMenu));
|
NSApp.setMainMenu(NSMenu(AMenu));
|
||||||
|
if (ALCLMenu = nil) or not ALCLMenu.HandleAllocated then Exit;
|
||||||
|
|
||||||
|
// Some older docs say we should use setAppleMenu to obtain the Services/Hide/Quit items,
|
||||||
|
// but its now private and in 10.10 it doesn't seam to do anything
|
||||||
|
{
|
||||||
|
for i := 0 to ALCLMenu.Items.Count-1 do
|
||||||
|
begin
|
||||||
|
lCurItem := ALCLMenu.Items.Items[i];
|
||||||
|
if not lCurItem.HandleAllocated or (lCurItem.Caption <> '') then Continue;
|
||||||
|
|
||||||
|
lMenuObj := NSObject(lCurItem.Handle);
|
||||||
|
if lMenuObj.isKindOfClass_(NSMenuItem) and NSMenuItem(lMenuObj).hasSubmenu and
|
||||||
|
(NSMenuItem(lMenuObj).submenu <> nil) then
|
||||||
|
begin
|
||||||
|
NSApp.setAppleMenu(NSMenuItem(lMenuObj).submenu);
|
||||||
|
Exit;
|
||||||
|
end
|
||||||
|
else if lMenuObj.isKindOfClass_(NSMenu) then
|
||||||
|
begin
|
||||||
|
NSApp.setAppleMenu(NSMenu(lMenuObj));
|
||||||
|
Exit;
|
||||||
|
end;
|
||||||
|
end;}
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{------------------------------------------------------------------------------
|
{------------------------------------------------------------------------------
|
||||||
|
@ -22,6 +22,7 @@ unit CocoaPrivate;
|
|||||||
{.$DEFINE COCOA_DEBUG_LISTVIEW}
|
{.$DEFINE COCOA_DEBUG_LISTVIEW}
|
||||||
{.$DEFINE COCOA_SPIN_DEBUG}
|
{.$DEFINE COCOA_SPIN_DEBUG}
|
||||||
{.$DEFINE COCOA_SPINEDIT_INSIDE_CONTAINER}
|
{.$DEFINE COCOA_SPINEDIT_INSIDE_CONTAINER}
|
||||||
|
{.$DEFINE COCOA_SUPERVIEW_HEIGHT}
|
||||||
|
|
||||||
interface
|
interface
|
||||||
|
|
||||||
@ -202,6 +203,7 @@ type
|
|||||||
|
|
||||||
TCocoaMenu = objcclass(NSMenu)
|
TCocoaMenu = objcclass(NSMenu)
|
||||||
public
|
public
|
||||||
|
isMainMenu: Boolean;
|
||||||
procedure lclItemSelected(sender: id); message 'lclItemSelected:';
|
procedure lclItemSelected(sender: id); message 'lclItemSelected:';
|
||||||
function lclIsHandle: Boolean; override;
|
function lclIsHandle: Boolean; override;
|
||||||
end;
|
end;
|
||||||
@ -635,6 +637,7 @@ type
|
|||||||
public
|
public
|
||||||
callback: ICommonCallback;
|
callback: ICommonCallback;
|
||||||
LCLPage: TCustomPage;
|
LCLPage: TCustomPage;
|
||||||
|
LCLParent: TCustomTabControl;
|
||||||
function lclGetCallback: ICommonCallback; override;
|
function lclGetCallback: ICommonCallback; override;
|
||||||
procedure lclClearCallback; override;
|
procedure lclClearCallback; override;
|
||||||
function lclFrame: TRect; override;
|
function lclFrame: TRect; override;
|
||||||
@ -862,6 +865,8 @@ function GetNSViewSuperViewHeight(view: NSView): CGFloat;
|
|||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
|
uses CocoaWSComCtrls;
|
||||||
|
|
||||||
{$I mackeycodes.inc}
|
{$I mackeycodes.inc}
|
||||||
|
|
||||||
procedure SetViewDefaults(AView: NSView);
|
procedure SetViewDefaults(AView: NSView);
|
||||||
@ -884,6 +889,9 @@ begin
|
|||||||
Result := TCocoaTabPageView(view.superview).tabview.contentRect.size.height
|
Result := TCocoaTabPageView(view.superview).tabview.contentRect.size.height
|
||||||
else
|
else
|
||||||
Result := view.superview.frame.size.height;
|
Result := view.superview.frame.size.height;
|
||||||
|
{$IFDEF COCOA_SUPERVIEW_HEIGHT}
|
||||||
|
WriteLn(Format('GetNSViewSuperViewHeight Result=%f', [Result]));
|
||||||
|
{$ENDIF}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TCocoaWindowContent }
|
{ TCocoaWindowContent }
|
||||||
@ -2757,10 +2765,22 @@ end;
|
|||||||
function TCocoaTabPage.lclFrame: TRect;
|
function TCocoaTabPage.lclFrame: TRect;
|
||||||
var
|
var
|
||||||
svh: CGFloat;
|
svh: CGFloat;
|
||||||
|
lParent: TCocoaTabControl;
|
||||||
begin
|
begin
|
||||||
svh := tabView.frame.size.height;
|
lParent := TCocoaWSCustomTabControl.GetCocoaTabControlHandle(LCLParent);
|
||||||
NSToLCLRect(tabView.contentRect, svh, Result);
|
if lParent <> nil then
|
||||||
//WriteLn('[TCocoaTabPage.lclFrame] '+dbgs(Result)+' '+NSStringToString(Self.label_));
|
begin
|
||||||
|
svh := lParent.contentRect.size.height;
|
||||||
|
NSToLCLRect(lParent.contentRect, svh, Result);
|
||||||
|
end
|
||||||
|
else
|
||||||
|
begin
|
||||||
|
svh := tabView.frame.size.height;
|
||||||
|
NSToLCLRect(tabView.contentRect, svh, Result);
|
||||||
|
end;
|
||||||
|
{$IFDEF COCOA_DEBUG_TABCONTROL}
|
||||||
|
WriteLn('[TCocoaTabPage.lclFrame] '+dbgs(Result)+' '+NSStringToString(Self.label_));
|
||||||
|
{$ENDIF}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TCocoaTabPage.lclClientFrame: TRect;
|
function TCocoaTabPage.lclClientFrame: TRect;
|
||||||
|
@ -47,6 +47,8 @@ type
|
|||||||
class function CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLIntfHandle; override;
|
class function CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLIntfHandle; override;
|
||||||
class procedure UpdateProperties(const ACustomPage: TCustomPage); override;
|
class procedure UpdateProperties(const ACustomPage: TCustomPage); override;
|
||||||
class procedure SetProperties(const ACustomPage: TCustomPage; ACocoaControl: NSTabViewItem);
|
class procedure SetProperties(const ACustomPage: TCustomPage; ACocoaControl: NSTabViewItem);
|
||||||
|
//
|
||||||
|
class procedure SetBounds(const AWinControl: TWinControl; const ALeft, ATop, AWidth, AHeight: Integer); override;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TCocoaWSCustomTabControl }
|
{ TCocoaWSCustomTabControl }
|
||||||
@ -54,6 +56,8 @@ type
|
|||||||
TCocoaWSCustomTabControl = class(TWSCustomTabControl)
|
TCocoaWSCustomTabControl = class(TWSCustomTabControl)
|
||||||
private
|
private
|
||||||
class function LCLTabPosToNSTabStyle(AShowTabs: Boolean; ABorderWidth: Integer; ATabPos: TTabPosition): NSTabViewType;
|
class function LCLTabPosToNSTabStyle(AShowTabs: Boolean; ABorderWidth: Integer; ATabPos: TTabPosition): NSTabViewType;
|
||||||
|
public
|
||||||
|
class function GetCocoaTabControlHandle(ATabControl: TCustomTabControl): TCocoaTabControl;
|
||||||
published
|
published
|
||||||
class function CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLIntfHandle; override;
|
class function CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLIntfHandle; override;
|
||||||
|
|
||||||
@ -330,6 +334,14 @@ begin
|
|||||||
ACocoaControl.setToolTip(NSStringUTF8(lHintStr));
|
ACocoaControl.setToolTip(NSStringUTF8(lHintStr));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
class procedure TCocoaWSCustomPage.SetBounds(const AWinControl: TWinControl;
|
||||||
|
const ALeft, ATop, AWidth, AHeight: Integer);
|
||||||
|
begin
|
||||||
|
// Pages should be fixed into their PageControl owner,
|
||||||
|
// allowing the TCocoaWSWinControl.SetBounds function to operate here
|
||||||
|
// was causing bug 28489
|
||||||
|
end;
|
||||||
|
|
||||||
{ TCocoaWSCustomTabControl }
|
{ TCocoaWSCustomTabControl }
|
||||||
|
|
||||||
class function TCocoaWSCustomTabControl.LCLTabPosToNSTabStyle(AShowTabs: Boolean; ABorderWidth: Integer; ATabPos: TTabPosition): NSTabViewType;
|
class function TCocoaWSCustomTabControl.LCLTabPosToNSTabStyle(AShowTabs: Boolean; ABorderWidth: Integer; ATabPos: TTabPosition): NSTabViewType;
|
||||||
@ -355,6 +367,14 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
class function TCocoaWSCustomTabControl.GetCocoaTabControlHandle(ATabControl: TCustomTabControl): TCocoaTabControl;
|
||||||
|
begin
|
||||||
|
Result := nil;
|
||||||
|
if ATabControl = nil then Exit;
|
||||||
|
if not ATabControl.HandleAllocated then Exit;
|
||||||
|
Result := TCocoaTabControl(ATabControl.Handle);
|
||||||
|
end;
|
||||||
|
|
||||||
class function TCocoaWSCustomTabControl.CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLIntfHandle;
|
class function TCocoaWSCustomTabControl.CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLIntfHandle;
|
||||||
var
|
var
|
||||||
lControl: TCocoaTabControl;
|
lControl: TCocoaTabControl;
|
||||||
@ -387,6 +407,7 @@ begin
|
|||||||
AChild.HandleNeeded();
|
AChild.HandleNeeded();
|
||||||
if not Assigned(AChild) or not AChild.HandleAllocated then Exit;
|
if not Assigned(AChild) or not AChild.HandleAllocated then Exit;
|
||||||
lTabPage := TCocoaWSCustomPage.GetCocoaTabPageFromHandle(AChild.Handle);
|
lTabPage := TCocoaWSCustomPage.GetCocoaTabPageFromHandle(AChild.Handle);
|
||||||
|
lTabPage.LCLParent := ATabControl;
|
||||||
|
|
||||||
lTabControl.insertTabViewItem_atIndex(lTabPage, AIndex);
|
lTabControl.insertTabViewItem_atIndex(lTabPage, AIndex);
|
||||||
{$IFDEF COCOA_DEBUG_TABCONTROL}
|
{$IFDEF COCOA_DEBUG_TABCONTROL}
|
||||||
|
@ -1259,7 +1259,8 @@ begin
|
|||||||
if AWinControl.HandleAllocated then
|
if AWinControl.HandleAllocated then
|
||||||
begin
|
begin
|
||||||
{$IFDEF COCOA_DEBUG_SETBOUNDS}
|
{$IFDEF COCOA_DEBUG_SETBOUNDS}
|
||||||
writeln('TCocoaWSWinControl.SetBounds: '+AWinControl.Name+'Bounds='+dbgs(Bounds(ALeft, ATop, AWidth, AHeight)));
|
writeln(Format('TCocoaWSWinControl.SetBounds: %s Bounds=%s',
|
||||||
|
[AWinControl.Name, dbgs(Bounds(ALeft, ATop, AWidth, AHeight))]));
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
NSObject(AWinControl.Handle).lclSetFrame(Bounds(ALeft, ATop, AWidth, AHeight));
|
NSObject(AWinControl.Handle).lclSetFrame(Bounds(ALeft, ATop, AWidth, AHeight));
|
||||||
end;
|
end;
|
||||||
|
@ -285,15 +285,15 @@ begin
|
|||||||
if NSObject(ACustForm.Menu.Handle).isKindOfClass_(TCocoaMenuItem) then
|
if NSObject(ACustForm.Menu.Handle).isKindOfClass_(TCocoaMenuItem) then
|
||||||
begin
|
begin
|
||||||
if TCocoaMenuItem(ACustForm.Menu.Handle).hasSubmenu then
|
if TCocoaMenuItem(ACustForm.Menu.Handle).hasSubmenu then
|
||||||
CocoaWidgetSet.SetMainMenu(HMENU(TCocoaMenuItem(ACustForm.Menu.Handle).submenu))
|
CocoaWidgetSet.SetMainMenu(HMENU(TCocoaMenuItem(ACustForm.Menu.Handle).submenu), ACustForm.Menu)
|
||||||
else
|
else
|
||||||
debugln('Warning: Menu does not have a valid handle.');
|
debugln('Warning: Menu does not have a valid handle.');
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
CocoaWidgetSet.SetMainMenu(ACustForm.Menu.Handle);
|
CocoaWidgetSet.SetMainMenu(ACustForm.Menu.Handle, ACustForm.Menu);
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
CocoaWidgetSet.SetMainMenu(0);
|
CocoaWidgetSet.SetMainMenu(0, nil);
|
||||||
|
|
||||||
LCLSendActivateMsg(Target, WA_ACTIVE, false);
|
LCLSendActivateMsg(Target, WA_ACTIVE, false);
|
||||||
LCLSendSetFocusMsg(Target);
|
LCLSendSetFocusMsg(Target);
|
||||||
@ -528,6 +528,7 @@ end;
|
|||||||
|
|
||||||
class procedure TCocoaWSCustomForm.ShowModal(const ACustomForm: TCustomForm);
|
class procedure TCocoaWSCustomForm.ShowModal(const ACustomForm: TCustomForm);
|
||||||
begin
|
begin
|
||||||
|
// modal is started in ShowHide with (fsModal in AForm.FormState)
|
||||||
// if ACustomForm.HandleAllocated then
|
// if ACustomForm.HandleAllocated then
|
||||||
// NSPanel(ACustomForm.Handle).setStyleMask(NSwindow(ACustomForm.Handle).styleMask or NSDocModalWindowMask);
|
// NSPanel(ACustomForm.Handle).setStyleMask(NSwindow(ACustomForm.Handle).styleMask or NSDocModalWindowMask);
|
||||||
end;
|
end;
|
||||||
|
@ -62,9 +62,8 @@ type
|
|||||||
{ TCocoaWSMainMenu }
|
{ TCocoaWSMainMenu }
|
||||||
|
|
||||||
TCocoaWSMainMenu = class(TWSMainMenu)
|
TCocoaWSMainMenu = class(TWSMainMenu)
|
||||||
private
|
published
|
||||||
protected
|
class function CreateHandle(const AMenu: TMenu): HMENU; override;
|
||||||
public
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TCocoaWSPopupMenu }
|
{ TCocoaWSPopupMenu }
|
||||||
@ -119,6 +118,14 @@ begin
|
|||||||
Result := HMENU(TCocoaMenu.alloc.initWithTitle(NSStringUtf8('')));
|
Result := HMENU(TCocoaMenu.alloc.initWithTitle(NSStringUtf8('')));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
{ TCocoaWSMainMenu }
|
||||||
|
|
||||||
|
class function TCocoaWSMainMenu.CreateHandle(const AMenu: TMenu): HMENU;
|
||||||
|
begin
|
||||||
|
Result := HMENU(TCocoaMenu.alloc.initWithTitle(NSStringUtf8('')));
|
||||||
|
TCocoaMenu(Result).isMainMenu := True;
|
||||||
|
end;
|
||||||
|
|
||||||
{ TCocoaWSMenuItem }
|
{ TCocoaWSMenuItem }
|
||||||
|
|
||||||
{------------------------------------------------------------------------------
|
{------------------------------------------------------------------------------
|
||||||
|
Loading…
Reference in New Issue
Block a user