Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

717 lines
20 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 = 300;
  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. WCHAR * GetDefaultQuery() { return _awcDefaultQuery; }
  150. private:
  151. HWND _MakeMDI(WCHAR const * pwcTitle,WCHAR * pwcClass,UINT uiState,
  152. DWORD dwFlags,LPARAM lpCreate);
  153. int _CountMDIChildren();
  154. int _CountMDISearch();
  155. LRESULT _SendToMDIChildren(UINT msg,WPARAM wParam,LPARAM lParam);
  156. LRESULT _SendToSpecificChildren(WCHAR *pwcClass,UINT msg,WPARAM wParam,LPARAM lParam);
  157. LRESULT _SendToActiveMDI(UINT msg,WPARAM wParam,LPARAM lParam);
  158. int _SaveWindowState(BOOL bApp);
  159. void _SizeMDIAndBars(BOOL fMove,int iDX,int iDY);
  160. void _SaveProfileData();
  161. void _ReadDefaultFonts();
  162. void _GetPaths();
  163. void _InitInstance(LPSTR pcCmdLine);
  164. void _InitApplication();
  165. void _CreateFonts();
  166. void _UnMarshallFont(LOGFONT &lf,WCHAR *pwcFont,WCHAR *pwcRegEntry);
  167. void _MarshallFont(LOGFONT &lf,WCHAR *pwcOriginal,WCHAR *pwcRegEntry);
  168. void _ShowHelp(UINT uiID,DWORD dw);
  169. HINSTANCE _hInst;
  170. HWND _hMDIClientWnd;
  171. HWND _hAppWnd;
  172. HWND _hStatusBarWnd;
  173. HWND _hToolBarWnd;
  174. HWND _hdlgCurrent;
  175. HACCEL _hAccTable;
  176. HBRUSH _hbrushBtnFace;
  177. HBRUSH _hbrushBtnHilite;
  178. HBRUSH _hbrushHilite;
  179. HBRUSH _hbrushWindow;
  180. NUMBERFMT _NumberFmt;
  181. NUMBERFMT _NumberFmtFloat;
  182. HFONT _hfontApp;
  183. HFONT _hfontBrowse;
  184. BOOL _fHelp;
  185. int _iAppCmdShow;
  186. int _iStartupState,_iMDIStartupState;
  187. WCHAR _awcAppFont[MAX_PATH],_awcBrowseFont[MAX_PATH];
  188. LOGFONT _lfApp,_lfBrowse;
  189. WCHAR _awcAppPath[MAX_PATH];
  190. WCHAR _awcHelpFile[MAX_PATH];
  191. SCODE _scBrowseLastError;
  192. XGrowable<WCHAR> _xCatList;
  193. WCHAR _awcDefaultQuery[ MAX_PATH ];
  194. WCHAR _awcSort[MAX_PATH];
  195. int _sortDir;
  196. LCID _lcid; // locale id for query
  197. BOOL _fToolBarOn;
  198. BOOL _fStatusBarOn;
  199. BOOL _fForceUseCI;
  200. ULONG _ulDialect; // tripolish version 1 or 2 or SQL
  201. ULONG _ulLimit; // CiMaxRecordsInResultSet
  202. ULONG _ulFirstRows;
  203. WCHAR _awcSortINI[MAX_PATH];
  204. int _sortDirINI;
  205. LCID _lcidINI;
  206. BOOL _fToolBarOnINI;
  207. BOOL _fStatusBarOnINI;
  208. BOOL _fForceUseCIINI;
  209. ULONG _ulDialectINI;
  210. ULONG _ulLimitINI;
  211. ULONG _ulFirstRowsINI;
  212. CResString _strTrue;
  213. CResString _strFalse;
  214. CResString _strAttrib;
  215. CResString _strBlob;
  216. CResString _strYes;
  217. CResString _strNo;
  218. XInterface<ISimpleCommandCreator> _xCmdCreator;
  219. };
  220. // whomping global state data
  221. extern CSearchApp App;
  222. inline CResString::CResString( UINT strIDS )
  223. {
  224. _awc[ 0 ] = 0;
  225. LoadString( App.Instance(),
  226. strIDS,
  227. _awc,
  228. sizeof _awc / sizeof WCHAR );
  229. }
  230. inline BOOL CResString::Load( UINT strIDS )
  231. {
  232. _awc[ 0 ] = 0;
  233. LoadString( App.Instance(),
  234. strIDS,
  235. _awc,
  236. sizeof _awc / sizeof WCHAR );
  237. return ( 0 != _awc[ 0 ] );
  238. }
  239. // name of the helpfile
  240. #define CISEARCH_HELPFILE L"srch.chm"
  241. // registry entry names
  242. #define CISEARCH_PARENT_REG_KEY L"software\\microsoft"
  243. #define CISEARCH_REG_SUBKEY L"CI Search"
  244. #define CISEARCH_REG_TOOLBAR L"Show Icon bar"
  245. #define CISEARCH_REG_STATUSBAR L"Show Status bar"
  246. #define CISEARCH_REG_POSITION L"Position"
  247. #define CISEARCH_REG_STATUSPOSITION L"Status Position"
  248. #define CISEARCH_REG_FONT L"Results Font"
  249. #define CISEARCH_REG_SORTPROP L"Sort property"
  250. #define CISEARCH_REG_SORTDIR L"Sort direction"
  251. #define CISEARCH_REG_LOCALE L"Locale Id"
  252. #define CISEARCH_REG_BROWSEFONT L"Browse Font"
  253. #define CISEARCH_REG_BROWSE L"Browse tool"
  254. #define CISEARCH_REG_BROWSESTRIP L"Browse strip"
  255. #define CISEARCH_REG_DISPLAYPROPS L"Displayed properties"
  256. #define CISEARCH_REG_FORCEUSECI L"Force use CI"
  257. #define CISEARCH_REG_EDITOR L"Editor"
  258. #define CISEARCH_REG_DIALECT L"Dialect"
  259. #define CISEARCH_REG_LIMIT L"Limit"
  260. #define CISEARCH_REG_FIRSTROWS L"FirstRows"
  261. // built-in browser options
  262. #define BROWSER L"browse"
  263. #define BROWSER_SLICK L"s %ws"
  264. #define BROWSER_SLICK_SEARCH L"s %ws -#/%ws/"
  265. #define DEFAULT_DISPLAYED_PROPERTIES L"Size,Write,Path"
  266. #define DEFAULT_SORT_PROPERTIES L"Path"
  267. // T must be based on a basic type
  268. template<class T> BOOL isOdd(T value) { return 0 != (value & 1); }
  269. // srch.cxx
  270. INT_PTR WINAPI BrowseToolDlgProc(HWND hdlg,UINT msg,WPARAM wParam,LPARAM lParam);
  271. // toolbar.cxx
  272. HWND CreateTBar( HWND hParent, HINSTANCE hInstance );
  273. LRESULT ToolBarNotify( HWND hwnd, UINT uMessage, WPARAM wparam,
  274. LPARAM lparam, HINSTANCE hInst );
  275. void UpdateButtons( UINT *aid, UINT cid, BOOL fEnabled );
  276. // srchwnd.cxx
  277. LRESULT WINAPI SearchWndProc(HWND,UINT,WPARAM,LPARAM);
  278. INT_PTR WINAPI ScopeDlgProc(HWND hdlg,UINT msg,WPARAM wParam,LPARAM lParam);
  279. INT_PTR WINAPI FilterScopeDlgProc(HWND hdlg,UINT msg,WPARAM wParam,LPARAM lParam);
  280. INT_PTR WINAPI StatusDlgProc(HWND hdlg,UINT msg,WPARAM wParam,LPARAM lParam);
  281. // brcrtl.cxx
  282. LRESULT WINAPI BrowseWndProc(HWND,UINT,WPARAM,LPARAM);
  283. // lview.cxx
  284. LRESULT WINAPI ListViewWndProc(HWND,UINT,WPARAM,LPARAM);
  285. // srchutil.cxx
  286. void FormatSrchError( SCODE sc, WCHAR * pwc, LCID lcid );
  287. void SearchError(HWND hParent,ULONG dwErrorID,WCHAR const *pwcTitle);
  288. void SetReg(WCHAR const *pwcName,WCHAR const *pwcValue);
  289. BOOL GetReg(WCHAR const *pwcName,WCHAR *pwcValue,DWORD *pdwSize);
  290. int GetRegInt(WCHAR const *pwcName,int iDef);
  291. void SetRegInt(WCHAR const *pwcName,int iValue);
  292. LCID GetRegLCID(WCHAR const *pwcName,LCID defLCID);
  293. void SetRegLCID(WCHAR const *pwcName,LCID lcid);
  294. void LoadNumberFormatInfo(NUMBERFMT &rFormat);
  295. void FreeNumberFormatInfo(NUMBERFMT &rFormat);
  296. void SaveWindowRect( HWND hwnd, WCHAR const *pwc );
  297. BOOL LoadWindowRect(int *left, int *top, int *right, int *bottom, WCHAR const *pwc );
  298. void WINAPI CenterDialog(HWND hdlg);
  299. void PassOnToEdit(UINT,WPARAM,LPARAM);
  300. int GetLineHeight(HWND hwnd,HFONT hfont=0);
  301. INT_PTR DoModalDialog(DLGPROC,HWND,WCHAR *,LPARAM);
  302. void ShowResError(HWND,UINT,BOOL);
  303. int SaveWindowState(BOOL);
  304. int GetWindowState(BOOL);
  305. BOOL IsSpecificClass(HWND,WCHAR const *);
  306. int GetAvgWidth(HWND hwnd,HFONT hFont);
  307. void PutInClipboard(WCHAR const *pwc);
  308. void ExecApp( WCHAR const *pwcCmd );
  309. BOOL GetCatListItem( const XGrowable<WCHAR> & const_xCatList,
  310. unsigned iItem,
  311. WCHAR * pwszMachine,
  312. WCHAR * pwszCatalog,
  313. WCHAR * pwszScope,
  314. BOOL & fDeep );
  315. enum enumViewFile { fileBrowse, fileEdit, fileOpen };
  316. BOOL ViewFile( WCHAR const *pwcFile,
  317. enumViewFile eViewType,
  318. int iLineNumber = 1,
  319. DBCOMMANDTREE * prstQuery = 0 );
  320. // handy macros
  321. inline WORD MyWmCommandID(WPARAM wp,LPARAM lp)
  322. { return LOWORD(wp); }
  323. inline HWND MyWmCommandHWnd(WPARAM wp,LPARAM lp)
  324. { return (HWND) lp; }
  325. inline WORD MyWmCommandCmd(WPARAM wp,LPARAM lp)
  326. { return HIWORD(wp); }
  327. inline LRESULT MySendWmCommand(HWND hwnd,UINT id,HWND hctl,UINT cmd)
  328. { return SendMessage(hwnd,WM_COMMAND,
  329. (WPARAM) MAKELONG(id,cmd),(LPARAM) hctl); }
  330. inline BOOL MyPostWmCommand(HWND hwnd,UINT id,HWND hctl,UINT cmd)
  331. { return PostMessage(hwnd,WM_COMMAND,
  332. (WPARAM) MAKELONG(id,cmd),(LPARAM) hctl); }
  333. inline LRESULT MySendEMSetSel(HWND hwnd,UINT uiStart,UINT uiEnd)
  334. { return SendMessage(hwnd,EM_SETSEL,
  335. (WPARAM) uiStart,(LPARAM) uiEnd); }
  336. inline UINT MyMenuSelectCmd(WPARAM wp,LPARAM lp)
  337. { return LOWORD(wp); }
  338. inline UINT MyMenuSelectFlags(WPARAM wp,LPARAM lp)
  339. { return HIWORD(wp); }
  340. inline HMENU MyMenuSelectHMenu(WPARAM wp,LPARAM lp)
  341. { return (HMENU) lp; }
  342. inline UINT MyGetWindowID(HWND hwnd)
  343. { return (UINT) GetWindowLong(hwnd,GWL_ID); }
  344. inline HINSTANCE MyGetWindowInstance(HWND hwnd)
  345. { return (HINSTANCE) GetWindowLongPtr(hwnd,GWLP_HINSTANCE); }
  346. #ifndef SMOOTHSCROLLINFO
  347. extern "C"
  348. {
  349. #define SSI_DEFAULT ((UINT)-1)
  350. #define SSIF_SCROLLPROC 0x0001
  351. #define SSIF_MAXSCROLLTIME 0x0002
  352. #define SSIF_MINSCROLL 0x0003
  353. typedef int (CALLBACK *PFNSMOOTHSCROLLPROC)( HWND hWnd,
  354. int dx,
  355. int dy,
  356. CONST RECT *prcScroll,
  357. CONST RECT *prcClip ,
  358. HRGN hrgnUpdate,
  359. LPRECT prcUpdate,
  360. UINT flags);
  361. typedef struct tagSSWInfo{
  362. UINT cbSize;
  363. DWORD fMask;
  364. HWND hwnd;
  365. int dx;
  366. int dy;
  367. LPCRECT lprcSrc;
  368. LPCRECT lprcClip;
  369. HRGN hrgnUpdate;
  370. LPRECT lprcUpdate;
  371. UINT fuScroll;
  372. UINT uMaxScrollTime;
  373. UINT cxMinScroll;
  374. UINT cyMinScroll;
  375. PFNSMOOTHSCROLLPROC pfnScrollProc; // we'll call this back instead
  376. } SMOOTHSCROLLINFO, *PSMOOTHSCROLLINFO;
  377. WINCOMMCTRLAPI INT WINAPI SmoothScrollWindow(PSMOOTHSCROLLINFO pssi);
  378. #define SSW_EX_NOTIMELIMIT 0x00010000
  379. #define SSW_EX_IMMEDIATE 0x00020000
  380. #define SSW_EX_IGNORESETTINGS 0x00040000 // ignore system settings to turn on/off smooth scroll
  381. }
  382. #endif // SMOOTHSCROLLINFO
  383. inline void MyScrollWindow(
  384. HWND hwnd,
  385. int dx,
  386. int dy,
  387. CONST RECT * pRect,
  388. CONST RECT * pClipRect,
  389. BOOL fSmooth = TRUE )
  390. {
  391. #if 1
  392. if ( fSmooth )
  393. {
  394. SMOOTHSCROLLINFO ssi;
  395. ssi.cbSize = sizeof ssi;
  396. ssi.fMask = SSIF_MINSCROLL | SSIF_MAXSCROLLTIME; //0;
  397. ssi.hwnd = hwnd;
  398. ssi.dx = dx;
  399. ssi.dy = dy;
  400. ssi.lprcSrc = pRect;
  401. ssi.lprcClip = pClipRect;
  402. ssi.hrgnUpdate = 0;
  403. ssi.lprcUpdate = 0;
  404. ssi.fuScroll = SW_INVALIDATE | SW_ERASE;
  405. ssi.uMaxScrollTime = GetDoubleClickTime() / 6; //SSI_DEFAULT,
  406. ssi.cxMinScroll = 1; //SSI_DEFAULT,
  407. ssi.cyMinScroll = 1; //SSI_DEFAULT,
  408. ssi.pfnScrollProc = 0;
  409. SmoothScrollWindow( &ssi );
  410. }
  411. else
  412. #endif
  413. {
  414. ScrollWindow( hwnd, dx, dy, pRect, pClipRect );
  415. }
  416. } //MyScrollWindow
  417. struct SLocaleEntry
  418. {
  419. DWORD iMenuOption;
  420. LCID lcid;
  421. };
  422. extern const SLocaleEntry aLocaleEntries[];
  423. extern const ULONG cLocaleEntries;
  424. class CQueryResult
  425. {
  426. public:
  427. CQueryResult( WCHAR const * pwcPath, DBCOMMANDTREE const * pTree, BOOL fDelete ) :
  428. _pwcPath( pwcPath ), _pTree( pTree ), _fDeleteWhenDone( fDelete ) {}
  429. WCHAR const * _pwcPath;
  430. DBCOMMANDTREE const * _pTree;
  431. BOOL _fDeleteWhenDone;
  432. };
  433. class CColumnList
  434. {
  435. public:
  436. CColumnList() : _aColumns(0), _cColumns(0) {}
  437. ~CColumnList()
  438. {
  439. if ( 0 != _aColumns )
  440. {
  441. UINT iColumn;
  442. for( iColumn = 0; iColumn < _cColumns; iColumn++ )
  443. delete [] _aColumns[ iColumn ];
  444. delete [] _aColumns;
  445. }
  446. }
  447. void SetColumn( WCHAR const * wcsColumn, UINT uPos )
  448. {
  449. // does _aColumns need to be extended?
  450. if( uPos >= _cColumns )
  451. {
  452. WCHAR ** pwcsTemp = new WCHAR *[ uPos + 1 ];
  453. UINT cCol;
  454. // copy the old pointers and 0 any new ones
  455. for( cCol = 0; cCol < uPos + 1; cCol++ )
  456. {
  457. if( cCol < _cColumns )
  458. pwcsTemp[ cCol ] = _aColumns[ cCol ];
  459. else
  460. pwcsTemp[ cCol ] = 0;
  461. }
  462. delete [] _aColumns;
  463. _cColumns = uPos + 1;
  464. _aColumns = pwcsTemp;
  465. }
  466. // free any previous column string
  467. delete [] _aColumns[ uPos ];
  468. // copy & set the column
  469. if( wcsColumn == 0 )
  470. {
  471. _aColumns[ uPos ] = 0;
  472. }
  473. else
  474. {
  475. int iLength = wcslen( wcsColumn ) + 1;
  476. _aColumns[ uPos ] = new WCHAR[ iLength ];
  477. memcpy( _aColumns[ uPos ], wcsColumn, iLength * sizeof(WCHAR) );
  478. }
  479. }
  480. WCHAR const * GetColumn( UINT uPos ) const
  481. {
  482. if( uPos >= _cColumns )
  483. return 0;
  484. return _aColumns[ uPos ];
  485. }
  486. void SetNumberOfColumns( UINT cCol )
  487. {
  488. if( cCol < _cColumns )
  489. {
  490. for( ; cCol < _cColumns; cCol++ )
  491. {
  492. delete [] _aColumns[ cCol ];
  493. _aColumns[ cCol ] = 0;
  494. }
  495. }
  496. }
  497. UINT NumberOfColumns() const
  498. {
  499. UINT cCol;
  500. for( cCol = 0; cCol < _cColumns; cCol++ )
  501. {
  502. if( _aColumns[ cCol ] == 0 )
  503. break;
  504. }
  505. return cCol;
  506. }
  507. void MakeList( XArray<WCHAR> &a )
  508. {
  509. UINT cCol;
  510. UINT cwc = 0;
  511. for ( cCol = 0; cCol < _cColumns; cCol++ )
  512. {
  513. if ( _aColumns[ cCol ] == 0 )
  514. break;
  515. cwc += wcslen( _aColumns[cCol] ) + 1;
  516. }
  517. cwc++;
  518. a.ReSize( cwc );
  519. WCHAR *pwc = a.GetPointer();
  520. for ( cCol = 0; cCol < _cColumns; cCol++ )
  521. {
  522. if ( _aColumns[ cCol ] == 0 )
  523. break;
  524. if ( 0 != cCol )
  525. *pwc++ = L',';
  526. WCHAR *p = _aColumns[cCol];
  527. while ( 0 != *p )
  528. *pwc++ = *p++;
  529. }
  530. *pwc = 0;
  531. }
  532. private:
  533. WCHAR ** _aColumns;
  534. UINT _cColumns;
  535. };
  536. class CSortList
  537. {
  538. public:
  539. CSortList() : _pwcSort(0) {}
  540. ~CSortList() { delete [] _pwcSort; }
  541. void SetSort( WCHAR const * pwc, int iDir )
  542. {
  543. _iSortDir = iDir;
  544. if ( 0 != _pwcSort )
  545. {
  546. delete [] _pwcSort;
  547. _pwcSort = 0;
  548. }
  549. int cwc = wcslen( pwc ) + 1;
  550. _pwcSort = new WCHAR[ cwc ];
  551. wcscpy( _pwcSort, pwc );
  552. }
  553. int GetSortDir() { return _iSortDir; }
  554. WCHAR const * pwcGetSort() { return _pwcSort; }
  555. void MakeList( XArray<WCHAR> & a )
  556. {
  557. int cwc = wcslen( _pwcSort );
  558. a.ReSize( cwc + 1 + 3 );
  559. wcscpy( a.Get(), _pwcSort );
  560. a[cwc] = L'[';
  561. a[cwc + 1] = ( SORT_UP == _iSortDir ) ? L'a' : L'd';
  562. a[cwc + 2] = L']';
  563. a[cwc + 3] = 0;
  564. }
  565. private:
  566. int _iSortDir;
  567. WCHAR * _pwcSort;
  568. };