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
70 wxListItemData( const wxListItem
&info
);
71 void SetItem( const wxListItem
&info
);
72 void SetText( const wxString
&s
);
73 void SetImage( int image
);
74 void SetData( long data
);
75 void SetPosition( int x
, int y
);
76 void SetSize( int width
, int height
);
77 void SetColour( wxColour
*col
);
78 bool HasImage() const;
80 bool IsHit( int x
, int y
) const;
81 void GetText( wxString
&s
);
82 int GetX( void ) const;
83 int GetY( void ) const;
85 int GetHeight() const;
87 void GetItem( wxListItem
&info
);
88 wxColour
*GetColour();
91 DECLARE_DYNAMIC_CLASS(wxListItemData
);
94 //-----------------------------------------------------------------------------
95 // wxListHeaderData (internal)
96 //-----------------------------------------------------------------------------
98 class WXDLLEXPORT wxListHeaderData
: public wxObject
111 wxListHeaderData( const wxListItem
&info
);
112 void SetItem( const wxListItem
&item
);
113 void SetPosition( int x
, int y
);
114 void SetWidth( int w
);
115 void SetFormat( int format
);
116 void SetHeight( int h
);
117 bool HasImage() const;
118 bool HasText() const;
119 bool IsHit( int x
, int y
) const;
120 void GetItem( wxListItem
&item
);
121 void GetText( wxString
&s
);
122 int GetImage() const;
123 int GetWidth() const;
124 int GetFormat() const;
127 DECLARE_DYNAMIC_CLASS(wxListHeaderData
);
130 //-----------------------------------------------------------------------------
131 // wxListLineData (internal)
132 //-----------------------------------------------------------------------------
134 class WXDLLEXPORT wxListLineData
: public wxObject
139 wxRect m_bound_label
;
141 wxRect m_bound_hilight
;
144 wxBrush
*m_hilightBrush
;
146 wxListMainWindow
*m_owner
;
148 void DoDraw( wxDC
*dc
, bool hilight
, bool paintBG
);
152 wxListLineData( wxListMainWindow
*owner
, int mode
, wxBrush
*hilightBrush
);
153 void CalculateSize( wxDC
*dc
, int spacing
);
154 void SetPosition( wxDC
*dc
, int x
, int y
, int window_width
);
155 void SetColumnPosition( int index
, int x
);
156 void GetSize( int &width
, int &height
);
157 void GetExtent( int &x
, int &y
, int &width
, int &height
);
158 void GetLabelExtent( int &x
, int &y
, int &width
, int &height
);
159 long IsHit( int x
, int y
);
160 void InitItems( int num
);
161 void SetItem( int index
, const wxListItem
&info
);
162 void GetItem( int index
, wxListItem
&info
);
163 void GetText( int index
, wxString
&s
);
164 void SetText( int index
, const wxString s
);
165 int GetImage( int index
);
166 void GetRect( wxRect
&rect
);
167 void Hilight( bool on
);
168 void ReverseHilight();
169 void DrawRubberBand( wxDC
*dc
, bool on
);
170 void Draw( wxDC
*dc
);
171 bool IsInRect( int x
, int y
, const wxRect
&rect
);
173 void AssignRect( wxRect
&dest
, int x
, int y
, int width
, int height
);
174 void AssignRect( wxRect
&dest
, const wxRect
&source
);
177 DECLARE_DYNAMIC_CLASS(wxListLineData
);
180 //-----------------------------------------------------------------------------
181 // wxListHeaderWindow (internal)
182 //-----------------------------------------------------------------------------
184 class WXDLLEXPORT wxListHeaderWindow
: public wxWindow
187 wxListMainWindow
*m_owner
;
188 wxCursor
*m_currentCursor
;
189 wxCursor
*m_resizeCursor
;
196 wxListHeaderWindow();
197 ~wxListHeaderWindow();
198 wxListHeaderWindow( wxWindow
*win
, wxWindowID id
, wxListMainWindow
*owner
,
199 const wxPoint
&pos
= wxDefaultPosition
, const wxSize
&size
= wxDefaultSize
,
200 long style
= 0, const wxString
&name
= "columntitles" );
201 void DoDrawRect( wxDC
*dc
, int x
, int y
, int w
, int h
);
202 void OnPaint( wxPaintEvent
&event
);
204 void OnMouse( wxMouseEvent
&event
);
205 void OnSetFocus( wxFocusEvent
&event
);
208 DECLARE_DYNAMIC_CLASS(wxListHeaderWindow
)
209 DECLARE_EVENT_TABLE()
212 //-----------------------------------------------------------------------------
213 // wxListRenameTimer (internal)
214 //-----------------------------------------------------------------------------
216 class WXDLLEXPORT wxListRenameTimer
: public wxTimer
219 wxListMainWindow
*m_owner
;
222 wxListRenameTimer( wxListMainWindow
*owner
);
226 //-----------------------------------------------------------------------------
227 // wxListTextCtrl (internal)
228 //-----------------------------------------------------------------------------
230 class WXDLLEXPORT wxListTextCtrl
: public wxTextCtrl
235 wxListMainWindow
*m_owner
;
236 wxString m_startValue
;
240 wxListTextCtrl( wxWindow
*parent
, const wxWindowID id
,
241 bool *accept
, wxString
*res
, wxListMainWindow
*owner
,
242 const wxString
&value
= "",
243 const wxPoint
&pos
= wxDefaultPosition
, const wxSize
&size
= wxDefaultSize
,
245 int style
= 0, const wxValidator
& validator
= wxDefaultValidator
,
247 const wxString
&name
= "wxListTextCtrlText" );
248 void OnChar( wxKeyEvent
&event
);
249 void OnKillFocus( wxFocusEvent
&event
);
252 DECLARE_DYNAMIC_CLASS(wxListTextCtrl
);
253 DECLARE_EVENT_TABLE()
256 //-----------------------------------------------------------------------------
257 // wxListMainWindow (internal)
258 //-----------------------------------------------------------------------------
260 class WXDLLEXPORT wxListMainWindow
: public wxScrolledWindow
266 wxListLineData
*m_current
;
267 wxListLineData
*m_currentEdit
;
269 wxBrush
*m_hilightBrush
;
270 wxColour
*m_hilightColour
;
271 int m_xScroll
,m_yScroll
;
273 wxImageList
*m_small_image_list
;
274 wxImageList
*m_normal_image_list
;
276 int m_normal_spacing
;
280 wxTimer
*m_renameTimer
;
282 wxString m_renameRes
;
289 wxListMainWindow( wxWindow
*parent
, wxWindowID id
,
290 const wxPoint
&pos
= wxDefaultPosition
, const wxSize
&size
= wxDefaultSize
,
291 long style
= 0, const wxString
&name
= "listctrl" );
293 void RefreshLine( wxListLineData
*line
);
294 void OnPaint( wxPaintEvent
&event
);
295 void HilightAll( bool on
);
296 void SendNotify( wxListLineData
*line
, wxEventType command
);
297 void FocusLine( wxListLineData
*line
);
298 void UnfocusLine( wxListLineData
*line
);
299 void SelectLine( wxListLineData
*line
);
300 void DeselectLine( wxListLineData
*line
);
301 void DeleteLine( wxListLineData
*line
);
303 void EditLabel( long item
);
304 void Edit( long item
) { EditLabel(item
); } // deprecated
305 void OnRenameTimer();
306 void OnRenameAccept();
308 void OnMouse( wxMouseEvent
&event
);
310 void OnArrowChar( wxListLineData
*newCurrent
, bool shiftDown
);
311 void OnChar( wxKeyEvent
&event
);
312 void OnKeyDown( wxKeyEvent
&event
);
313 void OnSetFocus( wxFocusEvent
&event
);
314 void OnKillFocus( wxFocusEvent
&event
);
315 void OnSize( wxSizeEvent
&event
);
316 void OnScroll(wxScrollWinEvent
& event
) ;
318 void DrawImage( int index
, wxDC
*dc
, int x
, int y
);
319 void GetImageSize( int index
, int &width
, int &height
);
320 int GetIndexOfLine( const wxListLineData
*line
);
321 int GetTextLength( wxString
&s
); // should be const
323 void SetImageList( wxImageList
*imageList
, int which
);
324 void SetItemSpacing( int spacing
, bool isSmall
= FALSE
);
325 int GetItemSpacing( bool isSmall
= FALSE
);
326 void SetColumn( int col
, wxListItem
&item
);
327 void SetColumnWidth( int col
, int width
);
328 void GetColumn( int col
, wxListItem
&item
);
329 int GetColumnWidth( int vol
);
330 int GetColumnCount();
331 int GetCountPerPage();
332 void SetItem( wxListItem
&item
);
333 void GetItem( wxListItem
&item
);
334 void SetItemState( long item
, long state
, long stateMask
);
335 int GetItemState( long item
, long stateMask
);
337 void GetItemRect( long index
, wxRect
&rect
);
338 bool GetItemPosition( long item
, wxPoint
& pos
);
339 int GetSelectedItemCount();
340 void SetMode( long mode
);
341 long GetMode() const;
342 void CalculatePositions();
343 void RealizeChanges();
344 long GetNextItem( long item
, int geometry
, int state
);
345 void DeleteItem( long index
);
346 void DeleteAllItems();
347 void DeleteColumn( int col
);
348 void DeleteEverything();
349 void EnsureVisible( long index
);
350 long FindItem( long start
, const wxString
& str
, bool partial
= FALSE
);
351 long FindItem( long start
, long data
);
352 long HitTest( int x
, int y
, int &flags
);
353 void InsertItem( wxListItem
&item
);
354 // void AddItem( wxListItem &item );
355 void InsertColumn( long col
, wxListItem
&item
);
356 // void AddColumn( wxListItem &item );
357 void SortItems( wxListCtrlCompare fn
, long data
);
360 DECLARE_DYNAMIC_CLASS(wxListMainWindow
);
361 DECLARE_EVENT_TABLE()
364 //-----------------------------------------------------------------------------
366 //-----------------------------------------------------------------------------
368 class WXDLLEXPORT wxListCtrl
: public wxControl
372 wxListCtrl( wxWindow
*parent
, wxWindowID id
= -1,
373 const wxPoint
&pos
= wxDefaultPosition
, const wxSize
&size
= wxDefaultSize
,
375 long style
= wxLC_ICON
, const wxValidator
& validator
= wxDefaultValidator
,
377 const wxString
&name
= "listctrl" )
379 Create(parent
, id
, pos
, size
, style
, validator
, name
);
383 bool Create( wxWindow
*parent
, wxWindowID id
= -1,
384 const wxPoint
&pos
= wxDefaultPosition
, const wxSize
&size
= wxDefaultSize
,
386 long style
= wxLC_ICON
, const wxValidator
& validator
= wxDefaultValidator
,
388 const wxString
&name
= "listctrl" );
390 bool GetColumn( int col
, wxListItem
& item
) const;
391 bool SetColumn( int col
, wxListItem
& item
);
392 int GetColumnWidth( int col
) const;
393 bool SetColumnWidth( int col
, int width
);
394 int GetCountPerPage() const; // not the same in wxGLC as in Windows, I think
396 bool GetItem( wxListItem
& info
) const;
397 bool SetItem( wxListItem
& info
) ;
398 long SetItem( long index
, int col
, const wxString
& label
, int imageId
= -1 );
399 int GetItemState( long item
, long stateMask
) const;
400 bool SetItemState( long item
, long state
, long stateMask
);
401 bool SetItemImage( long item
, int image
, int selImage
);
402 wxString
GetItemText( long item
) const;
403 void SetItemText( long item
, const wxString
& str
);
404 long GetItemData( long item
) const;
405 bool SetItemData( long item
, long data
);
406 bool GetItemRect( long item
, wxRect
& rect
, int code
= wxLIST_RECT_BOUNDS
) const;
407 bool GetItemPosition( long item
, wxPoint
& pos
) const;
408 bool SetItemPosition( long item
, const wxPoint
& pos
); // not supported in wxGLC
409 int GetItemCount() const;
410 int GetColumnCount() const;
411 void SetItemSpacing( int spacing
, bool isSmall
= FALSE
);
412 int GetItemSpacing( bool isSmall
) const;
413 int GetSelectedItemCount() const;
414 // wxColour GetTextColour() const; // wxGLC has colours for every Item (see wxListItem)
415 // void SetTextColour(const wxColour& col);
416 long GetTopItem() const;
418 void SetSingleStyle( long style
, bool add
= TRUE
) ;
419 void SetWindowStyleFlag( long style
);
420 void RecreateWindow() {}
421 long GetNextItem( long item
, int geometry
= wxLIST_NEXT_ALL
, int state
= wxLIST_STATE_DONTCARE
) const;
422 wxImageList
*GetImageList( int which
) const;
423 void SetImageList( wxImageList
*imageList
, int which
);
424 bool Arrange( int flag
= wxLIST_ALIGN_DEFAULT
); // always wxLIST_ALIGN_LEFT in wxGLC
427 bool DeleteItem( long item
);
428 bool DeleteAllItems();
429 bool DeleteAllColumns();
430 bool DeleteColumn( int col
);
432 void EditLabel( long item
) { Edit(item
); }
433 void Edit( long item
);
435 bool EnsureVisible( long item
);
436 long FindItem( long start
, const wxString
& str
, bool partial
= FALSE
);
437 long FindItem( long start
, long data
);
438 long FindItem( long start
, const wxPoint
& pt
, int direction
); // not supported in wxGLC
439 long HitTest( const wxPoint
& point
, int& flags
);
440 long InsertItem(wxListItem
& info
);
441 long InsertItem( long index
, const wxString
& label
);
442 long InsertItem( long index
, int imageIndex
);
443 long InsertItem( long index
, const wxString
& label
, int imageIndex
);
444 long InsertColumn( long col
, wxListItem
& info
);
445 long InsertColumn( long col
, const wxString
& heading
, int format
= wxLIST_FORMAT_LEFT
,
447 bool ScrollList( int dx
, int dy
);
448 bool SortItems( wxListCtrlCompare fn
, long data
);
449 bool Update( long item
);
451 void OnIdle( wxIdleEvent
&event
);
452 void OnSize( wxSizeEvent
&event
);
454 // We have to hand down a few functions
456 bool SetBackgroundColour( const wxColour
&colour
);
457 bool SetForegroundColour( const wxColour
&colour
);
458 bool SetFont( const wxFont
&font
);
460 #if wxUSE_DRAG_AND_DROP
461 void SetDropTarget( wxDropTarget
*dropTarget
)
462 { m_mainWin
->SetDropTarget( dropTarget
); }
463 wxDropTarget
*GetDropTarget() const
464 { return m_mainWin
->GetDropTarget(); }
467 bool SetCursor( const wxCursor
&cursor
)
468 { return m_mainWin
? m_mainWin
->wxWindow::SetCursor(cursor
) : FALSE
; }
469 wxColour
GetBackgroundColour() const
470 { return m_mainWin
? m_mainWin
->GetBackgroundColour() : wxColour(); }
471 wxColour
GetForegroundColour() const
472 { return m_mainWin
? m_mainWin
->GetForegroundColour() : wxColour(); }
473 bool DoPopupMenu( wxMenu
*menu
, int x
, int y
)
474 { return m_mainWin
->PopupMenu( menu
, x
, y
); }
477 /* The test in window.cpp fails as we are a composite
478 window, so it checks against "this", but not m_mainWin. */
479 if (FindFocus() != this)
480 m_mainWin
->SetFocus();
486 wxImageList
*m_imageListNormal
;
487 wxImageList
*m_imageListSmall
;
488 wxImageList
*m_imageListState
; // what's that ?
489 wxListHeaderWindow
*m_headerWin
;
490 wxListMainWindow
*m_mainWin
;
493 DECLARE_EVENT_TABLE()
494 DECLARE_DYNAMIC_CLASS(wxListCtrl
);
498 #endif // __LISTCTRLH_G__