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.

232 lines
7.6 KiB

  1. /* /////////////////////////////////////////////////////////////////////////
  2. * File: winstl/window/window_traits.hpp
  3. *
  4. * Purpose: Contains the window_traits template class, and ANSI
  5. * and Unicode specialisations thereof.
  6. *
  7. * Created: 24th August 2003
  8. * Updated: 10th August 2009
  9. *
  10. * Home: http://stlsoft.org/
  11. *
  12. * Copyright (c) 2003-2009, Matthew Wilson and Synesis Software
  13. * All rights reserved.
  14. *
  15. * Redistribution and use in source and binary forms, with or without
  16. * modification, are permitted provided that the following conditions are met:
  17. *
  18. * - Redistributions of source code must retain the above copyright notice, this
  19. * list of conditions and the following disclaimer.
  20. * - Redistributions in binary form must reproduce the above copyright notice,
  21. * this list of conditions and the following disclaimer in the documentation
  22. * and/or other materials provided with the distribution.
  23. * - Neither the name(s) of Matthew Wilson and Synesis Software nor the names of
  24. * any contributors may be used to endorse or promote products derived from
  25. * this software without specific prior written permission.
  26. *
  27. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  28. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  29. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  30. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  31. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  32. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  33. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  34. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  35. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  36. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  37. * POSSIBILITY OF SUCH DAMAGE.
  38. *
  39. * ////////////////////////////////////////////////////////////////////// */
  40. /** \file winstl/window/window_traits.hpp
  41. *
  42. * \brief [C++ only] Definition of the winstl::window_traits traits class
  43. * template, and ANSI and Unicode specialisations thereof
  44. * (\ref group__library__windows_window "Windows Window" Library).
  45. */
  46. #ifndef WINSTL_INCL_WINSTL_WINDOW_HPP_WINDOW_TRAITS
  47. #define WINSTL_INCL_WINSTL_WINDOW_HPP_WINDOW_TRAITS
  48. #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
  49. # define WINSTL_VER_WINSTL_WINDOW_HPP_WINDOW_TRAITS_MAJOR 4
  50. # define WINSTL_VER_WINSTL_WINDOW_HPP_WINDOW_TRAITS_MINOR 1
  51. # define WINSTL_VER_WINSTL_WINDOW_HPP_WINDOW_TRAITS_REVISION 1
  52. # define WINSTL_VER_WINSTL_WINDOW_HPP_WINDOW_TRAITS_EDIT 31
  53. #endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
  54. /* /////////////////////////////////////////////////////////////////////////
  55. * Includes
  56. */
  57. #ifndef WINSTL_INCL_WINSTL_H_WINSTL
  58. # include <winstl/winstl.h>
  59. #endif /* !WINSTL_INCL_WINSTL_H_WINSTL */
  60. #ifndef STLSOFT_INCL_STLSOFT_SHIMS_ACCESS_HPP_STRING
  61. # include <stlsoft/shims/access/string.hpp>
  62. #endif /* !STLSOFT_INCL_STLSOFT_SHIMS_ACCESS_HPP_STRING */
  63. #ifndef WINSTL_INCL_WINSTL_SHIMS_ACCESS_HPP_STRING
  64. # include <winstl/shims/access/string.hpp>
  65. #endif /* !WINSTL_INCL_WINSTL_SHIMS_ACCESS_HPP_STRING */
  66. #ifndef WINSTL_INCL_WINSTL_SYSTEM_HPP_SYSTEM_TRAITS
  67. # include <winstl/system/system_traits.hpp>
  68. #endif /* !WINSTL_INCL_WINSTL_SYSTEM_HPP_SYSTEM_TRAITS */
  69. /* /////////////////////////////////////////////////////////////////////////
  70. * Namespace
  71. */
  72. #ifndef _WINSTL_NO_NAMESPACE
  73. # if defined(_STLSOFT_NO_NAMESPACE) || \
  74. defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
  75. /* There is no stlsoft namespace, so must define ::winstl */
  76. namespace winstl
  77. {
  78. # else
  79. /* Define stlsoft::winstl_project */
  80. namespace stlsoft
  81. {
  82. namespace winstl_project
  83. {
  84. # endif /* _STLSOFT_NO_NAMESPACE */
  85. #endif /* !_WINSTL_NO_NAMESPACE */
  86. /* /////////////////////////////////////////////////////////////////////////
  87. * Classes
  88. */
  89. #ifdef STLSOFT_DOCUMENTATION_SKIP_SECTION
  90. /** \brief Traits for accessing the correct registry functions for a given character type
  91. *
  92. * \ingroup group__library__windows_window
  93. *
  94. * window_traits is a traits class for determining the correct window manipulation
  95. * structures and functions for a given character type.
  96. */
  97. template <ss_typename_param_k C>
  98. struct window_traits
  99. : public system_traits<C>
  100. {
  101. /// \name Member Types
  102. /// @{
  103. public:
  104. /// The character type
  105. typedef C char_type;
  106. /// The size type
  107. typedef ws_size_t size_type;
  108. /// The difference type
  109. typedef ws_ptrdiff_t difference_type;
  110. /// @}
  111. /// \name Window functions
  112. /// @{
  113. public:
  114. /// Gets the number of characters of text for the given window
  115. static ws_int_t get_window_text_length(HWND hwnd);
  116. /// Retrieves the text for the given window
  117. static ws_int_t get_window_text(HWND hwnd, char_type* buffer, ws_int_t cchBuff);
  118. /// Sets the text for the given window
  119. static ws_bool_t set_window_text(HWND hwnd, char_type const* buffer);
  120. /// @}
  121. };
  122. #else
  123. template <ss_typename_param_k C>
  124. struct window_traits;
  125. STLSOFT_TEMPLATE_SPECIALISATION
  126. struct window_traits<ws_char_a_t>
  127. : public system_traits<ws_char_a_t>
  128. {
  129. public:
  130. typedef window_traits<ws_char_a_t> class_type;
  131. typedef ws_char_a_t char_type;
  132. typedef ws_size_t size_type;
  133. typedef ws_ptrdiff_t difference_type;
  134. public:
  135. static ws_int_t get_window_text_length(HWND hwnd)
  136. {
  137. return ::GetWindowTextLength(hwnd);
  138. }
  139. static ws_int_t get_window_text(HWND hwnd, char_type* buffer, ws_int_t cchBuff)
  140. {
  141. return ::GetWindowTextA(hwnd, buffer, cchBuff);
  142. }
  143. static ws_bool_t set_window_text(HWND hwnd, char_type const* s)
  144. {
  145. return 0 != ::SetWindowTextA(hwnd, s);
  146. }
  147. #ifdef STLSOFT_CF_MEMBER_TEMPLATE_CTOR_SUPPORT
  148. template <ss_typename_param_k S>
  149. static ws_bool_t set_window_text(HWND hwnd, S const& s)
  150. {
  151. return class_type::set_window_text(hwnd, stlsoft_ns_qual(c_str_ptr_a)(s));
  152. }
  153. #endif /* STLSOFT_CF_MEMBER_TEMPLATE_CTOR_SUPPORT */
  154. };
  155. STLSOFT_TEMPLATE_SPECIALISATION
  156. struct window_traits<ws_char_w_t>
  157. : public system_traits<ws_char_w_t>
  158. {
  159. public:
  160. typedef window_traits<ws_char_w_t> class_type;
  161. typedef ws_char_w_t char_type;
  162. typedef ws_size_t size_type;
  163. typedef ws_ptrdiff_t difference_type;
  164. public:
  165. static ws_int_t get_window_text_length(HWND hwnd)
  166. {
  167. return ::GetWindowTextLength(hwnd);
  168. }
  169. static ws_int_t get_window_text(HWND hwnd, char_type* buffer, ws_int_t cchBuff)
  170. {
  171. return ::GetWindowTextW(hwnd, buffer, cchBuff);
  172. }
  173. static ws_bool_t set_window_text(HWND hwnd, char_type const* s)
  174. {
  175. return 0 != ::SetWindowTextW(hwnd, s);
  176. }
  177. #ifdef STLSOFT_CF_MEMBER_TEMPLATE_CTOR_SUPPORT
  178. template <ss_typename_param_k S>
  179. static ws_bool_t set_window_text(HWND hwnd, S const& s)
  180. {
  181. return class_type::set_window_text(hwnd, stlsoft_ns_qual(c_str_ptr_w)(s));
  182. }
  183. #endif /* STLSOFT_CF_MEMBER_TEMPLATE_CTOR_SUPPORT */
  184. };
  185. #endif /* STLSOFT_DOCUMENTATION_SKIP_SECTION */
  186. /* ////////////////////////////////////////////////////////////////////// */
  187. #ifndef _WINSTL_NO_NAMESPACE
  188. # if defined(_STLSOFT_NO_NAMESPACE) || \
  189. defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
  190. } // namespace winstl
  191. # else
  192. } // namespace winstl_project
  193. } // namespace stlsoft
  194. # endif /* _STLSOFT_NO_NAMESPACE */
  195. #endif /* !_WINSTL_NO_NAMESPACE */
  196. /* ////////////////////////////////////////////////////////////////////// */
  197. #endif /* WINSTL_INCL_WINSTL_WINDOW_HPP_WINDOW_TRAITS */
  198. /* ///////////////////////////// end of file //////////////////////////// */