072c704423476d0564b01f0c1ee1959d58189339
[modest] / src / gtk2 / modest-msg-window.c
1 /* Copyright (c) 2006, Nokia Corporation
2  * All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  *   notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  *   notice, this list of conditions and the following disclaimer in the
12  *   documentation and/or other materials provided with the distribution.
13  * * Neither the name of the Nokia Corporation nor the names of its
14  *   contributors may be used to endorse or promote products derived from
15  *   this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
18  * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
20  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
21  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
24  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  */
29
30 #include <modest-tny-msg-view.h>
31 #include "modest-msg-window.h"
32
33 /* 'private'/'protected' functions */
34 static void                   modest_msg_window_class_init    (ModestMsgWindowClass *klass);
35 static void                   modest_msg_window_init          (ModestMsgWindow *obj);
36 static void                   modest_msg_window_finalize      (GObject *obj);
37
38 /* list my signals */
39 enum {
40         /* MY_SIGNAL_1, */
41         /* MY_SIGNAL_2, */
42         LAST_SIGNAL
43 };
44
45 typedef struct _ModestMsgWindowPrivate ModestMsgWindowPrivate;
46 struct _ModestMsgWindowPrivate {
47         /* my private members go here, eg. */
48         /* gboolean frobnicate_mode; */
49 };
50 #define MODEST_MSG_WINDOW_GET_PRIVATE(o)      (G_TYPE_INSTANCE_GET_PRIVATE((o), \
51                                                MODEST_TYPE_MSG_WINDOW, \
52                                                ModestMsgWindowPrivate))
53 /* globals */
54 static GtkWindowClass *parent_class = NULL;
55
56 /* uncomment the following if you have defined any signals */
57 /* static guint signals[LAST_SIGNAL] = {0}; */
58
59 GType
60 modest_msg_window_get_type (void)
61 {
62         static GType my_type = 0;
63         if (!my_type) {
64                 static const GTypeInfo my_info = {
65                         sizeof(ModestMsgWindowClass),
66                         NULL,           /* base init */
67                         NULL,           /* base finalize */
68                         (GClassInitFunc) modest_msg_window_class_init,
69                         NULL,           /* class finalize */
70                         NULL,           /* class data */
71                         sizeof(ModestMsgWindow),
72                         1,              /* n_preallocs */
73                         (GInstanceInitFunc) modest_msg_window_init,
74                 };
75                 my_type = g_type_register_static (GTK_TYPE_WINDOW,
76                                                   "ModestMsgWindow",
77                                                   &my_info, 0);
78         }
79         return my_type;
80 }
81
82 static void
83 modest_msg_window_class_init (ModestMsgWindowClass *klass)
84 {
85         GObjectClass *gobject_class;
86         gobject_class = (GObjectClass*) klass;
87
88         parent_class            = g_type_class_peek_parent (klass);
89         gobject_class->finalize = modest_msg_window_finalize;
90
91         g_type_class_add_private (gobject_class, sizeof(ModestMsgWindowPrivate));
92
93         /* signal definitions go here, e.g.: */
94 /*      signals[MY_SIGNAL_1] = */
95 /*              g_signal_new ("my_signal_1",....); */
96 /*      signals[MY_SIGNAL_2] = */
97 /*              g_signal_new ("my_signal_2",....); */
98 /*      etc. */
99 }
100
101 static void
102 modest_msg_window_init (ModestMsgWindow *obj)
103 {
104         GtkWidget *to_button, *cc_button, *bcc_button, *subject_label;
105         GtkWidget *to_field, *cc_field, *bcc_field, *subject_field;
106         GtkWidget *header_table;
107         GtkWidget *main_vbox;
108         GtkWidget *msg_field;
109         
110         ModestMsgWindowPrivate *priv;
111         priv = MODEST_MSG_WINDOW_GET_PRIVATE(obj);
112
113         to_button     = gtk_button_new_with_label (_("To..."));
114         cc_button     = gtk_button_new_with_label (_("Cc..."));
115         bcc_button    = gtk_button_new_with_label (_("Bcc..."));
116         subject_label = gtk_label_new (_("Subject:"));
117         
118         to_field      = gtk_entry_new ();
119         cc_field      = gtk_entry_new ();
120         bcc_field     = gtk_entry_new ();
121         subject_field = gtk_entry_new ();
122
123         header_table = gtk_table_new (4,2, FALSE);
124         gtk_table_attach_defaults (GTK_TABLE(header_table), to_button,     0,1,0,1);
125         gtk_table_attach_defaults (GTK_TABLE(header_table), cc_button,     0,1,1,2);
126         gtk_table_attach_defaults (GTK_TABLE(header_table), bcc_button,    0,1,2,3);
127         gtk_table_attach_defaults (GTK_TABLE(header_table), subject_label, 0,1,3,4);
128
129         gtk_table_attach_defaults (GTK_TABLE(header_table), to_field,      1,2,0,1);
130         gtk_table_attach_defaults (GTK_TABLE(header_table), cc_field,      1,2,1,2);
131         gtk_table_attach_defaults (GTK_TABLE(header_table), bcc_field,     1,2,2,3);
132         gtk_table_attach_defaults (GTK_TABLE(header_table), subject_field, 1,2,3,4);
133
134         msg_field = modest_tny_msg_view_new (NULL);
135         
136         main_vbox = gtk_vbox_new  (FALSE, 6);
137
138         gtk_box_pack_start (GTK_BOX(main_vbox), header_table, FALSE, FALSE, 6);
139         gtk_box_pack_start (GTK_BOX(main_vbox), msg_field,    TRUE, TRUE, 6);
140
141         gtk_widget_show_all (GTK_WIDGET(main_vbox));
142         
143         gtk_container_add (GTK_CONTAINER(obj), main_vbox);
144 }
145
146 static void
147 modest_msg_window_finalize (GObject *obj)
148 {
149 /*      free/unref instance resources here */
150 }
151
152 GtkWidget*
153 modest_msg_window_new  (ModestMsgWindowType type, TnyMsgIface *msg)
154 {
155         GObject *obj;
156         
157         g_return_val_if_fail ((type >= 1 && type <= MODEST_MSG_WINDOW_TYPE_NUM), NULL);
158         
159         obj = g_object_new(MODEST_TYPE_MSG_WINDOW, NULL);
160
161         return GTK_WIDGET (obj);
162 }
163