/
Card.pas
285 lines (264 loc) · 9.05 KB
/
Card.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
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
{
Copyright (C) 2006-2008 Matteo Salvi of SalvadorSoftware
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
}
unit Card;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, ComCtrls, ShellApi, VirtualTrees, CommonClasses;
type
TfrmCard = class(TForm)
pcCard: TPageControl;
tbHome: TTabSheet;
GroupBox3: TGroupBox;
lbASuiteWebSite: TLabel;
imASuiteLogo: TImage;
lbASuiteTitle: TLabel;
lbASuiteVersion: TLabel;
memIntro: TMemo;
tbCard: TTabSheet;
lbDesc: TLabel;
lbOpinion: TLabel;
lbNotes: TLabel;
gbSoftware: TGroupBox;
lbxSHouse: TLabel;
lbWebSite: TLabel;
lbxName: TLabel;
lbxVersion: TLabel;
memOpinion: TMemo;
memNotes: TMemo;
memDesc: TMemo;
lbName: TLabel;
lbSHouse: TLabel;
lbVersion: TLabel;
procedure GetInfoCard(Sender: TBaseVirtualTree;Node: PVirtualNode);
procedure lbASuiteWebSiteClick(Sender: TObject);
procedure TranslateForm(Lingua: string);
procedure FormCreate(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure lbWebSiteClick(Sender: TObject);
procedure FormActivate(Sender: TObject);
private
{ Private declarations }
FArea: Cardinal;
UnMagnet: Boolean;
OldPoint: TPoint;
procedure WMMoving(var Msg: TWMMoving); message WM_Moving;
public
{ Public declarations }
end;
TSideMagnet = (smNone, smLeft, smTop, smRight, smBottom); //None, Left, Top, Right, Bottom
var
frmCard : TfrmCard;
SideMagnet : TSideMagnet;
implementation
uses Main, Menu, CommonUtils, Types;
{$R *.dfm}
procedure TfrmCard.FormActivate(Sender: TObject);
begin
if IsFormOpen('frmMenu') then
frmMenu.CloseMenu;
end;
procedure TfrmCard.FormCreate(Sender: TObject);
begin
FArea := 15;
TranslateForm(LauncherOptions.LangName);
end;
procedure TfrmCard.FormShow(Sender: TObject);
begin
if (frmMain.Left + frmMain.Width + Width) <= (GetDeviceCaps(GetDC(frmCard.Handle), HORZRES)) then
begin
Left := frmMain.Left + frmMain.Width;
SideMagnet := smLeft;
end
else begin
Left := frmMain.Left - Width;
SideMagnet := smRight;
end;
Top := frmMain.Top;
if pcCard.ActivePageIndex = 1 then
Caption := TransCompName.Card
else
Caption := TransCompName.About;
end;
procedure TfrmCard.GetInfoCard(Sender: TBaseVirtualTree;Node: PVirtualNode);
var
NodeData : PTreeData;
begin
if Assigned(Node) then
begin
NodeData := Sender.GetNodeData(Node);
if NodeData.Tipo = 1 then
begin
pcCard.ActivePageIndex := 1;
Caption := TransCompName.Card;
//Components position
if lbxName.Width < lbxSHouse.Width then
begin
lbName.Left := lbxSHouse.Left + lbxSHouse.Width + 4;
lbSHouse.Left := lbxSHouse.Left + lbxSHouse.Width + 4;
end
else begin
lbName.Left := lbxName.Left + lbxName.Width + 4;
lbSHouse.Left := lbxName.Left + lbxName.Width + 4;
end;
lbVersion.Left := lbxVersion.Left + lbxVersion.Width + 4;
//Get infos
with NodeData^ do
begin
lbName.Caption := Name;
lbSHouse.Caption := Developer;
lbVersion.Caption := Version;
lbWebSite.Enabled := Not((WebSite = '') or (WebSite = 'http://'));
memDesc.Text := StringReplace(Desc,'[br]',#13#10,[rfReplaceAll]);
memOpinion.Text := StringReplace(Opinion,'[br]',#13#10,[rfReplaceAll]);
memNotes.Text := StringReplace(Notes,'[br]',#13#10,[rfReplaceAll]);
end;
end;
end;
end;
procedure TfrmCard.lbASuiteWebSiteClick(Sender: TObject);
begin
ShellExecute(GetDesktopWindow, 'open', PChar(lbASuiteWebSite.Caption), nil, nil, SW_SHOWDEFAULT);
end;
procedure TfrmCard.lbWebSiteClick(Sender: TObject);
var
NodeData : PTreeData;
begin
with frmMain do
begin
if Assigned(vstList.FocusedNode) then
begin
NodeData := vstList.GetNodeData(vstList.FocusedNode);
if NodeData.Tipo = 1 then
ShellExecute(GetDesktopWindow, 'open', PChar(String(NodeData.WebSite)),
nil, nil, SW_SHOWDEFAULT);
end;
end;
end;
procedure TfrmCard.TranslateForm(Lingua: string);
begin
with frmMain.xmldTranslate.DocumentElement.ChildNodes['Form2'] do
begin
main.TransCompName.Card := ChildNodes['FormCaptionCard'].Text;
main.TransCompName.About := ChildNodes['FormCaptionAbout'].Text;
//tbHome (About)
lbASuiteVersion.Caption := ChildNodes['LabelASVersion'].Text + ReleaseVersion;
if PreReleaseVersion <> '' then
lbASuiteVersion.Caption := lbASuiteVersion.Caption + PreReleaseVersion;
memIntro.Text := StringReplace(ChildNodes['LabelIntro'].Text,'[br]',#13#10,[rfReplaceAll]);
//tbCard
gbSoftware.Caption := ChildNodes['GroupBoxSoftware'].Text;
lbxName.Caption := ChildNodes['LabelNameSw'].Text;
lbxSHouse.Caption := ChildNodes['LabelDeveloper'].Text;
lbxVersion.Caption := ChildNodes['LabelVersion'].Text;
lbWebSite.Caption := ChildNodes['LabelWebSite'].Text;
lbDesc.Caption := ChildNodes['LabelDescription'].Text;
lbNotes.Caption := ChildNodes['LabelNote'].Text;
lbOpinion.Caption := ChildNodes['LabelOpinion'].Text;
end;
end;
procedure TfrmCard.WMMoving(var Msg: TWMMoving);
var
MainRect, FormRect : TRect;
Point : TPoint;
begin
//Save position of frmCard and frmMain in FormRect and MainRect
FormRect := Msg.DragRect^;
MainRect.Left := Application.MainForm.Left;
MainRect.Top := Application.MainForm.Top;
MainRect.Right := Application.MainForm.Left + Application.MainForm.Width;
MainRect.Bottom := Application.MainForm.Top + Application.MainForm.Height;
//Mouse position - If Magnet is active, this code
GetCursorPos(Point);
UnMagnet := False;
if (SideMagnet <> smNone) then
begin
//Coordinate X
if (SideMagnet = smLeft) or
(SideMagnet = smRight) then
begin
if (OldPoint.X < Point.X - 5) or
(OldPoint.X > Point.X + 5) then
UnMagnet := True;
end;
//Coordinate Y
if (SideMagnet = smTop) or
(SideMagnet = smBottom) then
begin
if (OldPoint.Y < Point.Y - 5) or
(OldPoint.Y > Point.Y + 5) then
UnMagnet := True;
end;
end;
OldPoint := Point;
if Not(UnMagnet) then
begin
//Coordinate X
if (formRect.Bottom > MainRect.Top) and
(formRect.Top < MainRect.Top + frmMain.Height) then
begin
//Right
if ((formRect.Right < MainRect.Left) and
(formRect.Right > MainRect.Left - Integer(FArea))) or
((formRect.Right > MainRect.Left) and
(formRect.Right < MainRect.Left + Integer(FArea))) then
begin
formRect.Left := MainRect.Left - frmCard.Width;
formRect.Right := MainRect.Left;
SideMagnet := smRight;
end;
//Left
if ((formRect.Left < MainRect.Right) and
(formRect.Left > MainRect.Right - Integer(FArea))) or
((formRect.Left > MainRect.Right) and
(formRect.Left < MainRect.Right + Integer(FArea))) then
begin
formRect.Left := MainRect.Left + frmMain.Width;
formRect.Right := formRect.Left + frmCard.Width;
SideMagnet := smLeft;
end;
end;
//Coordinate Y
if (formRect.Right > MainRect.Left) and
(formRect.Left < MainRect.Right) then
begin
//Bottom
if ((formRect.Bottom < MainRect.Top) and
(formRect.Bottom > MainRect.Top - Integer(FArea))) or
((formRect.Bottom > MainRect.Top) and
(formRect.Bottom < MainRect.Top + Integer(FArea))) then
begin
formRect.Top := MainRect.Top - frmCard.Height;
formRect.Bottom := MainRect.Top;
SideMagnet := smBottom;
end;
//Top
if ((formRect.Top < MainRect.Bottom) and
(formRect.Top > MainRect.Bottom - Integer(FArea))) or
((formRect.Top > MainRect.Bottom) and
(formRect.Top < MainRect.Bottom + Integer(FArea))) then
begin
formRect.Top := MainRect.Bottom;
formRect.Bottom := formRect.Top + frmCard.Height;
SideMagnet := smTop;
end;
end;
Msg.DragRect^ := FormRect;
end
else begin
SideMagnet := smNone;
end;
end;
end.