]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/msw/listctrl.cpp
Assert fixes [ 1212949 ] Fix some asserts in wxMediaCtrl
[wxWidgets.git] / src / msw / listctrl.cpp
... / ...
Content-type: text/html ]> git.saurik.com Git - wxWidgets.git/blame_incremental - 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 314.
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: src/msw/listctrl.cpp
3// Purpose: wxListCtrl
4// Author: Julian Smart
5// Modified by:
6// Created: 04/01/98
7// RCS-ID: $Id$
8// Copyright: (c) Julian Smart
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19
20#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
21 #pragma implementation "listctrl.h"
22 #pragma implementation "listctrlbase.h"
23#endif
24
25// For compilers that support precompilation, includes "wx.h".
26#include "wx/wxprec.h"
27
28#ifdef __BORLANDC__
29 #pragma hdrstop
30#endif
31
32#if wxUSE_LISTCTRL && defined(__WIN95__)
33
34#ifndef WX_PRECOMP
35 #include "wx/app.h"
36 #include "wx/intl.h"
37 #include "wx/log.h"
38 #include "wx/settings.h"
39#endif
40
41#include "wx/textctrl.h"
42#include "wx/imaglist.h"
43#include "wx/listctrl.h"
44#include "wx/dcclient.h"
45
46#include "wx/msw/private.h"
47
48#if defined(__WXWINCE__) && !defined(__HANDHELDPC__)
49 #include <ole2.h>
50 #include <shellapi.h>
51 #if _WIN32_WCE < 400
52 #include <aygshell.h>
53 #endif
54#endif
55
56// include <commctrl.h> "properly"
57#include "wx/msw/wrapcctl.h"
58
59// Currently gcc and watcom don't define NMLVFINDITEM, and DMC only defines
60// it by its old name NM_FINDTIEM.
61//
62#if defined(__VISUALC__) || defined(__BORLANDC__) || defined(NMLVFINDITEM)
63 #define HAVE_NMLVFINDITEM 1
64#elif defined(__DMC__) || defined(NM_FINDITEM)
65 #define HAVE_NM_FINDITEM 1
66#endif
67
68// ----------------------------------------------------------------------------
69// private functions
70// ----------------------------------------------------------------------------
71
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);
83
84// convert our wxListItem to LV_COLUMN
85static void wxConvertToMSWListCol(int col, const wxListItem& item,
86 LV_COLUMN& lvCol);
87
88// ----------------------------------------------------------------------------
89// private helper classes
90// ----------------------------------------------------------------------------
91
92// We have to handle both fooW and fooA notifications in several cases
93// because of broken comctl32.dll and/or unicows.dll. This class is used to
94// convert LV_ITEMA and LV_ITEMW to LV_ITEM (which is either LV_ITEMA or
95// LV_ITEMW depending on wxUSE_UNICODE setting), so that it can be processed
96// by wxConvertToMSWListItem().
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
111class wxLV_ITEM
112{
113public:
114 // default ctor, use Init() later
115 wxLV_ITEM() { m_buf = NULL; m_pItem = NULL; }
116
117 // init without conversion
118 void Init(LV_ITEM_NATIVE& item)
119 {
120 wxASSERT_MSG( !m_pItem, _T("Init() called twice?") );
121
122 m_pItem = &item;
123 }
124
125 // init with conversion
126 void Init(LV_ITEM_OTHER& item)
127 {
128 // avoid unnecessary dynamic memory allocation, jjust make m_pItem
129 // point to our own m_item
130
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
135 memcpy(&m_item, &item, sizeof(LV_ITEM_NATIVE));
136
137 // convert text from ANSI to Unicod if necessary
138 if ( (item.mask & LVIF_TEXT) && item.pszText )
139 {
140 m_buf = new LV_CONV_BUF(wxConvLocal.LV_CONV_TO_WX(item.pszText));
141 m_item.pszText = (wxChar *)m_buf->data();
142 }
143 }
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
159private:
160 LV_CONV_BUF *m_buf;
161
162 LV_ITEM_NATIVE *m_pItem;
163 LV_ITEM_NATIVE m_item;
164
165 DECLARE_NO_COPY_CLASS(wxLV_ITEM)
166};
167
168///////////////////////////////////////////////////////
169// Problem:
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
174// the following items were out of sync.
175//
176// Solution:
177// Under MSW the only way to associate data with a List
178// item independent of its position in the list is to
179// store a pointer to it in its lParam attribute. However
180// user programs are already using this (via the
181// SetItemData() GetItemData() calls).
182//
183// However what we can do is store a pointer to a
184// structure which contains the attributes we want *and*
185// a lParam for the users data, e.g.
186//
187// class wxListItemInternalData
188// {
189// public:
190// wxListItemAttr *attr;
191// long lParam; // user data
192// };
193//
194// To conserve memory, a wxListItemInternalData is
195// only allocated for a LV_ITEM if text attributes or
196// user data(lparam) are being set.
197
198
199// class wxListItemInternalData
200class wxListItemInternalData
201{
202public:
203 wxListItemAttr *attr;
204 LPARAM lParam; // user data
205
206 wxListItemInternalData() : attr(NULL), lParam(0) {}
207 ~wxListItemInternalData()
208 {
209 if (attr)
210 delete attr;
211 };
212
213 DECLARE_NO_COPY_CLASS(wxListItemInternalData)
214};
215
216// Get the internal data structure
217static wxListItemInternalData *wxGetInternalData(HWND hwnd, long itemId);
218static wxListItemInternalData *wxGetInternalData(const wxListCtrl *ctl, long itemId);
219static wxListItemAttr *wxGetInternalDataAttr(wxListCtrl *ctl, long itemId);
220static void wxDeleteInternalData(wxListCtrl* ctl, long itemId);
221
222
223// ----------------------------------------------------------------------------
224// events
225// ----------------------------------------------------------------------------
226
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)
233#if WXWIN_COMPATIBILITY_2_4
234DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_GET_INFO)
235DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_SET_INFO)
236#endif
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)
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)
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)
249DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_FOCUSED)
250DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_CACHE_HINT)
251
252#if wxUSE_EXTENDED_RTTI
253WX_DEFINE_FLAGS( wxListCtrlStyle )
254
255wxBEGIN_FLAGS( wxListCtrlStyle )
256 // new style border flags, we put them first to
257 // use them for streaming out
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)
264
265 // old style border flags
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)
271 wxFLAGS_MEMBER(wxBORDER)
272
273 // standard window styles
274 wxFLAGS_MEMBER(wxTAB_TRAVERSAL)
275 wxFLAGS_MEMBER(wxCLIP_CHILDREN)
276 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW)
277 wxFLAGS_MEMBER(wxWANTS_CHARS)
278 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE)
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 )
299
300IMPLEMENT_DYNAMIC_CLASS_XTI(wxListCtrl, wxControl,"wx/listctrl.h")
301
302wxBEGIN_PROPERTIES_TABLE(wxListCtrl)
303 wxEVENT_PROPERTY( TextUpdated , wxEVT_COMMAND_TEXT_UPDATED , wxCommandEvent )
304
305 wxPROPERTY_FLAGS( WindowStyle , wxListCtrlStyle , long , SetWindowStyleFlag , GetWindowStyleFlag , EMPTY_MACROVALUE , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
306wxEND_PROPERTIES_TABLE()
307
308wxBEGIN_HANDLERS_TABLE(wxListCtrl)
309wxEND_HANDLERS_TABLE()
310
311wxCONSTRUCTOR_5( wxListCtrl , wxWindow* , Parent , wxWindowID , Id , wxPoint , Position , wxSize , Size , long , WindowStyle )
312
313/*
314