// This MFC Samples source code demonstrates using MFC Microsoft Office Fluent User Interface
// (the "Fluent UI") and is provided only as referential material to supplement the
// Microsoft Foundation Classes Reference and related electronic documentation
// included with the MFC C++ library software.
// License terms to copy, use or distribute the Fluent UI are available separately.
// To learn more about our Fluent UI licensing program, please visit
// http://msdn.microsoft.com/officeui.
//
// Copyright (C) Microsoft Corporation
// All rights reserved.
#include "stdafx.h"
#include "MSOffice2007Demo.h"
#include "OptionsPage.h"
#include "ResourcePage.h"
#include "MainFrm.h"
#include "keys.h"
#include "RibbonTableButton.h"
#include <memory>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#pragma warning(disable:4100)
const int IdStartProgressTimer = 1;
const int IdShowProgressTimer = 2;
const DWORD idTabDeveloper = 101;
/////////////////////////////////////////////////////////////////////////////
// CMainFrame
IMPLEMENT_DYNCREATE(CMainFrame, CFrameWndEx)
BEGIN_MESSAGE_MAP(CMainFrame, CFrameWndEx)
//{{AFX_MSG_MAP(CMainFrame)
ON_WM_CREATE()
ON_WM_GETMINMAXINFO()
ON_WM_PAINT()
ON_WM_ERASEBKGND()
ON_WM_SIZING()
ON_WM_SIZE()
ON_WM_TIMER()
ON_COMMAND(ID_WRITE_CLIPBOARD, OnWriteClipboard)
ON_UPDATE_COMMAND_UI(ID_WRITE_CLIPBOARD, OnUpdateWriteClipboard)
ON_COMMAND(ID_VIEW_RTL, OnViewRtl)
ON_UPDATE_COMMAND_UI(ID_VIEW_RTL, OnUpdateViewRtl)
ON_COMMAND(ID_STATUSBAR_ZOOM_SLIDER, OnZoomSlider)
ON_COMMAND(ID_STATUSBAR_ZOOM, OnZoom)
ON_COMMAND_RANGE(ID_VIEW_APPLOOK_2003, ID_VIEW_APPLOOK_2007_4, OnAppLook)
ON_UPDATE_COMMAND_UI_RANGE(ID_VIEW_APPLOOK_2003, ID_VIEW_APPLOOK_2007_4, OnUpdateAppLook)
ON_COMMAND(ID_STATUSBAR_REFRESH, OnRefresh)
ON_UPDATE_COMMAND_UI(ID_STATUSBAR_REFRESH, OnUpdateRefresh)
ON_COMMAND(ID_STATUSBAR_SPELL, OnSpell)
ON_COMMAND(ID_TOOLS_OPTIONS, OnToolsOptions)
ON_REGISTERED_MESSAGE(AFX_WM_ON_RIBBON_CUSTOMIZE, OnRibbonCustomize)
ON_COMMAND(ID_STATUSBAR_LINK, OnLink)
ON_REGISTERED_MESSAGE(AFX_WM_ON_HIGHLIGHT_RIBBON_LIST_ITEM, OnHighlightRibbonListItem)
ON_COMMAND(ID_VIEW_MESSAGEBAR, OnViewMessageBar)
ON_UPDATE_COMMAND_UI(ID_VIEW_MESSAGEBAR, OnUpdateViewMessageBar)
ON_REGISTERED_MESSAGE(AFX_WM_ON_BEFORE_SHOW_RIBBON_ITEM_MENU, OnShowRibbonItemMenu)
ON_COMMAND_RANGE(ID_PAGELAYOUT_EFFECTS_ACADEMIC, ID_PAGELAYOUT_THEMES_MORETHEMES, OnDummy)
ON_COMMAND(ID_FILE_PRINT, OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, OnFilePrintPreview)
ON_UPDATE_COMMAND_UI(ID_FILE_PRINT_PREVIEW, OnUpdateFilePrintPreview)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMainFrame construction/destruction
CMainFrame::CMainFrame()
{
m_rectFill.SetRectEmpty();
m_rectSizing.SetRectEmpty();
m_nProgressValue = -1;
m_bInfiniteProgressMode = TRUE;
CreateDocumentColors();
CreateStyleList();
CreateThemeList();
CreateFontsList();
CMFCPopupMenu::SetAnimationType(CMFCPopupMenu::SYSTEM_DEFAULT_ANIMATION);
}
CMainFrame::~CMainFrame()
{
for (POSITION pos = m_TooltipImages.GetStartPosition(); pos != NULL;)
{
CMFCToolBarImages* pBmp = NULL;
UINT uiID;
m_TooltipImages.GetNextAssoc(pos, uiID, pBmp);
delete pBmp;
}
}
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CFrameWndEx::OnCreate(lpCreateStruct) == -1)
return -1;
// Load background patterns:
m_Pat[0].Create(CMFCControlRendererInfo(IDB_VIEWPAT_1, RGB(255, 0, 255), CRect(0, 0, 8, 8), CRect(0, 0, 0, 0)));
m_Pat[1].Create(CMFCControlRendererInfo(IDB_VIEWPAT_2, RGB(255, 255, 255), CRect(0, 0, 499, 157), CRect(0, 0, 0, 0), CRect(480, 0, 0, 0), CRect(480, 0, 499, 157)));
m_Pat[2].Create(CMFCControlRendererInfo(IDB_VIEWPAT_3, RGB(255, 255, 255), CRect(0, 0, 499, 157), CRect(0, 0, 0, 0), CRect(480, 0, 0, 0), CRect(480, 0, 499, 157)));
m_Pat[3].Create(CMFCControlRendererInfo(IDB_VIEWPAT_4, RGB(255, 255, 255), CRect(0, 0, 499, 157), CRect(0, 0, 0, 0), CRect(480, 0, 0, 0), CRect(480, 0, 499, 157)));
if (!CreateRibbonBar())
{
TRACE0("Failed to create ribbon bar\n");
return -1; // fail to create
};
if (!CreateStatusBar())
{
TRACE0("Failed to create status bar\n");
return -1; // fail to create
}
if (!CreateMessageBar())
{
TRACE0("Failed to create message bar\n");
}
// Create task pane:
CRect rectDummy(0, 0, 200, 400);
if (!m_wndTaskPane.Create(_T("Clipboard"), this, rectDummy, TRUE, ID_VIEW_TASK_PANE, WS_CHILD | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | CBRS_LEFT | AFX_CBRS_CLOSE | AFX_CBRS_FLOAT))
{
TRACE0("Failed to create task pane\n");
return -1;
}
m_wndTaskPane.EnableDocking(CBRS_ALIGN_RIGHT | CBRS_ALIGN_LEFT);
DockPane(&m_wndTaskPane);
EnableDocking(CBRS_ALIGN_ANY);
OnChangeLayout();
// Show progress bar after the short delay:
SetTimer(IdStartProgressTimer, 500, NULL);
// Start animation:
CMFCRibbonStatusBarPane* pPane = DYNAMIC_DOWNCAST(CMFCRibbonStatusBarPane, m_wndStatusBar.FindElement(ID_STATUSBAR_SPELL));
if (pPane != NULL)
{
pPane->StartAnimation(500 /* Frame delay*/, 5000 /* Duration */);
}
return 0;
}
void CMainFrame::SetKeys()
{
m_MainButton.SetKeys(_T("f"));
for (int i = 0; keys [i].uiCmd != 0; i++)
{
CString str = keys [i].lpszKey;
int nAmpIndex = str.Find(_T('&'));
if (nAmpIndex >= 0)
{
CString str1 = str.Left(nAmpIndex);
CString str2 = str.Mid(nAmpIndex + 1);
m_wndRibbonBar.SetElementKeys(keys [i].uiCmd, str1, str2);
}
else
{
m_wndRibbonBar.SetElementKeys(keys [i].uiCmd, str);
}
}
}
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
if ( !CFrameWndEx::PreCreateWindow(cs) )
return FALSE;
cs.style |= WS_CLIPCHILDREN;
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CMainFrame diagnostics
#ifdef _DEBUG
void CMainFrame::AssertValid() const
{
CFrameWndEx::AssertValid();
}
void CMainFrame::Dump(CDumpContext& dc) const
{
CFrameWndEx::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMainFrame message handlers
void CMainFrame::OnAppLook(UINT id)
{
CWaitCursor wait;
theApp.m_nAppLook = id;
switch (theApp.m_nAppLook)
{
case ID_VIEW_APPLOOK_2003:
CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerOffice2003));
break;
default:
switch (theApp.m_nAppLook)
{
case ID_VIEW_APPLOOK_2007_1:
CMFCVisualManagerOffice2007::SetStyle(CMFCVisualManagerOffice2007::Office2007_LunaBlue);
break;
case ID_VIEW_APPLOOK_2007_2:
CMFCVisualManagerOffice2007::SetStyle(CMFCVisualManagerOffice2007::Office2007_ObsidianBlack);
break;
case ID_VIEW_APPLOOK_2007_3:
CMFCVisualManagerOffice2007::SetStyle(CMFCVisualManagerOffice2007::Office2007_Aqua);
break;
case ID_VIEW_APPLOOK_2007_4:
CMFCVisualManagerOffice2007::SetStyle(CMFCVisualManagerOffice2007::Office2007_Silver);
break;
}
CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerOffice2007));
}
if (m_MemBitmap.GetSafeHandle() != NULL)
{
m_MemBitmap.DeleteObject();
}
RedrawWindow(NULL, NULL, RDW_ALLCHILDREN | RDW_INVALIDATE | RDW_UPDATENOW | RDW_FRAME | RDW_ERASE);
theApp.WriteInt(_T("ApplicationLook"), theApp.m_nAppLook);
}
void CMainFrame::OnUpdateAppLook(CCmdUI* pCmdUI)
{
pCmdUI->SetRadio(theApp.m_nAppLook == pCmdUI->m_nID);
}
BOOL CMainFrame::CreateRibbonBar()
{
if (!m_wndRibbonBar.Create(this))
{
return -1; // fail to create
}
// Load panel images:
m_PanelImages.SetImageSize(CSize(16, 16));
if (!m_PanelImages.Load(IDB_BUTTONS))
{
TRACE0("Failed to load panel images\n