📄 virtualtrees.pas
字号:
unit VirtualTrees;
// Version 4.4.3
//
// The contents of this file are subject to the Mozilla Public License
// Version 1.1 (the "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
//
// Alternatively, you may redistribute this library, use and/or modify it under the terms of the
// GNU Lesser General Public License as published by the Free Software Foundation;
// either version 2.1 of the License, or (at your option) any later version.
// You may obtain a copy of the LGPL at http://www.gnu.org/copyleft/.
//
// Software distributed under the License is distributed on an "AS IS" basis,
// WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the
// specific language governing rights and limitations under the License.
//
// The original code is VirtualTrees.pas, released September 30, 2000.
//
// The initial developer of the original code is digital publishing AG (Munich, Germany, www.digitalpublishing.de),
// written by Mike Lischke (public@soft-gems.net, www.soft-gems.net).
//
// Portions created by digital publishing AG are Copyright
// (C) 1999-2001 digital publishing AG. All Rights Reserved.
//----------------------------------------------------------------------------------------------------------------------
//
// December 2005
// - Bug fix: check for column index for auto setting main column if the current one is deleted.
//
// For full document history see help file.
//
// Credits for their valuable assistance and code donations go to:
// Freddy Ertl, Marian Aldenh鰒el, Thomas Bogenrieder, Jim Kuenemann, Werner Lehmann, Jens Treichler,
// Paul Gallagher (IBO tree), Ondrej Kelle, Ronaldo Melo Ferraz, Heri Bender, Roland Bed黵ftig (BCB)
// Anthony Mills, Alexander Egorushkin (BCB), Mathias Torell (BCB), Frank van den Bergh, Vadim Sedulin, Peter Evans,
// Milan Vandrovec (BCB), Steve Moss, Joe White, David Clark, Anders Thomsen, Igor Afanasyev, Eugene Programmer,
// Corbin Dunn, Richard Pringle, Uli Gerhardt, Azza, Igor Savkic
// Beta testers:
// Freddy Ertl, Hans-J黵gen Schnorrenberg, Werner Lehmann, Jim Kueneman, Vadim Sedulin, Moritz Franckenstein,
// Wim van der Vegt, Franc v/d Westelaken
// Indirect contribution (via publicly accessible work of those persons):
// Alex Denissov, Hiroyuki Hori (MMXAsm expert)
// Documentation:
// Markus Spoettl and toolsfactory GbR (http://www.doc-o-matic.com/, sponsoring Soft Gems development
// with a free copy of the Doc-O-Matic help authoring system), Sven H. (Step by step tutorial)
// CLX:
// Dmitri Dmitrienko (initial developer)
//----------------------------------------------------------------------------------------------------------------------
interface
{$booleval off} // Use fastest possible boolean evaluation.
{$I Compilers.inc}
{$I VTConfig.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}
{$HPPEMIT '#include <objidl.h>'}
{$HPPEMIT '#include <oleidl.h>'} // Necessary for BCB 6 SP 2.
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, ImgList, ActiveX, StdCtrls, Menus, Printers,
CommCtrl // image lists, common controls tree structures
{$ifdef ThemeSupport}
{$ifndef COMPILER_7_UP}
, ThemeSrv, TMSchema, UxTheme // Windows XP themes support. Get these units from www.soft-gems.net
{$else}
, Themes, UxTheme
{$endif COMPILE_7_UP}
{$endif ThemeSupport}
{$ifdef TntSupport}
, TntStdCtrls // Unicode aware inplace editor.
{$endif TntSupport}
;
const
VTVersion = '4.4.3';
VTTreeStreamVersion = 2;
VTHeaderStreamVersion = 3; // The header needs an own stream version to indicate changes only relevant to the header.
CacheThreshold = 2000; // Number of nodes a tree must at least have to start caching and at the same
// time the maximum number of nodes between two cache entries.
FadeAnimationStepCount = 255; // Number of animation steps for hint fading (0..255).
ShadowSize = 5; // Size in pixels of the hint shadow. This value has no influence on Win2K and XP systems
// as those OSes have native shadow support.
// Special identifiers for columns.
NoColumn = -1;
InvalidColumn = -2;
// Indices for check state images used for checking.
ckEmpty = 0; // an empty image used as place holder
// radio buttons
ckRadioUncheckedNormal = 1;
ckRadioUncheckedHot = 2;
ckRadioUncheckedPressed = 3;
ckRadioUncheckedDisabled = 4;
ckRadioCheckedNormal = 5;
ckRadioCheckedHot = 6;
ckRadioCheckedPressed = 7;
ckRadioCheckedDisabled = 8;
// check boxes
ckCheckUncheckedNormal = 9;
ckCheckUncheckedHot = 10;
ckCheckUncheckedPressed = 11;
ckCheckUncheckedDisabled = 12;
ckCheckCheckedNormal = 13;
ckCheckCheckedHot = 14;
ckCheckCheckedPressed = 15;
ckCheckCheckedDisabled = 16;
ckCheckMixedNormal = 17;
ckCheckMixedHot = 18;
ckCheckMixedPressed = 19;
ckCheckMixedDisabled = 20;
// simple button
ckButtonNormal = 21;
ckButtonHot = 22;
ckButtonPressed = 23;
ckButtonDisabled = 24;
// Instead using a TTimer class for each of the various events I use Windows timers with messages
// as this is more economical.
ExpandTimer = 1;
EditTimer = 2;
HeaderTimer = 3;
ScrollTimer = 4;
ChangeTimer = 5;
StructureChangeTimer = 6;
SearchTimer = 7;
// Need to use this message to release the edit link interface asynchronously.
WM_CHANGESTATE = WM_APP + 32;
// Virtual Treeview does not need to be subclassed by an eventual Theme Manager instance as it handles
// Windows XP theme painting itself. Hence the special message is used to prevent subclassing.
CM_DENYSUBCLASSING = CM_BASE + 2000;
// Decoupling message for auto-adjusting the internal edit window.
CM_AUTOADJUST = CM_BASE + 2005;
// VT's own clipboard formats,
// Note: The reference format is used internally to allow to link to a tree reference
// to implement optimized moves and other back references.
CFSTR_VIRTUALTREE = 'Virtual Tree Data';
CFSTR_VTREFERENCE = 'Virtual Tree Reference';
CFSTR_HTML = 'HTML Format';
CFSTR_RTF = 'Rich Text Format';
CFSTR_RTFNOOBJS = 'Rich Text Format Without Objects';
CFSTR_CSV = 'CSV';
// Drag image helpers for Windows 2000 and up.
IID_IDropTargetHelper: TGUID = (D1: $4657278B; D2: $411B; D3: $11D2; D4: ($83, $9A, $00, $C0, $4F, $D9, $18, $D0));
IID_IDragSourceHelper: TGUID = (D1: $DE5BF786; D2: $477A; D3: $11D2; D4: ($83, $9D, $00, $C0, $4F, $D9, $18, $D0));
IID_IDropTarget: TGUID = (D1: $00000122; D2: $0000; D3: $0000; D4: ($C0, $00, $00, $00, $00, $00, $00, $46));
CLSID_DragDropHelper: TGUID = (D1: $4657278A; D2: $411B; D3: $11D2; D4: ($83, $9A, $00, $C0, $4F, $D9, $18, $D0));
SID_IDropTargetHelper = '{4657278B-411B-11D2-839A-00C04FD918D0}';
SID_IDragSourceHelper = '{DE5BF786-477A-11D2-839D-00C04FD918D0}';
SID_IDropTarget = '{00000122-0000-0000-C000-000000000046}';
// Help identifiers for exceptions. Application developers are responsible to link them with actual help topics.
hcTFEditLinkIsNil = 2000;
hcTFWrongMoveError = 2001;
hcTFWrongStreamFormat = 2002;
hcTFWrongStreamVersion = 2003;
hcTFStreamTooSmall = 2004;
hcTFCorruptStream1 = 2005;
hcTFCorruptStream2 = 2006;
hcTFClipboardFailed = 2007;
hcTFCannotSetUserData = 2008;
// Header standard split cursor.
crHeaderSplit = TCursor(100);
UtilityImageSize = 16; // Needed by descendants for hittests.
var // Clipboard format IDs used in OLE drag'n drop and clipboard transfers.
CF_VIRTUALTREE,
CF_VTREFERENCE,
CF_VRTF,
CF_VRTFNOOBJS, // Unfortunately CF_RTF* is already defined as being
// registration strings so I have to use different identifiers.
CF_HTML,
CF_CSV: Word;
MMXAvailable: Boolean; // necessary to know because the blend code uses MMX instructions
IsWinNT: Boolean; // Necessary to fix bugs in Win95/WinME (non-client area region intersection, edit resize)
// and to allow for check of system dependent hint animation.
IsWin2K: Boolean; // Nessary to provide correct string shortage
IsWinXP: Boolean;
{$MinEnumSize 1, make enumerations as small as possible}
type
// The exception used by the trees.
EVirtualTreeError = class(Exception);
PCardinal = ^Cardinal;
// Limits the speed interval which can be used for auto scrolling (milliseconds).
TAutoScrollInterval = 1..1000;
// Need to declare the correct WMNCPaint record as the VCL (D5-) doesn't.
TRealWMNCPaint = packed record
Msg: Cardinal;
Rgn: HRGN;
lParam: Integer;
Result: Integer;
end;
// The next two message records are not declared in Delphi 6 and lower.
TWMPrint = packed record
Msg: Cardinal;
DC: HDC;
Flags: Cardinal;
Result: Integer;
end;
TWMPrintClient = TWMPrint;
{$ifndef COMPILER_5_UP}
TWMContextMenu = TWMMouse;
{$endif COMPILER_5_UP}
// Be careful when adding new states as this might change the size of the type which in turn
// changes the alignment in the node record as well as the stream chunks.
// Do not reorder the states and always add new states at the end of this enumeration in order to avoid
// breaking existing code.
TVirtualNodeState = (
vsInitialized, // Set after the node has been initialized.
vsChecking, // Node's check state is changing, avoid propagation.
vsCutOrCopy, // Node is selected as cut or copy and paste source.
vsDisabled, // Set if node is disabled.
vsDeleting, // Set when the node is about to be freed.
vsExpanded, // Set if the node is expanded.
vsHasChildren, // Indicates the presence of child nodes without actually setting them.
vsVisible, // Indicate whether the node is visible or not (independant of the expand states of its parents).
vsSelected, // Set if the node is in the current selection.
vsInitialUserData, // Set if (via AddChild or InsertNode) initial user data has been set which requires OnFreeNode.
vsAllChildrenHidden, // Set if vsHasChildren is set and no child node has the vsVisible flag set.
vsClearing, // A node's children are being deleted. Don't register structure change event.
vsMultiline, // Node text is wrapped at the cell boundaries instead of being shorted.
vsHeightMeasured, // Node height has been determined and does not need a recalculation.
vsToggling // Set when a node is expanded/collapsed to prevent recursive calls.
);
TVirtualNodeStates = set of TVirtualNodeState;
// States used in InitNode to indicate states a node shall initially have.
TVirtualNodeInitState = (
ivsDisabled,
ivsExpanded,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -