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.

159 lines
4.6 KiB

  1. /*
  2. * OLEUTL.CPP
  3. *
  4. * Miscellaneous utility functions for OLE 2.0 Applications:
  5. *
  6. * Function Purpose
  7. * -------------------------------------------------------------------
  8. * XformWidthInHimetricToPixels Converts an int width from HiMetric units
  9. * XformHeightInHimetricToPixels Converts an int height from HiMetric units
  10. *
  11. * CommitStorage Commits all changes in a docfile
  12. * CreateChildStorage Creates child storage in another storage
  13. * OpenChildStorage Opens child storage in another storage
  14. *
  15. *
  16. * Copyright (c)1992 Microsoft Corporation, All Right Reserved
  17. */
  18. #include "precomp.h"
  19. #include <stdlib.h>
  20. //Internal function to this module. No need for UNICODE in this function
  21. static LPSTR GetWord(LPSTR lpszSrc, LPSTR lpszDst);
  22. /*
  23. * XformWidthInHimetricToPixels
  24. * XformHeightInHimetricToPixels
  25. *
  26. * Functions to convert an int between a device coordinate system and
  27. * logical HiMetric units.
  28. *
  29. * Parameters:
  30. * hDC HDC providing reference to the pixel mapping. If
  31. * NULL, a screen DC is used.
  32. *
  33. * Size Functions:
  34. * lpSizeSrc LPSIZEL providing the structure to convert.
  35. * lpSizeDst LPSIZEL providing the structure to receive converted
  36. * units.
  37. *
  38. * Width Functions:
  39. * iWidth int containing the value to convert.
  40. *
  41. * Return Value:
  42. * Size Functions: None
  43. * Width Functions: Converted value of the input parameters.
  44. *
  45. * NOTE:
  46. * When displaying on the screen, Window apps display everything enlarged
  47. * from its actual size so that it is easier to read. For example, if an
  48. * app wants to display a 1in. horizontal line, that when printed is
  49. * actually a 1in. line on the printed page, then it will display the line
  50. * on the screen physically larger than 1in. This is described as a line
  51. * that is "logically" 1in. along the display width. Windows maintains as
  52. * part of the device-specific information about a given display device:
  53. * LOGPIXELSX -- no. of pixels per logical in along the display width
  54. * LOGPIXELSY -- no. of pixels per logical in along the display height
  55. *
  56. * The following formula converts a distance in pixels into its equivalent
  57. * logical HIMETRIC units:
  58. *
  59. * DistInHiMetric = (HIMETRIC_PER_INCH * DistInPix)
  60. * -------------------------------
  61. * PIXELS_PER_LOGICAL_IN
  62. *
  63. */
  64. STDAPI_(int) XformWidthInHimetricToPixels(HDC hDC, int iWidthInHiMetric)
  65. {
  66. int iXppli; //Pixels per logical inch along width
  67. int iWidthInPix;
  68. BOOL fSystemDC=FALSE;
  69. if (NULL==hDC)
  70. {
  71. hDC=GetDC(NULL);
  72. if (NULL==hDC)
  73. {
  74. //What can we do if hDC is NULL here? Just don't
  75. //transform, I guess.
  76. return iWidthInHiMetric;
  77. }
  78. fSystemDC=TRUE;
  79. }
  80. iXppli = GetDeviceCaps (hDC, LOGPIXELSX);
  81. //We got logical HIMETRIC along the display, convert them to pixel units
  82. iWidthInPix = MAP_LOGHIM_TO_PIX(iWidthInHiMetric, iXppli);
  83. if (fSystemDC)
  84. ReleaseDC(NULL, hDC);
  85. return iWidthInPix;
  86. }
  87. STDAPI_(int) XformHeightInHimetricToPixels(HDC hDC, int iHeightInHiMetric)
  88. {
  89. int iYppli; //Pixels per logical inch along height
  90. int iHeightInPix;
  91. BOOL fSystemDC=FALSE;
  92. if (NULL==hDC)
  93. {
  94. hDC=GetDC(NULL);
  95. if (NULL==hDC)
  96. {
  97. //What can we do if hDC is NULL here? Just don't
  98. //transform, I guess.
  99. return iHeightInHiMetric;
  100. }
  101. fSystemDC=TRUE;
  102. }
  103. iYppli = GetDeviceCaps (hDC, LOGPIXELSY);
  104. //* We got logical HIMETRIC along the display, convert them to pixel units
  105. iHeightInPix = MAP_LOGHIM_TO_PIX(iHeightInHiMetric, iYppli);
  106. if (fSystemDC)
  107. ReleaseDC(NULL, hDC);
  108. return iHeightInPix;
  109. }
  110. /* GetWord
  111. * -------
  112. *
  113. * LPSTR lpszSrc - Pointer to a source string
  114. * LPSTR lpszDst - Pointer to destination buffer
  115. *
  116. * Will copy one space-terminated or null-terminated word from the source
  117. * string to the destination buffer.
  118. * returns: pointer to next character following the word.
  119. */
  120. static LPSTR GetWord(LPSTR lpszSrc, LPSTR lpszDst)
  121. {
  122. while (*lpszSrc && !(*lpszSrc == ' ' || *lpszSrc == '\t' || *lpszSrc == '\n'))
  123. *lpszDst++ = *lpszSrc++;
  124. *lpszDst = '\0';
  125. return lpszSrc;
  126. }