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