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