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

📄 mygridvw.cpp

📁 mfc internals 源码 mfc internals 源码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
		RemoveCols(range.left, range.right);
	}
}

void CMyGridView::OnEditRemoverows()
{
	CGXRangeList* pSelList = GetParam()->GetRangeList();
	if (pSelList->IsAnyCellFromCol(0) && pSelList->GetCount() == 1)
	{
		CGXRange range = pSelList->GetHead();
		range.ExpandRange(1, 0, GetRowCount(), 0);
		RemoveRows(range.top, range.bottom);
	}
}

void CMyGridView::OnUpdateEditRemovecols(CCmdUI* pCmdUI)
{
	if (GetParam() == NULL)
	{
		pCmdUI->Enable(FALSE);
		return;
	}

	CGXRangeList* pSelList = GetParam()->GetRangeList();
	pCmdUI->Enable(pSelList->IsAnyCellFromRow(0) && pSelList->GetCount() == 1);
}

void CMyGridView::OnUpdateEditRemoverows(CCmdUI* pCmdUI)
{
	if (GetParam() == NULL)
	{
		pCmdUI->Enable(FALSE);
		return;
	}

	CGXRangeList* pSelList = GetParam()->GetRangeList();
	pCmdUI->Enable(pSelList->IsAnyCellFromCol(0) && pSelList->GetCount() == 1);
}

/////////////////////////////////////////////////////////////////////////////
// View menu handlers

void CMyGridView::OnViewProperties()
{
	BOOL bSaveDefault = FALSE;

	CGXProperties* pPropertyObj = GetParam()->GetProperties();
	ASSERT(pPropertyObj->IsKindOf(RUNTIME_CLASS(CGXProperties)));

	CGXProperties* pNewSettings = new CGXProperties;
	*pNewSettings = *pPropertyObj;

	CGXDisplayPropertiesDialog dlg(pNewSettings, GetParam()->GetStylesMap(), &bSaveDefault, FALSE);

	int result = dlg.DoModal();
	if (result == IDOK)
	{
		*pPropertyObj = *pNewSettings;
		if (bSaveDefault)
			pPropertyObj->WriteProfile();

		SetModifiedFlag();
		Redraw();
	}

	delete pNewSettings;
}

void CMyGridView::OnView100()
{
	SetZoom(100);
}

void CMyGridView::OnViewZoomin()
{
	if (GetZoom() < 300)
		SetZoom(GetZoom()*11/10);
}

void CMyGridView::OnViewZoomout()
{
	if (GetZoom() > 40)
		SetZoom(GetZoom()*10/11);
}

void CMyGridView::OnUpdateViewZoomin(CCmdUI* pCmdUI)
{
	pCmdUI->Enable(GetParam() && GetZoom() < 300);
}

void CMyGridView::OnUpdateViewZoomout(CCmdUI* pCmdUI)
{
	pCmdUI->Enable(GetParam() && GetZoom() > 40);
}

void CMyGridView::OnViewReadonly()
{
	SetReadOnly(!IsReadOnly());
}

void CMyGridView::OnUpdateViewReadonly(CCmdUI* pCmdUI)
{
	pCmdUI->SetCheck(GetParam() && IsReadOnly());
}

/////////////////////////////////////////////////////////////////////////////
// Format menu handlers

void CMyGridView::OnFormatCells()
{
	// if there are no cells selected,
	// copy the current cell's coordinates
	CGXRangeList selList;
	if (!CopyRangeList(selList, TRUE))
		return;

	ROWCOL nRow = selList.GetHead()->top;
	ROWCOL nCol = selList.GetHead()->left;

	CGXStyle* pStyle = CreateStyle();
	ComposeStyleRowCol(max(nRow, 1), max(nCol, 1), pStyle);

	CGXStyleSheet sheet("Cells", *GetParam()->GetStylesMap());

	sheet.CreatePages();
	sheet.SetDefaultStyle(*pStyle);
	sheet.SetStyle(CGXStyle());

	if (sheet.DoModal() != IDOK)
		return;

	CGXLongOperation theOp;

	BeginTrans(GXGetAppData()->strmCellFormatting);

	TRY
	{
		// markierte Zellen
		POSITION pos = selList.GetHeadPosition();
		while (pos)
		{
			CGXRange rect = selList.GetNext(pos);

			if (!SetStyleRange(rect, sheet.GetStyle(), gxOverride, rect.IsCells() ? 0 : -1))
				AfxThrowUserException();
		}

		CommitTrans();
	}
	CATCH(CUserException, e)
	{
		Rollback();
	}
	END_CATCH

	delete pStyle;
}

void CMyGridView::OnFormatLookup()
{
	ROWCOL nRow, nCol;
	if (GetCurrentCell(nRow, nCol))
	{
		CGXStyle* pStyle = CreateStyle();
		ComposeStyleRowCol(max(nRow, 1), max(nCol, 1), pStyle);

		CGXStyleSheet sheet("Current Cell", *GetParam()->GetStylesMap());
		sheet.CreatePages();
		sheet.SetStyle(*pStyle);

		sheet.DoModal();
		delete pStyle;
	}
}

void CMyGridView::OnFormatStyles()
{
	CGXStylesDialog dlg;
	CGXStylesMap& map = *GetParam()->GetStylesMap();

	dlg.SetStylesMap(map);

	if (dlg.DoModal() == IDOK)
	{
		map = dlg.GetStylesMap();
		Redraw();
	}
}

void CMyGridView::OnUpdateFormatCells(CCmdUI* pCmdUI)
{
	pCmdUI->Enable(IsCurrentCell() || GetParam() && GetParam()->GetRangeList()->GetCount() > 0);
}

void CMyGridView::OnUpdateFormatLookup(CCmdUI* pCmdUI)
{
	pCmdUI->Enable(GetParam() && IsCurrentCell());
}

/////////////////////////////////////////////////////////////////////////////
// Freeze Rows and Columns menu handlers

void CMyGridView::OnFormatFreezecols()
{
	FreezeCols();
}

void CMyGridView::OnFormatFreezerows()
{
	FreezeRows();
}

void CMyGridView::OnFormatUnfreezecols()
{
	UnfreezeCols();
}

void CMyGridView::OnFormatUnfreezerows()
{
	UnfreezeRows();
}

void CMyGridView::OnUpdateFormatFreezecols(CCmdUI* pCmdUI)
{
	pCmdUI->Enable(CanFreezeCols());
}

void CMyGridView::OnUpdateFormatFreezerows(CCmdUI* pCmdUI)
{
	pCmdUI->Enable(CanFreezeRows());
}

void CMyGridView::OnUpdateFormatUnfreezecols(CCmdUI* pCmdUI)
{
	pCmdUI->Enable(CanUnfreezeCols());
}

void CMyGridView::OnUpdateFormatUnfreezerows(CCmdUI* pCmdUI)
{
	pCmdUI->Enable(CanUnfreezeRows());
}

/////////////////////////////////////////////////////////////////////////////
// Optimize rows and column widths

void CMyGridView::OnFormatResizecols()
{
	// if there are no cells selected,
	// copy the current cell's coordinates
	CGXRangeList selList;
	if (!CopyRangeList(selList, TRUE))
		return;

	CGXLongOperation theOp;

	// Transfer Current Cell's Data to grid
	if (!TransferCurrentCell())
		return;

	BeginTrans(GXGetAppData()->strmResizeCols);

	// stop updating the display for subsequent commands
	LockUpdate(TRUE);

	TRY
	{
		// series of commands
		// (ResizeColWidthsToFit will do a lot of SetColWidth commands)
		POSITION pos = selList.GetHeadPosition();
		CGXRange* pRange;
		while (pos)
		{
			pRange = selList.GetNext(pos);
			if (!ResizeColWidthsToFit(*pRange))
				AfxThrowUserException();
		}

		CommitTrans();
	}
	CATCH(CUserException, e)
	{
		Rollback();
	}
	END_CATCH

	// Now, refresh the whole grid
	LockUpdate(FALSE);
	Redraw();
}

void CMyGridView::OnUpdateFormatResizecols(CCmdUI* pCmdUI)
{
	pCmdUI->Enable(IsCurrentCell() || GetParam() && GetParam()->GetRangeList()->GetCount() > 0);
}

void CMyGridView::OnFormatResizerows()
{
	// if there are no cells selected,
	// copy the current cell's coordinates
	CGXRangeList selList;
	if (!CopyRangeList(selList, TRUE))
		return;

	CGXLongOperation theOp;

	// Transfer Current Cell's Data to grid
	if (!TransferCurrentCell())
		return;

	BeginTrans(GXGetAppData()->strmResizeRows);

	// stop updating the display for subsequent commands
	LockUpdate(TRUE);

	TRY
	{
		// series of commands
		// (ResizeRowHeihtsToFit will do a lot of SetRowHeight commands)
		POSITION pos = selList.GetHeadPosition();
		CGXRange* pRange;
		while (pos)
		{
			pRange = selList.GetNext(pos);
			if (!ResizeRowHeightsToFit(*pRange))
				AfxThrowUserException();
		}

		CommitTrans();
	}
	CATCH(CUserException, e)
	{
		Rollback();
	}
	END_CATCH

	// Now, refresh the whole grid
	LockUpdate(FALSE);
	Redraw();
}

void CMyGridView::OnUpdateFormatResizerows(CCmdUI* pCmdUI)
{
	pCmdUI->Enable(IsCurrentCell() || GetParam() && GetParam()->GetRangeList()->GetCount() > 0);
}

/////////////////////////////////////////////////////////////////////////////
// Cover Cells menu handlers

void CMyGridView::OnFormatCovercells()
{
	CGXRangeList* pSelList = GetParam()->GetRangeList();

	// check if there is a valid selection
	if (pSelList->IsEmpty()
		|| !pSelList->GetHead()->IsCells() /* check if range of cells and not rows or coluns */)
		return;

	CGXRange* range = pSelList->GetHead();

	if (SetCoveredCellsRowCol(range->top, range->left, range->bottom, range->right))
	{
		// remove all selections, if command was succesfull
		SetSelection(0);
	}
}

void CMyGridView::OnFormatRemovecover()
{
	ROWCOL nRow, nCol;

	if (GetCurrentCell(&nRow, &nCol))
	{
		CGXRange covered;

		if (GetCoveredCellsRowCol(nRow, nCol, covered))
		{
			SetCoveredCellsRowCol(nRow, nCol, nRow, nCol);
		}
	}
}

void CMyGridView::OnUpdateFormatCovercells(CCmdUI* pCmdUI)
{
	if (GetParam() == NULL)
	{
		pCmdUI->Enable(FALSE);
		return;
	}

	CGXRangeList* pSelList = GetParam()->GetRangeList();

	// check if there is a valid selection
	BOOL b = pSelList->IsEmpty()
		|| !pSelList->GetHead()->IsCells(); /* check if range of cells and not rows or coluns */

	pCmdUI->Enable(!b);
}

void CMyGridView::OnUpdateFormatRemovecover(CCmdUI* pCmdUI)
{
	if (GetParam() == NULL)
	{
		pCmdUI->Enable(FALSE);
		return;
	}

	ROWCOL nRow, nCol;

	if (GetCurrentCell(&nRow, &nCol))
	{
		CGXRange covered;

		if (GetCoveredCellsRowCol(nRow, nCol, covered))
		{
			pCmdUI->Enable(TRUE);
			return;
		}
	}
	pCmdUI->Enable(FALSE);
}

/////////////////////////////////////////////////////////////////////////////
// Alignment menu handlers

void CMyGridView::OnFormatAlignCenter()
{
	SetStyle(CGXStyle().SetHorizontalAlignment(DT_CENTER));
}

void CMyGridView::OnFormatAlignLeft()
{
	SetStyle(CGXStyle().SetHorizontalAlignment(DT_LEFT));
}

void CMyGridView::OnFormatAlignRight()
{
	SetStyle(CGXStyle().SetHorizontalAlignment(DT_RIGHT));
}

void CMyGridView::OnUpdateFormatAlignCenter(CCmdUI* pCmdUI)
{
	if (GetParam() == NULL)
	{
		pCmdUI->Enable(FALSE);
		return;
	}

	BOOL bCheck = FALSE;
	pCmdUI->Enable(NeedStyle(CGXStyle().SetHorizontalAlignment(DT_CENTER), bCheck));
	pCmdUI->SetCheck(bCheck);
}

void CMyGridView::OnUpdateFormatAlignLeft(CCmdUI* pCmdUI)
{
	if (GetParam() == NULL)
	{
		pCmdUI->Enable(FALSE);
		return;
	}

	BOOL bCheck = FALSE;
	pCmdUI->Enable(NeedStyle(CGXStyle().SetHorizontalAlignment(DT_LEFT), bCheck));
	pCmdUI->SetCheck(bCheck);
}

void CMyGridView::OnUpdateFormatAlignRight(CCmdUI* pCmdUI)
{
	if (GetParam() == NULL)
	{
		pCmdUI->Enable(FALSE);
		return;
	}

	BOOL bCheck = FALSE;
	pCmdUI->Enable(NeedStyle(CGXStyle().SetHorizontalAlignment(DT_RIGHT), bCheck));
	pCmdUI->SetCheck(bCheck);
}

/////////////////////////////////////////////////////////////////////////////
// Style menu handlers

void CMyGridView::OnFormatStyleBold()
{
	BOOL bSet = TRUE;
	if (NeedStyle(CGXStyle().SetFont(CGXFont().SetBold(TRUE)), bSet))
		SetStyle(CGXStyle().SetFont(CGXFont().SetBold(!bSet)));
}

void CMyGridView::OnFormatStyleItalic()
{
	BOOL bSet = TRUE;
	if (NeedStyle(CGXStyle().SetFont(CGXFont().SetItalic(TRUE)), bSet))
		SetStyle(CGXStyle().SetFont(CGXFont().SetItalic(!bSet)));
}

void CMyGridView::OnFormatStyleUnderline()
{
	BOOL bSet = TRUE;
	if (NeedStyle(CGXStyle().SetFont(CGXFont().SetUnderline(TRUE)), bSet))
		SetStyle(CGXStyle().SetFont(CGXFont().SetUnderline(!bSet)));
}

void CMyGridView::OnUpdateFormatStyleBold(CCmdUI* pCmdUI)
{
	if (GetParam() == NULL)
	{
		pCmdUI->Enable(FALSE);
		return;
	}

	BOOL bCheck = FALSE;
	pCmdUI->Enable(NeedStyle(CGXStyle().SetFont(CGXFont().SetBold(TRUE)), bCheck));
	pCmdUI->SetCheck(bCheck);
}

void CMyGridView::OnUpdateFormatStyleItalic(CCmdUI* pCmdUI)
{
	if (GetParam() == NULL)
	{
		pCmdUI->Enable(FALSE);
		return;
	}

	BOOL bCheck = FALSE;
	pCmdUI->Enable(NeedStyle(CGXStyle().SetFont(CGXFont().SetItalic(TRUE)), bCheck));
	pCmdUI->SetCheck(bCheck);
}

void CMyGridView::OnUpdateFormatStyleUnderline(CCmdUI* pCmdUI)
{
	if (GetParam() == NULL)
	{
		pCmdUI->Enable(FALSE);
		return;
	}

	BOOL bCheck = FALSE;
	pCmdUI->Enable(NeedStyle(CGXStyle().SetFont(CGXFont().SetUnderline(TRUE)), bCheck));
	pCmdUI->SetCheck(bCheck);
}


⌨️ 快捷键说明

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