home *** CD-ROM | disk | FTP | other *** search
- // gridsvw3.cpp : implementation of the CGridSample3View 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 "gridsvw3.h"
- #include "dlguser.h"
- #include "mainfrm.h"
- #include "gridfrms.h"
-
- #ifdef _DEBUG
- #undef THIS_FILE
- static char BASED_CODE THIS_FILE[] = __FILE__;
- #endif
-
- /////////////////////////////////////////////////////////////////////////////
- // CGridSample3View
- //
- // Composition of styles is a very powerful feature of Objective Grid/MFC.
- // CGridSample3View shows you how to create and modify base styles which the
- // user can modify through the styles-dialog. (Menu: Format->Styles)
- // and change some properties, parameters
- //
- // CGridSample3View also shows you how to inhibit dragging columns
- // depending on context (e.g. not to move unfrozen columns to frozen colums).
- // See OnSelDragColsStart and OnSelDragColsMove.
- //
- // Finally, CGridSample3View illustrates how to freeze rows or columns,
- // use several rows or columns for headers and the possibility to use
- // SetCoveredCellsRowCol with Column headers.
- //
-
- IMPLEMENT_DYNCREATE(CGridSample3View, CMyGridView)
-
- static TCHAR BASED_CODE szErrorStyle[] = _T("Error Style");
- static TCHAR BASED_CODE szComboStyle[] = _T("Combo Style");
-
- static TCHAR BASED_CODE szInstruct[] =
- _T("This view shows the usage of base styles and the possibility to use ")
- _T("several rows or columns as headers and to freeze columns. ")
- _T("You can call Format->Styles to add or modify base styles.");
-
-
- #define new DEBUG_NEW
-
- BEGIN_MESSAGE_MAP(CGridSample3View, CMyGridView)
- //{{AFX_MSG_MAP(CGridSample3View)
- ON_COMMAND(ID_VIEW_USERACTIONS, OnViewUseractions)
- ON_COMMAND(ID_VIEW_SPLITTERVIEW, OnViewSplitterview)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
-
- /////////////////////////////////////////////////////////////////////////////
- // CGridSample3View construction/destruction
-
- CGridSample3View::CGridSample3View()
- {
- // TODO: add construction code here
- }
-
- CGridSample3View::~CGridSample3View()
- {
- }
-
- BOOL CGridSample3View::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 CGridSample3View::SetupBaseStyles()
- {
- ASSERT(GetParam()->GetStylesMap() == NULL);
- // ASSERTION-> a stylesmap is already connected to parameter-object ->END
-
- if (GetParam()->GetStylesMap() != NULL)
- return;
-
- // create a stylesmap and connect it with the parameter-object
- CGXStylesMap* pStyMap;
-
- GetParam()->SetStylesMap(pStyMap = new CGXStylesMap);
-
- // create standard styles
- pStyMap->CreateStandardStyles();
-
- // Add some base styles
-
- // "Combo Style" - A style with a combo box and choice list
- pStyMap->RegisterStyle(szComboStyle,
- CGXStyle()
- .SetControl(GX_IDS_CTRL_CBS_DROPDOWNLIST)
- .SetChoiceList(_T("one\r\ntwo\r\nthree\r\nfour\r\nfive\r\nsix\r\n")),
- TRUE // system-style (non removable)
- );
-
- // "Error Style" - Yellow text on red backcolor with a bold font
- pStyMap->RegisterStyle(szErrorStyle,
- CGXStyle()
- .SetTextColor(RGB(255,255,0)) // yellow
- .SetInterior(RGB(255,0,0)) // red
- .SetFont(
- CGXFont()
- .SetBold(TRUE)
- ),
- TRUE // system-style (non removable)
- );
-
- // I do also want to adapt the base styles:
-
- // StandardStyle() calls pStyMap->LookupStyle(pStyMap->m_wStyleStandard, ...)
- // and returns a reference to the Standard-Style.
- //
- // So, I can simply adapt this style's settings to my needs.
-
- StandardStyle()
- .SetFont( CGXFont()
- .SetFaceName(_T("Times New Roman"))
- .SetSize(9) );
-
- RowHeaderStyle()
- .SetTextColor(RGB(0,0,255) );
-
- // Now, read the styles from profile.
- // Note that reading style from profile can override the previous settings.
- // The previous settings are standard settings.
-
- pStyMap->SetSection(_T("My Base Styles")); // extra profile section
-
- pStyMap->ReadProfile();
- }
-
-
- /////////////////////////////////////////////////////////////////////////////
- // CGridSample3View drawing
-
- void CGridSample3View::OnInitialUpdate()
- {
- BOOL bNew = ConnectParam();
-
- if (bNew)
- SetupBaseStyles(); // Setup base styles and read them from profile
-
- CMyGridView::OnInitialUpdate(); // Creates all objects and links them to the grid
-
- // check out identifiers for the styles previously registered with RegisterStyle
- m_wStyleCombo = GetParam()->GetStylesMap()->GetBaseStyleId(szComboStyle);
- m_wStyleError = GetParam()->GetStylesMap()->GetBaseStyleId(szErrorStyle);
-
- // you could use these identifiers later if you want to change the style
- // e.g.
- // BaseStyle(m_wStyleCombo)
- // .SetChoiceList(_T("one\ntwo\nthree"));
- //
- // where BaseStyle(id) is a member function of CGXGridCore which returns a
- // reference to the specified base-style.
- //
- // You need this identifier if you want to apply this base-style to cells
- // e.g.
- // SetStyleRange(
- // CGXRange(5,2,8,3),
- // CGXStyle()
- // .SetBaseStyle(m_wStyleCombo)
- // );
-
- if (bNew)
- {
- // Don't create undo-information for the following commands
- GetParam()->EnableUndo(FALSE);
- // (at the end of this procedure, I will reenable it)
-
- // Number of rows and columns
- SetRowCount(100);
- SetColCount(20);
-
- // Now you can apply base styles to cells
-
- SetStyleRange(
- CGXRange(5,2,8,3),
- CGXStyle()
- .SetBaseStyle(m_wStyleCombo)
- .SetValue(_T("one"))
- );
-
- // Optimize row heights
- ResizeRowHeightsToFit(CGXRange(5,2,8,2));
-
- SetStyleRange(
- CGXRange(5,4,8,5),
- CGXStyle()
- .SetBaseStyle(m_wStyleError)
- .SetValue(_T("ALERT!"))
- );
-
- // ... and row
- SetStyleRange(
- CGXRange().SetRows(10,11), // Rows 10 to 11
- CGXStyle()
- .SetValue(szErrorStyle)
- .SetBaseStyle(m_wStyleError)
- );
-
- // 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));
-
- // freeze 3 columns, use 1 extra row as header ( + standard header at column 0)
- SetFrozenCols(3, 1);
-
- // freeze 3 rows, use 3 extra columns as headers ( + standard header at row 0)
- SetFrozenRows(3, 3);
-
- // Do not draw column headers pressed when moving the current cell
- GetParam()->GetProperties()->SetMarkColHeader(FALSE);
-
- // Use covered cells even with row headers
- SetCoveredCellsRowCol(5,0,7,0);
-
- SetStyleRange(CGXRange(5,0), _T("Covered Header"));
-
- // Enable ceration of undo-information for user interactions
- GetParam()->EnableUndo(TRUE);
- }
-
- // Position the current cell
-
- SetCurrentCell(4, 2, FALSE /* avoid immediate updating */);
-
- // Enable Update-Hint-Mechanism
-
- EnableHints();
- }
-
- // Inhibit dragging frozen columns.
-
- BOOL CGridSample3View::OnSelDragColsStart(ROWCOL nFirstCol, ROWCOL)
- {
- return nFirstCol > GetFrozenCols();
-
- }
-
- // Inhibit dragging columns to nonfrozen columns.
- // The grid will display a "no drop"-cursor if OnSelDragColsMove returns FALSE.
-
- BOOL CGridSample3View::OnSelDragColsMove(ROWCOL, ROWCOL, ROWCOL nDestCol)
- {
- return nDestCol > GetFrozenCols();
- }
-
- /////////////////////////////////////////////////////////////////////////////
- // CGridSample3View diagnostics
-
- #ifdef _DEBUG
- void CGridSample3View::AssertValid() const
- {
- CMyGridView::AssertValid();
- }
-
- void CGridSample3View::Dump(CDumpContext& dc) const
- {
- CMyGridView::Dump(dc);
- }
-
- CGridSampleDoc* CGridSample3View::GetDocument() // non-debug version is inline
- {
- ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CGridSampleDoc)));
- return (CGridSampleDoc*) m_pDocument;
- }
-
- #endif //_DEBUG
-
-
- /////////////////////////////////////////////////////////////////////////////
- // CGridSample3View message handlers
-
- // Menu handler for View->Splitter View
-
- void CGridSample3View::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;
-
- CGridSample3View* pView = (CGridSample3View*)
- 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 CGridSample3View::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();
- }
- }
-