foobar2000 SDK  2015-01-14
dropdown_helper.h
Go to the documentation of this file.
1 #ifdef _WIN32
2 
3 #ifndef _DROPDOWN_HELPER_H_
4 #define _DROPDOWN_HELPER_H_
5 
7 {
8  const unsigned m_max;
10  void parse_list(const pfc::ptr_list_t<char> & src);
11 public:
12  enum {separator = '\n'};
13  virtual void set_state(const char * val) = 0;
14  virtual void get_state(pfc::string_base & out) const = 0;
15  _cfg_dropdown_history_base(unsigned p_max) : m_max(p_max) {}
16  void on_init(HWND ctrl, const char * initVal) {
17  add_item(initVal); setup_dropdown(ctrl); uSetWindowText(ctrl, initVal);
18  }
19  void setup_dropdown(HWND wnd);
20  void setup_dropdown(HWND wnd,UINT id) {setup_dropdown(GetDlgItem(wnd,id));}
21  bool add_item(const char * item); //returns true when the content has changed, false when not (the item was already on the list)
22  bool add_item(const char * item, HWND combobox); //immediately adds the item to the combobox
23  bool is_empty();
24  bool on_context(HWND wnd,LPARAM coords); //returns true when the content has changed
25 };
26 
28 public:
29  cfg_dropdown_history(const GUID & p_guid,unsigned p_max = 10,const char * init_vals = "") : _cfg_dropdown_history_base(p_max), m_state(p_guid, init_vals) {}
30  void set_state(const char * val) {m_state = val;}
31  void get_state(pfc::string_base & out) const {out = m_state;}
32 private:
34 };
35 
37 public:
38  cfg_dropdown_history_mt(const GUID & p_guid,unsigned p_max = 10,const char * init_vals = "") : _cfg_dropdown_history_base(p_max), m_state(p_guid, init_vals) {}
39  void set_state(const char * val) {m_state.set(val);}
40  void get_state(pfc::string_base & out) const {m_state.get(out);}
41 private:
43 };
44 
45 // ATL-compatible message map entry macro for installing dropdown list context menus.
46 #define DROPDOWN_HISTORY_HANDLER(ctrlID,var) \
47  if(uMsg == WM_CONTEXTMENU) { \
48  const HWND source = (HWND) wParam; \
49  if (source != NULL && source == CWindow(hWnd).GetDlgItem(ctrlID)) { \
50  var.on_context(source,lParam); \
51  lResult = 0; \
52  return TRUE; \
53  } \
54  }
55 
56 #endif //_DROPDOWN_HELPER_H_
57 
58 #endif // _WIN32
cfg_dropdown_history_mt(const GUID &p_guid, unsigned p_max=10, const char *init_vals="")
Definition: pfc.h:53
void set(const char *val, t_size valLen=~0)
Definition: cfg_var.h:131
void set_state(const char *val)
virtual void set_state(const char *val)=0
cfg_dropdown_history(const GUID &p_guid, unsigned p_max=10, const char *init_vals="")
void build_list(pfc::ptr_list_t< char > &out)
void get(pfc::string_base &out) const
Definition: cfg_var.h:127
virtual void get_state(pfc::string_base &out) const =0
void get_state(pfc::string_base &out) const
_cfg_dropdown_history_base(unsigned p_max)
void set_state(const char *val)
BOOL SHARED_EXPORT uSetWindowText(HWND wnd, const char *p_text)
void get_state(pfc::string_base &out) const
String config variable. Stored in the stream with int32 header containing size in bytes...
Definition: cfg_var.h:97
void on_init(HWND ctrl, const char *initVal)
bool on_context(HWND wnd, LPARAM coords)
bool add_item(const char *item)
void parse_list(const pfc::ptr_list_t< char > &src)
void setup_dropdown(HWND wnd, UINT id)