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