Back to index

lightning-sunbird  0.9+nobinonly
nsNativeAppSupportPh.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is Mozilla Communicator client code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either of the GNU General Public License Version 2 or later (the "GPL"),
00026  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 #include "nsNativeAppSupport.h"
00039 
00040 #define PX_IMAGE_MODULES
00041 #define PX_BMP_SUPPORT
00042 #include <photon/PxImage.h>
00043 
00044 #include <Ph.h>
00045 #include <Pt.h>
00046 
00047 class nsSplashScreenPh : public nsISplashScreen {
00048 public:
00049     nsSplashScreenPh()
00050         : mDialog( 0 ), mRefCnt( 0 ) {
00051 
00052      /* initialize widget library and attach to Photon */
00053       if( PtInit( NULL ) )
00054          exit( EXIT_FAILURE );
00055 
00056      /* increase the draw buffer */
00057       PgSetDrawBufferSize( 0x8000 );
00058     }
00059     ~nsSplashScreenPh() {
00060        Hide();
00061     }
00062 
00063     NS_IMETHOD Show();
00064     NS_IMETHOD Hide();
00065 
00066     // nsISupports methods
00067     NS_IMETHOD_(nsrefcnt) AddRef() {
00068         mRefCnt++;
00069         return mRefCnt;
00070     }
00071     NS_IMETHOD_(nsrefcnt) Release() {
00072         --mRefCnt;
00073         if ( !mRefCnt ) {
00074             delete this;
00075             return 0;
00076         }
00077         return mRefCnt;
00078     }
00079     NS_IMETHOD QueryInterface( const nsIID &iid, void**p ) {
00080         nsresult rv = NS_OK;
00081         if ( p ) {
00082             *p = 0;
00083             if ( iid.Equals( NS_GET_IID( nsISplashScreen ) ) ) {
00084                 nsISplashScreen *result = this;
00085                 *p = result;
00086                 NS_ADDREF( result );
00087             } else if ( iid.Equals( NS_GET_IID( nsISupports ) ) ) {
00088                 nsISupports *result = NS_STATIC_CAST( nsISupports*, this );
00089                 *p = result;
00090                 NS_ADDREF( result );
00091             } else {
00092                 rv = NS_NOINTERFACE;
00093             }
00094         } else {
00095             rv = NS_ERROR_NULL_POINTER;
00096         }
00097         return rv;
00098     }
00099 
00100     PtWidget_t *mDialog;
00101     nsrefcnt mRefCnt;
00102 }; // class nsSplashScreenPh
00103 
00104 
00105 NS_IMETHODIMP
00106 nsSplashScreenPh::Show()
00107 {
00108   PhImage_t  *img = nsnull;
00109   char       *p = NULL;
00110   char       *splash = NULL;
00111   char       splash_path[256];
00112   int         inp_grp,n=0;
00113   PhRid_t     rid;
00114   PhRegion_t  region;
00115   PhRect_t    rect;
00116   PRInt32     aWidth, aHeight;
00117   PhRect_t  console;
00118   struct stat sbuf;
00119 
00120    /* Get the Screen Size and Depth, so I can center the splash dialog, there has to be a better way!*/
00121         p = getenv("PHIG");
00122         if( p ) inp_grp = atoi( p );
00123         else inp_grp = 1;
00124 
00125    PhQueryRids( 0, 0, inp_grp, Ph_INPUTGROUP_REGION, 0, 0, 0, &rid, 1 );
00126    PhRegionQuery( rid, &region, &rect, NULL, 0 );
00127    inp_grp = region.input_group;
00128    PhWindowQueryVisible( Ph_QUERY_INPUT_GROUP | Ph_QUERY_EXACT, 0, inp_grp, &rect );
00129    aWidth  = rect.lr.x - rect.ul.x + 1;
00130    aHeight = rect.lr.y - rect.ul.y + 1;  
00131 
00132    /* Get the current console offset */
00133    if (PhWindowQueryVisible( Ph_QUERY_GRAPHICS, 0, inp_grp, &console ) == 0)
00134       
00135    mDialog = nsnull;   
00136        
00137    /* Setup proper path to the splash.bmp so it loads the splash screen at start up. */
00138    splash = getenv( "MOZILLA_FIVE_HOME" );
00139    if( splash )  {
00140                      sprintf( splash_path, "%s/splash.bmp", splash );
00141       if( ( img = PxLoadImage( splash_path, NULL ) ) != NULL )
00142       {
00143        PtArg_t     arg[10];
00144        PhPoint_t   pos;
00145 
00146       img->flags = img->flags | Ph_RELEASE_IMAGE_ALL;
00147 
00148       pos.x = (aWidth/2)  - (img->size.w/2);
00149       pos.y = (aHeight/2) - (img->size.h/2);
00150 
00151       pos.x += console.ul.x;
00152       pos.y += console.ul.y;
00153 
00154       PtSetArg( &arg[n++], Pt_ARG_DIM, &img->size, 0 );
00155       PtSetArg( &arg[n++], Pt_ARG_POS, &pos, 0 );
00156       PtSetArg( &arg[n++], Pt_ARG_WINDOW_RENDER_FLAGS, 0, 0xFFFFFFFF );
00157       PtSetArg( &arg[n++], Pt_ARG_FILL_COLOR, Pg_BLACK, 0 );
00158       PtSetArg( &arg[n++], Pt_ARG_WINDOW_MANAGED_FLAGS, Ph_WM_CLOSE | Ph_WM_TOFRONT | Ph_WM_TOBACK | Ph_WM_MOVE | Ph_WM_RESIZE, ~0 );
00159       mDialog = PtCreateWidget( PtWindow, NULL, n, arg );
00160 
00161       n=0;
00162       pos.x = pos.y = 0;
00163       PtSetArg( &arg[n++], Pt_ARG_POS, &pos, 0 );
00164       PtSetArg( &arg[n++], Pt_ARG_LABEL_TYPE, Pt_IMAGE, 0 );
00165       PtSetArg( &arg[n++], Pt_ARG_LABEL_DATA, img, sizeof(PhImage_t) );
00166       PtSetArg( &arg[n++], Pt_ARG_MARGIN_HEIGHT, 0, 0);
00167       PtSetArg( &arg[n++], Pt_ARG_MARGIN_WIDTH, 0, 0);
00168       PtCreateWidget( PtLabel, mDialog, n, arg );
00169       PtRealizeWidget( mDialog );
00170       PtFlush();
00171       }
00172    }
00173 #ifdef DEBUG
00174    else
00175    {
00176      fprintf( stderr, "Error loading splash screen image: %s\n", splash );
00177    }
00178 #endif
00179 
00180    return NS_OK;
00181 }
00182 
00183 NS_IMETHODIMP
00184 nsSplashScreenPh::Hide() {
00185        if ( mDialog ) {
00186         PtDestroyWidget(mDialog);
00187         mDialog = nsnull;
00188        }
00189     return NS_OK;
00190 }
00191 
00192 nsresult NS_CreateSplashScreen(nsISplashScreen**aResult)
00193 {
00194   if ( aResult ) {   
00195       *aResult = new nsSplashScreenPh;
00196       if ( *aResult ) {
00197           NS_ADDREF( *aResult );
00198           return NS_OK;
00199       } else {
00200           return NS_ERROR_OUT_OF_MEMORY;
00201       }
00202   } else {
00203       return NS_ERROR_NULL_POINTER;
00204   }
00205 }
00206 
00207 PRBool NS_CanRun() 
00208 {
00209        return PR_TRUE;
00210 }