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