home *** CD-ROM | disk | FTP | other *** search
- // browsevw.cpp : implementation of the CDBaseBrowserView class
- //
-
- // This is a part of the Objective Grid C++ Library.
- // Copyright (C) 1995,1996 ClassWorks, Stefan Hoenig.
- // All rights reserved.
- //
- // This source code is only intended as a supplement to
- // the Objective Grid Classes Reference and related
- // electronic documentation provided with the library.
- // See these sources for detailed information regarding
- // the Objective Grid product.
- //
-
- #include "stdafx.h"
- #include "gridapp.h"
- #include "browsevw.h"
- #include <limits.h>
-
- #ifdef _DEBUG
- #undef THIS_FILE
- static char BASED_CODE THIS_FILE[] = __FILE__;
- #endif
-
- /////////////////////////////////////////////////////////////////////////////
- // CDBaseBrowserView
-
- IMPLEMENT_DYNCREATE(CDBaseBrowserView, CMyGridView)
-
- CDBaseBrowserView::CDBaseBrowserView()
- {
- }
-
- CDBaseBrowserView::~CDBaseBrowserView()
- {
- }
-
-
- BEGIN_MESSAGE_MAP(CDBaseBrowserView, CMyGridView)
- //{{AFX_MSG_MAP(CDBaseBrowserView)
- // NOTE - the ClassWizard will add and remove mapping macros here.
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
-
-
- /////////////////////////////////////////////////////////////////////////////
- // CDBaseBrowserView diagnostics
-
- #ifdef _DEBUG
- void CDBaseBrowserView::AssertValid() const
- {
- CMyGridView::AssertValid();
- }
-
- void CDBaseBrowserView::Dump(CDumpContext& dc) const
- {
- CMyGridView::Dump(dc);
- }
- #endif //_DEBUG
-
- /////////////////////////////////////////////////////////////////////////////
- // CDBaseBrowserView message handlers
-
- void CDBaseBrowserView::OnInitialUpdate()
- {
- BOOL bNew = (GetParam() == NULL);
-
- // Link grid to document,
- SetParam(&GetDocument()->m_param, FALSE /* do not destroy*/);
-
- CMyGridView::OnInitialUpdate();
-
- EnableHints(TRUE); // I have several views connected with one doc
- }
-
- // Bind gridview to DBase file
- ROWCOL CDBaseBrowserView::GetRowCount()
- {
- return GetDocument()->m_dbfile.nRecordCount;
- }
-
- ROWCOL CDBaseBrowserView::GetColCount()
- {
- return GetDocument()->m_dbfile.nFieldCount;
- }
-
- CField* CDBaseBrowserView::GetField(ROWCOL nCol)
- {
- return GetDocument()->m_dbfile.GetField(GetFieldId(nCol));
- }
-
- int CDBaseBrowserView::GetFieldId(ROWCOL nCol)
- {
- ASSERT(nCol >= 1 && nCol <= INT_MAX);
- long nField = -1;
-
- GetDocument()->m_columnIdMap.Lookup(nCol, nField);
- return (int) (nField);
- }
-
- BOOL CDBaseBrowserView::GetStyleRowCol(ROWCOL nRow, ROWCOL nCol, CGXStyle& style, GXModifyType mt, int nType)
- {
- if (mt == gxRemove) // not supported
- return FALSE;
-
- // Note: I do not distinct between gxApplyNew, gxCopy and gxOverride
-
- ASSERT(nRow <= LONG_MAX);
- long nRecord = (long) nRow;
-
- if (nType == -1)
- {
- // here you can return the style for a complete row, column or table
- return FALSE;
- }
- else if (nRow == 0 && nCol == 0)
- {
- // style for the top-left button
- return FALSE;
- }
- else if (nRow == 0)
- {
- // Column headers
- // if application was compiled with _UNICODE
- // the column name will be converted to wide chars
- style.SetValue(GetField(nCol)->name);
- }
- else if (GetDocument()->m_dbfile.Seek(nRecord-1))
- {
- if (nCol == 0)
- {
- // Row headers
- TCHAR buf[20];
- wsprintf(buf, _T("%5lu%c"), nRow, GetDocument()->m_dbfile.IsDeleted() ? _T('*') : _T(' '));
- style.SetValue(buf);
- }
- else
- {
- // Cell value
- CString s;
- CField* fld = GetField(nCol);
- GetDocument()->m_dbfile.GetValue(GetFieldId(nCol), s);
-
- style
- .SetValue(s)
- .SetMaxLength(fld->len);
-
- // Note on UNICODE/DBCS Support:
- // fld->type is a signed char even for this special modes
-
- switch (fld->type)
- {
- case 'N': style.SetBaseStyle(GetDocument()->m_wStyleNumeric); break;
- case 'C': style.SetBaseStyle(GetDocument()->m_wStyleText); break;
- case 'D': style.SetBaseStyle(GetDocument()->m_wStyleDate); break;
- case 'L': style.SetBaseStyle(GetDocument()->m_wStyleLogical); break;
- }
- }
- return TRUE;
- }
-
- // unreferenced:
- mt;
-
- return FALSE;
- }
-
- BOOL CDBaseBrowserView::StoreStyleRowCol(ROWCOL nRow, ROWCOL nCol, const CGXStyle* pStyle, GXModifyType mt, int nType)
- {
- if (mt == gxRemove) // not supported
- return FALSE;
-
- // Note: I do not distinct between gxApplyNew, gxCopy and gxOverride
-
- ASSERT(nRow <= LONG_MAX);
- long nRecord = (long) nRow;
-
- if (nType == -1)
- {
- // here you could store the style for a complete row, column or table
- return FALSE;
- }
- else if (nRow == 0 && nCol == 0)
- {
- // style for the top-left button
- return FALSE;
- }
- else if (nRow == 0)
- {
- // Column headers
- return FALSE;
- }
- else if (GetDocument()->m_dbfile.Seek(nRecord-1))
- {
- if (nCol == 0)
- {
- // Row headers
- return FALSE;
- }
- else
- {
- // Cell value
- if (pStyle->GetIncludeValue())
- GetDocument()->m_dbfile.SetValue(GetFieldId(nCol), pStyle->GetValue());
-
- SetModifiedFlag();
- return TRUE;
- }
- }
-
- // unreferenced:
- mt;
-
- return FALSE;
- }
-
- int CDBaseBrowserView::GetColWidth(ROWCOL nCol)
- {
- ASSERT(nCol <= INT_MAX);
-
- if (nCol > 0)
- {
- // GX_NXAVGWIDTH is average logical width of a char
- // Width_LPtoDP converts from logical to pixel value
- if (IsColHidden(nCol))
- return 0;
- else
- return Width_LPtoDP( (long) GetField(nCol)->display_width * GX_NXAVGWIDTH);
- }
-
- return CMyGridView::GetColWidth(nCol);
- }
-
- BOOL CDBaseBrowserView::StoreColWidth(ROWCOL nCol, int nWidth)
- {
- ASSERT(nCol <= INT_MAX);
-
- if (nCol > 0)
- {
- if (nWidth > 0)
- {
- // GX_NXAVGWIDTH is average logical width of a char
- // Width_DPtoLP converts from pixel to logical value
- GetField(nCol)->display_width = (short) (Width_DPtoLP(nWidth) / GX_NXAVGWIDTH);
- }
- else
- // reset to default column width
- GetField(nCol)->display_width = GetField(nCol)->width ;
-
- SetModifiedFlag();
-
- return TRUE;
- }
-
- return CMyGridView::StoreColWidth(nCol, nWidth);
- }
-
- BOOL CDBaseBrowserView::StoreMoveCols(ROWCOL nFromCol, ROWCOL nToCol, ROWCOL nDestCol, BOOL bProcessed)
- {
- GetDocument()->m_columnIdMap.Move(nFromCol, nToCol, nDestCol);
-
- SetModifiedFlag();
-
- return CMyGridView::StoreMoveCols(nFromCol, nToCol, nDestCol, bProcessed = TRUE);
- }
-