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.

653 lines
24 KiB

  1. /* /////////////////////////////////////////////////////////////////////////
  2. * File: winstl/shell/drophandle_sequence.hpp
  3. *
  4. * Purpose: Contains the basic_drophandle_sequence template class, and ANSI
  5. * and Unicode specialisations thereof.
  6. *
  7. * Created: 13th November 2002
  8. * Updated: 26th July 2012
  9. *
  10. * Home: http://stlsoft.org/
  11. *
  12. * Copyright (c) 2002-2012, Matthew Wilson and Synesis Software
  13. * All rights reserved.
  14. *
  15. * Redistribution and use in source and binary forms, with or without
  16. * modification, are permitted provided that the following conditions are met:
  17. *
  18. * - Redistributions of source code must retain the above copyright notice, this
  19. * list of conditions and the following disclaimer.
  20. * - Redistributions in binary form must reproduce the above copyright notice,
  21. * this list of conditions and the following disclaimer in the documentation
  22. * and/or other materials provided with the distribution.
  23. * - Neither the name(s) of Matthew Wilson and Synesis Software nor the names of
  24. * any contributors may be used to endorse or promote products derived from
  25. * this software without specific prior written permission.
  26. *
  27. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  28. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  29. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  30. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  31. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  32. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  33. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  34. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  35. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  36. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  37. * POSSIBILITY OF SUCH DAMAGE.
  38. *
  39. * ////////////////////////////////////////////////////////////////////// */
  40. /** \file winstl/shell/drophandle_sequence.hpp
  41. *
  42. * \brief [C++ only] Definition of the winstl::basic_drophandle_sequence
  43. * class template
  44. * (\ref group__library__windows_shell "Windows Shell" Library).
  45. */
  46. #ifndef WINSTL_INCL_WINSTL_SHELL_HPP_DROPHANDLE_SEQUENCE
  47. #define WINSTL_INCL_WINSTL_SHELL_HPP_DROPHANDLE_SEQUENCE
  48. #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
  49. # define WINSTL_VER_WINSTL_SHELL_HPP_DROPHANDLE_SEQUENCE_MAJOR 4
  50. # define WINSTL_VER_WINSTL_SHELL_HPP_DROPHANDLE_SEQUENCE_MINOR 1
  51. # define WINSTL_VER_WINSTL_SHELL_HPP_DROPHANDLE_SEQUENCE_REVISION 5
  52. # define WINSTL_VER_WINSTL_SHELL_HPP_DROPHANDLE_SEQUENCE_EDIT 97
  53. #endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
  54. /* /////////////////////////////////////////////////////////////////////////
  55. * Includes
  56. */
  57. #ifndef WINSTL_INCL_WINSTL_H_WINSTL
  58. # include <winstl/winstl.h>
  59. #endif /* !WINSTL_INCL_WINSTL_H_WINSTL */
  60. #ifndef STLSOFT_INCL_STLSOFT_MEMORY_HPP_AUTO_BUFFER
  61. # include <stlsoft/memory/auto_buffer.hpp>
  62. #endif /* !STLSOFT_INCL_STLSOFT_MEMORY_HPP_AUTO_BUFFER */
  63. #if defined(STLSOFT_CF_FRAME_STRING_SHIM_NOT_SUPPORTED) || \
  64. ( defined(STLSOFT_COMPILER_IS_MSVC) && \
  65. _MSC_VER < 1200)
  66. # ifndef WINSTL_INCL_WINSTL_MEMORY_HPP_PROCESSHEAP_ALLOCATOR
  67. # include <winstl/memory/processheap_allocator.hpp>
  68. # endif /* !WINSTL_INCL_WINSTL_MEMORY_HPP_PROCESSHEAP_ALLOCATOR */
  69. # ifndef STLSOFT_INCL_STLSOFT_STRING_HPP_SIMPLE_STRING
  70. # include <stlsoft/string/simple_string.hpp>
  71. # endif /* !STLSOFT_INCL_STLSOFT_STRING_HPP_SIMPLE_STRING */
  72. #else /* ? STLSOFT_CF_FRAME_STRING_SHIM_NOT_SUPPORTED */
  73. # ifndef STLSOFT_INCL_STLSOFT_STRING_HPP_STATIC_STRING
  74. # include <stlsoft/string/static_string.hpp>
  75. # endif /* !STLSOFT_INCL_STLSOFT_STRING_HPP_STATIC_STRING */
  76. #endif /* STLSOFT_CF_FRAME_STRING_SHIM_NOT_SUPPORTED */
  77. #ifndef STLSOFT_INCL_STLSOFT_UTIL_STD_HPP_ITERATOR_HELPER
  78. # include <stlsoft/util/std/iterator_helper.hpp>
  79. #endif /* !STLSOFT_INCL_STLSOFT_UTIL_STD_HPP_ITERATOR_HELPER */
  80. #ifndef STLSOFT_INCL_STLSOFT_UTIL_STD_HPP_ITERATOR_GENERATORS
  81. # include <stlsoft/util/std/iterator_generators.hpp>
  82. #endif /* !STLSOFT_INCL_STLSOFT_UTIL_STD_HPP_ITERATOR_GENERATORS */
  83. #ifndef STLSOFT_INCL_STLSOFT_COLLECTIONS_UTIL_HPP_COLLECTIONS
  84. # include <stlsoft/collections/util/collections.hpp>
  85. #endif /* !STLSOFT_INCL_STLSOFT_COLLECTIONS_UTIL_HPP_COLLECTIONS */
  86. /* /////////////////////////////////////////////////////////////////////////
  87. * Namespace
  88. */
  89. #ifndef _WINSTL_NO_NAMESPACE
  90. # if defined(_STLSOFT_NO_NAMESPACE) || \
  91. defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
  92. /* There is no stlsoft namespace, so must define ::winstl */
  93. namespace winstl
  94. {
  95. # else
  96. /* Define stlsoft::winstl_project */
  97. namespace stlsoft
  98. {
  99. namespace winstl_project
  100. {
  101. # endif /* _STLSOFT_NO_NAMESPACE */
  102. #endif /* !_WINSTL_NO_NAMESPACE */
  103. /* /////////////////////////////////////////////////////////////////////////
  104. * Typedefs
  105. */
  106. #ifdef _STLSOFT_DROPHANDLE_SEQUENCE_VALUE_TYPE
  107. # undef _STLSOFT_DROPHANDLE_SEQUENCE_VALUE_TYPE
  108. #endif /* _STLSOFT_DROPHANDLE_SEQUENCE_VALUE_TYPE */
  109. #if defined(STLSOFT_CF_FRAME_STRING_SHIM_NOT_SUPPORTED) || \
  110. ( defined(STLSOFT_COMPILER_IS_MSVC) && \
  111. _MSC_VER < 1200)
  112. # define _STLSOFT_DROPHANDLE_SEQUENCE_VALUE_TYPE(C) stlsoft_ns_qual(basic_simple_string)<C, stlsoft_ns_qual(char_traits)<C>, processheap_allocator<C> >
  113. #else /* ? STLSOFT_CF_FRAME_STRING_SHIM_NOT_SUPPORTED */
  114. # define _STLSOFT_DROPHANDLE_SEQUENCE_VALUE_TYPE(C) stlsoft_ns_qual(basic_static_string)<C, WINSTL_CONST_MAX_PATH>
  115. #endif /* STLSOFT_CF_FRAME_STRING_SHIM_NOT_SUPPORTED */
  116. /* /////////////////////////////////////////////////////////////////////////
  117. * Forward declarations
  118. */
  119. #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
  120. template <ss_typename_param_k C, ss_typename_param_k T>
  121. class basic_drophandle_sequence;
  122. #endif /* STLSOFT_DOCUMENTATION_SKIP_SECTION */
  123. /* /////////////////////////////////////////////////////////////////////////
  124. * Classes
  125. */
  126. #ifdef STLSOFT_DOCUMENTATION_SKIP_SECTION
  127. /** \brief Traits for accessing the correct drop-handle functions for a given character type
  128. *
  129. * \ingroup group__library__windows_shell
  130. *
  131. * drophandle_sequence_traits is a traits class for determining the correct
  132. * drop-handle structures and functions for a given character type.
  133. *
  134. * \param C The character type
  135. */
  136. template <ss_typename_param_k C>
  137. struct drophandle_sequence_traits
  138. {
  139. /// Queries the information from the given drop handle
  140. ///
  141. /// \param hdrop The drop handle
  142. /// \param index The index of the requested item
  143. /// \param buffer The buffer within which to write the results
  144. /// \param cchBuffer The size of \c buffer in characters
  145. static ws_uint_t drag_query_file(HDROP hdrop, ws_uint_t index, C* buffer, ws_uint_t cchBuffer);
  146. };
  147. #else
  148. template <ss_typename_param_k C>
  149. struct drophandle_sequence_traits;
  150. STLSOFT_TEMPLATE_SPECIALISATION
  151. struct drophandle_sequence_traits<ws_char_a_t>
  152. {
  153. static ws_uint_t drag_query_file(HDROP hdrop, ws_uint_t index, ws_char_a_t* buffer, ws_uint_t cchBuffer)
  154. {
  155. return DragQueryFileA(hdrop, index, buffer, cchBuffer);
  156. }
  157. };
  158. STLSOFT_TEMPLATE_SPECIALISATION
  159. struct drophandle_sequence_traits<ws_char_w_t>
  160. {
  161. static ws_uint_t drag_query_file(HDROP hdrop, ws_uint_t index, ws_char_w_t* buffer, ws_uint_t cchBuffer)
  162. {
  163. return DragQueryFileW(hdrop, index, buffer, cchBuffer);
  164. }
  165. };
  166. #endif /* STLSOFT_DOCUMENTATION_SKIP_SECTION */
  167. // class basic_drophandle_sequence_const_iterator
  168. /** \brief Iterator for the basic_drophandle_sequence class
  169. *
  170. * \ingroup group__library__windows_shell
  171. *
  172. * \param C The character type
  173. * \param T The traits type. For translators that support default template arguments this defaults to drophandle_sequence_traits<C>
  174. */
  175. template< ss_typename_param_k C
  176. #ifdef STLSOFT_CF_TEMPLATE_CLASS_DEFAULT_CLASS_ARGUMENT_SUPPORT
  177. , ss_typename_param_k T = drophandle_sequence_traits<C>
  178. #else /* ? STLSOFT_CF_TEMPLATE_CLASS_DEFAULT_CLASS_ARGUMENT_SUPPORT */
  179. , ss_typename_param_k T /* = drophandle_sequence_traits<C> */
  180. #endif /* STLSOFT_CF_TEMPLATE_CLASS_DEFAULT_CLASS_ARGUMENT_SUPPORT */
  181. >
  182. class basic_drophandle_sequence_const_iterator
  183. : public stlsoft_ns_qual(iterator_base)<winstl_ns_qual_std(bidirectional_iterator_tag)
  184. , _STLSOFT_DROPHANDLE_SEQUENCE_VALUE_TYPE(C)
  185. , ws_ptrdiff_t
  186. , void // By-Value Temporary reference
  187. , _STLSOFT_DROPHANDLE_SEQUENCE_VALUE_TYPE(C) // By-Value Temporary reference category
  188. >
  189. {
  190. public:
  191. /// The character type
  192. typedef C char_type;
  193. /// The traits type
  194. typedef T traits_type;
  195. /// The string type
  196. typedef _STLSOFT_DROPHANDLE_SEQUENCE_VALUE_TYPE(C) string_type;
  197. /// The current parameterisation of the type
  198. typedef basic_drophandle_sequence_const_iterator<C, T> class_type;
  199. /// The value type
  200. typedef string_type value_type;
  201. /// The index type
  202. typedef ws_uint_t index_type;
  203. // Construction
  204. protected:
  205. /// Create an iterator based on the given drop handle
  206. ss_explicit_k basic_drophandle_sequence_const_iterator(HDROP hdrop, index_type index);
  207. public:
  208. // Default constructor
  209. basic_drophandle_sequence_const_iterator();
  210. /// Copy constructor
  211. basic_drophandle_sequence_const_iterator(class_type const& rhs);
  212. /// Copy assignment operator
  213. basic_drophandle_sequence_const_iterator& operator =(class_type const& rhs);
  214. // Operators
  215. public:
  216. /// Pre-increment operator
  217. class_type& operator ++();
  218. /// Pre-decrement operator
  219. class_type& operator --();
  220. /// Post-increment operator
  221. class_type operator ++(int);
  222. /// Post-decrement operator
  223. class_type operator --(int);
  224. /// Dereference
  225. const value_type operator *() const;
  226. /// Evaluates whether \c this and \c rhs are equivalent
  227. ws_bool_t equal(class_type const& rhs) const;
  228. #if 0
  229. private:
  230. value_type *operator ->();
  231. value_type const *operator ->() const;
  232. #endif /* 0 */
  233. // Implementation
  234. private:
  235. static index_type sentinel_();
  236. // Members
  237. private:
  238. friend class basic_drophandle_sequence<C, T>;
  239. HDROP m_hdrop;
  240. index_type m_index;
  241. };
  242. // class basic_drophandle_sequence
  243. /** \brief This class wraps an STL-like sequence interface over a Win32 drop handle
  244. *
  245. * \ingroup group__library__windows_shell
  246. *
  247. * \param C The character type
  248. * \param T The traits type. For translators that support default template arguments this defaults to drophandle_sequence_traits<C>
  249. */
  250. template< ss_typename_param_k C
  251. #ifdef STLSOFT_CF_TEMPLATE_CLASS_DEFAULT_CLASS_ARGUMENT_SUPPORT
  252. , ss_typename_param_k T = drophandle_sequence_traits<C>
  253. #else /* ? STLSOFT_CF_TEMPLATE_CLASS_DEFAULT_CLASS_ARGUMENT_SUPPORT */
  254. , ss_typename_param_k T /* = drophandle_sequence_traits<C> */
  255. #endif /* STLSOFT_CF_TEMPLATE_CLASS_DEFAULT_CLASS_ARGUMENT_SUPPORT */
  256. >
  257. class basic_drophandle_sequence
  258. : public stlsoft_ns_qual(stl_collection_tag)
  259. {
  260. public:
  261. /// \brief The character type
  262. typedef C char_type;
  263. /// \brief The traits type
  264. typedef T traits_type;
  265. /// \brief The current parameterisation of the type
  266. typedef basic_drophandle_sequence<C, T> class_type;
  267. /// \brief The non-mutating (const) iterator type
  268. typedef basic_drophandle_sequence_const_iterator<C, T> const_iterator;
  269. /// \brief The value type
  270. typedef ss_typename_type_k const_iterator::value_type value_type;
  271. /// \brief The difference type
  272. typedef ws_ptrdiff_t difference_type;
  273. #if defined(STLSOFT_LF_BIDIRECTIONAL_ITERATOR_SUPPORT) && \
  274. !defined(STLSOFT_COMPILER_IS_BORLAND)
  275. /// \brief The non-mutating (const) reverse iterator type
  276. typedef
  277. #if !defined(STLSOFT_COMPILER_IS_BORLAND)
  278. ss_typename_type_k
  279. #endif /* compiler */
  280. stlsoft_ns_qual(const_reverse_iterator_generator)< const_iterator
  281. , value_type
  282. , value_type // By-Value Temporary reference category
  283. , void // By-Value Temporary reference category
  284. , difference_type
  285. >::type const_reverse_iterator;
  286. #endif /* STLSOFT_LF_BIDIRECTIONAL_ITERATOR_SUPPORT */
  287. // Construction
  288. public:
  289. /// \brief Construct a sequence based on the contents of the given drop handle
  290. ss_explicit_k basic_drophandle_sequence(HDROP hdrop, ws_bool_t bOwnHandle = true);
  291. /// \brief Release any resources aquired
  292. ~basic_drophandle_sequence() stlsoft_throw_0();
  293. // Attributes
  294. public:
  295. /// \brief The number of elements in the sequence
  296. ws_size_t size() const;
  297. /// \brief Indicates whether the sequence is empty
  298. ws_bool_t empty() const;
  299. // Iteration
  300. public:
  301. /// \brief Begins the iteration
  302. ///
  303. /// \return An iterator representing the start of the sequence
  304. const_iterator begin() const;
  305. /// \brief Ends the iteration
  306. ///
  307. /// \return An iterator representing the end of the sequence
  308. const_iterator end() const;
  309. #if defined(STLSOFT_LF_BIDIRECTIONAL_ITERATOR_SUPPORT) && \
  310. !defined(STLSOFT_COMPILER_IS_BORLAND)
  311. /// \brief Begins the reverse iteration
  312. ///
  313. /// \return An iterator representing the start of the reverse sequence
  314. const_reverse_iterator rbegin() const;
  315. /// \brief Ends the reverse iteration
  316. ///
  317. /// \return An iterator representing the end of the reverse sequence
  318. const_reverse_iterator rend() const;
  319. #endif /* STLSOFT_LF_BIDIRECTIONAL_ITERATOR_SUPPORT */
  320. // Members
  321. private:
  322. HDROP m_hdrop;
  323. const ws_bool_t m_bOwnHandle;
  324. // Implementation
  325. private:
  326. // Not to be implemented
  327. private:
  328. basic_drophandle_sequence(class_type const&);
  329. class_type& operator =(class_type const&);
  330. };
  331. /* Typedefs to commonly encountered types. */
  332. /** \brief Specialisation of the basic_drophandle_sequence template for the ANSI character type \c char
  333. *
  334. * \ingroup group__library__shell
  335. */
  336. typedef basic_drophandle_sequence<ws_char_a_t, drophandle_sequence_traits<ws_char_a_t> > drophandle_sequence_a;
  337. /** \brief Specialisation of the basic_drophandle_sequence template for the Unicode character type \c wchar_t
  338. *
  339. * \ingroup group__library__shell
  340. */
  341. typedef basic_drophandle_sequence<ws_char_w_t, drophandle_sequence_traits<ws_char_w_t> > drophandle_sequence_w;
  342. /** \brief Specialisation of the basic_drophandle_sequence template for the ANSI character type \c char
  343. *
  344. * \ingroup group__library__shell
  345. */
  346. typedef basic_drophandle_sequence<TCHAR, drophandle_sequence_traits<TCHAR> > drophandle_sequence;
  347. ////////////////////////////////////////////////////////////////////////////
  348. // Operators
  349. template< ss_typename_param_k C
  350. , ss_typename_param_k T
  351. >
  352. inline ws_bool_t operator ==( basic_drophandle_sequence_const_iterator<C, T> const& lhs
  353. , basic_drophandle_sequence_const_iterator<C, T> const& rhs)
  354. {
  355. return lhs.equal(rhs);
  356. }
  357. template< ss_typename_param_k C
  358. , ss_typename_param_k T
  359. >
  360. inline ws_bool_t operator !=( basic_drophandle_sequence_const_iterator<C, T> const& lhs
  361. , basic_drophandle_sequence_const_iterator<C, T> const& rhs)
  362. {
  363. return !lhs.equal(rhs);
  364. }
  365. ////////////////////////////////////////////////////////////////////////////
  366. #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
  367. // basic_drophandle_sequence_const_iterator
  368. template< ss_typename_param_k C
  369. , ss_typename_param_k T
  370. >
  371. inline /* static */ ss_typename_type_ret_k basic_drophandle_sequence_const_iterator<C, T>::index_type basic_drophandle_sequence_const_iterator<C, T>::sentinel_()
  372. {
  373. return 0x7fffffff;
  374. }
  375. template< ss_typename_param_k C
  376. , ss_typename_param_k T
  377. >
  378. inline /* ss_explicit_k */ 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)
  379. : m_hdrop(hdrop)
  380. , m_index(index)
  381. {}
  382. template< ss_typename_param_k C
  383. , ss_typename_param_k T
  384. >
  385. inline basic_drophandle_sequence_const_iterator<C, T>::basic_drophandle_sequence_const_iterator()
  386. : m_hdrop(0)
  387. , m_index(sentinel_())
  388. {}
  389. template< ss_typename_param_k C
  390. , ss_typename_param_k T
  391. >
  392. 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)
  393. : m_hdrop(rhs.m_hdrop)
  394. , m_index(rhs.m_index)
  395. {}
  396. template< ss_typename_param_k C
  397. , ss_typename_param_k T
  398. >
  399. 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)
  400. {
  401. m_hdrop = rhs.m_hdrop;
  402. m_index = rhs.m_index;
  403. return *this;
  404. }
  405. template< ss_typename_param_k C
  406. , ss_typename_param_k T
  407. >
  408. inline ss_typename_type_ret_k basic_drophandle_sequence_const_iterator<C, T>::class_type& basic_drophandle_sequence_const_iterator<C, T>::operator ++()
  409. {
  410. WINSTL_MESSAGE_ASSERT("Incrementing the end iterator", m_index != sentinel_());
  411. ws_uint_t const res = traits_type::drag_query_file(m_hdrop, static_cast<ws_uint_t>(m_index + 1), NULL, 0);
  412. if(res == 0)
  413. {
  414. // Failed, so become 'end'
  415. m_index = sentinel_();
  416. }
  417. else
  418. {
  419. // Fine, so increment to next
  420. ++m_index;
  421. }
  422. return *this;
  423. }
  424. template< ss_typename_param_k C
  425. , ss_typename_param_k T
  426. >
  427. inline ss_typename_type_ret_k basic_drophandle_sequence_const_iterator<C, T>::class_type& basic_drophandle_sequence_const_iterator<C, T>::operator --()
  428. {
  429. // If currently at 'end' ....
  430. if(m_index == sentinel_())
  431. {
  432. // ... then determine the new end ...
  433. m_index = static_cast<index_type>(traits_type::drag_query_file(m_hdrop, static_cast<ws_uint_t>(0xFFFFFFFF), NULL, 0));
  434. if(m_index == 0xFFFFFFFF)
  435. {
  436. // ... failed. Must set to end again!
  437. m_index = sentinel_();
  438. }
  439. else
  440. {
  441. // ... decrement from end
  442. --m_index;
  443. }
  444. }
  445. else
  446. {
  447. // ... decrement from current position
  448. --m_index;
  449. }
  450. return *this;
  451. }
  452. template< ss_typename_param_k C
  453. , ss_typename_param_k T
  454. >
  455. inline ss_typename_type_ret_k basic_drophandle_sequence_const_iterator<C, T>::class_type basic_drophandle_sequence_const_iterator<C, T>::operator ++(int)
  456. {
  457. class_type ret(*this);
  458. operator ++();
  459. return ret;
  460. }
  461. template< ss_typename_param_k C
  462. , ss_typename_param_k T
  463. >
  464. inline ss_typename_type_ret_k basic_drophandle_sequence_const_iterator<C, T>::class_type basic_drophandle_sequence_const_iterator<C, T>::operator --(int)
  465. {
  466. class_type ret(*this);
  467. operator --();
  468. return ret;
  469. }
  470. template< ss_typename_param_k C
  471. , ss_typename_param_k T
  472. >
  473. inline const ss_typename_type_k basic_drophandle_sequence_const_iterator<C, T>::value_type basic_drophandle_sequence_const_iterator<C, T>::operator *() const
  474. {
  475. WINSTL_MESSAGE_ASSERT("Dereferencing the end iterator", m_index != sentinel_());
  476. ws_uint_t cch = traits_type::drag_query_file(m_hdrop, static_cast<ws_uint_t>(m_index), NULL, 0);
  477. stlsoft_ns_qual(auto_buffer)<char_type> sz(1 + cch);
  478. if( 0 == sz.size() ||
  479. 0 == (cch = traits_type::drag_query_file(m_hdrop, static_cast<ws_uint_t>(m_index), &sz[0], ws_uint_t(sz.size()))))
  480. {
  481. sz[0] = '\0';
  482. }
  483. return value_type(sz.data());
  484. }
  485. template< ss_typename_param_k C
  486. , ss_typename_param_k T
  487. >
  488. 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
  489. {
  490. WINSTL_MESSAGE_ASSERT("Comparing iterators from different sequences", (m_hdrop == NULL || rhs.m_hdrop == NULL || m_hdrop == rhs.m_hdrop));
  491. return m_index == rhs.m_index;
  492. }
  493. // basic_drophandle_sequence
  494. template <ss_typename_param_k C, ss_typename_param_k T>
  495. inline basic_drophandle_sequence<C, T>::basic_drophandle_sequence(HDROP hdrop, ws_bool_t bOwnHandle /* = true */)
  496. : m_hdrop(hdrop)
  497. , m_bOwnHandle(bOwnHandle)
  498. {}
  499. template <ss_typename_param_k C, ss_typename_param_k T>
  500. inline basic_drophandle_sequence<C, T>::~basic_drophandle_sequence() stlsoft_throw_0()
  501. {
  502. if(m_bOwnHandle)
  503. {
  504. ::DragFinish(m_hdrop);
  505. }
  506. }
  507. template <ss_typename_param_k C, ss_typename_param_k T>
  508. inline ws_size_t basic_drophandle_sequence<C, T>::size() const
  509. {
  510. return traits_type::drag_query_file(m_hdrop, static_cast<ws_uint_t>(0xFFFFFFFF), NULL, 0);
  511. }
  512. template <ss_typename_param_k C, ss_typename_param_k T>
  513. inline ws_bool_t basic_drophandle_sequence<C, T>::empty() const
  514. {
  515. return size() == 0;
  516. }
  517. template <ss_typename_param_k C, ss_typename_param_k T>
  518. inline ss_typename_type_ret_k basic_drophandle_sequence<C, T>::const_iterator basic_drophandle_sequence<C, T>::begin() const
  519. {
  520. ws_uint_t const res = traits_type::drag_query_file(m_hdrop, 0, NULL, 0);
  521. return const_iterator(m_hdrop, (res == 0) ? const_iterator::sentinel_() : 0);
  522. }
  523. template <ss_typename_param_k C, ss_typename_param_k T>
  524. inline ss_typename_type_ret_k basic_drophandle_sequence<C, T>::const_iterator basic_drophandle_sequence<C, T>::end() const
  525. {
  526. return const_iterator(m_hdrop, const_iterator::sentinel_());
  527. }
  528. #if defined(STLSOFT_LF_BIDIRECTIONAL_ITERATOR_SUPPORT) && \
  529. !defined(STLSOFT_COMPILER_IS_BORLAND)
  530. template <ss_typename_param_k C, ss_typename_param_k T>
  531. inline ss_typename_type_ret_k basic_drophandle_sequence<C, T>::const_reverse_iterator basic_drophandle_sequence<C, T>::rbegin() const
  532. {
  533. return const_reverse_iterator(end());
  534. }
  535. template <ss_typename_param_k C, ss_typename_param_k T>
  536. inline ss_typename_type_ret_k basic_drophandle_sequence<C, T>::const_reverse_iterator basic_drophandle_sequence<C, T>::rend() const
  537. {
  538. return const_reverse_iterator(begin());
  539. }
  540. #endif /* STLSOFT_LF_BIDIRECTIONAL_ITERATOR_SUPPORT */
  541. #endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
  542. ////////////////////////////////////////////////////////////////////////////
  543. // Unit-testing
  544. #ifdef STLSOFT_UNITTEST
  545. # include "./unittest/drophandle_sequence_unittest_.h"
  546. #endif /* STLSOFT_UNITTEST */
  547. /* ////////////////////////////////////////////////////////////////////// */
  548. #ifndef _WINSTL_NO_NAMESPACE
  549. # if defined(_STLSOFT_NO_NAMESPACE) || \
  550. defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
  551. } // namespace winstl
  552. # else
  553. } // namespace winstl_project
  554. } // namespace stlsoft
  555. # endif /* _STLSOFT_NO_NAMESPACE */
  556. #endif /* !_WINSTL_NO_NAMESPACE */
  557. /* ////////////////////////////////////////////////////////////////////// */
  558. #endif /* WINSTL_INCL_WINSTL_SHELL_HPP_DROPHANDLE_SEQUENCE */
  559. /* ///////////////////////////// end of file //////////////////////////// */