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
00045 LLUploadDialog* LLUploadDialog::sDialog = NULL;
00046
00047
00048 LLUploadDialog* LLUploadDialog::modalUploadDialog(const std::string& msg)
00049 {
00050
00051 return new LLUploadDialog(msg);
00052 }
00053
00054
00055 void LLUploadDialog::modalUploadFinished()
00056 {
00057
00058 delete LLUploadDialog::sDialog;
00059 LLUploadDialog::sDialog = NULL;
00060 }
00061
00063
00064
00065 LLUploadDialog::LLUploadDialog( const std::string& msg)
00066 :
00067 LLPanel( "Uploading...", LLRect(0,100,100,0) )
00068 {
00069 setBackgroundVisible( TRUE );
00070
00071 if( LLUploadDialog::sDialog )
00072 {
00073 delete LLUploadDialog::sDialog;
00074 }
00075 LLUploadDialog::sDialog = this;
00076
00077 const LLFontGL* font = LLResMgr::getInstance()->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, "Filename", font );
00082 addChild(mLabelBox[line_num]);
00083 }
00084
00085 setMessage(msg);
00086
00087
00088 gViewerWindow->setTopCtrl( this );
00089 }
00090
00091 void LLUploadDialog::setMessage( const std::string& msg)
00092 {
00093 const LLFontGL* font = LLResMgr::getInstance()->getRes( LLFONT_SANSSERIF );
00094
00095 const S32 VPAD = 16;
00096 const S32 HPAD = 25;
00097
00098
00099 const S32 TEXT_PAD = 8;
00100
00101
00102 S32 max_msg_width = 0;
00103 std::list<std::string> msg_lines;
00104
00105 S32 size = msg.size() + 1;
00106 char* temp_msg = new char[size];
00107
00108
00109 if (temp_msg == NULL)
00110 {
00111 llerrs << "Memory Allocation Failed" << llendl;
00112 return;
00113 }
00114
00115 strcpy( temp_msg, msg.c_str());
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.push_back( std::string( 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.size() + 2 * VPAD;
00130
00131 reshape( dialog_width, dialog_height, FALSE );
00132
00133
00134 S32 msg_x = (getRect().getWidth() - max_msg_width) / 2;
00135 S32 msg_y = getRect().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 (std::list<std::string>::iterator iter = msg_lines.begin();
00143 iter != msg_lines.end(); ++iter)
00144 {
00145 std::string& cur_line = *iter;
00146 LLRect msg_rect;
00147 msg_rect.setOriginAndSize( msg_x, msg_y, max_msg_width, line_height );
00148 mLabelBox[line_num]->setRect(msg_rect);
00149 mLabelBox[line_num]->setText(cur_line);
00150 mLabelBox[line_num]->setColor( gColors.getColor( "LabelTextColor" ) );
00151 mLabelBox[line_num]->setVisible(TRUE);
00152 msg_y -= line_height;
00153 ++line_num;
00154 }
00155
00156 centerWithin(gViewerWindow->getRootView()->getRect());
00157 }
00158
00159 LLUploadDialog::~LLUploadDialog()
00160 {
00161 gFocusMgr.releaseFocusIfNeeded( this );
00162
00163
00164
00165
00166 LLUploadDialog::sDialog = NULL;
00167 }
00168
00169
00170