mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-08 00:02:03 +02:00
Gtk2: fixed clientRect of GtkTreeView, new routine GetWidgetClientRect() in gtk2proc to simplify gtk2winapi, fixed offset for custom drawn listview.
git-svn-id: trunk@39043 -
This commit is contained in:
parent
f3f7450f44
commit
0309af8ded
@ -64,6 +64,13 @@ end;
|
||||
function TGtkDeviceContext.GetOffset: TPoint;
|
||||
var
|
||||
Fixed: Pointer;
|
||||
AChild: PGtkWidget;
|
||||
AColumn: PGtkTreeViewColumn;
|
||||
Area: TGdkRectangle;
|
||||
h: gint;
|
||||
w: gint;
|
||||
yoffs: gint;
|
||||
xoffs: gint;
|
||||
begin
|
||||
Result := Point(0, 0);
|
||||
if Assigned(FWidget) then
|
||||
@ -76,6 +83,20 @@ begin
|
||||
Inc(Result.X, FWidget^.Allocation.x);
|
||||
Inc(Result.y, FWidget^.Allocation.y);
|
||||
end;
|
||||
if (GTK_IS_SCROLLED_WINDOW(FWidget) and GTK_IS_BIN(FWidget)) or (GTK_IS_TREE_VIEW(FWidget)) then
|
||||
begin
|
||||
if GTK_IS_TREE_VIEW(FWidget) then
|
||||
AChild := FWidget
|
||||
else
|
||||
AChild := gtk_bin_get_child(PGtkBin(FWidget));
|
||||
if GTK_IS_TREE_VIEW(AChild) and gtk_tree_view_get_headers_visible(PGtkTreeView(AChild)) then
|
||||
begin
|
||||
AColumn := gtk_tree_view_get_column(PGtkTreeView(AChild), 0);
|
||||
gtk_tree_view_column_cell_get_size(AColumn, @Area, @xoffs, @yoffs, @w, @h);
|
||||
// borders are 2px
|
||||
dec(Result.y, h - 2);
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
|
@ -4524,6 +4524,86 @@ begin
|
||||
Result := GetWidgetOrigin(TheWidget);
|
||||
end;
|
||||
|
||||
function GetWidgetClientRect(TheWidget: PGtkWidget): TRect;
|
||||
var
|
||||
Widget, ClientWidget: PGtkWidget;
|
||||
AChild: PGtkWidget;
|
||||
|
||||
procedure GetNoteBookClientRect(NBWidget: PGtkNotebook);
|
||||
var
|
||||
PageIndex: LongInt;
|
||||
PageWidget: PGtkWidget;
|
||||
FrameBorders: TRect;
|
||||
aWidth: LongInt;
|
||||
aHeight: LongInt;
|
||||
begin
|
||||
// get current page
|
||||
PageIndex:=gtk_notebook_get_current_page(NBWidget);
|
||||
if PageIndex>=0 then
|
||||
PageWidget:=gtk_notebook_get_nth_page(NBWidget,PageIndex)
|
||||
else
|
||||
PageWidget:=nil;
|
||||
if (PageWidget<>nil) and GTK_WIDGET_RC_STYLE(PageWidget)
|
||||
and ((PageWidget^.Allocation.Width>1) or (PageWidget^.Allocation.Height>1))
|
||||
then begin
|
||||
// get the size of the current page
|
||||
Result.Right:=PageWidget^.Allocation.Width;
|
||||
Result.Bottom:=PageWidget^.Allocation.Height;
|
||||
//DebugLn(['GetNoteBookClientRect using pagewidget: ',GetWidgetDebugReport(Widget),' ARect=',dbgs(aRect)]);
|
||||
end else begin
|
||||
// use defaults
|
||||
FrameBorders:=GetStyleNotebookFrameBorders;
|
||||
aWidth:=Widget^.allocation.width;
|
||||
aHeight:=Widget^.allocation.height;
|
||||
Result:=Rect(0,0,
|
||||
Max(0,AWidth-FrameBorders.Left-FrameBorders.Right),
|
||||
Max(0,aHeight-FrameBorders.Top-FrameBorders.Bottom));
|
||||
//DebugLn(['GetNoteBookClientRect using defaults: ',GetWidgetDebugReport(Widget),' ARect=',dbgs(aRect),' Frame=',dbgs(FrameBorders)]);
|
||||
end;
|
||||
end;
|
||||
begin
|
||||
Result := Rect(0, 0, 0, 0);
|
||||
Widget := TheWidget;
|
||||
ClientWidget := GetFixedWidget(Widget);
|
||||
if (ClientWidget <> nil) then
|
||||
Widget := ClientWidget;
|
||||
if (Widget <> nil) then
|
||||
begin
|
||||
Result.Right:=Widget^.Allocation.Width;
|
||||
Result.Bottom:=Widget^.Allocation.Height;
|
||||
if GtkWidgetIsA(Widget,gtk_notebook_get_type) then
|
||||
GetNoteBookClientRect(PGtkNoteBook(Widget))
|
||||
else
|
||||
if GTK_IS_SCROLLED_WINDOW(Widget) and GTK_IS_BIN(Widget) then
|
||||
begin
|
||||
AChild := gtk_bin_get_child(PGtkBin(Widget));
|
||||
if (AChild <> nil) and GTK_IS_TREE_VIEW(AChild) then
|
||||
begin
|
||||
Result.Right := AChild^.allocation.width - AChild^.allocation.x;
|
||||
Result.Bottom := AChild^.allocation.height - AChild^.allocation.y;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
{$IfDef VerboseGetClientRect}
|
||||
if ClientWidget<>nil then begin
|
||||
DebugLn('GetClientRect Widget=',GetWidgetDebugReport(PgtkWidget(Handle)),
|
||||
' Client=',DbgS(ClientWidget),WidgetFlagsToString(ClientWidget),
|
||||
' WindowSize=',dbgs(Result.Right),',',dbgs(Result.Bottom),
|
||||
' Allocation=',dbgs(ClientWidget^.Allocation.Width),',',dbgs(ClientWidget^.Allocation.Height)
|
||||
);
|
||||
end else begin
|
||||
DebugLn('GetClientRect Widget=',GetWidgetDebugReport(PgtkWidget(Handle)),
|
||||
' Client=',DbgS(ClientWidget),WidgetFlagsToString(ClientWidget),
|
||||
' WindowSize=',dbgs(Result.Right),',',dbgs(Result.Bottom),
|
||||
' Allocation=',dbgs(Widget^.Allocation.Width),',',dbgs(Widget^.Allocation.Height)
|
||||
);
|
||||
end;
|
||||
if GetLCLObject(Widget) is TCustomPage then begin
|
||||
DebugLn(['TGtk2WidgetSet.GetClientRect Rect=',dbgs(Result),' ',GetWidgetDebugReport(Widget)]);
|
||||
end;
|
||||
{$EndIf}
|
||||
end;
|
||||
|
||||
{-------------------------------------------------------------------------------
|
||||
TranslateGdkPointToClientArea
|
||||
|
||||
|
@ -465,6 +465,7 @@ procedure UpdateNotebookTabFont(APage: TWinControl; AFont: TFont);
|
||||
// coordinate transformation
|
||||
function GetWidgetOrigin(TheWidget: PGtkWidget): TPoint;
|
||||
function GetWidgetClientOrigin(TheWidget: PGtkWidget): TPoint;
|
||||
function GetWidgetClientRect(TheWidget: PGtkWidget): TRect;
|
||||
function TranslateGdkPointToClientArea(SourceWindow: PGdkWindow;
|
||||
SourcePos: TPoint; DestinationWidget: PGtkWidget): TPoint;
|
||||
function SubtractScoll(AWidget: PGtkWidget; APosition: TPoint): TPoint;
|
||||
|
@ -4359,79 +4359,11 @@ end;
|
||||
child controls are visible.
|
||||
------------------------------------------------------------------------------}
|
||||
function TGtk2WidgetSet.GetClientRect(handle : HWND; var ARect : TRect) : Boolean;
|
||||
var
|
||||
Widget, ClientWidget: PGtkWidget;
|
||||
|
||||
procedure GetNoteBookClientRect(NBWidget: PGtkNotebook);
|
||||
var
|
||||
PageIndex: LongInt;
|
||||
PageWidget: PGtkWidget;
|
||||
FrameBorders: TRect;
|
||||
aWidth: LongInt;
|
||||
aHeight: LongInt;
|
||||
begin
|
||||
// get current page
|
||||
PageIndex:=gtk_notebook_get_current_page(NBWidget);
|
||||
if PageIndex>=0 then
|
||||
PageWidget:=gtk_notebook_get_nth_page(NBWidget,PageIndex)
|
||||
else
|
||||
PageWidget:=nil;
|
||||
if (PageWidget<>nil) and GTK_WIDGET_RC_STYLE(PageWidget)
|
||||
and ((PageWidget^.Allocation.Width>1) or (PageWidget^.Allocation.Height>1))
|
||||
then begin
|
||||
// get the size of the current page
|
||||
ARect.Right:=PageWidget^.Allocation.Width;
|
||||
ARect.Bottom:=PageWidget^.Allocation.Height;
|
||||
//DebugLn(['GetNoteBookClientRect using pagewidget: ',GetWidgetDebugReport(Widget),' ARect=',dbgs(aRect)]);
|
||||
end else begin
|
||||
// use defaults
|
||||
FrameBorders:=GetStyleNotebookFrameBorders;
|
||||
aWidth:=Widget^.allocation.width;
|
||||
aHeight:=Widget^.allocation.height;
|
||||
ARect:=Rect(0,0,
|
||||
Max(0,AWidth-FrameBorders.Left-FrameBorders.Right),
|
||||
Max(0,aHeight-FrameBorders.Top-FrameBorders.Bottom));
|
||||
//DebugLn(['GetNoteBookClientRect using defaults: ',GetWidgetDebugReport(Widget),' ARect=',dbgs(aRect),' Frame=',dbgs(FrameBorders)]);
|
||||
end;
|
||||
end;
|
||||
|
||||
begin
|
||||
Result := false;
|
||||
if Handle = 0 then Exit;
|
||||
ARect.Left := 0;
|
||||
ARect.Top := 0;
|
||||
Widget := {%H-}PGtkWidget(Handle);
|
||||
ClientWidget := GetFixedWidget(Widget);
|
||||
if (ClientWidget <> nil) then
|
||||
Widget := ClientWidget;
|
||||
if (Widget <> nil) then begin
|
||||
ARect.Right:=Widget^.Allocation.Width;
|
||||
ARect.Bottom:=Widget^.Allocation.Height;
|
||||
if GtkWidgetIsA(Widget,gtk_notebook_get_type) then
|
||||
GetNoteBookClientRect(PGtkNoteBook(Widget));
|
||||
end else begin
|
||||
ARect.Right:=0;
|
||||
ARect.Bottom:=0;
|
||||
end;
|
||||
{$IfDef VerboseGetClientRect}
|
||||
if ClientWidget<>nil then begin
|
||||
DebugLn('GetClientRect Widget=',GetWidgetDebugReport(PgtkWidget(Handle)),
|
||||
' Client=',DbgS(ClientWidget),WidgetFlagsToString(ClientWidget),
|
||||
' WindowSize=',dbgs(ARect.Right),',',dbgs(ARect.Bottom),
|
||||
' Allocation=',dbgs(ClientWidget^.Allocation.Width),',',dbgs(ClientWidget^.Allocation.Height)
|
||||
);
|
||||
end else begin
|
||||
DebugLn('GetClientRect Widget=',GetWidgetDebugReport(PgtkWidget(Handle)),
|
||||
' Client=',DbgS(ClientWidget),WidgetFlagsToString(ClientWidget),
|
||||
' WindowSize=',dbgs(ARect.Right),',',dbgs(ARect.Bottom),
|
||||
' Allocation=',dbgs(Widget^.Allocation.Width),',',dbgs(Widget^.Allocation.Height)
|
||||
);
|
||||
end;
|
||||
if GetLCLObject(Widget) is TCustomPage then begin
|
||||
DebugLn(['TGtk2WidgetSet.GetClientRect Rect=',dbgs(aRect),' ',GetWidgetDebugReport(Widget)]);
|
||||
end;
|
||||
{$EndIf}
|
||||
Result:=true;
|
||||
ARect := GetWidgetClientRect(PGtkWidget(Handle));
|
||||
Result := True;
|
||||
end;
|
||||
|
||||
{------------------------------------------------------------------------------
|
||||
|
@ -1078,9 +1078,7 @@ begin
|
||||
begin
|
||||
Column := gtk_tree_view_get_column(PGtkTreeView(MainView), ASubItem);
|
||||
gtk_tree_view_get_cell_area(PGtkTreeView(MainView), Path, Column, @ItemRect);
|
||||
// do not make any offset for drLabel and drIcon. issue #23094
|
||||
if not (ACode in [drIcon, drLabel]) and
|
||||
gtk_tree_view_get_headers_visible(PGtkTreeView(MainView)) then
|
||||
if gtk_tree_view_get_headers_visible(PGtkTreeView(MainView)) then
|
||||
begin
|
||||
gtk_tree_view_column_cell_get_size(gtk_tree_view_get_column(PGtkTreeView(MainView), 0),
|
||||
@ARect, @L, @T, @W, @H);
|
||||
|
Loading…
Reference in New Issue
Block a user