]> git.saurik.com Git - wxWidgets.git/blob - include/wx/generic/listctrl.h
Add some "USE" defs that were missing.
[wxWidgets.git] / include / wx / generic / listctrl.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/generic/listctrl.h
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
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 #ifndef __LISTCTRLH_G__
12 #define __LISTCTRLH_G__
13
14 #ifdef __GNUG__
15 #pragma interface "listctrl.h"
16 #endif
17
18 #include "wx/defs.h"
19 #include "wx/object.h"
20 #include "wx/generic/imaglist.h"
21 #include "wx/control.h"
22 #include "wx/timer.h"
23 #include "wx/textctrl.h"
24 #include "wx/dcclient.h"
25 #include "wx/scrolwin.h"
26 #include "wx/settings.h"
27
28 #if wxUSE_DRAG_AND_DROP
29 class WXDLLEXPORT wxDropTarget;
30 #endif
31
32 //-----------------------------------------------------------------------------
33 // classes
34 //-----------------------------------------------------------------------------
35
36 class WXDLLEXPORT wxListItem;
37 class WXDLLEXPORT wxListEvent;
38 class WXDLLEXPORT wxListCtrl;
39
40 //-----------------------------------------------------------------------------
41 // internal classes
42 //-----------------------------------------------------------------------------
43
44 class WXDLLEXPORT wxListHeaderData;
45 class WXDLLEXPORT wxListItemData;
46 class WXDLLEXPORT wxListLineData;
47
48 class WXDLLEXPORT wxListHeaderWindow;
49 class WXDLLEXPORT wxListMainWindow;
50
51 class WXDLLEXPORT wxListRenameTimer;
52 class WXDLLEXPORT wxListTextCtrl;
53
54 //-----------------------------------------------------------------------------
55 // wxListItemData (internal)
56 //-----------------------------------------------------------------------------
57
58 class WXDLLEXPORT wxListItemData : public wxObject
59 {
60 public:
61 wxString m_text;
62 int m_image;
63 long m_data;
64 int m_xpos,m_ypos;
65 int m_width,m_height;
66
67 wxListItemAttr *m_attr;
68
69 public:
70 wxListItemData();
71 ~wxListItemData() { delete m_attr; }
72
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;
81 bool HasText() 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;
87 int GetWidth() const;
88 int GetHeight() const;
89 int GetImage() const;
90 void GetItem( wxListItem &info ) const;
91
92 wxListItemAttr *GetAttributes() const { return m_attr; }
93
94 private:
95 DECLARE_DYNAMIC_CLASS(wxListItemData);
96 };
97
98 //-----------------------------------------------------------------------------
99 // wxListHeaderData (internal)
100 //-----------------------------------------------------------------------------
101
102 class WXDLLEXPORT wxListHeaderData : public wxObject
103 {
104 protected:
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;
112
113 public:
114 wxListHeaderData();
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;
129
130 private:
131 DECLARE_DYNAMIC_CLASS(wxListHeaderData);
132 };
133
134 //-----------------------------------------------------------------------------
135 // wxListLineData (internal)
136 //-----------------------------------------------------------------------------
137
138 class WXDLLEXPORT wxListLineData : public wxObject
139 {
140 public:
141 wxList m_items;
142 wxRect m_bound_all;
143 wxRect m_bound_label;
144 wxRect m_bound_icon;
145 wxRect m_bound_hilight;
146 int m_mode;
147 bool m_hilighted;
148 wxBrush *m_hilightBrush;
149 int m_spacing;
150 wxListMainWindow *m_owner;
151
152 void DoDraw( wxDC *dc, bool hilight, bool paintBG );
153
154 public:
155 wxListLineData() {}
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 );
176 bool IsHilighted();
177 void AssignRect( wxRect &dest, int x, int y, int width, int height );
178 void AssignRect( wxRect &dest, const wxRect &source );
179
180 private:
181 void SetAttributes(wxDC *dc,
182 const wxListItemAttr *attr,
183 const wxColour& colText, const wxFont& font,
184 bool hilight);
185
186 DECLARE_DYNAMIC_CLASS(wxListLineData);
187 };
188
189 //-----------------------------------------------------------------------------
190 // wxListHeaderWindow (internal)
191 //-----------------------------------------------------------------------------
192
193 class WXDLLEXPORT wxListHeaderWindow : public wxWindow
194 {
195 protected:
196 wxListMainWindow *m_owner;
197 wxCursor *m_currentCursor;
198 wxCursor *m_resizeCursor;
199 bool m_isDragging;
200 int m_column;
201 int m_minX;
202 int m_currentX;
203
204 public:
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 );
212 void DrawCurrent();
213 void OnMouse( wxMouseEvent &event );
214 void OnSetFocus( wxFocusEvent &event );
215
216 private:
217 DECLARE_DYNAMIC_CLASS(wxListHeaderWindow)
218 DECLARE_EVENT_TABLE()
219 };
220
221 //-----------------------------------------------------------------------------
222 // wxListRenameTimer (internal)
223 //-----------------------------------------------------------------------------
224
225 class WXDLLEXPORT wxListRenameTimer: public wxTimer
226 {
227 private:
228 wxListMainWindow *m_owner;
229
230 public:
231 wxListRenameTimer( wxListMainWindow *owner );
232 void Notify();
233 };
234
235 //-----------------------------------------------------------------------------
236 // wxListTextCtrl (internal)
237 //-----------------------------------------------------------------------------
238
239 class WXDLLEXPORT wxListTextCtrl: public wxTextCtrl
240 {
241 private:
242 bool *m_accept;
243 wxString *m_res;
244 wxListMainWindow *m_owner;
245 wxString m_startValue;
246
247 public:
248 wxListTextCtrl() {}
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,
253 int style = 0,
254 #if wxUSE_VALIDATORS
255 const wxValidator& validator = wxDefaultValidator,
256 #endif
257 const wxString &name = "wxListTextCtrlText" );
258 void OnChar( wxKeyEvent &event );
259 void OnKillFocus( wxFocusEvent &event );
260
261 private:
262 DECLARE_DYNAMIC_CLASS(wxListTextCtrl);
263 DECLARE_EVENT_TABLE()
264 };
265
266 //-----------------------------------------------------------------------------
267 // wxListMainWindow (internal)
268 //-----------------------------------------------------------------------------
269
270 class WXDLLEXPORT wxListMainWindow: public wxScrolledWindow
271 {
272 public:
273 long m_mode;
274 wxList m_lines;
275 wxList m_columns;
276 wxListLineData *m_current;
277 wxListLineData *m_currentEdit;
278 int m_visibleLines;
279 wxBrush *m_hilightBrush;
280 wxColour *m_hilightColour;
281 int m_xScroll,m_yScroll;
282 bool m_dirty;
283 wxImageList *m_small_image_list;
284 wxImageList *m_normal_image_list;
285 int m_small_spacing;
286 int m_normal_spacing;
287 bool m_hasFocus;
288 bool m_usedKeys;
289 bool m_lastOnSame;
290 wxTimer *m_renameTimer;
291 bool m_renameAccept;
292 wxString m_renameRes;
293 bool m_isCreated;
294 int m_dragCount;
295 wxPoint m_dragStart;
296
297 public:
298 wxListMainWindow();
299 wxListMainWindow( wxWindow *parent, wxWindowID id,
300 const wxPoint &pos = wxDefaultPosition, const wxSize &size = wxDefaultSize,
301 long style = 0, const wxString &name = "listctrl" );
302 ~wxListMainWindow();
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 );
312
313 void EditLabel( long item );
314 void Edit( long item ) { EditLabel(item); } // deprecated
315 void OnRenameTimer();
316 void OnRenameAccept();
317
318 void OnMouse( wxMouseEvent &event );
319 void MoveToFocus();
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) ;
327
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
332
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 );
346 int GetItemCount();
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 );
368
369 private:
370 DECLARE_DYNAMIC_CLASS(wxListMainWindow);
371 DECLARE_EVENT_TABLE()
372 };
373
374 //-----------------------------------------------------------------------------
375 // wxListCtrl
376 //-----------------------------------------------------------------------------
377
378 class WXDLLEXPORT wxListCtrl: public wxControl
379 {
380 public:
381 wxListCtrl();
382 wxListCtrl( wxWindow *parent, wxWindowID id = -1,
383 const wxPoint &pos = wxDefaultPosition, const wxSize &size = wxDefaultSize,
384 #if wxUSE_VALIDATORS
385 long style = wxLC_ICON, const wxValidator& validator = wxDefaultValidator,
386 #endif
387 const wxString &name = "listctrl" )
388 {
389 Create(parent, id, pos, size, style, validator, name);
390 }
391 ~wxListCtrl();
392
393 bool Create( wxWindow *parent, wxWindowID id = -1,
394 const wxPoint &pos = wxDefaultPosition, const wxSize &size = wxDefaultSize,
395 #if wxUSE_VALIDATORS
396 long style = wxLC_ICON, const wxValidator& validator = wxDefaultValidator,
397 #endif
398 const wxString &name = "listctrl" );
399
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
405
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;
427
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
435
436 void ClearAll();
437 bool DeleteItem( long item );
438 bool DeleteAllItems();
439 bool DeleteAllColumns();
440 bool DeleteColumn( int col );
441
442 void EditLabel( long item ) { Edit(item); }
443 void Edit( long item );
444
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,
456 int width = -1 );
457 bool ScrollList( int dx, int dy );
458 bool SortItems( wxListCtrlCompare fn, long data );
459 bool Update( long item );
460
461 void OnIdle( wxIdleEvent &event );
462 void OnSize( wxSizeEvent &event );
463
464 // We have to hand down a few functions
465
466 bool SetBackgroundColour( const wxColour &colour );
467 bool SetForegroundColour( const wxColour &colour );
468 bool SetFont( const wxFont &font );
469
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(); }
475 #endif
476
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 ); }
485 void SetFocus()
486 {
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();
491 }
492
493 // implementation
494 // --------------
495
496 wxImageList *m_imageListNormal;
497 wxImageList *m_imageListSmall;
498 wxImageList *m_imageListState; // what's that ?
499 wxListHeaderWindow *m_headerWin;
500 wxListMainWindow *m_mainWin;
501
502 private:
503 DECLARE_EVENT_TABLE()
504 DECLARE_DYNAMIC_CLASS(wxListCtrl);
505 };
506
507
508 #endif // __LISTCTRLH_G__