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