Repository navigation
Expand file tree
/
Copy pathSCDbNavButton.pas
More file actions
416 lines (363 loc) · 10.5 KB
/
Copy pathSCDbNavButton.pas
File metadata and controls
416 lines (363 loc) · 10.5 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
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
{*******************************************************}
{ }
{ CA SweetControls Component Library }
{ }
{ Copyright (c) 1996,2004 CodeAccelerate Corporation }
{ }
{*******************************************************}
unit SCDbNavButton;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ImgList, Db, DbConsts, SCConsts, SCControl, SCGraphicButton, SCDbCommon;
type
TSCNavConfirmEvent = procedure(Sender: TObject; NavType: TSCNavigateType;
var CanOperate: Boolean) of object;
TSCNavButtonDataLink = class;
TSCCustomNavButton = class(TSCCustomGraphicButton)
private
FDataLink: TSCNavButtonDataLink;
FConfirmDelete: Boolean;
FNavType: TSCNavigateType;
FOnBeforeAction: TSCNavConfirmEvent;
FOnAfterAction: TNotifyEvent;
FOnConfirmDelete: TSCNavConfirmEvent;
function GetDataSource:TDataSource;
procedure SetDataSource(Value: TDataSource);
procedure SetNavType(Value: TSCNavigateType);
protected
procedure Notification(AComponent: TComponent; Operation: TOperation); override;
procedure Loaded; override;
function GetImages: TCustomImageList; override;
function GetImageIndex: TImageIndex; override;
function CanActivate: Boolean; dynamic;
procedure EditingChanged;
procedure DataChanged;
procedure ActiveChanged;
property ConfirmDelete: Boolean read FConfirmDelete write FConfirmDelete default True;
property DataSource: TDataSource read GetDataSource write SetDataSource;
property NavType: TSCNavigateType read FNavType write SetNavType default scntFirst;
property RepeatClick default False;
property RepeatInterval default 150;
property Transparent default False;
property OnAfterAction: TNotifyEvent read FOnAfterAction write FOnAfterAction;
property OnBeforeAction: TSCNavConfirmEvent read FOnBeforeAction write FOnBeforeAction;
property OnConfirmDelete: TSCNavConfirmEvent read FOnConfirmDelete write FOnConfirmDelete;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure Assign(Source: TPersistent); override;
procedure Click; override;
property Enabled default False;
end;
TSCNavButton = class(TSCCustomNavButton)
published
property Align;
property AllowAllUp;
property Anchors;
property ArrowColor;
property BiDiMode;
property Cancel;
property Caption;
property Center;
property Color;
property ConfirmDelete;
property Constraints;
property Cursor;
property DataSource;
property DragCursor;
property DragKind;
property DragMode;
property DropdownMenu;
property EndEllipsis;
property Font;
property Gradient;
property GroupIndex;
property Down;
property HighlightColor;
property HottrackColor;
property Images;
property ImageIndex;
property Indent;
property Layout;
property ModalResult;
property Multiline;
property NavType;
property ParentBiDiMode;
property ParentColor;
property ParentFont;
property ParentShowHint;
property PopupArrow;
property RepeatClick;
property RepeatInterval;
property RoundColor;
property Rounded;
property RoundWithParentColor;
property ShowCaption;
property ShowHint;
property Spacing;
property Style;
property Transparent;
property Visible;
property OnAfterAction;
property OnBeforeAction;
property OnConfirmDelete;
property OnCanResize;
property OnClick;
{$IFDEF SC_DELPHI5_UP}
property OnContextPopup;
{$ENDIF}
property OnDblClick;
property OnDragDrop;
property OnDragOver;
property OnEndDock;
property OnEndDrag;
property OnMouseDown;
property OnMouseEnter;
property OnMouseLeave;
property OnMouseMove;
property OnMouseUp;
property OnResize;
property OnStartDock;
property OnStartDrag;
end;
TSCNavButtonDataLink = class(TDataLink)
private
FNavigator: TSCCustomNavButton;
protected
procedure EditingChanged; override;
procedure DataSetChanged; override;
procedure ActiveChanged; override;
public
constructor Create(ANavBtn: TSCCustomNavButton);
destructor Destroy; override;
end;
implementation
{ TSCNavButtonDataLink }
procedure TSCNavButtonDataLink.ActiveChanged;
begin
if FNavigator <> nil then
FNavigator.ActiveChanged;
end;
constructor TSCNavButtonDataLink.Create(ANavBtn: TSCCustomNavButton);
begin
inherited Create;
FNavigator := ANavBtn;
VisualControl := True;
end;
procedure TSCNavButtonDataLink.DataSetChanged;
begin
if FNavigator <> nil then
FNavigator.DataChanged;
end;
destructor TSCNavButtonDataLink.Destroy;
begin
FNavigator := nil;
inherited Destroy;
end;
procedure TSCNavButtonDataLink.EditingChanged;
begin
if FNavigator <> nil then
FNavigator.EditingChanged;
end;
{ TSCCustomNavButton }
procedure TSCCustomNavButton.ActiveChanged;
begin
if (FDataLink = nil) or not (FDataLink.Active and CanActivate) then
Enabled := False
else begin
DataChanged;
EditingChanged;
end;
end;
procedure TSCCustomNavButton.Assign(Source: TPersistent);
begin
inherited Assign(Source);
if Source is TSCCustomNavButton then
begin
with TSCCustomNavButton(Source) do
begin
Self.DataSource := DataSource;
Self.ConfirmDelete := ConfirmDelete;
Self.NavType := NavType;
end;
end;
end;
function TSCCustomNavButton.CanActivate: Boolean;
begin
Result := True;
end;
procedure TSCCustomNavButton.Click;
var
CanOperate: Boolean;
begin
inherited Click;
if (IsLoading or IsDestroying) or not Enabled or
(DataSource = nil) or (DataSource.DataSet = nil) or
(DataSource.DataSet.State = dsInactive) then
Exit;
CanOperate := True;
if Assigned(FOnBeforeAction) then
FOnBeforeAction(Self, FNavType, CanOperate);
if CanOperate then
with DataSource.DataSet do
begin
case NavType of
scntAppend: Append;
scntInsert: Insert;
scntEdit: Edit;
scntPost: Post;
scntCancel: Cancel;
scntRefresh: Refresh;
scntFirst: First;
scntPrior: Prior;
scntNext: Next;
scntLast: Last;
scntDelete:
begin
CanOperate := True;
if FConfirmDelete and Assigned(FOnConfirmDelete) then
FOnConfirmDelete(Self, FNavType, CanOperate);
if CanOperate then
Delete;
end;
end;
end;
if Assigned(FOnAfterAction) then
FOnAfterAction(Self);
end;
constructor TSCCustomNavButton.Create(AOwner: TComponent);
begin
FNavType := scntFirst;
inherited Create(AOwner);
ControlStyle := ControlStyle - [csReplicatable];
FDataLink := TSCNavButtonDataLink.Create(Self);
FConfirmDelete := True;
Enabled := False;
Transparent := False;
RepeatClick := False;
RepeatInterval := 150;
SetNavType(scntFirst);
end;
procedure TSCCustomNavButton.DataChanged;
var
UpEnable, DnEnable: Boolean;
begin
UpEnable := (FDataLink <> nil) and FDataLink.Active and
(FDataLink.DataSet <> nil) and not FDataLink.DataSet.BOF;
DnEnable := (FDataLink <> nil) and FDataLink.Active and
(FDataLink.DataSet <> nil) and not FDataLink.DataSet.EOF;
case FNavType of
scntFirst:
Enabled := UpEnable;
scntPrior:
Enabled := UpEnable;
scntNext:
Enabled := DnEnable;
scntLast:
Enabled := DnEnable;
scntDelete:
Enabled := (FDataLink <> nil) and FDataLink.Active and
(FDataLink.DataSet <> nil) and FDataLink.DataSet.CanModify and
not (FDataLink.DataSet.BOF and FDataLink.DataSet.EOF);
end;
end;
destructor TSCCustomNavButton.Destroy;
begin
FDataLink.Free;
FDataLink := nil;
inherited Destroy;
end;
procedure TSCCustomNavButton.EditingChanged;
var
CanModify: Boolean;
begin
CanModify := (FDataLink <> nil) and FDataLink.Active and
(FDataLink.DataSet <> nil) and FDataLink.DataSet.CanModify;
case FNavType of
scntAppend:
Enabled := CanModify;
scntInsert:
Enabled := CanModify;
scntEdit:
Enabled := CanModify and not FDataLink.Editing;
scntPost:
Enabled := CanModify and FDataLink.Editing;
scntCancel:
Enabled := CanModify and FDataLink.Editing;
scntRefresh:
Enabled := CanModify;
end;
end;
function TSCCustomNavButton.GetDataSource: TDataSource;
begin
Result := nil;
if FDataLink <> nil then
Result := FDataLink.DataSource;
end;
function TSCCustomNavButton.GetImageIndex: TImageIndex;
begin
Result := inherited GetImageIndex;
if Self.Images = nil then
case FNavType of
scntFirst:
Result := 0;
scntPrior:
Result := 1;
scntNext:
Result := 2;
scntLast:
Result := 3;
scntInsert:
Result := 4;
scntAppend:
Result := 5;
scntDelete:
Result := 6;
scntEdit:
Result := 7;
scntPost:
Result := 8;
scntCancel:
Result := 9;
scntRefresh:
Result := 10;
end;
end;
function TSCCustomNavButton.GetImages: TCustomImageList;
begin
Result := inherited GetImages;
if Result = nil then Result := SCDBImages;
end;
procedure TSCCustomNavButton.Loaded;
begin
inherited Loaded;
ActiveChanged;
end;
procedure TSCCustomNavButton.Notification(AComponent: TComponent;
Operation: TOperation);
begin
inherited Notification(AComponent, Operation);
if (Operation = opRemove) and (FDataLink <> nil) and
(AComponent = DataSource) then DataSource := nil;
end;
procedure TSCCustomNavButton.SetDataSource(Value: TDataSource);
begin
if FDataLink <> nil then
FDataLink.DataSource := Value;
end;
procedure TSCCustomNavButton.SetNavType(Value: TSCNavigateType);
var
R1, R2: TSCNavButtonRec;
begin
R1 := GetNavigateTypeRec(FNavType);
R2 := GetNavigateTypeRec(Value);
FNavType := Value;
if (Caption = R1.Caption) or ((Caption = Self.Name) and IsDesigning) then
Self.Caption := R2.Caption;
if (Hint = R1.Hint) or ((Hint = '') and IsDesigning) then
Self.Hint := R2.Hint;
ActiveChanged;
end;
{$I SCVerRec.inc}
end.