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

📄 customlist.cpp

📁 funambol windows mobile plugin source code, the source code is taken from the funambol site
💻 CPP
📖 第 1 页 / 共 2 页
字号:
    // if the list is locked we ignore the message
    if(locked)
        return;

    // try to see if this item is selected for the 2nd time
    int oldSel, newSel;
    oldSel = GetCurSelItem();
    Default(); // call default message handler
    newSel = GetCurSelItem();

    CRect rect; GetItemRect(newSel, &rect, LVIR_BOUNDS);

    if( (rect.PtInRect(point)) &&  (newSel == oldSel) ){
        CWnd* wndMain = AfxGetMainWnd();
        if(wndMain)
            ((CuiDlg*)wndMain)->SelectSource(newSel);
    }

    // clears non-item part of list
    Invalidate();
}

void CCustomList::setText(int id, CString text ){
    CString s1;
    s1+= "("; s1+=text;
    s1+=")";

    CExtItem* pItem = getItem(id);
    if(pItem){
        pItem->setText(s1);
        InvalidatePane(id);
    }
}

CString CCustomList::getText(int id){
    CExtItem* pItem = getItem(id);

    if(pItem){
        return pItem->getText();
    }

    return CString("");
}

void CCustomList::enableItem( int id, bool enable ){
    CExtItem* pItem = getItem(id);
    pItem->setEnabled(enable);
}

void CCustomList::setState( int id, int state ){
    CExtItem* item = getItem(id);
    if(item){
        item->setItemState(state);
    }
}

void CCustomList::InvalidatePane( int id ){
    CRect rect;
    GetItemRect(idToIndex(id),rect,LVIR_BOUNDS);
    InvalidateRect(rect);
}

void CCustomList::setIcon( int id, HICON hIcon ){
    CExtItem* pItem = getItem(id);
    if(pItem){
        pItem->setIcon(hIcon);
    }
}

void CCustomList::startAnim(int id){
    this->SetTimer(id + ANIM_TIMER_OFFSET, ANIM_ICON_DELAY, NULL);
}

void CCustomList::stopAnim(int id){
    CExtItem* pItem = getItem(id);

    this->KillTimer(id + ANIM_TIMER_OFFSET);
    resetSourceIcon(id);
}

bool CCustomList::isEnabledItem( int id ){
    CExtItem* pItem = getItem(id);
    if(pItem){
        return pItem->isEnabled();
    }
    return false;
}

int CCustomList::getState( int id ){
    CExtItem* pItem = getItem(id);
    if(pItem){
        return pItem->getItemState();
    }

    return 1; // state_ok default
}

void CCustomList::setStateToAll( int state, bool onlyEnabled /*= false*/ )
{
    for (int i=0;i<=pItemList.GetUpperBound(); i++){
        CExtItem* pItem = pItemList.GetAt(i);
        if(pItem){
            if(onlyEnabled) {
                if(pItem->isEnabled()){
                    pItem->setItemState(state);
                }
            }
            else{
                pItem->setItemState(state);
            }
        }
    }
}


void CCustomList::MeasureItem(LPMEASUREITEMSTRUCT lpMIS)
{
    lpMIS->itemHeight  = nItemHeight;
    lpMIS->itemWidth   = nItemWidth;
}


LRESULT CCustomList::OnSetFont(WPARAM wParam, LPARAM)
{
    LRESULT res =  Default();

    CRect rc;
    GetWindowRect( &rc );

    WINDOWPOS wp;
    wp.hwnd = m_hWnd;
    wp.cx = rc.Width();
    wp.cy = rc.Height();
    wp.flags = SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOZORDER;
    SendMessage( WM_WINDOWPOSCHANGED, 0, (LPARAM)&wp );

    return res;
}


void CCustomList::addItem(int id, CString lpszItemName,HICON hIcon)
{
    CExtItem* pItem = new CExtItem(id, lpszItemName,hIcon);
    pItemList.Add(pItem);

    InsertItem(GetItemCount(), lpszItemName);
}

CExtItem* CCustomList::getItem( int id ){
    int i=0;
    while(i<pItemList.GetCount()){
        if(pItemList.GetAt(i)->getId() == id){
            return pItemList.GetAt(i);
        }
        i++;
    }

    return NULL; // should not get here
}


void CCustomList::OnTimer(UINT_PTR nIDEvent ){
    int sourceId = nIDEvent - ANIM_TIMER_OFFSET;

    if(!doesIdExist(sourceId))
        return;

    CExtItem* pItem = getItem(sourceId);
    if(pItem == NULL)
        return;

    int counter = pItem->getCounterAnim();

    if(counter == 4){
        counter = 0;
    }

    switch(counter){
    case 0:
    this->setIcon(sourceId, AfxGetApp()->LoadIcon(IDI_ARROWS22A));
    break;
    case 1:
    this->setIcon(sourceId, AfxGetApp()->LoadIcon(IDI_ARROWS22B));
    break;
    case 2:
    this->setIcon(sourceId, AfxGetApp()->LoadIcon(IDI_ARROWS22C));
    break;
    case 3:
    this->setIcon(sourceId, AfxGetApp()->LoadIcon(IDI_ARROWS22D));
    break;
    };

    counter++;

    pItem->setCounterAnim(counter);
    InvalidatePane(sourceId);
}

void CCustomList::resetSourceIcon( int id ){
    int iconId = -1;
    bool isItemEnabled = isEnabledItem(id);

    switch(id){
        case SOURCE_MAIL:
            iconId = isItemEnabled ? IDI_MAIL : IDI_MAIL_DIM; break;
        case SOURCE_CONTACTS:
            iconId = isItemEnabled ? IDI_CONTACTS : IDI_CONTACTS_DIM; break;
        case SOURCE_CALENDAR:
            iconId = isItemEnabled ? IDI_CALENDAR : IDI_CALENDAR_DIM; break;
        case SOURCE_TASKS:
            iconId = isItemEnabled ? IDI_TASKS : IDI_TASKS_DIM; break;
        case SOURCE_BRIEFCASE:
            iconId = isItemEnabled ? IDI_BRIEFCASE : IDI_BRIEFCASE_DIM; break;

        #if defined(WIN32_PLATFORM_PSPC)
            case SOURCE_NOTES:
                iconId = isItemEnabled ? IDI_NOTES : IDI_NOTES_DIM; break;
        #endif
    }

    if(iconId != -1)
        setIcon(id, AfxGetApp()->LoadIcon(iconId));
}

int CCustomList::indexToId( int index ){
    if(index < 0){
        return 0;
        // TODO: signal error
    }
    CExtItem* item = pItemList.GetAt(index);
    if(item){
        return item->getId();
    }

    return 0;
}

int CCustomList::idToIndex( int id ){
    CExtItem* pItem;
    int i = 0;
    int index = 0;

    while(i <= pItemList.GetUpperBound() ){
        pItem = pItemList.GetAt(i);
        if(pItem){
            if(pItem->getId() == id){
                index = i;
            }
        }
       i++;
    }

    return index;
}


void CCustomList::resetSourceIcons(){
    for(int i=0;i<GetItemCount();i++)
        resetSourceIcon(indexToId(i));
}



void CCustomList::setIsSyncing( int id, bool value ){
    CExtItem* item = getItem(id);
    if(item){
        item->setIsItemSyncing(value);
    }
}

bool CCustomList::getIsSyncing( int id ){
    CExtItem* item = getItem(id);
    if(item){
        return item->getIsItemSyncing();
    }

    return false;
}

void CCustomList::OnPaint(){
    // call default handler to redraw items if needed
    Default();

    // now we repaint area in which there are no items
    CPaintDC dc(this);
    CRect rect, rectLastItem;
    // get client area
    GetClientRect(&rect);

    // get last item area
    int count = GetItemCount();
    GetItemRect(count-1, &rectLastItem, LVIR_BOUNDS);

    // fill the area below the last item
    dc.FillSolidRect(0, rectLastItem.BottomRight().y, rect.Width(),
        rect.Height()-rectLastItem.BottomRight().y, LIST_COLOR_BACKGROUND);
}

BOOL CCustomList::OnEraseBkgnd( CDC* pDC ){
    // we disable automatic redrawing of list background

    // now we repaint area in which there are no items
    CRect rect, rectLastItem;
    CDC tempdc; tempdc.CreateCompatibleDC(pDC);
    CBitmap bmpTemp;

    // get client area
    GetClientRect(&rect);

    int nSavedDC = pDC->SaveDC();

    // get last item area
    int count = GetItemCount();
    GetItemRect(count-1, &rectLastItem, LVIR_BOUNDS);

    CRect rectDraw(0, rectLastItem.BottomRight().y, rect.Width(), rect.Height()-rectLastItem.BottomRight().y);
    tempdc.SetBkMode(TRANSPARENT);

    bmpTemp.CreateCompatibleBitmap(&tempdc, rectDraw.Width(), rectDraw.Height());
    HBITMAP pOldBitmap = (HBITMAP) tempdc.SelectObject(bmpTemp);

    // fill the area below the last item
    tempdc.FillSolidRect(0, rectLastItem.BottomRight().y, rect.Width(),
        rect.Height()-rectLastItem.BottomRight().y, LIST_COLOR_BACKGROUND);

    // bitblt into pDC
    pDC->BitBlt(rectDraw.TopLeft().x, rectDraw.TopLeft().y, rectDraw.Width(),
        rectDraw.Height(), &tempdc, rectDraw.TopLeft().x,rectDraw.TopLeft().y,SRCCOPY);

    tempdc.SelectObject(pOldBitmap);
    bmpTemp.DeleteObject();

    tempdc.DeleteDC();

    return TRUE;
}

BOOL CCustomList::GetItemRect( int nItem,LPRECT lpRect, UINT nCode ) const{
    CListCtrl::GetItemRect(nItem, lpRect, nCode);
    lpRect->right = nItemWidth;

    return 0;
}

bool CCustomList::doesIdExist( int id ){
    CExtItem* pItem;
    int i = 0;
    int index = -1;

    while(i <= pItemList.GetUpperBound() ){
        pItem = pItemList.GetAt(i);
        if(pItem){
            if(pItem->getId() == id){
                index = i;
            }
        }
        i++;
    }

    if(index == -1){
        return false;
    }
    else{
        return true;
    }
}

⌨️ 快捷键说明

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