Debian Codegraph @

src/widget-drop-down.h

raw symbols SCIP
1 // SPDX-FileCopyrightText: 2023-2026 Geoffrey D. Bennett <[email protected]>
2 // SPDX-License-Identifier: GPL-3.0-or-later
3
4 #pragma once
5
6 #include <gtk/gtk.h>
7
8 #include "alsa.h"
9
10 GtkWidget *make_drop_down_alsa_elem(
11 struct alsa_elem *elem,
12 const char *label_text
13 );
14
15 // Operations for a drop-down whose ALSA value isn't a 0..N-1 row index.
16 // All callbacks receive the user_data passed to make_value_mapped_drop_down_alsa_elem.
17 struct drop_down_value_ops {
18
19 // Map an ALSA value to a row index in the model, or -1 if no row
20 // matches (in which case refresh_model is expected to add one).
21 int (*value_to_row)(int value, void *user_data);
22
23 // Map a row index to the ALSA value to write. current_value is the
24 // live element value at click time; return it to make the click a
25 // no-op (useful for synthetic rows that don't represent a setting).
26 // The row is guaranteed to be a valid index into the current model.
27 int (*row_to_value)(int row, int current_value, void *user_data);
28
29 // Return the button label for the given ALSA value. The returned
30 // string is owned by the caller and must be freed with g_free().
31 char *(*button_label)(int value, void *user_data);
32
33 // Update the model so that value_to_row(value) returns a valid index
34 // afterwards. May be NULL if the model is static and value_to_row
35 // never returns -1. Called before every refresh.
36 void (*refresh_model)(GtkStringList *model, int value, void *user_data);
37 };
38
39 // Build a drop-down that decouples the ALSA element value from the row
40 // index. The widget takes ownership of model and frees user_data with
41 // user_data_free on destruction (user_data_free may be NULL).
42 GtkWidget *make_value_mapped_drop_down_alsa_elem(
43 struct alsa_elem *elem,
44 GtkStringList *model,
45 const struct drop_down_value_ops *ops,
46 void *user_data,
47 GDestroyNotify user_data_free
48 );