-
Notifications
You must be signed in to change notification settings - Fork 10
/
DW.VCL.List.pas
87 lines (71 loc) · 2.21 KB
/
DW.VCL.List.pas
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
unit DW.VCL.List;
interface
uses
SysUtils, Classes, Controls, StrUtils, DW.VCL.CustomRegion, DW.VCL.Control,
DWElementTag;
type
TIWBSListType = (bsltNone, bsltDropDownMenu, bsltGroup, bsltInline, bsltNav, bsltPager,
bsltPagination, bsltPaginationLg, bsltPaginationSm, bsltBreadcrumb);
const
aIWBSListType: array [bsltNone .. bsltBreadcrumb] of string = ('', 'dropdown-menu', 'list-group',
'list-inline', 'nav navbar-nav', 'pager', 'pagination', 'pagination pagination-lg',
'pagination pagination-sm', 'breadcrumb');
type
TDWList = class(TDWCustomRegion)
private
FListType: TIWBSListType;
procedure SetListType(const Value: TIWBSListType);
protected
procedure InternalRenderCss(var ACss: string); override;
procedure SetParent(AParent: TWinControl); override;
public
constructor Create(AOwner: TComponent); override;
class procedure WrapItem(AControl: TDWControl; var AHTMLTag: TDWElementTag);
published
property BSListType: TIWBSListType read FListType write SetListType default bsltNone;
end;
implementation
uses
DW.VCL.Common, DW.VCL.NavBar, DW.VCL.Region, DWTypes;
constructor TDWList.Create(AOwner: TComponent);
begin
inherited;
FTagName := 'ul';
end;
procedure TDWList.InternalRenderCss(var ACss: string);
begin
TDWBSCommon.AddCssClass(ACss, aIWBSListType[FListType]);
inherited;
end;
procedure TDWList.SetListType(const Value: TIWBSListType);
begin
if Parent is TDWNavBarBase then
FListType := bsltNav
else
FListType := Value;
Invalidate;
end;
procedure TDWList.SetParent(AParent: TWinControl);
begin
inherited;
if (AParent is TDWNavBarBase) then
FListType := bsltNav
else if (AParent is TDWRegion) and (TDWRegion(Parent).BSRegionType = bsrtDropDown) then
FListType := bsltDropDownMenu;
end;
class procedure TDWList.WrapItem(AControl: TDWControl; var AHTMLTag: TDWElementTag);
var
xHTMLTag: TDWElementTag;
begin
if AControl.Parent is TDWList then
begin
xHTMLTag := TDWElementTag.CreateHTMLTag('li');
case TDWList(AControl.Parent).BSListType of
bsltGroup:
xHTMLTag.AddClassParam('list-group-item');
end;
xHTMLTag.Contents.AddElemetAsObject(AHTMLTag);
AHTMLTag := xHTMLTag;
end;
end;
end.