home *** CD-ROM | disk | FTP | other *** search
-
- // gridsvw4.cpp : implementation of the CGridSample4View 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 "gridsdoc.h"
- #include "gridsvw4.h"
- #include "dlguser.h"
- #include "mainfrm.h"
- #include "gridfrms.h"
-
- #ifdef _DEBUG
- #undef THIS_FILE
- static char BASED_CODE THIS_FILE[] = __FILE__;
- #endif
-
- /////////////////////////////////////////////////////////////////////////////
- // CGridSample4View
- //
- // CGridSample4View illustrates how to override CGXPrintProperties,
- // use own tokens for header and footers and connect the derived
- // properties object with the grid.
- //
- // CGridSample4View also illustrates how to register a bitmap control
- // and display it in a covered cell
- //
-
- IMPLEMENT_DYNCREATE(CGridSample4View, CMyGridView)
- IMPLEMENT_SERIAL(CMyProperties, CGXProperties, 0)
-
- static TCHAR BASED_CODE szInstruct[] =
- _T("This view shows a bitmap, some 3d-effects and has registered some header/footer tokens. ")
- _T("Call File->Header/Footer and File->Print Preview to see the tokens. ")
- _T("The bitmap can be applied to cells with Format->Cells->Control.");
-
- #define new DEBUG_NEW
-
- CMyProperties::CMyProperties()
- {
- m_nTokDate = AddToken(_T("#DATE#"));
- m_nTokText = AddToken(_T("$T"));
-
- CGXData& mapDataHeader = GetDataHeader();
- CGXData& mapDataFooter = GetDataFooter();
-
- mapDataHeader.DeleteContents();
-
- mapDataHeader.StoreStyleRowCol(1, 2, CGXStyle()
- .SetValue(_T("Header"))
- .SetFont(CGXFont().SetSize(10))
- , gxCopy
- );
-
- mapDataHeader.StoreStyleRowCol(2, 2, CGXStyle()
- .SetValue(_T("$R"))
- .SetFont(CGXFont()
- .SetBold(TRUE)
- .SetSize(16))
- , gxCopy
- );
-
- mapDataHeader.StoreStyleRowCol(2, 3, CGXStyle()
- .SetValue(_T("Datum: #DATE#{%x, %X}")) // see GXIntlStrFTime for date formatting
- .SetFont(CGXFont().SetSize(10))
- , gxCopy
- );
-
-
- mapDataFooter.DeleteContents();
-
- mapDataFooter.StoreStyleRowCol(1, 2, CGXStyle()
- .SetValue(_T("Footer"))
- .SetFont(CGXFont().SetSize(10).SetBold(TRUE))
- , gxCopy
- );
- mapDataFooter.StoreStyleRowCol(2, 2, CGXStyle()
- .SetValue(_T("- $T -"))
- , gxCopy
- );
- }
-
- CString CMyProperties::SubstTokenText(int nToken, CString& sRest)
- {
- if (nToken == m_nTokDate)
- {
- CString args = GetTokenArgs(sRest);
- if (args.IsEmpty())
- args = _T("%c");
-
- TCHAR szBuffer[255];
-
- // GetCurrentTime
- time_t ti = time(NULL);
- struct tm* ptmTemp = localtime(&ti);
- ASSERT(ptmTemp != NULL); // make sure the time has been initialized!
-
- if (!GXIntlStrFtime(AfxGetResourceHandle(), GX_IDS_TIME_ADAY1,
- szBuffer, sizeof(szBuffer) / sizeof(TCHAR), args, ptmTemp))
- szBuffer[0] = _T('\0');
- return szBuffer;
- }
- else if (nToken == m_nTokText)
- {
- return _T("Text-Token");
- }
-
- return CGXProperties::SubstTokenText(nToken, sRest);
- }
-
- BEGIN_MESSAGE_MAP(CGridSample4View, CMyGridView)
- //{{AFX_MSG_MAP(CGridSample4View)
- ON_COMMAND(ID_VIEW_USERACTIONS, OnViewUseractions)
- ON_COMMAND(ID_VIEW_SPLITTERVIEW, OnViewSplitterview)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
-
- /////////////////////////////////////////////////////////////////////////////
- // CGridSample4View construction/destruction
-
- CGridSample4View::CGridSample4View()
- {
- // TODO: add construction code here
- }
-
- CGridSample4View::~CGridSample4View()
- {
- }
-
- BOOL CGridSample4View::ConnectParam()
- {
- // Note: this method is copied from CGridSampleView
- //
-
- BOOL bNew = FALSE;
-
- // Retrive the zero-based worksheet-id if used as worksheet
- if (GetParentTabWnd(this, TRUE))
- m_nViewID = GetParentTabViewID(this);
-
- // check if it is a new pane in a splitter window
- CSplitterWnd* pSplitterWnd = GetParentDynamicSplitter(this, TRUE);
- if (pSplitterWnd != NULL)
- {
- CGXGridView *pView = (CGXGridView *) pSplitterWnd->GetPane(0, 0);
- if (pView != this)
- m_nViewID = pView->GetViewID();
- }
-
- // check if parameter-object exist (in document)
- if (GetDocument()->GetParam(m_nViewID) == NULL)
- {
- // create a parameter-object on the heap
- GetDocument()->SetParam(m_nViewID, new CGXGridParam);
-
- bNew = TRUE; // this view needs initializing
- }
-
- // connect parameter-object with grid
- SetParam((CGXGridParam*) GetDocument()->GetParam(m_nViewID), FALSE);
-
- return bNew;
- }
-
- void CGridSample4View::SetupProperties()
- {
- ASSERT(GetParam()->GetProperties() == NULL);
- // ASSERTION-> a property object is already connected to parameter-object ->END
-
- if (GetParam()->GetProperties() != NULL)
- return;
-
- // create a property object and connect it with the parameter-object
- CMyProperties* pProp;
-
- GetParam()->SetProperties(pProp = new CMyProperties);
- pProp->AddDefaultUserProperties();
-
- pProp->SetCenterHorizontal(TRUE);
- pProp->SetDisplayHorzLines(FALSE);
- pProp->SetPrintHorzLines(FALSE);
- pProp->SetDisplayVertLines(FALSE);
- pProp->SetPrintVertLines(FALSE);
- pProp->SetBlackWhite(TRUE);
- pProp->SetPrintFrame(FALSE);
-
- // Now, read the properties from profile.
- // Note that reading properties from profile can override the previous settings.
- // The previous settings are standard settings.
-
- pProp->SetSection(_T("My Properties")); // extra profile section
-
- pProp->ReadProfile();
- }
-
-
- /////////////////////////////////////////////////////////////////////////////
- // CGridSample4View drawing
-
- void CGridSample4View::OnInitialUpdate()
- {
- BOOL bNew = ConnectParam();
-
- if (bNew)
- SetupProperties(); // Setup base styles and read them from profile
-
- CMyGridView::OnInitialUpdate(); // Creates all objects and links them to the grid
-
- // Register the welcome bitmap
- // Use CGXDIBitmapButton instead of CGXBitmapButton
- RegisterControl(IDS_CTRL_BITMAP, new CGXDIBitmapButton(this, IDB_WELCOME));
- // You can apply this bitmap to cells with Format->Cells->Control
-
- if (bNew)
- {
- GetParam()->EnableUndo(FALSE);
-
- SetRowCount(100);
- SetColCount(20);
-
- // Hide the row header
- SetRowHeight(0, 0, 0);
-
- // Hide the column header
- SetColWidth(0, 0, 0);
-
- // Disable tracking column header size
- GetParam()->EnableTrackRowHeight(GX_TRACK_INDIVIDUAL | GX_TRACK_EXTHITTEST | GX_TRACK_NOTHEADER);
- // you can drop GX_TRACK_EXTHITTEST if you don't want the extended size feature
-
- GetParam()->EnableTrackColWidth(GX_TRACK_INDIVIDUAL | GX_TRACK_EXTHITTEST | GX_TRACK_NOTHEADER);
-
- // disable selecting cells
- GetParam()->EnableSelection(GX_SELNONE);
-
- // give the cells some 3d inset effect and a pattern
- StandardStyle()
- .SetDraw3dFrame(gxFrameInset)
- .SetInterior(
- CGXBrush()
- .SetPattern(4)
- .SetColor(RGB(0,0,255)) ) // blue dots
- .SetBorders(gxBorderAll, CGXPen(PS_SOLID, 3, RGB(192,192,192)));
-
- // ... add the extra width used by borders to the default row-height
- SetDefaultRowHeight(GetDefaultRowHeight()+6);
-
- // Display the welcome bitmap
- SetCoveredCellsRowCol(5, 2, 16, 6);
- SetStyleRange(CGXRange(5, 2), CGXStyle()
- .SetControl(IDS_CTRL_BITMAP)
- .SetInterior(RGB(192,192,192))
- );
-
- // Instructions
- SetCoveredCellsRowCol(1, 1, 3, 5);
- SetStyleRange(CGXRange(1, 1),
- CGXStyle()
- .SetWrapText(TRUE)
- .SetEnabled(FALSE)
- .SetFont(CGXFont().SetFaceName(_T("Times New Roman")))
- .SetInterior(RGB(255,251,240)) // Off-white
- .SetHorizontalAlignment(DT_CENTER)
- .SetVerticalAlignment(DT_VCENTER)
- .SetControl(GX_IDS_CTRL_STATIC)
- .SetBorders(gxBorderAll, CGXPen().SetWidth(2))
- .SetValue(szInstruct));
-
- // Enable ceration of undo-information for user interactions
- GetParam()->EnableUndo(TRUE);
- }
-
- // Position the current cell
-
- SetCurrentCell(4, 1, FALSE /* avoid immediate updating */);
-
- // Enable Update-Hint-Mechanism
-
- EnableHints();
- }
-
- /////////////////////////////////////////////////////////////////////////////
- // CGridSample4View diagnostics
-
- #ifdef _DEBUG
- void CGridSample4View::AssertValid() const
- {
- CMyGridView::AssertValid();
- }
-
- void CGridSample4View::Dump(CDumpContext& dc) const
- {
- CMyGridView::Dump(dc);
- }
-
- CGridSampleDoc* CGridSample4View::GetDocument() // non-debug version is inline
- {
- ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CGridSampleDoc)));
- return (CGridSampleDoc*) m_pDocument;
- }
-
- #endif //_DEBUG
-
-
- /////////////////////////////////////////////////////////////////////////////
- // CGridSample4View message handlers
-
- // Menu handler for View->Splitter View
-
- void CGridSample4View::OnViewSplitterview()
- {
- CDocument* pDoc = GetDocument();
-
- CMyMultiDocTemplate* pTemplate
- = (CMyMultiDocTemplate*) ((CGridSampleApp*) AfxGetApp())->m_pSplitterTemplate;
-
- pTemplate->SetViewClass(GetRuntimeClass());
-
- CMDIChildWnd* pNewFrame
- = (CMDIChildWnd*) pTemplate->CreateNewFrame(GetDocument(), NULL);
-
- if (pNewFrame == NULL)
- return; // not created
-
- ASSERT(pNewFrame->IsKindOf(RUNTIME_CLASS(CSplitterMDIChildWnd)));
-
- CSplitterWnd& splitter = (CSplitterWnd&)
- ((CSplitterMDIChildWnd *) pNewFrame)->m_wndSplitter;
-
- CGridSample4View* pView = (CGridSample4View*)
- splitter.GetPane(0, 0);
-
- // Set view id to active tab view id
- pView->m_nViewID = m_nViewID;
-
- pTemplate->InitialUpdateFrame(pNewFrame, pDoc);
-
- pNewFrame->GetActiveView();
- ASSERT(pView);
- }
-
- // Menu handler for View->User Actions...
-
- void CGridSample4View::OnViewUseractions()
- {
- // Note: this method is copied from CGridSampleView
- //
- // Shows a dialog with some attributes of the parameter-object
- // where you can experiment with some attributes
- // such as allowing the user to track columns, select cells
- // or use the grid as a listbox.
-
- // Transfer Current Cell's Data to grid
- if (!TransferCurrentCell())
- return;
-
- CUserActionsDialog dlg(GetParam());
-
- if (dlg.DoModal() == IDOK)
- {
- // Redraw the grid
- Redraw();
- }
- }
-