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
,
186 DECLARE_DYNAMIC_CLASS(wxListLineData
);
189 //-----------------------------------------------------------------------------
190 // wxListHeaderWindow (internal)
191 //-----------------------------------------------------------------------------
193 class WXDLLEXPORT wxListHeaderWindow
: public wxWindow
196 wxListMainWindow
*m_owner
;
197 wxCursor
*m_currentCursor
;
198 wxCursor
*m_resizeCursor
;
205 wxListHeaderWindow();
206 ~wxListHeaderWindow();
207 wxListHeaderWindow( wxWindow
*win
, wxWindowID id
, wxListMainWindow
*owner
,
208 const wxPoint
&pos
= wxDefaultPosition
, const wxSize
&size
= wxDefaultSize
,
209 long style
= 0, const wxString
&name
= "columntitles" );
210 void DoDrawRect( wxDC
*dc
, int x
, int y
, int w
, int h
);
211 void OnPaint( wxPaintEvent
&event
);
213 void OnMouse( wxMouseEvent
&event
);
214 void OnSetFocus( wxFocusEvent
&event
);
217 DECLARE_DYNAMIC_CLASS(wxListHeaderWindow
)
218 DECLARE_EVENT_TABLE()
221 //-----------------------------------------------------------------------------
222 // wxListRenameTimer (internal)
223 //-----------------------------------------------------------------------------
225 class WXDLLEXPORT wxListRenameTimer
: public wxTimer
228 wxListMainWindow
*m_owner
;
231 wxListRenameTimer( wxListMainWindow
*owner
);
235 //-----------------------------------------------------------------------------
236 // wxListTextCtrl (internal)
237 //-----------------------------------------------------------------------------
239 class WXDLLEXPORT wxListTextCtrl
: public wxTextCtrl
244 wxListMainWindow
*m_owner
;
245 wxString m_startValue
;
249 wxListTextCtrl( wxWindow
*parent
, const wxWindowID id
,
250 bool *accept
, wxString
*res
, wxListMainWindow
*owner
,
251 const wxString
&value
= "",
252 const wxPoint
&pos
= wxDefaultPosition
, const wxSize
&size
= wxDefaultSize
,
255 const wxValidator
& validator
= wxDefaultValidator
,
257 const wxString
&name
= "wxListTextCtrlText" );
258 void OnChar( wxKeyEvent
&event
);
259 void OnKillFocus( wxFocusEvent
&event
);
262 DECLARE_DYNAMIC_CLASS(wxListTextCtrl
);
263 DECLARE_EVENT_TABLE()
266 //-----------------------------------------------------------------------------
267 // wxListMainWindow (internal)
268 //-----------------------------------------------------------------------------
270 class WXDLLEXPORT wxListMainWindow
: public wxScrolledWindow
276 wxListLineData
*m_current
;
277 wxListLineData
*m_currentEdit
;
279 wxBrush
*m_hilightBrush
;
280 wxColour
*m_hilightColour
;
281 int m_xScroll
,m_yScroll
;
283 wxImageList
*m_small_image_list
;
284 wxImageList
*m_normal_image_list
;
286 int m_normal_spacing
;
290 wxTimer
*m_renameTimer
;
292 wxString m_renameRes
;
299 wxListMainWindow( wxWindow
*parent
, wxWindowID id
,
300 const wxPoint
&pos
= wxDefaultPosition
, const wxSize
&size
= wxDefaultSize
,
301 long style
= 0, const wxString
&name
= "listctrl" );
303 void RefreshLine( wxListLineData
*line
);
304 void OnPaint( wxPaintEvent
&event
);
305 void HilightAll( bool on
);
306 void SendNotify( wxListLineData
*line
, wxEventType command
);
307 void FocusLine( wxListLineData
*line
);
308 void UnfocusLine( wxListLineData
*line
);
309 void SelectLine( wxListLineData
*line
);
310 void DeselectLine( wxListLineData
*line
);
311 void DeleteLine( wxListLineData
*line
);
313 void EditLabel( long item
);
314 void Edit( long item
) { EditLabel(item
); } // deprecated
315 void OnRenameTimer();
316 void OnRenameAccept();
318 void OnMouse( wxMouseEvent
&event
);
320 void OnArrowChar( wxListLineData
*newCurrent
, bool shiftDown
);
321 void OnChar( wxKeyEvent
&event
);
322 void OnKeyDown( wxKeyEvent
&event
);
323 void OnSetFocus( wxFocusEvent
&event
);
324 void OnKillFocus( wxFocusEvent
&event
);
325 void OnSize( wxSizeEvent
&event
);
326 void OnScroll(wxScrollWinEvent
& event
) ;
328 void DrawImage( int index
, wxDC
*dc
, int x
, int y
);
329 void GetImageSize( int index
, int &width
, int &height
);
330 int GetIndexOfLine( const wxListLineData
*line
);
331 int GetTextLength( wxString
&s
); // should be const
333 void SetImageList( wxImageList
*imageList
, int which
);
334 void SetItemSpacing( int spacing
, bool isSmall
= FALSE
);
335 int GetItemSpacing( bool isSmall
= FALSE
);
336 void SetColumn( int col
, wxListItem
&item
);
337 void SetColumnWidth( int col
, int width
);
338 void GetColumn( int col
, wxListItem
&item
);
339 int GetColumnWidth( int vol
);
340 int GetColumnCount();
341 int GetCountPerPage();
342 void SetItem( wxListItem
&item
);
343 void GetItem( wxListItem
&item
);
344 void SetItemState( long item
, long state
, long stateMask
);
345 int GetItemState( long item
, long stateMask
);
347 void GetItemRect( long index
, wxRect
&rect
);
348 bool GetItemPosition( long item
, wxPoint
& pos
);
349 int GetSelectedItemCount();
350 void SetMode( long mode
);
351 long GetMode() const;
352 void CalculatePositions();
353 void RealizeChanges();
354 long GetNextItem( long item
, int geometry
, int state
);
355 void DeleteItem( long index
);
356 void DeleteAllItems();
357 void DeleteColumn( int col
);
358 void DeleteEverything();
359 void EnsureVisible( long index
);
360 long FindItem( long start
, const wxString
& str
, bool partial
= FALSE
);
361 long FindItem( long start
, long data
);
362 long HitTest( int x
, int y
, int &flags
);
363 void InsertItem( wxListItem
&item
);
364 // void AddItem( wxListItem &item );
365 void InsertColumn( long col
, wxListItem
&item
);
366 // void AddColumn( wxListItem &item );
367 void SortItems( wxListCtrlCompare fn
, long data
);
370 DECLARE_DYNAMIC_CLASS(wxListMainWindow
);
371 DECLARE_EVENT_TABLE()
374 //-----------------------------------------------------------------------------
376 //-----------------------------------------------------------------------------
378 class WXDLLEXPORT wxListCtrl
: public wxControl
382 wxListCtrl( wxWindow
*parent
, wxWindowID id
= -1,
383 const wxPoint
&pos
= wxDefaultPosition
, const wxSize
&size
= wxDefaultSize
,
385 long style
= wxLC_ICON
, const wxValidator
& validator
= wxDefaultValidator
,
387 const wxString
&name
= "listctrl" )
389 Create(parent
, id
, pos
, size
, style
, validator
, name
);
393 bool Create( wxWindow
*parent
, wxWindowID id
= -1,
394 const wxPoint
&pos
= wxDefaultPosition
, const wxSize
&size
= wxDefaultSize
,
396 long style
= wxLC_ICON
, const wxValidator
& validator
= wxDefaultValidator
,
398 const wxString
&name
= "listctrl" );
400 bool GetColumn( int col
, wxListItem
& item
) const;
401 bool SetColumn( int col
, wxListItem
& item
);
402 int GetColumnWidth( int col
) const;
403 bool SetColumnWidth( int col
, int width
);
404 int GetCountPerPage() const; // not the same in wxGLC as in Windows, I think
406 bool GetItem( wxListItem
& info
) const;
407 bool SetItem( wxListItem
& info
) ;
408 long SetItem( long index
, int col
, const wxString
& label
, int imageId
= -1 );
409 int GetItemState( long item
, long stateMask
) const;
410 bool SetItemState( long item
, long state
, long stateMask
);
411 bool SetItemImage( long item
, int image
, int selImage
);
412 wxString
GetItemText( long item
) const;
413 void SetItemText( long item
, const wxString
& str
);
414 long GetItemData( long item
) const;
415 bool SetItemData( long item
, long data
);
416 bool GetItemRect( long item
, wxRect
& rect
, int code
= wxLIST_RECT_BOUNDS
) const;
417 bool GetItemPosition( long item
, wxPoint
& pos
) const;
418 bool SetItemPosition( long item
, const wxPoint
& pos
); // not supported in wxGLC
419 int GetItemCount() const;
420 int GetColumnCount() const;
421 void SetItemSpacing( int spacing
, bool isSmall
= FALSE
);
422 int GetItemSpacing( bool isSmall
) const;
423 int GetSelectedItemCount() const;
424 wxColour
GetTextColour() const;
425 void SetTextColour(const wxColour
& col
);
426 long GetTopItem() const;
428 void SetSingleStyle( long style
, bool add
= TRUE
) ;
429 void SetWindowStyleFlag( long style
);
430 void RecreateWindow() {}
431 long GetNextItem( long item
, int geometry
= wxLIST_NEXT_ALL
, int state
= wxLIST_STATE_DONTCARE
) const;
432 wxImageList
*GetImageList( int which
) const;
433 void SetImageList( wxImageList
*imageList
, int which
);
434 bool Arrange( int flag
= wxLIST_ALIGN_DEFAULT
); // always wxLIST_ALIGN_LEFT in wxGLC
437 bool DeleteItem( long item
);
438 bool DeleteAllItems();
439 bool DeleteAllColumns();
440 bool DeleteColumn( int col
);
442 void EditLabel( long item
) { Edit(item
); }
443 void Edit( long item
);
445 bool EnsureVisible( long item
);
446 long FindItem( long start
, const wxString
& str
, bool partial
= FALSE
);
447 long FindItem( long start
, long data
);
448 long FindItem( long start
, const wxPoint
& pt
, int direction
); // not supported in wxGLC
449 long HitTest( const wxPoint
& point
, int& flags
);
450 long InsertItem(wxListItem
& info
);
451 long InsertItem( long index
, const wxString
& label
);
452 long InsertItem( long index
, int imageIndex
);
453 long InsertItem( long index
, const wxString
& label
, int imageIndex
);
454 long InsertColumn( long col
, wxListItem
& info
);
455 long InsertColumn( long col
, const wxString
& heading
, int format
= wxLIST_FORMAT_LEFT
,
457 bool ScrollList( int dx
, int dy
);
458 bool SortItems( wxListCtrlCompare fn
, long data
);
459 bool Update( long item
);
461 void OnIdle( wxIdleEvent
&event
);
462 void OnSize( wxSizeEvent
&event
);
464 // We have to hand down a few functions
466 bool SetBackgroundColour( const wxColour
&colour
);
467 bool SetForegroundColour( const wxColour
&colour
);
468 bool SetFont( const wxFont
&font
);
470 #if wxUSE_DRAG_AND_DROP
471 void SetDropTarget( wxDropTarget
*dropTarget
)
472 { m_mainWin
->SetDropTarget( dropTarget
); }
473 wxDropTarget
*GetDropTarget() const
474 { return m_mainWin
->GetDropTarget(); }
477 bool SetCursor( const wxCursor
&cursor
)
478 { return m_mainWin
? m_mainWin
->wxWindow::SetCursor(cursor
) : FALSE
; }
479 wxColour
GetBackgroundColour() const
480 { return m_mainWin
? m_mainWin
->GetBackgroundColour() : wxColour(); }
481 wxColour
GetForegroundColour() const
482 { return m_mainWin
? m_mainWin
->GetForegroundColour() : wxColour(); }
483 bool DoPopupMenu( wxMenu
*menu
, int x
, int y
)
484 { return m_mainWin
->PopupMenu( menu
, x
, y
); }
487 /* The test in window.cpp fails as we are a composite
488 window, so it checks against "this", but not m_mainWin. */
489 if (FindFocus() != this)
490 m_mainWin
->SetFocus();
496 wxImageList
*m_imageListNormal
;
497 wxImageList
*m_imageListSmall
;
498 wxImageList
*m_imageListState
; // what's that ?
499 wxListHeaderWindow
*m_headerWin
;
500 wxListMainWindow
*m_mainWin
;
503 DECLARE_EVENT_TABLE()
504 DECLARE_DYNAMIC_CLASS(wxListCtrl
);
508 #endif // __LISTCTRLH_G__