]> git.saurik.com Git - wxWidgets.git/blame_incremental - include/wx/dbgrid.h
Added wxDataViewBitmapCell
[wxWidgets.git] / include / wx / dbgrid.h
... / ...
CommitLineData
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 wxUSE_ODBC
18#if wxUSE_GRID
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
28WX_DECLARE_USER_EXPORTED_OBJARRAY(GenericKey,keyarray,WXDLLIMPEXP_DBGRID);
29
30static const int wxUSE_QUERY = -1;
31
32class WXDLLIMPEXP_DBGRID wxDbGridColInfoBase
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;
48 Title = ref.Title;
49 }
50 //Empty destructor for member obj's
51 ~wxDbGridColInfoBase() {}
52
53 int DbCol;
54 wxString wxtypename;
55 wxString Title;
56};
57
58
59class WXDLLIMPEXP_DBGRID wxDbGridColInfo
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
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
89 protected:
90 wxDbGridColInfoBase m_data;
91 wxDbGridColInfo *m_next;
92
93 friend class wxDbGridTableBase;
94};
95
96
97class WXDLLIMPEXP_DBGRID wxDbGridCellAttrProvider : public wxGridCellAttrProvider
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
113class WXDLLIMPEXP_DBGRID wxDbGridTableBase : public wxGridTableBase
114{
115public:
116 wxDbGridTableBase(wxDbTable *tab, wxDbGridColInfo *ColInfo,
117 int count = wxUSE_QUERY, bool takeOwnership = true);
118 virtual ~wxDbGridTableBase();
119
120 virtual int GetNumberRows()
121 {
122 wxLogDebug(_T(" GetNumberRows() = %i"),m_rowtotal);
123 return m_rowtotal;
124 }
125 virtual int GetNumberCols()
126 {
127 wxLogDebug(_T(" GetNumberCols() = %i"),m_nocols);
128 return m_nocols;
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
147 virtual wxString GetColLabelValue(int col);
148
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
152 {
153 if (m_row != row)
154 return true;
155 else
156 return Writeback();
157 }
158
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
174#endif // #if wxUSE_GRID
175#endif // #if wxUSE_ODBC
176
177#endif // _WX_GENERIC_DBGRID_H_