foobar2000 SDK  2015-08-03
Functions
listview_helper Namespace Reference

Functions

bool ensure_visible (HWND p_listview, unsigned p_index)
 
void get_item_text (HWND p_listview, unsigned p_index, unsigned p_column, pfc::string_base &p_out)
 
unsigned insert_column (HWND p_listview, unsigned p_index, const char *p_name, unsigned p_width_dlu)
 
unsigned insert_item (HWND p_listview, unsigned p_index, const char *p_name, LPARAM p_param)
 
unsigned insert_item2 (HWND p_listview, unsigned p_index, const char *col0, const char *col1, LPARAM p_param)
 
unsigned insert_item3 (HWND p_listview, unsigned p_index, const char *col0, const char *col1, const char *col2, LPARAM p_param)
 
bool is_item_selected (HWND p_listview, unsigned p_index)
 
bool select_single_item (HWND p_listview, unsigned p_index)
 
void set_item_selection (HWND p_listview, unsigned p_index, bool p_state)
 
bool set_item_text (HWND p_listview, unsigned p_index, unsigned p_column, const char *p_name)
 

Function Documentation

bool listview_helper::ensure_visible ( HWND  p_listview,
unsigned  p_index 
)

Definition at line 112 of file listview_helper.cpp.

113  {
114  return uSendMessage(p_listview,LVM_ENSUREVISIBLE,p_index,FALSE) ? true : false;
115  }
void listview_helper::get_item_text ( HWND  p_listview,
unsigned  p_index,
unsigned  p_column,
pfc::string_base p_out 
)

Definition at line 60 of file listview_helper.cpp.

60  {
61  enum {buffer_length = 1024*64};
62  pfc::array_t<TCHAR> buffer; buffer.set_size(buffer_length);
63  ListView_GetItemText(p_listview,p_index,p_column,buffer.get_ptr(),buffer_length);
64  p_out = pfc::stringcvt::string_utf8_from_os(buffer.get_ptr(),buffer_length);
65  }
const t_item * get_ptr() const
Definition: array.h:213
string_utf8_from_wide string_utf8_from_os
Definition: string_conv.h:517
void set_size(t_size p_size)
Definition: array.h:104
unsigned listview_helper::insert_column ( HWND  p_listview,
unsigned  p_index,
const char *  p_name,
unsigned  p_width_dlu 
)

Definition at line 42 of file listview_helper.cpp.

43  {
44  pfc::stringcvt::string_os_from_utf8 os_string_temp(p_name);
45 
46  RECT rect = {0,0,p_width_dlu,0};
47  MapDialogRect(GetParent(p_listview),&rect);
48 
49  LVCOLUMN data = {};
50  data.mask = LVCF_TEXT | LVCF_WIDTH | LVCF_FMT;
51  data.fmt = LVCFMT_LEFT;
52  data.cx = rect.right;
53  data.pszText = const_cast<TCHAR*>(os_string_temp.get_ptr());
54 
55  LRESULT ret = uSendMessage(p_listview,LVM_INSERTCOLUMN,p_index,(LPARAM)&data);
56  if (ret < 0) return ~0;
57  else return (unsigned) ret;
58  }
unsigned listview_helper::insert_item ( HWND  p_listview,
unsigned  p_index,
const char *  p_name,
LPARAM  p_param 
)

Definition at line 8 of file listview_helper.cpp.

9  {
10  if (p_index == ~0) p_index = ListView_GetItemCount(p_listview);
11  LVITEM item = {};
12 
13  pfc::stringcvt::string_os_from_utf8 os_string_temp(p_name);
14 
15  item.mask = LVIF_TEXT | LVIF_PARAM;
16  item.iItem = p_index;
17  item.lParam = p_param;
18  item.pszText = const_cast<TCHAR*>(os_string_temp.get_ptr());
19 
20  LRESULT ret = uSendMessage(p_listview,LVM_INSERTITEM,0,(LPARAM)&item);
21  if (ret < 0) return ~0;
22  else return (unsigned) ret;
23  }
unsigned listview_helper::insert_item2 ( HWND  p_listview,
unsigned  p_index,
const char *  col0,
const char *  col1,
LPARAM  p_param 
)

Definition at line 25 of file listview_helper.cpp.

25  {
26  unsigned i = insert_item( p_listview, p_index, col0, p_param );
27  if (i != ~0) {
28  set_item_text( p_listview, i, 1, col1 );
29  }
30  return i;
31  }
bool set_item_text(HWND p_listview, unsigned p_index, unsigned p_column, const char *p_name)
unsigned insert_item(HWND p_listview, unsigned p_index, const char *p_name, LPARAM p_param)
unsigned listview_helper::insert_item3 ( HWND  p_listview,
unsigned  p_index,
const char *  col0,
const char *  col1,
const char *  col2,
LPARAM  p_param 
)

Definition at line 33 of file listview_helper.cpp.

33  {
34  unsigned i = insert_item( p_listview, p_index, col0, p_param );
35  if (i != ~0) {
36  set_item_text( p_listview, i, 1, col1 );
37  set_item_text( p_listview, i, 2, col2 );
38  }
39  return i;
40  }
bool set_item_text(HWND p_listview, unsigned p_index, unsigned p_column, const char *p_name)
unsigned insert_item(HWND p_listview, unsigned p_index, const char *p_name, LPARAM p_param)
bool listview_helper::is_item_selected ( HWND  p_listview,
unsigned  p_index 
)

Definition at line 80 of file listview_helper.cpp.

81  {
82  LVITEM item = {};
83  item.mask = LVIF_STATE;
84  item.iItem = p_index;
85  item.stateMask = LVIS_SELECTED;
86  if (!uSendMessage(p_listview,LVM_GETITEM,0,(LPARAM)&item)) return false;
87  return (item.state & LVIS_SELECTED) ? true : false;
88  }
bool listview_helper::select_single_item ( HWND  p_listview,
unsigned  p_index 
)

Definition at line 99 of file listview_helper.cpp.

100  {
101  LRESULT temp = SendMessage(p_listview,LVM_GETITEMCOUNT,0,0);
102  if (temp < 0) return false;
103  ListView_SetSelectionMark(p_listview,p_index);
104  unsigned n; const unsigned m = pfc::downcast_guarded<unsigned>(temp);
105  for(n=0;n<m;n++) {
106  enum {mask = LVIS_FOCUSED | LVIS_SELECTED};
107  ListView_SetItemState(p_listview,n,n == p_index ? mask : 0, mask);
108  }
109  return ensure_visible(p_listview,p_index);
110  }
bool ensure_visible(HWND p_listview, unsigned p_index)
void listview_helper::set_item_selection ( HWND  p_listview,
unsigned  p_index,
bool  p_state 
)

Definition at line 90 of file listview_helper.cpp.

91  {
92  PFC_ASSERT( ::IsWindow(p_listview) );
93  LVITEM item = {};
94  item.stateMask = LVIS_SELECTED;
95  item.state = p_state ? LVIS_SELECTED : 0;
96  WIN32_OP_D( SendMessage(p_listview,LVM_SETITEMSTATE,(WPARAM)p_index,(LPARAM)&item) );
97  }
bool listview_helper::set_item_text ( HWND  p_listview,
unsigned  p_index,
unsigned  p_column,
const char *  p_name 
)

Definition at line 67 of file listview_helper.cpp.

68  {
69  LVITEM item = {};
70 
71  pfc::stringcvt::string_os_from_utf8 os_string_temp(p_name);
72 
73  item.mask = LVIF_TEXT;
74  item.iItem = p_index;
75  item.iSubItem = p_column;
76  item.pszText = const_cast<TCHAR*>(os_string_temp.get_ptr());
77  return uSendMessage(p_listview,LVM_SETITEM,0,(LPARAM)&item) ? true : false;
78  }