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