]>
Commit | Line | Data |
---|---|---|
32a2907b GT |
1 | /////////////////////////////////////////////////////////////////////////////// |
2 | // Name: dbgrid.h | |
3 | // Purpose: Displays a wxDbTable in a wxGrid. | |
4 | // Author: Roger Gammans, Paul Gammans | |
5 | // Modified by: | |
9aa3137d | 6 | // Created: |
32a2907b GT |
7 | // RCS-ID: $Id$ |
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 | /////////////////////////////////////////////////////////////////////////////// | |
13 | ||
14 | #ifndef _WX_GENERIC_DBGRID_H_ | |
15 | #define _WX_GENERIC_DBGRID_H_ | |
16 | ||
17 | #ifdef __GNUG__ | |
18 | #pragma interface "dbgrid.h" | |
19 | #endif | |
20 | ||
21 | #if wxUSE_ODBC | |
22 | #if wxUSE_NEW_GRID | |
23 | ||
24 | #include "wx/log.h" | |
25 | #include "wx/dbtable.h" | |
26 | #include "wx/dynarray.h" | |
27 | #include "wx/grid.h" | |
28 | #include "wx/dbkeyg.h" | |
29 | ||
30 | #define wxGRID_VALUE_DBAUTO _T("dbauto") | |
31 | ||
32 | WX_DECLARE_OBJARRAY(GenericKey,keyarray); | |
33 | ||
34 | static const int wxUSE_QUERY = -1; | |
35 | ||
36 | class wxDbGridColInfoBase | |
37 | { | |
38 | public: | |
39 | //Default ctor | |
40 | wxDbGridColInfoBase() { } | |
41 | wxDbGridColInfoBase(int colNo, | |
42 | wxString type, wxString title) : | |
43 | DbCol(colNo), | |
44 | wxtypename(type), | |
45 | Title(title) | |
46 | { } | |
47 | //Copy Ctor | |
48 | wxDbGridColInfoBase(const wxDbGridColInfoBase& ref) | |
49 | { | |
50 | DbCol = ref.DbCol; | |
51 | wxtypename = ref.wxtypename; | |
9aa3137d | 52 | Title = ref.Title; |
32a2907b GT |
53 | } |
54 | //Empty destructor for member obj's | |
55 | ~wxDbGridColInfoBase() {} | |
9aa3137d | 56 | |
32a2907b GT |
57 | int DbCol; |
58 | wxString wxtypename; | |
59 | wxString Title; | |
60 | }; | |
61 | ||
62 | ||
63 | class wxDbGridColInfo | |
64 | { | |
65 | public: | |
66 | wxDbGridColInfo(int colNo, | |
67 | wxString type, | |
68 | wxString title, | |
69 | wxDbGridColInfo *next) : | |
70 | m_data(colNo,type,title) | |
71 | { | |
72 | m_next=next; | |
73 | } | |
74 | ||
75 | //Empty List | |
76 | ~wxDbGridColInfo() { delete m_next; } | |
77 | ||
78 | //Recurse to find length. | |
79 | int Length() { return (m_next ? m_next->Length() +1 : 1); } | |
80 | ||
81 | protected: | |
82 | wxDbGridColInfoBase m_data; | |
83 | wxDbGridColInfo *m_next; | |
84 | ||
85 | friend class wxDbGridTableBase; | |
86 | }; | |
87 | ||
88 | ||
89 | class wxDbGridCellAttrProvider : public wxGridCellAttrProvider | |
90 | { | |
91 | public: | |
92 | wxDbGridCellAttrProvider(); | |
93 | wxDbGridCellAttrProvider(wxDbTable *tab, wxDbGridColInfoBase* ColInfo); | |
94 | virtual ~wxDbGridCellAttrProvider(); | |
95 | ||
96 | virtual wxGridCellAttr *GetAttr(int row, int col, | |
97 | wxGridCellAttr::wxAttrKind kind) const; | |
98 | virtual void AssignDbTable(wxDbTable *tab); | |
99 | private: | |
100 | wxDbTable *m_data; | |
101 | wxDbGridColInfoBase *m_ColInfo; | |
102 | }; | |
103 | ||
104 | ||
105 | class wxDbGridTableBase : public wxGridTableBase | |
106 | { | |
107 | public: | |
108 | wxDbGridTableBase(wxDbTable *tab, wxDbGridColInfo *ColInfo, | |
a144affe | 109 | int count = wxUSE_QUERY, bool takeOwnership = TRUE); |
32a2907b GT |
110 | ~wxDbGridTableBase(); |
111 | ||
112 | virtual int GetNumberRows() | |
113 | { | |
114 | wxLogDebug(" GetNumberRows() = %i",m_rowtotal); | |
9aa3137d | 115 | return m_rowtotal; |
32a2907b GT |
116 | } |
117 | virtual int GetNumberCols() | |
9aa3137d | 118 | { |
32a2907b | 119 | wxLogDebug(" GetNumberCols() = %i",m_nocols); |
9aa3137d | 120 | return m_nocols; |
32a2907b GT |
121 | } |
122 | virtual bool IsEmptyCell(int row, int col) ; | |
123 | virtual wxString GetValue(int row, int col) ; | |
124 | virtual void SetValue(int row, int col, const wxString& value); | |
125 | virtual bool CanHaveAttributes(); | |
126 | virtual wxString GetTypeName(int row, int col); | |
127 | virtual bool CanGetValueAs(int row, int col, const wxString& typeName); | |
128 | virtual bool CanSetValueAs(int row, int col, const wxString& typeName); | |
129 | virtual long GetValueAsLong(int row, int col); | |
130 | virtual double GetValueAsDouble(int row, int col); | |
131 | virtual bool GetValueAsBool(int row, int col); | |
132 | virtual void SetValueAsLong(int row, int col, long value); | |
133 | virtual void SetValueAsDouble(int row, int col, double value); | |
134 | virtual void SetValueAsBool(int row, int col, bool value); | |
135 | virtual void *GetValueAsCustom(int row, int col, const wxString& typeName); | |
136 | virtual void SetValueAsCustom(int row, int col, const wxString& typeName, void* value); | |
137 | ||
138 | ||
abfcca57 | 139 | virtual wxString GetColLabelValue(int col); |
32a2907b | 140 | |
a144affe | 141 | virtual bool AssignDbTable(wxDbTable *tab, int count = wxUSE_QUERY, bool takeOwnership=TRUE); |
32a2907b GT |
142 | virtual void ValidateRow(int row); |
143 | virtual bool UpdateRow(int row) const | |
144 | { | |
145 | if (m_row != row) | |
a144affe | 146 | return TRUE; |
9aa3137d | 147 | else |
32a2907b GT |
148 | return Writeback(); |
149 | } | |
9aa3137d | 150 | |
32a2907b GT |
151 | private: |
152 | //Operates on the current row | |
153 | bool Writeback() const; | |
154 | ||
155 | typedef wxGridTableBase inherited; | |
156 | keyarray m_keys; | |
157 | wxDbTable *m_data; | |
158 | bool m_dbowner; | |
159 | int m_rowtotal; | |
160 | int m_nocols; | |
161 | int m_row; | |
162 | wxDbGridColInfoBase *m_ColInfo; | |
163 | bool m_rowmodified; | |
164 | }; | |
165 | ||
166 | #endif // #if wxUSE_NEW_GRID | |
167 | #endif // #if wxUSE_ODBC | |
168 | ||
9aa3137d | 169 | #endif // _WX_GENERIC_DBGRID_H_ |