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.

113 lines
2.4 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. void CDevDesc::LRtoDR(RECT &rcDest, const RECT &rcSrc, TFLOW tflow) const
  78. {
  79. TRACEBEGIN(TRCSUBSYSDISP, TRCSCOPEINTERN, "CDevDesc::LRtoDR");
  80. if (!IsUVerticalTflow(tflow))
  81. {
  82. rcDest.left = LXtoDX(rcSrc.left);
  83. rcDest.right = LXtoDX(rcSrc.right);
  84. rcDest.top = LYtoDY(rcSrc.top);
  85. rcDest.bottom = LYtoDY(rcSrc.bottom);
  86. }
  87. else
  88. {
  89. rcDest.left = LYtoDY(rcSrc.left);
  90. rcDest.right = LYtoDY(rcSrc.right);
  91. rcDest.top = LXtoDX(rcSrc.top);
  92. rcDest.bottom = LXtoDX(rcSrc.bottom);
  93. }
  94. }