Annotation of /trunk/linden/indra/newview/lluploaddialog.cpp
Parent Directory
|
Revision Log
Revision 61 - (view) (download)
| 1 : | mjm | 57 | /** |
| 2 : | * @file lluploaddialog.cpp | ||
| 3 : | * @brief LLUploadDialog class implementation | ||
| 4 : | * | ||
| 5 : | * $LicenseInfo:firstyear=2001&license=viewergpl$ | ||
| 6 : | * | ||
| 7 : | * Copyright (c) 2001-2008, Linden Research, Inc. | ||
| 8 : | * | ||
| 9 : | * Second Life Viewer Source Code | ||
| 10 : | * The source code in this file ("Source Code") is provided by Linden Lab | ||
| 11 : | * to you under the terms of the GNU General Public License, version 2.0 | ||
| 12 : | * ("GPL"), unless you have obtained a separate licensing agreement | ||
| 13 : | * ("Other License"), formally executed by you and Linden Lab. Terms of | ||
| 14 : | * the GPL can be found in doc/GPL-license.txt in this distribution, or | ||
| 15 : | * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2 | ||
| 16 : | * | ||
| 17 : | * There are special exceptions to the terms and conditions of the GPL as | ||
| 18 : | * it is applied to this Source Code. View the full text of the exception | ||
| 19 : | * in the file doc/FLOSS-exception.txt in this software distribution, or | ||
| 20 : | * online at http://secondlifegrid.net/programs/open_source/licensing/flossexception | ||
| 21 : | * | ||
| 22 : | * By copying, modifying or distributing this software, you acknowledge | ||
| 23 : | * that you have read and understood your obligations described above, | ||
| 24 : | * and agree to abide by those obligations. | ||
| 25 : | * | ||
| 26 : | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | ||
| 27 : | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
| 28 : | * COMPLETENESS OR PERFORMANCE. | ||
| 29 : | * $/LicenseInfo$ | ||
| 30 : | */ | ||
| 31 : | |||
| 32 : | #include "llviewerprecompiledheaders.h" | ||
| 33 : | |||
| 34 : | #include "lluploaddialog.h" | ||
| 35 : | #include "llviewerwindow.h" | ||
| 36 : | #include "llfontgl.h" | ||
| 37 : | #include "llresmgr.h" | ||
| 38 : | #include "lltextbox.h" | ||
| 39 : | #include "llbutton.h" | ||
| 40 : | #include "llkeyboard.h" | ||
| 41 : | #include "llfocusmgr.h" | ||
| 42 : | #include "llviewercontrol.h" | ||
| 43 : | |||
| 44 : | // static | ||
| 45 : | LLUploadDialog* LLUploadDialog::sDialog = NULL; | ||
| 46 : | |||
| 47 : | // static | ||
| 48 : | LLUploadDialog* LLUploadDialog::modalUploadDialog(const std::string& msg) | ||
| 49 : | { | ||
| 50 : | // Note: object adds, removes, and destroys itself. | ||
| 51 : | return new LLUploadDialog(msg); | ||
| 52 : | } | ||
| 53 : | |||
| 54 : | // static | ||
| 55 : | void LLUploadDialog::modalUploadFinished() | ||
| 56 : | { | ||
| 57 : | // Note: object adds, removes, and destroys itself. | ||
| 58 : | delete LLUploadDialog::sDialog; | ||
| 59 : | LLUploadDialog::sDialog = NULL; | ||
| 60 : | } | ||
| 61 : | |||
| 62 : | //////////////////////////////////////////////////////////// | ||
| 63 : | // Private methods | ||
| 64 : | |||
| 65 : | LLUploadDialog::LLUploadDialog( const std::string& msg) | ||
| 66 : | : | ||
| 67 : | LLPanel( std::string("Uploading..."), LLRect(0,100,100,0) ) // dummy rect. Will reshape below. | ||
| 68 : | { | ||
| 69 : | setBackgroundVisible( TRUE ); | ||
| 70 : | |||
| 71 : | if( LLUploadDialog::sDialog ) | ||
| 72 : | { | ||
| 73 : | delete LLUploadDialog::sDialog; | ||
| 74 : | } | ||
| 75 : | LLUploadDialog::sDialog = this; | ||
| 76 : | |||
| 77 : | const LLFontGL* font = LLResMgr::getInstance()->getRes( LLFONT_SANSSERIF ); | ||
| 78 : | LLRect msg_rect; | ||
| 79 : | for (int line_num=0; line_num<16; ++line_num) | ||
| 80 : | { | ||
| 81 : | mLabelBox[line_num] = new LLTextBox( std::string("Filename"), msg_rect, std::string("Filename"), font ); | ||
| 82 : | addChild(mLabelBox[line_num]); | ||
| 83 : | } | ||
| 84 : | |||
| 85 : | setMessage(msg); | ||
| 86 : | |||
| 87 : | // The dialog view is a root view | ||
| 88 : | gFocusMgr.setTopCtrl( this ); | ||
| 89 : | } | ||
| 90 : | |||
| 91 : | void LLUploadDialog::setMessage( const std::string& msg) | ||
| 92 : | { | ||
| 93 : | const LLFontGL* font = LLResMgr::getInstance()->getRes( LLFONT_SANSSERIF ); | ||
| 94 : | |||
| 95 : | const S32 VPAD = 16; | ||
| 96 : | const S32 HPAD = 25; | ||
| 97 : | |||
| 98 : | // Make the text boxes a little wider than the text | ||
| 99 : | const S32 TEXT_PAD = 8; | ||
| 100 : | |||
| 101 : | // Split message into lines, separated by '\n' | ||
| 102 : | S32 max_msg_width = 0; | ||
| 103 : | std::list<std::string> msg_lines; | ||
| 104 : | |||
| 105 : | S32 size = msg.size() + 1;// + strlen("Uploading...\n\n"); | ||
| 106 : | char* temp_msg = new char[size]; | ||
| 107 : | |||
| 108 : | //strcpy(temp_msg,"Uploading...\n\n"); | ||
| 109 : | if (temp_msg == NULL) | ||
| 110 : | { | ||
| 111 : | llerrs << "Memory Allocation Failed" << llendl; | ||
| 112 : | return; | ||
| 113 : | } | ||
| 114 : | |||
| 115 : | strcpy( temp_msg, msg.c_str()); /* Flawfinder: ignore */ | ||
| 116 : | char* token = strtok( temp_msg, "\n" ); | ||
| 117 : | while( token ) | ||
| 118 : | { | ||
| 119 : | std::string tokstr(token); | ||
| 120 : | S32 cur_width = S32(font->getWidth(tokstr) + 0.99f) + TEXT_PAD; | ||
| 121 : | max_msg_width = llmax( max_msg_width, cur_width ); | ||
| 122 : | msg_lines.push_back( tokstr ); | ||
| 123 : | token = strtok( NULL, "\n" ); | ||
| 124 : | } | ||
| 125 : | delete[] temp_msg; | ||
| 126 : | |||
| 127 : | |||
| 128 : | S32 line_height = S32( font->getLineHeight() + 0.99f ); | ||
| 129 : | S32 dialog_width = max_msg_width + 2 * HPAD; | ||
| 130 : | S32 dialog_height = line_height * msg_lines.size() + 2 * VPAD; | ||
| 131 : | |||
| 132 : | reshape( dialog_width, dialog_height, FALSE ); | ||
| 133 : | |||
| 134 : | // Message | ||
| 135 : | S32 msg_x = (getRect().getWidth() - max_msg_width) / 2; | ||
| 136 : | S32 msg_y = getRect().getHeight() - VPAD - line_height; | ||
| 137 : | int line_num; | ||
| 138 : | for (line_num=0; line_num<16; ++line_num) | ||
| 139 : | { | ||
| 140 : | mLabelBox[line_num]->setVisible(FALSE); | ||
| 141 : | } | ||
| 142 : | line_num = 0; | ||
| 143 : | for (std::list<std::string>::iterator iter = msg_lines.begin(); | ||
| 144 : | iter != msg_lines.end(); ++iter) | ||
| 145 : | { | ||
| 146 : | std::string& cur_line = *iter; | ||
| 147 : | LLRect msg_rect; | ||
| 148 : | msg_rect.setOriginAndSize( msg_x, msg_y, max_msg_width, line_height ); | ||
| 149 : | mLabelBox[line_num]->setRect(msg_rect); | ||
| 150 : | mLabelBox[line_num]->setText(cur_line); | ||
| 151 : | mLabelBox[line_num]->setColor( gColors.getColor( "LabelTextColor" ) ); | ||
| 152 : | mLabelBox[line_num]->setVisible(TRUE); | ||
| 153 : | msg_y -= line_height; | ||
| 154 : | ++line_num; | ||
| 155 : | } | ||
| 156 : | |||
| 157 : | centerWithin(gViewerWindow->getRootView()->getRect()); | ||
| 158 : | } | ||
| 159 : | |||
| 160 : | LLUploadDialog::~LLUploadDialog() | ||
| 161 : | { | ||
| 162 : | gFocusMgr.releaseFocusIfNeeded( this ); | ||
| 163 : | |||
| 164 : | // LLFilePicker::instance().reset(); | ||
| 165 : | |||
| 166 : | |||
| 167 : | LLUploadDialog::sDialog = NULL; | ||
| 168 : | } | ||
| 169 : | |||
| 170 : | |||
| 171 : |
| ViewVC Help | |
| Powered by ViewVC 1.0.0 |

