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.

152 lines
3.2 KiB

  1. /*
  2. * _DEVDSC.H
  3. *
  4. * Purpose:
  5. * CDevDesc (Device Descriptor) class
  6. *
  7. * Authors:
  8. * Original RichEdit code: David R. Fulmer
  9. * Christian Fortini
  10. * Murray Sargent
  11. */
  12. #ifndef _DEVDSC_H
  13. #define _DEVDSC_H
  14. class CTxtEdit;
  15. // device descriptor
  16. class CDevDesc
  17. {
  18. friend class CMeasurer;
  19. protected:
  20. CTxtEdit * _ped; // used to GetDC and ReleaseDC
  21. HDC _hdc; // hdc for rendering device
  22. BOOL _fMetafile; // Is this device a metafile.
  23. SHORT _dxpInch; // device units per horizontal "inch"
  24. SHORT _dypInch; // device units per vertical "inch"
  25. HDC GetScreenDC () const;
  26. void ReleaseScreenDC (HDC hdc) const;
  27. public:
  28. CDevDesc(CTxtEdit * ped)
  29. {
  30. _fMetafile = FALSE;
  31. _ped = ped;
  32. _dxpInch = 0;
  33. _hdc = NULL;
  34. _dypInch = 0;
  35. }
  36. // Test validity of device descriptor
  37. // (whether SetDC has been properly called)
  38. BOOL IsValid() const {return _dxpInch != 0 && _dypInch != 0;}
  39. BOOL IsMetafile() const
  40. {
  41. if(!_hdc)
  42. return FALSE;
  43. return _fMetafile;
  44. }
  45. BOOL SetDC(HDC hdc, LONG dxpInch = -1, LONG dypInch = -1);
  46. void SetMetafileDC(
  47. HDC hdcMetafile,
  48. LONG xMeasurePerInch,
  49. LONG yMeasurePerInch);
  50. void ResetDC() { SetDC(NULL); }
  51. //REVIEW (keithcu) GetScreenDC/ReleaseScreenDC needed?
  52. HDC GetDC() const
  53. {
  54. if(_hdc)
  55. return _hdc;
  56. return GetScreenDC();
  57. }
  58. void ReleaseDC(HDC hdc) const
  59. {
  60. if(!_hdc)
  61. ReleaseScreenDC(hdc);
  62. }
  63. // Methods for converting between pixels and himetric
  64. LONG HimetricXtoDX(LONG xHimetric) const { return W32->HimetricXtoDX(xHimetric, _dxpInch); }
  65. LONG HimetricYtoDY(LONG yHimetric) const { return W32->HimetricYtoDY(yHimetric, _dypInch); }
  66. LONG DXtoHimetricX(LONG dx) const { return W32->DXtoHimetricX(dx, _dxpInch); }
  67. LONG DYtoHimetricY(LONG dy) const { return W32->DYtoHimetricY(dy, _dypInch); }
  68. LONG DXtoLX(LONG x) const;
  69. LONG DYtoLY(LONG y) const;
  70. void DPtoLP(POINT &ptDest, const POINT &ptSrc) const;
  71. void DRtoLR(RECT &rcDest, const RECT &rcSrc) const;
  72. #ifdef DEBUG
  73. LONG LXtoDX(LONG x) const;
  74. LONG LYtoDY(LONG y) const;
  75. #else
  76. LONG LXtoDX(LONG x) const {return ((x * _dxpInch) + LX_PER_INCH / 2) / LX_PER_INCH;}
  77. LONG LYtoDY(LONG y) const {return ((y * _dypInch) + LY_PER_INCH / 2) / LY_PER_INCH;}
  78. #endif
  79. void LPtoDP(POINT &ptDest, const POINT &ptSrc) const;
  80. void LRtoDR(RECT &rcDest, const RECT &rcSrc) const;
  81. BOOL SameDevice(const CDevDesc *pdd) const
  82. {
  83. return (_dxpInch == pdd->_dxpInch) && (_dypInch == pdd->_dypInch)
  84. ? TRUE : FALSE;
  85. }
  86. LONG ConvertXToDev(LONG x, const CDevDesc *pdd) const
  87. {
  88. return MulDiv(x, _dxpInch, pdd->_dxpInch);
  89. }
  90. LONG ConvertYToDev(LONG y, const CDevDesc *pdd) const
  91. {
  92. return MulDiv(y, _dypInch, pdd->_dxpInch);
  93. }
  94. // Assignment
  95. CDevDesc& operator = (const CDevDesc& dd)
  96. {
  97. _hdc = dd._hdc;
  98. _dxpInch = dd._dxpInch;
  99. _dypInch = dd._dypInch;
  100. return *this;
  101. }
  102. // Compares two device descriptors
  103. BOOL operator == (const CDevDesc& dd) const
  104. {
  105. return _hdc == dd._hdc;
  106. }
  107. BOOL operator != (const CDevDesc& dd) const
  108. {
  109. return !(*this == dd);
  110. }
  111. LONG GetDxpInch() const
  112. {
  113. AssertSz(_dxpInch != 0, "CDevDesc::GetDxpInch_dxpInch is 0");
  114. return _dxpInch;
  115. }
  116. LONG GetDypInch() const
  117. {
  118. AssertSz(_dypInch != 0, "CDevDesc::GetDypInch _dypInch is 0");
  119. return _dypInch;
  120. }
  121. };
  122. #endif