foobar2000 SDK  2015-08-03
ui_element.cpp
Go to the documentation of this file.
1 #include "stdafx.h"
2 
3 
4 class CMyElemWindow : public ui_element_instance, public CWindowImpl<CMyElemWindow> {
5 public:
6  // ATL window class declaration. Replace class name with your own when reusing code.
7  DECLARE_WND_CLASS_EX(TEXT("{DC2917D5-1288-4434-A28C-F16CFCE13C4B}"),CS_VREDRAW | CS_HREDRAW,(-1));
8 
9  void initialize_window(HWND parent) {WIN32_OP(Create(parent,0,0,0,WS_EX_STATICEDGE) != NULL);}
10 
11  BEGIN_MSG_MAP(ui_element_dummy)
12  MESSAGE_HANDLER(WM_LBUTTONDOWN,OnLButtonDown);
13  MSG_WM_ERASEBKGND(OnEraseBkgnd)
14  MSG_WM_PAINT(OnPaint)
15  END_MSG_MAP()
16 
18  HWND get_wnd() {return *this;}
19  void set_configuration(ui_element_config::ptr config) {m_config = config;}
20  ui_element_config::ptr get_configuration() {return m_config;}
21  static GUID g_get_guid() {
22  // This is our GUID. Substitute with your own when reusing code.
23  static const GUID guid_myelem = { 0xb46dc166, 0x88f3, 0x4b45, { 0x9f, 0x77, 0xab, 0x33, 0xf4, 0xc3, 0xf2, 0xe4 } };
24  return guid_myelem;
25  }
27  static void g_get_name(pfc::string_base & out) {out = "Sample UI Element";}
28  static ui_element_config::ptr g_get_default_configuration() {return ui_element_config::g_create_empty(g_get_guid());}
29  static const char * g_get_description() {return "This is a sample UI Element.";}
30 
31  void notify(const GUID & p_what, t_size p_param1, const void * p_param2, t_size p_param2size);
32 private:
33  LRESULT OnLButtonDown(UINT,WPARAM,LPARAM,BOOL&) {m_callback->request_replace(this);return 0;}
34  void OnPaint(CDCHandle);
35  BOOL OnEraseBkgnd(CDCHandle);
36  ui_element_config::ptr m_config;
37 protected:
38  // this must be declared as protected for ui_element_impl_withpopup<> to work.
40 };
41 void CMyElemWindow::notify(const GUID & p_what, t_size p_param1, const void * p_param2, t_size p_param2size) {
43  // we use global colors and fonts - trigger a repaint whenever these change.
44  Invalidate();
45  }
46 }
47 CMyElemWindow::CMyElemWindow(ui_element_config::ptr config,ui_element_instance_callback_ptr p_callback) : m_callback(p_callback), m_config(config) {
48 }
49 
51  CRect rc; WIN32_OP_D( GetClientRect(&rc) );
52  CBrush brush;
53  WIN32_OP_D( brush.CreateSolidBrush( m_callback->query_std_color(ui_color_background) ) != NULL );
54  WIN32_OP_D( dc.FillRect(&rc, brush) );
55  return TRUE;
56 }
57 void CMyElemWindow::OnPaint(CDCHandle) {
58  CPaintDC dc(*this);
59  dc.SetTextColor( m_callback->query_std_color(ui_color_text) );
60  dc.SetBkMode(TRANSPARENT);
61  SelectObjectScope fontScope(dc, (HGDIOBJ) m_callback->query_font_ex(ui_font_default) );
62  const UINT format = DT_NOPREFIX | DT_CENTER | DT_VCENTER | DT_SINGLELINE;
63  CRect rc;
64  WIN32_OP_D( GetClientRect(&rc) );
65  WIN32_OP_D( dc.DrawText(_T("This is a sample element."), -1, &rc, format) > 0 );
66 }
67 
68 // ui_element_impl_withpopup autogenerates standalone version of our component and proper menu commands. Use ui_element_impl instead if you don't want that.
69 class ui_element_myimpl : public ui_element_impl_withpopup<CMyElemWindow> {};
70 
void notify(const GUID &p_what, t_size p_param1, const void *p_param2, t_size p_param2size)
Used by host to notify the element about various events. See ui_element_notify_* GUIDs for possible p...
Definition: ui_element.cpp:41
static const GUID ui_element_subclass_utility
Definition: ui_element.h:569
Configuration of a UI element.
Definition: ui_element.h:2
static const GUID ui_color_background
Definition: ui_element.h:87
static const GUID ui_element_notify_colors_changed
Dispatched through ui_element_instance::notify() when host changes color settings. Other parameters are not used and should be set to zero.
Definition: ui_element.h:533
static GUID g_get_guid()
Definition: ui_element.cpp:21
static const GUID ui_font_default
Definition: ui_element.h:91
Definition: pfc.h:71
BOOL OnEraseBkgnd(CDCHandle)
Definition: ui_element.cpp:50
static ui_element_config::ptr g_get_default_configuration()
Definition: ui_element.cpp:28
static service_factory_single_t< ui_element_myimpl > g_ui_element_myimpl_factory
Definition: ui_element.cpp:71
typedef BOOL(WINAPI *pPowerSetRequest_t)(__in HANDLE PowerRequest
static const char * g_get_description()
Definition: ui_element.cpp:29
ui_element_config::ptr m_config
Definition: ui_element.cpp:36
LRESULT OnLButtonDown(UINT, WPARAM, LPARAM, BOOL &)
Definition: ui_element.cpp:33
static const GUID ui_element_notify_font_changed
Definition: ui_element.h:534
static const GUID ui_color_text
Definition: ui_element.h:86
size_t t_size
Definition: int_types.h:48
Instance of a UI element.
Definition: ui_element.h:270
void OnPaint(CDCHandle)
Definition: ui_element.cpp:57
const ui_element_instance_callback_ptr m_callback
Definition: ui_element.cpp:39
void set_configuration(ui_element_config::ptr config)
Alters element&#39;s current configuration. Specified ui_element_config&#39;s GUID must be the same as this e...
Definition: ui_element.cpp:19
DECLARE_WND_CLASS_EX(TEXT("{DC2917D5-1288-4434-A28C-F16CFCE13C4B}"), CS_VREDRAW|CS_HREDRAW,(-1))
static void g_get_name(pfc::string_base &out)
Definition: ui_element.cpp:27
ui_element_config::ptr get_configuration()
Retrieves element&#39;s current configuration. Returned object&#39;s GUID must be set to your element&#39;s GUID ...
Definition: ui_element.cpp:20
static GUID g_get_subclass()
Definition: ui_element.cpp:26
Autopointer class to be used with all services. Manages reference counter calls behind-the-scenes.
Definition: service.h:55
void initialize_window(HWND parent)
Definition: ui_element.cpp:9
static service_ptr_t< ui_element_config > g_create_empty(const GUID &id=pfc::guid_null)
Definition: ui_element.h:20
virtual HWND get_wnd()=0
Returns ui_element_instance&#39;s window handle. UI Element&#39;s window must be created when the ui_element_...
BEGIN_MSG_MAP(ui_element_dummy) MESSAGE_HANDLER(WM_LBUTTONDOWN