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