mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-18 20:49:27 +02:00
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:
parent
dfa3af129d
commit
407997bc6f
@ -1,39 +1,15 @@
|
||||
<?xml version="1.0"?>
|
||||
<CONFIG>
|
||||
<ProjectOptions>
|
||||
<PathDelim Value="/"/>
|
||||
<Version Value="5"/>
|
||||
<General>
|
||||
<MainUnit Value="0"/>
|
||||
<ActiveEditorIndexAtStart Value="0"/>
|
||||
<IconPath Value="./"/>
|
||||
<TargetFileExt Value=""/>
|
||||
<Title Value="Example for the Object Inspector"/>
|
||||
<ActiveEditorIndexAtStart Value="1"/>
|
||||
</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>
|
||||
<Version Value="2"/>
|
||||
<IgnoreBinaries Value="False"/>
|
||||
@ -51,9 +27,48 @@
|
||||
<PackageName Value="IDEIntf"/>
|
||||
</Item1>
|
||||
</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>
|
||||
<CompilerOptions>
|
||||
<Version Value="3"/>
|
||||
<Version Value="5"/>
|
||||
<SearchPaths>
|
||||
<OtherUnitFiles Value="$(LazarusDir)/components/units/"/>
|
||||
<LCLWidgetType Value="gtk"/>
|
||||
|
@ -3241,6 +3241,7 @@ function gtkListBoxSelectionChangedAfter(widget: PGtkWidget; data: gPointer
|
||||
): GBoolean; cdecl;
|
||||
var
|
||||
Mess: TLMessage;
|
||||
GtkList: PGtkList;
|
||||
begin
|
||||
Result := CallBackDefaultReturn;
|
||||
{$IFDEF EventTrace}
|
||||
@ -3248,27 +3249,14 @@ begin
|
||||
{$ENDIF}
|
||||
FillChar(Mess,SizeOf(Mess),0);
|
||||
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);
|
||||
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 gtkListViewCallback.inc}
|
||||
{$I gtkComboBoxCallback.inc}
|
||||
|
@ -234,6 +234,7 @@ begin
|
||||
Mess.Result := 0;
|
||||
DeliverMessage(LCLList.Owner, Mess);
|
||||
end;
|
||||
|
||||
{*************************************************************}
|
||||
{ TGtkListStringList methods }
|
||||
{*************************************************************}
|
||||
@ -785,6 +786,11 @@ begin
|
||||
end;
|
||||
Include(FStates,glsItemCacheNeedsUpdate);
|
||||
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);
|
||||
FCachedCount:=0;
|
||||
EndUpdate;
|
||||
@ -821,6 +827,15 @@ begin
|
||||
FCachedCapacity:=FCachedCapacity shr 1;
|
||||
ReAllocMem(FCachedItems,SizeOf(PGtkListItem)*FCachedCapacity);
|
||||
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
|
||||
if Count = 0 then
|
||||
CheckForInvalidFocus
|
||||
@ -839,6 +854,7 @@ begin
|
||||
end;
|
||||
gtk_list_clear_items(FGtkList, Index, Index + 1);
|
||||
Include(FStates,glsItemCacheNeedsUpdate);
|
||||
|
||||
{$IFDEF CheckGtkList}
|
||||
ConsistencyCheck;
|
||||
{$ENDIF}
|
||||
|
@ -3478,6 +3478,8 @@ end;
|
||||
var
|
||||
AControl: TWinControl;
|
||||
SelectionMode: TGtkSelectionMode;
|
||||
GtkList: PGtkList;
|
||||
GtkCList: PGtkCList;
|
||||
begin
|
||||
AControl:=TWinControl(Sender);
|
||||
if (AControl is TWinControl) and
|
||||
@ -3489,19 +3491,28 @@ begin
|
||||
then SelectionMode:= GTK_SELECTION_EXTENDED
|
||||
else SelectionMode:= GTK_SELECTION_MULTIPLE;
|
||||
end
|
||||
else
|
||||
SelectionMode:= GTK_SELECTION_SINGLE;
|
||||
else begin
|
||||
SelectionMode:= GTK_SELECTION_BROWSE;
|
||||
end;
|
||||
case AControl.fCompStyle of
|
||||
|
||||
csListBox, csCheckListBox:
|
||||
gtk_list_set_selection_mode(PGtkList(
|
||||
GetWidgetInfo(Widget, True)^.CoreWidget),
|
||||
SelectionMode);
|
||||
begin
|
||||
GtkList:=PGtkList(GetWidgetInfo(Widget, True)^.CoreWidget);
|
||||
if (GtkList^.selection=nil)
|
||||
and (SelectionMode=GTK_SELECTION_BROWSE) then
|
||||
SelectionMode:=GTK_SELECTION_SINGLE;
|
||||
gtk_list_set_selection_mode(GtkList,SelectionMode);
|
||||
end;
|
||||
|
||||
csCListBox:
|
||||
gtk_clist_set_selection_mode(PGtkCList(
|
||||
GetWidgetInfo(Widget, True)^.CoreWidget),
|
||||
SelectionMode);
|
||||
begin
|
||||
GtkCList:=PGtkCList(GetWidgetInfo(Widget, True)^.CoreWidget);
|
||||
if (GtkCList^.selection=nil)
|
||||
and (SelectionMode=GTK_SELECTION_BROWSE) then
|
||||
SelectionMode:=GTK_SELECTION_SINGLE;
|
||||
gtk_clist_set_selection_mode(GtkCList,SelectionMode);
|
||||
end;
|
||||
|
||||
else
|
||||
Assert (true, 'WARNING:[TGtkWidgetSet.IntSendMessage3] usage of LM_SETSELMODE unimplemented for actual component');
|
||||
@ -4868,6 +4879,7 @@ var
|
||||
Widget: PGtkCombo;
|
||||
ItemList: TGtkListStringList;
|
||||
ComboBox: TComboBox;
|
||||
GtkList: PGtkList;
|
||||
begin
|
||||
ComboBox:=TComboBox(ComboBoxObject);
|
||||
Result:= gtk_combo_new();
|
||||
@ -4880,17 +4892,21 @@ begin
|
||||
|
||||
// Prevents the OnSelect event be fired after inserting the first 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
|
||||
ItemList:= TGtkListStringList.Create(PGtkList(Widget^.List),ComboBox,False);
|
||||
ItemList:= TGtkListStringList.Create(GtkList,ComboBox,False);
|
||||
gtk_object_set_data(PGtkObject(Widget), GtkListItemLCLListTag, ItemList);
|
||||
ItemList.Assign(ComboBox.Items);
|
||||
ItemList.Sorted:= ComboBox.Sorted;
|
||||
|
||||
// ItemIndex
|
||||
if ComboBox.ItemIndex >= 0 then
|
||||
gtk_list_select_item(PGtkList(Widget^.list), ComboBox.ItemIndex);
|
||||
gtk_list_select_item(GtkList, ComboBox.ItemIndex);
|
||||
|
||||
// MaxLength
|
||||
gtk_entry_set_max_length(PGtkEntry(Widget^.entry),guint16(ComboBox.MaxLength));
|
||||
|
@ -6152,6 +6152,28 @@ begin
|
||||
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
|
||||
Params: Widget: PGtkWidget A widget that is the handle of a lcl control.
|
||||
|
@ -231,9 +231,6 @@ procedure GTKStyleChanged(Widget: PGtkWidget; previous_style :
|
||||
function gtkListBoxSelectionChangedAfter(widget: PGtkWidget;
|
||||
data: gPointer): GBoolean; cdecl;
|
||||
|
||||
function gtkListSelectChild(widget: PGtkWidget;child : PGtkWidget;
|
||||
data: gPointer): GBoolean; cdecl;
|
||||
|
||||
// gtkDragCallback.inc headers
|
||||
Function edit_drag_data_received(widget: pgtkWidget;
|
||||
Context: pGdkDragContext;
|
||||
@ -686,6 +683,12 @@ procedure UpdateStatusBarPanels(StatusBar: TObject;
|
||||
procedure UpdateStatusBarPanel(StatusBar: TObject; Index: integer;
|
||||
StatusPanelWidget: PGtkWidget);
|
||||
|
||||
// list
|
||||
function gtkListSelectChild(widget: PGtkWidget;child : PGtkWidget;
|
||||
data: gPointer): GBoolean; cdecl;
|
||||
function gtkListGetSelectionMode(list: PGtkList): TGtkSelectionMode;cdecl;
|
||||
|
||||
|
||||
// sizing
|
||||
procedure SaveSizeNotification(Widget: PGtkWidget);
|
||||
procedure SaveClientSizeNotification(FixWidget: PGtkWidget);
|
||||
|
Loading…
Reference in New Issue
Block a user