]> git.saurik.com Git - wxWidgets.git/blame - include/wx/dbgrid.h
Compile fixes
[wxWidgets.git] / include / wx / dbgrid.h
CommitLineData
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)
65571936 9// Licence: wxWindows licence
32a2907b
GT
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
32a2907b 17#if wxUSE_ODBC
dd74a7ad 18#if wxUSE_GRID
32a2907b
GT
19
20#include "wx/log.h"
21#include "wx/dbtable.h"
22#include "wx/dynarray.h"
23#include "wx/grid.h"
24#include "wx/dbkeyg.h"
25
26#define wxGRID_VALUE_DBAUTO _T("dbauto")
27
bfe13288 28WX_DECLARE_USER_EXPORTED_OBJARRAY(GenericKey,keyarray,WXDLLIMPEXP_DBGRID);
32a2907b
GT
29
30static const int wxUSE_QUERY = -1;
31
83b9886f 32class WXDLLIMPEXP_DBGRID wxDbGridColInfoBase
32a2907b
GT
33{
34public:
35 //Default ctor
36 wxDbGridColInfoBase() { }
37 wxDbGridColInfoBase(int colNo,
38 wxString type, wxString title) :
39 DbCol(colNo),
40 wxtypename(type),
41 Title(title)
42 { }
43 //Copy Ctor
44 wxDbGridColInfoBase(const wxDbGridColInfoBase& ref)
45 {
46 DbCol = ref.DbCol;
47 wxtypename = ref.wxtypename;
9aa3137d 48 Title = ref.Title;
32a2907b
GT
49 }
50 //Empty destructor for member obj's
51 ~wxDbGridColInfoBase() {}
9aa3137d 52
32a2907b
GT
53 int DbCol;
54 wxString wxtypename;
55 wxString Title;
56};
57
58
83b9886f 59class WXDLLIMPEXP_DBGRID wxDbGridColInfo
32a2907b
GT
60{
61public:
62 wxDbGridColInfo(int colNo,
63 wxString type,
64 wxString title,
65 wxDbGridColInfo *next) :
66 m_data(colNo,type,title)
67 {
68 m_next=next;
69 }
70
71 //Empty List
72 ~wxDbGridColInfo() { delete m_next; }
73
74 //Recurse to find length.
75 int Length() { return (m_next ? m_next->Length() +1 : 1); }
76
f24badde
RG
77 // Adds a new column info (2 step creation)
78 void AddColInfo (int colNo,
79 wxString type,
80 wxString title)
81 {
82 GetLast()->m_next = new wxDbGridColInfo (colNo, type, title, NULL);
83 }
84
85 // Searches last
86 wxDbGridColInfo *GetLast() { return (m_next ? m_next->GetLast() : this); }
87
88
32a2907b
GT
89 protected:
90 wxDbGridColInfoBase m_data;
91 wxDbGridColInfo *m_next;
92
93 friend class wxDbGridTableBase;
94};
95
96
83b9886f 97class WXDLLIMPEXP_DBGRID wxDbGridCellAttrProvider : public wxGridCellAttrProvider
32a2907b
GT
98{
99public:
100 wxDbGridCellAttrProvider();
101 wxDbGridCellAttrProvider(wxDbTable *tab, wxDbGridColInfoBase* ColInfo);
102 virtual ~wxDbGridCellAttrProvider();
103
104 virtual wxGridCellAttr *GetAttr(int row, int col,
105 wxGridCellAttr::wxAttrKind kind) const;
106 virtual void AssignDbTable(wxDbTable *tab);
107private:
108 wxDbTable *m_data;
109 wxDbGridColInfoBase *m_ColInfo;
110};
111
112
83b9886f 113class WXDLLIMPEXP_DBGRID wxDbGridTableBase : public wxGridTableBase
32a2907b
GT
114{
115public:
116 wxDbGridTableBase(wxDbTable *tab, wxDbGridColInfo *ColInfo,
68379eaf 117 int count = wxUSE_QUERY, bool takeOwnership = true);
d3c7fc99 118 virtual ~wxDbGridTableBase();
32a2907b
GT
119
120 virtual int GetNumberRows()
121 {
8a39593e 122 wxLogDebug(_T(" GetNumberRows() = %i"),m_rowtotal);
9aa3137d 123 return m_rowtotal;
32a2907b
GT
124 }
125 virtual int GetNumberCols()
9aa3137d 126 {
8a39593e 127 wxLogDebug(_T(" GetNumberCols() = %i"),m_nocols);
9aa3137d 128 return m_nocols;
32a2907b
GT
129 }
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);
145
146
abfcca57 147 virtual wxString GetColLabelValue(int col);
32a2907b 148
68379eaf 149 virtual bool AssignDbTable(wxDbTable *tab, int count = wxUSE_QUERY, bool takeOwnership=true);
32a2907b
GT
150 virtual void ValidateRow(int row);
151 virtual bool UpdateRow(int row) const
152 {
153 if (m_row != row)
68379eaf 154 return true;
9aa3137d 155 else
32a2907b
GT
156 return Writeback();
157 }
9aa3137d 158
32a2907b
GT
159private:
160 //Operates on the current row
161 bool Writeback() const;
162
163 typedef wxGridTableBase inherited;
164 keyarray m_keys;
165 wxDbTable *m_data;
166 bool m_dbowner;
167 int m_rowtotal;
168 int m_nocols;
169 int m_row;
170 wxDbGridColInfoBase *m_ColInfo;
171 bool m_rowmodified;
172};
173
dd74a7ad 174#endif // #if wxUSE_GRID
32a2907b
GT
175#endif // #if wxUSE_ODBC
176
9aa3137d 177#endif // _WX_GENERIC_DBGRID_H_