home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / winfe / dropmenu.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  13.3 KB  |  339 lines

  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  *
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19. // dropmenu.h
  20. // Provides the interface for a popup menu in which you can drag and drop
  21. // Created by Scott Putterman on 9/10/96
  22.  
  23. #ifndef _DROPMENU_H
  24. #define _DROPMENU_H
  25.  
  26. #include "stdafx.h"
  27. #include "tlbutton.h"
  28.  
  29. #define DM_DROPOCCURRED        WM_USER + 50
  30. #define DM_CLOSEALLMENUS    WM_USER + 51
  31. #define DM_MENUCLOSED        WM_USER + 52
  32. #define DM_FILLINMENU        WM_USER + 53
  33. #define DM_DRAGGINGOCCURRED WM_USER + 54
  34.  
  35. typedef enum {eABOVE=1, eON=2, eBELOW=3, eNONE} MenuSelectionType;
  36.  
  37. class CDropMenuButton : public CStationaryToolbarButton {
  38.  
  39. public:
  40.     CDropMenuButton();
  41.  
  42. protected:
  43.     BOOL m_bButtonPressed;    // have had a mouse down
  44.     BOOL m_bMenuShowing;      // is the menu showing
  45.     BOOL m_bFirstTime;          // is this the first time we've moved after a mouse up
  46.  
  47.     // Generated message map functions
  48.     //{{AFX_MSG(CDropMenuButton)
  49.     virtual afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
  50.     virtual afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
  51.     virtual afx_msg void OnMouseMove(UINT nFlags, CPoint point);
  52.     virtual afx_msg LRESULT OnMenuClosed(WPARAM, LPARAM); 
  53.  
  54.     //}}AFX_MSG
  55.     DECLARE_MESSAGE_MAP()
  56.  
  57. };
  58.  
  59. class CDropMenu;
  60.  
  61. class CDropMenuItem  {
  62.  
  63. private:
  64.     CString        m_szText;
  65.     UINT        m_nCommandID;
  66.     void*        m_pCustomIcon;                    // An icon can be drawn instead of using bitmaps
  67.     IconType    m_nIconType;                    // The icon type.
  68.     HBITMAP     m_hUnselectedBitmap;        // Just like the toolbar buttons (DWH)
  69.     HBITMAP     m_hSelectedBitmap;
  70.     CDropMenu * m_pSubMenu;
  71.     BOOL        m_bIsSeparator;
  72.     CSize        m_unselectedBitmapSize;
  73.     CSize        m_selectedBitmapSize;
  74.     CSize        m_textSize;
  75.     CSize        m_totalSize;
  76.     CRect        m_menuItemRect;
  77.     BOOL        m_bShowFeedback;            //Does this show selection information
  78.     BOOL        m_bIsEmpty;                    //Is the submenu empty
  79.     int            m_nColumn;                    //The column in the menu this item is in
  80.     void *        m_pUserData;
  81. public:
  82.     CDropMenuItem(UINT nFlags, CString szText, UINT nCommandID,
  83.                   HBITMAP hUnselectedBitmap, HBITMAP hSelectedBitmap, BOOL bShowFeedback,
  84.                   void *pUserData = NULL);
  85.     CDropMenuItem(UINT nFlags, CString szText, UINT nCommandID, CDropMenu *pSubMenu, BOOL bIsEmpty,
  86.                   HBITMAP hUnselectedBitmap, HBITMAP hSelectedBitmap, BOOL bShowFeedback,
  87.                   void *pUserData = NULL);
  88.  
  89.     ~CDropMenuItem();
  90.  
  91.     CDropMenu *GetSubMenu(void)    { return m_pSubMenu; }
  92.     CString    GetText(void)       { return m_szText; }
  93.     UINT       GetCommand(void)    { return m_nCommandID; }
  94.     HBITMAP       GetUnselectedBitmap(void)   { return m_hUnselectedBitmap; }
  95.     HBITMAP    GetSelectedBitmap(void)     { return m_hSelectedBitmap; }
  96.     BOOL       IsSeparator(void)   { return m_bIsSeparator; }
  97.     BOOL       IsSubMenu(void)       { return m_pSubMenu != NULL && !m_bIsSeparator; }
  98.     BOOL       IsMenuItem(void)       { return m_pSubMenu == NULL && !m_bIsSeparator; }
  99.     BOOL       IsEmpty(void)       { return m_bIsEmpty; }
  100.     CSize       GetUnselectedBitmapSize(void) { return m_unselectedBitmapSize; }
  101.     void       SetUnselectedBitmapSize(CSize bitmapSize) { m_unselectedBitmapSize = bitmapSize; }
  102.     CSize       GetSelectedBitmapSize(void) { return m_selectedBitmapSize; }
  103.     void       SetSelectedBitmapSize(CSize bitmapSize) { m_selectedBitmapSize = bitmapSize; }
  104.     CSize       GetTextSize(void)   { return m_textSize; }
  105.     void       SetTextSize(CSize textSize) { m_textSize = textSize; }
  106.     CSize       GetTotalSize(void)  { return m_totalSize; }
  107.     void       SetTotalSize(CSize totalSize) { m_totalSize = totalSize; }
  108.     void       GetMenuItemRect(LPRECT rect);
  109.     void       SetMenuItemRect(LPRECT rect);
  110.     BOOL       GetShowFeedback(void) { return m_bShowFeedback;}
  111.     void       SetColumn(int nColumn) { m_nColumn = nColumn; }
  112.     int           GetColumn(void) { return m_nColumn; }
  113.     void *       GetUserData(void) { return m_pUserData; }
  114.     void       SetIcon(void* pIcon, IconType iconType) { m_pCustomIcon = pIcon; m_nIconType = iconType; }
  115.     HICON       GetLocalFileIcon() { return (HICON)m_pCustomIcon; }
  116.     NSNavCenterImage* GetCustomIcon() { return (NSNavCenterImage*)m_pCustomIcon; }
  117.     IconType GetIconType() { return m_nIconType; }
  118. };
  119.  
  120. #define DT_DROPOCCURRED WM_USER + 60
  121. #define DT_DRAGGINGOCCURRED WM_USER + 61
  122. #define PT_REFRESH WM_USER + 62
  123.  
  124. class CDropMenuDropTarget : public COleDropTarget
  125. {
  126. protected:
  127.     CWnd *m_pOwner;
  128.  
  129. public:
  130.     CDropMenuDropTarget(CWnd *pOwner);
  131.      
  132. protected:
  133.     virtual DROPEFFECT OnDragEnter(CWnd * pWnd,
  134.             COleDataObject * pDataObject, DWORD dwKeyState, CPoint point);
  135.     virtual DROPEFFECT OnDragOver(CWnd * pWnd,
  136.             COleDataObject * pDataObject, DWORD dwKeyState, CPoint point );
  137.     virtual BOOL OnDrop(CWnd * pWnd, COleDataObject * pDataObject,
  138.             DROPEFFECT dropEffect, CPoint point);
  139.     
  140. };
  141.  
  142. class CDropMenuColumn {
  143.  
  144. private:
  145.     int m_nFirstItem;
  146.     int m_nLastItem;
  147.     int m_nWidth;
  148.     int m_nHeight;
  149.     int m_nWidestImage;
  150.     BOOL m_bHasSubMenu;
  151.  
  152. public:
  153.     CDropMenuColumn(int nFirstItem, int nLastItem, int nWidth, int nHeight);
  154.  
  155.     CDropMenuColumn() {;}
  156.     void SetFirstItem(int nFirstItem) { m_nFirstItem = nFirstItem; }
  157.     int  GetFirstItem(void) { return m_nFirstItem; }
  158.     void SetLastItem(int nLastItem) { m_nLastItem = nLastItem; }
  159.     int  GetLastItem(void) { return m_nLastItem; }
  160.     void SetWidth(int nWidth) { m_nWidth = nWidth; }
  161.     int  GetWidth(void) { return m_nWidth; }
  162.     void SetHeight(int nHeight) { m_nHeight = nHeight; }
  163.     int  GetHeight(void) { return m_nHeight; }
  164.     void SetWidestImage(int nWidestImage) { m_nWidestImage = nWidestImage; }
  165.     int  GetWidestImage(void) { return m_nWidestImage; }
  166.     void SetHasSubMenu(BOOL bHasSubMenu) {m_bHasSubMenu = bHasSubMenu; }
  167.     BOOL GetHasSubMenu(void) { return m_bHasSubMenu; }
  168.  
  169. };
  170.  
  171. class CDropMenuDragData
  172. {
  173. public:
  174.     CPoint m_PointHit;                // Added by Dave H.  In our RDF world, we need to give drag feedback
  175.     MenuSelectionType eSelType;        // in the drop menus, since some drops won't be allowed.
  176.     COleDataObject* m_pDataSource;
  177.     UINT m_nCommand;
  178.     DROPEFFECT m_DropEffect;
  179.  
  180. public:
  181.     CDropMenuDragData(COleDataObject* pDataSource, const CPoint& point)
  182.         :m_pDataSource(pDataSource), m_PointHit(point) { m_DropEffect = DROPEFFECT_NONE; };
  183. };
  184.  
  185. class CDropMenu: public CWnd {
  186.  
  187. protected:
  188.     CPtrArray m_pMenuItemArray;
  189.     CPtrArray m_pColumnArray;
  190.  
  191. private:
  192.     int m_WidestImage;
  193.     int m_WidestText;
  194.  
  195.     int m_nSelectedItem;
  196.     MenuSelectionType m_eSelectedItemSelType; //is selection above, on, below or on?
  197.  
  198.     CWnd *m_pParent;                    //The real parent of this menu (could me some other window)
  199.     CDropMenu *m_pMenuParent;            //The menu parent of this menu (if its real parent is
  200.                                         //another type of window, this is NULL
  201.  
  202.     CDropMenu *m_pShowingSubmenu;        //The current submenu that is showing
  203.  
  204.     CDropMenuDropTarget *m_pDropTarget;
  205.  
  206.     HBITMAP m_hSubmenuUnselectedBitmap;
  207.     HBITMAP m_hSubmenuSelectedBitmap;
  208.  
  209.     BOOL m_bShowing;                    //even though it may be showing on screen, is it a submenu
  210.                                         //that has been killed and is just waiting the specified delay time
  211.     BOOL m_bAboutToShow;                //A submenu that is about to be opened but is not yet on the screen.
  212.     BOOL m_bHasSubMenu;                    //does this menu have at least one submenu
  213.     BOOL m_bNotDestroyed;
  214.     BOOL m_bDropOccurring;                //Have we just been dropped on
  215.  
  216.     BOOL m_bMouseUsed;                    //Is the mouse or keyboard being used
  217.     BOOL m_bDragging;                    //Is this menu being displayed for drag and drop
  218.     CDropMenuItem *m_pUnselectedItem;    //Which menu has most recently been unselected
  219.     UINT m_nUnselectTimer;                //the unselected menu timer
  220.  
  221.     CDropMenuItem *m_pSelectedItem;        //Which menu has most recently been selected
  222.     UINT m_nSelectTimer;                //the selected menu timer
  223.  
  224.     UINT m_nHaveFocusTimer;
  225.     BOOL m_bRight;                        //is this window to the right of its parent
  226.     BOOL m_bIsOpen;                        //Are we currently open
  227.     BOOL m_bShowFeedback;                //Does this draw feedback above and below menu item
  228.  
  229.     HHOOK m_mouseHook;
  230.     CDropMenuItem *m_pOverflowMenuItem;    //The overflow menu item;
  231.     int     m_nLastVisibleColumn;            //The last column that will show up on the screen before it overflows
  232.     BOOL m_bFirstPaint;
  233.     CDropMenuItem *m_pParentMenuItem;    //The menu item this submenu belongs to
  234.     void * m_pUserData;                    // User data attached to the menu item
  235. public:
  236.  
  237.     CDropMenu();
  238.     ~CDropMenu();
  239.  
  240.     UINT GetMenuItemCount();
  241.  
  242.     void AppendMenu(UINT nFlags, UINT nIDNewItem, CString szText, BOOL bShowFeedback, HBITMAP hUnselectedBitmap, HBITMAP hSelectedBitmap = NULL, 
  243.                     void* pCustomIcon = NULL, IconType iconType = BUILTIN_BITMAP, void *pUserData = NULL);
  244.     void AppendMenu(UINT nFlags, UINT nIDNewItem, CDropMenu *pSubMenu, BOOL bIsEmpty,
  245.                     CString szText, BOOL bShowFeedback, HBITMAP pUnselectedBitmap, HBITMAP hSelectedBitmap = NULL,
  246.                     void* pCustomIcon = NULL, IconType iconType = BUILTIN_BITMAP, void *pUserData = NULL);
  247.     
  248.     void DeleteMenu(UINT nPosition, UINT nFlags);
  249.  
  250.     void CreateOverflowMenuItem(UINT nCommand, CString szText, HBITMAP hUnselectedBitmap, HBITMAP hSelectedBitmap = NULL);
  251.  
  252.     BOOL IsOpen(void)           { return m_bIsOpen; }
  253.     BOOL IsDragging(void)  { return m_bDragging;}
  254.  
  255.     int GetSelected(void) { return m_nSelectedItem; }
  256.     int Create(CWnd *pParent, int x, int y);
  257.  
  258.     void TrackDropMenu(CWnd* pParent, int x, int y,  BOOL bDragging = FALSE, CDropMenuDropTarget *pDropTarget = NULL, BOOL bShowFeedback = FALSE, int oppX = -1, int oppY = -1);
  259.     BOOL PointInMenus(POINT pt);
  260.     BOOL IsShowingMenu(HWND hwnd);
  261.     void HandleKeystroke(WPARAM key);
  262.  
  263.     virtual BOOL OnCommand( WPARAM wParam, LPARAM lParam );
  264.     void Deactivate(void); 
  265.     void SetUserData(void *pUserData) { m_pUserData = pUserData; }
  266.     void *GetUserData(void) { return m_pUserData; }
  267.     void PostNcDestroy(void );
  268.     void DestroyDropMenu(void);
  269.  
  270.     static CDropMenu* GetLastDropMenu(); // Handle to the gLastMenu var.
  271.     static void SetLastDropMenu(CDropMenu* menu); // Sets the gLastMenu var.
  272.  
  273. protected:
  274.     void DrawSeparator(HDC hDC, int x, int y, int nWidth);
  275.     void DrawVerticalSeparator(HDC hDC, int x, int y, int nHeight);
  276.     void DrawBorders(HDC hDC, CRect rcClient);
  277.     void    SetDropMenuTarget(CDropMenuDropTarget *pDropTarget);
  278.     virtual CSize GetMenuSize(void);
  279.     virtual CSize CalculateColumn(CDropMenuColumn *pColumn, int nStartX);
  280.     int AddOverflowItem(int nColumn, int nStartX);
  281.     virtual void CalculateItemDimensions(void);
  282.     virtual void CalculateOneItemsDimensions(CDropMenuItem* item);
  283.     virtual CSize MeasureBitmap(HBITMAP hBitmap);
  284.     virtual CSize MeasureText(CString text);
  285.     virtual CSize MeasureItem(CDropMenuItem *pItem);
  286.     virtual void  DrawItem(CDropMenuColumn *pColumn, CDropMenuItem *pItem, CRect rc, HDC hDC, BOOL bIsSelected, MenuSelectionType eSelType);
  287.     virtual CSize DrawImage(CDC * pDC, const CRect & rect, CDropMenuColumn *pColumn, CDropMenuItem * pItem, BOOL bIsSelected,
  288.                             MenuSelectionType eSelType);
  289.     virtual CDropMenuDropTarget *GetDropMenuDropTarget(CWnd *pOwner);
  290.     void ChangeSelection(CPoint point);
  291.     int  FindSelection(CPoint point, MenuSelectionType &eSelType);
  292.     int  FindSelectionInColumn(CDropMenuColumn *pColumn, CPoint point, MenuSelectionType &eSelType);
  293.     MenuSelectionType FindSelectionType(CDropMenuItem *pItem, int y, int nHeight);
  294.     void SelectMenuItem(int nItemIndex, BOOL bIsSelected, BOOL bHandleSubmenus, MenuSelectionType eSelType);
  295.     BOOL NoSubmenusShowing(void);
  296.     CDropMenu *GetMenuParent(void);
  297.     BOOL IsDescendant(CWnd *pDescendant);
  298.     BOOL IsAncestor(CWnd *pAncestor);
  299.     void DropMenuTrackDropMenu(CDropMenu *pParent, int x, int y, BOOL bDragging, CDropMenuDropTarget *pDropTarget,
  300.                                BOOL bShowFeedback, int oppX =- 1, int oppY = -1);
  301.     virtual BOOL DestroyWindow(void);
  302.     BOOL ShowWindow( int nCmdShow );
  303.     int FindCommand(UINT nCommand);
  304.     CPoint FindStartPoint(int x, int y, CSize size, int oppX = -1, int oppY = -1);
  305.     void HandleUpArrow(void);
  306.     void HandleDownArrow(void);
  307.     void HandleLeftArrow(void);
  308.     void HandleRightArrow(void);
  309.     void HandleReturnKey(void);
  310.     void ShowSubmenu(CDropMenuItem * pItem);
  311.     int    FindMenuItemPosition(CDropMenuItem* pMenuItem);
  312.     void InvalidateMenuItemRect(CDropMenuItem *pMenuItem);
  313.     void KeepMenuAroundIfClosing(void);
  314.     void SetSubmenuBitmaps(HBITMAP hSelectedBitmap, HBITMAP hUnselectedBitmap);
  315.     CWnd *GetTopLevelParent(void);
  316.  
  317.         // Generated message map functions
  318.     //{{AFX_MSG(CDropMenu)
  319.     afx_msg void OnPaint();
  320.     virtual afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
  321.     virtual afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
  322.     afx_msg void OnRButtonDown(UINT nFlags, CPoint point);
  323.     virtual afx_msg void OnMouseMove(UINT nFlags, CPoint point);
  324.     afx_msg UINT OnNcHitTest( CPoint point );
  325.     afx_msg LRESULT OnDropTargetDropOccurred(WPARAM, LPARAM); 
  326.     afx_msg LRESULT OnDropTargetDraggingOccurred(WPARAM, LPARAM);
  327.     afx_msg LRESULT OnCloseAllMenus(WPARAM, LPARAM); 
  328.     afx_msg void OnTimer( UINT  nIDEvent );
  329.     afx_msg void OnActivate( UINT nState, CWnd* pWndOther, BOOL bMinimized );
  330.     afx_msg void OnDestroy( );
  331.     //}}AFX_MSG
  332.     DECLARE_MESSAGE_MAP()
  333.  
  334. };
  335.  
  336.  
  337.  
  338. #endif
  339.