]>
Commit | Line | Data |
---|---|---|
ad486020 FM |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: listctrl.h | |
3 | // Purpose: private definitions of wxListCtrl helpers | |
4 | // Author: Robert Roebling | |
5 | // Vadim Zeitlin (virtual list control support) | |
6 | // Id: $Id$ | |
7 | // Copyright: (c) 1998 Robert Roebling | |
8 | // Licence: wxWindows licence | |
9 | ///////////////////////////////////////////////////////////////////////////// | |
10 | ||
11 | #ifndef _WX_GENERIC_LISTCTRL_PRIVATE_H_ | |
12 | #define _WX_GENERIC_LISTCTRL_PRIVATE_H_ | |
13 | ||
14 | #include "wx/defs.h" | |
15 | ||
16 | #if wxUSE_LISTCTRL | |
17 | ||
18 | #include "wx/listctrl.h" | |
19 | #include "wx/selstore.h" | |
4d833b7b VZ |
20 | #include "wx/timer.h" |
21 | #include "wx/settings.h" | |
ad486020 FM |
22 | |
23 | // ============================================================================ | |
24 | // private classes | |
25 | // ============================================================================ | |
26 | ||
27 | //----------------------------------------------------------------------------- | |
28 | // wxColWidthInfo (internal) | |
29 | //----------------------------------------------------------------------------- | |
30 | ||
31 | struct wxColWidthInfo | |
32 | { | |
33 | int nMaxWidth; | |
34 | bool bNeedsUpdate; // only set to true when an item whose | |
35 | // width == nMaxWidth is removed | |
36 | ||
37 | wxColWidthInfo(int w = 0, bool needsUpdate = false) | |
38 | { | |
39 | nMaxWidth = w; | |
40 | bNeedsUpdate = needsUpdate; | |
41 | } | |
42 | }; | |
43 | ||
44 | WX_DEFINE_ARRAY_PTR(wxColWidthInfo *, ColWidthArray); | |
45 | ||
46 | //----------------------------------------------------------------------------- | |
47 | // wxListItemData (internal) | |
48 | //----------------------------------------------------------------------------- | |
49 | ||
50 | class wxListItemData | |
51 | { | |
52 | public: | |
53 | wxListItemData(wxListMainWindow *owner); | |
54 | ~wxListItemData(); | |
55 | ||
56 | void SetItem( const wxListItem &info ); | |
57 | void SetImage( int image ) { m_image = image; } | |
58 | void SetData( wxUIntPtr data ) { m_data = data; } | |
59 | void SetPosition( int x, int y ); | |
60 | void SetSize( int width, int height ); | |
61 | ||
62 | bool HasText() const { return !m_text.empty(); } | |
63 | const wxString& GetText() const { return m_text; } | |
64 | void SetText(const wxString& text) { m_text = text; } | |
65 | ||
66 | // we can't use empty string for measuring the string width/height, so | |
67 | // always return something | |
68 | wxString GetTextForMeasuring() const | |
69 | { | |
70 | wxString s = GetText(); | |
71 | if ( s.empty() ) | |
9a83f860 | 72 | s = wxT('H'); |
ad486020 FM |
73 | |
74 | return s; | |
75 | } | |
76 | ||
77 | bool IsHit( int x, int y ) const; | |
78 | ||
79 | int GetX() const; | |
80 | int GetY() const; | |
81 | int GetWidth() const; | |
82 | int GetHeight() const; | |
83 | ||
84 | int GetImage() const { return m_image; } | |
85 | bool HasImage() const { return GetImage() != -1; } | |
86 | ||
87 | void GetItem( wxListItem &info ) const; | |
88 | ||
89 | void SetAttr(wxListItemAttr *attr) { m_attr = attr; } | |
90 | wxListItemAttr *GetAttr() const { return m_attr; } | |
91 | ||
92 | public: | |
93 | // the item image or -1 | |
94 | int m_image; | |
95 | ||
96 | // user data associated with the item | |
97 | wxUIntPtr m_data; | |
98 | ||
99 | // the item coordinates are not used in report mode; instead this pointer is | |
100 | // NULL and the owner window is used to retrieve the item position and size | |
101 | wxRect *m_rect; | |
102 | ||
103 | // the list ctrl we are in | |
104 | wxListMainWindow *m_owner; | |
105 | ||
106 | // custom attributes or NULL | |
107 | wxListItemAttr *m_attr; | |
108 | ||
109 | protected: | |
110 | // common part of all ctors | |
111 | void Init(); | |
112 | ||
113 | wxString m_text; | |
114 | }; | |
115 | ||
116 | //----------------------------------------------------------------------------- | |
117 | // wxListHeaderData (internal) | |
118 | //----------------------------------------------------------------------------- | |
119 | ||
120 | class wxListHeaderData : public wxObject | |
121 | { | |
122 | public: | |
123 | wxListHeaderData(); | |
124 | wxListHeaderData( const wxListItem &info ); | |
125 | void SetItem( const wxListItem &item ); | |
126 | void SetPosition( int x, int y ); | |
127 | void SetWidth( int w ); | |
128 | void SetState( int state ); | |
129 | void SetFormat( int format ); | |
130 | void SetHeight( int h ); | |
131 | bool HasImage() const; | |
132 | ||
133 | bool HasText() const { return !m_text.empty(); } | |
134 | const wxString& GetText() const { return m_text; } | |
135 | void SetText(const wxString& text) { m_text = text; } | |
136 | ||
137 | void GetItem( wxListItem &item ); | |
138 | ||
139 | bool IsHit( int x, int y ) const; | |
140 | int GetImage() const; | |
141 | int GetWidth() const; | |
142 | int GetFormat() const; | |
143 | int GetState() const; | |
144 | ||
145 | protected: | |
146 | long m_mask; | |
147 | int m_image; | |
148 | wxString m_text; | |
149 | int m_format; | |
150 | int m_width; | |
151 | int m_xpos, | |
152 | m_ypos; | |
153 | int m_height; | |
154 | int m_state; | |
155 | ||
156 | private: | |
157 | void Init(); | |
158 | }; | |
159 | ||
160 | //----------------------------------------------------------------------------- | |
161 | // wxListLineData (internal) | |
162 | //----------------------------------------------------------------------------- | |
163 | ||
164 | WX_DECLARE_LIST(wxListItemData, wxListItemDataList); | |
165 | ||
166 | class wxListLineData | |
167 | { | |
168 | public: | |
169 | // the list of subitems: only may have more than one item in report mode | |
170 | wxListItemDataList m_items; | |
171 | ||
172 | // this is not used in report view | |
173 | struct GeometryInfo | |
174 | { | |
175 | // total item rect | |
176 | wxRect m_rectAll; | |
177 | ||
178 | // label only | |
179 | wxRect m_rectLabel; | |
180 | ||
181 | // icon only | |
182 | wxRect m_rectIcon; | |
183 | ||
184 | // the part to be highlighted | |
185 | wxRect m_rectHighlight; | |
186 | ||
187 | // extend all our rects to be centered inside the one of given width | |
188 | void ExtendWidth(wxCoord w) | |
189 | { | |
190 | wxASSERT_MSG( m_rectAll.width <= w, | |
9a83f860 | 191 | wxT("width can only be increased") ); |
ad486020 FM |
192 | |
193 | m_rectAll.width = w; | |
194 | m_rectLabel.x = m_rectAll.x + (w - m_rectLabel.width) / 2; | |
195 | m_rectIcon.x = m_rectAll.x + (w - m_rectIcon.width) / 2; | |
196 | m_rectHighlight.x = m_rectAll.x + (w - m_rectHighlight.width) / 2; | |
197 | } | |
198 | } | |
199 | *m_gi; | |
200 | ||
201 | // is this item selected? [NB: not used in virtual mode] | |
202 | bool m_highlighted; | |
203 | ||
204 | // back pointer to the list ctrl | |
205 | wxListMainWindow *m_owner; | |
206 | ||
207 | public: | |
208 | wxListLineData(wxListMainWindow *owner); | |
209 | ||
210 | ~wxListLineData() | |
211 | { | |
212 | WX_CLEAR_LIST(wxListItemDataList, m_items); | |
213 | delete m_gi; | |
214 | } | |
215 | ||
476de5ea VZ |
216 | // called by the owner when it toggles report view |
217 | void SetReportView(bool inReportView) | |
218 | { | |
219 | // we only need m_gi when we're not in report view so update as needed | |
220 | if ( inReportView ) | |
221 | { | |
222 | delete m_gi; | |
223 | m_gi = NULL; | |
224 | } | |
225 | else | |
226 | { | |
227 | m_gi = new GeometryInfo; | |
228 | } | |
229 | } | |
230 | ||
ad486020 FM |
231 | // are we in report mode? |
232 | inline bool InReportView() const; | |
233 | ||
234 | // are we in virtual report mode? | |
235 | inline bool IsVirtual() const; | |
236 | ||
237 | // these 2 methods shouldn't be called for report view controls, in that | |
238 | // case we determine our position/size ourselves | |
239 | ||
240 | // calculate the size of the line | |
241 | void CalculateSize( wxDC *dc, int spacing ); | |
242 | ||
243 | // remember the position this line appears at | |
244 | void SetPosition( int x, int y, int spacing ); | |
245 | ||
246 | // wxListCtrl API | |
247 | ||
248 | void SetImage( int image ) { SetImage(0, image); } | |
249 | int GetImage() const { return GetImage(0); } | |
250 | void SetImage( int index, int image ); | |
251 | int GetImage( int index ) const; | |
252 | ||
253 | bool HasImage() const { return GetImage() != -1; } | |
254 | bool HasText() const { return !GetText(0).empty(); } | |
255 | ||
256 | void SetItem( int index, const wxListItem &info ); | |
257 | void GetItem( int index, wxListItem &info ); | |
258 | ||
259 | wxString GetText(int index) const; | |
260 | void SetText( int index, const wxString& s ); | |
261 | ||
262 | wxListItemAttr *GetAttr() const; | |
263 | void SetAttr(wxListItemAttr *attr); | |
264 | ||
265 | // return true if the highlighting really changed | |
266 | bool Highlight( bool on ); | |
267 | ||
268 | void ReverseHighlight(); | |
269 | ||
270 | bool IsHighlighted() const | |
271 | { | |
9a83f860 | 272 | wxASSERT_MSG( !IsVirtual(), wxT("unexpected call to IsHighlighted") ); |
ad486020 FM |
273 | |
274 | return m_highlighted; | |
275 | } | |
276 | ||
277 | // draw the line on the given DC in icon/list mode | |
278 | void Draw( wxDC *dc ); | |
279 | ||
280 | // the same in report mode | |
281 | void DrawInReportMode( wxDC *dc, | |
282 | const wxRect& rect, | |
283 | const wxRect& rectHL, | |
284 | bool highlighted, | |
285 | bool current ); | |
286 | ||
287 | private: | |
288 | // set the line to contain num items (only can be > 1 in report mode) | |
289 | void InitItems( int num ); | |
290 | ||
291 | // get the mode (i.e. style) of the list control | |
292 | inline int GetMode() const; | |
293 | ||
294 | // prepare the DC for drawing with these item's attributes, return true if | |
295 | // we need to draw the items background to highlight it, false otherwise | |
296 | bool SetAttributes(wxDC *dc, | |
297 | const wxListItemAttr *attr, | |
298 | bool highlight); | |
299 | ||
300 | // draw the text on the DC with the correct justification; also add an | |
301 | // ellipsis if the text is too large to fit in the current width | |
302 | void DrawTextFormatted(wxDC *dc, | |
303 | const wxString &text, | |
304 | int col, | |
305 | int x, | |
306 | int yMid, // this is middle, not top, of the text | |
307 | int width); | |
308 | }; | |
309 | ||
310 | WX_DECLARE_OBJARRAY(wxListLineData, wxListLineDataArray); | |
311 | ||
312 | //----------------------------------------------------------------------------- | |
313 | // wxListHeaderWindow (internal) | |
314 | //----------------------------------------------------------------------------- | |
315 | ||
316 | class wxListHeaderWindow : public wxWindow | |
317 | { | |
318 | protected: | |
319 | wxListMainWindow *m_owner; | |
320 | const wxCursor *m_currentCursor; | |
321 | wxCursor *m_resizeCursor; | |
322 | bool m_isDragging; | |
323 | ||
324 | // column being resized or -1 | |
325 | int m_column; | |
326 | ||
327 | // divider line position in logical (unscrolled) coords | |
328 | int m_currentX; | |
329 | ||
330 | // minimal position beyond which the divider line | |
331 | // can't be dragged in logical coords | |
332 | int m_minX; | |
333 | ||
334 | public: | |
335 | wxListHeaderWindow(); | |
336 | ||
337 | wxListHeaderWindow( wxWindow *win, | |
338 | wxWindowID id, | |
339 | wxListMainWindow *owner, | |
340 | const wxPoint &pos = wxDefaultPosition, | |
341 | const wxSize &size = wxDefaultSize, | |
342 | long style = 0, | |
343 | const wxString &name = wxT("wxlistctrlcolumntitles") ); | |
344 | ||
345 | virtual ~wxListHeaderWindow(); | |
346 | ||
347 | void DrawCurrent(); | |
348 | void AdjustDC( wxDC& dc ); | |
349 | ||
350 | void OnPaint( wxPaintEvent &event ); | |
351 | void OnMouse( wxMouseEvent &event ); | |
352 | void OnSetFocus( wxFocusEvent &event ); | |
353 | ||
354 | // needs refresh | |
355 | bool m_dirty; | |
356 | ||
357 | // Update main window's column later | |
358 | bool m_sendSetColumnWidth; | |
359 | int m_colToSend; | |
360 | int m_widthToSend; | |
361 | ||
362 | virtual void OnInternalIdle(); | |
363 | ||
364 | private: | |
365 | // common part of all ctors | |
366 | void Init(); | |
367 | ||
368 | // generate and process the list event of the given type, return true if | |
369 | // it wasn't vetoed, i.e. if we should proceed | |
370 | bool SendListEvent(wxEventType type, const wxPoint& pos); | |
371 | ||
372 | DECLARE_EVENT_TABLE() | |
373 | }; | |
374 | ||
375 | //----------------------------------------------------------------------------- | |
376 | // wxListRenameTimer (internal) | |
377 | //----------------------------------------------------------------------------- | |
378 | ||
379 | class wxListRenameTimer: public wxTimer | |
380 | { | |
381 | private: | |
382 | wxListMainWindow *m_owner; | |
383 | ||
384 | public: | |
385 | wxListRenameTimer( wxListMainWindow *owner ); | |
386 | void Notify(); | |
387 | }; | |
388 | ||
389 | //----------------------------------------------------------------------------- | |
390 | // wxListTextCtrlWrapper: wraps a wxTextCtrl to make it work for inline editing | |
391 | //----------------------------------------------------------------------------- | |
392 | ||
393 | class wxListTextCtrlWrapper : public wxEvtHandler | |
394 | { | |
395 | public: | |
396 | // NB: text must be a valid object but not Create()d yet | |
397 | wxListTextCtrlWrapper(wxListMainWindow *owner, | |
398 | wxTextCtrl *text, | |
399 | size_t itemEdit); | |
400 | ||
401 | wxTextCtrl *GetText() const { return m_text; } | |
402 | ||
403 | void EndEdit( bool discardChanges ); | |
404 | ||
405 | protected: | |
406 | void OnChar( wxKeyEvent &event ); | |
407 | void OnKeyUp( wxKeyEvent &event ); | |
408 | void OnKillFocus( wxFocusEvent &event ); | |
409 | ||
410 | bool AcceptChanges(); | |
411 | void Finish( bool setfocus ); | |
412 | ||
413 | private: | |
414 | wxListMainWindow *m_owner; | |
415 | wxTextCtrl *m_text; | |
416 | wxString m_startValue; | |
417 | size_t m_itemEdited; | |
418 | bool m_aboutToFinish; | |
419 | ||
420 | DECLARE_EVENT_TABLE() | |
421 | }; | |
422 | ||
423 | //----------------------------------------------------------------------------- | |
424 | // wxListMainWindow (internal) | |
425 | //----------------------------------------------------------------------------- | |
426 | ||
427 | WX_DECLARE_LIST(wxListHeaderData, wxListHeaderDataList); | |
428 | ||
429 | class wxListMainWindow : public wxWindow | |
430 | { | |
431 | public: | |
432 | wxListMainWindow(); | |
433 | wxListMainWindow( wxWindow *parent, | |
434 | wxWindowID id, | |
435 | const wxPoint& pos = wxDefaultPosition, | |
436 | const wxSize& size = wxDefaultSize, | |
437 | long style = 0, | |
9a83f860 | 438 | const wxString &name = wxT("listctrlmainwindow") ); |
ad486020 FM |
439 | |
440 | virtual ~wxListMainWindow(); | |
441 | ||
476de5ea VZ |
442 | // called by the main control when its mode changes |
443 | void SetReportView(bool inReportView); | |
444 | ||
445 | // helper to simplify testing for wxLC_XXX flags | |
ad486020 FM |
446 | bool HasFlag(int flag) const { return m_parent->HasFlag(flag); } |
447 | ||
448 | // return true if this is a virtual list control | |
449 | bool IsVirtual() const { return HasFlag(wxLC_VIRTUAL); } | |
450 | ||
451 | // return true if the control is in report mode | |
452 | bool InReportView() const { return HasFlag(wxLC_REPORT); } | |
453 | ||
454 | // return true if we are in single selection mode, false if multi sel | |
455 | bool IsSingleSel() const { return HasFlag(wxLC_SINGLE_SEL); } | |
456 | ||
457 | // do we have a header window? | |
458 | bool HasHeader() const | |
459 | { return InReportView() && !HasFlag(wxLC_NO_HEADER); } | |
460 | ||
461 | void HighlightAll( bool on ); | |
462 | ||
463 | // all these functions only do something if the line is currently visible | |
464 | ||
465 | // change the line "selected" state, return true if it really changed | |
466 | bool HighlightLine( size_t line, bool highlight = true); | |
467 | ||
468 | // as HighlightLine() but do it for the range of lines: this is incredibly | |
469 | // more efficient for virtual list controls! | |
470 | // | |
471 | // NB: unlike HighlightLine() this one does refresh the lines on screen | |
472 | void HighlightLines( size_t lineFrom, size_t lineTo, bool on = true ); | |
473 | ||
474 | // toggle the line state and refresh it | |
475 | void ReverseHighlight( size_t line ) | |
476 | { HighlightLine(line, !IsHighlighted(line)); RefreshLine(line); } | |
477 | ||
478 | // return true if the line is highlighted | |
479 | bool IsHighlighted(size_t line) const; | |
480 | ||
481 | // refresh one or several lines at once | |
482 | void RefreshLine( size_t line ); | |
483 | void RefreshLines( size_t lineFrom, size_t lineTo ); | |
484 | ||
485 | // refresh all selected items | |
486 | void RefreshSelected(); | |
487 | ||
488 | // refresh all lines below the given one: the difference with | |
489 | // RefreshLines() is that the index here might not be a valid one (happens | |
490 | // when the last line is deleted) | |
491 | void RefreshAfter( size_t lineFrom ); | |
492 | ||
493 | // the methods which are forwarded to wxListLineData itself in list/icon | |
494 | // modes but are here because the lines don't store their positions in the | |
495 | // report mode | |
496 | ||
497 | // get the bound rect for the entire line | |
498 | wxRect GetLineRect(size_t line) const; | |
499 | ||
500 | // get the bound rect of the label | |
501 | wxRect GetLineLabelRect(size_t line) const; | |
502 | ||
503 | // get the bound rect of the items icon (only may be called if we do have | |
504 | // an icon!) | |
505 | wxRect GetLineIconRect(size_t line) const; | |
506 | ||
507 | // get the rect to be highlighted when the item has focus | |
508 | wxRect GetLineHighlightRect(size_t line) const; | |
509 | ||
510 | // get the size of the total line rect | |
511 | wxSize GetLineSize(size_t line) const | |
512 | { return GetLineRect(line).GetSize(); } | |
513 | ||
514 | // return the hit code for the corresponding position (in this line) | |
515 | long HitTestLine(size_t line, int x, int y) const; | |
516 | ||
517 | // bring the selected item into view, scrolling to it if necessary | |
518 | void MoveToItem(size_t item); | |
519 | ||
520 | bool ScrollList( int WXUNUSED(dx), int dy ); | |
521 | ||
522 | // bring the current item into view | |
523 | void MoveToFocus() { MoveToItem(m_current); } | |
524 | ||
525 | // start editing the label of the given item | |
526 | wxTextCtrl *EditLabel(long item, | |
527 | wxClassInfo* textControlClass = CLASSINFO(wxTextCtrl)); | |
528 | wxTextCtrl *GetEditControl() const | |
529 | { | |
530 | return m_textctrlWrapper ? m_textctrlWrapper->GetText() : NULL; | |
531 | } | |
532 | ||
533 | void ResetTextControl(wxTextCtrl *text) | |
534 | { | |
535 | delete text; | |
536 | m_textctrlWrapper = NULL; | |
537 | } | |
538 | ||
539 | void OnRenameTimer(); | |
540 | bool OnRenameAccept(size_t itemEdit, const wxString& value); | |
541 | void OnRenameCancelled(size_t itemEdit); | |
542 | ||
543 | void OnMouse( wxMouseEvent &event ); | |
544 | ||
545 | // called to switch the selection from the current item to newCurrent, | |
546 | void OnArrowChar( size_t newCurrent, const wxKeyEvent& event ); | |
547 | ||
548 | void OnChar( wxKeyEvent &event ); | |
549 | void OnKeyDown( wxKeyEvent &event ); | |
550 | void OnKeyUp( wxKeyEvent &event ); | |
551 | void OnSetFocus( wxFocusEvent &event ); | |
552 | void OnKillFocus( wxFocusEvent &event ); | |
553 | void OnScroll( wxScrollWinEvent& event ); | |
554 | ||
555 | void OnPaint( wxPaintEvent &event ); | |
556 | ||
557 | void OnChildFocus(wxChildFocusEvent& event); | |
558 | ||
559 | void DrawImage( int index, wxDC *dc, int x, int y ); | |
560 | void GetImageSize( int index, int &width, int &height ) const; | |
561 | int GetTextLength( const wxString &s ) const; | |
562 | ||
563 | void SetImageList( wxImageList *imageList, int which ); | |
564 | void SetItemSpacing( int spacing, bool isSmall = false ); | |
565 | int GetItemSpacing( bool isSmall = false ); | |
566 | ||
567 | void SetColumn( int col, wxListItem &item ); | |
568 | void SetColumnWidth( int col, int width ); | |
569 | void GetColumn( int col, wxListItem &item ) const; | |
570 | int GetColumnWidth( int col ) const; | |
571 | int GetColumnCount() const { return m_columns.GetCount(); } | |
572 | ||
573 | // returns the sum of the heights of all columns | |
574 | int GetHeaderWidth() const; | |
575 | ||
576 | int GetCountPerPage() const; | |
577 | ||
578 | void SetItem( wxListItem &item ); | |
579 | void GetItem( wxListItem &item ) const; | |
580 | void SetItemState( long item, long state, long stateMask ); | |
581 | void SetItemStateAll( long state, long stateMask ); | |
582 | int GetItemState( long item, long stateMask ) const; | |
583 | bool GetItemRect( long item, wxRect &rect ) const | |
584 | { | |
585 | return GetSubItemRect(item, wxLIST_GETSUBITEMRECT_WHOLEITEM, rect); | |
586 | } | |
587 | bool GetSubItemRect( long item, long subItem, wxRect& rect ) const; | |
588 | wxRect GetViewRect() const; | |
589 | bool GetItemPosition( long item, wxPoint& pos ) const; | |
590 | int GetSelectedItemCount() const; | |
591 | ||
592 | wxString GetItemText(long item) const | |
593 | { | |
594 | wxListItem info; | |
595 | info.m_mask = wxLIST_MASK_TEXT; | |
596 | info.m_itemId = item; | |
597 | GetItem( info ); | |
598 | return info.m_text; | |
599 | } | |
600 | ||
601 | void SetItemText(long item, const wxString& value) | |
602 | { | |
603 | wxListItem info; | |
604 | info.m_mask = wxLIST_MASK_TEXT; | |
605 | info.m_itemId = item; | |
606 | info.m_text = value; | |
607 | SetItem( info ); | |
608 | } | |
609 | ||
610 | wxImageList* GetSmallImageList() const | |
611 | { return m_small_image_list; } | |
612 | ||
613 | // set the scrollbars and update the positions of the items | |
614 | void RecalculatePositions(bool noRefresh = false); | |
615 | ||
616 | // refresh the window and the header | |
617 | void RefreshAll(); | |
618 | ||
619 | long GetNextItem( long item, int geometry, int state ) const; | |
620 | void DeleteItem( long index ); | |
621 | void DeleteAllItems(); | |
622 | void DeleteColumn( int col ); | |
623 | void DeleteEverything(); | |
624 | void EnsureVisible( long index ); | |
625 | long FindItem( long start, const wxString& str, bool partial = false ); | |
626 | long FindItem( long start, wxUIntPtr data); | |
627 | long FindItem( const wxPoint& pt ); | |
628 | long HitTest( int x, int y, int &flags ) const; | |
629 | void InsertItem( wxListItem &item ); | |
630 | void InsertColumn( long col, wxListItem &item ); | |
631 | int GetItemWidthWithImage(wxListItem * item); | |
b18e2046 | 632 | void SortItems( wxListCtrlCompare fn, wxIntPtr data ); |
ad486020 FM |
633 | |
634 | size_t GetItemCount() const; | |
635 | bool IsEmpty() const { return GetItemCount() == 0; } | |
636 | void SetItemCount(long count); | |
637 | ||
638 | // change the current (== focused) item, send a notification event | |
639 | void ChangeCurrent(size_t current); | |
640 | void ResetCurrent() { ChangeCurrent((size_t)-1); } | |
641 | bool HasCurrent() const { return m_current != (size_t)-1; } | |
642 | ||
643 | // send out a wxListEvent | |
644 | void SendNotify( size_t line, | |
645 | wxEventType command, | |
646 | const wxPoint& point = wxDefaultPosition ); | |
647 | ||
648 | // override base class virtual to reset m_lineHeight when the font changes | |
649 | virtual bool SetFont(const wxFont& font) | |
650 | { | |
651 | if ( !wxWindow::SetFont(font) ) | |
652 | return false; | |
653 | ||
654 | m_lineHeight = 0; | |
655 | ||
656 | return true; | |
657 | } | |
658 | ||
659 | // these are for wxListLineData usage only | |
660 | ||
661 | // get the backpointer to the list ctrl | |
662 | wxGenericListCtrl *GetListCtrl() const | |
663 | { | |
664 | return wxStaticCast(GetParent(), wxGenericListCtrl); | |
665 | } | |
666 | ||
667 | // get the height of all lines (assuming they all do have the same height) | |
668 | wxCoord GetLineHeight() const; | |
669 | ||
670 | // get the y position of the given line (only for report view) | |
671 | wxCoord GetLineY(size_t line) const; | |
672 | ||
673 | // get the brush to use for the item highlighting | |
674 | wxBrush *GetHighlightBrush() const | |
675 | { | |
676 | return m_hasFocus ? m_highlightBrush : m_highlightUnfocusedBrush; | |
677 | } | |
678 | ||
679 | bool HasFocus() const | |
680 | { | |
681 | return m_hasFocus; | |
682 | } | |
683 | ||
684 | protected: | |
685 | // the array of all line objects for a non virtual list control (for the | |
686 | // virtual list control we only ever use m_lines[0]) | |
687 | wxListLineDataArray m_lines; | |
688 | ||
689 | // the list of column objects | |
690 | wxListHeaderDataList m_columns; | |
691 | ||
692 | // currently focused item or -1 | |
693 | size_t m_current; | |
694 | ||
695 | // the number of lines per page | |
696 | int m_linesPerPage; | |
697 | ||
698 | // this flag is set when something which should result in the window | |
699 | // redrawing happens (i.e. an item was added or deleted, or its appearance | |
700 | // changed) and OnPaint() doesn't redraw the window while it is set which | |
701 | // allows to minimize the number of repaintings when a lot of items are | |
702 | // being added. The real repainting occurs only after the next OnIdle() | |
703 | // call | |
704 | bool m_dirty; | |
705 | ||
706 | wxColour *m_highlightColour; | |
707 | wxImageList *m_small_image_list; | |
708 | wxImageList *m_normal_image_list; | |
709 | int m_small_spacing; | |
710 | int m_normal_spacing; | |
711 | bool m_hasFocus; | |
712 | ||
713 | bool m_lastOnSame; | |
714 | wxTimer *m_renameTimer; | |
715 | bool m_isCreated; | |
716 | int m_dragCount; | |
717 | wxPoint m_dragStart; | |
718 | ColWidthArray m_aColWidths; | |
719 | ||
720 | // for double click logic | |
721 | size_t m_lineLastClicked, | |
722 | m_lineBeforeLastClicked, | |
723 | m_lineSelectSingleOnUp; | |
724 | ||
725 | protected: | |
726 | wxWindow *GetMainWindowOfCompositeControl() { return GetParent(); } | |
727 | ||
728 | // the total count of items in a virtual list control | |
729 | size_t m_countVirt; | |
730 | ||
731 | // the object maintaining the items selection state, only used in virtual | |
732 | // controls | |
733 | wxSelectionStore m_selStore; | |
734 | ||
735 | // common part of all ctors | |
736 | void Init(); | |
737 | ||
738 | // get the line data for the given index | |
739 | wxListLineData *GetLine(size_t n) const | |
740 | { | |
9a83f860 | 741 | wxASSERT_MSG( n != (size_t)-1, wxT("invalid line index") ); |
ad486020 FM |
742 | |
743 | if ( IsVirtual() ) | |
744 | { | |
745 | wxConstCast(this, wxListMainWindow)->CacheLineData(n); | |
746 | n = 0; | |
747 | } | |
748 | ||
749 | return &m_lines[n]; | |
750 | } | |
751 | ||
752 | // get a dummy line which can be used for geometry calculations and such: | |
753 | // you must use GetLine() if you want to really draw the line | |
754 | wxListLineData *GetDummyLine() const; | |
755 | ||
756 | // cache the line data of the n-th line in m_lines[0] | |
757 | void CacheLineData(size_t line); | |
758 | ||
759 | // get the range of visible lines | |
760 | void GetVisibleLinesRange(size_t *from, size_t *to); | |
761 | ||
762 | // force us to recalculate the range of visible lines | |
763 | void ResetVisibleLinesRange() { m_lineFrom = (size_t)-1; } | |
764 | ||
765 | // get the colour to be used for drawing the rules | |
766 | wxColour GetRuleColour() const | |
767 | { | |
768 | return wxSystemSettings::GetColour(wxSYS_COLOUR_3DLIGHT); | |
769 | } | |
770 | ||
771 | private: | |
772 | // initialize the current item if needed | |
773 | void UpdateCurrent(); | |
774 | ||
775 | // delete all items but don't refresh: called from dtor | |
776 | void DoDeleteAllItems(); | |
777 | ||
778 | // the height of one line using the current font | |
779 | wxCoord m_lineHeight; | |
780 | ||
781 | // the total header width or 0 if not calculated yet | |
782 | wxCoord m_headerWidth; | |
783 | ||
784 | // the first and last lines being shown on screen right now (inclusive), | |
785 | // both may be -1 if they must be calculated so never access them directly: | |
786 | // use GetVisibleLinesRange() above instead | |
787 | size_t m_lineFrom, | |
788 | m_lineTo; | |
789 | ||
790 | // the brushes to use for item highlighting when we do/don't have focus | |
791 | wxBrush *m_highlightBrush, | |
792 | *m_highlightUnfocusedBrush; | |
793 | ||
794 | // wrapper around the text control currently used for in place editing or | |
795 | // NULL if no item is being edited | |
796 | wxListTextCtrlWrapper *m_textctrlWrapper; | |
797 | ||
798 | ||
799 | DECLARE_EVENT_TABLE() | |
800 | ||
801 | friend class wxGenericListCtrl; | |
802 | }; | |
803 | ||
804 | #endif // wxUSE_LISTCTRL | |
805 | #endif // _WX_GENERIC_LISTCTRL_PRIVATE_H_ |