]> git.saurik.com Git - wxWidgets.git/blob - include/wx/generic/listctrl.h
compile fix
[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
185 DECLARE_DYNAMIC_CLASS(wxListLineData);
186 };
187
188 //-----------------------------------------------------------------------------
189 // wxListHeaderWindow (internal)
190 //-----------------------------------------------------------------------------
191
192 class WXDLLEXPORT wxListHeaderWindow : public wxWindow
193 {
194 protected:
195 wxListMainWindow *m_owner;
196 wxCursor *m_currentCursor;
197 wxCursor *m_resizeCursor;
198 bool m_isDragging;
199 int m_column;
200 int m_minX;
201 int m_currentX;
202
203 public:
204 wxListHeaderWindow();
205 ~wxListHeaderWindow();
206 wxListHeaderWindow( wxWindow *win, wxWindowID id, wxListMainWindow *owner,
207 const wxPoint &pos = wxDefaultPosition, const wxSize &size = wxDefaultSize,
208 long style = 0, const wxString &name = "columntitles" );
209 void DoDrawRect( wxDC *dc, int x, int y, int w, int h );
210 void OnPaint( wxPaintEvent &event );
211 void DrawCurrent();
212 void OnMouse( wxMouseEvent &event );
213 void OnSetFocus( wxFocusEvent &event );
214
215 private:
216 DECLARE_DYNAMIC_CLASS(wxListHeaderWindow)
217 DECLARE_EVENT_TABLE()
218 };
219
220 //-----------------------------------------------------------------------------
221 // wxListRenameTimer (internal)
222 //-----------------------------------------------------------------------------
223
224 class WXDLLEXPORT wxListRenameTimer: public wxTimer
225 {
226 private:
227 wxListMainWindow *m_owner;
228
229 public:
230 wxListRenameTimer( wxListMainWindow *owner );
231 void Notify();
232 };
233
234 //-----------------------------------------------------------------------------
235 // wxListTextCtrl (internal)
236 //-----------------------------------------------------------------------------
237
238 class WXDLLEXPORT wxListTextCtrl: public wxTextCtrl
239 {
240 private:
241 bool *m_accept;
242 wxString *m_res;
243 wxListMainWindow *m_owner;
244 wxString m_startValue;
245
246 public:
247 wxListTextCtrl() {}
248 wxListTextCtrl( wxWindow *parent, const wxWindowID id,
249 bool *accept, wxString *res, wxListMainWindow *owner,
250 const wxString &value = "",
251 const wxPoint &pos = wxDefaultPosition, const wxSize &size = wxDefaultSize,
252 int style = 0,
253 #if wxUSE_VALIDATORS
254 const wxValidator& validator = wxDefaultValidator,
255 #endif
256 const wxString &name = "wxListTextCtrlText" );
257 void OnChar( wxKeyEvent &event );
258 void OnKillFocus( wxFocusEvent &event );
259
260 private:
261 DECLARE_DYNAMIC_CLASS(wxListTextCtrl);
262 DECLARE_EVENT_TABLE()
263 };
264
265 //-----------------------------------------------------------------------------
266 // wxListMainWindow (internal)
267 //-----------------------------------------------------------------------------
268
269 class WXDLLEXPORT wxListMainWindow: public wxScrolledWindow
270 {
271 public:
272 long m_mode;
273 wxList m_lines;
274 wxList m_columns;
275 wxListLineData *m_current;
276 wxListLineData *m_currentEdit;
277 int m_visibleLines;
278 wxBrush *m_hilightBrush;
279 wxColour *m_hilightColour;
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;
290 bool m_renameAccept;
291 wxString m_renameRes;
292 bool m_isCreated;
293 int m_dragCount;
294 wxPoint m_dragStart;
295
296 public:
297 wxListMainWindow();
298 wxListMainWindow( wxWindow *parent, wxWindowID id,
299 const wxPoint &pos = wxDefaultPosition, const wxSize &size = wxDefaultSize,
300 long style = 0, const wxString &name = "listctrl" );
301 ~wxListMainWindow();
302 void RefreshLine( wxListLineData *line );
303 void OnPaint( wxPaintEvent &event );
304 void HilightAll( bool on );
305 void SendNotify( wxListLineData *line, wxEventType command );
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 );
311
312 void EditLabel( long item );
313 void Edit( long item ) { EditLabel(item); } // deprecated
314 void OnRenameTimer();
315 void OnRenameAccept();
316
317 void OnMouse( wxMouseEvent &event );
318 void MoveToFocus();
319 void OnArrowChar( wxListLineData *newCurrent, bool shiftDown );
320 void OnChar( wxKeyEvent &event );
321 void OnKeyDown( wxKeyEvent &event );
322 void OnSetFocus( wxFocusEvent &event );
323 void OnKillFocus( wxFocusEvent &event );
324 void OnSize( wxSizeEvent &event );
325 void OnScroll(wxScrollWinEvent& event) ;
326
327 void DrawImage( int index, wxDC *dc, int x, int y );
328 void GetImageSize( int index, int &width, int &height );
329 int GetIndexOfLine( const wxListLineData *line );
330 int GetTextLength( wxString &s ); // should be const
331
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 );
339 int GetColumnCount();
340 int GetCountPerPage();
341 void SetItem( wxListItem &item );
342 void GetItem( wxListItem &item );
343 void SetItemState( long item, long state, long stateMask );
344 int GetItemState( long item, long stateMask );
345 int GetItemCount();
346 void GetItemRect( long index, wxRect &rect );
347 bool GetItemPosition( long item, wxPoint& pos );
348 int GetSelectedItemCount();
349 void SetMode( long mode );
350 long GetMode() const;
351 void CalculatePositions();
352 void RealizeChanges();
353 long GetNextItem( long item, int geometry, int state );
354 void DeleteItem( long index );
355 void DeleteAllItems();
356 void DeleteColumn( int col );
357 void DeleteEverything();
358 void EnsureVisible( long index );
359 long FindItem( long start, const wxString& str, bool partial = FALSE );
360 long FindItem( long start, long data);
361 long HitTest( int x, int y, int &flags );
362 void InsertItem( wxListItem &item );
363 // void AddItem( wxListItem &item );
364 void InsertColumn( long col, wxListItem &item );
365 // void AddColumn( wxListItem &item );
366 void SortItems( wxListCtrlCompare fn, long data );
367
368 private:
369 DECLARE_DYNAMIC_CLASS(wxListMainWindow);
370 DECLARE_EVENT_TABLE()
371 };
372
373 //-----------------------------------------------------------------------------
374 // wxListCtrl
375 //-----------------------------------------------------------------------------
376
377 class WXDLLEXPORT wxListCtrl: public wxControl
378 {
379 public:
380 wxListCtrl();
381 wxListCtrl( wxWindow *parent, wxWindowID id = -1,
382 const wxPoint &pos = wxDefaultPosition, const wxSize &size = wxDefaultSize,
383 #if wxUSE_VALIDATORS
384 long style = wxLC_ICON, const wxValidator& validator = wxDefaultValidator,
385 #endif
386 const wxString &name = "listctrl" )
387 {
388 Create(parent, id, pos, size, style, validator, name);
389 }
390 ~wxListCtrl();
391
392 bool Create( wxWindow *parent, wxWindowID id = -1,
393 const wxPoint &pos = wxDefaultPosition, const wxSize &size = wxDefaultSize,
394 #if wxUSE_VALIDATORS
395 long style = wxLC_ICON, const wxValidator& validator = wxDefaultValidator,
396 #endif
397 const wxString &name = "listctrl" );
398
399 bool GetColumn( int col, wxListItem& item ) const;
400 bool SetColumn( int col, wxListItem& item );
401 int GetColumnWidth( int col ) const;
402 bool SetColumnWidth( int col, int width);
403 int GetCountPerPage() const; // not the same in wxGLC as in Windows, I think
404
405 bool GetItem( wxListItem& info ) const;
406 bool SetItem( wxListItem& info ) ;
407 long SetItem( long index, int col, const wxString& label, int imageId = -1 );
408 int GetItemState( long item, long stateMask ) const;
409 bool SetItemState( long item, long state, long stateMask);
410 bool SetItemImage( long item, int image, int selImage);
411 wxString GetItemText( long item ) const;
412 void SetItemText( long item, const wxString& str );
413 long GetItemData( long item ) const;
414 bool SetItemData( long item, long data );
415 bool GetItemRect( long item, wxRect& rect, int code = wxLIST_RECT_BOUNDS ) const;
416 bool GetItemPosition( long item, wxPoint& pos ) const;
417 bool SetItemPosition( long item, const wxPoint& pos ); // not supported in wxGLC
418 int GetItemCount() const;
419 int GetColumnCount() const;
420 void SetItemSpacing( int spacing, bool isSmall = FALSE );
421 int GetItemSpacing( bool isSmall ) const;
422 int GetSelectedItemCount() const;
423 wxColour GetTextColour() const;
424 void SetTextColour(const wxColour& col);
425 long GetTopItem() const;
426
427 void SetSingleStyle( long style, bool add = TRUE ) ;
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 );
433 bool Arrange( int flag = wxLIST_ALIGN_DEFAULT ); // always wxLIST_ALIGN_LEFT in wxGLC
434
435 void ClearAll();
436 bool DeleteItem( long item );
437 bool DeleteAllItems();
438 bool DeleteAllColumns();
439 bool DeleteColumn( int col );
440
441 void EditLabel( long item ) { Edit(item); }
442 void Edit( long item );
443
444 bool EnsureVisible( long item );
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);
449 long InsertItem(wxListItem& info);
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 );
459
460 void OnIdle( wxIdleEvent &event );
461 void OnSize( wxSizeEvent &event );
462
463 // We have to hand down a few functions
464
465 bool SetBackgroundColour( const wxColour &colour );
466 bool SetForegroundColour( const wxColour &colour );
467 bool SetFont( const wxFont &font );
468
469 #if wxUSE_DRAG_AND_DROP
470 void SetDropTarget( wxDropTarget *dropTarget )
471 { m_mainWin->SetDropTarget( dropTarget ); }
472 wxDropTarget *GetDropTarget() const
473 { return m_mainWin->GetDropTarget(); }
474 #endif
475
476 bool SetCursor( const wxCursor &cursor )
477 { return m_mainWin ? m_mainWin->wxWindow::SetCursor(cursor) : FALSE; }
478 wxColour GetBackgroundColour() const
479 { return m_mainWin ? m_mainWin->GetBackgroundColour() : wxColour(); }
480 wxColour GetForegroundColour() const
481 { return m_mainWin ? m_mainWin->GetForegroundColour() : wxColour(); }
482 bool DoPopupMenu( wxMenu *menu, int x, int y )
483 { return m_mainWin->PopupMenu( menu, x, y ); }
484 void SetFocus()
485 {
486 /* The test in window.cpp fails as we are a composite
487 window, so it checks against "this", but not m_mainWin. */
488 if (FindFocus() != this)
489 m_mainWin->SetFocus();
490 }
491
492 // implementation
493 // --------------
494
495 wxImageList *m_imageListNormal;
496 wxImageList *m_imageListSmall;
497 wxImageList *m_imageListState; // what's that ?
498 wxListHeaderWindow *m_headerWin;
499 wxListMainWindow *m_mainWin;
500
501 private:
502 DECLARE_EVENT_TABLE()
503 DECLARE_DYNAMIC_CLASS(wxListCtrl);
504 };
505
506
507 #endif // __LISTCTRLH_G__