fixed removing focus of a gtk listbox on delete item from Collin Western

git-svn-id: trunk@6999 -
This commit is contained in:
mattias 2005-03-21 08:12:10 +00:00
parent 62622ade38
commit 22928a36c1
3 changed files with 37 additions and 11 deletions

View File

@ -183,6 +183,19 @@ begin
end;
end;
procedure TGtkListStringList.CheckForInvalidFocus;
var
Window: PGtkWindow;
begin
{ This procedure works round a gtk problem - a deleted item may have the focus
according to an enclosing window, but the enclosing window does not notice that
the item has gone. }
Window := PGtkWindow(gtk_widget_get_ancestor(PGtkWidget(FGtkList),gtk_window_get_type));
if (Window <> nil) and (Window^.focus_widget <> nil)
and (gtk_widget_get_ancestor(Window^.focus_widget, gtk_list_get_type) = PGtkWidget(FGtkList)) then
Window^.focus_widget := nil;
end;
{------------------------------------------------------------------------------
procedure TGtkListStringList.ConnectItemCallbacks(Index: integer);
@ -577,6 +590,7 @@ begin
BeginUpdate;
RemoveAllCallbacks;
Include(FStates,glsItemCacheNeedsUpdate);
CheckForInvalidFocus;
gtk_list_clear_items(FGtkList, 0, Count);
FCachedCount:=0;
EndUpdate;
@ -609,16 +623,20 @@ begin
ReAllocMem(FCachedItems,SizeOf(PGtkListItem)*FCachedCapacity);
end;
// remove item from gtk list
{$IFDEF Gtk1}
{ Work round gtk bug - crashes if deleting first item in list
and item has focus and there are remaining items }
if (Index = 0) and (PGTKContainer(FGtkList)^.focus_child <> nil)
and (gtk_list_child_position(FGtkList,PGTKContainer(FGtkList)^.focus_child) = 0) then begin
Next := FGtkList^.children^.next;
if Next <> nil then
gtk_widget_grab_focus(Next^.data);
if Count = 0 then
CheckForInvalidFocus
else begin
{$IFDEF Gtk1}
{ Work round gtk bug - crashes if deleting first item in list
and item has focus and there are remaining items }
if (Index = 0) and (PGTKContainer(FGtkList)^.focus_child <> nil)
and (gtk_list_child_position(FGtkList,PGTKContainer(FGtkList)^.focus_child) = 0) then begin
Next := FGtkList^.children^.next;
if Next <> nil then
gtk_widget_grab_focus(Next^.data);
end;
{$ENDIF}
end;
{$ENDIF}
gtk_list_clear_items(FGtkList, Index, Index + 1);
{$IFDEF CheckGtkList}
ConsistencyCheck;
@ -976,6 +994,9 @@ end;
{ =============================================================================
$Log$
Revision 1.31 2005/03/21 08:12:10 mattias
fixed removing focus of a gtk listbox on delete item from Collin Western
Revision 1.30 2005/03/13 22:35:17 mattias
fixed deleting selected TListBox item under gtk1 from Collin

View File

@ -44,6 +44,7 @@ type
procedure Put(Index: Integer; const S: string); override;
procedure PutObject(Index: Integer; AnObject: TObject); override;
procedure SetSorted(Val : boolean); virtual;
procedure CheckForInvalidFocus;
procedure ConnectItemCallbacks(Index: integer);
procedure ConnectItemCallbacks(Li: PGtkListItem); virtual;
procedure ConnectAllCallbacks; virtual;
@ -96,6 +97,9 @@ type
{ =============================================================================
$Log$
Revision 1.11 2005/03/21 08:12:10 mattias
fixed removing focus of a gtk listbox on delete item from Collin Western
Revision 1.10 2004/07/03 11:11:08 mattias
TGTKListStringList now keeps selection on Put and Move

View File

@ -224,9 +224,7 @@ begin
FormWidget:=PGtkWidget(AForm.Handle);
FormWindow:=PGdkWindowPrivate(FormWidget^.window);
if FormWindow<>nil then begin
{$IFDEF EnableGtkWindowFocus}
GDK_WINDOW_ACTIVATE(FormWindow);
{$ENDIF}
end;
{$ENDIF}
{$ifdef gtk2}
@ -8987,6 +8985,9 @@ end;
{ =============================================================================
$Log$
Revision 1.417 2005/03/21 08:12:10 mattias
fixed removing focus of a gtk listbox on delete item from Collin Western
Revision 1.416 2005/03/20 09:45:05 mattias
disabled gtk1 focussing a window, enable it with -dEnableGtkWindowFocus