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

📄 uimanager.cpp

📁 一个WinCE6。0下的IP phone的源代码
💻 CPP
📖 第 1 页 / 共 4 页
字号:

}
    
HRESULT 
UIManager_t::UpdateSelection(
    void
    )
{
    CallDisplayItem_t*  pItem = NULL;
    
    int ItemCount       = m_ListBox.GetCount();  
    int ValidCallIndex  = -1; 
    int ToBeSelectedIndex  = -1;

    for (int Index = 0; Index < ItemCount; Index++)
    {
        pItem = (CallDisplayItem_t*)m_ListBox.GetItem(Index);
        if (! pItem)
        {
            ASSERT(FALSE);
            goto exit;
        }

        switch (pItem->GetState())
        {
        //The connected or answering call should have selection, since the user
        //is talking to them :)
        case e_csConnected:
        case e_csAnswering:
            ToBeSelectedIndex = Index;
            goto exit;

        //we should track all other valid calls and select the first one (provided there
        //is no connected/answering call)
        case e_csHolding:
        case e_csIncoming:
        case e_csInProgress:
        case e_csReferring:
        case e_csTransferring:
            if (ValidCallIndex == -1)
            {
                ValidCallIndex = Index;
            }
            break;
            
        default:
            break;
        }
        
    }
    
exit:    
    //make sure we have a selection
    if (ToBeSelectedIndex == -1)
    {
        //default to the first valid call item
        if (ValidCallIndex != -1)
        {
            ToBeSelectedIndex = ValidCallIndex;
        }
        else if (ItemCount > 0)
        {
            //otherwise use the first item in the display
            ToBeSelectedIndex = 0;
        }
    }

    if (ToBeSelectedIndex >= 0)
    {
        m_ListBox.SetCurSel(ToBeSelectedIndex); 
    }

    return S_OK;
}

HRESULT 
UIManager_t::OnBackSpace()
{
    CallDisplayItem_t*  pSelectedItem = NULL; 
    GetSelectedDisplayItem(&pSelectedItem); 
    if (pSelectedItem == NULL)
    {
        return S_FALSE; 
    }

    return pSelectedItem->OnBackspace(); 
}

HRESULT 
UIManager_t::OnDial(
    void
    )
{
    CallDisplayItem_t* pItem = (CallDisplayItem_t*)m_ListBox.GetItem(0);
    if (pItem == NULL)
    {
        ASSERT(FALSE);
        return E_UNEXPECTED;
    }

    WCHAR DialString[MAX_PATH] = L"";        
    HRESULT hr = pItem->GetText(
                            DialString, 
                            ARRAYSIZE(DialString)
                            );
    if ((FAILED(hr)) || !DialString[0])
    {
        return E_FAIL; 
    }

    CComPtr<Call_t> cpCall;    
    hr = GetApp()->Call(
                    DialString,
                    NULL, 
                    &cpCall
                    );
    if (FAILED(hr))
    {
        return hr; 
    }
    
    hr = pItem->AssignCall(cpCall);
    
    UpdateStatusHeader();

    return hr;
}


HRESULT
UIManager_t::OnCancel(
    void
    )
{
    StopTransferring(); 
    UpdateDialBand(); 

    return S_OK; 
}


HRESULT
UIManager_t::OnHangup(
    void
    )
{
    CallDisplayItem_t*  pSelectedItem = NULL; 
    GetSelectedDisplayItem(&pSelectedItem); 
    if (pSelectedItem == NULL)
    {
        return S_FALSE;
    }
    
    CComPtr<Call_t> cpCall;    
    HRESULT hr = pSelectedItem->GetCall(&cpCall);
    if (cpCall == NULL)
    {
        return S_FALSE; 
    }

    return cpCall->DoPhoneVerb(PH_VERB_END);         
}

HRESULT
UIManager_t::OnAddToSpeedDial(
    void
    )
{
    //Get the current display item
    CallDisplayItem_t*  pSelectedItem = NULL; 
    GetSelectedDisplayItem(&pSelectedItem); 
    if (pSelectedItem == NULL)
    {
        return S_FALSE;
    }

    PH_SPEEDDIAL_ENTRY  SpeedDialEntry = {0};
    SpeedDialEntry.StructSize = sizeof(SpeedDialEntry);

    //Fill the speed dial entry with the contents of 
    //the call display item
    pSelectedItem->GetSubItemText(
        CallDisplayItem_t::DisplayName, 
        SpeedDialEntry.pName, 
        _countof(SpeedDialEntry.pName)
        );

    pSelectedItem->GetSubItemText(
        CallDisplayItem_t::URI, 
        SpeedDialEntry.pNumber, 
        _countof(SpeedDialEntry.pNumber)
        );

    return PHAddSpeedDialEntry(&SpeedDialEntry);
}

HRESULT
UIManager_t::OnAnswer(
    void
    )
{
    if (m_cpIncomingCall == NULL)
    {
        return E_UNEXPECTED; 
    }

    if (GetApp()->IsOffHook())
    {
        ForceCloseCurrentMessageBox(); 
        
        HRESULT hr = GetApp()->PlaceActiveSessionOnHold(); 
        if (FAILED(hr))
        {
            //if we failed at placing other active calls on hold, reject the call
            PHONEAPP_DEBUGMSG(ZONE_PHONEAPP_ERROR, (L"Failed at placing other active session on hold, hr = 0x%x", hr)); 
            m_cpIncomingCall->DoPhoneVerb(PH_VERB_REJECT_INCOMING);         
            return hr;     
        }

        hr = m_cpIncomingCall->DoPhoneVerb(PH_VERB_ACCEPT_INCOMING);         
        if (FAILED(hr))
        {
            PHONEAPP_DEBUGMSG(ZONE_PHONEAPP_ERROR, (L"Failed at accepting incoming call, hr = 0x%x", hr));             
        }

        return hr;
    }
    
    return GetApp()->EnsureOffHook();
}

HRESULT
UIManager_t::OnReject(
    void
    )
{
    if (m_cpIncomingCall == NULL)
    {
        return E_UNEXPECTED; 
    }

    //mark this call is rejected
    m_cpIncomingCall->MarkAsRejected(); 

    return  m_cpIncomingCall->DoPhoneVerb(PH_VERB_REJECT_INCOMING);    
}


HRESULT
UIManager_t::OnHold(
    bool*   pHandled 
    )
{
    if (pHandled != NULL)
    {
        *pHandled = false; 
    }

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

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

    bool    Handled = false; 
    HRESULT hr = S_OK; 
    
    switch (cpCall->GetCallStatus())
    {
        case RTCSS_HOLD: 
            Handled = true; 
            hr = cpCall->DoPhoneVerb(PH_VERB_UNHOLD); 
            break; 

        case RTCSS_CONNECTED:
            Handled = true; 
            hr = cpCall->DoPhoneVerb(PH_VERB_HOLD); 
            break; 

        default: 
            break; 
    }

    if (pHandled != NULL)
    {
        *pHandled = Handled; 
    }

    return hr;

}

HRESULT
UIManager_t::OnTransfer(
    bool*   pHandled
    )
{
    if (pHandled != NULL)
    {
        *pHandled = false; 
    }
    
    CallDisplayItem_t* pSelectedItem = NULL; 
    int                Index; 
    bool               Handled; 
    
    GetSelectedDisplayItem(
        &pSelectedItem, 
        &Index
        ); 
    if (pSelectedItem == NULL)
    {
        return E_UNEXPECTED; 
    }
    
    CallDisplayItemState ItemState = pSelectedItem->GetState();     
    if (ItemState == e_csDialing)
    {
        return S_FALSE;
    }

    CComPtr<Call_t> cpCall; 
    if (FAILED(pSelectedItem->GetCall(&cpCall)))
    {
        return E_UNEXPECTED;
    }

    HRESULT hr = S_OK; 
    
    switch (ItemState)
    {
    case e_csTransferring:
        Handled = true;
        hr = Transfer();
        break;

    case e_csConnected:
        hr = cpCall->DoPhoneVerb(PH_VERB_HOLD);
        if (FAILED(hr))
        {
            ASSERT(FALSE);
            return hr;
        }

        //intentional fall through        
    case e_csHolding:
        hr = pSelectedItem->StartTransferring();        
        RedrawItem(Index);        
        Handled = true;
        break;
        
    default:
        hr = S_FALSE;
        break;
    }

    if (Handled)
    {
        UpdateDialBand();
        UpdateMenuBar(); 
    }

    if (pHandled != NULL)
    {
        *pHandled = Handled; 
    }
    
    return hr;    

}


HRESULT 
UIManager_t::Transfer(
    void
    )
{
    CallDisplayItem_t*  pSelectedItem = NULL; 
    GetSelectedDisplayItem(&pSelectedItem); 
    if (pSelectedItem == NULL)
    {
        return E_UNEXPECTED; 
    }
    
    CComPtr<Call_t> cpCall;     
    HRESULT hr = pSelectedItem->GetCall(&cpCall);
    if (FAILED(hr))
    {
        return hr; 
    }

    WCHAR   DialString[MAX_PATH] = L""; 
    hr = pSelectedItem->GetText(DialString, ARRAYSIZE(DialString));
    if (FAILED(hr))
    {
        return hr; 
    }

    unsigned int DialStringLength; 
    hr = StringCchLength(
            DialString, 
            ARRAYSIZE(DialString), 
            &DialStringLength
            ); 
    if (FAILED(hr) || DialStringLength <= 0)
    {
        return E_UNEXPECTED; 
    }

    ce::auto_bstr TransferToURI; 
    hr = GetApp()->GetDialEngine().GetPhoneNumberToTransfer(
                                    DialString, 
                                    DialStringLength, 
                                    &TransferToURI
                                    ); 

    if (FAILED(hr))
    {
        PHONEAPP_DEBUGMSG(ZONE_PHONEAPP_ERROR, (L"Failed at convert the dial string (%s) to a URI -- hr = 0x%x", DialString, hr)); 
        return hr; 
    }

    return cpCall->DoPhoneVerb(
                        PH_VERB_TRANSFER, 
                        reinterpret_cast<VPARAM>(static_cast<WCHAR*>(TransferToURI))
                        ); 

}


HRESULT 
UIManager_t::StopTransferring(
    void
    )
{
    CallDisplayItem_t*  pSelectedItem   = NULL; 
    int                 ItemIndex       = -1; 
    
    GetSelectedDisplayItem(
        &pSelectedItem, 
        &ItemIndex
        ); 
    if (pSelectedItem == NULL)
    {
        return E_UNEXPECTED; 
    }

    pSelectedItem->StopTransferring(); 

    RedrawItem(ItemIndex); 
    
    return UpdateMenuBar();

}

/*------------------------------------------------------------------------------
    UIManager_t::OnPressAndHold
    
    Handles a press-and-hold keydown event
    
    Parameters:
        : The key being held down
    
    Returns (HRESULT): indicating success or failure
------------------------------------------------------------------------------*/
HRESULT 
UIManager_t::OnPressAndHold(
    UINT VirtualKey
    )
{
    if (! m_Initialized)
    {
        return S_FALSE;
    }

    //we only care about keys 0-9
    if (VirtualKey < L'0' || VirtualKey > L'9')
    {
        return S_FALSE;
    }

    CallDisplayItem_t*  pSelectedItem   = NULL;
    WCHAR               TextString[4]   = L"";
    ce::auto_bstr       UriString;
    
    CComPtr<IVoIPCallerInfoRecord> cpRecord;
    CComPtr<IVoIPCallerInfoDB>     cpDB;
    
    // If there is no DialBand show up, it means that user press and hold
    // at homescreen w/o being hook off or speaker on. Then we go check speed
    // dial directly
    if (!IsShowingDialBand())
    {
        goto CheckSpeedDial;    
    }

    GetSelectedDisplayItem(&pSelectedItem); 
    if (pSelectedItem == NULL)
    {
        return S_FALSE; 
    }

    //if the item is not 'dialing', then we don't attempt to auto-dial
    if (pSelectedItem->GetState() != e_csDialing)
    {
        return S_FALSE;
    }

    //Check that this is the first character in the buffer
    pSelectedItem->GetText(TextString, ARRAYSIZE(TextString));
    if (wcslen(TextString) != 1)
    {
        return S_FALSE;
    }

CheckSpeedDial:

    ce::auto_bstr bstrNumber; 
    HRESULT hr = GetApp()->GetDatabase().GetNumberFromSpeedDialEntry(
                                    VirtualKey - L'0', 
                                    &bstrNumber
                                    ); 
    if (FAILED(hr))
    {
        return S_FALSE; 
    }

    CComPtr<Call_t>    cpCall; 
    hr = GetApp()->Call(
                    bstrNumber, 
                    NULL, 
                    &cpCall
                    ); 
    if (FAILED(hr))
    {
        return S_FALSE; 
    }

    // Only if pItem is not NULL, we do this. 
    // if user press and hold w/o showing dial band, the pItem will be NULL
    if (pSelectedItem)
    {
        pSelectedItem->AssignCall(cpCall);
    }
   
    return S_OK;

}


HRESULT 
UIManager_t::RefreshCallDisplayItems(
    void
    )
{
    int ItemCount = m_ListBox.GetCount(); 

    if (ItemCount == 0)
    {   
        if (m_cpIncomingCall == NULL)
        {
            //close the help message box
            ForceCloseCurrentMessageBox(); 
        }

        //hide the window
        ShowWindow(m_MainDialog, SW_HIDE); 

        //set the flag in registry to indicate the phone app is not active anymore
        PHSetValue(
            phsPhoneAppStatus, 
            PHGetSetting(phsPhoneAppStatus) & ~VOIP_PHONEAPP_ACTIVE_BITMASK
            ); 
    }

    //Redraw the items that are animating: and remove the items that are disconnected
    for (int Index = 0; Index < ItemCount; Index++)
    {
        CallDisplayItem_t*  pCallItem = (CallDisplayItem_t*)m_ListBox.GetItem(Index);
        if (pCallItem == NULL)        
        {
            ASSERT(FALSE);
            continue;
        }

        if (pCallItem->IsAnimated())

⌨️ 快捷键说明

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