forked from 7plus/7plus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ExplorerTabs.ahk
924 lines (883 loc) · 32.8 KB
/
ExplorerTabs.ahk
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
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
#if Settings.Explorer.Tabs.UseTabs && WinActive("ahk_group ExplorerGroup")
^t::CreateTab(WinActive("ahk_group ExplorerGroup")+0)
#if
#if Settings.Explorer.Tabs.UseTabs && IsTabbedWindow(WinExist("A")+0)
^Tab Up::ExplorerWindows.GetItemWithValue("hwnd", WinExist("A")+0).TabContainer.CycleTabs(1)
^+Tab Up::ExplorerWindows.GetItemWithValue("hwnd", WinExist("A")+0).TabContainer.CycleTabs(-1)
^w::CloseActiveTab()
#if
#if Settings.Explorer.Tabs.UseTabs && IsMouseOverTabButton()
LButton::MouseActivateTab()
MButton::MouseCloseTab()
#if
CloseActiveTab()
{
global ExplorerWindows
Debug("close active tab")
TabContainer := ExplorerWindows.GetItemWithValue("hwnd", WinExist("A")+0).TabContainer
tab := TabContainer.tabs.GetItemWithValue("hwnd", WinExist("A")+0)
if(tab)
{
Debug("tab found", "active tab " tab.path WinExist("A")+0)
TabContainer.CloseTab(tab)
}
}
IsTabbedWindow(hwnd)
{
global ExplorerWindows
if(IsObject(ExplorerWindows) && IsObject(ExplorerWindow := ExplorerWindows.GetItemWithValue("hwnd", hwnd+0)) && IsObject(ExplorerWindow.TabContainer))
return hwnd+0
return false
}
IsMouseOverTabButton(ByRef TabContainer="")
{
global ExplorerWindows
CoordMode, Mouse, Screen
MouseGetPos,x,y,window
if(window && WinExist("TabWindow ahk_class AutoHotkeyGUI ahk_id " window))
{
WinGetPos,WinX,WinY,,,ahk_id %window%
;Tab Coords are relative
x-=WinX
y-=WinY
; Debug("correct window x" x "y" y )
TabContainer:=ExplorerWindows.TabContainerList.GetItemWithValue("TabWindow", window+0)
if(TabContainer)
{
; Debug("tab container")
Loop % TabContainer.tabs.MaxIndex()
{
if(IsInArea(x,y,TabContainer.tabs[A_Index].x,TabContainer.tabs[A_Index].y,TabContainer.tabs[A_Index].width,TabContainer.tabs[A_Index].height))
return A_Index
}
; Debug("not found")
}
}
; CoordMode, Mouse, Screen
return false
}
MouseActivateTab()
{
index := IsMouseOverTabButton(TabContainer)
Debug("mouse over tab button " index)
if(index && TabContainer && TabContainer.tabs[index].hwnd != TabContainer.active)
TabContainer.ActivateTab(index)
}
MouseCloseTab()
{
index := IsMouseOverTabButton(TabContainer)
if(index)
TabContainer.CloseTab(TabContainer.tabs[index])
return index > 0
}
CalculateTabText(tab)
{
global ExplorerWindows
Debug("calculate tab text for " tab.hwnd+0)
TabContainer := ExplorerWindows.GetItemWithValue("hwnd", tab.hwnd+0).TabContainer
WinGetPos x,y,w,h,% "ahk_id " TabContainer.TabWindow
; Create a gdi bitmap with width and height of what we are going to draw into it. This is the entire drawing area for everything
hbm := CreateDIBSection(w, h)
; Get a device context compatible with the screen
hdc := CreateCompatibleDC()
; Select the bitmap into the device context
obm := SelectObject(hdc, hbm)
; Get a pointer to the graphics of the bitmap, for use with drawing functions
G := Gdip_GraphicsFromHDC(hdc)
Font := ExplorerWindows.TabContainerList.Font
FontSize:=ExplorerWindows.TabContainerList.FontSize
;Measure the spaces
RectF:=Gdip_TextToGraphics(G, tab.DisplayName, " s" FontSize " r4", Font,"","",1)
StringSplit, RectF, RectF, |
DrawText := tab.DisplayName
drawcharcount := strlen(tab.DisplayName)
Debug(ExploreObj(tab))
while(RectF3 > (tab.width-2*ExplorerWindows.TabContainerList.hPadding))
{
oldcount := drawcharcount
drawcharcount := max(min(oldcount-1,floor(strlen(tab.DisplayName) * (Tab.Width -2*ExplorerWindows.TabContainerList.hPadding)/ RectF3)),0)
if(drawcharcount = 0)
{
Debug("clear drawtext")
drawtext := ""
break
}
drawtext := SubStr(tab.DisplayName,1, drawcharcount) "..."
RectF:=Gdip_TextToGraphics(G, drawtext, " s" FontSize " r4", Font,"","",1)
StringSplit, RectF, RectF, |
}
tab.DrawText := drawtext
Debug("set drawtext to " drawtext)
; Select the object back into the hdc
SelectObject(hdc, obm)
; Now the bitmap may be deleted
DeleteObject(hbm)
; Also the device context related to the bitmap may be deleted
DeleteDC(hdc)
; The graphics may now be deleted
Gdip_DeleteGraphics(G)
}
;Called when a tab is activated
; TabEvent:
; Debug("activate tab " TabControl ", previous exp window is " hwnd)
; NoTabUpdate:=true
; OldTab:=TabControl
; Gui, %TabNum%:Submit
; if(TabClose)
; {
; TabClose:=false
; hwnd:=TabContainerList.Active
; class:=WinGetClass("ahk_id " hwnd)
; TabContainer:=TabContainerList.ContainsHWND(TabContainerList.active)
; CloseTab(TabContainer.tabs[TabControl],TabContainer)
; Debug("current tab: " class)
; WinActivate ahk_id %hwnd%
; }
; else
; ActivateTab(TabControl)
; NoTabUpdate:=false
; UpdateTabs()
; return
CloseAllInactiveTabs()
{
global ExplorerWindows
len := ExplorerWindows.TabContainerList.MaxIndex()
loop %len% ;Fixed length for delete loop
ExplorerWindows.TabContainerList[1].CloseInactiveTabs()
}
/*
TabContainerList_indexOf(TabContainerList,TabContainer)
{
Loop % TabContainerList.MaxIndex()
{
tc:=TabContainerList[A_Index]
if(tc.ContainsHWND(TabContainer.active))
return A_Index
}
}
*/
DrawTabWindow:
ExplorerWindows.GetItemWithValue("hwnd", WinExist("A")+0).DrawTabWindow()
return
Class CTabContainer
{
__New(ExplorerWindow)
{
global ExplorerWindows
this.Tabs := Array()
this.x := 0
this.y := 0
this.w := 0
this.h := 0
this.state := 0
this.Active := ExplorerWindow.hwnd
ExplorerWindows.TabContainerList.Insert(this)
this.Add(ExplorerWindow)
this.CreateTabWindow()
}
__Delete()
{
Gui % this.TabNum ":Destroy"
}
CreateTabWindow()
{
global ExplorerWindows
;Critical
Debug("Create tab window")
this.TabNum:=GetFreeGUINum(10)
Gui, % this.TabNum ":+LastFound +ToolWindow -Border -Resize -Caption +E0x80000"
this.TabWindow := WinExist()+0
AttachToolWindow(this.Active, this.TabNum, false)
TabNum := this.TabNum
Gui %TabNum%:Show, NA, TabWindow
this.UpdatePosition()
this.UpdateTabs()
Return
}
Add(ExplorerWindow,position="", Activate = 0)
{
global ExplorerWindows
if(!ExplorerWindow.DisplayName)
ExplorerWindow.DisplayName := Navigation.GetDisplayName(ExplorerWindow.hwnd)
tab := Object("hwnd",ExplorerWindow.hwnd, "DisplayName", ExplorerWindow.DisplayName)
tab.y := ExplorerWindows.TabContainerList.InActiveHeightDifference
tab.height := ExplorerWindows.TabContainerList.height - ExplorerWindows.TabContainerList.InActiveHeightDifference
if(position="")
{
this.tabs.Insert(tab)
this.CalculateHorizontalTabPositions(this.tabs.MaxIndex())
this.CalculateVerticalTabPosition(this.tabs.MaxIndex())
}
else
{
this.tabs.insert(position,tab)
this.CalculateHorizontalTabPositions(position)
this.CalculateVerticalTabPosition(position)
}
ExplorerWindow.TabContainer := this
if(this.tabs.MaxIndex() > 1)
{
if(Activate)
this.ActivateTab(position = "" ? this.Tabs.MaxIndex() : position)
else
{
;To hide the old tab without showing the hide anim, it is moved outside of the screen first
WinMove, % "ahk_id " ExplorerWindow.hwnd,,-10000,-10000
WinHide, % "ahk_id " ExplorerWindow.hwnd
}
}
; CalculateTabText(tab)
this.DrawTabWindow()
}
CalculateVerticalTabPosition(index)
{
global ExplorerWindows
tab := this.tabs[index]
if(tab)
{
if(tab.hwnd = this.Active)
{
tab.y := 0
tab.height := ExplorerWindows.TabContainerList.height
}
else
{
tab.y := ExplorerWindows.TabContainerList.InActiveHeightDifference
tab.height := ExplorerWindows.TabContainerlist.height - ExplorerWindows.TabContainerList.InActiveHeightDifference
}
}
}
ActivateTab(pos)
{
global ExplorerWindows
; Debug("ActivateTab(" pos ")")
SetWinDelay, -1
hwnd := this.tabs[pos].hwnd + 0
;DisableMinimizeAnim(1)
ExplorerWindows.TabContainerList.TabActivationInProgress := true
OldTab := this.active
;To hide the old tab without showing the hide anim, it is moved outside of the screen first
WinMove,ahk_id %OldTab%,, -10000, -10000
DeAttachToolWindow(this.TabNum)
WinHide,ahk_id %OldTab%
DetectHiddenWindows, On
if(this.w != 0)
{
if(this.state = 1)
WinSetPlacement(hwnd, this.x, this.y, this.w, this.h, 3)
else
WinSetPlacement(hwnd, this.x, this.y, this.w, this.h, 1)
;WinMove ahk_id %hwnd%,,%x%,%y%,%w%,%h%
}
/*
if(this.state = 1)
WinMaximize ahk_id %hwnd%
else if(this.state = 0)
WinRestore ahk_id %hwnd%
*/
WinShow, ahk_id %hwnd%
WinActivate, ahk_id %hwnd%
this.Active := hwnd
AttachToolWindow(hwnd, this.TabNum, false)
;DisableMinimizeAnim(0)
this.CalculateVerticalTabPosition(pos)
this.CalculateVerticalTabPosition(this.tabs.FindKeyWithValue("hwnd", OldTab + 0))
this.UpdatePosition()
this.UpdateTabs()
Gui, % this.TabNum ":Show", NA
Sleep 10 ;To allow any message hooks to be executed
ExplorerWindows.TabContainerList.TabActivationInProgress := false
}
/*
* Cycles through tabs in order indicated by dir
*/
CycleTabs(dir)
{
if(this.tabs.MaxIndex()>1)
{
pos:=this.tabs.FindKeyWithValue("hwnd", this.active+0)
pos+=dir
if(pos<1)
pos+=this.tabs.MaxIndex()
Else if(pos>this.tabs.MaxIndex())
pos-=this.tabs.MaxIndex()
Debug("activate tab " pos)
this.ActivateTab(pos)
}
Else
Notify("Explorer Tabs Error!", "Tab container is too small!", 5, NotifyIcons.Error)
}
/*
* Recreates Tabs
*/
UpdateTabs()
{
global ExplorerWindows
Debug("updatetabs")
; global
; local TabContainer, hwnd,tabhwnd,folder,tabs
; WasCritical := A_IsCritical
; Critical
; if(!SuppressTabEvents && !NoTabUpdate)
; {
; hwnd:=WinActive("ahk_group ExplorerGroup")
; TabContainer:=TabContainerList.ContainsHWND(hwnd)
; if(hwnd && TabContainer)
; {
Loop % ExplorerWindows.MaxIndex()
{
if(ExplorerWindows[A_Index].TabContainer != this)
continue
DisplayName := ExplorerWindows[A_Index].DisplayName
Tab := ExplorerWindows[A_Index].TabContainer.tabs.GetItemWithValue("hwnd", ExplorerWindows[A_Index].hwnd+0)
if(Tab && DisplayName != Tab.DisplayName)
{
Tab.DisplayName := DisplayName
CalculateTabText(Tab)
}
}
this.CalculateHorizontalTabPositions()
; }
; SuppressTabEvents:=false
this.DrawTabWindow()
; }
; if(!WasCritical)
; Critical, Off
return
/*
SuppressTabEvents:=true
*/
}
UpdatePosition()
{
global ExplorerWindows
Debug("updateposition")
; global SuppressTabEvents, TabContainerList, TabControl, NoTabUpdate
; static gid=0 ;fid & gid are function id and global id. I use them to see if the function interupted itself.
SetWinDelay -1
/*
if(SuppressTabEvents)
{
Debug("update suppressed")
return
}
*/
; if(NoTabUpdate)
; return
; fid:=gid+=1
;SuppressTabEvents:=true
; hwnd:=WinActive("ahk_group ExplorerGroup")
; TabContainer:=TabContainerList.ContainsHWND(hwnd)
; class:=WinGetClass("A")
; if( hwnd && TabContainer)
; {
;Get restored-state coordinates
WinGetPlacement(this.Active,x,y,w,h)
;Update stored position so we can restore it if a tab is closed
WinGet, state, minmax, % "ahk_id " this.Active
changed := this.x != x || this.y != y || this.w != w || this.h != h || this.state != state
changedsize := this.w != w || this.h != h
if(changed)
{
Debug("update coords to x" x " y" y " w" w " h" h)
this.state := state
this.x := x
this.y := y
this.w := w
this.h := h
;Now get current coordinates for tab window placement
WinGetPos, x,y,width,h, % "ahk_id " this.Active
x+=24
y+=4
w := width - 135
;The Explorer in Windows 8 finally uses its window space more effectively. In return this means that there's no real space for the tabs anymore.
;For now they will be placed in the center of the titlebar. This increases the chance of not overlapping with other elements.
if(WinVer = WIN_8)
{
w -= 150
x := (x - 24) + (width / 2 - w / 2)
}
h:=ExplorerWindows.TabContainerList.height
Debug("move tabwindow x" x " y" y " w" w " h" h)
WinMove, % "ahk_id " this.TabWindow,,%x%,%y%,%w%,%h%
;Limit drawing rate to make resizing more smoother
if(changedsize)
SetTimer, DrawTabWindow, -20
; if (fid != gid) ;some newer instance of the function was running, so just return (function was interupted by itself). Without this, older instance will continue with old host window position and clients will jump to older location. This is not so visible with WinMove as it is very fast, but SetWindowPos shows this in full light.
; return
}
;Debug("updateposition() tab control: w" w)
;GuiControl, %TabNum%:Move, TabControl, w%w%
; WinGet, style, style, % "ahk_id " this.TabWindow
; if(!(style & 0x10000000)) ;WS_VISIBLE
; {
; Debug("show " this.TabNum)
; Gui % this.TabNum ": Show", NA
; }
;WinShow ahk_id %TabWindow%
; }
; else if (class && (WinExist("A")!=TabWindow || WinGet("minmax","ahk_id " TabContainerList.active)=-1))
; {
; WinGet, style, style, ahk_id %TabWindow%
; if(style & 0x10000000)
; {
; Debug("hide " class " id " TabWindow)
; WinHide ahk_id %TabWindow%
; ;DllCall("AnimateWindow","Ptr",TabWindow,UInt,0,UInt,0x00010000)
; }
; }
;SuppressTabEvents:=false
}
CloseInactiveTabs()
{
global ExplorerWindows
ExplorerWindows.TabContainerList.Delete(ExplorerWindows.TabContainerList.indexOf(this))
ExplorerWindows.TabContainerList.TabCloseInProgress := true
loop % this.tabs.MaxIndex()
{
hwnd := this.tabs[A_Index].hwnd+0
;Remove all references to the Tab Container so that its delete routine may be called and ExplorerDestroyed doesn't recurse
ExplorerWindows.GetItemWithValue("hwnd", hwnd).Remove("TabContainer")
if(hwnd!=this.active)
WinClose, ahk_id %hwnd%
}
Loop 100
{
if(!ExplorerWindows.TabContainerList.TabCloseInProgress)
return
Sleep 100
}
ExplorerWindows.TabContainerList.TabCloseInProgress := false
Debug("tab close event timeout")
}
CloseAllTabs()
{
global ExplorerWindows
; NoTabUpdate:=true
; SuppressTabEvents:=true
; Debug("close all tabs")
; TabContainerList.Print()
; index:=TabContainerList.indexOf(TabContainer)
ExplorerWindows.TabContainerList.Delete(ExplorerWindows.TabContainerList.indexOf(this))
; Denug("index " index)
; Debug("after deletion:")
; TabContainerList.Print()
ExplorerWindows.TabContainerList.TabCloseInProgress := true
loop % this.tabs.MaxIndex()
{
hwnd := this.tabs[A_Index].hwnd+0
;Remove all references to the Tab Container so that its delete routine may be called and ExplorerDestroyed doesn't recurse
ExplorerWindows.GetItemWithValue("hwnd", hwnd).Remove("TabContainer")
WinClose, ahk_id %hwnd%
}
Loop 100
{
if(!ExplorerWindows.TabContainerList.TabCloseInProgress)
return
Sleep 100
}
ExplorerWindows.TabContainerList.TabCloseInProgress := false
Debug("tab close event timeout")
; NoTabUpdate:=false
; SuppressTabEvents:=false
}
CalculateHorizontalTabPositions(start=1)
{
i:=start
if(start>1)
x:=this.tabs[start-1].x+this.tabs[start-1].width
else
x:=0
Loop
{
if(i>this.tabs.MaxIndex())
break
this.tabs[i].x:=x
x+=this.tabs[i].width
i++
}
}
DrawTabWindow()
{
global ExplorerWindows
WinGetPos x,y,w,h, % "ahk_id " this.TabWindow
Debug("draw tab window current size x" x " y" y " w" w " h" h)
count := this.tabs.MaxIndex()
desiredwidth := 0
loop % count
{
desiredwidth += ExplorerWindows.TabContainerList.TabWidth
totalpadding += 2*ExplorerWindows.TabContainerList.hPadding
}
if(desiredwidth + totalpadding > w)
{
scale := max((w-totalpadding),0)/desiredwidth
Loop % count
{
this.tabs[A_Index].width := floor(ExplorerWindows.TabContainerList.TabWidth * scale)
CalculateTabText(this.tabs[A_Index])
}
}
else
{
Loop % count
{
this.tabs[A_Index].width := ExplorerWindows.TabContainerList.TabWidth
CalculateTabText(this.tabs[A_Index])
}
}
this.CalculateHorizontalTabPositions()
; Create a gdi bitmap with width and height of what we are going to draw into it. This is the entire drawing area for everything
hbm := CreateDIBSection(w, h)
; Get a device context compatible with the screen
hdc := CreateCompatibleDC()
; Select the bitmap into the device context
obm := SelectObject(hdc, hbm)
; Get a pointer to the graphics of the bitmap, for use with drawing functions
G := Gdip_GraphicsFromHDC(hdc)
Font := ExplorerWindows.TabContainerList.Font
FontSize := ExplorerWindows.TabContainerList.FontSize
; Set the smoothing mode to antialias = 4 to make shapes appear smother (only used for vector drawing and filling)
Gdip_SetSmoothingMode(G, 4)
; Create brushes
pBrushActive := Gdip_BrushCreateSolid(0xFFFAFAFA)
;Create pen for border liens
pPenBorder := Gdip_CreatePen(0xFF808080, 1)
;Draw all tabs
Loop % this.tabs.MaxIndex()
{
tab := this.tabs[A_Index]
Gdip_SetSmoothingMode(G, 4)
; Draw background
if(tab.hwnd = this.active)
{
Debug("draw active tab x"tab.x " y" tab.y "w "tab.width " h"tab.height)
Gdip_FillRectangle(G, pBrushActive, tab.x, tab.y, tab.width, tab.height)
}
else
{
if(WinVer >= WIN_Vista && WinVer < WIN_8) ;Win 8 draws on the title bar, so the tabs must be opaque to avoid partial overdrawing
pBrushGradient := Gdip_CreateLineBrushFromRect(0,0, tab.width, tab.height, 0xFFF8F8F8, 0x22222222)
else
pBrushGradient := Gdip_CreateLineBrushFromRect(0,0, tab.width, tab.height, 0xFFF8F8F8, 0xFFAAAAAA)
Gdip_FillRectangle(G, pBrushGradient, tab.x, tab.y, tab.width, tab.height)
Gdip_DeleteBrush(pBrushGradient)
Debug("draw inactive tab x"tab.x " y" tab.y "w "tab.width " h"tab.height)
}
Gdip_SetSmoothingMode(G, 1)
Gdip_DrawLine(G, pPenBorder, tab.x, tab.y, tab.x+tab.width, tab.y)
Gdip_DrawLine(G, pPenBorder, tab.x, tab.y, tab.x, tab.y+tab.height)
Gdip_DrawLine(G, pPenBorder, tab.x+tab.width, tab.y, tab.x+tab.width, tab.y+tab.height)
Gdip_SetSmoothingMode(G, 4)
Gdip_TextToGraphics(G, tab.drawtext, "x" (tab.x+ExplorerWindows.TabContainerList.hPadding) " y" ExplorerWindows.TabContainerList.vPadding " cff000000 r5 Centre s" FontSize, Font,tab.width - 2*ExplorerWindows.TabContainerList.hPadding,tab.height)
}
UpdateLayeredWindow(this.TabWindow, hdc, x, y, w, h)
; Delete the brush as it is no longer needed and wastes memory
Gdip_DeleteBrush(pBrushActive)
Gdip_DeletePen(pPenBorder)
; Select the object back into the hdc
SelectObject(hdc, obm)
; Now the bitmap may be deleted
DeleteObject(hbm)
; Also the device context related to the bitmap may be deleted
DeleteDC(hdc)
; The graphics may now be deleted
Gdip_DeleteGraphics(G)
}
/*
* Closes the tab hwnd
*/
CloseTab(Tab)
{
; global TabContainerList,TabNum, NoTabUpdate
global ExplorerWindows
; DetectHiddenWindows, On
; NoTabUpdate:=true
; Folder:=Navigation.GetPath(hwnd)
; Debug("close " hwnd " " folder)
; TabContainerList.print()
; if(!TabContainer)
; TabContainer:=TabContainerList.ContainsHWND(hwnd)
; Debug("close tab " this.tabs.IndexOf(Tab))
Debug("currently active tab" this.tabs.FindKeyWithValue("hwnd", this.active+0))
if(Tab.hwnd=this.active)
{
if(Settings.Explorer.Tabs.OnTabClose=1)
this.CycleTabs(-1)
else if(Settings.Explorer.Tabs.OnTabClose=2)
this.CycleTabs(1)
}
Debug("currently active tab after cycling" this.tabs.FindKeyWithValue("hwnd", this.active+0))
if(this.tabs.MaxIndex()=2)
{
;Remove all references to the Tab Container so that its delete routine may be called
ExplorerWindows.TabContainerList.Delete(ExplorerWindows.TabContainerList.indexOf(this))
Loop % this.tabs.MaxIndex()
ExplorerWindows.GetItemWithValue("hwnd", this.tabs[A_Index].hwnd+0).Remove("TabContainer")
}
Else
{
this.tabs.Delete(this.tabs.IndexOf(Tab))
ExplorerWindows.GetItemWithValue("hwnd", Tab.hwnd+0).Remove("TabContainer")
}
WinMove, % "ahk_id " Tab.hwnd,,-10000,-10000
ExplorerWindows.TabContainerList.TabCloseInProgress++
WinClose % "ahk_id " Tab.hwnd
; Debug("update closed")
; NoTabUpdate:=false
this.UpdateTabs()
Loop 100
{
if(!ExplorerWindows.TabContainerList.TabCloseInProgress)
return
Sleep 100
}
ExplorerWindows.TabContainerList.TabCloseInProgress := false
Debug("tab close event timeout")
}
;Called when a tab is closed manually (close button, alt+f4, ...)
TabClosed(hwnd)
{
global ExplorerWindows
Debug("tab closed manually " hwnd)
Tab := this.Tabs.GetItemWithValue("hwnd", hwnd)
if(!Tab)
return false
if(hwnd=this.active)
{
if(Settings.Explorer.Tabs.OnTabClose=1)
this.CycleTabs(-1)
else if(Settings.Explorer.Tabs.OnTabClose=2)
this.CycleTabs(1)
}
if(this.tabs.MaxIndex()=2)
{
;Remove all references to the Tab Container so that its delete routine may be called
ExplorerWindows.TabContainerList.Delete(ExplorerWindows.TabContainerList.indexOf(this))
Loop % this.tabs.MaxIndex()
ExplorerWindows.GetItemWithValue("hwnd", this.tabs[A_Index].hwnd+0).Remove("TabContainer")
}
Else
this.tabs.Delete(this.tabs.IndexOf(Tab))
this.UpdateTabs()
}
}
CreateTab(hwnd, path=-1,Activate=-1)
{
; global TabContainerList, TabContainerBase, SuppressTabEvents, TabNum, TabWindow,TabControl
global ExplorerWindows
if(!hwnd)
{
Notify("Explorer Tabs Error!", "CreateTab(): No active tab!", 5, NotifyIcons.Error)
Return
}
WasCritical := A_IsCritical
Critical
Activate := Activate = -1 ? Settings.Explorer.Tabs.ActivateTab : Activate
path := path = -1 ? Settings.Explorer.Tabs.TabStartupPath : path
ExplorerWindow := ExplorerWindows.GetItemWithValue("hwnd", hwnd+0)
if(!ExplorerWindow)
{
Notify("Explorer Tabs Error!", "Error creating tab: Explorer window not registered!", 5, NotifyIcons.Error)
return false
}
if(path = "")
path := ExplorerWindow.Path
if(!TabContainer:=ExplorerWindow.TabContainer) ;Create new Tab Container if it doesn't exist yet
{
Debug("add new tab container")
TabContainer := new CTabContainer(ExplorerWindow)
}
Prev_DetectHiddenWindows := A_DetectHiddenWindows
DetectHiddenWindows, On
DisableMinimizeAnim(1)
Run, explorer "%path%"
WinWaitNotActive ahk_id %hwnd%
WinWaitNotActive % "ahk_id " TabContainer.TabWindow
WinWaitNotActive ahk_id %hwnd%
Timeout := 10000
start := A_TickCount
Loop ;Make sure new window is really active
{
Sleep 10
hwndnew := WinActive("ahk_group ExplorerGroup") +0
if(hwndnew)
{
ExplorerWindows.TabContainerList.TabCreationInProgress := true ;Set it to avoid ExplorerActivated function
Debug("1st loop " hwndnew " " hwnd)
If (hwndnew <> hwnd )
Break
}
if(A_TickCount - start > Timeout)
{
gosub CreateTab_Cleanup
return 0
}
}
start := A_TickCount
Loop ;Wait until new window is visible
{
Sleep 10
WinGet,visible,style, ahk_id %hwndnew%
if(visible & 0x10000000)
break
if(A_TickCount - start > Timeout)
{
gosub CreateTab_Cleanup
return 0
}
}
if(!Activate)
{
start := A_TickCount
Loop ;and hide it until it is invisible again
{
Sleep 10
WinGet,visible,style, ahk_id %hwndnew%
WinGetPos,x,y,w,h,ahk_id %hwndnew%
Debug("2nd loop x" x " y" y " w" w " h" h)
if(visible & 0x10000000) ;WS_VISIBLE
{
Debug("hide style " visible " title " title)
WinHide ahk_id %hwndnew%
;DllCall("AnimateWindow","Ptr",hwndnew,UInt,0,UInt,0x00010000)
}
Else
break
if(A_TickCount - start > Timeout)
{
gosub CreateTab_Cleanup
return 0
}
}
Debug("hide tab " hwndnew)
}
WinGetPlacement(hwnd,x,y,w,h,state)
WinSetPlacement(hwndnew,x,y,w,h,state)
if(!Activate)
WinHide ahk_id %hwndnew%
;DllCall("AnimateWindow","Ptr",hwndnew,UInt,0,UInt,0x00010000) ;Hide again because WinSetPlacement unhides it, but is required for max/restore state
; msgbox h%hwndnew%
;WinMove ahk_id %hwndnew%,,%x%,%y%,%w%,%h%
;if(state = 1)
; WinMaximize ahk_id %hwndnew%
if(!Activate)
WinActivate ahk_id %hwnd%
Else
{
DeAttachToolWindow(TabContainer.TabNum)
; TabContainerList.active:=hwndnew
TabContainer.active:=hwndnew
WinHide ahk_id %hwnd%
;DllCall("AnimateWindow","Ptr",hwnd,UInt,0,UInt,0x00010000)
; Debug("hide old tab")
}
RegisterExplorerWindows()
TabContainer.CalculateVerticalTabPosition(TabContainer.tabs.FindKeyWithValue("hwnd", hwnd+0))
if(Settings.Explorer.Tabs.NewTabPosition = 1)
TabContainer.add(ExplorerWindows.GetItemWithValue("hwnd", hwndnew+0),TabContainer.tabs.FindKeyWithValue("hwnd", hwnd+0) + 1,1) ;Add new tab right to the current tab
else if(Settings.Explorer.Tabs.NewTabPosition = 2)
TabContainer.add(ExplorerWindows.GetItemWithValue("hwnd", hwndnew+0),"",1) ;Add new tab to end of list
; TabContainer.CalculateVerticalTabPosition(TabContainer.tabs.FindKeyWithValue("hwnd", hwndnew))
if(Activate)
AttachToolWindow(TabContainer.Active, TabContainer.TabNum, false)
TabContainer.UpdateTabs()
TabContainer.UpdatePosition()
Gui, % TabContainer.TabNum ":Show", NA
; this.DrawTabWindow()
; GuiControl, %TabNum%:MoveDraw, TabControl
CreateTab_Cleanup:
DetectHiddenWindows, %Prev_DetectHiddenWindows%
DisableMinimizeAnim(0)
if(!WasCritical)
Critical, Off
ExplorerWindows.TabContainerList.TabCreationInProgress := false
return
}
; Class TabContainerList
; {
; __New()
; {
; this := Array()
; return this
; }
; CloseAllInActiveTabs()
; {
; }
; }
;Slide Window array constructor with some additional functions
; TabContainerList(p1="N", p2="N", p3="N", p4="N", p5="N", p6="N"){
; static TabContainerList
; If !TabContainerListBase
; TabContainerListBase := Object("len", "Array_Length", "indexOf", "Array_indexOf", "join", "Array_Join"
; , "append", "Array_Append", "insert", "Array_Insert", "delete", "Array_Delete"
; , "sort", "Array_sort", "reverse", "Array_Reverse", "unique", "Array_Unique"
; , "extend", "Array_Extend", "copy", "Array_Copy", "pop", "Array_Pop", "ContainsHWND", "TabContainerList_ContainsHWND"
; , "CloseAllInactiveTabs", "TabContainerList_CloseAllInactiveTabs", "Print","TabContainerList_Print"
; , "active", 0)
; TabContainerList := Object("base", TabContainerListBase)
; While (_:=p%A_Index%)!="N" && A_Index<=6
; TabContainerList[A_Index] := _
; Return TabContainerList
; }
; TabContainer_ContainsHWND(TabContainer,hwnd)
; {
;;DecToHex(hwnd)
; Loop % TabContainer.tabs.MaxIndex()
; {
; if(TabContainer.tabs[A_Index].hwnd = hwnd)
; return A_Index
; }
; return 0
; }
; TabContainer_Print(TabContainer)
; {
; active:=TabContainer.active
; x:=TabContainer.x
; y:=TabContainer.y
; w:=TabContainer.w
; h:=TabContainer.h
; state:=TabContainer.state
; Debug("Active: " active)
; Debug("state: " state)
; Debug("x: " x)
; Debug("y: " y)
; Debug("w: " w)
; Debug("h: " h)
; Loop % TabContainer.tabs.MaxIndex()
; {
; path:=Navigation.GetPath(TabContainer.tabs[A_Index].hwnd)
; hwnd:=TabContainer.tabs[A_Index].hwnd
; Debug(A_Tab A_Index " " hwnd ": " path)
; }
; }
; TabContainerList_ContainsHWND(TabContainerList,hwnd)
; {
;;DecToHex(hwnd)
;;Debug("TabContainerList_ContainsHWND(" hwnd ")")
; Loop % TabContainerList.MaxIndex()
; {
; TabContainer:=TabContainerList[A_Index]
; if(TabContainer.ContainsHWND(hwnd))
; {
; return TabContainer
; }
; }
; return false
; }
; TabContainerList_Print(TabContainerList)
; {
; Debug("--------------------------------------------")
; active:=TabContainerList.active
; Debug("Active: " active)
; count:=TabContainerList.MaxIndex()
; Debug("tab container count: " count)
; loop % TabContainerList.MaxIndex()
; {
; count:=TabContainerList[A_Index].tabs.MaxIndex()
; Debug(A_Index ": " count " entries")
; TabContainerList[A_Index].Print()
; }
; Debug("--------------------------------------------")
; }
; #t::ExploreObj(ExplorerWindows)