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