⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gridsvw2.cpp

📁 mfc internals 源码 mfc internals 源码
💻 CPP
字号:
// gridsvw2.cpp : implementation of the CGridSample2View 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 "gridsdoc.h"
#include "gridsvw2.h"
#include "dlguser.h"
#include "mainfrm.h"
#include "gridfrms.h"

#ifdef _DEBUG
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CGridSample2View
//
// CGridSample2View can be used as standalone, splitter or worksheet gridview
// as you have already seen with CGridSample2View
//
// CGridSample2View illustrates how to apply cell formattings
//

IMPLEMENT_DYNCREATE(CGridSample2View, CMyGridView)

static char BASED_CODE szInstruct[] =
		"This view shows some simple cell formattings. "
		"You can call Format->Cells to change the formattings for the selected range of cells.";

#define new DEBUG_NEW

BEGIN_MESSAGE_MAP(CGridSample2View, CMyGridView)
	//{{AFX_MSG_MAP(CGridSample2View)
	ON_COMMAND(ID_VIEW_USERACTIONS, OnViewUseractions)
	ON_COMMAND(ID_VIEW_SPLITTERVIEW, OnViewSplitterview)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CGridSample2View construction/destruction

CGridSample2View::CGridSample2View()
{
	// TODO: add construction code here
}

CGridSample2View::~CGridSample2View()
{
}

BOOL CGridSample2View::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;
}

/////////////////////////////////////////////////////////////////////////////
// CGridSample2View drawing

void CGridSample2View::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)

		// Number of rows and columns
		SetRowCount(100);
		SetColCount(20);

		// You can create one big cell which spans several other cells
		SetCoveredCellsRowCol(5,2, 10, 4);

		// ... and apply a big bold "times new roman" font and a border
		SetStyleRange(
			CGXRange(5,2),
			CGXStyle()
				.SetValue("Welcome!")
				.SetWrapText(FALSE)         // use single line edit control
				.SetHorizontalAlignment(DT_CENTER)
				.SetVerticalAlignment(DT_VCENTER)
				.SetInterior(CGXBrush().SetPattern(5))
				.SetDraw3dFrame(gxFrameRaised)
				// ... a big bold "times new roman" font
				.SetFont(
					CGXFont()
						.SetSize(24)
						.SetBold(TRUE)
						.SetFaceName("Times New Roman"))
				// ... and a blue border
				.SetBorders(gxBorderAll, CGXPen().SetWidth(2).SetColor(RGB(0,0,255)))
			);

		// You can apply formattings to all cells of a row or column

		// ... set rows strike-out
		SetStyleRange(
			CGXRange().SetRows(11, 15),     // Rows 9 to 13
			CGXStyle()
				.SetValue("YYY")
				.SetFont( CGXFont().SetStrikeOut(TRUE) )
			);

		// ... and columns light blue
		SetStyleRange(
			CGXRange().SetCols(5,6),        // Columns 5 to 6
			CGXStyle()
				.SetValue("XXX")
				.SetInterior(RGB(166,202,240))   // Light blue
			);

		// Take a look at the cell  11,5: It combines both the formattings
		// of the row and the columns. They are Light Blue and StrikeOut

		// Turn off StrikeOut for cells 13,5 to 13,6
		SetStyleRange(
			CGXRange().SetCells(13,5,13,6),     // equal to CGXRange(19,8,20,9)
			CGXStyle()
				.SetFont( CGXFont().SetStrikeOut(FALSE) )
			);

		// Add a selection
		POSITION area = GetParam()->GetRangeList()->AddTail(new CGXRange);
		SetSelection(area, 13, 2, 18, 5);

		// Composition of styles is a very powerful feature of Objective Grid/MFC.
		// In CGridSample3View, I will show you how to create the base styles which the
		// user can modify through the styles-dialog. (Menu: Format->Styles)

		// Instructions
		SetCoveredCellsRowCol(1, 1, 3, 5);
		SetStyleRange(CGXRange(1,1),
			CGXStyle()
				.SetWrapText(TRUE)
				.SetEnabled(FALSE)
				.SetFont(CGXFont().SetFaceName("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();
}

/////////////////////////////////////////////////////////////////////////////
// CGridSample2View diagnostics

#ifdef _DEBUG
void CGridSample2View::AssertValid() const
{
	CMyGridView::AssertValid();
}

void CGridSample2View::Dump(CDumpContext& dc) const
{
	CMyGridView::Dump(dc);
}

CGridSampleDoc* CGridSample2View::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CGridSampleDoc)));
	return (CGridSampleDoc*) m_pDocument;
}

#endif //_DEBUG


/////////////////////////////////////////////////////////////////////////////
// CGridSample2View message handlers

// Menu handler for View->Splitter View

void CGridSample2View::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;

	CGridSample2View* pView = (CGridSample2View*)
		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 CGridSample2View::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();
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -