/usr/lib/lazarus/0.9.30.4/lcl/checklst.pas is in lazarus-src-0.9.30.4 0.9.30.4-6.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 | { $Id: checklst.pas 27756 2010-10-19 01:02:35Z paul $
/***************************************************************************
checklst.pas
------------
Initial Revision : Thu Jun 19 CST 2003
***************************************************************************/
*****************************************************************************
* *
* This file is part of the Lazarus Component Library (LCL) *
* *
* See the file COPYING.modifiedLGPL.txt, included in this distribution, *
* for details about the copyright. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* *
*****************************************************************************
}
unit CheckLst;
{$mode objfpc} {$H+}
interface
uses
Classes, SysUtils, Math, LCLProc, LCLType, GraphType, Graphics, LMessages,
LResources, Controls, StdCtrls, LCLIntf;
type
TCheckListClicked = procedure(Sender: TObject; Index: integer) of object;
{ TCustomCheckListBox }
TCustomCheckListBox = class(TCustomListBox)
private
FAllowGrayed: Boolean;
FItemDataOffset: Integer;
FOnClickCheck : TNotifyEvent;
FOnItemClick: TCheckListClicked;
function GetChecked(const AIndex: Integer): Boolean;
function GetCount: integer;
function GetItemEnabled(AIndex: Integer): Boolean;
function GetState(AIndex: Integer): TCheckBoxState;
procedure SetChecked(const AIndex: Integer; const AValue: Boolean);
procedure SendItemState(const AIndex: Integer; const AState: TCheckBoxState);
procedure SendItemEnabled(const AIndex: Integer; const AEnabled: Boolean);
procedure DoChange(var Msg: TLMessage); message LM_CHANGED;
procedure SetItemEnabled(AIndex: Integer; const AValue: Boolean);
procedure SetState(AIndex: Integer; const AValue: TCheckBoxState);
protected
class procedure WSRegisterClass; override;
procedure AssignItemDataToCache(const AIndex: Integer; const AData: Pointer); override;
procedure AssignCacheToItemData(const AIndex: Integer; const AData: Pointer); override;
function GetCachedDataSize: Integer; override;
procedure DefineProperties(Filer: TFiler); override;
procedure ReadData(Stream: TStream);
procedure WriteData(Stream: TStream);
procedure ClickCheck; virtual;
procedure ItemClick(const AIndex: Integer); virtual;
procedure KeyDown(var Key: Word; Shift: TShiftState); override;
procedure FontChanged(Sender: TObject); override;
public
constructor Create(AOwner: TComponent); override;
procedure MeasureItem(Index: Integer; var TheHeight: Integer); override;
procedure Toggle(AIndex: Integer);
property AllowGrayed: Boolean read FAllowGrayed write FAllowGrayed default False;
property Checked[AIndex: Integer]: Boolean read GetChecked write SetChecked;
property ItemEnabled[AIndex: Integer]: Boolean read GetItemEnabled write SetItemEnabled;
property State[AIndex: Integer]: TCheckBoxState read GetState write SetState;
property Count: integer read GetCount;
property OnClickCheck: TNotifyEvent read FOnClickCheck write FOnClickCheck;
property OnItemClick: TCheckListClicked read FOnItemClick write FOnItemClick;
end;
{ TCheckListBox }
TCheckListBox = class(TCustomCheckListBox)
published
property Align;
property AllowGrayed;
property Anchors;
property BidiMode;
property BorderSpacing;
property BorderStyle;
property Color;
property Columns;
property Constraints;
property DragCursor;
property DragMode;
property ExtendedSelect;
property Enabled;
property Font;
property IntegralHeight;
property Items;
property ItemHeight;
property MultiSelect;
property OnChangeBounds;
property OnClick;
property OnClickCheck;
property OnContextPopup;
property OnDblClick;
property OnDrawItem;
property OnDragDrop;
property OnDragOver;
property OnEndDrag;
property OnEnter;
property OnExit;
property OnItemClick;
property OnKeyPress;
property OnKeyDown;
property OnKeyUp;
property OnMouseMove;
property OnMouseDown;
property OnMouseUp;
property OnMouseEnter;
property OnMouseLeave;
property OnMouseWheel;
property OnMouseWheelDown;
property OnMouseWheelUp;
property OnResize;
property OnShowHint;
property OnStartDrag;
property OnUTF8KeyPress;
property ParentBidiMode;
property ParentFont;
property ParentShowHint;
property PopupMenu;
property ShowHint;
property Sorted;
property Style;
property TabOrder;
property TabStop;
property TopIndex;
property Visible;
end;
procedure Register;
implementation
uses
WSCheckLst;
procedure Register;
begin
RegisterComponents('Additional',[TCheckListBox]);
end;
type
PCachedItemData = ^TCachedItemData;
TCachedItemData = record
State: TCheckBoxState;
Disabled: Boolean;
end;
{ TCustomCheckListBox }
procedure TCustomCheckListBox.AssignCacheToItemData(const AIndex: Integer;
const AData: Pointer);
begin
inherited AssignCacheToItemData(AIndex, AData);
SendItemState(AIndex, PCachedItemData(AData + FItemDataOffset)^.State);
SendItemEnabled(AIndex, not PCachedItemData(AData + FItemDataOffset)^.Disabled);
end;
procedure TCustomCheckListBox.AssignItemDataToCache(const AIndex: Integer;
const AData: Pointer);
begin
inherited AssignItemDataToCache(AIndex, AData);
PCachedItemData(AData + FItemDataOffset)^.State := State[AIndex];
PCachedItemData(AData + FItemDataOffset)^.Disabled := not ItemEnabled[AIndex];
end;
constructor TCustomCheckListBox.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FCompStyle := csCheckListBox;
FItemDataOffset := inherited GetCachedDataSize;
end;
procedure TCustomCheckListBox.MeasureItem(Index: Integer; var TheHeight: Integer);
begin
if (Style = lbStandard) then
TheHeight := Max(CalculateStandardItemHeight, GetSystemMetrics(SM_CYMENUCHECK) + 2)
else
inherited MeasureItem(Index, TheHeight);
end;
procedure TCustomCheckListBox.Toggle(AIndex: Integer);
const
NextStateMap: array[TCheckBoxState] of array[Boolean] of TCheckBoxState =
(
{cbUnchecked} (cbChecked, cbChecked),
{cbChecked } (cbUnChecked, cbGrayed),
{cbGrayed } (cbUnChecked, cbUnChecked)
);
begin
State[AIndex] := NextStateMap[State[AIndex]][AllowGrayed];
end;
procedure TCustomCheckListBox.DoChange(var Msg: TLMessage);
begin
//DebugLn(['TCustomCheckListBox.DoChange ',DbgSName(Self),' ',Msg.WParam]);
ClickCheck;
ItemClick(Msg.WParam);
end;
function TCustomCheckListBox.GetCachedDataSize: Integer;
begin
FItemDataOffset := inherited GetCachedDataSize;
Result := FItemDataOffset + SizeOf(TCachedItemData);
end;
function TCustomCheckListBox.GetChecked(const AIndex: Integer): Boolean;
begin
Result := State[AIndex] <> cbUnchecked;
end;
function TCustomCheckListBox.GetCount: integer;
begin
Result := Items.Count;
end;
function TCustomCheckListBox.GetItemEnabled(AIndex: Integer): Boolean;
begin
CheckIndex(AIndex);
if HandleAllocated then
Result := TWSCustomCheckListBoxClass(WidgetSetClass).GetItemEnabled(Self, AIndex)
else
Result := not PCachedItemData(GetCachedData(AIndex) + FItemDataOffset)^.Disabled;
end;
function TCustomCheckListBox.GetState(AIndex: Integer): TCheckBoxState;
begin
CheckIndex(AIndex);
if HandleAllocated then
Result := TWSCustomCheckListBoxClass(WidgetSetClass).GetState(Self, AIndex)
else
Result := PCachedItemData(GetCachedData(AIndex) + FItemDataOffset)^.State;
end;
procedure TCustomCheckListBox.KeyDown(var Key: Word; Shift: TShiftState);
var
Index: Integer;
begin
if (Key = VK_SPACE) and (Shift=[]) then
begin
Index := ItemIndex;
Checked[Index] := not Checked[Index];
ItemClick(Index);
Key := VK_UNKNOWN;
end else
inherited KeyDown(Key,Shift);
end;
procedure TCustomCheckListBox.SetItemEnabled(AIndex: Integer;
const AValue: Boolean);
begin
CheckIndex(AIndex);
if HandleAllocated then
SendItemEnabled(AIndex, AValue)
else
PCachedItemData(GetCachedData(AIndex) + FItemDataOffset)^.Disabled := not AValue;
end;
procedure TCustomCheckListBox.SetState(AIndex: Integer;
const AValue: TCheckBoxState);
begin
CheckIndex(AIndex);
if GetState(AIndex) = AValue then
Exit;
if HandleAllocated then
SendItemState(AIndex, AValue)
else
PCachedItemData(GetCachedData(AIndex) + FItemDataOffset)^.State := AValue;
end;
class procedure TCustomCheckListBox.WSRegisterClass;
begin
inherited WSRegisterClass;
RegisterCustomCheckListBox;
end;
procedure TCustomCheckListBox.SendItemState(const AIndex: Integer;
const AState: TCheckBoxState);
begin
if HandleAllocated then
TWSCustomCheckListBoxClass(WidgetSetClass).SetState(Self, AIndex, AState);
end;
procedure TCustomCheckListBox.SendItemEnabled(const AIndex: Integer;
const AEnabled: Boolean);
begin
if HandleAllocated then
TWSCustomCheckListBoxClass(WidgetSetClass).SetItemEnabled(Self, AIndex, AEnabled);
end;
procedure TCustomCheckListBox.SetChecked(const AIndex: Integer;
const AValue: Boolean);
begin
if AValue then
SetState(AIndex, cbChecked)
else
SetState(AIndex, cbUnChecked);
end;
procedure TCustomCheckListBox.ClickCheck;
begin
if Assigned(FOnClickCheck) then FOnClickCheck(Self);
end;
procedure TCustomCheckListBox.ItemClick(const AIndex: Integer);
begin
if Assigned(OnItemClick) then OnItemClick(Self, AIndex);
end;
procedure TCustomCheckListBox.FontChanged(Sender: TObject);
begin
inherited FontChanged(Sender);
if ([csLoading, csDestroying] * ComponentState = []) and (Style = lbStandard) then
ItemHeight := CalculateStandardItemHeight;
end;
procedure TCustomCheckListBox.DefineProperties(Filer: TFiler);
begin
inherited DefineProperties(Filer);
Filer.DefineBinaryProperty('Data', @ReadData, @WriteData, Items.Count > 0);
end;
procedure TCustomCheckListBox.ReadData(Stream: TStream);
var
ChecksCount: integer;
Checks: string;
i: Integer;
begin
ChecksCount := ReadLRSInteger(Stream);
if ChecksCount > 0 then
begin
SetLength(Checks, ChecksCount);
Stream.ReadBuffer(Checks[1], ChecksCount);
for i := 0 to ChecksCount-1 do
State[i] := TCheckBoxState(ord(Checks[i + 1]));
end;
end;
procedure TCustomCheckListBox.WriteData(Stream: TStream);
var
ChecksCount: integer;
Checks: string;
i: Integer;
begin
ChecksCount := Items.Count;
WriteLRSInteger(Stream, ChecksCount);
if ChecksCount > 0 then
begin
SetLength(Checks, ChecksCount);
for i := 0 to ChecksCount - 1 do
Checks[i+1] := chr(Ord(State[i]));
Stream.WriteBuffer(Checks[1], ChecksCount);
end;
end;
end.
|