ASPiK SDK
win32menu.h
1 // This file is part of VSTGUI. It is subject to the license terms
2 // in the LICENSE file found in the top-level directory of this
3 // distribution and at http://github.com/steinbergmedia/vstgui/LICENSE
4 
5 #pragma once
6 
7 #include "../../../../lib/cstring.h"
8 #include <windows.h>
9 #include <functional>
10 #include <vector>
11 #include <memory>
12 
13 //------------------------------------------------------------------------
14 namespace VSTGUI {
15 namespace Standalone {
16 namespace Platform {
17 
18 struct Win32Menu;
19 
20 //------------------------------------------------------------------------
22 {
23  UTF8String title;
24  char16_t key {0};
25  uint32_t flags {0};
26  uint32_t id {0};
27 
28  enum Flags
29  {
30  disabled = 1 << 0,
31  separator = 1 << 1,
32  submenu = 1 << 2,
33  };
34 
35  bool isDisabled () const { return (flags & Flags::disabled) != 0; }
36  bool isSeparator () const { return (flags & Flags::separator) != 0; }
37  bool isSubmenu () const { return (flags & Flags::submenu) != 0; }
38 
39  void disable () { flags |= Flags::disabled; }
40  void enable () { flags &= ~Flags::disabled; }
41 
42  virtual Win32Menu* asMenu () { return nullptr; }
43 };
44 
45 //------------------------------------------------------------------------
47 {
48  using SubMenuPtr = std::shared_ptr<Win32Menu>;
49  using ItemPtr = std::shared_ptr<Win32MenuItem>;
50  using Items = std::vector<ItemPtr>;
51 
53  ~Win32Menu () noexcept;
54 
55  size_t addSeparator ();
56  size_t addItem (ItemPtr&& item);
57  size_t addItem (UTF8StringView title, char16_t key = 0, uint32_t id = 0);
58  size_t addSubMenu (const SubMenuPtr& subMenu);
59 
60  ItemPtr itemAtIndex (size_t index) const;
61 
62  using ValidateFunc = std::function<bool (Win32MenuItem& item)>;
63  void validateMenuItems (const ValidateFunc& func);
64 
65  operator HMENU () const { return menu; }
66  Win32Menu* asMenu () override { return this; }
67 
68  static Win32Menu* fromHMENU (HMENU menu);
69 //------------------------------------------------------------------------
70 private:
71  HMENU menu {nullptr};
72  Items items;
73 };
74 
75 //------------------------------------------------------------------------
76 } // Platform
77 } // Standalone
78 } // VSTGUI
Definition: win32menu.h:46
Definition: customcontrols.cpp:8
a view on a null terminated UTF-8 String
Definition: cstring.h:172
holds an UTF8 encoded string and a platform representation of it
Definition: cstring.h:56