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.

989 lines
25 KiB

  1. /*
  2. CFileWindow.CPP
  3. File window class
  4. */
  5. #include "stdafx.h"
  6. #include <commdlg.h>
  7. #include "resource.h"
  8. #include "cfilewindow.h"
  9. #define BUFFER_GROW_SIZE 1024
  10. #define CURSOR_BLINK 1000
  11. #define LEFT_MARGIN_SIZE 40
  12. #define MIN( _arg1, _arg2 ) (( _arg1 < _arg2 ? _arg1 : _arg2 ))
  13. #define MAX( _arg1, _arg2 ) (( _arg1 > _arg2 ? _arg1 : _arg2 ))
  14. #define DUMP_RECT( _rect ) { TCHAR sz[MAX_PATH]; wsprintf( sz, "( L%u, %T%u, R%u, B%u )", _rect.left, _rect.top, _rect.right, _rect.bottom ); OutputDebugString( sz ); }
  15. //#define DEBUG_PAINT
  16. //
  17. // Constructor
  18. //
  19. CFileWindow::CFileWindow(
  20. HWND hParent )
  21. {
  22. TCHAR szTitle[ MAX_PATH ];
  23. _hParent = hParent;
  24. _pszFilename = NULL;
  25. _nLength = 0;
  26. _pLine = NULL;
  27. LoadString( g_hInstance,
  28. IDS_UNTITLED,
  29. szTitle,
  30. sizeof(szTitle)/sizeof(szTitle[0]) );
  31. _hWnd = CreateWindowEx( WS_EX_ACCEPTFILES,
  32. CFILEWINDOWCLASS,
  33. szTitle,
  34. WS_OVERLAPPEDWINDOW
  35. | WS_CLIPSIBLINGS,
  36. CW_USEDEFAULT,
  37. 0,
  38. CW_USEDEFAULT,
  39. 0,
  40. NULL,
  41. NULL,
  42. g_hInstance,
  43. (LPVOID) this);
  44. if (!_hWnd)
  45. {
  46. return;
  47. }
  48. ShowWindow( _hWnd, SW_NORMAL );
  49. UpdateWindow( _hWnd );
  50. }
  51. //
  52. // Destructor
  53. //
  54. CFileWindow::~CFileWindow( )
  55. {
  56. if ( _pszFilename )
  57. LocalFree( _pszFilename );
  58. if ( _pLine )
  59. LocalFree( _pLine );
  60. }
  61. //
  62. // _UpdateTitle( )
  63. //
  64. HRESULT
  65. CFileWindow::_UpdateTitle( )
  66. {
  67. TCHAR szTitleBar[ MAX_PATH * 2 ];
  68. LPTSTR pszTitle;
  69. if ( _pszFilename )
  70. {
  71. pszTitle = strrchr( _pszFilename, TEXT('\\') );
  72. if ( pszTitle )
  73. {
  74. INT iResult;
  75. TCHAR ch;
  76. TCHAR szCWD[ MAX_PATH ];
  77. GetCurrentDirectory( MAX_PATH, szCWD );
  78. ch = *pszTitle; // save
  79. *pszTitle = 0; // terminate
  80. iResult = strcmp( szCWD, _pszFilename );// compare
  81. *pszTitle = ch; // restore
  82. pszTitle++; // skip past the slash
  83. if ( iResult != 0 )
  84. {
  85. pszTitle = _pszFilename;
  86. }
  87. }
  88. else
  89. {
  90. pszTitle = _pszFilename;
  91. }
  92. strcpy( szTitleBar, pszTitle );
  93. }
  94. else
  95. {
  96. LoadString( g_hInstance,
  97. IDS_UNTITLED,
  98. szTitleBar,
  99. sizeof(szTitleBar)/sizeof(szTitleBar[0]) );
  100. }
  101. SetWindowText( _hWnd, szTitleBar );
  102. return S_OK;
  103. }
  104. //
  105. // SetInformation( )
  106. //
  107. HRESULT
  108. CFileWindow::SetInformation(
  109. ULONG nNode,
  110. LPTSTR pszFilename,
  111. LINEPOINTER * pLineBuffer,
  112. ULONG nLineCount )
  113. {
  114. SCROLLINFO si;
  115. if ( pszFilename )
  116. {
  117. if ( _pszFilename )
  118. LocalFree( _pszFilename );
  119. _pszFilename = pszFilename;
  120. _UpdateTitle( );
  121. }
  122. _nNode = nNode;
  123. _pLine = pLineBuffer;
  124. _nLineCount = nLineCount;
  125. if ( !_fVertSBVisible
  126. && _yWindow < (LONG)(_nLineCount * _tm.tmHeight) )
  127. {
  128. _fVertSBVisible = TRUE;
  129. EnableScrollBar( _hWnd, SB_VERT, ESB_ENABLE_BOTH );
  130. ShowScrollBar( _hWnd, SB_VERT, TRUE );
  131. }
  132. else if ( _fVertSBVisible
  133. && _yWindow >= (LONG)(_nLineCount * _tm.tmHeight) )
  134. {
  135. _fVertSBVisible = FALSE;
  136. //EnableScrollBar( _hWnd, SB_VERT, ESB_ENABLE_BOTH );
  137. ShowScrollBar( _hWnd, SB_VERT, FALSE );
  138. }
  139. si.cbSize = sizeof(si);
  140. si.fMask = SIF_RANGE;
  141. si.nMin = 0;
  142. si.nMax = _nLineCount;
  143. SetScrollInfo( _hWnd, SB_VERT, &si, TRUE );
  144. InvalidateRect( _hWnd, NULL, TRUE );
  145. return S_OK;
  146. }
  147. //
  148. // _OnPaint( )
  149. //
  150. LRESULT
  151. CFileWindow::_OnPaint(
  152. WPARAM wParam,
  153. LPARAM lParam )
  154. {
  155. HDC hdc;
  156. TCHAR szBuf[ 6 ]; // max 5-digits
  157. LONG y;
  158. LONG wx; // window coords
  159. LONG wy;
  160. RECT rect;
  161. RECT rectResult;
  162. SIZE size;
  163. LPTSTR pszStartLine; // beginning of line (PID/TID)
  164. LPTSTR pszStartTimeDate; // beginning of time/data stamp
  165. LPTSTR pszStartComponent; // beginning of component name
  166. LPTSTR pszStartResType; // beginning of a resource component
  167. LPTSTR pszStartText; // beginning of text
  168. LPTSTR pszCurrent; // current position and beginning of text
  169. SCROLLINFO si;
  170. PAINTSTRUCT ps;
  171. #if 0
  172. #if defined(_DEBUG)
  173. static DWORD cPaint = 0;
  174. {
  175. TCHAR szBuf[ MAX_PATH ];
  176. wsprintf( szBuf, "%u paint\n", ++cPaint );
  177. OutputDebugString( szBuf );
  178. }
  179. #endif
  180. #endif
  181. si.cbSize = sizeof(si);
  182. si.fMask = SIF_POS | SIF_PAGE;
  183. GetScrollInfo( _hWnd, SB_VERT, &si );
  184. hdc = BeginPaint( _hWnd, &ps);
  185. if ( !_pLine )
  186. goto EndPaint;
  187. SetBkMode( hdc, OPAQUE );
  188. SelectObject( hdc, g_hFont );
  189. y = si.nPos;
  190. wy = 0;
  191. while ( y <= (LONG)(si.nPos + si.nPage)
  192. && y < _nLineCount )
  193. {
  194. // draw line number
  195. SetRect( &rect,
  196. 0,
  197. wy,
  198. LEFT_MARGIN_SIZE,
  199. wy + _tm.tmHeight );
  200. if ( IntersectRect( &rectResult, &ps.rcPaint, &rect ) )
  201. {
  202. //FillRect( hdc, &rect, g_pConfig->GetMarginColor( ) );
  203. SetBkColor( hdc, GetSysColor( COLOR_GRAYTEXT ) );
  204. SetTextColor( hdc, GetSysColor( COLOR_WINDOWTEXT ) );
  205. DrawText( hdc,
  206. szBuf,
  207. wsprintf( szBuf, TEXT("%05.5u"), y ),
  208. &rect,
  209. DT_NOCLIP | DT_NOPREFIX | DT_SINGLELINE );
  210. }
  211. wx = LEFT_MARGIN_SIZE;
  212. if ( _pLine[ y ].psLine )
  213. {
  214. //
  215. // KB: This is what a typical cluster log line looks like.
  216. // 3fc.268::1999/07/19-19:14:45.548 [EVT] Node up: 2, new UpNodeSet: 0002
  217. // 3fc.268::1999/07/19-19:14:45.548 [EVT] EvOnline : calling ElfRegisterClusterSvc
  218. // 3fc.268::1999/07/19-19:14:45.548 [GUM] GumSendUpdate: queuing update type 2 context 19
  219. // 3fc.268::1999/07/19-19:14:45.548 [GUM] GumSendUpdate: Dispatching seq 2585 type 2 context 19 to node 1
  220. // 3fc.268::1999/07/19-19:14:45.548 [NM] Received update to set extended state for node 1 to 0
  221. // 3fc.268::1999/07/19-19:14:45.548 [NM] Issuing event 0.
  222. // 3fc.268::1999/07/19-19:14:45.548 [GUM] GumSendUpdate: completed update seq 2585 type 2 context 19
  223. // 37c.3a0::1999/07/19-19:14:45.548 Physical Disk: AddVolume : \\?\Volume{99d8d508-39fa-11d3-a200-806d6172696f}\ 'C', 7 (11041600)
  224. // 37c.3a0::1999/07/19-19:14:45.558 Physical Disk: AddVolume: GetPartitionInfo(\??\Volume{99d8d503-39fa-11d3-a200-806d6172696f}), error 170
  225. // 37c.3a0::1999/07/19-19:14:45.568 Physical Disk: AddVolume: GetPartitionInfo(\??\Volume{99d8d504-39fa-11d3-a200-806d6172696f}), error 170
  226. // 37c.3a0::1999/07/19-19:14:45.568 Physical Disk: AddVolume: GetPartitionInfo(\??\Volume{99d8d505-39fa-11d3-a200-806d6172696f}), error 170
  227. // 37c.3a0::1999/07/19-19:14:45.578 Physical Disk: AddVolume: GetPartitionInfo(\??\Volume{99d8d506-39fa-11d3-a200-806d6172696f}), error 170
  228. // 37c.3a0::1999/07/19-19:14:45.578 Physical Disk: AddVolume: GetPartitionInfo(\??\Volume{99d8d501-39fa-11d3-a200-806d6172696f}), error 1
  229. //
  230. if ( _pLine[ y ].nFile != _nNode )
  231. goto SkipLine;
  232. pszStartResType =
  233. pszStartComponent = NULL;
  234. pszStartLine =
  235. pszStartText =
  236. pszStartTimeDate =
  237. pszCurrent = _pLine[ y ].psLine;
  238. // Find the thread and process IDs
  239. while ( *pszCurrent && *pszCurrent != ':' && *pszCurrent >= 32 )
  240. {
  241. pszCurrent++;
  242. }
  243. if ( *pszCurrent < 32 )
  244. goto DrawRestOfLine;
  245. pszCurrent++;
  246. if ( *pszCurrent != ':' )
  247. goto DrawRestOfLine;
  248. pszCurrent++;
  249. // Find Time/Date stamp which is:
  250. // ####/##/##-##:##:##.###<space>
  251. pszStartTimeDate = pszCurrent;
  252. while ( *pszCurrent && *pszCurrent != ' ' && *pszCurrent >= 32 )
  253. {
  254. pszCurrent++;
  255. }
  256. if ( *pszCurrent < 32 )
  257. goto DrawRestOfLine;
  258. pszCurrent++;
  259. pszStartText = pszCurrent;
  260. // [OPTIONAL] Cluster component which looks like:
  261. // [<id...>]
  262. if ( *pszCurrent == '[' )
  263. {
  264. while ( *pszCurrent && *pszCurrent != ']' && *pszCurrent >= 32 )
  265. {
  266. pszCurrent++;
  267. }
  268. if ( *pszCurrent < 32 )
  269. goto NoComponentTryResouce;
  270. pszCurrent++;
  271. pszStartComponent = pszStartText;
  272. pszStartText = pszCurrent;
  273. }
  274. else
  275. {
  276. // [OPTIONAL] If not a component, see if there is a res type
  277. NoComponentTryResouce:
  278. pszCurrent = pszStartText;
  279. while ( *pszCurrent && *pszCurrent != ':' && *pszCurrent >= 32 )
  280. {
  281. pszCurrent++;
  282. }
  283. if ( *pszCurrent >= 32 )
  284. {
  285. pszCurrent++;
  286. pszStartResType = pszStartText;
  287. pszStartText = pszCurrent;
  288. }
  289. }
  290. if ( pszStartComponent )
  291. {
  292. DWORD n = 0;
  293. LONG nLen = pszStartText - pszStartComponent - 2;
  294. LPTSTR psz = g_pszFilters;
  295. while ( n < g_nComponentFilters )
  296. {
  297. if ( g_pfSelectedComponent[ n ]
  298. && ( nLen == lstrlen( psz ) )
  299. && ( _strnicmp( pszStartComponent + 1, psz, nLen ) == 0 ) )
  300. goto SkipLine;
  301. while ( *psz )
  302. {
  303. psz++;
  304. }
  305. psz += 2;
  306. n++;
  307. }
  308. }
  309. #if 0
  310. if ( pszStartResType )
  311. {
  312. if ( !g_fNetworkName
  313. && _strnicmp( pszStartResType, "Network Name", sizeof("Network Name") - 1 ) == 0 )
  314. goto SkipLine;
  315. if ( !g_fGenericService
  316. && _strnicmp( pszStartResType, "Generic Service", sizeof("Generic Service") - 1 ) == 0 )
  317. goto SkipLine;
  318. if ( !g_fPhysicalDisk
  319. && _strnicmp( pszStartResType, "Physical Disk", sizeof("Physical Disk") - 1 ) == 0 )
  320. goto SkipLine;
  321. if ( !g_fIPAddress
  322. && _strnicmp( pszStartResType, "IP Address", sizeof("IP Address") - 1 ) == 0 )
  323. goto SkipLine;
  324. if ( !g_fGenericApplication
  325. && _strnicmp( pszStartResType, "Generic Application", sizeof("Generic Application") - 1 ) == 0 )
  326. goto SkipLine;
  327. if ( !g_fFileShare
  328. && _strnicmp( pszStartResType, "File Share", sizeof("File Share") - 1 ) == 0 )
  329. goto SkipLine;
  330. }
  331. #endif
  332. // Draw PID and TID
  333. GetTextExtentPoint32( hdc,
  334. pszStartLine,
  335. pszStartTimeDate - pszStartLine - 2,
  336. &size );
  337. SetRect( &rect,
  338. wx,
  339. wy,
  340. wx + size.cx,
  341. wy + _tm.tmHeight );
  342. if ( IntersectRect( &rectResult, &ps.rcPaint, &rect ) )
  343. {
  344. SetBkColor( hdc, 0xFF8080 );
  345. SetTextColor( hdc, 0x000000 );
  346. DrawText( hdc,
  347. pszStartLine,
  348. pszStartTimeDate - pszStartLine - 2,
  349. &rect,
  350. DT_NOCLIP | DT_NOPREFIX | DT_SINGLELINE );
  351. }
  352. wx += size.cx;
  353. GetTextExtentPoint32( hdc,
  354. "::",
  355. 2,
  356. &size );
  357. SetRect( &rect,
  358. wx,
  359. wy,
  360. wx + size.cx,
  361. wy + _tm.tmHeight );
  362. if ( IntersectRect( &rectResult, &ps.rcPaint, &rect ) )
  363. {
  364. SetBkColor( hdc, 0xFFFFFF );
  365. SetTextColor( hdc, 0x000000 );
  366. DrawText( hdc,
  367. "::",
  368. 2,
  369. &rect,
  370. DT_NOCLIP | DT_NOPREFIX | DT_SINGLELINE );
  371. }
  372. wx += size.cx;
  373. // Draw Time/Date
  374. pszCurrent = ( pszStartComponent ?
  375. pszStartComponent :
  376. ( pszStartResType ?
  377. pszStartResType :
  378. pszStartText )
  379. ) - 1;
  380. GetTextExtentPoint32( hdc,
  381. pszStartTimeDate,
  382. pszCurrent - pszStartTimeDate,
  383. &size );
  384. SetRect( &rect,
  385. wx,
  386. wy,
  387. wx + size.cx,
  388. wy + _tm.tmHeight );
  389. if ( IntersectRect( &rectResult, &ps.rcPaint, &rect ) )
  390. {
  391. SetBkColor( hdc, 0x80FF80 );
  392. SetTextColor( hdc, 0x000000 );
  393. DrawText( hdc,
  394. pszStartTimeDate,
  395. pszCurrent - pszStartTimeDate,
  396. &rect,
  397. DT_NOCLIP | DT_NOPREFIX | DT_SINGLELINE );
  398. }
  399. wx += size.cx;
  400. // Draw component
  401. if ( pszStartComponent )
  402. {
  403. GetTextExtentPoint32( hdc,
  404. pszStartComponent,
  405. pszStartText - pszStartComponent,
  406. &size );
  407. SetRect( &rect,
  408. wx,
  409. wy,
  410. wx + size.cx,
  411. wy + _tm.tmHeight );
  412. if ( IntersectRect( &rectResult, &ps.rcPaint, &rect ) )
  413. {
  414. SetBkColor( hdc, GetSysColor( COLOR_WINDOW ) );
  415. SetTextColor( hdc, 0x800000 );
  416. DrawText( hdc,
  417. pszStartComponent,
  418. pszStartText - pszStartComponent,
  419. &rect,
  420. DT_NOCLIP | DT_NOPREFIX | DT_SINGLELINE );
  421. }
  422. wx += size.cx;
  423. }
  424. if ( pszStartResType )
  425. {
  426. GetTextExtentPoint32( hdc,
  427. pszStartResType,
  428. pszStartText - pszStartResType,
  429. &size );
  430. SetRect( &rect,
  431. wx,
  432. wy,
  433. wx + size.cx,
  434. wy + _tm.tmHeight );
  435. if ( IntersectRect( &rectResult, &ps.rcPaint, &rect ) )
  436. {
  437. SetBkColor( hdc, GetSysColor( COLOR_WINDOW ) );
  438. SetTextColor( hdc, 0x008000 );
  439. DrawText( hdc,
  440. pszStartResType,
  441. pszStartText - pszStartResType,
  442. &rect,
  443. DT_NOCLIP | DT_NOPREFIX | DT_SINGLELINE );
  444. }
  445. wx += size.cx;
  446. }
  447. DrawRestOfLine:
  448. pszCurrent = pszStartText;
  449. while ( *pszCurrent && *pszCurrent != 13 )
  450. {
  451. pszCurrent++;
  452. }
  453. GetTextExtentPoint32( hdc,
  454. pszStartText,
  455. pszCurrent - pszStartText,
  456. &size );
  457. SetRect( &rect,
  458. wx,
  459. wy,
  460. wx + size.cx,
  461. wy + _tm.tmHeight );
  462. if ( IntersectRect( &rectResult, &ps.rcPaint, &rect ) )
  463. {
  464. SetBkColor( hdc, GetSysColor( COLOR_WINDOW ) );
  465. SetTextColor( hdc, GetSysColor( COLOR_WINDOWTEXT ) );
  466. DrawText( hdc,
  467. pszStartText,
  468. pszCurrent - pszStartText,
  469. &rect,
  470. DT_NOCLIP /*| DT_NOPREFIX */ | DT_SINGLELINE );
  471. }
  472. wx += size.cx;
  473. }
  474. SkipLine:
  475. SetRect( &rect,
  476. wx,
  477. wy,
  478. _xWindow,
  479. wy + _tm.tmHeight );
  480. if ( IntersectRect( &rectResult, &ps.rcPaint, &rect ) )
  481. {
  482. HBRUSH hBrush;
  483. hBrush = CreateSolidBrush( GetSysColor( COLOR_WINDOW ) );
  484. FillRect( hdc, &rect, hBrush );
  485. DeleteObject( hBrush );
  486. }
  487. wy += _tm.tmHeight;
  488. y++;
  489. }
  490. SetRect( &rect,
  491. wx,
  492. wy,
  493. _xWindow,
  494. wy + _tm.tmHeight );
  495. if ( IntersectRect( &rectResult, &ps.rcPaint, &rect ) )
  496. {
  497. HBRUSH hBrush;
  498. hBrush = CreateSolidBrush( GetSysColor( COLOR_WINDOW ) );
  499. FillRect( hdc, &rect, hBrush );
  500. DeleteObject( hBrush );
  501. }
  502. SetRect( &rect,
  503. 0,
  504. wy + _tm.tmHeight,
  505. LEFT_MARGIN_SIZE,
  506. _yWindow );
  507. if ( IntersectRect( &rectResult, &ps.rcPaint, &rect ) )
  508. {
  509. HBRUSH hBrush;
  510. hBrush = CreateSolidBrush( GetSysColor( COLOR_GRAYTEXT ) );
  511. FillRect( hdc, &rect, hBrush );
  512. DeleteObject( hBrush );
  513. }
  514. SetRect( &rect,
  515. LEFT_MARGIN_SIZE,
  516. wy + _tm.tmHeight,
  517. _xWindow,
  518. _yWindow );
  519. if ( IntersectRect( &rectResult, &ps.rcPaint, &rect ) )
  520. {
  521. HBRUSH hBrush;
  522. hBrush = CreateSolidBrush( GetSysColor( COLOR_WINDOW ) );
  523. FillRect( hdc, &rect, hBrush );
  524. DeleteObject( hBrush );
  525. }
  526. EndPaint:
  527. EndPaint(_hWnd, &ps);
  528. return 0;
  529. }
  530. //
  531. // _OnCommand( )
  532. //
  533. LRESULT
  534. CFileWindow::_OnCommand(
  535. WPARAM wParam,
  536. LPARAM lParam )
  537. {
  538. UINT cmd = LOWORD(wParam);
  539. switch ( cmd )
  540. {
  541. // Pass these back up
  542. case IDM_OPEN_FILE:
  543. return SendMessage( GetParent( GetParent( _hWnd ) ), WM_COMMAND, IDM_OPEN_FILE, 0 );
  544. case IDM_NEW_FILE:
  545. return SendMessage( GetParent( GetParent( _hWnd ) ), WM_COMMAND, IDM_NEW_FILE, 0 );
  546. default:
  547. break;
  548. }
  549. return DefWindowProc( _hWnd, WM_COMMAND, wParam, lParam);
  550. }
  551. //
  552. // _OnCloseWindow( )
  553. //
  554. LRESULT
  555. CFileWindow::_OnCloseWindow( )
  556. {
  557. return 0;
  558. }
  559. //
  560. // _OnDestroyWindow( )
  561. //
  562. LRESULT
  563. CFileWindow::_OnDestroyWindow( )
  564. {
  565. delete this;
  566. return 0;
  567. }
  568. //
  569. // _OnFocus( )
  570. //
  571. LRESULT
  572. CFileWindow::_OnFocus(
  573. WPARAM wParam,
  574. LPARAM lParam )
  575. {
  576. return 0;
  577. }
  578. //
  579. // _OnKillFocus( )
  580. //
  581. LRESULT
  582. CFileWindow::_OnKillFocus(
  583. WPARAM wParam,
  584. LPARAM lParam )
  585. {
  586. HideCaret( _hWnd );
  587. DestroyCaret( );
  588. return 0;
  589. }
  590. //
  591. // _OnTimer( )
  592. //
  593. LRESULT
  594. CFileWindow::_OnTimer(
  595. WPARAM wParam,
  596. LPARAM lParam )
  597. {
  598. OutputDebugString( "Timer!\n" );
  599. return 0;
  600. }
  601. //
  602. // _OnKeyUp( )
  603. //
  604. BOOL
  605. CFileWindow::_OnKeyUp(
  606. WPARAM wParam,
  607. LPARAM lParam )
  608. {
  609. return FALSE;
  610. }
  611. //
  612. // _OnVerticalScroll( )
  613. //
  614. LRESULT
  615. CFileWindow::_OnVerticalScroll(
  616. WPARAM wParam,
  617. LPARAM lParam )
  618. {
  619. SCROLLINFO si;
  620. INT nScrollCode = LOWORD(wParam); // scroll bar value
  621. INT nPos;
  622. //INT nPos = HIWORD(wParam); // scroll box position
  623. //HWND hwndScrollBar = (HWND) lParam; // handle to scroll bar
  624. si.cbSize = sizeof(si);
  625. si.fMask = SIF_ALL;
  626. GetScrollInfo( _hWnd, SB_VERT, &si );
  627. nPos = si.nPos;
  628. switch( nScrollCode )
  629. {
  630. case SB_BOTTOM:
  631. si.nPos = si.nMax;
  632. break;
  633. case SB_THUMBPOSITION:
  634. si.nPos = nPos;
  635. break;
  636. case SB_THUMBTRACK:
  637. si.nPos = si.nTrackPos;
  638. break;
  639. case SB_TOP:
  640. si.nPos = si.nMin;
  641. break;
  642. case SB_LINEDOWN:
  643. si.nPos += 1;
  644. break;
  645. case SB_LINEUP:
  646. si.nPos -= 1;
  647. break;
  648. case SB_PAGEDOWN:
  649. si.nPos += si.nPage;
  650. break;
  651. case SB_PAGEUP:
  652. si.nPos -= si.nPage;
  653. break;
  654. }
  655. si.fMask = SIF_POS;
  656. SetScrollInfo( _hWnd, SB_VERT, &si, TRUE );
  657. GetScrollInfo( _hWnd, SB_VERT, &si );
  658. if ( si.nPos != nPos )
  659. {
  660. ScrollWindowEx( _hWnd,
  661. 0,
  662. (nPos - si.nPos) * _tm.tmHeight,
  663. NULL,
  664. NULL,
  665. NULL,
  666. NULL,
  667. SW_INVALIDATE );
  668. }
  669. return 0;
  670. }
  671. //
  672. // _OnCreate( )
  673. //
  674. LRESULT
  675. CFileWindow::_OnCreate(
  676. HWND hwnd,
  677. LPCREATESTRUCT pcs )
  678. {
  679. _hWnd = hwnd;
  680. SetWindowLong( _hWnd, GWL_USERDATA, (LONG) this );
  681. _UpdateTitle( );
  682. return 0;
  683. }
  684. //
  685. // _OnSize( )
  686. //
  687. LRESULT
  688. CFileWindow::_OnSize(
  689. LPARAM lParam )
  690. {
  691. HDC hdc;
  692. SIZE size;
  693. HGDIOBJ hObj;
  694. TCHAR szSpace[ 1 ] = { TEXT(' ') };
  695. SCROLLINFO si;
  696. _xWindow = LOWORD( lParam );
  697. _yWindow = HIWORD( lParam );
  698. hdc = GetDC( _hWnd );
  699. hObj = SelectObject( hdc, g_hFont );
  700. GetTextMetrics( hdc, &_tm );
  701. GetTextExtentPoint32( hdc, szSpace, 1, &size );
  702. _xSpace = size.cx;
  703. si.cbSize = sizeof(si);
  704. si.fMask = SIF_RANGE | SIF_PAGE;
  705. si.nMin = 0;
  706. si.nMax = _nLineCount;
  707. si.nPage = _yWindow / _tm.tmHeight;
  708. SetScrollInfo( _hWnd, SB_VERT, &si, FALSE );
  709. // cleanup the HDC
  710. SelectObject( hdc, hObj );
  711. ReleaseDC( _hWnd, hdc );
  712. return 0;
  713. }
  714. //
  715. // _OnMouseWheel( )
  716. //
  717. LRESULT
  718. CFileWindow::_OnMouseWheel( SHORT iDelta )
  719. {
  720. if ( iDelta > 0 )
  721. {
  722. SendMessage( _hWnd, WM_VSCROLL, SB_LINEUP, 0 );
  723. SendMessage( _hWnd, WM_VSCROLL, SB_LINEUP, 0 );
  724. SendMessage( _hWnd, WM_VSCROLL, SB_LINEUP, 0 );
  725. }
  726. else if ( iDelta < 0 )
  727. {
  728. SendMessage( _hWnd, WM_VSCROLL, SB_LINEDOWN, 0 );
  729. SendMessage( _hWnd, WM_VSCROLL, SB_LINEDOWN, 0 );
  730. SendMessage( _hWnd, WM_VSCROLL, SB_LINEDOWN, 0 );
  731. }
  732. return 0;
  733. }
  734. //
  735. // WndProc( )
  736. //
  737. LRESULT CALLBACK
  738. CFileWindow::WndProc(
  739. HWND hWnd,
  740. UINT uMsg,
  741. WPARAM wParam,
  742. LPARAM lParam )
  743. {
  744. CFileWindow * pfw = (CFileWindow *) GetWindowLong( hWnd, GWL_USERDATA );
  745. if ( pfw != NULL )
  746. {
  747. switch( uMsg )
  748. {
  749. case WM_COMMAND:
  750. return pfw->_OnCommand( wParam, lParam );
  751. case WM_PAINT:
  752. return pfw->_OnPaint( wParam, lParam );
  753. case WM_CLOSE:
  754. return pfw->_OnCloseWindow( );
  755. case WM_DESTROY:
  756. SetWindowLong( hWnd, GWL_USERDATA, NULL );
  757. return pfw->_OnDestroyWindow( );
  758. case WM_SETFOCUS:
  759. pfw->_OnFocus( wParam, lParam );
  760. break; // don't return!
  761. case WM_KILLFOCUS:
  762. return pfw->_OnKillFocus( wParam, lParam );
  763. case WM_TIMER:
  764. return pfw->_OnTimer( wParam, lParam );
  765. case WM_SIZE:
  766. return pfw->_OnSize( lParam );
  767. case WM_KEYDOWN:
  768. case WM_SYSKEYDOWN:
  769. if ( pfw->_OnKeyDown( wParam, lParam ) )
  770. return 0;
  771. break; // do default as well
  772. case WM_KEYUP:
  773. case WM_SYSKEYUP:
  774. if ( pfw->_OnKeyUp( wParam, lParam ) )
  775. return 0;
  776. break;
  777. case WM_VSCROLL:
  778. return pfw->_OnVerticalScroll( wParam, lParam );
  779. case WM_MOUSEWHEEL:
  780. return pfw->_OnMouseWheel( HIWORD(wParam) );
  781. }
  782. }
  783. if ( uMsg == WM_CREATE )
  784. {
  785. LPCREATESTRUCT pcs = (LPCREATESTRUCT) lParam;
  786. //LPMDICREATESTRUCT pmdics = (LPMDICREATESTRUCT) pcs->lpCreateParams;
  787. //pfw = (CFileWindow *) pmdics->lParam;
  788. pfw = (CFileWindow *) pcs->lpCreateParams;
  789. return pfw->_OnCreate( hWnd, pcs );
  790. }
  791. if ( uMsg == WM_ERASEBKGND )
  792. {
  793. RECT rect;
  794. RECT rectWnd;
  795. HDC hdc = (HDC) wParam;
  796. HBRUSH hBrush;
  797. #if defined(DEBUG_PAINT)
  798. hBrush = CreateSolidBrush( 0xFF00FF );
  799. #else
  800. hBrush = CreateSolidBrush( GetSysColor( COLOR_GRAYTEXT ) );
  801. #endif
  802. GetClientRect( hWnd, &rectWnd );
  803. SetRect( &rect,
  804. 0,
  805. 0,
  806. LEFT_MARGIN_SIZE,
  807. rectWnd.bottom );
  808. FillRect( hdc, &rect, hBrush );
  809. DeleteObject( hBrush );
  810. #if defined(DEBUG_PAINT)
  811. hBrush = CreateSolidBrush( 0xFF00FF );
  812. #else
  813. hBrush = CreateSolidBrush( GetSysColor( COLOR_WINDOW ) );
  814. #endif
  815. SetRect( &rect,
  816. LEFT_MARGIN_SIZE,
  817. 0,
  818. rectWnd.right,
  819. rectWnd.bottom );
  820. FillRect( hdc, &rect, hBrush );
  821. DeleteObject( hBrush );
  822. return TRUE;
  823. }
  824. return DefWindowProc( hWnd, uMsg, wParam, lParam );
  825. }