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