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