]>
Commit | Line | Data |
---|---|---|
1 | /////////////////////////////////////////////////////////////////////////////// | |
2 | // Name: dbgrid.h | |
3 | // Purpose: Displays a wxDbTable in a wxGrid. | |
4 | // Author: Roger Gammans, Paul Gammans | |
5 | // Modified by: | |
6 | // Created: | |
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 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) | |
18 | #pragma interface "dbgrid.h" | |
19 | #endif | |
20 | ||
21 | #if wxUSE_ODBC | |
22 | #if wxUSE_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_EXPORTED_OBJARRAY(GenericKey,keyarray); | |
33 | ||
34 | static const int wxUSE_QUERY = -1; | |
35 | ||
36 | class WXDLLIMPEXP_DBGRID 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; | |
52 | Title = ref.Title; | |
53 | } | |
54 | //Empty destructor for member obj's | |
55 | ~wxDbGridColInfoBase() {} | |
56 | ||
57 | int DbCol; | |
58 | wxString wxtypename; | |
59 | wxString Title; | |
60 | }; | |
61 | ||
62 | ||
63 | class WXDLLIMPEXP_DBGRID 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 | // Adds a new column info (2 step creation) | |
82 | void AddColInfo (int colNo, | |
83 | wxString type, | |
84 | wxString title) | |
85 | { | |
86 | GetLast()->m_next = new wxDbGridColInfo (colNo, type, title, NULL); | |
87 | } | |
88 | ||
89 | // Searches last | |
90 | wxDbGridColInfo *GetLast() { return (m_next ? m_next->GetLast() : this); } | |
91 | ||
92 | ||
93 | protected: | |
94 | wxDbGridColInfoBase m_data; | |
95 | wxDbGridColInfo *m_next; | |
96 | ||
97 | friend class wxDbGridTableBase; | |
98 | }; | |
99 | ||
100 | ||
101 | class WXDLLIMPEXP_DBGRID wxDbGridCellAttrProvider : public wxGridCellAttrProvider | |
102 | { | |
103 | public: | |
104 | wxDbGridCellAttrProvider(); | |
105 | wxDbGridCellAttrProvider(wxDbTable *tab, wxDbGridColInfoBase* ColInfo); | |
106 | virtual ~wxDbGridCellAttrProvider(); | |
107 | ||
108 | virtual wxGridCellAttr *GetAttr(int row, int col, | |
109 | wxGridCellAttr::wxAttrKind kind) const; | |
110 | virtual void AssignDbTable(wxDbTable *tab); | |
111 | private: | |
112 | wxDbTable *m_data; | |
113 | wxDbGridColInfoBase *m_ColInfo; | |
114 | }; | |
115 | ||
116 | ||
117 | class WXDLLIMPEXP_DBGRID wxDbGridTableBase : public wxGridTableBase | |
118 | { | |
119 | public: | |
120 | wxDbGridTableBase(wxDbTable *tab, wxDbGridColInfo *ColInfo, | |
121 | int count = wxUSE_QUERY, bool takeOwnership = TRUE); | |
122 | ~wxDbGridTableBase(); | |
123 | ||
124 | virtual int GetNumberRows() | |
125 | { | |
126 | wxLogDebug(_T(" GetNumberRows() = %i"),m_rowtotal); | |
127 | return m_rowtotal; | |
128 | } | |
129 | virtual int GetNumberCols() | |
130 | { | |
131 | wxLogDebug(_T(" GetNumberCols() = %i"),m_nocols); | |
132 | return m_nocols; | |
133 | } | |
134 | virtual bool IsEmptyCell(int row, int col) ; | |
135 | virtual wxString GetValue(int row, int col) ; | |
136 | virtual void SetValue(int row, int col, const wxString& value); | |
137 | virtual bool CanHaveAttributes(); | |
138 | virtual wxString GetTypeName(int row, int col); | |
139 | virtual bool CanGetValueAs(int row, int col, const wxString& typeName); | |
140 | virtual bool CanSetValueAs(int row, int col, const wxString& typeName); | |
141 | virtual long GetValueAsLong(int row, int col); | |
142 | virtual double GetValueAsDouble(int row, int col); | |
143 | virtual bool GetValueAsBool(int row, int col); | |
144 | virtual void SetValueAsLong(int row, int col, long value); | |
145 | virtual void SetValueAsDouble(int row, int col, double value); | |
146 | virtual void SetValueAsBool(int row, int col, bool value); | |
147 | virtual void *GetValueAsCustom(int row, int col, const wxString& typeName); | |
148 | virtual void SetValueAsCustom(int row, int col, const wxString& typeName, void* value); | |
149 | ||
150 | ||
151 | virtual wxString GetColLabelValue(int col); | |
152 | ||
153 | virtual bool AssignDbTable(wxDbTable *tab, int count = wxUSE_QUERY, bool takeOwnership=TRUE); | |
154 | virtual void ValidateRow(int row); | |
155 | virtual bool UpdateRow(int row) const | |
156 | { | |
157 | if (m_row != row) | |
158 | return TRUE; | |
159 | else | |
160 | return Writeback(); | |
161 | } | |
162 | ||
163 | private: | |
164 | //Operates on the current row | |
165 | bool Writeback() const; | |
166 | ||
167 | typedef wxGridTableBase inherited; | |
168 | keyarray m_keys; | |
169 | wxDbTable *m_data; | |
170 | bool m_dbowner; | |
171 | int m_rowtotal; | |
172 | int m_nocols; | |
173 | int m_row; | |
174 | wxDbGridColInfoBase *m_ColInfo; | |
175 | bool m_rowmodified; | |
176 | }; | |
177 | ||
178 | #endif // #if wxUSE_GRID | |
179 | #endif // #if wxUSE_ODBC | |
180 | ||
181 | #endif // _WX_GENERIC_DBGRID_H_ |