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