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