📄 calldisplayitem.cpp
字号:
CallDisplayItem_t::RemoveControls
Destroys the edit control if it has been created
------------------------------------------------------------------------------*/
HRESULT
CallDisplayItem_t::RemoveControls(
void
)
{
if ((HWND)m_EditControl)
{
m_RemovingEditControl = true;
DestroyWindow(m_EditControl);
}
return S_OK;
}
/*------------------------------------------------------------------------------
CallDisplayItem_t::DrawCallInfo
If we are in a call and not dialing/transferring, draw the
information relevant to this call:
Name, Phone Number, Duration and Glyph represeting the status
------------------------------------------------------------------------------*/
HRESULT
CallDisplayItem_t::DrawCallInfo(
HDC hdc,
const RECT* pRECT,
BOOL Selected
)
{
HRESULT hr = S_OK;
HFONT hfntOld = NULL;
INT bmOld = -1;
COLORREF crOld;
RECT rcText;
RECT rc;
HFONT hfntURI = NULL;
HFONT hfntName = NULL;
HFONT hfntDuration = NULL;
WCHAR wszBuffer[MAX_PATH] = L"";
rc = *pRECT;
// Shrink the rectangle to account for margins
rc.top += Layout_t::CallTextTopMargin();
rc.bottom -= Layout_t::CallTextBottomMargin();
rc.left += Layout_t::CallTextLeftMargin();
rc.right -= Layout_t::CallTextRightMargin();
// Break up the remaining section into quadrants for the four pieces of
// text that will be drawn
INT xLeftText = rc.right - Layout_t::CallDurationWidth();
INT yBottomText = rc.top + (rc.bottom - rc.top) / 2;
// Is the band empty?
if(m_cpCall == NULL)
{
// Can bypass the entire draw phase
return S_OK;
}
if(SUCCEEDED(hr))
{
// Create the fonts
hfntURI = PHGetFont(phfStandardText);
hfntName = PHGetFont(phfStandardTextBold);
hfntDuration = PHGetFont(phfInformationText);
if(
hfntURI == NULL ||
hfntName == NULL ||
hfntDuration == NULL
)
{
hr = CommonUtilities_t::GetErrorFromWin32();
}
}
if(SUCCEEDED(hr))
{
hfntOld = (HFONT)SelectObject(hdc, hfntName);
bmOld = SetBkMode(hdc, TRANSPARENT);
crOld = SetTextColor(hdc, Selected ? PHGetColor(phcDisplayItemSelectedTextColor): PHGetColor(phcDisplayItemTextColor));
hr = GetSubItemText(DisplayName, wszBuffer, ARRAYSIZE(wszBuffer));
}
if(SUCCEEDED(hr))
{
if(wszBuffer[0] != L'\0')
{
// Upper left quadrant
SetRect(&rcText, rc.left, rc.top, xLeftText, yBottomText);
// Draw the name
hr = CommonUtilities_t::ToHR(DrawText(
hdc,
wszBuffer,
-1,
&rcText,
DT_TOP | DT_LEFT | DT_SINGLELINE | DT_NOPREFIX | DT_END_ELLIPSIS
));
}
}
if(SUCCEEDED(hr))
{
hr = DrawGlyph(hdc, &rc, (RTC_SESSION_STATE)GetState());
}
if(SUCCEEDED(hr))
{
SelectObject(hdc, hfntURI);
// Get the URI from the current call
hr = GetSubItemText(URI, wszBuffer, ARRAYSIZE(wszBuffer));
}
if(SUCCEEDED(hr))
{
if(wszBuffer[0] != L'\0')
{
// Lower left quadrant
SetRect(&rcText, rc.left, yBottomText, xLeftText, rc.bottom);
// Draw the URI
hr = CommonUtilities_t::ToHR(DrawText(
hdc,
wszBuffer,
-1,
&rcText,
DT_BOTTOM | DT_LEFT | DT_SINGLELINE | DT_NOPREFIX | DT_END_ELLIPSIS
));
}
}
if(SUCCEEDED(hr))
{
SelectObject(hdc, hfntDuration);
hr = GetSubItemText(Duration, wszBuffer, ARRAYSIZE(wszBuffer));
}
if(SUCCEEDED(hr))
{
// Lower right quadrant
SetRect(&rcText, xLeftText, yBottomText, rc.right, rc.bottom);
// Draw the elapsed time
hr = CommonUtilities_t::ToHR(::DrawText(
hdc,
wszBuffer,
-1,
&rcText,
DT_BOTTOM | DT_RIGHT | DT_NOPREFIX
));
}
// Restore the DC
//
if(bmOld != -1)
{
SetBkMode(hdc, bmOld);
SetTextColor(hdc, crOld);
}
if(hfntOld != NULL)
{
SelectObject(hdc, hfntOld);
}
// Clean up
//
//intentionally leak the font handles and the bitmap handles
//since they are cached objects
return hr;
}
/*------------------------------------------------------------------------------
CallDisplayItem_t::DrawGlyph
Draws the glyph representing the call state in the appropriate part of
the rectangle
------------------------------------------------------------------------------*/
HRESULT
CallDisplayItem_t::DrawGlyph(
HDC hdc,
RECT* pRECT,
RTC_SESSION_STATE CallStatus
)
{
HRESULT hr = S_FALSE;
VARIANT_BOOL vbIsHost = VARIANT_FALSE,
vbIsPart = VARIANT_FALSE;
// Find the status entry and change the text color if found
const CallAnimationEntry *c_pEntry = FindAnimationStatusEntry(CallStatus);
if (!c_pEntry)
{
return S_FALSE;
}
INT idxGlyphOffset = c_pEntry->idxGlyphOffset;
INT cGlyphFrames = c_pEntry->cGlyphFrames;
if(c_pEntry != NULL)
{
// Draw the glyph for this item's status
INT idxFrame =
(::GetTickCount() / c_cmsAnimateSpeed) %
cGlyphFrames;
// Load the bitmap for the item glyph
HBITMAP hbmGlyphs = GlobalData_t::s_GDICacheObject.LoadCachedBitmap(IDB_CALL_GLYPHS);
hr = CommonUtilities_t::ToHR(TransparentImage(
hdc,
pRECT->right - Layout_t::CallGlyphWidth() - 2,
pRECT->top,
Layout_t::CallGlyphWidth(),
Layout_t::CallGlyphHeight(),
(HANDLE)hbmGlyphs,
idxFrame * Layout_t::CallGlyphWidth(),
idxGlyphOffset * Layout_t::CallGlyphHeight(),
Layout_t::CallGlyphWidth(),
Layout_t::CallGlyphHeight(),
PHGetColor(phcDefaultTransparentColor)
));
}
return hr;
}
/*------------------------------------------------------------------------------
CallDisplayItem_t::DrawDialing
Draws the item when its state is Dialing
------------------------------------------------------------------------------*/
HRESULT
CallDisplayItem_t::DrawDialing(
HDC hdc,
const RECT* pRECT,
BOOL Selected
)
{
HRESULT hr = S_OK;
WCHAR wszDial[MAX_PATH] = L"";
HFONT hfntText = NULL;
RECT rcDraw = *pRECT;
//Load the strings and fonts for drawing
hfntText = PHGetFont(phfStandardText);
hr = CommonUtilities_t::ToHR(hfntText != NULL);
if (SUCCEEDED(hr))
{
hr = GetSubItemText(DialLabel, wszDial, ARRAYSIZE(wszDial));
}
if (SUCCEEDED(hr))
{
//Draw the text
HFONT hfntOld = (HFONT)SelectObject(hdc, hfntText);
INT bkOld = SetBkMode(hdc, TRANSPARENT);
COLORREF crOld = SetTextColor(
hdc,
Selected ? PHGetColor(phcDisplayItemSelectedTextColor): PHGetColor(phcDisplayItemTextColor)
);
rcDraw.left += Layout_t::CallControlLabelMarginWidth();
hr = CommonUtilities_t::ToHR(::DrawText(
hdc,
wszDial,
-1,
&rcDraw,
DT_BOTTOM | DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_NOPREFIX
));
SelectObject(hdc, hfntOld);
SetBkMode (hdc, bkOld);
SetTextColor(hdc, crOld);
}
return hr;
}
/*------------------------------------------------------------------------------
CallDisplayItem_t::DrawTransferring
Draw the item when the state is (internal) transferring
------------------------------------------------------------------------------*/
HRESULT
CallDisplayItem_t::DrawTransferring(
HDC hdc,
const RECT* pRECT,
BOOL Selected
)
{
PREFAST_ASSERT(pRECT != NULL && m_cpCall != NULL);
//first draw the transfer text
//then draw the dial text
HRESULT hr = S_OK;
WCHAR wszText [MAX_PATH] = L"";
RECT rcDraw, rcGlyph;
RTC_SESSION_STATE CallStatus = m_cpCall->GetCallStatus();
hr = GetSubItemText(TransferText, wszText, ARRAYSIZE(wszText));
//Draw the glyph
if (SUCCEEDED(hr))
{
SetRect(
&rcGlyph ,
pRECT->left + Layout_t::CallTextLeftMargin(),
pRECT->top + Layout_t::CallTextTopMargin(),
pRECT->right - Layout_t::CallTextRightMargin(),
pRECT->bottom - Layout_t::CallTextBottomMargin()
);
hr = DrawGlyph(hdc, &rcGlyph, CallStatus);
}
//Draw the "transfer to:" text
if (SUCCEEDED(hr))
{
RECT rcEdit = {0},
rcParent = {0};
::GetWindowRect(GetParent(m_EditControl), &rcParent);
::GetWindowRect(m_EditControl, &rcEdit);
rcDraw = *pRECT;
rcDraw.left += rcEdit.left - rcParent.left;
rcDraw.top += Layout_t::TransferEditFromTop();
HFONT hfntTransfer = PHGetFont(phfInformationText);
HFONT hfntOld = (HFONT)SelectObject(hdc, hfntTransfer);
INT bkOld = SetBkMode(hdc, TRANSPARENT);
COLORREF crOld = SetTextColor(hdc, Colors_t::TransferToLabelColor());
hr = CommonUtilities_t::ToHR(::DrawText(
hdc,
wszText,
-1,
&rcDraw,
DT_TOP | DT_LEFT | DT_SINGLELINE | DT_NOPREFIX
));
SetTextColor(hdc, crOld);
SetBkMode(hdc, bkOld);
SelectObject(hdc, hfntOld);
}
//The rest of the band looks exactly like the dialing band
if (SUCCEEDED(hr))
{
hr = DrawDialing(hdc, pRECT, Selected);
}
return hr;
}
/*------------------------------------------------------------------------------
CallDisplayItem_t::Draw
Draws the entire item.
Parameters:
hdc: Device context into which to draw.
pRECT: Rectangle into which to draw.
dwItemState: Item state for this item.
------------------------------------------------------------------------------*/
HRESULT
CallDisplayItem_t::Draw(
HDC hdc,
const RECT* pRECT,
BOOL fSelected,
BOOL fTopItem
)
{
HRESULT hr = S_OK;
// Draw the band
// this can be changed to use the common control
hr = DrawBand(
hdc,
pRECT,
fSelected,
fTopItem
);
//Draw the rest of the information over the band based on the state of
//the item
if (SUCCEEDED(hr))
{
switch (GetState())
{
case e_csDialing:
hr = DrawDialing(hdc, pRECT, fSelected);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -