bitmap_tree.h

Go to the documentation of this file.
00001 #ifndef BITMAP_TREE_CLASS
00002 #define BITMAP_TREE_CLASS
00003 
00004 /*****************************************************************************\
00005 *                                                                             *
00006 *  Name   : bitmap_tree                                                       *
00007 *  Author : see article                                                       *
00008 *  Mods   : Chris Koeritz                                                     *
00009 *                                                                             *
00010 *  Purpose:                                                                   *
00011 *                                                                             *
00012 *    Provides a tree control that is specialized for displaying bitmaps at    *
00013 *  the tree nodes.                                                            *
00014 *                                                                             *
00015 *******************************************************************************
00016 * Copyright (c) 1998-$now By Author.  This program is free software; you can  *
00017 * redistribute it and/or modify it under the terms of the GNU General Public  *
00018 * License as published by the Free Software Foundation; either version 2 of   *
00019 * the License or (at your option) any later version.  This is online at:      *
00020 *     http://www.fsf.org/copyleft/gpl.html                                    *
00021 * Please send any updates to: fred@gruntose.com                               *
00022 \*****************************************************************************/
00023 
00024 #include "mfc_dll.h"
00025 
00026 #include <afxcmn.h>
00027 
00028 // forward.
00029 class bitmap_tree;
00030 
00031 typedef bool (*TREE_CALLBACK)(bitmap_tree *, HTREEITEM, LPARAM);
00032 
00033 class MFC_EXTENSIONS_CLASS_STYLE bitmap_tree : public CTreeCtrl
00034 {
00035 public:
00036   bitmap_tree();
00037   virtual ~bitmap_tree();
00038 
00039   // parameter setting...
00040 
00041   int  SetNormalImages(UINT bitmap, int number, COLORREF mask);
00042   int  SetOverlayImages(UINT bitmap, COLORREF mask);
00043   int  SetStateImages(UINT bitmap, int number, COLORREF mask);
00044   void SetSortFunction(PFNTVCOMPARE func, LPARAM l);
00045   void SetDocumentSortFunction(int offset);
00046   void SetExpandable(int base);
00047   void SetDraggable(int base);
00048   void SetDropTarget(int base);
00049   void SetMultiSelect(bool b = true);
00050   void SetDrag(TREE_CALLBACK func, UINT bitmap= 0, COLORREF mask= 0);
00051   void SetSelChange(bool b) { m_canChangeSel= b; }
00052 
00053   // parameter access
00054 
00055   int ItemOffset() const { return m_itemOffset; }
00056 
00057   int GetNormalImageCount()
00058       { return m_ilNormal.m_hImageList ? (m_ilNormal.GetImageCount()
00059             - m_numOverlays) : 0; }
00060 
00061   bool GetOverlayImageCount() { return m_numOverlays != 0; }
00062 
00063   int GetStateImageCount()
00064       { return m_ilState.m_hImageList? m_ilState.GetImageCount() : 0; }
00065   bool IsSelected(HTREEITEM h)
00066       { return TVIS_SELECTED & GetItemState(h, TVIS_SELECTED); }
00067   bool AreMultiSelected() { return m_multiSet && m_multiSelected;}
00068   bool IsExpandable(int base);
00069   virtual bool IsDraggable(HTREEITEM, int base);
00070   virtual bool IsDropTarget(HTREEITEM, int base);
00071 
00072   // operations
00073   void SetExpandImage(HTREEITEM hitem, bool expand);
00074   HTREEITEM GetItemUnderMouse(TV_HITTESTINFO *t= NULL);
00075   void ToggleTree(UINT code, HTREEITEM hitem= NULL);
00076   void SortTree(HTREEITEM hitem= NULL);
00077 
00078   // selection functions
00079   bool DoForAllSelected(TREE_CALLBACK func, HTREEITEM hitem, LPARAM l);
00080   bool DoForAll(TREE_CALLBACK func, HTREEITEM hitem, LPARAM l);
00081   void ClearMultiSelect();
00082   void SelectAnotherItem(HTREEITEM h, bool select);
00083   void SelectRange(HTREEITEM h1, HTREEITEM h2);
00084 
00085 // ugly macros to be cleaned up.
00086   #define STATE_IMAGE_MASK_TO_INDEX(n) ((n) >> 12)
00087   #define OVERLAY_MASK_TO_INDEX(n) ((n) >> 8)
00088 
00089   // overlay info
00090   int GetOverlayInfo(HTREEITEM hitem)
00091       { return OVERLAY_MASK_TO_INDEX(GetItemState(hitem, TVIS_OVERLAYMASK)); }
00092 
00093   // state info
00094   int GetStateImageInfo(HTREEITEM hitem)
00095       { return STATE_IMAGE_MASK_TO_INDEX(GetItemState(hitem,
00096             TVIS_STATEIMAGEMASK)); }
00097 
00098   // starts and stops the "drag while scrolling" timer.
00099   void start_timer();
00100   void stop_timer();
00101 
00102   // handy callbacks that are provided by the bitmap_tree implementation.
00103   static bool MoveTreeItemCB(bitmap_tree *bt, HTREEITEM h, LPARAM l);
00104   static bool ClearSelection(bitmap_tree *bt, HTREEITEM h, LPARAM l);
00105   static bool PrepareDrag(bitmap_tree *bt, HTREEITEM h, LPARAM l);
00106   static int CALLBACK NodeTypeCompare(LPARAM lParam1, LPARAM lParam2,
00107            LPARAM lParamSort);
00108 
00109 protected:
00110   DECLARE_MESSAGE_MAP()
00111 
00112   void SetOverlayInfo(HTREEITEM hitem, int image)
00113       { SetItemState(hitem, INDEXTOOVERLAYMASK(image), TVIS_OVERLAYMASK); }
00114   void SetStateImageInfo(HTREEITEM hi, int image)
00115       { SetItemState(hi, INDEXTOSTATEIMAGEMASK(image), TVIS_STATEIMAGEMASK); }
00116 
00117   virtual BOOL OnExpanded(NMHDR *pNMHDR, LRESULT *pResult);
00118   virtual BOOL OnSelChanging(NMHDR *pNMHDR, LRESULT *pResult);
00119   virtual BOOL OnClick(NMHDR *pNMHDR, LRESULT *pResult);
00120   virtual BOOL OnKey(NMHDR* pNMHDR, LRESULT* pResult);
00121 //  virtual BOOL OnRClick(NMHDR *pNMHDR, LRESULT *pResult);
00122   virtual BOOL OnDoubleClick(NMHDR *pNMHDR, LRESULT *pResult);
00123   virtual BOOL OnBeginDrag(NMHDR* pNMHDR, LRESULT* pResult);
00124   virtual BOOL OnDelete(NMHDR* pNMHDR, LRESULT* pResult);
00125   afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
00126   afx_msg void OnMouseMove(UINT nFlags, CPoint point);
00127   afx_msg void OnTimer(UINT nIDEvent);
00128 
00129 private:
00130   enum OverlayImages { m_overlay1=1, m_overlay2, m_overlay3, m_overlay4 };
00131   int m_numOverlays;
00132   int m_itemOffset;
00133 
00134   // images
00135   CSize m_sNormalImage, m_sStateImage;
00136   CImageList m_ilNormal, m_ilState;
00137   int m_toggle;
00138   bool m_overlaySet, m_multiSet;
00139 
00140   // multiple selection
00141   bool m_multiSelected, m_canChangeSel;
00142   HTREEITEM m_lastSelected, m_postSelect;
00143   UINT m_firstKey;
00144 
00145   // sorting
00146   TV_SORTCB m_sortcb;
00147 
00148   // dragging
00149   CImageList m_ilDrag, *m_dragList;
00150   TREE_CALLBACK m_dragFunction;
00151   int m_draggable, m_dropTarget;
00152   int m_xDrag, m_docDrag, m_multiDrag;
00153 };
00154 
00155 #endif
00156 

Generated on Thu Nov 20 04:28:49 2008 for HOOPLE Libraries by  doxygen 1.5.1