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.

162 lines
3.7 KiB

  1. /*
  2. * DEVDSC.C
  3. *
  4. * Purpose:
  5. * CDevDesc (Device Descriptor) class
  6. *
  7. * Owner:
  8. * Original RichEdit code: David R. Fulmer
  9. * Christian Fortini
  10. * Murray Sargent
  11. */
  12. #include "_common.h"
  13. #include "_devdsc.h"
  14. #include "_edit.h"
  15. #include "_font.h"
  16. ASSERTDATA
  17. BOOL CDevDesc::SetDC(HDC hdc, LONG dxpInch, LONG dypInch)
  18. {
  19. TRACEBEGIN(TRCSUBSYSDISP, TRCSCOPEINTERN, "CDevDesc::SetDC");
  20. AssertSz((NULL == hdc) || (GetDeviceCaps(hdc, TECHNOLOGY) != DT_METAFILE),
  21. "CDevDesc::SetDC attempting to set a metafile");
  22. _hdc = hdc;
  23. if(!_hdc)
  24. {
  25. if(!_ped->_fInPlaceActive || !(hdc = _ped->TxGetDC()))
  26. {
  27. _dxpInch = _dypInch = 0;
  28. return FALSE;
  29. }
  30. }
  31. if (dxpInch == -1)
  32. {
  33. // Get device metrics - these should both succeed
  34. _dxpInch = (SHORT)GetDeviceCaps(hdc, LOGPIXELSX);
  35. AssertSz(_dxpInch != 0, "CDevDesc::SetDC _dxpInch is 0");
  36. }
  37. else
  38. _dxpInch = dxpInch;
  39. if (dypInch == -1)
  40. {
  41. _dypInch = (SHORT)GetDeviceCaps(hdc, LOGPIXELSY);
  42. AssertSz(_dypInch != 0, "CDevDesc::SetDC _dypInch is 0");
  43. }
  44. else
  45. _dypInch = dypInch;
  46. if(!_dxpInch || !_dypInch)
  47. return FALSE;
  48. // Release DC if we got the window DC
  49. if(!_hdc)
  50. _ped->TxReleaseDC(hdc);
  51. return TRUE;
  52. }
  53. void CDevDesc::SetMetafileDC(
  54. HDC hdcMetafile,
  55. LONG xMeasurePerInch,
  56. LONG yMeasurePerInch)
  57. {
  58. _fMetafile = TRUE;
  59. _hdc = hdcMetafile;
  60. _dxpInch = (SHORT) xMeasurePerInch;
  61. _dypInch = (SHORT) yMeasurePerInch;
  62. }
  63. HDC CDevDesc::GetScreenDC() const
  64. {
  65. TRACEBEGIN(TRCSUBSYSDISP, TRCSCOPEINTERN, "CDevDesc::GetScreenDC");
  66. Assert(!_hdc);
  67. Assert(_ped);
  68. return _ped->TxGetDC();
  69. }
  70. VOID CDevDesc::ReleaseScreenDC(HDC hdc) const
  71. {
  72. TRACEBEGIN(TRCSUBSYSDISP, TRCSCOPEINTERN, "CDevDesc::ReleaseScreenDC");
  73. Assert(!_hdc);
  74. Assert(_ped);
  75. _ped->TxReleaseDC(hdc);
  76. }
  77. LONG CDevDesc::DXtoLX(LONG x) const
  78. {
  79. TRACEBEGIN(TRCSUBSYSDISP, TRCSCOPEINTERN, "CDevDesc::DXtoLX");
  80. AssertSz(_dxpInch, "CDevDesc::DXtoLX() - hdc has not been set");
  81. return ((x * LX_PER_INCH) * 2 + _dxpInch) / (2 * _dxpInch);
  82. }
  83. LONG CDevDesc::DYtoLY(LONG y) const
  84. {
  85. TRACEBEGIN(TRCSUBSYSDISP, TRCSCOPEINTERN, "CDevDesc::DYtoLY");
  86. AssertSz(_dypInch, "CDevDesc::DYtoLY() - hdc has not been set");
  87. return ((y * LY_PER_INCH) * 2 + _dypInch) / (2 * _dypInch);
  88. }
  89. void CDevDesc::DPtoLP(POINT &ptDest, const POINT &ptSrc) const
  90. {
  91. TRACEBEGIN(TRCSUBSYSDISP, TRCSCOPEINTERN, "CDevDesc::DPtoLP");
  92. ptDest.x = DXtoLX(ptSrc.x);
  93. ptDest.y = DYtoLY(ptSrc.y);
  94. }
  95. void CDevDesc::DRtoLR(RECT &rcDest, const RECT &rcSrc) const
  96. {
  97. TRACEBEGIN(TRCSUBSYSDISP, TRCSCOPEINTERN, "CDevDesc::DRtoLR");
  98. rcDest.left = DXtoLX(rcSrc.left);
  99. rcDest.right = DXtoLX(rcSrc.right);
  100. rcDest.top = DYtoLY(rcSrc.top);
  101. rcDest.bottom = DYtoLY(rcSrc.bottom);
  102. }
  103. #ifdef DEBUG
  104. LONG CDevDesc::LXtoDX(LONG x) const
  105. {
  106. TRACEBEGIN(TRCSUBSYSDISP, TRCSCOPEINTERN, "CDevDesc::LXtoDX");
  107. AssertSz(_dxpInch, "CDevDesc::LXtoDX() - hdc has not been set");
  108. return ((x * _dxpInch) + LX_PER_INCH / 2) / LX_PER_INCH;
  109. }
  110. LONG CDevDesc::LYtoDY(LONG y) const
  111. {
  112. TRACEBEGIN(TRCSUBSYSDISP, TRCSCOPEINTERN, "CDevDesc::LYtoDY");
  113. AssertSz(_dypInch, "CDevDesc::LYtoDY() - hdc has not been set");
  114. return ((y * _dypInch) + LY_PER_INCH / 2) / LY_PER_INCH;
  115. }
  116. #endif // DEBUG
  117. void CDevDesc::LPtoDP(POINT &ptDest, const POINT &ptSrc) const
  118. {
  119. TRACEBEGIN(TRCSUBSYSDISP, TRCSCOPEINTERN, "CDevDesc::LPtoDP");
  120. ptDest.x = LXtoDX(ptSrc.x);
  121. ptDest.y = LYtoDY(ptSrc.y);
  122. }
  123. void CDevDesc::LRtoDR(RECT &rcDest, const RECT &rcSrc) const
  124. {
  125. TRACEBEGIN(TRCSUBSYSDISP, TRCSCOPEINTERN, "CDevDesc::LRtoDR");
  126. rcDest.left = LXtoDX(rcSrc.left);
  127. rcDest.right = LXtoDX(rcSrc.right);
  128. rcDest.top = LYtoDY(rcSrc.top);
  129. rcDest.bottom = LYtoDY(rcSrc.bottom);
  130. }