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.

207 lines
6.1 KiB

  1. /* /////////////////////////////////////////////////////////////////////////
  2. * File: winstl/window/textmetrics_functions.h (originally MWGdi.h, ::SynesisWin)
  3. *
  4. * Purpose: TEXTMETRICS functions.
  5. *
  6. * Created: 20th October 1994
  7. * Updated: 10th August 2009
  8. *
  9. * Home: http://stlsoft.org/
  10. *
  11. * Copyright (c) 1994-2009, Matthew Wilson and Synesis Software
  12. * All rights reserved.
  13. *
  14. * Redistribution and use in source and binary forms, with or without
  15. * modification, are permitted provided that the following conditions are met:
  16. *
  17. * - Redistributions of source code must retain the above copyright notice, this
  18. * list of conditions and the following disclaimer.
  19. * - Redistributions in binary form must reproduce the above copyright notice,
  20. * this list of conditions and the following disclaimer in the documentation
  21. * and/or other materials provided with the distribution.
  22. * - Neither the name(s) of Matthew Wilson and Synesis Software nor the names of
  23. * any contributors may be used to endorse or promote products derived from
  24. * this software without specific prior written permission.
  25. *
  26. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  27. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  28. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  29. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  30. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  31. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  32. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  33. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  34. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  35. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  36. * POSSIBILITY OF SUCH DAMAGE.
  37. *
  38. * ////////////////////////////////////////////////////////////////////// */
  39. /** \file winstl/window/textmetrics_functions.h
  40. *
  41. * \brief [C, C++] TEXTMETRICS functions
  42. * (\ref group__library__windows_window "Windows Window" Library).
  43. */
  44. #ifndef WINSTL_INCL_WINSTL_WINDOW_H_TEXTMETRICS_FUNCTIONS
  45. #define WINSTL_INCL_WINSTL_WINDOW_H_TEXTMETRICS_FUNCTIONS
  46. #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
  47. # define WINSTL_VER_WINSTL_WINDOW_H_TEXTMETRICS_FUNCTIONS_MAJOR 3
  48. # define WINSTL_VER_WINSTL_WINDOW_H_TEXTMETRICS_FUNCTIONS_MINOR 0
  49. # define WINSTL_VER_WINSTL_WINDOW_H_TEXTMETRICS_FUNCTIONS_REVISION 1
  50. # define WINSTL_VER_WINSTL_WINDOW_H_TEXTMETRICS_FUNCTIONS_EDIT 37
  51. #endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
  52. /* /////////////////////////////////////////////////////////////////////////
  53. * Includes
  54. */
  55. #ifndef WINSTL_INCL_WINSTL_H_WINSTL
  56. # include <winstl/winstl.h>
  57. #endif /* !WINSTL_INCL_WINSTL_H_WINSTL */
  58. #ifdef __cplusplus
  59. # ifndef WINSTL_INCL_WINSTL_WINDOW_HPP_HDC_SCOPE
  60. # include <winstl/window/hdc_scope.hpp>
  61. # endif /* !WINSTL_INCL_WINSTL_WINDOW_HPP_HDC_SCOPE */
  62. #endif /* __cplusplus */
  63. /* /////////////////////////////////////////////////////////////////////////
  64. * Namespace
  65. */
  66. #ifndef _WINSTL_NO_NAMESPACE
  67. # if defined(_STLSOFT_NO_NAMESPACE) || \
  68. defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
  69. /* There is no stlsoft namespace, so must define ::winstl */
  70. namespace winstl
  71. {
  72. # else
  73. /* Define stlsoft::winstl_project */
  74. namespace stlsoft
  75. {
  76. namespace winstl_project
  77. {
  78. # endif /* _STLSOFT_NO_NAMESPACE */
  79. #endif /* !_WINSTL_NO_NAMESPACE */
  80. /* /////////////////////////////////////////////////////////////////////////
  81. * C functions
  82. */
  83. STLSOFT_INLINE TEXTMETRICA winstl__get_textmetrics_a(HDC hdc)
  84. {
  85. static TEXTMETRICA s_tm;
  86. TEXTMETRICA tm;
  87. return STLSOFT_NS_GLOBAL(GetTextMetricsA)(hdc, &tm) ? tm : s_tm;
  88. }
  89. STLSOFT_INLINE TEXTMETRICW winstl__get_textmetrics_w(HDC hdc)
  90. {
  91. static TEXTMETRICW s_tm;
  92. TEXTMETRICW tm;
  93. return STLSOFT_NS_GLOBAL(GetTextMetricsW)(hdc, &tm) ? tm : s_tm;
  94. }
  95. STLSOFT_INLINE TEXTMETRIC winstl__get_textmetrics(HDC hdc)
  96. {
  97. # ifdef UNICODE
  98. return winstl__get_textmetrics_w(hdc);
  99. # else /* ? UNICODE */
  100. return winstl__get_textmetrics_a(hdc);
  101. # endif /* UNICODE */
  102. }
  103. /* /////////////////////////////////////////////////////////////////////////
  104. * C++ functions
  105. */
  106. #ifdef __cplusplus
  107. inline TEXTMETRICA get_textmetrics_a(HDC hdc)
  108. {
  109. return winstl__get_textmetrics_a(hdc);
  110. }
  111. inline TEXTMETRICW get_textmetrics_w(HDC hdc)
  112. {
  113. return winstl__get_textmetrics_w(hdc);
  114. }
  115. inline TEXTMETRIC get_textmetrics(HDC hdc)
  116. {
  117. return winstl__get_textmetrics(hdc);
  118. }
  119. inline TEXTMETRICA get_window_textmetrics_a(HWND hwnd)
  120. {
  121. HDC_scope hdc(::GetWindowDC(hwnd), hwnd);
  122. return winstl__get_textmetrics_a(hdc.get_hdc());
  123. }
  124. inline TEXTMETRICW get_window_textmetrics_w(HWND hwnd)
  125. {
  126. HDC_scope hdc(::GetWindowDC(hwnd), hwnd);
  127. return winstl__get_textmetrics_w(hdc.get_hdc());
  128. }
  129. inline TEXTMETRIC get_window_textmetrics(HWND hwnd)
  130. {
  131. # ifdef UNICODE
  132. return get_window_textmetrics_w(hwnd);
  133. # else /* ? UNICODE */
  134. return get_window_textmetrics_a(hwnd);
  135. # endif /* UNICODE */
  136. }
  137. inline TEXTMETRICA get_client_textmetrics_a(HWND hwnd)
  138. {
  139. HDC_scope hdc(::GetDC(hwnd), hwnd);
  140. return winstl__get_textmetrics_a(hdc.get_hdc());
  141. }
  142. inline TEXTMETRICW get_client_textmetrics_w(HWND hwnd)
  143. {
  144. HDC_scope hdc(::GetDC(hwnd), hwnd);
  145. return winstl__get_textmetrics_w(hdc.get_hdc());
  146. }
  147. inline TEXTMETRIC get_client_textmetrics(HWND hwnd)
  148. {
  149. # ifdef UNICODE
  150. return get_client_textmetrics_w(hwnd);
  151. # else /* ? UNICODE */
  152. return get_client_textmetrics_a(hwnd);
  153. # endif /* UNICODE */
  154. }
  155. #endif /* __cplusplus */
  156. /* ////////////////////////////////////////////////////////////////////// */
  157. #ifndef _WINSTL_NO_NAMESPACE
  158. # if defined(_STLSOFT_NO_NAMESPACE) || \
  159. defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
  160. } /* namespace winstl */
  161. # else
  162. } /* namespace winstl_project */
  163. } /* namespace stlsoft */
  164. # endif /* _STLSOFT_NO_NAMESPACE */
  165. #endif /* !_WINSTL_NO_NAMESPACE */
  166. /* ////////////////////////////////////////////////////////////////////// */
  167. #endif /* WINSTL_INCL_WINSTL_WINDOW_H_TEXTMETRICS_FUNCTIONS */
  168. /* ///////////////////////////// end of file //////////////////////////// */