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