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