]>
Commit | Line | Data |
---|---|---|
ad486020 | 1 | ///////////////////////////////////////////////////////////////////////////// |
ac6a837e | 2 | // Name: wx/generic/private/listctrl.h |
ad486020 FM |
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 | |
ed84dc74 | 278 | void Draw( wxDC *dc, bool current ); |
ad486020 | 279 | |
ed84dc74 VZ |
280 | // the same in report mode: it needs more parameters as we don't store |
281 | // everything in the item in report mode | |
ad486020 FM |
282 | void DrawInReportMode( wxDC *dc, |
283 | const wxRect& rect, | |
284 | const wxRect& rectHL, | |
285 | bool highlighted, | |
286 | bool current ); | |
287 | ||
288 | private: | |
289 | // set the line to contain num items (only can be > 1 in report mode) | |
290 | void InitItems( int num ); | |
291 | ||
292 | // get the mode (i.e. style) of the list control | |
293 | inline int GetMode() const; | |
294 | ||
ed84dc74 VZ |
295 | // Apply this item attributes to the given DC: set the text font and colour |
296 | // and also erase the background appropriately. | |
297 | void ApplyAttributes(wxDC *dc, | |
298 | const wxRect& rectHL, | |
299 | bool highlighted, | |
300 | bool current); | |
ad486020 FM |
301 | |
302 | // draw the text on the DC with the correct justification; also add an | |
303 | // ellipsis if the text is too large to fit in the current width | |
304 | void DrawTextFormatted(wxDC *dc, | |
305 | const wxString &text, | |
306 | int col, | |
307 | int x, | |
308 | int yMid, // this is middle, not top, of the text | |
309 | int width); | |
310 | }; | |
311 | ||
312 | WX_DECLARE_OBJARRAY(wxListLineData, wxListLineDataArray); | |
313 | ||
314 | //----------------------------------------------------------------------------- | |
315 | // wxListHeaderWindow (internal) | |
316 | //----------------------------------------------------------------------------- | |
317 | ||
318 | class wxListHeaderWindow : public wxWindow | |
319 | { | |
320 | protected: | |
321 | wxListMainWindow *m_owner; | |
322 | const wxCursor *m_currentCursor; | |
323 | wxCursor *m_resizeCursor; | |
324 | bool m_isDragging; | |
325 | ||
326 | // column being resized or -1 | |
327 | int m_column; | |
328 | ||
329 | // divider line position in logical (unscrolled) coords | |
330 | int m_currentX; | |
331 | ||
332 | // minimal position beyond which the divider line | |
333 | // can't be dragged in logical coords | |
334 | int m_minX; | |
335 | ||
336 | public: | |
337 | wxListHeaderWindow(); | |
338 | ||
339 | wxListHeaderWindow( wxWindow *win, | |
340 | wxWindowID id, | |
341 | wxListMainWindow *owner, | |
342 | const wxPoint &pos = wxDefaultPosition, | |
343 | const wxSize &size = wxDefaultSize, | |
344 | long style = 0, | |
345 | const wxString &name = wxT("wxlistctrlcolumntitles") ); | |
346 | ||
347 | virtual ~wxListHeaderWindow(); | |
348 | ||
22930be8 VZ |
349 | // We never need focus as we don't have any keyboard interface. |
350 | virtual bool AcceptsFocus() const { return false; } | |
351 | ||
ad486020 FM |
352 | void DrawCurrent(); |
353 | void AdjustDC( wxDC& dc ); | |
354 | ||
355 | void OnPaint( wxPaintEvent &event ); | |
356 | void OnMouse( wxMouseEvent &event ); | |
ad486020 FM |
357 | |
358 | // needs refresh | |
359 | bool m_dirty; | |
360 | ||
361 | // Update main window's column later | |
362 | bool m_sendSetColumnWidth; | |
363 | int m_colToSend; | |
364 | int m_widthToSend; | |
365 | ||
366 | virtual void OnInternalIdle(); | |
367 | ||
368 | private: | |
369 | // common part of all ctors | |
370 | void Init(); | |
371 | ||
372 | // generate and process the list event of the given type, return true if | |
373 | // it wasn't vetoed, i.e. if we should proceed | |
374 | bool SendListEvent(wxEventType type, const wxPoint& pos); | |
375 | ||
376 | DECLARE_EVENT_TABLE() | |
377 | }; | |
378 | ||
379 | //----------------------------------------------------------------------------- | |
380 | // wxListRenameTimer (internal) | |
381 | //----------------------------------------------------------------------------- | |
382 | ||
383 | class wxListRenameTimer: public wxTimer | |
384 | { | |
385 | private: | |
386 | wxListMainWindow *m_owner; | |
387 | ||
388 | public: | |
389 | wxListRenameTimer( wxListMainWindow *owner ); | |
390 | void Notify(); | |
391 | }; | |
392 | ||
d34d31f6 VZ |
393 | //----------------------------------------------------------------------------- |
394 | // wxListFindTimer (internal) | |
395 | //----------------------------------------------------------------------------- | |
396 | ||
397 | class wxListFindTimer: public wxTimer | |
398 | { | |
399 | public: | |
400 | // reset the current prefix after half a second of inactivity | |
401 | enum { DELAY = 500 }; | |
402 | ||
403 | wxListFindTimer( wxListMainWindow *owner ) | |
404 | : m_owner(owner) | |
405 | { | |
406 | } | |
407 | ||
408 | virtual void Notify(); | |
409 | ||
410 | private: | |
411 | wxListMainWindow *m_owner; | |
412 | }; | |
413 | ||
ad486020 FM |
414 | //----------------------------------------------------------------------------- |
415 | // wxListTextCtrlWrapper: wraps a wxTextCtrl to make it work for inline editing | |
416 | //----------------------------------------------------------------------------- | |
417 | ||
418 | class wxListTextCtrlWrapper : public wxEvtHandler | |
419 | { | |
420 | public: | |
421 | // NB: text must be a valid object but not Create()d yet | |
422 | wxListTextCtrlWrapper(wxListMainWindow *owner, | |
423 | wxTextCtrl *text, | |
424 | size_t itemEdit); | |
425 | ||
426 | wxTextCtrl *GetText() const { return m_text; } | |
427 | ||
64ac3db8 VZ |
428 | // Check if the given key event should stop editing and return true if it |
429 | // does or false otherwise. | |
430 | bool CheckForEndEditKey(const wxKeyEvent& event); | |
431 | ||
93f6e00d VZ |
432 | // Different reasons for calling EndEdit(): |
433 | // | |
434 | // It was called because: | |
435 | enum EndReason | |
436 | { | |
437 | End_Accept, // user has accepted the changes. | |
438 | End_Discard, // user has cancelled editing. | |
439 | End_Destroy // the entire control is being destroyed. | |
440 | }; | |
441 | ||
442 | void EndEdit(EndReason reason); | |
ad486020 FM |
443 | |
444 | protected: | |
445 | void OnChar( wxKeyEvent &event ); | |
446 | void OnKeyUp( wxKeyEvent &event ); | |
447 | void OnKillFocus( wxFocusEvent &event ); | |
448 | ||
449 | bool AcceptChanges(); | |
450 | void Finish( bool setfocus ); | |
451 | ||
452 | private: | |
453 | wxListMainWindow *m_owner; | |
454 | wxTextCtrl *m_text; | |
455 | wxString m_startValue; | |
456 | size_t m_itemEdited; | |
457 | bool m_aboutToFinish; | |
458 | ||
459 | DECLARE_EVENT_TABLE() | |
460 | }; | |
461 | ||
462 | //----------------------------------------------------------------------------- | |
463 | // wxListMainWindow (internal) | |
464 | //----------------------------------------------------------------------------- | |
465 | ||
466 | WX_DECLARE_LIST(wxListHeaderData, wxListHeaderDataList); | |
467 | ||
468 | class wxListMainWindow : public wxWindow | |
469 | { | |
470 | public: | |
471 | wxListMainWindow(); | |
472 | wxListMainWindow( wxWindow *parent, | |
473 | wxWindowID id, | |
1c0a0736 VZ |
474 | const wxPoint& pos, |
475 | const wxSize& size ); | |
ad486020 FM |
476 | |
477 | virtual ~wxListMainWindow(); | |
478 | ||
476de5ea VZ |
479 | // called by the main control when its mode changes |
480 | void SetReportView(bool inReportView); | |
481 | ||
482 | // helper to simplify testing for wxLC_XXX flags | |
ad486020 FM |
483 | bool HasFlag(int flag) const { return m_parent->HasFlag(flag); } |
484 | ||
485 | // return true if this is a virtual list control | |
486 | bool IsVirtual() const { return HasFlag(wxLC_VIRTUAL); } | |
487 | ||
488 | // return true if the control is in report mode | |
489 | bool InReportView() const { return HasFlag(wxLC_REPORT); } | |
490 | ||
491 | // return true if we are in single selection mode, false if multi sel | |
492 | bool IsSingleSel() const { return HasFlag(wxLC_SINGLE_SEL); } | |
493 | ||
494 | // do we have a header window? | |
495 | bool HasHeader() const | |
496 | { return InReportView() && !HasFlag(wxLC_NO_HEADER); } | |
497 | ||
498 | void HighlightAll( bool on ); | |
499 | ||
500 | // all these functions only do something if the line is currently visible | |
501 | ||
502 | // change the line "selected" state, return true if it really changed | |
503 | bool HighlightLine( size_t line, bool highlight = true); | |
504 | ||
505 | // as HighlightLine() but do it for the range of lines: this is incredibly | |
506 | // more efficient for virtual list controls! | |
507 | // | |
508 | // NB: unlike HighlightLine() this one does refresh the lines on screen | |
509 | void HighlightLines( size_t lineFrom, size_t lineTo, bool on = true ); | |
510 | ||
511 | // toggle the line state and refresh it | |
512 | void ReverseHighlight( size_t line ) | |
513 | { HighlightLine(line, !IsHighlighted(line)); RefreshLine(line); } | |
514 | ||
515 | // return true if the line is highlighted | |
516 | bool IsHighlighted(size_t line) const; | |
517 | ||
518 | // refresh one or several lines at once | |
519 | void RefreshLine( size_t line ); | |
520 | void RefreshLines( size_t lineFrom, size_t lineTo ); | |
521 | ||
522 | // refresh all selected items | |
523 | void RefreshSelected(); | |
524 | ||
525 | // refresh all lines below the given one: the difference with | |
526 | // RefreshLines() is that the index here might not be a valid one (happens | |
527 | // when the last line is deleted) | |
528 | void RefreshAfter( size_t lineFrom ); | |
529 | ||
530 | // the methods which are forwarded to wxListLineData itself in list/icon | |
531 | // modes but are here because the lines don't store their positions in the | |
532 | // report mode | |
533 | ||
534 | // get the bound rect for the entire line | |
535 | wxRect GetLineRect(size_t line) const; | |
536 | ||
537 | // get the bound rect of the label | |
538 | wxRect GetLineLabelRect(size_t line) const; | |
539 | ||
540 | // get the bound rect of the items icon (only may be called if we do have | |
541 | // an icon!) | |
542 | wxRect GetLineIconRect(size_t line) const; | |
543 | ||
544 | // get the rect to be highlighted when the item has focus | |
545 | wxRect GetLineHighlightRect(size_t line) const; | |
546 | ||
547 | // get the size of the total line rect | |
548 | wxSize GetLineSize(size_t line) const | |
549 | { return GetLineRect(line).GetSize(); } | |
550 | ||
551 | // return the hit code for the corresponding position (in this line) | |
552 | long HitTestLine(size_t line, int x, int y) const; | |
553 | ||
554 | // bring the selected item into view, scrolling to it if necessary | |
555 | void MoveToItem(size_t item); | |
556 | ||
557 | bool ScrollList( int WXUNUSED(dx), int dy ); | |
558 | ||
559 | // bring the current item into view | |
560 | void MoveToFocus() { MoveToItem(m_current); } | |
561 | ||
562 | // start editing the label of the given item | |
563 | wxTextCtrl *EditLabel(long item, | |
b19b28c8 | 564 | wxClassInfo* textControlClass = wxCLASSINFO(wxTextCtrl)); |
ad486020 FM |
565 | wxTextCtrl *GetEditControl() const |
566 | { | |
567 | return m_textctrlWrapper ? m_textctrlWrapper->GetText() : NULL; | |
568 | } | |
569 | ||
570 | void ResetTextControl(wxTextCtrl *text) | |
571 | { | |
572 | delete text; | |
573 | m_textctrlWrapper = NULL; | |
574 | } | |
575 | ||
576 | void OnRenameTimer(); | |
577 | bool OnRenameAccept(size_t itemEdit, const wxString& value); | |
578 | void OnRenameCancelled(size_t itemEdit); | |
579 | ||
d34d31f6 VZ |
580 | void OnFindTimer(); |
581 | // set whether or not to ring the find bell | |
582 | // (does nothing on MSW - bell is always rung) | |
583 | void EnableBellOnNoMatch( bool on ); | |
584 | ||
ad486020 FM |
585 | void OnMouse( wxMouseEvent &event ); |
586 | ||
587 | // called to switch the selection from the current item to newCurrent, | |
588 | void OnArrowChar( size_t newCurrent, const wxKeyEvent& event ); | |
589 | ||
64ac3db8 | 590 | void OnCharHook( wxKeyEvent &event ); |
ad486020 FM |
591 | void OnChar( wxKeyEvent &event ); |
592 | void OnKeyDown( wxKeyEvent &event ); | |
593 | void OnKeyUp( wxKeyEvent &event ); | |
594 | void OnSetFocus( wxFocusEvent &event ); | |
595 | void OnKillFocus( wxFocusEvent &event ); | |
596 | void OnScroll( wxScrollWinEvent& event ); | |
597 | ||
598 | void OnPaint( wxPaintEvent &event ); | |
599 | ||
600 | void OnChildFocus(wxChildFocusEvent& event); | |
601 | ||
602 | void DrawImage( int index, wxDC *dc, int x, int y ); | |
603 | void GetImageSize( int index, int &width, int &height ) const; | |
ad486020 FM |
604 | |
605 | void SetImageList( wxImageList *imageList, int which ); | |
606 | void SetItemSpacing( int spacing, bool isSmall = false ); | |
607 | int GetItemSpacing( bool isSmall = false ); | |
608 | ||
94248d2e | 609 | void SetColumn( int col, const wxListItem &item ); |
ad486020 FM |
610 | void SetColumnWidth( int col, int width ); |
611 | void GetColumn( int col, wxListItem &item ) const; | |
612 | int GetColumnWidth( int col ) const; | |
613 | int GetColumnCount() const { return m_columns.GetCount(); } | |
614 | ||
615 | // returns the sum of the heights of all columns | |
616 | int GetHeaderWidth() const; | |
617 | ||
618 | int GetCountPerPage() const; | |
619 | ||
620 | void SetItem( wxListItem &item ); | |
621 | void GetItem( wxListItem &item ) const; | |
622 | void SetItemState( long item, long state, long stateMask ); | |
623 | void SetItemStateAll( long state, long stateMask ); | |
624 | int GetItemState( long item, long stateMask ) const; | |
625 | bool GetItemRect( long item, wxRect &rect ) const | |
626 | { | |
627 | return GetSubItemRect(item, wxLIST_GETSUBITEMRECT_WHOLEITEM, rect); | |
628 | } | |
629 | bool GetSubItemRect( long item, long subItem, wxRect& rect ) const; | |
630 | wxRect GetViewRect() const; | |
631 | bool GetItemPosition( long item, wxPoint& pos ) const; | |
632 | int GetSelectedItemCount() const; | |
633 | ||
0fe26008 | 634 | wxString GetItemText(long item, int col = 0) const |
ad486020 FM |
635 | { |
636 | wxListItem info; | |
637 | info.m_mask = wxLIST_MASK_TEXT; | |
638 | info.m_itemId = item; | |
0fe26008 | 639 | info.m_col = col; |
ad486020 FM |
640 | GetItem( info ); |
641 | return info.m_text; | |
642 | } | |
643 | ||
644 | void SetItemText(long item, const wxString& value) | |
645 | { | |
646 | wxListItem info; | |
647 | info.m_mask = wxLIST_MASK_TEXT; | |
648 | info.m_itemId = item; | |
649 | info.m_text = value; | |
650 | SetItem( info ); | |
651 | } | |
652 | ||
653 | wxImageList* GetSmallImageList() const | |
654 | { return m_small_image_list; } | |
655 | ||
656 | // set the scrollbars and update the positions of the items | |
657 | void RecalculatePositions(bool noRefresh = false); | |
658 | ||
659 | // refresh the window and the header | |
660 | void RefreshAll(); | |
661 | ||
662 | long GetNextItem( long item, int geometry, int state ) const; | |
663 | void DeleteItem( long index ); | |
664 | void DeleteAllItems(); | |
665 | void DeleteColumn( int col ); | |
666 | void DeleteEverything(); | |
667 | void EnsureVisible( long index ); | |
668 | long FindItem( long start, const wxString& str, bool partial = false ); | |
669 | long FindItem( long start, wxUIntPtr data); | |
670 | long FindItem( const wxPoint& pt ); | |
671 | long HitTest( int x, int y, int &flags ) const; | |
672 | void InsertItem( wxListItem &item ); | |
57bf8a6f | 673 | long InsertColumn( long col, const wxListItem &item ); |
ad486020 | 674 | int GetItemWidthWithImage(wxListItem * item); |
b18e2046 | 675 | void SortItems( wxListCtrlCompare fn, wxIntPtr data ); |
ad486020 FM |
676 | |
677 | size_t GetItemCount() const; | |
678 | bool IsEmpty() const { return GetItemCount() == 0; } | |
679 | void SetItemCount(long count); | |
680 | ||
681 | // change the current (== focused) item, send a notification event | |
682 | void ChangeCurrent(size_t current); | |
683 | void ResetCurrent() { ChangeCurrent((size_t)-1); } | |
684 | bool HasCurrent() const { return m_current != (size_t)-1; } | |
685 | ||
686 | // send out a wxListEvent | |
687 | void SendNotify( size_t line, | |
688 | wxEventType command, | |
689 | const wxPoint& point = wxDefaultPosition ); | |
690 | ||
691 | // override base class virtual to reset m_lineHeight when the font changes | |
692 | virtual bool SetFont(const wxFont& font) | |
693 | { | |
694 | if ( !wxWindow::SetFont(font) ) | |
695 | return false; | |
696 | ||
697 | m_lineHeight = 0; | |
698 | ||
699 | return true; | |
700 | } | |
701 | ||
702 | // these are for wxListLineData usage only | |
703 | ||
704 | // get the backpointer to the list ctrl | |
705 | wxGenericListCtrl *GetListCtrl() const | |
706 | { | |
707 | return wxStaticCast(GetParent(), wxGenericListCtrl); | |
708 | } | |
709 | ||
710 | // get the height of all lines (assuming they all do have the same height) | |
711 | wxCoord GetLineHeight() const; | |
712 | ||
713 | // get the y position of the given line (only for report view) | |
714 | wxCoord GetLineY(size_t line) const; | |
715 | ||
716 | // get the brush to use for the item highlighting | |
717 | wxBrush *GetHighlightBrush() const | |
718 | { | |
719 | return m_hasFocus ? m_highlightBrush : m_highlightUnfocusedBrush; | |
720 | } | |
721 | ||
722 | bool HasFocus() const | |
723 | { | |
724 | return m_hasFocus; | |
725 | } | |
726 | ||
727 | protected: | |
728 | // the array of all line objects for a non virtual list control (for the | |
729 | // virtual list control we only ever use m_lines[0]) | |
730 | wxListLineDataArray m_lines; | |
731 | ||
732 | // the list of column objects | |
733 | wxListHeaderDataList m_columns; | |
734 | ||
735 | // currently focused item or -1 | |
736 | size_t m_current; | |
737 | ||
738 | // the number of lines per page | |
739 | int m_linesPerPage; | |
740 | ||
741 | // this flag is set when something which should result in the window | |
742 | // redrawing happens (i.e. an item was added or deleted, or its appearance | |
743 | // changed) and OnPaint() doesn't redraw the window while it is set which | |
744 | // allows to minimize the number of repaintings when a lot of items are | |
745 | // being added. The real repainting occurs only after the next OnIdle() | |
746 | // call | |
747 | bool m_dirty; | |
748 | ||
749 | wxColour *m_highlightColour; | |
750 | wxImageList *m_small_image_list; | |
751 | wxImageList *m_normal_image_list; | |
752 | int m_small_spacing; | |
753 | int m_normal_spacing; | |
754 | bool m_hasFocus; | |
755 | ||
756 | bool m_lastOnSame; | |
757 | wxTimer *m_renameTimer; | |
d34d31f6 VZ |
758 | |
759 | // incremental search data | |
760 | wxString m_findPrefix; | |
761 | wxTimer *m_findTimer; | |
762 | // This flag is set to 0 if the bell is disabled, 1 if it is enabled and -1 | |
763 | // if it is globally enabled but has been temporarily disabled because we | |
764 | // had already beeped for this particular search. | |
765 | int m_findBell; | |
766 | ||
ad486020 FM |
767 | bool m_isCreated; |
768 | int m_dragCount; | |
769 | wxPoint m_dragStart; | |
770 | ColWidthArray m_aColWidths; | |
771 | ||
772 | // for double click logic | |
773 | size_t m_lineLastClicked, | |
774 | m_lineBeforeLastClicked, | |
775 | m_lineSelectSingleOnUp; | |
776 | ||
777 | protected: | |
778 | wxWindow *GetMainWindowOfCompositeControl() { return GetParent(); } | |
779 | ||
780 | // the total count of items in a virtual list control | |
781 | size_t m_countVirt; | |
782 | ||
783 | // the object maintaining the items selection state, only used in virtual | |
784 | // controls | |
785 | wxSelectionStore m_selStore; | |
786 | ||
787 | // common part of all ctors | |
788 | void Init(); | |
789 | ||
790 | // get the line data for the given index | |
791 | wxListLineData *GetLine(size_t n) const | |
792 | { | |
9a83f860 | 793 | wxASSERT_MSG( n != (size_t)-1, wxT("invalid line index") ); |
ad486020 FM |
794 | |
795 | if ( IsVirtual() ) | |
796 | { | |
797 | wxConstCast(this, wxListMainWindow)->CacheLineData(n); | |
798 | n = 0; | |
799 | } | |
800 | ||
801 | return &m_lines[n]; | |
802 | } | |
803 | ||
804 | // get a dummy line which can be used for geometry calculations and such: | |
805 | // you must use GetLine() if you want to really draw the line | |
806 | wxListLineData *GetDummyLine() const; | |
807 | ||
808 | // cache the line data of the n-th line in m_lines[0] | |
809 | void CacheLineData(size_t line); | |
810 | ||
811 | // get the range of visible lines | |
812 | void GetVisibleLinesRange(size_t *from, size_t *to); | |
813 | ||
814 | // force us to recalculate the range of visible lines | |
815 | void ResetVisibleLinesRange() { m_lineFrom = (size_t)-1; } | |
816 | ||
d34d31f6 VZ |
817 | // find the first item starting with the given prefix after the given item |
818 | size_t PrefixFindItem(size_t item, const wxString& prefix) const; | |
819 | ||
ad486020 FM |
820 | // get the colour to be used for drawing the rules |
821 | wxColour GetRuleColour() const | |
822 | { | |
823 | return wxSystemSettings::GetColour(wxSYS_COLOUR_3DLIGHT); | |
824 | } | |
825 | ||
826 | private: | |
827 | // initialize the current item if needed | |
828 | void UpdateCurrent(); | |
829 | ||
830 | // delete all items but don't refresh: called from dtor | |
831 | void DoDeleteAllItems(); | |
832 | ||
3d167c00 VZ |
833 | // Compute the minimal width needed to fully display the column header. |
834 | int ComputeMinHeaderWidth(const wxListHeaderData* header) const; | |
835 | ||
836 | ||
ad486020 FM |
837 | // the height of one line using the current font |
838 | wxCoord m_lineHeight; | |
839 | ||
840 | // the total header width or 0 if not calculated yet | |
841 | wxCoord m_headerWidth; | |
842 | ||
843 | // the first and last lines being shown on screen right now (inclusive), | |
844 | // both may be -1 if they must be calculated so never access them directly: | |
845 | // use GetVisibleLinesRange() above instead | |
846 | size_t m_lineFrom, | |
847 | m_lineTo; | |
848 | ||
849 | // the brushes to use for item highlighting when we do/don't have focus | |
850 | wxBrush *m_highlightBrush, | |
851 | *m_highlightUnfocusedBrush; | |
852 | ||
853 | // wrapper around the text control currently used for in place editing or | |
854 | // NULL if no item is being edited | |
855 | wxListTextCtrlWrapper *m_textctrlWrapper; | |
856 | ||
857 | ||
858 | DECLARE_EVENT_TABLE() | |
859 | ||
860 | friend class wxGenericListCtrl; | |
861 | }; | |
862 | ||
863 | #endif // wxUSE_LISTCTRL | |
864 | #endif // _WX_GENERIC_LISTCTRL_PRIVATE_H_ |