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.

2881 lines
86 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1996 - 2000.
  5. //
  6. // File: srchwnd.cxx
  7. //
  8. // Contents:
  9. //
  10. // History: 15 Aug 1996 DLee Created
  11. //
  12. //--------------------------------------------------------------------------
  13. #include "pch.cxx"
  14. #pragma hdrstop
  15. #include <ntquery.h>
  16. //
  17. // Main Search Window procedure
  18. //
  19. LRESULT WINAPI SearchWndProc(
  20. HWND hwnd,
  21. UINT msg,
  22. WPARAM wParam,
  23. LPARAM lParam )
  24. {
  25. LRESULT lRet = 0;
  26. // Find search control corresponding to this window
  27. CSearchControl *pControl = (CSearchControl *) GetWindowLongPtr( hwnd, 0 );
  28. switch (msg)
  29. {
  30. //
  31. // Message sent to us by ListView
  32. //
  33. case wmListNotify:
  34. lRet = pControl->wmListNotify (hwnd, wParam, lParam);
  35. break;
  36. case wmDrawItem :
  37. lRet = pControl->wmDrawItem(wParam,lParam);
  38. break;
  39. case wmMeasureItem:
  40. pControl->wmMeasureItem(wParam,lParam);
  41. break;
  42. // OLE DB notification
  43. case wmNotification:
  44. pControl->wmNotification(wParam,lParam);
  45. break;
  46. //------------------------------------
  47. case wmAccelerator :
  48. pControl->wmAccelerator(wParam,lParam);
  49. break;
  50. case WM_MDIACTIVATE :
  51. lRet = pControl->wmActivate( hwnd, wParam, lParam );
  52. break;
  53. case WM_DRAWITEM :
  54. lRet = pControl->wmRealDrawItem( hwnd, wParam, lParam );
  55. break;
  56. case WM_SIZE :
  57. lRet = pControl->wmSize(wParam,lParam);
  58. break;
  59. case wmDisplaySubwindows :
  60. pControl->wmDisplaySubwindows(wParam,lParam);
  61. break;
  62. case WM_CREATE :
  63. {
  64. CREATESTRUCT *pcs = (CREATESTRUCT *) lParam;
  65. MDICREATESTRUCT *pmcs = (MDICREATESTRUCT *) pcs->lpCreateParams;
  66. pControl = new CSearchControl(hwnd, (WCHAR *) pmcs->lParam);
  67. PostMessage( hwnd, wmDisplaySubwindows, 0, 0 );
  68. break;
  69. }
  70. case WM_CTLCOLORSTATIC :
  71. SetTextColor((HDC) wParam, GetSysColor( COLOR_BTNTEXT ) );
  72. // fall through
  73. case WM_CTLCOLORBTN :
  74. SetBkColor((HDC) wParam, GetSysColor( COLOR_BTNFACE ) );
  75. lRet = (LRESULT) (LPVOID) App.BtnFaceBrush();
  76. break;
  77. case wmNewFont :
  78. pControl->wmNewFont(wParam,lParam);
  79. break;
  80. case wmAppClosing :
  81. pControl->wmAppClosing(wParam,lParam);
  82. break;
  83. case WM_CLOSE :
  84. pControl->wmClose(wParam,lParam);
  85. lRet = DefMDIChildProc(hwnd,msg,wParam,lParam);
  86. break;
  87. case WM_DESTROY :
  88. delete pControl;
  89. break;
  90. case wmMenuCommand :
  91. pControl->wmMenuCommand(wParam,lParam);
  92. break;
  93. case WM_SETFOCUS :
  94. case wmGiveFocus :
  95. pControl->wmSetFocus(wParam,lParam);
  96. break;
  97. case WM_COMMAND :
  98. pControl->wmCommand(wParam,lParam);
  99. break;
  100. case wmInitMenu :
  101. pControl->wmInitMenu(wParam,lParam);
  102. break;
  103. case WM_SYSCOLORCHANGE :
  104. pControl->wmSysColorChange( wParam, lParam );
  105. lRet = DefMDIChildProc( hwnd, msg, wParam, lParam );
  106. break;
  107. case WM_NOTIFY :
  108. pControl->wmColumnNotify( wParam, lParam );
  109. break;
  110. case WM_CONTEXTMENU :
  111. pControl->wmContextMenu( hwnd, wParam, lParam );
  112. break;
  113. default:
  114. lRet = DefMDIChildProc( hwnd, msg, wParam, lParam );
  115. break;
  116. }
  117. return lRet;
  118. } //SearchWndProc
  119. //
  120. // Scope choice dialog box proc and helper functions
  121. //
  122. unsigned GetCatalogListCount( HWND hdlg )
  123. {
  124. unsigned cChecked = 0;
  125. HWND hCatList = GetDlgItem( hdlg, ID_CATALOG_LIST );
  126. Win4Assert( hCatList );
  127. unsigned iItem = ListView_GetItemCount( hCatList ) ;
  128. LVITEM lvi;
  129. for ( ; iItem > 0; iItem-- )
  130. {
  131. lvi.iItem = iItem - 1;
  132. if ( ListView_GetCheckState( hCatList, lvi.iItem ) )
  133. cChecked++;
  134. }
  135. return cChecked;
  136. } //GetCatalogListCount
  137. void DeleteCatalogSelectedListItems( HWND hdlg )
  138. {
  139. HWND hCatList = GetDlgItem( hdlg, ID_CATALOG_LIST );
  140. Win4Assert( hCatList );
  141. unsigned iItem = ListView_GetItemCount( hCatList ) ;
  142. for ( ; iItem > 0; iItem-- )
  143. {
  144. if ( LVIS_SELECTED == ListView_GetItemState( hCatList, iItem - 1, LVIS_SELECTED ) )
  145. ListView_DeleteItem( hCatList, iItem - 1 );
  146. }
  147. } //DeleteCatalogSelectedListItems
  148. BOOL IsInList(
  149. HWND hCatList,
  150. SScopeCatalogMachine const & scm,
  151. int & item )
  152. {
  153. unsigned iItem = ListView_GetItemCount( hCatList ) ;
  154. LVITEM lvi;
  155. WCHAR wTemp[MAX_PATH];
  156. lvi.pszText = (WCHAR*)wTemp;
  157. lvi.cchTextMax = MAX_PATH;
  158. for ( ; iItem > 0; iItem-- )
  159. {
  160. unsigned iCol = 0;
  161. lvi.iItem = iItem - 1;
  162. lvi.mask = LVIF_TEXT;
  163. // machine
  164. lvi.iSubItem = iCol++;
  165. ListView_GetItem( hCatList, &lvi );
  166. if ( !_wcsicmp( scm.awcMachine, lvi.pszText ) )
  167. {
  168. // catalog
  169. lvi.iSubItem = iCol++;
  170. ListView_GetItem( hCatList, &lvi );
  171. if ( !_wcsicmp( scm.awcCatalog, lvi.pszText ) )
  172. {
  173. // scope
  174. lvi.iSubItem = iCol++;
  175. ListView_GetItem( hCatList, &lvi );
  176. if ( !_wcsicmp( scm.awcScope, lvi.pszText ) )
  177. {
  178. item = lvi.iItem;
  179. return TRUE;
  180. }
  181. }
  182. }
  183. }
  184. return FALSE;
  185. } //IsInList
  186. void AddCatalogToList(
  187. HWND hdlg,
  188. SScopeCatalogMachine const & scm,
  189. BOOL fChecked )
  190. {
  191. HWND hCatList = GetDlgItem( hdlg, ID_CATALOG_LIST );
  192. Win4Assert( hCatList );
  193. // Don't add duplicates, but check the checkbox if needed
  194. int item;
  195. if ( IsInList( hCatList, scm, item ) )
  196. {
  197. if ( fChecked )
  198. ListView_SetCheckState( hCatList, item, fChecked );
  199. return;
  200. }
  201. unsigned cItems = ListView_GetItemCount( hCatList ) ;
  202. LVITEM lvItem;
  203. unsigned iCol = 0;
  204. // Machine
  205. lvItem.mask = LVIF_TEXT;
  206. lvItem.iItem = cItems;
  207. lvItem.iSubItem = iCol++;
  208. lvItem.pszText = (WCHAR*)scm.awcMachine;
  209. ListView_InsertItem( hCatList, &lvItem );
  210. // Catalog
  211. lvItem.iSubItem = iCol++;
  212. lvItem.pszText = (WCHAR*)scm.awcCatalog;
  213. ListView_SetItem( hCatList, &lvItem );
  214. // Scope
  215. lvItem.iSubItem = iCol++;
  216. lvItem.pszText = (WCHAR*)scm.awcScope;
  217. ListView_SetItem( hCatList, &lvItem );
  218. // Depth
  219. lvItem.iSubItem = iCol++;
  220. lvItem.pszText = ( TRUE == scm.fDeep ) ? App.GetYes() : App.GetNo();
  221. ListView_SetItem( hCatList, &lvItem );
  222. ListView_SetCheckState( hCatList, cItems, fChecked );
  223. } //AddCatalogToList
  224. void CheckItIfInList(
  225. HWND hdlg,
  226. SScopeCatalogMachine const & scm )
  227. {
  228. HWND hCatList = GetDlgItem( hdlg, ID_CATALOG_LIST );
  229. Win4Assert( hCatList );
  230. // Don't add duplicates, but check the checkbox if needed
  231. int item;
  232. if ( IsInList( hCatList, scm, item ) )
  233. ListView_SetCheckState( hCatList, item, TRUE );
  234. } //CheckItIfInList
  235. BOOL VerifyCatalogInfo( HWND hdlg, SScopeCatalogMachine & scm )
  236. {
  237. CWaitCursor wait;
  238. if (IsDlgButtonChecked(hdlg,ID_SCOPE_DEEP))
  239. scm.fDeep = TRUE;
  240. else
  241. scm.fDeep = FALSE;
  242. GetDlgItemText( hdlg,
  243. ID_SCOPE_EDIT,
  244. scm.awcScope,
  245. MAX_PATH );
  246. GetDlgItemText( hdlg,
  247. ID_SCOPE_CATALOG_EDIT,
  248. scm.awcCatalog,
  249. MAX_PATH );
  250. GetDlgItemText( hdlg,
  251. ID_SCOPE_MACHINE_EDIT,
  252. scm.awcMachine,
  253. SRCH_COMPUTERNAME_LENGTH );
  254. if ( 0 == scm.awcCatalog[0] )
  255. {
  256. //
  257. // If the user didn't specify a Catalog, then look for one using scope.
  258. //
  259. ULONG ccCat = sizeof(scm.awcCatalog)/sizeof(WCHAR);
  260. ULONG ccMachine = sizeof(scm.awcMachine)/sizeof(WCHAR);
  261. SCODE sc = LocateCatalogs( scm.awcScope,
  262. 0,
  263. scm.awcMachine,
  264. &ccMachine,
  265. scm.awcCatalog,
  266. &ccCat );
  267. }
  268. // don't allow empty catalog names
  269. if ( 0 == scm.awcCatalog[0] )
  270. {
  271. SearchError( hdlg,
  272. IDS_ERR_NO_CATALOG_SPECIFIED,
  273. L"" );
  274. return FALSE;
  275. }
  276. // if scope is empty make it a global physical scope.
  277. if ( 0 == scm.awcScope[0] )
  278. wcscpy( scm.awcScope, L"\\" ); // entire catalog
  279. // map empty machine name to local machine
  280. if ( 0 == scm.awcMachine[0] )
  281. wcscpy( scm.awcMachine, L"." ); // local machine
  282. // remove leading two backslashes from machine name
  283. if ( L'\\' == scm.awcMachine[0] &&
  284. L'\\' == scm.awcMachine[1] )
  285. {
  286. WCHAR awc[SRCH_COMPUTERNAME_LENGTH + 1];
  287. wcscpy( awc, scm.awcMachine+2 );
  288. wcscpy( scm.awcMachine, awc );
  289. }
  290. CI_STATE cistate;
  291. cistate.cbStruct = sizeof cistate;
  292. if (STATUS_NOT_FOUND == CIState( scm.awcCatalog,
  293. scm.awcMachine,
  294. & cistate ) )
  295. {
  296. SearchError( hdlg,
  297. IDS_ERR_BAD_CATALOG_SPECIFIED,
  298. L"" );
  299. return FALSE;
  300. }
  301. return TRUE;
  302. } //VerifyCatalogInfo
  303. void CatListToString( HWND hdlg, XGrowable<WCHAR> & xCatStr )
  304. {
  305. xCatStr.SetSize( 1 );
  306. xCatStr[0] = 0;
  307. HWND hCatList = GetDlgItem( hdlg, ID_CATALOG_LIST );
  308. Win4Assert( hCatList );
  309. unsigned iItem = ListView_GetItemCount( hCatList ) ;
  310. LVITEM lvi;
  311. WCHAR wTemp[MAX_PATH];
  312. lvi.pszText = (WCHAR*)wTemp;
  313. lvi.cchTextMax = MAX_PATH;
  314. for ( ; iItem > 0; iItem-- )
  315. {
  316. unsigned iCol = 0;
  317. unsigned cCatStr;
  318. unsigned cText;
  319. lvi.iItem = iItem - 1;
  320. if ( ListView_GetCheckState( hCatList, lvi.iItem ) )
  321. {
  322. lvi.mask = LVIF_TEXT;
  323. // machine
  324. lvi.iSubItem = iCol++;
  325. ListView_GetItem( hCatList, &lvi );
  326. cCatStr = wcslen( xCatStr.Get() );
  327. cText = wcslen( lvi.pszText );
  328. xCatStr.SetSize( cCatStr + cText + 2 );
  329. wcscat( xCatStr.Get(), lvi.pszText );
  330. wcscat( xCatStr.Get(), L"," );
  331. // catalog
  332. lvi.iSubItem = iCol++;
  333. ListView_GetItem( hCatList, &lvi );
  334. cCatStr = wcslen( xCatStr.Get() );
  335. cText = wcslen( lvi.pszText );
  336. xCatStr.SetSize( cCatStr + cText + 2 );
  337. wcscat( xCatStr.Get(), lvi.pszText );
  338. wcscat( xCatStr.Get(), L"," );
  339. // scope
  340. lvi.iSubItem = iCol++;
  341. ListView_GetItem( hCatList, &lvi );
  342. cCatStr = wcslen( xCatStr.Get() );
  343. cText = wcslen( lvi.pszText );
  344. xCatStr.SetSize( cCatStr + cText + 2 );
  345. wcscat( xCatStr.Get(), lvi.pszText );
  346. wcscat( xCatStr.Get(), L"," );
  347. // depth
  348. lvi.iSubItem = iCol++;
  349. ListView_GetItem( hCatList, &lvi );
  350. cCatStr = wcslen( xCatStr.Get() );
  351. cText = 1;
  352. xCatStr.SetSize( cCatStr + cText + 2 );
  353. wcscat( xCatStr.Get(),
  354. !wcscmp( App.GetYes(), lvi.pszText ) ? L"d" : L"s" );
  355. wcscat( xCatStr.Get(), L";" );
  356. }
  357. }
  358. } //CatListToString
  359. BOOL ScopeDlgInit(
  360. HWND hdlg,
  361. LPARAM lParam,
  362. LPWSTR awcScopeOrig)
  363. {
  364. SScopeCatalogMachine scm;
  365. // search control was passed as lParam
  366. SetWindowLongPtr(hdlg, DWLP_USER, lParam);
  367. XGrowable<WCHAR> *xCatList = (XGrowable<WCHAR> *) lParam;
  368. CheckDlgButton( hdlg, ID_SCOPE_DEEP, TRUE );
  369. SendDlgItemMessage( hdlg,
  370. ID_SCOPE_MACHINE_EDIT,
  371. EM_SETLIMITTEXT,
  372. SRCH_COMPUTERNAME_LENGTH,
  373. 0 );
  374. SendDlgItemMessage( hdlg,
  375. ID_SCOPE_EDIT,
  376. EM_SETLIMITTEXT,
  377. MAX_PATH,
  378. 0 );
  379. SendDlgItemMessage( hdlg,
  380. ID_SCOPE_CATALOG_EDIT,
  381. EM_SETLIMITTEXT,
  382. MAX_PATH,
  383. 0 );
  384. // Setup columns in the multi catalog list box
  385. HWND hCatList = GetDlgItem( hdlg, ID_CATALOG_LIST );
  386. Win4Assert( hCatList );
  387. ListView_SetExtendedListViewStyleEx( hCatList,
  388. LVS_EX_CHECKBOXES | LVS_EX_FULLROWSELECT,
  389. LVS_EX_CHECKBOXES | LVS_EX_FULLROWSELECT );
  390. CResString str;
  391. LVCOLUMN lvc;
  392. unsigned iCol = 0;
  393. lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
  394. lvc.fmt = LVCFMT_LEFT;
  395. lvc.cx = 100;
  396. lvc.iSubItem = iCol++;
  397. str.Load( IDS_CATLIST_COL_MACHINE );
  398. lvc.pszText = str.Get();
  399. ListView_InsertColumn( hCatList, iCol, &lvc) ;
  400. lvc.cx = 90;
  401. lvc.iSubItem = iCol++;
  402. str.Load( IDS_CATLIST_COL_CATALOG );
  403. lvc.pszText = str.Get();
  404. ListView_InsertColumn( hCatList, iCol, &lvc) ;
  405. lvc.cx = 90;
  406. lvc.iSubItem = iCol++;
  407. str.Load( IDS_CATLIST_COL_SCOPE );
  408. lvc.pszText = str.Get();
  409. ListView_InsertColumn( hCatList, iCol, &lvc) ;
  410. lvc.cx = 50;
  411. lvc.iSubItem = iCol++;
  412. str.Load( IDS_CATLIST_COL_SUBDIRS );
  413. lvc.pszText = str.Get();
  414. ListView_InsertColumn( hCatList, iCol, &lvc) ;
  415. BOOL fMultiCat = GetCatListItem( *xCatList,
  416. 1,
  417. scm.awcMachine,
  418. scm.awcCatalog,
  419. scm.awcScope,
  420. scm.fDeep );
  421. scm.fDeep = TRUE;
  422. //
  423. // Add the catalogs from the user's environment if present.
  424. // The SRCHDEFAULTS variable is of the form
  425. //
  426. // server\catalog:scope;server\catalog:scope;+server\catalog:scope
  427. //
  428. // + indicates that the server should be checked by default. If no
  429. // scope is provided, then \ is used.
  430. //
  431. WCHAR wszDefaults[MAX_PATH];
  432. DWORD dwResult = GetEnvironmentVariableW( L"SRCHDEFAULTS", wszDefaults, MAX_PATH );
  433. if (dwResult && dwResult < MAX_PATH)
  434. {
  435. LPWSTR psz = wszDefaults;
  436. while ( *psz )
  437. {
  438. BOOL fChecked = FALSE;
  439. if ( *psz == L'+' )
  440. {
  441. fChecked = TRUE;
  442. psz++;
  443. }
  444. // Everything up to the \ is the server name
  445. LPWSTR pszT = wcschr( psz, L'\\' );
  446. if ( 0 == pszT )
  447. {
  448. break;
  449. }
  450. *pszT++ = L'\0';
  451. lstrcpynW( scm.awcMachine, psz, SRCH_COMPUTERNAME_LENGTH + 1 );
  452. // Everything up to the ; or end of string is the catalog:scope
  453. psz = pszT;
  454. pszT = wcschr( psz, L';' );
  455. if ( 0 != pszT )
  456. {
  457. *pszT++ = L'\0';
  458. }
  459. else
  460. {
  461. pszT = psz + wcslen( psz );
  462. }
  463. //
  464. // If there is a : then that's the scope.
  465. //
  466. LPWSTR pszColon = wcschr( psz, L':' );
  467. if ( 0 != pszColon )
  468. {
  469. *pszColon++ = L'\0';
  470. lstrcpynW( scm.awcScope, pszColon, MAX_PATH );
  471. }
  472. else
  473. {
  474. // Default scope is "\"
  475. wcscpy( scm.awcScope, L"\\" );
  476. }
  477. lstrcpynW( scm.awcCatalog, psz, MAX_PATH );
  478. AddCatalogToList( hdlg, scm, fChecked );
  479. psz = pszT;
  480. }
  481. }
  482. else
  483. {
  484. // Add the well-known catalogs
  485. wcscpy( scm.awcScope, L"\\" );
  486. HRSRC hrc = FindResource( 0, (LPCWSTR) IDR_CATALOGS, RT_RCDATA );
  487. if ( 0 != hrc )
  488. {
  489. HGLOBAL hg = LoadResource( 0, hrc );
  490. if ( 0 != hg )
  491. {
  492. WCHAR * p = (WCHAR *) LockResource( hg );
  493. while ( 0 != p && 0 != *p )
  494. {
  495. wcscpy( scm.awcMachine, p );
  496. p += ( wcslen( p ) + 1 );
  497. wcscpy( scm.awcCatalog, p );
  498. p += ( wcslen( p ) + 1 );
  499. AddCatalogToList( hdlg, scm, FALSE );
  500. }
  501. }
  502. }
  503. }
  504. if ( ! fMultiCat )
  505. {
  506. if ( GetCatListItem( *xCatList,
  507. 0,
  508. scm.awcMachine,
  509. scm.awcCatalog,
  510. scm.awcScope,
  511. scm.fDeep ) )
  512. {
  513. SetDlgItemText( hdlg, ID_SCOPE_EDIT, scm.awcScope );
  514. SetDlgItemText( hdlg, ID_SCOPE_CATALOG_EDIT, scm.awcCatalog );
  515. SetDlgItemText( hdlg, ID_SCOPE_MACHINE_EDIT, scm.awcMachine );
  516. CheckDlgButton( hdlg, ID_SCOPE_DEEP, scm.fDeep );
  517. CheckItIfInList( hdlg, scm );
  518. }
  519. }
  520. else
  521. {
  522. for ( unsigned ii = 0; ; ii ++ )
  523. {
  524. if ( GetCatListItem( *xCatList,
  525. ii,
  526. scm.awcMachine,
  527. scm.awcCatalog,
  528. scm.awcScope,
  529. scm.fDeep ) )
  530. AddCatalogToList( hdlg, scm, TRUE );
  531. else
  532. break;
  533. }
  534. }
  535. wcscpy( awcScopeOrig, scm.awcScope );
  536. UINT ctlID = ID_SCOPE_MACHINE_EDIT;
  537. SetFocus( GetDlgItem( hdlg, ctlID ) );
  538. MySendEMSetSel( GetDlgItem( hdlg, ctlID ), 0, (UINT) -1 );
  539. CenterDialog( hdlg );
  540. return FALSE;
  541. } //ScopeDlgInit
  542. INT_PTR WINAPI ScopeDlgProc(
  543. HWND hdlg,
  544. UINT msg,
  545. WPARAM wParam,
  546. LPARAM lParam )
  547. {
  548. BOOL fRet = FALSE;
  549. // pointer to search control that will receive the new scope
  550. // safe: can have one dlg up at a time!
  551. SScopeCatalogMachine scm;
  552. static WCHAR awcScopeOrig[MAX_PATH];
  553. switch (msg)
  554. {
  555. case WM_INITDIALOG :
  556. {
  557. fRet = ScopeDlgInit( hdlg, lParam, awcScopeOrig );
  558. break;
  559. }
  560. case WM_NOTIFY:
  561. {
  562. if ( ID_CATALOG_LIST == (int) wParam )
  563. {
  564. LPNMHDR pnmh = (LPNMHDR) lParam;
  565. if ( LVN_KEYDOWN == pnmh->code )
  566. {
  567. NMLVKEYDOWN * pnkd = (NMLVKEYDOWN *) lParam;
  568. if ( VK_DELETE == pnkd->wVKey )
  569. DeleteCatalogSelectedListItems( hdlg );
  570. }
  571. }
  572. break;
  573. }
  574. case WM_COMMAND :
  575. {
  576. UINT uiID = MyWmCommandID( wParam, lParam );
  577. switch (uiID)
  578. {
  579. case ID_SCOPE_EDIT:
  580. {
  581. if ( EN_KILLFOCUS == HIWORD(wParam) )
  582. {
  583. // Try to locate a matching catalog
  584. GetDlgItemText( hdlg,
  585. ID_SCOPE_EDIT,
  586. scm.awcScope,
  587. MAX_PATH );
  588. // only look for a cat if the scope changed
  589. if ( 0 != wcscmp( scm.awcScope, awcScopeOrig ) )
  590. {
  591. CWaitCursor wait;
  592. ULONG ccCat = sizeof(scm.awcCatalog)/sizeof(WCHAR);
  593. ULONG ccMachine = sizeof(scm.awcMachine)/sizeof(WCHAR);
  594. SCODE sc = LocateCatalogs( scm.awcScope,
  595. 0,
  596. scm.awcMachine,
  597. &ccMachine,
  598. scm.awcCatalog,
  599. &ccCat );
  600. if ( S_OK == sc )
  601. {
  602. SetDlgItemText( hdlg, ID_SCOPE_CATALOG_EDIT, scm.awcCatalog );
  603. SetDlgItemText( hdlg, ID_SCOPE_MACHINE_EDIT, scm.awcMachine );
  604. }
  605. }
  606. }
  607. break;
  608. }
  609. case ID_CATALOG_ADD:
  610. {
  611. if ( VerifyCatalogInfo( hdlg, scm ) )
  612. {
  613. AddCatalogToList( hdlg, scm, TRUE );
  614. SetDlgItemText( hdlg, ID_SCOPE_EDIT, L"" );
  615. SetDlgItemText( hdlg, ID_SCOPE_CATALOG_EDIT, L"" );
  616. SetDlgItemText( hdlg, ID_SCOPE_MACHINE_EDIT, L"" );
  617. SetFocus( GetDlgItem( hdlg, ID_SCOPE_MACHINE_EDIT ) );
  618. }
  619. break;
  620. }
  621. case IDOK:
  622. {
  623. XGrowable<WCHAR> *xCatList = reinterpret_cast<XGrowable<WCHAR> *>
  624. (GetWindowLongPtr(hdlg, DWLP_USER));
  625. GetDlgItemText( hdlg,
  626. ID_SCOPE_EDIT,
  627. scm.awcScope,
  628. MAX_PATH );
  629. GetDlgItemText( hdlg,
  630. ID_SCOPE_CATALOG_EDIT,
  631. scm.awcCatalog,
  632. MAX_PATH );
  633. GetDlgItemText( hdlg,
  634. ID_SCOPE_MACHINE_EDIT,
  635. scm.awcMachine,
  636. SRCH_COMPUTERNAME_LENGTH );
  637. // We look at the edit fields only if user has entered some
  638. // value and nothing has been added to the catalog list.
  639. // If anything has been added to catalog list, then we
  640. // only look at the list and ignore these fields
  641. if ( ( scm.awcScope[0] || scm.awcCatalog[0] || scm.awcMachine[0] )
  642. && 0 == GetCatalogListCount( hdlg ) )
  643. {
  644. if ( VerifyCatalogInfo( hdlg, scm ) )
  645. AddCatalogToList( hdlg, scm, TRUE );
  646. else
  647. break;
  648. }
  649. CatListToString( hdlg, *xCatList );
  650. if ( 0 == (*xCatList)[0] )
  651. {
  652. SearchError( hdlg,
  653. IDS_ERR_NO_CATALOG_SPECIFIED,
  654. L"" );
  655. break;
  656. }
  657. }
  658. // fall through!
  659. case IDCANCEL:
  660. EndDialog( hdlg, IDOK == uiID );
  661. break;
  662. }
  663. break;
  664. }
  665. }
  666. return fRet;
  667. } //ScopeDlgProc
  668. static WNDPROC g_DlgWndProc = 0;
  669. INT_PTR WINAPI DisplayPropsDlgProc(
  670. HWND hdlg,
  671. UINT msg,
  672. WPARAM wParam,
  673. LPARAM lParam );
  674. void EnableOrDisableButtons(
  675. HWND hdlg,
  676. HWND hAvail,
  677. HWND hDisp )
  678. {
  679. int iSelAvail = (int) SendMessage( hAvail, LB_GETCURSEL, 0, 0 );
  680. int iSelDisp = (int) SendMessage( hDisp, LB_GETCURSEL, 0, 0 );
  681. HWND hAdd = GetDlgItem( hdlg, ID_PROP_ADD );
  682. HWND hRemove = GetDlgItem( hdlg, ID_PROP_REMOVE );
  683. if ( iSelAvail == -1 && GetFocus() == hAdd )
  684. SetFocus( hAvail );
  685. if ( iSelDisp == -1 && GetFocus() == hRemove )
  686. SetFocus( hDisp );
  687. EnableWindow( hAdd, iSelAvail != -1 );
  688. EnableWindow( hRemove, iSelDisp != -1 );
  689. } //EnableOrDisableButtons
  690. LRESULT WINAPI DlgSubclassProc(
  691. HWND hwnd,
  692. UINT msg,
  693. WPARAM wParam,
  694. LPARAM lParam )
  695. {
  696. static UINT msgDrag = RegisterWindowMessage( DRAGLISTMSGSTRING );
  697. static iDraggedItem;
  698. LRESULT lRet = 0;
  699. if ( msgDrag == msg )
  700. {
  701. HWND hAvail = GetDlgItem( hwnd, ID_PROP_AVAIL );
  702. HWND hDisp = GetDlgItem( hwnd, ID_PROP_DISP );
  703. DRAGLISTINFO *pInfo = (DRAGLISTINFO *) lParam;
  704. switch( pInfo->uNotification )
  705. {
  706. case DL_BEGINDRAG :
  707. {
  708. iDraggedItem = LBItemFromPt( pInfo->hWnd,
  709. pInfo->ptCursor, TRUE );
  710. lRet = TRUE;
  711. break;
  712. }
  713. case DL_DRAGGING :
  714. {
  715. int i = -1;
  716. HWND hDst = hDisp;
  717. if ( pInfo->hWnd == hAvail )
  718. {
  719. i = LBItemFromPt( hDisp, pInfo->ptCursor, TRUE );
  720. }
  721. else
  722. {
  723. i = LBItemFromPt( hDisp, pInfo->ptCursor, TRUE );
  724. if ( -1 == i )
  725. {
  726. i = LBItemFromPt( hAvail, pInfo->ptCursor, TRUE );
  727. hDst = hAvail;
  728. }
  729. }
  730. DrawInsert( hwnd, hDst, i );
  731. if ( -1 == i )
  732. lRet = DL_STOPCURSOR;
  733. else
  734. lRet = DL_MOVECURSOR;
  735. break;
  736. }
  737. case DL_CANCELDRAG :
  738. {
  739. DrawInsert( hwnd, pInfo->hWnd, -1 );
  740. lRet = DL_CURSORSET;
  741. break;
  742. }
  743. case DL_DROPPED :
  744. {
  745. int i = -1;
  746. HWND hDst = hDisp;
  747. if ( pInfo->hWnd == hAvail )
  748. {
  749. i = LBItemFromPt( hDisp, pInfo->ptCursor, TRUE );
  750. }
  751. else
  752. {
  753. i = LBItemFromPt( hDisp, pInfo->ptCursor, TRUE );
  754. if ( -1 == i )
  755. {
  756. i = LBItemFromPt( hAvail, pInfo->ptCursor, TRUE );
  757. hDst = hAvail;
  758. }
  759. }
  760. if ( ( -1 != i && -1 != iDraggedItem ) &&
  761. ( ! ( pInfo->hWnd == hDisp &&
  762. hDst == hDisp &&
  763. i == iDraggedItem ) ) )
  764. {
  765. if ( hDst == hAvail )
  766. {
  767. // move displayed to avail
  768. DisplayPropsDlgProc( hwnd,
  769. WM_COMMAND,
  770. (WPARAM) MAKELONG(ID_PROP_REMOVE,0),
  771. 0 );
  772. }
  773. else if ( pInfo->hWnd == hAvail )
  774. {
  775. // move avail to displayed
  776. WCHAR awcBuf[ cwcBufSize ];
  777. SendMessage( hAvail, LB_GETTEXT, iDraggedItem, (LPARAM) awcBuf );
  778. SendMessage( hDisp, LB_INSERTSTRING, i, (LPARAM ) awcBuf );
  779. SendMessage( hAvail, LB_DELETESTRING, iDraggedItem, 0 );
  780. }
  781. else
  782. {
  783. // reorder displayed items
  784. WCHAR awcBuf[ cwcBufSize ];
  785. SendMessage( hDisp, LB_GETTEXT, iDraggedItem, (LPARAM) awcBuf );
  786. SendMessage( hDisp, LB_INSERTSTRING, i, (LPARAM ) awcBuf );
  787. if ( iDraggedItem > i )
  788. iDraggedItem++;
  789. SendMessage( hDisp, LB_DELETESTRING, iDraggedItem, 0 );
  790. }
  791. }
  792. DrawInsert( hwnd, pInfo->hWnd, -1 );
  793. lRet = DL_CURSORSET;
  794. EnableOrDisableButtons( hwnd, hAvail, hDisp );
  795. break;
  796. }
  797. }
  798. return lRet;
  799. }
  800. if ( 0 != g_DlgWndProc )
  801. lRet = g_DlgWndProc( hwnd, msg, wParam, lParam );
  802. return lRet;
  803. } //DlgSubclassProc
  804. INT_PTR WINAPI DisplayPropsDlgProc(
  805. HWND hdlg,
  806. UINT msg,
  807. WPARAM wParam,
  808. LPARAM lParam )
  809. {
  810. // pointer to search control that will receive the new props
  811. // safe: can have one dlg up at a time!
  812. static CSearchControl *s_pControl = 0;
  813. BOOL fRet = FALSE;
  814. switch (msg)
  815. {
  816. case WM_INITDIALOG :
  817. {
  818. // subclass the dlgproc -- we need a window proc, not a dlgproc
  819. g_DlgWndProc = (WNDPROC) GetWindowLongPtr( hdlg, GWLP_WNDPROC );
  820. SetWindowLongPtr( hdlg, GWLP_WNDPROC, (LONG_PTR) DlgSubclassProc );
  821. // search control was passed as lParam
  822. s_pControl = (CSearchControl *) lParam;
  823. CColumnList & columns = s_pControl->GetColumnList();
  824. IColumnMapper & map = s_pControl->GetColumnMapper();
  825. // fill the displayed and available listboxes
  826. HWND hAvail = GetDlgItem( hdlg, ID_PROP_AVAIL );
  827. HWND hDisp = GetDlgItem( hdlg, ID_PROP_DISP );
  828. unsigned cDisp = columns.NumberOfColumns();
  829. MakeDragList( hAvail );
  830. MakeDragList( hDisp );
  831. ULONG iEntry = 0;
  832. WCHAR const *pwcName;
  833. DBID *pdbid;
  834. DBTYPE dbtype;
  835. unsigned int uiWidth;
  836. while ( SUCCEEDED( map.EnumPropInfo( iEntry,
  837. &pwcName,
  838. &pdbid,
  839. &dbtype,
  840. &uiWidth ) ) )
  841. {
  842. if ( 0 != uiWidth )
  843. {
  844. XArray<WCHAR> xLower( 1 + wcslen( pwcName ) );
  845. wcscpy( xLower.Get(), pwcName );
  846. _wcslwr( xLower.Get() + 1 );
  847. BOOL fIsDisp = FALSE;
  848. for ( unsigned i = 0; i < cDisp; i++ )
  849. {
  850. if ( !_wcsicmp( xLower.Get(), columns.GetColumn( i ) ) )
  851. {
  852. fIsDisp = TRUE;
  853. break;
  854. }
  855. }
  856. if (!fIsDisp)
  857. SendMessage( hAvail,
  858. LB_ADDSTRING,
  859. 0,
  860. (LPARAM) xLower.Get() );
  861. }
  862. iEntry++;
  863. }
  864. for ( unsigned i = 0; i < cDisp; i++ )
  865. SendMessage( hDisp, LB_ADDSTRING, 0,
  866. (LPARAM) columns.GetColumn( i ) );
  867. CenterDialog( hdlg );
  868. EnableOrDisableButtons( hdlg, hAvail, hDisp );
  869. fRet = FALSE;
  870. break;
  871. }
  872. case WM_COMMAND :
  873. {
  874. HWND hAvail = GetDlgItem( hdlg, ID_PROP_AVAIL );
  875. HWND hDisp = GetDlgItem( hdlg, ID_PROP_DISP );
  876. WORD cmd = MyWmCommandCmd( wParam, lParam );
  877. switch ( MyWmCommandID( wParam, lParam ) )
  878. {
  879. case ID_PROP_ADD :
  880. {
  881. int iSelDisp = (int) SendMessage( hDisp, LB_GETCURSEL, 0, 0 );
  882. int iSelAvail = (int) SendMessage( hAvail, LB_GETCURSEL, 0, 0 );
  883. if ( LB_ERR != iSelAvail )
  884. {
  885. WCHAR awcBuf[ cwcBufSize ];
  886. SendMessage( hAvail, LB_GETTEXT, iSelAvail, (LPARAM) awcBuf );
  887. SendMessage( hDisp,
  888. LB_INSERTSTRING,
  889. iSelDisp != LB_ERR ? iSelDisp : -1,
  890. (LPARAM ) awcBuf );
  891. SendMessage( hAvail, LB_DELETESTRING, iSelAvail, 0 );
  892. }
  893. EnableOrDisableButtons( hdlg, hAvail, hDisp );
  894. break;
  895. }
  896. case ID_PROP_REMOVE :
  897. {
  898. int iSelDisp = (int) SendMessage( hDisp, LB_GETCURSEL, 0, 0 );
  899. if ( LB_ERR != iSelDisp )
  900. {
  901. WCHAR awcBuf[ cwcBufSize ];
  902. SendMessage( hDisp, LB_GETTEXT, iSelDisp, (LPARAM) awcBuf );
  903. SendMessage( hAvail, LB_ADDSTRING, 0, (LPARAM ) awcBuf );
  904. SendMessage( hDisp, LB_DELETESTRING, iSelDisp, 0 );
  905. }
  906. EnableOrDisableButtons( hdlg, hAvail, hDisp );
  907. break;
  908. }
  909. case ID_PROP_AVAIL :
  910. {
  911. if ( LBN_DBLCLK == cmd )
  912. DisplayPropsDlgProc( hdlg,
  913. WM_COMMAND,
  914. (WPARAM) MAKELONG(ID_PROP_ADD,0),
  915. 0 );
  916. EnableOrDisableButtons( hdlg, hAvail, hDisp );
  917. break;
  918. }
  919. case ID_PROP_DISP :
  920. {
  921. if ( LBN_DBLCLK == cmd )
  922. DisplayPropsDlgProc( hdlg,
  923. WM_COMMAND,
  924. (WPARAM) MAKELONG(ID_PROP_REMOVE,0),
  925. 0 );
  926. EnableOrDisableButtons( hdlg, hAvail, hDisp );
  927. break;
  928. }
  929. case IDOK :
  930. {
  931. HWND hDisp = GetDlgItem( hdlg, ID_PROP_DISP );
  932. ULONG cDisp = (ULONG)SendMessage( hDisp, LB_GETCOUNT, 0, 0 );
  933. WCHAR awcDisp[ cwcBufSize ];
  934. awcDisp[0] = 0;
  935. cDisp = __min( cDisp, maxBoundCols );
  936. for ( unsigned i = 0; i < cDisp; i++ )
  937. {
  938. WCHAR awcBuf[ cwcBufSize ];
  939. SendMessage( hDisp, LB_GETTEXT, i, (LPARAM) awcBuf );
  940. if ( 0 != awcDisp[0] )
  941. wcscat( awcDisp, L"," );
  942. wcscat( awcDisp, awcBuf );
  943. }
  944. SetReg( CISEARCH_REG_DISPLAYPROPS, awcDisp );
  945. s_pControl->SetupDisplayProps( awcDisp );
  946. EndDialog( hdlg, TRUE );
  947. break;
  948. }
  949. case ID_PROP_DEFAULT :
  950. {
  951. WCHAR awcDisp[ cwcBufSize ];
  952. wcscpy( awcDisp, DEFAULT_DISPLAYED_PROPERTIES );
  953. SetReg( CISEARCH_REG_DISPLAYPROPS, awcDisp );
  954. s_pControl->SetupDisplayProps( awcDisp );
  955. EndDialog( hdlg, TRUE );
  956. break;
  957. }
  958. case IDCANCEL :
  959. {
  960. EndDialog( hdlg, FALSE );
  961. break;
  962. }
  963. }
  964. break;
  965. }
  966. }
  967. return fRet;
  968. } //DisplayPropsDlgProc
  969. //
  970. // Subclass window procedure for edit control
  971. //
  972. LRESULT WINAPI EditSubclassProc(
  973. HWND hwnd,
  974. UINT msg,
  975. WPARAM wParam,
  976. LPARAM lParam )
  977. {
  978. LRESULT lRet = 0;
  979. HWND hParent = GetParent(GetParent(hwnd));
  980. if (0 != hParent)
  981. {
  982. CSearchControl *pControl = (CSearchControl *) GetWindowLongPtr (hParent, 0);
  983. if (0 != pControl)
  984. lRet = pControl->EditSubclassEvent(hwnd,msg,wParam,lParam);
  985. }
  986. return lRet;
  987. } //EditSubclassProc
  988. //
  989. // Search Control
  990. //
  991. CSearchControl::CSearchControl(
  992. HWND hwnd,
  993. WCHAR * pwcScope)
  994. :
  995. #pragma warning(disable : 4355)
  996. _view( hwnd, *this, _columns ),
  997. #pragma warning(default : 4355)
  998. _hInst( 0 ),
  999. _hwndSearch( hwnd ),
  1000. _hwndQuery( 0 ),
  1001. _hwndQueryTitle( 0 ),
  1002. _hwndHeader( 0 ),
  1003. _hwndList( 0 ),
  1004. _lpOrgEditProc( 0 ),
  1005. _pSearch( 0 ),
  1006. _fDeep( TRUE )
  1007. {
  1008. ISimpleCommandCreator & cmdCreator = *App.GetCommandCreator();
  1009. XInterface<IColumnMapperCreator> xMapper;
  1010. SCODE sc = cmdCreator.QueryInterface( IID_IColumnMapperCreator, xMapper.GetQIPointer() );
  1011. if ( FAILED( sc ) )
  1012. THROW( CException( sc ) );
  1013. sc = xMapper->GetColumnMapper( L".", L"SYSTEM", _xColumnMapper.GetPPointer() );
  1014. if ( FAILED( sc ) )
  1015. THROW( CException( sc ) );
  1016. SetWindowLongPtr( hwnd, 0, (LONG_PTR) this );
  1017. _sort.SetSort( App.GetSortProp(), App.GetSortDir() );
  1018. _lcid = App.GetLocale();
  1019. _hInst = MyGetWindowInstance( _hwndSearch );
  1020. _xCatList = App.CatalogList();
  1021. // Get the first cat item
  1022. GetCatListItem( App.CatalogList(), 0, _awcMachine, _awcCatalog, _awcScope, _fDeep );
  1023. ResetTitle();
  1024. InitPanes();
  1025. } //CSearchControl
  1026. LRESULT CSearchControl::wmActivate(
  1027. HWND hwnd,
  1028. WPARAM wParam,
  1029. LPARAM lParam )
  1030. {
  1031. if ( hwnd == (HWND) lParam )
  1032. {
  1033. SIZE size;
  1034. {
  1035. HDC hdc = GetDC( _hwndQueryTitle );
  1036. if ( 0 != hdc )
  1037. {
  1038. CResString str( IDS_COUNTTITLE );
  1039. GetTextExtentPoint32( hdc, str.Get(), wcslen( str.Get() ), &size );
  1040. ReleaseDC( _hwndQueryTitle, hdc );
  1041. }
  1042. }
  1043. int apos[] = { size.cx + 2, size.cx + 102, -1 };
  1044. SendMessage( App.StatusBarWindow(),
  1045. SB_SETPARTS,
  1046. sizeof apos / sizeof apos[ 0 ],
  1047. (LPARAM) apos );
  1048. _UpdateStatusWindow( L"", L"" );
  1049. UINT cDisable = 2;
  1050. static UINT aDisable[] = { IDM_PREVIOUS_HIT,
  1051. IDM_NEXT_HIT,
  1052. IDM_BROWSE, };
  1053. UINT cEnable = 4;
  1054. static UINT aEnable[] = { IDM_SEARCH,
  1055. IDM_SEARCHCLASSDEF,
  1056. IDM_SEARCHFUNCDEF,
  1057. IDM_DISPLAY_PROPS,
  1058. IDM_BROWSE };
  1059. if ( ( 0 != _pSearch ) &&
  1060. ( _pSearch->IsSelected() ) )
  1061. cEnable++;
  1062. else
  1063. cDisable++;
  1064. UpdateButtons( aDisable, cDisable, FALSE );
  1065. UpdateButtons( aEnable, cEnable, TRUE );
  1066. _UpdateCount();
  1067. }
  1068. return 0;
  1069. } //wmActivate
  1070. void CSearchControl::_UpdateStatusWindow(
  1071. WCHAR const * pwcMsg,
  1072. WCHAR const * pwcReliability )
  1073. {
  1074. SendMessage( App.StatusBarWindow(), SB_SETTEXT, SBT_OWNERDRAW | idStatusRatio, 0 );
  1075. SendMessage( App.StatusBarWindow(), SB_SETTEXT, idStatusMsg, (LPARAM) pwcMsg );
  1076. SendMessage( App.StatusBarWindow(), SB_SETTEXT, idStatusReliability, (LPARAM) pwcReliability );
  1077. } //_UpdateStatusWindow
  1078. LRESULT CSearchControl::wmRealDrawItem(
  1079. HWND hwnd,
  1080. WPARAM wParam,
  1081. LPARAM lParam )
  1082. {
  1083. LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT) lParam;
  1084. if ( lpdis->hwndItem == App.StatusBarWindow() )
  1085. {
  1086. ULONG iPct = 0;
  1087. if ( 0 != _pSearch )
  1088. iPct = _pSearch->PctDone();
  1089. RECT rc;
  1090. CopyRect( &rc, &lpdis->rcItem );
  1091. rc.right += iPct;
  1092. FillRect( lpdis->hDC, &rc, App.BtnHiliteBrush() );
  1093. CopyRect( &rc, &lpdis->rcItem );
  1094. rc.left += iPct;
  1095. FillRect( lpdis->hDC, &rc, App.BtnFaceBrush() );
  1096. if ( 0 != _pSearch )
  1097. {
  1098. int iOldMode = SetBkMode( lpdis->hDC, TRANSPARENT );
  1099. COLORREF crOld = SetTextColor( lpdis->hDC,
  1100. GetSysColor( COLOR_BTNTEXT ) );
  1101. WCHAR awc[40];
  1102. if ( QUERY_FILL_STATUS( _pSearch->QueryStatus() ) == STAT_ERROR )
  1103. {
  1104. CResString strError( IDS_QUERYERROR );
  1105. wcscpy( awc, strError.Get() );
  1106. }
  1107. else if ( _pSearch->MostlyDone() )
  1108. {
  1109. CResString strDone( IDS_QUERYDONE );
  1110. wcscpy( awc, strDone.Get() );
  1111. }
  1112. else
  1113. wsprintf( awc, L"%d%%", iPct );
  1114. DrawText( lpdis->hDC, awc, wcslen( awc ), & lpdis->rcItem,
  1115. DT_SINGLELINE | DT_VCENTER | DT_CENTER );
  1116. SetTextColor( lpdis->hDC, crOld );
  1117. SetBkMode( lpdis->hDC, iOldMode );
  1118. }
  1119. }
  1120. return 1;
  1121. } //wmRealDrawItem
  1122. LRESULT CSearchControl::wmColumnNotify(
  1123. WPARAM wParam,
  1124. LPARAM lParam )
  1125. {
  1126. HD_NOTIFY * pn = (HD_NOTIFY *) lParam;
  1127. switch ( pn->hdr.code )
  1128. {
  1129. case HDN_ENDTRACK :
  1130. {
  1131. if ( (int) _view.ColumnWidth( pn->iItem ) != pn->pitem->cxy )
  1132. {
  1133. _view.SetColumnWidth( pn->iItem, pn->pitem->cxy );
  1134. InvalidateRect( _hwndList, 0, TRUE );
  1135. }
  1136. break;
  1137. }
  1138. case HDN_DIVIDERDBLCLICK :
  1139. {
  1140. HD_ITEM hdi;
  1141. hdi.mask = HDI_FORMAT | HDI_WIDTH | HDI_TEXT;
  1142. hdi.cxy = _view.SetDefColumnWidth( pn->iItem );
  1143. hdi.pszText = (WCHAR *) _columns.GetColumn( pn->iItem );
  1144. hdi.hbm = 0;
  1145. hdi.cchTextMax = wcslen( hdi.pszText );
  1146. hdi.fmt = HDF_STRING | HDF_LEFT;
  1147. hdi.lParam = 0;
  1148. Header_SetItem( _hwndHeader, pn->iItem, &hdi );
  1149. InvalidateRect( _hwndList, 0, TRUE );
  1150. break;
  1151. }
  1152. case HDN_ITEMCLICK :
  1153. {
  1154. //BOOL fUp = ( 0 == ( 0x8000 & GetAsyncKeyState( VK_CONTROL ) ) );
  1155. // invert the old sort order
  1156. int dir = ( _sort.GetSortDir() == SORT_UP ) ? SORT_DOWN : SORT_UP;
  1157. _sort.SetSort( _columns.GetColumn( pn->iItem ), dir );
  1158. wcscpy( App.GetSortProp(), _columns.GetColumn( pn->iItem ) );
  1159. App.GetSortDir() = dir;
  1160. PostMessage ( _hwndSearch,
  1161. ::wmMenuCommand,
  1162. IDM_SEARCH,
  1163. MAKELPARAM( 1, 0 ) );
  1164. break;
  1165. }
  1166. }
  1167. return DefMDIChildProc( _hwndSearch, WM_NOTIFY, wParam, lParam );
  1168. } //wmColumnNotify
  1169. void CSearchControl::SetupDisplayProps(
  1170. WCHAR *pwcProps )
  1171. {
  1172. _columns.SetNumberOfColumns( 0 );
  1173. WCHAR *pwc = pwcProps;
  1174. unsigned iPos = 0;
  1175. do
  1176. {
  1177. WCHAR *pwcStart = pwc;
  1178. while ( *pwc && ',' != *pwc )
  1179. pwc++;
  1180. if ( ',' == *pwc )
  1181. {
  1182. *pwc = 0;
  1183. pwc++;
  1184. }
  1185. if ( *pwcStart )
  1186. _columns.SetColumn( pwcStart, iPos++ );
  1187. else
  1188. break;
  1189. } while ( TRUE );
  1190. // if the list is bad -- no props added, add the default props
  1191. if ( 0 == iPos )
  1192. {
  1193. WCHAR awcProp[ cwcBufSize ];
  1194. wcscpy( awcProp, DEFAULT_DISPLAYED_PROPERTIES );
  1195. SetupDisplayProps( awcProp );
  1196. }
  1197. _view.ColumnsChanged();
  1198. _AddColumnHeadings();
  1199. } //SetupDisplayProps
  1200. void CSearchControl::_AddColumnHeadings()
  1201. {
  1202. // delete any existing column headers
  1203. int cItems = Header_GetItemCount( _hwndHeader );
  1204. for ( int i = 0; i < cItems; i++ )
  1205. Header_DeleteItem( _hwndHeader, 0 );
  1206. // add the current column headers
  1207. HD_ITEM hdi;
  1208. hdi.mask = HDI_FORMAT | HDI_WIDTH | HDI_TEXT;
  1209. hdi.hbm = 0;
  1210. hdi.fmt = HDF_STRING | HDF_LEFT;
  1211. hdi.lParam = 0;
  1212. for ( unsigned x = 0; x < _columns.NumberOfColumns(); x++ )
  1213. {
  1214. hdi.cxy = _view.ColumnWidth( x );
  1215. hdi.pszText = (WCHAR *) _columns.GetColumn( x );
  1216. hdi.cchTextMax = wcslen( hdi.pszText );
  1217. Header_InsertItem( _hwndHeader, x, &hdi );
  1218. }
  1219. } //_AddColumnHeadings
  1220. void CSearchControl::InitPanes ()
  1221. {
  1222. // Query pane
  1223. _hwndQuery = CreateWindow( L"COMBOBOX",
  1224. 0,
  1225. WS_VSCROLL | CBS_AUTOHSCROLL | CBS_DROPDOWN | WS_CHILD | WS_BORDER | WS_TABSTOP | WS_GROUP,
  1226. 0, 0, 0, 0,
  1227. _hwndSearch,
  1228. (HMENU) idQueryChild,
  1229. _hInst,
  1230. 0 );
  1231. // Get the edit field from the combobox
  1232. // This is a hack, but I can't find any way of getting the
  1233. // edit field from the combo box
  1234. HWND hEdit = FindWindowEx( _hwndQuery, 0, L"EDIT", 0 );
  1235. if ( 0 == hEdit )
  1236. return;
  1237. _lpOrgEditProc = (WNDPROC) GetWindowLongPtr( hEdit, GWLP_WNDPROC );
  1238. SetWindowLongPtr( hEdit, GWLP_WNDPROC, (LONG_PTR) EditSubclassProc );
  1239. _hLastToHaveFocus = _hwndQuery;
  1240. // List View pane
  1241. // to be replaced by ListView
  1242. _hwndList = CreateWindow( LIST_VIEW_CLASS,
  1243. L"",
  1244. WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_GROUP |
  1245. WS_VSCROLL | WS_BORDER,
  1246. 0, 0, 0, 0,
  1247. _hwndSearch,
  1248. (HMENU) idListChild,
  1249. _hInst,
  1250. 0 );
  1251. DWORD err;
  1252. if (_hwndList == 0)
  1253. err = GetLastError();
  1254. const long styleStatic = SS_LEFT | WS_CHILD;
  1255. CResString strQuery (IDS_QUERYTITLE);
  1256. _hwndQueryTitle = CreateWindow( L"static",
  1257. strQuery.Get(),
  1258. styleStatic,
  1259. 0,0,0,0,
  1260. _hwndSearch,
  1261. (HMENU) idQueryTitle,
  1262. _hInst,
  1263. 0 );
  1264. _hwndHeader = CreateWindowEx( 0,
  1265. WC_HEADER,
  1266. 0,
  1267. WS_CHILD | WS_BORDER |
  1268. HDS_HORZ | HDS_BUTTONS,
  1269. 0,0,0,0,
  1270. _hwndSearch,
  1271. (HMENU) idHeader,
  1272. _hInst,
  1273. 0 );
  1274. _view.InitPanes ( _hwndQueryTitle,
  1275. _hwndQuery,
  1276. _hwndList,
  1277. _hwndHeader );
  1278. WCHAR awcDisplayProps[cwcBufSize];
  1279. ULONG cb = sizeof awcDisplayProps;
  1280. if ( !GetReg( CISEARCH_REG_DISPLAYPROPS, awcDisplayProps, &cb ) )
  1281. wcscpy( awcDisplayProps, DEFAULT_DISPLAYED_PROPERTIES );
  1282. SetupDisplayProps( awcDisplayProps );
  1283. PostMessage( _hwndSearch, wmGiveFocus, 0, 0 );
  1284. } //InitPanes
  1285. CSearchControl::~CSearchControl()
  1286. {
  1287. SetWindowLongPtr( _hwndSearch, 0, 0 );
  1288. delete _pSearch;
  1289. } //~CSearchControl
  1290. LRESULT CSearchControl::wmListNotify(
  1291. HWND hwnd,
  1292. WPARAM wParam,
  1293. LPARAM lParam )
  1294. {
  1295. if (!_pSearch)
  1296. {
  1297. *(long *)lParam = -1;
  1298. return LRESULT(FALSE);
  1299. }
  1300. BOOL f = (BOOL)_pSearch->ListNotify (hwnd, wParam, (long *)lParam);
  1301. static UINT aItem[] = { IDM_BROWSE };
  1302. UpdateButtons( aItem, 1, _pSearch->IsSelected() );
  1303. return (LRESULT) f;
  1304. } //wmListNotify
  1305. //
  1306. // Edit control procedure
  1307. //
  1308. LRESULT CSearchControl::EditSubclassEvent(
  1309. HWND hwnd,
  1310. UINT msg,
  1311. WPARAM wParam,
  1312. LPARAM lParam )
  1313. {
  1314. LRESULT lRet = 0;
  1315. switch (msg)
  1316. {
  1317. #if 0
  1318. case WM_KEYDOWN :
  1319. {
  1320. if ( VK_UP == wParam )
  1321. pwc = _history.Previous();
  1322. else if ( VK_DOWN == wParam )
  1323. pwc = _history.Next();
  1324. else
  1325. lRet = CallWindowProc( _lpOrgEditProc,
  1326. hwnd, msg, wParam, lParam );
  1327. if ( 0 != pwc )
  1328. {
  1329. SetWindowText( hwnd, pwc );
  1330. MySendEMSetSel( hwnd, 0, (UINT) -1 );
  1331. }
  1332. break;
  1333. }
  1334. #endif
  1335. case WM_KEYUP :
  1336. {
  1337. if ( VK_ESCAPE == wParam )
  1338. {
  1339. if ( SendMessage( _hwndQuery, CB_GETDROPPEDSTATE, 0, 0 ) )
  1340. {
  1341. SendMessage( _hwndQuery, CB_SHOWDROPDOWN, (WPARAM)FALSE, 0 );
  1342. }
  1343. }
  1344. lRet = CallWindowProc( _lpOrgEditProc, hwnd, msg, wParam, lParam );
  1345. break;
  1346. }
  1347. case WM_CHAR :
  1348. {
  1349. if ( VK_RETURN == wParam || 11 == wParam )
  1350. {
  1351. // Handle 'enter' only if combobox list is closed. If it is open,
  1352. // then we handle the selection message in wmCommand
  1353. if ( FALSE == SendMessage( _hwndQuery, CB_GETDROPPEDSTATE, 0, 0 ) )
  1354. {
  1355. SendMessage ( _hwndSearch,
  1356. ::wmMenuCommand,
  1357. IDM_SEARCH,
  1358. MAKELPARAM( 1, 0 ) );
  1359. // swallow cr/lf
  1360. break;
  1361. }
  1362. }
  1363. else
  1364. {
  1365. // Match the user entered string with the strings in the combobox
  1366. // list box...
  1367. lRet = CallWindowProc( _lpOrgEditProc, hwnd, msg, wParam, lParam );
  1368. UINT uiLen = GetWindowTextLength( hwnd );
  1369. if (0 != uiLen && VK_BACK != wParam )
  1370. {
  1371. XGrowable<WCHAR> xBuf;
  1372. xBuf.SetSize( uiLen + 1 );
  1373. GetWindowText( hwnd, xBuf.Get(), uiLen + 1 );
  1374. int index = (int)SendMessage( _hwndQuery, CB_FINDSTRING, -1, (LPARAM) xBuf.Get() );
  1375. if ( CB_ERR != index)
  1376. {
  1377. unsigned uiFullLen = (unsigned)SendMessage( _hwndQuery, CB_GETLBTEXTLEN, index, 0 );
  1378. xBuf.SetSize( uiFullLen + 1 );
  1379. if ( CB_ERR != SendMessage( _hwndQuery,
  1380. CB_GETLBTEXT,
  1381. index,
  1382. (LPARAM) xBuf.Get() ) )
  1383. {
  1384. SetWindowText( hwnd, xBuf.Get() );
  1385. MySendEMSetSel( hwnd, uiLen, (UINT) -1 );
  1386. }
  1387. }
  1388. }
  1389. break;
  1390. }
  1391. // no break, fall through!
  1392. }
  1393. default :
  1394. lRet = CallWindowProc( _lpOrgEditProc, hwnd, msg, wParam, lParam );
  1395. break;
  1396. }
  1397. return lRet;
  1398. } //EditSubclassEvent
  1399. LRESULT CSearchControl::wmSize(
  1400. WPARAM wParam,
  1401. LPARAM lParam )
  1402. {
  1403. // no need to do this since User doesn't have the repaint bug with
  1404. // comboboxes that it does with edit controls
  1405. //if (_hwndQuery)
  1406. // InvalidateRect(_hwndQuery, 0, TRUE);
  1407. LRESULT lr = DefMDIChildProc(_hwndSearch, WM_SIZE, wParam, lParam);
  1408. if ( _hwndQuery )
  1409. _view.Size( LOWORD (lParam), HIWORD (lParam));
  1410. return lr;
  1411. } //wmSize
  1412. LRESULT CSearchControl::wmDisplaySubwindows(
  1413. WPARAM wParam,
  1414. LPARAM lParam )
  1415. {
  1416. ShowWindow(_hwndQuery,SW_SHOW);
  1417. ShowWindow(_hwndList,SW_SHOW);
  1418. ShowWindow(_hwndQueryTitle,SW_SHOW);
  1419. ShowWindow(_hwndHeader,SW_SHOW);
  1420. return 0;
  1421. } //wmDisplaySubwindows
  1422. LRESULT CSearchControl::wmContextMenu(
  1423. HWND hwnd,
  1424. WPARAM wParam,
  1425. LPARAM lParam )
  1426. {
  1427. POINT pt;
  1428. pt.x = LOWORD( lParam );
  1429. pt.y = HIWORD( lParam );
  1430. GetCursorPos( &pt );
  1431. RECT rc;
  1432. GetWindowRect( _hwndHeader, &rc );
  1433. WCHAR *pwcMenu = L"bogus";
  1434. // is the click over the properties header?
  1435. if ( PtInRect( &rc, pt ) )
  1436. {
  1437. pwcMenu = L"HeaderContextMenu";
  1438. }
  1439. else
  1440. {
  1441. // do hit testing on listview -- on a hit?
  1442. int iHit = (int) SendMessage( _hwndList,
  1443. wmContextMenuHitTest,
  1444. 0,
  1445. MAKELPARAM( pt.x, pt.y ) );
  1446. if ( -1 != iHit )
  1447. pwcMenu = L"ResultsContextMenu";
  1448. }
  1449. HMENU hMenu = LoadMenu( App.Instance(), pwcMenu );
  1450. if ( 0 != hMenu )
  1451. {
  1452. HMENU hTrackMenu = GetSubMenu( hMenu, 0 );
  1453. if ( 0 != hTrackMenu )
  1454. {
  1455. if ( !wcscmp( pwcMenu, L"ResultsContextMenu" ) )
  1456. SetMenuDefaultItem( hTrackMenu, IDM_BROWSE, FALSE );
  1457. // yes, the function returns a BOOL that you switch on
  1458. BOOL b = TrackPopupMenuEx( hTrackMenu,
  1459. TPM_LEFTALIGN | TPM_RIGHTBUTTON |
  1460. TPM_RETURNCMD,
  1461. pt.x,
  1462. pt.y,
  1463. hwnd,
  1464. 0 );
  1465. switch ( b )
  1466. {
  1467. case IDM_EDITCOPY :
  1468. case IDM_EDITCOPYALL :
  1469. case IDM_DISPLAY_PROPS :
  1470. {
  1471. wmMenuCommand( b, 0 );
  1472. break;
  1473. }
  1474. case IDM_BROWSE :
  1475. {
  1476. _DoBrowse( fileBrowse );
  1477. break;
  1478. }
  1479. case IDM_BROWSE_OPEN :
  1480. {
  1481. _DoBrowse( fileOpen );
  1482. break;
  1483. }
  1484. case IDM_BROWSE_EDIT :
  1485. {
  1486. _DoBrowse( fileEdit );
  1487. break;
  1488. }
  1489. }
  1490. }
  1491. DestroyMenu( hMenu );
  1492. }
  1493. return 0;
  1494. } //wmContextMenu
  1495. void CSearchControl::_DoBrowse(
  1496. enumViewFile eViewType )
  1497. {
  1498. if (_pSearch)
  1499. {
  1500. CWaitCursor curWait;
  1501. TRY
  1502. {
  1503. BOOL fIsZoomed = IsZoomed( _hwndSearch );
  1504. BOOL fOK = _pSearch->Browse( eViewType );
  1505. if ( !fOK && fIsZoomed )
  1506. {
  1507. App.ZoomMDI( _hwndSearch );
  1508. InvalidateRect( _hwndSearch, NULL, TRUE );
  1509. }
  1510. }
  1511. CATCH (CException, e)
  1512. {
  1513. }
  1514. END_CATCH;
  1515. }
  1516. } //_DoBrowse
  1517. LRESULT CSearchControl::wmCommand(
  1518. WPARAM wParam,
  1519. LPARAM lParam )
  1520. {
  1521. UINT uiID = MyWmCommandID( wParam, lParam );
  1522. HWND hCtl = MyWmCommandHWnd( wParam, lParam );
  1523. UINT uiCmd = MyWmCommandCmd( wParam, lParam );
  1524. switch (uiID)
  1525. {
  1526. case idQueryChild :
  1527. switch (uiCmd)
  1528. {
  1529. case CBN_SETFOCUS:
  1530. _hLastToHaveFocus = _hwndQuery;
  1531. break;
  1532. case CBN_SELENDOK :
  1533. PostMessage ( _hwndSearch,
  1534. ::wmMenuCommand,
  1535. IDM_SEARCH,
  1536. MAKELPARAM( 1, 0 ) );
  1537. break;
  1538. case CBN_DROPDOWN:
  1539. // This list is getting dropped
  1540. // Set its size
  1541. _view.ResizeQueryCB();
  1542. break;
  1543. }
  1544. break;
  1545. case idListChild :
  1546. switch (uiCmd)
  1547. {
  1548. case LBN_SETFOCUS :
  1549. _hLastToHaveFocus = _hwndList;
  1550. break;
  1551. case LBN_DBLCLK :
  1552. {
  1553. BOOL fCtrl = ( 0 != ( 0x8000 & GetAsyncKeyState( VK_CONTROL ) ) );
  1554. _DoBrowse( fCtrl ? fileOpen : fileBrowse );
  1555. break;
  1556. }
  1557. }
  1558. break;
  1559. }
  1560. return 0;
  1561. } //wmCommand
  1562. LRESULT CSearchControl::wmAccelerator(
  1563. WPARAM wParam,
  1564. LPARAM lParam)
  1565. {
  1566. switch (wParam)
  1567. {
  1568. case ACC_ALTQ :
  1569. SetFocus(_hwndQuery);
  1570. break;
  1571. case ACC_ALTR :
  1572. SetFocus(_hwndList);
  1573. break;
  1574. case ACC_TAB :
  1575. case ACC_SHIFTTAB :
  1576. if (_hLastToHaveFocus == _hwndQuery)
  1577. SetFocus(_hwndList);
  1578. else
  1579. SetFocus(_hwndQuery);
  1580. break;
  1581. }
  1582. return 0;
  1583. } //wmAccelerator
  1584. LRESULT CSearchControl::wmNewFont(
  1585. WPARAM wParam,
  1586. LPARAM lParam)
  1587. {
  1588. HFONT hfontNew = (HFONT) wParam;
  1589. _view.FontChanged (hfontNew);
  1590. WCHAR awcDisplayProps[cwcBufSize];
  1591. ULONG cb = sizeof awcDisplayProps;
  1592. if ( !GetReg( CISEARCH_REG_DISPLAYPROPS, awcDisplayProps, &cb ) )
  1593. wcscpy( awcDisplayProps, DEFAULT_DISPLAYED_PROPERTIES );
  1594. SetupDisplayProps( awcDisplayProps );
  1595. SendMessage( _hwndList, WM_SETFONT, (WPARAM) hfontNew, 1L );
  1596. SendMessage( _hwndQuery, WM_SETFONT, (WPARAM) hfontNew, 1L );
  1597. RECT rc;
  1598. GetClientRect( _hwndSearch, &rc );
  1599. _view.Size( rc.right - rc.left, rc.bottom - rc.top );
  1600. return 0;
  1601. } //wmNewFont
  1602. LRESULT CSearchControl::wmDrawItem(
  1603. WPARAM wParam,
  1604. LPARAM lParam)
  1605. {
  1606. LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT) lParam;
  1607. if (lpdis->hwndItem == _hwndList)
  1608. {
  1609. if (lpdis->itemID == (UINT) -1)
  1610. lpdis->itemAction = ODA_FOCUS;
  1611. if ( lpdis->itemAction & ODA_DRAWENTIRE )
  1612. {
  1613. if ( _pSearch && _pSearch->IsSelected( lpdis->itemID ) )
  1614. lpdis->itemState |= ODS_SELECTED;
  1615. RECT rc;
  1616. _view.PrimeItem( lpdis, rc );
  1617. //if ( lpdis->itemState & ( ODS_SELECTED | ODS_FOCUS ) )
  1618. // DrawFocusRect( lpdis->hDC, &rc );
  1619. if ( 0 != _pSearch )
  1620. _view.PaintItem( _pSearch,
  1621. lpdis->hDC,
  1622. rc,
  1623. lpdis->itemID );
  1624. }
  1625. }
  1626. return 1;
  1627. } //wmDrawItem
  1628. LRESULT CSearchControl::wmAppClosing(
  1629. WPARAM wParam,
  1630. LPARAM lParam )
  1631. {
  1632. SendMessage( _hwndSearch, ::wmMenuCommand, IDM_NEWSEARCH, 0 );
  1633. return 0;
  1634. } //wmAppClosing
  1635. void CSearchControl::ResetTitle()
  1636. {
  1637. SScopeCatalogMachine scm;
  1638. XGrowable<WCHAR> xTitle;
  1639. xTitle.SetSize( wcslen(_xCatList.Get()) + 50 );
  1640. xTitle[0] = 0;
  1641. unsigned ii;
  1642. for ( ii = 0; ; ii++ )
  1643. {
  1644. if ( ! GetCatListItem( _xCatList,
  1645. ii,
  1646. scm.awcMachine,
  1647. scm.awcCatalog,
  1648. scm.awcScope,
  1649. scm.fDeep ) )
  1650. {
  1651. break;
  1652. }
  1653. if ( ii > 0 )
  1654. {
  1655. wcscat( xTitle.Get(), L", " );
  1656. }
  1657. if ( scm.awcMachine[0] != L'.' )
  1658. {
  1659. wcscat( xTitle.Get(), scm.awcMachine );
  1660. wcscat( xTitle.Get(), L" " );
  1661. }
  1662. wcscat( xTitle.Get(), scm.awcCatalog );
  1663. wcscat( xTitle.Get(), L" " );
  1664. wcscat( xTitle.Get(), scm.awcScope );
  1665. }
  1666. SetWindowText( _hwndSearch, xTitle.Get() );
  1667. } //ResetTitle
  1668. //+-------------------------------------------------------------------------
  1669. //
  1670. // Function: MyForceMasterMerge
  1671. //
  1672. // Synopsis: Forces a master merge on the catalog
  1673. //
  1674. // Arguments: [pwcCatalog] - Catalog name
  1675. // [pwcMachine] - Machine on which catalog resides
  1676. //
  1677. //--------------------------------------------------------------------------
  1678. HRESULT MyForceMasterMerge(
  1679. WCHAR const * pwcCatalog,
  1680. WCHAR const * pwcMachine )
  1681. {
  1682. // Create the main Indexing Service administration object.
  1683. CLSID clsid;
  1684. HRESULT hr = CLSIDFromProgID( L"Microsoft.ISAdm", &clsid );
  1685. if ( FAILED( hr ) )
  1686. return hr;
  1687. XInterface<IAdminIndexServer> xAdmin;
  1688. hr = CoCreateInstance( clsid,
  1689. 0,
  1690. CLSCTX_INPROC_SERVER,
  1691. __uuidof(IAdminIndexServer),
  1692. xAdmin.GetQIPointer() );
  1693. if ( FAILED( hr ) )
  1694. return hr;
  1695. // Set the machine name.
  1696. BSTR bstrMachine = SysAllocString( pwcMachine );
  1697. if ( 0 == bstrMachine )
  1698. return E_OUTOFMEMORY;
  1699. XBStr xbstr( bstrMachine );
  1700. hr = xAdmin->put_MachineName( bstrMachine );
  1701. if ( FAILED( hr ) )
  1702. return hr;
  1703. // Get a catalog administration object.
  1704. BSTR bstrCatalog = SysAllocString( pwcCatalog );
  1705. if ( 0 == bstrCatalog )
  1706. return E_OUTOFMEMORY;
  1707. xbstr.Free();
  1708. xbstr.Set( bstrCatalog );
  1709. XInterface<ICatAdm> xCatAdmin;
  1710. hr = xAdmin->GetCatalogByName( bstrCatalog,
  1711. (IDispatch **) xCatAdmin.GetQIPointer() );
  1712. if ( FAILED( hr ) )
  1713. return hr;
  1714. // Force the merge.
  1715. return xCatAdmin->ForceMasterMerge();
  1716. } //MyForceMasterMerge
  1717. LRESULT CSearchControl::wmMenuCommand(
  1718. WPARAM wParam,
  1719. LPARAM lParam )
  1720. {
  1721. switch (wParam)
  1722. {
  1723. case IDM_EDITCOPY :
  1724. if ( ( 0 != _hwndList ) &&
  1725. ( _hwndList == GetFocus() ) &&
  1726. ( 0 != _pSearch ) &&
  1727. ( _pSearch->IsSelected() ) )
  1728. {
  1729. WCHAR *pwcPath;
  1730. HROW hrow;
  1731. if ( _pSearch->GetSelectedRowData( pwcPath, hrow ) )
  1732. {
  1733. PutInClipboard( pwcPath );
  1734. _pSearch->FreeSelectedRowData( hrow );
  1735. }
  1736. }
  1737. break;
  1738. case IDM_SCOPE_AND_DEPTH:
  1739. {
  1740. if ( DoModalDialog( ScopeDlgProc,
  1741. _hwndSearch,
  1742. L"ScopeBox",
  1743. (LPARAM) &_xCatList ) )
  1744. {
  1745. // Get the first cat list item
  1746. GetCatListItem( _xCatList, 0, _awcMachine, _awcCatalog, _awcScope, _fDeep );
  1747. SendMessage(_hwndSearch,
  1748. ::wmMenuCommand,
  1749. IDM_SEARCH,
  1750. MAKELPARAM (1,0));
  1751. }
  1752. break;
  1753. }
  1754. case IDM_DISPLAY_PROPS:
  1755. if ( DoModalDialog( DisplayPropsDlgProc,
  1756. _hwndSearch,
  1757. L"DisplayPropsBox",
  1758. (LPARAM) this ) )
  1759. {
  1760. SendMessage(_hwndSearch,
  1761. ::wmMenuCommand,
  1762. IDM_SEARCH,
  1763. MAKELPARAM (1,0));
  1764. }
  1765. break;
  1766. case IDM_EDITCOPYALL :
  1767. if (0 != _pSearch)
  1768. {
  1769. CWaitCursor curWait;
  1770. _pSearch->WriteResults();
  1771. }
  1772. break;
  1773. case IDM_BROWSE:
  1774. MyPostWmCommand(_hwndSearch, idListChild, _hwndSearch, LBN_DBLCLK);
  1775. break;
  1776. case IDM_LIMIT_10:
  1777. App.Limit() = 10;
  1778. SendMessage( _hwndSearch,
  1779. ::wmMenuCommand,
  1780. IDM_SEARCH,
  1781. MAKELPARAM( 1, 0 ) );
  1782. break;
  1783. case IDM_LIMIT_300:
  1784. App.Limit() = 300;
  1785. SendMessage( _hwndSearch,
  1786. ::wmMenuCommand,
  1787. IDM_SEARCH,
  1788. MAKELPARAM( 1, 0 ) );
  1789. break;
  1790. case IDM_LIMIT_NONE:
  1791. App.Limit() = 0;
  1792. SendMessage( _hwndSearch,
  1793. ::wmMenuCommand,
  1794. IDM_SEARCH,
  1795. MAKELPARAM( 1, 0 ) );
  1796. break;
  1797. case IDM_FIRSTROWS_5:
  1798. App.FirstRows() = 5;
  1799. SendMessage( _hwndSearch,
  1800. ::wmMenuCommand,
  1801. IDM_SEARCH,
  1802. MAKELPARAM( 1, 0 ) );
  1803. break;
  1804. case IDM_FIRSTROWS_15:
  1805. App.FirstRows() = 15;
  1806. SendMessage( _hwndSearch,
  1807. ::wmMenuCommand,
  1808. IDM_SEARCH,
  1809. MAKELPARAM( 1, 0 ) );
  1810. break;
  1811. case IDM_FIRSTROWS_NONE:
  1812. App.FirstRows() = 0;
  1813. SendMessage( _hwndSearch,
  1814. ::wmMenuCommand,
  1815. IDM_SEARCH,
  1816. MAKELPARAM( 1, 0 ) );
  1817. break;
  1818. case IDM_DIALECT_1:
  1819. case IDM_DIALECT_2:
  1820. if ( wParam == IDM_DIALECT_1 )
  1821. App.Dialect() = ISQLANG_V1;
  1822. else
  1823. App.Dialect() = ISQLANG_V2;
  1824. break;
  1825. case IDM_DIALECT_3:
  1826. App.Dialect() = SQLTEXT;
  1827. break;
  1828. case IDM_LOCALE_NEUTRAL:
  1829. case IDM_LOCALE_CHINESE_TRADITIONAL:
  1830. case IDM_LOCALE_CHINESE_SIMPLIFIED:
  1831. case IDM_LOCALE_CHINESE_HONGKONG:
  1832. case IDM_LOCALE_CHINESE_SINGAPORE:
  1833. case IDM_LOCALE_CHINESE_MACAU:
  1834. case IDM_LOCALE_DUTCH_DUTCH:
  1835. case IDM_LOCALE_ENGLISH_CAN:
  1836. case IDM_LOCALE_ENGLISH_US:
  1837. case IDM_LOCALE_ENGLISH_UK:
  1838. case IDM_LOCALE_FINNISH_DEFAULT:
  1839. case IDM_LOCALE_FARSI_DEFAULT:
  1840. case IDM_LOCALE_FRENCH_FRENCH:
  1841. case IDM_LOCALE_FRENCH_CANADIAN:
  1842. case IDM_LOCALE_GERMAN_GERMAN:
  1843. case IDM_LOCALE_GREEK_DEFAULT:
  1844. case IDM_LOCALE_HEBREW_DEFAULT:
  1845. case IDM_LOCALE_HINDI_DEFAULT:
  1846. case IDM_LOCALE_ITALIAN_ITALIAN:
  1847. case IDM_LOCALE_JAPANESE_DEFAULT:
  1848. case IDM_LOCALE_KOREAN_KOREAN:
  1849. // case IDM_LOCALE_KOREAN_JOHAB:
  1850. case IDM_LOCALE_POLISH_DEFAULT:
  1851. case IDM_LOCALE_ROMANIAN_DEFAULT:
  1852. case IDM_LOCALE_RUSSIAN_DEFAULT:
  1853. case IDM_LOCALE_SPANISH_CASTILIAN:
  1854. case IDM_LOCALE_SPANISH_MEXICAN:
  1855. case IDM_LOCALE_SPANISH_MODERN:
  1856. case IDM_LOCALE_SWAHILI_DEFAULT:
  1857. case IDM_LOCALE_SWEDISH_DEFAULT:
  1858. case IDM_LOCALE_THAI_DEFAULT:
  1859. case IDM_LOCALE_TURKISH_DEFAULT:
  1860. case IDM_LOCALE_UKRAINIAN_DEFAULT:
  1861. case IDM_LOCALE_VIETNAMESE_DEFAULT:
  1862. {
  1863. for ( ULONG i = 0; i < cLocaleEntries; i++ )
  1864. {
  1865. if ( wParam == aLocaleEntries[ i ].iMenuOption )
  1866. {
  1867. _lcid = aLocaleEntries[ i ].lcid;
  1868. App.SetLocale( _lcid );
  1869. break;
  1870. }
  1871. }
  1872. break;
  1873. }
  1874. case IDM_FORCE_USE_CI :
  1875. {
  1876. BOOL fTmp = App.ForceUseCI();
  1877. App.ForceUseCI() = !fTmp;
  1878. break;
  1879. }
  1880. case IDM_CATALOG_STATUS:
  1881. // what about distributed queries? They aren't supported
  1882. CreateDialogParam( _hInst,
  1883. L"CatalogStatusBox",
  1884. App.AppWindow(),
  1885. StatusDlgProc,
  1886. (LPARAM) this );
  1887. break;
  1888. case IDM_MASTER_MERGE:
  1889. {
  1890. // what about distributed queries?
  1891. SCODE sc = MyForceMasterMerge( CatalogOrNull(),
  1892. Machine() );
  1893. if ( FAILED( sc ) )
  1894. {
  1895. WCHAR awcError[MAX_PATH];
  1896. FormatSrchError( sc, awcError, _lcid );
  1897. MessageBox( _hwndSearch,
  1898. awcError,
  1899. _awcScope,
  1900. MB_OK|MB_ICONEXCLAMATION );
  1901. }
  1902. break;
  1903. }
  1904. case IDM_SEARCH :
  1905. case IDM_SEARCHCLASSDEF :
  1906. case IDM_SEARCHFUNCDEF :
  1907. {
  1908. CWaitCursor curWait;
  1909. // Scope change invokes a new query, so make sure title bar is ok
  1910. ResetTitle();
  1911. CSearchQuery *ptmp = _pSearch;
  1912. _pSearch = 0;
  1913. // Let the user know we're doing something
  1914. {
  1915. CResString strHitCount(IDS_COUNTEND);
  1916. _UpdateStatusWindow( strHitCount.Get(), L"" );
  1917. UpdateWindow( App.StatusBarWindow() );
  1918. }
  1919. SendMessage( _hwndList, wmResetContents, 0, 0 );
  1920. delete ptmp;
  1921. static UINT aItem[] = { IDM_BROWSE };
  1922. UpdateButtons( aItem, 1, FALSE );
  1923. // Let the user know we're doing something
  1924. {
  1925. CResString strHitCount(IDS_COUNTSTART);
  1926. _UpdateStatusWindow( strHitCount.Get(), L"" );
  1927. UpdateWindow( App.StatusBarWindow() );
  1928. }
  1929. HWND hEdit = FindWindowEx( _hwndQuery, 0, L"EDIT", 0 );
  1930. UINT uiLen = GetWindowTextLength(hEdit);
  1931. if (0 == uiLen)
  1932. {
  1933. CResString strCount (IDS_COUNTTITLE);
  1934. SendMessage( App.StatusBarWindow(), SB_SETTEXT, idStatusMsg, (LPARAM) strCount.Get() );
  1935. }
  1936. else
  1937. {
  1938. WCHAR * pwcBuf = new WCHAR [uiLen + 1];
  1939. TRY
  1940. {
  1941. GetWindowText (hEdit, pwcBuf, uiLen + 1);
  1942. ESearchType st = srchNormal;
  1943. if (IDM_SEARCHCLASSDEF == wParam)
  1944. st = srchClass;
  1945. else if (IDM_SEARCHFUNCDEF == wParam)
  1946. st = srchFunction;
  1947. //----------
  1948. // NEW QUERY
  1949. //----------
  1950. _pSearch = new CSearchQuery( _xCatList,
  1951. pwcBuf,
  1952. _hwndSearch,
  1953. _view.Lines(),
  1954. _lcid,
  1955. st,
  1956. _xColumnMapper.GetReference(),
  1957. _columns,
  1958. _sort,
  1959. App.Dialect(),
  1960. App.Limit(),
  1961. App.FirstRows() );
  1962. _pSearch->InitNotifications(_hwndList);
  1963. // Scope may have changed if server was down
  1964. ResetTitle();
  1965. // Let the user know we're doing something
  1966. {
  1967. WCHAR awcCount[100];
  1968. CResString strHitCount(IDS_HITCOUNT);
  1969. swprintf( awcCount, strHitCount.Get(), 0, 0.0f );
  1970. SendMessage( App.StatusBarWindow(), SB_SETTEXT, SBT_OWNERDRAW | idStatusRatio, 0 );
  1971. SendMessage( App.StatusBarWindow(), SB_SETTEXT, idStatusMsg, (LPARAM) awcCount );
  1972. UpdateWindow( App.StatusBarWindow() );
  1973. }
  1974. MySendEMSetSel( hEdit, 0, (UINT) -1 );
  1975. if ( CB_ERR == SendMessage( _hwndQuery, CB_FINDSTRINGEXACT, -1, (LPARAM) pwcBuf ) )
  1976. {
  1977. SendMessage( _hwndQuery, CB_INSERTSTRING, 0, (LPARAM) pwcBuf );
  1978. }
  1979. //_history.Add( pwcBuf );
  1980. delete [] pwcBuf;
  1981. pwcBuf = 0;
  1982. }
  1983. CATCH (CException, e )
  1984. {
  1985. SCODE sc = e.GetErrorCode();
  1986. if ( 0 == _pSearch )
  1987. {
  1988. // check for version mismatch, otherwise just report
  1989. // the error
  1990. if ( STATUS_INVALID_PARAMETER_MIX == sc )
  1991. {
  1992. SearchError( _hwndSearch,
  1993. IDS_ERR_BAD_VERSION,
  1994. _awcScope );
  1995. }
  1996. else // if ( QUERY_E_ALLNOISE != sc )
  1997. {
  1998. WCHAR awcError[MAX_PATH];
  1999. FormatSrchError( sc, awcError, _lcid );
  2000. CResString strErr( IDS_ERR_QUERY_ERROR );
  2001. WCHAR awcMsg[MAX_PATH];
  2002. swprintf( awcMsg, strErr.Get(), awcError );
  2003. MessageBox( _hwndSearch,
  2004. awcMsg,
  2005. _awcScope,
  2006. MB_OK|MB_ICONEXCLAMATION );
  2007. }
  2008. }
  2009. else
  2010. {
  2011. delete _pSearch;
  2012. _pSearch = 0;
  2013. }
  2014. delete [] pwcBuf;
  2015. CResString strCount (IDS_COUNTTITLE);
  2016. SendMessage( App.StatusBarWindow(), SB_SETTEXT,
  2017. idStatusMsg, (LPARAM) strCount.Get() );
  2018. }
  2019. END_CATCH;
  2020. }
  2021. }
  2022. break;
  2023. case IDM_NEWSEARCH :
  2024. {
  2025. CWaitCursor curWait;
  2026. CSearchQuery *ptmp = _pSearch;
  2027. _pSearch = 0;
  2028. // Let the user know we're doing something
  2029. {
  2030. CResString strHitCount(IDS_COUNTEND);
  2031. _UpdateStatusWindow( strHitCount.Get(), L"" );
  2032. UpdateWindow( App.StatusBarWindow() );
  2033. }
  2034. delete ptmp;
  2035. static UINT aItem[] = { IDM_BROWSE };
  2036. UpdateButtons( aItem, 1, FALSE );
  2037. ResetTitle();
  2038. CResString strCount (IDS_COUNTTITLE);
  2039. _UpdateStatusWindow( strCount.Get(), L"" );
  2040. SetWindowText( _hwndQuery, L"") ;
  2041. SendMessage( _hwndList, wmResetContents, 0, 0 );
  2042. SetFocus( _hwndQuery );
  2043. }
  2044. break;
  2045. }
  2046. return 0;
  2047. } //wmMenuCommand
  2048. LRESULT CSearchControl::wmSetFocus(
  2049. WPARAM wParam,
  2050. LPARAM lParam )
  2051. {
  2052. if (0 != _hLastToHaveFocus)
  2053. SetFocus(_hLastToHaveFocus);
  2054. return 0;
  2055. } //wmSetFocus
  2056. LRESULT CSearchControl::wmClose(
  2057. WPARAM wParam,
  2058. LPARAM lParam )
  2059. {
  2060. SendMessage( _hwndSearch, ::wmMenuCommand, IDM_NEWSEARCH, 0 );
  2061. return 0;
  2062. } //wmClose
  2063. void _CheckReliability(
  2064. DWORD dwStatus,
  2065. DWORD bit,
  2066. UINT msg,
  2067. WCHAR * pwcMsg )
  2068. {
  2069. if ( QUERY_RELIABILITY_STATUS( dwStatus ) & bit )
  2070. {
  2071. CResString str( msg );
  2072. if ( 0 != pwcMsg[ 0 ] )
  2073. wcscat( pwcMsg, L" / " );
  2074. wcscat( pwcMsg, str.Get() );
  2075. }
  2076. } //_CheckReliability
  2077. void CSearchControl::_UpdateCount()
  2078. {
  2079. if ( _hwndSearch == App.GetActiveMDI() )
  2080. {
  2081. WCHAR awcCount[200];
  2082. CResString strHitCount;
  2083. WCHAR awcReliability[MAX_PATH];
  2084. awcReliability[ 0 ] = 0;
  2085. DWORD dwStatus = 0;
  2086. if ( _pSearch )
  2087. {
  2088. strHitCount.Load( IDS_HITCOUNT );
  2089. swprintf( awcCount,
  2090. strHitCount.Get(),
  2091. _pSearch->RowCount(),
  2092. (float) _pSearch->QueryTime() );
  2093. dwStatus = _pSearch->QueryStatus();
  2094. if ( 0 != _pSearch->LastError() )
  2095. {
  2096. FormatSrchError( _pSearch->LastError(), awcReliability, _lcid );
  2097. }
  2098. else
  2099. {
  2100. _CheckReliability( dwStatus,
  2101. STAT_CONTENT_OUT_OF_DATE,
  2102. IDS_RELIABILITY_OUTOFDATE,
  2103. awcReliability );
  2104. _CheckReliability( dwStatus,
  2105. STAT_NOISE_WORDS,
  2106. IDS_RELIABILITY_NOISE,
  2107. awcReliability );
  2108. _CheckReliability( dwStatus,
  2109. STAT_PARTIAL_SCOPE,
  2110. IDS_RELIABILITY_PARTIAL,
  2111. awcReliability );
  2112. _CheckReliability( dwStatus,
  2113. STAT_REFRESH_INCOMPLETE,
  2114. IDS_RELIABILITY_REFRESH_INCOMPLETE,
  2115. awcReliability );
  2116. _CheckReliability( dwStatus,
  2117. STAT_CONTENT_QUERY_INCOMPLETE,
  2118. IDS_RELIABILITY_CONTENT_QUERY_INCOMPLETE,
  2119. awcReliability );
  2120. _CheckReliability( dwStatus,
  2121. STAT_TIME_LIMIT_EXCEEDED,
  2122. IDS_RELIABILITY_TIME_LIMIT_EXCEEDED,
  2123. awcReliability );
  2124. }
  2125. }
  2126. else
  2127. {
  2128. CResString strCount( IDS_COUNTTITLE );
  2129. wcscpy( awcCount, strCount.Get() );
  2130. }
  2131. _UpdateStatusWindow( awcCount, awcReliability );
  2132. UpdateWindow( App.StatusBarWindow() );
  2133. }
  2134. } //_UpdateCount
  2135. LRESULT CSearchControl::wmNotification(
  2136. WPARAM wParam,
  2137. LPARAM lParam)
  2138. {
  2139. if (0 != _pSearch)
  2140. {
  2141. _pSearch->ProcessNotification( _hwndList,
  2142. DBWATCHNOTIFY(wParam),
  2143. (IRowset*)lParam);
  2144. BOOL fMore;
  2145. _pSearch->UpdateProgress( fMore );
  2146. PostMessage( _hwndList, wmSetCountBefore, 0,
  2147. (LPARAM)_pSearch->RowCurrent() );
  2148. PostMessage( _hwndList, wmSetCount, 0,
  2149. (LPARAM)_pSearch->RowCount() );
  2150. _UpdateCount();
  2151. _pSearch->ProcessNotificationComplete();
  2152. }
  2153. return 0;
  2154. } //wmNotification
  2155. LRESULT CSearchControl::wmInitMenu(
  2156. WPARAM wParam,
  2157. LPARAM lParam)
  2158. {
  2159. HMENU hmenu = (HMENU) wParam;
  2160. for ( ULONG i = 0; i < cLocaleEntries; i++ )
  2161. {
  2162. DWORD option = aLocaleEntries[ i ].iMenuOption;
  2163. EnableMenuItem( hmenu, option, MF_ENABLED );
  2164. LCID lcid = aLocaleEntries[ i ].lcid;
  2165. CheckMenuItem( hmenu,
  2166. option,
  2167. _lcid == lcid ? MF_CHECKED : MF_UNCHECKED );
  2168. }
  2169. EnableMenuItem(hmenu,IDM_SEARCH,MF_ENABLED);
  2170. if ( SQLTEXT == App.Dialect() )
  2171. {
  2172. EnableMenuItem( hmenu, IDM_SEARCHCLASSDEF, MF_GRAYED );
  2173. EnableMenuItem( hmenu, IDM_SEARCHFUNCDEF, MF_GRAYED );
  2174. }
  2175. else
  2176. {
  2177. EnableMenuItem( hmenu, IDM_SEARCHCLASSDEF, MF_ENABLED );
  2178. EnableMenuItem( hmenu, IDM_SEARCHFUNCDEF, MF_ENABLED);
  2179. }
  2180. EnableMenuItem(hmenu,IDM_NEWSEARCH,MF_ENABLED);
  2181. EnableMenuItem(hmenu,IDM_SCOPE_AND_DEPTH,MF_ENABLED);
  2182. EnableMenuItem(hmenu,IDM_FILTER_SCOPE,MF_ENABLED);
  2183. EnableMenuItem(hmenu,IDM_DISPLAY_PROPS,MF_ENABLED);
  2184. EnableMenuItem(hmenu, IDM_FORCE_USE_CI, MF_ENABLED);
  2185. CheckMenuItem(hmenu, IDM_FORCE_USE_CI, App.ForceUseCI() ? MF_CHECKED : MF_UNCHECKED );
  2186. EnableMenuItem( hmenu, IDM_DIALECT_1, MF_ENABLED );
  2187. EnableMenuItem( hmenu, IDM_DIALECT_2, MF_ENABLED );
  2188. EnableMenuItem( hmenu, IDM_DIALECT_3, MF_ENABLED );
  2189. CheckMenuItem( hmenu, IDM_DIALECT_1, ISQLANG_V1 == App.Dialect() ? MF_CHECKED : MF_UNCHECKED );
  2190. CheckMenuItem( hmenu, IDM_DIALECT_2, ISQLANG_V2 == App.Dialect() ? MF_CHECKED : MF_UNCHECKED );
  2191. CheckMenuItem( hmenu, IDM_DIALECT_3, SQLTEXT == App.Dialect() ? MF_CHECKED : MF_UNCHECKED );
  2192. EnableMenuItem( hmenu, IDM_LIMIT_10, MF_ENABLED );
  2193. EnableMenuItem( hmenu, IDM_LIMIT_300, MF_ENABLED );
  2194. EnableMenuItem( hmenu, IDM_LIMIT_NONE, MF_ENABLED );
  2195. CheckMenuItem( hmenu, IDM_LIMIT_10, 10 == App.Limit() ? MF_CHECKED : MF_UNCHECKED );
  2196. CheckMenuItem( hmenu, IDM_LIMIT_300, 300 == App.Limit() ? MF_CHECKED : MF_UNCHECKED );
  2197. CheckMenuItem( hmenu, IDM_LIMIT_NONE, 0 == App.Limit() ? MF_CHECKED : MF_UNCHECKED );
  2198. EnableMenuItem( hmenu, IDM_FIRSTROWS_5, MF_ENABLED );
  2199. EnableMenuItem( hmenu, IDM_FIRSTROWS_15, MF_ENABLED );
  2200. EnableMenuItem( hmenu, IDM_FIRSTROWS_NONE, MF_ENABLED );
  2201. CheckMenuItem( hmenu, IDM_FIRSTROWS_5, 5 == App.FirstRows() ? MF_CHECKED : MF_UNCHECKED );
  2202. CheckMenuItem( hmenu, IDM_FIRSTROWS_15, 15 == App.FirstRows() ? MF_CHECKED : MF_UNCHECKED );
  2203. CheckMenuItem( hmenu, IDM_FIRSTROWS_NONE, 0 == App.FirstRows() ? MF_CHECKED : MF_UNCHECKED );
  2204. EnableMenuItem(hmenu,IDM_CATALOG_STATUS,MF_ENABLED);
  2205. EnableMenuItem(hmenu,IDM_MASTER_MERGE,MF_ENABLED);
  2206. if ( 0 != _hwndList && _hwndList == GetFocus() )
  2207. {
  2208. if (0 != _pSearch && _pSearch->IsSelected())
  2209. {
  2210. EnableMenuItem( hmenu, IDM_BROWSE, MF_ENABLED );
  2211. EnableMenuItem( hmenu, IDM_EDITCOPY, MF_ENABLED );
  2212. }
  2213. }
  2214. if ( 0 != _pSearch && 0 != _pSearch->RowCount() )
  2215. EnableMenuItem( hmenu, IDM_EDITCOPYALL, MF_ENABLED );
  2216. return 0;
  2217. } //wmInitMenu
  2218. LRESULT CSearchControl::wmMeasureItem(
  2219. WPARAM wParam,
  2220. LPARAM lParam)
  2221. {
  2222. MEASUREITEMSTRUCT* lpmis = (MEASUREITEMSTRUCT*) lParam;
  2223. if (lpmis->CtlType == odtListView)
  2224. lpmis->itemHeight = _view.GetLineHeight();
  2225. return 0;
  2226. } //wmMeasureItem
  2227. void SStatusDlg::SetCaption()
  2228. {
  2229. CResString str( IDS_STATUS_CAPTION );
  2230. WCHAR awc[ MAX_PATH + 100 ];
  2231. WCHAR *pwcCat = _CatalogOrNull();
  2232. WCHAR *pwcScope = _Scope();
  2233. WCHAR *pwcMachine = _Machine();
  2234. WCHAR awcM[ SRCH_COMPUTERNAME_LENGTH + 2 ];
  2235. if ( L'.' == *pwcMachine )
  2236. awcM[0] = 0;
  2237. else
  2238. {
  2239. awcM[0] = ' ';
  2240. wcscpy( awcM+1, pwcMachine );
  2241. }
  2242. wsprintf( awc, str.Get(), awcM, pwcCat ? pwcCat : pwcScope );
  2243. SetWindowText( _hdlg, awc );
  2244. } //SetCaption
  2245. const DWORD ALL_CI_MERGE = ( CI_STATE_SHADOW_MERGE |
  2246. CI_STATE_ANNEALING_MERGE |
  2247. CI_STATE_MASTER_MERGE |
  2248. CI_STATE_MASTER_MERGE_PAUSED );
  2249. void SStatusDlg::Update()
  2250. {
  2251. CI_STATE state;
  2252. RtlZeroMemory( &state, sizeof state );
  2253. state.cbStruct = sizeof state;
  2254. SCODE sc = CIState( _CatalogOrNull(),
  2255. _Machine(),
  2256. & state );
  2257. if ( SUCCEEDED( sc ) )
  2258. {
  2259. SetDlgItemInt( _hdlg, ID_STAT_FTF, state.cDocuments, FALSE );
  2260. SetDlgItemInt( _hdlg, ID_STAT_SECQ, state.cSecQDocuments, FALSE );
  2261. SetDlgItemInt( _hdlg, ID_STAT_FF, state.cFilteredDocuments, FALSE );
  2262. SetDlgItemInt( _hdlg, ID_STAT_FTE, state.cFreshTest, FALSE );
  2263. SetDlgItemInt( _hdlg, ID_STAT_WL, state.cWordList, FALSE );
  2264. SetDlgItemInt( _hdlg, ID_STAT_PI, state.cPersistentIndex, FALSE );
  2265. SetDlgItemInt( _hdlg, ID_STAT_KEYS, state.cUniqueKeys, FALSE );
  2266. SetDlgItemInt( _hdlg, ID_STAT_FILES, state.cTotalDocuments, FALSE );
  2267. SetDlgItemInt( _hdlg, ID_STAT_Q, state.cQueries, FALSE );
  2268. if ( 0 != ( state.eState & CI_STATE_SCANNING ) )
  2269. {
  2270. WCHAR awcTmp[50];
  2271. swprintf( awcTmp, L"%ws: %d", App.GetYes(), state.cPendingScans );
  2272. SetDlgItemText( _hdlg, ID_STAT_SCANNING, awcTmp );
  2273. }
  2274. else
  2275. {
  2276. SetDlgItemText( _hdlg, ID_STAT_SCANNING, App.GetNo() );
  2277. }
  2278. unsigned idStatus = IDS_CI_STATE_OK;
  2279. if ( 0 != ( state.eState & CI_STATE_RECOVERING ) )
  2280. idStatus = IDS_CI_STATE_RECOVER;
  2281. else if ( 0 != ( state.eState & CI_STATE_HIGH_IO ) )
  2282. idStatus = IDS_CI_STATE_HIIO;
  2283. else if ( 0 != ( state.eState & CI_STATE_LOW_MEMORY ) )
  2284. idStatus = IDS_CI_STATE_LOMEM;
  2285. else if ( 0 != ( state.eState & CI_STATE_BATTERY_POWER ) )
  2286. idStatus = IDS_CI_STATE_BATTERY;
  2287. else if ( 0 != ( state.eState & CI_STATE_READ_ONLY ) )
  2288. idStatus = IDS_CI_STATE_READ_ONLY;
  2289. else if ( 0 != ( state.eState & CI_STATE_USER_ACTIVE ) )
  2290. idStatus = IDS_CI_STATE_USER_ACTIVE;
  2291. else if ( 0 != ( state.eState & CI_STATE_STARTING ) )
  2292. idStatus = IDS_CI_STATE_STARTING;
  2293. else if ( 0 != ( state.eState & CI_STATE_READING_USNS ) )
  2294. idStatus = IDS_CI_STATE_READING_USNS;
  2295. {
  2296. CResString str( idStatus );
  2297. SetDlgItemText( _hdlg, ID_STAT_STATUS, str.Get() );
  2298. }
  2299. if ( 0 != ( state.eState & ALL_CI_MERGE ) )
  2300. {
  2301. unsigned idStr;
  2302. if ( state.eState & CI_STATE_SHADOW_MERGE )
  2303. idStr = IDS_MERGE_SHADOW;
  2304. else if ( state.eState & CI_STATE_ANNEALING_MERGE )
  2305. idStr = IDS_MERGE_ANNEALING;
  2306. else if ( state.eState & CI_STATE_MASTER_MERGE )
  2307. idStr = IDS_MERGE_MASTER;
  2308. else
  2309. idStr = IDS_MERGE_MASTER_PAUSED;
  2310. CResString str( idStr );
  2311. WCHAR awc[ cwcBufSize ];
  2312. swprintf( awc,
  2313. L"%ws %d%%",
  2314. str.Get(),
  2315. state.dwMergeProgress );
  2316. SetDlgItemText( _hdlg, ID_STAT_MT, awc );
  2317. }
  2318. else
  2319. {
  2320. SetDlgItemText( _hdlg, ID_STAT_MT, App.GetNo() );
  2321. }
  2322. }
  2323. else
  2324. {
  2325. WCHAR awcTmp[80];
  2326. swprintf( awcTmp, L"0x%x", sc );
  2327. //FormatSrchError( sc, awcTmp, App.GetLocale() );
  2328. SetDlgItemText( _hdlg, ID_STAT_STATUS, awcTmp );
  2329. SetDlgItemText( _hdlg, ID_STAT_FTF, L"" );
  2330. SetDlgItemText( _hdlg, ID_STAT_SECQ, L"" );
  2331. SetDlgItemText( _hdlg, ID_STAT_FF, L"" );
  2332. SetDlgItemText( _hdlg, ID_STAT_FTE, L"" );
  2333. SetDlgItemText( _hdlg, ID_STAT_WL, L"" );
  2334. SetDlgItemText( _hdlg, ID_STAT_PI, L"" );
  2335. SetDlgItemText( _hdlg, ID_STAT_KEYS, L"" );
  2336. SetDlgItemText( _hdlg, ID_STAT_FILES, L"" );
  2337. SetDlgItemText( _hdlg, ID_STAT_Q, L"" );
  2338. SetDlgItemText( _hdlg, ID_STAT_SCANNING, L"" );
  2339. SetDlgItemText( _hdlg, ID_STAT_MT, L"" );
  2340. }
  2341. } //Update
  2342. INT_PTR WINAPI StatusDlgProc(
  2343. HWND hdlg,
  2344. UINT msg,
  2345. WPARAM wParam,
  2346. LPARAM lParam )
  2347. {
  2348. BOOL fRet = FALSE;
  2349. SStatusDlg * pstat = (SStatusDlg *) GetWindowLongPtr( hdlg, DWLP_USER );
  2350. switch( msg )
  2351. {
  2352. case WM_INITDIALOG :
  2353. {
  2354. CSearchControl &ctrl = * (CSearchControl *) lParam;
  2355. pstat = new SStatusDlg( ctrl, hdlg );
  2356. SetWindowLongPtr( hdlg, DWLP_USER, (LONG_PTR) pstat );
  2357. fRet = TRUE;
  2358. SetTimer( hdlg, 2, 1000, 0);
  2359. int left,top,right,bottom;
  2360. if ( LoadWindowRect( &left,
  2361. &top,
  2362. &right,
  2363. &bottom,
  2364. CISEARCH_REG_STATUSPOSITION ) )
  2365. {
  2366. RECT rc;
  2367. GetWindowRect( hdlg,(LPRECT) &rc );
  2368. MoveWindow( hdlg,
  2369. left,
  2370. top,
  2371. rc.right - rc.left,
  2372. rc.bottom - rc.top,
  2373. FALSE );
  2374. }
  2375. pstat->SetCaption();
  2376. pstat->Update();
  2377. break;
  2378. }
  2379. case WM_ACTIVATE :
  2380. {
  2381. if ( 0 == wParam )
  2382. App.GetCurrentDialog() = 0;
  2383. else
  2384. App.GetCurrentDialog() = hdlg;
  2385. break;
  2386. }
  2387. case WM_TIMER :
  2388. {
  2389. if ( ! IsIconic( App.AppWindow() ) )
  2390. pstat->Update();
  2391. break;
  2392. }
  2393. case WM_DESTROY :
  2394. {
  2395. KillTimer( hdlg, 2 );
  2396. App.GetCurrentDialog() = 0;
  2397. SaveWindowRect( hdlg, CISEARCH_REG_STATUSPOSITION );
  2398. SetWindowLongPtr( hdlg, DWLP_USER, 0 );
  2399. delete pstat;
  2400. break;
  2401. }
  2402. case WM_COMMAND :
  2403. {
  2404. UINT uiID = MyWmCommandID( wParam, lParam );
  2405. switch( uiID )
  2406. {
  2407. case IDCANCEL :
  2408. {
  2409. DestroyWindow( hdlg );
  2410. fRet = TRUE;
  2411. break;
  2412. }
  2413. }
  2414. break;
  2415. }
  2416. }
  2417. return fRet;
  2418. } //StatusDlgProc