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