Back to index

lightning-sunbird  0.9+nobinonly
nsNativeAppSupportGtk.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
00002  *
00003  * ***** BEGIN LICENSE BLOCK *****
00004  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00005  *
00006  * The contents of this file are subject to the Mozilla Public License Version
00007  * 1.1 (the "License"); you may not use this file except in compliance with
00008  * the License. You may obtain a copy of the License at
00009  * http://www.mozilla.org/MPL/
00010  *
00011  * Software distributed under the License is distributed on an "AS IS" basis,
00012  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00013  * for the specific language governing rights and limitations under the
00014  * License.
00015  *
00016  * The Original Code is the Mozilla browser.
00017  *
00018  * The Initial Developer of the Original Code is
00019  * Netscape Communications Corporation.
00020  * Portions created by the Initial Developer are Copyright (C) 1999
00021  * the Initial Developer. All Rights Reserved.
00022  *
00023  * Contributor(s):
00024  *   syd@netscape.com 2/12/00.
00025  *   pavlov@netscape.com 2/13/00.
00026  *   bryner@brianryner.com 11/20/01.
00027  *
00028  * Alternatively, the contents of this file may be used under the terms of
00029  * either of the GNU General Public License Version 2 or later (the "GPL"),
00030  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00031  * in which case the provisions of the GPL or the LGPL are applicable instead
00032  * of those above. If you wish to allow use of your version of this file only
00033  * under the terms of either the GPL or the LGPL, and not to allow others to
00034  * use your version of this file under the terms of the MPL, indicate your
00035  * decision by deleting the provisions above and replace them with the notice
00036  * and other provisions required by the GPL or the LGPL. If you do not delete
00037  * the provisions above, a recipient may use your version of this file under
00038  * the terms of any one of the MPL, the GPL or the LGPL.
00039  *
00040  * ***** END LICENSE BLOCK ***** */
00041 
00042 #include "nsStringSupport.h"
00043 
00044 #include "nsNativeAppSupportBase.h"
00045 #include "gdk/gdk.h"
00046 #include "prenv.h"
00047 #ifdef MOZ_XUL_APP
00048 extern char* splash_xpm[];
00049 #else
00050 #include SPLASH_XPM
00051 #endif
00052 
00053 class nsSplashScreenGtk : public nsISplashScreen {
00054 public:
00055   nsSplashScreenGtk();
00056   virtual ~nsSplashScreenGtk();
00057 
00058   NS_IMETHOD Show();
00059   NS_IMETHOD Hide();
00060 
00061   NS_DECL_ISUPPORTS
00062 
00063 private:
00064   GdkWindow *mDialog;
00065 }; // class nsSplashScreenGtk
00066 
00067 class nsNativeAppSupportGtk : public nsNativeAppSupportBase {
00068   // We don't have any methods to override.
00069 };
00070 
00071 NS_IMPL_ISUPPORTS1(nsSplashScreenGtk, nsISplashScreen)
00072 
00073 nsSplashScreenGtk::nsSplashScreenGtk()
00074 {
00075 }
00076 
00077 nsSplashScreenGtk::~nsSplashScreenGtk()
00078 {
00079   Hide();
00080 }
00081 
00082 NS_IMETHODIMP nsSplashScreenGtk::Show()
00083 {
00084 #ifdef MOZ_XUL_APP
00085   if (!splash_xpm[0])
00086     return NS_OK;
00087 #endif
00088 
00089   nsCAutoString path(PR_GetEnv("MOZILLA_FIVE_HOME"));
00090 
00091   if (path.IsEmpty()) {
00092     path.Assign("splash.xpm");
00093   } else {
00094     path.Append("/splash.xpm");
00095   }
00096 
00097   /* See if the user has a custom splash screen */
00098   GdkPixmap* pmap = gdk_pixmap_colormap_create_from_xpm(NULL,
00099                                                     gdk_colormap_get_system(),
00100                                                     NULL, NULL, path.get());
00101 
00102   if (!pmap) {
00103     /* create a pixmap based on xpm data */
00104     pmap = gdk_pixmap_colormap_create_from_xpm_d(NULL,
00105                                                     gdk_colormap_get_system(),
00106                                                     NULL, NULL, splash_xpm);
00107   }
00108 
00109   if (!pmap) {
00110     gdk_window_destroy(mDialog);
00111     mDialog = nsnull;
00112     return NS_ERROR_FAILURE;
00113   }
00114 
00115   gint width, height;
00116   gdk_window_get_size(pmap, &width, &height);
00117 
00118   GdkWindowAttr attr;
00119   attr.window_type = GDK_WINDOW_TEMP;
00120   attr.wclass = GDK_INPUT_OUTPUT;
00121   attr.x = (gdk_screen_width() >> 1) - (width >> 1);
00122   attr.y = (gdk_screen_height() >> 1) - (height >> 1);
00123   attr.width = width;
00124   attr.height = height;
00125   attr.event_mask = GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK;
00126   mDialog = gdk_window_new(NULL, &attr, GDK_WA_X | GDK_WA_Y);
00127 
00128   gdk_window_set_back_pixmap(mDialog, pmap, FALSE);
00129   gdk_pixmap_unref(pmap);
00130 
00131   gdk_window_show(mDialog);
00132 
00133   return NS_OK;
00134 }
00135 
00136 NS_IMETHODIMP nsSplashScreenGtk::Hide()
00137 {
00138   if (mDialog) {
00139     gdk_window_destroy(mDialog);
00140     mDialog = nsnull;
00141   }
00142   return NS_OK;
00143 }
00144 
00145 nsresult NS_CreateNativeAppSupport(nsINativeAppSupport** aNativeApp) {
00146   *aNativeApp = new nsNativeAppSupportGtk;
00147   NS_ADDREF(*aNativeApp);
00148   return NS_OK;
00149 }
00150 
00151 nsresult NS_CreateSplashScreen(nsISplashScreen** aSplash) {
00152   *aSplash = new nsSplashScreenGtk;
00153   NS_ADDREF(*aSplash);
00154   return NS_OK;
00155 }
00156 
00157 PRBool NS_CanRun()
00158 {
00159   return PR_TRUE;
00160 }