-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUnit1.pas
More file actions
323 lines (274 loc) · 9.99 KB
/
Copy pathUnit1.pas
File metadata and controls
323 lines (274 loc) · 9.99 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
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ComCtrls, ChromeTabs,
ChromeTabsClasses, ChromeTabsTypes,
Vcl.StdCtrls, cxGraphics, cxControls, cxLookAndFeels, cxLookAndFeelPainters,
cxPC, Vcl.ExtCtrls;
type
TForm1 = class(TForm)
ChromeTabs1: TChromeTabs;
Memo1: TMemo;
Button1: TButton;
cxPageControl1: TcxPageControl;
Panel1: TPanel;
Button2: TButton;
Edit1: TEdit;
ChromeTabs2: TChromeTabs;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure ChromeTabs1ActiveTabChanged(Sender: TObject; ATab: TChromeTab);
procedure ChromeTabs1ActiveTabChanging(Sender: TObject;
AOldTab, ANewTab: TChromeTab; var Allow: Boolean);
procedure ChromeTabs1ButtonAddClick(Sender: TObject; var Handled: Boolean);
procedure ChromeTabs1ButtonCloseTabClick(Sender: TObject; ATab: TChromeTab;
var Close: Boolean);
procedure ChromeTabs1NeedDragImageControl(Sender: TObject; ATab: TChromeTab;
var DragControl: TWinControl);
procedure ChromeTabs1TabDragDrop(Sender: TObject; X, Y: Integer;
DragTabObject: IDragTabObject; Cancelled: Boolean;
var TabDropOptions: TTabDropOptions);
procedure ChromeTabs1TabDragDropped(Sender: TObject; DragTabObject:
IDragTabObject; NewTab: TChromeTab);
procedure ChromeTabs1TabDragOver(Sender: TObject; X, Y: Integer;
State: TDragState; DragTabObject: IDragTabObject; var Accept: Boolean);
procedure ChromeTabs1TabDragStart(Sender: TObject; ATab: TChromeTab; var Allow:
Boolean);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
function AddTab(ChromeTabs: TChromeTabs; const Text: String;
ImageIndex: Integer): TChromeTab;
procedure Log(aTitle, aContent: string);
procedure ProcessDroppedTab(Sender: TObject; X, Y: Integer;
DragTabObject: IDragTabObject; Cancelled: Boolean;
var TabDropOptions: TTabDropOptions);
public
{ Public declarations }
// taskbar icon application
// -------------------------------------------------------------------------
function GetAppID(AHandle: THandle): string;
function SetAppID(AHandle: THandle; const AAppID: String): Boolean;
procedure CreateParams(var Params: TCreateParams); override;
// -------------------------------------------------------------------------
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
uses Unit2, ActiveX, PropSys, PropKey;
function TForm1.AddTab(ChromeTabs: TChromeTabs; const Text: String;
ImageIndex: Integer): TChromeTab;
begin
Result := ChromeTabs.Tabs.Add;
Result.Caption := Text;
Result.ImageIndex := ImageIndex;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
Memo1.Lines.Clear;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
cxPageControl1.Pages[StrToInt(Edit1.Text)].Free;
end;
procedure TForm1.ChromeTabs1ActiveTabChanged(Sender: TObject; ATab: TChromeTab);
begin
// Log('ActiveTabChangedEvent', '[tabIndex: ' + IntToStr(ATab.Index) + ']');
if ChromeTabs1.Tabs.Count = cxPageControl1.PageCount then
cxPageControl1.ActivePageIndex := ATab.Index;
Text := cxPageControl1.ActivePage.Caption;
end;
procedure TForm1.ChromeTabs1ActiveTabChanging(Sender: TObject;
AOldTab, ANewTab: TChromeTab; var Allow: Boolean);
begin
// Log('ActiveTabChangingEvent', '[newTabIndex: ' + IntToStr(ANewTab.Index) + ']');
// cxPageControl1.ActivePageIndex := ANewTab.Index;
end;
procedure TForm1.ChromeTabs1ButtonAddClick(Sender: TObject;
var Handled: Boolean);
var
sTabTitle: string;
tabSheet: TcxTabSheet;
currentCount: Integer;
NewForm2: TForm2;
NewForm1: TForm1;
begin
// get current chrome tabs index
currentCount := (Sender as TChromeTabs).Tabs.Count;
// Log
Log('ButtonAddClickEvent', '[TabIndex: ' + IntToStr(currentCount) + ']');
// add new tab
sTabTitle := 'Page' + IntToStr(currentCount);
AddTab(ChromeTabs1, sTabTitle, -1);
Handled := TRUE;
// add new page
tabSheet := TcxTabSheet.Create(Nil);
with tabSheet do
begin
PageControl := cxPageControl1;
Name := sTabTitle;
Caption := sTabTitle;
// TabVisible := False;
end;
cxPageControl1.ActivePageIndex := currentCount;
// change form title
Text := tabSheet.Caption;
// create new form, embedded to page control
NewForm2 := TForm2.Create(Application);
NewForm2.Parent := tabSheet;
NewForm2.Align := TAlign.alClient;
NewForm2.BorderStyle := TFormBorderStyle.bsNone;
NewForm2.Button1.Caption := 'button' + IntToStr(currentCount);
NewForm2.Show;
end;
procedure TForm1.ChromeTabs1NeedDragImageControl(Sender: TObject;
ATab: TChromeTab; var DragControl: TWinControl);
begin
// set drag image
if ATab.Index < cxPageControl1.PageCount then
DragControl := cxPageControl1.Pages[ATab.Index];
end;
procedure TForm1.ChromeTabs1TabDragOver(Sender: TObject; X, Y: Integer;
State: TDragState; DragTabObject: IDragTabObject; var Accept: Boolean);
var
Tabs: TChromeTabs;
begin
Tabs := Sender as TChromeTabs;
if Tabs.ActiveDragTabObject <> nil then
begin
// Log('DragOverEvent', '[DragTabIndex: ' + IntToStr(Tabs.ActiveDragTabObject.DragTab.Index) + ']');
// Log('DragOverEvent', '[DropTabIndex: ' + IntToStr(Tabs.ActiveDragTabObject.DropTabIndex) + ']');
// Log('DragOverEvent', '[ChromeTabCount: ' + IntToStr(ChromeTabs1.Tabs.Count) + ', PageCount: ' + IntToStr(cxPageControl1.PageCount) + ']');
// Log('DragOverEvent', '[ActiveTabsIndex: ' + IntToStr(Tabs.ActiveTabIndex) + ', ActivePageIndex: ' + IntToStr(cxPageControl1.ActivePageIndex) + ']');
// Log('drag index', IntToStr(Tabs.ActiveDragTabObject.DragTab.Index));
// Log('drop index', IntToStr(Tabs.ActiveDragTabObject.DropTabIndex));
if Tabs.ActiveDragTabObject.DropTabIndex < cxPageControl1.PageCount then
cxPageControl1.Pages[cxPageControl1.ActivePageIndex].PageIndex :=
Tabs.ActiveDragTabObject.DropTabIndex;
end;
end;
procedure TForm1.ChromeTabs1ButtonCloseTabClick(Sender: TObject;
ATab: TChromeTab; var Close: Boolean);
begin
Log('ButtonCloseTabClickEvent', 'TabIndex' + IntToStr(ATab.Index));
// Log('Active page tab index', IntToStr(cxPageControl1.ActivePageIndex));
// Log('Active page tab count', IntToStr(cxPageControl1.PageCount));
// free closed page
cxPageControl1.Pages[ATab.Index].Free;
// set active page index to new page
// cxPageControl1.ActivePageIndex := ChromeTabs1.ActiveTabIndex - 1;
end;
procedure TForm1.FormCreate(Sender: TObject);
var
page: Integer;
begin
for page := 0 to cxPageControl1.PageCount - 1 do
begin
cxPageControl1.Pages[page].TabVisible := false;
end;
cxPageControl1.ActivePageIndex := -1;
end;
procedure TForm1.Log(aTitle, aContent: string);
begin
Memo1.Lines.Add(aTitle);
Memo1.Lines.Add(aContent);
Memo1.Lines.Add('');
end;
procedure TForm1.ProcessDroppedTab(Sender: TObject; X, Y: Integer;
DragTabObject: IDragTabObject; Cancelled: Boolean;
var TabDropOptions: TTabDropOptions);
var
WinX, WinY: Integer;
NewForm: TForm1;
tabSheet: TcxTabSheet;
begin
if (not Cancelled) and (DragTabObject.SourceControl <>
DragTabObject.DockControl) and (DragTabObject.DockControl = nil) then
begin
// find the drop position
WinX := MOuse.CursorPos.X - DragTabObject.DragCursorOffset.X -
((Width - ClientWidth) div 2);
WinY := MOuse.CursorPos.Y - DragTabObject.DragCursorOffset.Y -
(Height - ClientHeight) + ((Width - ClientWidth) div 2);
// create new form
{$region 'Create New Form'}
NewForm := TForm1.Create(Application);
NewForm.Position := poDesigned;
NewForm.Left := WinX;
NewForm.Top := WinY;
SetAppID(NewForm.Handle, 'test1');
tabSheet := cxPageControl1.ActivePage;
tabSheet.PageControl := NewForm.cxPageControl1;
NewForm.AddTab(NewForm.ChromeTabs1, tabSheet.Caption, -1);
NewForm.Show;
{$endregion}
// Remove the original tab
TabDropOptions := [tdDeleteDraggedTab];
// free closed page
// cxPageControl1.Pages[cxPageControl1.ActivePageIndex].Free;
end;
end;
procedure TForm1.ChromeTabs1TabDragDrop(Sender: TObject; X, Y: Integer;
DragTabObject: IDragTabObject; Cancelled: Boolean;
var TabDropOptions: TTabDropOptions);
begin
// Log('TabDragDropEvent', '[TabIndex: ' + IntToStr((Sender as TChromeTab).Index) + ']');
ProcessDroppedTab(Sender, X, Y, DragTabObject, Cancelled, TabDropOptions);
end;
// taskbar icon application
// ------------------------------------------------------------------------------
function SHGetPropertyStoreForWindow(hwnd: hwnd; const riid: TGUID;
out ppv: IPropertyStore): HRESULT; stdcall; external 'shell32.dll';
procedure TForm1.ChromeTabs1TabDragDropped(Sender: TObject; DragTabObject:
IDragTabObject; NewTab: TChromeTab);
var pageControl : TcxPageControl;
begin
Log('TabDragDroppedEvent', '[NewIndex: ' + IntToStr(newtab.Index) + ']');
end;
procedure TForm1.ChromeTabs1TabDragStart(Sender: TObject; ATab: TChromeTab; var
Allow: Boolean);
begin
Log('TabDragStartEvent', '[TabIndex: '+ IntToStr(ATab.Index) + ']');
end;
function TForm1.GetAppID(AHandle: THandle): string;
var
hr: HRESULT;
pps: IPropertyStore;
v: TPropVariant;
begin
hr := SHGetPropertyStoreForWindow(AHandle, IID_IPropertyStore, pps);
if Succeeded(hr) then
begin
pps.GetValue(PKEY_AppUserModel_ID, v);
Result := v.bstrVal;
end
else
Result := '';
end;
function TForm1.SetAppID(AHandle: THandle; const AAppID: String): Boolean;
var
hr: HRESULT;
pps: IPropertyStore;
v: TPropVariant;
begin
hr := SHGetPropertyStoreForWindow(AHandle, IID_IPropertyStore, pps);
if Succeeded(hr) then
begin
v.vt := VT_BSTR;
v.bstrVal := SysAllocString(PChar(AAppID));
Result := pps.SetValue(PKEY_AppUserModel_ID, v) = S_OK;
end
else
Result := false;
end;
procedure TForm1.CreateParams(var Params: TCreateParams);
begin
inherited;
Params.ExStyle := Params.ExStyle or WS_EX_APPWINDOW;
Params.WndParent := HWND_DESKTOP
end;
// ------------------------------------------------------------------------------
end.