Menu

[r3204]: / branches / experimental / Src / TrunkSrc / USnippetsTVDraw.pas  Maximize  Restore  History

Download this file

155 lines (134 with data), 4.4 kB

  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
{
* This Source Code Form is subject to the terms of the Mozilla Public License,
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
* obtain one at http://mozilla.org/MPL/2.0/
*
* Copyright (C) 2009-2012, Peter Johnson (www.delphidabbler.com).
*
* $Rev$
* $Date$
*
* Provides an abstract base class that can render tree nodes representing
* snippets in a tree view.
}
unit USnippetsTVDraw;
interface
uses
// Delphi
ComCtrls;
type
{
TSnippetsTVDraw:
Abstract base class that can render tree nodes representing snippets objects
in a tree view.
}
TSnippetsTVDraw = class abstract(TObject)
strict protected
function IsUserDefinedNode(const Node: TTreeNode): Boolean;
virtual; abstract;
{Checks if a node represents a user defined snippets object.
@param Node [in] Node to be checked.
@return True if node represents user defined object, False if not.
}
function IsSectionHeadNode(const Node: TTreeNode): Boolean;
virtual;
{Checks if a node represents a section header.
@param Node [in] Node to be checked.
@return True if node is a section header, False if not.
}
function IsErrorNode(const Node: TTreeNode): Boolean;
virtual;
{Checks if a node represents an error condition.
@param Node [in] Node to be checked.
@return True if node represents error condition, False if not.
}
public
procedure CustomDrawItem(Sender: TCustomTreeView; Node: TTreeNode;
State: TCustomDrawState; var DefaultDraw: Boolean);
{Handles event triggered when a snippets tree view item is to be
displayed. Draws nodes depending on whether group heading, snippet, user
defined, selected or focussed.
@param Sender [in] Reference to treeview being drawn.
@param Node [in] Node to be displayed.
@param State [in] State of node.
@param DefaultDraw [in/out] Not changed. Permits item to be drawn by
system.
}
end;
implementation
uses
// Delphi
Graphics,
// Project
UColours, UPreferences;
{ TSnippetsTVDraw }
procedure TSnippetsTVDraw.CustomDrawItem(Sender: TCustomTreeView;
Node: TTreeNode; State: TCustomDrawState; var DefaultDraw: Boolean);
{Handles event triggered when a snippets tree view item is to be displayed.
Draws nodes depending on whether group heading, snippet, user defined,
selected or focussed.
@param Sender [in] Reference to treeview being drawn.
@param Node [in] Node to be displayed.
@param State [in] State of node.
@param DefaultDraw [in/out] Not changed. Permits item to be drawn by system.
}
var
TV: TTreeView; // reference to treeview being rendered
begin
Assert(Sender is TTreeView,
ClassName + '.CustomDrawItem: Sender is not TTreeView');
TV := Sender as TTreeView;
if Assigned(Node) then
begin
// Set font and background colour according to selected / focusses state
if cdsSelected in State then
begin
if cdsFocused in State then
begin
// selected and focussed
TV.Canvas.Brush.Color := clHighlight;
TV.Canvas.Font.Color := clHighlightText;
end
else
begin
// selected but not focussed
TV.Canvas.Brush.Color := clBtnFace;
TV.Canvas.Font.Color := TV.Font.Color;
end;
end
else
begin
// not selected
if IsErrorNode(Node) then
// colour unselected error nodes differently
TV.Canvas.Font.Color := clWarningText
else
TV.Canvas.Font.Color :=
Preferences.DBHeadingColours[IsUserDefinedNode(Node)];
TV.Canvas.Brush.Color := TV.Color;
end;
if IsSectionHeadNode(Node) then
// make header items bold
TV.Canvas.Font.Style := [fsBold];
DefaultDraw := True;
end;
end;
function TSnippetsTVDraw.IsErrorNode(const Node: TTreeNode): Boolean;
{Checks if a node represents an error condition.
@param Node [in] Node to be checked.
@return True if node represents error condition, False if not.
}
begin
// Default response
Result := False;
end;
function TSnippetsTVDraw.IsSectionHeadNode(const Node: TTreeNode): Boolean;
{Checks if a node represents a section header.
@param Node [in] Node to be checked.
@return True if node is a section header, False if not.
}
begin
// Default response
Result := False;
end;
end.
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.