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.

4864 lines
116 KiB

  1. /*++
  2. Copyright (c) 1990-1995 Microsoft Corporation
  3. Module Name:
  4. treeview.c
  5. Abstract:
  6. This module contains tree view function for the printer driver
  7. Author:
  8. 19-Jun-1995 Mon 11:50:26 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 DbgTreeView
  17. #define DBG_AI 0x00000001
  18. #define DBG_UTV 0x00000002
  19. #define DBG_MAI 0x00000004
  20. #define DBG_CTVWND 0x00000008
  21. #define DBG_AC 0x00000010
  22. #define DBG_TVPROC 0x00000020
  23. #define DBG_STVS 0x00000040
  24. #define DBG_AIG 0x00000080
  25. #define DBGITEM_INS 0x00000100
  26. #define DBGITEM_SET 0x00000200
  27. #define DBGITEM_AIG 0x00000400
  28. #define DBGITEM_SETUP 0x00000800
  29. #define DBGITEM_HIT 0x00001000
  30. #define DBGITEM_NEXTGRP 0x00002000
  31. #define DBGITEM_ADDITEM 0x00004000
  32. #define DBG_LBSIZE 0x00008000
  33. #define DBG_COTD 0x00010000
  34. #define DBG_INITDLG 0x00020000
  35. #define DBG_APG 0x00040000
  36. #define DBGITEM_SELCHG 0x00080000
  37. #define DBGITEM_UTV 0x00100000
  38. #define DBG_MSR 0x00200000
  39. #define DBGITEM_NEWICON 0x00400000
  40. #define DBG_TVHT 0x00800000
  41. #define DBGITEM_CREVERT 0x01000000
  42. #define DBGITEM_REVERT 0x02000000
  43. #define DBG_OEM_ITEM 0x04000000
  44. #define DBG_SCID 0x08000000
  45. #define DBG_KEYS 0x10000000
  46. #define DBG_ASSERT 0x80000000
  47. DEFINE_DBGVAR(0);
  48. CPSUIDBGBLK(extern LPSTR pTVOTName[])
  49. #define ICON_SIZE_ANY 0
  50. extern HINSTANCE hInstDLL;
  51. extern OPTTYPE OptTypeHdrPush;
  52. extern OPTPARAM OptParamHdrPush;
  53. static const TVDLGITEM TVDlgItem[] = {
  54. { 5, 0, IDD_3STATES_1 }, // 0 TVOT_2STATES
  55. { 5, 0, IDD_3STATES_1 }, // 1 TVOT_3STATES
  56. { 4, 0, IDD_TV_UDARROW }, // 2 TVOT_UDARROW
  57. { 3, 0, IDD_TV_TRACKBAR }, // 3 TVOT_TRACKBAR
  58. { 3, 0, IDD_TV_SB }, // 4 TVOT_SCROLLBAR
  59. { 1, 0, IDD_TV_LB }, // 5 TVOT_LISTBOX
  60. { 1, 0, IDD_TV_CB }, // 6 TVOT_COMBOBOX
  61. { 3, 0, IDD_TV_EDIT_EDIT }, // 7 TVOT_EDITBOX
  62. { 1, 0, IDD_TV_PUSH }, // 8 TVOT_PUSHBUTTON
  63. { 1, 0, IDD_TV_CHKBOX }, // 9 TVOT_CHKBOX
  64. { 1, 0, IDD_TV_EXTPUSH },
  65. { 1, 0, IDD_TV_EXTCHKBOX }
  66. };
  67. #define ITVGF_BPCL (ITVGF_BOLD | ITVGF_COLLAPSE)
  68. static const INTTVGRP IntTVGrpPaper[] = {
  69. { 1, DMPUB_HDR_PAPER },
  70. { 2, DMPUB_FORMNAME },
  71. { 2, DMPUB_ORIENTATION },
  72. { 2, DMPUB_DEFSOURCE },
  73. { 2, DMPUB_OUTPUTBIN },
  74. { 2, DMPUB_MEDIATYPE },
  75. { 2, DMPUB_COPIES_COLLATE },
  76. { 2, DMPUB_DUPLEX },
  77. { 2, DMPUB_PAGEORDER },
  78. { 2, DMPUB_NUP },
  79. { 0, DMPUB_HDR_TVROOT }
  80. };
  81. static const INTTVGRP IntTVGrpGraphic[] = {
  82. { 1, DMPUB_HDR_GRAPHIC },
  83. { 2, DMPUB_QUALITY },
  84. { 2, DMPUB_PRINTQUALITY },
  85. { 2 , DMPUB_COLOR },
  86. { 2 | ITVGF_BOLD, DMPUB_HDR_ICM },
  87. { 3, DMPUB_ICMMETHOD },
  88. { 3, DMPUB_ICMINTENT },
  89. { 2, DMPUB_SCALE },
  90. { 2, DMPUB_DITHERTYPE },
  91. { 2, DMPUB_TTOPTION },
  92. { 0, DMPUB_HDR_TVROOT }
  93. };
  94. static const WORD ChkBoxStrID[] = { IDS_CPSUI_FALSE,
  95. IDS_CPSUI_TRUE,
  96. IDS_CPSUI_NO,
  97. IDS_CPSUI_YES,
  98. IDS_CPSUI_OFF,
  99. IDS_CPSUI_ON,
  100. IDS_CPSUI_FALSE,
  101. 0,
  102. IDS_CPSUI_NO,
  103. 0,
  104. IDS_CPSUI_OFF,
  105. 0,
  106. IDS_CPSUI_NONE,
  107. 0 };
  108. #define STVS_REINIT 0x0001
  109. #define STVS_ACTIVE 0x0002
  110. POPTITEM
  111. GetOptions(
  112. PTVWND pTVWnd,
  113. LPARAM lParam
  114. )
  115. {
  116. TVLP tvlp;
  117. tvlp = GET_TVLP(lParam);
  118. if (tvlp.ItemIdx >= INTIDX_FIRST) {
  119. return(PIDX_INTOPTITEM(pTVWnd, tvlp.ItemIdx));
  120. } else if (tvlp.ItemIdx < pTVWnd->ComPropSheetUI.cOptItem) {
  121. return(pTVWnd->ComPropSheetUI.pOptItem + tvlp.ItemIdx);
  122. } else {
  123. CPSUIERR(("ERROR: GetOptions(tvlp): Idx=%04lx, cName=%ld, Flags=%02lx",
  124. (DWORD)tvlp.ItemIdx, (DWORD)tvlp.cName, (DWORD)tvlp.Flags));
  125. return(PIDX_INTOPTITEM(pTVWnd, INTIDX_TVROOT));
  126. }
  127. }
  128. #if (DO_IN_PLACE == 0)
  129. VOID
  130. MoveStateRadios(
  131. HWND hDlg,
  132. PTVWND pTVWnd,
  133. POPTTYPE pOptType,
  134. WORD InitFlags
  135. )
  136. /*++
  137. Routine Description:
  138. Arguments:
  139. Return Value:
  140. Author:
  141. 02-Sep-1995 Sat 21:08:14 created -by- Daniel Chou (danielc)
  142. Revision History:
  143. --*/
  144. {
  145. HWND hCtrl;
  146. UINT x;
  147. UINT CtrlID;
  148. UINT Count;
  149. UINT HideBits;
  150. TVOTSTATESINFO TSI;
  151. x = (InitFlags & INITCF_HAS_EXT) ? 0 : 1;
  152. if ((HideBits = (UINT)(_OT_FLAGS(pOptType) & OTINTF_STATES_HIDE_MASK)) ||
  153. (pOptType->Type == TVOT_2STATES)) {
  154. TSI = pTVWnd->SI2[x];
  155. if (!HideBits) {
  156. HideBits |= 0x04;
  157. }
  158. } else {
  159. TSI = pTVWnd->SI3[x];
  160. }
  161. CPSUIDBG(DBG_MSR, ("!! %hs: TSI: Top=%d, Inc=%d, Hide=%02x",
  162. pTVOTName[pOptType->Type], TSI.Top, TSI.Inc, HideBits));
  163. x = (UINT)pTVWnd->xCtrls;
  164. Count = 3;
  165. CtrlID = IDD_3STATES_1;
  166. while (Count--) {
  167. if (hCtrl = GetDlgItem(hDlg, CtrlID)) {
  168. if (HideBits & 0x01) {
  169. ShowWindow(hCtrl, SW_HIDE);
  170. EnableWindow(hCtrl, FALSE);
  171. CPSUIDBG(DBG_MSR,
  172. ("HIDE Radio Idx=%d (%d, %d)", 3-Count, x, TSI.Top));
  173. } else {
  174. CPSUIDBG(DBG_MSR,
  175. ("SHOW Radio Idx=%d (%d, %d)", 3-Count, x, TSI.Top));
  176. SetWindowPos(hCtrl, NULL,
  177. x, TSI.Top,
  178. 0, 0,
  179. SWP_NOSIZE | SWP_NOZORDER);
  180. TSI.Top += TSI.Inc;
  181. }
  182. }
  183. CtrlID += 2;
  184. HideBits >>= 1;
  185. }
  186. }
  187. #endif
  188. VOID
  189. SetOptHeader(
  190. HWND hDlg,
  191. PTVWND pTVWnd,
  192. POPTITEM pItem,
  193. BOOL HdrPush
  194. )
  195. /*++
  196. Routine Description:
  197. This function setup the string in the TREEVIEW page change item windows
  198. group box title.
  199. Arguments:
  200. Return Value:
  201. Author:
  202. 16-Oct-1995 Mon 19:23:36 created -by- Daniel Chou (danielc)
  203. Revision History:
  204. 20-Jul-1996 Sat 00:26:33 updated -by- Daniel Chou (danielc)
  205. Fixed the internationalize problem for compsition dynamic user data
  206. --*/
  207. {
  208. POPTITEM pRootItem = PIDX_INTOPTITEM(pTVWnd, INTIDX_TVROOT);
  209. UINT IntFmtStrID;
  210. GSBUF_DEF(pItem, MAX_RES_STR_CHARS + 80);
  211. if (HdrPush) {
  212. //
  213. // Root Header item: XXX Document/Advance Document/Device Settings
  214. // Other Header Item: XXX Options
  215. if (pItem == pRootItem) {
  216. GSBUF_FLAGS |= GBF_PREFIX_OK | GBF_DUP_PREFIX;
  217. IntFmtStrID = (UINT)pRootItem->UserData;
  218. } else {
  219. IntFmtStrID = (UINT)IDS_INT_CPSUI_OPTIONS;
  220. }
  221. } else {
  222. IntFmtStrID = IDS_INT_CPSUI_CHANGE_SET;
  223. }
  224. GSBUF_COMPOSE(IntFmtStrID, pItem->pName, 0, 0);
  225. SetWindowText(GetDlgItem(hDlg, IDD_TV_OPTION), GSBUF_BUF);
  226. }
  227. VOID
  228. ChangeOptTypeDisplay(
  229. HWND hDlg,
  230. PTVWND pTVWnd,
  231. POPTTYPE pOldOptType,
  232. POPTTYPE pNewOptType,
  233. BOOL NewTypeUpdatePermission
  234. )
  235. /*++
  236. Routine Description:
  237. This function hide the old type and enable the new type's option
  238. header/icon depends on the NewTypeEnable flag
  239. Arguments:
  240. hDlg - Handle to the dialog box
  241. pTVWnd - Pointer to TVWND structure of our instance data
  242. pCurItem - Pointer to OPTITEM associate with NewType
  243. pOldOptType - Pointer to the OLD OPTTYPE
  244. pNewOptType - Pointer to the NEW OPTTYPE
  245. NewTypeUpdatePermission - TRUE if new type is not disabled
  246. Return Value:
  247. VOID
  248. Author:
  249. 21-Jun-1995 Wed 20:30:53 created -by- Daniel Chou (danielc)
  250. 31-Aug-1995 Thu 18:34:16 updated -by- Daniel Chou (danielc)
  251. Updated according to the usage of DlgCtrl.c
  252. Revision History:
  253. --*/
  254. {
  255. HWND hCtrl;
  256. BOOL Enable;
  257. UINT OldType;
  258. UINT NewType;
  259. INT swMode;
  260. if ((pOldOptType != pNewOptType) &&
  261. (pOldOptType) &&
  262. ((OldType = (UINT)pOldOptType->Type) <= TVOT_LAST)) {
  263. TVDLGITEM tdi;
  264. #if DO_IN_PLACE
  265. CPSUIINT(("OldType=%ld, NewType=%ld, hWndEdit=%08lx:%08lx:%08lx",
  266. OldType,
  267. (pNewOptType) ? pNewOptType->Type : - 1,
  268. pTVWnd->hWndEdit[0], pTVWnd->hWndEdit[1], pTVWnd->hWndEdit[2]));
  269. switch (OldType) {
  270. case TVOT_2STATES:
  271. case TVOT_3STATES:
  272. case TVOT_LISTBOX:
  273. case TVOT_CHKBOX:
  274. OldType = TVOT_COMBOBOX;
  275. break;
  276. case TVOT_SCROLLBAR:
  277. case TVOT_TRACKBAR:
  278. OldType = TVOT_UDARROW;
  279. break;
  280. default:
  281. break;
  282. }
  283. pTVWnd->chWndEdit = 0;
  284. #endif
  285. CPSUIINT(("OldType=%ld, NewType=%ld", OldType,
  286. (pNewOptType) ? pNewOptType->Type : - 1));
  287. tdi = TVDlgItem[OldType];
  288. while (tdi.cItem--) {
  289. if (hCtrl = GetDlgItem(hDlg, tdi.BegID++)) {
  290. EnableWindow(hCtrl, FALSE);
  291. ShowWindow(hCtrl, SW_HIDE);
  292. CPSUIINT(("Disable/Hide hCtrl=%08lx (%ld)",
  293. hCtrl, tdi.BegID - 1));
  294. }
  295. if (tdi.BegID == (IDD_TV_TRACKBAR + 1)) {
  296. tdi.BegID = IDD_TV_SB_LOW;
  297. }
  298. }
  299. }
  300. //
  301. // Display option header, icon if any
  302. //
  303. NewType = (UINT)((pNewOptType) ? pNewOptType->Type : TVOT_NONE);
  304. if (Enable = (BOOL)(NewType <= TVOT_LAST)) {
  305. swMode = SW_SHOW;
  306. if ((!NewTypeUpdatePermission) ||
  307. (!(pTVWnd->Flags & TWF_CAN_UPDATE))) {
  308. Enable = FALSE;
  309. }
  310. } else {
  311. swMode = SW_HIDE;
  312. }
  313. ShowWindow(hCtrl = GetDlgItem(hDlg, IDD_TV_OPTION), swMode);
  314. EnableWindow(hCtrl, Enable);
  315. ShowWindow(GetDlgItem(hDlg, IDD_TV_ICON), swMode);
  316. CPSUIDBG(DBG_COTD, ("OldType=%ld, NewType=%ld, Enable=%ld, swMode=%ld",
  317. (LONG)OldType, (LONG)NewType, (DWORD)Enable, (DWORD)swMode));
  318. }
  319. LRESULT
  320. CALLBACK
  321. MyEditWndProc(
  322. HWND hWnd,
  323. UINT Msg,
  324. WPARAM wParam,
  325. LPARAM lParam
  326. )
  327. /*++
  328. Routine Description:
  329. This is the subclass WNDPROC for the numberical edit control, it check
  330. valid input for the number entered.
  331. Arguments:
  332. WNDPROC standard
  333. Return Value:
  334. INT (The original WNDPROC returned), if the entered keys are not valid
  335. then it return right away without processing
  336. Author:
  337. 20-Mar-1996 Wed 15:36:48 created -by- Daniel Chou (danielc)
  338. Revision History:
  339. --*/
  340. {
  341. PTVWND pTVWnd;
  342. WNDPROC OldWndProc;
  343. if (OldWndProc = (WNDPROC)GetProp(hWnd, CPSUIPROP_WNDPROC)) {
  344. switch (Msg) {
  345. case WM_KEYDOWN:
  346. if (ChkEditKEYDOWN(hWnd, wParam)) {
  347. return(0);
  348. }
  349. break;
  350. case WM_DESTROY:
  351. SetWindowLongPtr(hWnd, GWLP_WNDPROC, (LPARAM)OldWndProc);
  352. RemoveProp(hWnd, CPSUIPROP_WNDPROC);
  353. RemoveProp(hWnd, CPSUIPROP_PTVWND);
  354. break;
  355. default:
  356. break;
  357. }
  358. return(CallWindowProc(OldWndProc, hWnd, Msg, wParam, lParam));
  359. } else {
  360. CPSUIERR(("MyEditWndProc: GetProc(%08lx) FAILED", hWnd));
  361. return(0);
  362. }
  363. }
  364. VOID
  365. DrawPushFocusRect(
  366. HWND hWnd
  367. )
  368. /*++
  369. Routine Description:
  370. Arguments:
  371. Return Value:
  372. Author:
  373. 13-Aug-1998 Thu 11:21:49 created -by- Daniel Chou (danielc)
  374. Revision History:
  375. --*/
  376. {
  377. if (GetFocus() == hWnd) {
  378. HDC hDC;
  379. RECT rc;
  380. GetClientRect(hWnd, &rc);
  381. hDC = GetWindowDC(hWnd);
  382. rc.left += 3;
  383. rc.top += 3;
  384. rc.right -= 3;
  385. rc.bottom -= 3;
  386. if (hDC) {
  387. DrawFocusRect(hDC, &rc);
  388. ReleaseDC(hWnd, hDC);
  389. }
  390. }
  391. }
  392. LRESULT
  393. CALLBACK
  394. PushWndProc(
  395. HWND hWnd,
  396. UINT Msg,
  397. WPARAM wParam,
  398. LPARAM lParam
  399. )
  400. /*++
  401. Routine Description:
  402. This is the subclass WNDPROC for the numberical edit control, it check
  403. valid input for the number entered.
  404. Arguments:
  405. WNDPROC standard
  406. Return Value:
  407. INT (The original WNDPROC returned), if the entered keys are not valid
  408. then it return right away without processing
  409. Author:
  410. 20-Mar-1996 Wed 15:36:48 created -by- Daniel Chou (danielc)
  411. Revision History:
  412. --*/
  413. {
  414. HDC hDC;
  415. PTVWND pTVWnd;
  416. WNDPROC OldWndProc;
  417. RECT rc;
  418. LRESULT Result;
  419. if (OldWndProc = (WNDPROC)GetProp(hWnd, CPSUIPROP_WNDPROC)) {
  420. switch (Msg) {
  421. case WM_KILLFOCUS:
  422. break;
  423. case WM_SETFOCUS:
  424. InvalidateRect(hWnd, NULL, FALSE);
  425. break;
  426. case WM_PAINT:
  427. case WM_NCPAINT:
  428. Result = CallWindowProc(OldWndProc, hWnd, Msg, wParam, lParam);
  429. DrawPushFocusRect(hWnd);
  430. return(Result);
  431. case WM_GETDLGCODE:
  432. return(DLGC_WANTARROWS);
  433. case WM_KEYDOWN:
  434. CPSUIDBG(DBG_KEYS,
  435. ("PushWndProc: WM_KEYDOWN, VKey=%ld", wParam));
  436. if (ChkhWndEdit0KEYDOWN(hWnd, wParam)) {
  437. return(0);
  438. }
  439. break;
  440. case WM_DESTROY:
  441. SetWindowLongPtr(hWnd, GWLP_WNDPROC, (LPARAM)OldWndProc);
  442. RemoveProp(hWnd, CPSUIPROP_WNDPROC);
  443. RemoveProp(hWnd, CPSUIPROP_PTVWND);
  444. break;
  445. default:
  446. break;
  447. }
  448. return(CallWindowProc(OldWndProc, hWnd, Msg, wParam, lParam));
  449. } else {
  450. CPSUIERR(("PushWndProc: GetProc(%08lx) FAILED", hWnd));
  451. return(0);
  452. }
  453. }
  454. LRESULT
  455. CALLBACK
  456. ExtWndProc(
  457. HWND hWnd,
  458. UINT Msg,
  459. WPARAM wParam,
  460. LPARAM lParam
  461. )
  462. /*++
  463. Routine Description:
  464. This is the subclass WNDPROC for the numberical edit control, it check
  465. valid input for the number entered.
  466. Arguments:
  467. WNDPROC standard
  468. Return Value:
  469. INT (The original WNDPROC returned), if the entered keys are not valid
  470. then it return right away without processing
  471. Author:
  472. 20-Mar-1996 Wed 15:36:48 created -by- Daniel Chou (danielc)
  473. Revision History:
  474. --*/
  475. {
  476. HDC hDC;
  477. PTVWND pTVWnd;
  478. WNDPROC OldWndProc;
  479. RECT rc;
  480. LRESULT Result;
  481. if (OldWndProc = (WNDPROC)GetProp(hWnd, CPSUIPROP_WNDPROC)) {
  482. switch (Msg) {
  483. case WM_KILLFOCUS:
  484. break;
  485. case WM_SETFOCUS:
  486. InvalidateRect(hWnd, NULL, FALSE);
  487. break;
  488. case WM_PAINT:
  489. case WM_NCPAINT:
  490. Result = CallWindowProc(OldWndProc, hWnd, Msg, wParam, lParam);
  491. if ((GetWindowLongPtr(hWnd, GWL_STYLE) & 0x0F) == 0) {
  492. DrawPushFocusRect(hWnd);
  493. }
  494. return(Result);
  495. case WM_GETDLGCODE:
  496. return(DLGC_WANTARROWS);
  497. case WM_KEYDOWN:
  498. CPSUIDBG(DBG_KEYS,
  499. ("ExtWndProc: WM_KEYDOWN, VKey=%ld", wParam));
  500. switch (wParam) {
  501. case VK_LEFT:
  502. case VK_BACK:
  503. case VK_RIGHT:
  504. if (pTVWnd = (PTVWND)GetProp(hWnd, CPSUIPROP_PTVWND)) {
  505. switch (wParam) {
  506. case VK_LEFT:
  507. case VK_BACK:
  508. if (pTVWnd->hWndEdit[0]) {
  509. SetFocus(pTVWnd->hWndEdit[0]);
  510. return(0);
  511. }
  512. case VK_RIGHT:
  513. return(0);
  514. default:
  515. break;
  516. }
  517. }
  518. break;
  519. }
  520. break;
  521. case WM_DESTROY:
  522. SetWindowLongPtr(hWnd, GWLP_WNDPROC, (LPARAM)OldWndProc);
  523. RemoveProp(hWnd, CPSUIPROP_WNDPROC);
  524. RemoveProp(hWnd, CPSUIPROP_PTVWND);
  525. break;
  526. default:
  527. break;
  528. }
  529. return(CallWindowProc(OldWndProc, hWnd, Msg, wParam, lParam));
  530. } else {
  531. CPSUIERR(("MyCBWndProc: GetProc(%08lx) FAILED", hWnd));
  532. return(0);
  533. }
  534. }
  535. VOID
  536. InitDlgCtrl(
  537. HWND hDlg,
  538. PTVWND pTVWnd
  539. )
  540. /*++
  541. Routine Description:
  542. Arguments:
  543. Return Value:
  544. Author:
  545. 05-Jul-1995 Wed 17:49:58 created -by- Daniel Chou (danielc)
  546. Revision History:
  547. --*/
  548. {
  549. HWND hWndTV = pTVWnd->hWndTV;
  550. HFONT hFont;
  551. HWND hCtrl;
  552. RECT rc;
  553. RECT rc2;
  554. DWORD dw;
  555. WORD tECB;
  556. WORD bECB;
  557. WORD tLB;
  558. WORD bLB;
  559. WORD cyUnit;
  560. WORD cyStates;
  561. LONG tOpt;
  562. LONG bOpt;
  563. LONG cx;
  564. LONG cy;
  565. UINT i;
  566. WORD InitItemIdx = 0xFFFE;
  567. ReCreateLBCB(hDlg, IDD_TV_LB, TRUE);
  568. dw = ReCreateLBCB(hDlg, IDD_TV_CB, FALSE);
  569. CreateTrackBar(hDlg, IDD_TV_TRACKBAR);
  570. CreateUDArrow(hDlg, IDD_TV_UDARROW_EDIT, IDD_TV_UDARROW, 0, 100, 50);
  571. #if DO_IN_PLACE
  572. CtrlIDrcWnd(hDlg, IDD_TV_UDARROW, &rc);
  573. CtrlIDrcWnd(hDlg, IDD_TV_UDARROW_EDIT, &rc2);
  574. pTVWnd->cxCBAdd = LOWORD(dw);
  575. pTVWnd->cxMaxUDEdit += LOWORD(dw);
  576. CtrlIDrcWnd(hDlg, IDD_TV_CHKBOX, &rc);
  577. pTVWnd->cxChkBoxAdd = (WORD)(rc.right - rc.left);
  578. pTVWnd->cxChkBoxAdd = (WORD)GetSystemMetrics(SM_CXSMICON);
  579. CPSUIINT(("cxCBAdd = %ld, cxChkBoxAdd=%ld",
  580. pTVWnd->cxCBAdd, pTVWnd->cxChkBoxAdd));
  581. if (hCtrl = GetDlgItem(hDlg, IDD_TV_EDIT_EDIT)) {
  582. SetProp(hCtrl,
  583. CPSUIPROP_WNDPROC,
  584. (HANDLE)GetWindowLongPtr(hCtrl, GWLP_WNDPROC));
  585. SetProp(hCtrl, CPSUIPROP_PTVWND, (HANDLE)pTVWnd);
  586. SetWindowLongPtr(hCtrl, GWLP_WNDPROC, (LPARAM)MyEditWndProc);
  587. }
  588. if (hCtrl = GetDlgItem(hDlg, IDD_TV_PUSH)) {
  589. SetProp(hCtrl,
  590. CPSUIPROP_WNDPROC,
  591. (HANDLE)GetWindowLongPtr(hCtrl, GWLP_WNDPROC));
  592. SetProp(hCtrl, CPSUIPROP_PTVWND, (HANDLE)pTVWnd);
  593. SetWindowLongPtr(hCtrl, GWLP_WNDPROC, (LPARAM)PushWndProc);
  594. }
  595. hFont = pTVWnd->hTVFont[0];
  596. #endif
  597. for (i = 0; i < COUNT_ARRAY(TVDlgItem); i++) {
  598. TVDLGITEM tdi;
  599. tdi = TVDlgItem[i];
  600. while (tdi.cItem--) {
  601. if (hCtrl = GetDlgItem(hDlg, tdi.BegID++)) {
  602. ShowWindow(hCtrl, SW_HIDE);
  603. EnableWindow(hCtrl, FALSE);
  604. SETCTRLDATA(hCtrl, CTRLS_TV_STATIC, 0);
  605. #if DO_IN_PLACE
  606. SetParent(hCtrl, hWndTV);
  607. SendMessage(hCtrl, WM_SETFONT, (WPARAM)hFont, 0);
  608. SetWindowLongPtr(hCtrl,
  609. GWL_EXSTYLE,
  610. GetWindowLongPtr(hCtrl, GWL_EXSTYLE) |
  611. WS_EX_CONTEXTHELP);
  612. #endif
  613. if (tdi.BegID == (IDD_TV_TRACKBAR + 1)) {
  614. tdi.BegID = IDD_TV_SB_LOW;
  615. }
  616. }
  617. }
  618. }
  619. //
  620. // Set MSAA name label as a child of treeview dialog
  621. //
  622. if (hCtrl = GetDlgItem(hDlg, IDD_TV_MSAA_NAME))
  623. {
  624. SetParent(hCtrl, hWndTV);
  625. }
  626. //
  627. // Figure how to expand/shrink the listbox in the treeview page, the
  628. // maximum for non ExtChkBox/ExtPush is at bottom of Extended control
  629. // otherwise the maximu is at top of Extended control - space between
  630. // bottom of extended control and option header bottom
  631. //
  632. #if DO_IN_PLACE
  633. hCtrl = GetDlgItem(hWndTV, IDD_TV_EXTPUSH);
  634. #else
  635. hCtrl = GetDlgItem(hDlg, IDD_TV_EXTPUSH);
  636. #endif
  637. ShowWindow(hCtrl, SW_HIDE);
  638. EnableWindow(hCtrl, FALSE);
  639. SetProp(hCtrl,
  640. CPSUIPROP_WNDPROC,
  641. (HANDLE)GetWindowLongPtr(hCtrl, GWLP_WNDPROC));
  642. SetProp(hCtrl, CPSUIPROP_PTVWND, (HANDLE)pTVWnd);
  643. SetWindowLongPtr(hCtrl, GWLP_WNDPROC, (LPARAM)ExtWndProc);
  644. #if DO_IN_PLACE
  645. hCtrl = CtrlIDrcWnd(hWndTV, IDD_TV_EXTCHKBOX, &rc);
  646. #else
  647. hCtrl = CtrlIDrcWnd(hDlg, IDD_TV_EXTCHKBOX, &rc);
  648. #endif
  649. ShowWindow(hCtrl, SW_HIDE);
  650. EnableWindow(hCtrl, FALSE);
  651. SETCTRLDATA(hCtrl, CTRLS_TV_STATIC, 0);
  652. pTVWnd->yECB =
  653. tECB = (WORD)rc.top;
  654. bECB = (WORD)rc.bottom;
  655. #if DO_IN_PLACE
  656. SetProp(hCtrl,
  657. CPSUIPROP_WNDPROC,
  658. (HANDLE)GetWindowLongPtr(hCtrl, GWLP_WNDPROC));
  659. SetProp(hCtrl, CPSUIPROP_PTVWND, (HANDLE)pTVWnd);
  660. SetWindowLongPtr(hCtrl, GWLP_WNDPROC, (LPARAM)ExtWndProc);
  661. CtrlIDrcWnd(hWndTV, IDD_TV_LB, &rc);
  662. #else
  663. CtrlIDrcWnd(hDlg, IDD_TV_LB, &rc);
  664. #endif
  665. pTVWnd->xCtrls = (WORD)rc.left;
  666. pTVWnd->tLB =
  667. tLB = (WORD)rc.top;
  668. bLB = (WORD)rc.bottom;
  669. hCtrl = CtrlIDrcWnd(hDlg, IDD_TV_OPTION, &rc);
  670. ShowWindow(hCtrl, SW_HIDE);
  671. EnableWindow(hCtrl, TRUE);
  672. SETCTRLDATA(hCtrl, CTRLS_TV_STATIC, 0);
  673. pTVWnd->yLB[0] = (WORD)(tECB - (rc.bottom - bECB) - tLB);
  674. pTVWnd->yLB[1] = bECB - tLB;
  675. tOpt = tLB;
  676. bOpt = tECB;
  677. CPSUIDBG(DBG_INITDLG, ("!! yLB=(%ld / %ld) !!",
  678. pTVWnd->yLB[0], pTVWnd->yLB[1]));
  679. //
  680. // Figure how to move 2 states, and 3 states, basically this is range
  681. // in the space between top and bottom of options header
  682. //
  683. #if DO_IN_PLACE
  684. CtrlIDrcWnd(hWndTV, IDD_3STATES_1, &rc);
  685. #else
  686. CtrlIDrcWnd(hDlg, IDD_3STATES_1, &rc);
  687. #endif
  688. cyStates = (WORD)(rc.bottom - rc.top);
  689. //
  690. // For 2/3 states, there is top, increment, one with extended and one not
  691. //
  692. cy = (LONG)(bLB - tLB);
  693. cyUnit = (WORD)((cy - (cyStates * 2) + 1) / 3);
  694. pTVWnd->SI2[0].Top = tLB + (WORD)cyUnit;
  695. pTVWnd->SI2[0].Inc = (WORD)(cyStates + cyUnit);
  696. cyUnit = (WORD)((cy - (cyStates * 3) + 2) / 4);
  697. pTVWnd->SI3[0].Top = tLB + (WORD)cyUnit;
  698. pTVWnd->SI3[0].Inc = (WORD)(cyStates + cyUnit);
  699. cy = (LONG)(bOpt - tOpt);
  700. cyUnit = (WORD)((cy - (cyStates * 2) + 1) / 3);
  701. pTVWnd->SI2[1].Top = (WORD)tOpt + (WORD)cyUnit;
  702. pTVWnd->SI2[1].Inc = (WORD)(cyStates + cyUnit);
  703. cyUnit = (WORD)((cy - (cyStates * 3) + 2) / 4);
  704. pTVWnd->SI3[1].Top = (WORD)tOpt + (WORD)cyUnit;
  705. pTVWnd->SI3[1].Inc = (WORD)(cyStates + cyUnit);
  706. CPSUIINT(("SI2[0]=%d, %d, SI2[1]=%d, %d, SI3[0]=%d, %d, SI3[1]=%d, %d",
  707. pTVWnd->SI2[0].Top, pTVWnd->SI2[0].Inc,
  708. pTVWnd->SI2[1].Top, pTVWnd->SI2[1].Inc,
  709. pTVWnd->SI3[0].Top, pTVWnd->SI3[0].Inc,
  710. pTVWnd->SI3[1].Top, pTVWnd->SI3[1].Inc));
  711. //
  712. // Change the static rectangle to the static ICON style and how big the
  713. // icon will stretch to
  714. //
  715. hCtrl = CtrlIDrcWnd(hDlg, IDD_TV_ICON, &rc);
  716. dw = (DWORD)GetWindowLongPtr(hCtrl, GWL_STYLE);
  717. dw &= ~SS_TYPEMASK;
  718. dw |= (SS_ICON | SS_CENTERIMAGE);
  719. SetWindowLongPtr(hCtrl, GWL_STYLE, dw);
  720. ShowWindow(hCtrl, SW_HIDE);
  721. EnableWindow(hCtrl, TRUE);
  722. SETCTRLDATA(hCtrl, CTRLS_TV_STATIC, 0);
  723. //
  724. // We want to make sure that the cx/cy TVICON is the same size, if not
  725. // then we will correct it and adjust it to the right size
  726. //
  727. #if ICON_SIZE_ANY
  728. if ((cx = rc.right - rc.left) != (cy = rc.bottom - rc.top)) {
  729. CPSUIINT(("\nORIGINAL TVIcon=(%ld, %ld) %ld x %ld",
  730. rc.left, rc.top, cx, cy));
  731. cy = cx;
  732. }
  733. #else
  734. cx =
  735. cy = 32;
  736. #endif
  737. rc.left = rc.left + ((rc.right - rc.left - cx + 1) / 2);
  738. rc.top = (LONG)(tOpt + ((bOpt - tOpt - cy + 1) / 2));
  739. SetWindowPos(hCtrl, NULL, rc.left, rc.top, cx, cy, SWP_NOZORDER);
  740. CPSUIINT(("\nCHANGED TVIcon=(%ld, %ld) %ld x %ld",
  741. rc.left, rc.top, cx, cy));
  742. pTVWnd->cxcyTVIcon = (WORD)cx;
  743. CPSUIDBG(DBG_CTVWND, ("\nIDD_TV_ICON Style=%08lx", dw));
  744. //
  745. // now check it out ECB icon
  746. //
  747. hCtrl = CtrlIDrcWnd(hDlg, IDD_TV_ECB_ICON, &rc);
  748. dw = (DWORD)GetWindowLongPtr(hCtrl = GetDlgItem(hDlg, IDD_TV_ECB_ICON), GWL_STYLE);
  749. dw &= ~SS_TYPEMASK;
  750. dw |= (SS_ICON | SS_CENTERIMAGE);
  751. SetWindowLongPtr(hCtrl, GWL_STYLE, dw);
  752. //
  753. // We want to make sure that the cx/cy ECBICON is the same size, if not
  754. // then we will correct it and adjust it to the right size
  755. //
  756. if ((cx = rc.right - rc.left) != (cy = rc.bottom - rc.top)) {
  757. CPSUIINT(("\nORIGINAL ECBIcon=(%ld, %ld) %ld x %ld",
  758. rc.left, rc.top, cx, cy));
  759. rc.right = rc.left + (cx = cy);
  760. SetWindowPos(hCtrl, NULL, rc.left, rc.top, cx, cy, SWP_NOZORDER);
  761. CPSUIINT(("\nCHANGED ECBIcon=(%ld, %ld) %ld x %ld",
  762. rc.left, rc.top, cx, cy));
  763. }
  764. pTVWnd->cxcyECBIcon = (WORD)cx;
  765. CPSUIDBG(DBG_CTVWND,
  766. ("\nTVIcon=%ld x %ld, ECBIcon=%ld x %ld",
  767. (DWORD)pTVWnd->cxcyTVIcon, (DWORD)pTVWnd->cxcyTVIcon,
  768. (DWORD)pTVWnd->cxcyECBIcon, (DWORD)pTVWnd->cxcyECBIcon));
  769. }
  770. HTREEITEM
  771. SelectFirstVisibleOptItem(
  772. PTVWND pTVWnd,
  773. HTREEITEM hItem
  774. )
  775. /*++
  776. Routine Description:
  777. Arguments:
  778. Return Value:
  779. Author:
  780. 21-Sep-1995 Thu 14:31:01 created -by- Daniel Chou (danielc)
  781. Revision History:
  782. --*/
  783. {
  784. HWND hWndTV = pTVWnd->hWndTV;
  785. //
  786. // Do all the siblings and for each calling the child to do their work
  787. //
  788. while (hItem) {
  789. POPTITEM pItem;
  790. TV_ITEM tvi;
  791. tvi.mask = TVIF_CHILDREN | TVIF_HANDLE | TVIF_PARAM | TVIF_STATE;
  792. tvi.hItem = hItem;
  793. TreeView_GetItem(hWndTV, &tvi);
  794. //
  795. // Now check if we can do it
  796. //
  797. if ((pItem = GetOptions(pTVWnd, tvi.lParam)) &&
  798. (pItem->pOptType) &&
  799. (!IS_HDR_PUSH(pItem->pOptType)) &&
  800. (pItem->pOptType->Type <= TVOT_LAST)) {
  801. TreeView_SelectItem(hWndTV, hItem);
  802. return(hItem);
  803. }
  804. if ((tvi.cChildren) &&
  805. (tvi.state & TVIS_EXPANDED) &&
  806. (hItem = TreeView_GetChild(hWndTV, hItem)) &&
  807. (hItem = SelectFirstVisibleOptItem(pTVWnd, hItem))) {
  808. return(hItem);
  809. }
  810. hItem = TreeView_GetNextSibling(hWndTV, hItem);
  811. }
  812. return(hItem);
  813. }
  814. UINT
  815. CountRevertOptItem(
  816. PTVWND pTVWnd,
  817. POPTITEM pOptItem,
  818. HTREEITEM hItem,
  819. DWORD Flags
  820. )
  821. /*++
  822. Routine Description:
  823. Arguments:
  824. Return Value:
  825. Author:
  826. 21-Sep-1995 Thu 14:31:01 created -by- Daniel Chou (danielc)
  827. Revision History:
  828. --*/
  829. {
  830. HWND hWndTV = pTVWnd->hWndTV;
  831. POPTITEM pLastItem;
  832. UINT cRevert = 0;
  833. NM_TREEVIEW NMtv;
  834. //
  835. // Do all the siblings and for each calling the child to do their work
  836. //
  837. if ((hWndTV) && (hItem)) {
  838. pOptItem =
  839. pLastItem = NULL;
  840. } else {
  841. Flags |= CROIF_DO_SIBLING;
  842. hItem = (HTREEITEM)1;
  843. if (!pOptItem) {
  844. pOptItem = pTVWnd->ComPropSheetUI.pOptItem;
  845. pLastItem = pTVWnd->pLastItem;
  846. } else {
  847. pLastItem = pOptItem;
  848. }
  849. }
  850. while (hItem) {
  851. POPTITEM pItem;
  852. PDEVHTADJDATA pDevHTAdjData;
  853. POPTTYPE pOptType;
  854. POPTPARAM pOptParam;
  855. TV_ITEM tvi;
  856. UINT cAdd = 0;
  857. if (pOptItem) {
  858. pItem = pOptItem;
  859. } else {
  860. tvi.mask = TVIF_CHILDREN | TVIF_HANDLE | TVIF_PARAM | TVIF_STATE;
  861. tvi.hItem = hItem;
  862. TreeView_GetItem(hWndTV, &tvi);
  863. pItem = GetOptions(pTVWnd, tvi.lParam);
  864. }
  865. //
  866. // Now check if we can do it
  867. //
  868. if ((pItem) &&
  869. ((pItem->Flags & OPTIF_CHANGEONCE) ||
  870. (Flags & CROIF_REVERT_DEF2)) &&
  871. (pOptType = pItem->pOptType)) {
  872. LPBYTE pDefSelMem;
  873. LPVOID pDefSel;
  874. LPVOID pvAlloc;
  875. DWORD DefOPTIF;
  876. pvAlloc =
  877. pDefSel = (LPVOID)(pDefSelMem = (LPBYTE)_OI_PDEFSEL(pItem));
  878. if (Flags & CROIF_REVERT_DEF2) {
  879. DefOPTIF = (DWORD)_OI_DEF_OPTIF2(pItem);
  880. pDefSelMem += _OI_CBPDEFSEL(pItem);
  881. pDefSel = _OI_PDEFSEL2(pItem);
  882. } else {
  883. DefOPTIF = (DWORD)_OI_DEF_OPTIF(pItem);
  884. }
  885. switch (pOptType->Type) {
  886. case TVOT_EDITBOX:
  887. if (!pvAlloc) {
  888. CPSUIASSERT(0, "CountRevertOptItem(EDITBOX:pvAlloc=NULL)", pvAlloc, 0);
  889. break;
  890. }
  891. if (pTVWnd->Flags & TWF_ANSI_CALL) {
  892. CPSUIINT(("pEdit=%hs, pDefEdit=%hs",
  893. pItem->pSel, pDefSel));
  894. if (lstrcmpA((LPSTR)(LONG_PTR)pItem->Sel, (LPSTR)pDefSelMem)) {
  895. cAdd = 1;
  896. if (Flags & CROIF_REVERT) {
  897. StringCchCopyA((LPSTR)pItem->pSel, (size_t)pOptType->pOptParam[1].IconID, (LPSTR)pDefSelMem);
  898. }
  899. }
  900. } else {
  901. CPSUIINT(("pEdit=%s, pDefEdit=%s",
  902. pItem->pSel, pDefSel));
  903. if (lstrcmp(pItem->pSel, (LPWSTR)pDefSelMem)) {
  904. cAdd = 1;
  905. if (Flags & CROIF_REVERT) {
  906. StringCchCopy((LPWSTR)pItem->pSel, (size_t)pOptType->pOptParam[1].IconID, (LPWSTR)pDefSelMem);
  907. }
  908. }
  909. }
  910. break;
  911. case TVOT_PUSHBUTTON:
  912. pOptParam = pOptType->pOptParam;
  913. switch (pOptParam->Style) {
  914. case PUSHBUTTON_TYPE_HTSETUP:
  915. if (!pvAlloc) {
  916. CPSUIASSERT(0, "CountRevertOptItem(HTSETUP:pvAlloc=NULL)", pvAlloc, 0);
  917. break;
  918. }
  919. pDevHTAdjData = (PDEVHTADJDATA)(pOptParam->pData);
  920. if (memcmp(pDefSelMem,
  921. pDevHTAdjData->pAdjHTInfo,
  922. sizeof(DEVHTINFO))) {
  923. cAdd = 1;
  924. if (Flags & CROIF_REVERT) {
  925. CopyMemory(pDevHTAdjData->pAdjHTInfo,
  926. pDefSelMem,
  927. sizeof(DEVHTINFO));
  928. }
  929. }
  930. break;
  931. case PUSHBUTTON_TYPE_HTCLRADJ:
  932. if (!pvAlloc) {
  933. CPSUIASSERT(0, "CountRevertOptItem(HTCLRADJ:pvAlloc=NULL)", pvAlloc, 0);
  934. break;
  935. }
  936. if (memcmp(pDefSelMem,
  937. pOptParam->pData,
  938. sizeof(COLORADJUSTMENT))) {
  939. cAdd = 1;
  940. if (Flags & CROIF_REVERT) {
  941. CopyMemory(pOptParam->pData,
  942. pDefSelMem,
  943. sizeof(COLORADJUSTMENT));
  944. }
  945. }
  946. break;
  947. default:
  948. break;
  949. }
  950. break;
  951. default:
  952. if (pItem->pSel != (LPVOID)pDefSel) {
  953. cAdd = 1;
  954. if (Flags & CROIF_REVERT) {
  955. pItem->pSel = pDefSel;
  956. }
  957. }
  958. break;
  959. }
  960. if ((pItem->pExtChkBox) &&
  961. (!(pItem->Flags & OPTIF_EXT_IS_EXTPUSH)) &&
  962. ((pItem->Flags & OPTIF_ECB_MASK) !=
  963. (DefOPTIF & OPTIF_ECB_MASK))) {
  964. cAdd = 1;
  965. if (Flags & CROIF_REVERT) {
  966. pItem->Flags &= ~OPTIF_ECB_MASK;
  967. pItem->Flags |= (DWORD)(DefOPTIF & OPTIF_ECB_MASK);
  968. }
  969. }
  970. if (cAdd) {
  971. if (Flags & CROIF_REVERT) {
  972. pItem->Flags |= OPTIF_CHANGED;
  973. //
  974. // Call the callback function if there is one, and update the current
  975. // selected item after changing the content
  976. //
  977. DoCallBack(pTVWnd->hDlgTV,
  978. pTVWnd,
  979. pItem,
  980. pItem->pSel,
  981. NULL,
  982. NULL,
  983. 0,
  984. CPSUICB_REASON_SEL_CHANGED);
  985. //
  986. // Refresh the current selected item data, otherwise the data may
  987. // not be consistent
  988. //
  989. NMtv.itemNew.hItem = TreeView_GetSelection(pTVWnd->hWndTV);
  990. NMtv.itemNew.mask = TVIF_HANDLE | TVIF_PARAM;
  991. if (TreeView_GetItem(pTVWnd->hWndTV, &(NMtv.itemNew))) {
  992. NMtv.itemOld = NMtv.itemNew;
  993. SetupTVSelect(pTVWnd->hDlgTV, &NMtv, STVS_REINIT);
  994. }
  995. }
  996. CPSUIOPTITEM(DBGITEM_CREVERT,
  997. pTVWnd,
  998. "CountRevertOptItem",
  999. 0,
  1000. pItem);
  1001. }
  1002. cRevert += cAdd;
  1003. }
  1004. if (pOptItem) {
  1005. if (++pOptItem > pLastItem) {
  1006. hItem = NULL;
  1007. } else {
  1008. ++(ULONG_PTR)hItem;
  1009. }
  1010. } else {
  1011. if (tvi.cChildren) {
  1012. cRevert += CountRevertOptItem(pTVWnd,
  1013. NULL,
  1014. TreeView_GetChild(hWndTV, hItem),
  1015. Flags | CROIF_DO_SIBLING);
  1016. }
  1017. hItem = (Flags & CROIF_DO_SIBLING) ?
  1018. TreeView_GetNextSibling(hWndTV, hItem) : NULL;
  1019. }
  1020. }
  1021. CPSUIDBG(DBG_CTVWND, ("hWndTV=%08lx, hItem=%08lx, pOptItem=%08lx, cRevert=%u",
  1022. hWndTV, hItem, pOptItem, cRevert));
  1023. return(cRevert);
  1024. }
  1025. CPSUICALLBACK
  1026. InternalRevertDef2(
  1027. PCPSUICBPARAM pCBParam
  1028. )
  1029. /*++
  1030. Routine Description:
  1031. Arguments:
  1032. Return Value:
  1033. Author:
  1034. 21-Sep-1995 Thu 10:50:19 created -by- Daniel Chou (danielc)
  1035. Revision History:
  1036. --*/
  1037. {
  1038. PTVWND pTVWnd;
  1039. POPTITEM pItem;
  1040. UINT cRevert;
  1041. CPSUIINT(("INTERNAL CALLBACK: GOT Internal RevertOptItem() PUSH"));
  1042. pTVWnd = GET_PTVWND(pCBParam->hDlg);
  1043. pItem = pCBParam->pCurItem;
  1044. CPSUIOPTITEM(DBGITEM_REVERT,
  1045. pTVWnd,
  1046. "InternalRevertOptItem",
  1047. 2,
  1048. pItem);
  1049. cRevert = CountRevertOptItem(pTVWnd,
  1050. NULL,
  1051. NULL,
  1052. CROIF_REVERT | CROIF_REVERT_DEF2);
  1053. //
  1054. // Now is the time to hide the push button
  1055. //
  1056. return((cRevert) ? CPSUICB_ACTION_OPTIF_CHANGED : CPSUICB_ACTION_NONE);
  1057. }
  1058. CPSUICALLBACK
  1059. InternalRevertOptItem(
  1060. PCPSUICBPARAM pCBParam
  1061. )
  1062. /*++
  1063. Routine Description:
  1064. Arguments:
  1065. Return Value:
  1066. Author:
  1067. 21-Sep-1995 Thu 10:50:19 created -by- Daniel Chou (danielc)
  1068. Revision History:
  1069. --*/
  1070. {
  1071. PTVWND pTVWnd;
  1072. POPTITEM pItem;
  1073. UINT cRevert;
  1074. CPSUIINT(("INTERNAL CALLBACK: GOT Internal RevertOptItem() PUSH"));
  1075. pTVWnd = GET_PTVWND(pCBParam->hDlg);
  1076. pItem = pCBParam->pCurItem;
  1077. CPSUIOPTITEM(DBGITEM_REVERT,
  1078. pTVWnd,
  1079. "InternalRevertOptItem",
  1080. 2,
  1081. pItem);
  1082. cRevert = CountRevertOptItem(pTVWnd,
  1083. pItem,
  1084. _OI_HITEM(pItem),
  1085. CROIF_REVERT);
  1086. //
  1087. // Now is the time to hide the push button
  1088. //
  1089. #if DO_IN_PLACE
  1090. return((cRevert) ? CPSUICB_ACTION_OPTIF_CHANGED : CPSUICB_ACTION_NONE);
  1091. #else
  1092. if (cRevert) {
  1093. if ((pItem >= pTVWnd->ComPropSheetUI.pOptItem) &&
  1094. (pItem <= pTVWnd->pLastItem)) {
  1095. pItem->Flags |= OPTIF_CHANGED;
  1096. } else {
  1097. UpdateTreeViewItem(pCBParam->hDlg, pTVWnd, pItem, TRUE);
  1098. }
  1099. return(CPSUICB_ACTION_OPTIF_CHANGED);
  1100. } else {
  1101. return(CPSUICB_ACTION_NONE);
  1102. }
  1103. #endif
  1104. }
  1105. BOOL
  1106. SetTVItemImage(
  1107. PTVWND pTVWnd,
  1108. TV_DISPINFO *ptvdi
  1109. )
  1110. /*++
  1111. Routine Description:
  1112. This function either insert a item to the tree or reset the content of
  1113. the tree item
  1114. Arguments:
  1115. pTVWnd - Pointer to the TVWND for common UI instance data
  1116. ptvi - pointer to TV_ITEM strucuture.
  1117. Return Value:
  1118. BOOLEAN
  1119. Author:
  1120. 06-Jul-1995 Thu 19:38:51 created -by- Daniel Chou (danielc)
  1121. 31-Aug-1995 Thu 12:03:32 updated -by- Daniel Chou (danielc)
  1122. Updated so it will not take pStrName anymore and it will also insert
  1123. the item at this function
  1124. Revision History:
  1125. --*/
  1126. {
  1127. TV_ITEM *ptvi = &(ptvdi->item);
  1128. if (ptvi->mask & (TVIF_IMAGE | TVIF_SELECTEDIMAGE)) {
  1129. POPTTYPE pOptType;
  1130. POPTITEM pItem;
  1131. ULONG_PTR IconResID;
  1132. DWORD IntIconID;
  1133. pItem = GetOptions(pTVWnd, ptvi->lParam);
  1134. if (IS_HDR_PUSH(pOptType = GET_POPTTYPE(pItem))) {
  1135. IconResID = GETSELICONID(pItem);
  1136. IntIconID = IDI_CPSUI_GENERIC_OPTION;
  1137. } else {
  1138. PEXTCHKBOX pECB;
  1139. POPTPARAM pOptParam = pOptType->pOptParam;
  1140. switch (pOptType->Type) {
  1141. case TVOT_COMBOBOX:
  1142. case TVOT_LISTBOX:
  1143. if ((DWORD)pItem->Sel >= (DWORD)pOptType->Count) {
  1144. pOptParam = &pTVWnd->OptParamNone;
  1145. break;
  1146. }
  1147. case TVOT_2STATES:
  1148. case TVOT_3STATES:
  1149. pOptParam += (DWORD)pItem->Sel;
  1150. break;
  1151. case TVOT_CHKBOX:
  1152. case TVOT_TRACKBAR:
  1153. case TVOT_SCROLLBAR:
  1154. case TVOT_UDARROW:
  1155. case TVOT_PUSHBUTTON:
  1156. case TVOT_EDITBOX:
  1157. break;
  1158. }
  1159. IconResID = GET_ICONID(pOptParam, OPTPF_ICONID_AS_HICON);
  1160. IntIconID = IDI_CPSUI_GENERIC_ITEM;
  1161. }
  1162. ptvi->iSelectedImage =
  1163. ptvi->iImage = (INT)GetIcon16Idx(pTVWnd,
  1164. _OI_HINST(pItem),
  1165. IconResID,
  1166. IntIconID);
  1167. ptvi->hItem = _OI_HITEM(pItem);
  1168. ptvi->mask = (TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_HANDLE);
  1169. SendMessage(pTVWnd->hWndTV, TVM_SETITEM, 0, (LPARAM)ptvi);
  1170. CPSUIOPTITEM(DBGITEM_NEWICON, pTVWnd, "SetTVItemImage", 0, pItem);
  1171. }
  1172. return(TRUE);
  1173. }
  1174. VOID
  1175. SetTVItemState(
  1176. PTVWND pTVWnd,
  1177. TV_INSERTSTRUCT *ptvins,
  1178. POPTITEM pCurItem
  1179. )
  1180. /*++
  1181. Routine Description:
  1182. This function either insert a item to the tree or reset the content of
  1183. the tree item
  1184. Arguments:
  1185. pTVWnd - Pointer to the TVWND for common UI instance data
  1186. ptvins - pointer to TV_INSERTSTRUCT strucuture, if it is not NULL then
  1187. this item will be inserted to the tree
  1188. pCurItem - Pointer to the current OPTITEM
  1189. Return Value:
  1190. WORD - Icon resource ID
  1191. Author:
  1192. 06-Jul-1995 Thu 19:38:51 created -by- Daniel Chou (danielc)
  1193. 31-Aug-1995 Thu 12:03:32 updated -by- Daniel Chou (danielc)
  1194. Updated so it will not take pStrName anymore and it will also insert
  1195. the item at this function
  1196. 20-Jul-1996 Sat 00:26:33 updated -by- Daniel Chou (danielc)
  1197. Fixed the internationalize problem for compsition dynamic user data
  1198. Revision History:
  1199. --*/
  1200. {
  1201. POPTTYPE pOptType;
  1202. TV_INSERTSTRUCT tvins;
  1203. TVLP tvlp;
  1204. ULONG_PTR IconResID;
  1205. DWORD IntIconID;
  1206. DWORD Flags;
  1207. GSBUF_DEF(pCurItem, MAX_RES_STR_CHARS * 2);
  1208. if (ptvins) {
  1209. tvins = *ptvins;
  1210. tvins.item.mask |= TVIF_TEXT |
  1211. TVIF_PARAM |
  1212. TVIF_IMAGE |
  1213. TVIF_SELECTEDIMAGE |
  1214. TVIF_STATE;
  1215. } else {
  1216. CPSUIASSERT(0, "SetTVItemState, NULL hItem", _OI_HITEM(pCurItem),0);
  1217. if (!(tvins.item.hItem = _OI_HITEM(pCurItem))) {
  1218. CPSUIOPTITEM(DBG_ASSERT,
  1219. pTVWnd,
  1220. "SetTVItemState(NULL)", 1,
  1221. pCurItem);
  1222. return;
  1223. }
  1224. tvins.item.state =
  1225. tvins.item.stateMask = 0;
  1226. tvins.item.mask = TVIF_HANDLE |
  1227. TVIF_PARAM |
  1228. TVIF_TEXT |
  1229. TVIF_IMAGE |
  1230. TVIF_SELECTEDIMAGE |
  1231. TVIF_STATE;
  1232. }
  1233. if ((pCurItem >= pTVWnd->ComPropSheetUI.pOptItem) &&
  1234. (pCurItem <= pTVWnd->pLastItem)) {
  1235. tvlp.ItemIdx = (WORD)(pCurItem - pTVWnd->ComPropSheetUI.pOptItem);
  1236. } else if ((pCurItem >= PBEG_INTOPTITEM(pTVWnd)) &&
  1237. (pCurItem <= PEND_INTOPTITEM(pTVWnd))) {
  1238. tvlp.ItemIdx = (WORD)IIDX_INTOPTITEM(pTVWnd, pCurItem);
  1239. } else {
  1240. CPSUIERR(("ERROR: SetupTVItemState(Invalid pOptItem=%08lx)", pCurItem));
  1241. tvlp.ItemIdx = INTIDX_TVROOT;
  1242. }
  1243. tvins.item.pszText = GSBUF_BUF;
  1244. //
  1245. // Check if we need to overlay CPSUI provided icons
  1246. //
  1247. tvlp.Flags = ((Flags = pCurItem->Flags) & OPTIF_OVERLAY_WARNING_ICON) ?
  1248. TVLPF_WARNING : 0;
  1249. if (Flags & (OPTIF_OVERLAY_STOP_ICON | OPTIF_HIDE)) {
  1250. tvlp.Flags |= TVLPF_STOP;
  1251. }
  1252. if (Flags & OPTIF_OVERLAY_NO_ICON) {
  1253. tvlp.Flags |= TVLPF_NO;
  1254. }
  1255. if (IS_HDR_PUSH(pOptType = GET_POPTTYPE(pCurItem))) {
  1256. POPTITEM pRootItem = PIDX_INTOPTITEM(pTVWnd, INTIDX_TVROOT);
  1257. if (pCurItem == pRootItem) {
  1258. GSBUF_FLAGS |= GBF_PREFIX_OK;
  1259. GSBUF_COMPOSE(LODWORD(pCurItem->UserData), pCurItem->pName, 0, 0);
  1260. } else if (pCurItem == PIDX_INTOPTITEM(pTVWnd, INTIDX_OPTIONS)) {
  1261. //
  1262. // Make it 'Document Options' here
  1263. //
  1264. GSBUF_GETINTSTR(IDS_INT_CPSUI_OPTIONS);
  1265. } else {
  1266. GSBUF_GETSTR(pCurItem->pName);
  1267. }
  1268. tvlp.cName = (BYTE)(GSBUF_COUNT);
  1269. CPSUIINT(("HeaderItem (%ld): '%ws'", tvlp.cName, GSBUF_BUF));
  1270. IconResID = GETSELICONID(pCurItem);
  1271. IntIconID = IDI_CPSUI_GENERIC_OPTION;
  1272. #if DO_IN_PLACE
  1273. if ((!IconResID) ||
  1274. (!GetIcon16Idx(pTVWnd,
  1275. _OI_HINST(pCurItem),
  1276. IconResID,
  1277. IDI_CPSUI_EMPTY))) {
  1278. tvins.item.mask &= ~(TVIF_IMAGE | TVIF_SELECTEDIMAGE);
  1279. tvlp.Flags |= TVLPF_EMPTYICON;
  1280. }
  1281. #endif
  1282. } else {
  1283. POPTPARAM pOptParam;
  1284. PEXTCHKBOX pECB;
  1285. LPTSTR pEndText = NULL;
  1286. UINT Idx;
  1287. BOOL RealECBChecked;
  1288. BOOL EndTextAddSpace;
  1289. #if DO_IN_PLACE
  1290. tvins.item.mask &= ~(TVIF_IMAGE | TVIF_SELECTEDIMAGE);
  1291. tvlp.Flags |= TVLPF_EMPTYICON;
  1292. #endif
  1293. GSBUF_GETSTR(pCurItem->pName);
  1294. pOptParam = pOptType->pOptParam;
  1295. if (RealECBChecked = REAL_ECB_CHECKED(pCurItem, pECB)) {
  1296. if (pECB->Flags & ECBF_OVERLAY_ECBICON_IF_CHECKED) {
  1297. tvlp.Flags |= TVLPF_ECBICON;
  1298. if (pECB->Flags & ECBF_OVERLAY_WARNING_ICON) {
  1299. tvlp.Flags |= TVLPF_WARNING;
  1300. }
  1301. if (pECB->Flags & ECBF_OVERLAY_STOP_ICON) {
  1302. tvlp.Flags |= TVLPF_STOP;
  1303. }
  1304. if (pECB->Flags & ECBF_OVERLAY_NO_ICON) {
  1305. tvlp.Flags |= TVLPF_NO;
  1306. }
  1307. }
  1308. }
  1309. if ((RealECBChecked) &&
  1310. ((!(Flags & OPTIF_EXT_DISABLED)) ||
  1311. (!(pECB->Flags & ECBF_CHECKNAME_ONLY_ENABLED)))) {
  1312. NULL;
  1313. } else {
  1314. pECB = NULL;
  1315. }
  1316. //
  1317. // PUSHBUTTON: PusName... <pCheckedName>
  1318. //
  1319. if (pOptType->Type == TVOT_PUSHBUTTON) {
  1320. if (!(pOptType->Style & OTS_PUSH_NO_DOT_DOT_DOT)) {
  1321. GSBUF_GETSTR(IDS_CPSUI_MORE);
  1322. }
  1323. } else {
  1324. GSBUF_GETSTR(IDS_CPSUI_COLON_SEP);
  1325. }
  1326. tvlp.cName = (BYTE)(GSBUF_COUNT);
  1327. CPSUIINT(("TreeviewItem (%ld): '%ws'", tvlp.cName, GSBUF_BUF));
  1328. if ((pECB) && (pECB->Flags & ECBF_CHECKNAME_ONLY)){
  1329. GSBUF_GETSTR(pECB->pCheckedName);
  1330. pECB = NULL;
  1331. } else {
  1332. if ((pECB) && (pECB->Flags & ECBF_CHECKNAME_AT_FRONT)) {
  1333. //
  1334. // pName: <pCheckedName SEP pSelection>
  1335. //
  1336. GSBUF_GETSTR(pECB->pCheckedName);
  1337. GSBUF_GETSTR(pECB->pSeparator);
  1338. pECB = NULL;
  1339. }
  1340. EndTextAddSpace = (!(pOptType->Flags & OPTTF_NOSPACE_BEFORE_POSTFIX));
  1341. switch (pOptType->Type) {
  1342. case TVOT_CHKBOX:
  1343. Idx = (UINT)(pCurItem->Sel + (pOptParam->Style << 1));
  1344. if (!(pEndText = (LPTSTR)ChkBoxStrID[Idx])) {
  1345. pEndText = pOptParam->pData;
  1346. }
  1347. GSBUF_GETSTR(pEndText);
  1348. pEndText = NULL;
  1349. break;
  1350. case TVOT_COMBOBOX:
  1351. case TVOT_LISTBOX:
  1352. if ((DWORD)pCurItem->Sel >= (DWORD)pOptType->Count) {
  1353. pOptParam = &pTVWnd->OptParamNone;
  1354. } else {
  1355. pOptParam += (DWORD)pCurItem->Sel;
  1356. }
  1357. GSBUF_GETSTR(pOptParam->pData);
  1358. break;
  1359. case TVOT_2STATES:
  1360. case TVOT_3STATES:
  1361. pOptParam += pCurItem->Sel;
  1362. GSBUF_GETSTR(pOptParam->pData);
  1363. break;
  1364. case TVOT_TRACKBAR:
  1365. case TVOT_SCROLLBAR:
  1366. GSBUF_ADDNUM(pCurItem->Sel * (LONG)pOptParam[2].IconID, TRUE);
  1367. pEndText = pOptParam->pData;
  1368. break;
  1369. case TVOT_UDARROW:
  1370. GSBUF_ADDNUM(pCurItem->Sel, TRUE);
  1371. pEndText = pOptParam->pData;
  1372. break;
  1373. case TVOT_PUSHBUTTON:
  1374. Flags &= ~OPTIF_CHANGEONCE;
  1375. break;
  1376. case TVOT_EDITBOX:
  1377. GSBUF_GETSTR(pCurItem->pSel);
  1378. pEndText = pOptParam->pData;
  1379. break;
  1380. }
  1381. if (pEndText) {
  1382. LPWSTR pwBuf;
  1383. if (EndTextAddSpace) {
  1384. GSBUF_ADD_SPACE(1);
  1385. }
  1386. pwBuf = GSBUF_PBUF;
  1387. GSBUF_GETSTR(pEndText);
  1388. if ((GSBUF_PBUF == pwBuf) &&
  1389. (EndTextAddSpace)) {
  1390. GSBUF_SUB_SIZE(1);
  1391. }
  1392. }
  1393. }
  1394. if (pECB) {
  1395. GSBUF_GETSTR(pECB->pSeparator);
  1396. GSBUF_GETSTR(pECB->pCheckedName);
  1397. }
  1398. IconResID = GET_ICONID(pOptParam, OPTPF_ICONID_AS_HICON);
  1399. IntIconID = IDI_CPSUI_GENERIC_ITEM;
  1400. if (pOptParam->Flags & OPTPF_OVERLAY_WARNING_ICON) {
  1401. tvlp.Flags |= TVLPF_WARNING;
  1402. }
  1403. if (pOptParam->Flags & OPTPF_OVERLAY_STOP_ICON) {
  1404. tvlp.Flags |= TVLPF_STOP;
  1405. }
  1406. if (pOptParam->Flags & OPTPF_OVERLAY_NO_ICON) {
  1407. tvlp.Flags |= TVLPF_NO;
  1408. }
  1409. }
  1410. if (ptvins) {
  1411. tvins.item.iImage =
  1412. tvins.item.iSelectedImage = -1;
  1413. } else {
  1414. tvins.item.iSelectedImage =
  1415. tvins.item.iImage = (INT)GetIcon16Idx(pTVWnd,
  1416. _OI_HINST(pCurItem),
  1417. IconResID,
  1418. IntIconID);
  1419. }
  1420. tvins.item.cchTextMax = GSBUF_COUNT;
  1421. #if DO_IN_PLACE
  1422. if (tvins.item.mask & (TVIF_IMAGE | TVIF_SELECTEDIMAGE)) {
  1423. tvins.item.state |= TVIS_OVERLAYMASK | TVIS_STATEIMAGEMASK;
  1424. } else {
  1425. tvins.item.state &= ~(TVIS_OVERLAYMASK | TVIS_STATEIMAGEMASK);
  1426. }
  1427. #endif
  1428. tvins.item.stateMask |= TVIS_OVERLAYMASK | TVIS_STATEIMAGEMASK;
  1429. //
  1430. // Change the overlay mask
  1431. //
  1432. if ((!(pTVWnd->Flags & TWF_CAN_UPDATE)) ||
  1433. (pCurItem->Flags & OPTIF_DISABLED)) {
  1434. tvlp.Flags |= TVLPF_DISABLED;
  1435. }
  1436. if (Flags & OPTIF_CHANGEONCE) {
  1437. tvlp.Flags |= TVLPF_CHANGEONCE;
  1438. }
  1439. tvins.item.lParam = TVLP2LP(tvlp);
  1440. if (ptvins) {
  1441. _OI_HITEM(pCurItem) = TreeView_InsertItem(pTVWnd->hWndTV, &tvins);
  1442. CPSUIOPTITEM(DBGITEM_INS, pTVWnd, "SetTVItemState(INSERT)", 1, pCurItem);
  1443. } else {
  1444. if (_OI_INTFLAGS(pCurItem) & OIDF_ZERO_SEL_LEN) {
  1445. UINT cSpace;
  1446. //
  1447. // Do not update string while is selected
  1448. //
  1449. if (pTVWnd->cxItem > pTVWnd->cxMaxItem) {
  1450. cSpace = (UINT)(((DWORD)pTVWnd->cxEdit +
  1451. (DWORD)pTVWnd->cxSpace - 1) /
  1452. (DWORD)pTVWnd->cxSpace) + 1;
  1453. GSBUF_PBUF = GSBUF_BUF + tvlp.cName;
  1454. GSBUF_ADD_SPACE(cSpace);
  1455. CPSUIINT(("!! ZERO_SEL_LEN Item: %ld GREATER Than %ld, cName=%ld, cSpace=%ld",
  1456. pTVWnd->cxItem, pTVWnd->cxMaxItem, tvlp.cName, cSpace));
  1457. pTVWnd->cxMaxItem = pTVWnd->cxItem;
  1458. TreeView_SetItem(pTVWnd->hWndTV, &(tvins.item));
  1459. } else {
  1460. CPSUIINT(("!! ZERO_SEL_LEN Item: %ld Less than %ld, cName=%ld",
  1461. pTVWnd->cxItem, pTVWnd->cxMaxItem, tvlp.cName));
  1462. }
  1463. GSBUF_BUF[tvlp.cName] = L'\0';
  1464. CPSUIINT(("!! ZERO_SEL_LEN Item pszText='%ws'",
  1465. tvins.item.pszText));
  1466. }
  1467. TreeView_SetItem(pTVWnd->hWndTV, &(tvins.item));
  1468. CPSUIOPTITEM(DBGITEM_SET, pTVWnd, "SetTVItemState(SET)", 1, pCurItem);
  1469. }
  1470. }
  1471. POPTITEM
  1472. SetupTVSelect(
  1473. HWND hDlg,
  1474. NM_TREEVIEW *pNMTV,
  1475. DWORD STVSMode
  1476. )
  1477. /*++
  1478. Routine Description:
  1479. Arguments:
  1480. Return Value:
  1481. Author:
  1482. 21-Jun-1995 Wed 15:14:54 created -by- Daniel Chou (danielc)
  1483. Revision History:
  1484. --*/
  1485. {
  1486. HWND hParent;
  1487. HWND hCtrl;
  1488. HWND hWndTV;
  1489. PTVWND pTVWnd = GET_PTVWND(hDlg);
  1490. POPTTYPE pOldOptType;
  1491. POPTITEM pOldItem;
  1492. POPTTYPE pOptType;
  1493. POPTITEM pNewItem;
  1494. POPTPARAM pOptParam;
  1495. TVLP tvlp;
  1496. WORD InitFlags;
  1497. WORD InitItemIdx;
  1498. WORD IconMode = 0;
  1499. BYTE NewType;
  1500. BOOL CanUpdate;
  1501. hWndTV = pTVWnd->hWndTV;
  1502. pNewItem = GetOptions(pTVWnd, pNMTV->itemNew.lParam);
  1503. tvlp = GET_TVLP(pNMTV->itemNew.lParam);
  1504. InitItemIdx = tvlp.ItemIdx;
  1505. if (!pTVWnd->pCurTVItem) {
  1506. pOldItem = NULL;
  1507. pOldOptType = NULL;
  1508. } else {
  1509. pOldItem = GetOptions(pTVWnd, pNMTV->itemOld.lParam);
  1510. pOldOptType = GET_POPTTYPE(pOldItem);
  1511. }
  1512. CPSUIOPTITEM(DBGITEM_SETUP, pTVWnd, "Setup OLD", 0, pOldItem);
  1513. CPSUIOPTITEM(DBGITEM_SETUP, pTVWnd, "Setup New", 0, pNewItem);
  1514. pOptType = GET_POPTTYPE(pNewItem);
  1515. #if DO_IN_PLACE
  1516. hParent = hWndTV;
  1517. switch (NewType = pOptType->Type) {
  1518. case TVOT_2STATES:
  1519. case TVOT_3STATES:
  1520. case TVOT_LISTBOX:
  1521. NewType = TVOT_COMBOBOX;
  1522. break;
  1523. case TVOT_SCROLLBAR:
  1524. case TVOT_TRACKBAR:
  1525. NewType = TVOT_UDARROW;
  1526. break;
  1527. default:
  1528. break;
  1529. }
  1530. #else
  1531. hParent = hDlg;
  1532. NewType = pOptType->Type;
  1533. #endif
  1534. //
  1535. // If we have push button, and it said we always can call it then update
  1536. // is true
  1537. //
  1538. if ((STVSMode & STVS_ACTIVE) &&
  1539. (pOldItem != pNewItem) &&
  1540. (pNewItem->Flags & OPTIF_CALLBACK) &&
  1541. (InitItemIdx < pTVWnd->ComPropSheetUI.cOptItem)) {
  1542. //
  1543. // Callback back ONLY for the user item which has CALLBACK
  1544. //
  1545. DoCallBack(hDlg,
  1546. pTVWnd,
  1547. pNewItem,
  1548. pNewItem->pSel,
  1549. NULL,
  1550. NULL,
  1551. 0,
  1552. CPSUICB_REASON_OPTITEM_SETFOCUS);
  1553. }
  1554. if ((pNewItem == PIDX_INTOPTITEM(pTVWnd, INTIDX_TVROOT)) ||
  1555. ((NewType == TVOT_PUSHBUTTON) &&
  1556. (pOptType->Flags & OTS_PUSH_ENABLE_ALWAYS))) {
  1557. CanUpdate = TRUE;
  1558. } else {
  1559. CanUpdate = (BOOL)(pTVWnd->Flags & TWF_CAN_UPDATE);
  1560. }
  1561. pTVWnd->Flags &= ~TWF_TVITEM_NOTYPE;
  1562. if (IS_HDR_PUSH(pOptType)) {
  1563. #if DO_IN_PLACE
  1564. pOptType = NULL;
  1565. NewType = TVOT_NONE;
  1566. #else
  1567. HTREEITEM hItem;
  1568. UINT cRevert;
  1569. if ((!CanUpdate) ||
  1570. (!(cRevert = CountRevertOptItem(pTVWnd,
  1571. pNewItem,
  1572. _OI_HITEM(pNewItem),
  1573. 0)))) {
  1574. CPSUIINT(("CountRevertOptItem=0, NOT REVERT"));
  1575. //
  1576. // We always enable the ROOT
  1577. //
  1578. if ((InitItemIdx == INTIDX_TVROOT) ||
  1579. ((pNewItem->pExtChkBox) &&
  1580. (!(pNewItem->Flags & OPTIF_EXT_HIDE)))) {
  1581. pTVWnd->Flags |= TWF_ONE_REVERT_ITEM;
  1582. pOptType->Flags |= OPTTF_TYPE_DISABLED;
  1583. } else {
  1584. pTVWnd->Flags |= TWF_TVITEM_NOTYPE;
  1585. pOptType = NULL;
  1586. NewType = TVOT_NONE;
  1587. }
  1588. } else {
  1589. pOptType->Flags &= ~OPTTF_TYPE_DISABLED;
  1590. if (cRevert == 1) {
  1591. pTVWnd->Flags |= TWF_ONE_REVERT_ITEM;
  1592. } else {
  1593. pTVWnd->Flags &= ~TWF_ONE_REVERT_ITEM;
  1594. }
  1595. CPSUIINT(("CountRevertOptItem=%d, Let's do the PUSH", cRevert));
  1596. }
  1597. #endif
  1598. }
  1599. if ((pNewItem->Flags & OPTIF_DISABLED) || (!CanUpdate)) {
  1600. InitFlags = INITCF_TVDLG;
  1601. } else {
  1602. InitFlags = INITCF_ENABLE | INITCF_TVDLG;
  1603. }
  1604. if ((STVSMode & STVS_REINIT) || (pOldItem != pNewItem)) {
  1605. InitFlags |= (INITCF_INIT | INITCF_SETCTRLDATA);
  1606. ChangeOptTypeDisplay(hParent,
  1607. pTVWnd,
  1608. pOldOptType,
  1609. pOptType,
  1610. InitFlags & INITCF_ENABLE);
  1611. }
  1612. //
  1613. // The extended check box will also looked at TWF_CAN_UPDATE flags to
  1614. // disable the ECB if the flag is clear
  1615. //
  1616. if (pOptType) {
  1617. if (INIT_EXTENDED(pTVWnd,
  1618. hParent,
  1619. pNewItem,
  1620. IDD_TV_EXTCHKBOX,
  1621. IDD_TV_EXTPUSH,
  1622. IDD_TV_ECB_ICON,
  1623. InitItemIdx,
  1624. InitFlags)) {
  1625. InitFlags |= INITCF_HAS_EXT;
  1626. }
  1627. } else if (InitFlags & INITCF_INIT) {
  1628. if (hCtrl = GetDlgItem(hParent, IDD_TV_EXTPUSH)) {
  1629. CPSUIINT(("!! DISABLE/HIDE HEADER EXTPUSH !!!"));
  1630. EnableWindow(hCtrl, FALSE);
  1631. ShowWindow(hCtrl, SW_HIDE);
  1632. }
  1633. if (hCtrl = GetDlgItem(hParent, IDD_TV_EXTCHKBOX)) {
  1634. CPSUIINT(("!! DISABLE/HIDE HEADER EXTCHKBOX !!"));
  1635. EnableWindow(hCtrl, FALSE);
  1636. ShowWindow(hCtrl, SW_HIDE);
  1637. }
  1638. }
  1639. if (pOptType) {
  1640. LONG Select;
  1641. UINT IDSetCurSel = CB_SETCURSEL;
  1642. UINT idLBCB = IDD_TV_CB;
  1643. UINT cyLBMax = 0;
  1644. ULONG_PTR IconResID;
  1645. WORD BegCtrlID;
  1646. WORD IntIconID = IDI_CPSUI_GENERIC_ITEM;
  1647. if (pNewItem->Flags & OPTIF_OVERLAY_WARNING_ICON) {
  1648. IconMode |= MIM_WARNING_OVERLAY;
  1649. }
  1650. if (pNewItem->Flags & (OPTIF_OVERLAY_STOP_ICON | OPTIF_HIDE)) {
  1651. IconMode |= MIM_STOP_OVERLAY;
  1652. }
  1653. if (pNewItem->Flags & OPTIF_OVERLAY_NO_ICON) {
  1654. IconMode |= MIM_NO_OVERLAY;
  1655. }
  1656. if (pOptType->Flags & OPTTF_TYPE_DISABLED) {
  1657. InitFlags &= ~INITCF_ENABLE;
  1658. }
  1659. //
  1660. // We have something to do here, if we have same option type
  1661. // with the old one then we need not to re-create them
  1662. // and if we have same select then we do not need to re-draw
  1663. //
  1664. // Now set the option text to reflect the changes
  1665. //
  1666. pOptParam = pOptType->pOptParam;
  1667. //
  1668. // Compose '&Change xxxx Option' or
  1669. // 'xxxxx Option"
  1670. //
  1671. #if (DO_IN_PLACE == 0)
  1672. if (InitFlags & INITCF_INIT) {
  1673. SetOptHeader(hDlg, pTVWnd, pNewItem, IS_HDR_PUSH(pOptType));
  1674. }
  1675. #endif
  1676. Select = pNewItem->Sel;
  1677. BegCtrlID = pOptType->BegCtrlID;
  1678. CPSUIDBG(DBG_STVS,
  1679. ("TVOT_TYPE=%hs, InitFlags=%04lx, InitItemIdx = %ld, Select=%ld [%08lx]",
  1680. (LPTSTR)pTVOTName[NewType],
  1681. (DWORD)InitFlags, (DWORD)InitItemIdx, Select, Select));
  1682. switch(NewType) {
  1683. case TVOT_2STATES:
  1684. case TVOT_3STATES:
  1685. #if (DO_IN_PLACE == 0)
  1686. if (InitFlags & INITCF_INIT) {
  1687. MoveStateRadios(hDlg, pTVWnd, pOptType, InitFlags);
  1688. }
  1689. #endif
  1690. #if DO_IN_PLACE
  1691. cyLBMax = pTVWnd->yLB[(InitFlags & INITCF_HAS_EXT) ? 0 : 1];
  1692. InitLBCB(pTVWnd,
  1693. hParent,
  1694. pNewItem,
  1695. idLBCB,
  1696. IDSetCurSel,
  1697. pOptType,
  1698. InitItemIdx,
  1699. Select,
  1700. InitFlags,
  1701. cyLBMax);
  1702. #else
  1703. InitStates(pTVWnd,
  1704. hParent,
  1705. pNewItem,
  1706. pOptType,
  1707. IDD_3STATES_1,
  1708. InitItemIdx,
  1709. Select,
  1710. InitFlags);
  1711. #endif
  1712. pOptParam += Select;
  1713. break;
  1714. case TVOT_UDARROW:
  1715. InitUDArrow(pTVWnd,
  1716. hParent,
  1717. pNewItem,
  1718. pOptParam,
  1719. IDD_TV_UDARROW,
  1720. IDD_TV_UDARROW_EDIT,
  1721. IDD_TV_UDARROW_ENDTEXT,
  1722. IDD_TV_UDARROW_HELP,
  1723. InitItemIdx,
  1724. Select,
  1725. InitFlags);
  1726. break;
  1727. case TVOT_SCROLLBAR:
  1728. case TVOT_TRACKBAR:
  1729. CPSUIINT(("hParent=%08lx, NewType=%ld, hCtrl=%08lx",
  1730. hParent, NewType,
  1731. GetDlgItem(hParent, (NewType == TVOT_TRACKBAR) ?
  1732. IDD_TV_TRACKBAR : IDD_TV_SB)));
  1733. InitTBSB(pTVWnd,
  1734. hParent,
  1735. pNewItem,
  1736. GetDlgItem(hParent, (NewType == TVOT_TRACKBAR) ?
  1737. IDD_TV_TRACKBAR : IDD_TV_SB),
  1738. pOptType,
  1739. 0,
  1740. IDD_TV_SB_LOW,
  1741. IDD_TV_SB_HIGH,
  1742. InitItemIdx,
  1743. Select,
  1744. InitFlags);
  1745. break;
  1746. case TVOT_LISTBOX:
  1747. //
  1748. // If we only has one item then make it combo box
  1749. //
  1750. cyLBMax = pTVWnd->yLB[(InitFlags & INITCF_HAS_EXT) ? 0 : 1];
  1751. IDSetCurSel = LB_SETCURSEL;
  1752. idLBCB = IDD_TV_LB;
  1753. //
  1754. // Fall through
  1755. //
  1756. case TVOT_COMBOBOX:
  1757. InitLBCB(pTVWnd,
  1758. hParent,
  1759. pNewItem,
  1760. idLBCB,
  1761. IDSetCurSel,
  1762. pOptType,
  1763. InitItemIdx,
  1764. Select,
  1765. InitFlags,
  1766. cyLBMax);
  1767. if ((DWORD)Select >= (DWORD)pOptType->Count) {
  1768. CPSUIDBG(DBG_STVS, ("Get NONE type of select=%ld", Select));
  1769. pOptParam = &pTVWnd->OptParamNone;
  1770. } else {
  1771. pOptParam += (DWORD)Select;
  1772. }
  1773. break;
  1774. case TVOT_EDITBOX:
  1775. InitEditBox(pTVWnd,
  1776. hParent,
  1777. pNewItem,
  1778. pOptParam,
  1779. IDD_TV_EDIT_EDIT,
  1780. IDD_TV_EDIT_ENDTEXT,
  1781. IDD_TV_EDIT_HELP,
  1782. InitItemIdx,
  1783. pNewItem->pSel,
  1784. InitFlags);
  1785. break;
  1786. case TVOT_PUSHBUTTON:
  1787. InitPushButton(pTVWnd,
  1788. hParent,
  1789. pNewItem,
  1790. IDD_TV_PUSH,
  1791. InitItemIdx,
  1792. InitFlags);
  1793. break;
  1794. case TVOT_CHKBOX:
  1795. #if DO_IN_PLACE
  1796. {
  1797. OPTTYPE ChkBoxOT;
  1798. OPTPARAM ChkBoxOP[2];
  1799. UINT Idx;
  1800. ChkBoxOT = *pOptType;
  1801. ChkBoxOT.Type = TVOT_COMBOBOX;
  1802. ChkBoxOT.Count = 2;
  1803. ChkBoxOT.pOptParam = ChkBoxOP;
  1804. ChkBoxOP[0] =
  1805. ChkBoxOP[1] = *pOptParam;
  1806. ChkBoxOP[0].Style =
  1807. ChkBoxOP[1].Style = 0;
  1808. ChkBoxOP[0].IconID =
  1809. ChkBoxOP[1].IconID = 0;
  1810. Idx = (UINT)(pOptParam->Style << 1);
  1811. if (ChkBoxStrID[Idx]) {
  1812. ChkBoxOP[0].pData = (LPTSTR)ChkBoxStrID[Idx];
  1813. }
  1814. if (ChkBoxStrID[Idx + 1]) {
  1815. ChkBoxOP[1].pData = (LPTSTR)ChkBoxStrID[Idx + 1];
  1816. }
  1817. cyLBMax = pTVWnd->yLB[(InitFlags & INITCF_HAS_EXT) ? 0 : 1];
  1818. InitLBCB(pTVWnd,
  1819. hParent,
  1820. pNewItem,
  1821. idLBCB,
  1822. IDSetCurSel,
  1823. &ChkBoxOT,
  1824. InitItemIdx,
  1825. Select,
  1826. InitFlags,
  1827. cyLBMax);
  1828. }
  1829. #else
  1830. InitChkBox(pTVWnd,
  1831. hParent,
  1832. pNewItem,
  1833. IDD_TV_CHKBOX,
  1834. pNewItem->pName,
  1835. InitItemIdx,
  1836. (BOOL)Select,
  1837. InitFlags);
  1838. #endif
  1839. break;
  1840. }
  1841. if (IS_HDR_PUSH(pOptType)) {
  1842. IconResID = GETSELICONID(pNewItem);
  1843. IntIconID = IDI_CPSUI_GENERIC_OPTION;
  1844. } else {
  1845. IconResID = GET_ICONID(pOptParam, OPTPF_ICONID_AS_HICON);
  1846. if (pOptParam->Flags & OPTPF_OVERLAY_WARNING_ICON) {
  1847. IconMode |= MIM_WARNING_OVERLAY;
  1848. }
  1849. if (pOptParam->Flags & OPTPF_OVERLAY_STOP_ICON) {
  1850. IconMode |= MIM_STOP_OVERLAY;
  1851. }
  1852. if (pOptParam->Flags & OPTPF_OVERLAY_NO_ICON) {
  1853. IconMode |= MIM_NO_OVERLAY;
  1854. }
  1855. }
  1856. #if (DO_IN_PLACE == 0)
  1857. SetIcon(_OI_HINST(pNewItem),
  1858. GetDlgItem(hParent, IDD_TV_ICON),
  1859. IconResID,
  1860. MK_INTICONID(IntIconID, IconMode),
  1861. pTVWnd->cxcyTVIcon);
  1862. #endif
  1863. }
  1864. return(pNewItem);
  1865. }
  1866. LONG
  1867. UpdateTreeViewItem(
  1868. HWND hDlg,
  1869. PTVWND pTVWnd,
  1870. POPTITEM pItem,
  1871. BOOL ReInit
  1872. )
  1873. /*++
  1874. Routine Description:
  1875. This function update a single item in the treeview, and reset the bottom
  1876. option change controls if this item also the current selected one
  1877. Arguments:
  1878. hDlg - Handle to the dialog box
  1879. pTVWnd - Handle to common UI instance data
  1880. pItem - Pointer to OPTITEM to be updated
  1881. Return Value:
  1882. LONG
  1883. Author:
  1884. 01-Sep-1995 Fri 01:05:56 created -by- Daniel Chou (danielc)
  1885. Revision History:
  1886. --*/
  1887. {
  1888. if ((pItem) && (!(pItem->Flags & OPTIF_INT_HIDE))) {
  1889. SetTVItemState(pTVWnd, NULL, pItem);
  1890. if (pItem == pTVWnd->pCurTVItem) {
  1891. NM_TREEVIEW NMtv;
  1892. NMtv.itemNew.hItem = _OI_HITEM(pItem);
  1893. NMtv.itemNew.mask = TVIF_HANDLE | TVIF_PARAM;
  1894. if (IS_HDR_PUSH(GET_POPTTYPE(pItem))) {
  1895. ReInit = TRUE;
  1896. }
  1897. if (TreeView_GetItem(pTVWnd->hWndTV, &(NMtv.itemNew))) {
  1898. NMtv.itemOld = NMtv.itemNew;
  1899. SetupTVSelect(hDlg, &NMtv, (ReInit) ? STVS_REINIT : 0);
  1900. CPSUIDBG(DBG_UTV, ("*UpdateTreeViewItem: Item=Current Selection"));
  1901. }
  1902. }
  1903. return(1);
  1904. } else {
  1905. return(0);
  1906. }
  1907. }
  1908. LONG
  1909. UpdateTreeView(
  1910. HWND hDlg,
  1911. PMYDLGPAGE pCurMyDP
  1912. )
  1913. /*++
  1914. Routine Description:
  1915. Arguments:
  1916. Return Value:
  1917. Author:
  1918. 08-Aug-1995 Tue 15:37:16 created -by- Daniel Chou (danielc)
  1919. Revision History:
  1920. --*/
  1921. {
  1922. INT cUpdated = 0;
  1923. if (pCurMyDP->Flags & (MYDPF_CHANGED | MYDPF_REINIT)) {
  1924. PTVWND pTVWnd;
  1925. POPTITEM pItem;
  1926. UINT cItem;
  1927. BOOL ReInit;
  1928. BOOL TVByPush;
  1929. BYTE TVPageIdx;
  1930. pTVWnd = (PTVWND)pCurMyDP->pTVWnd;
  1931. pItem = pTVWnd->ComPropSheetUI.pOptItem;
  1932. cItem = (UINT)pTVWnd->ComPropSheetUI.cOptItem;
  1933. ReInit = (pCurMyDP->Flags & MYDPF_REINIT);
  1934. TVByPush = (BOOL)(pTVWnd->Flags & TWF_TV_BY_PUSH);
  1935. TVPageIdx = pTVWnd->TVPageIdx;
  1936. CPSUIASSERT(0, "UpdateTreeView: DlgPage not treevie page (%ld)",
  1937. ((pCurMyDP->DlgPage.DlgTemplateID == DP_STD_TREEVIEWPAGE) ||
  1938. (pCurMyDP->DlgPage.DlgTemplateID == DP_STD_INT_TVPAGE))
  1939. && ((BYTE)pCurMyDP->PageIdx == TVPageIdx),
  1940. (BYTE)pCurMyDP->PageIdx);
  1941. CPSUIDBG(DBGITEM_UTV, ("UpdateTreeView (OPTIF_INT_TV_CHANGED)"));
  1942. while (cItem--) {
  1943. if (pItem->Flags & OPTIF_INT_TV_CHANGED) {
  1944. if ((!TVByPush) || (pItem->DlgPageIdx == TVPageIdx)) {
  1945. CPSUIOPTITEM(DBGITEM_UTV, pTVWnd, "UpdateTreeView",
  1946. 1, pItem);
  1947. UpdateTreeViewItem(hDlg, pTVWnd, pItem, ReInit);
  1948. ++cUpdated;
  1949. }
  1950. pItem->Flags &= ~OPTIF_INT_TV_CHANGED;
  1951. }
  1952. pItem++;
  1953. }
  1954. pCurMyDP->Flags &= ~(MYDPF_CHANGED | MYDPF_REINIT);
  1955. }
  1956. return((LONG)cUpdated);
  1957. }
  1958. POPTITEM
  1959. TreeViewHitTest(
  1960. PTVWND pTVWnd,
  1961. LONG MousePos,
  1962. UINT TVHTMask
  1963. )
  1964. /*++
  1965. Routine Description:
  1966. Arguments:
  1967. Return Value:
  1968. Author:
  1969. 07-Sep-1995 Thu 22:32:04 created -by- Daniel Chou (danielc)
  1970. Revision History:
  1971. --*/
  1972. {
  1973. HWND hWndTV = pTVWnd->hWndTV;
  1974. TV_HITTESTINFO ht;
  1975. //
  1976. // Find out the mouse cursor location if on the state icon/bmp
  1977. //
  1978. if (MousePos != -1) {
  1979. ht.pt.x = (LONG)LOWORD(MousePos);
  1980. ht.pt.y = (LONG)HIWORD(MousePos);
  1981. } else {
  1982. GetCursorPos(&ht.pt);
  1983. }
  1984. ScreenToClient(hWndTV, &ht.pt);
  1985. TreeView_HitTest(hWndTV, &ht);
  1986. CPSUIDBG(DBG_TVHT,
  1987. ("TreeViewHitTest: pt=(%ld, %ld), HitTest=%04lx, TVHT_xx=%ld",
  1988. (DWORD)ht.pt.x, (DWORD)ht.pt.y, TVHTMask, (DWORD)ht.flags));
  1989. if (ht.flags & TVHTMask) {
  1990. POPTTYPE pOptType;
  1991. POPTITEM pItem;
  1992. TV_ITEM tvi;
  1993. tvi.hItem = ht.hItem;
  1994. tvi.mask = TVIF_CHILDREN | TVIF_HANDLE | TVIF_STATE | TVIF_PARAM;
  1995. tvi.stateMask = TVIS_STATEIMAGEMASK;
  1996. if (TreeView_GetItem(hWndTV, &tvi)) {
  1997. return(GetOptions(pTVWnd, tvi.lParam));
  1998. }
  1999. }
  2000. return(NULL);
  2001. }
  2002. VOID
  2003. TreeViewChangeMode(
  2004. PTVWND pTVWnd,
  2005. POPTITEM pItem,
  2006. UINT Mode
  2007. )
  2008. /*++
  2009. Routine Description:
  2010. Arguments:
  2011. Return Value:
  2012. Author:
  2013. 07-Sep-1995 Thu 22:56:05 created -by- Daniel Chou (danielc)
  2014. Revision History:
  2015. --*/
  2016. {
  2017. HWND hWndTV = pTVWnd->hWndTV;
  2018. POPTTYPE pOptType;
  2019. TV_ITEM tvi;
  2020. tvi.mask = TVIF_CHILDREN | TVIF_HANDLE | TVIF_STATE | TVIF_PARAM;
  2021. if ((!pItem) ||
  2022. (!(tvi.hItem = _OI_HITEM(pItem))) ||
  2023. (!TreeView_GetItem(hWndTV, &tvi))) {
  2024. return;
  2025. }
  2026. switch (Mode) {
  2027. case TVCM_TOGGLE:
  2028. if (tvi.cChildren) {
  2029. PostMessage(hWndTV,
  2030. TVM_EXPAND,
  2031. (WPARAM)TVE_TOGGLE,
  2032. (LPARAM)tvi.hItem);
  2033. }
  2034. break;
  2035. case TVCM_SELECT:
  2036. PostMessage(hWndTV,
  2037. TVM_SELECTITEM,
  2038. (WPARAM)TVGN_CARET,
  2039. (LPARAM)tvi.hItem);
  2040. //
  2041. // We will go to the next control only if the item is not disabled
  2042. // and has an update permisson (push button always has one).
  2043. //
  2044. #if DO_IN_PLACE
  2045. if ((!tvi.cChildren) &&
  2046. (!(pItem->Flags & OPTIF_DISABLED)) &&
  2047. (pOptType = GET_POPTTYPE(pItem)) &&
  2048. (!IS_HDR_PUSH(pOptType)) &&
  2049. ((pTVWnd->Flags & TWF_CAN_UPDATE) ||
  2050. (pOptType->Flags & OTS_PUSH_ENABLE_ALWAYS))) {
  2051. if (pOptType->Type == TVOT_PUSHBUTTON) {
  2052. PostMessage(pTVWnd->hDlgTV,
  2053. WM_COMMAND,
  2054. MAKEWPARAM(IDD_TV_PUSH, BN_CLICKED),
  2055. (LPARAM)GetDlgItem(pTVWnd->hWndTV, IDD_TV_PUSH));
  2056. } else if (pTVWnd->chWndEdit) {
  2057. PostMessage(pTVWnd->hDlgTV,
  2058. WM_NEXTDLGCTL,
  2059. (WPARAM)pTVWnd->hWndEdit[0],
  2060. (LPARAM)1);
  2061. }
  2062. }
  2063. #else
  2064. if ((!tvi.cChildren) &&
  2065. (!(pItem->Flags & OPTIF_DISABLED)) &&
  2066. (pOptType = GET_POPTTYPE(pItem)) &&
  2067. (pOptType->Type == TVOT_PUSHBUTTON) &&
  2068. (!IS_HDR_PUSH(pOptType)) &&
  2069. ((pTVWnd->Flags & TWF_CAN_UPDATE) ||
  2070. (pOptType->Flags & OTS_PUSH_ENABLE_ALWAYS))) {
  2071. PostMessage(pTVWnd->hDlgTV,
  2072. WM_COMMAND,
  2073. MAKEWPARAM(IDD_TV_PUSH, BN_CLICKED),
  2074. (LPARAM)GetDlgItem(pTVWnd->hDlgTV, IDD_TV_PUSH));
  2075. }
  2076. #endif
  2077. break;
  2078. }
  2079. }
  2080. VOID
  2081. MouseSelectItem(
  2082. HWND hDlg,
  2083. PTVWND pTVWnd
  2084. )
  2085. /*++
  2086. Routine Description:
  2087. Arguments:
  2088. Return Value:
  2089. Author:
  2090. 22-Jun-1995 Thu 13:44:18 created -by- Daniel Chou (danielc)
  2091. Revision History:
  2092. --*/
  2093. {
  2094. POPTITEM pItem;
  2095. //
  2096. // Find out the mouse cursor location if on the state icon/bmp
  2097. //
  2098. if (pItem = TreeViewHitTest(pTVWnd, -1, TVHT_ONITEM)) {
  2099. TreeViewChangeMode(pTVWnd, pItem, TVCM_SELECT);
  2100. }
  2101. }
  2102. HWND
  2103. CreatehWndTV(
  2104. HWND hDlg,
  2105. PTVWND pTVWnd
  2106. )
  2107. /*++
  2108. Routine Description:
  2109. This function create TREE VIEW window
  2110. Arguments:
  2111. hDlg - Handle to the dialog for the treeview to be created, it must
  2112. have item identify as IDD_TV_WND for the treeview window location
  2113. Return Value:
  2114. HWND for the treeview window
  2115. Author:
  2116. 21-Jun-1995 Wed 13:33:29 created -by- Daniel Chou (danielc)
  2117. Revision History:
  2118. --*/
  2119. {
  2120. HWND hWndTV = NULL;
  2121. HWND hCtrl;
  2122. DWORD dw;
  2123. RECT rc;
  2124. WORD InitItemIdx = 0xFFFE;
  2125. //
  2126. // Create TreeView Window, Get the window size for the treeview
  2127. //
  2128. hCtrl = CtrlIDrcWnd(hDlg, IDD_TV_WND, &rc);
  2129. if (hCtrl)
  2130. {
  2131. SETCTRLDATA(hCtrl, CTRLS_TV_STATIC, 0);
  2132. ShowWindow(hCtrl, SW_HIDE);
  2133. CPSUIDBG(DBG_CTVWND,
  2134. ("\nINIT DEV DLG, CLIENT rc=(%ld, %ld) - (%ld, %ld) = %ld x %ld",
  2135. rc.left, rc.top, rc.right, rc.bottom,
  2136. rc.right - rc.left, rc.bottom - rc.top));
  2137. if (hWndTV = CreateWindowEx(WS_EX_NOPARENTNOTIFY |
  2138. WS_EX_CLIENTEDGE,
  2139. WC_TREEVIEW,
  2140. L"",
  2141. WS_VISIBLE |
  2142. TVS_HASBUTTONS |
  2143. TVS_SHOWSELALWAYS |
  2144. TVS_DISABLEDRAGDROP |
  2145. // TVS_LINESATROOT |
  2146. TVS_HASLINES |
  2147. WS_CLIPCHILDREN |
  2148. WS_CHILD |
  2149. WS_BORDER |
  2150. WS_TABSTOP |
  2151. WS_CLIPSIBLINGS |
  2152. WS_GROUP,
  2153. rc.left,
  2154. rc.top,
  2155. rc.right - rc.left,
  2156. rc.bottom - rc.top,
  2157. hDlg,
  2158. (HMENU)(IDD_TV_WND + 0),
  2159. hInstDLL,
  2160. 0)) {
  2161. DestroyWindow(hCtrl);
  2162. pTVWnd->hWndTV = hWndTV;
  2163. SetWindowPos(hWndTV, GetDlgItem(hDlg, IDD_TV_WND), 0, 0, 0, 0,
  2164. SWP_NOMOVE | SWP_NOSIZE | SWP_NOREDRAW);
  2165. InitItemIdx = 0xFFFF;
  2166. SETCTRLDATA(hWndTV, CTRLS_TV_WND, 0);
  2167. #if DO_IN_PLACE
  2168. if (pTVWnd->hDCTVWnd = GetWindowDC(hWndTV)) {
  2169. CreateTVFonts(pTVWnd,
  2170. (HANDLE)SendMessage(hWndTV, WM_GETFONT, 0, 0));
  2171. }
  2172. #endif
  2173. pTVWnd->TVWndProc = (WNDPROC)SetWindowLongPtr(hWndTV,
  2174. GWLP_WNDPROC,
  2175. (LPARAM)MyTVWndProc);
  2176. }
  2177. CPSUIDBG(DBG_CTVWND, ("\nINIT DLG (%08lx), hWndTV = %08lx",
  2178. hDlg, hWndTV));
  2179. }
  2180. return(hWndTV);
  2181. }
  2182. HTREEITEM
  2183. AddItem(
  2184. PTVWND pTVWnd,
  2185. HTREEITEM hParent,
  2186. POPTITEM pItem,
  2187. UINT DefTVIS,
  2188. UINT TVLevel
  2189. )
  2190. /*++
  2191. Routine Description:
  2192. This function add a item to the end of list of treeview specified by
  2193. Arguments:
  2194. hParent - handle to the parent item for the item to be added
  2195. pItem - Pointer to the OPTITEM to be added
  2196. ItemIdx - Index to the pOptItem
  2197. DefTVIS - default TVIS_xxxx
  2198. Return Value:
  2199. HTREEITEM of the item added or NULL if nothing added
  2200. Author:
  2201. 19-Jun-1995 Mon 16:38:27 created -by- Daniel Chou (danielc)
  2202. 08-Sep-1995 Fri 13:43:34 updated -by- Daniel Chou (danielc)
  2203. Re-write to make it more compact
  2204. Revision History:
  2205. --*/
  2206. {
  2207. WORD ItemIdx;
  2208. DWORD Flags;
  2209. if ((VALID_PTR(pItem)) &&
  2210. (pItem >= pTVWnd->ComPropSheetUI.pOptItem) &&
  2211. (pItem <= pTVWnd->pLastItem)) {
  2212. ItemIdx = (WORD)(pItem - pTVWnd->ComPropSheetUI.pOptItem);
  2213. } else {
  2214. ItemIdx = LOWORD(LODWORD(pItem));
  2215. pItem = PIDX_INTOPTITEM(pTVWnd, ItemIdx);
  2216. if ((ItemIdx == INTIDX_PAPER) ||
  2217. (ItemIdx == INTIDX_GRAPHIC)) {
  2218. if (pTVWnd->Flags & TWF_ADVDOCPROP) {
  2219. DefTVIS &= ~TVIS_EXPANDED;
  2220. } else {
  2221. DefTVIS |= TVIS_EXPANDED;
  2222. }
  2223. }
  2224. }
  2225. CPSUIDBG(DBG_AI, ("ItemIdx = %ld (%08lx)", ItemIdx, ItemIdx));
  2226. CPSUIOPTITEM(DBG_AI, pTVWnd, "AddItem", 1, pItem);
  2227. if (!(pItem->Flags & (OPTIF_INT_ADDED | OPTIF_ITEM_HIDE))) {
  2228. TV_INSERTSTRUCT tvins;
  2229. //
  2230. // Set to internal added if this item is a user item
  2231. //
  2232. _OI_TVLEVEL(pItem) = (BYTE)TVLevel;
  2233. tvins.item.state = DefTVIS;
  2234. tvins.item.stateMask = TVIS_EXPANDED; // | TVIS_BOLD;
  2235. tvins.item.mask = TVIF_TEXT |
  2236. TVIF_STATE |
  2237. TVIF_IMAGE |
  2238. TVIF_SELECTEDIMAGE;
  2239. tvins.hInsertAfter = TVI_LAST;
  2240. tvins.hParent = hParent;
  2241. SetTVItemState(pTVWnd, &tvins, pItem);
  2242. if ((pItem->Flags |= OPTIF_INT_ADDED) & OPTIF_INITIAL_TVITEM) {
  2243. if (pTVWnd->pCurTVItem) {
  2244. CPSUIWARN(("Treeview: More than one OPTIF_INITIAL_TVITEM, OverRide"));
  2245. }
  2246. pTVWnd->pCurTVItem = pItem;
  2247. }
  2248. return(_OI_HITEM(pItem));
  2249. }
  2250. return(NULL);
  2251. }
  2252. UINT
  2253. AddItemGroup(
  2254. PTVWND pTVWnd,
  2255. HTREEITEM hParent,
  2256. POPTITEM *ppItem,
  2257. UINT TVLevel,
  2258. UINT BegDMPubID,
  2259. UINT EndDMPubID
  2260. )
  2261. /*++
  2262. Routine Description:
  2263. This function add items starting from the *ppItem, the item added includes
  2264. item's sibling and all theirs children until end of the the pOptItem array.
  2265. It also skip all the OPTIF_INT_ADDED and OPTIF_ITEM_HIDE items
  2266. and its children
  2267. Arguments:
  2268. pTVWnd - Pointer to the TVWND instance data
  2269. hParent - Parent of the starting item
  2270. ppItem - Pointer to POPTITEM for the starting item in the pOptItem array
  2271. at return this pointer is updated to the next item which either
  2272. at end of array or the parent's sibling
  2273. Return Value:
  2274. UINT, count of item added to the treeview, it also update ppItem pointer
  2275. Author:
  2276. 27-Jun-1995 Tue 18:44:16 created -by- Daniel Chou (danielc)
  2277. Revision History:
  2278. --*/
  2279. {
  2280. POPTITEM pItem;
  2281. HTREEITEM hCurGrp;
  2282. POPTITEM pLastItem;
  2283. BYTE GrpLevel;
  2284. BYTE CurLevel;
  2285. UINT cAdd;
  2286. pItem = *ppItem;
  2287. pLastItem = pTVWnd->pLastItem;
  2288. GrpLevel = pItem->Level;
  2289. hCurGrp = hParent;
  2290. cAdd = 0;
  2291. while (pItem <= pLastItem) {
  2292. if ((CurLevel = pItem->Level) < GrpLevel) {
  2293. //
  2294. // Finished the group level
  2295. //
  2296. break;
  2297. } else if (pItem->Flags & (OPTIF_ITEM_HIDE | OPTIF_INT_ADDED)) {
  2298. //
  2299. // Skip this item and all its children
  2300. //
  2301. CPSUIOPTITEM(DBGITEM_AIG, pTVWnd, "Skip HIDE/INT_ADDED Item", 1, pItem);
  2302. while ((++pItem <= pLastItem) && (pItem->Level > CurLevel));
  2303. } else if (CurLevel > GrpLevel) {
  2304. //
  2305. // Adding its children only if this item is not OPTIF_INT_ADDED and
  2306. // OPTIF_ITEM_HIDE
  2307. //
  2308. CPSUIOPTITEM(DBG_AIG, pTVWnd, "AddItemGroup", 1, pItem);
  2309. cAdd += AddItemGroup(pTVWnd,
  2310. hCurGrp,
  2311. &pItem,
  2312. TVLevel + 1,
  2313. 0,
  2314. 0xFFFF);
  2315. } else if (((UINT)pItem->DMPubID < BegDMPubID) ||
  2316. ((UINT)pItem->DMPubID > EndDMPubID)) {
  2317. //
  2318. // Skip this item and all its children
  2319. //
  2320. CPSUIOPTITEM(DBGITEM_AIG, pTVWnd, "Skip DMPubID Item", 1, pItem);
  2321. CPSUIDBG(DBGITEM_AIG, ("Skip %ld (ONLY DMPubID=%ld-%ld Items)",
  2322. pItem->DMPubID, BegDMPubID, EndDMPubID));
  2323. while ((++pItem <= pLastItem) && (pItem->Level > CurLevel));
  2324. } else {
  2325. HTREEITEM hAdd;
  2326. UINT DefTVIS = 0;
  2327. //
  2328. // Adding its sibling, checking if we could have children, if
  2329. // we do then add the TVIS_BOLD flag to it, at return we want to
  2330. // know if did add the item, if we do then this is his childrern's
  2331. // parent handle
  2332. //
  2333. DefTVIS = (pItem->Flags & OPTIF_COLLAPSE) ? 0 : TVIS_EXPANDED;
  2334. if ((pItem < pLastItem) && ((pItem + 1)->Level > CurLevel)) {
  2335. DefTVIS |= TVIS_BOLD;
  2336. }
  2337. if (hAdd = AddItem(pTVWnd, hParent, pItem, DefTVIS, TVLevel)) {
  2338. hCurGrp = hAdd;
  2339. cAdd++;
  2340. }
  2341. pItem++;
  2342. }
  2343. }
  2344. *ppItem = pItem;
  2345. return(cAdd);
  2346. }
  2347. UINT
  2348. AddPubGroup(
  2349. PTVWND pTVWnd,
  2350. HTREEITEM hParent,
  2351. PINTTVGRP *ppitvg,
  2352. UINT TVLevel,
  2353. UINT DMPubIDAdd
  2354. )
  2355. /*++
  2356. Routine Description:
  2357. Arguments:
  2358. Return Value:
  2359. Author:
  2360. 09-Sep-1995 Sat 11:58:59 created -by- Daniel Chou (danielc)
  2361. Revision History:
  2362. --*/
  2363. {
  2364. POPTITEM pItem = NULL;
  2365. HTREEITEM hLastGrp;
  2366. HTREEITEM hCurGrp;
  2367. PINTTVGRP pitvg;
  2368. LPWORD pDMPubIdx;
  2369. UINT cAdd;
  2370. WORD Idx;
  2371. BYTE GrpLevel;
  2372. BYTE CurLevel;
  2373. pitvg = *ppitvg;
  2374. pDMPubIdx = pTVWnd->DMPubIdx;
  2375. GrpLevel = (BYTE)(pitvg->LevelFlags & ITVG_LEVEL_MASK);
  2376. hLastGrp = NULL;
  2377. hCurGrp = hParent;
  2378. cAdd = 0;
  2379. while ((CurLevel = (pitvg->LevelFlags & ITVG_LEVEL_MASK)) >= GrpLevel) {
  2380. if (CurLevel > GrpLevel) {
  2381. //
  2382. // Adding its children
  2383. //
  2384. PINTTVGRP pParentitvg = pitvg - 1;
  2385. CPSUIASSERT(0, "AddPubGroup: Internal ERROR, no parent=%ld",
  2386. (cAdd) && (hCurGrp), UIntToPtr(cAdd));
  2387. if (Idx = (WORD)AddPubGroup(pTVWnd,
  2388. hCurGrp,
  2389. &pitvg,
  2390. TVLevel + 1,
  2391. DMPubIDAdd)) {
  2392. cAdd += (UINT)Idx;
  2393. } else {
  2394. CPSUIDBG(DBG_APG,
  2395. ("AddPubGroup(Level=%02lx, ID=%ld), pItem=%08lx",
  2396. pParentitvg->LevelFlags, pParentitvg->DMPubID, pItem));
  2397. if ((pParentitvg->DMPubID >= DMPUB_HDR_FIRST) ||
  2398. ((pItem) && (pItem->pOptType == NULL))) {
  2399. //
  2400. // Nothing added for this group, if this is the internal
  2401. // group item then delete otherwise do not delete user's
  2402. // item if the item has OPTTYPE
  2403. //
  2404. CPSUIINT(("0 Added, DELETE its Parent"));
  2405. TreeView_DeleteItem(pTVWnd->hWndTV, hCurGrp);
  2406. --cAdd;
  2407. hCurGrp = hLastGrp;
  2408. hLastGrp = NULL;
  2409. } else {
  2410. //
  2411. // We need to take out the BOLD status
  2412. //
  2413. TV_ITEM tvi;
  2414. tvi.mask = TVIF_STATE;
  2415. tvi.hItem = hCurGrp;
  2416. tvi.state = 0;
  2417. tvi.stateMask = TVIS_BOLD;
  2418. CPSUIINT(("0 Added, Remove pItem's BOLD"));
  2419. TreeView_SetItem(pTVWnd->hWndTV, &tvi);
  2420. }
  2421. }
  2422. } else {
  2423. HTREEITEM hAdd = NULL;
  2424. UINT DefTVIS;
  2425. BYTE DMPubID;
  2426. BOOL IsHdr;
  2427. //
  2428. // Adding its sibling, checking if we could have children, if
  2429. // we do then add the TVIS_BOLD flag to it, at return we want to
  2430. // know if did add the item, if we do then this is his childrern's
  2431. // parent handle
  2432. //
  2433. if (pitvg->LevelFlags & ITVGF_COLLAPSE) {
  2434. DefTVIS = 0;
  2435. } else {
  2436. DefTVIS = TVIS_EXPANDED;
  2437. }
  2438. if (pitvg->LevelFlags & ITVGF_BOLD) {
  2439. DefTVIS |= TVIS_BOLD;
  2440. }
  2441. if ((DMPubID = pitvg->DMPubID) >= DMPUB_HDR_FIRST) {
  2442. pItem = (POPTITEM)UIntToPtr(DMPubID - DMPUB_HDR_FIRST + INTIDX_FIRST);
  2443. DefTVIS |= TVIS_BOLD;
  2444. } else if ((Idx = pDMPubIdx[DMPubID - DMPUB_FIRST]) != 0xFFFF) {
  2445. pItem = pTVWnd->ComPropSheetUI.pOptItem + Idx;
  2446. } else {
  2447. pItem = NULL;
  2448. }
  2449. if ((pItem) &&
  2450. (hAdd = AddItem(pTVWnd, hParent, pItem, DefTVIS, TVLevel))) {
  2451. hLastGrp = hCurGrp;
  2452. hCurGrp = hAdd;
  2453. cAdd++;
  2454. //
  2455. // If this item has children, add the children
  2456. //
  2457. if ((VALID_PTR(pItem)) &&
  2458. (++pItem <= pTVWnd->pLastItem) &&
  2459. (pItem->Level > (pItem-1)->Level)) {
  2460. cAdd += AddItemGroup(pTVWnd,
  2461. hAdd,
  2462. &pItem,
  2463. TVLevel + 1,
  2464. 0,
  2465. 0xFFFF);
  2466. }
  2467. pitvg++;
  2468. } else {
  2469. //
  2470. // Skip all the childrens belongs to him
  2471. //
  2472. CPSUIDBG(DBG_APG,
  2473. ("Eiter pItem=NULL(%08lx) or AddItem()=NULL(%08lx)",
  2474. pItem, hAdd));
  2475. while (((++pitvg)->LevelFlags & ITVG_LEVEL_MASK) > CurLevel) {
  2476. //
  2477. // We need to skip all the internal header and hide all
  2478. // the real user items
  2479. //
  2480. if ((DMPubID = pitvg->DMPubID) &&
  2481. (DMPubID <= DMPUB_LAST) &&
  2482. ((Idx = pDMPubIdx[DMPubID - DMPUB_FIRST]) != 0xFFFF)) {
  2483. POPTITEM pLastItem;
  2484. BYTE ItemLevel;
  2485. pItem = pTVWnd->ComPropSheetUI.pOptItem + Idx;
  2486. pLastItem = pTVWnd->pLastItem;
  2487. ItemLevel = pItem->Level;
  2488. CPSUIOPTITEM(DBG_APG, pTVWnd, "Skip ITVG", 1, pItem);
  2489. SKIP_CHILDREN_ORFLAGS(pItem,
  2490. pLastItem,
  2491. ItemLevel,
  2492. OPTIF_INT_ADDED);
  2493. }
  2494. }
  2495. }
  2496. }
  2497. }
  2498. if ((GrpLevel == 1) && (hCurGrp)) {
  2499. CPSUIDBG(DBG_OEM_ITEM,
  2500. ("Add OEM Item Group, DMPubID=%ld", DMPubIDAdd));
  2501. pItem = pTVWnd->ComPropSheetUI.pOptItem;
  2502. cAdd += AddItemGroup(pTVWnd,
  2503. hCurGrp,
  2504. &pItem,
  2505. TVLevel,
  2506. DMPubIDAdd,
  2507. DMPubIDAdd);
  2508. }
  2509. *ppitvg = pitvg;
  2510. return(cAdd);
  2511. }
  2512. BOOL
  2513. AddOptItemToTreeView(
  2514. PTVWND pTVWnd
  2515. )
  2516. /*++
  2517. Routine Description:
  2518. Arguments:
  2519. Return Value:
  2520. Author:
  2521. 18-Aug-1995 Fri 14:39:32 created -by- Daniel Chou (danielc)
  2522. Revision History:
  2523. 30-Jul-1997 Wed 14:02:36 updated -by- Daniel Chou (danielc)
  2524. Added codes that allowed DMPubID 0 to be added to Root
  2525. --*/
  2526. {
  2527. HTREEITEM hParent;
  2528. HTREEITEM hRoot;
  2529. POPTITEM pItem;
  2530. UINT DefTVIS = TVIS_EXPANDED;
  2531. UINT TVLevel = 0;
  2532. //
  2533. // Adding the header to it as Icon: CallerName XXXX
  2534. //
  2535. hRoot =
  2536. hParent = AddItem(pTVWnd,
  2537. TVI_ROOT,
  2538. (POPTITEM)INTIDX_TVROOT,
  2539. DefTVIS | TVIS_BOLD,
  2540. TVLevel);
  2541. TVLevel += 1;
  2542. if (pTVWnd->Flags & TWF_TVPAGE_CHK_DMPUB) {
  2543. if (pTVWnd->Flags & TWF_TVPAGE_NODMPUB) {
  2544. POPTITEM pLastItem = pTVWnd->pLastItem;
  2545. //
  2546. // Mark all the DMPUB_xxx to OPTIF_INT_ADDED
  2547. //
  2548. pItem = pTVWnd->ComPropSheetUI.pOptItem;
  2549. while (pItem <= pLastItem) {
  2550. BYTE CurLevel = pItem->Level;
  2551. if ((pItem->DMPubID != DMPUB_NONE) &&
  2552. (pItem->DMPubID < DMPUB_USER)) {
  2553. SKIP_CHILDREN_ORFLAGS(pItem,
  2554. pLastItem,
  2555. CurLevel,
  2556. OPTIF_INT_ADDED);
  2557. } else {
  2558. SKIP_CHILDREN(pItem, pLastItem, CurLevel);
  2559. }
  2560. }
  2561. } else {
  2562. HTREEITEM hHdrGrp;
  2563. PINTTVGRP pitvg;
  2564. pitvg = (PINTTVGRP)IntTVGrpPaper;
  2565. AddPubGroup(pTVWnd,
  2566. hRoot,
  2567. &pitvg,
  2568. TVLevel,
  2569. DMPUB_OEM_PAPER_ITEM);
  2570. pitvg = (PINTTVGRP)IntTVGrpGraphic;
  2571. AddPubGroup(pTVWnd,
  2572. hRoot,
  2573. &pitvg,
  2574. TVLevel,
  2575. DMPUB_OEM_GRAPHIC_ITEM);
  2576. DefTVIS = 0;
  2577. }
  2578. }
  2579. if (pTVWnd->IntTVOptIdx) {
  2580. pItem = PIDX_INTOPTITEM(pTVWnd, pTVWnd->IntTVOptIdx);
  2581. if (pTVWnd->Flags & (TWF_ADVDOCPROP | TWF_TV_BY_PUSH)) {
  2582. pItem->Flags &= ~OPTIF_COLLAPSE;
  2583. }
  2584. if (pItem->Flags & OPTIF_COLLAPSE) {
  2585. DefTVIS &= ~TVIS_EXPANDED;
  2586. } else {
  2587. DefTVIS |= TVIS_EXPANDED;
  2588. }
  2589. hParent = AddItem(pTVWnd,
  2590. hRoot,
  2591. (POPTITEM)pTVWnd->IntTVOptIdx,
  2592. DefTVIS | TVIS_BOLD,
  2593. TVLevel);
  2594. //
  2595. // Add OEM items that under the TVROOT
  2596. //
  2597. CPSUIDBG(DBG_OEM_ITEM,
  2598. ("Add OEM Item Group, DMPubID=%ld", DMPUB_OEM_ROOT_ITEM));
  2599. pItem = pTVWnd->ComPropSheetUI.pOptItem;
  2600. AddItemGroup(pTVWnd,
  2601. hRoot,
  2602. &pItem,
  2603. TVLevel,
  2604. DMPUB_OEM_ROOT_ITEM,
  2605. DMPUB_OEM_ROOT_ITEM);
  2606. TVLevel += 1;
  2607. }
  2608. //
  2609. // Add rest of the OPTITEMS
  2610. //
  2611. pItem = pTVWnd->ComPropSheetUI.pOptItem;
  2612. if ((!AddItemGroup(pTVWnd, hParent, &pItem, TVLevel, 0, 0xFFFF)) &&
  2613. (hParent != hRoot)) {
  2614. //
  2615. // Since we did not add any item, s delete the Options header if any
  2616. //
  2617. CPSUIINT(("There is NO 'Options' items, delete the header"));
  2618. TreeView_DeleteItem(pTVWnd->hWndTV, hParent);
  2619. }
  2620. return(TRUE);
  2621. }
  2622. HWND
  2623. CreateTVOption(
  2624. HWND hDlg,
  2625. PTVWND pTVWnd
  2626. )
  2627. /*++
  2628. Routine Description:
  2629. Arguments:
  2630. Return Value:
  2631. Author:
  2632. 19-Jun-1995 Mon 16:18:43 created -by- Daniel Chou (danielc)
  2633. Revision History:
  2634. --*/
  2635. {
  2636. HWND hWndTV;
  2637. HTREEITEM hRoot;
  2638. POPTITEM pItem;
  2639. POPTITEM pCurTVItem;
  2640. POPTITEM pLastItem;
  2641. BYTE TVPageIdx;
  2642. pTVWnd->hDlgTV = hDlg;
  2643. pCurTVItem = pTVWnd->pCurTVItem;
  2644. if (hWndTV = CreatehWndTV(hDlg, pTVWnd)) {
  2645. pItem = &(pTVWnd->IntOptItem[0]);
  2646. pLastItem = &(pTVWnd->IntOptItem[INTIDX_TOTAL - 1]);
  2647. TVPageIdx = (BYTE)(pTVWnd->cMyDlgPage - 1);
  2648. while (pItem <= pLastItem) {
  2649. _OI_HITEM(pItem) = NULL;
  2650. pItem->Flags &= ~(OPTIF_INT_ADDED | OPTIF_INITIAL_TVITEM);
  2651. pItem->DlgPageIdx = TVPageIdx;
  2652. if (pItem == pCurTVItem) {
  2653. pItem->Flags |= OPTIF_INITIAL_TVITEM;
  2654. }
  2655. ++pItem;
  2656. }
  2657. pItem = pTVWnd->ComPropSheetUI.pOptItem;
  2658. pLastItem = pTVWnd->pLastItem;
  2659. while (pItem <= pLastItem) {
  2660. _OI_HITEM(pItem) = NULL;
  2661. pItem->Flags &= ~(OPTIF_INT_ADDED | OPTIF_INITIAL_TVITEM);
  2662. if ((pTVWnd->Flags & TWF_TV_BY_PUSH) &&
  2663. (pItem->DlgPageIdx != TVPageIdx)) {
  2664. pItem->Flags |= OPTIF_INT_ADDED;
  2665. }
  2666. if (pItem == pCurTVItem) {
  2667. pItem->Flags |= OPTIF_INITIAL_TVITEM;
  2668. }
  2669. ++pItem;
  2670. }
  2671. pTVWnd->pCurTVItem = NULL;
  2672. InitDlgCtrl(hDlg, pTVWnd);
  2673. SendMessage(pTVWnd->hWndTV,
  2674. TVM_SETIMAGELIST,
  2675. (WPARAM)TVSIL_NORMAL,
  2676. (LPARAM)pTVWnd->himi);
  2677. AddOptItemToTreeView(pTVWnd);
  2678. } else {
  2679. CPSUIERR(("\nCreatehWndTV() failed"));
  2680. }
  2681. return(hWndTV);
  2682. }
  2683. INT_PTR
  2684. CALLBACK
  2685. TreeViewProc(
  2686. HWND hDlg,
  2687. UINT Msg,
  2688. WPARAM wParam,
  2689. LPARAM lParam
  2690. )
  2691. /*++
  2692. Routine Description:
  2693. Arguments:
  2694. Return Value:
  2695. Author:
  2696. 28-Jun-1995 Wed 17:00:44 created -by- Daniel Chou (danielc)
  2697. Revision History:
  2698. --*/
  2699. {
  2700. POPTITEM pItem;
  2701. HWND hWndTV;
  2702. HWND *phWnd;
  2703. HICON hIcon;
  2704. PTVWND pTVWnd;
  2705. PMYDLGPAGE pCurMyDP;
  2706. NM_TREEVIEW *pNMTV;
  2707. DWORD dw;
  2708. HTREEITEM hItem;
  2709. if (Msg == WM_INITDIALOG) {
  2710. CPSUIINT(("Treeview WM_INITDIALOG: hDlg=%08lx, pPSP=%08lx", hDlg, lParam));
  2711. pCurMyDP = (PMYDLGPAGE)(((LPPROPSHEETPAGE)lParam)->lParam);
  2712. pTVWnd = (PTVWND)pCurMyDP->pTVWnd;
  2713. pCurMyDP->pPSPInfo = PPSPINFO_FROM_WM_INITDIALOG_LPARAM(lParam);
  2714. pCurMyDP->hDlgChild = NULL;
  2715. pTVWnd->Flags |= TWF_IN_TVPAGE;
  2716. SetWindowLongPtr(hDlg,
  2717. GWL_EXSTYLE,
  2718. GetWindowLongPtr(hDlg, GWL_EXSTYLE) | WS_EX_CONTEXTHELP);
  2719. if (!ADD_PMYDLGPAGE(hDlg, pCurMyDP)) {
  2720. return(FALSE);
  2721. }
  2722. if (pTVWnd->Flags & TWF_TV_BY_PUSH) {
  2723. SetWindowText(hDlg, ((LPPROPSHEETPAGE)lParam)->pszTitle);
  2724. }
  2725. CreateImageList(hDlg, pTVWnd);
  2726. CreateTVOption(hDlg, pTVWnd);
  2727. SetUniqChildID(hDlg);
  2728. UpdateCallBackChanges(hDlg, pTVWnd, TRUE);
  2729. if (pItem = pTVWnd->pCurTVItem) {
  2730. pTVWnd->pCurTVItem = NULL;
  2731. if (!TreeView_SelectItem(pTVWnd->hWndTV, _OI_HITEM(pItem))) {
  2732. pItem = NULL;
  2733. }
  2734. }
  2735. if ((!pItem) &&
  2736. (hItem = TreeView_GetRoot(pTVWnd->hWndTV)) &&
  2737. (!SelectFirstVisibleOptItem(pTVWnd, hItem))) {
  2738. TreeView_SelectItem(pTVWnd->hWndTV, hItem);
  2739. }
  2740. if (pTVWnd->Flags & TWF_TV_BY_PUSH) {
  2741. SetOptItemNewDef(hDlg, pTVWnd, TRUE);
  2742. }
  2743. SetFocus(pTVWnd->hWndTV);
  2744. return(FALSE);
  2745. }
  2746. if (pCurMyDP = GET_PMYDLGPAGE(hDlg)) {
  2747. pTVWnd = pCurMyDP->pTVWnd;
  2748. hWndTV = pTVWnd->hWndTV;
  2749. switch(Msg) {
  2750. case WM_GETDLGCODE:
  2751. CPSUIINT(("TreeViewProc: WM_GETDLGCODE"));
  2752. break;
  2753. case WM_NEXTDLGCTL:
  2754. CPSUIINT(("TreeViewProc: WM_NEXTDLGCTL: flHandle=%ld, wParam=%08lx",
  2755. LOWORD(lParam), wParam));
  2756. break;
  2757. case WM_DRAWITEM:
  2758. return(DrawLBCBItem(pTVWnd, (LPDRAWITEMSTRUCT)lParam));
  2759. case WM_COMMAND:
  2760. if (pTVWnd->Flags & TWF_TV_BY_PUSH) {
  2761. switch (LOWORD(wParam)) {
  2762. case IDCANCEL:
  2763. pItem = PIDX_INTOPTITEM(pTVWnd, INTIDX_TVROOT);
  2764. DoCallBack(hDlg,
  2765. pTVWnd,
  2766. pItem,
  2767. pItem->pSel,
  2768. (_CPSUICALLBACK)InternalRevertDef2,
  2769. NULL,
  2770. 0,
  2771. CPSUICB_REASON_SEL_CHANGED);
  2772. UpdateCallBackChanges(hDlg, pTVWnd, TRUE);
  2773. EndDialog(hDlg, 0);
  2774. return(TRUE);
  2775. case IDOK:
  2776. UpdateCallBackChanges(hDlg, pTVWnd, TRUE);
  2777. EndDialog(hDlg, 1);
  2778. return(TRUE);
  2779. default:
  2780. break;
  2781. }
  2782. }
  2783. //
  2784. // Fall though
  2785. //
  2786. case WM_HSCROLL:
  2787. if (pItem = DlgHScrollCommand(hDlg, pTVWnd, (HWND)lParam, wParam)) {
  2788. UpdateTreeViewItem(hDlg, pTVWnd, pItem, FALSE);
  2789. }
  2790. break;
  2791. case WM_ACTIVATE:
  2792. if (LOWORD(wParam) != WA_INACTIVE) {
  2793. CPSUIINT(("!! WM_SETACTIVE: cEdit=%ld !!", pTVWnd->chWndEdit));
  2794. InvalidateRect(hWndTV, NULL, FALSE);
  2795. if (dw = (DWORD)pTVWnd->chWndEdit) {
  2796. phWnd = pTVWnd->hWndEdit;
  2797. while (dw--) {
  2798. if (hWndTV = *phWnd++) {
  2799. SetWindowPos(hWndTV, NULL,
  2800. 0, 0, 0, 0,
  2801. SWP_NOSIZE | SWP_NOZORDER |
  2802. SWP_NOMOVE | SWP_FRAMECHANGED);
  2803. InvalidateRect(hWndTV, NULL, FALSE);
  2804. }
  2805. }
  2806. }
  2807. }
  2808. break;
  2809. case WM_HELP:
  2810. wParam = (WPARAM)((LPHELPINFO)lParam)->hItemHandle;
  2811. lParam = (LPARAM)MAKELONG(((LPHELPINFO)lParam)->MousePos.x,
  2812. ((LPHELPINFO)lParam)->MousePos.y);
  2813. case WM_CONTEXTMENU:
  2814. if (lParam == 0xFFFFFFFF) {
  2815. RECT rc;
  2816. if ((HWND)(wParam = (WPARAM)GetFocus()) == hWndTV) {
  2817. pTVWnd->VKeyTV = VK_F1;
  2818. if (TreeView_GetItemRect(hWndTV,
  2819. _OI_HITEM(pTVWnd->pCurTVItem),
  2820. &rc,
  2821. TRUE)) {
  2822. ClientToScreen(hWndTV, (LPPOINT)&rc.left);
  2823. ClientToScreen(hWndTV, (LPPOINT)&rc.right);
  2824. } else {
  2825. GetWindowRect((HWND)wParam, &rc);
  2826. }
  2827. } else {
  2828. GetWindowRect((HWND)wParam, &rc);
  2829. }
  2830. CPSUIINT(("MousePos=0xFFFFFFFF, GetFocus=%08lx, rc=(%ld, %ld)-(%ld, %ld)",
  2831. (HWND)wParam, rc.left, rc.top, rc.right, rc.bottom));
  2832. rc.left += ((rc.right - rc.left) / 2);
  2833. rc.top += ((rc.bottom - rc.top) / 2);
  2834. lParam = (LPARAM)MAKELONG(rc.left, rc.top);
  2835. }
  2836. CPSUIINT(("--- WM_%ws --hWndTV=%08lx, wParam=%08lx. Mouse=(%ld, %ld)----",
  2837. (Msg == WM_HELP) ? L"HELP" : L"CONTEXTMENU",
  2838. hWndTV, wParam, LOWORD(lParam), HIWORD(lParam)));
  2839. if ((HWND)wParam == hWndTV) {
  2840. pItem = (pTVWnd->VKeyTV == VK_F1) ?
  2841. pTVWnd->pCurTVItem : TreeViewHitTest(pTVWnd,
  2842. (LONG)lParam,
  2843. TVHT_ONITEM);
  2844. if (!pItem) {
  2845. CPSUIINT(("pItem=NULL, hWnd=%08lx, ID=%ld",
  2846. wParam, GetWindowLongPtr((HWND)wParam, GWLP_ID)));
  2847. pItem = pItemFromhWnd(hWndTV, pTVWnd, NULL, (LONG)lParam);
  2848. }
  2849. } else {
  2850. pItem = pItemFromhWnd(hDlg, pTVWnd, (HWND)wParam, (LONG)lParam);
  2851. }
  2852. //
  2853. // Reset key now
  2854. //
  2855. pTVWnd->VKeyTV = 0;
  2856. if (Msg == WM_CONTEXTMENU) {
  2857. DoContextMenu(pTVWnd, hDlg, pItem, lParam);
  2858. } else if (pItem) {
  2859. CommonPropSheetUIHelp(hDlg,
  2860. pTVWnd,
  2861. (HWND)hWndTV,
  2862. (DWORD)lParam,
  2863. pItem,
  2864. HELP_WM_HELP);
  2865. }
  2866. break;
  2867. case WM_NOTIFY:
  2868. pNMTV = (NM_TREEVIEW *)lParam;
  2869. dw = 0;
  2870. switch (pNMTV->hdr.code) {
  2871. case NM_DBLCLK:
  2872. TreeViewChangeMode(pTVWnd, pTVWnd->pCurTVItem, TVCM_SELECT);
  2873. break;
  2874. case NM_SETFOCUS:
  2875. case NM_CLICK:
  2876. case NM_RDBLCLK:
  2877. case NM_RCLICK:
  2878. break;
  2879. case TVN_ITEMEXPANDING:
  2880. CPSUIDBG(DBG_TVPROC, ("TVN_ITEMEXPANDING:"));
  2881. break;
  2882. case TVN_ITEMEXPANDED:
  2883. CPSUIDBG(DBG_TVPROC, ("TVN_ITEMEXPANDED:"));
  2884. if ((pTVWnd->IntTVOptIdx) &&
  2885. (pItem = PIDX_INTOPTITEM(pTVWnd, pTVWnd->IntTVOptIdx)) &&
  2886. (_OI_HITEM(pItem) == pNMTV->itemNew.hItem)) {
  2887. if (pNMTV->itemNew.state & TVIS_EXPANDED) {
  2888. CPSUIINT(("Internal OPTIONS Expanded"));
  2889. pItem->Flags &= ~OPTIF_COLLAPSE;
  2890. } else {
  2891. CPSUIINT(("Internal OPTIONS Collapse"));
  2892. pItem->Flags |= OPTIF_COLLAPSE;
  2893. }
  2894. }
  2895. break;
  2896. case TVN_KEYDOWN:
  2897. pTVWnd->VKeyTV = ((TV_KEYDOWN *)lParam)->wVKey;
  2898. CPSUIDBG(DBG_KEYS, ("TVN_KEYDOWN: VKey=%ld", pTVWnd->VKeyTV));
  2899. if ((pItem = pTVWnd->pCurTVItem) &&
  2900. (hItem = _OI_HITEM(pItem))) {
  2901. switch (pTVWnd->VKeyTV) {
  2902. case VK_LEFT:
  2903. case VK_BACK:
  2904. if ((!TreeView_GetChild(hWndTV, hItem)) &&
  2905. (hItem = TreeView_GetParent(hWndTV, hItem))) {
  2906. PostMessage(hWndTV,
  2907. TVM_SELECTITEM,
  2908. (WPARAM)TVGN_CARET,
  2909. (LPARAM)hItem);
  2910. }
  2911. break;
  2912. case VK_RIGHT:
  2913. if ((pTVWnd->chWndEdit) &&
  2914. (pTVWnd->hWndEdit[0])) {
  2915. SetFocus(pTVWnd->hWndEdit[0]);
  2916. }
  2917. break;
  2918. }
  2919. }
  2920. break;
  2921. case TVN_GETDISPINFO:
  2922. SetTVItemImage(pTVWnd, (TV_DISPINFO *)lParam);
  2923. break;
  2924. case TVN_SELCHANGED:
  2925. #if DO_IN_PLACE
  2926. if (pItem = pTVWnd->pCurTVItem) {
  2927. _OI_INTFLAGS(pItem) &= ~OIDF_ZERO_SEL_LEN;
  2928. SetTVItemState(pTVWnd, NULL, pItem);
  2929. }
  2930. if ((pItem = GetOptions(pTVWnd, pNMTV->itemNew.lParam)) &&
  2931. (!(pItem->Flags & OPTIF_INT_HIDE))) {
  2932. CPSUIINT(("pOldItem=%08lx, pNewItem=%08lx, cxItem=%ld/%ld",
  2933. pTVWnd->pCurTVItem, pItem, pTVWnd->cxItem, pTVWnd->cxMaxItem));
  2934. _OI_INTFLAGS(pItem) |= OIDF_ZERO_SEL_LEN;
  2935. SetTVItemState(pTVWnd, NULL, pItem);
  2936. }
  2937. pTVWnd->pCurTVItem = (POPTITEM)~0;
  2938. #endif
  2939. pTVWnd->pCurTVItem = SetupTVSelect(hDlg,
  2940. pNMTV,
  2941. STVS_REINIT | STVS_ACTIVE);
  2942. #if DO_IN_PLACE
  2943. if (pTVWnd->cxItem > pTVWnd->cxMaxItem) {
  2944. CPSUIINT(("pCurTVItem=%08lx, cxItem=%ld <= %ld, Redo SetTVItemState()",
  2945. pTVWnd->pCurTVItem, pTVWnd->cxItem, pTVWnd->cxMaxItem));
  2946. SetTVItemState(pTVWnd, NULL, pTVWnd->pCurTVItem);
  2947. }
  2948. #endif
  2949. CPSUIOPTITEM(DBGITEM_SELCHG, pTVWnd, "TVN_SELCHANGED", 1, pTVWnd->pCurTVItem);
  2950. CPSUIDBG(DBG_SCID, ("\n-----EnumChild of (%08lx)-----",
  2951. GetParent(hDlg)));
  2952. break;
  2953. case PSN_SETACTIVE:
  2954. CPSUIDBG(DBG_TVPROC,
  2955. ("\nTreeView: Got PSN_SETACTIVE, pTVWnd=%08lx (%ld), Page=%u -> %u\n",
  2956. pTVWnd, pTVWnd->cMyDlgPage,
  2957. (UINT)pTVWnd->ActiveDlgPage, (UINT)pCurMyDP->PageIdx));
  2958. pCurMyDP->Flags |= MYDPF_PAGE_ACTIVE;
  2959. pTVWnd->ActiveDlgPage = pCurMyDP->PageIdx;
  2960. pTVWnd->Flags |= TWF_IN_TVPAGE;
  2961. DoCallBack(hDlg,
  2962. pTVWnd,
  2963. pTVWnd->ComPropSheetUI.pOptItem,
  2964. (LPVOID)-1,
  2965. NULL,
  2966. NULL,
  2967. 0,
  2968. CPSUICB_REASON_SETACTIVE);
  2969. if ((pTVWnd->pCurTVItem) &&
  2970. (IS_HDR_PUSH(GET_POPTTYPE(pTVWnd->pCurTVItem)))) {
  2971. UpdateTreeViewItem(hDlg, pTVWnd, pTVWnd->pCurTVItem, TRUE);
  2972. }
  2973. UpdateTreeView(hDlg, pCurMyDP);
  2974. CPSUIINT(("!! WM_SETACTIVE: cEdit=%ld", pTVWnd->chWndEdit));
  2975. InvalidateRect(hWndTV, NULL, FALSE);
  2976. if (dw = (DWORD)pTVWnd->chWndEdit) {
  2977. phWnd = pTVWnd->hWndEdit;
  2978. while (dw--) {
  2979. if (hWndTV = *phWnd++) {
  2980. InvalidateRect(hWndTV, NULL, FALSE);
  2981. }
  2982. }
  2983. }
  2984. dw = 0;
  2985. break;
  2986. case PSN_KILLACTIVE:
  2987. CPSUIDBG(DBG_TVPROC, ("TreeView: Got PSN_KILLACTIVE, pTVWnd=%08lx (%ld)",
  2988. pTVWnd, pTVWnd->cMyDlgPage));
  2989. if (pCurMyDP) {
  2990. pCurMyDP->hWndFocus = GetFocus();
  2991. pCurMyDP->Flags &= ~MYDPF_PAGE_ACTIVE;
  2992. DoCallBack(hDlg,
  2993. pTVWnd,
  2994. pTVWnd->ComPropSheetUI.pOptItem,
  2995. (LPVOID)-1,
  2996. NULL,
  2997. NULL,
  2998. 0,
  2999. CPSUICB_REASON_KILLACTIVE);
  3000. pTVWnd->Flags &= ~TWF_IN_TVPAGE;
  3001. }
  3002. break;
  3003. case PSN_APPLY:
  3004. if ((pTVWnd->Flags & TWF_CAN_UPDATE) &&
  3005. (pTVWnd->ActiveDlgPage == pCurMyDP->PageIdx)) {
  3006. CPSUIDBG(DBG_TVPROC,
  3007. ("\nTreeViewPage: Do PSN_APPLY(%ld), Page: Cur=%u, Active=%u, Flags=%04lx, CALLBACK",
  3008. (pTVWnd->Flags & TWF_APPLY_NO_NEWDEF) ? 1 : 0,
  3009. (UINT)pCurMyDP->PageIdx, (UINT)pTVWnd->ActiveDlgPage,
  3010. pTVWnd->Flags));
  3011. if (DoCallBack(hDlg,
  3012. pTVWnd,
  3013. (pTVWnd->Flags & TWF_APPLY_NO_NEWDEF) ?
  3014. NULL : pTVWnd->ComPropSheetUI.pOptItem,
  3015. (LPVOID)-1,
  3016. NULL,
  3017. NULL,
  3018. 0,
  3019. CPSUICB_REASON_APPLYNOW) ==
  3020. CPSUICB_ACTION_NO_APPLY_EXIT) {
  3021. // send a PSN_SETACTIVE message to treeview page so that we will set the
  3022. // flags like TWF_IN_TVPAGE
  3023. HWND hParent;
  3024. if (hParent = GetParent(pTVWnd->hDlgTV)) {
  3025. PropSheet_SetCurSelByID(hParent, pCurMyDP->DlgPage.DlgTemplateID);
  3026. }
  3027. dw = PSNRET_INVALID_NOCHANGEPAGE;
  3028. }
  3029. } else {
  3030. CPSUIDBG(DBG_TVPROC,
  3031. ("\nTreeViewPage: Ignore PSN_APPLY, Page: Cur=%u, Active=%u, Flags=%04lx, DO NOTHING",
  3032. (UINT)pCurMyDP->PageIdx, (UINT)pTVWnd->ActiveDlgPage,
  3033. pTVWnd->Flags));
  3034. }
  3035. break;
  3036. case PSN_RESET:
  3037. CPSUIDBG(DBG_TVPROC, ("\nTreeView: Got PSN_RESET (Cancel)\n"));
  3038. break;
  3039. case PSN_HELP:
  3040. CPSUIDBG(DBG_TVPROC, ("\nTreeView: Got PSN_HELP (Help)\n"));
  3041. CommonPropSheetUIHelp(hDlg,
  3042. pTVWnd,
  3043. hWndTV,
  3044. 0,
  3045. NULL,
  3046. HELP_CONTENTS);
  3047. break;
  3048. default:
  3049. CPSUIDBG(DBG_TVPROC,
  3050. ("*TVProc: Unknow WM_NOTIFY=%08lx, id=%ld, hWnd=%08lx",
  3051. (DWORD)pNMTV->hdr.code, pNMTV->hdr.idFrom, pNMTV->hdr.hwndFrom));
  3052. break;
  3053. }
  3054. SetWindowLongPtr(hDlg, DWLP_MSGRESULT, (LPARAM)dw);
  3055. return(TRUE);
  3056. break;
  3057. case WM_DESTROY:
  3058. CPSUIINT(("TreeViewProc: Get WM_DESTROY Message"));
  3059. SetWindowLongPtr(hWndTV, GWLP_WNDPROC, (LPARAM)pTVWnd->TVWndProc);
  3060. DeleteTVFonts(pTVWnd);
  3061. if (pTVWnd->hDCTVWnd) {
  3062. ReleaseDC(hWndTV, pTVWnd->hDCTVWnd);
  3063. pTVWnd->hDCTVWnd = NULL;
  3064. }
  3065. if (hIcon = (HICON)SendDlgItemMessage(hDlg,
  3066. IDD_TV_ICON,
  3067. STM_SETIMAGE,
  3068. (WPARAM)IMAGE_ICON,
  3069. (LPARAM)NULL)) {
  3070. DestroyIcon(hIcon);
  3071. }
  3072. if (hIcon = (HICON)SendDlgItemMessage(hDlg,
  3073. IDD_TV_ECB_ICON,
  3074. STM_SETIMAGE,
  3075. (WPARAM)IMAGE_ICON,
  3076. (LPARAM)NULL)) {
  3077. DestroyIcon(hIcon);
  3078. }
  3079. SendMessage(hWndTV,
  3080. TVM_SETIMAGELIST,
  3081. (WPARAM)TVSIL_NORMAL,
  3082. (LPARAM)NULL);
  3083. DEL_PMYDLGPAGE(hDlg);
  3084. pTVWnd->hWndTV = NULL;
  3085. pTVWnd->Flags &= ~TWF_IN_TVPAGE;
  3086. break;
  3087. }
  3088. }
  3089. return(FALSE);
  3090. #undef pPSPInfo
  3091. }