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