]> git.saurik.com Git - wxWidgets.git/blame - src/msw/listctrl.cpp
Change log update
[wxWidgets.git] / src / msw / listctrl.cpp
Content-type: text/html ]> git.saurik.com Git - wxWidgets.git/blame - src/msw/listctrl.cpp


500 - Internal Server Error

Malformed UTF-8 character (fatal) at /usr/lib/x86_64-linux-gnu/perl5/5.40/HTML/Entities.pm line 485, <$fd> line 1100.
CommitLineData
2bda0e17 1/////////////////////////////////////////////////////////////////////////////
648bec3e 2// Name: src/msw/listctrl.cpp
2bda0e17
KB
3// Purpose: wxListCtrl
4// Author: Julian Smart
5// Modified by:
6// Created: 04/01/98
7// RCS-ID: $Id$
6c9a19aa 8// Copyright: (c) Julian Smart
65571936 9// Licence: wxWindows licence
2bda0e17
KB
10/////////////////////////////////////////////////////////////////////////////
11
edccf428
VZ
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19
14f355c2 20#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
0b5efdc7 21 #pragma implementation "listctrl.h"
3c1a88d8 22 #pragma implementation "listctrlbase.h"
2bda0e17
KB
23#endif
24
25// For compilers that support precompilation, includes "wx.h".
26#include "wx/wxprec.h"
27
28#ifdef __BORLANDC__
0b5efdc7 29 #pragma hdrstop
2bda0e17
KB
30#endif
31
98ec9dbe 32#if wxUSE_LISTCTRL && defined(__WIN95__)
9f303149 33
2bda0e17 34#ifndef WX_PRECOMP
9f303149 35 #include "wx/app.h"
9f303149
VZ
36 #include "wx/intl.h"
37 #include "wx/log.h"
38 #include "wx/settings.h"
2bda0e17
KB
39#endif
40
de8e98f1
JS
41#include "wx/textctrl.h"
42#include "wx/imaglist.h"
2bda0e17 43#include "wx/listctrl.h"
68fdcf29 44#include "wx/dcclient.h"
2bda0e17
KB
45
46#include "wx/msw/private.h"
47
781a24e8 48#if defined(__WXWINCE__) && !defined(__HANDHELDPC__)
80a81a12
JS
49 #include <ole2.h>
50 #include <shellapi.h>
2d36b3d8
JS
51 #if _WIN32_WCE < 400
52 #include <aygshell.h>
53 #endif
80a81a12
JS
54#endif
55
0d236fd0
VZ
56// include <commctrl.h> "properly"
57#include "wx/msw/wrapcctl.h"
12979259 58
2f73fd38
MW
59// Currently gcc and watcom don't define NMLVFINDITEM, and DMC only defines
60// it by its old name NM_FINDTIEM.
61//
73f91e1e 62#if defined(__VISUALC__) || defined(__BORLANDC__) || defined(NMLVFINDITEM)
2f73fd38 63 #define HAVE_NMLVFINDITEM 1
73f91e1e 64#elif defined(__DMC__) || defined(NM_FINDITEM)
2f73fd38
MW
65 #define HAVE_NM_FINDITEM 1
66#endif
67
edccf428
VZ
68// ----------------------------------------------------------------------------
69// private functions
70// ----------------------------------------------------------------------------
2bda0e17 71
8dff2b5c
VZ
72// convert our state and mask flags to LV_ITEM constants
73static void wxConvertToMSWFlags(long state, long mask, LV_ITEM& lvItem);
74
75// convert wxListItem to LV_ITEM
76static void wxConvertToMSWListItem(const wxListCtrl *ctrl,
77 const wxListItem& info, LV_ITEM& lvItem);
78
79// convert LV_ITEM to wxListItem
80static void wxConvertFromMSWListItem(HWND hwndListCtrl,
81 wxListItem& info,
82 /* const */ LV_ITEM& lvItem);
2bda0e17 83
6f806543
VZ
84// convert our wxListItem to LV_COLUMN
85static void wxConvertToMSWListCol(int col, const wxListItem& item,
86 LV_COLUMN& lvCol);
87
8c21905b
VS
88// ----------------------------------------------------------------------------
89// private helper classes
90// ----------------------------------------------------------------------------
91
92// We have to handle both fooW and fooA notifications in several cases
d2ed74b9 93// because of broken comctl32.dll and/or unicows.dll. This class is used to
73d8c5fd 94// convert LV_ITEMA and LV_ITEMW to LV_ITEM (which is either LV_ITEMA or
8c21905b
VS
95// LV_ITEMW depending on wxUSE_UNICODE setting), so that it can be processed
96// by wxConvertToMSWListItem().
d2ed74b9
VZ
97#if wxUSE_UNICODE
98 #define LV_ITEM_NATIVE LV_ITEMW
99 #define LV_ITEM_OTHER LV_ITEMA
100
101 #define LV_CONV_TO_WX cMB2WX
102 #define LV_CONV_BUF wxMB2WXbuf
103#else // ANSI
104 #define LV_ITEM_NATIVE LV_ITEMA
105 #define LV_ITEM_OTHER LV_ITEMW
106
107 #define LV_CONV_TO_WX cWC2WX
108 #define LV_CONV_BUF wxWC2WXbuf
109#endif // Unicode/ANSI
110
8c21905b
VS
111class wxLV_ITEM
112{
113public:
d2ed74b9
VZ
114 // default ctor, use Init() later
115 wxLV_ITEM() { m_buf = NULL; m_pItem = NULL; }
8c21905b 116
d2ed74b9
VZ
117 // init without conversion
118 void Init(LV_ITEM_NATIVE& item)
8c21905b 119 {
d2ed74b9
VZ
120 wxASSERT_MSG( !m_pItem, _T("Init() called twice?") );
121
122 m_pItem = &item;
73d8c5fd 123 }
8c21905b 124
d2ed74b9
VZ
125 // init with conversion
126 void Init(LV_ITEM_OTHER& item)
8c21905b 127 {
d2ed74b9
VZ
128 // avoid unnecessary dynamic memory allocation, jjust make m_pItem
129 // point to our own m_item
2b5f62a0 130
1c6f2414
WS
131 // memcpy() can't work if the struct sizes are different
132 wxCOMPILE_TIME_ASSERT( sizeof(LV_ITEM_OTHER) == sizeof(LV_ITEM_NATIVE),
133 CodeCantWorkIfDiffSizes);
134
d2ed74b9
VZ
135 memcpy(&m_item, &item, sizeof(LV_ITEM_NATIVE));
136
137 // convert text from ANSI to Unicod if necessary
8c21905b
VS
138 if ( (item.mask & LVIF_TEXT) && item.pszText )
139 {
d2ed74b9
VZ
140 m_buf = new LV_CONV_BUF(wxConvLocal.LV_CONV_TO_WX(item.pszText));
141 m_item.pszText = (wxChar *)m_buf->data();
8c21905b 142 }
73d8c5fd 143 }
d2ed74b9
VZ
144
145 // ctor without conversion
146 wxLV_ITEM(LV_ITEM_NATIVE& item) : m_buf(NULL), m_pItem(&item) { }
147
148 // ctor with conversion
149 wxLV_ITEM(LV_ITEM_OTHER& item) : m_buf(NULL)
150 {
151 Init(item);
152 }
153
154 ~wxLV_ITEM() { delete m_buf; }
155
156 // conversion to the real LV_ITEM
157 operator LV_ITEM_NATIVE&() const { return *m_pItem; }
158
8c21905b 159private:
d2ed74b9 160 LV_CONV_BUF *m_buf;
8c21905b 161
d2ed74b9
VZ
162 LV_ITEM_NATIVE *m_pItem;
163 LV_ITEM_NATIVE m_item;
22f3361e
VZ
164
165 DECLARE_NO_COPY_CLASS(wxLV_ITEM)
8c21905b
VS
166};
167
7cf46fdb
VZ
168///////////////////////////////////////////////////////
169// Problem:
73d8c5fd
RD
170// The MSW version had problems with SetTextColour() et
171// al as the wxListItemAttr's were stored keyed on the
172// item index. If a item was inserted anywhere but the end
173// of the list the the text attributes (colour etc) for
7cf46fdb 174// the following items were out of sync.
73d8c5fd 175//
7cf46fdb 176// Solution:
73d8c5fd 177// Under MSW the only way to associate data with a List
43e8916f 178// item independent of its position in the list is to
73d8c5fd
RD
179// store a pointer to it in its lParam attribute. However
180// user programs are already using this (via the
7cf46fdb 181// SetItemData() GetItemData() calls).
73d8c5fd
RD
182//
183// However what we can do is store a pointer to a
184// structure which contains the attributes we want *and*
7cf46fdb 185// a lParam for the users data, e.g.
73d8c5fd 186//
7cf46fdb
VZ
187// class wxListItemInternalData
188// {
189// public:
73d8c5fd 190// wxListItemAttr *attr;
7cf46fdb
VZ
191// long lParam; // user data
192// };
73d8c5fd
RD
193//
194// To conserve memory, a wxListItemInternalData is
195// only allocated for a LV_ITEM if text attributes or
7cf46fdb
VZ
196// user data(lparam) are being set.
197
198
199// class wxListItemInternalData
200class wxListItemInternalData
201{
202public:
73d8c5fd 203 wxListItemAttr *attr;
7cf46fdb
VZ
204 LPARAM lParam; // user data
205
206 wxListItemInternalData() : attr(NULL), lParam(0) {}
207 ~wxListItemInternalData()
208 {
209 if (attr)
210 delete attr;
211 };
22f3361e
VZ
212
213 DECLARE_NO_COPY_CLASS(wxListItemInternalData)
7cf46fdb
VZ
214};
215
216// Get the internal data structure
6149de71 217static wxListItemInternalData *wxGetInternalData(HWND hwnd, long itemId);
97c611f8 218static wxListItemInternalData *wxGetInternalData(const wxListCtrl *ctl, long itemId);
6149de71
RD
219static wxListItemAttr *wxGetInternalDataAttr(wxListCtrl *ctl, long itemId);
220static void wxDeleteInternalData(wxListCtrl* ctl, long itemId);
7cf46fdb
VZ
221
222
edccf428 223// ----------------------------------------------------------------------------
2e4df4bf 224// events
edccf428
VZ
225// ----------------------------------------------------------------------------
226
2e4df4bf
VZ
227DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_DRAG)
228DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_RDRAG)
229DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT)
230DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_END_LABEL_EDIT)
231DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_DELETE_ITEM)
232DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS)
c3627a00 233#if WXWIN_COMPATIBILITY_2_4
2e4df4bf
VZ
234DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_GET_INFO)
235DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_SET_INFO)
c3627a00 236#endif
2e4df4bf
VZ
237DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_SELECTED)
238DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_DESELECTED)
239DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_KEY_DOWN)
240DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_INSERT_ITEM)
241DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_CLICK)
11358d39
VZ
242DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_RIGHT_CLICK)
243DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_BEGIN_DRAG)
244DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_DRAGGING)
245DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_END_DRAG)
2e4df4bf
VZ
246DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK)
247DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK)
248DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_ACTIVATED)
0ddefeb0 249DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_FOCUSED)
614391dc 250DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_CACHE_HINT)
2e4df4bf 251
786a2425 252#if wxUSE_EXTENDED_RTTI
bc9fb572
JS
253WX_DEFINE_FLAGS( wxListCtrlStyle )
254
321239b6 255wxBEGIN_FLAGS( wxListCtrlStyle )
bc9fb572
JS
256 // new style border flags, we put them first to
257 // use them for streaming out
321239b6
SC
258 wxFLAGS_MEMBER(wxBORDER_SIMPLE)
259 wxFLAGS_MEMBER(wxBORDER_SUNKEN)
260 wxFLAGS_MEMBER(wxBORDER_DOUBLE)
261 wxFLAGS_MEMBER(wxBORDER_RAISED)
262 wxFLAGS_MEMBER(wxBORDER_STATIC)
263 wxFLAGS_MEMBER(wxBORDER_NONE)
598ddd96 264
bc9fb572 265 // old style border flags
321239b6
SC
266 wxFLAGS_MEMBER(wxSIMPLE_BORDER)
267 wxFLAGS_MEMBER(wxSUNKEN_BORDER)
268 wxFLAGS_MEMBER(wxDOUBLE_BORDER)
269 wxFLAGS_MEMBER(wxRAISED_BORDER)
270 wxFLAGS_MEMBER(wxSTATIC_BORDER)
cb0afb26 271 wxFLAGS_MEMBER(wxBORDER)
bc9fb572
JS
272
273 // standard window styles
321239b6
SC
274 wxFLAGS_MEMBER(wxTAB_TRAVERSAL)
275 wxFLAGS_MEMBER(wxCLIP_CHILDREN)
276 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW)
277 wxFLAGS_MEMBER(wxWANTS_CHARS)
cb0afb26 278 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE)
321239b6
SC
279 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB )
280 wxFLAGS_MEMBER(wxVSCROLL)
281 wxFLAGS_MEMBER(wxHSCROLL)
282
283 wxFLAGS_MEMBER(wxLC_LIST)
284 wxFLAGS_MEMBER(wxLC_REPORT)
285 wxFLAGS_MEMBER(wxLC_ICON)
286 wxFLAGS_MEMBER(wxLC_SMALL_ICON)
287 wxFLAGS_MEMBER(wxLC_ALIGN_TOP)
288 wxFLAGS_MEMBER(wxLC_ALIGN_LEFT)
289 wxFLAGS_MEMBER(wxLC_AUTOARRANGE)
290 wxFLAGS_MEMBER(wxLC_USER_TEXT)
291 wxFLAGS_MEMBER(wxLC_EDIT_LABELS)
292 wxFLAGS_MEMBER(wxLC_NO_HEADER)
293 wxFLAGS_MEMBER(wxLC_SINGLE_SEL)
294 wxFLAGS_MEMBER(wxLC_SORT_ASCENDING)
295 wxFLAGS_MEMBER(wxLC_SORT_DESCENDING)
296 wxFLAGS_MEMBER(wxLC_VIRTUAL)
297
298wxEND_FLAGS( wxListCtrlStyle )
bc9fb572 299
786a2425
SC
300IMPLEMENT_DYNAMIC_CLASS_XTI(wxListCtrl, wxControl,"wx/listctrl.h")
301
321239b6 302wxBEGIN_PROPERTIES_TABLE(wxListCtrl)
598ddd96 303 wxEVENT_PROPERTY( TextUpdated , wxEVT_COMMAND_TEXT_UPDATED , wxCommandEvent )
c5ca409b 304
af498247 305 wxPROPERTY_FLAGS( WindowStyle , wxListCtrlStyle , long , SetWindowStyleFlag , GetWindowStyleFlag , EMPTY_MACROVALUE , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
321239b6 306wxEND_PROPERTIES_TABLE()
786a2425 307
321239b6
SC
308wxBEGIN_HANDLERS_TABLE(wxListCtrl)
309wxEND_HANDLERS_TABLE()
786a2425 310
598ddd96 311wxCONSTRUCTOR_5( wxListCtrl , wxWindow* , Parent , wxWindowID , Id , wxPoint , Position , wxSize , Size , long , WindowStyle )
786a2425
SC
312
313/*
314