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.

809 lines
22 KiB

  1. /* /////////////////////////////////////////////////////////////////////////
  2. * File: winstl/controls/functionals.hpp
  3. *
  4. * Purpose: Functionals for application to controls.
  5. *
  6. * Created: 8th October 2002
  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/functionals.hpp
  40. *
  41. * \brief [C++] Functionals for application to controls
  42. * (\ref group__library__windows_controls "Windows Controls" Library).
  43. */
  44. #ifndef WINSTL_INCL_WINSTL_CONTROL_HPP_FUNCTIONALS
  45. #define WINSTL_INCL_WINSTL_CONTROL_HPP_FUNCTIONALS
  46. #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
  47. # define WINSTL_VER_WINSTL_CONTROL_HPP_FUNCTIONALS_MAJOR 4
  48. # define WINSTL_VER_WINSTL_CONTROL_HPP_FUNCTIONALS_MINOR 2
  49. # define WINSTL_VER_WINSTL_CONTROL_HPP_FUNCTIONALS_REVISION 1
  50. # define WINSTL_VER_WINSTL_CONTROL_HPP_FUNCTIONALS_EDIT 78
  51. #endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
  52. /* /////////////////////////////////////////////////////////////////////////
  53. * Compatibility
  54. */
  55. /*
  56. [Incompatibilies-start]
  57. STLSOFT_COMPILER_IS_DMC: __DMC__<0x0850
  58. STLSOFT_COMPILER_IS_GCC: __GNUC__<3
  59. STLSOFT_COMPILER_IS_MSVC: _MSC_VER<1100
  60. [Incompatibilies-end]
  61. */
  62. /* /////////////////////////////////////////////////////////////////////////
  63. * Includes
  64. */
  65. #ifndef WINSTL_INCL_WINSTL_H_WINSTL
  66. # include <winstl/winstl.h>
  67. #endif /* !WINSTL_INCL_WINSTL_H_WINSTL */
  68. #if defined(STLSOFT_COMPILER_IS_GCC) && \
  69. __GNUC__ < 3
  70. # error winstl/controls/functionals.hpp is not compatible with GNU C++ prior to 3.0
  71. #endif /* compiler */
  72. #if defined(STLSOFT_COMPILER_IS_MSVC) && \
  73. _MSC_VER < 1100
  74. # error winstl/controls/functionals.hpp is not compatible with Visual C++ 4.2 or earlier
  75. #endif /* compiler */
  76. #ifndef STLSOFT_INCL_STLSOFT_SHIMS_ACCESS_HPP_STRING
  77. # include <stlsoft/shims/access/string.hpp>
  78. #endif /* !STLSOFT_INCL_STLSOFT_SHIMS_ACCESS_HPP_STRING */
  79. #ifndef STLSOFT_INCL_STLSOFT_ITERATORS_HPP_UNARY_FUNCTION_OUTPUT_ITERATOR_ADAPTOR
  80. # include <stlsoft/iterators/unary_function_output_iterator_adaptor.hpp>
  81. #endif /* !STLSOFT_INCL_STLSOFT_ITERATORS_HPP_UNARY_FUNCTION_OUTPUT_ITERATOR_ADAPTOR */
  82. #ifndef WINSTL_INCL_WINSTL_SHIMS_ACCESS_HPP_STRING
  83. # include <winstl/shims/access/string.hpp>
  84. #endif /* !WINSTL_INCL_WINSTL_SHIMS_ACCESS_HPP_STRING */
  85. #ifndef WINSTL_INCL_SHIMS_ATTRIBUTE_HPP_GET_HWND
  86. # include <winstl/shims/attribute/get_HWND.hpp>
  87. #endif /* !WINSTL_INCL_SHIMS_ATTRIBUTE_HPP_GET_HWND */
  88. #ifndef WINSTL_INCL_WINSTL_CONVERSION_HPP_CHAR_CONVERSIONS
  89. # include <winstl/conversion/char_conversions.hpp> // for winstl::a2w, w2a
  90. #endif /* !WINSTL_INCL_WINSTL_CONVERSION_HPP_CHAR_CONVERSIONS */
  91. #ifndef WINSTL_INCL_WINSTL_CONTROLS_H_FUNCTIONS
  92. # include <winstl/controls/functions.h> // for winstl::listbox_add_string, ...
  93. #endif /* !WINSTL_INCL_WINSTL_CONTROLS_H_FUNCTIONS */
  94. #ifndef WINSTL_INCL_WINSTL_SYSTEM_HPP_SYSTEM_TRAITS
  95. # include <winstl/system/system_traits.hpp>
  96. #endif /* !WINSTL_INCL_WINSTL_SYSTEM_HPP_SYSTEM_TRAITS */
  97. #ifndef _WINSTL_CONTROL_FUNCTIONALS_NO_STD
  98. # include <functional>
  99. #else /* ? _WINSTL_CONTROL_FUNCTIONALS_NO_STD */
  100. # error Now need to write that std_binary_function stuff!!
  101. #endif /* _WINSTL_CONTROL_FUNCTIONALS_NO_STD */
  102. /* /////////////////////////////////////////////////////////////////////////
  103. * Namespace
  104. */
  105. #ifndef _WINSTL_NO_NAMESPACE
  106. # if defined(_STLSOFT_NO_NAMESPACE) || \
  107. defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
  108. /* There is no stlsoft namespace, so must define ::winstl */
  109. namespace winstl
  110. {
  111. # else
  112. /* Define stlsoft::winstl_project */
  113. namespace stlsoft
  114. {
  115. namespace winstl_project
  116. {
  117. # endif /* _STLSOFT_NO_NAMESPACE */
  118. #endif /* !_WINSTL_NO_NAMESPACE */
  119. /* /////////////////////////////////////////////////////////////////////////
  120. * Workarounds
  121. */
  122. #if defined(STLSOFT_COMPILER_IS_DMC)
  123. #endif /* STLSOFT_COMPILER_IS_DMC */
  124. /* /////////////////////////////////////////////////////////////////////////
  125. * Classes
  126. */
  127. /** \brief Functor used to (un)check buttons
  128. *
  129. * \ingroup group__library__windows_controls
  130. */
  131. // [[synesis:class:unary-functor: button_check]]
  132. class button_check
  133. : public stlsoft_ns_qual_std(unary_function)<HWND, void>
  134. {
  135. public:
  136. /// This type
  137. typedef button_check class_type;
  138. public:
  139. ss_explicit_k button_check(int nCheck = BST_CHECKED)
  140. : m_nCheck(nCheck)
  141. {}
  142. button_check(button_check const& rhs)
  143. : m_nCheck(rhs.m_nCheck)
  144. {}
  145. public:
  146. void operator ()(HWND hwnd) const
  147. {
  148. check_(hwnd, m_nCheck);
  149. }
  150. template <ss_typename_param_k W>
  151. void operator ()(W &wnd) const
  152. {
  153. check_(winstl_ns_qual(get_HWND)(wnd), m_nCheck);
  154. }
  155. private:
  156. static void check_(HWND hwnd, int nCheck)
  157. {
  158. ::SendMessage(hwnd, BM_SETCHECK, static_cast<WPARAM>(nCheck), 0L);
  159. }
  160. private:
  161. const int m_nCheck;
  162. private:
  163. class_type& operator =(class_type const&);
  164. };
  165. /** \brief Predicate used to indicate the check-state of buttons
  166. *
  167. * \ingroup group__library__windows_controls
  168. */
  169. // [[synesis:class:unary-predicate: is_checked]]
  170. class is_checked
  171. : public stlsoft_ns_qual_std(unary_function)<HWND, BOOL>
  172. {
  173. public:
  174. /// This type
  175. typedef is_checked class_type;
  176. public:
  177. is_checked(int nCheckType = -1)
  178. : m_nCheckType(nCheckType)
  179. {
  180. WINSTL_ASSERT((-1 == nCheckType) || (BST_UNCHECKED == nCheckType) || (BST_CHECKED == nCheckType) || (BST_INDETERMINATE == nCheckType));
  181. }
  182. public:
  183. BOOL operator ()(HWND hwnd) const
  184. {
  185. return is_checked_(hwnd);
  186. }
  187. template <ss_typename_param_k W>
  188. BOOL operator ()(W &wnd) const
  189. {
  190. return is_checked_(winstl_ns_qual(get_HWND)(wnd));
  191. }
  192. private:
  193. BOOL is_checked_(HWND hwnd) const
  194. {
  195. int nCheck = static_cast<int>(::SendMessage(hwnd, BM_GETCHECK, 0, 0L));
  196. if(-1 == m_nCheckType)
  197. {
  198. return nCheck;
  199. }
  200. else
  201. {
  202. return m_nCheckType == nCheck;
  203. }
  204. }
  205. private:
  206. class_type& operator =(class_type const&);
  207. private:
  208. const int m_nCheckType;
  209. };
  210. /** \brief Predicate used to detect whether the window is of a given class
  211. *
  212. * \ingroup group__library__windows_controls
  213. */
  214. // [[synesis:class:unary-predicate: is_class]]
  215. class is_class
  216. : public stlsoft_ns_qual_std(unary_function)<HWND, BOOL>
  217. {
  218. public:
  219. /// This type
  220. typedef is_class class_type;
  221. public:
  222. ss_explicit_k is_class(ws_char_a_t const* windowClass)
  223. : m_bUnicode(false)
  224. {
  225. typedef system_traits<ws_char_a_t> traits_t;
  226. WINSTL_ASSERT(NULL != windowClass);
  227. const traits_t::size_type cchClass = traits_t::str_len(windowClass);
  228. WINSTL_ASSERT(cchClass < STLSOFT_NUM_ELEMENTS(m_name.sza));
  229. ::memcpy(&m_name.sza[0], windowClass, cchClass);
  230. m_name.sza[cchClass] = '\0';
  231. }
  232. ss_explicit_k is_class(ws_char_w_t const* windowClass)
  233. : m_bUnicode(true)
  234. {
  235. typedef system_traits<ws_char_w_t> traits_t;
  236. WINSTL_ASSERT(NULL != windowClass);
  237. const traits_t::size_type cchClass = traits_t::str_len(windowClass);
  238. WINSTL_ASSERT(cchClass < STLSOFT_NUM_ELEMENTS(m_name.szw));
  239. ::memcpy(&m_name.szw[0], windowClass, cchClass);
  240. m_name.szw[cchClass] = '\0';
  241. }
  242. public:
  243. BOOL operator ()(HWND hwnd) const
  244. {
  245. return is_class_(hwnd);
  246. }
  247. template <ss_typename_param_k W>
  248. BOOL operator ()(W &wnd) const
  249. {
  250. return is_class_(winstl_ns_qual(get_HWND)(wnd));
  251. }
  252. private:
  253. BOOL is_class_(HWND hwnd) const
  254. {
  255. return m_bUnicode ? is_class_w_(hwnd) : is_class_a_(hwnd);
  256. }
  257. BOOL is_class_w_(HWND hwnd) const
  258. {
  259. ws_char_w_t szw[256];
  260. return ::GetClassNameW(hwnd, &szw[0], STLSOFT_NUM_ELEMENTS(szw)) &&
  261. 0 == ::lstrcmpiW(&szw[0], &m_name.szw[0]);
  262. }
  263. BOOL is_class_a_(HWND hwnd) const
  264. {
  265. ws_char_a_t sza[256];
  266. return ::GetClassNameA(hwnd, &sza[0], STLSOFT_NUM_ELEMENTS(sza)) &&
  267. 0 == ::lstrcmpiA(&sza[0], &m_name.sza[0]);
  268. }
  269. private:
  270. union
  271. {
  272. ws_char_a_t sza[256];
  273. ws_char_w_t szw[256];
  274. } m_name;
  275. const int m_bUnicode;
  276. // Not to be implemented
  277. private:
  278. class_type& operator =(class_type const&);
  279. };
  280. /** \brief A function class used to insert items at the front of list-box
  281. *
  282. * \ingroup group__library__windows_controls
  283. */
  284. // [[synesis:class:unary-functor: listbox_front_inserter]]
  285. struct listbox_front_inserter
  286. #if !defined(STLSOFT_COMPILER_IS_DMC) || \
  287. __DMC__ > 0x0850
  288. : public stlsoft_ns_qual(unary_function_output_iterator_adaptor)<listbox_front_inserter>
  289. #endif /* compiler */
  290. {
  291. public:
  292. /// This type
  293. typedef listbox_front_inserter class_type;
  294. public:
  295. /// Construct with the target list-box window
  296. ss_explicit_k listbox_front_inserter(HWND hwndListbox)
  297. : m_hwndListbox(hwndListbox)
  298. , m_bUnicode(::IsWindowUnicode(hwndListbox))
  299. {}
  300. listbox_front_inserter(class_type const& rhs)
  301. : m_hwndListbox(rhs.m_hwndListbox)
  302. , m_bUnicode(rhs.m_bUnicode)
  303. {}
  304. #ifdef STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT
  305. /// Function call operator taking the item string
  306. template <ss_typename_param_k S>
  307. void operator ()(S const& s)
  308. {
  309. insert(stlsoft_ns_qual(c_str_ptr)(s));
  310. }
  311. #endif // STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT
  312. /// Function call operator taking the item string
  313. void operator ()(ws_char_a_t const* s)
  314. {
  315. insert(s);
  316. }
  317. /// Function call operator taking the item string
  318. void operator ()(ws_char_w_t const* s)
  319. {
  320. insert(s);
  321. }
  322. // Implementation
  323. private:
  324. void insert(ws_char_a_t const* s)
  325. {
  326. if(m_bUnicode)
  327. {
  328. listbox_insertstring_w(m_hwndListbox, a2w(s), 0);
  329. }
  330. else
  331. {
  332. listbox_insertstring_a(m_hwndListbox, s, 0);
  333. }
  334. }
  335. void insert(ws_char_w_t const* s)
  336. {
  337. if(m_bUnicode)
  338. {
  339. listbox_insertstring_w(m_hwndListbox, s, 0);
  340. }
  341. else
  342. {
  343. listbox_insertstring_a(m_hwndListbox, w2a(s), 0);
  344. }
  345. }
  346. private:
  347. HWND m_hwndListbox;
  348. ws_int32_t m_bUnicode;
  349. };
  350. /** \brief A function class used to add items to a list-box
  351. *
  352. * \ingroup group__library__windows_controls
  353. */
  354. // [[synesis:class:unary-functor: listbox_add_inserter]]
  355. struct listbox_add_inserter
  356. #if !defined(STLSOFT_COMPILER_IS_DMC) || \
  357. __DMC__ > 0x0850
  358. : public stlsoft_ns_qual(unary_function_output_iterator_adaptor)<listbox_add_inserter>
  359. #endif /* compiler */
  360. {
  361. public:
  362. /// This type
  363. typedef listbox_add_inserter class_type;
  364. public:
  365. /// Construct with the target list-box window
  366. ss_explicit_k listbox_add_inserter(HWND hwndListbox)
  367. : m_hwndListbox(hwndListbox)
  368. , m_bUnicode(::IsWindowUnicode(hwndListbox))
  369. {}
  370. listbox_add_inserter(class_type const& rhs)
  371. : m_hwndListbox(rhs.m_hwndListbox)
  372. , m_bUnicode(rhs.m_bUnicode)
  373. {}
  374. #ifdef STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT
  375. /// Function call operator taking the item string
  376. template <ss_typename_param_k S>
  377. void operator ()(S const& s)
  378. {
  379. add(stlsoft_ns_qual(c_str_ptr)(s));
  380. }
  381. #endif // STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT
  382. /// Function call operator taking the item string
  383. void operator ()(ws_char_a_t const* s)
  384. {
  385. add(s);
  386. }
  387. /// Function call operator taking the item string
  388. void operator ()(ws_char_w_t const* s)
  389. {
  390. add(s);
  391. }
  392. // Implementation
  393. private:
  394. void add(ws_char_a_t const* s)
  395. {
  396. if(m_bUnicode)
  397. {
  398. listbox_addstring_w(m_hwndListbox, a2w(s));
  399. }
  400. else
  401. {
  402. listbox_addstring_a(m_hwndListbox, s);
  403. }
  404. }
  405. void add(ws_char_w_t const* s)
  406. {
  407. if(m_bUnicode)
  408. {
  409. listbox_addstring_w(m_hwndListbox, s);
  410. }
  411. else
  412. {
  413. listbox_addstring_a(m_hwndListbox, w2a(s));
  414. }
  415. }
  416. private:
  417. HWND m_hwndListbox;
  418. ws_int32_t m_bUnicode;
  419. };
  420. /** \brief A function class used to insert items to the back of a list-box
  421. *
  422. * \ingroup group__library__windows_controls
  423. */
  424. // [[synesis:class:unary-functor: listbox_back_inserter]]
  425. struct listbox_back_inserter
  426. #if !defined(STLSOFT_COMPILER_IS_DMC) || \
  427. __DMC__ > 0x0850
  428. : public stlsoft_ns_qual(unary_function_output_iterator_adaptor)<listbox_back_inserter>
  429. #endif /* compiler */
  430. {
  431. public:
  432. /// This type
  433. typedef listbox_back_inserter class_type;
  434. public:
  435. /// Construct with the target list-box window
  436. ss_explicit_k listbox_back_inserter(HWND hwndListbox)
  437. : m_hwndListbox(hwndListbox)
  438. , m_bUnicode(::IsWindowUnicode(hwndListbox))
  439. {}
  440. listbox_back_inserter(class_type const& rhs)
  441. : m_hwndListbox(rhs.m_hwndListbox)
  442. , m_bUnicode(rhs.m_bUnicode)
  443. {}
  444. #ifdef STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT
  445. /// Function call operator taking the item string
  446. template <ss_typename_param_k S>
  447. void operator ()(S const& s)
  448. {
  449. insert(stlsoft_ns_qual(c_str_ptr)(s));
  450. }
  451. #endif // STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT
  452. /// Function call operator taking the item string
  453. void operator ()(ws_char_a_t const* s)
  454. {
  455. insert(s);
  456. }
  457. /// Function call operator taking the item string
  458. void operator ()(ws_char_w_t const* s)
  459. {
  460. insert(s);
  461. }
  462. // Implementation
  463. private:
  464. void insert(ws_char_a_t const* s)
  465. {
  466. if(m_bUnicode)
  467. {
  468. listbox_insertstring_w(m_hwndListbox, a2w(s), -1);
  469. }
  470. else
  471. {
  472. listbox_insertstring_a(m_hwndListbox, s, -1);
  473. }
  474. }
  475. void insert(ws_char_w_t const* s)
  476. {
  477. if(m_bUnicode)
  478. {
  479. listbox_insertstring_w(m_hwndListbox, s, -1);
  480. }
  481. else
  482. {
  483. listbox_insertstring_a(m_hwndListbox, w2a(s), -1);
  484. }
  485. }
  486. private:
  487. HWND m_hwndListbox;
  488. ws_int32_t m_bUnicode;
  489. };
  490. /** \brief A function class used to insert items at the front of combo-box
  491. *
  492. * \ingroup group__library__windows_controls
  493. */
  494. // [[synesis:class:unary-functor: combobox_front_inserter]]
  495. struct combobox_front_inserter
  496. #if !defined(STLSOFT_COMPILER_IS_DMC) || \
  497. __DMC__ > 0x0850
  498. : public stlsoft_ns_qual(unary_function_output_iterator_adaptor)<combobox_front_inserter>
  499. #endif /* compiler */
  500. {
  501. public:
  502. /// This type
  503. typedef combobox_front_inserter class_type;
  504. public:
  505. /// Construct with the target combo-box window
  506. ss_explicit_k combobox_front_inserter(HWND hwndListbox)
  507. : m_hwndListbox(hwndListbox)
  508. , m_bUnicode(::IsWindowUnicode(hwndListbox))
  509. {}
  510. combobox_front_inserter(class_type const& rhs)
  511. : m_hwndListbox(rhs.m_hwndListbox)
  512. , m_bUnicode(rhs.m_bUnicode)
  513. {}
  514. #ifdef STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT
  515. /// Function call operator taking the item string
  516. template <ss_typename_param_k S>
  517. void operator ()(S const& s)
  518. {
  519. insert(stlsoft_ns_qual(c_str_ptr)(s));
  520. }
  521. #endif // STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT
  522. /// Function call operator taking the item string
  523. void operator ()(ws_char_a_t const* s)
  524. {
  525. insert(s);
  526. }
  527. /// Function call operator taking the item string
  528. void operator ()(ws_char_w_t const* s)
  529. {
  530. insert(s);
  531. }
  532. // Implementation
  533. private:
  534. void insert(ws_char_a_t const* s)
  535. {
  536. if(m_bUnicode)
  537. {
  538. combobox_insertstring_w(m_hwndListbox, a2w(s), 0);
  539. }
  540. else
  541. {
  542. combobox_insertstring_a(m_hwndListbox, s, 0);
  543. }
  544. }
  545. void insert(ws_char_w_t const* s)
  546. {
  547. if(m_bUnicode)
  548. {
  549. combobox_insertstring_w(m_hwndListbox, s, 0);
  550. }
  551. else
  552. {
  553. combobox_insertstring_a(m_hwndListbox, w2a(s), 0);
  554. }
  555. }
  556. private:
  557. HWND m_hwndListbox;
  558. ws_int32_t m_bUnicode;
  559. };
  560. /** \brief A function class used to add items to a combo-box
  561. *
  562. * \ingroup group__library__windows_controls
  563. */
  564. // [[synesis:class:unary-functor: combobox_add_inserter]]
  565. struct combobox_add_inserter
  566. #if !defined(STLSOFT_COMPILER_IS_DMC) || \
  567. __DMC__ > 0x0850
  568. : public stlsoft_ns_qual(unary_function_output_iterator_adaptor)<combobox_add_inserter>
  569. #endif /* compiler */
  570. {
  571. public:
  572. /// This type
  573. typedef combobox_add_inserter class_type;
  574. public:
  575. /// Construct with the target combo-box window
  576. ss_explicit_k combobox_add_inserter(HWND hwndListbox)
  577. : m_hwndListbox(hwndListbox)
  578. , m_bUnicode(::IsWindowUnicode(hwndListbox))
  579. {}
  580. combobox_add_inserter(class_type const& rhs)
  581. : m_hwndListbox(rhs.m_hwndListbox)
  582. , m_bUnicode(rhs.m_bUnicode)
  583. {}
  584. #ifdef STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT
  585. /// Function call operator taking the item string
  586. template <ss_typename_param_k S>
  587. void operator ()(S const& s)
  588. {
  589. add(stlsoft_ns_qual(c_str_ptr)(s));
  590. }
  591. #endif // STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT
  592. /// Function call operator taking the item string
  593. void operator ()(ws_char_a_t const* s)
  594. {
  595. add(s);
  596. }
  597. /// Function call operator taking the item string
  598. void operator ()(ws_char_w_t const* s)
  599. {
  600. add(s);
  601. }
  602. // Implementation
  603. private:
  604. void add(ws_char_a_t const* s)
  605. {
  606. if(m_bUnicode)
  607. {
  608. combobox_addstring_w(m_hwndListbox, a2w(s));
  609. }
  610. else
  611. {
  612. combobox_addstring_a(m_hwndListbox, s);
  613. }
  614. }
  615. void add(ws_char_w_t const* s)
  616. {
  617. if(m_bUnicode)
  618. {
  619. combobox_addstring_w(m_hwndListbox, s);
  620. }
  621. else
  622. {
  623. combobox_addstring_a(m_hwndListbox, w2a(s));
  624. }
  625. }
  626. private:
  627. HWND m_hwndListbox;
  628. ws_int32_t m_bUnicode;
  629. };
  630. /** \brief A function class used to insert items to the back of a combo-box
  631. *
  632. * \ingroup group__library__windows_controls
  633. */
  634. // [[synesis:class:unary-functor: combobox_back_inserter]]
  635. struct combobox_back_inserter
  636. #if !defined(STLSOFT_COMPILER_IS_DMC) || \
  637. __DMC__ > 0x0850
  638. : public stlsoft_ns_qual(unary_function_output_iterator_adaptor)<combobox_back_inserter>
  639. #endif /* compiler */
  640. {
  641. public:
  642. /// This type
  643. typedef combobox_back_inserter class_type;
  644. public:
  645. /// Construct with the target combo-box window
  646. ss_explicit_k combobox_back_inserter(HWND hwndListbox)
  647. : m_hwndListbox(hwndListbox)
  648. , m_bUnicode(::IsWindowUnicode(hwndListbox))
  649. {}
  650. combobox_back_inserter(class_type const& rhs)
  651. : m_hwndListbox(rhs.m_hwndListbox)
  652. , m_bUnicode(rhs.m_bUnicode)
  653. {}
  654. #ifdef STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT
  655. /// Function call operator taking the item string
  656. template <ss_typename_param_k S>
  657. void operator ()(S const& s)
  658. {
  659. insert(stlsoft_ns_qual(c_str_ptr)(s));
  660. }
  661. #endif // STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT
  662. /// Function call operator taking the item string
  663. void operator ()(ws_char_a_t const* s)
  664. {
  665. insert(s);
  666. }
  667. /// Function call operator taking the item string
  668. void operator ()(ws_char_w_t const* s)
  669. {
  670. insert(s);
  671. }
  672. // Implementation
  673. private:
  674. void insert(ws_char_a_t const* s)
  675. {
  676. if(m_bUnicode)
  677. {
  678. combobox_insertstring_w(m_hwndListbox, a2w(s), -1);
  679. }
  680. else
  681. {
  682. combobox_insertstring_a(m_hwndListbox, s, -1);
  683. }
  684. }
  685. void insert(ws_char_w_t const* s)
  686. {
  687. if(m_bUnicode)
  688. {
  689. combobox_insertstring_w(m_hwndListbox, s, -1);
  690. }
  691. else
  692. {
  693. combobox_insertstring_a(m_hwndListbox, w2a(s), -1);
  694. }
  695. }
  696. private:
  697. HWND m_hwndListbox;
  698. ws_int32_t m_bUnicode;
  699. };
  700. ////////////////////////////////////////////////////////////////////////////
  701. // Unit-testing
  702. #ifdef STLSOFT_UNITTEST
  703. # include "./unittest/functionals_unittest_.h"
  704. #endif /* STLSOFT_UNITTEST */
  705. /* ////////////////////////////////////////////////////////////////////// */
  706. #ifndef _WINSTL_NO_NAMESPACE
  707. # if defined(_STLSOFT_NO_NAMESPACE) || \
  708. defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
  709. } // namespace winstl
  710. # else
  711. } // namespace winstl_project
  712. } // namespace stlsoft
  713. # endif /* _STLSOFT_NO_NAMESPACE */
  714. #endif /* !_WINSTL_NO_NAMESPACE */
  715. /* ////////////////////////////////////////////////////////////////////// */
  716. #endif /* WINSTL_INCL_WINSTL_CONTROL_HPP_FUNCTIONALS */
  717. /* ///////////////////////////// end of file //////////////////////////// */