~ubuntu-branches/ubuntu/precise/kompozer/precise

« back to all changes in this revision

Viewing changes to mozilla/xpfe/bootstrap/nsNativeAppSupportPh.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Anthony Yarusso
  • Date: 2007-08-27 01:11:03 UTC
  • Revision ID: james.westby@ubuntu.com-20070827011103-2jgf4s6532gqu2ka
Tags: upstream-0.7.10
ImportĀ upstreamĀ versionĀ 0.7.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 
2
/* ***** BEGIN LICENSE BLOCK *****
 
3
 * Version: NPL 1.1/GPL 2.0/LGPL 2.1
 
4
 *
 
5
 * The contents of this file are subject to the Netscape Public License
 
6
 * Version 1.1 (the "License"); you may not use this file except in
 
7
 * compliance with the License. You may obtain a copy of the License at
 
8
 * http://www.mozilla.org/NPL/
 
9
 *
 
10
 * Software distributed under the License is distributed on an "AS IS" basis,
 
11
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 
12
 * for the specific language governing rights and limitations under the
 
13
 * License.
 
14
 *
 
15
 * The Original Code is Mozilla Communicator client code.
 
16
 *
 
17
 * The Initial Developer of the Original Code is 
 
18
 * Netscape Communications Corporation.
 
19
 * Portions created by the Initial Developer are Copyright (C) 1998
 
20
 * the Initial Developer. All Rights Reserved.
 
21
 *
 
22
 * Contributor(s):
 
23
 *
 
24
 * Alternatively, the contents of this file may be used under the terms of
 
25
 * either the GNU General Public License Version 2 or later (the "GPL"), or 
 
26
 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 
27
 * in which case the provisions of the GPL or the LGPL are applicable instead
 
28
 * of those above. If you wish to allow use of your version of this file only
 
29
 * under the terms of either the GPL or the LGPL, and not to allow others to
 
30
 * use your version of this file under the terms of the NPL, indicate your
 
31
 * decision by deleting the provisions above and replace them with the notice
 
32
 * and other provisions required by the GPL or the LGPL. If you do not delete
 
33
 * the provisions above, a recipient may use your version of this file under
 
34
 * the terms of any one of the NPL, the GPL or the LGPL.
 
35
 *
 
36
 * ***** END LICENSE BLOCK ***** */
 
37
 
 
38
#include "nsNativeAppSupport.h"
 
39
 
 
40
#define PX_IMAGE_MODULES
 
41
#define PX_BMP_SUPPORT
 
42
#include <photon/PxImage.h>
 
43
 
 
44
#include <Ph.h>
 
45
#include <Pt.h>
 
46
 
 
47
class nsSplashScreenPh : public nsISplashScreen {
 
48
public:
 
49
    nsSplashScreenPh()
 
50
        : mDialog( 0 ), mRefCnt( 0 ) {
 
51
 
 
52
     /* initialize widget library and attach to Photon */
 
53
      if( PtInit( NULL ) )
 
54
         exit( EXIT_FAILURE );
 
55
 
 
56
     /* increase the draw buffer */
 
57
      PgSetDrawBufferSize( 0x8000 );
 
58
    }
 
59
    ~nsSplashScreenPh() {
 
60
       Hide();
 
61
    }
 
62
 
 
63
    NS_IMETHOD Show();
 
64
    NS_IMETHOD Hide();
 
65
 
 
66
    // nsISupports methods
 
67
    NS_IMETHOD_(nsrefcnt) AddRef() {
 
68
        mRefCnt++;
 
69
        return mRefCnt;
 
70
    }
 
71
    NS_IMETHOD_(nsrefcnt) Release() {
 
72
        --mRefCnt;
 
73
        if ( !mRefCnt ) {
 
74
            delete this;
 
75
            return 0;
 
76
        }
 
77
        return mRefCnt;
 
78
    }
 
79
    NS_IMETHOD QueryInterface( const nsIID &iid, void**p ) {
 
80
        nsresult rv = NS_OK;
 
81
        if ( p ) {
 
82
            *p = 0;
 
83
            if ( iid.Equals( NS_GET_IID( nsISplashScreen ) ) ) {
 
84
                nsISplashScreen *result = this;
 
85
                *p = result;
 
86
                NS_ADDREF( result );
 
87
            } else if ( iid.Equals( NS_GET_IID( nsISupports ) ) ) {
 
88
                nsISupports *result = NS_STATIC_CAST( nsISupports*, this );
 
89
                *p = result;
 
90
                NS_ADDREF( result );
 
91
            } else {
 
92
                rv = NS_NOINTERFACE;
 
93
            }
 
94
        } else {
 
95
            rv = NS_ERROR_NULL_POINTER;
 
96
        }
 
97
        return rv;
 
98
    }
 
99
 
 
100
    PtWidget_t *mDialog;
 
101
    nsrefcnt mRefCnt;
 
102
}; // class nsSplashScreenPh
 
103
 
 
104
 
 
105
NS_IMETHODIMP
 
106
nsSplashScreenPh::Show()
 
107
{
 
108
  PhImage_t  *img = nsnull;
 
109
  char       *p = NULL;
 
110
  char       *splash = NULL;
 
111
  char       splash_path[256];
 
112
  int         inp_grp,n=0;
 
113
  PhRid_t     rid;
 
114
  PhRegion_t  region;
 
115
  PhRect_t    rect;
 
116
  PRInt32     aWidth, aHeight;
 
117
  PhRect_t  console;
 
118
  struct stat sbuf;
 
119
 
 
120
   /* Get the Screen Size and Depth, so I can center the splash dialog, there has to be a better way!*/
 
121
         p = getenv("PHIG");
 
122
         if( p ) inp_grp = atoi( p );
 
123
         else inp_grp = 1;
 
124
 
 
125
   PhQueryRids( 0, 0, inp_grp, Ph_INPUTGROUP_REGION, 0, 0, 0, &rid, 1 );
 
126
   PhRegionQuery( rid, &region, &rect, NULL, 0 );
 
127
   inp_grp = region.input_group;
 
128
   PhWindowQueryVisible( Ph_QUERY_INPUT_GROUP | Ph_QUERY_EXACT, 0, inp_grp, &rect );
 
129
   aWidth  = rect.lr.x - rect.ul.x + 1;
 
130
   aHeight = rect.lr.y - rect.ul.y + 1;  
 
131
 
 
132
   /* Get the current console offset */
 
133
   if (PhWindowQueryVisible( Ph_QUERY_GRAPHICS, 0, inp_grp, &console ) == 0)
 
134
      
 
135
   mDialog = nsnull;   
 
136
        
 
137
   /* Setup proper path to the splash.bmp so it loads the splash screen at start up. */
 
138
   splash = getenv( "MOZILLA_FIVE_HOME" );
 
139
   if( splash )  {
 
140
                        sprintf( splash_path, "%s/splash.bmp", splash );
 
141
      if( ( img = PxLoadImage( splash_path, NULL ) ) != NULL )
 
142
      {
 
143
       PtArg_t     arg[10];
 
144
       PhPoint_t   pos;
 
145
 
 
146
      img->flags = img->flags | Ph_RELEASE_IMAGE_ALL;
 
147
 
 
148
      pos.x = (aWidth/2)  - (img->size.w/2);
 
149
      pos.y = (aHeight/2) - (img->size.h/2);
 
150
 
 
151
      pos.x += console.ul.x;
 
152
      pos.y += console.ul.y;
 
153
 
 
154
      PtSetArg( &arg[n++], Pt_ARG_DIM, &img->size, 0 );
 
155
      PtSetArg( &arg[n++], Pt_ARG_POS, &pos, 0 );
 
156
      PtSetArg( &arg[n++], Pt_ARG_WINDOW_RENDER_FLAGS, 0, 0xFFFFFFFF );
 
157
      PtSetArg( &arg[n++], Pt_ARG_FILL_COLOR, Pg_BLACK, 0 );
 
158
      PtSetArg( &arg[n++], Pt_ARG_WINDOW_MANAGED_FLAGS, Ph_WM_CLOSE | Ph_WM_TOFRONT | Ph_WM_TOBACK | Ph_WM_MOVE | Ph_WM_RESIZE, ~0 );
 
159
      mDialog = PtCreateWidget( PtWindow, NULL, n, arg );
 
160
 
 
161
      n=0;
 
162
      pos.x = pos.y = 0;
 
163
      PtSetArg( &arg[n++], Pt_ARG_POS, &pos, 0 );
 
164
      PtSetArg( &arg[n++], Pt_ARG_LABEL_TYPE, Pt_IMAGE, 0 );
 
165
      PtSetArg( &arg[n++], Pt_ARG_LABEL_DATA, img, sizeof(PhImage_t) );
 
166
      PtSetArg( &arg[n++], Pt_ARG_MARGIN_HEIGHT, 0, 0);
 
167
      PtSetArg( &arg[n++], Pt_ARG_MARGIN_WIDTH, 0, 0);
 
168
      PtCreateWidget( PtLabel, mDialog, n, arg );
 
169
      PtRealizeWidget( mDialog );
 
170
      PtFlush();
 
171
      }
 
172
   }
 
173
   else
 
174
   {
 
175
     fprintf( stderr, "Error loading splash screen image: %s\n", splash );
 
176
   }
 
177
 
 
178
   return NS_OK;
 
179
}
 
180
 
 
181
NS_IMETHODIMP
 
182
nsSplashScreenPh::Hide() {
 
183
        if ( mDialog ) {
 
184
        PtDestroyWidget(mDialog);
 
185
        mDialog = nsnull;
 
186
        }
 
187
    return NS_OK;
 
188
}
 
189
 
 
190
nsresult NS_CreateSplashScreen(nsISplashScreen**aResult)
 
191
{
 
192
  if ( aResult ) {      
 
193
      *aResult = new nsSplashScreenPh;
 
194
      if ( *aResult ) {
 
195
          NS_ADDREF( *aResult );
 
196
          return NS_OK;
 
197
      } else {
 
198
          return NS_ERROR_OUT_OF_MEMORY;
 
199
      }
 
200
  } else {
 
201
      return NS_ERROR_NULL_POINTER;
 
202
  }
 
203
}
 
204
 
 
205
PRBool NS_CanRun() 
 
206
{
 
207
        return PR_TRUE;
 
208
}