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