1 ///////////////////////////////////////////////////////////////////////////////
3 // Purpose: Displays a wxDbTable in a wxGrid.
4 // Author: Roger Gammans, Paul Gammans
8 // Copyright: (c) 1999 The Computer Surgery (roger@computer-surgery.co.uk)
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
11 // Branched From : dbgrid.h,v 1.19 2001/03/28 11:16:01
12 ///////////////////////////////////////////////////////////////////////////////
14 #ifndef _WX_GENERIC_DBGRID_H_
15 #define _WX_GENERIC_DBGRID_H_
21 #include "wx/dbtable.h"
22 #include "wx/dynarray.h"
24 #include "wx/dbkeyg.h"
26 #define wxGRID_VALUE_DBAUTO _T("dbauto")
28 WX_DECLARE_USER_EXPORTED_OBJARRAY(GenericKey
,keyarray
,WXDLLIMPEXP_DBGRID
);
30 static const int wxUSE_QUERY
= -1;
32 class WXDLLIMPEXP_DBGRID wxDbGridColInfoBase
36 wxDbGridColInfoBase() { }
37 wxDbGridColInfoBase(int colNo
,
38 wxString type
, wxString title
) :
44 wxDbGridColInfoBase(const wxDbGridColInfoBase
& ref
)
47 wxtypename
= ref
.wxtypename
;
50 //Empty destructor for member obj's
51 ~wxDbGridColInfoBase() {}
59 class WXDLLIMPEXP_DBGRID wxDbGridColInfo
62 wxDbGridColInfo(int colNo
,
65 wxDbGridColInfo
*next
) :
66 m_data(colNo
,type
,title
)
72 ~wxDbGridColInfo() { delete m_next
; }
74 //Recurse to find length.
75 int Length() { return (m_next
? m_next
->Length() +1 : 1); }
77 // Adds a new column info (2 step creation)
78 void AddColInfo (int colNo
,
82 GetLast()->m_next
= new wxDbGridColInfo (colNo
, type
, title
, NULL
);
86 wxDbGridColInfo
*GetLast() { return (m_next
? m_next
->GetLast() : this); }
90 wxDbGridColInfoBase m_data
;
91 wxDbGridColInfo
*m_next
;
93 friend class wxDbGridTableBase
;
97 class WXDLLIMPEXP_DBGRID wxDbGridCellAttrProvider
: public wxGridCellAttrProvider
100 wxDbGridCellAttrProvider();
101 wxDbGridCellAttrProvider(wxDbTable
*tab
, wxDbGridColInfoBase
* ColInfo
);
102 virtual ~wxDbGridCellAttrProvider();
104 virtual wxGridCellAttr
*GetAttr(int row
, int col
,
105 wxGridCellAttr::wxAttrKind kind
) const;
106 virtual void AssignDbTable(wxDbTable
*tab
);
109 wxDbGridColInfoBase
*m_ColInfo
;
113 class WXDLLIMPEXP_DBGRID wxDbGridTableBase
: public wxGridTableBase
116 wxDbGridTableBase(wxDbTable
*tab
, wxDbGridColInfo
*ColInfo
,
117 int count
= wxUSE_QUERY
, bool takeOwnership
= true);
118 virtual ~wxDbGridTableBase();
120 virtual int GetNumberRows()
122 wxLogDebug(_T(" GetNumberRows() = %i"),m_rowtotal
);
125 virtual int GetNumberCols()
127 wxLogDebug(_T(" GetNumberCols() = %i"),m_nocols
);
130 virtual bool IsEmptyCell(int row
, int col
) ;
131 virtual wxString
GetValue(int row
, int col
) ;
132 virtual void SetValue(int row
, int col
, const wxString
& value
);
133 virtual bool CanHaveAttributes();
134 virtual wxString
GetTypeName(int row
, int col
);
135 virtual bool CanGetValueAs(int row
, int col
, const wxString
& typeName
);
136 virtual bool CanSetValueAs(int row
, int col
, const wxString
& typeName
);
137 virtual long GetValueAsLong(int row
, int col
);
138 virtual double GetValueAsDouble(int row
, int col
);
139 virtual bool GetValueAsBool(int row
, int col
);
140 virtual void SetValueAsLong(int row
, int col
, long value
);
141 virtual void SetValueAsDouble(int row
, int col
, double value
);
142 virtual void SetValueAsBool(int row
, int col
, bool value
);
143 virtual void *GetValueAsCustom(int row
, int col
, const wxString
& typeName
);
144 virtual void SetValueAsCustom(int row
, int col
, const wxString
& typeName
, void* value
);
147 virtual wxString
GetColLabelValue(int col
);
149 virtual bool AssignDbTable(wxDbTable
*tab
, int count
= wxUSE_QUERY
, bool takeOwnership
=true);
150 virtual void ValidateRow(int row
);
151 virtual bool UpdateRow(int row
) const
160 //Operates on the current row
161 bool Writeback() const;
163 typedef wxGridTableBase inherited
;
170 wxDbGridColInfoBase
*m_ColInfo
;
174 #endif // #if wxUSE_GRID
175 #endif // #if wxUSE_ODBC
177 #endif // _WX_GENERIC_DBGRID_H_