📄 uimanager.cpp
字号:
{
if (pCall == NULL)
{
ASSERT(FALSE);
return E_INVALIDARG;
}
RTC_SESSION_STATE CallStatus = pCall->GetCallStatus();
HRESULT hr = S_OK;
CallDisplayItem_t* pItem = NULL;
int ItemIndex = -1;
FindDisplayItem(
pCall,
&pItem,
&ItemIndex
);
if (pItem == NULL)
{
if (pCall->IsRejected())
{
//if this call is rejected, no need to add it to UI
return S_FALSE;
}
CallDisplayItem_t* pCallDisplayItem = new CallDisplayItem_t(pCall);
if (pCallDisplayItem == NULL)
{
return E_OUTOFMEMORY;
}
hr = m_ListBox.AddItem(
-1,
pCallDisplayItem
);
if (FAILED(hr))
{
delete pCallDisplayItem;
}
ItemIndex = m_ListBox.GetCount();
}
else
{
if (CallStatus == RTCSS_DISCONNECTED)
{
hr = pItem->StopTransferring();
pItem->SetTickCount(GetTickCount());
}
}
//update the current call
hr = RedrawItem(ItemIndex);
if (FAILED(hr))
{
return hr;
}
UpdateDialBand();
UpdateMenuBar();
UpdateStatusHeader();
if (NeedToUpdateSelection(CallStatus))
{
UpdateSelection();
}
return hr;
}
void
UIManager_t::FindDisplayItem(
Call_t* pCall,
CallDisplayItem_t** ppCallDisplayItem,
int* pItemIndex
)
{
// Parameter check
if(pCall == NULL || ppCallDisplayItem == NULL)
{
return;
}
*ppCallDisplayItem = NULL;
if (pItemIndex != NULL)
{
*pItemIndex = -1;
}
HRESULT hr = S_OK;
int NumberOfItems = m_ListBox.GetCount();
int StartIndex = (IsShowingDialBand()) ? 1 : 0;
// Iterate over each item in the list
for(int Index = StartIndex; Index < NumberOfItems; Index++)
{
CallDisplayItem_t* pCallItem = NULL;
CComPtr<Call_t> cpStoredCall;
// Get the item at the current index
pCallItem = (CallDisplayItem_t*)m_ListBox.GetItem(Index);
if(pCallItem == NULL)
{
ASSERT(FALSE);
return;
}
// Get the call that must be stored with the item
hr = pCallItem->GetCall(&cpStoredCall);
if (FAILED(hr))
{
ASSERT(FALSE);
return;
}
// Compare the calls
if(cpStoredCall == pCall)
{
// We found it!
*ppCallDisplayItem = pCallItem;
if (pItemIndex != NULL)
{
*pItemIndex = Index;
}
return;
}
}
return;
}
HRESULT
UIManager_t::CreateListenerWindow(
void
)
{
if (m_ListenerWindow != NULL)
{
//already existed!
ASSERT(FALSE);
return S_FALSE;
}
//register our notification window class
WNDCLASS WindowClass = {0};
WindowClass.lpfnWndProc = s_ListenerWindowProc;
WindowClass.hInstance = GlobalData_t::s_ModuleInstance;
WindowClass.lpszClassName = sc_ListenerWindowClassName;
//it's ok if our class already exists...
if (! RegisterClass(&WindowClass) && GetLastError() != ERROR_CLASS_ALREADY_EXISTS)
{
ASSERT(FALSE);
PHONEAPP_DEBUGMSG(ZONE_PHONEAPP_ERROR, (L"Could not register the window class - last error = (decimal) %d", GetLastError()));
return E_FAIL;
}
//create the notification window and pack our 'this' pointer into the CREATESTRUCT
m_ListenerWindow = CreateWindowEx(
WS_EX_NOACTIVATE,
sc_ListenerWindowClassName,
sc_ListenerWindowName,
0, 0, 0, 0, 0, NULL, NULL,
GlobalData_t::s_ModuleInstance,
reinterpret_cast<void*>(this)
);
if (m_ListenerWindow == NULL)
{
ASSERT(FALSE);
PHONEAPP_DEBUGMSG(ZONE_PHONEAPP_ERROR, (L"Could not create the listener window! - error code (decimal) %d", GetLastError()));
return CommonUtilities_t::GetErrorFromWin32();
}
return S_OK;
}
HRESULT
UIManager_t::CreateMainDialog(
bool IsVisible
)
{
if (m_ListenerWindow == NULL)
{
return E_UNEXPECTED;
}
PH_DIALOG_SCREEN_PARAMETERS DialogScreenParameters = {0};
DialogScreenParameters.StructSize = sizeof(PH_DIALOG_SCREEN_PARAMETERS);
DialogScreenParameters.Flags = VDF_TYPE_MODELESS | (IsVisible ? 0 : VDF_HIDDEN);
DialogScreenParameters.Owner = m_ListenerWindow;
DialogScreenParameters.Instance = GlobalData_t::s_ModuleInstance;
DialogScreenParameters.pStatusHeader = MAKEINTRESOURCE(IDS_DEFAULT_HEADER);
DialogScreenParameters.pTitle = CommonUtilities_t::LoadString(GlobalData_t::s_ModuleInstance, IDS_DEFAULT_TITLE);
DialogScreenParameters.MenuId = IDMB_DEFAULT_BUTTONS;
DialogScreenParameters.Id = PHONEAPP_DIALER_SCREEN_ID;
if (!PHDialogScreen(
&DialogScreenParameters
))
{
PHONEAPP_DEBUGMSG(ZONE_PHONEAPP_ERROR, (L"Failed at initializing the Dialog screen"));
}
m_MainDialog = DialogScreenParameters.result.Dialog;
m_MenuBar = GetDlgItem(m_MainDialog, IDC_MENUBAR);
m_StatusHeader = GetDlgItem(m_MainDialog, IDC_STATUSREGION);
m_ListBox = GetDlgItem(m_MainDialog, IDC_LISTBOX);
return S_OK;
}
HRESULT
UIManager_t::CreateIncomingCallMessageBox(
void
)
{
if ((m_cpIncomingCall == NULL) || (m_ListenerWindow == NULL))
{
return E_UNEXPECTED;
}
WCHAR Buffer[MAX_PATH] = L"";
WCHAR Caller[MAX_PATH] = L"";
WCHAR Number[MAX_PATH] = L"";
m_cpIncomingCall->GetDisplayName(
Caller,
ARRAYSIZE(Caller)
);
m_cpIncomingCall->GetDisplayNumber(
Number,
ARRAYSIZE(Number)
);
//arguments to format message
DWORD MessageArguments[] =
{
(DWORD)Caller,
(DWORD)Number,
};
//format the buffer to display to the user
if (!FormatMessage(
FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_ARGUMENT_ARRAY,
L"%1\n%2",
0,
0,
Buffer,
ARRAYSIZE(Buffer),
reinterpret_cast<va_list*>(MessageArguments)
))
{
return CommonUtilities_t::GetErrorFromWin32();
}
PH_MESSAGE_BOX_PARAMETERS MessageBoxParameters = {0};
MessageBoxParameters.StructSize = sizeof(MessageBoxParameters);
MessageBoxParameters.Flags = VDF_TYPE_MODELESS;
MessageBoxParameters.Owner = m_ListenerWindow;
MessageBoxParameters.Instance = GlobalData_t::s_ModuleInstance;
MessageBoxParameters.pTitle = CommonUtilities_t::LoadString(GlobalData_t::s_ModuleInstance, IDS_INCOMING_TITLE);
MessageBoxParameters.pText = Buffer;
MessageBoxParameters.IconId = IDB_ICON_INCOMINGCALL;
MessageBoxParameters.MenuId = IDMB_INCOMING_BUTTONS;
if (!PHMessageBox(
&MessageBoxParameters
))
{
PHONEAPP_DEBUGMSG(ZONE_PHONEAPP_ERROR, (L"Failed at creatting a message box!"));
return E_FAIL;
}
m_MessageBox = MessageBoxParameters.result.Dialog;
return S_OK;
}
HRESULT
UIManager_t::UpdateDialBand(
void
)
{
bool ShowingDialBand = IsShowingDialBand();
HRESULT hr = S_OK;
if (ShouldShowDialBand())
{
if (!ShowingDialBand)
{
CallDisplayItem_t* pCallDisplayItem = new CallDisplayItem_t();
if (pCallDisplayItem == NULL)
{
return E_OUTOFMEMORY;
}
hr = m_ListBox.AddItem(
0,
pCallDisplayItem
);
if (FAILED(hr))
{
delete pCallDisplayItem;
PHONEAPP_DEBUGMSG(ZONE_PHONEAPP_ERROR, (L"Failed at adding a new item into listbox, hr = 0x%x", hr));
return hr;
}
return hr;
}
}
else
{
if (ShowingDialBand)
{
hr = SendMessage(
m_ListBox,
LB_DELETESTRING,
(WPARAM)0,
0
);
return UpdateSelection();
}
}
return hr;
}
bool
UIManager_t::ShouldShowDialBand(
void
)
{
if (!GetApp()->IsOffHook())
{
return false;
}
if (GetApp()->OffHookByMakingCall())
{
return false;
}
RTC_SESSION_STATE vcs = RTCSS_IDLE;
CallList_t pCallList = GetApp()->GetCallList();
for (CallList_t::iterator pCall = pCallList.begin(); pCall != pCallList.end(); pCall ++)
{
switch ((*pCall)->GetCallStatus())
{
case RTCSS_INPROGRESS:
case RTCSS_CONNECTED:
case RTCSS_ANSWERING:
case RTCSS_REFER:
return false;
default:
break;
}
}
//if there is a call in UI currently in transferring state, we should NOT show dial panel
CallDisplayItem_t* pItem;
int NumberOfCalls = m_ListBox.GetCount();
for (int Index = 0; Index < NumberOfCalls; Index++)
{
pItem = static_cast<CallDisplayItem_t*>(m_ListBox.GetItem(Index));
if (pItem == NULL)
{
ASSERT(FALSE);
break;
}
if (pItem->GetState() == e_csTransferring)
{
return false;
}
}
return true;
}
bool
UIManager_t::IsShowingDialBand(
void
)
{
CallDisplayItem_t* pItem = static_cast<CallDisplayItem_t*>(m_ListBox.GetItem(0));
if (pItem == NULL)
{
return false;
}
return (pItem->GetState() == e_csDialing);
}
HRESULT
UIManager_t::ForceCloseCurrentMessageBox(
void
)
{
if (!ThereIsCurrentMessageBox())
{
return S_FALSE;
}
if (!DestroyWindow(m_MessageBox))
{
ASSERT(FALSE);
return CommonUtilities_t::GetErrorFromWin32();
}
m_MessageBox = NULL;
return S_OK;
}
HRESULT
UIManager_t::UpdateMenuBar(
void
)
{
UINT MenuId = 0;
CallDisplayItem_t* pSelectedItem = NULL;
GetSelectedDisplayItem(&pSelectedItem);
if (pSelectedItem == NULL)
{
return m_MenuBar.SetMenu(
GlobalData_t::s_ModuleInstance,
IDMB_DEFAULT_BUTTONS
);
}
HRESULT hr = S_OK;
WCHAR ItemText[MAX_PATH] = L"";
hr = pSelectedItem->GetText(ItemText, MAX_PATH);
if (FAILED(hr))
{
return hr;
}
CallDisplayItemState ItemState = pSelectedItem->GetState();
switch (ItemState)
{
case e_csDialing:
return m_MenuBar.SetMenu(
GlobalData_t::s_ModuleInstance,
(ItemText[0] != 0) ? IDMB_DIALING_BUTTONS : IDMB_DIALING_EMPTY_BUTTONS
);
case e_csTransferring:
return m_MenuBar.SetMenu(
GlobalData_t::s_ModuleInstance,
(ItemText[0] != 0) ? IDMB_TRANSFERRING_BUTTONS : IDMB_TRANSFERRING_EMPTY_BUTTONS
);
default:
hr = m_MenuBar.SetMenu(
GlobalData_t::s_ModuleInstance,
IDMB_CALLSTATUS_BUTTONS
);
if (FAILED(hr))
{
return hr;
}
return m_MenuBar.ShowMenuButton(IDM_HANGUP, ItemState != e_csDisconnected);
}
return S_OK;
}
HRESULT
UIManager_t::UpdateStatusHeader(
void
)
{
STATUS_HEADER_PARAMETERS Parameters = {
GlobalData_t::s_ModuleInstance,
IDS_STATUS_HELP_DEFAULT,
shpDefault,
sc_StatusHeaderCookie,
INFINITE
};
CallDisplayItem_t* pSelectedItem = NULL;
CComPtr<Call_t> cpCall;
GetSelectedDisplayItem(&pSelectedItem);
if (pSelectedItem == NULL)
{
goto exit;
}
if (FAILED(pSelectedItem->GetCall(&cpCall)))
{
goto exit;
}
RTC_SESSION_STATE CallStatus = cpCall->GetCallStatus();
LONG NetworkStatus = cpCall->GetNetworkStatus();
switch (CallStatus)
{
case RTCSS_INCOMING:
Parameters.ResourceId = IDS_STATUS_CALL_RINGING;
break;
case RTCSS_CONNECTED:
Parameters.ResourceId = IDS_STATUS_CALL_CONNECTED;
break;
case RTCSS_HOLD:
Parameters.ResourceId = IDS_STATUS_CALL_HOLDING;
break;
case RTCSS_INPROGRESS:
switch (NetworkStatus)
{
case RTC_E_STATUS_INFO_TRYING:
Parameters.ResourceId = IDS_STATUS_CALL_TRYING;
break;
case RTC_E_STATUS_INFO_CALL_FORWARDING:
Parameters.ResourceId = IDS_STATUS_CALL_FORWARDING;
break;
case RTC_E_STATUS_SESSION_PROGRESS:
Parameters.ResourceId = IDS_STATUS_CALL_PROGRESS;
break;
case RTC_E_STATUS_INFO_RINGING:
Parameters.ResourceId = IDS_STATUS_CALL_RINGING;
break;
default:
Parameters.ResourceId = IDS_STATUS_CALL_CONTACTINGSERVER;
break;
}
break;
case RTCSS_DISCONNECTED:
if (SUCCEEDED(NetworkStatus))
{
return S_OK;
}
Parameters.Cookie = NetworkStatus;
Parameters.Priority = shpError;
Parameters.secTimeout = sc_ErrorNotificationTimeOut;
Parameters.ResourceId = GetStringIdForErrorCode(NetworkStatus);
break;
default:
break;
}
exit:
return AddStatusNotification(&Parameters);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -