customlist.h

来自「funambol window mobile客户端源代码」· C头文件 代码 · 共 367 行

H
367
字号
/*
 * Funambol is a mobile platform developed by Funambol, Inc. 
 * 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 Affero General Public License version 3 as published by
 * the Free Software Foundation with the addition of the following permission
 * added to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED
 * WORK IN WHICH THE COPYRIGHT IS OWNED BY FUNAMBOL, FUNAMBOL DISCLAIMS THE
 * WARRANTY OF NON INFRINGEMENT  OF THIRD PARTY RIGHTS.
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 
 * details.
 * 
 * You should have received a copy of the GNU Affero General Public License
 * along with this program; if not, see http://www.gnu.org/licenses or write to
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 * MA 02110-1301 USA.
 * 
 * You can contact Funambol, Inc. headquarters at 643 Bair Island Road, Suite
 * 305, Redwood City, CA 94063, USA, or at email address info@funambol.com.
 * 
 * The interactive user interfaces in modified source and object code versions
 * of this program must display Appropriate Legal Notices, as required under
 * Section 5 of the GNU Affero General Public License version 3.
 * 
 * In accordance with Section 7(b) of the GNU Affero General Public License
 * version 3, these Appropriate Legal Notices must retain the display of the
 * "Powered by Funambol" logo. If the display of the logo is not reasonably
 * feasible for technical reasons, the Appropriate Legal Notices must display
 * the words "Powered by Funambol".
 */

#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

#define MAIN_LOGO_USE_ANIMATION     1                   /**< Set to 0 to disable animation */
#define MAIN_LOGO_ID                700                 /**< The unique ID for the main logo timer */
#define MAIN_LOGO_DELAY             100                 /**< The delay for the main logo timer [milliseconds] */
#define MAIN_LOGO_NAME              "mainLogo.gif"      /**< The main logo file name */
#define MAIN_LOGO_NUM_FRAMES        20                  /**< The main logo total # of frames */

                                                        // mainLogo is 60x60 pixel
#define MAIN_LOGO_UPPER_CORNER      70                  /**< The main logo distance of upper corner */
#define MAIN_LOGO_LOWER_CORNER      10                  /**< The main logo distance of lower corner */
#define MAIN_LOGO_LEFT_CORNER       80                  /**< The main logo distance of left corner */
#define MAIN_LOGO_RIGHT_CORNER      20                  /**< The main logo distance of right corner */


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

#include <afxtempl.h>
#include "imaging.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();
    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)

	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;


    
    /**
     * The main logo image.
     */
    IImage* mainLogo;

    /// Counter for the main logo: indicates the frame# to be showed.
    int mainLogoCounter;

    /// The rectangle on UI where main logo is shown.
    RECT mainLogoRect;

    /// The main logo real size of each frame (0.01mm units)
    SIZE mainLogoSize;

    /// true if main logo animation is running
    bool isMainLogoAnimated;




    /**
     * return the offset between the name of the source and the status
     */
    int GetTextOffSet();

    /**
     * Manages the animation of main logo: refresh the image based on
     * the internal counterAnim of CExtItem.
     */
    void animateMainLogo();
    void updateMainLogoImage();


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

    void initMainLogo();
    void calculateMainLogoPosition();
    void startMainLogo();
    void stopMainLogo();

};

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

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

#endif

⌨️ 快捷键说明

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