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
/* ev-loading-message.c
 *  this file is part of lector, a cafe document viewer
 *
 * Copyright (C) 2010, 2012 Carlos Garcia Campos <carlosgc@gnome.org>
 *
 * Lector 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 2 of the License, or
 * (at your option) any later version.
 *
 * Lector 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
 * 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
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */

#include "config.h"
#include "ev-loading-message.h"

#include <string.h>
#include <glib/gi18n.h>

struct _EvLoadingMessage {
        CtkBox     base_instance;

        CtkWidget *spinner;
};

struct _EvLoadingMessageClass {
        CtkBoxClass base_class;
};

G_DEFINE_TYPE (EvLoadingMessage, ev_loading_message, CTK_TYPE_BOX)<--- There is an unknown macro here somewhere. Configuration is required. If G_DEFINE_TYPE is a macro then please configure it.

static void
ev_loading_message_init (EvLoadingMessage *message)
{
        CtkWidget *label;

        ctk_container_set_border_width (CTK_CONTAINER (message), 10);

        message->spinner = ctk_spinner_new ();
        ctk_box_pack_start (CTK_BOX (message), message->spinner, FALSE, FALSE, 0);
        ctk_widget_show (message->spinner);

        label = ctk_label_new (_("Loading…"));
        ctk_box_pack_start (CTK_BOX (message), label, FALSE, FALSE, 0);
        ctk_widget_show (label);
}

static void
get_widget_padding (CtkWidget *widget,
                    CtkBorder *padding)
{
        CtkStyleContext *context;
        CtkStateFlags state;

        context = ctk_widget_get_style_context (widget);
        state = ctk_style_context_get_state (context);
        ctk_style_context_get_padding (context, state, padding);
}

static void
ev_loading_message_size_allocate (CtkWidget     *widget,
                                  CtkAllocation *allocation)
{
        CtkAllocation child_allocation;
        CtkBorder padding;

        get_widget_padding (widget, &padding);
        child_allocation.y = allocation->x + padding.left;
        child_allocation.x = allocation->y + padding.top;
        child_allocation.width = MAX (1, allocation->width - (padding.left + padding.right));
        child_allocation.height = MAX (1, allocation->height - (padding.top + padding.bottom));

        CTK_WIDGET_CLASS (ev_loading_message_parent_class)->size_allocate (widget, &child_allocation);
        ctk_widget_set_allocation (widget, allocation);
}

static void
ev_loading_message_get_preferred_width (CtkWidget *widget,
                                        gint      *minimum_size,
                                        gint      *natural_size)
{
        CtkBorder padding;

        CTK_WIDGET_CLASS (ev_loading_message_parent_class)->get_preferred_width (widget, minimum_size, natural_size);

        get_widget_padding (widget, &padding);
        *minimum_size += padding.left + padding.right;
        *natural_size += padding.left + padding.right;
}

static void
ev_loading_message_get_preferred_height (CtkWidget *widget,
                                         gint      *minimum_size,
                                         gint      *natural_size)
{
        CtkBorder padding;

        CTK_WIDGET_CLASS (ev_loading_message_parent_class)->get_preferred_height (widget, minimum_size, natural_size);

        get_widget_padding (widget, &padding);
        *minimum_size += padding.top + padding.bottom;
        *natural_size += padding.top + padding.bottom;
}

static gboolean
ev_loading_message_draw (CtkWidget *widget,
                         cairo_t   *cr)
{
        CtkStyleContext *context;
        gint             width, height;

        context = ctk_widget_get_style_context (widget);
        width = ctk_widget_get_allocated_width (widget);
        height = ctk_widget_get_allocated_height (widget);

        ctk_render_background (context, cr, 0, 0, width, height);
        ctk_render_frame (context, cr, 0, 0, width, height);

        CTK_WIDGET_CLASS (ev_loading_message_parent_class)->draw (widget, cr);

        return TRUE;
}

static void
ev_loading_message_hide (CtkWidget *widget)
{
        EvLoadingMessage *message = EV_LOADING_MESSAGE (widget);

        ctk_spinner_stop (CTK_SPINNER (message->spinner));

        CTK_WIDGET_CLASS (ev_loading_message_parent_class)->hide (widget);
}

static void
ev_loading_message_show (CtkWidget *widget)
{
        EvLoadingMessage *message = EV_LOADING_MESSAGE (widget);

        ctk_spinner_start (CTK_SPINNER (message->spinner));

        CTK_WIDGET_CLASS (ev_loading_message_parent_class)->show (widget);
}

static void
ev_loading_message_class_init (EvLoadingMessageClass *klass)
{
        CtkWidgetClass *ctk_widget_class = CTK_WIDGET_CLASS (klass);

        ctk_widget_class->size_allocate = ev_loading_message_size_allocate;
        ctk_widget_class->get_preferred_width = ev_loading_message_get_preferred_width;
        ctk_widget_class->get_preferred_height = ev_loading_message_get_preferred_height;
        ctk_widget_class->draw = ev_loading_message_draw;
        ctk_widget_class->show = ev_loading_message_show;
        ctk_widget_class->hide = ev_loading_message_hide;
}

/* Public methods */
CtkWidget *
ev_loading_message_new (void)
{
        CtkWidget *message;

        message = g_object_new (EV_TYPE_LOADING_MESSAGE,
                                "orientation", CTK_ORIENTATION_HORIZONTAL,
                                "spacing", 12,
                                NULL);
        return message;
}