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.

222 lines
6.9 KiB

  1. /* /////////////////////////////////////////////////////////////////////////
  2. * File: atlstl/window/enhanced_window.hpp
  3. *
  4. * Purpose: Mixin class providing enhanced functions for ATL windows.
  5. *
  6. * Created: 30th November 2000
  7. * Updated: 10th August 2009
  8. *
  9. * Home: http://stlsoft.org/
  10. *
  11. * Copyright (c) 2000-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 atlstl/window/enhanced_window.hpp
  40. *
  41. * \brief [C++ only; requires ATL library] Definition of the
  42. * atlstl::EnhancedWindow class template
  43. * (\ref group__library__windows_window "Windows Window" Library).
  44. */
  45. #ifndef ATLSTL_INCL_ATLSTL_WINDOW_HPP_ENHANCED_WINDOW
  46. #define ATLSTL_INCL_ATLSTL_WINDOW_HPP_ENHANCED_WINDOW
  47. #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
  48. # define ATLSTL_VER_ATLSTL_WINDOW_HPP_ENHANCED_WINDOW_MAJOR 4
  49. # define ATLSTL_VER_ATLSTL_WINDOW_HPP_ENHANCED_WINDOW_MINOR 0
  50. # define ATLSTL_VER_ATLSTL_WINDOW_HPP_ENHANCED_WINDOW_REVISION 2
  51. # define ATLSTL_VER_ATLSTL_WINDOW_HPP_ENHANCED_WINDOW_EDIT 29
  52. #endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
  53. /* /////////////////////////////////////////////////////////////////////////
  54. * Includes
  55. */
  56. #ifndef ATLSTL_INCL_ATLSTL_HPP_ATLSTL
  57. # include <atlstl/atlstl.hpp>
  58. #endif /* !ATLSTL_INCL_ATLSTL_HPP_ATLSTL */
  59. #ifndef ATLSTL_INCL_ATLSTL_SHIMS_ACCESS_HPP_STRING
  60. # include <atlstl/shims/access/string.hpp>
  61. #endif /* !ATLSTL_INCL_ATLSTL_SHIMS_ACCESS_HPP_STRING */
  62. /* /////////////////////////////////////////////////////////////////////////
  63. * Namespace
  64. */
  65. #ifndef _ATLSTL_NO_NAMESPACE
  66. # if defined(_STLSOFT_NO_NAMESPACE) || \
  67. defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
  68. /* There is no stlsoft namespace, so must define ::atlstl */
  69. namespace atlstl
  70. {
  71. # else
  72. /* Define stlsoft::atlstl_project */
  73. namespace stlsoft
  74. {
  75. namespace atlstl_project
  76. {
  77. # endif /* _STLSOFT_NO_NAMESPACE */
  78. #endif /* !_ATLSTL_NO_NAMESPACE */
  79. /* /////////////////////////////////////////////////////////////////////////
  80. * Classes
  81. */
  82. /** \brief This template is a veneer that provides various useful (and usually missing)
  83. * member functions of dialogs and parent windows.
  84. *
  85. * \ingroup group__library__windows_window
  86. */
  87. // [[synesis:class:ui-window: atlstl::EnhancedWindow<T<D>>]]
  88. template <ss_typename_param_k D>
  89. class EnhancedWindow
  90. {
  91. /// \name Types
  92. /// @{
  93. public:
  94. typedef D dialog_window_type;
  95. typedef EnhancedWindow<D> class_type;
  96. /// @}
  97. /// \name Operations
  98. /// @{
  99. public:
  100. /// \brief Returns the length of the window text of the child window with the given identifier
  101. int GetDlgItemTextLength(int idChild)
  102. {
  103. HWND hwndChild = GetDlgItem_(idChild);
  104. ATLSTL_ASSERT(::IsWindow(hwndChild));
  105. return ::GetWindowTextLength(hwndChild);
  106. }
  107. /// \brief Changes the enable state of the child window with the given identifier
  108. BOOL EnableDlgItem(int idChild, BOOL bEnable)
  109. {
  110. HWND hwndChild = GetDlgItem_(idChild);
  111. ATLSTL_ASSERT(::IsWindow(hwndChild));
  112. return ::EnableWindow(hwndChild, bEnable);
  113. }
  114. /// \brief Indicates whether the child window with the given identifier is enabled
  115. BOOL IsDlgItemEnabled(int idChild)
  116. {
  117. HWND hwndChild = GetDlgItem_(idChild);
  118. ATLSTL_ASSERT(::IsWindow(hwndChild));
  119. return ::IsWindowEnabled(hwndChild);
  120. }
  121. /// \brief Changes the visible state of the child window with the given identifier
  122. BOOL ShowDlgItem(int idChild, BOOL bShow)
  123. {
  124. HWND hwndChild = GetDlgItem_(idChild);
  125. ATLSTL_ASSERT(::IsWindow(hwndChild));
  126. return ::ShowWindow(hwndChild, bShow ? SW_SHOW : SW_HIDE);
  127. }
  128. /// \brief Changes the enable and visible states of the child window with the given identifier
  129. BOOL ShowAndEnableDlgItem(int idChild, BOOL bShowAndEnable, BOOL bHideIfDisabled)
  130. {
  131. BOOL bRet = true;
  132. if( bShowAndEnable ||
  133. bHideIfDisabled)
  134. {
  135. if(!this_()->ShowDlgItem(idChild, bShowAndEnable))
  136. {
  137. bRet = false;
  138. }
  139. }
  140. if(!this_()->EnableDlgItem(idChild, bShowAndEnable))
  141. {
  142. bRet = false;
  143. }
  144. return bRet;
  145. }
  146. /// \brief Sets the focus to the child window with the given identifier
  147. HWND SetDlgItemFocus(int idChild)
  148. {
  149. HWND hwndChild = GetDlgItem_(idChild);
  150. ATLSTL_ASSERT(::IsWindow(hwndChild));
  151. return ::SetFocus(hwndChild);
  152. }
  153. /// @}
  154. /// \name Implementation
  155. /// @{
  156. private:
  157. dialog_window_type* this_()
  158. {
  159. return static_cast<dialog_window_type*>(this);
  160. }
  161. dialog_window_type const* this_() const
  162. {
  163. return static_cast<dialog_window_type const*>(this);
  164. }
  165. HWND GetDlgItem_(int idChild) const
  166. {
  167. return this_()->GetDlgItem(idChild);
  168. }
  169. /// @}
  170. };
  171. /* ////////////////////////////////////////////////////////////////////// */
  172. #ifndef _ATLSTL_NO_NAMESPACE
  173. # if defined(_STLSOFT_NO_NAMESPACE) || \
  174. defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
  175. } // namespace atlstl
  176. # else
  177. } // namespace atlstl_project
  178. } // namespace stlsoft
  179. # endif /* _STLSOFT_NO_NAMESPACE */
  180. #endif /* !_ATLSTL_NO_NAMESPACE */
  181. /* ////////////////////////////////////////////////////////////////////// */
  182. #endif /* !ATLSTL_INCL_ATLSTL_WINDOW_HPP_ENHANCED_WINDOW */
  183. /* ///////////////////////////// end of file //////////////////////////// */