home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / wxos2240.zip / wxWindows-2.4.0 / include / wx / dbgrid.h < prev    next >
C/C++ Source or Header  |  2002-08-31  |  5KB  |  170 lines

  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: dbgrid.h,v 1.7 2002/08/31 11:29:09 GD Exp $
  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 defined(__GNUG__) && !defined(__APPLE__)
  18.     #pragma interface "dbgrid.h"
  19. #endif
  20.  
  21. #if wxUSE_ODBC
  22. #if wxUSE_NEW_GRID
  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.  
  32. WX_DECLARE_EXPORTED_OBJARRAY(GenericKey,keyarray);
  33.  
  34. static const int wxUSE_QUERY = -1;
  35.  
  36. class WXDLLEXPORT wxDbGridColInfoBase
  37. {
  38. public:
  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;
  52.         Title       = ref.Title;
  53.     }
  54.     //Empty destructor for member obj's
  55.     ~wxDbGridColInfoBase() {}
  56.  
  57.     int        DbCol;
  58.     wxString   wxtypename;
  59.     wxString   Title;
  60. };
  61.  
  62.  
  63. class WXDLLEXPORT wxDbGridColInfo
  64. {
  65. public:
  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.  
  81.     protected:
  82.     wxDbGridColInfoBase  m_data;
  83.     wxDbGridColInfo     *m_next;
  84.  
  85.     friend class wxDbGridTableBase;
  86. };
  87.  
  88.  
  89. class WXDLLEXPORT wxDbGridCellAttrProvider : public wxGridCellAttrProvider
  90. {
  91. public:
  92.     wxDbGridCellAttrProvider();
  93.     wxDbGridCellAttrProvider(wxDbTable *tab, wxDbGridColInfoBase* ColInfo);
  94.     virtual ~wxDbGridCellAttrProvider();
  95.  
  96.     virtual wxGridCellAttr *GetAttr(int row, int col,
  97.                                     wxGridCellAttr::wxAttrKind kind) const;
  98.     virtual void AssignDbTable(wxDbTable *tab);
  99. private:
  100.     wxDbTable           *m_data;
  101.     wxDbGridColInfoBase *m_ColInfo;
  102. };
  103.  
  104.  
  105. class WXDLLEXPORT wxDbGridTableBase : public wxGridTableBase
  106. {
  107. public:
  108.     wxDbGridTableBase(wxDbTable *tab, wxDbGridColInfo *ColInfo,
  109.               int count = wxUSE_QUERY, bool takeOwnership = TRUE);
  110.     ~wxDbGridTableBase();
  111.  
  112.     virtual int GetNumberRows()
  113.     {
  114.         wxLogDebug(" GetNumberRows() = %i",m_rowtotal);
  115.         return m_rowtotal;
  116.     }
  117.     virtual int GetNumberCols()
  118.     {
  119.         wxLogDebug(" GetNumberCols() = %i",m_nocols);
  120.         return m_nocols;
  121.     }
  122.     virtual bool     IsEmptyCell(int row, int col) ;
  123.     virtual wxString GetValue(int row, int col) ;
  124.     virtual void     SetValue(int row, int col, const wxString& value);
  125.     virtual bool     CanHaveAttributes();
  126.     virtual wxString GetTypeName(int row, int col);
  127.     virtual bool     CanGetValueAs(int row, int col, const wxString& typeName);
  128.     virtual bool     CanSetValueAs(int row, int col, const wxString& typeName);
  129.     virtual long     GetValueAsLong(int row, int col);
  130.     virtual double   GetValueAsDouble(int row, int col);
  131.     virtual bool     GetValueAsBool(int row, int col);
  132.     virtual void     SetValueAsLong(int row, int col, long value);
  133.     virtual void     SetValueAsDouble(int row, int col, double value);
  134.     virtual void     SetValueAsBool(int row, int col, bool value);
  135.     virtual void    *GetValueAsCustom(int row, int col, const wxString& typeName);
  136.     virtual void     SetValueAsCustom(int row, int col, const wxString& typeName, void* value);
  137.  
  138.  
  139.     virtual wxString GetColLabelValue(int col);
  140.  
  141.     virtual bool     AssignDbTable(wxDbTable *tab, int count = wxUSE_QUERY, bool takeOwnership=TRUE);
  142.     virtual void     ValidateRow(int row);
  143.     virtual bool     UpdateRow(int row) const
  144.     {
  145.         if (m_row != row)
  146.             return TRUE;
  147.         else
  148.             return Writeback();
  149.     }
  150.  
  151. private:
  152.     //Operates on the current row
  153.     bool Writeback() const;
  154.  
  155.     typedef wxGridTableBase inherited;
  156.     keyarray     m_keys;
  157.     wxDbTable   *m_data;
  158.     bool         m_dbowner;
  159.     int          m_rowtotal;
  160.     int          m_nocols;
  161.     int          m_row;
  162.     wxDbGridColInfoBase *m_ColInfo;
  163.     bool         m_rowmodified;
  164. };
  165.  
  166. #endif  // #if wxUSE_NEW_GRID
  167. #endif  // #if wxUSE_ODBC
  168.  
  169. #endif  // _WX_GENERIC_DBGRID_H_
  170.