⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 grid.h

📁 wxGTK 是 wxWidgets 的 linux GTK+ (>2.2.3)版本。wxWidgets 是一个跨平台的 GUI 框架
💻 H
📖 第 1 页 / 共 5 页
字号:
/////////////////////////////////////////////////////////////////////////////// Name:        wx/generic/grid.h// Purpose:     wxGrid and related classes// Author:      Michael Bedward (based on code by Julian Smart, Robin Dunn)// Modified by: Santiago Palacios// Created:     1/08/1999// RCS-ID:      $Id: grid.h,v 1.160 2006/10/28 13:57:33 VZ Exp $// Copyright:   (c) Michael Bedward// Licence:     wxWindows licence/////////////////////////////////////////////////////////////////////////////#ifndef _WX_GENERIC_GRID_H_#define _WX_GENERIC_GRID_H_#include "wx/defs.h"#if wxUSE_GRID#include "wx/scrolwin.h"// ----------------------------------------------------------------------------// constants// ----------------------------------------------------------------------------extern WXDLLIMPEXP_DATA_ADV(const wxChar) wxGridNameStr[];// Default parameters for wxGrid//#define WXGRID_DEFAULT_NUMBER_ROWS            10#define WXGRID_DEFAULT_NUMBER_COLS            10#if defined(__WXMSW__) || defined(__WXGTK20__)#define WXGRID_DEFAULT_ROW_HEIGHT             25#else#define WXGRID_DEFAULT_ROW_HEIGHT             30#endif  // __WXMSW__#define WXGRID_DEFAULT_COL_WIDTH              80#define WXGRID_DEFAULT_COL_LABEL_HEIGHT       32#define WXGRID_DEFAULT_ROW_LABEL_WIDTH        82#define WXGRID_LABEL_EDGE_ZONE                 2#define WXGRID_MIN_ROW_HEIGHT                 15#define WXGRID_MIN_COL_WIDTH                  15#define WXGRID_DEFAULT_SCROLLBAR_WIDTH        16// type names for grid table values#define wxGRID_VALUE_STRING     _T("string")#define wxGRID_VALUE_BOOL       _T("bool")#define wxGRID_VALUE_NUMBER     _T("long")#define wxGRID_VALUE_FLOAT      _T("double")#define wxGRID_VALUE_CHOICE     _T("choice")#define wxGRID_VALUE_TEXT wxGRID_VALUE_STRING#define wxGRID_VALUE_LONG wxGRID_VALUE_NUMBER// ----------------------------------------------------------------------------// forward declarations// ----------------------------------------------------------------------------class WXDLLIMPEXP_ADV wxGrid;class WXDLLIMPEXP_ADV wxGridCellAttr;class WXDLLIMPEXP_ADV wxGridCellAttrProviderData;class WXDLLIMPEXP_ADV wxGridColLabelWindow;class WXDLLIMPEXP_ADV wxGridCornerLabelWindow;class WXDLLIMPEXP_ADV wxGridRowLabelWindow;class WXDLLIMPEXP_ADV wxGridWindow;class WXDLLIMPEXP_ADV wxGridTypeRegistry;class WXDLLIMPEXP_ADV wxGridSelection;class WXDLLEXPORT wxCheckBox;class WXDLLEXPORT wxComboBox;class WXDLLEXPORT wxTextCtrl;#if wxUSE_SPINCTRLclass WXDLLEXPORT wxSpinCtrl;#endif// ----------------------------------------------------------------------------// macros// ----------------------------------------------------------------------------#define wxSafeIncRef(p) if ( p ) (p)->IncRef()#define wxSafeDecRef(p) if ( p ) (p)->DecRef()// ----------------------------------------------------------------------------// wxGridCellWorker: common base class for wxGridCellRenderer and// wxGridCellEditor//// NB: this is more an implementation convenience than a design issue, so this//     class is not documented and is not public at all// ----------------------------------------------------------------------------class WXDLLIMPEXP_ADV wxGridCellWorker : public wxClientDataContainer{public:    wxGridCellWorker() { m_nRef = 1; }    // this class is ref counted: it is created with ref count of 1, so    // calling DecRef() once will delete it. Calling IncRef() allows to lock    // it until the matching DecRef() is called    void IncRef() { m_nRef++; }    void DecRef() { if ( --m_nRef == 0 ) delete this; }    // interpret renderer parameters: arbitrary string whose interpretatin is    // left to the derived classes    virtual void SetParameters(const wxString& params);protected:    // virtual dtor for any base class - private because only DecRef() can    // delete us    virtual ~wxGridCellWorker();private:    size_t m_nRef;    // suppress the stupid gcc warning about the class having private dtor and    // no friends    friend class wxGridCellWorkerDummyFriend;};// ----------------------------------------------------------------------------// wxGridCellRenderer: this class is responsible for actually drawing the cell// in the grid. You may pass it to the wxGridCellAttr (below) to change the// format of one given cell or to wxGrid::SetDefaultRenderer() to change the// view of all cells. This is an ABC, you will normally use one of the// predefined derived classes or derive your own class from it.// ----------------------------------------------------------------------------class WXDLLIMPEXP_ADV wxGridCellRenderer : public wxGridCellWorker{public:    // draw the given cell on the provided DC inside the given rectangle    // using the style specified by the attribute and the default or selected    // state corresponding to the isSelected value.    //    // this pure virtual function has a default implementation which will    // prepare the DC using the given attribute: it will draw the rectangle    // with the bg colour from attr and set the text colour and font    virtual void Draw(wxGrid& grid,                      wxGridCellAttr& attr,                      wxDC& dc,                      const wxRect& rect,                      int row, int col,                      bool isSelected) = 0;    // get the preferred size of the cell for its contents    virtual wxSize GetBestSize(wxGrid& grid,                               wxGridCellAttr& attr,                               wxDC& dc,                               int row, int col) = 0;    // create a new object which is the copy of this one    virtual wxGridCellRenderer *Clone() const = 0;};// the default renderer for the cells containing string dataclass WXDLLIMPEXP_ADV wxGridCellStringRenderer : public wxGridCellRenderer{public:    // draw the string    virtual void Draw(wxGrid& grid,                      wxGridCellAttr& attr,                      wxDC& dc,                      const wxRect& rect,                      int row, int col,                      bool isSelected);    // return the string extent    virtual wxSize GetBestSize(wxGrid& grid,                               wxGridCellAttr& attr,                               wxDC& dc,                               int row, int col);    virtual wxGridCellRenderer *Clone() const        { return new wxGridCellStringRenderer; }protected:    // set the text colours before drawing    void SetTextColoursAndFont(const wxGrid& grid,                               const wxGridCellAttr& attr,                               wxDC& dc,                               bool isSelected);    // calc the string extent for given string/font    wxSize DoGetBestSize(const wxGridCellAttr& attr,                         wxDC& dc,                         const wxString& text);};// the default renderer for the cells containing numeric (long) dataclass WXDLLIMPEXP_ADV wxGridCellNumberRenderer : public wxGridCellStringRenderer{public:    // draw the string right aligned    virtual void Draw(wxGrid& grid,                      wxGridCellAttr& attr,                      wxDC& dc,                      const wxRect& rect,                      int row, int col,                      bool isSelected);    virtual wxSize GetBestSize(wxGrid& grid,                               wxGridCellAttr& attr,                               wxDC& dc,                               int row, int col);    virtual wxGridCellRenderer *Clone() const        { return new wxGridCellNumberRenderer; }protected:    wxString GetString(const wxGrid& grid, int row, int col);};class WXDLLIMPEXP_ADV wxGridCellFloatRenderer : public wxGridCellStringRenderer{public:    wxGridCellFloatRenderer(int width = -1, int precision = -1);    // get/change formatting parameters    int GetWidth() const { return m_width; }    void SetWidth(int width) { m_width = width; m_format.clear(); }    int GetPrecision() const { return m_precision; }    void SetPrecision(int precision) { m_precision = precision; m_format.clear(); }    // draw the string right aligned with given width/precision    virtual void Draw(wxGrid& grid,                      wxGridCellAttr& attr,                      wxDC& dc,                      const wxRect& rect,                      int row, int col,                      bool isSelected);    virtual wxSize GetBestSize(wxGrid& grid,                               wxGridCellAttr& attr,                               wxDC& dc,                               int row, int col);    // parameters string format is "width[,precision]"    virtual void SetParameters(const wxString& params);    virtual wxGridCellRenderer *Clone() const;protected:    wxString GetString(const wxGrid& grid, int row, int col);private:    // formatting parameters    int m_width,        m_precision;    wxString m_format;};// renderer for boolean fieldsclass WXDLLIMPEXP_ADV wxGridCellBoolRenderer : public wxGridCellRenderer{public:    // draw a check mark or nothing    virtual void Draw(wxGrid& grid,                      wxGridCellAttr& attr,                      wxDC& dc,                      const wxRect& rect,                      int row, int col,                      bool isSelected);    // return the checkmark size    virtual wxSize GetBestSize(wxGrid& grid,                               wxGridCellAttr& attr,                               wxDC& dc,                               int row, int col);    virtual wxGridCellRenderer *Clone() const        { return new wxGridCellBoolRenderer; }private:    static wxSize ms_sizeCheckMark;};// ----------------------------------------------------------------------------// wxGridCellEditor:  This class is responsible for providing and manipulating// the in-place edit controls for the grid.  Instances of wxGridCellEditor// (actually, instances of derived classes since it is an ABC) can be// associated with the cell attributes for individual cells, rows, columns, or// even for the entire grid.// ----------------------------------------------------------------------------class WXDLLIMPEXP_ADV wxGridCellEditor : public wxGridCellWorker{public:    wxGridCellEditor();    bool IsCreated() { return m_control != NULL; }    wxControl* GetControl() { return m_control; }    void SetControl(wxControl* control) { m_control = control; }    wxGridCellAttr* GetCellAttr() { return m_attr; }    void SetCellAttr(wxGridCellAttr* attr) { m_attr = attr; }    // Creates the actual edit control    virtual void Create(wxWindow* parent,                        wxWindowID id,                        wxEvtHandler* evtHandler) = 0;    // Size and position the edit control    virtual void SetSize(const wxRect& rect);    // Show or hide the edit control, use the specified attributes to set    // colours/fonts for it    virtual void Show(bool show, wxGridCellAttr *attr = (wxGridCellAttr *)NULL);    // Draws the part of the cell not occupied by the control: the base class    // version just fills it with background colour from the attribute    virtual void PaintBackground(const wxRect& rectCell, wxGridCellAttr *attr);    // Fetch the value from the table and prepare the edit control    // to begin editing.  Set the focus to the edit control.    virtual void BeginEdit(int row, int col, wxGrid* grid) = 0;    // Complete the editing of the current cell. Returns true if the value has    // changed.  If necessary, the control may be destroyed.    virtual bool EndEdit(int row, int col, wxGrid* grid) = 0;    // Reset the value in the control back to its starting value    virtual void Reset() = 0;    // return true to allow the given key to start editing: the base class    // version only checks that the event has no modifiers. The derived    // classes are supposed to do "if ( base::IsAcceptedKey() && ... )" in    // their IsAcceptedKey() implementation, although, of course, it is not a    // mandatory requirment.    //    // NB: if the key is F2 (special), editing will always start and this    //     method will not be called at all (but StartingKey() will)    virtual bool IsAcceptedKey(wxKeyEvent& event);    // If the editor is enabled by pressing keys on the grid, this will be    // called to let the editor do something about that first key if desired    virtual void StartingKey(wxKeyEvent& event);    // if the editor is enabled by clicking on the cell, this method will be    // called    virtual void StartingClick();    // Some types of controls on some platforms may need some help    // with the Return key.    virtual void HandleReturn(wxKeyEvent& event);    // Final cleanup    virtual void Destroy();    // create a new object which is the copy of this one    virtual wxGridCellEditor *Clone() const = 0;    // added GetValue so we can get the value which is in the control    virtual wxString GetValue() const = 0;protected:    // the dtor is private because only DecRef() can delete us    virtual ~wxGridCellEditor();    // the control we show on screen    wxControl*  m_control;    // a temporary pointer to the attribute being edited    wxGridCellAttr* m_attr;    // if we change the colours/font of the control from the default ones, we    // must restore the default later and we save them here between calls to    // Show(true) and Show(false)    wxColour m_colFgOld,             m_colBgOld;    wxFont m_fontOld;    // suppress the stupid gcc warning about the class having private dtor and    // no friends    friend class wxGridCellEditorDummyFriend;    DECLARE_NO_COPY_CLASS(wxGridCellEditor)};#if wxUSE_TEXTCTRL

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -