gridcombo.h

Go to the documentation of this file.
00001 
00002 // Name:        gridcombo.h
00003 // Purpose:     A grid grid combo
00004 // Author:      Mikhail Tatarnikov
00005 // Modified by:
00006 // Created:     2006-08-16
00007 // RCS-ID:      $Id: $
00008 // Copyright:   (c) 2006 Xara Ltd
00009 // Licence:     wxWindows licence
00011 
00012 #ifndef _WXXTRA_GRIDCOMBO_H_
00013 #define _WXXTRA_GRIDCOMBO_H_
00014 
00015 #include <wx/defs.h>
00016 //#include <wx/grid.h>
00017 #include <vector>
00018 #include <wx/scrolwin.h>
00019 #include <wx/timer.h>
00020 #include <wx/settings.h>
00021 
00022 #if wxUSE_COMBOCTRL
00023 #include <wx/combo.h>
00024 #else
00025 #include "combog.h"
00026 #endif
00027 
00028 
00029 class wxGridCombo;
00030 
00031 
00032 
00033 /*************************************************************************
00034 Class         : wxGridComboPopup
00035 Base Class    : public wxScrolledWindow
00036                 public wxComboPopup
00037 Author        : Mikhail Tatarnikov
00038 Description   : A base class for wxComboPopup implementation implementing
00039                 a grid-like popup (multicolmn as opposint to a standard one-column
00040                 list box popup).
00041 Pure Virtual  : DrawItem - you have to override it and do the actuall cell paint in it.
00042 Known Issues  : None
00043 Usage Notes   : All the information that pertain to the control as a whole (a combobox and popup)
00044                 is stored in the combobox itself. A number of access functions (e.g. GetColumns)
00045                 are provided.
00046                 An item can be in selected or highlighted (when the mouse is hovered over the item)
00047                 state.
00048 Override Notes: None
00049 **************************************************************************/
00050 class wxGridComboPopup : public wxScrolledWindow,
00051                          public wxComboPopup
00052 {
00053     friend class wxGridCombo;
00054 public:
00055     enum EDrawFlags
00056     {
00057         keSelected     = 0x0001,    // The item is selected.
00058         keHighlight    = 0x0002,    // The item is hovered.
00059         keComboControl = 0x0004,    // The paint the item in the combo control itself.
00060         keDisabled     = 0x0008     // The item is disabled. For now can be applied for the combo
00061                                     // control itself only.
00062     };
00063     
00064 public:
00065 
00066     wxGridComboPopup(wxGridCombo* pCombo);
00067 
00068     virtual void Init();
00069     virtual bool Create(wxWindow* pwndParent);
00070 
00071     virtual void      OnShow();
00072     virtual wxSize    GetAdjustedSize(int iMinWidth, int iPrefHeight, int iMaxHeight);
00073     virtual wxWindow* GetControl() {return this;}
00074 
00075     // Drawing functions.
00076     virtual void DrawItem(wxDC& dc, const wxRect& rect, int iItem, int iFlags) = 0;
00077     virtual void PaintComboControl(wxDC& dc, const wxRect& rect);
00078 
00079     virtual void SetSelected(int iItem);
00080     virtual int  GetSelected() const;
00081 
00082 
00083     // Helper function
00084     inline int    GetColumns() const;
00085     inline int    GetRows() const;
00086     inline int    GetItemsNum() const;
00087     inline wxSize GetItemSize() const;
00088 
00089 
00090     // Gets displayed string representation of the value.
00091     // Since we are owner-drawn control, the string doen't matter much.
00092     virtual wxString GetStringValue() const {return wxString();}
00093 
00094 protected:
00095     virtual void DrawItem(wxDC& dc, const wxRect& rect, int iCol, int iRow, bool bSelected);
00096     virtual void UpdateScrollers();
00097     virtual void UpdateColumnsNum();
00098     virtual void ChangeSelection(int iOldSelected, int iNewSelected);
00099     virtual void SendComboBoxEvent(int iSelection);
00100 
00101     wxRect  GetItemRect(int iItem);
00102     wxPoint ItemToGrid(int iItem);
00103     int     ItemFromPoint(wxPoint ptClient);
00104     void    InvalidateItem(int iItem);
00105     void    ClientToScrolledVirtual(int* pX, int* pY);
00106 
00107     // Closes the popup and sends notig
00108     void DismissWithEvent();
00109 
00110     // Message handlers.
00111     virtual void OnDraw(wxDC& dc);
00112     void OnSize(wxSizeEvent& event);
00113     void OnMouseMove(wxMouseEvent& event);
00114     void OnKey(wxKeyEvent& event);
00115     void OnLeftClick(wxMouseEvent& event);
00116     void OnTimer(wxTimerEvent& event);
00117 
00118 protected:
00119     wxGridCombo* m_pCombo;
00120     int          m_iHighlighed;
00121     wxTimer      m_tmrHighlited;    // Need a timer to spot the moment the mouse leaves popup (to dehighlight an item).
00122 private:
00123     DECLARE_EVENT_TABLE()
00124 };
00125 
00126 
00127 
00128 
00129 
00130 
00131 
00132 
00133 
00134 
00135 
00136 
00137 struct CGridComboUserData
00138 {
00139     virtual ~CGridComboUserData(){};
00140 };
00141 
00142 
00143 
00144 /*************************************************************************
00145 Class         : wxGridCombo
00146 Base Class    : public wxComboCtrl
00147 Author        : Mikhail Tatarnikov
00148 Description   : wxWidgit control extension that implements grid-like behaivor. Uses wxGridComboPopup
00149                 or its derivitives.
00150 Pure Virtual  : None
00151 Known Issues  : None
00152 Usage Notes   : None
00153 Override Notes: 
00154 **************************************************************************/
00155 class WXDLLIMPEXP_ADV wxGridCombo : public wxComboCtrl
00156 {
00157 //  friend class wxGridComboPopup;
00158 public:
00159 
00160     wxGridCombo(){Init();}
00161 
00162     wxGridCombo(wxWindow* pwndParent,
00163                 wxWindowID wiID = wxID_ANY,
00164                 const wxPoint& crptPos = wxDefaultPosition,
00165                 const wxSize& crszSize = wxDefaultSize,
00166                 long lStyle = 0,
00167                 const wxString& crstrName = wxT("wxSliderComboBox"));
00168 
00169     bool Create(wxWindow* pwndParent,
00170                 wxWindowID wiID = wxID_ANY,
00171                 const wxPoint& crptPos = wxDefaultPosition,
00172                 const wxSize& crszSize = wxDefaultSize,
00173                 long lStyle = 0,
00174                 const wxString& crstrName = wxT("wxSliderComboBox"));
00175 
00176     virtual ~wxGridCombo();
00177 
00178 
00179     virtual void AddItem(CGridComboUserData* pUserData);
00180     virtual CGridComboUserData* GetUserData(int iIndex);
00181 
00182     virtual void Clear();
00183     virtual void DeleteUserData();
00184 
00185 
00186     void SetColumns(int iCols);
00187     int GetColumns() const {return m_iColumns;}
00188     int GetRows();
00189 
00190     void SetSelected(int iSelected);
00191     int  GetSelected() const;
00192 
00193     int GetItemsNum() const {return m_vecUserData.size();}
00194 
00195     void   SetItemSize(wxSize szItem);
00196     wxSize GetItemSize() const {return m_szItem;}
00197 
00198 
00199 protected:
00200     void Init();
00201 
00202 protected:
00203 
00204     std::vector<CGridComboUserData*> m_vecUserData;
00205 
00206 private:
00207     int m_iColumns;
00208 
00209     int m_iSelected;
00210 
00211     wxSize m_szItem;    // The item size. In grid we can have items with the same size only. TODO: allow rows/columns with different sizes?
00212 
00213     DECLARE_DYNAMIC_CLASS(wxGridCombo)
00214 };
00215 
00216 #endif //_WXXTRA_GRIDCOMBO_H_

Generated on Sat Nov 10 03:49:02 2007 for Camelot by  doxygen 1.4.4