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.

713 lines
19 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1996 - 2000.
  5. //
  6. // File: srch.hxx
  7. //
  8. // Contents:
  9. //
  10. // History: 15 Aug 1996 DLee Created
  11. //
  12. //--------------------------------------------------------------------------
  13. #pragma once
  14. // private window messages
  15. const UINT wmSetState = WM_APP + 1;
  16. const UINT wmSetString = WM_APP + 2;
  17. const UINT wmAccelerator = WM_APP + 4;
  18. const UINT wmNewFont = WM_APP + 5;
  19. const UINT wmDisplaySubwindows = WM_APP + 6;
  20. const UINT wmMenuCommand = WM_APP + 7;
  21. const UINT wmGiveFocus = WM_APP + 8;
  22. const UINT wmCmndLine = WM_APP + 9;
  23. const UINT wmInitMenu = WM_APP + 10;
  24. const UINT wmUpdate = WM_APP + 11;
  25. const UINT wmResSetString = WM_APP + 12;
  26. const UINT wmAppClosing = WM_APP + 13;
  27. const UINT wmNotification = WM_APP + 14;
  28. const UINT wmOpenCatalog = WM_APP + 15;
  29. const UINT wmListNotify = WM_APP + 16;
  30. const UINT wmListFont = WM_APP + 17;
  31. const UINT wmDrawItem = WM_APP + 18;
  32. const UINT wmMeasureItem = WM_APP + 19;
  33. const UINT wmSetCountBefore = WM_APP + 20;
  34. const UINT wmSetCount = WM_APP + 21;
  35. const UINT wmResetContents = WM_APP + 22;
  36. const UINT wmInsertItem = WM_APP + 23;
  37. const UINT wmDeleteItem = WM_APP + 24;
  38. const UINT wmUpdateItem = WM_APP + 25;
  39. const UINT wmContextMenuHitTest = WM_APP + 26;
  40. const WPARAM listScrollLineUp = 1;
  41. const WPARAM listScrollLineDn = 2;
  42. const WPARAM listScrollPageUp = 3;
  43. const WPARAM listScrollPageDn = 4;
  44. const WPARAM listScrollTop = 5;
  45. const WPARAM listScrollBottom = 6;
  46. const WPARAM listScrollPos = 7;
  47. const WPARAM listSize = 8;
  48. const WPARAM listSelect = 9;
  49. const WPARAM listSelectUp = 10;
  50. const WPARAM listSelectDown = 11;
  51. const ULONG odtListView = 100;
  52. // window classes
  53. #define APP_CLASS L"SrchWClass"
  54. #define SEARCH_CLASS L"SrchSearchWClass"
  55. #define BROWSE_CLASS L"SrchBrowseWClass"
  56. #define LIST_VIEW_CLASS L"SrchListViewWClass"
  57. #define SORT_UP 0
  58. #define SORT_DOWN 1
  59. const unsigned cwcBufSize = 400;
  60. const unsigned maxBoundCols = 30;
  61. const unsigned cwcResBuf = 100;
  62. class CResString
  63. {
  64. public:
  65. CResString() { _awc[ 0 ] = 0; }
  66. inline CResString( UINT strIDS );
  67. inline BOOL Load( UINT strIDS );
  68. WCHAR* Get() { return _awc; }
  69. private:
  70. WCHAR _awc[ cwcResBuf ];
  71. };
  72. class CWaitCursor
  73. {
  74. public:
  75. CWaitCursor ()
  76. {
  77. _hcurOld = SetCursor(LoadCursor(NULL,IDC_WAIT));
  78. }
  79. ~CWaitCursor ()
  80. {
  81. SetCursor(_hcurOld);
  82. }
  83. private:
  84. HCURSOR _hcurOld;
  85. };
  86. // computer name lengths can be really big (server.redmond.corp.microsoft.com)
  87. #define SRCH_COMPUTERNAME_LENGTH MAX_PATH
  88. struct SScopeCatalogMachine
  89. {
  90. SScopeCatalogMachine()
  91. {
  92. *awcScope = 0;
  93. *awcCatalog = 0;
  94. *awcMachine = 0;
  95. fDeep = FALSE;
  96. }
  97. WCHAR awcScope[MAX_PATH];
  98. WCHAR awcCatalog[MAX_PATH];
  99. WCHAR awcMachine[SRCH_COMPUTERNAME_LENGTH + 1];
  100. BOOL fDeep;
  101. };
  102. // big global object for the app
  103. class CSearchApp
  104. {
  105. public:
  106. CSearchApp();
  107. ~CSearchApp ();
  108. void Init (HINSTANCE hInst,int nCmdShow,LPSTR pcCmdLine);
  109. void Shutdown( HINSTANCE hInst );
  110. int MessageLoop();
  111. LRESULT WndProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam);
  112. HINSTANCE Instance() { return _hInst; }
  113. NUMBERFMT & NumberFormat() { return _NumberFmt; }
  114. NUMBERFMT & NumberFormatFloat() { return _NumberFmtFloat; }
  115. HFONT AppFont() { return _hfontApp; }
  116. HFONT BrowseFont() { return _hfontBrowse; }
  117. HBRUSH BtnFaceBrush() { return _hbrushBtnFace; }
  118. HBRUSH BtnHiliteBrush() { return _hbrushBtnHilite; }
  119. HBRUSH HiliteBrush() { return _hbrushHilite; }
  120. HBRUSH WindowBrush() { return _hbrushWindow; }
  121. WCHAR * GetSortProp() { return _awcSort; }
  122. int & GetSortDir() { return _sortDir; }
  123. void SetLocale( LCID lcid ) { _lcid = lcid; }
  124. LCID GetLocale() { return _lcid; }
  125. HWND CreateBrowser(WCHAR const *pwcPath,LPARAM lp)
  126. { return _MakeMDI(pwcPath,BROWSE_CLASS,0, 0/*WS_VSCROLL */ ,lp); }
  127. HWND AppWindow() { return _hAppWnd; }
  128. HWND ToolBarWindow() { return _hToolBarWnd; }
  129. HWND StatusBarWindow() { return _hStatusBarWnd; }
  130. LOGFONT & BrowseLogFont() { return _lfBrowse; }
  131. HWND GetActiveMDI()
  132. { return (HWND) SendMessage(_hMDIClientWnd,WM_MDIGETACTIVE,0,0); }
  133. void ZoomMDI( HWND hwnd )
  134. { PostMessage(_hMDIClientWnd,WM_MDIMAXIMIZE,(WPARAM) hwnd,0); }
  135. WCHAR * GetTrue() { return _strTrue.Get(); }
  136. WCHAR * GetFalse() { return _strFalse.Get(); }
  137. WCHAR * GetAttrib() { return _strAttrib.Get(); }
  138. WCHAR * GetBlob() { return _strBlob.Get(); }
  139. WCHAR * GetYes() { return _strYes.Get(); }
  140. WCHAR * GetNo() { return _strNo.Get(); }
  141. XGrowable<WCHAR> CatalogList() const { return _xCatList; }
  142. ISimpleCommandCreator * GetCommandCreator() { return _xCmdCreator.GetPointer(); }
  143. HWND & GetCurrentDialog() { return _hdlgCurrent; }
  144. BOOL & ForceUseCI() { return _fForceUseCI; }
  145. ULONG & Dialect() { return _ulDialect; }
  146. ULONG & Limit() { return _ulLimit; }
  147. ULONG & FirstRows() { return _ulFirstRows; }
  148. SCODE & BrowseLastError() { return _scBrowseLastError; }
  149. private:
  150. HWND _MakeMDI(WCHAR const * pwcTitle,WCHAR * pwcClass,UINT uiState,
  151. DWORD dwFlags,LPARAM lpCreate);
  152. int _CountMDIChildren();
  153. int _CountMDISearch();
  154. LRESULT _SendToMDIChildren(UINT msg,WPARAM wParam,LPARAM lParam);
  155. LRESULT _SendToSpecificChildren(WCHAR *pwcClass,UINT msg,WPARAM wParam,LPARAM lParam);
  156. LRESULT _SendToActiveMDI(UINT msg,WPARAM wParam,LPARAM lParam);
  157. int _SaveWindowState(BOOL bApp);
  158. void _SizeMDIAndBars(BOOL fMove,int iDX,int iDY);
  159. void _SaveProfileData();
  160. void _ReadDefaultFonts();
  161. void _GetPaths();
  162. void _InitInstance(LPSTR pcCmdLine);
  163. void _InitApplication();
  164. void _CreateFonts();
  165. void _UnMarshallFont(LOGFONT &lf,WCHAR *pwcFont,WCHAR *pwcRegEntry);
  166. void _MarshallFont(LOGFONT &lf,WCHAR *pwcOriginal,WCHAR *pwcRegEntry);
  167. void _ShowHelp(UINT uiID,DWORD dw);
  168. HINSTANCE _hInst;
  169. HWND _hMDIClientWnd;
  170. HWND _hAppWnd;
  171. HWND _hStatusBarWnd;
  172. HWND _hToolBarWnd;
  173. HWND _hdlgCurrent;
  174. HACCEL _hAccTable;
  175. HBRUSH _hbrushBtnFace;
  176. HBRUSH _hbrushBtnHilite;
  177. HBRUSH _hbrushHilite;
  178. HBRUSH _hbrushWindow;
  179. NUMBERFMT _NumberFmt;
  180. NUMBERFMT _NumberFmtFloat;
  181. HFONT _hfontApp;
  182. HFONT _hfontBrowse;
  183. BOOL _fHelp;
  184. int _iAppCmdShow;
  185. int _iStartupState,_iMDIStartupState;
  186. WCHAR _awcAppFont[MAX_PATH],_awcBrowseFont[MAX_PATH];
  187. LOGFONT _lfApp,_lfBrowse;
  188. WCHAR _awcAppPath[MAX_PATH];
  189. WCHAR _awcHelpFile[MAX_PATH];
  190. SCODE _scBrowseLastError;
  191. XGrowable<WCHAR> _xCatList;
  192. WCHAR _awcSort[MAX_PATH];
  193. int _sortDir;
  194. LCID _lcid; // locale id for query
  195. BOOL _fToolBarOn;
  196. BOOL _fStatusBarOn;
  197. BOOL _fForceUseCI;
  198. ULONG _ulDialect; // tripolish version 1 or 2 or SQL
  199. ULONG _ulLimit; // CiMaxRecordsInResultSet
  200. ULONG _ulFirstRows;
  201. WCHAR _awcSortINI[MAX_PATH];
  202. int _sortDirINI;
  203. LCID _lcidINI;
  204. BOOL _fToolBarOnINI;
  205. BOOL _fStatusBarOnINI;
  206. BOOL _fForceUseCIINI;
  207. ULONG _ulDialectINI;
  208. ULONG _ulLimitINI;
  209. ULONG _ulFirstRowsINI;
  210. CResString _strTrue;
  211. CResString _strFalse;
  212. CResString _strAttrib;
  213. CResString _strBlob;
  214. CResString _strYes;
  215. CResString _strNo;
  216. XInterface<ISimpleCommandCreator> _xCmdCreator;
  217. };
  218. // whomping global state data
  219. extern CSearchApp App;
  220. inline CResString::CResString( UINT strIDS )
  221. {
  222. _awc[ 0 ] = 0;
  223. LoadString( App.Instance(),
  224. strIDS,
  225. _awc,
  226. sizeof _awc / sizeof WCHAR );
  227. }
  228. inline BOOL CResString::Load( UINT strIDS )
  229. {
  230. _awc[ 0 ] = 0;
  231. LoadString( App.Instance(),
  232. strIDS,
  233. _awc,
  234. sizeof _awc / sizeof WCHAR );
  235. return ( 0 != _awc[ 0 ] );
  236. }
  237. // name of the helpfile
  238. #define CISEARCH_HELPFILE L"srch.chm"
  239. // registry entry names
  240. #define CISEARCH_PARENT_REG_KEY L"software\\microsoft"
  241. #define CISEARCH_REG_SUBKEY L"CI Search"
  242. #define CISEARCH_REG_TOOLBAR L"Show Icon bar"
  243. #define CISEARCH_REG_STATUSBAR L"Show Status bar"
  244. #define CISEARCH_REG_POSITION L"Position"
  245. #define CISEARCH_REG_STATUSPOSITION L"Status Position"
  246. #define CISEARCH_REG_FONT L"Results Font"
  247. #define CISEARCH_REG_SORTPROP L"Sort property"
  248. #define CISEARCH_REG_SORTDIR L"Sort direction"
  249. #define CISEARCH_REG_LOCALE L"Locale Id"
  250. #define CISEARCH_REG_BROWSEFONT L"Browse Font"
  251. #define CISEARCH_REG_BROWSE L"Browse tool"
  252. #define CISEARCH_REG_BROWSESTRIP L"Browse strip"
  253. #define CISEARCH_REG_DISPLAYPROPS L"Displayed properties"
  254. #define CISEARCH_REG_FORCEUSECI L"Force use CI"
  255. #define CISEARCH_REG_EDITOR L"Editor"
  256. #define CISEARCH_REG_DIALECT L"Dialect"
  257. #define CISEARCH_REG_LIMIT L"Limit"
  258. #define CISEARCH_REG_FIRSTROWS L"FirstRows"
  259. // built-in browser options
  260. #define BROWSER L"browse"
  261. #define BROWSER_SLICK L"s %ws"
  262. #define BROWSER_SLICK_SEARCH L"s %ws -#/%ws/"
  263. #define DEFAULT_DISPLAYED_PROPERTIES L"Size,Write,Path"
  264. #define DEFAULT_SORT_PROPERTIES L"Path"
  265. // T must be based on a basic type
  266. template<class T> BOOL isOdd(T value) { return 0 != (value & 1); }
  267. // srch.cxx
  268. INT_PTR WINAPI BrowseToolDlgProc(HWND hdlg,UINT msg,WPARAM wParam,LPARAM lParam);
  269. // toolbar.cxx
  270. HWND CreateTBar( HWND hParent, HINSTANCE hInstance );
  271. LRESULT ToolBarNotify( HWND hwnd, UINT uMessage, WPARAM wparam,
  272. LPARAM lparam, HINSTANCE hInst );
  273. void UpdateButtons( UINT *aid, UINT cid, BOOL fEnabled );
  274. // srchwnd.cxx
  275. LRESULT WINAPI SearchWndProc(HWND,UINT,WPARAM,LPARAM);
  276. INT_PTR WINAPI ScopeDlgProc(HWND hdlg,UINT msg,WPARAM wParam,LPARAM lParam);
  277. INT_PTR WINAPI FilterScopeDlgProc(HWND hdlg,UINT msg,WPARAM wParam,LPARAM lParam);
  278. INT_PTR WINAPI StatusDlgProc(HWND hdlg,UINT msg,WPARAM wParam,LPARAM lParam);
  279. // brcrtl.cxx
  280. LRESULT WINAPI BrowseWndProc(HWND,UINT,WPARAM,LPARAM);
  281. // lview.cxx
  282. LRESULT WINAPI ListViewWndProc(HWND,UINT,WPARAM,LPARAM);
  283. // srchutil.cxx
  284. void FormatSrchError( SCODE sc, WCHAR * pwc, LCID lcid );
  285. void SearchError(HWND hParent,ULONG dwErrorID,WCHAR const *pwcTitle);
  286. void SetReg(WCHAR const *pwcName,WCHAR const *pwcValue);
  287. BOOL GetReg(WCHAR const *pwcName,WCHAR *pwcValue,DWORD *pdwSize);
  288. int GetRegInt(WCHAR const *pwcName,int iDef);
  289. void SetRegInt(WCHAR const *pwcName,int iValue);
  290. LCID GetRegLCID(WCHAR const *pwcName,LCID defLCID);
  291. void SetRegLCID(WCHAR const *pwcName,LCID lcid);
  292. void LoadNumberFormatInfo(NUMBERFMT &rFormat);
  293. void FreeNumberFormatInfo(NUMBERFMT &rFormat);
  294. void SaveWindowRect( HWND hwnd, WCHAR const *pwc );
  295. BOOL LoadWindowRect(int *left, int *top, int *right, int *bottom, WCHAR const *pwc );
  296. void WINAPI CenterDialog(HWND hdlg);
  297. void PassOnToEdit(UINT,WPARAM,LPARAM);
  298. int GetLineHeight(HWND hwnd,HFONT hfont=0);
  299. INT_PTR DoModalDialog(DLGPROC,HWND,WCHAR *,LPARAM);
  300. void ShowResError(HWND,UINT,BOOL);
  301. int SaveWindowState(BOOL);
  302. int GetWindowState(BOOL);
  303. BOOL IsSpecificClass(HWND,WCHAR const *);
  304. int GetAvgWidth(HWND hwnd,HFONT hFont);
  305. void PutInClipboard(WCHAR const *pwc);
  306. void ExecApp( WCHAR const *pwcCmd );
  307. BOOL GetCatListItem( const XGrowable<WCHAR> & const_xCatList,
  308. unsigned iItem,
  309. WCHAR * pwszMachine,
  310. WCHAR * pwszCatalog,
  311. WCHAR * pwszScope,
  312. BOOL & fDeep );
  313. enum enumViewFile { fileBrowse, fileEdit, fileOpen };
  314. BOOL ViewFile( WCHAR const *pwcFile,
  315. enumViewFile eViewType,
  316. int iLineNumber = 1,
  317. DBCOMMANDTREE * prstQuery = 0 );
  318. // handy macros
  319. inline WORD MyWmCommandID(WPARAM wp,LPARAM lp)
  320. { return LOWORD(wp); }
  321. inline HWND MyWmCommandHWnd(WPARAM wp,LPARAM lp)
  322. { return (HWND) lp; }
  323. inline WORD MyWmCommandCmd(WPARAM wp,LPARAM lp)
  324. { return HIWORD(wp); }
  325. inline LRESULT MySendWmCommand(HWND hwnd,UINT id,HWND hctl,UINT cmd)
  326. { return SendMessage(hwnd,WM_COMMAND,
  327. (WPARAM) MAKELONG(id,cmd),(LPARAM) hctl); }
  328. inline BOOL MyPostWmCommand(HWND hwnd,UINT id,HWND hctl,UINT cmd)
  329. { return PostMessage(hwnd,WM_COMMAND,
  330. (WPARAM) MAKELONG(id,cmd),(LPARAM) hctl); }
  331. inline LRESULT MySendEMSetSel(HWND hwnd,UINT uiStart,UINT uiEnd)
  332. { return SendMessage(hwnd,EM_SETSEL,
  333. (WPARAM) uiStart,(LPARAM) uiEnd); }
  334. inline UINT MyMenuSelectCmd(WPARAM wp,LPARAM lp)
  335. { return LOWORD(wp); }
  336. inline UINT MyMenuSelectFlags(WPARAM wp,LPARAM lp)
  337. { return HIWORD(wp); }
  338. inline HMENU MyMenuSelectHMenu(WPARAM wp,LPARAM lp)
  339. { return (HMENU) lp; }
  340. inline UINT MyGetWindowID(HWND hwnd)
  341. { return (UINT) GetWindowLong(hwnd,GWL_ID); }
  342. inline HINSTANCE MyGetWindowInstance(HWND hwnd)
  343. { return (HINSTANCE) GetWindowLongPtr(hwnd,GWLP_HINSTANCE); }
  344. #ifndef SMOOTHSCROLLINFO
  345. extern "C"
  346. {
  347. #define SSI_DEFAULT ((UINT)-1)
  348. #define SSIF_SCROLLPROC 0x0001
  349. #define SSIF_MAXSCROLLTIME 0x0002
  350. #define SSIF_MINSCROLL 0x0003
  351. typedef int (CALLBACK *PFNSMOOTHSCROLLPROC)( HWND hWnd,
  352. int dx,
  353. int dy,
  354. CONST RECT *prcScroll,
  355. CONST RECT *prcClip ,
  356. HRGN hrgnUpdate,
  357. LPRECT prcUpdate,
  358. UINT flags);
  359. typedef struct tagSSWInfo{
  360. UINT cbSize;
  361. DWORD fMask;
  362. HWND hwnd;
  363. int dx;
  364. int dy;
  365. LPCRECT lprcSrc;
  366. LPCRECT lprcClip;
  367. HRGN hrgnUpdate;
  368. LPRECT lprcUpdate;
  369. UINT fuScroll;
  370. UINT uMaxScrollTime;
  371. UINT cxMinScroll;
  372. UINT cyMinScroll;
  373. PFNSMOOTHSCROLLPROC pfnScrollProc; // we'll call this back instead
  374. } SMOOTHSCROLLINFO, *PSMOOTHSCROLLINFO;
  375. WINCOMMCTRLAPI INT WINAPI SmoothScrollWindow(PSMOOTHSCROLLINFO pssi);
  376. #define SSW_EX_NOTIMELIMIT 0x00010000
  377. #define SSW_EX_IMMEDIATE 0x00020000
  378. #define SSW_EX_IGNORESETTINGS 0x00040000 // ignore system settings to turn on/off smooth scroll
  379. }
  380. #endif // SMOOTHSCROLLINFO
  381. inline void MyScrollWindow(
  382. HWND hwnd,
  383. int dx,
  384. int dy,
  385. CONST RECT * pRect,
  386. CONST RECT * pClipRect,
  387. BOOL fSmooth = TRUE )
  388. {
  389. #if 1
  390. if ( fSmooth )
  391. {
  392. SMOOTHSCROLLINFO ssi;
  393. ssi.cbSize = sizeof ssi;
  394. ssi.fMask = SSIF_MINSCROLL | SSIF_MAXSCROLLTIME; //0;
  395. ssi.hwnd = hwnd;
  396. ssi.dx = dx;
  397. ssi.dy = dy;
  398. ssi.lprcSrc = pRect;
  399. ssi.lprcClip = pClipRect;
  400. ssi.hrgnUpdate = 0;
  401. ssi.lprcUpdate = 0;
  402. ssi.fuScroll = SW_INVALIDATE | SW_ERASE;
  403. ssi.uMaxScrollTime = GetDoubleClickTime() / 6; //SSI_DEFAULT,
  404. ssi.cxMinScroll = 1; //SSI_DEFAULT,
  405. ssi.cyMinScroll = 1; //SSI_DEFAULT,
  406. ssi.pfnScrollProc = 0;
  407. SmoothScrollWindow( &ssi );
  408. }
  409. else
  410. #endif
  411. {
  412. ScrollWindow( hwnd, dx, dy, pRect, pClipRect );
  413. }
  414. } //MyScrollWindow
  415. struct SLocaleEntry
  416. {
  417. DWORD iMenuOption;
  418. LCID lcid;
  419. };
  420. extern const SLocaleEntry aLocaleEntries[];
  421. extern const ULONG cLocaleEntries;
  422. class CQueryResult
  423. {
  424. public:
  425. CQueryResult( WCHAR const * pwcPath, DBCOMMANDTREE const * pTree, BOOL fDelete ) :
  426. _pwcPath( pwcPath ), _pTree( pTree ), _fDeleteWhenDone( fDelete ) {}
  427. WCHAR const * _pwcPath;
  428. DBCOMMANDTREE const * _pTree;
  429. BOOL _fDeleteWhenDone;
  430. };
  431. class CColumnList
  432. {
  433. public:
  434. CColumnList() : _aColumns(0), _cColumns(0) {}
  435. ~CColumnList()
  436. {
  437. if ( 0 != _aColumns )
  438. {
  439. UINT iColumn;
  440. for( iColumn = 0; iColumn < _cColumns; iColumn++ )
  441. delete [] _aColumns[ iColumn ];
  442. delete [] _aColumns;
  443. }
  444. }
  445. void SetColumn( WCHAR const * wcsColumn, UINT uPos )
  446. {
  447. // does _aColumns need to be extended?
  448. if( uPos >= _cColumns )
  449. {
  450. WCHAR ** pwcsTemp = new WCHAR *[ uPos + 1 ];
  451. UINT cCol;
  452. // copy the old pointers and 0 any new ones
  453. for( cCol = 0; cCol < uPos + 1; cCol++ )
  454. {
  455. if( cCol < _cColumns )
  456. pwcsTemp[ cCol ] = _aColumns[ cCol ];
  457. else
  458. pwcsTemp[ cCol ] = 0;
  459. }
  460. delete [] _aColumns;
  461. _cColumns = uPos + 1;
  462. _aColumns = pwcsTemp;
  463. }
  464. // free any previous column string
  465. delete [] _aColumns[ uPos ];
  466. // copy & set the column
  467. if( wcsColumn == 0 )
  468. {
  469. _aColumns[ uPos ] = 0;
  470. }
  471. else
  472. {
  473. int iLength = wcslen( wcsColumn ) + 1;
  474. _aColumns[ uPos ] = new WCHAR[ iLength ];
  475. memcpy( _aColumns[ uPos ], wcsColumn, iLength * sizeof(WCHAR) );
  476. }
  477. }
  478. WCHAR const * GetColumn( UINT uPos ) const
  479. {
  480. if( uPos >= _cColumns )
  481. return 0;
  482. return _aColumns[ uPos ];
  483. }
  484. void SetNumberOfColumns( UINT cCol )
  485. {
  486. if( cCol < _cColumns )
  487. {
  488. for( ; cCol < _cColumns; cCol++ )
  489. {
  490. delete [] _aColumns[ cCol ];
  491. _aColumns[ cCol ] = 0;
  492. }
  493. }
  494. }
  495. UINT NumberOfColumns() const
  496. {
  497. UINT cCol;
  498. for( cCol = 0; cCol < _cColumns; cCol++ )
  499. {
  500. if( _aColumns[ cCol ] == 0 )
  501. break;
  502. }
  503. return cCol;
  504. }
  505. void MakeList( XArray<WCHAR> &a )
  506. {
  507. UINT cCol;
  508. UINT cwc = 0;
  509. for ( cCol = 0; cCol < _cColumns; cCol++ )
  510. {
  511. if ( _aColumns[ cCol ] == 0 )
  512. break;
  513. cwc += wcslen( _aColumns[cCol] ) + 1;
  514. }
  515. cwc++;
  516. a.ReSize( cwc );
  517. WCHAR *pwc = a.GetPointer();
  518. for ( cCol = 0; cCol < _cColumns; cCol++ )
  519. {
  520. if ( _aColumns[ cCol ] == 0 )
  521. break;
  522. if ( 0 != cCol )
  523. *pwc++ = L',';
  524. WCHAR *p = _aColumns[cCol];
  525. while ( 0 != *p )
  526. *pwc++ = *p++;
  527. }
  528. *pwc = 0;
  529. }
  530. private:
  531. WCHAR ** _aColumns;
  532. UINT _cColumns;
  533. };
  534. class CSortList
  535. {
  536. public:
  537. CSortList() : _pwcSort(0) {}
  538. ~CSortList() { delete [] _pwcSort; }
  539. void SetSort( WCHAR const * pwc, int iDir )
  540. {
  541. _iSortDir = iDir;
  542. if ( 0 != _pwcSort )
  543. {
  544. delete [] _pwcSort;
  545. _pwcSort = 0;
  546. }
  547. int cwc = wcslen( pwc ) + 1;
  548. _pwcSort = new WCHAR[ cwc ];
  549. wcscpy( _pwcSort, pwc );
  550. }
  551. int GetSortDir() { return _iSortDir; }
  552. WCHAR const * pwcGetSort() { return _pwcSort; }
  553. void MakeList( XArray<WCHAR> & a )
  554. {
  555. int cwc = wcslen( _pwcSort );
  556. a.ReSize( cwc + 1 + 3 );
  557. wcscpy( a.Get(), _pwcSort );
  558. a[cwc] = L'[';
  559. a[cwc + 1] = ( SORT_UP == _iSortDir ) ? L'a' : L'd';
  560. a[cwc + 2] = L']';
  561. a[cwc + 3] = 0;
  562. }
  563. private:
  564. int _iSortDir;
  565. WCHAR * _pwcSort;
  566. };