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

📄 outlookcontactlist.cpp

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

    TotalItems = 0;
    cpItems->get_Count(&TotalItems);

    switch (type)
    {
    case AddAllItems:
        CurrentItem = 1;
        LastItem    = TotalItems;
        break;

    case AddBeginningOfItems:
        CurrentItem = 1;
        LastItem    = (m_QueryValue.length() == 0 && TotalItems > INITIAL_ITEM_THRESHOLD) ? INITIAL_ITEM_THRESHOLD : TotalItems;
        break;
        
    case AddRestOfItems:
        CurrentItem = INITIAL_ITEM_THRESHOLD + 1;
        LastItem    = TotalItems;
        break;

    default:
        ASSERT(FALSE);
        goto exit;
    }

    for (; CurrentItem <= LastItem; CurrentItem++)
    {
        CComPtr<IContact>     cpContact;
        ce::auto_bstr         FileAs;
        IVoIPDisplayItem*     pItem = NULL;
        IVoIPTextDisplayItem* pTextItem = NULL;
        
        int  HighlightStart = -1;
        int  HighlightEnd;
        LONG Oid = 0;
        
        //get the ith item
        cpItems->Item(CurrentItem, (IDispatch**)&cpContact);

        if (! cpContact)
        {
            ASSERT(FALSE);
            continue;
        }

        //does it match the current filter?
        if (! MatchesFilter(m_Filter, m_QueryValue, m_QueryValue.length(), cpContact, &HighlightStart, &HighlightEnd))
        {
            continue;
        }

        //matches - add it to our list
        cpContact->get_FileAs(&FileAs);
        if (! FileAs)
        {
            continue;
        }

        cpContact->get_Oid(&Oid);
        if (! Oid)
        {
            ASSERT(FALSE);
            continue;
        }
        
        //it matches - create an item for it!
        hr = PHCreateTextDisplayItem(
            FileAs, 
            &pItem
            );
        if (FAILED(hr))
        {
            hr = S_FALSE;
            continue;
        }

        pItem->QueryInterface(IID_IVoIPTextDisplayItem, (void**)&pTextItem);
        if (! pTextItem)
        {
            ASSERT(FALSE);
            delete pItem;
            continue;
        }

        pTextItem->SetCookie(Oid);
        if (HighlightStart != -1)
        {
            pTextItem->SetHighlightIndices(
                HighlightStart, 
                HighlightEnd
                );
        }

        //add it to the list and continue
        hr = m_Listbox.AddItem(-1, pItem);
        if (FAILED(hr))
        {
            hr = S_FALSE;
            delete pItem;
            continue;
        }
    }

    //check if we need to add the rest of the items later...
    if (type == AddBeginningOfItems && LastItem < TotalItems)
    {
        //set a timer to add the rest of the items...
        if (FAILED(StartTimer(AddItemsTimer)))
        {
            //failed! add the rest of the items now!
            Refresh(AddRestOfItems);
            goto exit;
        }
    }

    //update the status header
    StringCchPrintf(
        StatusText, 
        _countof(StatusText),

        CommonUtilities_t::LoadString(
            GlobalData_t::s_ModuleInstance, 
            m_QueryValue[0] == 0 ? IDS_FMT_CONTACTS_ALL : IDS_FMT_CONTACTS_FILTER_MATCHES
            ),

        (LastItem < TotalItems) ? TotalItems : m_Listbox.GetCount()-1
        );

    ZeroMemory(&StatusParams, sizeof(STATUS_HEADER_PARAMETERS_EX)); 
    StatusParams.Instance   = GlobalData_t::s_ModuleInstance;
    StatusParams.ResourceId = 0;
    StatusParams.Priority   = shpDefault;
    StatusParams.Cookie     = 100;
    StatusParams.secTimeout = INFINITE;
    StatusParams.pwszDisplayString = StatusText;
    
    SendMessage(
        m_StatusRegion, 
        WM_STATUSHEADER_ADDSTATUSNOTIFICATION, 
        (WPARAM)sizeof(StatusParams), 
        (LPARAM)&StatusParams
        );

exit:
    //reenable redrawing...
    SendMessage(m_Listbox, WM_SETREDRAW, TRUE, 0);
    return hr;
}

/*------------------------------------------------------------------------------
    OutlookContactListDialog_t::StartTimer
    
    Start a specific timer
------------------------------------------------------------------------------*/
HRESULT
OutlookContactListDialog_t::StartTimer(
    TimerType_e type
    )
{
    //kill any outstanding timer for this class...
    StopTimer(type);

    switch (type)
    {
    case AddItemsTimer:
        m_AddItemsTimer = SetTimer(m_Dialog, 100 + AddItemsTimer, ADD_REST_OF_ITEMS_DELAY, NULL);
        if (! m_AddItemsTimer)
        {
            return CommonUtilities_t::GetErrorFromWin32();
        }

        return S_OK;

    case UserResponseTimer:
        m_UserResponseTimer = SetTimer(m_Dialog, 100 + UserResponseTimer, USER_RESPONSE_DELAY, NULL);
        if (! m_UserResponseTimer)
        {
            return CommonUtilities_t::GetErrorFromWin32();
        }

        return S_OK;

    default:
        ASSERT(FALSE);
        return E_UNEXPECTED;
    }
}

/*------------------------------------------------------------------------------
    OutlookContactListDialog_t::StopTimer
    
    Stop one of our timers
------------------------------------------------------------------------------*/
void
OutlookContactListDialog_t::StopTimer(
    TimerType_e type
    )
{
    int IdToKill = 0;
    
    switch (type)
    {
    case AddItemsTimer:
        IdToKill = m_AddItemsTimer;
        m_AddItemsTimer = 0;
        break;
        
    case UserResponseTimer:
        IdToKill = m_UserResponseTimer;
        m_UserResponseTimer = 0;
        break;

    default:
        ASSERT(FALSE);
        break;
    }

    if (IdToKill)
    {
        KillTimer(m_Dialog, IdToKill);
    }

    return;
}

/*------------------------------------------------------------------------------
    OutlookContactListDialog_t::OnTimer
    
    Handle one of our timers expiring
------------------------------------------------------------------------------*/
HRESULT 
OutlookContactListDialog_t::OnTimer(
    UINT TimerId
    )
{
    if (! TimerId)
    {
        ASSERT(FALSE);
        return E_UNEXPECTED;
    }
    
    if (TimerId == m_AddItemsTimer)
    {
        //stop the timer
        StopTimer(AddItemsTimer);
        
        //add the rest of the items to the listbox...
        return Refresh(AddRestOfItems);
    }
    else if (TimerId == m_UserResponseTimer)
    {
        //stop the timer
        StopTimer(UserResponseTimer);

        //refresh the display (completely)
        return Refresh(AddAllItems);
    }

    return E_FAIL;
}

/*------------------------------------------------------------------------------
    OutlookContactListDialog_t::UpdateFilter
    
    Update the filter due to a user request
------------------------------------------------------------------------------*/
HRESULT 
OutlookContactListDialog_t::UpdateFilter(
    Filter_e NewFilter
    )
{
    if (m_Filter == NewFilter)
    {
        return S_FALSE;
    }

    m_Filter = NewFilter;

    //if we haven't filtered anything out then we can simply update the label...
    IVoIPDisplayItem* pItem = m_Listbox.GetItem(0);
    if (! pItem)
    {
        //no items! - nothing to do...
        return S_FALSE;
    }

    //update the label
    UpdateEditItem();

    //no text - no need to refresh...
    if (! m_QueryValue[0])
    {
        return S_FALSE;
    }

    //reset the filter and refresh the whole dialog
    pItem->SetText(m_QueryValue);

    return Refresh();
}

/*------------------------------------------------------------------------------
    OutlookContactListDialog_t::UpdateEditItem
    
    Update the labeled edit display item that heads off this dialog
------------------------------------------------------------------------------*/
HRESULT
OutlookContactListDialog_t::UpdateEditItem()
{
    //get item 0
    IVoIPDisplayItem*  pItem = m_Listbox.GetItem(0);
    if (! pItem)
    {
        return E_FAIL;
    }

    //get the label interface from the item
    IVoIPLabeledEditDisplayItem* pLabelItem = NULL;
    pItem->QueryInterface(IID_IVoIPLabeledEditDisplayItem, (void**)&pLabelItem);

    if (! pLabelItem)
    {
        ASSERT(FALSE);
        return E_UNEXPECTED;
    }

    //update the label text
    HRESULT hr = pLabelItem->SetLabelText(
        CommonUtilities_t::LoadString(GlobalData_t::s_ModuleInstance, FilterToLabelId(m_Filter))
        );
    if (FAILED(hr))
    {
        ASSERT(FALSE);
        return hr;
    }

    //set or unset numbers only
    pLabelItem->SetNumbersOnly(m_Filter == Predictive);

    RECT ItemRect = {0};

    //force it to redraw
    m_Listbox.GetItemRect(0, &ItemRect);
    InvalidateRect(m_Listbox, &ItemRect, FALSE);

    UpdateQueryString();
    
    return S_OK;
}

/*------------------------------------------------------------------------------
    OutlookContactListDialog_t::OnSelectionChange
    
    Update the menu bar on selection changes
------------------------------------------------------------------------------*/
HRESULT
OutlookContactListDialog_t::OnSelectionChange()
{
    int SelectedIndex = m_Listbox.GetCurSel();
    int MenuId;
    
    if (SelectedIndex == 0)
    {
        MenuId = IDMB_OUTLOOKCONTACTLIST;
    }
    else
    {
        MenuId = IDMB_CONTACTSITEM;
    }

    if (MenuId == m_CurrentMenuId)
    {
        return S_OK;
    }

    m_CurrentMenuId = MenuId;
    
    HRESULT hr = m_MenuBar.SetMenu(
        GlobalData_t::s_ModuleInstance, 
        MenuId
        );

    if (SelectedIndex == 0)
    {
        UpdateQueryString();
    }

    return hr;
}

HRESULT
OutlookContactListDialog_t::GetSelectedContact(
    IContact** ppContact
    )
{
    ASSERT(ppContact);

    *ppContact = NULL;
    
    //get the OID (cookie) from the item - look up the contact...dial it!
    int SelectedIndex = m_Listbox.GetCurSel();
    if (SelectedIndex <= 0)
    {
        ASSERT(FALSE);
        return E_FAIL;
    }
    
    IVoIPDisplayItem* pItem = m_Listbox.GetItem(SelectedIndex);
    if (! pItem)
    {
        ASSERT(FALSE);
        return E_FAIL;
    }

    IVoIPTextDisplayItem* pTextItem = NULL;

    pItem->QueryInterface(
        IID_IVoIPTextDisplayItem, 
        (void**)&pTextItem
        );
    if (! pTextItem)
    {
        ASSERT(FALSE);
        return E_FAIL;
    }

    UINT Oid = pTextItem->GetCookie();
    if (! Oid)
    {
        ASSERT(FALSE);
        return E_FAIL;
    }

    return m_cpOutlookApp->GetItemFromOid(Oid, (IDispatch**)ppContact);
}

HRESULT OutlookContactListDialog_t::OnDial()
{
    CComPtr<IContact>   cpContact;

    HRESULT hr = GetSelectedContact(&cpContact);
    if (FAILED(hr))
    {
        return hr;
    }

    //
    //  Get the phone number.
    //
    ce::auto_bstr PhoneNumber;
    do
    {
        cpContact->get_BusinessTelephoneNumber(&PhoneNumber);
        if (PhoneNumber != NULL && PhoneNumber[0] != 0)
        {
            break;
        }

        PhoneNumber = NULL;
        cpContact->get_MobileTelephoneNumber(&PhoneNumber);
        if (PhoneNumber != NULL && PhoneNumber[0] != 0)
        {
            break;
        }

        PhoneNumber = NULL;
        cpContact->get_HomeTelephoneNumber(&PhoneNumber);
        if (PhoneNumber != NULL && PhoneNumber[0] != 0)
        {
            break;
        }

        return E_FAIL;
    }
    while (0);
        
    PH_MAKEPHONECALL_PARAMETERS Params = {0};
    Params.StructSize = sizeof(Params);

    StringCchCopy(
        Params.DestAddress,
        _countof(Params.DestAddress),
        PhoneNumber
        );

    //
    //  Get the Name, ignore errors.
    //
    ce::auto_bstr Name;
    hr = cpContact->get_FileAs(&Name);
    if (SUCCEEDED(hr) && Name != NULL && Name[0] != 0)
    {
        StringCchCopy(
            Params.CalledParty,
            _countof(Params.CalledParty),
            Name
            );
    }
    
    return PHMakePhoneCall(&Params);
}

/*------------------------------------------------------------------------------
    OutlookContactListDialog_t::OnDetails
    
    Enter the details screen with this contact's data
------------------------------------------------------------------------------*/
HRESULT
OutlookContactListDialog_t::OnDetails()
{
    CComPtr<IContact> cpContact = NULL;

    HRESULT hr = GetSelectedContact(&cpContact);
    if (FAILED(hr))
    {
        ASSERT(FALSE);
        return hr;
    }

    return PhInfoGlobalData_t::pPhInfoApp->CreateDetailsScreen(
        InfoApp_t::IdOutlookContactDetailsDialog,
        cpContact
        );
}


HRESULT
OutlookContactListDialog_t::UpdateQueryString()
{
    IVoIPDisplayItem* pItem = m_Listbox.GetItem(0);
    if (! pItem)
    {
        ASSERT(FALSE);
        return E_FAIL;
    }
    
    WCHAR Buffer[MAX_PATH];
    HRESULT hr = pItem->GetText(
        Buffer, 
        _countof(Buffer)
        );
    if (FAILED(hr))
    {
        return hr;
    }

    if(!m_QueryValue.assign(Buffer))
    {
        return E_OUTOFMEMORY;
    }   

    m_MenuBar.ShowMenuButton(
        IDC_BACKSPACE, 
        m_QueryValue[0] != 0
        );

    return S_OK;
}

⌨️ 快捷键说明

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