initial commit
[rofl0r-KOL.git] / demos / listviewchkboxes / Unit1.pas
blobe8f216e24f5ee72818c1bf20b3368359d865769c
1 { KOL MCK } // Do not remove this line!
2 {$DEFINE KOL_MCK}
3 unit Unit1;
5 interface
7 {$IFDEF KOL_MCK}
8 uses Windows, Messages, ShellAPI, KOL {$IFNDEF KOL_MCK}, mirror, Classes,
9 mckCtrls, Controls, mckObjs {$ENDIF};
10 {$ELSE}
11 {$I uses.inc}
12 Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;
13 {$ENDIF}
15 type
16 {$IFDEF KOL_MCK}
17 {$I MCKfakeClasses.inc}
18 PForm1 = ^TForm1;
19 TForm1 = object(TObj)
20 Form: PControl;
21 {$ELSE not_KOL_MCK}
22 TForm1 = class(TForm)
23 {$ENDIF KOL_MCK}
24 KOLProject1: TKOLProject;
25 KOLForm1: TKOLForm;
26 ListView1: TKOLListView;
27 ImageList1: TKOLImageList;
28 Panel1: TKOLPanel;
29 Button1: TKOLButton;
30 Timer1: TKOLTimer;
31 procedure KOLForm1FormCreate(Sender: PObj);
32 procedure Button1Click(Sender: PObj);
33 procedure ListView1MouseDown(Sender: PControl;
34 var Mouse: TMouseEventData);
35 procedure ListView1KeyDown(Sender: PControl; var Key: Integer;
36 Shift: Cardinal);
37 procedure Timer1Timer(Sender: PObj);
38 private
39 { Private declarations }
40 public
41 { Public declarations }
42 end;
44 const
45 range=10;
47 var
48 Form1 {$IFDEF KOL_MCK} : PForm1 {$ELSE} : TForm1 {$ENDIF} ;
50 {$IFDEF KOL_MCK}
51 procedure NewForm1( var Result: PForm1; AParent: PControl );
52 {$ENDIF}
54 implementation
56 //uses ... other user defined uses;
58 {$IFNDEF KOL_MCK} {$R *.DFM} {$ENDIF}
60 {$IFDEF KOL_MCK}
61 {$I Unit1_1.inc}
62 {$ENDIF}
67 procedure TForm1.KOLForm1FormCreate(Sender: PObj);
68 var
69 i: Integer;
71 begin
72 ListView1.LVColAdd('Colum1', taLeft, (ListView1.Width - 4){ div });
73 //ListView1.LVColAdd('Colum2', taLeft, (ListView1.Width - 4) div 2);
75 for i:=0 to range do
76 //ListView1.LVAdd('111', 0, [], 0, 0, 0);
77 ListView1.LVItemAdd('Item: '+Int2Str(i));
78 end;
82 procedure CheckIcon(LV: PControl; Item: Integer);
83 begin
84 if LV.LVItemImageIndex[Item]<>1 then
85 LV.LVItemImageIndex[Item]:=1
86 else
87 LV.LVItemImageIndex[Item]:=0;
88 end;
92 procedure TForm1.ListView1MouseDown(Sender: PControl;
93 var Mouse: TMouseEventData);
94 type
95 TLVHitTestInfo = packed record
96 pt: TPoint;
97 flags: DWORD;
98 iItem: Integer;
99 iSubItem: Integer;
100 end;
102 HTI: TLVHittestinfo;
104 begin
105 HTI.pt.x:=Mouse.X;
106 HTI.pt.y:=Mouse.y;
107 ListView1.Perform(LVM_HITTEST, 0, Integer(@ HTI));
108 if LongBool(HTI.flags and LVHT_ONITEMICON) then
109 CheckIcon(ListView1, HTI.iItem);
110 end;
114 procedure TForm1.ListView1KeyDown(Sender: PControl; var Key: Integer;
115 Shift: Cardinal);
116 begin
117 if Key=VK_SPACE then
118 if ListView1.CurIndex>=0 then
119 CheckIcon(ListView1, ListView1.CurIndex);
120 end;
124 procedure TForm1.Button1Click(Sender: PObj);
125 begin
126 if Timer1.Enabled then
127 begin
128 Timer1.Enabled:=False;
129 Button1.Caption:='Demonstrate';
131 else
132 begin
133 Timer1.Enabled:=True;
134 Button1.Caption:='Stop';
135 ListView1.Focused:=True;
136 end;
137 end;
141 procedure TForm1.Timer1Timer(Sender: PObj);
143 r, m: Integer;
145 begin
146 //randomize;
147 r:=random(range+1);
148 m:=random(range+1);
149 if (r>ListView1.Count) or (r>ListView1.Count) then Exit;
150 if ListView1.LVItemImageIndex[r]=0 then
151 ListView1.LVItemImageIndex[r]:=1
152 else
153 ListView1.LVItemImageIndex[r]:=0;
155 ListView1.LVSetItem(m, 0, ListView1.LVItems[m, 0], 0 , [lvisSelect], 0, 0, ListView1.LVItemData[m]);
156 end;
158 end.