foobar2000 SDK  2015-08-03
menu_item.cpp
Go to the documentation of this file.
1 #include "foobar2000.h"
2 
3 
4 
5 bool contextmenu_item::item_get_display_data_root(pfc::string_base & p_out,unsigned & p_displayflags,unsigned p_index,const pfc::list_base_const_t<metadb_handle_ptr> & p_data,const GUID & p_caller)
6 {
7  bool status = false;
8  pfc::ptrholder_t<contextmenu_item_node_root> root ( instantiate_item(p_index,p_data,p_caller) );
9  if (root.is_valid()) status = root->get_display_data(p_out,p_displayflags,p_data,p_caller);
10  return status;
11 }
12 
13 
14 static contextmenu_item_node * g_find_node(const GUID & p_guid,contextmenu_item_node * p_parent)
15 {
16  if (p_parent->get_guid() == p_guid) return p_parent;
17  else if (p_parent->get_type() == contextmenu_item_node::TYPE_POPUP)
18  {
19  t_size n, m = p_parent->get_children_count();
20  for(n=0;n<m;n++)
21  {
22  contextmenu_item_node * temp = g_find_node(p_guid,p_parent->get_child(n));
23  if (temp) return temp;
24  }
25  return 0;
26  }
27  else return 0;
28 }
29 
30 bool contextmenu_item::item_get_display_data(pfc::string_base & p_out,unsigned & p_displayflags,unsigned p_index,const GUID & p_node,const pfc::list_base_const_t<metadb_handle_ptr> & p_data,const GUID & p_caller)
31 {
32  bool status = false;
33  pfc::ptrholder_t<contextmenu_item_node_root> root ( instantiate_item(p_index,p_data,p_caller) );
34  if (root.is_valid())
35  {
36  contextmenu_item_node * node = g_find_node(p_node,root.get_ptr());
37  if (node) status = node->get_display_data(p_out,p_displayflags,p_data,p_caller);
38  }
39  return status;
40 }
41 
42 
44  unsigned total = get_num_items();
45  if (total < 1) return pfc::guid_null; // hide the item
46  pfc::string_formatter path, base; this->get_item_default_path(0, base);
47  for(unsigned walk = 1; walk < total; ++walk) {
48  this->get_item_default_path(walk, path);
49  if (strcmp(path, base) != 0) return contextmenu_groups::legacy;
50  }
51  return static_api_ptr_t<contextmenu_group_manager>()->path_to_group(base);
52 }
53 
55  contextmenu_item_v2::ptr v2;
56  if (service_query_t(v2)) {
57  return v2->get_parent();
58  } else {
59  return get_parent_fallback();
60  }
61 }
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
virtual GUID get_guid()=0
Definition: pfc.h:71
virtual bool get_display_data(pfc::string_base &p_out, unsigned &p_displayflags, metadb_handle_list_cref p_data, const GUID &p_caller)=0
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)
Definition: menu_item.cpp:5
virtual contextmenu_item_node_root * instantiate_item(unsigned p_index, metadb_handle_list_cref p_data, const GUID &p_caller)=0
Instantiates a context menu item (including sub-node tree for items that contain dynamically-generate...
virtual unsigned get_num_items()=0
Retrieves number of menu items provided by this contextmenu_item implementation.
size_t t_size
Definition: int_types.h:48
string8_fastalloc string_formatter
Definition: string_base.h:615
bool is_valid() const
Definition: other.h:100
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)
Definition: menu_item.cpp:30
virtual t_type get_type()=0
GUID get_parent_()
Definition: menu_item.cpp:54
T * get_ptr() const
Definition: other.h:103
bool service_query_t(service_ptr_t< T > &p_out)
Queries whether the object supports specific interface and retrieves a pointer to that interface...
Definition: service.h:350
Assumes t_freefunc to never throw exceptions.
Definition: other.h:93
virtual contextmenu_item_node * get_child(t_size p_index)=0
static const GUID legacy
Definition: contextmenu.h:282
Helper template used to easily access core services. Usage: static_api_ptr_t<myclass> api; api->doso...
Definition: service.h:533
GUID get_parent_fallback()
Definition: menu_item.cpp:43
const GUID guid_null
Definition: guid.cpp:175
virtual t_size get_children_count()=0