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