home *** CD-ROM | disk | FTP | other *** search
/ C/C++ User's Journal & Wi…eveloper's Journal Tools / C-C__Users_Journal_and_Windows_Developers_Journal_Tools_1997.iso / stingray / browsevw.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-10-27  |  6.1 KB  |  266 lines

  1. // browsevw.cpp : implementation of the CDBaseBrowserView class
  2. //
  3.  
  4. // This is a part of the Objective Grid C++ Library.
  5. // Copyright (C) 1995,1996 ClassWorks, Stefan Hoenig.
  6. // All rights reserved.
  7. //
  8. // This source code is only intended as a supplement to
  9. // the Objective Grid Classes Reference and related
  10. // electronic documentation provided with the library.
  11. // See these sources for detailed information regarding
  12. // the Objective Grid product.
  13. //
  14.  
  15. #include "stdafx.h"
  16. #include "gridapp.h"
  17. #include "browsevw.h"
  18. #include <limits.h>
  19.  
  20. #ifdef _DEBUG
  21. #undef THIS_FILE
  22. static char BASED_CODE THIS_FILE[] = __FILE__;
  23. #endif
  24.  
  25. /////////////////////////////////////////////////////////////////////////////
  26. // CDBaseBrowserView
  27.  
  28. IMPLEMENT_DYNCREATE(CDBaseBrowserView, CMyGridView)
  29.  
  30. CDBaseBrowserView::CDBaseBrowserView()
  31. {
  32. }
  33.  
  34. CDBaseBrowserView::~CDBaseBrowserView()
  35. {
  36. }
  37.  
  38.  
  39. BEGIN_MESSAGE_MAP(CDBaseBrowserView, CMyGridView)
  40.     //{{AFX_MSG_MAP(CDBaseBrowserView)
  41.         // NOTE - the ClassWizard will add and remove mapping macros here.
  42.     //}}AFX_MSG_MAP
  43. END_MESSAGE_MAP()
  44.  
  45.  
  46. /////////////////////////////////////////////////////////////////////////////
  47. // CDBaseBrowserView diagnostics
  48.  
  49. #ifdef _DEBUG
  50. void CDBaseBrowserView::AssertValid() const
  51. {
  52.     CMyGridView::AssertValid();
  53. }
  54.  
  55. void CDBaseBrowserView::Dump(CDumpContext& dc) const
  56. {
  57.     CMyGridView::Dump(dc);
  58. }
  59. #endif //_DEBUG
  60.  
  61. /////////////////////////////////////////////////////////////////////////////
  62. // CDBaseBrowserView message handlers
  63.  
  64. void CDBaseBrowserView::OnInitialUpdate()
  65. {
  66.     BOOL bNew = (GetParam() == NULL);
  67.  
  68.     // Link grid to document,
  69.     SetParam(&GetDocument()->m_param, FALSE /* do not destroy*/);
  70.  
  71.     CMyGridView::OnInitialUpdate();
  72.  
  73.     EnableHints(TRUE);  // I have several views connected with one doc
  74. }
  75.  
  76. // Bind gridview to DBase file
  77. ROWCOL CDBaseBrowserView::GetRowCount()
  78. {
  79.     return GetDocument()->m_dbfile.nRecordCount;
  80. }
  81.  
  82. ROWCOL CDBaseBrowserView::GetColCount()
  83. {
  84.     return GetDocument()->m_dbfile.nFieldCount;
  85. }
  86.  
  87. CField* CDBaseBrowserView::GetField(ROWCOL nCol)
  88. {
  89.     return GetDocument()->m_dbfile.GetField(GetFieldId(nCol));
  90. }
  91.  
  92. int CDBaseBrowserView::GetFieldId(ROWCOL nCol)
  93. {
  94.     ASSERT(nCol >= 1 && nCol <= INT_MAX);
  95.     long nField = -1;
  96.  
  97.     GetDocument()->m_columnIdMap.Lookup(nCol, nField);
  98.     return (int) (nField);
  99. }
  100.  
  101. BOOL CDBaseBrowserView::GetStyleRowCol(ROWCOL nRow, ROWCOL nCol, CGXStyle& style, GXModifyType mt, int nType)
  102. {
  103.     if (mt == gxRemove) // not supported
  104.         return FALSE;
  105.  
  106.     // Note: I do not distinct between gxApplyNew, gxCopy and gxOverride
  107.  
  108.     ASSERT(nRow <= LONG_MAX);
  109.     long nRecord = (long) nRow;
  110.  
  111.     if (nType == -1)
  112.     {
  113.         // here you can return the style for a complete row, column or table
  114.         return FALSE;
  115.     }
  116.     else if (nRow == 0 && nCol == 0)
  117.     {
  118.         // style for the top-left button
  119.         return FALSE;
  120.     }
  121.     else if (nRow == 0)
  122.     {
  123.         // Column headers
  124.         // if application was compiled with _UNICODE
  125.         // the column name will be converted to wide chars
  126.          style.SetValue(GetField(nCol)->name);
  127.     }
  128.     else if (GetDocument()->m_dbfile.Seek(nRecord-1))
  129.     {
  130.         if (nCol == 0)
  131.         {
  132.             // Row headers
  133.             TCHAR buf[20];
  134.             wsprintf(buf, _T("%5lu%c"), nRow, GetDocument()->m_dbfile.IsDeleted() ? _T('*') : _T(' '));
  135.             style.SetValue(buf);
  136.         }
  137.         else
  138.         {
  139.             // Cell value
  140.             CString s;
  141.             CField* fld = GetField(nCol);
  142.             GetDocument()->m_dbfile.GetValue(GetFieldId(nCol), s);
  143.  
  144.             style
  145.                 .SetValue(s)
  146.                 .SetMaxLength(fld->len);
  147.  
  148.             // Note on UNICODE/DBCS Support:
  149.             // fld->type is a signed char even for this special modes
  150.  
  151.             switch (fld->type)
  152.             {
  153.             case 'N':   style.SetBaseStyle(GetDocument()->m_wStyleNumeric); break;
  154.             case 'C':   style.SetBaseStyle(GetDocument()->m_wStyleText); break;
  155.             case 'D':   style.SetBaseStyle(GetDocument()->m_wStyleDate); break;
  156.             case 'L':   style.SetBaseStyle(GetDocument()->m_wStyleLogical); break;
  157.             }
  158.         }
  159.         return TRUE;
  160.     }
  161.  
  162.     // unreferenced:
  163.     mt;
  164.  
  165.     return FALSE;
  166. }
  167.  
  168. BOOL CDBaseBrowserView::StoreStyleRowCol(ROWCOL nRow, ROWCOL nCol, const CGXStyle* pStyle, GXModifyType mt, int nType)
  169. {
  170.     if (mt == gxRemove) // not supported
  171.         return FALSE;
  172.  
  173.     // Note: I do not distinct between gxApplyNew, gxCopy and gxOverride
  174.  
  175.     ASSERT(nRow <= LONG_MAX);
  176.     long nRecord = (long) nRow;
  177.  
  178.     if (nType == -1)
  179.     {
  180.         // here you could store the style for a complete row, column or table
  181.         return FALSE;
  182.     }
  183.     else if (nRow == 0 && nCol == 0)
  184.     {
  185.         // style for the top-left button
  186.         return FALSE;
  187.     }
  188.     else if (nRow == 0)
  189.     {
  190.         // Column headers
  191.         return FALSE;
  192.     }
  193.     else if (GetDocument()->m_dbfile.Seek(nRecord-1))
  194.     {
  195.         if (nCol == 0)
  196.         {
  197.             // Row headers
  198.             return FALSE;
  199.         }
  200.         else
  201.         {
  202.             // Cell value
  203.             if (pStyle->GetIncludeValue())
  204.                 GetDocument()->m_dbfile.SetValue(GetFieldId(nCol), pStyle->GetValue());
  205.  
  206.             SetModifiedFlag();
  207.             return TRUE;
  208.         }
  209.     }
  210.  
  211.     // unreferenced:
  212.     mt;
  213.  
  214.     return FALSE;
  215. }
  216.  
  217. int CDBaseBrowserView::GetColWidth(ROWCOL nCol)
  218. {
  219.     ASSERT(nCol <= INT_MAX);
  220.  
  221.     if (nCol > 0)
  222.     {
  223.         // GX_NXAVGWIDTH is average logical width of a char
  224.         // Width_LPtoDP converts from logical to pixel value
  225.         if (IsColHidden(nCol))
  226.             return 0;
  227.         else
  228.             return Width_LPtoDP( (long) GetField(nCol)->display_width * GX_NXAVGWIDTH);
  229.     }
  230.  
  231.     return CMyGridView::GetColWidth(nCol);
  232. }
  233.  
  234. BOOL CDBaseBrowserView::StoreColWidth(ROWCOL nCol, int nWidth)
  235. {
  236.     ASSERT(nCol <= INT_MAX);
  237.  
  238.     if (nCol > 0)
  239.     {
  240.         if (nWidth > 0)
  241.         {
  242.             // GX_NXAVGWIDTH is average logical width of a char
  243.             // Width_DPtoLP converts from pixel to logical value
  244.             GetField(nCol)->display_width = (short) (Width_DPtoLP(nWidth) / GX_NXAVGWIDTH);
  245.         }
  246.         else
  247.             // reset to default column width
  248.             GetField(nCol)->display_width = GetField(nCol)->width ;
  249.  
  250.         SetModifiedFlag();
  251.  
  252.         return TRUE;
  253.     }
  254.  
  255.     return CMyGridView::StoreColWidth(nCol, nWidth);
  256. }
  257.  
  258. BOOL CDBaseBrowserView::StoreMoveCols(ROWCOL nFromCol, ROWCOL nToCol, ROWCOL nDestCol, BOOL bProcessed)
  259. {
  260.     GetDocument()->m_columnIdMap.Move(nFromCol, nToCol, nDestCol);
  261.  
  262.     SetModifiedFlag();
  263.  
  264.     return CMyGridView::StoreMoveCols(nFromCol, nToCol, nDestCol, bProcessed = TRUE);
  265. }
  266.