Skip to content

Commit

Permalink
set default for language combo
Browse files Browse the repository at this point in the history
  • Loading branch information
dterrahe committed Jul 3, 2024
1 parent fe7194d commit ed97706
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 34 deletions.
57 changes: 23 additions & 34 deletions src/bauhaus/bauhaus.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ static float _widget_get_quad_width(dt_bauhaus_widget_t *w)
return .0f;
}

static dt_bauhaus_combobox_entry_t *_combobox_entry(const dt_bauhaus_combobox_data_t *d, int pos)
{
return g_ptr_array_index(d->entries, pos);
}

static void _combobox_next_sensitive(dt_bauhaus_widget_t *w,
int delta,
guint state,
Expand All @@ -117,7 +122,7 @@ static void _combobox_next_sensitive(dt_bauhaus_widget_t *w,

while(delta && cur >= 0 && cur < d->entries->len)
{
dt_bauhaus_combobox_entry_t *entry = g_ptr_array_index(d->entries, cur);
dt_bauhaus_combobox_entry_t *entry = _combobox_entry(d, cur);
gchar *text_cmp = g_utf8_casefold(entry->label, -1);
if(entry->sensitive && strstr(text_cmp, keys))
{
Expand Down Expand Up @@ -565,8 +570,7 @@ static gboolean _window_motion_notify(GtkWidget *widget,
const int active = (bh->mouse_y - w->top_gap) / bh->line_height;
if(active >= 0 && active < d->entries->len)
{
const dt_bauhaus_combobox_entry_t *entry = g_ptr_array_index(d->entries, active);
if(entry->sensitive && event->state & GDK_BUTTON1_MASK)
if(_combobox_entry(d, active)->sensitive && event->state & GDK_BUTTON1_MASK)
{
if(active != d->active)
_combobox_set(w, active, w->data.combobox.mute_scrolling);
Expand Down Expand Up @@ -1491,11 +1495,8 @@ void dt_bauhaus_combobox_add_list(GtkWidget *widget,
if(action)
g_hash_table_insert(darktable.bauhaus->combo_list, action, texts);

int item = 0;
while(texts && *texts)
dt_bauhaus_combobox_add_full(widget, Q_(*(texts++)),
DT_BAUHAUS_COMBOBOX_ALIGN_RIGHT,
GINT_TO_POINTER(item++), NULL, TRUE);
dt_bauhaus_combobox_add(widget, Q_(*(texts++)));
}

gboolean dt_bauhaus_combobox_add_introspection
Expand Down Expand Up @@ -1557,6 +1558,8 @@ void dt_bauhaus_combobox_add_full(GtkWidget *widget,
dt_bauhaus_widget_t *w = DT_BAUHAUS_WIDGET(widget);
if(w->type != DT_BAUHAUS_COMBOBOX) return;
dt_bauhaus_combobox_data_t *d = &w->data.combobox;
if(!data && d->entries->len > 0 && !_combobox_entry(d, 0)->data)
data =_combobox_entry(d, d->entries->len - 1)->data + 1;
dt_bauhaus_combobox_entry_t *entry = _new_combobox_entry(text, align,
sensitive, data, free_func);
g_ptr_array_add(d->entries, entry);
Expand All @@ -1577,7 +1580,7 @@ gboolean dt_bauhaus_combobox_set_entry_label(GtkWidget *widget,
if(w->type != DT_BAUHAUS_COMBOBOX) return FALSE;
dt_bauhaus_combobox_data_t *d = &w->data.combobox;
if(!d || pos < 0 || pos >= d->entries->len) return FALSE;
dt_bauhaus_combobox_entry_t *entry = g_ptr_array_index(d->entries, pos);
dt_bauhaus_combobox_entry_t *entry = _combobox_entry(d, pos);
g_free(entry->label);
entry->label = g_strdup(label);
return TRUE;
Expand Down Expand Up @@ -1679,23 +1682,17 @@ const char *dt_bauhaus_combobox_get_text(GtkWidget *widget)
if(!d) return NULL;

if(d->active < 0)
{
return d->editable ? d->text : NULL;
}
else
{
const dt_bauhaus_combobox_entry_t *entry = g_ptr_array_index(d->entries, d->active);
return entry->label;
}
return _combobox_entry(d, d->active)->label;
}

gpointer dt_bauhaus_combobox_get_data(GtkWidget *widget)
{
const dt_bauhaus_combobox_data_t *d = _combobox_data(widget);
if(!d || d->active < 0) return NULL;

const dt_bauhaus_combobox_entry_t *entry = g_ptr_array_index(d->entries, d->active);
return entry->data;
return _combobox_entry(d, d->active)->data;
}

void dt_bauhaus_combobox_clear(GtkWidget *widget)
Expand All @@ -1713,8 +1710,7 @@ const char *dt_bauhaus_combobox_get_entry(GtkWidget *widget,
const dt_bauhaus_combobox_data_t *d = _combobox_data(widget);
if(!d || pos < 0 || pos >= d->entries->len) return NULL;

const dt_bauhaus_combobox_entry_t *entry = g_ptr_array_index(d->entries, pos);
return entry->label;
return _combobox_entry(d, pos)->label;
}

void dt_bauhaus_combobox_set_text(GtkWidget *widget,
Expand Down Expand Up @@ -1757,9 +1753,8 @@ static void _combobox_set(dt_bauhaus_widget_t *w,
case DT_INTROSPECTION_TYPE_ENUM:;
if(d->active >= 0)
{
const dt_bauhaus_combobox_entry_t *entry =
g_ptr_array_index(d->entries, d->active);
int *e = w->field, preve = *e; *e = GPOINTER_TO_INT(entry->data);
int *e = w->field, preve = *e;
*e = GPOINTER_TO_INT(_combobox_entry(d, d->active)->data);
if(*e != preve) dt_iop_gui_changed(w->module, GTK_WIDGET(w), &preve);
}
break;
Expand Down Expand Up @@ -1802,8 +1797,7 @@ gboolean dt_bauhaus_combobox_set_from_text(GtkWidget *widget,

for(int i = 0; d && i < d->entries->len; i++)
{
const dt_bauhaus_combobox_entry_t *entry = g_ptr_array_index(d->entries, i);
if(!g_strcmp0(entry->label, text))
if(!g_strcmp0(_combobox_entry(d, i)->label, text))
{
dt_bauhaus_combobox_set(widget, i);
return TRUE;
Expand All @@ -1819,8 +1813,7 @@ int dt_bauhaus_combobox_get_from_value(GtkWidget *widget,

for(int i = 0; d && i < d->entries->len; i++)
{
const dt_bauhaus_combobox_entry_t *entry = g_ptr_array_index(d->entries, i);
if(GPOINTER_TO_INT(entry->data) == value)
if(GPOINTER_TO_INT(_combobox_entry(d, i)->data) == value)
{
return i;
}
Expand Down Expand Up @@ -1865,9 +1858,7 @@ void dt_bauhaus_combobox_entry_set_sensitive(GtkWidget *widget,
const dt_bauhaus_combobox_data_t *d = _combobox_data(widget);
if(!d || pos < 0 || pos >= d->entries->len) return;

dt_bauhaus_combobox_entry_t *entry =
(dt_bauhaus_combobox_entry_t *)g_ptr_array_index(d->entries, pos);
entry->sensitive = sensitive;
_combobox_entry(d, pos)->sensitive = sensitive;
}

void dt_bauhaus_slider_clear_stops(GtkWidget *widget)
Expand Down Expand Up @@ -2280,7 +2271,7 @@ static gboolean _popup_draw(GtkWidget *widget,
bh->unique_match = -1;
for(int j = 0; j < d->entries->len; j++)
{
const dt_bauhaus_combobox_entry_t *entry = g_ptr_array_index(d->entries, j);
const dt_bauhaus_combobox_entry_t *entry = _combobox_entry(d, j);
gchar *text_cmp = g_utf8_casefold(entry->label, -1);
gchar *search_found = strstr(text_cmp, keys);
gchar *entry_found = entry->label + (search_found - text_cmp);
Expand Down Expand Up @@ -2485,8 +2476,7 @@ static gboolean _widget_draw(GtkWidget *widget,
const gchar *text = d->text;
if(d->active >= 0 && d->active < d->entries->len)
{
const dt_bauhaus_combobox_entry_t *entry = g_ptr_array_index(d->entries, d->active);
text = entry->label;
text = _combobox_entry(d, d->active)->label;
}
set_color(cr, *text_color);

Expand Down Expand Up @@ -2649,7 +2639,7 @@ static gint _natural_width(GtkWidget *widget,

for(int i = 0; i < d->entries->len; i++)
{
const dt_bauhaus_combobox_entry_t *entry = g_ptr_array_index(d->entries, i);
const dt_bauhaus_combobox_entry_t *entry = _combobox_entry(d, i);

if(popup && (i || entry->alignment != DT_BAUHAUS_COMBOBOX_ALIGN_RIGHT))
label_width = 0;
Expand Down Expand Up @@ -3823,8 +3813,7 @@ static float _action_process_combo(gpointer target,
int value = dt_bauhaus_combobox_get(widget);
for(int i = value; i >= 0; i--)
{
dt_bauhaus_combobox_entry_t *entry = g_ptr_array_index(w->data.combobox.entries, i);
if(!entry->sensitive) value--; // don't count unselectable combo items in value
if(!_combobox_entry(&w->data.combobox, i)->sensitive) value--; // don't count unselectable combo items in value
}
return - 1 - value
+ (value == effect - DT_ACTION_EFFECT_COMBO_SEPARATOR - 1
Expand Down
1 change: 1 addition & 0 deletions src/gui/preferences.c
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ static void init_tab_general(GtkWidget *dialog, GtkWidget *stack, dt_gui_themetw
}

dt_bauhaus_combobox_set(widget, darktable.l10n->selected);
dt_bauhaus_combobox_set_default(widget, darktable.l10n->sys_default);
g_signal_connect(G_OBJECT(widget), "value-changed", G_CALLBACK(language_callback), 0);
gtk_widget_set_tooltip_text(labelev, _("double-click to reset to the system language"));
gtk_event_box_set_visible_window(GTK_EVENT_BOX(labelev), FALSE);
Expand Down

0 comments on commit ed97706

Please sign in to comment.