evolution-3.6.4/composer/e-composer-text-header.c

No issues found

  1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
  2 
  3 /*Modified for Anjal - Johnny Jacob <jjohnny@novell.com>*/
  4 
  5 /*
  6  * This program is free software; you can redistribute it and/or
  7  * modify it under the terms of the GNU Lesser General Public
  8  * License as published by the Free Software Foundation; either
  9  * version 2 of the License, or (at your option) version 3.
 10  *
 11  * This program is distributed in the hope that it will be useful,
 12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 14  * Lesser General Public License for more details.
 15  *
 16  * You should have received a copy of the GNU Lesser General Public
 17  * License along with the program; if not, see <http://www.gnu.org/licenses/>
 18  *
 19  * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
 20  */
 21 
 22 #ifdef HAVE_CONFIG_H
 23 #include <config.h>
 24 #endif
 25 
 26 #include "e-composer-text-header.h"
 27 
 28 /* Convenience macro */
 29 #define E_COMPOSER_TEXT_HEADER_GET_ENTRY(header) \
 30 	(GTK_ENTRY (E_COMPOSER_HEADER (header)->input_widget))
 31 
 32 struct _EComposerTextHeaderPrivate {
 33 	GtkLinkButton *linkbtn;
 34 	guint destination_index;
 35 };
 36 
 37 G_DEFINE_TYPE (
 38 	EComposerTextHeader,
 39 	e_composer_text_header,
 40 	E_TYPE_COMPOSER_HEADER)
 41 
 42 static void
 43 composer_text_header_changed_cb (GtkEntry *entry,
 44                                  EComposerTextHeader *header)
 45 {
 46 	g_signal_emit_by_name (header, "changed");
 47 }
 48 
 49 static gboolean
 50 composer_text_header_query_tooltip_cb (GtkEntry *entry,
 51                                        gint x,
 52                                        gint y,
 53                                        gboolean keyboard_mode,
 54                                        GtkTooltip *tooltip)
 55 {
 56 	const gchar *text;
 57 
 58 	text = gtk_entry_get_text (entry);
 59 
 60 	if (keyboard_mode || text == NULL || *text == '\0')
 61 		return FALSE;
 62 
 63 	gtk_tooltip_set_text (tooltip, text);
 64 
 65 	return TRUE;
 66 }
 67 
 68 static void
 69 composer_text_header_constructed (GObject *object)
 70 {
 71 	GtkWidget *widget;
 72 	EComposerTextHeader *header;
 73 	EComposerTextHeaderClass *class;
 74 
 75 	header = E_COMPOSER_TEXT_HEADER (object);
 76 	class = E_COMPOSER_TEXT_HEADER_GET_CLASS (header);
 77 
 78 	/* Input widget must be set before chaining up. */
 79 
 80 	widget = g_object_new (class->entry_type, NULL);
 81 	g_signal_connect (
 82 		widget, "changed",
 83 		G_CALLBACK (composer_text_header_changed_cb), header);
 84 	g_signal_connect (
 85 		widget, "query-tooltip",
 86 		G_CALLBACK (composer_text_header_query_tooltip_cb), NULL);
 87 	gtk_widget_set_has_tooltip (widget, TRUE);
 88 	E_COMPOSER_HEADER (object)->input_widget = g_object_ref_sink (widget);
 89 
 90 	/* Chain up to parent's constructed() method. */
 91 	G_OBJECT_CLASS (e_composer_text_header_parent_class)->
 92 		constructed (object);
 93 }
 94 
 95 static void
 96 e_composer_text_header_class_init (EComposerTextHeaderClass *class)
 97 {
 98 	GObjectClass *object_class;
 99 
100 	class->entry_type = GTK_TYPE_ENTRY;
101 
102 	object_class = G_OBJECT_CLASS (class);
103 	object_class->constructed = composer_text_header_constructed;
104 }
105 
106 static void
107 e_composer_text_header_init (EComposerTextHeader *header)
108 {
109 }
110 
111 EComposerHeader *
112 e_composer_text_header_new_label (ESourceRegistry *registry,
113                                   const gchar *label)
114 {
115 	g_return_val_if_fail (E_IS_SOURCE_REGISTRY (registry), NULL);
116 
117 	return g_object_new (
118 		E_TYPE_COMPOSER_TEXT_HEADER,
119 		"label", label, "button", FALSE,
120 		"registry", registry, NULL);
121 }
122 
123 EComposerHeader *
124 e_composer_text_header_new_button (ESourceRegistry *registry,
125                                    const gchar *label)
126 {
127 	g_return_val_if_fail (E_IS_SOURCE_REGISTRY (registry), NULL);
128 
129 	return g_object_new (
130 		E_TYPE_COMPOSER_TEXT_HEADER,
131 		"label", label, "button", TRUE,
132 		"registry", registry, NULL);
133 }
134 
135 const gchar *
136 e_composer_text_header_get_text (EComposerTextHeader *header)
137 {
138 	GtkEntry *entry;
139 
140 	g_return_val_if_fail (E_IS_COMPOSER_TEXT_HEADER (header), NULL);
141 
142 	entry = E_COMPOSER_TEXT_HEADER_GET_ENTRY (header);
143 
144 	return gtk_entry_get_text (entry);
145 }
146 
147 void
148 e_composer_text_header_set_text (EComposerTextHeader *header,
149                                  const gchar *text)
150 {
151 	GtkEntry *entry;
152 
153 	g_return_if_fail (E_IS_COMPOSER_TEXT_HEADER (header));
154 
155 	entry = E_COMPOSER_TEXT_HEADER_GET_ENTRY (header);
156 
157 	gtk_entry_set_text (entry, (text != NULL) ? text : "");
158 }