1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
|
{
*****************************************************************************
* Gtk3WSCheckLst.pp *
* ----------------- *
* *
* *
*****************************************************************************
*****************************************************************************
This file is part of the Lazarus Component Library (LCL)
See the file COPYING.modifiedLGPL.txt, included in this distribution,
for details about the license.
*****************************************************************************
}
unit Gtk3WSCheckLst;
{$i gtk3defines.inc}
{$mode objfpc}{$H+}
interface
uses
LazGObject2, LazGtk3, LazGLib2,
gtk3widgets,
////////////////////////////////////////////////////
// I M P O R T A N T
////////////////////////////////////////////////////
// To get as little as posible circles,
// uncomment only when needed for registration
////////////////////////////////////////////////////
CheckLst, StdCtrls, Controls, LCLType, SysUtils, Classes, LMessages, LCLProc,
////////////////////////////////////////////////////
WSCheckLst, WSLCLClasses, WSProc;
type
{ TGtk3WSCheckListBox }
{ TGtk3WSCustomCheckListBox }
TGtk3WSCustomCheckListBox = class(TWSCustomCheckListBox)
published
class function CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLIntfHandle; override;
class function GetItemEnabled(const ACheckListBox: TCustomCheckListBox;
const AIndex: integer): Boolean; override;
class function GetState(const ACheckListBox: TCustomCheckListBox;
const AIndex: integer): TCheckBoxState; override;
class procedure SetItemEnabled(const ACheckListBox: TCustomCheckListBox;
const AIndex: integer; const AEnabled: Boolean); override;
class procedure SetState(const ACheckListBox: TCustomCheckListBox;
const AIndex: integer; const AState: TCheckBoxState); override;
end;
implementation
uses
Gtk3WSControls, gtk3procs;
{ TGtk3WSCheckListBox }
class function TGtk3WSCustomCheckListBox.CreateHandle(
const AWinControl: TWinControl; const AParams: TCreateParams): TLCLIntfHandle;
begin
// DebugLn('>TGtk3WSCustomCheckListBox.CreateHandle');
Result := TLCLIntfHandle(TGtk3CheckListBox.Create(AWinControl, AParams));
// DebugLn('<TGtk3WSCustomCheckListBox.CreateHandle: Result=',dbgHex(Result));
end;
class function TGtk3WSCustomCheckListBox.GetItemEnabled(
const ACheckListBox: TCustomCheckListBox; const AIndex: integer): Boolean;
var
Iter : TGtkTreeIter;
TreeView: PGtkTreeView;
ListStore: PGtkTreeModel;
Disabled: gboolean;
begin
Result := False;
if not WSCheckHandleAllocated(ACheckListBox, 'GetItemEnabled') then
Exit;
// DebugLn('TGtk3WSCustomCheckListBox.GetItemEnabled AIndex=',dbgs(AIndex));
TreeView := PGtkTreeView(TGtk3CheckListBox(ACheckListBox.Handle).GetContainerWidget);
ListStore := gtk_tree_view_get_model(TreeView);
if gtk_tree_model_iter_nth_child(ListStore, @Iter, nil, AIndex) then
begin
gtk_tree_model_get(ListStore, @Iter, [gtk3CLBDisabled, @Disabled, -1]);
Result := not Disabled;
end;
end;
class function TGtk3WSCustomCheckListBox.GetState(
const ACheckListBox: TCustomCheckListBox; const AIndex: integer
): TCheckBoxState;
var
Iter : TGtkTreeIter;
TreeView: PGtkTreeView;
ListStore: PGtkTreeModel;
b: byte;
begin
Result := cbUnchecked;
if not WSCheckHandleAllocated(ACheckListBox, 'GetState') then
Exit;
// DebugLn('TGtk3WSCustomCheckListBox.GetState AIndex=',dbgs(AIndex));
TreeView := PGtkTreeView(TGtk3CheckListBox(ACheckListBox.Handle).GetContainerWidget);
ListStore := gtk_tree_view_get_model(TreeView);
if gtk_tree_model_iter_nth_child(ListStore, @Iter, nil, AIndex) then
begin
gtk_tree_model_get(ListStore, @Iter, [gtk3CLBState, @b, -1]);
Result := TCheckBoxState(b);
end;
end;
class procedure TGtk3WSCustomCheckListBox.SetItemEnabled(
const ACheckListBox: TCustomCheckListBox; const AIndex: integer;
const AEnabled: Boolean);
var
Iter : TGtkTreeIter;
TreeView: PGtkTreeView;
ListStore: PGtkTreeModel;
Disabled: gboolean;
begin
if not WSCheckHandleAllocated(ACheckListBox, 'SetItemEnabled') then
Exit;
// DebugLn('TGtk3WSCustomCheckListBox.SetItemEnabled AIndex=',dbgs(AIndex),' AEnabled=',dbgs(AEnabled));
TreeView := PGtkTreeView(TGtk3CheckListBox(ACheckListBox.Handle).GetContainerWidget);
ListStore := gtk_tree_view_get_model(TreeView);
if gtk_tree_model_iter_nth_child(ListStore, @Iter, nil, AIndex) then
begin
Disabled := not AEnabled;
gtk_list_store_set(PGtkListStore(ListStore), @Iter, [gtk3CLBDisabled, Disabled, -1]);
end;
end;
class procedure TGtk3WSCustomCheckListBox.SetState(
const ACheckListBox: TCustomCheckListBox; const AIndex: integer;
const AState: TCheckBoxState);
var
Iter : TGtkTreeIter;
TreeView: PGtkTreeView;
ListStore: PGtkTreeModel;
begin
if not WSCheckHandleAllocated(ACheckListBox, 'SetState') then
Exit;
// DebugLn('TGtk3WSCustomCheckListBox.SetState AIndex=',dbgs(AIndex),' AEnabled=',dbgs(Ord(AState)));
TreeView := PGtkTreeView(TGtk3CheckListBox(ACheckListBox.Handle).GetContainerWidget);
ListStore := gtk_tree_view_get_model(TreeView);
if gtk_tree_model_iter_nth_child(ListStore, @Iter, nil, AIndex) then
gtk_list_store_set(PGtkListStore(ListStore), @Iter, [gtk3CLBState, Byte(AState), -1]);
end;
end.
|