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 377 378 379 380 381 382 383 384 385 386 387 388
|
{
***************************************************************************
* *
* This source is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This code 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. See the GNU *
* General Public License for more details. *
* *
* A copy of the GNU General Public License is available on the World *
* Wide Web at <http://www.gnu.org/copyleft/gpl.html>. You can also *
* obtain it by writing to the Free Software Foundation, *
* Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1335, USA. *
* *
***************************************************************************
Author: Balázs Székely
}
unit opkman_categoriesfrm;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils,
// LCL
Forms, Controls, Graphics, ExtCtrls, StdCtrls, ButtonPanel, laz.VirtualTrees,
LCLPlatformDef,
// OpkMan
opkman_const, opkman_common, opkman_options, opkman_maindm;
type
{ TCategoriesFrm }
TCategoriesFrm = class(TForm)
BP: TButtonPanel;
lbMessage: TLabel;
pnMessage: TPanel;
procedure bOkClick(Sender: TObject);
procedure FormClose(Sender: TObject; var {%H-}CloseAction: TCloseAction);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure FormKeyPress(Sender: TObject; var Key: char);
procedure lbMessageResize(Sender: TObject);
private
FVST: TLazVirtualStringTree;
FModRes: TModalResult;
FCategoriesCSV: String;
FLazCompatibility: String;
FFPCCompatibility: String;
FSupportedWidgetSets: String;
FLineAdded: Boolean;
procedure VSTGetText(Sender: TBaseVirtualTree; Node: PVirtualNode;
Column: TColumnIndex; {%H-}TextType: TVSTTextType; var CellText: String);
procedure VSTGetImageIndex(Sender: TBaseVirtualTree; Node: PVirtualNode;
{%H-}Kind: TVTImageKind; Column: TColumnIndex; var {%H-}Ghosted: Boolean;
var ImageIndex: Integer);
procedure VSTCompareNodes(Sender: TBaseVirtualTree; Node1,
Node2: PVirtualNode; Column: TColumnIndex; var Result: Integer);
procedure VSTFreeNode(Sender: TBaseVirtualTree; Node: PVirtualNode);
function CheckNode(const AName: String): Boolean;
public
procedure SetupControls(const AType: Integer);
procedure PopulateTree(const AType: Integer);
property CategoriesCSV: String read FCategoriesCSV write FCategoriesCSV;
property LazCompatibility: String read FLazCompatibility write FLazCompatibility;
property FPCCompatibility: String read FFPCCompatibility write FFPCCompatibility;
property SupportedWidgetSets: String read FSupportedWidgetSets write FSupportedWidgetSets;
end;
var
CategoriesFrm: TCategoriesFrm;
implementation
{$R *.lfm}
type
PData = ^TData;
TData = record
FName: string[100];
FImageIndex: Integer;
FType: Integer;
end;
{ TCategoriesFrm }
procedure TCategoriesFrm.FormClose(Sender: TObject;
var CloseAction: TCloseAction);
begin
if FModRes <> mrNone then
ModalResult := FModRes;
end;
procedure TCategoriesFrm.bOkClick(Sender: TObject);
var
Node: PVirtualNode;
Data: PData;
begin
FCategoriesCSV := '';
FLazCompatibility := '';
FFPCCompatibility := '';
FSupportedWidgetSets := '';
Node := FVST.GetFirst;
while Assigned(Node) do
begin
Data := FVST.GetNodeData(Node);
if FVST.CheckState[Node] = csCheckedNormal then
begin
case Data^.FType of
0,1: begin
if FCategoriesCSV = '' then
FCategoriesCSV := Data^.FName
else
FCategoriesCSV := FCategoriesCSV + ', ' + Data^.FName;
end;
2: begin
if FLazCompatibility = '' then
FLazCompatibility := Data^.FName
else
FLazCompatibility := FLazCompatibility + ', ' + Data^.FName;
end;
3: begin
if FFPCCompatibility = '' then
FFPCCompatibility := Data^.FName
else
FFPCCompatibility := FFPCCompatibility + ', ' + Data^.FName;
end;
4: begin
if FSupportedWidgetSets = '' then
FSupportedWidgetSets := Data^.FName
else
FSupportedWidgetSets := FSupportedWidgetSets + ', ' + Data^.FName;
end;
end;
end;
Node := FVST.GetNext(Node);
end;
end;
procedure TCategoriesFrm.FormCreate(Sender: TObject);
begin
if not Options.UseDefaultTheme then
Self.Color := clBtnFace;
FVST := TLazVirtualStringTree.Create(nil);
with FVST do
begin
Parent := Self;
Align := alClient;
Anchors := [akLeft, akTop, akRight];
Images := MainDM.Images;
if not Options.UseDefaultTheme then
Color := clBtnFace;
DefaultNodeHeight := Scale96ToForm(25);
Indent := 0;
TabOrder := 1;
DefaultText := '';
Header.AutoSizeIndex := 0;
Header.Height := Scale96ToForm(25);
Colors.BorderColor := clBlack;
BorderSpacing.Top := Scale96ToForm(5);
BorderSpacing.Left := Scale96ToForm(10);
BorderSpacing.Right := Scale96ToForm(10);
with Header.Columns.Add do begin
Position := 0;
Width := 250;
Text := 'CategorieName';
end;
Header.Options := [hoAutoResize, hoColumnResize, hoRestrictDrag, hoShowSortGlyphs, hoAutoSpring];
Header.SortColumn := 0;
TabOrder := 1;
TreeOptions.MiscOptions := [toFullRepaintOnResize, toInitOnSave, toToggleOnDblClick, toWheelPanning, toCheckSupport];
TreeOptions.PaintOptions := [toHideFocusRect, toPopupMode, toShowButtons, toShowDropmark, toThemeAware, toUseBlendedImages];
TreeOptions.SelectionOptions := [toFullRowSelect, toRightClickSelect];
TreeOptions.AutoOptions := [toAutoTristateTracking];
OnGetText := @VSTGetText;
OnGetImageIndex := @VSTGetImageIndex;
OnCompareNodes := @VSTCompareNodes;
OnFreeNode := @VSTFreeNode;
end;
FVST.NodeDataSize := SizeOf(TData);
end;
procedure TCategoriesFrm.FormDestroy(Sender: TObject);
begin
FVST.Clear;
FVST.Free;
end;
procedure TCategoriesFrm.FormKeyPress(Sender: TObject; var Key: char);
begin
if Key = #13 then
begin
FModRes := mrYes;
Close;
end
else if Key = #27 then
begin
FModRes := mrNo;
Close;
end;
end;
procedure TCategoriesFrm.lbMessageResize(Sender: TObject);
begin
pnMessage.Height := lbMessage.Top + lbMessage.Height + 5;
end;
procedure TCategoriesFrm.VSTGetText(Sender: TBaseVirtualTree;
Node: PVirtualNode; Column: TColumnIndex; TextType: TVSTTextType;
var CellText: String);
var
Data: PData;
begin
Data := FVST.GetNodeData(Node);
if Column = 0 then
CellText := Data^.FName;
end;
procedure TCategoriesFrm.VSTGetImageIndex(Sender: TBaseVirtualTree;
Node: PVirtualNode; Kind: TVTImageKind; Column: TColumnIndex;
var Ghosted: Boolean; var ImageIndex: Integer);
var
Data: PData;
begin
Data := FVST.GetNodeData(Node);
if Column = 0 then
ImageIndex := Data^.FImageIndex;
end;
procedure TCategoriesFrm.VSTCompareNodes(Sender: TBaseVirtualTree; Node1,
Node2: PVirtualNode; Column: TColumnIndex; var Result: Integer);
var
Data1: PData;
Data2: PData;
Str1, Str2: String;
Int1, Int2: Integer;
begin
Data1 := Sender.GetNodeData(Node1);
Data2 := Sender.GetNodeData(Node2);
if Column = 0 then
begin
if Data1^.FType = Data2^.FType then
begin
Str1 := Data1^.FName;
Str1 := StringReplace(Str1, '.', '', [rfReplaceAll]);
Int1 := StrToIntDef(Str1, -1);
Str2 := Data2^.FName;
Str2 := StringReplace(Str1, '.', '', [rfReplaceAll]);
Int2 := StrToIntDef(Str2, -1);
if (Int1 <> -1) and (Int2 <> -1) then
Result := Int2 - Int1
else
Result := CompareText(Data1^.FName, Data2^.FName)
end
else if Data1^.FType > Data2^.FType then
Result := 1
else if Data1^.FType < Data2^.FType then
Result := -1
end;
end;
procedure TCategoriesFrm.VSTFreeNode(Sender: TBaseVirtualTree;
Node: PVirtualNode);
var
Data: PData;
begin
Data := FVST.GetNodeData(Node);
Finalize(Data^);
end;
procedure TCategoriesFrm.SetupControls(const AType: Integer);
begin
FModRes := mrNone;
BP.OKButton.Caption := rsCategoriesFrm_bYes_Caption;
BP.CancelButton.Caption := rsCategoriesFrm_bCancel_Caption;
case AType of
1: Caption := rsCategoriesFrm_Caption1;
2: Caption := rsCategoriesFrm_Caption2;
3: Caption := rsCategoriesFrm_Caption3;
4: Caption := rsCategoriesFrm_Caption4;
end;
lbMessage.Caption := rsCategoriesFrm_lbMessage_Caption;
end;
function TCategoriesFrm.CheckNode(const AName: String): Boolean;
var
Node: PVirtualNode;
Data: PData;
begin
Result := False;
Node := FVST.GetFirst;
while Assigned(Node) do
begin
Data := FVST.GetNodeData(Node);
if CompareText(Data^.FName, AName) = 0 then
begin
FVST.CheckState[Node] := csCheckedNormal;
Result := True;
Break;
end;
Node := FVST.GetNext(Node);
end;
end;
procedure TCategoriesFrm.PopulateTree(const AType: Integer);
var
I: Integer;
Node: PVirtualNode;
Data: PData;
SL: TStringList;
LCLPlatform: TLCLPlatform;
begin
FLineAdded := True;
SL := TStringList.Create;
try
SL.Delimiter := ',';
SL.StrictDelimiter := True;
case AType of
1: begin
for I := 0 to MaxCategories - 1 do
begin
Node := FVST.AddChild(nil);
Node^.CheckType := ctTriStateCheckBox;
Data := FVST.GetNodeData(Node);
Data^.FName := Categories[I];
Data^.FImageIndex := -1;
if CompareText(CategoriesEng[I], 'OTHER') = 0 then
Data^.FType := 1
else
Data^.FType := 0;
end;
SL.DelimitedText := FCategoriesCSV;
end;
2: begin
for I := 0 to MaxLazVersions - 1 do
begin
Node := FVST.AddChild(nil);
Node^.CheckType := ctTriStateCheckBox;
Data := FVST.GetNodeData(Node);
Data^.FName := LazVersions[I];
Data^.FImageIndex := -1;
Data^.FType := 2;
end;
SL.DelimitedText := FLazCompatibility;
end;
3: begin
for I := 0 to MaxFPCVersions - 1 do
begin
Node := FVST.AddChild(nil);
Node^.CheckType := ctTriStateCheckBox;
Data := FVST.GetNodeData(Node);
Data^.FName := FPCVersions[I];
Data^.FImageIndex := -1;
Data^.FType := 3;
end;
SL.DelimitedText := FFPCCompatibility;
end;
4: begin
for LCLPlatform := Low(TLCLPlatform) to High(TLCLPlatform) do
begin
Node := FVST.AddChild(nil);
Node^.CheckType := ctTriStateCheckBox;
Data := FVST.GetNodeData(Node);
Data^.FName := LCLPlatformDisplayNames[LCLPlatform];
Data^.FImageIndex := -1;
Data^.FType := 4;
end;
SL.DelimitedText := FSupportedWidgetSets;
end;
end;
FVST.SortTree(0, laz.VirtualTrees.sdAscending);
for I := 0 to SL.Count - 1 do
CheckNode(Trim(SL.Strings[I]));
finally
SL.Free;
end;
end;
end.
|