Source code of Windows XP (NT5)
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.

2001 lines
69 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1996 - 2000.
  5. //
  6. // File: Propsht.cxx
  7. //
  8. // Contents: Property sheets for for CI snapin.
  9. //
  10. // History: 26-Nov-1996 KyleP Created
  11. //
  12. //--------------------------------------------------------------------------
  13. #include <pch.cxx>
  14. #pragma hdrstop
  15. #include <cimbmgr.hxx>
  16. #include <strres.hxx>
  17. #include <ciares.h>
  18. #include <propsht.hxx>
  19. #include <catalog.hxx>
  20. #include <prop.hxx>
  21. #include <strings.hxx>
  22. //
  23. // Local prototypes
  24. //
  25. void InitVTList( HWND hwndCombo );
  26. void InitVSList( HWND hwndComboVS, HWND hwndComboNNTP, CCatalog const & cat,
  27. ULONG & cVServers, ULONG & cNNTPServers );
  28. void InitStorageLevelList( HWND hwndCombo );
  29. void DisplayError( HWND hwnd, CException & e );
  30. BOOL GetDlgItemXArrayText( HWND hwndDlg, USHORT idCtrl, XArray<WCHAR> & xawcText );
  31. DWORD VSToIndex( HWND hwndDlg, DWORD dwItem, ULONG ulVS, BOOL fTrack );
  32. UINT DBTypeToVT(UINT uidbt);
  33. CIndexSrvPropertySheet0::CIndexSrvPropertySheet0( HINSTANCE hInstance,
  34. LONG_PTR hMmcNotify,
  35. CCatalogs * pCats )
  36. : _pCats( pCats ),
  37. _fFirstActive( TRUE ),
  38. _hMmcNotify( hMmcNotify )
  39. {
  40. _PropSheet.dwSize = sizeof( *this );
  41. _PropSheet.dwFlags = PSP_USETITLE;
  42. _PropSheet.hInstance = hInstance;
  43. _PropSheet.pszTemplate = MAKEINTRESOURCE(IDP_IS_PAGE0);
  44. _PropSheet.pszTitle = MAKEINTRESOURCE(IDP_IS_PAGE0_TITLE);
  45. _PropSheet.pfnDlgProc = CIndexSrvPropertySheet0::DlgProc;
  46. _PropSheet.lParam = (LPARAM)this;
  47. _hPropSheet = CreatePropertySheetPage( &_PropSheet );
  48. }
  49. CIndexSrvPropertySheet0::~CIndexSrvPropertySheet0()
  50. {
  51. }
  52. INT_PTR APIENTRY CIndexSrvPropertySheet0::DlgProc( HWND hwndDlg,
  53. UINT message,
  54. WPARAM wParam,
  55. LPARAM lParam )
  56. {
  57. BOOL fRet = FALSE;
  58. TRY
  59. {
  60. switch ( message )
  61. {
  62. case WM_INITDIALOG:
  63. {
  64. ciaDebugOut(( DEB_ITRACE, "CIndexSrvPropertySheet0::DlgProc -- WM_INITDIALOG\n" ));
  65. LONG_PTR lthis = ((CIndexSrvPropertySheet0 *)lParam)->_PropSheet.lParam;
  66. CIndexSrvPropertySheet0 * pthis = (CIndexSrvPropertySheet0 *)lthis;
  67. SetWindowLongPtr( hwndDlg, DWLP_USER, lthis );
  68. //
  69. // Default to local machine.
  70. //
  71. CheckRadioButton( hwndDlg,
  72. IDDI_LOCAL_COMPUTER,
  73. IDDI_REMOTE_COMPUTER,
  74. IDDI_LOCAL_COMPUTER );
  75. EnableWindow( GetDlgItem( hwndDlg, IDDI_COMPNAME ), FALSE );
  76. fRet = TRUE;
  77. break;
  78. }
  79. case WM_COMMAND:
  80. {
  81. switch ( LOWORD( wParam ) )
  82. {
  83. case IDDI_LOCAL_COMPUTER:
  84. {
  85. if ( BN_CLICKED == HIWORD(wParam) )
  86. {
  87. EnableWindow( GetDlgItem( hwndDlg, IDDI_COMPNAME ), FALSE );
  88. PropSheet_SetWizButtons( GetParent(hwndDlg), PSWIZB_FINISH );
  89. fRet = TRUE;
  90. }
  91. break;
  92. }
  93. case IDDI_REMOTE_COMPUTER:
  94. {
  95. if ( BN_CLICKED == HIWORD(wParam) )
  96. {
  97. EnableWindow( GetDlgItem( hwndDlg, IDDI_COMPNAME ), TRUE );
  98. //
  99. // If we have a string, then enable finish button.
  100. //
  101. XArray<WCHAR> xawcTemp;
  102. if ( GetDlgItemXArrayText( hwndDlg, IDDI_COMPNAME, xawcTemp ) &&
  103. xawcTemp.Count() > 0 )
  104. {
  105. PropSheet_SetWizButtons( GetParent(hwndDlg), PSWIZB_FINISH );
  106. }
  107. else
  108. {
  109. PropSheet_SetWizButtons( GetParent(hwndDlg), PSWIZB_DISABLEDFINISH );
  110. }
  111. fRet = TRUE;
  112. }
  113. break;
  114. }
  115. case IDDI_COMPNAME:
  116. {
  117. if ( EN_CHANGE == HIWORD(wParam) )
  118. {
  119. //
  120. // If we have a string, then enable finish button.
  121. //
  122. XArray<WCHAR> xawcTemp;
  123. if ( GetDlgItemXArrayText( hwndDlg, IDDI_COMPNAME, xawcTemp ) &&
  124. xawcTemp.Count() > 0 )
  125. {
  126. PropSheet_SetWizButtons( GetParent(hwndDlg), PSWIZB_FINISH );
  127. }
  128. else
  129. {
  130. PropSheet_SetWizButtons( GetParent(hwndDlg), PSWIZB_DISABLEDFINISH );
  131. }
  132. fRet = TRUE;
  133. }
  134. break;
  135. }
  136. /* Help is not being used...
  137. case IDHELP:
  138. {
  139. DisplayHelp( hwndDlg, HIDD_CONNECT_TO_COMPUTER );
  140. break;
  141. }
  142. */
  143. } // switch
  144. break;
  145. }
  146. case WM_HELP:
  147. {
  148. HELPINFO *phi = (HELPINFO *) lParam;
  149. ciaDebugOut(( DEB_ITRACE, "CIndexSrvPropertySheet0 WM_HELP contexttype: '%s', ctlid: %d, contextid: %d\n",
  150. phi->iContextType == HELPINFO_MENUITEM ? "menu" : "window",
  151. phi->iCtrlId, phi->dwContextId ));
  152. if ( HELPINFO_WINDOW == phi->iContextType )
  153. {
  154. switch ( phi->iCtrlId )
  155. {
  156. case IDDI_STATIC:
  157. break;
  158. default :
  159. DisplayPopupHelp((HWND)((LPHELPINFO) lParam)->hItemHandle, HELP_WM_HELP);
  160. break;
  161. }
  162. }
  163. break;
  164. }
  165. case WM_CONTEXTMENU:
  166. {
  167. DisplayPopupHelp((HWND)wParam, HELP_CONTEXTMENU);
  168. break;
  169. }
  170. case WM_NOTIFY:
  171. {
  172. CIndexSrvPropertySheet0 * pthis = (CIndexSrvPropertySheet0 *)GetWindowLongPtr( hwndDlg, DWLP_USER );
  173. switch ( ((LPNMHDR) lParam)->code )
  174. {
  175. case PSN_KILLACTIVE:
  176. {
  177. // Allow loss of activation
  178. SetWindowLongPtr( hwndDlg, DWLP_MSGRESULT, FALSE );
  179. fRet = TRUE;
  180. break;
  181. }
  182. case PSN_SETACTIVE:
  183. {
  184. if ( pthis->_fFirstActive )
  185. {
  186. PropSheet_SetWizButtons( GetParent(hwndDlg), PSWIZB_FINISH );
  187. pthis->_fFirstActive = FALSE;
  188. }
  189. else
  190. {
  191. // Go to next page
  192. SetWindowLongPtr( hwndDlg, DWLP_MSGRESULT, -1 );
  193. }
  194. fRet = TRUE;
  195. break;
  196. }
  197. case PSN_WIZBACK:
  198. {
  199. // Allow previous page
  200. SetWindowLongPtr( hwndDlg, DWLP_MSGRESULT, PSNRET_NOERROR );
  201. fRet = TRUE;
  202. break;
  203. }
  204. case PSN_WIZNEXT:
  205. {
  206. // Allow next page
  207. SetWindowLongPtr( hwndDlg, DWLP_MSGRESULT, PSNRET_NOERROR );
  208. fRet = TRUE;
  209. break;
  210. }
  211. case PSN_WIZFINISH:
  212. {
  213. TRY
  214. {
  215. XArray<WCHAR> xawcCompName;
  216. if ( IsDlgButtonChecked( hwndDlg, IDDI_LOCAL_COMPUTER ) )
  217. pthis->_pCats->SetMachine( L"." );
  218. else
  219. {
  220. if ( GetDlgItemXArrayText( hwndDlg, IDDI_COMPNAME, xawcCompName ) )
  221. {
  222. pthis->_pCats->SetMachine( xawcCompName.GetPointer() );
  223. }
  224. }
  225. MMCPropertyChangeNotify( pthis->_hMmcNotify, 0 );
  226. fRet = TRUE;
  227. }
  228. CATCH( CException, e )
  229. {
  230. // The only error caught here is a result of an invalid
  231. // machine name.
  232. Win4Assert(e.GetErrorCode() == E_INVALIDARG);
  233. MessageBox( hwndDlg,
  234. STRINGRESOURCE( srInvalidComputerName ),
  235. STRINGRESOURCE( srIndexServerCmpManage ),
  236. MB_OK | MB_ICONINFORMATION );
  237. }
  238. END_CATCH
  239. break;
  240. }
  241. } // switch
  242. break;
  243. }
  244. case WM_DESTROY:
  245. {
  246. CIndexSrvPropertySheet0 * pthis = (CIndexSrvPropertySheet0 *)GetWindowLongPtr( hwndDlg, DWLP_USER );
  247. MMCFreeNotifyHandle( pthis->_hMmcNotify );
  248. delete pthis;
  249. fRet = TRUE;
  250. break;
  251. }
  252. } // switch
  253. }
  254. CATCH( CException, e )
  255. {
  256. ciaDebugOut(( DEB_ERROR, "CIndexSrvPropertySheet0: Caught 0x%x\n", e.GetErrorCode() ));
  257. fRet = FALSE;
  258. }
  259. END_CATCH
  260. return fRet;
  261. }
  262. CIndexSrvPropertySheet1::CIndexSrvPropertySheet1( HINSTANCE hInstance,
  263. LONG_PTR hMmcNotify,
  264. CCatalog * pCat )
  265. : _pCat( pCat ),
  266. _pCats( 0 ),
  267. _hMmcNotify( hMmcNotify )
  268. {
  269. _PropSheet.dwSize = sizeof( *this );
  270. _PropSheet.dwFlags = PSP_USETITLE;
  271. _PropSheet.hInstance = hInstance;
  272. _PropSheet.pszTemplate = MAKEINTRESOURCE(IDP_IS_PAGE1);
  273. _PropSheet.pszTitle = MAKEINTRESOURCE(IDP_IS_PAGE1_TITLE);
  274. _PropSheet.pfnDlgProc = CIndexSrvPropertySheet1::DlgProc;
  275. _PropSheet.lParam = (LPARAM)this;
  276. _hPropSheet = CreatePropertySheetPage( &_PropSheet );
  277. }
  278. CIndexSrvPropertySheet1::CIndexSrvPropertySheet1( HINSTANCE hInstance,
  279. LONG_PTR hMmcNotify,
  280. CCatalogs * pCats )
  281. : _pCat( 0 ),
  282. _pCats( pCats ),
  283. _hMmcNotify( hMmcNotify )
  284. {
  285. _PropSheet.dwSize = sizeof( *this );
  286. _PropSheet.dwFlags = PSP_USETITLE;
  287. _PropSheet.hInstance = hInstance;
  288. _PropSheet.pszTemplate = MAKEINTRESOURCE(IDP_IS_PAGE1);
  289. _PropSheet.pszTitle = MAKEINTRESOURCE(IDP_IS_PAGE1_TITLE);
  290. _PropSheet.pfnDlgProc = CIndexSrvPropertySheet1::DlgProc;
  291. _PropSheet.lParam = (LPARAM)this;
  292. _hPropSheet = CreatePropertySheetPage( &_PropSheet );
  293. }
  294. CIndexSrvPropertySheet1::~CIndexSrvPropertySheet1()
  295. {
  296. }
  297. INT_PTR APIENTRY CIndexSrvPropertySheet1::DlgProc( HWND hwndDlg,
  298. UINT message,
  299. WPARAM wParam,
  300. LPARAM lParam )
  301. {
  302. BOOL fRet = FALSE;
  303. TRY
  304. {
  305. switch ( message )
  306. {
  307. case WM_HELP:
  308. {
  309. HELPINFO *phi = (HELPINFO *) lParam;
  310. ciaDebugOut(( DEB_ITRACE, "CIndexSrvPropertySheet1 WM_HELP contexttype: '%s', ctlid: %d, contextid: %d\n",
  311. phi->iContextType == HELPINFO_MENUITEM ? "menu" : "window",
  312. phi->iCtrlId, phi->dwContextId ));
  313. if ( HELPINFO_WINDOW == phi->iContextType )
  314. {
  315. switch ( phi->iCtrlId )
  316. {
  317. case IDDI_STATIC:
  318. break;
  319. default :
  320. DisplayPopupHelp((HWND)((LPHELPINFO) lParam)->hItemHandle, HELP_WM_HELP);
  321. break;
  322. }
  323. }
  324. break;
  325. }
  326. case WM_CONTEXTMENU:
  327. {
  328. DisplayPopupHelp((HWND)wParam, HELP_CONTEXTMENU);
  329. break;
  330. }
  331. case WM_INITDIALOG:
  332. {
  333. ciaDebugOut(( DEB_ITRACE, "CIndexSrvPropertySheet1::DlgProc -- WM_INITDIALOG\n" ));
  334. LONG_PTR lthis = ((CIndexSrvPropertySheet1 *)lParam)->_PropSheet.lParam;
  335. CIndexSrvPropertySheet1 * pthis = (CIndexSrvPropertySheet1 *)lthis;
  336. SetWindowLongPtr( hwndDlg, DWLP_USER, lthis );
  337. BOOL fUnknown;
  338. BOOL fGenerateCharacterization;
  339. ULONG ccCharacterization;
  340. if ( pthis->IsTrackingCatalog() )
  341. {
  342. pthis->_pCat->GetGeneration( fUnknown, fGenerateCharacterization, ccCharacterization );
  343. // Look in the registry for Group1 params. If at least one of them is listed
  344. // we should uncheck the "Inherit" checkbox. Otherwise
  345. // (if none of them is listed), we should check the box.
  346. SendDlgItemMessage( hwndDlg,
  347. IDDI_INHERIT1,
  348. BM_SETCHECK,
  349. pthis->_pCat->DoGroup1SettingsExist() ? BST_UNCHECKED : BST_CHECKED,
  350. 0 );
  351. // If at least one setting exists, add the others in the group.
  352. // We don't want to have an incomplete set.
  353. if (pthis->_pCat->DoGroup1SettingsExist())
  354. pthis->_pCat->FillGroup1Settings();
  355. }
  356. else
  357. {
  358. // Hide the "Inherit" checkbox because it is not applicable here
  359. ShowWindow(GetDlgItem(hwndDlg, IDDI_INHERIT1), SW_HIDE);
  360. pthis->_pCats->GetGeneration( fUnknown, fGenerateCharacterization, ccCharacterization );
  361. }
  362. SendDlgItemMessage( hwndDlg,
  363. IDDI_FILTER_UNKNOWN,
  364. BM_SETCHECK,
  365. fUnknown ? BST_CHECKED : BST_UNCHECKED,
  366. 0 );
  367. SendDlgItemMessage( hwndDlg,
  368. IDDI_CHARACTERIZATION,
  369. BM_SETCHECK,
  370. fGenerateCharacterization ? BST_CHECKED : BST_UNCHECKED,
  371. 0 );
  372. WCHAR wcsSize[120];
  373. _ultow( ccCharacterization, wcsSize, 10 );
  374. SetDlgItemText( hwndDlg, IDDI_CHARACTERIZATION_SIZE, wcsSize );
  375. SendDlgItemMessage( hwndDlg,
  376. IDDI_SPIN_CHARACTERIZATION,
  377. UDM_SETRANGE,
  378. 0,
  379. (LPARAM) MAKELONG( 10000, 10) );
  380. // If the generate characterization checkbox is unchecked, we should disable the
  381. // characterization size controls
  382. if (!fGenerateCharacterization)
  383. {
  384. EnableWindow(GetDlgItem(hwndDlg, IDDI_CHARACTERIZATION_SIZE), FALSE);
  385. EnableWindow(GetDlgItem(hwndDlg, IDDI_SPIN_CHARACTERIZATION), FALSE);
  386. EnableWindow(GetDlgItem(hwndDlg, IDDI_STATIC2), FALSE);
  387. }
  388. // If we are inheriting, we should disable the local setting.
  389. if ( pthis->IsTrackingCatalog() && !pthis->_pCat->DoGroup1SettingsExist())
  390. {
  391. EnableWindow(GetDlgItem(hwndDlg, IDDI_FILTER_UNKNOWN), FALSE);
  392. EnableWindow(GetDlgItem(hwndDlg, IDDI_CHARACTERIZATION), FALSE);
  393. EnableWindow(GetDlgItem(hwndDlg, IDDI_CHARACTERIZATION_SIZE), FALSE);
  394. EnableWindow(GetDlgItem(hwndDlg, IDDI_SPIN_CHARACTERIZATION), FALSE);
  395. EnableWindow(GetDlgItem(hwndDlg, IDDI_STATIC2), FALSE);
  396. }
  397. fRet = TRUE;
  398. break;
  399. }
  400. case WM_COMMAND:
  401. {
  402. BOOL fChanged = FALSE;
  403. BOOL fCorrected = TRUE;
  404. switch ( LOWORD( wParam ) )
  405. {
  406. case IDDI_CHARACTERIZATION:
  407. if (BN_CLICKED == HIWORD(wParam))
  408. {
  409. BOOL fGenChar = ( BST_CHECKED == SendDlgItemMessage( hwndDlg,
  410. IDDI_CHARACTERIZATION,
  411. BM_GETCHECK, 0, 0 ) );
  412. EnableWindow(GetDlgItem(hwndDlg, IDDI_CHARACTERIZATION_SIZE), fGenChar);
  413. EnableWindow(GetDlgItem(hwndDlg, IDDI_SPIN_CHARACTERIZATION), fGenChar);
  414. EnableWindow(GetDlgItem(hwndDlg, IDDI_STATIC2), fGenChar);
  415. if( 0 != GetWindowLongPtr( hwndDlg, DWLP_USER ) )
  416. {
  417. fChanged = TRUE;
  418. fRet = TRUE;
  419. }
  420. }
  421. break;
  422. case IDDI_FILTER_UNKNOWN:
  423. {
  424. if ( BN_CLICKED == HIWORD(wParam) )
  425. fChanged = TRUE;
  426. // Fall through
  427. }
  428. case IDDI_CHARACTERIZATION_SIZE:
  429. {
  430. if ( EN_KILLFOCUS == HIWORD(wParam) && LOWORD( wParam ) == IDDI_CHARACTERIZATION_SIZE )
  431. {
  432. fRet = TRUE;
  433. ULONG ulVal = 10;
  434. // Validate the number
  435. XArray<WCHAR> xawcTemp;
  436. if ( (LOWORD(wParam) == IDDI_CHARACTERIZATION_SIZE) &&
  437. GetDlgItemXArrayText( hwndDlg, IDDI_CHARACTERIZATION_SIZE, xawcTemp ) &&
  438. xawcTemp.Count() > 0 )
  439. {
  440. // verify that all characters are digits
  441. ULONG ulLen = wcslen(xawcTemp.GetPointer());
  442. // When correcting, let's do our best
  443. ulVal = _wtoi(xawcTemp.GetPointer());
  444. for (ULONG i = 0; i < ulLen; i++)
  445. {
  446. if (!iswdigit(xawcTemp[i]))
  447. break;
  448. }
  449. if (i == ulLen)
  450. {
  451. // verify that the number is within range
  452. ulVal = _wtoi(xawcTemp.GetPointer());
  453. if (ulVal <= 10000 && ulVal >= 10)
  454. {
  455. fCorrected = FALSE;
  456. }
  457. else
  458. ulVal = (ulVal < 10) ? 10 : 10000;
  459. }
  460. }
  461. if (fCorrected)
  462. {
  463. WCHAR wszBuff[20]; // use this instead of a potentially empty xawcTemp
  464. ciaDebugOut((DEB_ITRACE, "%ws is NOT a valid number\n", xawcTemp.GetPointer()));
  465. MessageBeep(MB_ICONHAND);
  466. SetWindowText((HWND)lParam, _itow(ulVal, wszBuff, 10));
  467. SendMessage((HWND)lParam, EM_SETSEL, 0, -1);
  468. }
  469. }
  470. else if ( EN_CHANGE == HIWORD(wParam) && ( 0 != GetWindowLongPtr( hwndDlg, DWLP_USER )) )
  471. {
  472. fChanged = TRUE;
  473. fRet = TRUE;
  474. }
  475. break;
  476. }
  477. case IDDI_INHERIT1:
  478. {
  479. if ( EN_CHANGE == HIWORD(wParam) || BN_CLICKED == HIWORD(wParam) )
  480. {
  481. if ( 0 != GetWindowLongPtr( hwndDlg, DWLP_USER ) )
  482. {
  483. fChanged = TRUE;
  484. fRet = TRUE;
  485. // If the Inherit Settings button is checked, we should remove the registry entries from the catalog's
  486. // settings so the values will be inherited from the service.
  487. BOOL fInherit = ( BST_CHECKED == SendDlgItemMessage( hwndDlg, IDDI_INHERIT1, BM_GETCHECK, 0, 0 ) );
  488. BOOL fUnknown = FALSE, fGenerateCharacterization = FALSE;
  489. DWORD ccCharacterization = 0;
  490. CIndexSrvPropertySheet1 * pthis = (CIndexSrvPropertySheet1 *)GetWindowLongPtr( hwndDlg, DWLP_USER );
  491. if (fInherit)
  492. {
  493. Win4Assert(pthis->IsTrackingCatalog());
  494. pthis->_pCat->GetParent().GetGeneration( fUnknown, fGenerateCharacterization, ccCharacterization );
  495. }
  496. else
  497. {
  498. pthis->_pCat->GetGeneration( fUnknown, fGenerateCharacterization, ccCharacterization );
  499. // Enable so we can set controls
  500. EnableWindow(GetDlgItem(hwndDlg, IDDI_FILTER_UNKNOWN), TRUE);
  501. EnableWindow(GetDlgItem(hwndDlg, IDDI_CHARACTERIZATION), TRUE);
  502. EnableWindow(GetDlgItem(hwndDlg, IDDI_CHARACTERIZATION_SIZE), TRUE);
  503. EnableWindow(GetDlgItem(hwndDlg, IDDI_SPIN_CHARACTERIZATION), TRUE);
  504. EnableWindow(GetDlgItem(hwndDlg, IDDI_STATIC2), TRUE);
  505. }
  506. SendDlgItemMessage( hwndDlg,
  507. IDDI_FILTER_UNKNOWN,
  508. BM_SETCHECK,
  509. fUnknown ? BST_CHECKED : BST_UNCHECKED,
  510. 0 );
  511. SendDlgItemMessage( hwndDlg,
  512. IDDI_CHARACTERIZATION,
  513. BM_SETCHECK,
  514. fGenerateCharacterization ? BST_CHECKED : BST_UNCHECKED,
  515. 0 );
  516. WCHAR wcsSize[12];
  517. _ultow( ccCharacterization, wcsSize, 10 );
  518. SetDlgItemText( hwndDlg, IDDI_CHARACTERIZATION_SIZE, wcsSize );
  519. // Enable/Disable controls if we need to
  520. EnableWindow(GetDlgItem(hwndDlg, IDDI_FILTER_UNKNOWN), !fInherit);
  521. EnableWindow(GetDlgItem(hwndDlg, IDDI_CHARACTERIZATION), !fInherit);
  522. EnableWindow(GetDlgItem(hwndDlg, IDDI_CHARACTERIZATION_SIZE), !fInherit);
  523. EnableWindow(GetDlgItem(hwndDlg, IDDI_SPIN_CHARACTERIZATION), !fInherit);
  524. EnableWindow(GetDlgItem(hwndDlg, IDDI_STATIC2), !fInherit);
  525. }
  526. }
  527. }
  528. } // switch
  529. if ( fChanged )
  530. PropSheet_Changed( GetParent(hwndDlg), hwndDlg );
  531. break;
  532. } // case
  533. case WM_NOTIFY:
  534. {
  535. switch ( ((LPNMHDR) lParam)->code )
  536. {
  537. case PSN_APPLY:
  538. {
  539. TRY
  540. {
  541. CIndexSrvPropertySheet1 * pthis = (CIndexSrvPropertySheet1 *)GetWindowLongPtr( hwndDlg, DWLP_USER );
  542. BOOL fUnknown = ( BST_CHECKED == SendDlgItemMessage( hwndDlg, IDDI_FILTER_UNKNOWN, BM_GETSTATE, 0, 0 ) );
  543. BOOL fGenerateCharacterization = ( BST_CHECKED == SendDlgItemMessage( hwndDlg, IDDI_CHARACTERIZATION, BM_GETSTATE, 0, 0 ) );
  544. WCHAR wcsSize[12];
  545. GetDlgItemText( hwndDlg, IDDI_CHARACTERIZATION_SIZE, wcsSize, sizeof(wcsSize)/sizeof(WCHAR) );
  546. ULONG ccCharacterization = wcstoul( wcsSize, 0, 10 );
  547. if ( pthis->IsTrackingCatalog() )
  548. {
  549. // If the Inherit Settings button is checked, we should remove the registry entries from the catalog's
  550. // settings so the values will be inherited from the service.
  551. BOOL fInherit = ( BST_CHECKED == SendDlgItemMessage( hwndDlg, IDDI_INHERIT1, BM_GETSTATE, 0, 0 ) );
  552. if (fInherit)
  553. pthis->_pCat->DeleteGroup1Settings();
  554. else
  555. pthis->_pCat->SetGeneration( fUnknown, fGenerateCharacterization, ccCharacterization );
  556. // Set the values and enable or disable the local controls as appropriate
  557. pthis->_pCat->GetGeneration( fUnknown, fGenerateCharacterization, ccCharacterization );
  558. SendDlgItemMessage( hwndDlg,
  559. IDDI_FILTER_UNKNOWN,
  560. BM_SETCHECK,
  561. fUnknown ? BST_CHECKED : BST_UNCHECKED,
  562. 0 );
  563. SendDlgItemMessage( hwndDlg,
  564. IDDI_CHARACTERIZATION,
  565. BM_SETCHECK,
  566. fGenerateCharacterization ? BST_CHECKED : BST_UNCHECKED,
  567. 0 );
  568. WCHAR wcsSize[12];
  569. _ultow( ccCharacterization, wcsSize, 10 );
  570. SetDlgItemText( hwndDlg, IDDI_CHARACTERIZATION_SIZE, wcsSize);
  571. EnableWindow(GetDlgItem(hwndDlg, IDDI_FILTER_UNKNOWN), !fInherit);
  572. EnableWindow(GetDlgItem(hwndDlg, IDDI_CHARACTERIZATION), !fInherit);
  573. EnableWindow(GetDlgItem(hwndDlg, IDDI_CHARACTERIZATION_SIZE), !fInherit);
  574. EnableWindow(GetDlgItem(hwndDlg, IDDI_SPIN_CHARACTERIZATION), !fInherit);
  575. EnableWindow(GetDlgItem(hwndDlg, IDDI_STATIC2), !fInherit);
  576. }
  577. else
  578. pthis->_pCats->SetGeneration( fUnknown, fGenerateCharacterization, ccCharacterization );
  579. MMCPropertyChangeNotify( pthis->_hMmcNotify, 0 );
  580. fRet = TRUE;
  581. }
  582. CATCH( CException, e )
  583. {
  584. DisplayError( hwndDlg, e );
  585. }
  586. END_CATCH
  587. break;
  588. }
  589. } // switch
  590. break;
  591. }
  592. case WM_DESTROY:
  593. {
  594. CIndexSrvPropertySheet1 * pthis = (CIndexSrvPropertySheet1 *)GetWindowLongPtr( hwndDlg, DWLP_USER );
  595. //
  596. // Only gets called on *one* property page!
  597. //
  598. // MMCFreeNotifyHandle( pthis->_hMmcNotify );
  599. delete pthis;
  600. fRet = TRUE;
  601. break;
  602. }
  603. } // switch
  604. }
  605. CATCH( CException, e )
  606. {
  607. ciaDebugOut(( DEB_ERROR, "CIndexSrvPropertySheet1: Caught 0x%x\n", e.GetErrorCode() ));
  608. fRet = FALSE;
  609. }
  610. END_CATCH
  611. return fRet;
  612. }
  613. CCatalogBasicPropertySheet::CCatalogBasicPropertySheet( HINSTANCE hInstance,
  614. LONG_PTR hMmcNotify,
  615. CCatalog const * pCat )
  616. : _pCat( pCat ),
  617. _hMmcNotify( hMmcNotify )
  618. {
  619. _PropSheet.dwSize = sizeof( *this );
  620. _PropSheet.dwFlags = PSP_USETITLE;
  621. _PropSheet.hInstance = hInstance;
  622. _PropSheet.pszTemplate = MAKEINTRESOURCE(IDP_CATALOG_PAGE1);
  623. _PropSheet.pszTitle = MAKEINTRESOURCE(IDP_CATALOG_PAGE1_TITLE);
  624. _PropSheet.pfnDlgProc = CCatalogBasicPropertySheet::DlgProc;
  625. _PropSheet.lParam = (LPARAM)this;
  626. _hPropSheet = CreatePropertySheetPage( &_PropSheet );
  627. }
  628. CCatalogBasicPropertySheet::~CCatalogBasicPropertySheet()
  629. {
  630. }
  631. INT_PTR APIENTRY CCatalogBasicPropertySheet::DlgProc( HWND hwndDlg,
  632. UINT message,
  633. WPARAM wParam,
  634. LPARAM lParam )
  635. {
  636. BOOL fRet = FALSE;
  637. TRY
  638. {
  639. switch ( message )
  640. {
  641. case WM_HELP:
  642. {
  643. HELPINFO *phi = (HELPINFO *) lParam;
  644. ciaDebugOut(( DEB_ITRACE,
  645. "CCatalogBasicPropertySheet::DlgProc -- WM_HELP: wp 0x%x, lp 0x%x\n",
  646. wParam, lParam ));
  647. if ( HELPINFO_WINDOW == phi->iContextType )
  648. {
  649. switch ( phi->iCtrlId )
  650. {
  651. case IDDI_STATIC:
  652. break;
  653. default :
  654. DisplayPopupHelp((HWND)((LPHELPINFO) lParam)->hItemHandle, HELP_WM_HELP);
  655. break;
  656. }
  657. }
  658. break;
  659. }
  660. case WM_CONTEXTMENU:
  661. {
  662. DisplayPopupHelp((HWND)wParam, HELP_CONTEXTMENU);
  663. break;
  664. }
  665. case WM_INITDIALOG:
  666. {
  667. ciaDebugOut(( DEB_ITRACE, "CCatalogBasicPropertySheet::DlgProc -- WM_INITDIALOG\n" ));
  668. LONG_PTR lthis = ((CCatalogBasicPropertySheet *)lParam)->_PropSheet.lParam;
  669. SetWindowLongPtr( hwndDlg, DWLP_USER, lthis );
  670. CCatalog const * pCat = ((CCatalogBasicPropertySheet *)lParam)->_pCat;
  671. SetDlgItemText( hwndDlg, IDDI_CATNAME, pCat->GetCat( TRUE ) );
  672. SetDlgItemText( hwndDlg, IDDI_SIZE, pCat->GetSize( TRUE ) );
  673. SetDlgItemText( hwndDlg, IDDI_PATH, pCat->GetDrive( TRUE ) );
  674. SetDlgItemText( hwndDlg, IDDI_PROPCACHE_SIZE, pCat->GetPropCacheSize( TRUE ) );
  675. fRet = TRUE;
  676. break;
  677. }
  678. case WM_DESTROY:
  679. {
  680. CCatalogBasicPropertySheet * pthis = (CCatalogBasicPropertySheet *)GetWindowLongPtr( hwndDlg, DWLP_USER );
  681. //
  682. // Only gets called on *one* property page!
  683. //
  684. // MMCFreeNotifyHandle( pthis->_hMmcNotify );
  685. delete pthis;
  686. fRet = TRUE;
  687. break;
  688. }
  689. } // switch
  690. }
  691. CATCH( CException, e )
  692. {
  693. ciaDebugOut(( DEB_ERROR, "CCatalogBasicPropertySheet: Caught 0x%x\n", e.GetErrorCode() ));
  694. fRet = FALSE;
  695. }
  696. END_CATCH
  697. return fRet;
  698. }
  699. CIndexSrvPropertySheet2::CIndexSrvPropertySheet2( HINSTANCE hInstance,
  700. LONG_PTR hMmcNotify,
  701. CCatalog * pCat )
  702. : _pCat( pCat ),
  703. _pCats( 0 ),
  704. _hMmcNotify( hMmcNotify ),
  705. _fNNTPServer( FALSE ),
  706. _fWebServer( FALSE )
  707. {
  708. _PropSheet.dwSize = sizeof( *this );
  709. _PropSheet.dwFlags = PSP_USETITLE;
  710. _PropSheet.hInstance = hInstance;
  711. _PropSheet.pszTemplate = MAKEINTRESOURCE(IDP_CATALOG_PAGE2);
  712. _PropSheet.pszTitle = MAKEINTRESOURCE(IDP_CATALOG_PAGE2_TITLE);
  713. _PropSheet.pfnDlgProc = CIndexSrvPropertySheet2::DlgProc;
  714. _PropSheet.lParam = (LPARAM)this;
  715. _hPropSheet = CreatePropertySheetPage( &_PropSheet );
  716. }
  717. CIndexSrvPropertySheet2::CIndexSrvPropertySheet2( HINSTANCE hInstance,
  718. LONG_PTR hMmcNotify,
  719. CCatalogs * pCats )
  720. : _pCat( 0 ),
  721. _pCats( pCats ),
  722. _hMmcNotify( hMmcNotify )
  723. {
  724. _PropSheet.dwSize = sizeof( *this );
  725. _PropSheet.dwFlags = PSP_USETITLE;
  726. _PropSheet.hInstance = hInstance;
  727. _PropSheet.pszTemplate = MAKEINTRESOURCE(IDP_CATALOG_PAGE2);
  728. _PropSheet.pszTitle = MAKEINTRESOURCE(IDP_CATALOG_PAGE2_TITLE);
  729. _PropSheet.pfnDlgProc = CIndexSrvPropertySheet2::DlgProc;
  730. _PropSheet.lParam = (LPARAM)this;
  731. _hPropSheet = CreatePropertySheetPage( &_PropSheet );
  732. }
  733. CIndexSrvPropertySheet2::~CIndexSrvPropertySheet2()
  734. {
  735. }
  736. INT_PTR APIENTRY CIndexSrvPropertySheet2::DlgProc( HWND hwndDlg,
  737. UINT message,
  738. WPARAM wParam,
  739. LPARAM lParam )
  740. {
  741. BOOL fRet = FALSE;
  742. TRY
  743. {
  744. switch ( message )
  745. {
  746. case WM_HELP:
  747. {
  748. HELPINFO *phi = (HELPINFO *) lParam;
  749. ciaDebugOut(( DEB_ITRACE, "CIndexSrvPropertySheet2 WM_HELP contexttype: '%s', ctlid: %d, contextid: %d\n",
  750. phi->iContextType == HELPINFO_MENUITEM ? "menu" : "window",
  751. phi->iCtrlId, phi->dwContextId ));
  752. if ( HELPINFO_WINDOW == phi->iContextType )
  753. {
  754. switch ( phi->iCtrlId )
  755. {
  756. case IDDI_STATIC:
  757. break;
  758. default :
  759. DisplayPopupHelp((HWND)((LPHELPINFO) lParam)->hItemHandle, HELP_WM_HELP);
  760. break;
  761. }
  762. }
  763. break;
  764. }
  765. case WM_CONTEXTMENU:
  766. {
  767. DisplayPopupHelp((HWND)wParam, HELP_CONTEXTMENU);
  768. break;
  769. }
  770. case WM_INITDIALOG:
  771. {
  772. ciaDebugOut(( DEB_ITRACE, "CIndexSrvPropertySheet2::DlgProc -- WM_INITDIALOG\n" ));
  773. LONG_PTR lthis = ((CIndexSrvPropertySheet2 *)lParam)->_PropSheet.lParam;
  774. CIndexSrvPropertySheet2 * pthis = (CIndexSrvPropertySheet2 *)lthis;
  775. SetWindowLongPtr( hwndDlg, DWLP_USER, lthis );
  776. BOOL fAutoAlias;
  777. BOOL fVirtualRoots;
  778. BOOL fNNTPRoots;
  779. ULONG iVirtualServer;
  780. ULONG iNNTPServer;
  781. // It is important to initialize the counters here to guarantee that
  782. // they will remain 0 if we don't get to invoke the enumerators that
  783. // count the number of servers.
  784. ULONG cVServers = 0, cNNTPServers = 0;
  785. ShowWindow(GetDlgItem(hwndDlg, IDDI_VIRTUAL_SERVER), FALSE);
  786. ShowWindow(GetDlgItem(hwndDlg, IDDI_NNTP_SERVER), FALSE);
  787. ShowWindow(GetDlgItem(hwndDlg, IDDI_VSERVER_STATIC), FALSE);
  788. ShowWindow(GetDlgItem(hwndDlg, IDDI_NNTP_STATIC), FALSE);
  789. if ( 0 != pthis->_pCat )
  790. {
  791. if ( AreServersAvailable( *(pthis->_pCat) ) )
  792. {
  793. pthis->_pCat->GetWeb( fVirtualRoots,
  794. fNNTPRoots,
  795. iVirtualServer,
  796. iNNTPServer );
  797. InitVSList( GetDlgItem(hwndDlg, IDDI_VIRTUAL_SERVER),
  798. GetDlgItem(hwndDlg, IDDI_NNTP_SERVER),
  799. *(pthis->_pCat),
  800. cVServers,
  801. cNNTPServers );
  802. }
  803. pthis->_pCat->GetTracking( fAutoAlias );
  804. // Look in the registry for Group2 params. If at least one of them is listed
  805. // we should uncheck the "Inherit" checkbox. Otherwise
  806. // (if none of them is listed), we should check the box.
  807. SendDlgItemMessage( hwndDlg,
  808. IDDI_INHERIT2,
  809. BM_SETCHECK,
  810. pthis->_pCat->DoGroup2SettingsExist() ? BST_UNCHECKED : BST_CHECKED,
  811. 0 );
  812. // If all the settings don't exist, then delete the others in the group.
  813. // We don't want to have part of the group inherited and part local.
  814. if (pthis->_pCat->DoGroup2SettingsExist())
  815. pthis->_pCat->FillGroup2Settings();
  816. }
  817. else
  818. {
  819. // Hide the "Inherit" checkbox because it is not applicable here
  820. ShowWindow(GetDlgItem(hwndDlg, IDDI_INHERIT2), SW_HIDE);
  821. pthis->_pCats->GetTracking( fAutoAlias );
  822. }
  823. if (cVServers)
  824. {
  825. ShowWindow(GetDlgItem(hwndDlg, IDDI_VIRTUAL_SERVER), TRUE);
  826. ShowWindow(GetDlgItem(hwndDlg, IDDI_VSERVER_STATIC), TRUE);
  827. pthis->_fWebServer = TRUE;
  828. SendDlgItemMessage( hwndDlg,
  829. IDDI_VIRTUAL_SERVER,
  830. CB_SETCURSEL,
  831. VSToIndex( hwndDlg, IDDI_VIRTUAL_SERVER,
  832. iVirtualServer, fVirtualRoots ), 0 );
  833. }
  834. if (cNNTPServers)
  835. {
  836. ShowWindow(GetDlgItem(hwndDlg, IDDI_NNTP_SERVER), TRUE);
  837. ShowWindow(GetDlgItem(hwndDlg, IDDI_NNTP_STATIC), TRUE);
  838. pthis->_fNNTPServer = TRUE;
  839. SendDlgItemMessage( hwndDlg,
  840. IDDI_NNTP_SERVER,
  841. CB_SETCURSEL,
  842. VSToIndex( hwndDlg, IDDI_NNTP_SERVER,
  843. iNNTPServer, fNNTPRoots ), 0 );
  844. }
  845. SendDlgItemMessage( hwndDlg,
  846. IDDI_AUTO_ALIAS,
  847. BM_SETCHECK,
  848. fAutoAlias ? BST_CHECKED : BST_UNCHECKED,
  849. 0 );
  850. // If we are inheriting, we should disable the local setting.
  851. if ( 0 != pthis->_pCat && !pthis->_pCat->DoGroup2SettingsExist())
  852. EnableWindow(GetDlgItem(hwndDlg, IDDI_AUTO_ALIAS), FALSE);
  853. fRet = TRUE;
  854. break;
  855. }
  856. case WM_COMMAND:
  857. {
  858. BOOL fChanged = FALSE;
  859. switch ( LOWORD( wParam ) )
  860. {
  861. case IDDI_VIRTUAL_SERVER:
  862. case IDDI_NNTP_SERVER:
  863. {
  864. if ( CBN_SELCHANGE == HIWORD(wParam) )
  865. {
  866. if ( 0 != GetWindowLongPtr( hwndDlg, DWLP_USER ) )
  867. {
  868. fChanged = TRUE;
  869. fRet = TRUE;
  870. }
  871. }
  872. break;
  873. }
  874. case IDDI_AUTO_ALIAS:
  875. {
  876. if ( EN_CHANGE == HIWORD(wParam) || BN_CLICKED == HIWORD(wParam) )
  877. {
  878. if ( 0 != GetWindowLongPtr( hwndDlg, DWLP_USER ) )
  879. {
  880. fChanged = TRUE;
  881. fRet = TRUE;
  882. }
  883. }
  884. break;
  885. }
  886. case IDDI_INHERIT2:
  887. {
  888. if ( EN_CHANGE == HIWORD(wParam) || BN_CLICKED == HIWORD(wParam) )
  889. {
  890. if ( 0 != GetWindowLongPtr( hwndDlg, DWLP_USER ) )
  891. {
  892. fChanged = TRUE;
  893. fRet = TRUE;
  894. BOOL fInherit = ( BST_CHECKED == SendDlgItemMessage( hwndDlg, IDDI_INHERIT2, BM_GETCHECK, 0, 0 ) );
  895. BOOL fAutoAlias = FALSE;
  896. CIndexSrvPropertySheet2 * pthis = (CIndexSrvPropertySheet2 *)GetWindowLongPtr( hwndDlg, DWLP_USER );
  897. if (fInherit)
  898. {
  899. Win4Assert(pthis->IsTrackingCatalog());
  900. pthis->_pCat->GetParent().GetTracking(fAutoAlias);
  901. }
  902. else
  903. {
  904. pthis->_pCat->GetTracking(fAutoAlias);
  905. // Enable so we can set controls
  906. EnableWindow(GetDlgItem(hwndDlg, IDDI_AUTO_ALIAS), TRUE);
  907. }
  908. SendDlgItemMessage( hwndDlg,
  909. IDDI_AUTO_ALIAS,
  910. BM_SETCHECK,
  911. fAutoAlias ? BST_CHECKED : BST_UNCHECKED,
  912. 0 );
  913. // Disable controls if we need to
  914. if (fInherit)
  915. EnableWindow(GetDlgItem(hwndDlg, IDDI_AUTO_ALIAS), FALSE);
  916. }
  917. }
  918. }
  919. } // switch
  920. if ( fChanged )
  921. PropSheet_Changed( GetParent(hwndDlg), hwndDlg );
  922. break;
  923. }
  924. case WM_NOTIFY:
  925. {
  926. switch ( ((LPNMHDR) lParam)->code )
  927. {
  928. case PSN_APPLY:
  929. {
  930. TRY
  931. {
  932. CIndexSrvPropertySheet2 * pthis = (CIndexSrvPropertySheet2 *)GetWindowLongPtr( hwndDlg, DWLP_USER );
  933. BOOL fAutoAlias = ( BST_CHECKED == SendDlgItemMessage( hwndDlg, IDDI_AUTO_ALIAS, BM_GETSTATE, 0, 0 ) );
  934. if ( 0 != pthis->_pCat )
  935. {
  936. BOOL fVirtualRoots = FALSE;
  937. ULONG iVirtualServer = 0;
  938. if ( pthis->_fWebServer )
  939. {
  940. iVirtualServer = (ULONG)SendDlgItemMessage( hwndDlg, IDDI_VIRTUAL_SERVER, CB_GETCURSEL, 0, 0 );
  941. fVirtualRoots = ( 0 != iVirtualServer );
  942. iVirtualServer = (ULONG)SendDlgItemMessage( hwndDlg, IDDI_VIRTUAL_SERVER, CB_GETITEMDATA, iVirtualServer, 0 );
  943. }
  944. BOOL fNNTPRoots = FALSE;
  945. ULONG iNNTPServer = 0;
  946. if ( pthis->_fNNTPServer )
  947. {
  948. iNNTPServer = (ULONG)SendDlgItemMessage( hwndDlg, IDDI_NNTP_SERVER, CB_GETCURSEL, 0, 0 );
  949. fNNTPRoots = ( 0 != iNNTPServer );
  950. iNNTPServer = (ULONG)SendDlgItemMessage( hwndDlg, IDDI_NNTP_SERVER, CB_GETITEMDATA, iNNTPServer, 0 );
  951. }
  952. pthis->_pCat->SetWeb( fVirtualRoots, fNNTPRoots, iVirtualServer, iNNTPServer );
  953. // If the Inherit Settings button is checked, we should remove the registry entries from the catalog's
  954. // settings so the values will be inherited from the service.
  955. BOOL fInherit = ( BST_CHECKED == SendDlgItemMessage( hwndDlg, IDDI_INHERIT2, BM_GETSTATE, 0, 0 ) );
  956. if (fInherit)
  957. pthis->_pCat->DeleteGroup2Settings();
  958. else
  959. pthis->_pCat->SetTracking( fAutoAlias );
  960. // Set the current values and set state of the local controls
  961. BOOL fAutoAlias;
  962. pthis->_pCat->GetTracking( fAutoAlias );
  963. SendDlgItemMessage( hwndDlg,
  964. IDDI_AUTO_ALIAS,
  965. BM_SETCHECK,
  966. fAutoAlias ? BST_CHECKED : BST_UNCHECKED,
  967. 0 );
  968. EnableWindow(GetDlgItem(hwndDlg, IDDI_AUTO_ALIAS), !fInherit);
  969. }
  970. else
  971. pthis->_pCats->SetTracking( fAutoAlias );
  972. MMCPropertyChangeNotify( pthis->_hMmcNotify, 0 );
  973. fRet = TRUE;
  974. }
  975. CATCH( CException, e )
  976. {
  977. DisplayError( hwndDlg, e );
  978. }
  979. END_CATCH
  980. break;
  981. }
  982. } // switch
  983. break;
  984. }
  985. case WM_DESTROY:
  986. {
  987. CIndexSrvPropertySheet2 * pthis = (CIndexSrvPropertySheet2 *)GetWindowLongPtr( hwndDlg, DWLP_USER );
  988. //
  989. // Only gets called on *one* property page!
  990. //
  991. // MMCFreeNotifyHandle( pthis->_hMmcNotify );
  992. delete pthis;
  993. fRet = TRUE;
  994. break;
  995. }
  996. } // switch
  997. }
  998. CATCH( CException, e )
  999. {
  1000. ciaDebugOut(( DEB_ERROR, "CIndexSrvPropertySheet2: Caught 0x%x\n", e.GetErrorCode() ));
  1001. fRet = FALSE;
  1002. }
  1003. END_CATCH
  1004. return fRet;
  1005. }
  1006. CPropertyPropertySheet1::CPropertyPropertySheet1( HINSTANCE hInstance,
  1007. LONG_PTR hMmcNotify,
  1008. CCachedProperty * pProperty,
  1009. CCatalog * pCat )
  1010. : _pProperty( pProperty ),
  1011. _propNew( *pProperty ),
  1012. _hMmcNotify( hMmcNotify ),
  1013. _pCat( pCat )
  1014. {
  1015. _PropSheet.dwSize = sizeof( _PropSheet ) + sizeof( this );
  1016. _PropSheet.dwFlags = PSP_USETITLE;
  1017. _PropSheet.hInstance = hInstance;
  1018. _PropSheet.pszTemplate = MAKEINTRESOURCE(IDP_PROPERTY_PAGE1);
  1019. _PropSheet.pszTitle = MAKEINTRESOURCE(IDP_PROPERTY_PAGE1_TITLE);
  1020. _PropSheet.pfnDlgProc = CPropertyPropertySheet1::DlgProc;
  1021. _PropSheet.lParam = (LPARAM)this;
  1022. _hPropSheet = CreatePropertySheetPage( &_PropSheet );
  1023. }
  1024. CPropertyPropertySheet1::~CPropertyPropertySheet1()
  1025. {
  1026. }
  1027. INT_PTR APIENTRY CPropertyPropertySheet1::DlgProc( HWND hwndDlg,
  1028. UINT message,
  1029. WPARAM wParam,
  1030. LPARAM lParam )
  1031. {
  1032. BOOL fRet = FALSE;
  1033. TRY
  1034. {
  1035. switch ( message )
  1036. {
  1037. case WM_HELP:
  1038. {
  1039. HELPINFO *phi = (HELPINFO *) lParam;
  1040. ciaDebugOut(( DEB_ITRACE,
  1041. "CPropertyPropertySheet1 WM_HELP contexttype: '%s', ctlid: %d, contextid: %d\n",
  1042. phi->iContextType == HELPINFO_MENUITEM ? "menu" : "window",
  1043. phi->iCtrlId, phi->dwContextId ));
  1044. if ( HELPINFO_WINDOW == phi->iContextType )
  1045. {
  1046. switch ( phi->iCtrlId )
  1047. {
  1048. case IDDI_STATIC:
  1049. break;
  1050. default :
  1051. DisplayPopupHelp((HWND)((LPHELPINFO) lParam)->hItemHandle, HELP_WM_HELP);
  1052. break;
  1053. }
  1054. }
  1055. break;
  1056. }
  1057. case WM_CONTEXTMENU:
  1058. {
  1059. DisplayPopupHelp((HWND)wParam, HELP_CONTEXTMENU);
  1060. break;
  1061. }
  1062. case WM_INITDIALOG:
  1063. {
  1064. ciaDebugOut(( DEB_ITRACE, "CPropertyPropertySheet1::DlgProc -- WM_INITDIALOG\n" ));
  1065. LONG_PTR lthis = ((CPropertyPropertySheet1 *)lParam)->_PropSheet.lParam;
  1066. SetWindowLongPtr( hwndDlg, DWLP_USER, lthis );
  1067. CCachedProperty const & prop = ((CPropertyPropertySheet1 *)lthis)->_propNew;
  1068. SetDlgItemText( hwndDlg, IDDI_PROPSET, prop.GetPropSet() );
  1069. SetDlgItemText( hwndDlg, IDDI_PROPERTY, prop.GetProperty() );
  1070. SendDlgItemMessage( hwndDlg,
  1071. IDDI_SPIN_CACHEDSIZE,
  1072. UDM_SETRANGE,
  1073. 0,
  1074. (LPARAM) MAKELONG( 500, 4) );
  1075. InitVTList( GetDlgItem(hwndDlg, IDDI_DATATYPE) );
  1076. InitStorageLevelList( GetDlgItem(hwndDlg, IDDI_STORAGELEVEL) );
  1077. if ( prop.IsCached() )
  1078. {
  1079. SendDlgItemMessage( hwndDlg, IDDI_CACHED, BM_SETCHECK, BST_CHECKED, 0 );
  1080. SendDlgItemMessage( hwndDlg, IDDI_DATATYPE, CB_SETCURSEL, aulTypeIndex[ prop.GetVT() & ~VT_VECTOR ], 0 );
  1081. // StoreLevel() is 0 for primary, 1 for secondary, which is the sequence in which we added them.
  1082. // So using StoreLevel() as in index will work fine!
  1083. SendDlgItemMessage( hwndDlg, IDDI_STORAGELEVEL, CB_SETCURSEL, prop.StoreLevel(), 0 );
  1084. SetDlgItemText( hwndDlg, IDDI_CACHEDSIZE, prop.GetAllocation() );
  1085. // Currently we do not allow the storage level to be changed after initial setting
  1086. EnableWindow( GetDlgItem( hwndDlg, IDDI_STORAGELEVEL), FALSE );
  1087. }
  1088. else
  1089. {
  1090. SendDlgItemMessage( hwndDlg, IDDI_CACHED, BM_SETCHECK, BST_UNCHECKED, 0 );
  1091. EnableWindow( GetDlgItem( hwndDlg, IDDI_DATATYPE ), FALSE );
  1092. EnableWindow( GetDlgItem( hwndDlg, IDDI_STORAGELEVEL), FALSE );
  1093. EnableWindow( GetDlgItem( hwndDlg, IDDI_CACHEDSIZE ), FALSE );
  1094. EnableWindow( GetDlgItem( hwndDlg, IDDI_SPIN_CACHEDSIZE ), FALSE );
  1095. EnableWindow( GetDlgItem( GetParent(hwndDlg), IDOK), FALSE );
  1096. }
  1097. // If properties cannot be modified, disable all controls
  1098. // Only cached properties can be resitant to modifications!
  1099. if (!prop.IsModifiable() && prop.IsCached())
  1100. {
  1101. EnableWindow( GetDlgItem( hwndDlg, IDDI_CACHED), FALSE );
  1102. EnableWindow( GetDlgItem( hwndDlg, IDDI_DATATYPE ), FALSE );
  1103. EnableWindow( GetDlgItem( hwndDlg, IDDI_STORAGELEVEL), FALSE );
  1104. EnableWindow( GetDlgItem( hwndDlg, IDDI_CACHEDSIZE ), FALSE );
  1105. EnableWindow( GetDlgItem( hwndDlg, IDDI_SPIN_CACHEDSIZE ), FALSE );
  1106. EnableWindow( GetDlgItem( GetParent(hwndDlg), IDOK), FALSE );
  1107. }
  1108. fRet = TRUE;
  1109. break;
  1110. }
  1111. case WM_COMMAND:
  1112. {
  1113. BOOL fChanged = FALSE;
  1114. BOOL fCorrected = TRUE;
  1115. switch ( LOWORD( wParam ) )
  1116. {
  1117. case IDDI_DATATYPE:
  1118. {
  1119. if ( CBN_CLOSEUP == HIWORD(wParam) )
  1120. {
  1121. CPropertyPropertySheet1 * pthis = (CPropertyPropertySheet1 *)GetWindowLongPtr( hwndDlg, DWLP_USER );
  1122. fChanged = pthis->Refresh( hwndDlg, TRUE );
  1123. if ( pthis->_propNew.IsFixed() )
  1124. {
  1125. SetDlgItemText( hwndDlg, IDDI_CACHEDSIZE, pthis->_propNew.GetAllocation() );
  1126. // Disable the size control
  1127. EnableWindow( GetDlgItem( hwndDlg, IDDI_CACHEDSIZE ), FALSE );
  1128. EnableWindow( GetDlgItem( hwndDlg, IDDI_SPIN_CACHEDSIZE ), FALSE );
  1129. }
  1130. else
  1131. {
  1132. SetDlgItemText( hwndDlg, IDDI_CACHEDSIZE, L"4" );
  1133. // Enable the size control. Variable props can be resized.
  1134. EnableWindow( GetDlgItem( hwndDlg, IDDI_CACHEDSIZE ), TRUE );
  1135. EnableWindow( GetDlgItem( hwndDlg, IDDI_SPIN_CACHEDSIZE ), TRUE );
  1136. }
  1137. fRet = TRUE;
  1138. }
  1139. break;
  1140. }
  1141. case IDDI_STORAGELEVEL:
  1142. {
  1143. CPropertyPropertySheet1 * pthis = (CPropertyPropertySheet1 *)GetWindowLongPtr( hwndDlg, DWLP_USER );
  1144. if ( CBN_CLOSEUP == HIWORD(wParam) )
  1145. {
  1146. fChanged = pthis->Refresh( hwndDlg, TRUE );
  1147. fRet = TRUE;
  1148. }
  1149. break;
  1150. }
  1151. case IDDI_CACHEDSIZE:
  1152. {
  1153. if ( EN_KILLFOCUS == HIWORD(wParam) )
  1154. {
  1155. fRet = TRUE;
  1156. ULONG ulVal = 4;
  1157. // Validate the number
  1158. XArray<WCHAR> xawcTemp;
  1159. if ( GetDlgItemXArrayText( hwndDlg, IDDI_CACHEDSIZE, xawcTemp ) &&
  1160. xawcTemp.Count() > 0 )
  1161. {
  1162. // verify that all characters are digits
  1163. ULONG ulLen = wcslen(xawcTemp.GetPointer());
  1164. // When correcting, let's do our best.
  1165. ulVal = _wtoi(xawcTemp.GetPointer());
  1166. for (ULONG i = 0; i < ulLen; i++)
  1167. {
  1168. if (!iswdigit(xawcTemp[i]))
  1169. break;
  1170. }
  1171. if (i == ulLen)
  1172. {
  1173. // verify that the number is within range
  1174. ulVal = _wtoi(xawcTemp.GetPointer());
  1175. ciaDebugOut((DEB_ERROR, "number is %d, string is %ws\n",
  1176. ulVal, xawcTemp.GetPointer()));
  1177. if (ulVal <= 500)
  1178. fCorrected = FALSE;
  1179. else if (ulVal > 500)
  1180. ulVal = 500;
  1181. }
  1182. }
  1183. // if we are dealing with a vble property, we should ensure that the
  1184. // size is at least 4 bytes
  1185. if (ulVal < 4)
  1186. {
  1187. CPropertyPropertySheet1 * pthis = (CPropertyPropertySheet1 *)GetWindowLongPtr( hwndDlg, DWLP_USER );
  1188. if ( 0 != pthis )
  1189. {
  1190. if (pthis->_propNew.IsCached() && !pthis->_propNew.IsFixed())
  1191. {
  1192. ulVal = 4;
  1193. fCorrected = TRUE;
  1194. }
  1195. }
  1196. }
  1197. if (fCorrected)
  1198. {
  1199. MessageBeep(MB_ICONHAND);
  1200. // xawcTemp may not have a buffer, so don't use it for _itow. Use a temp vble
  1201. WCHAR wszBuff[20];
  1202. SetWindowText((HWND)lParam, _itow(ulVal, wszBuff, 10));
  1203. SendMessage((HWND)lParam, EM_SETSEL, 0, -1);
  1204. }
  1205. }
  1206. else if ( EN_CHANGE == HIWORD(wParam) && ( 0 != GetWindowLongPtr( hwndDlg, DWLP_USER )) )
  1207. {
  1208. CPropertyPropertySheet1 * pthis = (CPropertyPropertySheet1 *)GetWindowLongPtr( hwndDlg, DWLP_USER );
  1209. if ( 0 != pthis )
  1210. {
  1211. fChanged = pthis->Refresh( hwndDlg, FALSE );
  1212. fRet = TRUE;
  1213. }
  1214. }
  1215. break;
  1216. }
  1217. case IDDI_CACHED:
  1218. {
  1219. if ( BN_CLICKED == HIWORD(wParam) )
  1220. {
  1221. CPropertyPropertySheet1 * pthis = (CPropertyPropertySheet1 *)GetWindowLongPtr( hwndDlg, DWLP_USER );
  1222. ULONG fChecked = (ULONG)SendDlgItemMessage( hwndDlg, IDDI_CACHED, BM_GETSTATE, 0, 0 );
  1223. if ( fChecked & BST_CHECKED )
  1224. {
  1225. pthis->Refresh( hwndDlg, FALSE );
  1226. EnableWindow( GetDlgItem( hwndDlg, IDDI_DATATYPE ), TRUE );
  1227. EnableWindow( GetDlgItem( hwndDlg, IDDI_CACHEDSIZE ), TRUE );
  1228. EnableWindow( GetDlgItem( hwndDlg, IDDI_SPIN_CACHEDSIZE ), TRUE );
  1229. // If this property is currently being cached in the property store (as indicated
  1230. // by CCachedProperty), we do not let it's store level be changed. This ensures
  1231. // that a user cannot change a property between store levels.
  1232. if (pthis->_propNew.IsCached() && INVALID_STORE_LEVEL != pthis->_propNew.StoreLevel())
  1233. {
  1234. SendDlgItemMessage( hwndDlg, IDDI_STORAGELEVEL, CB_SETCURSEL,
  1235. pthis->_propNew.StoreLevel(), 0 );
  1236. EnableWindow( GetDlgItem( hwndDlg, IDDI_STORAGELEVEL), FALSE );
  1237. }
  1238. else
  1239. {
  1240. // enable and display the storage level. Default to secondary,
  1241. // if none is available
  1242. if (PRIMARY_STORE != pthis->_propNew.StoreLevel())
  1243. pthis->_propNew.SetStoreLevel(SECONDARY_STORE);
  1244. SendDlgItemMessage( hwndDlg, IDDI_STORAGELEVEL, CB_SETCURSEL,
  1245. pthis->_propNew.StoreLevel(), 0 );
  1246. EnableWindow( GetDlgItem( hwndDlg, IDDI_STORAGELEVEL), TRUE );
  1247. }
  1248. // if no item is currently selected, set lpwstr by default
  1249. if (VT_EMPTY == pthis->_propNew.GetVT() || 0 == pthis->_propNew.Allocation())
  1250. {
  1251. UINT uiType = DBTypeToVT(pthis->_propNew.GetDefaultType());
  1252. if (uiType != VT_EMPTY)
  1253. {
  1254. ciaDebugOut((DEB_ITRACE, "DIALOG: %ws has type %d (==> %d)\n",
  1255. pthis->_propNew.GetFName(), pthis->_propNew.GetDefaultType(),
  1256. DBTypeToVT(pthis->_propNew.GetDefaultType())));
  1257. pthis->_propNew.SetVT( uiType );
  1258. pthis->_propNew.SetAllocation( pthis->_propNew.GetDefaultSize() );
  1259. }
  1260. else
  1261. {
  1262. // default datatype should be LPWSTR
  1263. pthis->_propNew.SetVT( VT_LPWSTR );
  1264. pthis->_propNew.SetAllocation( 4 );
  1265. }
  1266. }
  1267. // Assert that the property is now marked cached
  1268. Win4Assert( pthis->_propNew.IsCached() );
  1269. // now display it
  1270. SendDlgItemMessage( hwndDlg, IDDI_DATATYPE, CB_SETCURSEL,
  1271. aulTypeIndex[ pthis->_propNew.GetVT() & ~VT_VECTOR ], 0 );
  1272. SetDlgItemText( hwndDlg, IDDI_CACHEDSIZE, pthis->_propNew.GetAllocation() );
  1273. // in case OK was disabled, enable it
  1274. EnableWindow( GetDlgItem( GetParent(hwndDlg), IDOK), TRUE );
  1275. }
  1276. else
  1277. {
  1278. pthis->_propNew.SetVT( VT_EMPTY );
  1279. pthis->_propNew.SetAllocation( 0 );
  1280. // IMPORTANT: Don't set storage level to invalid. We need to
  1281. // know where to delete this from!
  1282. //pthis->_propNew.SetStoreLevel(INVALID_STORE_LEVEL);
  1283. EnableWindow( GetDlgItem( hwndDlg, IDDI_DATATYPE ), FALSE );
  1284. EnableWindow( GetDlgItem( hwndDlg, IDDI_STORAGELEVEL), FALSE );
  1285. EnableWindow( GetDlgItem( hwndDlg, IDDI_CACHEDSIZE ), FALSE );
  1286. EnableWindow( GetDlgItem( hwndDlg, IDDI_SPIN_CACHEDSIZE ), FALSE );
  1287. }
  1288. fChanged = TRUE;
  1289. fRet = TRUE;
  1290. }
  1291. break;
  1292. }
  1293. } // switch
  1294. if ( fChanged )
  1295. {
  1296. CPropertyPropertySheet1 * pthis = (CPropertyPropertySheet1 *)GetWindowLongPtr( hwndDlg, DWLP_USER );
  1297. PropSheet_Changed( GetParent(hwndDlg), hwndDlg );
  1298. }
  1299. break;
  1300. }
  1301. case WM_NOTIFY:
  1302. {
  1303. switch ( ((LPNMHDR) lParam)->code )
  1304. {
  1305. case PSN_APPLY:
  1306. {
  1307. TRY
  1308. {
  1309. CPropertyPropertySheet1 * pthis = (CPropertyPropertySheet1 *)GetWindowLongPtr( hwndDlg, DWLP_USER );
  1310. *pthis->_pProperty = pthis->_propNew;
  1311. pthis->_pProperty->MakeUnappliedChange();
  1312. pthis->_pCat->UpdateCachedProperty(pthis->_pProperty);
  1313. MMCPropertyChangeNotify( pthis->_hMmcNotify, (LONG_PTR)pthis->_pProperty );
  1314. MessageBox( hwndDlg,
  1315. STRINGRESOURCE( srPendingProps ),
  1316. STRINGRESOURCE( srPendingPropsTitle ),
  1317. MB_OK | MB_ICONINFORMATION );
  1318. fRet = TRUE;
  1319. ciaDebugOut((DEB_ITRACE, "VarType is %d, Allocation size is %d, Store level is %d\n",
  1320. pthis->_pProperty->GetVT(), pthis->_pProperty->Allocation(),
  1321. pthis->_pProperty->StoreLevel() ));
  1322. }
  1323. CATCH( CException, e )
  1324. {
  1325. DisplayError( hwndDlg, e );
  1326. }
  1327. END_CATCH
  1328. break;
  1329. }
  1330. } // switch
  1331. break;
  1332. }
  1333. case WM_DESTROY:
  1334. {
  1335. CPropertyPropertySheet1 * pthis = (CPropertyPropertySheet1 *)GetWindowLongPtr( hwndDlg, DWLP_USER );
  1336. MMCFreeNotifyHandle( pthis->_hMmcNotify );
  1337. delete pthis;
  1338. fRet = TRUE;
  1339. break;
  1340. }
  1341. default:
  1342. fRet = FALSE;
  1343. break;
  1344. }
  1345. }
  1346. CATCH( CException, e )
  1347. {
  1348. ciaDebugOut(( DEB_ERROR, "CPropertyPropertySheet1: Caught 0x%x\n", e.GetErrorCode() ));
  1349. fRet = FALSE;
  1350. }
  1351. END_CATCH
  1352. return fRet;
  1353. }
  1354. BOOL CPropertyPropertySheet1::Refresh( HWND hwndDlg, BOOL fVTOnly )
  1355. {
  1356. BOOL fChanged = FALSE;
  1357. DWORD dwIndex = (DWORD)SendDlgItemMessage( hwndDlg, IDDI_DATATYPE, CB_GETCURSEL, 0, 0 );
  1358. ULONG vt = (ULONG)SendDlgItemMessage( hwndDlg, IDDI_DATATYPE, CB_GETITEMDATA, dwIndex, 0 );
  1359. if ( vt != _propNew.GetVT() )
  1360. fChanged = TRUE;
  1361. _propNew.SetVT( vt );
  1362. dwIndex = (DWORD)SendDlgItemMessage( hwndDlg, IDDI_STORAGELEVEL, CB_GETCURSEL, 0, 0 );
  1363. DWORD dwStoreLevel = (DWORD)SendDlgItemMessage( hwndDlg, IDDI_STORAGELEVEL, CB_GETITEMDATA, dwIndex, 0 );
  1364. if ( dwStoreLevel != _propNew.StoreLevel() )
  1365. fChanged = TRUE;
  1366. _propNew.SetStoreLevel( dwStoreLevel );
  1367. if ( !fVTOnly )
  1368. {
  1369. XArray<WCHAR> xawcSize;
  1370. if ( GetDlgItemXArrayText( hwndDlg, IDDI_CACHEDSIZE, xawcSize ) && xawcSize.Count() > 0)
  1371. {
  1372. ULONG cb = wcstoul( xawcSize.Get(), 0, 10 );
  1373. if ( cb != _propNew.Allocation() )
  1374. fChanged = TRUE;
  1375. _propNew.SetAllocation( cb );
  1376. }
  1377. }
  1378. return fChanged;
  1379. }
  1380. void InitVTList( HWND hwndCombo )
  1381. {
  1382. DWORD dwIndex;
  1383. //
  1384. // Add an item for each type group.
  1385. //
  1386. int j = 0;
  1387. for ( int i = 0; i < cType; i++ )
  1388. {
  1389. if ( 0 != awcsType[i] )
  1390. {
  1391. dwIndex = (DWORD)SendMessage( hwndCombo, CB_ADDSTRING, 0, (LPARAM)awcsType[i] );
  1392. SendMessage(hwndCombo, CB_SETITEMDATA, dwIndex, i );
  1393. j++;
  1394. }
  1395. }
  1396. //
  1397. // NOTE: After the first property box, this just sets identical values.
  1398. //
  1399. for ( j--; j >= 0; j-- )
  1400. {
  1401. dwIndex = (DWORD)SendMessage( hwndCombo, CB_GETITEMDATA, j, 0 );
  1402. aulTypeIndex[dwIndex] = j;
  1403. }
  1404. }
  1405. void InitStorageLevelList( HWND hwndCombo )
  1406. {
  1407. DWORD dwIndex;
  1408. //
  1409. // Add an item for each of the two levels.
  1410. //
  1411. dwIndex = (DWORD)SendMessage( hwndCombo, CB_ADDSTRING, 0, (LPARAM)STRINGRESOURCE(srPrimaryStore) );
  1412. SendMessage(hwndCombo, CB_SETITEMDATA, dwIndex, PRIMARY_STORE );
  1413. dwIndex = (DWORD)SendMessage( hwndCombo, CB_ADDSTRING, 0, (LPARAM)STRINGRESOURCE(srSecondaryStore) );
  1414. SendMessage(hwndCombo, CB_SETITEMDATA, dwIndex, SECONDARY_STORE );
  1415. }
  1416. //
  1417. // Helper class for virtual server callback.
  1418. //
  1419. //+---------------------------------------------------------------------------
  1420. //
  1421. // Class: CMetaDataVirtualServerCallBack
  1422. //
  1423. // Purpose: Pure virtual for vroot enumeration
  1424. //
  1425. // History: 07-Feb-1997 dlee Created
  1426. //
  1427. //----------------------------------------------------------------------------
  1428. class CVSComboBox : public CMetaDataVirtualServerCallBack
  1429. {
  1430. public:
  1431. CVSComboBox( HWND hwndCombo ) :
  1432. _hwndCombo( hwndCombo ),
  1433. cEntries( 0 )
  1434. {
  1435. }
  1436. virtual SCODE CallBack( DWORD iInstance, WCHAR const * pwcInstance );
  1437. virtual ~CVSComboBox() {}
  1438. ULONG EntryCount() { return cEntries; }
  1439. private:
  1440. HWND _hwndCombo;
  1441. ULONG cEntries;
  1442. };
  1443. SCODE CVSComboBox::CallBack( DWORD iInstance, WCHAR const * pwcInstance )
  1444. {
  1445. // We pass NULL for _hwndCombo when we only need a count of entries.
  1446. if (NULL != _hwndCombo)
  1447. {
  1448. DWORD dwIndex = (DWORD)SendMessage( _hwndCombo, CB_ADDSTRING, 0, (LPARAM)pwcInstance );
  1449. SendMessage( _hwndCombo, CB_SETITEMDATA, dwIndex, (LPARAM)iInstance );
  1450. }
  1451. cEntries++;
  1452. return S_OK;
  1453. }
  1454. BOOL AreServersAvailable( CCatalog const & cat )
  1455. {
  1456. BOOL fEntriesInList = FALSE;
  1457. //
  1458. // Virtual Server(s)
  1459. //
  1460. TRY
  1461. {
  1462. //
  1463. // Add an item for each type group.
  1464. //
  1465. CMetaDataMgr mgr( TRUE, W3VRoot, 0xffffffff, cat.GetMachine() );
  1466. CVSComboBox vsc( NULL );
  1467. mgr.EnumVServers( vsc );
  1468. fEntriesInList = (0 == vsc.EntryCount()) ? FALSE : TRUE;
  1469. }
  1470. CATCH( CException, e )
  1471. {
  1472. ciaDebugOut(( DEB_ERROR, "Couldn't enumerate virtual servers.\n" ));
  1473. }
  1474. END_CATCH
  1475. //
  1476. // Virtual NNTP Server(s)
  1477. //
  1478. TRY
  1479. {
  1480. //
  1481. // Add an item for each type group.
  1482. //
  1483. CMetaDataMgr mgr( TRUE, NNTPVRoot, 0xffffffff, cat.GetMachine() );
  1484. CVSComboBox vsc( NULL );
  1485. mgr.EnumVServers( vsc );
  1486. fEntriesInList = fEntriesInList || ( (0 == vsc.EntryCount()) ? FALSE : TRUE );
  1487. }
  1488. CATCH( CException, e )
  1489. {
  1490. ciaDebugOut(( DEB_ERROR, "Couldn't enumerate virtual servers.\n" ));
  1491. }
  1492. END_CATCH
  1493. return fEntriesInList;
  1494. }
  1495. void InitVSList( HWND hwndComboVS, HWND hwndComboNNTP, CCatalog const & cat,
  1496. ULONG & cVServers, ULONG & cNNTPServers )
  1497. {
  1498. //
  1499. // Virtual Server(s)
  1500. //
  1501. TRY
  1502. {
  1503. SendMessage( hwndComboVS, CB_ADDSTRING, 0,
  1504. (LPARAM) STRINGRESOURCE( srNoneSelected.wsz ) );
  1505. //
  1506. // Add an item for each type group.
  1507. //
  1508. CMetaDataMgr mgr( TRUE, W3VRoot, 0xffffffff, cat.GetMachine() );
  1509. CVSComboBox vsc( hwndComboVS );
  1510. Win4Assert(0 == vsc.EntryCount());
  1511. mgr.EnumVServers( vsc );
  1512. cVServers = vsc.EntryCount();
  1513. }
  1514. CATCH( CException, e )
  1515. {
  1516. ciaDebugOut(( DEB_ERROR, "Couldn't enumerate virtual servers.\n" ));
  1517. }
  1518. END_CATCH
  1519. //
  1520. // Virtual NNTP Server(s)
  1521. //
  1522. TRY
  1523. {
  1524. SendMessage( hwndComboNNTP, CB_ADDSTRING, 0,
  1525. (LPARAM) STRINGRESOURCE( srNoneSelected.wsz ) );
  1526. //
  1527. // Add an item for each type group.
  1528. //
  1529. CMetaDataMgr mgr( TRUE, NNTPVRoot, 0xffffffff, cat.GetMachine() );
  1530. CVSComboBox vsc( hwndComboNNTP );
  1531. Win4Assert(0 == vsc.EntryCount());
  1532. mgr.EnumVServers( vsc );
  1533. cNNTPServers = vsc.EntryCount();
  1534. }
  1535. CATCH( CException, e )
  1536. {
  1537. ciaDebugOut(( DEB_ERROR, "Couldn't enumerate virtual servers.\n" ));
  1538. }
  1539. END_CATCH
  1540. #if 0
  1541. //
  1542. // Virtual IMAP Server(s)
  1543. //
  1544. TRY
  1545. {
  1546. //
  1547. // Add an item for each type group.
  1548. //
  1549. CMetaDataMgr mgr( TRUE, IMAPVRoot, 0xffffffff, cat.GetMachine() );
  1550. DWORD dwIndex = SendMessage( hwndComboIMAP, CB_ADDSTRING, 0,
  1551. (LPARAM) STRINGRESOURCE( srNoneSelected.wsz ) );
  1552. CVSComboBox vsc( hwndComboIMAP );
  1553. mgr.EnumVServers( vsc );
  1554. }
  1555. CATCH( CException, e )
  1556. {
  1557. ciaDebugOut(( DEB_ERROR, "Couldn't enumerate virtual servers.\n" ));
  1558. }
  1559. END_CATCH
  1560. #endif
  1561. }
  1562. void DisplayError( HWND hwnd, CException & e )
  1563. {
  1564. WCHAR wcsError[MAX_PATH];
  1565. if ( !FormatMessage( FORMAT_MESSAGE_FROM_HMODULE,
  1566. GetModuleHandle(L"query.dll"),
  1567. GetOleError( e ),
  1568. GetSystemDefaultLCID(),
  1569. wcsError,
  1570. sizeof(wcsError) / sizeof(WCHAR),
  1571. 0 ) )
  1572. {
  1573. wsprintf( wcsError,
  1574. STRINGRESOURCE(srGenericError),
  1575. GetOleError( e ) );
  1576. }
  1577. MessageBox( hwnd,
  1578. wcsError,
  1579. STRINGRESOURCE( srIndexServerCmpManage ),
  1580. MB_OK | MB_ICONERROR );
  1581. }
  1582. DWORD VSToIndex( HWND hwndDlg, DWORD dwItem, ULONG ulVS, BOOL fTrack )
  1583. {
  1584. if ( !fTrack )
  1585. return 0;
  1586. unsigned cItem = (unsigned)SendDlgItemMessage( hwndDlg,
  1587. dwItem,
  1588. CB_GETCOUNT, 0, 0 );
  1589. for ( unsigned i = 1; i < cItem; i++ )
  1590. {
  1591. ULONG ulItem = (ULONG)SendDlgItemMessage( hwndDlg,
  1592. dwItem,
  1593. CB_GETITEMDATA, i, 0 );
  1594. if ( ulVS == ulItem )
  1595. break;
  1596. }
  1597. return i;
  1598. } //VSToIndex
  1599. // Return of VT_EMPTY could imply an unknown conversion.
  1600. UINT DBTypeToVT(UINT uidbt)
  1601. {
  1602. if (uidbt <= DBTYPE_GUID)
  1603. return uidbt;
  1604. // Some conversions
  1605. DBTYPE dbtSimpler = uidbt &~ DBTYPE_VECTOR &~ DBTYPE_ARRAY &~ DBTYPE_BYREF;
  1606. switch (dbtSimpler)
  1607. {
  1608. case DBTYPE_WSTR:
  1609. return VT_LPWSTR;
  1610. case DBTYPE_STR:
  1611. return VT_LPSTR;
  1612. case DBTYPE_FILETIME:
  1613. return VT_FILETIME;
  1614. default:
  1615. return VT_EMPTY;
  1616. }
  1617. }