static void gnc_period_select_set_date_common (GncPeriodSelect *period, const GDate *date) { GncPeriodSelectPrivate *priv; priv = GNC_PERIOD_SELECT_GET_PRIVATE(period); if (date) { if (priv->date_base) g_date_free(priv->date_base); priv->date_base = g_date_new_dmy(g_date_get_day(date), g_date_get_month(date), g_date_get_year(date)); if (priv->date_label == NULL) { priv->date_align = gtk_alignment_new(0.5, 0.5, 0, 0); gtk_alignment_set_padding(GTK_ALIGNMENT(priv->date_align), 0, 0, 6, 0); gtk_box_pack_start(GTK_BOX(period), priv->date_align, TRUE, TRUE, 0); priv->date_label = gtk_label_new(""); gtk_container_add(GTK_CONTAINER(priv->date_align), priv->date_label); gtk_widget_show_all(priv->date_align); } gnc_period_sample_update_date_label(period); return; } if (priv->date_base) { g_date_free(priv->date_base); priv->date_base = NULL; gtk_widget_destroy(priv->date_align); priv->date_align = NULL; priv->date_label = NULL; } }
/* Set an item in the GncPeriodSelect to be the active one. * This will first update the internal GtkCombobox (blocking * its "changed" callback to prevent an infinite loop). * Then it will update the sample label and finally it will * emit a "changed" signal of it's own for other objects * listening for this signal. */ static void gnc_period_select_set_active_internal (GncPeriodSelect *period, GncAccountingPeriod which) { GncPeriodSelectPrivate *priv; g_return_if_fail(period != NULL); g_return_if_fail(GNC_IS_PERIOD_SELECT(period)); g_return_if_fail(which >= 0); g_return_if_fail(which < GNC_ACCOUNTING_PERIOD_LAST); priv = GNC_PERIOD_SELECT_GET_PRIVATE(period); g_signal_handlers_block_by_func(G_OBJECT(period), G_CALLBACK(gnc_period_sample_combobox_changed), period); gtk_combo_box_set_active(GTK_COMBO_BOX(priv->selector), which); g_signal_handlers_unblock_by_func(G_OBJECT(period), G_CALLBACK(gnc_period_sample_combobox_changed), period); /* Update this widget */ gnc_period_sample_update_date_label(period); /* Pass it on... */ gnc_period_select_changed(period); }
static void gnc_period_select_set_date_common (GncPeriodSelect *period, const GDate *date) { GncPeriodSelectPrivate *priv; priv = GNC_PERIOD_SELECT_GET_PRIVATE(period); if (date) { if (priv->date_base) g_date_free(priv->date_base); priv->date_base = g_date_new_dmy(g_date_get_day(date), g_date_get_month(date), g_date_get_year(date)); if (priv->date_label == NULL) { priv->date_label = gtk_label_new(""); #if GTK_CHECK_VERSION(3,12,0) gtk_widget_set_margin_start (GTK_WIDGET(priv->date_label), 6); #else gtk_widget_set_margin_left (GTK_WIDGET(priv->date_label), 6); #endif gtk_box_pack_start(GTK_BOX(period), priv->date_label, TRUE, TRUE, 0); gtk_widget_show_all(priv->date_label); } gnc_period_sample_update_date_label(period); return; } if (priv->date_base) { g_date_free(priv->date_base); priv->date_base = NULL; gtk_widget_destroy(priv->date_label); priv->date_label = NULL; } }
/** Handle an application wide change in the date format. This * function will be called when the preference for the date format is * updated. It doesn't really care what the new format is, because * the date string is generated elsewhere. It just needs to know to * update the date label so that it matches the newly selected format. * * @param prefs Unused. * * @param pref Unused. * * @param period The GncPeriodSelect that needs to be updated. */ static void gnc_period_sample_new_date_format (gpointer prefs, gchar *pref, GncPeriodSelect *period) { gnc_period_sample_update_date_label(period); }