1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/generic/listctrl.h
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 //-----------------------------------------------------------------------------
55 // wxListItemData (internal)
56 //-----------------------------------------------------------------------------
58 class WXDLLEXPORT wxListItemData
: public wxObject
67 wxListItemAttr
*m_attr
;
71 ~wxListItemData() { delete m_attr
; }
73 wxListItemData( const wxListItem
&info
);
74 void SetItem( const wxListItem
&info
);
75 void SetText( const wxString
&s
);
76 void SetImage( int image
);
77 void SetData( long data
);
78 void SetPosition( int x
, int y
);
79 void SetSize( int width
, int height
);
80 bool HasImage() const;
82 bool IsHit( int x
, int y
) const;
83 void GetText( wxString
&s
);
84 const wxString
& GetText() { return m_text
; }
85 int GetX( void ) const;
86 int GetY( void ) const;
88 int GetHeight() const;
90 void GetItem( wxListItem
&info
) const;
92 wxListItemAttr
*GetAttributes() const { return m_attr
; }
95 DECLARE_DYNAMIC_CLASS(wxListItemData
);
98 //-----------------------------------------------------------------------------
99 // wxListHeaderData (internal)
100 //-----------------------------------------------------------------------------
102 class WXDLLEXPORT wxListHeaderData
: public wxObject
115 wxListHeaderData( const wxListItem
&info
);
116 void SetItem( const wxListItem
&item
);
117 void SetPosition( int x
, int y
);
118 void SetWidth( int w
);
119 void SetFormat( int format
);
120 void SetHeight( int h
);
121 bool HasImage() const;
122 bool HasText() const;
123 bool IsHit( int x
, int y
) const;
124 void GetItem( wxListItem
&item
);
125 void GetText( wxString
&s
);
126 int GetImage() const;
127 int GetWidth() const;
128 int GetFormat() const;
131 DECLARE_DYNAMIC_CLASS(wxListHeaderData
);
134 //-----------------------------------------------------------------------------
135 // wxListLineData (internal)
136 //-----------------------------------------------------------------------------
138 class WXDLLEXPORT wxListLineData
: public wxObject
143 wxRect m_bound_label
;
145 wxRect m_bound_hilight
;
148 wxBrush
*m_hilightBrush
;
150 wxListMainWindow
*m_owner
;
152 void DoDraw( wxDC
*dc
, bool hilight
, bool paintBG
);
156 wxListLineData( wxListMainWindow
*owner
, int mode
, wxBrush
*hilightBrush
);
157 void CalculateSize( wxDC
*dc
, int spacing
);
158 void SetPosition( wxDC
*dc
, int x
, int y
, int window_width
);
159 void SetColumnPosition( int index
, int x
);
160 void GetSize( int &width
, int &height
);
161 void GetExtent( int &x
, int &y
, int &width
, int &height
);
162 void GetLabelExtent( int &x
, int &y
, int &width
, int &height
);
163 long IsHit( int x
, int y
);
164 void InitItems( int num
);
165 void SetItem( int index
, const wxListItem
&info
);
166 void GetItem( int index
, wxListItem
&info
);
167 void GetText( int index
, wxString
&s
);
168 void SetText( int index
, const wxString s
);
169 int GetImage( int index
);
170 void GetRect( wxRect
&rect
);
171 void Hilight( bool on
);
172 void ReverseHilight();
173 void DrawRubberBand( wxDC
*dc
, bool on
);
174 void Draw( wxDC
*dc
);
175 bool IsInRect( int x
, int y
, const wxRect
&rect
);
177 void AssignRect( wxRect
&dest
, int x
, int y
, int width
, int height
);
178 void AssignRect( wxRect
&dest
, const wxRect
&source
);
181 void SetAttributes(wxDC
*dc
,
182 const wxListItemAttr
*attr
,
183 const wxColour
& colText
, const wxFont
& font
);
185 DECLARE_DYNAMIC_CLASS(wxListLineData
);
188 //-----------------------------------------------------------------------------
189 // wxListHeaderWindow (internal)
190 //-----------------------------------------------------------------------------
192 class WXDLLEXPORT wxListHeaderWindow
: public wxWindow
195 wxListMainWindow
*m_owner
;
196 wxCursor
*m_currentCursor
;
197 wxCursor
*m_resizeCursor
;
204 wxListHeaderWindow();
205 ~wxListHeaderWindow();
206 wxListHeaderWindow( wxWindow
*win
, wxWindowID id
, wxListMainWindow
*owner
,
207 const wxPoint
&pos
= wxDefaultPosition
, const wxSize
&size
= wxDefaultSize
,
208 long style
= 0, const wxString
&name
= "columntitles" );
209 void DoDrawRect( wxDC
*dc
, int x
, int y
, int w
, int h
);
210 void OnPaint( wxPaintEvent
&event
);
212 void OnMouse( wxMouseEvent
&event
);
213 void OnSetFocus( wxFocusEvent
&event
);
216 DECLARE_DYNAMIC_CLASS(wxListHeaderWindow
)
217 DECLARE_EVENT_TABLE()
220 //-----------------------------------------------------------------------------
221 // wxListRenameTimer (internal)
222 //-----------------------------------------------------------------------------
224 class WXDLLEXPORT wxListRenameTimer
: public wxTimer
227 wxListMainWindow
*m_owner
;
230 wxListRenameTimer( wxListMainWindow
*owner
);
234 //-----------------------------------------------------------------------------
235 // wxListTextCtrl (internal)
236 //-----------------------------------------------------------------------------
238 class WXDLLEXPORT wxListTextCtrl
: public wxTextCtrl
243 wxListMainWindow
*m_owner
;
244 wxString m_startValue
;
248 wxListTextCtrl( wxWindow
*parent
, const wxWindowID id
,
249 bool *accept
, wxString
*res
, wxListMainWindow
*owner
,
250 const wxString
&value
= "",
251 const wxPoint
&pos
= wxDefaultPosition
, const wxSize
&size
= wxDefaultSize
,
254 const wxValidator
& validator
= wxDefaultValidator
,
256 const wxString
&name
= "wxListTextCtrlText" );
257 void OnChar( wxKeyEvent
&event
);
258 void OnKillFocus( wxFocusEvent
&event
);
261 DECLARE_DYNAMIC_CLASS(wxListTextCtrl
);
262 DECLARE_EVENT_TABLE()
265 //-----------------------------------------------------------------------------
266 // wxListMainWindow (internal)
267 //-----------------------------------------------------------------------------
269 class WXDLLEXPORT wxListMainWindow
: public wxScrolledWindow
275 wxListLineData
*m_current
;
276 wxListLineData
*m_currentEdit
;
278 wxBrush
*m_hilightBrush
;
279 wxColour
*m_hilightColour
;
280 int m_xScroll
,m_yScroll
;
282 wxImageList
*m_small_image_list
;
283 wxImageList
*m_normal_image_list
;
285 int m_normal_spacing
;
289 wxTimer
*m_renameTimer
;
291 wxString m_renameRes
;
298 wxListMainWindow( wxWindow
*parent
, wxWindowID id
,
299 const wxPoint
&pos
= wxDefaultPosition
, const wxSize
&size
= wxDefaultSize
,
300 long style
= 0, const wxString
&name
= "listctrl" );
302 void RefreshLine( wxListLineData
*line
);
303 void OnPaint( wxPaintEvent
&event
);
304 void HilightAll( bool on
);
305 void SendNotify( wxListLineData
*line
, wxEventType command
);
306 void FocusLine( wxListLineData
*line
);
307 void UnfocusLine( wxListLineData
*line
);
308 void SelectLine( wxListLineData
*line
);
309 void DeselectLine( wxListLineData
*line
);
310 void DeleteLine( wxListLineData
*line
);
312 void EditLabel( long item
);
313 void Edit( long item
) { EditLabel(item
); } // deprecated
314 void OnRenameTimer();
315 void OnRenameAccept();
317 void OnMouse( wxMouseEvent
&event
);
319 void OnArrowChar( wxListLineData
*newCurrent
, bool shiftDown
);
320 void OnChar( wxKeyEvent
&event
);
321 void OnKeyDown( wxKeyEvent
&event
);
322 void OnSetFocus( wxFocusEvent
&event
);
323 void OnKillFocus( wxFocusEvent
&event
);
324 void OnSize( wxSizeEvent
&event
);
325 void OnScroll(wxScrollWinEvent
& event
) ;
327 void DrawImage( int index
, wxDC
*dc
, int x
, int y
);
328 void GetImageSize( int index
, int &width
, int &height
);
329 int GetIndexOfLine( const wxListLineData
*line
);
330 int GetTextLength( wxString
&s
); // should be const
332 void SetImageList( wxImageList
*imageList
, int which
);
333 void SetItemSpacing( int spacing
, bool isSmall
= FALSE
);
334 int GetItemSpacing( bool isSmall
= FALSE
);
335 void SetColumn( int col
, wxListItem
&item
);
336 void SetColumnWidth( int col
, int width
);
337 void GetColumn( int col
, wxListItem
&item
);
338 int GetColumnWidth( int vol
);
339 int GetColumnCount();
340 int GetCountPerPage();
341 void SetItem( wxListItem
&item
);
342 void GetItem( wxListItem
&item
);
343 void SetItemState( long item
, long state
, long stateMask
);
344 int GetItemState( long item
, long stateMask
);
346 void GetItemRect( long index
, wxRect
&rect
);
347 bool GetItemPosition( long item
, wxPoint
& pos
);
348 int GetSelectedItemCount();
349 void SetMode( long mode
);
350 long GetMode() const;
351 void CalculatePositions();
352 void RealizeChanges();
353 long GetNextItem( long item
, int geometry
, int state
);
354 void DeleteItem( long index
);
355 void DeleteAllItems();
356 void DeleteColumn( int col
);
357 void DeleteEverything();
358 void EnsureVisible( long index
);
359 long FindItem( long start
, const wxString
& str
, bool partial
= FALSE
);
360 long FindItem( long start
, long data
);
361 long HitTest( int x
, int y
, int &flags
);
362 void InsertItem( wxListItem
&item
);
363 // void AddItem( wxListItem &item );
364 void InsertColumn( long col
, wxListItem
&item
);
365 // void AddColumn( wxListItem &item );
366 void SortItems( wxListCtrlCompare fn
, long data
);
369 DECLARE_DYNAMIC_CLASS(wxListMainWindow
);
370 DECLARE_EVENT_TABLE()
373 //-----------------------------------------------------------------------------
375 //-----------------------------------------------------------------------------
377 class WXDLLEXPORT wxListCtrl
: public wxControl
381 wxListCtrl( wxWindow
*parent
, wxWindowID id
= -1,
382 const wxPoint
&pos
= wxDefaultPosition
, const wxSize
&size
= wxDefaultSize
,
384 long style
= wxLC_ICON
, const wxValidator
& validator
= wxDefaultValidator
,
386 const wxString
&name
= "listctrl" )
388 Create(parent
, id
, pos
, size
, style
, validator
, name
);
392 bool Create( wxWindow
*parent
, wxWindowID id
= -1,
393 const wxPoint
&pos
= wxDefaultPosition
, const wxSize
&size
= wxDefaultSize
,
395 long style
= wxLC_ICON
, const wxValidator
& validator
= wxDefaultValidator
,
397 const wxString
&name
= "listctrl" );
399 bool GetColumn( int col
, wxListItem
& item
) const;
400 bool SetColumn( int col
, wxListItem
& item
);
401 int GetColumnWidth( int col
) const;
402 bool SetColumnWidth( int col
, int width
);
403 int GetCountPerPage() const; // not the same in wxGLC as in Windows, I think
405 bool GetItem( wxListItem
& info
) const;
406 bool SetItem( wxListItem
& info
) ;
407 long SetItem( long index
, int col
, const wxString
& label
, int imageId
= -1 );
408 int GetItemState( long item
, long stateMask
) const;
409 bool SetItemState( long item
, long state
, long stateMask
);
410 bool SetItemImage( long item
, int image
, int selImage
);
411 wxString
GetItemText( long item
) const;
412 void SetItemText( long item
, const wxString
& str
);
413 long GetItemData( long item
) const;
414 bool SetItemData( long item
, long data
);
415 bool GetItemRect( long item
, wxRect
& rect
, int code
= wxLIST_RECT_BOUNDS
) const;
416 bool GetItemPosition( long item
, wxPoint
& pos
) const;
417 bool SetItemPosition( long item
, const wxPoint
& pos
); // not supported in wxGLC
418 int GetItemCount() const;
419 int GetColumnCount() const;
420 void SetItemSpacing( int spacing
, bool isSmall
= FALSE
);
421 int GetItemSpacing( bool isSmall
) const;
422 int GetSelectedItemCount() const;
423 wxColour
GetTextColour() const;
424 void SetTextColour(const wxColour
& col
);
425 long GetTopItem() const;
427 void SetSingleStyle( long style
, bool add
= TRUE
) ;
428 void SetWindowStyleFlag( long style
);
429 void RecreateWindow() {}
430 long GetNextItem( long item
, int geometry
= wxLIST_NEXT_ALL
, int state
= wxLIST_STATE_DONTCARE
) const;
431 wxImageList
*GetImageList( int which
) const;
432 void SetImageList( wxImageList
*imageList
, int which
);
433 bool Arrange( int flag
= wxLIST_ALIGN_DEFAULT
); // always wxLIST_ALIGN_LEFT in wxGLC
436 bool DeleteItem( long item
);
437 bool DeleteAllItems();
438 bool DeleteAllColumns();
439 bool DeleteColumn( int col
);
441 void EditLabel( long item
) { Edit(item
); }
442 void Edit( long item
);
444 bool EnsureVisible( long item
);
445 long FindItem( long start
, const wxString
& str
, bool partial
= FALSE
);
446 long FindItem( long start
, long data
);
447 long FindItem( long start
, const wxPoint
& pt
, int direction
); // not supported in wxGLC
448 long HitTest( const wxPoint
& point
, int& flags
);
449 long InsertItem(wxListItem
& info
);
450 long InsertItem( long index
, const wxString
& label
);
451 long InsertItem( long index
, int imageIndex
);
452 long InsertItem( long index
, const wxString
& label
, int imageIndex
);
453 long InsertColumn( long col
, wxListItem
& info
);
454 long InsertColumn( long col
, const wxString
& heading
, int format
= wxLIST_FORMAT_LEFT
,
456 bool ScrollList( int dx
, int dy
);
457 bool SortItems( wxListCtrlCompare fn
, long data
);
458 bool Update( long item
);
460 void OnIdle( wxIdleEvent
&event
);
461 void OnSize( wxSizeEvent
&event
);
463 // We have to hand down a few functions
465 bool SetBackgroundColour( const wxColour
&colour
);
466 bool SetForegroundColour( const wxColour
&colour
);
467 bool SetFont( const wxFont
&font
);
469 #if wxUSE_DRAG_AND_DROP
470 void SetDropTarget( wxDropTarget
*dropTarget
)
471 { m_mainWin
->SetDropTarget( dropTarget
); }
472 wxDropTarget
*GetDropTarget() const
473 { return m_mainWin
->GetDropTarget(); }
476 bool SetCursor( const wxCursor
&cursor
)
477 { return m_mainWin
? m_mainWin
->wxWindow::SetCursor(cursor
) : FALSE
; }
478 wxColour
GetBackgroundColour() const
479 { return m_mainWin
? m_mainWin
->GetBackgroundColour() : wxColour(); }
480 wxColour
GetForegroundColour() const
481 { return m_mainWin
? m_mainWin
->GetForegroundColour() : wxColour(); }
482 bool DoPopupMenu( wxMenu
*menu
, int x
, int y
)
483 { return m_mainWin
->PopupMenu( menu
, x
, y
); }
486 /* The test in window.cpp fails as we are a composite
487 window, so it checks against "this", but not m_mainWin. */
488 if (FindFocus() != this)
489 m_mainWin
->SetFocus();
495 wxImageList
*m_imageListNormal
;
496 wxImageList
*m_imageListSmall
;
497 wxImageList
*m_imageListState
; // what's that ?
498 wxListHeaderWindow
*m_headerWin
;
499 wxListMainWindow
*m_mainWin
;
502 DECLARE_EVENT_TABLE()
503 DECLARE_DYNAMIC_CLASS(wxListCtrl
);
507 #endif // __LISTCTRLH_G__