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