Gtk2: implemented TGtk2CustomListView.ItemDisplayRect, implemented editor for listview with style vsSmallIcon, vsIcon. issue

git-svn-id: trunk@38897 -
This commit is contained in:
zeljko 2012-09-29 11:14:16 +00:00
parent 0eef8e9087
commit 53848b11b5
4 changed files with 59 additions and 5 deletions

View File

@ -323,6 +323,7 @@ function gtk_icon_view_get_cursor(icon_view: PGtkIconView; var path: PGtkTreePat
procedure gtk_icon_view_set_cursor(icon_view: PGtkIconView; path: PGtkTreePath; cell: PGtkCellRenderer; start_editing: gboolean); cdecl; external gtklib;
function gtk_tree_view_get_visible_range(tree_view: PGtkTreeView; out start_path, endpath: PGtkTreePath): gboolean; cdecl; external gtklib;
function gtk_icon_view_get_visible_range(tree_view: PGtkTreeView; out start_path, endpath: PGtkTreePath): gboolean; cdecl; external gtklib;
function gtk_icon_view_get_item_at_pos(icon_view: PGtkIconView; x: gint; y: gint; var path: PGtkTreePath; var cell: PGtkCellRenderer): gboolean; cdecl; external gtklib;
procedure gtk_tree_view_column_queue_resize(tree_column: PGtkTreeViewColumn); cdecl; external gtklib;

View File

@ -31,7 +31,7 @@ uses
GLib2, Gtk2, Gdk2, Gdk2pixbuf,
// RTL, FCL, LCL
ComCtrls, Classes, LCLType, LMessages, Controls, Graphics,
StdCtrls, Forms, LCLProc, ImgList, Math, Sysutils, InterfaceBase,
StdCtrls, Forms, LCLProc, LCLIntf, ImgList, Math, Sysutils, InterfaceBase,
// widgetset
WSComCtrls, WSLCLClasses, WSControls, WSProc,
// GtkWidgetset

View File

@ -470,6 +470,8 @@ function Gtk2TreeViewEditorEvent(widget: PGtkWidget; event: PGdkEvent; data: GPo
var
R: TRect;
Alloc: TGtkAllocation;
w: PGtkWidget;
AOrientation: TGtkOrientation;
begin
Result := CallBackDefaultReturn;
case event^._type of
@ -490,6 +492,20 @@ begin
end;
gtk_widget_size_allocate(Widget, @Alloc);
end;
end else
begin
w := gtk_widget_get_parent(Widget);
if Assigned(w) and GTK_IS_ICON_VIEW(w) then
begin
//gtk2 does not layout items correctly when iconArrangement is iaTop.
//so we force it to do so.
AOrientation := gtk_icon_view_get_orientation(PGtkIconView(w));
if AOrientation = GTK_ORIENTATION_HORIZONTAL then
gtk_icon_view_set_orientation(PGtkIconView(w), GTK_ORIENTATION_VERTICAL)
else
gtk_icon_view_set_orientation(PGtkIconView(w), GTK_ORIENTATION_HORIZONTAL);
gtk_icon_view_set_orientation(PGtkIconView(w), AOrientation)
end;
end;
end;
end;
@ -520,8 +536,7 @@ begin
// gtk2 is pretty tricky about adding editor into control
if (AParent.FCompStyle = csListView) and
(TWinControl(AControl).FCompStyle = csEdit) and
GTK_IS_TREE_VIEW(gtk_bin_get_child(PGtkBin(PFixed))) then
(TWinControl(AControl).FCompStyle = csEdit) then
begin
ChildWidget := {%H-}PGtkWidget(TWinControl(AControl).Handle);
ParentWidget := gtk_bin_get_child(PGtkBin(PFixed)); // treeview

View File

@ -1055,8 +1055,11 @@ var
ItemRect: TGdkRectangle;
Column: PGtkTreeViewColumn;
Path: PGtkTreePath;
L, T, W, H: GInt;
X, Y, L, T, W, H: GInt;
ARect: TGdkRectangle;
R: TRect;
ANewCell: PGtkCellRenderer;
ANewPath: PGtkTreePath;
begin
Result := Rect(0, 0, 0, 0);
if not WSCheckHandleAllocated(ALV, 'ItemDisplayRect') then
@ -1083,11 +1086,46 @@ begin
else
if GTK_IS_ICON_VIEW(MainView) then
begin
// TODO: iconview
ItemRect.x := 0;
ItemRect.y := 0;
ItemRect.width := gtk_icon_view_get_item_width(PGtkIconView(MainView));
ItemRect.height := 0;
if Path <> nil then
begin
ANewPath := nil;
ANewCell := nil;
R := ALV.ClientRect;
l := 0;
t := 0;
Result := Rect(0, 0, 0, 0);
while t < R.Bottom - 1 do
begin
l := 0;
while l < R.Right - 1 do
begin
if gtk_icon_view_get_item_at_pos(PGtkIconView(MainView), l, t, ANewPath, ANewCell) then
begin
if (ANewPath <> nil) and (gtk_tree_path_compare(Path, ANewPath) = 0) then
begin
gtk_cell_renderer_get_size(ANewCell, PGtkWidget(MainView), @ItemRect, @x,@y,@w,@h);
Result := Rect(l, t, w + l, h + t);
ItemRect := GdkRectFromRect(Result);
if ANewPath <> nil then
gtk_tree_path_free(ANewPath);
break;
end;
if ANewPath <> nil then
gtk_tree_path_free(ANewPath);
end;
inc(l, 1);
end;
inc(t, 1);
if not IsRectEmpty(Result) then
break;
end;
end;
end;
finally
gtk_tree_path_free(Path);