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