1010
1111#include < max/Compiling/Configuration.hpp>
1212#include < maxGUI/Control.hpp>
13+ #include < maxGUI/Menu.hpp>
1314
1415#if defined(MAX_PLATFORM_WINDOWS)
1516 #ifndef WIN32_LEAN_AND_MEAN
1617 #define WIN32_LEAN_AND_MEAN
1718 #endif
19+
1820 #include < Windows.h>
21+
22+ #include < maxGUI/Win32String.hpp>
1923#elif defined(MAX_PLATFORM_LINUX)
2024 #include < string>
2125
2428 #include < maxGUI/FormStyles.hpp>
2529#endif
2630
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+
2746namespace maxGUI
2847{
2948
@@ -44,6 +63,40 @@ namespace maxGUI
4463 virtual LRESULT OnWindowMessage (FormConcept* form, UINT message, WPARAM wparam, LPARAM lparam) noexcept = 0;
4564 #endif
4665
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+
47100 template <typename T, typename ... Params>
48101 T* AddControl (Params&&... params) noexcept {
49102#if defined(MAX_PLATFORM_WINDOWS)
@@ -65,10 +118,15 @@ namespace maxGUI
65118
66119 #if defined(MAX_PLATFORM_WINDOWS)
67120 HWND window_handle_;
121+ HMENU menu_bar_handle_;
68122 #elif defined(MAX_PLATFORM_LINUX)
69123 QWidget window_;
70124 #endif
125+
71126 std::vector<std::unique_ptr<Control>> controls_;
127+ #if defined(MAX_PLATFORM_WINDOWS)
128+ std::vector<std::unique_ptr<Menu>> menus_;
129+ #endif
72130
73131 };
74132
0 commit comments