foobar2000 SDK  2015-08-03
Public Types | Public Member Functions | Private Member Functions | Private Attributes
_cfg_dropdown_history_baseabstract

#include <dropdown_helper.h>

+ Inheritance diagram for _cfg_dropdown_history_base:

Public Types

enum  { separator = '\n' }
 

Public Member Functions

 _cfg_dropdown_history_base (unsigned p_max)
 
bool add_item (const char *item)
 
bool add_item (const char *item, HWND combobox)
 
virtual void get_state (pfc::string_base &out) const =0
 
bool is_empty ()
 
bool on_context (HWND wnd, LPARAM coords)
 
void on_init (HWND ctrl, const char *initVal)
 
virtual void set_state (const char *val)=0
 
void setup_dropdown (HWND wnd)
 
void setup_dropdown (HWND wnd, UINT id)
 

Private Member Functions

void build_list (pfc::ptr_list_t< char > &out)
 
void parse_list (const pfc::ptr_list_t< char > &src)
 

Private Attributes

const unsigned m_max
 

Detailed Description

Definition at line 6 of file dropdown_helper.h.

Member Enumeration Documentation

anonymous enum
Enumerator
separator 

Definition at line 12 of file dropdown_helper.h.

Constructor & Destructor Documentation

_cfg_dropdown_history_base::_cfg_dropdown_history_base ( unsigned  p_max)
inline

Definition at line 15 of file dropdown_helper.h.

15 : m_max(p_max) {}

Member Function Documentation

bool _cfg_dropdown_history_base::add_item ( const char *  item)

Definition at line 52 of file dropdown_helper.cpp.

53 {
54  if (!item || !*item) return false;
55  pfc::string8 meh;
56  if (strchr(item,separator))
57  {
58  uReplaceChar(meh,item,-1,separator,'|',false);
59  item = meh;
60  }
62  build_list(list);
63  unsigned n;
64  bool found = false;
65  for(n=0;n<list.get_count();n++)
66  {
67  if (!strcmp(list[n],item))
68  {
69  char* temp = list.remove_by_idx(n);
70  list.insert_item(temp,0);
71  found = true;
72  }
73  }
74 
75  if (!found)
76  {
77  while(list.get_count() > m_max) list.delete_by_idx(list.get_count()-1);
78  list.insert_item(_strdup(item),0);
79  }
80  parse_list(list);
81  list.free_all();
82  return found;
83 }
void build_list(pfc::ptr_list_t< char > &out)
t_size get_count() const
Definition: list.h:365
T remove_by_idx(t_size idx)
Definition: list.h:331
t_size insert_item(const t_in &item, t_size idx)
Definition: list.h:323
void free_all()
Definition: ptr_list.h:14
t_size uReplaceChar(pfc::string_base &out, const char *src, t_size src_len, unsigned c1, unsigned c2, bool casesens)
Definition: shared.h:394
void delete_by_idx(t_size p_index)
Definition: ptr_list.h:19
void parse_list(const pfc::ptr_list_t< char > &src)
bool _cfg_dropdown_history_base::add_item ( const char *  item,
HWND  combobox 
)

Definition at line 85 of file dropdown_helper.cpp.

85  {
86  const bool state = add_item(item);
87  if (state) uSendMessageText(combobox, CB_ADDSTRING, 0, item);
88  return state;
89 }
LRESULT SHARED_EXPORT uSendMessageText(HWND wnd, UINT msg, WPARAM wp, const char *text)
bool add_item(const char *item)
void _cfg_dropdown_history_base::build_list ( pfc::ptr_list_t< char > &  out)
private

Definition at line 6 of file dropdown_helper.cpp.

7 {
8  pfc::string8 temp; get_state(temp);
9  const char * src = temp;
10  while(*src)
11  {
12  int ptr = 0;
13  while(src[ptr] && src[ptr]!=separator) ptr++;
14  if (ptr>0)
15  {
16  out.add_item(pfc::strdup_n(src,ptr));
17  src += ptr;
18  }
19  while(*src==separator) src++;
20  }
21 }
virtual void get_state(pfc::string_base &out) const =0
t_size add_item(const T &item)
Definition: list.h:522
char * strdup_n(const char *src, t_size len)
Definition: string_base.cpp:75
virtual void _cfg_dropdown_history_base::get_state ( pfc::string_base out) const
pure virtual
bool _cfg_dropdown_history_base::is_empty ( )

Definition at line 91 of file dropdown_helper.cpp.

92 {
93  pfc::string8 temp; get_state(temp);
94  const char * src = temp;
95  while(*src)
96  {
97  if (*src!=separator) return false;
98  src++;
99  }
100  return true;
101 }
virtual void get_state(pfc::string_base &out) const =0
bool _cfg_dropdown_history_base::on_context ( HWND  wnd,
LPARAM  coords 
)

Definition at line 103 of file dropdown_helper.cpp.

103  {
104  try {
105  int coords_x = (short)LOWORD(coords), coords_y = (short)HIWORD(coords);
106  if (coords_x == -1 && coords_y == -1)
107  {
108  RECT asdf;
109  GetWindowRect(wnd,&asdf);
110  coords_x = (asdf.left + asdf.right) / 2;
111  coords_y = (asdf.top + asdf.bottom) / 2;
112  }
113  enum {ID_ERASE_ALL = 1, ID_ERASE_ONE };
114  HMENU menu = CreatePopupMenu();
115  uAppendMenu(menu,MF_STRING,ID_ERASE_ALL,"Wipe history");
116  {
117  pfc::string8 tempvalue;
118  uGetWindowText(wnd,tempvalue);
119  if (!tempvalue.is_empty())
120  uAppendMenu(menu,MF_STRING,ID_ERASE_ONE,"Remove this history item");
121  }
122  int cmd = TrackPopupMenu(menu,TPM_RIGHTBUTTON|TPM_NONOTIFY|TPM_RETURNCMD,coords_x,coords_y,0,wnd,0);
123  DestroyMenu(menu);
124  switch(cmd)
125  {
126  case ID_ERASE_ALL:
127  {
128  set_state("");
129  pfc::string8 value;//preserve old value while wiping dropdown list
130  uGetWindowText(wnd,value);
131  uSendMessage(wnd,CB_RESETCONTENT,0,0);
132  uSetWindowText(wnd,value);
133  return true;
134  }
135  case ID_ERASE_ONE:
136  {
137  pfc::string8 value;
138  uGetWindowText(wnd,value);
139 
141  build_list(list);
142  bool found = false;
143  for(t_size n=0;n<list.get_size();n++)
144  {
145  if (!strcmp(value,list[n]))
146  {
147  free(list[n]);
148  list.remove_by_idx(n);
149  found = true;
150  break;
151  }
152  }
153  if (found) parse_list(list);
154  g_setup_dropdown_fromlist(wnd,list);
155  list.free_all();
156  return found;
157  }
158  }
159  } catch(...) {}
160  return false;
161 }
t_size get_size() const
Definition: list.h:366
BOOL SHARED_EXPORT uGetWindowText(HWND wnd, pfc::string_base &out)
virtual void set_state(const char *val)=0
void build_list(pfc::ptr_list_t< char > &out)
size_t t_size
Definition: int_types.h:48
T remove_by_idx(t_size idx)
Definition: list.h:331
BOOL SHARED_EXPORT uSetWindowText(HWND wnd, const char *p_text)
BOOL SHARED_EXPORT uAppendMenu(HMENU menu, UINT flags, UINT_PTR id, const char *content)
bool is_empty() const
Definition: string_base.h:213
void free_all()
Definition: ptr_list.h:14
void parse_list(const pfc::ptr_list_t< char > &src)
void _cfg_dropdown_history_base::on_init ( HWND  ctrl,
const char *  initVal 
)
inline

Definition at line 16 of file dropdown_helper.h.

16  {
17  add_item(initVal); setup_dropdown(ctrl); uSetWindowText(ctrl, initVal);
18  }
BOOL SHARED_EXPORT uSetWindowText(HWND wnd, const char *p_text)
bool add_item(const char *item)
void _cfg_dropdown_history_base::parse_list ( const pfc::ptr_list_t< char > &  src)
private

Definition at line 23 of file dropdown_helper.cpp.

24 {
25  t_size n;
27  for(n=0;n<src.get_count();n++)
28  {
29  temp.add_string(src[n]);
30  temp.add_char(separator);
31  }
32  set_state(temp);
33 }
virtual void set_state(const char *val)=0
t_size get_count() const
Definition: list.h:365
size_t t_size
Definition: int_types.h:48
string8_t< pfc::alloc_fast_aggressive > string8_fastalloc
Definition: string_base.h:436
virtual void _cfg_dropdown_history_base::set_state ( const char *  val)
pure virtual
void _cfg_dropdown_history_base::setup_dropdown ( HWND  wnd)

Definition at line 44 of file dropdown_helper.cpp.

45 {
47  build_list(list);
48  g_setup_dropdown_fromlist(wnd,list);
49  list.free_all();
50 }
void build_list(pfc::ptr_list_t< char > &out)
void free_all()
Definition: ptr_list.h:14
void _cfg_dropdown_history_base::setup_dropdown ( HWND  wnd,
UINT  id 
)
inline

Definition at line 20 of file dropdown_helper.h.

20 {setup_dropdown(GetDlgItem(wnd,id));}

Field Documentation

const unsigned _cfg_dropdown_history_base::m_max
private

Definition at line 8 of file dropdown_helper.h.


The documentation for this class was generated from the following files: