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 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629
|
unit VirtualTreesReg;
// This unit is an addendum to VirtualTrees.pas and contains code of design time editors as well as
// for theirs and the tree's registration.
interface
{$include Compilers.inc}
{$ifdef COMPILER_7_UP}
// For some things to work we need code, which is classified as being unsafe for .NET.
{$warn UNSAFE_TYPE off}
{$warn UNSAFE_CAST off}
{$warn UNSAFE_CODE off}
{$endif COMPILER_7_UP}
uses
Windows, Classes,
{$ifdef COMPILER_6_UP}
DesignIntf, DesignEditors, VCLEditors, PropertyCategories,
{$else}
DsgnIntf,
{$endif}
ColnEdit,
VirtualTrees, VTHeaderPopup;
type
TVirtualTreeEditor = class (TDefaultEditor)
public
procedure Edit; override;
end;
procedure Register;
//----------------------------------------------------------------------------------------------------------------------
implementation
uses
{$ifdef COMPILER_5_UP}
StrEdit,
{$else}
StrEditD4,
{$endif COMPILER_5_UP}
Dialogs, TypInfo, SysUtils, Graphics, CommCtrl, ImgList, Controls;
type
// The usual trick to make a protected property accessible in the ShowCollectionEditor call below.
TVirtualTreeCast = class(TBaseVirtualTree);
TClipboardElement = class(TNestedProperty {$ifdef COMPILER_6_UP}, ICustomPropertyDrawing {$endif COMPILER_6_UP})
private
FElement: string;
protected
constructor Create(Parent: TPropertyEditor; AElement: string); reintroduce;
public
function AllEqual: Boolean; override;
function GetAttributes: TPropertyAttributes; override;
function GetName: string; override;
function GetValue: string; override;
procedure GetValues(Proc: TGetStrProc); override;
procedure SetValue(const Value: string); override;
{$ifdef COMPILER_5_UP}
{$ifdef COMPILER_6_UP}
procedure PropDrawName(ACanvas: TCanvas; const ARect: TRect; ASelected: Boolean);
{$endif COMPILER_6_UP}
procedure PropDrawValue(ACanvas: TCanvas; const ARect: TRect; ASelected: Boolean);
{$ifndef COMPILER_6_UP} override; {$endif COMPILER_6_UP}
{$endif COMPILER_5_UP}
end;
// This is a special property editor to make the strings in the clipboard format string list
// being shown as subproperties in the object inspector. This way it is shown what formats are actually available
// and the user can pick them with a simple yes/no choice.
{$ifdef COMPILER_6_UP}
TGetPropEditProc = TGetPropProc;
{$endif}
TClipboardFormatsProperty = class(TStringListProperty {$ifdef COMPILER_6_UP}, ICustomPropertyDrawing {$endif COMPILER_6_UP})
public
function GetAttributes: TPropertyAttributes; override;
procedure GetProperties(Proc: TGetPropEditProc); override;
{$ifdef COMPILER_5_UP}
procedure PropDrawName(ACanvas: TCanvas; const ARect: TRect; ASelected: Boolean);
{$ifndef COMPILER_6_UP} override; {$endif}
procedure PropDrawValue(ACanvas: TCanvas; const ARect: TRect; ASelected: Boolean);
{$ifndef COMPILER_6_UP} override; {$endif}
{$endif}
end;
// Property categories. They are defined this way only for Delphi 5 & BCB 5.
{$ifdef COMPILER_5}
TVTHeaderCategory = class(TPropertyCategory)
public
class function Name: string; override;
class function Description: string; override;
end;
TVTPaintingCategory = class(TPropertyCategory)
public
class function Name: string; override;
class function Description: string; override;
end;
TVTIncrementalSearchCategory = class(TPropertyCategory)
public
class function Name: string; override;
class function Description: string; override;
end;
{$endif COMPILER_5}
TCheckImageKindProperty = class(TEnumProperty {$ifdef COMPILER_6_UP}, ICustomPropertyDrawing, ICustomPropertyListDrawing {$endif COMPILER_6_UP})
public
{$ifdef COMPILER_5_UP}
procedure ListMeasureHeight(const Value: string; Canvas: TCanvas; var AHeight: Integer);
{$ifndef COMPILER_6_UP} override; {$endif}
procedure ListMeasureWidth(const Value: string; ACanvas: TCanvas; var AWidth: Integer);
{$ifndef COMPILER_6_UP} override; {$endif}
procedure ListDrawValue(const Value: string; ACanvas: TCanvas; const ARect: TRect; ASelected: Boolean);
{$ifndef COMPILER_6_UP} override; {$endif}
{$ifdef COMPILER_6_UP}
procedure PropDrawName(ACanvas: TCanvas; const ARect: TRect; ASelected: Boolean);
{$endif}
procedure PropDrawValue(ACanvas: TCanvas; const ARect: TRect; ASelected: Boolean);
{$ifndef COMPILER_6_UP} override; {$endif}
{$endif}
end;
{$ifdef COMPILER_6_UP}
resourcestring
sVTHeaderCategoryName = 'Header';
sVTPaintingCategoryName = 'Custom painting';
sVTIncremenalCategoryName = 'Incremental search';
{$endif}
//----------------------------------------------------------------------------------------------------------------------
procedure TVirtualTreeEditor.Edit;
begin
ShowCollectionEditor(Designer, Component, TVirtualTreeCast(Component).Header.Columns, 'Columns');
end;
//----------------------------------------------------------------------------------------------------------------------
constructor TClipboardElement.Create(Parent: TPropertyEditor; AElement: string);
begin
inherited Create(Parent);
FElement := AElement;
end;
//----------------------------------------------------------------------------------------------------------------------
function TClipboardElement.AllEqual: Boolean;
// Determines if this element is included or excluded in all selected components it belongs to.
var
I, Index: Integer;
List: TClipboardFormats;
V: Boolean;
begin
Result := False;
if PropCount > 1 then
begin
List := TClipboardFormats(GetOrdValue);
V := List.Find(FElement, Index);
for I := 1 to PropCount - 1 do
begin
List := TClipboardFormats(GetOrdValue);
if List.Find(FElement, Index) <> V then
Exit;
end;
end;
Result := True;
end;
//----------------------------------------------------------------------------------------------------------------------
function TClipboardElement.GetAttributes: TPropertyAttributes;
begin
Result := [paMultiSelect, paValueList, paSortList];
end;
//----------------------------------------------------------------------------------------------------------------------
function TClipboardElement.GetName: string;
begin
Result := FElement;
end;
//----------------------------------------------------------------------------------------------------------------------
function TClipboardElement.GetValue: string;
var
List: TClipboardFormats;
begin
List := TClipboardFormats(GetOrdValue);
Result := BooleanIdents[List.IndexOf(FElement) > -1];
end;
//----------------------------------------------------------------------------------------------------------------------
procedure TClipboardElement.GetValues(Proc: TGetStrProc);
begin
Proc(BooleanIdents[False]);
Proc(BooleanIdents[True]);
end;
//----------------------------------------------------------------------------------------------------------------------
procedure TClipboardElement.SetValue(const Value: string);
var
List: TClipboardFormats;
I, Index: Integer;
begin
if CompareText(Value, 'True') = 0 then
begin
for I := 0 to PropCount - 1 do
begin
List := TClipboardFormats(GetOrdValueAt(I));
List.Add(FElement);
end;
end
else
begin
for I := 0 to PropCount - 1 do
begin
List := TClipboardFormats(GetOrdValueAt(I));
if List.Find(FElement, Index) then
List.Delete(Index);
end;
end;
Modified;
end;
//----------------------------------------------------------------------------------------------------------------------
{$ifdef COMPILER_5_UP}
procedure DrawBoolean(Checked: Boolean; ACanvas: TCanvas; const ARect: TRect; ASelected: Boolean);
var
BoxSize,
EntryWidth: Integer;
R: TRect;
State: Cardinal;
begin
with ACanvas do
begin
FillRect(ARect);
BoxSize := ARect.Bottom - ARect.Top;
EntryWidth := ARect.Right - ARect.Left;
R := Rect(ARect.Left + (EntryWidth - BoxSize) div 2, ARect.Top, ARect.Left + (EntryWidth + BoxSize) div 2,
ARect.Bottom);
InflateRect(R, -1, -1);
State := DFCS_BUTTONCHECK;
if Checked then
State := State or DFCS_CHECKED;
DrawFrameControl(Handle, R, DFC_BUTTON, State);
end;
end;
//----------------------------------------------------------------------------------------------------------------------
{$ifdef COMPILER_6_UP}
procedure TClipboardElement.PropDrawName(ACanvas: TCanvas; const ARect: TRect; ASelected: Boolean);
begin
DefaultPropertyDrawName(Self, ACanvas, ARect);
end;
{$endif COMPILER_6_UP}
//----------------------------------------------------------------------------------------------------------------------
procedure TClipboardElement.PropDrawValue(ACanvas: TCanvas; const ARect: TRect; ASelected: Boolean);
begin
DrawBoolean(CompareText(GetVisualValue, 'True') = 0, ACanvas, ARect, ASelected);
end;
{$endif COMPILER_5_UP}
//----------------- TClipboardFormatsProperty --------------------------------------------------------------------------
function TClipboardFormatsProperty.GetAttributes: TPropertyAttributes;
begin
Result := inherited GetAttributes + [paSubProperties {$ifdef COMPILER_5_UP}, paFullWidthName {$endif COMPILER_5_UP}];
end;
//----------------------------------------------------------------------------------------------------------------------
procedure TClipboardFormatsProperty.GetProperties(Proc: TGetPropEditProc);
var
List: TStringList;
I: Integer;
Tree: TBaseVirtualTree;
begin
List := TStringList.Create;
Tree := TClipboardFormats(GetOrdValue).Owner;
EnumerateVTClipboardFormats(TVirtualTreeClass(Tree.ClassType), List);
for I := 0 to List.Count - 1 do
Proc(TClipboardElement.Create(Self, List[I]));
end;
//----------------------------------------------------------------------------------------------------------------------
{$ifdef COMPILER_5_UP}
procedure TClipboardFormatsProperty.PropDrawName(ACanvas: TCanvas; const ARect: TRect; ASelected: Boolean);
var
S: string;
Width: Integer;
R: TRect;
begin
with ACanvas do
begin
Font.Name := 'Arial';
R := ARect;
Font.Color := clBlack;
S := GetName;
Width := TextWidth(S);
TextRect(R, R.Left + 1, R.Top + 1, S);
Inc(R.Left, Width + 8);
Font.Height := 14;
Font.Color := clBtnHighlight;
S := '(OLE drag and clipboard)';
SetBkMode(Handle, TRANSPARENT);
ExtTextOut(Handle, R.Left + 1, R.Top + 1, ETO_CLIPPED, @R, PChar(S), Length(S), nil);
Font.Color := clBtnShadow;
ExtTextOut(Handle, R.Left, R.Top, ETO_CLIPPED, @R, PChar(S), Length(S), nil);
end;
end;
//----------------------------------------------------------------------------------------------------------------------
procedure TClipboardFormatsProperty.PropDrawValue(ACanvas: TCanvas; const ARect: TRect; ASelected: Boolean);
begin
// Nothing to do here.
end;
{$endif COMPILER_5_UP}
{$ifdef COMPILER_5}
//----------------- TVTPaintingCategory --------------------------------------------------------------------------------
class function TVTPaintingCategory.Name: string;
begin
Result := 'Custom Painting';
end;
//----------------------------------------------------------------------------------------------------------------------
class function TVTPaintingCategory.Description: string;
begin
Result := 'Custom Painting';
end;
//----------------- TVTHeaderCategory ----------------------------------------------------------------------------------
class function TVTHeaderCategory.Name: string;
begin
Result := 'Header';
end;
//----------------------------------------------------------------------------------------------------------------------
class function TVTHeaderCategory.Description: string;
begin
Result := 'Header';
end;
//----------------- TVTIncrementalSearchCategory -----------------------------------------------------------------------
class function TVTIncrementalSearchCategory.Name: string;
begin
Result := 'Incremental Search';
end;
//----------------------------------------------------------------------------------------------------------------------
class function TVTIncrementalSearchCategory.Description: string;
begin
Result := 'Incremental Search';
end;
//----------------------------------------------------------------------------------------------------------------------
{$endif COMPILER_5}
//----------------- TCheckImageKindProperty ----------------------------------------------------------------------------
{$ifdef COMPILER_5_UP}
const
cCheckImageKindComboItemBorder = 0;
cCheckImageKindComboItemSpacing = 2;
cCheckImageKindComboBitmapHeight = 16;
cCheckImageKindComboBitmapWidth = 16;
//----------------------------------------------------------------------------------------------------------------------
{$ifdef COMPILER_6_UP}
procedure TCheckImageKindProperty.PropDrawName(ACanvas: TCanvas; const ARect: TRect; ASelected: Boolean);
begin
DefaultPropertyDrawName(Self, ACanvas, ARect);
end;
{$endif}
//----------------------------------------------------------------------------------------------------------------------
procedure TCheckImageKindProperty.PropDrawValue(ACanvas: TCanvas; const ARect: TRect; ASelected: Boolean);
begin
if GetVisualValue <> '' then
ListDrawValue(GetVisualValue, ACanvas, ARect, ASelected)
else
{$ifdef COMPILER_6_UP}
DefaultPropertyDrawValue(Self, ACanvas, ARect);
{$else}
inherited PropDrawValue(ACanvas, ARect, ASelected);
{$endif}
end;
//----------------------------------------------------------------------------------------------------------------------
procedure TCheckImageKindProperty.ListDrawValue(const Value: string; ACanvas: TCanvas; const ARect: TRect; ASelected: Boolean);
var
RighPosition: Integer;
OldPenColor: TColor;
CheckKind: TCheckImageKind;
ImageList: TCustomImageList;
RemainingRect: TRect;
begin
RighPosition := ARect.Left + cCheckImageKindComboBitmapWidth;
with ACanvas do
try
OldPenColor := Pen.Color;
Pen.Color := Brush.Color;
Rectangle(ARect.Left, ARect.Top, RighPosition, ARect.Bottom);
CheckKind := TCheckImageKind(GetEnumValue(GetPropInfo^.PropType^, Value));
ImageList := TVirtualTreeCast.GetCheckImageListFor(CheckKind);
if ImageList <> nil then
begin
ImageList_DrawEx(ImageList.Handle, ckCheckCheckedNormal, ACanvas.Handle, ARect.Left + cCheckImageKindComboItemBorder,
ARect.Top + cCheckImageKindComboItemBorder, 0, 0, CLR_NONE, CLR_NONE, ILD_TRANSPARENT);
end;
Pen.Color := OldPenColor;
finally
RemainingRect := Rect(RighPosition, ARect.Top, ARect.Right, ARect.Bottom);
{$ifdef COMPILER_6_UP}
DefaultPropertyListDrawValue(Value, ACanvas, RemainingRect, ASelected);
{$else}
inherited ListDrawValue(Value, ACanvas, RemainingRect, ASelected);
{$endif}
end;
end;
//----------------------------------------------------------------------------------------------------------------------
procedure TCheckImageKindProperty.ListMeasureHeight(const Value: string; Canvas: TCanvas; var AHeight: Integer);
begin
AHeight := cCheckImageKindComboBitmapHeight;
end;
//----------------------------------------------------------------------------------------------------------------------
procedure TCheckImageKindProperty.ListMeasureWidth(const Value: string; ACanvas: TCanvas; var AWidth: Integer);
begin
AWidth := AWidth + cCheckImageKindComboBitmapWidth;
end;
{$endif COMPILER_5_UP}
//----------------------------------------------------------------------------------------------------------------------
procedure Register;
begin
RegisterComponents('Virtual Controls', [TVirtualStringTree, TVirtualDrawTree, TVTHeaderPopupMenu]);
RegisterComponentEditor(TVirtualStringTree, TVirtualTreeEditor);
RegisterComponentEditor(TVirtualDrawTree, TVirtualTreeEditor);
RegisterPropertyEditor(TypeInfo(TClipboardFormats), nil, '', TClipboardFormatsProperty);
RegisterPropertyEditor(TypeInfo(TCheckImageKind), nil, '', TCheckImageKindProperty);
// Categories:
{$ifdef COMPILER_5_UP}
RegisterPropertiesInCategory({$ifdef COMPILER_5} TActionCategory, {$endif} {$ifdef COMPILER_6_UP} sActionCategoryName, {$endif COMPILER_6_UP}
TBaseVirtualTree,
['ChangeDelay',
'EditDelay']);
RegisterPropertiesInCategory({$ifdef COMPILER_5} TDataCategory, {$endif} {$ifdef COMPILER_6_UP} sDataCategoryName, {$endif COMPILER_6_UP}
TBaseVirtualTree,
['NodeDataSize',
'RootNodeCount',
'OnCompareNodes',
'OnGetNodeDataSize',
'OnInitNode',
'OnInitChildren',
'OnFreeNode',
'OnGetNodeWidth',
'OnGetPopupMenu',
'OnLoadNode',
'OnSaveNode',
'OnResetNode',
'OnNodeMov*',
'OnStructureChange',
'OnUpdating',
'OnGetText',
'OnNewText',
'OnShortenString']);
RegisterPropertiesInCategory({$ifdef COMPILER_5} TLayoutCategory, {$endif} {$ifdef COMPILER_6_UP} slayoutCategoryName, {$endif COMPILER_6_UP}
TBaseVirtualTree,
['AnimationDuration',
'AutoExpandDelay',
'AutoScroll*',
'ButtonStyle',
'DefaultNodeHeight',
'*Images*', 'OnGetImageIndex',
'Header',
'Indent',
'LineStyle', 'OnGetLineStyle',
'CheckImageKind',
'Options',
'Margin',
'NodeAlignment',
'ScrollBarOptions',
'SelectionCurveRadius',
'TextMargin']);
RegisterPropertiesInCategory({$ifdef COMPILER_5} TVisualCategory, {$endif} {$ifdef COMPILER_6_UP} sVisualCategoryName, {$endif COMPILER_6_UP}
TBaseVirtualTree,
['Background*',
'ButtonFillMode',
'CustomCheckimages',
'Colors',
'LineMode']);
RegisterPropertiesInCategory({$ifdef COMPILER_5} THelpCategory, {$endif} {$ifdef COMPILER_6_UP} sHelpCategoryName, {$endif COMPILER_6_UP}
TBaseVirtualTree,
['Hint*', 'On*Hint*', 'On*Help*']);
RegisterPropertiesInCategory({$ifdef COMPILER_5} TDragNDropCategory, {$endif} {$ifdef COMPILER_6_UP} sDragNDropCategoryName, {$endif COMPILER_6_UP}
TBaseVirtualTree,
['ClipboardFormats',
'DefaultPasteMode',
'OnCreateDataObject',
'OnCreateDragManager',
'OnGetUserClipboardFormats',
'OnNodeCop*',
'OnDragAllowed',
'OnRenderOLEData']);
RegisterPropertiesInCategory({$ifdef COMPILER_5} TInputCategory, {$endif} {$ifdef COMPILER_6_UP} sInputCategoryName, {$endif COMPILER_6_UP}
TBaseVirtualTree,
['DefaultText',
'DrawSelectionMode',
'WantTabs',
'OnChang*',
'OnCollaps*',
'OnExpand*',
'OnCheck*',
'OnEdit*',
'On*Click',
'OnFocus*',
'OnCreateEditor',
'OnScroll',
'OnHotChange']);
RegisterPropertiesInCategory({$ifdef COMPILER_5} TVTHeaderCategory, {$endif} {$ifdef COMPILER_6_UP} sVTHeaderCategoryName, {$endif COMPILER_6_UP}
TBaseVirtualTree,
['OnHeader*', 'OnGetHeader*']);
RegisterPropertiesInCategory({$ifdef COMPILER_5} TVTPaintingCategory, {$endif} {$ifdef COMPILER_6_UP} sVTPaintingCategoryName, {$endif COMPILER_6_UP}
TBaseVirtualTree,
['On*Paint*',
'OnDraw*',
'On*Erase*']);
RegisterPropertiesInCategory({$ifdef COMPILER_5} TVTIncrementalSearchCategory, {$endif} {$ifdef COMPILER_6_UP} sVTIncremenalCategoryName, {$endif COMPILER_6_UP}
TBaseVirtualTree,
['*Incremental*']);
{$endif COMPILER_5_UP}
end;
//----------------------------------------------------------------------------------------------------------------------
end.
|