mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-10-01 22:09:51 +02:00
improved gtk2 listbox from Andrew Haines
git-svn-id: trunk@6726 -
This commit is contained in:
parent
6fa632827f
commit
a6d80046bf
@ -176,6 +176,4 @@ implementation
|
||||
Result := Assigned(klass) and (PGtkTypeClass(klass)^.thetype = GTK_TYPE_GL_AREA);
|
||||
end;
|
||||
|
||||
{$PACKRECORDS DEFAULT}
|
||||
|
||||
end.
|
||||
|
@ -100,6 +100,7 @@ var
|
||||
i, Cnt: integer;
|
||||
begin
|
||||
LockSelectionChange;
|
||||
|
||||
// save ItemIndex on destroy handle
|
||||
if ([csDestroying,csLoading]*ComponentState=[]) then
|
||||
GetItemIndex;
|
||||
|
@ -159,7 +159,7 @@ uses
|
||||
// Gtk2WSMenus,
|
||||
// Gtk2WSPairSplitter,
|
||||
// Gtk2WSSpin,
|
||||
// Gtk2WSStdCtrls,
|
||||
Gtk2WSStdCtrls,
|
||||
// Gtk2WSToolwin,
|
||||
////////////////////////////////////////////////////
|
||||
gtkProc;
|
||||
@ -595,6 +595,9 @@ end.
|
||||
|
||||
{
|
||||
$Log$
|
||||
Revision 1.38 2005/02/03 16:51:29 mattias
|
||||
improved gtk2 listbox from Andrew Haines
|
||||
|
||||
Revision 1.37 2005/01/23 11:43:38 mattias
|
||||
fixed expandingtabs in synedit painting
|
||||
|
||||
|
@ -27,21 +27,24 @@ unit Gtk2WSStdCtrls;
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, Math, Controls, Graphics,
|
||||
////////////////////////////////////////////////////
|
||||
// I M P O R T A N T
|
||||
// I M P O R T A N T
|
||||
////////////////////////////////////////////////////
|
||||
// To get as little as posible circles,
|
||||
// uncomment only when needed for registration
|
||||
////////////////////////////////////////////////////
|
||||
// StdCtrls,
|
||||
StdCtrls,
|
||||
////////////////////////////////////////////////////
|
||||
WSStdCtrls, WSLCLClasses;
|
||||
glib2, gdk2pixbuf, gdk2, gtk2, Pango,
|
||||
WSStdCtrls, WSLCLClasses, GtkWSStdCtrls, Gtk2Int, LCLType, GtkDef, LCLProc,
|
||||
GTKWinApiWindow, gtkglobals, gtkproc, InterfaceBase;
|
||||
|
||||
type
|
||||
|
||||
{ TGtk2WSScrollBar }
|
||||
|
||||
TGtk2WSScrollBar = class(TWSScrollBar)
|
||||
TGtk2WSScrollBar = class(TGtkWSScrollBar)
|
||||
private
|
||||
protected
|
||||
public
|
||||
@ -49,7 +52,7 @@ type
|
||||
|
||||
{ TGtk2WSCustomGroupBox }
|
||||
|
||||
TGtk2WSCustomGroupBox = class(TWSCustomGroupBox)
|
||||
TGtk2WSCustomGroupBox = class(TGtkWSCustomGroupBox)
|
||||
private
|
||||
protected
|
||||
public
|
||||
@ -57,7 +60,7 @@ type
|
||||
|
||||
{ TGtk2WSGroupBox }
|
||||
|
||||
TGtk2WSGroupBox = class(TWSGroupBox)
|
||||
TGtk2WSGroupBox = class(TGtkWSGroupBox)
|
||||
private
|
||||
protected
|
||||
public
|
||||
@ -65,7 +68,7 @@ type
|
||||
|
||||
{ TGtk2WSCustomComboBox }
|
||||
|
||||
TGtk2WSCustomComboBox = class(TWSCustomComboBox)
|
||||
TGtk2WSCustomComboBox = class(TGtkWSCustomComboBox)
|
||||
private
|
||||
protected
|
||||
public
|
||||
@ -73,7 +76,7 @@ type
|
||||
|
||||
{ TGtk2WSComboBox }
|
||||
|
||||
TGtk2WSComboBox = class(TWSComboBox)
|
||||
TGtk2WSComboBox = class(TGtkWSComboBox)
|
||||
private
|
||||
protected
|
||||
public
|
||||
@ -81,15 +84,19 @@ type
|
||||
|
||||
{ TGtk2WSCustomListBox }
|
||||
|
||||
TGtk2WSCustomListBox = class(TWSCustomListBox)
|
||||
TGtk2WSCustomListBox = class(TGtkWSCustomListBox)
|
||||
private
|
||||
protected
|
||||
public
|
||||
class function GetItemIndex(const ACustomListBox: TCustomListBox): integer; override;
|
||||
class procedure SetItemIndex(const ACustomListBox: TCustomListBox; const AIndex: integer); override;
|
||||
class function GetSelected(const ACustomListBox: TCustomListBox; const AIndex: integer): boolean; override;
|
||||
class function GetStrings(const ACustomListBox: TCustomListBox): TStrings; override;
|
||||
end;
|
||||
|
||||
{ TGtk2WSListBox }
|
||||
|
||||
TGtk2WSListBox = class(TWSListBox)
|
||||
TGtk2WSListBox = class(TGtkWSListBox)
|
||||
private
|
||||
protected
|
||||
public
|
||||
@ -97,7 +104,7 @@ type
|
||||
|
||||
{ TGtk2WSCustomEdit }
|
||||
|
||||
TGtk2WSCustomEdit = class(TWSCustomEdit)
|
||||
TGtk2WSCustomEdit = class(TGtkWSCustomEdit)
|
||||
private
|
||||
protected
|
||||
public
|
||||
@ -105,7 +112,7 @@ type
|
||||
|
||||
{ TGtk2WSCustomMemo }
|
||||
|
||||
TGtk2WSCustomMemo = class(TWSCustomMemo)
|
||||
TGtk2WSCustomMemo = class(TGtkWSCustomMemo)
|
||||
private
|
||||
protected
|
||||
public
|
||||
@ -113,7 +120,7 @@ type
|
||||
|
||||
{ TGtk2WSEdit }
|
||||
|
||||
TGtk2WSEdit = class(TWSEdit)
|
||||
TGtk2WSEdit = class(TGtkWSEdit)
|
||||
private
|
||||
protected
|
||||
public
|
||||
@ -121,7 +128,7 @@ type
|
||||
|
||||
{ TGtk2WSMemo }
|
||||
|
||||
TGtk2WSMemo = class(TWSMemo)
|
||||
TGtk2WSMemo = class(TGtkWSMemo)
|
||||
private
|
||||
protected
|
||||
public
|
||||
@ -129,23 +136,26 @@ type
|
||||
|
||||
{ TGtk2WSCustomLabel }
|
||||
|
||||
TGtk2WSCustomLabel = class(TWSCustomLabel)
|
||||
{
|
||||
TGtk2WSCustomLabel = class(TGtkWSCustomLabel)
|
||||
private
|
||||
protected
|
||||
public
|
||||
end;
|
||||
|
||||
}
|
||||
{ TGtk2WSLabel }
|
||||
|
||||
TGtk2WSLabel = class(TWSLabel)
|
||||
{
|
||||
TGtk2WSLabel = class(TGtkWSLabel)
|
||||
private
|
||||
protected
|
||||
public
|
||||
end;
|
||||
|
||||
}
|
||||
|
||||
{ TGtk2WSButtonControl }
|
||||
|
||||
TGtk2WSButtonControl = class(TWSButtonControl)
|
||||
TGtk2WSButtonControl = class(TGtkWSButtonControl)
|
||||
private
|
||||
protected
|
||||
public
|
||||
@ -153,7 +163,7 @@ type
|
||||
|
||||
{ TGtk2WSCustomCheckBox }
|
||||
|
||||
TGtk2WSCustomCheckBox = class(TWSCustomCheckBox)
|
||||
TGtk2WSCustomCheckBox = class(TGtkWSCustomCheckBox)
|
||||
private
|
||||
protected
|
||||
public
|
||||
@ -161,15 +171,7 @@ type
|
||||
|
||||
{ TGtk2WSCheckBox }
|
||||
|
||||
TGtk2WSCheckBox = class(TWSCheckBox)
|
||||
private
|
||||
protected
|
||||
public
|
||||
end;
|
||||
|
||||
{ TGtk2WSCheckBox }
|
||||
|
||||
TGtk2WSCheckBox = class(TWSCheckBox)
|
||||
TGtk2WSCheckBox = class(TGtkWSCheckBox)
|
||||
private
|
||||
protected
|
||||
public
|
||||
@ -177,7 +179,7 @@ type
|
||||
|
||||
{ TGtk2WSToggleBox }
|
||||
|
||||
TGtk2WSToggleBox = class(TWSToggleBox)
|
||||
TGtk2WSToggleBox = class(TGtkWSToggleBox)
|
||||
private
|
||||
protected
|
||||
public
|
||||
@ -185,7 +187,7 @@ type
|
||||
|
||||
{ TGtk2WSRadioButton }
|
||||
|
||||
TGtk2WSRadioButton = class(TWSRadioButton)
|
||||
TGtk2WSRadioButton = class(TGtkWSRadioButton)
|
||||
private
|
||||
protected
|
||||
public
|
||||
@ -193,7 +195,7 @@ type
|
||||
|
||||
{ TGtk2WSCustomStaticText }
|
||||
|
||||
TGtk2WSCustomStaticText = class(TWSCustomStaticText)
|
||||
TGtk2WSCustomStaticText = class(TGtkWSCustomStaticText)
|
||||
private
|
||||
protected
|
||||
public
|
||||
@ -201,7 +203,7 @@ type
|
||||
|
||||
{ TGtk2WSStaticText }
|
||||
|
||||
TGtk2WSStaticText = class(TWSStaticText)
|
||||
TGtk2WSStaticText = class(TGtkWSStaticText)
|
||||
private
|
||||
protected
|
||||
public
|
||||
@ -210,6 +212,119 @@ type
|
||||
|
||||
implementation
|
||||
|
||||
{ TGtk2WSCustomListBox }
|
||||
|
||||
function TGtk2WSCustomListBox.GetItemIndex(const ACustomListBox: TCustomListBox
|
||||
): integer;
|
||||
var
|
||||
Handle: HWND;
|
||||
Widget: PGtkWidget;
|
||||
TreeView: PGtkTreeView;
|
||||
Selection: PGtkTreeSelection;
|
||||
Model: PGtkTreeModel;
|
||||
ListModel: TGtkListStore;
|
||||
Iter: TGtkTreeIter;
|
||||
Path: PGtkTreePath;
|
||||
begin
|
||||
Result := -1;
|
||||
Handle := ACustomListBox.Handle;
|
||||
if Handle<>0 then
|
||||
begin
|
||||
Widget:=GetWidgetInfo(Pointer(Handle),True)^.CoreWidget;
|
||||
if GtkWidgetIsA(Widget,gtk_tree_view_get_type) then begin
|
||||
TreeView := PGtkTreeView(Widget);
|
||||
Selection := Gtk_tree_view_get_selection(TreeView);
|
||||
Model := @ListModel;
|
||||
if gtk_tree_selection_get_selected(Selection, @Model, @Iter) then begin
|
||||
Path := gtk_tree_model_get_path(Model, @Iter);
|
||||
if Path <> nil then begin
|
||||
Result := gtk_tree_path_get_indices(Path)^;
|
||||
gtk_tree_path_free(Path);
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
end;
|
||||
|
||||
procedure TGtk2WSCustomListBox.SetItemIndex(
|
||||
const ACustomListBox: TCustomListBox; const AIndex: integer);
|
||||
var
|
||||
Handle: HWND;
|
||||
Widget: PGtkWidget;
|
||||
Selection: PGtkTreeSelection;
|
||||
begin
|
||||
Handle := ACustomListBox.Handle;
|
||||
if Handle<>0 then
|
||||
begin
|
||||
Widget:=GetWidgetInfo(Pointer(Handle),True)^.CoreWidget;
|
||||
if GtkWidgetIsA(Widget,gtk_tree_view_get_type) then begin
|
||||
Selection := Gtk_tree_view_get_selection(PGtkTreeView(Widget));
|
||||
if AIndex >= 0 then
|
||||
begin
|
||||
gtk_tree_selection_select_path(Selection, PGtkTreePath(@AIndex));
|
||||
//gtk_list_select_item(PGtkList(Widget), AIndex)
|
||||
end else
|
||||
gtk_tree_selection_unselect_all(Selection);
|
||||
//gtk_list_unselect_all(PGtkList(Widget));
|
||||
end else
|
||||
raise Exception.Create('');
|
||||
end;
|
||||
end;
|
||||
|
||||
function TGtk2WSCustomListBox.GetSelected(const ACustomListBox: TCustomListBox;
|
||||
const AIndex: integer): boolean;
|
||||
var
|
||||
Handle: HWND;
|
||||
Widget: PGtkWidget; // pointer to gtk-widget (local use when neccessary)
|
||||
Selection: PGtkTreeSelection;
|
||||
ListStoreModel: PGtkTreeModel;
|
||||
Item : PGtkTreeIter;
|
||||
begin
|
||||
Result := false; { assume: nothing found }
|
||||
Handle := ACustomListBox.Handle;
|
||||
Widget:=GetWidgetInfo(Pointer(Handle),True)^.CoreWidget;
|
||||
ListStoreModel := gtk_tree_view_get_model(PGtkTreeView(Widget));
|
||||
Selection := gtk_tree_view_get_selection(PGtkTreeView(Widget));
|
||||
|
||||
if gtk_tree_model_iter_nth_child(ListStoreModel, Item, nil, AIndex) then begin
|
||||
Result := gtk_tree_selection_iter_is_selected(Selection, Item);
|
||||
end;
|
||||
end;
|
||||
|
||||
function TGtk2WSCustomListBox.GetStrings(const ACustomListBox: TCustomListBox
|
||||
): TStrings;
|
||||
var
|
||||
Widget: PGtkWidget;// pointer to gtk-widget
|
||||
Handle: HWND;
|
||||
begin
|
||||
Handle := ACustomListBox.Handle;
|
||||
case ACustomListBox.fCompStyle of
|
||||
{csCListBox:
|
||||
begin
|
||||
Widget:= GetWidgetInfo(Pointer(Handle), True)^.CoreWidget;
|
||||
|
||||
Result := TGtkCListStringList.Create(PGtkCList(Widget));
|
||||
if ACustomListBox is TCustomListBox then
|
||||
TGtkCListStringList(Result).Sorted :=
|
||||
TCustomListBox(ACustomListBox).Sorted;
|
||||
end;
|
||||
}
|
||||
csCheckListBox, csListBox:
|
||||
begin
|
||||
Widget := GetWidgetInfo(Pointer(Handle), True)^.CoreWidget;
|
||||
Result := TGtkListStoreStringList.Create(gtk_tree_view_get_model(PGtkTreeView(Widget)),
|
||||
Ord(ACustomListBox.fCompStyle = csCheckListBox) ,ACustomListBox);
|
||||
if ACustomListBox is TCustomListBox then
|
||||
TGtkListStoreStringList(Result).Sorted := ACustomListBox.Sorted;
|
||||
end;
|
||||
else
|
||||
raise Exception.Create('TGtk2WSCustomListBox.GetStrings');
|
||||
end;
|
||||
|
||||
|
||||
end;
|
||||
|
||||
initialization
|
||||
|
||||
////////////////////////////////////////////////////
|
||||
@ -223,7 +338,7 @@ initialization
|
||||
// RegisterWSComponent(TGroupBox, TGtk2WSGroupBox);
|
||||
// RegisterWSComponent(TCustomComboBox, TGtk2WSCustomComboBox);
|
||||
// RegisterWSComponent(TComboBox, TGtk2WSComboBox);
|
||||
// RegisterWSComponent(TCustomListBox, TGtk2WSCustomListBox);
|
||||
RegisterWSComponent(TCustomListBox, TGtk2WSCustomListBox);
|
||||
// RegisterWSComponent(TListBox, TGtk2WSListBox);
|
||||
// RegisterWSComponent(TCustomEdit, TGtk2WSCustomEdit);
|
||||
// RegisterWSComponent(TCustomMemo, TGtk2WSCustomMemo);
|
||||
|
Loading…
Reference in New Issue
Block a user