foobar2000 SDK  2015-08-03
Data Structures | Functions
menu_helpers Namespace Reference

Data Structures

class  guid_to_name_table
 
class  name_to_guid_table
 

Functions

bool context_get_description (const GUID &p_guid, pfc::string_base &out)
 
bool find_command_by_name (const char *p_name, service_ptr_t< contextmenu_item > &p_item, unsigned &p_index)
 
bool find_command_by_name (const char *p_name, GUID &p_command)
 
bool guid_from_name (const char *p_name, unsigned p_name_len, GUID &p_out)
 
bool is_command_checked_context (const GUID &p_command, const GUID &p_subcommand, const pfc::list_base_const_t< metadb_handle_ptr > &data)
 
bool is_command_checked_context_playlist (const GUID &p_command, const GUID &p_subcommand)
 
bool name_from_guid (const GUID &p_guid, pfc::string_base &p_out)
 
bool run_command_context (const GUID &p_command, const GUID &p_subcommand, const pfc::list_base_const_t< metadb_handle_ptr > &data)
 
bool run_command_context_ex (const GUID &p_command, const GUID &p_subcommand, const pfc::list_base_const_t< metadb_handle_ptr > &data, const GUID &caller)
 
bool run_command_context_now_playing (const GUID &p_command, const GUID &p_subcommand)
 
bool run_command_context_playlist (const GUID &p_command, const GUID &p_subcommand)
 
bool test_command_context (const GUID &p_guid)
 
void win32_auto_mnemonics (HMENU menu)
 

Function Documentation

bool menu_helpers::context_get_description ( const GUID p_guid,
pfc::string_base out 
)

Definition at line 4 of file menu_helpers.cpp.

4  {
6  if (!menu_item_resolver::g_resolve_context_command(p_guid, ptr, index)) return false;
7  bool rv = ptr->get_item_description(index, out);
8  if (!rv) out.reset();
9  return rv;
10 }
static bool g_resolve_context_command(const GUID &id, service_ptr_t< class contextmenu_item > &out, t_uint32 &out_index)
Autopointer class to be used with all services. Manages reference counter calls behind-the-scenes.
Definition: service.h:55
uint32_t t_uint32
Definition: int_types.h:5
bool menu_helpers::find_command_by_name ( const char *  p_name,
service_ptr_t< contextmenu_item > &  p_item,
unsigned &  p_index 
)

Definition at line 247 of file menu_helpers.cpp.

248 {
249  pfc::string8_fastalloc path,name;
252  if (e.first(ptr)) do {
253 // if (ptr->get_type()==type)
254  {
255  unsigned action,num_actions = ptr->get_num_items();
256  for(action=0;action<num_actions;action++)
257  {
258  ptr->get_item_default_path(action,path); ptr->get_item_name(action,name);
259  if (!path.is_empty()) path += "/";
260  path += name;
261  if (!stricmp_utf8(p_name,path))
262  {
263  p_item = ptr;
264  p_index = action;
265  return true;
266  }
267  }
268  }
269  } while(e.next(ptr));
270  return false;
271 
272 }
bool first(service_ptr_t< t_query > &p_out)
Definition: service.h:581
int SHARED_EXPORT stricmp_utf8(const char *p1, const char *p2)
Autopointer class to be used with all services. Manages reference counter calls behind-the-scenes.
Definition: service.h:55
bool next(service_ptr_t< t_query > &p_out)
Definition: service.h:587
string8_t< pfc::alloc_fast_aggressive > string8_fastalloc
Definition: string_base.h:436
bool menu_helpers::find_command_by_name ( const char *  p_name,
GUID p_command 
)

Definition at line 274 of file menu_helpers.cpp.

275 {
277  unsigned index;
278  bool ret = find_command_by_name(p_name,item,index);
279  if (ret) p_command = item->get_item_guid(index);
280  return ret;
281 }
bool find_command_by_name(const char *p_name, service_ptr_t< contextmenu_item > &p_item, unsigned &p_index)
Autopointer class to be used with all services. Manages reference counter calls behind-the-scenes.
Definition: service.h:55
bool menu_helpers::guid_from_name ( const char *  p_name,
unsigned  p_name_len,
GUID p_out 
)

Definition at line 88 of file menu_helpers.cpp.

89 {
92  pfc::string8_fastalloc nametemp;
93  while(e.next(ptr))
94  {
95  unsigned n, m = ptr->get_num_items();
96  for(n=0;n<m;n++)
97  {
98  ptr->get_item_name(n,nametemp);
99  if (!strcmp_ex(nametemp,~0,p_name,p_name_len))
100  {
101  p_out = ptr->get_item_guid(n);
102  return true;
103  }
104  }
105  }
106  return false;
107 }
int strcmp_ex(const char *p1, t_size n1, const char *p2, t_size n2)
Autopointer class to be used with all services. Manages reference counter calls behind-the-scenes.
Definition: service.h:55
bool next(service_ptr_t< t_query > &p_out)
Definition: service.h:587
string8_t< pfc::alloc_fast_aggressive > string8_fastalloc
Definition: string_base.h:436
bool menu_helpers::is_command_checked_context ( const GUID p_command,
const GUID p_subcommand,
const pfc::list_base_const_t< metadb_handle_ptr > &  data 
)

Definition at line 53 of file menu_helpers.cpp.

54 {
55  return g_is_checked(p_command,p_subcommand,data,contextmenu_item::caller_undefined);
56 }
static const GUID caller_undefined
Definition: contextmenu.h:139
bool menu_helpers::is_command_checked_context_playlist ( const GUID p_command,
const GUID p_subcommand 
)

Definition at line 58 of file menu_helpers.cpp.

59 {
60  metadb_handle_list temp;
62  api->activeplaylist_get_selected_items(temp);
63  return g_is_checked(p_command,p_subcommand,temp,contextmenu_item::caller_playlist);
64 }
static const GUID caller_playlist
Deprecated - use caller_active_playlist_selection instead.
Definition: contextmenu.h:136
Helper template used to easily access core services. Usage: static_api_ptr_t<myclass> api; api->doso...
Definition: service.h:533
bool menu_helpers::name_from_guid ( const GUID p_guid,
pfc::string_base p_out 
)

Definition at line 109 of file menu_helpers.cpp.

109  {
111  if (!menu_item_resolver::g_resolve_context_command(p_guid, ptr, index)) return false;
112  ptr->get_item_name(index, p_out);
113  return true;
114 }
static bool g_resolve_context_command(const GUID &id, service_ptr_t< class contextmenu_item > &out, t_uint32 &out_index)
Autopointer class to be used with all services. Manages reference counter calls behind-the-scenes.
Definition: service.h:55
uint32_t t_uint32
Definition: int_types.h:5
bool menu_helpers::run_command_context ( const GUID p_command,
const GUID p_subcommand,
const pfc::list_base_const_t< metadb_handle_ptr > &  data 
)

Definition at line 25 of file menu_helpers.cpp.

26 {
27  return run_context_command_internal(p_command,p_subcommand,data,contextmenu_item::caller_undefined);
28 }
static const GUID caller_undefined
Definition: contextmenu.h:139
bool menu_helpers::run_command_context_ex ( const GUID p_command,
const GUID p_subcommand,
const pfc::list_base_const_t< metadb_handle_ptr > &  data,
const GUID caller 
)

Definition at line 30 of file menu_helpers.cpp.

31 {
32  return run_context_command_internal(p_command,p_subcommand,data,caller);
33 }
bool menu_helpers::run_command_context_now_playing ( const GUID p_command,
const GUID p_subcommand 
)

Definition at line 80 of file menu_helpers.cpp.

81 {
82  metadb_handle_ptr item;
83  if (!static_api_ptr_t<playback_control>()->get_now_playing(item)) return false;//not playing
85 }
static const GUID caller_now_playing
Definition: contextmenu.h:138
bool run_command_context_ex(const GUID &p_command, const GUID &p_subcommand, const pfc::list_base_const_t< metadb_handle_ptr > &data, const GUID &caller)
bool menu_helpers::run_command_context_playlist ( const GUID p_command,
const GUID p_subcommand 
)

Definition at line 72 of file menu_helpers.cpp.

73 {
74  metadb_handle_list temp;
76  api->activeplaylist_get_selected_items(temp);
77  return run_command_context_ex(p_command,p_subcommand,temp,contextmenu_item::caller_playlist);
78 }
static const GUID caller_playlist
Deprecated - use caller_active_playlist_selection instead.
Definition: contextmenu.h:136
Helper template used to easily access core services. Usage: static_api_ptr_t<myclass> api; api->doso...
Definition: service.h:533
bool run_command_context_ex(const GUID &p_command, const GUID &p_subcommand, const pfc::list_base_const_t< metadb_handle_ptr > &data, const GUID &caller)
bool menu_helpers::test_command_context ( const GUID p_guid)

Definition at line 35 of file menu_helpers.cpp.

36 {
38  return menu_item_resolver::g_resolve_context_command(p_guid, ptr, index);
39 }
static bool g_resolve_context_command(const GUID &id, service_ptr_t< class contextmenu_item > &out, t_uint32 &out_index)
Autopointer class to be used with all services. Manages reference counter calls behind-the-scenes.
Definition: service.h:55
uint32_t t_uint32
Definition: int_types.h:5
void menu_helpers::win32_auto_mnemonics ( HMENU  menu)

Definition at line 224 of file menu_manager.cpp.

225 {
226  mnemonic_manager mgr;
227  unsigned n, m = GetMenuItemCount(menu);
228  pfc::string8_fastalloc temp,temp2;
229  for(n=0;n<m;n++)//first pass, check existing mnemonics
230  {
231  unsigned type = uGetMenuItemType(menu,n);
232  if (type==MFT_STRING)
233  {
234  uGetMenuString(menu,n,temp,MF_BYPOSITION);
235  mgr.check_string(temp);
236  }
237  }
238 
239  for(n=0;n<m;n++)
240  {
241  HMENU submenu = GetSubMenu(menu,n);
242  if (submenu) win32_auto_mnemonics(submenu);
243 
244  {
245  unsigned type = uGetMenuItemType(menu,n);
246  if (type==MFT_STRING)
247  {
248  unsigned state = submenu ? 0 : GetMenuState(menu,n,MF_BYPOSITION);
249  unsigned id = GetMenuItemID(menu,n);
250  uGetMenuString(menu,n,temp,MF_BYPOSITION);
251  if (mgr.process_string(temp,temp2))
252  {
253  uModifyMenu(menu,n,MF_BYPOSITION|MF_STRING|state,id,temp2);
254  }
255  }
256  }
257  }
258 }
void win32_auto_mnemonics(HMENU menu)
UINT SHARED_EXPORT uGetMenuItemType(HMENU menu, UINT position)
BOOL SHARED_EXPORT uModifyMenu(HMENU menu, UINT id, UINT flags, UINT newitem, const char *data)
BOOL SHARED_EXPORT uGetMenuString(HMENU menu, UINT id, pfc::string_base &out, UINT flag)
string8_t< pfc::alloc_fast_aggressive > string8_fastalloc
Definition: string_base.h:436