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