void CMSOffice2007DemoView::OnInsertTable() { WPD_CHARFORMAT cf = GetCharFormatSelection(); InsertBitmap(IDB_TABLE); SetCharFormat (cf); SyncFont (); }
void CMSOffice2007DemoView::OnFontsize() { CMFCRibbonBar* pRibbon = ((CMainFrame*) GetTopLevelFrame())->GetRibbonBar(); ASSERT_VALID(pRibbon); CMFCRibbonComboBox* pSizeCombo = DYNAMIC_DOWNCAST(CMFCRibbonComboBox, pRibbon->FindByID(ID_FONT_FONTSIZE)); if (pSizeCombo == NULL) { return; } int nSize = GetTwipSize(pSizeCombo->GetEditText()); if (nSize == -2 || (nSize >= 0 && nSize < 20) || nSize > 32760) { // Restore current size: pSizeCombo->SetEditText (TwipsToPointString (GetCharFormatSelection ().yHeight)); MessageBox (_T("The number must be between 1 and 1638.")); return; } if (nSize > 0) { CCharFormat cf; cf.dwMask = CFM_SIZE; cf.yHeight = nSize; SetCharFormat(cf); } }
void CMSOffice2007DemoView::OnInsertPicture() { WPD_CHARFORMAT cf = GetCharFormatSelection(); InsertBitmap(IDB_PICTURE); SetCharFormat (cf); SyncFont (); }
void CEditFrameView::OnFontClear() { GetCharFormatSelection(); m_charformat.dwMask = CFM_BOLD | CFM_ITALIC | CFM_UNDERLINE | CFM_STRIKEOUT | CFM_COLOR; m_charformat.dwEffects = CFE_AUTOCOLOR; SetCharFormat(m_charformat); }
void CBCGPMSOffice2007DemoView::OnFontGrow() { WPD_CHARFORMAT cf = GetCharFormatSelection (); cf.yHeight += 20; SetCharFormat (cf); SyncFont (); }
// 得到字体信息 void CitbookView::onCharFormatgetEx(CHARFORMAT2& cf, DWORD dwMask,DWORD dwEffects) { cf = GetCharFormatSelection (); if (!(cf.dwMask & dwMask) || !(cf.dwEffects & dwEffects)) cf.dwEffects = dwEffects; else cf.dwEffects = 0; cf.dwMask = dwMask; }
void CBCGPMSOffice2007DemoView::OnFontShrink() { WPD_CHARFORMAT cf = GetCharFormatSelection (); if (cf.yHeight <= 20) { return; } cf.yHeight -= 20; SetCharFormat (cf); SyncFont (); }
void CMyRichEditView::OnCharUnderline () { CHARFORMAT2 cf; cf = GetCharFormatSelection(); if (!(cf.dwMask & CFM_UNDERLINE) || !(cf.dwEffects & CFE_UNDERLINE)) cf.dwEffects = CFE_UNDERLINE; else cf.dwEffects = 0; cf.dwMask = CFM_UNDERLINE; SetCharFormat(cf); }
void CMSOffice2007DemoView::OnInsertTableGallery() { if (CRibbonTableButton::GetRows() > 0 && CRibbonTableButton::GetColumns() > 0) { CString str; str.Format(_T("Demo: insert %dx%d table"), CRibbonTableButton::GetColumns(), CRibbonTableButton::GetRows()); MessageBox(str); WPD_CHARFORMAT cf = GetCharFormatSelection(); InsertBitmap(IDB_TABLE); SetCharFormat (cf); SyncFont (); } }
void CActionsSampleView::UpdateActionsState() { CHARFORMAT& cfm = GetCharFormatSelection(); CXTPCommandBars* pCommandBars = ((CXTPFrameWnd*)GetParentFrame())->GetCommandBars(); pCommandBars->GetActions()->FindAction(ID_CHAR_BOLD)->SetChecked( (cfm.dwMask & CFM_BOLD ? (cfm.dwEffects & CFE_BOLD ? 1 : 0) : 2)); pCommandBars->GetActions()->FindAction(ID_CHAR_ITALIC)->SetChecked( (cfm.dwMask & CFM_ITALIC ? (cfm.dwEffects & CFE_ITALIC ? 1 : 0) : 2)); pCommandBars->GetActions()->FindAction(ID_CHAR_UNDERLINE)->SetChecked( (cfm.dwMask & CFM_UNDERLINE ? (cfm.dwEffects & CFE_UNDERLINE ? 1 : 0) : 2)); }
void CBCGPMSOffice2007DemoView::SyncFont () { USES_CONVERSION; CString strFontName; // get the current font from the view and update WPD_CHARFORMAT cf = GetCharFormatSelection (); CBCGPRibbonBar* pRibbon = ((CMainFrame*) GetTopLevelFrame ())->GetRibbonBar (); ASSERT_VALID (pRibbon); // sync font name: CBCGPRibbonFontComboBox* pFontCombo = DYNAMIC_DOWNCAST ( CBCGPRibbonFontComboBox, pRibbon->FindByID (ID_FONT_FONT)); if (pFontCombo != NULL && !pFontCombo->HasFocus ()) { if ((cf.dwMask & (CFM_FACE|CFM_CHARSET)) == (CFM_FACE|CFM_CHARSET)) { #if _MSC_VER >= 1300 strFontName = cf.szFaceName; #else strFontName = A2T(cf.szFaceName); #endif pFontCombo->SetFont (strFontName, DEFAULT_CHARSET, TRUE); } else { pFontCombo->SetText(_T("")); } } // sync font size: CBCGPRibbonComboBox* pFontSizeCombo = DYNAMIC_DOWNCAST ( CBCGPRibbonComboBox, pRibbon->FindByID (ID_FONT_FONTSIZE)); if (pFontSizeCombo != NULL && !pFontSizeCombo->HasFocus ()) { pFontSizeCombo->SetEditText (TwipsToPointString (cf.yHeight)); } SetFocus (); }
void CMSOffice2007DemoView::OnFontname() { USES_CONVERSION; CMFCRibbonBar* pRibbon = ((CMainFrame*) GetTopLevelFrame())->GetRibbonBar(); ASSERT_VALID(pRibbon); CMFCRibbonFontComboBox* pFontCombo = DYNAMIC_DOWNCAST(CMFCRibbonFontComboBox, pRibbon->FindByID(ID_FONT_FONT)); if (pFontCombo == NULL) { return; } CString strWarning; CString strFontName = pFontCombo->GetEditText(); if (pFontCombo->FindItem(strFontName) == -1) { // Restore current name: pFontCombo->SetEditText (GetCharFormatSelection ().szFaceName); strWarning.Format(CString((LPCTSTR)ID_FONT_NOT_FOUND), strFontName); AfxMessageBox(strWarning, MB_OK | MB_ICONWARNING); return; } CCharFormat cf; cf.szFaceName[0] = NULL; cf.dwMask = CFM_FACE | CFM_CHARSET; const CMFCFontInfo* pDesc = pFontCombo->GetFontDesc(); ASSERT_VALID(pDesc); ASSERT(pDesc->m_strName.GetLength() < LF_FACESIZE); #if _MSC_VER >= 1300 lstrcpyn(cf.szFaceName, pDesc->m_strName, LF_FACESIZE); #else lstrcpynA(cf.szFaceName, T2A((LPTSTR)(LPCTSTR) pDesc->m_strName), LF_FACESIZE); #endif cf.bCharSet = pDesc->m_nCharSet; cf.bPitchAndFamily = pDesc->m_nPitchAndFamily; SetCharFormat(cf); }
BOOL CBCGPMSOffice2007DemoView::InsertBitmap (UINT uiBmpResID) { CWaitCursor wait; CBitmap bmp; if (!bmp.LoadBitmap(uiBmpResID)) { return FALSE; } COleDataSource* pDataSrc = new COleDataSource; COleDataObject* pData = new COleDataObject; CBCGPMSOffice2007DemoCntrItem* pItem = NULL; TRY { WPD_CHARFORMAT cf = GetCharFormatSelection(); STGMEDIUM stgm; stgm.hGlobal = bmp.GetSafeHandle(); stgm.tymed = TYMED_GDI; stgm.pUnkForRelease = NULL; pDataSrc->CacheData (CF_BITMAP, &stgm); LPDATAOBJECT lpdata; if (FAILED (pDataSrc->m_xDataObject.QueryInterface (IID_IDataObject, (LPVOID FAR*) &lpdata))) { AfxThrowUserException(); } pData->Attach (lpdata); CBCGPMSOffice2007DemoDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); pItem = new CBCGPMSOffice2007DemoCntrItem (NULL, pDoc); ASSERT_VALID(pItem); if (!pItem->CreateStaticFromData (pData)) { AfxThrowUserException(); } pItem->m_uiCategoryID = uiBmpResID; InsertItem (pItem); pDoc->UpdateAllViews (this); SetCharFormat (cf); SyncFont (); } CATCH(CException, e) { if (pItem != NULL) { ASSERT_VALID(pItem); pItem->Delete (); } delete pData; delete pDataSrc; return FALSE; } END_CATCH delete pData; delete pDataSrc; CMainFrame* pMainFrame = ((CMainFrame*) GetTopLevelFrame ()); ASSERT_VALID (pMainFrame); pMainFrame->ActivateRibbonContextCategory (uiBmpResID); return TRUE; }