1 //####COPYRIGHTBEGIN####
3 // ----------------------------------------------------------------------------
4 // Copyright (C) 1998, 1999, 2000 Red Hat, Inc.
6 // This program is part of the eCos host tools.
8 // This program is free software; you can redistribute it and/or modify it
9 // under the terms of the GNU General Public License as published by the Free
10 // Software Foundation; either version 2 of the License, or (at your option)
13 // This program is distributed in the hope that it will be useful, but WITHOUT
14 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
18 // You should have received a copy of the GNU General Public License along with
19 // this program; if not, write to the Free Software Foundation, Inc.,
20 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 // ----------------------------------------------------------------------------
24 //####COPYRIGHTEND####
26 //#####DESCRIPTIONBEGIN####
27 //*************************************************************************
28 // BCMenu.h : header file
30 // Date : December 2, 1999
31 // Author : Brent Corkum
32 // Email : corkum@rocscience.com
33 // Latest Version : http://www.rocscience.com/~corkum/BCMenu.html
35 // Bug Fixes and portions of code supplied by:
37 // Ben Ashley,Girish Bharadwaj,Jean-Edouard Lachand-Robert,
38 // Robert Edward Caldecott,Kenny Goers,Leonardo Zide,
39 // Stefan Kuhr,Reiner Jung,Martin Vladic,Kim Yoo Chul,
42 // You are free to use/modify this code but leave this header intact.
43 // This class is public domain so you are free to use it any of
44 // your applications (Freeware,Shareware,Commercial). All I ask is
45 // that you let me know so that if you have a real winner I can
46 // brag to my buddies that some of my code is in your app. I also
47 // wouldn't mind if you sent me a copy of your application since I
48 // like to play with new stuff.
49 //*************************************************************************
50 //####DESCRIPTIONEND####
57 // BCMenuData class. Fill this class structure to define a single menu item:
61 wchar_t *m_szMenuText;
63 BCMenuData () {menuIconNormal=-1;xoffset=-1;bitmap=NULL;pContext=NULL;
64 nFlags=0;nID=0;syncflag=0;m_szMenuText=NULL;};
65 void SetAnsiString(LPCSTR szAnsiString);
66 void SetWideString(const wchar_t *szWideString);
67 const wchar_t *GetWideString(void) {return m_szMenuText;};
69 CString GetString(void);//returns the menu text in ANSI or UNICODE
72 UINT nFlags,nID,syncflag;
74 void *pContext; // used to attach user data
77 //struct CMenuItemInfo : public MENUITEMINFO {
78 struct CMenuItemInfo : public
80 #ifndef UNICODE //SK: this fixes warning C4097: typedef-name 'MENUITEMINFO' used as synonym for class-name 'tagMENUITEMINFOA'
87 { memset(this, 0, sizeof(MENUITEMINFO));
88 cbSize = sizeof(MENUITEMINFO);
95 typedef enum {Normal,TextOnly} HIGHLIGHTSTYLE;
98 #define AppendMenu AppendMenuA
99 #define InsertMenu InsertMenuA
100 #define InsertODMenu InsertODMenuA
101 #define AppendODMenu AppendODMenuA
102 #define AppendODPopupMenu AppendODPopupMenuA
103 #define ModifyODMenu ModifyODMenuA
105 #define AppendMenu AppendMenuW
106 #define InsertMenu InsertMenuW
107 #define InsertODMenu InsertODMenuW
108 #define AppendODMenu AppendODMenuW
109 #define ModifyODMenu ModifyODMenuW
110 #define AppendODPopupMenu AppendODPopupMenuW
114 class BCMenu : public CMenu // Derived from CMenu
122 CTypedPtrArray<CPtrArray, BCMenuData*> m_MenuList; // Stores list of menu items
124 // When loading an owner-drawn menu using a Resource, BCMenu must keep track of
125 // the popup menu's that it creates. Warning, this list *MUST* be destroyed
126 // last item first :)
127 CTypedPtrArray<CPtrArray, HMENU> m_SubMenus; // Stores list of sub-menus
129 // Stores a list of all BCMenu's ever created
130 static CTypedPtrArray<CPtrArray, HMENU> m_AllSubMenus;
135 // ClassWizard generated virtual function overrides
136 //{{AFX_VIRTUAL(CCustomMenu)
140 static BOOL IsNewShell(void);
141 void SetBitmapBackground(COLORREF color);
142 void SetDisableOldStyle(void);
143 void UnSetDisableOldStyle(void);
144 BOOL GetDisableOldStyle(void);
145 void UnSetBitmapBackground(void);
146 BOOL AddBitmapToImageList(CImageList *list,UINT nResourceID);
147 BOOL LoadFromToolBar(UINT nID,UINT nToolBar,int& xoffset);
148 void InsertSpaces(void);
149 static LRESULT FindKeyboardShortcut(UINT nChar,UINT nFlags,CMenu *pMenu);
150 static void UpdateMenu(CMenu *pmenu);
151 static BOOL IsMenu(CMenu *submenu);
152 static BOOL IsMenu(HMENU submenu);
153 void DrawCheckMark(CDC *pDC,int x,int y,COLORREF color);
154 void DrawRadioDot(CDC *pDC,int x,int y,COLORREF color);
155 BCMenuData *BCMenu::FindMenuItem(UINT nID);
156 BCMenu *FindMenuOption(int nId,int& nLoc);
157 BCMenuData *FindMenuOption(wchar_t *lpstrText);
158 BOOL GetMenuText(UINT id,CString &string,UINT nFlags = MF_BYPOSITION );
159 CImageList *checkmaps;
165 void LoadCheckmarkBitmap(int unselect,int select);
166 void DitherBlt(HDC hdcDest, int nXDest, int nYDest, int nWidth,
167 int nHeight, HBITMAP hbm, int nXSrc, int nYSrc);
168 void DitherBlt2(CDC *drawdc, int nXDest, int nYDest, int nWidth,
169 int nHeight, CBitmap &bmp, int nXSrc, int nYSrc);
170 static HBITMAP LoadSysColorBitmap(int nResourceId);
171 BOOL GetBitmapFromImageList(CDC* pDC,CImageList *imglist,int nIndex,CBitmap &bmp);
172 BOOL ImageListDuplicate(CImageList *il,int xoffset,CImageList *newlist);
174 virtual ~BCMenu(); // Virtual Destructor
176 virtual void DrawItem( LPDRAWITEMSTRUCT); // Draw an item
177 virtual void MeasureItem( LPMEASUREITEMSTRUCT ); // Measure an item
181 void SetIconSize (int, int); // Set icon size
183 BOOL AppendODMenuA(LPCSTR lpstrText,
184 UINT nFlags = MF_OWNERDRAW,
186 int nIconNormal = -1);
188 BOOL AppendODMenuW(wchar_t *lpstrText,
189 UINT nFlags = MF_OWNERDRAW,
191 int nIconNormal = -1);
193 BOOL AppendODMenuA(LPCSTR lpstrText,
199 BOOL AppendODMenuW(wchar_t *lpstrText,
205 BOOL InsertODMenuA(UINT nPosition,
207 UINT nFlags = MF_OWNERDRAW,
209 int nIconNormal = -1);
211 BOOL InsertODMenuW(UINT nPosition,
213 UINT nFlags = MF_OWNERDRAW,
215 int nIconNormal = -1);
217 BOOL InsertODMenuA(UINT nPosition,
224 BOOL InsertODMenuW(UINT nPosition,
232 BOOL ModifyODMenuA(const char *lpstrText,UINT nID=0,int nIconNormal=-1);
233 BOOL ModifyODMenuA(const char *lpstrText,UINT nID,CImageList *il,int xoffset);
234 BOOL ModifyODMenuA(const char *lpstrText,UINT nID,CBitmap *bmp);
235 BOOL ModifyODMenuA(const char *lpstrText,const char *OptionText,int nIconNormal);
236 BOOL ModifyODMenuW(wchar_t *lpstrText,UINT nID=0,int nIconNormal=-1);
237 BOOL ModifyODMenuW(wchar_t *lpstrText,UINT nID,CImageList *il,int xoffset);
238 BOOL ModifyODMenuW(wchar_t *lpstrText,UINT nID,CBitmap *bmp);
239 BOOL ModifyODMenuW(wchar_t *lpstrText,wchar_t *OptionText,int nIconNormal);
240 BCMenuData *NewODMenu(UINT pos,UINT nFlags,UINT nID,CString string);
241 void SynchronizeMenu(void);
242 void BCMenu::InitializeMenuList(int value);
243 void BCMenu::DeleteMenuList(void);
244 BCMenuData *BCMenu::FindMenuList(UINT nID);
245 virtual BOOL LoadMenu(LPCTSTR lpszResourceName); // Load a menu
246 virtual BOOL LoadMenu(int nResource); // ...
247 void AddFromToolBar(CToolBar* pToolBar, int nResourceID);
248 BOOL Draw3DCheckmark(CDC *dc, const CRect& rc,BOOL bSelected,
250 BOOL LoadToolbar(UINT nToolBar);
251 BOOL LoadToolbars(const UINT *arID,int n);
253 // new overrides for dynamic menu's
254 BOOL RemoveMenu(UINT uiId,UINT nFlags);
255 BOOL DeleteMenu(UINT uiId,UINT nFlags);
256 BOOL AppendMenuA(UINT nFlags,UINT nIDNewItem=0,const char *lpszNewItem=NULL,int nIconNormal=-1);
257 BOOL AppendMenuA(UINT nFlags,UINT nIDNewItem,const char *lpszNewItem,CImageList *il,int xoffset);
258 BOOL AppendMenuA(UINT nFlags,UINT nIDNewItem,const char *lpszNewItem,CBitmap *bmp);
259 BOOL AppendMenuW(UINT nFlags,UINT nIDNewItem=0,wchar_t *lpszNewItem=NULL,int nIconNormal=-1);
260 BOOL AppendMenuW(UINT nFlags,UINT nIDNewItem,wchar_t *lpszNewItem,CImageList *il,int xoffset);
261 BOOL AppendMenuW(UINT nFlags,UINT nIDNewItem,wchar_t *lpszNewItem,CBitmap *bmp);
262 BOOL InsertMenuA(UINT nPosition,UINT nFlags,UINT nIDNewItem=0,const char *lpszNewItem=NULL,int nIconNormal=-1);
263 BOOL InsertMenuA(UINT nPosition,UINT nFlags,UINT nIDNewItem,const char *lpszNewItem,CImageList *il,int xoffset);
264 BOOL InsertMenuA(UINT nPosition,UINT nFlags,UINT nIDNewItem,const char *lpszNewItem,CBitmap *bmp);
265 BOOL InsertMenuW(UINT nPosition,UINT nFlags,UINT nIDNewItem=0,wchar_t *lpszNewItem=NULL,int nIconNormal=-1);
266 BOOL InsertMenuW(UINT nPosition,UINT nFlags,UINT nIDNewItem,wchar_t *lpszNewItem,CImageList *il,int xoffset);
267 BOOL InsertMenuW(UINT nPosition,UINT nFlags,UINT nIDNewItem,wchar_t *lpszNewItem,CBitmap *bmp);
268 BCMenu* AppendODPopupMenuA(LPCSTR lpstrText);
269 BCMenu* AppendODPopupMenuW(wchar_t *lpstrText);
273 virtual BOOL DestroyMenu();
275 // Generated message map functions
278 COLORREF m_bitmapBackground;
279 BOOL m_bitmapBackgroundFlag;
280 BOOL disable_old_style;
285 //*************************************************************************