summaryrefslogtreecommitdiff
path: root/app/wlib/gtklib/gtksplash.c
blob: 0f4977422e42bec3e0c259e27ea23a305d8d0a41 (plain)
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
/** \file gtksplash.c
 * Handling of the Splash Window functions
 *
 * $Header: /home/dmarkle/xtrkcad-fork-cvs/xtrkcad/app/wlib/gtklib/gtksplash.c,v 1.5 2009-05-31 14:48:58 m_fischer Exp $
 */

/*  XTrkCad - Model Railroad CAD
 *  Copyright (C) 2007 Martin Fischer
 *
 *  This program 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.
 *
 *  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 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>

#include <gdk/gdkkeysyms.h>
#include <gtk/gtk.h>

#include "gtkint.h"

#define LOGOFILENAME "logo.bmp"

static GtkWidget *window;	/** splash window handle */
static GtkWidget *message;	/** window handle for progress message */

/**
 * Create the splash window shown during startup. The function loads the logo 
 * bitmap and displays the program name and version as passed. 
 *
 * \param IN  appName the product name to be shown
 * \param IN  appVer  the product version to be shown
 * \return    TRUE if window was created, FALSE if an error occured
 */

int
wCreateSplash( char *appName, char *appVer )
{
   GtkWidget *vbox;
   GtkWidget *image;
   GtkWidget *label;
	char *temp;
	char logoPath[BUFSIZ];

	/* create the basic window */
   window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
	gtk_window_set_decorated( GTK_WINDOW (window), FALSE );
   gtk_window_set_title (GTK_WINDOW (window), appName); 
   gtk_window_set_position (GTK_WINDOW (window), GTK_WIN_POS_CENTER);
   gtk_window_set_resizable (GTK_WINDOW (window), FALSE);
   gtk_window_set_type_hint (GTK_WINDOW (window), GDK_WINDOW_TYPE_HINT_SPLASHSCREEN);
#if GTK_MINOR_VERSION > 5
   gtk_window_set_focus_on_map (GTK_WINDOW (window), FALSE);
#endif

   vbox = gtk_vbox_new (FALSE, 0);
   gtk_widget_show (vbox);
   gtk_container_add (GTK_CONTAINER (window), vbox);

   /* add the logo image to the top of the splash window */
   sprintf( logoPath, "%s/" LOGOFILENAME, wGetAppLibDir());
   image = gtk_image_new_from_file ( logoPath );
   gtk_widget_show (image);
   gtk_box_pack_start (GTK_BOX (vbox), image, TRUE, TRUE, 0);
   gtk_misc_set_alignment (GTK_MISC (image), 0, 0);

   /* put the product name into the window */
	
	temp = malloc( strlen( appName ) + strlen( appVer ) + 2 );
	if( !temp )
		return( FALSE );
		
	sprintf( temp, "%s %s", appName, appVer );	
	
   label = gtk_label_new ( temp );
   gtk_widget_show (label);
   gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
   gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_FILL);
   gtk_label_set_selectable (GTK_LABEL (label), FALSE);
   gtk_misc_set_padding (GTK_MISC (label), 6, 2);

	free( temp );

   label = gtk_label_new ("Application is starting...");
   gtk_widget_show (label);
   gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
   gtk_label_set_line_wrap (GTK_LABEL (label), FALSE);
   gtk_misc_set_padding (GTK_MISC (label), 6, 2);
#if GTK_MINOR_VERSION > 5   
   gtk_label_set_ellipsize (GTK_LABEL (label), PANGO_ELLIPSIZE_START);
#endif   
   message = label;	

	gtk_widget_show( window );
	
   return( TRUE );
}

/**
 * Update the progress message inside the splash window
 * msg	text message to display
 * return nonzero if ok
 */ 

int 
wSetSplashInfo( char *msg )
{
	if( msg ) {
		gtk_label_set_text( (GtkLabel *)message, msg );
		wFlush();
		return TRUE;
	}
	return FALSE;
}

/**
 * Destroy the splash window.
 *
 */

void 
wDestroySplash( void )
{
	/* kill window */
	gtk_widget_destroy( window );
	return;
}