2001-06-10 13:08:42 -04:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: dbgrid.h
|
|
|
|
// Purpose: Displays a wxDbTable in a wxGrid.
|
|
|
|
// Author: Roger Gammans, Paul Gammans
|
|
|
|
// Modified by:
|
2001-06-11 10:12:32 -04:00
|
|
|
// Created:
|
2001-06-10 13:08:42 -04:00
|
|
|
// RCS-ID: $Id$
|
|
|
|
// Copyright: (c) 1999 The Computer Surgery (roger@computer-surgery.co.uk)
|
2004-05-23 16:53:33 -04:00
|
|
|
// Licence: wxWindows licence
|
2001-06-10 13:08:42 -04:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Branched From : dbgrid.h,v 1.19 2001/03/28 11:16:01
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#ifndef _WX_GENERIC_DBGRID_H_
|
|
|
|
#define _WX_GENERIC_DBGRID_H_
|
|
|
|
|
|
|
|
#if wxUSE_ODBC
|
2003-06-11 06:03:57 -04:00
|
|
|
#if wxUSE_GRID
|
2001-06-10 13:08:42 -04:00
|
|
|
|
|
|
|
#include "wx/log.h"
|
|
|
|
#include "wx/dbtable.h"
|
|
|
|
#include "wx/dynarray.h"
|
|
|
|
#include "wx/grid.h"
|
|
|
|
#include "wx/dbkeyg.h"
|
|
|
|
|
|
|
|
#define wxGRID_VALUE_DBAUTO _T("dbauto")
|
|
|
|
|
2004-06-13 11:39:26 -04:00
|
|
|
WX_DECLARE_USER_EXPORTED_OBJARRAY(GenericKey,keyarray,WXDLLIMPEXP_DBGRID);
|
2001-06-10 13:08:42 -04:00
|
|
|
|
|
|
|
static const int wxUSE_QUERY = -1;
|
|
|
|
|
2003-08-03 16:26:51 -04:00
|
|
|
class WXDLLIMPEXP_DBGRID wxDbGridColInfoBase
|
2001-06-10 13:08:42 -04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
//Default ctor
|
|
|
|
wxDbGridColInfoBase() { }
|
|
|
|
wxDbGridColInfoBase(int colNo,
|
|
|
|
wxString type, wxString title) :
|
|
|
|
DbCol(colNo),
|
|
|
|
wxtypename(type),
|
|
|
|
Title(title)
|
|
|
|
{ }
|
|
|
|
//Copy Ctor
|
|
|
|
wxDbGridColInfoBase(const wxDbGridColInfoBase& ref)
|
|
|
|
{
|
|
|
|
DbCol = ref.DbCol;
|
|
|
|
wxtypename = ref.wxtypename;
|
2001-06-11 10:12:32 -04:00
|
|
|
Title = ref.Title;
|
2001-06-10 13:08:42 -04:00
|
|
|
}
|
|
|
|
//Empty destructor for member obj's
|
|
|
|
~wxDbGridColInfoBase() {}
|
2001-06-11 10:12:32 -04:00
|
|
|
|
2001-06-10 13:08:42 -04:00
|
|
|
int DbCol;
|
|
|
|
wxString wxtypename;
|
|
|
|
wxString Title;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2003-08-03 16:26:51 -04:00
|
|
|
class WXDLLIMPEXP_DBGRID wxDbGridColInfo
|
2001-06-10 13:08:42 -04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
wxDbGridColInfo(int colNo,
|
|
|
|
wxString type,
|
|
|
|
wxString title,
|
|
|
|
wxDbGridColInfo *next) :
|
|
|
|
m_data(colNo,type,title)
|
|
|
|
{
|
|
|
|
m_next=next;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Empty List
|
|
|
|
~wxDbGridColInfo() { delete m_next; }
|
|
|
|
|
|
|
|
//Recurse to find length.
|
|
|
|
int Length() { return (m_next ? m_next->Length() +1 : 1); }
|
|
|
|
|
2002-12-08 11:04:36 -05:00
|
|
|
// Adds a new column info (2 step creation)
|
|
|
|
void AddColInfo (int colNo,
|
|
|
|
wxString type,
|
|
|
|
wxString title)
|
|
|
|
{
|
|
|
|
GetLast()->m_next = new wxDbGridColInfo (colNo, type, title, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Searches last
|
|
|
|
wxDbGridColInfo *GetLast() { return (m_next ? m_next->GetLast() : this); }
|
|
|
|
|
|
|
|
|
2001-06-10 13:08:42 -04:00
|
|
|
protected:
|
|
|
|
wxDbGridColInfoBase m_data;
|
|
|
|
wxDbGridColInfo *m_next;
|
|
|
|
|
|
|
|
friend class wxDbGridTableBase;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2003-08-03 16:26:51 -04:00
|
|
|
class WXDLLIMPEXP_DBGRID wxDbGridCellAttrProvider : public wxGridCellAttrProvider
|
2001-06-10 13:08:42 -04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
wxDbGridCellAttrProvider();
|
|
|
|
wxDbGridCellAttrProvider(wxDbTable *tab, wxDbGridColInfoBase* ColInfo);
|
|
|
|
virtual ~wxDbGridCellAttrProvider();
|
|
|
|
|
|
|
|
virtual wxGridCellAttr *GetAttr(int row, int col,
|
|
|
|
wxGridCellAttr::wxAttrKind kind) const;
|
|
|
|
virtual void AssignDbTable(wxDbTable *tab);
|
|
|
|
private:
|
|
|
|
wxDbTable *m_data;
|
|
|
|
wxDbGridColInfoBase *m_ColInfo;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2003-08-03 16:26:51 -04:00
|
|
|
class WXDLLIMPEXP_DBGRID wxDbGridTableBase : public wxGridTableBase
|
2001-06-10 13:08:42 -04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
wxDbGridTableBase(wxDbTable *tab, wxDbGridColInfo *ColInfo,
|
2004-09-10 08:56:07 -04:00
|
|
|
int count = wxUSE_QUERY, bool takeOwnership = true);
|
2006-09-05 16:47:48 -04:00
|
|
|
virtual ~wxDbGridTableBase();
|
2001-06-10 13:08:42 -04:00
|
|
|
|
|
|
|
virtual int GetNumberRows()
|
|
|
|
{
|
2003-09-18 10:03:09 -04:00
|
|
|
wxLogDebug(_T(" GetNumberRows() = %i"),m_rowtotal);
|
2001-06-11 10:12:32 -04:00
|
|
|
return m_rowtotal;
|
2001-06-10 13:08:42 -04:00
|
|
|
}
|
|
|
|
virtual int GetNumberCols()
|
2001-06-11 10:12:32 -04:00
|
|
|
{
|
2003-09-18 10:03:09 -04:00
|
|
|
wxLogDebug(_T(" GetNumberCols() = %i"),m_nocols);
|
2001-06-11 10:12:32 -04:00
|
|
|
return m_nocols;
|
2001-06-10 13:08:42 -04:00
|
|
|
}
|
|
|
|
virtual bool IsEmptyCell(int row, int col) ;
|
|
|
|
virtual wxString GetValue(int row, int col) ;
|
|
|
|
virtual void SetValue(int row, int col, const wxString& value);
|
|
|
|
virtual bool CanHaveAttributes();
|
|
|
|
virtual wxString GetTypeName(int row, int col);
|
|
|
|
virtual bool CanGetValueAs(int row, int col, const wxString& typeName);
|
|
|
|
virtual bool CanSetValueAs(int row, int col, const wxString& typeName);
|
|
|
|
virtual long GetValueAsLong(int row, int col);
|
|
|
|
virtual double GetValueAsDouble(int row, int col);
|
|
|
|
virtual bool GetValueAsBool(int row, int col);
|
|
|
|
virtual void SetValueAsLong(int row, int col, long value);
|
|
|
|
virtual void SetValueAsDouble(int row, int col, double value);
|
|
|
|
virtual void SetValueAsBool(int row, int col, bool value);
|
|
|
|
virtual void *GetValueAsCustom(int row, int col, const wxString& typeName);
|
|
|
|
virtual void SetValueAsCustom(int row, int col, const wxString& typeName, void* value);
|
|
|
|
|
|
|
|
|
2001-11-07 04:26:33 -05:00
|
|
|
virtual wxString GetColLabelValue(int col);
|
2001-06-10 13:08:42 -04:00
|
|
|
|
2004-09-10 08:56:07 -04:00
|
|
|
virtual bool AssignDbTable(wxDbTable *tab, int count = wxUSE_QUERY, bool takeOwnership=true);
|
2001-06-10 13:08:42 -04:00
|
|
|
virtual void ValidateRow(int row);
|
|
|
|
virtual bool UpdateRow(int row) const
|
|
|
|
{
|
|
|
|
if (m_row != row)
|
2004-09-10 08:56:07 -04:00
|
|
|
return true;
|
2001-06-11 10:12:32 -04:00
|
|
|
else
|
2001-06-10 13:08:42 -04:00
|
|
|
return Writeback();
|
|
|
|
}
|
2001-06-11 10:12:32 -04:00
|
|
|
|
2001-06-10 13:08:42 -04:00
|
|
|
private:
|
|
|
|
//Operates on the current row
|
|
|
|
bool Writeback() const;
|
|
|
|
|
|
|
|
typedef wxGridTableBase inherited;
|
|
|
|
keyarray m_keys;
|
|
|
|
wxDbTable *m_data;
|
|
|
|
bool m_dbowner;
|
|
|
|
int m_rowtotal;
|
|
|
|
int m_nocols;
|
|
|
|
int m_row;
|
|
|
|
wxDbGridColInfoBase *m_ColInfo;
|
|
|
|
bool m_rowmodified;
|
|
|
|
};
|
|
|
|
|
2003-06-11 06:03:57 -04:00
|
|
|
#endif // #if wxUSE_GRID
|
2001-06-10 13:08:42 -04:00
|
|
|
#endif // #if wxUSE_ODBC
|
|
|
|
|
2001-06-11 10:12:32 -04:00
|
|
|
#endif // _WX_GENERIC_DBGRID_H_
|