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

📄 customlist.cpp

📁 funambol window mobile客户端源代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
}

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 ){

    if (nIDEvent == MAIN_LOGO_ID) {
        // It's the main logo, manage it separately.
        animateMainLogo();
        return;
    }

    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);
    
    // Redraw the logo on the right 
    // We need to calculate again the main logo position, as it could
    // be changed from Init (it happens on square smartphone)
    calculateMainLogoPosition();
    updateMainLogoImage();
}

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;
    }
}

              


/**
 * Animates the main logo.
 * The internal counter is updated, and then the image is refreshed.
 */
void CCustomList::animateMainLogo() {
    
    if (!mainLogo) {
        return;
    }

    mainLogoCounter++;
    if(mainLogoCounter == MAIN_LOGO_NUM_FRAMES){
        mainLogoCounter = 0;
    }

    //Invalidate();
    InvalidateRect(&mainLogoRect);
    updateMainLogoImage();
}


/**
 * Updates the main logo image:
 * - calculates the image section to redraw (depends on 'mainLogoCounter')
 * - draws the image to the screen
 */
void CCustomList::updateMainLogoImage() {

    if (!mainLogo) {
        return;
    }

    // Get the effective image section to be drawn
    CPaintDC dc(this);
    int xOffset = mainLogoCounter * mainLogoSize.cx;
    RECT offsetRc = {xOffset, 0, xOffset + mainLogoSize.cx, mainLogoSize.cy};

    mainLogo->Draw(dc.GetSafeHdc(), &mainLogoRect, &offsetRc);
}


/**
 * Initializes the main logo image.
 * The image 'mainLogo' will be loaded only if it's a portal build AND 
 * the file 'MAIN_LOGO_NAME' is found under the install dir.
 * If it's not a portal build or file not found, no image will be loaded and
 * 'mainLogo' member is NULL.
 * 
 * - gets the full path of the image file
 * - loads the image file and stores it to the internal member 'mainLogo'
 * - calculates the rect where image will be drawn, and real logo dimension
 */
void CCustomList::initMainLogo() {

    ClientSettings* cs = getRegConfig();
    if (cs->getBrandingParams().getShowBriefcaseSource() ||
        cs->getBrandingParams().getShowNoteSource() ) {    
        // need that also with only 1 source set the logo cannot be 
        // properly displayed
        // if(cs->getIsPortal() == false) {
        mainLogo = NULL;
        return;
    }

    // Get the image full path
    string imageName = cs->getAppPath();
    imageName += "\\";
    imageName += MAIN_LOGO_NAME;
    WCHAR* wImageName = toWideChar(imageName.c_str());

    // Create the imaging factory.
    IImagingFactory *pImgFactory = NULL;          
    CoInitializeEx(NULL, COINIT_MULTITHREADED);
    if (SUCCEEDED(CoCreateInstance (CLSID_ImagingFactory, NULL, CLSCTX_INPROC_SERVER, IID_IImagingFactory, (void **)&pImgFactory))) {        
        pImgFactory->CreateImageFromFile(wImageName, &mainLogo);
        pImgFactory->Release();
    }
    if (wImageName) { 
        delete [] wImageName; wImageName = NULL;
    }

    if (mainLogo) {
        // Image found: calculate position and size
        calculateMainLogoPosition();

        // Set the logo dimension: mainLogoSize
        SIZE imageSize;
        mainLogo->GetPhysicalDimension(&imageSize);
        mainLogoSize.cx = imageSize.cx / MAIN_LOGO_NUM_FRAMES;
        mainLogoSize.cy = imageSize.cy;
    }
    else {
        // No image found!
        CoUninitialize();
        mainLogoRect.bottom = mainLogoRect.top = 0;
        mainLogoRect.left = mainLogoRect.right = 0;
        mainLogoSize.cx = mainLogoSize.cy = 0;
    }
}



/**
 * Gets the rectangle for the main logo (mainLogoRect) and the
 * effective logo dimension (mainLogoSize) from the current 
 * main screen size.
 * They're always the same, so this method is called at the
 * beginning or if the screen size changes.
 */
void CCustomList::calculateMainLogoPosition() {

    if (!mainLogo) {
        return;
    }

    CPaintDC dc(this);
    CRect rect;
    GetClientRect(&rect);
    mainLogoRect.left   = rect.Width()  - MAIN_LOGO_LEFT_CORNER;
    mainLogoRect.right  = rect.Width()  - MAIN_LOGO_RIGHT_CORNER;
    mainLogoRect.top    = rect.Height() - MAIN_LOGO_UPPER_CORNER;    
    mainLogoRect.bottom = rect.Height() - MAIN_LOGO_LOWER_CORNER;

    // Correction of logo dimensions: if logo overlaps the last item pane,
    // we decrease the logo size to fill only the white area at the bottom.
    int count = GetItemCount();
    if (count > 0) {
        CRect rectLastItem;
        GetItemRect(count-1, &rectLastItem, LVIR_BOUNDS);
        if (mainLogoRect.top < rectLastItem.bottom) {
            mainLogoRect.left += (rectLastItem.bottom - mainLogoRect.top);
            mainLogoRect.top = rectLastItem.bottom;
        }
    }

    // Avoid drawing logo if it's too small...
    if ((mainLogoRect.bottom - mainLogoRect.top) < 10) {
        mainLogoRect.bottom = mainLogoRect.top = 0;
        mainLogoRect.left = mainLogoRect.right = 0;
    }
}





/**
 * Starts the timer for the main logo animation.
 * 'OnTimer(MAIN_LOGO_ID)' will be called every MAIN_LOGO_DELAY milliseconds.
 */
void CCustomList::startMainLogo() {
    if (!mainLogo) {
        return;
    }
    if (MAIN_LOGO_USE_ANIMATION) {
        SetTimer(MAIN_LOGO_ID, MAIN_LOGO_DELAY, NULL);
        isMainLogoAnimated = true;
    }
}


/**
 * Kills the timer for the main logo animation.
 */
void CCustomList::stopMainLogo() {
    if (!mainLogo) {
        return;
    }
    if (MAIN_LOGO_USE_ANIMATION) {
        if (KillTimer(MAIN_LOGO_ID)) {
            isMainLogoAnimated = false;
        }
    }
}

⌨️ 快捷键说明

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