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.

167 lines
5.5 KiB

  1. /* /////////////////////////////////////////////////////////////////////////
  2. * File: winstl/window/setfocus_scope.hpp
  3. *
  4. * Purpose: Cursor scoping class.
  5. *
  6. * Created: 4th 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/setfocus_scope.hpp
  40. *
  41. * \brief [C++ only] Definition of the winstl::setfocus_scope class
  42. * (\ref group__library__windows_window "Windows Window" Library).
  43. */
  44. #ifndef WINSTL_INCL_WINSTL_WINDOW_HPP_SETFOCUS_SCOPE
  45. #define WINSTL_INCL_WINSTL_WINDOW_HPP_SETFOCUS_SCOPE
  46. #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
  47. # define WINSTL_VER_WINSTL_WINDOW_HPP_SETFOCUS_SCOPE_MAJOR 4
  48. # define WINSTL_VER_WINSTL_WINDOW_HPP_SETFOCUS_SCOPE_MINOR 1
  49. # define WINSTL_VER_WINSTL_WINDOW_HPP_SETFOCUS_SCOPE_REVISION 1
  50. # define WINSTL_VER_WINSTL_WINDOW_HPP_SETFOCUS_SCOPE_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 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. // setfocus_scope
  85. /** \brief Provides scoping of the focus window.
  86. *
  87. * \ingroup group__library__windows_window
  88. *
  89. * This class provides scoping of the focus status of a window via the API
  90. * function SetFocus().
  91. */
  92. class setfocus_scope
  93. {
  94. /// \name Member Types
  95. /// @{
  96. public:
  97. typedef setfocus_scope class_type;
  98. /// @}
  99. /// \name Construction
  100. /// @{
  101. public:
  102. /// Changes the owner of the focus to the given window, and records the current owner of the focus, to which it will be restored in the destructor
  103. #ifdef STLSOFT_CF_MEMBER_TEMPLATE_CTOR_SUPPORT
  104. template <ss_typename_param_k W>
  105. ss_explicit_k setfocus_scope(W &wnd)
  106. : m_hwndFocus(::SetFocus(get_HWND(wnd)))
  107. #else
  108. ss_explicit_k setfocus_scope(HWND wnd)
  109. : m_hwndFocus(::SetFocus(wnd))
  110. #endif /* STLSOFT_CF_MEMBER_TEMPLATE_CTOR_SUPPORT */
  111. {}
  112. /// Records the current owner of the focus, to which it will be restored in the destructor
  113. setfocus_scope()
  114. : m_hwndFocus(::GetFocus())
  115. {}
  116. /// Resets the focus to the original holder
  117. ~setfocus_scope() stlsoft_throw_0()
  118. {
  119. ::SetFocus(m_hwndFocus);
  120. }
  121. /// @}
  122. /// \name Members
  123. /// @{
  124. private:
  125. HWND m_hwndFocus;
  126. /// @}
  127. /// \name Not to be implemented
  128. /// @{
  129. private:
  130. setfocus_scope(class_type const&);
  131. class_type& operator =(class_type const&);
  132. /// @}
  133. };
  134. /* ////////////////////////////////////////////////////////////////////// */
  135. #ifndef _WINSTL_NO_NAMESPACE
  136. # if defined(_STLSOFT_NO_NAMESPACE) || \
  137. defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
  138. } // namespace winstl
  139. # else
  140. } // namespace winstl_project
  141. } // namespace stlsoft
  142. # endif /* _STLSOFT_NO_NAMESPACE */
  143. #endif /* !_WINSTL_NO_NAMESPACE */
  144. /* ////////////////////////////////////////////////////////////////////// */
  145. #endif /* WINSTL_INCL_WINSTL_WINDOW_HPP_SETFOCUS_SCOPE */
  146. /* ///////////////////////////// end of file //////////////////////////// */