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
| unit MyTreeView;
interface
uses
Windows, Messages, SysUtils, Classes, Controls, ComCtrls, CommCtrl;
type
TMyTreeView = class(TcustomtreeView)
private
fCanExpand : Boolean;
fDblClicEnabled: Boolean;
Procedure SetDblClicEnabled(Value : Boolean);
procedure CNNotify(var Message: TWMNotify); message CN_NOTIFY;
procedure WMLButtonDblClk(var Message: TWMLButtonDblClk); message WM_LBUTTONDBLCLK;
Protected
Procedure Click;Override;// On surcharge click pour expand et collapse la branche sélectionnée
public
constructor Create(AOwner: TComponent); override;
published
property Align;
property Anchors;
property AutoExpand;
property BevelEdges;
property BevelInner;
property BevelOuter;
property BevelKind default bkNone;
property BevelWidth;
property BiDiMode;
property BorderStyle;
property BorderWidth;
property ChangeDelay;
property Color;
property Ctl3D;
property Constraints;
// Permet de bloquer le double clic
property DblClicEnabled : Boolean read fDblClicEnabled write SetDblClicEnabled;
fDblClicEnabled;
property DragKind;
property DragCursor;
property DragMode;
property Enabled;
property Font;
property HideSelection;
property HotTrack;
property Images;
property Indent;
property MultiSelect;
property MultiSelectStyle;
property ParentBiDiMode;
property ParentColor default False;
property ParentCtl3D;
property ParentFont;
property ParentShowHint;
property PopupMenu;
property ReadOnly;
property RightClickSelect;
property RowSelect;
property ShowButtons;
property ShowHint;
property ShowLines;
property ShowRoot;
property SortType;
property StateImages;
property TabOrder;
property TabStop default True;
property ToolTips;
property Visible;
property OnAddition;
property OnAdvancedCustomDraw;
property OnAdvancedCustomDrawItem;
property OnChange;
property OnChanging;
property OnClick;
property OnCollapsed;
property OnCollapsing;
property OnCompare;
property OnContextPopup;
property OnCreateNodeClass;
property OnCustomDraw;
property OnCustomDrawItem;
property OnDblClick;
property OnDeletion;
property OnDragDrop;
property OnDragOver;
property OnEdited;
property OnEditing;
property OnEndDock;
property OnEndDrag;
property OnEnter;
property OnExit;
property OnExpanding;
property OnExpanded;
property OnGetImageIndex;
property OnGetSelectedIndex;
property OnKeyDown;
property OnKeyPress;
property OnKeyUp;
property OnMouseDown;
property OnMouseMove;
property OnMouseUp;
property OnStartDock;
property OnStartDrag;
{ Items must be published after OnGetImageIndex and OnGetSelectedIndex }
property Items;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('eb', [TMyTreeView]);
end;
{ TMyTreeView }
constructor TMyTreeView.Create(AOwner: TComponent);
begin
inherited;
fCanExpand := True;
fDblClicEnabled := True;
end;
procedure TMyTreeView.CNNotify(var Message: TWMNotify);
begin
case Message.NMHdr^.code of
TVN_ITEMEXPANDING:
begin
if not(fCanExpand) then
begin
Message.Result := 1; // Blocage du Collapse/Expand
fCanExpand := True;
end;
end;
end;
inherited;
end;
procedure TMyTreeView.WMLButtonDblClk(var Message: TWMLButtonDblClk);
begin
if not(fDblClicEnabled) then
fCanExpand := False;
inherited;
end;
Procedure TMyTreeView.Click;
Begin
Inherited Click;
If not(fDblClicEnabled) then If self.Selected.Expanded then self.Selected.Collapse(false) else self.Selected.Expand(false);
End;
Procedure TMyTreeView.SetDblClicEnabled(Value : Boolean);
Begin
FDblClicEnabled := Value;
If FDblClicEnabled=false then
Begin
ReadOnly:=True;// Le fonctionnement "un seul click" est incompatible avec l'édition du label
AutoExpand:=False;// Le fonctionnement "un seul click" est incompatible avec AutoExpand
End;
End;
end. |
Partager