Mercurial > foo_out_sdl
comparison foosdk/sdk/foobar2000/SDK/ui.h @ 1:20d02a178406 default tip
*: check in everything else
yay
| author | Paper <paper@tflc.us> |
|---|---|
| date | Mon, 05 Jan 2026 02:15:46 -0500 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 0:e9bb126753e7 | 1:20d02a178406 |
|---|---|
| 1 #pragma once | |
| 2 | |
| 3 | |
| 4 //! Entrypoint service for user interface modules. Implement when registering an UI module. Do not call existing implementations; only core enumerates / dispatches calls. To control UI behaviors from other components, use ui_control API. \n | |
| 5 //! Use user_interface_factory_t<> to register, e.g static user_interface_factory_t<myclass> g_myclass_factory; | |
| 6 class NOVTABLE user_interface : public service_base { | |
| 7 FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(user_interface); | |
| 8 public: | |
| 9 #ifdef _WIN32 | |
| 10 //!HookProc usage: \n | |
| 11 //! in your windowproc, call HookProc first, and if it returns true, return LRESULT value it passed to you | |
| 12 typedef BOOL (WINAPI * HookProc_t)(HWND wnd,UINT msg,WPARAM wp,LPARAM lp,LRESULT * ret); | |
| 13 #else | |
| 14 typedef void* HookProc_t; // RESERVED | |
| 15 #endif | |
| 16 //! Retrieves name (UTF-8 null-terminated string) of the UI module. | |
| 17 virtual const char * get_name()=0; | |
| 18 //! Initializes the UI module - creates the main app window, etc. Failure should be signaled by appropriate exception (std::exception or a derivative). \n | |
| 19 //! Mac OS: return NSWindow cast to hwnd_t | |
| 20 virtual fb2k::hwnd_t init(HookProc_t hook) = 0; | |
| 21 //! Deinitializes the UI module - destroys the main app window, etc. | |
| 22 virtual void shutdown()=0; | |
| 23 //! Activates main app window. | |
| 24 virtual void activate()=0; | |
| 25 //! Minimizes/hides main app window. | |
| 26 virtual void hide()=0; | |
| 27 //! Returns whether main window is visible / not minimized. Used for activate/hide command. | |
| 28 virtual bool is_visible() = 0; | |
| 29 //! Retrieves GUID of your implementation, to be stored in configuration file etc. | |
| 30 virtual GUID get_guid() = 0; | |
| 31 | |
| 32 //! Overrides statusbar text with specified string. The parameter is a null terminated UTF-8 string. The override is valid until another override_statusbar_text() call or revert_statusbar_text() call. | |
| 33 virtual void override_statusbar_text(const char * p_text) = 0; | |
| 34 //! Disables statusbar text override. | |
| 35 virtual void revert_statusbar_text() = 0; | |
| 36 | |
| 37 //! Shows now-playing item somehow (e.g. system tray popup). | |
| 38 virtual void show_now_playing() = 0; | |
| 39 | |
| 40 static bool g_find(service_ptr_t<user_interface> & p_out,const GUID & p_guid); | |
| 41 }; | |
| 42 | |
| 43 template<typename T> | |
| 44 class user_interface_factory : public service_factory_single_t<T> {}; | |
| 45 | |
| 46 //! \since 1.4 | |
| 47 //! Extended version to allow explicit control over certain app features. | |
| 48 class NOVTABLE user_interface_v2 : public user_interface { | |
| 49 FB2K_MAKE_SERVICE_INTERFACE( user_interface_v2, user_interface ); | |
| 50 public: | |
| 51 //! Allows the core to ask the UI module about a specific feature. | |
| 52 virtual bool query_capability( const GUID & cap ) = 0; | |
| 53 | |
| 54 #ifdef _WIN32 | |
| 55 //! Suppress core's shellhook window for intercepting systemwide WM_APPCOMMAND? \n | |
| 56 //! Recommended: false - return true only if your UI does this on its own. | |
| 57 static const GUID cap_suppress_core_shellhook; | |
| 58 //! Suppress coer's integration with with Win10 Universal Volume Control? \n | |
| 59 //! Recommended: false - return true only if your UI is explicitly incompatbile with Win10 UVC. \n | |
| 60 //! Note that cap_suppress_core_shellhook is queried first, as core can't use UVC if this UI does global WM_APPCOMMAND handling on its own. \n | |
| 61 //! Returning true from cap_suppress_core_shellhook implies the same from cap_suppress_core_uvc. | |
| 62 static const GUID cap_suppress_core_uvc; | |
| 63 #endif | |
| 64 }; | |
| 65 | |
| 66 class ui_config_manager; | |
| 67 | |
| 68 //! \since 2.0 | |
| 69 class NOVTABLE user_interface_v3 : public user_interface_v2 { | |
| 70 FB2K_MAKE_SERVICE_INTERFACE(user_interface_v3, user_interface_v2); | |
| 71 public: | |
| 72 virtual service_ptr_t< ui_config_manager > get_config_manager() = 0; | |
| 73 }; | |
| 74 | |
| 75 //! \since 2.1 | |
| 76 class NOVTABLE user_interface_v4 : public user_interface_v3 { | |
| 77 FB2K_MAKE_SERVICE_INTERFACE(user_interface_v4, user_interface_v3); | |
| 78 public: | |
| 79 static constexpr uint32_t flagHide = 1; | |
| 80 virtual fb2k::hwnd_t init_v4(HookProc_t hook, uint32_t flags) = 0; | |
| 81 }; | |
| 82 | |
| 83 //! Interface class allowing you to override UI statusbar text. There may be multiple callers trying to override statusbar text; backend decides which one succeeds so you will not always get what you want. Statusbar text override is automatically cancelled when the object is released.\n | |
| 84 //! Use ui_control::override_status_text_create() to instantiate. | |
| 85 //! Implemented by core. Do not reimplement. | |
| 86 class NOVTABLE ui_status_text_override : public service_base | |
| 87 { | |
| 88 public: | |
| 89 //! Sets statusbar text to specified UTF-8 null-terminated string. | |
| 90 virtual void override_text(const char * p_message) = 0; | |
| 91 //! Cancels statusbar text override. | |
| 92 virtual void revert_text() = 0; | |
| 93 | |
| 94 FB2K_MAKE_SERVICE_INTERFACE(ui_status_text_override,service_base); | |
| 95 }; | |
| 96 | |
| 97 //! Serivce providing various UI-related commands. Implemented by core; do not reimplement. | |
| 98 //! Instantiation: use ui_control::get() to obtain an instance. | |
| 99 class NOVTABLE ui_control : public service_base { | |
| 100 FB2K_MAKE_SERVICE_COREAPI(ui_control); | |
| 101 public: | |
| 102 //! Returns whether primary UI is visible/unminimized. | |
| 103 virtual bool is_visible()=0; | |
| 104 //! Activates/unminimizes main UI. | |
| 105 virtual void activate()=0; | |
| 106 //! Hides/minimizese main UI. | |
| 107 virtual void hide()=0; | |
| 108 | |
| 109 #ifdef _WIN32 | |
| 110 //! Retrieves main GUI icon, to use as window icon etc. Returned handle does not need to be freed. | |
| 111 virtual fb2k::hicon_t get_main_icon()=0; | |
| 112 //! Loads main GUI icon, version with specified width/height. Returned handle needs to be freed with DestroyIcon when you are done using it. | |
| 113 virtual fb2k::hicon_t load_main_icon(unsigned width,unsigned height) = 0; | |
| 114 #endif | |
| 115 //! Activates preferences dialog and navigates to specified page. See also: preference_page API. \n | |
| 116 //! Since foobar2000 1.5, this can be used to show advanced preferences branches or settings, just pass GUID of the advconfig_entry you wish to show. | |
| 117 virtual void show_preferences(const GUID & p_page) = 0; | |
| 118 | |
| 119 //! Instantiates ui_status_text_override service, that can be used to display status messages. | |
| 120 //! @param p_out receives new ui_status_text_override instance. | |
| 121 //! @returns true on success, false on failure (out of memory / no GUI loaded / etc) | |
| 122 virtual bool override_status_text_create(service_ptr_t<ui_status_text_override> & p_out) = 0; | |
| 123 }; | |
| 124 | |
| 125 typedef ui_status_text_override ui_status_host; | |
| 126 | |
| 127 //! \since 1.5 | |
| 128 class NOVTABLE ui_control_v2 : public ui_control { | |
| 129 FB2K_MAKE_SERVICE_COREAPI_EXTENSION(ui_control_v2, ui_control) | |
| 130 public: | |
| 131 virtual void register_status_host(fb2k::hwnd_t wndFor, ui_status_host::ptr obj) = 0; | |
| 132 virtual void unregister_status_host(fb2k::hwnd_t wndFor) = 0; | |
| 133 }; | |
| 134 | |
| 135 #ifdef _WIN32 | |
| 136 //! Service called from the UI when some object is dropped into the UI. Usable for modifying drag&drop behaviors such as adding custom handlers for object types other than supported media files.\n | |
| 137 //! Implement where needed; use ui_drop_item_callback_factory_t<> template to register, e.g. static ui_drop_item_callback_factory_t<myclass> g_myclass_factory. | |
| 138 class NOVTABLE ui_drop_item_callback : public service_base { | |
| 139 public: | |
| 140 //! Called when an object was dropped; returns true if the object was processed and false if not. | |
| 141 virtual bool on_drop(interface IDataObject * pDataObject) = 0; | |
| 142 //! Tests whether specified object type is supported by this ui_drop_item_callback implementation. Returns true and sets p_effect when it's supported; returns false otherwise. \n | |
| 143 //! See IDropTarget::DragEnter() documentation for more information about p_effect values. | |
| 144 virtual bool is_accepted_type(interface IDataObject * pDataObject, DWORD * p_effect)=0; | |
| 145 | |
| 146 //! Static helper, calls all existing implementations appropriately. See on_drop(). | |
| 147 static bool g_on_drop(interface IDataObject * pDataObject); | |
| 148 //! Static helper, calls all existing implementations appropriately. See is_accepted_type(). | |
| 149 static bool g_is_accepted_type(interface IDataObject * pDataObject, DWORD * p_effect); | |
| 150 | |
| 151 FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(ui_drop_item_callback); | |
| 152 }; | |
| 153 | |
| 154 template<class T> | |
| 155 class ui_drop_item_callback_factory_t : public service_factory_single_t<T> {}; | |
| 156 #endif | |
| 157 | |
| 158 class ui_selection_callback; | |
| 159 | |
| 160 //! Write interface and reference counter for the shared selection. | |
| 161 //! The ui_selection_manager stores the selected items as a list. | |
| 162 //! The ui_selection_holder service allows components to modify this list. | |
| 163 //! It also serves as a reference count: the ui_selection_manager clears the stored | |
| 164 //! selection when no component holds a reference to a ui_selection_holder. | |
| 165 //! | |
| 166 //! When a window that uses the shared selection gets the focus, it should acquire | |
| 167 //! a ui_selection_holder from the ui_selection_manager. If it contains selectable items, | |
| 168 //! it should use the appropriate method to store its selected items as the shared selection. | |
| 169 //! If it just wants to preserve the selection - for example so it can display it - it should | |
| 170 //! merely store the acquired ui_selection_holder. | |
| 171 //! | |
| 172 //! When the window loses the focus, it should release its ui_selection_holder. | |
| 173 //! It should not use a set method to clear the selection | |
| 174 class NOVTABLE ui_selection_holder : public service_base { | |
| 175 public: | |
| 176 //! Sets selected items. | |
| 177 virtual void set_selection(metadb_handle_list_cref data) = 0; | |
| 178 //! Sets selected items to playlist selection and enables tracking. | |
| 179 //! When the playlist selection changes, the stored selection is automatically updated. | |
| 180 //! Tracking ends when a set method is called on any ui_selection_holder or when | |
| 181 //! the last reference to this ui_selection_holder is released. | |
| 182 virtual void set_playlist_selection_tracking() = 0; | |
| 183 //! Sets selected items to the contents of the active playlist and enables tracking. | |
| 184 //! When the active playlist or its contents changes, the stored selection is automatically updated. | |
| 185 //! Tracking ends when a set method is called on any ui_selection_holder or when | |
| 186 //! the last reference to this ui_selection_holder is released. | |
| 187 virtual void set_playlist_tracking() = 0; | |
| 188 | |
| 189 //! Sets selected items and type of selection holder. | |
| 190 //! @param type Specifies type of selection. Values same as contextmenu_item caller IDs. | |
| 191 virtual void set_selection_ex(metadb_handle_list_cref data, const GUID & type) = 0; | |
| 192 | |
| 193 FB2K_MAKE_SERVICE_INTERFACE(ui_selection_holder,service_base); | |
| 194 }; | |
| 195 | |
| 196 class NOVTABLE ui_selection_manager : public service_base { | |
| 197 FB2K_MAKE_SERVICE_COREAPI(ui_selection_manager); | |
| 198 public: | |
| 199 //! Retrieves the current selection. | |
| 200 virtual void get_selection(metadb_handle_list_ref p_selection) = 0; | |
| 201 //! Registers a callback. It is recommended to use ui_selection_callback_impl_base class instead of calling this directly. | |
| 202 virtual void register_callback(ui_selection_callback * p_callback) = 0; | |
| 203 //! Unregisters a callback. It is recommended to use ui_selection_callback_impl_base class instead of calling this directly. | |
| 204 virtual void unregister_callback(ui_selection_callback * p_callback) = 0; | |
| 205 | |
| 206 virtual ui_selection_holder::ptr acquire() = 0; | |
| 207 | |
| 208 //! Retrieves type of the active selection holder. Values same as contextmenu_item caller IDs. | |
| 209 virtual GUID get_selection_type() = 0; | |
| 210 }; | |
| 211 | |
| 212 //! \since 1.0 | |
| 213 class NOVTABLE ui_selection_manager_v2 : public ui_selection_manager { | |
| 214 FB2K_MAKE_SERVICE_COREAPI_EXTENSION(ui_selection_manager_v2, ui_selection_manager) | |
| 215 public: | |
| 216 enum { flag_no_now_playing = 1 }; | |
| 217 virtual void get_selection(metadb_handle_list_ref out, t_uint32 flags) = 0; | |
| 218 virtual GUID get_selection_type(t_uint32 flags) = 0; | |
| 219 virtual void register_callback(ui_selection_callback * callback, t_uint32 flags) = 0; | |
| 220 }; | |
| 221 | |
| 222 //! \since 2.0 | |
| 223 class NOVTABLE ui_selection_manager_v3 : public ui_selection_manager_v2 { | |
| 224 FB2K_MAKE_SERVICE_COREAPI_EXTENSION(ui_selection_manager_v3, ui_selection_manager_v2) | |
| 225 public: | |
| 226 virtual void add_callback_scope(ui_selection_callback* cb,const GUID & scope) = 0; | |
| 227 virtual bool is_scope_watched(const GUID& scope) = 0; | |
| 228 }; | |
| 229 | |
| 230 class ui_selection_callback { | |
| 231 public: | |
| 232 virtual void on_selection_changed(metadb_handle_list_cref p_selection) = 0; | |
| 233 protected: | |
| 234 ui_selection_callback() {} | |
| 235 ~ui_selection_callback() {} | |
| 236 }; | |
| 237 | |
| 238 //! ui_selection_callback implementation helper with autoregistration - do not instantiate statically | |
| 239 class ui_selection_callback_impl_base : public ui_selection_callback { | |
| 240 protected: | |
| 241 ui_selection_callback_impl_base(bool activate = true) : m_active() {ui_selection_callback_activate(activate);} | |
| 242 ~ui_selection_callback_impl_base() {ui_selection_callback_activate(false);} | |
| 243 | |
| 244 void ui_selection_callback_activate(bool state = true) { | |
| 245 if (state != m_active) { | |
| 246 m_active = state; | |
| 247 auto api = ui_selection_manager::get(); | |
| 248 if (state) api->register_callback(this); | |
| 249 else api->unregister_callback(this); | |
| 250 } | |
| 251 } | |
| 252 | |
| 253 //avoid pure virtual function calls in rare cases - provide a dummy implementation | |
| 254 void on_selection_changed(metadb_handle_list_cref p_selection) override { (void)p_selection; } | |
| 255 | |
| 256 PFC_CLASS_NOT_COPYABLE_EX(ui_selection_callback_impl_base); | |
| 257 private: | |
| 258 bool m_active; | |
| 259 }; | |
| 260 | |
| 261 //! \since 1.0 | |
| 262 //! ui_selection_callback implementation helper with autoregistration - do not instantiate statically | |
| 263 template<unsigned flags> | |
| 264 class ui_selection_callback_impl_base_ex : public ui_selection_callback { | |
| 265 protected: | |
| 266 enum { | |
| 267 ui_selection_flags = flags | |
| 268 }; | |
| 269 ui_selection_callback_impl_base_ex(bool activate = true) : m_active() {ui_selection_callback_activate(activate);} | |
| 270 ~ui_selection_callback_impl_base_ex() {ui_selection_callback_activate(false);} | |
| 271 | |
| 272 void ui_selection_callback_activate(bool state = true) { | |
| 273 if (state != m_active) { | |
| 274 m_active = state; | |
| 275 auto api = ui_selection_manager_v2::get(); | |
| 276 if (state) api->register_callback(this, flags); | |
| 277 else api->unregister_callback(this); | |
| 278 } | |
| 279 } | |
| 280 | |
| 281 //avoid pure virtual function calls in rare cases - provide a dummy implementation | |
| 282 void on_selection_changed(metadb_handle_list_cref p_selection) override {} | |
| 283 | |
| 284 PFC_CLASS_NOT_COPYABLE(ui_selection_callback_impl_base_ex, ui_selection_callback_impl_base_ex<flags>); | |
| 285 private: | |
| 286 bool m_active; | |
| 287 }; |
