1 /////////////////////////////////////////////////////////////////////////////// 2 // Name: wx/os2/listctrl.h 3 // Purpose: wxListCtrl class 4 // Author: 5 // Modified by: 6 // Created: 7 // Copyright: (c) wxWidgets team 8 // Licence: wxWindows licence 9 /////////////////////////////////////////////////////////////////////////////// 10 11 #ifndef _WX_LISTCTRL_H_ 12 #define _WX_LISTCTRL_H_ 13 14 #if wxUSE_LISTCTRL 15 16 #include "wx/control.h" 17 #include "wx/event.h" 18 #include "wx/hash.h" 19 #include "wx/textctrl.h" 20 21 22 class WXDLLIMPEXP_FWD_CORE wxImageList; 23 24 typedef int (wxCALLBACK *wxListCtrlCompare)(long lItem1, long lItem2, long lSortData); 25 26 class WXDLLIMPEXP_CORE wxListCtrl: public wxControl 27 { 28 public: wxListCtrl()29 wxListCtrl() { Init(); } 30 wxListCtrl( wxWindow* pParent 31 ,wxWindowID vId = -1 32 ,const wxPoint& rPos = wxDefaultPosition 33 ,const wxSize& rSize = wxDefaultSize 34 ,long lStyle = wxLC_ICON 35 ,const wxValidator& rValidator = wxDefaultValidator 36 ,const wxString& rsName = wxListCtrlNameStr) 37 { 38 Init(); 39 Create( pParent 40 ,vId 41 ,rPos 42 ,rSize 43 ,lStyle 44 ,rValidator 45 ,rsName 46 ); 47 } 48 virtual ~wxListCtrl(); 49 50 bool Create( wxWindow* pParent 51 ,wxWindowID vId = -1 52 ,const wxPoint& rPos = wxDefaultPosition 53 ,const wxSize& rSize = wxDefaultSize 54 ,long lStyle = wxLC_ICON 55 ,const wxValidator& rValidator = wxDefaultValidator 56 ,const wxString& rsName = wxListCtrlNameStr 57 ); 58 59 60 // Attributes 61 //////////////////////////////////////////////////////////////////////////// 62 // 63 64 // 65 // Set the control colours 66 // 67 bool SetForegroundColour(const wxColour& rCol); 68 bool SetBackgroundColour(const wxColour& rCol); 69 70 // 71 // Information about this column 72 // 73 bool GetColumn( int nCol 74 ,wxListItem& rItem 75 ) const; 76 bool SetColumn( int nCol 77 ,wxListItem& rItem 78 ); 79 80 // 81 // Column width 82 // 83 int GetColumnWidth(int nCol) const; 84 bool SetColumnWidth( int nCol 85 ,int nWidth 86 ); 87 88 // 89 // Gets the number of items that can fit vertically in the 90 // visible area of the list control (list or report view) 91 // or the total number of items in the list control (icon 92 // or small icon view) 93 // 94 int GetCountPerPage(void) const; 95 96 wxRect GetViewRect() const; 97 // 98 // Gets the edit control for editing labels. 99 // 100 wxTextCtrl* GetEditControl(void) const; 101 102 // 103 // Information about the item 104 // 105 bool GetItem(wxListItem& rInfo) const; 106 bool SetItem(wxListItem& rInfo); 107 108 // 109 // Sets a string field at a particular column 110 // 111 long SetItem( long lIndex 112 ,int nCol 113 ,const wxString& rsLabel 114 ,int nImageId = -1 115 ); 116 117 // 118 // Item state 119 // 120 int GetItemState( long lItem 121 ,long lStateMask 122 ) const; 123 bool SetItemState( long lItem 124 ,long lState 125 ,long lStateMask 126 ); 127 128 // 129 // Sets the item image 130 // 131 bool SetItemImage( long lItem 132 ,int nImage 133 ,int lSelImage 134 ); 135 bool SetItemColumnImage( long lItem 136 ,long lColumn 137 ,int nImage 138 ); 139 140 // 141 // Item text 142 // 143 wxString GetItemText(long lItem) const; 144 void SetItemText( long lItem 145 ,const wxString& rsStr 146 ); 147 148 // 149 // Item data 150 // 151 long GetItemData(long lItem) const; 152 bool SetItemPtrData(long item, wxUIntPtr data); SetItemData(long item,long data)153 bool SetItemData(long item, long data) { return SetItemPtrData(item, data); } 154 155 // 156 // Gets the item rectangle 157 // 158 bool GetItemRect( long lItem 159 ,wxRect& rRect 160 ,int nCode = wxLIST_RECT_BOUNDS 161 ) const; 162 163 // 164 // Item position 165 // 166 bool GetItemPosition( long lItem 167 ,wxPoint& rPos 168 ) const; 169 bool SetItemPosition( long lItem 170 ,const wxPoint& rPos 171 ); 172 173 // 174 // Gets the number of items in the list control 175 // 176 int GetItemCount(void) const; 177 178 // 179 // Gets the number of columns in the list control 180 // GetColumnCount(void)181 inline int GetColumnCount(void) const { return m_nColCount; } 182 183 // 184 // Retrieves the spacing between icons in pixels. 185 // If bIsSmall is true, gets the spacing for the small icon 186 // view, otherwise the large icon view. 187 // 188 int GetItemSpacing(bool bIsSmall) const; 189 190 // 191 // Foreground colour of an item. 192 // 193 wxColour GetItemTextColour(long lItem) const; 194 void SetItemTextColour( long lItem 195 ,const wxColour& rCol 196 ); 197 198 // 199 // Background colour of an item. 200 // 201 wxColour GetItemBackgroundColour(long lItem ) const; 202 void SetItemBackgroundColour( long lItem 203 ,const wxColour& rCol 204 ); 205 206 // 207 // Gets the number of selected items in the list control 208 // 209 int GetSelectedItemCount(void) const; 210 211 // 212 // Text colour of the listview 213 // 214 wxColour GetTextColour(void) const; 215 void SetTextColour(const wxColour& rCol); 216 217 // 218 // Gets the index of the topmost visible item when in 219 // list or report view 220 // 221 long GetTopItem(void) const; 222 223 // 224 // Add or remove a single window style 225 void SetSingleStyle( long lStyle 226 ,bool bAdd = true 227 ); 228 229 // 230 // Set the whole window style 231 // 232 void SetWindowStyleFlag(long lStyle); 233 234 // 235 // Searches for an item, starting from 'item'. 236 // item can be -1 to find the first item that matches the 237 // specified flags. 238 // Returns the item or -1 if unsuccessful. 239 long GetNextItem( long lItem 240 ,int nGeometry = wxLIST_NEXT_ALL 241 ,int lState = wxLIST_STATE_DONTCARE 242 ) const; 243 244 // 245 // Gets one of the three image lists 246 // 247 wxImageList* GetImageList(int nWhich) const; 248 249 // 250 // Sets the image list 251 // 252 void SetImageList( wxImageList* pImageList 253 ,int nWhich 254 ); 255 void AssignImageList( wxImageList* pImageList 256 ,int nWhich 257 ); 258 259 // 260 // Returns true if it is a virtual list control 261 // IsVirtual()262 inline bool IsVirtual() const { return (GetWindowStyle() & wxLC_VIRTUAL) != 0; } 263 264 // 265 // Refresh items selectively (only useful for virtual list controls) 266 // 267 void RefreshItem(long lItem); 268 void RefreshItems( long lItemFrom 269 ,long lItemTo 270 ); 271 272 // 273 // Operations 274 //////////////////////////////////////////////////////////////////////////// 275 // 276 277 // 278 // Arranges the items 279 // 280 bool Arrange(int nFlag = wxLIST_ALIGN_DEFAULT); 281 282 // 283 // Deletes an item 284 // 285 bool DeleteItem(long lItem); 286 287 // 288 // Deletes all items 289 bool DeleteAllItems(void); 290 291 // 292 // Deletes a column 293 // 294 bool DeleteColumn(int nCol); 295 296 // 297 // Deletes all columns 298 // 299 bool DeleteAllColumns(void); 300 301 // 302 // Clears items, and columns if there are any. 303 // 304 void ClearAll(void); 305 306 // 307 // Edit the label 308 // 309 wxTextCtrl* EditLabel( long lItem 310 ,wxClassInfo* pTextControlClass = wxCLASSINFO(wxTextCtrl) 311 ); 312 313 // 314 // End label editing, optionally cancelling the edit 315 // 316 bool EndEditLabel(bool bCancel); 317 318 // 319 // Ensures this item is visible 320 // 321 bool EnsureVisible(long lItem); 322 323 // 324 // Find an item whose label matches this string, starting from the item after 'start' 325 // or the beginning if 'start' is -1. 326 // 327 long FindItem( long lStart 328 ,const wxString& rsStr 329 ,bool bPartial = false 330 ); 331 332 // 333 // Find an item whose data matches this data, starting from the item after 'start' 334 // or the beginning if 'start' is -1. 335 // 336 long FindItem( long lStart 337 ,long lData 338 ); 339 340 // 341 // Find an item nearest this position in the specified direction, starting from 342 // the item after 'start' or the beginning if 'start' is -1. 343 // 344 long FindItem( long lStart 345 ,const wxPoint& rPoint 346 ,int lDirection 347 ); 348 349 // 350 // Determines which item (if any) is at the specified point, 351 // giving details in 'flags' (see wxLIST_HITTEST_... flags above) 352 // 353 long HitTest( const wxPoint& rPoint 354 ,int& rFlags 355 ); 356 357 // 358 // Inserts an item, returning the index of the new item if successful, 359 // -1 otherwise. 360 // 361 long InsertItem(wxListItem& rInfo); 362 363 // 364 // Insert a string item 365 // 366 long InsertItem( long lIndex 367 ,const wxString& rsLabel 368 ); 369 370 // 371 // Insert an image item 372 // 373 long InsertItem( long lIndex 374 ,int nImageIndex 375 ); 376 377 // 378 // Insert an image/string item 379 // 380 long InsertItem( long lIndex 381 ,const wxString& rsLabel 382 ,int nImageIndex 383 ); 384 385 // 386 // For list view mode (only), inserts a column. 387 // 388 long InsertColumn( long lCol 389 ,wxListItem& rInfo 390 ); 391 392 long InsertColumn( long lCol 393 ,const wxString& rsHeading 394 ,int nFormat = wxLIST_FORMAT_LEFT 395 ,int lWidth = -1 396 ); 397 398 // 399 // set the number of items in a virtual list control 400 // 401 void SetItemCount(long lCount); 402 403 // 404 // Scrolls the list control. If in icon, small icon or report view mode, 405 // x specifies the number of pixels to scroll. If in list view mode, x 406 // specifies the number of columns to scroll. 407 // If in icon, small icon or list view mode, y specifies the number of pixels 408 // to scroll. If in report view mode, y specifies the number of lines to scroll. 409 // 410 bool ScrollList( int nDx 411 ,int nDy 412 ); 413 414 // Sort items. 415 416 // 417 // fn is a function which takes 3 long arguments: item1, item2, data. 418 // item1 is the long data associated with a first item (NOT the index). 419 // item2 is the long data associated with a second item (NOT the index). 420 // data is the same value as passed to SortItems. 421 // The return value is a negative number if the first item should precede the second 422 // item, a positive number of the second item should precede the first, 423 // or zero if the two items are equivalent. 424 // 425 // data is arbitrary data to be passed to the sort function. 426 // 427 bool SortItems( wxListCtrlCompare fn 428 ,long lData 429 ); 430 431 // 432 // IMPLEMENTATION 433 // -------------- 434 // 435 virtual bool OS2Command( WXUINT uParam 436 ,WXWORD wId 437 ); 438 // 439 // Bring the control in sync with current m_windowStyle value 440 // 441 void UpdateStyle(void); 442 443 // 444 // Implementation: converts wxWidgets style to MSW style. 445 // Can be a single style flag or a bit list. 446 // oldStyle is 'normalised' so that it doesn't contain 447 // conflicting styles. 448 // 449 long ConvertToOS2Style( long& lOldStyle 450 ,long lStyle 451 ) const; 452 long ConvertArrangeToOS2Style(long lStyle); 453 long ConvertViewToOS2Style(long lStyle); 454 455 virtual MRESULT OS2WindowProc( WXUINT uMsg 456 ,WXWPARAM wParam 457 ,WXLPARAM lParam 458 ); 459 460 // Event handlers 461 //////////////////////////////////////////////////////////////////////////// 462 // Necessary for drawing hrules and vrules, if specified 463 void OnPaint(wxPaintEvent& rEvent); 464 465 protected: 466 // 467 // common part of all ctors 468 // 469 void Init(void); 470 471 // 472 // Free memory taken by all internal data 473 // 474 void FreeAllInternalData(void); 475 476 wxTextCtrl* m_pTextCtrl; // The control used for editing a label 477 wxImageList* m_pImageListNormal; // The image list for normal icons 478 wxImageList* m_pImageListSmall; // The image list for small icons 479 wxImageList* m_pImageListState; // The image list state icons (not implemented yet) 480 bool m_bOwnsImageListNormal; 481 bool m_bOwnsImageListSmall; 482 bool m_bOwnsImageListState; 483 long m_lBaseStyle; // Basic PM style flags, for recreation purposes 484 int m_nColCount; // PM doesn't have GetColumnCount so must 485 // keep track of inserted/deleted columns 486 487 // 488 // true if we have any internal data (user data & attributes) 489 // 490 bool m_bAnyInternalData; 491 492 // 493 // true if we have any items with custom attributes 494 // 495 bool m_bHasAnyAttr; 496 497 // 498 // These functions are only used for virtual list view controls, i.e. the 499 // ones with wxLC_VIRTUAL style 500 // 501 // return the text for the given column of the given item 502 // 503 virtual wxString OnGetItemText( long lItem 504 ,long lColumn 505 ) const; 506 507 // 508 // Return the icon for the given item. In report view, OnGetItemImage will 509 // only be called for the first column. See OnGetItemColumnImage for 510 // details. 511 // 512 virtual int OnGetItemImage(long lItem) const; 513 514 // 515 // Return the icon for the given item and column 516 // 517 virtual int OnGetItemColumnImage(long lItem, long lColumn) const; 518 519 // 520 // Return the attribute for the item (may return NULL if none) 521 // 522 virtual wxListItemAttr* OnGetItemAttr(long lItem) const; 523 524 private: 525 bool DoCreateControl( int nX 526 ,int nY 527 ,int nWidth 528 ,int nHeight 529 ); 530 531 DECLARE_DYNAMIC_CLASS(wxListCtrl) 532 DECLARE_EVENT_TABLE() 533 wxDECLARE_NO_COPY_CLASS(wxListCtrl); 534 }; // end of CLASS wxListCtrl 535 536 #endif // wxUSE_LISTCTRL 537 538 #endif // _WX_LISTCTRL_H_ 539 540