foobar2000 SDK  2015-08-03
ui_edit_context.h
Go to the documentation of this file.
1 
2 class NOVTABLE ui_edit_context : public service_base {
3  FB2K_MAKE_SERVICE_INTERFACE(ui_edit_context, service_base)
4 public:
6  virtual void initialize() = 0;
9  virtual void shutdown() = 0;
10 
11  enum {
12  flag_removable = 1,
13  flag_reorderable = 2,
14  flag_undoable = 4,
15  flag_redoable = 8,
16  flag_linearlist = 16,
17  flag_searchable = 32,
18  flag_insertable = 64,
19  };
20 
21  virtual t_uint32 get_flags() = 0;
22 
23  bool can_remove() {return (get_flags() & flag_removable) != 0;}
24  bool test_flags(t_uint32 flags) {return (get_flags() & flags) == flags;}
25  bool can_remove_mask() {return test_flags(flag_removable | flag_linearlist);}
26  bool can_reorder() {return test_flags(flag_reorderable);}
27  bool can_search() {return test_flags(flag_searchable);}
28 
29  virtual void select_all() {update_selection(bit_array_true(), bit_array_true());}
30  virtual void select_none() {update_selection(bit_array_true(), bit_array_false());}
31  virtual void get_selected_items(metadb_handle_list_ref out) {bit_array_bittable mask(get_item_count()); get_selection_mask(mask); get_items(out, mask);}
32  virtual void remove_selection() {bit_array_bittable mask(get_item_count()); get_selection_mask(mask); remove_items(mask);}
33  virtual void crop_selection() {bit_array_bittable mask(get_item_count()); get_selection_mask(mask); remove_items(bit_array_not(mask));}
34  virtual void clear() {remove_items(bit_array_true());}
35  virtual void get_all_items(metadb_handle_list_ref out) {get_items(out, bit_array_true());}
36  virtual GUID get_selection_type() = 0;
37 
38  // available if flag_linearlist is set
39  virtual void get_selection_mask(pfc::bit_array_var & out) {
40  const t_size count = get_item_count(); for(t_size walk = 0; walk < count; ++walk) out.set(walk, is_item_selected(walk));
41  }
42  virtual void update_selection(const pfc::bit_array & mask, const pfc::bit_array & newVals) = 0;
43  virtual t_size get_item_count(t_size max = ~0) = 0;
44  virtual metadb_handle_ptr get_item(t_size index) = 0;
45  virtual void get_items(metadb_handle_list_ref out, pfc::bit_array const & mask) = 0;
46  virtual bool is_item_selected(t_size item) = 0;
47  virtual void remove_items(pfc::bit_array const & mask) = 0;
48  virtual void reorder_items(const t_size * order, t_size count) = 0;
49  virtual t_size get_selection_count(t_size max = ~0) {
50  t_size count = 0;
51  const t_size total = get_item_count();
52  for(t_size walk = 0; walk < total && count < max; ++walk) if (is_item_selected(walk)) ++count;
53  return count;
54  }
55 
56  virtual void search() = 0;
57 
58  virtual void undo_backup() = 0;
59  virtual void undo_restore() = 0;
60  virtual void redo_restore() = 0;
61 
62  virtual void insert_items(t_size at, metadb_handle_list_cref items, pfc::bit_array const & selection) = 0;
63 
64  virtual t_size query_insert_mark() = 0;
65 
66  void sort_by_format(const char * spec, bool onlySelection) {
67  const t_size count = get_item_count();
68  pfc::array_t<t_size> order; order.set_size(count);
69  pfc::array_t<t_size> sel_map;
70  if (onlySelection) {
71  sel_map.set_size(count);
72  t_size sel_count = 0;
73  for(t_size n=0;n<count;n++) if (is_item_selected(n)) sel_map[sel_count++]=n;
74  sel_map.set_size(sel_count);
75  }
76 
77  {
78  metadb_handle_list temp;
79  pfc::array_t<t_size> order_temp;
80  if (onlySelection) {
81  get_selected_items(temp);
82  order_temp.set_size(count);
83  } else {
84  get_all_items(temp);
85  }
86 
87 
88  if (spec != NULL) {
89  temp.sort_by_format_get_order(onlySelection ? order_temp.get_ptr() : order.get_ptr(),spec,0);
90  } else {
91  static_api_ptr_t<genrand_service> api; api->seed((unsigned)__rdtsc());
92  api->generate_random_order(onlySelection ? order_temp.get_ptr() : order.get_ptr(),temp.get_count());
93  }
94 
95  if (onlySelection) {
96  t_size n,ptr;
97  for(n=0,ptr=0;n<count;n++) {
98  if (!is_item_selected(n)) {
99  order[n] = n;
100  } else {
101  t_size v = order_temp[ptr++];
102  order[n] = sel_map[v];
103  }
104  }
105  }
106  }
107 
108  reorder_items(order.get_ptr(), count);
109  }
110 
111 };
112 
114  FB2K_MAKE_SERVICE_INTERFACE(ui_edit_context_playlist, ui_edit_context)
115 public:
116  virtual t_size get_playlist_number() = 0;
117 };
118 
119 class NOVTABLE ui_edit_context_manager : public service_base {
120  FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(ui_edit_context_manager)
121 public:
122  virtual t_uint32 set_context(ui_edit_context::ptr context) = 0;
123  virtual void unset_context(t_uint32 id) = 0;
124  virtual ui_edit_context::ptr get_context() = 0;
125  virtual ui_edit_context::ptr create_playlist_context(t_size playlist_number) = 0;
126  virtual void disable_autofallback() = 0;
127  virtual t_uint32 set_context_active_playlist() = 0;
128 };
virtual void select_all()
bool test_flags(t_uint32 flags)
const t_item * get_ptr() const
Definition: array.h:213
Definition: pfc.h:71
Generic variable bit_array implementation. Needs to be initialized with requested array size before ...
void sort_by_format_get_order(t_size *order, const char *spec, titleformat_hook *p_hook) const
Bit array interface class, constant version (you can only retrieve values). Range of valid indexes d...
Definition: bit_array.h:6
t_size get_count() const
Definition: list.h:365
Negation of another array. Valid index range is the same as valid index range of the parameter array...
virtual void set(t_size n, bool val)=0
virtual void crop_selection()
virtual void clear()
size_t t_size
Definition: int_types.h:48
void set_size(t_size p_size)
Definition: array.h:104
Base class for all service classes. Provides interfaces for reference counter and querying for differ...
Definition: service.h:333
Bit array interface class, variable version (you can both set and retrieve values). As with the constant version, valid index range depends on the context.
Definition: bit_array.h:40
virtual void select_none()
virtual t_size get_selection_count(t_size max=~0)
bool is_item_selected(HWND p_listview, unsigned p_index)
virtual void remove_selection()
virtual void get_all_items(metadb_handle_list_ref out)
virtual void get_selected_items(metadb_handle_list_ref out)
virtual void get_selection_mask(pfc::bit_array_var &out)
void sort_by_format(const char *spec, bool onlySelection)
Helper template used to easily access core services. Usage: static_api_ptr_t<myclass> api; api->doso...
Definition: service.h:533
uint32_t t_uint32
Definition: int_types.h:5