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.

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