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.

184 lines
6.0 KiB

  1. /* /////////////////////////////////////////////////////////////////////////
  2. * File: winstl/controls/dialog_functionals.hpp
  3. *
  4. * Purpose: Functionals for application to controls.
  5. *
  6. * Created: 2nd August 2006
  7. * Updated: 10th August 2009
  8. *
  9. * Home: http://stlsoft.org/
  10. *
  11. * Copyright (c) 2002-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/controls/dialog_functionals.hpp
  40. *
  41. * \brief [C++] Functionals for application to dialog controls
  42. * (\ref group__library__windows_controls "Windows Controls" Library).
  43. */
  44. #ifndef WINSTL_INCL_WINSTL_CONTROL_HPP_DIALOG_FUNCTIONALS
  45. #define WINSTL_INCL_WINSTL_CONTROL_HPP_DIALOG_FUNCTIONALS
  46. #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
  47. # define WINSTL_VER_WINSTL_CONTROL_HPP_DIALOG_FUNCTIONALS_MAJOR 1
  48. # define WINSTL_VER_WINSTL_CONTROL_HPP_DIALOG_FUNCTIONALS_MINOR 0
  49. # define WINSTL_VER_WINSTL_CONTROL_HPP_DIALOG_FUNCTIONALS_REVISION 2
  50. # define WINSTL_VER_WINSTL_CONTROL_HPP_DIALOG_FUNCTIONALS_EDIT 8
  51. #endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
  52. /* /////////////////////////////////////////////////////////////////////////
  53. * Compatibility
  54. */
  55. /*
  56. [Incompatibilies-start]
  57. STLSOFT_COMPILER_IS_GCC: __GNUC__<3
  58. STLSOFT_COMPILER_IS_MSVC: _MSC_VER<1100
  59. [Incompatibilies-end]
  60. */
  61. /* /////////////////////////////////////////////////////////////////////////
  62. * Includes
  63. */
  64. #ifndef WINSTL_INCL_WINSTL_H_WINSTL
  65. # include <winstl/winstl.h>
  66. #endif /* !WINSTL_INCL_WINSTL_H_WINSTL */
  67. #if defined(STLSOFT_COMPILER_IS_GCC) && \
  68. __GNUC__ < 3
  69. # error winstl/controls/dialog_functionals.hpp is not compatible with GNU C++ prior to 3.0
  70. #endif /* compiler */
  71. #if defined(STLSOFT_COMPILER_IS_MSVC) && \
  72. _MSC_VER < 1100
  73. # error winstl/controls/dialog_functionals.hpp is not compatible with Visual C++ 4.2 or earlier
  74. #endif /* compiler */
  75. #ifndef WINSTL_INCL_SHIMS_ATTRIBUTE_HPP_GET_HWND
  76. # include <winstl/shims/attribute/get_HWND.hpp>
  77. #endif /* !WINSTL_INCL_SHIMS_ATTRIBUTE_HPP_GET_HWND */
  78. #ifndef _WINSTL_CONTROL_FUNCTIONALS_NO_STD
  79. # include <functional>
  80. #else /* ? _WINSTL_CONTROL_FUNCTIONALS_NO_STD */
  81. # error Now need to write that std_binary_function stuff!!
  82. #endif /* _WINSTL_CONTROL_FUNCTIONALS_NO_STD */
  83. /* /////////////////////////////////////////////////////////////////////////
  84. * Namespace
  85. */
  86. #ifndef _WINSTL_NO_NAMESPACE
  87. # if defined(_STLSOFT_NO_NAMESPACE) || \
  88. defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
  89. /* There is no stlsoft namespace, so must define ::winstl */
  90. namespace winstl
  91. {
  92. # else
  93. /* Define stlsoft::winstl_project */
  94. namespace stlsoft
  95. {
  96. namespace winstl_project
  97. {
  98. # endif /* _STLSOFT_NO_NAMESPACE */
  99. #endif /* !_WINSTL_NO_NAMESPACE */
  100. /* /////////////////////////////////////////////////////////////////////////
  101. * Classes
  102. */
  103. /** \brief Functor used to (un)check buttons
  104. *
  105. * \ingroup group__library__windows_controls
  106. */
  107. // [[synesis:class:unary-functor: dialog_button_id_check]]
  108. class dialog_button_id_check
  109. : public stlsoft_ns_qual_std(unary_function)<HWND, void>
  110. {
  111. public:
  112. /// This type
  113. typedef dialog_button_id_check class_type;
  114. public:
  115. ss_explicit_k dialog_button_id_check(HWND hwndDlg, UINT nCheck = BST_CHECKED)
  116. : m_hwndDlg(hwndDlg)
  117. , m_nCheck(nCheck)
  118. {}
  119. dialog_button_id_check(dialog_button_id_check const& rhs)
  120. : m_hwndDlg(rhs.m_hwndDlg)
  121. , m_nCheck(rhs.m_nCheck)
  122. {}
  123. public:
  124. void operator ()(int id) const
  125. {
  126. check_(id, m_nCheck);
  127. }
  128. private:
  129. void check_(int id, UINT nCheck) const
  130. {
  131. ::CheckDlgButton(m_hwndDlg, id, nCheck);
  132. }
  133. private:
  134. HWND m_hwndDlg;
  135. const UINT m_nCheck;
  136. private:
  137. class_type& operator =(class_type const&);
  138. };
  139. ////////////////////////////////////////////////////////////////////////////
  140. // Unit-testing
  141. #ifdef STLSOFT_UNITTEST
  142. # include "./unittest/dialog_functionals_unittest_.h"
  143. #endif /* STLSOFT_UNITTEST */
  144. /* ////////////////////////////////////////////////////////////////////// */
  145. #ifndef _WINSTL_NO_NAMESPACE
  146. # if defined(_STLSOFT_NO_NAMESPACE) || \
  147. defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
  148. } // namespace winstl
  149. # else
  150. } // namespace winstl_project
  151. } // namespace stlsoft
  152. # endif /* _STLSOFT_NO_NAMESPACE */
  153. #endif /* !_WINSTL_NO_NAMESPACE */
  154. /* ////////////////////////////////////////////////////////////////////// */
  155. #endif /* WINSTL_INCL_WINSTL_CONTROL_HPP_DIALOG_FUNCTIONALS */
  156. /* ///////////////////////////// end of file //////////////////////////// */