2000-02-13 18:23:28 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
2000-02-14 01:24:14 +03:00
|
|
|
* The contents of this file are subject to the Mozilla Public
|
2000-02-13 18:23:28 +03:00
|
|
|
* License Version 1.1 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
2000-02-14 01:24:14 +03:00
|
|
|
* the License at http://www.mozilla.org/MPL/
|
|
|
|
*
|
2000-02-13 18:23:28 +03:00
|
|
|
* Software distributed under the License is distributed on an "AS
|
|
|
|
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
|
|
|
* implied. See the License for the specific language governing
|
|
|
|
* rights and limitations under the License.
|
2000-02-14 01:24:14 +03:00
|
|
|
*
|
|
|
|
* The Original Code is the Mozilla browser.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Netscape
|
|
|
|
* Communications Corporation. Portions created by Netscape are
|
|
|
|
* Copyright (C) 1999 Netscape Communications Corporation. All
|
2000-02-13 18:23:28 +03:00
|
|
|
* Rights Reserved.
|
2000-02-14 01:24:14 +03:00
|
|
|
*
|
2000-02-13 18:23:28 +03:00
|
|
|
* Contributor(s):
|
|
|
|
* syd@netscape.com 2/12/00.
|
2000-02-14 01:24:14 +03:00
|
|
|
* pavlov@netscape.com 2/13/00.
|
2000-02-13 18:23:28 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "nsNativeAppSupport.h"
|
|
|
|
#include "gdk/gdk.h"
|
|
|
|
#include "gdk/gdkprivate.h"
|
|
|
|
|
|
|
|
class nsSplashScreenGtk : public nsISplashScreen {
|
|
|
|
public:
|
2000-02-14 01:24:14 +03:00
|
|
|
nsSplashScreenGtk();
|
|
|
|
virtual ~nsSplashScreenGtk();
|
2000-02-13 18:23:28 +03:00
|
|
|
|
2000-02-14 01:24:14 +03:00
|
|
|
NS_IMETHOD Show();
|
|
|
|
NS_IMETHOD Hide();
|
2000-02-13 18:23:28 +03:00
|
|
|
|
2000-02-14 01:24:14 +03:00
|
|
|
NS_DECL_ISUPPORTS
|
2000-02-13 18:23:28 +03:00
|
|
|
|
2000-02-14 01:24:14 +03:00
|
|
|
GdkWindow *mDialog;
|
2000-02-13 18:23:28 +03:00
|
|
|
}; // class nsSplashScreenGtk
|
|
|
|
|
2000-03-06 03:26:19 +03:00
|
|
|
NS_IMPL_THREADSAFE_ISUPPORTS0(nsSplashScreenGtk)
|
2000-02-14 01:24:14 +03:00
|
|
|
|
|
|
|
nsSplashScreenGtk::nsSplashScreenGtk()
|
|
|
|
{
|
|
|
|
NS_INIT_REFCNT();
|
|
|
|
// if this fails, we exit
|
|
|
|
gdk_init( 0, NULL );
|
|
|
|
}
|
|
|
|
|
|
|
|
nsSplashScreenGtk::~nsSplashScreenGtk()
|
|
|
|
{
|
|
|
|
Hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsSplashScreenGtk::Show()
|
2000-02-13 18:23:28 +03:00
|
|
|
{
|
2000-02-14 01:24:14 +03:00
|
|
|
GdkPixmap *pmap;
|
|
|
|
GdkBitmap *mask;
|
|
|
|
GdkWindowAttr attr;
|
|
|
|
int c, width, height, num_cols, cpp;
|
2000-02-13 18:23:28 +03:00
|
|
|
|
2000-02-14 01:24:14 +03:00
|
|
|
FILE *fp;
|
|
|
|
GdkColor transparentColor;
|
2000-02-13 18:23:28 +03:00
|
|
|
|
2000-02-14 01:24:14 +03:00
|
|
|
/* figure out what we are dealing with here */
|
2000-02-13 18:23:28 +03:00
|
|
|
|
2000-02-14 01:24:14 +03:00
|
|
|
if ( ( fp = fopen( "splash.xpm", "r" ) ) == (FILE *) NULL )
|
|
|
|
return NS_ERROR_FAILURE;
|
2000-02-13 18:23:28 +03:00
|
|
|
|
2000-02-14 01:24:14 +03:00
|
|
|
// find the first '"'
|
2000-02-13 18:23:28 +03:00
|
|
|
|
2000-02-14 01:24:14 +03:00
|
|
|
while ( !feof( fp ) ) {
|
|
|
|
c = fgetc( fp );
|
|
|
|
if ( c == '"' )
|
|
|
|
break;
|
|
|
|
}
|
2000-02-13 18:23:28 +03:00
|
|
|
|
2000-02-14 01:24:14 +03:00
|
|
|
if (feof(fp)) {
|
|
|
|
fclose( fp );
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* read size info */
|
2000-02-13 18:23:28 +03:00
|
|
|
|
2000-02-14 01:24:14 +03:00
|
|
|
fscanf( fp, "%d %d %d %d", &width, &height, &num_cols, &cpp );
|
2000-02-13 18:23:28 +03:00
|
|
|
|
2000-02-14 01:24:14 +03:00
|
|
|
fclose( fp );
|
2000-02-13 18:23:28 +03:00
|
|
|
|
2000-02-14 01:24:14 +03:00
|
|
|
/* create a window */
|
2000-02-13 18:23:28 +03:00
|
|
|
|
2000-02-14 01:24:14 +03:00
|
|
|
attr.window_type = GDK_WINDOW_TOPLEVEL;
|
|
|
|
attr.wclass = GDK_INPUT_OUTPUT;
|
|
|
|
attr.x = gdk_screen_width() >> 1; attr.x -= width >> 1;
|
|
|
|
attr.y = gdk_screen_height() >> 1; attr.y -= height >> 1;
|
|
|
|
attr.width = width;
|
|
|
|
attr.height = height;
|
|
|
|
attr.event_mask = 0;
|
2000-02-13 18:23:28 +03:00
|
|
|
|
2000-02-14 01:24:14 +03:00
|
|
|
mDialog = gdk_window_new( NULL, &attr, GDK_WA_X | GDK_WA_Y );
|
|
|
|
gdk_window_set_override_redirect(mDialog, PR_TRUE);
|
|
|
|
gdk_window_show( mDialog );
|
2000-02-13 18:23:28 +03:00
|
|
|
|
2000-02-14 01:24:14 +03:00
|
|
|
gdk_flush();
|
2000-02-13 18:23:28 +03:00
|
|
|
|
2000-02-14 01:24:14 +03:00
|
|
|
/* create a pixmap based on xpm data */
|
2000-02-13 18:23:28 +03:00
|
|
|
|
2000-02-14 01:24:14 +03:00
|
|
|
pmap = gdk_pixmap_colormap_create_from_xpm(mDialog,
|
|
|
|
gdk_colormap_get_system(),
|
|
|
|
&mask,
|
|
|
|
&transparentColor,
|
|
|
|
"splash.xpm" );
|
2000-02-13 18:23:28 +03:00
|
|
|
|
2000-02-14 01:24:14 +03:00
|
|
|
if ( !pmap ) {
|
|
|
|
gdk_window_destroy(mDialog);
|
|
|
|
mDialog = nsnull;
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2000-02-13 18:23:28 +03:00
|
|
|
|
2000-02-14 01:24:14 +03:00
|
|
|
GdkGC *gc;
|
2000-02-13 18:23:28 +03:00
|
|
|
|
2000-02-14 01:24:14 +03:00
|
|
|
gc = gdk_gc_new( mDialog );
|
2000-02-13 18:23:28 +03:00
|
|
|
|
2000-02-14 01:24:14 +03:00
|
|
|
gdk_window_copy_area( mDialog, gc, 0, 0, pmap, 0, 0, width, height );
|
2000-02-13 18:23:28 +03:00
|
|
|
|
2000-02-14 01:24:14 +03:00
|
|
|
gdk_flush();
|
2000-02-13 18:23:28 +03:00
|
|
|
|
2000-02-14 01:24:14 +03:00
|
|
|
gdk_gc_destroy(gc);
|
|
|
|
|
|
|
|
return NS_OK;
|
2000-02-13 18:23:28 +03:00
|
|
|
}
|
|
|
|
|
2000-02-14 01:24:14 +03:00
|
|
|
NS_IMETHODIMP nsSplashScreenGtk::Hide()
|
|
|
|
{
|
|
|
|
if (mDialog) {
|
|
|
|
gdk_window_destroy(mDialog);
|
|
|
|
mDialog = nsnull;
|
2000-02-13 18:23:28 +03:00
|
|
|
}
|
2000-02-14 01:24:14 +03:00
|
|
|
return NS_OK;
|
2000-02-13 18:23:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult NS_CreateSplashScreen(nsISplashScreen**aResult)
|
|
|
|
{
|
|
|
|
if ( aResult ) {
|
2000-02-14 01:24:14 +03:00
|
|
|
*aResult = new nsSplashScreenGtk;
|
|
|
|
if ( *aResult ) {
|
|
|
|
NS_ADDREF( *aResult );
|
|
|
|
return NS_OK;
|
|
|
|
} else {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
2000-02-13 18:23:28 +03:00
|
|
|
} else {
|
2000-02-14 01:24:14 +03:00
|
|
|
return NS_ERROR_NULL_POINTER;
|
2000-02-13 18:23:28 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool NS_CanRun()
|
|
|
|
{
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|