diff options
Diffstat (limited to 'xbmc/addons/kodi-dev-kit/include/kodi/gui/dialogs/ContextMenu.h')
| -rw-r--r-- | xbmc/addons/kodi-dev-kit/include/kodi/gui/dialogs/ContextMenu.h | 186 |
1 files changed, 186 insertions, 0 deletions
diff --git a/xbmc/addons/kodi-dev-kit/include/kodi/gui/dialogs/ContextMenu.h b/xbmc/addons/kodi-dev-kit/include/kodi/gui/dialogs/ContextMenu.h new file mode 100644 index 0000000..b576b9a --- /dev/null +++ b/xbmc/addons/kodi-dev-kit/include/kodi/gui/dialogs/ContextMenu.h | |||
| @@ -0,0 +1,186 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2005-2018 Team Kodi | ||
| 3 | * This file is part of Kodi - https://kodi.tv | ||
| 4 | * | ||
| 5 | * SPDX-License-Identifier: GPL-2.0-or-later | ||
| 6 | * See LICENSES/README.md for more information. | ||
| 7 | */ | ||
| 8 | |||
| 9 | #pragma once | ||
| 10 | |||
| 11 | #include "../../AddonBase.h" | ||
| 12 | #include "../../c-api/gui/dialogs/context_menu.h" | ||
| 13 | |||
| 14 | #ifdef __cplusplus | ||
| 15 | |||
| 16 | namespace kodi | ||
| 17 | { | ||
| 18 | namespace gui | ||
| 19 | { | ||
| 20 | namespace dialogs | ||
| 21 | { | ||
| 22 | |||
| 23 | //============================================================================== | ||
| 24 | /// @defgroup cpp_kodi_gui_dialogs_ContextMenu Dialog Context Menu | ||
| 25 | /// @ingroup cpp_kodi_gui_dialogs | ||
| 26 | /// @brief @cpp_namespace{ kodi::gui::dialogs::ContextMenu } | ||
| 27 | /// **Context menu dialog**@n | ||
| 28 | /// The function listed below permits the call of a dialogue as context menu to | ||
| 29 | /// select of an entry as a key | ||
| 30 | /// | ||
| 31 | /// It has the header @ref ContextMenu.h "#include <kodi/gui/dialogs/ContextMenu.h>" | ||
| 32 | /// be included to enjoy it. | ||
| 33 | /// | ||
| 34 | /// | ||
| 35 | namespace ContextMenu | ||
| 36 | { | ||
| 37 | //============================================================================== | ||
| 38 | /// @ingroup cpp_kodi_gui_dialogs_ContextMenu | ||
| 39 | /// @brief Show a context menu dialog about given parts. | ||
| 40 | /// | ||
| 41 | /// @param[in] heading Dialog heading name | ||
| 42 | /// @param[in] entries String list about entries | ||
| 43 | /// @return The selected entry, if return <tt>-1</tt> was nothing selected or canceled | ||
| 44 | /// | ||
| 45 | /// | ||
| 46 | ///------------------------------------------------------------------------- | ||
| 47 | /// | ||
| 48 | /// **Example:** | ||
| 49 | /// ~~~~~~~~~~~~~{.cpp} | ||
| 50 | /// #include <kodi/gui/dialogs/ContextMenu.h> | ||
| 51 | /// | ||
| 52 | /// const std::vector<std::string> entries | ||
| 53 | /// { | ||
| 54 | /// "Test 1", | ||
| 55 | /// "Test 2", | ||
| 56 | /// "Test 3", | ||
| 57 | /// "Test 4", | ||
| 58 | /// "Test 5" | ||
| 59 | /// }; | ||
| 60 | /// | ||
| 61 | /// int selected = kodi::gui::dialogs::ContextMenu::Show("Test selection", entries); | ||
| 62 | /// if (selected < 0) | ||
| 63 | /// fprintf(stderr, "Item selection canceled\n"); | ||
| 64 | /// else | ||
| 65 | /// fprintf(stderr, "Selected item is: %i\n", selected); | ||
| 66 | /// ~~~~~~~~~~~~~ | ||
| 67 | /// | ||
| 68 | inline int ATTRIBUTE_HIDDEN Show(const std::string& heading, | ||
| 69 | const std::vector<std::string>& entries) | ||
| 70 | { | ||
| 71 | using namespace ::kodi::addon; | ||
| 72 | unsigned int size = static_cast<unsigned int>(entries.size()); | ||
| 73 | const char** cEntries = static_cast<const char**>(malloc(size * sizeof(const char**))); | ||
| 74 | for (unsigned int i = 0; i < size; ++i) | ||
| 75 | { | ||
| 76 | cEntries[i] = entries[i].c_str(); | ||
| 77 | } | ||
| 78 | int ret = CAddonBase::m_interface->toKodi->kodi_gui->dialogContextMenu->open( | ||
| 79 | CAddonBase::m_interface->toKodi->kodiBase, heading.c_str(), cEntries, size); | ||
| 80 | free(cEntries); | ||
| 81 | return ret; | ||
| 82 | } | ||
| 83 | //------------------------------------------------------------------------------ | ||
| 84 | |||
| 85 | //============================================================================== | ||
| 86 | /// @ingroup cpp_kodi_gui_dialogs_ContextMenu | ||
| 87 | /// @brief Show a context menu dialog about given parts. | ||
| 88 | /// | ||
| 89 | /// @param[in] heading Dialog heading name | ||
| 90 | /// @param[in] entries String list about entries | ||
| 91 | /// @return The selected entry, if return <tt>-1</tt> was nothing selected or canceled | ||
| 92 | /// | ||
| 93 | /// | ||
| 94 | ///------------------------------------------------------------------------- | ||
| 95 | /// | ||
| 96 | /// **Example:** | ||
| 97 | /// ~~~~~~~~~~~~~{.cpp} | ||
| 98 | /// #include <kodi/gui/dialogs/ContextMenu.h> | ||
| 99 | /// | ||
| 100 | /// const std::vector<std::pair<std::string, std::string>> entries | ||
| 101 | /// { | ||
| 102 | /// { "ID 1", "Test 1" }, | ||
| 103 | /// { "ID 2", "Test 2" }, | ||
| 104 | /// { "ID 3", "Test 3" }, | ||
| 105 | /// { "ID 4", "Test 4" }, | ||
| 106 | /// { "ID 5", "Test 5" } | ||
| 107 | /// }; | ||
| 108 | /// | ||
| 109 | /// int selected = kodi::gui::dialogs::ContextMenu::Show("Test selection", entries); | ||
| 110 | /// if (selected < 0) | ||
| 111 | /// fprintf(stderr, "Item selection canceled\n"); | ||
| 112 | /// else | ||
| 113 | /// fprintf(stderr, "Selected item is: %i\n", selected); | ||
| 114 | /// ~~~~~~~~~~~~~ | ||
| 115 | /// | ||
| 116 | inline int ATTRIBUTE_HIDDEN Show(const std::string& heading, | ||
| 117 | const std::vector<std::pair<std::string, std::string>>& entries) | ||
| 118 | { | ||
| 119 | using namespace ::kodi::addon; | ||
| 120 | unsigned int size = static_cast<unsigned int>(entries.size()); | ||
| 121 | const char** cEntries = static_cast<const char**>(malloc(size * sizeof(const char**))); | ||
| 122 | for (unsigned int i = 0; i < size; ++i) | ||
| 123 | { | ||
| 124 | cEntries[i] = entries[i].second.c_str(); | ||
| 125 | } | ||
| 126 | int ret = CAddonBase::m_interface->toKodi->kodi_gui->dialogContextMenu->open( | ||
| 127 | CAddonBase::m_interface->toKodi->kodiBase, heading.c_str(), cEntries, size); | ||
| 128 | free(cEntries); | ||
| 129 | return ret; | ||
| 130 | } | ||
| 131 | //------------------------------------------------------------------------------ | ||
| 132 | |||
| 133 | //============================================================================== | ||
| 134 | /// @ingroup cpp_kodi_gui_dialogs_ContextMenu | ||
| 135 | /// @brief Show a context menu dialog about given parts. | ||
| 136 | /// | ||
| 137 | /// @param[in] heading Dialog heading name | ||
| 138 | /// @param[in] entries String list about entries | ||
| 139 | /// @return The selected entry, if return <tt>-1</tt> was nothing selected or canceled | ||
| 140 | /// | ||
| 141 | /// | ||
| 142 | ///------------------------------------------------------------------------- | ||
| 143 | /// | ||
| 144 | /// **Example:** | ||
| 145 | /// ~~~~~~~~~~~~~{.cpp} | ||
| 146 | /// #include <kodi/gui/dialogs/ContextMenu.h> | ||
| 147 | /// | ||
| 148 | /// const std::vector<std::pair<int, std::string>> entries | ||
| 149 | /// { | ||
| 150 | /// { 1, "Test 1" }, | ||
| 151 | /// { 2, "Test 2" }, | ||
| 152 | /// { 3, "Test 3" }, | ||
| 153 | /// { 4, "Test 4" }, | ||
| 154 | /// { 5, "Test 5" } | ||
| 155 | /// }; | ||
| 156 | /// | ||
| 157 | /// int selected = kodi::gui::dialogs::ContextMenu::Show("Test selection", entries); | ||
| 158 | /// if (selected < 0) | ||
| 159 | /// fprintf(stderr, "Item selection canceled\n"); | ||
| 160 | /// else | ||
| 161 | /// fprintf(stderr, "Selected item is: %i\n", selected); | ||
| 162 | /// ~~~~~~~~~~~~~ | ||
| 163 | /// | ||
| 164 | inline int ATTRIBUTE_HIDDEN Show(const std::string& heading, | ||
| 165 | const std::vector<std::pair<int, std::string>>& entries) | ||
| 166 | { | ||
| 167 | using namespace ::kodi::addon; | ||
| 168 | unsigned int size = static_cast<unsigned int>(entries.size()); | ||
| 169 | const char** cEntries = static_cast<const char**>(malloc(size * sizeof(const char**))); | ||
| 170 | for (unsigned int i = 0; i < size; ++i) | ||
| 171 | { | ||
| 172 | cEntries[i] = entries[i].second.c_str(); | ||
| 173 | } | ||
| 174 | int ret = CAddonBase::m_interface->toKodi->kodi_gui->dialogContextMenu->open( | ||
| 175 | CAddonBase::m_interface->toKodi->kodiBase, heading.c_str(), cEntries, size); | ||
| 176 | free(cEntries); | ||
| 177 | return ret; | ||
| 178 | } | ||
| 179 | //------------------------------------------------------------------------------ | ||
| 180 | }; // namespace ContextMenu | ||
| 181 | |||
| 182 | } /* namespace dialogs */ | ||
| 183 | } /* namespace gui */ | ||
| 184 | } /* namespace kodi */ | ||
| 185 | |||
| 186 | #endif /* __cplusplus */ | ||
