⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 uimanager.cpp

📁 一个WinCE6。0下的IP phone的源代码
💻 CPP
📖 第 1 页 / 共 4 页
字号:
        {
            RedrawItem(Index);
        }

        if(pCallItem->GetState() == e_csDisconnected)
        {
            // Yes, we must have stored a tick count with the item
            // If enough time has elapsed since the disconnected
            // event was flagged, remove the item now
            int tk = pCallItem->GetTickCount();
            if(GetTickCount() - tk > sc_DisconnectLag)
            {
                UpdateSelection();
                SendMessage(
                    m_ListBox, 
                    LB_DELETESTRING, 
                    (WPARAM)Index, 
                    0
                    ); 

                Index--;
                ItemCount--;

                UpdateMenuBar(); 
                UpdateStatusHeader(); 
            }
        }
    }

    return S_OK;
}


void 
UIManager_t::OnTimerExpires(
    UINT    TimerID
    )
{
    if (TimerID == 0 || TimerID != m_RefreshUITimerId)
    {
        ASSERT(FALSE); 
        return; 
    }

    SendMessage(
        m_StatusHeader, 
        WM_TIMER, 
        0, 0
        ); 

    SendMessage(
        m_ListBox, 
        WM_TIMER, 
        0, 0
        ); 
    
    RefreshCallDisplayItems();   

    return; 
    
}


void
UIManager_t::GetSelectedDisplayItem(
    CallDisplayItem_t** ppCallDisplayItem, 
    int*                pIndex
    )
{
    if (ppCallDisplayItem == NULL)
    {
        return; 
    }

    *ppCallDisplayItem = NULL; 
    
    int SelectedIndex = m_ListBox.GetCurSel(); 
    
    if (SelectedIndex == -1)
    {
        return;
    }

    if (pIndex != NULL)
    {
        *pIndex = SelectedIndex; 
    }

    *ppCallDisplayItem = static_cast<CallDisplayItem_t*>(m_ListBox.GetItem(SelectedIndex)); 

    return;  
    
}


HRESULT
UIManager_t::RedrawItem(
    int Index
    )
{
    RECT ItemRect   = {0}; 
    RECT ClientRect = {0}; 

    if (m_ListBox.GetItemRect(
                    Index, 
                    &ItemRect
                    ) == LB_ERR)
    {
        return CommonUtilities_t::GetErrorFromWin32(); 
    }

    GetClientRect(m_ListBox, &ClientRect); 
    if (ItemRect.top > ClientRect.bottom)
    {
        return S_FALSE; 
    }

    InvalidateRect(m_ListBox, &ItemRect, TRUE); 

    return S_OK; 
        
}


void
UIManager_t::OnCommand(
    WPARAM wParam
    )
{
    HRESULT hr = S_OK; 
    switch (wParam)
    {
    case IDM_BACKSPACE: 
        hr = OnBackSpace(); 
        break; 
        
    case IDM_DIAL: 
        hr = OnDial(); 
        break; 

    case IDM_CANCEL: 
        hr = OnCancel(); 
        break; 

    case IDM_TRANSFER: 
        hr = OnTransfer(); 
        break; 

    case IDM_HANGUP:
        hr = OnHangup(); 
        break; 
        
    case IDM_SAVETOSPEEDDIAL: 
        hr = OnAddToSpeedDial(); 
        break; 
        
    case IDM_DIRECTTOVOICEMAIL:
        hr = OnReject(); 
        break; 
        
    case IDM_ANSWER: 
        hr = OnAnswer(); 
        break;

    case IDM_HELP_OK: 
        hr = OnCloseHelp(); 
        break; 

    case IDM_INPUT: 
        break; 
        
    default: 
        ASSERT(FALSE); 
        break; 
    }

    if (FAILED(hr) && 
        hr != E_NOTIMPL)
    {
        HandleError(hr); 
    }

    return;     
}

void
UIManager_t::OnListboxNotify(
    DWORD   Notification
    )
{
    switch (Notification)
    {
    case LBN_SELCHANGE: 
        OnNotifySelectChanged(); 
        break;

    case LBN_DBLCLK: 
        OnNotifyDoubleClicked(); 
        break; 

    default: 
        break; 
    }

    return; 
}

HRESULT
UIManager_t::OnEditControlUpdate(
    void
    )
{
    //if the phone is idle, don't do anything
    if (! GetApp()->IsOffHook())
    {
        return S_FALSE;
    }

    GetApp()->StopActiveTone();

    CallDisplayItem_t*  pSelectedItem = NULL; 
    GetSelectedDisplayItem(&pSelectedItem); 
    if (pSelectedItem == NULL)
    {
        return E_UNEXPECTED; 
    }

    HRESULT hr = S_OK; 
    
    CallDisplayItemState  state = pSelectedItem->GetState();

    //If we are dialing or transferring, we are showing an edit pane. If we are
    //showing an edit pane, a character message might add/remove the context buttons or trigger
    //an auto-dial action
    if (state == e_csTransferring || state == e_csDialing)
    {
        WCHAR DialString[MAX_PATH] = L"";
        if (FAILED(pSelectedItem->GetText(
                                    DialString, 
                                    ARRAYSIZE(DialString)
                                    )))
        {
            ASSERT(FALSE);
            return E_UNEXPECTED;
        }

        unsigned int DialStringLength; 
        if (FAILED(StringCchLength(
                    DialString, 
                    ARRAYSIZE(DialString), 
                    &DialStringLength
                    )))
        {
            ASSERT(FALSE); 
            return E_UNEXPECTED; 
        }

        //Update the context buttons only if the change warrants an update
        if (DialStringLength == 0 || DialStringLength == 1)
        {
            UpdateMenuBar();
        }

        if (
            DialStringLength >0 && 
            PHGetSetting(phsAutoDial) &&
            GetApp()->GetDialEngine().IsPhoneNumberReadyForAutoDial(DialString)
            )
        {
            switch (state)
            {
            case e_csTransferring:
                hr = Transfer();
                break;

            case e_csDialing:
                hr = OnDial();
                break;

            default:
                ASSERT(FALSE);
                hr = E_UNEXPECTED;
            }
        }
    }

    return hr;
    
}

HRESULT
UIManager_t::OnNotifySelectChanged(
    void
    )
{
    CallDisplayItem_t* pSelectedItem = NULL; 
    GetSelectedDisplayItem(&pSelectedItem); 
    if (pSelectedItem == NULL)
    {
        return E_UNEXPECTED; 
    }

    CallDisplayItemState    ItemState = pSelectedItem->GetState(); 
    WCHAR                   ItemText[MAX_PATH] = L""; 

    pSelectedItem->GetText(
                    ItemText, 
                    ARRAYSIZE(ItemText)
                    ); 

    if (ItemState == e_csDialing && !ItemText[0])
    {
        GetApp()->PlayProgressTone(AudioManager_t::ProgressToneDial); 
    }
    else
    {
        GetApp()->StopActiveTone(); 
    }

    UpdateStatusHeader(); 
    UpdateMenuBar(); 
    
    return S_OK; 
}


HRESULT
UIManager_t::OnNotifyDoubleClicked(
    void
    )
{
    return OnHold(); 
}


HRESULT
UIManager_t::AddStatusNotification(
    STATUS_HEADER_PARAMETERS*     pParameters
    )
{
    return (HRESULT)SendMessage(
                        m_StatusHeader, 
                        WM_STATUSHEADER_ADDSTATUSNOTIFICATION, 
                        (WPARAM)sizeof(STATUS_HEADER_PARAMETERS), 
                        (LPARAM)pParameters
                        ); 
}

HRESULT
UIManager_t::SendDTMF(
    RTC_DTMF DTMFCode
    )
{

    CallDisplayItem_t*  pSelectedItem = NULL;
    GetSelectedDisplayItem(&pSelectedItem); 
    if (pSelectedItem == NULL)
    {
        return E_UNEXPECTED; 
    }
    
    CComPtr<Call_t> cpCall; 
    if (FAILED(pSelectedItem->GetCall(&cpCall)))
    {
        return E_UNEXPECTED; 
    }

    return cpCall->SendDTMF(DTMFCode); 
    
}

void
UIManager_t::HandleError(
    HRESULT ErrorHResult
    )
{
    PHONEAPP_RETAILMSG(ZONE_PHONEAPP_ERROR, (L"Handle Error 0x%x", ErrorHResult));

    STATUS_HEADER_PARAMETERS Parameters; 

    Parameters.Instance     = GlobalData_t::s_ModuleInstance; 
    Parameters.Cookie       = ErrorHResult; 
    Parameters.Priority     = shpError; 
    Parameters.secTimeout   = sc_ErrorNotificationTimeOut; 
    Parameters.ResourceId   = GetStringIdForErrorCode(ErrorHResult); 

    AddStatusNotification(&Parameters); 

    return; 
    
}

void
UIManager_t::OnHelp(
    void
    )
{
    CreateHelpMessageBox(IDS_SCREENHELP_CALLSINPROGRESS); 
    return; 
}

HRESULT
UIManager_t::OnCloseHelp(
    void
    )
{
    return ForceCloseCurrentMessageBox(); 
}

void
UIManager_t::OnHookDialing(
    WCHAR CurrentChar
    )
{
    if (CurrentChar > L'9' || CurrentChar < L'0')
    {
        return; 
    }

    if (!IsShowingDialBand())
    {
        m_AlreadyDialedString.append(CurrentChar); 
    }

    GetApp()->EnsureOffHook(); 

    return; 

}


void
UIManager_t::GetAlreadyDialedString(
    WCHAR*          pBuffer, 
    unsigned int    BufferSize
    )
{
    if (pBuffer == NULL || BufferSize <= 0)
    {
        return; 
    }

    StringCchCopy(
        pBuffer, 
        BufferSize, 
        m_AlreadyDialedString
        ); 

    //reset the cached string
    m_AlreadyDialedString.clear(); 
    
}


void
UIManager_t::OnFailedMakingACall(
    void
    )
{
    CreateHelpMessageBox(IDS_ERROR_INVALIDNUMBER); 

    return; 
}

HRESULT
UIManager_t::CreateHelpMessageBox(
    unsigned int TextStringId
    )
{
    ForceCloseCurrentMessageBox(); 

    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_SCREENHELP_TITLE);
    MessageBoxParameters.pText      = CommonUtilities_t::LoadString(GlobalData_t::s_ModuleInstance, TextStringId);
    MessageBoxParameters.IconId     = IDB_HELP_ICON;
    MessageBoxParameters.MenuId     = IDMB_HELP_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; 
    
}

bool
UIManager_t::IsEmpty(
    void
    )
{
    if (IsWindow(m_ListBox))
    {
        int ItemCount = m_ListBox.GetCount(); 
        
        if (ItemCount == 0)
        {
            return true; 
        }

        for (int Index = 0; Index < ItemCount; Index++)
        {
            CallDisplayItem_t*  pCallItem = (CallDisplayItem_t*)m_ListBox.GetItem(Index);
            if (pCallItem == NULL)        
            {
                ASSERT(FALSE);
                continue;
            }

            if(pCallItem->GetState() != e_csDisconnected)
            {
                return false; 
            }
        }

        return true; 

    }

    return true; 
}


/*------------------------------------------------------------------------------
    UIManager_t::GetStringIdForErrorCode
    
    static helper function to get the string resoruce id for given error code
------------------------------------------------------------------------------*/
/*static*/UINT 
UIManager_t::GetStringIdForErrorCode(
    LONG    ErrorCode
    )
{
    int     FacilityCode = HRESULT_FACILITY(ErrorCode); 
    
    switch (FacilityCode)
    {
        case FACILITY_RTC_INTERFACE: 
            return GetStringIdForRTCError(ErrorCode); 
            
        case FACILITY_SIP_STATUS_CODE:
        case FACILITY_PINT_STATUS_CODE: 
            return GetStringIdForSIPPINTError(ErrorCode); 

        case FACILITY_WIN32: 
            switch (ErrorCode)
            {
                case E_POINTER: 
                case E_UNEXPECTED: 
                case E_INVALIDARG:
                case E_FAIL: 
                    return IDS_ERROR_INTERNAL; 

                case E_OUTOFMEMORY: 
                    return IDS_ERROR_OUTOFMEMORY; 

                default: 
                    break;         
            }

            return IDS_ERROR_WIN32;  

       case FACILITY_ITF: 
            switch (ErrorCode)
            {
                case VOIP_E_REACHMAXNUMBEROFCALLS: 
                    return IDS_ERROR_INVALIDNUMBER; 

                default: 
                    break; 
            }

            return IDS_ERROR_WIN32; 

        default: 
            break;             
    }

    return IDS_ERROR_UNKNOWN; 
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -