comparison foosdk/sdk/foobar2000/SDK/ui_edit_context.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 //! A class used to redirect actions coming from the 'edit' menu, typically provided by the UI Element having focus. \n
4 //! Use ui_edit_context_manager to register and manipulate.
5 class NOVTABLE ui_edit_context : public service_base {
6 FB2K_MAKE_SERVICE_INTERFACE(ui_edit_context, service_base)
7 public:
8 //! Called by core only.
9 virtual void initialize() = 0;
10 //! Called by core only. \n
11 //! WARNING: you may get other methods called after shutdown() in case someone using ui_edit_context_manager has kept a reference to your service - for an example during an async operation. You should behave sanely in such case - either execute the operation if still possible or fail cleanly.
12 virtual void shutdown() = 0;
13
14 enum {
15 flag_removable = 1,
16 flag_reorderable = 2,
17 flag_undoable = 4,
18 flag_redoable = 8,
19 flag_linearlist = 16,
20 flag_searchable = 32,
21 flag_insertable = 64,
22 };
23
24 virtual t_uint32 get_flags() = 0;
25
26 bool can_remove() {return (get_flags() & flag_removable) != 0;}
27 bool test_flags(t_uint32 flags) {return (get_flags() & flags) == flags;}
28 bool can_remove_mask() {return test_flags(flag_removable | flag_linearlist);}
29 bool can_reorder() {return test_flags(flag_reorderable);}
30 bool can_search() {return test_flags(flag_searchable);}
31
32 virtual void select_all();
33 virtual void select_none();
34 virtual void get_selected_items(metadb_handle_list_ref out);
35 virtual void remove_selection();
36 virtual void crop_selection();
37 virtual void clear();
38 virtual void get_all_items(metadb_handle_list_ref out);
39 virtual GUID get_selection_type() = 0;
40
41 // available if flag_linearlist is set
42 virtual void get_selection_mask(pfc::bit_array_var & out);
43
44 virtual void update_selection(const pfc::bit_array & mask, const pfc::bit_array & newVals) = 0;
45 virtual t_size get_item_count(t_size max = ~0) = 0;
46 virtual metadb_handle_ptr get_item(t_size index) = 0;
47 virtual void get_items(metadb_handle_list_ref out, pfc::bit_array const & mask) = 0;
48 virtual bool is_item_selected(t_size item) = 0;
49 virtual void remove_items(pfc::bit_array const & mask) = 0;
50 virtual void reorder_items(const t_size * order, t_size count) = 0;
51 virtual t_size get_selection_count(t_size max = ~0);
52
53 virtual void search() = 0;
54
55 virtual void undo_backup() = 0;
56 virtual void undo_restore() = 0;
57 virtual void redo_restore() = 0;
58
59 virtual void insert_items(t_size at, metadb_handle_list_cref items, pfc::bit_array const & selection) = 0;
60
61 virtual t_size query_insert_mark() = 0;
62
63 void sort_by_format(const char * spec, bool onlySelection);
64
65 //! Safely prevent destruction from worker threads (some components attempt that).
66 static bool serviceRequiresMainThreadDestructor() { return true; }
67 };
68
69 //! Special case of ui_edit_context operating on a specific playlist (see playlist_manager). \n
70 //! Use this to let everyone know that your methods operate on a playlist, \n
71 //! in case some component wishes to provide additional functionality based on that.
72 class ui_edit_context_playlist : public ui_edit_context {
73 FB2K_MAKE_SERVICE_INTERFACE(ui_edit_context_playlist, ui_edit_context)
74 public:
75 virtual t_size get_playlist_number() = 0;
76 };
77
78 //! Entrypoint class for registering and manipulating ui_edit_context objects. \n
79 //! Implemented by core.
80 class NOVTABLE ui_edit_context_manager : public service_base {
81 FB2K_MAKE_SERVICE_COREAPI(ui_edit_context_manager)
82 public:
83 //! Sets the current edit context. \n
84 //! Typically called when a part of your UI receives focus. \n
85 //! @returns An identifier than can later be passed to unset_context when focus is lost.
86 virtual t_uint32 set_context(ui_edit_context::ptr context) = 0;
87 //! Removes an edit context. \n
88 //! @param id The value returned by matching set_context() call.
89 virtual void unset_context(t_uint32 id) = 0;
90 //! Retrieves the current context object. May return null when there's no context.
91 //! @returns The currently active context object, possibly null if none.
92 virtual ui_edit_context::ptr get_context() = 0;
93 //! Creates a context wrapping a specific playlist; see also playlist_manager.
94 //! @param playlist_number Number of wrapped playlist, per playlist_manager numbering.
95 //! @returns Newly creted context object.
96 virtual ui_edit_context::ptr create_playlist_context(t_size playlist_number) = 0;
97 //! By default, when no context is registered, \n
98 //! for an example, if the active user interface component is not ui_edit_context-aware, \n
99 //! a fallback context is automatically set; it follows the active playlist,\n
100 //! so the edit menu does something meaningful. \n
101 //! This method is intended to be called during initialiation of an user interface component; \n
102 //! it tells foobar2000 core to suppress the active playlist fallback-\n
103 //! but then entire edit menu becomes non-functional if no context is provided.
104 virtual void disable_autofallback() = 0;
105 //! Helper, sets the current context to an implemented-by-core context that tracks the active playlist. \n
106 //! Typically called when a part of your UI receives focus.
107 //! @returns Identifier value to pass to unset_context() when your focus is gone.
108 virtual t_uint32 set_context_active_playlist() = 0;
109 };