-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtray.cpp
9122 lines (7637 loc) · 268 KB
/
tray.cpp
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
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "cocreateinstancehook.h"
#include "cabinet.h"
#include <wtsapi32.h> // for NOTIFY_FOR_THIS_SESSION
//#include <winsta.h> // for disconnect and reconnect messages from terminal server
//#include "mmsysp.h"
#include "rcids.h"
#include "dlg.h"
#include <atlstuff.h>
//#include <shlapip.h>
#include "trayclok.h"
//#include <help.h> // help ids
//#include <desktray.h>
#include "util.h"
#include "tray.h"
#if defined(FE_IME)
#include <immp.h>
#endif
#include <regstr.h>
#include "bandsite.h"
#include "startmnu.h"
#include "uemapp.h"
//#include <uxthemep.h>
#define NO_NOTIFYSUBCLASSWNDPROC
#include "cwndproc.h"
#include "desktop2.h"
#include "mixer.h"
#include "strsafe.h"
#include "port32.h"
#include "shundoc.h"
#include "vssym32.h"
#include <CommCtrl.h>
#include "startids.h"
#include "debug.h"
#include <dwmapi.h>
#define DM_FOCUS 0 // focus
#define DM_SHUTDOWN TF_TRAY // shutdown
#define DM_UEMTRACE TF_TRAY // timer service, other UEM stuff
#define DM_MISC 0 // miscellany
const GUID CLSID_MSUTBDeskBand = { 0x540d8a8b, 0x1c3f, 0x4e32, 0x81, 0x32, 0x53, 0x0f, 0x6a, 0x50, 0x20, 0x90 };
// From Desktop2\proglist.cpp
HRESULT AddMenuItemsCacheTask(IShellTaskScheduler* pSystemScheduler, BOOL fKeepCacheWhenFinished);
// import the WIN31 Compatibility HACKs from the shell32.dll
//STDAPI_(void) CheckWinIniForAssocs(void);
//
//// hooks to Shell32.dll
//STDAPI CheckDiskSpace();
//STDAPI CheckStagingArea();
// startmnu.cpp
void HandleFirstTime();
HWND v_hwndDesktop = NULL;
HWND v_hwndTray = NULL;
HWND v_hwndStartPane = NULL;
BOOL g_fDesktopRaised = FALSE;
BOOL g_fInSizeMove = FALSE;
UINT _uMsgEnableUserTrackedBalloonTips = 0;
void ClearRecentDocumentsAndMRUStuff(BOOL fBroadcastChange);
void DoTaskBarProperties(HWND hwnd, DWORD dwFlags);
void ClassFactory_Start();
void ClassFactory_Stop();
void SetupMergedFolderKeys(LPCTSTR clsid);
void ComServer_Stop(LPCTSTR clsid);
//
// Settings UI entry point types.
//
typedef void (WINAPI* PTRAYPROPSHEETCALLBACK)(DWORD nStartPage);
typedef void (WINAPI* PSETTINGSUIENTRY)(PTRAYPROPSHEETCALLBACK);
// Shell perf automation
extern DWORD g_dwShellStartTime;
extern DWORD g_dwShellStopTime;
extern DWORD g_dwStopWatchMode;
CTray c_tray;
// from explorer\desktop2
STDAPI DesktopV2_Create(
IMenuPopup** ppmp, IMenuBand** ppmb, void** ppvStartPane);
STDAPI DesktopV2_Build(void* pvStartPane);
// dyna-res change for multi-config hot/warm-doc
void HandleDisplayChange(int x, int y, BOOL fCritical);
DWORD GetMinDisplayRes(void);
// timer IDs
#define IDT_AUTOHIDE 2
#define IDT_AUTOUNHIDE 3
#ifdef DELAYWININICHANGE
#define IDT_DELAYWININICHANGE 5
#endif
#define IDT_DESKTOP 6
#define IDT_PROGRAMS IDM_PROGRAMS
#define IDT_RECENT IDM_RECENT
#define IDT_REBUILDMENU 7
#define IDT_HANDLEDELAYBOOTSTUFF 8
#define IDT_REVERTPROGRAMS 9
#define IDT_REVERTRECENT 10
#define IDT_REVERTFAVORITES 11
#define IDT_STARTMENU 12
#define IDT_ENDUNHIDEONTRAYNOTIFY 13
#define IDT_SERVICE0 14
#define IDT_SERVICE1 15
#define IDT_SERVICELAST IDT_SERVICE1
#define IDT_SAVESETTINGS 17
#define IDT_ENABLEUNDO 18
#define IDT_STARTUPFAILED 19
#define IDT_CHECKDISKSPACE 21
#define IDT_STARTBUTTONBALLOON 22
#define IDT_CHANGENOTIFY 23
#define IDT_COFREEUNUSED 24
#define FADEINDELAY 100
#define BALLOONTIPDELAY 10000 // default balloon time copied from traynot.cpp
// INSTRUMENTATION WARNING: If you change anything here, make sure to update instrument.c
// we need to start at 500 because we're now sharing the hotkey handler
// with shortcuts.. they use an index array so they need to be 0 based
// NOTE, this constant is also in desktop.cpp, so that we can forward hotkeys from the desktop for
// NOTE, app compatibility.
#define GHID_FIRST 500
enum
{
GHID_RUN = GHID_FIRST,
GHID_MINIMIZEALL,
GHID_UNMINIMIZEALL,
GHID_HELP,
GHID_EXPLORER,
GHID_FINDFILES,
GHID_FINDCOMPUTER,
GHID_TASKTAB,
GHID_TASKSHIFTTAB,
GHID_SYSPROPERTIES,
GHID_DESKTOP,
GHID_TRAYNOTIFY,
GHID_MAX
};
const DWORD GlobalKeylist[] =
{
MAKELONG(TEXT('R'), MOD_WIN),
MAKELONG(TEXT('M'), MOD_WIN),
MAKELONG(TEXT('M'), MOD_SHIFT | MOD_WIN),
MAKELONG(VK_F1,MOD_WIN),
MAKELONG(TEXT('E'),MOD_WIN),
MAKELONG(TEXT('F'),MOD_WIN),
MAKELONG(TEXT('F'), MOD_CONTROL | MOD_WIN),
MAKELONG(VK_TAB, MOD_WIN),
MAKELONG(VK_TAB, MOD_WIN | MOD_SHIFT),
MAKELONG(VK_PAUSE,MOD_WIN),
MAKELONG(TEXT('D'),MOD_WIN),
MAKELONG(TEXT('B'),MOD_WIN),
};
CTray::CTray() : _fCanSizeMove(TRUE), _fIsLogoff(FALSE), _fIsDesktopConnected(TRUE)
{
}
void CTray::ClosePopupMenus()
{
if (_pmpStartMenu)
_pmpStartMenu->OnSelect(MPOS_FULLCANCEL);
if (_pmpStartPane)
_pmpStartPane->OnSelect(MPOS_FULLCANCEL);
}
BOOL Tray_StartPanelEnabled()
{
SHELLSTATE ss = { 0 };
SHGetSetSettings(&ss, SSF_STARTPANELON, FALSE);
return ss.fStartPanelOn;
}
//
// The StartButtonBalloonTip registry value can have one of these values:
//
// 0 (or nonexistent): User has never clicked the Start Button.
// 1: User has clicked the Start Button on a pre-Whistler system.
// 2: User has clicked the Start Button on a Whistler system.
//
// In case 0, we always want to show the balloon tip regardless of whether
// the user is running Classic or Personal.
//
// In case 1, we want to show the balloon tip if the user is using the
// Personal Start Menu, but not if using Classic (since he's already
// seen the Classic Start Menu). In the Classic case, upgrade the counter
// to 2 so the user won't be annoyed when they switch from Classic to
// Personal.
//
// In case 2, we don't want to show the balloon tip at all since the
// user has seen all we have to offer.
//
BOOL CTray::_ShouldWeShowTheStartButtonBalloon()
{
DWORD dwType;
DWORD dwData = 0;
DWORD cbSize = sizeof(DWORD);
SHGetValue(HKEY_CURRENT_USER, REGSTR_EXPLORER_ADVANCED,
TEXT("StartButtonBalloonTip"), &dwType, (BYTE*)&dwData, &cbSize);
if (Tray_StartPanelEnabled())
{
// Personal Start Menu is enabled, so show the balloon if the
// user has never logged on to a Whistler machine before.
return dwData < 2;
}
else
{
// Classic Start Menu is enabled.
switch (dwData)
{
case 0:
// User has never seen the Start Menu before, not even the
// classic one. So show the tip.
return TRUE;
case 1:
// User has already seen the Classic Start Menu, so don't
// prompt them again. Note that this means that they aren't
// prompted when they turn on the Personal Start Menu, but
// that's okay, because by the time they switch to Personal,
// they clearly have demonstrated that they know how the
// Start Button works and don't need a tip.
_DontShowTheStartButtonBalloonAnyMore();
return FALSE;
default:
// User has seen Whistler Start menu before, so don't show tip.
return FALSE;
}
}
}
//
// Set the value to 2 to indicate that the user has seen a Whistler
// Start Menu (either Classic or Personal).
//
void CTray::_DontShowTheStartButtonBalloonAnyMore()
{
DWORD dwData = 2;
SHSetValue(HKEY_CURRENT_USER, REGSTR_EXPLORER_ADVANCED,
TEXT("StartButtonBalloonTip"), REG_DWORD, (BYTE*)&dwData, sizeof(dwData));
}
void CTray::_DestroyStartButtonBalloon()
{
if (_hwndStartBalloon)
{
DestroyWindow(_hwndStartBalloon);
_hwndStartBalloon = NULL;
}
KillTimer(_hwnd, IDT_STARTBUTTONBALLOON);
}
void CTray::CreateStartButtonBalloon(UINT idsTitle, UINT idsMessage)
{
if (!_hwndStartBalloon)
{
_hwndStartBalloon = CreateWindow(TOOLTIPS_CLASS, NULL,
WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP | TTS_BALLOON,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
_hwnd, NULL, hinstCabinet,
NULL);
if (_hwndStartBalloon)
{
// set the version so we can have non buggy mouse event forwarding
SendMessage(_hwndStartBalloon, CCM_SETVERSION, COMCTL32_VERSION, 0);
SendMessage(_hwndStartBalloon, TTM_SETMAXTIPWIDTH, 0, (LPARAM)300);
// taskbar windows are themed under Taskbar subapp name
SendMessage(_hwndStartBalloon, TTM_SETWINDOWTHEME, 0, (LPARAM)c_wzTaskbarTheme);
// Tell the Start Menu that this is a special balloon tip
SetProp(_hwndStartBalloon, PROP_DV2_BALLOONTIP, DV2_BALLOONTIP_STARTBUTTON);
}
}
if (_hwndStartBalloon)
{
TCHAR szTip[MAX_PATH];
szTip[0] = TEXT('\0');
LoadString(hinstCabinet, idsMessage, szTip, ARRAYSIZE(szTip));
if (szTip[0])
{
RECT rc;
TOOLINFO ti = { 0 };
ti.cbSize = sizeof(ti);
ti.uFlags = TTF_IDISHWND | TTF_TRACK | TTF_TRANSPARENT;
ti.hwnd = _hwnd;
ti.uId = (UINT_PTR)_hwndStart;
//ti.lpszText = NULL;
SendMessage(_hwndStartBalloon, TTM_ADDTOOL, 0, (LPARAM)(LPTOOLINFO)&ti);
SendMessage(_hwndStartBalloon, TTM_TRACKACTIVATE, (WPARAM)FALSE, (LPARAM)0);
ti.lpszText = szTip;
SendMessage(_hwndStartBalloon, TTM_UPDATETIPTEXT, 0, (LPARAM)&ti);
LoadString(hinstCabinet, idsTitle, szTip, ARRAYSIZE(szTip));
if (szTip[0])
{
SendMessage(_hwndStartBalloon, TTM_SETTITLE, TTI_INFO, (LPARAM)szTip);
}
GetWindowRect(_hwndStart, &rc);
SendMessage(_hwndStartBalloon, TTM_TRACKPOSITION, 0, MAKELONG((rc.left + rc.right) / 2, rc.top));
SetWindowZorder(_hwndStartBalloon, HWND_TOPMOST);
SendMessage(_hwndStartBalloon, TTM_TRACKACTIVATE, (WPARAM)TRUE, (LPARAM)&ti);
SetTimer(_hwnd, IDT_STARTBUTTONBALLOON, BALLOONTIPDELAY, NULL);
}
}
}
void CTray::_ShowStartButtonToolTip()
{
if (!_ShouldWeShowTheStartButtonBalloon() || SHRestricted(REST_NOSMBALLOONTIP))
{
PostMessage(_hwnd, TM_SHOWTRAYBALLOON, TRUE, 0);
return;
}
if (Tray_StartPanelEnabled())
{
// In order to display the Start Menu, we need foreground activation
// so keyboard focus will work properly.
if (SetForegroundWindow(_hwnd))
{
// Inform the tray that start button is auto-popping, so the tray
// can hold off on showing balloons.
PostMessage(_hwnd, TM_SHOWTRAYBALLOON, FALSE, 0);
// This pushes the start button and causes the start menu to popup.
SendMessage(GetDlgItem(_hwnd, IDC_START), BM_SETSTATE, TRUE, 0);
// Once successfully done once, don't do it again.
_DontShowTheStartButtonBalloonAnyMore();
}
}
else
{
PostMessage(_hwnd, TM_SHOWTRAYBALLOON, TRUE, 0);
CreateStartButtonBalloon(IDS_STARTMENUBALLOON_TITLE, IDS_STARTMENUBALLOON_TIP);
}
}
BOOL CTray::_CreateClockWindow()
{
_hwndNotify = _trayNotify.TrayNotifyCreate(_hwnd, IDC_CLOCK, hinstCabinet);
SendMessage(_hwndNotify, TNM_UPDATEVERTICAL, 0, !STUCK_HORIZONTAL(_uStuckPlace));
return BOOLFROMPTR(_hwndNotify);
}
BOOL CTray::_InitTrayClass()
{
WNDCLASS wc = { 0 };
wc.lpszClassName = TEXT("Shell_TrayWnd");
wc.style = CS_DBLCLKS;
wc.lpfnWndProc = s_WndProc;
wc.hInstance = hinstCabinet;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1);
wc.cbWndExtra = sizeof(LONG_PTR);
return RegisterClass(&wc);
}
HFONT CTray::_CreateStartFont(HWND hwndTray)
{
HFONT hfontStart = NULL;
HTHEME hthemeStart = OpenThemeData(hwndTray, L"Button");
if (hthemeStart)
{
LOGFONT lf;
HDC hdc = GetDC(hwndTray);
if (SUCCEEDED(GetThemeFont(hthemeStart, hdc, BP_PUSHBUTTON, PBS_NORMAL, TMT_FONT, &lf)))
{
hfontStart = CreateFontIndirect(&lf);
}
ReleaseDC(hwndTray, hdc);
CloseThemeData(hthemeStart);
}
// Fallback to classic font if we can't get the theme font somehow
if (!hfontStart)
{
NONCLIENTMETRICS ncm;
ncm.cbSize = sizeof(ncm);
if (SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(ncm), &ncm, FALSE))
{
WORD wLang = GetUserDefaultLangID();
// Select normal weight font for chinese language.
if (PRIMARYLANGID(wLang) == LANG_CHINESE &&
((SUBLANGID(wLang) == SUBLANG_CHINESE_TRADITIONAL) ||
(SUBLANGID(wLang) == SUBLANG_CHINESE_SIMPLIFIED)))
ncm.lfCaptionFont.lfWeight = FW_NORMAL;
else
ncm.lfCaptionFont.lfWeight = FW_BOLD;
hfontStart = CreateFontIndirect(&ncm.lfCaptionFont);
}
}
return hfontStart;
}
// Set the stuck monitor for the tray window
void CTray::_SetStuckMonitor()
{
// use STICK_LEFT because most of the multi-monitors systems are set up
// side by side. use DEFAULTTONULL because we don't want to get the wrong one
// use the center point to call again in case we failed the first time.
_hmonStuck = MonitorFromRect(&_arStuckRects[STICK_LEFT],
MONITOR_DEFAULTTONULL);
if (!_hmonStuck)
{
POINT pt;
pt.x = (_arStuckRects[STICK_LEFT].left + _arStuckRects[STICK_LEFT].right) / 2;
pt.y = (_arStuckRects[STICK_LEFT].top + _arStuckRects[STICK_LEFT].bottom) / 2;
_hmonStuck = MonitorFromPoint(pt, MONITOR_DEFAULTTONEAREST);
}
_hmonOld = _hmonStuck;
}
DWORD _GetDefaultTVSDFlags()
{
DWORD dwFlags = TVSD_TOPMOST;
// if we are on a remote hydra session and if there is no previous saved value,
// do not display the clock.
if (SHGetMachineInfo(GMI_TSCLIENT))
{
dwFlags |= TVSD_HIDECLOCK;
}
return dwFlags;
}
void CTray::_GetSaveStateAndInitRects()
{
TVSDCOMPAT tvsd;
RECT rcDisplay;
DWORD dwTrayFlags;
UINT uStick;
SIZE size;
// first fill in the defaults
SetRect(&rcDisplay, 0, 0, g_cxPrimaryDisplay, g_cyPrimaryDisplay);
// size gets defaults
size.cx = _sizeStart.cx + 2 * (g_cxDlgFrame + g_cxBorder);
size.cy = _sizeStart.cy + 2 * (g_cyDlgFrame + g_cyBorder);
// sStuckWidths gets minimum
_sStuckWidths.cx = 2 * (g_cxDlgFrame + g_cxBorder);
_sStuckWidths.cy = _sizeStart.cy + 2 * (g_cyDlgFrame + g_cyBorder);
_uStuckPlace = STICK_BOTTOM;
dwTrayFlags = _GetDefaultTVSDFlags();
_uAutoHide = 0;
// now try to load saved vaules
// BUG : 231077
// Since Tasbar properties don't roam from NT5 to NT4, (NT4 -> NT5 yes)
// Allow roaming from NT4 to NT5 only for the first time the User logs
// on to NT5, so that future changes to NT5 are not lost when the user
// logs on to NT4 after customizing the taskbar properties on NT5.
DWORD cbData1 = sizeof(tvsd);
DWORD cbData2 = sizeof(tvsd);
if (Reg_GetStruct(g_hkeyExplorer, TEXT("StuckRectsXP2"), TEXT("Settings"),
&tvsd, &cbData1)
||
Reg_GetStruct(g_hkeyExplorer, TEXT("StuckRectsXP"), TEXT("Settings"),
&tvsd, &cbData2))
{
if (IS_CURRENT_TVSD(tvsd.t) && IsValidSTUCKPLACE(tvsd.t.uStuckPlace))
{
_GetDisplayRectFromRect(&rcDisplay, &tvsd.t.rcLastStuck,
MONITOR_DEFAULTTONEAREST);
size = tvsd.t.sStuckWidths;
_uStuckPlace = tvsd.t.uStuckPlace;
dwTrayFlags = tvsd.t.dwFlags;
}
else if (MAYBE_WIN95_TVSD(tvsd.w95) &&
IsValidSTUCKPLACE(tvsd.w95.uStuckPlace))
{
_uStuckPlace = tvsd.w95.uStuckPlace;
dwTrayFlags = tvsd.w95.dwFlags;
if (tvsd.w95.uAutoHide & AH_ON)
dwTrayFlags |= TVSD_AUTOHIDE;
switch (_uStuckPlace)
{
case STICK_LEFT:
size.cx = tvsd.w95.dxLeft;
break;
case STICK_RIGHT:
size.cx = tvsd.w95.dxRight;
break;
case STICK_BOTTOM:
size.cy = tvsd.w95.dyBottom;
break;
case STICK_TOP:
size.cy = tvsd.w95.dyTop;
break;
}
}
}
ASSERT(IsValidSTUCKPLACE(_uStuckPlace));
//
// use the size only if it is not bogus
//
if (_sStuckWidths.cx < size.cx)
_sStuckWidths.cx = size.cx;
if (_sStuckWidths.cy < size.cy)
_sStuckWidths.cy = size.cy;
//
// set the tray flags
//
_fAlwaysOnTop = BOOLIFY(dwTrayFlags & TVSD_TOPMOST);
_fSMSmallIcons = BOOLIFY(dwTrayFlags & TVSD_SMSMALLICONS);
_fHideClock = SHRestricted(REST_HIDECLOCK) || BOOLIFY(dwTrayFlags & TVSD_HIDECLOCK);
_uAutoHide = (dwTrayFlags & TVSD_AUTOHIDE) ? AH_ON | AH_HIDING : 0;
_RefreshSettings();
//
// initialize stuck rects
//
for (uStick = STICK_LEFT; uStick <= STICK_BOTTOM; uStick++)
_MakeStuckRect(&_arStuckRects[uStick], &rcDisplay, _sStuckWidths, uStick);
_UpdateVertical(_uStuckPlace);
// Determine which monitor the tray is on using its stuck rectangles
_SetStuckMonitor();
}
IBandSite* BandSite_CreateView();
HRESULT BandSite_SaveView(IUnknown* pbs);
LRESULT BandSite_OnMarshallBS(WPARAM wParam, LPARAM lParam);
void CTray::_SaveTrayStuff(void)
{
TVSD tvsd;
tvsd.dwSize = sizeof(tvsd);
tvsd.lSignature = TVSDSIG_CURRENT;
// position
CopyRect(&tvsd.rcLastStuck, &_arStuckRects[_uStuckPlace]);
tvsd.sStuckWidths = _sStuckWidths;
tvsd.uStuckPlace = _uStuckPlace;
tvsd.dwFlags = 0;
if (_fAlwaysOnTop) tvsd.dwFlags |= TVSD_TOPMOST;
if (_fSMSmallIcons) tvsd.dwFlags |= TVSD_SMSMALLICONS;
if (_fHideClock && !SHRestricted(REST_HIDECLOCK)) tvsd.dwFlags |= TVSD_HIDECLOCK;
if (_uAutoHide & AH_ON) tvsd.dwFlags |= TVSD_AUTOHIDE;
// Save in Stuck rects.
Reg_SetStruct(g_hkeyExplorer, TEXT("StuckRectsXP2"), TEXT("Settings"), &tvsd, sizeof(tvsd));
BandSite_SaveView(_ptbs);
return;
}
// align toolbar so that buttons are flush with client area
// and make toolbar's buttons to be MENU style
void CTray::_AlignStartButton()
{
HWND hwndStart = _hwndStart;
if (hwndStart)
{
TCHAR szStart[50];
LoadString(hinstCabinet, _hTheme ? IDS_START : IDS_STARTCLASSIC, szStart, ARRAYSIZE(szStart));
SetWindowText(_hwndStart, szStart);
RECT rcClient;
if (!_sizeStart.cx)
{
Button_GetIdealSize(hwndStart, &_sizeStart);
}
GetClientRect(_hwnd, &rcClient);
if (rcClient.right < _sizeStart.cx)
{
SetWindowText(_hwndStart, L"");
}
int cyStart = _sizeStart.cy;
if (_hwndTasks)
{
if (_hTheme)
{
cyStart = max(cyStart, SendMessage(_hwndTasks, TBC_BUTTONHEIGHT, 0, 0));
}
else
{
cyStart = SendMessage(_hwndTasks, TBC_BUTTONHEIGHT, 0, 0);
}
}
SetWindowPos(hwndStart, NULL, 0, 0, min(rcClient.right, _sizeStart.cx),
cyStart, SWP_NOZORDER | SWP_NOACTIVATE);
}
}
// Helper function for CDesktopHost so clicking twice on the Start Button
// treats the second click as a dismiss rather than a redisplay.
//
// The crazy state machine goes like this:
//
// SBSM_NORMAL - normal state, nothing exciting
//
// When user opens Start Pane, we become
//
// SBSM_SPACTIVE - start pane is active
//
// If user clicks Start Button while SBSM_SPACTIVE, then we become
//
// SBSM_EATING - eat mouse clicks
//
// Until we receive a WM_MOUSEFIRST/WM_MOUSELAST message, and then
// we return to SBSM_NORMAL.
//
// If user dismisses Start Pane, we go straight to SBSM_NORMAL.
//
//
// We eat the mouse clicks so that the click that the user made
// to "unclick" the start button doesn't cause it to get pushed down
// again (and cause the Start Menu to reopen).
//
#define SBSM_NORMAL 0
#define SBSM_SPACTIVE 1
#define SBSM_EATING 2
void Tray_SetStartPaneActive(BOOL fActive)
{
if (fActive)
{ // Start Pane appearing
c_tray._uStartButtonState = SBSM_SPACTIVE;
}
else if (c_tray._uStartButtonState != SBSM_EATING)
{ // Start Pane dismissing, not eating messages -> return to normal
c_tray._uStartButtonState = SBSM_NORMAL;
}
}
// Allow us to do stuff on a "button-down".
LRESULT WINAPI CTray::StartButtonSubclassWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
return c_tray._StartButtonSubclassWndProc(hwnd, uMsg, wParam, lParam);
}
LRESULT CTray::_StartButtonSubclassWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
LRESULT lRet;
ASSERT(_pfnButtonProc)
// Is the button going down?
if (uMsg == BM_SETSTATE)
{
// Is it going Down?
if (wParam)
{
// DebugMsg(DM_TRACE, "c.stswp: Set state %d", wParam);
// Yes - proceed if it's currently up and it's allowed to be down
if (!_uDown)
{
// Nope.
INSTRUMENT_STATECHANGE(SHCNFI_STATE_START_DOWN);
_uDown = 1;
// If we are going down, then we do not want to popup again until the Start Menu is collapsed
_fAllowUp = FALSE;
SendMessage(_hwndTrayTips, TTM_ACTIVATE, FALSE, 0L);
// Show the button down.
lRet = CallWindowProc(_pfnButtonProc, hwnd, uMsg, wParam, lParam);
// Notify the parent.
SendMessage(GetParent(hwnd), WM_COMMAND, (WPARAM)LOWORD(GetDlgCtrlID(hwnd)), (LPARAM)hwnd);
_tmOpen = GetTickCount();
return lRet;
}
else
{
// Yep. Do nothing.
// fDown = FALSE;
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
}
else
{
// DebugMsg(DM_TRACE, "c.stswp: Set state %d", wParam);
// Nope, buttons coming up.
// Is it supposed to be down? Is it not allowed to be up?
if (_uDown == 1 || !_fAllowUp)
{
INSTRUMENT_STATECHANGE(SHCNFI_STATE_START_UP);
// Yep, do nothing.
_uDown = 2;
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
else
{
SendMessage(_hwndTrayTips, TTM_ACTIVATE, TRUE, 0L);
// Nope, Forward it on.
_uDown = 0;
return CallWindowProc(_pfnButtonProc, hwnd, uMsg, wParam, lParam);
}
}
}
else
{
if (_uStartButtonState == SBSM_EATING &&
uMsg >= WM_MOUSEFIRST && uMsg <= WM_MOUSELAST)
{
_uStartButtonState = SBSM_NORMAL;
// Explicitly dismiss the Start Panel because it might be
// stuck in this limbo state where it is open but not the
// foreground window (_ShowStartButtonToolTip does this)
// so it doesn't know that it needs to go away.
ClosePopupMenus();
}
switch (uMsg) {
case WM_LBUTTONDOWN:
// The button was clicked on, then we don't need no stink'n focus rect.
SendMessage(GetParent(hwnd), WM_UPDATEUISTATE, MAKEWPARAM(UIS_SET,
UISF_HIDEFOCUS), 0);
goto ProcessCapture;
break;
case WM_KEYDOWN:
// The user pressed enter or return or some other bogus key combination when
// the start button had keyboard focus, so show the rect....
SendMessage(GetParent(hwnd), WM_UPDATEUISTATE, MAKEWPARAM(UIS_CLEAR,
UISF_HIDEFOCUS), 0);
if (wParam == VK_RETURN)
PostMessage(_hwnd, WM_COMMAND, IDC_KBSTART, 0);
// We do not need the capture, because we do all of our button processing
// on the button down. In fact taking capture for no good reason screws with
// drag and drop into the menus. We're overriding user.
ProcessCapture:
lRet = CallWindowProc(_pfnButtonProc, hwnd, uMsg, wParam, lParam);
SetCapture(NULL);
return lRet;
break;
case WM_MOUSEMOVE:
{
MSG msg;
msg.lParam = lParam;
msg.wParam = wParam;
msg.message = uMsg;
msg.hwnd = hwnd;
SendMessage(_hwndTrayTips, TTM_RELAYEVENT, 0, (LPARAM)(LPMSG)&msg);
break;
}
case WM_MOUSEACTIVATE:
if (_uStartButtonState != SBSM_NORMAL)
{
_uStartButtonState = SBSM_EATING;
return MA_ACTIVATEANDEAT;
}
break;
//
// Debounce the Start Button. Usability shows that lots of people
// double-click the Start Button, resulting in the menu opening
// and then immediately closing...
//
case WM_NCHITTEST:
if (GetTickCount() - _tmOpen < GetDoubleClickTime())
{
return HTNOWHERE;
}
break;
case WM_NULL:
break;
}
return CallWindowProc(_pfnButtonProc, hwnd, uMsg, wParam, lParam);
}
}
EXTERN_C const WCHAR c_wzTaskbarTheme[] = L"Taskbar";
EXTERN_C const WCHAR c_wzTaskbarVertTheme[] = L"TaskbarVert";
// create the toolbar with the three buttons and align windows
HWND CTray::_CreateStartButton()
{
DWORD dwStyle = 0;//BS_BITMAP;
_uStartButtonBalloonTip = RegisterWindowMessage(TEXT("Welcome Finished"));
_uLogoffUser = RegisterWindowMessage(TEXT("Logoff User"));
// Register for MM device changes
_uWinMM_DeviceChange = RegisterWindowMessage(WINMMDEVICECHANGEMSGSTRING);
HWND hwnd = CreateWindowEx(0, WC_BUTTON, TEXT("Start"),
WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS |
BS_PUSHBUTTON | BS_LEFT | BS_VCENTER | dwStyle,
0, 0, 0, 0, _hwnd, (HMENU)IDC_START, hinstCabinet, NULL);
if (hwnd)
{
// taskbar windows are themed under Taskbar subapp name
SetWindowTheme(hwnd, L"Start", NULL);
SendMessage(hwnd, CCM_DPISCALE, TRUE, 0);
// Subclass it.
_hwndStart = hwnd;
_pfnButtonProc = (WNDPROC)SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LPARAM)StartButtonSubclassWndProc);
_StartButtonReset();
}
return hwnd;
}
void CTray::_GetWindowSizes(UINT uStuckPlace, PRECT prcClient, PRECT prcView, PRECT prcNotify)
{
prcView->top = 0;
prcView->left = 0;
prcView->bottom = prcClient->bottom;
prcView->right = prcClient->right;
if (STUCK_HORIZONTAL(uStuckPlace))
{
DWORD_PTR dwNotifySize = SendMessage(_hwndNotify, WM_CALCMINSIZE, prcClient->right / 2, prcClient->bottom);
prcNotify->top = 0;
prcNotify->left = prcClient->right - LOWORD(dwNotifySize);
prcNotify->bottom = HIWORD(dwNotifySize);
prcNotify->right = prcClient->right;
prcView->left = _sizeStart.cx + g_cxFrame + 1;
prcView->right = prcNotify->left;
}
else
{
DWORD_PTR dwNotifySize = SendMessage(_hwndNotify, WM_CALCMINSIZE, prcClient->right, prcClient->bottom / 2);
prcNotify->top = prcClient->bottom - HIWORD(dwNotifySize);
prcNotify->left = 0;
prcNotify->bottom = prcClient->bottom;
prcNotify->right = LOWORD(dwNotifySize);
prcView->top = _sizeStart.cy + g_cyTabSpace;
prcView->bottom = prcNotify->top;
}
}
void CTray::_RestoreWindowPos()
{
WINDOWPLACEMENT wp;
//first restore the stuck postitions
_GetSaveStateAndInitRects();
wp.length = sizeof(wp);
wp.showCmd = SW_HIDE;
_uMoveStuckPlace = (UINT)-1;
_GetDockedRect(&wp.rcNormalPosition, FALSE);
SendMessage(_hwndNotify, TNM_TRAYHIDE, 0, _fHideClock);
SetWindowPlacement(_hwnd, &wp);
}
// Get the display (monitor) rectangle from the given arbitrary point
HMONITOR CTray::_GetDisplayRectFromPoint(LPRECT prcDisplay, POINT pt, UINT uFlags)
{
RECT rcEmpty = { 0 };
HMONITOR hmon = MonitorFromPoint(pt, uFlags);
if (hmon && prcDisplay)
GetMonitorRect(hmon, prcDisplay);
else if (prcDisplay)
*prcDisplay = rcEmpty;
return hmon;
}
// Get the display (monitor) rectangle from the given arbitrary rectangle
HMONITOR CTray::_GetDisplayRectFromRect(LPRECT prcDisplay, LPCRECT prcIn, UINT uFlags)
{
RECT rcEmpty = { 0 };
HMONITOR hmon = MonitorFromRect(prcIn, uFlags);
if (hmon && prcDisplay)
GetMonitorRect(hmon, prcDisplay);
else if (prcDisplay)
*prcDisplay = rcEmpty;
return hmon;
}
// Get the display (monitor) rectangle where the taskbar is currently on,
// if that monitor is invalid, get the nearest one.
void CTray::_GetStuckDisplayRect(UINT uStuckPlace, LPRECT prcDisplay)
{
ASSERT(prcDisplay);
BOOL fValid = GetMonitorRect(_hmonStuck, prcDisplay);
if (!fValid)
_GetDisplayRectFromRect(prcDisplay, &_arStuckRects[uStuckPlace], MONITOR_DEFAULTTONEAREST);
}
void CTray::_AdjustRectForSizingBar(UINT uStuckPlace, LPRECT prc, int iIncrement)
{
if (iIncrement != 0)
{
switch (uStuckPlace)
{
case STICK_BOTTOM: prc->top -= iIncrement * _sizeSizingBar.cy; break;
case STICK_TOP: prc->bottom += iIncrement * _sizeSizingBar.cy; break;
case STICK_LEFT: prc->right += iIncrement * _sizeSizingBar.cx; break;
case STICK_RIGHT: prc->left -= iIncrement * _sizeSizingBar.cx; break;
}
}
else
{
if (IS_BIDI_LOCALIZED_SYSTEM())
{
switch (uStuckPlace)
{
case STICK_BOTTOM: prc->bottom = prc->top + _sizeSizingBar.cy; break;
case STICK_TOP: prc->top = prc->bottom - _sizeSizingBar.cy; break;
case STICK_LEFT: prc->right = prc->left + _sizeSizingBar.cx; break;
case STICK_RIGHT: prc->left = prc->right - _sizeSizingBar.cx; break;