00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
#include "precomp.h"
00014
#pragma hdrstop
00015
00016
void _SetCloseDefault(
PMENU pSubMenu);
00017
PWND FindFakeMDIChild(
PWND pwndParent);
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 PMENU xxxLoadSysDesktopMenu (
PMENU * ppmenu, UINT uMenuId)
00031 {
00032
PMENU pmenu;
00033
00034
00035
00036 UserAssert(*ppmenu ==
NULL);
00037
00038 pmenu =
xxxLoadSysMenu(uMenuId);
00039
if (pmenu ==
NULL) {
00040
return NULL;
00041 }
00042
00043
00044
00045
00046
if (*ppmenu !=
NULL) {
00047 UserAssert(
TestMF(*ppmenu,
MFSYSMENU));
00048 RIPMSG1(RIP_WARNING,
00049
"LoadSysDesktopMenu: Menu loaded during callback. ppmenu:%#p",
00050 ppmenu);
00051
_DestroyMenu(pmenu);
00052
return *ppmenu;
00053 }
00054
00055
00056
00057
SetMF(pmenu,
MFSYSMENU);
00058
LockDesktopMenu(ppmenu, pmenu);
00059
return pmenu;
00060 }
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074 PVOID
LockDesktopMenu(
PMENU * ppmenu,
PMENU pmenu)
00075 {
00076
PMENU pSubMenu;
00077
PTHREADINFO ptiDesktop;
00078
00079
00080
00081 UserAssert(*ppmenu ==
NULL);
00082
00083
if (pmenu ==
NULL) {
00084
return NULL;
00085 }
00086
00087
SetMF(pmenu,
MFDESKTOP);
00088
00089
00090
00091
00092 ptiDesktop =
PtiCurrent()->rpdesk->rpwinstaParent->pTerm->ptiDesktop;
00093
HMChangeOwnerProcess(pmenu, ptiDesktop);
00094
00095 pSubMenu = pmenu->
rgItems->
spSubMenu;
00096 UserAssert(pSubMenu !=
NULL);
00097
00098
SetMF(pSubMenu,
MFDESKTOP);
00099
HMChangeOwnerProcess(pSubMenu, ptiDesktop);
00100
00101
#if DBG
00102
{
00103
00104
00105
00106
00107
PITEM pitem;
00108
UINT uItems;
00109
00110 UserAssert(pmenu->
cItems == 1);
00111
00112 pitem = pSubMenu->
rgItems;
00113 uItems = pSubMenu->
cItems;
00114
while (uItems--) {
00115 UserAssert(pitem->
spSubMenu ==
NULL);
00116 pitem++;
00117 }
00118 }
00119
#endif
00120
00121
return Lock(ppmenu, pmenu);
00122 }
00123
00124 PVOID
UnlockDesktopMenu(
PMENU * ppmenu)
00125 {
00126 UserAssert(*ppmenu !=
NULL);
00127 UserAssert(
TestMF(*ppmenu,
MFDESKTOP));
00128
ClearMF(*ppmenu,
MFDESKTOP);
00129 UserAssert(
TestMF((*ppmenu)->rgItems->spSubMenu,
MFDESKTOP));
00130
ClearMF((*ppmenu)->rgItems->spSubMenu,
MFDESKTOP);
00131
return Unlock(ppmenu);
00132 }
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142 PMENU xxxGetSysMenuHandle(
00143
PWND pwnd)
00144 {
00145
PMENU pMenu;
00146
00147
CheckLock(pwnd);
00148
00149
if (
TestWF(pwnd,
WFSYSMENU)) {
00150 pMenu = pwnd->
spmenuSys;
00151
00152
00153
00154
00155
if (pMenu ==
NULL) {
00156
00157
00158
00159
00160
00161
00162
00163 pMenu = pwnd->
head.rpdesk->spmenuSys;
00164
00165
00166
00167
00168
00169
00170
if (pMenu ==
NULL && !(
PtiCurrent()->TIF_flags & (
TIF_SYSTEMTHREAD |
TIF_INCLEANUP))) {
00171
00172 pMenu =
xxxLoadSysDesktopMenu (&pwnd->
head.rpdesk->spmenuSys,
ID_SYSMENU);
00173 }
00174 }
00175 }
else {
00176 pMenu =
NULL;
00177 }
00178
00179
return pMenu;
00180 }
00181
00182
00183
00184
00185
00186
00187
00188
00189 PMENU xxxGetSysMenu(
PWND pwnd, BOOL fSubMenu)
00190 {
00191
PMENU pMenu;
00192
00193
CheckLock(pwnd);
00194
xxxSetSysMenu(pwnd);
00195
if ((pMenu =
xxxGetSysMenuHandle(pwnd)) !=
NULL) {
00196
if (fSubMenu)
00197 pMenu =
_GetSubMenu(pMenu, 0);
00198 }
00199
00200
return(pMenu);
00201 }
00202
00203
00204
00205
00206
00207
00208 BOOL IsSmallerThanScreen(
PWND pwnd)
00209 {
00210
int dxMax, dyMax;
00211
PMONITOR pMonitor;
00212
00213 pMonitor =
_MonitorFromWindow(pwnd, MONITOR_DEFAULTTOPRIMARY);
00214 dxMax = pMonitor->
rcWork.right - pMonitor->
rcWork.left;
00215 dyMax = pMonitor->
rcWork.bottom - pMonitor->
rcWork.top;
00216
00217
if ((pwnd->
rcWindow.right - pwnd->
rcWindow.left < dxMax) ||
00218 (pwnd->
rcWindow.bottom - pwnd->
rcWindow.top < dyMax)) {
00219
return TRUE;
00220 }
00221
return FALSE;
00222 }
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232 void xxxSetSysMenu(
00233
PWND pwnd)
00234 {
00235
PMENU pMenu;
00236
UINT wSize;
00237
UINT wMinimize;
00238
UINT wMaximize;
00239
UINT wMove;
00240
UINT wRestore;
00241
UINT wDefault;
00242
BOOL fFramedDialogBox;
00243
TL tlmenu;
00244
00245
CheckLock(pwnd);
00246
00247
00248
00249
if ((pMenu =
xxxGetSysMenuHandle(pwnd)) !=
NULL) {
00250
00251 pMenu =
_GetSubMenu(pMenu, 0);
00252
if (!pMenu)
00253
return;
00254
00255
ThreadLockAlways(pMenu, &tlmenu);
00256
00257
00258
00259
00260
00261
00262
00263
00264 wSize = wMaximize = wMinimize = wMove = 0;
00265 wRestore = MFS_GRAYED;
00266
00267
00268
00269
00270 wDefault = SC_CLOSE;
00271
00272
00273
00274
00275
00276
00277
00278
if (
TestWF(pwnd,
WFMINIMIZED))
00279 {
00280 wRestore = 0;
00281 wMinimize = MFS_GRAYED;
00282 wSize = MFS_GRAYED;
00283 wDefault = SC_RESTORE;
00284
00285
if (
IsTrayWindow(pwnd))
00286 wMove = MFS_GRAYED;
00287 }
00288
else if (!
TestWF(pwnd,
WFMINBOX))
00289 wMinimize = MFS_GRAYED;
00290
00291
00292
00293
00294
if (!
TestWF(pwnd,
WFMAXBOX))
00295 wMaximize = MFS_GRAYED;
00296
else if (
TestWF(pwnd,
WFMAXIMIZED)) {
00297 wRestore = 0;
00298
00299
00300
00301
00302
00303
00304 wMove = MFS_GRAYED;
00305
if (!
TestWF(pwnd,
WFCHILD)) {
00306
if (
IsSmallerThanScreen(pwnd)) {
00307 wMove = 0;
00308 }
00309 }
00310
00311 wSize = MFS_GRAYED;
00312 wMaximize = MFS_GRAYED;
00313 }
00314
00315
if (!
TestWF(pwnd,
WFSIZEBOX))
00316 wSize = MFS_GRAYED;
00317
00318
00319
00320
00321
00322
00323 fFramedDialogBox =
00324 (((
TestWF(pwnd,
WFBORDERMASK) == (
BYTE)
LOBYTE(
WFDLGFRAME))
00325 || (
TestWF(pwnd,
WEFDLGMODALFRAME)))
00326 && !
TestWF(pwnd,
WFSIZEBOX |
WFMINBOX |
WFMAXBOX));
00327
00328
if (!fFramedDialogBox) {
00329
xxxEnableMenuItem(pMenu, (
UINT)SC_SIZE, wSize);
00330
if (!
TestWF(pwnd,
WEFTOOLWINDOW))
00331 {
00332
xxxEnableMenuItem(pMenu, (
UINT)SC_MINIMIZE, wMinimize);
00333
xxxEnableMenuItem(pMenu, (
UINT)SC_MAXIMIZE, wMaximize);
00334
xxxEnableMenuItem(pMenu, (
UINT)SC_RESTORE, wRestore);
00335 }
00336 }
00337
00338
xxxEnableMenuItem(pMenu, (
UINT)SC_MOVE, wMove);
00339
00340
#if DBG
00341
00342
00343
00344
if (
TestMF(pMenu,
MFSYSMENU)) {
00345
PITEM pItem =
MNLookUpItem(pMenu, SC_CLOSE,
FALSE,
NULL);
00346 UserAssert((pItem !=
NULL) && !
TestMFS(pItem, MFS_GRAYED));
00347 }
00348
#endif
00349
00350
if (wDefault == SC_CLOSE)
00351
_SetCloseDefault(pMenu);
00352
else
00353
_SetMenuDefaultItem(pMenu, wDefault, MF_BYCOMMAND);
00354
00355
ThreadUnlock(&tlmenu);
00356 }
00357 }
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368 PMENU xxxGetSystemMenu(
00369
PWND pwnd,
00370 BOOL fRevert)
00371 {
00372
PMENU pmenu;
00373
CheckLock(pwnd);
00374
00375
00376
00377
00378
00379 pmenu = pwnd->
spmenuSys;
00380
if (fRevert) {
00381
00382
00383
00384
00385
if ((pmenu !=
NULL) && !
TestMF(pmenu,
MFSYSMENU)) {
00386
00387
if (
UnlockWndMenu(pwnd, &pwnd->
spmenuSys)) {
00388
_DestroyMenu(pmenu);
00389 }
00390 }
00391 }
else {
00392
00393
00394
00395
00396
if (((pmenu ==
NULL) ||
TestMF(pmenu,
MFSYSMENU))
00397 &&
TestWF(pwnd,
WFSYSMENU)) {
00398
00399
PPOPUPMENU pGlobalPopupMenu;
00400
UINT uMenuId = (pwnd->
spmenuSys ==
NULL ?
ID_SYSMENU :
ID_DIALOGSYSMENU);
00401 pmenu =
xxxLoadSysMenu(uMenuId);
00402
if (pmenu ==
NULL) {
00403 RIPMSG1(RIP_WARNING,
"_GetSystemMenu: xxxLoadSysMenu Failed. pwnd:%#p", pwnd);
00404 }
00405
LockWndMenu(pwnd, &pwnd->
spmenuSys, pmenu);
00406
00407 pmenu = pwnd->
spmenuSys;
00408 pGlobalPopupMenu =
GetpGlobalPopupMenu(pwnd);
00409
if ((pGlobalPopupMenu !=
NULL)
00410 && !pGlobalPopupMenu->
fIsTrackPopup
00411 && (pGlobalPopupMenu->
spwndPopupMenu == pwnd)) {
00412
00413 UserAssert(pGlobalPopupMenu->
spwndNotify == pwnd);
00414
if (pGlobalPopupMenu->
fIsSysMenu) {
00415
Lock(&pGlobalPopupMenu->
spmenu, pmenu);
00416 }
else {
00417
Lock(&pGlobalPopupMenu->
spmenuAlternate, pmenu);
00418 }
00419 }
00420 }
00421 }
00422
00423
00424
00425
00426
if (pwnd->
spmenuSys !=
NULL) {
00427
00428
00429
00430
00431
00432
00433
00434 pmenu =
_GetSubMenu(pwnd->
spmenuSys, 0);
00435
if (pmenu) {
00436
SetMF(pmenu,
MFAPPSYSMENU);
00437
Lock(&pmenu->
spwndNotify, pwnd);
00438 }
00439
return pmenu;
00440 }
00441
00442
return NULL;
00443 }
00444
00445
00446
00447
00448
00449
00450
00451
00452
00453
00454
00455 DWORD MenuItemState(
00456
PMENU pMenu,
00457 UINT wCmd,
00458 DWORD wFlags,
00459 DWORD wMask,
00460
PMENU *ppMenu)
00461 {
00462
PITEM pItem;
00463
DWORD wRet;
00464
00465
00466
00467
00468
if ((pItem =
MNLookUpItem(pMenu, wCmd, (
BOOL) (wFlags & MF_BYPOSITION), ppMenu)) ==
NULL)
00469
return (
DWORD)-1;
00470
00471
00472
00473
00474 wRet = pItem->
fState & wMask;
00475
00476
00477
00478
00479 pItem->
fState ^= ((wRet ^ wFlags) & wMask);
00480
00481
return wRet;
00482 }
00483
00484
00485
00486
00487
00488
00489
00490
00491
00492
00493
00494 DWORD xxxEnableMenuItem(
00495
PMENU pMenu,
00496 UINT wIDEnableItem,
00497 UINT wEnable)
00498 {
00499
DWORD dres;
00500
PMENU pRealMenu;
00501
PPOPUPMENU ppopup;
00502
00503
CheckLock(pMenu);
00504
00505 dres =
MenuItemState(pMenu, wIDEnableItem, wEnable,
00506 MFS_GRAYED, &pRealMenu);
00507
00508
00509
00510
00511
if (
TestMF(pMenu,
MFAPPSYSMENU) && (pMenu->
spwndNotify !=
NULL)) {
00512
00513
TL tlpwnd;
00514
00515
switch (wIDEnableItem) {
00516
case SC_SIZE:
00517
case SC_MOVE:
00518
case SC_MINIMIZE:
00519
case SC_MAXIMIZE:
00520
case SC_CLOSE:
00521
case SC_RESTORE:
00522
ThreadLock(pMenu->
spwndNotify, &tlpwnd);
00523
xxxRedrawTitle(pMenu->
spwndNotify, DC_BUTTONS);
00524
ThreadUnlock(&tlpwnd);
00525 }
00526 }
00527
00528
00529
if(pRealMenu && (ppopup =
MNGetPopupFromMenu(pRealMenu,
NULL))){
00530
xxxMNUpdateShownMenu(ppopup,
NULL,
MNUS_DEFAULT);
00531 }
00532
00533
return dres;
00534 }
00535
00536
00537
00538
00539
00540
00541
00542
00543
00544
00545
00546 DWORD _CheckMenuItem(
00547
PMENU pMenu,
00548 UINT wIDCheckItem,
00549 UINT wCheck)
00550 {
00551
return MenuItemState(pMenu, wIDCheckItem, wCheck, (
UINT)MF_CHECKED,
NULL);
00552 }
00553
00554
00555
00556
00557
00558
00559
00560
00561
00562
00563
00564
00565
00566
00567 BOOL _SetMenuDefaultItem(
PMENU pMenu, UINT wID, BOOL fByPosition)
00568 {
00569
UINT iItem;
00570
UINT cItems;
00571
PITEM pItem;
00572
PITEM pItemFound;
00573
PMENU pMenuFound;
00574
00575
00576
00577
00578
00579
00580
if (wID !=
MFMWFP_NOITEM)
00581 {
00582 pItemFound =
MNLookUpItem(pMenu, wID, fByPosition, &pMenuFound);
00583
00584
00585
if ((pItemFound ==
NULL) || (pMenuFound != pMenu) ||
TestMFT(pItemFound, MFT_SEPARATOR))
00586
return(
FALSE);
00587
00588 }
00589
else
00590 pItemFound =
NULL;
00591
00592 pItem = pMenu->
rgItems;
00593 cItems = pMenu->
cItems;
00594
00595
00596
00597
for (iItem = 0; iItem < cItems; iItem++, pItem++) {
00598
00599
00600
00601
00602
00603
00604
if (
TestMFS(pItem, MFS_DEFAULT) && (pItem != pItemFound))
00605 {
00606
00607
00608
00609
00610
00611
00612
00613
00614
00615
00616
00617
00618
00619
00620
00621
ClearMFS(pItem, MFS_DEFAULT);
00622 pItem->
ulX =
UNDERLINE_RECALC;
00623 pItem->
ulWidth = 0;
00624 }
00625 }
00626
00627
if (wID !=
MFMWFP_NOITEM)
00628 {
00629
if (!
TestMFS(pItemFound, MFS_DEFAULT))
00630 {
00631
00632
00633
00634
00635
00636
SetMFS(pItemFound, MFS_DEFAULT);
00637 pItemFound->
ulX =
UNDERLINE_RECALC;
00638 pItemFound->
ulWidth = 0;
00639 }
00640 }
00641
00642
return(
TRUE);
00643 }
00644
00645
00646
00647
00648
00649
00650
00651
00652
00653
00654 void _SetCloseDefault(
PMENU pSubMenu)
00655 {
00656
if (!
_SetMenuDefaultItem(pSubMenu, SC_CLOSE, MF_BYCOMMAND))
00657 {
00658
00659
00660
00661
00662
00663
if (!
_SetMenuDefaultItem(pSubMenu, SC_CLOSE - 0x7000, MF_BYCOMMAND))
00664
_SetMenuDefaultItem(pSubMenu, 0xC070, MF_BYCOMMAND);
00665 }
00666 }
00667
00668
00669
00670
00671
00672
00673
00674
00675
00676
00677
00678 PWND FindFakeMDIChild(
PWND pwnd)
00679 {
00680
PWND pwndReturn;
00681
00682
00683
if (!
TestWF(pwnd,
WFVISIBLE))
00684
return(
NULL);
00685
00686
00687
if (
TestWF(pwnd,
WFCHILD) && (
TestWF(pwnd,
WFMAXIMIZED) || (pwnd->
spmenuSys)))
00688
return(pwnd);
00689
00690
00691
for (pwnd = pwnd->
spwndChild; pwnd; pwnd = pwnd->
spwndNext)
00692 {
00693 pwndReturn =
FindFakeMDIChild(pwnd);
00694
if (pwndReturn)
00695
return(pwndReturn);
00696 }
00697
00698
return(
NULL);
00699 }
00700
00701
00702
00703
00704
00705
00706
00707
00708
00709
00710
00711
00712
00713
00714
00715
00716
00717
00718
00719
00720
00721
00722
00723
00724 void SetupFakeMDIAppStuff(
PMENU lpMenu,
PITEM lpItem)
00725 {
00726
PMENU pSubMenu;
00727
PWND pwndParent;
00728
PWND pwndChild;
00729
00730
if (!(pSubMenu = lpItem->
spSubMenu))
00731
return;
00732
00733 pwndParent = lpMenu->
spwndNotify;
00734
00735
00736
00737
00738
00739
if (!
TestWF(pwndParent,
WFWIN40COMPAT))
00740 {
00741
if (
_GetMenuDefaultItem(pSubMenu,
TRUE, GMDI_USEDISABLED) == -1
L)
00742
_SetCloseDefault(pSubMenu);
00743 }
00744
00745
00746
00747
00748
00749
00750
00751
00752
if (pwndChild =
FindFakeMDIChild(pwndParent)) {
00753 lpItem->
dwItemData = (ULONG_PTR)
HWq(pwndChild);
00754
00755 }
00756 }