foobar2000 SDK  2015-08-03
Namespaces | Functions
listview_helper.h File Reference

Go to the source code of this file.

Namespaces

 listview_helper
 

Functions

bool listview_helper::ensure_visible (HWND p_listview, unsigned p_index)
 
void listview_helper::get_item_text (HWND p_listview, unsigned p_index, unsigned p_column, pfc::string_base &p_out)
 
unsigned listview_helper::insert_column (HWND p_listview, unsigned p_index, const char *p_name, unsigned p_width_dlu)
 
unsigned listview_helper::insert_item (HWND p_listview, unsigned p_index, const char *p_name, LPARAM p_param)
 
unsigned listview_helper::insert_item2 (HWND p_listview, unsigned p_index, const char *col0, const char *col1, 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)
 
bool listview_helper::is_item_selected (HWND p_listview, unsigned p_index)
 
int ListView_GetColumnCount (HWND listView)
 
void ListView_GetContextMenuPoint (HWND p_list, LPARAM p_coords, POINT &p_point, int &p_selection)
 
void ListView_GetContextMenuPoint (HWND p_list, POINT p_coords, POINT &p_point, int &p_selection)
 
static int ListView_GetFirstSelection (HWND p_listview)
 
static int ListView_GetFocusItem (HWND p_listview)
 
static int ListView_GetSingleSelection (HWND p_listview)
 
static bool ListView_IsItemSelected (HWND p_listview, int p_index)
 
bool listview_helper::select_single_item (HWND p_listview, unsigned p_index)
 
void listview_helper::set_item_selection (HWND p_listview, unsigned p_index, bool p_state)
 
bool listview_helper::set_item_text (HWND p_listview, unsigned p_index, unsigned p_column, const char *p_name)
 

Function Documentation

int ListView_GetColumnCount ( HWND  listView)

Definition at line 158 of file listview_helper.cpp.

158  {
159  if (!ProbeColumn(listView, 0)) return 0;
160  int hi = 1;
161  for(;;) {
162  if (!ProbeColumn(listView, hi)) break;
163  hi <<= 1;
164  if (hi <= 0) {
165  PFC_ASSERT(!"Shouldn't get here!");
166  return -1;
167  }
168  }
169  int lo = hi >> 1;
170  //lo is the highest known valid column, hi is the lowest known invalid, let's bsearch thru
171  while(lo + 1 < hi) {
172  PFC_ASSERT( lo < hi );
173  const int mid = lo + (hi - lo) / 2;
174  PFC_ASSERT( lo < mid && mid < hi );
175  if (ProbeColumn(listView, mid)) {
176  lo = mid;
177  } else {
178  hi = mid;
179  }
180  }
181  return hi;
182 }
static bool ProbeColumn(HWND view, int index)
void ListView_GetContextMenuPoint ( HWND  p_list,
LPARAM  p_coords,
POINT &  p_point,
int &  p_selection 
)

Definition at line 119 of file listview_helper.cpp.

119  {
120  POINT pt = {(short)LOWORD(p_coords),(short)HIWORD(p_coords)};
121  ListView_GetContextMenuPoint(p_list, pt, p_point, p_selection);
122 }
void ListView_GetContextMenuPoint(HWND p_list, LPARAM p_coords, POINT &p_point, int &p_selection)
void ListView_GetContextMenuPoint ( HWND  p_list,
POINT  p_coords,
POINT &  p_point,
int &  p_selection 
)

Definition at line 124 of file listview_helper.cpp.

124  {
125  if (p_coords.x == -1 && p_coords.y == -1) {
126  int firstsel = ListView_GetFirstSelection(p_list);
127  if (firstsel >= 0) {
128  ListView_EnsureVisible(p_list, firstsel, FALSE);
129  RECT rect;
130  WIN32_OP_D( ListView_GetItemRect(p_list,firstsel,&rect,LVIR_BOUNDS) );
131  p_point.x = (rect.left + rect.right) / 2;
132  p_point.y = (rect.top + rect.bottom) / 2;
133  WIN32_OP_D( ClientToScreen(p_list,&p_point) );
134  } else {
135  RECT rect;
136  WIN32_OP_D(GetClientRect(p_list,&rect));
137  p_point.x = (rect.left + rect.right) / 2;
138  p_point.y = (rect.top + rect.bottom) / 2;
139  WIN32_OP_D(ClientToScreen(p_list,&p_point));
140  }
141  p_selection = firstsel;
142  } else {
143  POINT pt = p_coords; // {(short)LOWORD(p_coords),(short)HIWORD(p_coords)};
144  p_point = pt;
145  POINT client = pt;
146  WIN32_OP_D( ScreenToClient(p_list,&client) );
147  LVHITTESTINFO info = {};
148  info.pt = client;
149  p_selection = ListView_HitTest(p_list,&info);
150  }
151 }
void info(const char *p_message)
Definition: console.cpp:4
static int ListView_GetFirstSelection(HWND p_listview)
static int ListView_GetFirstSelection ( HWND  p_listview)
static

Definition at line 27 of file listview_helper.h.

27  {
28  return ListView_GetNextItem(p_listview,-1,LVNI_SELECTED);
29 }
static int ListView_GetFocusItem ( HWND  p_listview)
static

Definition at line 36 of file listview_helper.h.

36  {
37  return ListView_GetNextItem(p_listview,-1,LVNI_FOCUSED);
38 }
static int ListView_GetSingleSelection ( HWND  p_listview)
static

Definition at line 31 of file listview_helper.h.

31  {
32  if (ListView_GetSelectedCount(p_listview) != 1) return -1;
33  return ListView_GetFirstSelection(p_listview);
34 }
static int ListView_GetFirstSelection(HWND p_listview)
static bool ListView_IsItemSelected ( HWND  p_listview,
int  p_index 
)
static

Definition at line 40 of file listview_helper.h.

40  {
41  return ListView_GetItemState(p_listview,p_index,LVIS_SELECTED) != 0;
42 }