llfloaterhtmlhelp.cpp

Go to the documentation of this file.
00001 
00032 #include "llviewerprecompiledheaders.h"
00033 
00034 #include "llfloaterhtmlhelp.h"
00035 
00036 #include "llvieweruictrlfactory.h"
00037 #include "llwebbrowserctrl.h"
00038 #include "llviewerwindow.h"
00039 #include "llviewercontrol.h"
00040 #include "llweb.h"
00041 #include "llui.h"
00042 
00043 #if LL_LIBXUL_ENABLED
00044 
00045 LLViewerHtmlHelp gViewerHtmlHelp;
00046 
00047 class LLFloaterHtmlHelp :
00048         public LLFloater,
00049         public LLWebBrowserCtrlObserver
00050 {
00051 public:
00052         LLFloaterHtmlHelp(std::string start_url, std::string title);
00053         virtual ~LLFloaterHtmlHelp();
00054         
00055         virtual void onClose( bool app_quitting );
00056         virtual void draw();
00057         
00058         static void show(std::string url, std::string title);
00059         static void onClickBack( void* data );
00060         static void onClickHome( void* data );
00061         static void onClickForward( void* data );
00062         static void onClickClose( void* data );
00063         
00064         // browser observer impls
00065         virtual void onStatusTextChange( const EventType& eventIn );
00066         virtual void onLocationChange( const EventType& eventIn );
00067         
00068         // used for some stats logging - will be removed at some point
00069         static BOOL sFloaterOpened;
00070 
00071         static void onClickF1HelpLoadURL(S32 option, void* userdata);
00072 
00073 protected:
00074         LLWebBrowserCtrl* mWebBrowser;
00075         static LLFloaterHtmlHelp* sInstance;
00076         LLButton* mBackButton;
00077         LLButton* mForwardButton;
00078         LLButton* mCloseButton;
00079         LLTextBox* mStatusText;
00080         LLString mStatusTextContents;
00081         LLString mCurrentUrl;
00082 };
00083 
00084 LLFloaterHtmlHelp* LLFloaterHtmlHelp::sInstance = 0;
00085 
00086 BOOL LLFloaterHtmlHelp::sFloaterOpened = FALSE;
00087 
00089 //
00090 LLFloaterHtmlHelp::LLFloaterHtmlHelp(std::string start_url, std::string title)
00091 :       LLFloater( "HTML Help" ),
00092         mWebBrowser( 0 ),
00093         mStatusTextContents( "" ),
00094         mCurrentUrl( "" )
00095 {
00096         sInstance = this;
00097                 
00098         // create floater from its XML definition
00099         gUICtrlFactory->buildFloater( this, "floater_html_help.xml" );
00100                 
00101         childSetAction("back_btn", onClickBack, this);
00102         childSetAction("home_btn", onClickHome, this);
00103         childSetAction("forward_btn", onClickForward, this);
00104         
00105         if (!title.empty())
00106         {
00107                 setTitle(title);
00108         }
00109 
00110         mWebBrowser = LLViewerUICtrlFactory::getWebBrowserByName(this,  "html_help_browser" );
00111         if ( mWebBrowser )
00112         {
00113                 // observe browser control events
00114                 mWebBrowser->addObserver( this );
00115 
00116                 if (start_url != "")
00117                 {
00118                         mWebBrowser->navigateTo( start_url );
00119                 }
00120                 else
00121                 {
00122                         // if the last page we were at before the client was closed is valid, go there and
00123                         // override what is in the XML file
00124                         // (not when the window was closed - it's only ever hidden - not closed)
00125                         LLString lastPageUrl = gSavedSettings.getString( "HtmlHelpLastPage" );
00126                         if ( lastPageUrl != "" )
00127                         {
00128                                 mWebBrowser->navigateTo( lastPageUrl );
00129                         };
00130                 }
00131         };
00132 }
00133 
00135 //
00136 LLFloaterHtmlHelp::~LLFloaterHtmlHelp()
00137 {
00138         // stop observing browser events
00139         if ( mWebBrowser )
00140         {
00141                 mWebBrowser->remObserver( this );
00142         };
00143 
00144         // save position of floater
00145         gSavedSettings.setRect( "HtmlHelpRect", mRect );
00146 
00147         // save the location we were at when SL closed 
00148         gSavedSettings.setString( "HtmlHelpLastPage", mCurrentUrl );
00149 
00150         sInstance = 0;
00151 }
00152 
00154 // virtual 
00155 void LLFloaterHtmlHelp::draw()
00156 {
00157         // enable/disable buttons depending on state
00158         if ( mWebBrowser )
00159         {
00160                 bool enable_back = mWebBrowser->canNavigateBack();      
00161                 childSetEnabled( "back_btn", enable_back );
00162 
00163                 bool enable_forward = mWebBrowser->canNavigateForward();        
00164                 childSetEnabled( "forward_btn", enable_forward );
00165         };
00166 
00167         LLFloater::draw();
00168 }
00169 
00171 //
00172 void LLFloaterHtmlHelp::show(std::string url, std::string title)
00173 {
00174     gViewerWindow->alertXml("ClickOpenF1Help", onClickF1HelpLoadURL, (void*) NULL);
00175 
00176         // switching this out for the moment - will come back later
00177         // want it still to be compiled so not using comments of #if 0
00178         if ( false )
00179         {
00180                 sFloaterOpened = true;
00181 
00182                 if ( sInstance )
00183                 {
00184                         if (sInstance->mWebBrowser)
00185                         {
00186                                 sInstance->mWebBrowser->navigateTo(url);
00187                         }
00188                         sInstance->setVisibleAndFrontmost();
00189                         return;
00190                 }
00191 
00192                 LLFloaterHtmlHelp* self = new LLFloaterHtmlHelp(url, title);
00193 
00194                 // reposition floater from saved settings
00195                 LLRect rect = gSavedSettings.getRect( "HtmlHelpRect" );
00196                 self->reshape( rect.getWidth(), rect.getHeight(), FALSE );
00197                 self->setRect( rect );
00198         };
00199 }
00200 
00201 // static 
00202 void LLFloaterHtmlHelp::onClickF1HelpLoadURL(S32 option, void* userdata)
00203 {
00204         if (option == 0)
00205         {
00206                 // choose HELP url based on selected language - default to english language support page
00207                 LLString lang = LLUI::sConfigGroup->getString("Language");
00208 
00209                 // this sucks but there isn't a way to grab an arbitrary string from an XML file
00210                 // (using llcontroldef strings causes problems if string don't exist)
00211                 LLString help_url( "http://secondlife.com/support" );
00212                 if ( lang == "ja" )
00213                         help_url = "http://help.secondlife.com/jp";
00214                 else
00215                 if ( lang == "ko" )
00216                         help_url = "http://help.secondlife.com/kr";
00217                 else
00218                 if ( lang == "pt" )
00219                         help_url = "http://help.secondlife.com/pt";
00220                 else
00221                 if ( lang == "de" )
00222                         help_url = "http://de.secondlife.com/support";
00223 
00224                 LLWeb::loadURL( help_url );
00225         };
00226 }
00227 
00229 //
00230 void LLFloaterHtmlHelp::onClose( bool app_quitting )
00231 {
00232         setVisible( false );
00233 }
00234 
00236 //
00237 void LLFloaterHtmlHelp::onClickClose( void* data )
00238 {
00239         LLFloaterHtmlHelp* self = ( LLFloaterHtmlHelp* )data;
00240 
00241         self->setVisible( false );
00242 }
00243 
00245 //
00246 void LLFloaterHtmlHelp::onClickBack( void* data )
00247 {
00248         LLFloaterHtmlHelp* self = ( LLFloaterHtmlHelp* )data;
00249         if ( self )
00250         {
00251                 if ( self->mWebBrowser )
00252                 {
00253                         self->mWebBrowser->navigateBack();
00254                 };
00255         };
00256 }
00257 
00259 //
00260 void LLFloaterHtmlHelp::onClickHome( void* data )
00261 {
00262         LLFloaterHtmlHelp* self = ( LLFloaterHtmlHelp* )data;
00263         if ( self )
00264         {
00265                 // get the home page URL (which can differ from the start URL) from XML and go there
00266                 LLWebBrowserCtrl* web_browser = LLUICtrlFactory::getWebBrowserCtrlByName( self, "html_help_browser" );
00267                 if ( web_browser )
00268                 {
00269                         web_browser->navigateHome();
00270                 };
00271         };
00272 }
00273 
00275 // 
00276 void LLFloaterHtmlHelp::onClickForward( void* data )
00277 {
00278         LLFloaterHtmlHelp* self = ( LLFloaterHtmlHelp* )data;
00279         if ( self )
00280         {
00281                 if ( self->mWebBrowser )
00282                 {
00283                         self->mWebBrowser->navigateForward();
00284                 };
00285         };
00286 }
00287 
00289 //
00290 void LLFloaterHtmlHelp::onStatusTextChange( const EventType& eventIn )
00291 {
00292         mStatusTextContents = LLString( eventIn.getStringValue() );
00293 
00294         childSetText("status_text", mStatusTextContents);
00295 }
00296 
00298 //
00299 void LLFloaterHtmlHelp::onLocationChange( const EventType& eventIn )
00300 {
00301         llinfos << "MOZ> Location changed to " << eventIn.getStringValue() << llendl;
00302         mCurrentUrl = LLString( eventIn.getStringValue() );
00303 }
00304 
00306 //
00307 LLViewerHtmlHelp::LLViewerHtmlHelp()
00308 {
00309         LLUI::setHtmlHelp(this);
00310 }
00311 
00312 LLViewerHtmlHelp::~LLViewerHtmlHelp()
00313 {
00314         LLUI::setHtmlHelp(NULL);
00315 }
00316 
00317 void LLViewerHtmlHelp::show(std::string url, std::string title)
00318 {
00319         LLFloaterHtmlHelp::show(url, title);
00320 }
00321 
00322 BOOL LLViewerHtmlHelp::getFloaterOpened()
00323 {
00324         return LLFloaterHtmlHelp::sFloaterOpened;
00325 }
00326 
00327 #endif  // LL_LIBXUL_ENABLED
00328 

Generated on Thu Jul 1 06:08:34 2010 for Second Life Viewer by  doxygen 1.4.7