3737
3838#include <pango/pangocairo.h>
3939
40+ // data portion for a slider
41+ typedef struct dt_bauhaus_slider_data_t
42+ {
43+ float pos ; // normalized slider value
44+ float oldpos ; // slider value before entering finetune mode (normalized)
45+ float step ; // step width (not normalized)
46+ float defpos ; // default value (not normalized)
47+ float min , max ; // min and max range
48+ float soft_min , soft_max ;
49+ float hard_min , hard_max ;
50+ int digits ; // how many decimals to round to
51+
52+ float (* grad_col )[3 ]; // colors for gradient slider
53+ int grad_cnt ; // how many stops
54+ float * grad_pos ; // and position of these.
55+
56+ int fill_feedback : 1 ; // fill the slider with brighter part up to the handle?
57+
58+ const char * format ; // numeric value is printed with this format
59+ float factor ; // multiplication factor before printing
60+ float offset ; // addition before printing
61+
62+ int is_dragging : 1 ; // indicates is mouse is dragging slider
63+ int is_changed : 1 ; // indicates new data
64+ guint timeout_handle ; // used to store id of timeout routine
65+ float (* curve )(float , dt_bauhaus_curve_t ); // callback function
66+ } dt_bauhaus_slider_data_t ;
67+
68+ typedef struct dt_bauhaus_combobox_entry_t
69+ {
70+ char * label ;
71+ dt_bauhaus_combobox_alignment_t alignment ;
72+ gboolean sensitive ;
73+ gpointer data ;
74+ void (* free_func )(gpointer ); // callback to free data elements
75+ } dt_bauhaus_combobox_entry_t ;
76+
77+ typedef struct dt_bauhaus_combobox_data_t
78+ {
79+ int active ; // currently active element
80+ int defpos ; // default position
81+ int editable ; // 1 if arbitrary text may be typed
82+ dt_bauhaus_combobox_alignment_t text_align ; // if selected text in combo should be aligned to the left/right
83+ char * text ; // to hold arbitrary text if editable
84+ PangoEllipsizeMode entries_ellipsis ;
85+ GPtrArray * entries ;
86+ gboolean mute_scrolling ; // if set, prevents to issue "data-changed"
87+ dt_bauhaus_combobox_populate_fct populate ; // function to populate the combo list on the fly
88+ dt_bauhaus_combobox_entry_select_fct entry_select ; // function to select an entry based on context
89+ } dt_bauhaus_combobox_data_t ;
90+
91+ typedef union dt_bauhaus_data_t
92+ {
93+ // this is the placeholder for the data portions
94+ // associated with the implementations such as
95+ // sliders, combo boxes, ..
96+ dt_bauhaus_slider_data_t slider ;
97+ dt_bauhaus_combobox_data_t combobox ;
98+ } dt_bauhaus_data_t ;
99+
100+ struct _DtBauhausWidget
101+ {
102+ // gtk base widget
103+ GtkDrawingArea parent ;
104+ // which type of control
105+ dt_bauhaus_type_t type ;
106+ // associated image operation module (to handle focus and such)
107+ dt_action_t * module ;
108+ // pointer to iop field linked to widget
109+ gpointer field ;
110+ // type of field
111+ dt_introspection_type_t field_type ;
112+
113+ // label text, short
114+ char label [256 ];
115+ gboolean show_label ;
116+ // section, short
117+ gchar * section ;
118+ gboolean show_extended_label ;
119+ // callback function to draw the quad icon
120+ dt_bauhaus_quad_paint_f quad_paint ;
121+ // tooltip to show when mouse is over the quad section
122+ gchar * tooltip ;
123+ // minimal modifiers for paint function.
124+ int quad_paint_flags ;
125+ // data for the paint callback
126+ void * quad_paint_data ;
127+ // quad is a toggle button?
128+ gboolean quad_toggle ;
129+ // show quad icon or space
130+ gboolean show_quad ;
131+
132+ // margin and padding structure, defined in css, retrieve on each draw
133+ GtkBorder margin , padding ;
134+ // gap to add to the top padding due to the vertical centering
135+ int top_gap ;
136+
137+ // goes last, might extend past the end:
138+ dt_bauhaus_data_t data ;
139+ };
140+
40141G_DEFINE_TYPE (DtBauhausWidget , dt_bh , GTK_TYPE_DRAWING_AREA )
41142
42143enum
@@ -984,6 +1085,14 @@ float dt_bauhaus_slider_get_default(GtkWidget *widget)
9841085 return d -> defpos ;
9851086}
9861087
1088+ dt_bauhaus_type_t dt_bauhaus_widget_get_type (GtkWidget * widget )
1089+ {
1090+ if (!DT_IS_BAUHAUS_WIDGET (widget )) return DT_BAUHAUS_INVALID ;
1091+
1092+ dt_bauhaus_widget_t * w = DT_BAUHAUS_WIDGET (widget );
1093+ return w -> type ;
1094+ }
1095+
9871096dt_action_t * dt_bauhaus_widget_set_label (GtkWidget * widget ,
9881097 const char * section ,
9891098 const char * label )
@@ -1050,6 +1159,26 @@ void dt_bauhaus_widget_hide_label(GtkWidget *widget)
10501159 w -> show_label = FALSE;
10511160}
10521161
1162+ void dt_bauhaus_widget_set_show_extended_label (GtkWidget * widget ,
1163+ gboolean show )
1164+ {
1165+ dt_bauhaus_widget_t * w = DT_BAUHAUS_WIDGET (widget );
1166+ w -> show_extended_label = show ;
1167+ }
1168+
1169+ void dt_bauhaus_widget_set_module (GtkWidget * widget ,
1170+ dt_action_t * module )
1171+ {
1172+ dt_bauhaus_widget_t * w = DT_BAUHAUS_WIDGET (widget );
1173+ w -> module = module ;
1174+ }
1175+
1176+ gpointer dt_bauhaus_widget_get_module (GtkWidget * widget )
1177+ {
1178+ dt_bauhaus_widget_t * w = DT_BAUHAUS_WIDGET (widget );
1179+ return w -> module ;
1180+ }
1181+
10531182void dt_bauhaus_widget_set_quad_paint (GtkWidget * widget ,
10541183 dt_bauhaus_quad_paint_f f ,
10551184 const int paint_flags ,
@@ -1074,13 +1203,12 @@ void dt_bauhaus_widget_set_quad_tooltip(GtkWidget *widget,
10741203gchar * dt_bauhaus_widget_get_tooltip_markup (GtkWidget * widget ,
10751204 dt_action_element_t element )
10761205{
1077- gchar * tooltip = DT_IS_BAUHAUS_WIDGET (widget )
1078- && element == DT_ACTION_ELEMENT_BUTTON
1079- ? DT_BAUHAUS_WIDGET (widget )-> tooltip : NULL ;
1080- if (!(tooltip ))
1206+ if (element == DT_ACTION_ELEMENT_BUTTON
1207+ && DT_IS_BAUHAUS_WIDGET (widget )
1208+ && DT_BAUHAUS_WIDGET (widget )-> tooltip )
1209+ return g_markup_escape_text (DT_BAUHAUS_WIDGET (widget )-> tooltip , -1 );
1210+ else
10811211 return gtk_widget_get_tooltip_markup (widget );
1082-
1083- return g_markup_escape_text (tooltip , -1 );
10841212}
10851213
10861214void dt_bauhaus_widget_set_field (GtkWidget * widget ,
@@ -1097,6 +1225,12 @@ void dt_bauhaus_widget_set_field(GtkWidget *widget,
10971225 w -> field_type = field_type ;
10981226}
10991227
1228+ gpointer dt_bauhaus_widget_get_field (GtkWidget * widget )
1229+ {
1230+ dt_bauhaus_widget_t * w = DT_BAUHAUS_WIDGET (widget );
1231+ return w -> field ;
1232+ }
1233+
11001234static void _highlight_changed_notebook_tab (GtkWidget * w , gpointer user_data )
11011235{
11021236 GtkWidget * notebook = gtk_widget_get_parent (w );
@@ -1225,14 +1359,14 @@ void dt_bauhaus_update_from_field(dt_iop_module_t *module,
12251359
12261360// make this quad a toggle button:
12271361void dt_bauhaus_widget_set_quad_toggle (GtkWidget * widget ,
1228- const int toggle )
1362+ const gboolean toggle )
12291363{
12301364 dt_bauhaus_widget_t * w = DT_BAUHAUS_WIDGET (widget );
12311365 w -> quad_toggle = toggle ;
12321366}
12331367
12341368void dt_bauhaus_widget_set_quad_active (GtkWidget * widget ,
1235- const int active )
1369+ const gboolean active )
12361370{
12371371 dt_bauhaus_widget_t * w = DT_BAUHAUS_WIDGET (widget );
12381372 if (active )
0 commit comments