]>
Commit | Line | Data |
---|---|---|
c801d85f | 1 | ///////////////////////////////////////////////////////////////////////////// |
54442116 VZ |
2 | // Name: generic/listctrl.cpp |
3 | // Purpose: generic implementation of wxListCtrl | |
c801d85f | 4 | // Author: Robert Roebling |
cf1dfa6b | 5 | // Vadim Zeitlin (virtual list control support) |
0208334d RR |
6 | // Id: $Id$ |
7 | // Copyright: (c) 1998 Robert Roebling | |
bd8289c1 | 8 | // Licence: wxWindows licence |
c801d85f KB |
9 | ///////////////////////////////////////////////////////////////////////////// |
10 | ||
b54e41c5 | 11 | /* |
70541533 | 12 | TODO |
b54e41c5 | 13 | |
70541533 | 14 | 1. we need to implement searching/sorting for virtual controls somehow |
0a816d95 | 15 | ?2. when changing selection the lines are refreshed twice |
b54e41c5 VZ |
16 | */ |
17 | ||
1370703e VZ |
18 | // ============================================================================ |
19 | // declarations | |
20 | // ============================================================================ | |
21 | ||
22 | // ---------------------------------------------------------------------------- | |
23 | // headers | |
24 | // ---------------------------------------------------------------------------- | |
25 | ||
14f355c2 | 26 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) |
510fc784 RR |
27 | #pragma implementation "listctrl.h" |
28 | #pragma implementation "listctrlbase.h" | |
1e4d446b | 29 | #endif |
5cd89174 | 30 | |
1e6d9499 JS |
31 | // For compilers that support precompilation, includes "wx.h". |
32 | #include "wx/wxprec.h" | |
33 | ||
34 | #ifdef __BORLANDC__ | |
35 | #pragma hdrstop | |
36 | #endif | |
37 | ||
1e6feb95 VZ |
38 | #if wxUSE_LISTCTRL |
39 | ||
33b7a549 VZ |
40 | #ifndef WX_PRECOMP |
41 | #include "wx/app.h" | |
42 | ||
43 | #include "wx/dynarray.h" | |
44 | ||
45 | #include "wx/dcscreen.h" | |
46 | ||
47 | #include "wx/textctrl.h" | |
48 | #endif | |
49 | ||
2b5f62a0 VZ |
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 | |
e81a301c | 53 | #if defined(__WIN32__) && !defined(__WXUNIVERSAL__) |
2b5f62a0 VZ |
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 | |
e81a301c | 59 | #include "wx/generic/listctrl.h" |
2b5f62a0 | 60 | #else // !HAVE_NATIVE_LISTCTRL |
e81a301c | 61 | #include "wx/listctrl.h" |
2b5f62a0 VZ |
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 | |
c801d85f | 70 | |
c71d3313 VZ |
71 | #include "wx/selstore.h" |
72 | ||
9c7f49f5 VZ |
73 | #include "wx/renderer.h" |
74 | ||
2e4df4bf VZ |
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) | |
11358d39 VZ |
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) | |
2e4df4bf VZ |
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) | |
0ddefeb0 | 99 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_FOCUSED) |
614391dc | 100 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_CACHE_HINT) |
2e4df4bf | 101 | |
cf1dfa6b VZ |
102 | // ---------------------------------------------------------------------------- |
103 | // constants | |
104 | // ---------------------------------------------------------------------------- | |
105 | ||
f8252483 JS |
106 | // // the height of the header window (FIXME: should depend on its font!) |
107 | // static const int HEADER_HEIGHT = 23; | |
cf1dfa6b VZ |
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) | |
b54e41c5 | 114 | static const int LINE_SPACING = 0; |
cf1dfa6b VZ |
115 | |
116 | // extra margins around the text label | |
117 | static const int EXTRA_WIDTH = 3; | |
118 | static const int EXTRA_HEIGHT = 4; | |
119 | ||
13602ebd VZ |
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 | ||
cf1dfa6b VZ |
124 | // offset for the header window |
125 | static const int HEADER_OFFSET_X = 1; | |
126 | static const int HEADER_OFFSET_Y = 1; | |
127 | ||
13602ebd VZ |
128 | // margin between rows of icons in [small] icon view |
129 | static const int MARGIN_BETWEEN_ROWS = 6; | |
130 | ||
cf1dfa6b VZ |
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 | ||
06b781c7 VZ |
138 | // the space between the image and the text in the report mode |
139 | static const int IMAGE_MARGIN_IN_REPORT_MODE = 5; | |
140 | ||
efbb7287 VZ |
141 | // ============================================================================ |
142 | // private classes | |
143 | // ============================================================================ | |
144 | ||
145 | //----------------------------------------------------------------------------- | |
146 | // wxListItemData (internal) | |
147 | //----------------------------------------------------------------------------- | |
148 | ||
cf1dfa6b | 149 | class WXDLLEXPORT wxListItemData |
efbb7287 | 150 | { |
efbb7287 | 151 | public: |
cf1dfa6b | 152 | wxListItemData(wxListMainWindow *owner); |
850ed6e7 | 153 | ~wxListItemData(); |
efbb7287 | 154 | |
efbb7287 | 155 | void SetItem( const wxListItem &info ); |
cf1dfa6b VZ |
156 | void SetImage( int image ) { m_image = image; } |
157 | void SetData( long data ) { m_data = data; } | |
efbb7287 VZ |
158 | void SetPosition( int x, int y ); |
159 | void SetSize( int width, int height ); | |
54442116 VZ |
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 | ||
cf1dfa6b VZ |
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 | ||
efbb7287 | 176 | bool IsHit( int x, int y ) const; |
54442116 | 177 | |
cf1dfa6b VZ |
178 | int GetX() const; |
179 | int GetY() const; | |
efbb7287 VZ |
180 | int GetWidth() const; |
181 | int GetHeight() const; | |
cf1dfa6b VZ |
182 | |
183 | int GetImage() const { return m_image; } | |
184 | bool HasImage() const { return GetImage() != -1; } | |
185 | ||
efbb7287 VZ |
186 | void GetItem( wxListItem &info ) const; |
187 | ||
6c02c329 VZ |
188 | void SetAttr(wxListItemAttr *attr) { m_attr = attr; } |
189 | wxListItemAttr *GetAttr() const { return m_attr; } | |
efbb7287 | 190 | |
54442116 | 191 | public: |
cf1dfa6b VZ |
192 | // the item image or -1 |
193 | int m_image; | |
194 | ||
195 | // user data associated with the item | |
196 | long m_data; | |
54442116 | 197 | |
cf1dfa6b VZ |
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 | |
54442116 VZ |
207 | wxListItemAttr *m_attr; |
208 | ||
209 | protected: | |
cf1dfa6b VZ |
210 | // common part of all ctors |
211 | void Init(); | |
54442116 | 212 | |
cf1dfa6b | 213 | wxString m_text; |
efbb7287 VZ |
214 | }; |
215 | ||
216 | //----------------------------------------------------------------------------- | |
217 | // wxListHeaderData (internal) | |
218 | //----------------------------------------------------------------------------- | |
219 | ||
220 | class WXDLLEXPORT wxListHeaderData : public wxObject | |
221 | { | |
efbb7287 VZ |
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; | |
54442116 VZ |
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 | ||
efbb7287 | 236 | void GetItem( wxListItem &item ); |
54442116 VZ |
237 | |
238 | bool IsHit( int x, int y ) const; | |
efbb7287 VZ |
239 | int GetImage() const; |
240 | int GetWidth() const; | |
241 | int GetFormat() const; | |
f6bcfd97 | 242 | |
0a816d95 VZ |
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 | ||
efbb7287 | 253 | private: |
0a816d95 | 254 | void Init(); |
efbb7287 VZ |
255 | }; |
256 | ||
257 | //----------------------------------------------------------------------------- | |
258 | // wxListLineData (internal) | |
259 | //----------------------------------------------------------------------------- | |
260 | ||
2c1f73ee VZ |
261 | WX_DECLARE_LIST(wxListItemData, wxListItemDataList); |
262 | #include "wx/listimpl.cpp" | |
263 | WX_DEFINE_LIST(wxListItemDataList); | |
264 | ||
61fef19b | 265 | class wxListLineData |
efbb7287 VZ |
266 | { |
267 | public: | |
cf1dfa6b VZ |
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 | |
b54e41c5 | 284 | wxRect m_rectHighlight; |
94dd23ae VZ |
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 | } | |
cf1dfa6b | 297 | } *m_gi; |
efbb7287 | 298 | |
cf1dfa6b | 299 | // is this item selected? [NB: not used in virtual mode] |
b54e41c5 | 300 | bool m_highlighted; |
cf1dfa6b VZ |
301 | |
302 | // back pointer to the list ctrl | |
303 | wxListMainWindow *m_owner; | |
efbb7287 VZ |
304 | |
305 | public: | |
5cd89174 | 306 | wxListLineData(wxListMainWindow *owner); |
cf1dfa6b | 307 | |
222ed1d6 MB |
308 | ~wxListLineData() |
309 | { | |
310 | WX_CLEAR_LIST(wxListItemDataList, m_items); | |
311 | delete m_gi; | |
312 | } | |
cf1dfa6b VZ |
313 | |
314 | // are we in report mode? | |
315 | inline bool InReportView() const; | |
316 | ||
317 | // are we in virtual report mode? | |
b54e41c5 | 318 | inline bool IsVirtual() const; |
cf1dfa6b VZ |
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 | |
efbb7287 | 324 | void CalculateSize( wxDC *dc, int spacing ); |
cf1dfa6b VZ |
325 | |
326 | // remember the position this line appears at | |
13602ebd | 327 | void SetPosition( int x, int y, int spacing ); |
cf1dfa6b | 328 | |
5cd89174 VZ |
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(); } | |
cf1dfa6b | 335 | |
efbb7287 VZ |
336 | void SetItem( int index, const wxListItem &info ); |
337 | void GetItem( int index, wxListItem &info ); | |
cf1dfa6b | 338 | |
54442116 | 339 | wxString GetText(int index) const; |
efbb7287 | 340 | void SetText( int index, const wxString s ); |
cf1dfa6b | 341 | |
6c02c329 VZ |
342 | wxListItemAttr *GetAttr() const; |
343 | void SetAttr(wxListItemAttr *attr); | |
344 | ||
cf1dfa6b | 345 | // return true if the highlighting really changed |
b54e41c5 | 346 | bool Highlight( bool on ); |
cf1dfa6b | 347 | |
b54e41c5 | 348 | void ReverseHighlight(); |
cf1dfa6b | 349 | |
b54e41c5 | 350 | bool IsHighlighted() const |
cf1dfa6b | 351 | { |
b54e41c5 | 352 | wxASSERT_MSG( !IsVirtual(), _T("unexpected call to IsHighlighted") ); |
cf1dfa6b | 353 | |
b54e41c5 | 354 | return m_highlighted; |
cf1dfa6b VZ |
355 | } |
356 | ||
5cd89174 VZ |
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 ); | |
f6bcfd97 | 365 | |
efbb7287 | 366 | private: |
cf1dfa6b VZ |
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 | ||
0e980f91 VZ |
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, | |
efbb7287 | 376 | const wxListItemAttr *attr, |
b54e41c5 | 377 | bool highlight); |
efbb7287 | 378 | |
2b5f62a0 VZ |
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 | ||
5cd89174 VZ |
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; | |
efbb7287 VZ |
387 | }; |
388 | ||
f6bcfd97 BP |
389 | WX_DECLARE_EXPORTED_OBJARRAY(wxListLineData, wxListLineDataArray); |
390 | #include "wx/arrimpl.cpp" | |
391 | WX_DEFINE_OBJARRAY(wxListLineDataArray); | |
392 | ||
efbb7287 VZ |
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; | |
f6bcfd97 | 404 | |
62313c27 | 405 | // column being resized or -1 |
f6bcfd97 BP |
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; | |
efbb7287 VZ |
414 | |
415 | public: | |
416 | wxListHeaderWindow(); | |
f6bcfd97 BP |
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, | |
2b5f62a0 | 424 | const wxString &name = wxT("wxlistctrlcolumntitles") ); |
f6bcfd97 | 425 | |
0a816d95 VZ |
426 | virtual ~wxListHeaderWindow(); |
427 | ||
efbb7287 | 428 | void DrawCurrent(); |
f6bcfd97 BP |
429 | void AdjustDC(wxDC& dc); |
430 | ||
431 | void OnPaint( wxPaintEvent &event ); | |
efbb7287 VZ |
432 | void OnMouse( wxMouseEvent &event ); |
433 | void OnSetFocus( wxFocusEvent &event ); | |
434 | ||
f6bcfd97 BP |
435 | // needs refresh |
436 | bool m_dirty; | |
437 | ||
efbb7287 | 438 | private: |
0a816d95 VZ |
439 | // common part of all ctors |
440 | void Init(); | |
441 | ||
355f2407 VZ |
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); | |
a77ec46d | 445 | |
efbb7287 VZ |
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: | |
1370703e | 457 | wxListMainWindow *m_owner; |
efbb7287 VZ |
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 | { | |
efbb7287 | 470 | public: |
62d89eb4 VZ |
471 | wxListTextCtrl(wxListMainWindow *owner, size_t itemEdit); |
472 | ||
473 | protected: | |
efbb7287 | 474 | void OnChar( wxKeyEvent &event ); |
c13cace1 | 475 | void OnKeyUp( wxKeyEvent &event ); |
efbb7287 VZ |
476 | void OnKillFocus( wxFocusEvent &event ); |
477 | ||
62d89eb4 VZ |
478 | bool AcceptChanges(); |
479 | void Finish(); | |
480 | ||
efbb7287 | 481 | private: |
62d89eb4 VZ |
482 | wxListMainWindow *m_owner; |
483 | wxString m_startValue; | |
484 | size_t m_itemEdited; | |
485 | bool m_finished; | |
486 | ||
efbb7287 VZ |
487 | DECLARE_EVENT_TABLE() |
488 | }; | |
489 | ||
490 | //----------------------------------------------------------------------------- | |
491 | // wxListMainWindow (internal) | |
492 | //----------------------------------------------------------------------------- | |
493 | ||
24b9f055 VZ |
494 | WX_DECLARE_LIST(wxListHeaderData, wxListHeaderDataList); |
495 | #include "wx/listimpl.cpp" | |
496 | WX_DEFINE_LIST(wxListHeaderDataList); | |
497 | ||
61fef19b | 498 | class wxListMainWindow : public wxScrolledWindow |
efbb7287 | 499 | { |
efbb7287 VZ |
500 | public: |
501 | wxListMainWindow(); | |
1370703e VZ |
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 | ||
cf1dfa6b VZ |
511 | bool HasFlag(int flag) const { return m_parent->HasFlag(flag); } |
512 | ||
1370703e | 513 | // return true if this is a virtual list control |
cf1dfa6b VZ |
514 | bool IsVirtual() const { return HasFlag(wxLC_VIRTUAL); } |
515 | ||
5cd89174 VZ |
516 | // return true if the control is in report mode |
517 | bool InReportView() const { return HasFlag(wxLC_REPORT); } | |
518 | ||
b54e41c5 VZ |
519 | // return true if we are in single selection mode, false if multi sel |
520 | bool IsSingleSel() const { return HasFlag(wxLC_SINGLE_SEL); } | |
521 | ||
cf1dfa6b VZ |
522 | // do we have a header window? |
523 | bool HasHeader() const | |
524 | { return HasFlag(wxLC_REPORT) && !HasFlag(wxLC_NO_HEADER); } | |
1370703e | 525 | |
b54e41c5 | 526 | void HighlightAll( bool on ); |
cf1dfa6b VZ |
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 | |
b54e41c5 VZ |
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 ); | |
cf1dfa6b VZ |
538 | |
539 | // toggle the line state and refresh it | |
b54e41c5 VZ |
540 | void ReverseHighlight( size_t line ) |
541 | { HighlightLine(line, !IsHighlighted(line)); RefreshLine(line); } | |
cf1dfa6b | 542 | |
6b4a8d93 VZ |
543 | // return true if the line is highlighted |
544 | bool IsHighlighted(size_t line) const; | |
545 | ||
cf1dfa6b VZ |
546 | // refresh one or several lines at once |
547 | void RefreshLine( size_t line ); | |
548 | void RefreshLines( size_t lineFrom, size_t lineTo ); | |
549 | ||
49ecb029 VZ |
550 | // refresh all selected items |
551 | void RefreshSelected(); | |
552 | ||
6b4a8d93 VZ |
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 ); | |
efbb7287 | 557 | |
5cd89174 VZ |
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 | ||
34bbbc27 VZ |
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 | ||
c5c528fc | 588 | // start editing the label of the given item |
efbb7287 | 589 | void EditLabel( long item ); |
c5c528fc VZ |
590 | |
591 | // suspend/resume redrawing the control | |
592 | void Freeze(); | |
593 | void Thaw(); | |
a77ec46d | 594 | |
a6d57d03 | 595 | void SetFocus(); |
c5c528fc | 596 | |
efbb7287 | 597 | void OnRenameTimer(); |
62d89eb4 | 598 | bool OnRenameAccept(size_t itemEdit, const wxString& value); |
86586459 | 599 | void OnRenameCancelled(size_t itemEdit); |
efbb7287 VZ |
600 | |
601 | void OnMouse( wxMouseEvent &event ); | |
cf1dfa6b VZ |
602 | |
603 | // called to switch the selection from the current item to newCurrent, | |
604 | void OnArrowChar( size_t newCurrent, const wxKeyEvent& event ); | |
605 | ||
efbb7287 VZ |
606 | void OnChar( wxKeyEvent &event ); |
607 | void OnKeyDown( wxKeyEvent &event ); | |
608 | void OnSetFocus( wxFocusEvent &event ); | |
609 | void OnKillFocus( wxFocusEvent &event ); | |
efbb7287 | 610 | void OnScroll(wxScrollWinEvent& event) ; |
f6bcfd97 | 611 | |
cf1dfa6b VZ |
612 | void OnPaint( wxPaintEvent &event ); |
613 | ||
efbb7287 | 614 | void DrawImage( int index, wxDC *dc, int x, int y ); |
5cd89174 VZ |
615 | void GetImageSize( int index, int &width, int &height ) const; |
616 | int GetTextLength( const wxString &s ) const; | |
efbb7287 | 617 | |
80020b62 | 618 | void SetImageList( wxImageListType *imageList, int which ); |
efbb7287 VZ |
619 | void SetItemSpacing( int spacing, bool isSmall = FALSE ); |
620 | int GetItemSpacing( bool isSmall = FALSE ); | |
cf1dfa6b | 621 | |
efbb7287 VZ |
622 | void SetColumn( int col, wxListItem &item ); |
623 | void SetColumnWidth( int col, int width ); | |
cf1dfa6b VZ |
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 | ||
5cd89174 | 631 | int GetCountPerPage() const; |
cf1dfa6b | 632 | |
efbb7287 | 633 | void SetItem( wxListItem &item ); |
62d89eb4 | 634 | void GetItem( wxListItem &item ) const; |
efbb7287 | 635 | void SetItemState( long item, long state, long stateMask ); |
62d89eb4 VZ |
636 | int GetItemState( long item, long stateMask ) const; |
637 | void GetItemRect( long index, wxRect &rect ) const; | |
f58fc140 | 638 | wxRect GetViewRect() const; |
62d89eb4 VZ |
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 | } | |
cf1dfa6b VZ |
658 | |
659 | // set the scrollbars and update the positions of the items | |
34bbbc27 | 660 | void RecalculatePositions(bool noRefresh = FALSE); |
b54e41c5 VZ |
661 | |
662 | // refresh the window and the header | |
663 | void RefreshAll(); | |
cf1dfa6b | 664 | |
62d89eb4 | 665 | long GetNextItem( long item, int geometry, int state ) const; |
efbb7287 VZ |
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 ); | |
efbb7287 | 675 | void InsertColumn( long col, wxListItem &item ); |
efbb7287 VZ |
676 | void SortItems( wxListCtrlCompare fn, long data ); |
677 | ||
cf1dfa6b | 678 | size_t GetItemCount() const; |
1370703e | 679 | bool IsEmpty() const { return GetItemCount() == 0; } |
2c1f73ee VZ |
680 | void SetItemCount(long count); |
681 | ||
0ddefeb0 VZ |
682 | // change the current (== focused) item, send a notification event |
683 | void ChangeCurrent(size_t current); | |
684 | void ResetCurrent() { ChangeCurrent((size_t)-1); } | |
cf1dfa6b VZ |
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 | ||
b54e41c5 VZ |
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 | } | |
cf1dfa6b VZ |
702 | |
703 | // these are for wxListLineData usage only | |
704 | ||
705 | // get the backpointer to the list ctrl | |
3cd94a0d | 706 | wxGenericListCtrl *GetListCtrl() const |
cf1dfa6b | 707 | { |
3cd94a0d | 708 | return wxStaticCast(GetParent(), wxGenericListCtrl); |
cf1dfa6b VZ |
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 | ||
49ecb029 VZ |
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 | ||
cf1dfa6b | 723 | //protected: |
904ccf52 VZ |
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]) | |
cf1dfa6b VZ |
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 | ||
cf1dfa6b VZ |
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 | ||
b54e41c5 | 745 | wxColour *m_highlightColour; |
80020b62 JS |
746 | wxImageListType *m_small_image_list; |
747 | wxImageListType *m_normal_image_list; | |
cf1dfa6b VZ |
748 | int m_small_spacing; |
749 | int m_normal_spacing; | |
750 | bool m_hasFocus; | |
751 | ||
752 | bool m_lastOnSame; | |
753 | wxTimer *m_renameTimer; | |
cf1dfa6b VZ |
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 | ||
1370703e | 762 | protected: |
cf1dfa6b | 763 | // the total count of items in a virtual list control |
b54e41c5 | 764 | size_t m_countVirt; |
cf1dfa6b | 765 | |
b54e41c5 VZ |
766 | // the object maintaining the items selection state, only used in virtual |
767 | // controls | |
768 | wxSelectionStore m_selStore; | |
cf1dfa6b | 769 | |
1370703e VZ |
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 | ||
cf1dfa6b VZ |
778 | if ( IsVirtual() ) |
779 | { | |
780 | wxConstCast(this, wxListMainWindow)->CacheLineData(n); | |
781 | ||
782 | n = 0; | |
783 | } | |
784 | ||
1370703e VZ |
785 | return &m_lines[n]; |
786 | } | |
787 | ||
b54e41c5 VZ |
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; | |
cf1dfa6b VZ |
791 | |
792 | // cache the line data of the n-th line in m_lines[0] | |
793 | void CacheLineData(size_t line); | |
794 | ||
b54e41c5 VZ |
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 | |
a756f210 | 807 | return wxSystemSettings::GetColour(wxSYS_COLOUR_3DLIGHT); |
b54e41c5 VZ |
808 | #endif |
809 | } | |
cf1dfa6b | 810 | |
efbb7287 | 811 | private: |
cf1dfa6b VZ |
812 | // initialize the current item if needed |
813 | void UpdateCurrent(); | |
814 | ||
5fe143df VZ |
815 | // delete all items but don't refresh: called from dtor |
816 | void DoDeleteAllItems(); | |
817 | ||
cf1dfa6b VZ |
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 | ||
b54e41c5 VZ |
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 | ||
49ecb029 VZ |
830 | // the brushes to use for item highlighting when we do/don't have focus |
831 | wxBrush *m_highlightBrush, | |
832 | *m_highlightUnfocusedBrush; | |
833 | ||
c5c528fc VZ |
834 | // if this is > 0, the control is frozen and doesn't redraw itself |
835 | size_t m_freezeCount; | |
836 | ||
5a1cad6e | 837 | DECLARE_DYNAMIC_CLASS(wxListMainWindow) |
efbb7287 | 838 | DECLARE_EVENT_TABLE() |
2b5f62a0 VZ |
839 | |
840 | friend class wxGenericListCtrl; | |
efbb7287 VZ |
841 | }; |
842 | ||
843 | // ============================================================================ | |
844 | // implementation | |
845 | // ============================================================================ | |
846 | ||
c801d85f KB |
847 | //----------------------------------------------------------------------------- |
848 | // wxListItemData | |
849 | //----------------------------------------------------------------------------- | |
850 | ||
850ed6e7 VZ |
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 | ||
cf1dfa6b | 863 | void wxListItemData::Init() |
c801d85f | 864 | { |
92976ab6 RR |
865 | m_image = -1; |
866 | m_data = 0; | |
cf1dfa6b | 867 | |
0530737d | 868 | m_attr = NULL; |
e1e955e1 | 869 | } |
c801d85f | 870 | |
cf1dfa6b | 871 | wxListItemData::wxListItemData(wxListMainWindow *owner) |
c801d85f | 872 | { |
cf1dfa6b | 873 | Init(); |
0530737d | 874 | |
cf1dfa6b VZ |
875 | m_owner = owner; |
876 | ||
850ed6e7 | 877 | if ( owner->InReportView() ) |
cf1dfa6b VZ |
878 | { |
879 | m_rect = NULL; | |
880 | } | |
881 | else | |
882 | { | |
883 | m_rect = new wxRect; | |
884 | } | |
e1e955e1 | 885 | } |
c801d85f KB |
886 | |
887 | void wxListItemData::SetItem( const wxListItem &info ) | |
888 | { | |
cf1dfa6b | 889 | if ( info.m_mask & wxLIST_MASK_TEXT ) |
54442116 | 890 | SetText(info.m_text); |
cf1dfa6b | 891 | if ( info.m_mask & wxLIST_MASK_IMAGE ) |
54442116 | 892 | m_image = info.m_image; |
cf1dfa6b | 893 | if ( info.m_mask & wxLIST_MASK_DATA ) |
54442116 | 894 | m_data = info.m_data; |
0530737d VZ |
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 | ||
cf1dfa6b VZ |
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 | } | |
e1e955e1 | 911 | } |
c801d85f | 912 | |
debe6624 | 913 | void wxListItemData::SetPosition( int x, int y ) |
c801d85f | 914 | { |
cf1dfa6b VZ |
915 | wxCHECK_RET( m_rect, _T("unexpected SetPosition() call") ); |
916 | ||
917 | m_rect->x = x; | |
918 | m_rect->y = y; | |
e1e955e1 | 919 | } |
c801d85f | 920 | |
1e6d9499 | 921 | void wxListItemData::SetSize( int width, int height ) |
c801d85f | 922 | { |
cf1dfa6b | 923 | wxCHECK_RET( m_rect, _T("unexpected SetSize() call") ); |
c801d85f | 924 | |
cf1dfa6b VZ |
925 | if ( width != -1 ) |
926 | m_rect->width = width; | |
927 | if ( height != -1 ) | |
928 | m_rect->height = height; | |
e1e955e1 | 929 | } |
c801d85f | 930 | |
debe6624 | 931 | bool wxListItemData::IsHit( int x, int y ) const |
c801d85f | 932 | { |
cf1dfa6b VZ |
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); | |
e1e955e1 | 936 | } |
c801d85f | 937 | |
fd9811b1 | 938 | int wxListItemData::GetX() const |
c801d85f | 939 | { |
cf1dfa6b VZ |
940 | wxCHECK_MSG( m_rect, 0, _T("can't be called in this mode") ); |
941 | ||
942 | return m_rect->x; | |
e1e955e1 | 943 | } |
c801d85f | 944 | |
fd9811b1 | 945 | int wxListItemData::GetY() const |
c801d85f | 946 | { |
cf1dfa6b VZ |
947 | wxCHECK_MSG( m_rect, 0, _T("can't be called in this mode") ); |
948 | ||
949 | return m_rect->y; | |
e1e955e1 | 950 | } |
c801d85f | 951 | |
fd9811b1 | 952 | int wxListItemData::GetWidth() const |
c801d85f | 953 | { |
cf1dfa6b VZ |
954 | wxCHECK_MSG( m_rect, 0, _T("can't be called in this mode") ); |
955 | ||
956 | return m_rect->width; | |
e1e955e1 | 957 | } |
c801d85f | 958 | |
fd9811b1 | 959 | int wxListItemData::GetHeight() const |
c801d85f | 960 | { |
cf1dfa6b | 961 | wxCHECK_MSG( m_rect, 0, _T("can't be called in this mode") ); |
c801d85f | 962 | |
cf1dfa6b | 963 | return m_rect->height; |
e1e955e1 | 964 | } |
c801d85f | 965 | |
0530737d | 966 | void wxListItemData::GetItem( wxListItem &info ) const |
c801d85f | 967 | { |
92976ab6 RR |
968 | info.m_text = m_text; |
969 | info.m_image = m_image; | |
970 | info.m_data = m_data; | |
c801d85f | 971 | |
0530737d VZ |
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 | } | |
e1e955e1 | 981 | } |
c801d85f KB |
982 | |
983 | //----------------------------------------------------------------------------- | |
984 | // wxListHeaderData | |
985 | //----------------------------------------------------------------------------- | |
986 | ||
0a816d95 | 987 | void wxListHeaderData::Init() |
c801d85f | 988 | { |
92976ab6 | 989 | m_mask = 0; |
0a816d95 | 990 | m_image = -1; |
92976ab6 RR |
991 | m_format = 0; |
992 | m_width = 0; | |
993 | m_xpos = 0; | |
994 | m_ypos = 0; | |
995 | m_height = 0; | |
e1e955e1 | 996 | } |
c801d85f | 997 | |
0a816d95 VZ |
998 | wxListHeaderData::wxListHeaderData() |
999 | { | |
1000 | Init(); | |
1001 | } | |
1002 | ||
c801d85f KB |
1003 | wxListHeaderData::wxListHeaderData( const wxListItem &item ) |
1004 | { | |
0a816d95 VZ |
1005 | Init(); |
1006 | ||
92976ab6 | 1007 | SetItem( item ); |
e1e955e1 | 1008 | } |
c801d85f KB |
1009 | |
1010 | void wxListHeaderData::SetItem( const wxListItem &item ) | |
1011 | { | |
92976ab6 | 1012 | m_mask = item.m_mask; |
cf1dfa6b | 1013 | |
0a816d95 VZ |
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); | |
e1e955e1 | 1025 | } |
c801d85f | 1026 | |
debe6624 | 1027 | void wxListHeaderData::SetPosition( int x, int y ) |
c801d85f | 1028 | { |
92976ab6 RR |
1029 | m_xpos = x; |
1030 | m_ypos = y; | |
e1e955e1 | 1031 | } |
c801d85f | 1032 | |
debe6624 | 1033 | void wxListHeaderData::SetHeight( int h ) |
c801d85f | 1034 | { |
92976ab6 | 1035 | m_height = h; |
e1e955e1 | 1036 | } |
c801d85f | 1037 | |
debe6624 | 1038 | void wxListHeaderData::SetWidth( int w ) |
c801d85f | 1039 | { |
92976ab6 | 1040 | m_width = w; |
cf1dfa6b VZ |
1041 | if (m_width < 0) |
1042 | m_width = WIDTH_COL_DEFAULT; | |
0a816d95 | 1043 | else if (m_width < WIDTH_COL_MIN) |
cf1dfa6b | 1044 | m_width = WIDTH_COL_MIN; |
e1e955e1 | 1045 | } |
c801d85f | 1046 | |
debe6624 | 1047 | void wxListHeaderData::SetFormat( int format ) |
c801d85f | 1048 | { |
92976ab6 | 1049 | m_format = format; |
e1e955e1 | 1050 | } |
c801d85f | 1051 | |
fd9811b1 | 1052 | bool wxListHeaderData::HasImage() const |
c801d85f | 1053 | { |
0a816d95 | 1054 | return m_image != -1; |
e1e955e1 | 1055 | } |
c801d85f | 1056 | |
c801d85f KB |
1057 | bool wxListHeaderData::IsHit( int x, int y ) const |
1058 | { | |
92976ab6 | 1059 | return ((x >= m_xpos) && (x <= m_xpos+m_width) && (y >= m_ypos) && (y <= m_ypos+m_height)); |
e1e955e1 | 1060 | } |
c801d85f | 1061 | |
0a816d95 | 1062 | void wxListHeaderData::GetItem( wxListItem& item ) |
c801d85f | 1063 | { |
92976ab6 RR |
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; | |
e1e955e1 | 1069 | } |
c801d85f | 1070 | |
fd9811b1 | 1071 | int wxListHeaderData::GetImage() const |
c801d85f | 1072 | { |
92976ab6 | 1073 | return m_image; |
e1e955e1 | 1074 | } |
c801d85f | 1075 | |
fd9811b1 | 1076 | int wxListHeaderData::GetWidth() const |
c801d85f | 1077 | { |
92976ab6 | 1078 | return m_width; |
e1e955e1 | 1079 | } |
c801d85f | 1080 | |
fd9811b1 | 1081 | int wxListHeaderData::GetFormat() const |
c801d85f | 1082 | { |
92976ab6 | 1083 | return m_format; |
e1e955e1 | 1084 | } |
c801d85f KB |
1085 | |
1086 | //----------------------------------------------------------------------------- | |
1087 | // wxListLineData | |
1088 | //----------------------------------------------------------------------------- | |
1089 | ||
cf1dfa6b VZ |
1090 | inline int wxListLineData::GetMode() const |
1091 | { | |
b54e41c5 | 1092 | return m_owner->GetListCtrl()->GetWindowStyleFlag() & wxLC_MASK_TYPE; |
cf1dfa6b | 1093 | } |
c801d85f | 1094 | |
cf1dfa6b | 1095 | inline bool wxListLineData::InReportView() const |
c801d85f | 1096 | { |
cf1dfa6b | 1097 | return m_owner->HasFlag(wxLC_REPORT); |
e1e955e1 | 1098 | } |
c801d85f | 1099 | |
b54e41c5 | 1100 | inline bool wxListLineData::IsVirtual() const |
c801d85f | 1101 | { |
cf1dfa6b VZ |
1102 | return m_owner->IsVirtual(); |
1103 | } | |
2c1f73ee | 1104 | |
5cd89174 | 1105 | wxListLineData::wxListLineData( wxListMainWindow *owner ) |
cf1dfa6b VZ |
1106 | { |
1107 | m_owner = owner; | |
2c1f73ee | 1108 | |
cf1dfa6b VZ |
1109 | if ( InReportView() ) |
1110 | { | |
1111 | m_gi = NULL; | |
1112 | } | |
1113 | else // !report | |
1114 | { | |
1115 | m_gi = new GeometryInfo; | |
1116 | } | |
f6bcfd97 | 1117 | |
b54e41c5 | 1118 | m_highlighted = FALSE; |
f6bcfd97 | 1119 | |
cf1dfa6b VZ |
1120 | InitItems( GetMode() == wxLC_REPORT ? m_owner->GetColumnCount() : 1 ); |
1121 | } | |
f6bcfd97 | 1122 | |
cf1dfa6b VZ |
1123 | void wxListLineData::CalculateSize( wxDC *dc, int spacing ) |
1124 | { | |
222ed1d6 | 1125 | wxListItemDataList::compatibility_iterator node = m_items.GetFirst(); |
cf1dfa6b VZ |
1126 | wxCHECK_RET( node, _T("no subitems at all??") ); |
1127 | ||
1128 | wxListItemData *item = node->GetData(); | |
1129 | ||
94dd23ae VZ |
1130 | wxString s; |
1131 | wxCoord lw, lh; | |
1132 | ||
cf1dfa6b VZ |
1133 | switch ( GetMode() ) |
1134 | { | |
1135 | case wxLC_ICON: | |
1136 | case wxLC_SMALL_ICON: | |
94dd23ae | 1137 | m_gi->m_rectAll.width = spacing; |
cf1dfa6b | 1138 | |
94dd23ae | 1139 | s = item->GetText(); |
cf1dfa6b | 1140 | |
94dd23ae VZ |
1141 | if ( s.empty() ) |
1142 | { | |
1143 | lh = | |
1144 | m_gi->m_rectLabel.width = | |
1145 | m_gi->m_rectLabel.height = 0; | |
92976ab6 | 1146 | } |
94dd23ae | 1147 | else // has label |
92976ab6 | 1148 | { |
92976ab6 | 1149 | dc->GetTextExtent( s, &lw, &lh ); |
cf1dfa6b VZ |
1150 | if (lh < SCROLL_UNIT_Y) |
1151 | lh = SCROLL_UNIT_Y; | |
1152 | lw += EXTRA_WIDTH; | |
1153 | lh += EXTRA_HEIGHT; | |
2c1f73ee | 1154 | |
94dd23ae VZ |
1155 | m_gi->m_rectAll.height = spacing + lh; |
1156 | if (lw > spacing) | |
1157 | m_gi->m_rectAll.width = lw; | |
1158 | ||
cf1dfa6b VZ |
1159 | m_gi->m_rectLabel.width = lw; |
1160 | m_gi->m_rectLabel.height = lh; | |
94dd23ae | 1161 | } |
f6bcfd97 | 1162 | |
94dd23ae VZ |
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 | } | |
f6bcfd97 | 1175 | |
94dd23ae VZ |
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; | |
f6bcfd97 | 1202 | |
94dd23ae VZ |
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; | |
92976ab6 | 1213 | } |
94dd23ae VZ |
1214 | |
1215 | m_gi->m_rectHighlight.width = m_gi->m_rectAll.width; | |
1216 | m_gi->m_rectHighlight.height = m_gi->m_rectAll.height; | |
92976ab6 | 1217 | break; |
2c1f73ee | 1218 | |
cf1dfa6b VZ |
1219 | case wxLC_REPORT: |
1220 | wxFAIL_MSG( _T("unexpected call to SetSize") ); | |
92976ab6 | 1221 | break; |
cf1dfa6b VZ |
1222 | |
1223 | default: | |
1224 | wxFAIL_MSG( _T("unknown mode") ); | |
e1e955e1 | 1225 | } |
e1e955e1 | 1226 | } |
c801d85f | 1227 | |
13602ebd | 1228 | void wxListLineData::SetPosition( int x, int y, int spacing ) |
c801d85f | 1229 | { |
222ed1d6 | 1230 | wxListItemDataList::compatibility_iterator node = m_items.GetFirst(); |
cf1dfa6b | 1231 | wxCHECK_RET( node, _T("no subitems at all??") ); |
2c1f73ee | 1232 | |
cf1dfa6b | 1233 | wxListItemData *item = node->GetData(); |
2c1f73ee | 1234 | |
cf1dfa6b | 1235 | switch ( GetMode() ) |
0b855868 RR |
1236 | { |
1237 | case wxLC_ICON: | |
cf1dfa6b VZ |
1238 | case wxLC_SMALL_ICON: |
1239 | m_gi->m_rectAll.x = x; | |
1240 | m_gi->m_rectAll.y = y; | |
1241 | ||
1242 | if ( item->HasImage() ) | |
0b855868 | 1243 | { |
c2569f41 VZ |
1244 | m_gi->m_rectIcon.x = m_gi->m_rectAll.x + 4 + |
1245 | (m_gi->m_rectAll.width - m_gi->m_rectIcon.width) / 2; | |
cf1dfa6b | 1246 | m_gi->m_rectIcon.y = m_gi->m_rectAll.y + 4; |
0b855868 | 1247 | } |
cf1dfa6b VZ |
1248 | |
1249 | if ( item->HasText() ) | |
0b855868 | 1250 | { |
cf1dfa6b VZ |
1251 | if (m_gi->m_rectAll.width > spacing) |
1252 | m_gi->m_rectLabel.x = m_gi->m_rectAll.x + 2; | |
5d25c050 | 1253 | else |
cf1dfa6b VZ |
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; | |
b54e41c5 VZ |
1256 | m_gi->m_rectHighlight.x = m_gi->m_rectLabel.x - 2; |
1257 | m_gi->m_rectHighlight.y = m_gi->m_rectLabel.y - 2; | |
bffa1c77 | 1258 | } |
cf1dfa6b | 1259 | else // no text, highlight the icon |
0b855868 | 1260 | { |
b54e41c5 VZ |
1261 | m_gi->m_rectHighlight.x = m_gi->m_rectIcon.x - 4; |
1262 | m_gi->m_rectHighlight.y = m_gi->m_rectIcon.y - 4; | |
bffa1c77 | 1263 | } |
0b855868 | 1264 | break; |
c801d85f | 1265 | |
cf1dfa6b VZ |
1266 | case wxLC_LIST: |
1267 | m_gi->m_rectAll.x = x; | |
1268 | m_gi->m_rectAll.y = y; | |
c801d85f | 1269 | |
b54e41c5 VZ |
1270 | m_gi->m_rectHighlight.x = m_gi->m_rectAll.x; |
1271 | m_gi->m_rectHighlight.y = m_gi->m_rectAll.y; | |
cf1dfa6b | 1272 | m_gi->m_rectLabel.y = m_gi->m_rectAll.y + 2; |
c801d85f | 1273 | |
cf1dfa6b VZ |
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; | |
c801d85f | 1285 | |
cf1dfa6b VZ |
1286 | case wxLC_REPORT: |
1287 | wxFAIL_MSG( _T("unexpected call to SetPosition") ); | |
1288 | break; | |
c801d85f | 1289 | |
cf1dfa6b VZ |
1290 | default: |
1291 | wxFAIL_MSG( _T("unknown mode") ); | |
1292 | } | |
e1e955e1 | 1293 | } |
c801d85f | 1294 | |
debe6624 | 1295 | void wxListLineData::InitItems( int num ) |
c801d85f | 1296 | { |
2c1f73ee | 1297 | for (int i = 0; i < num; i++) |
cf1dfa6b | 1298 | m_items.Append( new wxListItemData(m_owner) ); |
e1e955e1 | 1299 | } |
c801d85f | 1300 | |
debe6624 | 1301 | void wxListLineData::SetItem( int index, const wxListItem &info ) |
c801d85f | 1302 | { |
222ed1d6 | 1303 | wxListItemDataList::compatibility_iterator node = m_items.Item( index ); |
1370703e VZ |
1304 | wxCHECK_RET( node, _T("invalid column index in SetItem") ); |
1305 | ||
1306 | wxListItemData *item = node->GetData(); | |
1307 | item->SetItem( info ); | |
e1e955e1 | 1308 | } |
c801d85f | 1309 | |
1e6d9499 | 1310 | void wxListLineData::GetItem( int index, wxListItem &info ) |
c801d85f | 1311 | { |
222ed1d6 | 1312 | wxListItemDataList::compatibility_iterator node = m_items.Item( index ); |
139adb6a RR |
1313 | if (node) |
1314 | { | |
2c1f73ee | 1315 | wxListItemData *item = node->GetData(); |
139adb6a RR |
1316 | item->GetItem( info ); |
1317 | } | |
e1e955e1 | 1318 | } |
c801d85f | 1319 | |
54442116 | 1320 | wxString wxListLineData::GetText(int index) const |
c801d85f | 1321 | { |
54442116 VZ |
1322 | wxString s; |
1323 | ||
222ed1d6 | 1324 | wxListItemDataList::compatibility_iterator node = m_items.Item( index ); |
139adb6a RR |
1325 | if (node) |
1326 | { | |
2c1f73ee | 1327 | wxListItemData *item = node->GetData(); |
54442116 | 1328 | s = item->GetText(); |
139adb6a | 1329 | } |
54442116 VZ |
1330 | |
1331 | return s; | |
e1e955e1 | 1332 | } |
c801d85f | 1333 | |
debe6624 | 1334 | void wxListLineData::SetText( int index, const wxString s ) |
c801d85f | 1335 | { |
222ed1d6 | 1336 | wxListItemDataList::compatibility_iterator node = m_items.Item( index ); |
139adb6a RR |
1337 | if (node) |
1338 | { | |
2c1f73ee | 1339 | wxListItemData *item = node->GetData(); |
139adb6a RR |
1340 | item->SetText( s ); |
1341 | } | |
e1e955e1 | 1342 | } |
c801d85f | 1343 | |
cf1dfa6b | 1344 | void wxListLineData::SetImage( int index, int image ) |
c801d85f | 1345 | { |
222ed1d6 | 1346 | wxListItemDataList::compatibility_iterator node = m_items.Item( index ); |
cf1dfa6b VZ |
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 | { | |
222ed1d6 | 1355 | wxListItemDataList::compatibility_iterator node = m_items.Item( index ); |
cf1dfa6b VZ |
1356 | wxCHECK_MSG( node, -1, _T("invalid column index in GetImage()") ); |
1357 | ||
1358 | wxListItemData *item = node->GetData(); | |
1359 | return item->GetImage(); | |
e1e955e1 | 1360 | } |
c801d85f | 1361 | |
6c02c329 VZ |
1362 | wxListItemAttr *wxListLineData::GetAttr() const |
1363 | { | |
222ed1d6 | 1364 | wxListItemDataList::compatibility_iterator node = m_items.GetFirst(); |
6c02c329 VZ |
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 | { | |
222ed1d6 | 1373 | wxListItemDataList::compatibility_iterator node = m_items.GetFirst(); |
6c02c329 VZ |
1374 | wxCHECK_RET( node, _T("invalid column index in SetAttr()") ); |
1375 | ||
1376 | wxListItemData *item = node->GetData(); | |
1377 | item->SetAttr(attr); | |
1378 | } | |
1379 | ||
0e980f91 | 1380 | bool wxListLineData::SetAttributes(wxDC *dc, |
0530737d | 1381 | const wxListItemAttr *attr, |
0e980f91 | 1382 | bool highlighted) |
0530737d | 1383 | { |
0e980f91 VZ |
1384 | wxWindow *listctrl = m_owner->GetParent(); |
1385 | ||
1386 | // fg colour | |
1387 | ||
1388 | // don't use foreground colour for drawing highlighted items - this might | |
470caaf9 VZ |
1389 | // make them completely invisible (and there is no way to do bit |
1390 | // arithmetics on wxColour, unfortunately) | |
0e980f91 VZ |
1391 | wxColour colText; |
1392 | if ( highlighted ) | |
0530737d | 1393 | { |
a756f210 | 1394 | colText = wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT); |
0530737d VZ |
1395 | } |
1396 | else | |
1397 | { | |
0e980f91 VZ |
1398 | if ( attr && attr->HasTextColour() ) |
1399 | { | |
1400 | colText = attr->GetTextColour(); | |
1401 | } | |
1402 | else | |
1403 | { | |
1404 | colText = listctrl->GetForegroundColour(); | |
1405 | } | |
0530737d VZ |
1406 | } |
1407 | ||
0e980f91 VZ |
1408 | dc->SetTextForeground(colText); |
1409 | ||
1410 | // font | |
1411 | wxFont font; | |
0530737d VZ |
1412 | if ( attr && attr->HasFont() ) |
1413 | { | |
0e980f91 | 1414 | font = attr->GetFont(); |
0530737d VZ |
1415 | } |
1416 | else | |
1417 | { | |
0e980f91 | 1418 | font = listctrl->GetFont(); |
0530737d | 1419 | } |
0e980f91 VZ |
1420 | |
1421 | dc->SetFont(font); | |
1422 | ||
1423 | // bg colour | |
1424 | bool hasBgCol = attr && attr->HasBackgroundColour(); | |
1425 | if ( highlighted || hasBgCol ) | |
1426 | { | |
1427 | if ( highlighted ) | |
1428 | { | |
49ecb029 | 1429 | dc->SetBrush( *m_owner->GetHighlightBrush() ); |
0e980f91 VZ |
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; | |
0530737d VZ |
1442 | } |
1443 | ||
5cd89174 VZ |
1444 | void wxListLineData::Draw( wxDC *dc ) |
1445 | { | |
222ed1d6 | 1446 | wxListItemDataList::compatibility_iterator node = m_items.GetFirst(); |
5cd89174 VZ |
1447 | wxCHECK_RET( node, _T("no subitems at all??") ); |
1448 | ||
0e980f91 VZ |
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 | ||
94dd23ae VZ |
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 | ||
5cd89174 VZ |
1467 | wxListItemData *item = node->GetData(); |
1468 | if (item->HasImage()) | |
1469 | { | |
94dd23ae VZ |
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); | |
5cd89174 VZ |
1475 | } |
1476 | ||
1477 | if (item->HasText()) | |
1478 | { | |
94dd23ae | 1479 | const wxRect& rectLabel = m_gi->m_rectLabel; |
06b781c7 VZ |
1480 | |
1481 | wxDCClipper clipper(*dc, rectLabel); | |
94dd23ae | 1482 | dc->DrawText(item->GetText(), rectLabel.x, rectLabel.y); |
5cd89174 VZ |
1483 | } |
1484 | } | |
1485 | ||
1486 | void wxListLineData::DrawInReportMode( wxDC *dc, | |
938b652b | 1487 | const wxRect& rect, |
5cd89174 VZ |
1488 | const wxRect& rectHL, |
1489 | bool highlighted ) | |
c801d85f | 1490 | { |
6c02c329 VZ |
1491 | // TODO: later we should support setting different attributes for |
1492 | // different columns - to do it, just add "col" argument to | |
0e980f91 | 1493 | // GetAttr() and move these lines into the loop below |
6c02c329 | 1494 | wxListItemAttr *attr = GetAttr(); |
0e980f91 | 1495 | if ( SetAttributes(dc, attr, highlighted) ) |
c801d85f | 1496 | { |
5cd89174 | 1497 | dc->DrawRectangle( rectHL ); |
e1e955e1 | 1498 | } |
004fd0c8 | 1499 | |
938b652b VZ |
1500 | wxCoord x = rect.x + HEADER_OFFSET_X, |
1501 | y = rect.y + (LINE_SPACING + EXTRA_HEIGHT) / 2; | |
cf1dfa6b | 1502 | |
904ccf52 | 1503 | size_t col = 0; |
222ed1d6 | 1504 | for ( wxListItemDataList::compatibility_iterator node = m_items.GetFirst(); |
904ccf52 VZ |
1505 | node; |
1506 | node = node->GetNext(), col++ ) | |
5cd89174 VZ |
1507 | { |
1508 | wxListItemData *item = node->GetData(); | |
cf1dfa6b | 1509 | |
904ccf52 | 1510 | int width = m_owner->GetColumnWidth(col); |
5cd89174 | 1511 | int xOld = x; |
06b781c7 | 1512 | x += width; |
cf1dfa6b | 1513 | |
5cd89174 VZ |
1514 | if ( item->HasImage() ) |
1515 | { | |
1516 | int ix, iy; | |
06b781c7 | 1517 | m_owner->DrawImage( item->GetImage(), dc, xOld, y ); |
5cd89174 | 1518 | m_owner->GetImageSize( item->GetImage(), ix, iy ); |
cf1dfa6b | 1519 | |
06b781c7 | 1520 | ix += IMAGE_MARGIN_IN_REPORT_MODE; |
cf1dfa6b | 1521 | |
06b781c7 VZ |
1522 | xOld += ix; |
1523 | width -= ix; | |
1524 | } | |
1525 | ||
2b5f62a0 | 1526 | wxDCClipper clipper(*dc, xOld, y, width - 8, rect.height); |
cf1dfa6b | 1527 | |
5cd89174 VZ |
1528 | if ( item->HasText() ) |
1529 | { | |
2b5f62a0 VZ |
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); | |
2b5f62a0 VZ |
1548 | if (w <= width) |
1549 | { | |
e1e1272f | 1550 | // it can, draw it using the items alignment |
2b5f62a0 | 1551 | m_owner->GetColumn(col, item); |
e1e1272f VZ |
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); | |
2b5f62a0 VZ |
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 | |
5175dbbd VS |
1580 | wxCoord w_c, h_c; |
1581 | size_t len = text.Length(); | |
1582 | drawntext = text.Left(len); | |
1583 | while (len > 1) | |
2b5f62a0 | 1584 | { |
5175dbbd VS |
1585 | dc->GetTextExtent(drawntext.Last(), &w_c, &h_c); |
1586 | drawntext.RemoveLast(); | |
1587 | len--; | |
1588 | w -= w_c; | |
2b5f62a0 VZ |
1589 | if (w + base_w <= width) |
1590 | break; | |
2b5f62a0 VZ |
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); | |
5cd89174 | 1598 | } |
2b5f62a0 VZ |
1599 | |
1600 | // now draw the text | |
1601 | dc->DrawText(drawntext, x, y); | |
1602 | dc->DrawText(ellipsis, x + w, y); | |
e1e955e1 | 1603 | } |
e1e955e1 | 1604 | } |
c801d85f | 1605 | |
b54e41c5 | 1606 | bool wxListLineData::Highlight( bool on ) |
c801d85f | 1607 | { |
b54e41c5 | 1608 | wxCHECK_MSG( !m_owner->IsVirtual(), FALSE, _T("unexpected call to Highlight") ); |
c801d85f | 1609 | |
b54e41c5 | 1610 | if ( on == m_highlighted ) |
cf1dfa6b | 1611 | return FALSE; |
c801d85f | 1612 | |
b54e41c5 | 1613 | m_highlighted = on; |
c801d85f | 1614 | |
cf1dfa6b | 1615 | return TRUE; |
e1e955e1 | 1616 | } |
c801d85f | 1617 | |
b54e41c5 | 1618 | void wxListLineData::ReverseHighlight( void ) |
c801d85f | 1619 | { |
b54e41c5 | 1620 | Highlight(!IsHighlighted()); |
e1e955e1 | 1621 | } |
c801d85f KB |
1622 | |
1623 | //----------------------------------------------------------------------------- | |
1624 | // wxListHeaderWindow | |
1625 | //----------------------------------------------------------------------------- | |
1626 | ||
5a1cad6e | 1627 | IMPLEMENT_DYNAMIC_CLASS(wxListHeaderWindow,wxWindow) |
c801d85f KB |
1628 | |
1629 | BEGIN_EVENT_TABLE(wxListHeaderWindow,wxWindow) | |
63852e78 RR |
1630 | EVT_PAINT (wxListHeaderWindow::OnPaint) |
1631 | EVT_MOUSE_EVENTS (wxListHeaderWindow::OnMouse) | |
1632 | EVT_SET_FOCUS (wxListHeaderWindow::OnSetFocus) | |
c801d85f KB |
1633 | END_EVENT_TABLE() |
1634 | ||
0a816d95 | 1635 | void wxListHeaderWindow::Init() |
c801d85f | 1636 | { |
63852e78 | 1637 | m_currentCursor = (wxCursor *) NULL; |
cfb50f14 | 1638 | m_isDragging = FALSE; |
0a816d95 VZ |
1639 | m_dirty = FALSE; |
1640 | } | |
1641 | ||
1642 | wxListHeaderWindow::wxListHeaderWindow() | |
1643 | { | |
1644 | Init(); | |
1645 | ||
1646 | m_owner = (wxListMainWindow *) NULL; | |
1647 | m_resizeCursor = (wxCursor *) NULL; | |
e1e955e1 | 1648 | } |
c801d85f | 1649 | |
0a816d95 VZ |
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 ) | |
c801d85f | 1658 | { |
0a816d95 VZ |
1659 | Init(); |
1660 | ||
63852e78 | 1661 | m_owner = owner; |
63852e78 | 1662 | m_resizeCursor = new wxCursor( wxCURSOR_SIZEWE ); |
f6bcfd97 | 1663 | |
a756f210 | 1664 | SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE ) ); |
e1e955e1 | 1665 | } |
c801d85f | 1666 | |
0a816d95 | 1667 | wxListHeaderWindow::~wxListHeaderWindow() |
a367b9b3 | 1668 | { |
63852e78 | 1669 | delete m_resizeCursor; |
a367b9b3 JS |
1670 | } |
1671 | ||
2b5f62a0 VZ |
1672 | #ifdef __WXUNIVERSAL__ |
1673 | #include "wx/univ/renderer.h" | |
1674 | #include "wx/univ/theme.h" | |
1675 | #endif | |
1676 | ||
f6bcfd97 BP |
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 | { | |
f6bcfd97 BP |
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 ); | |
f6bcfd97 BP |
1689 | } |
1690 | ||
c801d85f KB |
1691 | void wxListHeaderWindow::OnPaint( wxPaintEvent &WXUNUSED(event) ) |
1692 | { | |
63852e78 | 1693 | wxPaintDC dc( this ); |
10bd0724 | 1694 | |
63852e78 | 1695 | PrepareDC( dc ); |
f6bcfd97 | 1696 | AdjustDC( dc ); |
bffa1c77 | 1697 | |
63852e78 | 1698 | dc.BeginDrawing(); |
bd8289c1 | 1699 | |
63852e78 | 1700 | dc.SetFont( GetFont() ); |
bd8289c1 | 1701 | |
f6bcfd97 BP |
1702 | // width and height of the entire header window |
1703 | int w, h; | |
63852e78 | 1704 | GetClientSize( &w, &h ); |
f6bcfd97 | 1705 | m_owner->CalcUnscrolledPosition(w, 0, &w, NULL); |
c801d85f | 1706 | |
f60d0f94 | 1707 | dc.SetBackgroundMode(wxTRANSPARENT); |
70846f0a VZ |
1708 | |
1709 | // do *not* use the listctrl colour for headers - one day we will have a | |
1710 | // function to set it separately | |
37d403aa | 1711 | //dc.SetTextForeground( *wxBLACK ); |
cf1dfa6b VZ |
1712 | dc.SetTextForeground(wxSystemSettings:: |
1713 | GetSystemColour( wxSYS_COLOUR_WINDOWTEXT )); | |
1714 | ||
1715 | int x = HEADER_OFFSET_X; | |
c801d85f | 1716 | |
63852e78 RR |
1717 | int numColumns = m_owner->GetColumnCount(); |
1718 | wxListItem item; | |
c5b7bb59 | 1719 | for ( int i = 0; i < numColumns && x < w; i++ ) |
63852e78 RR |
1720 | { |
1721 | m_owner->GetColumn( i, item ); | |
f6bcfd97 | 1722 | int wCol = item.m_width; |
f6bcfd97 | 1723 | |
0a816d95 VZ |
1724 | // the width of the rect to draw: make it smaller to fit entirely |
1725 | // inside the column rect | |
1726 | int cw = wCol - 2; | |
f6bcfd97 | 1727 | |
9c7f49f5 VZ |
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 | ); | |
0a816d95 | 1736 | |
e1e1272f VZ |
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; | |
73795999 VZ |
1746 | int ix = 0, // init them just to suppress the compiler warnings |
1747 | iy = 0; | |
e1e1272f VZ |
1748 | const int image = item.m_image; |
1749 | wxImageListType *imageList; | |
0a816d95 VZ |
1750 | if ( image != -1 ) |
1751 | { | |
e1e1272f | 1752 | imageList = m_owner->m_small_image_list; |
0a816d95 VZ |
1753 | if ( imageList ) |
1754 | { | |
0a816d95 | 1755 | imageList->GetSize(image, ix, iy); |
e1e1272f VZ |
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 | |
0a816d95 | 1771 | |
e1e1272f VZ |
1772 | case wxLIST_FORMAT_LEFT: |
1773 | xAligned = x; | |
1774 | break; | |
0a816d95 | 1775 | |
e1e1272f VZ |
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; | |
0a816d95 VZ |
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 ); | |
06b781c7 VZ |
1804 | |
1805 | dc.DrawText( item.GetText(), | |
e1e1272f | 1806 | xAligned + EXTRA_WIDTH, HEADER_OFFSET_Y + EXTRA_HEIGHT ); |
06b781c7 | 1807 | |
0a816d95 | 1808 | x += wCol; |
63852e78 | 1809 | } |
c5b7bb59 | 1810 | |
63852e78 | 1811 | dc.EndDrawing(); |
e1e955e1 | 1812 | } |
c801d85f | 1813 | |
0208334d RR |
1814 | void wxListHeaderWindow::DrawCurrent() |
1815 | { | |
63852e78 RR |
1816 | int x1 = m_currentX; |
1817 | int y1 = 0; | |
f16ba4e6 | 1818 | m_owner->ClientToScreen( &x1, &y1 ); |
f6bcfd97 | 1819 | |
f16ba4e6 | 1820 | int x2 = m_currentX; |
63852e78 | 1821 | int y2 = 0; |
f6bcfd97 | 1822 | m_owner->GetClientSize( NULL, &y2 ); |
63852e78 | 1823 | m_owner->ClientToScreen( &x2, &y2 ); |
0208334d | 1824 | |
63852e78 | 1825 | wxScreenDC dc; |
3c679789 | 1826 | dc.SetLogicalFunction( wxINVERT ); |
63852e78 RR |
1827 | dc.SetPen( wxPen( *wxBLACK, 2, wxSOLID ) ); |
1828 | dc.SetBrush( *wxTRANSPARENT_BRUSH ); | |
0208334d | 1829 | |
f6bcfd97 BP |
1830 | AdjustDC(dc); |
1831 | ||
63852e78 | 1832 | dc.DrawLine( x1, y1, x2, y2 ); |
0208334d | 1833 | |
63852e78 | 1834 | dc.SetLogicalFunction( wxCOPY ); |
0208334d | 1835 | |
63852e78 RR |
1836 | dc.SetPen( wxNullPen ); |
1837 | dc.SetBrush( wxNullBrush ); | |
0208334d RR |
1838 | } |
1839 | ||
c801d85f KB |
1840 | void wxListHeaderWindow::OnMouse( wxMouseEvent &event ) |
1841 | { | |
f6bcfd97 | 1842 | // we want to work with logical coords |
3ca6a5f0 BP |
1843 | int x; |
1844 | m_owner->CalcUnscrolledPosition(event.GetX(), 0, &x, NULL); | |
3ca6a5f0 | 1845 | int y = event.GetY(); |
f6bcfd97 | 1846 | |
cfb50f14 | 1847 | if (m_isDragging) |
0208334d | 1848 | { |
355f2407 | 1849 | SendListEvent(wxEVT_COMMAND_LIST_COL_DRAGGING, event.GetPosition()); |
a77ec46d | 1850 | |
f6bcfd97 BP |
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 ); | |
f6bcfd97 | 1855 | m_owner->CalcUnscrolledPosition(w, 0, &w, NULL); |
f6bcfd97 BP |
1856 | w -= 6; |
1857 | ||
1858 | // erase the line if it was drawn | |
1859 | if ( m_currentX < w ) | |
1860 | DrawCurrent(); | |
1861 | ||
63852e78 RR |
1862 | if (event.ButtonUp()) |
1863 | { | |
1864 | ReleaseMouse(); | |
cfb50f14 | 1865 | m_isDragging = FALSE; |
f6bcfd97 BP |
1866 | m_dirty = TRUE; |
1867 | m_owner->SetColumnWidth( m_column, m_currentX - m_minX ); | |
355f2407 | 1868 | SendListEvent(wxEVT_COMMAND_LIST_COL_END_DRAG, event.GetPosition()); |
63852e78 RR |
1869 | } |
1870 | else | |
1871 | { | |
f6bcfd97 | 1872 | if (x > m_minX + 7) |
63852e78 RR |
1873 | m_currentX = x; |
1874 | else | |
f6bcfd97 | 1875 | m_currentX = m_minX + 7; |
bd8289c1 | 1876 | |
f6bcfd97 BP |
1877 | // draw in the new location |
1878 | if ( m_currentX < w ) | |
1879 | DrawCurrent(); | |
bffa1c77 | 1880 | } |
0208334d | 1881 | } |
f6bcfd97 | 1882 | else // not dragging |
c801d85f | 1883 | { |
f6bcfd97 BP |
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 | |
62313c27 VZ |
1891 | int col, |
1892 | countCol = m_owner->GetColumnCount(); | |
1893 | for (col = 0; col < countCol; col++) | |
bffa1c77 | 1894 | { |
cf1dfa6b VZ |
1895 | xpos += m_owner->GetColumnWidth( col ); |
1896 | m_column = col; | |
f6bcfd97 BP |
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; | |
bffa1c77 | 1912 | } |
63852e78 | 1913 | |
62313c27 VZ |
1914 | if ( col == countCol ) |
1915 | m_column = -1; | |
1916 | ||
11358d39 | 1917 | if (event.LeftDown() || event.RightUp()) |
63852e78 | 1918 | { |
11358d39 | 1919 | if (hit_border && event.LeftDown()) |
f6bcfd97 | 1920 | { |
355f2407 VZ |
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 | |
f6bcfd97 | 1930 | } |
11358d39 | 1931 | else // click on a column |
f6bcfd97 | 1932 | { |
a77ec46d | 1933 | SendListEvent( event.LeftDown() |
11358d39 VZ |
1934 | ? wxEVT_COMMAND_LIST_COL_CLICK |
1935 | : wxEVT_COMMAND_LIST_COL_RIGHT_CLICK, | |
a77ec46d | 1936 | event.GetPosition()); |
f6bcfd97 | 1937 | } |
63852e78 | 1938 | } |
f6bcfd97 | 1939 | else if (event.Moving()) |
63852e78 | 1940 | { |
f6bcfd97 BP |
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); | |
63852e78 | 1955 | } |
e1e955e1 | 1956 | } |
e1e955e1 | 1957 | } |
c801d85f KB |
1958 | |
1959 | void wxListHeaderWindow::OnSetFocus( wxFocusEvent &WXUNUSED(event) ) | |
1960 | { | |
63852e78 | 1961 | m_owner->SetFocus(); |
e1e955e1 | 1962 | } |
c801d85f | 1963 | |
355f2407 | 1964 | bool wxListHeaderWindow::SendListEvent(wxEventType type, wxPoint pos) |
a77ec46d RD |
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; | |
355f2407 | 1978 | return !parent->GetEventHandler()->ProcessEvent( le ) || le.IsAllowed(); |
a77ec46d RD |
1979 | } |
1980 | ||
c801d85f KB |
1981 | //----------------------------------------------------------------------------- |
1982 | // wxListRenameTimer (internal) | |
1983 | //----------------------------------------------------------------------------- | |
1984 | ||
bd8289c1 VZ |
1985 | wxListRenameTimer::wxListRenameTimer( wxListMainWindow *owner ) |
1986 | { | |
63852e78 | 1987 | m_owner = owner; |
e1e955e1 | 1988 | } |
c801d85f | 1989 | |
bd8289c1 VZ |
1990 | void wxListRenameTimer::Notify() |
1991 | { | |
63852e78 | 1992 | m_owner->OnRenameTimer(); |
e1e955e1 | 1993 | } |
c801d85f | 1994 | |
ee7ee469 RR |
1995 | //----------------------------------------------------------------------------- |
1996 | // wxListTextCtrl (internal) | |
1997 | //----------------------------------------------------------------------------- | |
1998 | ||
ee7ee469 | 1999 | BEGIN_EVENT_TABLE(wxListTextCtrl,wxTextCtrl) |
63852e78 | 2000 | EVT_CHAR (wxListTextCtrl::OnChar) |
2c1f73ee | 2001 | EVT_KEY_UP (wxListTextCtrl::OnKeyUp) |
63852e78 | 2002 | EVT_KILL_FOCUS (wxListTextCtrl::OnKillFocus) |
ee7ee469 RR |
2003 | END_EVENT_TABLE() |
2004 | ||
62d89eb4 VZ |
2005 | wxListTextCtrl::wxListTextCtrl(wxListMainWindow *owner, size_t itemEdit) |
2006 | : m_startValue(owner->GetItemText(itemEdit)), | |
2007 | m_itemEdited(itemEdit) | |
2008 | { | |
63852e78 | 2009 | m_owner = owner; |
dd5a32cc | 2010 | m_finished = FALSE; |
62d89eb4 VZ |
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)); | |
ee7ee469 RR |
2020 | } |
2021 | ||
62d89eb4 | 2022 | void wxListTextCtrl::Finish() |
ee7ee469 | 2023 | { |
62d89eb4 | 2024 | if ( !m_finished ) |
63852e78 | 2025 | { |
62d89eb4 | 2026 | wxPendingDelete.Append(this); |
f6bcfd97 | 2027 | |
dd5a32cc | 2028 | m_finished = TRUE; |
62d89eb4 | 2029 | |
a6d57d03 | 2030 | m_owner->SetFocus(); |
62d89eb4 VZ |
2031 | } |
2032 | } | |
dd5a32cc | 2033 | |
62d89eb4 VZ |
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; | |
63852e78 | 2042 | } |
62d89eb4 VZ |
2043 | |
2044 | if ( !m_owner->OnRenameAccept(m_itemEdited, value) ) | |
63852e78 | 2045 | { |
62d89eb4 VZ |
2046 | // vetoed by the user |
2047 | return FALSE; | |
2048 | } | |
f6bcfd97 | 2049 | |
62d89eb4 VZ |
2050 | // accepted, do rename the item |
2051 | m_owner->SetItemText(m_itemEdited, value); | |
f6bcfd97 | 2052 | |
62d89eb4 VZ |
2053 | return TRUE; |
2054 | } | |
dd5a32cc | 2055 | |
62d89eb4 VZ |
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 | |
f6bcfd97 | 2067 | |
62d89eb4 VZ |
2068 | case WXK_ESCAPE: |
2069 | Finish(); | |
86586459 | 2070 | m_owner->OnRenameCancelled( m_itemEdited ); |
62d89eb4 VZ |
2071 | break; |
2072 | ||
2073 | default: | |
2074 | event.Skip(); | |
2075 | } | |
63852e78 RR |
2076 | } |
2077 | ||
c13cace1 VS |
2078 | void wxListTextCtrl::OnKeyUp( wxKeyEvent &event ) |
2079 | { | |
dd5a32cc RR |
2080 | if (m_finished) |
2081 | { | |
2082 | event.Skip(); | |
2083 | return; | |
2084 | } | |
2085 | ||
c13cace1 VS |
2086 | // auto-grow the textctrl: |
2087 | wxSize parentSize = m_owner->GetSize(); | |
2088 | wxPoint myPos = GetPosition(); | |
2089 | wxSize mySize = GetSize(); | |
2090 | int sx, sy; | |
a6d57d03 | 2091 | GetTextExtent(GetValue() + _T("MM"), &sx, &sy); |
cf1dfa6b VZ |
2092 | if (myPos.x + sx > parentSize.x) |
2093 | sx = parentSize.x - myPos.x; | |
2094 | if (mySize.x > sx) | |
2095 | sx = mySize.x; | |
c13cace1 | 2096 | SetSize(sx, -1); |
2c1f73ee | 2097 | |
c13cace1 VS |
2098 | event.Skip(); |
2099 | } | |
2100 | ||
dd5a32cc | 2101 | void wxListTextCtrl::OnKillFocus( wxFocusEvent &event ) |
63852e78 | 2102 | { |
62d89eb4 | 2103 | if ( !m_finished ) |
dd5a32cc | 2104 | { |
86586459 | 2105 | // We must finish regardless of success, otherwise we'll get focus problems |
62d89eb4 | 2106 | Finish(); |
86351e4a | 2107 | |
86586459 RR |
2108 | if ( !AcceptChanges() ) |
2109 | m_owner->OnRenameCancelled( m_itemEdited ); | |
62d89eb4 | 2110 | } |
86351e4a | 2111 | |
62d89eb4 | 2112 | event.Skip(); |
ee7ee469 RR |
2113 | } |
2114 | ||
c801d85f KB |
2115 | //----------------------------------------------------------------------------- |
2116 | // wxListMainWindow | |
2117 | //----------------------------------------------------------------------------- | |
2118 | ||
5a1cad6e | 2119 | IMPLEMENT_DYNAMIC_CLASS(wxListMainWindow,wxScrolledWindow) |
bd8289c1 | 2120 | |
c801d85f KB |
2121 | BEGIN_EVENT_TABLE(wxListMainWindow,wxScrolledWindow) |
2122 | EVT_PAINT (wxListMainWindow::OnPaint) | |
c801d85f KB |
2123 | EVT_MOUSE_EVENTS (wxListMainWindow::OnMouse) |
2124 | EVT_CHAR (wxListMainWindow::OnChar) | |
3dfb93fd | 2125 | EVT_KEY_DOWN (wxListMainWindow::OnKeyDown) |
c801d85f KB |
2126 | EVT_SET_FOCUS (wxListMainWindow::OnSetFocus) |
2127 | EVT_KILL_FOCUS (wxListMainWindow::OnKillFocus) | |
2fa7c206 | 2128 | EVT_SCROLLWIN (wxListMainWindow::OnScroll) |
c801d85f KB |
2129 | END_EVENT_TABLE() |
2130 | ||
1370703e | 2131 | void wxListMainWindow::Init() |
c801d85f | 2132 | { |
139adb6a | 2133 | m_dirty = TRUE; |
cf1dfa6b VZ |
2134 | m_countVirt = 0; |
2135 | m_lineFrom = | |
b54e41c5 | 2136 | m_lineTo = (size_t)-1; |
cf1dfa6b VZ |
2137 | m_linesPerPage = 0; |
2138 | ||
2139 | m_headerWidth = | |
2140 | m_lineHeight = 0; | |
1370703e | 2141 | |
80020b62 JS |
2142 | m_small_image_list = (wxImageListType *) NULL; |
2143 | m_normal_image_list = (wxImageListType *) NULL; | |
1370703e | 2144 | |
139adb6a RR |
2145 | m_small_spacing = 30; |
2146 | m_normal_spacing = 40; | |
1370703e | 2147 | |
139adb6a | 2148 | m_hasFocus = FALSE; |
1370703e VZ |
2149 | m_dragCount = 0; |
2150 | m_isCreated = FALSE; | |
2151 | ||
139adb6a RR |
2152 | m_lastOnSame = FALSE; |
2153 | m_renameTimer = new wxListRenameTimer( this ); | |
1370703e | 2154 | |
cf1dfa6b | 2155 | m_current = |
efbb7287 | 2156 | m_lineLastClicked = |
1370703e | 2157 | m_lineBeforeLastClicked = (size_t)-1; |
c5c528fc VZ |
2158 | |
2159 | m_freezeCount = 0; | |
e1e955e1 | 2160 | } |
c801d85f | 2161 | |
1370703e | 2162 | wxListMainWindow::wxListMainWindow() |
c801d85f | 2163 | { |
1370703e VZ |
2164 | Init(); |
2165 | ||
49ecb029 VZ |
2166 | m_highlightBrush = |
2167 | m_highlightUnfocusedBrush = (wxBrush *) NULL; | |
1370703e VZ |
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 | ||
49ecb029 VZ |
2181 | m_highlightBrush = new wxBrush |
2182 | ( | |
a756f210 | 2183 | wxSystemSettings::GetColour |
49ecb029 VZ |
2184 | ( |
2185 | wxSYS_COLOUR_HIGHLIGHT | |
2186 | ), | |
2187 | wxSOLID | |
2188 | ); | |
2189 | ||
2190 | m_highlightUnfocusedBrush = new wxBrush | |
2191 | ( | |
a756f210 | 2192 | wxSystemSettings::GetColour |
49ecb029 VZ |
2193 | ( |
2194 | wxSYS_COLOUR_BTNSHADOW | |
2195 | ), | |
2196 | wxSOLID | |
2197 | ); | |
2198 | ||
139adb6a RR |
2199 | wxSize sz = size; |
2200 | sz.y = 25; | |
bd8289c1 | 2201 | |
13602ebd | 2202 | SetScrollbars( SCROLL_UNIT_X, SCROLL_UNIT_Y, 0, 0, 0, 0 ); |
bd8289c1 | 2203 | |
a756f210 | 2204 | SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_LISTBOX ) ); |
e1e955e1 | 2205 | } |
c801d85f | 2206 | |
fd9811b1 | 2207 | wxListMainWindow::~wxListMainWindow() |
c801d85f | 2208 | { |
5fe143df | 2209 | DoDeleteAllItems(); |
222ed1d6 | 2210 | WX_CLEAR_LIST(wxListHeaderDataList, m_columns); |
12c1b46a | 2211 | |
b54e41c5 | 2212 | delete m_highlightBrush; |
49ecb029 | 2213 | delete m_highlightUnfocusedBrush; |
004fd0c8 | 2214 | |
139adb6a | 2215 | delete m_renameTimer; |
e1e955e1 | 2216 | } |
c801d85f | 2217 | |
cf1dfa6b | 2218 | void wxListMainWindow::CacheLineData(size_t line) |
c801d85f | 2219 | { |
3cd94a0d | 2220 | wxGenericListCtrl *listctrl = GetListCtrl(); |
25e3a937 | 2221 | |
b54e41c5 | 2222 | wxListLineData *ld = GetDummyLine(); |
f6bcfd97 | 2223 | |
cf1dfa6b VZ |
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 | ||
5cd89174 | 2230 | ld->SetImage(listctrl->OnGetItemImage(line)); |
6c02c329 | 2231 | ld->SetAttr(listctrl->OnGetItemAttr(line)); |
e1e955e1 | 2232 | } |
c801d85f | 2233 | |
b54e41c5 | 2234 | wxListLineData *wxListMainWindow::GetDummyLine() const |
c801d85f | 2235 | { |
cf1dfa6b | 2236 | wxASSERT_MSG( !IsEmpty(), _T("invalid line index") ); |
2c1f73ee | 2237 | |
904ccf52 VZ |
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() ) | |
2c1f73ee | 2247 | { |
904ccf52 VZ |
2248 | self->m_lines.Clear(); |
2249 | } | |
cf1dfa6b | 2250 | |
904ccf52 VZ |
2251 | if ( m_lines.IsEmpty() ) |
2252 | { | |
5cd89174 | 2253 | wxListLineData *line = new wxListLineData(self); |
cf1dfa6b | 2254 | self->m_lines.Add(line); |
904ccf52 VZ |
2255 | |
2256 | // don't waste extra memory -- there never going to be anything | |
2257 | // else/more in this array | |
2258 | self->m_lines.Shrink(); | |
2c1f73ee VZ |
2259 | } |
2260 | ||
cf1dfa6b VZ |
2261 | return &m_lines[0]; |
2262 | } | |
2263 | ||
5cd89174 VZ |
2264 | // ---------------------------------------------------------------------------- |
2265 | // line geometry (report mode only) | |
2266 | // ---------------------------------------------------------------------------- | |
2267 | ||
cf1dfa6b VZ |
2268 | wxCoord wxListMainWindow::GetLineHeight() const |
2269 | { | |
2270 | wxASSERT_MSG( HasFlag(wxLC_REPORT), _T("only works in report mode") ); | |
673dfcfa | 2271 | |
cf1dfa6b VZ |
2272 | // we cache the line height as calling GetTextExtent() is slow |
2273 | if ( !m_lineHeight ) | |
2c1f73ee | 2274 | { |
cf1dfa6b | 2275 | wxListMainWindow *self = wxConstCast(this, wxListMainWindow); |
bd8289c1 | 2276 | |
cf1dfa6b VZ |
2277 | wxClientDC dc( self ); |
2278 | dc.SetFont( GetFont() ); | |
c801d85f | 2279 | |
cf1dfa6b VZ |
2280 | wxCoord y; |
2281 | dc.GetTextExtent(_T("H"), NULL, &y); | |
004fd0c8 | 2282 | |
cf1dfa6b VZ |
2283 | if ( y < SCROLL_UNIT_Y ) |
2284 | y = SCROLL_UNIT_Y; | |
206b0a67 | 2285 | |
ca7353de RD |
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; | |
cf1dfa6b VZ |
2295 | self->m_lineHeight = y + LINE_SPACING; |
2296 | } | |
bffa1c77 | 2297 | |
cf1dfa6b VZ |
2298 | return m_lineHeight; |
2299 | } | |
bffa1c77 | 2300 | |
cf1dfa6b VZ |
2301 | wxCoord wxListMainWindow::GetLineY(size_t line) const |
2302 | { | |
2303 | wxASSERT_MSG( HasFlag(wxLC_REPORT), _T("only works in report mode") ); | |
1370703e | 2304 | |
cf1dfa6b VZ |
2305 | return LINE_SPACING + line*GetLineHeight(); |
2306 | } | |
206b0a67 | 2307 | |
5cd89174 VZ |
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 | { | |
fc4f1d5f VZ |
2360 | wxASSERT_MSG( line < GetItemCount(), _T("invalid line in HitTestLine") ); |
2361 | ||
5cd89174 VZ |
2362 | wxListLineData *ld = GetLine(line); |
2363 | ||
2364 | if ( ld->HasImage() && GetLineIconRect(line).Inside(x, y) ) | |
2365 | return wxLIST_HITTEST_ONITEMICON; | |
2366 | ||
acf4d858 VS |
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() ) | |
5cd89174 VZ |
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 | ||
b54e41c5 | 2386 | bool wxListMainWindow::IsHighlighted(size_t line) const |
cf1dfa6b VZ |
2387 | { |
2388 | if ( IsVirtual() ) | |
2389 | { | |
b54e41c5 | 2390 | return m_selStore.IsSelected(line); |
cf1dfa6b VZ |
2391 | } |
2392 | else // !virtual | |
2393 | { | |
2394 | wxListLineData *ld = GetLine(line); | |
b54e41c5 | 2395 | wxCHECK_MSG( ld, FALSE, _T("invalid index in IsHighlighted") ); |
cf1dfa6b | 2396 | |
b54e41c5 | 2397 | return ld->IsHighlighted(); |
cf1dfa6b VZ |
2398 | } |
2399 | } | |
2400 | ||
68a9ef0e VZ |
2401 | void wxListMainWindow::HighlightLines( size_t lineFrom, |
2402 | size_t lineTo, | |
2403 | bool highlight ) | |
cf1dfa6b | 2404 | { |
cf1dfa6b VZ |
2405 | if ( IsVirtual() ) |
2406 | { | |
68a9ef0e VZ |
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 | } | |
b54e41c5 | 2422 | } |
68a9ef0e | 2423 | else // iterate over all items in non report view |
b54e41c5 | 2424 | { |
b54e41c5 | 2425 | for ( size_t line = lineFrom; line <= lineTo; line++ ) |
cf1dfa6b | 2426 | { |
b54e41c5 | 2427 | if ( HighlightLine(line, highlight) ) |
68a9ef0e VZ |
2428 | { |
2429 | RefreshLine(line); | |
2430 | } | |
cf1dfa6b | 2431 | } |
b54e41c5 VZ |
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); | |
cf1dfa6b VZ |
2442 | } |
2443 | else // !virtual | |
2444 | { | |
2445 | wxListLineData *ld = GetLine(line); | |
49ecb029 | 2446 | wxCHECK_MSG( ld, FALSE, _T("invalid index in HighlightLine") ); |
cf1dfa6b | 2447 | |
b54e41c5 | 2448 | changed = ld->Highlight(highlight); |
cf1dfa6b VZ |
2449 | } |
2450 | ||
2451 | if ( changed ) | |
2452 | { | |
b54e41c5 | 2453 | SendNotify( line, highlight ? wxEVT_COMMAND_LIST_ITEM_SELECTED |
5cd89174 | 2454 | : wxEVT_COMMAND_LIST_ITEM_DESELECTED ); |
cf1dfa6b VZ |
2455 | } |
2456 | ||
2457 | return changed; | |
2458 | } | |
2459 | ||
2460 | void wxListMainWindow::RefreshLine( size_t line ) | |
2461 | { | |
6ea1323a VZ |
2462 | if ( HasFlag(wxLC_REPORT) ) |
2463 | { | |
2464 | size_t visibleFrom, visibleTo; | |
2465 | GetVisibleLinesRange(&visibleFrom, &visibleTo); | |
c1c4c551 | 2466 | |
6ea1323a VZ |
2467 | if ( line < visibleFrom || line > visibleTo ) |
2468 | return; | |
2469 | } | |
c1c4c551 | 2470 | |
5cd89174 | 2471 | wxRect rect = GetLineRect(line); |
cf1dfa6b VZ |
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 | ||
6b4a8d93 VZ |
2482 | wxASSERT_MSG( lineTo < GetItemCount(), _T("invalid line range") ); |
2483 | ||
cf1dfa6b VZ |
2484 | if ( HasFlag(wxLC_REPORT) ) |
2485 | { | |
b54e41c5 VZ |
2486 | size_t visibleFrom, visibleTo; |
2487 | GetVisibleLinesRange(&visibleFrom, &visibleTo); | |
2488 | ||
2489 | if ( lineFrom < visibleFrom ) | |
2490 | lineFrom = visibleFrom; | |
2491 | if ( lineTo > visibleTo ) | |
2492 | lineTo = visibleTo; | |
cf1dfa6b VZ |
2493 | |
2494 | wxRect rect; | |
2495 | rect.x = 0; | |
2496 | rect.y = GetLineY(lineFrom); | |
2497 | rect.width = GetClientSize().x; | |
91c6cc0e | 2498 | rect.height = GetLineY(lineTo) - rect.y + GetLineHeight(); |
cf1dfa6b VZ |
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 | ||
6b4a8d93 VZ |
2513 | void wxListMainWindow::RefreshAfter( size_t lineFrom ) |
2514 | { | |
2515 | if ( HasFlag(wxLC_REPORT) ) | |
2516 | { | |
c29582d0 JS |
2517 | size_t visibleFrom, visibleTo; |
2518 | GetVisibleLinesRange(&visibleFrom, &visibleTo); | |
6b4a8d93 VZ |
2519 | |
2520 | if ( lineFrom < visibleFrom ) | |
2521 | lineFrom = visibleFrom; | |
c29582d0 JS |
2522 | else if ( lineFrom > visibleTo ) |
2523 | return; | |
6b4a8d93 VZ |
2524 | |
2525 | wxRect rect; | |
2526 | rect.x = 0; | |
2527 | rect.y = GetLineY(lineFrom); | |
c29582d0 | 2528 | CalcScrolledPosition( rect.x, rect.y, &rect.x, &rect.y ); |
6b4a8d93 VZ |
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 | ||
6b4a8d93 | 2535 | RefreshRect( rect ); |
6b4a8d93 VZ |
2536 | } |
2537 | else // !report | |
2538 | { | |
2539 | // TODO: how to do it more efficiently? | |
2540 | m_dirty = TRUE; | |
2541 | } | |
2542 | } | |
2543 | ||
49ecb029 VZ |
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 | ||
cf30ae13 | 2560 | if ( HasCurrent() && m_current >= from && m_current <= to ) |
49ecb029 VZ |
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 | ||
c5c528fc VZ |
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 | ||
cf1dfa6b VZ |
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 | ||
c5c528fc | 2596 | if ( IsEmpty() || m_freezeCount ) |
cf1dfa6b | 2597 | { |
c5c528fc | 2598 | // nothing to draw or not the moment to draw it |
cf1dfa6b VZ |
2599 | return; |
2600 | } | |
2601 | ||
1e4d446b VZ |
2602 | if ( m_dirty ) |
2603 | { | |
2604 | // delay the repainting until we calculate all the items positions | |
2605 | return; | |
2606 | } | |
2607 | ||
cf1dfa6b VZ |
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 | { | |
b54e41c5 | 2619 | int lineHeight = GetLineHeight(); |
cf1dfa6b | 2620 | |
b54e41c5 VZ |
2621 | size_t visibleFrom, visibleTo; |
2622 | GetVisibleLinesRange(&visibleFrom, &visibleTo); | |
b84839ae VZ |
2623 | |
2624 | wxRect rectLine; | |
2625 | wxCoord xOrig, yOrig; | |
2626 | CalcUnscrolledPosition(0, 0, &xOrig, &yOrig); | |
2627 | ||
ff3d11a0 | 2628 | // tell the caller cache to cache the data |
91c6cc0e VZ |
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 | } | |
ff3d11a0 | 2638 | |
b54e41c5 | 2639 | for ( size_t line = visibleFrom; line <= visibleTo; line++ ) |
cf1dfa6b | 2640 | { |
b84839ae VZ |
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 | ||
5cd89174 | 2650 | GetLine(line)->DrawInReportMode( &dc, |
b84839ae | 2651 | rectLine, |
5cd89174 | 2652 | GetLineHighlightRect(line), |
49ecb029 | 2653 | IsHighlighted(line) ); |
cf1dfa6b VZ |
2654 | } |
2655 | ||
2656 | if ( HasFlag(wxLC_HRULES) ) | |
2657 | { | |
b54e41c5 | 2658 | wxPen pen(GetRuleColour(), 1, wxSOLID); |
cf1dfa6b VZ |
2659 | wxSize clientSize = GetClientSize(); |
2660 | ||
e7d073c3 RD |
2661 | // Don't draw the first one |
2662 | for ( size_t i = visibleFrom+1; i <= visibleTo; i++ ) | |
cf1dfa6b VZ |
2663 | { |
2664 | dc.SetPen(pen); | |
2665 | dc.SetBrush( *wxTRANSPARENT_BRUSH ); | |
b54e41c5 VZ |
2666 | dc.DrawLine(0 - dev_x, i*lineHeight, |
2667 | clientSize.x - dev_x, i*lineHeight); | |
cf1dfa6b VZ |
2668 | } |
2669 | ||
2670 | // Draw last horizontal rule | |
e7d073c3 | 2671 | if ( visibleTo == GetItemCount() - 1 ) |
cf1dfa6b VZ |
2672 | { |
2673 | dc.SetPen(pen); | |
2674 | dc.SetBrush( *wxTRANSPARENT_BRUSH ); | |
e7d073c3 RD |
2675 | dc.DrawLine(0 - dev_x, (m_lineTo+1)*lineHeight, |
2676 | clientSize.x - dev_x , (m_lineTo+1)*lineHeight ); | |
cf1dfa6b | 2677 | } |
2c1f73ee | 2678 | } |
206b0a67 JS |
2679 | |
2680 | // Draw vertical rules if required | |
cf1dfa6b | 2681 | if ( HasFlag(wxLC_VRULES) && !IsEmpty() ) |
206b0a67 | 2682 | { |
b54e41c5 | 2683 | wxPen pen(GetRuleColour(), 1, wxSOLID); |
cf1dfa6b | 2684 | |
206b0a67 JS |
2685 | int col = 0; |
2686 | wxRect firstItemRect; | |
2687 | wxRect lastItemRect; | |
e7d073c3 RD |
2688 | GetItemRect(visibleFrom, firstItemRect); |
2689 | GetItemRect(visibleTo, lastItemRect); | |
206b0a67 | 2690 | int x = firstItemRect.GetX(); |
673dfcfa JS |
2691 | dc.SetPen(pen); |
2692 | dc.SetBrush(* wxTRANSPARENT_BRUSH); | |
206b0a67 JS |
2693 | for (col = 0; col < GetColumnCount(); col++) |
2694 | { | |
2695 | int colWidth = GetColumnWidth(col); | |
cf1dfa6b | 2696 | x += colWidth; |
e7d073c3 RD |
2697 | dc.DrawLine(x - dev_x - 2, firstItemRect.GetY() - 1 - dev_y, |
2698 | x - dev_x - 2, lastItemRect.GetBottom() + 1 - dev_y); | |
206b0a67 | 2699 | } |
d786bf87 | 2700 | } |
139adb6a | 2701 | } |
cf1dfa6b | 2702 | else // !report |
139adb6a | 2703 | { |
1370703e | 2704 | size_t count = GetItemCount(); |
cf1dfa6b VZ |
2705 | for ( size_t i = 0; i < count; i++ ) |
2706 | { | |
2707 | GetLine(i)->Draw( &dc ); | |
2708 | } | |
139adb6a | 2709 | } |
004fd0c8 | 2710 | |
c25f61f1 | 2711 | if ( HasCurrent() ) |
cf1dfa6b | 2712 | { |
c25f61f1 | 2713 | // don't draw rect outline under Max if we already have the background |
49ecb029 VZ |
2714 | // color but under other platforms only draw it if we do: it is a bit |
2715 | // silly to draw "focus rect" if we don't have focus! | |
4176fb7d | 2716 | #ifdef __WXMAC__ |
c25f61f1 | 2717 | if ( !m_hasFocus ) |
49ecb029 VZ |
2718 | #else // !__WXMAC__ |
2719 | if ( m_hasFocus ) | |
2720 | #endif // __WXMAC__/!__WXMAC__ | |
c25f61f1 VZ |
2721 | { |
2722 | dc.SetPen( *wxBLACK_PEN ); | |
2723 | dc.SetBrush( *wxTRANSPARENT_BRUSH ); | |
2724 | dc.DrawRectangle( GetLineHighlightRect(m_current) ); | |
2725 | } | |
cf1dfa6b | 2726 | } |
c801d85f | 2727 | |
139adb6a | 2728 | dc.EndDrawing(); |
e1e955e1 | 2729 | } |
c801d85f | 2730 | |
b54e41c5 | 2731 | void wxListMainWindow::HighlightAll( bool on ) |
c801d85f | 2732 | { |
b54e41c5 | 2733 | if ( IsSingleSel() ) |
c801d85f | 2734 | { |
b54e41c5 VZ |
2735 | wxASSERT_MSG( !on, _T("can't do this in a single sel control") ); |
2736 | ||
2737 | // we just have one item to turn off | |
2738 | if ( HasCurrent() && IsHighlighted(m_current) ) | |
139adb6a | 2739 | { |
b54e41c5 VZ |
2740 | HighlightLine(m_current, FALSE); |
2741 | RefreshLine(m_current); | |
139adb6a | 2742 | } |
e1e955e1 | 2743 | } |
b54e41c5 | 2744 | else // multi sel |
cf1dfa6b | 2745 | { |
b54e41c5 | 2746 | HighlightLines(0, GetItemCount() - 1, on); |
cf1dfa6b | 2747 | } |
e1e955e1 | 2748 | } |
c801d85f | 2749 | |
cf1dfa6b | 2750 | void wxListMainWindow::SendNotify( size_t line, |
05a7f61d VZ |
2751 | wxEventType command, |
2752 | wxPoint point ) | |
c801d85f | 2753 | { |
139adb6a RR |
2754 | wxListEvent le( command, GetParent()->GetId() ); |
2755 | le.SetEventObject( GetParent() ); | |
cf1dfa6b | 2756 | le.m_itemIndex = line; |
05a7f61d VZ |
2757 | |
2758 | // set only for events which have position | |
2759 | if ( point != wxDefaultPosition ) | |
2760 | le.m_pointDrag = point; | |
2761 | ||
c1c4c551 VZ |
2762 | // don't try to get the line info for virtual list controls: the main |
2763 | // program has it anyhow and if we did it would result in accessing all | |
2764 | // the lines, even those which are not visible now and this is precisely | |
2765 | // what we're trying to avoid | |
2766 | if ( !IsVirtual() && (command != wxEVT_COMMAND_LIST_DELETE_ITEM) ) | |
91c6cc0e | 2767 | { |
0ddefeb0 VZ |
2768 | if ( line != (size_t)-1 ) |
2769 | { | |
2770 | GetLine(line)->GetItem( 0, le.m_item ); | |
2771 | } | |
2772 | //else: this happens for wxEVT_COMMAND_LIST_ITEM_FOCUSED event | |
91c6cc0e VZ |
2773 | } |
2774 | //else: there may be no more such item | |
2775 | ||
6e228e42 | 2776 | GetParent()->GetEventHandler()->ProcessEvent( le ); |
e1e955e1 | 2777 | } |
c801d85f | 2778 | |
0ddefeb0 | 2779 | void wxListMainWindow::ChangeCurrent(size_t current) |
c801d85f | 2780 | { |
0ddefeb0 | 2781 | m_current = current; |
c801d85f | 2782 | |
0ddefeb0 | 2783 | SendNotify(current, wxEVT_COMMAND_LIST_ITEM_FOCUSED); |
e1e955e1 | 2784 | } |
c801d85f | 2785 | |
5f1ea0ee | 2786 | void wxListMainWindow::EditLabel( long item ) |
c801d85f | 2787 | { |
cf1dfa6b | 2788 | wxCHECK_RET( (item >= 0) && ((size_t)item < GetItemCount()), |
3cd94a0d | 2789 | wxT("wrong index in wxGenericListCtrl::EditLabel()") ); |
004fd0c8 | 2790 | |
62d89eb4 | 2791 | size_t itemEdit = (size_t)item; |
e179bd65 | 2792 | |
fd9811b1 | 2793 | wxListEvent le( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT, GetParent()->GetId() ); |
139adb6a | 2794 | le.SetEventObject( GetParent() ); |
1370703e | 2795 | le.m_itemIndex = item; |
62d89eb4 | 2796 | wxListLineData *data = GetLine(itemEdit); |
1370703e VZ |
2797 | wxCHECK_RET( data, _T("invalid index in EditLabel()") ); |
2798 | data->GetItem( 0, le.m_item ); | |
62d89eb4 VZ |
2799 | if ( GetParent()->GetEventHandler()->ProcessEvent( le ) && !le.IsAllowed() ) |
2800 | { | |
2801 | // vetoed by user code | |
5f1ea0ee | 2802 | return; |
62d89eb4 | 2803 | } |
004fd0c8 | 2804 | |
cf1dfa6b VZ |
2805 | // We have to call this here because the label in question might just have |
2806 | // been added and no screen update taken place. | |
62d89eb4 | 2807 | if ( m_dirty ) |
cf1dfa6b | 2808 | wxSafeYield(); |
004fd0c8 | 2809 | |
62d89eb4 VZ |
2810 | wxListTextCtrl *text = new wxListTextCtrl(this, itemEdit); |
2811 | ||
92976ab6 | 2812 | text->SetFocus(); |
e1e955e1 | 2813 | } |
c801d85f | 2814 | |
e179bd65 RR |
2815 | void wxListMainWindow::OnRenameTimer() |
2816 | { | |
cf1dfa6b | 2817 | wxCHECK_RET( HasCurrent(), wxT("unexpected rename timer") ); |
004fd0c8 | 2818 | |
cf1dfa6b | 2819 | EditLabel( m_current ); |
e179bd65 RR |
2820 | } |
2821 | ||
62d89eb4 | 2822 | bool wxListMainWindow::OnRenameAccept(size_t itemEdit, const wxString& value) |
c801d85f | 2823 | { |
e179bd65 RR |
2824 | wxListEvent le( wxEVT_COMMAND_LIST_END_LABEL_EDIT, GetParent()->GetId() ); |
2825 | le.SetEventObject( GetParent() ); | |
62d89eb4 | 2826 | le.m_itemIndex = itemEdit; |
1370703e | 2827 | |
62d89eb4 VZ |
2828 | wxListLineData *data = GetLine(itemEdit); |
2829 | wxCHECK_MSG( data, FALSE, _T("invalid index in OnRenameAccept()") ); | |
1370703e VZ |
2830 | |
2831 | data->GetItem( 0, le.m_item ); | |
62d89eb4 VZ |
2832 | le.m_item.m_text = value; |
2833 | return !GetParent()->GetEventHandler()->ProcessEvent( le ) || | |
2834 | le.IsAllowed(); | |
e1e955e1 | 2835 | } |
c801d85f | 2836 | |
8f5a042b JJ |
2837 | #ifdef __VMS__ // Ignore unreacheable code |
2838 | # pragma message disable initnotreach | |
2839 | #endif | |
2840 | ||
8a39593e | 2841 | void wxListMainWindow::OnRenameCancelled(size_t WXUNUSED(itemEdit)) |
86586459 RR |
2842 | { |
2843 | // wxMSW seems not to notify the program about | |
2844 | // cancelled label edits. | |
2845 | return; | |
2846 | ||
8a39593e JS |
2847 | #if 0 |
2848 | // above unconditional return cause warning about not reachable code | |
2849 | ||
86586459 RR |
2850 | // let owner know that the edit was cancelled |
2851 | wxListEvent le( wxEVT_COMMAND_LIST_END_LABEL_EDIT, GetParent()->GetId() ); | |
86351e4a | 2852 | |
86586459 RR |
2853 | // These only exist for wxTreeCtrl, which should probably be changed |
2854 | // le.m_editCancelled = TRUE; | |
2855 | // le.m_label = wxEmptyString; | |
86351e4a | 2856 | |
86586459 RR |
2857 | le.SetEventObject( GetParent() ); |
2858 | le.m_itemIndex = itemEdit; | |
2859 | ||
2860 | wxListLineData *data = GetLine(itemEdit); | |
2861 | wxCHECK_RET( data, _T("invalid index in OnRenameCancelled()") ); | |
2862 | ||
2863 | data->GetItem( 0, le.m_item ); | |
2864 | ||
2865 | GetEventHandler()->ProcessEvent( le ); | |
8a39593e | 2866 | #endif |
86586459 | 2867 | } |
8f5a042b JJ |
2868 | #ifdef __VMS__ |
2869 | # pragma message enable initnotreach | |
2870 | #endif | |
86586459 | 2871 | |
c801d85f KB |
2872 | void wxListMainWindow::OnMouse( wxMouseEvent &event ) |
2873 | { | |
3e1c4e00 | 2874 | event.SetEventObject( GetParent() ); |
cf1dfa6b VZ |
2875 | if ( GetParent()->GetEventHandler()->ProcessEvent( event) ) |
2876 | return; | |
2877 | ||
2878 | if ( !HasCurrent() || IsEmpty() ) | |
2879 | return; | |
2880 | ||
2881 | if (m_dirty) | |
2882 | return; | |
e3e65dac | 2883 | |
cf1dfa6b VZ |
2884 | if ( !(event.Dragging() || event.ButtonDown() || event.LeftUp() || |
2885 | event.ButtonDClick()) ) | |
2886 | return; | |
c801d85f | 2887 | |
aaef15bf RR |
2888 | int x = event.GetX(); |
2889 | int y = event.GetY(); | |
2890 | CalcUnscrolledPosition( x, y, &x, &y ); | |
004fd0c8 | 2891 | |
cc734310 | 2892 | // where did we hit it (if we did)? |
92976ab6 | 2893 | long hitResult = 0; |
1370703e | 2894 | |
cf1dfa6b VZ |
2895 | size_t count = GetItemCount(), |
2896 | current; | |
2897 | ||
2898 | if ( HasFlag(wxLC_REPORT) ) | |
92976ab6 | 2899 | { |
5cd89174 | 2900 | current = y / GetLineHeight(); |
cc734310 VZ |
2901 | if ( current < count ) |
2902 | hitResult = HitTestLine(current, x, y); | |
cf1dfa6b VZ |
2903 | } |
2904 | else // !report | |
2905 | { | |
2906 | // TODO: optimize it too! this is less simple than for report view but | |
2907 | // enumerating all items is still not a way to do it!! | |
4e3ace65 | 2908 | for ( current = 0; current < count; current++ ) |
cf1dfa6b | 2909 | { |
5cd89174 | 2910 | hitResult = HitTestLine(current, x, y); |
4e3ace65 VZ |
2911 | if ( hitResult ) |
2912 | break; | |
cf1dfa6b | 2913 | } |
92976ab6 | 2914 | } |
bd8289c1 | 2915 | |
fd9811b1 | 2916 | if (event.Dragging()) |
92976ab6 | 2917 | { |
fd9811b1 | 2918 | if (m_dragCount == 0) |
8d1d2284 VZ |
2919 | { |
2920 | // we have to report the raw, physical coords as we want to be | |
2921 | // able to call HitTest(event.m_pointDrag) from the user code to | |
2922 | // get the item being dragged | |
2923 | m_dragStart = event.GetPosition(); | |
2924 | } | |
bffa1c77 | 2925 | |
fd9811b1 | 2926 | m_dragCount++; |
bffa1c77 | 2927 | |
cf1dfa6b VZ |
2928 | if (m_dragCount != 3) |
2929 | return; | |
bffa1c77 | 2930 | |
05a7f61d VZ |
2931 | int command = event.RightIsDown() ? wxEVT_COMMAND_LIST_BEGIN_RDRAG |
2932 | : wxEVT_COMMAND_LIST_BEGIN_DRAG; | |
bffa1c77 | 2933 | |
fd9811b1 | 2934 | wxListEvent le( command, GetParent()->GetId() ); |
92976ab6 | 2935 | le.SetEventObject( GetParent() ); |
e8c6a69c | 2936 | le.m_itemIndex = current; |
bffa1c77 VZ |
2937 | le.m_pointDrag = m_dragStart; |
2938 | GetParent()->GetEventHandler()->ProcessEvent( le ); | |
2939 | ||
2940 | return; | |
92976ab6 | 2941 | } |
fd9811b1 RR |
2942 | else |
2943 | { | |
2944 | m_dragCount = 0; | |
2945 | } | |
bd8289c1 | 2946 | |
cf1dfa6b VZ |
2947 | if ( !hitResult ) |
2948 | { | |
2949 | // outside of any item | |
2950 | return; | |
2951 | } | |
bd8289c1 | 2952 | |
efbb7287 | 2953 | bool forceClick = FALSE; |
92976ab6 RR |
2954 | if (event.ButtonDClick()) |
2955 | { | |
92976ab6 | 2956 | m_renameTimer->Stop(); |
efbb7287 VZ |
2957 | m_lastOnSame = FALSE; |
2958 | ||
ddba340d | 2959 | if ( current == m_lineLastClicked ) |
efbb7287 | 2960 | { |
cf1dfa6b | 2961 | SendNotify( current, wxEVT_COMMAND_LIST_ITEM_ACTIVATED ); |
004fd0c8 | 2962 | |
efbb7287 VZ |
2963 | return; |
2964 | } | |
2965 | else | |
2966 | { | |
2967 | // the first click was on another item, so don't interpret this as | |
2968 | // a double click, but as a simple click instead | |
2969 | forceClick = TRUE; | |
2970 | } | |
92976ab6 | 2971 | } |
bd8289c1 | 2972 | |
92976ab6 | 2973 | if (event.LeftUp() && m_lastOnSame) |
c801d85f | 2974 | { |
cf1dfa6b | 2975 | if ((current == m_current) && |
92976ab6 | 2976 | (hitResult == wxLIST_HITTEST_ONITEMLABEL) && |
cf1dfa6b | 2977 | HasFlag(wxLC_EDIT_LABELS) ) |
92976ab6 RR |
2978 | { |
2979 | m_renameTimer->Start( 100, TRUE ); | |
2980 | } | |
2981 | m_lastOnSame = FALSE; | |
e1e955e1 | 2982 | } |
cf1dfa6b | 2983 | else if (event.RightDown()) |
b204641e | 2984 | { |
cf1dfa6b | 2985 | SendNotify( current, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK, |
05a7f61d | 2986 | event.GetPosition() ); |
b204641e | 2987 | } |
cf1dfa6b | 2988 | else if (event.MiddleDown()) |
b204641e | 2989 | { |
cf1dfa6b | 2990 | SendNotify( current, wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK ); |
92976ab6 | 2991 | } |
cf1dfa6b | 2992 | else if ( event.LeftDown() || forceClick ) |
92976ab6 | 2993 | { |
efbb7287 | 2994 | m_lineBeforeLastClicked = m_lineLastClicked; |
cf1dfa6b VZ |
2995 | m_lineLastClicked = current; |
2996 | ||
2997 | size_t oldCurrent = m_current; | |
efbb7287 | 2998 | |
b54e41c5 | 2999 | if ( IsSingleSel() || !(event.ControlDown() || event.ShiftDown()) ) |
b204641e | 3000 | { |
b54e41c5 | 3001 | HighlightAll( FALSE ); |
0ddefeb0 VZ |
3002 | |
3003 | ChangeCurrent(current); | |
cf1dfa6b | 3004 | |
b54e41c5 | 3005 | ReverseHighlight(m_current); |
e1e955e1 | 3006 | } |
b54e41c5 | 3007 | else // multi sel & either ctrl or shift is down |
b204641e | 3008 | { |
473d087e | 3009 | if (event.ControlDown()) |
92976ab6 | 3010 | { |
0ddefeb0 | 3011 | ChangeCurrent(current); |
cf1dfa6b | 3012 | |
b54e41c5 | 3013 | ReverseHighlight(m_current); |
92976ab6 | 3014 | } |
473d087e | 3015 | else if (event.ShiftDown()) |
92976ab6 | 3016 | { |
0ddefeb0 | 3017 | ChangeCurrent(current); |
bffa1c77 | 3018 | |
cf1dfa6b VZ |
3019 | size_t lineFrom = oldCurrent, |
3020 | lineTo = current; | |
f6bcfd97 | 3021 | |
cf1dfa6b | 3022 | if ( lineTo < lineFrom ) |
92976ab6 | 3023 | { |
cf1dfa6b VZ |
3024 | lineTo = lineFrom; |
3025 | lineFrom = m_current; | |
92976ab6 RR |
3026 | } |
3027 | ||
b54e41c5 | 3028 | HighlightLines(lineFrom, lineTo); |
92976ab6 | 3029 | } |
cf1dfa6b | 3030 | else // !ctrl, !shift |
92976ab6 | 3031 | { |
cf1dfa6b VZ |
3032 | // test in the enclosing if should make it impossible |
3033 | wxFAIL_MSG( _T("how did we get here?") ); | |
92976ab6 | 3034 | } |
e1e955e1 | 3035 | } |
cf1dfa6b | 3036 | |
92976ab6 RR |
3037 | if (m_current != oldCurrent) |
3038 | { | |
3039 | RefreshLine( oldCurrent ); | |
92976ab6 | 3040 | } |
efbb7287 VZ |
3041 | |
3042 | // forceClick is only set if the previous click was on another item | |
3043 | m_lastOnSame = !forceClick && (m_current == oldCurrent); | |
e1e955e1 | 3044 | } |
e1e955e1 | 3045 | } |
c801d85f | 3046 | |
34bbbc27 | 3047 | void wxListMainWindow::MoveToItem(size_t item) |
c801d85f | 3048 | { |
34bbbc27 | 3049 | if ( item == (size_t)-1 ) |
cf1dfa6b | 3050 | return; |
004fd0c8 | 3051 | |
34bbbc27 | 3052 | wxRect rect = GetLineRect(item); |
cf3da716 | 3053 | |
cf1dfa6b | 3054 | int client_w, client_h; |
cf3da716 | 3055 | GetClientSize( &client_w, &client_h ); |
f6bcfd97 | 3056 | |
13602ebd VZ |
3057 | int view_x = SCROLL_UNIT_X*GetScrollPos( wxHORIZONTAL ); |
3058 | int view_y = SCROLL_UNIT_Y*GetScrollPos( wxVERTICAL ); | |
004fd0c8 | 3059 | |
cf1dfa6b | 3060 | if ( HasFlag(wxLC_REPORT) ) |
92976ab6 | 3061 | { |
b54e41c5 VZ |
3062 | // the next we need the range of lines shown it might be different, so |
3063 | // recalculate it | |
3064 | ResetVisibleLinesRange(); | |
3065 | ||
cf1dfa6b | 3066 | if (rect.y < view_y ) |
13602ebd | 3067 | Scroll( -1, rect.y/SCROLL_UNIT_Y ); |
cf1dfa6b | 3068 | if (rect.y+rect.height+5 > view_y+client_h) |
13602ebd | 3069 | Scroll( -1, (rect.y+rect.height-client_h+SCROLL_UNIT_Y)/SCROLL_UNIT_Y ); |
92976ab6 | 3070 | } |
b54e41c5 | 3071 | else // !report |
92976ab6 | 3072 | { |
cf1dfa6b | 3073 | if (rect.x-view_x < 5) |
13602ebd | 3074 | Scroll( (rect.x-5)/SCROLL_UNIT_X, -1 ); |
cf1dfa6b | 3075 | if (rect.x+rect.width-5 > view_x+client_w) |
13602ebd | 3076 | Scroll( (rect.x+rect.width-client_w+SCROLL_UNIT_X)/SCROLL_UNIT_X, -1 ); |
92976ab6 | 3077 | } |
e1e955e1 | 3078 | } |
c801d85f | 3079 | |
cf1dfa6b VZ |
3080 | // ---------------------------------------------------------------------------- |
3081 | // keyboard handling | |
3082 | // ---------------------------------------------------------------------------- | |
3083 | ||
3084 | void wxListMainWindow::OnArrowChar(size_t newCurrent, const wxKeyEvent& event) | |
c801d85f | 3085 | { |
cf1dfa6b VZ |
3086 | wxCHECK_RET( newCurrent < (size_t)GetItemCount(), |
3087 | _T("invalid item index in OnArrowChar()") ); | |
3088 | ||
3089 | size_t oldCurrent = m_current; | |
3090 | ||
3091 | // in single selection we just ignore Shift as we can't select several | |
3092 | // items anyhow | |
b54e41c5 | 3093 | if ( event.ShiftDown() && !IsSingleSel() ) |
cf1dfa6b | 3094 | { |
0ddefeb0 | 3095 | ChangeCurrent(newCurrent); |
cf1dfa6b VZ |
3096 | |
3097 | // select all the items between the old and the new one | |
3098 | if ( oldCurrent > newCurrent ) | |
3099 | { | |
3100 | newCurrent = oldCurrent; | |
3101 | oldCurrent = m_current; | |
3102 | } | |
3103 | ||
b54e41c5 | 3104 | HighlightLines(oldCurrent, newCurrent); |
cf1dfa6b VZ |
3105 | } |
3106 | else // !shift | |
3107 | { | |
b54e41c5 VZ |
3108 | // all previously selected items are unselected unless ctrl is held |
3109 | if ( !event.ControlDown() ) | |
3110 | HighlightAll(FALSE); | |
3111 | ||
0ddefeb0 | 3112 | ChangeCurrent(newCurrent); |
cf1dfa6b | 3113 | |
58c1c096 | 3114 | // refresh the old focus to remove it |
cf1dfa6b VZ |
3115 | RefreshLine( oldCurrent ); |
3116 | ||
3117 | if ( !event.ControlDown() ) | |
3118 | { | |
b54e41c5 | 3119 | HighlightLine( m_current, TRUE ); |
cf1dfa6b VZ |
3120 | } |
3121 | } | |
3122 | ||
92976ab6 | 3123 | RefreshLine( m_current ); |
cf1dfa6b | 3124 | |
cf3da716 | 3125 | MoveToFocus(); |
e1e955e1 | 3126 | } |
c801d85f | 3127 | |
3dfb93fd RR |
3128 | void wxListMainWindow::OnKeyDown( wxKeyEvent &event ) |
3129 | { | |
3130 | wxWindow *parent = GetParent(); | |
004fd0c8 | 3131 | |
3dfb93fd RR |
3132 | /* we propagate the key event up */ |
3133 | wxKeyEvent ke( wxEVT_KEY_DOWN ); | |
3134 | ke.m_shiftDown = event.m_shiftDown; | |
3135 | ke.m_controlDown = event.m_controlDown; | |
3136 | ke.m_altDown = event.m_altDown; | |
3137 | ke.m_metaDown = event.m_metaDown; | |
3138 | ke.m_keyCode = event.m_keyCode; | |
3139 | ke.m_x = event.m_x; | |
3140 | ke.m_y = event.m_y; | |
3141 | ke.SetEventObject( parent ); | |
3142 | if (parent->GetEventHandler()->ProcessEvent( ke )) return; | |
004fd0c8 | 3143 | |
3dfb93fd RR |
3144 | event.Skip(); |
3145 | } | |
004fd0c8 | 3146 | |
c801d85f KB |
3147 | void wxListMainWindow::OnChar( wxKeyEvent &event ) |
3148 | { | |
51cc4dad | 3149 | wxWindow *parent = GetParent(); |
004fd0c8 | 3150 | |
51cc4dad | 3151 | /* we send a list_key event up */ |
cf1dfa6b | 3152 | if ( HasCurrent() ) |
f6bcfd97 BP |
3153 | { |
3154 | wxListEvent le( wxEVT_COMMAND_LIST_KEY_DOWN, GetParent()->GetId() ); | |
cf1dfa6b VZ |
3155 | le.m_itemIndex = m_current; |
3156 | GetLine(m_current)->GetItem( 0, le.m_item ); | |
12a3f227 | 3157 | le.m_code = event.GetKeyCode(); |
f6bcfd97 BP |
3158 | le.SetEventObject( parent ); |
3159 | parent->GetEventHandler()->ProcessEvent( le ); | |
3160 | } | |
51cc4dad | 3161 | |
3dfb93fd RR |
3162 | /* we propagate the char event up */ |
3163 | wxKeyEvent ke( wxEVT_CHAR ); | |
51cc4dad RR |
3164 | ke.m_shiftDown = event.m_shiftDown; |
3165 | ke.m_controlDown = event.m_controlDown; | |
3166 | ke.m_altDown = event.m_altDown; | |
3167 | ke.m_metaDown = event.m_metaDown; | |
3168 | ke.m_keyCode = event.m_keyCode; | |
3169 | ke.m_x = event.m_x; | |
3170 | ke.m_y = event.m_y; | |
3171 | ke.SetEventObject( parent ); | |
3172 | if (parent->GetEventHandler()->ProcessEvent( ke )) return; | |
004fd0c8 | 3173 | |
12a3f227 | 3174 | if (event.GetKeyCode() == WXK_TAB) |
012a03e0 RR |
3175 | { |
3176 | wxNavigationKeyEvent nevent; | |
c5145d41 | 3177 | nevent.SetWindowChange( event.ControlDown() ); |
012a03e0 | 3178 | nevent.SetDirection( !event.ShiftDown() ); |
8253c7fd | 3179 | nevent.SetEventObject( GetParent()->GetParent() ); |
012a03e0 | 3180 | nevent.SetCurrentFocus( m_parent ); |
87948f22 VZ |
3181 | if (GetParent()->GetParent()->GetEventHandler()->ProcessEvent( nevent )) |
3182 | return; | |
012a03e0 | 3183 | } |
004fd0c8 | 3184 | |
51cc4dad | 3185 | /* no item -> nothing to do */ |
cf1dfa6b | 3186 | if (!HasCurrent()) |
c801d85f | 3187 | { |
51cc4dad RR |
3188 | event.Skip(); |
3189 | return; | |
e1e955e1 | 3190 | } |
51cc4dad | 3191 | |
12a3f227 | 3192 | switch (event.GetKeyCode()) |
c801d85f | 3193 | { |
51cc4dad | 3194 | case WXK_UP: |
cf1dfa6b VZ |
3195 | if ( m_current > 0 ) |
3196 | OnArrowChar( m_current - 1, event ); | |
51cc4dad | 3197 | break; |
cf1dfa6b | 3198 | |
51cc4dad | 3199 | case WXK_DOWN: |
cf1dfa6b VZ |
3200 | if ( m_current < (size_t)GetItemCount() - 1 ) |
3201 | OnArrowChar( m_current + 1, event ); | |
51cc4dad | 3202 | break; |
cf1dfa6b | 3203 | |
51cc4dad | 3204 | case WXK_END: |
1370703e | 3205 | if (!IsEmpty()) |
cf1dfa6b | 3206 | OnArrowChar( GetItemCount() - 1, event ); |
51cc4dad | 3207 | break; |
cf1dfa6b | 3208 | |
51cc4dad | 3209 | case WXK_HOME: |
1370703e | 3210 | if (!IsEmpty()) |
cf1dfa6b | 3211 | OnArrowChar( 0, event ); |
51cc4dad | 3212 | break; |
cf1dfa6b | 3213 | |
51cc4dad | 3214 | case WXK_PRIOR: |
f6bcfd97 | 3215 | { |
cf1dfa6b VZ |
3216 | int steps = 0; |
3217 | if ( HasFlag(wxLC_REPORT) ) | |
3218 | { | |
3219 | steps = m_linesPerPage - 1; | |
3220 | } | |
3221 | else | |
3222 | { | |
3223 | steps = m_current % m_linesPerPage; | |
3224 | } | |
3225 | ||
3226 | int index = m_current - steps; | |
3227 | if (index < 0) | |
3228 | index = 0; | |
3229 | ||
3230 | OnArrowChar( index, event ); | |
51cc4dad | 3231 | } |
51cc4dad | 3232 | break; |
cf1dfa6b | 3233 | |
51cc4dad | 3234 | case WXK_NEXT: |
bffa1c77 | 3235 | { |
cf1dfa6b VZ |
3236 | int steps = 0; |
3237 | if ( HasFlag(wxLC_REPORT) ) | |
3238 | { | |
3239 | steps = m_linesPerPage - 1; | |
3240 | } | |
3241 | else | |
3242 | { | |
3243 | steps = m_linesPerPage - (m_current % m_linesPerPage) - 1; | |
3244 | } | |
f6bcfd97 | 3245 | |
cf1dfa6b VZ |
3246 | size_t index = m_current + steps; |
3247 | size_t count = GetItemCount(); | |
3248 | if ( index >= count ) | |
3249 | index = count - 1; | |
3250 | ||
3251 | OnArrowChar( index, event ); | |
51cc4dad | 3252 | } |
51cc4dad | 3253 | break; |
cf1dfa6b | 3254 | |
51cc4dad | 3255 | case WXK_LEFT: |
cf1dfa6b | 3256 | if ( !HasFlag(wxLC_REPORT) ) |
51cc4dad | 3257 | { |
cf1dfa6b VZ |
3258 | int index = m_current - m_linesPerPage; |
3259 | if (index < 0) | |
3260 | index = 0; | |
3261 | ||
3262 | OnArrowChar( index, event ); | |
51cc4dad RR |
3263 | } |
3264 | break; | |
cf1dfa6b | 3265 | |
51cc4dad | 3266 | case WXK_RIGHT: |
cf1dfa6b | 3267 | if ( !HasFlag(wxLC_REPORT) ) |
51cc4dad | 3268 | { |
cf1dfa6b VZ |
3269 | size_t index = m_current + m_linesPerPage; |
3270 | ||
3271 | size_t count = GetItemCount(); | |
3272 | if ( index >= count ) | |
3273 | index = count - 1; | |
3274 | ||
3275 | OnArrowChar( index, event ); | |
51cc4dad RR |
3276 | } |
3277 | break; | |
cf1dfa6b | 3278 | |
51cc4dad | 3279 | case WXK_SPACE: |
b54e41c5 | 3280 | if ( IsSingleSel() ) |
33d0e17c | 3281 | { |
87948f22 | 3282 | SendNotify( m_current, wxEVT_COMMAND_LIST_ITEM_ACTIVATED ); |
70541533 VZ |
3283 | |
3284 | if ( IsHighlighted(m_current) ) | |
3285 | { | |
3286 | // don't unselect the item in single selection mode | |
3287 | break; | |
3288 | } | |
3289 | //else: select it in ReverseHighlight() below if unselected | |
33d0e17c | 3290 | } |
70541533 VZ |
3291 | |
3292 | ReverseHighlight(m_current); | |
51cc4dad | 3293 | break; |
cf1dfa6b | 3294 | |
51cc4dad RR |
3295 | case WXK_RETURN: |
3296 | case WXK_EXECUTE: | |
87948f22 | 3297 | SendNotify( m_current, wxEVT_COMMAND_LIST_ITEM_ACTIVATED ); |
51cc4dad | 3298 | break; |
cf1dfa6b | 3299 | |
51cc4dad | 3300 | default: |
51cc4dad | 3301 | event.Skip(); |
e1e955e1 | 3302 | } |
e1e955e1 | 3303 | } |
c801d85f | 3304 | |
cf1dfa6b VZ |
3305 | // ---------------------------------------------------------------------------- |
3306 | // focus handling | |
3307 | // ---------------------------------------------------------------------------- | |
3308 | ||
a6d57d03 VS |
3309 | void wxListMainWindow::SetFocus() |
3310 | { | |
3311 | // VS: wxListMainWindow derives from wxPanel (via wxScrolledWindow) and wxPanel | |
a77ec46d | 3312 | // overrides SetFocus in such way that it does never change focus from |
a6d57d03 | 3313 | // panel's child to the panel itself. Unfortunately, we must be able to change |
a77ec46d | 3314 | // focus to the panel from wxListTextCtrl because the text control should |
a6d57d03 VS |
3315 | // disappear when the user clicks outside it. |
3316 | ||
3317 | wxWindow *oldFocus = FindFocus(); | |
a77ec46d | 3318 | |
072da98f | 3319 | if ( oldFocus && oldFocus->GetParent() == this ) |
a6d57d03 VS |
3320 | { |
3321 | wxWindow::SetFocus(); | |
3322 | } | |
3323 | else | |
3324 | { | |
3325 | wxScrolledWindow::SetFocus(); | |
3326 | } | |
3327 | } | |
3328 | ||
c801d85f KB |
3329 | void wxListMainWindow::OnSetFocus( wxFocusEvent &WXUNUSED(event) ) |
3330 | { | |
dc76287d RD |
3331 | if ( GetParent() ) |
3332 | { | |
3333 | wxFocusEvent event( wxEVT_SET_FOCUS, GetParent()->GetId() ); | |
3334 | event.SetEventObject( GetParent() ); | |
3335 | if ( GetParent()->GetEventHandler()->ProcessEvent( event) ) | |
3336 | return; | |
3337 | } | |
3338 | ||
bde9072f VZ |
3339 | // wxGTK sends us EVT_SET_FOCUS events even if we had never got |
3340 | // EVT_KILL_FOCUS before which means that we finish by redrawing the items | |
3341 | // which are already drawn correctly resulting in horrible flicker - avoid | |
3342 | // it | |
47724389 VZ |
3343 | if ( !m_hasFocus ) |
3344 | { | |
3345 | m_hasFocus = TRUE; | |
bde9072f | 3346 | |
47724389 VZ |
3347 | RefreshSelected(); |
3348 | } | |
e1e955e1 | 3349 | } |
c801d85f KB |
3350 | |
3351 | void wxListMainWindow::OnKillFocus( wxFocusEvent &WXUNUSED(event) ) | |
3352 | { | |
dc76287d RD |
3353 | if ( GetParent() ) |
3354 | { | |
3355 | wxFocusEvent event( wxEVT_KILL_FOCUS, GetParent()->GetId() ); | |
3356 | event.SetEventObject( GetParent() ); | |
3357 | if ( GetParent()->GetEventHandler()->ProcessEvent( event) ) | |
3358 | return; | |
3359 | } | |
63852e78 | 3360 | m_hasFocus = FALSE; |
49ecb029 | 3361 | RefreshSelected(); |
e1e955e1 | 3362 | } |
c801d85f | 3363 | |
1e6d9499 | 3364 | void wxListMainWindow::DrawImage( int index, wxDC *dc, int x, int y ) |
c801d85f | 3365 | { |
cf1dfa6b | 3366 | if ( HasFlag(wxLC_ICON) && (m_normal_image_list)) |
63852e78 RR |
3367 | { |
3368 | m_normal_image_list->Draw( index, *dc, x, y, wxIMAGELIST_DRAW_TRANSPARENT ); | |
63852e78 | 3369 | } |
cf1dfa6b | 3370 | else if ( HasFlag(wxLC_SMALL_ICON) && (m_small_image_list)) |
63852e78 RR |
3371 | { |
3372 | m_small_image_list->Draw( index, *dc, x, y, wxIMAGELIST_DRAW_TRANSPARENT ); | |
3373 | } | |
cf1dfa6b | 3374 | else if ( HasFlag(wxLC_LIST) && (m_small_image_list)) |
0b855868 RR |
3375 | { |
3376 | m_small_image_list->Draw( index, *dc, x, y, wxIMAGELIST_DRAW_TRANSPARENT ); | |
3377 | } | |
cf1dfa6b | 3378 | else if ( HasFlag(wxLC_REPORT) && (m_small_image_list)) |
63852e78 RR |
3379 | { |
3380 | m_small_image_list->Draw( index, *dc, x, y, wxIMAGELIST_DRAW_TRANSPARENT ); | |
63852e78 | 3381 | } |
e1e955e1 | 3382 | } |
c801d85f | 3383 | |
5cd89174 | 3384 | void wxListMainWindow::GetImageSize( int index, int &width, int &height ) const |
c801d85f | 3385 | { |
cf1dfa6b | 3386 | if ( HasFlag(wxLC_ICON) && m_normal_image_list ) |
63852e78 RR |
3387 | { |
3388 | m_normal_image_list->GetSize( index, width, height ); | |
63852e78 | 3389 | } |
cf1dfa6b | 3390 | else if ( HasFlag(wxLC_SMALL_ICON) && m_small_image_list ) |
63852e78 RR |
3391 | { |
3392 | m_small_image_list->GetSize( index, width, height ); | |
63852e78 | 3393 | } |
cf1dfa6b | 3394 | else if ( HasFlag(wxLC_LIST) && m_small_image_list ) |
0b855868 RR |
3395 | { |
3396 | m_small_image_list->GetSize( index, width, height ); | |
0b855868 | 3397 | } |
cf1dfa6b | 3398 | else if ( HasFlag(wxLC_REPORT) && m_small_image_list ) |
63852e78 RR |
3399 | { |
3400 | m_small_image_list->GetSize( index, width, height ); | |
63852e78 | 3401 | } |
cf1dfa6b VZ |
3402 | else |
3403 | { | |
3404 | width = | |
3405 | height = 0; | |
3406 | } | |
e1e955e1 | 3407 | } |
c801d85f | 3408 | |
5cd89174 | 3409 | int wxListMainWindow::GetTextLength( const wxString &s ) const |
c801d85f | 3410 | { |
5cd89174 | 3411 | wxClientDC dc( wxConstCast(this, wxListMainWindow) ); |
cf1dfa6b | 3412 | dc.SetFont( GetFont() ); |
c801d85f | 3413 | |
cf1dfa6b VZ |
3414 | wxCoord lw; |
3415 | dc.GetTextExtent( s, &lw, NULL ); | |
3416 | ||
3417 | return lw + AUTOSIZE_COL_MARGIN; | |
e1e955e1 | 3418 | } |
c801d85f | 3419 | |
80020b62 | 3420 | void wxListMainWindow::SetImageList( wxImageListType *imageList, int which ) |
c801d85f | 3421 | { |
139adb6a | 3422 | m_dirty = TRUE; |
f6bcfd97 BP |
3423 | |
3424 | // calc the spacing from the icon size | |
3425 | int width = 0, | |
3426 | height = 0; | |
3427 | if ((imageList) && (imageList->GetImageCount()) ) | |
3428 | { | |
3429 | imageList->GetSize(0, width, height); | |
3430 | } | |
3431 | ||
3432 | if (which == wxIMAGE_LIST_NORMAL) | |
3433 | { | |
3434 | m_normal_image_list = imageList; | |
3435 | m_normal_spacing = width + 8; | |
3436 | } | |
3437 | ||
3438 | if (which == wxIMAGE_LIST_SMALL) | |
3439 | { | |
3440 | m_small_image_list = imageList; | |
3441 | m_small_spacing = width + 14; | |
ca7353de | 3442 | m_lineHeight = 0; // ensure that the line height will be recalc'd |
f6bcfd97 | 3443 | } |
e1e955e1 | 3444 | } |
c801d85f | 3445 | |
debe6624 | 3446 | void wxListMainWindow::SetItemSpacing( int spacing, bool isSmall ) |
c801d85f | 3447 | { |
139adb6a RR |
3448 | m_dirty = TRUE; |
3449 | if (isSmall) | |
3450 | { | |
3451 | m_small_spacing = spacing; | |
3452 | } | |
3453 | else | |
3454 | { | |
3455 | m_normal_spacing = spacing; | |
3456 | } | |
e1e955e1 | 3457 | } |
c801d85f | 3458 | |
debe6624 | 3459 | int wxListMainWindow::GetItemSpacing( bool isSmall ) |
c801d85f | 3460 | { |
f6bcfd97 | 3461 | return isSmall ? m_small_spacing : m_normal_spacing; |
e1e955e1 | 3462 | } |
c801d85f | 3463 | |
cf1dfa6b VZ |
3464 | // ---------------------------------------------------------------------------- |
3465 | // columns | |
3466 | // ---------------------------------------------------------------------------- | |
3467 | ||
debe6624 | 3468 | void wxListMainWindow::SetColumn( int col, wxListItem &item ) |
c801d85f | 3469 | { |
222ed1d6 | 3470 | wxListHeaderDataList::compatibility_iterator node = m_columns.Item( col ); |
f6bcfd97 | 3471 | |
cf1dfa6b VZ |
3472 | wxCHECK_RET( node, _T("invalid column index in SetColumn") ); |
3473 | ||
3474 | if ( item.m_width == wxLIST_AUTOSIZE_USEHEADER ) | |
3475 | item.m_width = GetTextLength( item.m_text ); | |
3476 | ||
3477 | wxListHeaderData *column = node->GetData(); | |
3478 | column->SetItem( item ); | |
3479 | ||
3480 | wxListHeaderWindow *headerWin = GetListCtrl()->m_headerWin; | |
f6bcfd97 BP |
3481 | if ( headerWin ) |
3482 | headerWin->m_dirty = TRUE; | |
cf1dfa6b VZ |
3483 | |
3484 | m_dirty = TRUE; | |
3485 | ||
3486 | // invalidate it as it has to be recalculated | |
3487 | m_headerWidth = 0; | |
e1e955e1 | 3488 | } |
c801d85f | 3489 | |
debe6624 | 3490 | void wxListMainWindow::SetColumnWidth( int col, int width ) |
c801d85f | 3491 | { |
cf1dfa6b VZ |
3492 | wxCHECK_RET( col >= 0 && col < GetColumnCount(), |
3493 | _T("invalid column index") ); | |
3494 | ||
3495 | wxCHECK_RET( HasFlag(wxLC_REPORT), | |
f6bcfd97 | 3496 | _T("SetColumnWidth() can only be called in report mode.") ); |
0208334d | 3497 | |
63852e78 | 3498 | m_dirty = TRUE; |
abe4a4f1 VS |
3499 | wxListHeaderWindow *headerWin = GetListCtrl()->m_headerWin; |
3500 | if ( headerWin ) | |
3501 | headerWin->m_dirty = TRUE; | |
bd8289c1 | 3502 | |
222ed1d6 | 3503 | wxListHeaderDataList::compatibility_iterator node = m_columns.Item( col ); |
cf1dfa6b VZ |
3504 | wxCHECK_RET( node, _T("no column?") ); |
3505 | ||
3506 | wxListHeaderData *column = node->GetData(); | |
3507 | ||
3508 | size_t count = GetItemCount(); | |
3509 | ||
f6bcfd97 BP |
3510 | if (width == wxLIST_AUTOSIZE_USEHEADER) |
3511 | { | |
cf1dfa6b | 3512 | width = GetTextLength(column->GetText()); |
f6bcfd97 | 3513 | } |
cf1dfa6b | 3514 | else if ( width == wxLIST_AUTOSIZE ) |
0180dad6 | 3515 | { |
cf1dfa6b VZ |
3516 | if ( IsVirtual() ) |
3517 | { | |
3518 | // TODO: determine the max width somehow... | |
3519 | width = WIDTH_COL_DEFAULT; | |
3520 | } | |
3521 | else // !virtual | |
0180dad6 | 3522 | { |
cf1dfa6b VZ |
3523 | wxClientDC dc(this); |
3524 | dc.SetFont( GetFont() ); | |
3525 | ||
3526 | int max = AUTOSIZE_COL_MARGIN; | |
3527 | ||
3528 | for ( size_t i = 0; i < count; i++ ) | |
0180dad6 | 3529 | { |
cf1dfa6b | 3530 | wxListLineData *line = GetLine(i); |
222ed1d6 | 3531 | wxListItemDataList::compatibility_iterator n = line->m_items.Item( col ); |
cf1dfa6b VZ |
3532 | |
3533 | wxCHECK_RET( n, _T("no subitem?") ); | |
3534 | ||
2c1f73ee | 3535 | wxListItemData *item = n->GetData(); |
cf1dfa6b VZ |
3536 | int current = 0; |
3537 | ||
bffa1c77 VZ |
3538 | if (item->HasImage()) |
3539 | { | |
cf1dfa6b | 3540 | int ix, iy; |
0180dad6 | 3541 | GetImageSize( item->GetImage(), ix, iy ); |
cf1dfa6b | 3542 | current += ix + 5; |
bffa1c77 | 3543 | } |
cf1dfa6b | 3544 | |
bffa1c77 VZ |
3545 | if (item->HasText()) |
3546 | { | |
cf1dfa6b VZ |
3547 | wxCoord w; |
3548 | dc.GetTextExtent( item->GetText(), &w, NULL ); | |
3549 | current += w; | |
bffa1c77 | 3550 | } |
cf1dfa6b | 3551 | |
2c1f73ee VZ |
3552 | if (current > max) |
3553 | max = current; | |
0180dad6 | 3554 | } |
cf1dfa6b VZ |
3555 | |
3556 | width = max + AUTOSIZE_COL_MARGIN; | |
0180dad6 | 3557 | } |
0180dad6 RR |
3558 | } |
3559 | ||
cf1dfa6b | 3560 | column->SetWidth( width ); |
bd8289c1 | 3561 | |
cf1dfa6b VZ |
3562 | // invalidate it as it has to be recalculated |
3563 | m_headerWidth = 0; | |
3564 | } | |
3565 | ||
3566 | int wxListMainWindow::GetHeaderWidth() const | |
3567 | { | |
3568 | if ( !m_headerWidth ) | |
0208334d | 3569 | { |
cf1dfa6b VZ |
3570 | wxListMainWindow *self = wxConstCast(this, wxListMainWindow); |
3571 | ||
3572 | size_t count = GetColumnCount(); | |
3573 | for ( size_t col = 0; col < count; col++ ) | |
63852e78 | 3574 | { |
cf1dfa6b | 3575 | self->m_headerWidth += GetColumnWidth(col); |
63852e78 | 3576 | } |
0208334d | 3577 | } |
bd8289c1 | 3578 | |
cf1dfa6b | 3579 | return m_headerWidth; |
e1e955e1 | 3580 | } |
c801d85f | 3581 | |
cf1dfa6b | 3582 | void wxListMainWindow::GetColumn( int col, wxListItem &item ) const |
c801d85f | 3583 | { |
222ed1d6 | 3584 | wxListHeaderDataList::compatibility_iterator node = m_columns.Item( col ); |
cf1dfa6b VZ |
3585 | wxCHECK_RET( node, _T("invalid column index in GetColumn") ); |
3586 | ||
3587 | wxListHeaderData *column = node->GetData(); | |
3588 | column->GetItem( item ); | |
e1e955e1 | 3589 | } |
c801d85f | 3590 | |
cf1dfa6b | 3591 | int wxListMainWindow::GetColumnWidth( int col ) const |
c801d85f | 3592 | { |
222ed1d6 | 3593 | wxListHeaderDataList::compatibility_iterator node = m_columns.Item( col ); |
24b9f055 VZ |
3594 | wxCHECK_MSG( node, 0, _T("invalid column index") ); |
3595 | ||
3596 | wxListHeaderData *column = node->GetData(); | |
3597 | return column->GetWidth(); | |
e1e955e1 | 3598 | } |
c801d85f | 3599 | |
cf1dfa6b VZ |
3600 | // ---------------------------------------------------------------------------- |
3601 | // item state | |
3602 | // ---------------------------------------------------------------------------- | |
c801d85f KB |
3603 | |
3604 | void wxListMainWindow::SetItem( wxListItem &item ) | |
3605 | { | |
cf1dfa6b VZ |
3606 | long id = item.m_itemId; |
3607 | wxCHECK_RET( id >= 0 && (size_t)id < GetItemCount(), | |
3608 | _T("invalid item index in SetItem") ); | |
3609 | ||
6c02c329 VZ |
3610 | if ( !IsVirtual() ) |
3611 | { | |
3612 | wxListLineData *line = GetLine((size_t)id); | |
3613 | line->SetItem( item.m_col, item ); | |
3614 | } | |
3615 | ||
285013b3 VZ |
3616 | // update the item on screen |
3617 | wxRect rectItem; | |
3618 | GetItemRect(id, rectItem); | |
3619 | RefreshRect(rectItem); | |
e1e955e1 | 3620 | } |
c801d85f | 3621 | |
cf1dfa6b | 3622 | void wxListMainWindow::SetItemState( long litem, long state, long stateMask ) |
c801d85f | 3623 | { |
cf1dfa6b | 3624 | wxCHECK_RET( litem >= 0 && (size_t)litem < GetItemCount(), |
54442116 VZ |
3625 | _T("invalid list ctrl item index in SetItem") ); |
3626 | ||
cf1dfa6b | 3627 | size_t oldCurrent = m_current; |
88b792af | 3628 | size_t item = (size_t)litem; // safe because of the check above |
bd8289c1 | 3629 | |
88b792af | 3630 | // do we need to change the focus? |
54442116 | 3631 | if ( stateMask & wxLIST_STATE_FOCUSED ) |
c801d85f | 3632 | { |
54442116 | 3633 | if ( state & wxLIST_STATE_FOCUSED ) |
92976ab6 | 3634 | { |
54442116 | 3635 | // don't do anything if this item is already focused |
cf1dfa6b | 3636 | if ( item != m_current ) |
92976ab6 | 3637 | { |
0ddefeb0 | 3638 | ChangeCurrent(item); |
cf1dfa6b | 3639 | |
88b792af | 3640 | if ( oldCurrent != (size_t)-1 ) |
cf1dfa6b | 3641 | { |
88b792af VZ |
3642 | if ( IsSingleSel() ) |
3643 | { | |
3644 | HighlightLine(oldCurrent, FALSE); | |
3645 | } | |
3646 | ||
cf1dfa6b VZ |
3647 | RefreshLine(oldCurrent); |
3648 | } | |
54442116 | 3649 | |
92976ab6 | 3650 | RefreshLine( m_current ); |
92976ab6 | 3651 | } |
54442116 VZ |
3652 | } |
3653 | else // unfocus | |
3654 | { | |
3655 | // don't do anything if this item is not focused | |
cf1dfa6b | 3656 | if ( item == m_current ) |
bffa1c77 | 3657 | { |
0ddefeb0 | 3658 | ResetCurrent(); |
88b792af | 3659 | |
943f6ad3 VZ |
3660 | if ( IsSingleSel() ) |
3661 | { | |
3662 | // we must unselect the old current item as well or we | |
3663 | // might end up with more than one selected item in a | |
3664 | // single selection control | |
3665 | HighlightLine(oldCurrent, FALSE); | |
3666 | } | |
3667 | ||
88b792af | 3668 | RefreshLine( oldCurrent ); |
bffa1c77 | 3669 | } |
92976ab6 | 3670 | } |
e1e955e1 | 3671 | } |
54442116 | 3672 | |
88b792af | 3673 | // do we need to change the selection state? |
54442116 VZ |
3674 | if ( stateMask & wxLIST_STATE_SELECTED ) |
3675 | { | |
3676 | bool on = (state & wxLIST_STATE_SELECTED) != 0; | |
54442116 | 3677 | |
b54e41c5 | 3678 | if ( IsSingleSel() ) |
54442116 | 3679 | { |
cf1dfa6b VZ |
3680 | if ( on ) |
3681 | { | |
3682 | // selecting the item also makes it the focused one in the | |
3683 | // single sel mode | |
3684 | if ( m_current != item ) | |
3685 | { | |
0ddefeb0 | 3686 | ChangeCurrent(item); |
cf1dfa6b VZ |
3687 | |
3688 | if ( oldCurrent != (size_t)-1 ) | |
3689 | { | |
b54e41c5 | 3690 | HighlightLine( oldCurrent, FALSE ); |
cf1dfa6b VZ |
3691 | RefreshLine( oldCurrent ); |
3692 | } | |
3693 | } | |
3694 | } | |
3695 | else // off | |
3696 | { | |
3697 | // only the current item may be selected anyhow | |
3698 | if ( item != m_current ) | |
3699 | return; | |
3700 | } | |
54442116 VZ |
3701 | } |
3702 | ||
b54e41c5 | 3703 | if ( HighlightLine(item, on) ) |
54442116 | 3704 | { |
cf1dfa6b | 3705 | RefreshLine(item); |
54442116 VZ |
3706 | } |
3707 | } | |
e1e955e1 | 3708 | } |
c801d85f | 3709 | |
62d89eb4 | 3710 | int wxListMainWindow::GetItemState( long item, long stateMask ) const |
c801d85f | 3711 | { |
cf1dfa6b VZ |
3712 | wxCHECK_MSG( item >= 0 && (size_t)item < GetItemCount(), 0, |
3713 | _T("invalid list ctrl item index in GetItemState()") ); | |
3714 | ||
92976ab6 | 3715 | int ret = wxLIST_STATE_DONTCARE; |
cf1dfa6b VZ |
3716 | |
3717 | if ( stateMask & wxLIST_STATE_FOCUSED ) | |
c801d85f | 3718 | { |
cf1dfa6b VZ |
3719 | if ( (size_t)item == m_current ) |
3720 | ret |= wxLIST_STATE_FOCUSED; | |
e1e955e1 | 3721 | } |
cf1dfa6b VZ |
3722 | |
3723 | if ( stateMask & wxLIST_STATE_SELECTED ) | |
c801d85f | 3724 | { |
b54e41c5 | 3725 | if ( IsHighlighted(item) ) |
cf1dfa6b | 3726 | ret |= wxLIST_STATE_SELECTED; |
e1e955e1 | 3727 | } |
cf1dfa6b | 3728 | |
92976ab6 | 3729 | return ret; |
e1e955e1 | 3730 | } |
c801d85f | 3731 | |
62d89eb4 | 3732 | void wxListMainWindow::GetItem( wxListItem &item ) const |
c801d85f | 3733 | { |
cf1dfa6b VZ |
3734 | wxCHECK_RET( item.m_itemId >= 0 && (size_t)item.m_itemId < GetItemCount(), |
3735 | _T("invalid item index in GetItem") ); | |
3736 | ||
3737 | wxListLineData *line = GetLine((size_t)item.m_itemId); | |
3738 | line->GetItem( item.m_col, item ); | |
e1e955e1 | 3739 | } |
c801d85f | 3740 | |
cf1dfa6b VZ |
3741 | // ---------------------------------------------------------------------------- |
3742 | // item count | |
3743 | // ---------------------------------------------------------------------------- | |
3744 | ||
3745 | size_t wxListMainWindow::GetItemCount() const | |
1370703e VZ |
3746 | { |
3747 | return IsVirtual() ? m_countVirt : m_lines.GetCount(); | |
3748 | } | |
3749 | ||
3750 | void wxListMainWindow::SetItemCount(long count) | |
c801d85f | 3751 | { |
b54e41c5 | 3752 | m_selStore.SetItemCount(count); |
1370703e VZ |
3753 | m_countVirt = count; |
3754 | ||
850ed6e7 VZ |
3755 | ResetVisibleLinesRange(); |
3756 | ||
5fe143df VZ |
3757 | // scrollbars must be reset |
3758 | m_dirty = TRUE; | |
e1e955e1 | 3759 | } |
c801d85f | 3760 | |
62d89eb4 | 3761 | int wxListMainWindow::GetSelectedItemCount() const |
c801d85f | 3762 | { |
cf1dfa6b | 3763 | // deal with the quick case first |
b54e41c5 | 3764 | if ( IsSingleSel() ) |
92976ab6 | 3765 | { |
b54e41c5 | 3766 | return HasCurrent() ? IsHighlighted(m_current) : FALSE; |
92976ab6 | 3767 | } |
cf1dfa6b VZ |
3768 | |
3769 | // virtual controls remmebers all its selections itself | |
3770 | if ( IsVirtual() ) | |
b54e41c5 | 3771 | return m_selStore.GetSelectedCount(); |
cf1dfa6b VZ |
3772 | |
3773 | // TODO: we probably should maintain the number of items selected even for | |
3774 | // non virtual controls as enumerating all lines is really slow... | |
3775 | size_t countSel = 0; | |
3776 | size_t count = GetItemCount(); | |
3777 | for ( size_t line = 0; line < count; line++ ) | |
92976ab6 | 3778 | { |
b54e41c5 | 3779 | if ( GetLine(line)->IsHighlighted() ) |
cf1dfa6b | 3780 | countSel++; |
92976ab6 | 3781 | } |
c801d85f | 3782 | |
cf1dfa6b | 3783 | return countSel; |
e1e955e1 | 3784 | } |
e3e65dac | 3785 | |
cf1dfa6b VZ |
3786 | // ---------------------------------------------------------------------------- |
3787 | // item position/size | |
3788 | // ---------------------------------------------------------------------------- | |
3789 | ||
11ebea16 VZ |
3790 | wxRect wxListMainWindow::GetViewRect() const |
3791 | { | |
3792 | wxASSERT_MSG( !HasFlag(wxLC_REPORT | wxLC_LIST), | |
3793 | _T("wxListCtrl::GetViewRect() only works in icon mode") ); | |
3794 | ||
3795 | // we need to find the longest/tallest label | |
3796 | wxCoord xMax = 0, | |
3797 | yMax = 0; | |
3798 | const int count = GetItemCount(); | |
3799 | if ( count ) | |
3800 | { | |
3801 | for ( int i = 0; i < count; i++ ) | |
3802 | { | |
3803 | wxRect r; | |
3804 | GetItemRect(i, r); | |
3805 | ||
3806 | wxCoord x = r.GetRight(), | |
3807 | y = r.GetBottom(); | |
3808 | ||
3809 | if ( x > xMax ) | |
3810 | xMax = x; | |
3811 | if ( y > yMax ) | |
3812 | yMax = y; | |
3813 | } | |
3814 | } | |
3815 | ||
eb6c4508 | 3816 | // some fudge needed to make it look prettier |
13602ebd VZ |
3817 | xMax += 2*EXTRA_BORDER_X; |
3818 | yMax += 2*EXTRA_BORDER_Y; | |
eb6c4508 VZ |
3819 | |
3820 | // account for the scrollbars if necessary | |
3821 | const wxSize sizeAll = GetClientSize(); | |
3822 | if ( xMax > sizeAll.x ) | |
3823 | yMax += wxSystemSettings::GetMetric(wxSYS_HSCROLL_Y); | |
3824 | if ( yMax > sizeAll.y ) | |
3825 | xMax += wxSystemSettings::GetMetric(wxSYS_VSCROLL_X); | |
11ebea16 VZ |
3826 | |
3827 | return wxRect(0, 0, xMax, yMax); | |
3828 | } | |
3829 | ||
62d89eb4 | 3830 | void wxListMainWindow::GetItemRect( long index, wxRect &rect ) const |
c801d85f | 3831 | { |
cf1dfa6b VZ |
3832 | wxCHECK_RET( index >= 0 && (size_t)index < GetItemCount(), |
3833 | _T("invalid index in GetItemRect") ); | |
3834 | ||
1e54be64 VZ |
3835 | // ensure that we're laid out, otherwise we could return nonsense |
3836 | if ( m_dirty ) | |
3837 | { | |
3838 | wxConstCast(this, wxListMainWindow)-> | |
3839 | RecalculatePositions(TRUE /* no refresh */); | |
3840 | } | |
3841 | ||
5cd89174 | 3842 | rect = GetLineRect((size_t)index); |
b54e41c5 | 3843 | |
cf1dfa6b | 3844 | CalcScrolledPosition(rect.x, rect.y, &rect.x, &rect.y); |
e1e955e1 | 3845 | } |
c801d85f | 3846 | |
62d89eb4 | 3847 | bool wxListMainWindow::GetItemPosition(long item, wxPoint& pos) const |
c801d85f | 3848 | { |
cf1dfa6b VZ |
3849 | wxRect rect; |
3850 | GetItemRect(item, rect); | |
bd8289c1 | 3851 | |
cf1dfa6b VZ |
3852 | pos.x = rect.x; |
3853 | pos.y = rect.y; | |
bd8289c1 | 3854 | |
cf1dfa6b | 3855 | return TRUE; |
e1e955e1 | 3856 | } |
c801d85f | 3857 | |
cf1dfa6b VZ |
3858 | // ---------------------------------------------------------------------------- |
3859 | // geometry calculation | |
3860 | // ---------------------------------------------------------------------------- | |
3861 | ||
34bbbc27 | 3862 | void wxListMainWindow::RecalculatePositions(bool noRefresh) |
c801d85f | 3863 | { |
1e6d9499 | 3864 | wxClientDC dc( this ); |
92976ab6 | 3865 | dc.SetFont( GetFont() ); |
c801d85f | 3866 | |
13602ebd VZ |
3867 | const size_t count = GetItemCount(); |
3868 | ||
cf1dfa6b VZ |
3869 | int iconSpacing; |
3870 | if ( HasFlag(wxLC_ICON) ) | |
3871 | iconSpacing = m_normal_spacing; | |
3872 | else if ( HasFlag(wxLC_SMALL_ICON) ) | |
3873 | iconSpacing = m_small_spacing; | |
3874 | else | |
3875 | iconSpacing = 0; | |
004fd0c8 | 3876 | |
bf632edd RR |
3877 | // Note that we do not call GetClientSize() here but |
3878 | // GetSize() and substract the border size for sunken | |
3879 | // borders manually. This is technically incorrect, | |
3880 | // but we need to know the client area's size WITHOUT | |
3881 | // scrollbars here. Since we don't know if there are | |
3882 | // any scrollbars, we use GetSize() instead. Another | |
3883 | // solution would be to call SetScrollbars() here to | |
3884 | // remove the scrollbars and call GetClientSize() then, | |
3885 | // but this might result in flicker and - worse - will | |
3886 | // reset the scrollbars to 0 which is not good at all | |
3887 | // if you resize a dialog/window, but don't want to | |
3888 | // reset the window scrolling. RR. | |
3889 | // Furthermore, we actually do NOT subtract the border | |
3890 | // width as 2 pixels is just the extra space which we | |
3891 | // need around the actual content in the window. Other- | |
3892 | // wise the text would e.g. touch the upper border. RR. | |
cf1dfa6b VZ |
3893 | int clientWidth, |
3894 | clientHeight; | |
bf632edd | 3895 | GetSize( &clientWidth, &clientHeight ); |
a77ec46d | 3896 | |
cf1dfa6b VZ |
3897 | if ( HasFlag(wxLC_REPORT) ) |
3898 | { | |
13602ebd | 3899 | // all lines have the same height and we scroll one line per step |
b54e41c5 | 3900 | int lineHeight = GetLineHeight(); |
c801d85f | 3901 | |
13602ebd | 3902 | int entireHeight = count*lineHeight + LINE_SPACING; |
bd8289c1 | 3903 | |
b54e41c5 VZ |
3904 | m_linesPerPage = clientHeight / lineHeight; |
3905 | ||
3906 | ResetVisibleLinesRange(); | |
2c1f73ee | 3907 | |
13602ebd VZ |
3908 | SetScrollbars( SCROLL_UNIT_X, lineHeight, |
3909 | GetHeaderWidth() / SCROLL_UNIT_X, | |
3910 | (entireHeight + lineHeight - 1) / lineHeight, | |
cf1dfa6b VZ |
3911 | GetScrollPos(wxHORIZONTAL), |
3912 | GetScrollPos(wxVERTICAL), | |
3913 | TRUE ); | |
e1e955e1 | 3914 | } |
cf1dfa6b | 3915 | else // !report |
92976ab6 | 3916 | { |
13602ebd VZ |
3917 | // we have 3 different layout strategies: either layout all items |
3918 | // horizontally/vertically (wxLC_ALIGN_XXX styles explicitly given) or | |
3919 | // to arrange them in top to bottom, left to right (don't ask me why | |
3920 | // not the other way round...) order | |
3921 | if ( HasFlag(wxLC_ALIGN_LEFT | wxLC_ALIGN_TOP) ) | |
e487524e | 3922 | { |
13602ebd VZ |
3923 | int x = EXTRA_BORDER_X; |
3924 | int y = EXTRA_BORDER_Y; | |
cf1dfa6b | 3925 | |
94dd23ae VZ |
3926 | wxCoord widthMax = 0; |
3927 | ||
3928 | size_t i; | |
3929 | for ( i = 0; i < count; i++ ) | |
92976ab6 | 3930 | { |
cf1dfa6b | 3931 | wxListLineData *line = GetLine(i); |
92976ab6 | 3932 | line->CalculateSize( &dc, iconSpacing ); |
13602ebd | 3933 | line->SetPosition( x, y, iconSpacing ); |
cf1dfa6b | 3934 | |
5cd89174 | 3935 | wxSize sizeLine = GetLineSize(i); |
cf1dfa6b | 3936 | |
13602ebd VZ |
3937 | if ( HasFlag(wxLC_ALIGN_TOP) ) |
3938 | { | |
94dd23ae VZ |
3939 | if ( sizeLine.x > widthMax ) |
3940 | widthMax = sizeLine.x; | |
3941 | ||
13602ebd VZ |
3942 | y += sizeLine.y; |
3943 | } | |
3944 | else // wxLC_ALIGN_LEFT | |
3945 | { | |
3946 | x += sizeLine.x + MARGIN_BETWEEN_ROWS; | |
3947 | } | |
3948 | } | |
3949 | ||
94dd23ae VZ |
3950 | if ( HasFlag(wxLC_ALIGN_TOP) ) |
3951 | { | |
3952 | // traverse the items again and tweak their sizes so that they are | |
3953 | // all the same in a row | |
3954 | for ( i = 0; i < count; i++ ) | |
3955 | { | |
3956 | wxListLineData *line = GetLine(i); | |
3957 | line->m_gi->ExtendWidth(widthMax); | |
3958 | } | |
3959 | } | |
3960 | ||
3961 | ||
13602ebd VZ |
3962 | SetScrollbars |
3963 | ( | |
3964 | SCROLL_UNIT_X, | |
3965 | SCROLL_UNIT_Y, | |
3966 | (x + SCROLL_UNIT_X) / SCROLL_UNIT_X, | |
3967 | (y + SCROLL_UNIT_Y) / SCROLL_UNIT_Y, | |
3968 | GetScrollPos( wxHORIZONTAL ), | |
3969 | GetScrollPos( wxVERTICAL ), | |
3970 | TRUE | |
3971 | ); | |
3972 | } | |
3973 | else // "flowed" arrangement, the most complicated case | |
3974 | { | |
3975 | // at first we try without any scrollbars, if the items don't fit into | |
3976 | // the window, we recalculate after subtracting the space taken by the | |
3977 | // scrollbar | |
3978 | ||
8a39593e JS |
3979 | int entireWidth = 0; |
3980 | #if 0 | |
3981 | // entireHeight is not used so no need to define it | |
3982 | int entireHeight = 0; | |
3983 | #endif | |
cf1dfa6b | 3984 | |
13602ebd VZ |
3985 | for (int tries = 0; tries < 2; tries++) |
3986 | { | |
3987 | entireWidth = 2*EXTRA_BORDER_X; | |
8a39593e JS |
3988 | #if 0 |
3989 | // entireHeight is not used so no need to define it | |
13602ebd | 3990 | entireHeight = 2*EXTRA_BORDER_Y; |
8a39593e | 3991 | #endif |
cf1dfa6b | 3992 | |
13602ebd | 3993 | if (tries == 1) |
92976ab6 | 3994 | { |
13602ebd VZ |
3995 | // Now we have decided that the items do not fit into the |
3996 | // client area, so we need a scrollbar | |
3997 | entireWidth += SCROLL_UNIT_X; | |
92976ab6 | 3998 | } |
a77ec46d | 3999 | |
13602ebd VZ |
4000 | int x = EXTRA_BORDER_X; |
4001 | int y = EXTRA_BORDER_Y; | |
4002 | int maxWidthInThisRow = 0; | |
4003 | ||
4004 | m_linesPerPage = 0; | |
4005 | int currentlyVisibleLines = 0; | |
a77ec46d | 4006 | |
13602ebd | 4007 | for (size_t i = 0; i < count; i++) |
92976ab6 | 4008 | { |
13602ebd VZ |
4009 | currentlyVisibleLines++; |
4010 | wxListLineData *line = GetLine(i); | |
4011 | line->CalculateSize( &dc, iconSpacing ); | |
4012 | line->SetPosition( x, y, iconSpacing ); | |
4013 | ||
4014 | wxSize sizeLine = GetLineSize(i); | |
a77ec46d | 4015 | |
13602ebd VZ |
4016 | if ( maxWidthInThisRow < sizeLine.x ) |
4017 | maxWidthInThisRow = sizeLine.x; | |
4018 | ||
4019 | y += sizeLine.y; | |
4020 | if (currentlyVisibleLines > m_linesPerPage) | |
4021 | m_linesPerPage = currentlyVisibleLines; | |
4022 | ||
4023 | if ( y + sizeLine.y >= clientHeight ) | |
4024 | { | |
4025 | currentlyVisibleLines = 0; | |
4026 | y = EXTRA_BORDER_Y; | |
4027 | maxWidthInThisRow += MARGIN_BETWEEN_ROWS; | |
4028 | x += maxWidthInThisRow; | |
4029 | entireWidth += maxWidthInThisRow; | |
4030 | maxWidthInThisRow = 0; | |
4031 | } | |
4032 | ||
4033 | // We have reached the last item. | |
4034 | if ( i == count - 1 ) | |
4035 | entireWidth += maxWidthInThisRow; | |
4036 | ||
4037 | if ( (tries == 0) && | |
4038 | (entireWidth + SCROLL_UNIT_X > clientWidth) ) | |
4039 | { | |
4040 | clientHeight -= wxSystemSettings:: | |
4041 | GetMetric(wxSYS_HSCROLL_Y); | |
4042 | m_linesPerPage = 0; | |
4043 | currentlyVisibleLines = 0; | |
4044 | break; | |
4045 | } | |
4046 | ||
4047 | if ( i == count - 1 ) | |
4048 | tries = 1; // Everything fits, no second try required. | |
4049 | } | |
92976ab6 | 4050 | } |
bffa1c77 | 4051 | |
13602ebd VZ |
4052 | SetScrollbars |
4053 | ( | |
4054 | SCROLL_UNIT_X, | |
4055 | SCROLL_UNIT_Y, | |
4056 | (entireWidth + SCROLL_UNIT_X) / SCROLL_UNIT_X, | |
4057 | 0, | |
4058 | GetScrollPos( wxHORIZONTAL ), | |
4059 | 0, | |
4060 | TRUE | |
4061 | ); | |
4062 | } | |
e1e955e1 | 4063 | } |
cf1dfa6b | 4064 | |
34bbbc27 VZ |
4065 | if ( !noRefresh ) |
4066 | { | |
4067 | // FIXME: why should we call it from here? | |
4068 | UpdateCurrent(); | |
b54e41c5 | 4069 | |
34bbbc27 VZ |
4070 | RefreshAll(); |
4071 | } | |
b54e41c5 VZ |
4072 | } |
4073 | ||
4074 | void wxListMainWindow::RefreshAll() | |
4075 | { | |
4076 | m_dirty = FALSE; | |
4077 | Refresh(); | |
4078 | ||
4079 | wxListHeaderWindow *headerWin = GetListCtrl()->m_headerWin; | |
70541533 | 4080 | if ( headerWin && headerWin->m_dirty ) |
b54e41c5 VZ |
4081 | { |
4082 | headerWin->m_dirty = FALSE; | |
4083 | headerWin->Refresh(); | |
4084 | } | |
e1e955e1 | 4085 | } |
c801d85f | 4086 | |
cf1dfa6b | 4087 | void wxListMainWindow::UpdateCurrent() |
c801d85f | 4088 | { |
b54e41c5 | 4089 | if ( !HasCurrent() && !IsEmpty() ) |
92976ab6 | 4090 | { |
0ddefeb0 | 4091 | ChangeCurrent(0); |
92976ab6 | 4092 | } |
e1e955e1 | 4093 | } |
c801d85f | 4094 | |
19695fbd VZ |
4095 | long wxListMainWindow::GetNextItem( long item, |
4096 | int WXUNUSED(geometry), | |
62d89eb4 | 4097 | int state ) const |
c801d85f | 4098 | { |
d1022fd6 VZ |
4099 | long ret = item, |
4100 | max = GetItemCount(); | |
4101 | wxCHECK_MSG( (ret == -1) || (ret < max), -1, | |
13771c08 | 4102 | _T("invalid listctrl index in GetNextItem()") ); |
19695fbd VZ |
4103 | |
4104 | // notice that we start with the next item (or the first one if item == -1) | |
4105 | // and this is intentional to allow writing a simple loop to iterate over | |
4106 | // all selected items | |
d1022fd6 VZ |
4107 | ret++; |
4108 | if ( ret == max ) | |
4109 | { | |
4110 | // this is not an error because the index was ok initially, just no | |
4111 | // such item | |
4112 | return -1; | |
4113 | } | |
4114 | ||
cf1dfa6b VZ |
4115 | if ( !state ) |
4116 | { | |
4117 | // any will do | |
4118 | return (size_t)ret; | |
4119 | } | |
4120 | ||
4121 | size_t count = GetItemCount(); | |
4122 | for ( size_t line = (size_t)ret; line < count; line++ ) | |
63852e78 | 4123 | { |
cf1dfa6b VZ |
4124 | if ( (state & wxLIST_STATE_FOCUSED) && (line == m_current) ) |
4125 | return line; | |
4126 | ||
b54e41c5 | 4127 | if ( (state & wxLIST_STATE_SELECTED) && IsHighlighted(line) ) |
cf1dfa6b | 4128 | return line; |
63852e78 | 4129 | } |
19695fbd | 4130 | |
63852e78 | 4131 | return -1; |
e1e955e1 | 4132 | } |
c801d85f | 4133 | |
cf1dfa6b VZ |
4134 | // ---------------------------------------------------------------------------- |
4135 | // deleting stuff | |
4136 | // ---------------------------------------------------------------------------- | |
4137 | ||
b54e41c5 | 4138 | void wxListMainWindow::DeleteItem( long lindex ) |
c801d85f | 4139 | { |
cf1dfa6b VZ |
4140 | size_t count = GetItemCount(); |
4141 | ||
b54e41c5 | 4142 | wxCHECK_RET( (lindex >= 0) && ((size_t)lindex < count), |
cf1dfa6b VZ |
4143 | _T("invalid item index in DeleteItem") ); |
4144 | ||
b54e41c5 VZ |
4145 | size_t index = (size_t)lindex; |
4146 | ||
d6ddcd57 VZ |
4147 | // we don't need to adjust the index for the previous items |
4148 | if ( HasCurrent() && m_current >= index ) | |
cf1dfa6b | 4149 | { |
d6ddcd57 VZ |
4150 | // if the current item is being deleted, we want the next one to |
4151 | // become selected - unless there is no next one - so don't adjust | |
4152 | // m_current in this case | |
4153 | if ( m_current != index || m_current == count - 1 ) | |
4154 | { | |
4155 | m_current--; | |
4156 | } | |
cf1dfa6b VZ |
4157 | } |
4158 | ||
938b652b | 4159 | if ( InReportView() ) |
63852e78 | 4160 | { |
6b4a8d93 | 4161 | ResetVisibleLinesRange(); |
938b652b VZ |
4162 | } |
4163 | ||
938b652b VZ |
4164 | if ( IsVirtual() ) |
4165 | { | |
4166 | m_countVirt--; | |
b54e41c5 VZ |
4167 | |
4168 | m_selStore.OnItemDelete(index); | |
4169 | } | |
4170 | else | |
4171 | { | |
4172 | m_lines.RemoveAt( index ); | |
63852e78 | 4173 | } |
6b4a8d93 | 4174 | |
70541533 | 4175 | // we need to refresh the (vert) scrollbar as the number of items changed |
b84839ae | 4176 | m_dirty = TRUE; |
91c6cc0e VZ |
4177 | |
4178 | SendNotify( index, wxEVT_COMMAND_LIST_DELETE_ITEM ); | |
4179 | ||
6b4a8d93 | 4180 | RefreshAfter(index); |
e1e955e1 | 4181 | } |
c801d85f | 4182 | |
debe6624 | 4183 | void wxListMainWindow::DeleteColumn( int col ) |
c801d85f | 4184 | { |
222ed1d6 | 4185 | wxListHeaderDataList::compatibility_iterator node = m_columns.Item( col ); |
24b9f055 VZ |
4186 | |
4187 | wxCHECK_RET( node, wxT("invalid column index in DeleteColumn()") ); | |
bd8289c1 | 4188 | |
5b077d48 | 4189 | m_dirty = TRUE; |
222ed1d6 MB |
4190 | delete node->GetData(); |
4191 | m_columns.Erase( node ); | |
ae409cb8 | 4192 | |
df6f82f0 VZ |
4193 | if ( !IsVirtual() ) |
4194 | { | |
4195 | // update all the items | |
4196 | for ( size_t i = 0; i < m_lines.GetCount(); i++ ) | |
4197 | { | |
4198 | wxListLineData * const line = GetLine(i); | |
222ed1d6 MB |
4199 | wxListItemDataList::compatibility_iterator n = line->m_items.Item( col ); |
4200 | delete n->GetData(); | |
4201 | line->m_items.Erase(n); | |
df6f82f0 VZ |
4202 | } |
4203 | } | |
4204 | ||
ae409cb8 VZ |
4205 | // invalidate it as it has to be recalculated |
4206 | m_headerWidth = 0; | |
e1e955e1 | 4207 | } |
c801d85f | 4208 | |
5fe143df | 4209 | void wxListMainWindow::DoDeleteAllItems() |
c801d85f | 4210 | { |
cf1dfa6b VZ |
4211 | if ( IsEmpty() ) |
4212 | { | |
4213 | // nothing to do - in particular, don't send the event | |
4214 | return; | |
4215 | } | |
4216 | ||
b54e41c5 | 4217 | ResetCurrent(); |
7c0ea335 VZ |
4218 | |
4219 | // to make the deletion of all items faster, we don't send the | |
cf1dfa6b VZ |
4220 | // notifications for each item deletion in this case but only one event |
4221 | // for all of them: this is compatible with wxMSW and documented in | |
4222 | // DeleteAllItems() description | |
bffa1c77 | 4223 | |
12c1b46a RR |
4224 | wxListEvent event( wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS, GetParent()->GetId() ); |
4225 | event.SetEventObject( GetParent() ); | |
4226 | GetParent()->GetEventHandler()->ProcessEvent( event ); | |
7c0ea335 | 4227 | |
b54e41c5 VZ |
4228 | if ( IsVirtual() ) |
4229 | { | |
4230 | m_countVirt = 0; | |
4231 | ||
850ed6e7 | 4232 | m_selStore.Clear(); |
b54e41c5 VZ |
4233 | } |
4234 | ||
6b4a8d93 VZ |
4235 | if ( InReportView() ) |
4236 | { | |
4237 | ResetVisibleLinesRange(); | |
4238 | } | |
4239 | ||
5b077d48 | 4240 | m_lines.Clear(); |
5fe143df | 4241 | } |
cf1dfa6b | 4242 | |
5fe143df VZ |
4243 | void wxListMainWindow::DeleteAllItems() |
4244 | { | |
4245 | DoDeleteAllItems(); | |
4246 | ||
4247 | RecalculatePositions(); | |
e1e955e1 | 4248 | } |
c801d85f | 4249 | |
12c1b46a | 4250 | void wxListMainWindow::DeleteEverything() |
c801d85f | 4251 | { |
222ed1d6 | 4252 | WX_CLEAR_LIST(wxListHeaderDataList, m_columns); |
904ccf52 VZ |
4253 | |
4254 | DeleteAllItems(); | |
e1e955e1 | 4255 | } |
c801d85f | 4256 | |
cf1dfa6b VZ |
4257 | // ---------------------------------------------------------------------------- |
4258 | // scanning for an item | |
4259 | // ---------------------------------------------------------------------------- | |
4260 | ||
debe6624 | 4261 | void wxListMainWindow::EnsureVisible( long index ) |
c801d85f | 4262 | { |
cf1dfa6b VZ |
4263 | wxCHECK_RET( index >= 0 && (size_t)index < GetItemCount(), |
4264 | _T("invalid index in EnsureVisible") ); | |
4265 | ||
4266 | // We have to call this here because the label in question might just have | |
34bbbc27 VZ |
4267 | // been added and its position is not known yet |
4268 | if ( m_dirty ) | |
4269 | { | |
34bbbc27 VZ |
4270 | RecalculatePositions(TRUE /* no refresh */); |
4271 | } | |
4272 | ||
4273 | MoveToItem((size_t)index); | |
e1e955e1 | 4274 | } |
c801d85f | 4275 | |
debe6624 | 4276 | long wxListMainWindow::FindItem(long start, const wxString& str, bool WXUNUSED(partial) ) |
c801d85f | 4277 | { |
5b077d48 RR |
4278 | long pos = start; |
4279 | wxString tmp = str; | |
cf1dfa6b VZ |
4280 | if (pos < 0) |
4281 | pos = 0; | |
54442116 | 4282 | |
cf1dfa6b VZ |
4283 | size_t count = GetItemCount(); |
4284 | for ( size_t i = (size_t)pos; i < count; i++ ) | |
4285 | { | |
4286 | wxListLineData *line = GetLine(i); | |
4287 | if ( line->GetText(0) == tmp ) | |
4288 | return i; | |
5b077d48 | 4289 | } |
cf1dfa6b VZ |
4290 | |
4291 | return wxNOT_FOUND; | |
e1e955e1 | 4292 | } |
c801d85f | 4293 | |
debe6624 | 4294 | long wxListMainWindow::FindItem(long start, long data) |
c801d85f | 4295 | { |
5b077d48 | 4296 | long pos = start; |
cf1dfa6b VZ |
4297 | if (pos < 0) |
4298 | pos = 0; | |
4299 | ||
4300 | size_t count = GetItemCount(); | |
4301 | for (size_t i = (size_t)pos; i < count; i++) | |
5b077d48 | 4302 | { |
cf1dfa6b | 4303 | wxListLineData *line = GetLine(i); |
5b077d48 RR |
4304 | wxListItem item; |
4305 | line->GetItem( 0, item ); | |
cf1dfa6b VZ |
4306 | if (item.m_data == data) |
4307 | return i; | |
5b077d48 | 4308 | } |
cf1dfa6b VZ |
4309 | |
4310 | return wxNOT_FOUND; | |
e1e955e1 | 4311 | } |
c801d85f | 4312 | |
debe6624 | 4313 | long wxListMainWindow::HitTest( int x, int y, int &flags ) |
c801d85f | 4314 | { |
aaef15bf | 4315 | CalcUnscrolledPosition( x, y, &x, &y ); |
e8741cca | 4316 | |
fc4f1d5f VZ |
4317 | size_t count = GetItemCount(); |
4318 | ||
5cd89174 | 4319 | if ( HasFlag(wxLC_REPORT) ) |
c801d85f | 4320 | { |
5cd89174 | 4321 | size_t current = y / GetLineHeight(); |
fc4f1d5f VZ |
4322 | if ( current < count ) |
4323 | { | |
4324 | flags = HitTestLine(current, x, y); | |
4325 | if ( flags ) | |
4326 | return current; | |
4327 | } | |
5cd89174 VZ |
4328 | } |
4329 | else // !report | |
4330 | { | |
4331 | // TODO: optimize it too! this is less simple than for report view but | |
4332 | // enumerating all items is still not a way to do it!! | |
5cd89174 | 4333 | for ( size_t current = 0; current < count; current++ ) |
5b077d48 | 4334 | { |
5cd89174 VZ |
4335 | flags = HitTestLine(current, x, y); |
4336 | if ( flags ) | |
4337 | return current; | |
5b077d48 | 4338 | } |
e1e955e1 | 4339 | } |
cf1dfa6b VZ |
4340 | |
4341 | return wxNOT_FOUND; | |
e1e955e1 | 4342 | } |
c801d85f | 4343 | |
cf1dfa6b VZ |
4344 | // ---------------------------------------------------------------------------- |
4345 | // adding stuff | |
4346 | // ---------------------------------------------------------------------------- | |
4347 | ||
c801d85f KB |
4348 | void wxListMainWindow::InsertItem( wxListItem &item ) |
4349 | { | |
cf1dfa6b VZ |
4350 | wxASSERT_MSG( !IsVirtual(), _T("can't be used with virtual control") ); |
4351 | ||
4352 | size_t count = GetItemCount(); | |
4353 | wxCHECK_RET( item.m_itemId >= 0 && (size_t)item.m_itemId <= count, | |
4354 | _T("invalid item index") ); | |
4355 | ||
4356 | size_t id = item.m_itemId; | |
4357 | ||
5b077d48 | 4358 | m_dirty = TRUE; |
cf1dfa6b | 4359 | |
8a39593e JS |
4360 | #if 0 |
4361 | // this is unused variable | |
5b077d48 | 4362 | int mode = 0; |
8a39593e | 4363 | #endif |
cf1dfa6b | 4364 | if ( HasFlag(wxLC_REPORT) ) |
2b5f62a0 | 4365 | { |
8a39593e JS |
4366 | #if 0 |
4367 | // this is unused variable | |
1370703e | 4368 | mode = wxLC_REPORT; |
8a39593e | 4369 | #endif |
2b5f62a0 VZ |
4370 | ResetVisibleLinesRange(); |
4371 | } | |
cf1dfa6b | 4372 | else if ( HasFlag(wxLC_LIST) ) |
8a39593e JS |
4373 | #if 0 |
4374 | // this is unused variable | |
1370703e | 4375 | mode = wxLC_LIST; |
8a39593e JS |
4376 | #else |
4377 | {} | |
4378 | #endif | |
cf1dfa6b | 4379 | else if ( HasFlag(wxLC_ICON) ) |
8a39593e JS |
4380 | #if 0 |
4381 | // this is unused variable | |
1370703e | 4382 | mode = wxLC_ICON; |
8a39593e JS |
4383 | #else |
4384 | {} | |
4385 | #endif | |
cf1dfa6b | 4386 | else if ( HasFlag(wxLC_SMALL_ICON) ) |
8a39593e JS |
4387 | #if 0 |
4388 | // this is unused variable | |
1370703e | 4389 | mode = wxLC_ICON; // no typo |
8a39593e JS |
4390 | #else |
4391 | {} | |
4392 | #endif | |
1370703e VZ |
4393 | else |
4394 | { | |
4395 | wxFAIL_MSG( _T("unknown mode") ); | |
4396 | } | |
004fd0c8 | 4397 | |
5cd89174 | 4398 | wxListLineData *line = new wxListLineData(this); |
004fd0c8 | 4399 | |
5b077d48 | 4400 | line->SetItem( 0, item ); |
cf1dfa6b VZ |
4401 | |
4402 | m_lines.Insert( line, id ); | |
5cd89174 | 4403 | |
b84839ae | 4404 | m_dirty = TRUE; |
a67e6e54 | 4405 | |
ab96d680 VZ |
4406 | // If an item is selected at or below the point of insertion, we need to |
4407 | // increment the member variables because the current row's index has gone | |
4408 | // up by one | |
4409 | if ( HasCurrent() && m_current >= id ) | |
4410 | { | |
4411 | m_current++; | |
4412 | } | |
4413 | ||
a67e6e54 VZ |
4414 | SendNotify(id, wxEVT_COMMAND_LIST_INSERT_ITEM); |
4415 | ||
5cd89174 | 4416 | RefreshLines(id, GetItemCount() - 1); |
e1e955e1 | 4417 | } |
c801d85f | 4418 | |
debe6624 | 4419 | void wxListMainWindow::InsertColumn( long col, wxListItem &item ) |
c801d85f | 4420 | { |
5b077d48 | 4421 | m_dirty = TRUE; |
cf1dfa6b | 4422 | if ( HasFlag(wxLC_REPORT) ) |
3db7be80 | 4423 | { |
54442116 VZ |
4424 | if (item.m_width == wxLIST_AUTOSIZE_USEHEADER) |
4425 | item.m_width = GetTextLength( item.m_text ); | |
df6f82f0 | 4426 | |
5b077d48 | 4427 | wxListHeaderData *column = new wxListHeaderData( item ); |
df6f82f0 VZ |
4428 | bool insert = (col >= 0) && ((size_t)col < m_columns.GetCount()); |
4429 | if ( insert ) | |
5b077d48 | 4430 | { |
222ed1d6 | 4431 | wxListHeaderDataList::compatibility_iterator node = m_columns.Item( col ); |
24b9f055 | 4432 | m_columns.Insert( node, column ); |
5b077d48 RR |
4433 | } |
4434 | else | |
4435 | { | |
4436 | m_columns.Append( column ); | |
4437 | } | |
ae409cb8 | 4438 | |
df6f82f0 VZ |
4439 | if ( !IsVirtual() ) |
4440 | { | |
4441 | // update all the items | |
4442 | for ( size_t i = 0; i < m_lines.GetCount(); i++ ) | |
4443 | { | |
4444 | wxListLineData * const line = GetLine(i); | |
4445 | wxListItemData * const data = new wxListItemData(this); | |
4446 | if ( insert ) | |
4447 | line->m_items.Insert(col, data); | |
4448 | else | |
4449 | line->m_items.Append(data); | |
4450 | } | |
4451 | } | |
4452 | ||
ae409cb8 VZ |
4453 | // invalidate it as it has to be recalculated |
4454 | m_headerWidth = 0; | |
3db7be80 | 4455 | } |
e1e955e1 | 4456 | } |
c801d85f | 4457 | |
cf1dfa6b VZ |
4458 | // ---------------------------------------------------------------------------- |
4459 | // sorting | |
4460 | // ---------------------------------------------------------------------------- | |
4461 | ||
c801d85f KB |
4462 | wxListCtrlCompare list_ctrl_compare_func_2; |
4463 | long list_ctrl_compare_data; | |
4464 | ||
f6bcfd97 | 4465 | int LINKAGEMODE list_ctrl_compare_func_1( wxListLineData **arg1, wxListLineData **arg2 ) |
c801d85f | 4466 | { |
f6bcfd97 BP |
4467 | wxListLineData *line1 = *arg1; |
4468 | wxListLineData *line2 = *arg2; | |
5b077d48 RR |
4469 | wxListItem item; |
4470 | line1->GetItem( 0, item ); | |
4471 | long data1 = item.m_data; | |
4472 | line2->GetItem( 0, item ); | |
4473 | long data2 = item.m_data; | |
4474 | return list_ctrl_compare_func_2( data1, data2, list_ctrl_compare_data ); | |
e1e955e1 | 4475 | } |
c801d85f KB |
4476 | |
4477 | void wxListMainWindow::SortItems( wxListCtrlCompare fn, long data ) | |
4478 | { | |
5b077d48 RR |
4479 | list_ctrl_compare_func_2 = fn; |
4480 | list_ctrl_compare_data = data; | |
4481 | m_lines.Sort( list_ctrl_compare_func_1 ); | |
af7c1052 | 4482 | m_dirty = TRUE; |
e1e955e1 | 4483 | } |
c801d85f | 4484 | |
cf1dfa6b VZ |
4485 | // ---------------------------------------------------------------------------- |
4486 | // scrolling | |
4487 | // ---------------------------------------------------------------------------- | |
4488 | ||
7c74e7fe SC |
4489 | void wxListMainWindow::OnScroll(wxScrollWinEvent& event) |
4490 | { | |
b54e41c5 VZ |
4491 | // update our idea of which lines are shown when we redraw the window the |
4492 | // next time | |
4493 | ResetVisibleLinesRange(); | |
cf1dfa6b | 4494 | |
29149a64 | 4495 | // FIXME |
3a8c693a | 4496 | #if defined(__WXGTK__) && !defined(__WXUNIVERSAL__) |
29149a64 VZ |
4497 | wxScrolledWindow::OnScroll(event); |
4498 | #else | |
1e6feb95 | 4499 | HandleOnScroll( event ); |
29149a64 | 4500 | #endif |
30954328 | 4501 | |
cf1dfa6b | 4502 | if ( event.GetOrientation() == wxHORIZONTAL && HasHeader() ) |
7c74e7fe | 4503 | { |
3cd94a0d | 4504 | wxGenericListCtrl* lc = GetListCtrl(); |
cf1dfa6b VZ |
4505 | wxCHECK_RET( lc, _T("no listctrl window?") ); |
4506 | ||
afbe906a RR |
4507 | lc->m_headerWin->Refresh(); |
4508 | lc->m_headerWin->Update(); | |
7c74e7fe | 4509 | } |
cf1dfa6b VZ |
4510 | } |
4511 | ||
5cd89174 VZ |
4512 | int wxListMainWindow::GetCountPerPage() const |
4513 | { | |
4514 | if ( !m_linesPerPage ) | |
4515 | { | |
4516 | wxConstCast(this, wxListMainWindow)-> | |
4517 | m_linesPerPage = GetClientSize().y / GetLineHeight(); | |
4518 | } | |
4519 | ||
4520 | return m_linesPerPage; | |
4521 | } | |
4522 | ||
b54e41c5 | 4523 | void wxListMainWindow::GetVisibleLinesRange(size_t *from, size_t *to) |
cf1dfa6b | 4524 | { |
b54e41c5 | 4525 | wxASSERT_MSG( HasFlag(wxLC_REPORT), _T("this is for report mode only") ); |
cf1dfa6b | 4526 | |
b54e41c5 VZ |
4527 | if ( m_lineFrom == (size_t)-1 ) |
4528 | { | |
b54e41c5 | 4529 | size_t count = GetItemCount(); |
6522713c VZ |
4530 | if ( count ) |
4531 | { | |
4532 | m_lineFrom = GetScrollPos(wxVERTICAL); | |
cf1dfa6b | 4533 | |
152c57f2 VZ |
4534 | // this may happen if SetScrollbars() hadn't been called yet |
4535 | if ( m_lineFrom >= count ) | |
bcc0da5c | 4536 | m_lineFrom = count - 1; |
cf1dfa6b | 4537 | |
6522713c VZ |
4538 | // we redraw one extra line but this is needed to make the redrawing |
4539 | // logic work when there is a fractional number of lines on screen | |
4540 | m_lineTo = m_lineFrom + m_linesPerPage; | |
4541 | if ( m_lineTo >= count ) | |
4542 | m_lineTo = count - 1; | |
4543 | } | |
4544 | else // empty control | |
4545 | { | |
4546 | m_lineFrom = 0; | |
4547 | m_lineTo = (size_t)-1; | |
4548 | } | |
cf1dfa6b | 4549 | } |
b54e41c5 | 4550 | |
ae167d2f VZ |
4551 | wxASSERT_MSG( IsEmpty() || |
4552 | (m_lineFrom <= m_lineTo && m_lineTo < GetItemCount()), | |
6b4a8d93 VZ |
4553 | _T("GetVisibleLinesRange() returns incorrect result") ); |
4554 | ||
b54e41c5 VZ |
4555 | if ( from ) |
4556 | *from = m_lineFrom; | |
4557 | if ( to ) | |
4558 | *to = m_lineTo; | |
7c74e7fe SC |
4559 | } |
4560 | ||
c801d85f | 4561 | // ------------------------------------------------------------------------------------- |
3cd94a0d | 4562 | // wxGenericListCtrl |
c801d85f KB |
4563 | // ------------------------------------------------------------------------------------- |
4564 | ||
3cd94a0d JS |
4565 | IMPLEMENT_DYNAMIC_CLASS(wxGenericListCtrl, wxControl) |
4566 | ||
3cd94a0d JS |
4567 | BEGIN_EVENT_TABLE(wxGenericListCtrl,wxControl) |
4568 | EVT_SIZE(wxGenericListCtrl::OnSize) | |
c801d85f KB |
4569 | END_EVENT_TABLE() |
4570 | ||
3cd94a0d | 4571 | wxGenericListCtrl::wxGenericListCtrl() |
c801d85f | 4572 | { |
80020b62 JS |
4573 | m_imageListNormal = (wxImageListType *) NULL; |
4574 | m_imageListSmall = (wxImageListType *) NULL; | |
4575 | m_imageListState = (wxImageListType *) NULL; | |
cf1dfa6b VZ |
4576 | |
4577 | m_ownsImageListNormal = | |
4578 | m_ownsImageListSmall = | |
4579 | m_ownsImageListState = FALSE; | |
4580 | ||
5b077d48 RR |
4581 | m_mainWin = (wxListMainWindow*) NULL; |
4582 | m_headerWin = (wxListHeaderWindow*) NULL; | |
f8252483 | 4583 | m_headerHeight = 0; |
c801d85f KB |
4584 | } |
4585 | ||
3cd94a0d | 4586 | wxGenericListCtrl::~wxGenericListCtrl() |
c801d85f | 4587 | { |
cf1dfa6b VZ |
4588 | if (m_ownsImageListNormal) |
4589 | delete m_imageListNormal; | |
4590 | if (m_ownsImageListSmall) | |
4591 | delete m_imageListSmall; | |
4592 | if (m_ownsImageListState) | |
4593 | delete m_imageListState; | |
4594 | } | |
4595 | ||
f8252483 JS |
4596 | void wxGenericListCtrl::CalculateAndSetHeaderHeight() |
4597 | { | |
86351e4a VZ |
4598 | if ( m_headerWin ) |
4599 | { | |
4600 | // we use 'g' to get the descent, too | |
4601 | int w, h, d; | |
4602 | m_headerWin->GetTextExtent(wxT("Hg"), &w, &h, &d); | |
4603 | h += d + 2 * HEADER_OFFSET_Y + EXTRA_HEIGHT; | |
4604 | ||
8b1ed8d9 VZ |
4605 | // only update if changed |
4606 | if ( h != m_headerHeight ) | |
86351e4a VZ |
4607 | { |
4608 | m_headerHeight = h; | |
4609 | ||
4610 | m_headerWin->SetSize(m_headerWin->GetSize().x, m_headerHeight); | |
4611 | ||
4612 | if ( HasFlag(wxLC_REPORT) && !HasFlag(wxLC_NO_HEADER) ) | |
4613 | ResizeReportView(TRUE); | |
4614 | } | |
4615 | } | |
f8252483 JS |
4616 | } |
4617 | ||
3cd94a0d | 4618 | void wxGenericListCtrl::CreateHeaderWindow() |
cf1dfa6b VZ |
4619 | { |
4620 | m_headerWin = new wxListHeaderWindow | |
4621 | ( | |
4622 | this, -1, m_mainWin, | |
4623 | wxPoint(0, 0), | |
f8252483 | 4624 | wxSize(GetClientSize().x, m_headerHeight), |
cf1dfa6b VZ |
4625 | wxTAB_TRAVERSAL |
4626 | ); | |
f8252483 | 4627 | CalculateAndSetHeaderHeight(); |
c801d85f KB |
4628 | } |
4629 | ||
3cd94a0d | 4630 | bool wxGenericListCtrl::Create(wxWindow *parent, |
25e3a937 VZ |
4631 | wxWindowID id, |
4632 | const wxPoint &pos, | |
4633 | const wxSize &size, | |
4634 | long style, | |
25e3a937 | 4635 | const wxValidator &validator, |
25e3a937 | 4636 | const wxString &name) |
c801d85f | 4637 | { |
cf1dfa6b VZ |
4638 | m_imageListNormal = |
4639 | m_imageListSmall = | |
80020b62 | 4640 | m_imageListState = (wxImageListType *) NULL; |
cf1dfa6b VZ |
4641 | m_ownsImageListNormal = |
4642 | m_ownsImageListSmall = | |
4643 | m_ownsImageListState = FALSE; | |
4644 | ||
5b077d48 RR |
4645 | m_mainWin = (wxListMainWindow*) NULL; |
4646 | m_headerWin = (wxListHeaderWindow*) NULL; | |
bd8289c1 | 4647 | |
b54e41c5 | 4648 | if ( !(style & wxLC_MASK_TYPE) ) |
5b077d48 | 4649 | { |
25e3a937 | 4650 | style = style | wxLC_LIST; |
5b077d48 | 4651 | } |
f6bcfd97 | 4652 | |
07215d86 | 4653 | if ( !wxControl::Create( parent, id, pos, size, style, validator, name ) ) |
cf1dfa6b | 4654 | return FALSE; |
f6bcfd97 | 4655 | |
b54e41c5 | 4656 | // don't create the inner window with the border |
6d460f76 | 4657 | style &= ~wxBORDER_MASK; |
bd8289c1 | 4658 | |
25e3a937 | 4659 | m_mainWin = new wxListMainWindow( this, -1, wxPoint(0,0), size, style ); |
bd8289c1 | 4660 | |
b54e41c5 | 4661 | if ( HasFlag(wxLC_REPORT) ) |
ea451729 | 4662 | { |
cf1dfa6b VZ |
4663 | CreateHeaderWindow(); |
4664 | ||
b54e41c5 | 4665 | if ( HasFlag(wxLC_NO_HEADER) ) |
cf1dfa6b VZ |
4666 | { |
4667 | // VZ: why do we create it at all then? | |
ea451729 | 4668 | m_headerWin->Show( FALSE ); |
cf1dfa6b | 4669 | } |
ea451729 | 4670 | } |
bd8289c1 | 4671 | |
cf1dfa6b | 4672 | return TRUE; |
e1e955e1 | 4673 | } |
c801d85f | 4674 | |
3cd94a0d | 4675 | void wxGenericListCtrl::SetSingleStyle( long style, bool add ) |
c801d85f | 4676 | { |
b54e41c5 VZ |
4677 | wxASSERT_MSG( !(style & wxLC_VIRTUAL), |
4678 | _T("wxLC_VIRTUAL can't be [un]set") ); | |
4679 | ||
f03fc89f | 4680 | long flag = GetWindowStyle(); |
bd8289c1 | 4681 | |
5b077d48 RR |
4682 | if (add) |
4683 | { | |
cf1dfa6b | 4684 | if (style & wxLC_MASK_TYPE) |
b54e41c5 | 4685 | flag &= ~(wxLC_MASK_TYPE | wxLC_VIRTUAL); |
cf1dfa6b VZ |
4686 | if (style & wxLC_MASK_ALIGN) |
4687 | flag &= ~wxLC_MASK_ALIGN; | |
4688 | if (style & wxLC_MASK_SORT) | |
4689 | flag &= ~wxLC_MASK_SORT; | |
5b077d48 | 4690 | } |
c801d85f | 4691 | |
5b077d48 RR |
4692 | if (add) |
4693 | { | |
4694 | flag |= style; | |
4695 | } | |
4696 | else | |
4697 | { | |
cf1dfa6b | 4698 | flag &= ~style; |
5b077d48 | 4699 | } |
bd8289c1 | 4700 | |
5b077d48 | 4701 | SetWindowStyleFlag( flag ); |
e1e955e1 | 4702 | } |
c801d85f | 4703 | |
3cd94a0d | 4704 | void wxGenericListCtrl::SetWindowStyleFlag( long flag ) |
c801d85f | 4705 | { |
121a3581 RR |
4706 | if (m_mainWin) |
4707 | { | |
4708 | m_mainWin->DeleteEverything(); | |
c801d85f | 4709 | |
a95cdab8 VZ |
4710 | // has the header visibility changed? |
4711 | bool hasHeader = HasFlag(wxLC_REPORT) && !HasFlag(wxLC_NO_HEADER), | |
4712 | willHaveHeader = (flag & wxLC_REPORT) && !(flag & wxLC_NO_HEADER); | |
c801d85f | 4713 | |
a95cdab8 | 4714 | if ( hasHeader != willHaveHeader ) |
5b077d48 | 4715 | { |
a95cdab8 VZ |
4716 | // toggle it |
4717 | if ( hasHeader ) | |
4718 | { | |
4719 | if ( m_headerWin ) | |
4720 | { | |
4721 | // don't delete, just hide, as we can reuse it later | |
4722 | m_headerWin->Show(FALSE); | |
4723 | } | |
4724 | //else: nothing to do | |
4725 | } | |
4726 | else // must show header | |
5b077d48 | 4727 | { |
121a3581 RR |
4728 | if (!m_headerWin) |
4729 | { | |
cf1dfa6b | 4730 | CreateHeaderWindow(); |
121a3581 | 4731 | } |
a95cdab8 | 4732 | else // already have it, just show |
004fd0c8 | 4733 | { |
a95cdab8 | 4734 | m_headerWin->Show( TRUE ); |
004fd0c8 | 4735 | } |
5b077d48 | 4736 | } |
a95cdab8 VZ |
4737 | |
4738 | ResizeReportView(willHaveHeader); | |
bffa1c77 | 4739 | } |
e1e955e1 | 4740 | } |
004fd0c8 | 4741 | |
5b077d48 | 4742 | wxWindow::SetWindowStyleFlag( flag ); |
e1e955e1 | 4743 | } |
c801d85f | 4744 | |
3cd94a0d | 4745 | bool wxGenericListCtrl::GetColumn(int col, wxListItem &item) const |
c801d85f | 4746 | { |
5b077d48 RR |
4747 | m_mainWin->GetColumn( col, item ); |
4748 | return TRUE; | |
e1e955e1 | 4749 | } |
c801d85f | 4750 | |
3cd94a0d | 4751 | bool wxGenericListCtrl::SetColumn( int col, wxListItem& item ) |
c801d85f | 4752 | { |
5b077d48 RR |
4753 | m_mainWin->SetColumn( col, item ); |
4754 | return TRUE; | |
e1e955e1 | 4755 | } |
c801d85f | 4756 | |
3cd94a0d | 4757 | int wxGenericListCtrl::GetColumnWidth( int col ) const |
c801d85f | 4758 | { |
5b077d48 | 4759 | return m_mainWin->GetColumnWidth( col ); |
e1e955e1 | 4760 | } |
c801d85f | 4761 | |
3cd94a0d | 4762 | bool wxGenericListCtrl::SetColumnWidth( int col, int width ) |
c801d85f | 4763 | { |
5b077d48 RR |
4764 | m_mainWin->SetColumnWidth( col, width ); |
4765 | return TRUE; | |
e1e955e1 | 4766 | } |
c801d85f | 4767 | |
3cd94a0d | 4768 | int wxGenericListCtrl::GetCountPerPage() const |
c801d85f KB |
4769 | { |
4770 | return m_mainWin->GetCountPerPage(); // different from Windows ? | |
e1e955e1 | 4771 | } |
c801d85f | 4772 | |
3cd94a0d | 4773 | bool wxGenericListCtrl::GetItem( wxListItem &info ) const |
c801d85f | 4774 | { |
5b077d48 RR |
4775 | m_mainWin->GetItem( info ); |
4776 | return TRUE; | |
e1e955e1 | 4777 | } |
c801d85f | 4778 | |
3cd94a0d | 4779 | bool wxGenericListCtrl::SetItem( wxListItem &info ) |
c801d85f | 4780 | { |
5b077d48 RR |
4781 | m_mainWin->SetItem( info ); |
4782 | return TRUE; | |
e1e955e1 | 4783 | } |
c801d85f | 4784 | |
3cd94a0d | 4785 | long wxGenericListCtrl::SetItem( long index, int col, const wxString& label, int imageId ) |
c801d85f | 4786 | { |
5b077d48 RR |
4787 | wxListItem info; |
4788 | info.m_text = label; | |
4789 | info.m_mask = wxLIST_MASK_TEXT; | |
4790 | info.m_itemId = index; | |
4791 | info.m_col = col; | |
4792 | if ( imageId > -1 ) | |
4793 | { | |
4794 | info.m_image = imageId; | |
4795 | info.m_mask |= wxLIST_MASK_IMAGE; | |
4796 | }; | |
4797 | m_mainWin->SetItem(info); | |
4798 | return TRUE; | |
e1e955e1 | 4799 | } |
c801d85f | 4800 | |
3cd94a0d | 4801 | int wxGenericListCtrl::GetItemState( long item, long stateMask ) const |
c801d85f | 4802 | { |
5b077d48 | 4803 | return m_mainWin->GetItemState( item, stateMask ); |
e1e955e1 | 4804 | } |
c801d85f | 4805 | |
3cd94a0d | 4806 | bool wxGenericListCtrl::SetItemState( long item, long state, long stateMask ) |
c801d85f | 4807 | { |
5b077d48 RR |
4808 | m_mainWin->SetItemState( item, state, stateMask ); |
4809 | return TRUE; | |
e1e955e1 | 4810 | } |
c801d85f | 4811 | |
3cd94a0d | 4812 | bool wxGenericListCtrl::SetItemImage( long item, int image, int WXUNUSED(selImage) ) |
c801d85f | 4813 | { |
5b077d48 RR |
4814 | wxListItem info; |
4815 | info.m_image = image; | |
4816 | info.m_mask = wxLIST_MASK_IMAGE; | |
4817 | info.m_itemId = item; | |
4818 | m_mainWin->SetItem( info ); | |
4819 | return TRUE; | |
e1e955e1 | 4820 | } |
c801d85f | 4821 | |
3cd94a0d | 4822 | wxString wxGenericListCtrl::GetItemText( long item ) const |
c801d85f | 4823 | { |
62d89eb4 | 4824 | return m_mainWin->GetItemText(item); |
e1e955e1 | 4825 | } |
c801d85f | 4826 | |
3cd94a0d | 4827 | void wxGenericListCtrl::SetItemText( long item, const wxString& str ) |
c801d85f | 4828 | { |
62d89eb4 | 4829 | m_mainWin->SetItemText(item, str); |
e1e955e1 | 4830 | } |
c801d85f | 4831 | |
3cd94a0d | 4832 | long wxGenericListCtrl::GetItemData( long item ) const |
c801d85f | 4833 | { |
5b077d48 RR |
4834 | wxListItem info; |
4835 | info.m_itemId = item; | |
4836 | m_mainWin->GetItem( info ); | |
4837 | return info.m_data; | |
e1e955e1 | 4838 | } |
c801d85f | 4839 | |
3cd94a0d | 4840 | bool wxGenericListCtrl::SetItemData( long item, long data ) |
c801d85f | 4841 | { |
5b077d48 RR |
4842 | wxListItem info; |
4843 | info.m_mask = wxLIST_MASK_DATA; | |
4844 | info.m_itemId = item; | |
4845 | info.m_data = data; | |
4846 | m_mainWin->SetItem( info ); | |
4847 | return TRUE; | |
e1e955e1 | 4848 | } |
c801d85f | 4849 | |
11ebea16 VZ |
4850 | wxRect wxGenericListCtrl::GetViewRect() const |
4851 | { | |
4852 | return m_mainWin->GetViewRect(); | |
4853 | } | |
4854 | ||
3cd94a0d | 4855 | bool wxGenericListCtrl::GetItemRect( long item, wxRect &rect, int WXUNUSED(code) ) const |
c801d85f | 4856 | { |
5b077d48 | 4857 | m_mainWin->GetItemRect( item, rect ); |
7e6874c0 | 4858 | if ( m_mainWin->HasHeader() ) |
f8252483 | 4859 | rect.y += m_headerHeight + 1; |
5b077d48 | 4860 | return TRUE; |
e1e955e1 | 4861 | } |
c801d85f | 4862 | |
3cd94a0d | 4863 | bool wxGenericListCtrl::GetItemPosition( long item, wxPoint& pos ) const |
c801d85f | 4864 | { |
5b077d48 RR |
4865 | m_mainWin->GetItemPosition( item, pos ); |
4866 | return TRUE; | |
e1e955e1 | 4867 | } |
c801d85f | 4868 | |
3cd94a0d | 4869 | bool wxGenericListCtrl::SetItemPosition( long WXUNUSED(item), const wxPoint& WXUNUSED(pos) ) |
c801d85f | 4870 | { |
5b077d48 | 4871 | return 0; |
e1e955e1 | 4872 | } |
c801d85f | 4873 | |
3cd94a0d | 4874 | int wxGenericListCtrl::GetItemCount() const |
c801d85f | 4875 | { |
5b077d48 | 4876 | return m_mainWin->GetItemCount(); |
e1e955e1 | 4877 | } |
c801d85f | 4878 | |
3cd94a0d | 4879 | int wxGenericListCtrl::GetColumnCount() const |
92976ab6 | 4880 | { |
5b077d48 | 4881 | return m_mainWin->GetColumnCount(); |
92976ab6 RR |
4882 | } |
4883 | ||
3cd94a0d | 4884 | void wxGenericListCtrl::SetItemSpacing( int spacing, bool isSmall ) |
33d0b396 | 4885 | { |
5b077d48 | 4886 | m_mainWin->SetItemSpacing( spacing, isSmall ); |
e1e955e1 | 4887 | } |
33d0b396 | 4888 | |
5db8d758 VZ |
4889 | wxSize wxGenericListCtrl::GetItemSpacing() const |
4890 | { | |
f58fc140 | 4891 | const int spacing = m_mainWin->GetItemSpacing(HasFlag(wxLC_SMALL_ICON)); |
5db8d758 VZ |
4892 | |
4893 | return wxSize(spacing, spacing); | |
4894 | } | |
4895 | ||
3cd94a0d | 4896 | int wxGenericListCtrl::GetItemSpacing( bool isSmall ) const |
c801d85f | 4897 | { |
5b077d48 | 4898 | return m_mainWin->GetItemSpacing( isSmall ); |
e1e955e1 | 4899 | } |
c801d85f | 4900 | |
3cd94a0d | 4901 | void wxGenericListCtrl::SetItemTextColour( long item, const wxColour &col ) |
5b98eb2f RL |
4902 | { |
4903 | wxListItem info; | |
4904 | info.m_itemId = item; | |
4905 | info.SetTextColour( col ); | |
4906 | m_mainWin->SetItem( info ); | |
4907 | } | |
4908 | ||
3cd94a0d | 4909 | wxColour wxGenericListCtrl::GetItemTextColour( long item ) const |
5b98eb2f RL |
4910 | { |
4911 | wxListItem info; | |
4912 | info.m_itemId = item; | |
4913 | m_mainWin->GetItem( info ); | |
4914 | return info.GetTextColour(); | |
4915 | } | |
4916 | ||
3cd94a0d | 4917 | void wxGenericListCtrl::SetItemBackgroundColour( long item, const wxColour &col ) |
5b98eb2f RL |
4918 | { |
4919 | wxListItem info; | |
4920 | info.m_itemId = item; | |
4921 | info.SetBackgroundColour( col ); | |
4922 | m_mainWin->SetItem( info ); | |
4923 | } | |
4924 | ||
3cd94a0d | 4925 | wxColour wxGenericListCtrl::GetItemBackgroundColour( long item ) const |
5b98eb2f RL |
4926 | { |
4927 | wxListItem info; | |
4928 | info.m_itemId = item; | |
4929 | m_mainWin->GetItem( info ); | |
4930 | return info.GetBackgroundColour(); | |
4931 | } | |
4932 | ||
3cd94a0d | 4933 | int wxGenericListCtrl::GetSelectedItemCount() const |
c801d85f | 4934 | { |
5b077d48 | 4935 | return m_mainWin->GetSelectedItemCount(); |
e1e955e1 | 4936 | } |
c801d85f | 4937 | |
3cd94a0d | 4938 | wxColour wxGenericListCtrl::GetTextColour() const |
c801d85f | 4939 | { |
0530737d | 4940 | return GetForegroundColour(); |
e1e955e1 | 4941 | } |
c801d85f | 4942 | |
3cd94a0d | 4943 | void wxGenericListCtrl::SetTextColour(const wxColour& col) |
c801d85f | 4944 | { |
0530737d | 4945 | SetForegroundColour(col); |
e1e955e1 | 4946 | } |
c801d85f | 4947 | |
3cd94a0d | 4948 | long wxGenericListCtrl::GetTopItem() const |
c801d85f | 4949 | { |
2b5f62a0 VZ |
4950 | size_t top; |
4951 | m_mainWin->GetVisibleLinesRange(&top, NULL); | |
4952 | return (long)top; | |
e1e955e1 | 4953 | } |
c801d85f | 4954 | |
3cd94a0d | 4955 | long wxGenericListCtrl::GetNextItem( long item, int geom, int state ) const |
c801d85f | 4956 | { |
5b077d48 | 4957 | return m_mainWin->GetNextItem( item, geom, state ); |
e1e955e1 | 4958 | } |
c801d85f | 4959 | |
80020b62 | 4960 | wxImageListType *wxGenericListCtrl::GetImageList(int which) const |
c801d85f | 4961 | { |
5b077d48 RR |
4962 | if (which == wxIMAGE_LIST_NORMAL) |
4963 | { | |
4964 | return m_imageListNormal; | |
4965 | } | |
4966 | else if (which == wxIMAGE_LIST_SMALL) | |
4967 | { | |
4968 | return m_imageListSmall; | |
4969 | } | |
4970 | else if (which == wxIMAGE_LIST_STATE) | |
4971 | { | |
4972 | return m_imageListState; | |
4973 | } | |
80020b62 | 4974 | return (wxImageListType *) NULL; |
e1e955e1 | 4975 | } |
c801d85f | 4976 | |
80020b62 | 4977 | void wxGenericListCtrl::SetImageList( wxImageListType *imageList, int which ) |
c801d85f | 4978 | { |
2e12c11a VS |
4979 | if ( which == wxIMAGE_LIST_NORMAL ) |
4980 | { | |
4981 | if (m_ownsImageListNormal) delete m_imageListNormal; | |
4982 | m_imageListNormal = imageList; | |
4983 | m_ownsImageListNormal = FALSE; | |
4984 | } | |
4985 | else if ( which == wxIMAGE_LIST_SMALL ) | |
4986 | { | |
4987 | if (m_ownsImageListSmall) delete m_imageListSmall; | |
4988 | m_imageListSmall = imageList; | |
4989 | m_ownsImageListSmall = FALSE; | |
4990 | } | |
4991 | else if ( which == wxIMAGE_LIST_STATE ) | |
4992 | { | |
4993 | if (m_ownsImageListState) delete m_imageListState; | |
4994 | m_imageListState = imageList; | |
4995 | m_ownsImageListState = FALSE; | |
4996 | } | |
4997 | ||
5b077d48 | 4998 | m_mainWin->SetImageList( imageList, which ); |
e1e955e1 | 4999 | } |
c801d85f | 5000 | |
80020b62 | 5001 | void wxGenericListCtrl::AssignImageList(wxImageListType *imageList, int which) |
2e12c11a VS |
5002 | { |
5003 | SetImageList(imageList, which); | |
5004 | if ( which == wxIMAGE_LIST_NORMAL ) | |
5005 | m_ownsImageListNormal = TRUE; | |
5006 | else if ( which == wxIMAGE_LIST_SMALL ) | |
5007 | m_ownsImageListSmall = TRUE; | |
5008 | else if ( which == wxIMAGE_LIST_STATE ) | |
5009 | m_ownsImageListState = TRUE; | |
5010 | } | |
5011 | ||
3cd94a0d | 5012 | bool wxGenericListCtrl::Arrange( int WXUNUSED(flag) ) |
c801d85f | 5013 | { |
5b077d48 | 5014 | return 0; |
e1e955e1 | 5015 | } |
c801d85f | 5016 | |
3cd94a0d | 5017 | bool wxGenericListCtrl::DeleteItem( long item ) |
c801d85f | 5018 | { |
5b077d48 RR |
5019 | m_mainWin->DeleteItem( item ); |
5020 | return TRUE; | |
e1e955e1 | 5021 | } |
c801d85f | 5022 | |
3cd94a0d | 5023 | bool wxGenericListCtrl::DeleteAllItems() |
c801d85f | 5024 | { |
5b077d48 RR |
5025 | m_mainWin->DeleteAllItems(); |
5026 | return TRUE; | |
e1e955e1 | 5027 | } |
c801d85f | 5028 | |
3cd94a0d | 5029 | bool wxGenericListCtrl::DeleteAllColumns() |
bd8289c1 | 5030 | { |
24b9f055 VZ |
5031 | size_t count = m_mainWin->m_columns.GetCount(); |
5032 | for ( size_t n = 0; n < count; n++ ) | |
85cdcb7a | 5033 | DeleteColumn(0); |
bffa1c77 | 5034 | |
5b077d48 | 5035 | return TRUE; |
4f22cf8d RR |
5036 | } |
5037 | ||
3cd94a0d | 5038 | void wxGenericListCtrl::ClearAll() |
4f22cf8d | 5039 | { |
5b077d48 | 5040 | m_mainWin->DeleteEverything(); |
bd8289c1 VZ |
5041 | } |
5042 | ||
3cd94a0d | 5043 | bool wxGenericListCtrl::DeleteColumn( int col ) |
c801d85f | 5044 | { |
5b077d48 | 5045 | m_mainWin->DeleteColumn( col ); |
40c08808 VZ |
5046 | |
5047 | // if we don't have the header any longer, we need to relayout the window | |
5048 | if ( !GetColumnCount() ) | |
5049 | { | |
5050 | ResizeReportView(FALSE /* no header */); | |
5051 | } | |
5052 | ||
5b077d48 | 5053 | return TRUE; |
e1e955e1 | 5054 | } |
c801d85f | 5055 | |
3cd94a0d | 5056 | void wxGenericListCtrl::Edit( long item ) |
c801d85f | 5057 | { |
cf1dfa6b | 5058 | m_mainWin->EditLabel( item ); |
e1e955e1 | 5059 | } |
c801d85f | 5060 | |
3cd94a0d | 5061 | bool wxGenericListCtrl::EnsureVisible( long item ) |
c801d85f | 5062 | { |
5b077d48 RR |
5063 | m_mainWin->EnsureVisible( item ); |
5064 | return TRUE; | |
e1e955e1 | 5065 | } |
c801d85f | 5066 | |
3cd94a0d | 5067 | long wxGenericListCtrl::FindItem( long start, const wxString& str, bool partial ) |
c801d85f | 5068 | { |
5b077d48 | 5069 | return m_mainWin->FindItem( start, str, partial ); |
e1e955e1 | 5070 | } |
c801d85f | 5071 | |
3cd94a0d | 5072 | long wxGenericListCtrl::FindItem( long start, long data ) |
c801d85f | 5073 | { |
5b077d48 | 5074 | return m_mainWin->FindItem( start, data ); |
e1e955e1 | 5075 | } |
c801d85f | 5076 | |
3cd94a0d | 5077 | long wxGenericListCtrl::FindItem( long WXUNUSED(start), const wxPoint& WXUNUSED(pt), |
debe6624 | 5078 | int WXUNUSED(direction)) |
c801d85f | 5079 | { |
5b077d48 | 5080 | return 0; |
e1e955e1 | 5081 | } |
c801d85f | 5082 | |
3cd94a0d | 5083 | long wxGenericListCtrl::HitTest( const wxPoint &point, int &flags ) |
c801d85f | 5084 | { |
5b077d48 | 5085 | return m_mainWin->HitTest( (int)point.x, (int)point.y, flags ); |
e1e955e1 | 5086 | } |
c801d85f | 5087 | |
3cd94a0d | 5088 | long wxGenericListCtrl::InsertItem( wxListItem& info ) |
c801d85f | 5089 | { |
5b077d48 | 5090 | m_mainWin->InsertItem( info ); |
2ebcd5f5 | 5091 | return info.m_itemId; |
e1e955e1 | 5092 | } |
c801d85f | 5093 | |
3cd94a0d | 5094 | long wxGenericListCtrl::InsertItem( long index, const wxString &label ) |
c801d85f | 5095 | { |
51cc4dad RR |
5096 | wxListItem info; |
5097 | info.m_text = label; | |
5098 | info.m_mask = wxLIST_MASK_TEXT; | |
5099 | info.m_itemId = index; | |
5100 | return InsertItem( info ); | |
e1e955e1 | 5101 | } |
c801d85f | 5102 | |
3cd94a0d | 5103 | long wxGenericListCtrl::InsertItem( long index, int imageIndex ) |
c801d85f | 5104 | { |
51cc4dad RR |
5105 | wxListItem info; |
5106 | info.m_mask = wxLIST_MASK_IMAGE; | |
5107 | info.m_image = imageIndex; | |
5108 | info.m_itemId = index; | |
5109 | return InsertItem( info ); | |
e1e955e1 | 5110 | } |
c801d85f | 5111 | |
3cd94a0d | 5112 | long wxGenericListCtrl::InsertItem( long index, const wxString &label, int imageIndex ) |
c801d85f | 5113 | { |
51cc4dad RR |
5114 | wxListItem info; |
5115 | info.m_text = label; | |
5116 | info.m_image = imageIndex; | |
5117 | info.m_mask = wxLIST_MASK_TEXT | wxLIST_MASK_IMAGE; | |
5118 | info.m_itemId = index; | |
5119 | return InsertItem( info ); | |
e1e955e1 | 5120 | } |
c801d85f | 5121 | |
3cd94a0d | 5122 | long wxGenericListCtrl::InsertColumn( long col, wxListItem &item ) |
c801d85f | 5123 | { |
40c08808 VZ |
5124 | wxCHECK_MSG( m_headerWin, -1, _T("can't add column in non report mode") ); |
5125 | ||
51cc4dad | 5126 | m_mainWin->InsertColumn( col, item ); |
40c08808 VZ |
5127 | |
5128 | // if we hadn't had header before and have it now we need to relayout the | |
5129 | // window | |
ac53090c | 5130 | if ( GetColumnCount() == 1 && m_mainWin->HasHeader() ) |
40c08808 VZ |
5131 | { |
5132 | ResizeReportView(TRUE /* have header */); | |
5133 | } | |
5134 | ||
d3e90957 | 5135 | m_headerWin->Refresh(); |
25e3a937 | 5136 | |
51cc4dad | 5137 | return 0; |
e1e955e1 | 5138 | } |
c801d85f | 5139 | |
3cd94a0d | 5140 | long wxGenericListCtrl::InsertColumn( long col, const wxString &heading, |
debe6624 | 5141 | int format, int width ) |
c801d85f | 5142 | { |
51cc4dad RR |
5143 | wxListItem item; |
5144 | item.m_mask = wxLIST_MASK_TEXT | wxLIST_MASK_FORMAT; | |
5145 | item.m_text = heading; | |
5146 | if (width >= -2) | |
5147 | { | |
5148 | item.m_mask |= wxLIST_MASK_WIDTH; | |
5149 | item.m_width = width; | |
5150 | } | |
5151 | item.m_format = format; | |
c801d85f | 5152 | |
51cc4dad | 5153 | return InsertColumn( col, item ); |
e1e955e1 | 5154 | } |
c801d85f | 5155 | |
3cd94a0d | 5156 | bool wxGenericListCtrl::ScrollList( int WXUNUSED(dx), int WXUNUSED(dy) ) |
c801d85f | 5157 | { |
51cc4dad | 5158 | return 0; |
e1e955e1 | 5159 | } |
c801d85f KB |
5160 | |
5161 | // Sort items. | |
5162 | // fn is a function which takes 3 long arguments: item1, item2, data. | |
5163 | // item1 is the long data associated with a first item (NOT the index). | |
5164 | // item2 is the long data associated with a second item (NOT the index). | |
5165 | // data is the same value as passed to SortItems. | |
5166 | // The return value is a negative number if the first item should precede the second | |
5167 | // item, a positive number of the second item should precede the first, | |
5168 | // or zero if the two items are equivalent. | |
5169 | // data is arbitrary data to be passed to the sort function. | |
5170 | ||
3cd94a0d | 5171 | bool wxGenericListCtrl::SortItems( wxListCtrlCompare fn, long data ) |
c801d85f | 5172 | { |
51cc4dad RR |
5173 | m_mainWin->SortItems( fn, data ); |
5174 | return TRUE; | |
e1e955e1 | 5175 | } |
c801d85f | 5176 | |
cf1dfa6b | 5177 | // ---------------------------------------------------------------------------- |
b54e41c5 | 5178 | // event handlers |
cf1dfa6b VZ |
5179 | // ---------------------------------------------------------------------------- |
5180 | ||
3cd94a0d | 5181 | void wxGenericListCtrl::OnSize(wxSizeEvent& WXUNUSED(event)) |
53010e52 | 5182 | { |
b54e41c5 | 5183 | if ( !m_mainWin ) |
cf1dfa6b | 5184 | return; |
53010e52 | 5185 | |
a95cdab8 VZ |
5186 | ResizeReportView(m_mainWin->HasHeader()); |
5187 | ||
5188 | m_mainWin->RecalculatePositions(); | |
5189 | } | |
5190 | ||
3cd94a0d | 5191 | void wxGenericListCtrl::ResizeReportView(bool showHeader) |
a95cdab8 | 5192 | { |
b54e41c5 | 5193 | int cw, ch; |
51cc4dad | 5194 | GetClientSize( &cw, &ch ); |
bd8289c1 | 5195 | |
a95cdab8 | 5196 | if ( showHeader ) |
51cc4dad | 5197 | { |
f8252483 JS |
5198 | m_headerWin->SetSize( 0, 0, cw, m_headerHeight ); |
5199 | m_mainWin->SetSize( 0, m_headerHeight + 1, cw, ch - m_headerHeight - 1 ); | |
51cc4dad | 5200 | } |
cf1dfa6b | 5201 | else // no header window |
51cc4dad | 5202 | { |
cf1dfa6b | 5203 | m_mainWin->SetSize( 0, 0, cw, ch ); |
51cc4dad | 5204 | } |
b54e41c5 | 5205 | } |
cf1dfa6b | 5206 | |
5180055b | 5207 | void wxGenericListCtrl::OnInternalIdle() |
b54e41c5 | 5208 | { |
5180055b | 5209 | wxWindow::OnInternalIdle(); |
86351e4a | 5210 | |
b54e41c5 VZ |
5211 | // do it only if needed |
5212 | if ( !m_mainWin->m_dirty ) | |
5213 | return; | |
5214 | ||
5215 | m_mainWin->RecalculatePositions(); | |
e1e955e1 | 5216 | } |
53010e52 | 5217 | |
cf1dfa6b VZ |
5218 | // ---------------------------------------------------------------------------- |
5219 | // font/colours | |
5220 | // ---------------------------------------------------------------------------- | |
5221 | ||
3cd94a0d | 5222 | bool wxGenericListCtrl::SetBackgroundColour( const wxColour &colour ) |
bd8289c1 | 5223 | { |
51cc4dad RR |
5224 | if (m_mainWin) |
5225 | { | |
5226 | m_mainWin->SetBackgroundColour( colour ); | |
5227 | m_mainWin->m_dirty = TRUE; | |
5228 | } | |
004fd0c8 | 5229 | |
f03fc89f | 5230 | return TRUE; |
e4d06860 RR |
5231 | } |
5232 | ||
3cd94a0d | 5233 | bool wxGenericListCtrl::SetForegroundColour( const wxColour &colour ) |
bd8289c1 | 5234 | { |
f03fc89f VZ |
5235 | if ( !wxWindow::SetForegroundColour( colour ) ) |
5236 | return FALSE; | |
004fd0c8 | 5237 | |
51cc4dad RR |
5238 | if (m_mainWin) |
5239 | { | |
5240 | m_mainWin->SetForegroundColour( colour ); | |
5241 | m_mainWin->m_dirty = TRUE; | |
5242 | } | |
004fd0c8 | 5243 | |
51cc4dad RR |
5244 | if (m_headerWin) |
5245 | { | |
5246 | m_headerWin->SetForegroundColour( colour ); | |
5247 | } | |
f03fc89f VZ |
5248 | |
5249 | return TRUE; | |
e4d06860 | 5250 | } |
bd8289c1 | 5251 | |
3cd94a0d | 5252 | bool wxGenericListCtrl::SetFont( const wxFont &font ) |
bd8289c1 | 5253 | { |
f03fc89f VZ |
5254 | if ( !wxWindow::SetFont( font ) ) |
5255 | return FALSE; | |
004fd0c8 | 5256 | |
51cc4dad RR |
5257 | if (m_mainWin) |
5258 | { | |
5259 | m_mainWin->SetFont( font ); | |
5260 | m_mainWin->m_dirty = TRUE; | |
5261 | } | |
004fd0c8 | 5262 | |
51cc4dad RR |
5263 | if (m_headerWin) |
5264 | { | |
5265 | m_headerWin->SetFont( font ); | |
f8252483 | 5266 | CalculateAndSetHeaderHeight(); |
51cc4dad | 5267 | } |
f03fc89f | 5268 | |
f8252483 JS |
5269 | Refresh(); |
5270 | ||
f03fc89f | 5271 | return TRUE; |
e4d06860 | 5272 | } |
c801d85f | 5273 | |
cf1dfa6b VZ |
5274 | // ---------------------------------------------------------------------------- |
5275 | // methods forwarded to m_mainWin | |
5276 | // ---------------------------------------------------------------------------- | |
5277 | ||
efbb7287 VZ |
5278 | #if wxUSE_DRAG_AND_DROP |
5279 | ||
3cd94a0d | 5280 | void wxGenericListCtrl::SetDropTarget( wxDropTarget *dropTarget ) |
efbb7287 VZ |
5281 | { |
5282 | m_mainWin->SetDropTarget( dropTarget ); | |
5283 | } | |
5284 | ||
3cd94a0d | 5285 | wxDropTarget *wxGenericListCtrl::GetDropTarget() const |
efbb7287 VZ |
5286 | { |
5287 | return m_mainWin->GetDropTarget(); | |
5288 | } | |
5289 | ||
5290 | #endif // wxUSE_DRAG_AND_DROP | |
5291 | ||
3cd94a0d | 5292 | bool wxGenericListCtrl::SetCursor( const wxCursor &cursor ) |
efbb7287 VZ |
5293 | { |
5294 | return m_mainWin ? m_mainWin->wxWindow::SetCursor(cursor) : FALSE; | |
5295 | } | |
5296 | ||
3cd94a0d | 5297 | wxColour wxGenericListCtrl::GetBackgroundColour() const |
efbb7287 VZ |
5298 | { |
5299 | return m_mainWin ? m_mainWin->GetBackgroundColour() : wxColour(); | |
5300 | } | |
5301 | ||
3cd94a0d | 5302 | wxColour wxGenericListCtrl::GetForegroundColour() const |
efbb7287 VZ |
5303 | { |
5304 | return m_mainWin ? m_mainWin->GetForegroundColour() : wxColour(); | |
5305 | } | |
5306 | ||
3cd94a0d | 5307 | bool wxGenericListCtrl::DoPopupMenu( wxMenu *menu, int x, int y ) |
efbb7287 | 5308 | { |
3a8c693a | 5309 | #if wxUSE_MENUS |
efbb7287 | 5310 | return m_mainWin->PopupMenu( menu, x, y ); |
3a8c693a VZ |
5311 | #else |
5312 | return FALSE; | |
5313 | #endif // wxUSE_MENUS | |
efbb7287 VZ |
5314 | } |
5315 | ||
3cd94a0d | 5316 | void wxGenericListCtrl::SetFocus() |
efbb7287 VZ |
5317 | { |
5318 | /* The test in window.cpp fails as we are a composite | |
5319 | window, so it checks against "this", but not m_mainWin. */ | |
5320 | if ( FindFocus() != this ) | |
5321 | m_mainWin->SetFocus(); | |
5322 | } | |
1e6feb95 | 5323 | |
2c1f73ee VZ |
5324 | // ---------------------------------------------------------------------------- |
5325 | // virtual list control support | |
5326 | // ---------------------------------------------------------------------------- | |
5327 | ||
3cd94a0d | 5328 | wxString wxGenericListCtrl::OnGetItemText(long WXUNUSED(item), long WXUNUSED(col)) const |
2c1f73ee VZ |
5329 | { |
5330 | // this is a pure virtual function, in fact - which is not really pure | |
5331 | // because the controls which are not virtual don't need to implement it | |
3cd94a0d | 5332 | wxFAIL_MSG( _T("wxGenericListCtrl::OnGetItemText not supposed to be called") ); |
2c1f73ee VZ |
5333 | |
5334 | return wxEmptyString; | |
5335 | } | |
5336 | ||
3cd94a0d | 5337 | int wxGenericListCtrl::OnGetItemImage(long WXUNUSED(item)) const |
2c1f73ee VZ |
5338 | { |
5339 | // same as above | |
3cd94a0d | 5340 | wxFAIL_MSG( _T("wxGenericListCtrl::OnGetItemImage not supposed to be called") ); |
2c1f73ee VZ |
5341 | |
5342 | return -1; | |
5343 | } | |
5344 | ||
3cd94a0d | 5345 | wxListItemAttr *wxGenericListCtrl::OnGetItemAttr(long item) const |
6c02c329 VZ |
5346 | { |
5347 | wxASSERT_MSG( item >= 0 && item < GetItemCount(), | |
5348 | _T("invalid item index in OnGetItemAttr()") ); | |
5349 | ||
5350 | // no attributes by default | |
5351 | return NULL; | |
5352 | } | |
5353 | ||
3cd94a0d | 5354 | void wxGenericListCtrl::SetItemCount(long count) |
2c1f73ee VZ |
5355 | { |
5356 | wxASSERT_MSG( IsVirtual(), _T("this is for virtual controls only") ); | |
5357 | ||
5358 | m_mainWin->SetItemCount(count); | |
5359 | } | |
5360 | ||
3cd94a0d | 5361 | void wxGenericListCtrl::RefreshItem(long item) |
1a6cb56f VZ |
5362 | { |
5363 | m_mainWin->RefreshLine(item); | |
5364 | } | |
5365 | ||
3cd94a0d | 5366 | void wxGenericListCtrl::RefreshItems(long itemFrom, long itemTo) |
1a6cb56f VZ |
5367 | { |
5368 | m_mainWin->RefreshLines(itemFrom, itemTo); | |
5369 | } | |
5370 | ||
2f1e3c46 VZ |
5371 | /* |
5372 | * Generic wxListCtrl is more or less a container for two other | |
5373 | * windows which drawings are done upon. These are namely | |
5374 | * 'm_headerWin' and 'm_mainWin'. | |
5375 | * Here we override 'virtual wxWindow::Refresh()' to mimic the | |
5376 | * behaviour wxListCtrl has under wxMSW. | |
5377 | */ | |
5378 | void wxGenericListCtrl::Refresh(bool eraseBackground, const wxRect *rect) | |
5379 | { | |
5380 | if (!rect) | |
5381 | { | |
5382 | // The easy case, no rectangle specified. | |
5383 | if (m_headerWin) | |
5384 | m_headerWin->Refresh(eraseBackground); | |
5385 | ||
5386 | if (m_mainWin) | |
5387 | m_mainWin->Refresh(eraseBackground); | |
5388 | } | |
5389 | else | |
5390 | { | |
5391 | // Refresh the header window | |
5392 | if (m_headerWin) | |
5393 | { | |
5394 | wxRect rectHeader = m_headerWin->GetRect(); | |
5395 | rectHeader.Intersect(*rect); | |
5396 | if (rectHeader.GetWidth() && rectHeader.GetHeight()) | |
5397 | { | |
5398 | int x, y; | |
5399 | m_headerWin->GetPosition(&x, &y); | |
5400 | rectHeader.Offset(-x, -y); | |
5401 | m_headerWin->Refresh(eraseBackground, &rectHeader); | |
5402 | } | |
5403 | ||
5404 | } | |
5405 | ||
5406 | // Refresh the main window | |
5407 | if (m_mainWin) | |
5408 | { | |
5409 | wxRect rectMain = m_mainWin->GetRect(); | |
5410 | rectMain.Intersect(*rect); | |
5411 | if (rectMain.GetWidth() && rectMain.GetHeight()) | |
5412 | { | |
5413 | int x, y; | |
5414 | m_mainWin->GetPosition(&x, &y); | |
5415 | rectMain.Offset(-x, -y); | |
5416 | m_mainWin->Refresh(eraseBackground, &rectMain); | |
5417 | } | |
5418 | } | |
5419 | } | |
5420 | } | |
5421 | ||
3cd94a0d | 5422 | void wxGenericListCtrl::Freeze() |
c5c528fc VZ |
5423 | { |
5424 | m_mainWin->Freeze(); | |
5425 | } | |
5426 | ||
3cd94a0d | 5427 | void wxGenericListCtrl::Thaw() |
c5c528fc VZ |
5428 | { |
5429 | m_mainWin->Thaw(); | |
5430 | } | |
5431 | ||
1e6feb95 | 5432 | #endif // wxUSE_LISTCTRL |
5b98eb2f | 5433 |