📄 browsdoc.cpp
字号:
// browsdoc.cpp : implementation of the CDBaseBrowserDoc class
//
// This is a part of the Objective Grid C++ Library.
// Copyright (C) 1995 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 "browsdoc.h"
#ifndef _GXTWND_H_
#include "gxtwnd.h"
#endif
#ifndef _GXVW_H_
#include "gxvw.h"
#endif
#ifdef _DEBUG
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDBaseBrowserDoc
IMPLEMENT_DYNCREATE(CDBaseBrowserDoc, CDocument)
static char BASED_CODE szNumeric[] = "Numeric";
static char BASED_CODE szText[] = "Text";
static char BASED_CODE szDate[] = "Date";
static char BASED_CODE szLogical[] = "Logical";
CDBaseBrowserDoc::CDBaseBrowserDoc()
{
// Standard styles
m_stylesMap.CreateStandardStyles();
// New styles
m_wStyleNumeric = m_stylesMap.RegisterStyle(szNumeric, CGXStyle()
.SetHorizontalAlignment(DT_RIGHT)
.SetMaxLength(20));
m_wStyleText = m_stylesMap.RegisterStyle(szText, CGXStyle()
.SetHorizontalAlignment(DT_LEFT),
TRUE /* system style */);
m_wStyleDate = m_stylesMap.RegisterStyle(szDate, CGXStyle()
.SetHorizontalAlignment(DT_LEFT)
.SetMaxLength(12),
TRUE /* system style */);
m_wStyleLogical = m_stylesMap.RegisterStyle(szLogical, CGXStyle()
.SetHorizontalAlignment(DT_RIGHT)
.SetMaxLength(6),
TRUE /* system style */);
// Change default styles
// Don't allow Enter-Key to enter several lines
CGXStyle* pStyle;
m_stylesMap.LookupStyle(m_stylesMap.m_wStyleStandard, pStyle);
pStyle->SetAllowEnter(FALSE);
// if you would use AddStyle, the previous style would get deleted
m_stylesMap.ReadProfile(); // read user defined standard settings
m_param.SetStylesMap(&m_stylesMap, FALSE /* do not destroy */);
// here you could set default settings
// m_properties.SetDisplayVertLines(FALSE);
m_properties.ReadProfile(); // read user defined standard settings
m_param.SetProperties(&m_properties, FALSE /* do not destroy */);
m_param.EnableTrackRowHeight(GX_TRACK_ALL);
m_param.EnableMoveRows(FALSE);
m_param.EnableSelection(GX_SELROW | GX_SELCOL | GX_SELTABLE | GX_SELSHIFT);
// Normally, the objects are created in CGXGridCore::OnInitialUpdate.
// CGXGridCore::OnInitialUpdate checks each pointer in CGXGridParam.
// If there exists no valid pointer yet, the object is created on the heap.
// If CGXGridParam creates an object, it sets a flag that indicates
// that the object has to be destroyed when the CGXGridParam-object gets
// destroyed.
// In the above calls to SetProperties, SetStylesMap, ... the FALSE parameter
// indicates that the object must not be destroyed by the CGXGridParam-object.
// See CDBaseBrowserView::OnInitialUpdate for linking the parameter-object
// to the gridview.
}
BOOL CDBaseBrowserDoc::OnNewDocument()
{
if (!CDocument::OnNewDocument())
return FALSE;
// Ask for Dbase-File
CFileDialog dlg(TRUE, "dsf", NULL,
0 /* OFN_HIDEREADONLY */, "DBase-Files (*.dbf) | *.dbf ||");
if (dlg.DoModal() != IDOK)
return FALSE;
BOOL b = m_dbfile.Open(dlg.GetPathName(), dlg.GetReadOnlyPref());
if (b)
{
for (int i = 1; i <= m_dbfile.nFieldCount; i++)
m_columnIdMap[i] = i-1;
}
SetModifiedFlag();
// initialize header
{
CGXData& header = m_properties.GetDataHeader();
header.DeleteContents();
header.StoreRowCount(10);
header.StoreColCount(3);
header.StoreStyleRowCol(1, 2, CGXStyle()
.SetValue("GridApp DBase Browser")
.SetFont(CGXFont().SetBold(TRUE).SetSize(12)),
gxOverride);
header.StoreStyleRowCol(2, 2, CGXStyle()
.SetValue(dlg.GetFileName())
.SetFont(CGXFont().SetBold(TRUE).SetSize(16)),
gxOverride);
}
return b;
}
CDBaseBrowserDoc::~CDBaseBrowserDoc()
{
}
BEGIN_MESSAGE_MAP(CDBaseBrowserDoc, CDocument)
//{{AFX_MSG_MAP(CDBaseBrowserDoc)
// NOTE - the ClassWizard will add and remove mapping macros here.
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDBaseBrowserDoc diagnostics
#ifdef _DEBUG
void CDBaseBrowserDoc::AssertValid() const
{
CDocument::AssertValid();
}
void CDBaseBrowserDoc::Dump(CDumpContext& dc) const
{
CDocument::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CDBaseBrowserDoc serialization
void CDBaseBrowserDoc::Serialize(CArchive& ar)
{
static const WORD wVersion = 1;
WORD wActualVersion = wVersion;
ASSERT_VALID( this );
if (ar.IsStoring())
{
ar << wVersion;
}
else
{
// Check for version first
ar >> wActualVersion;
if( wActualVersion != wVersion )
{
// Wrong version
#ifdef _DEBUG
TRACE0( "Imcompatible format while reading " );
CObject::Dump(afxDump);
TRACE2("in %s at line %d\n", __FILE__, __LINE__);
#endif
AfxThrowArchiveException(CArchiveException::badSchema);
return;
}
}
if (ar.IsStoring())
{
ar << m_dbfile.sFileName;
ar << (BYTE) m_dbfile.bReadOnly;
m_columnIdMap.Serialize(ar);
m_param.Serialize(ar);
// Column widths
for (int i = 0; i < m_dbfile.nFieldCount; i++)
ar << (WORD) m_dbfile.GetField(i)->width;
}
else
{
BYTE bReadOnly;
CString sFileName;
ar >> sFileName;
ar >> bReadOnly;
m_dbfile.Open(sFileName, (BOOL) bReadOnly);
m_columnIdMap.Serialize(ar);
m_param.Serialize(ar);
// Column widths
WORD w;
for (int i = 0; i < m_dbfile.nFieldCount; i++)
ar >> w, m_dbfile.GetField(i)->width = (short) w;
}
}
/////////////////////////////////////////////////////////////////////////////
// CDBaseBrowserDoc commands
BOOL CDBaseBrowserDoc::OnSaveDocument(LPCTSTR pszPathName)
{
// TRACE1("CDocument: OnSaveDocument(%s)\n", pszPathName);
// Ensure that each views current cell is stored
CGXGridHint hint(gxHintTransferCurrentCell);
hint.lParam = TRUE;
UpdateAllViews(NULL, 0, &hint);
// Now, I can save the document
if (!CDocument::OnSaveDocument(pszPathName))
return FALSE;
SetModifiedFlag(FALSE);
return TRUE;
}
BOOL CDBaseBrowserDoc::CanCloseFrame(CFrameWnd* pFrame)
{
// Ensure that views can be deactivated
CView* pView = pFrame->GetActiveView();
if (pView && pView->SendMessage(WM_GX_CANACTIVATE, 0, 0))
return FALSE;
// Ensure that the current cell is stored
if (pView->IsKindOf(RUNTIME_CLASS(CGXGridView))
&& !((CGXGridView*) pView)->TransferCurrentCell())
return FALSE;
// Now, I can close the view
return CDocument::CanCloseFrame(pFrame);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -