-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvisual.pas
More file actions
259 lines (217 loc) · 6.35 KB
/
visual.pas
File metadata and controls
259 lines (217 loc) · 6.35 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
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
unit Visual;
{$mode ObjFPC}{$H+}
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Windows, Dialogs, StdCtrls, ComCtrls,
Types, Buttons, Extctrls;
type
{ TVisual }
TVisual = class(TObject)
private
function NodeChecked(ANode:TTreeNode): Boolean;
public
constructor Create; overload;
destructor Destroy; override;
procedure ActiveTextBackGroundColor(Sender: TObject; Enable: Boolean);
function CheckEntryLength(Sender: TObject; aLength: Integer) : Boolean;
procedure AlterSystemMenu;
procedure CheckNode(Node: TTreeNode; Checked:boolean);
procedure ToggleTreeViewCheckBoxes(Node: TTreeNode);
function Helptext(Sender: TObject; aText : string) : String;
end;
implementation
uses Form_Main, Settings;
const
ImgIndexChecked = 0;
ImgIndexUnchecked = 1;
{ TVisual }
{%region Checkboxes treeview}
// Simulate checkbox in treeview with an image.
procedure TVisual.CheckNode(Node: TTreeNode; Checked: boolean);
begin
if Assigned(Node) then
if Checked then
Node.StateIndex := ImgIndexChecked
else
Node.StateIndex := ImgIndexUnchecked;
end;
procedure TVisual.ToggleTreeViewCheckBoxes(Node: TTreeNode);
begin
if Assigned(Node) then begin
if Node.StateIndex = ImgIndexUnchecked then
Node.StateIndex := ImgIndexChecked
else
if Node.StateIndex = ImgIndexChecked then
Node.StateIndex := ImgIndexUnchecked
end;
end;
function TVisual.NodeChecked(ANode: TTreeNode): Boolean;
begin
result := (ANode.StateIndex = ImgIndexChecked);
end;
{%endregion Checkboxes treeview}
{%region constructor - destructor}
constructor TVisual.Create;
begin
inherited;
//
end;
destructor TVisual.Destroy;
begin
//
inherited Destroy;
end;
{%endregion constructor - destructor}
procedure TVisual.ActiveTextBackGroundColor(Sender: TObject; Enable: Boolean);
var
_Edit : TEdit;
_ComboBox : TComboBox;
_Memo : TMemo;
begin
if sender is TEdit then
begin
_Edit := TEdit(sender);
if Enable then begin
_Edit.Color := clGradientInactiveCaption
end
else begin
_Edit.Color := clDefault;
end;
end
else if sender is TComboBox then
begin
_ComboBox := TComboBox(sender);
if Enable then begin
_ComboBox.Color := clGradientInactiveCaption;
end
else begin
_ComboBox.Color := clDefault;
end;
end
else if sender is TMemo then begin
_Memo := TMemo(sender);
if Enable then begin
_Memo.Color := clGradientInactiveCaption;
end
else begin
_Memo.Color := clDefault;
end;
end;
end;
function TVisual.CheckEntryLength(Sender: TObject; aLength: Integer) : Boolean;
var
_Edit : TEdit;
_Memo : TMemo;
_ComboBox : TComboBox;
begin
if aLength > 0 then begin
if sender is TEdit then begin
_Edit := TEdit(sender);
if Length(_Edit.Text) > aLength then begin
_Edit.Font.Color := clRed;
Result := false;
end
else begin
_Edit.Font.Color := clDefault;
Result := true;
end;
end
else if sender is TMemo then begin
_Memo := TMemo(sender);
if Length(_Memo.Text) > aLength then begin
_Memo.Font.Color := clRed;
Result := false;
end
else begin
_Memo.Font.Color := clDefault;
Result := true;
end;
end
else if sender is TComboBox then begin
_ComboBox := TComboBox(sender);
if Length(_ComboBox.Text) > aLength then begin
_ComboBox.Font.Color := clRed;
Result := false;
end
else begin
_ComboBox.Font.Color := clDefault;
Result := true;
end;
end;
end;
end;
procedure TVisual.AlterSystemMenu;
// Expand system menu with 1 line
const
sMyMenuCaption1 = Settings.ApplicationName + ' V' + Settings.Version + '.' + ' (HvB)';
SC_MyMenuItem1 = WM_USER + 1;
var
SysMenu : HMenu;
begin
SysMenu := GetSystemMenu(FrmMain.Handle, FALSE) ; {Get system menu}
AppendMenu(SysMenu, MF_SEPARATOR, 0, '') ; {Add a seperator bar to main form}
// AppendMenu(SysMenu, MF_STRING, SC_MyMenuItem1, '') ; //empty line
AppendMenu(SysMenu, MF_STRING, SC_MyMenuItem1, sMyMenuCaption1) ; {add our menu}
end;
function TVisual.Helptext(Sender: TObject; aText: string) : String;
var
MyPoint : TPoint;
_Button : TButton;
_TBitBtn : TBitBtn;
_Checkbox : TCheckbox;
_Edit : TEdit;
_Label : TLabel;
_ComboBox : TComboBox;
_RadioGroup : TRadioGroup;
begin
if sender is TRadioGroup then begin
_RadioGroup := TRadioGroup(sender);
MyPoint := _RadioGroup.ScreenToClient(Mouse.CursorPos);
if (PtInRect(_RadioGroup.ClientRect, MyPoint)) then begin // Mouse is inside the control, do something here.
Result := aText;
end;
end;
if sender is TButton then begin
_Button := TButton(sender);
MyPoint := _Button.ScreenToClient(Mouse.CursorPos);
if (PtInRect(_Button.ClientRect, MyPoint)) then begin
Result := aText;
end;
end;
if sender is TBitBtn then begin
_TBitBtn := TBitBtn(sender);
MyPoint := _TBitBtn.ScreenToClient(Mouse.CursorPos);
if (PtInRect(_TBitBtn.ClientRect, MyPoint)) then begin
Result := aText;
end;
end;
if sender is TCheckbox then begin
_Checkbox := TCheckbox(sender);
MyPoint := _Checkbox.ScreenToClient(Mouse.CursorPos);
if (PtInRect(_Checkbox.ClientRect, MyPoint)) then begin
Result := aText;
end;
end;
if sender is TEdit then begin
_Edit := TEdit(sender);
MyPoint := _Edit.ScreenToClient(Mouse.CursorPos);
if (PtInRect(_Edit.ClientRect, MyPoint)) then begin
Result := aText;
end;
end;
if sender is TLabel then begin
_Label := TLabel(sender);
MyPoint := _Label.ScreenToClient(Mouse.CursorPos);
if (PtInRect(_Label.ClientRect, MyPoint)) then begin
Result := aText;
end;
end;
if sender is TCombobox then begin
_Combobox := TCombobox(sender);
MyPoint := _Combobox.ScreenToClient(Mouse.CursorPos);
if (PtInRect(_Combobox.ClientRect, MyPoint)) then begin
Result := aText;
end;
end;
end;
end.