lcl-cocoa: Minor improvements in debug info for the tab control problem, implements correct height calculation for tabviewitem children

git-svn-id: trunk@44849 -
This commit is contained in:
sekelsenmat 2014-04-30 10:55:00 +00:00
parent 6032b26eb4
commit 633131dd11
5 changed files with 81 additions and 38 deletions

View File

@ -547,10 +547,12 @@ begin
if ALogFont.lfStrikeOut > 0 then
include(FStyle, cfs_StrikeOut);
FontName := NSStringUTF8(FName);
Attributes := NSDictionary.dictionaryWithObjectsAndKeys(
NSStringUTF8(FName), NSFontFamilyAttribute,
FontName, NSFontFamilyAttribute,
NSNumber.numberWithFloat(FSize), NSFontSizeAttribute,
nil);
FontName.release;
Descriptor := NSFontDescriptor.fontDescriptorWithFontAttributes(Attributes);
FFont := NSFont.fontWithDescriptor_textTransform(Descriptor, nil);
@ -1048,11 +1050,11 @@ begin
FText := NewText;
S := NSStringUTF8(NewText);
try
FTextStorage.beginEditing;
FTextStorage.replaceCharactersInRange_withString(GetTextRange, S);
updateFont;
updateColor;
FTextStorage.endEditing;
FTextStorage.beginEditing;
FTextStorage.replaceCharactersInRange_withString(GetTextRange, S);
updateFont;
updateColor;
FTextStorage.endEditing;
except
end;
S.release;

View File

@ -134,7 +134,6 @@ begin
CocoaWidgetSet := nil;
end;
{------------------------------------------------------------------------------

View File

@ -25,7 +25,7 @@ uses
Types, Classes, SysUtils,
CGGeometry,
// Libs
CocoaAll, CocoaUtils, CocoaGDIObjects,
MacOSAll, CocoaAll, CocoaUtils, CocoaGDIObjects,
// LCL
LCLType, LCLProc, Controls, ComCtrls;
@ -538,6 +538,10 @@ type
procedure lclClearCallback; override;
end;
TCocoaTabPageView = objcclass(NSView)
tabview: TCocoaTabControl;
end;
{ TCocoaTableListView }
TCocoaTableListView = objcclass(NSTableView, NSTableViewDelegateProtocol, NSTableViewDataSourceProtocol)
@ -603,6 +607,7 @@ type
procedure SetViewDefaults(AView: NSView);
function CheckMainThread: Boolean;
function GetNSViewSuperViewHeight(view: NSView): CGFloat;
implementation
@ -617,6 +622,17 @@ begin
Result := NSThread.currentThread.isMainThread;
end;
function GetNSViewSuperViewHeight(view: NSView): CGFloat;
begin
Result := -1;
if not Assigned(view) then Exit;
if not Assigned(view.superview) then Exit;
if view.superview.isKindOfClass_(TCocoaTabPageView) then
Result := TCocoaTabPageView(view.superview).tabview.contentRect.size.height
else
Result := view.superview.frame.size.height;
end;
{ TCocoaWindowContent }
function TCocoaWindowContent.lclIsHandle: Boolean;
@ -1713,18 +1729,34 @@ function LCLViewExtension.lclInitWithCreateParams(const AParams: TCreateParams):
var
p: NSView;
ns: NSRect;
{$IFDEF COCOA_DEBUG_SETBOUNDS}
pstr: string;
{$ENDIF}
begin
p := nil;
if (AParams.WndParent <> 0) then
begin
p := CocoaUtils.GetNSObjectView(NSObject(AParams.WndParent));
if (NSObject(AParams.WndParent).isKindOfClass_(NSView)) then
end;
with AParams do
if Assigned(p) then
LCLToNSRect(Types.Bounds(X,Y,Width, Height), p.frame.size.height, ns)
else
ns := GetNSRect(X, Y, Width, Height);
if Assigned(p) then
LCLToNSRect(Types.Bounds(AParams.X, AParams.Y, AParams.Width, AParams.Height),
p.frame.size.height, ns)
else
ns := GetNSRect(AParams.X, AParams.Y, AParams.Width, AParams.Height);
{$IFDEF COCOA_DEBUG_SETBOUNDS}
if Assigned(p) then
begin
pstr := NSStringToString(p.className);
if NSStringToString(NSObject(AParams.WndParent).className) = 'TCocoaTabPage' then
pstr := pstr + ' ' + NSStringToString(TCocoaTabPage(AParams.WndParent).label_);
end
else
pstr := '';
WriteLn(Format('[LCLViewExtension.lclInitWithCreateParams] Class=%s Caption=%s ParentClass=%s ParentClassView=%s rect=%d %d %d %d',
[NSStringToString(Self.className), AParams.Caption,
NSStringToString(NSObject(AParams.WndParent).className), pstr,
Round(ns.Origin.x), Round(ns.Origin.y), Round(ns.size.width), Round(ns.size.height)]));
{$ENDIF}
Result := initWithFrame(ns);
if not Assigned(Result) then
@ -1828,11 +1860,18 @@ end;
procedure LCLViewExtension.lclSetFrame(const r: TRect);
var
ns: NSRect;
svHeight: CGFloat;
begin
svHeight := GetNSViewSuperViewHeight(Self);
if Assigned(superview) then
LCLToNSRect(r, superview.frame.size.height, ns)
LCLToNSRect(r, svHeight, ns)
else
ns := RectToNSRect(r);
{$IFDEF COCOA_DEBUG_SETBOUNDS}
WriteLn(Format('LCLViewExtension.lclSetFrame: %s Bounds=%s height=%d ns_pos=%d %d ns_size=%d %d',
[NSStringToString(Self.ClassName), dbgs(r), Round(svHeight),
Round(ns.origin.x), Round(ns.origin.y), Round(ns.size.width), Round(ns.size.height)]));
{$ENDIF}
setFrame(ns);
end;

View File

@ -5,7 +5,7 @@ interface
{$mode delphi}
{$modeswitch objectivec1}
{$DEFINE COCOA_DEBUG_TABCONTROL}
{.$DEFINE COCOA_DEBUG_TABCONTROL}
uses
// RTL, FCL, LCL
@ -185,7 +185,8 @@ end;
class function TCocoaWSCustomPage.CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLIntfHandle;
var
lControl: TCocoaTabPage;
sv: NSScrollView;
tv: TCocoaTabPageView;
tabview: TCocoaTabControl;
begin
{$IFDEF COCOA_DEBUG_TABCONTROL}
WriteLn('[TCocoaWSCustomPage.CreateHandle]');
@ -198,13 +199,16 @@ begin
lControl.LCLPage := TCustomPage(AWinControl);
SetProperties(TCustomPage(AWinControl), lControl);
{sv := NSScrollView.alloc.initWithFrame(
TCocoaTabControl(AWinControl.Parent.Handle) .contentRect);
sv.setHasVerticalScroller(True);
sv.setHasHorizontalScroller(True);
sv.setAutohidesScrollers(True);
sv.setBorderType(NSNoBorder);
lControl.setView(sv);}
// Set a special view for the page
tabview := TCocoaTabControl(AWinControl.Parent.Handle);
tv := TCocoaTabPageView.alloc.initWithFrame(
tabview.contentRect);
{tv.setHasVerticalScroller(True);
tv.setHasHorizontalScroller(True);
tv.setAutohidesScrollers(True);
tv.setBorderType(NSNoBorder);}
tv.tabview := tabview;
lControl.setView(tv);
end;
end;

View File

@ -1193,30 +1193,29 @@ end;
class procedure TCocoaWSWinControl.SetBounds(const AWinControl: TWinControl;
const ALeft, ATop, AWidth, AHeight: Integer);
begin
if AWinControl.HandleAllocated then
begin
//debugln('TCocoaWSWinControl.SetBounds: '+AWinControl.Name+'Bounds='+dbgs(Bounds(ALeft, ATop, AWidth, AHeight)));
begin
{$IFDEF COCOA_DEBUG_SETBOUNDS}
writeln('TCocoaWSWinControl.SetBounds: '+AWinControl.Name+'Bounds='+dbgs(Bounds(ALeft, ATop, AWidth, AHeight)));
{$ENDIF}
NSObject(AWinControl.Handle).lclSetFrame(Bounds(ALeft, ATop, AWidth, AHeight));
end;
end;
end;
class procedure TCocoaWSWinControl.SetCursor(const AWinControl: TWinControl;
const ACursor: HCursor);
begin
//debugln('SetCursor '+AWinControl.name+' '+dbgs(ACursor));
if CocoaWidgetSet.CurrentCursor<>ACursor then
if CocoaWidgetSet.CurrentCursor<>ACursor then
begin
CocoaWidgetSet.CurrentCursor:= ACursor;
if ACursor<>0 then
TCocoaCursor(ACursor).SetCursor
else
TCocoaCursor.SetDefaultCursor;
CocoaWidgetSet.CurrentCursor:= ACursor;
if ACursor<>0 then
TCocoaCursor(ACursor).SetCursor
else
TCocoaCursor.SetDefaultCursor;
end;
end;
class procedure TCocoaWSWinControl.SetFont(const AWinControl: TWinControl; const AFont: TFont);