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.

151 lines
3.3 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. _hdc = NULL;
  33. _dxpInch = 0;
  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. // REVIEW (keithcu) Verify callers of these routines logic...Think of a way to make it hard for people
  64. // to screw up?
  65. // Methods for converting between pixels and himetric
  66. LONG HimetricXtoDX(LONG xHimetric) const { return W32->HimetricToDevice(xHimetric, _dxpInch); }
  67. LONG HimetricYtoDY(LONG yHimetric) const { return W32->HimetricToDevice(yHimetric, _dypInch); }
  68. LONG DXtoHimetricX(LONG dx) const { return W32->DeviceToHimetric(dx, _dxpInch); }
  69. LONG DYtoHimetricY(LONG dy) const { return W32->DeviceToHimetric(dy, _dypInch); }
  70. void LRtoDR(RECT &rcDest, const RECT &rcSrc, TFLOW tflow) const;
  71. LONG DXtoLX(LONG x) const
  72. {
  73. AssertSz(_dxpInch, "CDevDesc::DXtoLX() - hdc has not been set");
  74. return MulDiv(x, LX_PER_INCH, _dxpInch);
  75. }
  76. LONG DYtoLY(LONG y) const
  77. {
  78. AssertSz(_dypInch, "CDevDesc::DYtoLY() - hdc has not been set");
  79. return MulDiv(y, LY_PER_INCH, _dypInch);
  80. }
  81. LONG LXtoDX(LONG x) const
  82. {
  83. AssertSz(_dxpInch, "CDevDesc::LXtoDX() - hdc has not been set");
  84. return MulDiv(x, _dxpInch, LX_PER_INCH);
  85. }
  86. LONG LYtoDY(LONG y) const
  87. {
  88. AssertSz(_dypInch, "CDevDesc::LYtoDY() - hdc has not been set");
  89. return MulDiv(y, _dypInch, LY_PER_INCH);
  90. }
  91. BOOL SameDevice(const CDevDesc *pdd) const
  92. {
  93. return (_dxpInch == pdd->_dxpInch) && (_dypInch == pdd->_dypInch) ? TRUE : FALSE;
  94. }
  95. // Assignment
  96. CDevDesc& operator = (const CDevDesc& dd)
  97. {
  98. _hdc = dd._hdc;
  99. _dxpInch = dd._dxpInch;
  100. _dypInch = dd._dypInch;
  101. return *this;
  102. }
  103. // Compares two device descriptors
  104. BOOL operator == (const CDevDesc& dd) const
  105. {
  106. return _hdc == dd._hdc;
  107. }
  108. BOOL operator != (const CDevDesc& dd) const
  109. {
  110. return !(*this == dd);
  111. }
  112. LONG GetDxpInch() const
  113. {
  114. AssertSz(_dxpInch != 0, "CDevDesc::GetDxpInch _dxpInch is 0");
  115. return _dxpInch;
  116. }
  117. LONG GetDypInch() const
  118. {
  119. AssertSz(_dypInch != 0, "CDevDesc::GetDypInch _dypInch is 0");
  120. return _dypInch;
  121. }
  122. };
  123. #endif