aboutsummaryrefslogtreecommitdiffstats
path: root/widgets/misc/e-preview-pane.c
blob: 240bfbd82444fb70e160f3109995f6cb30f9f1f3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
/*
 * e-preview-pane.c
 *
 * This program 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 of the License, or (at your option) version 3.
 *
 * This program 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 the program; if not, see <http://www.gnu.org/licenses/>
 *
 *
 * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
 *
 */

#include "e-preview-pane.h"

#include <gdk/gdkkeysyms.h>

#define E_PREVIEW_PANE_GET_PRIVATE(obj) \
    (G_TYPE_INSTANCE_GET_PRIVATE \
    ((obj), E_TYPE_PREVIEW_PANE, EPreviewPanePrivate))

struct _EPreviewPanePrivate {
    GtkWidget *web_view;
    GtkWidget *search_bar;
};

enum {
    PROP_0,
    PROP_SEARCH_BAR,
    PROP_WEB_VIEW
};

enum {
    SHOW_SEARCH_BAR,
    LAST_SIGNAL
};

static gpointer parent_class;
static guint signals[LAST_SIGNAL];

static void
preview_pane_set_web_view (EPreviewPane *preview_pane,
                           EWebView *web_view)
{
    g_return_if_fail (E_IS_WEB_VIEW (web_view));
    g_return_if_fail (preview_pane->priv->web_view == NULL);

    preview_pane->priv->web_view = g_object_ref_sink (web_view);
}

static void
preview_pane_set_property (GObject *object,
                           guint property_id,
                           const GValue *value,
                           GParamSpec *pspec)
{
    switch (property_id) {
        case PROP_WEB_VIEW:
            preview_pane_set_web_view (
                E_PREVIEW_PANE (object),
                g_value_get_object (value));
            return;
    }

    G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
}

static void
preview_pane_get_property (GObject *object,
                           guint property_id,
                           GValue *value,
                           GParamSpec *pspec)
{
    switch (property_id) {
        case PROP_SEARCH_BAR:
            g_value_set_object (
                value, e_preview_pane_get_search_bar (
                E_PREVIEW_PANE (object)));
            return;

        case PROP_WEB_VIEW:
            g_value_set_object (
                value, e_preview_pane_get_web_view (
                E_PREVIEW_PANE (object)));
            return;
    }

    G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
}

static void
preview_pane_dispose (GObject *object)
{
    EPreviewPanePrivate *priv;

    priv = E_PREVIEW_PANE_GET_PRIVATE (object);

    if (priv->search_bar != NULL) {
        g_object_unref (priv->search_bar);
        priv->search_bar = NULL;
    }

    if (priv->web_view != NULL) {
        g_object_unref (priv->web_view);
        priv->web_view = NULL;
    }

    /* Chain up to parent's dispose() method. */
    G_OBJECT_CLASS (parent_class)->dispose (object);
}

static void
preview_pane_constructed (GObject *object)
{
    EPreviewPanePrivate *priv;
    GtkWidget *widget;

    priv = E_PREVIEW_PANE_GET_PRIVATE (object);

    widget = gtk_scrolled_window_new (NULL, NULL);
    gtk_scrolled_window_set_policy (
        GTK_SCROLLED_WINDOW (widget),
        GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
    gtk_scrolled_window_set_shadow_type (
        GTK_SCROLLED_WINDOW (widget), GTK_SHADOW_IN);
    gtk_box_pack_start (GTK_BOX (object), widget, TRUE, TRUE, 0);
    gtk_container_add (GTK_CONTAINER (widget), priv->web_view);
    gtk_widget_show (widget);

    widget = e_search_bar_new (E_WEB_VIEW (priv->web_view));
    gtk_box_pack_start (GTK_BOX (object), widget, FALSE, FALSE, 0);
    priv->search_bar = g_object_ref (widget);
    gtk_widget_hide (widget);
}

static void
preview_pane_show_search_bar (EPreviewPane *preview_pane)
{
    GtkWidget *search_bar;

    search_bar = preview_pane->priv->search_bar;

    if (!gtk_widget_get_visible (search_bar))
        gtk_widget_show (search_bar);
}

static void
preview_pane_class_init (EPreviewPaneClass *class)
{
    GObjectClass *object_class;
    GtkBindingSet *binding_set;

    parent_class = g_type_class_peek_parent (class);
    g_type_class_add_private (class, sizeof (EPreviewPanePrivate));

    object_class = G_OBJECT_CLASS (class);
    object_class->set_property = preview_pane_set_property;
    object_class->get_property = preview_pane_get_property;
    object_class->dispose = preview_pane_dispose;
    object_class->constructed = preview_pane_constructed;

    class->show_search_bar = preview_pane_show_search_bar;

    g_object_class_install_property (
        object_class,
        PROP_SEARCH_BAR,
        g_param_spec_object (
            "search-bar",
            "Search Bar",
            NULL,
            E_TYPE_SEARCH_BAR,
            G_PARAM_READABLE));

    g_object_class_install_property (
        object_class,
        PROP_WEB_VIEW,
        g_param_spec_object (
            "web-view",
            "Web View",
            NULL,
            E_TYPE_WEB_VIEW,
            G_PARAM_READWRITE |
            G_PARAM_CONSTRUCT_ONLY));

    signals[SHOW_SEARCH_BAR] = g_signal_new (
        "show-search-bar",
        G_TYPE_FROM_CLASS (class),
        G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
        G_STRUCT_OFFSET (EPreviewPaneClass, show_search_bar),
        NULL, NULL,
        g_cclosure_marshal_VOID__VOID,
        G_TYPE_NONE, 0);

    binding_set = gtk_binding_set_by_class (class);

    gtk_binding_entry_add_signal (
        binding_set, GDK_f, GDK_SHIFT_MASK | GDK_CONTROL_MASK,
        "show-search-bar", 0);
}

static void
preview_pane_init (EPreviewPane *preview_pane)
{
    preview_pane->priv = E_PREVIEW_PANE_GET_PRIVATE (preview_pane);

    gtk_box_set_spacing (GTK_BOX (preview_pane), 1);
}

GType
e_preview_pane_get_type (void)
{
    static GType type = 0;

    if (G_UNLIKELY (type == 0)) {
        static const GTypeInfo type_info = {
            sizeof (EPreviewPaneClass),
            (GBaseInitFunc) NULL,
            (GBaseFinalizeFunc) NULL,
            (GClassInitFunc) preview_pane_class_init,
            (GClassFinalizeFunc) NULL,
            NULL,  /* class_data */
            sizeof (EPreviewPane),
            0,     /* n_preallocs */
            (GInstanceInitFunc) preview_pane_init,
            NULL   /* value_table */
        };

        type = g_type_register_static (
            GTK_TYPE_VBOX, "EPreviewPane", &type_info, 0);
    }

    return type;
}

GtkWidget *
e_preview_pane_new (EWebView *web_view)
{
    g_return_val_if_fail (E_IS_WEB_VIEW (web_view), NULL);

    return g_object_new (
        E_TYPE_PREVIEW_PANE,
        "web-view", web_view, NULL);
}

EWebView *
e_preview_pane_get_web_view (EPreviewPane *preview_pane)
{
    g_return_val_if_fail (E_IS_PREVIEW_PANE (preview_pane), NULL);

    return E_WEB_VIEW (preview_pane->priv->web_view);
}

ESearchBar *
e_preview_pane_get_search_bar (EPreviewPane *preview_pane)
{
    g_return_val_if_fail (E_IS_PREVIEW_PANE (preview_pane), NULL);

    return E_SEARCH_BAR (preview_pane->priv->search_bar);
}

void
e_preview_pane_show_search_bar (EPreviewPane *preview_pane)
{
    g_return_if_fail (E_IS_PREVIEW_PANE (preview_pane));

    g_signal_emit (preview_pane, signals[SHOW_SEARCH_BAR], 0);
}