Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ivstcontextmenu.h 7.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. //------------------------------------------------------------------------
  2. // Project : VST SDK
  3. //
  4. // Category : Interfaces
  5. // Filename : pluginterfaces/vst/ivstcontextmenu.h
  6. // Created by : Steinberg, 10/2010
  7. // Description : VST Context Menu Interfaces
  8. //
  9. //-----------------------------------------------------------------------------
  10. // This file is part of a Steinberg SDK. It is subject to the license terms
  11. // in the LICENSE file found in the top-level directory of this distribution
  12. // and at www.steinberg.net/sdklicenses.
  13. // No part of the SDK, including this file, may be copied, modified, propagated,
  14. // or distributed except according to the terms contained in the LICENSE file.
  15. //-----------------------------------------------------------------------------
  16. #pragma once
  17. #include "pluginterfaces/base/funknown.h"
  18. #include "vsttypes.h"
  19. //------------------------------------------------------------------------
  20. #include "pluginterfaces/base/falignpush.h"
  21. //------------------------------------------------------------------------
  22. namespace Steinberg {
  23. class IPlugView;
  24. namespace Vst {
  25. class IContextMenu;
  26. //------------------------------------------------------------------------
  27. /** Extended Host callback interface IComponentHandler3 for an edit controller.
  28. \ingroup vstIHost vst350
  29. - [host imp]
  30. - [extends IComponentHandler]
  31. - [released: 3.5.0]
  32. - [optional]
  33. A Plug-in can ask the host to create a context menu for a given exported Parameter ID or a generic context menu.\n
  34. The host may pre-fill this context menu with specific items regarding the parameter ID like "Show automation for parameter",
  35. "MIDI learn" etc...\n
  36. The Plug-in can use the context menu in two ways :
  37. - add its own items to the menu via the IContextMenu interface and call IContextMenu::popup(..) to pop-up it. See the \ref IContextMenuExample.
  38. - extract the host menu items and add them to its own created context menu
  39. \b Note: You can and should use this even if you don't add your own items to the menu as this is considered to be a big user value.
  40. \sa IContextMenu
  41. \sa IContextMenuTarget
  42. \section IContextMenuExample Example
  43. Adding Plug-in specific items to the context menu
  44. \code
  45. class PluginContextMenuTarget : public IContextMenuTarget, public FObject
  46. {
  47. public:
  48. PluginContextMenuTarget () {}
  49. virtual tresult PLUGIN_API executeMenuItem (int32 tag)
  50. {
  51. // this will be called if the user has executed one of the menu items of the Plug-in.
  52. // It won't be called for items of the host.
  53. switch (tag)
  54. {
  55. case 1: break;
  56. case 2: break;
  57. }
  58. return kResultTrue;
  59. }
  60. OBJ_METHODS(PluginContextMenuTarget, FObject)
  61. DEFINE_INTERFACES
  62. DEF_INTERFACE (IContextMenuTarget)
  63. END_DEFINE_INTERFACES (FObject)
  64. REFCOUNT_METHODS(FObject)
  65. };
  66. // The following is the code to create the context menu
  67. void popupContextMenu (IComponentHandler* componentHandler, IPlugView* view, const ParamID* paramID, UCoord x, UCoord y)
  68. {
  69. if (componentHandler == 0 || view == 0)
  70. return;
  71. FUnknownPtr<IComponentHandler3> handler (componentHandler);
  72. if (handler == 0)
  73. return;
  74. IContextMenu* menu = handler->createContextMenu (view, paramID);
  75. if (menu)
  76. {
  77. // here you can add your entries (optional)
  78. PluginContextMenuTarget* target = new PluginContextMenuTarget ();
  79. IContextMenu::Item item = {0};
  80. UString128 ("My Item 1").copyTo (item.name, 128);
  81. item.tag = 1;
  82. menu->addItem (item, target);
  83. UString128 ("My Item 2").copyTo (item.name, 128);
  84. item.tag = 2;
  85. menu->addItem (item, target);
  86. target->release ();
  87. //--end of adding new entries
  88. // here the the context menu will be pop-up (and it waits a user interaction)
  89. menu->popup (x, y);
  90. menu->release ();
  91. }
  92. }
  93. \endcode
  94. */
  95. //------------------------------------------------------------------------
  96. class IComponentHandler3 : public FUnknown
  97. {
  98. public:
  99. /** Creates a host context menu for a Plug-in:
  100. - If paramID is zero, the host may create a generic context menu.
  101. - The IPlugView object must be valid.
  102. - The return IContextMenu object needs to be released afterwards by the Plug-in.
  103. */
  104. virtual IContextMenu* PLUGIN_API createContextMenu (IPlugView* plugView, const ParamID* paramID) = 0;
  105. //------------------------------------------------------------------------
  106. static const FUID iid;
  107. };
  108. DECLARE_CLASS_IID (IComponentHandler3, 0x69F11617, 0xD26B400D, 0xA4B6B964, 0x7B6EBBAB)
  109. //------------------------------------------------------------------------
  110. /** Context Menu Item Target Interface.
  111. \ingroup vstIHost vstIPlug vst350
  112. - [host imp]
  113. - [plug imp]
  114. - [released: 3.5.0]
  115. - [optional]
  116. A receiver of a menu item should implement this interface, which will be called after the user has selected
  117. this menu item.
  118. See IComponentHandler3 for more.
  119. */
  120. //------------------------------------------------------------------------
  121. class IContextMenuTarget : public FUnknown
  122. {
  123. public:
  124. /** Called when an menu item was executed. */
  125. virtual tresult PLUGIN_API executeMenuItem (int32 tag) = 0;
  126. //------------------------------------------------------------------------
  127. static const FUID iid;
  128. };
  129. DECLARE_CLASS_IID (IContextMenuTarget, 0x3CDF2E75, 0x85D34144, 0xBF86D36B, 0xD7C4894D)
  130. //------------------------------------------------------------------------
  131. /** IContextMenuItem is an entry element of the context menu. */
  132. struct IContextMenuItem
  133. {
  134. String128 name; ///< Name of the item
  135. int32 tag; ///< Identifier tag of the item
  136. int32 flags; ///< Flags of the item
  137. enum Flags {
  138. kIsSeparator = 1 << 0, ///< Item is a separator
  139. kIsDisabled = 1 << 1, ///< Item is disabled
  140. kIsChecked = 1 << 2, ///< Item is checked
  141. kIsGroupStart = 1 << 3 | kIsDisabled, ///< Item is a group start (like sub folder)
  142. kIsGroupEnd = 1 << 4 | kIsSeparator, ///< Item is a group end
  143. };
  144. };
  145. //------------------------------------------------------------------------
  146. /** Context Menu Interface.
  147. \ingroup vstIHost vst350
  148. - [host imp]
  149. - [create with IComponentHandler3::createContextMenu(..)]
  150. - [released: 3.5.0]
  151. - [optional]
  152. A context menu is composed of Item (entry). A Item is defined by a name, a tag, a flag
  153. and a associated target (called when this item will be selected/executed).
  154. With IContextMenu the Plug-in can retrieve a Item, add a Item, remove a Item and pop-up the menu.
  155. See IComponentHandler3 for more.
  156. */
  157. //------------------------------------------------------------------------
  158. class IContextMenu : public FUnknown
  159. {
  160. public:
  161. typedef IContextMenuItem Item;
  162. /** Gets the number of menu items. */
  163. virtual int32 PLUGIN_API getItemCount () = 0;
  164. /** Gets a menu item and its target (target could be not assigned). */
  165. virtual tresult PLUGIN_API getItem (int32 index, Item& item /*out*/, IContextMenuTarget** target /*out*/) = 0;
  166. /** Adds a menu item and its target. */
  167. virtual tresult PLUGIN_API addItem (const Item& item, IContextMenuTarget* target) = 0;
  168. /** Removes a menu item. */
  169. virtual tresult PLUGIN_API removeItem (const Item& item, IContextMenuTarget* target) = 0;
  170. /** Pop-ups the menu. Coordinates are relative to the top-left position of the Plug-ins view. */
  171. virtual tresult PLUGIN_API popup (UCoord x, UCoord y) = 0;
  172. //------------------------------------------------------------------------
  173. static const FUID iid;
  174. };
  175. DECLARE_CLASS_IID (IContextMenu, 0x2E93C863, 0x0C9C4588, 0x97DBECF5, 0xAD17817D)
  176. //------------------------------------------------------------------------
  177. } // namespace Vst
  178. } // namespace Steinberg
  179. //------------------------------------------------------------------------
  180. #include "pluginterfaces/base/falignpop.h"
  181. //------------------------------------------------------------------------