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