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