]>
Commit | Line | Data |
---|---|---|
c801d85f | 1 | ///////////////////////////////////////////////////////////////////////////// |
54442116 VZ |
2 | // Name: generic/listctrl.cpp |
3 | // Purpose: generic implementation of wxListCtrl | |
c801d85f | 4 | // Author: Robert Roebling |
cf1dfa6b | 5 | // Vadim Zeitlin (virtual list control support) |
0208334d RR |
6 | // Id: $Id$ |
7 | // Copyright: (c) 1998 Robert Roebling | |
bd8289c1 | 8 | // Licence: wxWindows licence |
c801d85f KB |
9 | ///////////////////////////////////////////////////////////////////////////// |
10 | ||
b54e41c5 | 11 | /* |
70541533 | 12 | TODO |
b54e41c5 | 13 | |
70541533 | 14 | 1. we need to implement searching/sorting for virtual controls somehow |
0a816d95 | 15 | ?2. when changing selection the lines are refreshed twice |
b54e41c5 VZ |
16 | */ |
17 | ||
1370703e VZ |
18 | // ============================================================================ |
19 | // declarations | |
20 | // ============================================================================ | |
21 | ||
22 | // ---------------------------------------------------------------------------- | |
23 | // headers | |
24 | // ---------------------------------------------------------------------------- | |
25 | ||
c801d85f | 26 | #ifdef __GNUG__ |
510fc784 RR |
27 | #pragma implementation "listctrl.h" |
28 | #pragma implementation "listctrlbase.h" | |
1e4d446b | 29 | #endif |
5cd89174 | 30 | |
1e6d9499 JS |
31 | // For compilers that support precompilation, includes "wx.h". |
32 | #include "wx/wxprec.h" | |
33 | ||
34 | #ifdef __BORLANDC__ | |
35 | #pragma hdrstop | |
36 | #endif | |
37 | ||
1e6feb95 VZ |
38 | #if wxUSE_LISTCTRL |
39 | ||
33b7a549 VZ |
40 | #ifndef WX_PRECOMP |
41 | #include "wx/app.h" | |
42 | ||
43 | #include "wx/dynarray.h" | |
44 | ||
45 | #include "wx/dcscreen.h" | |
46 | ||
47 | #include "wx/textctrl.h" | |
48 | #endif | |
49 | ||
e81a301c JS |
50 | // Include wx/listctrl.h (with wxListView declaration) |
51 | // only when wxGenericListCtrl is the only | |
52 | // implementation, and therefore wxListView needs | |
53 | // to be derived from the 'generic' version. | |
54 | ||
55 | #if defined(__WIN32__) && !defined(__WXUNIVERSAL__) | |
56 | #include "wx/generic/listctrl.h" | |
f9ceab7c JS |
57 | |
58 | #define wxImageListType wxGenericImageList | |
e81a301c JS |
59 | #else |
60 | #include "wx/listctrl.h" | |
f9ceab7c JS |
61 | |
62 | #define wxImageListType wxImageList | |
e81a301c | 63 | #endif |
c801d85f | 64 | |
f16ba4e6 | 65 | #if defined(__WXGTK__) |
33b7a549 VZ |
66 | #include <gtk/gtk.h> |
67 | #include "wx/gtk/win_gtk.h" | |
3fb435df RR |
68 | #endif |
69 | ||
2e4df4bf VZ |
70 | // ---------------------------------------------------------------------------- |
71 | // events | |
72 | // ---------------------------------------------------------------------------- | |
73 | ||
74 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_DRAG) | |
75 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_RDRAG) | |
76 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT) | |
77 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_END_LABEL_EDIT) | |
78 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_DELETE_ITEM) | |
79 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS) | |
80 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_GET_INFO) | |
81 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_SET_INFO) | |
82 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_SELECTED) | |
83 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_DESELECTED) | |
84 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_KEY_DOWN) | |
85 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_INSERT_ITEM) | |
86 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_CLICK) | |
11358d39 VZ |
87 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_RIGHT_CLICK) |
88 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_BEGIN_DRAG) | |
89 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_DRAGGING) | |
90 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_END_DRAG) | |
2e4df4bf VZ |
91 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK) |
92 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK) | |
93 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_ACTIVATED) | |
0ddefeb0 | 94 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_FOCUSED) |
614391dc | 95 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_CACHE_HINT) |
2e4df4bf | 96 | |
cf1dfa6b VZ |
97 | // ---------------------------------------------------------------------------- |
98 | // constants | |
99 | // ---------------------------------------------------------------------------- | |
100 | ||
101 | // the height of the header window (FIXME: should depend on its font!) | |
102 | static const int HEADER_HEIGHT = 23; | |
103 | ||
104 | // the scrollbar units | |
105 | static const int SCROLL_UNIT_X = 15; | |
106 | static const int SCROLL_UNIT_Y = 15; | |
107 | ||
108 | // the spacing between the lines (in report mode) | |
b54e41c5 | 109 | static const int LINE_SPACING = 0; |
cf1dfa6b VZ |
110 | |
111 | // extra margins around the text label | |
112 | static const int EXTRA_WIDTH = 3; | |
113 | static const int EXTRA_HEIGHT = 4; | |
114 | ||
115 | // offset for the header window | |
116 | static const int HEADER_OFFSET_X = 1; | |
117 | static const int HEADER_OFFSET_Y = 1; | |
118 | ||
119 | // when autosizing the columns, add some slack | |
120 | static const int AUTOSIZE_COL_MARGIN = 10; | |
121 | ||
122 | // default and minimal widths for the header columns | |
123 | static const int WIDTH_COL_DEFAULT = 80; | |
124 | static const int WIDTH_COL_MIN = 10; | |
125 | ||
06b781c7 VZ |
126 | // the space between the image and the text in the report mode |
127 | static const int IMAGE_MARGIN_IN_REPORT_MODE = 5; | |
128 | ||
efbb7287 VZ |
129 | // ============================================================================ |
130 | // private classes | |
131 | // ============================================================================ | |
132 | ||
b54e41c5 VZ |
133 | // ---------------------------------------------------------------------------- |
134 | // wxSelectionStore | |
135 | // ---------------------------------------------------------------------------- | |
136 | ||
137 | int CMPFUNC_CONV wxSizeTCmpFn(size_t n1, size_t n2) { return n1 - n2; } | |
138 | ||
5a1cad6e | 139 | WX_DEFINE_SORTED_EXPORTED_ARRAY_LONG(size_t, wxIndexArray); |
b54e41c5 VZ |
140 | |
141 | // this class is used to store the selected items in the virtual list control | |
142 | // (but it is not tied to list control and so can be used with other controls | |
143 | // such as wxListBox in wxUniv) | |
144 | // | |
145 | // the idea is to make it really smart later (i.e. store the selections as an | |
146 | // array of ranes + individual items) but, as I don't have time to do it now | |
147 | // (this would require writing code to merge/break ranges and much more) keep | |
148 | // it simple but define a clean interface to it which allows it to be made | |
149 | // smarter later | |
150 | class WXDLLEXPORT wxSelectionStore | |
151 | { | |
152 | public: | |
153 | wxSelectionStore() : m_itemsSel(wxSizeTCmpFn) { Init(); } | |
154 | ||
155 | // set the total number of items we handle | |
156 | void SetItemCount(size_t count) { m_count = count; } | |
157 | ||
158 | // special case of SetItemCount(0) | |
cf4d0c5b | 159 | void Clear() { m_itemsSel.Clear(); m_count = 0; m_defaultState = FALSE; } |
b54e41c5 VZ |
160 | |
161 | // must be called when a new item is inserted/added | |
162 | void OnItemAdd(size_t item) { wxFAIL_MSG( _T("TODO") ); } | |
163 | ||
164 | // must be called when an item is deleted | |
165 | void OnItemDelete(size_t item); | |
166 | ||
167 | // select one item, use SelectRange() insted if possible! | |
168 | // | |
169 | // returns true if the items selection really changed | |
170 | bool SelectItem(size_t item, bool select = TRUE); | |
171 | ||
172 | // select the range of items | |
68a9ef0e VZ |
173 | // |
174 | // return true and fill the itemsChanged array with the indices of items | |
175 | // which have changed state if "few" of them did, otherwise return false | |
176 | // (meaning that too many items changed state to bother counting them | |
177 | // individually) | |
178 | bool SelectRange(size_t itemFrom, size_t itemTo, | |
179 | bool select = TRUE, | |
180 | wxArrayInt *itemsChanged = NULL); | |
b54e41c5 VZ |
181 | |
182 | // return true if the given item is selected | |
183 | bool IsSelected(size_t item) const; | |
184 | ||
185 | // return the total number of selected items | |
186 | size_t GetSelectedCount() const | |
187 | { | |
188 | return m_defaultState ? m_count - m_itemsSel.GetCount() | |
189 | : m_itemsSel.GetCount(); | |
190 | } | |
191 | ||
192 | private: | |
193 | // (re)init | |
194 | void Init() { m_defaultState = FALSE; } | |
195 | ||
196 | // the total number of items we handle | |
197 | size_t m_count; | |
198 | ||
199 | // the default state: normally, FALSE (i.e. off) but maybe set to TRUE if | |
200 | // there are more selected items than non selected ones - this allows to | |
201 | // handle selection of all items efficiently | |
202 | bool m_defaultState; | |
203 | ||
204 | // the array of items whose selection state is different from default | |
205 | wxIndexArray m_itemsSel; | |
206 | ||
207 | DECLARE_NO_COPY_CLASS(wxSelectionStore) | |
208 | }; | |
209 | ||
efbb7287 VZ |
210 | //----------------------------------------------------------------------------- |
211 | // wxListItemData (internal) | |
212 | //----------------------------------------------------------------------------- | |
213 | ||
cf1dfa6b | 214 | class WXDLLEXPORT wxListItemData |
efbb7287 | 215 | { |
efbb7287 | 216 | public: |
cf1dfa6b | 217 | wxListItemData(wxListMainWindow *owner); |
850ed6e7 | 218 | ~wxListItemData(); |
efbb7287 | 219 | |
efbb7287 | 220 | void SetItem( const wxListItem &info ); |
cf1dfa6b VZ |
221 | void SetImage( int image ) { m_image = image; } |
222 | void SetData( long data ) { m_data = data; } | |
efbb7287 VZ |
223 | void SetPosition( int x, int y ); |
224 | void SetSize( int width, int height ); | |
54442116 VZ |
225 | |
226 | bool HasText() const { return !m_text.empty(); } | |
227 | const wxString& GetText() const { return m_text; } | |
228 | void SetText(const wxString& text) { m_text = text; } | |
229 | ||
cf1dfa6b VZ |
230 | // we can't use empty string for measuring the string width/height, so |
231 | // always return something | |
232 | wxString GetTextForMeasuring() const | |
233 | { | |
234 | wxString s = GetText(); | |
235 | if ( s.empty() ) | |
236 | s = _T('H'); | |
237 | ||
238 | return s; | |
239 | } | |
240 | ||
efbb7287 | 241 | bool IsHit( int x, int y ) const; |
54442116 | 242 | |
cf1dfa6b VZ |
243 | int GetX() const; |
244 | int GetY() const; | |
efbb7287 VZ |
245 | int GetWidth() const; |
246 | int GetHeight() const; | |
cf1dfa6b VZ |
247 | |
248 | int GetImage() const { return m_image; } | |
249 | bool HasImage() const { return GetImage() != -1; } | |
250 | ||
efbb7287 VZ |
251 | void GetItem( wxListItem &info ) const; |
252 | ||
6c02c329 VZ |
253 | void SetAttr(wxListItemAttr *attr) { m_attr = attr; } |
254 | wxListItemAttr *GetAttr() const { return m_attr; } | |
efbb7287 | 255 | |
54442116 | 256 | public: |
cf1dfa6b VZ |
257 | // the item image or -1 |
258 | int m_image; | |
259 | ||
260 | // user data associated with the item | |
261 | long m_data; | |
54442116 | 262 | |
cf1dfa6b VZ |
263 | // the item coordinates are not used in report mode, instead this pointer |
264 | // is NULL and the owner window is used to retrieve the item position and | |
265 | // size | |
266 | wxRect *m_rect; | |
267 | ||
268 | // the list ctrl we are in | |
269 | wxListMainWindow *m_owner; | |
270 | ||
271 | // custom attributes or NULL | |
54442116 VZ |
272 | wxListItemAttr *m_attr; |
273 | ||
274 | protected: | |
cf1dfa6b VZ |
275 | // common part of all ctors |
276 | void Init(); | |
54442116 | 277 | |
cf1dfa6b | 278 | wxString m_text; |
efbb7287 VZ |
279 | }; |
280 | ||
281 | //----------------------------------------------------------------------------- | |
282 | // wxListHeaderData (internal) | |
283 | //----------------------------------------------------------------------------- | |
284 | ||
285 | class WXDLLEXPORT wxListHeaderData : public wxObject | |
286 | { | |
efbb7287 VZ |
287 | public: |
288 | wxListHeaderData(); | |
289 | wxListHeaderData( const wxListItem &info ); | |
290 | void SetItem( const wxListItem &item ); | |
291 | void SetPosition( int x, int y ); | |
292 | void SetWidth( int w ); | |
293 | void SetFormat( int format ); | |
294 | void SetHeight( int h ); | |
295 | bool HasImage() const; | |
54442116 VZ |
296 | |
297 | bool HasText() const { return !m_text.empty(); } | |
298 | const wxString& GetText() const { return m_text; } | |
299 | void SetText(const wxString& text) { m_text = text; } | |
300 | ||
efbb7287 | 301 | void GetItem( wxListItem &item ); |
54442116 VZ |
302 | |
303 | bool IsHit( int x, int y ) const; | |
efbb7287 VZ |
304 | int GetImage() const; |
305 | int GetWidth() const; | |
306 | int GetFormat() const; | |
f6bcfd97 | 307 | |
0a816d95 VZ |
308 | protected: |
309 | long m_mask; | |
310 | int m_image; | |
311 | wxString m_text; | |
312 | int m_format; | |
313 | int m_width; | |
314 | int m_xpos, | |
315 | m_ypos; | |
316 | int m_height; | |
317 | ||
efbb7287 | 318 | private: |
0a816d95 | 319 | void Init(); |
efbb7287 VZ |
320 | }; |
321 | ||
322 | //----------------------------------------------------------------------------- | |
323 | // wxListLineData (internal) | |
324 | //----------------------------------------------------------------------------- | |
325 | ||
2c1f73ee VZ |
326 | WX_DECLARE_LIST(wxListItemData, wxListItemDataList); |
327 | #include "wx/listimpl.cpp" | |
328 | WX_DEFINE_LIST(wxListItemDataList); | |
329 | ||
cf1dfa6b | 330 | class WXDLLEXPORT wxListLineData |
efbb7287 VZ |
331 | { |
332 | public: | |
cf1dfa6b VZ |
333 | // the list of subitems: only may have more than one item in report mode |
334 | wxListItemDataList m_items; | |
335 | ||
336 | // this is not used in report view | |
337 | struct GeometryInfo | |
338 | { | |
339 | // total item rect | |
340 | wxRect m_rectAll; | |
341 | ||
342 | // label only | |
343 | wxRect m_rectLabel; | |
344 | ||
345 | // icon only | |
346 | wxRect m_rectIcon; | |
347 | ||
348 | // the part to be highlighted | |
b54e41c5 | 349 | wxRect m_rectHighlight; |
cf1dfa6b | 350 | } *m_gi; |
efbb7287 | 351 | |
cf1dfa6b | 352 | // is this item selected? [NB: not used in virtual mode] |
b54e41c5 | 353 | bool m_highlighted; |
cf1dfa6b VZ |
354 | |
355 | // back pointer to the list ctrl | |
356 | wxListMainWindow *m_owner; | |
efbb7287 VZ |
357 | |
358 | public: | |
5cd89174 | 359 | wxListLineData(wxListMainWindow *owner); |
cf1dfa6b VZ |
360 | |
361 | ~wxListLineData() { delete m_gi; } | |
362 | ||
363 | // are we in report mode? | |
364 | inline bool InReportView() const; | |
365 | ||
366 | // are we in virtual report mode? | |
b54e41c5 | 367 | inline bool IsVirtual() const; |
cf1dfa6b VZ |
368 | |
369 | // these 2 methods shouldn't be called for report view controls, in that | |
370 | // case we determine our position/size ourselves | |
371 | ||
372 | // calculate the size of the line | |
efbb7287 | 373 | void CalculateSize( wxDC *dc, int spacing ); |
cf1dfa6b VZ |
374 | |
375 | // remember the position this line appears at | |
376 | void SetPosition( int x, int y, int window_width, int spacing ); | |
377 | ||
5cd89174 VZ |
378 | // wxListCtrl API |
379 | ||
380 | void SetImage( int image ) { SetImage(0, image); } | |
381 | int GetImage() const { return GetImage(0); } | |
382 | bool HasImage() const { return GetImage() != -1; } | |
383 | bool HasText() const { return !GetText(0).empty(); } | |
cf1dfa6b | 384 | |
efbb7287 VZ |
385 | void SetItem( int index, const wxListItem &info ); |
386 | void GetItem( int index, wxListItem &info ); | |
cf1dfa6b | 387 | |
54442116 | 388 | wxString GetText(int index) const; |
efbb7287 | 389 | void SetText( int index, const wxString s ); |
cf1dfa6b | 390 | |
6c02c329 VZ |
391 | wxListItemAttr *GetAttr() const; |
392 | void SetAttr(wxListItemAttr *attr); | |
393 | ||
cf1dfa6b | 394 | // return true if the highlighting really changed |
b54e41c5 | 395 | bool Highlight( bool on ); |
cf1dfa6b | 396 | |
b54e41c5 | 397 | void ReverseHighlight(); |
cf1dfa6b | 398 | |
b54e41c5 | 399 | bool IsHighlighted() const |
cf1dfa6b | 400 | { |
b54e41c5 | 401 | wxASSERT_MSG( !IsVirtual(), _T("unexpected call to IsHighlighted") ); |
cf1dfa6b | 402 | |
b54e41c5 | 403 | return m_highlighted; |
cf1dfa6b VZ |
404 | } |
405 | ||
5cd89174 VZ |
406 | // draw the line on the given DC in icon/list mode |
407 | void Draw( wxDC *dc ); | |
408 | ||
409 | // the same in report mode | |
410 | void DrawInReportMode( wxDC *dc, | |
411 | const wxRect& rect, | |
412 | const wxRect& rectHL, | |
413 | bool highlighted ); | |
f6bcfd97 | 414 | |
efbb7287 | 415 | private: |
cf1dfa6b VZ |
416 | // set the line to contain num items (only can be > 1 in report mode) |
417 | void InitItems( int num ); | |
418 | ||
419 | // get the mode (i.e. style) of the list control | |
420 | inline int GetMode() const; | |
421 | ||
0e980f91 VZ |
422 | // prepare the DC for drawing with these item's attributes, return true if |
423 | // we need to draw the items background to highlight it, false otherwise | |
424 | bool SetAttributes(wxDC *dc, | |
efbb7287 | 425 | const wxListItemAttr *attr, |
b54e41c5 | 426 | bool highlight); |
efbb7287 | 427 | |
5cd89174 VZ |
428 | // these are only used by GetImage/SetImage above, we don't support images |
429 | // with subitems at the public API level yet | |
430 | void SetImage( int index, int image ); | |
431 | int GetImage( int index ) const; | |
efbb7287 VZ |
432 | }; |
433 | ||
f6bcfd97 BP |
434 | WX_DECLARE_EXPORTED_OBJARRAY(wxListLineData, wxListLineDataArray); |
435 | #include "wx/arrimpl.cpp" | |
436 | WX_DEFINE_OBJARRAY(wxListLineDataArray); | |
437 | ||
efbb7287 VZ |
438 | //----------------------------------------------------------------------------- |
439 | // wxListHeaderWindow (internal) | |
440 | //----------------------------------------------------------------------------- | |
441 | ||
442 | class WXDLLEXPORT wxListHeaderWindow : public wxWindow | |
443 | { | |
444 | protected: | |
445 | wxListMainWindow *m_owner; | |
446 | wxCursor *m_currentCursor; | |
447 | wxCursor *m_resizeCursor; | |
448 | bool m_isDragging; | |
f6bcfd97 | 449 | |
62313c27 | 450 | // column being resized or -1 |
f6bcfd97 BP |
451 | int m_column; |
452 | ||
453 | // divider line position in logical (unscrolled) coords | |
454 | int m_currentX; | |
455 | ||
456 | // minimal position beyond which the divider line can't be dragged in | |
457 | // logical coords | |
458 | int m_minX; | |
efbb7287 VZ |
459 | |
460 | public: | |
461 | wxListHeaderWindow(); | |
f6bcfd97 BP |
462 | |
463 | wxListHeaderWindow( wxWindow *win, | |
464 | wxWindowID id, | |
465 | wxListMainWindow *owner, | |
466 | const wxPoint &pos = wxDefaultPosition, | |
467 | const wxSize &size = wxDefaultSize, | |
468 | long style = 0, | |
469 | const wxString &name = "wxlistctrlcolumntitles" ); | |
470 | ||
0a816d95 VZ |
471 | virtual ~wxListHeaderWindow(); |
472 | ||
efbb7287 | 473 | void DoDrawRect( wxDC *dc, int x, int y, int w, int h ); |
efbb7287 | 474 | void DrawCurrent(); |
f6bcfd97 BP |
475 | void AdjustDC(wxDC& dc); |
476 | ||
477 | void OnPaint( wxPaintEvent &event ); | |
efbb7287 VZ |
478 | void OnMouse( wxMouseEvent &event ); |
479 | void OnSetFocus( wxFocusEvent &event ); | |
480 | ||
f6bcfd97 BP |
481 | // needs refresh |
482 | bool m_dirty; | |
483 | ||
efbb7287 | 484 | private: |
0a816d95 VZ |
485 | // common part of all ctors |
486 | void Init(); | |
487 | ||
a77ec46d RD |
488 | void SendListEvent(wxEventType type, wxPoint pos); |
489 | ||
efbb7287 VZ |
490 | DECLARE_DYNAMIC_CLASS(wxListHeaderWindow) |
491 | DECLARE_EVENT_TABLE() | |
492 | }; | |
493 | ||
494 | //----------------------------------------------------------------------------- | |
495 | // wxListRenameTimer (internal) | |
496 | //----------------------------------------------------------------------------- | |
497 | ||
498 | class WXDLLEXPORT wxListRenameTimer: public wxTimer | |
499 | { | |
500 | private: | |
1370703e | 501 | wxListMainWindow *m_owner; |
efbb7287 VZ |
502 | |
503 | public: | |
504 | wxListRenameTimer( wxListMainWindow *owner ); | |
505 | void Notify(); | |
506 | }; | |
507 | ||
508 | //----------------------------------------------------------------------------- | |
509 | // wxListTextCtrl (internal) | |
510 | //----------------------------------------------------------------------------- | |
511 | ||
512 | class WXDLLEXPORT wxListTextCtrl: public wxTextCtrl | |
513 | { | |
efbb7287 | 514 | public: |
62d89eb4 VZ |
515 | wxListTextCtrl(wxListMainWindow *owner, size_t itemEdit); |
516 | ||
517 | protected: | |
efbb7287 | 518 | void OnChar( wxKeyEvent &event ); |
c13cace1 | 519 | void OnKeyUp( wxKeyEvent &event ); |
efbb7287 VZ |
520 | void OnKillFocus( wxFocusEvent &event ); |
521 | ||
62d89eb4 VZ |
522 | bool AcceptChanges(); |
523 | void Finish(); | |
524 | ||
efbb7287 | 525 | private: |
62d89eb4 VZ |
526 | wxListMainWindow *m_owner; |
527 | wxString m_startValue; | |
528 | size_t m_itemEdited; | |
529 | bool m_finished; | |
530 | ||
efbb7287 VZ |
531 | DECLARE_EVENT_TABLE() |
532 | }; | |
533 | ||
534 | //----------------------------------------------------------------------------- | |
535 | // wxListMainWindow (internal) | |
536 | //----------------------------------------------------------------------------- | |
537 | ||
24b9f055 VZ |
538 | WX_DECLARE_LIST(wxListHeaderData, wxListHeaderDataList); |
539 | #include "wx/listimpl.cpp" | |
540 | WX_DEFINE_LIST(wxListHeaderDataList); | |
541 | ||
cf1dfa6b | 542 | class WXDLLEXPORT wxListMainWindow : public wxScrolledWindow |
efbb7287 | 543 | { |
efbb7287 VZ |
544 | public: |
545 | wxListMainWindow(); | |
1370703e VZ |
546 | wxListMainWindow( wxWindow *parent, |
547 | wxWindowID id, | |
548 | const wxPoint& pos = wxDefaultPosition, | |
549 | const wxSize& size = wxDefaultSize, | |
550 | long style = 0, | |
551 | const wxString &name = _T("listctrlmainwindow") ); | |
552 | ||
553 | virtual ~wxListMainWindow(); | |
554 | ||
cf1dfa6b VZ |
555 | bool HasFlag(int flag) const { return m_parent->HasFlag(flag); } |
556 | ||
1370703e | 557 | // return true if this is a virtual list control |
cf1dfa6b VZ |
558 | bool IsVirtual() const { return HasFlag(wxLC_VIRTUAL); } |
559 | ||
5cd89174 VZ |
560 | // return true if the control is in report mode |
561 | bool InReportView() const { return HasFlag(wxLC_REPORT); } | |
562 | ||
b54e41c5 VZ |
563 | // return true if we are in single selection mode, false if multi sel |
564 | bool IsSingleSel() const { return HasFlag(wxLC_SINGLE_SEL); } | |
565 | ||
cf1dfa6b VZ |
566 | // do we have a header window? |
567 | bool HasHeader() const | |
568 | { return HasFlag(wxLC_REPORT) && !HasFlag(wxLC_NO_HEADER); } | |
1370703e | 569 | |
b54e41c5 | 570 | void HighlightAll( bool on ); |
cf1dfa6b VZ |
571 | |
572 | // all these functions only do something if the line is currently visible | |
573 | ||
574 | // change the line "selected" state, return TRUE if it really changed | |
b54e41c5 VZ |
575 | bool HighlightLine( size_t line, bool highlight = TRUE); |
576 | ||
577 | // as HighlightLine() but do it for the range of lines: this is incredibly | |
578 | // more efficient for virtual list controls! | |
579 | // | |
580 | // NB: unlike HighlightLine() this one does refresh the lines on screen | |
581 | void HighlightLines( size_t lineFrom, size_t lineTo, bool on = TRUE ); | |
cf1dfa6b VZ |
582 | |
583 | // toggle the line state and refresh it | |
b54e41c5 VZ |
584 | void ReverseHighlight( size_t line ) |
585 | { HighlightLine(line, !IsHighlighted(line)); RefreshLine(line); } | |
cf1dfa6b | 586 | |
6b4a8d93 VZ |
587 | // return true if the line is highlighted |
588 | bool IsHighlighted(size_t line) const; | |
589 | ||
cf1dfa6b VZ |
590 | // refresh one or several lines at once |
591 | void RefreshLine( size_t line ); | |
592 | void RefreshLines( size_t lineFrom, size_t lineTo ); | |
593 | ||
49ecb029 VZ |
594 | // refresh all selected items |
595 | void RefreshSelected(); | |
596 | ||
6b4a8d93 VZ |
597 | // refresh all lines below the given one: the difference with |
598 | // RefreshLines() is that the index here might not be a valid one (happens | |
599 | // when the last line is deleted) | |
600 | void RefreshAfter( size_t lineFrom ); | |
efbb7287 | 601 | |
5cd89174 VZ |
602 | // the methods which are forwarded to wxListLineData itself in list/icon |
603 | // modes but are here because the lines don't store their positions in the | |
604 | // report mode | |
605 | ||
606 | // get the bound rect for the entire line | |
607 | wxRect GetLineRect(size_t line) const; | |
608 | ||
609 | // get the bound rect of the label | |
610 | wxRect GetLineLabelRect(size_t line) const; | |
611 | ||
612 | // get the bound rect of the items icon (only may be called if we do have | |
613 | // an icon!) | |
614 | wxRect GetLineIconRect(size_t line) const; | |
615 | ||
616 | // get the rect to be highlighted when the item has focus | |
617 | wxRect GetLineHighlightRect(size_t line) const; | |
618 | ||
619 | // get the size of the total line rect | |
620 | wxSize GetLineSize(size_t line) const | |
621 | { return GetLineRect(line).GetSize(); } | |
622 | ||
623 | // return the hit code for the corresponding position (in this line) | |
624 | long HitTestLine(size_t line, int x, int y) const; | |
625 | ||
34bbbc27 VZ |
626 | // bring the selected item into view, scrolling to it if necessary |
627 | void MoveToItem(size_t item); | |
628 | ||
629 | // bring the current item into view | |
630 | void MoveToFocus() { MoveToItem(m_current); } | |
631 | ||
c5c528fc | 632 | // start editing the label of the given item |
efbb7287 | 633 | void EditLabel( long item ); |
c5c528fc VZ |
634 | |
635 | // suspend/resume redrawing the control | |
636 | void Freeze(); | |
637 | void Thaw(); | |
a77ec46d | 638 | |
a6d57d03 | 639 | void SetFocus(); |
c5c528fc | 640 | |
efbb7287 | 641 | void OnRenameTimer(); |
62d89eb4 | 642 | bool OnRenameAccept(size_t itemEdit, const wxString& value); |
efbb7287 VZ |
643 | |
644 | void OnMouse( wxMouseEvent &event ); | |
cf1dfa6b VZ |
645 | |
646 | // called to switch the selection from the current item to newCurrent, | |
647 | void OnArrowChar( size_t newCurrent, const wxKeyEvent& event ); | |
648 | ||
efbb7287 VZ |
649 | void OnChar( wxKeyEvent &event ); |
650 | void OnKeyDown( wxKeyEvent &event ); | |
651 | void OnSetFocus( wxFocusEvent &event ); | |
652 | void OnKillFocus( wxFocusEvent &event ); | |
efbb7287 | 653 | void OnScroll(wxScrollWinEvent& event) ; |
f6bcfd97 | 654 | |
cf1dfa6b VZ |
655 | void OnPaint( wxPaintEvent &event ); |
656 | ||
efbb7287 | 657 | void DrawImage( int index, wxDC *dc, int x, int y ); |
5cd89174 VZ |
658 | void GetImageSize( int index, int &width, int &height ) const; |
659 | int GetTextLength( const wxString &s ) const; | |
efbb7287 | 660 | |
9cb07953 | 661 | void SetImageList( wxGenericImageList *imageList, int which ); |
efbb7287 VZ |
662 | void SetItemSpacing( int spacing, bool isSmall = FALSE ); |
663 | int GetItemSpacing( bool isSmall = FALSE ); | |
cf1dfa6b | 664 | |
efbb7287 VZ |
665 | void SetColumn( int col, wxListItem &item ); |
666 | void SetColumnWidth( int col, int width ); | |
cf1dfa6b VZ |
667 | void GetColumn( int col, wxListItem &item ) const; |
668 | int GetColumnWidth( int col ) const; | |
669 | int GetColumnCount() const { return m_columns.GetCount(); } | |
670 | ||
671 | // returns the sum of the heights of all columns | |
672 | int GetHeaderWidth() const; | |
673 | ||
5cd89174 | 674 | int GetCountPerPage() const; |
cf1dfa6b | 675 | |
efbb7287 | 676 | void SetItem( wxListItem &item ); |
62d89eb4 | 677 | void GetItem( wxListItem &item ) const; |
efbb7287 | 678 | void SetItemState( long item, long state, long stateMask ); |
62d89eb4 VZ |
679 | int GetItemState( long item, long stateMask ) const; |
680 | void GetItemRect( long index, wxRect &rect ) const; | |
681 | bool GetItemPosition( long item, wxPoint& pos ) const; | |
682 | int GetSelectedItemCount() const; | |
683 | ||
684 | wxString GetItemText(long item) const | |
685 | { | |
686 | wxListItem info; | |
687 | info.m_itemId = item; | |
688 | GetItem( info ); | |
689 | return info.m_text; | |
690 | } | |
691 | ||
692 | void SetItemText(long item, const wxString& value) | |
693 | { | |
694 | wxListItem info; | |
695 | info.m_mask = wxLIST_MASK_TEXT; | |
696 | info.m_itemId = item; | |
697 | info.m_text = value; | |
698 | SetItem( info ); | |
699 | } | |
cf1dfa6b VZ |
700 | |
701 | // set the scrollbars and update the positions of the items | |
34bbbc27 | 702 | void RecalculatePositions(bool noRefresh = FALSE); |
b54e41c5 VZ |
703 | |
704 | // refresh the window and the header | |
705 | void RefreshAll(); | |
cf1dfa6b | 706 | |
62d89eb4 | 707 | long GetNextItem( long item, int geometry, int state ) const; |
efbb7287 VZ |
708 | void DeleteItem( long index ); |
709 | void DeleteAllItems(); | |
710 | void DeleteColumn( int col ); | |
711 | void DeleteEverything(); | |
712 | void EnsureVisible( long index ); | |
713 | long FindItem( long start, const wxString& str, bool partial = FALSE ); | |
714 | long FindItem( long start, long data); | |
715 | long HitTest( int x, int y, int &flags ); | |
716 | void InsertItem( wxListItem &item ); | |
efbb7287 | 717 | void InsertColumn( long col, wxListItem &item ); |
efbb7287 VZ |
718 | void SortItems( wxListCtrlCompare fn, long data ); |
719 | ||
cf1dfa6b | 720 | size_t GetItemCount() const; |
1370703e | 721 | bool IsEmpty() const { return GetItemCount() == 0; } |
2c1f73ee VZ |
722 | void SetItemCount(long count); |
723 | ||
0ddefeb0 VZ |
724 | // change the current (== focused) item, send a notification event |
725 | void ChangeCurrent(size_t current); | |
726 | void ResetCurrent() { ChangeCurrent((size_t)-1); } | |
cf1dfa6b VZ |
727 | bool HasCurrent() const { return m_current != (size_t)-1; } |
728 | ||
729 | // send out a wxListEvent | |
730 | void SendNotify( size_t line, | |
731 | wxEventType command, | |
732 | wxPoint point = wxDefaultPosition ); | |
733 | ||
b54e41c5 VZ |
734 | // override base class virtual to reset m_lineHeight when the font changes |
735 | virtual bool SetFont(const wxFont& font) | |
736 | { | |
737 | if ( !wxScrolledWindow::SetFont(font) ) | |
738 | return FALSE; | |
739 | ||
740 | m_lineHeight = 0; | |
741 | ||
742 | return TRUE; | |
743 | } | |
cf1dfa6b VZ |
744 | |
745 | // these are for wxListLineData usage only | |
746 | ||
747 | // get the backpointer to the list ctrl | |
3cd94a0d | 748 | wxGenericListCtrl *GetListCtrl() const |
cf1dfa6b | 749 | { |
3cd94a0d | 750 | return wxStaticCast(GetParent(), wxGenericListCtrl); |
cf1dfa6b VZ |
751 | } |
752 | ||
753 | // get the height of all lines (assuming they all do have the same height) | |
754 | wxCoord GetLineHeight() const; | |
755 | ||
756 | // get the y position of the given line (only for report view) | |
757 | wxCoord GetLineY(size_t line) const; | |
758 | ||
49ecb029 VZ |
759 | // get the brush to use for the item highlighting |
760 | wxBrush *GetHighlightBrush() const | |
761 | { | |
762 | return m_hasFocus ? m_highlightBrush : m_highlightUnfocusedBrush; | |
763 | } | |
764 | ||
cf1dfa6b | 765 | //protected: |
904ccf52 VZ |
766 | // the array of all line objects for a non virtual list control (for the |
767 | // virtual list control we only ever use m_lines[0]) | |
cf1dfa6b VZ |
768 | wxListLineDataArray m_lines; |
769 | ||
770 | // the list of column objects | |
771 | wxListHeaderDataList m_columns; | |
772 | ||
773 | // currently focused item or -1 | |
774 | size_t m_current; | |
775 | ||
cf1dfa6b VZ |
776 | // the number of lines per page |
777 | int m_linesPerPage; | |
778 | ||
779 | // this flag is set when something which should result in the window | |
780 | // redrawing happens (i.e. an item was added or deleted, or its appearance | |
781 | // changed) and OnPaint() doesn't redraw the window while it is set which | |
782 | // allows to minimize the number of repaintings when a lot of items are | |
783 | // being added. The real repainting occurs only after the next OnIdle() | |
784 | // call | |
785 | bool m_dirty; | |
786 | ||
b54e41c5 | 787 | wxColour *m_highlightColour; |
cf1dfa6b VZ |
788 | int m_xScroll, |
789 | m_yScroll; | |
9cb07953 JS |
790 | wxGenericImageList *m_small_image_list; |
791 | wxGenericImageList *m_normal_image_list; | |
cf1dfa6b VZ |
792 | int m_small_spacing; |
793 | int m_normal_spacing; | |
794 | bool m_hasFocus; | |
795 | ||
796 | bool m_lastOnSame; | |
797 | wxTimer *m_renameTimer; | |
cf1dfa6b VZ |
798 | bool m_isCreated; |
799 | int m_dragCount; | |
800 | wxPoint m_dragStart; | |
801 | ||
802 | // for double click logic | |
803 | size_t m_lineLastClicked, | |
804 | m_lineBeforeLastClicked; | |
805 | ||
1370703e | 806 | protected: |
cf1dfa6b | 807 | // the total count of items in a virtual list control |
b54e41c5 | 808 | size_t m_countVirt; |
cf1dfa6b | 809 | |
b54e41c5 VZ |
810 | // the object maintaining the items selection state, only used in virtual |
811 | // controls | |
812 | wxSelectionStore m_selStore; | |
cf1dfa6b | 813 | |
1370703e VZ |
814 | // common part of all ctors |
815 | void Init(); | |
816 | ||
cf1dfa6b VZ |
817 | // intiialize m_[xy]Scroll |
818 | void InitScrolling(); | |
819 | ||
1370703e VZ |
820 | // get the line data for the given index |
821 | wxListLineData *GetLine(size_t n) const | |
822 | { | |
823 | wxASSERT_MSG( n != (size_t)-1, _T("invalid line index") ); | |
824 | ||
cf1dfa6b VZ |
825 | if ( IsVirtual() ) |
826 | { | |
827 | wxConstCast(this, wxListMainWindow)->CacheLineData(n); | |
828 | ||
829 | n = 0; | |
830 | } | |
831 | ||
1370703e VZ |
832 | return &m_lines[n]; |
833 | } | |
834 | ||
b54e41c5 VZ |
835 | // get a dummy line which can be used for geometry calculations and such: |
836 | // you must use GetLine() if you want to really draw the line | |
837 | wxListLineData *GetDummyLine() const; | |
cf1dfa6b VZ |
838 | |
839 | // cache the line data of the n-th line in m_lines[0] | |
840 | void CacheLineData(size_t line); | |
841 | ||
b54e41c5 VZ |
842 | // get the range of visible lines |
843 | void GetVisibleLinesRange(size_t *from, size_t *to); | |
844 | ||
845 | // force us to recalculate the range of visible lines | |
846 | void ResetVisibleLinesRange() { m_lineFrom = (size_t)-1; } | |
847 | ||
848 | // get the colour to be used for drawing the rules | |
849 | wxColour GetRuleColour() const | |
850 | { | |
851 | #ifdef __WXMAC__ | |
852 | return *wxWHITE; | |
853 | #else | |
a756f210 | 854 | return wxSystemSettings::GetColour(wxSYS_COLOUR_3DLIGHT); |
b54e41c5 VZ |
855 | #endif |
856 | } | |
cf1dfa6b | 857 | |
efbb7287 | 858 | private: |
cf1dfa6b VZ |
859 | // initialize the current item if needed |
860 | void UpdateCurrent(); | |
861 | ||
5fe143df VZ |
862 | // delete all items but don't refresh: called from dtor |
863 | void DoDeleteAllItems(); | |
864 | ||
cf1dfa6b VZ |
865 | // the height of one line using the current font |
866 | wxCoord m_lineHeight; | |
867 | ||
868 | // the total header width or 0 if not calculated yet | |
869 | wxCoord m_headerWidth; | |
870 | ||
b54e41c5 VZ |
871 | // the first and last lines being shown on screen right now (inclusive), |
872 | // both may be -1 if they must be calculated so never access them directly: | |
873 | // use GetVisibleLinesRange() above instead | |
874 | size_t m_lineFrom, | |
875 | m_lineTo; | |
876 | ||
49ecb029 VZ |
877 | // the brushes to use for item highlighting when we do/don't have focus |
878 | wxBrush *m_highlightBrush, | |
879 | *m_highlightUnfocusedBrush; | |
880 | ||
c5c528fc VZ |
881 | // if this is > 0, the control is frozen and doesn't redraw itself |
882 | size_t m_freezeCount; | |
883 | ||
5a1cad6e | 884 | DECLARE_DYNAMIC_CLASS(wxListMainWindow) |
efbb7287 VZ |
885 | DECLARE_EVENT_TABLE() |
886 | }; | |
887 | ||
888 | // ============================================================================ | |
889 | // implementation | |
890 | // ============================================================================ | |
891 | ||
b54e41c5 VZ |
892 | // ---------------------------------------------------------------------------- |
893 | // wxSelectionStore | |
894 | // ---------------------------------------------------------------------------- | |
895 | ||
896 | bool wxSelectionStore::IsSelected(size_t item) const | |
897 | { | |
898 | bool isSel = m_itemsSel.Index(item) != wxNOT_FOUND; | |
899 | ||
900 | // if the default state is to be selected, being in m_itemsSel means that | |
901 | // the item is not selected, so we have to inverse the logic | |
902 | return m_defaultState ? !isSel : isSel; | |
903 | } | |
904 | ||
905 | bool wxSelectionStore::SelectItem(size_t item, bool select) | |
906 | { | |
907 | // search for the item ourselves as like this we get the index where to | |
908 | // insert it later if needed, so we do only one search in the array instead | |
909 | // of two (adding item to a sorted array requires a search) | |
910 | size_t index = m_itemsSel.IndexForInsert(item); | |
911 | bool isSel = index < m_itemsSel.GetCount() && m_itemsSel[index] == item; | |
912 | ||
913 | if ( select != m_defaultState ) | |
914 | { | |
915 | if ( !isSel ) | |
916 | { | |
917 | m_itemsSel.AddAt(item, index); | |
918 | ||
919 | return TRUE; | |
920 | } | |
921 | } | |
922 | else // reset to default state | |
923 | { | |
924 | if ( isSel ) | |
925 | { | |
926 | m_itemsSel.RemoveAt(index); | |
927 | return TRUE; | |
928 | } | |
929 | } | |
930 | ||
931 | return FALSE; | |
932 | } | |
933 | ||
68a9ef0e VZ |
934 | bool wxSelectionStore::SelectRange(size_t itemFrom, size_t itemTo, |
935 | bool select, | |
936 | wxArrayInt *itemsChanged) | |
b54e41c5 | 937 | { |
68a9ef0e VZ |
938 | // 100 is hardcoded but it shouldn't matter much: the important thing is |
939 | // that we don't refresh everything when really few (e.g. 1 or 2) items | |
940 | // change state | |
941 | static const size_t MANY_ITEMS = 100; | |
942 | ||
b54e41c5 VZ |
943 | wxASSERT_MSG( itemFrom <= itemTo, _T("should be in order") ); |
944 | ||
945 | // are we going to have more [un]selected items than the other ones? | |
68a9ef0e | 946 | if ( itemTo - itemFrom > m_count/2 ) |
b54e41c5 VZ |
947 | { |
948 | if ( select != m_defaultState ) | |
949 | { | |
950 | // the default state now becomes the same as 'select' | |
951 | m_defaultState = select; | |
952 | ||
953 | // so all the old selections (which had state select) shouldn't be | |
954 | // selected any more, but all the other ones should | |
955 | wxIndexArray selOld = m_itemsSel; | |
956 | m_itemsSel.Empty(); | |
957 | ||
958 | // TODO: it should be possible to optimize the searches a bit | |
959 | // knowing the possible range | |
960 | ||
961 | size_t item; | |
962 | for ( item = 0; item < itemFrom; item++ ) | |
963 | { | |
964 | if ( selOld.Index(item) == wxNOT_FOUND ) | |
965 | m_itemsSel.Add(item); | |
966 | } | |
967 | ||
968 | for ( item = itemTo + 1; item < m_count; item++ ) | |
969 | { | |
970 | if ( selOld.Index(item) == wxNOT_FOUND ) | |
971 | m_itemsSel.Add(item); | |
972 | } | |
68a9ef0e VZ |
973 | |
974 | // many items (> half) changed state | |
975 | itemsChanged = NULL; | |
b54e41c5 VZ |
976 | } |
977 | else // select == m_defaultState | |
978 | { | |
979 | // get the inclusive range of items between itemFrom and itemTo | |
980 | size_t count = m_itemsSel.GetCount(), | |
981 | start = m_itemsSel.IndexForInsert(itemFrom), | |
982 | end = m_itemsSel.IndexForInsert(itemTo); | |
983 | ||
984 | if ( start == count || m_itemsSel[start] < itemFrom ) | |
985 | { | |
986 | start++; | |
987 | } | |
988 | ||
989 | if ( end == count || m_itemsSel[end] > itemTo ) | |
990 | { | |
991 | end--; | |
992 | } | |
993 | ||
994 | if ( start <= end ) | |
995 | { | |
996 | // delete all of them (from end to avoid changing indices) | |
997 | for ( int i = end; i >= (int)start; i-- ) | |
998 | { | |
68a9ef0e VZ |
999 | if ( itemsChanged ) |
1000 | { | |
1001 | if ( itemsChanged->GetCount() > MANY_ITEMS ) | |
1002 | { | |
1003 | // stop counting (see comment below) | |
1004 | itemsChanged = NULL; | |
1005 | } | |
ae0d8c14 VZ |
1006 | else |
1007 | { | |
1008 | itemsChanged->Add(m_itemsSel[i]); | |
1009 | } | |
68a9ef0e VZ |
1010 | } |
1011 | ||
b54e41c5 VZ |
1012 | m_itemsSel.RemoveAt(i); |
1013 | } | |
1014 | } | |
1015 | } | |
1016 | } | |
1017 | else // "few" items change state | |
1018 | { | |
68a9ef0e VZ |
1019 | if ( itemsChanged ) |
1020 | { | |
1021 | itemsChanged->Empty(); | |
1022 | } | |
1023 | ||
b54e41c5 VZ |
1024 | // just add the items to the selection |
1025 | for ( size_t item = itemFrom; item <= itemTo; item++ ) | |
1026 | { | |
68a9ef0e VZ |
1027 | if ( SelectItem(item, select) && itemsChanged ) |
1028 | { | |
1029 | itemsChanged->Add(item); | |
1030 | ||
1031 | if ( itemsChanged->GetCount() > MANY_ITEMS ) | |
1032 | { | |
1033 | // stop counting them, we'll just eat gobs of memory | |
1034 | // for nothing at all - faster to refresh everything in | |
1035 | // this case | |
1036 | itemsChanged = NULL; | |
1037 | } | |
1038 | } | |
b54e41c5 VZ |
1039 | } |
1040 | } | |
68a9ef0e VZ |
1041 | |
1042 | // we set it to NULL if there are many items changing state | |
1043 | return itemsChanged != NULL; | |
b54e41c5 VZ |
1044 | } |
1045 | ||
1046 | void wxSelectionStore::OnItemDelete(size_t item) | |
1047 | { | |
1048 | size_t count = m_itemsSel.GetCount(), | |
1049 | i = m_itemsSel.IndexForInsert(item); | |
1050 | ||
1051 | if ( i < count && m_itemsSel[i] == item ) | |
1052 | { | |
1053 | // this item itself was in m_itemsSel, remove it from there | |
1054 | m_itemsSel.RemoveAt(i); | |
938b652b VZ |
1055 | |
1056 | count--; | |
b54e41c5 VZ |
1057 | } |
1058 | ||
1059 | // and adjust the index of all which follow it | |
1060 | while ( i < count ) | |
1061 | { | |
1062 | // all following elements must be greater than the one we deleted | |
1063 | wxASSERT_MSG( m_itemsSel[i] > item, _T("logic error") ); | |
1064 | ||
1065 | m_itemsSel[i++]--; | |
1066 | } | |
1067 | } | |
1068 | ||
c801d85f KB |
1069 | //----------------------------------------------------------------------------- |
1070 | // wxListItemData | |
1071 | //----------------------------------------------------------------------------- | |
1072 | ||
850ed6e7 VZ |
1073 | wxListItemData::~wxListItemData() |
1074 | { | |
1075 | // in the virtual list control the attributes are managed by the main | |
1076 | // program, so don't delete them | |
1077 | if ( !m_owner->IsVirtual() ) | |
1078 | { | |
1079 | delete m_attr; | |
1080 | } | |
1081 | ||
1082 | delete m_rect; | |
1083 | } | |
1084 | ||
cf1dfa6b | 1085 | void wxListItemData::Init() |
c801d85f | 1086 | { |
92976ab6 RR |
1087 | m_image = -1; |
1088 | m_data = 0; | |
cf1dfa6b | 1089 | |
0530737d | 1090 | m_attr = NULL; |
e1e955e1 | 1091 | } |
c801d85f | 1092 | |
cf1dfa6b | 1093 | wxListItemData::wxListItemData(wxListMainWindow *owner) |
c801d85f | 1094 | { |
cf1dfa6b | 1095 | Init(); |
0530737d | 1096 | |
cf1dfa6b VZ |
1097 | m_owner = owner; |
1098 | ||
850ed6e7 | 1099 | if ( owner->InReportView() ) |
cf1dfa6b VZ |
1100 | { |
1101 | m_rect = NULL; | |
1102 | } | |
1103 | else | |
1104 | { | |
1105 | m_rect = new wxRect; | |
1106 | } | |
e1e955e1 | 1107 | } |
c801d85f KB |
1108 | |
1109 | void wxListItemData::SetItem( const wxListItem &info ) | |
1110 | { | |
cf1dfa6b | 1111 | if ( info.m_mask & wxLIST_MASK_TEXT ) |
54442116 | 1112 | SetText(info.m_text); |
cf1dfa6b | 1113 | if ( info.m_mask & wxLIST_MASK_IMAGE ) |
54442116 | 1114 | m_image = info.m_image; |
cf1dfa6b | 1115 | if ( info.m_mask & wxLIST_MASK_DATA ) |
54442116 | 1116 | m_data = info.m_data; |
0530737d VZ |
1117 | |
1118 | if ( info.HasAttributes() ) | |
1119 | { | |
1120 | if ( m_attr ) | |
1121 | *m_attr = *info.GetAttributes(); | |
1122 | else | |
1123 | m_attr = new wxListItemAttr(*info.GetAttributes()); | |
1124 | } | |
1125 | ||
cf1dfa6b VZ |
1126 | if ( m_rect ) |
1127 | { | |
1128 | m_rect->x = | |
1129 | m_rect->y = | |
1130 | m_rect->height = 0; | |
1131 | m_rect->width = info.m_width; | |
1132 | } | |
e1e955e1 | 1133 | } |
c801d85f | 1134 | |
debe6624 | 1135 | void wxListItemData::SetPosition( int x, int y ) |
c801d85f | 1136 | { |
cf1dfa6b VZ |
1137 | wxCHECK_RET( m_rect, _T("unexpected SetPosition() call") ); |
1138 | ||
1139 | m_rect->x = x; | |
1140 | m_rect->y = y; | |
e1e955e1 | 1141 | } |
c801d85f | 1142 | |
1e6d9499 | 1143 | void wxListItemData::SetSize( int width, int height ) |
c801d85f | 1144 | { |
cf1dfa6b | 1145 | wxCHECK_RET( m_rect, _T("unexpected SetSize() call") ); |
c801d85f | 1146 | |
cf1dfa6b VZ |
1147 | if ( width != -1 ) |
1148 | m_rect->width = width; | |
1149 | if ( height != -1 ) | |
1150 | m_rect->height = height; | |
e1e955e1 | 1151 | } |
c801d85f | 1152 | |
debe6624 | 1153 | bool wxListItemData::IsHit( int x, int y ) const |
c801d85f | 1154 | { |
cf1dfa6b VZ |
1155 | wxCHECK_MSG( m_rect, FALSE, _T("can't be called in this mode") ); |
1156 | ||
1157 | return wxRect(GetX(), GetY(), GetWidth(), GetHeight()).Inside(x, y); | |
e1e955e1 | 1158 | } |
c801d85f | 1159 | |
fd9811b1 | 1160 | int wxListItemData::GetX() const |
c801d85f | 1161 | { |
cf1dfa6b VZ |
1162 | wxCHECK_MSG( m_rect, 0, _T("can't be called in this mode") ); |
1163 | ||
1164 | return m_rect->x; | |
e1e955e1 | 1165 | } |
c801d85f | 1166 | |
fd9811b1 | 1167 | int wxListItemData::GetY() const |
c801d85f | 1168 | { |
cf1dfa6b VZ |
1169 | wxCHECK_MSG( m_rect, 0, _T("can't be called in this mode") ); |
1170 | ||
1171 | return m_rect->y; | |
e1e955e1 | 1172 | } |
c801d85f | 1173 | |
fd9811b1 | 1174 | int wxListItemData::GetWidth() const |
c801d85f | 1175 | { |
cf1dfa6b VZ |
1176 | wxCHECK_MSG( m_rect, 0, _T("can't be called in this mode") ); |
1177 | ||
1178 | return m_rect->width; | |
e1e955e1 | 1179 | } |
c801d85f | 1180 | |
fd9811b1 | 1181 | int wxListItemData::GetHeight() const |
c801d85f | 1182 | { |
cf1dfa6b | 1183 | wxCHECK_MSG( m_rect, 0, _T("can't be called in this mode") ); |
c801d85f | 1184 | |
cf1dfa6b | 1185 | return m_rect->height; |
e1e955e1 | 1186 | } |
c801d85f | 1187 | |
0530737d | 1188 | void wxListItemData::GetItem( wxListItem &info ) const |
c801d85f | 1189 | { |
92976ab6 RR |
1190 | info.m_text = m_text; |
1191 | info.m_image = m_image; | |
1192 | info.m_data = m_data; | |
c801d85f | 1193 | |
0530737d VZ |
1194 | if ( m_attr ) |
1195 | { | |
1196 | if ( m_attr->HasTextColour() ) | |
1197 | info.SetTextColour(m_attr->GetTextColour()); | |
1198 | if ( m_attr->HasBackgroundColour() ) | |
1199 | info.SetBackgroundColour(m_attr->GetBackgroundColour()); | |
1200 | if ( m_attr->HasFont() ) | |
1201 | info.SetFont(m_attr->GetFont()); | |
1202 | } | |
e1e955e1 | 1203 | } |
c801d85f KB |
1204 | |
1205 | //----------------------------------------------------------------------------- | |
1206 | // wxListHeaderData | |
1207 | //----------------------------------------------------------------------------- | |
1208 | ||
0a816d95 | 1209 | void wxListHeaderData::Init() |
c801d85f | 1210 | { |
92976ab6 | 1211 | m_mask = 0; |
0a816d95 | 1212 | m_image = -1; |
92976ab6 RR |
1213 | m_format = 0; |
1214 | m_width = 0; | |
1215 | m_xpos = 0; | |
1216 | m_ypos = 0; | |
1217 | m_height = 0; | |
e1e955e1 | 1218 | } |
c801d85f | 1219 | |
0a816d95 VZ |
1220 | wxListHeaderData::wxListHeaderData() |
1221 | { | |
1222 | Init(); | |
1223 | } | |
1224 | ||
c801d85f KB |
1225 | wxListHeaderData::wxListHeaderData( const wxListItem &item ) |
1226 | { | |
0a816d95 VZ |
1227 | Init(); |
1228 | ||
92976ab6 | 1229 | SetItem( item ); |
e1e955e1 | 1230 | } |
c801d85f KB |
1231 | |
1232 | void wxListHeaderData::SetItem( const wxListItem &item ) | |
1233 | { | |
92976ab6 | 1234 | m_mask = item.m_mask; |
cf1dfa6b | 1235 | |
0a816d95 VZ |
1236 | if ( m_mask & wxLIST_MASK_TEXT ) |
1237 | m_text = item.m_text; | |
1238 | ||
1239 | if ( m_mask & wxLIST_MASK_IMAGE ) | |
1240 | m_image = item.m_image; | |
1241 | ||
1242 | if ( m_mask & wxLIST_MASK_FORMAT ) | |
1243 | m_format = item.m_format; | |
1244 | ||
1245 | if ( m_mask & wxLIST_MASK_WIDTH ) | |
1246 | SetWidth(item.m_width); | |
e1e955e1 | 1247 | } |
c801d85f | 1248 | |
debe6624 | 1249 | void wxListHeaderData::SetPosition( int x, int y ) |
c801d85f | 1250 | { |
92976ab6 RR |
1251 | m_xpos = x; |
1252 | m_ypos = y; | |
e1e955e1 | 1253 | } |
c801d85f | 1254 | |
debe6624 | 1255 | void wxListHeaderData::SetHeight( int h ) |
c801d85f | 1256 | { |
92976ab6 | 1257 | m_height = h; |
e1e955e1 | 1258 | } |
c801d85f | 1259 | |
debe6624 | 1260 | void wxListHeaderData::SetWidth( int w ) |
c801d85f | 1261 | { |
92976ab6 | 1262 | m_width = w; |
cf1dfa6b VZ |
1263 | if (m_width < 0) |
1264 | m_width = WIDTH_COL_DEFAULT; | |
0a816d95 | 1265 | else if (m_width < WIDTH_COL_MIN) |
cf1dfa6b | 1266 | m_width = WIDTH_COL_MIN; |
e1e955e1 | 1267 | } |
c801d85f | 1268 | |
debe6624 | 1269 | void wxListHeaderData::SetFormat( int format ) |
c801d85f | 1270 | { |
92976ab6 | 1271 | m_format = format; |
e1e955e1 | 1272 | } |
c801d85f | 1273 | |
fd9811b1 | 1274 | bool wxListHeaderData::HasImage() const |
c801d85f | 1275 | { |
0a816d95 | 1276 | return m_image != -1; |
e1e955e1 | 1277 | } |
c801d85f | 1278 | |
c801d85f KB |
1279 | bool wxListHeaderData::IsHit( int x, int y ) const |
1280 | { | |
92976ab6 | 1281 | return ((x >= m_xpos) && (x <= m_xpos+m_width) && (y >= m_ypos) && (y <= m_ypos+m_height)); |
e1e955e1 | 1282 | } |
c801d85f | 1283 | |
0a816d95 | 1284 | void wxListHeaderData::GetItem( wxListItem& item ) |
c801d85f | 1285 | { |
92976ab6 RR |
1286 | item.m_mask = m_mask; |
1287 | item.m_text = m_text; | |
1288 | item.m_image = m_image; | |
1289 | item.m_format = m_format; | |
1290 | item.m_width = m_width; | |
e1e955e1 | 1291 | } |
c801d85f | 1292 | |
fd9811b1 | 1293 | int wxListHeaderData::GetImage() const |
c801d85f | 1294 | { |
92976ab6 | 1295 | return m_image; |
e1e955e1 | 1296 | } |
c801d85f | 1297 | |
fd9811b1 | 1298 | int wxListHeaderData::GetWidth() const |
c801d85f | 1299 | { |
92976ab6 | 1300 | return m_width; |
e1e955e1 | 1301 | } |
c801d85f | 1302 | |
fd9811b1 | 1303 | int wxListHeaderData::GetFormat() const |
c801d85f | 1304 | { |
92976ab6 | 1305 | return m_format; |
e1e955e1 | 1306 | } |
c801d85f KB |
1307 | |
1308 | //----------------------------------------------------------------------------- | |
1309 | // wxListLineData | |
1310 | //----------------------------------------------------------------------------- | |
1311 | ||
cf1dfa6b VZ |
1312 | inline int wxListLineData::GetMode() const |
1313 | { | |
b54e41c5 | 1314 | return m_owner->GetListCtrl()->GetWindowStyleFlag() & wxLC_MASK_TYPE; |
cf1dfa6b | 1315 | } |
c801d85f | 1316 | |
cf1dfa6b | 1317 | inline bool wxListLineData::InReportView() const |
c801d85f | 1318 | { |
cf1dfa6b | 1319 | return m_owner->HasFlag(wxLC_REPORT); |
e1e955e1 | 1320 | } |
c801d85f | 1321 | |
b54e41c5 | 1322 | inline bool wxListLineData::IsVirtual() const |
c801d85f | 1323 | { |
cf1dfa6b VZ |
1324 | return m_owner->IsVirtual(); |
1325 | } | |
2c1f73ee | 1326 | |
5cd89174 | 1327 | wxListLineData::wxListLineData( wxListMainWindow *owner ) |
cf1dfa6b VZ |
1328 | { |
1329 | m_owner = owner; | |
1330 | m_items.DeleteContents( TRUE ); | |
2c1f73ee | 1331 | |
cf1dfa6b VZ |
1332 | if ( InReportView() ) |
1333 | { | |
1334 | m_gi = NULL; | |
1335 | } | |
1336 | else // !report | |
1337 | { | |
1338 | m_gi = new GeometryInfo; | |
1339 | } | |
f6bcfd97 | 1340 | |
b54e41c5 | 1341 | m_highlighted = FALSE; |
f6bcfd97 | 1342 | |
cf1dfa6b VZ |
1343 | InitItems( GetMode() == wxLC_REPORT ? m_owner->GetColumnCount() : 1 ); |
1344 | } | |
f6bcfd97 | 1345 | |
cf1dfa6b VZ |
1346 | void wxListLineData::CalculateSize( wxDC *dc, int spacing ) |
1347 | { | |
1348 | wxListItemDataList::Node *node = m_items.GetFirst(); | |
1349 | wxCHECK_RET( node, _T("no subitems at all??") ); | |
1350 | ||
1351 | wxListItemData *item = node->GetData(); | |
1352 | ||
1353 | switch ( GetMode() ) | |
1354 | { | |
1355 | case wxLC_ICON: | |
1356 | case wxLC_SMALL_ICON: | |
1357 | { | |
1358 | m_gi->m_rectAll.width = spacing; | |
1359 | ||
1360 | wxString s = item->GetText(); | |
1361 | ||
1362 | wxCoord lw, lh; | |
1363 | if ( s.empty() ) | |
5d25c050 | 1364 | { |
cf1dfa6b VZ |
1365 | lh = |
1366 | m_gi->m_rectLabel.width = | |
1367 | m_gi->m_rectLabel.height = 0; | |
5d25c050 | 1368 | } |
cf1dfa6b VZ |
1369 | else // has label |
1370 | { | |
1371 | dc->GetTextExtent( s, &lw, &lh ); | |
1372 | if (lh < SCROLL_UNIT_Y) | |
1373 | lh = SCROLL_UNIT_Y; | |
1374 | lw += EXTRA_WIDTH; | |
1375 | lh += EXTRA_HEIGHT; | |
1376 | ||
1377 | m_gi->m_rectAll.height = spacing + lh; | |
1378 | if (lw > spacing) | |
1379 | m_gi->m_rectAll.width = lw; | |
1380 | ||
1381 | m_gi->m_rectLabel.width = lw; | |
1382 | m_gi->m_rectLabel.height = lh; | |
1383 | } | |
1384 | ||
1385 | if (item->HasImage()) | |
1386 | { | |
1387 | int w, h; | |
1388 | m_owner->GetImageSize( item->GetImage(), w, h ); | |
1389 | m_gi->m_rectIcon.width = w + 8; | |
1390 | m_gi->m_rectIcon.height = h + 8; | |
1391 | ||
1392 | if ( m_gi->m_rectIcon.width > m_gi->m_rectAll.width ) | |
1393 | m_gi->m_rectAll.width = m_gi->m_rectIcon.width; | |
1394 | if ( m_gi->m_rectIcon.height + lh > m_gi->m_rectAll.height - 4 ) | |
1395 | m_gi->m_rectAll.height = m_gi->m_rectIcon.height + lh + 4; | |
1396 | } | |
1397 | ||
1398 | if ( item->HasText() ) | |
5d25c050 | 1399 | { |
b54e41c5 VZ |
1400 | m_gi->m_rectHighlight.width = m_gi->m_rectLabel.width; |
1401 | m_gi->m_rectHighlight.height = m_gi->m_rectLabel.height; | |
cf1dfa6b VZ |
1402 | } |
1403 | else // no text, highlight the icon | |
1404 | { | |
b54e41c5 VZ |
1405 | m_gi->m_rectHighlight.width = m_gi->m_rectIcon.width; |
1406 | m_gi->m_rectHighlight.height = m_gi->m_rectIcon.height; | |
5d25c050 | 1407 | } |
92976ab6 RR |
1408 | } |
1409 | break; | |
cf1dfa6b | 1410 | |
92976ab6 | 1411 | case wxLC_LIST: |
92976ab6 | 1412 | { |
cf1dfa6b | 1413 | wxString s = item->GetTextForMeasuring(); |
2c1f73ee | 1414 | |
13111b2a | 1415 | wxCoord lw,lh; |
92976ab6 | 1416 | dc->GetTextExtent( s, &lw, &lh ); |
cf1dfa6b VZ |
1417 | if (lh < SCROLL_UNIT_Y) |
1418 | lh = SCROLL_UNIT_Y; | |
1419 | lw += EXTRA_WIDTH; | |
1420 | lh += EXTRA_HEIGHT; | |
2c1f73ee | 1421 | |
cf1dfa6b VZ |
1422 | m_gi->m_rectLabel.width = lw; |
1423 | m_gi->m_rectLabel.height = lh; | |
f6bcfd97 | 1424 | |
cf1dfa6b VZ |
1425 | m_gi->m_rectAll.width = lw; |
1426 | m_gi->m_rectAll.height = lh; | |
f6bcfd97 | 1427 | |
0b855868 RR |
1428 | if (item->HasImage()) |
1429 | { | |
cf1dfa6b | 1430 | int w, h; |
0b855868 | 1431 | m_owner->GetImageSize( item->GetImage(), w, h ); |
cf1dfa6b VZ |
1432 | m_gi->m_rectIcon.width = w; |
1433 | m_gi->m_rectIcon.height = h; | |
f6bcfd97 | 1434 | |
cf1dfa6b VZ |
1435 | m_gi->m_rectAll.width += 4 + w; |
1436 | if (h > m_gi->m_rectAll.height) | |
1437 | m_gi->m_rectAll.height = h; | |
bffa1c77 | 1438 | } |
f6bcfd97 | 1439 | |
b54e41c5 VZ |
1440 | m_gi->m_rectHighlight.width = m_gi->m_rectAll.width; |
1441 | m_gi->m_rectHighlight.height = m_gi->m_rectAll.height; | |
92976ab6 RR |
1442 | } |
1443 | break; | |
2c1f73ee | 1444 | |
cf1dfa6b VZ |
1445 | case wxLC_REPORT: |
1446 | wxFAIL_MSG( _T("unexpected call to SetSize") ); | |
92976ab6 | 1447 | break; |
cf1dfa6b VZ |
1448 | |
1449 | default: | |
1450 | wxFAIL_MSG( _T("unknown mode") ); | |
e1e955e1 | 1451 | } |
e1e955e1 | 1452 | } |
c801d85f | 1453 | |
cf1dfa6b VZ |
1454 | void wxListLineData::SetPosition( int x, int y, |
1455 | int window_width, | |
1456 | int spacing ) | |
c801d85f | 1457 | { |
2c1f73ee | 1458 | wxListItemDataList::Node *node = m_items.GetFirst(); |
cf1dfa6b | 1459 | wxCHECK_RET( node, _T("no subitems at all??") ); |
2c1f73ee | 1460 | |
cf1dfa6b | 1461 | wxListItemData *item = node->GetData(); |
2c1f73ee | 1462 | |
cf1dfa6b | 1463 | switch ( GetMode() ) |
0b855868 RR |
1464 | { |
1465 | case wxLC_ICON: | |
cf1dfa6b VZ |
1466 | case wxLC_SMALL_ICON: |
1467 | m_gi->m_rectAll.x = x; | |
1468 | m_gi->m_rectAll.y = y; | |
1469 | ||
1470 | if ( item->HasImage() ) | |
0b855868 | 1471 | { |
c2569f41 VZ |
1472 | m_gi->m_rectIcon.x = m_gi->m_rectAll.x + 4 + |
1473 | (m_gi->m_rectAll.width - m_gi->m_rectIcon.width) / 2; | |
cf1dfa6b | 1474 | m_gi->m_rectIcon.y = m_gi->m_rectAll.y + 4; |
0b855868 | 1475 | } |
cf1dfa6b VZ |
1476 | |
1477 | if ( item->HasText() ) | |
0b855868 | 1478 | { |
cf1dfa6b VZ |
1479 | if (m_gi->m_rectAll.width > spacing) |
1480 | m_gi->m_rectLabel.x = m_gi->m_rectAll.x + 2; | |
5d25c050 | 1481 | else |
cf1dfa6b VZ |
1482 | m_gi->m_rectLabel.x = m_gi->m_rectAll.x + 2 + (spacing/2) - (m_gi->m_rectLabel.width/2); |
1483 | m_gi->m_rectLabel.y = m_gi->m_rectAll.y + m_gi->m_rectAll.height + 2 - m_gi->m_rectLabel.height; | |
b54e41c5 VZ |
1484 | m_gi->m_rectHighlight.x = m_gi->m_rectLabel.x - 2; |
1485 | m_gi->m_rectHighlight.y = m_gi->m_rectLabel.y - 2; | |
bffa1c77 | 1486 | } |
cf1dfa6b | 1487 | else // no text, highlight the icon |
0b855868 | 1488 | { |
b54e41c5 VZ |
1489 | m_gi->m_rectHighlight.x = m_gi->m_rectIcon.x - 4; |
1490 | m_gi->m_rectHighlight.y = m_gi->m_rectIcon.y - 4; | |
bffa1c77 | 1491 | } |
0b855868 | 1492 | break; |
c801d85f | 1493 | |
cf1dfa6b VZ |
1494 | case wxLC_LIST: |
1495 | m_gi->m_rectAll.x = x; | |
1496 | m_gi->m_rectAll.y = y; | |
c801d85f | 1497 | |
b54e41c5 VZ |
1498 | m_gi->m_rectHighlight.x = m_gi->m_rectAll.x; |
1499 | m_gi->m_rectHighlight.y = m_gi->m_rectAll.y; | |
cf1dfa6b | 1500 | m_gi->m_rectLabel.y = m_gi->m_rectAll.y + 2; |
c801d85f | 1501 | |
cf1dfa6b VZ |
1502 | if (item->HasImage()) |
1503 | { | |
1504 | m_gi->m_rectIcon.x = m_gi->m_rectAll.x + 2; | |
1505 | m_gi->m_rectIcon.y = m_gi->m_rectAll.y + 2; | |
1506 | m_gi->m_rectLabel.x = m_gi->m_rectAll.x + 6 + m_gi->m_rectIcon.width; | |
1507 | } | |
1508 | else | |
1509 | { | |
1510 | m_gi->m_rectLabel.x = m_gi->m_rectAll.x + 2; | |
1511 | } | |
1512 | break; | |
c801d85f | 1513 | |
cf1dfa6b VZ |
1514 | case wxLC_REPORT: |
1515 | wxFAIL_MSG( _T("unexpected call to SetPosition") ); | |
1516 | break; | |
c801d85f | 1517 | |
cf1dfa6b VZ |
1518 | default: |
1519 | wxFAIL_MSG( _T("unknown mode") ); | |
1520 | } | |
e1e955e1 | 1521 | } |
c801d85f | 1522 | |
debe6624 | 1523 | void wxListLineData::InitItems( int num ) |
c801d85f | 1524 | { |
2c1f73ee | 1525 | for (int i = 0; i < num; i++) |
cf1dfa6b | 1526 | m_items.Append( new wxListItemData(m_owner) ); |
e1e955e1 | 1527 | } |
c801d85f | 1528 | |
debe6624 | 1529 | void wxListLineData::SetItem( int index, const wxListItem &info ) |
c801d85f | 1530 | { |
2c1f73ee | 1531 | wxListItemDataList::Node *node = m_items.Item( index ); |
1370703e VZ |
1532 | wxCHECK_RET( node, _T("invalid column index in SetItem") ); |
1533 | ||
1534 | wxListItemData *item = node->GetData(); | |
1535 | item->SetItem( info ); | |
e1e955e1 | 1536 | } |
c801d85f | 1537 | |
1e6d9499 | 1538 | void wxListLineData::GetItem( int index, wxListItem &info ) |
c801d85f | 1539 | { |
2c1f73ee | 1540 | wxListItemDataList::Node *node = m_items.Item( index ); |
139adb6a RR |
1541 | if (node) |
1542 | { | |
2c1f73ee | 1543 | wxListItemData *item = node->GetData(); |
139adb6a RR |
1544 | item->GetItem( info ); |
1545 | } | |
e1e955e1 | 1546 | } |
c801d85f | 1547 | |
54442116 | 1548 | wxString wxListLineData::GetText(int index) const |
c801d85f | 1549 | { |
54442116 VZ |
1550 | wxString s; |
1551 | ||
2c1f73ee | 1552 | wxListItemDataList::Node *node = m_items.Item( index ); |
139adb6a RR |
1553 | if (node) |
1554 | { | |
2c1f73ee | 1555 | wxListItemData *item = node->GetData(); |
54442116 | 1556 | s = item->GetText(); |
139adb6a | 1557 | } |
54442116 VZ |
1558 | |
1559 | return s; | |
e1e955e1 | 1560 | } |
c801d85f | 1561 | |
debe6624 | 1562 | void wxListLineData::SetText( int index, const wxString s ) |
c801d85f | 1563 | { |
2c1f73ee | 1564 | wxListItemDataList::Node *node = m_items.Item( index ); |
139adb6a RR |
1565 | if (node) |
1566 | { | |
2c1f73ee | 1567 | wxListItemData *item = node->GetData(); |
139adb6a RR |
1568 | item->SetText( s ); |
1569 | } | |
e1e955e1 | 1570 | } |
c801d85f | 1571 | |
cf1dfa6b | 1572 | void wxListLineData::SetImage( int index, int image ) |
c801d85f | 1573 | { |
2c1f73ee | 1574 | wxListItemDataList::Node *node = m_items.Item( index ); |
cf1dfa6b VZ |
1575 | wxCHECK_RET( node, _T("invalid column index in SetImage()") ); |
1576 | ||
1577 | wxListItemData *item = node->GetData(); | |
1578 | item->SetImage(image); | |
1579 | } | |
1580 | ||
1581 | int wxListLineData::GetImage( int index ) const | |
1582 | { | |
1583 | wxListItemDataList::Node *node = m_items.Item( index ); | |
1584 | wxCHECK_MSG( node, -1, _T("invalid column index in GetImage()") ); | |
1585 | ||
1586 | wxListItemData *item = node->GetData(); | |
1587 | return item->GetImage(); | |
e1e955e1 | 1588 | } |
c801d85f | 1589 | |
6c02c329 VZ |
1590 | wxListItemAttr *wxListLineData::GetAttr() const |
1591 | { | |
1592 | wxListItemDataList::Node *node = m_items.GetFirst(); | |
1593 | wxCHECK_MSG( node, NULL, _T("invalid column index in GetAttr()") ); | |
1594 | ||
1595 | wxListItemData *item = node->GetData(); | |
1596 | return item->GetAttr(); | |
1597 | } | |
1598 | ||
1599 | void wxListLineData::SetAttr(wxListItemAttr *attr) | |
1600 | { | |
1601 | wxListItemDataList::Node *node = m_items.GetFirst(); | |
1602 | wxCHECK_RET( node, _T("invalid column index in SetAttr()") ); | |
1603 | ||
1604 | wxListItemData *item = node->GetData(); | |
1605 | item->SetAttr(attr); | |
1606 | } | |
1607 | ||
0e980f91 | 1608 | bool wxListLineData::SetAttributes(wxDC *dc, |
0530737d | 1609 | const wxListItemAttr *attr, |
0e980f91 | 1610 | bool highlighted) |
0530737d | 1611 | { |
0e980f91 VZ |
1612 | wxWindow *listctrl = m_owner->GetParent(); |
1613 | ||
1614 | // fg colour | |
1615 | ||
1616 | // don't use foreground colour for drawing highlighted items - this might | |
470caaf9 VZ |
1617 | // make them completely invisible (and there is no way to do bit |
1618 | // arithmetics on wxColour, unfortunately) | |
0e980f91 VZ |
1619 | wxColour colText; |
1620 | if ( highlighted ) | |
0530737d | 1621 | { |
a756f210 | 1622 | colText = wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT); |
0530737d VZ |
1623 | } |
1624 | else | |
1625 | { | |
0e980f91 VZ |
1626 | if ( attr && attr->HasTextColour() ) |
1627 | { | |
1628 | colText = attr->GetTextColour(); | |
1629 | } | |
1630 | else | |
1631 | { | |
1632 | colText = listctrl->GetForegroundColour(); | |
1633 | } | |
0530737d VZ |
1634 | } |
1635 | ||
0e980f91 VZ |
1636 | dc->SetTextForeground(colText); |
1637 | ||
1638 | // font | |
1639 | wxFont font; | |
0530737d VZ |
1640 | if ( attr && attr->HasFont() ) |
1641 | { | |
0e980f91 | 1642 | font = attr->GetFont(); |
0530737d VZ |
1643 | } |
1644 | else | |
1645 | { | |
0e980f91 | 1646 | font = listctrl->GetFont(); |
0530737d | 1647 | } |
0e980f91 VZ |
1648 | |
1649 | dc->SetFont(font); | |
1650 | ||
1651 | // bg colour | |
1652 | bool hasBgCol = attr && attr->HasBackgroundColour(); | |
1653 | if ( highlighted || hasBgCol ) | |
1654 | { | |
1655 | if ( highlighted ) | |
1656 | { | |
49ecb029 | 1657 | dc->SetBrush( *m_owner->GetHighlightBrush() ); |
0e980f91 VZ |
1658 | } |
1659 | else | |
1660 | { | |
1661 | dc->SetBrush(wxBrush(attr->GetBackgroundColour(), wxSOLID)); | |
1662 | } | |
1663 | ||
1664 | dc->SetPen( *wxTRANSPARENT_PEN ); | |
1665 | ||
1666 | return TRUE; | |
1667 | } | |
1668 | ||
1669 | return FALSE; | |
0530737d VZ |
1670 | } |
1671 | ||
5cd89174 VZ |
1672 | void wxListLineData::Draw( wxDC *dc ) |
1673 | { | |
1674 | wxListItemDataList::Node *node = m_items.GetFirst(); | |
1675 | wxCHECK_RET( node, _T("no subitems at all??") ); | |
1676 | ||
0e980f91 VZ |
1677 | bool highlighted = IsHighlighted(); |
1678 | ||
1679 | wxListItemAttr *attr = GetAttr(); | |
1680 | ||
1681 | if ( SetAttributes(dc, attr, highlighted) ) | |
1682 | { | |
1683 | dc->DrawRectangle( m_gi->m_rectHighlight ); | |
1684 | } | |
1685 | ||
5cd89174 VZ |
1686 | wxListItemData *item = node->GetData(); |
1687 | if (item->HasImage()) | |
1688 | { | |
1689 | wxRect rectIcon = m_gi->m_rectIcon; | |
1690 | m_owner->DrawImage( item->GetImage(), dc, | |
1691 | rectIcon.x, rectIcon.y ); | |
1692 | } | |
1693 | ||
1694 | if (item->HasText()) | |
1695 | { | |
1696 | wxRect rectLabel = m_gi->m_rectLabel; | |
06b781c7 VZ |
1697 | |
1698 | wxDCClipper clipper(*dc, rectLabel); | |
5cd89174 VZ |
1699 | dc->DrawText( item->GetText(), rectLabel.x, rectLabel.y ); |
1700 | } | |
1701 | } | |
1702 | ||
1703 | void wxListLineData::DrawInReportMode( wxDC *dc, | |
938b652b | 1704 | const wxRect& rect, |
5cd89174 VZ |
1705 | const wxRect& rectHL, |
1706 | bool highlighted ) | |
c801d85f | 1707 | { |
6c02c329 VZ |
1708 | // TODO: later we should support setting different attributes for |
1709 | // different columns - to do it, just add "col" argument to | |
0e980f91 | 1710 | // GetAttr() and move these lines into the loop below |
6c02c329 | 1711 | wxListItemAttr *attr = GetAttr(); |
0e980f91 | 1712 | if ( SetAttributes(dc, attr, highlighted) ) |
c801d85f | 1713 | { |
5cd89174 | 1714 | dc->DrawRectangle( rectHL ); |
e1e955e1 | 1715 | } |
004fd0c8 | 1716 | |
938b652b VZ |
1717 | wxCoord x = rect.x + HEADER_OFFSET_X, |
1718 | y = rect.y + (LINE_SPACING + EXTRA_HEIGHT) / 2; | |
cf1dfa6b | 1719 | |
904ccf52 VZ |
1720 | size_t col = 0; |
1721 | for ( wxListItemDataList::Node *node = m_items.GetFirst(); | |
1722 | node; | |
1723 | node = node->GetNext(), col++ ) | |
5cd89174 VZ |
1724 | { |
1725 | wxListItemData *item = node->GetData(); | |
cf1dfa6b | 1726 | |
904ccf52 | 1727 | int width = m_owner->GetColumnWidth(col); |
5cd89174 | 1728 | int xOld = x; |
06b781c7 | 1729 | x += width; |
cf1dfa6b | 1730 | |
5cd89174 VZ |
1731 | if ( item->HasImage() ) |
1732 | { | |
1733 | int ix, iy; | |
06b781c7 | 1734 | m_owner->DrawImage( item->GetImage(), dc, xOld, y ); |
5cd89174 | 1735 | m_owner->GetImageSize( item->GetImage(), ix, iy ); |
cf1dfa6b | 1736 | |
06b781c7 | 1737 | ix += IMAGE_MARGIN_IN_REPORT_MODE; |
cf1dfa6b | 1738 | |
06b781c7 VZ |
1739 | xOld += ix; |
1740 | width -= ix; | |
1741 | } | |
1742 | ||
1743 | wxDCClipper clipper(*dc, xOld, y, width, rect.height); | |
cf1dfa6b | 1744 | |
5cd89174 VZ |
1745 | if ( item->HasText() ) |
1746 | { | |
06b781c7 | 1747 | dc->DrawText( item->GetText(), xOld, y ); |
5cd89174 | 1748 | } |
e1e955e1 | 1749 | } |
e1e955e1 | 1750 | } |
c801d85f | 1751 | |
b54e41c5 | 1752 | bool wxListLineData::Highlight( bool on ) |
c801d85f | 1753 | { |
b54e41c5 | 1754 | wxCHECK_MSG( !m_owner->IsVirtual(), FALSE, _T("unexpected call to Highlight") ); |
c801d85f | 1755 | |
b54e41c5 | 1756 | if ( on == m_highlighted ) |
cf1dfa6b | 1757 | return FALSE; |
c801d85f | 1758 | |
b54e41c5 | 1759 | m_highlighted = on; |
c801d85f | 1760 | |
cf1dfa6b | 1761 | return TRUE; |
e1e955e1 | 1762 | } |
c801d85f | 1763 | |
b54e41c5 | 1764 | void wxListLineData::ReverseHighlight( void ) |
c801d85f | 1765 | { |
b54e41c5 | 1766 | Highlight(!IsHighlighted()); |
e1e955e1 | 1767 | } |
c801d85f KB |
1768 | |
1769 | //----------------------------------------------------------------------------- | |
1770 | // wxListHeaderWindow | |
1771 | //----------------------------------------------------------------------------- | |
1772 | ||
5a1cad6e | 1773 | IMPLEMENT_DYNAMIC_CLASS(wxListHeaderWindow,wxWindow) |
c801d85f KB |
1774 | |
1775 | BEGIN_EVENT_TABLE(wxListHeaderWindow,wxWindow) | |
63852e78 RR |
1776 | EVT_PAINT (wxListHeaderWindow::OnPaint) |
1777 | EVT_MOUSE_EVENTS (wxListHeaderWindow::OnMouse) | |
1778 | EVT_SET_FOCUS (wxListHeaderWindow::OnSetFocus) | |
c801d85f KB |
1779 | END_EVENT_TABLE() |
1780 | ||
0a816d95 | 1781 | void wxListHeaderWindow::Init() |
c801d85f | 1782 | { |
63852e78 | 1783 | m_currentCursor = (wxCursor *) NULL; |
cfb50f14 | 1784 | m_isDragging = FALSE; |
0a816d95 VZ |
1785 | m_dirty = FALSE; |
1786 | } | |
1787 | ||
1788 | wxListHeaderWindow::wxListHeaderWindow() | |
1789 | { | |
1790 | Init(); | |
1791 | ||
1792 | m_owner = (wxListMainWindow *) NULL; | |
1793 | m_resizeCursor = (wxCursor *) NULL; | |
e1e955e1 | 1794 | } |
c801d85f | 1795 | |
0a816d95 VZ |
1796 | wxListHeaderWindow::wxListHeaderWindow( wxWindow *win, |
1797 | wxWindowID id, | |
1798 | wxListMainWindow *owner, | |
1799 | const wxPoint& pos, | |
1800 | const wxSize& size, | |
1801 | long style, | |
1802 | const wxString &name ) | |
1803 | : wxWindow( win, id, pos, size, style, name ) | |
c801d85f | 1804 | { |
0a816d95 VZ |
1805 | Init(); |
1806 | ||
63852e78 | 1807 | m_owner = owner; |
63852e78 | 1808 | m_resizeCursor = new wxCursor( wxCURSOR_SIZEWE ); |
f6bcfd97 | 1809 | |
a756f210 | 1810 | SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE ) ); |
e1e955e1 | 1811 | } |
c801d85f | 1812 | |
0a816d95 | 1813 | wxListHeaderWindow::~wxListHeaderWindow() |
a367b9b3 | 1814 | { |
63852e78 | 1815 | delete m_resizeCursor; |
a367b9b3 JS |
1816 | } |
1817 | ||
1e6d9499 | 1818 | void wxListHeaderWindow::DoDrawRect( wxDC *dc, int x, int y, int w, int h ) |
c801d85f | 1819 | { |
f16ba4e6 | 1820 | #if defined(__WXGTK__) && !defined(__WXUNIVERSAL__) |
b54e41c5 VZ |
1821 | GtkStateType state = m_parent->IsEnabled() ? GTK_STATE_NORMAL |
1822 | : GTK_STATE_INSENSITIVE; | |
2c1f73ee | 1823 | |
3fb435df | 1824 | x = dc->XLOG2DEV( x ); |
2c1f73ee | 1825 | |
b54e41c5 VZ |
1826 | gtk_paint_box (m_wxwindow->style, GTK_PIZZA(m_wxwindow)->bin_window, |
1827 | state, GTK_SHADOW_OUT, | |
90350682 VZ |
1828 | (GdkRectangle*) NULL, m_wxwindow, |
1829 | (char *)"button", // const_cast | |
b54e41c5 | 1830 | x-1, y-1, w+2, h+2); |
4176fb7d SC |
1831 | #elif defined( __WXMAC__ ) |
1832 | const int m_corner = 1; | |
1833 | ||
1834 | dc->SetBrush( *wxTRANSPARENT_BRUSH ); | |
1835 | ||
a756f210 | 1836 | dc->SetPen( wxPen( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNSHADOW ) , 1 , wxSOLID ) ); |
4176fb7d SC |
1837 | dc->DrawLine( x+w-m_corner+1, y, x+w, y+h ); // right (outer) |
1838 | dc->DrawRectangle( x, y+h, w+1, 1 ); // bottom (outer) | |
1839 | ||
1840 | wxPen pen( wxColour( 0x88 , 0x88 , 0x88 ), 1, wxSOLID ); | |
1841 | ||
1842 | dc->SetPen( pen ); | |
1843 | dc->DrawLine( x+w-m_corner, y, x+w-1, y+h ); // right (inner) | |
1844 | dc->DrawRectangle( x+1, y+h-1, w-2, 1 ); // bottom (inner) | |
1845 | ||
1846 | dc->SetPen( *wxWHITE_PEN ); | |
1847 | dc->DrawRectangle( x, y, w-m_corner+1, 1 ); // top (outer) | |
1848 | dc->DrawRectangle( x, y, 1, h ); // left (outer) | |
1849 | dc->DrawLine( x, y+h-1, x+1, y+h-1 ); | |
1850 | dc->DrawLine( x+w-1, y, x+w-1, y+1 ); | |
b54e41c5 | 1851 | #else // !GTK, !Mac |
63852e78 | 1852 | const int m_corner = 1; |
c801d85f | 1853 | |
63852e78 | 1854 | dc->SetBrush( *wxTRANSPARENT_BRUSH ); |
c801d85f | 1855 | |
63852e78 RR |
1856 | dc->SetPen( *wxBLACK_PEN ); |
1857 | dc->DrawLine( x+w-m_corner+1, y, x+w, y+h ); // right (outer) | |
17867d61 | 1858 | dc->DrawRectangle( x, y+h, w+1, 1 ); // bottom (outer) |
bd8289c1 | 1859 | |
a756f210 | 1860 | wxPen pen( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNSHADOW ), 1, wxSOLID ); |
004fd0c8 | 1861 | |
63852e78 RR |
1862 | dc->SetPen( pen ); |
1863 | dc->DrawLine( x+w-m_corner, y, x+w-1, y+h ); // right (inner) | |
1864 | dc->DrawRectangle( x+1, y+h-1, w-2, 1 ); // bottom (inner) | |
bd8289c1 | 1865 | |
63852e78 RR |
1866 | dc->SetPen( *wxWHITE_PEN ); |
1867 | dc->DrawRectangle( x, y, w-m_corner+1, 1 ); // top (outer) | |
1868 | dc->DrawRectangle( x, y, 1, h ); // left (outer) | |
1869 | dc->DrawLine( x, y+h-1, x+1, y+h-1 ); | |
1870 | dc->DrawLine( x+w-1, y, x+w-1, y+1 ); | |
3fb435df | 1871 | #endif |
e1e955e1 | 1872 | } |
c801d85f | 1873 | |
f6bcfd97 BP |
1874 | // shift the DC origin to match the position of the main window horz |
1875 | // scrollbar: this allows us to always use logical coords | |
1876 | void wxListHeaderWindow::AdjustDC(wxDC& dc) | |
1877 | { | |
f6bcfd97 BP |
1878 | int xpix; |
1879 | m_owner->GetScrollPixelsPerUnit( &xpix, NULL ); | |
1880 | ||
1881 | int x; | |
1882 | m_owner->GetViewStart( &x, NULL ); | |
1883 | ||
1884 | // account for the horz scrollbar offset | |
1885 | dc.SetDeviceOrigin( -x * xpix, 0 ); | |
f6bcfd97 BP |
1886 | } |
1887 | ||
c801d85f KB |
1888 | void wxListHeaderWindow::OnPaint( wxPaintEvent &WXUNUSED(event) ) |
1889 | { | |
f16ba4e6 | 1890 | #if defined(__WXGTK__) |
10bd0724 JS |
1891 | wxClientDC dc( this ); |
1892 | #else | |
63852e78 | 1893 | wxPaintDC dc( this ); |
10bd0724 JS |
1894 | #endif |
1895 | ||
63852e78 | 1896 | PrepareDC( dc ); |
f6bcfd97 | 1897 | AdjustDC( dc ); |
bffa1c77 | 1898 | |
63852e78 | 1899 | dc.BeginDrawing(); |
bd8289c1 | 1900 | |
63852e78 | 1901 | dc.SetFont( GetFont() ); |
bd8289c1 | 1902 | |
f6bcfd97 BP |
1903 | // width and height of the entire header window |
1904 | int w, h; | |
63852e78 | 1905 | GetClientSize( &w, &h ); |
f6bcfd97 | 1906 | m_owner->CalcUnscrolledPosition(w, 0, &w, NULL); |
c801d85f | 1907 | |
f60d0f94 | 1908 | dc.SetBackgroundMode(wxTRANSPARENT); |
70846f0a VZ |
1909 | |
1910 | // do *not* use the listctrl colour for headers - one day we will have a | |
1911 | // function to set it separately | |
37d403aa | 1912 | //dc.SetTextForeground( *wxBLACK ); |
cf1dfa6b VZ |
1913 | dc.SetTextForeground(wxSystemSettings:: |
1914 | GetSystemColour( wxSYS_COLOUR_WINDOWTEXT )); | |
1915 | ||
1916 | int x = HEADER_OFFSET_X; | |
c801d85f | 1917 | |
63852e78 RR |
1918 | int numColumns = m_owner->GetColumnCount(); |
1919 | wxListItem item; | |
c5b7bb59 | 1920 | for ( int i = 0; i < numColumns && x < w; i++ ) |
63852e78 RR |
1921 | { |
1922 | m_owner->GetColumn( i, item ); | |
f6bcfd97 | 1923 | int wCol = item.m_width; |
f6bcfd97 | 1924 | |
0a816d95 VZ |
1925 | // the width of the rect to draw: make it smaller to fit entirely |
1926 | // inside the column rect | |
1927 | int cw = wCol - 2; | |
f6bcfd97 | 1928 | |
63852e78 | 1929 | dc.SetPen( *wxWHITE_PEN ); |
c801d85f | 1930 | |
cf1dfa6b | 1931 | DoDrawRect( &dc, x, HEADER_OFFSET_Y, cw, h-2 ); |
0a816d95 VZ |
1932 | |
1933 | // if we have an image, draw it on the right of the label | |
1934 | int image = item.m_image; | |
1935 | if ( image != -1 ) | |
1936 | { | |
9cb07953 | 1937 | wxGenericImageList *imageList = m_owner->m_small_image_list; |
0a816d95 VZ |
1938 | if ( imageList ) |
1939 | { | |
1940 | int ix, iy; | |
1941 | imageList->GetSize(image, ix, iy); | |
1942 | ||
1943 | imageList->Draw | |
1944 | ( | |
1945 | image, | |
1946 | dc, | |
1947 | x + cw - ix - 1, | |
1948 | HEADER_OFFSET_Y + (h - 4 - iy)/2, | |
1949 | wxIMAGELIST_DRAW_TRANSPARENT | |
1950 | ); | |
1951 | ||
1952 | cw -= ix + 2; | |
1953 | } | |
1954 | //else: ignore the column image | |
1955 | } | |
1956 | ||
1957 | // draw the text clipping it so that it doesn't overwrite the column | |
1958 | // boundary | |
1959 | wxDCClipper clipper(dc, x, HEADER_OFFSET_Y, cw, h - 4 ); | |
06b781c7 VZ |
1960 | |
1961 | dc.DrawText( item.GetText(), | |
1962 | x + EXTRA_WIDTH, HEADER_OFFSET_Y + EXTRA_HEIGHT ); | |
1963 | ||
0a816d95 | 1964 | x += wCol; |
63852e78 | 1965 | } |
c5b7bb59 | 1966 | |
63852e78 | 1967 | dc.EndDrawing(); |
e1e955e1 | 1968 | } |
c801d85f | 1969 | |
0208334d RR |
1970 | void wxListHeaderWindow::DrawCurrent() |
1971 | { | |
63852e78 RR |
1972 | int x1 = m_currentX; |
1973 | int y1 = 0; | |
f16ba4e6 | 1974 | m_owner->ClientToScreen( &x1, &y1 ); |
f6bcfd97 | 1975 | |
f16ba4e6 | 1976 | int x2 = m_currentX; |
63852e78 | 1977 | int y2 = 0; |
f6bcfd97 | 1978 | m_owner->GetClientSize( NULL, &y2 ); |
63852e78 | 1979 | m_owner->ClientToScreen( &x2, &y2 ); |
0208334d | 1980 | |
63852e78 | 1981 | wxScreenDC dc; |
3c679789 | 1982 | dc.SetLogicalFunction( wxINVERT ); |
63852e78 RR |
1983 | dc.SetPen( wxPen( *wxBLACK, 2, wxSOLID ) ); |
1984 | dc.SetBrush( *wxTRANSPARENT_BRUSH ); | |
0208334d | 1985 | |
f6bcfd97 BP |
1986 | AdjustDC(dc); |
1987 | ||
63852e78 | 1988 | dc.DrawLine( x1, y1, x2, y2 ); |
0208334d | 1989 | |
63852e78 | 1990 | dc.SetLogicalFunction( wxCOPY ); |
0208334d | 1991 | |
63852e78 RR |
1992 | dc.SetPen( wxNullPen ); |
1993 | dc.SetBrush( wxNullBrush ); | |
0208334d RR |
1994 | } |
1995 | ||
c801d85f KB |
1996 | void wxListHeaderWindow::OnMouse( wxMouseEvent &event ) |
1997 | { | |
f6bcfd97 | 1998 | // we want to work with logical coords |
3ca6a5f0 BP |
1999 | int x; |
2000 | m_owner->CalcUnscrolledPosition(event.GetX(), 0, &x, NULL); | |
3ca6a5f0 | 2001 | int y = event.GetY(); |
f6bcfd97 | 2002 | |
cfb50f14 | 2003 | if (m_isDragging) |
0208334d | 2004 | { |
a77ec46d RD |
2005 | SendListEvent(wxEVT_COMMAND_LIST_COL_DRAGGING, |
2006 | event.GetPosition()); | |
2007 | ||
f6bcfd97 BP |
2008 | // we don't draw the line beyond our window, but we allow dragging it |
2009 | // there | |
2010 | int w = 0; | |
2011 | GetClientSize( &w, NULL ); | |
f6bcfd97 | 2012 | m_owner->CalcUnscrolledPosition(w, 0, &w, NULL); |
f6bcfd97 BP |
2013 | w -= 6; |
2014 | ||
2015 | // erase the line if it was drawn | |
2016 | if ( m_currentX < w ) | |
2017 | DrawCurrent(); | |
2018 | ||
63852e78 RR |
2019 | if (event.ButtonUp()) |
2020 | { | |
2021 | ReleaseMouse(); | |
cfb50f14 | 2022 | m_isDragging = FALSE; |
f6bcfd97 BP |
2023 | m_dirty = TRUE; |
2024 | m_owner->SetColumnWidth( m_column, m_currentX - m_minX ); | |
a77ec46d RD |
2025 | SendListEvent(wxEVT_COMMAND_LIST_COL_END_DRAG, |
2026 | event.GetPosition()); | |
63852e78 RR |
2027 | } |
2028 | else | |
2029 | { | |
f6bcfd97 | 2030 | if (x > m_minX + 7) |
63852e78 RR |
2031 | m_currentX = x; |
2032 | else | |
f6bcfd97 | 2033 | m_currentX = m_minX + 7; |
bd8289c1 | 2034 | |
f6bcfd97 BP |
2035 | // draw in the new location |
2036 | if ( m_currentX < w ) | |
2037 | DrawCurrent(); | |
bffa1c77 | 2038 | } |
0208334d | 2039 | } |
f6bcfd97 | 2040 | else // not dragging |
c801d85f | 2041 | { |
f6bcfd97 BP |
2042 | m_minX = 0; |
2043 | bool hit_border = FALSE; | |
2044 | ||
2045 | // end of the current column | |
2046 | int xpos = 0; | |
2047 | ||
2048 | // find the column where this event occured | |
62313c27 VZ |
2049 | int col, |
2050 | countCol = m_owner->GetColumnCount(); | |
2051 | for (col = 0; col < countCol; col++) | |
bffa1c77 | 2052 | { |
cf1dfa6b VZ |
2053 | xpos += m_owner->GetColumnWidth( col ); |
2054 | m_column = col; | |
f6bcfd97 BP |
2055 | |
2056 | if ( (abs(x-xpos) < 3) && (y < 22) ) | |
2057 | { | |
2058 | // near the column border | |
2059 | hit_border = TRUE; | |
2060 | break; | |
2061 | } | |
2062 | ||
2063 | if ( x < xpos ) | |
2064 | { | |
2065 | // inside the column | |
2066 | break; | |
2067 | } | |
2068 | ||
2069 | m_minX = xpos; | |
bffa1c77 | 2070 | } |
63852e78 | 2071 | |
62313c27 VZ |
2072 | if ( col == countCol ) |
2073 | m_column = -1; | |
2074 | ||
11358d39 | 2075 | if (event.LeftDown() || event.RightUp()) |
63852e78 | 2076 | { |
11358d39 | 2077 | if (hit_border && event.LeftDown()) |
f6bcfd97 BP |
2078 | { |
2079 | m_isDragging = TRUE; | |
2080 | m_currentX = x; | |
2081 | DrawCurrent(); | |
2082 | CaptureMouse(); | |
a77ec46d RD |
2083 | SendListEvent(wxEVT_COMMAND_LIST_COL_BEGIN_DRAG, |
2084 | event.GetPosition()); | |
f6bcfd97 | 2085 | } |
11358d39 | 2086 | else // click on a column |
f6bcfd97 | 2087 | { |
a77ec46d | 2088 | SendListEvent( event.LeftDown() |
11358d39 VZ |
2089 | ? wxEVT_COMMAND_LIST_COL_CLICK |
2090 | : wxEVT_COMMAND_LIST_COL_RIGHT_CLICK, | |
a77ec46d | 2091 | event.GetPosition()); |
f6bcfd97 | 2092 | } |
63852e78 | 2093 | } |
f6bcfd97 | 2094 | else if (event.Moving()) |
63852e78 | 2095 | { |
f6bcfd97 BP |
2096 | bool setCursor; |
2097 | if (hit_border) | |
2098 | { | |
2099 | setCursor = m_currentCursor == wxSTANDARD_CURSOR; | |
2100 | m_currentCursor = m_resizeCursor; | |
2101 | } | |
2102 | else | |
2103 | { | |
2104 | setCursor = m_currentCursor != wxSTANDARD_CURSOR; | |
2105 | m_currentCursor = wxSTANDARD_CURSOR; | |
2106 | } | |
2107 | ||
2108 | if ( setCursor ) | |
2109 | SetCursor(*m_currentCursor); | |
63852e78 | 2110 | } |
e1e955e1 | 2111 | } |
e1e955e1 | 2112 | } |
c801d85f KB |
2113 | |
2114 | void wxListHeaderWindow::OnSetFocus( wxFocusEvent &WXUNUSED(event) ) | |
2115 | { | |
63852e78 | 2116 | m_owner->SetFocus(); |
e1e955e1 | 2117 | } |
c801d85f | 2118 | |
a77ec46d RD |
2119 | void wxListHeaderWindow::SendListEvent(wxEventType type, wxPoint pos) |
2120 | { | |
2121 | wxWindow *parent = GetParent(); | |
2122 | wxListEvent le( type, parent->GetId() ); | |
2123 | le.SetEventObject( parent ); | |
2124 | le.m_pointDrag = pos; | |
2125 | ||
2126 | // the position should be relative to the parent window, not | |
2127 | // this one for compatibility with MSW and common sense: the | |
2128 | // user code doesn't know anything at all about this header | |
2129 | // window, so why should it get positions relative to it? | |
2130 | le.m_pointDrag.y -= GetSize().y; | |
2131 | ||
2132 | le.m_col = m_column; | |
2133 | parent->GetEventHandler()->ProcessEvent( le ); | |
2134 | } | |
2135 | ||
c801d85f KB |
2136 | //----------------------------------------------------------------------------- |
2137 | // wxListRenameTimer (internal) | |
2138 | //----------------------------------------------------------------------------- | |
2139 | ||
bd8289c1 VZ |
2140 | wxListRenameTimer::wxListRenameTimer( wxListMainWindow *owner ) |
2141 | { | |
63852e78 | 2142 | m_owner = owner; |
e1e955e1 | 2143 | } |
c801d85f | 2144 | |
bd8289c1 VZ |
2145 | void wxListRenameTimer::Notify() |
2146 | { | |
63852e78 | 2147 | m_owner->OnRenameTimer(); |
e1e955e1 | 2148 | } |
c801d85f | 2149 | |
ee7ee469 RR |
2150 | //----------------------------------------------------------------------------- |
2151 | // wxListTextCtrl (internal) | |
2152 | //----------------------------------------------------------------------------- | |
2153 | ||
ee7ee469 | 2154 | BEGIN_EVENT_TABLE(wxListTextCtrl,wxTextCtrl) |
63852e78 | 2155 | EVT_CHAR (wxListTextCtrl::OnChar) |
2c1f73ee | 2156 | EVT_KEY_UP (wxListTextCtrl::OnKeyUp) |
63852e78 | 2157 | EVT_KILL_FOCUS (wxListTextCtrl::OnKillFocus) |
ee7ee469 RR |
2158 | END_EVENT_TABLE() |
2159 | ||
62d89eb4 VZ |
2160 | wxListTextCtrl::wxListTextCtrl(wxListMainWindow *owner, size_t itemEdit) |
2161 | : m_startValue(owner->GetItemText(itemEdit)), | |
2162 | m_itemEdited(itemEdit) | |
2163 | { | |
63852e78 | 2164 | m_owner = owner; |
dd5a32cc | 2165 | m_finished = FALSE; |
62d89eb4 VZ |
2166 | |
2167 | wxRect rectLabel = owner->GetLineLabelRect(itemEdit); | |
2168 | ||
2169 | m_owner->CalcScrolledPosition(rectLabel.x, rectLabel.y, | |
2170 | &rectLabel.x, &rectLabel.y); | |
2171 | ||
2172 | (void)Create(owner, wxID_ANY, m_startValue, | |
2173 | wxPoint(rectLabel.x-4,rectLabel.y-4), | |
2174 | wxSize(rectLabel.width+11,rectLabel.height+8)); | |
ee7ee469 RR |
2175 | } |
2176 | ||
62d89eb4 | 2177 | void wxListTextCtrl::Finish() |
ee7ee469 | 2178 | { |
62d89eb4 | 2179 | if ( !m_finished ) |
63852e78 | 2180 | { |
62d89eb4 | 2181 | wxPendingDelete.Append(this); |
f6bcfd97 | 2182 | |
dd5a32cc | 2183 | m_finished = TRUE; |
62d89eb4 | 2184 | |
a6d57d03 | 2185 | m_owner->SetFocus(); |
62d89eb4 VZ |
2186 | } |
2187 | } | |
dd5a32cc | 2188 | |
62d89eb4 VZ |
2189 | bool wxListTextCtrl::AcceptChanges() |
2190 | { | |
2191 | const wxString value = GetValue(); | |
2192 | ||
2193 | if ( value == m_startValue ) | |
2194 | { | |
2195 | // nothing changed, always accept | |
2196 | return TRUE; | |
63852e78 | 2197 | } |
62d89eb4 VZ |
2198 | |
2199 | if ( !m_owner->OnRenameAccept(m_itemEdited, value) ) | |
63852e78 | 2200 | { |
62d89eb4 VZ |
2201 | // vetoed by the user |
2202 | return FALSE; | |
2203 | } | |
f6bcfd97 | 2204 | |
62d89eb4 VZ |
2205 | // accepted, do rename the item |
2206 | m_owner->SetItemText(m_itemEdited, value); | |
f6bcfd97 | 2207 | |
62d89eb4 VZ |
2208 | return TRUE; |
2209 | } | |
dd5a32cc | 2210 | |
62d89eb4 VZ |
2211 | void wxListTextCtrl::OnChar( wxKeyEvent &event ) |
2212 | { | |
2213 | switch ( event.m_keyCode ) | |
2214 | { | |
2215 | case WXK_RETURN: | |
2216 | if ( !AcceptChanges() ) | |
2217 | { | |
2218 | // vetoed by the user code | |
2219 | break; | |
2220 | } | |
2221 | //else: fall through | |
f6bcfd97 | 2222 | |
62d89eb4 VZ |
2223 | case WXK_ESCAPE: |
2224 | Finish(); | |
2225 | break; | |
2226 | ||
2227 | default: | |
2228 | event.Skip(); | |
2229 | } | |
63852e78 RR |
2230 | } |
2231 | ||
c13cace1 VS |
2232 | void wxListTextCtrl::OnKeyUp( wxKeyEvent &event ) |
2233 | { | |
dd5a32cc RR |
2234 | if (m_finished) |
2235 | { | |
2236 | event.Skip(); | |
2237 | return; | |
2238 | } | |
2239 | ||
c13cace1 VS |
2240 | // auto-grow the textctrl: |
2241 | wxSize parentSize = m_owner->GetSize(); | |
2242 | wxPoint myPos = GetPosition(); | |
2243 | wxSize mySize = GetSize(); | |
2244 | int sx, sy; | |
a6d57d03 | 2245 | GetTextExtent(GetValue() + _T("MM"), &sx, &sy); |
cf1dfa6b VZ |
2246 | if (myPos.x + sx > parentSize.x) |
2247 | sx = parentSize.x - myPos.x; | |
2248 | if (mySize.x > sx) | |
2249 | sx = mySize.x; | |
c13cace1 | 2250 | SetSize(sx, -1); |
2c1f73ee | 2251 | |
c13cace1 VS |
2252 | event.Skip(); |
2253 | } | |
2254 | ||
dd5a32cc | 2255 | void wxListTextCtrl::OnKillFocus( wxFocusEvent &event ) |
63852e78 | 2256 | { |
62d89eb4 | 2257 | if ( !m_finished ) |
dd5a32cc | 2258 | { |
62d89eb4 | 2259 | (void)AcceptChanges(); |
004fd0c8 | 2260 | |
62d89eb4 VZ |
2261 | Finish(); |
2262 | } | |
a77ec46d | 2263 | |
62d89eb4 | 2264 | event.Skip(); |
ee7ee469 RR |
2265 | } |
2266 | ||
c801d85f KB |
2267 | //----------------------------------------------------------------------------- |
2268 | // wxListMainWindow | |
2269 | //----------------------------------------------------------------------------- | |
2270 | ||
5a1cad6e | 2271 | IMPLEMENT_DYNAMIC_CLASS(wxListMainWindow,wxScrolledWindow) |
bd8289c1 | 2272 | |
c801d85f KB |
2273 | BEGIN_EVENT_TABLE(wxListMainWindow,wxScrolledWindow) |
2274 | EVT_PAINT (wxListMainWindow::OnPaint) | |
c801d85f KB |
2275 | EVT_MOUSE_EVENTS (wxListMainWindow::OnMouse) |
2276 | EVT_CHAR (wxListMainWindow::OnChar) | |
3dfb93fd | 2277 | EVT_KEY_DOWN (wxListMainWindow::OnKeyDown) |
c801d85f KB |
2278 | EVT_SET_FOCUS (wxListMainWindow::OnSetFocus) |
2279 | EVT_KILL_FOCUS (wxListMainWindow::OnKillFocus) | |
2fa7c206 | 2280 | EVT_SCROLLWIN (wxListMainWindow::OnScroll) |
c801d85f KB |
2281 | END_EVENT_TABLE() |
2282 | ||
1370703e | 2283 | void wxListMainWindow::Init() |
c801d85f | 2284 | { |
139adb6a | 2285 | m_columns.DeleteContents( TRUE ); |
139adb6a | 2286 | m_dirty = TRUE; |
cf1dfa6b VZ |
2287 | m_countVirt = 0; |
2288 | m_lineFrom = | |
b54e41c5 | 2289 | m_lineTo = (size_t)-1; |
cf1dfa6b VZ |
2290 | m_linesPerPage = 0; |
2291 | ||
2292 | m_headerWidth = | |
2293 | m_lineHeight = 0; | |
1370703e | 2294 | |
9cb07953 JS |
2295 | m_small_image_list = (wxGenericImageList *) NULL; |
2296 | m_normal_image_list = (wxGenericImageList *) NULL; | |
1370703e | 2297 | |
139adb6a RR |
2298 | m_small_spacing = 30; |
2299 | m_normal_spacing = 40; | |
1370703e | 2300 | |
139adb6a | 2301 | m_hasFocus = FALSE; |
1370703e VZ |
2302 | m_dragCount = 0; |
2303 | m_isCreated = FALSE; | |
2304 | ||
139adb6a RR |
2305 | m_lastOnSame = FALSE; |
2306 | m_renameTimer = new wxListRenameTimer( this ); | |
1370703e | 2307 | |
cf1dfa6b | 2308 | m_current = |
efbb7287 | 2309 | m_lineLastClicked = |
1370703e | 2310 | m_lineBeforeLastClicked = (size_t)-1; |
c5c528fc VZ |
2311 | |
2312 | m_freezeCount = 0; | |
e1e955e1 | 2313 | } |
c801d85f | 2314 | |
cf1dfa6b VZ |
2315 | void wxListMainWindow::InitScrolling() |
2316 | { | |
2317 | if ( HasFlag(wxLC_REPORT) ) | |
2318 | { | |
2319 | m_xScroll = SCROLL_UNIT_X; | |
2320 | m_yScroll = SCROLL_UNIT_Y; | |
2321 | } | |
2322 | else | |
2323 | { | |
2324 | m_xScroll = SCROLL_UNIT_Y; | |
2325 | m_yScroll = 0; | |
2326 | } | |
2327 | } | |
2328 | ||
1370703e | 2329 | wxListMainWindow::wxListMainWindow() |
c801d85f | 2330 | { |
1370703e VZ |
2331 | Init(); |
2332 | ||
49ecb029 VZ |
2333 | m_highlightBrush = |
2334 | m_highlightUnfocusedBrush = (wxBrush *) NULL; | |
1370703e VZ |
2335 | |
2336 | m_xScroll = | |
2337 | m_yScroll = 0; | |
2338 | } | |
2339 | ||
2340 | wxListMainWindow::wxListMainWindow( wxWindow *parent, | |
2341 | wxWindowID id, | |
2342 | const wxPoint& pos, | |
2343 | const wxSize& size, | |
2344 | long style, | |
2345 | const wxString &name ) | |
2346 | : wxScrolledWindow( parent, id, pos, size, | |
2347 | style | wxHSCROLL | wxVSCROLL, name ) | |
2348 | { | |
2349 | Init(); | |
2350 | ||
49ecb029 VZ |
2351 | m_highlightBrush = new wxBrush |
2352 | ( | |
a756f210 | 2353 | wxSystemSettings::GetColour |
49ecb029 VZ |
2354 | ( |
2355 | wxSYS_COLOUR_HIGHLIGHT | |
2356 | ), | |
2357 | wxSOLID | |
2358 | ); | |
2359 | ||
2360 | m_highlightUnfocusedBrush = new wxBrush | |
2361 | ( | |
a756f210 | 2362 | wxSystemSettings::GetColour |
49ecb029 VZ |
2363 | ( |
2364 | wxSYS_COLOUR_BTNSHADOW | |
2365 | ), | |
2366 | wxSOLID | |
2367 | ); | |
2368 | ||
139adb6a RR |
2369 | wxSize sz = size; |
2370 | sz.y = 25; | |
bd8289c1 | 2371 | |
cf1dfa6b | 2372 | InitScrolling(); |
139adb6a | 2373 | SetScrollbars( m_xScroll, m_yScroll, 0, 0, 0, 0 ); |
bd8289c1 | 2374 | |
a756f210 | 2375 | SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_LISTBOX ) ); |
e1e955e1 | 2376 | } |
c801d85f | 2377 | |
fd9811b1 | 2378 | wxListMainWindow::~wxListMainWindow() |
c801d85f | 2379 | { |
5fe143df | 2380 | DoDeleteAllItems(); |
12c1b46a | 2381 | |
b54e41c5 | 2382 | delete m_highlightBrush; |
49ecb029 | 2383 | delete m_highlightUnfocusedBrush; |
004fd0c8 | 2384 | |
139adb6a | 2385 | delete m_renameTimer; |
e1e955e1 | 2386 | } |
c801d85f | 2387 | |
cf1dfa6b | 2388 | void wxListMainWindow::CacheLineData(size_t line) |
c801d85f | 2389 | { |
3cd94a0d | 2390 | wxGenericListCtrl *listctrl = GetListCtrl(); |
25e3a937 | 2391 | |
b54e41c5 | 2392 | wxListLineData *ld = GetDummyLine(); |
f6bcfd97 | 2393 | |
cf1dfa6b VZ |
2394 | size_t countCol = GetColumnCount(); |
2395 | for ( size_t col = 0; col < countCol; col++ ) | |
2396 | { | |
2397 | ld->SetText(col, listctrl->OnGetItemText(line, col)); | |
2398 | } | |
2399 | ||
5cd89174 | 2400 | ld->SetImage(listctrl->OnGetItemImage(line)); |
6c02c329 | 2401 | ld->SetAttr(listctrl->OnGetItemAttr(line)); |
e1e955e1 | 2402 | } |
c801d85f | 2403 | |
b54e41c5 | 2404 | wxListLineData *wxListMainWindow::GetDummyLine() const |
c801d85f | 2405 | { |
cf1dfa6b | 2406 | wxASSERT_MSG( !IsEmpty(), _T("invalid line index") ); |
2c1f73ee | 2407 | |
904ccf52 VZ |
2408 | wxASSERT_MSG( IsVirtual(), _T("GetDummyLine() shouldn't be called") ); |
2409 | ||
2410 | wxListMainWindow *self = wxConstCast(this, wxListMainWindow); | |
2411 | ||
2412 | // we need to recreate the dummy line if the number of columns in the | |
2413 | // control changed as it would have the incorrect number of fields | |
2414 | // otherwise | |
2415 | if ( !m_lines.IsEmpty() && | |
2416 | m_lines[0].m_items.GetCount() != (size_t)GetColumnCount() ) | |
2c1f73ee | 2417 | { |
904ccf52 VZ |
2418 | self->m_lines.Clear(); |
2419 | } | |
cf1dfa6b | 2420 | |
904ccf52 VZ |
2421 | if ( m_lines.IsEmpty() ) |
2422 | { | |
5cd89174 | 2423 | wxListLineData *line = new wxListLineData(self); |
cf1dfa6b | 2424 | self->m_lines.Add(line); |
904ccf52 VZ |
2425 | |
2426 | // don't waste extra memory -- there never going to be anything | |
2427 | // else/more in this array | |
2428 | self->m_lines.Shrink(); | |
2c1f73ee VZ |
2429 | } |
2430 | ||
cf1dfa6b VZ |
2431 | return &m_lines[0]; |
2432 | } | |
2433 | ||
5cd89174 VZ |
2434 | // ---------------------------------------------------------------------------- |
2435 | // line geometry (report mode only) | |
2436 | // ---------------------------------------------------------------------------- | |
2437 | ||
cf1dfa6b VZ |
2438 | wxCoord wxListMainWindow::GetLineHeight() const |
2439 | { | |
2440 | wxASSERT_MSG( HasFlag(wxLC_REPORT), _T("only works in report mode") ); | |
673dfcfa | 2441 | |
cf1dfa6b VZ |
2442 | // we cache the line height as calling GetTextExtent() is slow |
2443 | if ( !m_lineHeight ) | |
2c1f73ee | 2444 | { |
cf1dfa6b | 2445 | wxListMainWindow *self = wxConstCast(this, wxListMainWindow); |
bd8289c1 | 2446 | |
cf1dfa6b VZ |
2447 | wxClientDC dc( self ); |
2448 | dc.SetFont( GetFont() ); | |
c801d85f | 2449 | |
cf1dfa6b VZ |
2450 | wxCoord y; |
2451 | dc.GetTextExtent(_T("H"), NULL, &y); | |
004fd0c8 | 2452 | |
cf1dfa6b VZ |
2453 | if ( y < SCROLL_UNIT_Y ) |
2454 | y = SCROLL_UNIT_Y; | |
2455 | y += EXTRA_HEIGHT; | |
206b0a67 | 2456 | |
cf1dfa6b VZ |
2457 | self->m_lineHeight = y + LINE_SPACING; |
2458 | } | |
bffa1c77 | 2459 | |
cf1dfa6b VZ |
2460 | return m_lineHeight; |
2461 | } | |
bffa1c77 | 2462 | |
cf1dfa6b VZ |
2463 | wxCoord wxListMainWindow::GetLineY(size_t line) const |
2464 | { | |
2465 | wxASSERT_MSG( HasFlag(wxLC_REPORT), _T("only works in report mode") ); | |
1370703e | 2466 | |
cf1dfa6b VZ |
2467 | return LINE_SPACING + line*GetLineHeight(); |
2468 | } | |
206b0a67 | 2469 | |
5cd89174 VZ |
2470 | wxRect wxListMainWindow::GetLineRect(size_t line) const |
2471 | { | |
2472 | if ( !InReportView() ) | |
2473 | return GetLine(line)->m_gi->m_rectAll; | |
2474 | ||
2475 | wxRect rect; | |
2476 | rect.x = HEADER_OFFSET_X; | |
2477 | rect.y = GetLineY(line); | |
2478 | rect.width = GetHeaderWidth(); | |
2479 | rect.height = GetLineHeight(); | |
2480 | ||
2481 | return rect; | |
2482 | } | |
2483 | ||
2484 | wxRect wxListMainWindow::GetLineLabelRect(size_t line) const | |
2485 | { | |
2486 | if ( !InReportView() ) | |
2487 | return GetLine(line)->m_gi->m_rectLabel; | |
2488 | ||
2489 | wxRect rect; | |
2490 | rect.x = HEADER_OFFSET_X; | |
2491 | rect.y = GetLineY(line); | |
2492 | rect.width = GetColumnWidth(0); | |
2493 | rect.height = GetLineHeight(); | |
2494 | ||
2495 | return rect; | |
2496 | } | |
2497 | ||
2498 | wxRect wxListMainWindow::GetLineIconRect(size_t line) const | |
2499 | { | |
2500 | if ( !InReportView() ) | |
2501 | return GetLine(line)->m_gi->m_rectIcon; | |
2502 | ||
2503 | wxListLineData *ld = GetLine(line); | |
2504 | wxASSERT_MSG( ld->HasImage(), _T("should have an image") ); | |
2505 | ||
2506 | wxRect rect; | |
2507 | rect.x = HEADER_OFFSET_X; | |
2508 | rect.y = GetLineY(line); | |
2509 | GetImageSize(ld->GetImage(), rect.width, rect.height); | |
2510 | ||
2511 | return rect; | |
2512 | } | |
2513 | ||
2514 | wxRect wxListMainWindow::GetLineHighlightRect(size_t line) const | |
2515 | { | |
2516 | return InReportView() ? GetLineRect(line) | |
2517 | : GetLine(line)->m_gi->m_rectHighlight; | |
2518 | } | |
2519 | ||
2520 | long wxListMainWindow::HitTestLine(size_t line, int x, int y) const | |
2521 | { | |
fc4f1d5f VZ |
2522 | wxASSERT_MSG( line < GetItemCount(), _T("invalid line in HitTestLine") ); |
2523 | ||
5cd89174 VZ |
2524 | wxListLineData *ld = GetLine(line); |
2525 | ||
2526 | if ( ld->HasImage() && GetLineIconRect(line).Inside(x, y) ) | |
2527 | return wxLIST_HITTEST_ONITEMICON; | |
2528 | ||
acf4d858 VS |
2529 | // VS: Testing for "ld->HasText() || InReportView()" instead of |
2530 | // "ld->HasText()" is needed to make empty lines in report view | |
2531 | // possible | |
2532 | if ( ld->HasText() || InReportView() ) | |
5cd89174 VZ |
2533 | { |
2534 | wxRect rect = InReportView() ? GetLineRect(line) | |
2535 | : GetLineLabelRect(line); | |
2536 | ||
2537 | if ( rect.Inside(x, y) ) | |
2538 | return wxLIST_HITTEST_ONITEMLABEL; | |
2539 | } | |
2540 | ||
2541 | return 0; | |
2542 | } | |
2543 | ||
2544 | // ---------------------------------------------------------------------------- | |
2545 | // highlight (selection) handling | |
2546 | // ---------------------------------------------------------------------------- | |
2547 | ||
b54e41c5 | 2548 | bool wxListMainWindow::IsHighlighted(size_t line) const |
cf1dfa6b VZ |
2549 | { |
2550 | if ( IsVirtual() ) | |
2551 | { | |
b54e41c5 | 2552 | return m_selStore.IsSelected(line); |
cf1dfa6b VZ |
2553 | } |
2554 | else // !virtual | |
2555 | { | |
2556 | wxListLineData *ld = GetLine(line); | |
b54e41c5 | 2557 | wxCHECK_MSG( ld, FALSE, _T("invalid index in IsHighlighted") ); |
cf1dfa6b | 2558 | |
b54e41c5 | 2559 | return ld->IsHighlighted(); |
cf1dfa6b VZ |
2560 | } |
2561 | } | |
2562 | ||
68a9ef0e VZ |
2563 | void wxListMainWindow::HighlightLines( size_t lineFrom, |
2564 | size_t lineTo, | |
2565 | bool highlight ) | |
cf1dfa6b | 2566 | { |
cf1dfa6b VZ |
2567 | if ( IsVirtual() ) |
2568 | { | |
68a9ef0e VZ |
2569 | wxArrayInt linesChanged; |
2570 | if ( !m_selStore.SelectRange(lineFrom, lineTo, highlight, | |
2571 | &linesChanged) ) | |
2572 | { | |
2573 | // meny items changed state, refresh everything | |
2574 | RefreshLines(lineFrom, lineTo); | |
2575 | } | |
2576 | else // only a few items changed state, refresh only them | |
2577 | { | |
2578 | size_t count = linesChanged.GetCount(); | |
2579 | for ( size_t n = 0; n < count; n++ ) | |
2580 | { | |
2581 | RefreshLine(linesChanged[n]); | |
2582 | } | |
2583 | } | |
b54e41c5 | 2584 | } |
68a9ef0e | 2585 | else // iterate over all items in non report view |
b54e41c5 | 2586 | { |
b54e41c5 | 2587 | for ( size_t line = lineFrom; line <= lineTo; line++ ) |
cf1dfa6b | 2588 | { |
b54e41c5 | 2589 | if ( HighlightLine(line, highlight) ) |
68a9ef0e VZ |
2590 | { |
2591 | RefreshLine(line); | |
2592 | } | |
cf1dfa6b | 2593 | } |
b54e41c5 VZ |
2594 | } |
2595 | } | |
2596 | ||
2597 | bool wxListMainWindow::HighlightLine( size_t line, bool highlight ) | |
2598 | { | |
2599 | bool changed; | |
2600 | ||
2601 | if ( IsVirtual() ) | |
2602 | { | |
2603 | changed = m_selStore.SelectItem(line, highlight); | |
cf1dfa6b VZ |
2604 | } |
2605 | else // !virtual | |
2606 | { | |
2607 | wxListLineData *ld = GetLine(line); | |
49ecb029 | 2608 | wxCHECK_MSG( ld, FALSE, _T("invalid index in HighlightLine") ); |
cf1dfa6b | 2609 | |
b54e41c5 | 2610 | changed = ld->Highlight(highlight); |
cf1dfa6b VZ |
2611 | } |
2612 | ||
2613 | if ( changed ) | |
2614 | { | |
b54e41c5 | 2615 | SendNotify( line, highlight ? wxEVT_COMMAND_LIST_ITEM_SELECTED |
5cd89174 | 2616 | : wxEVT_COMMAND_LIST_ITEM_DESELECTED ); |
cf1dfa6b VZ |
2617 | } |
2618 | ||
2619 | return changed; | |
2620 | } | |
2621 | ||
2622 | void wxListMainWindow::RefreshLine( size_t line ) | |
2623 | { | |
6ea1323a VZ |
2624 | if ( HasFlag(wxLC_REPORT) ) |
2625 | { | |
2626 | size_t visibleFrom, visibleTo; | |
2627 | GetVisibleLinesRange(&visibleFrom, &visibleTo); | |
c1c4c551 | 2628 | |
6ea1323a VZ |
2629 | if ( line < visibleFrom || line > visibleTo ) |
2630 | return; | |
2631 | } | |
c1c4c551 | 2632 | |
5cd89174 | 2633 | wxRect rect = GetLineRect(line); |
cf1dfa6b VZ |
2634 | |
2635 | CalcScrolledPosition( rect.x, rect.y, &rect.x, &rect.y ); | |
2636 | RefreshRect( rect ); | |
2637 | } | |
2638 | ||
2639 | void wxListMainWindow::RefreshLines( size_t lineFrom, size_t lineTo ) | |
2640 | { | |
2641 | // we suppose that they are ordered by caller | |
2642 | wxASSERT_MSG( lineFrom <= lineTo, _T("indices in disorder") ); | |
2643 | ||
6b4a8d93 VZ |
2644 | wxASSERT_MSG( lineTo < GetItemCount(), _T("invalid line range") ); |
2645 | ||
cf1dfa6b VZ |
2646 | if ( HasFlag(wxLC_REPORT) ) |
2647 | { | |
b54e41c5 VZ |
2648 | size_t visibleFrom, visibleTo; |
2649 | GetVisibleLinesRange(&visibleFrom, &visibleTo); | |
2650 | ||
2651 | if ( lineFrom < visibleFrom ) | |
2652 | lineFrom = visibleFrom; | |
2653 | if ( lineTo > visibleTo ) | |
2654 | lineTo = visibleTo; | |
cf1dfa6b VZ |
2655 | |
2656 | wxRect rect; | |
2657 | rect.x = 0; | |
2658 | rect.y = GetLineY(lineFrom); | |
2659 | rect.width = GetClientSize().x; | |
91c6cc0e | 2660 | rect.height = GetLineY(lineTo) - rect.y + GetLineHeight(); |
cf1dfa6b VZ |
2661 | |
2662 | CalcScrolledPosition( rect.x, rect.y, &rect.x, &rect.y ); | |
2663 | RefreshRect( rect ); | |
2664 | } | |
2665 | else // !report | |
2666 | { | |
2667 | // TODO: this should be optimized... | |
2668 | for ( size_t line = lineFrom; line <= lineTo; line++ ) | |
2669 | { | |
2670 | RefreshLine(line); | |
2671 | } | |
2672 | } | |
2673 | } | |
2674 | ||
6b4a8d93 VZ |
2675 | void wxListMainWindow::RefreshAfter( size_t lineFrom ) |
2676 | { | |
2677 | if ( HasFlag(wxLC_REPORT) ) | |
2678 | { | |
c29582d0 JS |
2679 | size_t visibleFrom, visibleTo; |
2680 | GetVisibleLinesRange(&visibleFrom, &visibleTo); | |
6b4a8d93 VZ |
2681 | |
2682 | if ( lineFrom < visibleFrom ) | |
2683 | lineFrom = visibleFrom; | |
c29582d0 JS |
2684 | else if ( lineFrom > visibleTo ) |
2685 | return; | |
6b4a8d93 VZ |
2686 | |
2687 | wxRect rect; | |
2688 | rect.x = 0; | |
2689 | rect.y = GetLineY(lineFrom); | |
c29582d0 | 2690 | CalcScrolledPosition( rect.x, rect.y, &rect.x, &rect.y ); |
6b4a8d93 VZ |
2691 | |
2692 | wxSize size = GetClientSize(); | |
2693 | rect.width = size.x; | |
2694 | // refresh till the bottom of the window | |
2695 | rect.height = size.y - rect.y; | |
2696 | ||
6b4a8d93 | 2697 | RefreshRect( rect ); |
6b4a8d93 VZ |
2698 | } |
2699 | else // !report | |
2700 | { | |
2701 | // TODO: how to do it more efficiently? | |
2702 | m_dirty = TRUE; | |
2703 | } | |
2704 | } | |
2705 | ||
49ecb029 VZ |
2706 | void wxListMainWindow::RefreshSelected() |
2707 | { | |
2708 | if ( IsEmpty() ) | |
2709 | return; | |
2710 | ||
2711 | size_t from, to; | |
2712 | if ( InReportView() ) | |
2713 | { | |
2714 | GetVisibleLinesRange(&from, &to); | |
2715 | } | |
2716 | else // !virtual | |
2717 | { | |
2718 | from = 0; | |
2719 | to = GetItemCount() - 1; | |
2720 | } | |
2721 | ||
cf30ae13 | 2722 | if ( HasCurrent() && m_current >= from && m_current <= to ) |
49ecb029 VZ |
2723 | { |
2724 | RefreshLine(m_current); | |
2725 | } | |
2726 | ||
2727 | for ( size_t line = from; line <= to; line++ ) | |
2728 | { | |
2729 | // NB: the test works as expected even if m_current == -1 | |
2730 | if ( line != m_current && IsHighlighted(line) ) | |
2731 | { | |
2732 | RefreshLine(line); | |
2733 | } | |
2734 | } | |
2735 | } | |
2736 | ||
c5c528fc VZ |
2737 | void wxListMainWindow::Freeze() |
2738 | { | |
2739 | m_freezeCount++; | |
2740 | } | |
2741 | ||
2742 | void wxListMainWindow::Thaw() | |
2743 | { | |
2744 | wxCHECK_RET( m_freezeCount > 0, _T("thawing unfrozen list control?") ); | |
2745 | ||
2746 | if ( !--m_freezeCount ) | |
2747 | { | |
2748 | Refresh(); | |
2749 | } | |
2750 | } | |
2751 | ||
cf1dfa6b VZ |
2752 | void wxListMainWindow::OnPaint( wxPaintEvent &WXUNUSED(event) ) |
2753 | { | |
2754 | // Note: a wxPaintDC must be constructed even if no drawing is | |
2755 | // done (a Windows requirement). | |
2756 | wxPaintDC dc( this ); | |
2757 | ||
c5c528fc | 2758 | if ( IsEmpty() || m_freezeCount ) |
cf1dfa6b | 2759 | { |
c5c528fc | 2760 | // nothing to draw or not the moment to draw it |
cf1dfa6b VZ |
2761 | return; |
2762 | } | |
2763 | ||
1e4d446b VZ |
2764 | if ( m_dirty ) |
2765 | { | |
2766 | // delay the repainting until we calculate all the items positions | |
2767 | return; | |
2768 | } | |
2769 | ||
cf1dfa6b VZ |
2770 | PrepareDC( dc ); |
2771 | ||
2772 | int dev_x, dev_y; | |
2773 | CalcScrolledPosition( 0, 0, &dev_x, &dev_y ); | |
2774 | ||
2775 | dc.BeginDrawing(); | |
2776 | ||
2777 | dc.SetFont( GetFont() ); | |
2778 | ||
2779 | if ( HasFlag(wxLC_REPORT) ) | |
2780 | { | |
b54e41c5 | 2781 | int lineHeight = GetLineHeight(); |
cf1dfa6b | 2782 | |
b54e41c5 VZ |
2783 | size_t visibleFrom, visibleTo; |
2784 | GetVisibleLinesRange(&visibleFrom, &visibleTo); | |
b84839ae VZ |
2785 | |
2786 | wxRect rectLine; | |
2787 | wxCoord xOrig, yOrig; | |
2788 | CalcUnscrolledPosition(0, 0, &xOrig, &yOrig); | |
2789 | ||
ff3d11a0 | 2790 | // tell the caller cache to cache the data |
91c6cc0e VZ |
2791 | if ( IsVirtual() ) |
2792 | { | |
2793 | wxListEvent evCache(wxEVT_COMMAND_LIST_CACHE_HINT, | |
2794 | GetParent()->GetId()); | |
2795 | evCache.SetEventObject( GetParent() ); | |
2796 | evCache.m_oldItemIndex = visibleFrom; | |
2797 | evCache.m_itemIndex = visibleTo; | |
2798 | GetParent()->GetEventHandler()->ProcessEvent( evCache ); | |
2799 | } | |
ff3d11a0 | 2800 | |
b54e41c5 | 2801 | for ( size_t line = visibleFrom; line <= visibleTo; line++ ) |
cf1dfa6b | 2802 | { |
b84839ae VZ |
2803 | rectLine = GetLineRect(line); |
2804 | ||
2805 | if ( !IsExposed(rectLine.x - xOrig, rectLine.y - yOrig, | |
2806 | rectLine.width, rectLine.height) ) | |
2807 | { | |
2808 | // don't redraw unaffected lines to avoid flicker | |
2809 | continue; | |
2810 | } | |
2811 | ||
5cd89174 | 2812 | GetLine(line)->DrawInReportMode( &dc, |
b84839ae | 2813 | rectLine, |
5cd89174 | 2814 | GetLineHighlightRect(line), |
49ecb029 | 2815 | IsHighlighted(line) ); |
cf1dfa6b VZ |
2816 | } |
2817 | ||
2818 | if ( HasFlag(wxLC_HRULES) ) | |
2819 | { | |
b54e41c5 | 2820 | wxPen pen(GetRuleColour(), 1, wxSOLID); |
cf1dfa6b VZ |
2821 | wxSize clientSize = GetClientSize(); |
2822 | ||
b54e41c5 | 2823 | for ( size_t i = visibleFrom; i <= visibleTo; i++ ) |
cf1dfa6b VZ |
2824 | { |
2825 | dc.SetPen(pen); | |
2826 | dc.SetBrush( *wxTRANSPARENT_BRUSH ); | |
b54e41c5 VZ |
2827 | dc.DrawLine(0 - dev_x, i*lineHeight, |
2828 | clientSize.x - dev_x, i*lineHeight); | |
cf1dfa6b VZ |
2829 | } |
2830 | ||
2831 | // Draw last horizontal rule | |
b54e41c5 | 2832 | if ( visibleTo > visibleFrom ) |
cf1dfa6b VZ |
2833 | { |
2834 | dc.SetPen(pen); | |
2835 | dc.SetBrush( *wxTRANSPARENT_BRUSH ); | |
b54e41c5 VZ |
2836 | dc.DrawLine(0 - dev_x, m_lineTo*lineHeight, |
2837 | clientSize.x - dev_x , m_lineTo*lineHeight ); | |
cf1dfa6b | 2838 | } |
2c1f73ee | 2839 | } |
206b0a67 JS |
2840 | |
2841 | // Draw vertical rules if required | |
cf1dfa6b | 2842 | if ( HasFlag(wxLC_VRULES) && !IsEmpty() ) |
206b0a67 | 2843 | { |
b54e41c5 | 2844 | wxPen pen(GetRuleColour(), 1, wxSOLID); |
cf1dfa6b | 2845 | |
206b0a67 JS |
2846 | int col = 0; |
2847 | wxRect firstItemRect; | |
2848 | wxRect lastItemRect; | |
2849 | GetItemRect(0, firstItemRect); | |
2850 | GetItemRect(GetItemCount() - 1, lastItemRect); | |
2851 | int x = firstItemRect.GetX(); | |
673dfcfa JS |
2852 | dc.SetPen(pen); |
2853 | dc.SetBrush(* wxTRANSPARENT_BRUSH); | |
206b0a67 JS |
2854 | for (col = 0; col < GetColumnCount(); col++) |
2855 | { | |
2856 | int colWidth = GetColumnWidth(col); | |
cf1dfa6b VZ |
2857 | x += colWidth; |
2858 | dc.DrawLine(x - dev_x, firstItemRect.GetY() - 1 - dev_y, | |
2859 | x - dev_x, lastItemRect.GetBottom() + 1 - dev_y); | |
206b0a67 | 2860 | } |
d786bf87 | 2861 | } |
139adb6a | 2862 | } |
cf1dfa6b | 2863 | else // !report |
139adb6a | 2864 | { |
1370703e | 2865 | size_t count = GetItemCount(); |
cf1dfa6b VZ |
2866 | for ( size_t i = 0; i < count; i++ ) |
2867 | { | |
2868 | GetLine(i)->Draw( &dc ); | |
2869 | } | |
139adb6a | 2870 | } |
004fd0c8 | 2871 | |
c25f61f1 | 2872 | if ( HasCurrent() ) |
cf1dfa6b | 2873 | { |
c25f61f1 | 2874 | // don't draw rect outline under Max if we already have the background |
49ecb029 VZ |
2875 | // color but under other platforms only draw it if we do: it is a bit |
2876 | // silly to draw "focus rect" if we don't have focus! | |
4176fb7d | 2877 | #ifdef __WXMAC__ |
c25f61f1 | 2878 | if ( !m_hasFocus ) |
49ecb029 VZ |
2879 | #else // !__WXMAC__ |
2880 | if ( m_hasFocus ) | |
2881 | #endif // __WXMAC__/!__WXMAC__ | |
c25f61f1 VZ |
2882 | { |
2883 | dc.SetPen( *wxBLACK_PEN ); | |
2884 | dc.SetBrush( *wxTRANSPARENT_BRUSH ); | |
2885 | dc.DrawRectangle( GetLineHighlightRect(m_current) ); | |
2886 | } | |
cf1dfa6b | 2887 | } |
c801d85f | 2888 | |
139adb6a | 2889 | dc.EndDrawing(); |
e1e955e1 | 2890 | } |
c801d85f | 2891 | |
b54e41c5 | 2892 | void wxListMainWindow::HighlightAll( bool on ) |
c801d85f | 2893 | { |
b54e41c5 | 2894 | if ( IsSingleSel() ) |
c801d85f | 2895 | { |
b54e41c5 VZ |
2896 | wxASSERT_MSG( !on, _T("can't do this in a single sel control") ); |
2897 | ||
2898 | // we just have one item to turn off | |
2899 | if ( HasCurrent() && IsHighlighted(m_current) ) | |
139adb6a | 2900 | { |
b54e41c5 VZ |
2901 | HighlightLine(m_current, FALSE); |
2902 | RefreshLine(m_current); | |
139adb6a | 2903 | } |
e1e955e1 | 2904 | } |
b54e41c5 | 2905 | else // multi sel |
cf1dfa6b | 2906 | { |
b54e41c5 | 2907 | HighlightLines(0, GetItemCount() - 1, on); |
cf1dfa6b | 2908 | } |
e1e955e1 | 2909 | } |
c801d85f | 2910 | |
cf1dfa6b | 2911 | void wxListMainWindow::SendNotify( size_t line, |
05a7f61d VZ |
2912 | wxEventType command, |
2913 | wxPoint point ) | |
c801d85f | 2914 | { |
139adb6a RR |
2915 | wxListEvent le( command, GetParent()->GetId() ); |
2916 | le.SetEventObject( GetParent() ); | |
cf1dfa6b | 2917 | le.m_itemIndex = line; |
05a7f61d VZ |
2918 | |
2919 | // set only for events which have position | |
2920 | if ( point != wxDefaultPosition ) | |
2921 | le.m_pointDrag = point; | |
2922 | ||
c1c4c551 VZ |
2923 | // don't try to get the line info for virtual list controls: the main |
2924 | // program has it anyhow and if we did it would result in accessing all | |
2925 | // the lines, even those which are not visible now and this is precisely | |
2926 | // what we're trying to avoid | |
2927 | if ( !IsVirtual() && (command != wxEVT_COMMAND_LIST_DELETE_ITEM) ) | |
91c6cc0e | 2928 | { |
0ddefeb0 VZ |
2929 | if ( line != (size_t)-1 ) |
2930 | { | |
2931 | GetLine(line)->GetItem( 0, le.m_item ); | |
2932 | } | |
2933 | //else: this happens for wxEVT_COMMAND_LIST_ITEM_FOCUSED event | |
91c6cc0e VZ |
2934 | } |
2935 | //else: there may be no more such item | |
2936 | ||
6e228e42 | 2937 | GetParent()->GetEventHandler()->ProcessEvent( le ); |
e1e955e1 | 2938 | } |
c801d85f | 2939 | |
0ddefeb0 | 2940 | void wxListMainWindow::ChangeCurrent(size_t current) |
c801d85f | 2941 | { |
0ddefeb0 | 2942 | m_current = current; |
c801d85f | 2943 | |
0ddefeb0 | 2944 | SendNotify(current, wxEVT_COMMAND_LIST_ITEM_FOCUSED); |
e1e955e1 | 2945 | } |
c801d85f | 2946 | |
5f1ea0ee | 2947 | void wxListMainWindow::EditLabel( long item ) |
c801d85f | 2948 | { |
cf1dfa6b | 2949 | wxCHECK_RET( (item >= 0) && ((size_t)item < GetItemCount()), |
3cd94a0d | 2950 | wxT("wrong index in wxGenericListCtrl::EditLabel()") ); |
004fd0c8 | 2951 | |
62d89eb4 | 2952 | size_t itemEdit = (size_t)item; |
e179bd65 | 2953 | |
fd9811b1 | 2954 | wxListEvent le( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT, GetParent()->GetId() ); |
139adb6a | 2955 | le.SetEventObject( GetParent() ); |
1370703e | 2956 | le.m_itemIndex = item; |
62d89eb4 | 2957 | wxListLineData *data = GetLine(itemEdit); |
1370703e VZ |
2958 | wxCHECK_RET( data, _T("invalid index in EditLabel()") ); |
2959 | data->GetItem( 0, le.m_item ); | |
62d89eb4 VZ |
2960 | if ( GetParent()->GetEventHandler()->ProcessEvent( le ) && !le.IsAllowed() ) |
2961 | { | |
2962 | // vetoed by user code | |
5f1ea0ee | 2963 | return; |
62d89eb4 | 2964 | } |
004fd0c8 | 2965 | |
cf1dfa6b VZ |
2966 | // We have to call this here because the label in question might just have |
2967 | // been added and no screen update taken place. | |
62d89eb4 | 2968 | if ( m_dirty ) |
cf1dfa6b | 2969 | wxSafeYield(); |
004fd0c8 | 2970 | |
62d89eb4 VZ |
2971 | wxListTextCtrl *text = new wxListTextCtrl(this, itemEdit); |
2972 | ||
92976ab6 | 2973 | text->SetFocus(); |
e1e955e1 | 2974 | } |
c801d85f | 2975 | |
e179bd65 RR |
2976 | void wxListMainWindow::OnRenameTimer() |
2977 | { | |
cf1dfa6b | 2978 | wxCHECK_RET( HasCurrent(), wxT("unexpected rename timer") ); |
004fd0c8 | 2979 | |
cf1dfa6b | 2980 | EditLabel( m_current ); |
e179bd65 RR |
2981 | } |
2982 | ||
62d89eb4 | 2983 | bool wxListMainWindow::OnRenameAccept(size_t itemEdit, const wxString& value) |
c801d85f | 2984 | { |
e179bd65 RR |
2985 | wxListEvent le( wxEVT_COMMAND_LIST_END_LABEL_EDIT, GetParent()->GetId() ); |
2986 | le.SetEventObject( GetParent() ); | |
62d89eb4 | 2987 | le.m_itemIndex = itemEdit; |
1370703e | 2988 | |
62d89eb4 VZ |
2989 | wxListLineData *data = GetLine(itemEdit); |
2990 | wxCHECK_MSG( data, FALSE, _T("invalid index in OnRenameAccept()") ); | |
1370703e VZ |
2991 | |
2992 | data->GetItem( 0, le.m_item ); | |
62d89eb4 VZ |
2993 | le.m_item.m_text = value; |
2994 | return !GetParent()->GetEventHandler()->ProcessEvent( le ) || | |
2995 | le.IsAllowed(); | |
e1e955e1 | 2996 | } |
c801d85f KB |
2997 | |
2998 | void wxListMainWindow::OnMouse( wxMouseEvent &event ) | |
2999 | { | |
3e1c4e00 | 3000 | event.SetEventObject( GetParent() ); |
cf1dfa6b VZ |
3001 | if ( GetParent()->GetEventHandler()->ProcessEvent( event) ) |
3002 | return; | |
3003 | ||
3004 | if ( !HasCurrent() || IsEmpty() ) | |
3005 | return; | |
3006 | ||
3007 | if (m_dirty) | |
3008 | return; | |
e3e65dac | 3009 | |
cf1dfa6b VZ |
3010 | if ( !(event.Dragging() || event.ButtonDown() || event.LeftUp() || |
3011 | event.ButtonDClick()) ) | |
3012 | return; | |
c801d85f | 3013 | |
aaef15bf RR |
3014 | int x = event.GetX(); |
3015 | int y = event.GetY(); | |
3016 | CalcUnscrolledPosition( x, y, &x, &y ); | |
004fd0c8 | 3017 | |
cc734310 | 3018 | // where did we hit it (if we did)? |
92976ab6 | 3019 | long hitResult = 0; |
1370703e | 3020 | |
cf1dfa6b VZ |
3021 | size_t count = GetItemCount(), |
3022 | current; | |
3023 | ||
3024 | if ( HasFlag(wxLC_REPORT) ) | |
92976ab6 | 3025 | { |
5cd89174 | 3026 | current = y / GetLineHeight(); |
cc734310 VZ |
3027 | if ( current < count ) |
3028 | hitResult = HitTestLine(current, x, y); | |
cf1dfa6b VZ |
3029 | } |
3030 | else // !report | |
3031 | { | |
3032 | // TODO: optimize it too! this is less simple than for report view but | |
3033 | // enumerating all items is still not a way to do it!! | |
4e3ace65 | 3034 | for ( current = 0; current < count; current++ ) |
cf1dfa6b | 3035 | { |
5cd89174 | 3036 | hitResult = HitTestLine(current, x, y); |
4e3ace65 VZ |
3037 | if ( hitResult ) |
3038 | break; | |
cf1dfa6b | 3039 | } |
92976ab6 | 3040 | } |
bd8289c1 | 3041 | |
fd9811b1 | 3042 | if (event.Dragging()) |
92976ab6 | 3043 | { |
fd9811b1 | 3044 | if (m_dragCount == 0) |
8d1d2284 VZ |
3045 | { |
3046 | // we have to report the raw, physical coords as we want to be | |
3047 | // able to call HitTest(event.m_pointDrag) from the user code to | |
3048 | // get the item being dragged | |
3049 | m_dragStart = event.GetPosition(); | |
3050 | } | |
bffa1c77 | 3051 | |
fd9811b1 | 3052 | m_dragCount++; |
bffa1c77 | 3053 | |
cf1dfa6b VZ |
3054 | if (m_dragCount != 3) |
3055 | return; | |
bffa1c77 | 3056 | |
05a7f61d VZ |
3057 | int command = event.RightIsDown() ? wxEVT_COMMAND_LIST_BEGIN_RDRAG |
3058 | : wxEVT_COMMAND_LIST_BEGIN_DRAG; | |
bffa1c77 | 3059 | |
fd9811b1 | 3060 | wxListEvent le( command, GetParent()->GetId() ); |
92976ab6 | 3061 | le.SetEventObject( GetParent() ); |
bffa1c77 VZ |
3062 | le.m_pointDrag = m_dragStart; |
3063 | GetParent()->GetEventHandler()->ProcessEvent( le ); | |
3064 | ||
3065 | return; | |
92976ab6 | 3066 | } |
fd9811b1 RR |
3067 | else |
3068 | { | |
3069 | m_dragCount = 0; | |
3070 | } | |
bd8289c1 | 3071 | |
cf1dfa6b VZ |
3072 | if ( !hitResult ) |
3073 | { | |
3074 | // outside of any item | |
3075 | return; | |
3076 | } | |
bd8289c1 | 3077 | |
efbb7287 | 3078 | bool forceClick = FALSE; |
92976ab6 RR |
3079 | if (event.ButtonDClick()) |
3080 | { | |
92976ab6 | 3081 | m_renameTimer->Stop(); |
efbb7287 VZ |
3082 | m_lastOnSame = FALSE; |
3083 | ||
ddba340d VS |
3084 | #ifdef __WXGTK__ |
3085 | // FIXME: wxGTK generates bad sequence of events prior to doubleclick | |
a77ec46d | 3086 | // ("down, up, down, double, up" while other ports |
ddba340d VS |
3087 | // do "down, up, double, up"). We have to have this hack |
3088 | // in place till somebody fixes wxGTK... | |
cf1dfa6b | 3089 | if ( current == m_lineBeforeLastClicked ) |
ddba340d VS |
3090 | #else |
3091 | if ( current == m_lineLastClicked ) | |
3092 | #endif | |
efbb7287 | 3093 | { |
cf1dfa6b | 3094 | SendNotify( current, wxEVT_COMMAND_LIST_ITEM_ACTIVATED ); |
004fd0c8 | 3095 | |
efbb7287 VZ |
3096 | return; |
3097 | } | |
3098 | else | |
3099 | { | |
3100 | // the first click was on another item, so don't interpret this as | |
3101 | // a double click, but as a simple click instead | |
3102 | forceClick = TRUE; | |
3103 | } | |
92976ab6 | 3104 | } |
bd8289c1 | 3105 | |
92976ab6 | 3106 | if (event.LeftUp() && m_lastOnSame) |
c801d85f | 3107 | { |
cf1dfa6b | 3108 | if ((current == m_current) && |
92976ab6 | 3109 | (hitResult == wxLIST_HITTEST_ONITEMLABEL) && |
cf1dfa6b | 3110 | HasFlag(wxLC_EDIT_LABELS) ) |
92976ab6 RR |
3111 | { |
3112 | m_renameTimer->Start( 100, TRUE ); | |
3113 | } | |
3114 | m_lastOnSame = FALSE; | |
e1e955e1 | 3115 | } |
cf1dfa6b | 3116 | else if (event.RightDown()) |
b204641e | 3117 | { |
cf1dfa6b | 3118 | SendNotify( current, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK, |
05a7f61d | 3119 | event.GetPosition() ); |
b204641e | 3120 | } |
cf1dfa6b | 3121 | else if (event.MiddleDown()) |
b204641e | 3122 | { |
cf1dfa6b | 3123 | SendNotify( current, wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK ); |
92976ab6 | 3124 | } |
cf1dfa6b | 3125 | else if ( event.LeftDown() || forceClick ) |
92976ab6 | 3126 | { |
efbb7287 | 3127 | m_lineBeforeLastClicked = m_lineLastClicked; |
cf1dfa6b VZ |
3128 | m_lineLastClicked = current; |
3129 | ||
3130 | size_t oldCurrent = m_current; | |
efbb7287 | 3131 | |
b54e41c5 | 3132 | if ( IsSingleSel() || !(event.ControlDown() || event.ShiftDown()) ) |
b204641e | 3133 | { |
b54e41c5 | 3134 | HighlightAll( FALSE ); |
0ddefeb0 VZ |
3135 | |
3136 | ChangeCurrent(current); | |
cf1dfa6b | 3137 | |
b54e41c5 | 3138 | ReverseHighlight(m_current); |
e1e955e1 | 3139 | } |
b54e41c5 | 3140 | else // multi sel & either ctrl or shift is down |
b204641e | 3141 | { |
473d087e | 3142 | if (event.ControlDown()) |
92976ab6 | 3143 | { |
0ddefeb0 | 3144 | ChangeCurrent(current); |
cf1dfa6b | 3145 | |
b54e41c5 | 3146 | ReverseHighlight(m_current); |
92976ab6 | 3147 | } |
473d087e | 3148 | else if (event.ShiftDown()) |
92976ab6 | 3149 | { |
0ddefeb0 | 3150 | ChangeCurrent(current); |
bffa1c77 | 3151 | |
cf1dfa6b VZ |
3152 | size_t lineFrom = oldCurrent, |
3153 | lineTo = current; | |
f6bcfd97 | 3154 | |
cf1dfa6b | 3155 | if ( lineTo < lineFrom ) |
92976ab6 | 3156 | { |
cf1dfa6b VZ |
3157 | lineTo = lineFrom; |
3158 | lineFrom = m_current; | |
92976ab6 RR |
3159 | } |
3160 | ||
b54e41c5 | 3161 | HighlightLines(lineFrom, lineTo); |
92976ab6 | 3162 | } |
cf1dfa6b | 3163 | else // !ctrl, !shift |
92976ab6 | 3164 | { |
cf1dfa6b VZ |
3165 | // test in the enclosing if should make it impossible |
3166 | wxFAIL_MSG( _T("how did we get here?") ); | |
92976ab6 | 3167 | } |
e1e955e1 | 3168 | } |
cf1dfa6b | 3169 | |
92976ab6 RR |
3170 | if (m_current != oldCurrent) |
3171 | { | |
3172 | RefreshLine( oldCurrent ); | |
92976ab6 | 3173 | } |
efbb7287 VZ |
3174 | |
3175 | // forceClick is only set if the previous click was on another item | |
3176 | m_lastOnSame = !forceClick && (m_current == oldCurrent); | |
e1e955e1 | 3177 | } |
e1e955e1 | 3178 | } |
c801d85f | 3179 | |
34bbbc27 | 3180 | void wxListMainWindow::MoveToItem(size_t item) |
c801d85f | 3181 | { |
34bbbc27 | 3182 | if ( item == (size_t)-1 ) |
cf1dfa6b | 3183 | return; |
004fd0c8 | 3184 | |
34bbbc27 | 3185 | wxRect rect = GetLineRect(item); |
cf3da716 | 3186 | |
cf1dfa6b | 3187 | int client_w, client_h; |
cf3da716 | 3188 | GetClientSize( &client_w, &client_h ); |
f6bcfd97 | 3189 | |
cf3da716 RR |
3190 | int view_x = m_xScroll*GetScrollPos( wxHORIZONTAL ); |
3191 | int view_y = m_yScroll*GetScrollPos( wxVERTICAL ); | |
004fd0c8 | 3192 | |
cf1dfa6b | 3193 | if ( HasFlag(wxLC_REPORT) ) |
92976ab6 | 3194 | { |
b54e41c5 VZ |
3195 | // the next we need the range of lines shown it might be different, so |
3196 | // recalculate it | |
3197 | ResetVisibleLinesRange(); | |
3198 | ||
cf1dfa6b VZ |
3199 | if (rect.y < view_y ) |
3200 | Scroll( -1, rect.y/m_yScroll ); | |
3201 | if (rect.y+rect.height+5 > view_y+client_h) | |
3202 | Scroll( -1, (rect.y+rect.height-client_h+SCROLL_UNIT_Y)/m_yScroll ); | |
92976ab6 | 3203 | } |
b54e41c5 | 3204 | else // !report |
92976ab6 | 3205 | { |
cf1dfa6b VZ |
3206 | if (rect.x-view_x < 5) |
3207 | Scroll( (rect.x-5)/m_xScroll, -1 ); | |
3208 | if (rect.x+rect.width-5 > view_x+client_w) | |
3209 | Scroll( (rect.x+rect.width-client_w+SCROLL_UNIT_X)/m_xScroll, -1 ); | |
92976ab6 | 3210 | } |
e1e955e1 | 3211 | } |
c801d85f | 3212 | |
cf1dfa6b VZ |
3213 | // ---------------------------------------------------------------------------- |
3214 | // keyboard handling | |
3215 | // ---------------------------------------------------------------------------- | |
3216 | ||
3217 | void wxListMainWindow::OnArrowChar(size_t newCurrent, const wxKeyEvent& event) | |
c801d85f | 3218 | { |
cf1dfa6b VZ |
3219 | wxCHECK_RET( newCurrent < (size_t)GetItemCount(), |
3220 | _T("invalid item index in OnArrowChar()") ); | |
3221 | ||
3222 | size_t oldCurrent = m_current; | |
3223 | ||
3224 | // in single selection we just ignore Shift as we can't select several | |
3225 | // items anyhow | |
b54e41c5 | 3226 | if ( event.ShiftDown() && !IsSingleSel() ) |
cf1dfa6b | 3227 | { |
0ddefeb0 | 3228 | ChangeCurrent(newCurrent); |
cf1dfa6b VZ |
3229 | |
3230 | // select all the items between the old and the new one | |
3231 | if ( oldCurrent > newCurrent ) | |
3232 | { | |
3233 | newCurrent = oldCurrent; | |
3234 | oldCurrent = m_current; | |
3235 | } | |
3236 | ||
b54e41c5 | 3237 | HighlightLines(oldCurrent, newCurrent); |
cf1dfa6b VZ |
3238 | } |
3239 | else // !shift | |
3240 | { | |
b54e41c5 VZ |
3241 | // all previously selected items are unselected unless ctrl is held |
3242 | if ( !event.ControlDown() ) | |
3243 | HighlightAll(FALSE); | |
3244 | ||
0ddefeb0 | 3245 | ChangeCurrent(newCurrent); |
cf1dfa6b | 3246 | |
58c1c096 | 3247 | // refresh the old focus to remove it |
cf1dfa6b VZ |
3248 | RefreshLine( oldCurrent ); |
3249 | ||
3250 | if ( !event.ControlDown() ) | |
3251 | { | |
b54e41c5 | 3252 | HighlightLine( m_current, TRUE ); |
cf1dfa6b VZ |
3253 | } |
3254 | } | |
3255 | ||
92976ab6 | 3256 | RefreshLine( m_current ); |
cf1dfa6b | 3257 | |
cf3da716 | 3258 | MoveToFocus(); |
e1e955e1 | 3259 | } |
c801d85f | 3260 | |
3dfb93fd RR |
3261 | void wxListMainWindow::OnKeyDown( wxKeyEvent &event ) |
3262 | { | |
3263 | wxWindow *parent = GetParent(); | |
004fd0c8 | 3264 | |
3dfb93fd RR |
3265 | /* we propagate the key event up */ |
3266 | wxKeyEvent ke( wxEVT_KEY_DOWN ); | |
3267 | ke.m_shiftDown = event.m_shiftDown; | |
3268 | ke.m_controlDown = event.m_controlDown; | |
3269 | ke.m_altDown = event.m_altDown; | |
3270 | ke.m_metaDown = event.m_metaDown; | |
3271 | ke.m_keyCode = event.m_keyCode; | |
3272 | ke.m_x = event.m_x; | |
3273 | ke.m_y = event.m_y; | |
3274 | ke.SetEventObject( parent ); | |
3275 | if (parent->GetEventHandler()->ProcessEvent( ke )) return; | |
004fd0c8 | 3276 | |
3dfb93fd RR |
3277 | event.Skip(); |
3278 | } | |
004fd0c8 | 3279 | |
c801d85f KB |
3280 | void wxListMainWindow::OnChar( wxKeyEvent &event ) |
3281 | { | |
51cc4dad | 3282 | wxWindow *parent = GetParent(); |
004fd0c8 | 3283 | |
51cc4dad | 3284 | /* we send a list_key event up */ |
cf1dfa6b | 3285 | if ( HasCurrent() ) |
f6bcfd97 BP |
3286 | { |
3287 | wxListEvent le( wxEVT_COMMAND_LIST_KEY_DOWN, GetParent()->GetId() ); | |
cf1dfa6b VZ |
3288 | le.m_itemIndex = m_current; |
3289 | GetLine(m_current)->GetItem( 0, le.m_item ); | |
f6bcfd97 BP |
3290 | le.m_code = (int)event.KeyCode(); |
3291 | le.SetEventObject( parent ); | |
3292 | parent->GetEventHandler()->ProcessEvent( le ); | |
3293 | } | |
51cc4dad | 3294 | |
3dfb93fd RR |
3295 | /* we propagate the char event up */ |
3296 | wxKeyEvent ke( wxEVT_CHAR ); | |
51cc4dad RR |
3297 | ke.m_shiftDown = event.m_shiftDown; |
3298 | ke.m_controlDown = event.m_controlDown; | |
3299 | ke.m_altDown = event.m_altDown; | |
3300 | ke.m_metaDown = event.m_metaDown; | |
3301 | ke.m_keyCode = event.m_keyCode; | |
3302 | ke.m_x = event.m_x; | |
3303 | ke.m_y = event.m_y; | |
3304 | ke.SetEventObject( parent ); | |
3305 | if (parent->GetEventHandler()->ProcessEvent( ke )) return; | |
004fd0c8 | 3306 | |
012a03e0 RR |
3307 | if (event.KeyCode() == WXK_TAB) |
3308 | { | |
3309 | wxNavigationKeyEvent nevent; | |
c5145d41 | 3310 | nevent.SetWindowChange( event.ControlDown() ); |
012a03e0 | 3311 | nevent.SetDirection( !event.ShiftDown() ); |
8253c7fd | 3312 | nevent.SetEventObject( GetParent()->GetParent() ); |
012a03e0 | 3313 | nevent.SetCurrentFocus( m_parent ); |
87948f22 VZ |
3314 | if (GetParent()->GetParent()->GetEventHandler()->ProcessEvent( nevent )) |
3315 | return; | |
012a03e0 | 3316 | } |
004fd0c8 | 3317 | |
51cc4dad | 3318 | /* no item -> nothing to do */ |
cf1dfa6b | 3319 | if (!HasCurrent()) |
c801d85f | 3320 | { |
51cc4dad RR |
3321 | event.Skip(); |
3322 | return; | |
e1e955e1 | 3323 | } |
51cc4dad RR |
3324 | |
3325 | switch (event.KeyCode()) | |
c801d85f | 3326 | { |
51cc4dad | 3327 | case WXK_UP: |
cf1dfa6b VZ |
3328 | if ( m_current > 0 ) |
3329 | OnArrowChar( m_current - 1, event ); | |
51cc4dad | 3330 | break; |
cf1dfa6b | 3331 | |
51cc4dad | 3332 | case WXK_DOWN: |
cf1dfa6b VZ |
3333 | if ( m_current < (size_t)GetItemCount() - 1 ) |
3334 | OnArrowChar( m_current + 1, event ); | |
51cc4dad | 3335 | break; |
cf1dfa6b | 3336 | |
51cc4dad | 3337 | case WXK_END: |
1370703e | 3338 | if (!IsEmpty()) |
cf1dfa6b | 3339 | OnArrowChar( GetItemCount() - 1, event ); |
51cc4dad | 3340 | break; |
cf1dfa6b | 3341 | |
51cc4dad | 3342 | case WXK_HOME: |
1370703e | 3343 | if (!IsEmpty()) |
cf1dfa6b | 3344 | OnArrowChar( 0, event ); |
51cc4dad | 3345 | break; |
cf1dfa6b | 3346 | |
51cc4dad | 3347 | case WXK_PRIOR: |
f6bcfd97 | 3348 | { |
cf1dfa6b VZ |
3349 | int steps = 0; |
3350 | if ( HasFlag(wxLC_REPORT) ) | |
3351 | { | |
3352 | steps = m_linesPerPage - 1; | |
3353 | } | |
3354 | else | |
3355 | { | |
3356 | steps = m_current % m_linesPerPage; | |
3357 | } | |
3358 | ||
3359 | int index = m_current - steps; | |
3360 | if (index < 0) | |
3361 | index = 0; | |
3362 | ||
3363 | OnArrowChar( index, event ); | |
51cc4dad | 3364 | } |
51cc4dad | 3365 | break; |
cf1dfa6b | 3366 | |
51cc4dad | 3367 | case WXK_NEXT: |
bffa1c77 | 3368 | { |
cf1dfa6b VZ |
3369 | int steps = 0; |
3370 | if ( HasFlag(wxLC_REPORT) ) | |
3371 | { | |
3372 | steps = m_linesPerPage - 1; | |
3373 | } | |
3374 | else | |
3375 | { | |
3376 | steps = m_linesPerPage - (m_current % m_linesPerPage) - 1; | |
3377 | } | |
f6bcfd97 | 3378 | |
cf1dfa6b VZ |
3379 | size_t index = m_current + steps; |
3380 | size_t count = GetItemCount(); | |
3381 | if ( index >= count ) | |
3382 | index = count - 1; | |
3383 | ||
3384 | OnArrowChar( index, event ); | |
51cc4dad | 3385 | } |
51cc4dad | 3386 | break; |
cf1dfa6b | 3387 | |
51cc4dad | 3388 | case WXK_LEFT: |
cf1dfa6b | 3389 | if ( !HasFlag(wxLC_REPORT) ) |
51cc4dad | 3390 | { |
cf1dfa6b VZ |
3391 | int index = m_current - m_linesPerPage; |
3392 | if (index < 0) | |
3393 | index = 0; | |
3394 | ||
3395 | OnArrowChar( index, event ); | |
51cc4dad RR |
3396 | } |
3397 | break; | |
cf1dfa6b | 3398 | |
51cc4dad | 3399 | case WXK_RIGHT: |
cf1dfa6b | 3400 | if ( !HasFlag(wxLC_REPORT) ) |
51cc4dad | 3401 | { |
cf1dfa6b VZ |
3402 | size_t index = m_current + m_linesPerPage; |
3403 | ||
3404 | size_t count = GetItemCount(); | |
3405 | if ( index >= count ) | |
3406 | index = count - 1; | |
3407 | ||
3408 | OnArrowChar( index, event ); | |
51cc4dad RR |
3409 | } |
3410 | break; | |
cf1dfa6b | 3411 | |
51cc4dad | 3412 | case WXK_SPACE: |
b54e41c5 | 3413 | if ( IsSingleSel() ) |
33d0e17c | 3414 | { |
87948f22 | 3415 | SendNotify( m_current, wxEVT_COMMAND_LIST_ITEM_ACTIVATED ); |
70541533 VZ |
3416 | |
3417 | if ( IsHighlighted(m_current) ) | |
3418 | { | |
3419 | // don't unselect the item in single selection mode | |
3420 | break; | |
3421 | } | |
3422 | //else: select it in ReverseHighlight() below if unselected | |
33d0e17c | 3423 | } |
70541533 VZ |
3424 | |
3425 | ReverseHighlight(m_current); | |
51cc4dad | 3426 | break; |
cf1dfa6b | 3427 | |
51cc4dad RR |
3428 | case WXK_RETURN: |
3429 | case WXK_EXECUTE: | |
87948f22 | 3430 | SendNotify( m_current, wxEVT_COMMAND_LIST_ITEM_ACTIVATED ); |
51cc4dad | 3431 | break; |
cf1dfa6b | 3432 | |
51cc4dad | 3433 | default: |
51cc4dad | 3434 | event.Skip(); |
e1e955e1 | 3435 | } |
e1e955e1 | 3436 | } |
c801d85f | 3437 | |
cf1dfa6b VZ |
3438 | // ---------------------------------------------------------------------------- |
3439 | // focus handling | |
3440 | // ---------------------------------------------------------------------------- | |
3441 | ||
a6d57d03 VS |
3442 | void wxListMainWindow::SetFocus() |
3443 | { | |
3444 | // VS: wxListMainWindow derives from wxPanel (via wxScrolledWindow) and wxPanel | |
a77ec46d | 3445 | // overrides SetFocus in such way that it does never change focus from |
a6d57d03 | 3446 | // panel's child to the panel itself. Unfortunately, we must be able to change |
a77ec46d | 3447 | // focus to the panel from wxListTextCtrl because the text control should |
a6d57d03 VS |
3448 | // disappear when the user clicks outside it. |
3449 | ||
3450 | wxWindow *oldFocus = FindFocus(); | |
a77ec46d | 3451 | |
072da98f | 3452 | if ( oldFocus && oldFocus->GetParent() == this ) |
a6d57d03 VS |
3453 | { |
3454 | wxWindow::SetFocus(); | |
3455 | } | |
3456 | else | |
3457 | { | |
3458 | wxScrolledWindow::SetFocus(); | |
3459 | } | |
3460 | } | |
3461 | ||
c801d85f KB |
3462 | void wxListMainWindow::OnSetFocus( wxFocusEvent &WXUNUSED(event) ) |
3463 | { | |
bde9072f VZ |
3464 | // wxGTK sends us EVT_SET_FOCUS events even if we had never got |
3465 | // EVT_KILL_FOCUS before which means that we finish by redrawing the items | |
3466 | // which are already drawn correctly resulting in horrible flicker - avoid | |
3467 | // it | |
47724389 VZ |
3468 | if ( !m_hasFocus ) |
3469 | { | |
3470 | m_hasFocus = TRUE; | |
bde9072f | 3471 | |
47724389 VZ |
3472 | RefreshSelected(); |
3473 | } | |
bd8289c1 | 3474 | |
47724389 | 3475 | if ( !GetParent() ) |
cf1dfa6b | 3476 | return; |
004fd0c8 | 3477 | |
63852e78 RR |
3478 | wxFocusEvent event( wxEVT_SET_FOCUS, GetParent()->GetId() ); |
3479 | event.SetEventObject( GetParent() ); | |
3480 | GetParent()->GetEventHandler()->ProcessEvent( event ); | |
e1e955e1 | 3481 | } |
c801d85f KB |
3482 | |
3483 | void wxListMainWindow::OnKillFocus( wxFocusEvent &WXUNUSED(event) ) | |
3484 | { | |
63852e78 | 3485 | m_hasFocus = FALSE; |
004fd0c8 | 3486 | |
49ecb029 | 3487 | RefreshSelected(); |
e1e955e1 | 3488 | } |
c801d85f | 3489 | |
1e6d9499 | 3490 | void wxListMainWindow::DrawImage( int index, wxDC *dc, int x, int y ) |
c801d85f | 3491 | { |
cf1dfa6b | 3492 | if ( HasFlag(wxLC_ICON) && (m_normal_image_list)) |
63852e78 RR |
3493 | { |
3494 | m_normal_image_list->Draw( index, *dc, x, y, wxIMAGELIST_DRAW_TRANSPARENT ); | |
63852e78 | 3495 | } |
cf1dfa6b | 3496 | else if ( HasFlag(wxLC_SMALL_ICON) && (m_small_image_list)) |
63852e78 RR |
3497 | { |
3498 | m_small_image_list->Draw( index, *dc, x, y, wxIMAGELIST_DRAW_TRANSPARENT ); | |
3499 | } | |
cf1dfa6b | 3500 | else if ( HasFlag(wxLC_LIST) && (m_small_image_list)) |
0b855868 RR |
3501 | { |
3502 | m_small_image_list->Draw( index, *dc, x, y, wxIMAGELIST_DRAW_TRANSPARENT ); | |
3503 | } | |
cf1dfa6b | 3504 | else if ( HasFlag(wxLC_REPORT) && (m_small_image_list)) |
63852e78 RR |
3505 | { |
3506 | m_small_image_list->Draw( index, *dc, x, y, wxIMAGELIST_DRAW_TRANSPARENT ); | |
63852e78 | 3507 | } |
e1e955e1 | 3508 | } |
c801d85f | 3509 | |
5cd89174 | 3510 | void wxListMainWindow::GetImageSize( int index, int &width, int &height ) const |
c801d85f | 3511 | { |
cf1dfa6b | 3512 | if ( HasFlag(wxLC_ICON) && m_normal_image_list ) |
63852e78 RR |
3513 | { |
3514 | m_normal_image_list->GetSize( index, width, height ); | |
63852e78 | 3515 | } |
cf1dfa6b | 3516 | else if ( HasFlag(wxLC_SMALL_ICON) && m_small_image_list ) |
63852e78 RR |
3517 | { |
3518 | m_small_image_list->GetSize( index, width, height ); | |
63852e78 | 3519 | } |
cf1dfa6b | 3520 | else if ( HasFlag(wxLC_LIST) && m_small_image_list ) |
0b855868 RR |
3521 | { |
3522 | m_small_image_list->GetSize( index, width, height ); | |
0b855868 | 3523 | } |
cf1dfa6b | 3524 | else if ( HasFlag(wxLC_REPORT) && m_small_image_list ) |
63852e78 RR |
3525 | { |
3526 | m_small_image_list->GetSize( index, width, height ); | |
63852e78 | 3527 | } |
cf1dfa6b VZ |
3528 | else |
3529 | { | |
3530 | width = | |
3531 | height = 0; | |
3532 | } | |
e1e955e1 | 3533 | } |
c801d85f | 3534 | |
5cd89174 | 3535 | int wxListMainWindow::GetTextLength( const wxString &s ) const |
c801d85f | 3536 | { |
5cd89174 | 3537 | wxClientDC dc( wxConstCast(this, wxListMainWindow) ); |
cf1dfa6b | 3538 | dc.SetFont( GetFont() ); |
c801d85f | 3539 | |
cf1dfa6b VZ |
3540 | wxCoord lw; |
3541 | dc.GetTextExtent( s, &lw, NULL ); | |
3542 | ||
3543 | return lw + AUTOSIZE_COL_MARGIN; | |
e1e955e1 | 3544 | } |
c801d85f | 3545 | |
9cb07953 | 3546 | void wxListMainWindow::SetImageList( wxGenericImageList *imageList, int which ) |
c801d85f | 3547 | { |
139adb6a | 3548 | m_dirty = TRUE; |
f6bcfd97 BP |
3549 | |
3550 | // calc the spacing from the icon size | |
3551 | int width = 0, | |
3552 | height = 0; | |
3553 | if ((imageList) && (imageList->GetImageCount()) ) | |
3554 | { | |
3555 | imageList->GetSize(0, width, height); | |
3556 | } | |
3557 | ||
3558 | if (which == wxIMAGE_LIST_NORMAL) | |
3559 | { | |
3560 | m_normal_image_list = imageList; | |
3561 | m_normal_spacing = width + 8; | |
3562 | } | |
3563 | ||
3564 | if (which == wxIMAGE_LIST_SMALL) | |
3565 | { | |
3566 | m_small_image_list = imageList; | |
3567 | m_small_spacing = width + 14; | |
3568 | } | |
e1e955e1 | 3569 | } |
c801d85f | 3570 | |
debe6624 | 3571 | void wxListMainWindow::SetItemSpacing( int spacing, bool isSmall ) |
c801d85f | 3572 | { |
139adb6a RR |
3573 | m_dirty = TRUE; |
3574 | if (isSmall) | |
3575 | { | |
3576 | m_small_spacing = spacing; | |
3577 | } | |
3578 | else | |
3579 | { | |
3580 | m_normal_spacing = spacing; | |
3581 | } | |
e1e955e1 | 3582 | } |
c801d85f | 3583 | |
debe6624 | 3584 | int wxListMainWindow::GetItemSpacing( bool isSmall ) |
c801d85f | 3585 | { |
f6bcfd97 | 3586 | return isSmall ? m_small_spacing : m_normal_spacing; |
e1e955e1 | 3587 | } |
c801d85f | 3588 | |
cf1dfa6b VZ |
3589 | // ---------------------------------------------------------------------------- |
3590 | // columns | |
3591 | // ---------------------------------------------------------------------------- | |
3592 | ||
debe6624 | 3593 | void wxListMainWindow::SetColumn( int col, wxListItem &item ) |
c801d85f | 3594 | { |
24b9f055 | 3595 | wxListHeaderDataList::Node *node = m_columns.Item( col ); |
f6bcfd97 | 3596 | |
cf1dfa6b VZ |
3597 | wxCHECK_RET( node, _T("invalid column index in SetColumn") ); |
3598 | ||
3599 | if ( item.m_width == wxLIST_AUTOSIZE_USEHEADER ) | |
3600 | item.m_width = GetTextLength( item.m_text ); | |
3601 | ||
3602 | wxListHeaderData *column = node->GetData(); | |
3603 | column->SetItem( item ); | |
3604 | ||
3605 | wxListHeaderWindow *headerWin = GetListCtrl()->m_headerWin; | |
f6bcfd97 BP |
3606 | if ( headerWin ) |
3607 | headerWin->m_dirty = TRUE; | |
cf1dfa6b VZ |
3608 | |
3609 | m_dirty = TRUE; | |
3610 | ||
3611 | // invalidate it as it has to be recalculated | |
3612 | m_headerWidth = 0; | |
e1e955e1 | 3613 | } |
c801d85f | 3614 | |
debe6624 | 3615 | void wxListMainWindow::SetColumnWidth( int col, int width ) |
c801d85f | 3616 | { |
cf1dfa6b VZ |
3617 | wxCHECK_RET( col >= 0 && col < GetColumnCount(), |
3618 | _T("invalid column index") ); | |
3619 | ||
3620 | wxCHECK_RET( HasFlag(wxLC_REPORT), | |
f6bcfd97 | 3621 | _T("SetColumnWidth() can only be called in report mode.") ); |
0208334d | 3622 | |
63852e78 | 3623 | m_dirty = TRUE; |
abe4a4f1 VS |
3624 | wxListHeaderWindow *headerWin = GetListCtrl()->m_headerWin; |
3625 | if ( headerWin ) | |
3626 | headerWin->m_dirty = TRUE; | |
bd8289c1 | 3627 | |
cf1dfa6b VZ |
3628 | wxListHeaderDataList::Node *node = m_columns.Item( col ); |
3629 | wxCHECK_RET( node, _T("no column?") ); | |
3630 | ||
3631 | wxListHeaderData *column = node->GetData(); | |
3632 | ||
3633 | size_t count = GetItemCount(); | |
3634 | ||
f6bcfd97 BP |
3635 | if (width == wxLIST_AUTOSIZE_USEHEADER) |
3636 | { | |
cf1dfa6b | 3637 | width = GetTextLength(column->GetText()); |
f6bcfd97 | 3638 | } |
cf1dfa6b | 3639 | else if ( width == wxLIST_AUTOSIZE ) |
0180dad6 | 3640 | { |
cf1dfa6b VZ |
3641 | if ( IsVirtual() ) |
3642 | { | |
3643 | // TODO: determine the max width somehow... | |
3644 | width = WIDTH_COL_DEFAULT; | |
3645 | } | |
3646 | else // !virtual | |
0180dad6 | 3647 | { |
cf1dfa6b VZ |
3648 | wxClientDC dc(this); |
3649 | dc.SetFont( GetFont() ); | |
3650 | ||
3651 | int max = AUTOSIZE_COL_MARGIN; | |
3652 | ||
3653 | for ( size_t i = 0; i < count; i++ ) | |
0180dad6 | 3654 | { |
cf1dfa6b VZ |
3655 | wxListLineData *line = GetLine(i); |
3656 | wxListItemDataList::Node *n = line->m_items.Item( col ); | |
3657 | ||
3658 | wxCHECK_RET( n, _T("no subitem?") ); | |
3659 | ||
2c1f73ee | 3660 | wxListItemData *item = n->GetData(); |
cf1dfa6b VZ |
3661 | int current = 0; |
3662 | ||
bffa1c77 VZ |
3663 | if (item->HasImage()) |
3664 | { | |
cf1dfa6b | 3665 | int ix, iy; |
0180dad6 | 3666 | GetImageSize( item->GetImage(), ix, iy ); |
cf1dfa6b | 3667 | current += ix + 5; |
bffa1c77 | 3668 | } |
cf1dfa6b | 3669 | |
bffa1c77 VZ |
3670 | if (item->HasText()) |
3671 | { | |
cf1dfa6b VZ |
3672 | wxCoord w; |
3673 | dc.GetTextExtent( item->GetText(), &w, NULL ); | |
3674 | current += w; | |
bffa1c77 | 3675 | } |
cf1dfa6b | 3676 | |
2c1f73ee VZ |
3677 | if (current > max) |
3678 | max = current; | |
0180dad6 | 3679 | } |
cf1dfa6b VZ |
3680 | |
3681 | width = max + AUTOSIZE_COL_MARGIN; | |
0180dad6 | 3682 | } |
0180dad6 RR |
3683 | } |
3684 | ||
cf1dfa6b | 3685 | column->SetWidth( width ); |
bd8289c1 | 3686 | |
cf1dfa6b VZ |
3687 | // invalidate it as it has to be recalculated |
3688 | m_headerWidth = 0; | |
3689 | } | |
3690 | ||
3691 | int wxListMainWindow::GetHeaderWidth() const | |
3692 | { | |
3693 | if ( !m_headerWidth ) | |
0208334d | 3694 | { |
cf1dfa6b VZ |
3695 | wxListMainWindow *self = wxConstCast(this, wxListMainWindow); |
3696 | ||
3697 | size_t count = GetColumnCount(); | |
3698 | for ( size_t col = 0; col < count; col++ ) | |
63852e78 | 3699 | { |
cf1dfa6b | 3700 | self->m_headerWidth += GetColumnWidth(col); |
63852e78 | 3701 | } |
0208334d | 3702 | } |
bd8289c1 | 3703 | |
cf1dfa6b | 3704 | return m_headerWidth; |
e1e955e1 | 3705 | } |
c801d85f | 3706 | |
cf1dfa6b | 3707 | void wxListMainWindow::GetColumn( int col, wxListItem &item ) const |
c801d85f | 3708 | { |
24b9f055 | 3709 | wxListHeaderDataList::Node *node = m_columns.Item( col ); |
cf1dfa6b VZ |
3710 | wxCHECK_RET( node, _T("invalid column index in GetColumn") ); |
3711 | ||
3712 | wxListHeaderData *column = node->GetData(); | |
3713 | column->GetItem( item ); | |
e1e955e1 | 3714 | } |
c801d85f | 3715 | |
cf1dfa6b | 3716 | int wxListMainWindow::GetColumnWidth( int col ) const |
c801d85f | 3717 | { |
24b9f055 VZ |
3718 | wxListHeaderDataList::Node *node = m_columns.Item( col ); |
3719 | wxCHECK_MSG( node, 0, _T("invalid column index") ); | |
3720 | ||
3721 | wxListHeaderData *column = node->GetData(); | |
3722 | return column->GetWidth(); | |
e1e955e1 | 3723 | } |
c801d85f | 3724 | |
cf1dfa6b VZ |
3725 | // ---------------------------------------------------------------------------- |
3726 | // item state | |
3727 | // ---------------------------------------------------------------------------- | |
c801d85f KB |
3728 | |
3729 | void wxListMainWindow::SetItem( wxListItem &item ) | |
3730 | { | |
cf1dfa6b VZ |
3731 | long id = item.m_itemId; |
3732 | wxCHECK_RET( id >= 0 && (size_t)id < GetItemCount(), | |
3733 | _T("invalid item index in SetItem") ); | |
3734 | ||
6c02c329 VZ |
3735 | if ( !IsVirtual() ) |
3736 | { | |
3737 | wxListLineData *line = GetLine((size_t)id); | |
3738 | line->SetItem( item.m_col, item ); | |
3739 | } | |
3740 | ||
3741 | if ( InReportView() ) | |
cf1dfa6b VZ |
3742 | { |
3743 | // just refresh the line to show the new value of the text/image | |
3744 | RefreshLine((size_t)id); | |
3745 | } | |
6c02c329 | 3746 | else // !report |
92976ab6 | 3747 | { |
6c02c329 | 3748 | // refresh everything (resulting in horrible flicker - FIXME!) |
cf1dfa6b | 3749 | m_dirty = TRUE; |
92976ab6 | 3750 | } |
e1e955e1 | 3751 | } |
c801d85f | 3752 | |
cf1dfa6b | 3753 | void wxListMainWindow::SetItemState( long litem, long state, long stateMask ) |
c801d85f | 3754 | { |
cf1dfa6b | 3755 | wxCHECK_RET( litem >= 0 && (size_t)litem < GetItemCount(), |
54442116 VZ |
3756 | _T("invalid list ctrl item index in SetItem") ); |
3757 | ||
cf1dfa6b | 3758 | size_t oldCurrent = m_current; |
88b792af | 3759 | size_t item = (size_t)litem; // safe because of the check above |
bd8289c1 | 3760 | |
88b792af | 3761 | // do we need to change the focus? |
54442116 | 3762 | if ( stateMask & wxLIST_STATE_FOCUSED ) |
c801d85f | 3763 | { |
54442116 | 3764 | if ( state & wxLIST_STATE_FOCUSED ) |
92976ab6 | 3765 | { |
54442116 | 3766 | // don't do anything if this item is already focused |
cf1dfa6b | 3767 | if ( item != m_current ) |
92976ab6 | 3768 | { |
0ddefeb0 | 3769 | ChangeCurrent(item); |
cf1dfa6b | 3770 | |
88b792af | 3771 | if ( oldCurrent != (size_t)-1 ) |
cf1dfa6b | 3772 | { |
88b792af VZ |
3773 | if ( IsSingleSel() ) |
3774 | { | |
3775 | HighlightLine(oldCurrent, FALSE); | |
3776 | } | |
3777 | ||
cf1dfa6b VZ |
3778 | RefreshLine(oldCurrent); |
3779 | } | |
54442116 | 3780 | |
92976ab6 | 3781 | RefreshLine( m_current ); |
92976ab6 | 3782 | } |
54442116 VZ |
3783 | } |
3784 | else // unfocus | |
3785 | { | |
3786 | // don't do anything if this item is not focused | |
cf1dfa6b | 3787 | if ( item == m_current ) |
bffa1c77 | 3788 | { |
0ddefeb0 | 3789 | ResetCurrent(); |
88b792af | 3790 | |
943f6ad3 VZ |
3791 | if ( IsSingleSel() ) |
3792 | { | |
3793 | // we must unselect the old current item as well or we | |
3794 | // might end up with more than one selected item in a | |
3795 | // single selection control | |
3796 | HighlightLine(oldCurrent, FALSE); | |
3797 | } | |
3798 | ||
88b792af | 3799 | RefreshLine( oldCurrent ); |
bffa1c77 | 3800 | } |
92976ab6 | 3801 | } |
e1e955e1 | 3802 | } |
54442116 | 3803 | |
88b792af | 3804 | // do we need to change the selection state? |
54442116 VZ |
3805 | if ( stateMask & wxLIST_STATE_SELECTED ) |
3806 | { | |
3807 | bool on = (state & wxLIST_STATE_SELECTED) != 0; | |
54442116 | 3808 | |
b54e41c5 | 3809 | if ( IsSingleSel() ) |
54442116 | 3810 | { |
cf1dfa6b VZ |
3811 | if ( on ) |
3812 | { | |
3813 | // selecting the item also makes it the focused one in the | |
3814 | // single sel mode | |
3815 | if ( m_current != item ) | |
3816 | { | |
0ddefeb0 | 3817 | ChangeCurrent(item); |
cf1dfa6b VZ |
3818 | |
3819 | if ( oldCurrent != (size_t)-1 ) | |
3820 | { | |
b54e41c5 | 3821 | HighlightLine( oldCurrent, FALSE ); |
cf1dfa6b VZ |
3822 | RefreshLine( oldCurrent ); |
3823 | } | |
3824 | } | |
3825 | } | |
3826 | else // off | |
3827 | { | |
3828 | // only the current item may be selected anyhow | |
3829 | if ( item != m_current ) | |
3830 | return; | |
3831 | } | |
54442116 VZ |
3832 | } |
3833 | ||
b54e41c5 | 3834 | if ( HighlightLine(item, on) ) |
54442116 | 3835 | { |
cf1dfa6b | 3836 | RefreshLine(item); |
54442116 VZ |
3837 | } |
3838 | } | |
e1e955e1 | 3839 | } |
c801d85f | 3840 | |
62d89eb4 | 3841 | int wxListMainWindow::GetItemState( long item, long stateMask ) const |
c801d85f | 3842 | { |
cf1dfa6b VZ |
3843 | wxCHECK_MSG( item >= 0 && (size_t)item < GetItemCount(), 0, |
3844 | _T("invalid list ctrl item index in GetItemState()") ); | |
3845 | ||
92976ab6 | 3846 | int ret = wxLIST_STATE_DONTCARE; |
cf1dfa6b VZ |
3847 | |
3848 | if ( stateMask & wxLIST_STATE_FOCUSED ) | |
c801d85f | 3849 | { |
cf1dfa6b VZ |
3850 | if ( (size_t)item == m_current ) |
3851 | ret |= wxLIST_STATE_FOCUSED; | |
e1e955e1 | 3852 | } |
cf1dfa6b VZ |
3853 | |
3854 | if ( stateMask & wxLIST_STATE_SELECTED ) | |
c801d85f | 3855 | { |
b54e41c5 | 3856 | if ( IsHighlighted(item) ) |
cf1dfa6b | 3857 | ret |= wxLIST_STATE_SELECTED; |
e1e955e1 | 3858 | } |
cf1dfa6b | 3859 | |
92976ab6 | 3860 | return ret; |
e1e955e1 | 3861 | } |
c801d85f | 3862 | |
62d89eb4 | 3863 | void wxListMainWindow::GetItem( wxListItem &item ) const |
c801d85f | 3864 | { |
cf1dfa6b VZ |
3865 | wxCHECK_RET( item.m_itemId >= 0 && (size_t)item.m_itemId < GetItemCount(), |
3866 | _T("invalid item index in GetItem") ); | |
3867 | ||
3868 | wxListLineData *line = GetLine((size_t)item.m_itemId); | |
3869 | line->GetItem( item.m_col, item ); | |
e1e955e1 | 3870 | } |
c801d85f | 3871 | |
cf1dfa6b VZ |
3872 | // ---------------------------------------------------------------------------- |
3873 | // item count | |
3874 | // ---------------------------------------------------------------------------- | |
3875 | ||
3876 | size_t wxListMainWindow::GetItemCount() const | |
1370703e VZ |
3877 | { |
3878 | return IsVirtual() ? m_countVirt : m_lines.GetCount(); | |
3879 | } | |
3880 | ||
3881 | void wxListMainWindow::SetItemCount(long count) | |
c801d85f | 3882 | { |
b54e41c5 | 3883 | m_selStore.SetItemCount(count); |
1370703e VZ |
3884 | m_countVirt = count; |
3885 | ||
850ed6e7 VZ |
3886 | ResetVisibleLinesRange(); |
3887 | ||
5fe143df VZ |
3888 | // scrollbars must be reset |
3889 | m_dirty = TRUE; | |
e1e955e1 | 3890 | } |
c801d85f | 3891 | |
62d89eb4 | 3892 | int wxListMainWindow::GetSelectedItemCount() const |
c801d85f | 3893 | { |
cf1dfa6b | 3894 | // deal with the quick case first |
b54e41c5 | 3895 | if ( IsSingleSel() ) |
92976ab6 | 3896 | { |
b54e41c5 | 3897 | return HasCurrent() ? IsHighlighted(m_current) : FALSE; |
92976ab6 | 3898 | } |
cf1dfa6b VZ |
3899 | |
3900 | // virtual controls remmebers all its selections itself | |
3901 | if ( IsVirtual() ) | |
b54e41c5 | 3902 | return m_selStore.GetSelectedCount(); |
cf1dfa6b VZ |
3903 | |
3904 | // TODO: we probably should maintain the number of items selected even for | |
3905 | // non virtual controls as enumerating all lines is really slow... | |
3906 | size_t countSel = 0; | |
3907 | size_t count = GetItemCount(); | |
3908 | for ( size_t line = 0; line < count; line++ ) | |
92976ab6 | 3909 | { |
b54e41c5 | 3910 | if ( GetLine(line)->IsHighlighted() ) |
cf1dfa6b | 3911 | countSel++; |
92976ab6 | 3912 | } |
c801d85f | 3913 | |
cf1dfa6b | 3914 | return countSel; |
e1e955e1 | 3915 | } |
e3e65dac | 3916 | |
cf1dfa6b VZ |
3917 | // ---------------------------------------------------------------------------- |
3918 | // item position/size | |
3919 | // ---------------------------------------------------------------------------- | |
3920 | ||
62d89eb4 | 3921 | void wxListMainWindow::GetItemRect( long index, wxRect &rect ) const |
c801d85f | 3922 | { |
cf1dfa6b VZ |
3923 | wxCHECK_RET( index >= 0 && (size_t)index < GetItemCount(), |
3924 | _T("invalid index in GetItemRect") ); | |
3925 | ||
5cd89174 | 3926 | rect = GetLineRect((size_t)index); |
b54e41c5 | 3927 | |
cf1dfa6b | 3928 | CalcScrolledPosition(rect.x, rect.y, &rect.x, &rect.y); |
e1e955e1 | 3929 | } |
c801d85f | 3930 | |
62d89eb4 | 3931 | bool wxListMainWindow::GetItemPosition(long item, wxPoint& pos) const |
c801d85f | 3932 | { |
cf1dfa6b VZ |
3933 | wxRect rect; |
3934 | GetItemRect(item, rect); | |
bd8289c1 | 3935 | |
cf1dfa6b VZ |
3936 | pos.x = rect.x; |
3937 | pos.y = rect.y; | |
bd8289c1 | 3938 | |
cf1dfa6b | 3939 | return TRUE; |
e1e955e1 | 3940 | } |
c801d85f | 3941 | |
cf1dfa6b VZ |
3942 | // ---------------------------------------------------------------------------- |
3943 | // geometry calculation | |
3944 | // ---------------------------------------------------------------------------- | |
3945 | ||
34bbbc27 | 3946 | void wxListMainWindow::RecalculatePositions(bool noRefresh) |
c801d85f | 3947 | { |
1e6d9499 | 3948 | wxClientDC dc( this ); |
92976ab6 | 3949 | dc.SetFont( GetFont() ); |
c801d85f | 3950 | |
cf1dfa6b VZ |
3951 | int iconSpacing; |
3952 | if ( HasFlag(wxLC_ICON) ) | |
3953 | iconSpacing = m_normal_spacing; | |
3954 | else if ( HasFlag(wxLC_SMALL_ICON) ) | |
3955 | iconSpacing = m_small_spacing; | |
3956 | else | |
3957 | iconSpacing = 0; | |
004fd0c8 | 3958 | |
bf632edd RR |
3959 | // Note that we do not call GetClientSize() here but |
3960 | // GetSize() and substract the border size for sunken | |
3961 | // borders manually. This is technically incorrect, | |
3962 | // but we need to know the client area's size WITHOUT | |
3963 | // scrollbars here. Since we don't know if there are | |
3964 | // any scrollbars, we use GetSize() instead. Another | |
3965 | // solution would be to call SetScrollbars() here to | |
3966 | // remove the scrollbars and call GetClientSize() then, | |
3967 | // but this might result in flicker and - worse - will | |
3968 | // reset the scrollbars to 0 which is not good at all | |
3969 | // if you resize a dialog/window, but don't want to | |
3970 | // reset the window scrolling. RR. | |
3971 | // Furthermore, we actually do NOT subtract the border | |
3972 | // width as 2 pixels is just the extra space which we | |
3973 | // need around the actual content in the window. Other- | |
3974 | // wise the text would e.g. touch the upper border. RR. | |
cf1dfa6b VZ |
3975 | int clientWidth, |
3976 | clientHeight; | |
bf632edd | 3977 | GetSize( &clientWidth, &clientHeight ); |
a77ec46d | 3978 | |
cf1dfa6b VZ |
3979 | if ( HasFlag(wxLC_REPORT) ) |
3980 | { | |
3981 | // all lines have the same height | |
b54e41c5 | 3982 | int lineHeight = GetLineHeight(); |
c801d85f | 3983 | |
cf1dfa6b | 3984 | // scroll one line per step |
b54e41c5 | 3985 | m_yScroll = lineHeight; |
bd8289c1 | 3986 | |
cf1dfa6b | 3987 | size_t lineCount = GetItemCount(); |
b54e41c5 | 3988 | int entireHeight = lineCount*lineHeight + LINE_SPACING; |
bd8289c1 | 3989 | |
b54e41c5 VZ |
3990 | m_linesPerPage = clientHeight / lineHeight; |
3991 | ||
3992 | ResetVisibleLinesRange(); | |
2c1f73ee | 3993 | |
cf1dfa6b | 3994 | SetScrollbars( m_xScroll, m_yScroll, |
c020c47e | 3995 | GetHeaderWidth() / m_xScroll, |
cf1dfa6b VZ |
3996 | (entireHeight + m_yScroll - 1)/m_yScroll, |
3997 | GetScrollPos(wxHORIZONTAL), | |
3998 | GetScrollPos(wxVERTICAL), | |
3999 | TRUE ); | |
e1e955e1 | 4000 | } |
cf1dfa6b | 4001 | else // !report |
92976ab6 RR |
4002 | { |
4003 | // at first we try without any scrollbar. if the items don't | |
4004 | // fit into the window, we recalculate after subtracting an | |
4005 | // approximated 15 pt for the horizontal scrollbar | |
004fd0c8 | 4006 | |
b54e41c5 | 4007 | int entireWidth = 0; |
bd8289c1 | 4008 | |
92976ab6 | 4009 | for (int tries = 0; tries < 2; tries++) |
e487524e | 4010 | { |
5d684756 RR |
4011 | // We start with 4 for the border around all items |
4012 | entireWidth = 4; | |
a77ec46d | 4013 | |
5d684756 RR |
4014 | if (tries == 1) |
4015 | { | |
4016 | // Now we have decided that the items do not fit into the | |
4017 | // client area. Unfortunately, wxWindows sometimes thinks | |
4018 | // that it does fit and therefore NO horizontal scrollbar | |
4019 | // is inserted. This looks ugly, so we fudge here and make | |
4020 | // the calculated width bigger than was actually has been | |
4021 | // calculated. This ensures that wxScrolledWindows puts | |
4022 | // a scrollbar at the bottom of its client area. | |
4023 | entireWidth += SCROLL_UNIT_X; | |
4024 | } | |
a77ec46d | 4025 | |
bf632edd | 4026 | // Start at 2,2 so the text does not touch the border |
5d25c050 RR |
4027 | int x = 2; |
4028 | int y = 2; | |
92976ab6 | 4029 | int maxWidth = 0; |
cf1dfa6b VZ |
4030 | m_linesPerPage = 0; |
4031 | int currentlyVisibleLines = 0; | |
4032 | ||
4033 | size_t count = GetItemCount(); | |
4034 | for (size_t i = 0; i < count; i++) | |
92976ab6 | 4035 | { |
cf1dfa6b VZ |
4036 | currentlyVisibleLines++; |
4037 | wxListLineData *line = GetLine(i); | |
92976ab6 | 4038 | line->CalculateSize( &dc, iconSpacing ); |
5d684756 | 4039 | line->SetPosition( x, y, clientWidth, iconSpacing ); // Why clientWidth? (FIXME) |
cf1dfa6b | 4040 | |
5cd89174 | 4041 | wxSize sizeLine = GetLineSize(i); |
cf1dfa6b VZ |
4042 | |
4043 | if ( maxWidth < sizeLine.x ) | |
4044 | maxWidth = sizeLine.x; | |
4045 | ||
4046 | y += sizeLine.y; | |
4047 | if (currentlyVisibleLines > m_linesPerPage) | |
4048 | m_linesPerPage = currentlyVisibleLines; | |
4049 | ||
5d684756 | 4050 | // Assume that the size of the next one is the same... (FIXME) |
bf632edd | 4051 | if ( y + sizeLine.y >= clientHeight ) |
92976ab6 | 4052 | { |
cf1dfa6b | 4053 | currentlyVisibleLines = 0; |
e1208c31 | 4054 | y = 2; |
8b53e5a2 RR |
4055 | x += maxWidth+6; |
4056 | entireWidth += maxWidth+6; | |
92976ab6 RR |
4057 | maxWidth = 0; |
4058 | } | |
a77ec46d | 4059 | |
5d684756 | 4060 | // We have reached the last item. |
cf1dfa6b VZ |
4061 | if ( i == count - 1 ) |
4062 | entireWidth += maxWidth; | |
a77ec46d | 4063 | |
5d684756 | 4064 | if ( (tries == 0) && (entireWidth+SCROLL_UNIT_X > clientWidth) ) |
92976ab6 | 4065 | { |
5d684756 | 4066 | clientHeight -= 15; // We guess the scrollbar height. (FIXME) |
cf1dfa6b VZ |
4067 | m_linesPerPage = 0; |
4068 | currentlyVisibleLines = 0; | |
92976ab6 RR |
4069 | break; |
4070 | } | |
a77ec46d | 4071 | |
cf1dfa6b | 4072 | if ( i == count - 1 ) |
5d684756 | 4073 | tries = 1; // Everything fits, no second try required. |
92976ab6 | 4074 | } |
e487524e | 4075 | } |
bffa1c77 | 4076 | |
92976ab6 | 4077 | int scroll_pos = GetScrollPos( wxHORIZONTAL ); |
cf1dfa6b | 4078 | SetScrollbars( m_xScroll, m_yScroll, (entireWidth+SCROLL_UNIT_X) / m_xScroll, 0, scroll_pos, 0, TRUE ); |
e1e955e1 | 4079 | } |
cf1dfa6b | 4080 | |
34bbbc27 VZ |
4081 | if ( !noRefresh ) |
4082 | { | |
4083 | // FIXME: why should we call it from here? | |
4084 | UpdateCurrent(); | |
b54e41c5 | 4085 | |
34bbbc27 VZ |
4086 | RefreshAll(); |
4087 | } | |
b54e41c5 VZ |
4088 | } |
4089 | ||
4090 | void wxListMainWindow::RefreshAll() | |
4091 | { | |
4092 | m_dirty = FALSE; | |
4093 | Refresh(); | |
4094 | ||
4095 | wxListHeaderWindow *headerWin = GetListCtrl()->m_headerWin; | |
70541533 | 4096 | if ( headerWin && headerWin->m_dirty ) |
b54e41c5 VZ |
4097 | { |
4098 | headerWin->m_dirty = FALSE; | |
4099 | headerWin->Refresh(); | |
4100 | } | |
e1e955e1 | 4101 | } |
c801d85f | 4102 | |
cf1dfa6b | 4103 | void wxListMainWindow::UpdateCurrent() |
c801d85f | 4104 | { |
b54e41c5 | 4105 | if ( !HasCurrent() && !IsEmpty() ) |
92976ab6 | 4106 | { |
0ddefeb0 | 4107 | ChangeCurrent(0); |
92976ab6 | 4108 | } |
e1e955e1 | 4109 | } |
c801d85f | 4110 | |
19695fbd VZ |
4111 | long wxListMainWindow::GetNextItem( long item, |
4112 | int WXUNUSED(geometry), | |
62d89eb4 | 4113 | int state ) const |
c801d85f | 4114 | { |
d1022fd6 VZ |
4115 | long ret = item, |
4116 | max = GetItemCount(); | |
4117 | wxCHECK_MSG( (ret == -1) || (ret < max), -1, | |
13771c08 | 4118 | _T("invalid listctrl index in GetNextItem()") ); |
19695fbd VZ |
4119 | |
4120 | // notice that we start with the next item (or the first one if item == -1) | |
4121 | // and this is intentional to allow writing a simple loop to iterate over | |
4122 | // all selected items | |
d1022fd6 VZ |
4123 | ret++; |
4124 | if ( ret == max ) | |
4125 | { | |
4126 | // this is not an error because the index was ok initially, just no | |
4127 | // such item | |
4128 | return -1; | |
4129 | } | |
4130 | ||
cf1dfa6b VZ |
4131 | if ( !state ) |
4132 | { | |
4133 | // any will do | |
4134 | return (size_t)ret; | |
4135 | } | |
4136 | ||
4137 | size_t count = GetItemCount(); | |
4138 | for ( size_t line = (size_t)ret; line < count; line++ ) | |
63852e78 | 4139 | { |
cf1dfa6b VZ |
4140 | if ( (state & wxLIST_STATE_FOCUSED) && (line == m_current) ) |
4141 | return line; | |
4142 | ||
b54e41c5 | 4143 | if ( (state & wxLIST_STATE_SELECTED) && IsHighlighted(line) ) |
cf1dfa6b | 4144 | return line; |
63852e78 | 4145 | } |
19695fbd | 4146 | |
63852e78 | 4147 | return -1; |
e1e955e1 | 4148 | } |
c801d85f | 4149 | |
cf1dfa6b VZ |
4150 | // ---------------------------------------------------------------------------- |
4151 | // deleting stuff | |
4152 | // ---------------------------------------------------------------------------- | |
4153 | ||
b54e41c5 | 4154 | void wxListMainWindow::DeleteItem( long lindex ) |
c801d85f | 4155 | { |
cf1dfa6b VZ |
4156 | size_t count = GetItemCount(); |
4157 | ||
b54e41c5 | 4158 | wxCHECK_RET( (lindex >= 0) && ((size_t)lindex < count), |
cf1dfa6b VZ |
4159 | _T("invalid item index in DeleteItem") ); |
4160 | ||
b54e41c5 VZ |
4161 | size_t index = (size_t)lindex; |
4162 | ||
d6ddcd57 VZ |
4163 | // we don't need to adjust the index for the previous items |
4164 | if ( HasCurrent() && m_current >= index ) | |
cf1dfa6b | 4165 | { |
d6ddcd57 VZ |
4166 | // if the current item is being deleted, we want the next one to |
4167 | // become selected - unless there is no next one - so don't adjust | |
4168 | // m_current in this case | |
4169 | if ( m_current != index || m_current == count - 1 ) | |
4170 | { | |
4171 | m_current--; | |
4172 | } | |
cf1dfa6b VZ |
4173 | } |
4174 | ||
938b652b | 4175 | if ( InReportView() ) |
63852e78 | 4176 | { |
6b4a8d93 | 4177 | ResetVisibleLinesRange(); |
938b652b VZ |
4178 | } |
4179 | ||
938b652b VZ |
4180 | if ( IsVirtual() ) |
4181 | { | |
4182 | m_countVirt--; | |
b54e41c5 VZ |
4183 | |
4184 | m_selStore.OnItemDelete(index); | |
4185 | } | |
4186 | else | |
4187 | { | |
4188 | m_lines.RemoveAt( index ); | |
63852e78 | 4189 | } |
6b4a8d93 | 4190 | |
70541533 | 4191 | // we need to refresh the (vert) scrollbar as the number of items changed |
b84839ae | 4192 | m_dirty = TRUE; |
91c6cc0e VZ |
4193 | |
4194 | SendNotify( index, wxEVT_COMMAND_LIST_DELETE_ITEM ); | |
4195 | ||
6b4a8d93 | 4196 | RefreshAfter(index); |
e1e955e1 | 4197 | } |
c801d85f | 4198 | |
debe6624 | 4199 | void wxListMainWindow::DeleteColumn( int col ) |
c801d85f | 4200 | { |
24b9f055 VZ |
4201 | wxListHeaderDataList::Node *node = m_columns.Item( col ); |
4202 | ||
4203 | wxCHECK_RET( node, wxT("invalid column index in DeleteColumn()") ); | |
bd8289c1 | 4204 | |
5b077d48 | 4205 | m_dirty = TRUE; |
24b9f055 | 4206 | m_columns.DeleteNode( node ); |
ae409cb8 VZ |
4207 | |
4208 | // invalidate it as it has to be recalculated | |
4209 | m_headerWidth = 0; | |
e1e955e1 | 4210 | } |
c801d85f | 4211 | |
5fe143df | 4212 | void wxListMainWindow::DoDeleteAllItems() |
c801d85f | 4213 | { |
cf1dfa6b VZ |
4214 | if ( IsEmpty() ) |
4215 | { | |
4216 | // nothing to do - in particular, don't send the event | |
4217 | return; | |
4218 | } | |
4219 | ||
b54e41c5 | 4220 | ResetCurrent(); |
7c0ea335 VZ |
4221 | |
4222 | // to make the deletion of all items faster, we don't send the | |
cf1dfa6b VZ |
4223 | // notifications for each item deletion in this case but only one event |
4224 | // for all of them: this is compatible with wxMSW and documented in | |
4225 | // DeleteAllItems() description | |
bffa1c77 | 4226 | |
12c1b46a RR |
4227 | wxListEvent event( wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS, GetParent()->GetId() ); |
4228 | event.SetEventObject( GetParent() ); | |
4229 | GetParent()->GetEventHandler()->ProcessEvent( event ); | |
7c0ea335 | 4230 | |
b54e41c5 VZ |
4231 | if ( IsVirtual() ) |
4232 | { | |
4233 | m_countVirt = 0; | |
4234 | ||
850ed6e7 | 4235 | m_selStore.Clear(); |
b54e41c5 VZ |
4236 | } |
4237 | ||
6b4a8d93 VZ |
4238 | if ( InReportView() ) |
4239 | { | |
4240 | ResetVisibleLinesRange(); | |
4241 | } | |
4242 | ||
5b077d48 | 4243 | m_lines.Clear(); |
5fe143df | 4244 | } |
cf1dfa6b | 4245 | |
5fe143df VZ |
4246 | void wxListMainWindow::DeleteAllItems() |
4247 | { | |
4248 | DoDeleteAllItems(); | |
4249 | ||
4250 | RecalculatePositions(); | |
e1e955e1 | 4251 | } |
c801d85f | 4252 | |
12c1b46a | 4253 | void wxListMainWindow::DeleteEverything() |
c801d85f | 4254 | { |
5b077d48 | 4255 | m_columns.Clear(); |
904ccf52 VZ |
4256 | |
4257 | DeleteAllItems(); | |
e1e955e1 | 4258 | } |
c801d85f | 4259 | |
cf1dfa6b VZ |
4260 | // ---------------------------------------------------------------------------- |
4261 | // scanning for an item | |
4262 | // ---------------------------------------------------------------------------- | |
4263 | ||
debe6624 | 4264 | void wxListMainWindow::EnsureVisible( long index ) |
c801d85f | 4265 | { |
cf1dfa6b VZ |
4266 | wxCHECK_RET( index >= 0 && (size_t)index < GetItemCount(), |
4267 | _T("invalid index in EnsureVisible") ); | |
4268 | ||
4269 | // We have to call this here because the label in question might just have | |
34bbbc27 VZ |
4270 | // been added and its position is not known yet |
4271 | if ( m_dirty ) | |
4272 | { | |
34bbbc27 VZ |
4273 | RecalculatePositions(TRUE /* no refresh */); |
4274 | } | |
4275 | ||
4276 | MoveToItem((size_t)index); | |
e1e955e1 | 4277 | } |
c801d85f | 4278 | |
debe6624 | 4279 | long wxListMainWindow::FindItem(long start, const wxString& str, bool WXUNUSED(partial) ) |
c801d85f | 4280 | { |
5b077d48 RR |
4281 | long pos = start; |
4282 | wxString tmp = str; | |
cf1dfa6b VZ |
4283 | if (pos < 0) |
4284 | pos = 0; | |
54442116 | 4285 | |
cf1dfa6b VZ |
4286 | size_t count = GetItemCount(); |
4287 | for ( size_t i = (size_t)pos; i < count; i++ ) | |
4288 | { | |
4289 | wxListLineData *line = GetLine(i); | |
4290 | if ( line->GetText(0) == tmp ) | |
4291 | return i; | |
5b077d48 | 4292 | } |
cf1dfa6b VZ |
4293 | |
4294 | return wxNOT_FOUND; | |
e1e955e1 | 4295 | } |
c801d85f | 4296 | |
debe6624 | 4297 | long wxListMainWindow::FindItem(long start, long data) |
c801d85f | 4298 | { |
5b077d48 | 4299 | long pos = start; |
cf1dfa6b VZ |
4300 | if (pos < 0) |
4301 | pos = 0; | |
4302 | ||
4303 | size_t count = GetItemCount(); | |
4304 | for (size_t i = (size_t)pos; i < count; i++) | |
5b077d48 | 4305 | { |
cf1dfa6b | 4306 | wxListLineData *line = GetLine(i); |
5b077d48 RR |
4307 | wxListItem item; |
4308 | line->GetItem( 0, item ); | |
cf1dfa6b VZ |
4309 | if (item.m_data == data) |
4310 | return i; | |
5b077d48 | 4311 | } |
cf1dfa6b VZ |
4312 | |
4313 | return wxNOT_FOUND; | |
e1e955e1 | 4314 | } |
c801d85f | 4315 | |
debe6624 | 4316 | long wxListMainWindow::HitTest( int x, int y, int &flags ) |
c801d85f | 4317 | { |
aaef15bf | 4318 | CalcUnscrolledPosition( x, y, &x, &y ); |
e8741cca | 4319 | |
fc4f1d5f VZ |
4320 | size_t count = GetItemCount(); |
4321 | ||
5cd89174 | 4322 | if ( HasFlag(wxLC_REPORT) ) |
c801d85f | 4323 | { |
5cd89174 | 4324 | size_t current = y / GetLineHeight(); |
fc4f1d5f VZ |
4325 | if ( current < count ) |
4326 | { | |
4327 | flags = HitTestLine(current, x, y); | |
4328 | if ( flags ) | |
4329 | return current; | |
4330 | } | |
5cd89174 VZ |
4331 | } |
4332 | else // !report | |
4333 | { | |
4334 | // TODO: optimize it too! this is less simple than for report view but | |
4335 | // enumerating all items is still not a way to do it!! | |
5cd89174 | 4336 | for ( size_t current = 0; current < count; current++ ) |
5b077d48 | 4337 | { |
5cd89174 VZ |
4338 | flags = HitTestLine(current, x, y); |
4339 | if ( flags ) | |
4340 | return current; | |
5b077d48 | 4341 | } |
e1e955e1 | 4342 | } |
cf1dfa6b VZ |
4343 | |
4344 | return wxNOT_FOUND; | |
e1e955e1 | 4345 | } |
c801d85f | 4346 | |
cf1dfa6b VZ |
4347 | // ---------------------------------------------------------------------------- |
4348 | // adding stuff | |
4349 | // ---------------------------------------------------------------------------- | |
4350 | ||
c801d85f KB |
4351 | void wxListMainWindow::InsertItem( wxListItem &item ) |
4352 | { | |
cf1dfa6b VZ |
4353 | wxASSERT_MSG( !IsVirtual(), _T("can't be used with virtual control") ); |
4354 | ||
4355 | size_t count = GetItemCount(); | |
4356 | wxCHECK_RET( item.m_itemId >= 0 && (size_t)item.m_itemId <= count, | |
4357 | _T("invalid item index") ); | |
4358 | ||
4359 | size_t id = item.m_itemId; | |
4360 | ||
5b077d48 | 4361 | m_dirty = TRUE; |
cf1dfa6b | 4362 | |
5b077d48 | 4363 | int mode = 0; |
cf1dfa6b | 4364 | if ( HasFlag(wxLC_REPORT) ) |
1370703e | 4365 | mode = wxLC_REPORT; |
cf1dfa6b | 4366 | else if ( HasFlag(wxLC_LIST) ) |
1370703e | 4367 | mode = wxLC_LIST; |
cf1dfa6b | 4368 | else if ( HasFlag(wxLC_ICON) ) |
1370703e | 4369 | mode = wxLC_ICON; |
cf1dfa6b | 4370 | else if ( HasFlag(wxLC_SMALL_ICON) ) |
1370703e VZ |
4371 | mode = wxLC_ICON; // no typo |
4372 | else | |
4373 | { | |
4374 | wxFAIL_MSG( _T("unknown mode") ); | |
4375 | } | |
004fd0c8 | 4376 | |
5cd89174 | 4377 | wxListLineData *line = new wxListLineData(this); |
004fd0c8 | 4378 | |
5b077d48 | 4379 | line->SetItem( 0, item ); |
cf1dfa6b VZ |
4380 | |
4381 | m_lines.Insert( line, id ); | |
5cd89174 | 4382 | |
b84839ae | 4383 | m_dirty = TRUE; |
5cd89174 | 4384 | RefreshLines(id, GetItemCount() - 1); |
e1e955e1 | 4385 | } |
c801d85f | 4386 | |
debe6624 | 4387 | void wxListMainWindow::InsertColumn( long col, wxListItem &item ) |
c801d85f | 4388 | { |
5b077d48 | 4389 | m_dirty = TRUE; |
cf1dfa6b | 4390 | if ( HasFlag(wxLC_REPORT) ) |
3db7be80 | 4391 | { |
54442116 VZ |
4392 | if (item.m_width == wxLIST_AUTOSIZE_USEHEADER) |
4393 | item.m_width = GetTextLength( item.m_text ); | |
5b077d48 RR |
4394 | wxListHeaderData *column = new wxListHeaderData( item ); |
4395 | if ((col >= 0) && (col < (int)m_columns.GetCount())) | |
4396 | { | |
24b9f055 VZ |
4397 | wxListHeaderDataList::Node *node = m_columns.Item( col ); |
4398 | m_columns.Insert( node, column ); | |
5b077d48 RR |
4399 | } |
4400 | else | |
4401 | { | |
4402 | m_columns.Append( column ); | |
4403 | } | |
ae409cb8 VZ |
4404 | |
4405 | // invalidate it as it has to be recalculated | |
4406 | m_headerWidth = 0; | |
3db7be80 | 4407 | } |
e1e955e1 | 4408 | } |
c801d85f | 4409 | |
cf1dfa6b VZ |
4410 | // ---------------------------------------------------------------------------- |
4411 | // sorting | |
4412 | // ---------------------------------------------------------------------------- | |
4413 | ||
c801d85f KB |
4414 | wxListCtrlCompare list_ctrl_compare_func_2; |
4415 | long list_ctrl_compare_data; | |
4416 | ||
f6bcfd97 | 4417 | int LINKAGEMODE list_ctrl_compare_func_1( wxListLineData **arg1, wxListLineData **arg2 ) |
c801d85f | 4418 | { |
f6bcfd97 BP |
4419 | wxListLineData *line1 = *arg1; |
4420 | wxListLineData *line2 = *arg2; | |
5b077d48 RR |
4421 | wxListItem item; |
4422 | line1->GetItem( 0, item ); | |
4423 | long data1 = item.m_data; | |
4424 | line2->GetItem( 0, item ); | |
4425 | long data2 = item.m_data; | |
4426 | return list_ctrl_compare_func_2( data1, data2, list_ctrl_compare_data ); | |
e1e955e1 | 4427 | } |
c801d85f KB |
4428 | |
4429 | void wxListMainWindow::SortItems( wxListCtrlCompare fn, long data ) | |
4430 | { | |
5b077d48 RR |
4431 | list_ctrl_compare_func_2 = fn; |
4432 | list_ctrl_compare_data = data; | |
4433 | m_lines.Sort( list_ctrl_compare_func_1 ); | |
af7c1052 | 4434 | m_dirty = TRUE; |
e1e955e1 | 4435 | } |
c801d85f | 4436 | |
cf1dfa6b VZ |
4437 | // ---------------------------------------------------------------------------- |
4438 | // scrolling | |
4439 | // ---------------------------------------------------------------------------- | |
4440 | ||
7c74e7fe SC |
4441 | void wxListMainWindow::OnScroll(wxScrollWinEvent& event) |
4442 | { | |
b54e41c5 VZ |
4443 | // update our idea of which lines are shown when we redraw the window the |
4444 | // next time | |
4445 | ResetVisibleLinesRange(); | |
cf1dfa6b | 4446 | |
29149a64 | 4447 | // FIXME |
3a8c693a | 4448 | #if defined(__WXGTK__) && !defined(__WXUNIVERSAL__) |
29149a64 VZ |
4449 | wxScrolledWindow::OnScroll(event); |
4450 | #else | |
1e6feb95 | 4451 | HandleOnScroll( event ); |
29149a64 | 4452 | #endif |
30954328 | 4453 | |
cf1dfa6b | 4454 | if ( event.GetOrientation() == wxHORIZONTAL && HasHeader() ) |
7c74e7fe | 4455 | { |
3cd94a0d | 4456 | wxGenericListCtrl* lc = GetListCtrl(); |
cf1dfa6b VZ |
4457 | wxCHECK_RET( lc, _T("no listctrl window?") ); |
4458 | ||
afbe906a RR |
4459 | lc->m_headerWin->Refresh(); |
4460 | lc->m_headerWin->Update(); | |
7c74e7fe | 4461 | } |
cf1dfa6b VZ |
4462 | } |
4463 | ||
5cd89174 VZ |
4464 | int wxListMainWindow::GetCountPerPage() const |
4465 | { | |
4466 | if ( !m_linesPerPage ) | |
4467 | { | |
4468 | wxConstCast(this, wxListMainWindow)-> | |
4469 | m_linesPerPage = GetClientSize().y / GetLineHeight(); | |
4470 | } | |
4471 | ||
4472 | return m_linesPerPage; | |
4473 | } | |
4474 | ||
b54e41c5 | 4475 | void wxListMainWindow::GetVisibleLinesRange(size_t *from, size_t *to) |
cf1dfa6b | 4476 | { |
b54e41c5 | 4477 | wxASSERT_MSG( HasFlag(wxLC_REPORT), _T("this is for report mode only") ); |
cf1dfa6b | 4478 | |
b54e41c5 VZ |
4479 | if ( m_lineFrom == (size_t)-1 ) |
4480 | { | |
b54e41c5 | 4481 | size_t count = GetItemCount(); |
6522713c VZ |
4482 | if ( count ) |
4483 | { | |
4484 | m_lineFrom = GetScrollPos(wxVERTICAL); | |
cf1dfa6b | 4485 | |
152c57f2 VZ |
4486 | // this may happen if SetScrollbars() hadn't been called yet |
4487 | if ( m_lineFrom >= count ) | |
bcc0da5c | 4488 | m_lineFrom = count - 1; |
cf1dfa6b | 4489 | |
6522713c VZ |
4490 | // we redraw one extra line but this is needed to make the redrawing |
4491 | // logic work when there is a fractional number of lines on screen | |
4492 | m_lineTo = m_lineFrom + m_linesPerPage; | |
4493 | if ( m_lineTo >= count ) | |
4494 | m_lineTo = count - 1; | |
4495 | } | |
4496 | else // empty control | |
4497 | { | |
4498 | m_lineFrom = 0; | |
4499 | m_lineTo = (size_t)-1; | |
4500 | } | |
cf1dfa6b | 4501 | } |
b54e41c5 | 4502 | |
ae167d2f VZ |
4503 | wxASSERT_MSG( IsEmpty() || |
4504 | (m_lineFrom <= m_lineTo && m_lineTo < GetItemCount()), | |
6b4a8d93 VZ |
4505 | _T("GetVisibleLinesRange() returns incorrect result") ); |
4506 | ||
b54e41c5 VZ |
4507 | if ( from ) |
4508 | *from = m_lineFrom; | |
4509 | if ( to ) | |
4510 | *to = m_lineTo; | |
7c74e7fe SC |
4511 | } |
4512 | ||
c801d85f KB |
4513 | // ------------------------------------------------------------------------------------- |
4514 | // wxListItem | |
4515 | // ------------------------------------------------------------------------------------- | |
4516 | ||
3cd94a0d | 4517 | #if !defined(__WIN32__) |
c801d85f | 4518 | IMPLEMENT_DYNAMIC_CLASS(wxListItem, wxObject) |
3cd94a0d | 4519 | #endif |
c801d85f | 4520 | |
c801d85f | 4521 | // ------------------------------------------------------------------------------------- |
3cd94a0d | 4522 | // wxGenericListCtrl |
c801d85f KB |
4523 | // ------------------------------------------------------------------------------------- |
4524 | ||
3cd94a0d JS |
4525 | IMPLEMENT_DYNAMIC_CLASS(wxGenericListCtrl, wxControl) |
4526 | ||
4527 | #if !defined(__WIN32__) | |
b5a7cdc0 | 4528 | IMPLEMENT_DYNAMIC_CLASS(wxListView, wxListCtrl) |
c801d85f | 4529 | |
0ded6bb6 | 4530 | IMPLEMENT_DYNAMIC_CLASS(wxListEvent, wxNotifyEvent) |
3cd94a0d | 4531 | #endif |
0ded6bb6 | 4532 | |
3cd94a0d JS |
4533 | BEGIN_EVENT_TABLE(wxGenericListCtrl,wxControl) |
4534 | EVT_SIZE(wxGenericListCtrl::OnSize) | |
4535 | EVT_IDLE(wxGenericListCtrl::OnIdle) | |
c801d85f KB |
4536 | END_EVENT_TABLE() |
4537 | ||
b31989e2 JS |
4538 | #if !defined(__WXMSW__) || defined(__WIN16__) || defined(__WXUNIVERSAL__) |
4539 | /* | |
4540 | * wxListCtrl has to be a real class or we have problems with | |
4541 | * the run-time information. | |
4542 | */ | |
4543 | ||
4544 | IMPLEMENT_DYNAMIC_CLASS(wxListCtrl, wxGenericListCtrl) | |
4545 | #endif | |
4546 | ||
3cd94a0d | 4547 | wxGenericListCtrl::wxGenericListCtrl() |
c801d85f | 4548 | { |
9cb07953 JS |
4549 | m_imageListNormal = (wxGenericImageList *) NULL; |
4550 | m_imageListSmall = (wxGenericImageList *) NULL; | |
4551 | m_imageListState = (wxGenericImageList *) NULL; | |
cf1dfa6b VZ |
4552 | |
4553 | m_ownsImageListNormal = | |
4554 | m_ownsImageListSmall = | |
4555 | m_ownsImageListState = FALSE; | |
4556 | ||
5b077d48 RR |
4557 | m_mainWin = (wxListMainWindow*) NULL; |
4558 | m_headerWin = (wxListHeaderWindow*) NULL; | |
c801d85f KB |
4559 | } |
4560 | ||
3cd94a0d | 4561 | wxGenericListCtrl::~wxGenericListCtrl() |
c801d85f | 4562 | { |
cf1dfa6b VZ |
4563 | if (m_ownsImageListNormal) |
4564 | delete m_imageListNormal; | |
4565 | if (m_ownsImageListSmall) | |
4566 | delete m_imageListSmall; | |
4567 | if (m_ownsImageListState) | |
4568 | delete m_imageListState; | |
4569 | } | |
4570 | ||
3cd94a0d | 4571 | void wxGenericListCtrl::CreateHeaderWindow() |
cf1dfa6b VZ |
4572 | { |
4573 | m_headerWin = new wxListHeaderWindow | |
4574 | ( | |
4575 | this, -1, m_mainWin, | |
4576 | wxPoint(0, 0), | |
4577 | wxSize(GetClientSize().x, HEADER_HEIGHT), | |
4578 | wxTAB_TRAVERSAL | |
4579 | ); | |
c801d85f KB |
4580 | } |
4581 | ||
3cd94a0d | 4582 | bool wxGenericListCtrl::Create(wxWindow *parent, |
25e3a937 VZ |
4583 | wxWindowID id, |
4584 | const wxPoint &pos, | |
4585 | const wxSize &size, | |
4586 | long style, | |
25e3a937 | 4587 | const wxValidator &validator, |
25e3a937 | 4588 | const wxString &name) |
c801d85f | 4589 | { |
cf1dfa6b VZ |
4590 | m_imageListNormal = |
4591 | m_imageListSmall = | |
9cb07953 | 4592 | m_imageListState = (wxGenericImageList *) NULL; |
cf1dfa6b VZ |
4593 | m_ownsImageListNormal = |
4594 | m_ownsImageListSmall = | |
4595 | m_ownsImageListState = FALSE; | |
4596 | ||
5b077d48 RR |
4597 | m_mainWin = (wxListMainWindow*) NULL; |
4598 | m_headerWin = (wxListHeaderWindow*) NULL; | |
bd8289c1 | 4599 | |
b54e41c5 | 4600 | if ( !(style & wxLC_MASK_TYPE) ) |
5b077d48 | 4601 | { |
25e3a937 | 4602 | style = style | wxLC_LIST; |
5b077d48 | 4603 | } |
f6bcfd97 | 4604 | |
07215d86 | 4605 | if ( !wxControl::Create( parent, id, pos, size, style, validator, name ) ) |
cf1dfa6b | 4606 | return FALSE; |
f6bcfd97 | 4607 | |
b54e41c5 VZ |
4608 | // don't create the inner window with the border |
4609 | style &= ~wxSUNKEN_BORDER; | |
bd8289c1 | 4610 | |
25e3a937 | 4611 | m_mainWin = new wxListMainWindow( this, -1, wxPoint(0,0), size, style ); |
bd8289c1 | 4612 | |
b54e41c5 | 4613 | if ( HasFlag(wxLC_REPORT) ) |
ea451729 | 4614 | { |
cf1dfa6b VZ |
4615 | CreateHeaderWindow(); |
4616 | ||
b54e41c5 | 4617 | if ( HasFlag(wxLC_NO_HEADER) ) |
cf1dfa6b VZ |
4618 | { |
4619 | // VZ: why do we create it at all then? | |
ea451729 | 4620 | m_headerWin->Show( FALSE ); |
cf1dfa6b | 4621 | } |
ea451729 | 4622 | } |
bd8289c1 | 4623 | |
cf1dfa6b | 4624 | return TRUE; |
e1e955e1 | 4625 | } |
c801d85f | 4626 | |
3cd94a0d | 4627 | void wxGenericListCtrl::SetSingleStyle( long style, bool add ) |
c801d85f | 4628 | { |
b54e41c5 VZ |
4629 | wxASSERT_MSG( !(style & wxLC_VIRTUAL), |
4630 | _T("wxLC_VIRTUAL can't be [un]set") ); | |
4631 | ||
f03fc89f | 4632 | long flag = GetWindowStyle(); |
bd8289c1 | 4633 | |
5b077d48 RR |
4634 | if (add) |
4635 | { | |
cf1dfa6b | 4636 | if (style & wxLC_MASK_TYPE) |
b54e41c5 | 4637 | flag &= ~(wxLC_MASK_TYPE | wxLC_VIRTUAL); |
cf1dfa6b VZ |
4638 | if (style & wxLC_MASK_ALIGN) |
4639 | flag &= ~wxLC_MASK_ALIGN; | |
4640 | if (style & wxLC_MASK_SORT) | |
4641 | flag &= ~wxLC_MASK_SORT; | |
5b077d48 | 4642 | } |
c801d85f | 4643 | |
5b077d48 RR |
4644 | if (add) |
4645 | { | |
4646 | flag |= style; | |
4647 | } | |
4648 | else | |
4649 | { | |
cf1dfa6b | 4650 | flag &= ~style; |
5b077d48 | 4651 | } |
bd8289c1 | 4652 | |
5b077d48 | 4653 | SetWindowStyleFlag( flag ); |
e1e955e1 | 4654 | } |
c801d85f | 4655 | |
3cd94a0d | 4656 | void wxGenericListCtrl::SetWindowStyleFlag( long flag ) |
c801d85f | 4657 | { |
121a3581 RR |
4658 | if (m_mainWin) |
4659 | { | |
4660 | m_mainWin->DeleteEverything(); | |
c801d85f | 4661 | |
a95cdab8 VZ |
4662 | // has the header visibility changed? |
4663 | bool hasHeader = HasFlag(wxLC_REPORT) && !HasFlag(wxLC_NO_HEADER), | |
4664 | willHaveHeader = (flag & wxLC_REPORT) && !(flag & wxLC_NO_HEADER); | |
c801d85f | 4665 | |
a95cdab8 | 4666 | if ( hasHeader != willHaveHeader ) |
5b077d48 | 4667 | { |
a95cdab8 VZ |
4668 | // toggle it |
4669 | if ( hasHeader ) | |
4670 | { | |
4671 | if ( m_headerWin ) | |
4672 | { | |
4673 | // don't delete, just hide, as we can reuse it later | |
4674 | m_headerWin->Show(FALSE); | |
4675 | } | |
4676 | //else: nothing to do | |
4677 | } | |
4678 | else // must show header | |
5b077d48 | 4679 | { |
121a3581 RR |
4680 | if (!m_headerWin) |
4681 | { | |
cf1dfa6b | 4682 | CreateHeaderWindow(); |
121a3581 | 4683 | } |
a95cdab8 | 4684 | else // already have it, just show |
004fd0c8 | 4685 | { |
a95cdab8 | 4686 | m_headerWin->Show( TRUE ); |
004fd0c8 | 4687 | } |
5b077d48 | 4688 | } |
a95cdab8 VZ |
4689 | |
4690 | ResizeReportView(willHaveHeader); | |
bffa1c77 | 4691 | } |
e1e955e1 | 4692 | } |
004fd0c8 | 4693 | |
5b077d48 | 4694 | wxWindow::SetWindowStyleFlag( flag ); |
e1e955e1 | 4695 | } |
c801d85f | 4696 | |
3cd94a0d | 4697 | bool wxGenericListCtrl::GetColumn(int col, wxListItem &item) const |
c801d85f | 4698 | { |
5b077d48 RR |
4699 | m_mainWin->GetColumn( col, item ); |
4700 | return TRUE; | |
e1e955e1 | 4701 | } |
c801d85f | 4702 | |
3cd94a0d | 4703 | bool wxGenericListCtrl::SetColumn( int col, wxListItem& item ) |
c801d85f | 4704 | { |
5b077d48 RR |
4705 | m_mainWin->SetColumn( col, item ); |
4706 | return TRUE; | |
e1e955e1 | 4707 | } |
c801d85f | 4708 | |
3cd94a0d | 4709 | int wxGenericListCtrl::GetColumnWidth( int col ) const |
c801d85f | 4710 | { |
5b077d48 | 4711 | return m_mainWin->GetColumnWidth( col ); |
e1e955e1 | 4712 | } |
c801d85f | 4713 | |
3cd94a0d | 4714 | bool wxGenericListCtrl::SetColumnWidth( int col, int width ) |
c801d85f | 4715 | { |
5b077d48 RR |
4716 | m_mainWin->SetColumnWidth( col, width ); |
4717 | return TRUE; | |
e1e955e1 | 4718 | } |
c801d85f | 4719 | |
3cd94a0d | 4720 | int wxGenericListCtrl::GetCountPerPage() const |
c801d85f KB |
4721 | { |
4722 | return m_mainWin->GetCountPerPage(); // different from Windows ? | |
e1e955e1 | 4723 | } |
c801d85f | 4724 | |
3cd94a0d | 4725 | bool wxGenericListCtrl::GetItem( wxListItem &info ) const |
c801d85f | 4726 | { |
5b077d48 RR |
4727 | m_mainWin->GetItem( info ); |
4728 | return TRUE; | |
e1e955e1 | 4729 | } |
c801d85f | 4730 | |
3cd94a0d | 4731 | bool wxGenericListCtrl::SetItem( wxListItem &info ) |
c801d85f | 4732 | { |
5b077d48 RR |
4733 | m_mainWin->SetItem( info ); |
4734 | return TRUE; | |
e1e955e1 | 4735 | } |
c801d85f | 4736 | |
3cd94a0d | 4737 | long wxGenericListCtrl::SetItem( long index, int col, const wxString& label, int imageId ) |
c801d85f | 4738 | { |
5b077d48 RR |
4739 | wxListItem info; |
4740 | info.m_text = label; | |
4741 | info.m_mask = wxLIST_MASK_TEXT; | |
4742 | info.m_itemId = index; | |
4743 | info.m_col = col; | |
4744 | if ( imageId > -1 ) | |
4745 | { | |
4746 | info.m_image = imageId; | |
4747 | info.m_mask |= wxLIST_MASK_IMAGE; | |
4748 | }; | |
4749 | m_mainWin->SetItem(info); | |
4750 | return TRUE; | |
e1e955e1 | 4751 | } |
c801d85f | 4752 | |
3cd94a0d | 4753 | int wxGenericListCtrl::GetItemState( long item, long stateMask ) const |
c801d85f | 4754 | { |
5b077d48 | 4755 | return m_mainWin->GetItemState( item, stateMask ); |
e1e955e1 | 4756 | } |
c801d85f | 4757 | |
3cd94a0d | 4758 | bool wxGenericListCtrl::SetItemState( long item, long state, long stateMask ) |
c801d85f | 4759 | { |
5b077d48 RR |
4760 | m_mainWin->SetItemState( item, state, stateMask ); |
4761 | return TRUE; | |
e1e955e1 | 4762 | } |
c801d85f | 4763 | |
3cd94a0d | 4764 | bool wxGenericListCtrl::SetItemImage( long item, int image, int WXUNUSED(selImage) ) |
c801d85f | 4765 | { |
5b077d48 RR |
4766 | wxListItem info; |
4767 | info.m_image = image; | |
4768 | info.m_mask = wxLIST_MASK_IMAGE; | |
4769 | info.m_itemId = item; | |
4770 | m_mainWin->SetItem( info ); | |
4771 | return TRUE; | |
e1e955e1 | 4772 | } |
c801d85f | 4773 | |
3cd94a0d | 4774 | wxString wxGenericListCtrl::GetItemText( long item ) const |
c801d85f | 4775 | { |
62d89eb4 | 4776 | return m_mainWin->GetItemText(item); |
e1e955e1 | 4777 | } |
c801d85f | 4778 | |
3cd94a0d | 4779 | void wxGenericListCtrl::SetItemText( long item, const wxString& str ) |
c801d85f | 4780 | { |
62d89eb4 | 4781 | m_mainWin->SetItemText(item, str); |
e1e955e1 | 4782 | } |
c801d85f | 4783 | |
3cd94a0d | 4784 | long wxGenericListCtrl::GetItemData( long item ) const |
c801d85f | 4785 | { |
5b077d48 RR |
4786 | wxListItem info; |
4787 | info.m_itemId = item; | |
4788 | m_mainWin->GetItem( info ); | |
4789 | return info.m_data; | |
e1e955e1 | 4790 | } |
c801d85f | 4791 | |
3cd94a0d | 4792 | bool wxGenericListCtrl::SetItemData( long item, long data ) |
c801d85f | 4793 | { |
5b077d48 RR |
4794 | wxListItem info; |
4795 | info.m_mask = wxLIST_MASK_DATA; | |
4796 | info.m_itemId = item; | |
4797 | info.m_data = data; | |
4798 | m_mainWin->SetItem( info ); | |
4799 | return TRUE; | |
e1e955e1 | 4800 | } |
c801d85f | 4801 | |
3cd94a0d | 4802 | bool wxGenericListCtrl::GetItemRect( long item, wxRect &rect, int WXUNUSED(code) ) const |
c801d85f | 4803 | { |
5b077d48 RR |
4804 | m_mainWin->GetItemRect( item, rect ); |
4805 | return TRUE; | |
e1e955e1 | 4806 | } |
c801d85f | 4807 | |
3cd94a0d | 4808 | bool wxGenericListCtrl::GetItemPosition( long item, wxPoint& pos ) const |
c801d85f | 4809 | { |
5b077d48 RR |
4810 | m_mainWin->GetItemPosition( item, pos ); |
4811 | return TRUE; | |
e1e955e1 | 4812 | } |
c801d85f | 4813 | |
3cd94a0d | 4814 | bool wxGenericListCtrl::SetItemPosition( long WXUNUSED(item), const wxPoint& WXUNUSED(pos) ) |
c801d85f | 4815 | { |
5b077d48 | 4816 | return 0; |
e1e955e1 | 4817 | } |
c801d85f | 4818 | |
3cd94a0d | 4819 | int wxGenericListCtrl::GetItemCount() const |
c801d85f | 4820 | { |
5b077d48 | 4821 | return m_mainWin->GetItemCount(); |
e1e955e1 | 4822 | } |
c801d85f | 4823 | |
3cd94a0d | 4824 | int wxGenericListCtrl::GetColumnCount() const |
92976ab6 | 4825 | { |
5b077d48 | 4826 | return m_mainWin->GetColumnCount(); |
92976ab6 RR |
4827 | } |
4828 | ||
3cd94a0d | 4829 | void wxGenericListCtrl::SetItemSpacing( int spacing, bool isSmall ) |
33d0b396 | 4830 | { |
5b077d48 | 4831 | m_mainWin->SetItemSpacing( spacing, isSmall ); |
e1e955e1 | 4832 | } |
33d0b396 | 4833 | |
3cd94a0d | 4834 | int wxGenericListCtrl::GetItemSpacing( bool isSmall ) const |
c801d85f | 4835 | { |
5b077d48 | 4836 | return m_mainWin->GetItemSpacing( isSmall ); |
e1e955e1 | 4837 | } |
c801d85f | 4838 | |
3cd94a0d | 4839 | void wxGenericListCtrl::SetItemTextColour( long item, const wxColour &col ) |
5b98eb2f RL |
4840 | { |
4841 | wxListItem info; | |
4842 | info.m_itemId = item; | |
4843 | info.SetTextColour( col ); | |
4844 | m_mainWin->SetItem( info ); | |
4845 | } | |
4846 | ||
3cd94a0d | 4847 | wxColour wxGenericListCtrl::GetItemTextColour( long item ) const |
5b98eb2f RL |
4848 | { |
4849 | wxListItem info; | |
4850 | info.m_itemId = item; | |
4851 | m_mainWin->GetItem( info ); | |
4852 | return info.GetTextColour(); | |
4853 | } | |
4854 | ||
3cd94a0d | 4855 | void wxGenericListCtrl::SetItemBackgroundColour( long item, const wxColour &col ) |
5b98eb2f RL |
4856 | { |
4857 | wxListItem info; | |
4858 | info.m_itemId = item; | |
4859 | info.SetBackgroundColour( col ); | |
4860 | m_mainWin->SetItem( info ); | |
4861 | } | |
4862 | ||
3cd94a0d | 4863 | wxColour wxGenericListCtrl::GetItemBackgroundColour( long item ) const |
5b98eb2f RL |
4864 | { |
4865 | wxListItem info; | |
4866 | info.m_itemId = item; | |
4867 | m_mainWin->GetItem( info ); | |
4868 | return info.GetBackgroundColour(); | |
4869 | } | |
4870 | ||
3cd94a0d | 4871 | int wxGenericListCtrl::GetSelectedItemCount() const |
c801d85f | 4872 | { |
5b077d48 | 4873 | return m_mainWin->GetSelectedItemCount(); |
e1e955e1 | 4874 | } |
c801d85f | 4875 | |
3cd94a0d | 4876 | wxColour wxGenericListCtrl::GetTextColour() const |
c801d85f | 4877 | { |
0530737d | 4878 | return GetForegroundColour(); |
e1e955e1 | 4879 | } |
c801d85f | 4880 | |
3cd94a0d | 4881 | void wxGenericListCtrl::SetTextColour(const wxColour& col) |
c801d85f | 4882 | { |
0530737d | 4883 | SetForegroundColour(col); |
e1e955e1 | 4884 | } |
c801d85f | 4885 | |
3cd94a0d | 4886 | long wxGenericListCtrl::GetTopItem() const |
c801d85f | 4887 | { |
5b077d48 | 4888 | return 0; |
e1e955e1 | 4889 | } |
c801d85f | 4890 | |
3cd94a0d | 4891 | long wxGenericListCtrl::GetNextItem( long item, int geom, int state ) const |
c801d85f | 4892 | { |
5b077d48 | 4893 | return m_mainWin->GetNextItem( item, geom, state ); |
e1e955e1 | 4894 | } |
c801d85f | 4895 | |
9cb07953 | 4896 | wxGenericImageList *wxGenericListCtrl::GetImageList(int which) const |
c801d85f | 4897 | { |
5b077d48 RR |
4898 | if (which == wxIMAGE_LIST_NORMAL) |
4899 | { | |
4900 | return m_imageListNormal; | |
4901 | } | |
4902 | else if (which == wxIMAGE_LIST_SMALL) | |
4903 | { | |
4904 | return m_imageListSmall; | |
4905 | } | |
4906 | else if (which == wxIMAGE_LIST_STATE) | |
4907 | { | |
4908 | return m_imageListState; | |
4909 | } | |
9cb07953 | 4910 | return (wxGenericImageList *) NULL; |
e1e955e1 | 4911 | } |
c801d85f | 4912 | |
9cb07953 | 4913 | void wxGenericListCtrl::SetImageList( wxGenericImageList *imageList, int which ) |
c801d85f | 4914 | { |
2e12c11a VS |
4915 | if ( which == wxIMAGE_LIST_NORMAL ) |
4916 | { | |
4917 | if (m_ownsImageListNormal) delete m_imageListNormal; | |
4918 | m_imageListNormal = imageList; | |
4919 | m_ownsImageListNormal = FALSE; | |
4920 | } | |
4921 | else if ( which == wxIMAGE_LIST_SMALL ) | |
4922 | { | |
4923 | if (m_ownsImageListSmall) delete m_imageListSmall; | |
4924 | m_imageListSmall = imageList; | |
4925 | m_ownsImageListSmall = FALSE; | |
4926 | } | |
4927 | else if ( which == wxIMAGE_LIST_STATE ) | |
4928 | { | |
4929 | if (m_ownsImageListState) delete m_imageListState; | |
4930 | m_imageListState = imageList; | |
4931 | m_ownsImageListState = FALSE; | |
4932 | } | |
4933 | ||
5b077d48 | 4934 | m_mainWin->SetImageList( imageList, which ); |
e1e955e1 | 4935 | } |
c801d85f | 4936 | |
9cb07953 | 4937 | void wxGenericListCtrl::AssignImageList(wxGenericImageList *imageList, int which) |
2e12c11a VS |
4938 | { |
4939 | SetImageList(imageList, which); | |
4940 | if ( which == wxIMAGE_LIST_NORMAL ) | |
4941 | m_ownsImageListNormal = TRUE; | |
4942 | else if ( which == wxIMAGE_LIST_SMALL ) | |
4943 | m_ownsImageListSmall = TRUE; | |
4944 | else if ( which == wxIMAGE_LIST_STATE ) | |
4945 | m_ownsImageListState = TRUE; | |
4946 | } | |
4947 | ||
3cd94a0d | 4948 | bool wxGenericListCtrl::Arrange( int WXUNUSED(flag) ) |
c801d85f | 4949 | { |
5b077d48 | 4950 | return 0; |
e1e955e1 | 4951 | } |
c801d85f | 4952 | |
3cd94a0d | 4953 | bool wxGenericListCtrl::DeleteItem( long item ) |
c801d85f | 4954 | { |
5b077d48 RR |
4955 | m_mainWin->DeleteItem( item ); |
4956 | return TRUE; | |
e1e955e1 | 4957 | } |
c801d85f | 4958 | |
3cd94a0d | 4959 | bool wxGenericListCtrl::DeleteAllItems() |
c801d85f | 4960 | { |
5b077d48 RR |
4961 | m_mainWin->DeleteAllItems(); |
4962 | return TRUE; | |
e1e955e1 | 4963 | } |
c801d85f | 4964 | |
3cd94a0d | 4965 | bool wxGenericListCtrl::DeleteAllColumns() |
bd8289c1 | 4966 | { |
24b9f055 VZ |
4967 | size_t count = m_mainWin->m_columns.GetCount(); |
4968 | for ( size_t n = 0; n < count; n++ ) | |
85cdcb7a | 4969 | DeleteColumn(0); |
bffa1c77 | 4970 | |
5b077d48 | 4971 | return TRUE; |
4f22cf8d RR |
4972 | } |
4973 | ||
3cd94a0d | 4974 | void wxGenericListCtrl::ClearAll() |
4f22cf8d | 4975 | { |
5b077d48 | 4976 | m_mainWin->DeleteEverything(); |
bd8289c1 VZ |
4977 | } |
4978 | ||
3cd94a0d | 4979 | bool wxGenericListCtrl::DeleteColumn( int col ) |
c801d85f | 4980 | { |
5b077d48 | 4981 | m_mainWin->DeleteColumn( col ); |
40c08808 VZ |
4982 | |
4983 | // if we don't have the header any longer, we need to relayout the window | |
4984 | if ( !GetColumnCount() ) | |
4985 | { | |
4986 | ResizeReportView(FALSE /* no header */); | |
4987 | } | |
4988 | ||
5b077d48 | 4989 | return TRUE; |
e1e955e1 | 4990 | } |
c801d85f | 4991 | |
3cd94a0d | 4992 | void wxGenericListCtrl::Edit( long item ) |
c801d85f | 4993 | { |
cf1dfa6b | 4994 | m_mainWin->EditLabel( item ); |
e1e955e1 | 4995 | } |
c801d85f | 4996 | |
3cd94a0d | 4997 | bool wxGenericListCtrl::EnsureVisible( long item ) |
c801d85f | 4998 | { |
5b077d48 RR |
4999 | m_mainWin->EnsureVisible( item ); |
5000 | return TRUE; | |
e1e955e1 | 5001 | } |
c801d85f | 5002 | |
3cd94a0d | 5003 | long wxGenericListCtrl::FindItem( long start, const wxString& str, bool partial ) |
c801d85f | 5004 | { |
5b077d48 | 5005 | return m_mainWin->FindItem( start, str, partial ); |
e1e955e1 | 5006 | } |
c801d85f | 5007 | |
3cd94a0d | 5008 | long wxGenericListCtrl::FindItem( long start, long data ) |
c801d85f | 5009 | { |
5b077d48 | 5010 | return m_mainWin->FindItem( start, data ); |
e1e955e1 | 5011 | } |
c801d85f | 5012 | |
3cd94a0d | 5013 | long wxGenericListCtrl::FindItem( long WXUNUSED(start), const wxPoint& WXUNUSED(pt), |
debe6624 | 5014 | int WXUNUSED(direction)) |
c801d85f | 5015 | { |
5b077d48 | 5016 | return 0; |
e1e955e1 | 5017 | } |
c801d85f | 5018 | |
3cd94a0d | 5019 | long wxGenericListCtrl::HitTest( const wxPoint &point, int &flags ) |
c801d85f | 5020 | { |
5b077d48 | 5021 | return m_mainWin->HitTest( (int)point.x, (int)point.y, flags ); |
e1e955e1 | 5022 | } |
c801d85f | 5023 | |
3cd94a0d | 5024 | long wxGenericListCtrl::InsertItem( wxListItem& info ) |
c801d85f | 5025 | { |
5b077d48 | 5026 | m_mainWin->InsertItem( info ); |
2ebcd5f5 | 5027 | return info.m_itemId; |
e1e955e1 | 5028 | } |
c801d85f | 5029 | |
3cd94a0d | 5030 | long wxGenericListCtrl::InsertItem( long index, const wxString &label ) |
c801d85f | 5031 | { |
51cc4dad RR |
5032 | wxListItem info; |
5033 | info.m_text = label; | |
5034 | info.m_mask = wxLIST_MASK_TEXT; | |
5035 | info.m_itemId = index; | |
5036 | return InsertItem( info ); | |
e1e955e1 | 5037 | } |
c801d85f | 5038 | |
3cd94a0d | 5039 | long wxGenericListCtrl::InsertItem( long index, int imageIndex ) |
c801d85f | 5040 | { |
51cc4dad RR |
5041 | wxListItem info; |
5042 | info.m_mask = wxLIST_MASK_IMAGE; | |
5043 | info.m_image = imageIndex; | |
5044 | info.m_itemId = index; | |
5045 | return InsertItem( info ); | |
e1e955e1 | 5046 | } |
c801d85f | 5047 | |
3cd94a0d | 5048 | long wxGenericListCtrl::InsertItem( long index, const wxString &label, int imageIndex ) |
c801d85f | 5049 | { |
51cc4dad RR |
5050 | wxListItem info; |
5051 | info.m_text = label; | |
5052 | info.m_image = imageIndex; | |
5053 | info.m_mask = wxLIST_MASK_TEXT | wxLIST_MASK_IMAGE; | |
5054 | info.m_itemId = index; | |
5055 | return InsertItem( info ); | |
e1e955e1 | 5056 | } |
c801d85f | 5057 | |
3cd94a0d | 5058 | long wxGenericListCtrl::InsertColumn( long col, wxListItem &item ) |
c801d85f | 5059 | { |
40c08808 VZ |
5060 | wxCHECK_MSG( m_headerWin, -1, _T("can't add column in non report mode") ); |
5061 | ||
51cc4dad | 5062 | m_mainWin->InsertColumn( col, item ); |
40c08808 VZ |
5063 | |
5064 | // if we hadn't had header before and have it now we need to relayout the | |
5065 | // window | |
5066 | if ( GetColumnCount() == 1 ) | |
5067 | { | |
5068 | ResizeReportView(TRUE /* have header */); | |
5069 | } | |
5070 | ||
d3e90957 | 5071 | m_headerWin->Refresh(); |
25e3a937 | 5072 | |
51cc4dad | 5073 | return 0; |
e1e955e1 | 5074 | } |
c801d85f | 5075 | |
3cd94a0d | 5076 | long wxGenericListCtrl::InsertColumn( long col, const wxString &heading, |
debe6624 | 5077 | int format, int width ) |
c801d85f | 5078 | { |
51cc4dad RR |
5079 | wxListItem item; |
5080 | item.m_mask = wxLIST_MASK_TEXT | wxLIST_MASK_FORMAT; | |
5081 | item.m_text = heading; | |
5082 | if (width >= -2) | |
5083 | { | |
5084 | item.m_mask |= wxLIST_MASK_WIDTH; | |
5085 | item.m_width = width; | |
5086 | } | |
5087 | item.m_format = format; | |
c801d85f | 5088 | |
51cc4dad | 5089 | return InsertColumn( col, item ); |
e1e955e1 | 5090 | } |
c801d85f | 5091 | |
3cd94a0d | 5092 | bool wxGenericListCtrl::ScrollList( int WXUNUSED(dx), int WXUNUSED(dy) ) |
c801d85f | 5093 | { |
51cc4dad | 5094 | return 0; |
e1e955e1 | 5095 | } |
c801d85f KB |
5096 | |
5097 | // Sort items. | |
5098 | // fn is a function which takes 3 long arguments: item1, item2, data. | |
5099 | // item1 is the long data associated with a first item (NOT the index). | |
5100 | // item2 is the long data associated with a second item (NOT the index). | |
5101 | // data is the same value as passed to SortItems. | |
5102 | // The return value is a negative number if the first item should precede the second | |
5103 | // item, a positive number of the second item should precede the first, | |
5104 | // or zero if the two items are equivalent. | |
5105 | // data is arbitrary data to be passed to the sort function. | |
5106 | ||
3cd94a0d | 5107 | bool wxGenericListCtrl::SortItems( wxListCtrlCompare fn, long data ) |
c801d85f | 5108 | { |
51cc4dad RR |
5109 | m_mainWin->SortItems( fn, data ); |
5110 | return TRUE; | |
e1e955e1 | 5111 | } |
c801d85f | 5112 | |
cf1dfa6b | 5113 | // ---------------------------------------------------------------------------- |
b54e41c5 | 5114 | // event handlers |
cf1dfa6b VZ |
5115 | // ---------------------------------------------------------------------------- |
5116 | ||
3cd94a0d | 5117 | void wxGenericListCtrl::OnSize(wxSizeEvent& WXUNUSED(event)) |
53010e52 | 5118 | { |
b54e41c5 | 5119 | if ( !m_mainWin ) |
cf1dfa6b | 5120 | return; |
53010e52 | 5121 | |
a95cdab8 VZ |
5122 | ResizeReportView(m_mainWin->HasHeader()); |
5123 | ||
5124 | m_mainWin->RecalculatePositions(); | |
5125 | } | |
5126 | ||
3cd94a0d | 5127 | void wxGenericListCtrl::ResizeReportView(bool showHeader) |
a95cdab8 | 5128 | { |
b54e41c5 | 5129 | int cw, ch; |
51cc4dad | 5130 | GetClientSize( &cw, &ch ); |
bd8289c1 | 5131 | |
a95cdab8 | 5132 | if ( showHeader ) |
51cc4dad | 5133 | { |
cf1dfa6b VZ |
5134 | m_headerWin->SetSize( 0, 0, cw, HEADER_HEIGHT ); |
5135 | m_mainWin->SetSize( 0, HEADER_HEIGHT + 1, cw, ch - HEADER_HEIGHT - 1 ); | |
51cc4dad | 5136 | } |
cf1dfa6b | 5137 | else // no header window |
51cc4dad | 5138 | { |
cf1dfa6b | 5139 | m_mainWin->SetSize( 0, 0, cw, ch ); |
51cc4dad | 5140 | } |
b54e41c5 | 5141 | } |
cf1dfa6b | 5142 | |
3cd94a0d | 5143 | void wxGenericListCtrl::OnIdle( wxIdleEvent & event ) |
b54e41c5 VZ |
5144 | { |
5145 | event.Skip(); | |
f6bcfd97 | 5146 | |
b54e41c5 VZ |
5147 | // do it only if needed |
5148 | if ( !m_mainWin->m_dirty ) | |
5149 | return; | |
5150 | ||
5151 | m_mainWin->RecalculatePositions(); | |
e1e955e1 | 5152 | } |
53010e52 | 5153 | |
cf1dfa6b VZ |
5154 | // ---------------------------------------------------------------------------- |
5155 | // font/colours | |
5156 | // ---------------------------------------------------------------------------- | |
5157 | ||
3cd94a0d | 5158 | bool wxGenericListCtrl::SetBackgroundColour( const wxColour &colour ) |
bd8289c1 | 5159 | { |
51cc4dad RR |
5160 | if (m_mainWin) |
5161 | { | |
5162 | m_mainWin->SetBackgroundColour( colour ); | |
5163 | m_mainWin->m_dirty = TRUE; | |
5164 | } | |
004fd0c8 | 5165 | |
f03fc89f | 5166 | return TRUE; |
e4d06860 RR |
5167 | } |
5168 | ||
3cd94a0d | 5169 | bool wxGenericListCtrl::SetForegroundColour( const wxColour &colour ) |
bd8289c1 | 5170 | { |
f03fc89f VZ |
5171 | if ( !wxWindow::SetForegroundColour( colour ) ) |
5172 | return FALSE; | |
004fd0c8 | 5173 | |
51cc4dad RR |
5174 | if (m_mainWin) |
5175 | { | |
5176 | m_mainWin->SetForegroundColour( colour ); | |
5177 | m_mainWin->m_dirty = TRUE; | |
5178 | } | |
004fd0c8 | 5179 | |
51cc4dad RR |
5180 | if (m_headerWin) |
5181 | { | |
5182 | m_headerWin->SetForegroundColour( colour ); | |
5183 | } | |
f03fc89f VZ |
5184 | |
5185 | return TRUE; | |
e4d06860 | 5186 | } |
bd8289c1 | 5187 | |
3cd94a0d | 5188 | bool wxGenericListCtrl::SetFont( const wxFont &font ) |
bd8289c1 | 5189 | { |
f03fc89f VZ |
5190 | if ( !wxWindow::SetFont( font ) ) |
5191 | return FALSE; | |
004fd0c8 | 5192 | |
51cc4dad RR |
5193 | if (m_mainWin) |
5194 | { | |
5195 | m_mainWin->SetFont( font ); | |
5196 | m_mainWin->m_dirty = TRUE; | |
5197 | } | |
004fd0c8 | 5198 | |
51cc4dad RR |
5199 | if (m_headerWin) |
5200 | { | |
5201 | m_headerWin->SetFont( font ); | |
5202 | } | |
f03fc89f VZ |
5203 | |
5204 | return TRUE; | |
e4d06860 | 5205 | } |
c801d85f | 5206 | |
cf1dfa6b VZ |
5207 | // ---------------------------------------------------------------------------- |
5208 | // methods forwarded to m_mainWin | |
5209 | // ---------------------------------------------------------------------------- | |
5210 | ||
efbb7287 VZ |
5211 | #if wxUSE_DRAG_AND_DROP |
5212 | ||
3cd94a0d | 5213 | void wxGenericListCtrl::SetDropTarget( wxDropTarget *dropTarget ) |
efbb7287 VZ |
5214 | { |
5215 | m_mainWin->SetDropTarget( dropTarget ); | |
5216 | } | |
5217 | ||
3cd94a0d | 5218 | wxDropTarget *wxGenericListCtrl::GetDropTarget() const |
efbb7287 VZ |
5219 | { |
5220 | return m_mainWin->GetDropTarget(); | |
5221 | } | |
5222 | ||
5223 | #endif // wxUSE_DRAG_AND_DROP | |
5224 | ||
3cd94a0d | 5225 | bool wxGenericListCtrl::SetCursor( const wxCursor &cursor ) |
efbb7287 VZ |
5226 | { |
5227 | return m_mainWin ? m_mainWin->wxWindow::SetCursor(cursor) : FALSE; | |
5228 | } | |
5229 | ||
3cd94a0d | 5230 | wxColour wxGenericListCtrl::GetBackgroundColour() const |
efbb7287 VZ |
5231 | { |
5232 | return m_mainWin ? m_mainWin->GetBackgroundColour() : wxColour(); | |
5233 | } | |
5234 | ||
3cd94a0d | 5235 | wxColour wxGenericListCtrl::GetForegroundColour() const |
efbb7287 VZ |
5236 | { |
5237 | return m_mainWin ? m_mainWin->GetForegroundColour() : wxColour(); | |
5238 | } | |
5239 | ||
3cd94a0d | 5240 | bool wxGenericListCtrl::DoPopupMenu( wxMenu *menu, int x, int y ) |
efbb7287 | 5241 | { |
3a8c693a | 5242 | #if wxUSE_MENUS |
efbb7287 | 5243 | return m_mainWin->PopupMenu( menu, x, y ); |
3a8c693a VZ |
5244 | #else |
5245 | return FALSE; | |
5246 | #endif // wxUSE_MENUS | |
efbb7287 VZ |
5247 | } |
5248 | ||
3cd94a0d | 5249 | void wxGenericListCtrl::SetFocus() |
efbb7287 VZ |
5250 | { |
5251 | /* The test in window.cpp fails as we are a composite | |
5252 | window, so it checks against "this", but not m_mainWin. */ | |
5253 | if ( FindFocus() != this ) | |
5254 | m_mainWin->SetFocus(); | |
5255 | } | |
1e6feb95 | 5256 | |
2c1f73ee VZ |
5257 | // ---------------------------------------------------------------------------- |
5258 | // virtual list control support | |
5259 | // ---------------------------------------------------------------------------- | |
5260 | ||
3cd94a0d | 5261 | wxString wxGenericListCtrl::OnGetItemText(long WXUNUSED(item), long WXUNUSED(col)) const |
2c1f73ee VZ |
5262 | { |
5263 | // this is a pure virtual function, in fact - which is not really pure | |
5264 | // because the controls which are not virtual don't need to implement it | |
3cd94a0d | 5265 | wxFAIL_MSG( _T("wxGenericListCtrl::OnGetItemText not supposed to be called") ); |
2c1f73ee VZ |
5266 | |
5267 | return wxEmptyString; | |
5268 | } | |
5269 | ||
3cd94a0d | 5270 | int wxGenericListCtrl::OnGetItemImage(long WXUNUSED(item)) const |
2c1f73ee VZ |
5271 | { |
5272 | // same as above | |
3cd94a0d | 5273 | wxFAIL_MSG( _T("wxGenericListCtrl::OnGetItemImage not supposed to be called") ); |
2c1f73ee VZ |
5274 | |
5275 | return -1; | |
5276 | } | |
5277 | ||
3cd94a0d | 5278 | wxListItemAttr *wxGenericListCtrl::OnGetItemAttr(long item) const |
6c02c329 VZ |
5279 | { |
5280 | wxASSERT_MSG( item >= 0 && item < GetItemCount(), | |
5281 | _T("invalid item index in OnGetItemAttr()") ); | |
5282 | ||
5283 | // no attributes by default | |
5284 | return NULL; | |
5285 | } | |
5286 | ||
3cd94a0d | 5287 | void wxGenericListCtrl::SetItemCount(long count) |
2c1f73ee VZ |
5288 | { |
5289 | wxASSERT_MSG( IsVirtual(), _T("this is for virtual controls only") ); | |
5290 | ||
5291 | m_mainWin->SetItemCount(count); | |
5292 | } | |
5293 | ||
3cd94a0d | 5294 | void wxGenericListCtrl::RefreshItem(long item) |
1a6cb56f VZ |
5295 | { |
5296 | m_mainWin->RefreshLine(item); | |
5297 | } | |
5298 | ||
3cd94a0d | 5299 | void wxGenericListCtrl::RefreshItems(long itemFrom, long itemTo) |
1a6cb56f VZ |
5300 | { |
5301 | m_mainWin->RefreshLines(itemFrom, itemTo); | |
5302 | } | |
5303 | ||
3cd94a0d | 5304 | void wxGenericListCtrl::Freeze() |
c5c528fc VZ |
5305 | { |
5306 | m_mainWin->Freeze(); | |
5307 | } | |
5308 | ||
3cd94a0d | 5309 | void wxGenericListCtrl::Thaw() |
c5c528fc VZ |
5310 | { |
5311 | m_mainWin->Thaw(); | |
5312 | } | |
5313 | ||
1e6feb95 | 5314 | #endif // wxUSE_LISTCTRL |
5b98eb2f | 5315 |