lluploaddialog.cpp

Go to the documentation of this file.
00001 
00032 #include "llviewerprecompiledheaders.h"
00033 
00034 #include "lluploaddialog.h"
00035 #include "llviewerwindow.h"
00036 #include "llfontgl.h"
00037 #include "llresmgr.h"
00038 #include "lltextbox.h"
00039 #include "llbutton.h"
00040 #include "llkeyboard.h"
00041 #include "llfocusmgr.h"
00042 #include "llviewercontrol.h"
00043 
00044 // static
00045 LLUploadDialog* LLUploadDialog::sDialog = NULL;
00046 
00047 // static
00048 LLUploadDialog* LLUploadDialog::modalUploadDialog(const std::string& msg)
00049 {
00050         // Note: object adds, removes, and destroys itself.
00051         return new LLUploadDialog(msg);
00052 }
00053 
00054 // static
00055 void LLUploadDialog::modalUploadFinished()
00056 {
00057         // Note: object adds, removes, and destroys itself.
00058         delete LLUploadDialog::sDialog;
00059         LLUploadDialog::sDialog = NULL;
00060 }
00061 
00063 // Private methods
00064 
00065 LLUploadDialog::LLUploadDialog( const std::string& msg)
00066         :
00067         LLPanel( "Uploading...", LLRect(0,100,100,0) )  // dummy rect.  Will reshape below.
00068 {
00069         setBackgroundVisible( TRUE );
00070 
00071         if( LLUploadDialog::sDialog )
00072         {
00073                 delete LLUploadDialog::sDialog;
00074         }
00075         LLUploadDialog::sDialog = this;
00076 
00077         const LLFontGL* font = gResMgr->getRes( LLFONT_SANSSERIF );
00078         LLRect msg_rect;
00079         for (int line_num=0; line_num<16; ++line_num)
00080         {
00081                 mLabelBox[line_num] = new LLTextBox( "Filename", msg_rect, "", font );
00082                 addChild(mLabelBox[line_num]);
00083         }
00084 
00085         setMessage(msg);
00086 
00087         // The dialog view is a root view
00088         gViewerWindow->setTopCtrl( this );
00089 }
00090 
00091 void LLUploadDialog::setMessage( const std::string& msg)
00092 {
00093         const LLFontGL* font = gResMgr->getRes( LLFONT_SANSSERIF );
00094 
00095         const S32 VPAD = 16;
00096         const S32 HPAD = 25;
00097 
00098         // Make the text boxes a little wider than the text
00099         const S32 TEXT_PAD = 8;
00100 
00101         // Split message into lines, separated by '\n'
00102         S32 max_msg_width = 0;
00103         LLDoubleLinkedList<LLString> msg_lines;
00104 
00105         S32 size = msg.size() + 1;// + strlen("Uploading...\n\n");
00106         char* temp_msg = new char[size];
00107         
00108         //strcpy(temp_msg,"Uploading...\n\n");
00109         if (temp_msg == NULL)
00110         {
00111                 llerrs << "Memory Allocation Failed" << llendl;
00112                 return;
00113         }
00114         
00115         strcpy( temp_msg, msg.c_str());         /* Flawfinder: ignore */
00116         char* token = strtok( temp_msg, "\n" );
00117         while( token )
00118         {
00119                 S32 cur_width = S32(font->getWidth(token) + 0.99f) + TEXT_PAD;
00120                 max_msg_width = llmax( max_msg_width, cur_width );
00121                 msg_lines.addDataAtEnd( new LLString( token ) );
00122                 token = strtok( NULL, "\n" );
00123         }
00124         delete[] temp_msg;
00125 
00126 
00127         S32 line_height = S32( font->getLineHeight() + 0.99f );
00128         S32 dialog_width = max_msg_width + 2 * HPAD;
00129         S32 dialog_height = line_height * msg_lines.getLength() + 2 * VPAD;
00130 
00131         reshape( dialog_width, dialog_height, FALSE );
00132 
00133         // Message
00134         S32 msg_x = (mRect.getWidth() - max_msg_width) / 2;
00135         S32 msg_y = mRect.getHeight() - VPAD - line_height;
00136         int line_num;
00137         for (line_num=0; line_num<16; ++line_num)
00138         {
00139                 mLabelBox[line_num]->setVisible(FALSE);
00140         }
00141         line_num = 0;
00142         for( LLString* cur_line = msg_lines.getFirstData(); cur_line; cur_line = msg_lines.getNextData() )
00143         {
00144                 LLRect msg_rect;
00145                 msg_rect.setOriginAndSize( msg_x, msg_y, max_msg_width, line_height );
00146                 mLabelBox[line_num]->setRect(msg_rect);
00147                 mLabelBox[line_num]->setText(*cur_line);
00148                 mLabelBox[line_num]->setColor( gColors.getColor( "LabelTextColor" ) );
00149                 mLabelBox[line_num]->setVisible(TRUE);
00150                 msg_y -= line_height;
00151                 ++line_num;
00152         }
00153         msg_lines.deleteAllData();
00154 
00155         centerDialog();
00156 }
00157 
00158 LLUploadDialog::~LLUploadDialog()
00159 {
00160         gFocusMgr.releaseFocusIfNeeded( this );
00161 
00162 //    LLFilePicker::instance().reset();
00163 
00164 
00165         LLUploadDialog::sDialog = NULL;
00166 }
00167 
00168 void LLUploadDialog::centerDialog()
00169 {
00170         LLRect window_rect = gViewerWindow->getRootView()->getRect();
00171 
00172         S32 dialog_left = window_rect.mLeft + (window_rect.getWidth() - mRect.getWidth()) / 2;
00173         S32 dialog_bottom = window_rect.mBottom + (window_rect.getHeight() - mRect.getHeight()) / 2;
00174 
00175         translate( dialog_left - mRect.mLeft, dialog_bottom - mRect.mBottom );
00176 }
00177 

Generated on Thu Jul 1 06:09:24 2010 for Second Life Viewer by  doxygen 1.4.7