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.

195 lines
6.3 KiB

  1. /* /////////////////////////////////////////////////////////////////////////
  2. * File: winstl/window/setcursor_scope.hpp
  3. *
  4. * Purpose: Cursor scoping class.
  5. *
  6. * Created: 12th May 2003
  7. * Updated: 10th August 2009
  8. *
  9. * Home: http://stlsoft.org/
  10. *
  11. * Copyright (c) 2003-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/setcursor_scope.hpp
  40. *
  41. * \brief [C++ only] Definition of the winstl::setcursor_scope class
  42. * (\ref group__library__windows_window "Windows Window" Library).
  43. */
  44. #ifndef WINSTL_INCL_WINSTL_WINDOW_HPP_SETCURSOR_SCOPE
  45. #define WINSTL_INCL_WINSTL_WINDOW_HPP_SETCURSOR_SCOPE
  46. #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
  47. # define WINSTL_VER_WINSTL_WINDOW_HPP_SETCURSOR_SCOPE_MAJOR 4
  48. # define WINSTL_VER_WINSTL_WINDOW_HPP_SETCURSOR_SCOPE_MINOR 0
  49. # define WINSTL_VER_WINSTL_WINDOW_HPP_SETCURSOR_SCOPE_REVISION 1
  50. # define WINSTL_VER_WINSTL_WINDOW_HPP_SETCURSOR_SCOPE_EDIT 44
  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 STLSOFT_INCL_STLSOFT_SHIMS_ACCESS_HPP_STRING
  59. # include <stlsoft/shims/access/string.hpp>
  60. #endif /* !STLSOFT_INCL_STLSOFT_SHIMS_ACCESS_HPP_STRING */
  61. #ifndef WINSTL_INCL_WINSTL_SHIMS_ACCESS_HPP_STRING
  62. # include <winstl/shims/access/string.hpp>
  63. #endif /* !WINSTL_INCL_WINSTL_SHIMS_ACCESS_HPP_STRING */
  64. /* /////////////////////////////////////////////////////////////////////////
  65. * Namespace
  66. */
  67. #ifndef _WINSTL_NO_NAMESPACE
  68. # if defined(_STLSOFT_NO_NAMESPACE) || \
  69. defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
  70. /* There is no stlsoft namespace, so must define ::winstl */
  71. namespace winstl
  72. {
  73. # else
  74. /* Define stlsoft::winstl_project */
  75. namespace stlsoft
  76. {
  77. namespace winstl_project
  78. {
  79. # endif /* _STLSOFT_NO_NAMESPACE */
  80. #endif /* !_WINSTL_NO_NAMESPACE */
  81. /* /////////////////////////////////////////////////////////////////////////
  82. * Classes
  83. */
  84. // setcursor_scope
  85. /** \brief Provides scoping of a window's cursor.
  86. *
  87. * \ingroup group__library__windows_window
  88. *
  89. * This class provides scoping of the cursor of a window via the API
  90. * function SetCursor().
  91. */
  92. class setcursor_scope
  93. {
  94. public:
  95. /// This type
  96. typedef setcursor_scope class_type;
  97. // Construction
  98. public:
  99. /// \brief Toggles the current cursor
  100. ///
  101. /// Sets the given cursor.
  102. ss_explicit_k setcursor_scope(HCURSOR hcur)
  103. : m_hcurLast(::SetCursor(hcur))
  104. {}
  105. #ifdef STLSOFT_CF_MEMBER_TEMPLATE_CTOR_SUPPORT
  106. /// \brief Toggles the current cursor
  107. ///
  108. /// Sets the given cursor resource from the given instance.
  109. template <ss_typename_param_k S>
  110. setcursor_scope(HINSTANCE hinst, S const& name)
  111. : m_hcurLast(::SetCursor(load_(hinst, stlsoft_ns_qual(c_str_ptr)(name))))
  112. {}
  113. #endif /* STLSOFT_CF_MEMBER_TEMPLATE_CTOR_SUPPORT */
  114. /// \brief Toggles the current cursor
  115. ///
  116. /// Sets the given cursor resource from the given instance.
  117. setcursor_scope(HINSTANCE hinst, ws_char_a_t const* name)
  118. : m_hcurLast(::SetCursor(load_(hinst, name)))
  119. {}
  120. /// \brief Toggles the current cursor
  121. ///
  122. /// Sets the given cursor resource from the given instance.
  123. setcursor_scope(HINSTANCE hinst, ws_char_w_t const* name)
  124. : m_hcurLast(::SetCursor(load_(hinst, name)))
  125. {}
  126. /// \brief Toggles the current cursor
  127. ///
  128. /// Sets the given cursor resource from the given instance.
  129. setcursor_scope(HINSTANCE hinst, int id)
  130. : m_hcurLast(::SetCursor(::LoadCursor(hinst, MAKEINTRESOURCE(id))))
  131. {}
  132. /// Resets the original cursor
  133. ~setcursor_scope() stlsoft_throw_0()
  134. {
  135. ::SetCursor(m_hcurLast);
  136. }
  137. /// \name Implementation
  138. /// @{
  139. private:
  140. static HCURSOR load_(HINSTANCE hinst, ws_char_a_t const* name)
  141. {
  142. return ::LoadCursorA(hinst, name);
  143. }
  144. static HCURSOR load_(HINSTANCE hinst, ws_char_w_t const* name)
  145. {
  146. return ::LoadCursorW(hinst, name);
  147. }
  148. /// @}
  149. /// \name Members
  150. /// @{
  151. private:
  152. HCURSOR m_hcurLast;
  153. /// @}
  154. /// \name Not to be implemented
  155. /// @{
  156. private:
  157. setcursor_scope(class_type const&);
  158. class_type& operator =(class_type const&);
  159. /// @}
  160. };
  161. /* ////////////////////////////////////////////////////////////////////// */
  162. #ifndef _WINSTL_NO_NAMESPACE
  163. # if defined(_STLSOFT_NO_NAMESPACE) || \
  164. defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
  165. } // namespace winstl
  166. # else
  167. } // namespace winstl_project
  168. } // namespace stlsoft
  169. # endif /* _STLSOFT_NO_NAMESPACE */
  170. #endif /* !_WINSTL_NO_NAMESPACE */
  171. /* ////////////////////////////////////////////////////////////////////// */
  172. #endif /* WINSTL_INCL_WINSTL_WINDOW_HPP_SETCURSOR_SCOPE */
  173. /* ///////////////////////////// end of file //////////////////////////// */