foobar2000 SDK  2015-01-14
ui_element.cpp
Go to the documentation of this file.
1 #include "foobar2000.h"
2 
3 
4 namespace {
5  class ui_element_config_impl : public ui_element_config {
6  public:
7  ui_element_config_impl(const GUID & guid) : m_guid(guid) {}
8  ui_element_config_impl(const GUID & guid, const void * buffer, t_size size) : m_guid(guid) {
9  m_content.set_data_fromptr(reinterpret_cast<const t_uint8*>(buffer),size);
10  }
11 
12  void * get_data_var() {return m_content.get_ptr();}
13  void set_data_size(t_size size) {m_content.set_size(size);}
14 
15  GUID get_guid() const {return m_guid;}
16  const void * get_data() const {return m_content.get_ptr();}
17  t_size get_data_size() const {return m_content.get_size();}
18  private:
19  const GUID m_guid;
20  pfc::array_t<t_uint8> m_content;
21  };
22 
23 }
24 
26  return new service_impl_t<ui_element_config_impl>(id,data,size);
27 }
28 
31  data->set_data_size(bytes);
32  in->read_object(data->get_data_var(),bytes,abort);
33  return data;
34 }
35 
37  if (bytes < sizeof(GUID)) throw exception_io_data_truncation();
38  GUID id; stream_reader_formatter<>(*in,abort) >> id;
39  return g_create(id,in,bytes - sizeof(GUID),abort);
40 }
41 
42 ui_element_config::ptr ui_element_config_parser::subelement(t_size size) {
44 }
45 ui_element_config::ptr ui_element_config_parser::subelement(const GUID & id, t_size dataSize) {
46  return ui_element_config::g_create(id, &m_stream, dataSize, m_abort);
47 }
48 
50  stream_reader_memblock_ref stream(data,size);
51  return g_create(&stream,size,abort_callback_dummy());
52 }
53 
56  p_out = "Playlist Renderers"; return true;
58  p_out = "Media Library Viewers"; return true;
60  p_out = "Selection Information"; return true;
62  p_out = "Playback Visualization"; return true;
64  p_out = "Playback Information"; return true;
65  } else if (id == ui_element_subclass_utility) {
66  p_out = "Utility"; return true;
67  } else if (id == ui_element_subclass_containers) {
68  p_out = "Containers"; return true;
69  } else {
70  return false;
71  }
72 }
73 
76 }
77 
79 #ifdef _WIN32
80  t_ui_color ret;
81  if (query_color(p_what,ret)) return ret;
82  int idx = ui_color_to_sys_color_index(p_what);
83  if (idx < 0) return 0;//should not be triggerable
84  return GetSysColor(idx);
85 #else
86 #error portme
87 #endif
88 }
89 
91  return service_by_guid(out, id);
92 }
93 
94 bool ui_element::g_get_name(pfc::string_base & p_out,const GUID & p_guid) {
95  ui_element::ptr ptr; if (!g_find(ptr,p_guid)) return false;
96  ptr->get_name(p_out); return true;
97 }
98 
100  ui_element_instance_callback_v2::ptr v2;
101  if (!this->service_query_t(v2)) {
102  PFC_ASSERT(!"Should not get here - somebody implemented ui_element_instance_callback but not ui_element_instance_callback_v2.");
103  return true;
104  }
105  return v2->is_elem_visible(elem);
106 }
107 
109  return notify_(source, ui_element_host_notify_set_elem_label, 0, label, strlen(label)) != 0;
110 }
111 
113  return (t_uint32) notify_(source, ui_element_host_notify_get_dialog_texture, 0, NULL, 0);
114 }
115 
117  return notify_(source, ui_element_host_notify_is_border_needed, 0, NULL, 0) != 0;
118 }
119 
120 t_size ui_element_instance_callback::notify_(ui_element_instance * source, const GUID & what, t_size param1, const void * param2, t_size param2size) {
121  ui_element_instance_callback_v3::ptr v3;
122  if (!this->service_query_t(v3)) { PFC_ASSERT(!"Outdated UI Element host implementation"); return 0; }
123  return v3->notify(source, what, param1, param2, param2size);
124 }
static const GUID ui_element_subclass_utility
Definition: ui_element.h:585
Configuration of a UI element.
Definition: ui_element.h:2
Template implementing reference-counting features of service_base. Intended for dynamic instantiation...
Definition: service_impl.h:4
bool ui_element_subclass_description(const GUID &id, pfc::string_base &p_out)
Definition: ui_element.cpp:54
static bool service_by_guid(service_ptr_t< what > &out, const GUID &theID)
Definition: service.h:738
virtual const void * get_data() const =0
Returns raw configuration data pointer.
Definition: pfc.h:53
bool is_elem_visible_(service_ptr_t< class ui_element_instance > elem)
Definition: ui_element.cpp:99
bool is_border_needed(ui_element_instance *source)
Definition: ui_element.cpp:116
static const GUID ui_element_host_notify_set_elem_label
Set to ui_element_instance_callback_v3 to set our element's label. Param1 is ignored, param2 is a pointer to a UTF-8 string containing the new label. Return value is 1 if the label is user-visible, 0 if the host does not support displaying overridden labels.
Definition: ui_element.h:561
abort_callback_impl abort_callback_dummy
virtual t_size get_data_size() const =0
Returns raw configuration data size, in bytes.
static const GUID ui_element_host_notify_get_dialog_texture
Definition: ui_element.h:562
ui_element_config::ptr subelement(t_size size)
Definition: ui_element.cpp:42
virtual bool query_color(const GUID &p_what, t_ui_color &p_out)=0
Returns true on success, false when the color is undefined and defaults such as global windows settin...
static const GUID ui_element_host_notify_is_border_needed
Definition: ui_element.h:563
COLORREF t_ui_color
Definition: ui_element.h:82
virtual GUID get_subclass()=0
Retrieves subclass GUID of the element. Typically one of ui_element_subclass_* values, but you can create your own custom subclasses. Subclass GUIDs are used for various purposes such as focusing an UI element that provides specific functionality.
bool set_elem_label(ui_element_instance *source, const char *label)
Definition: ui_element.cpp:108
t_ui_color query_std_color(const GUID &p_what)
Helper - a wrapper around query_color(), if the color is not user-overridden, returns relevant system...
Definition: ui_element.cpp:78
size_t t_size
Definition: int_types.h:48
static int ui_color_to_sys_color_index(const GUID &p_guid)
Definition: ui_element.h:102
static const GUID ui_element_subclass_selection_information
Definition: ui_element.h:582
static const GUID ui_element_subclass_playback_information
Definition: ui_element.h:584
static const GUID ui_element_subclass_containers
Definition: ui_element.h:581
static const GUID ui_element_subclass_media_library_viewers
Definition: ui_element.h:580
t_uint32 get_dialog_texture(ui_element_instance *source)
Definition: ui_element.cpp:112
static bool g_find(service_ptr_t< ui_element > &out, const GUID &id)
Definition: ui_element.cpp:90
Instance of a UI element.
Definition: ui_element.h:270
static const GUID ui_element_subclass_playlist_renderers
Definition: ui_element.h:579
static const GUID ui_element_subclass_playback_visualisation
Definition: ui_element.h:583
static bool g_get_name(pfc::string_base &p_out, const GUID &p_guid)
Definition: ui_element.cpp:94
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
Autopointer class to be used with all services. Manages reference counter calls behind-the-scenes.
Definition: service.h:55
t_size notify_(ui_element_instance *source, const GUID &what, t_size param1, const void *param2, t_size param2size)
Definition: ui_element.cpp:120
virtual bool get_element_group(pfc::string_base &p_out)
Retrieves a human-readable description of the element's function to use for grouping in the element l...
Definition: ui_element.cpp:74
virtual GUID get_guid() const =0
Returns GUID of the UI element this configuration data belongs to.
uint32_t t_uint32
Definition: int_types.h:5
static service_ptr_t< ui_element_config > g_create(const GUID &id, const void *data, t_size size)
Helper.
Definition: ui_element.cpp:25