📄 callrecorddisplayitem.cpp
字号:
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// Use of this sample source code is subject to the terms of the Microsoft
// license agreement under which you licensed this sample source code. If
// you did not accept the terms of the license agreement, you are not
// authorized to use this sample source code. For the terms of the license,
// please see the license agreement between you and Microsoft or, if applicable,
// see the LICENSE.RTF on your install media or the root of your tools installation.
// THE SAMPLE SOURCE CODE IS PROVIDED "AS IS", WITH NO WARRANTIES.
//
#include "CallRecordDisplayItem.h"
#include "PaintHelper.hpp"
#include "Resource.h"
#include "Common.hpp"
#include "Layout.hpp"
const INT c_siDisplayName = 0;
const INT c_siURI = 1;
const INT c_siStartDateTime = 2;
inline VOID FormatRect(
RECT *prcDest,
const RECT *prcSrc
)
{
*prcDest = *prcSrc;
prcDest->top += Layout_t::CallRecordMarginHeight();
prcDest->bottom -= Layout_t::CallRecordMarginHeight();
prcDest->left += Layout_t::CallRecordMarginWidth();
prcDest->right -= Layout_t::CallRecordMarginWidth();
}
CVoIPCallRecordDisplayItem::CVoIPCallRecordDisplayItem(
void* piRecord
)
{
if (piRecord == NULL)
{
ASSERT(FALSE);
}
HRESULT hr = static_cast<IUnknown*>(piRecord)->QueryInterface(
IID_IVoIPCallRecord,
(void**)&m_cpCallRecord
);
if (SUCCEEDED(hr))
{
ASSERT(m_cpCallRecord != NULL);
return;
}
hr = static_cast<IUnknown*>(piRecord)->QueryInterface(
IID_IVoIPCallerInfoRecord,
(void**)&m_cpCallerInfoRecord
);
if (SUCCEEDED(hr))
{
ASSERT(m_cpCallerInfoRecord != NULL);
return;
}
ASSERT(FALSE);
return;
}
CVoIPCallRecordDisplayItem::~CVoIPCallRecordDisplayItem()
{
}
BOOL CVoIPCallRecordDisplayItem::GetHeight(
UINT * pfHeight
)
{
ASSERT(pfHeight != NULL);
*pfHeight = Layout_t::CallRecordHeight();
return TRUE;
}
/*------------------------------------------------------------------------------
CVoIPCallRecordDisplayItem::GetStartTimeString
Gets a starttime string for the current item that shows when
the call started
Parameters:
str: Reference to a string that will be filled with the starttime.
------------------------------------------------------------------------------*/
HRESULT CVoIPCallRecordDisplayItem::GetStartTimeString(
ce::wstring &str
)
{
HRESULT hr = S_OK;
SYSTEMTIME st = {0};
WCHAR wszBuf[256];
// No duration if there's no record
if(m_cpCallRecord == NULL)
{
str = L"";
return S_OK;
}
// Get the starttime from the record
m_cpCallRecord->get_StartTime(&st);
// Turn the starttime into a string
hr = CommonUtilities_t::ToHR(GetTimeFormat(
LOCALE_USER_DEFAULT,
TIME_NOSECONDS,
&st,
NULL,
wszBuf,
_countof(wszBuf)
));
if (FAILED(hr))
{
ASSERT(FALSE);
return hr;
}
if (!str.assign(wszBuf))
{
return E_OUTOFMEMORY;
}
return S_OK;
}
/*------------------------------------------------------------------------------
CVoIPCallRecordDisplayItem::GetStartDateString
Gets a time string for the current item that shows when the call started
(day, month, year).
Parameters:
str: Reference to a string that will be filled with the start date.
------------------------------------------------------------------------------*/
HRESULT CVoIPCallRecordDisplayItem::GetStartDateString(
ce::wstring &str
)
{
HRESULT hr = S_OK;
SYSTEMTIME st;
WCHAR wszBuf[100];
// No start time if there's no record
if(m_cpCallRecord == NULL)
{
str = L"";
return S_OK;
}
// Get the start time from the current call
hr = m_cpCallRecord->get_StartTime(&st);
if (FAILED(hr))
{
ASSERT(FALSE);
return hr;
}
// Convert the system time to a date string
hr = CommonUtilities_t::ToHR(GetDateFormat(
LOCALE_SYSTEM_DEFAULT,
DATE_SHORTDATE,
&st,
NULL,
wszBuf,
_countof(wszBuf) - 1
));
if (FAILED(hr))
{
ASSERT(FALSE);
return hr;
}
if (!str.assign(wszBuf))
{
return E_OUTOFMEMORY;
}
return S_OK;
}
/*------------------------------------------------------------------------------
CVoIPCallRecordDisplayItem::DrawMain
Draws the main part of the call record item.
------------------------------------------------------------------------------*/
HRESULT CVoIPCallRecordDisplayItem::Draw(
HDC hdc,
const RECT *prc,
BOOL fSelected,
BOOL fTopItem
)
{
HRESULT hr = S_OK;
RECT rcText;
RECT rc;
WCHAR Buffer[MAX_PATH] = L"";
rc = *prc;
hr = DrawBand(
hdc,
prc,
fSelected,
fTopItem
);
if (FAILED(hr))
{
ASSERT(FALSE);
return hr;
}
PaintHelper_t paint;
hr = paint.Attach(hdc);
if (FAILED(hr))
{
ASSERT(FALSE);
return hr;
}
// Shrink the rectangle to account for margins
FormatRect(&rc, prc);
paint.SetTextColor(PHGetColor(fSelected ? phcDisplayItemSelectedTextColor : phcDisplayItemTextColor));
paint.SetBkMode(TRANSPARENT);
// Draw the friendly name using the bold font
paint.SetFont(PHGetFont(phfStandardTextBold));
GetSubItemText(c_siDisplayName, Buffer, _countof(Buffer));
if(Buffer[0])
{
// Upper left quadrant
SetRect(&rcText, rc.left, rc.top, rc.right, rc.bottom);
hr = paint.DrawText(
Buffer,
-1,
&rcText,
DT_TOP | DT_LEFT | DT_SINGLELINE | DT_NOPREFIX | DT_END_ELLIPSIS
);
ASSERT(SUCCEEDED(hr));
}
// Draw the rest of the items using the standard font
paint.SetFont(PHGetFont(phfStandardText));
//reset the buffer
Buffer[0] = 0;
//draw the URI
GetSubItemText(c_siURI, Buffer, _countof(Buffer));
if(Buffer[0])
{
// Lower left quadrant
SetRect(&rcText, rc.left, rc.top, rc.right - ((rc.right - rc.left)/2), rc.bottom);
// Draw the URI
hr = paint.DrawText(
Buffer,
-1,
&rcText,
DT_BOTTOM | DT_LEFT | DT_SINGLELINE | DT_NOPREFIX | DT_END_ELLIPSIS
);
ASSERT(SUCCEEDED(hr));
}
if (m_cpCallRecord == NULL)
{
return S_OK;
}
//reset the buffer
Buffer[0] = 0;
//draw the start time
GetSubItemText(c_siStartDateTime, Buffer, _countof(Buffer));
if(Buffer[0])
{
// Lower right quadrant
SetRect(&rcText, rc.left, rc.top, rc.right, rc.bottom);
// Draw the start time
hr = paint.DrawText(
Buffer,
-1,
&rcText,
DT_BOTTOM | DT_RIGHT | DT_SINGLELINE | DT_NOPREFIX | DT_END_ELLIPSIS
);
ASSERT(SUCCEEDED(hr));
}
// Restore the DC
//
paint.End();
return S_OK;
}
/*------------------------------------------------------------------------------
CVoIPCallRecordDisplayItem::GetRecord
Returns the associated IVoIPCallRecord.
------------------------------------------------------------------------------*/
HRESULT CVoIPCallRecordDisplayItem::GetCallRecord(
IVoIPCallRecord** ppiRecord
)
{
// Parameter check
if(ppiRecord == NULL)
{
return E_POINTER;
}
// Copy the COM pointer
*ppiRecord = m_cpCallRecord;
// AddRef since we're assigning to vanilla COM pointer
(*ppiRecord)->AddRef();
return S_OK;
}
HRESULT CVoIPCallRecordDisplayItem::GetCallerInfoRecord(
IVoIPCallerInfoRecord** ppiCallerInfoRecord
)
{
// Parameter check
if(ppiCallerInfoRecord == NULL)
{
return E_POINTER;
}
// Copy the COM pointer
*ppiCallerInfoRecord = m_cpCallerInfoRecord;
// AddRef since we're assigning to vanilla COM pointer
(*ppiCallerInfoRecord)->AddRef();
return S_OK;
}
/*------------------------------------------------------------------------------
CVoIPCallRecordDisplayItem::GetSubItemText
Returns the specified subitem's text
------------------------------------------------------------------------------*/
HRESULT CVoIPCallRecordDisplayItem::GetSubItemText(int idxSubItem, WCHAR *wszText, UINT cchText)
{
HRESULT hr = S_OK;
ce::auto_bstr bstr;
wszText[0] = L'\0';
switch (idxSubItem)
{
case c_siDisplayName:
if (m_cpCallRecord != NULL)
{
m_cpCallRecord->get_FriendlyName(&bstr);
}
else
{
m_cpCallerInfoRecord->get_FriendlyName(&bstr);
}
if (bstr && bstr[0])
{
StringCchCopy (
wszText,
cchText,
bstr
);
}
else
{
LoadString(
GlobalData_t::s_ModuleInstance,
IDS_LABEL_UNKNOWN_CALLER,
wszText,
cchText
);
}
break;
case c_siURI:
if (m_cpCallRecord != NULL)
{
m_cpCallRecord->get_URI(&bstr);
}
else
{
m_cpCallerInfoRecord->get_URI(&bstr);
}
if (bstr && bstr[0])
{
hr = StringCchCopy(
wszText,
cchText,
bstr
);
}
else
{
LoadString(
GlobalData_t::s_ModuleInstance,
IDS_LABEL_UNKNOWN_NUMBER,
wszText,
cchText
);
}
break;
case c_siStartDateTime:
{
ce::wstring strStartTime;
ce::wstring strStartDate;
// Get the duration from the record
hr = GetStartTimeString(strStartTime);
if(SUCCEEDED(hr))
{
// Get the date from the record
hr = GetStartDateString(strStartDate);
}
if(SUCCEEDED(hr))
{
// Concatenate the strings
strStartDate += L" ";
strStartDate += strStartTime;
StringCchCopy(
wszText,
cchText,
strStartDate.get_buffer()
);
}
}
break;
default:
hr = S_FALSE;
break;
}
return hr;
}
/*------------------------------------------------------------------------------
CVoIPCallRecordDisplayItem::NeedsToolTip
The item needs a tool tip if the URI cannot fit in its alloted drawing rectangle
------------------------------------------------------------------------------*/
BOOL CVoIPCallRecordDisplayItem::NeedsToolTip(
RECT * prc
)
{
if (! prc)
{
ASSERT(FALSE);
return FALSE;
}
WCHAR Buffer[100] = L"";
GetText(Buffer, _countof(Buffer));
if (! Buffer[0])
{
return FALSE;
}
RECT rcDraw = {0};
HRESULT hr = PaintHelper_t::CalculateTextDimensions(
Buffer,
-1,
PHGetFont(phfStandardText),
&rcDraw,
DT_TOP | DT_LEFT | DT_SINGLELINE | DT_NOPREFIX
);
if (FAILED(hr))
{
ASSERT(FALSE);
return FALSE;
}
rcDraw.right += Layout_t::CallRecordMarginWidth();
return (RECTWIDTH(rcDraw) > RECTWIDTH(*prc));
}
/*------------------------------------------------------------------------------
CVoIPCallRecordDisplayItem::GetText
Get text returns the URI in this case (which will be tool-tipped if its too long)
------------------------------------------------------------------------------*/
HRESULT CVoIPCallRecordDisplayItem::GetText(
WCHAR * wszBuffer,
INT cchBuffer
)
{
return GetSubItemText(
c_siURI,
wszBuffer,
cchBuffer
);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -