]> git.saurik.com Git - wxWidgets.git/blame - src/msw/listctrl.cpp
Fix for GCC compilation
[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 1049.
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
edccf428
VZ
59// ----------------------------------------------------------------------------
60// private functions
61// ----------------------------------------------------------------------------
2bda0e17 62
8dff2b5c
VZ
63// convert our state and mask flags to LV_ITEM constants
64static void wxConvertToMSWFlags(long state, long mask, LV_ITEM& lvItem);
65
66// convert wxListItem to LV_ITEM
67static void wxConvertToMSWListItem(const wxListCtrl *ctrl,
68 const wxListItem& info, LV_ITEM& lvItem);
69
70// convert LV_ITEM to wxListItem
71static void wxConvertFromMSWListItem(HWND hwndListCtrl,
72 wxListItem& info,
73 /* const */ LV_ITEM& lvItem);
2bda0e17 74
6f806543
VZ
75// convert our wxListItem to LV_COLUMN
76static void wxConvertToMSWListCol(int col, const wxListItem& item,
77 LV_COLUMN& lvCol);
78
8c21905b
VS
79// ----------------------------------------------------------------------------
80// private helper classes
81// ----------------------------------------------------------------------------
82
83// We have to handle both fooW and fooA notifications in several cases
d2ed74b9 84// because of broken comctl32.dll and/or unicows.dll. This class is used to
73d8c5fd 85// convert LV_ITEMA and LV_ITEMW to LV_ITEM (which is either LV_ITEMA or
8c21905b
VS
86// LV_ITEMW depending on wxUSE_UNICODE setting), so that it can be processed
87// by wxConvertToMSWListItem().
d2ed74b9
VZ
88#if wxUSE_UNICODE
89 #define LV_ITEM_NATIVE LV_ITEMW
90 #define LV_ITEM_OTHER LV_ITEMA
91
92 #define LV_CONV_TO_WX cMB2WX
93 #define LV_CONV_BUF wxMB2WXbuf
94#else // ANSI
95 #define LV_ITEM_NATIVE LV_ITEMA
96 #define LV_ITEM_OTHER LV_ITEMW
97
98 #define LV_CONV_TO_WX cWC2WX
99 #define LV_CONV_BUF wxWC2WXbuf
100#endif // Unicode/ANSI
101
8c21905b
VS
102class wxLV_ITEM
103{
104public:
d2ed74b9
VZ
105 // default ctor, use Init() later
106 wxLV_ITEM() { m_buf = NULL; m_pItem = NULL; }
8c21905b 107
d2ed74b9
VZ
108 // init without conversion
109 void Init(LV_ITEM_NATIVE& item)
8c21905b 110 {
d2ed74b9
VZ
111 wxASSERT_MSG( !m_pItem, _T("Init() called twice?") );
112
113 m_pItem = &item;
73d8c5fd 114 }
8c21905b 115
d2ed74b9
VZ
116 // init with conversion
117 void Init(LV_ITEM_OTHER& item)
8c21905b 118 {
d2ed74b9
VZ
119 // avoid unnecessary dynamic memory allocation, jjust make m_pItem
120 // point to our own m_item
2b5f62a0 121
1c6f2414
WS
122 // memcpy() can't work if the struct sizes are different
123 wxCOMPILE_TIME_ASSERT( sizeof(LV_ITEM_OTHER) == sizeof(LV_ITEM_NATIVE),
124 CodeCantWorkIfDiffSizes);
125
d2ed74b9
VZ
126 memcpy(&m_item, &item, sizeof(LV_ITEM_NATIVE));
127
128 // convert text from ANSI to Unicod if necessary
8c21905b
VS
129 if ( (item.mask & LVIF_TEXT) && item.pszText )
130 {
d2ed74b9
VZ
131 m_buf = new LV_CONV_BUF(wxConvLocal.LV_CONV_TO_WX(item.pszText));
132 m_item.pszText = (wxChar *)m_buf->data();
8c21905b 133 }
73d8c5fd 134 }
d2ed74b9
VZ
135
136 // ctor without conversion
137 wxLV_ITEM(LV_ITEM_NATIVE& item) : m_buf(NULL), m_pItem(&item) { }
138
139 // ctor with conversion
140 wxLV_ITEM(LV_ITEM_OTHER& item) : m_buf(NULL)
141 {
142 Init(item);
143 }
144
145 ~wxLV_ITEM() { delete m_buf; }
146
147 // conversion to the real LV_ITEM
148 operator LV_ITEM_NATIVE&() const { return *m_pItem; }
149
8c21905b 150private:
d2ed74b9 151 LV_CONV_BUF *m_buf;
8c21905b 152
d2ed74b9
VZ
153 LV_ITEM_NATIVE *m_pItem;
154 LV_ITEM_NATIVE m_item;
22f3361e
VZ
155
156 DECLARE_NO_COPY_CLASS(wxLV_ITEM)
8c21905b
VS
157};
158
7cf46fdb
VZ
159///////////////////////////////////////////////////////
160// Problem:
73d8c5fd
RD
161// The MSW version had problems with SetTextColour() et
162// al as the wxListItemAttr's were stored keyed on the
163// item index. If a item was inserted anywhere but the end
164// of the list the the text attributes (colour etc) for
7cf46fdb 165// the following items were out of sync.
73d8c5fd 166//
7cf46fdb 167// Solution:
73d8c5fd
RD
168// Under MSW the only way to associate data with a List
169// item independant of its position in the list is to
170// store a pointer to it in its lParam attribute. However
171// user programs are already using this (via the
7cf46fdb 172// SetItemData() GetItemData() calls).
73d8c5fd
RD
173//
174// However what we can do is store a pointer to a
175// structure which contains the attributes we want *and*
7cf46fdb 176// a lParam for the users data, e.g.
73d8c5fd 177//
7cf46fdb
VZ
178// class wxListItemInternalData
179// {
180// public:
73d8c5fd 181// wxListItemAttr *attr;
7cf46fdb
VZ
182// long lParam; // user data
183// };
73d8c5fd
RD
184//
185// To conserve memory, a wxListItemInternalData is
186// only allocated for a LV_ITEM if text attributes or
7cf46fdb
VZ
187// user data(lparam) are being set.
188
189
190// class wxListItemInternalData
191class wxListItemInternalData
192{
193public:
73d8c5fd 194 wxListItemAttr *attr;
7cf46fdb
VZ
195 LPARAM lParam; // user data
196
197 wxListItemInternalData() : attr(NULL), lParam(0) {}
198 ~wxListItemInternalData()
199 {
200 if (attr)
201 delete attr;
202 };
22f3361e
VZ
203
204 DECLARE_NO_COPY_CLASS(wxListItemInternalData)
7cf46fdb
VZ
205};
206
207// Get the internal data structure
6149de71 208static wxListItemInternalData *wxGetInternalData(HWND hwnd, long itemId);
97c611f8 209static wxListItemInternalData *wxGetInternalData(const wxListCtrl *ctl, long itemId);
6149de71
RD
210static wxListItemAttr *wxGetInternalDataAttr(wxListCtrl *ctl, long itemId);
211static void wxDeleteInternalData(wxListCtrl* ctl, long itemId);
7cf46fdb
VZ
212
213
edccf428 214// ----------------------------------------------------------------------------
2e4df4bf 215// events
edccf428
VZ
216// ----------------------------------------------------------------------------
217
2e4df4bf
VZ
218DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_DRAG)
219DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_RDRAG)
220DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT)
221DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_END_LABEL_EDIT)
222DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_DELETE_ITEM)
223DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS)
c3627a00 224#if WXWIN_COMPATIBILITY_2_4
2e4df4bf
VZ
225DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_GET_INFO)
226DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_SET_INFO)
c3627a00 227#endif
2e4df4bf
VZ
228DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_SELECTED)
229DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_DESELECTED)
230DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_KEY_DOWN)
231DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_INSERT_ITEM)
232DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_CLICK)
11358d39
VZ
233DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_RIGHT_CLICK)
234DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_BEGIN_DRAG)
235DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_DRAGGING)
236DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_END_DRAG)
2e4df4bf
VZ
237DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK)
238DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK)
239DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_ACTIVATED)
0ddefeb0 240DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_FOCUSED)
614391dc 241DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_CACHE_HINT)
2e4df4bf 242
786a2425 243#if wxUSE_EXTENDED_RTTI
bc9fb572
JS
244WX_DEFINE_FLAGS( wxListCtrlStyle )
245
321239b6 246wxBEGIN_FLAGS( wxListCtrlStyle )
bc9fb572
JS
247 // new style border flags, we put them first to
248 // use them for streaming out
321239b6
SC
249 wxFLAGS_MEMBER(wxBORDER_SIMPLE)
250 wxFLAGS_MEMBER(wxBORDER_SUNKEN)
251 wxFLAGS_MEMBER(wxBORDER_DOUBLE)
252 wxFLAGS_MEMBER(wxBORDER_RAISED)
253 wxFLAGS_MEMBER(wxBORDER_STATIC)
254 wxFLAGS_MEMBER(wxBORDER_NONE)
598ddd96 255
bc9fb572 256 // old style border flags
321239b6
SC
257 wxFLAGS_MEMBER(wxSIMPLE_BORDER)
258 wxFLAGS_MEMBER(wxSUNKEN_BORDER)
259 wxFLAGS_MEMBER(wxDOUBLE_BORDER)
260 wxFLAGS_MEMBER(wxRAISED_BORDER)
261 wxFLAGS_MEMBER(wxSTATIC_BORDER)
cb0afb26 262 wxFLAGS_MEMBER(wxBORDER)
bc9fb572
JS
263
264 // standard window styles
321239b6
SC
265 wxFLAGS_MEMBER(wxTAB_TRAVERSAL)
266 wxFLAGS_MEMBER(wxCLIP_CHILDREN)
267 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW)
268 wxFLAGS_MEMBER(wxWANTS_CHARS)
cb0afb26 269 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE)
321239b6
SC
270 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB )
271 wxFLAGS_MEMBER(wxVSCROLL)
272 wxFLAGS_MEMBER(wxHSCROLL)
273
274 wxFLAGS_MEMBER(wxLC_LIST)
275 wxFLAGS_MEMBER(wxLC_REPORT)
276 wxFLAGS_MEMBER(wxLC_ICON)
277 wxFLAGS_MEMBER(wxLC_SMALL_ICON)
278 wxFLAGS_MEMBER(wxLC_ALIGN_TOP)
279 wxFLAGS_MEMBER(wxLC_ALIGN_LEFT)
280 wxFLAGS_MEMBER(wxLC_AUTOARRANGE)
281 wxFLAGS_MEMBER(wxLC_USER_TEXT)
282 wxFLAGS_MEMBER(wxLC_EDIT_LABELS)
283 wxFLAGS_MEMBER(wxLC_NO_HEADER)
284 wxFLAGS_MEMBER(wxLC_SINGLE_SEL)
285 wxFLAGS_MEMBER(wxLC_SORT_ASCENDING)
286 wxFLAGS_MEMBER(wxLC_SORT_DESCENDING)
287 wxFLAGS_MEMBER(wxLC_VIRTUAL)
288
289wxEND_FLAGS( wxListCtrlStyle )
bc9fb572 290
786a2425
SC
291IMPLEMENT_DYNAMIC_CLASS_XTI(wxListCtrl, wxControl,"wx/listctrl.h")
292
321239b6 293wxBEGIN_PROPERTIES_TABLE(wxListCtrl)
598ddd96 294 wxEVENT_PROPERTY( TextUpdated , wxEVT_COMMAND_TEXT_UPDATED , wxCommandEvent )
c5ca409b 295
af498247 296 wxPROPERTY_FLAGS( WindowStyle , wxListCtrlStyle , long , SetWindowStyleFlag , GetWindowStyleFlag , EMPTY_MACROVALUE , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
321239b6 297wxEND_PROPERTIES_TABLE()
786a2425 298
321239b6
SC
299wxBEGIN_HANDLERS_TABLE(wxListCtrl)
300wxEND_HANDLERS_TABLE()
786a2425 301
598ddd96 302wxCONSTRUCTOR_5( wxListCtrl , wxWindow* , Parent , wxWindowID , Id , wxPoint , Position , wxSize , Size , long , WindowStyle )
786a2425
SC
303
304/*
305