Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

3621 lines
82 KiB

  1. /*++
  2. Copyright (c) 1990-1995 Microsoft Corporation
  3. Module Name:
  4. proppage.c
  5. Abstract:
  6. This module contains user page procs
  7. Author:
  8. 18-Aug-1995 Fri 18:57:12 created -by- Daniel Chou (danielc)
  9. [Environment:]
  10. NT Windows - Common Printer Driver UI DLL.
  11. [Notes:]
  12. Revision History:
  13. --*/
  14. #include "precomp.h"
  15. #pragma hdrstop
  16. #define DBG_CPSUIFILENAME DbgPropPage
  17. #define DBG_PROPPAGEPROC 0x00000001
  18. #define DBG_INITP1 0x00000002
  19. #define DBGITEM_INITP1 0x00000004
  20. #define DBGITEM_UP1 0x00000008
  21. #define DBG_HMII 0x00000010
  22. #define DBG_AII 0x00000020
  23. #define DBG_QSORT 0x00000040
  24. #define DBG_SETFOCUS 0x00000080
  25. #define DBG_STATES 0x00000100
  26. #define DBG_ADVPUSH 0x00000200
  27. DEFINE_DBGVAR(0);
  28. extern HINSTANCE hInstDLL;
  29. extern STDPAGEINFO StdPageInfo[];
  30. extern BYTE StdTVOT[];
  31. #define MAX_ITEM_CTRLS 12
  32. const BYTE cTVOTCtrls[] = { 8, 10, 9, 9, 9, 6, 6, 8, 6, 6, 0 };
  33. #define IIF_3STATES_1 OTINTF_STATES_1
  34. #define IIF_3STATES_2 OTINTF_STATES_2
  35. #define IIF_3STATES_3 OTINTF_STATES_3
  36. #define IIF_3STATES_HIDE OTINTF_STATES_HIDE_MASK
  37. #define IIF_STDPAGE_3STATES OTINTF_STDPAGE_3STATES
  38. #define IIF_ITEM_HIDE 0x10
  39. #define IIF_EXT_HIDE 0x20
  40. typedef struct _ITEMINFO {
  41. POPTITEM pItem;
  42. BYTE Flags;
  43. BYTE Type;
  44. WORD BegCtrlID;
  45. WORD CtrlBits;
  46. SHORT xExtMove;
  47. WORD yExt;
  48. WORD yMoveUp;
  49. WORD Extra;
  50. RECT rc;
  51. RECT rcCtrls;
  52. } ITEMINFO, *PITEMINFO;
  53. typedef struct _ITEMINFOHEADER {
  54. HWND hDlg;
  55. PTVWND pTVWnd;
  56. WORD cItem;
  57. WORD cMaxItem;
  58. ITEMINFO ItemInfo[1];
  59. } ITEMINFOHEADER, *PITEMINFOHEADER;
  60. #define OUTRANGE_LEFT 0x7FFFFFFFL
  61. #define INIT_ADDRECT(rc) ((rc).left = OUTRANGE_LEFT)
  62. #define HAS_ADDRECT(rc) ((rc).left != OUTRANGE_LEFT)
  63. typedef struct _HSINFO {
  64. HWND hCtrl;
  65. LONG x;
  66. LONG y;
  67. } HSINFO, *PHSINFO;
  68. INT
  69. __cdecl
  70. ItemInfoCompare(
  71. const void *pItemInfo1,
  72. const void *pItemInfo2
  73. )
  74. {
  75. return((INT)(((PITEMINFO)pItemInfo1)->rc.top) -
  76. (INT)(((PITEMINFO)pItemInfo2)->rc.top));
  77. }
  78. UINT
  79. AddRect(
  80. RECT *prc1,
  81. RECT *prc2
  82. )
  83. /*++
  84. Routine Description:
  85. This function add the *prc1 to *prc2, if any of the prc1 corners are
  86. outside of prc2
  87. Arguments:
  88. Return Value:
  89. UINT, count of *prc1 corners which is at outside of *prc2 corners, other
  90. word is the *prc2 corners which added to the *prc2 corner that is.
  91. Author:
  92. 16-Sep-1995 Sat 23:06:53 created -by- Daniel Chou (danielc)
  93. Revision History:
  94. --*/
  95. {
  96. UINT cAdded = 0;
  97. if (prc2->left == OUTRANGE_LEFT) {
  98. *prc2 = *prc1;
  99. return(0);
  100. } else {
  101. CPSUIASSERT(0, "AddRect: invalid rc.left=%d",
  102. (prc2->left >= 0) && (prc2->top >= 0) &&
  103. (prc2->right >= prc2->left) && (prc2->bottom >= prc2->top),
  104. LongToPtr(prc2->left));
  105. }
  106. if (prc2->left > prc1->left) {
  107. prc2->left = prc1->left;
  108. ++cAdded;
  109. }
  110. if (prc2->top > prc1->top) {
  111. prc2->top = prc1->top;
  112. ++cAdded;
  113. }
  114. if (prc2->right < prc1->right) {
  115. prc2->right = prc1->right;
  116. ++cAdded;
  117. }
  118. if (prc2->bottom < prc1->bottom) {
  119. prc2->bottom = prc1->bottom;
  120. ++cAdded;
  121. }
  122. return(cAdded);
  123. }
  124. UINT
  125. HideStates(
  126. HWND hDlg,
  127. PITEMINFO pII,
  128. RECT *prcVisibleNoStates
  129. )
  130. /*++
  131. Routine Description:
  132. Arguments:
  133. Return Value:
  134. Author:
  135. 22-Aug-1995 Tue 16:58:37 created -by- Daniel Chou (danielc)
  136. Revision History:
  137. --*/
  138. {
  139. PHSINFO pHSInfo;
  140. HSINFO HSInfo[6];
  141. UINT HideBits;
  142. UINT Mask;
  143. UINT CtrlID = (UINT)(pII->BegCtrlID + 2);
  144. RECT rcStates;
  145. RECT rcMax[3];
  146. UINT yRemoved = 0;
  147. SIZEL szlHide;
  148. SIZEL szlSpace;
  149. INT cStates;
  150. INT cHide;
  151. INT i;
  152. INT j;
  153. BOOL DoXDir;
  154. szlSpace.cx =
  155. szlSpace.cy =
  156. szlHide.cx =
  157. szlHide.cy = 0;
  158. cStates = (UINT)((pII->Type == TVOT_2STATES) ? 2 : 3);
  159. HideBits = (UINT)(pII->Flags & IIF_3STATES_HIDE);
  160. CPSUIDBG(DBG_STATES, ("\ncStates=%ld, HideBits=%02lx", cStates, HideBits));
  161. INIT_ADDRECT(rcStates);
  162. for (i = 0, cHide = 0, Mask = HideBits, pHSInfo = HSInfo;
  163. i < cStates;
  164. i++, Mask >>= 1) {
  165. INIT_ADDRECT(rcMax[i]);
  166. for (j = 0; j < 2; j++, pHSInfo++) {
  167. RECT rc;
  168. if (pHSInfo->hCtrl = CtrlIDrcWnd(hDlg, CtrlID++, &rc)) {
  169. CPSUIDBG(DBG_STATES,
  170. ("MoveStates: States=(%d:%d), ID=%d, Hide=%d",
  171. i, j, CtrlID - 1, (Mask & 0x01) ? 1 : 0));
  172. if (Mask & 0x01) {
  173. CPSUIDBG(DBG_STATES, ("Hide the State %d", i));
  174. }
  175. pHSInfo->x = rc.left;
  176. pHSInfo->y = rc.top;
  177. AddRect(&rc, &rcMax[i]);
  178. CPSUIDBG(DBG_STATES, ("i=%ld, j=%ld, rc=(%ld, %ld)-(%ld, %ld)=%ldx%ld",
  179. i, j, rc.left, rc.top, rc.right, rc.bottom,
  180. rc.right - rc.left, rc.bottom - rc.top));
  181. }
  182. }
  183. if (HAS_ADDRECT(rcMax[i])) {
  184. CPSUIRECT(0, "rcMax", &rcMax[i], i, 0);
  185. if (i) {
  186. if (rcMax[i].top > rcMax[i - 1].bottom) {
  187. yRemoved++;
  188. }
  189. szlSpace.cx += (rcMax[i].left - rcMax[i - 1].right);
  190. szlSpace.cy += (rcMax[i].top - rcMax[i - 1].bottom);
  191. }
  192. AddRect(&rcMax[i], &rcStates);
  193. if (Mask & 0x01) {
  194. CPSUIDBG(DBG_STATES, ("Hide i=%ld, szlHide.cy=%ld",
  195. i, szlHide.cy));
  196. if (i) {
  197. szlHide.cy += (rcMax[i].top - rcMax[i - 1].bottom);
  198. }
  199. szlHide.cx += rcMax[i].right - rcMax[i].left;
  200. szlHide.cy += rcMax[i].bottom - rcMax[i].top;
  201. if (++cHide == cStates) {
  202. CPSUIASSERT(0, "Error: HideStates(HIDE EVERY THING)=%d",
  203. cHide < cStates, UIntToPtr(cHide));
  204. return(0);
  205. }
  206. }
  207. }
  208. }
  209. CPSUIDBG(DBG_STATES, ("rcStates=(%ld, %ld)-(%ld, %ld)=%ldx%ld",
  210. rcStates.left, rcStates.top, rcStates.right, rcStates.bottom,
  211. rcStates.right - rcStates.left, rcStates.bottom - rcStates.top));
  212. CPSUIDBG(DBG_STATES,
  213. ("szlHide=%ldx%ld, szlSpace=%ldx%ld, yReMoved=%ld",
  214. szlHide.cx, szlHide.cy, szlSpace.cx, szlSpace.cy, yRemoved));
  215. if (yRemoved) {
  216. szlSpace.cy /= yRemoved;
  217. //
  218. // If we arrange top/down and we do not intersect with the visible
  219. // bits then we can remove the y space
  220. //
  221. if ((rcStates.top >= prcVisibleNoStates->bottom) ||
  222. (rcStates.bottom <= prcVisibleNoStates->top)) {
  223. //
  224. // We can remove the Y line now
  225. //
  226. rcStates.bottom -= (yRemoved = szlHide.cy);
  227. szlHide.cy = 0;
  228. CPSUIDBG(DBG_STATES,
  229. ("HideStates: OK to remove Y, yRemoved=%ld", yRemoved));
  230. } else {
  231. yRemoved = 0;
  232. //
  233. // Do not remove Y spaces, just arrange it
  234. //
  235. CPSUIINT(("---- STATES: CANNOT remove Y space, Re-Arrange it ---"));
  236. }
  237. DoXDir = FALSE;
  238. szlHide.cx =
  239. szlHide.cy = 0;
  240. szlSpace.cx = 0;
  241. } else {
  242. DoXDir = TRUE;
  243. szlHide.cy =
  244. szlSpace.cy = 0;
  245. }
  246. switch (cStates - cHide) {
  247. case 1:
  248. //
  249. // Only one state left, just center it
  250. //
  251. if (DoXDir) {
  252. szlHide.cx = ((szlSpace.cx + szlHide.cx) / 2);
  253. }
  254. break;
  255. case 2:
  256. if (DoXDir) {
  257. szlHide.cx = ((szlHide.cx + 1) / 3);
  258. szlSpace.cx += szlHide.cx;
  259. }
  260. break;
  261. }
  262. rcStates.left += szlHide.cx;
  263. rcStates.top += szlHide.cy;
  264. CPSUIDBG(DBG_STATES,
  265. ("State1=(%ld, %ld): szlHide=%ld x %ld, szlSpace=%ld x %ld, DoXDir=%ld",
  266. rcStates.left, rcStates.top,
  267. szlHide.cx, szlHide.cy, szlSpace.cx, szlSpace.cy, DoXDir));
  268. for (i = 0, Mask = HideBits, pHSInfo = HSInfo;
  269. i < cStates;
  270. i++, Mask >>= 1) {
  271. if (Mask & 0x01) {
  272. pHSInfo += 2;
  273. } else {
  274. for (j = 0; j < 2; j++, pHSInfo++) {
  275. if (pHSInfo->hCtrl) {
  276. szlHide.cx = pHSInfo->x - rcMax[i].left;
  277. szlHide.cy = pHSInfo->y - rcMax[i].top;
  278. CPSUIDBG(DBG_STATES,
  279. ("HideStates: MOVE(%d:%d) from (%ld, %ld) to (%ld, %ld)",
  280. i, j, pHSInfo->x, pHSInfo->y,
  281. rcStates.left + szlHide.cx,
  282. rcStates.top + szlHide.cy));
  283. SetWindowPos(pHSInfo->hCtrl, NULL,
  284. rcStates.left + szlHide.cx,
  285. rcStates.top + szlHide.cy,
  286. 0, 0,
  287. SWP_NOSIZE | SWP_NOZORDER);
  288. }
  289. }
  290. if (DoXDir) {
  291. rcStates.left += (szlSpace.cx + rcMax[i].right - rcMax[i].left);
  292. } else {
  293. rcStates.top += (szlSpace.cy + rcMax[i].bottom - rcMax[i].top);
  294. }
  295. }
  296. }
  297. return(yRemoved);
  298. }
  299. VOID
  300. AddItemInfo(
  301. PITEMINFOHEADER pIIHdr,
  302. POPTITEM pItem
  303. )
  304. /*++
  305. Routine Description:
  306. Arguments:
  307. Return Value:
  308. Author:
  309. 09-Sep-1995 Sat 17:27:01 created -by- Daniel Chou (danielc)
  310. Revision History:
  311. --*/
  312. {
  313. HWND hDlg;
  314. WORD Mask;
  315. WORD HideBits;
  316. WORD ExtBits;
  317. WORD NonStatesBits;
  318. UINT CurCtrlID;
  319. UINT cCtrls;
  320. UINT cStates;
  321. RECT rcVisible;
  322. RECT rcVisibleNoStates;
  323. RECT rcExt;
  324. RECT rcGrpBox;
  325. ITEMINFO II;
  326. if (pItem) {
  327. POPTTYPE pOptType;
  328. II.Flags = (pItem->Flags & OPTIF_ITEM_HIDE) ? IIF_ITEM_HIDE : 0;
  329. if ((pItem->Flags & OPTIF_EXT_HIDE) ||
  330. (!pItem->pExtChkBox)) {
  331. II.Flags |= IIF_EXT_HIDE;
  332. }
  333. if (pOptType = pItem->pOptType) {
  334. II.BegCtrlID = (WORD)pOptType->BegCtrlID;
  335. if (((II.Type = pOptType->Type) == TVOT_2STATES) ||
  336. (II.Type == TVOT_3STATES)) {
  337. II.Flags |= (_OT_FLAGS(pOptType) &
  338. (IIF_3STATES_HIDE | IIF_STDPAGE_3STATES));
  339. }
  340. } else {
  341. II.Type = TVOT_NONE;
  342. II.BegCtrlID = 0;
  343. }
  344. } else {
  345. //
  346. // Some Flags/Type/BegCtrlID and of the stuff already set in here
  347. //
  348. II = pIIHdr->ItemInfo[pIIHdr->cItem];
  349. }
  350. if (II.Flags & IIF_STDPAGE_3STATES) {
  351. II.Type = TVOT_3STATES;
  352. }
  353. CurCtrlID = II.BegCtrlID;
  354. cCtrls = (UINT)cTVOTCtrls[II.Type];
  355. II.pItem = pItem;
  356. II.CtrlBits = 0;
  357. II.xExtMove = 0;
  358. II.yExt = 0;
  359. II.yMoveUp = 0;
  360. hDlg = pIIHdr->hDlg;
  361. INIT_ADDRECT(II.rc);
  362. INIT_ADDRECT(rcExt);
  363. INIT_ADDRECT(rcVisible);
  364. INIT_ADDRECT(rcGrpBox);
  365. INIT_ADDRECT(rcVisibleNoStates);
  366. HideBits = 0;
  367. if ((II.Flags & IIF_3STATES_HIDE) &&
  368. (!(II.Flags & IIF_ITEM_HIDE))) {
  369. if (II.Flags & IIF_3STATES_1) {
  370. HideBits |= 0x0c;
  371. }
  372. if (II.Flags & IIF_3STATES_2) {
  373. HideBits |= 0x30;
  374. }
  375. if (II.Flags & IIF_3STATES_3) {
  376. HideBits |= 0xc0;
  377. }
  378. NonStatesBits = 0xff03;
  379. } else {
  380. NonStatesBits = 0;
  381. }
  382. if (II.Flags & IIF_EXT_HIDE) {
  383. ExtBits = (WORD)(3 << (cCtrls - 2));
  384. HideBits |= ExtBits;
  385. } else {
  386. ExtBits = 0;
  387. }
  388. CPSUIINT((" !! HideBits=%04lx, NonStateBits=%04lx, ExtBits=%04lx",
  389. HideBits, NonStatesBits, ExtBits));
  390. Mask = 0x0001;
  391. while (cCtrls--) {
  392. HWND hCtrl;
  393. RECT rc;
  394. //
  395. // We only count this ctrl's rectangle if it is vaild and visible
  396. //
  397. if (hCtrl = CtrlIDrcWnd(hDlg, CurCtrlID, &rc)) {
  398. CPSUIRECT(0, "AddItemInfo", &rc, cCtrls, CurCtrlID);
  399. if (Mask == 0x0001) {
  400. rcGrpBox = rc;
  401. } else {
  402. if (HideBits & Mask) {
  403. ShowWindow(hCtrl, SW_HIDE);
  404. EnableWindow(hCtrl, FALSE);
  405. } else {
  406. AddRect(&rc, &rcVisible);
  407. if (Mask & NonStatesBits) {
  408. AddRect(&rc, &rcVisibleNoStates);
  409. }
  410. }
  411. if (ExtBits & Mask) {
  412. AddRect(&rc, &rcExt);
  413. }
  414. AddRect(&rc, &II.rc);
  415. }
  416. II.CtrlBits |= Mask;
  417. }
  418. Mask <<= 1;
  419. CurCtrlID++;
  420. }
  421. II.rcCtrls = II.rc;
  422. CPSUIRECT(0, " rcGrpBox", &rcGrpBox, 0, 0);
  423. CPSUIRECT(0, " rcCtrls", &II.rcCtrls, 0, 0);
  424. CPSUIRECT(0, " rcExt", &rcExt, 0, 0);
  425. CPSUIRECT(0, "rcVisiable", &rcVisible, 0, 0);
  426. if (II.CtrlBits & 0x0001) {
  427. UINT cAdded;
  428. if ((cAdded = AddRect(&rcGrpBox, &II.rc)) != 4) {
  429. CPSUIINT(("AddRect(&rcGrp, &II.rc)=%d", cAdded));
  430. CPSUIOPTITEM(DBG_AII, pIIHdr->pTVWnd,
  431. "GroupBox too small", 1, pItem);
  432. }
  433. }
  434. if (HAS_ADDRECT(rcVisible)) {
  435. if ((II.Flags & IIF_3STATES_HIDE) &&
  436. (!(II.Flags & IIF_ITEM_HIDE))) {
  437. if (!HAS_ADDRECT(rcVisibleNoStates)) {
  438. rcVisibleNoStates.left =
  439. rcVisibleNoStates.top = 999999;
  440. rcVisibleNoStates.right =
  441. rcVisibleNoStates.bottom = -999999;
  442. }
  443. CPSUIRECT(0, "rcVisiableNoStates", &rcVisibleNoStates, 0, 0);
  444. II.yExt += (WORD)HideStates(hDlg, &II, &rcVisibleNoStates);
  445. }
  446. if (HAS_ADDRECT(rcExt)) {
  447. //
  448. // We need to move all other controls and shrink the group
  449. // box if necessary
  450. //
  451. if (II.CtrlBits & 0x0001) {
  452. if (rcExt.left > rcVisible.right) {
  453. //
  454. // The extended are at right of the ctrls, move to right
  455. //
  456. II.xExtMove = (SHORT)(rcExt.left - rcVisible.right);
  457. } else if (rcExt.right < rcVisible.left) {
  458. //
  459. // The extended are at left of the ctrls, move to left
  460. //
  461. II.xExtMove = (SHORT)(rcVisible.left - rcVisible.right);
  462. }
  463. //
  464. // distribute the move size on each side of the control
  465. //
  466. II.xExtMove /= 2;
  467. }
  468. if (rcExt.bottom > rcVisible.bottom) {
  469. //
  470. // The extended are at bottom of the ctrls, remove overlay
  471. //
  472. II.yExt += (WORD)(rcExt.bottom - rcVisible.bottom);
  473. }
  474. if (rcExt.top < rcVisible.top) {
  475. //
  476. // The extended are at top of the ctrls, remove that overlay
  477. //
  478. II.yExt += (WORD)(rcVisible.top - rcExt.top);
  479. }
  480. CPSUIINT(("!! Hide Extended(%d): xMove=%ld, yExt=%ld",
  481. II.BegCtrlID, (LONG)II.xExtMove, (LONG)II.yExt));
  482. }
  483. } else {
  484. II.Flags |= (IIF_ITEM_HIDE | IIF_EXT_HIDE);
  485. }
  486. if (pIIHdr->cItem >= pIIHdr->cMaxItem) {
  487. CPSUIERR(("AddItemInfo: Too many Items, Max=%ld", pIIHdr->cMaxItem));
  488. } else {
  489. pIIHdr->ItemInfo[pIIHdr->cItem++] = II;
  490. }
  491. }
  492. VOID
  493. HideMoveII(
  494. HWND hDlg,
  495. PITEMINFO pII
  496. )
  497. /*++
  498. Routine Description:
  499. Arguments:
  500. Return Value:
  501. Author:
  502. 11-Sep-1995 Mon 12:56:06 created -by- Daniel Chou (danielc)
  503. Revision History:
  504. --*/
  505. {
  506. ITEMINFO II = *pII;
  507. BOOL GrpBox = TRUE;
  508. if ((!(II.Flags & IIF_ITEM_HIDE)) &&
  509. (II.xExtMove == 0) &&
  510. (II.yExt == 0) &&
  511. (II.yMoveUp == 0)) {
  512. return;
  513. }
  514. CPSUIINT(("\n%hs Item: Flags=%04x, CtrlBits=%04lx, xExt=%d, yExt=%d, yMoveUp=%d",
  515. (II.Flags & IIF_ITEM_HIDE) ? "HIDE" : "MOVE",
  516. II.Flags, II.CtrlBits, II.xExtMove, II.yExt, II.yMoveUp));
  517. CPSUIRECT(DBG_HMII, "II.rcCtrls", &II.rcCtrls, II.BegCtrlID, 0);
  518. CPSUIRECT(DBG_HMII, " II.rc", &II.rc, II.BegCtrlID, 0);
  519. CPSUIOPTITEM(DBG_HMII, GET_PTVWND(hDlg), "HideMoveII", 1, II.pItem);
  520. while (II.CtrlBits) {
  521. HWND hCtrl;
  522. if ((II.CtrlBits & 0x0001) &&
  523. (hCtrl = GetDlgItem(hDlg, II.BegCtrlID))) {
  524. RECT rc;
  525. if (II.Flags & IIF_ITEM_HIDE) {
  526. ShowWindow(hCtrl, SW_HIDE);
  527. EnableWindow(hCtrl, FALSE);
  528. CPSUIINT((" HIDE Ctrls ID=%d", II.BegCtrlID));
  529. } else {
  530. hCtrlrcWnd(hDlg, hCtrl, &rc);
  531. if (GrpBox) {
  532. if ((II.yExt) || (II.yMoveUp)) {
  533. CPSUIINT(("Move GrpBox ID=%5d, Y: %ld -> %ld, cy: %ld -> %ld",
  534. II.BegCtrlID, rc.top,
  535. rc.top - II.yMoveUp, rc.bottom - rc.top,
  536. rc.bottom - rc.top - (LONG)II.yExt));
  537. SetWindowPos(hCtrl, NULL,
  538. rc.left, rc.top - II.yMoveUp,
  539. rc.right - rc.left,
  540. rc.bottom - rc.top - (LONG)II.yExt,
  541. SWP_NOZORDER);
  542. }
  543. } else if ((II.xExtMove) || (II.yMoveUp)) {
  544. //
  545. // We only need to move xExtMove if it is not group box
  546. // and also do the yMoveUp
  547. //
  548. CPSUIINT((" Move Ctrls ID=%5d, (%ld, %d) -> (%ld, %ld)",
  549. II.BegCtrlID, rc.left, rc.top,
  550. rc.left + (LONG)II.xExtMove,
  551. rc.top - (LONG)II.yMoveUp));
  552. SetWindowPos(hCtrl, NULL,
  553. rc.left + (LONG)II.xExtMove,
  554. rc.top - (LONG)II.yMoveUp,
  555. 0, 0,
  556. SWP_NOSIZE | SWP_NOZORDER);
  557. }
  558. }
  559. }
  560. GrpBox = FALSE;
  561. II.CtrlBits >>= 1;
  562. II.BegCtrlID++;
  563. }
  564. }
  565. VOID
  566. HideMoveType(
  567. HWND hDlg,
  568. UINT BegCtrlID,
  569. UINT Type
  570. )
  571. /*++
  572. Routine Description:
  573. Arguments:
  574. Return Value:
  575. Author:
  576. 19-Sep-1995 Tue 21:01:55 created -by- Daniel Chou (danielc)
  577. Revision History:
  578. --*/
  579. {
  580. ITEMINFO II;
  581. UINT cCtrls;
  582. cCtrls = (UINT)cTVOTCtrls[Type];
  583. II.Flags = IIF_ITEM_HIDE | IIF_EXT_HIDE;
  584. II.BegCtrlID = (WORD)BegCtrlID;
  585. II.CtrlBits = (WORD)(0xFFFF >> (16 - cCtrls));
  586. HideMoveII(hDlg, &II);
  587. }
  588. INT
  589. HideMovePropPage(
  590. PITEMINFOHEADER pIIHdr
  591. )
  592. /*++
  593. Routine Description:
  594. Arguments:
  595. Return Value:
  596. Author:
  597. 11-Sep-1995 Mon 01:25:53 created -by- Daniel Chou (danielc)
  598. Revision History:
  599. --*/
  600. {
  601. HWND hDlg;
  602. PITEMINFO pII;
  603. PITEMINFO pIIEnd;
  604. UINT yMoveUp;
  605. UINT yLastTop;
  606. UINT cItem;
  607. //
  608. // firstable, sort all the item based on the rc.top of each item
  609. //
  610. qsort(pII = pIIHdr->ItemInfo,
  611. cItem = (UINT)pIIHdr->cItem,
  612. sizeof(ITEMINFO),
  613. ItemInfoCompare);
  614. pIIEnd = pII + cItem;
  615. yMoveUp = 0;
  616. yLastTop = (UINT)pII->rc.top;
  617. hDlg = pIIHdr->hDlg;
  618. CPSUIDBGBLK({
  619. UINT i = cItem;
  620. PITEMINFO pIITmp = pII;
  621. CPSUIDBG(DBG_QSORT, ("qsort: cItem = %d", cItem));
  622. while (i--) {
  623. CPSUIRECT(DBG_QSORT, "QSort", &pIITmp->rc, pIITmp->BegCtrlID, 0);
  624. CPSUIOPTITEM(DBG_QSORT, pIIHdr->pTVWnd,
  625. "Sorted Item RECT", 1, pIITmp->pItem);
  626. pIITmp++;
  627. }
  628. })
  629. while (pII < pIIEnd) {
  630. PITEMINFO pIIBeg;
  631. PITEMINFO pIIBegSave;
  632. RECT rcBeg;
  633. UINT cHide;
  634. UINT cII;
  635. UINT cyCurHide;
  636. UINT yBegExt;
  637. UINT yGrpBoxShrink;
  638. UINT yGrpHideMoveUp;
  639. INT GrpBox;
  640. //
  641. // Do the group item first assume we do not need to hide the group
  642. // box, and skip the space between group box and first control, The
  643. // first group's top is the first control's top
  644. //
  645. pIIBegSave =
  646. pIIBeg = pII;
  647. rcBeg = pIIBeg->rc;
  648. cHide = 0;
  649. GrpBox = 1;
  650. //
  651. // yLastTop < 0 means the last group is totally hide and it need to
  652. // delete the space between last group end and this group begin
  653. //
  654. if (yLastTop == (UINT)0xFFFF) {
  655. yLastTop = 0;
  656. } else {
  657. yLastTop = (UINT)(rcBeg.top - yLastTop);
  658. }
  659. yGrpBoxShrink = 0;
  660. yMoveUp += yLastTop;
  661. yGrpHideMoveUp = (UINT)(yMoveUp + (rcBeg.bottom - rcBeg.top));
  662. yLastTop = rcBeg.top;
  663. do {
  664. CPSUIINT(("Item: yLastTop=%ld, yGrpBoxShrink=%d, yMoveUp=%d",
  665. yLastTop, yGrpBoxShrink, yMoveUp));
  666. if (pII->rc.bottom > rcBeg.bottom) {
  667. CPSUIOPTITEM(DBG_HMII, pIIHdr->pTVWnd, "Item Ctrls Overlay",
  668. 1, pII->pItem);
  669. CPSUIASSERT(0, "Item ctrls overlay",
  670. pII->rc.bottom <= rcBeg.bottom, LongToPtr(pII->rc.bottom));
  671. }
  672. if (pII->Flags & IIF_ITEM_HIDE) {
  673. cyCurHide = (UINT)(pII->rc.top - yLastTop);
  674. ++cHide;
  675. } else {
  676. cyCurHide = pII->yExt;
  677. pII->yMoveUp = (WORD)yMoveUp;
  678. }
  679. yGrpBoxShrink += cyCurHide;
  680. yMoveUp += cyCurHide;
  681. yLastTop = (GrpBox-- > 0) ? pII->rcCtrls.top : pII->rc.top;
  682. } while ((++pII < pIIEnd) && (pII->rc.top < rcBeg.bottom));
  683. CPSUIINT(("FINAL: yLastTop=%ld, yGrpBoxShrink=%d, yMoveUp=%d",
  684. yLastTop, yGrpBoxShrink, yMoveUp));
  685. //
  686. // Now check if we have same hide item
  687. //
  688. if (cHide == (cII = (UINT)(pII - pIIBeg))) {
  689. //
  690. // Hide them all and add in the extra yMoveUp for the the space
  691. // between group box and the first control which we reduced out
  692. // front.
  693. //
  694. yMoveUp = yGrpHideMoveUp;
  695. yLastTop = rcBeg.bottom;
  696. CPSUIINT(("Hide ALL items = %d, yMoveUp Change to %ld",
  697. cHide, yMoveUp));
  698. while (cHide--) {
  699. HideMoveII(hDlg, pIIBegSave++);
  700. }
  701. } else {
  702. CPSUIINT(("!! Grpup Items cII=%d !!", cII));
  703. //
  704. // We need to enable the group box and shrink it too
  705. //
  706. if (pIIBeg->Flags & IIF_ITEM_HIDE) {
  707. pIIBeg->yExt += (WORD)yGrpBoxShrink;
  708. pIIBeg->Flags &= ~IIF_ITEM_HIDE;
  709. pIIBeg->CtrlBits &= 0x01;
  710. } else {
  711. pIIBeg->yExt = (WORD)yGrpBoxShrink;
  712. }
  713. while (cII--) {
  714. HideMoveII(hDlg, pIIBegSave++);
  715. }
  716. yLastTop = 0xFFFF;
  717. }
  718. }
  719. return(yMoveUp);
  720. }
  721. LONG
  722. UpdatePropPageItem(
  723. HWND hDlg,
  724. PTVWND pTVWnd,
  725. POPTITEM pItem,
  726. BOOL DoInit
  727. )
  728. /*++
  729. Routine Description:
  730. Arguments:
  731. Return Value:
  732. Author:
  733. 31-Aug-1995 Thu 23:53:44 created -by- Daniel Chou (danielc)
  734. Revision History:
  735. --*/
  736. {
  737. HWND hCtrl;
  738. POPTTYPE pOptType;
  739. POPTPARAM pOptParam;
  740. LONG Sel;
  741. UINT Type;
  742. UINT BegCtrlID;
  743. UINT SetCurSelID;
  744. UINT cSetIcon;
  745. UINT ExtID;
  746. UINT UDArrowHelpID = 0;
  747. LONG Result = 1;
  748. WORD InitItemIdx;
  749. WORD InitFlags;
  750. BYTE CtrlData = 0;
  751. BOOL CanUpdate;
  752. InitItemIdx = (WORD)(pItem - pTVWnd->ComPropSheetUI.pOptItem);
  753. pOptType = pItem->pOptType;
  754. pOptParam = pOptType->pOptParam;
  755. BegCtrlID = (UINT)pOptType->BegCtrlID;
  756. Sel = pItem->Sel;
  757. Type = (UINT)pOptType->Type;
  758. //
  759. // If we have push button, and it said we always can call it then update
  760. // is true
  761. //
  762. if ((Type == TVOT_PUSHBUTTON) &&
  763. (pOptType->Flags & OTS_PUSH_ENABLE_ALWAYS)) {
  764. CanUpdate = TRUE;
  765. } else {
  766. CanUpdate = (BOOL)(pTVWnd->Flags & TWF_CAN_UPDATE);
  767. }
  768. if ((pItem->Flags & OPTIF_DISABLED) || (!CanUpdate)) {
  769. InitFlags = 0;
  770. } else {
  771. InitFlags = INITCF_ENABLE;
  772. }
  773. if (DoInit) {
  774. InitFlags |= (INITCF_INIT | INITCF_SETCTRLDATA);
  775. for (cSetIcon = 0; cSetIcon < (UINT)cTVOTCtrls[Type]; cSetIcon++) {
  776. if (hCtrl = GetDlgItem(hDlg, BegCtrlID++)) {
  777. //
  778. // This prevent to overwrite GWLP_USERDATA for the WNDPROC
  779. // saved for the hEdit
  780. //
  781. SETCTRLDATA(hCtrl, CTRLS_PROPPAGE_STATIC, (BYTE)cSetIcon);
  782. CPSUIINT(("SETCTRLDATA: %ld, hCtrl=%08lx, USER_DATA=%p",
  783. BegCtrlID - 1, hCtrl,
  784. GetWindowLongPtr(hCtrl, GWLP_USERDATA)));
  785. }
  786. }
  787. BegCtrlID = (UINT)pOptType->BegCtrlID;
  788. }
  789. //
  790. // We always set at least one icon
  791. //
  792. cSetIcon = 1;
  793. ExtID = (UINT)(BegCtrlID + cTVOTCtrls[Type] - 2);
  794. INIT_EXTENDED(pTVWnd,
  795. hDlg,
  796. pItem,
  797. ExtID,
  798. ExtID,
  799. ExtID + 1,
  800. InitItemIdx,
  801. InitFlags);
  802. if (pOptType->Flags & OPTTF_TYPE_DISABLED) {
  803. InitFlags &= ~INITCF_ENABLE;
  804. }
  805. switch(Type) {
  806. case TVOT_3STATES:
  807. case TVOT_2STATES:
  808. //
  809. // If this internal flag is set then this is a standard page which
  810. // always has a 3 states contrl ID but the caller's POPTTYPE only
  811. // presendt as TVOT_2STATES
  812. //
  813. if (_OT_FLAGS(pOptType) & OTINTF_STDPAGE_3STATES) {
  814. ExtID = (UINT)(BegCtrlID + cTVOTCtrls[TVOT_3STATES] - 2);
  815. }
  816. InitStates(pTVWnd,
  817. hDlg,
  818. pItem,
  819. pOptType,
  820. BegCtrlID + 2,
  821. InitItemIdx,
  822. (LONG)Sel,
  823. InitFlags);
  824. if (InitFlags & INITCF_INIT) {
  825. cSetIcon = pOptType->Count;
  826. CtrlData = 0;
  827. } else {
  828. CtrlData = (BYTE)Sel;
  829. pOptParam += Sel;
  830. BegCtrlID += (Sel << 1);
  831. }
  832. InitFlags |= INITCF_ICON_NOTIFY;
  833. break;
  834. case TVOT_UDARROW:
  835. if ((Result = InitUDArrow(pTVWnd,
  836. hDlg,
  837. pItem,
  838. pOptParam,
  839. BegCtrlID + 6,
  840. BegCtrlID + 2,
  841. BegCtrlID + 4,
  842. UDArrowHelpID = BegCtrlID + 5,
  843. InitItemIdx,
  844. Sel,
  845. InitFlags)) < 0) {
  846. return(Result);
  847. }
  848. break;
  849. case TVOT_TRACKBAR:
  850. case TVOT_SCROLLBAR:
  851. InitFlags |= INITCF_ADDSELPOSTFIX;
  852. hCtrl = GetDlgItem(hDlg, BegCtrlID + 2);
  853. if (Type == TVOT_TRACKBAR) {
  854. hCtrl = GetWindow(hCtrl, GW_HWNDNEXT);
  855. }
  856. InitTBSB(pTVWnd,
  857. hDlg,
  858. pItem,
  859. hCtrl,
  860. pOptType,
  861. BegCtrlID + 6,
  862. BegCtrlID + 4,
  863. BegCtrlID + 5,
  864. InitItemIdx,
  865. Sel,
  866. InitFlags);
  867. break;
  868. case TVOT_LISTBOX:
  869. case TVOT_COMBOBOX:
  870. SetCurSelID = LB_SETCURSEL;
  871. if (Type == TVOT_LISTBOX) {
  872. if (pOptType->Style & OTS_LBCB_PROPPAGE_LBUSECB) {
  873. SetCurSelID = CB_SETCURSEL;
  874. }
  875. } else if (!(pOptType->Style & OTS_LBCB_PROPPAGE_CBUSELB)) {
  876. SetCurSelID = CB_SETCURSEL;
  877. }
  878. //
  879. // Always need to set this new state icon
  880. //
  881. if ((DWORD)pItem->Sel >= (DWORD)pOptType->Count) {
  882. pOptParam = &pTVWnd->OptParamNone;
  883. } else {
  884. pOptParam += (DWORD)pItem->Sel;
  885. }
  886. if (hCtrl = GetDlgItem(hDlg, BegCtrlID + 2)) {
  887. InvalidateRect(hCtrl, NULL, FALSE);
  888. }
  889. InitLBCB(pTVWnd,
  890. hDlg,
  891. pItem,
  892. BegCtrlID + 2,
  893. SetCurSelID,
  894. pOptType,
  895. InitItemIdx,
  896. Sel,
  897. InitFlags,
  898. (UINT)_OT_ORGLBCBCY(pOptType));
  899. break;
  900. case TVOT_EDITBOX:
  901. InitEditBox(pTVWnd,
  902. hDlg,
  903. pItem,
  904. pOptParam,
  905. BegCtrlID + 2,
  906. BegCtrlID + 4,
  907. BegCtrlID + 5,
  908. InitItemIdx,
  909. (LPTSTR)(LONG_PTR)Sel,
  910. InitFlags);
  911. break;
  912. case TVOT_PUSHBUTTON:
  913. InitPushButton(pTVWnd,
  914. hDlg,
  915. pItem,
  916. (WORD)(BegCtrlID + 2),
  917. InitItemIdx,
  918. InitFlags);
  919. break;
  920. case TVOT_CHKBOX:
  921. InitFlags |= INITCF_ICON_NOTIFY;
  922. InitChkBox(pTVWnd,
  923. hDlg,
  924. pItem,
  925. BegCtrlID + 2,
  926. pItem->pName,
  927. InitItemIdx,
  928. (BOOL)Sel,
  929. InitFlags);
  930. break;
  931. default:
  932. return(ERR_CPSUI_INVALID_TVOT_TYPE);
  933. }
  934. if (InitFlags & (INITCF_INIT | INITCF_ADDSELPOSTFIX)) {
  935. SetDlgPageItemName(hDlg, pTVWnd, pItem, InitFlags, UDArrowHelpID);
  936. }
  937. if (cSetIcon) {
  938. UINT i;
  939. for (i = 0, BegCtrlID += 3;
  940. i < cSetIcon;
  941. i++, pOptParam++, CtrlData++, BegCtrlID += 2) {
  942. if (hCtrl = GetDlgItem(hDlg, BegCtrlID)) {
  943. WORD IconMode = 0;
  944. if ((pItem->Flags & OPTIF_OVERLAY_WARNING_ICON) ||
  945. (pOptParam->Flags & OPTPF_OVERLAY_WARNING_ICON)) {
  946. IconMode |= MIM_WARNING_OVERLAY;
  947. }
  948. if ((pItem->Flags & (OPTIF_OVERLAY_STOP_ICON | OPTIF_HIDE)) ||
  949. (pOptParam->Flags & OPTPF_OVERLAY_STOP_ICON)) {
  950. IconMode |= MIM_STOP_OVERLAY;
  951. }
  952. if ((pItem->Flags & (OPTIF_OVERLAY_NO_ICON)) ||
  953. (pOptParam->Flags & OPTPF_OVERLAY_NO_ICON)) {
  954. IconMode |= MIM_NO_OVERLAY;
  955. }
  956. SetIcon(_OI_HINST(pItem),
  957. hCtrl,
  958. GET_ICONID(pOptParam, OPTPF_ICONID_AS_HICON),
  959. MK_INTICONID(IDI_CPSUI_GENERIC_ITEM, IconMode),
  960. 32);
  961. if (InitFlags & INITCF_INIT) {
  962. HCTRL_SETCTRLDATA(hCtrl, CTRLS_PROPPAGE_ICON, CtrlData);
  963. }
  964. if (InitFlags & INITCF_ICON_NOTIFY) {
  965. DWORD dw = (DWORD)GetWindowLongPtr(hCtrl, GWL_STYLE);
  966. if (pOptParam->Flags & (OPTPF_DISABLED | OPTPF_HIDE)) {
  967. dw &= ~SS_NOTIFY;
  968. } else {
  969. dw |= SS_NOTIFY;
  970. }
  971. SetWindowLongPtr(hCtrl, GWL_STYLE, (LONG)dw);
  972. }
  973. }
  974. }
  975. }
  976. return(Result);
  977. }
  978. LONG
  979. InitPropPage(
  980. HWND hDlg,
  981. PMYDLGPAGE pCurMyDP
  982. )
  983. /*++
  984. Routine Description:
  985. Arguments:
  986. Return Value:
  987. Author:
  988. 14-Jun-1995 Wed 15:30:28 created -by- Daniel Chou (danielc)
  989. Revision History:
  990. --*/
  991. {
  992. PITEMINFOHEADER pIIHdr = NULL;
  993. PSTDPAGEINFO pSPI;
  994. PTVWND pTVWnd;
  995. POPTITEM pItem;
  996. POPTITEM pLastItem;
  997. LONG Result;
  998. WORD StdPageHide[DMPUB_LAST];
  999. BYTE CurPageIdx;
  1000. UINT i;
  1001. UINT BegCtrlID;
  1002. UINT Type;
  1003. UINT cStdPageHide = 0;
  1004. UINT cStatesHide = 0;
  1005. UINT cItem;
  1006. UINT cHide;
  1007. pTVWnd = (PTVWND)pCurMyDP->pTVWnd;
  1008. CurPageIdx = pCurMyDP->PageIdx;
  1009. pItem = pTVWnd->ComPropSheetUI.pOptItem;
  1010. pLastItem = pTVWnd->pLastItem;
  1011. cItem = (UINT)pCurMyDP->cItem;
  1012. cHide = (UINT)pCurMyDP->cHide;
  1013. if ((CurPageIdx == pTVWnd->StdPageIdx1) ||
  1014. (CurPageIdx == pTVWnd->StdPageIdx2)) {
  1015. //
  1016. // Check if any our standard pages' controls are not present in the
  1017. // pOptItem
  1018. //
  1019. for (i = 0, pSPI = StdPageInfo; i < DMPUB_LAST; i++, pSPI++) {
  1020. POPTITEM pDMPubItem;
  1021. POPTTYPE pOptType;
  1022. WORD Idx;
  1023. if ((pSPI->StdPageID == CurPageIdx) &&
  1024. (pSPI->BegCtrlID)) {
  1025. if ((Idx = pTVWnd->DMPubIdx[i]) == 0xFFFF) {
  1026. ++cStdPageHide;
  1027. } else {
  1028. pDMPubItem = pItem + Idx;
  1029. pOptType = pDMPubItem->pOptType;
  1030. switch (pOptType->Type) {
  1031. case TVOT_2STATES:
  1032. case TVOT_3STATES:
  1033. if (_OT_FLAGS(pOptType) & OTINTF_STATES_HIDE_MASK) {
  1034. ++cStatesHide;
  1035. }
  1036. break;
  1037. default:
  1038. break;
  1039. }
  1040. }
  1041. }
  1042. }
  1043. }
  1044. CPSUIDBG(DBG_INITP1,
  1045. ("InitPropPage: PageIdx=%d, cItem=%d, cHide=%d, cStdPageHide=% (%d)",
  1046. CurPageIdx, cItem, cHide, cStdPageHide, cStatesHide));
  1047. if ((cHide += cStdPageHide) || (cStatesHide)) {
  1048. //
  1049. // Some item in this page may have to hide
  1050. //
  1051. i = (UINT)(((cItem + cStdPageHide + cStatesHide) * sizeof(ITEMINFO)) +
  1052. sizeof(ITEMINFOHEADER));
  1053. CPSUIINT(("Total ItemInfo allocated=%d, cb=%d", cItem+cStdPageHide, i));
  1054. if (pIIHdr = LocalAlloc(LPTR, i)) {
  1055. pIIHdr->hDlg = hDlg;
  1056. pIIHdr->pTVWnd = pTVWnd;
  1057. pIIHdr->cItem = 0;
  1058. pIIHdr->cMaxItem = (WORD)(cItem + cStdPageHide);
  1059. //
  1060. // Stop redraw everything
  1061. //
  1062. SendMessage(hDlg, WM_SETREDRAW, (WPARAM)FALSE, 0L);
  1063. } else {
  1064. CPSUIERR(("LocalAlloc(pIIHdr(%u)) failed, cannot move items", i));
  1065. }
  1066. }
  1067. while (pItem <= pLastItem) {
  1068. BYTE CurLevel = pItem->Level;
  1069. if (pItem->DlgPageIdx != CurPageIdx) {
  1070. SKIP_CHILDREN(pItem, pLastItem, CurLevel);
  1071. continue;
  1072. }
  1073. do {
  1074. POPTTYPE pOptType;
  1075. if (pOptType = pItem->pOptType) {
  1076. DWORD cySize;
  1077. --cItem;
  1078. BegCtrlID = (UINT)pOptType->BegCtrlID;
  1079. Type = (UINT)pOptType->Type;
  1080. if (pItem->Flags & OPTIF_ITEM_HIDE) {
  1081. --cHide;
  1082. if (!pIIHdr) {
  1083. HideMoveType(hDlg, BegCtrlID, Type);
  1084. }
  1085. } else {
  1086. CPSUIOPTITEM(DBGITEM_INITP1, pTVWnd, "InitP1", 2, pItem);
  1087. //
  1088. // Checking anything need to done for the internal item
  1089. //
  1090. switch (Type) {
  1091. case TVOT_LISTBOX:
  1092. cySize = ReCreateLBCB(hDlg,
  1093. BegCtrlID + 2,
  1094. !(BOOL)(pOptType->Style &
  1095. OTS_LBCB_PROPPAGE_LBUSECB));
  1096. _OT_ORGLBCBCY(pOptType) = HIWORD(cySize);
  1097. break;
  1098. case TVOT_COMBOBOX:
  1099. cySize = ReCreateLBCB(hDlg,
  1100. BegCtrlID + 2,
  1101. (BOOL)(pOptType->Style &
  1102. OTS_LBCB_PROPPAGE_CBUSELB));
  1103. _OT_ORGLBCBCY(pOptType) = HIWORD(cySize);
  1104. break;
  1105. case TVOT_TRACKBAR:
  1106. if (!CreateTrackBar(hDlg, BegCtrlID + 2)) {
  1107. if (pIIHdr) {
  1108. LocalFree((HLOCAL)pIIHdr);
  1109. }
  1110. return(ERR_CPSUI_CREATE_TRACKBAR_FAILED);
  1111. }
  1112. break;
  1113. case TVOT_UDARROW:
  1114. if (!CreateUDArrow(hDlg,
  1115. BegCtrlID + 2,
  1116. BegCtrlID + 6,
  1117. (LONG)pOptType->pOptParam[1].IconID,
  1118. (LONG)pOptType->pOptParam[1].lParam,
  1119. (LONG)pItem->Sel)) {
  1120. if (pIIHdr) {
  1121. LocalFree((HLOCAL)pIIHdr);
  1122. }
  1123. return(ERR_CPSUI_CREATE_UDARROW_FAILED);
  1124. }
  1125. break;
  1126. }
  1127. if ((Result = UpdatePropPageItem(hDlg,
  1128. pTVWnd,
  1129. pItem,
  1130. TRUE)) < 0) {
  1131. if (pIIHdr) {
  1132. LocalFree((HLOCAL)pIIHdr);
  1133. }
  1134. return(Result);
  1135. }
  1136. }
  1137. if (pIIHdr) {
  1138. //
  1139. // Add the item info header
  1140. //
  1141. AddItemInfo(pIIHdr, pItem);
  1142. }
  1143. }
  1144. } WHILE_SKIP_CHILDREN(pItem, pLastItem, CurLevel);
  1145. }
  1146. CPSUIASSERT(0, "Error: mismatch visable items=%d", cItem == 0, UIntToPtr(cItem));
  1147. if (cStdPageHide) {
  1148. PITEMINFO pII;
  1149. if (pIIHdr) {
  1150. pII = &(pIIHdr->ItemInfo[pIIHdr->cItem]);
  1151. CPSUIINT(("cItem in ItemInfoHdr=%d", (UINT)pIIHdr->cItem));
  1152. }
  1153. for (i = 0, pSPI = StdPageInfo; i < DMPUB_LAST; i++, pSPI++) {
  1154. if ((BegCtrlID = (UINT)pSPI->BegCtrlID) &&
  1155. (pSPI->StdPageID == CurPageIdx) &&
  1156. (pTVWnd->DMPubIdx[i] == 0xFFFF)) {
  1157. Type = (UINT)StdTVOT[pSPI->iStdTVOT + pSPI->cStdTVOT - 1];
  1158. if (pIIHdr) {
  1159. CPSUIINT(("Add Extra DMPUB ID=%d, BegCtrID=%d ITEMINFO",
  1160. i, BegCtrlID));
  1161. pII->Flags = IIF_ITEM_HIDE | IIF_EXT_HIDE ;
  1162. pII->Type = (BYTE)Type;
  1163. pII->BegCtrlID = (WORD)BegCtrlID;
  1164. AddItemInfo(pIIHdr, NULL);
  1165. pII++;
  1166. } else {
  1167. HideMoveType(hDlg, BegCtrlID, Type);
  1168. }
  1169. --cHide;
  1170. }
  1171. }
  1172. }
  1173. if ((cStdPageHide) || (cStatesHide)) {
  1174. //
  1175. // Now hide/move all page's item
  1176. //
  1177. if (pIIHdr) {
  1178. HideMovePropPage(pIIHdr);
  1179. }
  1180. SendMessage(hDlg, WM_SETREDRAW, (WPARAM)TRUE, 0L);
  1181. InvalidateRect(hDlg, NULL, FALSE);
  1182. }
  1183. if (pIIHdr) {
  1184. LocalFree((HLOCAL)pIIHdr);
  1185. }
  1186. CPSUIASSERT(0, "Error: mismatch hide items=%d", cHide == 0, UIntToPtr(cHide));
  1187. return(pCurMyDP->cItem);
  1188. }
  1189. LONG
  1190. UpdatePropPage(
  1191. HWND hDlg,
  1192. PMYDLGPAGE pCurMyDP
  1193. )
  1194. /*++
  1195. Routine Description:
  1196. Arguments:
  1197. Return Value:
  1198. Author:
  1199. 08-Aug-1995 Tue 15:37:16 created -by- Daniel Chou (danielc)
  1200. Revision History:
  1201. --*/
  1202. {
  1203. INT cUpdated = 0;
  1204. if (pCurMyDP->Flags & (MYDPF_CHANGED | MYDPF_REINIT)) {
  1205. PTVWND pTVWnd;
  1206. POPTITEM pItem;
  1207. UINT cItem;
  1208. BYTE CurPageIdx;
  1209. BOOL ReInit;
  1210. pTVWnd = (PTVWND)pCurMyDP->pTVWnd;
  1211. CurPageIdx = (BYTE)pCurMyDP->PageIdx;
  1212. pItem = pTVWnd->ComPropSheetUI.pOptItem;
  1213. cItem = (UINT)pTVWnd->ComPropSheetUI.cOptItem;
  1214. ReInit = (BOOL)(pCurMyDP->Flags & MYDPF_REINIT);
  1215. CPSUIDBG(DBGITEM_UP1, ("UpdatePropPage Flags (OPTIDX_INT_CHANGED)"));
  1216. while (cItem--) {
  1217. if ((pItem->pOptType) &&
  1218. (pItem->DlgPageIdx == CurPageIdx) &&
  1219. (pItem->Flags & OPTIF_INT_CHANGED)) {
  1220. CPSUIOPTITEM(DBGITEM_UP1, pTVWnd, "UpdatePage1", 1, pItem);
  1221. UpdatePropPageItem(hDlg, pTVWnd, pItem, ReInit);
  1222. pItem->Flags &= ~OPTIF_INT_CHANGED;
  1223. ++cUpdated;
  1224. }
  1225. pItem++;
  1226. }
  1227. pCurMyDP->Flags &= ~(MYDPF_CHANGED | MYDPF_REINIT);
  1228. }
  1229. return((LONG)cUpdated);
  1230. }
  1231. LONG
  1232. CountPropPageItems(
  1233. PTVWND pTVWnd,
  1234. BYTE CurPageIdx
  1235. )
  1236. /*++
  1237. Routine Description:
  1238. Arguments:
  1239. Return Value:
  1240. Author:
  1241. 22-Aug-1995 Tue 14:34:01 created -by- Daniel Chou (danielc)
  1242. Revision History:
  1243. --*/
  1244. {
  1245. PMYDLGPAGE pCurMyDP;
  1246. POPTITEM pItem;
  1247. POPTITEM pLastItem;
  1248. BOOL IsTVPage;
  1249. UINT cHideItems = 0;
  1250. UINT cPageItems = 0;
  1251. if (CurPageIdx >= pTVWnd->cMyDlgPage) {
  1252. return(0);
  1253. }
  1254. pItem = pTVWnd->ComPropSheetUI.pOptItem;
  1255. pLastItem = pTVWnd->pLastItem;
  1256. if (pTVWnd->Flags & TWF_HAS_ADVANCED_PUSH) {
  1257. IsTVPage = FALSE;
  1258. } else {
  1259. IsTVPage = (BOOL)(pTVWnd->TVPageIdx == CurPageIdx);
  1260. }
  1261. while (pItem <= pLastItem) {
  1262. if (IsTVPage) {
  1263. ++cPageItems;
  1264. if (pItem->Flags & OPTIF_ITEM_HIDE) {
  1265. ++cHideItems;
  1266. }
  1267. } else if (pItem->DlgPageIdx == CurPageIdx) {
  1268. cPageItems++;
  1269. if (pItem->Flags & OPTIF_ITEM_HIDE) {
  1270. ++cHideItems;
  1271. }
  1272. }
  1273. pItem++;
  1274. }
  1275. pCurMyDP = pTVWnd->pMyDlgPage + CurPageIdx;
  1276. pCurMyDP->cItem = (WORD)cPageItems;
  1277. pCurMyDP->cHide = (WORD)cHideItems;
  1278. CPSUIINT(("PageIdx=%ld, cItem=%ld, cHide=%ld",
  1279. CurPageIdx, cPageItems, cHideItems));
  1280. return((LONG)(cPageItems - cHideItems));
  1281. }
  1282. BOOL
  1283. CALLBACK
  1284. ChildWndCleanUp(
  1285. HWND hWnd,
  1286. LPARAM lParam
  1287. )
  1288. {
  1289. UNREFERENCED_PARAMETER(lParam);
  1290. if ((SendMessage(hWnd, WM_GETDLGCODE, 0, 0) & DLGC_STATIC) &&
  1291. ((GetWindowLongPtr(hWnd, GWL_STYLE) & SS_TYPEMASK) == SS_ICON)) {
  1292. HICON hIcon;
  1293. if (hIcon = (HICON)SendMessage(hWnd, STM_SETICON, 0, 0L)) {
  1294. DestroyIcon(hIcon);
  1295. }
  1296. CPSUIINT(("ChildWndCleanUp: Static ID=%u, Icon=%08lx",
  1297. GetDlgCtrlID(hWnd), hIcon));
  1298. }
  1299. return(TRUE);
  1300. }
  1301. BOOL
  1302. CALLBACK
  1303. FixIconChildTo32x32(
  1304. HWND hWnd,
  1305. LPARAM lParam
  1306. )
  1307. {
  1308. HWND hDlg = (HWND)lParam;
  1309. if ((SendMessage(hWnd, WM_GETDLGCODE, 0, 0) & DLGC_STATIC) &&
  1310. ((GetWindowLongPtr(hWnd, GWL_STYLE) & SS_TYPEMASK) == SS_ICON)) {
  1311. RECT rc;
  1312. hCtrlrcWnd(hDlg, hWnd, &rc);
  1313. if (((rc.right - rc.left) != 32) ||
  1314. ((rc.bottom - rc.top) != 32)) {
  1315. CPSUIINT(("FixIcon32x32: Icon ID=%u, size=%ld x %ld, fix to 32x32",
  1316. GetDlgCtrlID(hWnd),
  1317. rc.right - rc.left, rc.bottom - rc.top));
  1318. SetWindowPos(hWnd, NULL, 0, 0, 32, 32, SWP_NOMOVE | SWP_NOZORDER);
  1319. }
  1320. }
  1321. return(TRUE);
  1322. }
  1323. VOID
  1324. MoveAdvancedPush(
  1325. HWND hDlg,
  1326. UINT EnlargeCtrlID,
  1327. UINT CenterCtrlID
  1328. )
  1329. /*++
  1330. Routine Description:
  1331. Arguments:
  1332. Return Value:
  1333. Author:
  1334. 25-Aug-1998 Tue 10:30:55 created -by- Daniel Chou (danielc)
  1335. Revision History:
  1336. --*/
  1337. {
  1338. HWND hTabCtrl;
  1339. HWND hCtrl;
  1340. RECT rcAdvPush;
  1341. RECT rcDlg;
  1342. POINTL ptl;
  1343. if ((hTabCtrl = PropSheet_GetTabControl(GetParent(hDlg))) &&
  1344. (hCtrl = GetDlgItem(hDlg, ADVANCED_PUSH))) {
  1345. GetWindowRect(hDlg, &rcDlg);
  1346. CPSUIDBG(DBG_ADVPUSH, ("Prop Page Rect (before adjust)=(%ld, %ld) - (%ld, %ld)",
  1347. rcDlg.left, rcDlg.top, rcDlg.right, rcDlg.bottom));
  1348. TabCtrl_AdjustRect(hTabCtrl, FALSE, &rcDlg);
  1349. CPSUIDBG(DBG_ADVPUSH, ("Prop Page Rect (after adjust)=(%ld, %ld) - (%ld, %ld)",
  1350. rcDlg.left, rcDlg.top, rcDlg.right, rcDlg.bottom));
  1351. GetWindowRect(hCtrl, &rcAdvPush);
  1352. CPSUIDBG(DBG_ADVPUSH, ("Advanced Btn Rect=(%ld, %ld) - (%ld, %ld)",
  1353. rcAdvPush.left, rcAdvPush.top, rcAdvPush.right, rcAdvPush.bottom));
  1354. ptl.y = rcDlg.bottom - (rcAdvPush.bottom - rcAdvPush.top);
  1355. CPSUIDBG(DBG_ADVPUSH, ("AdvPush cy=%ld, Move Y from %ld to %ld",
  1356. rcAdvPush.bottom - rcAdvPush.top, rcAdvPush.top, ptl.y));
  1357. MapWindowPoints(NULL, hDlg, (LPPOINT)&rcAdvPush, 2);
  1358. ScreenToClient(hDlg, (LPPOINT)&ptl);
  1359. ptl.x = rcAdvPush.left;
  1360. CPSUIDBG(DBG_ADVPUSH, ("New Push left/top in CLIENT top=%ld, Add=%ld",
  1361. ptl.y, ptl.y - rcAdvPush.top));
  1362. if (rcAdvPush.top != ptl.y) {
  1363. CPSUIDBG(DBG_ADVPUSH, ("Advance Push top change from %ld to %ld",
  1364. rcAdvPush.top, ptl.y));
  1365. SetWindowPos(hCtrl,
  1366. NULL,
  1367. ptl.x, ptl.y,
  1368. 0, 0,
  1369. SWP_NOSIZE | SWP_NOZORDER);
  1370. ptl.y -= rcAdvPush.top;
  1371. if (hCtrl = CtrlIDrcWnd(hDlg, EnlargeCtrlID, &rcDlg)) {
  1372. SetWindowPos(hCtrl,
  1373. NULL,
  1374. 0, 0,
  1375. rcDlg.right - rcDlg.left,
  1376. rcDlg.bottom - rcDlg.top + ptl.y,
  1377. SWP_NOMOVE | SWP_NOZORDER);
  1378. }
  1379. if (hCtrl = CtrlIDrcWnd(hDlg, CenterCtrlID, &rcDlg)) {
  1380. SetWindowPos(hCtrl,
  1381. NULL,
  1382. rcDlg.left,
  1383. rcDlg.top + (ptl.y / 2),
  1384. 0, 0,
  1385. SWP_NOSIZE | SWP_NOZORDER);
  1386. }
  1387. }
  1388. }
  1389. }
  1390. INT_PTR
  1391. CALLBACK
  1392. PropPageProc(
  1393. HWND hDlg,
  1394. UINT Msg,
  1395. WPARAM wParam,
  1396. LPARAM lParam
  1397. )
  1398. /*++
  1399. Routine Description:
  1400. Arguments:
  1401. Return Value:
  1402. Author:
  1403. 28-Aug-1995 Mon 16:13:10 created -by- Daniel Chou (danielc)
  1404. Revision History:
  1405. --*/
  1406. {
  1407. #define pNMHdr ((NMHDR *)lParam)
  1408. HWND hWndFocus;
  1409. HWND hCtrl;
  1410. PMYDLGPAGE pCurMyDP;
  1411. PTVWND pTVWnd;
  1412. POPTITEM pItem;
  1413. LONG MResult;
  1414. PLAYOUTBMP pData;
  1415. PCPSUIPAGE pPage;
  1416. if (Msg == WM_INITDIALOG) {
  1417. CPSUIINT(("PropPage WM_INITDIALOG: hDlg=%08lx, pPSP=%08lx", hDlg, lParam));
  1418. pCurMyDP = (PMYDLGPAGE)(((LPPROPSHEETPAGE)lParam)->lParam);
  1419. pTVWnd = (PTVWND)pCurMyDP->pTVWnd;
  1420. pCurMyDP->pPSPInfo = PPSPINFO_FROM_WM_INITDIALOG_LPARAM(lParam);
  1421. if (!ADD_PMYDLGPAGE(hDlg, pCurMyDP)) {
  1422. return(FALSE);
  1423. }
  1424. CreateImageList(hDlg, pTVWnd);
  1425. if ((MResult = InitPropPage(hDlg, pCurMyDP)) < 0) {
  1426. CPSUIERR(("InitProPage()=%ld, FAILED", MResult));
  1427. }
  1428. SetUniqChildID(hDlg);
  1429. UpdateCallBackChanges(hDlg, pTVWnd, TRUE);
  1430. EnumChildWindows(hDlg, FixIconChildTo32x32, (LPARAM)hDlg);
  1431. SetFocus((HWND)wParam);
  1432. MResult = TRUE;
  1433. ((LPPROPSHEETPAGE)lParam)->lParam = pCurMyDP->CPSUIUserData;
  1434. if ((pTVWnd->Flags & TWF_HAS_ADVANCED_PUSH) &&
  1435. (hCtrl = GetDlgItem(hDlg, ADVANCED_PUSH))) {
  1436. if (CountPropPageItems(pTVWnd, (BYTE)(pTVWnd->cMyDlgPage - 1))) {
  1437. WORD InitItemIdx = INTIDX_ADVANCED;
  1438. SETCTRLDATA(hCtrl, CTRLS_PUSHBUTTON, 0);
  1439. } else {
  1440. ShowWindow(hCtrl, SW_HIDE);
  1441. }
  1442. }
  1443. }
  1444. if (pCurMyDP = GET_PMYDLGPAGE(hDlg)) {
  1445. pTVWnd = (PTVWND)pCurMyDP->pTVWnd;
  1446. if (pTVWnd) {
  1447. if (pCurMyDP->DlgPage.DlgProc) {
  1448. //
  1449. // Passed the caller's original CPSUIUserData which is the UserData
  1450. // in the COMPROPSHEETUI data structure
  1451. //
  1452. MResult = (LONG)pCurMyDP->DlgPage.DlgProc(hDlg, Msg, wParam, lParam);
  1453. if (MResult) {
  1454. return(TRUE);
  1455. }
  1456. }
  1457. if (Msg == WM_INITDIALOG) {
  1458. if ((pCurMyDP->PageIdx != pTVWnd->StdPageIdx1) ||
  1459. (!(hCtrl = GetDlgItem(hDlg, IDD_LAYOUT_PICTURE)))) {
  1460. hCtrl = NULL;
  1461. }
  1462. MoveAdvancedPush(hDlg,
  1463. IDD_LAYOUT_PICTURE_GROUP,
  1464. IDD_LAYOUT_PICTURE);
  1465. if ((hCtrl) &&
  1466. (pData = InitLayoutBmp(hDlg, hCtrl, pTVWnd))) {
  1467. SetProp(hCtrl, CPSUIPROP_LAYOUTPUSH, (HANDLE)pData);
  1468. }
  1469. return((BOOL)MResult);
  1470. }
  1471. } else {
  1472. return(FALSE);
  1473. }
  1474. } else {
  1475. return(FALSE);
  1476. }
  1477. //
  1478. // Check if which one got the keyboard focus, if it is not the same as
  1479. // the one recored then send out the Focus message
  1480. //
  1481. if ((pCurMyDP->Flags & MYDPF_PAGE_ACTIVE) &&
  1482. (hWndFocus = GetFocus()) &&
  1483. (hWndFocus != pCurMyDP->hWndFocus) &&
  1484. (pItem = pItemFromhWnd(hDlg, pTVWnd, hWndFocus, -1)) &&
  1485. (pItem != pCurMyDP->pCurItem)) {
  1486. pCurMyDP->hWndFocus = hWndFocus;
  1487. pCurMyDP->pCurItem = pItem;
  1488. CPSUIOPTITEM(DBG_SETFOCUS, pTVWnd,
  1489. "PropPage: Keyboard Focus Changed", 0, pItem);
  1490. if ((pItem->Flags & OPTIF_CALLBACK) &&
  1491. (pTVWnd->ComPropSheetUI.pfnCallBack) &&
  1492. (pItem >= pTVWnd->ComPropSheetUI.pOptItem) &&
  1493. (pItem <= pTVWnd->pLastItem)) {
  1494. DoCallBack(hDlg,
  1495. pTVWnd,
  1496. pItem,
  1497. pItem->pSel,
  1498. NULL,
  1499. NULL,
  1500. 0,
  1501. CPSUICB_REASON_OPTITEM_SETFOCUS);
  1502. }
  1503. }
  1504. switch (Msg) {
  1505. case WM_DRAWITEM:
  1506. return(DrawLBCBItem(pTVWnd, (LPDRAWITEMSTRUCT)lParam));
  1507. case WM_COMMAND:
  1508. if ((LOWORD(wParam) == ADVANCED_PUSH) &&
  1509. (pTVWnd->Flags & TWF_HAS_ADVANCED_PUSH) &&
  1510. (HIWORD(wParam) == BN_CLICKED) &&
  1511. (pTVWnd->hCPSUIPage) &&
  1512. (pPage = HANDLETABLE_GetCPSUIPage(pTVWnd->hCPSUIPage))) {
  1513. pPage->Flags |= CPF_CALL_TV_DIRECT;
  1514. pTVWnd->Flags |= TWF_TV_BY_PUSH;
  1515. AddComPropSheetPage(pPage, pTVWnd->cInitMyDlgPage);
  1516. pTVWnd->Flags &= ~TWF_TV_BY_PUSH;
  1517. pPage->Flags &= ~CPF_CALL_TV_DIRECT;
  1518. HANDLETABLE_UnGetCPSUIPage(pPage);
  1519. SET_APPLY_BUTTON(pTVWnd, hDlg);
  1520. UpdatePropPage(hDlg, pCurMyDP);
  1521. InvalidateBMP(hDlg, pTVWnd);
  1522. break;
  1523. } else {
  1524. NULL;
  1525. }
  1526. //
  1527. // Fall through
  1528. //
  1529. case WM_HSCROLL:
  1530. if (pItem = DlgHScrollCommand(hDlg, pTVWnd, (HWND)lParam, wParam)) {
  1531. UpdatePropPageItem(hDlg, pTVWnd, pItem, FALSE);
  1532. InvalidateBMP(hDlg, pTVWnd);
  1533. }
  1534. break;
  1535. case WM_HELP:
  1536. wParam = (WPARAM)((LPHELPINFO)lParam)->hItemHandle;
  1537. lParam = (LPARAM)MAKELONG(((LPHELPINFO)lParam)->MousePos.x,
  1538. ((LPHELPINFO)lParam)->MousePos.y);
  1539. case WM_CONTEXTMENU:
  1540. if (lParam == 0xFFFFFFFF) {
  1541. RECT rc;
  1542. wParam = (WPARAM)GetFocus();
  1543. GetWindowRect((HWND)wParam, &rc);
  1544. CPSUIINT(("MousePos=0xFFFFFFFF, GetFocus=%08lx, rc=(%ld, %ld)-(%ld, %ld)",
  1545. (HWND)wParam, rc.left, rc.top, rc.right, rc.bottom));
  1546. rc.left += ((rc.right - rc.left) / 2);
  1547. rc.top += ((rc.bottom - rc.top) / 2);
  1548. lParam = (LPARAM)MAKELONG(rc.left, rc.top);
  1549. }
  1550. pTVWnd = GET_PTVWND(hDlg);
  1551. if (pTVWnd) {
  1552. pItem = pItemFromhWnd(hDlg, pTVWnd, (HWND)wParam, (LONG)lParam);
  1553. if (Msg == WM_CONTEXTMENU) {
  1554. DoContextMenu(pTVWnd, hDlg, pItem, lParam);
  1555. } else if (pItem) {
  1556. CommonPropSheetUIHelp(hDlg,
  1557. pTVWnd,
  1558. hDlg, // (HWND)GetFocus(),
  1559. (DWORD)lParam,
  1560. pItem,
  1561. HELP_WM_HELP);
  1562. }
  1563. }
  1564. break;
  1565. case WM_NOTIFY:
  1566. MResult = 0;
  1567. switch (pNMHdr->code) {
  1568. case NM_SETFOCUS:
  1569. case NM_CLICK:
  1570. case NM_DBLCLK:
  1571. case NM_RDBLCLK:
  1572. case NM_RCLICK:
  1573. break;
  1574. case PSN_APPLY:
  1575. if ((pTVWnd->Flags & TWF_CAN_UPDATE) &&
  1576. (pTVWnd->ActiveDlgPage == pCurMyDP->PageIdx)) {
  1577. CPSUIDBG(DBG_PROPPAGEPROC,
  1578. ("\nPropPage: Do PSN_APPLY(%ld), Page: Cur=%u, Active=%u, Flags=%04lx, CALLBACK",
  1579. (pTVWnd->Flags & TWF_APPLY_NO_NEWDEF) ? 1 : 0,
  1580. (UINT)pCurMyDP->PageIdx, (UINT)pTVWnd->ActiveDlgPage,
  1581. pTVWnd->Flags));
  1582. if (DoCallBack(hDlg,
  1583. pTVWnd,
  1584. (pTVWnd->Flags & TWF_APPLY_NO_NEWDEF) ?
  1585. NULL : pTVWnd->ComPropSheetUI.pOptItem,
  1586. (LPVOID)pCurMyDP->PageIdx,
  1587. NULL,
  1588. NULL,
  1589. 0,
  1590. CPSUICB_REASON_APPLYNOW) ==
  1591. CPSUICB_ACTION_NO_APPLY_EXIT) {
  1592. MResult = PSNRET_INVALID_NOCHANGEPAGE;
  1593. }
  1594. } else {
  1595. CPSUIDBG(DBG_PROPPAGEPROC,
  1596. ("\nPropPage: Ignore PSN_APPLY, Page: Cur=%u, Active=%u, Flags=%04lx, DO NOTHING",
  1597. (UINT)pCurMyDP->PageIdx, (UINT)pTVWnd->ActiveDlgPage,
  1598. pTVWnd->Flags));
  1599. }
  1600. break;
  1601. case PSN_RESET:
  1602. CPSUIDBG(DBG_PROPPAGEPROC, ("\nPropPage: Got PSN_RESET (Cancel)"));
  1603. break;
  1604. case PSN_HELP:
  1605. CPSUIDBG(DBG_PROPPAGEPROC, ("\nPropPage: Got PSN_HELP (Help)"));
  1606. CommonPropSheetUIHelp(hDlg,
  1607. pTVWnd,
  1608. GetFocus(),
  1609. 0,
  1610. NULL,
  1611. HELP_CONTENTS);
  1612. break;
  1613. case PSN_SETACTIVE:
  1614. CPSUIDBG(DBG_PROPPAGEPROC,
  1615. ("\nPropPage: Got PSN_SETACTIVE, pTVWnd=%08lx (%ld), Page=%u -> %u\n",
  1616. pTVWnd, pTVWnd->cMyDlgPage,
  1617. (UINT)pTVWnd->ActiveDlgPage, (UINT)pCurMyDP->PageIdx));
  1618. pCurMyDP->Flags |= MYDPF_PAGE_ACTIVE;
  1619. pTVWnd->ActiveDlgPage = pCurMyDP->PageIdx;
  1620. DoCallBack(hDlg,
  1621. pTVWnd,
  1622. pTVWnd->ComPropSheetUI.pOptItem,
  1623. (LPVOID)pCurMyDP->PageIdx,
  1624. NULL,
  1625. NULL,
  1626. 0,
  1627. CPSUICB_REASON_SETACTIVE);
  1628. UpdatePropPage(hDlg, pCurMyDP);
  1629. InvalidateBMP(hDlg, pTVWnd);
  1630. break;
  1631. case PSN_KILLACTIVE:
  1632. CPSUIDBG(DBG_PROPPAGEPROC, ("\nPropPage: Got PSN_KILLACTIVE, pTVWnd=%08lx (%ld)",
  1633. pTVWnd, pTVWnd->cMyDlgPage));
  1634. pCurMyDP->Flags &= ~MYDPF_PAGE_ACTIVE;
  1635. DoCallBack(hDlg,
  1636. pTVWnd,
  1637. pTVWnd->ComPropSheetUI.pOptItem,
  1638. (LPVOID)pCurMyDP->PageIdx,
  1639. NULL,
  1640. NULL,
  1641. 0,
  1642. CPSUICB_REASON_KILLACTIVE);
  1643. break;
  1644. default:
  1645. CPSUIDBG(DBG_PROPPAGEPROC,
  1646. ("*PropPageProc: Unknow WM_NOTIFY=%u", pNMHdr->code));
  1647. break;
  1648. }
  1649. SetWindowLongPtr(hDlg, DWLP_MSGRESULT, MResult);
  1650. return(TRUE);
  1651. break;
  1652. case WM_DESTROY:
  1653. CPSUIINT(("PropPage: Get WM_DESTROY Message"));
  1654. if ((hCtrl = GetDlgItem(hDlg, IDD_LAYOUT_PICTURE)) &&
  1655. (pData = (PLAYOUTBMP)GetProp(hCtrl, CPSUIPROP_LAYOUTPUSH))) {
  1656. FreeLayoutBmp(pData);
  1657. RemoveProp(hCtrl, CPSUIPROP_LAYOUTPUSH);
  1658. }
  1659. EnumChildWindows(hDlg, ChildWndCleanUp, 0);
  1660. DEL_PMYDLGPAGE(hDlg);
  1661. break;
  1662. }
  1663. return(FALSE);
  1664. #undef pNMHdr
  1665. }
  1666. PLAYOUTBMP
  1667. InitLayoutBmp(
  1668. HWND hDlg,
  1669. HANDLE hWnd,
  1670. PTVWND pTVWnd
  1671. )
  1672. /*++
  1673. Routine Description:
  1674. Loads bitmap resource and initializes array used in displaying layout preview
  1675. Arguments:
  1676. hDlg - Dialog handle
  1677. hWnd - Handle to the preview window control
  1678. pTVWnd - Treeview info
  1679. Return Value:
  1680. Pointer to LAYOUTBMP containing private settings
  1681. Author:
  1682. Revision History:
  1683. --*/
  1684. {
  1685. PLAYOUTBMP pData;
  1686. if (!(pData = LocalAlloc(LMEM_FIXED, sizeof(LAYOUTBMP)))) {
  1687. return NULL;
  1688. }
  1689. if (!(LoadLayoutBmp(hDlg, &pData->Portrait, IDI_CPSUI_LAYOUT_BMP_PORTRAIT)) ||
  1690. !(LoadLayoutBmp(hDlg, &pData->BookletL, IDI_CPSUI_LAYOUT_BMP_BOOKLETL)) ||
  1691. !(LoadLayoutBmp(hDlg, &pData->BookletP, IDI_CPSUI_LAYOUT_BMP_BOOKLETP)) ||
  1692. !(LoadLayoutBmp(hDlg, &pData->ArrowL, IDI_CPSUI_LAYOUT_BMP_ARROWL)) ||
  1693. !(LoadLayoutBmp(hDlg, &pData->ArrowS, IDI_CPSUI_LAYOUT_BMP_ARROWS)) ) {
  1694. // something went wrong. cleanup...
  1695. FreeLayoutBmp(pData);
  1696. return NULL;
  1697. }
  1698. pData->hWnd = hWnd;
  1699. InitData(pData, pTVWnd);
  1700. return pData;
  1701. }
  1702. BOOL
  1703. LoadLayoutBmp(
  1704. HWND hDlg,
  1705. MYBMP * pMyBmpData,
  1706. DWORD dwBitmapID
  1707. )
  1708. /*++
  1709. Routine Description:
  1710. Load bitmap resource and get color table information,
  1711. BITMAPINFOHEADER and offset to bits for bltting later.
  1712. Arguments:
  1713. Return Value:
  1714. Author:
  1715. Revision History:
  1716. --*/
  1717. {
  1718. HANDLE hResource, hBitmap;
  1719. LPBYTE lpBitmap;
  1720. LPBITMAPINFOHEADER lpbmi;
  1721. DWORD dwClrUsed;
  1722. if (!(hResource = FindResource(hInstDLL,
  1723. MAKEINTRESOURCE(dwBitmapID),
  1724. RT_BITMAP))){
  1725. return FALSE;
  1726. }
  1727. if (!(hBitmap = LoadResource(hInstDLL, hResource))) {
  1728. return FALSE;
  1729. }
  1730. if (!(lpBitmap = LockResource(hBitmap))) {
  1731. FreeResource(hBitmap);
  1732. return FALSE;
  1733. }
  1734. lpbmi = (LPBITMAPINFOHEADER)lpBitmap;
  1735. if (lpbmi->biSize == sizeof(BITMAPINFOHEADER)){
  1736. dwClrUsed = lpbmi->biClrUsed;
  1737. if (dwClrUsed == 0) {
  1738. switch(lpbmi->biBitCount){
  1739. case 1:
  1740. dwClrUsed = 2;
  1741. break;
  1742. case 4:
  1743. dwClrUsed = 16;
  1744. break;
  1745. case 8:
  1746. dwClrUsed = 256;
  1747. break;
  1748. default:
  1749. dwClrUsed = 0;
  1750. break;
  1751. }
  1752. }
  1753. lpBitmap += lpbmi->biSize + (dwClrUsed * sizeof(RGBQUAD));
  1754. } else {
  1755. FreeResource(hBitmap);
  1756. return FALSE;
  1757. }
  1758. pMyBmpData->hBitmap = hBitmap;
  1759. pMyBmpData->lpbmi = lpbmi;
  1760. pMyBmpData->lpBits = lpBitmap;
  1761. return TRUE;
  1762. }
  1763. VOID
  1764. DrawLayoutArrowAndText(
  1765. HDC hDC,
  1766. PRECT prcIn,
  1767. PRECT prcOut,
  1768. PLAYOUTBMP pData
  1769. )
  1770. /*++
  1771. Routine Description:
  1772. This function draws the arrow and the Side1/Side2 text for the
  1773. preview pages in duplex mode.
  1774. Arguments:
  1775. hDC - Screen DC
  1776. prcIn - Describes the total drawable dimensions for the preview control
  1777. prcOut - Pointer to RECT that describes the dimensions of the last page drawn
  1778. pData - Private data, stores the bitmap information
  1779. Return Value:
  1780. None
  1781. --*/
  1782. {
  1783. LPBITMAPINFOHEADER lpbmi;
  1784. LPBYTE lpBits;
  1785. INT left, top, strx1,strx2, stry1, stry2;
  1786. WCHAR awchBuf[MAX_RES_STR_CHARS];
  1787. HBITMAP hbm = NULL;
  1788. HDC hdcMem = NULL;
  1789. BOOL bArrowS;
  1790. if (pData->DuplexIdx == DUPLEX_SIMPLEX)
  1791. return;
  1792. if ((pData->DuplexIdx == DUPLEX_LONGSIDE && pData->OrientIdx == ORIENT_PORTRAIT) ||
  1793. (pData->DuplexIdx == DUPLEX_SHORTSIDE && pData->OrientIdx != ORIENT_PORTRAIT)) {
  1794. if ((pData->NupIdx == NUP_TWOUP || pData->NupIdx == NUP_SIXUP))
  1795. bArrowS = TRUE;
  1796. else
  1797. bArrowS = FALSE;
  1798. }
  1799. else {
  1800. if ((pData->NupIdx == NUP_TWOUP || pData->NupIdx == NUP_SIXUP))
  1801. bArrowS = FALSE;
  1802. else
  1803. bArrowS = TRUE;
  1804. }
  1805. if (bArrowS) {
  1806. lpbmi = pData->ArrowS.lpbmi;
  1807. lpBits = pData->ArrowS.lpBits;
  1808. left = prcOut->right + SHADOW_SIZE*2;
  1809. top = prcOut->top - (lpbmi->biHeight + SHADOW_SIZE)/2;
  1810. strx1 = strx2 = prcIn->left + (prcIn->right - prcIn->left)/16 ;
  1811. stry1 = prcIn->top;
  1812. stry2 = stry1 + ((prcIn->bottom - prcIn->top) + SHADOW_SIZE)/2;
  1813. }
  1814. else {
  1815. lpbmi = pData->ArrowL.lpbmi;
  1816. lpBits = pData->ArrowL.lpBits;
  1817. left = prcIn->left + (prcOut->right - prcOut->left) + SHADOW_SIZE;
  1818. top = prcOut->top + (prcOut->bottom - prcOut->top) + SHADOW_SIZE*2;
  1819. strx1 = prcIn->left + (prcIn->right - prcIn->left)/6 - SHADOW_SIZE;
  1820. stry1 = stry2 = prcIn->top + (prcIn->bottom - prcIn->top)/6 ;
  1821. strx2 = strx1 + (prcIn->right - prcIn->left)/2;
  1822. }
  1823. if (!(hbm = CreateCompatibleBitmap(hDC, lpbmi->biWidth, lpbmi->biHeight)) ||
  1824. !(hdcMem = CreateCompatibleDC(hDC)) ||
  1825. !SelectObject(hdcMem, hbm))
  1826. {
  1827. goto DrawArrowAndTextExit;
  1828. }
  1829. StretchDIBits(hdcMem,
  1830. 0,
  1831. 0,
  1832. lpbmi->biWidth,
  1833. lpbmi->biHeight,
  1834. 0,
  1835. 0,
  1836. lpbmi->biWidth,
  1837. lpbmi->biHeight,
  1838. lpBits,
  1839. (LPBITMAPINFO)lpbmi,
  1840. DIB_RGB_COLORS,
  1841. SRCCOPY
  1842. );
  1843. TransparentBlt(hDC,
  1844. left,
  1845. top,
  1846. lpbmi->biWidth,
  1847. lpbmi->biHeight,
  1848. hdcMem,
  1849. 0,
  1850. 0,
  1851. lpbmi->biWidth,
  1852. lpbmi->biHeight,
  1853. RGB(255, 0, 255)
  1854. );
  1855. //
  1856. // Draw the Text
  1857. //
  1858. LoadString(hInstDLL, IDS_CPSUI_SIDE1, awchBuf, MAX_RES_STR_CHARS);
  1859. TextOut(hDC, strx1, stry1, awchBuf, wcslen(awchBuf));
  1860. LoadString(hInstDLL, IDS_CPSUI_SIDE2, awchBuf, MAX_RES_STR_CHARS);
  1861. TextOut(hDC, strx2, stry2, awchBuf, wcslen(awchBuf));
  1862. DrawArrowAndTextExit:
  1863. if (hbm)
  1864. DeleteObject(hbm);
  1865. if (hdcMem)
  1866. DeleteDC(hdcMem);
  1867. }
  1868. VOID
  1869. UpdateLayoutBmp(
  1870. HDC hDC,
  1871. PLAYOUTBMP pData
  1872. )
  1873. /*++
  1874. Routine Description:
  1875. Calls whenever we get a WM_DRAWITEM to draw owner drawn controls.
  1876. Arguments:
  1877. hDC - Handle to screen DC
  1878. pData - Private data containing current selections etc.
  1879. Return Value:
  1880. None
  1881. Author:
  1882. Revision History:
  1883. Note:
  1884. PAGE_BOUNDARY_SCALE is 7 since it assumes that the destination control is
  1885. a square where in portrait mode, the width of the dest window is 5/7 of the square and in
  1886. landscape mode, the height of the dest window is 5/7 of the square. This is used to simplify
  1887. the code for both scenarios. We just need to scale based on the orientation
  1888. selected.
  1889. --*/
  1890. {
  1891. #define PAGE_BOUNDARY_SCALE 7
  1892. INT i, j, k, Row, Columm;
  1893. BOOL bDoBooklet = FALSE;
  1894. DWORD dwWidth, dwHeight, dwBookletLeft, dwBookletTop, dwOffset;
  1895. RECT rcControlIn, rcControlOut;
  1896. LPBITMAPINFOHEADER lpbmi;
  1897. LPBYTE lpBits;
  1898. HDC hCompDC;
  1899. HBITMAP hCompBitmap;
  1900. PAGEBORDER * pPageBorder;
  1901. BYTE DuplexIdx;
  1902. //
  1903. // PageBorder represents the factor for calculating the
  1904. // left, top, right, bottom rectangle of the current selected duplex option
  1905. //
  1906. static PAGEBORDER PageBorderP[] = {
  1907. { 4, 4, 2, 2 },
  1908. { 0, 4, 2, 2 },
  1909. { 2, 4, 2, 2 },
  1910. { 4, 0, 2, 2 },
  1911. { 4, 2, 2, 2 }
  1912. };
  1913. static PAGEBORDER PageBorderL[] = {
  1914. { 4, 4, 2, 2 },
  1915. { 4, 0, 2, 2 },
  1916. { 4, 2, 2, 2 },
  1917. { 0, 4, 2, 2 },
  1918. { 2, 4, 2, 2 }
  1919. };
  1920. //
  1921. // Duplex represents the the start and end of rectangles to be drawn for
  1922. // the current selected duplex options.
  1923. // For example, to draw page border for Long Side duplexinng,
  1924. // Start with PageBorder[1] and End with PageBorder[3]
  1925. //
  1926. static DUPLEX Duplex[MAX_DUPLEX_OPTION] = {
  1927. { 1, 3 }, // Long Side
  1928. { 3, 5 }, // Short Side
  1929. { 0, 1 } // Simplex
  1930. };
  1931. //
  1932. // Nup[] represents the row and columm for each Nup option
  1933. //
  1934. static NUP Nup[] = {
  1935. { 1, 1 }, // 1-up
  1936. { 2, 1 }, // 2-up
  1937. { 2, 2 }, // 4-up
  1938. { 3, 2 }, // 6-up
  1939. { 3, 3 }, // 9-up
  1940. { 4, 4 }, // 16-up
  1941. { 1, 1 } // Booklet
  1942. };
  1943. GetClientRect(pData->hWnd, &rcControlIn);
  1944. dwOffset = (rcControlIn.right - rcControlIn.left)/ PAGE_BOUNDARY_SCALE;
  1945. if (pData->OrientIdx == ORIENT_PORTRAIT){
  1946. if ((pData->NupIdx == NUP_TWOUP || pData->NupIdx == NUP_SIXUP))
  1947. {
  1948. rcControlIn.top += dwOffset;
  1949. rcControlIn.bottom -= dwOffset;
  1950. pPageBorder =PageBorderL;
  1951. }
  1952. else
  1953. {
  1954. rcControlIn.left += dwOffset;
  1955. rcControlIn.right -= dwOffset;
  1956. pPageBorder =PageBorderP;
  1957. }
  1958. }else {
  1959. if ((pData->NupIdx == NUP_TWOUP || pData->NupIdx == NUP_SIXUP))
  1960. {
  1961. rcControlIn.left += dwOffset;
  1962. rcControlIn.right -= dwOffset;
  1963. pPageBorder =PageBorderP;
  1964. }
  1965. else
  1966. {
  1967. rcControlIn.top += dwOffset;
  1968. rcControlIn.bottom -= dwOffset;
  1969. pPageBorder =PageBorderL;
  1970. }
  1971. }
  1972. CopyMemory(&rcControlOut, &rcControlIn, sizeof(RECT));
  1973. SetStretchBltMode(hDC, BLACKONWHITE);
  1974. if (bDoBooklet = (pData->NupIdx == NUP_BOOKLET))
  1975. DuplexIdx = DUPLEX_SIMPLEX;
  1976. else
  1977. DuplexIdx = pData->DuplexIdx;
  1978. for (k= Duplex[DuplexIdx].Start; k < Duplex[DuplexIdx].End; k++) {
  1979. DrawBorder(hDC,
  1980. !bDoBooklet,
  1981. !bDoBooklet,
  1982. &rcControlIn,
  1983. &rcControlOut,
  1984. &pPageBorder[k]
  1985. );
  1986. if (!bDoBooklet) {
  1987. rcControlOut.left += FRAME_BORDER;
  1988. rcControlOut.right -= FRAME_BORDER;
  1989. rcControlOut.top += FRAME_BORDER;
  1990. rcControlOut.bottom -= FRAME_BORDER;
  1991. dwWidth = rcControlOut.right - rcControlOut.left;
  1992. dwHeight = rcControlOut.bottom - rcControlOut.top;
  1993. lpBits = pData->Portrait.lpBits;
  1994. lpbmi = pData->Portrait.lpbmi;
  1995. if (pData->OrientIdx == ORIENT_PORTRAIT)
  1996. {
  1997. Row = Nup[pData->NupIdx].row;
  1998. Columm = Nup[pData->NupIdx].columm;
  1999. }
  2000. else {
  2001. Row = Nup[pData->NupIdx].columm;
  2002. Columm = Nup[pData->NupIdx].row;
  2003. }
  2004. if ((pData->NupIdx == NUP_TWOUP || pData->NupIdx == NUP_SIXUP)) {
  2005. i = Row;
  2006. Row = Columm;
  2007. Columm = i;
  2008. }
  2009. dwWidth /= Columm;
  2010. dwHeight /= Row;
  2011. }
  2012. else {
  2013. dwBookletLeft = rcControlOut.left;
  2014. dwBookletTop = rcControlOut.top;
  2015. if (pData->OrientIdx == ORIENT_PORTRAIT) {
  2016. lpBits = pData->BookletP.lpBits;
  2017. lpbmi = pData->BookletP.lpbmi;
  2018. dwWidth = pData->BookletP.lpbmi->biWidth;
  2019. dwHeight = pData->BookletP.lpbmi->biHeight;
  2020. rcControlOut.right = rcControlOut.left + dwWidth;
  2021. rcControlOut.bottom = rcControlOut.top + dwHeight;
  2022. rcControlOut.top = rcControlOut.top + dwHeight/5;
  2023. }
  2024. else {
  2025. lpBits = pData->BookletL.lpBits;
  2026. lpbmi = pData->BookletL.lpbmi;
  2027. dwWidth = pData->BookletL.lpbmi->biWidth;
  2028. dwHeight = pData->BookletL.lpbmi->biHeight;
  2029. rcControlOut.right = rcControlOut.left + dwWidth;
  2030. rcControlOut.bottom = rcControlOut.top + dwHeight;
  2031. rcControlOut.left = rcControlOut.left + dwWidth/5;
  2032. }
  2033. }
  2034. hCompDC = CreateCompatibleDC(hDC);
  2035. hCompBitmap = CreateCompatibleBitmap(hDC, dwWidth, dwHeight);
  2036. if (!hCompDC || !hCompBitmap)
  2037. return;
  2038. SelectObject(hCompDC, hCompBitmap);
  2039. StretchDIBits(hCompDC,
  2040. 0,
  2041. 0,
  2042. dwWidth,
  2043. dwHeight,
  2044. 0,
  2045. 0,
  2046. lpbmi->biWidth,
  2047. lpbmi->biHeight,
  2048. lpBits,
  2049. (LPBITMAPINFO)lpbmi,
  2050. DIB_RGB_COLORS,
  2051. SRCCOPY
  2052. );
  2053. if (bDoBooklet) {
  2054. DrawBorder(hDC,
  2055. TRUE,
  2056. FALSE,
  2057. NULL,
  2058. &rcControlOut,
  2059. NULL
  2060. );
  2061. TransparentBlt(hDC,
  2062. dwBookletLeft,
  2063. dwBookletTop ,
  2064. dwWidth,
  2065. dwHeight,
  2066. hCompDC,
  2067. 0,
  2068. 0,
  2069. dwWidth,
  2070. dwHeight,
  2071. RGB(255, 0, 255)
  2072. );
  2073. }
  2074. else {
  2075. for ( i = 0; i < Row; i++) {
  2076. for (j = 0; j < Columm; j++) {
  2077. BitBlt( hDC,
  2078. rcControlOut.left + dwWidth*j ,
  2079. rcControlOut.top + dwHeight*i,
  2080. dwWidth,
  2081. dwHeight,
  2082. hCompDC,
  2083. 0,
  2084. 0,
  2085. SRCCOPY
  2086. );
  2087. }
  2088. }
  2089. }
  2090. DeleteObject(hCompBitmap);
  2091. DeleteDC(hCompDC);
  2092. }
  2093. if (!bDoBooklet)
  2094. DrawLayoutArrowAndText(hDC,&rcControlIn, &rcControlOut, pData);
  2095. }
  2096. VOID
  2097. FreeLayoutBmp(
  2098. PLAYOUTBMP pData
  2099. )
  2100. /*++
  2101. Routine Description:
  2102. Unlock and Free Resources and free memory allocated for pData
  2103. Arguments:
  2104. Return Value:
  2105. Author:
  2106. Revision History:
  2107. --*/
  2108. {
  2109. if (pData){
  2110. UnlockResource(pData->Portrait.hBitmap);
  2111. UnlockResource(pData->BookletL.hBitmap);
  2112. UnlockResource(pData->BookletP.hBitmap);
  2113. UnlockResource(pData->ArrowL.hBitmap);
  2114. UnlockResource(pData->ArrowS.hBitmap);
  2115. FreeResource(pData->Portrait.hBitmap);
  2116. FreeResource(pData->BookletL.hBitmap);
  2117. FreeResource(pData->BookletP.hBitmap);
  2118. FreeResource(pData->ArrowL.hBitmap);
  2119. FreeResource(pData->ArrowS.hBitmap);
  2120. LocalFree(pData);
  2121. }
  2122. }
  2123. VOID
  2124. DrawBorder(
  2125. HDC hDC,
  2126. BOOL bDrawShadow,
  2127. BOOL bDrawBorder,
  2128. PRECT pRectIn,
  2129. PRECT pRectOut,
  2130. PAGEBORDER * pPageBorder
  2131. )
  2132. /*++
  2133. Routine Description:
  2134. Draw the page border for the preview bitmap
  2135. Arguments:
  2136. Return Value:
  2137. Author:
  2138. Revision History:
  2139. --*/
  2140. {
  2141. HPEN hOldPen, hPen;
  2142. HBRUSH hBrush;
  2143. DWORD dwWidth, dwHeight;
  2144. RECT rcShadow;
  2145. hPen = GetStockObject(BLACK_PEN);
  2146. hBrush = GetStockObject(GRAY_BRUSH);
  2147. hOldPen = (HPEN) SelectObject(hDC, hPen);
  2148. if (pPageBorder) {
  2149. dwWidth = pRectIn->right - pRectIn->left ;
  2150. dwHeight = pRectIn->bottom - pRectIn->top ;
  2151. pRectOut->left = pRectIn->left + ADDOFFSET(dwWidth ,pPageBorder->left);
  2152. pRectOut->top = pRectIn->top + ADDOFFSET(dwHeight,pPageBorder->top);
  2153. pRectOut->right = pRectOut->left + ADDOFFSET(dwWidth ,pPageBorder->right) ;
  2154. pRectOut->bottom = pRectOut->top + ADDOFFSET(dwHeight,pPageBorder->bottom);
  2155. }
  2156. if (bDrawBorder) {
  2157. InflateRect(pRectOut, -5, -5);
  2158. SelectObject ( hDC, hPen);
  2159. Rectangle( hDC, pRectOut->left, pRectOut->top, pRectOut->right , pRectOut->bottom );
  2160. }
  2161. if (bDrawShadow) {
  2162. rcShadow.left = pRectOut->right;
  2163. rcShadow.top = pRectOut->top + SHADOW_SIZE;
  2164. rcShadow.right = pRectOut->right + SHADOW_SIZE;
  2165. rcShadow.bottom = pRectOut->bottom + SHADOW_SIZE;
  2166. FillRect(hDC, &rcShadow, hBrush);
  2167. rcShadow.left = pRectOut->left + SHADOW_SIZE;
  2168. rcShadow.top = pRectOut->bottom;
  2169. rcShadow.right = pRectOut->right + SHADOW_SIZE;
  2170. rcShadow.bottom = pRectOut->bottom + SHADOW_SIZE;
  2171. FillRect(hDC, &rcShadow, hBrush);
  2172. }
  2173. SelectObject ( hDC, hOldPen);
  2174. if (hPen) {
  2175. DeleteObject ( hPen );
  2176. }
  2177. if (hBrush) {
  2178. DeleteObject ( hBrush );
  2179. }
  2180. }
  2181. VOID
  2182. InvalidateBMP(
  2183. HWND hDlg,
  2184. PTVWND pTVWnd
  2185. )
  2186. /*++
  2187. Routine Description:
  2188. Call InvalidateRect to get WM_DRAWITEM to update preview.
  2189. Arguments:
  2190. Return Value:
  2191. Author:
  2192. Revision History:
  2193. --*/
  2194. {
  2195. HWND hWnd;
  2196. PLAYOUTBMP pData;
  2197. if ((hWnd = GetDlgItem(hDlg, IDD_LAYOUT_PICTURE)) &&
  2198. (pData = (PLAYOUTBMP)GetProp(hWnd, CPSUIPROP_LAYOUTPUSH))) {
  2199. UpdateData(pData, pTVWnd);
  2200. InvalidateRect(hWnd, NULL, TRUE);
  2201. }
  2202. }
  2203. VOID
  2204. InitData(
  2205. PLAYOUTBMP pData,
  2206. PTVWND pTVWnd
  2207. )
  2208. /*++
  2209. Routine Description:
  2210. Arguments:
  2211. Return Value:
  2212. Author:
  2213. Revision History:
  2214. --*/
  2215. {
  2216. UINT Idx, Count, i;
  2217. POPTTYPE pOptType;
  2218. POPTPARAM pOptParam;
  2219. POPTITEM pItem = pTVWnd->ComPropSheetUI.pOptItem;
  2220. pData->OrientIdx = ORIENT_PORTRAIT;
  2221. pData->NupIdx = NUP_ONEUP;
  2222. pData->DuplexIdx = DUPLEX_SIMPLEX;
  2223. if (pItem = GET_PITEMDMPUB(pTVWnd, DMPUB_ORIENTATION, Idx)) {
  2224. pOptType = pItem->pOptType;
  2225. pOptParam = pOptType->pOptParam;
  2226. Count = pOptType->Count;
  2227. for ( i = 0; i < Count; i++) {
  2228. switch (pOptParam->IconID) {
  2229. case IDI_CPSUI_PORTRAIT:
  2230. pData->Orientation.PortraitIdx = (BYTE)i;
  2231. break;
  2232. case IDI_CPSUI_LANDSCAPE:
  2233. pData->Orientation.LandscapeIdx = (BYTE)i;
  2234. break;
  2235. case IDI_CPSUI_ROT_LAND:
  2236. pData->Orientation.RotateIdx = (BYTE)i;
  2237. break;
  2238. }
  2239. pOptParam++;
  2240. }
  2241. }
  2242. if (pItem = GET_PITEMDMPUB(pTVWnd, DMPUB_DUPLEX, Idx)) {
  2243. pOptType = pItem->pOptType;
  2244. pOptParam = pOptType->pOptParam;
  2245. Count = pOptType->Count;
  2246. for ( i = 0; i < Count; i++) {
  2247. switch (pOptParam->IconID) {
  2248. case IDI_CPSUI_DUPLEX_NONE:
  2249. case IDI_CPSUI_DUPLEX_NONE_L:
  2250. pData->Duplex.SimplexIdx = (BYTE)i;
  2251. break;
  2252. case IDI_CPSUI_DUPLEX_HORZ:
  2253. case IDI_CPSUI_DUPLEX_HORZ_L:
  2254. pData->Duplex.ShortSideIdx = (BYTE)i;
  2255. break;
  2256. case IDI_CPSUI_DUPLEX_VERT:
  2257. case IDI_CPSUI_DUPLEX_VERT_L:
  2258. pData->Duplex.LongSideIdx = (BYTE)i;
  2259. break;
  2260. }
  2261. pOptParam++;
  2262. }
  2263. }
  2264. }
  2265. VOID
  2266. UpdateData(
  2267. PLAYOUTBMP pData,
  2268. PTVWND pTVWnd
  2269. )
  2270. /*++
  2271. Routine Description:
  2272. Arguments:
  2273. Return Value:
  2274. Author:
  2275. Revision History:
  2276. --*/
  2277. {
  2278. POPTITEM pItem = pTVWnd->ComPropSheetUI.pOptItem;
  2279. UINT Idx;
  2280. if (pItem = GET_PITEMDMPUB(pTVWnd, DMPUB_DUPLEX, Idx)) {
  2281. if ((BYTE)pItem->Sel == pData->Duplex.SimplexIdx) {
  2282. pData->DuplexIdx = DUPLEX_SIMPLEX;
  2283. } else if ((BYTE)pItem->Sel == pData->Duplex.LongSideIdx) {
  2284. pData->DuplexIdx = DUPLEX_LONGSIDE;
  2285. } else if ((BYTE)pItem->Sel == pData->Duplex.ShortSideIdx) {
  2286. pData->DuplexIdx = DUPLEX_SHORTSIDE;
  2287. }
  2288. }
  2289. if (pItem = GET_PITEMDMPUB(pTVWnd, DMPUB_ORIENTATION, Idx)) {
  2290. if ((BYTE)pItem->Sel == pData->Orientation.PortraitIdx) {
  2291. pData->OrientIdx = ORIENT_PORTRAIT;
  2292. } else if ((BYTE)pItem->Sel == pData->Orientation.LandscapeIdx) {
  2293. pData->OrientIdx = ORIENT_LANDSCAPE;
  2294. } else if ((BYTE)pItem->Sel == pData->Orientation.RotateIdx) {
  2295. pData->OrientIdx = ORIENT_ROTATED;
  2296. }
  2297. }
  2298. if (pItem = GET_PITEMDMPUB(pTVWnd, DMPUB_NUP, Idx)) {
  2299. pData->NupIdx = (BYTE)pItem->Sel;
  2300. }
  2301. }