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
00049 #ifndef WINSTL_INCL_WINSTL_SHELL_HPP_DROPHANDLE_SEQUENCE
00050 #define WINSTL_INCL_WINSTL_SHELL_HPP_DROPHANDLE_SEQUENCE
00051
00052 #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
00053 # define WINSTL_VER_WINSTL_SHELL_HPP_DROPHANDLE_SEQUENCE_MAJOR 4
00054 # define WINSTL_VER_WINSTL_SHELL_HPP_DROPHANDLE_SEQUENCE_MINOR 1
00055 # define WINSTL_VER_WINSTL_SHELL_HPP_DROPHANDLE_SEQUENCE_REVISION 3
00056 # define WINSTL_VER_WINSTL_SHELL_HPP_DROPHANDLE_SEQUENCE_EDIT 95
00057 #endif
00058
00059
00060
00061
00062
00063 #ifndef WINSTL_INCL_WINSTL_H_WINSTL
00064 # include <winstl/winstl.h>
00065 #endif
00066 #ifndef STLSOFT_INCL_STLSOFT_MEMORY_HPP_AUTO_BUFFER
00067 # include <stlsoft/memory/auto_buffer.hpp>
00068 #endif
00069 #if defined(STLSOFT_CF_FRAME_STRING_SHIM_NOT_SUPPORTED) || \
00070 ( defined(STLSOFT_COMPILER_IS_MSVC) && \
00071 _MSC_VER < 1200)
00072 # ifndef WINSTL_INCL_WINSTL_MEMORY_HPP_PROCESSHEAP_ALLOCATOR
00073 # include <winstl/memory/processheap_allocator.hpp>
00074 # endif
00075 # ifndef STLSOFT_INCL_STLSOFT_STRING_HPP_SIMPLE_STRING
00076 # include <stlsoft/string/simple_string.hpp>
00077 # endif
00078 #else
00079 # ifndef STLSOFT_INCL_STLSOFT_STRING_HPP_STATIC_STRING
00080 # include <stlsoft/string/static_string.hpp>
00081 # endif
00082 #endif
00083 #ifndef STLSOFT_INCL_STLSOFT_UTIL_STD_HPP_ITERATOR_HELPER
00084 # include <stlsoft/util/std/iterator_helper.hpp>
00085 #endif
00086 #ifndef STLSOFT_INCL_STLSOFT_UTIL_STD_HPP_ITERATOR_GENERATORS
00087 # include <stlsoft/util/std/iterator_generators.hpp>
00088 #endif
00089 #ifndef STLSOFT_INCL_STLSOFT_COLLECTIONS_UTIL_HPP_COLLECTIONS
00090 # include <stlsoft/collections/util/collections.hpp>
00091 #endif
00092
00093
00094
00095
00096
00097 #ifndef _WINSTL_NO_NAMESPACE
00098 # if defined(_STLSOFT_NO_NAMESPACE) || \
00099 defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
00100
00101 namespace winstl
00102 {
00103 # else
00104
00105
00106 namespace stlsoft
00107 {
00108
00109 namespace winstl_project
00110 {
00111
00112 # endif
00113 #endif
00114
00115
00116
00117
00118
00119 #ifdef _STLSOFT_DROPHANDLE_SEQUENCE_VALUE_TYPE
00120 # undef _STLSOFT_DROPHANDLE_SEQUENCE_VALUE_TYPE
00121 #endif
00122
00123 #if defined(STLSOFT_CF_FRAME_STRING_SHIM_NOT_SUPPORTED) || \
00124 ( defined(STLSOFT_COMPILER_IS_MSVC) && \
00125 _MSC_VER < 1200)
00126 # define _STLSOFT_DROPHANDLE_SEQUENCE_VALUE_TYPE(C) stlsoft_ns_qual(basic_simple_string)<C, stlsoft_ns_qual(char_traits)<C>, processheap_allocator<C> >
00127 #else
00128 # define _STLSOFT_DROPHANDLE_SEQUENCE_VALUE_TYPE(C) stlsoft_ns_qual(basic_static_string)<C, WINSTL_CONST_MAX_PATH>
00129 #endif
00130
00131
00132
00133
00134
00135 #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
00136
00137 template <ss_typename_param_k C, ss_typename_param_k T>
00138 class basic_drophandle_sequence;
00139
00140 #endif
00141
00142
00143
00144
00145
00146 #ifdef STLSOFT_DOCUMENTATION_SKIP_SECTION
00147
00156 template <ss_typename_param_k C>
00157 struct drophandle_sequence_traits
00158 {
00165 static ws_uint_t drag_query_file(HDROP hdrop, ws_uint_t index, C *buffer, ws_uint_t cchBuffer);
00166 };
00167
00168 #else
00169
00170 template <ss_typename_param_k C>
00171 struct drophandle_sequence_traits;
00172
00173 STLSOFT_TEMPLATE_SPECIALISATION
00174
00175 struct drophandle_sequence_traits<ws_char_a_t>
00176 {
00177 static ws_uint_t drag_query_file(HDROP hdrop, ws_uint_t index, ws_char_a_t *buffer, ws_uint_t cchBuffer)
00178 {
00179 return DragQueryFileA(hdrop, index, buffer, cchBuffer);
00180 }
00181 };
00182
00183 STLSOFT_TEMPLATE_SPECIALISATION
00184 struct drophandle_sequence_traits<ws_char_w_t>
00185 {
00186 static ws_uint_t drag_query_file(HDROP hdrop, ws_uint_t index, ws_char_w_t *buffer, ws_uint_t cchBuffer)
00187 {
00188 return DragQueryFileW(hdrop, index, buffer, cchBuffer);
00189 }
00190 };
00191
00192 #endif
00193
00194
00195
00203 template< ss_typename_param_k C
00204 #ifdef STLSOFT_CF_TEMPLATE_CLASS_DEFAULT_CLASS_ARGUMENT_SUPPORT
00205 , ss_typename_param_k T = drophandle_sequence_traits<C>
00206 #else
00207 , ss_typename_param_k T
00208 #endif
00209 >
00210 class basic_drophandle_sequence_const_iterator
00211 : public stlsoft_ns_qual(iterator_base)<winstl_ns_qual_std(bidirectional_iterator_tag)
00212 , _STLSOFT_DROPHANDLE_SEQUENCE_VALUE_TYPE(C)
00213 , ws_ptrdiff_t
00214 , void
00215 , _STLSOFT_DROPHANDLE_SEQUENCE_VALUE_TYPE(C)
00216 >
00217 {
00218 public:
00220 typedef C char_type;
00222 typedef T traits_type;
00224 typedef _STLSOFT_DROPHANDLE_SEQUENCE_VALUE_TYPE(C) string_type;
00226 typedef basic_drophandle_sequence_const_iterator<C, T> class_type;
00228 typedef string_type value_type;
00230 typedef ws_uint_t index_type;
00231
00232
00233 protected:
00235 ss_explicit_k basic_drophandle_sequence_const_iterator(HDROP hdrop, index_type index);
00236 public:
00237
00238 basic_drophandle_sequence_const_iterator();
00240 basic_drophandle_sequence_const_iterator(class_type const& rhs);
00241
00243 basic_drophandle_sequence_const_iterator& operator =(class_type const& rhs);
00244
00245
00246 public:
00248 class_type& operator ++();
00250 class_type& operator --();
00252 class_type operator ++(int);
00254 class_type operator --(int);
00256 const value_type operator *() const;
00258 ws_bool_t equal(class_type const& rhs) const;
00259
00260 #if 0
00261 private:
00262 value_type *operator ->();
00263 value_type const *operator ->() const;
00264 #endif
00265
00266
00267 private:
00268 static index_type sentinel_();
00269
00270
00271 private:
00272 friend class basic_drophandle_sequence<C, T>;
00273
00274 HDROP m_hdrop;
00275 index_type m_index;
00276 };
00277
00278
00279
00287 template< ss_typename_param_k C
00288 #ifdef STLSOFT_CF_TEMPLATE_CLASS_DEFAULT_CLASS_ARGUMENT_SUPPORT
00289 , ss_typename_param_k T = drophandle_sequence_traits<C>
00290 #else
00291 , ss_typename_param_k T
00292 #endif
00293 >
00294 class basic_drophandle_sequence
00295 : public stlsoft_ns_qual(stl_collection_tag)
00296 {
00297 public:
00299 typedef C char_type;
00301 typedef T traits_type;
00303 typedef basic_drophandle_sequence<C, T> class_type;
00305 typedef basic_drophandle_sequence_const_iterator<C, T> const_iterator;
00307 typedef ss_typename_type_k const_iterator::value_type value_type;
00309 typedef ws_ptrdiff_t difference_type;
00310 #if defined(STLSOFT_LF_BIDIRECTIONAL_ITERATOR_SUPPORT) && \
00311 !defined(STLSOFT_COMPILER_IS_BORLAND)
00313 typedef
00314 #if !defined(STLSOFT_COMPILER_IS_BORLAND)
00315 ss_typename_type_k
00316 #endif
00317 stlsoft_ns_qual(const_reverse_iterator_generator)< const_iterator
00318 , value_type
00319 , value_type
00320 , void
00321 , difference_type
00322 >::type const_reverse_iterator;
00323 #endif
00324
00325
00326 public:
00328 ss_explicit_k basic_drophandle_sequence(HDROP hdrop, ws_bool_t bOwnHandle = true);
00330 ~basic_drophandle_sequence() stlsoft_throw_0();
00331
00332
00333 public:
00335 ws_size_t size() const;
00337 ws_bool_t empty() const;
00338
00339
00340 public:
00344 const_iterator begin() const;
00348 const_iterator end() const;
00349
00350 #if defined(STLSOFT_LF_BIDIRECTIONAL_ITERATOR_SUPPORT) && \
00351 !defined(STLSOFT_COMPILER_IS_BORLAND)
00355 const_reverse_iterator rbegin() const;
00359 const_reverse_iterator rend() const;
00360 #endif
00361
00362
00363 private:
00364 HDROP m_hdrop;
00365 const ws_bool_t m_bOwnHandle;
00366
00367
00368 private:
00369
00370
00371 private:
00372 basic_drophandle_sequence(class_type const&);
00373 class_type& operator =(class_type const&);
00374 };
00375
00376
00381 typedef basic_drophandle_sequence<ws_char_a_t, drophandle_sequence_traits<ws_char_a_t> > drophandle_sequence_a;
00386 typedef basic_drophandle_sequence<ws_char_w_t, drophandle_sequence_traits<ws_char_w_t> > drophandle_sequence_w;
00391 typedef basic_drophandle_sequence<TCHAR, drophandle_sequence_traits<TCHAR> > drophandle_sequence;
00392
00394
00395
00396 template< ss_typename_param_k C
00397 , ss_typename_param_k T
00398 >
00399 inline ws_bool_t operator ==( basic_drophandle_sequence_const_iterator<C, T> const& lhs
00400 , basic_drophandle_sequence_const_iterator<C, T> const& rhs)
00401 {
00402 return lhs.equal(rhs);
00403 }
00404
00405 template< ss_typename_param_k C
00406 , ss_typename_param_k T
00407 >
00408 inline ws_bool_t operator !=( basic_drophandle_sequence_const_iterator<C, T> const& lhs
00409 , basic_drophandle_sequence_const_iterator<C, T> const& rhs)
00410 {
00411 return !lhs.equal(rhs);
00412 }
00413
00415
00416 #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
00417
00418
00419
00420 template< ss_typename_param_k C
00421 , ss_typename_param_k T
00422 >
00423 inline ss_typename_type_ret_k basic_drophandle_sequence_const_iterator<C, T>::index_type basic_drophandle_sequence_const_iterator<C, T>::sentinel_()
00424 {
00425 return 0x7fffffff;
00426 }
00427
00428 template< ss_typename_param_k C
00429 , ss_typename_param_k T
00430 >
00431 inline basic_drophandle_sequence_const_iterator<C, T>::basic_drophandle_sequence_const_iterator(HDROP hdrop, ss_typename_type_k basic_drophandle_sequence_const_iterator<C, T>::index_type index)
00432 : m_hdrop(hdrop)
00433 , m_index(index)
00434 {}
00435
00436 template< ss_typename_param_k C
00437 , ss_typename_param_k T
00438 >
00439 inline basic_drophandle_sequence_const_iterator<C, T>::basic_drophandle_sequence_const_iterator()
00440 : m_hdrop(0)
00441 , m_index(sentinel_())
00442 {}
00443
00444 template< ss_typename_param_k C
00445 , ss_typename_param_k T
00446 >
00447 inline basic_drophandle_sequence_const_iterator<C, T>::basic_drophandle_sequence_const_iterator(ss_typename_type_k basic_drophandle_sequence_const_iterator<C, T>::class_type const& rhs)
00448 : m_hdrop(rhs.m_hdrop)
00449 , m_index(rhs.m_index)
00450 {}
00451
00452 template< ss_typename_param_k C
00453 , ss_typename_param_k T
00454 >
00455 inline ss_typename_type_ret_k basic_drophandle_sequence_const_iterator<C, T>::class_type& basic_drophandle_sequence_const_iterator<C, T>::operator =(ss_typename_type_k basic_drophandle_sequence_const_iterator<C, T>::class_type const& rhs)
00456 {
00457 m_hdrop = rhs.m_hdrop;
00458 m_index = rhs.m_index;
00459
00460 return *this;
00461 }
00462
00463 template< ss_typename_param_k C
00464 , ss_typename_param_k T
00465 >
00466 inline ss_typename_type_ret_k basic_drophandle_sequence_const_iterator<C, T>::class_type& basic_drophandle_sequence_const_iterator<C, T>::operator ++()
00467 {
00468 WINSTL_MESSAGE_ASSERT("Incrementing the end iterator", m_index != sentinel_());
00469
00470 char_type ch;
00471 ws_uint_t res = traits_type::drag_query_file(m_hdrop, static_cast<ws_uint_t>(m_index + 1), &ch, 1);
00472
00473 if(res == 0)
00474 {
00475
00476 m_index = sentinel_();
00477 }
00478 else
00479 {
00480
00481 ++m_index;
00482 }
00483
00484 return *this;
00485 }
00486
00487 template< ss_typename_param_k C
00488 , ss_typename_param_k T
00489 >
00490 inline ss_typename_type_ret_k basic_drophandle_sequence_const_iterator<C, T>::class_type& basic_drophandle_sequence_const_iterator<C, T>::operator --()
00491 {
00492
00493 if(m_index == sentinel_())
00494 {
00495
00496 m_index = static_cast<index_type>(traits_type::drag_query_file(m_hdrop, 0xFFFFFFFF, NULL, 0));
00497
00498 if(m_index == 0xFFFFFFFF)
00499 {
00500
00501 m_index = sentinel_();
00502 }
00503 else
00504 {
00505
00506 --m_index;
00507 }
00508 }
00509 else
00510 {
00511
00512 --m_index;
00513 }
00514
00515 return *this;
00516 }
00517
00518 template< ss_typename_param_k C
00519 , ss_typename_param_k T
00520 >
00521 inline ss_typename_type_ret_k basic_drophandle_sequence_const_iterator<C, T>::class_type basic_drophandle_sequence_const_iterator<C, T>::operator ++(int)
00522 {
00523 class_type ret(*this);
00524
00525 operator ++();
00526
00527 return ret;
00528 }
00529
00530 template< ss_typename_param_k C
00531 , ss_typename_param_k T
00532 >
00533 inline ss_typename_type_ret_k basic_drophandle_sequence_const_iterator<C, T>::class_type basic_drophandle_sequence_const_iterator<C, T>::operator --(int)
00534 {
00535 class_type ret(*this);
00536
00537 operator --();
00538
00539 return ret;
00540 }
00541
00542 template< ss_typename_param_k C
00543 , ss_typename_param_k T
00544 >
00545 inline const ss_typename_type_k basic_drophandle_sequence_const_iterator<C, T>::value_type basic_drophandle_sequence_const_iterator<C, T>::operator *() const
00546 {
00547 WINSTL_MESSAGE_ASSERT("Dereferencing the end iterator", m_index != sentinel_());
00548
00549 ws_uint_t cch = traits_type::drag_query_file(m_hdrop, static_cast<ws_uint_t>(m_index), NULL, 0);
00550 stlsoft_ns_qual(auto_buffer)<char_type> sz(1 + cch);
00551
00552 if( 0 == sz.size() ||
00553 0 == (cch = traits_type::drag_query_file(m_hdrop, static_cast<ws_uint_t>(m_index), &sz[0], ws_uint_t(sz.size()))))
00554 {
00555 sz[0] = '\0';
00556 }
00557
00558 return value_type(sz.data());
00559 }
00560
00561 template< ss_typename_param_k C
00562 , ss_typename_param_k T
00563 >
00564 inline ws_bool_t basic_drophandle_sequence_const_iterator<C, T>::equal(ss_typename_type_k basic_drophandle_sequence_const_iterator<C, T>::class_type const& rhs) const
00565 {
00566 WINSTL_MESSAGE_ASSERT("Comparing iterators from different sequences", (m_hdrop == NULL || rhs.m_hdrop == NULL || rhs.m_hdrop));
00567
00568 return m_index == rhs.m_index;
00569 }
00570
00571
00572
00573 template <ss_typename_param_k C, ss_typename_param_k T>
00574 inline basic_drophandle_sequence<C, T>::basic_drophandle_sequence(HDROP hdrop, ws_bool_t bOwnHandle )
00575 : m_hdrop(hdrop)
00576 , m_bOwnHandle(bOwnHandle)
00577 {}
00578
00579 template <ss_typename_param_k C, ss_typename_param_k T>
00580 inline basic_drophandle_sequence<C, T>::~basic_drophandle_sequence() stlsoft_throw_0()
00581 {
00582 if(m_bOwnHandle)
00583 {
00584 ::DragFinish(m_hdrop);
00585 }
00586 }
00587
00588 template <ss_typename_param_k C, ss_typename_param_k T>
00589 inline ws_size_t basic_drophandle_sequence<C, T>::size() const
00590 {
00591 return traits_type::drag_query_file(m_hdrop, static_cast<ws_uint_t>(-1), 0, 0);
00592 }
00593
00594 template <ss_typename_param_k C, ss_typename_param_k T>
00595 inline ws_bool_t basic_drophandle_sequence<C, T>::empty() const
00596 {
00597 return size() == 0;
00598 }
00599
00600 template <ss_typename_param_k C, ss_typename_param_k T>
00601 inline ss_typename_type_ret_k basic_drophandle_sequence<C, T>::const_iterator basic_drophandle_sequence<C, T>::begin() const
00602 {
00603 char_type ch;
00604 ws_uint_t res = traits_type::drag_query_file(m_hdrop, 0, &ch, 1);
00605
00606 return const_iterator(m_hdrop, (res == 0) ? const_iterator::sentinel_() : 0);
00607 }
00608
00609 template <ss_typename_param_k C, ss_typename_param_k T>
00610 inline ss_typename_type_ret_k basic_drophandle_sequence<C, T>::const_iterator basic_drophandle_sequence<C, T>::end() const
00611 {
00612 return const_iterator(m_hdrop, const_iterator::sentinel_());
00613 }
00614
00615 #if defined(STLSOFT_LF_BIDIRECTIONAL_ITERATOR_SUPPORT) && \
00616 !defined(STLSOFT_COMPILER_IS_BORLAND)
00617 template <ss_typename_param_k C, ss_typename_param_k T>
00618 inline ss_typename_type_ret_k basic_drophandle_sequence<C, T>::const_reverse_iterator basic_drophandle_sequence<C, T>::rbegin() const
00619 {
00620 return const_reverse_iterator(end());
00621 }
00622
00623 template <ss_typename_param_k C, ss_typename_param_k T>
00624 inline ss_typename_type_ret_k basic_drophandle_sequence<C, T>::const_reverse_iterator basic_drophandle_sequence<C, T>::rend() const
00625 {
00626 return const_reverse_iterator(begin());
00627 }
00628 #endif
00629
00630 #endif
00631
00633
00634
00635 #ifdef STLSOFT_UNITTEST
00636 # include "./unittest/drophandle_sequence_unittest_.h"
00637 #endif
00638
00639
00640
00641 #ifndef _WINSTL_NO_NAMESPACE
00642 # if defined(_STLSOFT_NO_NAMESPACE) || \
00643 defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
00644 }
00645 # else
00646 }
00647 }
00648 # endif
00649 #endif
00650
00651
00652
00653 #endif
00654
00655