📄 listview_sequence.hpp
字号:
/* /////////////////////////////////////////////////////////////////////////
* File: winstl/controls/listview_sequence.hpp
*
* Purpose: Contains the listview_sequence class template.
*
* Created: 8th May 2003
* Updated: 22nd March 2007
*
* Thanks: To Pablo Aguilar for making the requisite feature requests.
*
* Home: http://stlsoft.org/
*
* Copyright (c) 2003-2007, Matthew Wilson and Synesis Software
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* - Neither the name(s) of Matthew Wilson and Synesis Software nor the names of
* any contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* ////////////////////////////////////////////////////////////////////// */
/** \file winstl/controls/listview_sequence.hpp
*
* \brief [C++ only] Definition of the winstl::listview_sequence class
* (\ref group__library__windows_controls "Windows Controls" Library).
*/
#ifndef WINSTL_INCL_WINSTL_CONTROLS_HPP_LISTVIEW_SEQUENCE
#define WINSTL_INCL_WINSTL_CONTROLS_HPP_LISTVIEW_SEQUENCE
#ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
# define WINSTL_VER_WINSTL_CONTROLS_HPP_LISTVIEW_SEQUENCE_MAJOR 4
# define WINSTL_VER_WINSTL_CONTROLS_HPP_LISTVIEW_SEQUENCE_MINOR 1
# define WINSTL_VER_WINSTL_CONTROLS_HPP_LISTVIEW_SEQUENCE_REVISION 1
# define WINSTL_VER_WINSTL_CONTROLS_HPP_LISTVIEW_SEQUENCE_EDIT 70
#endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
/* /////////////////////////////////////////////////////////////////////////
* Compatibility
*/
/*
[Incompatibilies-start]
STLSOFT_COMPILER_IS_BORLAND:
[Incompatibilies-end]
*/
/* /////////////////////////////////////////////////////////////////////////
* Includes
*/
#ifndef WINSTL_INCL_WINSTL_H_WINSTL
# include <winstl/winstl.h>
#endif /* !WINSTL_INCL_WINSTL_H_WINSTL */
#ifndef STLSOFT_INCL_STLSOFT_COLLECTIONS_UTIL_HPP_COLLECTIONS
# include <stlsoft/collections/util/collections.hpp>
#endif /* !STLSOFT_INCL_STLSOFT_COLLECTIONS_UTIL_HPP_COLLECTIONS */
#ifndef STLSOFT_INCL_STLSOFT_MEMORY_HPP_AUTO_BUFFER
# include <stlsoft/memory/auto_buffer.hpp>
#endif /* !STLSOFT_INCL_STLSOFT_MEMORY_HPP_AUTO_BUFFER */
#ifndef WINSTL_INCL_WINSTL_MEMORY_HPP_PROCESSHEAP_ALLOCATOR
# include <winstl/memory/processheap_allocator.hpp>
#endif /* !WINSTL_INCL_WINSTL_MEMORY_HPP_PROCESSHEAP_ALLOCATOR */
#ifndef STLSOFT_INCL_STLSOFT_STRING_HPP_SHIM_STRING
# include <stlsoft/string/shim_string.hpp>
#endif /* !STLSOFT_INCL_STLSOFT_STRING_HPP_SHIM_STRING */
#ifndef STLSOFT_INCL_STLSOFT_STRING_HPP_SIMPLE_STRING
# include <stlsoft/string/simple_string.hpp>
#endif /* !STLSOFT_INCL_STLSOFT_STRING_HPP_SIMPLE_STRING */
#ifndef STLSOFT_INCL_STLSOFT_UTIL_STD_HPP_ITERATOR_HELPER
# include <stlsoft/util/std/iterator_helper.hpp>
#endif /* !STLSOFT_INCL_STLSOFT_UTIL_STD_HPP_ITERATOR_HELPER */
#ifndef WINSTL_INCL_WINSTL_CONTROLS_H_COMMCTRL_FUNCTIONS
# include <winstl/controls/commctrl_functions.h>
#endif /* !WINSTL_INCL_WINSTL_CONTROLS_H_COMMCTRL_FUNCTIONS */
#ifdef STLSOFT_CF_TEMPLATE_CLASS_DEFAULT_CLASS_ARGUMENT_SUPPORT
typedef stlsoft_ns_qual(basic_simple_string)<TCHAR> lvs_string_t;
#else
typedef stlsoft_ns_qual(basic_simple_string)< TCHAR
, stlsoft_ns_qual(stlsoft_char_traits)<TCHAR>
, winstl_ns_qual(processheap_allocator)<TCHAR>
> lvs_string_t;
#endif /* STLSOFT_CF_TEMPLATE_CLASS_DEFAULT_CLASS_ARGUMENT_SUPPORT */
#ifndef WINSTL_INCL_WINSTL_SHIMS_ACCESS_HPP_STRING
# include <winstl/shims/access/string.hpp>
#endif /* !WINSTL_INCL_WINSTL_SHIMS_ACCESS_HPP_STRING */
/* /////////////////////////////////////////////////////////////////////////
* Namespace
*/
#ifndef _WINSTL_NO_NAMESPACE
# if defined(_STLSOFT_NO_NAMESPACE) || \
defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
/* There is no stlsoft namespace, so must define ::winstl */
namespace winstl
{
# else
/* Define stlsoft::winstl_project */
namespace stlsoft
{
namespace winstl_project
{
# endif /* _STLSOFT_NO_NAMESPACE */
#endif /* !_WINSTL_NO_NAMESPACE */
/* /////////////////////////////////////////////////////////////////////////
* Classes
*/
/** \brief Item class used by the listview_sequence class
*
* \ingroup group__library__windows_controls
*/
//template<ss_typename_param_k S = lvs_string_t>
class listview_sequence_item
{
public:
// typedef S string_type;
public:
listview_sequence_item(HWND hwndListView, int iIndex)
: m_hwndListView(hwndListView)
, m_index(iIndex)
{}
public:
lvs_string_t text(int iSubItem = 0) const
{
typedef stlsoft_ns_qual(auto_buffer_old)< TCHAR
, processheap_allocator<TCHAR>
, 256
> buffer_t;
ws_size_t cb = buffer_t::internal_size();
LV_ITEM item;
item.mask = LVIF_TEXT;
item.iItem = m_index;
item.iSubItem = iSubItem;
for(;; cb += buffer_t::internal_size())
{
buffer_t buffer(cb);
item.cchTextMax = static_cast<int>(cb);
item.pszText = &buffer[0];
if(!ListView_GetItem(m_hwndListView, &item))
{
item.cchTextMax = 0;
break;
}
else
{
ss_size_t len = static_cast<ss_size_t>(lstrlen(item.pszText));
if(len + 1 < cb)
{
return lvs_string_t(item.pszText, len);
}
}
}
return lvs_string_t();
}
int index() const
{
return m_index;
}
HWND hwnd() const
{
return m_hwndListView;
}
int image() const;
int selected_image() const;
ws_dword_t data() const
{
LV_ITEM item;
item.mask = LVIF_PARAM;
item.iItem = m_index;
item.iSubItem = 0;
return ListView_GetItem(m_hwndListView, &item) ? static_cast<ws_dword_t>(item.lParam) : 0;
}
/// The item's state
UINT state(UINT mask = 0xffffffff) const
{
return ListView_GetItemState(m_hwndListView, m_index, mask);
}
private:
HWND m_hwndListView;
int m_index;
};
/** \brief Provides an STL-like sequence over the contents of a Windows List-view (<code>"SysListView32"</code>)
*
* \ingroup group__library__windows_controls
*/
class listview_sequence
: public stlsoft_ns_qual(stl_collection_tag)
{
public:
/// The value type
typedef listview_sequence_item sequence_value_type;
typedef sequence_value_type value_type;
/// The size type
typedef ss_size_t size_type;
/// The difference type
typedef ws_ptrdiff_t difference_type;
///
typedef listview_sequence sequence_class_type;
public:
ss_explicit_k listview_sequence(HWND hwndListView)
: m_hwndListView(hwndListView)
{}
public:
/// const_iterator for the listview_sequence
class const_iterator
: public stlsoft_ns_qual(iterator_base)<winstl_ns_qual_std(random_access_iterator_tag)
, sequence_value_type
, ws_ptrdiff_t
, void // By-Value Temporary reference
, sequence_value_type // By-Value Temporary reference
>
{
typedef const_iterator class_type;
public:
typedef sequence_value_type value_type;
public:
const_iterator()
: m_hwndListView(NULL)
, m_index(-1)
{}
const_iterator(HWND hwndListView, int iIndex)
: m_hwndListView(hwndListView)
, m_index(iIndex)
{}
const_iterator(class_type const& rhs)
: m_hwndListView(rhs.m_hwndListView)
, m_index(rhs.m_index)
{}
class_type& operator =(class_type const& rhs)
{
m_hwndListView = rhs.m_hwndListView;
m_index = rhs.m_index;
return *this;
}
public:
value_type operator *() const
{
return value_type(m_hwndListView, m_index);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -