00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00047 #ifndef WINSTL_INCL_WINSTL_CONTROL_HPP_FUNCTIONALS
00048 #define WINSTL_INCL_WINSTL_CONTROL_HPP_FUNCTIONALS
00049
00050 #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
00051 # define WINSTL_VER_WINSTL_CONTROL_HPP_FUNCTIONALS_MAJOR 4
00052 # define WINSTL_VER_WINSTL_CONTROL_HPP_FUNCTIONALS_MINOR 2
00053 # define WINSTL_VER_WINSTL_CONTROL_HPP_FUNCTIONALS_REVISION 1
00054 # define WINSTL_VER_WINSTL_CONTROL_HPP_FUNCTIONALS_EDIT 78
00055 #endif
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073 #ifndef WINSTL_INCL_WINSTL_H_WINSTL
00074 # include <winstl/winstl.h>
00075 #endif
00076
00077 #if defined(STLSOFT_COMPILER_IS_GCC) && \
00078 __GNUC__ < 3
00079 # error winstl/controls/functionals.hpp is not compatible with GNU C++ prior to 3.0
00080 #endif
00081 #if defined(STLSOFT_COMPILER_IS_MSVC) && \
00082 _MSC_VER < 1100
00083 # error winstl/controls/functionals.hpp is not compatible with Visual C++ 4.2 or earlier
00084 #endif
00085
00086 #ifndef STLSOFT_INCL_STLSOFT_SHIMS_ACCESS_HPP_STRING
00087 # include <stlsoft/shims/access/string.hpp>
00088 #endif
00089 #ifndef STLSOFT_INCL_STLSOFT_ITERATORS_HPP_UNARY_FUNCTION_OUTPUT_ITERATOR_ADAPTOR
00090 # include <stlsoft/iterators/unary_function_output_iterator_adaptor.hpp>
00091 #endif
00092 #ifndef WINSTL_INCL_WINSTL_SHIMS_ACCESS_HPP_STRING
00093 # include <winstl/shims/access/string.hpp>
00094 #endif
00095 #ifndef WINSTL_INCL_SHIMS_ATTRIBUTE_HPP_GET_HWND
00096 # include <winstl/shims/attribute/get_HWND.hpp>
00097 #endif
00098 #ifndef WINSTL_INCL_WINSTL_CONVERSION_HPP_CHAR_CONVERSIONS
00099 # include <winstl/conversion/char_conversions.hpp>
00100 #endif
00101 #ifndef WINSTL_INCL_WINSTL_CONTROLS_H_FUNCTIONS
00102 # include <winstl/controls/functions.h>
00103 #endif
00104 #ifndef WINSTL_INCL_WINSTL_SYSTEM_HPP_SYSTEM_TRAITS
00105 # include <winstl/system/system_traits.hpp>
00106 #endif
00107
00108 #ifndef _WINSTL_CONTROL_FUNCTIONALS_NO_STD
00109 # include <functional>
00110 #else
00111 # error Now need to write that std_binary_function stuff!!
00112 #endif
00113
00114
00115
00116
00117
00118 #ifndef _WINSTL_NO_NAMESPACE
00119 # if defined(_STLSOFT_NO_NAMESPACE) || \
00120 defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
00121
00122 namespace winstl
00123 {
00124 # else
00125
00126
00127 namespace stlsoft
00128 {
00129
00130 namespace winstl_project
00131 {
00132
00133 # endif
00134 #endif
00135
00136
00137
00138
00139
00140 #if defined(STLSOFT_COMPILER_IS_DMC)
00141
00142 #endif
00143
00144
00145
00146
00147
00152
00153 class button_check
00154 : public stlsoft_ns_qual_std(unary_function)<HWND, void>
00155 {
00156 public:
00158 typedef button_check class_type;
00159 public:
00160 ss_explicit_k button_check(int nCheck = BST_CHECKED)
00161 : m_nCheck(nCheck)
00162 {}
00163 button_check(button_check const& rhs)
00164 : m_nCheck(rhs.m_nCheck)
00165 {}
00166
00167 public:
00168 void operator ()(HWND hwnd) const
00169 {
00170 check_(hwnd, m_nCheck);
00171 }
00172 template <ss_typename_param_k W>
00173 void operator ()(W &wnd) const
00174 {
00175 check_(winstl_ns_qual(get_HWND)(wnd), m_nCheck);
00176 }
00177 private:
00178 static void check_(HWND hwnd, int nCheck)
00179 {
00180 ::SendMessage(hwnd, BM_SETCHECK, static_cast<WPARAM>(nCheck), 0L);
00181 }
00182
00183 private:
00184 const int m_nCheck;
00185
00186 private:
00187 class_type& operator =(class_type const&);
00188 };
00189
00190
00195
00196 class is_checked
00197 : public stlsoft_ns_qual_std(unary_function)<HWND, BOOL>
00198 {
00199 public:
00201 typedef is_checked class_type;
00202
00203 public:
00204 is_checked(int nCheckType = -1)
00205 : m_nCheckType(nCheckType)
00206 {
00207 WINSTL_ASSERT((-1 == nCheckType) || (BST_UNCHECKED == nCheckType) || (BST_CHECKED == nCheckType) || (BST_INDETERMINATE == nCheckType));
00208 }
00209
00210 public:
00211 BOOL operator ()(HWND hwnd) const
00212 {
00213 return is_checked_(hwnd);
00214 }
00215 template <ss_typename_param_k W>
00216 BOOL operator ()(W &wnd) const
00217 {
00218 return is_checked_(winstl_ns_qual(get_HWND)(wnd));
00219 }
00220 private:
00221 BOOL is_checked_(HWND hwnd) const
00222 {
00223 int nCheck = static_cast<int>(::SendMessage(hwnd, BM_GETCHECK, 0, 0L));
00224
00225 if(-1 == m_nCheckType)
00226 {
00227 return nCheck;
00228 }
00229 else
00230 {
00231 return m_nCheckType == nCheck;
00232 }
00233 }
00234
00235 private:
00236 class_type& operator =(class_type const&);
00237
00238 private:
00239 const int m_nCheckType;
00240 };
00241
00242
00247
00248 class is_class
00249 : public stlsoft_ns_qual_std(unary_function)<HWND, BOOL>
00250 {
00251 public:
00253 typedef is_class class_type;
00254
00255 public:
00256 ss_explicit_k is_class(ws_char_a_t const* windowClass)
00257 : m_bUnicode(false)
00258 {
00259 typedef system_traits<ws_char_a_t> traits_t;
00260
00261 WINSTL_ASSERT(NULL != windowClass);
00262
00263 const traits_t::size_type cchClass = traits_t::str_len(windowClass);
00264
00265 WINSTL_ASSERT(cchClass < STLSOFT_NUM_ELEMENTS(m_name.sza));
00266
00267 ::memcpy(&m_name.sza[0], windowClass, cchClass);
00268 m_name.sza[cchClass] = '\0';
00269 }
00270 ss_explicit_k is_class(ws_char_w_t const* windowClass)
00271 : m_bUnicode(true)
00272 {
00273 typedef system_traits<ws_char_w_t> traits_t;
00274
00275 WINSTL_ASSERT(NULL != windowClass);
00276
00277 const traits_t::size_type cchClass = traits_t::str_len(windowClass);
00278
00279 WINSTL_ASSERT(cchClass < STLSOFT_NUM_ELEMENTS(m_name.szw));
00280
00281 ::memcpy(&m_name.szw[0], windowClass, cchClass);
00282 m_name.szw[cchClass] = '\0';
00283 }
00284
00285 public:
00286 BOOL operator ()(HWND hwnd) const
00287 {
00288 return is_class_(hwnd);
00289 }
00290 template <ss_typename_param_k W>
00291 BOOL operator ()(W &wnd) const
00292 {
00293 return is_class_(winstl_ns_qual(get_HWND)(wnd));
00294 }
00295 private:
00296 BOOL is_class_(HWND hwnd) const
00297 {
00298 return m_bUnicode ? is_class_w_(hwnd) : is_class_a_(hwnd);
00299 }
00300 BOOL is_class_w_(HWND hwnd) const
00301 {
00302 ws_char_w_t szw[256];
00303
00304 return ::GetClassNameW(hwnd, &szw[0], STLSOFT_NUM_ELEMENTS(szw)) &&
00305 0 == ::lstrcmpiW(&szw[0], &m_name.szw[0]);
00306 }
00307 BOOL is_class_a_(HWND hwnd) const
00308 {
00309 ws_char_a_t sza[256];
00310
00311 return ::GetClassNameA(hwnd, &sza[0], STLSOFT_NUM_ELEMENTS(sza)) &&
00312 0 == ::lstrcmpiA(&sza[0], &m_name.sza[0]);
00313 }
00314
00315 private:
00316 union
00317 {
00318 ws_char_a_t sza[256];
00319 ws_char_w_t szw[256];
00320 } m_name;
00321 const int m_bUnicode;
00322
00323
00324 private:
00325 class_type& operator =(class_type const&);
00326 };
00327
00332
00333 struct listbox_front_inserter
00334 #if !defined(STLSOFT_COMPILER_IS_DMC) || \
00335 __DMC__ > 0x0850
00336 : public stlsoft_ns_qual(unary_function_output_iterator_adaptor)<listbox_front_inserter>
00337 #endif
00338 {
00339 public:
00341 typedef listbox_front_inserter class_type;
00342
00343 public:
00345 ss_explicit_k listbox_front_inserter(HWND hwndListbox)
00346 : m_hwndListbox(hwndListbox)
00347 , m_bUnicode(::IsWindowUnicode(hwndListbox))
00348 {}
00349
00350 listbox_front_inserter(class_type const& rhs)
00351 : m_hwndListbox(rhs.m_hwndListbox)
00352 , m_bUnicode(rhs.m_bUnicode)
00353 {}
00354
00355 #ifdef STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT
00357 template <ss_typename_param_k S>
00358 void operator ()(S const& s)
00359 {
00360 insert(stlsoft_ns_qual(c_str_ptr)(s));
00361 }
00362 #endif // STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT
00364 void operator ()(ws_char_a_t const* s)
00365 {
00366 insert(s);
00367 }
00369 void operator ()(ws_char_w_t const* s)
00370 {
00371 insert(s);
00372 }
00373
00374
00375 private:
00376 void insert(ws_char_a_t const* s)
00377 {
00378 if(m_bUnicode)
00379 {
00380 listbox_insertstring_w(m_hwndListbox, a2w(s), 0);
00381 }
00382 else
00383 {
00384 listbox_insertstring_a(m_hwndListbox, s, 0);
00385 }
00386 }
00387 void insert(ws_char_w_t const* s)
00388 {
00389 if(m_bUnicode)
00390 {
00391 listbox_insertstring_w(m_hwndListbox, s, 0);
00392 }
00393 else
00394 {
00395 listbox_insertstring_a(m_hwndListbox, w2a(s), 0);
00396 }
00397 }
00398
00399 private:
00400 HWND m_hwndListbox;
00401 ws_int32_t m_bUnicode;
00402 };
00403
00408
00409 struct listbox_add_inserter
00410 #if !defined(STLSOFT_COMPILER_IS_DMC) || \
00411 __DMC__ > 0x0850
00412 : public stlsoft_ns_qual(unary_function_output_iterator_adaptor)<listbox_add_inserter>
00413 #endif
00414 {
00415 public:
00417 typedef listbox_add_inserter class_type;
00418
00419 public:
00421 ss_explicit_k listbox_add_inserter(HWND hwndListbox)
00422 : m_hwndListbox(hwndListbox)
00423 , m_bUnicode(::IsWindowUnicode(hwndListbox))
00424 {}
00425
00426 listbox_add_inserter(class_type const& rhs)
00427 : m_hwndListbox(rhs.m_hwndListbox)
00428 , m_bUnicode(rhs.m_bUnicode)
00429 {}
00430
00431 #ifdef STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT
00433 template <ss_typename_param_k S>
00434 void operator ()(S const& s)
00435 {
00436 add(stlsoft_ns_qual(c_str_ptr)(s));
00437 }
00438 #endif // STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT
00440 void operator ()(ws_char_a_t const* s)
00441 {
00442 add(s);
00443 }
00445 void operator ()(ws_char_w_t const* s)
00446 {
00447 add(s);
00448 }
00449
00450
00451 private:
00452 void add(ws_char_a_t const* s)
00453 {
00454 if(m_bUnicode)
00455 {
00456 listbox_addstring_w(m_hwndListbox, a2w(s));
00457 }
00458 else
00459 {
00460 listbox_addstring_a(m_hwndListbox, s);
00461 }
00462 }
00463 void add(ws_char_w_t const* s)
00464 {
00465 if(m_bUnicode)
00466 {
00467 listbox_addstring_w(m_hwndListbox, s);
00468 }
00469 else
00470 {
00471 listbox_addstring_a(m_hwndListbox, w2a(s));
00472 }
00473 }
00474
00475 private:
00476 HWND m_hwndListbox;
00477 ws_int32_t m_bUnicode;
00478 };
00479
00484
00485 struct listbox_back_inserter
00486 #if !defined(STLSOFT_COMPILER_IS_DMC) || \
00487 __DMC__ > 0x0850
00488 : public stlsoft_ns_qual(unary_function_output_iterator_adaptor)<listbox_back_inserter>
00489 #endif
00490 {
00491 public:
00493 typedef listbox_back_inserter class_type;
00494
00495 public:
00497 ss_explicit_k listbox_back_inserter(HWND hwndListbox)
00498 : m_hwndListbox(hwndListbox)
00499 , m_bUnicode(::IsWindowUnicode(hwndListbox))
00500 {}
00501
00502 listbox_back_inserter(class_type const& rhs)
00503 : m_hwndListbox(rhs.m_hwndListbox)
00504 , m_bUnicode(rhs.m_bUnicode)
00505 {}
00506
00507 #ifdef STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT
00509 template <ss_typename_param_k S>
00510 void operator ()(S const& s)
00511 {
00512 insert(stlsoft_ns_qual(c_str_ptr)(s));
00513 }
00514 #endif // STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT
00516 void operator ()(ws_char_a_t const* s)
00517 {
00518 insert(s);
00519 }
00521 void operator ()(ws_char_w_t const* s)
00522 {
00523 insert(s);
00524 }
00525
00526
00527 private:
00528 void insert(ws_char_a_t const* s)
00529 {
00530 if(m_bUnicode)
00531 {
00532 listbox_insertstring_w(m_hwndListbox, a2w(s), -1);
00533 }
00534 else
00535 {
00536 listbox_insertstring_a(m_hwndListbox, s, -1);
00537 }
00538 }
00539 void insert(ws_char_w_t const* s)
00540 {
00541 if(m_bUnicode)
00542 {
00543 listbox_insertstring_w(m_hwndListbox, s, -1);
00544 }
00545 else
00546 {
00547 listbox_insertstring_a(m_hwndListbox, w2a(s), -1);
00548 }
00549 }
00550
00551 private:
00552 HWND m_hwndListbox;
00553 ws_int32_t m_bUnicode;
00554 };
00555
00556
00557
00562
00563 struct combobox_front_inserter
00564 #if !defined(STLSOFT_COMPILER_IS_DMC) || \
00565 __DMC__ > 0x0850
00566 : public stlsoft_ns_qual(unary_function_output_iterator_adaptor)<combobox_front_inserter>
00567 #endif
00568 {
00569 public:
00571 typedef combobox_front_inserter class_type;
00572
00573 public:
00575 ss_explicit_k combobox_front_inserter(HWND hwndListbox)
00576 : m_hwndListbox(hwndListbox)
00577 , m_bUnicode(::IsWindowUnicode(hwndListbox))
00578 {}
00579
00580 combobox_front_inserter(class_type const& rhs)
00581 : m_hwndListbox(rhs.m_hwndListbox)
00582 , m_bUnicode(rhs.m_bUnicode)
00583 {}
00584
00585 #ifdef STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT
00587 template <ss_typename_param_k S>
00588 void operator ()(S const& s)
00589 {
00590 insert(stlsoft_ns_qual(c_str_ptr)(s));
00591 }
00592 #endif // STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT
00594 void operator ()(ws_char_a_t const* s)
00595 {
00596 insert(s);
00597 }
00599 void operator ()(ws_char_w_t const* s)
00600 {
00601 insert(s);
00602 }
00603
00604
00605 private:
00606 void insert(ws_char_a_t const* s)
00607 {
00608 if(m_bUnicode)
00609 {
00610 combobox_insertstring_w(m_hwndListbox, a2w(s), 0);
00611 }
00612 else
00613 {
00614 combobox_insertstring_a(m_hwndListbox, s, 0);
00615 }
00616 }
00617 void insert(ws_char_w_t const* s)
00618 {
00619 if(m_bUnicode)
00620 {
00621 combobox_insertstring_w(m_hwndListbox, s, 0);
00622 }
00623 else
00624 {
00625 combobox_insertstring_a(m_hwndListbox, w2a(s), 0);
00626 }
00627 }
00628
00629 private:
00630 HWND m_hwndListbox;
00631 ws_int32_t m_bUnicode;
00632 };
00633
00638
00639 struct combobox_add_inserter
00640 #if !defined(STLSOFT_COMPILER_IS_DMC) || \
00641 __DMC__ > 0x0850
00642 : public stlsoft_ns_qual(unary_function_output_iterator_adaptor)<combobox_add_inserter>
00643 #endif
00644 {
00645 public:
00647 typedef combobox_add_inserter class_type;
00648
00649 public:
00651 ss_explicit_k combobox_add_inserter(HWND hwndListbox)
00652 : m_hwndListbox(hwndListbox)
00653 , m_bUnicode(::IsWindowUnicode(hwndListbox))
00654 {}
00655
00656 combobox_add_inserter(class_type const& rhs)
00657 : m_hwndListbox(rhs.m_hwndListbox)
00658 , m_bUnicode(rhs.m_bUnicode)
00659 {}
00660
00661 #ifdef STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT
00663 template <ss_typename_param_k S>
00664 void operator ()(S const& s)
00665 {
00666 add(stlsoft_ns_qual(c_str_ptr)(s));
00667 }
00668 #endif // STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT
00670 void operator ()(ws_char_a_t const* s)
00671 {
00672 add(s);
00673 }
00675 void operator ()(ws_char_w_t const* s)
00676 {
00677 add(s);
00678 }
00679
00680
00681 private:
00682 void add(ws_char_a_t const* s)
00683 {
00684 if(m_bUnicode)
00685 {
00686 combobox_addstring_w(m_hwndListbox, a2w(s));
00687 }
00688 else
00689 {
00690 combobox_addstring_a(m_hwndListbox, s);
00691 }
00692 }
00693 void add(ws_char_w_t const* s)
00694 {
00695 if(m_bUnicode)
00696 {
00697 combobox_addstring_w(m_hwndListbox, s);
00698 }
00699 else
00700 {
00701 combobox_addstring_a(m_hwndListbox, w2a(s));
00702 }
00703 }
00704
00705 private:
00706 HWND m_hwndListbox;
00707 ws_int32_t m_bUnicode;
00708 };
00709
00714
00715 struct combobox_back_inserter
00716 #if !defined(STLSOFT_COMPILER_IS_DMC) || \
00717 __DMC__ > 0x0850
00718 : public stlsoft_ns_qual(unary_function_output_iterator_adaptor)<combobox_back_inserter>
00719 #endif
00720 {
00721 public:
00723 typedef combobox_back_inserter class_type;
00724
00725 public:
00727 ss_explicit_k combobox_back_inserter(HWND hwndListbox)
00728 : m_hwndListbox(hwndListbox)
00729 , m_bUnicode(::IsWindowUnicode(hwndListbox))
00730 {}
00731
00732 combobox_back_inserter(class_type const& rhs)
00733 : m_hwndListbox(rhs.m_hwndListbox)
00734 , m_bUnicode(rhs.m_bUnicode)
00735 {}
00736
00737 #ifdef STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT
00739 template <ss_typename_param_k S>
00740 void operator ()(S const& s)
00741 {
00742 insert(stlsoft_ns_qual(c_str_ptr)(s));
00743 }
00744 #endif // STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT
00746 void operator ()(ws_char_a_t const* s)
00747 {
00748 insert(s);
00749 }
00751 void operator ()(ws_char_w_t const* s)
00752 {
00753 insert(s);
00754 }
00755
00756
00757 private:
00758 void insert(ws_char_a_t const* s)
00759 {
00760 if(m_bUnicode)
00761 {
00762 combobox_insertstring_w(m_hwndListbox, a2w(s), -1);
00763 }
00764 else
00765 {
00766 combobox_insertstring_a(m_hwndListbox, s, -1);
00767 }
00768 }
00769 void insert(ws_char_w_t const* s)
00770 {
00771 if(m_bUnicode)
00772 {
00773 combobox_insertstring_w(m_hwndListbox, s, -1);
00774 }
00775 else
00776 {
00777 combobox_insertstring_a(m_hwndListbox, w2a(s), -1);
00778 }
00779 }
00780
00781 private:
00782 HWND m_hwndListbox;
00783 ws_int32_t m_bUnicode;
00784 };
00785
00787
00788
00789 #ifdef STLSOFT_UNITTEST
00790 # include "./unittest/functionals_unittest_.h"
00791 #endif
00792
00793
00794
00795 #ifndef _WINSTL_NO_NAMESPACE
00796 # if defined(_STLSOFT_NO_NAMESPACE) || \
00797 defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
00798 }
00799 # else
00800 }
00801 }
00802 # endif
00803 #endif
00804
00805
00806
00807 #endif
00808
00809