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
00041
00042
00049 #ifndef WINSTL_INCL_WINSTL_CONTROLS_HPP_LISTVIEW_SEQUENCE
00050 #define WINSTL_INCL_WINSTL_CONTROLS_HPP_LISTVIEW_SEQUENCE
00051
00052 #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
00053 # define WINSTL_VER_WINSTL_CONTROLS_HPP_LISTVIEW_SEQUENCE_MAJOR 4
00054 # define WINSTL_VER_WINSTL_CONTROLS_HPP_LISTVIEW_SEQUENCE_MINOR 3
00055 # define WINSTL_VER_WINSTL_CONTROLS_HPP_LISTVIEW_SEQUENCE_REVISION 2
00056 # define WINSTL_VER_WINSTL_CONTROLS_HPP_LISTVIEW_SEQUENCE_EDIT 76
00057 #endif
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 #ifndef STLSOFT_INCL_STLSOFT_COLLECTIONS_UTIL_HPP_COLLECTIONS
00077 # include <stlsoft/collections/util/collections.hpp>
00078 #endif
00079 #ifndef STLSOFT_INCL_STLSOFT_MEMORY_HPP_AUTO_BUFFER
00080 # include <stlsoft/memory/auto_buffer.hpp>
00081 #endif
00082 #ifndef WINSTL_INCL_WINSTL_MEMORY_HPP_PROCESSHEAP_ALLOCATOR
00083 # include <winstl/memory/processheap_allocator.hpp>
00084 #endif
00085 #ifndef STLSOFT_INCL_STLSOFT_STRING_HPP_SHIM_STRING
00086 # include <stlsoft/string/shim_string.hpp>
00087 #endif
00088 #ifndef STLSOFT_INCL_STLSOFT_STRING_HPP_SIMPLE_STRING
00089 # include <stlsoft/string/simple_string.hpp>
00090 #endif
00091 #ifndef STLSOFT_INCL_STLSOFT_UTIL_STD_HPP_ITERATOR_HELPER
00092 # include <stlsoft/util/std/iterator_helper.hpp>
00093 #endif
00094 #ifndef WINSTL_INCL_WINSTL_CONTROLS_H_COMMCTRL_FUNCTIONS
00095 # include <winstl/controls/commctrl_functions.h>
00096 #endif
00097 #ifdef WINSTL_LISTVIEW_SEQUENCE_CUSTOM_STRING_TYPE
00098 typedef WINSTL_LISTVIEW_SEQUENCE_CUSTOM_STRING_TYPE lvs_string_t;
00099 #else
00100 # ifdef STLSOFT_CF_TEMPLATE_CLASS_DEFAULT_CLASS_ARGUMENT_SUPPORT
00101 typedef stlsoft_ns_qual(basic_simple_string)<TCHAR> lvs_string_t;
00102 # else
00103 typedef stlsoft_ns_qual(basic_simple_string)< TCHAR
00104 , stlsoft_ns_qual(stlsoft_char_traits)<TCHAR>
00105 , winstl_ns_qual(processheap_allocator)<TCHAR>
00106 > lvs_string_t;
00107 # endif
00108 #endif
00109 #ifndef WINSTL_INCL_WINSTL_SHIMS_ACCESS_HPP_STRING
00110 # include <winstl/shims/access/string.hpp>
00111 #endif
00112
00113
00114
00115
00116
00117 #ifndef _WINSTL_NO_NAMESPACE
00118 # if defined(_STLSOFT_NO_NAMESPACE) || \
00119 defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
00120
00121 namespace winstl
00122 {
00123 # else
00124
00125
00126 namespace stlsoft
00127 {
00128
00129 namespace winstl_project
00130 {
00131
00132 # endif
00133 #endif
00134
00135
00136
00137
00138
00139 #ifndef _WINSTL_NO_NAMESPACE
00140 using ::lvs_string_t;
00141 #endif
00142
00143
00144
00145
00146
00151
00152 class listview_sequence_item
00153 {
00154 public:
00155
00156
00157 public:
00158 listview_sequence_item(HWND hwndListView, int iIndex)
00159 : m_hwndListView(hwndListView)
00160 , m_index(iIndex)
00161 {}
00162
00163 public:
00164 lvs_string_t text(int iSubItem = 0) const
00165 {
00166 typedef stlsoft_ns_qual(auto_buffer_old)< TCHAR
00167 , processheap_allocator<TCHAR>
00168 , 256
00169 > buffer_t;
00170
00171 ws_size_t cb = buffer_t::internal_size();
00172 LV_ITEM item;
00173
00174 item.mask = LVIF_TEXT;
00175 item.iItem = m_index;
00176 item.iSubItem = iSubItem;
00177
00178 for(;; cb += buffer_t::internal_size())
00179 {
00180 buffer_t buffer(cb);
00181
00182 item.cchTextMax = static_cast<int>(cb);
00183 item.pszText = &buffer[0];
00184
00185 if(!ListView_GetItem(m_hwndListView, &item))
00186 {
00187 item.cchTextMax = 0;
00188 break;
00189 }
00190 else
00191 {
00192 ss_size_t len = static_cast<ss_size_t>(lstrlen(item.pszText));
00193
00194 if(len + 1 < cb)
00195 {
00196 return lvs_string_t(item.pszText, len);
00197 }
00198 }
00199 }
00200
00201 return lvs_string_t();
00202 }
00203
00204 int index() const
00205 {
00206 return m_index;
00207 }
00208 HWND hwnd() const
00209 {
00210 return m_hwndListView;
00211 }
00212
00213 int image() const;
00214 int selected_image() const;
00215 ws_dword_t data() const
00216 {
00217 LV_ITEM item;
00218
00219 item.mask = LVIF_PARAM;
00220 item.iItem = m_index;
00221 item.iSubItem = 0;
00222
00223 return ListView_GetItem(m_hwndListView, &item) ? static_cast<ws_dword_t>(item.lParam) : 0;
00224 }
00226 UINT state(UINT mask = 0xffffffff) const
00227 {
00228 return ListView_GetItemState(m_hwndListView, m_index, mask);
00229 }
00230
00231 private:
00232 HWND m_hwndListView;
00233 int m_index;
00234 };
00235
00236
00241 class listview_sequence
00242 : public stlsoft_ns_qual(stl_collection_tag)
00243 {
00244 public:
00246 typedef listview_sequence_item sequence_value_type;
00247 typedef sequence_value_type value_type;
00249 typedef ss_size_t size_type;
00251 typedef ws_ptrdiff_t difference_type;
00253 typedef listview_sequence sequence_class_type;
00254
00255
00256 public:
00257 ss_explicit_k listview_sequence(HWND hwndListView)
00258 : m_hwndListView(hwndListView)
00259 {}
00260
00261 public:
00263 class const_iterator
00264 : public stlsoft_ns_qual(iterator_base)<winstl_ns_qual_std(random_access_iterator_tag)
00265 , sequence_value_type
00266 , ws_ptrdiff_t
00267 , void
00268 , sequence_value_type
00269 >
00270 {
00271 typedef const_iterator class_type;
00272 public:
00273 typedef sequence_value_type value_type;
00274
00275 public:
00276 const_iterator()
00277 : m_hwndListView(NULL)
00278 , m_index(-1)
00279 {}
00280 const_iterator(HWND hwndListView, int iIndex)
00281 : m_hwndListView(hwndListView)
00282 , m_index(iIndex)
00283 {}
00284 const_iterator(class_type const& rhs)
00285 : m_hwndListView(rhs.m_hwndListView)
00286 , m_index(rhs.m_index)
00287 {}
00288
00289 class_type& operator =(class_type const& rhs)
00290 {
00291 m_hwndListView = rhs.m_hwndListView;
00292 m_index = rhs.m_index;
00293
00294 return *this;
00295 }
00296
00297 public:
00299 value_type operator *() const
00300 {
00301 return value_type(m_hwndListView, m_index);
00302 }
00303
00304 bool operator ==(class_type const& rhs) const
00305 {
00306 WINSTL_MESSAGE_ASSERT("Comparing iterators from different listview_sequence instances!", m_hwndListView == rhs.m_hwndListView);
00307
00308 return m_index == rhs.m_index;
00309 }
00310
00311 bool operator !=(class_type const& rhs) const
00312 {
00313 WINSTL_MESSAGE_ASSERT("Comparing iterators from different listview_sequence instances!", m_hwndListView == rhs.m_hwndListView);
00314
00315 return m_index != rhs.m_index;
00316 }
00317
00319 class_type& operator ++()
00320 {
00321 WINSTL_MESSAGE_ASSERT("Attempting to increment an off-the-end iterator", m_index < ListView_GetItemCount(m_hwndListView));
00322
00323 ++m_index;
00324
00325 return *this;
00326 }
00327
00329 class_type operator ++(int)
00330 {
00331 class_type ret(*this);
00332
00333 operator ++();
00334
00335 return ret;
00336 }
00337
00339 class_type& operator --()
00340 {
00341 WINSTL_MESSAGE_ASSERT("Attempting to decrement an iterator at the start of the sequence", 0 < m_index);
00342
00343 --m_index;
00344
00345 return *this;
00346 }
00347
00349 class_type operator --(int)
00350 {
00351 class_type ret(*this);
00352
00353 operator --();
00354
00355 return ret;
00356 }
00357
00358
00359
00361 class_type& operator +=(difference_type index)
00362 {
00363 m_index += index;
00364
00365 return *this;
00366 }
00367
00369 class_type& operator -=(difference_type index)
00370 {
00371 m_index -= index;
00372
00373 return *this;
00374 }
00375
00377 value_type operator [](difference_type index) const
00378 {
00379 return value_type(m_hwndListView, m_index + index);
00380 }
00381
00383 difference_type distance(class_type const& rhs) const
00384 {
00385 return m_index - rhs.m_index;
00386 }
00387
00389 class_type operator -(difference_type n) const
00390 {
00391 return class_type(*this) -= n;
00392 }
00393
00395 class_type operator +(difference_type n) const
00396 {
00397 return class_type(*this) += n;
00398 }
00399
00401 difference_type operator -(class_type const& rhs) const
00402 {
00403 return distance(rhs);
00404 }
00405
00406
00407 private:
00408 HWND m_hwndListView;
00409 int m_index;
00410 };
00411
00412 #if defined(STLSOFT_LF_BIDIRECTIONAL_ITERATOR_SUPPORT)
00414 typedef stlsoft_ns_qual(const_reverse_iterator_base)< const_iterator
00415 , value_type
00416 , value_type
00417 , void
00418 , difference_type
00419 > const_reverse_iterator;
00420 #endif
00421
00422
00423 public:
00425 size_type size() const
00426 {
00427 return static_cast<size_type>(ListView_GetItemCount(m_hwndListView));
00428 }
00430 ws_bool_t empty() const
00431 {
00432 return 0 == size();
00433 }
00435 static size_type max_size()
00436 {
00437 return static_cast<size_type>(-1) / sizeof(LPCTSTR);
00438 }
00439
00440
00441 public:
00442 const_iterator begin() const
00443 {
00444 return const_iterator(m_hwndListView, 0);
00445 }
00446 const_iterator end() const
00447 {
00448 return const_iterator(m_hwndListView, static_cast<int>(size()));
00449 }
00450
00451 #if defined(STLSOFT_LF_BIDIRECTIONAL_ITERATOR_SUPPORT)
00455 const_reverse_iterator rbegin() const
00456 {
00457 return const_reverse_iterator(end());
00458 }
00462 const_reverse_iterator rend() const
00463 {
00464 return const_reverse_iterator(begin());
00465 }
00466 #endif
00467
00468
00469 public:
00470 value_type operator [](size_type index) const
00471 {
00472 return value_type(m_hwndListView, static_cast<int>(index));
00473 }
00474
00475 private:
00476 HWND m_hwndListView;
00477 };
00478
00479
00480
00481
00482
00483 inline stlsoft_ns_qual(basic_shim_string)<TCHAR, 64, true, processheap_allocator<TCHAR> > c_str_ptr_null(listview_sequence_item const& lvi)
00484 {
00485 return stlsoft_ns_qual(c_str_ptr_null)(lvi.text());
00486 }
00487 #ifdef UNICODE
00488 inline stlsoft_ns_qual(basic_shim_string)<TCHAR, 64, true, processheap_allocator<TCHAR> > c_str_ptr_null_w(listview_sequence_item const& lvi)
00489 #else
00490 inline stlsoft_ns_qual(basic_shim_string)<TCHAR, 64, true, processheap_allocator<TCHAR> > c_str_ptr_null_a(listview_sequence_item const& lvi)
00491 #endif
00492 {
00493 return stlsoft_ns_qual(c_str_ptr_null)(lvi.text());
00494 }
00495
00496 inline stlsoft_ns_qual(basic_shim_string)<TCHAR, 64, false, processheap_allocator<TCHAR> > c_str_ptr(listview_sequence_item const& lvi)
00497 {
00498 return stlsoft_ns_qual(c_str_ptr)(lvi.text());
00499 }
00500 #ifdef UNICODE
00501 inline stlsoft_ns_qual(basic_shim_string)<TCHAR, 64, true, processheap_allocator<TCHAR> > c_str_ptr_w(listview_sequence_item const& lvi)
00502 #else
00503 inline stlsoft_ns_qual(basic_shim_string)<TCHAR, 64, true, processheap_allocator<TCHAR> > c_str_ptr_a(listview_sequence_item const& lvi)
00504 #endif
00505 {
00506 return stlsoft_ns_qual(c_str_ptr)(lvi.text());
00507 }
00508
00509 inline stlsoft_ns_qual(basic_shim_string)<TCHAR, 64, false, processheap_allocator<TCHAR> > c_str_data(listview_sequence_item const& lvi)
00510 {
00511 return stlsoft_ns_qual(c_str_data)(lvi.text());
00512 }
00513 #ifdef UNICODE
00514 inline stlsoft_ns_qual(basic_shim_string)<TCHAR, 64, true, processheap_allocator<TCHAR> > c_str_data_w(listview_sequence_item const& lvi)
00515 #else
00516 inline stlsoft_ns_qual(basic_shim_string)<TCHAR, 64, true, processheap_allocator<TCHAR> > c_str_data_a(listview_sequence_item const& lvi)
00517 #endif
00518 {
00519 return stlsoft_ns_qual(c_str_data)(lvi.text());
00520 }
00521
00522 inline ws_size_t c_str_len(listview_sequence_item const& lvi)
00523 {
00524 return stlsoft_ns_qual(c_str_len)(lvi.text());
00525 }
00526
00527
00528
00529 template< ss_typename_param_k S
00530 >
00531 inline S& operator <<(S& s, listview_sequence_item const& lvi)
00532 {
00533 s << lvi.text();
00534
00535 return s;
00536 }
00537
00538
00539
00540 #ifndef _WINSTL_NO_NAMESPACE
00541 # if defined(_STLSOFT_NO_NAMESPACE) || \
00542 defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
00543 }
00544 # else
00545 }
00546 }
00547 # endif
00548 #endif
00549
00550
00551
00552
00553
00554
00555
00556
00557
00558 #ifndef _WINSTL_NO_NAMESPACE
00559 # if !defined(_STLSOFT_NO_NAMESPACE) && \
00560 !defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
00561 namespace stlsoft
00562 {
00563 # else
00564
00565 # endif
00566
00567 using ::winstl::c_str_ptr_null;
00568 using ::winstl::c_str_ptr_null_a;
00569 using ::winstl::c_str_ptr_null_w;
00570
00571 using ::winstl::c_str_ptr;
00572 using ::winstl::c_str_ptr_a;
00573 using ::winstl::c_str_ptr_w;
00574
00575 using ::winstl::c_str_data;
00576 using ::winstl::c_str_data_a;
00577 using ::winstl::c_str_data_w;
00578
00579 using ::winstl::c_str_len;
00580
00581 # if !defined(_STLSOFT_NO_NAMESPACE) && \
00582 !defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
00583 }
00584 # else
00585
00586 # endif
00587 #endif
00588
00589
00590
00591 #endif
00592
00593