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.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. //------------------------------------------------------------------------
  2. // Project : VST SDK
  3. // Version : 3.6.7
  4. //
  5. // Category : Interfaces
  6. // Filename : pluginterfaces/vst/ivstcontextmenu.h
  7. // Created by : Steinberg, 10/2010
  8. // Description : VST Context Menu Interfaces
  9. //
  10. //-----------------------------------------------------------------------------
  11. // This file is part of a Steinberg SDK. It is subject to the license terms
  12. // in the LICENSE file found in the top-level directory of this distribution
  13. // and at www.steinberg.net/sdklicenses.
  14. // No part of the SDK, including this file, may be copied, modified, propagated,
  15. // or distributed except according to the terms contained in the LICENSE file.
  16. //-----------------------------------------------------------------------------
  17. #pragma once
  18. #include "pluginterfaces/base/funknown.h"
  19. #include "vsttypes.h"
  20. //------------------------------------------------------------------------
  21. #include "pluginterfaces/base/falignpush.h"
  22. //------------------------------------------------------------------------
  23. namespace Steinberg {
  24. class IPlugView;
  25. namespace Vst {
  26. class IContextMenu;
  27. //------------------------------------------------------------------------
  28. /** Extended Host callback interface IComponentHandler3 for an edit controller.
  29. \ingroup vstIHost vst350
  30. - [host imp]
  31. - [extends IComponentHandler]
  32. - [released: 3.5.0]
  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. A receiver of a menu item should implement this interface, which will be called after the user has selected
  116. this menu item.
  117. See IComponentHandler3 for more.
  118. */
  119. //------------------------------------------------------------------------
  120. class IContextMenuTarget : public FUnknown
  121. {
  122. public:
  123. /** Called when an menu item was executed. */
  124. virtual tresult PLUGIN_API executeMenuItem (int32 tag) = 0;
  125. //------------------------------------------------------------------------
  126. static const FUID iid;
  127. };
  128. DECLARE_CLASS_IID (IContextMenuTarget, 0x3CDF2E75, 0x85D34144, 0xBF86D36B, 0xD7C4894D)
  129. //------------------------------------------------------------------------
  130. /** Context Menu Interface.
  131. \ingroup vstIHost vst350
  132. - [host imp]
  133. - [create with IComponentHandler3::createContextMenu(..)]
  134. - [released: 3.5.0]
  135. A context menu is composed of Item (entry). A Item is defined by a name, a tag, a flag
  136. and a associated target (called when this item will be selected/executed).
  137. With IContextMenu the Plug-in can retrieve a Item, add a Item, remove a Item and pop-up the menu.
  138. See IComponentHandler3 for more.
  139. */
  140. //------------------------------------------------------------------------
  141. class IContextMenu : public FUnknown
  142. {
  143. public:
  144. /** Item is a entry element of the context menu. */
  145. struct Item
  146. {
  147. String128 name; ///< Name of the item
  148. int32 tag; ///< Identifier tag of the item
  149. int32 flags; ///< Flags of the item
  150. enum Flags {
  151. kIsSeparator = 1 << 0, ///< Item is a separator
  152. kIsDisabled = 1 << 1, ///< Item is disabled
  153. kIsChecked = 1 << 2, ///< Item is checked
  154. kIsGroupStart = 1 << 3 | kIsDisabled, ///< Item is a group start (like sub folder)
  155. kIsGroupEnd = 1 << 4 | kIsSeparator, ///< Item is a group end
  156. };
  157. };
  158. /** Gets the number of menu items. */
  159. virtual int32 PLUGIN_API getItemCount () = 0;
  160. /** Gets a menu item and its target (target could be not assigned). */
  161. virtual tresult PLUGIN_API getItem (int32 index, Item& item /*out*/, IContextMenuTarget** target /*out*/) = 0;
  162. /** Adds a menu item and its target. */
  163. virtual tresult PLUGIN_API addItem (const Item& item, IContextMenuTarget* target) = 0;
  164. /** Removes a menu item. */
  165. virtual tresult PLUGIN_API removeItem (const Item& item, IContextMenuTarget* target) = 0;
  166. /** Pop-ups the menu. Coordinates are relative to the top-left position of the Plug-ins view. */
  167. virtual tresult PLUGIN_API popup (UCoord x, UCoord y) = 0;
  168. //------------------------------------------------------------------------
  169. static const FUID iid;
  170. };
  171. DECLARE_CLASS_IID (IContextMenu, 0x2E93C863, 0x0C9C4588, 0x97DBECF5, 0xAD17817D)
  172. //------------------------------------------------------------------------
  173. } // namespace Vst
  174. } // namespace Steinberg
  175. //------------------------------------------------------------------------
  176. #include "pluginterfaces/base/falignpop.h"
  177. //------------------------------------------------------------------------