📄 dsofcontrol.cpp
字号:
return;
}
////////////////////////////////////////////////////////////////////////
// CDsoFramerControl::OnDraw
//
// Drawing is largely limited to border and titlebar, except when in
// design mode. We don't do any background painting to avoid paint problems
// when we have an ui active DocObject. It should do any painting for us.
//
STDMETHODIMP_(void) CDsoFramerControl::OnDraw(DWORD dvAspect, HDC hdcDraw, LPRECT prcBounds, LPRECT prcWBounds, HDC hicTargetDev, BOOL fOptimize)
{
COLORREF clrBackground, clrForeground, clrBorder, clrT;
HBRUSH hbshBackground, hbshBorder;
HFONT hfontText, hfontOld;
HPALETTE hpal, hpalOld;
LOGFONT lfText = {-11,0,0,0,FW_NORMAL,0,0,0,0,0,0,0,FF_SWISS, "Tahoma"};
RECT rc, rcT;
int iTxtMode;
// Copy out the bounding rect...
CopyRect(&rc, prcBounds);
// On 256 color systems, we may need a palette...
if ((GetDeviceCaps(hdcDraw, RASTERCAPS) & RC_PALETTE) &&
((GetDeviceCaps(hdcDraw, BITSPIXEL) * GetDeviceCaps(hdcDraw, PLANES)) == 8))
{
hpal = CreateHalftonePalette(hdcDraw);
hpalOld = SelectPalette(hdcDraw, hpal, TRUE);
RealizePalette(hdcDraw);
}
else hpal = NULL;
// Translate the OLE_COLOR values to a matching COLORREF in palette...
OleTranslateColor(m_clrBackColor, hpal, &clrBackground);
OleTranslateColor(m_clrForeColor, hpal, &clrForeground);
OleTranslateColor(m_clrBorderColor, hpal, &clrBorder);
// Create the resources we need for drawing and setting up the DC...
hbshBackground = CreateSolidBrush(clrBackground);
hbshBorder = CreateSolidBrush(clrBorder);
hfontText = CreateFontIndirect(&lfText);
hfontOld = (HFONT)SelectObject(hdcDraw, hfontText);
iTxtMode = SetBkMode(hdcDraw, TRANSPARENT);
// Based on the choosen border style, draw the border and deflate the
// drawing rect accordingly...
switch (m_fBorderStyle)
{
case 1:
{
HBRUSH hbT = GetSysColorBrush(COLOR_BTNFACE);
FrameRect(hdcDraw, &rc, hbshBorder); InflateRect(&rc, -1, -1);
FrameRect(hdcDraw, &rc, hbT); InflateRect(&rc, -1, -1);
FrameRect(hdcDraw, &rc, hbshBorder); InflateRect(&rc, -1, -1);
}
break;
case 2:
DrawEdge(hdcDraw, &rc, EDGE_SUNKEN, BF_RECT);
InflateRect(&rc, -2, -2);
break;
case 3:
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"探索者科技在线WORD控件"); //Office Control");
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;
// 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;
}
// 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, "&文件");
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,
DT_SINGLELINE | DT_VCENTER | ((v_fWindows2KPlus) ? DT_HIDEPREFIX : 0));
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_fComponentActive))
{
// 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);
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);
return;
}
////////////////////////////////////////////////////////////////////////
// CDsoFramerControl::OnFocusChange
//
// Selectively handle focus changes to make sure both host and ui
// active docobject are in synch.
//
STDMETHODIMP_(void) CDsoFramerControl::OnFocusChange(BOOL fGotFocus, HWND hFocusWnd)
{
HWND hwndT;
TRACE1("CDsoFramerControl::OnFocusChange(%d)\n", fGotFocus);
// When IP active, notify the control host of focus change...
if ((m_fInPlaceActive) && (m_pControlSite))
{
if (m_fModalState)
{
ODS("Got focus notifcation while modal.\n");
return;
}
if (fGotFocus) // If we got focus...
{
// Notify host we have focus (we only need
// to do this if we are not already UI Active)...
if (!(m_fUIActive))
m_pControlSite->OnFocus(fGotFocus);
#ifdef DSO_ACTIVATION_ON_FOCUS_CHANGE
// Notify object of activation change...
OnComponentActivationChange(TRUE);
#endif
// If we have an active document, forward the focus...
if ((m_pDocObjFrame) && (hwndT=m_pDocObjFrame->GetActiveWindow()))
{
ODS("Forward focus to host (ie, SetFocus to ActiveObject hwnd)\n");
SetFocus(hwndT);
}
}
else // else we lost focus...
{
// When we lose focus, only notify host if we lost to window
// that does not belong to us...
hwndT = hFocusWnd;
while (hwndT = GetParent(hwndT))
if (hwndT == m_hwnd) return;
#ifdef DSO_ACTIVATION_ON_FOCUS_CHANGE
// Notify object of activation change...
OnComponentActivationChange(FALSE);
#endif
ODS("Notify host of lost focus (ie, UI deactivate us)\n");
m_pControlSite->OnFocus(fGotFocus);
}
}
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");
m_hwnd = NULL;
Close();
if (m_pFrameHook)
{
m_pFrameHook->Detach(this);
m_pFrameHook = NULL;
}
if (m_hbmDeactive)
{
DeleteObject(m_hbmDeactive);
m_hbmDeactive = NULL;
}
if (m_hmenuFilePopup)
{
DestroyMenu(m_hmenuFilePopup);
m_hmenuFilePopup = NULL;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -