10
10
11
11
#include < max/Compiling/Configuration.hpp>
12
12
#include < maxGUI/Control.hpp>
13
+ #include < maxGUI/Menu.hpp>
13
14
14
15
#if defined(MAX_PLATFORM_WINDOWS)
15
16
#ifndef WIN32_LEAN_AND_MEAN
16
17
#define WIN32_LEAN_AND_MEAN
17
18
#endif
19
+
18
20
#include < Windows.h>
21
+
22
+ #include < maxGUI/Win32String.hpp>
19
23
#elif defined(MAX_PLATFORM_LINUX)
20
24
#include < string>
21
25
24
28
#include < maxGUI/FormStyles.hpp>
25
29
#endif
26
30
31
+ namespace {
32
+
33
+ // TODO: Use max's Exists here
34
+ template < typename T >
35
+ struct HasOnPressed {
36
+ typedef char yes[1 ];
37
+ typedef char no[2 ];
38
+
39
+ template <typename U> static yes& test (typename std::enable_if<std::is_function_v<decltype (U::OnPressed)>, bool>::type = 0);
40
+ template <typename U> static no& test (...);
41
+ static bool const value = sizeof (test<typename std::remove_cv<T>::type>(0 )) == sizeof (yes&);
42
+ };
43
+
44
+ } // anonymous namespace
45
+
27
46
namespace maxGUI
28
47
{
29
48
@@ -44,6 +63,40 @@ namespace maxGUI
44
63
virtual LRESULT OnWindowMessage (FormConcept* form, UINT message, WPARAM wparam, LPARAM lparam) noexcept = 0;
45
64
#endif
46
65
66
+ template < typename T, typename ... Params >
67
+ T* AppendMenu (Params&&... params) noexcept {
68
+ #if defined(MAX_PLATFORM_WINDOWS)
69
+ bool is_first_menu = menus_.size () == 0 ;
70
+ if (is_first_menu) {
71
+ menu_bar_handle_ = CreateMenu ();
72
+
73
+ MENUINFO menu_info = { 0 };
74
+ menu_info.cbSize = sizeof (menu_info);
75
+ menu_info.fMask = MIM_STYLE;
76
+ menu_info.dwStyle = MNS_NOTIFYBYPOS;
77
+ SetMenuInfo (menu_bar_handle_, &menu_info);
78
+
79
+ ::SetMenu (window_handle_, menu_bar_handle_);
80
+ }
81
+
82
+ HMENU menu_handle = T::Create (menu_bar_handle_, std::forward<Params>(params)...);
83
+ auto menu_ptr = std::make_unique<T>(std::move (menu_handle));
84
+ T* raw_menu_ptr = menu_ptr.get ();
85
+ menus_.push_back (std::move (menu_ptr));
86
+
87
+
88
+ if (is_first_menu) {
89
+ // TODO: This is only required if the window has already been drawn. IE the menus were added after WM_CREATE
90
+ DrawMenuBar (window_handle_);
91
+ }
92
+
93
+ return raw_menu_ptr;
94
+ #else
95
+ // TODO: Implement on other platforms
96
+ return nullptr ;
97
+ #endif
98
+ }
99
+
47
100
template <typename T, typename ... Params>
48
101
T* AddControl (Params&&... params) noexcept {
49
102
#if defined(MAX_PLATFORM_WINDOWS)
@@ -65,10 +118,15 @@ namespace maxGUI
65
118
66
119
#if defined(MAX_PLATFORM_WINDOWS)
67
120
HWND window_handle_;
121
+ HMENU menu_bar_handle_;
68
122
#elif defined(MAX_PLATFORM_LINUX)
69
123
QWidget window_;
70
124
#endif
125
+
71
126
std::vector<std::unique_ptr<Control>> controls_;
127
+ #if defined(MAX_PLATFORM_WINDOWS)
128
+ std::vector<std::unique_ptr<Menu>> menus_;
129
+ #endif
72
130
73
131
};
74
132
0 commit comments