1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
4 * Copyright (C) 2000, 2001 Ximian, Inc.
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of the
9 * License, or (at your option) any later version.
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 * General Public License for more details.
16 * You should have received a copy of the GNU General Public
17 * License along with this program; if not, write to the
18 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
21 * Author: Ettore Perazzoli
26 * @short_description: Splash screen
28 * @stability: Unstable
29 * @include: libanjuta/e-splash.h
37 #include <libgnomecanvas/gnome-canvas-pixbuf.h>
38 #include <libgnomecanvas/libgnomecanvas.h>
43 struct _ESplashPrivate
{
45 GnomeCanvasItem
*canvas_icon
;
46 GnomeCanvasItem
*canvas_text
;
47 GnomeCanvasItem
*canvas_line
;
48 GnomeCanvasItem
*canvas_line_back
;
49 GdkPixbuf
*splash_image_pixbuf
;
50 gint progressbar_position
;
53 G_DEFINE_TYPE(ESplash
, e_splash
, GTK_TYPE_WINDOW
)
55 /* Layout constants. These need to be changed if the splash changes. */
57 #define ICON_Y priv->progressbar_position
60 #define PROGRESS_SIZE 5
62 /* GtkObject methods. */
65 impl_destroy (GtkObject
*object
)
70 splash
= E_SPLASH (object
);
73 if (priv
->splash_image_pixbuf
!= NULL
)
74 gdk_pixbuf_unref (priv
->splash_image_pixbuf
);
79 e_splash_finalize (GObject
*obj
)
81 G_OBJECT_CLASS (e_splash_parent_class
)->finalize (obj
);
85 e_splash_class_init (ESplashClass
*klass
)
87 GtkObjectClass
*gtkobject_class
= GTK_OBJECT_CLASS (klass
);;
88 GObjectClass
*object_class
= G_OBJECT_CLASS (klass
);
90 gtkobject_class
->destroy
= impl_destroy
;
92 object_class
->finalize
= e_splash_finalize
;
96 e_splash_init (ESplash
*splash
)
100 priv
= g_new (ESplashPrivate
, 1);
102 priv
->splash_image_pixbuf
= NULL
;
103 priv
->progressbar_position
= 100;
108 button_press_event (GtkWidget
*widget
, GdkEventButton
*event
, gpointer data
)
110 ESplash
*splash
= (ESplash
*) data
;
112 gtk_widget_hide (GTK_WIDGET (splash
));
118 * e_splash_construct:
119 * @splash: A pointer to an ESplash widget
120 * @splash_image_pixbuf: The pixbuf for the image to appear in the splash dialog
122 * Construct @splash with @splash_image_pixbuf as the splash image.
125 e_splash_construct (ESplash
*splash
,
126 GdkPixbuf
*splash_image_pixbuf
,
127 gint progressbar_position
)
129 ESplashPrivate
*priv
;
130 GtkWidget
*canvas
; /*, *frame; */
131 int image_width
, image_height
;
133 g_return_if_fail (splash
!= NULL
);
134 g_return_if_fail (E_IS_SPLASH (splash
));
135 g_return_if_fail (splash_image_pixbuf
!= NULL
);
138 priv
->progressbar_position
= progressbar_position
;
139 priv
->splash_image_pixbuf
= gdk_pixbuf_ref (splash_image_pixbuf
);
141 canvas
= gnome_canvas_new_aa ();
142 priv
->canvas
= GNOME_CANVAS (canvas
);
144 image_width
= gdk_pixbuf_get_width (splash_image_pixbuf
);
145 image_height
= gdk_pixbuf_get_height (splash_image_pixbuf
);
147 gtk_widget_set_size_request (canvas
, image_width
, image_height
);
148 gnome_canvas_set_scroll_region (GNOME_CANVAS (canvas
), 0, 0, image_width
, image_height
);
149 gtk_widget_show (canvas
);
151 gtk_container_add (GTK_CONTAINER (splash
), canvas
);
153 gnome_canvas_item_new (GNOME_CANVAS_GROUP (priv
->canvas
->root
),
154 GNOME_TYPE_CANVAS_PIXBUF
,
155 "pixbuf", splash_image_pixbuf
,
157 priv
->canvas_icon
= gnome_canvas_item_new (GNOME_CANVAS_GROUP (priv
->canvas
->root
),
158 GNOME_TYPE_CANVAS_PIXBUF
,
159 "x", (double) (ICON_X
),
160 "y", (double) (ICON_Y
),
162 priv
->canvas_text
= gnome_canvas_item_new (GNOME_CANVAS_GROUP (priv
->canvas
->root
),
163 GNOME_TYPE_CANVAS_TEXT
,
164 "fill_color", "black",
165 "size_points", (double)12,
166 "anchor", GTK_ANCHOR_SOUTH_WEST
,
167 "x", (double)(ICON_X
+ ICON_SIZE
+ 10),
168 "y", (double)(ICON_Y
+ ICON_SIZE
- PROGRESS_SIZE
),
170 priv
->canvas_line
= gnome_canvas_item_new (GNOME_CANVAS_GROUP (priv
->canvas
->root
),
171 GNOME_TYPE_CANVAS_LINE
,
172 "fill_color", "black",
173 "width_pixels", PROGRESS_SIZE
,
175 priv
->canvas_line_back
= gnome_canvas_item_new (GNOME_CANVAS_GROUP (priv
->canvas
->root
),
176 GNOME_TYPE_CANVAS_LINE
,
177 "fill_color", "blue",
178 "width_pixels", PROGRESS_SIZE
,
180 g_signal_connect (G_OBJECT (splash
), "button-press-event",
181 G_CALLBACK (button_press_event
), splash
);
183 gtk_window_set_decorated(GTK_WINDOW(splash
), FALSE
);
184 gtk_window_set_position (GTK_WINDOW (splash
), GTK_WIN_POS_CENTER
);
185 gtk_window_set_resizable (GTK_WINDOW (splash
), FALSE
);
186 gtk_window_set_default_size (GTK_WINDOW (splash
), image_width
, image_height
);
187 gtk_window_set_title (GTK_WINDOW (splash
), "Anjuta");
193 * @image_file: Splash image file
195 * Create a new ESplash widget.
197 * Return value: A pointer to the newly created ESplash widget.
200 e_splash_new (const char *image_file
, gint progressbar_position
)
203 GdkPixbuf
*splash_image_pixbuf
;
205 splash_image_pixbuf
= gdk_pixbuf_new_from_file (image_file
, NULL
);
206 g_return_val_if_fail (splash_image_pixbuf
!= NULL
, NULL
);
208 splash
= g_object_new (e_splash_get_type (), "type", GTK_WINDOW_TOPLEVEL
, NULL
);
209 e_splash_construct (splash
, splash_image_pixbuf
, progressbar_position
);
211 /* gdk_pixbuf_unref (splash_image_pixbuf); */
213 return GTK_WIDGET (splash
);
218 * @splash: A pointer to an ESplash widget
219 * @icon_pixbuf: Pixbuf for the icon to be added
221 * @desc: Description.
222 * @progress_percentage: percentage of progress.
224 * Set the current progress/icon/text.
227 e_splash_set (ESplash
*splash
, GdkPixbuf
*icon_pixbuf
,
228 const gchar
*title
, const gchar
*desc
,
229 gfloat progress_percentage
)
231 ESplashPrivate
*priv
;
232 GnomeCanvasPoints
*points
;
233 gint inc_width
, progress_width
;
235 g_return_if_fail (splash
!= NULL
);
236 g_return_if_fail (E_IS_SPLASH (splash
));
238 #ifdef GNOME2_CONVERSION_COMPLETE
239 if (GTK_OBJECT_DESTROYED (splash
))
247 GdkPixbuf
*scaled_pixbuf
;
249 scaled_pixbuf
= gdk_pixbuf_new (GDK_COLORSPACE_RGB
, TRUE
,
250 8, ICON_SIZE
, ICON_SIZE
);
251 gdk_pixbuf_scale (icon_pixbuf
, scaled_pixbuf
,
253 ICON_SIZE
, ICON_SIZE
,
255 (double) ICON_SIZE
/ gdk_pixbuf_get_width (icon_pixbuf
),
256 (double) ICON_SIZE
/ gdk_pixbuf_get_height (icon_pixbuf
),
258 g_object_set (G_OBJECT (priv
->canvas_icon
),
259 "pixbuf", scaled_pixbuf
, NULL
);
260 gdk_pixbuf_unref (scaled_pixbuf
);
265 g_object_set (G_OBJECT (priv
->canvas_text
),
266 "markup", title
, NULL
);
269 inc_width
= gdk_pixbuf_get_width (priv
->splash_image_pixbuf
);
270 inc_width
-= (ICON_X
+ ICON_SIZE
+ 20);
271 progress_width
= inc_width
;
273 points
= gnome_canvas_points_new (2);
274 points
->coords
[0] = ICON_X
+ ICON_SIZE
+ 10;
275 points
->coords
[1] = ICON_Y
+ ICON_SIZE
;
276 points
->coords
[2] = ICON_X
+ ICON_SIZE
+ 10 + (progress_percentage
* inc_width
);
277 points
->coords
[3] = ICON_Y
+ ICON_SIZE
;
279 g_object_set (G_OBJECT (priv
->canvas_line
),
280 "points", points
, NULL
);
281 gnome_canvas_points_unref (points
);
283 points
= gnome_canvas_points_new (2);
284 points
->coords
[0] = ICON_X
+ ICON_SIZE
+ 10 + (progress_percentage
* inc_width
);
285 points
->coords
[1] = ICON_Y
+ ICON_SIZE
;
286 points
->coords
[2] = ICON_X
+ ICON_SIZE
+ 10 + progress_width
;
287 points
->coords
[3] = ICON_Y
+ ICON_SIZE
;
289 g_object_set (G_OBJECT (priv
->canvas_line_back
),
290 "points", points
, NULL
);
291 gnome_canvas_points_unref (points
);