return ret;
}
+gchar
+*solipa_string_replace (const gchar *string,
+ const gchar *origin,
+ const gchar *replace)
+{
+ gchar *ret;
+ gchar *p;
+
+ if (string == NULL) return NULL;
+ if (origin == NULL || replace == NULL) return g_strdup (string);
+
+ p = g_strstr_len (string, -1, origin);
+
+ if (p == NULL)
+ {
+ return g_strdup (string);
+ }
+
+ ret = g_strndup (string, p - string);
+
+ ret = g_strdup_printf ("%s%s%s", ret, replace, p + strlen (origin));
+
+ return ret;
+}
+
gchar
*solipa_format_money (gdouble number,
gint decimals,
(GDateYear)tt_tm->tm_year + 1900);
}
+GDateTime
+*solipa_tm_to_gdatetime (struct tm *tm_data)
+{
+ GDateTime *ret;
+
+ ret = NULL;
+ if (tm_data != NULL)
+ {
+ ret = g_date_time_new_local (tm_data->tm_year,
+ tm_data->tm_mon,
+ tm_data->tm_mday,
+ tm_data->tm_hour,
+ tm_data->tm_min,
+ tm_data->tm_sec);
+ }
+
+ return ret;
+}
+
+const gchar
+*solipa_tm_to_sql (struct tm *tm_data, const gchar *format)
+{
+ const gchar *ret;
+ gchar *_format;
+
+ ret = g_strdup ("NULL");
+
+ if (tm_data != NULL)
+ {
+ if (format == NULL)
+ {
+ _format = g_strdup ("%Y-%m-%d %H:%M:%S");
+ }
+ else
+ {
+ _format = g_strstrip (g_strdup (format));
+ if (g_strcmp0 (_format, "") == 0)
+ {
+ _format = g_strdup ("%Y-%m-%d %H:%M:%S");
+ }
+ }
+ ret = g_strdup_printf ("'%s'", g_date_time_format (solipa_tm_to_gdatetime (tm_data), _format));
+ }
+
+ return ret;
+}
+
+GDateTime
+*solipa_get_gdatetime_from_string (const gchar *string, const gchar *format)
+{
+ GDateTime *ret;
+ gchar *new_str;
+ gchar *new_format;
+ gchar **str_tokens;
+ gchar **format_tokens;
+ gchar *delimiters;
+ guint len_strv;
+ guint len_formatv;
+ guint i;
+ guint i_to;
+
+ gint year;
+ gint month;
+ gint day;
+ gint hour;
+ gint minute;
+ gdouble seconds;
+
+ g_return_val_if_fail (string != NULL, NULL);
+
+ new_str = g_strstrip (g_strdup (string));
+ if (g_strcmp0 (new_str, "") == 0)
+ {
+ g_free (new_str);
+ return NULL;
+ }
+
+ if (format == NULL)
+ {
+ new_format = g_strdup ("%Y-%m-%d %H:%M:%S");
+ }
+ else
+ {
+ new_format = g_strstrip (g_strdup (format));
+ if (g_strcmp0 (new_format, "") == 0)
+ {
+ new_format = g_strdup ("%Y-%m-%d %H:%M:%S");
+ }
+ }
+
+ /* removes format identifiers to find delimiters */
+ delimiters = solipa_string_replace (new_format, "%Y", "");
+ delimiters = solipa_string_replace (delimiters, "%m", "");
+ delimiters = solipa_string_replace (delimiters, "%d", "");
+ delimiters = solipa_string_replace (delimiters, "%H", "");
+ delimiters = solipa_string_replace (delimiters, "%M", "");
+ delimiters = solipa_string_replace (delimiters, "%S", "");
+
+ if (delimiters == NULL || g_strcmp0 (delimiters, "") == 0)
+ {
+ g_free (delimiters);
+ g_free (new_format);
+ g_free (new_str);
+ return NULL;
+ }
+
+ str_tokens = g_strsplit_set (string, delimiters, -1);
+ if (str_tokens == NULL)
+ {
+ g_free (delimiters);
+ g_free (new_format);
+ g_free (new_str);
+ return NULL;
+ }
+
+ format_tokens = g_strsplit_set (format, delimiters, -1);
+ if (format_tokens == NULL)
+ {
+ g_free (delimiters);
+ g_free (new_format);
+ g_free (new_str);
+ return NULL;
+ }
+
+ len_strv = g_strv_length (str_tokens);
+ len_formatv = g_strv_length (format_tokens);
+
+ i_to = MIN (len_strv, len_formatv);
+ for (i = 0; i < i_to; i++)
+ {
+ if (g_strcmp0 (format_tokens[i], "%Y") == 0)
+ {
+ year = strtol (str_tokens[i], NULL, 10) - 1900;
+ }
+ else if (g_strcmp0 (format_tokens[i], "%m") == 0)
+ {
+ month = strtol (str_tokens[i], NULL, 10) - 1;
+ }
+ else if (g_strcmp0 (format_tokens[i], "%d") == 0)
+ {
+ day = strtol (str_tokens[i], NULL, 10);
+ }
+ else if (g_strcmp0 (format_tokens[i], "%H") == 0)
+ {
+ hour = strtol (str_tokens[i], NULL, 10);
+ }
+ else if (g_strcmp0 (format_tokens[i], "%M") == 0)
+ {
+ minute = strtol (str_tokens[i], NULL, 10);
+ }
+ else if (g_strcmp0 (format_tokens[i], "%S") == 0)
+ {
+ seconds = g_strtod (str_tokens[i], NULL);
+ }
+ }
+
+ g_free (delimiters);
+ g_free (new_format);
+ g_free (new_str);
+
+ ret = g_date_time_new_local (year,
+ month,
+ day,
+ hour,
+ minute,
+ seconds);
+
+ return ret;
+}
+
gdouble
solipa_round (gdouble value, guint n_decimals)
{
return ret;
}
-const gchar
-*solipa_tm_to_sql (struct tm *tm_data, const gchar *format)
-{
- const gchar *ret;
- gchar *_format;
-
- ret = g_strdup ("NULL");
-
- if (tm_data != NULL)
- {
- if (format == NULL)
- {
- _format = g_strdup ("%Y-%m-%d %H:%M");
- }
- else
- {
- _format = g_strdup (format);
- g_strstrip (_format);
- if (g_strcmp0 (_format, "") == 0)
- {
- _format = g_strdup ("%Y-%m-%d %H:%M");
- }
- }
- ret = g_strdup_printf ("'%s'", gtk_form_field_datetime_get_str_from_tm (tm_data, _format));
- }
-
- return ret;
-}
-
gboolean
solipa_chk_codice_fiscale (const gchar *codice_fiscale, gboolean empty_good)
{
return risp;
}
+#define LABEL_SIZE 90
+
+static void
+label_size_request (GtkWidget *widget,
+ GtkRequisition *requisition,
+ gpointer user_data)
+{
+ requisition->width = LABEL_SIZE;
+}
+
+static void
+label_size_allocate_after (GtkWidget *widget,
+ GtkAllocation *allocation,
+ gpointer user_data)
+{
+ GtkWidget *lbl = (GtkWidget *)user_data;
+ gint width = LABEL_SIZE;
+
+ if (allocation->width > width)
+ width = allocation->width;
+
+ gtk_widget_set_size_request (lbl, width, -1);
+ /* Sometimes labels aren't drawn correctly after resize without this */
+ gtk_widget_queue_draw (lbl);
+}
+
GtkWidget
*solipa_info_bar (GtkMessageType type, const gchar *message_text)
{
GtkWidget *infobar;
GtkWidget *hbox;
GtkWidget *img;
+ GtkWidget *event_box;
GtkWidget *lbl;
gchar *stock;
- hbox = gtk_hbox_new (FALSE, 5);
+ hbox = gtk_hbox_new (FALSE, 10);
switch (type)
{
case GTK_MESSAGE_INFO:
img = gtk_image_new_from_stock (stock, GTK_ICON_SIZE_BUTTON);
gtk_box_pack_start (GTK_BOX (hbox), img, FALSE, FALSE, 0);
+
+ event_box = gtk_event_box_new ();
+ gtk_event_box_set_visible_window (GTK_EVENT_BOX (event_box), FALSE);
+ gtk_box_pack_start (GTK_BOX (hbox), event_box, TRUE, TRUE, 0);
+
lbl = gtk_label_new (message_text);
- gtk_box_pack_start (GTK_BOX (hbox), lbl, TRUE, TRUE, 0);
+ gtk_label_set_line_wrap (GTK_LABEL (lbl), TRUE);
+ gtk_label_set_line_wrap_mode (GTK_LABEL (lbl), PANGO_WRAP_WORD_CHAR);
+ gtk_label_set_justify (GTK_LABEL (lbl), GTK_JUSTIFY_CENTER);
+ gtk_misc_set_alignment (GTK_MISC (lbl), 0.5, 0.5);
+ gtk_container_add (GTK_CONTAINER (event_box), lbl);
+
+ /* A Hack so that PANGO_WRAP_WORD_CHAR works nicely */
+ g_signal_connect (G_OBJECT (event_box), "size-request",
+ G_CALLBACK (label_size_request), NULL);
+ g_signal_connect_after (G_OBJECT (event_box), "size-allocate",
+ G_CALLBACK (label_size_allocate_after), (gpointer)lbl);
+
infobar = gtk_info_bar_new ();
- gtk_container_add (GTK_CONTAINER (gtk_info_bar_get_content_area (GTK_INFO_BAR (infobar))), hbox);
gtk_info_bar_set_message_type (GTK_INFO_BAR (infobar), type);
+ gtk_container_add (GTK_CONTAINER (gtk_info_bar_get_content_area (GTK_INFO_BAR (infobar))), hbox);
- gtk_widget_show (hbox);
- gtk_widget_show (img);
- gtk_widget_show (lbl);
+ gtk_widget_show_all (infobar);
return infobar;
}
--- /dev/null
+/*
+ * Copyright (C) 2011 Andrea Zagli <azagli@libero.it>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <utils.h>
+
+GtkWidget *w;
+
+gboolean
+on_w_delete_event (GtkWidget *widget,
+ GdkEvent *event,
+ gpointer user_data)
+{
+ return FALSE;
+}
+
+int
+main (int argc, char *argv[])
+{
+ GtkWidget *infobar;
+
+ gtk_init (&argc, &argv);
+
+ w = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+ g_signal_connect (w, "delete-event", G_CALLBACK (on_w_delete_event), NULL);
+ g_signal_connect (w, "destroy", gtk_main_quit, NULL);
+
+ infobar = solipa_info_bar (GTK_MESSAGE_INFO, "Message very very very very very very very very very very very very very very very very very very very very very very very long");
+ gtk_container_add (GTK_CONTAINER (w), infobar);
+
+ gtk_widget_show (w);
+
+ gtk_main ();
+
+ return 0;
+}