foobar2000 SDK  2015-08-03
contextmenu.h
Go to the documentation of this file.
1 typedef void * t_glyph;
3 
4 
5 class NOVTABLE contextmenu_item_node {
6 public:
7  enum t_flags {
8  FLAG_CHECKED = 1,
9  FLAG_DISABLED = 2,
10  FLAG_GRAYED = 4,
11  FLAG_DISABLED_GRAYED = FLAG_DISABLED|FLAG_GRAYED,
12  FLAG_RADIOCHECKED = 8, //new in 0.9.5.2 - overrides FLAG_CHECKED, set together with FLAG_CHECKED for backwards compatibility.
13  };
14 
15  enum t_type {
19 
20  //for compatibility
21  TYPE_POPUP = type_group,TYPE_COMMAND = type_command,TYPE_SEPARATOR = type_separator,
22  };
23 
24  virtual bool get_display_data(pfc::string_base & p_out,unsigned & p_displayflags,metadb_handle_list_cref p_data,const GUID & p_caller) = 0;
25  virtual t_type get_type() = 0;
26  virtual void execute(metadb_handle_list_cref p_data,const GUID & p_caller) = 0;
27  virtual t_glyph get_glyph(metadb_handle_list_cref p_data,const GUID & p_caller) {return 0;}//RESERVED
28  virtual t_size get_children_count() = 0;
29  virtual contextmenu_item_node * get_child(t_size p_index) = 0;
30  virtual bool get_description(pfc::string_base & p_out) = 0;
31  virtual GUID get_guid() = 0;
32  virtual bool is_mappable_shortcut() = 0;
33 
34 protected:
37 };
38 
40 {
41 public:
43 };
44 
46 {
47 public:
49  t_size get_children_count() {return 0;}
51 };
52 
54 {
55 public:
57  t_size get_children_count() {return 0;}
59 };
60 
62 {
63 public:
65  void execute(metadb_handle_list_cref data,const GUID & caller) {}
66  bool get_description(pfc::string_base & p_out) {return false;}
67 };
68 
70 {
71 public:
73  void execute(metadb_handle_list_cref data,const GUID & caller) {}
74  bool get_description(pfc::string_base & p_out) {return false;}
75 };
76 
78 {
79 public:
80  t_type get_type() {return TYPE_SEPARATOR;}
81  void execute(metadb_handle_list_cref data,const GUID & caller) {}
82  bool get_description(pfc::string_base & p_out) {return false;}
83  t_size get_children_count() {return 0;}
84  bool get_display_data(pfc::string_base & p_out,unsigned & p_displayflags,metadb_handle_list_cref p_data,const GUID & p_caller)
85  {
86  p_displayflags = 0;
87  p_out = "---";
88  return true;
89  }
92  bool is_mappable_shortcut() {return false;}
93 };
94 
100 class NOVTABLE contextmenu_item : public service_base {
101 public:
106  };
107 
109  virtual unsigned get_num_items() = 0;
111  virtual contextmenu_item_node_root * instantiate_item(unsigned p_index,metadb_handle_list_cref p_data,const GUID & p_caller) = 0;
113  virtual GUID get_item_guid(unsigned p_index) = 0;
115  virtual void get_item_name(unsigned p_index,pfc::string_base & p_out) = 0;
117  virtual void get_item_default_path(unsigned p_index,pfc::string_base & p_out) {p_out = "";}
119  virtual bool get_item_description(unsigned p_index,pfc::string_base & p_out) = 0;
125  virtual t_enabled_state get_enabled_state(unsigned p_index) = 0;
127  virtual void item_execute_simple(unsigned p_index,const GUID & p_node,metadb_handle_list_cref p_data,const GUID & p_caller) = 0;
128 
129  bool item_get_display_data_root(pfc::string_base & p_out,unsigned & displayflags,unsigned p_index,metadb_handle_list_cref p_data,const GUID & p_caller);
130  bool item_get_display_data(pfc::string_base & p_out,unsigned & displayflags,unsigned p_index,const GUID & p_node,metadb_handle_list_cref p_data,const GUID & p_caller);
131 
132  GUID get_parent_fallback();
133  GUID get_parent_();
134 
136  static const GUID caller_playlist;
137 
138  static const GUID caller_active_playlist_selection, caller_active_playlist, caller_playlist_manager, caller_now_playing, caller_keyboard_shortcut_list, caller_media_library_viewer;
139  static const GUID caller_undefined;
140 
141  FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(contextmenu_item);
142 };
143 
145 class NOVTABLE contextmenu_item_v2 : public contextmenu_item {
147 public:
148  virtual double get_sort_priority() {return 0;}
149  virtual GUID get_parent() {return get_parent_fallback();}
150 };
151 
154 private:
155 public:
157  enum t_flags
158  {
159  FLAG_CHECKED = 1,
160  FLAG_DISABLED = 2,
161  FLAG_GRAYED = 4,
162  FLAG_DISABLED_GRAYED = FLAG_DISABLED|FLAG_GRAYED,
163  FLAG_RADIOCHECKED = 8, //new in 0.9.5.2 - overrides FLAG_CHECKED, set together with FLAG_CHECKED for backwards compatibility.
164  };
165 
166 
167  // Functions to be overridden by implementers (some are not mandatory).
169  virtual unsigned get_num_items() = 0;
170  virtual void get_item_name(unsigned p_index,pfc::string_base & p_out) = 0;
171  virtual void context_command(unsigned p_index,metadb_handle_list_cref p_data,const GUID& p_caller) = 0;
172  virtual bool context_get_display(unsigned p_index,metadb_handle_list_cref p_data,pfc::string_base & p_out,unsigned & p_displayflags,const GUID & p_caller) {
173  PFC_ASSERT(p_index>=0 && p_index<get_num_items());
174  get_item_name(p_index,p_out);
175  return true;
176  }
177  virtual GUID get_item_guid(unsigned p_index) = 0;
178  virtual bool get_item_description(unsigned p_index,pfc::string_base & p_out) = 0;
179 
180 
181 private:
183  public:
184  contextmenu_item_node_impl(contextmenu_item_simple * p_owner,unsigned p_index) : m_owner(p_owner), m_index(p_index) {}
185  bool get_display_data(pfc::string_base & p_out,unsigned & p_displayflags,metadb_handle_list_cref p_data,const GUID & p_caller) {return m_owner->get_display_data(m_index,p_data,p_out,p_displayflags,p_caller);}
186  void execute(metadb_handle_list_cref p_data,const GUID & p_caller) {m_owner->context_command(m_index,p_data,p_caller);}
187  bool get_description(pfc::string_base & p_out) {return m_owner->get_item_description(m_index,p_out);}
189  bool is_mappable_shortcut() {return m_owner->item_is_mappable_shortcut(m_index);}
190  private:
192  unsigned m_index;
193  };
194 
195  contextmenu_item_node_root * instantiate_item(unsigned p_index,metadb_handle_list_cref p_data,const GUID & p_caller)
196  {
197  return new contextmenu_item_node_impl(this,p_index);
198  }
199 
200 
201  void item_execute_simple(unsigned p_index,const GUID & p_node,metadb_handle_list_cref p_data,const GUID & p_caller)
202  {
203  if (p_node == pfc::guid_null)
204  context_command(p_index,p_data,p_caller);
205  }
206 
207  virtual bool item_is_mappable_shortcut(unsigned p_index)
208  {
209  return true;
210  }
211 
212 
213  virtual bool get_display_data(unsigned n,metadb_handle_list_cref data,pfc::string_base & p_out,unsigned & displayflags,const GUID & caller)
214  {
215  bool rv = false;
216  assert(n>=0 && n<get_num_items());
217  if (data.get_count()>0)
218  {
219  rv = context_get_display(n,data,p_out,displayflags,caller);
220  }
221  return rv;
222  }
223 
224 };
225 
226 
228 template<typename T>
230 
231 
233 #define DECLARE_CONTEXT_MENU_ITEM(P_CLASSNAME,P_NAME,P_DEFAULTPATH,P_FUNC,P_GUID,P_DESCRIPTION) \
234  namespace { \
235  class P_CLASSNAME : public contextmenu_item_simple { \
236  public: \
237  unsigned get_num_items() {return 1;} \
238  void get_item_name(unsigned p_index,pfc::string_base & p_out) {p_out = P_NAME;} \
239  void get_item_default_path(unsigned p_index,pfc::string_base & p_out) {p_out = P_DEFAULTPATH;} \
240  void context_command(unsigned p_index,metadb_handle_list_cref p_data,const GUID& p_caller) {P_FUNC(p_data);} \
241  GUID get_item_guid(unsigned p_index) {return P_GUID;} \
242  bool get_item_description(unsigned p_index,pfc::string_base & p_out) {if (P_DESCRIPTION[0] == 0) return false;p_out = P_DESCRIPTION; return true;} \
243  }; \
244  static contextmenu_item_factory_t<P_CLASSNAME> g_##P_CLASSNAME##_factory; \
245  }
246 
247 
248 
249 
253 public:
254  virtual bool resolve_context_command(const GUID & id, service_ptr_t<class contextmenu_item> & out, t_uint32 & out_index) = 0;
255  virtual bool resolve_main_command(const GUID & id, service_ptr_t<class mainmenu_commands> & out, t_uint32 & out_index) = 0;
256 
257  static bool g_resolve_context_command(const GUID & id, service_ptr_t<class contextmenu_item> & out, t_uint32 & out_index);
258  static bool g_resolve_main_command(const GUID & id, service_ptr_t<class mainmenu_commands> & out, t_uint32 & out_index);
259 
260  FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(menu_item_resolver)
261 };
262 
264 class NOVTABLE contextmenu_group : public service_base {
265  FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(contextmenu_group);
266 public:
267  virtual GUID get_guid() = 0;
268  virtual GUID get_parent() = 0;
269  virtual double get_sort_priority() = 0;
270 };
271 
274  FB2K_MAKE_SERVICE_INTERFACE(contextmenu_group_popup, contextmenu_group)
275 public:
276  virtual void get_display_string(pfc::string_base & out) = 0;
277  void get_name(pfc::string_base & out) {get_display_string(out);}
278 };
279 
281 public:
282  static const GUID root, utilities, tagging, tagging_pictures, replaygain, fileoperations, playbackstatistics, properties, convert, legacy;
283 };
284 
286 public:
287  contextmenu_group_impl(const GUID & guid, const GUID & parent, double sortPriority = 0) : m_guid(guid), m_parent(parent), m_sortPriority(sortPriority) {}
288  GUID get_guid() {return m_guid;}
289  GUID get_parent() {return m_parent;}
290  double get_sort_priority() {return m_sortPriority;}
291 private:
292  const GUID m_guid, m_parent;
293  const double m_sortPriority;
294 };
295 
297 public:
298  contextmenu_group_popup_impl(const GUID & guid, const GUID & parent, const char * name, double sortPriority = 0) : m_guid(guid), m_parent(parent), m_sortPriority(sortPriority), m_name(name) {}
299  GUID get_guid() {return m_guid;}
300  GUID get_parent() {return m_parent;}
301  double get_sort_priority() {return m_sortPriority;}
302  void get_display_string(pfc::string_base & out) {out = m_name;}
303 private:
304  const GUID m_guid, m_parent;
305  const double m_sortPriority;
306  const char * const m_name;
307 };
308 
309 
310 
312  enum {
313  root_queue = -100,
314  root_main = -50,
324  };
325 };
326 
327 
328 
329 class contextmenu_group_factory : public service_factory_single_t<contextmenu_group_impl> {
330 public:
331  contextmenu_group_factory(const GUID & guid, const GUID & parent, double sortPriority = 0) : service_factory_single_t<contextmenu_group_impl>(guid, parent, sortPriority) {}
332 };
333 
334 class contextmenu_group_popup_factory : public service_factory_single_t<contextmenu_group_popup_impl> {
335 public:
336  contextmenu_group_popup_factory(const GUID & guid, const GUID & parent, const char * name, double sortPriority = 0) : service_factory_single_t<contextmenu_group_popup_impl>(guid, parent, name, sortPriority) {}
337 };
virtual void get_item_default_path(unsigned p_index, pfc::string_base &p_out)
Obsolete since v1.0, don&#39;t use or override in new components.
Definition: contextmenu.h:117
void execute(metadb_handle_list_cref data, const GUID &caller)
Definition: contextmenu.h:81
contextmenu_item_node_root * instantiate_item(unsigned p_index, metadb_handle_list_cref p_data, const GUID &p_caller)
Instantiates a context menu item (including sub-node tree for items that contain dynamically-generate...
Definition: contextmenu.h:195
void execute(metadb_handle_list_cref data, const GUID &caller)
Definition: contextmenu.h:73
contextmenu_group_popup_factory(const GUID &guid, const GUID &parent, const char *name, double sortPriority=0)
Definition: contextmenu.h:336
Definition: pfc.h:71
const char *const m_name
Definition: contextmenu.h:306
bool get_description(pfc::string_base &p_out)
Definition: contextmenu.h:66
virtual bool get_display_data(unsigned n, metadb_handle_list_cref data, pfc::string_base &p_out, unsigned &displayflags, const GUID &caller)
Definition: contextmenu.h:213
virtual bool item_is_mappable_shortcut(unsigned p_index)
Definition: contextmenu.h:207
static const GUID caller_playlist_manager
Definition: contextmenu.h:138
void item_execute_simple(unsigned p_index, const GUID &p_node, metadb_handle_list_cref p_data, const GUID &p_caller)
Executes the menu item command without going thru the instantiate_item path. For items with dynamical...
Definition: contextmenu.h:201
void execute(metadb_handle_list_cref p_data, const GUID &p_caller)
Definition: contextmenu.h:186
virtual t_enabled_state get_enabled_state(unsigned p_index)
Controls default state of context menu preferences for this item: Return DEFAULT_ON to show this ite...
Definition: contextmenu.h:168
bool get_description(pfc::string_base &p_out)
Definition: contextmenu.h:82
virtual GUID get_parent()
Definition: contextmenu.h:149
virtual bool context_get_display(unsigned p_index, metadb_handle_list_cref p_data, pfc::string_base &p_out, unsigned &p_displayflags, const GUID &p_caller)
Definition: contextmenu.h:172
FB2K_MAKE_SERVICE_INTERFACE(contextmenu_group_popup, contextmenu_group) public void get_name(pfc::string_base &out)
Definition: contextmenu.h:277
static const GUID utilities
Definition: contextmenu.h:282
bool get_description(pfc::string_base &p_out)
Definition: contextmenu.h:187
virtual t_glyph get_glyph(metadb_handle_list_cref p_data, const GUID &p_caller)
Definition: contextmenu.h:27
bool get_display_data(pfc::string_base &p_out, unsigned &p_displayflags, metadb_handle_list_cref p_data, const GUID &p_caller)
Definition: contextmenu.h:84
void execute(metadb_handle_list_cref data, const GUID &caller)
Definition: contextmenu.h:65
size_t t_size
Definition: int_types.h:48
contextmenu_group_impl(const GUID &guid, const GUID &parent, double sortPriority=0)
Definition: contextmenu.h:287
virtual t_size get_count() const =0
void get_display_string(pfc::string_base &out)
Definition: contextmenu.h:302
virtual ~contextmenu_item_node_root()
Definition: contextmenu.h:42
Base class for all service classes. Provides interfaces for reference counter and querying for differ...
Definition: service.h:333
static const GUID caller_undefined
Definition: contextmenu.h:139
contextmenu_item_node_impl(contextmenu_item_simple *p_owner, unsigned p_index)
Definition: contextmenu.h:184
t_flags
Same as contextmenu_item_node::t_flags.
Definition: contextmenu.h:157
static const GUID caller_playlist
Deprecated - use caller_active_playlist_selection instead.
Definition: contextmenu.h:136
bool get_display_data(pfc::string_base &p_out, unsigned &p_displayflags, metadb_handle_list_cref p_data, const GUID &p_caller)
Definition: contextmenu.h:185
void * t_glyph
Reserved for future use.
Definition: contextmenu.h:2
contextmenu_group_popup_impl(const GUID &guid, const GUID &parent, const char *name, double sortPriority=0)
Definition: contextmenu.h:298
service_ptr_t< contextmenu_item_simple > m_owner
Definition: contextmenu.h:191
bool get_description(pfc::string_base &p_out)
Definition: contextmenu.h:74
contextmenu_item_node * get_child(t_size)
Definition: contextmenu.h:50
const GUID guid_null
Definition: guid.cpp:175
New in 0.9.5.1. Static methods safe to use in prior versions as it will use slow fallback mode when t...
Definition: contextmenu.h:252
contextmenu_item implementation helper for implementing non-dynamically-generated context menu items;...
Definition: contextmenu.h:153
FB2K_MAKE_SERVICE_INTERFACE(contextmenu_item_v2, contextmenu_item) public
Definition: contextmenu.h:146
const double m_sortPriority
Definition: contextmenu.h:293
contextmenu_group_factory(const GUID &guid, const GUID &parent, double sortPriority=0)
Definition: contextmenu.h:331
uint32_t t_uint32
Definition: int_types.h:5
contextmenu_item_node * get_child(t_size)
Definition: contextmenu.h:90
contextmenu_item_node * get_child(t_size)
Definition: contextmenu.h:58