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