comparison foosdk/sdk/foobar2000/SDK/preferences_page.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 class preferences_state {
4 public:
5 enum {
6 changed = 1,
7 needs_restart = 2,
8 needs_restart_playback = 4,
9 resettable = 8,
10
11 //! \since 1.1
12 //! Indicates that the dialog is currently busy and cannot be applied or cancelled. Do not use without a good reason! \n
13 //! This flag was introduced in 1.1. It will not be respected in earlier foobar2000 versions. It is recommended not to use this flag unless you are absolutely sure that you need it and take appropriate precautions. \n
14 //! Note that this has no power to entirely prevent your preferences page from being destroyed/cancelled as a result of app shutdown if the user dismisses the warnings, but you won't be getting an "apply" call while this is set.
15 busy = 16,
16
17 //! \since 1.4.1
18 needs_rescan_library = 32,
19
20 //! \since 2.0
21 dark_mode_supported = 1 << 16,
22 };
23 };
24
25 //! Implementing this service will generate a page in preferences dialog. Use preferences_page_factory_t template to register. \n
26 //! In 1.0 and newer you should always derive from preferences_page_v3 rather than from preferences_page directly.
27 class NOVTABLE preferences_page : public service_base {
28 public:
29 #ifdef _WIN32
30 //! Obsolete.
31 virtual fb2k::hwnd_t create(fb2k::hwnd_t p_parent) { (void)p_parent; uBugCheck(); }
32 #endif
33
34 #ifdef __APPLE__
35 //! Returns fb2k::NSObjectWrapper holding your NSViewController
36 virtual service_ptr instantiate( ) = 0;
37 #endif
38
39 //! Retrieves name of the preferences page to be displayed in preferences tree (static string).
40 virtual const char * get_name() = 0;
41 //! Retrieves GUID of the page.
42 virtual GUID get_guid() = 0;
43 //! Retrieves GUID of parent page/branch of this page. See preferences_page::guid_* constants for list of standard parent GUIDs. Can also be a GUID of another page or a branch (see: preferences_branch).
44 virtual GUID get_parent_guid() = 0;
45 #ifdef _WIN32
46 //! Obsolete.
47 virtual bool reset_query() { return false; }
48 //! Obsolete.
49 virtual void reset() {}
50 #endif
51 //! Retrieves help URL. Without overriding it, it will redirect to foobar2000 wiki.
52 virtual bool get_help_url(pfc::string_base & p_out);
53
54 static void get_help_url_helper(pfc::string_base & out, const char * category, const GUID & id, const char * name);
55
56 static const GUID guid_root, guid_hidden, guid_tools,guid_core,guid_display,guid_playback,guid_visualisations,guid_input,guid_tag_writing,guid_media_library, guid_tagging, guid_output, guid_advanced, guid_components, guid_dsp, guid_shell, guid_keyboard_shortcuts;
57 //! \since 1.5
58 static const GUID guid_input_info_filter;
59
60 double get_sort_priority_();
61
62 FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(preferences_page);
63 };
64
65 class NOVTABLE preferences_page_v2 : public preferences_page {
66 public:
67 //! Allows custom sorting order of preferences pages. Return lower value for higher priority (lower resulting index in the list). When sorting priority of two items matches, alphabetic sorting is used. Return 0 to use default alphabetic sorting without overriding priority.
68 virtual double get_sort_priority() {return 0;}
69
70 FB2K_MAKE_SERVICE_INTERFACE(preferences_page_v2,preferences_page);
71 };
72
73 template<class T>
74 class preferences_page_factory_t : public service_factory_single_t<T> {};
75
76 //! Creates a preferences branch - an empty page that only serves as a parent for other pages and is hidden when no child pages exist. Instead of implementing this, simply use preferences_branch_factory class to declare a preferences branch with specified parameters.
77 class NOVTABLE preferences_branch : public service_base {
78 public:
79 //! Retrieves name of the preferences branch.
80 virtual const char * get_name() = 0;
81 //! Retrieves GUID of the preferences branch. Use this GUID as parent GUID for pages/branches nested in this branch.
82 virtual GUID get_guid() = 0;
83 //! Retrieves GUID of parent page/branch of this branch. See preferences_page::guid_* constants for list of standard parent GUIDs. Can also be a GUID of another branch or a page.
84 virtual GUID get_parent_guid() = 0;
85
86
87 FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(preferences_branch);
88 };
89
90 class preferences_branch_v2 : public preferences_branch {
91 public:
92 //! Allows custom sorting order of preferences pages. Return lower value for higher priority (lower resulting index in the list). When sorting priority of two items matches, alphabetic sorting is used. Return 0 to use default alphabetic sorting without overriding priority.
93 virtual double get_sort_priority() {return 0;}
94
95 FB2K_MAKE_SERVICE_INTERFACE(preferences_branch_v2,preferences_branch);
96 };
97
98 class preferences_branch_impl : public preferences_branch_v2 {
99 public:
100 preferences_branch_impl(const GUID & p_guid,const GUID & p_parent,const char * p_name,double p_sort_priority = 0) : m_guid(p_guid), m_parent(p_parent), m_name(p_name), m_sort_priority(p_sort_priority) {}
101 const char * get_name() {return m_name;}
102 GUID get_guid() {return m_guid;}
103 GUID get_parent_guid() {return m_parent;}
104 double get_sort_priority() {return m_sort_priority;}
105 private:
106 const GUID m_guid,m_parent;
107 const pfc::string8 m_name;
108 const double m_sort_priority;
109 };
110
111 typedef service_factory_single_t<preferences_branch_impl> _preferences_branch_factory;
112
113 //! Instantiating this class declares a preferences branch with specified parameters.\n
114 //! Usage: static preferences_branch_factory g_mybranch(mybranchguid,parentbranchguid,"name of my preferences branch goes here");
115 class preferences_branch_factory : public _preferences_branch_factory {
116 public:
117 preferences_branch_factory(const GUID & p_guid,const GUID & p_parent,const char * p_name,double p_sort_priority = 0) : _preferences_branch_factory(p_guid,p_parent,p_name,p_sort_priority) {}
118 };
119
120
121 #ifdef _WIN32
122 class preferences_page_callback : public service_base {
123 FB2K_MAKE_SERVICE_INTERFACE(preferences_page_callback, service_base)
124 public:
125 virtual void on_state_changed() = 0;
126 };
127
128 //! \since 1.0
129 //! Implements a preferences page instance. \n
130 //! Instantiated through preferences_page_v3::instantiate(). \n
131 //! Note that the window will be destroyed by the caller before the last reference to the preferences_page_instance is released. \n
132 //! WARNING: misguided use of modal dialogs - or ANY windows APIs that might spawn such dialogs - may result in conditions when the owner dialog (along with your page) is destroyed somewhere inside your message handler, also releasing references to your object. \n
133 //! It is recommended to use window_service_impl_t<> from ATLHelpers to instantiate preferences_page_instances, or preferences_page_impl<> framework for your preferences_page code to cleanly workaround such cases.
134 class preferences_page_instance : public service_base {
135 FB2K_MAKE_SERVICE_INTERFACE(preferences_page_instance, service_base)
136 public:
137 //! @returns a combination of preferences_state constants.
138 virtual t_uint32 get_state() = 0;
139 //! @returns the window handle.
140 virtual fb2k::hwnd_t get_wnd() = 0;
141 //! Applies preferences changes.
142 virtual void apply() = 0;
143 //! Resets this page's content to the default values. Does not apply any changes - lets user preview the changes before hitting "apply".
144 virtual void reset() = 0;
145 };
146 #endif
147
148 //! \since 1.0
149 //! Implements a preferences page.
150 class preferences_page_v3 : public preferences_page_v2 {
151 FB2K_MAKE_SERVICE_INTERFACE(preferences_page_v3, preferences_page_v2)
152 public:
153 #ifdef _WIN32
154 virtual preferences_page_instance::ptr instantiate(fb2k::hwnd_t parent, preferences_page_callback::ptr callback) = 0;
155 #endif
156 };
157
158 //! \since 1.5
159 class NOVTABLE preferences_page_v4 : public preferences_page_v3 {
160 FB2K_MAKE_SERVICE_INTERFACE(preferences_page_v4, preferences_page_v3);
161 public:
162 virtual bool is_hidden() { return false; }
163 };