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.

349 lines
8.8 KiB

  1. /*++
  2. Copyright (C) 1996-1999 Microsoft Corporation
  3. Module Name:
  4. srcprop.cpp
  5. Abstract:
  6. Implementation of the Appearance property page.
  7. --*/
  8. #include "polyline.h"
  9. #include <Commdlg.h>
  10. #include "appearprop.h"
  11. #include <pdhmsg.h>
  12. #include "smonmsg.h"
  13. #include "unihelpr.h"
  14. #include "winhelpr.h"
  15. COLORREF CustomColors[16];
  16. CAppearPropPage::CAppearPropPage()
  17. {
  18. m_uIDDialog = IDD_APPEAR_PROPP_DLG;
  19. m_uIDTitle = IDS_APPEAR_PROPP_TITLE;
  20. }
  21. CAppearPropPage::~CAppearPropPage(
  22. void
  23. )
  24. {
  25. return;
  26. }
  27. BOOL
  28. CAppearPropPage::InitControls ( void )
  29. {
  30. BOOL bResult = TRUE;
  31. HWND hWnd;
  32. //
  33. // TODO: This piece of code should not be here to initialize
  34. // global variables
  35. //
  36. for (int i = 0; i < 16; i++) {
  37. CustomColors[i] = RGB(255, 255, 255);
  38. }
  39. hWnd = GetDlgItem( m_hDlg, IDC_COLOROBJECTS );
  40. if( NULL != hWnd ){
  41. CBInsert( hWnd, GraphColor, ResourceString(IDS_COLORCHOICE_GRAPH) );
  42. CBInsert( hWnd, ControlColor, ResourceString(IDS_COLORCHOICE_CONTROL) );
  43. CBInsert( hWnd, TextColor, ResourceString(IDS_COLORCHOICE_TEXT) );
  44. CBInsert( hWnd, GridColor, ResourceString(IDS_COLORCHOICE_GRID) );
  45. CBInsert( hWnd, TimebarColor, ResourceString(IDS_COLORCHOICE_TIMEBAR) );
  46. CBSetSelection( hWnd, 0 );
  47. }
  48. else {
  49. bResult = FALSE;
  50. }
  51. return bResult;
  52. }
  53. void
  54. CAppearPropPage::ColorizeButton()
  55. {
  56. HBRUSH hBrush;
  57. RECT rect;
  58. HWND hWndColorObject = NULL;
  59. HWND hWndColorSample = NULL;
  60. ColorChoices sel;
  61. COLORREF rgbColor;
  62. HDC hDC;
  63. hWndColorObject = GetDlgItem( m_hDlg, IDC_COLOROBJECTS );
  64. hWndColorSample = GetDlgItem( m_hDlg, IDC_COLORSAMPLE );
  65. if (hWndColorObject && hWndColorSample) {
  66. sel = (ColorChoices)CBSelection( hWndColorObject );
  67. rgbColor = (COLORREF)CBData( hWndColorObject, sel );
  68. hDC = GetWindowDC( hWndColorSample );
  69. if( hDC != NULL ) {
  70. hBrush = CreateSolidBrush( rgbColor );
  71. if ( NULL != hBrush ) {
  72. GetClientRect( hWndColorSample, &rect );
  73. OffsetRect(&rect, 3, 3);
  74. FillRect(hDC, &rect, hBrush);
  75. }
  76. ReleaseDC( hWndColorSample, hDC );
  77. }
  78. }
  79. }
  80. void CAppearPropPage::SampleFont()
  81. {
  82. HFONT hFont;
  83. HWND hwndSample;
  84. hwndSample = GetDlgItem( m_hDlg, IDC_FONTSAMPLE );
  85. if ( hwndSample != NULL ){
  86. hFont = CreateFontIndirect( &m_Font );
  87. if( hFont != NULL ){
  88. SendMessage( hwndSample, WM_SETFONT, (WPARAM)hFont, (LPARAM)TRUE );
  89. }
  90. }
  91. }
  92. BOOL
  93. CAppearPropPage::WndProc(
  94. UINT uMsg,
  95. WPARAM /* wParam */,
  96. LPARAM /* lParam */)
  97. {
  98. if( uMsg == WM_CTLCOLORBTN ){
  99. ColorizeButton();
  100. return TRUE;
  101. }
  102. return FALSE;
  103. }
  104. /*
  105. * CAppearPropPage::GetProperties
  106. *
  107. */
  108. BOOL CAppearPropPage::GetProperties(void)
  109. {
  110. BOOL bReturn = TRUE;
  111. ISystemMonitor *pObj;
  112. CImpISystemMonitor *pPrivObj;
  113. IFontDisp* pFontDisp;
  114. LPFONT pIFont;
  115. HFONT hFont;
  116. HRESULT hr;
  117. HWND hWnd;
  118. if (m_cObjects == 0) {
  119. bReturn = FALSE;
  120. } else {
  121. pObj = m_ppISysmon[0];
  122. // Get pointer to actual object for internal methods
  123. pPrivObj = (CImpISystemMonitor*)pObj;
  124. pPrivObj->get_Font( &pFontDisp );
  125. if ( NULL == pFontDisp ) {
  126. bReturn = FALSE;
  127. } else {
  128. hr = pFontDisp->QueryInterface(IID_IFont, (PPVOID)&pIFont);
  129. if (SUCCEEDED(hr)) {
  130. pIFont->get_hFont( &hFont );
  131. GetObject( hFont, sizeof(LOGFONT), &m_Font );
  132. pIFont->Release();
  133. }
  134. SampleFont();
  135. }
  136. hWnd = GetDlgItem( m_hDlg, IDC_COLOROBJECTS );
  137. if( hWnd != NULL ){
  138. OLE_COLOR OleColor;
  139. COLORREF rgbColor;
  140. pPrivObj->get_BackColor( &OleColor );
  141. OleTranslateColor(OleColor, NULL, &rgbColor);
  142. CBSetData( hWnd, GraphColor, rgbColor );
  143. pPrivObj->get_BackColorCtl( &OleColor );
  144. OleTranslateColor(OleColor, NULL, &rgbColor);
  145. CBSetData( hWnd, ControlColor, rgbColor );
  146. pPrivObj->get_ForeColor( &OleColor );
  147. OleTranslateColor(OleColor, NULL, &rgbColor);
  148. CBSetData( hWnd, TextColor, rgbColor );
  149. pPrivObj->get_GridColor( &OleColor );
  150. OleTranslateColor(OleColor, NULL, &rgbColor);
  151. CBSetData( hWnd, GridColor, rgbColor );
  152. pPrivObj->get_TimeBarColor( &OleColor );
  153. OleTranslateColor(OleColor, NULL, &rgbColor);
  154. CBSetData( hWnd, TimebarColor, rgbColor );
  155. ColorizeButton();
  156. }
  157. }
  158. return bReturn;
  159. }
  160. /*
  161. * CAppearPropPage::SetProperties
  162. *
  163. */
  164. BOOL CAppearPropPage::SetProperties(void)
  165. {
  166. BOOL bReturn = TRUE;
  167. IFontDisp* pFontDisp;
  168. ISystemMonitor *pObj;
  169. CImpISystemMonitor *pPrivObj;
  170. if (m_cObjects == 0) {
  171. bReturn = FALSE;
  172. } else {
  173. FONTDESC fd;
  174. pObj = m_ppISysmon[0];
  175. pPrivObj = (CImpISystemMonitor*)pObj;
  176. fd.cbSizeofstruct = sizeof(FONTDESC);
  177. fd.lpstrName = m_Font.lfFaceName;
  178. fd.sWeight = (short)m_Font.lfWeight;
  179. fd.sCharset = m_Font.lfCharSet;
  180. fd.fItalic = m_Font.lfItalic;
  181. fd.fUnderline = m_Font.lfUnderline;
  182. fd.fStrikethrough = m_Font.lfStrikeOut;
  183. long lfHeight = m_Font.lfHeight;
  184. int ppi;
  185. HDC hdc;
  186. if (lfHeight < 0){
  187. lfHeight = -lfHeight;
  188. }
  189. hdc = ::GetDC(GetDesktopWindow());
  190. ppi = GetDeviceCaps(hdc, LOGPIXELSY);
  191. ::ReleaseDC(GetDesktopWindow(), hdc);
  192. fd.cySize.Lo = lfHeight * 720000 / ppi;
  193. fd.cySize.Hi = 0;
  194. OleCreateFontIndirect(&fd, IID_IFontDisp, (void**) &pFontDisp);
  195. pPrivObj->putref_Font( pFontDisp );
  196. pFontDisp->Release();
  197. HWND hWnd = GetDlgItem( m_hDlg, IDC_COLOROBJECTS );
  198. if( hWnd != NULL ){
  199. COLORREF OleColor;
  200. OleColor = (OLE_COLOR)CBData( hWnd, GraphColor );
  201. pPrivObj->put_BackColor( OleColor );
  202. OleColor = (OLE_COLOR)CBData( hWnd, ControlColor );
  203. pPrivObj->put_BackColorCtl( OleColor );
  204. OleColor = (OLE_COLOR)CBData( hWnd, TextColor );
  205. pPrivObj->put_ForeColor( OleColor );
  206. OleColor = (OLE_COLOR)CBData( hWnd, GridColor );
  207. pPrivObj->put_GridColor( OleColor );
  208. OleColor = (OLE_COLOR)CBData( hWnd, TimebarColor );
  209. pPrivObj->put_TimeBarColor( OleColor );
  210. }
  211. }
  212. return bReturn;
  213. }
  214. void
  215. CAppearPropPage::DialogItemChange(
  216. WORD wID,
  217. WORD /* wMsg */)
  218. {
  219. BOOL bChanged = FALSE;
  220. switch (wID) {
  221. case IDC_COLOROBJECTS:
  222. ColorizeButton();
  223. break;
  224. case IDC_COLORSAMPLE:
  225. case IDC_COLORBUTTON:
  226. {
  227. CHOOSECOLOR cc;
  228. COLORREF rgbColor;
  229. HWND hWnd;
  230. hWnd = GetDlgItem( m_hDlg, IDC_COLOROBJECTS );
  231. if ( NULL != hWnd ) {
  232. ColorChoices sel = (ColorChoices)CBSelection( hWnd );
  233. rgbColor = (COLORREF)CBData( hWnd, sel );
  234. ZeroMemory(&cc, sizeof(CHOOSECOLOR));
  235. cc.lStructSize = sizeof(CHOOSECOLOR);
  236. cc.lpCustColors = CustomColors;
  237. cc.hwndOwner = m_hDlg;
  238. cc.Flags = CC_RGBINIT;
  239. cc.rgbResult = rgbColor;
  240. if ( ChooseColor(&cc) ) {
  241. CBSetData( hWnd, sel, cc.rgbResult );
  242. ColorizeButton();
  243. bChanged = TRUE;
  244. }
  245. }
  246. break;
  247. }
  248. case IDC_FONTBUTTON:
  249. case IDC_FONTSAMPLE:
  250. {
  251. CHOOSEFONT cf;
  252. LOGFONT lf;
  253. memset(&cf, 0, sizeof(CHOOSEFONT));
  254. memcpy( &lf, &m_Font, sizeof(LOGFONT) );
  255. cf.lStructSize = sizeof(CHOOSEFONT);
  256. cf.hwndOwner = m_hDlg;
  257. cf.lpLogFont = &lf; // give initial font
  258. cf.Flags = CF_INITTOLOGFONTSTRUCT | CF_FORCEFONTEXIST | CF_SCREENFONTS;
  259. cf.nSizeMin = 5;
  260. cf.nSizeMax = 50;
  261. if( ChooseFont(&cf) ){
  262. memcpy( &m_Font, &lf, sizeof(LOGFONT) );
  263. SampleFont();
  264. bChanged = TRUE;
  265. }
  266. break;
  267. }
  268. }
  269. if ( bChanged == TRUE ) {
  270. SetChange();
  271. }
  272. }