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
,
254 const wxValidator
& validator
= wxDefaultValidator
,
255 const wxString
&name
= "wxListTextCtrlText" );
256 void OnChar( wxKeyEvent
&event
);
257 void OnKillFocus( wxFocusEvent
&event
);
260 DECLARE_DYNAMIC_CLASS(wxListTextCtrl
);
261 DECLARE_EVENT_TABLE()
264 //-----------------------------------------------------------------------------
265 // wxListMainWindow (internal)
266 //-----------------------------------------------------------------------------
268 class WXDLLEXPORT wxListMainWindow
: public wxScrolledWindow
274 wxListLineData
*m_current
;
275 wxListLineData
*m_currentEdit
;
277 wxBrush
*m_hilightBrush
;
278 wxColour
*m_hilightColour
;
279 int m_xScroll
,m_yScroll
;
281 wxImageList
*m_small_image_list
;
282 wxImageList
*m_normal_image_list
;
284 int m_normal_spacing
;
288 wxTimer
*m_renameTimer
;
290 wxString m_renameRes
;
297 wxListMainWindow( wxWindow
*parent
, wxWindowID id
,
298 const wxPoint
&pos
= wxDefaultPosition
, const wxSize
&size
= wxDefaultSize
,
299 long style
= 0, const wxString
&name
= "listctrl" );
301 void RefreshLine( wxListLineData
*line
);
302 void OnPaint( wxPaintEvent
&event
);
303 void HilightAll( bool on
);
304 void SendNotify( wxListLineData
*line
, wxEventType command
);
305 void FocusLine( wxListLineData
*line
);
306 void UnfocusLine( wxListLineData
*line
);
307 void SelectLine( wxListLineData
*line
);
308 void DeselectLine( wxListLineData
*line
);
309 void DeleteLine( wxListLineData
*line
);
311 void EditLabel( long item
);
312 void Edit( long item
) { EditLabel(item
); } // deprecated
313 void OnRenameTimer();
314 void OnRenameAccept();
316 void OnMouse( wxMouseEvent
&event
);
318 void OnArrowChar( wxListLineData
*newCurrent
, bool shiftDown
);
319 void OnChar( wxKeyEvent
&event
);
320 void OnKeyDown( wxKeyEvent
&event
);
321 void OnSetFocus( wxFocusEvent
&event
);
322 void OnKillFocus( wxFocusEvent
&event
);
323 void OnSize( wxSizeEvent
&event
);
324 void OnScroll(wxScrollWinEvent
& event
) ;
326 void DrawImage( int index
, wxDC
*dc
, int x
, int y
);
327 void GetImageSize( int index
, int &width
, int &height
);
328 int GetIndexOfLine( const wxListLineData
*line
);
329 int GetTextLength( wxString
&s
); // should be const
331 void SetImageList( wxImageList
*imageList
, int which
);
332 void SetItemSpacing( int spacing
, bool isSmall
= FALSE
);
333 int GetItemSpacing( bool isSmall
= FALSE
);
334 void SetColumn( int col
, wxListItem
&item
);
335 void SetColumnWidth( int col
, int width
);
336 void GetColumn( int col
, wxListItem
&item
);
337 int GetColumnWidth( int vol
);
338 int GetColumnCount();
339 int GetCountPerPage();
340 void SetItem( wxListItem
&item
);
341 void GetItem( wxListItem
&item
);
342 void SetItemState( long item
, long state
, long stateMask
);
343 int GetItemState( long item
, long stateMask
);
345 void GetItemRect( long index
, wxRect
&rect
);
346 bool GetItemPosition( long item
, wxPoint
& pos
);
347 int GetSelectedItemCount();
348 void SetMode( long mode
);
349 long GetMode() const;
350 void CalculatePositions();
351 void RealizeChanges();
352 long GetNextItem( long item
, int geometry
, int state
);
353 void DeleteItem( long index
);
354 void DeleteAllItems();
355 void DeleteColumn( int col
);
356 void DeleteEverything();
357 void EnsureVisible( long index
);
358 long FindItem( long start
, const wxString
& str
, bool partial
= FALSE
);
359 long FindItem( long start
, long data
);
360 long HitTest( int x
, int y
, int &flags
);
361 void InsertItem( wxListItem
&item
);
362 // void AddItem( wxListItem &item );
363 void InsertColumn( long col
, wxListItem
&item
);
364 // void AddColumn( wxListItem &item );
365 void SortItems( wxListCtrlCompare fn
, long data
);
368 DECLARE_DYNAMIC_CLASS(wxListMainWindow
);
369 DECLARE_EVENT_TABLE()
372 //-----------------------------------------------------------------------------
374 //-----------------------------------------------------------------------------
376 class WXDLLEXPORT wxListCtrl
: public wxControl
380 wxListCtrl( wxWindow
*parent
,
382 const wxPoint
&pos
= wxDefaultPosition
,
383 const wxSize
&size
= wxDefaultSize
,
384 long style
= wxLC_ICON
,
385 const wxValidator
& validator
= wxDefaultValidator
,
386 const wxString
&name
= "listctrl" )
388 Create(parent
, id
, pos
, size
, style
, validator
, name
);
392 bool Create( wxWindow
*parent
,
394 const wxPoint
&pos
= wxDefaultPosition
,
395 const wxSize
&size
= wxDefaultSize
,
396 long style
= wxLC_ICON
,
397 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__