update for HEAD-2003091401
[reactos.git] / subsys / system / explorer / Seashell / SeaShellExt / Include / UIMenuBar.h
1 ////////////////////////////////////////////////////////////////
2 // Copyright 1998 Paul DiLascia
3 // If this code works, it was written by Paul DiLascia.
4 // If not, I don't know who wrote it.
5 //
6 #ifndef __MENUBAR_H
7 #define __MENUBAR_H
8
9 #include "UIsubclass.h"
10
11 #include "UIFlatBar.h"
12
13 //////////////////
14 // CMenuBar uses this private class to intercept messages on behalf
15 // of its owning frame, as well as the MDI client window. Conceptually,
16 // these should be two different hooks, but I want to save code.
17 //
18 class CMenuBarFrameHook : public CSubclassWnd {
19 protected:
20    friend class CMenuBar;
21    CMenuBar* m_pMenuBar;
22    CMenuBarFrameHook();
23    ~CMenuBarFrameHook();
24    BOOL Install(CMenuBar* pMenuBar, HWND hWndToHook);
25    virtual LRESULT WindowProc(UINT msg, WPARAM wp, LPARAM lp);
26 };
27
28 //////////////////
29 // CMenuBar implements an Office 97-style menu bar. Use it the way you would
30 // a CToolBar, only you need not call LoadToolbar. All you have to do is
31 //
32 // * Create the CMenuBar from your OnCreate or OnCreateBands handler.
33 //
34 // * Call LoadMenu to load a menu. This will set your frame's menu to NULL.
35 //
36 // * Implemenent your frame's PreTranslateMessage function, to call
37 //   CMenuBar::TranslateFrameMessage. 
38 //
39 class CTRL_EXT_CLASS CMenuBar : public CFlatToolBar {
40 public:
41         BOOL     m_bAutoRemoveFrameMenu;                 // set frame's menu to NULL
42
43         CMenuBar();
44         ~CMenuBar();
45
46         // You must call this from your frame's PreTranslateMessage fn
47         virtual BOOL TranslateFrameMessage(MSG* pMsg);
48
49         HMENU LoadMenu(HMENU hmenu);                            // load menu
50         HMENU LoadMenu(LPCTSTR lpszMenuName);   // ...from resource file
51         HMENU LoadMenu(UINT nID) {
52                 return LoadMenu(MAKEINTRESOURCE(nID));
53         }
54         HMENU GetMenu() { return m_hmenu; }                                     // get current menu
55
56         enum TRACKINGSTATE { // menubar has three states:
57                 TRACK_NONE = 0,   // * normal, not tracking anything
58                 TRACK_BUTTON,     // * tracking buttons (F10/Alt mode)
59                 TRACK_POPUP       // * tracking popups
60         };
61
62         TRACKINGSTATE GetTrackingState(int& iPopup) {
63                 iPopup = m_iPopupTracking; return m_iTrackingState;
64         }
65         static BOOL bTRACE;                                              // set TRUE to see TRACE msgs
66
67 protected:
68         friend class CMenuBarFrameHook;
69
70         CMenuBarFrameHook m_frameHook;           // hooks frame window messages
71         CStringArray            m_arStrings;             // array of menu item names
72         HMENU                                   m_hmenu;                                 // the menu
73
74         // menu tracking stuff:
75         int      m_iPopupTracking;                               // which popup I'm tracking if any
76         int      m_iNewPopup;                                            // next menu to track
77         BOOL     m_bProcessRightArrow;                   // process l/r arrow keys?
78         BOOL     m_bProcessLeftArrow;                    // ...
79         BOOL     m_bEscapeWasPressed;                    // user pressed escape to exit menu
80         CPoint m_ptMouse;                                                        // mouse location when tracking popup
81         HMENU    m_hMenuTracking;                                        // current popup I'm tracking
82
83         TRACKINGSTATE m_iTrackingState;          // current tracking state
84
85         // helpers
86         void  RecomputeToolbarSize();
87         void    RecomputeMenuLayout();
88         void    UpdateFont();
89         int     GetNextOrPrevButton(int iButton, BOOL bPrev);
90         void    SetTrackingState(TRACKINGSTATE iState, int iButton=-1);
91         void    TrackPopup(int iButton);
92         void    ToggleTrackButtonMode();
93         void    CancelMenuAndTrackNewOne(int iButton);
94         void  OnMenuSelect(HMENU hmenu, UINT nItemID);
95         CPoint ComputeMenuTrackPoint(const CRect& rcButn, TPMPARAMS& tpm);
96
97         BOOL    IsValidButton(int iButton) const
98                 { return 0 <= iButton && iButton < GetButtonCount(); }
99
100         virtual BOOL OnMenuInput(MSG& m);        // handle popup menu input
101
102         // overrides
103         virtual void OnBarStyleChange(DWORD dwOldStyle, DWORD dwNewStyle);
104         int HitTest(CPoint p) const;
105
106         // command/message handlers
107         afx_msg int  OnCreate(LPCREATESTRUCT lpCreateStruct);
108         afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
109         afx_msg void OnMouseMove(UINT nFlags, CPoint point);
110         afx_msg void OnSize(UINT nType, int cx, int cy);
111         afx_msg void OnUpdateMenuButton(CCmdUI* pCmdUI);
112         afx_msg LRESULT OnSetMenuNull(WPARAM wp, LPARAM lp);
113
114         static LRESULT CALLBACK MenuInputFilter(int code, WPARAM wp, LPARAM lp);
115         
116         DECLARE_DYNAMIC(CMenuBar)
117         DECLARE_MESSAGE_MAP()
118
119 #ifdef _DEBUG
120         virtual void AssertValid() const;
121         virtual void Dump(CDumpContext& dc) const;
122 #endif
123 };
124
125 #endif