1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Generic list control
4 // Author: Robert Roebling
7 // Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 #ifndef __LISTCTRLH_G__
12 #define __LISTCTRLH_G__
15 #pragma interface "listctrl.h"
19 #include "wx/object.h"
20 #include "wx/generic/imaglist.h"
21 #include "wx/control.h"
23 #include "wx/textctrl.h"
24 #include "wx/dcclient.h"
25 #include "wx/scrolwin.h"
26 #include "wx/settings.h"
28 #if wxUSE_DRAG_AND_DROP
29 class WXDLLEXPORT wxDropTarget
;
32 //-----------------------------------------------------------------------------
34 //-----------------------------------------------------------------------------
36 class WXDLLEXPORT wxListItem
;
37 class WXDLLEXPORT wxListEvent
;
38 class WXDLLEXPORT wxListCtrl
;
40 //-----------------------------------------------------------------------------
42 //-----------------------------------------------------------------------------
44 class WXDLLEXPORT wxListHeaderData
;
45 class WXDLLEXPORT wxListItemData
;
46 class WXDLLEXPORT wxListLineData
;
48 class WXDLLEXPORT wxListHeaderWindow
;
49 class WXDLLEXPORT wxListMainWindow
;
51 class WXDLLEXPORT wxListRenameTimer
;
52 class WXDLLEXPORT wxListTextCtrl
;
54 //-----------------------------------------------------------------------------
56 //-----------------------------------------------------------------------------
58 // type of compare function for wxListCtrl sort operation
59 typedef int (*wxListCtrlCompare
)(long item1
, long item2
, long sortData
);
61 //-----------------------------------------------------------------------------
63 //-----------------------------------------------------------------------------
65 #define wxLC_ICON 0x0004
66 #define wxLC_SMALL_ICON 0x0008
67 #define wxLC_LIST 0x0010
68 #define wxLC_REPORT 0x0020
69 #define wxLC_ALIGN_TOP 0x0040
70 #define wxLC_ALIGN_LEFT 0x0080
71 #define wxLC_AUTOARRANGE 0x0100 // not supported in wxGLC
72 #define wxLC_USER_TEXT 0x0200 // not supported in wxGLC (how does it work?)
73 #define wxLC_EDIT_LABELS 0x0400
74 #define wxLC_NO_HEADER 0x0800 // not supported in wxGLC
75 #define wxLC_NO_SORT_HEADER 0x1000 // not supported in wxGLC
76 #define wxLC_SINGLE_SEL 0x2000
77 #define wxLC_SORT_ASCENDING 0x4000
78 #define wxLC_SORT_DESCENDING 0x8000 // not supported in wxGLC
80 #define wxLC_MASK_TYPE (wxLC_ICON | wxLC_SMALL_ICON | wxLC_LIST | wxLC_REPORT)
81 #define wxLC_MASK_ALIGN (wxLC_ALIGN_TOP | wxLC_ALIGN_LEFT)
82 #define wxLC_MASK_SORT (wxLC_SORT_ASCENDING | wxLC_SORT_DESCENDING)
84 // Omitted because (a) too much detail (b) not enough style flags
85 // #define wxLC_NO_SCROLL
86 // #define wxLC_NO_LABEL_WRAP
87 // #define wxLC_OWNERDRAW_FIXED
88 // #define wxLC_SHOW_SEL_ALWAYS
90 // Mask flags to tell app/GUI what fields of wxListItem are valid
91 #define wxLIST_MASK_STATE 0x0001
92 #define wxLIST_MASK_TEXT 0x0002
93 #define wxLIST_MASK_IMAGE 0x0004
94 #define wxLIST_MASK_DATA 0x0008
95 #define wxLIST_SET_ITEM 0x0010
96 #define wxLIST_MASK_WIDTH 0x0020
97 #define wxLIST_MASK_FORMAT 0x0040
99 // State flags for indicating the state of an item
100 #define wxLIST_STATE_DONTCARE 0x0000
101 #define wxLIST_STATE_DROPHILITED 0x0001 // not supported in wxGLC
102 #define wxLIST_STATE_FOCUSED 0x0002
103 #define wxLIST_STATE_SELECTED 0x0004
104 #define wxLIST_STATE_CUT 0x0008 // not supported in wxGLC
106 // Hit test flags, used in HitTest // wxGLC suppots 20 and 80
107 #define wxLIST_HITTEST_ABOVE 0x0001 // Above the client area.
108 #define wxLIST_HITTEST_BELOW 0x0002 // Below the client area.
109 #define wxLIST_HITTEST_NOWHERE 0x0004 // In the client area but below the last item.
110 #define wxLIST_HITTEST_ONITEMICON 0x0020 // On the bitmap associated with an item.
111 #define wxLIST_HITTEST_ONITEMLABEL 0x0080 // On the label (string) associated with an item.
112 #define wxLIST_HITTEST_ONITEMRIGHT 0x0100 // In the area to the right of an item.
113 #define wxLIST_HITTEST_ONITEMSTATEICON 0x0200 // On the state icon for a tree view item that is in a user-defined state.
114 #define wxLIST_HITTEST_TOLEFT 0x0400 // To the right of the client area.
115 #define wxLIST_HITTEST_TORIGHT 0x0800 // To the left of the client area.
117 #define wxLIST_HITTEST_ONITEM (wxLIST_HITTEST_ONITEMICON | wxLIST_HITTEST_ONITEMLABEL | wxLIST_HITTEST_ONITEMSTATEICON)
121 // Flags for GetNextItem // always wxLIST_NEXT_ALL in wxGLC
123 wxLIST_NEXT_ABOVE
, // Searches for an item above the specified item
124 wxLIST_NEXT_ALL
, // Searches for subsequent item by index
125 wxLIST_NEXT_BELOW
, // Searches for an item below the specified item
126 wxLIST_NEXT_LEFT
, // Searches for an item to the left of the specified item
127 wxLIST_NEXT_RIGHT
// Searches for an item to the right of the specified item
130 // Alignment flags for Arrange // always wxLIST_ALIGN_LEFT in wxGLC
132 wxLIST_ALIGN_DEFAULT
,
135 wxLIST_ALIGN_SNAP_TO_GRID
138 // Column format // always wxLIST_FORMAT_LEFT in wxGLC
142 wxLIST_FORMAT_CENTRE
,
143 wxLIST_FORMAT_CENTER
= wxLIST_FORMAT_CENTRE
146 // Autosize values for SetColumnWidth
148 wxLIST_AUTOSIZE
= -1, // width of longest item
149 wxLIST_AUTOSIZE_USEHEADER
= -2 // always 80 in wxGLC
152 // Flag values for GetItemRect
159 // Flag values for FindItem // not supported by wxGLC
167 //-----------------------------------------------------------------------------
169 //-----------------------------------------------------------------------------
171 class WXDLLEXPORT wxListItem
: public wxObject
173 DECLARE_DYNAMIC_CLASS(wxListItem
)
176 long m_mask
; // Indicates what fields are valid
177 long m_itemId
; // The zero-based item position
178 int m_col
; // Zero-based column, if in report mode
179 long m_state
; // The state of the item
180 long m_stateMask
; // Which flags of m_state are valid (uses same flags)
181 wxString m_text
; // The label/header text
182 int m_image
; // The zero-based index into an image list
183 long m_data
; // App-defined data
184 wxColour
*m_colour
; // only wxGLC, not supported by Windows ;->
187 int m_format
; // left, right, centre
188 int m_width
; // width of column
193 //-----------------------------------------------------------------------------
194 // wxListItemData (internal)
195 //-----------------------------------------------------------------------------
197 class WXDLLEXPORT wxListItemData
: public wxObject
199 DECLARE_DYNAMIC_CLASS(wxListItemData
);
206 int m_width
,m_height
;
210 wxListItemData(void);
211 wxListItemData( const wxListItem
&info
);
212 void SetItem( const wxListItem
&info
);
213 void SetText( const wxString
&s
);
214 void SetImage( int image
);
215 void SetData( long data
);
216 void SetPosition( int x
, int y
);
217 void SetSize( int width
, int height
);
218 void SetColour( wxColour
*col
);
219 bool HasImage(void) const;
220 bool HasText(void) const;
221 bool IsHit( int x
, int y
) const;
222 void GetText( wxString
&s
);
223 int GetX( void ) const;
224 int GetY( void ) const;
225 int GetWidth(void) const;
226 int GetHeight(void) const;
227 int GetImage(void) const;
228 void GetItem( wxListItem
&info
);
229 wxColour
*GetColour(void);
232 //-----------------------------------------------------------------------------
233 // wxListHeaderData (internal)
234 //-----------------------------------------------------------------------------
236 class WXDLLEXPORT wxListHeaderData
: public wxObject
238 DECLARE_DYNAMIC_CLASS(wxListHeaderData
);
250 wxListHeaderData(void);
251 wxListHeaderData( const wxListItem
&info
);
252 void SetItem( const wxListItem
&item
);
253 void SetPosition( int x
, int y
);
254 void SetWidth( int w
);
255 void SetFormat( int format
);
256 void SetHeight( int h
);
257 bool HasImage(void) const;
258 bool HasText(void) const;
259 bool IsHit( int x
, int y
) const;
260 void GetItem( wxListItem
&item
);
261 void GetText( wxString
&s
);
262 int GetImage(void) const;
263 int GetWidth(void) const;
264 int GetFormat(void) const;
267 //-----------------------------------------------------------------------------
268 // wxListLineData (internal)
269 //-----------------------------------------------------------------------------
271 class WXDLLEXPORT wxListLineData
: public wxObject
273 DECLARE_DYNAMIC_CLASS(wxListLineData
);
278 wxRect m_bound_label
;
280 wxRect m_bound_hilight
;
283 wxBrush
*m_hilightBrush
;
285 wxListMainWindow
*m_owner
;
287 void DoDraw( wxDC
*dc
, bool hilight
, bool paintBG
);
290 wxListLineData( void ) {};
291 wxListLineData( wxListMainWindow
*owner
, int mode
, wxBrush
*hilightBrush
);
292 void CalculateSize( wxDC
*dc
, int spacing
);
293 void SetPosition( wxDC
*dc
, int x
, int y
, int window_width
);
294 void SetColumnPosition( int index
, int x
);
295 void GetSize( int &width
, int &height
);
296 void GetExtent( int &x
, int &y
, int &width
, int &height
);
297 void GetLabelExtent( int &x
, int &y
, int &width
, int &height
);
298 long IsHit( int x
, int y
);
299 void InitItems( int num
);
300 void SetItem( int index
, const wxListItem
&info
);
301 void GetItem( int index
, wxListItem
&info
);
302 void GetText( int index
, wxString
&s
);
303 void SetText( int index
, const wxString s
);
304 int GetImage( int index
);
305 void GetRect( wxRect
&rect
);
306 void Hilight( bool on
);
307 void ReverseHilight( void );
308 void DrawRubberBand( wxDC
*dc
, bool on
);
309 void Draw( wxDC
*dc
);
310 bool IsInRect( int x
, int y
, const wxRect
&rect
);
311 bool IsHilighted( void );
312 void AssignRect( wxRect
&dest
, int x
, int y
, int width
, int height
);
313 void AssignRect( wxRect
&dest
, const wxRect
&source
);
316 //-----------------------------------------------------------------------------
317 // wxListHeaderWindow (internal)
318 //-----------------------------------------------------------------------------
320 class WXDLLEXPORT wxListHeaderWindow
: public wxWindow
322 DECLARE_DYNAMIC_CLASS(wxListHeaderWindow
)
325 wxListMainWindow
*m_owner
;
326 wxCursor
*m_currentCursor
;
327 wxCursor
*m_resizeCursor
;
334 wxListHeaderWindow( void );
335 ~wxListHeaderWindow( void );
336 wxListHeaderWindow( wxWindow
*win
, wxWindowID id
, wxListMainWindow
*owner
,
337 const wxPoint
&pos
= wxDefaultPosition
, const wxSize
&size
= wxDefaultSize
,
338 long style
= 0, const wxString
&name
= "columntitles" );
339 void DoDrawRect( wxDC
*dc
, int x
, int y
, int w
, int h
);
340 void OnPaint( wxPaintEvent
&event
);
342 void OnMouse( wxMouseEvent
&event
);
343 void OnSetFocus( wxFocusEvent
&event
);
345 DECLARE_EVENT_TABLE()
348 //-----------------------------------------------------------------------------
349 // wxListRenameTimer (internal)
350 //-----------------------------------------------------------------------------
352 class WXDLLEXPORT wxListRenameTimer
: public wxTimer
355 wxListMainWindow
*m_owner
;
358 wxListRenameTimer( wxListMainWindow
*owner
);
362 //-----------------------------------------------------------------------------
363 // wxListTextCtrl (internal)
364 //-----------------------------------------------------------------------------
366 class WXDLLEXPORT wxListTextCtrl
: public wxTextCtrl
368 DECLARE_DYNAMIC_CLASS(wxListTextCtrl
);
373 wxListMainWindow
*m_owner
;
374 wxString m_startValue
;
377 wxListTextCtrl(void) {};
378 wxListTextCtrl( wxWindow
*parent
, const wxWindowID id
,
379 bool *accept
, wxString
*res
, wxListMainWindow
*owner
,
380 const wxString
&value
= "",
381 const wxPoint
&pos
= wxDefaultPosition
, const wxSize
&size
= wxDefaultSize
,
382 int style
= 0, const wxValidator
& validator
= wxDefaultValidator
,
383 const wxString
&name
= "wxListTextCtrlText" );
384 void OnChar( wxKeyEvent
&event
);
385 void OnKillFocus( wxFocusEvent
&event
);
387 DECLARE_EVENT_TABLE()
390 //-----------------------------------------------------------------------------
391 // wxListMainWindow (internal)
392 //-----------------------------------------------------------------------------
394 class WXDLLEXPORT wxListMainWindow
: public wxScrolledWindow
396 DECLARE_DYNAMIC_CLASS(wxListMainWindow
);
402 wxListLineData
*m_current
;
403 wxListLineData
*m_currentEdit
;
405 wxBrush
*m_hilightBrush
;
406 wxColour
*m_hilightColour
;
407 int m_xScroll
,m_yScroll
;
409 wxImageList
*m_small_image_list
;
410 wxImageList
*m_normal_image_list
;
412 int m_normal_spacing
;
416 wxTimer
*m_renameTimer
;
418 wxString m_renameRes
;
424 wxListMainWindow( wxWindow
*parent
, wxWindowID id
,
425 const wxPoint
&pos
= wxDefaultPosition
, const wxSize
&size
= wxDefaultSize
,
426 long style
= 0, const wxString
&name
= "listctrl" );
428 void RefreshLine( wxListLineData
*line
);
429 void OnPaint( wxPaintEvent
&event
);
430 void HilightAll( bool on
);
431 void SendNotify( wxListLineData
*line
, wxEventType command
);
432 void FocusLine( wxListLineData
*line
);
433 void UnfocusLine( wxListLineData
*line
);
434 void SelectLine( wxListLineData
*line
);
435 void DeselectLine( wxListLineData
*line
);
436 void DeleteLine( wxListLineData
*line
);
438 void EditLabel( long item
);
439 void Edit( long item
) { EditLabel(item
); } // deprecated
440 void OnRenameTimer();
441 void OnRenameAccept();
443 void OnMouse( wxMouseEvent
&event
);
445 void OnArrowChar( wxListLineData
*newCurrent
, bool shiftDown
);
446 void OnChar( wxKeyEvent
&event
);
447 void OnKeyDown( wxKeyEvent
&event
);
448 void OnSetFocus( wxFocusEvent
&event
);
449 void OnKillFocus( wxFocusEvent
&event
);
450 void OnSize( wxSizeEvent
&event
);
452 void DrawImage( int index
, wxDC
*dc
, int x
, int y
);
453 void GetImageSize( int index
, int &width
, int &height
);
454 int GetIndexOfLine( const wxListLineData
*line
);
455 int GetTextLength( wxString
&s
); // should be const
457 void SetImageList( wxImageList
*imageList
, int which
);
458 void SetItemSpacing( int spacing
, bool isSmall
= FALSE
);
459 int GetItemSpacing( bool isSmall
= FALSE
);
460 void SetColumn( int col
, wxListItem
&item
);
461 void SetColumnWidth( int col
, int width
);
462 void GetColumn( int col
, wxListItem
&item
);
463 int GetColumnWidth( int vol
);
464 int GetColumnCount();
465 int GetCountPerPage();
466 void SetItem( wxListItem
&item
);
467 void GetItem( wxListItem
&item
);
468 void SetItemState( long item
, long state
, long stateMask
);
469 int GetItemState( long item
, long stateMask
);
471 void GetItemRect( long index
, wxRect
&rect
);
472 bool GetItemPosition( long item
, wxPoint
& pos
);
473 int GetSelectedItemCount();
474 void SetMode( long mode
);
475 long GetMode() const;
476 void CalculatePositions();
477 void RealizeChanges();
478 long GetNextItem( long item
, int geometry
, int state
);
479 void DeleteItem( long index
);
480 void DeleteAllItems();
481 void DeleteColumn( int col
);
482 void DeleteEverything();
483 void EnsureVisible( long index
);
484 long FindItem( long start
, const wxString
& str
, bool partial
= FALSE
);
485 long FindItem( long start
, long data
);
486 long HitTest( int x
, int y
, int &flags
);
487 void InsertItem( wxListItem
&item
);
488 // void AddItem( wxListItem &item );
489 void InsertColumn( long col
, wxListItem
&item
);
490 // void AddColumn( wxListItem &item );
491 void SortItems( wxListCtrlCompare fn
, long data
);
493 DECLARE_EVENT_TABLE()
496 //-----------------------------------------------------------------------------
498 //-----------------------------------------------------------------------------
500 class WXDLLEXPORT wxListCtrl
: public wxControl
502 DECLARE_DYNAMIC_CLASS(wxListCtrl
);
506 wxListCtrl( wxWindow
*parent
, wxWindowID id
= -1,
507 const wxPoint
&pos
= wxDefaultPosition
, const wxSize
&size
= wxDefaultSize
,
508 long style
= wxLC_ICON
, const wxValidator
& validator
= wxDefaultValidator
,
509 const wxString
&name
= "listctrl" )
511 Create(parent
, id
, pos
, size
, style
, validator
, name
);
514 bool Create( wxWindow
*parent
, wxWindowID id
= -1,
515 const wxPoint
&pos
= wxDefaultPosition
, const wxSize
&size
= wxDefaultSize
,
516 long style
= wxLC_ICON
, const wxValidator
& validator
= wxDefaultValidator
,
517 const wxString
&name
= "listctrl" );
518 void OnSize( wxSizeEvent
&event
);
519 bool GetColumn( int col
, wxListItem
& item
) const;
520 bool SetColumn( int col
, wxListItem
& item
);
521 int GetColumnWidth( int col
) const;
522 bool SetColumnWidth( int col
, int width
);
523 int GetCountPerPage() const; // not the same in wxGLC as in Windows, I think
524 bool GetItem( wxListItem
& info
) const;
525 bool SetItem( wxListItem
& info
) ;
526 long SetItem( long index
, int col
, const wxString
& label
, int imageId
= -1 );
527 int GetItemState( long item
, long stateMask
) const;
528 bool SetItemState( long item
, long state
, long stateMask
);
529 bool SetItemImage( long item
, int image
, int selImage
);
530 wxString
GetItemText( long item
) const;
531 void SetItemText( long item
, const wxString
& str
);
532 long GetItemData( long item
) const;
533 bool SetItemData( long item
, long data
);
534 bool GetItemRect( long item
, wxRect
& rect
, int code
= wxLIST_RECT_BOUNDS
) const;
535 bool GetItemPosition( long item
, wxPoint
& pos
) const;
536 bool SetItemPosition( long item
, const wxPoint
& pos
); // not supported in wxGLC
537 int GetItemCount() const;
538 int GetColumnCount() const;
539 void SetItemSpacing( int spacing
, bool isSmall
= FALSE
);
540 int GetItemSpacing( bool isSmall
) const;
541 int GetSelectedItemCount() const;
542 // wxColour GetTextColour() const; // wxGLC has colours for every Item (see wxListItem)
543 // void SetTextColour(const wxColour& col);
544 long GetTopItem() const;
545 void SetSingleStyle( long style
, bool add
= TRUE
) ;
546 void SetWindowStyleFlag( long style
);
547 void RecreateWindow() {}
548 long GetNextItem( long item
, int geometry
= wxLIST_NEXT_ALL
, int state
= wxLIST_STATE_DONTCARE
) const;
549 wxImageList
*GetImageList( int which
) const;
550 void SetImageList( wxImageList
*imageList
, int which
);
551 bool Arrange( int flag
= wxLIST_ALIGN_DEFAULT
); // always wxLIST_ALIGN_LEFT in wxGLC
554 bool DeleteItem( long item
);
555 bool DeleteAllItems();
556 bool DeleteAllColumns();
557 bool DeleteColumn( int col
);
559 void EditLabel( long item
) { Edit(item
); }
560 void Edit( long item
);
562 bool EnsureVisible( long item
);
563 long FindItem( long start
, const wxString
& str
, bool partial
= FALSE
);
564 long FindItem( long start
, long data
);
565 long FindItem( long start
, const wxPoint
& pt
, int direction
); // not supported in wxGLC
566 long HitTest( const wxPoint
& point
, int& flags
);
567 long InsertItem(wxListItem
& info
);
568 long InsertItem( long index
, const wxString
& label
);
569 long InsertItem( long index
, int imageIndex
);
570 long InsertItem( long index
, const wxString
& label
, int imageIndex
);
571 long InsertColumn( long col
, wxListItem
& info
);
572 long InsertColumn( long col
, const wxString
& heading
, int format
= wxLIST_FORMAT_LEFT
,
574 bool ScrollList( int dx
, int dy
);
575 bool SortItems( wxListCtrlCompare fn
, long data
);
576 bool Update( long item
);
577 void OnIdle( wxIdleEvent
&event
);
579 // We have to hand down a few functions
581 bool SetBackgroundColour( const wxColour
&colour
);
582 bool SetForegroundColour( const wxColour
&colour
);
583 bool SetFont( const wxFont
&font
);
585 #if wxUSE_DRAG_AND_DROP
586 void SetDropTarget( wxDropTarget
*dropTarget
)
587 { m_mainWin
->SetDropTarget( dropTarget
); }
588 wxDropTarget
*GetDropTarget() const
589 { return m_mainWin
->GetDropTarget(); }
592 bool SetCursor( const wxCursor
&cursor
)
593 { return m_mainWin
? m_mainWin
->wxWindow::SetCursor(cursor
) : FALSE
; }
594 wxColour
GetBackgroundColour() const
595 { return m_mainWin
? m_mainWin
->GetBackgroundColour() : wxColour(); }
596 wxColour
GetForegroundColour() const
597 { return m_mainWin
? m_mainWin
->GetForegroundColour() : wxColour(); }
598 bool DoPopupMenu( wxMenu
*menu
, int x
, int y
)
599 { return m_mainWin
->PopupMenu( menu
, x
, y
); }
601 { m_mainWin
->SetFocus(); }
605 wxImageList
*m_imageListNormal
;
606 wxImageList
*m_imageListSmall
;
607 wxImageList
*m_imageListState
; // what's that ?
608 wxListHeaderWindow
*m_headerWin
;
609 wxListMainWindow
*m_mainWin
;
611 DECLARE_EVENT_TABLE()
616 #endif // __LISTCTRLH_G__