gtk intf: TListBox: single selection mode: when selected item is deleted switch to mode SINGLE, when item is selected switch to BROWSE mode, issue #1428

git-svn-id: trunk@10758 -
This commit is contained in:
mattias 2007-03-16 14:23:31 +00:00
parent dfa3af129d
commit 407997bc6f
6 changed files with 119 additions and 59 deletions

View File

@ -1,39 +1,15 @@
<?xml version="1.0"?> <?xml version="1.0"?>
<CONFIG> <CONFIG>
<ProjectOptions> <ProjectOptions>
<PathDelim Value="/"/>
<Version Value="5"/> <Version Value="5"/>
<General> <General>
<MainUnit Value="0"/> <MainUnit Value="0"/>
<ActiveEditorIndexAtStart Value="0"/>
<IconPath Value="./"/> <IconPath Value="./"/>
<TargetFileExt Value=""/> <TargetFileExt Value=""/>
<Title Value="Example for the Object Inspector"/> <Title Value="Example for the Object Inspector"/>
<ActiveEditorIndexAtStart Value="1"/>
</General> </General>
<JumpHistory Count="0" HistoryIndex="-1"/>
<Units Count="2">
<Unit0>
<CursorPos X="6" Y="10"/>
<EditorIndex Value="1"/>
<Filename Value="oiexample.lpr"/>
<IsPartOfProject Value="True"/>
<Loaded Value="True"/>
<TopLine Value="1"/>
<UnitName Value="OIExample"/>
<UsageCount Value="29"/>
</Unit0>
<Unit1>
<CursorPos X="6" Y="21"/>
<EditorIndex Value="0"/>
<Filename Value="mainunit.pas"/>
<ComponentName Value="Form1"/>
<IsPartOfProject Value="True"/>
<Loaded Value="True"/>
<ResourceFilename Value="mainunit.lrs"/>
<TopLine Value="1"/>
<UnitName Value="MainUnit"/>
<UsageCount Value="29"/>
</Unit1>
</Units>
<PublishOptions> <PublishOptions>
<Version Value="2"/> <Version Value="2"/>
<IgnoreBinaries Value="False"/> <IgnoreBinaries Value="False"/>
@ -51,9 +27,48 @@
<PackageName Value="IDEIntf"/> <PackageName Value="IDEIntf"/>
</Item1> </Item1>
</RequiredPackages> </RequiredPackages>
<Units Count="3">
<Unit0>
<Filename Value="oiexample.lpr"/>
<IsPartOfProject Value="True"/>
<UnitName Value="OIExample"/>
<CursorPos X="6" Y="10"/>
<TopLine Value="1"/>
<EditorIndex Value="2"/>
<UsageCount Value="29"/>
<Loaded Value="True"/>
</Unit0>
<Unit1>
<Filename Value="mainunit.pas"/>
<ComponentName Value="Form1"/>
<IsPartOfProject Value="True"/>
<ResourceFilename Value="mainunit.lrs"/>
<UnitName Value="MainUnit"/>
<CursorPos X="22" Y="28"/>
<TopLine Value="1"/>
<EditorIndex Value="0"/>
<UsageCount Value="29"/>
<Loaded Value="True"/>
</Unit1>
<Unit2>
<Filename Value="../../lcl/interfaces/win32/win32int.pp"/>
<UnitName Value="Win32Int"/>
<CursorPos X="10" Y="23"/>
<TopLine Value="14"/>
<EditorIndex Value="1"/>
<UsageCount Value="10"/>
<Loaded Value="True"/>
</Unit2>
</Units>
<JumpHistory Count="1" HistoryIndex="0">
<Position1>
<Filename Value="../../lcl/interfaces/win32/win32int.pp"/>
<Caret Line="1" Column="1" TopLine="1"/>
</Position1>
</JumpHistory>
</ProjectOptions> </ProjectOptions>
<CompilerOptions> <CompilerOptions>
<Version Value="3"/> <Version Value="5"/>
<SearchPaths> <SearchPaths>
<OtherUnitFiles Value="$(LazarusDir)/components/units/"/> <OtherUnitFiles Value="$(LazarusDir)/components/units/"/>
<LCLWidgetType Value="gtk"/> <LCLWidgetType Value="gtk"/>

View File

@ -3241,6 +3241,7 @@ function gtkListBoxSelectionChangedAfter(widget: PGtkWidget; data: gPointer
): GBoolean; cdecl; ): GBoolean; cdecl;
var var
Mess: TLMessage; Mess: TLMessage;
GtkList: PGtkList;
begin begin
Result := CallBackDefaultReturn; Result := CallBackDefaultReturn;
{$IFDEF EventTrace} {$IFDEF EventTrace}
@ -3248,27 +3249,14 @@ begin
{$ENDIF} {$ENDIF}
FillChar(Mess,SizeOf(Mess),0); FillChar(Mess,SizeOf(Mess),0);
Mess.msg := LM_SelChange; Mess.msg := LM_SelChange;
if (data=nil) or (PGtkList(widget)^.selection<>nil) then GtkList:=PGtkList(widget);
if (data=nil) or (GtkList^.selection<>nil) then begin
if gtkListGetSelectionMode(GtkList)=GTK_SELECTION_SINGLE then
gtk_list_set_selection_mode(GtkList,GTK_SELECTION_BROWSE);
DeliverMessage(Data, Mess); DeliverMessage(Data, Mess);
end;
end; end;
function gtkListSelectChild(widget: PGtkWidget; child: PGtkWidget;
data: gPointer): GBoolean; cdecl;
var
Mess: TLMessage;
begin
Result := CallBackDefaultReturn;
if LockOnChange(PgtkObject(TWinControl(Data).Handle),0) > 0 then Exit;
{$IFDEF EventTrace}
EventTrace('gtkListSelectChild', data);
{$ENDIF}
FillChar(Mess,SizeOf(Mess),0);
Mess.msg := LM_SelChange;
DeliverMessage(Data, Mess);
end;
{$I gtkDragCallback.inc} {$I gtkDragCallback.inc}
{$I gtkListViewCallback.inc} {$I gtkListViewCallback.inc}
{$I gtkComboBoxCallback.inc} {$I gtkComboBoxCallback.inc}

View File

@ -234,6 +234,7 @@ begin
Mess.Result := 0; Mess.Result := 0;
DeliverMessage(LCLList.Owner, Mess); DeliverMessage(LCLList.Owner, Mess);
end; end;
{*************************************************************} {*************************************************************}
{ TGtkListStringList methods } { TGtkListStringList methods }
{*************************************************************} {*************************************************************}
@ -785,6 +786,11 @@ begin
end; end;
Include(FStates,glsItemCacheNeedsUpdate); Include(FStates,glsItemCacheNeedsUpdate);
CheckForInvalidFocus; CheckForInvalidFocus;
if gtkListGetSelectionMode(FGtkList)=GTK_SELECTION_BROWSE then begin
// GTK_SELECTION_BROWSE always auto selects one child
// -> disable it and enable it when a selection is needed
gtk_list_set_selection_mode(FGtkList,GTK_SELECTION_SINGLE);
end;
gtk_list_clear_items(FGtkList, 0, Count); gtk_list_clear_items(FGtkList, 0, Count);
FCachedCount:=0; FCachedCount:=0;
EndUpdate; EndUpdate;
@ -821,6 +827,15 @@ begin
FCachedCapacity:=FCachedCapacity shr 1; FCachedCapacity:=FCachedCapacity shr 1;
ReAllocMem(FCachedItems,SizeOf(PGtkListItem)*FCachedCapacity); ReAllocMem(FCachedItems,SizeOf(PGtkListItem)*FCachedCapacity);
end; end;
// change selection mode if needed
if (gtkListGetSelectionMode(FGtkList)=GTK_SELECTION_BROWSE)
and (FGtkList^.selection<>nil)
and (g_list_nth_data(FGtkList^.children, Index)=FGtkList^.selection) then begin
// item is selected and BROWSE mode is enabled
// -> change selection mode to prevent, that gtk auto selects another child
gtk_list_set_selection_mode(FGtkList,GTK_SELECTION_SINGLE);
end;
// remove item from gtk list // remove item from gtk list
if Count = 0 then if Count = 0 then
CheckForInvalidFocus CheckForInvalidFocus
@ -839,6 +854,7 @@ begin
end; end;
gtk_list_clear_items(FGtkList, Index, Index + 1); gtk_list_clear_items(FGtkList, Index, Index + 1);
Include(FStates,glsItemCacheNeedsUpdate); Include(FStates,glsItemCacheNeedsUpdate);
{$IFDEF CheckGtkList} {$IFDEF CheckGtkList}
ConsistencyCheck; ConsistencyCheck;
{$ENDIF} {$ENDIF}

View File

@ -3478,6 +3478,8 @@ end;
var var
AControl: TWinControl; AControl: TWinControl;
SelectionMode: TGtkSelectionMode; SelectionMode: TGtkSelectionMode;
GtkList: PGtkList;
GtkCList: PGtkCList;
begin begin
AControl:=TWinControl(Sender); AControl:=TWinControl(Sender);
if (AControl is TWinControl) and if (AControl is TWinControl) and
@ -3489,19 +3491,28 @@ begin
then SelectionMode:= GTK_SELECTION_EXTENDED then SelectionMode:= GTK_SELECTION_EXTENDED
else SelectionMode:= GTK_SELECTION_MULTIPLE; else SelectionMode:= GTK_SELECTION_MULTIPLE;
end end
else else begin
SelectionMode:= GTK_SELECTION_SINGLE; SelectionMode:= GTK_SELECTION_BROWSE;
end;
case AControl.fCompStyle of case AControl.fCompStyle of
csListBox, csCheckListBox: csListBox, csCheckListBox:
gtk_list_set_selection_mode(PGtkList( begin
GetWidgetInfo(Widget, True)^.CoreWidget), GtkList:=PGtkList(GetWidgetInfo(Widget, True)^.CoreWidget);
SelectionMode); if (GtkList^.selection=nil)
and (SelectionMode=GTK_SELECTION_BROWSE) then
SelectionMode:=GTK_SELECTION_SINGLE;
gtk_list_set_selection_mode(GtkList,SelectionMode);
end;
csCListBox: csCListBox:
gtk_clist_set_selection_mode(PGtkCList( begin
GetWidgetInfo(Widget, True)^.CoreWidget), GtkCList:=PGtkCList(GetWidgetInfo(Widget, True)^.CoreWidget);
SelectionMode); if (GtkCList^.selection=nil)
and (SelectionMode=GTK_SELECTION_BROWSE) then
SelectionMode:=GTK_SELECTION_SINGLE;
gtk_clist_set_selection_mode(GtkCList,SelectionMode);
end;
else else
Assert (true, 'WARNING:[TGtkWidgetSet.IntSendMessage3] usage of LM_SETSELMODE unimplemented for actual component'); Assert (true, 'WARNING:[TGtkWidgetSet.IntSendMessage3] usage of LM_SETSELMODE unimplemented for actual component');
@ -4868,6 +4879,7 @@ var
Widget: PGtkCombo; Widget: PGtkCombo;
ItemList: TGtkListStringList; ItemList: TGtkListStringList;
ComboBox: TComboBox; ComboBox: TComboBox;
GtkList: PGtkList;
begin begin
ComboBox:=TComboBox(ComboBoxObject); ComboBox:=TComboBox(ComboBoxObject);
Result:= gtk_combo_new(); Result:= gtk_combo_new();
@ -4880,17 +4892,21 @@ begin
// Prevents the OnSelect event be fired after inserting the first item // Prevents the OnSelect event be fired after inserting the first item
// or deleting the selected item // or deleting the selected item
gtk_list_set_selection_mode(PGtkList(Widget^.List),GTK_SELECTION_SINGLE); GtkList:=PGtkList(Widget^.List);
if GtkList^.selection=nil then
gtk_list_set_selection_mode(GtkList,GTK_SELECTION_SINGLE)
else
gtk_list_set_selection_mode(GtkList,GTK_SELECTION_BROWSE);
// Items // Items
ItemList:= TGtkListStringList.Create(PGtkList(Widget^.List),ComboBox,False); ItemList:= TGtkListStringList.Create(GtkList,ComboBox,False);
gtk_object_set_data(PGtkObject(Widget), GtkListItemLCLListTag, ItemList); gtk_object_set_data(PGtkObject(Widget), GtkListItemLCLListTag, ItemList);
ItemList.Assign(ComboBox.Items); ItemList.Assign(ComboBox.Items);
ItemList.Sorted:= ComboBox.Sorted; ItemList.Sorted:= ComboBox.Sorted;
// ItemIndex // ItemIndex
if ComboBox.ItemIndex >= 0 then if ComboBox.ItemIndex >= 0 then
gtk_list_select_item(PGtkList(Widget^.list), ComboBox.ItemIndex); gtk_list_select_item(GtkList, ComboBox.ItemIndex);
// MaxLength // MaxLength
gtk_entry_set_max_length(PGtkEntry(Widget^.entry),guint16(ComboBox.MaxLength)); gtk_entry_set_max_length(PGtkEntry(Widget^.entry),guint16(ComboBox.MaxLength));

View File

@ -6152,6 +6152,28 @@ begin
end; end;
end; end;
function gtkListSelectChild(widget: PGtkWidget; child: PGtkWidget;
data: gPointer): GBoolean; cdecl;
var
Mess: TLMessage;
begin
Result := CallBackDefaultReturn;
if LockOnChange(PgtkObject(TWinControl(Data).Handle),0) > 0 then Exit;
{$IFDEF EventTrace}
EventTrace('gtkListSelectChild', data);
{$ENDIF}
FillChar(Mess,SizeOf(Mess),0);
Mess.msg := LM_SelChange;
DeliverMessage(Data, Mess);
end;
function gtkListGetSelectionMode(list: PGtkList): TGtkSelectionMode; cdecl;
begin
Result:=TGtkSelectionMode(
(list^.flag0 and bm_TGtkList_selection_mode) shr bp_TGtkList_selection_mode);
end;
{------------------------------------------------------------------------------ {------------------------------------------------------------------------------
SaveSizeNotification SaveSizeNotification
Params: Widget: PGtkWidget A widget that is the handle of a lcl control. Params: Widget: PGtkWidget A widget that is the handle of a lcl control.

View File

@ -231,9 +231,6 @@ procedure GTKStyleChanged(Widget: PGtkWidget; previous_style :
function gtkListBoxSelectionChangedAfter(widget: PGtkWidget; function gtkListBoxSelectionChangedAfter(widget: PGtkWidget;
data: gPointer): GBoolean; cdecl; data: gPointer): GBoolean; cdecl;
function gtkListSelectChild(widget: PGtkWidget;child : PGtkWidget;
data: gPointer): GBoolean; cdecl;
// gtkDragCallback.inc headers // gtkDragCallback.inc headers
Function edit_drag_data_received(widget: pgtkWidget; Function edit_drag_data_received(widget: pgtkWidget;
Context: pGdkDragContext; Context: pGdkDragContext;
@ -686,6 +683,12 @@ procedure UpdateStatusBarPanels(StatusBar: TObject;
procedure UpdateStatusBarPanel(StatusBar: TObject; Index: integer; procedure UpdateStatusBarPanel(StatusBar: TObject; Index: integer;
StatusPanelWidget: PGtkWidget); StatusPanelWidget: PGtkWidget);
// list
function gtkListSelectChild(widget: PGtkWidget;child : PGtkWidget;
data: gPointer): GBoolean; cdecl;
function gtkListGetSelectionMode(list: PGtkList): TGtkSelectionMode;cdecl;
// sizing // sizing
procedure SaveSizeNotification(Widget: PGtkWidget); procedure SaveSizeNotification(Widget: PGtkWidget);
procedure SaveClientSizeNotification(FixWidget: PGtkWidget); procedure SaveClientSizeNotification(FixWidget: PGtkWidget);