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