]>
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; |
ed9a7a63 KO |
1544 | if (m_owner->HasFocus() |
1545 | #ifdef __WXMAC__ | |
1546 | && IsControlActive( (ControlRef)m_owner->GetHandle() ) | |
1547 | #endif | |
1548 | ) | |
05d97538 RR |
1549 | flags |= wxCONTROL_FOCUSED; |
1550 | wxRendererNative::Get().DrawItemSelectionRect( m_owner, *dc, rectHL, flags ); | |
ccdbdc89 RR |
1551 | } |
1552 | else | |
1553 | { | |
1554 | dc->DrawRectangle( rectHL ); | |
1555 | } | |
1556 | } | |
1557 | #endif | |
004fd0c8 | 1558 | |
938b652b | 1559 | wxCoord x = rect.x + HEADER_OFFSET_X, |
ebadbb76 | 1560 | yMid = rect.y + rect.height/2; |
ccdbdc89 RR |
1561 | #ifdef __WXGTK__ |
1562 | // This probably needs to be done | |
1563 | // on all platforms as the icons | |
1564 | // otherwise nearly touch the border | |
1565 | x += 2; | |
1566 | #endif | |
cf1dfa6b | 1567 | |
904ccf52 | 1568 | size_t col = 0; |
222ed1d6 | 1569 | for ( wxListItemDataList::compatibility_iterator node = m_items.GetFirst(); |
904ccf52 VZ |
1570 | node; |
1571 | node = node->GetNext(), col++ ) | |
5cd89174 VZ |
1572 | { |
1573 | wxListItemData *item = node->GetData(); | |
cf1dfa6b | 1574 | |
904ccf52 | 1575 | int width = m_owner->GetColumnWidth(col); |
5cd89174 | 1576 | int xOld = x; |
06b781c7 | 1577 | x += width; |
cf1dfa6b | 1578 | |
5cd89174 VZ |
1579 | if ( item->HasImage() ) |
1580 | { | |
1581 | int ix, iy; | |
5cd89174 | 1582 | m_owner->GetImageSize( item->GetImage(), ix, iy ); |
ebadbb76 | 1583 | m_owner->DrawImage( item->GetImage(), dc, xOld, yMid - iy/2 ); |
cf1dfa6b | 1584 | |
06b781c7 | 1585 | ix += IMAGE_MARGIN_IN_REPORT_MODE; |
cf1dfa6b | 1586 | |
06b781c7 VZ |
1587 | xOld += ix; |
1588 | width -= ix; | |
1589 | } | |
1590 | ||
5cd89174 | 1591 | if ( item->HasText() ) |
ebadbb76 | 1592 | DrawTextFormatted(dc, item->GetText(), col, xOld, yMid, width - 8); |
2b5f62a0 VZ |
1593 | } |
1594 | } | |
1595 | ||
1596 | void wxListLineData::DrawTextFormatted(wxDC *dc, | |
359fb29e | 1597 | const wxString& textOrig, |
2b5f62a0 VZ |
1598 | int col, |
1599 | int x, | |
ebadbb76 | 1600 | int yMid, |
2b5f62a0 VZ |
1601 | int width) |
1602 | { | |
359fb29e VZ |
1603 | // we don't support displaying multiple lines currently (and neither does |
1604 | // wxMSW FWIW) so just merge all the lines | |
1605 | wxString text(textOrig); | |
1606 | text.Replace(_T("\n"), _T(" ")); | |
1607 | ||
ebadbb76 VZ |
1608 | wxCoord w, h; |
1609 | dc->GetTextExtent(text, &w, &h); | |
1610 | ||
1611 | const wxCoord y = yMid - (h + 1)/2; | |
1612 | ||
1613 | wxDCClipper clipper(*dc, x, y, width, h); | |
2b5f62a0 VZ |
1614 | |
1615 | // determine if the string can fit inside the current width | |
2b5f62a0 VZ |
1616 | if (w <= width) |
1617 | { | |
e1e1272f | 1618 | // it can, draw it using the items alignment |
ebadbb76 | 1619 | wxListItem item; |
2b5f62a0 | 1620 | m_owner->GetColumn(col, item); |
e1e1272f VZ |
1621 | switch ( item.GetAlign() ) |
1622 | { | |
e1e1272f VZ |
1623 | case wxLIST_FORMAT_LEFT: |
1624 | // nothing to do | |
1625 | break; | |
1626 | ||
1627 | case wxLIST_FORMAT_RIGHT: | |
1628 | x += width - w; | |
1629 | break; | |
1630 | ||
1631 | case wxLIST_FORMAT_CENTER: | |
1632 | x += (width - w) / 2; | |
1633 | break; | |
277ea1b4 DS |
1634 | |
1635 | default: | |
1636 | wxFAIL_MSG( _T("unknown list item format") ); | |
1637 | break; | |
e1e1272f VZ |
1638 | } |
1639 | ||
1640 | dc->DrawText(text, x, y); | |
2b5f62a0 VZ |
1641 | } |
1642 | else // otherwise, truncate and add an ellipsis if possible | |
1643 | { | |
1644 | // determine the base width | |
ebadbb76 VZ |
1645 | wxString ellipsis(wxT("...")); |
1646 | wxCoord base_w; | |
2b5f62a0 VZ |
1647 | dc->GetTextExtent(ellipsis, &base_w, &h); |
1648 | ||
1649 | // continue until we have enough space or only one character left | |
5175dbbd | 1650 | wxCoord w_c, h_c; |
faa94f3e | 1651 | size_t len = text.length(); |
ebadbb76 | 1652 | wxString drawntext = text.Left(len); |
5175dbbd | 1653 | while (len > 1) |
2b5f62a0 | 1654 | { |
5175dbbd VS |
1655 | dc->GetTextExtent(drawntext.Last(), &w_c, &h_c); |
1656 | drawntext.RemoveLast(); | |
1657 | len--; | |
1658 | w -= w_c; | |
2b5f62a0 VZ |
1659 | if (w + base_w <= width) |
1660 | break; | |
2b5f62a0 VZ |
1661 | } |
1662 | ||
1663 | // if still not enough space, remove ellipsis characters | |
faa94f3e | 1664 | while (ellipsis.length() > 0 && w + base_w > width) |
2b5f62a0 | 1665 | { |
faa94f3e | 1666 | ellipsis = ellipsis.Left(ellipsis.length() - 1); |
2b5f62a0 | 1667 | dc->GetTextExtent(ellipsis, &base_w, &h); |
5cd89174 | 1668 | } |
2b5f62a0 VZ |
1669 | |
1670 | // now draw the text | |
1671 | dc->DrawText(drawntext, x, y); | |
1672 | dc->DrawText(ellipsis, x + w, y); | |
e1e955e1 | 1673 | } |
e1e955e1 | 1674 | } |
c801d85f | 1675 | |
b54e41c5 | 1676 | bool wxListLineData::Highlight( bool on ) |
c801d85f | 1677 | { |
ca65c044 | 1678 | wxCHECK_MSG( !IsVirtual(), false, _T("unexpected call to Highlight") ); |
c801d85f | 1679 | |
b54e41c5 | 1680 | if ( on == m_highlighted ) |
ca65c044 | 1681 | return false; |
c801d85f | 1682 | |
b54e41c5 | 1683 | m_highlighted = on; |
c801d85f | 1684 | |
ca65c044 | 1685 | return true; |
e1e955e1 | 1686 | } |
c801d85f | 1687 | |
b54e41c5 | 1688 | void wxListLineData::ReverseHighlight( void ) |
c801d85f | 1689 | { |
b54e41c5 | 1690 | Highlight(!IsHighlighted()); |
e1e955e1 | 1691 | } |
c801d85f KB |
1692 | |
1693 | //----------------------------------------------------------------------------- | |
1694 | // wxListHeaderWindow | |
1695 | //----------------------------------------------------------------------------- | |
1696 | ||
5a1cad6e | 1697 | IMPLEMENT_DYNAMIC_CLASS(wxListHeaderWindow,wxWindow) |
c801d85f KB |
1698 | |
1699 | BEGIN_EVENT_TABLE(wxListHeaderWindow,wxWindow) | |
63852e78 RR |
1700 | EVT_PAINT (wxListHeaderWindow::OnPaint) |
1701 | EVT_MOUSE_EVENTS (wxListHeaderWindow::OnMouse) | |
1702 | EVT_SET_FOCUS (wxListHeaderWindow::OnSetFocus) | |
c801d85f KB |
1703 | END_EVENT_TABLE() |
1704 | ||
0a816d95 | 1705 | void wxListHeaderWindow::Init() |
c801d85f | 1706 | { |
63852e78 | 1707 | m_currentCursor = (wxCursor *) NULL; |
ca65c044 WS |
1708 | m_isDragging = false; |
1709 | m_dirty = false; | |
0a816d95 VZ |
1710 | } |
1711 | ||
1712 | wxListHeaderWindow::wxListHeaderWindow() | |
1713 | { | |
1714 | Init(); | |
1715 | ||
1716 | m_owner = (wxListMainWindow *) NULL; | |
1717 | m_resizeCursor = (wxCursor *) NULL; | |
e1e955e1 | 1718 | } |
c801d85f | 1719 | |
0a816d95 VZ |
1720 | wxListHeaderWindow::wxListHeaderWindow( wxWindow *win, |
1721 | wxWindowID id, | |
1722 | wxListMainWindow *owner, | |
1723 | const wxPoint& pos, | |
1724 | const wxSize& size, | |
1725 | long style, | |
1726 | const wxString &name ) | |
1727 | : wxWindow( win, id, pos, size, style, name ) | |
c801d85f | 1728 | { |
0a816d95 VZ |
1729 | Init(); |
1730 | ||
63852e78 | 1731 | m_owner = owner; |
63852e78 | 1732 | m_resizeCursor = new wxCursor( wxCURSOR_SIZEWE ); |
f6bcfd97 | 1733 | |
35d4c967 | 1734 | #if _USE_VISATTR |
ca65c044 | 1735 | wxVisualAttributes attr = wxPanel::GetClassDefaultAttributes(); |
fa47d7a7 VS |
1736 | SetOwnForegroundColour( attr.colFg ); |
1737 | SetOwnBackgroundColour( attr.colBg ); | |
92a4e4de VZ |
1738 | if (!m_hasFont) |
1739 | SetOwnFont( attr.font ); | |
35d4c967 | 1740 | #else |
fa47d7a7 VS |
1741 | SetOwnForegroundColour( wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT)); |
1742 | SetOwnBackgroundColour( wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE)); | |
92a4e4de VZ |
1743 | if (!m_hasFont) |
1744 | SetOwnFont( wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT )); | |
35d4c967 | 1745 | #endif |
e1e955e1 | 1746 | } |
c801d85f | 1747 | |
0a816d95 | 1748 | wxListHeaderWindow::~wxListHeaderWindow() |
a367b9b3 | 1749 | { |
63852e78 | 1750 | delete m_resizeCursor; |
a367b9b3 JS |
1751 | } |
1752 | ||
2b5f62a0 VZ |
1753 | #ifdef __WXUNIVERSAL__ |
1754 | #include "wx/univ/renderer.h" | |
1755 | #include "wx/univ/theme.h" | |
1756 | #endif | |
1757 | ||
f6bcfd97 BP |
1758 | // shift the DC origin to match the position of the main window horz |
1759 | // scrollbar: this allows us to always use logical coords | |
1760 | void wxListHeaderWindow::AdjustDC(wxDC& dc) | |
1761 | { | |
f6bcfd97 BP |
1762 | int xpix; |
1763 | m_owner->GetScrollPixelsPerUnit( &xpix, NULL ); | |
1764 | ||
5eefe029 RR |
1765 | int view_start; |
1766 | m_owner->GetViewStart( &view_start, NULL ); | |
1767 | ||
5eefe029 RR |
1768 | |
1769 | int org_x = 0; | |
1770 | int org_y = 0; | |
1771 | dc.GetDeviceOrigin( &org_x, &org_y ); | |
f6bcfd97 BP |
1772 | |
1773 | // account for the horz scrollbar offset | |
807a572e RR |
1774 | #ifdef __WXGTK__ |
1775 | if (GetLayoutDirection() == wxLayout_RightToLeft) | |
1776 | { | |
1777 | // Maybe we just have to check for m_signX | |
1778 | // in the DC, but I leave the #ifdef __WXGTK__ | |
1779 | // for now | |
1780 | dc.SetDeviceOrigin( org_x + (view_start * xpix), org_y ); | |
1781 | } | |
1782 | else | |
1783 | #endif | |
1784 | dc.SetDeviceOrigin( org_x - (view_start * xpix), org_y ); | |
f6bcfd97 BP |
1785 | } |
1786 | ||
c801d85f KB |
1787 | void wxListHeaderWindow::OnPaint( wxPaintEvent &WXUNUSED(event) ) |
1788 | { | |
63852e78 | 1789 | wxPaintDC dc( this ); |
10bd0724 | 1790 | |
63852e78 | 1791 | PrepareDC( dc ); |
f6bcfd97 | 1792 | AdjustDC( dc ); |
bffa1c77 | 1793 | |
63852e78 | 1794 | dc.SetFont( GetFont() ); |
bd8289c1 | 1795 | |
f6bcfd97 BP |
1796 | // width and height of the entire header window |
1797 | int w, h; | |
63852e78 | 1798 | GetClientSize( &w, &h ); |
f6bcfd97 | 1799 | m_owner->CalcUnscrolledPosition(w, 0, &w, NULL); |
c801d85f | 1800 | |
f60d0f94 | 1801 | dc.SetBackgroundMode(wxTRANSPARENT); |
35d4c967 | 1802 | dc.SetTextForeground(GetForegroundColour()); |
ca65c044 | 1803 | |
cf1dfa6b | 1804 | int x = HEADER_OFFSET_X; |
63852e78 RR |
1805 | int numColumns = m_owner->GetColumnCount(); |
1806 | wxListItem item; | |
c5b7bb59 | 1807 | for ( int i = 0; i < numColumns && x < w; i++ ) |
63852e78 RR |
1808 | { |
1809 | m_owner->GetColumn( i, item ); | |
f6bcfd97 | 1810 | int wCol = item.m_width; |
f6bcfd97 | 1811 | |
277ea1b4 DS |
1812 | int cw = wCol; |
1813 | int ch = h; | |
277ea1b4 | 1814 | |
df0edf44 KO |
1815 | int flags = 0; |
1816 | if (!m_parent->IsEnabled()) | |
1817 | flags |= wxCONTROL_DISABLED; | |
1818 | ||
6fef2483 | 1819 | // NB: The code below is not really Mac-specific, but since we are close |
df0edf44 KO |
1820 | // to 2.8 release and I don't have time to test on other platforms, I |
1821 | // defined this only for wxMac. If this behavior is desired on | |
1822 | // other platforms, please go ahead and revise or remove the #ifdef. | |
1823 | #ifdef __WXMAC__ | |
6fef2483 | 1824 | if ( !m_owner->IsVirtual() && (item.m_mask & wxLIST_MASK_STATE) && |
df0edf44 KO |
1825 | (item.m_state & wxLIST_STATE_SELECTED) ) |
1826 | flags |= wxCONTROL_SELECTED; | |
1827 | #endif | |
1828 | ||
9c7f49f5 VZ |
1829 | wxRendererNative::Get().DrawHeaderButton |
1830 | ( | |
1831 | this, | |
1832 | dc, | |
d108f236 | 1833 | wxRect(x, HEADER_OFFSET_Y, cw, ch), |
df0edf44 | 1834 | flags |
9c7f49f5 | 1835 | ); |
0a816d95 | 1836 | |
e1e1272f VZ |
1837 | // see if we have enough space for the column label |
1838 | ||
1839 | // for this we need the width of the text | |
1840 | wxCoord wLabel; | |
ca65c044 | 1841 | wxCoord hLabel; |
cabeffb0 | 1842 | dc.GetTextExtent(item.GetText(), &wLabel, &hLabel); |
277ea1b4 | 1843 | wLabel += 2 * EXTRA_WIDTH; |
e1e1272f VZ |
1844 | |
1845 | // and the width of the icon, if any | |
277ea1b4 | 1846 | int ix = 0, iy = 0; // init them just to suppress the compiler warnings |
e1e1272f | 1847 | const int image = item.m_image; |
8a3e173a | 1848 | wxImageList *imageList; |
0a816d95 VZ |
1849 | if ( image != -1 ) |
1850 | { | |
e1e1272f | 1851 | imageList = m_owner->m_small_image_list; |
0a816d95 VZ |
1852 | if ( imageList ) |
1853 | { | |
0a816d95 | 1854 | imageList->GetSize(image, ix, iy); |
936632d3 | 1855 | wLabel += ix + HEADER_IMAGE_MARGIN_IN_REPORT_MODE; |
e1e1272f VZ |
1856 | } |
1857 | } | |
1858 | else | |
1859 | { | |
1860 | imageList = NULL; | |
1861 | } | |
1862 | ||
1863 | // ignore alignment if there is not enough space anyhow | |
1864 | int xAligned; | |
1865 | switch ( wLabel < cw ? item.GetAlign() : wxLIST_FORMAT_LEFT ) | |
1866 | { | |
1867 | default: | |
1868 | wxFAIL_MSG( _T("unknown list item format") ); | |
1869 | // fall through | |
0a816d95 | 1870 | |
e1e1272f VZ |
1871 | case wxLIST_FORMAT_LEFT: |
1872 | xAligned = x; | |
1873 | break; | |
0a816d95 | 1874 | |
e1e1272f VZ |
1875 | case wxLIST_FORMAT_RIGHT: |
1876 | xAligned = x + cw - wLabel; | |
1877 | break; | |
1878 | ||
1879 | case wxLIST_FORMAT_CENTER: | |
1880 | xAligned = x + (cw - wLabel) / 2; | |
1881 | break; | |
1882 | } | |
1883 | ||
936632d3 VZ |
1884 | // draw the text and image clipping them so that they |
1885 | // don't overwrite the column boundary | |
1886 | wxDCClipper clipper(dc, x, HEADER_OFFSET_Y, cw, h - 4 ); | |
1887 | ||
e1e1272f VZ |
1888 | // if we have an image, draw it on the right of the label |
1889 | if ( imageList ) | |
1890 | { | |
1891 | imageList->Draw | |
1892 | ( | |
1893 | image, | |
1894 | dc, | |
936632d3 | 1895 | xAligned + wLabel - ix - HEADER_IMAGE_MARGIN_IN_REPORT_MODE, |
e1e1272f VZ |
1896 | HEADER_OFFSET_Y + (h - 4 - iy)/2, |
1897 | wxIMAGELIST_DRAW_TRANSPARENT | |
1898 | ); | |
0a816d95 VZ |
1899 | } |
1900 | ||
06b781c7 | 1901 | dc.DrawText( item.GetText(), |
cabeffb0 | 1902 | xAligned + EXTRA_WIDTH, h / 2 - hLabel / 2 ); //HEADER_OFFSET_Y + EXTRA_HEIGHT ); |
06b781c7 | 1903 | |
0a816d95 | 1904 | x += wCol; |
63852e78 | 1905 | } |
e1e955e1 | 1906 | } |
c801d85f | 1907 | |
0208334d RR |
1908 | void wxListHeaderWindow::DrawCurrent() |
1909 | { | |
b46ea782 RR |
1910 | #if 1 |
1911 | m_owner->SetColumnWidth( m_column, m_currentX - m_minX ); | |
1912 | #else | |
63852e78 RR |
1913 | int x1 = m_currentX; |
1914 | int y1 = 0; | |
f16ba4e6 | 1915 | m_owner->ClientToScreen( &x1, &y1 ); |
f6bcfd97 | 1916 | |
f16ba4e6 | 1917 | int x2 = m_currentX; |
63852e78 | 1918 | int y2 = 0; |
f6bcfd97 | 1919 | m_owner->GetClientSize( NULL, &y2 ); |
63852e78 | 1920 | m_owner->ClientToScreen( &x2, &y2 ); |
0208334d | 1921 | |
63852e78 | 1922 | wxScreenDC dc; |
3c679789 | 1923 | dc.SetLogicalFunction( wxINVERT ); |
63852e78 RR |
1924 | dc.SetPen( wxPen( *wxBLACK, 2, wxSOLID ) ); |
1925 | dc.SetBrush( *wxTRANSPARENT_BRUSH ); | |
0208334d | 1926 | |
f6bcfd97 BP |
1927 | AdjustDC(dc); |
1928 | ||
63852e78 | 1929 | dc.DrawLine( x1, y1, x2, y2 ); |
0208334d | 1930 | |
63852e78 | 1931 | dc.SetLogicalFunction( wxCOPY ); |
0208334d | 1932 | |
63852e78 RR |
1933 | dc.SetPen( wxNullPen ); |
1934 | dc.SetBrush( wxNullBrush ); | |
b46ea782 | 1935 | #endif |
0208334d RR |
1936 | } |
1937 | ||
c801d85f KB |
1938 | void wxListHeaderWindow::OnMouse( wxMouseEvent &event ) |
1939 | { | |
f6bcfd97 | 1940 | // we want to work with logical coords |
3ca6a5f0 BP |
1941 | int x; |
1942 | m_owner->CalcUnscrolledPosition(event.GetX(), 0, &x, NULL); | |
3ca6a5f0 | 1943 | int y = event.GetY(); |
f6bcfd97 | 1944 | |
cfb50f14 | 1945 | if (m_isDragging) |
0208334d | 1946 | { |
355f2407 | 1947 | SendListEvent(wxEVT_COMMAND_LIST_COL_DRAGGING, event.GetPosition()); |
a77ec46d | 1948 | |
f6bcfd97 BP |
1949 | // we don't draw the line beyond our window, but we allow dragging it |
1950 | // there | |
1951 | int w = 0; | |
1952 | GetClientSize( &w, NULL ); | |
f6bcfd97 | 1953 | m_owner->CalcUnscrolledPosition(w, 0, &w, NULL); |
f6bcfd97 BP |
1954 | w -= 6; |
1955 | ||
1956 | // erase the line if it was drawn | |
1957 | if ( m_currentX < w ) | |
1958 | DrawCurrent(); | |
1959 | ||
63852e78 RR |
1960 | if (event.ButtonUp()) |
1961 | { | |
1962 | ReleaseMouse(); | |
ca65c044 WS |
1963 | m_isDragging = false; |
1964 | m_dirty = true; | |
f6bcfd97 | 1965 | m_owner->SetColumnWidth( m_column, m_currentX - m_minX ); |
355f2407 | 1966 | SendListEvent(wxEVT_COMMAND_LIST_COL_END_DRAG, event.GetPosition()); |
63852e78 RR |
1967 | } |
1968 | else | |
1969 | { | |
f6bcfd97 | 1970 | if (x > m_minX + 7) |
63852e78 RR |
1971 | m_currentX = x; |
1972 | else | |
f6bcfd97 | 1973 | m_currentX = m_minX + 7; |
bd8289c1 | 1974 | |
f6bcfd97 BP |
1975 | // draw in the new location |
1976 | if ( m_currentX < w ) | |
1977 | DrawCurrent(); | |
bffa1c77 | 1978 | } |
0208334d | 1979 | } |
f6bcfd97 | 1980 | else // not dragging |
c801d85f | 1981 | { |
f6bcfd97 | 1982 | m_minX = 0; |
ca65c044 | 1983 | bool hit_border = false; |
f6bcfd97 BP |
1984 | |
1985 | // end of the current column | |
1986 | int xpos = 0; | |
1987 | ||
3103e8a9 | 1988 | // find the column where this event occurred |
62313c27 VZ |
1989 | int col, |
1990 | countCol = m_owner->GetColumnCount(); | |
1991 | for (col = 0; col < countCol; col++) | |
bffa1c77 | 1992 | { |
cf1dfa6b VZ |
1993 | xpos += m_owner->GetColumnWidth( col ); |
1994 | m_column = col; | |
f6bcfd97 BP |
1995 | |
1996 | if ( (abs(x-xpos) < 3) && (y < 22) ) | |
1997 | { | |
1998 | // near the column border | |
ca65c044 | 1999 | hit_border = true; |
f6bcfd97 BP |
2000 | break; |
2001 | } | |
2002 | ||
2003 | if ( x < xpos ) | |
2004 | { | |
2005 | // inside the column | |
2006 | break; | |
2007 | } | |
2008 | ||
2009 | m_minX = xpos; | |
bffa1c77 | 2010 | } |
63852e78 | 2011 | |
62313c27 VZ |
2012 | if ( col == countCol ) |
2013 | m_column = -1; | |
2014 | ||
11358d39 | 2015 | if (event.LeftDown() || event.RightUp()) |
63852e78 | 2016 | { |
11358d39 | 2017 | if (hit_border && event.LeftDown()) |
f6bcfd97 | 2018 | { |
355f2407 VZ |
2019 | if ( SendListEvent(wxEVT_COMMAND_LIST_COL_BEGIN_DRAG, |
2020 | event.GetPosition()) ) | |
2021 | { | |
ca65c044 | 2022 | m_isDragging = true; |
355f2407 | 2023 | m_currentX = x; |
355f2407 | 2024 | CaptureMouse(); |
03eccb83 | 2025 | DrawCurrent(); |
355f2407 VZ |
2026 | } |
2027 | //else: column resizing was vetoed by the user code | |
f6bcfd97 | 2028 | } |
11358d39 | 2029 | else // click on a column |
f6bcfd97 | 2030 | { |
df0edf44 KO |
2031 | // record the selected state of the columns |
2032 | if (event.LeftDown()) | |
2033 | { | |
2034 | for (int i=0; i < m_owner->GetColumnCount(); i++) | |
2035 | { | |
2036 | wxListItem colItem; | |
2037 | m_owner->GetColumn(i, colItem); | |
6fef2483 | 2038 | long state = colItem.GetState(); |
df0edf44 KO |
2039 | if (i == m_column) |
2040 | colItem.SetState(state | wxLIST_STATE_SELECTED); | |
2041 | else | |
2042 | colItem.SetState(state & ~wxLIST_STATE_SELECTED); | |
2043 | m_owner->SetColumn(i, colItem); | |
2044 | } | |
2045 | } | |
6fef2483 | 2046 | |
a77ec46d | 2047 | SendListEvent( event.LeftDown() |
11358d39 VZ |
2048 | ? wxEVT_COMMAND_LIST_COL_CLICK |
2049 | : wxEVT_COMMAND_LIST_COL_RIGHT_CLICK, | |
a77ec46d | 2050 | event.GetPosition()); |
f6bcfd97 | 2051 | } |
63852e78 | 2052 | } |
f6bcfd97 | 2053 | else if (event.Moving()) |
63852e78 | 2054 | { |
f6bcfd97 BP |
2055 | bool setCursor; |
2056 | if (hit_border) | |
2057 | { | |
2058 | setCursor = m_currentCursor == wxSTANDARD_CURSOR; | |
2059 | m_currentCursor = m_resizeCursor; | |
2060 | } | |
2061 | else | |
2062 | { | |
2063 | setCursor = m_currentCursor != wxSTANDARD_CURSOR; | |
2064 | m_currentCursor = wxSTANDARD_CURSOR; | |
2065 | } | |
2066 | ||
2067 | if ( setCursor ) | |
2068 | SetCursor(*m_currentCursor); | |
63852e78 | 2069 | } |
e1e955e1 | 2070 | } |
e1e955e1 | 2071 | } |
c801d85f KB |
2072 | |
2073 | void wxListHeaderWindow::OnSetFocus( wxFocusEvent &WXUNUSED(event) ) | |
2074 | { | |
63852e78 | 2075 | m_owner->SetFocus(); |
03eccb83 | 2076 | m_owner->Update(); |
e1e955e1 | 2077 | } |
c801d85f | 2078 | |
fbfb8bcc | 2079 | bool wxListHeaderWindow::SendListEvent(wxEventType type, const wxPoint& pos) |
a77ec46d RD |
2080 | { |
2081 | wxWindow *parent = GetParent(); | |
2082 | wxListEvent le( type, parent->GetId() ); | |
2083 | le.SetEventObject( parent ); | |
2084 | le.m_pointDrag = pos; | |
2085 | ||
2086 | // the position should be relative to the parent window, not | |
2087 | // this one for compatibility with MSW and common sense: the | |
2088 | // user code doesn't know anything at all about this header | |
2089 | // window, so why should it get positions relative to it? | |
2090 | le.m_pointDrag.y -= GetSize().y; | |
2091 | ||
2092 | le.m_col = m_column; | |
355f2407 | 2093 | return !parent->GetEventHandler()->ProcessEvent( le ) || le.IsAllowed(); |
a77ec46d RD |
2094 | } |
2095 | ||
c801d85f KB |
2096 | //----------------------------------------------------------------------------- |
2097 | // wxListRenameTimer (internal) | |
2098 | //----------------------------------------------------------------------------- | |
2099 | ||
bd8289c1 VZ |
2100 | wxListRenameTimer::wxListRenameTimer( wxListMainWindow *owner ) |
2101 | { | |
63852e78 | 2102 | m_owner = owner; |
e1e955e1 | 2103 | } |
c801d85f | 2104 | |
bd8289c1 VZ |
2105 | void wxListRenameTimer::Notify() |
2106 | { | |
63852e78 | 2107 | m_owner->OnRenameTimer(); |
e1e955e1 | 2108 | } |
c801d85f | 2109 | |
ee7ee469 | 2110 | //----------------------------------------------------------------------------- |
26e8da41 | 2111 | // wxListTextCtrlWrapper (internal) |
ee7ee469 RR |
2112 | //----------------------------------------------------------------------------- |
2113 | ||
26e8da41 VZ |
2114 | BEGIN_EVENT_TABLE(wxListTextCtrlWrapper, wxEvtHandler) |
2115 | EVT_CHAR (wxListTextCtrlWrapper::OnChar) | |
2116 | EVT_KEY_UP (wxListTextCtrlWrapper::OnKeyUp) | |
2117 | EVT_KILL_FOCUS (wxListTextCtrlWrapper::OnKillFocus) | |
ee7ee469 RR |
2118 | END_EVENT_TABLE() |
2119 | ||
26e8da41 VZ |
2120 | wxListTextCtrlWrapper::wxListTextCtrlWrapper(wxListMainWindow *owner, |
2121 | wxTextCtrl *text, | |
2122 | size_t itemEdit) | |
62d89eb4 VZ |
2123 | : m_startValue(owner->GetItemText(itemEdit)), |
2124 | m_itemEdited(itemEdit) | |
2125 | { | |
63852e78 | 2126 | m_owner = owner; |
26e8da41 | 2127 | m_text = text; |
ca65c044 | 2128 | m_finished = false; |
33fe475a | 2129 | m_aboutToFinish = false; |
62d89eb4 VZ |
2130 | |
2131 | wxRect rectLabel = owner->GetLineLabelRect(itemEdit); | |
2132 | ||
2133 | m_owner->CalcScrolledPosition(rectLabel.x, rectLabel.y, | |
2134 | &rectLabel.x, &rectLabel.y); | |
2135 | ||
26e8da41 VZ |
2136 | m_text->Create(owner, wxID_ANY, m_startValue, |
2137 | wxPoint(rectLabel.x-4,rectLabel.y-4), | |
2138 | wxSize(rectLabel.width+11,rectLabel.height+8)); | |
3603a389 | 2139 | m_text->SetFocus(); |
cf76cd4e | 2140 | |
26e8da41 | 2141 | m_text->PushEventHandler(this); |
ee7ee469 RR |
2142 | } |
2143 | ||
26e8da41 | 2144 | void wxListTextCtrlWrapper::Finish() |
ee7ee469 | 2145 | { |
62d89eb4 | 2146 | if ( !m_finished ) |
63852e78 | 2147 | { |
ca65c044 | 2148 | m_finished = true; |
62d89eb4 | 2149 | |
75ae9acf | 2150 | m_text->RemoveEventHandler(this); |
26e8da41 VZ |
2151 | m_owner->FinishEditing(m_text); |
2152 | ||
3603a389 | 2153 | wxPendingDelete.Append( this ); |
62d89eb4 VZ |
2154 | } |
2155 | } | |
dd5a32cc | 2156 | |
26e8da41 | 2157 | bool wxListTextCtrlWrapper::AcceptChanges() |
62d89eb4 | 2158 | { |
26e8da41 | 2159 | const wxString value = m_text->GetValue(); |
62d89eb4 | 2160 | |
0a904ed2 VZ |
2161 | // notice that we should always call OnRenameAccept() to generate the "end |
2162 | // label editing" event, even if the user hasn't really changed anything | |
62d89eb4 | 2163 | if ( !m_owner->OnRenameAccept(m_itemEdited, value) ) |
0a904ed2 | 2164 | { |
62d89eb4 | 2165 | // vetoed by the user |
ca65c044 | 2166 | return false; |
0a904ed2 | 2167 | } |
f6bcfd97 | 2168 | |
0a904ed2 VZ |
2169 | // accepted, do rename the item (unless nothing changed) |
2170 | if ( value != m_startValue ) | |
2171 | m_owner->SetItemText(m_itemEdited, value); | |
f6bcfd97 | 2172 | |
ca65c044 | 2173 | return true; |
62d89eb4 | 2174 | } |
dd5a32cc | 2175 | |
26e8da41 | 2176 | void wxListTextCtrlWrapper::AcceptChangesAndFinish() |
b6bc47ef RD |
2177 | { |
2178 | m_aboutToFinish = true; | |
277ea1b4 | 2179 | |
b6bc47ef RD |
2180 | // Notify the owner about the changes |
2181 | AcceptChanges(); | |
277ea1b4 | 2182 | |
b6bc47ef RD |
2183 | // Even if vetoed, close the control (consistent with MSW) |
2184 | Finish(); | |
2185 | } | |
2186 | ||
26e8da41 | 2187 | void wxListTextCtrlWrapper::OnChar( wxKeyEvent &event ) |
62d89eb4 VZ |
2188 | { |
2189 | switch ( event.m_keyCode ) | |
2190 | { | |
2191 | case WXK_RETURN: | |
b6bc47ef | 2192 | AcceptChangesAndFinish(); |
768276f6 | 2193 | break; |
f6bcfd97 | 2194 | |
62d89eb4 | 2195 | case WXK_ESCAPE: |
86586459 | 2196 | m_owner->OnRenameCancelled( m_itemEdited ); |
3603a389 | 2197 | Finish(); |
62d89eb4 VZ |
2198 | break; |
2199 | ||
2200 | default: | |
2201 | event.Skip(); | |
2202 | } | |
63852e78 RR |
2203 | } |
2204 | ||
26e8da41 | 2205 | void wxListTextCtrlWrapper::OnKeyUp( wxKeyEvent &event ) |
c13cace1 | 2206 | { |
dd5a32cc RR |
2207 | if (m_finished) |
2208 | { | |
2209 | event.Skip(); | |
2210 | return; | |
2211 | } | |
2212 | ||
c13cace1 VS |
2213 | // auto-grow the textctrl: |
2214 | wxSize parentSize = m_owner->GetSize(); | |
26e8da41 VZ |
2215 | wxPoint myPos = m_text->GetPosition(); |
2216 | wxSize mySize = m_text->GetSize(); | |
c13cace1 | 2217 | int sx, sy; |
26e8da41 | 2218 | m_text->GetTextExtent(m_text->GetValue() + _T("MM"), &sx, &sy); |
cf1dfa6b VZ |
2219 | if (myPos.x + sx > parentSize.x) |
2220 | sx = parentSize.x - myPos.x; | |
2221 | if (mySize.x > sx) | |
2222 | sx = mySize.x; | |
26e8da41 | 2223 | m_text->SetSize(sx, wxDefaultCoord); |
2c1f73ee | 2224 | |
c13cace1 VS |
2225 | event.Skip(); |
2226 | } | |
2227 | ||
26e8da41 | 2228 | void wxListTextCtrlWrapper::OnKillFocus( wxFocusEvent &event ) |
63852e78 | 2229 | { |
277ea1b4 | 2230 | if ( !m_finished && !m_aboutToFinish ) |
dd5a32cc | 2231 | { |
86586459 RR |
2232 | if ( !AcceptChanges() ) |
2233 | m_owner->OnRenameCancelled( m_itemEdited ); | |
cf76cd4e | 2234 | |
3603a389 | 2235 | Finish(); |
62d89eb4 | 2236 | } |
86351e4a | 2237 | |
3603a389 | 2238 | // We must let the native text control handle focus |
62d89eb4 | 2239 | event.Skip(); |
ee7ee469 RR |
2240 | } |
2241 | ||
c801d85f KB |
2242 | //----------------------------------------------------------------------------- |
2243 | // wxListMainWindow | |
2244 | //----------------------------------------------------------------------------- | |
2245 | ||
5a1cad6e | 2246 | IMPLEMENT_DYNAMIC_CLASS(wxListMainWindow,wxScrolledWindow) |
bd8289c1 | 2247 | |
c801d85f KB |
2248 | BEGIN_EVENT_TABLE(wxListMainWindow,wxScrolledWindow) |
2249 | EVT_PAINT (wxListMainWindow::OnPaint) | |
c801d85f KB |
2250 | EVT_MOUSE_EVENTS (wxListMainWindow::OnMouse) |
2251 | EVT_CHAR (wxListMainWindow::OnChar) | |
3dfb93fd | 2252 | EVT_KEY_DOWN (wxListMainWindow::OnKeyDown) |
6fef2483 | 2253 | EVT_KEY_UP (wxListMainWindow::OnKeyUp) |
c801d85f KB |
2254 | EVT_SET_FOCUS (wxListMainWindow::OnSetFocus) |
2255 | EVT_KILL_FOCUS (wxListMainWindow::OnKillFocus) | |
2fa7c206 | 2256 | EVT_SCROLLWIN (wxListMainWindow::OnScroll) |
c801d85f KB |
2257 | END_EVENT_TABLE() |
2258 | ||
1370703e | 2259 | void wxListMainWindow::Init() |
c801d85f | 2260 | { |
ca65c044 | 2261 | m_dirty = true; |
cf1dfa6b VZ |
2262 | m_countVirt = 0; |
2263 | m_lineFrom = | |
b54e41c5 | 2264 | m_lineTo = (size_t)-1; |
cf1dfa6b VZ |
2265 | m_linesPerPage = 0; |
2266 | ||
2267 | m_headerWidth = | |
2268 | m_lineHeight = 0; | |
1370703e | 2269 | |
8a3e173a KO |
2270 | m_small_image_list = (wxImageList *) NULL; |
2271 | m_normal_image_list = (wxImageList *) NULL; | |
1370703e | 2272 | |
139adb6a RR |
2273 | m_small_spacing = 30; |
2274 | m_normal_spacing = 40; | |
1370703e | 2275 | |
ca65c044 | 2276 | m_hasFocus = false; |
1370703e | 2277 | m_dragCount = 0; |
ca65c044 | 2278 | m_isCreated = false; |
1370703e | 2279 | |
ca65c044 | 2280 | m_lastOnSame = false; |
139adb6a | 2281 | m_renameTimer = new wxListRenameTimer( this ); |
26e8da41 | 2282 | m_textctrlWrapper = NULL; |
277ea1b4 | 2283 | |
cf1dfa6b | 2284 | m_current = |
efbb7287 | 2285 | m_lineLastClicked = |
8df44392 | 2286 | m_lineSelectSingleOnUp = |
1370703e | 2287 | m_lineBeforeLastClicked = (size_t)-1; |
c5c528fc VZ |
2288 | |
2289 | m_freezeCount = 0; | |
e1e955e1 | 2290 | } |
c801d85f | 2291 | |
1370703e | 2292 | wxListMainWindow::wxListMainWindow() |
c801d85f | 2293 | { |
1370703e VZ |
2294 | Init(); |
2295 | ||
49ecb029 VZ |
2296 | m_highlightBrush = |
2297 | m_highlightUnfocusedBrush = (wxBrush *) NULL; | |
1370703e VZ |
2298 | } |
2299 | ||
2300 | wxListMainWindow::wxListMainWindow( wxWindow *parent, | |
2301 | wxWindowID id, | |
2302 | const wxPoint& pos, | |
2303 | const wxSize& size, | |
2304 | long style, | |
2305 | const wxString &name ) | |
2306 | : wxScrolledWindow( parent, id, pos, size, | |
2307 | style | wxHSCROLL | wxVSCROLL, name ) | |
2308 | { | |
2309 | Init(); | |
2310 | ||
49ecb029 | 2311 | m_highlightBrush = new wxBrush |
4b8fa634 | 2312 | ( |
a756f210 | 2313 | wxSystemSettings::GetColour |
49ecb029 VZ |
2314 | ( |
2315 | wxSYS_COLOUR_HIGHLIGHT | |
2316 | ), | |
2317 | wxSOLID | |
4b8fa634 | 2318 | ); |
6fef2483 | 2319 | |
49ecb029 | 2320 | m_highlightUnfocusedBrush = new wxBrush |
4b8fa634 KO |
2321 | ( |
2322 | wxSystemSettings::GetColour | |
2323 | ( | |
2324 | wxSYS_COLOUR_BTNSHADOW | |
2325 | ), | |
2326 | wxSOLID | |
2327 | ); | |
49ecb029 | 2328 | |
6d78bbe6 | 2329 | SetScrollbars( 0, 0, 0, 0, 0, 0 ); |
bd8289c1 | 2330 | |
ca65c044 | 2331 | wxVisualAttributes attr = wxGenericListCtrl::GetClassDefaultAttributes(); |
fa47d7a7 VS |
2332 | SetOwnForegroundColour( attr.colFg ); |
2333 | SetOwnBackgroundColour( attr.colBg ); | |
92a4e4de VZ |
2334 | if (!m_hasFont) |
2335 | SetOwnFont( attr.font ); | |
e1e955e1 | 2336 | } |
c801d85f | 2337 | |
fd9811b1 | 2338 | wxListMainWindow::~wxListMainWindow() |
c801d85f | 2339 | { |
5fe143df | 2340 | DoDeleteAllItems(); |
222ed1d6 | 2341 | WX_CLEAR_LIST(wxListHeaderDataList, m_columns); |
8d36b216 | 2342 | WX_CLEAR_ARRAY(m_aColWidths); |
12c1b46a | 2343 | |
b54e41c5 | 2344 | delete m_highlightBrush; |
49ecb029 | 2345 | delete m_highlightUnfocusedBrush; |
139adb6a | 2346 | delete m_renameTimer; |
e1e955e1 | 2347 | } |
c801d85f | 2348 | |
cf1dfa6b | 2349 | void wxListMainWindow::CacheLineData(size_t line) |
c801d85f | 2350 | { |
3cd94a0d | 2351 | wxGenericListCtrl *listctrl = GetListCtrl(); |
25e3a937 | 2352 | |
b54e41c5 | 2353 | wxListLineData *ld = GetDummyLine(); |
f6bcfd97 | 2354 | |
cf1dfa6b VZ |
2355 | size_t countCol = GetColumnCount(); |
2356 | for ( size_t col = 0; col < countCol; col++ ) | |
2357 | { | |
2358 | ld->SetText(col, listctrl->OnGetItemText(line, col)); | |
e062c6a4 | 2359 | ld->SetImage(col, listctrl->OnGetItemColumnImage(line, col)); |
cf1dfa6b VZ |
2360 | } |
2361 | ||
6c02c329 | 2362 | ld->SetAttr(listctrl->OnGetItemAttr(line)); |
e1e955e1 | 2363 | } |
c801d85f | 2364 | |
b54e41c5 | 2365 | wxListLineData *wxListMainWindow::GetDummyLine() const |
c801d85f | 2366 | { |
cf1dfa6b | 2367 | wxASSERT_MSG( !IsEmpty(), _T("invalid line index") ); |
904ccf52 VZ |
2368 | wxASSERT_MSG( IsVirtual(), _T("GetDummyLine() shouldn't be called") ); |
2369 | ||
2370 | wxListMainWindow *self = wxConstCast(this, wxListMainWindow); | |
2371 | ||
2372 | // we need to recreate the dummy line if the number of columns in the | |
2373 | // control changed as it would have the incorrect number of fields | |
2374 | // otherwise | |
2375 | if ( !m_lines.IsEmpty() && | |
2376 | m_lines[0].m_items.GetCount() != (size_t)GetColumnCount() ) | |
2c1f73ee | 2377 | { |
904ccf52 VZ |
2378 | self->m_lines.Clear(); |
2379 | } | |
cf1dfa6b | 2380 | |
904ccf52 VZ |
2381 | if ( m_lines.IsEmpty() ) |
2382 | { | |
5cd89174 | 2383 | wxListLineData *line = new wxListLineData(self); |
cf1dfa6b | 2384 | self->m_lines.Add(line); |
904ccf52 VZ |
2385 | |
2386 | // don't waste extra memory -- there never going to be anything | |
2387 | // else/more in this array | |
2388 | self->m_lines.Shrink(); | |
2c1f73ee VZ |
2389 | } |
2390 | ||
cf1dfa6b VZ |
2391 | return &m_lines[0]; |
2392 | } | |
2393 | ||
5cd89174 VZ |
2394 | // ---------------------------------------------------------------------------- |
2395 | // line geometry (report mode only) | |
2396 | // ---------------------------------------------------------------------------- | |
2397 | ||
cf1dfa6b VZ |
2398 | wxCoord wxListMainWindow::GetLineHeight() const |
2399 | { | |
cf1dfa6b VZ |
2400 | // we cache the line height as calling GetTextExtent() is slow |
2401 | if ( !m_lineHeight ) | |
2c1f73ee | 2402 | { |
cf1dfa6b | 2403 | wxListMainWindow *self = wxConstCast(this, wxListMainWindow); |
bd8289c1 | 2404 | |
cf1dfa6b VZ |
2405 | wxClientDC dc( self ); |
2406 | dc.SetFont( GetFont() ); | |
c801d85f | 2407 | |
cf1dfa6b VZ |
2408 | wxCoord y; |
2409 | dc.GetTextExtent(_T("H"), NULL, &y); | |
004fd0c8 | 2410 | |
ca7353de RD |
2411 | if ( m_small_image_list && m_small_image_list->GetImageCount() ) |
2412 | { | |
277ea1b4 | 2413 | int iw = 0, ih = 0; |
ca7353de RD |
2414 | m_small_image_list->GetSize(0, iw, ih); |
2415 | y = wxMax(y, ih); | |
2416 | } | |
2417 | ||
2418 | y += EXTRA_HEIGHT; | |
cf1dfa6b VZ |
2419 | self->m_lineHeight = y + LINE_SPACING; |
2420 | } | |
bffa1c77 | 2421 | |
cf1dfa6b VZ |
2422 | return m_lineHeight; |
2423 | } | |
bffa1c77 | 2424 | |
cf1dfa6b VZ |
2425 | wxCoord wxListMainWindow::GetLineY(size_t line) const |
2426 | { | |
b5d43d1d | 2427 | wxASSERT_MSG( InReportView(), _T("only works in report mode") ); |
1370703e | 2428 | |
277ea1b4 | 2429 | return LINE_SPACING + line * GetLineHeight(); |
cf1dfa6b | 2430 | } |
206b0a67 | 2431 | |
5cd89174 VZ |
2432 | wxRect wxListMainWindow::GetLineRect(size_t line) const |
2433 | { | |
2434 | if ( !InReportView() ) | |
2435 | return GetLine(line)->m_gi->m_rectAll; | |
2436 | ||
2437 | wxRect rect; | |
2438 | rect.x = HEADER_OFFSET_X; | |
2439 | rect.y = GetLineY(line); | |
2440 | rect.width = GetHeaderWidth(); | |
2441 | rect.height = GetLineHeight(); | |
2442 | ||
2443 | return rect; | |
2444 | } | |
2445 | ||
2446 | wxRect wxListMainWindow::GetLineLabelRect(size_t line) const | |
2447 | { | |
2448 | if ( !InReportView() ) | |
2449 | return GetLine(line)->m_gi->m_rectLabel; | |
2450 | ||
a70598d5 RR |
2451 | int image_x = 0; |
2452 | wxListLineData *data = GetLine(line); | |
2453 | wxListItemDataList::compatibility_iterator node = data->m_items.GetFirst(); | |
2454 | if (node) | |
2455 | { | |
2456 | wxListItemData *item = node->GetData(); | |
2457 | if ( item->HasImage() ) | |
2458 | { | |
2459 | int ix, iy; | |
2460 | GetImageSize( item->GetImage(), ix, iy ); | |
2461 | image_x = 3 + ix + IMAGE_MARGIN_IN_REPORT_MODE; | |
2462 | } | |
2463 | } | |
a9aead31 | 2464 | |
5cd89174 | 2465 | wxRect rect; |
edddffb5 | 2466 | rect.x = image_x + HEADER_OFFSET_X; |
5cd89174 | 2467 | rect.y = GetLineY(line); |
edddffb5 | 2468 | rect.width = GetColumnWidth(0) - image_x; |
5cd89174 VZ |
2469 | rect.height = GetLineHeight(); |
2470 | ||
2471 | return rect; | |
2472 | } | |
2473 | ||
2474 | wxRect wxListMainWindow::GetLineIconRect(size_t line) const | |
2475 | { | |
2476 | if ( !InReportView() ) | |
2477 | return GetLine(line)->m_gi->m_rectIcon; | |
2478 | ||
2479 | wxListLineData *ld = GetLine(line); | |
2480 | wxASSERT_MSG( ld->HasImage(), _T("should have an image") ); | |
2481 | ||
2482 | wxRect rect; | |
2483 | rect.x = HEADER_OFFSET_X; | |
2484 | rect.y = GetLineY(line); | |
2485 | GetImageSize(ld->GetImage(), rect.width, rect.height); | |
2486 | ||
2487 | return rect; | |
2488 | } | |
2489 | ||
2490 | wxRect wxListMainWindow::GetLineHighlightRect(size_t line) const | |
2491 | { | |
2492 | return InReportView() ? GetLineRect(line) | |
2493 | : GetLine(line)->m_gi->m_rectHighlight; | |
2494 | } | |
2495 | ||
2496 | long wxListMainWindow::HitTestLine(size_t line, int x, int y) const | |
2497 | { | |
fc4f1d5f VZ |
2498 | wxASSERT_MSG( line < GetItemCount(), _T("invalid line in HitTestLine") ); |
2499 | ||
5cd89174 VZ |
2500 | wxListLineData *ld = GetLine(line); |
2501 | ||
22a35096 | 2502 | if ( ld->HasImage() && GetLineIconRect(line).Contains(x, y) ) |
5cd89174 VZ |
2503 | return wxLIST_HITTEST_ONITEMICON; |
2504 | ||
acf4d858 VS |
2505 | // VS: Testing for "ld->HasText() || InReportView()" instead of |
2506 | // "ld->HasText()" is needed to make empty lines in report view | |
2507 | // possible | |
2508 | if ( ld->HasText() || InReportView() ) | |
5cd89174 VZ |
2509 | { |
2510 | wxRect rect = InReportView() ? GetLineRect(line) | |
2511 | : GetLineLabelRect(line); | |
2512 | ||
22a35096 | 2513 | if ( rect.Contains(x, y) ) |
5cd89174 VZ |
2514 | return wxLIST_HITTEST_ONITEMLABEL; |
2515 | } | |
2516 | ||
2517 | return 0; | |
2518 | } | |
2519 | ||
2520 | // ---------------------------------------------------------------------------- | |
2521 | // highlight (selection) handling | |
2522 | // ---------------------------------------------------------------------------- | |
2523 | ||
b54e41c5 | 2524 | bool wxListMainWindow::IsHighlighted(size_t line) const |
cf1dfa6b VZ |
2525 | { |
2526 | if ( IsVirtual() ) | |
2527 | { | |
b54e41c5 | 2528 | return m_selStore.IsSelected(line); |
cf1dfa6b VZ |
2529 | } |
2530 | else // !virtual | |
2531 | { | |
2532 | wxListLineData *ld = GetLine(line); | |
ca65c044 | 2533 | wxCHECK_MSG( ld, false, _T("invalid index in IsHighlighted") ); |
cf1dfa6b | 2534 | |
b54e41c5 | 2535 | return ld->IsHighlighted(); |
cf1dfa6b VZ |
2536 | } |
2537 | } | |
2538 | ||
68a9ef0e VZ |
2539 | void wxListMainWindow::HighlightLines( size_t lineFrom, |
2540 | size_t lineTo, | |
2541 | bool highlight ) | |
cf1dfa6b | 2542 | { |
cf1dfa6b VZ |
2543 | if ( IsVirtual() ) |
2544 | { | |
68a9ef0e VZ |
2545 | wxArrayInt linesChanged; |
2546 | if ( !m_selStore.SelectRange(lineFrom, lineTo, highlight, | |
2547 | &linesChanged) ) | |
2548 | { | |
2549 | // meny items changed state, refresh everything | |
2550 | RefreshLines(lineFrom, lineTo); | |
2551 | } | |
2552 | else // only a few items changed state, refresh only them | |
2553 | { | |
2554 | size_t count = linesChanged.GetCount(); | |
2555 | for ( size_t n = 0; n < count; n++ ) | |
2556 | { | |
2557 | RefreshLine(linesChanged[n]); | |
2558 | } | |
2559 | } | |
b54e41c5 | 2560 | } |
68a9ef0e | 2561 | else // iterate over all items in non report view |
b54e41c5 | 2562 | { |
b54e41c5 | 2563 | for ( size_t line = lineFrom; line <= lineTo; line++ ) |
cf1dfa6b | 2564 | { |
b54e41c5 | 2565 | if ( HighlightLine(line, highlight) ) |
68a9ef0e | 2566 | RefreshLine(line); |
cf1dfa6b | 2567 | } |
b54e41c5 VZ |
2568 | } |
2569 | } | |
2570 | ||
2571 | bool wxListMainWindow::HighlightLine( size_t line, bool highlight ) | |
2572 | { | |
2573 | bool changed; | |
2574 | ||
2575 | if ( IsVirtual() ) | |
2576 | { | |
2577 | changed = m_selStore.SelectItem(line, highlight); | |
cf1dfa6b VZ |
2578 | } |
2579 | else // !virtual | |
2580 | { | |
2581 | wxListLineData *ld = GetLine(line); | |
ca65c044 | 2582 | wxCHECK_MSG( ld, false, _T("invalid index in HighlightLine") ); |
cf1dfa6b | 2583 | |
b54e41c5 | 2584 | changed = ld->Highlight(highlight); |
cf1dfa6b VZ |
2585 | } |
2586 | ||
2587 | if ( changed ) | |
2588 | { | |
b54e41c5 | 2589 | SendNotify( line, highlight ? wxEVT_COMMAND_LIST_ITEM_SELECTED |
5cd89174 | 2590 | : wxEVT_COMMAND_LIST_ITEM_DESELECTED ); |
cf1dfa6b VZ |
2591 | } |
2592 | ||
2593 | return changed; | |
2594 | } | |
2595 | ||
2596 | void wxListMainWindow::RefreshLine( size_t line ) | |
2597 | { | |
b5d43d1d | 2598 | if ( InReportView() ) |
6ea1323a VZ |
2599 | { |
2600 | size_t visibleFrom, visibleTo; | |
2601 | GetVisibleLinesRange(&visibleFrom, &visibleTo); | |
c1c4c551 | 2602 | |
6ea1323a VZ |
2603 | if ( line < visibleFrom || line > visibleTo ) |
2604 | return; | |
2605 | } | |
c1c4c551 | 2606 | |
5cd89174 | 2607 | wxRect rect = GetLineRect(line); |
cf1dfa6b VZ |
2608 | |
2609 | CalcScrolledPosition( rect.x, rect.y, &rect.x, &rect.y ); | |
2610 | RefreshRect( rect ); | |
2611 | } | |
2612 | ||
2613 | void wxListMainWindow::RefreshLines( size_t lineFrom, size_t lineTo ) | |
2614 | { | |
2615 | // we suppose that they are ordered by caller | |
2616 | wxASSERT_MSG( lineFrom <= lineTo, _T("indices in disorder") ); | |
2617 | ||
6b4a8d93 VZ |
2618 | wxASSERT_MSG( lineTo < GetItemCount(), _T("invalid line range") ); |
2619 | ||
b5d43d1d | 2620 | if ( InReportView() ) |
cf1dfa6b | 2621 | { |
b54e41c5 VZ |
2622 | size_t visibleFrom, visibleTo; |
2623 | GetVisibleLinesRange(&visibleFrom, &visibleTo); | |
2624 | ||
2625 | if ( lineFrom < visibleFrom ) | |
2626 | lineFrom = visibleFrom; | |
2627 | if ( lineTo > visibleTo ) | |
2628 | lineTo = visibleTo; | |
cf1dfa6b VZ |
2629 | |
2630 | wxRect rect; | |
2631 | rect.x = 0; | |
2632 | rect.y = GetLineY(lineFrom); | |
2633 | rect.width = GetClientSize().x; | |
91c6cc0e | 2634 | rect.height = GetLineY(lineTo) - rect.y + GetLineHeight(); |
cf1dfa6b VZ |
2635 | |
2636 | CalcScrolledPosition( rect.x, rect.y, &rect.x, &rect.y ); | |
2637 | RefreshRect( rect ); | |
2638 | } | |
2639 | else // !report | |
2640 | { | |
2641 | // TODO: this should be optimized... | |
2642 | for ( size_t line = lineFrom; line <= lineTo; line++ ) | |
2643 | { | |
2644 | RefreshLine(line); | |
2645 | } | |
2646 | } | |
2647 | } | |
2648 | ||
6b4a8d93 VZ |
2649 | void wxListMainWindow::RefreshAfter( size_t lineFrom ) |
2650 | { | |
b5d43d1d | 2651 | if ( InReportView() ) |
6b4a8d93 | 2652 | { |
c29582d0 JS |
2653 | size_t visibleFrom, visibleTo; |
2654 | GetVisibleLinesRange(&visibleFrom, &visibleTo); | |
6b4a8d93 VZ |
2655 | |
2656 | if ( lineFrom < visibleFrom ) | |
2657 | lineFrom = visibleFrom; | |
c29582d0 JS |
2658 | else if ( lineFrom > visibleTo ) |
2659 | return; | |
6b4a8d93 VZ |
2660 | |
2661 | wxRect rect; | |
2662 | rect.x = 0; | |
2663 | rect.y = GetLineY(lineFrom); | |
c29582d0 | 2664 | CalcScrolledPosition( rect.x, rect.y, &rect.x, &rect.y ); |
6b4a8d93 VZ |
2665 | |
2666 | wxSize size = GetClientSize(); | |
2667 | rect.width = size.x; | |
277ea1b4 | 2668 | |
6b4a8d93 VZ |
2669 | // refresh till the bottom of the window |
2670 | rect.height = size.y - rect.y; | |
2671 | ||
6b4a8d93 | 2672 | RefreshRect( rect ); |
6b4a8d93 VZ |
2673 | } |
2674 | else // !report | |
2675 | { | |
2676 | // TODO: how to do it more efficiently? | |
ca65c044 | 2677 | m_dirty = true; |
6b4a8d93 VZ |
2678 | } |
2679 | } | |
2680 | ||
49ecb029 VZ |
2681 | void wxListMainWindow::RefreshSelected() |
2682 | { | |
2683 | if ( IsEmpty() ) | |
2684 | return; | |
2685 | ||
2686 | size_t from, to; | |
2687 | if ( InReportView() ) | |
2688 | { | |
2689 | GetVisibleLinesRange(&from, &to); | |
2690 | } | |
2691 | else // !virtual | |
2692 | { | |
2693 | from = 0; | |
2694 | to = GetItemCount() - 1; | |
2695 | } | |
2696 | ||
cf30ae13 | 2697 | if ( HasCurrent() && m_current >= from && m_current <= to ) |
49ecb029 | 2698 | RefreshLine(m_current); |
49ecb029 VZ |
2699 | |
2700 | for ( size_t line = from; line <= to; line++ ) | |
2701 | { | |
2702 | // NB: the test works as expected even if m_current == -1 | |
2703 | if ( line != m_current && IsHighlighted(line) ) | |
49ecb029 | 2704 | RefreshLine(line); |
49ecb029 VZ |
2705 | } |
2706 | } | |
2707 | ||
c5c528fc VZ |
2708 | void wxListMainWindow::Freeze() |
2709 | { | |
2710 | m_freezeCount++; | |
2711 | } | |
2712 | ||
2713 | void wxListMainWindow::Thaw() | |
2714 | { | |
2715 | wxCHECK_RET( m_freezeCount > 0, _T("thawing unfrozen list control?") ); | |
2716 | ||
8d7eaf91 | 2717 | if ( --m_freezeCount == 0 ) |
c5c528fc | 2718 | Refresh(); |
c5c528fc VZ |
2719 | } |
2720 | ||
cf1dfa6b VZ |
2721 | void wxListMainWindow::OnPaint( wxPaintEvent &WXUNUSED(event) ) |
2722 | { | |
2723 | // Note: a wxPaintDC must be constructed even if no drawing is | |
2724 | // done (a Windows requirement). | |
2725 | wxPaintDC dc( this ); | |
2726 | ||
c5c528fc | 2727 | if ( IsEmpty() || m_freezeCount ) |
c5c528fc | 2728 | // nothing to draw or not the moment to draw it |
cf1dfa6b | 2729 | return; |
cf1dfa6b | 2730 | |
1e4d446b | 2731 | if ( m_dirty ) |
1e4d446b VZ |
2732 | // delay the repainting until we calculate all the items positions |
2733 | return; | |
1e4d446b | 2734 | |
cf1dfa6b VZ |
2735 | PrepareDC( dc ); |
2736 | ||
2737 | int dev_x, dev_y; | |
2738 | CalcScrolledPosition( 0, 0, &dev_x, &dev_y ); | |
2739 | ||
cf1dfa6b VZ |
2740 | dc.SetFont( GetFont() ); |
2741 | ||
b5d43d1d | 2742 | if ( InReportView() ) |
cf1dfa6b | 2743 | { |
b54e41c5 | 2744 | int lineHeight = GetLineHeight(); |
cf1dfa6b | 2745 | |
b54e41c5 VZ |
2746 | size_t visibleFrom, visibleTo; |
2747 | GetVisibleLinesRange(&visibleFrom, &visibleTo); | |
b84839ae VZ |
2748 | |
2749 | wxRect rectLine; | |
5eefe029 RR |
2750 | int xOrig = dc.LogicalToDeviceX( 0 ); |
2751 | int yOrig = dc.LogicalToDeviceY( 0 ); | |
6fef2483 | 2752 | |
ff3d11a0 | 2753 | // tell the caller cache to cache the data |
91c6cc0e VZ |
2754 | if ( IsVirtual() ) |
2755 | { | |
2756 | wxListEvent evCache(wxEVT_COMMAND_LIST_CACHE_HINT, | |
2757 | GetParent()->GetId()); | |
2758 | evCache.SetEventObject( GetParent() ); | |
2759 | evCache.m_oldItemIndex = visibleFrom; | |
2760 | evCache.m_itemIndex = visibleTo; | |
2761 | GetParent()->GetEventHandler()->ProcessEvent( evCache ); | |
2762 | } | |
ff3d11a0 | 2763 | |
b54e41c5 | 2764 | for ( size_t line = visibleFrom; line <= visibleTo; line++ ) |
cf1dfa6b | 2765 | { |
b84839ae VZ |
2766 | rectLine = GetLineRect(line); |
2767 | ||
5eefe029 RR |
2768 | |
2769 | if ( !IsExposed(rectLine.x + xOrig, rectLine.y + yOrig, | |
b84839ae VZ |
2770 | rectLine.width, rectLine.height) ) |
2771 | { | |
2772 | // don't redraw unaffected lines to avoid flicker | |
2773 | continue; | |
2774 | } | |
2775 | ||
5cd89174 | 2776 | GetLine(line)->DrawInReportMode( &dc, |
b84839ae | 2777 | rectLine, |
5cd89174 | 2778 | GetLineHighlightRect(line), |
49ecb029 | 2779 | IsHighlighted(line) ); |
cf1dfa6b VZ |
2780 | } |
2781 | ||
2782 | if ( HasFlag(wxLC_HRULES) ) | |
2783 | { | |
b54e41c5 | 2784 | wxPen pen(GetRuleColour(), 1, wxSOLID); |
cf1dfa6b VZ |
2785 | wxSize clientSize = GetClientSize(); |
2786 | ||
696a18c7 RR |
2787 | size_t i = visibleFrom; |
2788 | if (i == 0) i = 1; // Don't draw the first one | |
2789 | for ( ; i <= visibleTo; i++ ) | |
cf1dfa6b VZ |
2790 | { |
2791 | dc.SetPen(pen); | |
2792 | dc.SetBrush( *wxTRANSPARENT_BRUSH ); | |
277ea1b4 DS |
2793 | dc.DrawLine(0 - dev_x, i * lineHeight, |
2794 | clientSize.x - dev_x, i * lineHeight); | |
cf1dfa6b VZ |
2795 | } |
2796 | ||
2797 | // Draw last horizontal rule | |
e7d073c3 | 2798 | if ( visibleTo == GetItemCount() - 1 ) |
cf1dfa6b | 2799 | { |
277ea1b4 | 2800 | dc.SetPen( pen ); |
cf1dfa6b | 2801 | dc.SetBrush( *wxTRANSPARENT_BRUSH ); |
277ea1b4 DS |
2802 | dc.DrawLine(0 - dev_x, (m_lineTo + 1) * lineHeight, |
2803 | clientSize.x - dev_x , (m_lineTo + 1) * lineHeight ); | |
cf1dfa6b | 2804 | } |
2c1f73ee | 2805 | } |
206b0a67 JS |
2806 | |
2807 | // Draw vertical rules if required | |
cf1dfa6b | 2808 | if ( HasFlag(wxLC_VRULES) && !IsEmpty() ) |
206b0a67 | 2809 | { |
b54e41c5 | 2810 | wxPen pen(GetRuleColour(), 1, wxSOLID); |
277ea1b4 | 2811 | wxRect firstItemRect, lastItemRect; |
cf1dfa6b | 2812 | |
e7d073c3 RD |
2813 | GetItemRect(visibleFrom, firstItemRect); |
2814 | GetItemRect(visibleTo, lastItemRect); | |
206b0a67 | 2815 | int x = firstItemRect.GetX(); |
673dfcfa JS |
2816 | dc.SetPen(pen); |
2817 | dc.SetBrush(* wxTRANSPARENT_BRUSH); | |
277ea1b4 | 2818 | |
999836aa | 2819 | for (int col = 0; col < GetColumnCount(); col++) |
206b0a67 JS |
2820 | { |
2821 | int colWidth = GetColumnWidth(col); | |
cf1dfa6b | 2822 | x += colWidth; |
696a18c7 RR |
2823 | int x_pos = x - dev_x; |
2824 | if (col < GetColumnCount()-1) x_pos -= 2; | |
2825 | dc.DrawLine(x_pos, firstItemRect.GetY() - 1 - dev_y, | |
2826 | x_pos, lastItemRect.GetBottom() + 1 - dev_y); | |
206b0a67 | 2827 | } |
d786bf87 | 2828 | } |
139adb6a | 2829 | } |
cf1dfa6b | 2830 | else // !report |
139adb6a | 2831 | { |
1370703e | 2832 | size_t count = GetItemCount(); |
cf1dfa6b VZ |
2833 | for ( size_t i = 0; i < count; i++ ) |
2834 | { | |
2835 | GetLine(i)->Draw( &dc ); | |
2836 | } | |
139adb6a | 2837 | } |
004fd0c8 | 2838 | |
65a1f350 RR |
2839 | #ifndef __WXMAC__ |
2840 | // Don't draw rect outline under Mac at all. | |
c25f61f1 | 2841 | if ( HasCurrent() ) |
cf1dfa6b | 2842 | { |
49ecb029 | 2843 | if ( m_hasFocus ) |
c25f61f1 | 2844 | { |
ccdbdc89 | 2845 | wxRect rect( GetLineHighlightRect( m_current ) ); |
6cd53379 | 2846 | #ifndef __WXGTK20__ |
c25f61f1 VZ |
2847 | dc.SetPen( *wxBLACK_PEN ); |
2848 | dc.SetBrush( *wxTRANSPARENT_BRUSH ); | |
ccdbdc89 RR |
2849 | dc.DrawRectangle( rect ); |
2850 | #else | |
05d97538 | 2851 | wxRendererNative::Get().DrawItemSelectionRect( this, dc, rect, wxCONTROL_CURRENT|wxCONTROL_FOCUSED ); |
6fef2483 | 2852 | |
ccdbdc89 | 2853 | #endif |
c25f61f1 | 2854 | } |
cf1dfa6b | 2855 | } |
65a1f350 | 2856 | #endif |
e1e955e1 | 2857 | } |
c801d85f | 2858 | |
b54e41c5 | 2859 | void wxListMainWindow::HighlightAll( bool on ) |
c801d85f | 2860 | { |
b54e41c5 | 2861 | if ( IsSingleSel() ) |
c801d85f | 2862 | { |
277ea1b4 | 2863 | wxASSERT_MSG( !on, _T("can't do this in a single selection control") ); |
b54e41c5 VZ |
2864 | |
2865 | // we just have one item to turn off | |
2866 | if ( HasCurrent() && IsHighlighted(m_current) ) | |
139adb6a | 2867 | { |
ca65c044 | 2868 | HighlightLine(m_current, false); |
b54e41c5 | 2869 | RefreshLine(m_current); |
139adb6a | 2870 | } |
e1e955e1 | 2871 | } |
b54e41c5 | 2872 | else // multi sel |
cf1dfa6b | 2873 | { |
b54e41c5 | 2874 | HighlightLines(0, GetItemCount() - 1, on); |
cf1dfa6b | 2875 | } |
e1e955e1 | 2876 | } |
c801d85f | 2877 | |
cf1dfa6b | 2878 | void wxListMainWindow::SendNotify( size_t line, |
05a7f61d | 2879 | wxEventType command, |
fbfb8bcc | 2880 | const wxPoint& point ) |
c801d85f | 2881 | { |
139adb6a RR |
2882 | wxListEvent le( command, GetParent()->GetId() ); |
2883 | le.SetEventObject( GetParent() ); | |
6fef2483 | 2884 | |
cf1dfa6b | 2885 | le.m_itemIndex = line; |
05a7f61d VZ |
2886 | |
2887 | // set only for events which have position | |
2888 | if ( point != wxDefaultPosition ) | |
2889 | le.m_pointDrag = point; | |
2890 | ||
c1c4c551 VZ |
2891 | // don't try to get the line info for virtual list controls: the main |
2892 | // program has it anyhow and if we did it would result in accessing all | |
2893 | // the lines, even those which are not visible now and this is precisely | |
2894 | // what we're trying to avoid | |
a95d5751 | 2895 | if ( !IsVirtual() ) |
91c6cc0e | 2896 | { |
0ddefeb0 VZ |
2897 | if ( line != (size_t)-1 ) |
2898 | { | |
2899 | GetLine(line)->GetItem( 0, le.m_item ); | |
2900 | } | |
2901 | //else: this happens for wxEVT_COMMAND_LIST_ITEM_FOCUSED event | |
91c6cc0e VZ |
2902 | } |
2903 | //else: there may be no more such item | |
2904 | ||
6e228e42 | 2905 | GetParent()->GetEventHandler()->ProcessEvent( le ); |
e1e955e1 | 2906 | } |
c801d85f | 2907 | |
0ddefeb0 | 2908 | void wxListMainWindow::ChangeCurrent(size_t current) |
c801d85f | 2909 | { |
0ddefeb0 | 2910 | m_current = current; |
c801d85f | 2911 | |
6fef2483 VZ |
2912 | // as the current item changed, we shouldn't start editing it when the |
2913 | // "slow click" timer expires as the click happened on another item | |
2914 | if ( m_renameTimer->IsRunning() ) | |
2915 | m_renameTimer->Stop(); | |
2916 | ||
0ddefeb0 | 2917 | SendNotify(current, wxEVT_COMMAND_LIST_ITEM_FOCUSED); |
e1e955e1 | 2918 | } |
c801d85f | 2919 | |
26e8da41 | 2920 | wxTextCtrl *wxListMainWindow::EditLabel(long item, wxClassInfo* textControlClass) |
c801d85f | 2921 | { |
26e8da41 | 2922 | wxCHECK_MSG( (item >= 0) && ((size_t)item < GetItemCount()), NULL, |
3cd94a0d | 2923 | wxT("wrong index in wxGenericListCtrl::EditLabel()") ); |
004fd0c8 | 2924 | |
26e8da41 VZ |
2925 | wxASSERT_MSG( textControlClass->IsKindOf(CLASSINFO(wxTextCtrl)), |
2926 | wxT("EditLabel() needs a text control") ); | |
2927 | ||
62d89eb4 | 2928 | size_t itemEdit = (size_t)item; |
e179bd65 | 2929 | |
fd9811b1 | 2930 | wxListEvent le( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT, GetParent()->GetId() ); |
139adb6a | 2931 | le.SetEventObject( GetParent() ); |
1370703e | 2932 | le.m_itemIndex = item; |
62d89eb4 | 2933 | wxListLineData *data = GetLine(itemEdit); |
26e8da41 | 2934 | wxCHECK_MSG( data, NULL, _T("invalid index in EditLabel()") ); |
1370703e | 2935 | data->GetItem( 0, le.m_item ); |
277ea1b4 | 2936 | |
62d89eb4 | 2937 | if ( GetParent()->GetEventHandler()->ProcessEvent( le ) && !le.IsAllowed() ) |
26e8da41 | 2938 | { |
62d89eb4 | 2939 | // vetoed by user code |
26e8da41 VZ |
2940 | return NULL; |
2941 | } | |
004fd0c8 | 2942 | |
cf1dfa6b VZ |
2943 | // We have to call this here because the label in question might just have |
2944 | // been added and no screen update taken place. | |
62d89eb4 | 2945 | if ( m_dirty ) |
a502b284 | 2946 | { |
cf1dfa6b | 2947 | wxSafeYield(); |
004fd0c8 | 2948 | |
a502b284 VZ |
2949 | // Pending events dispatched by wxSafeYield might have changed the item |
2950 | // count | |
2951 | if ( (size_t)item >= GetItemCount() ) | |
2952 | return NULL; | |
2953 | } | |
2954 | ||
26e8da41 VZ |
2955 | wxTextCtrl * const text = (wxTextCtrl *)textControlClass->CreateObject(); |
2956 | m_textctrlWrapper = new wxListTextCtrlWrapper(this, text, item); | |
2957 | return m_textctrlWrapper->GetText(); | |
e1e955e1 | 2958 | } |
c801d85f | 2959 | |
e179bd65 RR |
2960 | void wxListMainWindow::OnRenameTimer() |
2961 | { | |
cf1dfa6b | 2962 | wxCHECK_RET( HasCurrent(), wxT("unexpected rename timer") ); |
004fd0c8 | 2963 | |
cf1dfa6b | 2964 | EditLabel( m_current ); |
e179bd65 RR |
2965 | } |
2966 | ||
62d89eb4 | 2967 | bool wxListMainWindow::OnRenameAccept(size_t itemEdit, const wxString& value) |
c801d85f | 2968 | { |
e179bd65 RR |
2969 | wxListEvent le( wxEVT_COMMAND_LIST_END_LABEL_EDIT, GetParent()->GetId() ); |
2970 | le.SetEventObject( GetParent() ); | |
62d89eb4 | 2971 | le.m_itemIndex = itemEdit; |
1370703e | 2972 | |
62d89eb4 | 2973 | wxListLineData *data = GetLine(itemEdit); |
277ea1b4 | 2974 | |
ca65c044 | 2975 | wxCHECK_MSG( data, false, _T("invalid index in OnRenameAccept()") ); |
1370703e VZ |
2976 | |
2977 | data->GetItem( 0, le.m_item ); | |
62d89eb4 VZ |
2978 | le.m_item.m_text = value; |
2979 | return !GetParent()->GetEventHandler()->ProcessEvent( le ) || | |
2980 | le.IsAllowed(); | |
e1e955e1 | 2981 | } |
c801d85f | 2982 | |
18dd54e3 | 2983 | void wxListMainWindow::OnRenameCancelled(size_t itemEdit) |
86586459 | 2984 | { |
86586459 RR |
2985 | // let owner know that the edit was cancelled |
2986 | wxListEvent le( wxEVT_COMMAND_LIST_END_LABEL_EDIT, GetParent()->GetId() ); | |
86351e4a | 2987 | |
ca65c044 | 2988 | le.SetEditCanceled(true); |
86351e4a | 2989 | |
86586459 RR |
2990 | le.SetEventObject( GetParent() ); |
2991 | le.m_itemIndex = itemEdit; | |
2992 | ||
2993 | wxListLineData *data = GetLine(itemEdit); | |
2994 | wxCHECK_RET( data, _T("invalid index in OnRenameCancelled()") ); | |
2995 | ||
2996 | data->GetItem( 0, le.m_item ); | |
86586459 RR |
2997 | GetEventHandler()->ProcessEvent( le ); |
2998 | } | |
2999 | ||
c801d85f KB |
3000 | void wxListMainWindow::OnMouse( wxMouseEvent &event ) |
3001 | { | |
8b1464af | 3002 | |
b6bc47ef RD |
3003 | #ifdef __WXMAC__ |
3004 | // On wxMac we can't depend on the EVT_KILL_FOCUS event to properly | |
3005 | // shutdown the edit control when the mouse is clicked elsewhere on the | |
3006 | // listctrl because the order of events is different (or something like | |
277ea1b4 | 3007 | // that), so explicitly end the edit if it is active. |
26e8da41 VZ |
3008 | if ( event.LeftDown() && m_textctrlWrapper ) |
3009 | m_textctrlWrapper->AcceptChangesAndFinish(); | |
3010 | #endif // __WXMAC__ | |
277ea1b4 | 3011 | |
8d4b048e | 3012 | if ( event.LeftDown() ) |
ca06242b | 3013 | SetFocusIgnoringChildren(); |
6fef2483 | 3014 | |
3e1c4e00 | 3015 | event.SetEventObject( GetParent() ); |
cf1dfa6b VZ |
3016 | if ( GetParent()->GetEventHandler()->ProcessEvent( event) ) |
3017 | return; | |
3018 | ||
185f6036 RD |
3019 | if (event.GetEventType() == wxEVT_MOUSEWHEEL) |
3020 | { | |
3021 | // let the base handle mouse wheel events. | |
3022 | event.Skip(); | |
3023 | return; | |
3024 | } | |
2ac08aeb | 3025 | |
cf1dfa6b | 3026 | if ( !HasCurrent() || IsEmpty() ) |
8b1464af RR |
3027 | { |
3028 | if (event.RightDown()) | |
3029 | { | |
3030 | SendNotify( (size_t)-1, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK, event.GetPosition() ); | |
fc694caa RR |
3031 | |
3032 | wxContextMenuEvent evtCtx( | |
3033 | wxEVT_CONTEXT_MENU, | |
3034 | GetParent()->GetId(), | |
3035 | ClientToScreen(event.GetPosition())); | |
3036 | evtCtx.SetEventObject(GetParent()); | |
3037 | GetParent()->GetEventHandler()->ProcessEvent(evtCtx); | |
8b1464af | 3038 | } |
cf1dfa6b | 3039 | return; |
8b1464af | 3040 | } |
cf1dfa6b VZ |
3041 | |
3042 | if (m_dirty) | |
3043 | return; | |
e3e65dac | 3044 | |
cf1dfa6b VZ |
3045 | if ( !(event.Dragging() || event.ButtonDown() || event.LeftUp() || |
3046 | event.ButtonDClick()) ) | |
3047 | return; | |
c801d85f | 3048 | |
aaef15bf RR |
3049 | int x = event.GetX(); |
3050 | int y = event.GetY(); | |
3051 | CalcUnscrolledPosition( x, y, &x, &y ); | |
004fd0c8 | 3052 | |
cc734310 | 3053 | // where did we hit it (if we did)? |
92976ab6 | 3054 | long hitResult = 0; |
1370703e | 3055 | |
cf1dfa6b VZ |
3056 | size_t count = GetItemCount(), |
3057 | current; | |
3058 | ||
b5d43d1d | 3059 | if ( InReportView() ) |
92976ab6 | 3060 | { |
5cd89174 | 3061 | current = y / GetLineHeight(); |
cc734310 VZ |
3062 | if ( current < count ) |
3063 | hitResult = HitTestLine(current, x, y); | |
cf1dfa6b VZ |
3064 | } |
3065 | else // !report | |
3066 | { | |
3067 | // TODO: optimize it too! this is less simple than for report view but | |
3068 | // enumerating all items is still not a way to do it!! | |
4e3ace65 | 3069 | for ( current = 0; current < count; current++ ) |
cf1dfa6b | 3070 | { |
5cd89174 | 3071 | hitResult = HitTestLine(current, x, y); |
4e3ace65 VZ |
3072 | if ( hitResult ) |
3073 | break; | |
cf1dfa6b | 3074 | } |
92976ab6 | 3075 | } |
bd8289c1 | 3076 | |
fd9811b1 | 3077 | if (event.Dragging()) |
92976ab6 | 3078 | { |
fd9811b1 | 3079 | if (m_dragCount == 0) |
8d1d2284 VZ |
3080 | { |
3081 | // we have to report the raw, physical coords as we want to be | |
3082 | // able to call HitTest(event.m_pointDrag) from the user code to | |
3083 | // get the item being dragged | |
3084 | m_dragStart = event.GetPosition(); | |
3085 | } | |
bffa1c77 | 3086 | |
fd9811b1 | 3087 | m_dragCount++; |
bffa1c77 | 3088 | |
cf1dfa6b VZ |
3089 | if (m_dragCount != 3) |
3090 | return; | |
bffa1c77 | 3091 | |
05a7f61d VZ |
3092 | int command = event.RightIsDown() ? wxEVT_COMMAND_LIST_BEGIN_RDRAG |
3093 | : wxEVT_COMMAND_LIST_BEGIN_DRAG; | |
bffa1c77 | 3094 | |
fd9811b1 | 3095 | wxListEvent le( command, GetParent()->GetId() ); |
92976ab6 | 3096 | le.SetEventObject( GetParent() ); |
8df44392 | 3097 | le.m_itemIndex = m_lineLastClicked; |
bffa1c77 VZ |
3098 | le.m_pointDrag = m_dragStart; |
3099 | GetParent()->GetEventHandler()->ProcessEvent( le ); | |
3100 | ||
3101 | return; | |
92976ab6 | 3102 | } |
fd9811b1 RR |
3103 | else |
3104 | { | |
3105 | m_dragCount = 0; | |
3106 | } | |
bd8289c1 | 3107 | |
cf1dfa6b VZ |
3108 | if ( !hitResult ) |
3109 | { | |
8b1464af RR |
3110 | // outside of any item |
3111 | if (event.RightDown()) | |
3112 | { | |
3113 | SendNotify( (size_t) -1, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK, event.GetPosition() ); | |
fc694caa RR |
3114 | |
3115 | wxContextMenuEvent evtCtx( | |
3116 | wxEVT_CONTEXT_MENU, | |
3117 | GetParent()->GetId(), | |
3118 | ClientToScreen(event.GetPosition())); | |
3119 | evtCtx.SetEventObject(GetParent()); | |
3120 | GetParent()->GetEventHandler()->ProcessEvent(evtCtx); | |
8b1464af RR |
3121 | } |
3122 | else | |
3123 | { | |
3124 | // reset the selection and bail out | |
3125 | HighlightAll(false); | |
3126 | } | |
cf76cd4e | 3127 | |
cf1dfa6b VZ |
3128 | return; |
3129 | } | |
bd8289c1 | 3130 | |
ca65c044 | 3131 | bool forceClick = false; |
92976ab6 RR |
3132 | if (event.ButtonDClick()) |
3133 | { | |
6fef2483 VZ |
3134 | if ( m_renameTimer->IsRunning() ) |
3135 | m_renameTimer->Stop(); | |
3136 | ||
ca65c044 | 3137 | m_lastOnSame = false; |
efbb7287 | 3138 | |
ddba340d | 3139 | if ( current == m_lineLastClicked ) |
efbb7287 | 3140 | { |
cf1dfa6b | 3141 | SendNotify( current, wxEVT_COMMAND_LIST_ITEM_ACTIVATED ); |
004fd0c8 | 3142 | |
efbb7287 VZ |
3143 | return; |
3144 | } | |
3145 | else | |
3146 | { | |
8df44392 | 3147 | // The first click was on another item, so don't interpret this as |
efbb7287 | 3148 | // a double click, but as a simple click instead |
ca65c044 | 3149 | forceClick = true; |
efbb7287 | 3150 | } |
92976ab6 | 3151 | } |
bd8289c1 | 3152 | |
8df44392 | 3153 | if (event.LeftUp()) |
c801d85f | 3154 | { |
277ea1b4 | 3155 | if (m_lineSelectSingleOnUp != (size_t)-1) |
92976ab6 | 3156 | { |
8df44392 RR |
3157 | // select single line |
3158 | HighlightAll( false ); | |
3159 | ReverseHighlight(m_lineSelectSingleOnUp); | |
3160 | } | |
277ea1b4 | 3161 | |
2cb1f3da | 3162 | if (m_lastOnSame) |
8df44392 RR |
3163 | { |
3164 | if ((current == m_current) && | |
3165 | (hitResult == wxLIST_HITTEST_ONITEMLABEL) && | |
2cb1f3da | 3166 | HasFlag(wxLC_EDIT_LABELS) ) |
8df44392 | 3167 | { |
5595181f VZ |
3168 | if ( !InReportView() || |
3169 | GetLineLabelRect(current).Contains(x, y) ) | |
a70598d5 | 3170 | { |
5595181f VZ |
3171 | int dclick = wxSystemSettings::GetMetric(wxSYS_DCLICK_MSEC); |
3172 | m_renameTimer->Start(dclick > 0 ? dclick : 250, true); | |
a70598d5 | 3173 | } |
8df44392 | 3174 | } |
92976ab6 | 3175 | } |
277ea1b4 | 3176 | |
ca65c044 | 3177 | m_lastOnSame = false; |
277ea1b4 | 3178 | m_lineSelectSingleOnUp = (size_t)-1; |
8df44392 RR |
3179 | } |
3180 | else | |
3181 | { | |
3103e8a9 | 3182 | // This is necessary, because after a DnD operation in |
2997ca30 | 3183 | // from and to ourself, the up event is swallowed by the |
8df44392 RR |
3184 | // DnD code. So on next non-up event (which means here and |
3185 | // now) m_lineSelectSingleOnUp should be reset. | |
277ea1b4 | 3186 | m_lineSelectSingleOnUp = (size_t)-1; |
e1e955e1 | 3187 | } |
8df44392 | 3188 | if (event.RightDown()) |
b204641e | 3189 | { |
8df44392 RR |
3190 | m_lineBeforeLastClicked = m_lineLastClicked; |
3191 | m_lineLastClicked = current; | |
277ea1b4 | 3192 | |
eaefbb88 KH |
3193 | // If the item is already selected, do not update the selection. |
3194 | // Multi-selections should not be cleared if a selected item is clicked. | |
3195 | if (!IsHighlighted(current)) | |
3196 | { | |
3197 | HighlightAll(false); | |
3198 | ChangeCurrent(current); | |
3199 | ReverseHighlight(m_current); | |
3200 | } | |
277ea1b4 DS |
3201 | |
3202 | SendNotify( current, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK, event.GetPosition() ); | |
3203 | ||
18216ae3 RR |
3204 | // Allow generation of context menu event |
3205 | event.Skip(); | |
b204641e | 3206 | } |
cf1dfa6b | 3207 | else if (event.MiddleDown()) |
b204641e | 3208 | { |
cf1dfa6b | 3209 | SendNotify( current, wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK ); |
92976ab6 | 3210 | } |
cf1dfa6b | 3211 | else if ( event.LeftDown() || forceClick ) |
92976ab6 | 3212 | { |
efbb7287 | 3213 | m_lineBeforeLastClicked = m_lineLastClicked; |
cf1dfa6b VZ |
3214 | m_lineLastClicked = current; |
3215 | ||
3216 | size_t oldCurrent = m_current; | |
2cb1f3da JS |
3217 | bool oldWasSelected = IsHighlighted(m_current); |
3218 | ||
39e39d39 | 3219 | bool cmdModifierDown = event.CmdDown(); |
2fe417e4 | 3220 | if ( IsSingleSel() || !(cmdModifierDown || event.ShiftDown()) ) |
8df44392 | 3221 | { |
277ea1b4 | 3222 | if ( IsSingleSel() || !IsHighlighted(current) ) |
eb3d60a2 KH |
3223 | { |
3224 | HighlightAll( false ); | |
0ddefeb0 | 3225 | |
eb3d60a2 | 3226 | ChangeCurrent(current); |
cf1dfa6b | 3227 | |
eb3d60a2 KH |
3228 | ReverseHighlight(m_current); |
3229 | } | |
3230 | else // multi sel & current is highlighted & no mod keys | |
8df44392 | 3231 | { |
2997ca30 | 3232 | m_lineSelectSingleOnUp = current; |
8df44392 RR |
3233 | ChangeCurrent(current); // change focus |
3234 | } | |
e1e955e1 | 3235 | } |
b54e41c5 | 3236 | else // multi sel & either ctrl or shift is down |
b204641e | 3237 | { |
015fd9ef | 3238 | if (cmdModifierDown) |
92976ab6 | 3239 | { |
0ddefeb0 | 3240 | ChangeCurrent(current); |
cf1dfa6b | 3241 | |
b54e41c5 | 3242 | ReverseHighlight(m_current); |
92976ab6 | 3243 | } |
473d087e | 3244 | else if (event.ShiftDown()) |
92976ab6 | 3245 | { |
0ddefeb0 | 3246 | ChangeCurrent(current); |
bffa1c77 | 3247 | |
cf1dfa6b VZ |
3248 | size_t lineFrom = oldCurrent, |
3249 | lineTo = current; | |
f6bcfd97 | 3250 | |
cf1dfa6b | 3251 | if ( lineTo < lineFrom ) |
92976ab6 | 3252 | { |
cf1dfa6b VZ |
3253 | lineTo = lineFrom; |
3254 | lineFrom = m_current; | |
92976ab6 RR |
3255 | } |
3256 | ||
b54e41c5 | 3257 | HighlightLines(lineFrom, lineTo); |
92976ab6 | 3258 | } |
cf1dfa6b | 3259 | else // !ctrl, !shift |
92976ab6 | 3260 | { |
cf1dfa6b VZ |
3261 | // test in the enclosing if should make it impossible |
3262 | wxFAIL_MSG( _T("how did we get here?") ); | |
92976ab6 | 3263 | } |
e1e955e1 | 3264 | } |
cf1dfa6b | 3265 | |
92976ab6 | 3266 | if (m_current != oldCurrent) |
92976ab6 | 3267 | RefreshLine( oldCurrent ); |
efbb7287 VZ |
3268 | |
3269 | // forceClick is only set if the previous click was on another item | |
2cb1f3da | 3270 | m_lastOnSame = !forceClick && (m_current == oldCurrent) && oldWasSelected; |
e1e955e1 | 3271 | } |
e1e955e1 | 3272 | } |
c801d85f | 3273 | |
34bbbc27 | 3274 | void wxListMainWindow::MoveToItem(size_t item) |
c801d85f | 3275 | { |
34bbbc27 | 3276 | if ( item == (size_t)-1 ) |
cf1dfa6b | 3277 | return; |
004fd0c8 | 3278 | |
34bbbc27 | 3279 | wxRect rect = GetLineRect(item); |
cf3da716 | 3280 | |
cf1dfa6b | 3281 | int client_w, client_h; |
cf3da716 | 3282 | GetClientSize( &client_w, &client_h ); |
f6bcfd97 | 3283 | |
6d78bbe6 VZ |
3284 | const int hLine = GetLineHeight(); |
3285 | ||
277ea1b4 DS |
3286 | int view_x = SCROLL_UNIT_X * GetScrollPos( wxHORIZONTAL ); |
3287 | int view_y = hLine * GetScrollPos( wxVERTICAL ); | |
004fd0c8 | 3288 | |
b5d43d1d | 3289 | if ( InReportView() ) |
92976ab6 | 3290 | { |
277ea1b4 DS |
3291 | // the next we need the range of lines shown it might be different, |
3292 | // so recalculate it | |
b54e41c5 VZ |
3293 | ResetVisibleLinesRange(); |
3294 | ||
277ea1b4 DS |
3295 | if (rect.y < view_y) |
3296 | Scroll( -1, rect.y / hLine ); | |
3297 | if (rect.y + rect.height + 5 > view_y + client_h) | |
3298 | Scroll( -1, (rect.y + rect.height - client_h + hLine) / hLine ); | |
92976ab6 | 3299 | } |
b54e41c5 | 3300 | else // !report |
92976ab6 | 3301 | { |
807a572e RR |
3302 | if (rect.x-view_x < 5) |
3303 | Scroll( (rect.x - 5) / SCROLL_UNIT_X, -1 ); | |
3304 | if (rect.x + rect.width - 5 > view_x + client_w) | |
3305 | Scroll( (rect.x + rect.width - client_w + SCROLL_UNIT_X) / SCROLL_UNIT_X, -1 ); | |
92976ab6 | 3306 | } |
e1e955e1 | 3307 | } |
c801d85f | 3308 | |
cf1dfa6b VZ |
3309 | // ---------------------------------------------------------------------------- |
3310 | // keyboard handling | |
3311 | // ---------------------------------------------------------------------------- | |
3312 | ||
3313 | void wxListMainWindow::OnArrowChar(size_t newCurrent, const wxKeyEvent& event) | |
c801d85f | 3314 | { |
cf1dfa6b VZ |
3315 | wxCHECK_RET( newCurrent < (size_t)GetItemCount(), |
3316 | _T("invalid item index in OnArrowChar()") ); | |
3317 | ||
3318 | size_t oldCurrent = m_current; | |
3319 | ||
3320 | // in single selection we just ignore Shift as we can't select several | |
3321 | // items anyhow | |
b54e41c5 | 3322 | if ( event.ShiftDown() && !IsSingleSel() ) |
cf1dfa6b | 3323 | { |
0ddefeb0 | 3324 | ChangeCurrent(newCurrent); |
cf1dfa6b | 3325 | |
65a1f350 RR |
3326 | // refresh the old focus to remove it |
3327 | RefreshLine( oldCurrent ); | |
3328 | ||
cf1dfa6b VZ |
3329 | // select all the items between the old and the new one |
3330 | if ( oldCurrent > newCurrent ) | |
3331 | { | |
3332 | newCurrent = oldCurrent; | |
3333 | oldCurrent = m_current; | |
3334 | } | |
3335 | ||
b54e41c5 | 3336 | HighlightLines(oldCurrent, newCurrent); |
cf1dfa6b VZ |
3337 | } |
3338 | else // !shift | |
3339 | { | |
b54e41c5 | 3340 | // all previously selected items are unselected unless ctrl is held |
a9aead31 VZ |
3341 | // in a multiselection control |
3342 | if ( !event.ControlDown() || IsSingleSel() ) | |
ca65c044 | 3343 | HighlightAll(false); |
b54e41c5 | 3344 | |
0ddefeb0 | 3345 | ChangeCurrent(newCurrent); |
ca65c044 | 3346 | |
65a1f350 RR |
3347 | // refresh the old focus to remove it |
3348 | RefreshLine( oldCurrent ); | |
cf1dfa6b | 3349 | |
a9aead31 VZ |
3350 | // in single selection mode we must always have a selected item |
3351 | if ( !event.ControlDown() || IsSingleSel() ) | |
ca65c044 | 3352 | HighlightLine( m_current, true ); |
cf1dfa6b | 3353 | } |
ca65c044 | 3354 | |
92976ab6 | 3355 | RefreshLine( m_current ); |
cf1dfa6b | 3356 | |
cf3da716 | 3357 | MoveToFocus(); |
e1e955e1 | 3358 | } |
c801d85f | 3359 | |
3dfb93fd RR |
3360 | void wxListMainWindow::OnKeyDown( wxKeyEvent &event ) |
3361 | { | |
3362 | wxWindow *parent = GetParent(); | |
004fd0c8 | 3363 | |
277ea1b4 | 3364 | // propagate the key event upwards |
3dfb93fd RR |
3365 | wxKeyEvent ke( wxEVT_KEY_DOWN ); |
3366 | ke.m_shiftDown = event.m_shiftDown; | |
3367 | ke.m_controlDown = event.m_controlDown; | |
3368 | ke.m_altDown = event.m_altDown; | |
3369 | ke.m_metaDown = event.m_metaDown; | |
3370 | ke.m_keyCode = event.m_keyCode; | |
3371 | ke.m_x = event.m_x; | |
3372 | ke.m_y = event.m_y; | |
3373 | ke.SetEventObject( parent ); | |
3374 | if (parent->GetEventHandler()->ProcessEvent( ke )) return; | |
004fd0c8 | 3375 | |
3dfb93fd RR |
3376 | event.Skip(); |
3377 | } | |
004fd0c8 | 3378 | |
9fe25f13 KO |
3379 | void wxListMainWindow::OnKeyUp( wxKeyEvent &event ) |
3380 | { | |
3381 | wxWindow *parent = GetParent(); | |
3382 | ||
3383 | // propagate the key event upwards | |
3384 | wxKeyEvent ke( wxEVT_KEY_UP ); | |
3385 | ke.m_shiftDown = event.m_shiftDown; | |
3386 | ke.m_controlDown = event.m_controlDown; | |
3387 | ke.m_altDown = event.m_altDown; | |
3388 | ke.m_metaDown = event.m_metaDown; | |
3389 | ke.m_keyCode = event.m_keyCode; | |
3390 | ke.m_x = event.m_x; | |
3391 | ke.m_y = event.m_y; | |
3392 | ke.SetEventObject( parent ); | |
3393 | if (parent->GetEventHandler()->ProcessEvent( ke )) return; | |
3394 | ||
3395 | event.Skip(); | |
3396 | } | |
3397 | ||
c801d85f KB |
3398 | void wxListMainWindow::OnChar( wxKeyEvent &event ) |
3399 | { | |
51cc4dad | 3400 | wxWindow *parent = GetParent(); |
004fd0c8 | 3401 | |
277ea1b4 | 3402 | // send a list_key event up |
cf1dfa6b | 3403 | if ( HasCurrent() ) |
f6bcfd97 BP |
3404 | { |
3405 | wxListEvent le( wxEVT_COMMAND_LIST_KEY_DOWN, GetParent()->GetId() ); | |
cf1dfa6b VZ |
3406 | le.m_itemIndex = m_current; |
3407 | GetLine(m_current)->GetItem( 0, le.m_item ); | |
12a3f227 | 3408 | le.m_code = event.GetKeyCode(); |
f6bcfd97 BP |
3409 | le.SetEventObject( parent ); |
3410 | parent->GetEventHandler()->ProcessEvent( le ); | |
3411 | } | |
51cc4dad | 3412 | |
277ea1b4 | 3413 | // propagate the char event upwards |
3dfb93fd | 3414 | wxKeyEvent ke( wxEVT_CHAR ); |
51cc4dad RR |
3415 | ke.m_shiftDown = event.m_shiftDown; |
3416 | ke.m_controlDown = event.m_controlDown; | |
3417 | ke.m_altDown = event.m_altDown; | |
3418 | ke.m_metaDown = event.m_metaDown; | |
3419 | ke.m_keyCode = event.m_keyCode; | |
3420 | ke.m_x = event.m_x; | |
3421 | ke.m_y = event.m_y; | |
3422 | ke.SetEventObject( parent ); | |
3423 | if (parent->GetEventHandler()->ProcessEvent( ke )) return; | |
004fd0c8 | 3424 | |
12a3f227 | 3425 | if (event.GetKeyCode() == WXK_TAB) |
012a03e0 RR |
3426 | { |
3427 | wxNavigationKeyEvent nevent; | |
c5145d41 | 3428 | nevent.SetWindowChange( event.ControlDown() ); |
012a03e0 | 3429 | nevent.SetDirection( !event.ShiftDown() ); |
8253c7fd | 3430 | nevent.SetEventObject( GetParent()->GetParent() ); |
012a03e0 | 3431 | nevent.SetCurrentFocus( m_parent ); |
87948f22 VZ |
3432 | if (GetParent()->GetParent()->GetEventHandler()->ProcessEvent( nevent )) |
3433 | return; | |
012a03e0 | 3434 | } |
004fd0c8 | 3435 | |
277ea1b4 | 3436 | // no item -> nothing to do |
cf1dfa6b | 3437 | if (!HasCurrent()) |
c801d85f | 3438 | { |
51cc4dad RR |
3439 | event.Skip(); |
3440 | return; | |
e1e955e1 | 3441 | } |
51cc4dad | 3442 | |
cf76cd4e VZ |
3443 | // don't use m_linesPerPage directly as it might not be computed yet |
3444 | const int pageSize = GetCountPerPage(); | |
3445 | wxCHECK_RET( pageSize, _T("should have non zero page size") ); | |
3446 | ||
03703fc0 RR |
3447 | if (GetLayoutDirection() == wxLayout_RightToLeft) |
3448 | { | |
3449 | if (event.GetKeyCode() == WXK_RIGHT) | |
3450 | event.m_keyCode = WXK_LEFT; | |
3451 | else if (event.GetKeyCode() == WXK_LEFT) | |
3452 | event.m_keyCode = WXK_RIGHT; | |
3453 | } | |
3454 | ||
cf76cd4e | 3455 | switch ( event.GetKeyCode() ) |
c801d85f | 3456 | { |
51cc4dad | 3457 | case WXK_UP: |
cf1dfa6b VZ |
3458 | if ( m_current > 0 ) |
3459 | OnArrowChar( m_current - 1, event ); | |
51cc4dad | 3460 | break; |
cf1dfa6b | 3461 | |
51cc4dad | 3462 | case WXK_DOWN: |
cf1dfa6b VZ |
3463 | if ( m_current < (size_t)GetItemCount() - 1 ) |
3464 | OnArrowChar( m_current + 1, event ); | |
51cc4dad | 3465 | break; |
cf1dfa6b | 3466 | |
51cc4dad | 3467 | case WXK_END: |
1370703e | 3468 | if (!IsEmpty()) |
cf1dfa6b | 3469 | OnArrowChar( GetItemCount() - 1, event ); |
51cc4dad | 3470 | break; |
cf1dfa6b | 3471 | |
51cc4dad | 3472 | case WXK_HOME: |
1370703e | 3473 | if (!IsEmpty()) |
cf1dfa6b | 3474 | OnArrowChar( 0, event ); |
51cc4dad | 3475 | break; |
cf1dfa6b | 3476 | |
faa94f3e | 3477 | case WXK_PAGEUP: |
f6bcfd97 | 3478 | { |
cf76cd4e VZ |
3479 | int steps = InReportView() ? pageSize - 1 |
3480 | : m_current % pageSize; | |
cf1dfa6b VZ |
3481 | |
3482 | int index = m_current - steps; | |
3483 | if (index < 0) | |
3484 | index = 0; | |
3485 | ||
3486 | OnArrowChar( index, event ); | |
51cc4dad | 3487 | } |
51cc4dad | 3488 | break; |
cf1dfa6b | 3489 | |
faa94f3e | 3490 | case WXK_PAGEDOWN: |
bffa1c77 | 3491 | { |
b5d43d1d | 3492 | int steps = InReportView() |
cf76cd4e VZ |
3493 | ? pageSize - 1 |
3494 | : pageSize - (m_current % pageSize) - 1; | |
f6bcfd97 | 3495 | |
cf1dfa6b VZ |
3496 | size_t index = m_current + steps; |
3497 | size_t count = GetItemCount(); | |
3498 | if ( index >= count ) | |
3499 | index = count - 1; | |
3500 | ||
3501 | OnArrowChar( index, event ); | |
51cc4dad | 3502 | } |
51cc4dad | 3503 | break; |
cf1dfa6b | 3504 | |
51cc4dad | 3505 | case WXK_LEFT: |
b5d43d1d | 3506 | if ( !InReportView() ) |
51cc4dad | 3507 | { |
cf76cd4e | 3508 | int index = m_current - pageSize; |
cf1dfa6b VZ |
3509 | if (index < 0) |
3510 | index = 0; | |
3511 | ||
3512 | OnArrowChar( index, event ); | |
51cc4dad RR |
3513 | } |
3514 | break; | |
cf1dfa6b | 3515 | |
51cc4dad | 3516 | case WXK_RIGHT: |
b5d43d1d | 3517 | if ( !InReportView() ) |
51cc4dad | 3518 | { |
cf76cd4e | 3519 | size_t index = m_current + pageSize; |
cf1dfa6b VZ |
3520 | |
3521 | size_t count = GetItemCount(); | |
3522 | if ( index >= count ) | |
3523 | index = count - 1; | |
3524 | ||
3525 | OnArrowChar( index, event ); | |
51cc4dad RR |
3526 | } |
3527 | break; | |
cf1dfa6b | 3528 | |
51cc4dad | 3529 | case WXK_SPACE: |
b54e41c5 | 3530 | if ( IsSingleSel() ) |
33d0e17c | 3531 | { |
a9aead31 VZ |
3532 | if ( event.ControlDown() ) |
3533 | { | |
3534 | ReverseHighlight(m_current); | |
3535 | } | |
3536 | else // normal space press | |
70541533 | 3537 | { |
a9aead31 | 3538 | SendNotify( m_current, wxEVT_COMMAND_LIST_ITEM_ACTIVATED ); |
70541533 | 3539 | } |
33d0e17c | 3540 | } |
a9aead31 VZ |
3541 | else // multiple selection |
3542 | { | |
3543 | ReverseHighlight(m_current); | |
3544 | } | |
51cc4dad | 3545 | break; |
cf1dfa6b | 3546 | |
51cc4dad RR |
3547 | case WXK_RETURN: |
3548 | case WXK_EXECUTE: | |
87948f22 | 3549 | SendNotify( m_current, wxEVT_COMMAND_LIST_ITEM_ACTIVATED ); |
51cc4dad | 3550 | break; |
cf1dfa6b | 3551 | |
51cc4dad | 3552 | default: |
51cc4dad | 3553 | event.Skip(); |
e1e955e1 | 3554 | } |
e1e955e1 | 3555 | } |
c801d85f | 3556 | |
cf1dfa6b VZ |
3557 | // ---------------------------------------------------------------------------- |
3558 | // focus handling | |
3559 | // ---------------------------------------------------------------------------- | |
3560 | ||
c801d85f KB |
3561 | void wxListMainWindow::OnSetFocus( wxFocusEvent &WXUNUSED(event) ) |
3562 | { | |
dc76287d RD |
3563 | if ( GetParent() ) |
3564 | { | |
3565 | wxFocusEvent event( wxEVT_SET_FOCUS, GetParent()->GetId() ); | |
3566 | event.SetEventObject( GetParent() ); | |
3567 | if ( GetParent()->GetEventHandler()->ProcessEvent( event) ) | |
3568 | return; | |
3569 | } | |
3570 | ||
bde9072f VZ |
3571 | // wxGTK sends us EVT_SET_FOCUS events even if we had never got |
3572 | // EVT_KILL_FOCUS before which means that we finish by redrawing the items | |
3573 | // which are already drawn correctly resulting in horrible flicker - avoid | |
3574 | // it | |
47724389 VZ |
3575 | if ( !m_hasFocus ) |
3576 | { | |
ca65c044 | 3577 | m_hasFocus = true; |
bde9072f | 3578 | |
47724389 VZ |
3579 | RefreshSelected(); |
3580 | } | |
e1e955e1 | 3581 | } |
c801d85f KB |
3582 | |
3583 | void wxListMainWindow::OnKillFocus( wxFocusEvent &WXUNUSED(event) ) | |
3584 | { | |
dc76287d RD |
3585 | if ( GetParent() ) |
3586 | { | |
3587 | wxFocusEvent event( wxEVT_KILL_FOCUS, GetParent()->GetId() ); | |
3588 | event.SetEventObject( GetParent() ); | |
3589 | if ( GetParent()->GetEventHandler()->ProcessEvent( event) ) | |
3590 | return; | |
3591 | } | |
277ea1b4 | 3592 | |
ca65c044 | 3593 | m_hasFocus = false; |
49ecb029 | 3594 | RefreshSelected(); |
e1e955e1 | 3595 | } |
c801d85f | 3596 | |
1e6d9499 | 3597 | void wxListMainWindow::DrawImage( int index, wxDC *dc, int x, int y ) |
c801d85f | 3598 | { |
cf1dfa6b | 3599 | if ( HasFlag(wxLC_ICON) && (m_normal_image_list)) |
63852e78 RR |
3600 | { |
3601 | m_normal_image_list->Draw( index, *dc, x, y, wxIMAGELIST_DRAW_TRANSPARENT ); | |
63852e78 | 3602 | } |
cf1dfa6b | 3603 | else if ( HasFlag(wxLC_SMALL_ICON) && (m_small_image_list)) |
63852e78 RR |
3604 | { |
3605 | m_small_image_list->Draw( index, *dc, x, y, wxIMAGELIST_DRAW_TRANSPARENT ); | |
3606 | } | |
cf1dfa6b | 3607 | else if ( HasFlag(wxLC_LIST) && (m_small_image_list)) |
0b855868 RR |
3608 | { |
3609 | m_small_image_list->Draw( index, *dc, x, y, wxIMAGELIST_DRAW_TRANSPARENT ); | |
3610 | } | |
b5d43d1d | 3611 | else if ( InReportView() && (m_small_image_list)) |
63852e78 RR |
3612 | { |
3613 | m_small_image_list->Draw( index, *dc, x, y, wxIMAGELIST_DRAW_TRANSPARENT ); | |
63852e78 | 3614 | } |
e1e955e1 | 3615 | } |
c801d85f | 3616 | |
5cd89174 | 3617 | void wxListMainWindow::GetImageSize( int index, int &width, int &height ) const |
c801d85f | 3618 | { |
cf1dfa6b | 3619 | if ( HasFlag(wxLC_ICON) && m_normal_image_list ) |
63852e78 RR |
3620 | { |
3621 | m_normal_image_list->GetSize( index, width, height ); | |
63852e78 | 3622 | } |
cf1dfa6b | 3623 | else if ( HasFlag(wxLC_SMALL_ICON) && m_small_image_list ) |
63852e78 RR |
3624 | { |
3625 | m_small_image_list->GetSize( index, width, height ); | |
63852e78 | 3626 | } |
cf1dfa6b | 3627 | else if ( HasFlag(wxLC_LIST) && m_small_image_list ) |
0b855868 RR |
3628 | { |
3629 | m_small_image_list->GetSize( index, width, height ); | |
0b855868 | 3630 | } |
b5d43d1d | 3631 | else if ( InReportView() && m_small_image_list ) |
63852e78 RR |
3632 | { |
3633 | m_small_image_list->GetSize( index, width, height ); | |
63852e78 | 3634 | } |
cf1dfa6b VZ |
3635 | else |
3636 | { | |
3637 | width = | |
3638 | height = 0; | |
3639 | } | |
e1e955e1 | 3640 | } |
c801d85f | 3641 | |
5cd89174 | 3642 | int wxListMainWindow::GetTextLength( const wxString &s ) const |
c801d85f | 3643 | { |
5cd89174 | 3644 | wxClientDC dc( wxConstCast(this, wxListMainWindow) ); |
cf1dfa6b | 3645 | dc.SetFont( GetFont() ); |
c801d85f | 3646 | |
cf1dfa6b VZ |
3647 | wxCoord lw; |
3648 | dc.GetTextExtent( s, &lw, NULL ); | |
3649 | ||
3650 | return lw + AUTOSIZE_COL_MARGIN; | |
e1e955e1 | 3651 | } |
c801d85f | 3652 | |
8a3e173a | 3653 | void wxListMainWindow::SetImageList( wxImageList *imageList, int which ) |
c801d85f | 3654 | { |
ca65c044 | 3655 | m_dirty = true; |
f6bcfd97 BP |
3656 | |
3657 | // calc the spacing from the icon size | |
277ea1b4 DS |
3658 | int width = 0, height = 0; |
3659 | ||
f6bcfd97 | 3660 | if ((imageList) && (imageList->GetImageCount()) ) |
f6bcfd97 | 3661 | imageList->GetSize(0, width, height); |
f6bcfd97 BP |
3662 | |
3663 | if (which == wxIMAGE_LIST_NORMAL) | |
3664 | { | |
3665 | m_normal_image_list = imageList; | |
3666 | m_normal_spacing = width + 8; | |
3667 | } | |
3668 | ||
3669 | if (which == wxIMAGE_LIST_SMALL) | |
3670 | { | |
3671 | m_small_image_list = imageList; | |
3672 | m_small_spacing = width + 14; | |
ca7353de | 3673 | m_lineHeight = 0; // ensure that the line height will be recalc'd |
f6bcfd97 | 3674 | } |
e1e955e1 | 3675 | } |
c801d85f | 3676 | |
debe6624 | 3677 | void wxListMainWindow::SetItemSpacing( int spacing, bool isSmall ) |
c801d85f | 3678 | { |
ca65c044 | 3679 | m_dirty = true; |
139adb6a | 3680 | if (isSmall) |
139adb6a | 3681 | m_small_spacing = spacing; |
139adb6a | 3682 | else |
139adb6a | 3683 | m_normal_spacing = spacing; |
e1e955e1 | 3684 | } |
c801d85f | 3685 | |
debe6624 | 3686 | int wxListMainWindow::GetItemSpacing( bool isSmall ) |
c801d85f | 3687 | { |
f6bcfd97 | 3688 | return isSmall ? m_small_spacing : m_normal_spacing; |
e1e955e1 | 3689 | } |
c801d85f | 3690 | |
cf1dfa6b VZ |
3691 | // ---------------------------------------------------------------------------- |
3692 | // columns | |
3693 | // ---------------------------------------------------------------------------- | |
3694 | ||
debe6624 | 3695 | void wxListMainWindow::SetColumn( int col, wxListItem &item ) |
c801d85f | 3696 | { |
222ed1d6 | 3697 | wxListHeaderDataList::compatibility_iterator node = m_columns.Item( col ); |
f6bcfd97 | 3698 | |
cf1dfa6b VZ |
3699 | wxCHECK_RET( node, _T("invalid column index in SetColumn") ); |
3700 | ||
3701 | if ( item.m_width == wxLIST_AUTOSIZE_USEHEADER ) | |
3702 | item.m_width = GetTextLength( item.m_text ); | |
3703 | ||
3704 | wxListHeaderData *column = node->GetData(); | |
3705 | column->SetItem( item ); | |
3706 | ||
3707 | wxListHeaderWindow *headerWin = GetListCtrl()->m_headerWin; | |
f6bcfd97 | 3708 | if ( headerWin ) |
ca65c044 | 3709 | headerWin->m_dirty = true; |
cf1dfa6b | 3710 | |
ca65c044 | 3711 | m_dirty = true; |
cf1dfa6b VZ |
3712 | |
3713 | // invalidate it as it has to be recalculated | |
3714 | m_headerWidth = 0; | |
e1e955e1 | 3715 | } |
c801d85f | 3716 | |
debe6624 | 3717 | void wxListMainWindow::SetColumnWidth( int col, int width ) |
c801d85f | 3718 | { |
cf1dfa6b VZ |
3719 | wxCHECK_RET( col >= 0 && col < GetColumnCount(), |
3720 | _T("invalid column index") ); | |
3721 | ||
b5d43d1d | 3722 | wxCHECK_RET( InReportView(), |
f6bcfd97 | 3723 | _T("SetColumnWidth() can only be called in report mode.") ); |
0208334d | 3724 | |
ca65c044 | 3725 | m_dirty = true; |
abe4a4f1 VS |
3726 | wxListHeaderWindow *headerWin = GetListCtrl()->m_headerWin; |
3727 | if ( headerWin ) | |
ca65c044 | 3728 | headerWin->m_dirty = true; |
bd8289c1 | 3729 | |
222ed1d6 | 3730 | wxListHeaderDataList::compatibility_iterator node = m_columns.Item( col ); |
cf1dfa6b VZ |
3731 | wxCHECK_RET( node, _T("no column?") ); |
3732 | ||
3733 | wxListHeaderData *column = node->GetData(); | |
3734 | ||
3735 | size_t count = GetItemCount(); | |
3736 | ||
f6bcfd97 BP |
3737 | if (width == wxLIST_AUTOSIZE_USEHEADER) |
3738 | { | |
cf1dfa6b | 3739 | width = GetTextLength(column->GetText()); |
d63c9ecf VZ |
3740 | width += 2*EXTRA_WIDTH; |
3741 | ||
3742 | // check for column header's image availability | |
3743 | const int image = column->GetImage(); | |
3744 | if ( image != -1 ) | |
3745 | { | |
3746 | if ( m_small_image_list ) | |
3747 | { | |
3748 | int ix = 0, iy = 0; | |
3749 | m_small_image_list->GetSize(image, ix, iy); | |
3750 | width += ix + HEADER_IMAGE_MARGIN_IN_REPORT_MODE; | |
3751 | } | |
3752 | } | |
f6bcfd97 | 3753 | } |
cf1dfa6b | 3754 | else if ( width == wxLIST_AUTOSIZE ) |
0180dad6 | 3755 | { |
cf1dfa6b VZ |
3756 | if ( IsVirtual() ) |
3757 | { | |
3758 | // TODO: determine the max width somehow... | |
3759 | width = WIDTH_COL_DEFAULT; | |
3760 | } | |
3761 | else // !virtual | |
0180dad6 | 3762 | { |
cf1dfa6b VZ |
3763 | wxClientDC dc(this); |
3764 | dc.SetFont( GetFont() ); | |
3765 | ||
3766 | int max = AUTOSIZE_COL_MARGIN; | |
3767 | ||
7d4813a0 VZ |
3768 | // if the cached column width isn't valid then recalculate it |
3769 | if (m_aColWidths.Item(col)->bNeedsUpdate) | |
0180dad6 | 3770 | { |
7d4813a0 VZ |
3771 | for (size_t i = 0; i < count; i++) |
3772 | { | |
277ea1b4 | 3773 | wxListLineData *line = GetLine( i ); |
7d4813a0 | 3774 | wxListItemDataList::compatibility_iterator n = line->m_items.Item( col ); |
cf1dfa6b | 3775 | |
7d4813a0 | 3776 | wxCHECK_RET( n, _T("no subitem?") ); |
cf1dfa6b | 3777 | |
7d4813a0 VZ |
3778 | wxListItemData *itemData = n->GetData(); |
3779 | wxListItem item; | |
cf1dfa6b | 3780 | |
7d4813a0 VZ |
3781 | itemData->GetItem(item); |
3782 | int itemWidth = GetItemWidthWithImage(&item); | |
3783 | if (itemWidth > max) | |
3784 | max = itemWidth; | |
bffa1c77 | 3785 | } |
cf1dfa6b | 3786 | |
7d4813a0 VZ |
3787 | m_aColWidths.Item(col)->bNeedsUpdate = false; |
3788 | m_aColWidths.Item(col)->nMaxWidth = max; | |
0180dad6 | 3789 | } |
cf1dfa6b | 3790 | |
7d4813a0 | 3791 | max = m_aColWidths.Item(col)->nMaxWidth; |
cf1dfa6b | 3792 | width = max + AUTOSIZE_COL_MARGIN; |
0180dad6 | 3793 | } |
0180dad6 RR |
3794 | } |
3795 | ||
cf1dfa6b | 3796 | column->SetWidth( width ); |
bd8289c1 | 3797 | |
cf1dfa6b VZ |
3798 | // invalidate it as it has to be recalculated |
3799 | m_headerWidth = 0; | |
3800 | } | |
3801 | ||
3802 | int wxListMainWindow::GetHeaderWidth() const | |
3803 | { | |
3804 | if ( !m_headerWidth ) | |
0208334d | 3805 | { |
cf1dfa6b VZ |
3806 | wxListMainWindow *self = wxConstCast(this, wxListMainWindow); |
3807 | ||
3808 | size_t count = GetColumnCount(); | |
3809 | for ( size_t col = 0; col < count; col++ ) | |
63852e78 | 3810 | { |
cf1dfa6b | 3811 | self->m_headerWidth += GetColumnWidth(col); |
63852e78 | 3812 | } |
0208334d | 3813 | } |
bd8289c1 | 3814 | |
cf1dfa6b | 3815 | return m_headerWidth; |
e1e955e1 | 3816 | } |
c801d85f | 3817 | |
cf1dfa6b | 3818 | void wxListMainWindow::GetColumn( int col, wxListItem &item ) const |
c801d85f | 3819 | { |
222ed1d6 | 3820 | wxListHeaderDataList::compatibility_iterator node = m_columns.Item( col ); |
cf1dfa6b VZ |
3821 | wxCHECK_RET( node, _T("invalid column index in GetColumn") ); |
3822 | ||
3823 | wxListHeaderData *column = node->GetData(); | |
3824 | column->GetItem( item ); | |
e1e955e1 | 3825 | } |
c801d85f | 3826 | |
cf1dfa6b | 3827 | int wxListMainWindow::GetColumnWidth( int col ) const |
c801d85f | 3828 | { |
222ed1d6 | 3829 | wxListHeaderDataList::compatibility_iterator node = m_columns.Item( col ); |
24b9f055 VZ |
3830 | wxCHECK_MSG( node, 0, _T("invalid column index") ); |
3831 | ||
3832 | wxListHeaderData *column = node->GetData(); | |
3833 | return column->GetWidth(); | |
e1e955e1 | 3834 | } |
c801d85f | 3835 | |
cf1dfa6b VZ |
3836 | // ---------------------------------------------------------------------------- |
3837 | // item state | |
3838 | // ---------------------------------------------------------------------------- | |
c801d85f KB |
3839 | |
3840 | void wxListMainWindow::SetItem( wxListItem &item ) | |
3841 | { | |
cf1dfa6b VZ |
3842 | long id = item.m_itemId; |
3843 | wxCHECK_RET( id >= 0 && (size_t)id < GetItemCount(), | |
3844 | _T("invalid item index in SetItem") ); | |
3845 | ||
6c02c329 VZ |
3846 | if ( !IsVirtual() ) |
3847 | { | |
3848 | wxListLineData *line = GetLine((size_t)id); | |
3849 | line->SetItem( item.m_col, item ); | |
7d4813a0 | 3850 | |
39a7f085 VZ |
3851 | // Set item state if user wants |
3852 | if ( item.m_mask & wxLIST_MASK_STATE ) | |
3853 | SetItemState( item.m_itemId, item.m_state, item.m_state ); | |
3854 | ||
7d4813a0 VZ |
3855 | if (InReportView()) |
3856 | { | |
3857 | // update the Max Width Cache if needed | |
3858 | int width = GetItemWidthWithImage(&item); | |
3859 | ||
3860 | if (width > m_aColWidths.Item(item.m_col)->nMaxWidth) | |
3861 | m_aColWidths.Item(item.m_col)->nMaxWidth = width; | |
3862 | } | |
6c02c329 VZ |
3863 | } |
3864 | ||
285013b3 VZ |
3865 | // update the item on screen |
3866 | wxRect rectItem; | |
3867 | GetItemRect(id, rectItem); | |
3868 | RefreshRect(rectItem); | |
e1e955e1 | 3869 | } |
c801d85f | 3870 | |
0afa5859 VZ |
3871 | void wxListMainWindow::SetItemStateAll(long state, long stateMask) |
3872 | { | |
3873 | if ( IsEmpty() ) | |
3874 | return; | |
3875 | ||
3876 | // first deal with selection | |
3877 | if ( stateMask & wxLIST_STATE_SELECTED ) | |
3878 | { | |
3879 | // set/clear select state | |
3880 | if ( IsVirtual() ) | |
3881 | { | |
3882 | // optimized version for virtual listctrl. | |
3883 | m_selStore.SelectRange(0, GetItemCount() - 1, state == wxLIST_STATE_SELECTED); | |
3884 | Refresh(); | |
3885 | } | |
3886 | else if ( state & wxLIST_STATE_SELECTED ) | |
3887 | { | |
3888 | const long count = GetItemCount(); | |
3889 | for( long i = 0; i < count; i++ ) | |
3890 | { | |
3891 | SetItemState( i, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED ); | |
3892 | } | |
3893 | ||
3894 | } | |
3895 | else | |
3896 | { | |
3897 | // clear for non virtual (somewhat optimized by using GetNextItem()) | |
3898 | long i = -1; | |
3899 | while ( (i = GetNextItem(i, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED)) != -1 ) | |
3900 | { | |
3901 | SetItemState( i, 0, wxLIST_STATE_SELECTED ); | |
3902 | } | |
3903 | } | |
3904 | } | |
3905 | ||
3906 | if ( HasCurrent() && (state == 0) && (stateMask & wxLIST_STATE_FOCUSED) ) | |
3907 | { | |
3908 | // unfocus all: only one item can be focussed, so clearing focus for | |
3909 | // all items is simply clearing focus of the focussed item. | |
3910 | SetItemState(m_current, state, stateMask); | |
3911 | } | |
3912 | //(setting focus to all items makes no sense, so it is not handled here.) | |
3913 | } | |
3914 | ||
cf1dfa6b | 3915 | void wxListMainWindow::SetItemState( long litem, long state, long stateMask ) |
c801d85f | 3916 | { |
0afa5859 VZ |
3917 | if ( litem == -1 ) |
3918 | { | |
3919 | SetItemStateAll(state, stateMask); | |
3920 | return; | |
3921 | } | |
3922 | ||
7448de8d WS |
3923 | wxCHECK_RET( litem >= 0 && (size_t)litem < GetItemCount(), |
3924 | _T("invalid list ctrl item index in SetItem") ); | |
54442116 | 3925 | |
cf1dfa6b | 3926 | size_t oldCurrent = m_current; |
88b792af | 3927 | size_t item = (size_t)litem; // safe because of the check above |
bd8289c1 | 3928 | |
88b792af | 3929 | // do we need to change the focus? |
54442116 | 3930 | if ( stateMask & wxLIST_STATE_FOCUSED ) |
c801d85f | 3931 | { |
54442116 | 3932 | if ( state & wxLIST_STATE_FOCUSED ) |
92976ab6 | 3933 | { |
54442116 | 3934 | // don't do anything if this item is already focused |
cf1dfa6b | 3935 | if ( item != m_current ) |
92976ab6 | 3936 | { |
0ddefeb0 | 3937 | ChangeCurrent(item); |
cf1dfa6b | 3938 | |
88b792af | 3939 | if ( oldCurrent != (size_t)-1 ) |
cf1dfa6b | 3940 | { |
88b792af VZ |
3941 | if ( IsSingleSel() ) |
3942 | { | |
ca65c044 | 3943 | HighlightLine(oldCurrent, false); |
88b792af VZ |
3944 | } |
3945 | ||
cf1dfa6b VZ |
3946 | RefreshLine(oldCurrent); |
3947 | } | |
54442116 | 3948 | |
92976ab6 | 3949 | RefreshLine( m_current ); |
92976ab6 | 3950 | } |
54442116 VZ |
3951 | } |
3952 | else // unfocus | |
3953 | { | |
3954 | // don't do anything if this item is not focused | |
cf1dfa6b | 3955 | if ( item == m_current ) |
bffa1c77 | 3956 | { |
0ddefeb0 | 3957 | ResetCurrent(); |
88b792af | 3958 | |
943f6ad3 VZ |
3959 | if ( IsSingleSel() ) |
3960 | { | |
3961 | // we must unselect the old current item as well or we | |
3962 | // might end up with more than one selected item in a | |
3963 | // single selection control | |
ca65c044 | 3964 | HighlightLine(oldCurrent, false); |
943f6ad3 VZ |
3965 | } |
3966 | ||
88b792af | 3967 | RefreshLine( oldCurrent ); |
bffa1c77 | 3968 | } |
92976ab6 | 3969 | } |
e1e955e1 | 3970 | } |
54442116 | 3971 | |
88b792af | 3972 | // do we need to change the selection state? |
54442116 VZ |
3973 | if ( stateMask & wxLIST_STATE_SELECTED ) |
3974 | { | |
3975 | bool on = (state & wxLIST_STATE_SELECTED) != 0; | |
54442116 | 3976 | |
b54e41c5 | 3977 | if ( IsSingleSel() ) |
54442116 | 3978 | { |
cf1dfa6b VZ |
3979 | if ( on ) |
3980 | { | |
3981 | // selecting the item also makes it the focused one in the | |
3982 | // single sel mode | |
3983 | if ( m_current != item ) | |
3984 | { | |
0ddefeb0 | 3985 | ChangeCurrent(item); |
cf1dfa6b VZ |
3986 | |
3987 | if ( oldCurrent != (size_t)-1 ) | |
3988 | { | |
ca65c044 | 3989 | HighlightLine( oldCurrent, false ); |
cf1dfa6b VZ |
3990 | RefreshLine( oldCurrent ); |
3991 | } | |
3992 | } | |
3993 | } | |
3994 | else // off | |
3995 | { | |
3996 | // only the current item may be selected anyhow | |
3997 | if ( item != m_current ) | |
3998 | return; | |
3999 | } | |
54442116 VZ |
4000 | } |
4001 | ||
b54e41c5 | 4002 | if ( HighlightLine(item, on) ) |
54442116 | 4003 | { |
cf1dfa6b | 4004 | RefreshLine(item); |
54442116 VZ |
4005 | } |
4006 | } | |
e1e955e1 | 4007 | } |
c801d85f | 4008 | |
62d89eb4 | 4009 | int wxListMainWindow::GetItemState( long item, long stateMask ) const |
c801d85f | 4010 | { |
cf1dfa6b VZ |
4011 | wxCHECK_MSG( item >= 0 && (size_t)item < GetItemCount(), 0, |
4012 | _T("invalid list ctrl item index in GetItemState()") ); | |
4013 | ||
92976ab6 | 4014 | int ret = wxLIST_STATE_DONTCARE; |
cf1dfa6b VZ |
4015 | |
4016 | if ( stateMask & wxLIST_STATE_FOCUSED ) | |
c801d85f | 4017 | { |
cf1dfa6b VZ |
4018 | if ( (size_t)item == m_current ) |
4019 | ret |= wxLIST_STATE_FOCUSED; | |
e1e955e1 | 4020 | } |
cf1dfa6b VZ |
4021 | |
4022 | if ( stateMask & wxLIST_STATE_SELECTED ) | |
c801d85f | 4023 | { |
b54e41c5 | 4024 | if ( IsHighlighted(item) ) |
cf1dfa6b | 4025 | ret |= wxLIST_STATE_SELECTED; |
e1e955e1 | 4026 | } |
cf1dfa6b | 4027 | |
92976ab6 | 4028 | return ret; |
e1e955e1 | 4029 | } |
c801d85f | 4030 | |
62d89eb4 | 4031 | void wxListMainWindow::GetItem( wxListItem &item ) const |
c801d85f | 4032 | { |
cf1dfa6b VZ |
4033 | wxCHECK_RET( item.m_itemId >= 0 && (size_t)item.m_itemId < GetItemCount(), |
4034 | _T("invalid item index in GetItem") ); | |
4035 | ||
4036 | wxListLineData *line = GetLine((size_t)item.m_itemId); | |
4037 | line->GetItem( item.m_col, item ); | |
39a7f085 VZ |
4038 | |
4039 | // Get item state if user wants it | |
4040 | if ( item.m_mask & wxLIST_MASK_STATE ) | |
4041 | item.m_state = GetItemState( item.m_itemId, wxLIST_STATE_SELECTED | | |
4042 | wxLIST_STATE_FOCUSED ); | |
e1e955e1 | 4043 | } |
c801d85f | 4044 | |
cf1dfa6b VZ |
4045 | // ---------------------------------------------------------------------------- |
4046 | // item count | |
4047 | // ---------------------------------------------------------------------------- | |
4048 | ||
4049 | size_t wxListMainWindow::GetItemCount() const | |
1370703e VZ |
4050 | { |
4051 | return IsVirtual() ? m_countVirt : m_lines.GetCount(); | |
4052 | } | |
4053 | ||
4054 | void wxListMainWindow::SetItemCount(long count) | |
c801d85f | 4055 | { |
b54e41c5 | 4056 | m_selStore.SetItemCount(count); |
1370703e VZ |
4057 | m_countVirt = count; |
4058 | ||
850ed6e7 VZ |
4059 | ResetVisibleLinesRange(); |
4060 | ||
5fe143df | 4061 | // scrollbars must be reset |
ca65c044 | 4062 | m_dirty = true; |
e1e955e1 | 4063 | } |
c801d85f | 4064 | |
62d89eb4 | 4065 | int wxListMainWindow::GetSelectedItemCount() const |
c801d85f | 4066 | { |
cf1dfa6b | 4067 | // deal with the quick case first |
b54e41c5 | 4068 | if ( IsSingleSel() ) |
ca65c044 | 4069 | return HasCurrent() ? IsHighlighted(m_current) : false; |
cf1dfa6b VZ |
4070 | |
4071 | // virtual controls remmebers all its selections itself | |
4072 | if ( IsVirtual() ) | |
b54e41c5 | 4073 | return m_selStore.GetSelectedCount(); |
cf1dfa6b VZ |
4074 | |
4075 | // TODO: we probably should maintain the number of items selected even for | |
4076 | // non virtual controls as enumerating all lines is really slow... | |
4077 | size_t countSel = 0; | |
4078 | size_t count = GetItemCount(); | |
4079 | for ( size_t line = 0; line < count; line++ ) | |
92976ab6 | 4080 | { |
b54e41c5 | 4081 | if ( GetLine(line)->IsHighlighted() ) |
cf1dfa6b | 4082 | countSel++; |
92976ab6 | 4083 | } |
c801d85f | 4084 | |
cf1dfa6b | 4085 | return countSel; |
e1e955e1 | 4086 | } |
e3e65dac | 4087 | |
cf1dfa6b VZ |
4088 | // ---------------------------------------------------------------------------- |
4089 | // item position/size | |
4090 | // ---------------------------------------------------------------------------- | |
4091 | ||
11ebea16 VZ |
4092 | wxRect wxListMainWindow::GetViewRect() const |
4093 | { | |
4094 | wxASSERT_MSG( !HasFlag(wxLC_REPORT | wxLC_LIST), | |
4095 | _T("wxListCtrl::GetViewRect() only works in icon mode") ); | |
4096 | ||
4097 | // we need to find the longest/tallest label | |
277ea1b4 | 4098 | wxCoord xMax = 0, yMax = 0; |
11ebea16 VZ |
4099 | const int count = GetItemCount(); |
4100 | if ( count ) | |
4101 | { | |
4102 | for ( int i = 0; i < count; i++ ) | |
4103 | { | |
4104 | wxRect r; | |
4105 | GetItemRect(i, r); | |
4106 | ||
4107 | wxCoord x = r.GetRight(), | |
4108 | y = r.GetBottom(); | |
4109 | ||
4110 | if ( x > xMax ) | |
4111 | xMax = x; | |
4112 | if ( y > yMax ) | |
4113 | yMax = y; | |
4114 | } | |
4115 | } | |
4116 | ||
eb6c4508 | 4117 | // some fudge needed to make it look prettier |
277ea1b4 DS |
4118 | xMax += 2 * EXTRA_BORDER_X; |
4119 | yMax += 2 * EXTRA_BORDER_Y; | |
eb6c4508 VZ |
4120 | |
4121 | // account for the scrollbars if necessary | |
4122 | const wxSize sizeAll = GetClientSize(); | |
4123 | if ( xMax > sizeAll.x ) | |
4124 | yMax += wxSystemSettings::GetMetric(wxSYS_HSCROLL_Y); | |
4125 | if ( yMax > sizeAll.y ) | |
4126 | xMax += wxSystemSettings::GetMetric(wxSYS_VSCROLL_X); | |
11ebea16 VZ |
4127 | |
4128 | return wxRect(0, 0, xMax, yMax); | |
4129 | } | |
4130 | ||
62d89eb4 | 4131 | void wxListMainWindow::GetItemRect( long index, wxRect &rect ) const |
c801d85f | 4132 | { |
cf1dfa6b VZ |
4133 | wxCHECK_RET( index >= 0 && (size_t)index < GetItemCount(), |
4134 | _T("invalid index in GetItemRect") ); | |
4135 | ||
1e54be64 VZ |
4136 | // ensure that we're laid out, otherwise we could return nonsense |
4137 | if ( m_dirty ) | |
4138 | { | |
4139 | wxConstCast(this, wxListMainWindow)-> | |
ca65c044 | 4140 | RecalculatePositions(true /* no refresh */); |
1e54be64 VZ |
4141 | } |
4142 | ||
5cd89174 | 4143 | rect = GetLineRect((size_t)index); |
b54e41c5 | 4144 | |
cf1dfa6b | 4145 | CalcScrolledPosition(rect.x, rect.y, &rect.x, &rect.y); |
e1e955e1 | 4146 | } |
c801d85f | 4147 | |
62d89eb4 | 4148 | bool wxListMainWindow::GetItemPosition(long item, wxPoint& pos) const |
c801d85f | 4149 | { |
cf1dfa6b VZ |
4150 | wxRect rect; |
4151 | GetItemRect(item, rect); | |
bd8289c1 | 4152 | |
cf1dfa6b VZ |
4153 | pos.x = rect.x; |
4154 | pos.y = rect.y; | |
bd8289c1 | 4155 | |
ca65c044 | 4156 | return true; |
e1e955e1 | 4157 | } |
c801d85f | 4158 | |
cf1dfa6b VZ |
4159 | // ---------------------------------------------------------------------------- |
4160 | // geometry calculation | |
4161 | // ---------------------------------------------------------------------------- | |
4162 | ||
34bbbc27 | 4163 | void wxListMainWindow::RecalculatePositions(bool noRefresh) |
c801d85f | 4164 | { |
6d6d86a6 RD |
4165 | const int lineHeight = GetLineHeight(); |
4166 | ||
1e6d9499 | 4167 | wxClientDC dc( this ); |
92976ab6 | 4168 | dc.SetFont( GetFont() ); |
c801d85f | 4169 | |
13602ebd VZ |
4170 | const size_t count = GetItemCount(); |
4171 | ||
cf1dfa6b VZ |
4172 | int iconSpacing; |
4173 | if ( HasFlag(wxLC_ICON) ) | |
4174 | iconSpacing = m_normal_spacing; | |
4175 | else if ( HasFlag(wxLC_SMALL_ICON) ) | |
4176 | iconSpacing = m_small_spacing; | |
4177 | else | |
4178 | iconSpacing = 0; | |
004fd0c8 | 4179 | |
bf632edd | 4180 | // Note that we do not call GetClientSize() here but |
34621cc5 | 4181 | // GetSize() and subtract the border size for sunken |
bf632edd RR |
4182 | // borders manually. This is technically incorrect, |
4183 | // but we need to know the client area's size WITHOUT | |
4184 | // scrollbars here. Since we don't know if there are | |
4185 | // any scrollbars, we use GetSize() instead. Another | |
4186 | // solution would be to call SetScrollbars() here to | |
4187 | // remove the scrollbars and call GetClientSize() then, | |
4188 | // but this might result in flicker and - worse - will | |
4189 | // reset the scrollbars to 0 which is not good at all | |
4190 | // if you resize a dialog/window, but don't want to | |
4191 | // reset the window scrolling. RR. | |
4192 | // Furthermore, we actually do NOT subtract the border | |
4193 | // width as 2 pixels is just the extra space which we | |
4194 | // need around the actual content in the window. Other- | |
4195 | // wise the text would e.g. touch the upper border. RR. | |
cf1dfa6b VZ |
4196 | int clientWidth, |
4197 | clientHeight; | |
bf632edd | 4198 | GetSize( &clientWidth, &clientHeight ); |
a77ec46d | 4199 | |
b5d43d1d | 4200 | if ( InReportView() ) |
cf1dfa6b | 4201 | { |
13602ebd | 4202 | // all lines have the same height and we scroll one line per step |
277ea1b4 | 4203 | int entireHeight = count * lineHeight + LINE_SPACING; |
bd8289c1 | 4204 | |
b54e41c5 VZ |
4205 | m_linesPerPage = clientHeight / lineHeight; |
4206 | ||
4207 | ResetVisibleLinesRange(); | |
2c1f73ee | 4208 | |
13602ebd VZ |
4209 | SetScrollbars( SCROLL_UNIT_X, lineHeight, |
4210 | GetHeaderWidth() / SCROLL_UNIT_X, | |
4211 | (entireHeight + lineHeight - 1) / lineHeight, | |
cf1dfa6b VZ |
4212 | GetScrollPos(wxHORIZONTAL), |
4213 | GetScrollPos(wxVERTICAL), | |
ca65c044 | 4214 | true ); |
e1e955e1 | 4215 | } |
cf1dfa6b | 4216 | else // !report |
92976ab6 | 4217 | { |
13602ebd VZ |
4218 | // we have 3 different layout strategies: either layout all items |
4219 | // horizontally/vertically (wxLC_ALIGN_XXX styles explicitly given) or | |
4220 | // to arrange them in top to bottom, left to right (don't ask me why | |
4221 | // not the other way round...) order | |
4222 | if ( HasFlag(wxLC_ALIGN_LEFT | wxLC_ALIGN_TOP) ) | |
e487524e | 4223 | { |
13602ebd VZ |
4224 | int x = EXTRA_BORDER_X; |
4225 | int y = EXTRA_BORDER_Y; | |
cf1dfa6b | 4226 | |
94dd23ae VZ |
4227 | wxCoord widthMax = 0; |
4228 | ||
4229 | size_t i; | |
4230 | for ( i = 0; i < count; i++ ) | |
92976ab6 | 4231 | { |
cf1dfa6b | 4232 | wxListLineData *line = GetLine(i); |
92976ab6 | 4233 | line->CalculateSize( &dc, iconSpacing ); |
13602ebd | 4234 | line->SetPosition( x, y, iconSpacing ); |
cf1dfa6b | 4235 | |
5cd89174 | 4236 | wxSize sizeLine = GetLineSize(i); |
cf1dfa6b | 4237 | |
13602ebd VZ |
4238 | if ( HasFlag(wxLC_ALIGN_TOP) ) |
4239 | { | |
94dd23ae VZ |
4240 | if ( sizeLine.x > widthMax ) |
4241 | widthMax = sizeLine.x; | |
4242 | ||
13602ebd VZ |
4243 | y += sizeLine.y; |
4244 | } | |
4245 | else // wxLC_ALIGN_LEFT | |
4246 | { | |
4247 | x += sizeLine.x + MARGIN_BETWEEN_ROWS; | |
4248 | } | |
4249 | } | |
4250 | ||
94dd23ae VZ |
4251 | if ( HasFlag(wxLC_ALIGN_TOP) ) |
4252 | { | |
4253 | // traverse the items again and tweak their sizes so that they are | |
4254 | // all the same in a row | |
4255 | for ( i = 0; i < count; i++ ) | |
4256 | { | |
4257 | wxListLineData *line = GetLine(i); | |
4258 | line->m_gi->ExtendWidth(widthMax); | |
4259 | } | |
4260 | } | |
4261 | ||
13602ebd VZ |
4262 | SetScrollbars |
4263 | ( | |
4264 | SCROLL_UNIT_X, | |
6d78bbe6 | 4265 | lineHeight, |
13602ebd | 4266 | (x + SCROLL_UNIT_X) / SCROLL_UNIT_X, |
6d78bbe6 | 4267 | (y + lineHeight) / lineHeight, |
13602ebd VZ |
4268 | GetScrollPos( wxHORIZONTAL ), |
4269 | GetScrollPos( wxVERTICAL ), | |
ca65c044 | 4270 | true |
13602ebd VZ |
4271 | ); |
4272 | } | |
4273 | else // "flowed" arrangement, the most complicated case | |
4274 | { | |
4275 | // at first we try without any scrollbars, if the items don't fit into | |
4276 | // the window, we recalculate after subtracting the space taken by the | |
4277 | // scrollbar | |
4278 | ||
8a39593e | 4279 | int entireWidth = 0; |
cf1dfa6b | 4280 | |
13602ebd VZ |
4281 | for (int tries = 0; tries < 2; tries++) |
4282 | { | |
277ea1b4 | 4283 | entireWidth = 2 * EXTRA_BORDER_X; |
cf1dfa6b | 4284 | |
13602ebd | 4285 | if (tries == 1) |
92976ab6 | 4286 | { |
13602ebd VZ |
4287 | // Now we have decided that the items do not fit into the |
4288 | // client area, so we need a scrollbar | |
4289 | entireWidth += SCROLL_UNIT_X; | |
92976ab6 | 4290 | } |
a77ec46d | 4291 | |
13602ebd VZ |
4292 | int x = EXTRA_BORDER_X; |
4293 | int y = EXTRA_BORDER_Y; | |
4294 | int maxWidthInThisRow = 0; | |
4295 | ||
4296 | m_linesPerPage = 0; | |
4297 | int currentlyVisibleLines = 0; | |
a77ec46d | 4298 | |
13602ebd | 4299 | for (size_t i = 0; i < count; i++) |
92976ab6 | 4300 | { |
13602ebd | 4301 | currentlyVisibleLines++; |
277ea1b4 | 4302 | wxListLineData *line = GetLine( i ); |
13602ebd VZ |
4303 | line->CalculateSize( &dc, iconSpacing ); |
4304 | line->SetPosition( x, y, iconSpacing ); | |
4305 | ||
277ea1b4 | 4306 | wxSize sizeLine = GetLineSize( i ); |
a77ec46d | 4307 | |
13602ebd VZ |
4308 | if ( maxWidthInThisRow < sizeLine.x ) |
4309 | maxWidthInThisRow = sizeLine.x; | |
4310 | ||
4311 | y += sizeLine.y; | |
4312 | if (currentlyVisibleLines > m_linesPerPage) | |
4313 | m_linesPerPage = currentlyVisibleLines; | |
4314 | ||
4315 | if ( y + sizeLine.y >= clientHeight ) | |
4316 | { | |
4317 | currentlyVisibleLines = 0; | |
4318 | y = EXTRA_BORDER_Y; | |
4319 | maxWidthInThisRow += MARGIN_BETWEEN_ROWS; | |
4320 | x += maxWidthInThisRow; | |
4321 | entireWidth += maxWidthInThisRow; | |
4322 | maxWidthInThisRow = 0; | |
4323 | } | |
4324 | ||
4325 | // We have reached the last item. | |
4326 | if ( i == count - 1 ) | |
4327 | entireWidth += maxWidthInThisRow; | |
4328 | ||
4329 | if ( (tries == 0) && | |
4330 | (entireWidth + SCROLL_UNIT_X > clientWidth) ) | |
4331 | { | |
4332 | clientHeight -= wxSystemSettings:: | |
4333 | GetMetric(wxSYS_HSCROLL_Y); | |
4334 | m_linesPerPage = 0; | |
13602ebd VZ |
4335 | break; |
4336 | } | |
4337 | ||
4338 | if ( i == count - 1 ) | |
4339 | tries = 1; // Everything fits, no second try required. | |
4340 | } | |
92976ab6 | 4341 | } |
bffa1c77 | 4342 | |
13602ebd VZ |
4343 | SetScrollbars |
4344 | ( | |
4345 | SCROLL_UNIT_X, | |
6d78bbe6 | 4346 | lineHeight, |
13602ebd VZ |
4347 | (entireWidth + SCROLL_UNIT_X) / SCROLL_UNIT_X, |
4348 | 0, | |
4349 | GetScrollPos( wxHORIZONTAL ), | |
4350 | 0, | |
ca65c044 | 4351 | true |
13602ebd VZ |
4352 | ); |
4353 | } | |
e1e955e1 | 4354 | } |
cf1dfa6b | 4355 | |
34bbbc27 VZ |
4356 | if ( !noRefresh ) |
4357 | { | |
4358 | // FIXME: why should we call it from here? | |
4359 | UpdateCurrent(); | |
b54e41c5 | 4360 | |
34bbbc27 VZ |
4361 | RefreshAll(); |
4362 | } | |
b54e41c5 VZ |
4363 | } |
4364 | ||
4365 | void wxListMainWindow::RefreshAll() | |
4366 | { | |
ca65c044 | 4367 | m_dirty = false; |
b54e41c5 VZ |
4368 | Refresh(); |
4369 | ||
4370 | wxListHeaderWindow *headerWin = GetListCtrl()->m_headerWin; | |
70541533 | 4371 | if ( headerWin && headerWin->m_dirty ) |
b54e41c5 | 4372 | { |
ca65c044 | 4373 | headerWin->m_dirty = false; |
b54e41c5 VZ |
4374 | headerWin->Refresh(); |
4375 | } | |
e1e955e1 | 4376 | } |
c801d85f | 4377 | |
cf1dfa6b | 4378 | void wxListMainWindow::UpdateCurrent() |
c801d85f | 4379 | { |
b54e41c5 | 4380 | if ( !HasCurrent() && !IsEmpty() ) |
0ddefeb0 | 4381 | ChangeCurrent(0); |
e1e955e1 | 4382 | } |
c801d85f | 4383 | |
19695fbd VZ |
4384 | long wxListMainWindow::GetNextItem( long item, |
4385 | int WXUNUSED(geometry), | |
62d89eb4 | 4386 | int state ) const |
c801d85f | 4387 | { |
d1022fd6 VZ |
4388 | long ret = item, |
4389 | max = GetItemCount(); | |
4390 | wxCHECK_MSG( (ret == -1) || (ret < max), -1, | |
13771c08 | 4391 | _T("invalid listctrl index in GetNextItem()") ); |
19695fbd VZ |
4392 | |
4393 | // notice that we start with the next item (or the first one if item == -1) | |
4394 | // and this is intentional to allow writing a simple loop to iterate over | |
4395 | // all selected items | |
d1022fd6 VZ |
4396 | ret++; |
4397 | if ( ret == max ) | |
277ea1b4 DS |
4398 | // this is not an error because the index was OK initially, |
4399 | // just no such item | |
d1022fd6 | 4400 | return -1; |
d1022fd6 | 4401 | |
cf1dfa6b | 4402 | if ( !state ) |
cf1dfa6b VZ |
4403 | // any will do |
4404 | return (size_t)ret; | |
cf1dfa6b VZ |
4405 | |
4406 | size_t count = GetItemCount(); | |
4407 | for ( size_t line = (size_t)ret; line < count; line++ ) | |
63852e78 | 4408 | { |
cf1dfa6b VZ |
4409 | if ( (state & wxLIST_STATE_FOCUSED) && (line == m_current) ) |
4410 | return line; | |
4411 | ||
b54e41c5 | 4412 | if ( (state & wxLIST_STATE_SELECTED) && IsHighlighted(line) ) |
cf1dfa6b | 4413 | return line; |
63852e78 | 4414 | } |
19695fbd | 4415 | |
63852e78 | 4416 | return -1; |
e1e955e1 | 4417 | } |
c801d85f | 4418 | |
cf1dfa6b VZ |
4419 | // ---------------------------------------------------------------------------- |
4420 | // deleting stuff | |
4421 | // ---------------------------------------------------------------------------- | |
4422 | ||
b54e41c5 | 4423 | void wxListMainWindow::DeleteItem( long lindex ) |
c801d85f | 4424 | { |
cf1dfa6b VZ |
4425 | size_t count = GetItemCount(); |
4426 | ||
b54e41c5 | 4427 | wxCHECK_RET( (lindex >= 0) && ((size_t)lindex < count), |
cf1dfa6b VZ |
4428 | _T("invalid item index in DeleteItem") ); |
4429 | ||
b54e41c5 VZ |
4430 | size_t index = (size_t)lindex; |
4431 | ||
d6ddcd57 VZ |
4432 | // we don't need to adjust the index for the previous items |
4433 | if ( HasCurrent() && m_current >= index ) | |
cf1dfa6b | 4434 | { |
d6ddcd57 VZ |
4435 | // if the current item is being deleted, we want the next one to |
4436 | // become selected - unless there is no next one - so don't adjust | |
4437 | // m_current in this case | |
4438 | if ( m_current != index || m_current == count - 1 ) | |
d6ddcd57 | 4439 | m_current--; |
cf1dfa6b | 4440 | } |
6fef2483 | 4441 | |
938b652b | 4442 | if ( InReportView() ) |
63852e78 | 4443 | { |
a95d5751 RR |
4444 | // mark the Column Max Width cache as dirty if the items in the line |
4445 | // we're deleting contain the Max Column Width | |
7d4813a0 VZ |
4446 | wxListLineData * const line = GetLine(index); |
4447 | wxListItemDataList::compatibility_iterator n; | |
4448 | wxListItemData *itemData; | |
4449 | wxListItem item; | |
4450 | int itemWidth; | |
4451 | ||
4452 | for (size_t i = 0; i < m_columns.GetCount(); i++) | |
4453 | { | |
4454 | n = line->m_items.Item( i ); | |
4455 | itemData = n->GetData(); | |
4456 | itemData->GetItem(item); | |
4457 | ||
4458 | itemWidth = GetItemWidthWithImage(&item); | |
4459 | ||
4460 | if (itemWidth >= m_aColWidths.Item(i)->nMaxWidth) | |
4461 | m_aColWidths.Item(i)->bNeedsUpdate = true; | |
4462 | } | |
4463 | ||
6b4a8d93 | 4464 | ResetVisibleLinesRange(); |
938b652b VZ |
4465 | } |
4466 | ||
a95d5751 RR |
4467 | SendNotify( index, wxEVT_COMMAND_LIST_DELETE_ITEM, wxDefaultPosition ); |
4468 | ||
938b652b VZ |
4469 | if ( IsVirtual() ) |
4470 | { | |
4471 | m_countVirt--; | |
b54e41c5 VZ |
4472 | m_selStore.OnItemDelete(index); |
4473 | } | |
4474 | else | |
4475 | { | |
4476 | m_lines.RemoveAt( index ); | |
63852e78 | 4477 | } |
6b4a8d93 | 4478 | |
70541533 | 4479 | // we need to refresh the (vert) scrollbar as the number of items changed |
ca65c044 | 4480 | m_dirty = true; |
91c6cc0e | 4481 | |
6b4a8d93 | 4482 | RefreshAfter(index); |
e1e955e1 | 4483 | } |
c801d85f | 4484 | |
debe6624 | 4485 | void wxListMainWindow::DeleteColumn( int col ) |
c801d85f | 4486 | { |
222ed1d6 | 4487 | wxListHeaderDataList::compatibility_iterator node = m_columns.Item( col ); |
24b9f055 VZ |
4488 | |
4489 | wxCHECK_RET( node, wxT("invalid column index in DeleteColumn()") ); | |
bd8289c1 | 4490 | |
ca65c044 | 4491 | m_dirty = true; |
222ed1d6 MB |
4492 | delete node->GetData(); |
4493 | m_columns.Erase( node ); | |
ae409cb8 | 4494 | |
df6f82f0 VZ |
4495 | if ( !IsVirtual() ) |
4496 | { | |
4497 | // update all the items | |
4498 | for ( size_t i = 0; i < m_lines.GetCount(); i++ ) | |
4499 | { | |
4500 | wxListLineData * const line = GetLine(i); | |
222ed1d6 MB |
4501 | wxListItemDataList::compatibility_iterator n = line->m_items.Item( col ); |
4502 | delete n->GetData(); | |
4503 | line->m_items.Erase(n); | |
df6f82f0 VZ |
4504 | } |
4505 | } | |
4506 | ||
7d4813a0 VZ |
4507 | if ( InReportView() ) // we only cache max widths when in Report View |
4508 | { | |
4509 | delete m_aColWidths.Item(col); | |
4510 | m_aColWidths.RemoveAt(col); | |
4511 | } | |
4512 | ||
ae409cb8 VZ |
4513 | // invalidate it as it has to be recalculated |
4514 | m_headerWidth = 0; | |
e1e955e1 | 4515 | } |
c801d85f | 4516 | |
5fe143df | 4517 | void wxListMainWindow::DoDeleteAllItems() |
c801d85f | 4518 | { |
cf1dfa6b | 4519 | if ( IsEmpty() ) |
cf1dfa6b VZ |
4520 | // nothing to do - in particular, don't send the event |
4521 | return; | |
cf1dfa6b | 4522 | |
b54e41c5 | 4523 | ResetCurrent(); |
7c0ea335 VZ |
4524 | |
4525 | // to make the deletion of all items faster, we don't send the | |
cf1dfa6b VZ |
4526 | // notifications for each item deletion in this case but only one event |
4527 | // for all of them: this is compatible with wxMSW and documented in | |
4528 | // DeleteAllItems() description | |
bffa1c77 | 4529 | |
12c1b46a RR |
4530 | wxListEvent event( wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS, GetParent()->GetId() ); |
4531 | event.SetEventObject( GetParent() ); | |
4532 | GetParent()->GetEventHandler()->ProcessEvent( event ); | |
7c0ea335 | 4533 | |
b54e41c5 VZ |
4534 | if ( IsVirtual() ) |
4535 | { | |
4536 | m_countVirt = 0; | |
850ed6e7 | 4537 | m_selStore.Clear(); |
b54e41c5 VZ |
4538 | } |
4539 | ||
6b4a8d93 VZ |
4540 | if ( InReportView() ) |
4541 | { | |
4542 | ResetVisibleLinesRange(); | |
7d4813a0 VZ |
4543 | for (size_t i = 0; i < m_aColWidths.GetCount(); i++) |
4544 | { | |
8d36b216 | 4545 | m_aColWidths.Item(i)->bNeedsUpdate = true; |
7d4813a0 | 4546 | } |
6b4a8d93 VZ |
4547 | } |
4548 | ||
5b077d48 | 4549 | m_lines.Clear(); |
5fe143df | 4550 | } |
cf1dfa6b | 4551 | |
5fe143df VZ |
4552 | void wxListMainWindow::DeleteAllItems() |
4553 | { | |
4554 | DoDeleteAllItems(); | |
4555 | ||
4556 | RecalculatePositions(); | |
e1e955e1 | 4557 | } |
c801d85f | 4558 | |
12c1b46a | 4559 | void wxListMainWindow::DeleteEverything() |
c801d85f | 4560 | { |
222ed1d6 | 4561 | WX_CLEAR_LIST(wxListHeaderDataList, m_columns); |
8d36b216 | 4562 | WX_CLEAR_ARRAY(m_aColWidths); |
904ccf52 VZ |
4563 | |
4564 | DeleteAllItems(); | |
e1e955e1 | 4565 | } |
c801d85f | 4566 | |
cf1dfa6b VZ |
4567 | // ---------------------------------------------------------------------------- |
4568 | // scanning for an item | |
4569 | // ---------------------------------------------------------------------------- | |
4570 | ||
debe6624 | 4571 | void wxListMainWindow::EnsureVisible( long index ) |
c801d85f | 4572 | { |
cf1dfa6b VZ |
4573 | wxCHECK_RET( index >= 0 && (size_t)index < GetItemCount(), |
4574 | _T("invalid index in EnsureVisible") ); | |
4575 | ||
4576 | // We have to call this here because the label in question might just have | |
34bbbc27 VZ |
4577 | // been added and its position is not known yet |
4578 | if ( m_dirty ) | |
ca65c044 | 4579 | RecalculatePositions(true /* no refresh */); |
34bbbc27 VZ |
4580 | |
4581 | MoveToItem((size_t)index); | |
e1e955e1 | 4582 | } |
c801d85f | 4583 | |
23739465 | 4584 | long wxListMainWindow::FindItem(long start, const wxString& str, bool partial ) |
c801d85f | 4585 | { |
23739465 RR |
4586 | if (str.empty()) |
4587 | return wxNOT_FOUND; | |
6fef2483 | 4588 | |
5b077d48 | 4589 | long pos = start; |
23739465 | 4590 | wxString str_upper = str.Upper(); |
cf1dfa6b VZ |
4591 | if (pos < 0) |
4592 | pos = 0; | |
54442116 | 4593 | |
cf1dfa6b VZ |
4594 | size_t count = GetItemCount(); |
4595 | for ( size_t i = (size_t)pos; i < count; i++ ) | |
4596 | { | |
4597 | wxListLineData *line = GetLine(i); | |
23739465 RR |
4598 | wxString line_upper = line->GetText(0).Upper(); |
4599 | if (!partial) | |
4600 | { | |
4601 | if (line_upper == str_upper ) | |
4602 | return i; | |
4603 | } | |
4604 | else | |
4605 | { | |
4606 | if (line_upper.find(str_upper) == 0) | |
4607 | return i; | |
4608 | } | |
5b077d48 | 4609 | } |
cf1dfa6b VZ |
4610 | |
4611 | return wxNOT_FOUND; | |
e1e955e1 | 4612 | } |
c801d85f | 4613 | |
81ce36aa | 4614 | long wxListMainWindow::FindItem(long start, wxUIntPtr data) |
c801d85f | 4615 | { |
5b077d48 | 4616 | long pos = start; |
cf1dfa6b VZ |
4617 | if (pos < 0) |
4618 | pos = 0; | |
4619 | ||
4620 | size_t count = GetItemCount(); | |
4621 | for (size_t i = (size_t)pos; i < count; i++) | |
5b077d48 | 4622 | { |
cf1dfa6b | 4623 | wxListLineData *line = GetLine(i); |
5b077d48 RR |
4624 | wxListItem item; |
4625 | line->GetItem( 0, item ); | |
cf1dfa6b VZ |
4626 | if (item.m_data == data) |
4627 | return i; | |
5b077d48 | 4628 | } |
cf1dfa6b VZ |
4629 | |
4630 | return wxNOT_FOUND; | |
e1e955e1 | 4631 | } |
c801d85f | 4632 | |
8158e0e1 VZ |
4633 | long wxListMainWindow::FindItem( const wxPoint& pt ) |
4634 | { | |
e6bf9573 | 4635 | size_t topItem; |
277ea1b4 | 4636 | GetVisibleLinesRange( &topItem, NULL ); |
8158e0e1 | 4637 | |
e6bf9573 | 4638 | wxPoint p; |
277ea1b4 DS |
4639 | GetItemPosition( GetItemCount() - 1, p ); |
4640 | if ( p.y == 0 ) | |
e6bf9573 | 4641 | return topItem; |
277ea1b4 DS |
4642 | |
4643 | long id = (long)floor( pt.y * double(GetItemCount() - topItem - 1) / p.y + topItem ); | |
4644 | if ( id >= 0 && id < (long)GetItemCount() ) | |
e6bf9573 | 4645 | return id; |
8158e0e1 | 4646 | |
e6bf9573 | 4647 | return wxNOT_FOUND; |
8158e0e1 VZ |
4648 | } |
4649 | ||
be0e5d69 | 4650 | long wxListMainWindow::HitTest( int x, int y, int &flags ) const |
c801d85f | 4651 | { |
aaef15bf | 4652 | CalcUnscrolledPosition( x, y, &x, &y ); |
e8741cca | 4653 | |
fc4f1d5f VZ |
4654 | size_t count = GetItemCount(); |
4655 | ||
b5d43d1d | 4656 | if ( InReportView() ) |
c801d85f | 4657 | { |
5cd89174 | 4658 | size_t current = y / GetLineHeight(); |
fc4f1d5f VZ |
4659 | if ( current < count ) |
4660 | { | |
4661 | flags = HitTestLine(current, x, y); | |
4662 | if ( flags ) | |
4663 | return current; | |
4664 | } | |
5cd89174 VZ |
4665 | } |
4666 | else // !report | |
4667 | { | |
4668 | // TODO: optimize it too! this is less simple than for report view but | |
4669 | // enumerating all items is still not a way to do it!! | |
5cd89174 | 4670 | for ( size_t current = 0; current < count; current++ ) |
5b077d48 | 4671 | { |
5cd89174 VZ |
4672 | flags = HitTestLine(current, x, y); |
4673 | if ( flags ) | |
4674 | return current; | |
5b077d48 | 4675 | } |
e1e955e1 | 4676 | } |
cf1dfa6b VZ |
4677 | |
4678 | return wxNOT_FOUND; | |
e1e955e1 | 4679 | } |
c801d85f | 4680 | |
cf1dfa6b VZ |
4681 | // ---------------------------------------------------------------------------- |
4682 | // adding stuff | |
4683 | // ---------------------------------------------------------------------------- | |
4684 | ||
c801d85f KB |
4685 | void wxListMainWindow::InsertItem( wxListItem &item ) |
4686 | { | |
cf1dfa6b VZ |
4687 | wxASSERT_MSG( !IsVirtual(), _T("can't be used with virtual control") ); |
4688 | ||
c7cf7a78 | 4689 | int count = GetItemCount(); |
33c956e6 | 4690 | wxCHECK_RET( item.m_itemId >= 0, _T("invalid item index") ); |
cf1dfa6b | 4691 | |
33c956e6 RD |
4692 | if (item.m_itemId > count) |
4693 | item.m_itemId = count; | |
b713f891 | 4694 | |
cf1dfa6b VZ |
4695 | size_t id = item.m_itemId; |
4696 | ||
ca65c044 | 4697 | m_dirty = true; |
cf1dfa6b | 4698 | |
b5d43d1d | 4699 | if ( InReportView() ) |
2b5f62a0 | 4700 | { |
2b5f62a0 | 4701 | ResetVisibleLinesRange(); |
7d4813a0 VZ |
4702 | |
4703 | // calculate the width of the item and adjust the max column width | |
4704 | wxColWidthInfo *pWidthInfo = m_aColWidths.Item(item.GetColumn()); | |
f5c479cc | 4705 | int width = GetItemWidthWithImage(&item); |
7d4813a0 VZ |
4706 | item.SetWidth(width); |
4707 | if (width > pWidthInfo->nMaxWidth) | |
4708 | pWidthInfo->nMaxWidth = width; | |
1370703e | 4709 | } |
004fd0c8 | 4710 | |
5cd89174 | 4711 | wxListLineData *line = new wxListLineData(this); |
004fd0c8 | 4712 | |
1e6601c7 | 4713 | line->SetItem( item.m_col, item ); |
cf1dfa6b VZ |
4714 | |
4715 | m_lines.Insert( line, id ); | |
5cd89174 | 4716 | |
ca65c044 | 4717 | m_dirty = true; |
a67e6e54 | 4718 | |
ab96d680 VZ |
4719 | // If an item is selected at or below the point of insertion, we need to |
4720 | // increment the member variables because the current row's index has gone | |
4721 | // up by one | |
4722 | if ( HasCurrent() && m_current >= id ) | |
ab96d680 | 4723 | m_current++; |
ab96d680 | 4724 | |
a67e6e54 VZ |
4725 | SendNotify(id, wxEVT_COMMAND_LIST_INSERT_ITEM); |
4726 | ||
5cd89174 | 4727 | RefreshLines(id, GetItemCount() - 1); |
e1e955e1 | 4728 | } |
c801d85f | 4729 | |
debe6624 | 4730 | void wxListMainWindow::InsertColumn( long col, wxListItem &item ) |
c801d85f | 4731 | { |
ca65c044 | 4732 | m_dirty = true; |
b5d43d1d | 4733 | if ( InReportView() ) |
3db7be80 | 4734 | { |
54442116 VZ |
4735 | if (item.m_width == wxLIST_AUTOSIZE_USEHEADER) |
4736 | item.m_width = GetTextLength( item.m_text ); | |
df6f82f0 | 4737 | |
5b077d48 | 4738 | wxListHeaderData *column = new wxListHeaderData( item ); |
7d4813a0 VZ |
4739 | wxColWidthInfo *colWidthInfo = new wxColWidthInfo(); |
4740 | ||
df6f82f0 VZ |
4741 | bool insert = (col >= 0) && ((size_t)col < m_columns.GetCount()); |
4742 | if ( insert ) | |
5b077d48 | 4743 | { |
7d4813a0 VZ |
4744 | wxListHeaderDataList::compatibility_iterator |
4745 | node = m_columns.Item( col ); | |
24b9f055 | 4746 | m_columns.Insert( node, column ); |
7d4813a0 | 4747 | m_aColWidths.Insert( colWidthInfo, col ); |
5b077d48 RR |
4748 | } |
4749 | else | |
4750 | { | |
4751 | m_columns.Append( column ); | |
7d4813a0 | 4752 | m_aColWidths.Add( colWidthInfo ); |
5b077d48 | 4753 | } |
ae409cb8 | 4754 | |
df6f82f0 VZ |
4755 | if ( !IsVirtual() ) |
4756 | { | |
4757 | // update all the items | |
4758 | for ( size_t i = 0; i < m_lines.GetCount(); i++ ) | |
4759 | { | |
4760 | wxListLineData * const line = GetLine(i); | |
4761 | wxListItemData * const data = new wxListItemData(this); | |
4762 | if ( insert ) | |
4763 | line->m_items.Insert(col, data); | |
4764 | else | |
4765 | line->m_items.Append(data); | |
4766 | } | |
4767 | } | |
4768 | ||
ae409cb8 VZ |
4769 | // invalidate it as it has to be recalculated |
4770 | m_headerWidth = 0; | |
3db7be80 | 4771 | } |
e1e955e1 | 4772 | } |
c801d85f | 4773 | |
7d4813a0 VZ |
4774 | int wxListMainWindow::GetItemWidthWithImage(wxListItem * item) |
4775 | { | |
4776 | int width = 0; | |
4777 | wxClientDC dc(this); | |
4778 | ||
4779 | dc.SetFont( GetFont() ); | |
4780 | ||
4781 | if (item->GetImage() != -1) | |
4782 | { | |
4783 | int ix, iy; | |
4784 | GetImageSize( item->GetImage(), ix, iy ); | |
4785 | width += ix + 5; | |
4786 | } | |
4787 | ||
4788 | if (!item->GetText().empty()) | |
4789 | { | |
4790 | wxCoord w; | |
4791 | dc.GetTextExtent( item->GetText(), &w, NULL ); | |
4792 | width += w; | |
4793 | } | |
4794 | ||
4795 | return width; | |
4796 | } | |
4797 | ||
cf1dfa6b VZ |
4798 | // ---------------------------------------------------------------------------- |
4799 | // sorting | |
4800 | // ---------------------------------------------------------------------------- | |
4801 | ||
c801d85f KB |
4802 | wxListCtrlCompare list_ctrl_compare_func_2; |
4803 | long list_ctrl_compare_data; | |
4804 | ||
f6bcfd97 | 4805 | int LINKAGEMODE list_ctrl_compare_func_1( wxListLineData **arg1, wxListLineData **arg2 ) |
c801d85f | 4806 | { |
f6bcfd97 BP |
4807 | wxListLineData *line1 = *arg1; |
4808 | wxListLineData *line2 = *arg2; | |
5b077d48 RR |
4809 | wxListItem item; |
4810 | line1->GetItem( 0, item ); | |
81ce36aa | 4811 | wxUIntPtr data1 = item.m_data; |
5b077d48 | 4812 | line2->GetItem( 0, item ); |
81ce36aa | 4813 | wxUIntPtr data2 = item.m_data; |
5b077d48 | 4814 | return list_ctrl_compare_func_2( data1, data2, list_ctrl_compare_data ); |
e1e955e1 | 4815 | } |
c801d85f KB |
4816 | |
4817 | void wxListMainWindow::SortItems( wxListCtrlCompare fn, long data ) | |
4818 | { | |
6b06a727 VZ |
4819 | // selections won't make sense any more after sorting the items so reset |
4820 | // them | |
4821 | HighlightAll(false); | |
4822 | ResetCurrent(); | |
4823 | ||
5b077d48 RR |
4824 | list_ctrl_compare_func_2 = fn; |
4825 | list_ctrl_compare_data = data; | |
4826 | m_lines.Sort( list_ctrl_compare_func_1 ); | |
ca65c044 | 4827 | m_dirty = true; |
e1e955e1 | 4828 | } |
c801d85f | 4829 | |
cf1dfa6b VZ |
4830 | // ---------------------------------------------------------------------------- |
4831 | // scrolling | |
4832 | // ---------------------------------------------------------------------------- | |
4833 | ||
7c74e7fe SC |
4834 | void wxListMainWindow::OnScroll(wxScrollWinEvent& event) |
4835 | { | |
29149a64 | 4836 | // FIXME |
4e6b6f21 | 4837 | #if ( defined(__WXGTK__) || defined(__WXMAC__) ) && !defined(__WXUNIVERSAL__) |
29149a64 VZ |
4838 | wxScrolledWindow::OnScroll(event); |
4839 | #else | |
1e6feb95 | 4840 | HandleOnScroll( event ); |
29149a64 | 4841 | #endif |
30954328 | 4842 | |
602e3365 RR |
4843 | // update our idea of which lines are shown when we redraw the window the |
4844 | // next time | |
4845 | ResetVisibleLinesRange(); | |
a9aead31 | 4846 | |
cf1dfa6b | 4847 | if ( event.GetOrientation() == wxHORIZONTAL && HasHeader() ) |
7c74e7fe | 4848 | { |
3cd94a0d | 4849 | wxGenericListCtrl* lc = GetListCtrl(); |
cf1dfa6b VZ |
4850 | wxCHECK_RET( lc, _T("no listctrl window?") ); |
4851 | ||
afbe906a RR |
4852 | lc->m_headerWin->Refresh(); |
4853 | lc->m_headerWin->Update(); | |
7c74e7fe | 4854 | } |
cf1dfa6b VZ |
4855 | } |
4856 | ||
5cd89174 VZ |
4857 | int wxListMainWindow::GetCountPerPage() const |
4858 | { | |
4859 | if ( !m_linesPerPage ) | |
4860 | { | |
4861 | wxConstCast(this, wxListMainWindow)-> | |
4862 | m_linesPerPage = GetClientSize().y / GetLineHeight(); | |
4863 | } | |
4864 | ||
4865 | return m_linesPerPage; | |
4866 | } | |
4867 | ||
b54e41c5 | 4868 | void wxListMainWindow::GetVisibleLinesRange(size_t *from, size_t *to) |
cf1dfa6b | 4869 | { |
b5d43d1d | 4870 | wxASSERT_MSG( InReportView(), _T("this is for report mode only") ); |
cf1dfa6b | 4871 | |
b54e41c5 VZ |
4872 | if ( m_lineFrom == (size_t)-1 ) |
4873 | { | |
b54e41c5 | 4874 | size_t count = GetItemCount(); |
6522713c VZ |
4875 | if ( count ) |
4876 | { | |
4877 | m_lineFrom = GetScrollPos(wxVERTICAL); | |
cf1dfa6b | 4878 | |
152c57f2 VZ |
4879 | // this may happen if SetScrollbars() hadn't been called yet |
4880 | if ( m_lineFrom >= count ) | |
bcc0da5c | 4881 | m_lineFrom = count - 1; |
cf1dfa6b | 4882 | |
6522713c VZ |
4883 | // we redraw one extra line but this is needed to make the redrawing |
4884 | // logic work when there is a fractional number of lines on screen | |
4885 | m_lineTo = m_lineFrom + m_linesPerPage; | |
4886 | if ( m_lineTo >= count ) | |
4887 | m_lineTo = count - 1; | |
4888 | } | |
4889 | else // empty control | |
4890 | { | |
4891 | m_lineFrom = 0; | |
4892 | m_lineTo = (size_t)-1; | |
4893 | } | |
cf1dfa6b | 4894 | } |
b54e41c5 | 4895 | |
ae167d2f VZ |
4896 | wxASSERT_MSG( IsEmpty() || |
4897 | (m_lineFrom <= m_lineTo && m_lineTo < GetItemCount()), | |
6b4a8d93 VZ |
4898 | _T("GetVisibleLinesRange() returns incorrect result") ); |
4899 | ||
b54e41c5 VZ |
4900 | if ( from ) |
4901 | *from = m_lineFrom; | |
4902 | if ( to ) | |
4903 | *to = m_lineTo; | |
7c74e7fe SC |
4904 | } |
4905 | ||
c801d85f | 4906 | // ------------------------------------------------------------------------------------- |
3cd94a0d | 4907 | // wxGenericListCtrl |
c801d85f KB |
4908 | // ------------------------------------------------------------------------------------- |
4909 | ||
3cd94a0d JS |
4910 | IMPLEMENT_DYNAMIC_CLASS(wxGenericListCtrl, wxControl) |
4911 | ||
3cd94a0d JS |
4912 | BEGIN_EVENT_TABLE(wxGenericListCtrl,wxControl) |
4913 | EVT_SIZE(wxGenericListCtrl::OnSize) | |
c801d85f KB |
4914 | END_EVENT_TABLE() |
4915 | ||
3cd94a0d | 4916 | wxGenericListCtrl::wxGenericListCtrl() |
c801d85f | 4917 | { |
8a3e173a KO |
4918 | m_imageListNormal = (wxImageList *) NULL; |
4919 | m_imageListSmall = (wxImageList *) NULL; | |
4920 | m_imageListState = (wxImageList *) NULL; | |
cf1dfa6b VZ |
4921 | |
4922 | m_ownsImageListNormal = | |
4923 | m_ownsImageListSmall = | |
ca65c044 | 4924 | m_ownsImageListState = false; |
cf1dfa6b | 4925 | |
5b077d48 RR |
4926 | m_mainWin = (wxListMainWindow*) NULL; |
4927 | m_headerWin = (wxListHeaderWindow*) NULL; | |
f8252483 | 4928 | m_headerHeight = 0; |
c801d85f KB |
4929 | } |
4930 | ||
3cd94a0d | 4931 | wxGenericListCtrl::~wxGenericListCtrl() |
c801d85f | 4932 | { |
cf1dfa6b VZ |
4933 | if (m_ownsImageListNormal) |
4934 | delete m_imageListNormal; | |
4935 | if (m_ownsImageListSmall) | |
4936 | delete m_imageListSmall; | |
4937 | if (m_ownsImageListState) | |
4938 | delete m_imageListState; | |
4939 | } | |
4940 | ||
f8252483 JS |
4941 | void wxGenericListCtrl::CalculateAndSetHeaderHeight() |
4942 | { | |
86351e4a VZ |
4943 | if ( m_headerWin ) |
4944 | { | |
fec8346a | 4945 | #ifdef __WXMAC__ |
277ea1b4 | 4946 | SInt32 h; |
0afa5859 | 4947 | GetThemeMetric( kThemeMetricListHeaderHeight, &h ); |
fec8346a | 4948 | #else |
86351e4a VZ |
4949 | // we use 'g' to get the descent, too |
4950 | int w, h, d; | |
4951 | m_headerWin->GetTextExtent(wxT("Hg"), &w, &h, &d); | |
4952 | h += d + 2 * HEADER_OFFSET_Y + EXTRA_HEIGHT; | |
fec8346a | 4953 | #endif |
277ea1b4 | 4954 | |
8b1ed8d9 VZ |
4955 | // only update if changed |
4956 | if ( h != m_headerHeight ) | |
86351e4a VZ |
4957 | { |
4958 | m_headerHeight = h; | |
4959 | ||
b5d43d1d | 4960 | if ( HasHeader() ) |
ca65c044 | 4961 | ResizeReportView(true); |
2ae226dd JS |
4962 | else //why is this needed if it doesn't have a header? |
4963 | m_headerWin->SetSize(m_headerWin->GetSize().x, m_headerHeight); | |
86351e4a VZ |
4964 | } |
4965 | } | |
f8252483 JS |
4966 | } |
4967 | ||
3cd94a0d | 4968 | void wxGenericListCtrl::CreateHeaderWindow() |
cf1dfa6b VZ |
4969 | { |
4970 | m_headerWin = new wxListHeaderWindow | |
4971 | ( | |
ca65c044 | 4972 | this, wxID_ANY, m_mainWin, |
c47addef | 4973 | wxPoint(0,0), |
f8252483 | 4974 | wxSize(GetClientSize().x, m_headerHeight), |
cf1dfa6b VZ |
4975 | wxTAB_TRAVERSAL |
4976 | ); | |
f8252483 | 4977 | CalculateAndSetHeaderHeight(); |
c801d85f KB |
4978 | } |
4979 | ||
3cd94a0d | 4980 | bool wxGenericListCtrl::Create(wxWindow *parent, |
25e3a937 VZ |
4981 | wxWindowID id, |
4982 | const wxPoint &pos, | |
4983 | const wxSize &size, | |
4984 | long style, | |
25e3a937 | 4985 | const wxValidator &validator, |
25e3a937 | 4986 | const wxString &name) |
c801d85f | 4987 | { |
cf1dfa6b VZ |
4988 | m_imageListNormal = |
4989 | m_imageListSmall = | |
8a3e173a | 4990 | m_imageListState = (wxImageList *) NULL; |
cf1dfa6b VZ |
4991 | m_ownsImageListNormal = |
4992 | m_ownsImageListSmall = | |
ca65c044 | 4993 | m_ownsImageListState = false; |
cf1dfa6b | 4994 | |
5b077d48 RR |
4995 | m_mainWin = (wxListMainWindow*) NULL; |
4996 | m_headerWin = (wxListHeaderWindow*) NULL; | |
bd8289c1 | 4997 | |
3fc93ebd JS |
4998 | m_headerHeight = 0; |
4999 | ||
b54e41c5 | 5000 | if ( !(style & wxLC_MASK_TYPE) ) |
5b077d48 | 5001 | { |
25e3a937 | 5002 | style = style | wxLC_LIST; |
5b077d48 | 5003 | } |
f6bcfd97 | 5004 | |
07215d86 | 5005 | if ( !wxControl::Create( parent, id, pos, size, style, validator, name ) ) |
ca65c044 | 5006 | return false; |
f6bcfd97 | 5007 | |
6ac90263 VZ |
5008 | // this window itself shouldn't get the focus, only m_mainWin should |
5009 | SetCanFocus(false); | |
5010 | ||
b54e41c5 | 5011 | // don't create the inner window with the border |
6d460f76 | 5012 | style &= ~wxBORDER_MASK; |
bd8289c1 | 5013 | |
277ea1b4 | 5014 | m_mainWin = new wxListMainWindow( this, wxID_ANY, wxPoint(0, 0), size, style ); |
bd8289c1 | 5015 | |
b713f891 | 5016 | #ifdef __WXMAC_CARBON__ |
309e4c14 SC |
5017 | // Human Interface Guidelines ask us for a special font in this case |
5018 | if ( GetWindowVariant() == wxWINDOW_VARIANT_NORMAL ) | |
5019 | { | |
277ea1b4 DS |
5020 | wxFont font; |
5021 | font.MacCreateThemeFont( kThemeViewsFont ); | |
5022 | SetFont( font ); | |
309e4c14 | 5023 | } |
f89d65ea | 5024 | #endif |
277ea1b4 | 5025 | |
b5d43d1d | 5026 | if ( InReportView() ) |
ea451729 | 5027 | { |
cf1dfa6b | 5028 | CreateHeaderWindow(); |
277ea1b4 | 5029 | |
d108f236 SC |
5030 | #ifdef __WXMAC_CARBON__ |
5031 | if (m_headerWin) | |
5032 | { | |
277ea1b4 DS |
5033 | wxFont font; |
5034 | font.MacCreateThemeFont( kThemeSmallSystemFont ); | |
d108f236 SC |
5035 | m_headerWin->SetFont( font ); |
5036 | CalculateAndSetHeaderHeight(); | |
5037 | } | |
5038 | #endif | |
277ea1b4 | 5039 | |
b54e41c5 | 5040 | if ( HasFlag(wxLC_NO_HEADER) ) |
cf1dfa6b | 5041 | // VZ: why do we create it at all then? |
ca65c044 | 5042 | m_headerWin->Show( false ); |
ea451729 | 5043 | } |
bd8289c1 | 5044 | |
170acdc9 | 5045 | SetInitialSize(size); |
ca65c044 WS |
5046 | |
5047 | return true; | |
e1e955e1 | 5048 | } |
c801d85f | 5049 | |
3cd94a0d | 5050 | void wxGenericListCtrl::SetSingleStyle( long style, bool add ) |
c801d85f | 5051 | { |
b54e41c5 VZ |
5052 | wxASSERT_MSG( !(style & wxLC_VIRTUAL), |
5053 | _T("wxLC_VIRTUAL can't be [un]set") ); | |
5054 | ||
f03fc89f | 5055 | long flag = GetWindowStyle(); |
bd8289c1 | 5056 | |
5b077d48 RR |
5057 | if (add) |
5058 | { | |
cf1dfa6b | 5059 | if (style & wxLC_MASK_TYPE) |
b54e41c5 | 5060 | flag &= ~(wxLC_MASK_TYPE | wxLC_VIRTUAL); |
cf1dfa6b VZ |
5061 | if (style & wxLC_MASK_ALIGN) |
5062 | flag &= ~wxLC_MASK_ALIGN; | |
5063 | if (style & wxLC_MASK_SORT) | |
5064 | flag &= ~wxLC_MASK_SORT; | |
5b077d48 | 5065 | } |
c801d85f | 5066 | |
5b077d48 | 5067 | if (add) |
5b077d48 | 5068 | flag |= style; |
5b077d48 | 5069 | else |
cf1dfa6b | 5070 | flag &= ~style; |
bd8289c1 | 5071 | |
5b077d48 | 5072 | SetWindowStyleFlag( flag ); |
e1e955e1 | 5073 | } |
c801d85f | 5074 | |
3cd94a0d | 5075 | void wxGenericListCtrl::SetWindowStyleFlag( long flag ) |
c801d85f | 5076 | { |
121a3581 RR |
5077 | if (m_mainWin) |
5078 | { | |
5079 | m_mainWin->DeleteEverything(); | |
c801d85f | 5080 | |
a95cdab8 | 5081 | // has the header visibility changed? |
b5d43d1d VZ |
5082 | bool hasHeader = HasHeader(); |
5083 | bool willHaveHeader = (flag & wxLC_REPORT) && !(flag & wxLC_NO_HEADER); | |
c801d85f | 5084 | |
a95cdab8 | 5085 | if ( hasHeader != willHaveHeader ) |
5b077d48 | 5086 | { |
a95cdab8 VZ |
5087 | // toggle it |
5088 | if ( hasHeader ) | |
5089 | { | |
5090 | if ( m_headerWin ) | |
5091 | { | |
5092 | // don't delete, just hide, as we can reuse it later | |
ca65c044 | 5093 | m_headerWin->Show(false); |
a95cdab8 VZ |
5094 | } |
5095 | //else: nothing to do | |
5096 | } | |
5097 | else // must show header | |
5b077d48 | 5098 | { |
121a3581 RR |
5099 | if (!m_headerWin) |
5100 | { | |
cf1dfa6b | 5101 | CreateHeaderWindow(); |
121a3581 | 5102 | } |
a95cdab8 | 5103 | else // already have it, just show |
004fd0c8 | 5104 | { |
ca65c044 | 5105 | m_headerWin->Show( true ); |
004fd0c8 | 5106 | } |
5b077d48 | 5107 | } |
a95cdab8 VZ |
5108 | |
5109 | ResizeReportView(willHaveHeader); | |
bffa1c77 | 5110 | } |
e1e955e1 | 5111 | } |
004fd0c8 | 5112 | |
5b077d48 | 5113 | wxWindow::SetWindowStyleFlag( flag ); |
e1e955e1 | 5114 | } |
c801d85f | 5115 | |
3cd94a0d | 5116 | bool wxGenericListCtrl::GetColumn(int col, wxListItem &item) const |
c801d85f | 5117 | { |
5b077d48 | 5118 | m_mainWin->GetColumn( col, item ); |
ca65c044 | 5119 | return true; |
e1e955e1 | 5120 | } |
c801d85f | 5121 | |
3cd94a0d | 5122 | bool wxGenericListCtrl::SetColumn( int col, wxListItem& item ) |
c801d85f | 5123 | { |
5b077d48 | 5124 | m_mainWin->SetColumn( col, item ); |
ca65c044 | 5125 | return true; |
e1e955e1 | 5126 | } |
c801d85f | 5127 | |
3cd94a0d | 5128 | int wxGenericListCtrl::GetColumnWidth( int col ) const |
c801d85f | 5129 | { |
5b077d48 | 5130 | return m_mainWin->GetColumnWidth( col ); |
e1e955e1 | 5131 | } |
c801d85f | 5132 | |
3cd94a0d | 5133 | bool wxGenericListCtrl::SetColumnWidth( int col, int width ) |
c801d85f | 5134 | { |
5b077d48 | 5135 | m_mainWin->SetColumnWidth( col, width ); |
ca65c044 | 5136 | return true; |
e1e955e1 | 5137 | } |
c801d85f | 5138 | |
3cd94a0d | 5139 | int wxGenericListCtrl::GetCountPerPage() const |
c801d85f KB |
5140 | { |
5141 | return m_mainWin->GetCountPerPage(); // different from Windows ? | |
e1e955e1 | 5142 | } |
c801d85f | 5143 | |
3cd94a0d | 5144 | bool wxGenericListCtrl::GetItem( wxListItem &info ) const |
c801d85f | 5145 | { |
5b077d48 | 5146 | m_mainWin->GetItem( info ); |
ca65c044 | 5147 | return true; |
e1e955e1 | 5148 | } |
c801d85f | 5149 | |
3cd94a0d | 5150 | bool wxGenericListCtrl::SetItem( wxListItem &info ) |
c801d85f | 5151 | { |
5b077d48 | 5152 | m_mainWin->SetItem( info ); |
ca65c044 | 5153 | return true; |
e1e955e1 | 5154 | } |
c801d85f | 5155 | |
3cd94a0d | 5156 | long wxGenericListCtrl::SetItem( long index, int col, const wxString& label, int imageId ) |
c801d85f | 5157 | { |
5b077d48 RR |
5158 | wxListItem info; |
5159 | info.m_text = label; | |
5160 | info.m_mask = wxLIST_MASK_TEXT; | |
5161 | info.m_itemId = index; | |
5162 | info.m_col = col; | |
5163 | if ( imageId > -1 ) | |
5164 | { | |
5165 | info.m_image = imageId; | |
5166 | info.m_mask |= wxLIST_MASK_IMAGE; | |
277ea1b4 DS |
5167 | } |
5168 | ||
5b077d48 | 5169 | m_mainWin->SetItem(info); |
ca65c044 | 5170 | return true; |
e1e955e1 | 5171 | } |
c801d85f | 5172 | |
3cd94a0d | 5173 | int wxGenericListCtrl::GetItemState( long item, long stateMask ) const |
c801d85f | 5174 | { |
5b077d48 | 5175 | return m_mainWin->GetItemState( item, stateMask ); |
e1e955e1 | 5176 | } |
c801d85f | 5177 | |
3cd94a0d | 5178 | bool wxGenericListCtrl::SetItemState( long item, long state, long stateMask ) |
c801d85f | 5179 | { |
5b077d48 | 5180 | m_mainWin->SetItemState( item, state, stateMask ); |
ca65c044 | 5181 | return true; |
e1e955e1 | 5182 | } |
c801d85f | 5183 | |
aba3d35e VZ |
5184 | bool |
5185 | wxGenericListCtrl::SetItemImage( long item, int image, int WXUNUSED(selImage) ) | |
06db67bc RD |
5186 | { |
5187 | return SetItemColumnImage(item, 0, image); | |
5188 | } | |
5189 | ||
5190 | bool | |
5191 | wxGenericListCtrl::SetItemColumnImage( long item, long column, int image ) | |
c3627a00 JS |
5192 | { |
5193 | wxListItem info; | |
5194 | info.m_image = image; | |
5195 | info.m_mask = wxLIST_MASK_IMAGE; | |
5196 | info.m_itemId = item; | |
06db67bc | 5197 | info.m_col = column; |
c3627a00 JS |
5198 | m_mainWin->SetItem( info ); |
5199 | return true; | |
5200 | } | |
c801d85f | 5201 | |
3cd94a0d | 5202 | wxString wxGenericListCtrl::GetItemText( long item ) const |
c801d85f | 5203 | { |
62d89eb4 | 5204 | return m_mainWin->GetItemText(item); |
e1e955e1 | 5205 | } |
c801d85f | 5206 | |
3cd94a0d | 5207 | void wxGenericListCtrl::SetItemText( long item, const wxString& str ) |
c801d85f | 5208 | { |
62d89eb4 | 5209 | m_mainWin->SetItemText(item, str); |
e1e955e1 | 5210 | } |
c801d85f | 5211 | |
81ce36aa | 5212 | wxUIntPtr wxGenericListCtrl::GetItemData( long item ) const |
c801d85f | 5213 | { |
5b077d48 | 5214 | wxListItem info; |
39a7f085 | 5215 | info.m_mask = wxLIST_MASK_DATA; |
5b077d48 RR |
5216 | info.m_itemId = item; |
5217 | m_mainWin->GetItem( info ); | |
5218 | return info.m_data; | |
e1e955e1 | 5219 | } |
c801d85f | 5220 | |
9fcd0bf7 | 5221 | bool wxGenericListCtrl::SetItemPtrData( long item, wxUIntPtr data ) |
c801d85f | 5222 | { |
5b077d48 RR |
5223 | wxListItem info; |
5224 | info.m_mask = wxLIST_MASK_DATA; | |
5225 | info.m_itemId = item; | |
5226 | info.m_data = data; | |
5227 | m_mainWin->SetItem( info ); | |
ca65c044 | 5228 | return true; |
e1e955e1 | 5229 | } |
c801d85f | 5230 | |
11ebea16 VZ |
5231 | wxRect wxGenericListCtrl::GetViewRect() const |
5232 | { | |
5233 | return m_mainWin->GetViewRect(); | |
5234 | } | |
5235 | ||
277ea1b4 | 5236 | bool wxGenericListCtrl::GetItemRect( long item, wxRect &rect, int WXUNUSED(code) ) const |
c801d85f | 5237 | { |
5b077d48 | 5238 | m_mainWin->GetItemRect( item, rect ); |
7e6874c0 | 5239 | if ( m_mainWin->HasHeader() ) |
f8252483 | 5240 | rect.y += m_headerHeight + 1; |
ca65c044 | 5241 | return true; |
e1e955e1 | 5242 | } |
c801d85f | 5243 | |
3cd94a0d | 5244 | bool wxGenericListCtrl::GetItemPosition( long item, wxPoint& pos ) const |
c801d85f | 5245 | { |
5b077d48 | 5246 | m_mainWin->GetItemPosition( item, pos ); |
ca65c044 | 5247 | return true; |
e1e955e1 | 5248 | } |
c801d85f | 5249 | |
3cd94a0d | 5250 | bool wxGenericListCtrl::SetItemPosition( long WXUNUSED(item), const wxPoint& WXUNUSED(pos) ) |
c801d85f | 5251 | { |
5b077d48 | 5252 | return 0; |
e1e955e1 | 5253 | } |
c801d85f | 5254 | |
3cd94a0d | 5255 | int wxGenericListCtrl::GetItemCount() const |
c801d85f | 5256 | { |
5b077d48 | 5257 | return m_mainWin->GetItemCount(); |
e1e955e1 | 5258 | } |
c801d85f | 5259 | |
3cd94a0d | 5260 | int wxGenericListCtrl::GetColumnCount() const |
92976ab6 | 5261 | { |
5b077d48 | 5262 | return m_mainWin->GetColumnCount(); |
92976ab6 RR |
5263 | } |
5264 | ||
3cd94a0d | 5265 | void wxGenericListCtrl::SetItemSpacing( int spacing, bool isSmall ) |
33d0b396 | 5266 | { |
5b077d48 | 5267 | m_mainWin->SetItemSpacing( spacing, isSmall ); |
e1e955e1 | 5268 | } |
33d0b396 | 5269 | |
5db8d758 VZ |
5270 | wxSize wxGenericListCtrl::GetItemSpacing() const |
5271 | { | |
f58fc140 | 5272 | const int spacing = m_mainWin->GetItemSpacing(HasFlag(wxLC_SMALL_ICON)); |
5db8d758 VZ |
5273 | |
5274 | return wxSize(spacing, spacing); | |
5275 | } | |
5276 | ||
82d492f1 | 5277 | #if WXWIN_COMPATIBILITY_2_6 |
3cd94a0d | 5278 | int wxGenericListCtrl::GetItemSpacing( bool isSmall ) const |
c801d85f | 5279 | { |
5b077d48 | 5280 | return m_mainWin->GetItemSpacing( isSmall ); |
e1e955e1 | 5281 | } |
82d492f1 | 5282 | #endif // WXWIN_COMPATIBILITY_2_6 |
c801d85f | 5283 | |
3cd94a0d | 5284 | void wxGenericListCtrl::SetItemTextColour( long item, const wxColour &col ) |
5b98eb2f RL |
5285 | { |
5286 | wxListItem info; | |
5287 | info.m_itemId = item; | |
5288 | info.SetTextColour( col ); | |
5289 | m_mainWin->SetItem( info ); | |
5290 | } | |
5291 | ||
3cd94a0d | 5292 | wxColour wxGenericListCtrl::GetItemTextColour( long item ) const |
5b98eb2f RL |
5293 | { |
5294 | wxListItem info; | |
5295 | info.m_itemId = item; | |
5296 | m_mainWin->GetItem( info ); | |
5297 | return info.GetTextColour(); | |
5298 | } | |
5299 | ||
3cd94a0d | 5300 | void wxGenericListCtrl::SetItemBackgroundColour( long item, const wxColour &col ) |
5b98eb2f RL |
5301 | { |
5302 | wxListItem info; | |
5303 | info.m_itemId = item; | |
5304 | info.SetBackgroundColour( col ); | |
5305 | m_mainWin->SetItem( info ); | |
5306 | } | |
5307 | ||
3cd94a0d | 5308 | wxColour wxGenericListCtrl::GetItemBackgroundColour( long item ) const |
5b98eb2f RL |
5309 | { |
5310 | wxListItem info; | |
5311 | info.m_itemId = item; | |
5312 | m_mainWin->GetItem( info ); | |
5313 | return info.GetBackgroundColour(); | |
5314 | } | |
5315 | ||
bb29edfa KO |
5316 | int wxGenericListCtrl::GetScrollPos( int orient ) const |
5317 | { | |
5318 | return m_mainWin->GetScrollPos( orient ); | |
5319 | } | |
5320 | ||
5321 | void wxGenericListCtrl::SetScrollPos( int orient, int pos, bool refresh ) | |
5322 | { | |
5323 | m_mainWin->SetScrollPos( orient, pos, refresh ); | |
5324 | } | |
5325 | ||
35c2acd4 MW |
5326 | void wxGenericListCtrl::SetItemFont( long item, const wxFont &f ) |
5327 | { | |
5328 | wxListItem info; | |
5329 | info.m_itemId = item; | |
5330 | info.SetFont( f ); | |
5331 | m_mainWin->SetItem( info ); | |
5332 | } | |
5333 | ||
5334 | wxFont wxGenericListCtrl::GetItemFont( long item ) const | |
5335 | { | |
5336 | wxListItem info; | |
5337 | info.m_itemId = item; | |
5338 | m_mainWin->GetItem( info ); | |
5339 | return info.GetFont(); | |
5340 | } | |
5341 | ||
3cd94a0d | 5342 | int wxGenericListCtrl::GetSelectedItemCount() const |
c801d85f | 5343 | { |
5b077d48 | 5344 | return m_mainWin->GetSelectedItemCount(); |
e1e955e1 | 5345 | } |
c801d85f | 5346 | |
3cd94a0d | 5347 | wxColour wxGenericListCtrl::GetTextColour() const |
c801d85f | 5348 | { |
0530737d | 5349 | return GetForegroundColour(); |
e1e955e1 | 5350 | } |
c801d85f | 5351 | |
3cd94a0d | 5352 | void wxGenericListCtrl::SetTextColour(const wxColour& col) |
c801d85f | 5353 | { |
0530737d | 5354 | SetForegroundColour(col); |
e1e955e1 | 5355 | } |
c801d85f | 5356 | |
3cd94a0d | 5357 | long wxGenericListCtrl::GetTopItem() const |
c801d85f | 5358 | { |
2b5f62a0 VZ |
5359 | size_t top; |
5360 | m_mainWin->GetVisibleLinesRange(&top, NULL); | |
5361 | return (long)top; | |
e1e955e1 | 5362 | } |
c801d85f | 5363 | |
3cd94a0d | 5364 | long wxGenericListCtrl::GetNextItem( long item, int geom, int state ) const |
c801d85f | 5365 | { |
5b077d48 | 5366 | return m_mainWin->GetNextItem( item, geom, state ); |
e1e955e1 | 5367 | } |
c801d85f | 5368 | |
8a3e173a | 5369 | wxImageList *wxGenericListCtrl::GetImageList(int which) const |
c801d85f | 5370 | { |
5b077d48 | 5371 | if (which == wxIMAGE_LIST_NORMAL) |
5b077d48 | 5372 | return m_imageListNormal; |
5b077d48 | 5373 | else if (which == wxIMAGE_LIST_SMALL) |
5b077d48 | 5374 | return m_imageListSmall; |
5b077d48 | 5375 | else if (which == wxIMAGE_LIST_STATE) |
5b077d48 | 5376 | return m_imageListState; |
277ea1b4 | 5377 | |
8a3e173a | 5378 | return (wxImageList *) NULL; |
e1e955e1 | 5379 | } |
c801d85f | 5380 | |
8a3e173a | 5381 | void wxGenericListCtrl::SetImageList( wxImageList *imageList, int which ) |
c801d85f | 5382 | { |
2e12c11a VS |
5383 | if ( which == wxIMAGE_LIST_NORMAL ) |
5384 | { | |
277ea1b4 DS |
5385 | if (m_ownsImageListNormal) |
5386 | delete m_imageListNormal; | |
2e12c11a | 5387 | m_imageListNormal = imageList; |
ca65c044 | 5388 | m_ownsImageListNormal = false; |
2e12c11a VS |
5389 | } |
5390 | else if ( which == wxIMAGE_LIST_SMALL ) | |
5391 | { | |
277ea1b4 DS |
5392 | if (m_ownsImageListSmall) |
5393 | delete m_imageListSmall; | |
2e12c11a | 5394 | m_imageListSmall = imageList; |
ca65c044 | 5395 | m_ownsImageListSmall = false; |
2e12c11a VS |
5396 | } |
5397 | else if ( which == wxIMAGE_LIST_STATE ) | |
5398 | { | |
277ea1b4 DS |
5399 | if (m_ownsImageListState) |
5400 | delete m_imageListState; | |
2e12c11a | 5401 | m_imageListState = imageList; |
ca65c044 | 5402 | m_ownsImageListState = false; |
2e12c11a VS |
5403 | } |
5404 | ||
5b077d48 | 5405 | m_mainWin->SetImageList( imageList, which ); |
e1e955e1 | 5406 | } |
c801d85f | 5407 | |
8a3e173a | 5408 | void wxGenericListCtrl::AssignImageList(wxImageList *imageList, int which) |
2e12c11a VS |
5409 | { |
5410 | SetImageList(imageList, which); | |
5411 | if ( which == wxIMAGE_LIST_NORMAL ) | |
ca65c044 | 5412 | m_ownsImageListNormal = true; |
2e12c11a | 5413 | else if ( which == wxIMAGE_LIST_SMALL ) |
ca65c044 | 5414 | m_ownsImageListSmall = true; |
2e12c11a | 5415 | else if ( which == wxIMAGE_LIST_STATE ) |
ca65c044 | 5416 | m_ownsImageListState = true; |
2e12c11a VS |
5417 | } |
5418 | ||
3cd94a0d | 5419 | bool wxGenericListCtrl::Arrange( int WXUNUSED(flag) ) |
c801d85f | 5420 | { |
5b077d48 | 5421 | return 0; |
e1e955e1 | 5422 | } |
c801d85f | 5423 | |
3cd94a0d | 5424 | bool wxGenericListCtrl::DeleteItem( long item ) |
c801d85f | 5425 | { |
5b077d48 | 5426 | m_mainWin->DeleteItem( item ); |
ca65c044 | 5427 | return true; |
e1e955e1 | 5428 | } |
c801d85f | 5429 | |
3cd94a0d | 5430 | bool wxGenericListCtrl::DeleteAllItems() |
c801d85f | 5431 | { |
5b077d48 | 5432 | m_mainWin->DeleteAllItems(); |
ca65c044 | 5433 | return true; |
e1e955e1 | 5434 | } |
c801d85f | 5435 | |
3cd94a0d | 5436 | bool wxGenericListCtrl::DeleteAllColumns() |
bd8289c1 | 5437 | { |
24b9f055 VZ |
5438 | size_t count = m_mainWin->m_columns.GetCount(); |
5439 | for ( size_t n = 0; n < count; n++ ) | |
277ea1b4 | 5440 | DeleteColumn( 0 ); |
ca65c044 | 5441 | return true; |
4f22cf8d RR |
5442 | } |
5443 | ||
3cd94a0d | 5444 | void wxGenericListCtrl::ClearAll() |
4f22cf8d | 5445 | { |
5b077d48 | 5446 | m_mainWin->DeleteEverything(); |
bd8289c1 VZ |
5447 | } |
5448 | ||
3cd94a0d | 5449 | bool wxGenericListCtrl::DeleteColumn( int col ) |
c801d85f | 5450 | { |
5b077d48 | 5451 | m_mainWin->DeleteColumn( col ); |
40c08808 VZ |
5452 | |
5453 | // if we don't have the header any longer, we need to relayout the window | |
5454 | if ( !GetColumnCount() ) | |
ca65c044 | 5455 | ResizeReportView(false /* no header */); |
ca65c044 | 5456 | return true; |
e1e955e1 | 5457 | } |
c801d85f | 5458 | |
26e8da41 VZ |
5459 | wxTextCtrl *wxGenericListCtrl::EditLabel(long item, |
5460 | wxClassInfo* textControlClass) | |
5461 | { | |
5462 | return m_mainWin->EditLabel( item, textControlClass ); | |
5463 | } | |
5464 | ||
5465 | wxTextCtrl *wxGenericListCtrl::GetEditControl() const | |
c801d85f | 5466 | { |
26e8da41 | 5467 | return m_mainWin->GetEditControl(); |
e1e955e1 | 5468 | } |
c801d85f | 5469 | |
3cd94a0d | 5470 | bool wxGenericListCtrl::EnsureVisible( long item ) |
c801d85f | 5471 | { |
5b077d48 | 5472 | m_mainWin->EnsureVisible( item ); |
ca65c044 | 5473 | return true; |
e1e955e1 | 5474 | } |
c801d85f | 5475 | |
277ea1b4 | 5476 | long wxGenericListCtrl::FindItem( long start, const wxString& str, bool partial ) |
c801d85f | 5477 | { |
5b077d48 | 5478 | return m_mainWin->FindItem( start, str, partial ); |
e1e955e1 | 5479 | } |
c801d85f | 5480 | |
81ce36aa | 5481 | long wxGenericListCtrl::FindItem( long start, wxUIntPtr data ) |
c801d85f | 5482 | { |
5b077d48 | 5483 | return m_mainWin->FindItem( start, data ); |
e1e955e1 | 5484 | } |
c801d85f | 5485 | |
8158e0e1 | 5486 | long wxGenericListCtrl::FindItem( long WXUNUSED(start), const wxPoint& pt, |
debe6624 | 5487 | int WXUNUSED(direction)) |
c801d85f | 5488 | { |
8158e0e1 | 5489 | return m_mainWin->FindItem( pt ); |
e1e955e1 | 5490 | } |
c801d85f | 5491 | |
164a7972 | 5492 | // TODO: sub item hit testing |
be0e5d69 | 5493 | long wxGenericListCtrl::HitTest(const wxPoint& point, int& flags, long *) const |
c801d85f | 5494 | { |
5b077d48 | 5495 | return m_mainWin->HitTest( (int)point.x, (int)point.y, flags ); |
e1e955e1 | 5496 | } |
c801d85f | 5497 | |
3cd94a0d | 5498 | long wxGenericListCtrl::InsertItem( wxListItem& info ) |
c801d85f | 5499 | { |
5b077d48 | 5500 | m_mainWin->InsertItem( info ); |
2ebcd5f5 | 5501 | return info.m_itemId; |
e1e955e1 | 5502 | } |
c801d85f | 5503 | |
3cd94a0d | 5504 | long wxGenericListCtrl::InsertItem( long index, const wxString &label ) |
c801d85f | 5505 | { |
51cc4dad RR |
5506 | wxListItem info; |
5507 | info.m_text = label; | |
5508 | info.m_mask = wxLIST_MASK_TEXT; | |
5509 | info.m_itemId = index; | |
5510 | return InsertItem( info ); | |
e1e955e1 | 5511 | } |
c801d85f | 5512 | |
3cd94a0d | 5513 | long wxGenericListCtrl::InsertItem( long index, int imageIndex ) |
c801d85f | 5514 | { |
51cc4dad RR |
5515 | wxListItem info; |
5516 | info.m_mask = wxLIST_MASK_IMAGE; | |
5517 | info.m_image = imageIndex; | |
5518 | info.m_itemId = index; | |
5519 | return InsertItem( info ); | |
e1e955e1 | 5520 | } |
c801d85f | 5521 | |
3cd94a0d | 5522 | long wxGenericListCtrl::InsertItem( long index, const wxString &label, int imageIndex ) |
c801d85f | 5523 | { |
51cc4dad RR |
5524 | wxListItem info; |
5525 | info.m_text = label; | |
5526 | info.m_image = imageIndex; | |
5527 | info.m_mask = wxLIST_MASK_TEXT | wxLIST_MASK_IMAGE; | |
5528 | info.m_itemId = index; | |
5529 | return InsertItem( info ); | |
e1e955e1 | 5530 | } |
c801d85f | 5531 | |
3cd94a0d | 5532 | long wxGenericListCtrl::InsertColumn( long col, wxListItem &item ) |
c801d85f | 5533 | { |
40c08808 VZ |
5534 | wxCHECK_MSG( m_headerWin, -1, _T("can't add column in non report mode") ); |
5535 | ||
51cc4dad | 5536 | m_mainWin->InsertColumn( col, item ); |
40c08808 | 5537 | |
277ea1b4 DS |
5538 | // if we hadn't had a header before but have one now |
5539 | // then we need to relayout the window | |
ac53090c | 5540 | if ( GetColumnCount() == 1 && m_mainWin->HasHeader() ) |
ca65c044 | 5541 | ResizeReportView(true /* have header */); |
40c08808 | 5542 | |
d3e90957 | 5543 | m_headerWin->Refresh(); |
25e3a937 | 5544 | |
51cc4dad | 5545 | return 0; |
e1e955e1 | 5546 | } |
c801d85f | 5547 | |
3cd94a0d | 5548 | long wxGenericListCtrl::InsertColumn( long col, const wxString &heading, |
debe6624 | 5549 | int format, int width ) |
c801d85f | 5550 | { |
51cc4dad RR |
5551 | wxListItem item; |
5552 | item.m_mask = wxLIST_MASK_TEXT | wxLIST_MASK_FORMAT; | |
5553 | item.m_text = heading; | |
5554 | if (width >= -2) | |
5555 | { | |
5556 | item.m_mask |= wxLIST_MASK_WIDTH; | |
5557 | item.m_width = width; | |
5558 | } | |
277ea1b4 | 5559 | |
51cc4dad | 5560 | item.m_format = format; |
c801d85f | 5561 | |
51cc4dad | 5562 | return InsertColumn( col, item ); |
e1e955e1 | 5563 | } |
c801d85f | 5564 | |
3cd94a0d | 5565 | bool wxGenericListCtrl::ScrollList( int WXUNUSED(dx), int WXUNUSED(dy) ) |
c801d85f | 5566 | { |
51cc4dad | 5567 | return 0; |
e1e955e1 | 5568 | } |
c801d85f KB |
5569 | |
5570 | // Sort items. | |
5571 | // fn is a function which takes 3 long arguments: item1, item2, data. | |
5572 | // item1 is the long data associated with a first item (NOT the index). | |
5573 | // item2 is the long data associated with a second item (NOT the index). | |
5574 | // data is the same value as passed to SortItems. | |
5575 | // The return value is a negative number if the first item should precede the second | |
5576 | // item, a positive number of the second item should precede the first, | |
5577 | // or zero if the two items are equivalent. | |
5578 | // data is arbitrary data to be passed to the sort function. | |
5579 | ||
3cd94a0d | 5580 | bool wxGenericListCtrl::SortItems( wxListCtrlCompare fn, long data ) |
c801d85f | 5581 | { |
51cc4dad | 5582 | m_mainWin->SortItems( fn, data ); |
ca65c044 | 5583 | return true; |
e1e955e1 | 5584 | } |
c801d85f | 5585 | |
cf1dfa6b | 5586 | // ---------------------------------------------------------------------------- |
b54e41c5 | 5587 | // event handlers |
cf1dfa6b VZ |
5588 | // ---------------------------------------------------------------------------- |
5589 | ||
3cd94a0d | 5590 | void wxGenericListCtrl::OnSize(wxSizeEvent& WXUNUSED(event)) |
53010e52 | 5591 | { |
b54e41c5 | 5592 | if ( !m_mainWin ) |
cf1dfa6b | 5593 | return; |
53010e52 | 5594 | |
a95cdab8 | 5595 | ResizeReportView(m_mainWin->HasHeader()); |
a95cdab8 VZ |
5596 | m_mainWin->RecalculatePositions(); |
5597 | } | |
5598 | ||
3cd94a0d | 5599 | void wxGenericListCtrl::ResizeReportView(bool showHeader) |
a95cdab8 | 5600 | { |
b54e41c5 | 5601 | int cw, ch; |
51cc4dad | 5602 | GetClientSize( &cw, &ch ); |
bd8289c1 | 5603 | |
a95cdab8 | 5604 | if ( showHeader ) |
51cc4dad | 5605 | { |
f8252483 | 5606 | m_headerWin->SetSize( 0, 0, cw, m_headerHeight ); |
2ae226dd | 5607 | if(ch > m_headerHeight) |
faa94f3e | 5608 | m_mainWin->SetSize( 0, m_headerHeight + 1, |
2ae226dd JS |
5609 | cw, ch - m_headerHeight - 1 ); |
5610 | else | |
faa94f3e | 5611 | m_mainWin->SetSize( 0, m_headerHeight + 1, |
2ae226dd | 5612 | cw, 0); |
51cc4dad | 5613 | } |
cf1dfa6b | 5614 | else // no header window |
51cc4dad | 5615 | { |
cf1dfa6b | 5616 | m_mainWin->SetSize( 0, 0, cw, ch ); |
51cc4dad | 5617 | } |
b54e41c5 | 5618 | } |
cf1dfa6b | 5619 | |
5180055b | 5620 | void wxGenericListCtrl::OnInternalIdle() |
b54e41c5 | 5621 | { |
5180055b | 5622 | wxWindow::OnInternalIdle(); |
86351e4a | 5623 | |
b54e41c5 VZ |
5624 | // do it only if needed |
5625 | if ( !m_mainWin->m_dirty ) | |
5626 | return; | |
5627 | ||
5628 | m_mainWin->RecalculatePositions(); | |
e1e955e1 | 5629 | } |
53010e52 | 5630 | |
cf1dfa6b VZ |
5631 | // ---------------------------------------------------------------------------- |
5632 | // font/colours | |
5633 | // ---------------------------------------------------------------------------- | |
5634 | ||
3cd94a0d | 5635 | bool wxGenericListCtrl::SetBackgroundColour( const wxColour &colour ) |
bd8289c1 | 5636 | { |
51cc4dad RR |
5637 | if (m_mainWin) |
5638 | { | |
5639 | m_mainWin->SetBackgroundColour( colour ); | |
ca65c044 | 5640 | m_mainWin->m_dirty = true; |
51cc4dad | 5641 | } |
004fd0c8 | 5642 | |
ca65c044 | 5643 | return true; |
e4d06860 RR |
5644 | } |
5645 | ||
3cd94a0d | 5646 | bool wxGenericListCtrl::SetForegroundColour( const wxColour &colour ) |
bd8289c1 | 5647 | { |
f03fc89f | 5648 | if ( !wxWindow::SetForegroundColour( colour ) ) |
ca65c044 | 5649 | return false; |
004fd0c8 | 5650 | |
51cc4dad RR |
5651 | if (m_mainWin) |
5652 | { | |
5653 | m_mainWin->SetForegroundColour( colour ); | |
ca65c044 | 5654 | m_mainWin->m_dirty = true; |
51cc4dad | 5655 | } |
004fd0c8 | 5656 | |
51cc4dad | 5657 | if (m_headerWin) |
51cc4dad | 5658 | m_headerWin->SetForegroundColour( colour ); |
f03fc89f | 5659 | |
ca65c044 | 5660 | return true; |
e4d06860 | 5661 | } |
bd8289c1 | 5662 | |
3cd94a0d | 5663 | bool wxGenericListCtrl::SetFont( const wxFont &font ) |
bd8289c1 | 5664 | { |
f03fc89f | 5665 | if ( !wxWindow::SetFont( font ) ) |
ca65c044 | 5666 | return false; |
004fd0c8 | 5667 | |
51cc4dad RR |
5668 | if (m_mainWin) |
5669 | { | |
5670 | m_mainWin->SetFont( font ); | |
ca65c044 | 5671 | m_mainWin->m_dirty = true; |
51cc4dad | 5672 | } |
004fd0c8 | 5673 | |
51cc4dad RR |
5674 | if (m_headerWin) |
5675 | { | |
5676 | m_headerWin->SetFont( font ); | |
f8252483 | 5677 | CalculateAndSetHeaderHeight(); |
51cc4dad | 5678 | } |
f03fc89f | 5679 | |
f8252483 JS |
5680 | Refresh(); |
5681 | ||
ca65c044 | 5682 | return true; |
e4d06860 | 5683 | } |
c801d85f | 5684 | |
277ea1b4 | 5685 | // static |
35d4c967 RD |
5686 | wxVisualAttributes |
5687 | wxGenericListCtrl::GetClassDefaultAttributes(wxWindowVariant variant) | |
5688 | { | |
5689 | #if _USE_VISATTR | |
5690 | // Use the same color scheme as wxListBox | |
5691 | return wxListBox::GetClassDefaultAttributes(variant); | |
5692 | #else | |
e7045784 | 5693 | wxUnusedVar(variant); |
35d4c967 RD |
5694 | wxVisualAttributes attr; |
5695 | attr.colFg = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT); | |
5696 | attr.colBg = wxSystemSettings::GetColour(wxSYS_COLOUR_LISTBOX); | |
5697 | attr.font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT); | |
5698 | return attr; | |
5699 | #endif | |
5700 | } | |
5701 | ||
cf1dfa6b VZ |
5702 | // ---------------------------------------------------------------------------- |
5703 | // methods forwarded to m_mainWin | |
5704 | // ---------------------------------------------------------------------------- | |
5705 | ||
efbb7287 VZ |
5706 | #if wxUSE_DRAG_AND_DROP |
5707 | ||
3cd94a0d | 5708 | void wxGenericListCtrl::SetDropTarget( wxDropTarget *dropTarget ) |
efbb7287 VZ |
5709 | { |
5710 | m_mainWin->SetDropTarget( dropTarget ); | |
5711 | } | |
5712 | ||
3cd94a0d | 5713 | wxDropTarget *wxGenericListCtrl::GetDropTarget() const |
efbb7287 VZ |
5714 | { |
5715 | return m_mainWin->GetDropTarget(); | |
5716 | } | |
5717 | ||
277ea1b4 | 5718 | #endif |
efbb7287 | 5719 | |
3cd94a0d | 5720 | bool wxGenericListCtrl::SetCursor( const wxCursor &cursor ) |
efbb7287 | 5721 | { |
ca65c044 | 5722 | return m_mainWin ? m_mainWin->wxWindow::SetCursor(cursor) : false; |
efbb7287 VZ |
5723 | } |
5724 | ||
3cd94a0d | 5725 | wxColour wxGenericListCtrl::GetBackgroundColour() const |
efbb7287 VZ |
5726 | { |
5727 | return m_mainWin ? m_mainWin->GetBackgroundColour() : wxColour(); | |
5728 | } | |
5729 | ||
3cd94a0d | 5730 | wxColour wxGenericListCtrl::GetForegroundColour() const |
efbb7287 VZ |
5731 | { |
5732 | return m_mainWin ? m_mainWin->GetForegroundColour() : wxColour(); | |
5733 | } | |
5734 | ||
3cd94a0d | 5735 | bool wxGenericListCtrl::DoPopupMenu( wxMenu *menu, int x, int y ) |
efbb7287 | 5736 | { |
3a8c693a | 5737 | #if wxUSE_MENUS |
efbb7287 | 5738 | return m_mainWin->PopupMenu( menu, x, y ); |
3a8c693a | 5739 | #else |
ca65c044 | 5740 | return false; |
277ea1b4 | 5741 | #endif |
efbb7287 VZ |
5742 | } |
5743 | ||
7447bdd7 VZ |
5744 | void wxGenericListCtrl::DoClientToScreen( int *x, int *y ) const |
5745 | { | |
5d584acb | 5746 | m_mainWin->DoClientToScreen(x, y); |
7447bdd7 VZ |
5747 | } |
5748 | ||
5749 | void wxGenericListCtrl::DoScreenToClient( int *x, int *y ) const | |
5750 | { | |
5d584acb | 5751 | m_mainWin->DoScreenToClient(x, y); |
7447bdd7 VZ |
5752 | } |
5753 | ||
3cd94a0d | 5754 | void wxGenericListCtrl::SetFocus() |
efbb7287 | 5755 | { |
277ea1b4 DS |
5756 | // The test in window.cpp fails as we are a composite |
5757 | // window, so it checks against "this", but not m_mainWin. | |
66370e38 | 5758 | if ( DoFindFocus() != this ) |
efbb7287 VZ |
5759 | m_mainWin->SetFocus(); |
5760 | } | |
1e6feb95 | 5761 | |
3872d96d RD |
5762 | wxSize wxGenericListCtrl::DoGetBestSize() const |
5763 | { | |
5764 | // Something is better than nothing... | |
5765 | // 100x80 is what the MSW version will get from the default | |
5766 | // wxControl::DoGetBestSize | |
277ea1b4 | 5767 | return wxSize(100, 80); |
3872d96d RD |
5768 | } |
5769 | ||
2c1f73ee VZ |
5770 | // ---------------------------------------------------------------------------- |
5771 | // virtual list control support | |
5772 | // ---------------------------------------------------------------------------- | |
5773 | ||
3cd94a0d | 5774 | wxString wxGenericListCtrl::OnGetItemText(long WXUNUSED(item), long WXUNUSED(col)) const |
2c1f73ee VZ |
5775 | { |
5776 | // this is a pure virtual function, in fact - which is not really pure | |
5777 | // because the controls which are not virtual don't need to implement it | |
3cd94a0d | 5778 | wxFAIL_MSG( _T("wxGenericListCtrl::OnGetItemText not supposed to be called") ); |
2c1f73ee VZ |
5779 | |
5780 | return wxEmptyString; | |
5781 | } | |
5782 | ||
3cd94a0d | 5783 | int wxGenericListCtrl::OnGetItemImage(long WXUNUSED(item)) const |
2c1f73ee | 5784 | { |
611a725e RD |
5785 | wxCHECK_MSG(!GetImageList(wxIMAGE_LIST_SMALL), |
5786 | -1, | |
208458a7 | 5787 | wxT("List control has an image list, OnGetItemImage or OnGetItemColumnImage should be overridden.")); |
2c1f73ee VZ |
5788 | return -1; |
5789 | } | |
5790 | ||
208458a7 RD |
5791 | int wxGenericListCtrl::OnGetItemColumnImage(long item, long column) const |
5792 | { | |
5793 | if (!column) | |
5794 | return OnGetItemImage(item); | |
5795 | ||
5796 | return -1; | |
08a175ce | 5797 | } |
208458a7 | 5798 | |
999836aa VZ |
5799 | wxListItemAttr * |
5800 | wxGenericListCtrl::OnGetItemAttr(long WXUNUSED_UNLESS_DEBUG(item)) const | |
6c02c329 VZ |
5801 | { |
5802 | wxASSERT_MSG( item >= 0 && item < GetItemCount(), | |
5803 | _T("invalid item index in OnGetItemAttr()") ); | |
5804 | ||
5805 | // no attributes by default | |
5806 | return NULL; | |
5807 | } | |
5808 | ||
3cd94a0d | 5809 | void wxGenericListCtrl::SetItemCount(long count) |
2c1f73ee VZ |
5810 | { |
5811 | wxASSERT_MSG( IsVirtual(), _T("this is for virtual controls only") ); | |
5812 | ||
5813 | m_mainWin->SetItemCount(count); | |
5814 | } | |
5815 | ||
3cd94a0d | 5816 | void wxGenericListCtrl::RefreshItem(long item) |
1a6cb56f VZ |
5817 | { |
5818 | m_mainWin->RefreshLine(item); | |
5819 | } | |
5820 | ||
3cd94a0d | 5821 | void wxGenericListCtrl::RefreshItems(long itemFrom, long itemTo) |
1a6cb56f VZ |
5822 | { |
5823 | m_mainWin->RefreshLines(itemFrom, itemTo); | |
5824 | } | |
5825 | ||
277ea1b4 DS |
5826 | // Generic wxListCtrl is more or less a container for two other |
5827 | // windows which drawings are done upon. These are namely | |
5828 | // 'm_headerWin' and 'm_mainWin'. | |
5829 | // Here we override 'virtual wxWindow::Refresh()' to mimic the | |
5830 | // behaviour wxListCtrl has under wxMSW. | |
5831 | // | |
2f1e3c46 VZ |
5832 | void wxGenericListCtrl::Refresh(bool eraseBackground, const wxRect *rect) |
5833 | { | |
5834 | if (!rect) | |
5835 | { | |
5836 | // The easy case, no rectangle specified. | |
5837 | if (m_headerWin) | |
5838 | m_headerWin->Refresh(eraseBackground); | |
5839 | ||
5840 | if (m_mainWin) | |
5841 | m_mainWin->Refresh(eraseBackground); | |
5842 | } | |
5843 | else | |
5844 | { | |
5845 | // Refresh the header window | |
5846 | if (m_headerWin) | |
5847 | { | |
5848 | wxRect rectHeader = m_headerWin->GetRect(); | |
5849 | rectHeader.Intersect(*rect); | |
5850 | if (rectHeader.GetWidth() && rectHeader.GetHeight()) | |
5851 | { | |
5852 | int x, y; | |
5853 | m_headerWin->GetPosition(&x, &y); | |
5854 | rectHeader.Offset(-x, -y); | |
5855 | m_headerWin->Refresh(eraseBackground, &rectHeader); | |
5856 | } | |
2f1e3c46 VZ |
5857 | } |
5858 | ||
5859 | // Refresh the main window | |
5860 | if (m_mainWin) | |
5861 | { | |
5862 | wxRect rectMain = m_mainWin->GetRect(); | |
5863 | rectMain.Intersect(*rect); | |
5864 | if (rectMain.GetWidth() && rectMain.GetHeight()) | |
5865 | { | |
5866 | int x, y; | |
5867 | m_mainWin->GetPosition(&x, &y); | |
5868 | rectMain.Offset(-x, -y); | |
5869 | m_mainWin->Refresh(eraseBackground, &rectMain); | |
5870 | } | |
5871 | } | |
5872 | } | |
5873 | } | |
5874 | ||
3cd94a0d | 5875 | void wxGenericListCtrl::Freeze() |
c5c528fc VZ |
5876 | { |
5877 | m_mainWin->Freeze(); | |
5878 | } | |
5879 | ||
3cd94a0d | 5880 | void wxGenericListCtrl::Thaw() |
c5c528fc VZ |
5881 | { |
5882 | m_mainWin->Thaw(); | |
5883 | } | |
5884 | ||
1e6feb95 | 5885 | #endif // wxUSE_LISTCTRL |