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