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