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.

241 lines
8.7 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. // Color information
  55. int GetColorList(LPPOINT Res, PLONGLONG *ppColor);
  56. void SetCurColor(int Color) { _BestMatch(NULL, Color, FALSE); }
  57. int GetCurColor() { return _CURCOLOR;}
  58. BOOL IsColorChanged()
  59. {
  60. return (_ORGCOLOR == -1) ? FALSE : (_CURCOLOR != _ORGCOLOR);
  61. }
  62. // Resolution information
  63. int GetResolutionList(int Color, PPOINT *ppRes);
  64. void SetCurResolution(LPPOINT ppt, IN BOOL fAutoSetColorDepth) { _BestMatch(ppt, -1, fAutoSetColorDepth); }
  65. void GetCurResolution(LPPOINT ppt)
  66. {
  67. ppt->x = _CURXRES;
  68. ppt->y = _CURYRES;
  69. }
  70. BOOL IsResolutionChanged()
  71. {
  72. if (_ORGXRES == -1)
  73. return FALSE;
  74. else
  75. return ((_CURXRES != _ORGXRES) && (_CURYRES != _ORGYRES));
  76. }
  77. int GetFrequencyList(int Color, LPPOINT Res, PLONGLONG *ppFreq);
  78. int GetCurFrequency() { return _CURFREQ; }
  79. BOOL IsFrequencyChanged()
  80. {
  81. return (_ORGFREQ == -1) ? FALSE : (_CURFREQ != _ORGFREQ);
  82. }
  83. // Position information
  84. void SetCurPosition(LPPOINT ppt) {_ptCurPos = *ppt;}
  85. void SetOrgPosition(LPPOINT ppt) {_ptOrgPos = *ppt;}
  86. void GetCurPosition(PRECT prc)
  87. {
  88. prc->left = _ptCurPos.x;
  89. prc->top = _ptCurPos.y;
  90. prc->right = _ptCurPos.x + _CURXRES;
  91. prc->bottom = _ptCurPos.y + _CURYRES;
  92. }
  93. void GetOrgPosition(PRECT prc)
  94. {
  95. prc->left = _ptOrgPos.x;
  96. prc->top = _ptOrgPos.y;
  97. prc->right = _ptOrgPos.x + _ORGXRES;
  98. prc->bottom = _ptOrgPos.y + _ORGYRES;
  99. }
  100. void GetPreviewPosition(PRECT prc)
  101. {
  102. *prc = _rcPreview;
  103. }
  104. void SetPreviewPosition(PRECT prc)
  105. {
  106. _rcPreview = *prc;
  107. }
  108. // Adapter & Monitor information
  109. BOOL GetMonitorName(LPTSTR pszName, DWORD cchSize);
  110. BOOL GetMonitorDevice(LPTSTR pszDevice, DWORD cchSize);
  111. // *** IUnknown methods
  112. STDMETHODIMP QueryInterface(REFIID riid, PVOID *ppvObj);
  113. STDMETHODIMP_(ULONG) AddRef(void);
  114. STDMETHODIMP_(ULONG) Release(void);
  115. // *** IDataObject methods
  116. STDMETHODIMP GetData(FORMATETC *pfmtetcIn, STGMEDIUM *pstgmed);
  117. STDMETHODIMP GetDataHere(FORMATETC *pfmtetc, STGMEDIUM *pstgpmed);
  118. STDMETHODIMP QueryGetData(FORMATETC *pfmtetc);
  119. STDMETHODIMP GetCanonicalFormatEtc(FORMATETC *pfmtetcIn, FORMATETC *pfmtetcOut);
  120. STDMETHODIMP SetData(FORMATETC *pfmtetc, STGMEDIUM *pstgmed, BOOL bRelease);
  121. STDMETHODIMP EnumFormatEtc(DWORD dwDirection, IEnumFORMATETC **ppienumFormatEtc);
  122. STDMETHODIMP DAdvise(FORMATETC *pfmtetc, DWORD dwAdviseFlags, IAdviseSink * piadvsink, PDWORD pdwConnection);
  123. STDMETHODIMP DUnadvise(DWORD dwConnection);
  124. STDMETHODIMP EnumDAdvise(IEnumSTATDATA **ppienumStatData);
  125. // Helper functions
  126. STDMETHODIMP CopyDataToStorage(STGMEDIUM *pstgmed, LPTSTR pszOut);
  127. // *** IDisplaySettings methods
  128. STDMETHODIMP SetMonitor(DWORD dwMonitor);
  129. STDMETHODIMP GetModeCount(DWORD* pdwCount, BOOL fOnlyPreferredModes);
  130. STDMETHODIMP GetMode(DWORD dwMode, BOOL fOnlyPreferredModes, DWORD* pdwWidth, DWORD* pdwHeight, DWORD* pdwColor);
  131. STDMETHODIMP SetSelectedMode(HWND hwnd, DWORD dwWidth, DWORD dwHeight, DWORD dwColor, BOOL* pfApplied, DWORD dwFlags);
  132. STDMETHODIMP GetSelectedMode(DWORD* pdwWidth, DWORD* pdwHeight, DWORD* pdwColor);
  133. STDMETHODIMP GetAttached(BOOL* pfAttached);
  134. STDMETHODIMP SetPruningMode(BOOL fIsPruningOn);
  135. STDMETHODIMP GetPruningMode(BOOL* pfCanBePruned, BOOL* pfIsPruningReadOnly, BOOL* pfIsPruningOn);
  136. protected:
  137. // The Display Device we are currently working with.
  138. LPDISPLAY_DEVICE _pDisplayDevice;
  139. ULONG _cpdm;
  140. PMODEARRAY _apdm;
  141. // The current system settings
  142. POINT _ptOrgPos;
  143. LPDEVMODE _pOrgDevmode;
  144. BOOL _fOrgAttached;
  145. // The current CPL settings.
  146. POINT _ptCurPos;
  147. LPDEVMODE _pCurDevmode;
  148. BOOL _fCurAttached;
  149. RECT _rcPreview;
  150. // If the current device is attached to the desktop
  151. BOOL _fUsingDefault;
  152. BOOL _fPrimary;
  153. // Pruning
  154. BOOL _bCanBePruned; // true if raw mode list != pruned mode list
  155. BOOL _bIsPruningReadOnly; // true if can be pruned and pruning mode can be written
  156. BOOL _bIsPruningOn; // true if can be pruned and pruning mode is on
  157. HKEY _hPruningRegKey;
  158. // Orientation
  159. BOOL _bFilterOrientation;
  160. DWORD _dwOrientation;
  161. BOOL _bFilterFixedOutput;
  162. DWORD _dwFixedOutput;
  163. // Ref count for IDataObject
  164. LONG _cRef;
  165. // Private functions
  166. #ifdef DEBUG
  167. void _Dump_CDisplaySettings(BOOL bAll);
  168. void _Dump_CDevmodeList(VOID);
  169. void _Dump_CDevmode(LPDEVMODE pdm);
  170. #endif
  171. int _InsertSortedDwords(int val1, int val2, int cval, int **ppval);
  172. BOOL _AddDevMode(LPDEVMODE lpdm);
  173. void _BestMatch(LPPOINT Res, int Color, IN BOOL fAutoSetColorDepth);
  174. BOOL _ExactMatch(LPDEVMODE lpdm, BOOL bForceVisible);
  175. BOOL _PerfectMatch(LPDEVMODE lpdm);
  176. void _SetCurrentValues(LPDEVMODE lpdm);
  177. int _GetCurrentModeFrequencyList(int Color, LPPOINT Res, PLONGLONG *ppFrequency);
  178. BOOL _MarkMode(LPDEVMODE lpdm);
  179. BOOL _IsCurDevmodeRaw();
  180. BOOL _IsModeVisible(int i);
  181. BOOL _IsModePreferred(int i);
  182. static BOOL _IsModeVisible(CDisplaySettings* pSettings, int i);
  183. // OLE support for extensibility.
  184. void _InitClipboardFormats();
  185. void _FilterModes();
  186. static LPDEVMODEW _lpfnEnumAllModes(LPVOID pContext, DWORD iMode);
  187. static BOOL _lpfnSetSelectedMode(LPVOID pContext, LPDEVMODEW lpdm);
  188. static LPDEVMODEW _lpfnGetSelectedMode(LPVOID pContext);
  189. static VOID _lpfnSetPruningMode(LPVOID pContext, BOOL bIsPruningOn);
  190. static VOID _lpfnGetPruningMode(LPVOID pContext,
  191. BOOL* pbCanBePruned,
  192. BOOL* pbIsPruningReadOnly,
  193. BOOL* pbIsPruningOn);
  194. private:
  195. HRESULT _GetRegKey(LPDEVMODE pDevmode, int * pnIndex, LPTSTR pszRegKey, DWORD cchSize, LPTSTR pszRegValue, DWORD cchValueSize);
  196. };
  197. #endif // SETTINGS_HXX