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

Generated on Thu Aug 12 06:18:29 2004 for TNTsdk by doxygen 1.3.4-20031026