]> git.saurik.com Git - wxWidgets.git/blame - src/msw/listctrl.cpp
use newly added GetViewRect() instead of trying to guess the list ctrl size ourselves
[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 874.
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
JS
8// Copyright: (c) Julian Smart
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
0d236fd0
VZ
48// include <commctrl.h> "properly"
49#include "wx/msw/wrapcctl.h"
12979259 50
edccf428
VZ
51// ----------------------------------------------------------------------------
52// private functions
53// ----------------------------------------------------------------------------
2bda0e17 54
8dff2b5c
VZ
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);
2bda0e17 66
6f806543
VZ
67// convert our wxListItem to LV_COLUMN
68static void wxConvertToMSWListCol(int col, const wxListItem& item,
69 LV_COLUMN& lvCol);
70
8c21905b
VS
71// ----------------------------------------------------------------------------
72// private helper classes
73// ----------------------------------------------------------------------------
74
75// We have to handle both fooW and fooA notifications in several cases
76// because of broken commctl.dll and/or unicows.dll. This class is used to
73d8c5fd 77// convert LV_ITEMA and LV_ITEMW to LV_ITEM (which is either LV_ITEMA or
8c21905b
VS
78// LV_ITEMW depending on wxUSE_UNICODE setting), so that it can be processed
79// by wxConvertToMSWListItem().
80class wxLV_ITEM
81{
82public:
83 ~wxLV_ITEM() { delete m_buf; }
84 operator LV_ITEM&() const { return *m_item; }
85
86#if wxUSE_UNICODE
87 wxLV_ITEM(LV_ITEMW &item) : m_buf(NULL), m_item(&item) {}
88 wxLV_ITEM(LV_ITEMA &item)
89 {
90 m_item = new LV_ITEM((LV_ITEM&)item);
91 if ( (item.mask & LVIF_TEXT) && item.pszText )
92 {
93 m_buf = new wxMB2WXbuf(wxConvLocal.cMB2WX(item.pszText));
94 m_item->pszText = (wxChar*)m_buf->data();
95 }
96 else
97 m_buf = NULL;
73d8c5fd 98 }
8c21905b
VS
99private:
100 wxMB2WXbuf *m_buf;
101
2b5f62a0 102#else // !wxUSE_UNICODE
8c21905b
VS
103 wxLV_ITEM(LV_ITEMW &item)
104 {
105 m_item = new LV_ITEM((LV_ITEM&)item);
2b5f62a0
VZ
106
107 // the code below doesn't compile without wxUSE_WCHAR_T and as I don't
108 // know if it's useful to have it at all (do we ever get Unicode
109 // notifications in ANSI mode? I don't think so...) I'm not going to
110 // write alternative implementation right now
111 //
112 // but if it is indeed used, we should simply directly use
113 // ::WideCharToMultiByte() here
114#if wxUSE_WCHAR_T
8c21905b
VS
115 if ( (item.mask & LVIF_TEXT) && item.pszText )
116 {
117 m_buf = new wxWC2WXbuf(wxConvLocal.cWC2WX(item.pszText));
118 m_item->pszText = (wxChar*)m_buf->data();
119 }
120 else
2b5f62a0 121#endif // wxUSE_WCHAR_T
8c21905b 122 m_buf = NULL;
73d8c5fd 123 }
8c21905b
VS
124 wxLV_ITEM(LV_ITEMA &item) : m_buf(NULL), m_item(&item) {}
125private:
126 wxWC2WXbuf *m_buf;
2b5f62a0 127#endif // wxUSE_UNICODE/!wxUSE_UNICODE
8c21905b
VS
128
129 LV_ITEM *m_item;
22f3361e
VZ
130
131 DECLARE_NO_COPY_CLASS(wxLV_ITEM)
8c21905b
VS
132};
133
7cf46fdb
VZ
134///////////////////////////////////////////////////////
135// Problem:
73d8c5fd
RD
136// The MSW version had problems with SetTextColour() et
137// al as the wxListItemAttr's were stored keyed on the
138// item index. If a item was inserted anywhere but the end
139// of the list the the text attributes (colour etc) for
7cf46fdb 140// the following items were out of sync.
73d8c5fd 141//
7cf46fdb 142// Solution:
73d8c5fd
RD
143// Under MSW the only way to associate data with a List
144// item independant of its position in the list is to
145// store a pointer to it in its lParam attribute. However
146// user programs are already using this (via the
7cf46fdb 147// SetItemData() GetItemData() calls).
73d8c5fd
RD
148//
149// However what we can do is store a pointer to a
150// structure which contains the attributes we want *and*
7cf46fdb 151// a lParam for the users data, e.g.
73d8c5fd 152//
7cf46fdb
VZ
153// class wxListItemInternalData
154// {
155// public:
73d8c5fd 156// wxListItemAttr *attr;
7cf46fdb
VZ
157// long lParam; // user data
158// };
73d8c5fd
RD
159//
160// To conserve memory, a wxListItemInternalData is
161// only allocated for a LV_ITEM if text attributes or
7cf46fdb
VZ
162// user data(lparam) are being set.
163
164
165// class wxListItemInternalData
166class wxListItemInternalData
167{
168public:
73d8c5fd 169 wxListItemAttr *attr;
7cf46fdb
VZ
170 LPARAM lParam; // user data
171
172 wxListItemInternalData() : attr(NULL), lParam(0) {}
173 ~wxListItemInternalData()
174 {
175 if (attr)
176 delete attr;
177 };
22f3361e
VZ
178
179 DECLARE_NO_COPY_CLASS(wxListItemInternalData)
7cf46fdb
VZ
180};
181
182// Get the internal data structure
6149de71
RD
183static wxListItemInternalData *wxGetInternalData(HWND hwnd, long itemId);
184static wxListItemInternalData *wxGetInternalData(wxListCtrl *ctl, long itemId);
185static wxListItemAttr *wxGetInternalDataAttr(wxListCtrl *ctl, long itemId);
186static void wxDeleteInternalData(wxListCtrl* ctl, long itemId);
7cf46fdb
VZ
187
188
edccf428 189// ----------------------------------------------------------------------------
2e4df4bf 190// events
edccf428
VZ
191// ----------------------------------------------------------------------------
192
2e4df4bf
VZ
193DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_DRAG)
194DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_RDRAG)
195DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT)
196DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_END_LABEL_EDIT)
197DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_DELETE_ITEM)
198DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS)
199DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_GET_INFO)
200DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_SET_INFO)
201DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_SELECTED)
202DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_DESELECTED)
203DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_KEY_DOWN)
204DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_INSERT_ITEM)
205DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_CLICK)
11358d39
VZ
206DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_RIGHT_CLICK)
207DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_BEGIN_DRAG)
208DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_DRAGGING)
209DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_END_DRAG)
2e4df4bf
VZ
210DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK)
211DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK)
212DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_ACTIVATED)
0ddefeb0 213DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_FOCUSED)
614391dc 214DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_CACHE_HINT)
2e4df4bf 215
786a2425 216#if wxUSE_EXTENDED_RTTI
bc9fb572
JS
217WX_DEFINE_FLAGS( wxListCtrlStyle )
218
321239b6 219wxBEGIN_FLAGS( wxListCtrlStyle )
bc9fb572
JS
220 // new style border flags, we put them first to
221 // use them for streaming out
321239b6
SC
222 wxFLAGS_MEMBER(wxBORDER_SIMPLE)
223 wxFLAGS_MEMBER(wxBORDER_SUNKEN)
224 wxFLAGS_MEMBER(wxBORDER_DOUBLE)
225 wxFLAGS_MEMBER(wxBORDER_RAISED)
226 wxFLAGS_MEMBER(wxBORDER_STATIC)
227 wxFLAGS_MEMBER(wxBORDER_NONE)
bc9fb572
JS
228
229 // old style border flags
321239b6
SC
230 wxFLAGS_MEMBER(wxSIMPLE_BORDER)
231 wxFLAGS_MEMBER(wxSUNKEN_BORDER)
232 wxFLAGS_MEMBER(wxDOUBLE_BORDER)
233 wxFLAGS_MEMBER(wxRAISED_BORDER)
234 wxFLAGS_MEMBER(wxSTATIC_BORDER)
235 wxFLAGS_MEMBER(wxNO_BORDER)
bc9fb572
JS
236
237 // standard window styles
321239b6
SC
238 wxFLAGS_MEMBER(wxTAB_TRAVERSAL)
239 wxFLAGS_MEMBER(wxCLIP_CHILDREN)
240 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW)
241 wxFLAGS_MEMBER(wxWANTS_CHARS)
242 wxFLAGS_MEMBER(wxNO_FULL_REPAINT_ON_RESIZE)
243 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB )
244 wxFLAGS_MEMBER(wxVSCROLL)
245 wxFLAGS_MEMBER(wxHSCROLL)
246
247 wxFLAGS_MEMBER(wxLC_LIST)
248 wxFLAGS_MEMBER(wxLC_REPORT)
249 wxFLAGS_MEMBER(wxLC_ICON)
250 wxFLAGS_MEMBER(wxLC_SMALL_ICON)
251 wxFLAGS_MEMBER(wxLC_ALIGN_TOP)
252 wxFLAGS_MEMBER(wxLC_ALIGN_LEFT)
253 wxFLAGS_MEMBER(wxLC_AUTOARRANGE)
254 wxFLAGS_MEMBER(wxLC_USER_TEXT)
255 wxFLAGS_MEMBER(wxLC_EDIT_LABELS)
256 wxFLAGS_MEMBER(wxLC_NO_HEADER)
257 wxFLAGS_MEMBER(wxLC_SINGLE_SEL)
258 wxFLAGS_MEMBER(wxLC_SORT_ASCENDING)
259 wxFLAGS_MEMBER(wxLC_SORT_DESCENDING)
260 wxFLAGS_MEMBER(wxLC_VIRTUAL)
261
262wxEND_FLAGS( wxListCtrlStyle )
bc9fb572 263
786a2425
SC
264IMPLEMENT_DYNAMIC_CLASS_XTI(wxListCtrl, wxControl,"wx/listctrl.h")
265
321239b6
SC
266wxBEGIN_PROPERTIES_TABLE(wxListCtrl)
267 wxEVENT_PROPERTY( TextUpdated , wxEVT_COMMAND_TEXT_UPDATED , wxCommandEvent )
c5ca409b 268
321239b6
SC
269 wxPROPERTY_FLAGS( WindowStyle , wxListCtrlStyle , long , SetWindowStyleFlag , GetWindowStyleFlag , , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
270wxEND_PROPERTIES_TABLE()
786a2425 271
321239b6
SC
272wxBEGIN_HANDLERS_TABLE(wxListCtrl)
273wxEND_HANDLERS_TABLE()
786a2425 274
321239b6 275wxCONSTRUCTOR_5( wxListCtrl , wxWindow* , Parent , wxWindowID , Id , wxPoint , Position , wxSize , Size , long , WindowStyle )
786a2425
SC
276
277/*
278