-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathDW.OTA.BaseProjectConfigComboBox.pas
More file actions
201 lines (175 loc) · 5.37 KB
/
DW.OTA.BaseProjectConfigComboBox.pas
File metadata and controls
201 lines (175 loc) · 5.37 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
unit DW.OTA.BaseProjectConfigComboBox;
{*******************************************************}
{ }
{ TOTAL - Terrific Open Tools API Library }
{ }
{*******************************************************}
interface
uses
System.Types, System.Classes,
Winapi.Messages,
Vcl.Controls, Vcl.StdCtrls,
DW.Proj.Types,
DW.OTA.Types;
const
cProjectPlatformsShort: array[TProjectPlatform] of string = (
'Android', 'Android64',
'iOSDevice32', 'iOSDevice64', 'iOSSimARM64',
'Linux64',
'OSX32', 'OSX64', 'OSXARM64',
'Win32', 'Win64'
);
type
TProjectPlatformHelper = record
class function FindProjectPlatform(const AShortName: string; out APlatform: TProjectPlatform): Boolean; static;
end;
TProjectTarget = record
Config: TProjConfig;
Target: TProjectPlatform;
IsAllPlatforms: Boolean;
constructor Create(const AConfig: TProjConfig; const ATarget: TProjectPlatform; const AIsAllPlatforms: Boolean);
function GetDisplayValue(const ANeedExtended: Boolean): string;
end;
TProjectTargets = TArray<TProjectTarget>;
TProjectTargetsHelper = record helper for TProjectTargets
procedure Add(const ATarget: TProjectTarget);
end;
TBaseProjectConfigComboBox = class(TComboBox)
private
FTargets: TProjectTargets;
protected
procedure DrawItem(Index: Integer; Rect: TRect; State: TOwnerDrawState); override;
procedure DoLoadTargets; virtual;
property Targets: TProjectTargets read FTargets;
public
constructor Create(AOwner: TComponent); override;
procedure Clear; override;
procedure LoadTargets;
end;
implementation
uses
System.SysUtils, System.IOUtils,
Winapi.Windows,
{$IF Defined(EXPERT)}
BrandingAPI,
{$ENDIF}
Vcl.Graphics;
const
cProjectPlatformsLong: array[TProjectPlatform] of string = (
'Android 32-bit', 'Android 64-bit',
'iOS 32-bit', 'iOS 64-bit', 'iOS Simulator ARM 64-bit',
'Linux 64-bit',
'macOS 32-bit', 'macOS 64-bit', 'macOS ARM 64-bit',
'Windows 32-bit', 'Windows 64-bit'
);
{ TProjectPlatformHelper }
class function TProjectPlatformHelper.FindProjectPlatform(const AShortName: string; out APlatform: TProjectPlatform): Boolean;
var
LPlatform: TProjectPlatform;
begin
Result := False;
for LPlatform := Low(TProjectPlatform) to High(TProjectPlatform) do
begin
if SameText(cProjectPlatformsShort[LPlatform], AShortName) then
begin
APlatform := LPlatform;
Result := True;
Break;
end;
end;
end;
{ TProjectTargetsHelper }
procedure TProjectTargetsHelper.Add(const ATarget: TProjectTarget);
begin
Self := Self + [ATarget];
end;
{ TProjectTarget }
constructor TProjectTarget.Create(const AConfig: TProjConfig; const ATarget: TProjectPlatform; const AIsAllPlatforms: Boolean);
begin
Config := AConfig;
Target := ATarget;
IsAllPlatforms := AIsAllPlatforms;
end;
function TProjectTarget.GetDisplayValue(const ANeedExtended: Boolean): string;
begin
if Config.Name = 'Base' then
Result := 'All Configurations'
else
Result := Config.Name + ' Configuration';
if not IsAllPlatforms then
begin
if ANeedExtended then
Result := Format('%s - %s', [Result, cProjectPlatformsLong[Target]])
else
Result := cProjectPlatformsLong[Target]
end;
end;
{ TBaseProjectConfigComboBox }
constructor TBaseProjectConfigComboBox.Create(AOwner: TComponent);
begin
inherited;
Style := csOwnerDrawFixed;
end;
procedure TBaseProjectConfigComboBox.Clear;
begin
inherited;
FTargets := [];
Enabled := False;
end;
procedure TBaseProjectConfigComboBox.LoadTargets;
begin
Clear;
Items.BeginUpdate;
try
DoLoadTargets;
finally
Items.EndUpdate;
end;
if Length(Targets) > 24 then
DropDownCount := 24
else
DropDownCount := Length(Targets);
if Items.Count > 0 then
ItemIndex := 0;
Enabled := Items.Count > 0;
end;
procedure TBaseProjectConfigComboBox.DoLoadTargets;
begin
//
end;
procedure TBaseProjectConfigComboBox.DrawItem(Index: Integer; Rect: TRect; State: TOwnerDrawState);
var
LTarget: TProjectTarget;
begin
TControlCanvas(Canvas).UpdateTextFlags;
{$IF Defined(EXPERT)}
if (ThemeProperties <> nil) and (odSelected in State) then
begin
Canvas.Brush.Color := ThemeProperties.StyleServices.GetSystemColor(clHighlight);
Canvas.Font.Color := ThemeProperties.StyleServices.GetSystemColor(clHighlightText);
end;
{$ENDIF}
Canvas.FillRect(Rect);
if Index >= 0 then
begin
LTarget := FTargets[Index];
if (odComboBoxEdit in State) or not DroppedDown then
begin
Canvas.Font.Style := Canvas.Font.Style - [fsBold];
Canvas.TextOut(Rect.Left, Rect.Top, LTarget.GetDisplayValue(True));
end
else
begin
if LTarget.IsAllPlatforms then
Canvas.Font.Style := Canvas.Font.Style + [fsBold]
else
Canvas.Font.Style := Canvas.Font.Style - [fsBold];
Canvas.TextOut(Rect.Left + (Ord(not LTarget.IsAllPlatforms) * 16), Rect.Top, LTarget.GetDisplayValue(odComboBoxEdit in State));
end;
{$IF Defined(EXPERT)}
if (ThemeProperties <> nil) and (odFocused in State) then
DrawFocusRect(Canvas.Handle, Rect);
{$ENDIF}
end;
end;
end.