]>
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 | ||
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 |
56 | static void wxConvertToMSWFlags(long state, long mask, LV_ITEM& lvItem); | |
57 | ||
58 | // convert wxListItem to LV_ITEM | |
59 | static void wxConvertToMSWListItem(const wxListCtrl *ctrl, | |
60 | const wxListItem& info, LV_ITEM& lvItem); | |
61 | ||
62 | // convert LV_ITEM to wxListItem | |
63 | static void wxConvertFromMSWListItem(HWND hwndListCtrl, | |
64 | wxListItem& info, | |
65 | /* const */ LV_ITEM& lvItem); | |
2bda0e17 | 66 | |
6f806543 VZ |
67 | // convert our wxListItem to LV_COLUMN |
68 | static 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 | |
d2ed74b9 | 76 | // because of broken comctl32.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(). | |
d2ed74b9 VZ |
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 | ||
8c21905b VS |
94 | class wxLV_ITEM |
95 | { | |
96 | public: | |
d2ed74b9 VZ |
97 | // default ctor, use Init() later |
98 | wxLV_ITEM() { m_buf = NULL; m_pItem = NULL; } | |
8c21905b | 99 | |
d2ed74b9 VZ |
100 | // init without conversion |
101 | void Init(LV_ITEM_NATIVE& item) | |
8c21905b | 102 | { |
d2ed74b9 VZ |
103 | wxASSERT_MSG( !m_pItem, _T("Init() called twice?") ); |
104 | ||
105 | m_pItem = &item; | |
73d8c5fd | 106 | } |
8c21905b | 107 | |
d2ed74b9 VZ |
108 | // init with conversion |
109 | void Init(LV_ITEM_OTHER& item) | |
8c21905b | 110 | { |
d2ed74b9 VZ |
111 | // avoid unnecessary dynamic memory allocation, jjust make m_pItem |
112 | // point to our own m_item | |
2b5f62a0 | 113 | |
d2ed74b9 VZ |
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 | |
8c21905b VS |
121 | if ( (item.mask & LVIF_TEXT) && item.pszText ) |
122 | { | |
d2ed74b9 VZ |
123 | m_buf = new LV_CONV_BUF(wxConvLocal.LV_CONV_TO_WX(item.pszText)); |
124 | m_item.pszText = (wxChar *)m_buf->data(); | |
8c21905b | 125 | } |
73d8c5fd | 126 | } |
d2ed74b9 VZ |
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 | ||
8c21905b | 142 | private: |
d2ed74b9 | 143 | LV_CONV_BUF *m_buf; |
8c21905b | 144 | |
d2ed74b9 VZ |
145 | LV_ITEM_NATIVE *m_pItem; |
146 | LV_ITEM_NATIVE m_item; | |
22f3361e VZ |
147 | |
148 | DECLARE_NO_COPY_CLASS(wxLV_ITEM) | |
8c21905b VS |
149 | }; |
150 | ||
7cf46fdb VZ |
151 | /////////////////////////////////////////////////////// |
152 | // Problem: | |
73d8c5fd RD |
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 | |
7cf46fdb | 157 | // the following items were out of sync. |
73d8c5fd | 158 | // |
7cf46fdb | 159 | // Solution: |
73d8c5fd RD |
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 | |
7cf46fdb | 164 | // SetItemData() GetItemData() calls). |
73d8c5fd RD |
165 | // |
166 | // However what we can do is store a pointer to a | |
167 | // structure which contains the attributes we want *and* | |
7cf46fdb | 168 | // a lParam for the users data, e.g. |
73d8c5fd | 169 | // |
7cf46fdb VZ |
170 | // class wxListItemInternalData |
171 | // { | |
172 | // public: | |
73d8c5fd | 173 | // wxListItemAttr *attr; |
7cf46fdb VZ |
174 | // long lParam; // user data |
175 | // }; | |
73d8c5fd RD |
176 | // |
177 | // To conserve memory, a wxListItemInternalData is | |
178 | // only allocated for a LV_ITEM if text attributes or | |
7cf46fdb VZ |
179 | // user data(lparam) are being set. |
180 | ||
181 | ||
182 | // class wxListItemInternalData | |
183 | class wxListItemInternalData | |
184 | { | |
185 | public: | |
73d8c5fd | 186 | wxListItemAttr *attr; |
7cf46fdb VZ |
187 | LPARAM lParam; // user data |
188 | ||
189 | wxListItemInternalData() : attr(NULL), lParam(0) {} | |
190 | ~wxListItemInternalData() | |
191 | { | |
192 | if (attr) | |
193 | delete attr; | |
194 | }; | |
22f3361e VZ |
195 | |
196 | DECLARE_NO_COPY_CLASS(wxListItemInternalData) | |
7cf46fdb VZ |
197 | }; |
198 | ||
199 | // Get the internal data structure | |
6149de71 RD |
200 | static wxListItemInternalData *wxGetInternalData(HWND hwnd, long itemId); |
201 | static wxListItemInternalData *wxGetInternalData(wxListCtrl *ctl, long itemId); | |
202 | static wxListItemAttr *wxGetInternalDataAttr(wxListCtrl *ctl, long itemId); | |
203 | static void wxDeleteInternalData(wxListCtrl* ctl, long itemId); | |
7cf46fdb VZ |
204 | |
205 | ||
edccf428 | 206 | // ---------------------------------------------------------------------------- |
2e4df4bf | 207 | // events |
edccf428 VZ |
208 | // ---------------------------------------------------------------------------- |
209 | ||
2e4df4bf VZ |
210 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_DRAG) |
211 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_RDRAG) | |
212 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT) | |
213 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_END_LABEL_EDIT) | |
214 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_DELETE_ITEM) | |
215 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS) | |
216 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_GET_INFO) | |
217 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_SET_INFO) | |
218 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_SELECTED) | |
219 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_DESELECTED) | |
220 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_KEY_DOWN) | |
221 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_INSERT_ITEM) | |
222 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_CLICK) | |
11358d39 VZ |
223 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_RIGHT_CLICK) |
224 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_BEGIN_DRAG) | |
225 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_DRAGGING) | |
226 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_END_DRAG) | |
2e4df4bf VZ |
227 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK) |
228 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK) | |
229 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_ACTIVATED) | |
0ddefeb0 | 230 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_FOCUSED) |
614391dc | 231 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_CACHE_HINT) |
2e4df4bf | 232 | |
786a2425 | 233 | #if wxUSE_EXTENDED_RTTI |
bc9fb572 JS |
234 | WX_DEFINE_FLAGS( wxListCtrlStyle ) |
235 | ||
321239b6 | 236 | wxBEGIN_FLAGS( wxListCtrlStyle ) |
bc9fb572 JS |
237 | // new style border flags, we put them first to |
238 | // use them for streaming out | |
321239b6 SC |
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) | |
bc9fb572 JS |
245 | |
246 | // old style border flags | |
321239b6 SC |
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) | |
cb0afb26 | 252 | wxFLAGS_MEMBER(wxBORDER) |
bc9fb572 JS |
253 | |
254 | // standard window styles | |
321239b6 SC |
255 | wxFLAGS_MEMBER(wxTAB_TRAVERSAL) |
256 | wxFLAGS_MEMBER(wxCLIP_CHILDREN) | |
257 | wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW) | |
258 | wxFLAGS_MEMBER(wxWANTS_CHARS) | |
cb0afb26 | 259 | wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE) |
321239b6 SC |
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 | ||
279 | wxEND_FLAGS( wxListCtrlStyle ) | |
bc9fb572 | 280 | |
786a2425 SC |
281 | IMPLEMENT_DYNAMIC_CLASS_XTI(wxListCtrl, wxControl,"wx/listctrl.h") |
282 | ||
321239b6 SC |
283 | wxBEGIN_PROPERTIES_TABLE(wxListCtrl) |
284 | wxEVENT_PROPERTY( TextUpdated , wxEVT_COMMAND_TEXT_UPDATED , wxCommandEvent ) | |
c5ca409b | 285 | |
321239b6 SC |
286 | wxPROPERTY_FLAGS( WindowStyle , wxListCtrlStyle , long , SetWindowStyleFlag , GetWindowStyleFlag , , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style |
287 | wxEND_PROPERTIES_TABLE() | |
786a2425 | 288 | |
321239b6 SC |
289 | wxBEGIN_HANDLERS_TABLE(wxListCtrl) |
290 | wxEND_HANDLERS_TABLE() | |
786a2425 | 291 | |
321239b6 | 292 | wxCONSTRUCTOR_5( wxListCtrl , wxWindow* , Parent , wxWindowID , Id , wxPoint , Position , wxSize , Size , long , WindowStyle ) |
786a2425 SC |
293 | |
294 | /* | |
295 | Content-type: text/html ]>