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.

269 lines
8.2 KiB

  1. /* /////////////////////////////////////////////////////////////////////////
  2. * File: winstl/functional/window.hpp
  3. *
  4. * Purpose: Window function classes and predicates.
  5. *
  6. * Created: 19th January 2001
  7. * Updated: 10th August 2009
  8. *
  9. * Home: http://stlsoft.org/
  10. *
  11. * Copyright (c) 2001-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/functional/window.hpp
  40. *
  41. * \brief [C++ only] Window function classes and predicates
  42. * (\ref group__library__functional "Functional" Library).
  43. */
  44. #ifndef WINSTL_INCL_WINSTL_FUNCTIONAL_HPP_WINDOW
  45. #define WINSTL_INCL_WINSTL_FUNCTIONAL_HPP_WINDOW
  46. #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
  47. # define WINSTL_VER_WINSTL_FUNCTIONAL_HPP_WINDOW_MAJOR 4
  48. # define WINSTL_VER_WINSTL_FUNCTIONAL_HPP_WINDOW_MINOR 1
  49. # define WINSTL_VER_WINSTL_FUNCTIONAL_HPP_WINDOW_REVISION 1
  50. # define WINSTL_VER_WINSTL_FUNCTIONAL_HPP_WINDOW_EDIT 41
  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. #ifndef WINSTL_INCL_SHIMS_ATTRIBUTE_HPP_GET_HWND
  59. # include <winstl/shims/attribute/get_HWND.hpp>
  60. #endif /* !WINSTL_INCL_SHIMS_ATTRIBUTE_HPP_GET_HWND */
  61. #ifndef _WINSTL_WINDOW_FUNCTIONALS_NO_STD
  62. # include <functional>
  63. #else /* ? _WINSTL_WINDOW_FUNCTIONALS_NO_STD */
  64. # error Now need to write that std_binary_function stuff!!
  65. #endif /* _WINSTL_WINDOW_FUNCTIONALS_NO_STD */
  66. /* /////////////////////////////////////////////////////////////////////////
  67. * Namespace
  68. */
  69. #ifndef _WINSTL_NO_NAMESPACE
  70. # if defined(_STLSOFT_NO_NAMESPACE) || \
  71. defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
  72. /* There is no stlsoft namespace, so must define ::winstl */
  73. namespace winstl
  74. {
  75. # else
  76. /* Define stlsoft::winstl_project */
  77. namespace stlsoft
  78. {
  79. namespace winstl_project
  80. {
  81. # endif /* _STLSOFT_NO_NAMESPACE */
  82. #endif /* !_WINSTL_NO_NAMESPACE */
  83. /* /////////////////////////////////////////////////////////////////////////
  84. * Predicate classes
  85. */
  86. /** \brief Predicate used to determine whether windows are visible
  87. *
  88. * \ingroup group__library__functional
  89. *
  90. */
  91. // [[synesis:class:function-class:unary-predicate: is_visible]]
  92. struct is_visible
  93. : public winstl_ns_qual_std(unary_function)<HWND, BOOL>
  94. {
  95. private:
  96. typedef winstl_ns_qual_std(unary_function)<HWND, BOOL> parent_class_type;
  97. public:
  98. /// The argument type
  99. typedef parent_class_type::argument_type argument_type;
  100. /// The result type
  101. typedef parent_class_type::result_type result_type;
  102. // Operations
  103. public:
  104. /// Function call operator which evaluates whether the given window is visible
  105. result_type operator ()(HWND hwnd) const
  106. {
  107. return ::IsWindowVisible(hwnd);
  108. }
  109. #ifdef STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT
  110. /// Function call operator which evaluates whether the given window is visible
  111. template <ss_typename_param_k W>
  112. result_type operator ()(W const& w) const
  113. {
  114. return ::IsWindowVisible(winstl_ns_qual(get_HWND)(w));
  115. }
  116. #endif // STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT
  117. };
  118. /** \brief Predicate used to determine whether windows are enabled
  119. *
  120. * \ingroup group__library__functional
  121. *
  122. */
  123. // [[synesis:class:function-class:unary-predicate: is_enabled]]
  124. struct is_enabled
  125. : public winstl_ns_qual_std(unary_function)<HWND, BOOL>
  126. {
  127. private:
  128. typedef winstl_ns_qual_std(unary_function)<HWND, BOOL> parent_class_type;
  129. public:
  130. /// The argument type
  131. typedef parent_class_type::argument_type argument_type;
  132. /// The result type
  133. typedef parent_class_type::result_type result_type;
  134. // Operations
  135. public:
  136. /// Function call operator which evaluates whether the given window is enabled
  137. result_type operator ()(HWND hwnd) const
  138. {
  139. return ::IsWindowEnabled(hwnd);
  140. }
  141. #ifdef STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT
  142. /// Function call operator which evaluates whether the given window is enabled
  143. template <ss_typename_param_k W>
  144. result_type operator ()(W const& w) const
  145. {
  146. return ::IsWindowEnabled(winstl_ns_qual(get_HWND)(w));
  147. }
  148. #endif // STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT
  149. };
  150. /* /////////////////////////////////////////////////////////////////////////
  151. * Functor classes
  152. */
  153. /** \brief Functor used to show or hide windows
  154. *
  155. * \ingroup group__library__functional
  156. *
  157. */
  158. // [[synesis:class:unary-functor: window_show]]
  159. struct window_show
  160. : public std::unary_function<HWND, void>
  161. {
  162. public:
  163. /// This type
  164. typedef window_show class_type;
  165. public:
  166. ss_explicit_k window_show(ws_bool_t bShow = true)
  167. : m_bShow(bShow)
  168. {}
  169. window_show(window_show const& rhs)
  170. : m_bShow(rhs.m_bShow)
  171. {}
  172. public:
  173. void operator ()(HWND hwnd) const
  174. {
  175. show_(hwnd, m_bShow);
  176. }
  177. template <ss_typename_param_k W>
  178. void operator ()(W &wnd) const
  179. {
  180. show_(winstl_ns_qual(get_HWND)(wnd), m_bShow);
  181. }
  182. private:
  183. static void show_(HWND hwnd, ws_bool_t bShow)
  184. {
  185. ::ShowWindow(hwnd, bShow ? SW_SHOW : SW_HIDE);
  186. }
  187. private:
  188. const ws_bool_t m_bShow;
  189. private:
  190. class_type& operator =(class_type const&);
  191. };
  192. /** \brief Functor used to enable or disable windows
  193. *
  194. * \ingroup group__library__functional
  195. *
  196. */
  197. // [[synesis:class:unary-functor: window_enable]]
  198. struct window_enable
  199. : public std::unary_function<HWND, void>
  200. {
  201. public:
  202. /// This type
  203. typedef window_enable class_type;
  204. public:
  205. ss_explicit_k window_enable(ws_bool_t bEnable = true)
  206. : m_bEnable(bEnable)
  207. {}
  208. window_enable(window_enable const& rhs)
  209. : m_bEnable(rhs.m_bEnable)
  210. {}
  211. public:
  212. void operator ()(HWND hwnd) const
  213. {
  214. enable_(hwnd, m_bEnable);
  215. }
  216. template <ss_typename_param_k W>
  217. void operator ()(W &wnd) const
  218. {
  219. enable_(winstl_ns_qual(get_HWND)(wnd), m_bEnable);
  220. }
  221. private:
  222. static void enable_(HWND hwnd, ws_bool_t bEnable)
  223. {
  224. ::EnableWindow(hwnd, bEnable);
  225. }
  226. private:
  227. const ws_bool_t m_bEnable;
  228. private:
  229. class_type& operator =(class_type const&);
  230. };
  231. /* ////////////////////////////////////////////////////////////////////// */
  232. #ifndef _WINSTL_NO_NAMESPACE
  233. # if defined(_STLSOFT_NO_NAMESPACE) || \
  234. defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
  235. } // namespace winstl
  236. # else
  237. } // namespace winstl_project
  238. } // namespace stlsoft
  239. # endif /* _STLSOFT_NO_NAMESPACE */
  240. #endif /* !_WINSTL_NO_NAMESPACE */
  241. /* ////////////////////////////////////////////////////////////////////// */
  242. #endif /* WINSTL_INCL_WINSTL_FUNCTIONAL_HPP_WINDOW */
  243. /* ///////////////////////////// end of file //////////////////////////// */