1 /*
2  * Copyright (c) 1996, 2019, Oracle and/or its affiliates. All rights reserved.
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * This code is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License version 2 only, as
7  * published by the Free Software Foundation.  Oracle designates this
8  * particular file as subject to the "Classpath" exception as provided
9  * by Oracle in the LICENSE file that accompanied this code.
10  *
11  * This code is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14  * version 2 for more details (a copy is included in the LICENSE file that
15  * accompanied this code).
16  *
17  * You should have received a copy of the GNU General Public License version
18  * 2 along with this work; if not, write to the Free Software Foundation,
19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20  *
21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22  * or visit www.oracle.com if you need additional information or have any
23  * questions.
24  */
25 
26 #ifndef AWT_MENU_H
27 #define AWT_MENU_H
28 
29 #include "awt_MenuItem.h"
30 
31 #include <java_awt_MenuItem.h>
32 #include <sun_awt_windows_WMenuItemPeer.h>
33 #include <java_awt_Menu.h>
34 #include <sun_awt_windows_WMenuPeer.h>
35 
36 class AwtMenuBar;
37 
38 
39 /************************************************************************
40  * AwtMenu class
41  */
42 
43 class AwtMenu : public AwtMenuItem {
44 public:
45     /* method ids for java.awt.Menu */
46     static jmethodID countItemsMID;
47     static jmethodID getItemMID;
48 
49     AwtMenu();
50     virtual ~AwtMenu();
51 
52     virtual void Dispose();
53 
54     virtual LPCTSTR GetClassName();
55 
56     /* Create a new AwtMenu.  This must be run on the main thread. */
57     static AwtMenu* Create(jobject self, jobject parent);
58 
GetHMenu()59     INLINE HMENU GetHMenu() { return m_hMenu; }
SetHMenu(HMENU hMenu)60     INLINE void SetHMenu(HMENU hMenu) {
61         m_hMenu = hMenu;
62         SetID(static_cast<UINT>(reinterpret_cast<INT_PTR>(GetHMenu())));
63     }
64 
65     virtual AwtMenuBar* GetMenuBar();
66 
67     virtual void UpdateContainerLayout();
68     void UpdateLayout();
69     virtual void AddItem(AwtMenuItem *item);
70     virtual void DeleteItem(UINT index);
71 
72     virtual HWND GetOwnerHWnd();
73 
74     /*for multifont menu */
75     BOOL IsTopMenu();
76     virtual AwtMenuItem* GetItem(jobject target, long index);
77 
78     virtual int CountItem(jobject target);
79 
80     virtual void SendDrawItem(AwtMenuItem* awtMenuItem,
81                               DRAWITEMSTRUCT& drawInfo);
82     virtual void SendMeasureItem(AwtMenuItem* awtMenuItem, HDC hDC,
83                                  MEASUREITEMSTRUCT& measureInfo);
84     void DrawItem(DRAWITEMSTRUCT& drawInfo);
85     void DrawItems(DRAWITEMSTRUCT& drawInfo);
86     void MeasureItem(HDC hDC, MEASUREITEMSTRUCT& measureInfo);
87     void MeasureItems(HDC hDC, MEASUREITEMSTRUCT& measureInfo);
88 
89     // invoked on Toolkit thread
90     static void _DelItem(void *param);
91     static void _CreateMenu(void *param);
92     static void _CreateSubMenu(void *param);
IsSeparator()93     virtual BOOL IsSeparator() { return FALSE; }
94 
95 protected:
RemoveCmdID()96     virtual void RemoveCmdID() { /* do nothing */ }
97 
98 private:
99     void UpdateLayout(const HMENU hmenu);
100     HMENU    m_hMenu;
101 };
102 
103 #endif /* AWT_MENU_H */
104