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.

276 lines
7.2 KiB

  1. // LogViewer.cpp : Implementation of CLogViewer
  2. #include "precomp.h"
  3. #include "LogViewer.h"
  4. #include "viewlog.h"
  5. extern HWND g_hwndIssues;
  6. extern BOOL g_bInternalMode;
  7. extern void RefreshLog(HWND hDlg);
  8. extern void ExportSelectedLog(HWND hDlg);
  9. extern void DeleteSelectedLog(HWND hDlg);
  10. extern void DeleteAllLogs(HWND hDlg);
  11. extern void FillTreeView(HWND hDlg);
  12. extern void SetDescriptionText(HWND hDlg, CProcessLogEntry* pEntry);
  13. //
  14. // Stores information about children windows within
  15. // the logviewer window.
  16. //
  17. CHILDINFO g_rgChildInfo[NUM_CHILDREN];
  18. //
  19. // Used to show error messages versus showing all messages.
  20. //
  21. extern VLOG_LEVEL g_eMinLogLevel;
  22. // CLogViewer
  23. HWND
  24. CLogViewer::CreateControlWindow(
  25. HWND hwndParent,
  26. RECT& rcPos
  27. )
  28. {
  29. UINT uIndex;
  30. RECT rcTemp = {0};
  31. HWND hWnd;
  32. hWnd = CComCompositeControl<CLogViewer>::CreateControlWindow(hwndParent, rcPos);
  33. g_hwndIssues = GetDlgItem(IDC_ISSUES);
  34. //
  35. // Store the coordinates for the parent in the first element.
  36. //
  37. g_rgChildInfo[0].uChildId = 0;
  38. g_rgChildInfo[0].hWnd = hWnd;
  39. ::GetWindowRect(hWnd, &g_rgChildInfo[0].rcParent);
  40. //
  41. // Fill in the array of CHILDINFO structs which helps handle sizing
  42. // of the child controls.
  43. //
  44. g_rgChildInfo[VIEW_EXPORTED_LOG_INDEX].uChildId = IDC_VIEW_EXPORTED_LOG;
  45. g_rgChildInfo[DELETE_LOG_INDEX].uChildId = IDC_BTN_DELETE_LOG;
  46. g_rgChildInfo[DELETE_ALL_LOGS_INDEX].uChildId = IDC_BTN_DELETE_ALL;
  47. g_rgChildInfo[ISSUES_INDEX].uChildId = IDC_ISSUES;
  48. g_rgChildInfo[SOLUTIONS_STATIC_INDEX].uChildId = IDC_SOLUTIONS_STATIC;
  49. g_rgChildInfo[ISSUE_DESCRIPTION_INDEX].uChildId = IDC_ISSUE_DESCRIPTION;
  50. for (uIndex = 1; uIndex <= NUM_CHILDREN; uIndex++) {
  51. g_rgChildInfo[uIndex].hWnd = GetDlgItem(g_rgChildInfo[uIndex].uChildId);
  52. ::GetWindowRect(g_rgChildInfo[uIndex].hWnd,
  53. &g_rgChildInfo[uIndex].rcChild);
  54. ::MapWindowPoints(NULL,
  55. hWnd,
  56. (LPPOINT)&g_rgChildInfo[uIndex].rcChild,
  57. 2);
  58. }
  59. CheckDlgButton(IDC_SHOW_ERRORS, BST_CHECKED);
  60. return hWnd;
  61. }
  62. LRESULT
  63. CLogViewer::OnInitDialog(
  64. UINT uMsg,
  65. WPARAM wParam,
  66. LPARAM lParam,
  67. BOOL& bHandled
  68. )
  69. {
  70. HWND hWndTree = GetDlgItem(IDC_ISSUES);
  71. ::SetFocus(hWndTree);
  72. bHandled = TRUE;
  73. return FALSE;
  74. }
  75. LRESULT
  76. CLogViewer::OnButtonDown(
  77. WORD wNotifyCode,
  78. WORD wID,
  79. HWND hWndCtl,
  80. BOOL& bHandled
  81. )
  82. {
  83. bHandled = TRUE;
  84. switch(wID) {
  85. case IDC_EXPORT_LOG:
  86. ExportSelectedLog(static_cast<HWND>(*this));
  87. break;
  88. case IDC_BTN_DELETE_LOG:
  89. DeleteSelectedLog(static_cast<HWND>(*this));
  90. SetDescriptionText(static_cast<HWND>(*this), NULL);
  91. break;
  92. case IDC_BTN_DELETE_ALL:
  93. DeleteAllLogs(static_cast<HWND>(*this));
  94. SetDescriptionText(static_cast<HWND>(*this), NULL);
  95. break;
  96. case IDC_SHOW_ERRORS:
  97. g_eMinLogLevel = VLOG_LEVEL_WARNING;
  98. *g_szSingleLogFile = TEXT('\0');
  99. RefreshLog(static_cast<HWND>(*this));
  100. break;
  101. case IDC_SHOW_ALL:
  102. g_eMinLogLevel = VLOG_LEVEL_INFO;
  103. *g_szSingleLogFile = TEXT('\0');
  104. RefreshLog(static_cast<HWND>(*this));
  105. break;
  106. default:
  107. bHandled = FALSE;
  108. }
  109. return TRUE;
  110. }
  111. LRESULT
  112. CLogViewer::OnNotify(
  113. UINT uMsg,
  114. WPARAM wParam,
  115. LPARAM lParam,
  116. BOOL& bHandled
  117. )
  118. {
  119. LRESULT lResult = DlgViewLog(static_cast<HWND>(*this),
  120. uMsg,
  121. wParam,
  122. lParam);
  123. bHandled = (lResult) ? TRUE : FALSE;
  124. return lResult;
  125. }
  126. //
  127. // We receive this when the dialog is being displayed.
  128. //
  129. LRESULT
  130. CLogViewer::OnSetFocus(
  131. UINT uMsg,
  132. WPARAM wParam,
  133. LPARAM lParam,
  134. BOOL& bHandled
  135. )
  136. {
  137. *g_szSingleLogFile = TEXT('\0');
  138. RefreshLog(static_cast<HWND>(*this));
  139. bHandled = FALSE;
  140. return 0;
  141. }
  142. LRESULT
  143. CLogViewer::OnSize(
  144. UINT uMsg,
  145. WPARAM wParam,
  146. LPARAM lParam,
  147. BOOL& bHandled
  148. )
  149. {
  150. HDC hdc;
  151. TEXTMETRIC tm;
  152. RECT rcViewSessionLog, rcDeleteAllLogs;
  153. RECT rcViewExportedLog, rcExportLog;
  154. RECT rcDeleteLog, rcDlg;
  155. int nWidth, nHeight;
  156. int nCurWidth, nCurHeight;
  157. int nDeltaW, nDeltaH;
  158. nWidth = LOWORD(lParam);
  159. nHeight = HIWORD(lParam);
  160. GetWindowRect(&rcDlg);
  161. nCurWidth = rcDlg.right - rcDlg.left;
  162. nCurHeight = rcDlg.bottom - rcDlg.top;
  163. nDeltaW = (g_rgChildInfo[0].rcParent.right -
  164. g_rgChildInfo[0].rcParent.left) -
  165. nCurWidth;
  166. nDeltaH = (g_rgChildInfo[0].rcParent.bottom -
  167. g_rgChildInfo[0].rcParent.top) -
  168. nCurHeight;
  169. //
  170. // If below a certain size, just proceed as if that size.
  171. // This way, if the user makes the window really small, all our
  172. // controls won't just scrunch up. Better way would be to make it
  173. // impossible for the user to make the window this small, but devenv
  174. // doesn't pass the WM_SIZING message to the ActiveX control.
  175. //
  176. if (nWidth < 550) {
  177. nWidth = 550;
  178. }
  179. if (nHeight < 225) {
  180. nHeight = 225;
  181. }
  182. hdc = GetDC();
  183. GetTextMetrics(hdc, &tm);
  184. ReleaseDC(hdc);
  185. //
  186. // Adjust the treeview. The top left corner does not move.
  187. // It either gets wider/more narrow or taller/shorter.
  188. //
  189. /*::SetWindowPos(g_rgChildInfo[ISSUES_INDEX].hWnd,
  190. NULL,
  191. 0,
  192. 0,
  193. (g_rgChildInfo[ISSUES_INDEX].rcChild.right -
  194. g_rgChildInfo[ISSUES_INDEX].rcChild.left) +
  195. nDeltaW,
  196. (g_rgChildInfo[ISSUES_INDEX].rcChild.bottom -
  197. g_rgChildInfo[ISSUES_INDEX].rcChild.top) +
  198. nDeltaH,
  199. SWP_NOZORDER | SWP_NOMOVE | SWP_NOACTIVATE);*/
  200. //
  201. // Move description window and to bottom of screen.
  202. //
  203. ::MoveWindow(GetDlgItem(IDC_ISSUE_DESCRIPTION), tm.tmMaxCharWidth,
  204. nHeight - (nHeight/4 + tm.tmHeight),
  205. nWidth - 2*tm.tmMaxCharWidth, nHeight/4, FALSE);
  206. //
  207. // Move caption to right above that.
  208. //
  209. ::MoveWindow(GetDlgItem(IDC_SOLUTIONS_STATIC), tm.tmMaxCharWidth,
  210. nHeight - (2*tm.tmHeight + nHeight/4),
  211. nWidth-2*tm.tmMaxCharWidth, tm.tmHeight, FALSE);
  212. //
  213. // Expand treeview to fill in empty space.
  214. //
  215. ::MoveWindow(GetDlgItem(IDC_ISSUES), tm.tmMaxCharWidth,
  216. tm.tmHeight*4, nWidth-2*tm.tmMaxCharWidth, nHeight - (6*tm.tmHeight+nHeight/4), FALSE);
  217. InvalidateRect(NULL);
  218. bHandled = TRUE;
  219. //::GetWindowRect(g_hWndLogViewer, &g_rgChildInfo[0].rcParent);
  220. return 0;
  221. }
  222. HRESULT
  223. STDMETHODCALLTYPE
  224. CLogViewer::Refresh(
  225. void
  226. )
  227. {
  228. *g_szSingleLogFile = TEXT('\0');
  229. RefreshLog(static_cast<HWND>(*this));
  230. return S_OK;
  231. }