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