📄 dsofcontrol.cpp
字号:
DrawEdge(hdcDraw, &rc, BDR_SUNKENOUTER, BF_RECT);
InflateRect(&rc, -1, -1);
break;
//default: no border...
}
// Draw the titlebar if visible...
if (m_fShowTitlebar)
{
COLORREF clrTitlebar, clrTitlebarText;
HBRUSH hbshTitlebar, hbshT;
LPWSTR pwszDCaption = NULL;
LPWSTR pwszROCaption = NULL;
LPWSTR pwszCaption = ((m_bstrCustomCaption) ?
m_bstrCustomCaption : L"KB311765: Office Framer Control Sample");
CopyRect(&rcT, &rc);
rcT.bottom = rcT.top + 21;
OleTranslateColor(m_clrTBarColor, hpal, &clrTitlebar);
OleTranslateColor(m_clrTBarTextColor, hpal, &clrTitlebarText);
hbshTitlebar = CreateSolidBrush(clrTitlebar);
FillRect(hdcDraw, &rcT, hbshTitlebar);
DrawIconEx(hdcDraw, rcT.left+2, rcT.top+2, v_icoOffDocIcon, 16, 16, 0, NULL, DI_NORMAL);
clrT = SetTextColor(hdcDraw, clrTitlebarText);
rcT.left += 22;
// If we have an embedded object, check to see if it is an open doc and
// append the name to the titlebar. Also append "Read-Only" string if file
// was open in read-only mode.
if (m_pDocObjFrame)
{
if ((pwszDCaption = (LPWSTR)m_pDocObjFrame->GetSourceDocName()) != NULL)
{
LPCWSTR pwszCat[2] = {L" - ", pwszDCaption};
pwszDCaption = DsoCopyStringCatEx(pwszCaption, 2, pwszCat);
pwszCaption = pwszDCaption;
}
if (m_pDocObjFrame->IsReadOnly())
{
pwszROCaption = DsoCopyStringCat(pwszCaption, L" (Read-Only)");
pwszCaption = pwszROCaption;
}
}
// Draw out the custom titlebar caption in Unicode if on NT/XP OS, since
// a custom caption may have non-ANSI characters...
FDrawText(hdcDraw, pwszCaption, &rcT, DT_VCENTER|DT_SINGLELINE);
// Cleanup temp strings...
if (pwszROCaption) DsoMemFree(pwszROCaption);
if (pwszDCaption) DsoMemFree(pwszDCaption);
CopyRect(&rcT, &rc);
rcT.bottom = rcT.top + 21;
rcT.top = rcT.bottom - 1;
hbshT = GetSysColorBrush(COLOR_BTNSHADOW);
FillRect(hdcDraw, &rcT, hbshT);
SetTextColor(hdcDraw, clrT);
DeleteObject(hbshTitlebar);
}
// Draw menu bar if visible...
if (m_fShowMenuBar)
{
GetSizeRectForMenuBar(prcBounds, &rcT);
FillRect(hdcDraw, &rcT, GetSysColorBrush(COLOR_BTNFACE));
// When in design mode, we just draw placeholder...
if (FRunningInDesignMode())
{
clrT = SetTextColor(hdcDraw, GetSysColor(COLOR_BTNSHADOW));
DrawText(hdcDraw, "Menu Bar", -1, &rcT, DT_SINGLELINE|DT_VCENTER|DT_CENTER);
SetTextColor(hdcDraw, clrT);
}
else
{
HMENU hCurMenu;
CHAR szbuf[DSO_MAX_MENUNAME_LENGTH];
UINT i, yTop, yBottom, xLast, xNext;
SIZE ptMItem; RECT rcMDraw;
BOOL fSelected;
DWORD dwDTFlags = (DT_SINGLELINE | DT_VCENTER);
// Get the current menu and setup to draw the number of items in it...
if (hCurMenu = GetActivePopupMenu())
{
yTop = rcT.top + 3; yBottom = rcT.bottom - 3; xLast = rcT.left + 2;
if (hCurMenu == m_hmenuFilePopup)
{ m_cMenuItems = 1; }
else
{
if ((m_cMenuItems = (USHORT)GetMenuItemCount(hCurMenu)) > DSO_MAX_MENUITEMS)
m_cMenuItems = DSO_MAX_MENUITEMS;
}
// If we are on an OS that supports it, hide the prefix when we are not UI active
// or if the host has disabled menu accelerators for this instance...
if (v_fWindows2KPlus && (!(m_fUIActive) || (m_fDisableMenuAccel)))
dwDTFlags |= DT_HIDEPREFIX;
// For each item in the menu, get the menu name and draw it to the
// menu bar. We need to calculate the size taken by the font used and
// store the information in an array used by mouse move handler to
// determine which menu item the user is over...
for (i = 0; i < m_cMenuItems; i++)
{
szbuf[0] = '\0';
if (i == 0) lstrcpy(szbuf, "&File");
else GetMenuString(hCurMenu, i, szbuf, DSO_MAX_MENUNAME_LENGTH, MF_BYPOSITION);
GetTextExtentPoint32(hdcDraw, szbuf, lstrlen(szbuf), &ptMItem);
xNext = (xLast + ptMItem.cx + 2);
if (xNext > (UINT)(rcT.right)){ m_cMenuItems = (USHORT)i; break; }
SetRect(&rcMDraw, xLast, yTop, xNext, yBottom);
if (fOptimize)
CopyRect(&m_rgrcMenuItems[i], &rcMDraw);
// If user is over this particular item, we draw it as selected...
fSelected = ((m_wSelMenuItem) && (i == (UINT)(m_wSelMenuItem - 1)));
if (fSelected)
{
FillRect(hdcDraw, &rcMDraw, GetSysColorBrush(COLOR_HIGHLIGHT));
clrT = SetTextColor(hdcDraw, GetSysColor(COLOR_HIGHLIGHTTEXT));
}
rcMDraw.left += 4;
DrawText(hdcDraw, szbuf, lstrlen(szbuf), &rcMDraw, dwDTFlags);
if (fSelected)
SetTextColor(hdcDraw, clrT);
xLast = xNext + 2;
}
}
}
rcT.top = rcT.bottom - 1; // Draw a line to separate menu from workspace...
FillRect(hdcDraw, &rcT, GetSysColorBrush(COLOR_BTNSHADOW));
}
// Fill in the background (but only if there is no active object)...
if (!m_pDocObjFrame)
{
GetSizeRectForDocument(prcBounds, &rcT);
FillRect(hdcDraw, &rcT, hbshBackground);
// When in design mode, we do a little extra stuff to help the
// developer visualize some of the control settings (toolbars,
// foreground color, etc.)...
if (FRunningInDesignMode())
{
if (m_fShowToolbars)
{
rcT.bottom = rcT.top + 25;
FillRect(hdcDraw, &rcT, GetSysColorBrush(COLOR_BTNFACE));
clrT = SetTextColor(hdcDraw, GetSysColor(COLOR_BTNSHADOW));
DrawText(hdcDraw, "Toolbar Space", -1, &rcT, DT_SINGLELINE|DT_VCENTER|DT_CENTER);
SetTextColor(hdcDraw, clrT);
GetSizeRectForDocument(prcBounds, &rcT);
rcT.top = rcT.top + 25;
}
clrT = SetTextColor(hdcDraw, GetSysColor(COLOR_BTNSHADOW));
DrawText(hdcDraw, "ActiveX Document Object", -1, &rcT, DT_SINGLELINE|DT_VCENTER|DT_CENTER);
SetTextColor(hdcDraw, clrT);
}
}
else if ((m_pDocObjFrame) && (!m_fAppActive || !m_fComponentActive) && (FDrawBitmapOnAppDeactive() || FIPDeactivateOnCompChange()))
{
// In the case we have more than one component, and this component is
// has an object but is not ui active we draw a bitmap representation
// of the obect to fill the area. This gives the user a sense the object
// is there but in background, and can click to reactivate...
GetSizeRectForDocument(prcBounds, &rcT);
if (m_hbmDeactive)
{
HDC hdcT = CreateCompatibleDC(hdcDraw);
HBITMAP bmpOld = (HBITMAP)SelectObject(hdcT, m_hbmDeactive);
BITMAP bm;
if (GetObject(m_hbmDeactive, sizeof(BITMAP), &bm))
{
StretchBlt(hdcDraw, rcT.left, rcT.top,
(rcT.right - rcT.left), (rcT.bottom - rcT.top),
hdcT, 0, 0, bm.bmWidth, bm.bmHeight, SRCCOPY);
}
else
{
BitBlt(hdcDraw, rcT.left, rcT.top,
(rcT.right - rcT.left), (rcT.bottom - rcT.top), hdcT, 0,0, SRCCOPY);
}
SelectObject(hdcT, bmpOld);
DeleteDC(hdcT);
}
else if (!m_fInDocumentLoad)
{
//FillRect(hdcDraw, &rcT, hbshBackground);
rcT.top = ((rc.bottom - rc.top) / 2);
//clrT = SetTextColor(hdcDraw, clrForeground);
//DrawText(hdcDraw, "Unable to display inactive document. Click here to reactivate the object.", -1, &rcT, DT_WORDBREAK | DT_CENTER);
//SetCursor(LoadCursor(NULL, IDC_WAIT));//add code 080703
//Activate();
//UIActivate(TRUE);
//SetTextColor(hdcDraw, clrT);
}
} // else The docobj draws the rest...
// Cleanup the hDC as required...
DeleteObject(hbshBackground);
DeleteObject(hbshBorder);
SelectObject(hdcDraw, hfontOld);
DeleteObject(hfontText);
if (hpal)
{
SelectPalette(hdcDraw, hpalOld, TRUE);
DeleteObject(hpal);
}
SetBkMode(hdcDraw, iTxtMode);
SetMapMode(hdcDraw, iMapMode);
return;
}
////////////////////////////////////////////////////////////////////////
// CDsoFramerControl::OnDestroyWindow
//
// When the window closes make sure the object closes and release the
// subclass we have on the parent's top-level window.
//
STDMETHODIMP_(void) CDsoFramerControl::OnDestroyWindow()
{
ODS("CDsoFramerControl::OnDestroyWindow\n");
if (m_pDocObjFrame)
Close();
if (m_pHookManager)
{
m_pHookManager->DetachComponent(m_hwnd);
m_pHookManager = NULL;
}
m_hwnd = NULL;
if (m_pServerLock)
SetTempServerLock(FALSE);
if (m_hbmDeactive)
{
DeleteObject(m_hbmDeactive);
m_hbmDeactive = NULL;
}
if (m_hmenuFilePopup)
{
DestroyMenu(m_hmenuFilePopup);
m_hmenuFilePopup = NULL;
}
}
////////////////////////////////////////////////////////////////////////
// CDsoFramerControl::OnResize
//
// Resize the window and notify the doc site.
//
STDMETHODIMP_(void) CDsoFramerControl::OnResize()
{
RECT rcPlace;
ODS("CDsoFramerControl::OnResize\n");
if (m_pDocObjFrame)
{
if (FChangeObjActiveOnFocusChange() && (!m_fUIActive))
UIActivate(FALSE);
GetSizeRectForDocument(NULL, &rcPlace);
m_pDocObjFrame->OnNotifySizeChange(&rcPlace);
}
}
////////////////////////////////////////////////////////////////////////
// CDsoFramerControl::OnMouseMove
//
// We watch for mouse movement on menu bar (when visible).
//
STDMETHODIMP_(void) CDsoFramerControl::OnMouseMove(UINT x, UINT y)
{
// TRACE2("CDsoFramerControl::OnMouseMove(%d, %d)\n", x, y);
// TRACE3(" fAppActive=%d, fUIActive=%d, fCompActive=%d\n", m_fAppActive, m_fUIActive, m_fComponentActive);
// TRACE2(" fModalState=%d, fNoInteractive=%d\n", m_fModalState, m_fNoInteractive);
// When we are in mouse move, watch for menu selection. Only need to
// do this if bar is visible and we are not in modal state...
if ((m_fShowMenuBar) && (m_fComponentActive) && (m_fUIActive) && (m_fAppActive) &&
(!m_fModalState) && (!m_fNoInteractive))
{
UINT item;
POINT pt; pt.x = x; pt.y = y;
// If we already have item selected, check to see if we are still
// over it. If so, we can exit now. If not, we sould unselect it.
if (m_wSelMenuItem)
{
item = m_wSelMenuItem - 1;
if (PtInRect(&m_rgrcMenuItems[item], pt))
return;
ReleaseCapture(); m_wSelMenuItem = 0;
InvalidateRect(m_hwnd, &m_rgrcMenuItems[item], FALSE);
}
// Now loop through the menu items and see if mouse is over them.
// If it is, we set a mouse capture and draw item as selected...
for (item = 0; item < m_cMenuItems; item++)
{
if (PtInRect(&m_rgrcMenuItems[item], pt))
{
SetCapture(m_hwnd);
m_wSelMenuItem = (USHORT)(item + 1);
InvalidateRect(m_hwnd, &m_rgrcMenuItems[item], FALSE);
break;
}
}
}
return;
}
////////////////////////////////////////////////////////////////////////
// CDsoFramerControl::OnButtonDown
//
// We watch for mouse button down events when the titlebar is visible
// so we can drop down our popup menu if the user clicks around the
// area of the file icon. This is our workaround for menu merging.
//
STDMETHODIMP_(void) CDsoFramerControl::OnButtonDown(UINT x, UINT y)
{
HMENU hCurMenu = NULL;
RECT rc;
// Don't do anything if we are in modal state...
if (m_fModalState) return;
// We don't handle commands when m_fNoInteractive is set, except for the
// condition where we are in print preview and want to display custom menu
// item to end the preview. Office apps have toolbar button to do this, but
// we will provide this option just in case user needs it to exit preview mode...
if (m_fNoInteractive)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -