comparison foosdk/sdk/foobar2000/SDK/ui.cpp @ 1:20d02a178406 default tip

*: check in everything else yay
author Paper <paper@tflc.us>
date Mon, 05 Jan 2026 02:15:46 -0500
parents
children
comparison
equal deleted inserted replaced
0:e9bb126753e7 1:20d02a178406
1 #include "foobar2000-sdk-pch.h"
2 #include "ui_edit_context.h"
3 #include "ui.h"
4 #include "genrand.h"
5
6 #ifdef _WIN32
7 bool ui_drop_item_callback::g_on_drop(interface IDataObject * pDataObject)
8 {
9 for (auto ptr : enumerate()) {
10 if (ptr->on_drop(pDataObject)) return true;
11 }
12 return false;
13 }
14
15 bool ui_drop_item_callback::g_is_accepted_type(interface IDataObject * pDataObject, DWORD * p_effect)
16 {
17 for (auto ptr : enumerate()) {
18 if (ptr->is_accepted_type(pDataObject, p_effect)) return true;
19 }
20 return false;
21 }
22 #endif // _WIN32
23
24 bool user_interface::g_find(service_ptr_t<user_interface> & p_out,const GUID & p_guid)
25 {
26 for (auto ptr : enumerate()) {
27 if (ptr->get_guid() == p_guid) {
28 p_out = ptr;
29 return true;
30 }
31 }
32 return false;
33 }
34
35 // ui_edit_context.h code
36
37 void ui_edit_context::select_all() { update_selection(pfc::bit_array_true(), pfc::bit_array_true()); }
38 void ui_edit_context::select_none() { update_selection(pfc::bit_array_true(), pfc::bit_array_false()); }
39 void ui_edit_context::get_selected_items(metadb_handle_list_ref out) { pfc::bit_array_bittable mask(get_item_count()); get_selection_mask(mask); get_items(out, mask); }
40 void ui_edit_context::remove_selection() { pfc::bit_array_bittable mask(get_item_count()); get_selection_mask(mask); remove_items(mask); }
41 void ui_edit_context::crop_selection() { pfc::bit_array_bittable mask(get_item_count()); get_selection_mask(mask); remove_items(pfc::bit_array_not(mask)); }
42 void ui_edit_context::clear() { remove_items(pfc::bit_array_true()); }
43 void ui_edit_context::get_all_items(metadb_handle_list_ref out) { get_items(out, pfc::bit_array_true()); }
44
45 void ui_edit_context::get_selection_mask(pfc::bit_array_var & out) {
46 const t_size count = get_item_count(); for (t_size walk = 0; walk < count; ++walk) out.set(walk, is_item_selected(walk));
47 }
48
49 t_size ui_edit_context::get_selection_count(t_size max) {
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 void ui_edit_context::sort_by_format(const char * spec, bool onlySelection) {
57 const t_size count = get_item_count();
58 pfc::array_t<t_size> order; order.set_size(count);
59 pfc::array_t<t_size> sel_map;
60 if (onlySelection) {
61 sel_map.set_size(count);
62 t_size sel_count = 0;
63 for (t_size n = 0; n<count; n++) if (is_item_selected(n)) sel_map[sel_count++] = n;
64 sel_map.set_size(sel_count);
65 }
66
67 {
68 metadb_handle_list temp;
69 pfc::array_t<t_size> order_temp;
70 if (onlySelection) {
71 get_selected_items(temp);
72 order_temp.set_size(count);
73 } else {
74 get_all_items(temp);
75 }
76
77
78 if (spec != NULL) {
79 temp.sort_by_format_get_order(onlySelection ? order_temp.get_ptr() : order.get_ptr(), spec, 0);
80 } else {
81 auto api = genrand_service::get(); api->seed();
82 api->generate_random_order(onlySelection ? order_temp.get_ptr() : order.get_ptr(), temp.get_count());
83 }
84
85 if (onlySelection) {
86 t_size n, ptr;
87 for (n = 0, ptr = 0; n<count; n++) {
88 if (!is_item_selected(n)) {
89 order[n] = n;
90 } else {
91 t_size v = order_temp[ptr++];
92 order[n] = sel_map[v];
93 }
94 }
95 }
96 }
97
98 reorder_items(order.get_ptr(), count);
99 }