Gtk3: implemented TCustomListView.ItemDelete, fixed crash in gtk3cellrenderer

git-svn-id: trunk@43200 -
This commit is contained in:
zeljko 2013-10-11 08:17:51 +00:00
parent a79e21d916
commit 216a903513
3 changed files with 28 additions and 11 deletions

View File

@ -662,7 +662,8 @@ procedure LCLIntfCellRenderer_CellDataFunc(cell_layout:PGtkCellLayout;
var var
LCLCellRenderer: PLCLIntfCellRenderer absolute cell; LCLCellRenderer: PLCLIntfCellRenderer absolute cell;
APath: PGtkTreePath; APath: PGtkTreePath;
Str: PgChar; S: String;
// Str: PgChar;
ListColumn: TListColumn; ListColumn: TListColumn;
ListItem: TListItem; ListItem: TListItem;
Value: TGValue; Value: TGValue;
@ -711,15 +712,14 @@ begin
else else
LCLCellRenderer^.ColumnIndex := ListColumn.Index; LCLCellRenderer^.ColumnIndex := ListColumn.Index;
S := '';
if LCLCellRenderer^.ColumnIndex <= 0 then if LCLCellRenderer^.ColumnIndex <= 0 then
Str := PgChar(ListItem.Caption) S := ListItem.Caption
else else
if ListColumn.Index-1 <= ListItem.SubItems.Count-1 then if ListColumn.Index-1 <= ListItem.SubItems.Count-1 then
Str := PgChar(ListItem.SubItems.Strings[LCLCellRenderer^.ColumnIndex-1]); S := ListItem.SubItems.Strings[LCLCellRenderer^.ColumnIndex-1];
//Value.data[0].v_pointer := PChar(Str); Value.data[0].v_pointer := PgChar(S);
//g_object_set_property(PGObject(cell), 'text', @Value);
Value.set_string(Str);
cell^.set_property('text', @Value); cell^.set_property('text', @Value);
end else end else
if (wtListBox in TGtk3Widget(Data).WidgetType) then if (wtListBox in TGtk3Widget(Data).WidgetType) then
@ -731,10 +731,10 @@ begin
cell^.get_property('text', @Value); cell^.get_property('text', @Value);
// DebugLn('PropertyType=',dbgs(Value.g_type),' IsString=',dbgs(Value.g_type = G_TYPE_STRING),' getString=',Value.get_string); // DebugLn('PropertyType=',dbgs(Value.g_type),' IsString=',dbgs(Value.g_type = G_TYPE_STRING),' getString=',Value.get_string);
Str := PgChar(TCustomListBox(TGtk3Widget(Data).LCLObject).Items.Strings[LCLCellRenderer^.Index]); S := TCustomListBox(TGtk3Widget(Data).LCLObject).Items.Strings[LCLCellRenderer^.Index];
// DebugLn('LCLCellRenderer^.Index=',dbgs(LCLCellRenderer^.Index),' text=',Str); // DebugLn('LCLCellRenderer^.Index=',dbgs(LCLCellRenderer^.Index),' text=',Str);
// Value.data[0].v_pointer := PChar(Str); Value.data[0].v_pointer := PgChar(S);
Value.set_string(Str); // Value.set_string(Str);
// set text only if we are not ownerdrawn ! // set text only if we are not ownerdrawn !
cell^.set_property('text', @Value); cell^.set_property('text', @Value);
// DebugLn('IsFixedCellSize ',dbgs(PGtkTreeView(TGtk3Widget(Data).GetContainerWidget)^.get_fixed_height_mode)); // DebugLn('IsFixedCellSize ',dbgs(PGtkTreeView(TGtk3Widget(Data).GetContainerWidget)^.get_fixed_height_mode));

View File

@ -543,6 +543,7 @@ type
procedure SetColumnWidth(AIndex: Integer; AColumn: TListColumn; AWidth: Integer); procedure SetColumnWidth(AIndex: Integer; AColumn: TListColumn; AWidth: Integer);
procedure SetColumnVisible(AIndex: Integer; AColumn: TListColumn; AVisible: Boolean); procedure SetColumnVisible(AIndex: Integer; AColumn: TListColumn; AVisible: Boolean);
procedure ItemDelete(AIndex: Integer);
procedure ItemInsert(AIndex: Integer; AItem: TListItem); procedure ItemInsert(AIndex: Integer; AItem: TListItem);
procedure ItemSetText(AIndex, ASubIndex: Integer; AItem: TListItem; const AText: String); procedure ItemSetText(AIndex, ASubIndex: Integer; AItem: TListItem; const AText: String);
procedure ItemSetState(const AIndex: Integer; const AItem: TListItem; const AState: TListItemState; procedure ItemSetState(const AIndex: Integer; const AItem: TListItem; const AState: TListItemState;
@ -5421,6 +5422,19 @@ begin
end; end;
end; end;
procedure TGtk3ListView.ItemDelete(AIndex: Integer);
var
AModel: PGtkTreeModel;
Iter: TGtkTreeIter;
begin
if IsTreeView then
AModel := PGtkTreeView(getContainerWidget)^.get_model
else
AModel := PGtkIconView(getContainerWidget)^.get_model;
if gtk_tree_model_iter_nth_child(AModel, @Iter, nil, AIndex) then
gtk_list_store_remove(PGtkListStore(AModel), @Iter);
end;
procedure TGtk3ListView.ItemInsert(AIndex: Integer; AItem: TListItem); procedure TGtk3ListView.ItemInsert(AIndex: Integer; AItem: TListItem);
var var
AModel: PGtkTreeModel; AModel: PGtkTreeModel;

View File

@ -600,7 +600,10 @@ type
class procedure TGtk3WSCustomListView.ItemDelete(const ALV: TCustomListView; class procedure TGtk3WSCustomListView.ItemDelete(const ALV: TCustomListView;
const AIndex: Integer); const AIndex: Integer);
begin begin
DebugLn('TGtk3WSCustomListView.ItemDelete '); if not WSCheckHandleAllocated(ALV, 'ItemDelete') then
Exit;
TGtk3ListView(ALV.Handle).ItemDelete(AIndex);
// DebugLn('TGtk3WSCustomListView.ItemDelete ');
// inherited ItemDelete(ALV, AIndex); // inherited ItemDelete(ALV, AIndex);
end; end;
@ -669,7 +672,7 @@ class procedure TGtk3WSCustomListView.ItemSetImage(const ALV: TCustomListView;
const AIndex: Integer; const AItem: TListItem; const ASubIndex, const AIndex: Integer; const AItem: TListItem; const ASubIndex,
AImageIndex: Integer); AImageIndex: Integer);
begin begin
DebugLn('TGtk3WSCustomListView.ItemSetImage '); // DebugLn('TGtk3WSCustomListView.ItemSetImage ');
// inherited ItemSetImage(ALV, AIndex, AItem, ASubIndex, AImageIndex); // inherited ItemSetImage(ALV, AIndex, AItem, ASubIndex, AImageIndex);
end; end;