grid.h

Go to the documentation of this file.
00001 /**
00002  * \file mgui/grid.h
00003  * \brief MGUI::CTRL_GRID class definitions
00004  *
00005  * \if NODOC
00006  * $Id: grid.h_v 1.53 2005/06/29 17:44:31 mju Exp $
00007  *
00008  * $Log: grid.h_v $
00009  * Revision 1.53  2005/06/29 17:44:31  mju
00010  * Template ctor needs to init onUserResizeColumnFunc.
00011  *
00012  * Revision 1.52  2005/05/23 23:12:16  dfriberg
00013  * Added virtual methods for column resize and order change
00014  *
00015  * Revision 1.51  2005/03/31 16:57:08  fileserver!dwilliss
00016  * Rename one of our types to MIUNICODE because it conflicted with a Microsoft #define
00017  *
00018  * Revision 1.50  2005/02/14 17:45:10  dwilliss
00019  * Changed parameters to method that I just added. Use const MISTRING& instead
00020  * of const MIUNICODE*
00021  *
00022  * Revision 1.49  2005/02/14 16:59:54  dwilliss
00023  * Added a new method
00024  *
00025  * Revision 1.48  2004/11/08 15:41:39  mju
00026  * Change lpoint2d to struct so matches previous defns.
00027  *
00028  * Revision 1.47  2004/11/04 20:31:49  dwilliss
00029  * added lpoint2D to OnRightClickItem
00030  *
00031  * Revision 1.46  2004/05/28 21:44:28  mju
00032  * Add methods using mistring.
00033  *
00034  * Revision 1.45  2004/05/25 15:09:50  mju
00035  * OnEndLabelEdit now uses non-const string.
00036  *
00037  * Revision 1.44  2003/10/27 21:22:32  mju
00038  * Remove SetItemFocus as done automatically by SetItemSelected.
00039  *
00040  * Revision 1.43  2003/10/03 19:58:19  linux32build!build
00041  * Doxygen
00042  *
00043  * Revision 1.42  2003/09/15 13:49:32  fileserver!dwilliss
00044  * Doxygen
00045  *
00046  * Revision 1.41  2003/09/11 16:59:18  mju
00047  * Specify namespace for ID in case ambiguous
00048  *
00049  * Revision 1.40  2003/09/10 21:30:48  mju
00050  * Use MGUI::ID for "item data".
00051  *
00052  * Revision 1.39  2003/07/24 20:13:09  dwilliss
00053  * Added a STYLE type
00054  *
00055  * Revision 1.38  2003/04/09 20:50:59  dwilliss
00056  * Don't use _T in tmplates. Mac's ctype.h defines a global _T
00057  *
00058  * Revision 1.37  2003/01/27 18:54:28  mju
00059  * Add GetHeadingHeight.
00060  *
00061  * Revision 1.36  2003/01/24 21:05:28  mju
00062  * Add InsertItem methods taking position.
00063  *
00064  * Revision 1.35  2003/01/24 20:41:10  mju
00065  * Add EditItem methods.
00066  *
00067  * Revision 1.34  2003/01/23 20:18:07  mju
00068  * Make all methods referencing wrapped control non-inline.
00069  *
00070  * Revision 1.33  2003/01/15 18:29:51  mju
00071  * Remove #ifdefed-out methods.
00072  *
00073  * Revision 1.32  2003/01/06 18:15:30  dwilliss
00074  * Typo in template
00075  *
00076  * Revision 1.31  2003/01/06 17:47:59  dwilliss
00077  * Added members to keep track of previously selected item so that we can
00078  * implement multiselect
00079  *
00080  * Revision 1.30  2003/01/06 15:45:14  dwilliss
00081  * Revert back to Mike's fix.  I didn't realize he had "fixed" it for me in
00082  * a way counter to the way I would have done it.
00083  *
00084  * Revision 1.28  2003/01/06 14:08:24  mju
00085  * Fix template to use correct signature for onitemselect/unselect.
00086  *
00087  * Revision 1.27  2003/01/03 23:09:11  dwilliss
00088  * almost right...
00089  *
00090  * Revision 1.26  2003/01/03 23:04:11  dwilliss
00091  * OnItemSelect/Unselect need to return bool on the actual control used in X
00092  *
00093  * Revision 1.25  2002/12/11 15:20:35  mju
00094  * Move contrib stuff here.
00095  *
00096  * Revision 1.24  2002/10/24 21:51:46  dwilliss
00097  * Had broken something in MFC-only code
00098  *
00099  * Revision 1.23  2002/10/24 20:52:19  dwilliss
00100  * Fixed sorting issues
00101  *
00102  * Revision 1.22  2002/10/11 14:50:15  dwilliss
00103  * Moved KEYSTATE enum out of this control and into ctrl.h
00104  *
00105  * Revision 1.21  2002/10/10 19:49:40  dwilliss
00106  * Took out a method that shouldn't be there
00107  *
00108  * Revision 1.20  2002/10/10 17:57:14  dwilliss
00109  * Made the KEYSTATE enum ORable.  The MIGRID that the X version is implemented
00110  * on now passes keyboard state through the OnLClicked methods
00111  *
00112  * Revision 1.19  2002/10/10 17:15:10  dwilliss
00113  * Added a KEYSTATE enum and parameter to all the OnClickXxx methods
00114  *
00115  * Revision 1.18  2002/10/09 16:35:29  mju
00116  * Rename as 'grid.h'.
00117  *
00118  * Revision 1.17  2002/10/09 16:07:48  mju
00119  * Moved to 'mgui' folder.
00120  *
00121  * Revision 1.16  2002/10/09 14:18:43  dwilliss
00122  * Change CUSTOMDRAW to call the HDC "gc" so it's the same name in X and MFC
00123  *
00124  * Revision 1.14  2002/06/07 15:58:26  dwilliss
00125  * OnGetDispInfo now returns bool
00126  *
00127  * Revision 1.13  2002/05/17 15:28:07  dwilliss
00128  * OnClickColumn defined inconsistantly between base and derived class - FIXED
00129  * Constructor had stupid compile error that only the Mac caught.
00130  *
00131  * Revision 1.12  2002/04/05 21:40:28  dwilliss
00132  * SetExtendedStyle() shouldn't be private
00133  *
00134  * Revision 1.11  2002/03/15 22:32:20  dwilliss
00135  * If not BeginLabelEditFunc() set in template, default should depend on
00136  * STYLE_EditLabels flag, not just always true
00137  *
00138  * Revision 1.10  2002/02/19 20:21:31  dwilliss
00139  * OnEditStart actually cancels the edit for X now
00140  *
00141  * Revision 1.6  2002/02/14 17:15:25  dwilliss
00142  * Added methods to delete columns
00143  *
00144  * Revision 1.5  2002/02/12 17:03:46  dwilliss
00145  * X implementation almost done
00146  *
00147  * Revision 1.3  2002/02/08 23:16:16  dwilliss
00148  * OnDrawItem now takes a struct with parameters instead of a bunch of parms
00149  *
00150  * Revision 1.2  2002/02/08 22:16:51  dwilliss
00151  * Compiles for both X and MFC now.  Renamed to CTRL_GRID (was CTRL_LIST)
00152  *
00153  * Revision 1.1  2002/02/04 18:48:22  dwilliss
00154  * Initial revision
00155  *
00156  * 
00157  * 2     12/13/01 10:55a Mju
00158  * MGUI unificiation with X.
00159  * 
00160  * 1     12/03/01 9:41a Mju
00161  * \endif
00162 **/
00163 
00164 #ifndef  INC_MGUI_GRID_H
00165 #define  INC_MGUI_GRID_H
00166 
00167 #ifndef  INC_MGUI_CTRL_H
00168 #include <mgui/ctrl.h>
00169 #endif
00170 
00171 namespace MGD {
00172    class CONTEXT;
00173    }
00174 
00175 struct LPOINT2D;
00176 
00177 namespace MGUI {
00178 
00179 class IMAGELIST;
00180 
00181 //------------------------------------------------------------------------------------------------
00182 //! Grid user interface class.
00183 //! There is also a MGUI::CTRL_GRID_T template which helps eliminate the need for subclassing.  See
00184 //! the description for MGUI::CTRL for more information on using templates.
00185 //! There are two general ways to work with lists, "standard" and "owner-data" (virtual).  In the
00186 //! standard configuration the list control itself contains all of the data (strings, icons, states)
00187 //! for each list entry.  In the "owner-data" configuration, the data is stored outside the list
00188 //! and the OnGetDispInfo and OnOwnerDataCacheHint methods are overridden (or set when using the
00189 //! template) and will be called by the list control when data is needed to be displayed in the list.
00190 class CTRL_GRID : public MGUI::CTRL {
00191    public:
00192 
00193       // Note: enum constants are the same values as the MFC #defines but hard-coded since they're not defined in the X case (alternative was ugly repetition)
00194       enum FORMAT {
00195          FORMAT_Left =           0, //!< LVCFMT_LEFT,
00196          FORMAT_Right =          1, //!< LVCFMT_RIGHT
00197          FORMAT_Center =         2  //!< LVCFMT_CENTER,
00198          };
00199 
00200       enum STYLE {
00201          STYLE_AlignLeft =       0x0800,  //!<LVS_ALIGNLEFT,
00202          STYLE_AlignTop =        0x0000,  //!<LVS_ALIGNTOP,
00203          STYLE_AutoArrange =     0x0100,  //!<LVS_AUTOARRANGE,
00204          STYLE_EditLabels =      0x0200,  //!<LVS_EDITLABELS,
00205          STYLE_NoColumnHeader =  0x4000,  //!<LVS_NOCOLUMNHEADER,
00206          STYLE_NoLabelWrap =     0x0080,  //!<LVS_NOLABELWRAP,
00207          STYLE_NoScroll =        0x2000,  //!<LVS_NOSCROLL,
00208          STYLE_NoSortHeader =    0x8000,  //!<LVS_NOSORTHEADER,
00209          STYLE_OwnerData =       0x1000,  //!<LVS_OWNERDATA,
00210          STYLE_ShowSelAlways =   0x0008,  //!<LVS_SHOWSELALWAYS,
00211          STYLE_NoGridLines =     0x0001,  //!<
00212          STYLE_SingleSel =       0x0004,  //!<LVS_SINGLESEL,
00213          STYLE_SortAscending =   0x0010,  //!<LVS_SORTASCENDING,
00214          STYLE_SortDescending =  0x0020   //!<LVS_SORTDESCENDING
00215          };
00216 
00217       enum VIEWMODE {
00218          VIEWMODE_Icon =         0,    //!<LVS_ICON,           NOTE: Not implemented in X case
00219          VIEWMODE_Report =       1,    //!<LVS_REPORT,         
00220          VIEWMODE_SmallIcon =    2,    //!<LVS_SMALLICON    NOTE: Not implemented in X case
00221          VIEWMODE_List =         3     //!<LVS_LIST,           
00222          };
00223 
00224       enum IMAGELISTTYPE {
00225          IMAGELISTTYPE_Normal =  0,    //!< LVSIL_NORMAL
00226          IMAGELISTTYPE_Small  =  1,    //!< LVSIL_SMALL
00227          IMAGELISTTYPE_State  =  2     //!< LVSIL_STATE
00228          };
00229 
00230       //! Structure passed to OnGetDispInfo
00231       //! Note: for the present, only the m_text member is supported by X
00232       struct DISPINFO {
00233          DISPINFO () :
00234             m_indent(0),
00235             m_IconIndex(-1),
00236             m_StateImageIndex(-1),
00237             m_OverlayImageIndex(-1),
00238             m_bSelected(false) 
00239             {}
00240             
00241          ~DISPINFO() {}
00242 
00243          MISTRING m_text;  //!< String to display
00244          int m_indent;     //!< Number of icon widths to indent (default == 0)
00245          int m_IconIndex;  //!< 0-based Index into IMAGELIST set by SetImageList(), -1 == none
00246          int m_StateImageIndex;  //!< Displayed next to the item's icon -1 = none.  
00247          int m_OverlayImageIndex;   //!< Drawn on top of item's icon. -1 = none.
00248          bool m_bSelected; 
00249          };
00250       
00251       //! Structure passed to OnDrawItem()
00252       struct CUSTOMDRAW {
00253          int row;
00254          int col;
00255          LRECT2D rect;
00256          COLOR BackgroundColor;
00257          COLOR TextColor;
00258          bool ChangedBackgroundColor;
00259          bool ChangedTextColor;
00260       #ifdef WIN32_MFC
00261          HDC gc;
00262       #else
00263          MGD::CONTEXT* gc;
00264       #endif
00265          };
00266             
00267       //! Constructor.
00268       CTRL_GRID (
00269          );
00270 
00271       //! Destructor.
00272       virtual ~CTRL_GRID (
00273          );
00274 
00275       //! Create the control.
00276       void Create (
00277          MGUI::LAYOUT_PANE_BASE& ParentPane,    //!< Parent pane
00278          int height = 10,                       //!< Height in rows,
00279          int width = 40,                        //!< Width in 'em' characters
00280          VIEWMODE viewmode = VIEWMODE_Report,   //!< Initial viewing mode
00281          STYLE style = STYLE_AlignTop,          //!< List style
00282          MGUI::LAYOUT_SIZEALIGN sizealign = MGUI::LAYOUT_SIZEALIGN_Expand
00283          );
00284 
00285       //! Delete all columns.
00286       void DeleteAllColumns (
00287          );
00288 
00289       //! Delete all items.
00290       void DeleteAllItems (
00291          );
00292 
00293       //! Delete specified column.
00294       void DeleteColumn (
00295          int col
00296          );
00297 
00298       //! Delete specified item.
00299       void DeleteItem (
00300          int itemnum
00301          );
00302 
00303       //! Delete specified item given assigned data value.
00304       void DeleteItemByData (
00305          ID id
00306          );
00307 
00308       //! Deselect all items.
00309       void DeselectAllItems (
00310          );
00311 
00312       //! Begin editing specified item, starting with currently displayed value.
00313       //! @return true if successful, false if not.
00314       bool EditItem (
00315          int itemnum,
00316          int column = 0,
00317          bool selectall = true                  //!< Select all existing text so typing will replace
00318          );
00319 
00320       //! Begin editing specified item, starting with specified string.
00321       //! @return true if successful, false if not.
00322       bool EditItem (
00323          int itemnum,
00324          int column,
00325          const MIUNICODE *initstr,                 //!< String to replace with prior to editing
00326          bool selectall = true                  //!< Select all existing text so typing will replace
00327          );
00328 
00329       //! Ensures that an item is visible.
00330       void EnsureVisible (
00331          int itemnum,
00332          bool PartialOK = false
00333          );
00334 
00335       //! Find item by matching specified data value as pointer.
00336       //! @return Item number or -1 if none found.
00337       int FindItemByData (
00338          const void* value
00339          ) const;
00340 
00341       //! Find item by matching specified data value as ID.
00342       //! @return Item number or -1 if none found.
00343       int FindItemByData (
00344          ID data
00345          ) const { return (FindItemByData((void*)data)); }
00346 
00347       //! Get the index (row number) of the bottom-most visible item.
00348       //! Note: Return value may be greater than number of rows of data
00349       //! if more rows are visible than there are data for.
00350       int GetBottomRow (
00351          ) const { return (GetTopRow() + GetCountPerPage()); }
00352 
00353       //! Get the bounding rectangle of a single cell.
00354       bool GetCellRect (
00355          int itemnum,
00356          int col,
00357          LRECT2D& rect
00358          ) const;
00359 
00360       //! Get number of columns in the list.
00361       int GetColumnCount (
00362          ) const;
00363 
00364       //! Get the label for a column.
00365       //! @return true if successful, false otherwise
00366       bool GetColumnLabel (
00367          int column,
00368          MISTRING& label
00369          ) const;
00370 
00371       //! Get the order of columns in the list.  
00372       //! Columns can be reordered by dragging them around if you call
00373       //! SetExtendedStyle() with LVS_EX_HEADERDRAGDROP
00374       ERRVALUE GetColumnOrderArray (
00375          SIMPLE_ARRAY<INT32>& array
00376          );
00377 
00378       //! Get the width of a column in pixels.
00379       int GetColumnWidth (
00380          int column
00381          ) const;
00382 
00383       //! Get number of items that can fit vertically in the visible area of control (in report mode only).
00384       int GetCountPerPage (
00385          ) const;
00386 
00387       //! Get height of heading in pixels.
00388       int GetHeadingHeight (
00389          ) const;
00390 
00391       //! Get number of items in list.
00392       int GetItemCount (
00393          ) const;
00394 
00395       //! Get data value associated with item.
00396       MGUI::ID GetItemData (
00397          int itemnum
00398          ) const;
00399 
00400       //! Get next selected item in list.
00401       //! @return Index of next item or -1 if no more items.
00402       int GetNextSelectedItem (
00403          int startitem = -1                     //!< Starting item for search, starting item is excluded
00404          ) const;
00405 
00406       //! Get number of selected items.
00407       int GetSelectedCount (
00408          ) const;
00409 
00410    #ifdef WIN32_MFC
00411       //! Return the rectangle (in client coordinates) of a given row/column in the list
00412       //! Only exists in MFC version because it returns an MFC CRect
00413       BOOL GetSubItemRect (
00414          int item,
00415          int colnum,
00416          CRect& rect
00417          );
00418    #endif
00419 
00420       //! Get the index (row number) of the top-most visible item
00421       int GetTopRow (
00422          ) const;
00423 
00424       //! Insert new column with label from resource or ASCII string.
00425       int InsertColumn (
00426          int colnum,                            //!< Column number and subitem
00427          const char *string,                    //!< String for resource lookup or to set
00428          FORMAT format = FORMAT_Left,           //!< Column format
00429          int width = -1,                        //!< Width of column in PIXELS
00430          bool lookup = true                     //!< 'true' to perform resource lookup, false to use string as-is
00431          );
00432 
00433       //! Insert new column with label from MIUNICODE* string.
00434       int InsertColumn (
00435          int colnum,                            //!< Column number and subitem
00436          const MIUNICODE *string,                  //!< String for column heading
00437          FORMAT format = FORMAT_Left,           //!< Column format
00438          int width = -1                         //!< Width of column in PIXELS
00439          );
00440 
00441       //! Insert new column with label from MISTRING;
00442       int InsertColumn (
00443          int colnum,                            //!< Column number and subitem
00444          const MISTRING& string,                //!< String for column heading
00445          FORMAT format = FORMAT_Left,           //!< Column format
00446          int width = -1                         //!< Width of column in PIXELS
00447          ) { return (InsertColumn(colnum,static_cast<const MIUNICODE*>(string),format,width)); }
00448 
00449       //! Insert new column with label from MIUNICODE* string.
00450       //! Every cell in the column is a combo box.
00451       //! The menu parameter is an MISTRING of newline-seperated entries to
00452       //! use when populating the drop down menu.  Note that other than having
00453       //! a fixed set of options in a dropdown menu, this column type still
00454       //! returns its current value as text, not as anything numeric. 
00455       //!
00456       //! @note This column type is only implemented in X, not MFC.
00457       int InsertColumnComboBox (
00458          int colnum,                            //!< Column number and subitem
00459          const MISTRING& label,                 //!< String for column heading
00460          const MISTRING& menu,
00461          int width = -1                         //!< Width of column in PIXELS
00462          );
00463 
00464       //! Insert new item from resource or ASCII string.
00465       //! @return Item number of inserted item if successful, < 0 if error.
00466       int InsertItem (
00467          const char *string,                    //!< String for resource lookup or to set
00468          bool lookup = true                     //!< 'true' to perform resource lookup, false to use string as-is
00469          );
00470 
00471       //! Insert new item with Unicode string.
00472       //! @return Item number of inserted item if successful, < 0 if error.
00473       int InsertItem (
00474          const MIUNICODE *string                //!< Item string
00475          );
00476 
00477       //! Insert new item with Unicode string.
00478       //! @return Item number of inserted item if successful, < 0 if error.
00479       int InsertItem (
00480          const MISTRING& string                 //!< Item string
00481          ) { return (InsertItem(static_cast<const MIUNICODE*>(string))); }
00482 
00483       //! Insert new item at specified position from resource or ASCII string.
00484       //! @return Item number of inserted item if successful, < 0 if error.
00485       int InsertItem (
00486          int pos,                               //!< Item position in list
00487          const char *string,                    //!< String for resource lookup or to set
00488          bool lookup = true                     //!< 'true' to perform resource lookup, false to use string as-is
00489          );
00490 
00491       //! Insert new item at specified position with Unicode string.
00492       //! @return Item number of inserted item if successful, < 0 if error.
00493       int InsertItem (
00494          int pos,                               //!< Item position in list
00495          const MIUNICODE *string                //!< Item string
00496          );
00497 
00498       //! Determine if specified item is currently "selected".
00499       //! @return 'true' if selected, 'false' if not.
00500       bool IsItemSelected (
00501          int itemnum
00502          ) const;
00503 
00504       //! Force the control to repaint all items.
00505       void Redraw (
00506          bool updatenow = true
00507          );
00508 
00509       //! Force the control to repaint a range of items.
00510       void RedrawItems (
00511          int firstitemnum,
00512          int lastitemnum,
00513          bool updatenow = true
00514          );
00515 
00516       //! Set column label.
00517       //! @return true if successful, false otherwise
00518       bool SetColumnLabel (
00519          int column,
00520          const MIUNICODE* label
00521          );
00522 
00523       //! Set the order of columns within the list.
00524       void SetColumnOrderArray (
00525          SIMPLE_ARRAY<INT32>& array
00526          );
00527 
00528       //! Set the width of a column.  The width can be in pixels or one of the
00529       //! constants LVSCW_AUTOSIZE or LVSCW_AUTOSIZE_USE_HEADER as described in
00530       //! LVM_SETCOLUMNWIDTH in the Platform SDK documentation.
00531       void SetColumnWidth (
00532          int column,
00533          int width
00534          );
00535 
00536    #ifdef WIN32_MFC
00537       //! Set extended styles.    (MFC version only)
00538       void SetExtendedStyle (
00539          UINT32 exstyles,                       //!< LVS_EX_...
00540          UINT32 mask = 0                        //!< Mask for styles to change, 0 to set all specified
00541          );
00542    #endif
00543 
00544       //! Set image list.
00545       void SetImageList (
00546          IMAGELIST& imagelist,                  //!< Image list
00547          IMAGELISTTYPE listtype = IMAGELISTTYPE_Small,            //!< Type of image list, IMAGELISTTYPE_Normal, IMAGELISTTYPE_Small or IMAGELISTTYPE_State
00548          bool shared = false                    //!< 'true' if image list is shared, 'false' if control should take ownership
00549          );
00550 
00551       //! Set number of items in list.
00552       int SetItemCount (
00553          int NumItems
00554          );
00555 
00556       //! Set application-specific data to associate with list item.
00557       void SetItemData (
00558          int itemnum,                           //!< Item number
00559          ID value                         //!< Value to associate with item
00560          );
00561 
00562       //! Set the image index to use for a givem item.
00563       //! This only handles column 0, and currently only for MFC
00564       //! Pass -1 for imageindex to have no icon
00565       //! imageindex is a 0-based index into the IMAGELIST set via
00566       //! SetImageList()
00567       void SetItemImage (
00568          int itemnum,
00569          int imageindex
00570          );
00571 
00572       //! Set whether item is 'selected or not.
00573       void SetItemSelected (
00574          int itemnum,                           //!< Item number
00575          bool selected = true
00576          );
00577 
00578       //! Set item or subitem text from resource or ASCII string.
00579       void SetItemText (
00580          int itemnum,                           //!< Item number
00581          int subitem,                           //!< Sub item, 0 for item
00582          const char *string,                    //!< String for resource lookup or to set
00583          bool lookup = true                     //!< 'true' to perform resource lookup, false to use string as-is
00584          );
00585 
00586       //! Set item or subitem text from Unicode string.
00587       void SetItemText (
00588          int itemnum,                           //!< Item number
00589          int subitem,                           //!< Sub item, 0 for item
00590          const MIUNICODE *string                //!< Item or subitem string
00591          );
00592 
00593       //! Sort the data in the list on a given column.
00594       void SortItems (
00595          int column = 0,         //!< Column to sort on
00596          bool bAscending = true
00597          );
00598 
00599       //! Force the control to repaint a specified item
00600       void Update (
00601          int itemnum
00602          );
00603 
00604    protected:
00605 
00606       STYLE GetStyle (
00607          ) const { return m_style; }
00608 
00609       //! Called when user clicks on label to begin editing.
00610       //! @return 'false' if editing is NOT allowed or 'true' if editing is allowed.
00611       //! Default implementation always returns 'true' if the grid was
00612       //! created with STYLE_EditLabels or 'false' if not.
00613       virtual bool OnBeginLabelEdit (
00614          int itemnum,
00615          int subitemnum
00616          );
00617 
00618       //! Called when the order of the columns are changed.
00619       virtual void OnChangeColumnOrder (
00620          int fromCol,
00621          int toCol
00622          );
00623 
00624       //! Called when user clicks on column heading.
00625       virtual void OnClickColumn (
00626          int itemnum,
00627          int column,
00628          KEYSTATE state
00629          );
00630 
00631       //! Called when user left-clicks on a list item.
00632       virtual void OnClickItem (
00633          int itemnum,                                             
00634          int column,
00635          KEYSTATE state
00636          );
00637 
00638       //! Called when user double-left-clicks on a list item.
00639       virtual void OnDoubleClickItem (
00640          int itemnum,
00641          int column,
00642          KEYSTATE state
00643          );
00644       
00645       //! Called before an item is drawn.
00646       //! Override if you want to do the drawing yourself. 
00647       //! Should return true if you did all the drawing.  Return false to let the base class draw the item.
00648       virtual bool OnDrawItem (
00649          CUSTOMDRAW& drawinfo
00650          );
00651 
00652       //! Called when user clicks on label to begin editing.
00653       //! @return 'true' if to accept changes or 'false' to reject changes.
00654       //! Default implementation always returns 'true' if the grid was
00655       //! created with STYLE_EditLabels or 'false' if not.
00656       virtual bool OnEndLabelEdit (
00657          int row,
00658          int col,
00659          MISTRING& string
00660          );
00661 
00662       //! Called by list to request information stored by owner rather than list.
00663       //!
00664       //! Derived implementation should return true if it actually filled in
00665       //! anything.  Return false to behave as if OnGetDispInfo wasn't overridden.
00666       virtual bool OnGetDispInfo (
00667          int row,
00668          int col,
00669          CTRL_GRID::DISPINFO& dispinfo 
00670          );
00671 
00672       //! Called when an item is "activated" (normally via a double click).
00673       virtual void OnItemActivate (
00674          );
00675 
00676       //! Called by SortItems() to compare items.
00677       //! Should return < 0 if rowitem1 should precede rowitem2 and > 0 if rowitem1 should follow rowitem2
00678       //! and 0 if the two items are equivalent.
00679       //! XXX DEPRECATED. Don't override this, override the one that takes
00680       //! a column number and direction
00681       virtual int OnItemCompare (
00682          UINT32 rowitem1,
00683          UINT32 rowitem2
00684          );
00685 
00686       //! Called by SortItems() to compare items.
00687       //! Should return < 0 if rowitem1 should precede rowitem2 and > 0 if rowitem1 should follow rowitem2
00688       //! and 0 if the two items are equivalent.
00689       //! if bAscending is false, you should reverse the order.
00690       virtual int OnItemCompare (
00691          UINT32 rowitem1,
00692          UINT32 rowitem2,
00693          int colnum,
00694          bool bAscending
00695          );
00696 
00697       //! Called when an item is "selected".
00698       virtual void OnItemSelect (
00699          int itemnum,
00700          int subitemnum
00701          );
00702 
00703       //! Called when an item is "unselected".
00704       virtual void OnItemUnselect (
00705          int itemnum,
00706          int subitemnum
00707          );
00708 
00709       //! Called for owner-data list to provide hints about what to cache.
00710       virtual void OnOwnerDataCacheHint (
00711          int from,
00712          int to
00713          );
00714 
00715       //! Called when user right-clicks on a list item.
00716       virtual void OnRightClickItem (
00717          int itemnum,
00718          int column,
00719          const LPOINT2D&,
00720          KEYSTATE state
00721          );
00722 
00723       //! Called when user release mouse after dragging column header.
00724       virtual void OnUserResizeColumn (
00725          int column,
00726          int width
00727          );
00728 
00729    private:
00730       #ifndef GENERATING_DOXYGEN_OUTPUT
00731 
00732       class MyListCtrl;
00733       friend class MyListCtrl;
00734 
00735       MyListCtrl *m_pCtrl;
00736       STYLE m_style;
00737       int m_PrevSelRow;
00738       int m_PrevSelCol;
00739 
00740       // UNIMPLEMENTED / UNSUPPORTED
00741       CTRL_GRID (const CTRL_GRID&);
00742       CTRL_GRID& operator= (const CTRL_GRID&);
00743 
00744    #ifdef WIN32_MFC
00745       static int CALLBACK CompareCallback (LPARAM rowitem1, LPARAM rowitem2, LPARAM cbdata);
00746    #endif
00747       #endif // GENERATING_DOXYGEN_OUTPUT
00748 
00749 
00750    };
00751 
00752 DEFINE_ENUM_OPERATORS(MGUI::CTRL_GRID::STYLE);
00753 
00754 
00755 //------------------------------------------------------------------------------------------------
00756 //! List control template.
00757 template <class _CT> class CTRL_GRID_T : public MGUI::CTRL_GRID {
00758    public:
00759       //! Constructor.
00760       CTRL_GRID_T (
00761          ):
00762          m_pContainer(0),
00763          m_OnBeginLabelEditFunc(0),
00764          m_OnClickColumnFunc(0),
00765          m_OnClickItemFunc(0),
00766          m_OnDoubleClickItemFunc(0),
00767          m_OnEndLabelEditFunc(0),
00768          m_OnGetDispInfoFunc(0),
00769          m_OnItemActivateFunc(0),
00770          m_OnItemDrawFunc(0),
00771          m_OnItemCompareFunc(0),
00772          m_OnItemSelectFunc(0),
00773          m_OnItemUnselectFunc(0),
00774          m_OnOwnerDataCacheHintFunc(0),
00775          m_OnRightClickItemFunc(0),
00776          m_OnUserResizeColumnFunc(0)
00777          { }
00778 
00779       //! Destructor.
00780       virtual ~CTRL_GRID_T (
00781          ) { }
00782 
00783       //! Create list box control with no label.
00784       void Create (
00785          MGUI::LAYOUT_PANE_BASE& ParentPane,    //!< Parent pane
00786          _CT *pContainer,                       //!< Pointer to callback container class
00787          int height = 10,                       //!< Height in rows,
00788          int width = 40,                        //!< Width in 'em' characters
00789          VIEWMODE viewmode = VIEWMODE_Report,   //!< Initial viewing mode
00790          STYLE style = STYLE_AlignTop,          //!< List style
00791          MGUI::LAYOUT_SIZEALIGN sizealign = MGUI::LAYOUT_SIZEALIGN_Expand
00792          ) {
00793          m_pContainer = pContainer;
00794          CTRL_GRID::Create(ParentPane,height,width,viewmode,style,sizealign);
00795          return;
00796          }
00797 
00798       //! Set method to call when user clicks on label to begin editing.
00799       void SetBeginLabelEditFunc (
00800          bool (_CT::*BeginLabelEditFunc)(int row, int col)
00801          ) { m_OnBeginLabelEditFunc = BeginLabelEditFunc; };
00802 
00803       //! Set method to call when user changes order of columns.
00804       void SetChangeColumnOrderFunc (
00805          void (_CT::*ChangeColumnOrderFunc)(int fromCol, int toCol)
00806          ) { m_OnChangeColumnOrderFunc = ChangeColumnOrderFunc; };
00807 
00808       //! Set method to call when user clicks on a column heading.
00809       void SetClickColumnFunc (
00810          void (_CT::*ClickColumnFunc)(int itemnum, int column, KEYSTATE state)
00811          ) { m_OnClickColumnFunc = ClickColumnFunc; };
00812 
00813       //! Set method to call when user left-clicks on an item.
00814       void SetClickItemFunc (
00815          void (_CT::*ClickItemFunc)(int itemnum, int column, KEYSTATE state)
00816          ) { m_OnClickItemFunc = ClickItemFunc; };
00817 
00818       //! Set method to call when user double-left-clicks on an item.
00819       void SetDoubleClickItemFunc (
00820          void (_CT::*DoubleClickItemFunc)(int itemnum, int column, KEYSTATE state)
00821          ) { m_OnDoubleClickItemFunc = DoubleClickItemFunc; };
00822 
00823       //! Set method to call when user clicks on label to end editing.
00824       void SetEndLabelEditFunc (
00825          bool (_CT::*EndLabelEditFunc)(int row, int col, MISTRING& string)
00826          ) { m_OnEndLabelEditFunc = EndLabelEditFunc; };
00827 
00828       //! Set method to call when user activates or deactivates item.
00829             //! XXX NMLVDISPINFO& is meaningless in X case
00830       void SetGetDispInfoFunc (
00831          bool (_CT::*GetDispInfoFunc)(int row, int col, DISPINFO& info)
00832          ) { m_OnGetDispInfoFunc = GetDispInfoFunc; };
00833 
00834       //! Set method to call when user activates or deactivates item.
00835       void SetItemActivateFunc (
00836          void (_CT::*ItemActivateFunc)()
00837          ) { m_OnItemActivateFunc = ItemActivateFunc; };
00838 
00839       //! Set method to call for compare two items for sorting
00840       //! Should return < 0 if rowitem1 should precede rowitem2 and > 0 if rowitem1 should follow rowitem2
00841       //! and 0 if the two items are equivalent.
00842       void SetItemCompareFunc (
00843          int (_CT::*ItemCompareFunc)(UINT32 rowitem1, UINT32 rowitem2, int ColNum, bool bAscending)
00844          ) { m_OnItemCompareFunc = ItemCompareFunc; };
00845 
00846       //! Set method to call for custom item drawing.
00847             //! XXX NMLVCUSTOMDRAW& is meaningless in X case
00848       void SetItemDrawFunc (
00849          bool (_CT::*ItemDrawFunc)(CUSTOMDRAW&)
00850          ) { m_OnItemDrawFunc = ItemDrawFunc; };
00851 
00852       //! Set method to call when item is selected
00853       void SetItemSelectFunc (
00854          void (_CT::*ItemSelectFunc)(int itemnum, int subitemnum)
00855          ) { m_OnItemSelectFunc = ItemSelectFunc; };
00856 
00857       //! Set method to call when item is unselected
00858       void SetItemUnselectFunc (
00859          void (_CT::*ItemUnselectFunc)(int itemnum, int subitemnum)
00860          ) { m_OnItemUnselectFunc = ItemUnselectFunc; };
00861 
00862       //! Set method to call when user activates or deactivates item.
00863       void SetOwnerDataCacheHintFunc (
00864          void (_CT::*OwnerDataCacheHintFunc)(int from, int to)
00865          ) { m_OnOwnerDataCacheHintFunc = OwnerDataCacheHintFunc; };
00866 
00867       //! Set method to call when user right-clicks on an item.
00868       void SetRightClickItemFunc (
00869          void (_CT::*RightClickItemFunc)(int itemnum, int column, const LPOINT2D&, KEYSTATE state)
00870          ) { m_OnRightClickItemFunc = RightClickItemFunc; };
00871 
00872       //! Set method to call when user resizes column and releases mouse button.
00873       void SetUserResizeColumnFunc (
00874          void (_CT::*OnUserResizeColumnFunc)(int column, int width)
00875          ) { m_OnUserResizeColumnFunc = OnUserResizeColumnFunc; };
00876 
00877    private:
00878       #ifndef GENERATING_DOXYGEN_OUTPUT
00879 
00880       virtual bool OnBeginLabelEdit (
00881          int row,
00882          int col
00883          ) { 
00884          if (m_OnBeginLabelEditFunc != 0) {
00885             return (m_pContainer->*m_OnBeginLabelEditFunc)(row, col);
00886             }
00887          else {
00888             return ((GetStyle() & STYLE_EditLabels) != 0);
00889             }
00890          }
00891 
00892       virtual void OnChangeColumnOrder (
00893          int fromCol,
00894          int toCol
00895          ) { if (m_OnChangeColumnOrderFunc != 0) (m_pContainer->*m_OnChangeColumnOrderFunc)(fromCol, toCol); }
00896 
00897       virtual void OnClickColumn (
00898          int itemnum,
00899          int column,
00900          KEYSTATE state
00901          ) { if (m_OnClickColumnFunc != 0) (m_pContainer->*m_OnClickColumnFunc)(itemnum,column,state); }
00902 
00903       virtual void OnClickItem (
00904          int itemnum,
00905          int column,
00906          KEYSTATE state
00907          ) { if (itemnum >= 0 && m_OnClickItemFunc != 0) (m_pContainer->*m_OnClickItemFunc)(itemnum,column,state); 
00908             else CTRL_GRID::OnClickItem(itemnum, column, state); 
00909          }
00910 
00911       virtual void OnDoubleClickItem (
00912          int itemnum,
00913          int column,
00914          KEYSTATE state
00915          ) { if (m_OnDoubleClickItemFunc != 0) (m_pContainer->*m_OnDoubleClickItemFunc)(itemnum,column, state); }
00916 
00917       virtual int OnItemCompare (
00918          UINT32 rowitem1,
00919          UINT32 rowitem2,
00920          int colnum,
00921          bool bAscending
00922          ) { if (m_OnItemCompareFunc != 0) return ((m_pContainer->*m_OnItemCompareFunc)(rowitem1, rowitem2, colnum, bAscending)); else return (0); }
00923 
00924       virtual bool OnDrawItem (
00925          CUSTOMDRAW& drawinfo
00926          ) { if (m_OnItemDrawFunc != 0) return ((m_pContainer->*m_OnItemDrawFunc)(drawinfo)); else return (false); }
00927 
00928       virtual bool OnEndLabelEdit (
00929          int row,
00930          int col,
00931          MISTRING& string
00932          ) { return ((m_OnEndLabelEditFunc != 0) ? (m_pContainer->*m_OnEndLabelEditFunc)(row, col, string) : true); }
00933 
00934       virtual bool OnGetDispInfo (
00935          int row,
00936          int col,
00937          DISPINFO& info
00938          ) { if (m_OnGetDispInfoFunc != 0) return((m_pContainer->*m_OnGetDispInfoFunc)(row, col, info)); 
00939          return (false);
00940          }
00941 
00942       virtual void OnItemActivate (
00943          ) { if (m_OnItemActivateFunc != 0) (m_pContainer->*m_OnItemActivateFunc)(); }
00944 
00945       virtual void OnItemSelect (
00946          int itemnum,
00947          int subitemnum
00948          ) { if (m_OnItemSelectFunc != 0) (m_pContainer->*m_OnItemSelectFunc)(itemnum, subitemnum);
00949             else CTRL_GRID::OnItemSelect(itemnum, subitemnum);
00950          }
00951 
00952       virtual void OnItemUnselect (
00953          int itemnum,
00954          int subitemnum
00955          ) { if (m_OnItemUnselectFunc != 0) (m_pContainer->*m_OnItemUnselectFunc)(itemnum, subitemnum);
00956             else CTRL_GRID::OnItemUnselect(itemnum, subitemnum);
00957          }
00958 
00959       virtual void OnOwnerDataCacheHint (
00960          int from,
00961          int to
00962          ) { if (m_OnOwnerDataCacheHintFunc != 0) (m_pContainer->*m_OnOwnerDataCacheHintFunc)(from,to); };
00963 
00964       virtual void OnRightClickItem (
00965          int itemnum,
00966          int column,
00967          const LPOINT2D& pt,
00968          KEYSTATE state
00969          ) { if (m_OnRightClickItemFunc != 0) (m_pContainer->*m_OnRightClickItemFunc)(itemnum,column,pt,state); }
00970 
00971       virtual void OnUserResizeColumn (
00972          int column,
00973          int width
00974          ) { if (m_OnUserResizeColumnFunc != 0) (m_pContainer->*m_OnUserResizeColumnFunc)(column, width); }
00975 
00976       _CT *m_pContainer;
00977       bool (_CT::*m_OnBeginLabelEditFunc)(int row, int col);
00978       void (_CT::*m_OnChangeColumnOrderFunc)(int fromCol, int toCol);
00979       void (_CT::*m_OnClickColumnFunc)(int row, int column, KEYSTATE state);
00980       void (_CT::*m_OnClickItemFunc)(int row, int column, KEYSTATE state);
00981       void (_CT::*m_OnDoubleClickItemFunc)(int row, int column, KEYSTATE state);
00982       bool (_CT::*m_OnEndLabelEditFunc)(int row, int col, MISTRING& string);
00983       bool (_CT::*m_OnGetDispInfoFunc)(int row, int col, CTRL_GRID::DISPINFO&info);
00984       void (_CT::*m_OnItemActivateFunc)();
00985       void (_CT::*m_OnItemSelectFunc)(int item, int subitem);
00986       void (_CT::*m_OnItemUnselectFunc)(int item, int subitem);
00987       int (_CT::*m_OnItemCompareFunc)(UINT32 rowitem1, UINT32 rowitem2, int col, bool bAscending);
00988       bool (_CT::*m_OnItemDrawFunc)(CUSTOMDRAW& drawinfo);
00989       void (_CT::*m_OnOwnerDataCacheHintFunc)(int from, int to);
00990       void (_CT::*m_OnRightClickItemFunc)(int itemnum, int column, const LPOINT2D&, KEYSTATE state);
00991       void (_CT::*m_OnUserResizeColumnFunc)(int column, int width);
00992       #endif // GENERATING_DOXYGEN_OUTPUT
00993    };
00994 
00995 //------------------------------------------------------------------------------------------------
00996 
00997 }  // End of MGUI namespace
00998 
00999 #endif   // INC_MGUI_GRID_H
01000 

Generated on Wed May 31 15:26:46 2006 for TNTsdk by  doxygen 1.3.8-20040913