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

📄 customlist.h

📁 funambol windows mobile plugin source code, the source code is taken from the funambol site
💻 H
字号:
/*
 * Copyright (C) 2003-2007 Funambol, Inc
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY, TITLE, NONINFRINGEMENT or FITNESS FOR A PARTICULAR
 * PURPOSE.  See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
 * 02111-1307  USA
 */

#if !defined(AFX_CUSTOMLIST_H__3BCE6295_516B_4715_A125_E1A03E26DF40__INCLUDED_)
#define AFX_CUSTOMLIST_H__3BCE6295_516B_4715_A125_E1A03E26DF40__INCLUDED_

#if _MSC_VER >= 1000
#pragma once
#endif // _MSC_VER >= 1000

#define MAXITEMSTRING	256

#define ITEM_STATE_OK 1
#define ITEM_STATE_TO_SYNC 2

#define ANIM_TIMER_OFFSET 500
#define ANIM_ICON_DELAY 250

// unselected pane default bk color (white)
#define LIST_COLOR_BACKGROUND RGB(255,255,255)

//#define LIST_COLOR_SELECTED_ITEM RGB(220,220,255)

// selected pane default bk color
#define LIST_COLOR_SELECTED_ITEM RGB(153, 209, 252) // #99d1fc

// pane text color
#define LIST_COLOR_TEXT RGB(0,0,0)

// sync status text offset for SPH
#define OFFSET_SYNC_STATUS_TEXT_SPH 59

// sync status text offset for PPC
#define OFFSET_SYNC_STATUS_TEXT_PPC 60

#include <afxtempl.h>

/**
 * main window implemented as owner-draw CListCtrl (list) control where each item is a CExtItem,
 *
 */


/**
 * this is an item from the main list, it represents a sync source
 */
class CExtItem
{
protected:
    /**
     * item name as source name (i.e. 'Mail', 'Contacts',..)
     */
    CString itemName;

    /**
     * item status displayed in the right of the source name
     * eg. : '(Last sync failed)', '(Not synchronized)',...
     */
    CString itemStatus;

    /**
     * true if the item(source) is enabled
     */
    bool enabled;

    /**
     * sync source represented by this item (SOURCE_MAIL, SOURCE_BRIEFCASE, ..)
     */
    int id;

    /**
     * source state (ITEM_STATE_OK,  ITEM_STATE_TO_SYNC)
     */
    int itemState;

    /**
     * handle to the item's icon, changes if the item is disabled/enabled
     */
    HICON	hIcon;

    /**
     *  in which phase the anim icon is
     */
    int counterAnim;

    /**
     *  true if this source is currently syncing
     */
    bool bSyncing;

public:
    CExtItem(int _id,CString sItemName,HICON hIcon)
    {
        itemName = sItemName;
        hIcon = hIcon;
        itemState = ITEM_STATE_OK;
        enabled = true;
        id = _id;
        counterAnim = 0;
        bSyncing = false;
    }

    /**
     * accessors
     */
    CString getName() {return itemName;}
    void setName(CString s1) {itemName = s1; }

    CString getText() {return itemStatus;}
    void setText(CString s1) {itemStatus = s1; }

    int getItemState() const { return itemState; }
    void setItemState(int val) { itemState = val; }

    bool isEnabled() const { return enabled; }
    void setEnabled(bool val) { enabled = val; }

    int getId() const { return id; }
    void setId(int val) { id = val; }

    HICON getIcon() const { return hIcon; }
    void setIcon(HICON val) { hIcon = val; }

    int getCounterAnim() const { return counterAnim; }
    void setCounterAnim(int val) { counterAnim = val; }

    bool getIsItemSyncing() const { return bSyncing; }
    void setIsItemSyncing(bool val) { bSyncing = val; }
};
//////////////////////////////////////////////////////////////////////////


/**
 * extension of  CListCtrl UI control,
 * contains an array of CExtItem items (pItemList) with info about each source
 */
class CCustomList : public CListCtrl
{
public:
	CCustomList();

public:
    int  GetCurSelItem() const;
    BOOL SetCurSelItem(int nIndex);

    // sets the default icon for a source
    void resetSourceIcon(int id);

    CExtItem* getItem(int index);
protected:
    void RepaintSelectedItems();

// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CCustomList)
	protected:
	virtual void PreSubclassWindow();
	//}}AFX_VIRTUAL


// Implementation
public:
    virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);
    BOOL GetItemRect(int nItem,LPRECT lpRect, UINT nCode ) const;

	virtual ~CCustomList();

	// Generated message map functions
protected:
	//{{AFX_MSG(CCustomList)
   afx_msg void OnSetFocus(CWnd* pOldWnd);
   afx_msg void OnKillFocus(CWnd* pNewWnd);
   afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
   //afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
   afx_msg LRESULT OnSetFont(WPARAM wParam, LPARAM);

   /**
    * @return : the default width and height for a list item
    */
   afx_msg void MeasureItem ( LPMEASUREITEMSTRUCT lpMeasureItemStruct );

   //afx_msg void OnDrawItem(  int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct);

   /**
    * called when a source is syncing and the sync arrows are spinning,
    * there is a timer for each source sync icon, the source id is (sourceId = nIDEvent - ANIM_TIMER_OFFSET;)
    */
   afx_msg void OnTimer( UINT_PTR nIDEvent );

   /**
    * when repainting by default only the items are redrawn,
    * so here we redraw also the empty space (if any) below the last item
    */
   afx_msg void OnPaint( );

   /**
    * do the same as for  OnPaint
    * @return : TRUE so we disable default processing of the message ( which would lead to excessive redrawing and flickering)
    */
   afx_msg BOOL OnEraseBkgnd(CDC* pDC );


	//}}AFX_MSG
 DECLARE_MESSAGE_MAP()

private:
    /**
     * inits the list by inserting a column
     */
    void Init();

    CBrush brushHollow;
    int nItemHeight, nItemWidth; // item sizes

    /**
     *  true if the items is locked, so the user cannot select any item
     */
    bool locked;

    /**
     * array of CExtItem, holds info about each source item
     */
    CArray<CExtItem *> pItemList;

public:
    CFont fontBold;
    /**
     *  adds a new item to the list, used only on application startup
     */
    void addItem(int id, CString lpszItemName,HICON hIcon);

    void setText(int id, CString text);
    CString getText(int id);
    void setIcon(int id, HICON hIcon);
    void setItemHeight(int height) { nItemHeight = height; }
    int getItemHeight(){return nItemHeight;}
    void setItemWidth(int width)  { nItemWidth = width; }

    /**
     * displays the sync arrows in the <id> source, and starts spinning it
     */
    void startAnim(int id);

    /**
     *  for the <id> source stops the animation, deletes the timer, restore the default icon
     */
    void stopAnim(int id);

    int getState(int id);
    void setState(int id, int state);
    void setStateToAll(int state, bool onlyEnabled = false);
    void enableItem(int id, bool enable);
    bool isEnabledItem(int id);

    /**
     * repaints the <id> source pane
     */
    void InvalidatePane(int id);

    /**
     * conversion between the source id and the index in the list  pItemList
     */
    int indexToId(int index);
    int idToIndex( int id );

    bool doesIdExist(int id);

    void setIsSyncing(int id, bool value);
    bool getIsSyncing(int id);

    /**
     * resets the panes to their default icons
     */
    void resetSourceIcons();

    void lockList(){locked = true;}
    void unlockList() {locked = false;}
    bool getIsLocked() const {return locked;}
};

/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif

⌨️ 快捷键说明

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