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.

243 lines
8.6 KiB

  1. /**************************************************************************\
  2. * Module Name: settings.hxx
  3. *
  4. * CDeviceSettings class
  5. *
  6. * This class is in charge of all the settings specific to one display
  7. * device. Including Screen Size, Color Depth, Font size.
  8. *
  9. * Copyright (c) Microsoft Corp. 1992-1998 All Rights Reserved
  10. *
  11. \**************************************************************************/
  12. #ifndef SETTINGS_HXX
  13. #define SETTINGS_HXX
  14. #define MAKEXYRES(p,xval,yval) ((p)->x = xval, (p)->y = yval)
  15. #define _CURXRES ((_pCurDevmode != NULL) ? (int)_pCurDevmode->dmPelsWidth : -1)
  16. #define _CURYRES ((_pCurDevmode != NULL) ? (int)_pCurDevmode->dmPelsHeight : -1)
  17. #define _ORGXRES ((_pOrgDevmode != NULL) ? (int)_pOrgDevmode->dmPelsWidth : -1)
  18. #define _ORGYRES ((_pOrgDevmode != NULL) ? (int)_pOrgDevmode->dmPelsHeight : -1)
  19. #define _CURCOLOR ((_pCurDevmode != NULL) ? (int)_pCurDevmode->dmBitsPerPel : -1)
  20. #define _ORGCOLOR ((_pOrgDevmode != NULL) ? (int)_pOrgDevmode->dmBitsPerPel : -1)
  21. #define _CURFREQ ((_pCurDevmode != NULL) ? (int)_pCurDevmode->dmDisplayFrequency : -1)
  22. #define _ORGFREQ ((_pOrgDevmode != NULL) ? (int)_pOrgDevmode->dmDisplayFrequency : -1)
  23. #define MODE_INVALID 0x00000001
  24. #define MODE_RAW 0x00000002
  25. typedef struct _MODEARRAY {
  26. DWORD dwFlags;
  27. LPDEVMODE lpdm;
  28. } MODEARRAY, *PMODEARRAY;
  29. HRESULT CDisplaySettings_CreateInstance(IN IUnknown * punkOuter, IN REFIID riid, OUT LPVOID * ppvObj);
  30. class CDisplaySettings : public IDataObject,
  31. public IDisplaySettings
  32. {
  33. public:
  34. CDisplaySettings();
  35. ~CDisplaySettings();
  36. // General Settings support
  37. BOOL InitSettings(LPDISPLAY_DEVICE pDisplay);
  38. int SaveSettings(DWORD dwSet);
  39. int RestoreSettings();
  40. BOOL ConfirmChangeSettings();
  41. BOOL IsKnownSafe();
  42. BOOL bIsModeChanged() {return _pCurDevmode != _pOrgDevmode;}
  43. // Device Settings
  44. void SetPrimary(BOOL fPrimary) { _fPrimary = fPrimary; };
  45. void SetAttached(BOOL fAttached) { _fCurAttached = fAttached; };
  46. BOOL IsPrimary() { return _fPrimary; };
  47. BOOL IsAttached() { return _fCurAttached; };
  48. BOOL IsOrgAttached() { return _fOrgAttached; };
  49. BOOL IsSmallFontNecessary();
  50. BOOL IsRemovable()
  51. {
  52. return ((_pDisplayDevice->StateFlags & DISPLAY_DEVICE_REMOVABLE) != 0);
  53. }
  54. LPDEVMODE GetCurrentDevMode(void);
  55. // Color information
  56. int GetColorList(LPPOINT Res, PLONGLONG *ppColor);
  57. void SetCurColor(int Color) { _BestMatch(NULL, Color, FALSE); }
  58. int GetCurColor() { return _CURCOLOR;}
  59. BOOL IsColorChanged()
  60. {
  61. return (_ORGCOLOR == -1) ? FALSE : (_CURCOLOR != _ORGCOLOR);
  62. }
  63. // Resolution information
  64. int GetResolutionList(int Color, PPOINT *ppRes);
  65. void SetCurResolution(LPPOINT ppt, IN BOOL fAutoSetColorDepth) { _BestMatch(ppt, -1, fAutoSetColorDepth); }
  66. void GetCurResolution(LPPOINT ppt)
  67. {
  68. ppt->x = _CURXRES;
  69. ppt->y = _CURYRES;
  70. }
  71. BOOL IsResolutionChanged()
  72. {
  73. if (_ORGXRES == -1)
  74. return FALSE;
  75. else
  76. return ((_CURXRES != _ORGXRES) && (_CURYRES != _ORGYRES));
  77. }
  78. int GetFrequencyList(int Color, LPPOINT Res, PLONGLONG *ppFreq);
  79. void SetCurFrequency(int Frequency);
  80. int GetCurFrequency() { return _CURFREQ; }
  81. BOOL IsFrequencyChanged()
  82. {
  83. return (_ORGFREQ == -1) ? FALSE : (_CURFREQ != _ORGFREQ);
  84. }
  85. // Position information
  86. void SetCurPosition(LPPOINT ppt) {_ptCurPos = *ppt;}
  87. void SetOrgPosition(LPPOINT ppt) {_ptOrgPos = *ppt;}
  88. void GetCurPosition(PRECT prc)
  89. {
  90. prc->left = _ptCurPos.x;
  91. prc->top = _ptCurPos.y;
  92. prc->right = _ptCurPos.x + _CURXRES;
  93. prc->bottom = _ptCurPos.y + _CURYRES;
  94. }
  95. void GetOrgPosition(PRECT prc)
  96. {
  97. prc->left = _ptOrgPos.x;
  98. prc->top = _ptOrgPos.y;
  99. prc->right = _ptOrgPos.x + _ORGXRES;
  100. prc->bottom = _ptOrgPos.y + _ORGYRES;
  101. }
  102. void GetPreviewPosition(PRECT prc)
  103. {
  104. *prc = _rcPreview;
  105. }
  106. void SetPreviewPosition(PRECT prc)
  107. {
  108. _rcPreview = *prc;
  109. }
  110. // Adapter & Monitor information
  111. BOOL GetMonitorName(LPTSTR pszName, DWORD cchSize);
  112. BOOL GetMonitorDevice(LPTSTR pszDevice);
  113. HRESULT GetDevInstID(LPTSTR lpszDeviceKey, STGMEDIUM *pstgmed);
  114. // *** IUnknown methods
  115. STDMETHODIMP QueryInterface(REFIID riid, PVOID *ppvObj);
  116. STDMETHODIMP_(ULONG) AddRef(void);
  117. STDMETHODIMP_(ULONG) Release(void);
  118. // *** IDataObject methods
  119. STDMETHODIMP GetData(FORMATETC *pfmtetcIn, STGMEDIUM *pstgmed);
  120. STDMETHODIMP GetDataHere(FORMATETC *pfmtetc, STGMEDIUM *pstgpmed);
  121. STDMETHODIMP QueryGetData(FORMATETC *pfmtetc);
  122. STDMETHODIMP GetCanonicalFormatEtc(FORMATETC *pfmtetcIn, FORMATETC *pfmtetcOut);
  123. STDMETHODIMP SetData(FORMATETC *pfmtetc, STGMEDIUM *pstgmed, BOOL bRelease);
  124. STDMETHODIMP EnumFormatEtc(DWORD dwDirection, IEnumFORMATETC **ppienumFormatEtc);
  125. STDMETHODIMP DAdvise(FORMATETC *pfmtetc, DWORD dwAdviseFlags, IAdviseSink * piadvsink, PDWORD pdwConnection);
  126. STDMETHODIMP DUnadvise(DWORD dwConnection);
  127. STDMETHODIMP EnumDAdvise(IEnumSTATDATA **ppienumStatData);
  128. // Helper functions
  129. STDMETHODIMP CopyDataToStorage(STGMEDIUM *pstgmed, LPTSTR pszOut);
  130. // *** IDisplaySettings methods
  131. STDMETHODIMP SetMonitor(DWORD dwMonitor);
  132. STDMETHODIMP GetModeCount(DWORD* pdwCount, BOOL fOnlyPreferredModes);
  133. STDMETHODIMP GetMode(DWORD dwMode, BOOL fOnlyPreferredModes, DWORD* pdwWidth, DWORD* pdwHeight, DWORD* pdwColor);
  134. STDMETHODIMP SetSelectedMode(HWND hwnd, DWORD dwWidth, DWORD dwHeight, DWORD dwColor, BOOL* pfApplied, DWORD dwFlags);
  135. STDMETHODIMP GetSelectedMode(DWORD* pdwWidth, DWORD* pdwHeight, DWORD* pdwColor);
  136. STDMETHODIMP GetAttached(BOOL* pfAttached);
  137. STDMETHODIMP SetPruningMode(BOOL fIsPruningOn);
  138. STDMETHODIMP GetPruningMode(BOOL* pfCanBePruned, BOOL* pfIsPruningReadOnly, BOOL* pfIsPruningOn);
  139. protected:
  140. // The Display Device we are currently working with.
  141. LPDISPLAY_DEVICE _pDisplayDevice;
  142. ULONG _cpdm;
  143. PMODEARRAY _apdm;
  144. // The current system settings
  145. POINT _ptOrgPos;
  146. LPDEVMODE _pOrgDevmode;
  147. BOOL _fOrgAttached;
  148. // The current CPL settings.
  149. POINT _ptCurPos;
  150. LPDEVMODE _pCurDevmode;
  151. BOOL _fCurAttached;
  152. RECT _rcPreview;
  153. // If the current device is attached to the desktop
  154. BOOL _fUsingDefault;
  155. BOOL _fPrimary;
  156. // Pruning
  157. BOOL _bCanBePruned; // true if raw mode list != pruned mode list
  158. BOOL _bIsPruningReadOnly; // true if can be pruned and pruning mode can be written
  159. BOOL _bIsPruningOn; // true if can be pruned and pruning mode is on
  160. HKEY _hPruningRegKey;
  161. // Orientation
  162. BOOL _bFilterOrientation;
  163. DWORD _dwOrientation;
  164. BOOL _bFilterFixedOutput;
  165. DWORD _dwFixedOutput;
  166. // Ref count for IDataObject
  167. LONG _cRef;
  168. // Private functions
  169. void _Dump_CDisplaySettings(BOOL bAll);
  170. void _Dump_CDevmodeList(VOID);
  171. void _Dump_CDevmode(LPDEVMODE pdm);
  172. int _InsertSortedDwords(int val1, int val2, int cval, int **ppval);
  173. BOOL _AddDevMode(LPDEVMODE lpdm);
  174. void _BestMatch(LPPOINT Res, int Color, IN BOOL fAutoSetColorDepth);
  175. BOOL _ExactMatch(LPDEVMODE lpdm, BOOL bForceVisible);
  176. BOOL _PerfectMatch(LPDEVMODE lpdm);
  177. void _SetCurrentValues(LPDEVMODE lpdm);
  178. int _GetCurrentModeFrequencyList(int Color, LPPOINT Res, PLONGLONG *ppFrequency);
  179. BOOL _MarkMode(LPDEVMODE lpdm);
  180. BOOL _IsCurDevmodeRaw();
  181. BOOL _IsModeVisible(int i);
  182. BOOL _IsModePreferred(int i);
  183. static BOOL _IsModeVisible(CDisplaySettings* pSettings, int i);
  184. // OLE support for extensibility.
  185. void _InitClipboardFormats();
  186. void _FilterModes();
  187. void _SetFilterOptions(LPCTSTR pszDeviceName, LPDEVMODEW lpdm);
  188. static LPDEVMODEW _lpfnEnumAllModes(LPVOID pContext, DWORD iMode);
  189. static BOOL _lpfnSetSelectedMode(LPVOID pContext, LPDEVMODEW lpdm);
  190. static LPDEVMODEW _lpfnGetSelectedMode(LPVOID pContext);
  191. static VOID _lpfnSetPruningMode(LPVOID pContext, BOOL bIsPruningOn);
  192. static VOID _lpfnGetPruningMode(LPVOID pContext,
  193. BOOL* pbCanBePruned,
  194. BOOL* pbIsPruningReadOnly,
  195. BOOL* pbIsPruningOn);
  196. private:
  197. HRESULT _GetRegKey(LPDEVMODE pDevmode, int * pnIndex, LPTSTR pszRegKey, DWORD cchSize, LPTSTR pszRegValue, DWORD cchValueSize);
  198. };
  199. #endif // SETTINGS_HXX