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