]>
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 | { | |
cabeffb0 RR |
1811 | return; |
1812 | ||
63852e78 RR |
1813 | int x1 = m_currentX; |
1814 | int y1 = 0; | |
f16ba4e6 | 1815 | m_owner->ClientToScreen( &x1, &y1 ); |
f6bcfd97 | 1816 | |
f16ba4e6 | 1817 | int x2 = m_currentX; |
63852e78 | 1818 | int y2 = 0; |
f6bcfd97 | 1819 | m_owner->GetClientSize( NULL, &y2 ); |
63852e78 | 1820 | m_owner->ClientToScreen( &x2, &y2 ); |
0208334d | 1821 | |
63852e78 | 1822 | wxScreenDC dc; |
3c679789 | 1823 | dc.SetLogicalFunction( wxINVERT ); |
63852e78 RR |
1824 | dc.SetPen( wxPen( *wxBLACK, 2, wxSOLID ) ); |
1825 | dc.SetBrush( *wxTRANSPARENT_BRUSH ); | |
0208334d | 1826 | |
f6bcfd97 BP |
1827 | AdjustDC(dc); |
1828 | ||
63852e78 | 1829 | dc.DrawLine( x1, y1, x2, y2 ); |
0208334d | 1830 | |
63852e78 | 1831 | dc.SetLogicalFunction( wxCOPY ); |
0208334d | 1832 | |
63852e78 RR |
1833 | dc.SetPen( wxNullPen ); |
1834 | dc.SetBrush( wxNullBrush ); | |
0208334d RR |
1835 | } |
1836 | ||
c801d85f KB |
1837 | void wxListHeaderWindow::OnMouse( wxMouseEvent &event ) |
1838 | { | |
f6bcfd97 | 1839 | // we want to work with logical coords |
3ca6a5f0 BP |
1840 | int x; |
1841 | m_owner->CalcUnscrolledPosition(event.GetX(), 0, &x, NULL); | |
3ca6a5f0 | 1842 | int y = event.GetY(); |
f6bcfd97 | 1843 | |
cfb50f14 | 1844 | if (m_isDragging) |
0208334d | 1845 | { |
355f2407 | 1846 | SendListEvent(wxEVT_COMMAND_LIST_COL_DRAGGING, event.GetPosition()); |
a77ec46d | 1847 | |
f6bcfd97 BP |
1848 | // we don't draw the line beyond our window, but we allow dragging it |
1849 | // there | |
1850 | int w = 0; | |
1851 | GetClientSize( &w, NULL ); | |
f6bcfd97 | 1852 | m_owner->CalcUnscrolledPosition(w, 0, &w, NULL); |
f6bcfd97 BP |
1853 | w -= 6; |
1854 | ||
1855 | // erase the line if it was drawn | |
1856 | if ( m_currentX < w ) | |
1857 | DrawCurrent(); | |
1858 | ||
63852e78 RR |
1859 | if (event.ButtonUp()) |
1860 | { | |
1861 | ReleaseMouse(); | |
cfb50f14 | 1862 | m_isDragging = FALSE; |
f6bcfd97 BP |
1863 | m_dirty = TRUE; |
1864 | m_owner->SetColumnWidth( m_column, m_currentX - m_minX ); | |
355f2407 | 1865 | SendListEvent(wxEVT_COMMAND_LIST_COL_END_DRAG, event.GetPosition()); |
63852e78 RR |
1866 | } |
1867 | else | |
1868 | { | |
f6bcfd97 | 1869 | if (x > m_minX + 7) |
63852e78 RR |
1870 | m_currentX = x; |
1871 | else | |
f6bcfd97 | 1872 | m_currentX = m_minX + 7; |
bd8289c1 | 1873 | |
f6bcfd97 BP |
1874 | // draw in the new location |
1875 | if ( m_currentX < w ) | |
1876 | DrawCurrent(); | |
bffa1c77 | 1877 | } |
0208334d | 1878 | } |
f6bcfd97 | 1879 | else // not dragging |
c801d85f | 1880 | { |
f6bcfd97 BP |
1881 | m_minX = 0; |
1882 | bool hit_border = FALSE; | |
1883 | ||
1884 | // end of the current column | |
1885 | int xpos = 0; | |
1886 | ||
1887 | // find the column where this event occured | |
62313c27 VZ |
1888 | int col, |
1889 | countCol = m_owner->GetColumnCount(); | |
1890 | for (col = 0; col < countCol; col++) | |
bffa1c77 | 1891 | { |
cf1dfa6b VZ |
1892 | xpos += m_owner->GetColumnWidth( col ); |
1893 | m_column = col; | |
f6bcfd97 BP |
1894 | |
1895 | if ( (abs(x-xpos) < 3) && (y < 22) ) | |
1896 | { | |
1897 | // near the column border | |
1898 | hit_border = TRUE; | |
1899 | break; | |
1900 | } | |
1901 | ||
1902 | if ( x < xpos ) | |
1903 | { | |
1904 | // inside the column | |
1905 | break; | |
1906 | } | |
1907 | ||
1908 | m_minX = xpos; | |
bffa1c77 | 1909 | } |
63852e78 | 1910 | |
62313c27 VZ |
1911 | if ( col == countCol ) |
1912 | m_column = -1; | |
1913 | ||
11358d39 | 1914 | if (event.LeftDown() || event.RightUp()) |
63852e78 | 1915 | { |
11358d39 | 1916 | if (hit_border && event.LeftDown()) |
f6bcfd97 | 1917 | { |
355f2407 VZ |
1918 | if ( SendListEvent(wxEVT_COMMAND_LIST_COL_BEGIN_DRAG, |
1919 | event.GetPosition()) ) | |
1920 | { | |
1921 | m_isDragging = TRUE; | |
1922 | m_currentX = x; | |
1923 | DrawCurrent(); | |
1924 | CaptureMouse(); | |
1925 | } | |
1926 | //else: column resizing was vetoed by the user code | |
f6bcfd97 | 1927 | } |
11358d39 | 1928 | else // click on a column |
f6bcfd97 | 1929 | { |
a77ec46d | 1930 | SendListEvent( event.LeftDown() |
11358d39 VZ |
1931 | ? wxEVT_COMMAND_LIST_COL_CLICK |
1932 | : wxEVT_COMMAND_LIST_COL_RIGHT_CLICK, | |
a77ec46d | 1933 | event.GetPosition()); |
f6bcfd97 | 1934 | } |
63852e78 | 1935 | } |
f6bcfd97 | 1936 | else if (event.Moving()) |
63852e78 | 1937 | { |
f6bcfd97 BP |
1938 | bool setCursor; |
1939 | if (hit_border) | |
1940 | { | |
1941 | setCursor = m_currentCursor == wxSTANDARD_CURSOR; | |
1942 | m_currentCursor = m_resizeCursor; | |
1943 | } | |
1944 | else | |
1945 | { | |
1946 | setCursor = m_currentCursor != wxSTANDARD_CURSOR; | |
1947 | m_currentCursor = wxSTANDARD_CURSOR; | |
1948 | } | |
1949 | ||
1950 | if ( setCursor ) | |
1951 | SetCursor(*m_currentCursor); | |
63852e78 | 1952 | } |
e1e955e1 | 1953 | } |
e1e955e1 | 1954 | } |
c801d85f KB |
1955 | |
1956 | void wxListHeaderWindow::OnSetFocus( wxFocusEvent &WXUNUSED(event) ) | |
1957 | { | |
63852e78 | 1958 | m_owner->SetFocus(); |
e1e955e1 | 1959 | } |
c801d85f | 1960 | |
355f2407 | 1961 | bool wxListHeaderWindow::SendListEvent(wxEventType type, wxPoint pos) |
a77ec46d RD |
1962 | { |
1963 | wxWindow *parent = GetParent(); | |
1964 | wxListEvent le( type, parent->GetId() ); | |
1965 | le.SetEventObject( parent ); | |
1966 | le.m_pointDrag = pos; | |
1967 | ||
1968 | // the position should be relative to the parent window, not | |
1969 | // this one for compatibility with MSW and common sense: the | |
1970 | // user code doesn't know anything at all about this header | |
1971 | // window, so why should it get positions relative to it? | |
1972 | le.m_pointDrag.y -= GetSize().y; | |
1973 | ||
1974 | le.m_col = m_column; | |
355f2407 | 1975 | return !parent->GetEventHandler()->ProcessEvent( le ) || le.IsAllowed(); |
a77ec46d RD |
1976 | } |
1977 | ||
c801d85f KB |
1978 | //----------------------------------------------------------------------------- |
1979 | // wxListRenameTimer (internal) | |
1980 | //----------------------------------------------------------------------------- | |
1981 | ||
bd8289c1 VZ |
1982 | wxListRenameTimer::wxListRenameTimer( wxListMainWindow *owner ) |
1983 | { | |
63852e78 | 1984 | m_owner = owner; |
e1e955e1 | 1985 | } |
c801d85f | 1986 | |
bd8289c1 VZ |
1987 | void wxListRenameTimer::Notify() |
1988 | { | |
63852e78 | 1989 | m_owner->OnRenameTimer(); |
e1e955e1 | 1990 | } |
c801d85f | 1991 | |
ee7ee469 RR |
1992 | //----------------------------------------------------------------------------- |
1993 | // wxListTextCtrl (internal) | |
1994 | //----------------------------------------------------------------------------- | |
1995 | ||
ee7ee469 | 1996 | BEGIN_EVENT_TABLE(wxListTextCtrl,wxTextCtrl) |
63852e78 | 1997 | EVT_CHAR (wxListTextCtrl::OnChar) |
2c1f73ee | 1998 | EVT_KEY_UP (wxListTextCtrl::OnKeyUp) |
63852e78 | 1999 | EVT_KILL_FOCUS (wxListTextCtrl::OnKillFocus) |
ee7ee469 RR |
2000 | END_EVENT_TABLE() |
2001 | ||
62d89eb4 VZ |
2002 | wxListTextCtrl::wxListTextCtrl(wxListMainWindow *owner, size_t itemEdit) |
2003 | : m_startValue(owner->GetItemText(itemEdit)), | |
2004 | m_itemEdited(itemEdit) | |
2005 | { | |
63852e78 | 2006 | m_owner = owner; |
dd5a32cc | 2007 | m_finished = FALSE; |
62d89eb4 VZ |
2008 | |
2009 | wxRect rectLabel = owner->GetLineLabelRect(itemEdit); | |
2010 | ||
2011 | m_owner->CalcScrolledPosition(rectLabel.x, rectLabel.y, | |
2012 | &rectLabel.x, &rectLabel.y); | |
2013 | ||
2014 | (void)Create(owner, wxID_ANY, m_startValue, | |
2015 | wxPoint(rectLabel.x-4,rectLabel.y-4), | |
2016 | wxSize(rectLabel.width+11,rectLabel.height+8)); | |
ee7ee469 RR |
2017 | } |
2018 | ||
62d89eb4 | 2019 | void wxListTextCtrl::Finish() |
ee7ee469 | 2020 | { |
62d89eb4 | 2021 | if ( !m_finished ) |
63852e78 | 2022 | { |
62d89eb4 | 2023 | wxPendingDelete.Append(this); |
f6bcfd97 | 2024 | |
dd5a32cc | 2025 | m_finished = TRUE; |
62d89eb4 | 2026 | |
a6d57d03 | 2027 | m_owner->SetFocus(); |
62d89eb4 VZ |
2028 | } |
2029 | } | |
dd5a32cc | 2030 | |
62d89eb4 VZ |
2031 | bool wxListTextCtrl::AcceptChanges() |
2032 | { | |
2033 | const wxString value = GetValue(); | |
2034 | ||
2035 | if ( value == m_startValue ) | |
2036 | { | |
2037 | // nothing changed, always accept | |
2038 | return TRUE; | |
63852e78 | 2039 | } |
62d89eb4 VZ |
2040 | |
2041 | if ( !m_owner->OnRenameAccept(m_itemEdited, value) ) | |
63852e78 | 2042 | { |
62d89eb4 VZ |
2043 | // vetoed by the user |
2044 | return FALSE; | |
2045 | } | |
f6bcfd97 | 2046 | |
62d89eb4 VZ |
2047 | // accepted, do rename the item |
2048 | m_owner->SetItemText(m_itemEdited, value); | |
f6bcfd97 | 2049 | |
62d89eb4 VZ |
2050 | return TRUE; |
2051 | } | |
dd5a32cc | 2052 | |
62d89eb4 VZ |
2053 | void wxListTextCtrl::OnChar( wxKeyEvent &event ) |
2054 | { | |
2055 | switch ( event.m_keyCode ) | |
2056 | { | |
2057 | case WXK_RETURN: | |
2058 | if ( !AcceptChanges() ) | |
2059 | { | |
2060 | // vetoed by the user code | |
2061 | break; | |
2062 | } | |
2063 | //else: fall through | |
f6bcfd97 | 2064 | |
62d89eb4 VZ |
2065 | case WXK_ESCAPE: |
2066 | Finish(); | |
86586459 | 2067 | m_owner->OnRenameCancelled( m_itemEdited ); |
62d89eb4 VZ |
2068 | break; |
2069 | ||
2070 | default: | |
2071 | event.Skip(); | |
2072 | } | |
63852e78 RR |
2073 | } |
2074 | ||
c13cace1 VS |
2075 | void wxListTextCtrl::OnKeyUp( wxKeyEvent &event ) |
2076 | { | |
dd5a32cc RR |
2077 | if (m_finished) |
2078 | { | |
2079 | event.Skip(); | |
2080 | return; | |
2081 | } | |
2082 | ||
c13cace1 VS |
2083 | // auto-grow the textctrl: |
2084 | wxSize parentSize = m_owner->GetSize(); | |
2085 | wxPoint myPos = GetPosition(); | |
2086 | wxSize mySize = GetSize(); | |
2087 | int sx, sy; | |
a6d57d03 | 2088 | GetTextExtent(GetValue() + _T("MM"), &sx, &sy); |
cf1dfa6b VZ |
2089 | if (myPos.x + sx > parentSize.x) |
2090 | sx = parentSize.x - myPos.x; | |
2091 | if (mySize.x > sx) | |
2092 | sx = mySize.x; | |
c13cace1 | 2093 | SetSize(sx, -1); |
2c1f73ee | 2094 | |
c13cace1 VS |
2095 | event.Skip(); |
2096 | } | |
2097 | ||
dd5a32cc | 2098 | void wxListTextCtrl::OnKillFocus( wxFocusEvent &event ) |
63852e78 | 2099 | { |
62d89eb4 | 2100 | if ( !m_finished ) |
dd5a32cc | 2101 | { |
86586459 | 2102 | // We must finish regardless of success, otherwise we'll get focus problems |
62d89eb4 | 2103 | Finish(); |
86351e4a | 2104 | |
86586459 RR |
2105 | if ( !AcceptChanges() ) |
2106 | m_owner->OnRenameCancelled( m_itemEdited ); | |
62d89eb4 | 2107 | } |
86351e4a | 2108 | |
62d89eb4 | 2109 | event.Skip(); |
ee7ee469 RR |
2110 | } |
2111 | ||
c801d85f KB |
2112 | //----------------------------------------------------------------------------- |
2113 | // wxListMainWindow | |
2114 | //----------------------------------------------------------------------------- | |
2115 | ||
5a1cad6e | 2116 | IMPLEMENT_DYNAMIC_CLASS(wxListMainWindow,wxScrolledWindow) |
bd8289c1 | 2117 | |
c801d85f KB |
2118 | BEGIN_EVENT_TABLE(wxListMainWindow,wxScrolledWindow) |
2119 | EVT_PAINT (wxListMainWindow::OnPaint) | |
c801d85f KB |
2120 | EVT_MOUSE_EVENTS (wxListMainWindow::OnMouse) |
2121 | EVT_CHAR (wxListMainWindow::OnChar) | |
3dfb93fd | 2122 | EVT_KEY_DOWN (wxListMainWindow::OnKeyDown) |
c801d85f KB |
2123 | EVT_SET_FOCUS (wxListMainWindow::OnSetFocus) |
2124 | EVT_KILL_FOCUS (wxListMainWindow::OnKillFocus) | |
2fa7c206 | 2125 | EVT_SCROLLWIN (wxListMainWindow::OnScroll) |
c801d85f KB |
2126 | END_EVENT_TABLE() |
2127 | ||
1370703e | 2128 | void wxListMainWindow::Init() |
c801d85f | 2129 | { |
139adb6a | 2130 | m_dirty = TRUE; |
cf1dfa6b VZ |
2131 | m_countVirt = 0; |
2132 | m_lineFrom = | |
b54e41c5 | 2133 | m_lineTo = (size_t)-1; |
cf1dfa6b VZ |
2134 | m_linesPerPage = 0; |
2135 | ||
2136 | m_headerWidth = | |
2137 | m_lineHeight = 0; | |
1370703e | 2138 | |
80020b62 JS |
2139 | m_small_image_list = (wxImageListType *) NULL; |
2140 | m_normal_image_list = (wxImageListType *) NULL; | |
1370703e | 2141 | |
139adb6a RR |
2142 | m_small_spacing = 30; |
2143 | m_normal_spacing = 40; | |
1370703e | 2144 | |
139adb6a | 2145 | m_hasFocus = FALSE; |
1370703e VZ |
2146 | m_dragCount = 0; |
2147 | m_isCreated = FALSE; | |
2148 | ||
139adb6a RR |
2149 | m_lastOnSame = FALSE; |
2150 | m_renameTimer = new wxListRenameTimer( this ); | |
1370703e | 2151 | |
cf1dfa6b | 2152 | m_current = |
efbb7287 | 2153 | m_lineLastClicked = |
1370703e | 2154 | m_lineBeforeLastClicked = (size_t)-1; |
c5c528fc VZ |
2155 | |
2156 | m_freezeCount = 0; | |
e1e955e1 | 2157 | } |
c801d85f | 2158 | |
1370703e | 2159 | wxListMainWindow::wxListMainWindow() |
c801d85f | 2160 | { |
1370703e VZ |
2161 | Init(); |
2162 | ||
49ecb029 VZ |
2163 | m_highlightBrush = |
2164 | m_highlightUnfocusedBrush = (wxBrush *) NULL; | |
1370703e VZ |
2165 | } |
2166 | ||
2167 | wxListMainWindow::wxListMainWindow( wxWindow *parent, | |
2168 | wxWindowID id, | |
2169 | const wxPoint& pos, | |
2170 | const wxSize& size, | |
2171 | long style, | |
2172 | const wxString &name ) | |
2173 | : wxScrolledWindow( parent, id, pos, size, | |
2174 | style | wxHSCROLL | wxVSCROLL, name ) | |
2175 | { | |
2176 | Init(); | |
2177 | ||
49ecb029 VZ |
2178 | m_highlightBrush = new wxBrush |
2179 | ( | |
a756f210 | 2180 | wxSystemSettings::GetColour |
49ecb029 VZ |
2181 | ( |
2182 | wxSYS_COLOUR_HIGHLIGHT | |
2183 | ), | |
2184 | wxSOLID | |
2185 | ); | |
2186 | ||
2187 | m_highlightUnfocusedBrush = new wxBrush | |
2188 | ( | |
a756f210 | 2189 | wxSystemSettings::GetColour |
49ecb029 VZ |
2190 | ( |
2191 | wxSYS_COLOUR_BTNSHADOW | |
2192 | ), | |
2193 | wxSOLID | |
2194 | ); | |
2195 | ||
139adb6a RR |
2196 | wxSize sz = size; |
2197 | sz.y = 25; | |
bd8289c1 | 2198 | |
6d78bbe6 | 2199 | SetScrollbars( 0, 0, 0, 0, 0, 0 ); |
bd8289c1 | 2200 | |
a756f210 | 2201 | SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_LISTBOX ) ); |
e1e955e1 | 2202 | } |
c801d85f | 2203 | |
fd9811b1 | 2204 | wxListMainWindow::~wxListMainWindow() |
c801d85f | 2205 | { |
5fe143df | 2206 | DoDeleteAllItems(); |
222ed1d6 | 2207 | WX_CLEAR_LIST(wxListHeaderDataList, m_columns); |
12c1b46a | 2208 | |
b54e41c5 | 2209 | delete m_highlightBrush; |
49ecb029 | 2210 | delete m_highlightUnfocusedBrush; |
004fd0c8 | 2211 | |
139adb6a | 2212 | delete m_renameTimer; |
e1e955e1 | 2213 | } |
c801d85f | 2214 | |
cf1dfa6b | 2215 | void wxListMainWindow::CacheLineData(size_t line) |
c801d85f | 2216 | { |
3cd94a0d | 2217 | wxGenericListCtrl *listctrl = GetListCtrl(); |
25e3a937 | 2218 | |
b54e41c5 | 2219 | wxListLineData *ld = GetDummyLine(); |
f6bcfd97 | 2220 | |
cf1dfa6b VZ |
2221 | size_t countCol = GetColumnCount(); |
2222 | for ( size_t col = 0; col < countCol; col++ ) | |
2223 | { | |
2224 | ld->SetText(col, listctrl->OnGetItemText(line, col)); | |
2225 | } | |
2226 | ||
5cd89174 | 2227 | ld->SetImage(listctrl->OnGetItemImage(line)); |
6c02c329 | 2228 | ld->SetAttr(listctrl->OnGetItemAttr(line)); |
e1e955e1 | 2229 | } |
c801d85f | 2230 | |
b54e41c5 | 2231 | wxListLineData *wxListMainWindow::GetDummyLine() const |
c801d85f | 2232 | { |
cf1dfa6b | 2233 | wxASSERT_MSG( !IsEmpty(), _T("invalid line index") ); |
2c1f73ee | 2234 | |
904ccf52 VZ |
2235 | wxASSERT_MSG( IsVirtual(), _T("GetDummyLine() shouldn't be called") ); |
2236 | ||
2237 | wxListMainWindow *self = wxConstCast(this, wxListMainWindow); | |
2238 | ||
2239 | // we need to recreate the dummy line if the number of columns in the | |
2240 | // control changed as it would have the incorrect number of fields | |
2241 | // otherwise | |
2242 | if ( !m_lines.IsEmpty() && | |
2243 | m_lines[0].m_items.GetCount() != (size_t)GetColumnCount() ) | |
2c1f73ee | 2244 | { |
904ccf52 VZ |
2245 | self->m_lines.Clear(); |
2246 | } | |
cf1dfa6b | 2247 | |
904ccf52 VZ |
2248 | if ( m_lines.IsEmpty() ) |
2249 | { | |
5cd89174 | 2250 | wxListLineData *line = new wxListLineData(self); |
cf1dfa6b | 2251 | self->m_lines.Add(line); |
904ccf52 VZ |
2252 | |
2253 | // don't waste extra memory -- there never going to be anything | |
2254 | // else/more in this array | |
2255 | self->m_lines.Shrink(); | |
2c1f73ee VZ |
2256 | } |
2257 | ||
cf1dfa6b VZ |
2258 | return &m_lines[0]; |
2259 | } | |
2260 | ||
5cd89174 VZ |
2261 | // ---------------------------------------------------------------------------- |
2262 | // line geometry (report mode only) | |
2263 | // ---------------------------------------------------------------------------- | |
2264 | ||
cf1dfa6b VZ |
2265 | wxCoord wxListMainWindow::GetLineHeight() const |
2266 | { | |
cf1dfa6b VZ |
2267 | // we cache the line height as calling GetTextExtent() is slow |
2268 | if ( !m_lineHeight ) | |
2c1f73ee | 2269 | { |
cf1dfa6b | 2270 | wxListMainWindow *self = wxConstCast(this, wxListMainWindow); |
bd8289c1 | 2271 | |
cf1dfa6b VZ |
2272 | wxClientDC dc( self ); |
2273 | dc.SetFont( GetFont() ); | |
c801d85f | 2274 | |
cf1dfa6b VZ |
2275 | wxCoord y; |
2276 | dc.GetTextExtent(_T("H"), NULL, &y); | |
004fd0c8 | 2277 | |
ca7353de RD |
2278 | if ( m_small_image_list && m_small_image_list->GetImageCount() ) |
2279 | { | |
2280 | int iw = 0; | |
2281 | int ih = 0; | |
2282 | m_small_image_list->GetSize(0, iw, ih); | |
2283 | y = wxMax(y, ih); | |
2284 | } | |
2285 | ||
2286 | y += EXTRA_HEIGHT; | |
cf1dfa6b VZ |
2287 | self->m_lineHeight = y + LINE_SPACING; |
2288 | } | |
bffa1c77 | 2289 | |
cf1dfa6b VZ |
2290 | return m_lineHeight; |
2291 | } | |
bffa1c77 | 2292 | |
cf1dfa6b VZ |
2293 | wxCoord wxListMainWindow::GetLineY(size_t line) const |
2294 | { | |
2295 | wxASSERT_MSG( HasFlag(wxLC_REPORT), _T("only works in report mode") ); | |
1370703e | 2296 | |
cf1dfa6b VZ |
2297 | return LINE_SPACING + line*GetLineHeight(); |
2298 | } | |
206b0a67 | 2299 | |
5cd89174 VZ |
2300 | wxRect wxListMainWindow::GetLineRect(size_t line) const |
2301 | { | |
2302 | if ( !InReportView() ) | |
2303 | return GetLine(line)->m_gi->m_rectAll; | |
2304 | ||
2305 | wxRect rect; | |
2306 | rect.x = HEADER_OFFSET_X; | |
2307 | rect.y = GetLineY(line); | |
2308 | rect.width = GetHeaderWidth(); | |
2309 | rect.height = GetLineHeight(); | |
2310 | ||
2311 | return rect; | |
2312 | } | |
2313 | ||
2314 | wxRect wxListMainWindow::GetLineLabelRect(size_t line) const | |
2315 | { | |
2316 | if ( !InReportView() ) | |
2317 | return GetLine(line)->m_gi->m_rectLabel; | |
2318 | ||
2319 | wxRect rect; | |
2320 | rect.x = HEADER_OFFSET_X; | |
2321 | rect.y = GetLineY(line); | |
2322 | rect.width = GetColumnWidth(0); | |
2323 | rect.height = GetLineHeight(); | |
2324 | ||
2325 | return rect; | |
2326 | } | |
2327 | ||
2328 | wxRect wxListMainWindow::GetLineIconRect(size_t line) const | |
2329 | { | |
2330 | if ( !InReportView() ) | |
2331 | return GetLine(line)->m_gi->m_rectIcon; | |
2332 | ||
2333 | wxListLineData *ld = GetLine(line); | |
2334 | wxASSERT_MSG( ld->HasImage(), _T("should have an image") ); | |
2335 | ||
2336 | wxRect rect; | |
2337 | rect.x = HEADER_OFFSET_X; | |
2338 | rect.y = GetLineY(line); | |
2339 | GetImageSize(ld->GetImage(), rect.width, rect.height); | |
2340 | ||
2341 | return rect; | |
2342 | } | |
2343 | ||
2344 | wxRect wxListMainWindow::GetLineHighlightRect(size_t line) const | |
2345 | { | |
2346 | return InReportView() ? GetLineRect(line) | |
2347 | : GetLine(line)->m_gi->m_rectHighlight; | |
2348 | } | |
2349 | ||
2350 | long wxListMainWindow::HitTestLine(size_t line, int x, int y) const | |
2351 | { | |
fc4f1d5f VZ |
2352 | wxASSERT_MSG( line < GetItemCount(), _T("invalid line in HitTestLine") ); |
2353 | ||
5cd89174 VZ |
2354 | wxListLineData *ld = GetLine(line); |
2355 | ||
2356 | if ( ld->HasImage() && GetLineIconRect(line).Inside(x, y) ) | |
2357 | return wxLIST_HITTEST_ONITEMICON; | |
2358 | ||
acf4d858 VS |
2359 | // VS: Testing for "ld->HasText() || InReportView()" instead of |
2360 | // "ld->HasText()" is needed to make empty lines in report view | |
2361 | // possible | |
2362 | if ( ld->HasText() || InReportView() ) | |
5cd89174 VZ |
2363 | { |
2364 | wxRect rect = InReportView() ? GetLineRect(line) | |
2365 | : GetLineLabelRect(line); | |
2366 | ||
2367 | if ( rect.Inside(x, y) ) | |
2368 | return wxLIST_HITTEST_ONITEMLABEL; | |
2369 | } | |
2370 | ||
2371 | return 0; | |
2372 | } | |
2373 | ||
2374 | // ---------------------------------------------------------------------------- | |
2375 | // highlight (selection) handling | |
2376 | // ---------------------------------------------------------------------------- | |
2377 | ||
b54e41c5 | 2378 | bool wxListMainWindow::IsHighlighted(size_t line) const |
cf1dfa6b VZ |
2379 | { |
2380 | if ( IsVirtual() ) | |
2381 | { | |
b54e41c5 | 2382 | return m_selStore.IsSelected(line); |
cf1dfa6b VZ |
2383 | } |
2384 | else // !virtual | |
2385 | { | |
2386 | wxListLineData *ld = GetLine(line); | |
b54e41c5 | 2387 | wxCHECK_MSG( ld, FALSE, _T("invalid index in IsHighlighted") ); |
cf1dfa6b | 2388 | |
b54e41c5 | 2389 | return ld->IsHighlighted(); |
cf1dfa6b VZ |
2390 | } |
2391 | } | |
2392 | ||
68a9ef0e VZ |
2393 | void wxListMainWindow::HighlightLines( size_t lineFrom, |
2394 | size_t lineTo, | |
2395 | bool highlight ) | |
cf1dfa6b | 2396 | { |
cf1dfa6b VZ |
2397 | if ( IsVirtual() ) |
2398 | { | |
68a9ef0e VZ |
2399 | wxArrayInt linesChanged; |
2400 | if ( !m_selStore.SelectRange(lineFrom, lineTo, highlight, | |
2401 | &linesChanged) ) | |
2402 | { | |
2403 | // meny items changed state, refresh everything | |
2404 | RefreshLines(lineFrom, lineTo); | |
2405 | } | |
2406 | else // only a few items changed state, refresh only them | |
2407 | { | |
2408 | size_t count = linesChanged.GetCount(); | |
2409 | for ( size_t n = 0; n < count; n++ ) | |
2410 | { | |
2411 | RefreshLine(linesChanged[n]); | |
2412 | } | |
2413 | } | |
b54e41c5 | 2414 | } |
68a9ef0e | 2415 | else // iterate over all items in non report view |
b54e41c5 | 2416 | { |
b54e41c5 | 2417 | for ( size_t line = lineFrom; line <= lineTo; line++ ) |
cf1dfa6b | 2418 | { |
b54e41c5 | 2419 | if ( HighlightLine(line, highlight) ) |
68a9ef0e VZ |
2420 | { |
2421 | RefreshLine(line); | |
2422 | } | |
cf1dfa6b | 2423 | } |
b54e41c5 VZ |
2424 | } |
2425 | } | |
2426 | ||
2427 | bool wxListMainWindow::HighlightLine( size_t line, bool highlight ) | |
2428 | { | |
2429 | bool changed; | |
2430 | ||
2431 | if ( IsVirtual() ) | |
2432 | { | |
2433 | changed = m_selStore.SelectItem(line, highlight); | |
cf1dfa6b VZ |
2434 | } |
2435 | else // !virtual | |
2436 | { | |
2437 | wxListLineData *ld = GetLine(line); | |
49ecb029 | 2438 | wxCHECK_MSG( ld, FALSE, _T("invalid index in HighlightLine") ); |
cf1dfa6b | 2439 | |
b54e41c5 | 2440 | changed = ld->Highlight(highlight); |
cf1dfa6b VZ |
2441 | } |
2442 | ||
2443 | if ( changed ) | |
2444 | { | |
b54e41c5 | 2445 | SendNotify( line, highlight ? wxEVT_COMMAND_LIST_ITEM_SELECTED |
5cd89174 | 2446 | : wxEVT_COMMAND_LIST_ITEM_DESELECTED ); |
cf1dfa6b VZ |
2447 | } |
2448 | ||
2449 | return changed; | |
2450 | } | |
2451 | ||
2452 | void wxListMainWindow::RefreshLine( size_t line ) | |
2453 | { | |
6ea1323a VZ |
2454 | if ( HasFlag(wxLC_REPORT) ) |
2455 | { | |
2456 | size_t visibleFrom, visibleTo; | |
2457 | GetVisibleLinesRange(&visibleFrom, &visibleTo); | |
c1c4c551 | 2458 | |
6ea1323a VZ |
2459 | if ( line < visibleFrom || line > visibleTo ) |
2460 | return; | |
2461 | } | |
c1c4c551 | 2462 | |
5cd89174 | 2463 | wxRect rect = GetLineRect(line); |
cf1dfa6b VZ |
2464 | |
2465 | CalcScrolledPosition( rect.x, rect.y, &rect.x, &rect.y ); | |
2466 | RefreshRect( rect ); | |
2467 | } | |
2468 | ||
2469 | void wxListMainWindow::RefreshLines( size_t lineFrom, size_t lineTo ) | |
2470 | { | |
2471 | // we suppose that they are ordered by caller | |
2472 | wxASSERT_MSG( lineFrom <= lineTo, _T("indices in disorder") ); | |
2473 | ||
6b4a8d93 VZ |
2474 | wxASSERT_MSG( lineTo < GetItemCount(), _T("invalid line range") ); |
2475 | ||
cf1dfa6b VZ |
2476 | if ( HasFlag(wxLC_REPORT) ) |
2477 | { | |
b54e41c5 VZ |
2478 | size_t visibleFrom, visibleTo; |
2479 | GetVisibleLinesRange(&visibleFrom, &visibleTo); | |
2480 | ||
2481 | if ( lineFrom < visibleFrom ) | |
2482 | lineFrom = visibleFrom; | |
2483 | if ( lineTo > visibleTo ) | |
2484 | lineTo = visibleTo; | |
cf1dfa6b VZ |
2485 | |
2486 | wxRect rect; | |
2487 | rect.x = 0; | |
2488 | rect.y = GetLineY(lineFrom); | |
2489 | rect.width = GetClientSize().x; | |
91c6cc0e | 2490 | rect.height = GetLineY(lineTo) - rect.y + GetLineHeight(); |
cf1dfa6b VZ |
2491 | |
2492 | CalcScrolledPosition( rect.x, rect.y, &rect.x, &rect.y ); | |
2493 | RefreshRect( rect ); | |
2494 | } | |
2495 | else // !report | |
2496 | { | |
2497 | // TODO: this should be optimized... | |
2498 | for ( size_t line = lineFrom; line <= lineTo; line++ ) | |
2499 | { | |
2500 | RefreshLine(line); | |
2501 | } | |
2502 | } | |
2503 | } | |
2504 | ||
6b4a8d93 VZ |
2505 | void wxListMainWindow::RefreshAfter( size_t lineFrom ) |
2506 | { | |
2507 | if ( HasFlag(wxLC_REPORT) ) | |
2508 | { | |
c29582d0 JS |
2509 | size_t visibleFrom, visibleTo; |
2510 | GetVisibleLinesRange(&visibleFrom, &visibleTo); | |
6b4a8d93 VZ |
2511 | |
2512 | if ( lineFrom < visibleFrom ) | |
2513 | lineFrom = visibleFrom; | |
c29582d0 JS |
2514 | else if ( lineFrom > visibleTo ) |
2515 | return; | |
6b4a8d93 VZ |
2516 | |
2517 | wxRect rect; | |
2518 | rect.x = 0; | |
2519 | rect.y = GetLineY(lineFrom); | |
c29582d0 | 2520 | CalcScrolledPosition( rect.x, rect.y, &rect.x, &rect.y ); |
6b4a8d93 VZ |
2521 | |
2522 | wxSize size = GetClientSize(); | |
2523 | rect.width = size.x; | |
2524 | // refresh till the bottom of the window | |
2525 | rect.height = size.y - rect.y; | |
2526 | ||
6b4a8d93 | 2527 | RefreshRect( rect ); |
6b4a8d93 VZ |
2528 | } |
2529 | else // !report | |
2530 | { | |
2531 | // TODO: how to do it more efficiently? | |
2532 | m_dirty = TRUE; | |
2533 | } | |
2534 | } | |
2535 | ||
49ecb029 VZ |
2536 | void wxListMainWindow::RefreshSelected() |
2537 | { | |
2538 | if ( IsEmpty() ) | |
2539 | return; | |
2540 | ||
2541 | size_t from, to; | |
2542 | if ( InReportView() ) | |
2543 | { | |
2544 | GetVisibleLinesRange(&from, &to); | |
2545 | } | |
2546 | else // !virtual | |
2547 | { | |
2548 | from = 0; | |
2549 | to = GetItemCount() - 1; | |
2550 | } | |
2551 | ||
cf30ae13 | 2552 | if ( HasCurrent() && m_current >= from && m_current <= to ) |
49ecb029 VZ |
2553 | { |
2554 | RefreshLine(m_current); | |
2555 | } | |
2556 | ||
2557 | for ( size_t line = from; line <= to; line++ ) | |
2558 | { | |
2559 | // NB: the test works as expected even if m_current == -1 | |
2560 | if ( line != m_current && IsHighlighted(line) ) | |
2561 | { | |
2562 | RefreshLine(line); | |
2563 | } | |
2564 | } | |
2565 | } | |
2566 | ||
c5c528fc VZ |
2567 | void wxListMainWindow::Freeze() |
2568 | { | |
2569 | m_freezeCount++; | |
2570 | } | |
2571 | ||
2572 | void wxListMainWindow::Thaw() | |
2573 | { | |
2574 | wxCHECK_RET( m_freezeCount > 0, _T("thawing unfrozen list control?") ); | |
2575 | ||
2576 | if ( !--m_freezeCount ) | |
2577 | { | |
2578 | Refresh(); | |
2579 | } | |
2580 | } | |
2581 | ||
cf1dfa6b VZ |
2582 | void wxListMainWindow::OnPaint( wxPaintEvent &WXUNUSED(event) ) |
2583 | { | |
2584 | // Note: a wxPaintDC must be constructed even if no drawing is | |
2585 | // done (a Windows requirement). | |
2586 | wxPaintDC dc( this ); | |
2587 | ||
c5c528fc | 2588 | if ( IsEmpty() || m_freezeCount ) |
cf1dfa6b | 2589 | { |
c5c528fc | 2590 | // nothing to draw or not the moment to draw it |
cf1dfa6b VZ |
2591 | return; |
2592 | } | |
2593 | ||
1e4d446b VZ |
2594 | if ( m_dirty ) |
2595 | { | |
2596 | // delay the repainting until we calculate all the items positions | |
2597 | return; | |
2598 | } | |
2599 | ||
cf1dfa6b VZ |
2600 | PrepareDC( dc ); |
2601 | ||
2602 | int dev_x, dev_y; | |
2603 | CalcScrolledPosition( 0, 0, &dev_x, &dev_y ); | |
2604 | ||
2605 | dc.BeginDrawing(); | |
2606 | ||
2607 | dc.SetFont( GetFont() ); | |
2608 | ||
2609 | if ( HasFlag(wxLC_REPORT) ) | |
2610 | { | |
b54e41c5 | 2611 | int lineHeight = GetLineHeight(); |
cf1dfa6b | 2612 | |
b54e41c5 VZ |
2613 | size_t visibleFrom, visibleTo; |
2614 | GetVisibleLinesRange(&visibleFrom, &visibleTo); | |
b84839ae VZ |
2615 | |
2616 | wxRect rectLine; | |
2617 | wxCoord xOrig, yOrig; | |
2618 | CalcUnscrolledPosition(0, 0, &xOrig, &yOrig); | |
2619 | ||
ff3d11a0 | 2620 | // tell the caller cache to cache the data |
91c6cc0e VZ |
2621 | if ( IsVirtual() ) |
2622 | { | |
2623 | wxListEvent evCache(wxEVT_COMMAND_LIST_CACHE_HINT, | |
2624 | GetParent()->GetId()); | |
2625 | evCache.SetEventObject( GetParent() ); | |
2626 | evCache.m_oldItemIndex = visibleFrom; | |
2627 | evCache.m_itemIndex = visibleTo; | |
2628 | GetParent()->GetEventHandler()->ProcessEvent( evCache ); | |
2629 | } | |
ff3d11a0 | 2630 | |
b54e41c5 | 2631 | for ( size_t line = visibleFrom; line <= visibleTo; line++ ) |
cf1dfa6b | 2632 | { |
b84839ae VZ |
2633 | rectLine = GetLineRect(line); |
2634 | ||
2635 | if ( !IsExposed(rectLine.x - xOrig, rectLine.y - yOrig, | |
2636 | rectLine.width, rectLine.height) ) | |
2637 | { | |
2638 | // don't redraw unaffected lines to avoid flicker | |
2639 | continue; | |
2640 | } | |
2641 | ||
5cd89174 | 2642 | GetLine(line)->DrawInReportMode( &dc, |
b84839ae | 2643 | rectLine, |
5cd89174 | 2644 | GetLineHighlightRect(line), |
49ecb029 | 2645 | IsHighlighted(line) ); |
cf1dfa6b VZ |
2646 | } |
2647 | ||
2648 | if ( HasFlag(wxLC_HRULES) ) | |
2649 | { | |
b54e41c5 | 2650 | wxPen pen(GetRuleColour(), 1, wxSOLID); |
cf1dfa6b VZ |
2651 | wxSize clientSize = GetClientSize(); |
2652 | ||
e7d073c3 RD |
2653 | // Don't draw the first one |
2654 | for ( size_t i = visibleFrom+1; i <= visibleTo; i++ ) | |
cf1dfa6b VZ |
2655 | { |
2656 | dc.SetPen(pen); | |
2657 | dc.SetBrush( *wxTRANSPARENT_BRUSH ); | |
b54e41c5 VZ |
2658 | dc.DrawLine(0 - dev_x, i*lineHeight, |
2659 | clientSize.x - dev_x, i*lineHeight); | |
cf1dfa6b VZ |
2660 | } |
2661 | ||
2662 | // Draw last horizontal rule | |
e7d073c3 | 2663 | if ( visibleTo == GetItemCount() - 1 ) |
cf1dfa6b VZ |
2664 | { |
2665 | dc.SetPen(pen); | |
2666 | dc.SetBrush( *wxTRANSPARENT_BRUSH ); | |
e7d073c3 RD |
2667 | dc.DrawLine(0 - dev_x, (m_lineTo+1)*lineHeight, |
2668 | clientSize.x - dev_x , (m_lineTo+1)*lineHeight ); | |
cf1dfa6b | 2669 | } |
2c1f73ee | 2670 | } |
206b0a67 JS |
2671 | |
2672 | // Draw vertical rules if required | |
cf1dfa6b | 2673 | if ( HasFlag(wxLC_VRULES) && !IsEmpty() ) |
206b0a67 | 2674 | { |
b54e41c5 | 2675 | wxPen pen(GetRuleColour(), 1, wxSOLID); |
cf1dfa6b | 2676 | |
206b0a67 JS |
2677 | wxRect firstItemRect; |
2678 | wxRect lastItemRect; | |
e7d073c3 RD |
2679 | GetItemRect(visibleFrom, firstItemRect); |
2680 | GetItemRect(visibleTo, lastItemRect); | |
206b0a67 | 2681 | int x = firstItemRect.GetX(); |
673dfcfa JS |
2682 | dc.SetPen(pen); |
2683 | dc.SetBrush(* wxTRANSPARENT_BRUSH); | |
999836aa | 2684 | for (int col = 0; col < GetColumnCount(); col++) |
206b0a67 JS |
2685 | { |
2686 | int colWidth = GetColumnWidth(col); | |
cf1dfa6b | 2687 | x += colWidth; |
e7d073c3 RD |
2688 | dc.DrawLine(x - dev_x - 2, firstItemRect.GetY() - 1 - dev_y, |
2689 | x - dev_x - 2, lastItemRect.GetBottom() + 1 - dev_y); | |
206b0a67 | 2690 | } |
d786bf87 | 2691 | } |
139adb6a | 2692 | } |
cf1dfa6b | 2693 | else // !report |
139adb6a | 2694 | { |
1370703e | 2695 | size_t count = GetItemCount(); |
cf1dfa6b VZ |
2696 | for ( size_t i = 0; i < count; i++ ) |
2697 | { | |
2698 | GetLine(i)->Draw( &dc ); | |
2699 | } | |
139adb6a | 2700 | } |
004fd0c8 | 2701 | |
c25f61f1 | 2702 | if ( HasCurrent() ) |
cf1dfa6b | 2703 | { |
c25f61f1 | 2704 | // don't draw rect outline under Max if we already have the background |
49ecb029 VZ |
2705 | // color but under other platforms only draw it if we do: it is a bit |
2706 | // silly to draw "focus rect" if we don't have focus! | |
4176fb7d | 2707 | #ifdef __WXMAC__ |
c25f61f1 | 2708 | if ( !m_hasFocus ) |
49ecb029 VZ |
2709 | #else // !__WXMAC__ |
2710 | if ( m_hasFocus ) | |
2711 | #endif // __WXMAC__/!__WXMAC__ | |
c25f61f1 VZ |
2712 | { |
2713 | dc.SetPen( *wxBLACK_PEN ); | |
2714 | dc.SetBrush( *wxTRANSPARENT_BRUSH ); | |
2715 | dc.DrawRectangle( GetLineHighlightRect(m_current) ); | |
2716 | } | |
cf1dfa6b | 2717 | } |
c801d85f | 2718 | |
139adb6a | 2719 | dc.EndDrawing(); |
e1e955e1 | 2720 | } |
c801d85f | 2721 | |
b54e41c5 | 2722 | void wxListMainWindow::HighlightAll( bool on ) |
c801d85f | 2723 | { |
b54e41c5 | 2724 | if ( IsSingleSel() ) |
c801d85f | 2725 | { |
b54e41c5 VZ |
2726 | wxASSERT_MSG( !on, _T("can't do this in a single sel control") ); |
2727 | ||
2728 | // we just have one item to turn off | |
2729 | if ( HasCurrent() && IsHighlighted(m_current) ) | |
139adb6a | 2730 | { |
b54e41c5 VZ |
2731 | HighlightLine(m_current, FALSE); |
2732 | RefreshLine(m_current); | |
139adb6a | 2733 | } |
e1e955e1 | 2734 | } |
b54e41c5 | 2735 | else // multi sel |
cf1dfa6b | 2736 | { |
b54e41c5 | 2737 | HighlightLines(0, GetItemCount() - 1, on); |
cf1dfa6b | 2738 | } |
e1e955e1 | 2739 | } |
c801d85f | 2740 | |
cf1dfa6b | 2741 | void wxListMainWindow::SendNotify( size_t line, |
05a7f61d VZ |
2742 | wxEventType command, |
2743 | wxPoint point ) | |
c801d85f | 2744 | { |
139adb6a RR |
2745 | wxListEvent le( command, GetParent()->GetId() ); |
2746 | le.SetEventObject( GetParent() ); | |
cf1dfa6b | 2747 | le.m_itemIndex = line; |
05a7f61d VZ |
2748 | |
2749 | // set only for events which have position | |
2750 | if ( point != wxDefaultPosition ) | |
2751 | le.m_pointDrag = point; | |
2752 | ||
c1c4c551 VZ |
2753 | // don't try to get the line info for virtual list controls: the main |
2754 | // program has it anyhow and if we did it would result in accessing all | |
2755 | // the lines, even those which are not visible now and this is precisely | |
2756 | // what we're trying to avoid | |
2757 | if ( !IsVirtual() && (command != wxEVT_COMMAND_LIST_DELETE_ITEM) ) | |
91c6cc0e | 2758 | { |
0ddefeb0 VZ |
2759 | if ( line != (size_t)-1 ) |
2760 | { | |
2761 | GetLine(line)->GetItem( 0, le.m_item ); | |
2762 | } | |
2763 | //else: this happens for wxEVT_COMMAND_LIST_ITEM_FOCUSED event | |
91c6cc0e VZ |
2764 | } |
2765 | //else: there may be no more such item | |
2766 | ||
6e228e42 | 2767 | GetParent()->GetEventHandler()->ProcessEvent( le ); |
e1e955e1 | 2768 | } |
c801d85f | 2769 | |
0ddefeb0 | 2770 | void wxListMainWindow::ChangeCurrent(size_t current) |
c801d85f | 2771 | { |
0ddefeb0 | 2772 | m_current = current; |
c801d85f | 2773 | |
0ddefeb0 | 2774 | SendNotify(current, wxEVT_COMMAND_LIST_ITEM_FOCUSED); |
e1e955e1 | 2775 | } |
c801d85f | 2776 | |
5f1ea0ee | 2777 | void wxListMainWindow::EditLabel( long item ) |
c801d85f | 2778 | { |
cf1dfa6b | 2779 | wxCHECK_RET( (item >= 0) && ((size_t)item < GetItemCount()), |
3cd94a0d | 2780 | wxT("wrong index in wxGenericListCtrl::EditLabel()") ); |
004fd0c8 | 2781 | |
62d89eb4 | 2782 | size_t itemEdit = (size_t)item; |
e179bd65 | 2783 | |
fd9811b1 | 2784 | wxListEvent le( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT, GetParent()->GetId() ); |
139adb6a | 2785 | le.SetEventObject( GetParent() ); |
1370703e | 2786 | le.m_itemIndex = item; |
62d89eb4 | 2787 | wxListLineData *data = GetLine(itemEdit); |
1370703e VZ |
2788 | wxCHECK_RET( data, _T("invalid index in EditLabel()") ); |
2789 | data->GetItem( 0, le.m_item ); | |
62d89eb4 VZ |
2790 | if ( GetParent()->GetEventHandler()->ProcessEvent( le ) && !le.IsAllowed() ) |
2791 | { | |
2792 | // vetoed by user code | |
5f1ea0ee | 2793 | return; |
62d89eb4 | 2794 | } |
004fd0c8 | 2795 | |
cf1dfa6b VZ |
2796 | // We have to call this here because the label in question might just have |
2797 | // been added and no screen update taken place. | |
62d89eb4 | 2798 | if ( m_dirty ) |
cf1dfa6b | 2799 | wxSafeYield(); |
004fd0c8 | 2800 | |
62d89eb4 VZ |
2801 | wxListTextCtrl *text = new wxListTextCtrl(this, itemEdit); |
2802 | ||
92976ab6 | 2803 | text->SetFocus(); |
e1e955e1 | 2804 | } |
c801d85f | 2805 | |
e179bd65 RR |
2806 | void wxListMainWindow::OnRenameTimer() |
2807 | { | |
cf1dfa6b | 2808 | wxCHECK_RET( HasCurrent(), wxT("unexpected rename timer") ); |
004fd0c8 | 2809 | |
cf1dfa6b | 2810 | EditLabel( m_current ); |
e179bd65 RR |
2811 | } |
2812 | ||
62d89eb4 | 2813 | bool wxListMainWindow::OnRenameAccept(size_t itemEdit, const wxString& value) |
c801d85f | 2814 | { |
e179bd65 RR |
2815 | wxListEvent le( wxEVT_COMMAND_LIST_END_LABEL_EDIT, GetParent()->GetId() ); |
2816 | le.SetEventObject( GetParent() ); | |
62d89eb4 | 2817 | le.m_itemIndex = itemEdit; |
1370703e | 2818 | |
62d89eb4 VZ |
2819 | wxListLineData *data = GetLine(itemEdit); |
2820 | wxCHECK_MSG( data, FALSE, _T("invalid index in OnRenameAccept()") ); | |
1370703e VZ |
2821 | |
2822 | data->GetItem( 0, le.m_item ); | |
62d89eb4 VZ |
2823 | le.m_item.m_text = value; |
2824 | return !GetParent()->GetEventHandler()->ProcessEvent( le ) || | |
2825 | le.IsAllowed(); | |
e1e955e1 | 2826 | } |
c801d85f | 2827 | |
18dd54e3 | 2828 | void wxListMainWindow::OnRenameCancelled(size_t itemEdit) |
86586459 | 2829 | { |
86586459 RR |
2830 | // let owner know that the edit was cancelled |
2831 | wxListEvent le( wxEVT_COMMAND_LIST_END_LABEL_EDIT, GetParent()->GetId() ); | |
86351e4a | 2832 | |
d2ed74b9 | 2833 | le.SetEditCanceled(TRUE); |
86351e4a | 2834 | |
86586459 RR |
2835 | le.SetEventObject( GetParent() ); |
2836 | le.m_itemIndex = itemEdit; | |
2837 | ||
2838 | wxListLineData *data = GetLine(itemEdit); | |
2839 | wxCHECK_RET( data, _T("invalid index in OnRenameCancelled()") ); | |
2840 | ||
2841 | data->GetItem( 0, le.m_item ); | |
2842 | ||
2843 | GetEventHandler()->ProcessEvent( le ); | |
2844 | } | |
2845 | ||
c801d85f KB |
2846 | void wxListMainWindow::OnMouse( wxMouseEvent &event ) |
2847 | { | |
3e1c4e00 | 2848 | event.SetEventObject( GetParent() ); |
cf1dfa6b VZ |
2849 | if ( GetParent()->GetEventHandler()->ProcessEvent( event) ) |
2850 | return; | |
2851 | ||
2852 | if ( !HasCurrent() || IsEmpty() ) | |
2853 | return; | |
2854 | ||
2855 | if (m_dirty) | |
2856 | return; | |
e3e65dac | 2857 | |
cf1dfa6b VZ |
2858 | if ( !(event.Dragging() || event.ButtonDown() || event.LeftUp() || |
2859 | event.ButtonDClick()) ) | |
2860 | return; | |
c801d85f | 2861 | |
aaef15bf RR |
2862 | int x = event.GetX(); |
2863 | int y = event.GetY(); | |
2864 | CalcUnscrolledPosition( x, y, &x, &y ); | |
004fd0c8 | 2865 | |
cc734310 | 2866 | // where did we hit it (if we did)? |
92976ab6 | 2867 | long hitResult = 0; |
1370703e | 2868 | |
cf1dfa6b VZ |
2869 | size_t count = GetItemCount(), |
2870 | current; | |
2871 | ||
2872 | if ( HasFlag(wxLC_REPORT) ) | |
92976ab6 | 2873 | { |
5cd89174 | 2874 | current = y / GetLineHeight(); |
cc734310 VZ |
2875 | if ( current < count ) |
2876 | hitResult = HitTestLine(current, x, y); | |
cf1dfa6b VZ |
2877 | } |
2878 | else // !report | |
2879 | { | |
2880 | // TODO: optimize it too! this is less simple than for report view but | |
2881 | // enumerating all items is still not a way to do it!! | |
4e3ace65 | 2882 | for ( current = 0; current < count; current++ ) |
cf1dfa6b | 2883 | { |
5cd89174 | 2884 | hitResult = HitTestLine(current, x, y); |
4e3ace65 VZ |
2885 | if ( hitResult ) |
2886 | break; | |
cf1dfa6b | 2887 | } |
92976ab6 | 2888 | } |
bd8289c1 | 2889 | |
fd9811b1 | 2890 | if (event.Dragging()) |
92976ab6 | 2891 | { |
fd9811b1 | 2892 | if (m_dragCount == 0) |
8d1d2284 VZ |
2893 | { |
2894 | // we have to report the raw, physical coords as we want to be | |
2895 | // able to call HitTest(event.m_pointDrag) from the user code to | |
2896 | // get the item being dragged | |
2897 | m_dragStart = event.GetPosition(); | |
2898 | } | |
bffa1c77 | 2899 | |
fd9811b1 | 2900 | m_dragCount++; |
bffa1c77 | 2901 | |
cf1dfa6b VZ |
2902 | if (m_dragCount != 3) |
2903 | return; | |
bffa1c77 | 2904 | |
05a7f61d VZ |
2905 | int command = event.RightIsDown() ? wxEVT_COMMAND_LIST_BEGIN_RDRAG |
2906 | : wxEVT_COMMAND_LIST_BEGIN_DRAG; | |
bffa1c77 | 2907 | |
fd9811b1 | 2908 | wxListEvent le( command, GetParent()->GetId() ); |
92976ab6 | 2909 | le.SetEventObject( GetParent() ); |
e8c6a69c | 2910 | le.m_itemIndex = current; |
bffa1c77 VZ |
2911 | le.m_pointDrag = m_dragStart; |
2912 | GetParent()->GetEventHandler()->ProcessEvent( le ); | |
2913 | ||
2914 | return; | |
92976ab6 | 2915 | } |
fd9811b1 RR |
2916 | else |
2917 | { | |
2918 | m_dragCount = 0; | |
2919 | } | |
bd8289c1 | 2920 | |
cf1dfa6b VZ |
2921 | if ( !hitResult ) |
2922 | { | |
2923 | // outside of any item | |
2924 | return; | |
2925 | } | |
bd8289c1 | 2926 | |
efbb7287 | 2927 | bool forceClick = FALSE; |
92976ab6 RR |
2928 | if (event.ButtonDClick()) |
2929 | { | |
92976ab6 | 2930 | m_renameTimer->Stop(); |
efbb7287 VZ |
2931 | m_lastOnSame = FALSE; |
2932 | ||
ddba340d | 2933 | if ( current == m_lineLastClicked ) |
efbb7287 | 2934 | { |
cf1dfa6b | 2935 | SendNotify( current, wxEVT_COMMAND_LIST_ITEM_ACTIVATED ); |
004fd0c8 | 2936 | |
efbb7287 VZ |
2937 | return; |
2938 | } | |
2939 | else | |
2940 | { | |
2941 | // the first click was on another item, so don't interpret this as | |
2942 | // a double click, but as a simple click instead | |
2943 | forceClick = TRUE; | |
2944 | } | |
92976ab6 | 2945 | } |
bd8289c1 | 2946 | |
92976ab6 | 2947 | if (event.LeftUp() && m_lastOnSame) |
c801d85f | 2948 | { |
cf1dfa6b | 2949 | if ((current == m_current) && |
92976ab6 | 2950 | (hitResult == wxLIST_HITTEST_ONITEMLABEL) && |
cf1dfa6b | 2951 | HasFlag(wxLC_EDIT_LABELS) ) |
92976ab6 RR |
2952 | { |
2953 | m_renameTimer->Start( 100, TRUE ); | |
2954 | } | |
2955 | m_lastOnSame = FALSE; | |
e1e955e1 | 2956 | } |
cf1dfa6b | 2957 | else if (event.RightDown()) |
b204641e | 2958 | { |
cf1dfa6b | 2959 | SendNotify( current, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK, |
05a7f61d | 2960 | event.GetPosition() ); |
b204641e | 2961 | } |
cf1dfa6b | 2962 | else if (event.MiddleDown()) |
b204641e | 2963 | { |
cf1dfa6b | 2964 | SendNotify( current, wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK ); |
92976ab6 | 2965 | } |
cf1dfa6b | 2966 | else if ( event.LeftDown() || forceClick ) |
92976ab6 | 2967 | { |
efbb7287 | 2968 | m_lineBeforeLastClicked = m_lineLastClicked; |
cf1dfa6b VZ |
2969 | m_lineLastClicked = current; |
2970 | ||
2971 | size_t oldCurrent = m_current; | |
efbb7287 | 2972 | |
b54e41c5 | 2973 | if ( IsSingleSel() || !(event.ControlDown() || event.ShiftDown()) ) |
b204641e | 2974 | { |
b54e41c5 | 2975 | HighlightAll( FALSE ); |
0ddefeb0 VZ |
2976 | |
2977 | ChangeCurrent(current); | |
cf1dfa6b | 2978 | |
b54e41c5 | 2979 | ReverseHighlight(m_current); |
e1e955e1 | 2980 | } |
b54e41c5 | 2981 | else // multi sel & either ctrl or shift is down |
b204641e | 2982 | { |
473d087e | 2983 | if (event.ControlDown()) |
92976ab6 | 2984 | { |
0ddefeb0 | 2985 | ChangeCurrent(current); |
cf1dfa6b | 2986 | |
b54e41c5 | 2987 | ReverseHighlight(m_current); |
92976ab6 | 2988 | } |
473d087e | 2989 | else if (event.ShiftDown()) |
92976ab6 | 2990 | { |
0ddefeb0 | 2991 | ChangeCurrent(current); |
bffa1c77 | 2992 | |
cf1dfa6b VZ |
2993 | size_t lineFrom = oldCurrent, |
2994 | lineTo = current; | |
f6bcfd97 | 2995 | |
cf1dfa6b | 2996 | if ( lineTo < lineFrom ) |
92976ab6 | 2997 | { |
cf1dfa6b VZ |
2998 | lineTo = lineFrom; |
2999 | lineFrom = m_current; | |
92976ab6 RR |
3000 | } |
3001 | ||
b54e41c5 | 3002 | HighlightLines(lineFrom, lineTo); |
92976ab6 | 3003 | } |
cf1dfa6b | 3004 | else // !ctrl, !shift |
92976ab6 | 3005 | { |
cf1dfa6b VZ |
3006 | // test in the enclosing if should make it impossible |
3007 | wxFAIL_MSG( _T("how did we get here?") ); | |
92976ab6 | 3008 | } |
e1e955e1 | 3009 | } |
cf1dfa6b | 3010 | |
92976ab6 RR |
3011 | if (m_current != oldCurrent) |
3012 | { | |
3013 | RefreshLine( oldCurrent ); | |
92976ab6 | 3014 | } |
efbb7287 VZ |
3015 | |
3016 | // forceClick is only set if the previous click was on another item | |
3017 | m_lastOnSame = !forceClick && (m_current == oldCurrent); | |
e1e955e1 | 3018 | } |
e1e955e1 | 3019 | } |
c801d85f | 3020 | |
34bbbc27 | 3021 | void wxListMainWindow::MoveToItem(size_t item) |
c801d85f | 3022 | { |
34bbbc27 | 3023 | if ( item == (size_t)-1 ) |
cf1dfa6b | 3024 | return; |
004fd0c8 | 3025 | |
34bbbc27 | 3026 | wxRect rect = GetLineRect(item); |
cf3da716 | 3027 | |
cf1dfa6b | 3028 | int client_w, client_h; |
cf3da716 | 3029 | GetClientSize( &client_w, &client_h ); |
f6bcfd97 | 3030 | |
6d78bbe6 VZ |
3031 | const int hLine = GetLineHeight(); |
3032 | ||
13602ebd | 3033 | int view_x = SCROLL_UNIT_X*GetScrollPos( wxHORIZONTAL ); |
6d78bbe6 | 3034 | int view_y = hLine*GetScrollPos( wxVERTICAL ); |
004fd0c8 | 3035 | |
cf1dfa6b | 3036 | if ( HasFlag(wxLC_REPORT) ) |
92976ab6 | 3037 | { |
b54e41c5 VZ |
3038 | // the next we need the range of lines shown it might be different, so |
3039 | // recalculate it | |
3040 | ResetVisibleLinesRange(); | |
3041 | ||
cf1dfa6b | 3042 | if (rect.y < view_y ) |
6d78bbe6 | 3043 | Scroll( -1, rect.y/hLine ); |
cf1dfa6b | 3044 | if (rect.y+rect.height+5 > view_y+client_h) |
6d78bbe6 | 3045 | Scroll( -1, (rect.y+rect.height-client_h+hLine)/hLine ); |
92976ab6 | 3046 | } |
b54e41c5 | 3047 | else // !report |
92976ab6 | 3048 | { |
cf1dfa6b | 3049 | if (rect.x-view_x < 5) |
13602ebd | 3050 | Scroll( (rect.x-5)/SCROLL_UNIT_X, -1 ); |
cf1dfa6b | 3051 | if (rect.x+rect.width-5 > view_x+client_w) |
13602ebd | 3052 | Scroll( (rect.x+rect.width-client_w+SCROLL_UNIT_X)/SCROLL_UNIT_X, -1 ); |
92976ab6 | 3053 | } |
e1e955e1 | 3054 | } |
c801d85f | 3055 | |
cf1dfa6b VZ |
3056 | // ---------------------------------------------------------------------------- |
3057 | // keyboard handling | |
3058 | // ---------------------------------------------------------------------------- | |
3059 | ||
3060 | void wxListMainWindow::OnArrowChar(size_t newCurrent, const wxKeyEvent& event) | |
c801d85f | 3061 | { |
cf1dfa6b VZ |
3062 | wxCHECK_RET( newCurrent < (size_t)GetItemCount(), |
3063 | _T("invalid item index in OnArrowChar()") ); | |
3064 | ||
3065 | size_t oldCurrent = m_current; | |
3066 | ||
3067 | // in single selection we just ignore Shift as we can't select several | |
3068 | // items anyhow | |
b54e41c5 | 3069 | if ( event.ShiftDown() && !IsSingleSel() ) |
cf1dfa6b | 3070 | { |
0ddefeb0 | 3071 | ChangeCurrent(newCurrent); |
cf1dfa6b VZ |
3072 | |
3073 | // select all the items between the old and the new one | |
3074 | if ( oldCurrent > newCurrent ) | |
3075 | { | |
3076 | newCurrent = oldCurrent; | |
3077 | oldCurrent = m_current; | |
3078 | } | |
3079 | ||
b54e41c5 | 3080 | HighlightLines(oldCurrent, newCurrent); |
cf1dfa6b VZ |
3081 | } |
3082 | else // !shift | |
3083 | { | |
b54e41c5 VZ |
3084 | // all previously selected items are unselected unless ctrl is held |
3085 | if ( !event.ControlDown() ) | |
3086 | HighlightAll(FALSE); | |
3087 | ||
0ddefeb0 | 3088 | ChangeCurrent(newCurrent); |
cf1dfa6b | 3089 | |
58c1c096 | 3090 | // refresh the old focus to remove it |
cf1dfa6b VZ |
3091 | RefreshLine( oldCurrent ); |
3092 | ||
3093 | if ( !event.ControlDown() ) | |
3094 | { | |
b54e41c5 | 3095 | HighlightLine( m_current, TRUE ); |
cf1dfa6b VZ |
3096 | } |
3097 | } | |
3098 | ||
92976ab6 | 3099 | RefreshLine( m_current ); |
cf1dfa6b | 3100 | |
cf3da716 | 3101 | MoveToFocus(); |
e1e955e1 | 3102 | } |
c801d85f | 3103 | |
3dfb93fd RR |
3104 | void wxListMainWindow::OnKeyDown( wxKeyEvent &event ) |
3105 | { | |
3106 | wxWindow *parent = GetParent(); | |
004fd0c8 | 3107 | |
3dfb93fd RR |
3108 | /* we propagate the key event up */ |
3109 | wxKeyEvent ke( wxEVT_KEY_DOWN ); | |
3110 | ke.m_shiftDown = event.m_shiftDown; | |
3111 | ke.m_controlDown = event.m_controlDown; | |
3112 | ke.m_altDown = event.m_altDown; | |
3113 | ke.m_metaDown = event.m_metaDown; | |
3114 | ke.m_keyCode = event.m_keyCode; | |
3115 | ke.m_x = event.m_x; | |
3116 | ke.m_y = event.m_y; | |
3117 | ke.SetEventObject( parent ); | |
3118 | if (parent->GetEventHandler()->ProcessEvent( ke )) return; | |
004fd0c8 | 3119 | |
3dfb93fd RR |
3120 | event.Skip(); |
3121 | } | |
004fd0c8 | 3122 | |
c801d85f KB |
3123 | void wxListMainWindow::OnChar( wxKeyEvent &event ) |
3124 | { | |
51cc4dad | 3125 | wxWindow *parent = GetParent(); |
004fd0c8 | 3126 | |
51cc4dad | 3127 | /* we send a list_key event up */ |
cf1dfa6b | 3128 | if ( HasCurrent() ) |
f6bcfd97 BP |
3129 | { |
3130 | wxListEvent le( wxEVT_COMMAND_LIST_KEY_DOWN, GetParent()->GetId() ); | |
cf1dfa6b VZ |
3131 | le.m_itemIndex = m_current; |
3132 | GetLine(m_current)->GetItem( 0, le.m_item ); | |
12a3f227 | 3133 | le.m_code = event.GetKeyCode(); |
f6bcfd97 BP |
3134 | le.SetEventObject( parent ); |
3135 | parent->GetEventHandler()->ProcessEvent( le ); | |
3136 | } | |
51cc4dad | 3137 | |
3dfb93fd RR |
3138 | /* we propagate the char event up */ |
3139 | wxKeyEvent ke( wxEVT_CHAR ); | |
51cc4dad RR |
3140 | ke.m_shiftDown = event.m_shiftDown; |
3141 | ke.m_controlDown = event.m_controlDown; | |
3142 | ke.m_altDown = event.m_altDown; | |
3143 | ke.m_metaDown = event.m_metaDown; | |
3144 | ke.m_keyCode = event.m_keyCode; | |
3145 | ke.m_x = event.m_x; | |
3146 | ke.m_y = event.m_y; | |
3147 | ke.SetEventObject( parent ); | |
3148 | if (parent->GetEventHandler()->ProcessEvent( ke )) return; | |
004fd0c8 | 3149 | |
12a3f227 | 3150 | if (event.GetKeyCode() == WXK_TAB) |
012a03e0 RR |
3151 | { |
3152 | wxNavigationKeyEvent nevent; | |
c5145d41 | 3153 | nevent.SetWindowChange( event.ControlDown() ); |
012a03e0 | 3154 | nevent.SetDirection( !event.ShiftDown() ); |
8253c7fd | 3155 | nevent.SetEventObject( GetParent()->GetParent() ); |
012a03e0 | 3156 | nevent.SetCurrentFocus( m_parent ); |
87948f22 VZ |
3157 | if (GetParent()->GetParent()->GetEventHandler()->ProcessEvent( nevent )) |
3158 | return; | |
012a03e0 | 3159 | } |
004fd0c8 | 3160 | |
51cc4dad | 3161 | /* no item -> nothing to do */ |
cf1dfa6b | 3162 | if (!HasCurrent()) |
c801d85f | 3163 | { |
51cc4dad RR |
3164 | event.Skip(); |
3165 | return; | |
e1e955e1 | 3166 | } |
51cc4dad | 3167 | |
12a3f227 | 3168 | switch (event.GetKeyCode()) |
c801d85f | 3169 | { |
51cc4dad | 3170 | case WXK_UP: |
cf1dfa6b VZ |
3171 | if ( m_current > 0 ) |
3172 | OnArrowChar( m_current - 1, event ); | |
51cc4dad | 3173 | break; |
cf1dfa6b | 3174 | |
51cc4dad | 3175 | case WXK_DOWN: |
cf1dfa6b VZ |
3176 | if ( m_current < (size_t)GetItemCount() - 1 ) |
3177 | OnArrowChar( m_current + 1, event ); | |
51cc4dad | 3178 | break; |
cf1dfa6b | 3179 | |
51cc4dad | 3180 | case WXK_END: |
1370703e | 3181 | if (!IsEmpty()) |
cf1dfa6b | 3182 | OnArrowChar( GetItemCount() - 1, event ); |
51cc4dad | 3183 | break; |
cf1dfa6b | 3184 | |
51cc4dad | 3185 | case WXK_HOME: |
1370703e | 3186 | if (!IsEmpty()) |
cf1dfa6b | 3187 | OnArrowChar( 0, event ); |
51cc4dad | 3188 | break; |
cf1dfa6b | 3189 | |
51cc4dad | 3190 | case WXK_PRIOR: |
f6bcfd97 | 3191 | { |
999836aa | 3192 | int steps = HasFlag(wxLC_REPORT) ? m_linesPerPage - 1 : m_current % m_linesPerPage; |
cf1dfa6b VZ |
3193 | |
3194 | int index = m_current - steps; | |
3195 | if (index < 0) | |
3196 | index = 0; | |
3197 | ||
3198 | OnArrowChar( index, event ); | |
51cc4dad | 3199 | } |
51cc4dad | 3200 | break; |
cf1dfa6b | 3201 | |
51cc4dad | 3202 | case WXK_NEXT: |
bffa1c77 | 3203 | { |
999836aa VZ |
3204 | int steps = HasFlag(wxLC_REPORT) |
3205 | ? m_linesPerPage - 1 | |
3206 | : m_linesPerPage - (m_current % m_linesPerPage) - 1; | |
f6bcfd97 | 3207 | |
cf1dfa6b VZ |
3208 | size_t index = m_current + steps; |
3209 | size_t count = GetItemCount(); | |
3210 | if ( index >= count ) | |
3211 | index = count - 1; | |
3212 | ||
3213 | OnArrowChar( index, event ); | |
51cc4dad | 3214 | } |
51cc4dad | 3215 | break; |
cf1dfa6b | 3216 | |
51cc4dad | 3217 | case WXK_LEFT: |
cf1dfa6b | 3218 | if ( !HasFlag(wxLC_REPORT) ) |
51cc4dad | 3219 | { |
cf1dfa6b VZ |
3220 | int index = m_current - m_linesPerPage; |
3221 | if (index < 0) | |
3222 | index = 0; | |
3223 | ||
3224 | OnArrowChar( index, event ); | |
51cc4dad RR |
3225 | } |
3226 | break; | |
cf1dfa6b | 3227 | |
51cc4dad | 3228 | case WXK_RIGHT: |
cf1dfa6b | 3229 | if ( !HasFlag(wxLC_REPORT) ) |
51cc4dad | 3230 | { |
cf1dfa6b VZ |
3231 | size_t index = m_current + m_linesPerPage; |
3232 | ||
3233 | size_t count = GetItemCount(); | |
3234 | if ( index >= count ) | |
3235 | index = count - 1; | |
3236 | ||
3237 | OnArrowChar( index, event ); | |
51cc4dad RR |
3238 | } |
3239 | break; | |
cf1dfa6b | 3240 | |
51cc4dad | 3241 | case WXK_SPACE: |
b54e41c5 | 3242 | if ( IsSingleSel() ) |
33d0e17c | 3243 | { |
87948f22 | 3244 | SendNotify( m_current, wxEVT_COMMAND_LIST_ITEM_ACTIVATED ); |
70541533 VZ |
3245 | |
3246 | if ( IsHighlighted(m_current) ) | |
3247 | { | |
3248 | // don't unselect the item in single selection mode | |
3249 | break; | |
3250 | } | |
3251 | //else: select it in ReverseHighlight() below if unselected | |
33d0e17c | 3252 | } |
70541533 VZ |
3253 | |
3254 | ReverseHighlight(m_current); | |
51cc4dad | 3255 | break; |
cf1dfa6b | 3256 | |
51cc4dad RR |
3257 | case WXK_RETURN: |
3258 | case WXK_EXECUTE: | |
87948f22 | 3259 | SendNotify( m_current, wxEVT_COMMAND_LIST_ITEM_ACTIVATED ); |
51cc4dad | 3260 | break; |
cf1dfa6b | 3261 | |
51cc4dad | 3262 | default: |
51cc4dad | 3263 | event.Skip(); |
e1e955e1 | 3264 | } |
e1e955e1 | 3265 | } |
c801d85f | 3266 | |
cf1dfa6b VZ |
3267 | // ---------------------------------------------------------------------------- |
3268 | // focus handling | |
3269 | // ---------------------------------------------------------------------------- | |
3270 | ||
a6d57d03 VS |
3271 | void wxListMainWindow::SetFocus() |
3272 | { | |
3273 | // VS: wxListMainWindow derives from wxPanel (via wxScrolledWindow) and wxPanel | |
a77ec46d | 3274 | // overrides SetFocus in such way that it does never change focus from |
a6d57d03 | 3275 | // panel's child to the panel itself. Unfortunately, we must be able to change |
a77ec46d | 3276 | // focus to the panel from wxListTextCtrl because the text control should |
a6d57d03 VS |
3277 | // disappear when the user clicks outside it. |
3278 | ||
3279 | wxWindow *oldFocus = FindFocus(); | |
a77ec46d | 3280 | |
072da98f | 3281 | if ( oldFocus && oldFocus->GetParent() == this ) |
a6d57d03 VS |
3282 | { |
3283 | wxWindow::SetFocus(); | |
3284 | } | |
3285 | else | |
3286 | { | |
3287 | wxScrolledWindow::SetFocus(); | |
3288 | } | |
3289 | } | |
3290 | ||
c801d85f KB |
3291 | void wxListMainWindow::OnSetFocus( wxFocusEvent &WXUNUSED(event) ) |
3292 | { | |
dc76287d RD |
3293 | if ( GetParent() ) |
3294 | { | |
3295 | wxFocusEvent event( wxEVT_SET_FOCUS, GetParent()->GetId() ); | |
3296 | event.SetEventObject( GetParent() ); | |
3297 | if ( GetParent()->GetEventHandler()->ProcessEvent( event) ) | |
3298 | return; | |
3299 | } | |
3300 | ||
bde9072f VZ |
3301 | // wxGTK sends us EVT_SET_FOCUS events even if we had never got |
3302 | // EVT_KILL_FOCUS before which means that we finish by redrawing the items | |
3303 | // which are already drawn correctly resulting in horrible flicker - avoid | |
3304 | // it | |
47724389 VZ |
3305 | if ( !m_hasFocus ) |
3306 | { | |
3307 | m_hasFocus = TRUE; | |
bde9072f | 3308 | |
47724389 VZ |
3309 | RefreshSelected(); |
3310 | } | |
e1e955e1 | 3311 | } |
c801d85f KB |
3312 | |
3313 | void wxListMainWindow::OnKillFocus( wxFocusEvent &WXUNUSED(event) ) | |
3314 | { | |
dc76287d RD |
3315 | if ( GetParent() ) |
3316 | { | |
3317 | wxFocusEvent event( wxEVT_KILL_FOCUS, GetParent()->GetId() ); | |
3318 | event.SetEventObject( GetParent() ); | |
3319 | if ( GetParent()->GetEventHandler()->ProcessEvent( event) ) | |
3320 | return; | |
3321 | } | |
63852e78 | 3322 | m_hasFocus = FALSE; |
49ecb029 | 3323 | RefreshSelected(); |
e1e955e1 | 3324 | } |
c801d85f | 3325 | |
1e6d9499 | 3326 | void wxListMainWindow::DrawImage( int index, wxDC *dc, int x, int y ) |
c801d85f | 3327 | { |
cf1dfa6b | 3328 | if ( HasFlag(wxLC_ICON) && (m_normal_image_list)) |
63852e78 RR |
3329 | { |
3330 | m_normal_image_list->Draw( index, *dc, x, y, wxIMAGELIST_DRAW_TRANSPARENT ); | |
63852e78 | 3331 | } |
cf1dfa6b | 3332 | else if ( HasFlag(wxLC_SMALL_ICON) && (m_small_image_list)) |
63852e78 RR |
3333 | { |
3334 | m_small_image_list->Draw( index, *dc, x, y, wxIMAGELIST_DRAW_TRANSPARENT ); | |
3335 | } | |
cf1dfa6b | 3336 | else if ( HasFlag(wxLC_LIST) && (m_small_image_list)) |
0b855868 RR |
3337 | { |
3338 | m_small_image_list->Draw( index, *dc, x, y, wxIMAGELIST_DRAW_TRANSPARENT ); | |
3339 | } | |
cf1dfa6b | 3340 | else if ( HasFlag(wxLC_REPORT) && (m_small_image_list)) |
63852e78 RR |
3341 | { |
3342 | m_small_image_list->Draw( index, *dc, x, y, wxIMAGELIST_DRAW_TRANSPARENT ); | |
63852e78 | 3343 | } |
e1e955e1 | 3344 | } |
c801d85f | 3345 | |
5cd89174 | 3346 | void wxListMainWindow::GetImageSize( int index, int &width, int &height ) const |
c801d85f | 3347 | { |
cf1dfa6b | 3348 | if ( HasFlag(wxLC_ICON) && m_normal_image_list ) |
63852e78 RR |
3349 | { |
3350 | m_normal_image_list->GetSize( index, width, height ); | |
63852e78 | 3351 | } |
cf1dfa6b | 3352 | else if ( HasFlag(wxLC_SMALL_ICON) && m_small_image_list ) |
63852e78 RR |
3353 | { |
3354 | m_small_image_list->GetSize( index, width, height ); | |
63852e78 | 3355 | } |
cf1dfa6b | 3356 | else if ( HasFlag(wxLC_LIST) && m_small_image_list ) |
0b855868 RR |
3357 | { |
3358 | m_small_image_list->GetSize( index, width, height ); | |
0b855868 | 3359 | } |
cf1dfa6b | 3360 | else if ( HasFlag(wxLC_REPORT) && m_small_image_list ) |
63852e78 RR |
3361 | { |
3362 | m_small_image_list->GetSize( index, width, height ); | |
63852e78 | 3363 | } |
cf1dfa6b VZ |
3364 | else |
3365 | { | |
3366 | width = | |
3367 | height = 0; | |
3368 | } | |
e1e955e1 | 3369 | } |
c801d85f | 3370 | |
5cd89174 | 3371 | int wxListMainWindow::GetTextLength( const wxString &s ) const |
c801d85f | 3372 | { |
5cd89174 | 3373 | wxClientDC dc( wxConstCast(this, wxListMainWindow) ); |
cf1dfa6b | 3374 | dc.SetFont( GetFont() ); |
c801d85f | 3375 | |
cf1dfa6b VZ |
3376 | wxCoord lw; |
3377 | dc.GetTextExtent( s, &lw, NULL ); | |
3378 | ||
3379 | return lw + AUTOSIZE_COL_MARGIN; | |
e1e955e1 | 3380 | } |
c801d85f | 3381 | |
80020b62 | 3382 | void wxListMainWindow::SetImageList( wxImageListType *imageList, int which ) |
c801d85f | 3383 | { |
139adb6a | 3384 | m_dirty = TRUE; |
f6bcfd97 BP |
3385 | |
3386 | // calc the spacing from the icon size | |
3387 | int width = 0, | |
3388 | height = 0; | |
3389 | if ((imageList) && (imageList->GetImageCount()) ) | |
3390 | { | |
3391 | imageList->GetSize(0, width, height); | |
3392 | } | |
3393 | ||
3394 | if (which == wxIMAGE_LIST_NORMAL) | |
3395 | { | |
3396 | m_normal_image_list = imageList; | |
3397 | m_normal_spacing = width + 8; | |
3398 | } | |
3399 | ||
3400 | if (which == wxIMAGE_LIST_SMALL) | |
3401 | { | |
3402 | m_small_image_list = imageList; | |
3403 | m_small_spacing = width + 14; | |
ca7353de | 3404 | m_lineHeight = 0; // ensure that the line height will be recalc'd |
f6bcfd97 | 3405 | } |
e1e955e1 | 3406 | } |
c801d85f | 3407 | |
debe6624 | 3408 | void wxListMainWindow::SetItemSpacing( int spacing, bool isSmall ) |
c801d85f | 3409 | { |
139adb6a RR |
3410 | m_dirty = TRUE; |
3411 | if (isSmall) | |
3412 | { | |
3413 | m_small_spacing = spacing; | |
3414 | } | |
3415 | else | |
3416 | { | |
3417 | m_normal_spacing = spacing; | |
3418 | } | |
e1e955e1 | 3419 | } |
c801d85f | 3420 | |
debe6624 | 3421 | int wxListMainWindow::GetItemSpacing( bool isSmall ) |
c801d85f | 3422 | { |
f6bcfd97 | 3423 | return isSmall ? m_small_spacing : m_normal_spacing; |
e1e955e1 | 3424 | } |
c801d85f | 3425 | |
cf1dfa6b VZ |
3426 | // ---------------------------------------------------------------------------- |
3427 | // columns | |
3428 | // ---------------------------------------------------------------------------- | |
3429 | ||
debe6624 | 3430 | void wxListMainWindow::SetColumn( int col, wxListItem &item ) |
c801d85f | 3431 | { |
222ed1d6 | 3432 | wxListHeaderDataList::compatibility_iterator node = m_columns.Item( col ); |
f6bcfd97 | 3433 | |
cf1dfa6b VZ |
3434 | wxCHECK_RET( node, _T("invalid column index in SetColumn") ); |
3435 | ||
3436 | if ( item.m_width == wxLIST_AUTOSIZE_USEHEADER ) | |
3437 | item.m_width = GetTextLength( item.m_text ); | |
3438 | ||
3439 | wxListHeaderData *column = node->GetData(); | |
3440 | column->SetItem( item ); | |
3441 | ||
3442 | wxListHeaderWindow *headerWin = GetListCtrl()->m_headerWin; | |
f6bcfd97 BP |
3443 | if ( headerWin ) |
3444 | headerWin->m_dirty = TRUE; | |
cf1dfa6b VZ |
3445 | |
3446 | m_dirty = TRUE; | |
3447 | ||
3448 | // invalidate it as it has to be recalculated | |
3449 | m_headerWidth = 0; | |
e1e955e1 | 3450 | } |
c801d85f | 3451 | |
debe6624 | 3452 | void wxListMainWindow::SetColumnWidth( int col, int width ) |
c801d85f | 3453 | { |
cf1dfa6b VZ |
3454 | wxCHECK_RET( col >= 0 && col < GetColumnCount(), |
3455 | _T("invalid column index") ); | |
3456 | ||
3457 | wxCHECK_RET( HasFlag(wxLC_REPORT), | |
f6bcfd97 | 3458 | _T("SetColumnWidth() can only be called in report mode.") ); |
0208334d | 3459 | |
63852e78 | 3460 | m_dirty = TRUE; |
abe4a4f1 VS |
3461 | wxListHeaderWindow *headerWin = GetListCtrl()->m_headerWin; |
3462 | if ( headerWin ) | |
3463 | headerWin->m_dirty = TRUE; | |
bd8289c1 | 3464 | |
222ed1d6 | 3465 | wxListHeaderDataList::compatibility_iterator node = m_columns.Item( col ); |
cf1dfa6b VZ |
3466 | wxCHECK_RET( node, _T("no column?") ); |
3467 | ||
3468 | wxListHeaderData *column = node->GetData(); | |
3469 | ||
3470 | size_t count = GetItemCount(); | |
3471 | ||
f6bcfd97 BP |
3472 | if (width == wxLIST_AUTOSIZE_USEHEADER) |
3473 | { | |
cf1dfa6b | 3474 | width = GetTextLength(column->GetText()); |
f6bcfd97 | 3475 | } |
cf1dfa6b | 3476 | else if ( width == wxLIST_AUTOSIZE ) |
0180dad6 | 3477 | { |
cf1dfa6b VZ |
3478 | if ( IsVirtual() ) |
3479 | { | |
3480 | // TODO: determine the max width somehow... | |
3481 | width = WIDTH_COL_DEFAULT; | |
3482 | } | |
3483 | else // !virtual | |
0180dad6 | 3484 | { |
cf1dfa6b VZ |
3485 | wxClientDC dc(this); |
3486 | dc.SetFont( GetFont() ); | |
3487 | ||
3488 | int max = AUTOSIZE_COL_MARGIN; | |
3489 | ||
3490 | for ( size_t i = 0; i < count; i++ ) | |
0180dad6 | 3491 | { |
cf1dfa6b | 3492 | wxListLineData *line = GetLine(i); |
222ed1d6 | 3493 | wxListItemDataList::compatibility_iterator n = line->m_items.Item( col ); |
cf1dfa6b VZ |
3494 | |
3495 | wxCHECK_RET( n, _T("no subitem?") ); | |
3496 | ||
2c1f73ee | 3497 | wxListItemData *item = n->GetData(); |
cf1dfa6b VZ |
3498 | int current = 0; |
3499 | ||
bffa1c77 VZ |
3500 | if (item->HasImage()) |
3501 | { | |
cf1dfa6b | 3502 | int ix, iy; |
0180dad6 | 3503 | GetImageSize( item->GetImage(), ix, iy ); |
cf1dfa6b | 3504 | current += ix + 5; |
bffa1c77 | 3505 | } |
cf1dfa6b | 3506 | |
bffa1c77 VZ |
3507 | if (item->HasText()) |
3508 | { | |
cf1dfa6b VZ |
3509 | wxCoord w; |
3510 | dc.GetTextExtent( item->GetText(), &w, NULL ); | |
3511 | current += w; | |
bffa1c77 | 3512 | } |
cf1dfa6b | 3513 | |
2c1f73ee VZ |
3514 | if (current > max) |
3515 | max = current; | |
0180dad6 | 3516 | } |
cf1dfa6b VZ |
3517 | |
3518 | width = max + AUTOSIZE_COL_MARGIN; | |
0180dad6 | 3519 | } |
0180dad6 RR |
3520 | } |
3521 | ||
cf1dfa6b | 3522 | column->SetWidth( width ); |
bd8289c1 | 3523 | |
cf1dfa6b VZ |
3524 | // invalidate it as it has to be recalculated |
3525 | m_headerWidth = 0; | |
3526 | } | |
3527 | ||
3528 | int wxListMainWindow::GetHeaderWidth() const | |
3529 | { | |
3530 | if ( !m_headerWidth ) | |
0208334d | 3531 | { |
cf1dfa6b VZ |
3532 | wxListMainWindow *self = wxConstCast(this, wxListMainWindow); |
3533 | ||
3534 | size_t count = GetColumnCount(); | |
3535 | for ( size_t col = 0; col < count; col++ ) | |
63852e78 | 3536 | { |
cf1dfa6b | 3537 | self->m_headerWidth += GetColumnWidth(col); |
63852e78 | 3538 | } |
0208334d | 3539 | } |
bd8289c1 | 3540 | |
cf1dfa6b | 3541 | return m_headerWidth; |
e1e955e1 | 3542 | } |
c801d85f | 3543 | |
cf1dfa6b | 3544 | void wxListMainWindow::GetColumn( int col, wxListItem &item ) const |
c801d85f | 3545 | { |
222ed1d6 | 3546 | wxListHeaderDataList::compatibility_iterator node = m_columns.Item( col ); |
cf1dfa6b VZ |
3547 | wxCHECK_RET( node, _T("invalid column index in GetColumn") ); |
3548 | ||
3549 | wxListHeaderData *column = node->GetData(); | |
3550 | column->GetItem( item ); | |
e1e955e1 | 3551 | } |
c801d85f | 3552 | |
cf1dfa6b | 3553 | int wxListMainWindow::GetColumnWidth( int col ) const |
c801d85f | 3554 | { |
222ed1d6 | 3555 | wxListHeaderDataList::compatibility_iterator node = m_columns.Item( col ); |
24b9f055 VZ |
3556 | wxCHECK_MSG( node, 0, _T("invalid column index") ); |
3557 | ||
3558 | wxListHeaderData *column = node->GetData(); | |
3559 | return column->GetWidth(); | |
e1e955e1 | 3560 | } |
c801d85f | 3561 | |
cf1dfa6b VZ |
3562 | // ---------------------------------------------------------------------------- |
3563 | // item state | |
3564 | // ---------------------------------------------------------------------------- | |
c801d85f KB |
3565 | |
3566 | void wxListMainWindow::SetItem( wxListItem &item ) | |
3567 | { | |
cf1dfa6b VZ |
3568 | long id = item.m_itemId; |
3569 | wxCHECK_RET( id >= 0 && (size_t)id < GetItemCount(), | |
3570 | _T("invalid item index in SetItem") ); | |
3571 | ||
6c02c329 VZ |
3572 | if ( !IsVirtual() ) |
3573 | { | |
3574 | wxListLineData *line = GetLine((size_t)id); | |
3575 | line->SetItem( item.m_col, item ); | |
3576 | } | |
3577 | ||
285013b3 VZ |
3578 | // update the item on screen |
3579 | wxRect rectItem; | |
3580 | GetItemRect(id, rectItem); | |
3581 | RefreshRect(rectItem); | |
e1e955e1 | 3582 | } |
c801d85f | 3583 | |
cf1dfa6b | 3584 | void wxListMainWindow::SetItemState( long litem, long state, long stateMask ) |
c801d85f | 3585 | { |
cf1dfa6b | 3586 | wxCHECK_RET( litem >= 0 && (size_t)litem < GetItemCount(), |
54442116 VZ |
3587 | _T("invalid list ctrl item index in SetItem") ); |
3588 | ||
cf1dfa6b | 3589 | size_t oldCurrent = m_current; |
88b792af | 3590 | size_t item = (size_t)litem; // safe because of the check above |
bd8289c1 | 3591 | |
88b792af | 3592 | // do we need to change the focus? |
54442116 | 3593 | if ( stateMask & wxLIST_STATE_FOCUSED ) |
c801d85f | 3594 | { |
54442116 | 3595 | if ( state & wxLIST_STATE_FOCUSED ) |
92976ab6 | 3596 | { |
54442116 | 3597 | // don't do anything if this item is already focused |
cf1dfa6b | 3598 | if ( item != m_current ) |
92976ab6 | 3599 | { |
0ddefeb0 | 3600 | ChangeCurrent(item); |
cf1dfa6b | 3601 | |
88b792af | 3602 | if ( oldCurrent != (size_t)-1 ) |
cf1dfa6b | 3603 | { |
88b792af VZ |
3604 | if ( IsSingleSel() ) |
3605 | { | |
3606 | HighlightLine(oldCurrent, FALSE); | |
3607 | } | |
3608 | ||
cf1dfa6b VZ |
3609 | RefreshLine(oldCurrent); |
3610 | } | |
54442116 | 3611 | |
92976ab6 | 3612 | RefreshLine( m_current ); |
92976ab6 | 3613 | } |
54442116 VZ |
3614 | } |
3615 | else // unfocus | |
3616 | { | |
3617 | // don't do anything if this item is not focused | |
cf1dfa6b | 3618 | if ( item == m_current ) |
bffa1c77 | 3619 | { |
0ddefeb0 | 3620 | ResetCurrent(); |
88b792af | 3621 | |
943f6ad3 VZ |
3622 | if ( IsSingleSel() ) |
3623 | { | |
3624 | // we must unselect the old current item as well or we | |
3625 | // might end up with more than one selected item in a | |
3626 | // single selection control | |
3627 | HighlightLine(oldCurrent, FALSE); | |
3628 | } | |
3629 | ||
88b792af | 3630 | RefreshLine( oldCurrent ); |
bffa1c77 | 3631 | } |
92976ab6 | 3632 | } |
e1e955e1 | 3633 | } |
54442116 | 3634 | |
88b792af | 3635 | // do we need to change the selection state? |
54442116 VZ |
3636 | if ( stateMask & wxLIST_STATE_SELECTED ) |
3637 | { | |
3638 | bool on = (state & wxLIST_STATE_SELECTED) != 0; | |
54442116 | 3639 | |
b54e41c5 | 3640 | if ( IsSingleSel() ) |
54442116 | 3641 | { |
cf1dfa6b VZ |
3642 | if ( on ) |
3643 | { | |
3644 | // selecting the item also makes it the focused one in the | |
3645 | // single sel mode | |
3646 | if ( m_current != item ) | |
3647 | { | |
0ddefeb0 | 3648 | ChangeCurrent(item); |
cf1dfa6b VZ |
3649 | |
3650 | if ( oldCurrent != (size_t)-1 ) | |
3651 | { | |
b54e41c5 | 3652 | HighlightLine( oldCurrent, FALSE ); |
cf1dfa6b VZ |
3653 | RefreshLine( oldCurrent ); |
3654 | } | |
3655 | } | |
3656 | } | |
3657 | else // off | |
3658 | { | |
3659 | // only the current item may be selected anyhow | |
3660 | if ( item != m_current ) | |
3661 | return; | |
3662 | } | |
54442116 VZ |
3663 | } |
3664 | ||
b54e41c5 | 3665 | if ( HighlightLine(item, on) ) |
54442116 | 3666 | { |
cf1dfa6b | 3667 | RefreshLine(item); |
54442116 VZ |
3668 | } |
3669 | } | |
e1e955e1 | 3670 | } |
c801d85f | 3671 | |
62d89eb4 | 3672 | int wxListMainWindow::GetItemState( long item, long stateMask ) const |
c801d85f | 3673 | { |
cf1dfa6b VZ |
3674 | wxCHECK_MSG( item >= 0 && (size_t)item < GetItemCount(), 0, |
3675 | _T("invalid list ctrl item index in GetItemState()") ); | |
3676 | ||
92976ab6 | 3677 | int ret = wxLIST_STATE_DONTCARE; |
cf1dfa6b VZ |
3678 | |
3679 | if ( stateMask & wxLIST_STATE_FOCUSED ) | |
c801d85f | 3680 | { |
cf1dfa6b VZ |
3681 | if ( (size_t)item == m_current ) |
3682 | ret |= wxLIST_STATE_FOCUSED; | |
e1e955e1 | 3683 | } |
cf1dfa6b VZ |
3684 | |
3685 | if ( stateMask & wxLIST_STATE_SELECTED ) | |
c801d85f | 3686 | { |
b54e41c5 | 3687 | if ( IsHighlighted(item) ) |
cf1dfa6b | 3688 | ret |= wxLIST_STATE_SELECTED; |
e1e955e1 | 3689 | } |
cf1dfa6b | 3690 | |
92976ab6 | 3691 | return ret; |
e1e955e1 | 3692 | } |
c801d85f | 3693 | |
62d89eb4 | 3694 | void wxListMainWindow::GetItem( wxListItem &item ) const |
c801d85f | 3695 | { |
cf1dfa6b VZ |
3696 | wxCHECK_RET( item.m_itemId >= 0 && (size_t)item.m_itemId < GetItemCount(), |
3697 | _T("invalid item index in GetItem") ); | |
3698 | ||
3699 | wxListLineData *line = GetLine((size_t)item.m_itemId); | |
3700 | line->GetItem( item.m_col, item ); | |
e1e955e1 | 3701 | } |
c801d85f | 3702 | |
cf1dfa6b VZ |
3703 | // ---------------------------------------------------------------------------- |
3704 | // item count | |
3705 | // ---------------------------------------------------------------------------- | |
3706 | ||
3707 | size_t wxListMainWindow::GetItemCount() const | |
1370703e VZ |
3708 | { |
3709 | return IsVirtual() ? m_countVirt : m_lines.GetCount(); | |
3710 | } | |
3711 | ||
3712 | void wxListMainWindow::SetItemCount(long count) | |
c801d85f | 3713 | { |
b54e41c5 | 3714 | m_selStore.SetItemCount(count); |
1370703e VZ |
3715 | m_countVirt = count; |
3716 | ||
850ed6e7 VZ |
3717 | ResetVisibleLinesRange(); |
3718 | ||
5fe143df VZ |
3719 | // scrollbars must be reset |
3720 | m_dirty = TRUE; | |
e1e955e1 | 3721 | } |
c801d85f | 3722 | |
62d89eb4 | 3723 | int wxListMainWindow::GetSelectedItemCount() const |
c801d85f | 3724 | { |
cf1dfa6b | 3725 | // deal with the quick case first |
b54e41c5 | 3726 | if ( IsSingleSel() ) |
92976ab6 | 3727 | { |
b54e41c5 | 3728 | return HasCurrent() ? IsHighlighted(m_current) : FALSE; |
92976ab6 | 3729 | } |
cf1dfa6b VZ |
3730 | |
3731 | // virtual controls remmebers all its selections itself | |
3732 | if ( IsVirtual() ) | |
b54e41c5 | 3733 | return m_selStore.GetSelectedCount(); |
cf1dfa6b VZ |
3734 | |
3735 | // TODO: we probably should maintain the number of items selected even for | |
3736 | // non virtual controls as enumerating all lines is really slow... | |
3737 | size_t countSel = 0; | |
3738 | size_t count = GetItemCount(); | |
3739 | for ( size_t line = 0; line < count; line++ ) | |
92976ab6 | 3740 | { |
b54e41c5 | 3741 | if ( GetLine(line)->IsHighlighted() ) |
cf1dfa6b | 3742 | countSel++; |
92976ab6 | 3743 | } |
c801d85f | 3744 | |
cf1dfa6b | 3745 | return countSel; |
e1e955e1 | 3746 | } |
e3e65dac | 3747 | |
cf1dfa6b VZ |
3748 | // ---------------------------------------------------------------------------- |
3749 | // item position/size | |
3750 | // ---------------------------------------------------------------------------- | |
3751 | ||
11ebea16 VZ |
3752 | wxRect wxListMainWindow::GetViewRect() const |
3753 | { | |
3754 | wxASSERT_MSG( !HasFlag(wxLC_REPORT | wxLC_LIST), | |
3755 | _T("wxListCtrl::GetViewRect() only works in icon mode") ); | |
3756 | ||
3757 | // we need to find the longest/tallest label | |
3758 | wxCoord xMax = 0, | |
3759 | yMax = 0; | |
3760 | const int count = GetItemCount(); | |
3761 | if ( count ) | |
3762 | { | |
3763 | for ( int i = 0; i < count; i++ ) | |
3764 | { | |
3765 | wxRect r; | |
3766 | GetItemRect(i, r); | |
3767 | ||
3768 | wxCoord x = r.GetRight(), | |
3769 | y = r.GetBottom(); | |
3770 | ||
3771 | if ( x > xMax ) | |
3772 | xMax = x; | |
3773 | if ( y > yMax ) | |
3774 | yMax = y; | |
3775 | } | |
3776 | } | |
3777 | ||
eb6c4508 | 3778 | // some fudge needed to make it look prettier |
13602ebd VZ |
3779 | xMax += 2*EXTRA_BORDER_X; |
3780 | yMax += 2*EXTRA_BORDER_Y; | |
eb6c4508 VZ |
3781 | |
3782 | // account for the scrollbars if necessary | |
3783 | const wxSize sizeAll = GetClientSize(); | |
3784 | if ( xMax > sizeAll.x ) | |
3785 | yMax += wxSystemSettings::GetMetric(wxSYS_HSCROLL_Y); | |
3786 | if ( yMax > sizeAll.y ) | |
3787 | xMax += wxSystemSettings::GetMetric(wxSYS_VSCROLL_X); | |
11ebea16 VZ |
3788 | |
3789 | return wxRect(0, 0, xMax, yMax); | |
3790 | } | |
3791 | ||
62d89eb4 | 3792 | void wxListMainWindow::GetItemRect( long index, wxRect &rect ) const |
c801d85f | 3793 | { |
cf1dfa6b VZ |
3794 | wxCHECK_RET( index >= 0 && (size_t)index < GetItemCount(), |
3795 | _T("invalid index in GetItemRect") ); | |
3796 | ||
1e54be64 VZ |
3797 | // ensure that we're laid out, otherwise we could return nonsense |
3798 | if ( m_dirty ) | |
3799 | { | |
3800 | wxConstCast(this, wxListMainWindow)-> | |
3801 | RecalculatePositions(TRUE /* no refresh */); | |
3802 | } | |
3803 | ||
5cd89174 | 3804 | rect = GetLineRect((size_t)index); |
b54e41c5 | 3805 | |
cf1dfa6b | 3806 | CalcScrolledPosition(rect.x, rect.y, &rect.x, &rect.y); |
e1e955e1 | 3807 | } |
c801d85f | 3808 | |
62d89eb4 | 3809 | bool wxListMainWindow::GetItemPosition(long item, wxPoint& pos) const |
c801d85f | 3810 | { |
cf1dfa6b VZ |
3811 | wxRect rect; |
3812 | GetItemRect(item, rect); | |
bd8289c1 | 3813 | |
cf1dfa6b VZ |
3814 | pos.x = rect.x; |
3815 | pos.y = rect.y; | |
bd8289c1 | 3816 | |
cf1dfa6b | 3817 | return TRUE; |
e1e955e1 | 3818 | } |
c801d85f | 3819 | |
cf1dfa6b VZ |
3820 | // ---------------------------------------------------------------------------- |
3821 | // geometry calculation | |
3822 | // ---------------------------------------------------------------------------- | |
3823 | ||
34bbbc27 | 3824 | void wxListMainWindow::RecalculatePositions(bool noRefresh) |
c801d85f | 3825 | { |
1e6d9499 | 3826 | wxClientDC dc( this ); |
92976ab6 | 3827 | dc.SetFont( GetFont() ); |
c801d85f | 3828 | |
13602ebd VZ |
3829 | const size_t count = GetItemCount(); |
3830 | ||
cf1dfa6b VZ |
3831 | int iconSpacing; |
3832 | if ( HasFlag(wxLC_ICON) ) | |
3833 | iconSpacing = m_normal_spacing; | |
3834 | else if ( HasFlag(wxLC_SMALL_ICON) ) | |
3835 | iconSpacing = m_small_spacing; | |
3836 | else | |
3837 | iconSpacing = 0; | |
004fd0c8 | 3838 | |
bf632edd RR |
3839 | // Note that we do not call GetClientSize() here but |
3840 | // GetSize() and substract the border size for sunken | |
3841 | // borders manually. This is technically incorrect, | |
3842 | // but we need to know the client area's size WITHOUT | |
3843 | // scrollbars here. Since we don't know if there are | |
3844 | // any scrollbars, we use GetSize() instead. Another | |
3845 | // solution would be to call SetScrollbars() here to | |
3846 | // remove the scrollbars and call GetClientSize() then, | |
3847 | // but this might result in flicker and - worse - will | |
3848 | // reset the scrollbars to 0 which is not good at all | |
3849 | // if you resize a dialog/window, but don't want to | |
3850 | // reset the window scrolling. RR. | |
3851 | // Furthermore, we actually do NOT subtract the border | |
3852 | // width as 2 pixels is just the extra space which we | |
3853 | // need around the actual content in the window. Other- | |
3854 | // wise the text would e.g. touch the upper border. RR. | |
cf1dfa6b VZ |
3855 | int clientWidth, |
3856 | clientHeight; | |
bf632edd | 3857 | GetSize( &clientWidth, &clientHeight ); |
a77ec46d | 3858 | |
6d78bbe6 VZ |
3859 | const int lineHeight = GetLineHeight(); |
3860 | ||
cf1dfa6b VZ |
3861 | if ( HasFlag(wxLC_REPORT) ) |
3862 | { | |
13602ebd | 3863 | // all lines have the same height and we scroll one line per step |
13602ebd | 3864 | int entireHeight = count*lineHeight + LINE_SPACING; |
bd8289c1 | 3865 | |
b54e41c5 VZ |
3866 | m_linesPerPage = clientHeight / lineHeight; |
3867 | ||
3868 | ResetVisibleLinesRange(); | |
2c1f73ee | 3869 | |
13602ebd VZ |
3870 | SetScrollbars( SCROLL_UNIT_X, lineHeight, |
3871 | GetHeaderWidth() / SCROLL_UNIT_X, | |
3872 | (entireHeight + lineHeight - 1) / lineHeight, | |
cf1dfa6b VZ |
3873 | GetScrollPos(wxHORIZONTAL), |
3874 | GetScrollPos(wxVERTICAL), | |
3875 | TRUE ); | |
e1e955e1 | 3876 | } |
cf1dfa6b | 3877 | else // !report |
92976ab6 | 3878 | { |
13602ebd VZ |
3879 | // we have 3 different layout strategies: either layout all items |
3880 | // horizontally/vertically (wxLC_ALIGN_XXX styles explicitly given) or | |
3881 | // to arrange them in top to bottom, left to right (don't ask me why | |
3882 | // not the other way round...) order | |
3883 | if ( HasFlag(wxLC_ALIGN_LEFT | wxLC_ALIGN_TOP) ) | |
e487524e | 3884 | { |
13602ebd VZ |
3885 | int x = EXTRA_BORDER_X; |
3886 | int y = EXTRA_BORDER_Y; | |
cf1dfa6b | 3887 | |
94dd23ae VZ |
3888 | wxCoord widthMax = 0; |
3889 | ||
3890 | size_t i; | |
3891 | for ( i = 0; i < count; i++ ) | |
92976ab6 | 3892 | { |
cf1dfa6b | 3893 | wxListLineData *line = GetLine(i); |
92976ab6 | 3894 | line->CalculateSize( &dc, iconSpacing ); |
13602ebd | 3895 | line->SetPosition( x, y, iconSpacing ); |
cf1dfa6b | 3896 | |
5cd89174 | 3897 | wxSize sizeLine = GetLineSize(i); |
cf1dfa6b | 3898 | |
13602ebd VZ |
3899 | if ( HasFlag(wxLC_ALIGN_TOP) ) |
3900 | { | |
94dd23ae VZ |
3901 | if ( sizeLine.x > widthMax ) |
3902 | widthMax = sizeLine.x; | |
3903 | ||
13602ebd VZ |
3904 | y += sizeLine.y; |
3905 | } | |
3906 | else // wxLC_ALIGN_LEFT | |
3907 | { | |
3908 | x += sizeLine.x + MARGIN_BETWEEN_ROWS; | |
3909 | } | |
3910 | } | |
3911 | ||
94dd23ae VZ |
3912 | if ( HasFlag(wxLC_ALIGN_TOP) ) |
3913 | { | |
3914 | // traverse the items again and tweak their sizes so that they are | |
3915 | // all the same in a row | |
3916 | for ( i = 0; i < count; i++ ) | |
3917 | { | |
3918 | wxListLineData *line = GetLine(i); | |
3919 | line->m_gi->ExtendWidth(widthMax); | |
3920 | } | |
3921 | } | |
3922 | ||
3923 | ||
13602ebd VZ |
3924 | SetScrollbars |
3925 | ( | |
3926 | SCROLL_UNIT_X, | |
6d78bbe6 | 3927 | lineHeight, |
13602ebd | 3928 | (x + SCROLL_UNIT_X) / SCROLL_UNIT_X, |
6d78bbe6 | 3929 | (y + lineHeight) / lineHeight, |
13602ebd VZ |
3930 | GetScrollPos( wxHORIZONTAL ), |
3931 | GetScrollPos( wxVERTICAL ), | |
3932 | TRUE | |
3933 | ); | |
3934 | } | |
3935 | else // "flowed" arrangement, the most complicated case | |
3936 | { | |
3937 | // at first we try without any scrollbars, if the items don't fit into | |
3938 | // the window, we recalculate after subtracting the space taken by the | |
3939 | // scrollbar | |
3940 | ||
8a39593e | 3941 | int entireWidth = 0; |
cf1dfa6b | 3942 | |
13602ebd VZ |
3943 | for (int tries = 0; tries < 2; tries++) |
3944 | { | |
3945 | entireWidth = 2*EXTRA_BORDER_X; | |
cf1dfa6b | 3946 | |
13602ebd | 3947 | if (tries == 1) |
92976ab6 | 3948 | { |
13602ebd VZ |
3949 | // Now we have decided that the items do not fit into the |
3950 | // client area, so we need a scrollbar | |
3951 | entireWidth += SCROLL_UNIT_X; | |
92976ab6 | 3952 | } |
a77ec46d | 3953 | |
13602ebd VZ |
3954 | int x = EXTRA_BORDER_X; |
3955 | int y = EXTRA_BORDER_Y; | |
3956 | int maxWidthInThisRow = 0; | |
3957 | ||
3958 | m_linesPerPage = 0; | |
3959 | int currentlyVisibleLines = 0; | |
a77ec46d | 3960 | |
13602ebd | 3961 | for (size_t i = 0; i < count; i++) |
92976ab6 | 3962 | { |
13602ebd VZ |
3963 | currentlyVisibleLines++; |
3964 | wxListLineData *line = GetLine(i); | |
3965 | line->CalculateSize( &dc, iconSpacing ); | |
3966 | line->SetPosition( x, y, iconSpacing ); | |
3967 | ||
3968 | wxSize sizeLine = GetLineSize(i); | |
a77ec46d | 3969 | |
13602ebd VZ |
3970 | if ( maxWidthInThisRow < sizeLine.x ) |
3971 | maxWidthInThisRow = sizeLine.x; | |
3972 | ||
3973 | y += sizeLine.y; | |
3974 | if (currentlyVisibleLines > m_linesPerPage) | |
3975 | m_linesPerPage = currentlyVisibleLines; | |
3976 | ||
3977 | if ( y + sizeLine.y >= clientHeight ) | |
3978 | { | |
3979 | currentlyVisibleLines = 0; | |
3980 | y = EXTRA_BORDER_Y; | |
3981 | maxWidthInThisRow += MARGIN_BETWEEN_ROWS; | |
3982 | x += maxWidthInThisRow; | |
3983 | entireWidth += maxWidthInThisRow; | |
3984 | maxWidthInThisRow = 0; | |
3985 | } | |
3986 | ||
3987 | // We have reached the last item. | |
3988 | if ( i == count - 1 ) | |
3989 | entireWidth += maxWidthInThisRow; | |
3990 | ||
3991 | if ( (tries == 0) && | |
3992 | (entireWidth + SCROLL_UNIT_X > clientWidth) ) | |
3993 | { | |
3994 | clientHeight -= wxSystemSettings:: | |
3995 | GetMetric(wxSYS_HSCROLL_Y); | |
3996 | m_linesPerPage = 0; | |
13602ebd VZ |
3997 | break; |
3998 | } | |
3999 | ||
4000 | if ( i == count - 1 ) | |
4001 | tries = 1; // Everything fits, no second try required. | |
4002 | } | |
92976ab6 | 4003 | } |
bffa1c77 | 4004 | |
13602ebd VZ |
4005 | SetScrollbars |
4006 | ( | |
4007 | SCROLL_UNIT_X, | |
6d78bbe6 | 4008 | lineHeight, |
13602ebd VZ |
4009 | (entireWidth + SCROLL_UNIT_X) / SCROLL_UNIT_X, |
4010 | 0, | |
4011 | GetScrollPos( wxHORIZONTAL ), | |
4012 | 0, | |
4013 | TRUE | |
4014 | ); | |
4015 | } | |
e1e955e1 | 4016 | } |
cf1dfa6b | 4017 | |
34bbbc27 VZ |
4018 | if ( !noRefresh ) |
4019 | { | |
4020 | // FIXME: why should we call it from here? | |
4021 | UpdateCurrent(); | |
b54e41c5 | 4022 | |
34bbbc27 VZ |
4023 | RefreshAll(); |
4024 | } | |
b54e41c5 VZ |
4025 | } |
4026 | ||
4027 | void wxListMainWindow::RefreshAll() | |
4028 | { | |
4029 | m_dirty = FALSE; | |
4030 | Refresh(); | |
4031 | ||
4032 | wxListHeaderWindow *headerWin = GetListCtrl()->m_headerWin; | |
70541533 | 4033 | if ( headerWin && headerWin->m_dirty ) |
b54e41c5 VZ |
4034 | { |
4035 | headerWin->m_dirty = FALSE; | |
4036 | headerWin->Refresh(); | |
4037 | } | |
e1e955e1 | 4038 | } |
c801d85f | 4039 | |
cf1dfa6b | 4040 | void wxListMainWindow::UpdateCurrent() |
c801d85f | 4041 | { |
b54e41c5 | 4042 | if ( !HasCurrent() && !IsEmpty() ) |
92976ab6 | 4043 | { |
0ddefeb0 | 4044 | ChangeCurrent(0); |
92976ab6 | 4045 | } |
e1e955e1 | 4046 | } |
c801d85f | 4047 | |
19695fbd VZ |
4048 | long wxListMainWindow::GetNextItem( long item, |
4049 | int WXUNUSED(geometry), | |
62d89eb4 | 4050 | int state ) const |
c801d85f | 4051 | { |
d1022fd6 VZ |
4052 | long ret = item, |
4053 | max = GetItemCount(); | |
4054 | wxCHECK_MSG( (ret == -1) || (ret < max), -1, | |
13771c08 | 4055 | _T("invalid listctrl index in GetNextItem()") ); |
19695fbd VZ |
4056 | |
4057 | // notice that we start with the next item (or the first one if item == -1) | |
4058 | // and this is intentional to allow writing a simple loop to iterate over | |
4059 | // all selected items | |
d1022fd6 VZ |
4060 | ret++; |
4061 | if ( ret == max ) | |
4062 | { | |
4063 | // this is not an error because the index was ok initially, just no | |
4064 | // such item | |
4065 | return -1; | |
4066 | } | |
4067 | ||
cf1dfa6b VZ |
4068 | if ( !state ) |
4069 | { | |
4070 | // any will do | |
4071 | return (size_t)ret; | |
4072 | } | |
4073 | ||
4074 | size_t count = GetItemCount(); | |
4075 | for ( size_t line = (size_t)ret; line < count; line++ ) | |
63852e78 | 4076 | { |
cf1dfa6b VZ |
4077 | if ( (state & wxLIST_STATE_FOCUSED) && (line == m_current) ) |
4078 | return line; | |
4079 | ||
b54e41c5 | 4080 | if ( (state & wxLIST_STATE_SELECTED) && IsHighlighted(line) ) |
cf1dfa6b | 4081 | return line; |
63852e78 | 4082 | } |
19695fbd | 4083 | |
63852e78 | 4084 | return -1; |
e1e955e1 | 4085 | } |
c801d85f | 4086 | |
cf1dfa6b VZ |
4087 | // ---------------------------------------------------------------------------- |
4088 | // deleting stuff | |
4089 | // ---------------------------------------------------------------------------- | |
4090 | ||
b54e41c5 | 4091 | void wxListMainWindow::DeleteItem( long lindex ) |
c801d85f | 4092 | { |
cf1dfa6b VZ |
4093 | size_t count = GetItemCount(); |
4094 | ||
b54e41c5 | 4095 | wxCHECK_RET( (lindex >= 0) && ((size_t)lindex < count), |
cf1dfa6b VZ |
4096 | _T("invalid item index in DeleteItem") ); |
4097 | ||
b54e41c5 VZ |
4098 | size_t index = (size_t)lindex; |
4099 | ||
d6ddcd57 VZ |
4100 | // we don't need to adjust the index for the previous items |
4101 | if ( HasCurrent() && m_current >= index ) | |
cf1dfa6b | 4102 | { |
d6ddcd57 VZ |
4103 | // if the current item is being deleted, we want the next one to |
4104 | // become selected - unless there is no next one - so don't adjust | |
4105 | // m_current in this case | |
4106 | if ( m_current != index || m_current == count - 1 ) | |
4107 | { | |
4108 | m_current--; | |
4109 | } | |
cf1dfa6b VZ |
4110 | } |
4111 | ||
938b652b | 4112 | if ( InReportView() ) |
63852e78 | 4113 | { |
6b4a8d93 | 4114 | ResetVisibleLinesRange(); |
938b652b VZ |
4115 | } |
4116 | ||
938b652b VZ |
4117 | if ( IsVirtual() ) |
4118 | { | |
4119 | m_countVirt--; | |
b54e41c5 VZ |
4120 | |
4121 | m_selStore.OnItemDelete(index); | |
4122 | } | |
4123 | else | |
4124 | { | |
4125 | m_lines.RemoveAt( index ); | |
63852e78 | 4126 | } |
6b4a8d93 | 4127 | |
70541533 | 4128 | // we need to refresh the (vert) scrollbar as the number of items changed |
b84839ae | 4129 | m_dirty = TRUE; |
91c6cc0e VZ |
4130 | |
4131 | SendNotify( index, wxEVT_COMMAND_LIST_DELETE_ITEM ); | |
4132 | ||
6b4a8d93 | 4133 | RefreshAfter(index); |
e1e955e1 | 4134 | } |
c801d85f | 4135 | |
debe6624 | 4136 | void wxListMainWindow::DeleteColumn( int col ) |
c801d85f | 4137 | { |
222ed1d6 | 4138 | wxListHeaderDataList::compatibility_iterator node = m_columns.Item( col ); |
24b9f055 VZ |
4139 | |
4140 | wxCHECK_RET( node, wxT("invalid column index in DeleteColumn()") ); | |
bd8289c1 | 4141 | |
5b077d48 | 4142 | m_dirty = TRUE; |
222ed1d6 MB |
4143 | delete node->GetData(); |
4144 | m_columns.Erase( node ); | |
ae409cb8 | 4145 | |
df6f82f0 VZ |
4146 | if ( !IsVirtual() ) |
4147 | { | |
4148 | // update all the items | |
4149 | for ( size_t i = 0; i < m_lines.GetCount(); i++ ) | |
4150 | { | |
4151 | wxListLineData * const line = GetLine(i); | |
222ed1d6 MB |
4152 | wxListItemDataList::compatibility_iterator n = line->m_items.Item( col ); |
4153 | delete n->GetData(); | |
4154 | line->m_items.Erase(n); | |
df6f82f0 VZ |
4155 | } |
4156 | } | |
4157 | ||
ae409cb8 VZ |
4158 | // invalidate it as it has to be recalculated |
4159 | m_headerWidth = 0; | |
e1e955e1 | 4160 | } |
c801d85f | 4161 | |
5fe143df | 4162 | void wxListMainWindow::DoDeleteAllItems() |
c801d85f | 4163 | { |
cf1dfa6b VZ |
4164 | if ( IsEmpty() ) |
4165 | { | |
4166 | // nothing to do - in particular, don't send the event | |
4167 | return; | |
4168 | } | |
4169 | ||
b54e41c5 | 4170 | ResetCurrent(); |
7c0ea335 VZ |
4171 | |
4172 | // to make the deletion of all items faster, we don't send the | |
cf1dfa6b VZ |
4173 | // notifications for each item deletion in this case but only one event |
4174 | // for all of them: this is compatible with wxMSW and documented in | |
4175 | // DeleteAllItems() description | |
bffa1c77 | 4176 | |
12c1b46a RR |
4177 | wxListEvent event( wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS, GetParent()->GetId() ); |
4178 | event.SetEventObject( GetParent() ); | |
4179 | GetParent()->GetEventHandler()->ProcessEvent( event ); | |
7c0ea335 | 4180 | |
b54e41c5 VZ |
4181 | if ( IsVirtual() ) |
4182 | { | |
4183 | m_countVirt = 0; | |
4184 | ||
850ed6e7 | 4185 | m_selStore.Clear(); |
b54e41c5 VZ |
4186 | } |
4187 | ||
6b4a8d93 VZ |
4188 | if ( InReportView() ) |
4189 | { | |
4190 | ResetVisibleLinesRange(); | |
4191 | } | |
4192 | ||
5b077d48 | 4193 | m_lines.Clear(); |
5fe143df | 4194 | } |
cf1dfa6b | 4195 | |
5fe143df VZ |
4196 | void wxListMainWindow::DeleteAllItems() |
4197 | { | |
4198 | DoDeleteAllItems(); | |
4199 | ||
4200 | RecalculatePositions(); | |
e1e955e1 | 4201 | } |
c801d85f | 4202 | |
12c1b46a | 4203 | void wxListMainWindow::DeleteEverything() |
c801d85f | 4204 | { |
222ed1d6 | 4205 | WX_CLEAR_LIST(wxListHeaderDataList, m_columns); |
904ccf52 VZ |
4206 | |
4207 | DeleteAllItems(); | |
e1e955e1 | 4208 | } |
c801d85f | 4209 | |
cf1dfa6b VZ |
4210 | // ---------------------------------------------------------------------------- |
4211 | // scanning for an item | |
4212 | // ---------------------------------------------------------------------------- | |
4213 | ||
debe6624 | 4214 | void wxListMainWindow::EnsureVisible( long index ) |
c801d85f | 4215 | { |
cf1dfa6b VZ |
4216 | wxCHECK_RET( index >= 0 && (size_t)index < GetItemCount(), |
4217 | _T("invalid index in EnsureVisible") ); | |
4218 | ||
4219 | // We have to call this here because the label in question might just have | |
34bbbc27 VZ |
4220 | // been added and its position is not known yet |
4221 | if ( m_dirty ) | |
4222 | { | |
34bbbc27 VZ |
4223 | RecalculatePositions(TRUE /* no refresh */); |
4224 | } | |
4225 | ||
4226 | MoveToItem((size_t)index); | |
e1e955e1 | 4227 | } |
c801d85f | 4228 | |
debe6624 | 4229 | long wxListMainWindow::FindItem(long start, const wxString& str, bool WXUNUSED(partial) ) |
c801d85f | 4230 | { |
5b077d48 RR |
4231 | long pos = start; |
4232 | wxString tmp = str; | |
cf1dfa6b VZ |
4233 | if (pos < 0) |
4234 | pos = 0; | |
54442116 | 4235 | |
cf1dfa6b VZ |
4236 | size_t count = GetItemCount(); |
4237 | for ( size_t i = (size_t)pos; i < count; i++ ) | |
4238 | { | |
4239 | wxListLineData *line = GetLine(i); | |
4240 | if ( line->GetText(0) == tmp ) | |
4241 | return i; | |
5b077d48 | 4242 | } |
cf1dfa6b VZ |
4243 | |
4244 | return wxNOT_FOUND; | |
e1e955e1 | 4245 | } |
c801d85f | 4246 | |
debe6624 | 4247 | long wxListMainWindow::FindItem(long start, long data) |
c801d85f | 4248 | { |
5b077d48 | 4249 | long pos = start; |
cf1dfa6b VZ |
4250 | if (pos < 0) |
4251 | pos = 0; | |
4252 | ||
4253 | size_t count = GetItemCount(); | |
4254 | for (size_t i = (size_t)pos; i < count; i++) | |
5b077d48 | 4255 | { |
cf1dfa6b | 4256 | wxListLineData *line = GetLine(i); |
5b077d48 RR |
4257 | wxListItem item; |
4258 | line->GetItem( 0, item ); | |
cf1dfa6b VZ |
4259 | if (item.m_data == data) |
4260 | return i; | |
5b077d48 | 4261 | } |
cf1dfa6b VZ |
4262 | |
4263 | return wxNOT_FOUND; | |
e1e955e1 | 4264 | } |
c801d85f | 4265 | |
debe6624 | 4266 | long wxListMainWindow::HitTest( int x, int y, int &flags ) |
c801d85f | 4267 | { |
aaef15bf | 4268 | CalcUnscrolledPosition( x, y, &x, &y ); |
e8741cca | 4269 | |
fc4f1d5f VZ |
4270 | size_t count = GetItemCount(); |
4271 | ||
5cd89174 | 4272 | if ( HasFlag(wxLC_REPORT) ) |
c801d85f | 4273 | { |
5cd89174 | 4274 | size_t current = y / GetLineHeight(); |
fc4f1d5f VZ |
4275 | if ( current < count ) |
4276 | { | |
4277 | flags = HitTestLine(current, x, y); | |
4278 | if ( flags ) | |
4279 | return current; | |
4280 | } | |
5cd89174 VZ |
4281 | } |
4282 | else // !report | |
4283 | { | |
4284 | // TODO: optimize it too! this is less simple than for report view but | |
4285 | // enumerating all items is still not a way to do it!! | |
5cd89174 | 4286 | for ( size_t current = 0; current < count; current++ ) |
5b077d48 | 4287 | { |
5cd89174 VZ |
4288 | flags = HitTestLine(current, x, y); |
4289 | if ( flags ) | |
4290 | return current; | |
5b077d48 | 4291 | } |
e1e955e1 | 4292 | } |
cf1dfa6b VZ |
4293 | |
4294 | return wxNOT_FOUND; | |
e1e955e1 | 4295 | } |
c801d85f | 4296 | |
cf1dfa6b VZ |
4297 | // ---------------------------------------------------------------------------- |
4298 | // adding stuff | |
4299 | // ---------------------------------------------------------------------------- | |
4300 | ||
c801d85f KB |
4301 | void wxListMainWindow::InsertItem( wxListItem &item ) |
4302 | { | |
cf1dfa6b VZ |
4303 | wxASSERT_MSG( !IsVirtual(), _T("can't be used with virtual control") ); |
4304 | ||
4305 | size_t count = GetItemCount(); | |
4306 | wxCHECK_RET( item.m_itemId >= 0 && (size_t)item.m_itemId <= count, | |
4307 | _T("invalid item index") ); | |
4308 | ||
4309 | size_t id = item.m_itemId; | |
4310 | ||
5b077d48 | 4311 | m_dirty = TRUE; |
cf1dfa6b | 4312 | |
8a39593e JS |
4313 | #if 0 |
4314 | // this is unused variable | |
5b077d48 | 4315 | int mode = 0; |
8a39593e | 4316 | #endif |
cf1dfa6b | 4317 | if ( HasFlag(wxLC_REPORT) ) |
2b5f62a0 | 4318 | { |
8a39593e JS |
4319 | #if 0 |
4320 | // this is unused variable | |
1370703e | 4321 | mode = wxLC_REPORT; |
8a39593e | 4322 | #endif |
2b5f62a0 VZ |
4323 | ResetVisibleLinesRange(); |
4324 | } | |
cf1dfa6b | 4325 | else if ( HasFlag(wxLC_LIST) ) |
8a39593e JS |
4326 | #if 0 |
4327 | // this is unused variable | |
1370703e | 4328 | mode = wxLC_LIST; |
8a39593e JS |
4329 | #else |
4330 | {} | |
4331 | #endif | |
cf1dfa6b | 4332 | else if ( HasFlag(wxLC_ICON) ) |
8a39593e JS |
4333 | #if 0 |
4334 | // this is unused variable | |
1370703e | 4335 | mode = wxLC_ICON; |
8a39593e JS |
4336 | #else |
4337 | {} | |
4338 | #endif | |
cf1dfa6b | 4339 | else if ( HasFlag(wxLC_SMALL_ICON) ) |
8a39593e JS |
4340 | #if 0 |
4341 | // this is unused variable | |
1370703e | 4342 | mode = wxLC_ICON; // no typo |
8a39593e JS |
4343 | #else |
4344 | {} | |
4345 | #endif | |
1370703e VZ |
4346 | else |
4347 | { | |
4348 | wxFAIL_MSG( _T("unknown mode") ); | |
4349 | } | |
004fd0c8 | 4350 | |
5cd89174 | 4351 | wxListLineData *line = new wxListLineData(this); |
004fd0c8 | 4352 | |
5b077d48 | 4353 | line->SetItem( 0, item ); |
cf1dfa6b VZ |
4354 | |
4355 | m_lines.Insert( line, id ); | |
5cd89174 | 4356 | |
b84839ae | 4357 | m_dirty = TRUE; |
a67e6e54 | 4358 | |
ab96d680 VZ |
4359 | // If an item is selected at or below the point of insertion, we need to |
4360 | // increment the member variables because the current row's index has gone | |
4361 | // up by one | |
4362 | if ( HasCurrent() && m_current >= id ) | |
4363 | { | |
4364 | m_current++; | |
4365 | } | |
4366 | ||
a67e6e54 VZ |
4367 | SendNotify(id, wxEVT_COMMAND_LIST_INSERT_ITEM); |
4368 | ||
5cd89174 | 4369 | RefreshLines(id, GetItemCount() - 1); |
e1e955e1 | 4370 | } |
c801d85f | 4371 | |
debe6624 | 4372 | void wxListMainWindow::InsertColumn( long col, wxListItem &item ) |
c801d85f | 4373 | { |
5b077d48 | 4374 | m_dirty = TRUE; |
cf1dfa6b | 4375 | if ( HasFlag(wxLC_REPORT) ) |
3db7be80 | 4376 | { |
54442116 VZ |
4377 | if (item.m_width == wxLIST_AUTOSIZE_USEHEADER) |
4378 | item.m_width = GetTextLength( item.m_text ); | |
df6f82f0 | 4379 | |
5b077d48 | 4380 | wxListHeaderData *column = new wxListHeaderData( item ); |
df6f82f0 VZ |
4381 | bool insert = (col >= 0) && ((size_t)col < m_columns.GetCount()); |
4382 | if ( insert ) | |
5b077d48 | 4383 | { |
222ed1d6 | 4384 | wxListHeaderDataList::compatibility_iterator node = m_columns.Item( col ); |
24b9f055 | 4385 | m_columns.Insert( node, column ); |
5b077d48 RR |
4386 | } |
4387 | else | |
4388 | { | |
4389 | m_columns.Append( column ); | |
4390 | } | |
ae409cb8 | 4391 | |
df6f82f0 VZ |
4392 | if ( !IsVirtual() ) |
4393 | { | |
4394 | // update all the items | |
4395 | for ( size_t i = 0; i < m_lines.GetCount(); i++ ) | |
4396 | { | |
4397 | wxListLineData * const line = GetLine(i); | |
4398 | wxListItemData * const data = new wxListItemData(this); | |
4399 | if ( insert ) | |
4400 | line->m_items.Insert(col, data); | |
4401 | else | |
4402 | line->m_items.Append(data); | |
4403 | } | |
4404 | } | |
4405 | ||
ae409cb8 VZ |
4406 | // invalidate it as it has to be recalculated |
4407 | m_headerWidth = 0; | |
3db7be80 | 4408 | } |
e1e955e1 | 4409 | } |
c801d85f | 4410 | |
cf1dfa6b VZ |
4411 | // ---------------------------------------------------------------------------- |
4412 | // sorting | |
4413 | // ---------------------------------------------------------------------------- | |
4414 | ||
c801d85f KB |
4415 | wxListCtrlCompare list_ctrl_compare_func_2; |
4416 | long list_ctrl_compare_data; | |
4417 | ||
f6bcfd97 | 4418 | int LINKAGEMODE list_ctrl_compare_func_1( wxListLineData **arg1, wxListLineData **arg2 ) |
c801d85f | 4419 | { |
f6bcfd97 BP |
4420 | wxListLineData *line1 = *arg1; |
4421 | wxListLineData *line2 = *arg2; | |
5b077d48 RR |
4422 | wxListItem item; |
4423 | line1->GetItem( 0, item ); | |
4424 | long data1 = item.m_data; | |
4425 | line2->GetItem( 0, item ); | |
4426 | long data2 = item.m_data; | |
4427 | return list_ctrl_compare_func_2( data1, data2, list_ctrl_compare_data ); | |
e1e955e1 | 4428 | } |
c801d85f KB |
4429 | |
4430 | void wxListMainWindow::SortItems( wxListCtrlCompare fn, long data ) | |
4431 | { | |
5b077d48 RR |
4432 | list_ctrl_compare_func_2 = fn; |
4433 | list_ctrl_compare_data = data; | |
4434 | m_lines.Sort( list_ctrl_compare_func_1 ); | |
af7c1052 | 4435 | m_dirty = TRUE; |
e1e955e1 | 4436 | } |
c801d85f | 4437 | |
cf1dfa6b VZ |
4438 | // ---------------------------------------------------------------------------- |
4439 | // scrolling | |
4440 | // ---------------------------------------------------------------------------- | |
4441 | ||
7c74e7fe SC |
4442 | void wxListMainWindow::OnScroll(wxScrollWinEvent& event) |
4443 | { | |
b54e41c5 VZ |
4444 | // update our idea of which lines are shown when we redraw the window the |
4445 | // next time | |
4446 | ResetVisibleLinesRange(); | |
cf1dfa6b | 4447 | |
29149a64 | 4448 | // FIXME |
3a8c693a | 4449 | #if defined(__WXGTK__) && !defined(__WXUNIVERSAL__) |
29149a64 VZ |
4450 | wxScrolledWindow::OnScroll(event); |
4451 | #else | |
1e6feb95 | 4452 | HandleOnScroll( event ); |
29149a64 | 4453 | #endif |
30954328 | 4454 | |
cf1dfa6b | 4455 | if ( event.GetOrientation() == wxHORIZONTAL && HasHeader() ) |
7c74e7fe | 4456 | { |
3cd94a0d | 4457 | wxGenericListCtrl* lc = GetListCtrl(); |
cf1dfa6b VZ |
4458 | wxCHECK_RET( lc, _T("no listctrl window?") ); |
4459 | ||
afbe906a RR |
4460 | lc->m_headerWin->Refresh(); |
4461 | lc->m_headerWin->Update(); | |
7c74e7fe | 4462 | } |
cf1dfa6b VZ |
4463 | } |
4464 | ||
5cd89174 VZ |
4465 | int wxListMainWindow::GetCountPerPage() const |
4466 | { | |
4467 | if ( !m_linesPerPage ) | |
4468 | { | |
4469 | wxConstCast(this, wxListMainWindow)-> | |
4470 | m_linesPerPage = GetClientSize().y / GetLineHeight(); | |
4471 | } | |
4472 | ||
4473 | return m_linesPerPage; | |
4474 | } | |
4475 | ||
b54e41c5 | 4476 | void wxListMainWindow::GetVisibleLinesRange(size_t *from, size_t *to) |
cf1dfa6b | 4477 | { |
b54e41c5 | 4478 | wxASSERT_MSG( HasFlag(wxLC_REPORT), _T("this is for report mode only") ); |
cf1dfa6b | 4479 | |
b54e41c5 VZ |
4480 | if ( m_lineFrom == (size_t)-1 ) |
4481 | { | |
b54e41c5 | 4482 | size_t count = GetItemCount(); |
6522713c VZ |
4483 | if ( count ) |
4484 | { | |
4485 | m_lineFrom = GetScrollPos(wxVERTICAL); | |
cf1dfa6b | 4486 | |
152c57f2 VZ |
4487 | // this may happen if SetScrollbars() hadn't been called yet |
4488 | if ( m_lineFrom >= count ) | |
bcc0da5c | 4489 | m_lineFrom = count - 1; |
cf1dfa6b | 4490 | |
6522713c VZ |
4491 | // we redraw one extra line but this is needed to make the redrawing |
4492 | // logic work when there is a fractional number of lines on screen | |
4493 | m_lineTo = m_lineFrom + m_linesPerPage; | |
4494 | if ( m_lineTo >= count ) | |
4495 | m_lineTo = count - 1; | |
4496 | } | |
4497 | else // empty control | |
4498 | { | |
4499 | m_lineFrom = 0; | |
4500 | m_lineTo = (size_t)-1; | |
4501 | } | |
cf1dfa6b | 4502 | } |
b54e41c5 | 4503 | |
ae167d2f VZ |
4504 | wxASSERT_MSG( IsEmpty() || |
4505 | (m_lineFrom <= m_lineTo && m_lineTo < GetItemCount()), | |
6b4a8d93 VZ |
4506 | _T("GetVisibleLinesRange() returns incorrect result") ); |
4507 | ||
b54e41c5 VZ |
4508 | if ( from ) |
4509 | *from = m_lineFrom; | |
4510 | if ( to ) | |
4511 | *to = m_lineTo; | |
7c74e7fe SC |
4512 | } |
4513 | ||
c801d85f | 4514 | // ------------------------------------------------------------------------------------- |
3cd94a0d | 4515 | // wxGenericListCtrl |
c801d85f KB |
4516 | // ------------------------------------------------------------------------------------- |
4517 | ||
3cd94a0d JS |
4518 | IMPLEMENT_DYNAMIC_CLASS(wxGenericListCtrl, wxControl) |
4519 | ||
3cd94a0d JS |
4520 | BEGIN_EVENT_TABLE(wxGenericListCtrl,wxControl) |
4521 | EVT_SIZE(wxGenericListCtrl::OnSize) | |
c801d85f KB |
4522 | END_EVENT_TABLE() |
4523 | ||
3cd94a0d | 4524 | wxGenericListCtrl::wxGenericListCtrl() |
c801d85f | 4525 | { |
80020b62 JS |
4526 | m_imageListNormal = (wxImageListType *) NULL; |
4527 | m_imageListSmall = (wxImageListType *) NULL; | |
4528 | m_imageListState = (wxImageListType *) NULL; | |
cf1dfa6b VZ |
4529 | |
4530 | m_ownsImageListNormal = | |
4531 | m_ownsImageListSmall = | |
4532 | m_ownsImageListState = FALSE; | |
4533 | ||
5b077d48 RR |
4534 | m_mainWin = (wxListMainWindow*) NULL; |
4535 | m_headerWin = (wxListHeaderWindow*) NULL; | |
f8252483 | 4536 | m_headerHeight = 0; |
c801d85f KB |
4537 | } |
4538 | ||
3cd94a0d | 4539 | wxGenericListCtrl::~wxGenericListCtrl() |
c801d85f | 4540 | { |
cf1dfa6b VZ |
4541 | if (m_ownsImageListNormal) |
4542 | delete m_imageListNormal; | |
4543 | if (m_ownsImageListSmall) | |
4544 | delete m_imageListSmall; | |
4545 | if (m_ownsImageListState) | |
4546 | delete m_imageListState; | |
4547 | } | |
4548 | ||
f8252483 JS |
4549 | void wxGenericListCtrl::CalculateAndSetHeaderHeight() |
4550 | { | |
86351e4a VZ |
4551 | if ( m_headerWin ) |
4552 | { | |
4553 | // we use 'g' to get the descent, too | |
4554 | int w, h, d; | |
4555 | m_headerWin->GetTextExtent(wxT("Hg"), &w, &h, &d); | |
4556 | h += d + 2 * HEADER_OFFSET_Y + EXTRA_HEIGHT; | |
4557 | ||
8b1ed8d9 VZ |
4558 | // only update if changed |
4559 | if ( h != m_headerHeight ) | |
86351e4a VZ |
4560 | { |
4561 | m_headerHeight = h; | |
4562 | ||
4563 | m_headerWin->SetSize(m_headerWin->GetSize().x, m_headerHeight); | |
4564 | ||
4565 | if ( HasFlag(wxLC_REPORT) && !HasFlag(wxLC_NO_HEADER) ) | |
4566 | ResizeReportView(TRUE); | |
4567 | } | |
4568 | } | |
f8252483 JS |
4569 | } |
4570 | ||
3cd94a0d | 4571 | void wxGenericListCtrl::CreateHeaderWindow() |
cf1dfa6b VZ |
4572 | { |
4573 | m_headerWin = new wxListHeaderWindow | |
4574 | ( | |
4575 | this, -1, m_mainWin, | |
4576 | wxPoint(0, 0), | |
f8252483 | 4577 | wxSize(GetClientSize().x, m_headerHeight), |
cf1dfa6b VZ |
4578 | wxTAB_TRAVERSAL |
4579 | ); | |
f8252483 | 4580 | CalculateAndSetHeaderHeight(); |
c801d85f KB |
4581 | } |
4582 | ||
3cd94a0d | 4583 | bool wxGenericListCtrl::Create(wxWindow *parent, |
25e3a937 VZ |
4584 | wxWindowID id, |
4585 | const wxPoint &pos, | |
4586 | const wxSize &size, | |
4587 | long style, | |
25e3a937 | 4588 | const wxValidator &validator, |
25e3a937 | 4589 | const wxString &name) |
c801d85f | 4590 | { |
cf1dfa6b VZ |
4591 | m_imageListNormal = |
4592 | m_imageListSmall = | |
80020b62 | 4593 | m_imageListState = (wxImageListType *) NULL; |
cf1dfa6b VZ |
4594 | m_ownsImageListNormal = |
4595 | m_ownsImageListSmall = | |
4596 | m_ownsImageListState = FALSE; | |
4597 | ||
5b077d48 RR |
4598 | m_mainWin = (wxListMainWindow*) NULL; |
4599 | m_headerWin = (wxListHeaderWindow*) NULL; | |
bd8289c1 | 4600 | |
3fc93ebd JS |
4601 | m_headerHeight = 0; |
4602 | ||
b54e41c5 | 4603 | if ( !(style & wxLC_MASK_TYPE) ) |
5b077d48 | 4604 | { |
25e3a937 | 4605 | style = style | wxLC_LIST; |
5b077d48 | 4606 | } |
f6bcfd97 | 4607 | |
07215d86 | 4608 | if ( !wxControl::Create( parent, id, pos, size, style, validator, name ) ) |
cf1dfa6b | 4609 | return FALSE; |
f6bcfd97 | 4610 | |
b54e41c5 | 4611 | // don't create the inner window with the border |
6d460f76 | 4612 | style &= ~wxBORDER_MASK; |
bd8289c1 | 4613 | |
25e3a937 | 4614 | m_mainWin = new wxListMainWindow( this, -1, wxPoint(0,0), size, style ); |
bd8289c1 | 4615 | |
b54e41c5 | 4616 | if ( HasFlag(wxLC_REPORT) ) |
ea451729 | 4617 | { |
cf1dfa6b VZ |
4618 | CreateHeaderWindow(); |
4619 | ||
b54e41c5 | 4620 | if ( HasFlag(wxLC_NO_HEADER) ) |
cf1dfa6b VZ |
4621 | { |
4622 | // VZ: why do we create it at all then? | |
ea451729 | 4623 | m_headerWin->Show( FALSE ); |
cf1dfa6b | 4624 | } |
ea451729 | 4625 | } |
bd8289c1 | 4626 | |
cf1dfa6b | 4627 | return TRUE; |
e1e955e1 | 4628 | } |
c801d85f | 4629 | |
3cd94a0d | 4630 | void wxGenericListCtrl::SetSingleStyle( long style, bool add ) |
c801d85f | 4631 | { |
b54e41c5 VZ |
4632 | wxASSERT_MSG( !(style & wxLC_VIRTUAL), |
4633 | _T("wxLC_VIRTUAL can't be [un]set") ); | |
4634 | ||
f03fc89f | 4635 | long flag = GetWindowStyle(); |
bd8289c1 | 4636 | |
5b077d48 RR |
4637 | if (add) |
4638 | { | |
cf1dfa6b | 4639 | if (style & wxLC_MASK_TYPE) |
b54e41c5 | 4640 | flag &= ~(wxLC_MASK_TYPE | wxLC_VIRTUAL); |
cf1dfa6b VZ |
4641 | if (style & wxLC_MASK_ALIGN) |
4642 | flag &= ~wxLC_MASK_ALIGN; | |
4643 | if (style & wxLC_MASK_SORT) | |
4644 | flag &= ~wxLC_MASK_SORT; | |
5b077d48 | 4645 | } |
c801d85f | 4646 | |
5b077d48 RR |
4647 | if (add) |
4648 | { | |
4649 | flag |= style; | |
4650 | } | |
4651 | else | |
4652 | { | |
cf1dfa6b | 4653 | flag &= ~style; |
5b077d48 | 4654 | } |
bd8289c1 | 4655 | |
5b077d48 | 4656 | SetWindowStyleFlag( flag ); |
e1e955e1 | 4657 | } |
c801d85f | 4658 | |
3cd94a0d | 4659 | void wxGenericListCtrl::SetWindowStyleFlag( long flag ) |
c801d85f | 4660 | { |
121a3581 RR |
4661 | if (m_mainWin) |
4662 | { | |
4663 | m_mainWin->DeleteEverything(); | |
c801d85f | 4664 | |
a95cdab8 VZ |
4665 | // has the header visibility changed? |
4666 | bool hasHeader = HasFlag(wxLC_REPORT) && !HasFlag(wxLC_NO_HEADER), | |
4667 | willHaveHeader = (flag & wxLC_REPORT) && !(flag & wxLC_NO_HEADER); | |
c801d85f | 4668 | |
a95cdab8 | 4669 | if ( hasHeader != willHaveHeader ) |
5b077d48 | 4670 | { |
a95cdab8 VZ |
4671 | // toggle it |
4672 | if ( hasHeader ) | |
4673 | { | |
4674 | if ( m_headerWin ) | |
4675 | { | |
4676 | // don't delete, just hide, as we can reuse it later | |
4677 | m_headerWin->Show(FALSE); | |
4678 | } | |
4679 | //else: nothing to do | |
4680 | } | |
4681 | else // must show header | |
5b077d48 | 4682 | { |
121a3581 RR |
4683 | if (!m_headerWin) |
4684 | { | |
cf1dfa6b | 4685 | CreateHeaderWindow(); |
121a3581 | 4686 | } |
a95cdab8 | 4687 | else // already have it, just show |
004fd0c8 | 4688 | { |
a95cdab8 | 4689 | m_headerWin->Show( TRUE ); |
004fd0c8 | 4690 | } |
5b077d48 | 4691 | } |
a95cdab8 VZ |
4692 | |
4693 | ResizeReportView(willHaveHeader); | |
bffa1c77 | 4694 | } |
e1e955e1 | 4695 | } |
004fd0c8 | 4696 | |
5b077d48 | 4697 | wxWindow::SetWindowStyleFlag( flag ); |
e1e955e1 | 4698 | } |
c801d85f | 4699 | |
3cd94a0d | 4700 | bool wxGenericListCtrl::GetColumn(int col, wxListItem &item) const |
c801d85f | 4701 | { |
5b077d48 RR |
4702 | m_mainWin->GetColumn( col, item ); |
4703 | return TRUE; | |
e1e955e1 | 4704 | } |
c801d85f | 4705 | |
3cd94a0d | 4706 | bool wxGenericListCtrl::SetColumn( int col, wxListItem& item ) |
c801d85f | 4707 | { |
5b077d48 RR |
4708 | m_mainWin->SetColumn( col, item ); |
4709 | return TRUE; | |
e1e955e1 | 4710 | } |
c801d85f | 4711 | |
3cd94a0d | 4712 | int wxGenericListCtrl::GetColumnWidth( int col ) const |
c801d85f | 4713 | { |
5b077d48 | 4714 | return m_mainWin->GetColumnWidth( col ); |
e1e955e1 | 4715 | } |
c801d85f | 4716 | |
3cd94a0d | 4717 | bool wxGenericListCtrl::SetColumnWidth( int col, int width ) |
c801d85f | 4718 | { |
5b077d48 RR |
4719 | m_mainWin->SetColumnWidth( col, width ); |
4720 | return TRUE; | |
e1e955e1 | 4721 | } |
c801d85f | 4722 | |
3cd94a0d | 4723 | int wxGenericListCtrl::GetCountPerPage() const |
c801d85f KB |
4724 | { |
4725 | return m_mainWin->GetCountPerPage(); // different from Windows ? | |
e1e955e1 | 4726 | } |
c801d85f | 4727 | |
3cd94a0d | 4728 | bool wxGenericListCtrl::GetItem( wxListItem &info ) const |
c801d85f | 4729 | { |
5b077d48 RR |
4730 | m_mainWin->GetItem( info ); |
4731 | return TRUE; | |
e1e955e1 | 4732 | } |
c801d85f | 4733 | |
3cd94a0d | 4734 | bool wxGenericListCtrl::SetItem( wxListItem &info ) |
c801d85f | 4735 | { |
5b077d48 RR |
4736 | m_mainWin->SetItem( info ); |
4737 | return TRUE; | |
e1e955e1 | 4738 | } |
c801d85f | 4739 | |
3cd94a0d | 4740 | long wxGenericListCtrl::SetItem( long index, int col, const wxString& label, int imageId ) |
c801d85f | 4741 | { |
5b077d48 RR |
4742 | wxListItem info; |
4743 | info.m_text = label; | |
4744 | info.m_mask = wxLIST_MASK_TEXT; | |
4745 | info.m_itemId = index; | |
4746 | info.m_col = col; | |
4747 | if ( imageId > -1 ) | |
4748 | { | |
4749 | info.m_image = imageId; | |
4750 | info.m_mask |= wxLIST_MASK_IMAGE; | |
4751 | }; | |
4752 | m_mainWin->SetItem(info); | |
4753 | return TRUE; | |
e1e955e1 | 4754 | } |
c801d85f | 4755 | |
3cd94a0d | 4756 | int wxGenericListCtrl::GetItemState( long item, long stateMask ) const |
c801d85f | 4757 | { |
5b077d48 | 4758 | return m_mainWin->GetItemState( item, stateMask ); |
e1e955e1 | 4759 | } |
c801d85f | 4760 | |
3cd94a0d | 4761 | bool wxGenericListCtrl::SetItemState( long item, long state, long stateMask ) |
c801d85f | 4762 | { |
5b077d48 RR |
4763 | m_mainWin->SetItemState( item, state, stateMask ); |
4764 | return TRUE; | |
e1e955e1 | 4765 | } |
c801d85f | 4766 | |
3cd94a0d | 4767 | bool wxGenericListCtrl::SetItemImage( long item, int image, int WXUNUSED(selImage) ) |
c801d85f | 4768 | { |
5b077d48 RR |
4769 | wxListItem info; |
4770 | info.m_image = image; | |
4771 | info.m_mask = wxLIST_MASK_IMAGE; | |
4772 | info.m_itemId = item; | |
4773 | m_mainWin->SetItem( info ); | |
4774 | return TRUE; | |
e1e955e1 | 4775 | } |
c801d85f | 4776 | |
3cd94a0d | 4777 | wxString wxGenericListCtrl::GetItemText( long item ) const |
c801d85f | 4778 | { |
62d89eb4 | 4779 | return m_mainWin->GetItemText(item); |
e1e955e1 | 4780 | } |
c801d85f | 4781 | |
3cd94a0d | 4782 | void wxGenericListCtrl::SetItemText( long item, const wxString& str ) |
c801d85f | 4783 | { |
62d89eb4 | 4784 | m_mainWin->SetItemText(item, str); |
e1e955e1 | 4785 | } |
c801d85f | 4786 | |
3cd94a0d | 4787 | long wxGenericListCtrl::GetItemData( long item ) const |
c801d85f | 4788 | { |
5b077d48 RR |
4789 | wxListItem info; |
4790 | info.m_itemId = item; | |
4791 | m_mainWin->GetItem( info ); | |
4792 | return info.m_data; | |
e1e955e1 | 4793 | } |
c801d85f | 4794 | |
3cd94a0d | 4795 | bool wxGenericListCtrl::SetItemData( long item, long data ) |
c801d85f | 4796 | { |
5b077d48 RR |
4797 | wxListItem info; |
4798 | info.m_mask = wxLIST_MASK_DATA; | |
4799 | info.m_itemId = item; | |
4800 | info.m_data = data; | |
4801 | m_mainWin->SetItem( info ); | |
4802 | return TRUE; | |
e1e955e1 | 4803 | } |
c801d85f | 4804 | |
11ebea16 VZ |
4805 | wxRect wxGenericListCtrl::GetViewRect() const |
4806 | { | |
4807 | return m_mainWin->GetViewRect(); | |
4808 | } | |
4809 | ||
3cd94a0d | 4810 | bool wxGenericListCtrl::GetItemRect( long item, wxRect &rect, int WXUNUSED(code) ) const |
c801d85f | 4811 | { |
5b077d48 | 4812 | m_mainWin->GetItemRect( item, rect ); |
7e6874c0 | 4813 | if ( m_mainWin->HasHeader() ) |
f8252483 | 4814 | rect.y += m_headerHeight + 1; |
5b077d48 | 4815 | return TRUE; |
e1e955e1 | 4816 | } |
c801d85f | 4817 | |
3cd94a0d | 4818 | bool wxGenericListCtrl::GetItemPosition( long item, wxPoint& pos ) const |
c801d85f | 4819 | { |
5b077d48 RR |
4820 | m_mainWin->GetItemPosition( item, pos ); |
4821 | return TRUE; | |
e1e955e1 | 4822 | } |
c801d85f | 4823 | |
3cd94a0d | 4824 | bool wxGenericListCtrl::SetItemPosition( long WXUNUSED(item), const wxPoint& WXUNUSED(pos) ) |
c801d85f | 4825 | { |
5b077d48 | 4826 | return 0; |
e1e955e1 | 4827 | } |
c801d85f | 4828 | |
3cd94a0d | 4829 | int wxGenericListCtrl::GetItemCount() const |
c801d85f | 4830 | { |
5b077d48 | 4831 | return m_mainWin->GetItemCount(); |
e1e955e1 | 4832 | } |
c801d85f | 4833 | |
3cd94a0d | 4834 | int wxGenericListCtrl::GetColumnCount() const |
92976ab6 | 4835 | { |
5b077d48 | 4836 | return m_mainWin->GetColumnCount(); |
92976ab6 RR |
4837 | } |
4838 | ||
3cd94a0d | 4839 | void wxGenericListCtrl::SetItemSpacing( int spacing, bool isSmall ) |
33d0b396 | 4840 | { |
5b077d48 | 4841 | m_mainWin->SetItemSpacing( spacing, isSmall ); |
e1e955e1 | 4842 | } |
33d0b396 | 4843 | |
5db8d758 VZ |
4844 | wxSize wxGenericListCtrl::GetItemSpacing() const |
4845 | { | |
f58fc140 | 4846 | const int spacing = m_mainWin->GetItemSpacing(HasFlag(wxLC_SMALL_ICON)); |
5db8d758 VZ |
4847 | |
4848 | return wxSize(spacing, spacing); | |
4849 | } | |
4850 | ||
3cd94a0d | 4851 | int wxGenericListCtrl::GetItemSpacing( bool isSmall ) const |
c801d85f | 4852 | { |
5b077d48 | 4853 | return m_mainWin->GetItemSpacing( isSmall ); |
e1e955e1 | 4854 | } |
c801d85f | 4855 | |
3cd94a0d | 4856 | void wxGenericListCtrl::SetItemTextColour( long item, const wxColour &col ) |
5b98eb2f RL |
4857 | { |
4858 | wxListItem info; | |
4859 | info.m_itemId = item; | |
4860 | info.SetTextColour( col ); | |
4861 | m_mainWin->SetItem( info ); | |
4862 | } | |
4863 | ||
3cd94a0d | 4864 | wxColour wxGenericListCtrl::GetItemTextColour( long item ) const |
5b98eb2f RL |
4865 | { |
4866 | wxListItem info; | |
4867 | info.m_itemId = item; | |
4868 | m_mainWin->GetItem( info ); | |
4869 | return info.GetTextColour(); | |
4870 | } | |
4871 | ||
3cd94a0d | 4872 | void wxGenericListCtrl::SetItemBackgroundColour( long item, const wxColour &col ) |
5b98eb2f RL |
4873 | { |
4874 | wxListItem info; | |
4875 | info.m_itemId = item; | |
4876 | info.SetBackgroundColour( col ); | |
4877 | m_mainWin->SetItem( info ); | |
4878 | } | |
4879 | ||
3cd94a0d | 4880 | wxColour wxGenericListCtrl::GetItemBackgroundColour( long item ) const |
5b98eb2f RL |
4881 | { |
4882 | wxListItem info; | |
4883 | info.m_itemId = item; | |
4884 | m_mainWin->GetItem( info ); | |
4885 | return info.GetBackgroundColour(); | |
4886 | } | |
4887 | ||
3cd94a0d | 4888 | int wxGenericListCtrl::GetSelectedItemCount() const |
c801d85f | 4889 | { |
5b077d48 | 4890 | return m_mainWin->GetSelectedItemCount(); |
e1e955e1 | 4891 | } |
c801d85f | 4892 | |
3cd94a0d | 4893 | wxColour wxGenericListCtrl::GetTextColour() const |
c801d85f | 4894 | { |
0530737d | 4895 | return GetForegroundColour(); |
e1e955e1 | 4896 | } |
c801d85f | 4897 | |
3cd94a0d | 4898 | void wxGenericListCtrl::SetTextColour(const wxColour& col) |
c801d85f | 4899 | { |
0530737d | 4900 | SetForegroundColour(col); |
e1e955e1 | 4901 | } |
c801d85f | 4902 | |
3cd94a0d | 4903 | long wxGenericListCtrl::GetTopItem() const |
c801d85f | 4904 | { |
2b5f62a0 VZ |
4905 | size_t top; |
4906 | m_mainWin->GetVisibleLinesRange(&top, NULL); | |
4907 | return (long)top; | |
e1e955e1 | 4908 | } |
c801d85f | 4909 | |
3cd94a0d | 4910 | long wxGenericListCtrl::GetNextItem( long item, int geom, int state ) const |
c801d85f | 4911 | { |
5b077d48 | 4912 | return m_mainWin->GetNextItem( item, geom, state ); |
e1e955e1 | 4913 | } |
c801d85f | 4914 | |
80020b62 | 4915 | wxImageListType *wxGenericListCtrl::GetImageList(int which) const |
c801d85f | 4916 | { |
5b077d48 RR |
4917 | if (which == wxIMAGE_LIST_NORMAL) |
4918 | { | |
4919 | return m_imageListNormal; | |
4920 | } | |
4921 | else if (which == wxIMAGE_LIST_SMALL) | |
4922 | { | |
4923 | return m_imageListSmall; | |
4924 | } | |
4925 | else if (which == wxIMAGE_LIST_STATE) | |
4926 | { | |
4927 | return m_imageListState; | |
4928 | } | |
80020b62 | 4929 | return (wxImageListType *) NULL; |
e1e955e1 | 4930 | } |
c801d85f | 4931 | |
80020b62 | 4932 | void wxGenericListCtrl::SetImageList( wxImageListType *imageList, int which ) |
c801d85f | 4933 | { |
2e12c11a VS |
4934 | if ( which == wxIMAGE_LIST_NORMAL ) |
4935 | { | |
4936 | if (m_ownsImageListNormal) delete m_imageListNormal; | |
4937 | m_imageListNormal = imageList; | |
4938 | m_ownsImageListNormal = FALSE; | |
4939 | } | |
4940 | else if ( which == wxIMAGE_LIST_SMALL ) | |
4941 | { | |
4942 | if (m_ownsImageListSmall) delete m_imageListSmall; | |
4943 | m_imageListSmall = imageList; | |
4944 | m_ownsImageListSmall = FALSE; | |
4945 | } | |
4946 | else if ( which == wxIMAGE_LIST_STATE ) | |
4947 | { | |
4948 | if (m_ownsImageListState) delete m_imageListState; | |
4949 | m_imageListState = imageList; | |
4950 | m_ownsImageListState = FALSE; | |
4951 | } | |
4952 | ||
5b077d48 | 4953 | m_mainWin->SetImageList( imageList, which ); |
e1e955e1 | 4954 | } |
c801d85f | 4955 | |
80020b62 | 4956 | void wxGenericListCtrl::AssignImageList(wxImageListType *imageList, int which) |
2e12c11a VS |
4957 | { |
4958 | SetImageList(imageList, which); | |
4959 | if ( which == wxIMAGE_LIST_NORMAL ) | |
4960 | m_ownsImageListNormal = TRUE; | |
4961 | else if ( which == wxIMAGE_LIST_SMALL ) | |
4962 | m_ownsImageListSmall = TRUE; | |
4963 | else if ( which == wxIMAGE_LIST_STATE ) | |
4964 | m_ownsImageListState = TRUE; | |
4965 | } | |
4966 | ||
3cd94a0d | 4967 | bool wxGenericListCtrl::Arrange( int WXUNUSED(flag) ) |
c801d85f | 4968 | { |
5b077d48 | 4969 | return 0; |
e1e955e1 | 4970 | } |
c801d85f | 4971 | |
3cd94a0d | 4972 | bool wxGenericListCtrl::DeleteItem( long item ) |
c801d85f | 4973 | { |
5b077d48 RR |
4974 | m_mainWin->DeleteItem( item ); |
4975 | return TRUE; | |
e1e955e1 | 4976 | } |
c801d85f | 4977 | |
3cd94a0d | 4978 | bool wxGenericListCtrl::DeleteAllItems() |
c801d85f | 4979 | { |
5b077d48 RR |
4980 | m_mainWin->DeleteAllItems(); |
4981 | return TRUE; | |
e1e955e1 | 4982 | } |
c801d85f | 4983 | |
3cd94a0d | 4984 | bool wxGenericListCtrl::DeleteAllColumns() |
bd8289c1 | 4985 | { |
24b9f055 VZ |
4986 | size_t count = m_mainWin->m_columns.GetCount(); |
4987 | for ( size_t n = 0; n < count; n++ ) | |
85cdcb7a | 4988 | DeleteColumn(0); |
bffa1c77 | 4989 | |
5b077d48 | 4990 | return TRUE; |
4f22cf8d RR |
4991 | } |
4992 | ||
3cd94a0d | 4993 | void wxGenericListCtrl::ClearAll() |
4f22cf8d | 4994 | { |
5b077d48 | 4995 | m_mainWin->DeleteEverything(); |
bd8289c1 VZ |
4996 | } |
4997 | ||
3cd94a0d | 4998 | bool wxGenericListCtrl::DeleteColumn( int col ) |
c801d85f | 4999 | { |
5b077d48 | 5000 | m_mainWin->DeleteColumn( col ); |
40c08808 VZ |
5001 | |
5002 | // if we don't have the header any longer, we need to relayout the window | |
5003 | if ( !GetColumnCount() ) | |
5004 | { | |
5005 | ResizeReportView(FALSE /* no header */); | |
5006 | } | |
5007 | ||
5b077d48 | 5008 | return TRUE; |
e1e955e1 | 5009 | } |
c801d85f | 5010 | |
3cd94a0d | 5011 | void wxGenericListCtrl::Edit( long item ) |
c801d85f | 5012 | { |
cf1dfa6b | 5013 | m_mainWin->EditLabel( item ); |
e1e955e1 | 5014 | } |
c801d85f | 5015 | |
3cd94a0d | 5016 | bool wxGenericListCtrl::EnsureVisible( long item ) |
c801d85f | 5017 | { |
5b077d48 RR |
5018 | m_mainWin->EnsureVisible( item ); |
5019 | return TRUE; | |
e1e955e1 | 5020 | } |
c801d85f | 5021 | |
3cd94a0d | 5022 | long wxGenericListCtrl::FindItem( long start, const wxString& str, bool partial ) |
c801d85f | 5023 | { |
5b077d48 | 5024 | return m_mainWin->FindItem( start, str, partial ); |
e1e955e1 | 5025 | } |
c801d85f | 5026 | |
3cd94a0d | 5027 | long wxGenericListCtrl::FindItem( long start, long data ) |
c801d85f | 5028 | { |
5b077d48 | 5029 | return m_mainWin->FindItem( start, data ); |
e1e955e1 | 5030 | } |
c801d85f | 5031 | |
3cd94a0d | 5032 | long wxGenericListCtrl::FindItem( long WXUNUSED(start), const wxPoint& WXUNUSED(pt), |
debe6624 | 5033 | int WXUNUSED(direction)) |
c801d85f | 5034 | { |
5b077d48 | 5035 | return 0; |
e1e955e1 | 5036 | } |
c801d85f | 5037 | |
3cd94a0d | 5038 | long wxGenericListCtrl::HitTest( const wxPoint &point, int &flags ) |
c801d85f | 5039 | { |
5b077d48 | 5040 | return m_mainWin->HitTest( (int)point.x, (int)point.y, flags ); |
e1e955e1 | 5041 | } |
c801d85f | 5042 | |
3cd94a0d | 5043 | long wxGenericListCtrl::InsertItem( wxListItem& info ) |
c801d85f | 5044 | { |
5b077d48 | 5045 | m_mainWin->InsertItem( info ); |
2ebcd5f5 | 5046 | return info.m_itemId; |
e1e955e1 | 5047 | } |
c801d85f | 5048 | |
3cd94a0d | 5049 | long wxGenericListCtrl::InsertItem( long index, const wxString &label ) |
c801d85f | 5050 | { |
51cc4dad RR |
5051 | wxListItem info; |
5052 | info.m_text = label; | |
5053 | info.m_mask = wxLIST_MASK_TEXT; | |
5054 | info.m_itemId = index; | |
5055 | return InsertItem( info ); | |
e1e955e1 | 5056 | } |
c801d85f | 5057 | |
3cd94a0d | 5058 | long wxGenericListCtrl::InsertItem( long index, int imageIndex ) |
c801d85f | 5059 | { |
51cc4dad RR |
5060 | wxListItem info; |
5061 | info.m_mask = wxLIST_MASK_IMAGE; | |
5062 | info.m_image = imageIndex; | |
5063 | info.m_itemId = index; | |
5064 | return InsertItem( info ); | |
e1e955e1 | 5065 | } |
c801d85f | 5066 | |
3cd94a0d | 5067 | long wxGenericListCtrl::InsertItem( long index, const wxString &label, int imageIndex ) |
c801d85f | 5068 | { |
51cc4dad RR |
5069 | wxListItem info; |
5070 | info.m_text = label; | |
5071 | info.m_image = imageIndex; | |
5072 | info.m_mask = wxLIST_MASK_TEXT | wxLIST_MASK_IMAGE; | |
5073 | info.m_itemId = index; | |
5074 | return InsertItem( info ); | |
e1e955e1 | 5075 | } |
c801d85f | 5076 | |
3cd94a0d | 5077 | long wxGenericListCtrl::InsertColumn( long col, wxListItem &item ) |
c801d85f | 5078 | { |
40c08808 VZ |
5079 | wxCHECK_MSG( m_headerWin, -1, _T("can't add column in non report mode") ); |
5080 | ||
51cc4dad | 5081 | m_mainWin->InsertColumn( col, item ); |
40c08808 VZ |
5082 | |
5083 | // if we hadn't had header before and have it now we need to relayout the | |
5084 | // window | |
ac53090c | 5085 | if ( GetColumnCount() == 1 && m_mainWin->HasHeader() ) |
40c08808 VZ |
5086 | { |
5087 | ResizeReportView(TRUE /* have header */); | |
5088 | } | |
5089 | ||
d3e90957 | 5090 | m_headerWin->Refresh(); |
25e3a937 | 5091 | |
51cc4dad | 5092 | return 0; |
e1e955e1 | 5093 | } |
c801d85f | 5094 | |
3cd94a0d | 5095 | long wxGenericListCtrl::InsertColumn( long col, const wxString &heading, |
debe6624 | 5096 | int format, int width ) |
c801d85f | 5097 | { |
51cc4dad RR |
5098 | wxListItem item; |
5099 | item.m_mask = wxLIST_MASK_TEXT | wxLIST_MASK_FORMAT; | |
5100 | item.m_text = heading; | |
5101 | if (width >= -2) | |
5102 | { | |
5103 | item.m_mask |= wxLIST_MASK_WIDTH; | |
5104 | item.m_width = width; | |
5105 | } | |
5106 | item.m_format = format; | |
c801d85f | 5107 | |
51cc4dad | 5108 | return InsertColumn( col, item ); |
e1e955e1 | 5109 | } |
c801d85f | 5110 | |
3cd94a0d | 5111 | bool wxGenericListCtrl::ScrollList( int WXUNUSED(dx), int WXUNUSED(dy) ) |
c801d85f | 5112 | { |
51cc4dad | 5113 | return 0; |
e1e955e1 | 5114 | } |
c801d85f KB |
5115 | |
5116 | // Sort items. | |
5117 | // fn is a function which takes 3 long arguments: item1, item2, data. | |
5118 | // item1 is the long data associated with a first item (NOT the index). | |
5119 | // item2 is the long data associated with a second item (NOT the index). | |
5120 | // data is the same value as passed to SortItems. | |
5121 | // The return value is a negative number if the first item should precede the second | |
5122 | // item, a positive number of the second item should precede the first, | |
5123 | // or zero if the two items are equivalent. | |
5124 | // data is arbitrary data to be passed to the sort function. | |
5125 | ||
3cd94a0d | 5126 | bool wxGenericListCtrl::SortItems( wxListCtrlCompare fn, long data ) |
c801d85f | 5127 | { |
51cc4dad RR |
5128 | m_mainWin->SortItems( fn, data ); |
5129 | return TRUE; | |
e1e955e1 | 5130 | } |
c801d85f | 5131 | |
cf1dfa6b | 5132 | // ---------------------------------------------------------------------------- |
b54e41c5 | 5133 | // event handlers |
cf1dfa6b VZ |
5134 | // ---------------------------------------------------------------------------- |
5135 | ||
3cd94a0d | 5136 | void wxGenericListCtrl::OnSize(wxSizeEvent& WXUNUSED(event)) |
53010e52 | 5137 | { |
b54e41c5 | 5138 | if ( !m_mainWin ) |
cf1dfa6b | 5139 | return; |
53010e52 | 5140 | |
a95cdab8 VZ |
5141 | ResizeReportView(m_mainWin->HasHeader()); |
5142 | ||
5143 | m_mainWin->RecalculatePositions(); | |
5144 | } | |
5145 | ||
3cd94a0d | 5146 | void wxGenericListCtrl::ResizeReportView(bool showHeader) |
a95cdab8 | 5147 | { |
b54e41c5 | 5148 | int cw, ch; |
51cc4dad | 5149 | GetClientSize( &cw, &ch ); |
bd8289c1 | 5150 | |
a95cdab8 | 5151 | if ( showHeader ) |
51cc4dad | 5152 | { |
f8252483 JS |
5153 | m_headerWin->SetSize( 0, 0, cw, m_headerHeight ); |
5154 | m_mainWin->SetSize( 0, m_headerHeight + 1, cw, ch - m_headerHeight - 1 ); | |
51cc4dad | 5155 | } |
cf1dfa6b | 5156 | else // no header window |
51cc4dad | 5157 | { |
cf1dfa6b | 5158 | m_mainWin->SetSize( 0, 0, cw, ch ); |
51cc4dad | 5159 | } |
b54e41c5 | 5160 | } |
cf1dfa6b | 5161 | |
5180055b | 5162 | void wxGenericListCtrl::OnInternalIdle() |
b54e41c5 | 5163 | { |
5180055b | 5164 | wxWindow::OnInternalIdle(); |
86351e4a | 5165 | |
b54e41c5 VZ |
5166 | // do it only if needed |
5167 | if ( !m_mainWin->m_dirty ) | |
5168 | return; | |
5169 | ||
5170 | m_mainWin->RecalculatePositions(); | |
e1e955e1 | 5171 | } |
53010e52 | 5172 | |
cf1dfa6b VZ |
5173 | // ---------------------------------------------------------------------------- |
5174 | // font/colours | |
5175 | // ---------------------------------------------------------------------------- | |
5176 | ||
3cd94a0d | 5177 | bool wxGenericListCtrl::SetBackgroundColour( const wxColour &colour ) |
bd8289c1 | 5178 | { |
51cc4dad RR |
5179 | if (m_mainWin) |
5180 | { | |
5181 | m_mainWin->SetBackgroundColour( colour ); | |
5182 | m_mainWin->m_dirty = TRUE; | |
5183 | } | |
004fd0c8 | 5184 | |
f03fc89f | 5185 | return TRUE; |
e4d06860 RR |
5186 | } |
5187 | ||
3cd94a0d | 5188 | bool wxGenericListCtrl::SetForegroundColour( const wxColour &colour ) |
bd8289c1 | 5189 | { |
f03fc89f VZ |
5190 | if ( !wxWindow::SetForegroundColour( colour ) ) |
5191 | return FALSE; | |
004fd0c8 | 5192 | |
51cc4dad RR |
5193 | if (m_mainWin) |
5194 | { | |
5195 | m_mainWin->SetForegroundColour( colour ); | |
5196 | m_mainWin->m_dirty = TRUE; | |
5197 | } | |
004fd0c8 | 5198 | |
51cc4dad RR |
5199 | if (m_headerWin) |
5200 | { | |
5201 | m_headerWin->SetForegroundColour( colour ); | |
5202 | } | |
f03fc89f VZ |
5203 | |
5204 | return TRUE; | |
e4d06860 | 5205 | } |
bd8289c1 | 5206 | |
3cd94a0d | 5207 | bool wxGenericListCtrl::SetFont( const wxFont &font ) |
bd8289c1 | 5208 | { |
f03fc89f VZ |
5209 | if ( !wxWindow::SetFont( font ) ) |
5210 | return FALSE; | |
004fd0c8 | 5211 | |
51cc4dad RR |
5212 | if (m_mainWin) |
5213 | { | |
5214 | m_mainWin->SetFont( font ); | |
5215 | m_mainWin->m_dirty = TRUE; | |
5216 | } | |
004fd0c8 | 5217 | |
51cc4dad RR |
5218 | if (m_headerWin) |
5219 | { | |
5220 | m_headerWin->SetFont( font ); | |
f8252483 | 5221 | CalculateAndSetHeaderHeight(); |
51cc4dad | 5222 | } |
f03fc89f | 5223 | |
f8252483 JS |
5224 | Refresh(); |
5225 | ||
f03fc89f | 5226 | return TRUE; |
e4d06860 | 5227 | } |
c801d85f | 5228 | |
cf1dfa6b VZ |
5229 | // ---------------------------------------------------------------------------- |
5230 | // methods forwarded to m_mainWin | |
5231 | // ---------------------------------------------------------------------------- | |
5232 | ||
efbb7287 VZ |
5233 | #if wxUSE_DRAG_AND_DROP |
5234 | ||
3cd94a0d | 5235 | void wxGenericListCtrl::SetDropTarget( wxDropTarget *dropTarget ) |
efbb7287 VZ |
5236 | { |
5237 | m_mainWin->SetDropTarget( dropTarget ); | |
5238 | } | |
5239 | ||
3cd94a0d | 5240 | wxDropTarget *wxGenericListCtrl::GetDropTarget() const |
efbb7287 VZ |
5241 | { |
5242 | return m_mainWin->GetDropTarget(); | |
5243 | } | |
5244 | ||
5245 | #endif // wxUSE_DRAG_AND_DROP | |
5246 | ||
3cd94a0d | 5247 | bool wxGenericListCtrl::SetCursor( const wxCursor &cursor ) |
efbb7287 VZ |
5248 | { |
5249 | return m_mainWin ? m_mainWin->wxWindow::SetCursor(cursor) : FALSE; | |
5250 | } | |
5251 | ||
3cd94a0d | 5252 | wxColour wxGenericListCtrl::GetBackgroundColour() const |
efbb7287 VZ |
5253 | { |
5254 | return m_mainWin ? m_mainWin->GetBackgroundColour() : wxColour(); | |
5255 | } | |
5256 | ||
3cd94a0d | 5257 | wxColour wxGenericListCtrl::GetForegroundColour() const |
efbb7287 VZ |
5258 | { |
5259 | return m_mainWin ? m_mainWin->GetForegroundColour() : wxColour(); | |
5260 | } | |
5261 | ||
3cd94a0d | 5262 | bool wxGenericListCtrl::DoPopupMenu( wxMenu *menu, int x, int y ) |
efbb7287 | 5263 | { |
3a8c693a | 5264 | #if wxUSE_MENUS |
efbb7287 | 5265 | return m_mainWin->PopupMenu( menu, x, y ); |
3a8c693a VZ |
5266 | #else |
5267 | return FALSE; | |
5268 | #endif // wxUSE_MENUS | |
efbb7287 VZ |
5269 | } |
5270 | ||
3cd94a0d | 5271 | void wxGenericListCtrl::SetFocus() |
efbb7287 VZ |
5272 | { |
5273 | /* The test in window.cpp fails as we are a composite | |
5274 | window, so it checks against "this", but not m_mainWin. */ | |
5275 | if ( FindFocus() != this ) | |
5276 | m_mainWin->SetFocus(); | |
5277 | } | |
1e6feb95 | 5278 | |
2c1f73ee VZ |
5279 | // ---------------------------------------------------------------------------- |
5280 | // virtual list control support | |
5281 | // ---------------------------------------------------------------------------- | |
5282 | ||
3cd94a0d | 5283 | wxString wxGenericListCtrl::OnGetItemText(long WXUNUSED(item), long WXUNUSED(col)) const |
2c1f73ee VZ |
5284 | { |
5285 | // this is a pure virtual function, in fact - which is not really pure | |
5286 | // because the controls which are not virtual don't need to implement it | |
3cd94a0d | 5287 | wxFAIL_MSG( _T("wxGenericListCtrl::OnGetItemText not supposed to be called") ); |
2c1f73ee VZ |
5288 | |
5289 | return wxEmptyString; | |
5290 | } | |
5291 | ||
3cd94a0d | 5292 | int wxGenericListCtrl::OnGetItemImage(long WXUNUSED(item)) const |
2c1f73ee VZ |
5293 | { |
5294 | // same as above | |
3cd94a0d | 5295 | wxFAIL_MSG( _T("wxGenericListCtrl::OnGetItemImage not supposed to be called") ); |
2c1f73ee VZ |
5296 | |
5297 | return -1; | |
5298 | } | |
5299 | ||
999836aa VZ |
5300 | wxListItemAttr * |
5301 | wxGenericListCtrl::OnGetItemAttr(long WXUNUSED_UNLESS_DEBUG(item)) const | |
6c02c329 VZ |
5302 | { |
5303 | wxASSERT_MSG( item >= 0 && item < GetItemCount(), | |
5304 | _T("invalid item index in OnGetItemAttr()") ); | |
5305 | ||
5306 | // no attributes by default | |
5307 | return NULL; | |
5308 | } | |
5309 | ||
3cd94a0d | 5310 | void wxGenericListCtrl::SetItemCount(long count) |
2c1f73ee VZ |
5311 | { |
5312 | wxASSERT_MSG( IsVirtual(), _T("this is for virtual controls only") ); | |
5313 | ||
5314 | m_mainWin->SetItemCount(count); | |
5315 | } | |
5316 | ||
3cd94a0d | 5317 | void wxGenericListCtrl::RefreshItem(long item) |
1a6cb56f VZ |
5318 | { |
5319 | m_mainWin->RefreshLine(item); | |
5320 | } | |
5321 | ||
3cd94a0d | 5322 | void wxGenericListCtrl::RefreshItems(long itemFrom, long itemTo) |
1a6cb56f VZ |
5323 | { |
5324 | m_mainWin->RefreshLines(itemFrom, itemTo); | |
5325 | } | |
5326 | ||
2f1e3c46 VZ |
5327 | /* |
5328 | * Generic wxListCtrl is more or less a container for two other | |
5329 | * windows which drawings are done upon. These are namely | |
5330 | * 'm_headerWin' and 'm_mainWin'. | |
5331 | * Here we override 'virtual wxWindow::Refresh()' to mimic the | |
5332 | * behaviour wxListCtrl has under wxMSW. | |
5333 | */ | |
5334 | void wxGenericListCtrl::Refresh(bool eraseBackground, const wxRect *rect) | |
5335 | { | |
5336 | if (!rect) | |
5337 | { | |
5338 | // The easy case, no rectangle specified. | |
5339 | if (m_headerWin) | |
5340 | m_headerWin->Refresh(eraseBackground); | |
5341 | ||
5342 | if (m_mainWin) | |
5343 | m_mainWin->Refresh(eraseBackground); | |
5344 | } | |
5345 | else | |
5346 | { | |
5347 | // Refresh the header window | |
5348 | if (m_headerWin) | |
5349 | { | |
5350 | wxRect rectHeader = m_headerWin->GetRect(); | |
5351 | rectHeader.Intersect(*rect); | |
5352 | if (rectHeader.GetWidth() && rectHeader.GetHeight()) | |
5353 | { | |
5354 | int x, y; | |
5355 | m_headerWin->GetPosition(&x, &y); | |
5356 | rectHeader.Offset(-x, -y); | |
5357 | m_headerWin->Refresh(eraseBackground, &rectHeader); | |
5358 | } | |
5359 | ||
5360 | } | |
5361 | ||
5362 | // Refresh the main window | |
5363 | if (m_mainWin) | |
5364 | { | |
5365 | wxRect rectMain = m_mainWin->GetRect(); | |
5366 | rectMain.Intersect(*rect); | |
5367 | if (rectMain.GetWidth() && rectMain.GetHeight()) | |
5368 | { | |
5369 | int x, y; | |
5370 | m_mainWin->GetPosition(&x, &y); | |
5371 | rectMain.Offset(-x, -y); | |
5372 | m_mainWin->Refresh(eraseBackground, &rectMain); | |
5373 | } | |
5374 | } | |
5375 | } | |
5376 | } | |
5377 | ||
3cd94a0d | 5378 | void wxGenericListCtrl::Freeze() |
c5c528fc VZ |
5379 | { |
5380 | m_mainWin->Freeze(); | |
5381 | } | |
5382 | ||
3cd94a0d | 5383 | void wxGenericListCtrl::Thaw() |
c5c528fc VZ |
5384 | { |
5385 | m_mainWin->Thaw(); | |
5386 | } | |
5387 | ||
1e6feb95 | 5388 | #endif // wxUSE_LISTCTRL |
5b98eb2f | 5389 |