gatuno-terminal/src/terminal-info-bar.c

117 lines
2.9 KiB
C
Raw Normal View History

2011-11-06 14:13:49 -06:00
/*
* Copyright © 2010 Christian Persch
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3, or (at your option)
* any later version.
*
* This program is distributed in the hope info_bar it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
2012-10-11 18:34:18 -05:00
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
2011-11-06 14:13:49 -06:00
*/
#include <config.h>
#include "terminal-info-bar.h"
#include <gtk/gtk.h>
struct _TerminalInfoBarPrivate
{
2011-11-06 16:14:03 -06:00
GtkWidget *content_box;
2011-11-06 14:13:49 -06:00
};
G_DEFINE_TYPE_WITH_PRIVATE (TerminalInfoBar, terminal_info_bar, GTK_TYPE_INFO_BAR)
2011-11-06 14:13:49 -06:00
/* helper functions */
static void
terminal_info_bar_init (TerminalInfoBar *bar)
{
2011-11-06 16:14:03 -06:00
GtkInfoBar *info_bar = GTK_INFO_BAR (bar);
TerminalInfoBarPrivate *priv;
2011-11-06 14:13:49 -06:00
priv = bar->priv = terminal_info_bar_get_instance_private (bar);
2011-11-06 14:13:49 -06:00
priv->content_box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
2011-11-06 16:14:03 -06:00
gtk_box_pack_start (GTK_BOX (gtk_info_bar_get_content_area (info_bar)),
priv->content_box, TRUE, TRUE, 0);
2011-11-06 14:13:49 -06:00
}
static void
terminal_info_bar_class_init (TerminalInfoBarClass *klass)
{
}
/* public API */
/**
* terminal_info_bar_new:
* @type: a #GtkMessageType
*
* Returns: a new #TerminalInfoBar for @screen
*/
GtkWidget *
terminal_info_bar_new (GtkMessageType type,
const char *first_button_text,
...)
{
2011-11-06 16:14:03 -06:00
GtkWidget *info_bar;
va_list args;
2011-11-06 14:13:49 -06:00
2011-11-06 16:14:03 -06:00
info_bar = g_object_new (TERMINAL_TYPE_INFO_BAR,
"message-type", type,
NULL);
2011-11-06 14:13:49 -06:00
2011-11-06 16:14:03 -06:00
va_start (args, first_button_text);
while (first_button_text != NULL)
{
int response_id;
2011-11-06 14:13:49 -06:00
2011-11-06 16:14:03 -06:00
response_id = va_arg (args, int);
gtk_info_bar_add_button (GTK_INFO_BAR (info_bar),
first_button_text, response_id);
2011-11-06 14:13:49 -06:00
2011-11-06 16:14:03 -06:00
first_button_text = va_arg (args, const char *);
}
va_end (args);
2011-11-06 14:13:49 -06:00
2011-11-06 16:14:03 -06:00
return info_bar;
2011-11-06 14:13:49 -06:00
}
void
terminal_info_bar_format_text (TerminalInfoBar *bar,
const char *format,
...)
{
2011-11-06 16:14:03 -06:00
TerminalInfoBarPrivate *priv;
char *text;
GtkWidget *label;
va_list args;
2011-11-06 14:13:49 -06:00
2011-11-06 16:14:03 -06:00
g_return_if_fail (TERMINAL_IS_INFO_BAR (bar));
2011-11-06 14:13:49 -06:00
2011-11-06 16:14:03 -06:00
priv = bar->priv;
2011-11-06 14:13:49 -06:00
2011-11-06 16:14:03 -06:00
va_start (args, format);
text = g_strdup_vprintf (format, args);
va_end (args);
2011-11-06 14:13:49 -06:00
2011-11-06 16:14:03 -06:00
label = gtk_label_new (text);
g_free (text);
2011-11-06 14:13:49 -06:00
2011-11-06 16:14:03 -06:00
gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
gtk_label_set_selectable (GTK_LABEL (label), TRUE);
gtk_label_set_xalign (GTK_LABEL (label), 0.0);
gtk_label_set_yalign (GTK_LABEL (label), 0.0);
2011-11-06 16:14:03 -06:00
gtk_box_pack_start (GTK_BOX (priv->content_box), label, FALSE, FALSE, 0);
gtk_widget_show_all (priv->content_box);
2011-11-06 14:13:49 -06:00
}