home *** CD-ROM | disk | FTP | other *** search
- // gridsvw.cpp : implementation of the CGridSampleView 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 "gridsvw.h"
- #include "dlguser.h"
- #include "mainfrm.h"
- #include "gridfrms.h"
-
- #ifdef _DEBUG
- #undef THIS_FILE
- static char BASED_CODE THIS_FILE[] = __FILE__;
- #endif
-
- /////////////////////////////////////////////////////////////////////////////
- // CGridSampleView
- //
- // CGridSampleView can be used as standalone, splitter or worksheet gridview.
- //
- // As described in the overview of the programmers guide,
- // it is necessary to attach a parameter-object to the grid
- // and attach several other objects as a property-object, a data-object,
- // a printdevice-object and stylesmap-object to the parameter-object.
- //
- // CGridSampleDoc maintains an array with parameter objects.
- // CGridSampleView initializes m_nViewID with its worksheet id
- // or 0 if it is used as standalone view.
- // m_nViewID is used as index for the parameters stored in CGridSampleDoc.
- //
- // CGridSampleView checks if parameter-object exists for the m_nViewID index
- // and connects this parameter-object with the gridview. If the parameter
- // object is not existing, one is created on the heap.
- //
- // Next, CGridSampleView calls OnInitialUpdate to initialize all other objects.
- // When the view is closed, all these objects will be destroyed.
- //
- // CGridSampleView enables hint creation by calling EnableHints().
- // To avoid setting the document dirty when initial commands are executed,
- // EnableHints() is called as last command in OnInitialUpdate.
- //
- // To prevent the user undoing the initial commands, OnInitialUpdate calls
- // GetParam()->EnableUndo(FALSE) and after executing inital commands
- // GetParam()->EnableUndo(TRUE).
-
- // CGridSampleView also illustrates how to apply cell some simple formattings.
- //
-
- static TCHAR BASED_CODE szInstruct[] =
- _T("This is a simple gridview. You can move the current cell, ")
- _T("edit the cell contents, zoom the view, change the printers settings, ")
- _T("and ...");
-
- IMPLEMENT_DYNCREATE(CGridSampleView, CMyGridView)
-
- #define new DEBUG_NEW
-
- BEGIN_MESSAGE_MAP(CGridSampleView, CMyGridView)
- //{{AFX_MSG_MAP(CGridSampleView)
- ON_COMMAND(ID_VIEW_USERACTIONS, OnViewUseractions)
- ON_COMMAND(ID_VIEW_SPLITTERVIEW, OnViewSplitterview)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
-
- /////////////////////////////////////////////////////////////////////////////
- // CGridSampleView construction/destruction
-
- CGridSampleView::CGridSampleView()
- {
- }
-
- CGridSampleView::~CGridSampleView()
- {
- }
-
- BOOL CGridSampleView::ConnectParam()
- {
- 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 CGridSampleView::OnInitialUpdate()
- {
- BOOL bNew = ConnectParam();
-
- CMyGridView::OnInitialUpdate(); // Creates all objects and links them to the grid
-
- // Now, all objects are connected:
- ASSERT(GetParam() != NULL); // parameter object
- ASSERT(GetParam()->GetProperties() != NULL); // properties object (with header-/footer, colors,...)
- ASSERT(GetParam()->GetStylesMap() != NULL); // stylesmap object (with base styles)
- ASSERT(GetParam()->GetData() != NULL); // data object (with cell's data)
- ASSERT(GetParam()->GetPrintDevice() != NULL); // printdevice object (with printer settings)
-
- // ... and you can execute commands on the grid
-
- if (bNew)
- {
- // Don't create undo-information for the following commands
- GetParam()->EnableUndo(FALSE);
- // (at the end of this procedure, I will reenable it)
-
- // Change default background color
- // StandardStyle() returns a reference to the "Standard-Style".
- // All cells in the grid inherit their attributes from this Standard-Style
- // The user can change the Standard-Style with menu Format|Styles.
-
- StandardStyle()
- .SetInterior(RGB(255,255,255));
-
- // Turn off row-numbers
- // RowHeaderStyle() returns a reference to the "Row Header-Style".
- RowHeaderStyle()
- .SetValue(_T(""));
-
- // Number of rows and columns
- SetRowCount(100);
- SetColCount(20);
-
- // Apply some formattings to the cells
- SetValueRange(CGXRange(5,1), _T("Hello"));
-
- // You can call SetStyleRange several times on the same cell
- SetValueRange(CGXRange(6,1), _T("world!"));
- // you could also call:
- // SetStyleRange(CGXRange(6,1), CGXStyle().SetValue(_T("world!")));
-
- // .. right alignment is added to the cell's formatting
- SetStyleRange(CGXRange(6,1), CGXStyle().SetHorizontalAlignment(DT_RIGHT));
-
- // ... or you can call SetStyleRange with several attributes.
- SetStyleRange(
- CGXRange(8,2,12,3),
- CGXStyle()
- .SetValue(_T("ABC"))
- .SetTextColor(RGB(255,255,0)) // Bright Yellow
- .SetDraw3dFrame(gxFrameInset) // "inset" 3d-effect
- .SetInterior(
- CGXBrush()
- .SetPattern(14) // "////" - Pattern, red lines, blue background
- .SetColor(RGB(255,0,0))
- .SetBkColor(RGB(0,0,255)) )
- .SetMaxLength(4) // Limit input to 4 chars
- .SetBorders(gxBorderAll,
- CGXPen()
- .SetColor(RGB(192,192,192)) ) // grey border
- .SetHorizontalAlignment(DT_CENTER));
-
- // Automatically adapt row heights to the previous block of cell
- ResizeRowHeightsToFit( CGXRange(8,2,12,3) );
-
- // apply a style to rows
- SetStyleRange(CGXRange().SetRows(7, 13),
- CGXStyle()
- .SetAutoSize(TRUE) // automatically resize cells when user enters text
- .SetInterior(RGB(192,192,192)) // grey background
- );
-
- // Instructions
- SetCoveredCellsRowCol(1, 1, 3, 5);
- SetStyleRange(CGXRange(1, 1),
- CGXStyle()
- .SetWrapText(TRUE) // wrap text
- .SetEnabled(FALSE) // inhibit usage as current cell
- .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) // Static Text
- .SetBorders(gxBorderAll,
- CGXPen()
- .SetWidth(2)) // black border, 2-pixels thick
- .SetValue(szInstruct));
-
- // Enable ceration of undo-information for user interactions
- GetParam()->EnableUndo(TRUE);
-
- // Draw border in current cell
- CGXProperties* pProp = GetParam()->GetProperties();
- pProp->SetUserProperty(GX_IDS_OUTLINECURRENTCELL,
- (CGXStyle)(pProp->sInvertDrawBorder)); // need cast to compile
- }
-
- // Position the current cell
-
- SetCurrentCell(4, 1, FALSE /* avoid immediate updating */);
-
- // Enable Update-Hint-Mechanism
- // You should put this line as last command into OnInitialUpdate,
- // becaus as long as EnableHints is not called, the modified flag
- // of the document will not be changed.
-
- EnableHints();
- }
-
- /////////////////////////////////////////////////////////////////////////////
- // CGridSampleView diagnostics
-
- #ifdef _DEBUG
- void CGridSampleView::AssertValid() const
- {
- CMyGridView::AssertValid();
- }
-
- void CGridSampleView::Dump(CDumpContext& dc) const
- {
- CMyGridView::Dump(dc);
- }
-
- CGridSampleDoc* CGridSampleView::GetDocument() // non-debug version is inline
- {
- ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CGridSampleDoc)));
- return (CGridSampleDoc*) m_pDocument;
- }
-
- #endif //_DEBUG
-
-
- /////////////////////////////////////////////////////////////////////////////
- // CGridSampleView message handlers
-
- // Menu handler for View->Splitter View
-
- void CGridSampleView::OnViewSplitterview()
- {
- // Creates a new CSplitterMDIChildWnd frame with a CGridSampleView
- // and initializes it with the same view id.
-
- 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;
-
- CGridSampleView* pView = (CGridSampleView*)
- 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 CGridSampleView::OnViewUseractions()
- {
- /*
- // just some performance checking
-
- ((CMDIChildWnd*) GetParentFrame())->MDIMaximize();
-
- OnViewZoomin();
- OnViewZoomin();
- OnViewZoomin();
-
- OnViewZoomout();
- OnViewZoomout();
- OnViewZoomout();
- OnViewZoomout();
- OnViewZoomout();
-
- OnViewZoomin();
- OnViewZoomin();
- OnViewZoomin();
- OnViewZoomin();
- OnViewZoomin();
-
- OnViewZoomout();
- OnViewZoomout();
- OnViewZoomout();
-
- ProcessKeys(this, WM_CHAR, 20, 1, 0);
- return;
- */
-
- // 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();
- }
- }
-
-