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)
|
|
|
|
// Licence: wxWindows licence
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Branched From : dbgrid.h,v 1.19 2001/03/28 11:16:01
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#ifndef _WX_GENERIC_DBGRID_H_
|
|
|
|
#define _WX_GENERIC_DBGRID_H_
|
|
|
|
|
2002-08-31 07:29:13 -04:00
|
|
|
#if defined(__GNUG__) && !defined(__APPLE__)
|
2001-06-10 13:08:42 -04:00
|
|
|
#pragma interface "dbgrid.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if wxUSE_ODBC
|
|
|
|
#if wxUSE_NEW_GRID
|
|
|
|
|
|
|
|
#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")
|
|
|
|
|
2002-01-16 14:50:01 -05:00
|
|
|
WX_DECLARE_EXPORTED_OBJARRAY(GenericKey,keyarray);
|
2001-06-10 13:08:42 -04:00
|
|
|
|
|
|
|
static const int wxUSE_QUERY = -1;
|
|
|
|
|
2002-01-14 07:14:38 -05:00
|
|
|
class WXDLLEXPORT 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;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2002-01-14 07:14:38 -05:00
|
|
|
class WXDLLEXPORT 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); }
|
|
|
|
|
|
|
|
protected:
|
|
|
|
wxDbGridColInfoBase m_data;
|
|
|
|
wxDbGridColInfo *m_next;
|
|
|
|
|
|
|
|
friend class wxDbGridTableBase;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2002-01-14 07:14:38 -05:00
|
|
|
class WXDLLEXPORT 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;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2002-01-14 07:14:38 -05:00
|
|
|
class WXDLLEXPORT wxDbGridTableBase : public wxGridTableBase
|
2001-06-10 13:08:42 -04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
wxDbGridTableBase(wxDbTable *tab, wxDbGridColInfo *ColInfo,
|
2001-06-11 12:54:28 -04:00
|
|
|
int count = wxUSE_QUERY, bool takeOwnership = TRUE);
|
2001-06-10 13:08:42 -04:00
|
|
|
~wxDbGridTableBase();
|
|
|
|
|
|
|
|
virtual int GetNumberRows()
|
|
|
|
{
|
|
|
|
wxLogDebug(" 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
|
|
|
{
|
2001-06-10 13:08:42 -04:00
|
|
|
wxLogDebug(" 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
|
|
|
|
2001-06-11 12:54:28 -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)
|
2001-06-11 12:54:28 -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;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // #if wxUSE_NEW_GRID
|
|
|
|
#endif // #if wxUSE_ODBC
|
|
|
|
|
2001-06-11 10:12:32 -04:00
|
|
|
#endif // _WX_GENERIC_DBGRID_H_
|