]> git.saurik.com Git - wxWidgets.git/blame - include/wx/dbgrid.h
added wxTLWBase::GetDefaultSize() to avoid creating windows with default size unsuita...
[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)
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
12028905 17#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
32a2907b
GT
18 #pragma interface "dbgrid.h"
19#endif
20
21#if wxUSE_ODBC
dd74a7ad 22#if wxUSE_GRID
32a2907b
GT
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
12353a27 32WX_DECLARE_EXPORTED_OBJARRAY(GenericKey,keyarray);
32a2907b
GT
33
34static const int wxUSE_QUERY = -1;
35
83b9886f 36class WXDLLIMPEXP_DBGRID wxDbGridColInfoBase
32a2907b
GT
37{
38public:
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
83b9886f 63class WXDLLIMPEXP_DBGRID wxDbGridColInfo
32a2907b
GT
64{
65public:
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
f24badde
RG
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
32a2907b
GT
93 protected:
94 wxDbGridColInfoBase m_data;
95 wxDbGridColInfo *m_next;
96
97 friend class wxDbGridTableBase;
98};
99
100
83b9886f 101class WXDLLIMPEXP_DBGRID wxDbGridCellAttrProvider : public wxGridCellAttrProvider
32a2907b
GT
102{
103public:
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);
111private:
112 wxDbTable *m_data;
113 wxDbGridColInfoBase *m_ColInfo;
114};
115
116
83b9886f 117class WXDLLIMPEXP_DBGRID wxDbGridTableBase : public wxGridTableBase
32a2907b
GT
118{
119public:
120 wxDbGridTableBase(wxDbTable *tab, wxDbGridColInfo *ColInfo,
a144affe 121 int count = wxUSE_QUERY, bool takeOwnership = TRUE);
32a2907b
GT
122 ~wxDbGridTableBase();
123
124 virtual int GetNumberRows()
125 {
8a39593e 126 wxLogDebug(_T(" GetNumberRows() = %i"),m_rowtotal);
9aa3137d 127 return m_rowtotal;
32a2907b
GT
128 }
129 virtual int GetNumberCols()
9aa3137d 130 {
8a39593e 131 wxLogDebug(_T(" GetNumberCols() = %i"),m_nocols);
9aa3137d 132 return m_nocols;
32a2907b
GT
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
abfcca57 151 virtual wxString GetColLabelValue(int col);
32a2907b 152
a144affe 153 virtual bool AssignDbTable(wxDbTable *tab, int count = wxUSE_QUERY, bool takeOwnership=TRUE);
32a2907b
GT
154 virtual void ValidateRow(int row);
155 virtual bool UpdateRow(int row) const
156 {
157 if (m_row != row)
a144affe 158 return TRUE;
9aa3137d 159 else
32a2907b
GT
160 return Writeback();
161 }
9aa3137d 162
32a2907b
GT
163private:
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
dd74a7ad 178#endif // #if wxUSE_GRID
32a2907b
GT
179#endif // #if wxUSE_ODBC
180
9aa3137d 181#endif // _WX_GENERIC_DBGRID_H_