Bug Summary

File:rootdir/src/extern/wxWidgets/listctrl.cpp
Warning:line 498, column 43
Called C++ object pointer is null

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name listctrl.cpp -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=all -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/rootdir/src -fcoverage-compilation-dir=/rootdir/src -resource-dir /usr/lib/llvm-19/lib/clang/19 -D HAVE_CONFIG_H -I . -I .. -D USE_WX_EXTENSIONS -I /usr/lib/x86_64-linux-gnu/wx/include/gtk3-unicode-3.2 -I /usr/include/wx-3.2 -D _FILE_OFFSET_BITS=64 -D WXUSINGDLL -D __WXGTK__ -I ./libs -I ./include -I /usr/include/upnp -D ENABLE_UPNP=1 -D ENABLE_IP2COUNTRY=1 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/14/../../../../include/c++/14 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/14/../../../../include/x86_64-linux-gnu/c++/14 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/14/../../../../include/c++/14/backward -internal-isystem /usr/lib/llvm-19/lib/clang/19/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/14/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -Wno-register -fdeprecated-macro -ferror-limit 19 -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fcxx-exceptions -fexceptions -analyzer-checker deadcode.DeadStores -analyzer-checker alpha.deadcode.UnreachableCode -analyzer-checker alpha.core.CastSize -analyzer-checker alpha.core.CastToStruct -analyzer-checker alpha.core.IdenticalExpr -analyzer-checker alpha.security.ArrayBoundV2 -analyzer-checker alpha.security.MallocOverflow -analyzer-checker alpha.security.ReturnPtrRange -analyzer-checker alpha.unix.SimpleStream -analyzer-checker alpha.unix.cstring.BufferOverlap -analyzer-checker alpha.unix.cstring.NotNullTerminated -analyzer-checker alpha.unix.cstring.OutOfBounds -analyzer-checker alpha.core.FixedAddr -analyzer-output=html -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /rootdir/html-report/2025-01-14-161821-17216-1 -x c++ extern/wxWidgets/listctrl.cpp
1/////////////////////////////////////////////////////////////////////////////
2// Name: src/generic/listctrl.cpp
3// Purpose: generic implementation of wxListCtrl
4// Author: Robert Roebling
5// Vadim Zeitlin (virtual list control support)
6// Id: $Id$
7// Copyright: Copyright (c) 1998-2011 Robert Roebling
8// Licence: wxWindows licence
9/////////////////////////////////////////////////////////////////////////////
10
11// TODO
12//
13// 1. we need to implement searching/sorting for virtual controls somehow
14// 2. when changing selection the lines are refreshed twice
15
16
17// For compilers that support precompilation, includes "wx.h".
18#include <wx/wxprec.h>
19
20#ifdef __BORLANDC__
21 #pragma hdrstop
22#endif
23
24#if wxUSE_LISTCTRL1
25
26#include "listctrl.h"
27
28#ifndef WX_PRECOMP
29 #include <wx/scrolwin.h>
30 #include <wx/timer.h>
31 #include <wx/settings.h>
32 #include <wx/dynarray.h>
33 #include <wx/dcclient.h>
34 #include <wx/dcscreen.h>
35 #include <wx/math.h>
36#endif
37
38#include <wx/imaglist.h>
39#include <wx/selstore.h>
40#include <wx/renderer.h>
41#include <wx/dcbuffer.h>
42
43
44// NOTE: If using the wxListBox visual attributes works everywhere then this can
45// be removed, as well as the #else case below.
46#define _USE_VISATTR0 0
47
48namespace MuleExtern {
49
50// ----------------------------------------------------------------------------
51// constants
52// ----------------------------------------------------------------------------
53
54// // the height of the header window (FIXME: should depend on its font!)
55// static const int HEADER_HEIGHT = 23;
56
57static const int SCROLL_UNIT_X = 15;
58
59// the spacing between the lines (in report mode)
60static const int LINE_SPACING = 0;
61
62// extra margins around the text label
63#ifdef __WXGTK__1
64static const int EXTRA_WIDTH = 6;
65#else
66static const int EXTRA_WIDTH = 4;
67#endif
68static const int EXTRA_HEIGHT = 4;
69
70// margin between the window and the items
71static const int EXTRA_BORDER_X = 2;
72static const int EXTRA_BORDER_Y = 2;
73
74// offset for the header window
75static const int HEADER_OFFSET_X = 0;
76static const int HEADER_OFFSET_Y = 0;
77
78// margin between rows of icons in [small] icon view
79static const int MARGIN_BETWEEN_ROWS = 6;
80
81// when autosizing the columns, add some slack
82static const int AUTOSIZE_COL_MARGIN = 10;
83
84// default width for the header columns
85static const int WIDTH_COL_DEFAULT = 80;
86
87// the space between the image and the text in the report mode
88static const int IMAGE_MARGIN_IN_REPORT_MODE = 5;
89
90// the space between the image and the text in the report mode in header
91static const int HEADER_IMAGE_MARGIN_IN_REPORT_MODE = 2;
92
93const wxChar wxListCtrlNameStr[] = wxT("listCtrl")L"listCtrl";
94
95// ============================================================================
96// private classes
97// ============================================================================
98
99//-----------------------------------------------------------------------------
100// wxColWidthInfo (internal)
101//-----------------------------------------------------------------------------
102
103struct wxColWidthInfo
104{
105 int nMaxWidth;
106 bool bNeedsUpdate; // only set to true when an item whose
107 // width == nMaxWidth is removed
108
109 wxColWidthInfo(int w = 0, bool needsUpdate = false)
110 {
111 nMaxWidth = w;
112 bNeedsUpdate = needsUpdate;
113 }
114};
115
116WX_DEFINE_ARRAY_PTR(wxColWidthInfo *, ColWidthArray)typedef wxBaseArray<wxColWidthInfo *> wxBaseArrayForColWidthArray
; class ColWidthArray : public wxBaseArrayForColWidthArray { typedef
wxBaseArrayForColWidthArray Base; public: ColWidthArray() : Base
() { } explicit ColWidthArray(size_t n) : Base(n) { } ColWidthArray
(size_t n, Base::const_reference v) : Base(n, v) { } template
<class InputIterator> ColWidthArray(InputIterator first
, InputIterator last) : Base(first, last) { } template<typename
U> ColWidthArray(std::initializer_list<U> list) : Base
(list.begin(), list.end()) { } }
;
117
118//-----------------------------------------------------------------------------
119// wxListItemData (internal)
120//-----------------------------------------------------------------------------
121
122class wxListItemData
123{
124public:
125 wxListItemData(wxListMainWindow *owner);
126 ~wxListItemData();
127
128 void SetItem( const wxListItem &info );
129 void SetImage( int image ) { m_image = image; }
130 void SetData( wxUIntPtr data ) { m_data = data; }
131 void SetPosition( int x, int y );
132 void SetSize( int width, int height );
133
134 bool HasText() const { return !m_text.empty(); }
135 const wxString& GetText() const { return m_text; }
136 void SetText(const wxString& text) { m_text = text; }
137
138 // we can't use empty string for measuring the string width/height, so
139 // always return something
140 wxString GetTextForMeasuring() const
141 {
142 wxString s = GetText();
143 if ( s.empty() )
144 s = _T('H')L'H';
145
146 return s;
147 }
148
149 bool IsHit( int x, int y ) const;
150
151 int GetX() const;
152 int GetY() const;
153 int GetWidth() const;
154 int GetHeight() const;
155
156 int GetImage() const { return m_image; }
157 bool HasImage() const { return GetImage() != -1; }
158
159 void GetItem( wxListItem &info ) const;
160
161 void SetAttr(wxListItemAttr *attr) { m_attr = attr; }
162 wxListItemAttr *GetAttr() const { return m_attr; }
163
164public:
165 // the item image or -1
166 int m_image;
167
168 // user data associated with the item
169 wxUIntPtr m_data;
170
171 // the item coordinates are not used in report mode; instead this pointer is
172 // NULL and the owner window is used to retrieve the item position and size
173 wxRect *m_rect;
174
175 // the list ctrl we are in
176 wxListMainWindow *m_owner;
177
178 // custom attributes or NULL
179 wxListItemAttr *m_attr;
180
181protected:
182 // common part of all ctors
183 void Init();
184
185 wxString m_text;
186};
187
188//-----------------------------------------------------------------------------
189// wxListHeaderData (internal)
190//-----------------------------------------------------------------------------
191
192class wxListHeaderData : public wxObject
193{
194public:
195 wxListHeaderData();
196 wxListHeaderData( const wxListItem &info );
197 void SetItem( const wxListItem &item );
198 void SetPosition( int x, int y );
199 void SetWidth( int w );
200 void SetState( int state );
201 void SetFormat( int format );
202 void SetHeight( int h );
203 bool HasImage() const;
204
205 bool HasText() const { return !m_text.empty(); }
206 const wxString& GetText() const { return m_text; }
207 void SetText(const wxString& text) { m_text = text; }
208
209 void GetItem( wxListItem &item );
210
211 bool IsHit( int x, int y ) const;
212 int GetImage() const;
213 int GetWidth() const;
214 int GetFormat() const;
215 int GetState() const;
216
217protected:
218 long m_mask;
219 int m_image;
220 wxString m_text;
221 int m_format;
222 int m_width;
223 int m_xpos,
224 m_ypos;
225 int m_height;
226 int m_state;
227
228private:
229 void Init();
230};
231
232//-----------------------------------------------------------------------------
233// wxListLineData (internal)
234//-----------------------------------------------------------------------------
235
236WX_DECLARE_LIST(wxListItemData, wxListItemDataList)typedef wxListItemData _WX_LIST_ITEM_TYPE_wxListItemDataList;
typedef int (*wxSortFuncFor_wxListItemDataList)(const wxListItemData
**, const wxListItemData **); class wxwxListItemDataListNode
: public wxNodeBase { public: wxwxListItemDataListNode(wxListBase
*list = __null, wxwxListItemDataListNode *previous = __null,
wxwxListItemDataListNode *next = __null, wxListItemData *data
= __null, const wxListKey& key = wxDefaultListKey) : wxNodeBase
(list, previous, next, data, key) { } wxwxListItemDataListNode
*GetNext() const { return (wxwxListItemDataListNode *)wxNodeBase
::GetNext(); } wxwxListItemDataListNode *GetPrevious() const {
return (wxwxListItemDataListNode *)wxNodeBase::GetPrevious()
; } wxListItemData *GetData() const { return (wxListItemData *
)wxNodeBase::GetData(); } void SetData(wxListItemData *data) {
wxNodeBase::SetData(data); } protected: virtual void DeleteData
() override; private: wxwxListItemDataListNode(const wxwxListItemDataListNode
&) = delete; wxwxListItemDataListNode& operator=(const
wxwxListItemDataListNode&) = delete; }; class wxListItemDataList
: public wxListBase { public: typedef wxwxListItemDataListNode
Node; class compatibility_iterator { public: compatibility_iterator
(Node *ptr = __null) : m_ptr(ptr) { } Node *operator->() const
{ return m_ptr; } operator Node *() const { return m_ptr; } private
: Node *m_ptr; }; wxListItemDataList(wxKeyType keyType = wxKEY_NONE
) : wxListBase(keyType) { } wxListItemDataList(const wxListItemDataList
& list) : wxListBase(list.GetKeyType()) { Assign(list); }
wxListItemDataList& operator=(const wxListItemDataList&
list) { if (&list != this) Assign(list); return *this; }
wxwxListItemDataListNode *GetFirst() const { return (wxwxListItemDataListNode
*)wxListBase::GetFirst(); } wxwxListItemDataListNode *GetLast
() const { return (wxwxListItemDataListNode *)wxListBase::GetLast
(); } wxwxListItemDataListNode *Item(size_t index) const { return
(wxwxListItemDataListNode *)wxListBase::Item(index); } wxListItemData
*operator[](size_t index) const { wxwxListItemDataListNode *
node = Item(index); return node ? (wxListItemData*)(node->
GetData()) : __null; } wxwxListItemDataListNode *Append(wxListItemData
*object) { return (wxwxListItemDataListNode *)wxListBase::Append
(object); } wxwxListItemDataListNode *Insert(wxListItemData *
object) { return (wxwxListItemDataListNode *)Insert(static_cast
<wxwxListItemDataListNode *>(__null), object); } wxwxListItemDataListNode
*Insert(size_t pos, wxListItemData *object) { return (wxwxListItemDataListNode
*)wxListBase::Insert(pos, object); } wxwxListItemDataListNode
*Insert(wxwxListItemDataListNode *prev, wxListItemData *object
) { return (wxwxListItemDataListNode *)wxListBase::Insert(prev
, object); } wxwxListItemDataListNode *Append(long key, void *
object) { return (wxwxListItemDataListNode *)wxListBase::Append
(key, object); } wxwxListItemDataListNode *Append(const wxChar
*key, void *object) { return (wxwxListItemDataListNode *)wxListBase
::Append(key, object); } wxwxListItemDataListNode *DetachNode
(wxwxListItemDataListNode *node) { return (wxwxListItemDataListNode
*)wxListBase::DetachNode(node); } bool DeleteNode(wxwxListItemDataListNode
*node) { return wxListBase::DeleteNode(node); } bool DeleteObject
(wxListItemData *object) { return wxListBase::DeleteObject(object
); } void Erase(wxwxListItemDataListNode *it) { DeleteNode(it
); } wxwxListItemDataListNode *Find(const wxListItemData *object
) const { return (wxwxListItemDataListNode *)wxListBase::Find
(object); } virtual wxwxListItemDataListNode *Find(const wxListKey
& key) const { return (wxwxListItemDataListNode *)wxListBase
::Find(key); } bool Member(const wxListItemData *object) const
{ return Find(object) != __null; } int IndexOf(wxListItemData
*object) const { return wxListBase::IndexOf(object); } void Sort
(wxSortCompareFunction func) { wxListBase::Sort(func); } void
Sort(wxSortFuncFor_wxListItemDataList func) { Sort((wxSortCompareFunction
)func); } protected: virtual wxNodeBase *CreateNode(wxNodeBase
*prev, wxNodeBase *next, void *data, const wxListKey& key
= wxDefaultListKey) override { return new wxwxListItemDataListNode
(this, (wxwxListItemDataListNode *)prev, (wxwxListItemDataListNode
*)next, (wxListItemData *)data, key); } public: typedef size_t
size_type; typedef int difference_type; typedef wxListItemData
* value_type; typedef wxListItemData* base_value_type; typedef
value_type& reference; typedef const value_type& const_reference
; typedef base_value_type& base_reference; typedef const base_value_type
& const_base_reference; class iterator { public: typedef std
::ptrdiff_t difference_type; typedef std::bidirectional_iterator_tag
iterator_category; typedef wxListItemData* value_type; typedef
value_type* pointer; typedef value_type& reference; typedef
wxwxListItemDataListNode Node; typedef iterator itor; Node* m_node
; Node* m_init; public: typedef reference reference_type; typedef
pointer pointer_type; iterator(Node* node, Node* init) : m_node
(node), m_init(init) {} iterator() : m_node(__null), m_init(__null
) { } reference_type operator*() const { return *(pointer_type
)m_node->GetDataPtr(); } itor& operator++() { do { if (
m_node ) { } else if ( wxTheAssertHandler && (wxOnAssert
("extern/wxWidgets/listctrl.cpp", 236, __FUNCTION__, "m_node"
, L"uninitialized iterator"), wxTrapInAssert) ) { wxTrapInAssert
= false; asm volatile ("int $3"); } } while ( (void)0, 0 ); m_node
= m_node->GetNext(); return *this; } const itor operator++
(int) { itor tmp = *this; do { if ( m_node ) { } else if ( wxTheAssertHandler
&& (wxOnAssert("extern/wxWidgets/listctrl.cpp", 236,
__FUNCTION__, "m_node", L"uninitialized iterator"), wxTrapInAssert
) ) { wxTrapInAssert = false; asm volatile ("int $3"); } } while
( (void)0, 0 ); m_node = m_node->GetNext(); return tmp; }
itor& operator--() { m_node = m_node ? m_node->GetPrevious
() : m_init; return *this; } const itor operator--(int) { itor
tmp = *this; m_node = m_node ? m_node->GetPrevious() : m_init
; return tmp; } bool operator!=(const itor& it) const { return
it.m_node != m_node; } bool operator==(const itor& it) const
{ return it.m_node == m_node; } }; class const_iterator { public
: typedef std::ptrdiff_t difference_type; typedef std::bidirectional_iterator_tag
iterator_category; typedef wxListItemData* value_type; typedef
const value_type* pointer; typedef const value_type& reference
; typedef wxwxListItemDataListNode Node; typedef const_iterator
itor; Node* m_node; Node* m_init; public: typedef reference reference_type
; typedef pointer pointer_type; const_iterator(Node* node, Node
* init) : m_node(node), m_init(init) { } const_iterator() : m_node
(__null), m_init(__null) { } const_iterator(const iterator&
it) : m_node(it.m_node), m_init(it.m_init) { } reference_type
operator*() const { return *(pointer_type)m_node->GetDataPtr
(); } itor& operator++() { do { if ( m_node ) { } else if
( wxTheAssertHandler && (wxOnAssert("extern/wxWidgets/listctrl.cpp"
, 236, __FUNCTION__, "m_node", L"uninitialized iterator"), wxTrapInAssert
) ) { wxTrapInAssert = false; asm volatile ("int $3"); } } while
( (void)0, 0 ); m_node = m_node->GetNext(); return *this;
} const itor operator++(int) { itor tmp = *this; do { if ( m_node
) { } else if ( wxTheAssertHandler && (wxOnAssert("extern/wxWidgets/listctrl.cpp"
, 236, __FUNCTION__, "m_node", L"uninitialized iterator"), wxTrapInAssert
) ) { wxTrapInAssert = false; asm volatile ("int $3"); } } while
( (void)0, 0 ); m_node = m_node->GetNext(); return tmp; }
itor& operator--() { m_node = m_node ? m_node->GetPrevious
() : m_init; return *this; } const itor operator--(int) { itor
tmp = *this; m_node = m_node ? m_node->GetPrevious() : m_init
; return tmp; } bool operator!=(const itor& it) const { return
it.m_node != m_node; } bool operator==(const itor& it) const
{ return it.m_node == m_node; } }; class reverse_iterator { public
: typedef std::ptrdiff_t difference_type; typedef std::bidirectional_iterator_tag
iterator_category; typedef wxListItemData* value_type; typedef
value_type* pointer; typedef value_type& reference; typedef
wxwxListItemDataListNode Node; typedef reverse_iterator itor
; Node* m_node; Node* m_init; public: typedef reference reference_type
; typedef pointer pointer_type; reverse_iterator(Node* node, Node
* init) : m_node(node), m_init(init) { } reverse_iterator() :
m_node(__null), m_init(__null) { } reference_type operator*(
) const { return *(pointer_type)m_node->GetDataPtr(); } itor
& operator++() { m_node = m_node->GetPrevious(); return
*this; } const itor operator++(int) { itor tmp = *this; m_node
= m_node->GetPrevious(); return tmp; } itor& operator
--() { m_node = m_node ? m_node->GetNext() : m_init; return
*this; } const itor operator--(int) { itor tmp = *this; m_node
= m_node ? m_node->GetNext() : m_init; return tmp; } bool
operator!=(const itor& it) const { return it.m_node != m_node
; } bool operator==(const itor& it) const { return it.m_node
== m_node; } }; class const_reverse_iterator { public: typedef
std::ptrdiff_t difference_type; typedef std::bidirectional_iterator_tag
iterator_category; typedef wxListItemData* value_type; typedef
const value_type* pointer; typedef const value_type& reference
; typedef wxwxListItemDataListNode Node; typedef const_reverse_iterator
itor; Node* m_node; Node* m_init; public: typedef reference reference_type
; typedef pointer pointer_type; const_reverse_iterator(Node* node
, Node* init) : m_node(node), m_init(init) { } const_reverse_iterator
() : m_node(__null), m_init(__null) { } const_reverse_iterator
(const reverse_iterator& it) : m_node(it.m_node), m_init(
it.m_init) { } reference_type operator*() const { return *(pointer_type
)m_node->GetDataPtr(); } itor& operator++() { m_node =
m_node->GetPrevious(); return *this; } const itor operator
++(int) { itor tmp = *this; m_node = m_node->GetPrevious()
; return tmp; } itor& operator--() { m_node = m_node ? m_node
->GetNext() : m_init; return *this;} const itor operator--
(int) { itor tmp = *this; m_node = m_node ? m_node->GetNext
() : m_init; return tmp; } bool operator!=(const itor& it
) const { return it.m_node != m_node; } bool operator==(const
itor& it) const { return it.m_node == m_node; } }; explicit
wxListItemDataList(size_type n, const_reference v = value_type
()) { assign(n, v); } wxListItemDataList(const const_iterator
& first, const const_iterator& last) { assign(first, last
); } iterator begin() { return iterator(GetFirst(), GetLast()
); } const_iterator begin() const { return const_iterator(GetFirst
(), GetLast()); } iterator end() { return iterator(__null, GetLast
()); } const_iterator end() const { return const_iterator(__null
, GetLast()); } reverse_iterator rbegin() { return reverse_iterator
(GetLast(), GetFirst()); } const_reverse_iterator rbegin() const
{ return const_reverse_iterator(GetLast(), GetFirst()); } reverse_iterator
rend() { return reverse_iterator(__null, GetFirst()); } const_reverse_iterator
rend() const { return const_reverse_iterator(__null, GetFirst
()); } void resize(size_type n, value_type v = value_type()) {
while (n < size()) pop_back(); while (n > size()) push_back
(v); } size_type size() const { return GetCount(); } size_type
max_size() const { return 2147483647; } bool empty() const {
return IsEmpty(); } reference front() { return *begin(); } const_reference
front() const { return *begin(); } reference back() { iterator
tmp = end(); return *--tmp; } const_reference back() const {
const_iterator tmp = end(); return *--tmp; } void push_front
(const_reference v = value_type()) { Insert(GetFirst(), (const_base_reference
)v); } void pop_front() { DeleteNode(GetFirst()); } void push_back
(const_reference v = value_type()) { Append((const_base_reference
)v); } void pop_back() { DeleteNode(GetLast()); } void assign
(const_iterator first, const const_iterator& last) { clear
(); for(; first != last; ++first) Append((const_base_reference
)*first); } void assign(size_type n, const_reference v = value_type
()) { clear(); for(size_type i = 0; i < n; ++i) Append((const_base_reference
)v); } iterator insert(const iterator& it, const_reference
v) { if ( it == end() ) { Append((const_base_reference)v); iterator
itins(end()); return --itins; } else { Insert(it.m_node, (const_base_reference
)v); iterator itins(it); return --itins; } } void insert(const
iterator& it, size_type n, const_reference v) { for(size_type
i = 0; i < n; ++i) insert(it, v); } void insert(const iterator
& it, const_iterator first, const const_iterator& last
) { for(; first != last; ++first) insert(it, *first); } iterator
erase(const iterator& it) { iterator next = iterator(it.
m_node->GetNext(), GetLast()); DeleteNode(it.m_node); return
next; } iterator erase(const iterator& first, const iterator
& last) { iterator next = last; if ( next != end() ) ++next
; DeleteNodes(first.m_node, last.m_node); return next; } void
clear() { Clear(); } void splice(const iterator& it, wxListItemDataList
& l, const iterator& first, const iterator& last)
{ insert(it, first, last); l.erase(first, last); } void splice
(const iterator& it, wxListItemDataList& l) { splice(
it, l, l.begin(), l.end() ); } void splice(const iterator&
it, wxListItemDataList& l, const iterator& first) { if
( it != first ) { insert(it, *first); l.erase(first); } } void
remove(const_reference v) { DeleteObject((const_base_reference
)v); } void reverse() { Reverse(); } }
;
237#include <wx/listimpl.cpp>
238WX_DEFINE_LIST(wxListItemDataList)void wxwxListItemDataListNode::DeleteData() { delete (_WX_LIST_ITEM_TYPE_wxListItemDataList
*)GetData(); }
239
240class wxListLineData
241{
242public:
243 // the list of subitems: only may have more than one item in report mode
244 wxListItemDataList m_items;
245
246 // this is not used in report view
247 struct GeometryInfo
248 {
249 // total item rect
250 wxRect m_rectAll;
251
252 // label only
253 wxRect m_rectLabel;
254
255 // icon only
256 wxRect m_rectIcon;
257
258 // the part to be highlighted
259 wxRect m_rectHighlight;
260
261 // extend all our rects to be centered inside the one of given width
262 void ExtendWidth(wxCoord w)
263 {
264 wxASSERT_MSG( m_rectAll.width <= w,do { if ( m_rectAll.width <= w ) { } else if ( wxTheAssertHandler
&& (wxOnAssert("extern/wxWidgets/listctrl.cpp", 265,
__FUNCTION__, "m_rectAll.width <= w", L"width can only be increased"
), wxTrapInAssert) ) { wxTrapInAssert = false; asm volatile (
"int $3"); } } while ( (void)0, 0 )
265 _T("width can only be increased") )do { if ( m_rectAll.width <= w ) { } else if ( wxTheAssertHandler
&& (wxOnAssert("extern/wxWidgets/listctrl.cpp", 265,
__FUNCTION__, "m_rectAll.width <= w", L"width can only be increased"
), wxTrapInAssert) ) { wxTrapInAssert = false; asm volatile (
"int $3"); } } while ( (void)0, 0 )
;
266
267 m_rectAll.width = w;
268 m_rectLabel.x = m_rectAll.x + (w - m_rectLabel.width) / 2;
269 m_rectIcon.x = m_rectAll.x + (w - m_rectIcon.width) / 2;
270 m_rectHighlight.x = m_rectAll.x + (w - m_rectHighlight.width) / 2;
271 }
272 }
273 *m_gi;
274
275 // is this item selected? [NB: not used in virtual mode]
276 bool m_highlighted;
277
278 // back pointer to the list ctrl
279 wxListMainWindow *m_owner;
280
281public:
282 wxListLineData(wxListMainWindow *owner);
283
284 ~wxListLineData()
285 {
286 WX_CLEAR_LIST(wxListItemDataList, m_items){ wxListItemDataList::iterator it, en; for( it = (m_items).begin
(), en = (m_items).end(); it != en; ++it ) delete *it; (m_items
).clear(); }
;
287 delete m_gi;
288 }
289
290 // are we in report mode?
291 inline bool InReportView() const;
292
293 // are we in virtual report mode?
294 inline bool IsVirtual() const;
295
296 // these 2 methods shouldn't be called for report view controls, in that
297 // case we determine our position/size ourselves
298
299 // calculate the size of the line
300 void CalculateSize( wxDC *dc, int spacing );
301
302 // remember the position this line appears at
303 void SetPosition( int x, int y, int spacing );
304
305 // wxListCtrl API
306
307 void SetImage( int image ) { SetImage(0, image); }
308 int GetImage() const { return GetImage(0); }
309 void SetImage( int index, int image );
310 int GetImage( int index ) const;
311
312 bool HasImage() const { return GetImage() != -1; }
313 bool HasText() const { return !GetText(0).empty(); }
314
315 void SetItem( int index, const wxListItem &info );
316 void GetItem( int index, wxListItem &info );
317
318 wxString GetText(int index) const;
319 void SetText( int index, const wxString& s );
320
321 wxListItemAttr *GetAttr() const;
322 void SetAttr(wxListItemAttr *attr);
323
324 // return true if the highlighting really changed
325 bool Highlight( bool on );
326
327 void ReverseHighlight();
328
329 bool IsHighlighted() const
330 {
331 wxASSERT_MSG( !IsVirtual(), _T("unexpected call to IsHighlighted") )do { if ( !IsVirtual() ) { } else if ( wxTheAssertHandler &&
(wxOnAssert("extern/wxWidgets/listctrl.cpp", 331, __FUNCTION__
, "!IsVirtual()", L"unexpected call to IsHighlighted"), wxTrapInAssert
) ) { wxTrapInAssert = false; asm volatile ("int $3"); } } while
( (void)0, 0 )
;
332
333 return m_highlighted;
334 }
335
336 // draw the line on the given DC in icon/list mode
337 void Draw( wxDC *dc );
338
339 // the same in report mode
340 void DrawInReportMode( wxDC *dc,
341 const wxRect& rect,
342 const wxRect& rectHL,
343 bool highlighted );
344
345private:
346 // set the line to contain num items (only can be > 1 in report mode)
347 void InitItems( int num );
348
349 // get the mode (i.e. style) of the list control
350 inline int GetMode() const;
351
352 // prepare the DC for drawing with these item's attributes, return true if
353 // we need to draw the items background to highlight it, false otherwise
354 bool SetAttributes(wxDC *dc,
355 const wxListItemAttr *attr,
356 bool highlight);
357
358 // draw the text on the DC with the correct justification; also add an
359 // ellipsis if the text is too large to fit in the current width
360 void DrawTextFormatted(wxDC *dc,
361 const wxString &text,
362 int col,
363 int x,
364 int yMid, // this is middle, not top, of the text
365 int width);
366};
367
368WX_DECLARE_OBJARRAY(wxListLineData, wxListLineDataArray)class wxObjectArrayTraitsForwxListLineDataArray { public: static
wxListLineData* Clone(wxListLineData const& item); static
void Free(wxListLineData* p); }; typedef wxBaseObjectArray<
wxListLineData, wxObjectArrayTraitsForwxListLineDataArray>
wxBaseObjectArrayForwxListLineDataArray; class wxListLineDataArray
: public wxBaseObjectArrayForwxListLineDataArray { }
;
369#include <wx/arrimpl.cpp>
370WX_DEFINE_OBJARRAY(wxListLineDataArray)wxListLineDataArray::value_type* wxObjectArrayTraitsForwxListLineDataArray
::Clone(const wxListLineDataArray::value_type& item) { return
new wxListLineDataArray::value_type(item); } void wxObjectArrayTraitsForwxListLineDataArray
::Free(wxListLineDataArray::value_type* p) { delete p; }
371
372//-----------------------------------------------------------------------------
373// wxListHeaderWindow (internal)
374//-----------------------------------------------------------------------------
375
376class wxListHeaderWindow : public wxWindow
377{
378protected:
379 wxListMainWindow *m_owner;
380 const wxCursor *m_currentCursor;
381 wxCursor *m_resizeCursor;
382 bool m_isDragging;
383
384 // column being resized or -1
385 int m_column;
386
387 // divider line position in logical (unscrolled) coords
388 int m_currentX;
389
390 // minimal position beyond which the divider line
391 // can't be dragged in logical coords
392 int m_minX;
393
394public:
395 wxListHeaderWindow();
396
397 wxListHeaderWindow( wxWindow *win,
398 wxWindowID id,
399 wxListMainWindow *owner,
400 const wxPoint &pos = wxDefaultPosition,
401 const wxSize &size = wxDefaultSize,
402 long style = 0,
403 const wxString &name = wxT("wxlistctrlcolumntitles")L"wxlistctrlcolumntitles" );
404
405 virtual ~wxListHeaderWindow();
406
407 void DrawCurrent();
408 void AdjustDC( wxDC& dc );
409
410 void OnPaint( wxPaintEvent &event );
411 void OnMouse( wxMouseEvent &event );
412 void OnSetFocus( wxFocusEvent &event );
413
414 // needs refresh
415 bool m_dirty;
416
417private:
418 // common part of all ctors
419 void Init();
420
421 // generate and process the list event of the given type, return true if
422 // it wasn't vetoed, i.e. if we should proceed
423 bool SendListEvent(wxEventType type, const wxPoint& pos);
424
425 DECLARE_EVENT_TABLE()private: static const wxEventTableEntry sm_eventTableEntries[
]; protected: GCC diagnostic push GCC diagnostic ignored "-Wsuggest-override"
GCC diagnostic push GCC diagnostic ignored "-Winconsistent-missing-override"
const wxEventTable* GetEventTable() const ; wxEventHashTable
& GetEventHashTable() const ; GCC diagnostic pop GCC diagnostic
pop static const wxEventTable sm_eventTable; static wxEventHashTable
sm_eventHashTable;
426};
427
428//-----------------------------------------------------------------------------
429// wxListRenameTimer (internal)
430//-----------------------------------------------------------------------------
431
432class wxListRenameTimer: public wxTimer
433{
434private:
435 wxListMainWindow *m_owner;
436
437public:
438 wxListRenameTimer( wxListMainWindow *owner );
439 void Notify();
440};
441
442//-----------------------------------------------------------------------------
443// wxListTextCtrlWrapper: wraps a wxTextCtrl to make it work for inline editing
444//-----------------------------------------------------------------------------
445
446class wxListTextCtrlWrapper : public wxEvtHandler
447{
448public:
449 // NB: text must be a valid object but not Create()d yet
450 wxListTextCtrlWrapper(wxListMainWindow *owner,
451 wxTextCtrl *text,
452 size_t itemEdit);
453
454 wxTextCtrl *GetText() const { return m_text; }
455
456 void AcceptChangesAndFinish();
457
458protected:
459 void OnChar( wxKeyEvent &event );
460 void OnKeyUp( wxKeyEvent &event );
461 void OnKillFocus( wxFocusEvent &event );
462
463 bool AcceptChanges();
464 void Finish();
465
466private:
467 wxListMainWindow *m_owner;
468 wxTextCtrl *m_text;
469 wxString m_startValue;
470 size_t m_itemEdited;
471 bool m_finished;
472 bool m_aboutToFinish;
473
474 DECLARE_EVENT_TABLE()private: static const wxEventTableEntry sm_eventTableEntries[
]; protected: GCC diagnostic push GCC diagnostic ignored "-Wsuggest-override"
GCC diagnostic push GCC diagnostic ignored "-Winconsistent-missing-override"
const wxEventTable* GetEventTable() const ; wxEventHashTable
& GetEventHashTable() const ; GCC diagnostic pop GCC diagnostic
pop static const wxEventTable sm_eventTable; static wxEventHashTable
sm_eventHashTable;
475};
476
477//-----------------------------------------------------------------------------
478// wxListMainWindow (internal)
479//-----------------------------------------------------------------------------
480
481WX_DECLARE_LIST(wxListHeaderData, wxListHeaderDataList)typedef wxListHeaderData _WX_LIST_ITEM_TYPE_wxListHeaderDataList
; typedef int (*wxSortFuncFor_wxListHeaderDataList)(const wxListHeaderData
**, const wxListHeaderData **); class wxwxListHeaderDataListNode
: public wxNodeBase { public: wxwxListHeaderDataListNode(wxListBase
*list = __null, wxwxListHeaderDataListNode *previous = __null
, wxwxListHeaderDataListNode *next = __null, wxListHeaderData
*data = __null, const wxListKey& key = wxDefaultListKey)
: wxNodeBase(list, previous, next, data, key) { } wxwxListHeaderDataListNode
*GetNext() const { return (wxwxListHeaderDataListNode *)wxNodeBase
::GetNext(); } wxwxListHeaderDataListNode *GetPrevious() const
{ return (wxwxListHeaderDataListNode *)wxNodeBase::GetPrevious
(); } wxListHeaderData *GetData() const { return (wxListHeaderData
*)wxNodeBase::GetData(); } void SetData(wxListHeaderData *data
) { wxNodeBase::SetData(data); } protected: virtual void DeleteData
() override; private: wxwxListHeaderDataListNode(const wxwxListHeaderDataListNode
&) = delete; wxwxListHeaderDataListNode& operator=(const
wxwxListHeaderDataListNode&) = delete; }; class wxListHeaderDataList
: public wxListBase { public: typedef wxwxListHeaderDataListNode
Node; class compatibility_iterator { public: compatibility_iterator
(Node *ptr = __null) : m_ptr(ptr) { } Node *operator->() const
{ return m_ptr; } operator Node *() const { return m_ptr; } private
: Node *m_ptr; }; wxListHeaderDataList(wxKeyType keyType = wxKEY_NONE
) : wxListBase(keyType) { } wxListHeaderDataList(const wxListHeaderDataList
& list) : wxListBase(list.GetKeyType()) { Assign(list); }
wxListHeaderDataList& operator=(const wxListHeaderDataList
& list) { if (&list != this) Assign(list); return *this
; } wxwxListHeaderDataListNode *GetFirst() const { return (wxwxListHeaderDataListNode
*)wxListBase::GetFirst(); } wxwxListHeaderDataListNode *GetLast
() const { return (wxwxListHeaderDataListNode *)wxListBase::GetLast
(); } wxwxListHeaderDataListNode *Item(size_t index) const { return
(wxwxListHeaderDataListNode *)wxListBase::Item(index); } wxListHeaderData
*operator[](size_t index) const { wxwxListHeaderDataListNode
*node = Item(index); return node ? (wxListHeaderData*)(node->
GetData()) : __null; } wxwxListHeaderDataListNode *Append(wxListHeaderData
*object) { return (wxwxListHeaderDataListNode *)wxListBase::
Append(object); } wxwxListHeaderDataListNode *Insert(wxListHeaderData
*object) { return (wxwxListHeaderDataListNode *)Insert(static_cast
<wxwxListHeaderDataListNode *>(__null), object); } wxwxListHeaderDataListNode
*Insert(size_t pos, wxListHeaderData *object) { return (wxwxListHeaderDataListNode
*)wxListBase::Insert(pos, object); } wxwxListHeaderDataListNode
*Insert(wxwxListHeaderDataListNode *prev, wxListHeaderData *
object) { return (wxwxListHeaderDataListNode *)wxListBase::Insert
(prev, object); } wxwxListHeaderDataListNode *Append(long key
, void *object) { return (wxwxListHeaderDataListNode *)wxListBase
::Append(key, object); } wxwxListHeaderDataListNode *Append(const
wxChar *key, void *object) { return (wxwxListHeaderDataListNode
*)wxListBase::Append(key, object); } wxwxListHeaderDataListNode
*DetachNode(wxwxListHeaderDataListNode *node) { return (wxwxListHeaderDataListNode
*)wxListBase::DetachNode(node); } bool DeleteNode(wxwxListHeaderDataListNode
*node) { return wxListBase::DeleteNode(node); } bool DeleteObject
(wxListHeaderData *object) { return wxListBase::DeleteObject(
object); } void Erase(wxwxListHeaderDataListNode *it) { DeleteNode
(it); } wxwxListHeaderDataListNode *Find(const wxListHeaderData
*object) const { return (wxwxListHeaderDataListNode *)wxListBase
::Find(object); } virtual wxwxListHeaderDataListNode *Find(const
wxListKey& key) const { return (wxwxListHeaderDataListNode
*)wxListBase::Find(key); } bool Member(const wxListHeaderData
*object) const { return Find(object) != __null; } int IndexOf
(wxListHeaderData *object) const { return wxListBase::IndexOf
(object); } void Sort(wxSortCompareFunction func) { wxListBase
::Sort(func); } void Sort(wxSortFuncFor_wxListHeaderDataList func
) { Sort((wxSortCompareFunction)func); } protected: virtual wxNodeBase
*CreateNode(wxNodeBase *prev, wxNodeBase *next, void *data, const
wxListKey& key = wxDefaultListKey) override { return new
wxwxListHeaderDataListNode(this, (wxwxListHeaderDataListNode
*)prev, (wxwxListHeaderDataListNode *)next, (wxListHeaderData
*)data, key); } public: typedef size_t size_type; typedef int
difference_type; typedef wxListHeaderData* value_type; typedef
wxListHeaderData* base_value_type; typedef value_type& reference
; typedef const value_type& const_reference; typedef base_value_type
& base_reference; typedef const base_value_type& const_base_reference
; class iterator { public: typedef std::ptrdiff_t difference_type
; typedef std::bidirectional_iterator_tag iterator_category; typedef
wxListHeaderData* value_type; typedef value_type* pointer; typedef
value_type& reference; typedef wxwxListHeaderDataListNode
Node; typedef iterator itor; Node* m_node; Node* m_init; public
: typedef reference reference_type; typedef pointer pointer_type
; iterator(Node* node, Node* init) : m_node(node), m_init(init
) {} iterator() : m_node(__null), m_init(__null) { } reference_type
operator*() const { return *(pointer_type)m_node->GetDataPtr
(); } itor& operator++() { do { if ( m_node ) { } else if
( wxTheAssertHandler && (wxOnAssert("extern/wxWidgets/listctrl.cpp"
, 481, __FUNCTION__, "m_node", L"uninitialized iterator"), wxTrapInAssert
) ) { wxTrapInAssert = false; asm volatile ("int $3"); } } while
( (void)0, 0 ); m_node = m_node->GetNext(); return *this;
} const itor operator++(int) { itor tmp = *this; do { if ( m_node
) { } else if ( wxTheAssertHandler && (wxOnAssert("extern/wxWidgets/listctrl.cpp"
, 481, __FUNCTION__, "m_node", L"uninitialized iterator"), wxTrapInAssert
) ) { wxTrapInAssert = false; asm volatile ("int $3"); } } while
( (void)0, 0 ); m_node = m_node->GetNext(); return tmp; }
itor& operator--() { m_node = m_node ? m_node->GetPrevious
() : m_init; return *this; } const itor operator--(int) { itor
tmp = *this; m_node = m_node ? m_node->GetPrevious() : m_init
; return tmp; } bool operator!=(const itor& it) const { return
it.m_node != m_node; } bool operator==(const itor& it) const
{ return it.m_node == m_node; } }; class const_iterator { public
: typedef std::ptrdiff_t difference_type; typedef std::bidirectional_iterator_tag
iterator_category; typedef wxListHeaderData* value_type; typedef
const value_type* pointer; typedef const value_type& reference
; typedef wxwxListHeaderDataListNode Node; typedef const_iterator
itor; Node* m_node; Node* m_init; public: typedef reference reference_type
; typedef pointer pointer_type; const_iterator(Node* node, Node
* init) : m_node(node), m_init(init) { } const_iterator() : m_node
(__null), m_init(__null) { } const_iterator(const iterator&
it) : m_node(it.m_node), m_init(it.m_init) { } reference_type
operator*() const { return *(pointer_type)m_node->GetDataPtr
(); } itor& operator++() { do { if ( m_node ) { } else if
( wxTheAssertHandler && (wxOnAssert("extern/wxWidgets/listctrl.cpp"
, 481, __FUNCTION__, "m_node", L"uninitialized iterator"), wxTrapInAssert
) ) { wxTrapInAssert = false; asm volatile ("int $3"); } } while
( (void)0, 0 ); m_node = m_node->GetNext(); return *this;
} const itor operator++(int) { itor tmp = *this; do { if ( m_node
) { } else if ( wxTheAssertHandler && (wxOnAssert("extern/wxWidgets/listctrl.cpp"
, 481, __FUNCTION__, "m_node", L"uninitialized iterator"), wxTrapInAssert
) ) { wxTrapInAssert = false; asm volatile ("int $3"); } } while
( (void)0, 0 ); m_node = m_node->GetNext(); return tmp; }
itor& operator--() { m_node = m_node ? m_node->GetPrevious
() : m_init; return *this; } const itor operator--(int) { itor
tmp = *this; m_node = m_node ? m_node->GetPrevious() : m_init
; return tmp; } bool operator!=(const itor& it) const { return
it.m_node != m_node; } bool operator==(const itor& it) const
{ return it.m_node == m_node; } }; class reverse_iterator { public
: typedef std::ptrdiff_t difference_type; typedef std::bidirectional_iterator_tag
iterator_category; typedef wxListHeaderData* value_type; typedef
value_type* pointer; typedef value_type& reference; typedef
wxwxListHeaderDataListNode Node; typedef reverse_iterator itor
; Node* m_node; Node* m_init; public: typedef reference reference_type
; typedef pointer pointer_type; reverse_iterator(Node* node, Node
* init) : m_node(node), m_init(init) { } reverse_iterator() :
m_node(__null), m_init(__null) { } reference_type operator*(
) const { return *(pointer_type)m_node->GetDataPtr(); } itor
& operator++() { m_node = m_node->GetPrevious(); return
*this; } const itor operator++(int) { itor tmp = *this; m_node
= m_node->GetPrevious(); return tmp; } itor& operator
--() { m_node = m_node ? m_node->GetNext() : m_init; return
*this; } const itor operator--(int) { itor tmp = *this; m_node
= m_node ? m_node->GetNext() : m_init; return tmp; } bool
operator!=(const itor& it) const { return it.m_node != m_node
; } bool operator==(const itor& it) const { return it.m_node
== m_node; } }; class const_reverse_iterator { public: typedef
std::ptrdiff_t difference_type; typedef std::bidirectional_iterator_tag
iterator_category; typedef wxListHeaderData* value_type; typedef
const value_type* pointer; typedef const value_type& reference
; typedef wxwxListHeaderDataListNode Node; typedef const_reverse_iterator
itor; Node* m_node; Node* m_init; public: typedef reference reference_type
; typedef pointer pointer_type; const_reverse_iterator(Node* node
, Node* init) : m_node(node), m_init(init) { } const_reverse_iterator
() : m_node(__null), m_init(__null) { } const_reverse_iterator
(const reverse_iterator& it) : m_node(it.m_node), m_init(
it.m_init) { } reference_type operator*() const { return *(pointer_type
)m_node->GetDataPtr(); } itor& operator++() { m_node =
m_node->GetPrevious(); return *this; } const itor operator
++(int) { itor tmp = *this; m_node = m_node->GetPrevious()
; return tmp; } itor& operator--() { m_node = m_node ? m_node
->GetNext() : m_init; return *this;} const itor operator--
(int) { itor tmp = *this; m_node = m_node ? m_node->GetNext
() : m_init; return tmp; } bool operator!=(const itor& it
) const { return it.m_node != m_node; } bool operator==(const
itor& it) const { return it.m_node == m_node; } }; explicit
wxListHeaderDataList(size_type n, const_reference v = value_type
()) { assign(n, v); } wxListHeaderDataList(const const_iterator
& first, const const_iterator& last) { assign(first, last
); } iterator begin() { return iterator(GetFirst(), GetLast()
); } const_iterator begin() const { return const_iterator(GetFirst
(), GetLast()); } iterator end() { return iterator(__null, GetLast
()); } const_iterator end() const { return const_iterator(__null
, GetLast()); } reverse_iterator rbegin() { return reverse_iterator
(GetLast(), GetFirst()); } const_reverse_iterator rbegin() const
{ return const_reverse_iterator(GetLast(), GetFirst()); } reverse_iterator
rend() { return reverse_iterator(__null, GetFirst()); } const_reverse_iterator
rend() const { return const_reverse_iterator(__null, GetFirst
()); } void resize(size_type n, value_type v = value_type()) {
while (n < size()) pop_back(); while (n > size()) push_back
(v); } size_type size() const { return GetCount(); } size_type
max_size() const { return 2147483647; } bool empty() const {
return IsEmpty(); } reference front() { return *begin(); } const_reference
front() const { return *begin(); } reference back() { iterator
tmp = end(); return *--tmp; } const_reference back() const {
const_iterator tmp = end(); return *--tmp; } void push_front
(const_reference v = value_type()) { Insert(GetFirst(), (const_base_reference
)v); } void pop_front() { DeleteNode(GetFirst()); } void push_back
(const_reference v = value_type()) { Append((const_base_reference
)v); } void pop_back() { DeleteNode(GetLast()); } void assign
(const_iterator first, const const_iterator& last) { clear
(); for(; first != last; ++first) Append((const_base_reference
)*first); } void assign(size_type n, const_reference v = value_type
()) { clear(); for(size_type i = 0; i < n; ++i) Append((const_base_reference
)v); } iterator insert(const iterator& it, const_reference
v) { if ( it == end() ) { Append((const_base_reference)v); iterator
itins(end()); return --itins; } else { Insert(it.m_node, (const_base_reference
)v); iterator itins(it); return --itins; } } void insert(const
iterator& it, size_type n, const_reference v) { for(size_type
i = 0; i < n; ++i) insert(it, v); } void insert(const iterator
& it, const_iterator first, const const_iterator& last
) { for(; first != last; ++first) insert(it, *first); } iterator
erase(const iterator& it) { iterator next = iterator(it.
m_node->GetNext(), GetLast()); DeleteNode(it.m_node); return
next; } iterator erase(const iterator& first, const iterator
& last) { iterator next = last; if ( next != end() ) ++next
; DeleteNodes(first.m_node, last.m_node); return next; } void
clear() { Clear(); } void splice(const iterator& it, wxListHeaderDataList
& l, const iterator& first, const iterator& last)
{ insert(it, first, last); l.erase(first, last); } void splice
(const iterator& it, wxListHeaderDataList& l) { splice
(it, l, l.begin(), l.end() ); } void splice(const iterator&
it, wxListHeaderDataList& l, const iterator& first) {
if ( it != first ) { insert(it, *first); l.erase(first); } }
void remove(const_reference v) { DeleteObject((const_base_reference
)v); } void reverse() { Reverse(); } }
;
482#include <wx/listimpl.cpp>
483WX_DEFINE_LIST(wxListHeaderDataList)void wxwxListHeaderDataListNode::DeleteData() { delete (_WX_LIST_ITEM_TYPE_wxListHeaderDataList
*)GetData(); }
484
485class wxListMainWindow : public wxScrolledWindow
486{
487public:
488 wxListMainWindow();
489 wxListMainWindow( wxWindow *parent,
490 wxWindowID id,
491 const wxPoint& pos = wxDefaultPosition,
492 const wxSize& size = wxDefaultSize,
493 long style = 0,
494 const wxString &name = _T("listctrlmainwindow")L"listctrlmainwindow" );
495
496 virtual ~wxListMainWindow();
497
498 bool HasFlag(int flag) const { return m_parent->HasFlag(flag); }
8
Called C++ object pointer is null
499
500 // return true if this is a virtual list control
501 bool IsVirtual() const { return HasFlag(wxLC_VIRTUAL0x0200); }
7
Calling 'wxListMainWindow::HasFlag'
502
503 // return true if the control is in report mode
504 bool InReportView() const { return HasFlag(wxLC_REPORT0x0020); }
505
506 // return true if we are in single selection mode, false if multi sel
507 bool IsSingleSel() const { return HasFlag(wxLC_SINGLE_SEL0x2000); }
508
509 // do we have a header window?
510 bool HasHeader() const
511 { return InReportView() && !HasFlag(wxLC_NO_HEADER0x0800); }
512
513 void HighlightAll( bool on );
514
515 // all these functions only do something if the line is currently visible
516
517 // change the line "selected" state, return true if it really changed
518 bool HighlightLine( size_t line, bool highlight = true);
519
520 // as HighlightLine() but do it for the range of lines: this is incredibly
521 // more efficient for virtual list controls!
522 //
523 // NB: unlike HighlightLine() this one does refresh the lines on screen
524 void HighlightLines( size_t lineFrom, size_t lineTo, bool on = true );
525
526 // toggle the line state and refresh it
527 void ReverseHighlight( size_t line )
528 { HighlightLine(line, !IsHighlighted(line)); RefreshLine(line); }
529
530 // return true if the line is highlighted
531 bool IsHighlighted(size_t line) const;
532
533 // refresh one or several lines at once
534 void RefreshLine( size_t line );
535 void RefreshLines( size_t lineFrom, size_t lineTo );
536
537 // refresh all selected items
538 void RefreshSelected();
539
540 // refresh all lines below the given one: the difference with
541 // RefreshLines() is that the index here might not be a valid one (happens
542 // when the last line is deleted)
543 void RefreshAfter( size_t lineFrom );
544
545 // the methods which are forwarded to wxListLineData itself in list/icon
546 // modes but are here because the lines don't store their positions in the
547 // report mode
548
549 // get the bound rect for the entire line
550 wxRect GetLineRect(size_t line) const;
551
552 // get the bound rect of the label
553 wxRect GetLineLabelRect(size_t line) const;
554
555 // get the bound rect of the items icon (only may be called if we do have
556 // an icon!)
557 wxRect GetLineIconRect(size_t line) const;
558
559 // get the rect to be highlighted when the item has focus
560 wxRect GetLineHighlightRect(size_t line) const;
561
562 // get the size of the total line rect
563 wxSize GetLineSize(size_t line) const
564 { return GetLineRect(line).GetSize(); }
565
566 // return the hit code for the corresponding position (in this line)
567 long HitTestLine(size_t line, int x, int y) const;
568
569 // bring the selected item into view, scrolling to it if necessary
570 void MoveToItem(size_t item);
571
572 // bring the current item into view
573 void MoveToFocus() { MoveToItem(m_current); }
574
575 // start editing the label of the given item
576 wxTextCtrl *EditLabel(long item,
577 wxClassInfo* textControlClass = CLASSINFO(wxTextCtrl)(&wxTextCtrl::ms_classInfo));
578 wxTextCtrl *GetEditControl() const
579 {
580 return m_textctrlWrapper ? m_textctrlWrapper->GetText() : NULL__null;
581 }
582
583 void FinishEditing(wxTextCtrl *text)
584 {
585 delete text;
586 m_textctrlWrapper = NULL__null;
587 SetFocusIgnoringChildren();
588 }
589
590 // suspend/resume redrawing the control
591 void Freeze();
592 void Thaw();
593
594 void OnRenameTimer();
595 bool OnRenameAccept(size_t itemEdit, const wxString& value);
596 void OnRenameCancelled(size_t itemEdit);
597
598 void OnMouse( wxMouseEvent &event );
599
600 // called to switch the selection from the current item to newCurrent,
601 void OnArrowChar( size_t newCurrent, const wxKeyEvent& event );
602
603 void OnChar( wxKeyEvent &event );
604 void OnKeyDown( wxKeyEvent &event );
605 void OnKeyUp( wxKeyEvent &event );
606 void OnSetFocus( wxFocusEvent &event );
607 void OnKillFocus( wxFocusEvent &event );
608 void OnScroll( wxScrollWinEvent& event );
609
610 void OnPaint( wxPaintEvent &event );
611 void OnErase( wxEraseEvent& event ) {
612 // This is needed to avoid garbage on empty lists.
613 if ( IsEmpty() ) {
614 event.Skip();
615 }
616 }
617
618 void OnChildFocus(wxChildFocusEvent& event);
619
620 void DrawImage( int index, wxDC *dc, int x, int y );
621 void GetImageSize( int index, int &width, int &height ) const;
622 int GetTextLength( const wxString &s ) const;
623
624 void SetImageList( wxImageList *imageList, int which );
625 void SetItemSpacing( int spacing, bool isSmall = false );
626 int GetItemSpacing( bool isSmall = false );
627
628 void SetColumn( int col, wxListItem &item );
629 void SetColumnWidth( int col, int width );
630 void GetColumn( int col, wxListItem &item ) const;
631 int GetColumnWidth( int col ) const;
632 int GetColumnCount() const { return m_columns.GetCount(); }
633
634 // returns the sum of the heights of all columns
635 int GetHeaderWidth() const;
636
637 int GetCountPerPage() const;
638
639 void SetItem( wxListItem &item );
640 void GetItem( wxListItem &item ) const;
641 void SetItemState( long item, long state, long stateMask );
642 void SetItemStateAll( long state, long stateMask );
643 int GetItemState( long item, long stateMask ) const;
644 void GetItemRect( long index, wxRect &rect ) const;
645 wxRect GetViewRect() const;
646 bool GetItemPosition( long item, wxPoint& pos ) const;
647 int GetSelectedItemCount() const;
648
649 wxString GetItemText(long item) const
650 {
651 wxListItem info;
652 info.m_mask = wxLIST_MASK_TEXT0x0002;
653 info.m_itemId = item;
654 GetItem( info );
655 return info.m_text;
656 }
657
658 void SetItemText(long item, const wxString& value)
659 {
660 wxListItem info;
661 info.m_mask = wxLIST_MASK_TEXT0x0002;
662 info.m_itemId = item;
663 info.m_text = value;
664 SetItem( info );
665 }
666
667 // set the scrollbars and update the positions of the items
668 void RecalculatePositions(bool noRefresh = false);
669
670 // refresh the window and the header
671 void RefreshAll();
672
673 long GetNextItem( long item, int geometry, int state ) const;
674 void DeleteItem( long index );
675 void DeleteAllItems();
676 void DeleteColumn( int col );
677 void DeleteEverything();
678 void EnsureVisible( long index );
679 long FindItem( long start, const wxString& str, bool partial = false );
680 long FindItem( long start, wxUIntPtr data);
681 long FindItem( const wxPoint& pt );
682 long HitTest( int x, int y, int &flags ) const;
683 void InsertItem( wxListItem &item );
684 void InsertColumn( long col, wxListItem &item );
685 int GetItemWidthWithImage(wxListItem * item);
686 void SortItems( MuleListCtrlCompare fn, long data );
687
688 size_t GetItemCount() const;
689 bool IsEmpty() const { return GetItemCount() == 0; }
5
Calling 'wxListMainWindow::GetItemCount'
690 void SetItemCount(long count);
691
692 // change the current (== focused) item, send a notification event
693 void ChangeCurrent(size_t current);
694 void ResetCurrent() { ChangeCurrent((size_t)-1); }
695 bool HasCurrent() const { return m_current != (size_t)-1; }
696
697 // send out a wxListEvent
698 void SendNotify( size_t line,
699 wxEventType command,
700 const wxPoint& point = wxDefaultPosition );
701
702 // override base class virtual to reset m_lineHeight when the font changes
703 virtual bool SetFont(const wxFont& font)
704 {
705 if ( !wxScrolledWindow::SetFont(font) )
706 return false;
707
708 m_lineHeight = 0;
709
710 return true;
711 }
712
713 // these are for wxListLineData usage only
714
715 // get the backpointer to the list ctrl
716 wxGenericListCtrl *GetListCtrl() const
717 {
718 return wxStaticCast(GetParent(), wxGenericListCtrl)wxCheckCast<wxGenericListCtrl>(GetParent());
719 }
720
721 // get the height of all lines (assuming they all do have the same height)
722 wxCoord GetLineHeight() const;
723
724 // get the y position of the given line (only for report view)
725 wxCoord GetLineY(size_t line) const;
726
727 // get the brush to use for the item highlighting
728 const wxBrush& GetHighlightBrush() const
729 {
730 return m_hasFocus ? m_highlightBrush : m_highlightUnfocusedBrush;
731 }
732
733 bool HasFocus() const
734 {
735 return m_hasFocus;
736 }
737
738//protected:
739 // the array of all line objects for a non virtual list control (for the
740 // virtual list control we only ever use m_lines[0])
741 wxListLineDataArray m_lines;
742
743 // the list of column objects
744 wxListHeaderDataList m_columns;
745
746 // currently focused item or -1
747 size_t m_current;
748
749 // the number of lines per page
750 int m_linesPerPage;
751
752 // this flag is set when something which should result in the window
753 // redrawing happens (i.e. an item was added or deleted, or its appearance
754 // changed) and OnPaint() doesn't redraw the window while it is set which
755 // allows to minimize the number of repaintings when a lot of items are
756 // being added. The real repainting occurs only after the next OnIdle()
757 // call
758 bool m_dirty;
759
760 wxColour *m_highlightColour;
761 wxImageList *m_small_image_list;
762 wxImageList *m_normal_image_list;
763 int m_small_spacing;
764 int m_normal_spacing;
765 bool m_hasFocus;
766
767 bool m_lastOnSame;
768 wxTimer *m_renameTimer;
769 bool m_isCreated;
770 int m_dragCount;
771 wxPoint m_dragStart;
772 ColWidthArray m_aColWidths;
773
774 // for double click logic
775 size_t m_lineLastClicked,
776 m_lineBeforeLastClicked,
777 m_lineSelectSingleOnUp;
778
779protected:
780 wxWindow *GetMainWindowOfCompositeControl() { return GetParent(); }
781
782 // the total count of items in a virtual list control
783 size_t m_countVirt;
784
785 // the object maintaining the items selection state, only used in virtual
786 // controls
787 wxSelectionStore m_selStore;
788
789 // common part of all ctors
790 void Init();
791
792 // get the line data for the given index
793 wxListLineData *GetLine(size_t n) const
794 {
795 wxASSERT_MSG( n != (size_t)-1, _T("invalid line index") )do { if ( n != (size_t)-1 ) { } else if ( wxTheAssertHandler &&
(wxOnAssert("extern/wxWidgets/listctrl.cpp", 795, __FUNCTION__
, "n != (size_t)-1", L"invalid line index"), wxTrapInAssert) )
{ wxTrapInAssert = false; asm volatile ("int $3"); } } while
( (void)0, 0 )
;
796
797 if ( IsVirtual() )
798 {
799 wxConstCast(this, wxListMainWindow)const_cast<wxListMainWindow *>(this)->CacheLineData(n);
800 n = 0;
801 }
802
803 return &m_lines[n];
804 }
805
806 // get a dummy line which can be used for geometry calculations and such:
807 // you must use GetLine() if you want to really draw the line
808 wxListLineData *GetDummyLine() const;
809
810 // cache the line data of the n-th line in m_lines[0]
811 void CacheLineData(size_t line);
812
813 // get the range of visible lines
814 void GetVisibleLinesRange(size_t *from, size_t *to);
815
816 // force us to recalculate the range of visible lines
817 void ResetVisibleLinesRange() { m_lineFrom = (size_t)-1; }
818
819 // get the colour to be used for drawing the rules
820 wxColour GetRuleColour() const
821 {
822 return wxSystemSettings::GetColour(wxSYS_COLOUR_3DLIGHT);
823 }
824
825private:
826 // initialize the current item if needed
827 void UpdateCurrent();
828
829 // delete all items but don't refresh: called from dtor
830 void DoDeleteAllItems();
831
832 // the height of one line using the current font
833 wxCoord m_lineHeight;
834
835 // the total header width or 0 if not calculated yet
836 wxCoord m_headerWidth;
837
838 // the first and last lines being shown on screen right now (inclusive),
839 // both may be -1 if they must be calculated so never access them directly:
840 // use GetVisibleLinesRange() above instead
841 size_t m_lineFrom,
842 m_lineTo;
843
844 // the brushes to use for item highlighting when we do/don't have focus
845 wxBrush m_highlightBrush,
846 m_highlightUnfocusedBrush;
847
848 // if this is > 0, the control is frozen and doesn't redraw itself
849 size_t m_freezeCount;
850
851 // wrapper around the text control currently used for in place editing or
852 // NULL if no item is being edited
853 wxListTextCtrlWrapper *m_textctrlWrapper;
854
855
856 DECLARE_EVENT_TABLE()private: static const wxEventTableEntry sm_eventTableEntries[
]; protected: GCC diagnostic push GCC diagnostic ignored "-Wsuggest-override"
GCC diagnostic push GCC diagnostic ignored "-Winconsistent-missing-override"
const wxEventTable* GetEventTable() const ; wxEventHashTable
& GetEventHashTable() const ; GCC diagnostic pop GCC diagnostic
pop static const wxEventTable sm_eventTable; static wxEventHashTable
sm_eventHashTable;
857
858 friend class wxGenericListCtrl;
859};
860
861
862wxListItemData::~wxListItemData()
863{
864 // in the virtual list control the attributes are managed by the main
865 // program, so don't delete them
866 if ( !m_owner->IsVirtual() )
867 delete m_attr;
868
869 delete m_rect;
870}
871
872void wxListItemData::Init()
873{
874 m_image = -1;
875 m_data = 0;
876
877 m_attr = NULL__null;
878}
879
880wxListItemData::wxListItemData(wxListMainWindow *owner)
881{
882 Init();
883
884 m_owner = owner;
885
886 if ( owner->InReportView() )
887 m_rect = NULL__null;
888 else
889 m_rect = new wxRect;
890}
891
892void wxListItemData::SetItem( const wxListItem &info )
893{
894 if ( info.m_mask & wxLIST_MASK_TEXT0x0002 )
895 SetText(info.m_text);
896 if ( info.m_mask & wxLIST_MASK_IMAGE0x0004 )
897 m_image = info.m_image;
898 if ( info.m_mask & wxLIST_MASK_DATA0x0008 )
899 m_data = info.m_data;
900
901 if ( info.HasAttributes() )
902 {
903 if ( m_attr )
904 m_attr->AssignFrom(*info.GetAttributes());
905 else
906 m_attr = new wxListItemAttr(*info.GetAttributes());
907 }
908
909 if ( m_rect )
910 {
911 m_rect->x =
912 m_rect->y =
913 m_rect->height = 0;
914 m_rect->width = info.m_width;
915 }
916}
917
918void wxListItemData::SetPosition( int x, int y )
919{
920 wxCHECK_RET( m_rect, _T("unexpected SetPosition() call") )if ( m_rect ) {} else { do { if ( wxTheAssertHandler &&
(wxOnAssert("extern/wxWidgets/listctrl.cpp", 920, __FUNCTION__
, "\"m_rect\"", L"unexpected SetPosition() call"), wxTrapInAssert
) ) { wxTrapInAssert = false; asm volatile ("int $3"); } } while
( (void)0, 0 ); return; } struct wxDummyCheckStruct920
;
921
922 m_rect->x = x;
923 m_rect->y = y;
924}
925
926void wxListItemData::SetSize( int width, int height )
927{
928 wxCHECK_RET( m_rect, _T("unexpected SetSize() call") )if ( m_rect ) {} else { do { if ( wxTheAssertHandler &&
(wxOnAssert("extern/wxWidgets/listctrl.cpp", 928, __FUNCTION__
, "\"m_rect\"", L"unexpected SetSize() call"), wxTrapInAssert
) ) { wxTrapInAssert = false; asm volatile ("int $3"); } } while
( (void)0, 0 ); return; } struct wxDummyCheckStruct928
;
929
930 if ( width != -1 )
931 m_rect->width = width;
932 if ( height != -1 )
933 m_rect->height = height;
934}
935
936bool wxListItemData::IsHit( int x, int y ) const
937{
938 wxCHECK_MSG( m_rect, false, _T("can't be called in this mode") )if ( m_rect ) {} else { do { if ( wxTheAssertHandler &&
(wxOnAssert("extern/wxWidgets/listctrl.cpp", 938, __FUNCTION__
, "\"m_rect\"", L"can't be called in this mode"), wxTrapInAssert
) ) { wxTrapInAssert = false; asm volatile ("int $3"); } } while
( (void)0, 0 ); return false; } struct wxDummyCheckStruct938
;
939
940 return wxRect(GetX(), GetY(), GetWidth(), GetHeight()).Contains(x, y);
941}
942
943int wxListItemData::GetX() const
944{
945 wxCHECK_MSG( m_rect, 0, _T("can't be called in this mode") )if ( m_rect ) {} else { do { if ( wxTheAssertHandler &&
(wxOnAssert("extern/wxWidgets/listctrl.cpp", 945, __FUNCTION__
, "\"m_rect\"", L"can't be called in this mode"), wxTrapInAssert
) ) { wxTrapInAssert = false; asm volatile ("int $3"); } } while
( (void)0, 0 ); return 0; } struct wxDummyCheckStruct945
;
946
947 return m_rect->x;
948}
949
950int wxListItemData::GetY() const
951{
952 wxCHECK_MSG( m_rect, 0, _T("can't be called in this mode") )if ( m_rect ) {} else { do { if ( wxTheAssertHandler &&
(wxOnAssert("extern/wxWidgets/listctrl.cpp", 952, __FUNCTION__
, "\"m_rect\"", L"can't be called in this mode"), wxTrapInAssert
) ) { wxTrapInAssert = false; asm volatile ("int $3"); } } while
( (void)0, 0 ); return 0; } struct wxDummyCheckStruct952
;
953
954 return m_rect->y;
955}
956
957int wxListItemData::GetWidth() const
958{
959 wxCHECK_MSG( m_rect, 0, _T("can't be called in this mode") )if ( m_rect ) {} else { do { if ( wxTheAssertHandler &&
(wxOnAssert("extern/wxWidgets/listctrl.cpp", 959, __FUNCTION__
, "\"m_rect\"", L"can't be called in this mode"), wxTrapInAssert
) ) { wxTrapInAssert = false; asm volatile ("int $3"); } } while
( (void)0, 0 ); return 0; } struct wxDummyCheckStruct959
;
960
961 return m_rect->width;
962}
963
964int wxListItemData::GetHeight() const
965{
966 wxCHECK_MSG( m_rect, 0, _T("can't be called in this mode") )if ( m_rect ) {} else { do { if ( wxTheAssertHandler &&
(wxOnAssert("extern/wxWidgets/listctrl.cpp", 966, __FUNCTION__
, "\"m_rect\"", L"can't be called in this mode"), wxTrapInAssert
) ) { wxTrapInAssert = false; asm volatile ("int $3"); } } while
( (void)0, 0 ); return 0; } struct wxDummyCheckStruct966
;
967
968 return m_rect->height;
969}
970
971void wxListItemData::GetItem( wxListItem &info ) const
972{
973 long mask = info.m_mask;
974 if ( !mask )
975 // by default, get everything for backwards compatibility
976 mask = -1;
977
978 if ( mask & wxLIST_MASK_TEXT0x0002 )
979 info.m_text = m_text;
980 if ( mask & wxLIST_MASK_IMAGE0x0004 )
981 info.m_image = m_image;
982 if ( mask & wxLIST_MASK_DATA0x0008 )
983 info.m_data = m_data;
984
985 if ( m_attr )
986 {
987 if ( m_attr->HasTextColour() )
988 info.SetTextColour(m_attr->GetTextColour());
989 if ( m_attr->HasBackgroundColour() )
990 info.SetBackgroundColour(m_attr->GetBackgroundColour());
991 if ( m_attr->HasFont() )
992 info.SetFont(m_attr->GetFont());
993 }
994}
995
996//-----------------------------------------------------------------------------
997// wxListHeaderData
998//-----------------------------------------------------------------------------
999
1000void wxListHeaderData::Init()
1001{
1002 m_mask = 0;
1003 m_image = -1;
1004 m_format = 0;
1005 m_width = 0;
1006 m_xpos = 0;
1007 m_ypos = 0;
1008 m_height = 0;
1009 m_state = 0;
1010}
1011
1012wxListHeaderData::wxListHeaderData()
1013{
1014 Init();
1015}
1016
1017wxListHeaderData::wxListHeaderData( const wxListItem &item )
1018{
1019 Init();
1020
1021 SetItem( item );
1022}
1023
1024void wxListHeaderData::SetItem( const wxListItem &item )
1025{
1026 m_mask = item.m_mask;
1027
1028 if ( m_mask & wxLIST_MASK_TEXT0x0002 )
1029 m_text = item.m_text;
1030
1031 if ( m_mask & wxLIST_MASK_IMAGE0x0004 )
1032 m_image = item.m_image;
1033
1034 if ( m_mask & wxLIST_MASK_FORMAT0x0040 )
1035 m_format = item.m_format;
1036
1037 if ( m_mask & wxLIST_MASK_WIDTH0x0020 )
1038 SetWidth(item.m_width);
1039
1040 if ( m_mask & wxLIST_MASK_STATE0x0001 )
1041 SetState(item.m_state);
1042}
1043
1044void wxListHeaderData::SetPosition( int x, int y )
1045{
1046 m_xpos = x;
1047 m_ypos = y;
1048}
1049
1050void wxListHeaderData::SetHeight( int h )
1051{
1052 m_height = h;
1053}
1054
1055void wxListHeaderData::SetWidth( int w )
1056{
1057 m_width = w < 0 ? WIDTH_COL_DEFAULT : w;
1058}
1059
1060void wxListHeaderData::SetState( int flag )
1061{
1062 m_state = flag;
1063}
1064
1065void wxListHeaderData::SetFormat( int format )
1066{
1067 m_format = format;
1068}
1069
1070bool wxListHeaderData::HasImage() const
1071{
1072 return m_image != -1;
1073}
1074
1075bool wxListHeaderData::IsHit( int x, int y ) const
1076{
1077 return ((x >= m_xpos) && (x <= m_xpos+m_width) && (y >= m_ypos) && (y <= m_ypos+m_height));
1078}
1079
1080void wxListHeaderData::GetItem( wxListItem& item )
1081{
1082 item.m_mask = m_mask;
1083 item.m_text = m_text;
1084 item.m_image = m_image;
1085 item.m_format = m_format;
1086 item.m_width = m_width;
1087 item.m_state = m_state;
1088}
1089
1090int wxListHeaderData::GetImage() const
1091{
1092 return m_image;
1093}
1094
1095int wxListHeaderData::GetWidth() const
1096{
1097 return m_width;
1098}
1099
1100int wxListHeaderData::GetFormat() const
1101{
1102 return m_format;
1103}
1104
1105int wxListHeaderData::GetState() const
1106{
1107 return m_state;
1108}
1109
1110//-----------------------------------------------------------------------------
1111// wxListLineData
1112//-----------------------------------------------------------------------------
1113
1114inline int wxListLineData::GetMode() const
1115{
1116 return m_owner->GetListCtrl()->GetWindowStyleFlag() & wxLC_MASK_TYPE(0x0004 | 0x0008 | 0x0010 | 0x0020);
1117}
1118
1119inline bool wxListLineData::InReportView() const
1120{
1121 return m_owner->HasFlag(wxLC_REPORT0x0020);
1122}
1123
1124inline bool wxListLineData::IsVirtual() const
1125{
1126 return m_owner->IsVirtual();
1127}
1128
1129wxListLineData::wxListLineData( wxListMainWindow *owner )
1130{
1131 m_owner = owner;
1132
1133 if ( InReportView() )
1134 m_gi = NULL__null;
1135 else // !report
1136 m_gi = new GeometryInfo;
1137
1138 m_highlighted = false;
1139
1140 InitItems( GetMode() == wxLC_REPORT0x0020 ? m_owner->GetColumnCount() : 1 );
1141}
1142
1143void wxListLineData::CalculateSize( wxDC *dc, int spacing )
1144{
1145 wxListItemDataList::compatibility_iterator node = m_items.GetFirst();
1146 wxCHECK_RET( node, _T("no subitems at all??") )if ( node ) {} else { do { if ( wxTheAssertHandler &&
(wxOnAssert("extern/wxWidgets/listctrl.cpp", 1146, __FUNCTION__
, "\"node\"", L"no subitems at all??"), wxTrapInAssert) ) { wxTrapInAssert
= false; asm volatile ("int $3"); } } while ( (void)0, 0 ); return
; } struct wxDummyCheckStruct1146
;
1147
1148 wxListItemData *item = node->GetData();
1149
1150 wxString s;
1151 wxCoord lw, lh;
1152
1153 switch ( GetMode() )
1154 {
1155 case wxLC_ICON0x0004:
1156 case wxLC_SMALL_ICON0x0008:
1157 m_gi->m_rectAll.width = spacing;
1158
1159 s = item->GetText();
1160
1161 if ( s.empty() )
1162 {
1163 lh =
1164 m_gi->m_rectLabel.width =
1165 m_gi->m_rectLabel.height = 0;
1166 }
1167 else // has label
1168 {
1169 dc->GetTextExtent( s, &lw, &lh );
1170 lw += EXTRA_WIDTH;
1171 lh += EXTRA_HEIGHT;
1172
1173 m_gi->m_rectAll.height = spacing + lh;
1174 if (lw > spacing)
1175 m_gi->m_rectAll.width = lw;
1176
1177 m_gi->m_rectLabel.width = lw;
1178 m_gi->m_rectLabel.height = lh;
1179 }
1180
1181 if (item->HasImage())
1182 {
1183 int w, h;
1184 m_owner->GetImageSize( item->GetImage(), w, h );
1185 m_gi->m_rectIcon.width = w + 8;
1186 m_gi->m_rectIcon.height = h + 8;
1187
1188 if ( m_gi->m_rectIcon.width > m_gi->m_rectAll.width )
1189 m_gi->m_rectAll.width = m_gi->m_rectIcon.width;
1190 if ( m_gi->m_rectIcon.height + lh > m_gi->m_rectAll.height - 4 )
1191 m_gi->m_rectAll.height = m_gi->m_rectIcon.height + lh + 4;
1192 }
1193
1194 if ( item->HasText() )
1195 {
1196 m_gi->m_rectHighlight.width = m_gi->m_rectLabel.width;
1197 m_gi->m_rectHighlight.height = m_gi->m_rectLabel.height;
1198 }
1199 else // no text, highlight the icon
1200 {
1201 m_gi->m_rectHighlight.width = m_gi->m_rectIcon.width;
1202 m_gi->m_rectHighlight.height = m_gi->m_rectIcon.height;
1203 }
1204 break;
1205
1206 case wxLC_LIST0x0010:
1207 s = item->GetTextForMeasuring();
1208
1209 dc->GetTextExtent( s, &lw, &lh );
1210 lw += EXTRA_WIDTH;
1211 lh += EXTRA_HEIGHT;
1212
1213 m_gi->m_rectLabel.width = lw;
1214 m_gi->m_rectLabel.height = lh;
1215
1216 m_gi->m_rectAll.width = lw;
1217 m_gi->m_rectAll.height = lh;
1218
1219 if (item->HasImage())
1220 {
1221 int w, h;
1222 m_owner->GetImageSize( item->GetImage(), w, h );
1223 m_gi->m_rectIcon.width = w;
1224 m_gi->m_rectIcon.height = h;
1225
1226 m_gi->m_rectAll.width += 4 + w;
1227 if (h > m_gi->m_rectAll.height)
1228 m_gi->m_rectAll.height = h;
1229 }
1230
1231 m_gi->m_rectHighlight.width = m_gi->m_rectAll.width;
1232 m_gi->m_rectHighlight.height = m_gi->m_rectAll.height;
1233 break;
1234
1235 case wxLC_REPORT0x0020:
1236 wxFAIL_MSG( _T("unexpected call to SetSize") )do { if ( wxTheAssertHandler && (wxOnAssert("extern/wxWidgets/listctrl.cpp"
, 1236, __FUNCTION__, "\"Assert failure\"", L"unexpected call to SetSize"
), wxTrapInAssert) ) { wxTrapInAssert = false; asm volatile (
"int $3"); } } while ( (void)0, 0 )
;
1237 break;
1238
1239 default:
1240 wxFAIL_MSG( _T("unknown mode") )do { if ( wxTheAssertHandler && (wxOnAssert("extern/wxWidgets/listctrl.cpp"
, 1240, __FUNCTION__, "\"Assert failure\"", L"unknown mode"),
wxTrapInAssert) ) { wxTrapInAssert = false; asm volatile ("int $3"
); } } while ( (void)0, 0 )
;
1241 break;
1242 }
1243}
1244
1245void wxListLineData::SetPosition( int x, int y, int spacing )
1246{
1247 wxListItemDataList::compatibility_iterator node = m_items.GetFirst();
1248 wxCHECK_RET( node, _T("no subitems at all??") )if ( node ) {} else { do { if ( wxTheAssertHandler &&
(wxOnAssert("extern/wxWidgets/listctrl.cpp", 1248, __FUNCTION__
, "\"node\"", L"no subitems at all??"), wxTrapInAssert) ) { wxTrapInAssert
= false; asm volatile ("int $3"); } } while ( (void)0, 0 ); return
; } struct wxDummyCheckStruct1248
;
1249
1250 wxListItemData *item = node->GetData();
1251
1252 switch ( GetMode() )
1253 {
1254 case wxLC_ICON0x0004:
1255 case wxLC_SMALL_ICON0x0008:
1256 m_gi->m_rectAll.x = x;
1257 m_gi->m_rectAll.y = y;
1258
1259 if ( item->HasImage() )
1260 {
1261 m_gi->m_rectIcon.x = m_gi->m_rectAll.x + 4 +
1262 (m_gi->m_rectAll.width - m_gi->m_rectIcon.width) / 2;
1263 m_gi->m_rectIcon.y = m_gi->m_rectAll.y + 4;
1264 }
1265
1266 if ( item->HasText() )
1267 {
1268 if (m_gi->m_rectAll.width > spacing)
1269 m_gi->m_rectLabel.x = m_gi->m_rectAll.x + (EXTRA_WIDTH/2);
1270 else
1271 m_gi->m_rectLabel.x = m_gi->m_rectAll.x + (EXTRA_WIDTH/2) + (spacing / 2) - (m_gi->m_rectLabel.width / 2);
1272 m_gi->m_rectLabel.y = m_gi->m_rectAll.y + m_gi->m_rectAll.height + 2 - m_gi->m_rectLabel.height;
1273 m_gi->m_rectHighlight.x = m_gi->m_rectLabel.x - 2;
1274 m_gi->m_rectHighlight.y = m_gi->m_rectLabel.y - 2;
1275 }
1276 else // no text, highlight the icon
1277 {
1278 m_gi->m_rectHighlight.x = m_gi->m_rectIcon.x - 4;
1279 m_gi->m_rectHighlight.y = m_gi->m_rectIcon.y - 4;
1280 }
1281 break;
1282
1283 case wxLC_LIST0x0010:
1284 m_gi->m_rectAll.x = x;
1285 m_gi->m_rectAll.y = y;
1286
1287 m_gi->m_rectHighlight.x = m_gi->m_rectAll.x;
1288 m_gi->m_rectHighlight.y = m_gi->m_rectAll.y;
1289 m_gi->m_rectLabel.y = m_gi->m_rectAll.y + 2;
1290
1291 if (item->HasImage())
1292 {
1293 m_gi->m_rectIcon.x = m_gi->m_rectAll.x + 2;
1294 m_gi->m_rectIcon.y = m_gi->m_rectAll.y + 2;
1295 m_gi->m_rectLabel.x = m_gi->m_rectAll.x + 4 + (EXTRA_WIDTH/2) + m_gi->m_rectIcon.width;
1296 }
1297 else
1298 {
1299 m_gi->m_rectLabel.x = m_gi->m_rectAll.x + (EXTRA_WIDTH/2);
1300 }
1301 break;
1302
1303 case wxLC_REPORT0x0020:
1304 wxFAIL_MSG( _T("unexpected call to SetPosition") )do { if ( wxTheAssertHandler && (wxOnAssert("extern/wxWidgets/listctrl.cpp"
, 1304, __FUNCTION__, "\"Assert failure\"", L"unexpected call to SetPosition"
), wxTrapInAssert) ) { wxTrapInAssert = false; asm volatile (
"int $3"); } } while ( (void)0, 0 )
;
1305 break;
1306
1307 default:
1308 wxFAIL_MSG( _T("unknown mode") )do { if ( wxTheAssertHandler && (wxOnAssert("extern/wxWidgets/listctrl.cpp"
, 1308, __FUNCTION__, "\"Assert failure\"", L"unknown mode"),
wxTrapInAssert) ) { wxTrapInAssert = false; asm volatile ("int $3"
); } } while ( (void)0, 0 )
;
1309 break;
1310 }
1311}
1312
1313void wxListLineData::InitItems( int num )
1314{
1315 for (int i = 0; i < num; i++)
1316 m_items.Append( new wxListItemData(m_owner) );
1317}
1318
1319void wxListLineData::SetItem( int index, const wxListItem &info )
1320{
1321 wxListItemDataList::compatibility_iterator node = m_items.Item( index );
1322 wxCHECK_RET( node, _T("invalid column index in SetItem") )if ( node ) {} else { do { if ( wxTheAssertHandler &&
(wxOnAssert("extern/wxWidgets/listctrl.cpp", 1322, __FUNCTION__
, "\"node\"", L"invalid column index in SetItem"), wxTrapInAssert
) ) { wxTrapInAssert = false; asm volatile ("int $3"); } } while
( (void)0, 0 ); return; } struct wxDummyCheckStruct1322
;
1323
1324 wxListItemData *item = node->GetData();
1325 item->SetItem( info );
1326}
1327
1328void wxListLineData::GetItem( int index, wxListItem &info )
1329{
1330 wxListItemDataList::compatibility_iterator node = m_items.Item( index );
1331 if (node)
1332 {
1333 wxListItemData *item = node->GetData();
1334 item->GetItem( info );
1335 }
1336}
1337
1338wxString wxListLineData::GetText(int index) const
1339{
1340 wxString s;
1341
1342 wxListItemDataList::compatibility_iterator node = m_items.Item( index );
1343 if (node)
1344 {
1345 wxListItemData *item = node->GetData();
1346 s = item->GetText();
1347 }
1348
1349 return s;
1350}
1351
1352void wxListLineData::SetText( int index, const wxString& s )
1353{
1354 wxListItemDataList::compatibility_iterator node = m_items.Item( index );
1355 if (node)
1356 {
1357 wxListItemData *item = node->GetData();
1358 item->SetText( s );
1359 }
1360}
1361
1362void wxListLineData::SetImage( int index, int image )
1363{
1364 wxListItemDataList::compatibility_iterator node = m_items.Item( index );
1365 wxCHECK_RET( node, _T("invalid column index in SetImage()") )if ( node ) {} else { do { if ( wxTheAssertHandler &&
(wxOnAssert("extern/wxWidgets/listctrl.cpp", 1365, __FUNCTION__
, "\"node\"", L"invalid column index in SetImage()"), wxTrapInAssert
) ) { wxTrapInAssert = false; asm volatile ("int $3"); } } while
( (void)0, 0 ); return; } struct wxDummyCheckStruct1365
;
1366
1367 wxListItemData *item = node->GetData();
1368 item->SetImage(image);
1369}
1370
1371int wxListLineData::GetImage( int index ) const
1372{
1373 wxListItemDataList::compatibility_iterator node = m_items.Item( index );
1374 wxCHECK_MSG( node, -1, _T("invalid column index in GetImage()") )if ( node ) {} else { do { if ( wxTheAssertHandler &&
(wxOnAssert("extern/wxWidgets/listctrl.cpp", 1374, __FUNCTION__
, "\"node\"", L"invalid column index in GetImage()"), wxTrapInAssert
) ) { wxTrapInAssert = false; asm volatile ("int $3"); } } while
( (void)0, 0 ); return -1; } struct wxDummyCheckStruct1374
;
1375
1376 wxListItemData *item = node->GetData();
1377 return item->GetImage();
1378}
1379
1380wxListItemAttr *wxListLineData::GetAttr() const
1381{
1382 wxListItemDataList::compatibility_iterator node = m_items.GetFirst();
1383 wxCHECK_MSG( node, NULL, _T("invalid column index in GetAttr()") )if ( node ) {} else { do { if ( wxTheAssertHandler &&
(wxOnAssert("extern/wxWidgets/listctrl.cpp", 1383, __FUNCTION__
, "\"node\"", L"invalid column index in GetAttr()"), wxTrapInAssert
) ) { wxTrapInAssert = false; asm volatile ("int $3"); } } while
( (void)0, 0 ); return __null; } struct wxDummyCheckStruct1383
;
1384
1385 wxListItemData *item = node->GetData();
1386 return item->GetAttr();
1387}
1388
1389void wxListLineData::SetAttr(wxListItemAttr *attr)
1390{
1391 wxListItemDataList::compatibility_iterator node = m_items.GetFirst();
1392 wxCHECK_RET( node, _T("invalid column index in SetAttr()") )if ( node ) {} else { do { if ( wxTheAssertHandler &&
(wxOnAssert("extern/wxWidgets/listctrl.cpp", 1392, __FUNCTION__
, "\"node\"", L"invalid column index in SetAttr()"), wxTrapInAssert
) ) { wxTrapInAssert = false; asm volatile ("int $3"); } } while
( (void)0, 0 ); return; } struct wxDummyCheckStruct1392
;
1393
1394 wxListItemData *item = node->GetData();
1395 item->SetAttr(attr);
1396}
1397
1398bool wxListLineData::SetAttributes(wxDC *dc,
1399 const wxListItemAttr *attr,
1400 bool highlighted)
1401{
1402 wxWindow *listctrl = m_owner->GetParent();
1403
1404 // fg colour
1405
1406 // don't use foreground colour for drawing highlighted items - this might
1407 // make them completely invisible (and there is no way to do bit
1408 // arithmetics on wxColour, unfortunately)
1409 wxColour colText;
1410 if ( highlighted )
1411#ifdef __WXMAC__
1412 {
1413 if (m_owner->HasFocus()
1414#if defined( __WXMAC__ ) && !defined(__WXUNIVERSAL__) && wxOSX_USE_CARBON
1415 && IsControlActive( (ControlRef)m_owner->GetHandle() )
1416#endif
1417 )
1418 colText = *wxWHITEwxStockGDI::GetColour(wxStockGDI::COLOUR_WHITE);
1419 else
1420 colText = *wxBLACKwxStockGDI::GetColour(wxStockGDI::COLOUR_BLACK);
1421 }
1422#else
1423 colText = wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT);
1424#endif
1425 else if ( attr && attr->HasTextColour() )
1426 colText = attr->GetTextColour();
1427 else
1428 colText = listctrl->GetForegroundColour();
1429
1430 dc->SetTextForeground(colText);
1431
1432 // font
1433 wxFont font;
1434 if ( attr && attr->HasFont() )
1435 font = attr->GetFont();
1436 else
1437 font = listctrl->GetFont();
1438
1439 dc->SetFont(font);
1440
1441 // bg colour
1442 bool hasBgCol = attr && attr->HasBackgroundColour();
1443 if ( highlighted || hasBgCol )
1444 {
1445 if ( highlighted )
1446 dc->SetBrush( m_owner->GetHighlightBrush() );
1447 else
1448 dc->SetBrush(*(wxTheBrushList->FindOrCreateBrush(attr->GetBackgroundColour(), wxBRUSHSTYLE_SOLID)));
1449
1450 dc->SetPen( *wxTRANSPARENT_PENwxStockGDI::GetPen(wxStockGDI::PEN_TRANSPARENT) );
1451
1452 return true;
1453 }
1454
1455 return false;
1456}
1457
1458void wxListLineData::Draw( wxDC *dc )
1459{
1460 wxListItemDataList::compatibility_iterator node = m_items.GetFirst();
1461 wxCHECK_RET( node, _T("no subitems at all??") )if ( node ) {} else { do { if ( wxTheAssertHandler &&
(wxOnAssert("extern/wxWidgets/listctrl.cpp", 1461, __FUNCTION__
, "\"node\"", L"no subitems at all??"), wxTrapInAssert) ) { wxTrapInAssert
= false; asm volatile ("int $3"); } } while ( (void)0, 0 ); return
; } struct wxDummyCheckStruct1461
;
1462
1463 bool highlighted = IsHighlighted();
1464
1465 wxListItemAttr *attr = GetAttr();
1466
1467 if ( SetAttributes(dc, attr, highlighted) )
1468#if ( !defined(__WXGTK2__) && !defined(__WXMAC__) )
1469 {
1470 dc->DrawRectangle( m_gi->m_rectHighlight );
1471 }
1472#else
1473 {
1474 if (highlighted)
1475 {
1476 int flags = wxCONTROL_SELECTED;
1477 if (m_owner->HasFocus()
1478#if defined( __WXMAC__ ) && !defined(__WXUNIVERSAL__) && wxOSX_USE_CARBON
1479 && IsControlActive( (ControlRef)m_owner->GetHandle() )
1480#endif
1481 )
1482 flags |= wxCONTROL_FOCUSED;
1483 wxRendererNative::Get().DrawItemSelectionRect( m_owner, *dc, m_gi->m_rectHighlight, flags );
1484
1485 }
1486 else
1487 {
1488 dc->DrawRectangle( m_gi->m_rectHighlight );
1489 }
1490 }
1491#endif
1492
1493 // just for debugging to better see where the items are
1494#if 0
1495 dc->SetPen(*wxRED_PENwxStockGDI::GetPen(wxStockGDI::PEN_RED));
1496 dc->SetBrush(*wxTRANSPARENT_BRUSHwxStockGDI::GetBrush(wxStockGDI::BRUSH_TRANSPARENT));
1497 dc->DrawRectangle( m_gi->m_rectAll );
1498 dc->SetPen(*wxGREEN_PENwxStockGDI::GetPen(wxStockGDI::PEN_GREEN));
1499 dc->DrawRectangle( m_gi->m_rectIcon );
1500#endif
1501
1502 wxListItemData *item = node->GetData();
1503 if (item->HasImage())
1504 {
1505 // centre the image inside our rectangle, this looks nicer when items
1506 // ae aligned in a row
1507 const wxRect& rectIcon = m_gi->m_rectIcon;
1508
1509 m_owner->DrawImage(item->GetImage(), dc, rectIcon.x, rectIcon.y);
1510 }
1511
1512 if (item->HasText())
1513 {
1514 const wxRect& rectLabel = m_gi->m_rectLabel;
1515
1516 wxDCClipper clipper(*dc, rectLabel);
1517 dc->DrawText(item->GetText(), rectLabel.x, rectLabel.y);
1518 }
1519}
1520
1521void wxListLineData::DrawInReportMode( wxDC *dc,
1522 const wxRect& rect,
1523 const wxRect& rectHL,
1524 bool highlighted )
1525{
1526 // TODO: later we should support setting different attributes for
1527 // different columns - to do it, just add "col" argument to
1528 // GetAttr() and move these lines into the loop below
1529 wxListItemAttr *attr = GetAttr();
1530 if ( SetAttributes(dc, attr, highlighted) )
1531#if ( !defined(__WXGTK2__) && !defined(__WXMAC__) )
1532 {
1533 dc->DrawRectangle( rectHL );
1534 }
1535#else
1536 {
1537 if (highlighted)
1538 {
1539 int flags = wxCONTROL_SELECTED;
1540 if (m_owner->HasFocus()
1541#if defined( __WXMAC__ ) && !defined(__WXUNIVERSAL__) && wxOSX_USE_CARBON
1542 && IsControlActive( (ControlRef)m_owner->GetHandle() )
1543#endif
1544 )
1545 flags |= wxCONTROL_FOCUSED;
1546 wxRendererNative::Get().DrawItemSelectionRect( m_owner, *dc, rectHL, flags );
1547 }
1548 else
1549 {
1550 dc->DrawRectangle( rectHL );
1551 }
1552 }
1553#endif
1554
1555 wxCoord x = rect.x + HEADER_OFFSET_X,
1556 yMid = rect.y + rect.height/2;
1557#ifdef __WXGTK__1
1558 // This probably needs to be done
1559 // on all platforms as the icons
1560 // otherwise nearly touch the border
1561 x += 2;
1562#endif
1563
1564 size_t col = 0;
1565 for ( wxListItemDataList::compatibility_iterator node = m_items.GetFirst();
1566 node;
1567 node = node->GetNext(), col++ )
1568 {
1569 wxListItemData *item = node->GetData();
1570
1571 int width = m_owner->GetColumnWidth(col);
1572 int xOld = x;
1573 x += width;
1574
1575 if ( item->HasImage() )
1576 {
1577 int ix, iy;
1578 m_owner->GetImageSize( item->GetImage(), ix, iy );
1579 m_owner->DrawImage( item->GetImage(), dc, xOld, yMid - iy/2 );
1580
1581 ix += IMAGE_MARGIN_IN_REPORT_MODE;
1582
1583 xOld += ix;
1584 width -= ix;
1585 }
1586
1587 if ( item->HasText() )
1588 DrawTextFormatted(dc, item->GetText(), col, xOld, yMid, width - 8);
1589 }
1590}
1591
1592void wxListLineData::DrawTextFormatted(wxDC *dc,
1593 const wxString& textOrig,
1594 int col,
1595 int x,
1596 int yMid,
1597 int width)
1598{
1599 // we don't support displaying multiple lines currently (and neither does
1600 // wxMSW FWIW) so just merge all the lines
1601 wxString text(textOrig);
1602 text.Replace(_T("\n")L"\n", _T(" ")L" ");
1603
1604 wxCoord w, h;
1605 dc->GetTextExtent(text, &w, &h);
1606
1607 const wxCoord y = yMid - (h + 1)/2;
1608
1609 wxDCClipper clipper(*dc, x, y, width, h);
1610
1611 // determine if the string can fit inside the current width
1612 if (w <= width)
1613 {
1614 // it can, draw it using the items alignment
1615 wxListItem item;
1616 m_owner->GetColumn(col, item);
1617 switch ( item.GetAlign() )
1618 {
1619 case wxLIST_FORMAT_LEFT:
1620 // nothing to do
1621 break;
1622
1623 case wxLIST_FORMAT_RIGHT:
1624 x += width - w;
1625 break;
1626
1627 case wxLIST_FORMAT_CENTER:
1628 x += (width - w) / 2;
1629 break;
1630
1631 default:
1632 wxFAIL_MSG( _T("unknown list item format") )do { if ( wxTheAssertHandler && (wxOnAssert("extern/wxWidgets/listctrl.cpp"
, 1632, __FUNCTION__, "\"Assert failure\"", L"unknown list item format"
), wxTrapInAssert) ) { wxTrapInAssert = false; asm volatile (
"int $3"); } } while ( (void)0, 0 )
;
1633 break;
1634 }
1635
1636 dc->DrawText(text, x, y);
1637 }
1638 else // otherwise, truncate and add an ellipsis if possible
1639 {
1640 // determine the base width
1641 wxString ellipsis(wxT("...")L"...");
1642 wxCoord base_w;
1643 dc->GetTextExtent(ellipsis, &base_w, &h);
1644
1645 // continue until we have enough space or only one character left
1646 wxCoord w_c, h_c;
1647 size_t len = text.length();
1648 wxString drawntext = text.Left(len);
1649 while (len > 1)
1650 {
1651 dc->GetTextExtent(drawntext.Last(), &w_c, &h_c);
1652 drawntext.RemoveLast();
1653 len--;
1654 w -= w_c;
1655 if (w + base_w <= width)
1656 break;
1657 }
1658
1659 // if still not enough space, remove ellipsis characters
1660 while (ellipsis.length() > 0 && w + base_w > width)
1661 {
1662 ellipsis = ellipsis.Left(ellipsis.length() - 1);
1663 dc->GetTextExtent(ellipsis, &base_w, &h);
1664 }
1665
1666 // now draw the text
1667 dc->DrawText(drawntext, x, y);
1668 dc->DrawText(ellipsis, x + w, y);
1669 }
1670}
1671
1672bool wxListLineData::Highlight( bool on )
1673{
1674 wxCHECK_MSG( !IsVirtual(), false, _T("unexpected call to Highlight") )if ( !IsVirtual() ) {} else { do { if ( wxTheAssertHandler &&
(wxOnAssert("extern/wxWidgets/listctrl.cpp", 1674, __FUNCTION__
, "\"!IsVirtual()\"", L"unexpected call to Highlight"), wxTrapInAssert
) ) { wxTrapInAssert = false; asm volatile ("int $3"); } } while
( (void)0, 0 ); return false; } struct wxDummyCheckStruct1674
;
1675
1676 if ( on == m_highlighted )
1677 return false;
1678
1679 m_highlighted = on;
1680
1681 return true;
1682}
1683
1684void wxListLineData::ReverseHighlight( void )
1685{
1686 Highlight(!IsHighlighted());
1687}
1688
1689//-----------------------------------------------------------------------------
1690// wxListHeaderWindow
1691//-----------------------------------------------------------------------------
1692
1693BEGIN_EVENT_TABLE(wxListHeaderWindow,wxWindow)const wxEventTable wxListHeaderWindow::sm_eventTable = { &
wxWindow::sm_eventTable, &wxListHeaderWindow::sm_eventTableEntries
[0] }; const wxEventTable *wxListHeaderWindow::GetEventTable(
) const { return &wxListHeaderWindow::sm_eventTable; } wxEventHashTable
wxListHeaderWindow::sm_eventHashTable(wxListHeaderWindow::sm_eventTable
); wxEventHashTable &wxListHeaderWindow::GetEventHashTable
() const { return wxListHeaderWindow::sm_eventHashTable; } const
wxEventTableEntry wxListHeaderWindow::sm_eventTableEntries[]
= {
1694 EVT_PAINT (wxListHeaderWindow::OnPaint)wxEventTableEntry(wxEVT_PAINT, wxID_ANY, wxID_ANY, wxNewEventTableFunctor
(wxEVT_PAINT, wxEventFunctionCast(wxPrivate::DoCast<wxPrivate
::EventArgOf<wxPaintEventFunction>::type>(&wxListHeaderWindow
::OnPaint))), __null),
1695 EVT_MOUSE_EVENTS (wxListHeaderWindow::OnMouse)wxEventTableEntry(wxEVT_LEFT_DOWN, wxID_ANY, wxID_ANY, wxNewEventTableFunctor
(wxEVT_LEFT_DOWN, wxEventFunctionCast(wxPrivate::DoCast<wxPrivate
::EventArgOf<wxMouseEventFunction>::type>(&wxListHeaderWindow
::OnMouse))), __null), wxEventTableEntry(wxEVT_LEFT_UP, wxID_ANY
, wxID_ANY, wxNewEventTableFunctor(wxEVT_LEFT_UP, wxEventFunctionCast
(wxPrivate::DoCast<wxPrivate::EventArgOf<wxMouseEventFunction
>::type>(&wxListHeaderWindow::OnMouse))), __null), wxEventTableEntry
(wxEVT_LEFT_DCLICK, wxID_ANY, wxID_ANY, wxNewEventTableFunctor
(wxEVT_LEFT_DCLICK, wxEventFunctionCast(wxPrivate::DoCast<
wxPrivate::EventArgOf<wxMouseEventFunction>::type>(&
wxListHeaderWindow::OnMouse))), __null), wxEventTableEntry(wxEVT_MIDDLE_DOWN
, wxID_ANY, wxID_ANY, wxNewEventTableFunctor(wxEVT_MIDDLE_DOWN
, wxEventFunctionCast(wxPrivate::DoCast<wxPrivate::EventArgOf
<wxMouseEventFunction>::type>(&wxListHeaderWindow
::OnMouse))), __null), wxEventTableEntry(wxEVT_MIDDLE_UP, wxID_ANY
, wxID_ANY, wxNewEventTableFunctor(wxEVT_MIDDLE_UP, wxEventFunctionCast
(wxPrivate::DoCast<wxPrivate::EventArgOf<wxMouseEventFunction
>::type>(&wxListHeaderWindow::OnMouse))), __null), wxEventTableEntry
(wxEVT_MIDDLE_DCLICK, wxID_ANY, wxID_ANY, wxNewEventTableFunctor
(wxEVT_MIDDLE_DCLICK, wxEventFunctionCast(wxPrivate::DoCast<
wxPrivate::EventArgOf<wxMouseEventFunction>::type>(&
wxListHeaderWindow::OnMouse))), __null), wxEventTableEntry(wxEVT_RIGHT_DOWN
, wxID_ANY, wxID_ANY, wxNewEventTableFunctor(wxEVT_RIGHT_DOWN
, wxEventFunctionCast(wxPrivate::DoCast<wxPrivate::EventArgOf
<wxMouseEventFunction>::type>(&wxListHeaderWindow
::OnMouse))), __null), wxEventTableEntry(wxEVT_RIGHT_UP, wxID_ANY
, wxID_ANY, wxNewEventTableFunctor(wxEVT_RIGHT_UP, wxEventFunctionCast
(wxPrivate::DoCast<wxPrivate::EventArgOf<wxMouseEventFunction
>::type>(&wxListHeaderWindow::OnMouse))), __null), wxEventTableEntry
(wxEVT_RIGHT_DCLICK, wxID_ANY, wxID_ANY, wxNewEventTableFunctor
(wxEVT_RIGHT_DCLICK, wxEventFunctionCast(wxPrivate::DoCast<
wxPrivate::EventArgOf<wxMouseEventFunction>::type>(&
wxListHeaderWindow::OnMouse))), __null), wxEventTableEntry(wxEVT_AUX1_DOWN
, wxID_ANY, wxID_ANY, wxNewEventTableFunctor(wxEVT_AUX1_DOWN,
wxEventFunctionCast(wxPrivate::DoCast<wxPrivate::EventArgOf
<wxMouseEventFunction>::type>(&wxListHeaderWindow
::OnMouse))), __null), wxEventTableEntry(wxEVT_AUX1_UP, wxID_ANY
, wxID_ANY, wxNewEventTableFunctor(wxEVT_AUX1_UP, wxEventFunctionCast
(wxPrivate::DoCast<wxPrivate::EventArgOf<wxMouseEventFunction
>::type>(&wxListHeaderWindow::OnMouse))), __null), wxEventTableEntry
(wxEVT_AUX1_DCLICK, wxID_ANY, wxID_ANY, wxNewEventTableFunctor
(wxEVT_AUX1_DCLICK, wxEventFunctionCast(wxPrivate::DoCast<
wxPrivate::EventArgOf<wxMouseEventFunction>::type>(&
wxListHeaderWindow::OnMouse))), __null), wxEventTableEntry(wxEVT_AUX2_DOWN
, wxID_ANY, wxID_ANY, wxNewEventTableFunctor(wxEVT_AUX2_DOWN,
wxEventFunctionCast(wxPrivate::DoCast<wxPrivate::EventArgOf
<wxMouseEventFunction>::type>(&wxListHeaderWindow
::OnMouse))), __null), wxEventTableEntry(wxEVT_AUX2_UP, wxID_ANY
, wxID_ANY, wxNewEventTableFunctor(wxEVT_AUX2_UP, wxEventFunctionCast
(wxPrivate::DoCast<wxPrivate::EventArgOf<wxMouseEventFunction
>::type>(&wxListHeaderWindow::OnMouse))), __null), wxEventTableEntry
(wxEVT_AUX2_DCLICK, wxID_ANY, wxID_ANY, wxNewEventTableFunctor
(wxEVT_AUX2_DCLICK, wxEventFunctionCast(wxPrivate::DoCast<
wxPrivate::EventArgOf<wxMouseEventFunction>::type>(&
wxListHeaderWindow::OnMouse))), __null), wxEventTableEntry(wxEVT_MOTION
, wxID_ANY, wxID_ANY, wxNewEventTableFunctor(wxEVT_MOTION, wxEventFunctionCast
(wxPrivate::DoCast<wxPrivate::EventArgOf<wxMouseEventFunction
>::type>(&wxListHeaderWindow::OnMouse))), __null), wxEventTableEntry
(wxEVT_LEAVE_WINDOW, wxID_ANY, wxID_ANY, wxNewEventTableFunctor
(wxEVT_LEAVE_WINDOW, wxEventFunctionCast(wxPrivate::DoCast<
wxPrivate::EventArgOf<wxMouseEventFunction>::type>(&
wxListHeaderWindow::OnMouse))), __null), wxEventTableEntry(wxEVT_ENTER_WINDOW
, wxID_ANY, wxID_ANY, wxNewEventTableFunctor(wxEVT_ENTER_WINDOW
, wxEventFunctionCast(wxPrivate::DoCast<wxPrivate::EventArgOf
<wxMouseEventFunction>::type>(&wxListHeaderWindow
::OnMouse))), __null), wxEventTableEntry(wxEVT_MOUSEWHEEL, wxID_ANY
, wxID_ANY, wxNewEventTableFunctor(wxEVT_MOUSEWHEEL, wxEventFunctionCast
(wxPrivate::DoCast<wxPrivate::EventArgOf<wxMouseEventFunction
>::type>(&wxListHeaderWindow::OnMouse))), __null), wxEventTableEntry
(wxEVT_MAGNIFY, wxID_ANY, wxID_ANY, wxNewEventTableFunctor(wxEVT_MAGNIFY
, wxEventFunctionCast(wxPrivate::DoCast<wxPrivate::EventArgOf
<wxMouseEventFunction>::type>(&wxListHeaderWindow
::OnMouse))), __null),
1696 EVT_SET_FOCUS (wxListHeaderWindow::OnSetFocus)wxEventTableEntry(wxEVT_SET_FOCUS, wxID_ANY, wxID_ANY, wxNewEventTableFunctor
(wxEVT_SET_FOCUS, wxEventFunctionCast(wxPrivate::DoCast<wxPrivate
::EventArgOf<wxFocusEventFunction>::type>(&wxListHeaderWindow
::OnSetFocus))), __null),
1697END_EVENT_TABLE()wxEventTableEntry(wxEVT_NULL, 0, 0, __null, __null) };
1698
1699void wxListHeaderWindow::Init()
1700{
1701 m_currentCursor = (wxCursor *) NULL__null;
1702 m_isDragging = false;
1703 m_dirty = false;
1704}
1705
1706wxListHeaderWindow::wxListHeaderWindow()
1707{
1708 Init();
1709
1710 m_owner = (wxListMainWindow *) NULL__null;
1711 m_resizeCursor = (wxCursor *) NULL__null;
1712}
1713
1714wxListHeaderWindow::wxListHeaderWindow( wxWindow *win,
1715 wxWindowID id,
1716 wxListMainWindow *owner,
1717 const wxPoint& pos,
1718 const wxSize& size,
1719 long style,
1720 const wxString &name )
1721 : wxWindow( win, id, pos, size, style, name )
1722{
1723 Init();
1724
1725 m_owner = owner;
1726 m_resizeCursor = new wxCursor( wxCURSOR_SIZEWE );
1727
1728#if _USE_VISATTR0
1729 wxVisualAttributes attr = wxPanel::GetClassDefaultAttributes();
1730 SetOwnForegroundColour( attr.colFg );
1731 SetOwnBackgroundColour( attr.colBg );
1732 if (!m_hasFont)
1733 SetOwnFont( attr.font );
1734#else
1735 SetOwnForegroundColour( wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT));
1736 SetOwnBackgroundColour( wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE));
1737 if (!m_hasFont)
1738 SetOwnFont( wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT ));
1739#endif
1740}
1741
1742wxListHeaderWindow::~wxListHeaderWindow()
1743{
1744 delete m_resizeCursor;
1745}
1746
1747#ifdef __WXUNIVERSAL__
1748#include <wx/univ/renderer.h>
1749#include <wx/univ/theme.h>
1750#endif
1751
1752// shift the DC origin to match the position of the main window horz
1753// scrollbar: this allows us to always use logical coords
1754void wxListHeaderWindow::AdjustDC(wxDC& dc)
1755{
1756 int xpix;
1757 m_owner->GetScrollPixelsPerUnit( &xpix, NULL__null );
1758
1759 int view_start;
1760 m_owner->GetViewStart( &view_start, NULL__null );
1761
1762
1763 int org_x = 0;
1764 int org_y = 0;
1765 dc.GetDeviceOrigin( &org_x, &org_y );
1766
1767 // account for the horz scrollbar offset
1768#ifdef __WXGTK__1
1769 if (GetLayoutDirection() == wxLayout_RightToLeft)
1770 {
1771 // Maybe we just have to check for m_signX
1772 // in the DC, but I leave the #ifdef __WXGTK__
1773 // for now
1774 dc.SetDeviceOrigin( org_x + (view_start * xpix), org_y );
1775 }
1776 else
1777#endif
1778 dc.SetDeviceOrigin( org_x - (view_start * xpix), org_y );
1779}
1780
1781void wxListHeaderWindow::OnPaint( wxPaintEvent &WXUNUSED(event) )
1782{
1783 wxPaintDC dc( this );
1784
1785 PrepareDC( dc );
1786 AdjustDC( dc );
1787
1788 dc.SetFont( GetFont() );
1789
1790 // width and height of the entire header window
1791 int w, h;
1792 GetClientSize( &w, &h );
1793 m_owner->CalcUnscrolledPosition(w, 0, &w, NULL__null);
1794
1795 dc.SetBackgroundMode(wxTRANSPARENT);
1796 dc.SetTextForeground(GetForegroundColour());
1797
1798 int x = HEADER_OFFSET_X;
1799 int numColumns = m_owner->GetColumnCount();
1800 wxListItem item;
1801 for ( int i = 0; i < numColumns && x < w; i++ )
1802 {
1803 m_owner->GetColumn( i, item );
1804 int wCol = item.m_width;
1805
1806 int cw = wCol;
1807 int ch = h;
1808
1809 int flags = 0;
1810 if (!m_parent->IsEnabled())
1811 flags |= wxCONTROL_DISABLED;
1812
1813// NB: The code below is not really Mac-specific, but since we are close
1814// to 2.8 release and I don't have time to test on other platforms, I
1815// defined this only for wxMac. If this behavior is desired on
1816// other platforms, please go ahead and revise or remove the #ifdef.
1817#ifdef __WXMAC__
1818 if ( !m_owner->IsVirtual() && (item.m_mask & wxLIST_MASK_STATE0x0001) &&
1819 (item.m_state & wxLIST_STATE_SELECTED0x0004) )
1820 flags |= wxCONTROL_SELECTED;
1821#endif
1822
1823 wxRendererNative::Get().DrawHeaderButton
1824 (
1825 this,
1826 dc,
1827 wxRect(x, HEADER_OFFSET_Y, cw, ch),
1828 flags
1829 );
1830
1831 // see if we have enough space for the column label
1832
1833 // for this we need the width of the text
1834 wxCoord wLabel;
1835 wxCoord hLabel;
1836 dc.GetTextExtent(item.GetText(), &wLabel, &hLabel);
1837 wLabel += 2 * EXTRA_WIDTH;
1838
1839 // and the width of the icon, if any
1840 int ix = 0, iy = 0; // init them just to suppress the compiler warnings
1841 const int image = item.m_image;
1842 wxImageList *imageList;
1843 if ( image != -1 )
1844 {
1845 imageList = m_owner->m_small_image_list;
1846 if ( imageList )
1847 {
1848 imageList->GetSize(image, ix, iy);
1849 wLabel += ix + HEADER_IMAGE_MARGIN_IN_REPORT_MODE;
1850 }
1851 }
1852 else
1853 {
1854 imageList = NULL__null;
1855 }
1856
1857 // ignore alignment if there is not enough space anyhow
1858 int xAligned;
1859 switch ( wLabel < cw ? item.GetAlign() : wxLIST_FORMAT_LEFT )
1860 {
1861 default:
1862 wxFAIL_MSG( _T("unknown list item format") )do { if ( wxTheAssertHandler && (wxOnAssert("extern/wxWidgets/listctrl.cpp"
, 1862, __FUNCTION__, "\"Assert failure\"", L"unknown list item format"
), wxTrapInAssert) ) { wxTrapInAssert = false; asm volatile (
"int $3"); } } while ( (void)0, 0 )
;
1863 // fall through
1864
1865 case wxLIST_FORMAT_LEFT:
1866 xAligned = x;
1867 break;
1868
1869 case wxLIST_FORMAT_RIGHT:
1870 xAligned = x + cw - wLabel;
1871 break;
1872
1873 case wxLIST_FORMAT_CENTER:
1874 xAligned = x + (cw - wLabel) / 2;
1875 break;
1876 }
1877
1878 // draw the text and image clipping them so that they
1879 // don't overwrite the column boundary
1880 wxDCClipper clipper(dc, x, HEADER_OFFSET_Y, cw, h );
1881
1882 // if we have an image, draw it on the right of the label
1883 if ( imageList )
1884 {
1885 imageList->Draw
1886 (
1887 image,
1888 dc,
1889 xAligned + wLabel - ix - HEADER_IMAGE_MARGIN_IN_REPORT_MODE,
1890 HEADER_OFFSET_Y + (h - 4 - iy)/2,
1891 wxIMAGELIST_DRAW_TRANSPARENT0x0002
1892 );
1893 }
1894
1895 dc.DrawText( item.GetText(),
1896 xAligned + EXTRA_WIDTH, h / 2 - hLabel / 2 ); //HEADER_OFFSET_Y + EXTRA_HEIGHT );
1897
1898 x += wCol;
1899 }
1900
1901 // Fill in what's missing to the right of the columns, otherwise we will
1902 // leave an unpainted area when columns are removed (and it looks better)
1903 if ( x < w )
1904 {
1905 wxRendererNative::Get().DrawHeaderButton
1906 (
1907 this,
1908 dc,
1909 wxRect(x, HEADER_OFFSET_Y, w - x, h),
1910 0
1911 );
1912 }
1913}
1914
1915void wxListHeaderWindow::DrawCurrent()
1916{
1917#if 1
1918 m_owner->SetColumnWidth( m_column, m_currentX - m_minX );
1919#else
1920 int x1 = m_currentX;
1921 int y1 = 0;
1922 m_owner->ClientToScreen( &x1, &y1 );
1923
1924 int x2 = m_currentX;
1925 int y2 = 0;
1926 m_owner->GetClientSize( NULL__null, &y2 );
1927 m_owner->ClientToScreen( &x2, &y2 );
1928
1929 wxScreenDC dc;
1930 dc.SetLogicalFunction( wxINVERT );
1931 dc.SetPen( *(wxThePenList->FindOrCreatePen(*wxBLACKwxStockGDI::GetColour(wxStockGDI::COLOUR_BLACK), 2, wxSOLID ) ));
1932 dc.SetBrush( *wxTRANSPARENT_BRUSHwxStockGDI::GetBrush(wxStockGDI::BRUSH_TRANSPARENT) );
1933
1934 AdjustDC(dc);
1935
1936 dc.DrawLine( x1, y1, x2, y2 );
1937
1938 dc.SetLogicalFunction( wxCOPY );
1939
1940 dc.SetPen( wxNullPen );
1941 dc.SetBrush( wxNullBrush );
1942#endif
1943}
1944
1945void wxListHeaderWindow::OnMouse( wxMouseEvent &event )
1946{
1947 // we want to work with logical coords
1948 int x;
1949 m_owner->CalcUnscrolledPosition(event.GetX(), 0, &x, NULL__null);
1950 int y = event.GetY();
1951
1952 if (m_isDragging)
1953 {
1954 SendListEvent(wxEVT_COMMAND_LIST_COL_DRAGGINGwxEVT_LIST_COL_DRAGGING, event.GetPosition());
1955
1956 // we don't draw the line beyond our window, but we allow dragging it
1957 // there
1958 int w = 0;
1959 GetClientSize( &w, NULL__null );
1960 m_owner->CalcUnscrolledPosition(w, 0, &w, NULL__null);
1961 w -= 6;
1962
1963 // erase the line if it was drawn
1964 if ( m_currentX < w )
1965 DrawCurrent();
1966
1967 if (event.ButtonUp())
1968 {
1969 ReleaseMouse();
1970 m_isDragging = false;
1971 m_dirty = true;
1972 m_owner->SetColumnWidth( m_column, m_currentX - m_minX );
1973 SendListEvent(wxEVT_COMMAND_LIST_COL_END_DRAGwxEVT_LIST_COL_END_DRAG, event.GetPosition());
1974 }
1975 else
1976 {
1977 if (x > m_minX + 7)
1978 m_currentX = x;
1979 else
1980 m_currentX = m_minX + 7;
1981
1982 // draw in the new location
1983 if ( m_currentX < w )
1984 DrawCurrent();
1985 }
1986 }
1987 else // not dragging
1988 {
1989 m_minX = 0;
1990 bool hit_border = false;
1991
1992 // end of the current column
1993 int xpos = 0;
1994
1995 // find the column where this event occurred
1996 int col,
1997 countCol = m_owner->GetColumnCount();
1998 for (col = 0; col < countCol; col++)
1999 {
2000 xpos += m_owner->GetColumnWidth( col );
2001 m_column = col;
2002
2003 if ( (abs(x-xpos) < 3) && (y < 22) )
2004 {
2005 // near the column border
2006 hit_border = true;
2007 break;
2008 }
2009
2010 if ( x < xpos )
2011 {
2012 // inside the column
2013 break;
2014 }
2015
2016 m_minX = xpos;
2017 }
2018
2019 if ( col == countCol )
2020 m_column = -1;
2021
2022 if (event.LeftDown() || event.RightUp())
2023 {
2024 if (hit_border && event.LeftDown())
2025 {
2026 if ( SendListEvent(wxEVT_COMMAND_LIST_COL_BEGIN_DRAGwxEVT_LIST_COL_BEGIN_DRAG,
2027 event.GetPosition()) )
2028 {
2029 m_isDragging = true;
2030 m_currentX = x;
2031 CaptureMouse();
2032 DrawCurrent();
2033 }
2034 //else: column resizing was vetoed by the user code
2035 }
2036 else // click on a column
2037 {
2038 // record the selected state of the columns
2039 if (event.LeftDown())
2040 {
2041 for (int i=0; i < m_owner->GetColumnCount(); i++)
2042 {
2043 wxListItem colItem;
2044 m_owner->GetColumn(i, colItem);
2045 long state = colItem.GetState();
2046 if (i == m_column)
2047 colItem.SetState(state | wxLIST_STATE_SELECTED0x0004);
2048 else
2049 colItem.SetState(state & ~wxLIST_STATE_SELECTED0x0004);
2050 m_owner->SetColumn(i, colItem);
2051 }
2052 }
2053
2054 SendListEvent( event.LeftDown()
2055 ? wxEVT_COMMAND_LIST_COL_CLICKwxEVT_LIST_COL_CLICK
2056 : wxEVT_COMMAND_LIST_COL_RIGHT_CLICKwxEVT_LIST_COL_RIGHT_CLICK,
2057 event.GetPosition());
2058 }
2059 }
2060 else if (event.Moving())
2061 {
2062 bool setCursor;
2063 if (hit_border)
2064 {
2065 setCursor = m_currentCursor == wxSTANDARD_CURSORwxStockGDI::GetCursor(wxStockGDI::CURSOR_STANDARD);
2066 m_currentCursor = m_resizeCursor;
2067 }
2068 else
2069 {
2070 setCursor = m_currentCursor != wxSTANDARD_CURSORwxStockGDI::GetCursor(wxStockGDI::CURSOR_STANDARD);
2071 m_currentCursor = wxSTANDARD_CURSORwxStockGDI::GetCursor(wxStockGDI::CURSOR_STANDARD);
2072 }
2073
2074 if ( setCursor )
2075 SetCursor(*m_currentCursor);
2076 }
2077 }
2078}
2079
2080void wxListHeaderWindow::OnSetFocus( wxFocusEvent &WXUNUSED(event) )
2081{
2082 m_owner->SetFocus();
2083 m_owner->Update();
2084}
2085
2086bool wxListHeaderWindow::SendListEvent(wxEventType type, const wxPoint& pos)
2087{
2088 wxWindow *parent = GetParent();
2089 wxListEvent le( type, parent->GetId() );
2090 le.SetEventObject( parent );
2091 le.m_pointDrag = pos;
2092
2093 // the position should be relative to the parent window, not
2094 // this one for compatibility with MSW and common sense: the
2095 // user code doesn't know anything at all about this header
2096 // window, so why should it get positions relative to it?
2097 le.m_pointDrag.y -= GetSize().y;
2098
2099 le.m_col = m_column;
2100 return !parent->GetEventHandler()->ProcessEvent( le ) || le.IsAllowed();
2101}
2102
2103//-----------------------------------------------------------------------------
2104// wxListRenameTimer (internal)
2105//-----------------------------------------------------------------------------
2106
2107wxListRenameTimer::wxListRenameTimer( wxListMainWindow *owner )
2108{
2109 m_owner = owner;
2110}
2111
2112void wxListRenameTimer::Notify()
2113{
2114 m_owner->OnRenameTimer();
2115}
2116
2117//-----------------------------------------------------------------------------
2118// wxListTextCtrlWrapper (internal)
2119//-----------------------------------------------------------------------------
2120
2121BEGIN_EVENT_TABLE(wxListTextCtrlWrapper, wxEvtHandler)const wxEventTable wxListTextCtrlWrapper::sm_eventTable = { &
wxEvtHandler::sm_eventTable, &wxListTextCtrlWrapper::sm_eventTableEntries
[0] }; const wxEventTable *wxListTextCtrlWrapper::GetEventTable
() const { return &wxListTextCtrlWrapper::sm_eventTable; }
wxEventHashTable wxListTextCtrlWrapper::sm_eventHashTable(wxListTextCtrlWrapper
::sm_eventTable); wxEventHashTable &wxListTextCtrlWrapper
::GetEventHashTable() const { return wxListTextCtrlWrapper::sm_eventHashTable
; } const wxEventTableEntry wxListTextCtrlWrapper::sm_eventTableEntries
[] = {
2122 EVT_CHAR (wxListTextCtrlWrapper::OnChar)wxEventTableEntry(wxEVT_CHAR, wxID_ANY, wxID_ANY, wxNewEventTableFunctor
(wxEVT_CHAR, wxEventFunctionCast(wxPrivate::DoCast<wxPrivate
::EventArgOf<wxCharEventFunction>::type>(&wxListTextCtrlWrapper
::OnChar))), __null),
2123 EVT_KEY_UP (wxListTextCtrlWrapper::OnKeyUp)wxEventTableEntry(wxEVT_KEY_UP, wxID_ANY, wxID_ANY, wxNewEventTableFunctor
(wxEVT_KEY_UP, wxEventFunctionCast(wxPrivate::DoCast<wxPrivate
::EventArgOf<wxCharEventFunction>::type>(&wxListTextCtrlWrapper
::OnKeyUp))), __null),
2124 EVT_KILL_FOCUS (wxListTextCtrlWrapper::OnKillFocus)wxEventTableEntry(wxEVT_KILL_FOCUS, wxID_ANY, wxID_ANY, wxNewEventTableFunctor
(wxEVT_KILL_FOCUS, wxEventFunctionCast(wxPrivate::DoCast<wxPrivate
::EventArgOf<wxFocusEventFunction>::type>(&wxListTextCtrlWrapper
::OnKillFocus))), __null),
2125END_EVENT_TABLE()wxEventTableEntry(wxEVT_NULL, 0, 0, __null, __null) };
2126
2127wxListTextCtrlWrapper::wxListTextCtrlWrapper(wxListMainWindow *owner,
2128 wxTextCtrl *text,
2129 size_t itemEdit)
2130 : m_startValue(owner->GetItemText(itemEdit)),
2131 m_itemEdited(itemEdit)
2132{
2133 m_owner = owner;
2134 m_text = text;
2135 m_finished = false;
2136 m_aboutToFinish = false;
2137
2138 wxRect rectLabel = owner->GetLineLabelRect(itemEdit);
2139
2140 m_owner->CalcScrolledPosition(rectLabel.x, rectLabel.y,
2141 &rectLabel.x, &rectLabel.y);
2142
2143 m_text->Create(owner, wxID_ANY, m_startValue,
2144 wxPoint(rectLabel.x-4,rectLabel.y-4),
2145 wxSize(rectLabel.width+11,rectLabel.height+8));
2146 m_text->SetFocus();
2147
2148 m_text->PushEventHandler(this);
2149}
2150
2151void wxListTextCtrlWrapper::Finish()
2152{
2153 if ( !m_finished )
2154 {
2155 m_finished = true;
2156
2157 m_text->RemoveEventHandler(this);
2158 m_owner->FinishEditing(m_text);
2159
2160 wxPendingDelete.Append( this );
2161 }
2162}
2163
2164bool wxListTextCtrlWrapper::AcceptChanges()
2165{
2166 const wxString value = m_text->GetValue();
2167
2168 // notice that we should always call OnRenameAccept() to generate the "end
2169 // label editing" event, even if the user hasn't really changed anything
2170 if ( !m_owner->OnRenameAccept(m_itemEdited, value) )
2171 {
2172 // vetoed by the user
2173 return false;
2174 }
2175
2176 // accepted, do rename the item (unless nothing changed)
2177 if ( value != m_startValue )
2178 m_owner->SetItemText(m_itemEdited, value);
2179
2180 return true;
2181}
2182
2183void wxListTextCtrlWrapper::AcceptChangesAndFinish()
2184{
2185 m_aboutToFinish = true;
2186
2187 // Notify the owner about the changes
2188 AcceptChanges();
2189
2190 // Even if vetoed, close the control (consistent with MSW)
2191 Finish();
2192}
2193
2194void wxListTextCtrlWrapper::OnChar( wxKeyEvent &event )
2195{
2196 switch ( event.m_keyCode )
2197 {
2198 case WXK_RETURN:
2199 AcceptChangesAndFinish();
2200 break;
2201
2202 case WXK_ESCAPE:
2203 m_owner->OnRenameCancelled( m_itemEdited );
2204 Finish();
2205 break;
2206
2207 default:
2208 event.Skip();
2209 }
2210}
2211
2212void wxListTextCtrlWrapper::OnKeyUp( wxKeyEvent &event )
2213{
2214 if (m_finished)
2215 {
2216 event.Skip();
2217 return;
2218 }
2219
2220 // auto-grow the textctrl:
2221 wxSize parentSize = m_owner->GetSize();
2222 wxPoint myPos = m_text->GetPosition();
2223 wxSize mySize = m_text->GetSize();
2224 int sx, sy;
2225 m_text->GetTextExtent(m_text->GetValue() + _T("MM")L"MM", &sx, &sy);
2226 if (myPos.x + sx > parentSize.x)
2227 sx = parentSize.x - myPos.x;
2228 if (mySize.x > sx)
2229 sx = mySize.x;
2230 m_text->SetSize(sx, wxDefaultCoord);
2231
2232 event.Skip();
2233}
2234
2235void wxListTextCtrlWrapper::OnKillFocus( wxFocusEvent &event )
2236{
2237 if ( !m_finished && !m_aboutToFinish )
2238 {
2239 if ( !AcceptChanges() )
2240 m_owner->OnRenameCancelled( m_itemEdited );
2241
2242 Finish();
2243 }
2244
2245 // We must let the native text control handle focus
2246 event.Skip();
2247}
2248
2249//-----------------------------------------------------------------------------
2250// wxListMainWindow
2251//-----------------------------------------------------------------------------
2252
2253BEGIN_EVENT_TABLE(wxListMainWindow,wxScrolledWindow)const wxEventTable wxListMainWindow::sm_eventTable = { &wxScrolledWindow
::sm_eventTable, &wxListMainWindow::sm_eventTableEntries[
0] }; const wxEventTable *wxListMainWindow::GetEventTable() const
{ return &wxListMainWindow::sm_eventTable; } wxEventHashTable
wxListMainWindow::sm_eventHashTable(wxListMainWindow::sm_eventTable
); wxEventHashTable &wxListMainWindow::GetEventHashTable(
) const { return wxListMainWindow::sm_eventHashTable; } const
wxEventTableEntry wxListMainWindow::sm_eventTableEntries[] =
{
2254 EVT_PAINT (wxListMainWindow::OnPaint)wxEventTableEntry(wxEVT_PAINT, wxID_ANY, wxID_ANY, wxNewEventTableFunctor
(wxEVT_PAINT, wxEventFunctionCast(wxPrivate::DoCast<wxPrivate
::EventArgOf<wxPaintEventFunction>::type>(&wxListMainWindow
::OnPaint))), __null),
2255 EVT_ERASE_BACKGROUND (wxListMainWindow::OnErase)wxEventTableEntry(wxEVT_ERASE_BACKGROUND, wxID_ANY, wxID_ANY,
wxNewEventTableFunctor(wxEVT_ERASE_BACKGROUND, wxEventFunctionCast
(wxPrivate::DoCast<wxPrivate::EventArgOf<wxEraseEventFunction
>::type>(&wxListMainWindow::OnErase))), __null),
2256 EVT_MOUSE_EVENTS (wxListMainWindow::OnMouse)wxEventTableEntry(wxEVT_LEFT_DOWN, wxID_ANY, wxID_ANY, wxNewEventTableFunctor
(wxEVT_LEFT_DOWN, wxEventFunctionCast(wxPrivate::DoCast<wxPrivate
::EventArgOf<wxMouseEventFunction>::type>(&wxListMainWindow
::OnMouse))), __null), wxEventTableEntry(wxEVT_LEFT_UP, wxID_ANY
, wxID_ANY, wxNewEventTableFunctor(wxEVT_LEFT_UP, wxEventFunctionCast
(wxPrivate::DoCast<wxPrivate::EventArgOf<wxMouseEventFunction
>::type>(&wxListMainWindow::OnMouse))), __null), wxEventTableEntry
(wxEVT_LEFT_DCLICK, wxID_ANY, wxID_ANY, wxNewEventTableFunctor
(wxEVT_LEFT_DCLICK, wxEventFunctionCast(wxPrivate::DoCast<
wxPrivate::EventArgOf<wxMouseEventFunction>::type>(&
wxListMainWindow::OnMouse))), __null), wxEventTableEntry(wxEVT_MIDDLE_DOWN
, wxID_ANY, wxID_ANY, wxNewEventTableFunctor(wxEVT_MIDDLE_DOWN
, wxEventFunctionCast(wxPrivate::DoCast<wxPrivate::EventArgOf
<wxMouseEventFunction>::type>(&wxListMainWindow::
OnMouse))), __null), wxEventTableEntry(wxEVT_MIDDLE_UP, wxID_ANY
, wxID_ANY, wxNewEventTableFunctor(wxEVT_MIDDLE_UP, wxEventFunctionCast
(wxPrivate::DoCast<wxPrivate::EventArgOf<wxMouseEventFunction
>::type>(&wxListMainWindow::OnMouse))), __null), wxEventTableEntry
(wxEVT_MIDDLE_DCLICK, wxID_ANY, wxID_ANY, wxNewEventTableFunctor
(wxEVT_MIDDLE_DCLICK, wxEventFunctionCast(wxPrivate::DoCast<
wxPrivate::EventArgOf<wxMouseEventFunction>::type>(&
wxListMainWindow::OnMouse))), __null), wxEventTableEntry(wxEVT_RIGHT_DOWN
, wxID_ANY, wxID_ANY, wxNewEventTableFunctor(wxEVT_RIGHT_DOWN
, wxEventFunctionCast(wxPrivate::DoCast<wxPrivate::EventArgOf
<wxMouseEventFunction>::type>(&wxListMainWindow::
OnMouse))), __null), wxEventTableEntry(wxEVT_RIGHT_UP, wxID_ANY
, wxID_ANY, wxNewEventTableFunctor(wxEVT_RIGHT_UP, wxEventFunctionCast
(wxPrivate::DoCast<wxPrivate::EventArgOf<wxMouseEventFunction
>::type>(&wxListMainWindow::OnMouse))), __null), wxEventTableEntry
(wxEVT_RIGHT_DCLICK, wxID_ANY, wxID_ANY, wxNewEventTableFunctor
(wxEVT_RIGHT_DCLICK, wxEventFunctionCast(wxPrivate::DoCast<
wxPrivate::EventArgOf<wxMouseEventFunction>::type>(&
wxListMainWindow::OnMouse))), __null), wxEventTableEntry(wxEVT_AUX1_DOWN
, wxID_ANY, wxID_ANY, wxNewEventTableFunctor(wxEVT_AUX1_DOWN,
wxEventFunctionCast(wxPrivate::DoCast<wxPrivate::EventArgOf
<wxMouseEventFunction>::type>(&wxListMainWindow::
OnMouse))), __null), wxEventTableEntry(wxEVT_AUX1_UP, wxID_ANY
, wxID_ANY, wxNewEventTableFunctor(wxEVT_AUX1_UP, wxEventFunctionCast
(wxPrivate::DoCast<wxPrivate::EventArgOf<wxMouseEventFunction
>::type>(&wxListMainWindow::OnMouse))), __null), wxEventTableEntry
(wxEVT_AUX1_DCLICK, wxID_ANY, wxID_ANY, wxNewEventTableFunctor
(wxEVT_AUX1_DCLICK, wxEventFunctionCast(wxPrivate::DoCast<
wxPrivate::EventArgOf<wxMouseEventFunction>::type>(&
wxListMainWindow::OnMouse))), __null), wxEventTableEntry(wxEVT_AUX2_DOWN
, wxID_ANY, wxID_ANY, wxNewEventTableFunctor(wxEVT_AUX2_DOWN,
wxEventFunctionCast(wxPrivate::DoCast<wxPrivate::EventArgOf
<wxMouseEventFunction>::type>(&wxListMainWindow::
OnMouse))), __null), wxEventTableEntry(wxEVT_AUX2_UP, wxID_ANY
, wxID_ANY, wxNewEventTableFunctor(wxEVT_AUX2_UP, wxEventFunctionCast
(wxPrivate::DoCast<wxPrivate::EventArgOf<wxMouseEventFunction
>::type>(&wxListMainWindow::OnMouse))), __null), wxEventTableEntry
(wxEVT_AUX2_DCLICK, wxID_ANY, wxID_ANY, wxNewEventTableFunctor
(wxEVT_AUX2_DCLICK, wxEventFunctionCast(wxPrivate::DoCast<
wxPrivate::EventArgOf<wxMouseEventFunction>::type>(&
wxListMainWindow::OnMouse))), __null), wxEventTableEntry(wxEVT_MOTION
, wxID_ANY, wxID_ANY, wxNewEventTableFunctor(wxEVT_MOTION, wxEventFunctionCast
(wxPrivate::DoCast<wxPrivate::EventArgOf<wxMouseEventFunction
>::type>(&wxListMainWindow::OnMouse))), __null), wxEventTableEntry
(wxEVT_LEAVE_WINDOW, wxID_ANY, wxID_ANY, wxNewEventTableFunctor
(wxEVT_LEAVE_WINDOW, wxEventFunctionCast(wxPrivate::DoCast<
wxPrivate::EventArgOf<wxMouseEventFunction>::type>(&
wxListMainWindow::OnMouse))), __null), wxEventTableEntry(wxEVT_ENTER_WINDOW
, wxID_ANY, wxID_ANY, wxNewEventTableFunctor(wxEVT_ENTER_WINDOW
, wxEventFunctionCast(wxPrivate::DoCast<wxPrivate::EventArgOf
<wxMouseEventFunction>::type>(&wxListMainWindow::
OnMouse))), __null), wxEventTableEntry(wxEVT_MOUSEWHEEL, wxID_ANY
, wxID_ANY, wxNewEventTableFunctor(wxEVT_MOUSEWHEEL, wxEventFunctionCast
(wxPrivate::DoCast<wxPrivate::EventArgOf<wxMouseEventFunction
>::type>(&wxListMainWindow::OnMouse))), __null), wxEventTableEntry
(wxEVT_MAGNIFY, wxID_ANY, wxID_ANY, wxNewEventTableFunctor(wxEVT_MAGNIFY
, wxEventFunctionCast(wxPrivate::DoCast<wxPrivate::EventArgOf
<wxMouseEventFunction>::type>(&wxListMainWindow::
OnMouse))), __null),
2257 EVT_CHAR (wxListMainWindow::OnChar)wxEventTableEntry(wxEVT_CHAR, wxID_ANY, wxID_ANY, wxNewEventTableFunctor
(wxEVT_CHAR, wxEventFunctionCast(wxPrivate::DoCast<wxPrivate
::EventArgOf<wxCharEventFunction>::type>(&wxListMainWindow
::OnChar))), __null),
2258 EVT_KEY_DOWN (wxListMainWindow::OnKeyDown)wxEventTableEntry(wxEVT_KEY_DOWN, wxID_ANY, wxID_ANY, wxNewEventTableFunctor
(wxEVT_KEY_DOWN, wxEventFunctionCast(wxPrivate::DoCast<wxPrivate
::EventArgOf<wxCharEventFunction>::type>(&wxListMainWindow
::OnKeyDown))), __null),
2259 EVT_KEY_UP (wxListMainWindow::OnKeyUp)wxEventTableEntry(wxEVT_KEY_UP, wxID_ANY, wxID_ANY, wxNewEventTableFunctor
(wxEVT_KEY_UP, wxEventFunctionCast(wxPrivate::DoCast<wxPrivate
::EventArgOf<wxCharEventFunction>::type>(&wxListMainWindow
::OnKeyUp))), __null),
2260 EVT_SET_FOCUS (wxListMainWindow::OnSetFocus)wxEventTableEntry(wxEVT_SET_FOCUS, wxID_ANY, wxID_ANY, wxNewEventTableFunctor
(wxEVT_SET_FOCUS, wxEventFunctionCast(wxPrivate::DoCast<wxPrivate
::EventArgOf<wxFocusEventFunction>::type>(&wxListMainWindow
::OnSetFocus))), __null),
2261 EVT_KILL_FOCUS (wxListMainWindow::OnKillFocus)wxEventTableEntry(wxEVT_KILL_FOCUS, wxID_ANY, wxID_ANY, wxNewEventTableFunctor
(wxEVT_KILL_FOCUS, wxEventFunctionCast(wxPrivate::DoCast<wxPrivate
::EventArgOf<wxFocusEventFunction>::type>(&wxListMainWindow
::OnKillFocus))), __null),
2262 EVT_SCROLLWIN (wxListMainWindow::OnScroll)wxEventTableEntry(wxEVT_SCROLLWIN_TOP, wxID_ANY, wxID_ANY, wxNewEventTableFunctor
(wxEVT_SCROLLWIN_TOP, wxEventFunctionCast(wxPrivate::DoCast<
wxPrivate::EventArgOf<wxScrollWinEventFunction>::type>
(&wxListMainWindow::OnScroll))), __null), wxEventTableEntry
(wxEVT_SCROLLWIN_BOTTOM, wxID_ANY, wxID_ANY, wxNewEventTableFunctor
(wxEVT_SCROLLWIN_BOTTOM, wxEventFunctionCast(wxPrivate::DoCast
<wxPrivate::EventArgOf<wxScrollWinEventFunction>::type
>(&wxListMainWindow::OnScroll))), __null), wxEventTableEntry
(wxEVT_SCROLLWIN_LINEUP, wxID_ANY, wxID_ANY, wxNewEventTableFunctor
(wxEVT_SCROLLWIN_LINEUP, wxEventFunctionCast(wxPrivate::DoCast
<wxPrivate::EventArgOf<wxScrollWinEventFunction>::type
>(&wxListMainWindow::OnScroll))), __null), wxEventTableEntry
(wxEVT_SCROLLWIN_LINEDOWN, wxID_ANY, wxID_ANY, wxNewEventTableFunctor
(wxEVT_SCROLLWIN_LINEDOWN, wxEventFunctionCast(wxPrivate::DoCast
<wxPrivate::EventArgOf<wxScrollWinEventFunction>::type
>(&wxListMainWindow::OnScroll))), __null), wxEventTableEntry
(wxEVT_SCROLLWIN_PAGEUP, wxID_ANY, wxID_ANY, wxNewEventTableFunctor
(wxEVT_SCROLLWIN_PAGEUP, wxEventFunctionCast(wxPrivate::DoCast
<wxPrivate::EventArgOf<wxScrollWinEventFunction>::type
>(&wxListMainWindow::OnScroll))), __null), wxEventTableEntry
(wxEVT_SCROLLWIN_PAGEDOWN, wxID_ANY, wxID_ANY, wxNewEventTableFunctor
(wxEVT_SCROLLWIN_PAGEDOWN, wxEventFunctionCast(wxPrivate::DoCast
<wxPrivate::EventArgOf<wxScrollWinEventFunction>::type
>(&wxListMainWindow::OnScroll))), __null), wxEventTableEntry
(wxEVT_SCROLLWIN_THUMBTRACK, wxID_ANY, wxID_ANY, wxNewEventTableFunctor
(wxEVT_SCROLLWIN_THUMBTRACK, wxEventFunctionCast(wxPrivate::DoCast
<wxPrivate::EventArgOf<wxScrollWinEventFunction>::type
>(&wxListMainWindow::OnScroll))), __null), wxEventTableEntry
(wxEVT_SCROLLWIN_THUMBRELEASE, wxID_ANY, wxID_ANY, wxNewEventTableFunctor
(wxEVT_SCROLLWIN_THUMBRELEASE, wxEventFunctionCast(wxPrivate::
DoCast<wxPrivate::EventArgOf<wxScrollWinEventFunction>
::type>(&wxListMainWindow::OnScroll))), __null),
2263 EVT_CHILD_FOCUS (wxListMainWindow::OnChildFocus)wxEventTableEntry(wxEVT_CHILD_FOCUS, wxID_ANY, wxID_ANY, wxNewEventTableFunctor
(wxEVT_CHILD_FOCUS, wxEventFunctionCast(wxPrivate::DoCast<
wxPrivate::EventArgOf<wxChildFocusEventFunction>::type>
(&wxListMainWindow::OnChildFocus))), __null),
2264END_EVENT_TABLE()wxEventTableEntry(wxEVT_NULL, 0, 0, __null, __null) };
2265
2266void wxListMainWindow::Init()
2267{
2268 m_dirty = true;
2269 m_countVirt = 0;
2270 m_lineFrom =
2271 m_lineTo = (size_t)-1;
2272 m_linesPerPage = 0;
2273
2274 m_headerWidth =
2275 m_lineHeight = 0;
2276
2277 m_small_image_list = (wxImageList *) NULL__null;
2278 m_normal_image_list = (wxImageList *) NULL__null;
2279
2280 m_small_spacing = 30;
2281 m_normal_spacing = 40;
2282
2283 m_hasFocus = false;
2284 m_dragCount = 0;
2285 m_isCreated = false;
2286
2287 m_lastOnSame = false;
2288 m_renameTimer = new wxListRenameTimer( this );
2289 m_textctrlWrapper = NULL__null;
2290
2291 m_current =
2292 m_lineLastClicked =
2293 m_lineSelectSingleOnUp =
2294 m_lineBeforeLastClicked = (size_t)-1;
2295
2296 m_freezeCount = 0;
2297}
2298
2299wxListMainWindow::wxListMainWindow()
2300{
2301 Init();
2302}
2303
2304wxListMainWindow::wxListMainWindow( wxWindow *parent,
2305 wxWindowID id,
2306 const wxPoint& pos,
2307 const wxSize& size,
2308 long style,
2309 const wxString &name )
2310 : wxScrolledWindow( parent, id, pos, size,
2311 style | wxHSCROLL0x40000000 | wxVSCROLL((int)0x80000000), name )
2312{
2313 Init();
2314
2315 m_highlightBrush = *(wxTheBrushList->FindOrCreateBrush(
2316 wxSystemSettings::GetColour
2317 (
2318 wxSYS_COLOUR_HIGHLIGHT
2319 ),
2320 wxBRUSHSTYLE_SOLID
2321 ));
2322
2323 m_highlightUnfocusedBrush = *(wxTheBrushList->FindOrCreateBrush(
2324 wxSystemSettings::GetColour
2325 (
2326 wxSYS_COLOUR_BTNSHADOW
2327 ),
2328 wxBRUSHSTYLE_SOLID
2329 ));
2330
2331 SetScrollbars( 0, 0, 0, 0, 0, 0 );
2332
2333 wxVisualAttributes attr = wxGenericListCtrl::GetClassDefaultAttributes();
2334 SetOwnForegroundColour( attr.colFg );
2335 SetOwnBackgroundColour( attr.colBg );
2336 if (!m_hasFont)
2337 SetOwnFont( attr.font );
2338}
2339
2340wxListMainWindow::~wxListMainWindow()
2341{
2342 DoDeleteAllItems();
2343 WX_CLEAR_LIST(wxListHeaderDataList, m_columns){ wxListHeaderDataList::iterator it, en; for( it = (m_columns
).begin(), en = (m_columns).end(); it != en; ++it ) delete *it
; (m_columns).clear(); }
;
2344 WX_CLEAR_ARRAY(m_aColWidths);
2345
2346 delete m_renameTimer;
2347}
2348
2349void wxListMainWindow::CacheLineData(size_t line)
2350{
2351 wxGenericListCtrl *listctrl = GetListCtrl();
2352
2353 wxListLineData *ld = GetDummyLine();
2354
2355 size_t countCol = GetColumnCount();
2356 for ( size_t col = 0; col < countCol; col++ )
2357 {
2358 ld->SetText(col, listctrl->OnGetItemText(line, col));
2359 ld->SetImage(col, listctrl->OnGetItemColumnImage(line, col));
2360 }
2361
2362 ld->SetAttr(listctrl->OnGetItemAttr(line));
2363}
2364
2365wxListLineData *wxListMainWindow::GetDummyLine() const
2366{
2367 wxASSERT_MSG( !IsEmpty(), _T("invalid line index") )do { if ( !IsEmpty() ) { } else if ( wxTheAssertHandler &&
(wxOnAssert("extern/wxWidgets/listctrl.cpp", 2367, __FUNCTION__
, "!IsEmpty()", L"invalid line index"), wxTrapInAssert) ) { wxTrapInAssert
= false; asm volatile ("int $3"); } } while ( (void)0, 0 )
;
2368 wxASSERT_MSG( IsVirtual(), _T("GetDummyLine() shouldn't be called") )do { if ( IsVirtual() ) { } else if ( wxTheAssertHandler &&
(wxOnAssert("extern/wxWidgets/listctrl.cpp", 2368, __FUNCTION__
, "IsVirtual()", L"GetDummyLine() shouldn't be called"), wxTrapInAssert
) ) { wxTrapInAssert = false; asm volatile ("int $3"); } } while
( (void)0, 0 )
;
2369
2370 wxListMainWindow *self = wxConstCast(this, wxListMainWindow)const_cast<wxListMainWindow *>(this);
2371
2372 // we need to recreate the dummy line if the number of columns in the
2373 // control changed as it would have the incorrect number of fields
2374 // otherwise
2375 if ( !m_lines.IsEmpty() &&
2376 m_lines[0].m_items.GetCount() != (size_t)GetColumnCount() )
2377 {
2378 self->m_lines.Clear();
2379 }
2380
2381 if ( m_lines.IsEmpty() )
2382 {
2383 wxListLineData *line = new wxListLineData(self);
2384 self->m_lines.Add(line);
2385
2386 // don't waste extra memory -- there never going to be anything
2387 // else/more in this array
2388 self->m_lines.Shrink();
2389 }
2390
2391 return &m_lines[0];
2392}
2393
2394// ----------------------------------------------------------------------------
2395// line geometry (report mode only)
2396// ----------------------------------------------------------------------------
2397
2398wxCoord wxListMainWindow::GetLineHeight() const
2399{
2400 // we cache the line height as calling GetTextExtent() is slow
2401 if ( !m_lineHeight )
2402 {
2403 wxListMainWindow *self = wxConstCast(this, wxListMainWindow)const_cast<wxListMainWindow *>(this);
2404
2405 wxClientDC dc( self );
2406 dc.SetFont( GetFont() );
2407
2408 wxCoord y;
2409 dc.GetTextExtent(_T("H")L"H", NULL__null, &y);
2410
2411 if ( m_small_image_list && m_small_image_list->GetImageCount() )
2412 {
2413 int iw = 0, ih = 0;
2414 m_small_image_list->GetSize(0, iw, ih);
2415 y = wxMax(y, ih);
2416 }
2417
2418 y += EXTRA_HEIGHT;
2419 self->m_lineHeight = y + LINE_SPACING;
2420 }
2421
2422 return m_lineHeight;
2423}
2424
2425wxCoord wxListMainWindow::GetLineY(size_t line) const
2426{
2427 wxASSERT_MSG( InReportView(), _T("only works in report mode") )do { if ( InReportView() ) { } else if ( wxTheAssertHandler &&
(wxOnAssert("extern/wxWidgets/listctrl.cpp", 2427, __FUNCTION__
, "InReportView()", L"only works in report mode"), wxTrapInAssert
) ) { wxTrapInAssert = false; asm volatile ("int $3"); } } while
( (void)0, 0 )
;
2428
2429 return LINE_SPACING + line * GetLineHeight();
2430}
2431
2432wxRect wxListMainWindow::GetLineRect(size_t line) const
2433{
2434 if ( !InReportView() )
2435 return GetLine(line)->m_gi->m_rectAll;
2436
2437 wxRect rect;
2438 rect.x = HEADER_OFFSET_X;
2439 rect.y = GetLineY(line);
2440 rect.width = GetHeaderWidth();
2441 rect.height = GetLineHeight();
2442
2443 return rect;
2444}
2445
2446wxRect wxListMainWindow::GetLineLabelRect(size_t line) const
2447{
2448 if ( !InReportView() )
2449 return GetLine(line)->m_gi->m_rectLabel;
2450
2451 int image_x = 0;
2452 wxListLineData *data = GetLine(line);
2453 wxListItemDataList::compatibility_iterator node = data->m_items.GetFirst();
2454 if (node)
2455 {
2456 wxListItemData *item = node->GetData();
2457 if ( item->HasImage() )
2458 {
2459 int ix, iy;
2460 GetImageSize( item->GetImage(), ix, iy );
2461 image_x = 3 + ix + IMAGE_MARGIN_IN_REPORT_MODE;
2462 }
2463 }
2464
2465 wxRect rect;
2466 rect.x = image_x + HEADER_OFFSET_X;
2467 rect.y = GetLineY(line);
2468 rect.width = GetColumnWidth(0) - image_x;
2469 rect.height = GetLineHeight();
2470
2471 return rect;
2472}
2473
2474wxRect wxListMainWindow::GetLineIconRect(size_t line) const
2475{
2476 if ( !InReportView() )
2477 return GetLine(line)->m_gi->m_rectIcon;
2478
2479 wxListLineData *ld = GetLine(line);
2480 wxASSERT_MSG( ld->HasImage(), _T("should have an image") )do { if ( ld->HasImage() ) { } else if ( wxTheAssertHandler
&& (wxOnAssert("extern/wxWidgets/listctrl.cpp", 2480
, __FUNCTION__, "ld->HasImage()", L"should have an image")
, wxTrapInAssert) ) { wxTrapInAssert = false; asm volatile ("int $3"
); } } while ( (void)0, 0 )
;
2481
2482 wxRect rect;
2483 rect.x = HEADER_OFFSET_X;
2484 rect.y = GetLineY(line);
2485 GetImageSize(ld->GetImage(), rect.width, rect.height);
2486
2487 return rect;
2488}
2489
2490wxRect wxListMainWindow::GetLineHighlightRect(size_t line) const
2491{
2492 return InReportView() ? GetLineRect(line)
2493 : GetLine(line)->m_gi->m_rectHighlight;
2494}
2495
2496long wxListMainWindow::HitTestLine(size_t line, int x, int y) const
2497{
2498 wxASSERT_MSG( line < GetItemCount(), _T("invalid line in HitTestLine") )do { if ( line < GetItemCount() ) { } else if ( wxTheAssertHandler
&& (wxOnAssert("extern/wxWidgets/listctrl.cpp", 2498
, __FUNCTION__, "line < GetItemCount()", L"invalid line in HitTestLine"
), wxTrapInAssert) ) { wxTrapInAssert = false; asm volatile (
"int $3"); } } while ( (void)0, 0 )
;
2499
2500 wxListLineData *ld = GetLine(line);
2501
2502 if ( ld->HasImage() && GetLineIconRect(line).Contains(x, y) )
2503 return wxLIST_HITTEST_ONITEMICON0x0020;
2504
2505 // VS: Testing for "ld->HasText() || InReportView()" instead of
2506 // "ld->HasText()" is needed to make empty lines in report view
2507 // possible
2508 if ( ld->HasText() || InReportView() )
2509 {
2510 wxRect rect = InReportView() ? GetLineRect(line)
2511 : GetLineLabelRect(line);
2512
2513 if ( rect.Contains(x, y) )
2514 return wxLIST_HITTEST_ONITEMLABEL0x0080;
2515 }
2516
2517 return 0;
2518}
2519
2520// ----------------------------------------------------------------------------
2521// highlight (selection) handling
2522// ----------------------------------------------------------------------------
2523
2524bool wxListMainWindow::IsHighlighted(size_t line) const
2525{
2526 if ( IsVirtual() )
2527 {
2528 return m_selStore.IsSelected(line);
2529 }
2530 else // !virtual
2531 {
2532 wxListLineData *ld = GetLine(line);
2533 wxCHECK_MSG( ld, false, _T("invalid index in IsHighlighted") )if ( ld ) {} else { do { if ( wxTheAssertHandler && (
wxOnAssert("extern/wxWidgets/listctrl.cpp", 2533, __FUNCTION__
, "\"ld\"", L"invalid index in IsHighlighted"), wxTrapInAssert
) ) { wxTrapInAssert = false; asm volatile ("int $3"); } } while
( (void)0, 0 ); return false; } struct wxDummyCheckStruct2533
;
2534
2535 return ld->IsHighlighted();
2536 }
2537}
2538
2539void wxListMainWindow::HighlightLines( size_t lineFrom,
2540 size_t lineTo,
2541 bool highlight )
2542{
2543 if ( IsVirtual() )
2544 {
2545 wxArrayInt linesChanged;
2546 if ( !m_selStore.SelectRange(lineFrom, lineTo, highlight,
2547 &linesChanged) )
2548 {
2549 // many items changed state, refresh everything
2550 RefreshLines(lineFrom, lineTo);
2551 }
2552 else // only a few items changed state, refresh only them
2553 {
2554 size_t count = linesChanged.GetCount();
2555 for ( size_t n = 0; n < count; n++ )
2556 {
2557 RefreshLine(linesChanged[n]);
2558 }
2559 }
2560 }
2561 else // iterate over all items in non report view
2562 {
2563 for ( size_t line = lineFrom; line <= lineTo; line++ )
2564 {
2565 if ( HighlightLine(line, highlight) )
2566 RefreshLine(line);
2567 }
2568 }
2569}
2570
2571bool wxListMainWindow::HighlightLine( size_t line, bool highlight )
2572{
2573 bool changed;
2574
2575 if ( IsVirtual() )
2576 {
2577 changed = m_selStore.SelectItem(line, highlight);
2578 }
2579 else // !virtual
2580 {
2581 wxListLineData *ld = GetLine(line);
2582 wxCHECK_MSG( ld, false, _T("invalid index in HighlightLine") )if ( ld ) {} else { do { if ( wxTheAssertHandler && (
wxOnAssert("extern/wxWidgets/listctrl.cpp", 2582, __FUNCTION__
, "\"ld\"", L"invalid index in HighlightLine"), wxTrapInAssert
) ) { wxTrapInAssert = false; asm volatile ("int $3"); } } while
( (void)0, 0 ); return false; } struct wxDummyCheckStruct2582
;
2583
2584 changed = ld->Highlight(highlight);
2585 }
2586
2587 if ( changed )
2588 {
2589 SendNotify( line, highlight ? wxEVT_COMMAND_LIST_ITEM_SELECTEDwxEVT_LIST_ITEM_SELECTED
2590 : wxEVT_COMMAND_LIST_ITEM_DESELECTEDwxEVT_LIST_ITEM_DESELECTED );
2591 }
2592
2593 return changed;
2594}
2595
2596void wxListMainWindow::RefreshLine( size_t line )
2597{
2598 if ( InReportView() )
2599 {
2600 size_t visibleFrom, visibleTo;
2601 GetVisibleLinesRange(&visibleFrom, &visibleTo);
2602
2603 if ( line < visibleFrom || line > visibleTo )
2604 return;
2605 }
2606
2607 wxRect rect = GetLineRect(line);
2608
2609 CalcScrolledPosition( rect.x, rect.y, &rect.x, &rect.y );
2610 RefreshRect( rect );
2611}
2612
2613void wxListMainWindow::RefreshLines( size_t lineFrom, size_t lineTo )
2614{
2615 // we suppose that they are ordered by caller
2616 wxASSERT_MSG( lineFrom <= lineTo, _T("indices in disorder") )do { if ( lineFrom <= lineTo ) { } else if ( wxTheAssertHandler
&& (wxOnAssert("extern/wxWidgets/listctrl.cpp", 2616
, __FUNCTION__, "lineFrom <= lineTo", L"indices in disorder"
), wxTrapInAssert) ) { wxTrapInAssert = false; asm volatile (
"int $3"); } } while ( (void)0, 0 )
;
2617
2618 wxASSERT_MSG( lineTo < GetItemCount(), _T("invalid line range") )do { if ( lineTo < GetItemCount() ) { } else if ( wxTheAssertHandler
&& (wxOnAssert("extern/wxWidgets/listctrl.cpp", 2618
, __FUNCTION__, "lineTo < GetItemCount()", L"invalid line range"
), wxTrapInAssert) ) { wxTrapInAssert = false; asm volatile (
"int $3"); } } while ( (void)0, 0 )
;
2619
2620 if ( InReportView() )
2621 {
2622 size_t visibleFrom, visibleTo;
2623 GetVisibleLinesRange(&visibleFrom, &visibleTo);
2624
2625 if ( lineFrom < visibleFrom )
2626 lineFrom = visibleFrom;
2627 if ( lineTo > visibleTo )
2628 lineTo = visibleTo;
2629
2630 wxRect rect;
2631 rect.x = 0;
2632 rect.y = GetLineY(lineFrom);
2633 rect.width = GetClientSize().x;
2634 rect.height = GetLineY(lineTo) - rect.y + GetLineHeight();
2635
2636 CalcScrolledPosition( rect.x, rect.y, &rect.x, &rect.y );
2637 RefreshRect( rect );
2638 }
2639 else // !report
2640 {
2641 // TODO: this should be optimized...
2642 for ( size_t line = lineFrom; line <= lineTo; line++ )
2643 {
2644 RefreshLine(line);
2645 }
2646 }
2647}
2648
2649void wxListMainWindow::RefreshAfter( size_t lineFrom )
2650{
2651 if ( InReportView() )
2652 {
2653 size_t visibleFrom, visibleTo;
2654 GetVisibleLinesRange(&visibleFrom, &visibleTo);
2655
2656 if ( lineFrom < visibleFrom )
2657 lineFrom = visibleFrom;
2658 else if ( lineFrom > visibleTo )
2659 return;
2660
2661 wxRect rect;
2662 rect.x = 0;
2663 rect.y = GetLineY(lineFrom);
2664 CalcScrolledPosition( rect.x, rect.y, &rect.x, &rect.y );
2665
2666 wxSize size = GetClientSize();
2667 rect.width = size.x;
2668
2669 // refresh till the bottom of the window
2670 rect.height = size.y - rect.y;
2671
2672 RefreshRect( rect );
2673 }
2674 else // !report
2675 {
2676 // TODO: how to do it more efficiently?
2677 m_dirty = true;
2678 }
2679}
2680
2681void wxListMainWindow::RefreshSelected()
2682{
2683 if ( IsEmpty() )
4
Calling 'wxListMainWindow::IsEmpty'
2684 return;
2685
2686 size_t from, to;
2687 if ( InReportView() )
2688 {
2689 GetVisibleLinesRange(&from, &to);
2690 }
2691 else // !virtual
2692 {
2693 from = 0;
2694 to = GetItemCount() - 1;
2695 }
2696
2697 if ( HasCurrent() && m_current >= from && m_current <= to )
2698 RefreshLine(m_current);
2699
2700 for ( size_t line = from; line <= to; line++ )
2701 {
2702 // NB: the test works as expected even if m_current == -1
2703 if ( line != m_current && IsHighlighted(line) )
2704 RefreshLine(line);
2705 }
2706}
2707
2708void wxListMainWindow::Freeze()
2709{
2710 m_freezeCount++;
2711}
2712
2713void wxListMainWindow::Thaw()
2714{
2715 wxCHECK_RET( m_freezeCount > 0, _T("thawing unfrozen list control?") )if ( m_freezeCount > 0 ) {} else { do { if ( wxTheAssertHandler
&& (wxOnAssert("extern/wxWidgets/listctrl.cpp", 2715
, __FUNCTION__, "\"m_freezeCount > 0\"", L"thawing unfrozen list control?"
), wxTrapInAssert) ) { wxTrapInAssert = false; asm volatile (
"int $3"); } } while ( (void)0, 0 ); return; } struct wxDummyCheckStruct2715
;
2716
2717 if ( --m_freezeCount == 0 )
2718 Refresh();
2719}
2720
2721void wxListMainWindow::OnPaint( wxPaintEvent &WXUNUSED(event) )
2722{
2723 // Note: a wxPaintDC must be constructed even if no drawing is
2724 // done (a Windows requirement).
2725 wxBufferedPaintDC dc( this );
2726
2727 // Ensure an uniform background color, as to avoid differences between
2728 // the automatically cleared parts and the rest of the canvas.
2729 dc.SetBackground(*(wxTheBrushList->FindOrCreateBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_LISTBOX), wxBRUSHSTYLE_SOLID)));
2730
2731 // We need to clear the DC manually, since we intercept BG-erase events.
2732 // Clearing must be done first thing because caching of the double-buffering causes artifacts otherwise.
2733 dc.Clear();
2734
2735 if ( m_freezeCount )
2736 return;
2737
2738 if ( m_dirty )
2739 // delay the repainting until we calculate all the items positions
2740 return;
2741
2742 PrepareDC( dc );
2743
2744 // IsEmpty is checked now, after clearing, to avoid garbage on empty lists.
2745 if ( IsEmpty() ) {
2746 return;
2747 }
2748
2749 int dev_x, dev_y;
2750 CalcScrolledPosition( 0, 0, &dev_x, &dev_y );
2751
2752 dc.SetFont( GetFont() );
2753
2754 if ( InReportView() )
2755 {
2756 int lineHeight = GetLineHeight();
2757
2758 size_t visibleFrom, visibleTo;
2759 GetVisibleLinesRange(&visibleFrom, &visibleTo);
2760
2761 wxRect rectLine;
2762 int xOrig = dc.LogicalToDeviceX( 0 );
2763 int yOrig = dc.LogicalToDeviceY( 0 );
2764
2765 // tell the caller cache to cache the data
2766 if ( IsVirtual() )
2767 {
2768 wxListEvent evCache(wxEVT_COMMAND_LIST_CACHE_HINTwxEVT_LIST_CACHE_HINT,
2769 GetParent()->GetId());
2770 evCache.SetEventObject( GetParent() );
2771 evCache.m_oldItemIndex = visibleFrom;
2772 evCache.m_itemIndex = visibleTo;
2773 GetParent()->GetEventHandler()->ProcessEvent( evCache );
2774 }
2775
2776 for ( size_t line = visibleFrom; line <= visibleTo; line++ )
2777 {
2778 rectLine = GetLineRect(line);
2779
2780
2781 if ( !IsExposed(rectLine.x + xOrig, rectLine.y + yOrig,
2782 rectLine.width, rectLine.height) )
2783 {
2784 // don't redraw unaffected lines to avoid flicker
2785 continue;
2786 }
2787
2788 if (HasFlag(wxLC_OWNERDRAW0x10000)) {
2789 ((wxGenericListCtrl*)m_parent)->OnDrawItem(line, &dc, rectLine, GetLineHighlightRect(line), IsHighlighted(line));
2790 } else {
2791 GetLine(line)->DrawInReportMode( &dc,
2792 rectLine,
2793 GetLineHighlightRect(line),
2794 IsHighlighted(line) );
2795 }
2796 }
2797
2798 if ( HasFlag(wxLC_HRULES0x0002) )
2799 {
2800 wxPen pen = *(wxThePenList->FindOrCreatePen(GetRuleColour(), 1, wxPENSTYLE_SOLID));
2801 wxSize clientSize = GetClientSize();
2802
2803 size_t i = visibleFrom;
2804 if (i == 0) i = 1; // Don't draw the first one
2805 for ( ; i <= visibleTo; i++ )
2806 {
2807 dc.SetPen(pen);
2808 dc.SetBrush( *wxTRANSPARENT_BRUSHwxStockGDI::GetBrush(wxStockGDI::BRUSH_TRANSPARENT) );
2809 dc.DrawLine(0 - dev_x, i * lineHeight,
2810 clientSize.x - dev_x, i * lineHeight);
2811 }
2812
2813 // Draw last horizontal rule
2814 if ( visibleTo == GetItemCount() - 1 )
2815 {
2816 dc.SetPen( pen );
2817 dc.SetBrush( *wxTRANSPARENT_BRUSHwxStockGDI::GetBrush(wxStockGDI::BRUSH_TRANSPARENT) );
2818 dc.DrawLine(0 - dev_x, (m_lineTo + 1) * lineHeight,
2819 clientSize.x - dev_x , (m_lineTo + 1) * lineHeight );
2820 }
2821 }
2822
2823 // Draw vertical rules if required
2824 if ( HasFlag(wxLC_VRULES0x0001) && !IsEmpty() )
2825 {
2826 wxPen pen = *(wxThePenList->FindOrCreatePen(GetRuleColour(), 1, wxPENSTYLE_SOLID));
2827 wxRect firstItemRect, lastItemRect;
2828
2829 GetItemRect(visibleFrom, firstItemRect);
2830 GetItemRect(visibleTo, lastItemRect);
2831 int x = firstItemRect.GetX();
2832 dc.SetPen(pen);
2833 dc.SetBrush(* wxTRANSPARENT_BRUSHwxStockGDI::GetBrush(wxStockGDI::BRUSH_TRANSPARENT));
2834
2835 for (int col = 0; col < GetColumnCount(); col++)
2836 {
2837 int colWidth = GetColumnWidth(col);
2838 x += colWidth;
2839 int x_pos = x - dev_x;
2840 if (col < GetColumnCount()-1) x_pos -= 2;
2841 dc.DrawLine(x_pos, firstItemRect.GetY() - 1 - dev_y,
2842 x_pos, lastItemRect.GetBottom() + 1 - dev_y);
2843 }
2844 }
2845 }
2846 else // !report
2847 {
2848 size_t count = GetItemCount();
2849 for ( size_t i = 0; i < count; i++ )
2850 {
2851 GetLine(i)->Draw( &dc );
2852 }
2853 }
2854
2855#ifndef __WXMAC__
2856 // Don't draw rect outline under Mac at all.
2857 if ( HasCurrent() )
2858 {
2859 if ( m_hasFocus )
2860 {
2861 wxRect rect( GetLineHighlightRect( m_current ) );
2862#ifndef __WXGTK2__
2863 dc.SetPen( *wxBLACK_PENwxStockGDI::GetPen(wxStockGDI::PEN_BLACK) );
2864 dc.SetBrush( *wxTRANSPARENT_BRUSHwxStockGDI::GetBrush(wxStockGDI::BRUSH_TRANSPARENT) );
2865 dc.DrawRectangle( rect );
2866#else
2867 wxRendererNative::Get().DrawItemSelectionRect( this, dc, rect, wxCONTROL_CURRENT|wxCONTROL_FOCUSED );
2868
2869#endif
2870 }
2871 }
2872#endif
2873}
2874
2875void wxListMainWindow::HighlightAll( bool on )
2876{
2877 if ( IsSingleSel() )
2878 {
2879 wxASSERT_MSG( !on, _T("can't do this in a single selection control") )do { if ( !on ) { } else if ( wxTheAssertHandler && (
wxOnAssert("extern/wxWidgets/listctrl.cpp", 2879, __FUNCTION__
, "!on", L"can't do this in a single selection control"), wxTrapInAssert
) ) { wxTrapInAssert = false; asm volatile ("int $3"); } } while
( (void)0, 0 )
;
2880
2881 // we just have one item to turn off
2882 if ( HasCurrent() && IsHighlighted(m_current) )
2883 {
2884 HighlightLine(m_current, false);
2885 RefreshLine(m_current);
2886 }
2887 }
2888 else // multi selection
2889 {
2890 if ( !IsEmpty() )
2891 HighlightLines(0, GetItemCount() - 1, on);
2892 }
2893}
2894
2895void wxListMainWindow::OnChildFocus(wxChildFocusEvent& WXUNUSED(event))
2896{
2897 // Do nothing here. This prevents the default handler in wxScrolledWindow
2898 // from needlessly scrolling the window when the edit control is
2899 // dismissed. See ticket #9563.
2900}
2901
2902void wxListMainWindow::SendNotify( size_t line,
2903 wxEventType command,
2904 const wxPoint& point )
2905{
2906 wxListEvent le( command, GetParent()->GetId() );
2907 le.SetEventObject( GetParent() );
2908
2909 le.m_itemIndex = line;
2910
2911 // set only for events which have position
2912 if ( point != wxDefaultPosition )
2913 le.m_pointDrag = point;
2914
2915 // don't try to get the line info for virtual list controls: the main
2916 // program has it anyhow and if we did it would result in accessing all
2917 // the lines, even those which are not visible now and this is precisely
2918 // what we're trying to avoid
2919 if ( !IsVirtual() )
2920 {
2921 if ( line != (size_t)-1 )
2922 {
2923 GetLine(line)->GetItem( 0, le.m_item );
2924 }
2925 //else: this happens for wxEVT_COMMAND_LIST_ITEM_FOCUSED event
2926 }
2927 //else: there may be no more such item
2928
2929 GetParent()->GetEventHandler()->ProcessEvent( le );
2930}
2931
2932void wxListMainWindow::ChangeCurrent(size_t current)
2933{
2934 m_current = current;
2935
2936 // as the current item changed, we shouldn't start editing it when the
2937 // "slow click" timer expires as the click happened on another item
2938 if ( m_renameTimer->IsRunning() )
2939 m_renameTimer->Stop();
2940
2941 SendNotify(current, wxEVT_COMMAND_LIST_ITEM_FOCUSEDwxEVT_LIST_ITEM_FOCUSED);
2942}
2943
2944wxTextCtrl *wxListMainWindow::EditLabel(long item, wxClassInfo* textControlClass)
2945{
2946 wxCHECK_MSG( (item >= 0) && ((size_t)item < GetItemCount()), NULL,if ( (item >= 0) && ((size_t)item < GetItemCount
()) ) {} else { do { if ( wxTheAssertHandler && (wxOnAssert
("extern/wxWidgets/listctrl.cpp", 2947, __FUNCTION__, "\"(item >= 0) && ((size_t)item < GetItemCount())\""
, L"wrong index in wxGenericListCtrl::EditLabel()"), wxTrapInAssert
) ) { wxTrapInAssert = false; asm volatile ("int $3"); } } while
( (void)0, 0 ); return __null; } struct wxDummyCheckStruct2947
2947 wxT("wrong index in wxGenericListCtrl::EditLabel()") )if ( (item >= 0) && ((size_t)item < GetItemCount
()) ) {} else { do { if ( wxTheAssertHandler && (wxOnAssert
("extern/wxWidgets/listctrl.cpp", 2947, __FUNCTION__, "\"(item >= 0) && ((size_t)item < GetItemCount())\""
, L"wrong index in wxGenericListCtrl::EditLabel()"), wxTrapInAssert
) ) { wxTrapInAssert = false; asm volatile ("int $3"); } } while
( (void)0, 0 ); return __null; } struct wxDummyCheckStruct2947
;
2948
2949 wxASSERT_MSG( textControlClass->IsKindOf(CLASSINFO(wxTextCtrl)),do { if ( textControlClass->IsKindOf((&wxTextCtrl::ms_classInfo
)) ) { } else if ( wxTheAssertHandler && (wxOnAssert(
"extern/wxWidgets/listctrl.cpp", 2950, __FUNCTION__, "textControlClass->IsKindOf((&wxTextCtrl::ms_classInfo))"
, L"EditLabel() needs a text control"), wxTrapInAssert) ) { wxTrapInAssert
= false; asm volatile ("int $3"); } } while ( (void)0, 0 )
2950 wxT("EditLabel() needs a text control") )do { if ( textControlClass->IsKindOf((&wxTextCtrl::ms_classInfo
)) ) { } else if ( wxTheAssertHandler && (wxOnAssert(
"extern/wxWidgets/listctrl.cpp", 2950, __FUNCTION__, "textControlClass->IsKindOf((&wxTextCtrl::ms_classInfo))"
, L"EditLabel() needs a text control"), wxTrapInAssert) ) { wxTrapInAssert
= false; asm volatile ("int $3"); } } while ( (void)0, 0 )
;
2951
2952 size_t itemEdit = (size_t)item;
2953
2954 wxListEvent le( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDITwxEVT_LIST_BEGIN_LABEL_EDIT, GetParent()->GetId() );
2955 le.SetEventObject( GetParent() );
2956 le.m_itemIndex = item;
2957 wxListLineData *data = GetLine(itemEdit);
2958 wxCHECK_MSG( data, NULL, _T("invalid index in EditLabel()") )if ( data ) {} else { do { if ( wxTheAssertHandler &&
(wxOnAssert("extern/wxWidgets/listctrl.cpp", 2958, __FUNCTION__
, "\"data\"", L"invalid index in EditLabel()"), wxTrapInAssert
) ) { wxTrapInAssert = false; asm volatile ("int $3"); } } while
( (void)0, 0 ); return __null; } struct wxDummyCheckStruct2958
;
2959 data->GetItem( 0, le.m_item );
2960
2961 if ( GetParent()->GetEventHandler()->ProcessEvent( le ) && !le.IsAllowed() )
2962 {
2963 // vetoed by user code
2964 return NULL__null;
2965 }
2966
2967 // We have to call this here because the label in question might just have
2968 // been added and no screen update taken place.
2969 if ( m_dirty )
2970 {
2971 wxSafeYield();
2972
2973 // Pending events dispatched by wxSafeYield might have changed the item
2974 // count
2975 if ( (size_t)item >= GetItemCount() )
2976 return NULL__null;
2977 }
2978
2979 wxTextCtrl * const text = (wxTextCtrl *)textControlClass->CreateObject();
2980 m_textctrlWrapper = new wxListTextCtrlWrapper(this, text, item);
2981 return m_textctrlWrapper->GetText();
2982}
2983
2984void wxListMainWindow::OnRenameTimer()
2985{
2986 wxCHECK_RET( HasCurrent(), wxT("unexpected rename timer") )if ( HasCurrent() ) {} else { do { if ( wxTheAssertHandler &&
(wxOnAssert("extern/wxWidgets/listctrl.cpp", 2986, __FUNCTION__
, "\"HasCurrent()\"", L"unexpected rename timer"), wxTrapInAssert
) ) { wxTrapInAssert = false; asm volatile ("int $3"); } } while
( (void)0, 0 ); return; } struct wxDummyCheckStruct2986
;
2987
2988 EditLabel( m_current );
2989}
2990
2991bool wxListMainWindow::OnRenameAccept(size_t itemEdit, const wxString& value)
2992{
2993 wxListEvent le( wxEVT_COMMAND_LIST_END_LABEL_EDITwxEVT_LIST_END_LABEL_EDIT, GetParent()->GetId() );
2994 le.SetEventObject( GetParent() );
2995 le.m_itemIndex = itemEdit;
2996
2997 wxListLineData *data = GetLine(itemEdit);
2998
2999 wxCHECK_MSG( data, false, _T("invalid index in OnRenameAccept()") )if ( data ) {} else { do { if ( wxTheAssertHandler &&
(wxOnAssert("extern/wxWidgets/listctrl.cpp", 2999, __FUNCTION__
, "\"data\"", L"invalid index in OnRenameAccept()"), wxTrapInAssert
) ) { wxTrapInAssert = false; asm volatile ("int $3"); } } while
( (void)0, 0 ); return false; } struct wxDummyCheckStruct2999
;
3000
3001 data->GetItem( 0, le.m_item );
3002 le.m_item.m_text = value;
3003 return !GetParent()->GetEventHandler()->ProcessEvent( le ) ||
3004 le.IsAllowed();
3005}
3006
3007void wxListMainWindow::OnRenameCancelled(size_t itemEdit)
3008{
3009 // let owner know that the edit was cancelled
3010 wxListEvent le( wxEVT_COMMAND_LIST_END_LABEL_EDITwxEVT_LIST_END_LABEL_EDIT, GetParent()->GetId() );
3011
3012 le.SetEditCanceled(true);
3013
3014 le.SetEventObject( GetParent() );
3015 le.m_itemIndex = itemEdit;
3016
3017 wxListLineData *data = GetLine(itemEdit);
3018 wxCHECK_RET( data, _T("invalid index in OnRenameCancelled()") )if ( data ) {} else { do { if ( wxTheAssertHandler &&
(wxOnAssert("extern/wxWidgets/listctrl.cpp", 3018, __FUNCTION__
, "\"data\"", L"invalid index in OnRenameCancelled()"), wxTrapInAssert
) ) { wxTrapInAssert = false; asm volatile ("int $3"); } } while
( (void)0, 0 ); return; } struct wxDummyCheckStruct3018
;
3019
3020 data->GetItem( 0, le.m_item );
3021 GetEventHandler()->ProcessEvent( le );
3022}
3023
3024void wxListMainWindow::OnMouse( wxMouseEvent &event )
3025{
3026
3027#ifdef __WXMAC__
3028 // On wxMac we can't depend on the EVT_KILL_FOCUS event to properly
3029 // shutdown the edit control when the mouse is clicked elsewhere on the
3030 // listctrl because the order of events is different (or something like
3031 // that), so explicitly end the edit if it is active.
3032 if ( event.LeftDown() && m_textctrlWrapper )
3033 m_textctrlWrapper->AcceptChangesAndFinish();
3034#endif // __WXMAC__
3035
3036 if ( event.LeftDown() )
3037 SetFocusIgnoringChildren();
3038
3039 event.SetEventObject( GetParent() );
3040 if ( GetParent()->GetEventHandler()->ProcessEvent( event) )
3041 return;
3042
3043 if (event.GetEventType() == wxEVT_MOUSEWHEEL)
3044 {
3045 // let the base handle mouse wheel events.
3046 event.Skip();
3047 return;
3048 }
3049
3050 if ( !HasCurrent() || IsEmpty() )
3051 {
3052 if (event.RightDown())
3053 {
3054 SendNotify( (size_t)-1, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICKwxEVT_LIST_ITEM_RIGHT_CLICK, event.GetPosition() );
3055 // Allow generation of context menu event
3056 event.Skip();
3057 }
3058 return;
3059 }
3060
3061 if (m_dirty)
3062 return;
3063
3064 if ( !(event.Dragging() || event.ButtonDown() || event.LeftUp() ||
3065 event.ButtonDClick()) )
3066 return;
3067
3068 int x = event.GetX();
3069 int y = event.GetY();
3070 CalcUnscrolledPosition( x, y, &x, &y );
3071
3072 // where did we hit it (if we did)?
3073 long hitResult = 0;
3074
3075 size_t count = GetItemCount(),
3076 current;
3077
3078 if ( InReportView() )
3079 {
3080 current = y / GetLineHeight();
3081 if ( current < count )
3082 hitResult = HitTestLine(current, x, y);
3083 }
3084 else // !report
3085 {
3086 // TODO: optimize it too! this is less simple than for report view but
3087 // enumerating all items is still not a way to do it!!
3088 for ( current = 0; current < count; current++ )
3089 {
3090 hitResult = HitTestLine(current, x, y);
3091 if ( hitResult )
3092 break;
3093 }
3094 }
3095
3096 if (event.Dragging())
3097 {
3098 if (m_dragCount == 0)
3099 {
3100 // we have to report the raw, physical coords as we want to be
3101 // able to call HitTest(event.m_pointDrag) from the user code to
3102 // get the item being dragged
3103 m_dragStart = event.GetPosition();
3104 }
3105
3106 m_dragCount++;
3107
3108 if (m_dragCount != 3)
3109 return;
3110
3111 int command = event.RightIsDown() ? wxEVT_COMMAND_LIST_BEGIN_RDRAGwxEVT_LIST_BEGIN_RDRAG
3112 : wxEVT_COMMAND_LIST_BEGIN_DRAGwxEVT_LIST_BEGIN_DRAG;
3113
3114 wxListEvent le( command, GetParent()->GetId() );
3115 le.SetEventObject( GetParent() );
3116 le.m_itemIndex = m_lineLastClicked;
3117 le.m_pointDrag = m_dragStart;
3118 GetParent()->GetEventHandler()->ProcessEvent( le );
3119
3120 return;
3121 }
3122 else
3123 {
3124 m_dragCount = 0;
3125 }
3126
3127 if ( !hitResult )
3128 {
3129 // outside of any item
3130 if (event.RightDown())
3131 {
3132 SendNotify( (size_t) -1, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICKwxEVT_LIST_ITEM_RIGHT_CLICK, event.GetPosition() );
3133
3134 wxContextMenuEvent evtCtx(
3135 wxEVT_CONTEXT_MENU,
3136 GetParent()->GetId(),
3137 ClientToScreen(event.GetPosition()));
3138 evtCtx.SetEventObject(GetParent());
3139 GetParent()->GetEventHandler()->ProcessEvent(evtCtx);
3140 }
3141 else
3142 {
3143 // reset the selection and bail out
3144 HighlightAll(false);
3145 }
3146
3147 return;
3148 }
3149
3150 bool forceClick = false;
3151 if (event.ButtonDClick())
3152 {
3153 if ( m_renameTimer->IsRunning() )
3154 m_renameTimer->Stop();
3155
3156 m_lastOnSame = false;
3157
3158 if ( current == m_lineLastClicked )
3159 {
3160 SendNotify( current, wxEVT_COMMAND_LIST_ITEM_ACTIVATEDwxEVT_LIST_ITEM_ACTIVATED );
3161
3162 return;
3163 }
3164 else
3165 {
3166 // The first click was on another item, so don't interpret this as
3167 // a double click, but as a simple click instead
3168 forceClick = true;
3169 }
3170 }
3171
3172 if (event.LeftUp())
3173 {
3174 if (m_lineSelectSingleOnUp != (size_t)-1)
3175 {
3176 // select single line
3177 HighlightAll( false );
3178 ReverseHighlight(m_lineSelectSingleOnUp);
3179 }
3180
3181 if (m_lastOnSame)
3182 {
3183 if ((current == m_current) &&
3184 (hitResult == wxLIST_HITTEST_ONITEMLABEL0x0080) &&
3185 HasFlag(wxLC_EDIT_LABELS0x0400) )
3186 {
3187 if (InReportView())
3188 {
3189 wxRect label = GetLineLabelRect( current );
3190 if (label.Contains( x, y ))
3191 m_renameTimer->Start( 250, true );
3192
3193 }
3194 else
3195 m_renameTimer->Start( 250, true );
3196 }
3197 }
3198
3199 m_lastOnSame = false;
3200 m_lineSelectSingleOnUp = (size_t)-1;
3201 }
3202 else
3203 {
3204 // This is necessary, because after a DnD operation in
3205 // from and to ourself, the up event is swallowed by the
3206 // DnD code. So on next non-up event (which means here and
3207 // now) m_lineSelectSingleOnUp should be reset.
3208 m_lineSelectSingleOnUp = (size_t)-1;
3209 }
3210 if (event.RightDown())
3211 {
3212 m_lineBeforeLastClicked = m_lineLastClicked;
3213 m_lineLastClicked = current;
3214
3215 // If the item is already selected, do not update the selection.
3216 // Multi-selections should not be cleared if a selected item is clicked.
3217 if (!IsHighlighted(current))
3218 {
3219 HighlightAll(false);
3220 ChangeCurrent(current);
3221 ReverseHighlight(m_current);
3222 }
3223
3224 SendNotify( current, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICKwxEVT_LIST_ITEM_RIGHT_CLICK, event.GetPosition() );
3225
3226 wxContextMenuEvent evtCtx(
3227 wxEVT_CONTEXT_MENU,
3228 GetParent()->GetId(),
3229 ClientToScreen(event.GetPosition()));
3230 evtCtx.SetEventObject(GetParent());
3231 GetParent()->GetEventHandler()->ProcessEvent(evtCtx);
3232 }
3233 else if (event.MiddleDown())
3234 {
3235 SendNotify( current, wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICKwxEVT_LIST_ITEM_MIDDLE_CLICK );
3236 }
3237 else if ( event.LeftDown() || forceClick )
3238 {
3239 m_lineBeforeLastClicked = m_lineLastClicked;
3240 m_lineLastClicked = current;
3241
3242 size_t oldCurrent = m_current;
3243 bool oldWasSelected = IsHighlighted(m_current);
3244
3245 bool cmdModifierDown = event.CmdDown();
3246 if ( IsSingleSel() || !(cmdModifierDown || event.ShiftDown()) )
3247 {
3248 if ( IsSingleSel() || !IsHighlighted(current) )
3249 {
3250 HighlightAll( false );
3251
3252 ChangeCurrent(current);
3253
3254 ReverseHighlight(m_current);
3255 }
3256 else // multi sel & current is highlighted & no mod keys
3257 {
3258 m_lineSelectSingleOnUp = current;
3259 ChangeCurrent(current); // change focus
3260 }
3261 }
3262 else // multi sel & either ctrl or shift is down
3263 {
3264 if (cmdModifierDown)
3265 {
3266 ChangeCurrent(current);
3267
3268 ReverseHighlight(m_current);
3269 }
3270 else if (event.ShiftDown())
3271 {
3272 ChangeCurrent(current);
3273
3274 size_t lineFrom = oldCurrent,
3275 lineTo = current;
3276
3277 if ( lineTo < lineFrom )
3278 {
3279 lineTo = lineFrom;
3280 lineFrom = m_current;
3281 }
3282
3283 HighlightLines(lineFrom, lineTo);
3284 }
3285 else // !ctrl, !shift
3286 {
3287 // test in the enclosing if should make it impossible
3288 wxFAIL_MSG( _T("how did we get here?") )do { if ( wxTheAssertHandler && (wxOnAssert("extern/wxWidgets/listctrl.cpp"
, 3288, __FUNCTION__, "\"Assert failure\"", L"how did we get here?"
), wxTrapInAssert) ) { wxTrapInAssert = false; asm volatile (
"int $3"); } } while ( (void)0, 0 )
;
3289 }
3290 }
3291
3292 if (m_current != oldCurrent)
3293 RefreshLine( oldCurrent );
3294
3295 // forceClick is only set if the previous click was on another item
3296 m_lastOnSame = !forceClick && (m_current == oldCurrent) && oldWasSelected;
3297 }
3298}
3299
3300void wxListMainWindow::MoveToItem(size_t item)
3301{
3302 if ( item == (size_t)-1 )
3303 return;
3304
3305 wxRect rect = GetLineRect(item);
3306
3307 int client_w, client_h;
3308 GetClientSize( &client_w, &client_h );
3309
3310 const int hLine = GetLineHeight();
3311
3312 int view_x = SCROLL_UNIT_X * GetScrollPos( wxHORIZONTAL );
3313 int view_y = hLine * GetScrollPos( wxVERTICAL );
3314
3315 if ( InReportView() )
3316 {
3317 // the next we need the range of lines shown it might be different,
3318 // so recalculate it
3319 ResetVisibleLinesRange();
3320
3321 if (rect.y < view_y)
3322 Scroll( -1, rect.y / hLine );
3323 if (rect.y + rect.height + 5 > view_y + client_h)
3324 Scroll( -1, (rect.y + rect.height - client_h + hLine) / hLine );
3325
3326#ifdef __WXMAC__
3327 // At least on Mac the visible lines value will get reset inside of
3328 // Scroll *before* it actually scrolls the window because of the
3329 // Update() that happens there, so it will still have the wrong value.
3330 // So let's reset it again and wait for it to be recalculated in the
3331 // next paint event. I would expect this problem to show up in wxGTK
3332 // too but couldn't duplicate it there. Perhaps the order of events
3333 // is different... --Robin
3334 ResetVisibleLinesRange();
3335#endif
3336 }
3337 else // !report
3338 {
3339 if (rect.x-view_x < 5)
3340 Scroll( (rect.x - 5) / SCROLL_UNIT_X, -1 );
3341 if (rect.x + rect.width - 5 > view_x + client_w)
3342 Scroll( (rect.x + rect.width - client_w + SCROLL_UNIT_X) / SCROLL_UNIT_X, -1 );
3343 }
3344}
3345
3346// ----------------------------------------------------------------------------
3347// keyboard handling
3348// ----------------------------------------------------------------------------
3349
3350void wxListMainWindow::OnArrowChar(size_t newCurrent, const wxKeyEvent& event)
3351{
3352 wxCHECK_RET( newCurrent < (size_t)GetItemCount(),if ( newCurrent < (size_t)GetItemCount() ) {} else { do { if
( wxTheAssertHandler && (wxOnAssert("extern/wxWidgets/listctrl.cpp"
, 3353, __FUNCTION__, "\"newCurrent < (size_t)GetItemCount()\""
, L"invalid item index in OnArrowChar()"), wxTrapInAssert) ) {
wxTrapInAssert = false; asm volatile ("int $3"); } } while (
(void)0, 0 ); return; } struct wxDummyCheckStruct3353
3353 _T("invalid item index in OnArrowChar()") )if ( newCurrent < (size_t)GetItemCount() ) {} else { do { if
( wxTheAssertHandler && (wxOnAssert("extern/wxWidgets/listctrl.cpp"
, 3353, __FUNCTION__, "\"newCurrent < (size_t)GetItemCount()\""
, L"invalid item index in OnArrowChar()"), wxTrapInAssert) ) {
wxTrapInAssert = false; asm volatile ("int $3"); } } while (
(void)0, 0 ); return; } struct wxDummyCheckStruct3353
;
3354
3355 size_t oldCurrent = m_current;
3356
3357 // in single selection we just ignore Shift as we can't select several
3358 // items anyhow
3359 if ( event.ShiftDown() && !IsSingleSel() )
3360 {
3361 ChangeCurrent(newCurrent);
3362
3363 // refresh the old focus to remove it
3364 RefreshLine( oldCurrent );
3365
3366 // select all the items between the old and the new one
3367 if ( oldCurrent > newCurrent )
3368 {
3369 newCurrent = oldCurrent;
3370 oldCurrent = m_current;
3371 }
3372
3373 HighlightLines(oldCurrent, newCurrent);
3374 }
3375 else // !shift
3376 {
3377 // all previously selected items are unselected unless ctrl is held
3378 // in a multiselection control
3379 if ( !event.ControlDown() || IsSingleSel() )
3380 HighlightAll(false);
3381
3382 ChangeCurrent(newCurrent);
3383
3384 // refresh the old focus to remove it
3385 RefreshLine( oldCurrent );
3386
3387 // in single selection mode we must always have a selected item
3388 if ( !event.ControlDown() || IsSingleSel() )
3389 HighlightLine( m_current, true );
3390 }
3391
3392 RefreshLine( m_current );
3393
3394 MoveToFocus();
3395}
3396
3397void wxListMainWindow::OnKeyDown( wxKeyEvent &event )
3398{
3399 wxWindow *parent = GetParent();
3400
3401 // propagate the key event upwards
3402 wxKeyEvent ke(event);
3403 if (parent->GetEventHandler()->ProcessEvent( ke ))
3404 return;
3405
3406 event.Skip();
3407}
3408
3409void wxListMainWindow::OnKeyUp( wxKeyEvent &event )
3410{
3411 wxWindow *parent = GetParent();
3412
3413 // propagate the key event upwards
3414 wxKeyEvent ke(event);
3415 ke.SetEventObject( parent );
3416 if (parent->GetEventHandler()->ProcessEvent( ke ))
3417 return;
3418
3419 event.Skip();
3420}
3421
3422void wxListMainWindow::OnChar( wxKeyEvent &event )
3423{
3424 wxWindow *parent = GetParent();
3425
3426 // send a list_key event up
3427 if ( HasCurrent() )
3428 {
3429 wxListEvent le( wxEVT_COMMAND_LIST_KEY_DOWNwxEVT_LIST_KEY_DOWN, GetParent()->GetId() );
3430 le.m_itemIndex = m_current;
3431 GetLine(m_current)->GetItem( 0, le.m_item );
3432 le.m_code = event.GetKeyCode();
3433 le.SetEventObject( parent );
3434 parent->GetEventHandler()->ProcessEvent( le );
3435 }
3436
3437 // propagate the char event upwards
3438 wxKeyEvent ke(event);
3439 if (parent->GetEventHandler()->ProcessEvent( ke ))
3440 return;
3441
3442 if (event.GetKeyCode() == WXK_TAB)
3443 {
3444 wxNavigationKeyEvent nevent;
3445 nevent.SetWindowChange( event.ControlDown() );
3446 nevent.SetDirection( !event.ShiftDown() );
3447 nevent.SetEventObject( GetParent()->GetParent() );
3448 nevent.SetCurrentFocus( m_parent );
3449 if (GetParent()->GetParent()->GetEventHandler()->ProcessEvent( nevent ))
3450 return;
3451 }
3452
3453 // no item -> nothing to do
3454 if (!HasCurrent())
3455 {
3456 event.Skip();
3457 return;
3458 }
3459
3460 // don't use m_linesPerPage directly as it might not be computed yet
3461 const int pageSize = GetCountPerPage();
3462 wxCHECK_RET( pageSize, _T("should have non zero page size") )if ( pageSize ) {} else { do { if ( wxTheAssertHandler &&
(wxOnAssert("extern/wxWidgets/listctrl.cpp", 3462, __FUNCTION__
, "\"pageSize\"", L"should have non zero page size"), wxTrapInAssert
) ) { wxTrapInAssert = false; asm volatile ("int $3"); } } while
( (void)0, 0 ); return; } struct wxDummyCheckStruct3462
;
3463
3464 if (GetLayoutDirection() == wxLayout_RightToLeft)
3465 {
3466 if (event.GetKeyCode() == WXK_RIGHT)
3467 event.m_keyCode = WXK_LEFT;
3468 else if (event.GetKeyCode() == WXK_LEFT)
3469 event.m_keyCode = WXK_RIGHT;
3470 }
3471
3472 switch ( event.GetKeyCode() )
3473 {
3474 case WXK_UP:
3475 if ( m_current > 0 )
3476 OnArrowChar( m_current - 1, event );
3477 break;
3478
3479 case WXK_DOWN:
3480 if ( m_current < (size_t)GetItemCount() - 1 )
3481 OnArrowChar( m_current + 1, event );
3482 break;
3483
3484 case WXK_END:
3485 if (!IsEmpty())
3486 OnArrowChar( GetItemCount() - 1, event );
3487 break;
3488
3489 case WXK_HOME:
3490 if (!IsEmpty())
3491 OnArrowChar( 0, event );
3492 break;
3493
3494 case WXK_PAGEUP:
3495 {
3496 int steps = InReportView() ? pageSize - 1
3497 : m_current % pageSize;
3498
3499 int index = m_current - steps;
3500 if (index < 0)
3501 index = 0;
3502
3503 OnArrowChar( index, event );
3504 }
3505 break;
3506
3507 case WXK_PAGEDOWN:
3508 {
3509 int steps = InReportView()
3510 ? pageSize - 1
3511 : pageSize - (m_current % pageSize) - 1;
3512
3513 size_t index = m_current + steps;
3514 size_t count = GetItemCount();
3515 if ( index >= count )
3516 index = count - 1;
3517
3518 OnArrowChar( index, event );
3519 }
3520 break;
3521
3522 case WXK_LEFT:
3523 if ( !InReportView() )
3524 {
3525 int index = m_current - pageSize;
3526 if (index < 0)
3527 index = 0;
3528
3529 OnArrowChar( index, event );
3530 }
3531 break;
3532
3533 case WXK_RIGHT:
3534 if ( !InReportView() )
3535 {
3536 size_t index = m_current + pageSize;
3537
3538 size_t count = GetItemCount();
3539 if ( index >= count )
3540 index = count - 1;
3541
3542 OnArrowChar( index, event );
3543 }
3544 break;
3545
3546 case WXK_SPACE:
3547 if ( IsSingleSel() )
3548 {
3549 if ( event.ControlDown() )
3550 {
3551 ReverseHighlight(m_current);
3552 }
3553 else // normal space press
3554 {
3555 SendNotify( m_current, wxEVT_COMMAND_LIST_ITEM_ACTIVATEDwxEVT_LIST_ITEM_ACTIVATED );
3556 }
3557 }
3558 else // multiple selection
3559 {
3560 ReverseHighlight(m_current);
3561 }
3562 break;
3563
3564 case WXK_RETURN:
3565 case WXK_EXECUTE:
3566 SendNotify( m_current, wxEVT_COMMAND_LIST_ITEM_ACTIVATEDwxEVT_LIST_ITEM_ACTIVATED );
3567 break;
3568
3569 default:
3570 event.Skip();
3571 }
3572}
3573
3574// ----------------------------------------------------------------------------
3575// focus handling
3576// ----------------------------------------------------------------------------
3577
3578void wxListMainWindow::OnSetFocus( wxFocusEvent &WXUNUSED(event) )
3579{
3580 if ( GetParent() )
3581 {
3582 wxFocusEvent event( wxEVT_SET_FOCUS, GetParent()->GetId() );
3583 event.SetEventObject( GetParent() );
3584 if ( GetParent()->GetEventHandler()->ProcessEvent( event) )
3585 return;
3586 }
3587
3588 // wxGTK sends us EVT_SET_FOCUS events even if we had never got
3589 // EVT_KILL_FOCUS before which means that we finish by redrawing the items
3590 // which are already drawn correctly resulting in horrible flicker - avoid
3591 // it
3592 if ( !m_hasFocus )
3593 {
3594 m_hasFocus = true;
3595
3596 RefreshSelected();
3597 }
3598}
3599
3600void wxListMainWindow::OnKillFocus( wxFocusEvent &WXUNUSED(event) )
3601{
3602 if ( GetParent() )
1
Assuming pointer value is null
2
Taking false branch
3603 {
3604 wxFocusEvent event( wxEVT_KILL_FOCUS, GetParent()->GetId() );
3605 event.SetEventObject( GetParent() );
3606 if ( GetParent()->GetEventHandler()->ProcessEvent( event) )
3607 return;
3608 }
3609
3610 m_hasFocus = false;
3611 RefreshSelected();
3
Calling 'wxListMainWindow::RefreshSelected'
3612}
3613
3614void wxListMainWindow::DrawImage( int index, wxDC *dc, int x, int y )
3615{
3616 if ( HasFlag(wxLC_ICON0x0004) && (m_normal_image_list))
3617 {
3618 m_normal_image_list->Draw( index, *dc, x, y, wxIMAGELIST_DRAW_TRANSPARENT0x0002 );
3619 }
3620 else if ( HasFlag(wxLC_SMALL_ICON0x0008) && (m_small_image_list))
3621 {
3622 m_small_image_list->Draw( index, *dc, x, y, wxIMAGELIST_DRAW_TRANSPARENT0x0002 );
3623 }
3624 else if ( HasFlag(wxLC_LIST0x0010) && (m_small_image_list))
3625 {
3626 m_small_image_list->Draw( index, *dc, x, y, wxIMAGELIST_DRAW_TRANSPARENT0x0002 );
3627 }
3628 else if ( InReportView() && (m_small_image_list))
3629 {
3630 m_small_image_list->Draw( index, *dc, x, y, wxIMAGELIST_DRAW_TRANSPARENT0x0002 );
3631 }
3632}
3633
3634void wxListMainWindow::GetImageSize( int index, int &width, int &height ) const
3635{
3636 if ( HasFlag(wxLC_ICON0x0004) && m_normal_image_list )
3637 {
3638 m_normal_image_list->GetSize( index, width, height );
3639 }
3640 else if ( HasFlag(wxLC_SMALL_ICON0x0008) && m_small_image_list )
3641 {
3642 m_small_image_list->GetSize( index, width, height );
3643 }
3644 else if ( HasFlag(wxLC_LIST0x0010) && m_small_image_list )
3645 {
3646 m_small_image_list->GetSize( index, width, height );
3647 }
3648 else if ( InReportView() && m_small_image_list )
3649 {
3650 m_small_image_list->GetSize( index, width, height );
3651 }
3652 else
3653 {
3654 width =
3655 height = 0;
3656 }
3657}
3658
3659int wxListMainWindow::GetTextLength( const wxString &s ) const
3660{
3661 wxClientDC dc( wxConstCast(this, wxListMainWindow)const_cast<wxListMainWindow *>(this) );
3662 dc.SetFont( GetFont() );
3663
3664 wxCoord lw;
3665 dc.GetTextExtent( s, &lw, NULL__null );
3666
3667 return lw + AUTOSIZE_COL_MARGIN;
3668}
3669
3670void wxListMainWindow::SetImageList( wxImageList *imageList, int which )
3671{
3672 m_dirty = true;
3673
3674 // calc the spacing from the icon size
3675 int width = 0, height = 0;
3676
3677 if ((imageList) && (imageList->GetImageCount()) )
3678 imageList->GetSize(0, width, height);
3679
3680 if (which == wxIMAGE_LIST_NORMAL)
3681 {
3682 m_normal_image_list = imageList;
3683 m_normal_spacing = width + 8;
3684 }
3685
3686 if (which == wxIMAGE_LIST_SMALL)
3687 {
3688 m_small_image_list = imageList;
3689 m_small_spacing = width + 14;
3690 m_lineHeight = 0; // ensure that the line height will be recalc'd
3691 }
3692}
3693
3694void wxListMainWindow::SetItemSpacing( int spacing, bool isSmall )
3695{
3696 m_dirty = true;
3697 if (isSmall)
3698 m_small_spacing = spacing;
3699 else
3700 m_normal_spacing = spacing;
3701}
3702
3703int wxListMainWindow::GetItemSpacing( bool isSmall )
3704{
3705 return isSmall ? m_small_spacing : m_normal_spacing;
3706}
3707
3708// ----------------------------------------------------------------------------
3709// columns
3710// ----------------------------------------------------------------------------
3711
3712void wxListMainWindow::SetColumn( int col, wxListItem &item )
3713{
3714 wxListHeaderDataList::compatibility_iterator node = m_columns.Item( col );
3715
3716 wxCHECK_RET( node, _T("invalid column index in SetColumn") )if ( node ) {} else { do { if ( wxTheAssertHandler &&
(wxOnAssert("extern/wxWidgets/listctrl.cpp", 3716, __FUNCTION__
, "\"node\"", L"invalid column index in SetColumn"), wxTrapInAssert
) ) { wxTrapInAssert = false; asm volatile ("int $3"); } } while
( (void)0, 0 ); return; } struct wxDummyCheckStruct3716
;
3717
3718 if ( item.m_width == wxLIST_AUTOSIZE_USEHEADER )
3719 item.m_width = GetTextLength( item.m_text );
3720
3721 wxListHeaderData *column = node->GetData();
3722 column->SetItem( item );
3723
3724 wxListHeaderWindow *headerWin = GetListCtrl()->m_headerWin;
3725 if ( headerWin )
3726 headerWin->m_dirty = true;
3727
3728 m_dirty = true;
3729
3730 // invalidate it as it has to be recalculated
3731 m_headerWidth = 0;
3732}
3733
3734void wxListMainWindow::SetColumnWidth( int col, int width )
3735{
3736 { wxCHECK_RET( col >= 0 && col < GetColumnCount(),if ( col >= 0 && col < GetColumnCount() ) {} else
{ do { if ( wxTheAssertHandler && (wxOnAssert("extern/wxWidgets/listctrl.cpp"
, 3737, __FUNCTION__, "\"col >= 0 && col < GetColumnCount()\""
, L"invalid column index"), wxTrapInAssert) ) { wxTrapInAssert
= false; asm volatile ("int $3"); } } while ( (void)0, 0 ); return
; } struct wxDummyCheckStruct3737
3737 _T("invalid column index") )if ( col >= 0 && col < GetColumnCount() ) {} else
{ do { if ( wxTheAssertHandler && (wxOnAssert("extern/wxWidgets/listctrl.cpp"
, 3737, __FUNCTION__, "\"col >= 0 && col < GetColumnCount()\""
, L"invalid column index"), wxTrapInAssert) ) { wxTrapInAssert
= false; asm volatile ("int $3"); } } while ( (void)0, 0 ); return
; } struct wxDummyCheckStruct3737
; }
3738
3739 { wxCHECK_RET( InReportView(),if ( InReportView() ) {} else { do { if ( wxTheAssertHandler &&
(wxOnAssert("extern/wxWidgets/listctrl.cpp", 3740, __FUNCTION__
, "\"InReportView()\"", L"SetColumnWidth() can only be called in report mode."
), wxTrapInAssert) ) { wxTrapInAssert = false; asm volatile (
"int $3"); } } while ( (void)0, 0 ); return; } struct wxDummyCheckStruct3740
3740 _T("SetColumnWidth() can only be called in report mode.") )if ( InReportView() ) {} else { do { if ( wxTheAssertHandler &&
(wxOnAssert("extern/wxWidgets/listctrl.cpp", 3740, __FUNCTION__
, "\"InReportView()\"", L"SetColumnWidth() can only be called in report mode."
), wxTrapInAssert) ) { wxTrapInAssert = false; asm volatile (
"int $3"); } } while ( (void)0, 0 ); return; } struct wxDummyCheckStruct3740
; }
3741
3742 m_dirty = true;
3743 wxListHeaderWindow *headerWin = GetListCtrl()->m_headerWin;
3744 if ( headerWin )
3745 headerWin->m_dirty = true;
3746
3747 wxListHeaderDataList::compatibility_iterator node = m_columns.Item( col );
3748 { wxCHECK_RET( node, _T("no column?") )if ( node ) {} else { do { if ( wxTheAssertHandler &&
(wxOnAssert("extern/wxWidgets/listctrl.cpp", 3748, __FUNCTION__
, "\"node\"", L"no column?"), wxTrapInAssert) ) { wxTrapInAssert
= false; asm volatile ("int $3"); } } while ( (void)0, 0 ); return
; } struct wxDummyCheckStruct3748
; }
3749
3750 wxListHeaderData *column = node->GetData();
3751
3752 size_t count = GetItemCount();
3753
3754 if (width == wxLIST_AUTOSIZE_USEHEADER)
3755 {
3756 width = GetTextLength(column->GetText());
3757 width += 2*EXTRA_WIDTH;
3758
3759 // check for column header's image availability
3760 const int image = column->GetImage();
3761 if ( image != -1 )
3762 {
3763 if ( m_small_image_list )
3764 {
3765 int ix = 0, iy = 0;
3766 m_small_image_list->GetSize(image, ix, iy);
3767 width += ix + HEADER_IMAGE_MARGIN_IN_REPORT_MODE;
3768 }
3769 }
3770 }
3771 else if ( width == wxLIST_AUTOSIZE )
3772 {
3773 if ( IsVirtual() )
3774 {
3775 // TODO: determine the max width somehow...
3776 width = WIDTH_COL_DEFAULT;
3777 }
3778 else // !virtual
3779 {
3780 wxClientDC dc(this);
3781 dc.SetFont( GetFont() );
3782
3783 int max = AUTOSIZE_COL_MARGIN;
3784
3785 // if the cached column width isn't valid then recalculate it
3786 if (m_aColWidths.Item(col)->bNeedsUpdate)
3787 {
3788 for (size_t i = 0; i < count; i++)
3789 {
3790 wxListLineData *line = GetLine( i );
3791 wxListItemDataList::compatibility_iterator n = line->m_items.Item( col );
3792
3793 wxCHECK_RET( n, _T("no subitem?") )if ( n ) {} else { do { if ( wxTheAssertHandler && (wxOnAssert
("extern/wxWidgets/listctrl.cpp", 3793, __FUNCTION__, "\"n\""
, L"no subitem?"), wxTrapInAssert) ) { wxTrapInAssert = false
; asm volatile ("int $3"); } } while ( (void)0, 0 ); return; }
struct wxDummyCheckStruct3793
;
3794
3795 wxListItemData *itemData = n->GetData();
3796 wxListItem item;
3797
3798 itemData->GetItem(item);
3799 int itemWidth = GetItemWidthWithImage(&item);
3800 if (itemWidth > max)
3801 max = itemWidth;
3802 }
3803
3804 m_aColWidths.Item(col)->bNeedsUpdate = false;
3805 m_aColWidths.Item(col)->nMaxWidth = max;
3806 }
3807
3808 max = m_aColWidths.Item(col)->nMaxWidth;
3809 width = max + AUTOSIZE_COL_MARGIN;
3810 }
3811 }
3812
3813 column->SetWidth( width );
3814
3815 // invalidate it as it has to be recalculated
3816 m_headerWidth = 0;
3817}
3818
3819int wxListMainWindow::GetHeaderWidth() const
3820{
3821 if ( !m_headerWidth )
3822 {
3823 wxListMainWindow *self = wxConstCast(this, wxListMainWindow)const_cast<wxListMainWindow *>(this);
3824
3825 size_t count = GetColumnCount();
3826 for ( size_t col = 0; col < count; col++ )
3827 {
3828 self->m_headerWidth += GetColumnWidth(col);
3829 }
3830 }
3831
3832 return m_headerWidth;
3833}
3834
3835void wxListMainWindow::GetColumn( int col, wxListItem &item ) const
3836{
3837 wxListHeaderDataList::compatibility_iterator node = m_columns.Item( col );
3838 wxCHECK_RET( node, _T("invalid column index in GetColumn") )if ( node ) {} else { do { if ( wxTheAssertHandler &&
(wxOnAssert("extern/wxWidgets/listctrl.cpp", 3838, __FUNCTION__
, "\"node\"", L"invalid column index in GetColumn"), wxTrapInAssert
) ) { wxTrapInAssert = false; asm volatile ("int $3"); } } while
( (void)0, 0 ); return; } struct wxDummyCheckStruct3838
;
3839
3840 wxListHeaderData *column = node->GetData();
3841 column->GetItem( item );
3842}
3843
3844int wxListMainWindow::GetColumnWidth( int col ) const
3845{
3846 wxListHeaderDataList::compatibility_iterator node = m_columns.Item( col );
3847 wxCHECK_MSG( node, 0, _T("invalid column index") )if ( node ) {} else { do { if ( wxTheAssertHandler &&
(wxOnAssert("extern/wxWidgets/listctrl.cpp", 3847, __FUNCTION__
, "\"node\"", L"invalid column index"), wxTrapInAssert) ) { wxTrapInAssert
= false; asm volatile ("int $3"); } } while ( (void)0, 0 ); return
0; } struct wxDummyCheckStruct3847
;
3848
3849 wxListHeaderData *column = node->GetData();
3850 return column->GetWidth();
3851}
3852
3853// ----------------------------------------------------------------------------
3854// item state
3855// ----------------------------------------------------------------------------
3856
3857void wxListMainWindow::SetItem( wxListItem &item )
3858{
3859 long id = item.m_itemId;
3860 wxCHECK_RET( id >= 0 && (size_t)id < GetItemCount(),if ( id >= 0 && (size_t)id < GetItemCount() ) {
} else { do { if ( wxTheAssertHandler && (wxOnAssert(
"extern/wxWidgets/listctrl.cpp", 3861, __FUNCTION__, "\"id >= 0 && (size_t)id < GetItemCount()\""
, L"invalid item index in SetItem"), wxTrapInAssert) ) { wxTrapInAssert
= false; asm volatile ("int $3"); } } while ( (void)0, 0 ); return
; } struct wxDummyCheckStruct3861
3861 _T("invalid item index in SetItem") )if ( id >= 0 && (size_t)id < GetItemCount() ) {
} else { do { if ( wxTheAssertHandler && (wxOnAssert(
"extern/wxWidgets/listctrl.cpp", 3861, __FUNCTION__, "\"id >= 0 && (size_t)id < GetItemCount()\""
, L"invalid item index in SetItem"), wxTrapInAssert) ) { wxTrapInAssert
= false; asm volatile ("int $3"); } } while ( (void)0, 0 ); return
; } struct wxDummyCheckStruct3861
;
3862
3863 if ( !IsVirtual() )
3864 {
3865 wxListLineData *line = GetLine((size_t)id);
3866 line->SetItem( item.m_col, item );
3867
3868 // Set item state if user wants
3869 if ( item.m_mask & wxLIST_MASK_STATE0x0001 )
3870 SetItemState( item.m_itemId, item.m_state, item.m_state );
3871
3872 if (InReportView())
3873 {
3874 // update the Max Width Cache if needed
3875 int width = GetItemWidthWithImage(&item);
3876
3877 if (width > m_aColWidths.Item(item.m_col)->nMaxWidth)
3878 m_aColWidths.Item(item.m_col)->nMaxWidth = width;
3879 }
3880 }
3881
3882 // update the item on screen
3883 wxRect rectItem;
3884 GetItemRect(id, rectItem);
3885 RefreshRect(rectItem);
3886}
3887
3888void wxListMainWindow::SetItemStateAll(long state, long stateMask)
3889{
3890 if ( IsEmpty() )
3891 return;
3892
3893 // first deal with selection
3894 if ( stateMask & wxLIST_STATE_SELECTED0x0004 )
3895 {
3896 // set/clear select state
3897 if ( IsVirtual() )
3898 {
3899 // optimized version for virtual listctrl.
3900 m_selStore.SelectRange(0, GetItemCount() - 1, state == wxLIST_STATE_SELECTED0x0004);
3901 Refresh();
3902 }
3903 else if ( state & wxLIST_STATE_SELECTED0x0004 )
3904 {
3905 const long count = GetItemCount();
3906 for( long i = 0; i < count; i++ )
3907 {
3908 SetItemState( i, wxLIST_STATE_SELECTED0x0004, wxLIST_STATE_SELECTED0x0004 );
3909 }
3910
3911 }
3912 else
3913 {
3914 // clear for non virtual (somewhat optimized by using GetNextItem())
3915 long i = -1;
3916 while ( (i = GetNextItem(i, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED0x0004)) != -1 )
3917 {
3918 SetItemState( i, 0, wxLIST_STATE_SELECTED0x0004 );
3919 }
3920 }
3921 }
3922
3923 if ( HasCurrent() && (state == 0) && (stateMask & wxLIST_STATE_FOCUSED0x0002) )
3924 {
3925 // unfocus all: only one item can be focused, so clearing focus for
3926 // all items is simply clearing focus of the focused item.
3927 SetItemState(m_current, state, stateMask);
3928 }
3929 //(setting focus to all items makes no sense, so it is not handled here.)
3930}
3931
3932void wxListMainWindow::SetItemState( long litem, long state, long stateMask )
3933{
3934 if ( litem == -1 )
3935 {
3936 SetItemStateAll(state, stateMask);
3937 return;
3938 }
3939
3940 wxCHECK_RET( litem >= 0 && (size_t)litem < GetItemCount(),if ( litem >= 0 && (size_t)litem < GetItemCount
() ) {} else { do { if ( wxTheAssertHandler && (wxOnAssert
("extern/wxWidgets/listctrl.cpp", 3941, __FUNCTION__, "\"litem >= 0 && (size_t)litem < GetItemCount()\""
, L"invalid list ctrl item index in SetItem"), wxTrapInAssert
) ) { wxTrapInAssert = false; asm volatile ("int $3"); } } while
( (void)0, 0 ); return; } struct wxDummyCheckStruct3941
3941 _T("invalid list ctrl item index in SetItem") )if ( litem >= 0 && (size_t)litem < GetItemCount
() ) {} else { do { if ( wxTheAssertHandler && (wxOnAssert
("extern/wxWidgets/listctrl.cpp", 3941, __FUNCTION__, "\"litem >= 0 && (size_t)litem < GetItemCount()\""
, L"invalid list ctrl item index in SetItem"), wxTrapInAssert
) ) { wxTrapInAssert = false; asm volatile ("int $3"); } } while
( (void)0, 0 ); return; } struct wxDummyCheckStruct3941
;
3942
3943 size_t oldCurrent = m_current;
3944 size_t item = (size_t)litem; // safe because of the check above
3945
3946 // do we need to change the focus?
3947 if ( stateMask & wxLIST_STATE_FOCUSED0x0002 )
3948 {
3949 if ( state & wxLIST_STATE_FOCUSED0x0002 )
3950 {
3951 // don't do anything if this item is already focused
3952 if ( item != m_current )
3953 {
3954 ChangeCurrent(item);
3955
3956 if ( oldCurrent != (size_t)-1 )
3957 {
3958 if ( IsSingleSel() )
3959 {
3960 HighlightLine(oldCurrent, false);
3961 }
3962
3963 RefreshLine(oldCurrent);
3964 }
3965
3966 RefreshLine( m_current );
3967 }
3968 }
3969 else // unfocus
3970 {
3971 // don't do anything if this item is not focused
3972 if ( item == m_current )
3973 {
3974 ResetCurrent();
3975
3976 if ( IsSingleSel() )
3977 {
3978 // we must unselect the old current item as well or we
3979 // might end up with more than one selected item in a
3980 // single selection control
3981 HighlightLine(oldCurrent, false);
3982 }
3983
3984 RefreshLine( oldCurrent );
3985 }
3986 }
3987 }
3988
3989 // do we need to change the selection state?
3990 if ( stateMask & wxLIST_STATE_SELECTED0x0004 )
3991 {
3992 bool on = (state & wxLIST_STATE_SELECTED0x0004) != 0;
3993
3994 if ( IsSingleSel() )
3995 {
3996 if ( on )
3997 {
3998 // selecting the item also makes it the focused one in the
3999 // single sel mode
4000 if ( m_current != item )
4001 {
4002 ChangeCurrent(item);
4003
4004 if ( oldCurrent != (size_t)-1 )
4005 {
4006 HighlightLine( oldCurrent, false );
4007 RefreshLine( oldCurrent );
4008 }
4009 }
4010 }
4011 else // off
4012 {
4013 // only the current item may be selected anyhow
4014 if ( item != m_current )
4015 return;
4016 }
4017 }
4018
4019 if ( HighlightLine(item, on) )
4020 {
4021 RefreshLine(item);
4022 }
4023 }
4024}
4025
4026int wxListMainWindow::GetItemState( long item, long stateMask ) const
4027{
4028 wxCHECK_MSG( item >= 0 && (size_t)item < GetItemCount(), 0,if ( item >= 0 && (size_t)item < GetItemCount()
) {} else { do { if ( wxTheAssertHandler && (wxOnAssert
("extern/wxWidgets/listctrl.cpp", 4029, __FUNCTION__, "\"item >= 0 && (size_t)item < GetItemCount()\""
, L"invalid list ctrl item index in GetItemState()"), wxTrapInAssert
) ) { wxTrapInAssert = false; asm volatile ("int $3"); } } while
( (void)0, 0 ); return 0; } struct wxDummyCheckStruct4029
4029 _T("invalid list ctrl item index in GetItemState()") )if ( item >= 0 && (size_t)item < GetItemCount()
) {} else { do { if ( wxTheAssertHandler && (wxOnAssert
("extern/wxWidgets/listctrl.cpp", 4029, __FUNCTION__, "\"item >= 0 && (size_t)item < GetItemCount()\""
, L"invalid list ctrl item index in GetItemState()"), wxTrapInAssert
) ) { wxTrapInAssert = false; asm volatile ("int $3"); } } while
( (void)0, 0 ); return 0; } struct wxDummyCheckStruct4029
;
4030
4031 int ret = wxLIST_STATE_DONTCARE0x0000;
4032
4033 if ( stateMask & wxLIST_STATE_FOCUSED0x0002 )
4034 {
4035 if ( (size_t)item == m_current )
4036 ret |= wxLIST_STATE_FOCUSED0x0002;
4037 }
4038
4039 if ( stateMask & wxLIST_STATE_SELECTED0x0004 )
4040 {
4041 if ( IsHighlighted(item) )
4042 ret |= wxLIST_STATE_SELECTED0x0004;
4043 }
4044
4045 return ret;
4046}
4047
4048void wxListMainWindow::GetItem( wxListItem &item ) const
4049{
4050 wxCHECK_RET( item.m_itemId >= 0 && (size_t)item.m_itemId < GetItemCount(),if ( item.m_itemId >= 0 && (size_t)item.m_itemId <
GetItemCount() ) {} else { do { if ( wxTheAssertHandler &&
(wxOnAssert("extern/wxWidgets/listctrl.cpp", 4051, __FUNCTION__
, "\"item.m_itemId >= 0 && (size_t)item.m_itemId < GetItemCount()\""
, L"invalid item index in GetItem"), wxTrapInAssert) ) { wxTrapInAssert
= false; asm volatile ("int $3"); } } while ( (void)0, 0 ); return
; } struct wxDummyCheckStruct4051
4051 _T("invalid item index in GetItem") )if ( item.m_itemId >= 0 && (size_t)item.m_itemId <
GetItemCount() ) {} else { do { if ( wxTheAssertHandler &&
(wxOnAssert("extern/wxWidgets/listctrl.cpp", 4051, __FUNCTION__
, "\"item.m_itemId >= 0 && (size_t)item.m_itemId < GetItemCount()\""
, L"invalid item index in GetItem"), wxTrapInAssert) ) { wxTrapInAssert
= false; asm volatile ("int $3"); } } while ( (void)0, 0 ); return
; } struct wxDummyCheckStruct4051
;
4052
4053 wxListLineData *line = GetLine((size_t)item.m_itemId);
4054 line->GetItem( item.m_col, item );
4055
4056 // Get item state if user wants it
4057 if ( item.m_mask & wxLIST_MASK_STATE0x0001 )
4058 item.m_state = GetItemState( item.m_itemId, wxLIST_STATE_SELECTED0x0004 |
4059 wxLIST_STATE_FOCUSED0x0002 );
4060}
4061
4062// ----------------------------------------------------------------------------
4063// item count
4064// ----------------------------------------------------------------------------
4065
4066size_t wxListMainWindow::GetItemCount() const
4067{
4068 return IsVirtual() ? m_countVirt : m_lines.GetCount();
6
Calling 'wxListMainWindow::IsVirtual'
4069}
4070
4071void wxListMainWindow::SetItemCount(long count)
4072{
4073 m_selStore.SetItemCount(count);
4074 m_countVirt = count;
4075
4076 ResetVisibleLinesRange();
4077
4078 // scrollbars must be reset
4079 m_dirty = true;
4080}
4081
4082int wxListMainWindow::GetSelectedItemCount() const
4083{
4084 // deal with the quick case first
4085 if ( IsSingleSel() )
4086 return HasCurrent() ? IsHighlighted(m_current) : false;
4087
4088 // virtual controls remembers all its selections itself
4089 if ( IsVirtual() )
4090 return m_selStore.GetSelectedCount();
4091
4092 // TODO: we probably should maintain the number of items selected even for
4093 // non virtual controls as enumerating all lines is really slow...
4094 size_t countSel = 0;
4095 size_t count = GetItemCount();
4096 for ( size_t line = 0; line < count; line++ )
4097 {
4098 if ( GetLine(line)->IsHighlighted() )
4099 countSel++;
4100 }
4101
4102 return countSel;
4103}
4104
4105// ----------------------------------------------------------------------------
4106// item position/size
4107// ----------------------------------------------------------------------------
4108
4109wxRect wxListMainWindow::GetViewRect() const
4110{
4111 wxASSERT_MSG( !HasFlag(wxLC_REPORT | wxLC_LIST),do { if ( !HasFlag(0x0020 | 0x0010) ) { } else if ( wxTheAssertHandler
&& (wxOnAssert("extern/wxWidgets/listctrl.cpp", 4112
, __FUNCTION__, "!HasFlag(0x0020 | 0x0010)", L"wxListCtrl::GetViewRect() only works in icon mode"
), wxTrapInAssert) ) { wxTrapInAssert = false; asm volatile (
"int $3"); } } while ( (void)0, 0 )
4112 _T("wxListCtrl::GetViewRect() only works in icon mode") )do { if ( !HasFlag(0x0020 | 0x0010) ) { } else if ( wxTheAssertHandler
&& (wxOnAssert("extern/wxWidgets/listctrl.cpp", 4112
, __FUNCTION__, "!HasFlag(0x0020 | 0x0010)", L"wxListCtrl::GetViewRect() only works in icon mode"
), wxTrapInAssert) ) { wxTrapInAssert = false; asm volatile (
"int $3"); } } while ( (void)0, 0 )
;
4113
4114 // we need to find the longest/tallest label
4115 wxCoord xMax = 0, yMax = 0;
4116 const int count = GetItemCount();
4117 if ( count )
4118 {
4119 for ( int i = 0; i < count; i++ )
4120 {
4121 // we need logical, not physical, coordinates here, so use
4122 // GetLineRect() instead of GetItemRect()
4123 wxRect r = GetLineRect(i);
4124
4125 wxCoord x = r.GetRight(),
4126 y = r.GetBottom();
4127
4128 if ( x > xMax )
4129 xMax = x;
4130 if ( y > yMax )
4131 yMax = y;
4132 }
4133 }
4134
4135 // some fudge needed to make it look prettier
4136 xMax += 2 * EXTRA_BORDER_X;
4137 yMax += 2 * EXTRA_BORDER_Y;
4138
4139 // account for the scrollbars if necessary
4140 const wxSize sizeAll = GetClientSize();
4141 if ( xMax > sizeAll.x )
4142 yMax += wxSystemSettings::GetMetric(wxSYS_HSCROLL_Y);
4143 if ( yMax > sizeAll.y )
4144 xMax += wxSystemSettings::GetMetric(wxSYS_VSCROLL_X);
4145
4146 return wxRect(0, 0, xMax, yMax);
4147}
4148
4149void wxListMainWindow::GetItemRect( long index, wxRect &rect ) const
4150{
4151 wxCHECK_RET( index >= 0 && (size_t)index < GetItemCount(),if ( index >= 0 && (size_t)index < GetItemCount
() ) {} else { do { if ( wxTheAssertHandler && (wxOnAssert
("extern/wxWidgets/listctrl.cpp", 4152, __FUNCTION__, "\"index >= 0 && (size_t)index < GetItemCount()\""
, L"invalid index in GetItemRect"), wxTrapInAssert) ) { wxTrapInAssert
= false; asm volatile ("int $3"); } } while ( (void)0, 0 ); return
; } struct wxDummyCheckStruct4152
4152 _T("invalid index in GetItemRect") )if ( index >= 0 && (size_t)index < GetItemCount
() ) {} else { do { if ( wxTheAssertHandler && (wxOnAssert
("extern/wxWidgets/listctrl.cpp", 4152, __FUNCTION__, "\"index >= 0 && (size_t)index < GetItemCount()\""
, L"invalid index in GetItemRect"), wxTrapInAssert) ) { wxTrapInAssert
= false; asm volatile ("int $3"); } } while ( (void)0, 0 ); return
; } struct wxDummyCheckStruct4152
;
4153
4154 // ensure that we're laid out, otherwise we could return nonsense
4155 if ( m_dirty )
4156 {
4157 wxConstCast(this, wxListMainWindow)const_cast<wxListMainWindow *>(this)->
4158 RecalculatePositions(true /* no refresh */);
4159 }
4160
4161 rect = GetLineRect((size_t)index);
4162
4163 CalcScrolledPosition(rect.x, rect.y, &rect.x, &rect.y);
4164}
4165
4166bool wxListMainWindow::GetItemPosition(long item, wxPoint& pos) const
4167{
4168 wxRect rect;
4169 GetItemRect(item, rect);
4170
4171 pos.x = rect.x;
4172 pos.y = rect.y;
4173
4174 return true;
4175}
4176
4177// ----------------------------------------------------------------------------
4178// geometry calculation
4179// ----------------------------------------------------------------------------
4180
4181void wxListMainWindow::RecalculatePositions(bool noRefresh)
4182{
4183 const int lineHeight = GetLineHeight();
4184
4185 wxClientDC dc( this );
4186 dc.SetFont( GetFont() );
4187
4188 const size_t count = GetItemCount();
4189
4190 int iconSpacing;
4191 if ( HasFlag(wxLC_ICON0x0004) && m_normal_image_list )
4192 iconSpacing = m_normal_spacing;
4193 else if ( HasFlag(wxLC_SMALL_ICON0x0008) && m_small_image_list )
4194 iconSpacing = m_small_spacing;
4195 else
4196 iconSpacing = 0;
4197
4198 // Note that we do not call GetClientSize() here but
4199 // GetSize() and subtract the border size for sunken
4200 // borders manually. This is technically incorrect,
4201 // but we need to know the client area's size WITHOUT
4202 // scrollbars here. Since we don't know if there are
4203 // any scrollbars, we use GetSize() instead. Another
4204 // solution would be to call SetScrollbars() here to
4205 // remove the scrollbars and call GetClientSize() then,
4206 // but this might result in flicker and - worse - will
4207 // reset the scrollbars to 0 which is not good at all
4208 // if you resize a dialog/window, but don't want to
4209 // reset the window scrolling. RR.
4210 // Furthermore, we actually do NOT subtract the border
4211 // width as 2 pixels is just the extra space which we
4212 // need around the actual content in the window. Other-
4213 // wise the text would e.g. touch the upper border. RR.
4214 int clientWidth,
4215 clientHeight;
4216 GetSize( &clientWidth, &clientHeight );
4217
4218 if ( InReportView() )
4219 {
4220 // all lines have the same height and we scroll one line per step
4221 int entireHeight = count * lineHeight + LINE_SPACING;
4222
4223 m_linesPerPage = clientHeight / lineHeight;
4224
4225 ResetVisibleLinesRange();
4226
4227 SetScrollbars( SCROLL_UNIT_X, lineHeight,
4228 GetHeaderWidth() / SCROLL_UNIT_X,
4229 (entireHeight + lineHeight - 1) / lineHeight,
4230 GetScrollPos(wxHORIZONTAL),
4231 GetScrollPos(wxVERTICAL),
4232 true );
4233 }
4234 else // !report
4235 {
4236 // we have 3 different layout strategies: either layout all items
4237 // horizontally/vertically (wxLC_ALIGN_XXX styles explicitly given) or
4238 // to arrange them in top to bottom, left to right (don't ask me why
4239 // not the other way round...) order
4240 if ( HasFlag(wxLC_ALIGN_LEFT0x0080 | wxLC_ALIGN_TOP0x0040) )
4241 {
4242 int x = EXTRA_BORDER_X;
4243 int y = EXTRA_BORDER_Y;
4244
4245 wxCoord widthMax = 0;
4246
4247 size_t i;
4248 for ( i = 0; i < count; i++ )
4249 {
4250 wxListLineData *line = GetLine(i);
4251 line->CalculateSize( &dc, iconSpacing );
4252 line->SetPosition( x, y, iconSpacing );
4253
4254 wxSize sizeLine = GetLineSize(i);
4255
4256 if ( HasFlag(wxLC_ALIGN_TOP0x0040) )
4257 {
4258 if ( sizeLine.x > widthMax )
4259 widthMax = sizeLine.x;
4260
4261 y += sizeLine.y;
4262 }
4263 else // wxLC_ALIGN_LEFT
4264 {
4265 x += sizeLine.x + MARGIN_BETWEEN_ROWS;
4266 }
4267 }
4268
4269 if ( HasFlag(wxLC_ALIGN_TOP0x0040) )
4270 {
4271 // traverse the items again and tweak their sizes so that they are
4272 // all the same in a row
4273 for ( i = 0; i < count; i++ )
4274 {
4275 wxListLineData *line = GetLine(i);
4276 line->m_gi->ExtendWidth(widthMax);
4277 }
4278 }
4279
4280 SetScrollbars
4281 (
4282 SCROLL_UNIT_X,
4283 lineHeight,
4284 (x + SCROLL_UNIT_X) / SCROLL_UNIT_X,
4285 (y + lineHeight) / lineHeight,
4286 GetScrollPos( wxHORIZONTAL ),
4287 GetScrollPos( wxVERTICAL ),
4288 true
4289 );
4290 }
4291 else // "flowed" arrangement, the most complicated case
4292 {
4293 // at first we try without any scrollbars, if the items don't fit into
4294 // the window, we recalculate after subtracting the space taken by the
4295 // scrollbar
4296
4297 int entireWidth = 0;
4298
4299 for (int tries = 0; tries < 2; tries++)
4300 {
4301 entireWidth = 2 * EXTRA_BORDER_X;
4302
4303 if (tries == 1)
4304 {
4305 // Now we have decided that the items do not fit into the
4306 // client area, so we need a scrollbar
4307 entireWidth += SCROLL_UNIT_X;
4308 }
4309
4310 int x = EXTRA_BORDER_X;
4311 int y = EXTRA_BORDER_Y;
4312 int maxWidthInThisRow = 0;
4313
4314 m_linesPerPage = 0;
4315 int currentlyVisibleLines = 0;
4316
4317 for (size_t i = 0; i < count; i++)
4318 {
4319 currentlyVisibleLines++;
4320 wxListLineData *line = GetLine( i );
4321 line->CalculateSize( &dc, iconSpacing );
4322 line->SetPosition( x, y, iconSpacing );
4323
4324 wxSize sizeLine = GetLineSize( i );
4325
4326 if ( maxWidthInThisRow < sizeLine.x )
4327 maxWidthInThisRow = sizeLine.x;
4328
4329 y += sizeLine.y;
4330 if (currentlyVisibleLines > m_linesPerPage)
4331 m_linesPerPage = currentlyVisibleLines;
4332
4333 if ( y + sizeLine.y >= clientHeight )
4334 {
4335 currentlyVisibleLines = 0;
4336 y = EXTRA_BORDER_Y;
4337 maxWidthInThisRow += MARGIN_BETWEEN_ROWS;
4338 x += maxWidthInThisRow;
4339 entireWidth += maxWidthInThisRow;
4340 maxWidthInThisRow = 0;
4341 }
4342
4343 // We have reached the last item.
4344 if ( i == count - 1 )
4345 entireWidth += maxWidthInThisRow;
4346
4347 if ( (tries == 0) &&
4348 (entireWidth + SCROLL_UNIT_X > clientWidth) )
4349 {
4350 clientHeight -= wxSystemSettings::
4351 GetMetric(wxSYS_HSCROLL_Y);
4352 m_linesPerPage = 0;
4353 break;
4354 }
4355
4356 if ( i == count - 1 )
4357 tries = 1; // Everything fits, no second try required.
4358 }
4359 }
4360
4361 SetScrollbars
4362 (
4363 SCROLL_UNIT_X,
4364 lineHeight,
4365 (entireWidth + SCROLL_UNIT_X) / SCROLL_UNIT_X,
4366 0,
4367 GetScrollPos( wxHORIZONTAL ),
4368 0,
4369 true
4370 );
4371 }
4372 }
4373
4374 if ( !noRefresh )
4375 {
4376 // FIXME: why should we call it from here?
4377 UpdateCurrent();
4378
4379 RefreshAll();
4380 }
4381}
4382
4383void wxListMainWindow::RefreshAll()
4384{
4385 m_dirty = false;
4386 Refresh();
4387
4388 wxListHeaderWindow *headerWin = GetListCtrl()->m_headerWin;
4389 if ( headerWin && headerWin->m_dirty )
4390 {
4391 headerWin->m_dirty = false;
4392 headerWin->Refresh();
4393 }
4394}
4395
4396void wxListMainWindow::UpdateCurrent()
4397{
4398 if ( !HasCurrent() && !IsEmpty() )
4399 ChangeCurrent(0);
4400}
4401
4402long wxListMainWindow::GetNextItem( long item,
4403 int WXUNUSED(geometry),
4404 int state ) const
4405{
4406 long ret = item,
4407 max = GetItemCount();
4408 wxCHECK_MSG( (ret == -1) || (ret < max), -1,if ( (ret == -1) || (ret < max) ) {} else { do { if ( wxTheAssertHandler
&& (wxOnAssert("extern/wxWidgets/listctrl.cpp", 4409
, __FUNCTION__, "\"(ret == -1) || (ret < max)\"", L"invalid listctrl index in GetNextItem()"
), wxTrapInAssert) ) { wxTrapInAssert = false; asm volatile (
"int $3"); } } while ( (void)0, 0 ); return -1; } struct wxDummyCheckStruct4409
4409 _T("invalid listctrl index in GetNextItem()") )if ( (ret == -1) || (ret < max) ) {} else { do { if ( wxTheAssertHandler
&& (wxOnAssert("extern/wxWidgets/listctrl.cpp", 4409
, __FUNCTION__, "\"(ret == -1) || (ret < max)\"", L"invalid listctrl index in GetNextItem()"
), wxTrapInAssert) ) { wxTrapInAssert = false; asm volatile (
"int $3"); } } while ( (void)0, 0 ); return -1; } struct wxDummyCheckStruct4409
;
4410
4411 // notice that we start with the next item (or the first one if item == -1)
4412 // and this is intentional to allow writing a simple loop to iterate over
4413 // all selected items
4414 ret++;
4415 if ( ret == max )
4416 // this is not an error because the index was OK initially,
4417 // just no such item
4418 return -1;
4419
4420 if ( !state )
4421 // any will do
4422 return (size_t)ret;
4423
4424 size_t count = GetItemCount();
4425 for ( size_t line = (size_t)ret; line < count; line++ )
4426 {
4427 if ( (state & wxLIST_STATE_FOCUSED0x0002) && (line == m_current) )
4428 return line;
4429
4430 if ( (state & wxLIST_STATE_SELECTED0x0004) && IsHighlighted(line) )
4431 return line;
4432 }
4433
4434 return -1;
4435}
4436
4437// ----------------------------------------------------------------------------
4438// deleting stuff
4439// ----------------------------------------------------------------------------
4440
4441void wxListMainWindow::DeleteItem( long lindex )
4442{
4443 size_t count = GetItemCount();
4444
4445 wxCHECK_RET( (lindex >= 0) && ((size_t)lindex < count),if ( (lindex >= 0) && ((size_t)lindex < count) )
{} else { do { if ( wxTheAssertHandler && (wxOnAssert
("extern/wxWidgets/listctrl.cpp", 4446, __FUNCTION__, "\"(lindex >= 0) && ((size_t)lindex < count)\""
, L"invalid item index in DeleteItem"), wxTrapInAssert) ) { wxTrapInAssert
= false; asm volatile ("int $3"); } } while ( (void)0, 0 ); return
; } struct wxDummyCheckStruct4446
4446 _T("invalid item index in DeleteItem") )if ( (lindex >= 0) && ((size_t)lindex < count) )
{} else { do { if ( wxTheAssertHandler && (wxOnAssert
("extern/wxWidgets/listctrl.cpp", 4446, __FUNCTION__, "\"(lindex >= 0) && ((size_t)lindex < count)\""
, L"invalid item index in DeleteItem"), wxTrapInAssert) ) { wxTrapInAssert
= false; asm volatile ("int $3"); } } while ( (void)0, 0 ); return
; } struct wxDummyCheckStruct4446
;
4447
4448 size_t index = (size_t)lindex;
4449
4450 // we don't need to adjust the index for the previous items
4451 if ( HasCurrent() && m_current >= index )
4452 {
4453 // if the current item is being deleted, we want the next one to
4454 // become selected - unless there is no next one - so don't adjust
4455 // m_current in this case
4456 if ( m_current != index || m_current == count - 1 )
4457 m_current--;
4458 }
4459
4460 if ( InReportView() )
4461 {
4462 // mark the Column Max Width cache as dirty if the items in the line
4463 // we're deleting contain the Max Column Width
4464 wxListLineData * const line = GetLine(index);
4465 wxListItemDataList::compatibility_iterator n;
4466 wxListItemData *itemData;
4467 wxListItem item;
4468 int itemWidth;
4469
4470 for (size_t i = 0; i < m_columns.GetCount(); i++)
4471 {
4472 n = line->m_items.Item( i );
4473 itemData = n->GetData();
4474 itemData->GetItem(item);
4475
4476 itemWidth = GetItemWidthWithImage(&item);
4477
4478 if (itemWidth >= m_aColWidths.Item(i)->nMaxWidth)
4479 m_aColWidths.Item(i)->bNeedsUpdate = true;
4480 }
4481
4482 ResetVisibleLinesRange();
4483 }
4484
4485 SendNotify( index, wxEVT_COMMAND_LIST_DELETE_ITEMwxEVT_LIST_DELETE_ITEM, wxDefaultPosition );
4486
4487 if ( IsVirtual() )
4488 {
4489 m_countVirt--;
4490 m_selStore.OnItemDelete(index);
4491 }
4492 else
4493 {
4494 m_lines.RemoveAt( index );
4495 }
4496
4497 // we need to refresh the (vert) scrollbar as the number of items changed
4498 m_dirty = true;
4499
4500 RefreshAfter(index);
4501}
4502
4503void wxListMainWindow::DeleteColumn( int col )
4504{
4505 wxListHeaderDataList::compatibility_iterator node = m_columns.Item( col );
4506
4507 wxCHECK_RET( node, wxT("invalid column index in DeleteColumn()") )if ( node ) {} else { do { if ( wxTheAssertHandler &&
(wxOnAssert("extern/wxWidgets/listctrl.cpp", 4507, __FUNCTION__
, "\"node\"", L"invalid column index in DeleteColumn()"), wxTrapInAssert
) ) { wxTrapInAssert = false; asm volatile ("int $3"); } } while
( (void)0, 0 ); return; } struct wxDummyCheckStruct4507
;
4508
4509 m_dirty = true;
4510 delete node->GetData();
4511 m_columns.Erase( node );
4512
4513 if ( !IsVirtual() )
4514 {
4515 // update all the items
4516 for ( size_t i = 0; i < m_lines.GetCount(); i++ )
4517 {
4518 wxListLineData * const line = GetLine(i);
4519 wxListItemDataList::compatibility_iterator n = line->m_items.Item( col );
4520 delete n->GetData();
4521 line->m_items.Erase(n);
4522 }
4523 }
4524
4525 if ( InReportView() ) // we only cache max widths when in Report View
4526 {
4527 delete m_aColWidths.Item(col);
4528 m_aColWidths.RemoveAt(col);
4529 }
4530
4531 // invalidate it as it has to be recalculated
4532 m_headerWidth = 0;
4533}
4534
4535void wxListMainWindow::DoDeleteAllItems()
4536{
4537 if ( IsEmpty() )
4538 // nothing to do - in particular, don't send the event
4539 return;
4540
4541 ResetCurrent();
4542
4543 // to make the deletion of all items faster, we don't send the
4544 // notifications for each item deletion in this case but only one event
4545 // for all of them: this is compatible with wxMSW and documented in
4546 // DeleteAllItems() description
4547
4548 wxListEvent event( wxEVT_COMMAND_LIST_DELETE_ALL_ITEMSwxEVT_LIST_DELETE_ALL_ITEMS, GetParent()->GetId() );
4549 event.SetEventObject( GetParent() );
4550 GetParent()->GetEventHandler()->ProcessEvent( event );
4551
4552 if ( IsVirtual() )
4553 {
4554 m_countVirt = 0;
4555 m_selStore.Clear();
4556 }
4557
4558 if ( InReportView() )
4559 {
4560 ResetVisibleLinesRange();
4561 for (size_t i = 0; i < m_aColWidths.GetCount(); i++)
4562 {
4563 m_aColWidths.Item(i)->bNeedsUpdate = true;
4564 }
4565 }
4566
4567 m_lines.Clear();
4568}
4569
4570void wxListMainWindow::DeleteAllItems()
4571{
4572 DoDeleteAllItems();
4573
4574 RecalculatePositions();
4575}
4576
4577void wxListMainWindow::DeleteEverything()
4578{
4579 WX_CLEAR_LIST(wxListHeaderDataList, m_columns){ wxListHeaderDataList::iterator it, en; for( it = (m_columns
).begin(), en = (m_columns).end(); it != en; ++it ) delete *it
; (m_columns).clear(); }
;
4580 WX_CLEAR_ARRAY(m_aColWidths);
4581
4582 DeleteAllItems();
4583}
4584
4585// ----------------------------------------------------------------------------
4586// scanning for an item
4587// ----------------------------------------------------------------------------
4588
4589void wxListMainWindow::EnsureVisible( long index )
4590{
4591 wxCHECK_RET( index >= 0 && (size_t)index < GetItemCount(),if ( index >= 0 && (size_t)index < GetItemCount
() ) {} else { do { if ( wxTheAssertHandler && (wxOnAssert
("extern/wxWidgets/listctrl.cpp", 4592, __FUNCTION__, "\"index >= 0 && (size_t)index < GetItemCount()\""
, L"invalid index in EnsureVisible"), wxTrapInAssert) ) { wxTrapInAssert
= false; asm volatile ("int $3"); } } while ( (void)0, 0 ); return
; } struct wxDummyCheckStruct4592
4592 _T("invalid index in EnsureVisible") )if ( index >= 0 && (size_t)index < GetItemCount
() ) {} else { do { if ( wxTheAssertHandler && (wxOnAssert
("extern/wxWidgets/listctrl.cpp", 4592, __FUNCTION__, "\"index >= 0 && (size_t)index < GetItemCount()\""
, L"invalid index in EnsureVisible"), wxTrapInAssert) ) { wxTrapInAssert
= false; asm volatile ("int $3"); } } while ( (void)0, 0 ); return
; } struct wxDummyCheckStruct4592
;
4593
4594 // We have to call this here because the label in question might just have
4595 // been added and its position is not known yet
4596 if ( m_dirty )
4597 RecalculatePositions(true /* no refresh */);
4598
4599 MoveToItem((size_t)index);
4600}
4601
4602long wxListMainWindow::FindItem(long start, const wxString& str, bool partial )
4603{
4604 if (str.empty())
4605 return wxNOT_FOUND(-1);
4606
4607 long pos = start;
4608 wxString str_upper = str.Upper();
4609 if (pos < 0)
4610 pos = 0;
4611
4612 size_t count = GetItemCount();
4613 for ( size_t i = (size_t)pos; i < count; i++ )
4614 {
4615 wxListLineData *line = GetLine(i);
4616 wxString line_upper = line->GetText(0).Upper();
4617 if (!partial)
4618 {
4619 if (line_upper == str_upper )
4620 return i;
4621 }
4622 else
4623 {
4624 if (line_upper.find(str_upper) == 0)
4625 return i;
4626 }
4627 }
4628
4629 return wxNOT_FOUND(-1);
4630}
4631
4632long wxListMainWindow::FindItem(long start, wxUIntPtr data)
4633{
4634 long pos = start;
4635 if (pos < 0)
4636 pos = 0;
4637
4638 size_t count = GetItemCount();
4639 for (size_t i = (size_t)pos; i < count; i++)
4640 {
4641 wxListLineData *line = GetLine(i);
4642 wxListItem item;
4643 line->GetItem( 0, item );
4644 if (item.m_data == data)
4645 return i;
4646 }
4647
4648 return wxNOT_FOUND(-1);
4649}
4650
4651long wxListMainWindow::FindItem( const wxPoint& pt )
4652{
4653 size_t topItem;
4654 GetVisibleLinesRange( &topItem, NULL__null );
4655
4656 wxPoint p;
4657 GetItemPosition( GetItemCount() - 1, p );
4658 if ( p.y == 0 )
4659 return topItem;
4660
4661 long id = (long)floor( pt.y * double(GetItemCount() - topItem - 1) / p.y + topItem );
4662 if ( id >= 0 && id < (long)GetItemCount() )
4663 return id;
4664
4665 return wxNOT_FOUND(-1);
4666}
4667
4668long wxListMainWindow::HitTest( int x, int y, int &flags ) const
4669{
4670 CalcUnscrolledPosition( x, y, &x, &y );
4671
4672 size_t count = GetItemCount();
4673
4674 if ( InReportView() )
4675 {
4676 size_t current = y / GetLineHeight();
4677 if ( current < count )
4678 {
4679 flags = HitTestLine(current, x, y);
4680 if ( flags )
4681 return current;
4682 }
4683 }
4684 else // !report
4685 {
4686 // TODO: optimize it too! this is less simple than for report view but
4687 // enumerating all items is still not a way to do it!!
4688 for ( size_t current = 0; current < count; current++ )
4689 {
4690 flags = HitTestLine(current, x, y);
4691 if ( flags )
4692 return current;
4693 }
4694 }
4695
4696 return wxNOT_FOUND(-1);
4697}
4698
4699// ----------------------------------------------------------------------------
4700// adding stuff
4701// ----------------------------------------------------------------------------
4702
4703void wxListMainWindow::InsertItem( wxListItem &item )
4704{
4705 wxASSERT_MSG( !IsVirtual(), _T("can't be used with virtual control") )do { if ( !IsVirtual() ) { } else if ( wxTheAssertHandler &&
(wxOnAssert("extern/wxWidgets/listctrl.cpp", 4705, __FUNCTION__
, "!IsVirtual()", L"can't be used with virtual control"), wxTrapInAssert
) ) { wxTrapInAssert = false; asm volatile ("int $3"); } } while
( (void)0, 0 )
;
4706
4707 int count = GetItemCount();
4708 wxCHECK_RET( item.m_itemId >= 0, _T("invalid item index") )if ( item.m_itemId >= 0 ) {} else { do { if ( wxTheAssertHandler
&& (wxOnAssert("extern/wxWidgets/listctrl.cpp", 4708
, __FUNCTION__, "\"item.m_itemId >= 0\"", L"invalid item index"
), wxTrapInAssert) ) { wxTrapInAssert = false; asm volatile (
"int $3"); } } while ( (void)0, 0 ); return; } struct wxDummyCheckStruct4708
;
4709
4710 if (item.m_itemId > count)
4711 item.m_itemId = count;
4712
4713 size_t id = item.m_itemId;
4714
4715 m_dirty = true;
4716
4717 if ( InReportView() )
4718 {
4719 ResetVisibleLinesRange();
4720
4721 // calculate the width of the item and adjust the max column width
4722 wxColWidthInfo *pWidthInfo = m_aColWidths.Item(item.GetColumn());
4723 int width = GetItemWidthWithImage(&item);
4724 item.SetWidth(width);
4725 if (width > pWidthInfo->nMaxWidth)
4726 pWidthInfo->nMaxWidth = width;
4727 }
4728
4729 wxListLineData *line = new wxListLineData(this);
4730
4731 line->SetItem( item.m_col, item );
4732
4733 m_lines.Insert( line, id );
4734
4735 m_dirty = true;
4736
4737 // If an item is selected at or below the point of insertion, we need to
4738 // increment the member variables because the current row's index has gone
4739 // up by one
4740 if ( HasCurrent() && m_current >= id )
4741 m_current++;
4742
4743 SendNotify(id, wxEVT_COMMAND_LIST_INSERT_ITEMwxEVT_LIST_INSERT_ITEM);
4744
4745 RefreshLines(id, GetItemCount() - 1);
4746}
4747
4748void wxListMainWindow::InsertColumn( long col, wxListItem &item )
4749{
4750 m_dirty = true;
4751 if ( InReportView() )
4752 {
4753 if (item.m_width == wxLIST_AUTOSIZE_USEHEADER)
4754 item.m_width = GetTextLength( item.m_text );
4755
4756 wxListHeaderData *column = new wxListHeaderData( item );
4757 wxColWidthInfo *colWidthInfo = new wxColWidthInfo();
4758
4759 bool insert = (col >= 0) && ((size_t)col < m_columns.GetCount());
4760 if ( insert )
4761 {
4762 wxListHeaderDataList::compatibility_iterator
4763 node = m_columns.Item( col );
4764 m_columns.Insert( node, column );
4765 m_aColWidths.Insert( colWidthInfo, col );
4766 }
4767 else
4768 {
4769 m_columns.Append( column );
4770 m_aColWidths.Add( colWidthInfo );
4771 }
4772
4773 if ( !IsVirtual() )
4774 {
4775 // update all the items
4776 for ( size_t i = 0; i < m_lines.GetCount(); i++ )
4777 {
4778 wxListLineData * const line = GetLine(i);
4779 wxListItemData * const data = new wxListItemData(this);
4780 if ( insert )
4781 line->m_items.Insert(col, data);
4782 else
4783 line->m_items.Append(data);
4784 }
4785 }
4786
4787 // invalidate it as it has to be recalculated
4788 m_headerWidth = 0;
4789 }
4790}
4791
4792int wxListMainWindow::GetItemWidthWithImage(wxListItem * item)
4793{
4794 int width = 0;
4795 wxClientDC dc(this);
4796
4797 dc.SetFont( GetFont() );
4798
4799 if (item->GetImage() != -1)
4800 {
4801 int ix, iy;
4802 GetImageSize( item->GetImage(), ix, iy );
4803 width += ix + 5;
4804 }
4805
4806 if (!item->GetText().empty())
4807 {
4808 wxCoord w;
4809 dc.GetTextExtent( item->GetText(), &w, NULL__null );
4810 width += w;
4811 }
4812
4813 return width;
4814}
4815
4816// ----------------------------------------------------------------------------
4817// sorting
4818// ----------------------------------------------------------------------------
4819
4820MuleListCtrlCompare list_ctrl_compare_func_2;
4821long list_ctrl_compare_data;
4822
4823static int LINKAGEMODE list_ctrl_compare_func_1( wxListLineData **arg1, wxListLineData **arg2 )
4824{
4825 wxListLineData *line1 = *arg1;
4826 wxListLineData *line2 = *arg2;
4827 wxListItem item;
4828 line1->GetItem( 0, item );
4829 wxUIntPtr data1 = item.m_data;
4830 line2->GetItem( 0, item );
4831 wxUIntPtr data2 = item.m_data;
4832 return list_ctrl_compare_func_2( data1, data2, list_ctrl_compare_data );
4833}
4834
4835void wxListMainWindow::SortItems( MuleListCtrlCompare fn, long data )
4836{
4837 // selections won't make sense any more after sorting the items so reset
4838 // them
4839 HighlightAll(false);
4840 ResetCurrent();
4841
4842 list_ctrl_compare_func_2 = fn;
4843 list_ctrl_compare_data = data;
4844 m_lines.Sort( list_ctrl_compare_func_1 );
4845 m_dirty = true;
4846}
4847
4848// ----------------------------------------------------------------------------
4849// scrolling
4850// ----------------------------------------------------------------------------
4851
4852void wxListMainWindow::OnScroll(wxScrollWinEvent& event)
4853{
4854 // wxScrolledWindows::OnScroll is deprecated in wx 3.0.0 and it does not exist anymore in 3.1.0.
4855 // Please also notice that call to
4856 // - wxScrolledWindow::OnScroll
4857 // - HandleOnScroll
4858 // have been removed in code present in
4859 // src/generic/listctrl.cpp, wxListMainWindow::OnScroll
4860 // of wxWidgets 3.0
4861 // FIXME
4862 HandleOnScroll( event );
4863
4864 // update our idea of which lines are shown when we redraw the window the
4865 // next time
4866 ResetVisibleLinesRange();
4867
4868 if ( event.GetOrientation() == wxHORIZONTAL && HasHeader() )
4869 {
4870 wxGenericListCtrl* lc = GetListCtrl();
4871 wxCHECK_RET( lc, _T("no listctrl window?") )if ( lc ) {} else { do { if ( wxTheAssertHandler && (
wxOnAssert("extern/wxWidgets/listctrl.cpp", 4871, __FUNCTION__
, "\"lc\"", L"no listctrl window?"), wxTrapInAssert) ) { wxTrapInAssert
= false; asm volatile ("int $3"); } } while ( (void)0, 0 ); return
; } struct wxDummyCheckStruct4871
;
4872
4873 lc->m_headerWin->Refresh();
4874 lc->m_headerWin->Update();
4875 }
4876}
4877
4878int wxListMainWindow::GetCountPerPage() const
4879{
4880 if ( !m_linesPerPage )
4881 {
4882 wxConstCast(this, wxListMainWindow)const_cast<wxListMainWindow *>(this)->
4883 m_linesPerPage = GetClientSize().y / GetLineHeight();
4884 }
4885
4886 return m_linesPerPage;
4887}
4888
4889void wxListMainWindow::GetVisibleLinesRange(size_t *from, size_t *to)
4890{
4891 wxASSERT_MSG( InReportView(), _T("this is for report mode only") )do { if ( InReportView() ) { } else if ( wxTheAssertHandler &&
(wxOnAssert("extern/wxWidgets/listctrl.cpp", 4891, __FUNCTION__
, "InReportView()", L"this is for report mode only"), wxTrapInAssert
) ) { wxTrapInAssert = false; asm volatile ("int $3"); } } while
( (void)0, 0 )
;
4892
4893 if ( m_lineFrom == (size_t)-1 )
4894 {
4895 size_t count = GetItemCount();
4896 if ( count )
4897 {
4898 m_lineFrom = GetScrollPos(wxVERTICAL);
4899
4900 // this may happen if SetScrollbars() hadn't been called yet
4901 if ( m_lineFrom >= count )
4902 m_lineFrom = count - 1;
4903
4904 // we redraw one extra line but this is needed to make the redrawing
4905 // logic work when there is a fractional number of lines on screen
4906 m_lineTo = m_lineFrom + m_linesPerPage;
4907 if ( m_lineTo >= count )
4908 m_lineTo = count - 1;
4909 }
4910 else // empty control
4911 {
4912 m_lineFrom = 0;
4913 m_lineTo = (size_t)-1;
4914 }
4915 }
4916
4917 wxASSERT_MSG( IsEmpty() ||do { if ( IsEmpty() || (m_lineFrom <= m_lineTo && m_lineTo
< GetItemCount()) ) { } else if ( wxTheAssertHandler &&
(wxOnAssert("extern/wxWidgets/listctrl.cpp", 4919, __FUNCTION__
, "IsEmpty() || (m_lineFrom <= m_lineTo && m_lineTo < GetItemCount())"
, L"GetVisibleLinesRange() returns incorrect result"), wxTrapInAssert
) ) { wxTrapInAssert = false; asm volatile ("int $3"); } } while
( (void)0, 0 )
4918 (m_lineFrom <= m_lineTo && m_lineTo < GetItemCount()),do { if ( IsEmpty() || (m_lineFrom <= m_lineTo && m_lineTo
< GetItemCount()) ) { } else if ( wxTheAssertHandler &&
(wxOnAssert("extern/wxWidgets/listctrl.cpp", 4919, __FUNCTION__
, "IsEmpty() || (m_lineFrom <= m_lineTo && m_lineTo < GetItemCount())"
, L"GetVisibleLinesRange() returns incorrect result"), wxTrapInAssert
) ) { wxTrapInAssert = false; asm volatile ("int $3"); } } while
( (void)0, 0 )
4919 _T("GetVisibleLinesRange() returns incorrect result") )do { if ( IsEmpty() || (m_lineFrom <= m_lineTo && m_lineTo
< GetItemCount()) ) { } else if ( wxTheAssertHandler &&
(wxOnAssert("extern/wxWidgets/listctrl.cpp", 4919, __FUNCTION__
, "IsEmpty() || (m_lineFrom <= m_lineTo && m_lineTo < GetItemCount())"
, L"GetVisibleLinesRange() returns incorrect result"), wxTrapInAssert
) ) { wxTrapInAssert = false; asm volatile ("int $3"); } } while
( (void)0, 0 )
;
4920
4921 if ( from )
4922 *from = m_lineFrom;
4923 if ( to )
4924 *to = m_lineTo;
4925}
4926
4927// -------------------------------------------------------------------------------------
4928// wxGenericListCtrl
4929// -------------------------------------------------------------------------------------
4930
4931BEGIN_EVENT_TABLE(wxGenericListCtrl,wxControl)const wxEventTable wxGenericListCtrl::sm_eventTable = { &
wxControl::sm_eventTable, &wxGenericListCtrl::sm_eventTableEntries
[0] }; const wxEventTable *wxGenericListCtrl::GetEventTable()
const { return &wxGenericListCtrl::sm_eventTable; } wxEventHashTable
wxGenericListCtrl::sm_eventHashTable(wxGenericListCtrl::sm_eventTable
); wxEventHashTable &wxGenericListCtrl::GetEventHashTable
() const { return wxGenericListCtrl::sm_eventHashTable; } const
wxEventTableEntry wxGenericListCtrl::sm_eventTableEntries[] =
{
4932 EVT_SIZE(wxGenericListCtrl::OnSize)wxEventTableEntry(wxEVT_SIZE, wxID_ANY, wxID_ANY, wxNewEventTableFunctor
(wxEVT_SIZE, wxEventFunctionCast(wxPrivate::DoCast<wxPrivate
::EventArgOf<wxSizeEventFunction>::type>(&wxGenericListCtrl
::OnSize))), __null),
4933END_EVENT_TABLE()wxEventTableEntry(wxEVT_NULL, 0, 0, __null, __null) };
4934
4935wxGenericListCtrl::wxGenericListCtrl()
4936{
4937 m_imageListNormal = (wxImageList *) NULL__null;
4938 m_imageListSmall = (wxImageList *) NULL__null;
4939 m_imageListState = (wxImageList *) NULL__null;
4940
4941 m_ownsImageListNormal =
4942 m_ownsImageListSmall =
4943 m_ownsImageListState = false;
4944
4945 m_mainWin = (wxListMainWindow*) NULL__null;
4946 m_headerWin = (wxListHeaderWindow*) NULL__null;
4947 m_headerHeight = 0;
4948}
4949
4950wxGenericListCtrl::~wxGenericListCtrl()
4951{
4952 if (m_ownsImageListNormal)
4953 delete m_imageListNormal;
4954 if (m_ownsImageListSmall)
4955 delete m_imageListSmall;
4956 if (m_ownsImageListState)
4957 delete m_imageListState;
4958}
4959
4960void wxGenericListCtrl::CalculateAndSetHeaderHeight()
4961{
4962 if ( m_headerWin )
4963 {
4964#if defined( __WXMAC__ ) && !defined(__WXUNIVERSAL__) && wxOSX_USE_CARBON
4965 SInt32 h;
4966 GetThemeMetric( kThemeMetricListHeaderHeight, &h );
4967#else
4968 // we use 'g' to get the descent, too
4969 int w, h, d;
4970 m_headerWin->GetTextExtent(wxT("Hg")L"Hg", &w, &h, &d);
4971 h += d + 2 * HEADER_OFFSET_Y + EXTRA_HEIGHT;
4972#endif
4973
4974 // only update if changed
4975 if ( h != m_headerHeight )
4976 {
4977 m_headerHeight = h;
4978
4979 if ( HasHeader() )
4980 ResizeReportView(true);
4981 else //why is this needed if it doesn't have a header?
4982 m_headerWin->SetSize(m_headerWin->GetSize().x, m_headerHeight);
4983 }
4984 }
4985}
4986
4987void wxGenericListCtrl::CreateHeaderWindow()
4988{
4989 m_headerWin = new wxListHeaderWindow
4990 (
4991 this, wxID_ANY, m_mainWin,
4992 wxPoint(0,0),
4993 wxSize(GetClientSize().x, m_headerHeight),
4994 wxTAB_TRAVERSAL0x00080000
4995 );
4996 CalculateAndSetHeaderHeight();
4997}
4998
4999bool wxGenericListCtrl::GetFocus()
5000{
5001 return m_mainWin->m_hasFocus;
5002}
5003
5004bool wxGenericListCtrl::Create(wxWindow *parent,
5005 wxWindowID id,
5006 const wxPoint &pos,
5007 const wxSize &size,
5008 long style,
5009 const wxValidator &validator,
5010 const wxString &name)
5011{
5012 m_imageListNormal =
5013 m_imageListSmall =
5014 m_imageListState = (wxImageList *) NULL__null;
5015 m_ownsImageListNormal =
5016 m_ownsImageListSmall =
5017 m_ownsImageListState = false;
5018
5019 m_mainWin = (wxListMainWindow*) NULL__null;
5020 m_headerWin = (wxListHeaderWindow*) NULL__null;
5021
5022 m_headerHeight = 0;
5023
5024 if ( !(style & wxLC_MASK_TYPE(0x0004 | 0x0008 | 0x0010 | 0x0020)) )
5025 {
5026 style = style | wxLC_LIST0x0010;
5027 }
5028
5029 // add more styles here that should only appear
5030 // in the main window
5031 unsigned long only_main_window_style = wxALWAYS_SHOW_SB0x00800000;
5032
5033 if ( !wxControl::Create( parent, id, pos, size, style & ~only_main_window_style, validator, name ) )
5034 return false;
5035
5036 // don't create the inner window with the border
5037 style &= ~wxBORDER_MASK;
5038
5039 m_mainWin = new wxListMainWindow( this, wxID_ANY, wxPoint(0, 0), size, style );
5040
5041#ifdef __WXMAC_CARBON__
5042 // Human Interface Guidelines ask us for a special font in this case
5043 if ( GetWindowVariant() == wxWINDOW_VARIANT_NORMAL )
5044 {
5045 wxFont font;
5046 font.MacCreateThemeFont( kThemeViewsFont );
5047 SetFont( font );
5048 }
5049#endif
5050
5051 if ( InReportView() )
5052 {
5053 CreateHeaderWindow();
5054
5055#ifdef __WXMAC_CARBON__
5056 if (m_headerWin)
5057 {
5058 wxFont font;
5059 font.MacCreateThemeFont( kThemeSmallSystemFont );
5060 m_headerWin->SetFont( font );
5061 CalculateAndSetHeaderHeight();
5062 }
5063#endif
5064
5065 if ( HasFlag(wxLC_NO_HEADER0x0800) )
5066 // VZ: why do we create it at all then?
5067 m_headerWin->Show( false );
5068 }
5069
5070 SetInitialSize(size);
5071
5072 return true;
5073}
5074
5075void wxGenericListCtrl::SetSingleStyle( long style, bool add )
5076{
5077 wxASSERT_MSG( !(style & wxLC_VIRTUAL),do { if ( !(style & 0x0200) ) { } else if ( wxTheAssertHandler
&& (wxOnAssert("extern/wxWidgets/listctrl.cpp", 5078
, __FUNCTION__, "!(style & 0x0200)", L"wxLC_VIRTUAL can't be [un]set"
), wxTrapInAssert) ) { wxTrapInAssert = false; asm volatile (
"int $3"); } } while ( (void)0, 0 )
5078 _T("wxLC_VIRTUAL can't be [un]set") )do { if ( !(style & 0x0200) ) { } else if ( wxTheAssertHandler
&& (wxOnAssert("extern/wxWidgets/listctrl.cpp", 5078
, __FUNCTION__, "!(style & 0x0200)", L"wxLC_VIRTUAL can't be [un]set"
), wxTrapInAssert) ) { wxTrapInAssert = false; asm volatile (
"int $3"); } } while ( (void)0, 0 )
;
5079
5080 long flag = GetWindowStyle();
5081
5082 if (add)
5083 {
5084 if (style & wxLC_MASK_TYPE(0x0004 | 0x0008 | 0x0010 | 0x0020))
5085 flag &= ~(wxLC_MASK_TYPE(0x0004 | 0x0008 | 0x0010 | 0x0020) | wxLC_VIRTUAL0x0200);
5086 if (style & wxLC_MASK_ALIGN(0x0040 | 0x0080))
5087 flag &= ~wxLC_MASK_ALIGN(0x0040 | 0x0080);
5088 if (style & wxLC_MASK_SORT(0x4000 | 0x8000))
5089 flag &= ~wxLC_MASK_SORT(0x4000 | 0x8000);
5090 }
5091
5092 if (add)
5093 flag |= style;
5094 else
5095 flag &= ~style;
5096
5097 // some styles can be set without recreating everything (as happens in
5098 // SetWindowStyleFlag() which calls wxListMainWindow::DeleteEverything())
5099 if ( !(style & ~(wxLC_HRULES0x0002 | wxLC_VRULES0x0001)) )
5100 {
5101 Refresh();
5102 wxWindow::SetWindowStyleFlag(flag);
5103 }
5104 else
5105 {
5106 SetWindowStyleFlag( flag );
5107 }
5108}
5109
5110void wxGenericListCtrl::SetWindowStyleFlag( long flag )
5111{
5112 if (m_mainWin)
5113 {
5114 m_mainWin->DeleteEverything();
5115
5116 // has the header visibility changed?
5117 bool hasHeader = HasHeader();
5118 bool willHaveHeader = (flag & wxLC_REPORT0x0020) && !(flag & wxLC_NO_HEADER0x0800);
5119
5120 if ( hasHeader != willHaveHeader )
5121 {
5122 // toggle it
5123 if ( hasHeader )
5124 {
5125 if ( m_headerWin )
5126 {
5127 // don't delete, just hide, as we can reuse it later
5128 m_headerWin->Show(false);
5129 }
5130 //else: nothing to do
5131 }
5132 else // must show header
5133 {
5134 if (!m_headerWin)
5135 {
5136 CreateHeaderWindow();
5137 }
5138 else // already have it, just show
5139 {
5140 m_headerWin->Show( true );
5141 }
5142 }
5143
5144 ResizeReportView(willHaveHeader);
5145 }
5146 }
5147
5148 wxWindow::SetWindowStyleFlag( flag );
5149}
5150
5151bool wxGenericListCtrl::GetColumn(int col, wxListItem &item) const
5152{
5153 m_mainWin->GetColumn( col, item );
5154 return true;
5155}
5156
5157bool wxGenericListCtrl::SetColumn( int col, wxListItem& item )
5158{
5159 m_mainWin->SetColumn( col, item );
5160 return true;
5161}
5162
5163int wxGenericListCtrl::GetColumnWidth( int col ) const
5164{
5165 return m_mainWin->GetColumnWidth( col );
5166}
5167
5168bool wxGenericListCtrl::SetColumnWidth( int col, int width )
5169{
5170 m_mainWin->SetColumnWidth( col, width );
5171 return true;
5172}
5173
5174int wxGenericListCtrl::GetCountPerPage() const
5175{
5176 return m_mainWin->GetCountPerPage(); // different from Windows ?
5177}
5178
5179bool wxGenericListCtrl::GetItem( wxListItem &info ) const
5180{
5181 m_mainWin->GetItem( info );
5182 return true;
5183}
5184
5185bool wxGenericListCtrl::SetItem( wxListItem &info )
5186{
5187 m_mainWin->SetItem( info );
5188 return true;
5189}
5190
5191long wxGenericListCtrl::SetItem( long index, int col, const wxString& label, int imageId )
5192{
5193 wxListItem info;
5194 info.m_text = label;
5195 info.m_mask = wxLIST_MASK_TEXT0x0002;
5196 info.m_itemId = index;
5197 info.m_col = col;
5198 if ( imageId > -1 )
5199 {
5200 info.m_image = imageId;
5201 info.m_mask |= wxLIST_MASK_IMAGE0x0004;
5202 }
5203
5204 m_mainWin->SetItem(info);
5205 return true;
5206}
5207
5208int wxGenericListCtrl::GetItemState( long item, long stateMask ) const
5209{
5210 return m_mainWin->GetItemState( item, stateMask );
5211}
5212
5213bool wxGenericListCtrl::SetItemState( long item, long state, long stateMask )
5214{
5215 m_mainWin->SetItemState( item, state, stateMask );
5216 return true;
5217}
5218
5219bool
5220wxGenericListCtrl::SetItemImage( long item, int image, int WXUNUSED(selImage) )
5221{
5222 return SetItemColumnImage(item, 0, image);
5223}
5224
5225bool
5226wxGenericListCtrl::SetItemColumnImage( long item, long column, int image )
5227{
5228 wxListItem info;
5229 info.m_image = image;
5230 info.m_mask = wxLIST_MASK_IMAGE0x0004;
5231 info.m_itemId = item;
5232 info.m_col = column;
5233 m_mainWin->SetItem( info );
5234 return true;
5235}
5236
5237wxString wxGenericListCtrl::GetItemText( long item ) const
5238{
5239 return m_mainWin->GetItemText(item);
5240}
5241
5242void wxGenericListCtrl::SetItemText( long item, const wxString& str )
5243{
5244 m_mainWin->SetItemText(item, str);
5245}
5246
5247wxUIntPtr wxGenericListCtrl::GetItemData( long item ) const
5248{
5249 wxListItem info;
5250 info.m_mask = wxLIST_MASK_DATA0x0008;
5251 info.m_itemId = item;
5252 m_mainWin->GetItem( info );
5253 return info.m_data;
5254}
5255
5256bool wxGenericListCtrl::SetItemPtrData( long item, wxUIntPtr data )
5257{
5258 wxListItem info;
5259 info.m_mask = wxLIST_MASK_DATA0x0008;
5260 info.m_itemId = item;
5261 info.m_data = data;
5262 m_mainWin->SetItem( info );
5263 return true;
5264}
5265
5266#if 0
5267bool wxGenericListCtrl::SetItemData(long item, long data)
5268{
5269 return SetItemPtrData(item, data);
5270}
5271#endif
5272
5273wxRect wxGenericListCtrl::GetViewRect() const
5274{
5275 return m_mainWin->GetViewRect();
5276}
5277
5278bool wxGenericListCtrl::GetItemRect( long item, wxRect &rect, int WXUNUSED(code) ) const
5279{
5280 m_mainWin->GetItemRect( item, rect );
5281 if ( m_mainWin->HasHeader() )
5282 rect.y += m_headerHeight + 1;
5283 return true;
5284}
5285
5286bool wxGenericListCtrl::GetItemPosition( long item, wxPoint& pos ) const
5287{
5288 m_mainWin->GetItemPosition( item, pos );
5289 return true;
5290}
5291
5292bool wxGenericListCtrl::SetItemPosition( long WXUNUSED(item), const wxPoint& WXUNUSED(pos) )
5293{
5294 return 0;
5295}
5296
5297int wxGenericListCtrl::GetItemCount() const
5298{
5299 return m_mainWin->GetItemCount();
5300}
5301
5302int wxGenericListCtrl::GetColumnCount() const
5303{
5304 return m_mainWin->GetColumnCount();
5305}
5306
5307void wxGenericListCtrl::SetItemSpacing( int spacing, bool isSmall )
5308{
5309 m_mainWin->SetItemSpacing( spacing, isSmall );
5310}
5311
5312wxSize wxGenericListCtrl::GetItemSpacing() const
5313{
5314 const int spacing = m_mainWin->GetItemSpacing(HasFlag(wxLC_SMALL_ICON0x0008));
5315
5316 return wxSize(spacing, spacing);
5317}
5318
5319void wxGenericListCtrl::OnDrawItem(int WXUNUSED(item), wxDC* WXUNUSED(dc), const wxRect& WXUNUSED(rect), const wxRect& WXUNUSED(rectHL), bool WXUNUSED(highlighted))
5320{
5321 // do nothing here, this is just a stub
5322}
5323
5324void wxGenericListCtrl::SetItemTextColour( long item, const wxColour &col )
5325{
5326 wxListItem info;
5327 info.m_itemId = item;
5328 info.SetTextColour( col );
5329 m_mainWin->SetItem( info );
5330}
5331
5332wxColour wxGenericListCtrl::GetItemTextColour( long item ) const
5333{
5334 wxListItem info;
5335 info.m_itemId = item;
5336 m_mainWin->GetItem( info );
5337 return info.GetTextColour();
5338}
5339
5340void wxGenericListCtrl::SetItemBackgroundColour( long item, const wxColour &col )
5341{
5342 wxListItem info;
5343 info.m_itemId = item;
5344 info.SetBackgroundColour( col );
5345 m_mainWin->SetItem( info );
5346}
5347
5348wxColour wxGenericListCtrl::GetItemBackgroundColour( long item ) const
5349{
5350 wxListItem info;
5351 info.m_itemId = item;
5352 m_mainWin->GetItem( info );
5353 return info.GetBackgroundColour();
5354}
5355
5356int wxGenericListCtrl::GetScrollPos( int orient ) const
5357{
5358 return m_mainWin->GetScrollPos( orient );
5359}
5360
5361void wxGenericListCtrl::SetScrollPos( int orient, int pos, bool refresh )
5362{
5363 m_mainWin->SetScrollPos( orient, pos, refresh );
5364}
5365
5366void wxGenericListCtrl::SetItemFont( long item, const wxFont &f )
5367{
5368 wxListItem info;
5369 info.m_itemId = item;
5370 info.SetFont( f );
5371 m_mainWin->SetItem( info );
5372}
5373
5374wxFont wxGenericListCtrl::GetItemFont( long item ) const
5375{
5376 wxListItem info;
5377 info.m_itemId = item;
5378 m_mainWin->GetItem( info );
5379 return info.GetFont();
5380}
5381
5382int wxGenericListCtrl::GetSelectedItemCount() const
5383{
5384 return m_mainWin->GetSelectedItemCount();
5385}
5386
5387wxColour wxGenericListCtrl::GetTextColour() const
5388{
5389 return GetForegroundColour();
5390}
5391
5392void wxGenericListCtrl::SetTextColour(const wxColour& col)
5393{
5394 SetForegroundColour(col);
5395}
5396
5397long wxGenericListCtrl::GetTopItem() const
5398{
5399 size_t top;
5400 m_mainWin->GetVisibleLinesRange(&top, NULL__null);
5401 return (long)top;
5402}
5403
5404void wxGenericListCtrl::GetVisibleLines(long* first, long* last)
5405{
5406 size_t from, to;
5407
5408 m_mainWin->GetVisibleLinesRange(&from, &to);
5409
5410 if (first) *first = (long)from;
5411 if (last) *last = (long)to;
5412}
5413
5414long wxGenericListCtrl::GetNextItem( long item, int geom, int state ) const
5415{
5416 return m_mainWin->GetNextItem( item, geom, state );
5417}
5418
5419wxImageList *wxGenericListCtrl::GetImageList(int which) const
5420{
5421 if (which == wxIMAGE_LIST_NORMAL)
5422 return m_imageListNormal;
5423 else if (which == wxIMAGE_LIST_SMALL)
5424 return m_imageListSmall;
5425 else if (which == wxIMAGE_LIST_STATE)
5426 return m_imageListState;
5427
5428 return (wxImageList *) NULL__null;
5429}
5430
5431void wxGenericListCtrl::SetImageList( wxImageList *imageList, int which )
5432{
5433 if ( which == wxIMAGE_LIST_NORMAL )
5434 {
5435 if (m_ownsImageListNormal)
5436 delete m_imageListNormal;
5437 m_imageListNormal = imageList;
5438 m_ownsImageListNormal = false;
5439 }
5440 else if ( which == wxIMAGE_LIST_SMALL )
5441 {
5442 if (m_ownsImageListSmall)
5443 delete m_imageListSmall;
5444 m_imageListSmall = imageList;
5445 m_ownsImageListSmall = false;
5446 }
5447 else if ( which == wxIMAGE_LIST_STATE )
5448 {
5449 if (m_ownsImageListState)
5450 delete m_imageListState;
5451 m_imageListState = imageList;
5452 m_ownsImageListState = false;
5453 }
5454
5455 m_mainWin->SetImageList( imageList, which );
5456}
5457
5458void wxGenericListCtrl::AssignImageList(wxImageList *imageList, int which)
5459{
5460 SetImageList(imageList, which);
5461 if ( which == wxIMAGE_LIST_NORMAL )
5462 m_ownsImageListNormal = true;
5463 else if ( which == wxIMAGE_LIST_SMALL )
5464 m_ownsImageListSmall = true;
5465 else if ( which == wxIMAGE_LIST_STATE )
5466 m_ownsImageListState = true;
5467}
5468
5469bool wxGenericListCtrl::Arrange( int WXUNUSED(flag) )
5470{
5471 return 0;
5472}
5473
5474bool wxGenericListCtrl::DeleteItem( long item )
5475{
5476 m_mainWin->DeleteItem( item );
5477 return true;
5478}
5479
5480bool wxGenericListCtrl::DeleteAllItems()
5481{
5482 m_mainWin->DeleteAllItems();
5483 return true;
5484}
5485
5486bool wxGenericListCtrl::DeleteAllColumns()
5487{
5488 size_t count = m_mainWin->m_columns.GetCount();
5489 for ( size_t n = 0; n < count; n++ )
5490 DeleteColumn( 0 );
5491 return true;
5492}
5493
5494void wxGenericListCtrl::ClearAll()
5495{
5496 m_mainWin->DeleteEverything();
5497}
5498
5499bool wxGenericListCtrl::DeleteColumn( int col )
5500{
5501 m_mainWin->DeleteColumn( col );
5502
5503 // if we don't have the header any longer, we need to relayout the window
5504 if ( !GetColumnCount() )
5505 ResizeReportView(false /* no header */);
5506 return true;
5507}
5508
5509wxTextCtrl *wxGenericListCtrl::EditLabel(long item,
5510 wxClassInfo* textControlClass)
5511{
5512 return m_mainWin->EditLabel( item, textControlClass );
5513}
5514
5515wxTextCtrl *wxGenericListCtrl::GetEditControl() const
5516{
5517 return m_mainWin->GetEditControl();
5518}
5519
5520bool wxGenericListCtrl::EnsureVisible( long item )
5521{
5522 m_mainWin->EnsureVisible( item );
5523 return true;
5524}
5525
5526long wxGenericListCtrl::FindItem( long start, const wxString& str, bool partial )
5527{
5528 return m_mainWin->FindItem( start, str, partial );
5529}
5530
5531long wxGenericListCtrl::FindItem( long start, wxUIntPtr data )
5532{
5533 return m_mainWin->FindItem( start, data );
5534}
5535
5536long wxGenericListCtrl::FindItem( long WXUNUSED(start), const wxPoint& pt,
5537 int WXUNUSED(direction))
5538{
5539 return m_mainWin->FindItem( pt );
5540}
5541
5542// TODO: sub item hit testing
5543long wxGenericListCtrl::HitTest(const wxPoint& point, int& flags, long *) const
5544{
5545 return m_mainWin->HitTest( (int)point.x, (int)point.y, flags );
5546}
5547
5548long wxGenericListCtrl::InsertItem( wxListItem& info )
5549{
5550 m_mainWin->InsertItem( info );
5551 return info.m_itemId;
5552}
5553
5554long wxGenericListCtrl::InsertItem( long index, const wxString &label )
5555{
5556 wxListItem info;
5557 info.m_text = label;
5558 info.m_mask = wxLIST_MASK_TEXT0x0002;
5559 info.m_itemId = index;
5560 return InsertItem( info );
5561}
5562
5563long wxGenericListCtrl::InsertItem( long index, int imageIndex )
5564{
5565 wxListItem info;
5566 info.m_mask = wxLIST_MASK_IMAGE0x0004;
5567 info.m_image = imageIndex;
5568 info.m_itemId = index;
5569 return InsertItem( info );
5570}
5571
5572long wxGenericListCtrl::InsertItem( long index, const wxString &label, int imageIndex )
5573{
5574 wxListItem info;
5575 info.m_text = label;
5576 info.m_image = imageIndex;
5577 info.m_mask = wxLIST_MASK_TEXT0x0002 | wxLIST_MASK_IMAGE0x0004;
5578 info.m_itemId = index;
5579 return InsertItem( info );
5580}
5581
5582long wxGenericListCtrl::InsertColumn( long col, wxListItem &item )
5583{
5584 wxCHECK_MSG( m_headerWin, -1, _T("can't add column in non report mode") )if ( m_headerWin ) {} else { do { if ( wxTheAssertHandler &&
(wxOnAssert("extern/wxWidgets/listctrl.cpp", 5584, __FUNCTION__
, "\"m_headerWin\"", L"can't add column in non report mode"),
wxTrapInAssert) ) { wxTrapInAssert = false; asm volatile ("int $3"
); } } while ( (void)0, 0 ); return -1; } struct wxDummyCheckStruct5584
;
5585
5586 m_mainWin->InsertColumn( col, item );
5587
5588 // if we hadn't had a header before but have one now
5589 // then we need to relayout the window
5590 if ( GetColumnCount() == 1 && m_mainWin->HasHeader() )
5591 ResizeReportView(true /* have header */);
5592
5593 m_headerWin->Refresh();
5594
5595 return 0;
5596}
5597
5598long wxGenericListCtrl::InsertColumn( long col, const wxString &heading,
5599 int format, int width )
5600{
5601 wxListItem item;
5602 item.m_mask = wxLIST_MASK_TEXT0x0002 | wxLIST_MASK_FORMAT0x0040;
5603 item.m_text = heading;
5604 if (width >= -2)
5605 {
5606 item.m_mask |= wxLIST_MASK_WIDTH0x0020;
5607 item.m_width = width;
5608 }
5609
5610 item.m_format = format;
5611
5612 return InsertColumn( col, item );
5613}
5614
5615bool wxGenericListCtrl::ScrollList( int WXUNUSED(dx), int WXUNUSED(dy) )
5616{
5617 return 0;
5618}
5619
5620// Sort items.
5621// fn is a function which takes 3 long arguments: item1, item2, data.
5622// item1 is the long data associated with a first item (NOT the index).
5623// item2 is the long data associated with a second item (NOT the index).
5624// data is the same value as passed to SortItems.
5625// The return value is a negative number if the first item should precede the second
5626// item, a positive number of the second item should precede the first,
5627// or zero if the two items are equivalent.
5628// data is arbitrary data to be passed to the sort function.
5629
5630bool wxGenericListCtrl::SortItems( MuleListCtrlCompare fn, long data )
5631{
5632 m_mainWin->SortItems( fn, data );
5633 return true;
5634}
5635
5636// ----------------------------------------------------------------------------
5637// event handlers
5638// ----------------------------------------------------------------------------
5639
5640void wxGenericListCtrl::OnSize(wxSizeEvent& WXUNUSED(event))
5641{
5642 if ( !m_mainWin )
5643 return;
5644
5645 ResizeReportView(m_mainWin->HasHeader());
5646 m_mainWin->RecalculatePositions();
5647}
5648
5649void wxGenericListCtrl::ResizeReportView(bool showHeader)
5650{
5651 int cw, ch;
5652 GetClientSize( &cw, &ch );
5653
5654 if ( showHeader )
5655 {
5656 m_headerWin->SetSize( 0, 0, cw, m_headerHeight );
5657 if(ch > m_headerHeight)
5658 m_mainWin->SetSize( 0, m_headerHeight + 1,
5659 cw, ch - m_headerHeight - 1 );
5660 else
5661 m_mainWin->SetSize( 0, m_headerHeight + 1,
5662 cw, 0);
5663 }
5664 else // no header window
5665 {
5666 m_mainWin->SetSize( 0, 0, cw, ch );
5667 }
5668}
5669
5670void wxGenericListCtrl::OnInternalIdle()
5671{
5672 wxWindow::OnInternalIdle();
5673
5674 // do it only if needed
5675 if ( !m_mainWin->m_dirty )
5676 return;
5677
5678 m_mainWin->RecalculatePositions();
5679}
5680
5681// ----------------------------------------------------------------------------
5682// font/colours
5683// ----------------------------------------------------------------------------
5684
5685bool wxGenericListCtrl::SetBackgroundColour( const wxColour &colour )
5686{
5687 if (m_mainWin)
5688 {
5689 m_mainWin->SetBackgroundColour( colour );
5690 m_mainWin->m_dirty = true;
5691 }
5692
5693 return true;
5694}
5695
5696bool wxGenericListCtrl::SetForegroundColour( const wxColour &colour )
5697{
5698 if ( !wxWindow::SetForegroundColour( colour ) )
5699 return false;
5700
5701 if (m_mainWin)
5702 {
5703 m_mainWin->SetForegroundColour( colour );
5704 m_mainWin->m_dirty = true;
5705 }
5706
5707 if (m_headerWin)
5708 m_headerWin->SetForegroundColour( colour );
5709
5710 return true;
5711}
5712
5713bool wxGenericListCtrl::SetFont( const wxFont &font )
5714{
5715 if ( !wxWindow::SetFont( font ) )
5716 return false;
5717
5718 if (m_mainWin)
5719 {
5720 m_mainWin->SetFont( font );
5721 m_mainWin->m_dirty = true;
5722 }
5723
5724 if (m_headerWin)
5725 {
5726 m_headerWin->SetFont( font );
5727 CalculateAndSetHeaderHeight();
5728 }
5729
5730 Refresh();
5731
5732 return true;
5733}
5734
5735// static
5736wxVisualAttributes
5737wxGenericListCtrl::GetClassDefaultAttributes(wxWindowVariant variant)
5738{
5739#if _USE_VISATTR0
5740 // Use the same color scheme as wxListBox
5741 return wxListBox::GetClassDefaultAttributes(variant);
5742#else
5743 wxUnusedVar(variant);
5744 wxVisualAttributes attr;
5745 attr.colFg = wxSystemSettings::GetColour(wxSYS_COLOUR_LISTBOXTEXT);
5746 attr.colBg = wxSystemSettings::GetColour(wxSYS_COLOUR_LISTBOX);
5747 attr.font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
5748 return attr;
5749#endif
5750}
5751
5752// ----------------------------------------------------------------------------
5753// methods forwarded to m_mainWin
5754// ----------------------------------------------------------------------------
5755
5756#if wxUSE_DRAG_AND_DROP1
5757
5758void wxGenericListCtrl::SetDropTarget( wxDropTarget *dropTarget )
5759{
5760 m_mainWin->SetDropTarget( dropTarget );
5761}
5762
5763wxDropTarget *wxGenericListCtrl::GetDropTarget() const
5764{
5765 return m_mainWin->GetDropTarget();
5766}
5767
5768#endif
5769
5770bool wxGenericListCtrl::SetCursor( const wxCursor &cursor )
5771{
5772 return m_mainWin ? m_mainWin->wxWindow::SetCursor(cursor) : false;
5773}
5774
5775wxColour wxGenericListCtrl::GetBackgroundColour() const
5776{
5777 return m_mainWin ? m_mainWin->GetBackgroundColour() : wxColour();
5778}
5779
5780wxColour wxGenericListCtrl::GetForegroundColour() const
5781{
5782 return m_mainWin ? m_mainWin->GetForegroundColour() : wxColour();
5783}
5784
5785bool wxGenericListCtrl::DoPopupMenu( wxMenu *menu, int x, int y )
5786{
5787#if wxUSE_MENUS1
5788 return m_mainWin->PopupMenu( menu, x, y );
5789#else
5790 return false;
5791#endif
5792}
5793
5794void wxGenericListCtrl::SetFocus()
5795{
5796 // The test in window.cpp fails as we are a composite
5797 // window, so it checks against "this", but not m_mainWin.
5798 if ( DoFindFocus() != this )
5799 m_mainWin->SetFocus();
5800}
5801
5802wxSize wxGenericListCtrl::DoGetBestSize() const
5803{
5804 // Something is better than nothing...
5805 // 100x80 is what the MSW version will get from the default
5806 // wxControl::DoGetBestSize
5807 return wxSize(100, 80);
5808}
5809
5810// ----------------------------------------------------------------------------
5811// virtual list control support
5812// ----------------------------------------------------------------------------
5813
5814wxString wxGenericListCtrl::OnGetItemText(long WXUNUSED(item), long WXUNUSED(col)) const
5815{
5816 // this is a pure virtual function, in fact - which is not really pure
5817 // because the controls which are not virtual don't need to implement it
5818 wxFAIL_MSG( _T("wxGenericListCtrl::OnGetItemText not supposed to be called") )do { if ( wxTheAssertHandler && (wxOnAssert("extern/wxWidgets/listctrl.cpp"
, 5818, __FUNCTION__, "\"Assert failure\"", L"wxGenericListCtrl::OnGetItemText not supposed to be called"
), wxTrapInAssert) ) { wxTrapInAssert = false; asm volatile (
"int $3"); } } while ( (void)0, 0 )
;
5819
5820 return wxEmptyString;
5821}
5822
5823int wxGenericListCtrl::OnGetItemImage(long WXUNUSED(item)) const
5824{
5825 wxCHECK_MSG(!GetImageList(wxIMAGE_LIST_SMALL),if ( !GetImageList(wxIMAGE_LIST_SMALL) ) {} else { do { if ( wxTheAssertHandler
&& (wxOnAssert("extern/wxWidgets/listctrl.cpp", 5827
, __FUNCTION__, "\"!GetImageList(wxIMAGE_LIST_SMALL)\"", L"List control has an image list, OnGetItemImage or OnGetItemColumnImage should be overridden."
), wxTrapInAssert) ) { wxTrapInAssert = false; asm volatile (
"int $3"); } } while ( (void)0, 0 ); return -1; } struct wxDummyCheckStruct5827
5826 -1,if ( !GetImageList(wxIMAGE_LIST_SMALL) ) {} else { do { if ( wxTheAssertHandler
&& (wxOnAssert("extern/wxWidgets/listctrl.cpp", 5827
, __FUNCTION__, "\"!GetImageList(wxIMAGE_LIST_SMALL)\"", L"List control has an image list, OnGetItemImage or OnGetItemColumnImage should be overridden."
), wxTrapInAssert) ) { wxTrapInAssert = false; asm volatile (
"int $3"); } } while ( (void)0, 0 ); return -1; } struct wxDummyCheckStruct5827
5827 wxT("List control has an image list, OnGetItemImage or OnGetItemColumnImage should be overridden."))if ( !GetImageList(wxIMAGE_LIST_SMALL) ) {} else { do { if ( wxTheAssertHandler
&& (wxOnAssert("extern/wxWidgets/listctrl.cpp", 5827
, __FUNCTION__, "\"!GetImageList(wxIMAGE_LIST_SMALL)\"", L"List control has an image list, OnGetItemImage or OnGetItemColumnImage should be overridden."
), wxTrapInAssert) ) { wxTrapInAssert = false; asm volatile (
"int $3"); } } while ( (void)0, 0 ); return -1; } struct wxDummyCheckStruct5827
;
5828 return -1;
5829}
5830
5831int wxGenericListCtrl::OnGetItemColumnImage(long item, long column) const
5832{
5833 if (!column)
5834 return OnGetItemImage(item);
5835
5836 return -1;
5837}
5838
5839wxListItemAttr *
5840wxGenericListCtrl::OnGetItemAttr(long WXUNUSED_UNLESS_DEBUG(item)item) const
5841{
5842 wxASSERT_MSG( item >= 0 && item < GetItemCount(),do { if ( item >= 0 && item < GetItemCount() ) {
} else if ( wxTheAssertHandler && (wxOnAssert("extern/wxWidgets/listctrl.cpp"
, 5843, __FUNCTION__, "item >= 0 && item < GetItemCount()"
, L"invalid item index in OnGetItemAttr()"), wxTrapInAssert) )
{ wxTrapInAssert = false; asm volatile ("int $3"); } } while
( (void)0, 0 )
5843 _T("invalid item index in OnGetItemAttr()") )do { if ( item >= 0 && item < GetItemCount() ) {
} else if ( wxTheAssertHandler && (wxOnAssert("extern/wxWidgets/listctrl.cpp"
, 5843, __FUNCTION__, "item >= 0 && item < GetItemCount()"
, L"invalid item index in OnGetItemAttr()"), wxTrapInAssert) )
{ wxTrapInAssert = false; asm volatile ("int $3"); } } while
( (void)0, 0 )
;
5844
5845 // no attributes by default
5846 return NULL__null;
5847}
5848
5849void wxGenericListCtrl::SetItemCount(long count)
5850{
5851 wxASSERT_MSG( IsVirtual(), _T("this is for virtual controls only") )do { if ( IsVirtual() ) { } else if ( wxTheAssertHandler &&
(wxOnAssert("extern/wxWidgets/listctrl.cpp", 5851, __FUNCTION__
, "IsVirtual()", L"this is for virtual controls only"), wxTrapInAssert
) ) { wxTrapInAssert = false; asm volatile ("int $3"); } } while
( (void)0, 0 )
;
5852
5853 m_mainWin->SetItemCount(count);
5854}
5855
5856void wxGenericListCtrl::RefreshItem(long item)
5857{
5858 m_mainWin->RefreshLine(item);
5859}
5860
5861void wxGenericListCtrl::RefreshItems(long itemFrom, long itemTo)
5862{
5863 m_mainWin->RefreshLines(itemFrom, itemTo);
5864}
5865
5866// Generic wxListCtrl is more or less a container for two other
5867// windows which drawings are done upon. These are namely
5868// 'm_headerWin' and 'm_mainWin'.
5869// Here we override 'virtual wxWindow::Refresh()' to mimic the
5870// behaviour wxListCtrl has under wxMSW.
5871//
5872void wxGenericListCtrl::Refresh(bool eraseBackground, const wxRect *rect)
5873{
5874 if (!rect)
5875 {
5876 // The easy case, no rectangle specified.
5877 if (m_headerWin)
5878 m_headerWin->Refresh(eraseBackground);
5879
5880 if (m_mainWin)
5881 m_mainWin->Refresh(eraseBackground);
5882 }
5883 else
5884 {
5885 // Refresh the header window
5886 if (m_headerWin)
5887 {
5888 wxRect rectHeader = m_headerWin->GetRect();
5889 rectHeader.Intersect(*rect);
5890 if (rectHeader.GetWidth() && rectHeader.GetHeight())
5891 {
5892 int x, y;
5893 m_headerWin->GetPosition(&x, &y);
5894 rectHeader.Offset(-x, -y);
5895 m_headerWin->Refresh(eraseBackground, &rectHeader);
5896 }
5897 }
5898
5899 // Refresh the main window
5900 if (m_mainWin)
5901 {
5902 wxRect rectMain = m_mainWin->GetRect();
5903 rectMain.Intersect(*rect);
5904 if (rectMain.GetWidth() && rectMain.GetHeight())
5905 {
5906 int x, y;
5907 m_mainWin->GetPosition(&x, &y);
5908 rectMain.Offset(-x, -y);
5909 m_mainWin->Refresh(eraseBackground, &rectMain);
5910 }
5911 }
5912 }
5913}
5914
5915void wxGenericListCtrl::Freeze()
5916{
5917 m_mainWin->Freeze();
5918}
5919
5920void wxGenericListCtrl::Thaw()
5921{
5922 m_mainWin->Thaw();
5923}
5924
5925} // namespace MuleExtern
5926
5927#endif // wxUSE_LISTCTRL