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.

2012 lines
71 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 ( !pthis->IsTrackingCatalog() )
  492. break;
  493. if (fInherit)
  494. {
  495. Win4Assert(pthis->IsTrackingCatalog());
  496. pthis->_pCat->GetParent().GetGeneration( fUnknown, fGenerateCharacterization, ccCharacterization );
  497. }
  498. else
  499. {
  500. pthis->_pCat->GetGeneration( fUnknown, fGenerateCharacterization, ccCharacterization );
  501. // Enable so we can set controls
  502. EnableWindow(GetDlgItem(hwndDlg, IDDI_FILTER_UNKNOWN), TRUE);
  503. EnableWindow(GetDlgItem(hwndDlg, IDDI_CHARACTERIZATION), TRUE);
  504. EnableWindow(GetDlgItem(hwndDlg, IDDI_CHARACTERIZATION_SIZE), TRUE);
  505. EnableWindow(GetDlgItem(hwndDlg, IDDI_SPIN_CHARACTERIZATION), TRUE);
  506. EnableWindow(GetDlgItem(hwndDlg, IDDI_STATIC2), TRUE);
  507. }
  508. SendDlgItemMessage( hwndDlg,
  509. IDDI_FILTER_UNKNOWN,
  510. BM_SETCHECK,
  511. fUnknown ? BST_CHECKED : BST_UNCHECKED,
  512. 0 );
  513. SendDlgItemMessage( hwndDlg,
  514. IDDI_CHARACTERIZATION,
  515. BM_SETCHECK,
  516. fGenerateCharacterization ? BST_CHECKED : BST_UNCHECKED,
  517. 0 );
  518. WCHAR wcsSize[12];
  519. _ultow( ccCharacterization, wcsSize, 10 );
  520. SetDlgItemText( hwndDlg, IDDI_CHARACTERIZATION_SIZE, wcsSize );
  521. // Enable/Disable controls if we need to
  522. EnableWindow(GetDlgItem(hwndDlg, IDDI_FILTER_UNKNOWN), !fInherit);
  523. EnableWindow(GetDlgItem(hwndDlg, IDDI_CHARACTERIZATION), !fInherit);
  524. EnableWindow(GetDlgItem(hwndDlg, IDDI_CHARACTERIZATION_SIZE), !fInherit);
  525. EnableWindow(GetDlgItem(hwndDlg, IDDI_SPIN_CHARACTERIZATION), !fInherit);
  526. EnableWindow(GetDlgItem(hwndDlg, IDDI_STATIC2), !fInherit);
  527. }
  528. }
  529. }
  530. } // switch
  531. if ( fChanged )
  532. PropSheet_Changed( GetParent(hwndDlg), hwndDlg );
  533. break;
  534. } // case
  535. case WM_NOTIFY:
  536. {
  537. switch ( ((LPNMHDR) lParam)->code )
  538. {
  539. case PSN_APPLY:
  540. {
  541. TRY
  542. {
  543. CIndexSrvPropertySheet1 * pthis = (CIndexSrvPropertySheet1 *)GetWindowLongPtr( hwndDlg, DWLP_USER );
  544. BOOL fUnknown = ( BST_CHECKED == SendDlgItemMessage( hwndDlg, IDDI_FILTER_UNKNOWN, BM_GETSTATE, 0, 0 ) );
  545. BOOL fGenerateCharacterization = ( BST_CHECKED == SendDlgItemMessage( hwndDlg, IDDI_CHARACTERIZATION, BM_GETSTATE, 0, 0 ) );
  546. WCHAR wcsSize[12];
  547. GetDlgItemText( hwndDlg, IDDI_CHARACTERIZATION_SIZE, wcsSize, sizeof(wcsSize)/sizeof(WCHAR) );
  548. ULONG ccCharacterization = wcstoul( wcsSize, 0, 10 );
  549. if ( pthis->IsTrackingCatalog() )
  550. {
  551. // If the Inherit Settings button is checked, we should remove the registry entries from the catalog's
  552. // settings so the values will be inherited from the service.
  553. BOOL fInherit = ( BST_CHECKED == SendDlgItemMessage( hwndDlg, IDDI_INHERIT1, BM_GETSTATE, 0, 0 ) );
  554. if (fInherit)
  555. pthis->_pCat->DeleteGroup1Settings();
  556. else
  557. pthis->_pCat->SetGeneration( fUnknown, fGenerateCharacterization, ccCharacterization );
  558. // Set the values and enable or disable the local controls as appropriate
  559. pthis->_pCat->GetGeneration( fUnknown, fGenerateCharacterization, ccCharacterization );
  560. SendDlgItemMessage( hwndDlg,
  561. IDDI_FILTER_UNKNOWN,
  562. BM_SETCHECK,
  563. fUnknown ? BST_CHECKED : BST_UNCHECKED,
  564. 0 );
  565. SendDlgItemMessage( hwndDlg,
  566. IDDI_CHARACTERIZATION,
  567. BM_SETCHECK,
  568. fGenerateCharacterization ? BST_CHECKED : BST_UNCHECKED,
  569. 0 );
  570. WCHAR wcsSize[12];
  571. _ultow( ccCharacterization, wcsSize, 10 );
  572. SetDlgItemText( hwndDlg, IDDI_CHARACTERIZATION_SIZE, wcsSize);
  573. EnableWindow(GetDlgItem(hwndDlg, IDDI_FILTER_UNKNOWN), !fInherit);
  574. EnableWindow(GetDlgItem(hwndDlg, IDDI_CHARACTERIZATION), !fInherit);
  575. EnableWindow(GetDlgItem(hwndDlg, IDDI_CHARACTERIZATION_SIZE), !fInherit);
  576. EnableWindow(GetDlgItem(hwndDlg, IDDI_SPIN_CHARACTERIZATION), !fInherit);
  577. EnableWindow(GetDlgItem(hwndDlg, IDDI_STATIC2), !fInherit);
  578. }
  579. else
  580. pthis->_pCats->SetGeneration( fUnknown, fGenerateCharacterization, ccCharacterization );
  581. MMCPropertyChangeNotify( pthis->_hMmcNotify, 0 );
  582. fRet = TRUE;
  583. }
  584. CATCH( CException, e )
  585. {
  586. DisplayError( hwndDlg, e );
  587. }
  588. END_CATCH
  589. break;
  590. }
  591. } // switch
  592. break;
  593. }
  594. case WM_DESTROY:
  595. {
  596. CIndexSrvPropertySheet1 * pthis = (CIndexSrvPropertySheet1 *)GetWindowLongPtr( hwndDlg, DWLP_USER );
  597. //
  598. // Only gets called on *one* property page!
  599. //
  600. // MMCFreeNotifyHandle( pthis->_hMmcNotify );
  601. delete pthis;
  602. fRet = TRUE;
  603. break;
  604. }
  605. } // switch
  606. }
  607. CATCH( CException, e )
  608. {
  609. ciaDebugOut(( DEB_ERROR, "CIndexSrvPropertySheet1: Caught 0x%x\n", e.GetErrorCode() ));
  610. fRet = FALSE;
  611. }
  612. END_CATCH
  613. return fRet;
  614. }
  615. CCatalogBasicPropertySheet::CCatalogBasicPropertySheet( HINSTANCE hInstance,
  616. LONG_PTR hMmcNotify,
  617. CCatalog const * pCat )
  618. : _pCat( pCat ),
  619. _hMmcNotify( hMmcNotify )
  620. {
  621. _PropSheet.dwSize = sizeof( *this );
  622. _PropSheet.dwFlags = PSP_USETITLE;
  623. _PropSheet.hInstance = hInstance;
  624. _PropSheet.pszTemplate = MAKEINTRESOURCE(IDP_CATALOG_PAGE1);
  625. _PropSheet.pszTitle = MAKEINTRESOURCE(IDP_CATALOG_PAGE1_TITLE);
  626. _PropSheet.pfnDlgProc = CCatalogBasicPropertySheet::DlgProc;
  627. _PropSheet.lParam = (LPARAM)this;
  628. _hPropSheet = CreatePropertySheetPage( &_PropSheet );
  629. }
  630. CCatalogBasicPropertySheet::~CCatalogBasicPropertySheet()
  631. {
  632. }
  633. INT_PTR APIENTRY CCatalogBasicPropertySheet::DlgProc( HWND hwndDlg,
  634. UINT message,
  635. WPARAM wParam,
  636. LPARAM lParam )
  637. {
  638. BOOL fRet = FALSE;
  639. TRY
  640. {
  641. switch ( message )
  642. {
  643. case WM_HELP:
  644. {
  645. HELPINFO *phi = (HELPINFO *) lParam;
  646. ciaDebugOut(( DEB_ITRACE,
  647. "CCatalogBasicPropertySheet::DlgProc -- WM_HELP: wp 0x%x, lp 0x%x\n",
  648. wParam, lParam ));
  649. if ( HELPINFO_WINDOW == phi->iContextType )
  650. {
  651. switch ( phi->iCtrlId )
  652. {
  653. case IDDI_STATIC:
  654. break;
  655. default :
  656. DisplayPopupHelp((HWND)((LPHELPINFO) lParam)->hItemHandle, HELP_WM_HELP);
  657. break;
  658. }
  659. }
  660. break;
  661. }
  662. case WM_CONTEXTMENU:
  663. {
  664. DisplayPopupHelp((HWND)wParam, HELP_CONTEXTMENU);
  665. break;
  666. }
  667. case WM_INITDIALOG:
  668. {
  669. ciaDebugOut(( DEB_ITRACE, "CCatalogBasicPropertySheet::DlgProc -- WM_INITDIALOG\n" ));
  670. LONG_PTR lthis = ((CCatalogBasicPropertySheet *)lParam)->_PropSheet.lParam;
  671. SetWindowLongPtr( hwndDlg, DWLP_USER, lthis );
  672. CCatalog const * pCat = ((CCatalogBasicPropertySheet *)lParam)->_pCat;
  673. SetDlgItemText( hwndDlg, IDDI_CATNAME, pCat->GetCat( TRUE ) );
  674. SetDlgItemText( hwndDlg, IDDI_SIZE, pCat->GetSize( TRUE ) );
  675. SetDlgItemText( hwndDlg, IDDI_PATH, pCat->GetDrive( TRUE ) );
  676. SetDlgItemText( hwndDlg, IDDI_PROPCACHE_SIZE, pCat->GetPropCacheSize( TRUE ) );
  677. fRet = TRUE;
  678. break;
  679. }
  680. case WM_DESTROY:
  681. {
  682. CCatalogBasicPropertySheet * pthis = (CCatalogBasicPropertySheet *)GetWindowLongPtr( hwndDlg, DWLP_USER );
  683. //
  684. // Only gets called on *one* property page!
  685. //
  686. // MMCFreeNotifyHandle( pthis->_hMmcNotify );
  687. delete pthis;
  688. fRet = TRUE;
  689. break;
  690. }
  691. } // switch
  692. }
  693. CATCH( CException, e )
  694. {
  695. ciaDebugOut(( DEB_ERROR, "CCatalogBasicPropertySheet: Caught 0x%x\n", e.GetErrorCode() ));
  696. fRet = FALSE;
  697. }
  698. END_CATCH
  699. return fRet;
  700. }
  701. CIndexSrvPropertySheet2::CIndexSrvPropertySheet2( HINSTANCE hInstance,
  702. LONG_PTR hMmcNotify,
  703. CCatalog * pCat )
  704. : _pCat( pCat ),
  705. _pCats( 0 ),
  706. _hMmcNotify( hMmcNotify ),
  707. _fNNTPServer( FALSE ),
  708. _fWebServer( FALSE )
  709. {
  710. _PropSheet.dwSize = sizeof( *this );
  711. _PropSheet.dwFlags = PSP_USETITLE;
  712. _PropSheet.hInstance = hInstance;
  713. _PropSheet.pszTemplate = MAKEINTRESOURCE(IDP_CATALOG_PAGE2);
  714. _PropSheet.pszTitle = MAKEINTRESOURCE(IDP_CATALOG_PAGE2_TITLE);
  715. _PropSheet.pfnDlgProc = CIndexSrvPropertySheet2::DlgProc;
  716. _PropSheet.lParam = (LPARAM)this;
  717. _hPropSheet = CreatePropertySheetPage( &_PropSheet );
  718. }
  719. CIndexSrvPropertySheet2::CIndexSrvPropertySheet2( HINSTANCE hInstance,
  720. LONG_PTR hMmcNotify,
  721. CCatalogs * pCats )
  722. : _pCat( 0 ),
  723. _pCats( pCats ),
  724. _hMmcNotify( hMmcNotify )
  725. {
  726. _PropSheet.dwSize = sizeof( *this );
  727. _PropSheet.dwFlags = PSP_USETITLE;
  728. _PropSheet.hInstance = hInstance;
  729. _PropSheet.pszTemplate = MAKEINTRESOURCE(IDP_CATALOG_PAGE2);
  730. _PropSheet.pszTitle = MAKEINTRESOURCE(IDP_CATALOG_PAGE2_TITLE);
  731. _PropSheet.pfnDlgProc = CIndexSrvPropertySheet2::DlgProc;
  732. _PropSheet.lParam = (LPARAM)this;
  733. _hPropSheet = CreatePropertySheetPage( &_PropSheet );
  734. }
  735. CIndexSrvPropertySheet2::~CIndexSrvPropertySheet2()
  736. {
  737. }
  738. INT_PTR APIENTRY CIndexSrvPropertySheet2::DlgProc( HWND hwndDlg,
  739. UINT message,
  740. WPARAM wParam,
  741. LPARAM lParam )
  742. {
  743. BOOL fRet = FALSE;
  744. TRY
  745. {
  746. switch ( message )
  747. {
  748. case WM_HELP:
  749. {
  750. HELPINFO *phi = (HELPINFO *) lParam;
  751. ciaDebugOut(( DEB_ITRACE, "CIndexSrvPropertySheet2 WM_HELP contexttype: '%s', ctlid: %d, contextid: %d\n",
  752. phi->iContextType == HELPINFO_MENUITEM ? "menu" : "window",
  753. phi->iCtrlId, phi->dwContextId ));
  754. if ( HELPINFO_WINDOW == phi->iContextType )
  755. {
  756. switch ( phi->iCtrlId )
  757. {
  758. case IDDI_STATIC:
  759. break;
  760. default :
  761. DisplayPopupHelp((HWND)((LPHELPINFO) lParam)->hItemHandle, HELP_WM_HELP);
  762. break;
  763. }
  764. }
  765. break;
  766. }
  767. case WM_CONTEXTMENU:
  768. {
  769. DisplayPopupHelp((HWND)wParam, HELP_CONTEXTMENU);
  770. break;
  771. }
  772. case WM_INITDIALOG:
  773. {
  774. ciaDebugOut(( DEB_ITRACE, "CIndexSrvPropertySheet2::DlgProc -- WM_INITDIALOG\n" ));
  775. LONG_PTR lthis = ((CIndexSrvPropertySheet2 *)lParam)->_PropSheet.lParam;
  776. CIndexSrvPropertySheet2 * pthis = (CIndexSrvPropertySheet2 *)lthis;
  777. SetWindowLongPtr( hwndDlg, DWLP_USER, lthis );
  778. BOOL fAutoAlias;
  779. BOOL fVirtualRoots;
  780. BOOL fNNTPRoots;
  781. ULONG iVirtualServer;
  782. ULONG iNNTPServer;
  783. // It is important to initialize the counters here to guarantee that
  784. // they will remain 0 if we don't get to invoke the enumerators that
  785. // count the number of servers.
  786. ULONG cVServers = 0, cNNTPServers = 0;
  787. ShowWindow(GetDlgItem(hwndDlg, IDDI_VIRTUAL_SERVER), FALSE);
  788. ShowWindow(GetDlgItem(hwndDlg, IDDI_NNTP_SERVER), FALSE);
  789. ShowWindow(GetDlgItem(hwndDlg, IDDI_VSERVER_STATIC), FALSE);
  790. ShowWindow(GetDlgItem(hwndDlg, IDDI_NNTP_STATIC), FALSE);
  791. if ( 0 != pthis->_pCat )
  792. {
  793. if ( AreServersAvailable( *(pthis->_pCat) ) )
  794. {
  795. pthis->_pCat->GetWeb( fVirtualRoots,
  796. fNNTPRoots,
  797. iVirtualServer,
  798. iNNTPServer );
  799. InitVSList( GetDlgItem(hwndDlg, IDDI_VIRTUAL_SERVER),
  800. GetDlgItem(hwndDlg, IDDI_NNTP_SERVER),
  801. *(pthis->_pCat),
  802. cVServers,
  803. cNNTPServers );
  804. }
  805. pthis->_pCat->GetTracking( fAutoAlias );
  806. // Look in the registry for Group2 params. If at least one of them is listed
  807. // we should uncheck the "Inherit" checkbox. Otherwise
  808. // (if none of them is listed), we should check the box.
  809. SendDlgItemMessage( hwndDlg,
  810. IDDI_INHERIT2,
  811. BM_SETCHECK,
  812. pthis->_pCat->DoGroup2SettingsExist() ? BST_UNCHECKED : BST_CHECKED,
  813. 0 );
  814. // If all the settings don't exist, then delete the others in the group.
  815. // We don't want to have part of the group inherited and part local.
  816. if (pthis->_pCat->DoGroup2SettingsExist())
  817. pthis->_pCat->FillGroup2Settings();
  818. }
  819. else
  820. {
  821. // Hide the "Inherit" checkbox because it is not applicable here
  822. ShowWindow(GetDlgItem(hwndDlg, IDDI_INHERIT2), SW_HIDE);
  823. pthis->_pCats->GetTracking( fAutoAlias );
  824. }
  825. if (cVServers)
  826. {
  827. ShowWindow(GetDlgItem(hwndDlg, IDDI_VIRTUAL_SERVER), TRUE);
  828. ShowWindow(GetDlgItem(hwndDlg, IDDI_VSERVER_STATIC), TRUE);
  829. pthis->_fWebServer = TRUE;
  830. SendDlgItemMessage( hwndDlg,
  831. IDDI_VIRTUAL_SERVER,
  832. CB_SETCURSEL,
  833. VSToIndex( hwndDlg, IDDI_VIRTUAL_SERVER,
  834. iVirtualServer, fVirtualRoots ), 0 );
  835. }
  836. if (cNNTPServers)
  837. {
  838. ShowWindow(GetDlgItem(hwndDlg, IDDI_NNTP_SERVER), TRUE);
  839. ShowWindow(GetDlgItem(hwndDlg, IDDI_NNTP_STATIC), TRUE);
  840. pthis->_fNNTPServer = TRUE;
  841. SendDlgItemMessage( hwndDlg,
  842. IDDI_NNTP_SERVER,
  843. CB_SETCURSEL,
  844. VSToIndex( hwndDlg, IDDI_NNTP_SERVER,
  845. iNNTPServer, fNNTPRoots ), 0 );
  846. }
  847. SendDlgItemMessage( hwndDlg,
  848. IDDI_AUTO_ALIAS,
  849. BM_SETCHECK,
  850. fAutoAlias ? BST_CHECKED : BST_UNCHECKED,
  851. 0 );
  852. // If we are inheriting, we should disable the local setting.
  853. if ( 0 != pthis->_pCat && !pthis->_pCat->DoGroup2SettingsExist())
  854. EnableWindow(GetDlgItem(hwndDlg, IDDI_AUTO_ALIAS), FALSE);
  855. fRet = TRUE;
  856. break;
  857. }
  858. case WM_COMMAND:
  859. {
  860. BOOL fChanged = FALSE;
  861. switch ( LOWORD( wParam ) )
  862. {
  863. case IDDI_VIRTUAL_SERVER:
  864. case IDDI_NNTP_SERVER:
  865. {
  866. if ( CBN_SELCHANGE == HIWORD(wParam) )
  867. {
  868. if ( 0 != GetWindowLongPtr( hwndDlg, DWLP_USER ) )
  869. {
  870. fChanged = TRUE;
  871. fRet = TRUE;
  872. }
  873. }
  874. break;
  875. }
  876. case IDDI_AUTO_ALIAS:
  877. {
  878. if ( EN_CHANGE == HIWORD(wParam) || BN_CLICKED == HIWORD(wParam) )
  879. {
  880. if ( 0 != GetWindowLongPtr( hwndDlg, DWLP_USER ) )
  881. {
  882. fChanged = TRUE;
  883. fRet = TRUE;
  884. }
  885. }
  886. break;
  887. }
  888. case IDDI_INHERIT2:
  889. {
  890. if ( EN_CHANGE == HIWORD(wParam) || BN_CLICKED == HIWORD(wParam) )
  891. {
  892. if ( 0 != GetWindowLongPtr( hwndDlg, DWLP_USER ) )
  893. {
  894. fChanged = TRUE;
  895. fRet = TRUE;
  896. BOOL fInherit = ( BST_CHECKED == SendDlgItemMessage( hwndDlg, IDDI_INHERIT2, BM_GETCHECK, 0, 0 ) );
  897. BOOL fAutoAlias = FALSE;
  898. CIndexSrvPropertySheet2 * pthis = (CIndexSrvPropertySheet2 *)GetWindowLongPtr( hwndDlg, DWLP_USER );
  899. if (fInherit)
  900. {
  901. Win4Assert(pthis->IsTrackingCatalog());
  902. pthis->_pCat->GetParent().GetTracking(fAutoAlias);
  903. }
  904. else
  905. {
  906. pthis->_pCat->GetTracking(fAutoAlias);
  907. // Enable so we can set controls
  908. EnableWindow(GetDlgItem(hwndDlg, IDDI_AUTO_ALIAS), TRUE);
  909. }
  910. SendDlgItemMessage( hwndDlg,
  911. IDDI_AUTO_ALIAS,
  912. BM_SETCHECK,
  913. fAutoAlias ? BST_CHECKED : BST_UNCHECKED,
  914. 0 );
  915. // Disable controls if we need to
  916. if (fInherit)
  917. EnableWindow(GetDlgItem(hwndDlg, IDDI_AUTO_ALIAS), FALSE);
  918. }
  919. }
  920. }
  921. } // switch
  922. if ( fChanged )
  923. PropSheet_Changed( GetParent(hwndDlg), hwndDlg );
  924. break;
  925. }
  926. case WM_NOTIFY:
  927. {
  928. switch ( ((LPNMHDR) lParam)->code )
  929. {
  930. case PSN_APPLY:
  931. {
  932. TRY
  933. {
  934. CIndexSrvPropertySheet2 * pthis = (CIndexSrvPropertySheet2 *)GetWindowLongPtr( hwndDlg, DWLP_USER );
  935. BOOL fAutoAlias = ( BST_CHECKED == SendDlgItemMessage( hwndDlg, IDDI_AUTO_ALIAS, BM_GETSTATE, 0, 0 ) );
  936. if ( 0 != pthis->_pCat )
  937. {
  938. BOOL fVirtualRoots = FALSE;
  939. ULONG iVirtualServer = 0;
  940. if ( pthis->_fWebServer )
  941. {
  942. iVirtualServer = (ULONG)SendDlgItemMessage( hwndDlg, IDDI_VIRTUAL_SERVER, CB_GETCURSEL, 0, 0 );
  943. fVirtualRoots = ( 0 != iVirtualServer );
  944. iVirtualServer = (ULONG)SendDlgItemMessage( hwndDlg, IDDI_VIRTUAL_SERVER, CB_GETITEMDATA, iVirtualServer, 0 );
  945. }
  946. BOOL fNNTPRoots = FALSE;
  947. ULONG iNNTPServer = 0;
  948. if ( pthis->_fNNTPServer )
  949. {
  950. iNNTPServer = (ULONG)SendDlgItemMessage( hwndDlg, IDDI_NNTP_SERVER, CB_GETCURSEL, 0, 0 );
  951. fNNTPRoots = ( 0 != iNNTPServer );
  952. iNNTPServer = (ULONG)SendDlgItemMessage( hwndDlg, IDDI_NNTP_SERVER, CB_GETITEMDATA, iNNTPServer, 0 );
  953. }
  954. pthis->_pCat->SetWeb( fVirtualRoots, fNNTPRoots, iVirtualServer, iNNTPServer );
  955. // If the Inherit Settings button is checked, we should remove the registry entries from the catalog's
  956. // settings so the values will be inherited from the service.
  957. BOOL fInherit = ( BST_CHECKED == SendDlgItemMessage( hwndDlg, IDDI_INHERIT2, BM_GETSTATE, 0, 0 ) );
  958. if (fInherit)
  959. pthis->_pCat->DeleteGroup2Settings();
  960. else
  961. pthis->_pCat->SetTracking( fAutoAlias );
  962. // Set the current values and set state of the local controls
  963. BOOL fAutoAlias;
  964. pthis->_pCat->GetTracking( fAutoAlias );
  965. SendDlgItemMessage( hwndDlg,
  966. IDDI_AUTO_ALIAS,
  967. BM_SETCHECK,
  968. fAutoAlias ? BST_CHECKED : BST_UNCHECKED,
  969. 0 );
  970. EnableWindow(GetDlgItem(hwndDlg, IDDI_AUTO_ALIAS), !fInherit);
  971. }
  972. else
  973. pthis->_pCats->SetTracking( fAutoAlias );
  974. MMCPropertyChangeNotify( pthis->_hMmcNotify, 0 );
  975. fRet = TRUE;
  976. }
  977. CATCH( CException, e )
  978. {
  979. DisplayError( hwndDlg, e );
  980. }
  981. END_CATCH
  982. break;
  983. }
  984. } // switch
  985. break;
  986. }
  987. case WM_DESTROY:
  988. {
  989. CIndexSrvPropertySheet2 * pthis = (CIndexSrvPropertySheet2 *)GetWindowLongPtr( hwndDlg, DWLP_USER );
  990. //
  991. // Only gets called on *one* property page!
  992. //
  993. // MMCFreeNotifyHandle( pthis->_hMmcNotify );
  994. delete pthis;
  995. fRet = TRUE;
  996. break;
  997. }
  998. } // switch
  999. }
  1000. CATCH( CException, e )
  1001. {
  1002. ciaDebugOut(( DEB_ERROR, "CIndexSrvPropertySheet2: Caught 0x%x\n", e.GetErrorCode() ));
  1003. fRet = FALSE;
  1004. }
  1005. END_CATCH
  1006. return fRet;
  1007. }
  1008. CPropertyPropertySheet1::CPropertyPropertySheet1( HINSTANCE hInstance,
  1009. LONG_PTR hMmcNotify,
  1010. CCachedProperty * pProperty,
  1011. CCatalog * pCat )
  1012. : _pProperty( pProperty ),
  1013. _propNew( *pProperty ),
  1014. _hMmcNotify( hMmcNotify ),
  1015. _pCat( pCat )
  1016. {
  1017. _PropSheet.dwSize = sizeof( _PropSheet ) + sizeof( this );
  1018. _PropSheet.dwFlags = PSP_USETITLE;
  1019. _PropSheet.hInstance = hInstance;
  1020. _PropSheet.pszTemplate = MAKEINTRESOURCE(IDP_PROPERTY_PAGE1);
  1021. _PropSheet.pszTitle = MAKEINTRESOURCE(IDP_PROPERTY_PAGE1_TITLE);
  1022. _PropSheet.pfnDlgProc = CPropertyPropertySheet1::DlgProc;
  1023. _PropSheet.lParam = (LPARAM)this;
  1024. _hPropSheet = CreatePropertySheetPage( &_PropSheet );
  1025. }
  1026. CPropertyPropertySheet1::~CPropertyPropertySheet1()
  1027. {
  1028. }
  1029. INT_PTR APIENTRY CPropertyPropertySheet1::DlgProc( HWND hwndDlg,
  1030. UINT message,
  1031. WPARAM wParam,
  1032. LPARAM lParam )
  1033. {
  1034. BOOL fRet = FALSE;
  1035. TRY
  1036. {
  1037. switch ( message )
  1038. {
  1039. case WM_HELP:
  1040. {
  1041. HELPINFO *phi = (HELPINFO *) lParam;
  1042. ciaDebugOut(( DEB_ITRACE,
  1043. "CPropertyPropertySheet1 WM_HELP contexttype: '%s', ctlid: %d, contextid: %d\n",
  1044. phi->iContextType == HELPINFO_MENUITEM ? "menu" : "window",
  1045. phi->iCtrlId, phi->dwContextId ));
  1046. if ( HELPINFO_WINDOW == phi->iContextType )
  1047. {
  1048. switch ( phi->iCtrlId )
  1049. {
  1050. case IDDI_STATIC:
  1051. break;
  1052. default :
  1053. DisplayPopupHelp((HWND)((LPHELPINFO) lParam)->hItemHandle, HELP_WM_HELP);
  1054. break;
  1055. }
  1056. }
  1057. break;
  1058. }
  1059. case WM_CONTEXTMENU:
  1060. {
  1061. DisplayPopupHelp((HWND)wParam, HELP_CONTEXTMENU);
  1062. break;
  1063. }
  1064. case WM_INITDIALOG:
  1065. {
  1066. ciaDebugOut(( DEB_ITRACE, "CPropertyPropertySheet1::DlgProc -- WM_INITDIALOG\n" ));
  1067. LONG_PTR lthis = ((CPropertyPropertySheet1 *)lParam)->_PropSheet.lParam;
  1068. SetWindowLongPtr( hwndDlg, DWLP_USER, lthis );
  1069. CCachedProperty const & prop = ((CPropertyPropertySheet1 *)lthis)->_propNew;
  1070. SetDlgItemText( hwndDlg, IDDI_PROPSET, prop.GetPropSet() );
  1071. SetDlgItemText( hwndDlg, IDDI_PROPERTY, prop.GetProperty() );
  1072. SendDlgItemMessage( hwndDlg,
  1073. IDDI_SPIN_CACHEDSIZE,
  1074. UDM_SETRANGE,
  1075. 0,
  1076. (LPARAM) MAKELONG( 500, 4) );
  1077. InitVTList( GetDlgItem(hwndDlg, IDDI_DATATYPE) );
  1078. InitStorageLevelList( GetDlgItem(hwndDlg, IDDI_STORAGELEVEL) );
  1079. if ( prop.IsCached() )
  1080. {
  1081. SendDlgItemMessage( hwndDlg, IDDI_CACHED, BM_SETCHECK, BST_CHECKED, 0 );
  1082. SendDlgItemMessage( hwndDlg, IDDI_DATATYPE, CB_SETCURSEL, aulTypeIndex[ prop.GetVT() & ~VT_VECTOR ], 0 );
  1083. // StoreLevel() is 0 for primary, 1 for secondary, which is the sequence in which we added them.
  1084. // So using StoreLevel() as in index will work fine!
  1085. SendDlgItemMessage( hwndDlg, IDDI_STORAGELEVEL, CB_SETCURSEL, prop.StoreLevel(), 0 );
  1086. SetDlgItemText( hwndDlg, IDDI_CACHEDSIZE, prop.GetAllocation() );
  1087. // Currently we do not allow the storage level to be changed after initial setting
  1088. EnableWindow( GetDlgItem( hwndDlg, IDDI_STORAGELEVEL), FALSE );
  1089. }
  1090. else
  1091. {
  1092. SendDlgItemMessage( hwndDlg, IDDI_CACHED, BM_SETCHECK, BST_UNCHECKED, 0 );
  1093. EnableWindow( GetDlgItem( hwndDlg, IDDI_DATATYPE ), FALSE );
  1094. EnableWindow( GetDlgItem( hwndDlg, IDDI_STORAGELEVEL), FALSE );
  1095. EnableWindow( GetDlgItem( hwndDlg, IDDI_CACHEDSIZE ), FALSE );
  1096. EnableWindow( GetDlgItem( hwndDlg, IDDI_SPIN_CACHEDSIZE ), FALSE );
  1097. EnableWindow( GetDlgItem( GetParent(hwndDlg), IDOK), FALSE );
  1098. }
  1099. // If properties cannot be modified, disable all controls
  1100. // Only cached properties can be resitant to modifications!
  1101. if (!prop.IsModifiable() && prop.IsCached())
  1102. {
  1103. EnableWindow( GetDlgItem( hwndDlg, IDDI_CACHED), FALSE );
  1104. EnableWindow( GetDlgItem( hwndDlg, IDDI_DATATYPE ), FALSE );
  1105. EnableWindow( GetDlgItem( hwndDlg, IDDI_STORAGELEVEL), FALSE );
  1106. EnableWindow( GetDlgItem( hwndDlg, IDDI_CACHEDSIZE ), FALSE );
  1107. EnableWindow( GetDlgItem( hwndDlg, IDDI_SPIN_CACHEDSIZE ), FALSE );
  1108. EnableWindow( GetDlgItem( GetParent(hwndDlg), IDOK), FALSE );
  1109. }
  1110. fRet = TRUE;
  1111. break;
  1112. }
  1113. case WM_COMMAND:
  1114. {
  1115. BOOL fChanged = FALSE;
  1116. BOOL fCorrected = TRUE;
  1117. switch ( LOWORD( wParam ) )
  1118. {
  1119. case IDDI_DATATYPE:
  1120. {
  1121. if ( CBN_CLOSEUP == HIWORD(wParam) )
  1122. {
  1123. CPropertyPropertySheet1 * pthis = (CPropertyPropertySheet1 *)GetWindowLongPtr( hwndDlg, DWLP_USER );
  1124. fChanged = pthis->Refresh( hwndDlg, TRUE );
  1125. if ( pthis->_propNew.IsFixed() )
  1126. {
  1127. SetDlgItemText( hwndDlg, IDDI_CACHEDSIZE, pthis->_propNew.GetAllocation() );
  1128. // Disable the size control
  1129. EnableWindow( GetDlgItem( hwndDlg, IDDI_CACHEDSIZE ), FALSE );
  1130. EnableWindow( GetDlgItem( hwndDlg, IDDI_SPIN_CACHEDSIZE ), FALSE );
  1131. }
  1132. else
  1133. {
  1134. SetDlgItemText( hwndDlg, IDDI_CACHEDSIZE, L"4" );
  1135. // Enable the size control. Variable props can be resized.
  1136. EnableWindow( GetDlgItem( hwndDlg, IDDI_CACHEDSIZE ), TRUE );
  1137. EnableWindow( GetDlgItem( hwndDlg, IDDI_SPIN_CACHEDSIZE ), TRUE );
  1138. }
  1139. fRet = TRUE;
  1140. }
  1141. break;
  1142. }
  1143. case IDDI_STORAGELEVEL:
  1144. {
  1145. CPropertyPropertySheet1 * pthis = (CPropertyPropertySheet1 *)GetWindowLongPtr( hwndDlg, DWLP_USER );
  1146. if ( CBN_CLOSEUP == HIWORD(wParam) )
  1147. {
  1148. fChanged = pthis->Refresh( hwndDlg, TRUE );
  1149. fRet = TRUE;
  1150. }
  1151. break;
  1152. }
  1153. case IDDI_CACHEDSIZE:
  1154. {
  1155. if ( EN_KILLFOCUS == HIWORD(wParam) )
  1156. {
  1157. fRet = TRUE;
  1158. ULONG ulVal = 4;
  1159. // Validate the number
  1160. XArray<WCHAR> xawcTemp;
  1161. if ( GetDlgItemXArrayText( hwndDlg, IDDI_CACHEDSIZE, xawcTemp ) &&
  1162. xawcTemp.Count() > 0 )
  1163. {
  1164. // verify that all characters are digits
  1165. ULONG ulLen = wcslen(xawcTemp.GetPointer());
  1166. // When correcting, let's do our best.
  1167. ulVal = _wtoi(xawcTemp.GetPointer());
  1168. for (ULONG i = 0; i < ulLen; i++)
  1169. {
  1170. if (!iswdigit(xawcTemp[i]))
  1171. break;
  1172. }
  1173. if (i == ulLen)
  1174. {
  1175. // verify that the number is within range
  1176. ulVal = _wtoi(xawcTemp.GetPointer());
  1177. ciaDebugOut((DEB_ERROR, "number is %d, string is %ws\n",
  1178. ulVal, xawcTemp.GetPointer()));
  1179. if (ulVal <= 500)
  1180. fCorrected = FALSE;
  1181. else if (ulVal > 500)
  1182. ulVal = 500;
  1183. }
  1184. }
  1185. // if we are dealing with a vble property, we should ensure that the
  1186. // size is at least 4 bytes
  1187. if (ulVal < 4)
  1188. {
  1189. CPropertyPropertySheet1 * pthis = (CPropertyPropertySheet1 *)GetWindowLongPtr( hwndDlg, DWLP_USER );
  1190. if ( 0 != pthis )
  1191. {
  1192. if (pthis->_propNew.IsCached() && !pthis->_propNew.IsFixed())
  1193. {
  1194. ulVal = 4;
  1195. fCorrected = TRUE;
  1196. }
  1197. }
  1198. }
  1199. if (fCorrected)
  1200. {
  1201. MessageBeep(MB_ICONHAND);
  1202. // xawcTemp may not have a buffer, so don't use it for _itow. Use a temp vble
  1203. WCHAR wszBuff[20];
  1204. SetWindowText((HWND)lParam, _itow(ulVal, wszBuff, 10));
  1205. SendMessage((HWND)lParam, EM_SETSEL, 0, -1);
  1206. }
  1207. }
  1208. else if ( EN_CHANGE == HIWORD(wParam) && ( 0 != GetWindowLongPtr( hwndDlg, DWLP_USER )) )
  1209. {
  1210. CPropertyPropertySheet1 * pthis = (CPropertyPropertySheet1 *)GetWindowLongPtr( hwndDlg, DWLP_USER );
  1211. if ( 0 != pthis )
  1212. {
  1213. fChanged = pthis->Refresh( hwndDlg, FALSE );
  1214. fRet = TRUE;
  1215. }
  1216. }
  1217. break;
  1218. }
  1219. case IDDI_CACHED:
  1220. {
  1221. if ( BN_CLICKED == HIWORD(wParam) )
  1222. {
  1223. CPropertyPropertySheet1 * pthis = (CPropertyPropertySheet1 *)GetWindowLongPtr( hwndDlg, DWLP_USER );
  1224. ULONG fChecked = (ULONG)SendDlgItemMessage( hwndDlg, IDDI_CACHED, BM_GETSTATE, 0, 0 );
  1225. if ( fChecked & BST_CHECKED )
  1226. {
  1227. pthis->Refresh( hwndDlg, FALSE );
  1228. EnableWindow( GetDlgItem( hwndDlg, IDDI_DATATYPE ), TRUE );
  1229. EnableWindow( GetDlgItem( hwndDlg, IDDI_CACHEDSIZE ), TRUE );
  1230. EnableWindow( GetDlgItem( hwndDlg, IDDI_SPIN_CACHEDSIZE ), TRUE );
  1231. // If this property is currently being cached in the property store (as indicated
  1232. // by CCachedProperty), we do not let it's store level be changed. This ensures
  1233. // that a user cannot change a property between store levels.
  1234. if (pthis->_propNew.IsCached() && INVALID_STORE_LEVEL != pthis->_propNew.StoreLevel())
  1235. {
  1236. SendDlgItemMessage( hwndDlg, IDDI_STORAGELEVEL, CB_SETCURSEL,
  1237. pthis->_propNew.StoreLevel(), 0 );
  1238. EnableWindow( GetDlgItem( hwndDlg, IDDI_STORAGELEVEL), FALSE );
  1239. }
  1240. else
  1241. {
  1242. // enable and display the storage level. Default to secondary,
  1243. // if none is available
  1244. if (PRIMARY_STORE != pthis->_propNew.StoreLevel())
  1245. pthis->_propNew.SetStoreLevel(SECONDARY_STORE);
  1246. SendDlgItemMessage( hwndDlg, IDDI_STORAGELEVEL, CB_SETCURSEL,
  1247. pthis->_propNew.StoreLevel(), 0 );
  1248. EnableWindow( GetDlgItem( hwndDlg, IDDI_STORAGELEVEL), TRUE );
  1249. }
  1250. // if no item is currently selected, set lpwstr by default
  1251. if (VT_EMPTY == pthis->_propNew.GetVT() || 0 == pthis->_propNew.Allocation())
  1252. {
  1253. UINT uiType = DBTypeToVT(pthis->_propNew.GetDefaultType());
  1254. if (uiType != VT_EMPTY)
  1255. {
  1256. ciaDebugOut((DEB_ITRACE, "DIALOG: %ws has type %d (==> %d)\n",
  1257. pthis->_propNew.GetFName(), pthis->_propNew.GetDefaultType(),
  1258. DBTypeToVT(pthis->_propNew.GetDefaultType())));
  1259. pthis->_propNew.SetVT( uiType );
  1260. pthis->_propNew.SetAllocation( pthis->_propNew.GetDefaultSize() );
  1261. }
  1262. else
  1263. {
  1264. // default datatype should be LPWSTR
  1265. pthis->_propNew.SetVT( VT_LPWSTR );
  1266. pthis->_propNew.SetAllocation( 4 );
  1267. }
  1268. }
  1269. // Assert that the property is now marked cached
  1270. Win4Assert( pthis->_propNew.IsCached() );
  1271. // now display it
  1272. SendDlgItemMessage( hwndDlg, IDDI_DATATYPE, CB_SETCURSEL,
  1273. aulTypeIndex[ pthis->_propNew.GetVT() & ~VT_VECTOR ], 0 );
  1274. SetDlgItemText( hwndDlg, IDDI_CACHEDSIZE, pthis->_propNew.GetAllocation() );
  1275. // in case OK was disabled, enable it
  1276. EnableWindow( GetDlgItem( GetParent(hwndDlg), IDOK), TRUE );
  1277. }
  1278. else
  1279. {
  1280. pthis->_propNew.SetVT( VT_EMPTY );
  1281. pthis->_propNew.SetAllocation( 0 );
  1282. // IMPORTANT: Don't set storage level to invalid. We need to
  1283. // know where to delete this from!
  1284. //pthis->_propNew.SetStoreLevel(INVALID_STORE_LEVEL);
  1285. EnableWindow( GetDlgItem( hwndDlg, IDDI_DATATYPE ), FALSE );
  1286. EnableWindow( GetDlgItem( hwndDlg, IDDI_STORAGELEVEL), FALSE );
  1287. EnableWindow( GetDlgItem( hwndDlg, IDDI_CACHEDSIZE ), FALSE );
  1288. EnableWindow( GetDlgItem( hwndDlg, IDDI_SPIN_CACHEDSIZE ), FALSE );
  1289. }
  1290. fChanged = TRUE;
  1291. fRet = TRUE;
  1292. }
  1293. break;
  1294. }
  1295. } // switch
  1296. if ( fChanged )
  1297. {
  1298. CPropertyPropertySheet1 * pthis = (CPropertyPropertySheet1 *)GetWindowLongPtr( hwndDlg, DWLP_USER );
  1299. PropSheet_Changed( GetParent(hwndDlg), hwndDlg );
  1300. }
  1301. break;
  1302. }
  1303. case WM_NOTIFY:
  1304. {
  1305. switch ( ((LPNMHDR) lParam)->code )
  1306. {
  1307. case PSN_APPLY:
  1308. {
  1309. TRY
  1310. {
  1311. CPropertyPropertySheet1 * pthis = (CPropertyPropertySheet1 *)GetWindowLongPtr( hwndDlg, DWLP_USER );
  1312. *pthis->_pProperty = pthis->_propNew;
  1313. pthis->_pProperty->MakeUnappliedChange();
  1314. pthis->_pCat->UpdateCachedProperty(pthis->_pProperty);
  1315. MMCPropertyChangeNotify( pthis->_hMmcNotify, (LONG_PTR)pthis->_pProperty );
  1316. MessageBox( hwndDlg,
  1317. STRINGRESOURCE( srPendingProps ),
  1318. STRINGRESOURCE( srPendingPropsTitle ),
  1319. MB_OK | MB_ICONINFORMATION );
  1320. fRet = TRUE;
  1321. ciaDebugOut((DEB_ITRACE, "VarType is %d, Allocation size is %d, Store level is %d\n",
  1322. pthis->_pProperty->GetVT(), pthis->_pProperty->Allocation(),
  1323. pthis->_pProperty->StoreLevel() ));
  1324. }
  1325. CATCH( CException, e )
  1326. {
  1327. DisplayError( hwndDlg, e );
  1328. }
  1329. END_CATCH
  1330. break;
  1331. }
  1332. } // switch
  1333. break;
  1334. }
  1335. case WM_DESTROY:
  1336. {
  1337. CPropertyPropertySheet1 * pthis = (CPropertyPropertySheet1 *)GetWindowLongPtr( hwndDlg, DWLP_USER );
  1338. // Freeing this will cause a double-delete since it's shared across instances of this page
  1339. #if 0
  1340. DbgPrint( "WM_DESTROY CPropertyPropertySheet1 this %#x, _hMmcNotify: %#x\n", pthis, pthis->_hMmcNotify );
  1341. MMCFreeNotifyHandle( pthis->_hMmcNotify );
  1342. pthis->_hMmcNotify = 0;
  1343. #endif
  1344. delete pthis;
  1345. fRet = TRUE;
  1346. break;
  1347. }
  1348. default:
  1349. fRet = FALSE;
  1350. break;
  1351. }
  1352. }
  1353. CATCH( CException, e )
  1354. {
  1355. ciaDebugOut(( DEB_ERROR, "CPropertyPropertySheet1: Caught 0x%x\n", e.GetErrorCode() ));
  1356. fRet = FALSE;
  1357. }
  1358. END_CATCH
  1359. return fRet;
  1360. }
  1361. BOOL CPropertyPropertySheet1::Refresh( HWND hwndDlg, BOOL fVTOnly )
  1362. {
  1363. BOOL fChanged = FALSE;
  1364. DWORD dwIndex = (DWORD)SendDlgItemMessage( hwndDlg, IDDI_DATATYPE, CB_GETCURSEL, 0, 0 );
  1365. ULONG vt = (ULONG)SendDlgItemMessage( hwndDlg, IDDI_DATATYPE, CB_GETITEMDATA, dwIndex, 0 );
  1366. if ( vt != _propNew.GetVT() )
  1367. fChanged = TRUE;
  1368. _propNew.SetVT( vt );
  1369. dwIndex = (DWORD)SendDlgItemMessage( hwndDlg, IDDI_STORAGELEVEL, CB_GETCURSEL, 0, 0 );
  1370. DWORD dwStoreLevel = (DWORD)SendDlgItemMessage( hwndDlg, IDDI_STORAGELEVEL, CB_GETITEMDATA, dwIndex, 0 );
  1371. if ( dwStoreLevel != _propNew.StoreLevel() )
  1372. fChanged = TRUE;
  1373. _propNew.SetStoreLevel( dwStoreLevel );
  1374. if ( !fVTOnly )
  1375. {
  1376. XArray<WCHAR> xawcSize;
  1377. if ( GetDlgItemXArrayText( hwndDlg, IDDI_CACHEDSIZE, xawcSize ) && xawcSize.Count() > 0)
  1378. {
  1379. ULONG cb = wcstoul( xawcSize.Get(), 0, 10 );
  1380. if ( cb != _propNew.Allocation() )
  1381. fChanged = TRUE;
  1382. _propNew.SetAllocation( cb );
  1383. }
  1384. }
  1385. return fChanged;
  1386. }
  1387. void InitVTList( HWND hwndCombo )
  1388. {
  1389. DWORD dwIndex;
  1390. //
  1391. // Add an item for each type group.
  1392. //
  1393. int j = 0;
  1394. for ( int i = 0; i < cType; i++ )
  1395. {
  1396. if ( 0 != awcsType[i] )
  1397. {
  1398. dwIndex = (DWORD)SendMessage( hwndCombo, CB_ADDSTRING, 0, (LPARAM)awcsType[i] );
  1399. SendMessage(hwndCombo, CB_SETITEMDATA, dwIndex, i );
  1400. j++;
  1401. }
  1402. }
  1403. //
  1404. // NOTE: After the first property box, this just sets identical values.
  1405. //
  1406. for ( j--; j >= 0; j-- )
  1407. {
  1408. dwIndex = (DWORD)SendMessage( hwndCombo, CB_GETITEMDATA, j, 0 );
  1409. aulTypeIndex[dwIndex] = j;
  1410. }
  1411. }
  1412. void InitStorageLevelList( HWND hwndCombo )
  1413. {
  1414. DWORD dwIndex;
  1415. //
  1416. // Add an item for each of the two levels.
  1417. //
  1418. dwIndex = (DWORD)SendMessage( hwndCombo, CB_ADDSTRING, 0, (LPARAM)STRINGRESOURCE(srPrimaryStore) );
  1419. SendMessage(hwndCombo, CB_SETITEMDATA, dwIndex, PRIMARY_STORE );
  1420. dwIndex = (DWORD)SendMessage( hwndCombo, CB_ADDSTRING, 0, (LPARAM)STRINGRESOURCE(srSecondaryStore) );
  1421. SendMessage(hwndCombo, CB_SETITEMDATA, dwIndex, SECONDARY_STORE );
  1422. }
  1423. //
  1424. // Helper class for virtual server callback.
  1425. //
  1426. //+---------------------------------------------------------------------------
  1427. //
  1428. // Class: CMetaDataVirtualServerCallBack
  1429. //
  1430. // Purpose: Pure virtual for vroot enumeration
  1431. //
  1432. // History: 07-Feb-1997 dlee Created
  1433. //
  1434. //----------------------------------------------------------------------------
  1435. class CVSComboBox : public CMetaDataVirtualServerCallBack
  1436. {
  1437. public:
  1438. CVSComboBox( HWND hwndCombo ) :
  1439. _hwndCombo( hwndCombo ),
  1440. cEntries( 0 )
  1441. {
  1442. }
  1443. virtual SCODE CallBack( DWORD iInstance, WCHAR const * pwcInstance );
  1444. virtual ~CVSComboBox() {}
  1445. ULONG EntryCount() { return cEntries; }
  1446. private:
  1447. HWND _hwndCombo;
  1448. ULONG cEntries;
  1449. };
  1450. SCODE CVSComboBox::CallBack( DWORD iInstance, WCHAR const * pwcInstance )
  1451. {
  1452. // We pass NULL for _hwndCombo when we only need a count of entries.
  1453. if (NULL != _hwndCombo)
  1454. {
  1455. DWORD dwIndex = (DWORD)SendMessage( _hwndCombo, CB_ADDSTRING, 0, (LPARAM)pwcInstance );
  1456. SendMessage( _hwndCombo, CB_SETITEMDATA, dwIndex, (LPARAM)iInstance );
  1457. }
  1458. cEntries++;
  1459. return S_OK;
  1460. }
  1461. BOOL AreServersAvailable( CCatalog const & cat )
  1462. {
  1463. BOOL fEntriesInList = FALSE;
  1464. //
  1465. // Virtual Server(s)
  1466. //
  1467. TRY
  1468. {
  1469. //
  1470. // Add an item for each type group.
  1471. //
  1472. CMetaDataMgr mgr( TRUE, W3VRoot, 0xffffffff, cat.GetMachine() );
  1473. CVSComboBox vsc( NULL );
  1474. mgr.EnumVServers( vsc );
  1475. fEntriesInList = (0 == vsc.EntryCount()) ? FALSE : TRUE;
  1476. }
  1477. CATCH( CException, e )
  1478. {
  1479. ciaDebugOut(( DEB_ERROR, "Couldn't enumerate virtual servers.\n" ));
  1480. }
  1481. END_CATCH
  1482. //
  1483. // Virtual NNTP Server(s)
  1484. //
  1485. TRY
  1486. {
  1487. //
  1488. // Add an item for each type group.
  1489. //
  1490. CMetaDataMgr mgr( TRUE, NNTPVRoot, 0xffffffff, cat.GetMachine() );
  1491. CVSComboBox vsc( NULL );
  1492. mgr.EnumVServers( vsc );
  1493. fEntriesInList = fEntriesInList || ( (0 == vsc.EntryCount()) ? FALSE : TRUE );
  1494. }
  1495. CATCH( CException, e )
  1496. {
  1497. ciaDebugOut(( DEB_ERROR, "Couldn't enumerate virtual servers.\n" ));
  1498. }
  1499. END_CATCH
  1500. return fEntriesInList;
  1501. }
  1502. void InitVSList( HWND hwndComboVS, HWND hwndComboNNTP, CCatalog const & cat,
  1503. ULONG & cVServers, ULONG & cNNTPServers )
  1504. {
  1505. //
  1506. // Virtual Server(s)
  1507. //
  1508. TRY
  1509. {
  1510. SendMessage( hwndComboVS, CB_ADDSTRING, 0,
  1511. (LPARAM) STRINGRESOURCE( srNoneSelected.wsz ) );
  1512. //
  1513. // Add an item for each type group.
  1514. //
  1515. CMetaDataMgr mgr( TRUE, W3VRoot, 0xffffffff, cat.GetMachine() );
  1516. CVSComboBox vsc( hwndComboVS );
  1517. Win4Assert(0 == vsc.EntryCount());
  1518. mgr.EnumVServers( vsc );
  1519. cVServers = vsc.EntryCount();
  1520. }
  1521. CATCH( CException, e )
  1522. {
  1523. ciaDebugOut(( DEB_ERROR, "Couldn't enumerate virtual servers.\n" ));
  1524. }
  1525. END_CATCH
  1526. //
  1527. // Virtual NNTP Server(s)
  1528. //
  1529. TRY
  1530. {
  1531. SendMessage( hwndComboNNTP, CB_ADDSTRING, 0,
  1532. (LPARAM) STRINGRESOURCE( srNoneSelected.wsz ) );
  1533. //
  1534. // Add an item for each type group.
  1535. //
  1536. CMetaDataMgr mgr( TRUE, NNTPVRoot, 0xffffffff, cat.GetMachine() );
  1537. CVSComboBox vsc( hwndComboNNTP );
  1538. Win4Assert(0 == vsc.EntryCount());
  1539. mgr.EnumVServers( vsc );
  1540. cNNTPServers = vsc.EntryCount();
  1541. }
  1542. CATCH( CException, e )
  1543. {
  1544. ciaDebugOut(( DEB_ERROR, "Couldn't enumerate virtual servers.\n" ));
  1545. }
  1546. END_CATCH
  1547. #if 0
  1548. //
  1549. // Virtual IMAP Server(s)
  1550. //
  1551. TRY
  1552. {
  1553. //
  1554. // Add an item for each type group.
  1555. //
  1556. CMetaDataMgr mgr( TRUE, IMAPVRoot, 0xffffffff, cat.GetMachine() );
  1557. DWORD dwIndex = SendMessage( hwndComboIMAP, CB_ADDSTRING, 0,
  1558. (LPARAM) STRINGRESOURCE( srNoneSelected.wsz ) );
  1559. CVSComboBox vsc( hwndComboIMAP );
  1560. mgr.EnumVServers( vsc );
  1561. }
  1562. CATCH( CException, e )
  1563. {
  1564. ciaDebugOut(( DEB_ERROR, "Couldn't enumerate virtual servers.\n" ));
  1565. }
  1566. END_CATCH
  1567. #endif
  1568. }
  1569. void DisplayError( HWND hwnd, CException & e )
  1570. {
  1571. WCHAR wcsError[MAX_PATH];
  1572. if ( !FormatMessage( FORMAT_MESSAGE_FROM_HMODULE,
  1573. GetModuleHandle(L"query.dll"),
  1574. GetOleError( e ),
  1575. GetSystemDefaultLCID(),
  1576. wcsError,
  1577. sizeof(wcsError) / sizeof(WCHAR),
  1578. 0 ) )
  1579. {
  1580. wsprintf( wcsError,
  1581. STRINGRESOURCE(srGenericError),
  1582. GetOleError( e ) );
  1583. }
  1584. MessageBox( hwnd,
  1585. wcsError,
  1586. STRINGRESOURCE( srIndexServerCmpManage ),
  1587. MB_OK | MB_ICONERROR );
  1588. }
  1589. DWORD VSToIndex( HWND hwndDlg, DWORD dwItem, ULONG ulVS, BOOL fTrack )
  1590. {
  1591. if ( !fTrack )
  1592. return 0;
  1593. unsigned cItem = (unsigned)SendDlgItemMessage( hwndDlg,
  1594. dwItem,
  1595. CB_GETCOUNT, 0, 0 );
  1596. for ( unsigned i = 1; i < cItem; i++ )
  1597. {
  1598. ULONG ulItem = (ULONG)SendDlgItemMessage( hwndDlg,
  1599. dwItem,
  1600. CB_GETITEMDATA, i, 0 );
  1601. if ( ulVS == ulItem )
  1602. break;
  1603. }
  1604. return i;
  1605. } //VSToIndex
  1606. // Return of VT_EMPTY could imply an unknown conversion.
  1607. UINT DBTypeToVT(UINT uidbt)
  1608. {
  1609. if (uidbt <= DBTYPE_GUID)
  1610. return uidbt;
  1611. // Some conversions
  1612. DBTYPE dbtSimpler = uidbt &~ DBTYPE_VECTOR &~ DBTYPE_ARRAY &~ DBTYPE_BYREF;
  1613. switch (dbtSimpler)
  1614. {
  1615. case DBTYPE_WSTR:
  1616. return VT_LPWSTR;
  1617. case DBTYPE_STR:
  1618. return VT_LPSTR;
  1619. case DBTYPE_FILETIME:
  1620. return VT_FILETIME;
  1621. default:
  1622. return VT_EMPTY;
  1623. }
  1624. }