]>
Commit | Line | Data |
---|---|---|
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 | |
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); | |
66 | ||
67 | // convert our wxListItem to LV_COLUMN | |
68 | static 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 commctl.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 | class wxLV_ITEM | |
81 | { | |
82 | public: | |
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; | |
98 | } | |
99 | private: | |
100 | wxMB2WXbuf *m_buf; | |
101 | ||
102 | #else // !wxUSE_UNICODE | |
103 | wxLV_ITEM(LV_ITEMW &item) | |
104 | { | |
105 | m_item = new LV_ITEM((LV_ITEM&)item); | |
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 | |
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 | |
121 | #endif // wxUSE_WCHAR_T | |
122 | m_buf = NULL; | |
123 | } | |
124 | wxLV_ITEM(LV_ITEMA &item) : m_buf(NULL), m_item(&item) {} | |
125 | private: | |
126 | wxWC2WXbuf *m_buf; | |
127 | #endif // wxUSE_UNICODE/!wxUSE_UNICODE | |
128 | ||
129 | LV_ITEM *m_item; | |
130 | ||
131 | DECLARE_NO_COPY_CLASS(wxLV_ITEM) | |
132 | }; | |
133 | ||
134 | /////////////////////////////////////////////////////// | |
135 | // Problem: | |
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 | |
140 | // the following items were out of sync. | |
141 | // | |
142 | // Solution: | |
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 | |
147 | // SetItemData() GetItemData() calls). | |
148 | // | |
149 | // However what we can do is store a pointer to a | |
150 | // structure which contains the attributes we want *and* | |
151 | // a lParam for the users data, e.g. | |
152 | // | |
153 | // class wxListItemInternalData | |
154 | // { | |
155 | // public: | |
156 | // wxListItemAttr *attr; | |
157 | // long lParam; // user data | |
158 | // }; | |
159 | // | |
160 | // To conserve memory, a wxListItemInternalData is | |
161 | // only allocated for a LV_ITEM if text attributes or | |
162 | // user data(lparam) are being set. | |
163 | ||
164 | ||
165 | // class wxListItemInternalData | |
166 | class wxListItemInternalData | |
167 | { | |
168 | public: | |
169 | wxListItemAttr *attr; | |
170 | LPARAM lParam; // user data | |
171 | ||
172 | wxListItemInternalData() : attr(NULL), lParam(0) {} | |
173 | ~wxListItemInternalData() | |
174 | { | |
175 | if (attr) | |
176 | delete attr; | |
177 | }; | |
178 | ||
179 | DECLARE_NO_COPY_CLASS(wxListItemInternalData) | |
180 | }; | |
181 | ||
182 | // Get the internal data structure | |
183 | static wxListItemInternalData *wxGetInternalData(HWND hwnd, long itemId); | |
184 | static wxListItemInternalData *wxGetInternalData(wxListCtrl *ctl, long itemId); | |
185 | static wxListItemAttr *wxGetInternalDataAttr(wxListCtrl *ctl, long itemId); | |
186 | static void wxDeleteInternalData(wxListCtrl* ctl, long itemId); | |
187 | ||
188 | ||
189 | // ---------------------------------------------------------------------------- | |
190 | // events | |
191 | // ---------------------------------------------------------------------------- | |
192 | ||
193 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_DRAG) | |
194 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_RDRAG) | |
195 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT) | |
196 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_END_LABEL_EDIT) | |
197 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_DELETE_ITEM) | |
198 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS) | |
199 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_GET_INFO) | |
200 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_SET_INFO) | |
201 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_SELECTED) | |
202 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_DESELECTED) | |
203 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_KEY_DOWN) | |
204 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_INSERT_ITEM) | |
205 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_CLICK) | |
206 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_RIGHT_CLICK) | |
207 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_BEGIN_DRAG) | |
208 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_DRAGGING) | |
209 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_END_DRAG) | |
210 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK) | |
211 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK) | |
212 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_ACTIVATED) | |
213 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_FOCUSED) | |
214 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_CACHE_HINT) | |
215 | ||
216 | #if wxUSE_EXTENDED_RTTI | |
217 | WX_DEFINE_FLAGS( wxListCtrlStyle ) | |
218 | ||
219 | wxBEGIN_FLAGS( wxListCtrlStyle ) | |
220 | // new style border flags, we put them first to | |
221 | // use them for streaming out | |
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) | |
228 | ||
229 | // old style border flags | |
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) | |
236 | ||
237 | // standard window styles | |
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 | ||
262 | wxEND_FLAGS( wxListCtrlStyle ) | |
263 | ||
264 | IMPLEMENT_DYNAMIC_CLASS_XTI(wxListCtrl, wxControl,"wx/listctrl.h") | |
265 | ||
266 | wxBEGIN_PROPERTIES_TABLE(wxListCtrl) | |
267 | wxEVENT_PROPERTY( TextUpdated , wxEVT_COMMAND_TEXT_UPDATED , wxCommandEvent ) | |
268 | ||
269 | wxPROPERTY_FLAGS( WindowStyle , wxListCtrlStyle , long , SetWindowStyleFlag , GetWindowStyleFlag , , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style | |
270 | wxEND_PROPERTIES_TABLE() | |
271 | ||
272 | wxBEGIN_HANDLERS_TABLE(wxListCtrl) | |
273 | wxEND_HANDLERS_TABLE() | |
274 | ||
275 | wxCONSTRUCTOR_5( wxListCtrl , wxWindow* , Parent , wxWindowID , Id , wxPoint , Position , wxSize , Size , long , WindowStyle ) | |
276 | ||
277 | /* | |
278 | Content-type: text/html ]>