llfloaterhtml.cpp

Go to the documentation of this file.
00001 
00032 #include "llviewerprecompiledheaders.h"
00033 
00034 #include "llfloaterhtml.h"
00035 
00036 // viewer includes
00037 #include "lluictrlfactory.h"
00038 #include "llviewercontrol.h"
00039 #include "lllineeditor.h"
00040 #include "llviewerwindow.h"
00041 #include "llweb.h"
00042 
00043 #include "llwebbrowserctrl.h"
00044 
00045 LLFloaterHtml* LLFloaterHtml::sInstance = 0;
00046 
00048 //
00049 LLFloaterHtml* LLFloaterHtml::getInstance()
00050 {
00051     if ( ! sInstance )
00052         sInstance = new LLFloaterHtml();
00053 
00054         return sInstance;
00055 }
00056 
00058 //
00059 LLFloaterHtml::LLFloaterHtml()
00060 :       LLFloater( "HTML Floater" )
00061 
00062         ,
00063         mWebBrowser( 0 )
00064 {
00065         LLUICtrlFactory::getInstance()->buildFloater( this, "floater_html.xml" );
00066 
00067         childSetAction("back_btn", onClickBack, this);
00068         childSetAction("home_btn", onClickHome, this);
00069         childSetAction("forward_btn", onClickForward, this);
00070         childSetAction("close_btn", onClickClose, this);
00071         childSetCommitCallback("url_edit", onCommitUrlEdit, this );
00072         childSetAction("go_btn", onClickGo, this );
00073 
00074         // reposition floater from saved settings
00075         LLRect rect = gSavedSettings.getRect( "FloaterHtmlRect" );
00076         reshape( rect.getWidth(), rect.getHeight(), FALSE );
00077         setRect( rect );
00078 
00079         mWebBrowser = getChild<LLWebBrowserCtrl>("html_floater_browser" );
00080         if ( mWebBrowser )
00081         {
00082                 // open links in internal browser
00083                 mWebBrowser->setOpenInExternalBrowser( false );
00084         }
00085 }
00086 
00088 //
00089 LLFloaterHtml::~LLFloaterHtml()
00090 {
00091         // save position of floater
00092         gSavedSettings.setRect( "FloaterHtmlRect", getRect() );
00093 
00094         sInstance = 0;
00095 }
00096 
00098 // virtual 
00099 void LLFloaterHtml::draw()
00100 {
00101         // enable/disable buttons depending on state
00102         if ( mWebBrowser )
00103         {
00104                 bool enable_back = mWebBrowser->canNavigateBack();      
00105                 childSetEnabled( "back_btn", enable_back );
00106 
00107                 bool enable_forward = mWebBrowser->canNavigateForward();        
00108                 childSetEnabled( "forward_btn", enable_forward );
00109         };
00110 
00111         LLFloater::draw();
00112 }
00113 
00115 //
00116 void LLFloaterHtml::show( LLString content_id, bool open_link_external, bool open_app_slurls )
00117 {
00118         // calculate the XML labels we'll need (if only XML folders worked)
00119         LLString title_str = content_id + "_title";
00120         LLString url_str = content_id + "_url";
00121 
00122         std::string title = getString( title_str );
00123         std::string url = getString( url_str );
00124 
00125         show( url, title, open_link_external, open_app_slurls );
00126 }
00127 
00129 //
00130 void LLFloaterHtml::show( std::string start_url, std::string title, bool open_link_external, bool open_app_slurls )
00131 {
00132         // set the title 
00133         setTitle( title );
00134 
00135         // navigate to the URL
00136         if ( mWebBrowser )
00137         {
00138                 mWebBrowser->setOpenAppSLURLs( open_app_slurls );
00139                 mWebBrowser->setOpenInExternalBrowser( open_link_external );
00140                 mWebBrowser->navigateTo( start_url );
00141         }
00142 
00143         // make floater appear
00144         setVisibleAndFrontmost();
00145 }
00146 
00148 //
00149 void LLFloaterHtml::onClose( bool app_quitting )
00150 {
00151         setVisible( false );
00152         // HACK for fast XML iteration replace with:
00153         // destroy();
00154 }
00155 
00157 //
00158 void LLFloaterHtml::onClickClose( void* data )
00159 {
00160         LLFloaterHtml* self = ( LLFloaterHtml* )data;
00161         self->close();
00162 }
00163 
00165 // static
00166 void LLFloaterHtml::onClickBack( void* data )
00167 {
00168         LLFloaterHtml* self = ( LLFloaterHtml* )data;
00169         if ( self )
00170         {
00171                 if ( self->mWebBrowser )
00172                 {
00173                         self->mWebBrowser->navigateBack();
00174                 };
00175         };
00176 }
00177 
00179 //
00180 void LLFloaterHtml::onClickHome( void* data )
00181 {
00182         LLFloaterHtml* self = ( LLFloaterHtml* )data;
00183         if ( self )
00184         {
00185                 if ( self->mWebBrowser )
00186                 {
00187                         std::string home_url = self->getString("home_page_url");
00188                         if ( home_url.length() > 4 )
00189                         {
00190                                 self->mWebBrowser->navigateTo( home_url );
00191                         }
00192                         else
00193                         {
00194                                 llwarns << "Invalid home page specified for HTML floater - navigating to default" << llendl;
00195                                 self->mWebBrowser->navigateTo( "http://secondlife.com" );
00196                         }
00197                 };
00198         };
00199 }
00200 
00202 // static
00203 void LLFloaterHtml::onClickForward( void* data )
00204 {
00205         LLFloaterHtml* self = ( LLFloaterHtml* )data;
00206         if ( self )
00207         {
00208                 if ( self->mWebBrowser )
00209                 {
00210                         self->mWebBrowser->navigateForward();
00211                 };
00212         };
00213 }
00214 
00216 // static
00217 void LLFloaterHtml::onCommitUrlEdit(LLUICtrl* ctrl, void* user_data)
00218 {
00219         LLFloaterHtml* self = (LLFloaterHtml*)user_data;
00220 
00221         LLLineEditor* editor = (LLLineEditor*)ctrl;
00222         std::string url = editor->getText();
00223 
00224         if ( self->mWebBrowser )
00225         {
00226                 self->mWebBrowser->navigateTo( url );
00227         };
00228 }
00229 
00231 //  static
00232 void LLFloaterHtml::onClickGo( void* data )
00233 {
00234         LLFloaterHtml* self = ( LLFloaterHtml* )data;
00235         if ( self )
00236         {
00237                 std::string url = self->childGetValue( "url_edit" ).asString();
00238                 if ( url.length() )
00239                 {
00240                         if ( self->mWebBrowser )
00241                         {
00242                                 self->mWebBrowser->navigateTo( url );
00243                         }
00244                 }
00245         }
00246 }

Generated on Fri May 16 08:33:27 2008 for SecondLife by  doxygen 1.5.5