STLSoft - ... Robust, Lightweight, Cross-platform, Template Software ... ATLSTL - Template Software for the Active Template Library COMSTL - The Standard Template Library meets the Component Object Model .netSTL - Standard Template Library meets the Microsoft.NET Common Language Runtime InetSTL - The Standard Template Library meets WinInet MFCSTL - Template Software for the Microsoft Foundation Classes UNIXSTL - Template Software for the UNIX Operating System WinSTL - where the Standard Template Library meets the Win32 API

Main Page   Modules   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

winstl_control_functionals.h

Go to the documentation of this file.
00001 /* 
00002  * File:        winstl_control_functionals.h
00003  *
00004  * Purpose:     Functionals for application to controls.
00005  *
00006  * Created:     8th October 2002
00007  * Updated:     11th September 2004
00008  *
00009  * Home:        http://stlsoft.org/
00010  *
00011  * Copyright (c) 2002-2004, Matthew Wilson and Synesis Software
00012  * All rights reserved.
00013  *
00014  * Redistribution and use in source and binary forms, with or without
00015  * modification, are permitted provided that the following conditions are met:
00016  *
00017  * - Redistributions of source code must retain the above copyright notice, this
00018  *   list of conditions and the following disclaimer.
00019  * - Redistributions in binary form must reproduce the above copyright notice,
00020  *   this list of conditions and the following disclaimer in the documentation
00021  *   and/or other materials provided with the distribution.
00022  * - Neither the name(s) of Matthew Wilson and Synesis Software nor the names of
00023  *   any contributors may be used to endorse or promote products derived from
00024  *   this software without specific prior written permission.
00025  *
00026  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00027  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00028  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00029  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00030  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00031  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00032  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00033  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00034  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00035  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00036  * POSSIBILITY OF SUCH DAMAGE.
00037  *
00038  * 
00039 
00040 
00044 
00045 #ifndef WINSTL_INCL_H_WINSTL_CONTROL_FUNCTIONALS
00046 #define WINSTL_INCL_H_WINSTL_CONTROL_FUNCTIONALS
00047 
00048 #ifndef __STLSOFT_DOCUMENTATION_SKIP_SECTION
00049 # define WINSTL_VER_H_WINSTL_CONTROL_FUNCTIONALS_MAJOR      2
00050 # define WINSTL_VER_H_WINSTL_CONTROL_FUNCTIONALS_MINOR      0
00051 # define WINSTL_VER_H_WINSTL_CONTROL_FUNCTIONALS_REVISION   1
00052 # define WINSTL_VER_H_WINSTL_CONTROL_FUNCTIONALS_EDIT       35
00053 #endif /* !__STLSOFT_DOCUMENTATION_SKIP_SECTION */
00054 
00055 /* 
00056  * Compatibility
00057  */
00058 
00059 /*
00060 [Incompatibilies-start]
00061 __STLSOFT_COMPILER_IS_GCC: __GNUC__<3
00062 __STLSOFT_COMPILER_IS_MSVC: _MSC_VER<1200
00063 [Incompatibilies-end]
00064  */
00065 
00066 /* 
00067  * Includes
00068  */
00069 
00070 #ifndef WINSTL_INCL_H_WINSTL
00071 # include "winstl.h"                    // Include the WinSTL root header
00072 #endif /* !WINSTL_INCL_H_WINSTL */
00073 
00074 #if defined(__STLSOFT_COMPILER_IS_GCC) && \
00075     __GNUC__ < 3
00076 # error winstl_control_functionals.h is not compatible with GNU C++ prior to 3.0
00077 #endif /* compiler */
00078 #if defined(__STLSOFT_COMPILER_IS_MSVC) && \
00079     _MSC_VER < 1200
00080 # error winstl_control_functionals.h is not compatible with Visual C++ 5.0 or earlier
00081 #endif /* compiler */
00082 
00083 #ifndef STLSOFT_INCL_H_STLSOFT_STRING_ACCESS
00084 # include "stlsoft_string_access.h"     // stlsoft::c_str_ptr
00085 #endif /* !STLSOFT_INCL_H_STLSOFT_STRING_ACCESS */
00086 #ifndef WINSTL_INCL_H_WINSTL_STRING_ACCESS
00087 # include "winstl_string_access.h"      // winstl::c_str_ptr
00088 #endif /* !WINSTL_INCL_H_WINSTL_STRING_ACCESS */
00089 #ifndef WINSTL_INCL_H_WINSTL_CHAR_CONVERSIONS
00090 # include "winstl_char_conversions.h"      // winstl::a2w, w2a
00091 #endif /* !WINSTL_INCL_H_WINSTL_CHAR_CONVERSIONS */
00092 #ifndef WINSTL_INCL_H_WINSTL_CONTROL_FUNCTIONS
00093 # include "winstl_control_functions.h"     // winstl::listbox_add_string, ...
00094 #endif /* !WINSTL_INCL_H_WINSTL_CONTROL_FUNCTIONS */
00095 
00096 /* 
00097  * Namespace
00098  */
00099 
00100 #ifndef _WINSTL_NO_NAMESPACE
00101 # if defined(_STLSOFT_NO_NAMESPACE) || \
00102      defined(__STLSOFT_DOCUMENTATION_SKIP_SECTION)
00103 /* There is no stlsoft namespace, so must define ::winstl */
00104 namespace winstl
00105 {
00106 # else
00107 /* Define stlsoft::winstl_project */
00108 
00109 namespace stlsoft
00110 {
00111 
00112 namespace winstl_project
00113 {
00114 
00115 # endif /* _STLSOFT_NO_NAMESPACE */
00116 #endif /* !_WINSTL_NO_NAMESPACE */
00117 
00118 #if !defined(__STLSOFT_COMPILER_IS_MWERKS)
00119 stlsoft_ns_using(c_str_ptr)
00120 #endif /* compiler */
00121 
00122 /* 
00123 
00126 
00130 
00135 
00136 /* 
00137  * Classes
00138  */
00139 
00141 struct listbox_front_inserter
00142 {
00143 public:
00145     ss_explicit_k listbox_front_inserter(HWND hwndListbox)
00146         : m_hwndListbox(hwndListbox)
00147         , m_bUnicode(::IsWindowUnicode(hwndListbox))
00148     {}
00149 
00150 #ifdef __STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT
00151 
00152     template <ss_typename_param_k S>
00153     void operator ()(S const &s)
00154     {
00155         insert(c_str_ptr(s));
00156     }
00157 #endif // __STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT
00158 
00159     void operator ()(ws_char_a_t const *s)
00160     {
00161         insert(s);
00162     }
00164     void operator ()(ws_char_w_t const *s)
00165     {
00166         insert(s);
00167     }
00168 
00169 // Implementation
00170 private:
00171     void insert(ws_char_a_t const *s)
00172     {
00173         if(m_bUnicode)
00174         {
00175             listbox_insertstring_w(m_hwndListbox, a2w(s), 0);
00176         }
00177         else
00178         {
00179             listbox_insertstring_a(m_hwndListbox, s, 0);
00180         }
00181     }
00182     void insert(ws_char_w_t const *s)
00183     {
00184         if(m_bUnicode)
00185         {
00186             listbox_insertstring_w(m_hwndListbox, s, 0);
00187         }
00188         else
00189         {
00190             listbox_insertstring_a(m_hwndListbox, w2a(s), 0);
00191         }
00192     }
00193 
00194 private:
00195     HWND        m_hwndListbox;
00196     ws_int32_t  m_bUnicode;
00197 };
00198 
00200 struct listbox_add_inserter
00201 {
00202 public:
00204     ss_explicit_k listbox_add_inserter(HWND hwndListbox)
00205         : m_hwndListbox(hwndListbox)
00206         , m_bUnicode(::IsWindowUnicode(hwndListbox))
00207     {}
00208 
00209 #ifdef __STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT
00210 
00211     template <ss_typename_param_k S>
00212     void operator ()(S const &s)
00213     {
00214         add(c_str_ptr(s));
00215     }
00216 #endif // __STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT
00217 
00218     void operator ()(ws_char_a_t const *s)
00219     {
00220         add(s);
00221     }
00223     void operator ()(ws_char_w_t const *s)
00224     {
00225         add(s);
00226     }
00227 
00228 // Implementation
00229 private:
00230     void add(ws_char_a_t const *s)
00231     {
00232         if(m_bUnicode)
00233         {
00234             listbox_addstring_w(m_hwndListbox, a2w(s));
00235         }
00236         else
00237         {
00238             listbox_addstring_a(m_hwndListbox, s);
00239         }
00240     }
00241     void add(ws_char_w_t const *s)
00242     {
00243         if(m_bUnicode)
00244         {
00245             listbox_addstring_w(m_hwndListbox, s);
00246         }
00247         else
00248         {
00249             listbox_addstring_a(m_hwndListbox, w2a(s));
00250         }
00251     }
00252 
00253 private:
00254     HWND        m_hwndListbox;
00255     ws_int32_t  m_bUnicode;
00256 };
00257 
00259 struct listbox_back_inserter
00260 {
00261 public:
00263     ss_explicit_k listbox_back_inserter(HWND hwndListbox)
00264         : m_hwndListbox(hwndListbox)
00265         , m_bUnicode(::IsWindowUnicode(hwndListbox))
00266     {}
00267 
00268 #ifdef __STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT
00269 
00270     template <ss_typename_param_k S>
00271     void operator ()(S const &s)
00272     {
00273         insert(c_str_ptr(s));
00274     }
00275 #endif // __STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT
00276 
00277     void operator ()(ws_char_a_t const *s)
00278     {
00279         insert(s);
00280     }
00282     void operator ()(ws_char_w_t const *s)
00283     {
00284         insert(s);
00285     }
00286 
00287 // Implementation
00288 private:
00289     void insert(ws_char_a_t const *s)
00290     {
00291         if(m_bUnicode)
00292         {
00293             listbox_insertstring_w(m_hwndListbox, a2w(s), -1);
00294         }
00295         else
00296         {
00297             listbox_insertstring_a(m_hwndListbox, s, -1);
00298         }
00299     }
00300     void insert(ws_char_w_t const *s)
00301     {
00302         if(m_bUnicode)
00303         {
00304             listbox_insertstring_w(m_hwndListbox, s, -1);
00305         }
00306         else
00307         {
00308             listbox_insertstring_a(m_hwndListbox, w2a(s), -1);
00309         }
00310     }
00311 
00312 private:
00313     HWND        m_hwndListbox;
00314     ws_int32_t  m_bUnicode;
00315 };
00316 
00317 
00318 
00320 struct combobox_front_inserter
00321 {
00322 public:
00324     ss_explicit_k combobox_front_inserter(HWND hwndListbox)
00325         : m_hwndListbox(hwndListbox)
00326         , m_bUnicode(::IsWindowUnicode(hwndListbox))
00327     {}
00328 
00329 #ifdef __STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT
00330 
00331     template <ss_typename_param_k S>
00332     void operator ()(S const &s)
00333     {
00334         insert(c_str_ptr(s));
00335     }
00336 #endif // __STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT
00337 
00338     void operator ()(ws_char_a_t const *s)
00339     {
00340         insert(s);
00341     }
00343     void operator ()(ws_char_w_t const *s)
00344     {
00345         insert(s);
00346     }
00347 
00348 // Implementation
00349 private:
00350     void insert(ws_char_a_t const *s)
00351     {
00352         if(m_bUnicode)
00353         {
00354             combobox_insertstring_w(m_hwndListbox, a2w(s), 0);
00355         }
00356         else
00357         {
00358             combobox_insertstring_a(m_hwndListbox, s, 0);
00359         }
00360     }
00361     void insert(ws_char_w_t const *s)
00362     {
00363         if(m_bUnicode)
00364         {
00365             combobox_insertstring_w(m_hwndListbox, s, 0);
00366         }
00367         else
00368         {
00369             combobox_insertstring_a(m_hwndListbox, w2a(s), 0);
00370         }
00371     }
00372 
00373 private:
00374     HWND        m_hwndListbox;
00375     ws_int32_t  m_bUnicode;
00376 };
00377 
00379 struct combobox_add_inserter
00380 {
00381 public:
00383     ss_explicit_k combobox_add_inserter(HWND hwndListbox)
00384         : m_hwndListbox(hwndListbox)
00385         , m_bUnicode(::IsWindowUnicode(hwndListbox))
00386     {}
00387 
00388 #ifdef __STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT
00389 
00390     template <ss_typename_param_k S>
00391     void operator ()(S const &s)
00392     {
00393         add(c_str_ptr(s));
00394     }
00395 #endif // __STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT
00396 
00397     void operator ()(ws_char_a_t const *s)
00398     {
00399         add(s);
00400     }
00402     void operator ()(ws_char_w_t const *s)
00403     {
00404         add(s);
00405     }
00406 
00407 // Implementation
00408 private:
00409     void add(ws_char_a_t const *s)
00410     {
00411         if(m_bUnicode)
00412         {
00413             combobox_addstring_w(m_hwndListbox, a2w(s));
00414         }
00415         else
00416         {
00417             combobox_addstring_a(m_hwndListbox, s);
00418         }
00419     }
00420     void add(ws_char_w_t const *s)
00421     {
00422         if(m_bUnicode)
00423         {
00424             combobox_addstring_w(m_hwndListbox, s);
00425         }
00426         else
00427         {
00428             combobox_addstring_a(m_hwndListbox, w2a(s));
00429         }
00430     }
00431 
00432 private:
00433     HWND        m_hwndListbox;
00434     ws_int32_t  m_bUnicode;
00435 };
00436 
00438 struct combobox_back_inserter
00439 {
00440 public:
00442     ss_explicit_k combobox_back_inserter(HWND hwndListbox)
00443         : m_hwndListbox(hwndListbox)
00444         , m_bUnicode(::IsWindowUnicode(hwndListbox))
00445     {}
00446 
00447 #ifdef __STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT
00448 
00449     template <ss_typename_param_k S>
00450     void operator ()(S const &s)
00451     {
00452         insert(c_str_ptr(s));
00453     }
00454 #endif // __STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT
00455 
00456     void operator ()(ws_char_a_t const *s)
00457     {
00458         insert(s);
00459     }
00461     void operator ()(ws_char_w_t const *s)
00462     {
00463         insert(s);
00464     }
00465 
00466 // Implementation
00467 private:
00468     void insert(ws_char_a_t const *s)
00469     {
00470         if(m_bUnicode)
00471         {
00472             combobox_insertstring_w(m_hwndListbox, a2w(s), -1);
00473         }
00474         else
00475         {
00476             combobox_insertstring_a(m_hwndListbox, s, -1);
00477         }
00478     }
00479     void insert(ws_char_w_t const *s)
00480     {
00481         if(m_bUnicode)
00482         {
00483             combobox_insertstring_w(m_hwndListbox, s, -1);
00484         }
00485         else
00486         {
00487             combobox_insertstring_a(m_hwndListbox, w2a(s), -1);
00488         }
00489     }
00490 
00491 private:
00492     HWND        m_hwndListbox;
00493     ws_int32_t  m_bUnicode;
00494 };
00495 
00497 // Unit-testing
00498 
00499 #ifdef STLSOFT_UNITTEST
00500 
00501 namespace unittest
00502 {
00503     ss_bool_t test_winstl_control_functionals(unittest_reporter *r)
00504     {
00505         using stlsoft::unittest::unittest_initialiser;
00506 
00507         ss_bool_t               bSuccess    =   true;
00508 
00509         unittest_initialiser    init(r, "WinSTL", "control_functionals", __FILE__);
00510 
00511 #if 0
00512         if(<<TODO>>)
00513         {
00514             r->report("<<TODO>> failed ", __LINE__);
00515             bSuccess = false;
00516         }
00517 #endif /* 0 */
00518 
00519         return bSuccess;
00520     }
00521 
00522     unittest_registrar    unittest_winstl_control_functionals(test_winstl_control_functionals);
00523 
00524 } // namespace unittest
00525 
00526 #endif /* STLSOFT_UNITTEST */
00527 
00528 /* 
00529 
00531 
00532 /* 
00533 
00534 #ifndef _WINSTL_NO_NAMESPACE
00535 # if defined(_STLSOFT_NO_NAMESPACE) || \
00536      defined(__STLSOFT_DOCUMENTATION_SKIP_SECTION)
00537 } // namespace winstl
00538 # else
00539 } // namespace winstl_project
00540 } // namespace stlsoft
00541 # endif /* _STLSOFT_NO_NAMESPACE */
00542 #endif /* !_WINSTL_NO_NAMESPACE */
00543 
00544 /* 
00545 
00546 #endif /* WINSTL_INCL_H_WINSTL_CONTROL_FUNCTIONALS */
00547 
00548 /* 

STLSoft Libraries documentation © Synesis Software Pty Ltd, 2001-2004