File: gtkwschecklst.pp

package info (click to toggle)
lazarus 4.0%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 275,760 kB
  • sloc: pascal: 2,341,904; xml: 509,420; makefile: 348,726; cpp: 93,608; sh: 3,387; java: 609; perl: 297; sql: 222; ansic: 137
file content (101 lines) | stat: -rw-r--r-- 3,453 bytes parent folder | download | duplicates (4)
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
{ $Id$}
{
 *****************************************************************************
 *                             GtkWSCheckLst.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 GtkWSCheckLst;

{$mode objfpc}{$H+}

interface

uses
  CheckLst, StdCtrls, WSCheckLst, WSLCLClasses,
  {$IFDEF gtk2}
  glib2, gdk2pixbuf, gdk2, gtk2, Pango,
  {$ELSE}
  glib, gdk, gtk, gdkpixbuf, GtkFontCache,
  {$ENDIF}
  GtkInt, Classes, GTKWinApiWindow, gtkglobals, gtkproc;

type

  { TGtkWSCustomCheckListBox }

  TGtkWSCustomCheckListBox = class(TWSCustomCheckListBox)
  published
    class function  GetState(const ACheckListBox: TCustomCheckListBox;
      const AIndex: integer): TCheckBoxState; override;
    class procedure SetState(const ACheckListBox: TCustomCheckListBox;
      const AIndex: integer; const AState: TCheckBoxState); override;
  end;


implementation

class function TGtkWSCustomCheckListBox.GetState(
  const ACheckListBox: TCustomCheckListBox; const AIndex: integer
  ): TCheckBoxState;
var
  Widget     : PGtkWidget; // pointer to gtk-widget (local use when neccessary)
  ChildWidget: PGtkWidget; // generic pointer to a child gtk-widget
                            // (local use when neccessary)
  ListItem   : PGtkListItem;
begin
  Result := cbUnChecked;
  { Get the child in question of that index }
  Widget := GetWidgetInfo(Pointer(ACheckListBox.Handle),True)^.CoreWidget;
  ListItem := g_list_nth_data(PGtkList(Widget)^.children, AIndex);
  if ListItem <> nil then
  begin
    ChildWidget := PPointer(PGTKBox(PGtkBin(ListItem)^.child)^.Children^.Data)^;
    if (ChildWidget <> nil) then
    begin
      if (gtk_object_get_data(PgtkObject(ChildWidget), 'Grayed') <> nil) then
        Result:=cbGrayed
      else
      if gtk_toggle_button_get_active(PGTKToggleButton(ChildWidget)) then
        Result := cbChecked
      else
        Result := cbUnChecked;
    end;
  end;
end;

class procedure TGtkWSCustomCheckListBox.SetState(
  const ACheckListBox: TCustomCheckListBox; const AIndex: integer;
  const AState: TCheckBoxState);
var
  Widget, ChildWidget: PGtkWidget;
  ListItem: PGtkListItem;
begin
  Widget := GetWidgetInfo(Pointer(ACheckListBox.Handle), True)^.CoreWidget;
  ListItem := g_list_nth_data(PGtkList(Widget)^.children, AIndex);
  if ListItem <> nil then
  begin
    ChildWidget := PPointer(PGTKBox(PGtkBin(ListItem)^.child)^.Children^.Data)^;
    if (ChildWidget <> nil) then
    begin
      LockOnChange(PGtkObject(ChildWidget), 1);
      if AState = cbGrayed then
        gtk_object_set_data(PGtkObject(ChildWidget), 'Grayed', ChildWidget)
      else
        gtk_object_set_data(PGtkObject(ChildWidget), 'Grayed', nil);
      gtk_toggle_button_set_active(PGtkToggleButton(ChildWidget), AState = cbChecked);
      LockOnChange(PGtkObject(ChildWidget), -1);
    end;
  end;
end;

end.