]> git.saurik.com Git - wxWidgets.git/blame - include/wx/generic/listctrl.h
Various things related to wxFileDialog and attributes.
[wxWidgets.git] / include / wx / generic / listctrl.h
CommitLineData
c801d85f 1/////////////////////////////////////////////////////////////////////////////
bdc72a22 2// Name: wx/generic/listctrl.h
c801d85f
KB
3// Purpose: Generic list control
4// Author: Robert Roebling
5// Created: 01/02/97
6// Id:
7// Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem
bdc72a22 8// Licence: wxWindows licence
c801d85f
KB
9/////////////////////////////////////////////////////////////////////////////
10
11#ifndef __LISTCTRLH_G__
12#define __LISTCTRLH_G__
13
14#ifdef __GNUG__
0d3820b3 15#pragma interface "listctrl.h"
c801d85f
KB
16#endif
17
18#include "wx/defs.h"
19#include "wx/object.h"
f60d0f94 20#include "wx/generic/imaglist.h"
c801d85f
KB
21#include "wx/control.h"
22#include "wx/timer.h"
ee7ee469 23#include "wx/textctrl.h"
c801d85f
KB
24#include "wx/dcclient.h"
25#include "wx/scrolwin.h"
26#include "wx/settings.h"
27
1e6d9499
JS
28#if wxUSE_DRAG_AND_DROP
29class WXDLLEXPORT wxDropTarget;
30#endif
31
c801d85f
KB
32//-----------------------------------------------------------------------------
33// classes
34//-----------------------------------------------------------------------------
35
1e6d9499
JS
36class WXDLLEXPORT wxListItem;
37class WXDLLEXPORT wxListEvent;
38class WXDLLEXPORT wxListCtrl;
c801d85f
KB
39
40//-----------------------------------------------------------------------------
41// internal classes
42//-----------------------------------------------------------------------------
43
1e6d9499
JS
44class WXDLLEXPORT wxListHeaderData;
45class WXDLLEXPORT wxListItemData;
46class WXDLLEXPORT wxListLineData;
c801d85f 47
1e6d9499
JS
48class WXDLLEXPORT wxListHeaderWindow;
49class WXDLLEXPORT wxListMainWindow;
c801d85f 50
1e6d9499 51class WXDLLEXPORT wxListRenameTimer;
e179bd65 52class WXDLLEXPORT wxListTextCtrl;
c801d85f 53
c801d85f
KB
54//-----------------------------------------------------------------------------
55// wxListItemData (internal)
56//-----------------------------------------------------------------------------
57
1e6d9499 58class WXDLLEXPORT wxListItemData : public wxObject
c801d85f 59{
fd9811b1 60public:
c801d85f
KB
61 wxString m_text;
62 int m_image;
63 long m_data;
64 int m_xpos,m_ypos;
65 int m_width,m_height;
0530737d
VZ
66
67 wxListItemAttr *m_attr;
a3622daa 68
fd9811b1
RR
69public:
70 wxListItemData();
0530737d
VZ
71 ~wxListItemData() { delete m_attr; }
72
c801d85f
KB
73 wxListItemData( const wxListItem &info );
74 void SetItem( const wxListItem &info );
75 void SetText( const wxString &s );
debe6624
JS
76 void SetImage( int image );
77 void SetData( long data );
78 void SetPosition( int x, int y );
79 void SetSize( int width, int height );
fd9811b1
RR
80 bool HasImage() const;
81 bool HasText() const;
debe6624 82 bool IsHit( int x, int y ) const;
c801d85f 83 void GetText( wxString &s );
0530737d 84 const wxString& GetText() { return m_text; }
c801d85f
KB
85 int GetX( void ) const;
86 int GetY( void ) const;
fd9811b1
RR
87 int GetWidth() const;
88 int GetHeight() const;
89 int GetImage() const;
0530737d
VZ
90 void GetItem( wxListItem &info ) const;
91
92 wxListItemAttr *GetAttributes() const { return m_attr; }
57c4d796 93
fd9811b1
RR
94private:
95 DECLARE_DYNAMIC_CLASS(wxListItemData);
c801d85f
KB
96};
97
98//-----------------------------------------------------------------------------
99// wxListHeaderData (internal)
100//-----------------------------------------------------------------------------
101
1e6d9499 102class WXDLLEXPORT wxListHeaderData : public wxObject
c801d85f 103{
b16088bf 104protected:
c801d85f
KB
105 long m_mask;
106 int m_image;
107 wxString m_text;
108 int m_format;
109 int m_width;
110 int m_xpos,m_ypos;
111 int m_height;
a3622daa 112
b16088bf 113public:
fd9811b1 114 wxListHeaderData();
c801d85f
KB
115 wxListHeaderData( const wxListItem &info );
116 void SetItem( const wxListItem &item );
debe6624
JS
117 void SetPosition( int x, int y );
118 void SetWidth( int w );
119 void SetFormat( int format );
120 void SetHeight( int h );
fd9811b1
RR
121 bool HasImage() const;
122 bool HasText() const;
debe6624 123 bool IsHit( int x, int y ) const;
c801d85f
KB
124 void GetItem( wxListItem &item );
125 void GetText( wxString &s );
fd9811b1
RR
126 int GetImage() const;
127 int GetWidth() const;
128 int GetFormat() const;
b16088bf
RR
129
130private:
131 DECLARE_DYNAMIC_CLASS(wxListHeaderData);
c801d85f
KB
132};
133
134//-----------------------------------------------------------------------------
135// wxListLineData (internal)
136//-----------------------------------------------------------------------------
137
1e6d9499 138class WXDLLEXPORT wxListLineData : public wxObject
c801d85f 139{
b16088bf 140public:
c801d85f 141 wxList m_items;
fd9811b1
RR
142 wxRect m_bound_all;
143 wxRect m_bound_label;
144 wxRect m_bound_icon;
145 wxRect m_bound_hilight;
c801d85f
KB
146 int m_mode;
147 bool m_hilighted;
148 wxBrush *m_hilightBrush;
149 int m_spacing;
150 wxListMainWindow *m_owner;
151
1e6d9499 152 void DoDraw( wxDC *dc, bool hilight, bool paintBG );
c801d85f 153
b16088bf
RR
154public:
155 wxListLineData() {}
debe6624 156 wxListLineData( wxListMainWindow *owner, int mode, wxBrush *hilightBrush );
1e6d9499
JS
157 void CalculateSize( wxDC *dc, int spacing );
158 void SetPosition( wxDC *dc, int x, int y, int window_width );
debe6624 159 void SetColumnPosition( int index, int x );
c801d85f
KB
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 );
debe6624
JS
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 );
0a240683 170 void GetRect( wxRect &rect );
debe6624 171 void Hilight( bool on );
fd9811b1 172 void ReverseHilight();
1e6d9499
JS
173 void DrawRubberBand( wxDC *dc, bool on );
174 void Draw( wxDC *dc );
0a240683 175 bool IsInRect( int x, int y, const wxRect &rect );
fd9811b1 176 bool IsHilighted();
0a240683
JS
177 void AssignRect( wxRect &dest, int x, int y, int width, int height );
178 void AssignRect( wxRect &dest, const wxRect &source );
b16088bf
RR
179
180private:
0530737d
VZ
181 void SetAttributes(wxDC *dc,
182 const wxListItemAttr *attr,
183 const wxColour& colText, const wxFont& font);
184
b16088bf 185 DECLARE_DYNAMIC_CLASS(wxListLineData);
c801d85f
KB
186};
187
188//-----------------------------------------------------------------------------
189// wxListHeaderWindow (internal)
190//-----------------------------------------------------------------------------
191
1e6d9499 192class WXDLLEXPORT wxListHeaderWindow : public wxWindow
c801d85f 193{
b16088bf 194protected:
c801d85f
KB
195 wxListMainWindow *m_owner;
196 wxCursor *m_currentCursor;
197 wxCursor *m_resizeCursor;
cfb50f14 198 bool m_isDragging;
0208334d
RR
199 int m_column;
200 int m_minX;
201 int m_currentX;
c801d85f 202
b16088bf 203public:
fd9811b1
RR
204 wxListHeaderWindow();
205 ~wxListHeaderWindow();
a3622daa 206 wxListHeaderWindow( wxWindow *win, wxWindowID id, wxListMainWindow *owner,
debe6624
JS
207 const wxPoint &pos = wxDefaultPosition, const wxSize &size = wxDefaultSize,
208 long style = 0, const wxString &name = "columntitles" );
1e6d9499 209 void DoDrawRect( wxDC *dc, int x, int y, int w, int h );
c801d85f 210 void OnPaint( wxPaintEvent &event );
0208334d 211 void DrawCurrent();
c801d85f
KB
212 void OnMouse( wxMouseEvent &event );
213 void OnSetFocus( wxFocusEvent &event );
a3622daa 214
b16088bf
RR
215private:
216 DECLARE_DYNAMIC_CLASS(wxListHeaderWindow)
217 DECLARE_EVENT_TABLE()
c801d85f
KB
218};
219
220//-----------------------------------------------------------------------------
221// wxListRenameTimer (internal)
222//-----------------------------------------------------------------------------
223
1e6d9499 224class WXDLLEXPORT wxListRenameTimer: public wxTimer
c801d85f 225{
b16088bf
RR
226private:
227 wxListMainWindow *m_owner;
a3622daa 228
b16088bf
RR
229public:
230 wxListRenameTimer( wxListMainWindow *owner );
231 void Notify();
c801d85f
KB
232};
233
c801d85f
KB
234//-----------------------------------------------------------------------------
235// wxListTextCtrl (internal)
236//-----------------------------------------------------------------------------
237
1e6d9499 238class WXDLLEXPORT wxListTextCtrl: public wxTextCtrl
c801d85f 239{
b16088bf 240private:
c801d85f
KB
241 bool *m_accept;
242 wxString *m_res;
243 wxListMainWindow *m_owner;
5f1ea0ee 244 wxString m_startValue;
c801d85f 245
b16088bf
RR
246public:
247 wxListTextCtrl() {}
57c4d796 248 wxListTextCtrl( wxWindow *parent, const wxWindowID id,
ee7ee469
RR
249 bool *accept, wxString *res, wxListMainWindow *owner,
250 const wxString &value = "",
251 const wxPoint &pos = wxDefaultPosition, const wxSize &size = wxDefaultSize,
0530737d 252 int style = 0,
57c4d796 253#if wxUSE_VALIDATORS
0530737d 254 const wxValidator& validator = wxDefaultValidator,
57c4d796 255#endif
ee7ee469
RR
256 const wxString &name = "wxListTextCtrlText" );
257 void OnChar( wxKeyEvent &event );
258 void OnKillFocus( wxFocusEvent &event );
57c4d796 259
b16088bf
RR
260private:
261 DECLARE_DYNAMIC_CLASS(wxListTextCtrl);
262 DECLARE_EVENT_TABLE()
c801d85f
KB
263};
264
c801d85f
KB
265//-----------------------------------------------------------------------------
266// wxListMainWindow (internal)
267//-----------------------------------------------------------------------------
268
1e6d9499 269class WXDLLEXPORT wxListMainWindow: public wxScrolledWindow
c801d85f 270{
b16088bf 271public:
c801d85f
KB
272 long m_mode;
273 wxList m_lines;
a3622daa 274 wxList m_columns;
c801d85f 275 wxListLineData *m_current;
e179bd65 276 wxListLineData *m_currentEdit;
c801d85f
KB
277 int m_visibleLines;
278 wxBrush *m_hilightBrush;
279 wxColour *m_hilightColour;
c801d85f
KB
280 int m_xScroll,m_yScroll;
281 bool m_dirty;
282 wxImageList *m_small_image_list;
283 wxImageList *m_normal_image_list;
284 int m_small_spacing;
285 int m_normal_spacing;
286 bool m_hasFocus;
287 bool m_usedKeys;
288 bool m_lastOnSame;
289 wxTimer *m_renameTimer;
c801d85f
KB
290 bool m_renameAccept;
291 wxString m_renameRes;
292 bool m_isCreated;
e3e65dac 293 int m_dragCount;
fd9811b1 294 wxPoint m_dragStart;
c801d85f 295
b16088bf 296public:
e179bd65 297 wxListMainWindow();
a3622daa 298 wxListMainWindow( wxWindow *parent, wxWindowID id,
debe6624
JS
299 const wxPoint &pos = wxDefaultPosition, const wxSize &size = wxDefaultSize,
300 long style = 0, const wxString &name = "listctrl" );
e179bd65 301 ~wxListMainWindow();
c801d85f
KB
302 void RefreshLine( wxListLineData *line );
303 void OnPaint( wxPaintEvent &event );
debe6624 304 void HilightAll( bool on );
64693098 305 void SendNotify( wxListLineData *line, wxEventType command );
c801d85f
KB
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 );
57c4d796 311
5f1ea0ee
RR
312 void EditLabel( long item );
313 void Edit( long item ) { EditLabel(item); } // deprecated
e179bd65
RR
314 void OnRenameTimer();
315 void OnRenameAccept();
57c4d796 316
c801d85f 317 void OnMouse( wxMouseEvent &event );
e179bd65 318 void MoveToFocus();
c801d85f
KB
319 void OnArrowChar( wxListLineData *newCurrent, bool shiftDown );
320 void OnChar( wxKeyEvent &event );
3dfb93fd 321 void OnKeyDown( wxKeyEvent &event );
c801d85f
KB
322 void OnSetFocus( wxFocusEvent &event );
323 void OnKillFocus( wxFocusEvent &event );
324 void OnSize( wxSizeEvent &event );
0530737d
VZ
325 void OnScroll(wxScrollWinEvent& event) ;
326
1e6d9499 327 void DrawImage( int index, wxDC *dc, int x, int y );
c801d85f
KB
328 void GetImageSize( int index, int &width, int &height );
329 int GetIndexOfLine( const wxListLineData *line );
330 int GetTextLength( wxString &s ); // should be const
331
debe6624
JS
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 );
e179bd65
RR
339 int GetColumnCount();
340 int GetCountPerPage();
c801d85f
KB
341 void SetItem( wxListItem &item );
342 void GetItem( wxListItem &item );
a3622daa 343 void SetItemState( long item, long state, long stateMask );
debe6624 344 int GetItemState( long item, long stateMask );
e179bd65 345 int GetItemCount();
0a240683 346 void GetItemRect( long index, wxRect &rect );
e179bd65
RR
347 bool GetItemPosition( long item, wxPoint& pos );
348 int GetSelectedItemCount();
debe6624 349 void SetMode( long mode );
e179bd65
RR
350 long GetMode() const;
351 void CalculatePositions();
352 void RealizeChanges();
debe6624
JS
353 long GetNextItem( long item, int geometry, int state );
354 void DeleteItem( long index );
e179bd65 355 void DeleteAllItems();
debe6624 356 void DeleteColumn( int col );
e179bd65 357 void DeleteEverything();
debe6624 358 void EnsureVisible( long index );
e179bd65
RR
359 long FindItem( long start, const wxString& str, bool partial = FALSE );
360 long FindItem( long start, long data);
debe6624 361 long HitTest( int x, int y, int &flags );
c801d85f 362 void InsertItem( wxListItem &item );
30dea054 363// void AddItem( wxListItem &item );
debe6624 364 void InsertColumn( long col, wxListItem &item );
30dea054 365// void AddColumn( wxListItem &item );
c801d85f 366 void SortItems( wxListCtrlCompare fn, long data );
a3622daa 367
b16088bf
RR
368private:
369 DECLARE_DYNAMIC_CLASS(wxListMainWindow);
370 DECLARE_EVENT_TABLE()
c801d85f
KB
371};
372
373//-----------------------------------------------------------------------------
374// wxListCtrl
375//-----------------------------------------------------------------------------
376
1e6d9499 377class WXDLLEXPORT wxListCtrl: public wxControl
c801d85f 378{
b16088bf 379public:
e179bd65 380 wxListCtrl();
32e9da8b 381 wxListCtrl( wxWindow *parent, wxWindowID id = -1,
debe6624 382 const wxPoint &pos = wxDefaultPosition, const wxSize &size = wxDefaultSize,
57c4d796 383#if wxUSE_VALIDATORS
32e9da8b 384 long style = wxLC_ICON, const wxValidator& validator = wxDefaultValidator,
57c4d796 385#endif
32e9da8b
RR
386 const wxString &name = "listctrl" )
387 {
b16088bf 388 Create(parent, id, pos, size, style, validator, name);
32e9da8b 389 }
e179bd65 390 ~wxListCtrl();
b16088bf 391
32e9da8b 392 bool Create( wxWindow *parent, wxWindowID id = -1,
debe6624 393 const wxPoint &pos = wxDefaultPosition, const wxSize &size = wxDefaultSize,
57c4d796 394#if wxUSE_VALIDATORS
32e9da8b 395 long style = wxLC_ICON, const wxValidator& validator = wxDefaultValidator,
57c4d796 396#endif
b16088bf
RR
397 const wxString &name = "listctrl" );
398
e487524e 399 bool GetColumn( int col, wxListItem& item ) const;
debe6624 400 bool SetColumn( int col, wxListItem& item );
e487524e 401 int GetColumnWidth( int col ) const;
debe6624 402 bool SetColumnWidth( int col, int width);
e179bd65 403 int GetCountPerPage() const; // not the same in wxGLC as in Windows, I think
b16088bf 404
e487524e 405 bool GetItem( wxListItem& info ) const;
c801d85f 406 bool SetItem( wxListItem& info ) ;
debe6624 407 long SetItem( long index, int col, const wxString& label, int imageId = -1 );
e487524e 408 int GetItemState( long item, long stateMask ) const;
debe6624
JS
409 bool SetItemState( long item, long state, long stateMask);
410 bool SetItemImage( long item, int image, int selImage);
e487524e 411 wxString GetItemText( long item ) const;
debe6624 412 void SetItemText( long item, const wxString& str );
e487524e 413 long GetItemData( long item ) const;
debe6624 414 bool SetItemData( long item, long data );
0a240683 415 bool GetItemRect( long item, wxRect& rect, int code = wxLIST_RECT_BOUNDS ) const;
e487524e 416 bool GetItemPosition( long item, wxPoint& pos ) const;
debe6624 417 bool SetItemPosition( long item, const wxPoint& pos ); // not supported in wxGLC
e179bd65
RR
418 int GetItemCount() const;
419 int GetColumnCount() const;
33d0b396 420 void SetItemSpacing( int spacing, bool isSmall = FALSE );
e487524e 421 int GetItemSpacing( bool isSmall ) const;
e179bd65 422 int GetSelectedItemCount() const;
0530737d
VZ
423 wxColour GetTextColour() const;
424 void SetTextColour(const wxColour& col);
e179bd65 425 long GetTopItem() const;
b16088bf 426
debe6624 427 void SetSingleStyle( long style, bool add = TRUE ) ;
e179bd65
RR
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 );
debe6624 433 bool Arrange( int flag = wxLIST_ALIGN_DEFAULT ); // always wxLIST_ALIGN_LEFT in wxGLC
57c4d796 434
4f22cf8d 435 void ClearAll();
debe6624 436 bool DeleteItem( long item );
e179bd65
RR
437 bool DeleteAllItems();
438 bool DeleteAllColumns();
debe6624 439 bool DeleteColumn( int col );
57c4d796 440
e179bd65
RR
441 void EditLabel( long item ) { Edit(item); }
442 void Edit( long item );
57c4d796 443
debe6624 444 bool EnsureVisible( long item );
e179bd65
RR
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);
c801d85f 449 long InsertItem(wxListItem& info);
e179bd65
RR
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,
455 int width = -1 );
456 bool ScrollList( int dx, int dy );
457 bool SortItems( wxListCtrlCompare fn, long data );
458 bool Update( long item );
b16088bf 459
77e7a1dc 460 void OnIdle( wxIdleEvent &event );
b16088bf 461 void OnSize( wxSizeEvent &event );
57c4d796 462
77e7a1dc 463 // We have to hand down a few functions
57c4d796 464
f03fc89f
VZ
465 bool SetBackgroundColour( const wxColour &colour );
466 bool SetForegroundColour( const wxColour &colour );
467 bool SetFont( const wxFont &font );
57c4d796 468
1e6d9499 469#if wxUSE_DRAG_AND_DROP
c801d85f 470 void SetDropTarget( wxDropTarget *dropTarget )
77e7a1dc 471 { m_mainWin->SetDropTarget( dropTarget ); }
c801d85f 472 wxDropTarget *GetDropTarget() const
77e7a1dc 473 { return m_mainWin->GetDropTarget(); }
1e6d9499
JS
474#endif
475
f03fc89f
VZ
476 bool SetCursor( const wxCursor &cursor )
477 { return m_mainWin ? m_mainWin->wxWindow::SetCursor(cursor) : FALSE; }
77e7a1dc 478 wxColour GetBackgroundColour() const
f03fc89f 479 { return m_mainWin ? m_mainWin->GetBackgroundColour() : wxColour(); }
77e7a1dc 480 wxColour GetForegroundColour() const
f03fc89f 481 { return m_mainWin ? m_mainWin->GetForegroundColour() : wxColour(); }
a1665b22 482 bool DoPopupMenu( wxMenu *menu, int x, int y )
39570cd4 483 { return m_mainWin->PopupMenu( menu, x, y ); }
b292e2f5 484 void SetFocus()
b16088bf 485 {
c0d6c58b
KB
486 /* The test in window.cpp fails as we are a composite
487 window, so it checks against "this", but not m_mainWin. */
b16088bf
RR
488 if (FindFocus() != this)
489 m_mainWin->SetFocus();
490 }
c801d85f 491
b16088bf
RR
492 // implementation
493 // --------------
57c4d796 494
a3622daa
VZ
495 wxImageList *m_imageListNormal;
496 wxImageList *m_imageListSmall;
c801d85f
KB
497 wxImageList *m_imageListState; // what's that ?
498 wxListHeaderWindow *m_headerWin;
499 wxListMainWindow *m_mainWin;
a3622daa 500
b16088bf
RR
501private:
502 DECLARE_EVENT_TABLE()
503 DECLARE_DYNAMIC_CLASS(wxListCtrl);
c801d85f
KB
504};
505
506
507#endif // __LISTCTRLH_G__