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