PageRenderTime 36ms CodeModel.GetById 21ms app.highlight 13ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/newview/lluploaddialog.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 161 lines | 97 code | 27 blank | 37 comment | 5 complexity | a6c1912cfce7cc5f81bad1284b5b54ef MD5 | raw file
  1/** 
  2 * @file lluploaddialog.cpp
  3 * @brief LLUploadDialog class implementation
  4 *
  5 * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  6 * Second Life Viewer Source Code
  7 * Copyright (C) 2010, Linden Research, Inc.
  8 * 
  9 * This library is free software; you can redistribute it and/or
 10 * modify it under the terms of the GNU Lesser General Public
 11 * License as published by the Free Software Foundation;
 12 * version 2.1 of the License only.
 13 * 
 14 * This library is distributed in the hope that it will be useful,
 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 17 * Lesser General Public License for more details.
 18 * 
 19 * You should have received a copy of the GNU Lesser General Public
 20 * License along with this library; if not, write to the Free Software
 21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 22 * 
 23 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 24 * $/LicenseInfo$
 25 */
 26
 27#include "llviewerprecompiledheaders.h"
 28
 29#include "lluploaddialog.h"
 30#include "llviewerwindow.h"
 31#include "llfontgl.h"
 32#include "llresmgr.h"
 33#include "lltextbox.h"
 34#include "llbutton.h"
 35#include "llkeyboard.h"
 36#include "llfocusmgr.h"
 37#include "llviewercontrol.h"
 38#include "llrootview.h"
 39
 40// static
 41LLUploadDialog*	LLUploadDialog::sDialog = NULL;
 42
 43// static
 44LLUploadDialog* LLUploadDialog::modalUploadDialog(const std::string& msg)
 45{
 46	// Note: object adds, removes, and destroys itself.
 47	return new LLUploadDialog(msg);
 48}
 49
 50// static
 51void LLUploadDialog::modalUploadFinished()
 52{
 53	// Note: object adds, removes, and destroys itself.
 54	delete LLUploadDialog::sDialog;
 55	LLUploadDialog::sDialog = NULL;
 56}
 57
 58////////////////////////////////////////////////////////////
 59// Private methods
 60
 61LLUploadDialog::LLUploadDialog( const std::string& msg)
 62  : LLPanel()
 63{
 64	setBackgroundVisible( TRUE );
 65
 66	if( LLUploadDialog::sDialog )
 67	{
 68		delete LLUploadDialog::sDialog;
 69	}
 70	LLUploadDialog::sDialog = this;
 71
 72	const LLFontGL* font = LLFontGL::getFontSansSerif();
 73	LLRect msg_rect;
 74	for (int line_num=0; line_num<16; ++line_num)
 75	{
 76		LLTextBox::Params params;
 77		params.name("Filename");
 78		params.rect(msg_rect);
 79		params.initial_value("Filename");
 80		params.font(font);
 81		mLabelBox[line_num] = LLUICtrlFactory::create<LLTextBox> (params);
 82		addChild(mLabelBox[line_num]);
 83	}
 84
 85	setMessage(msg);
 86
 87	// The dialog view is a root view
 88	gViewerWindow->addPopup(this);
 89}
 90
 91void LLUploadDialog::setMessage( const std::string& msg)
 92{
 93	const LLFontGL* font = LLFontGL::getFontSansSerif();
 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;
106	std::vector<char> temp_msg(size); // non-const copy to make strtok happy
107	strcpy( &temp_msg[0], msg.c_str());
108	char* token = strtok( &temp_msg[0], "\n" );
109	while( token )
110	{
111		std::string tokstr(token);
112		S32 cur_width = S32(font->getWidth(tokstr) + 0.99f) + TEXT_PAD;
113		max_msg_width = llmax( max_msg_width, cur_width );
114		msg_lines.push_back( tokstr );
115		token = strtok( NULL, "\n" );
116	}
117
118	S32 line_height = S32( font->getLineHeight() + 0.99f );
119	S32 dialog_width = max_msg_width + 2 * HPAD;
120	S32 dialog_height = line_height * msg_lines.size() + 2 * VPAD;
121
122	reshape( dialog_width, dialog_height, FALSE );
123
124	// Message
125	S32 msg_x = (getRect().getWidth() - max_msg_width) / 2;
126	S32 msg_y = getRect().getHeight() - VPAD - line_height;
127	int line_num;
128	for (line_num=0; line_num<16; ++line_num)
129	{
130		mLabelBox[line_num]->setVisible(FALSE);
131	}
132	line_num = 0;
133	for (std::list<std::string>::iterator iter = msg_lines.begin();
134		 iter != msg_lines.end(); ++iter)
135	{
136		std::string& cur_line = *iter;
137		LLRect msg_rect;
138		msg_rect.setOriginAndSize( msg_x, msg_y, max_msg_width, line_height );
139		mLabelBox[line_num]->setRect(msg_rect);
140		mLabelBox[line_num]->setText(cur_line);
141		mLabelBox[line_num]->setColor( LLUIColorTable::instance().getColor( "LabelTextColor" ) );
142		mLabelBox[line_num]->setVisible(TRUE);
143		msg_y -= line_height;
144		++line_num;
145	}
146
147	centerWithin(gViewerWindow->getRootView()->getRect());
148}
149
150LLUploadDialog::~LLUploadDialog()
151{
152	gFocusMgr.releaseFocusIfNeeded( this );
153
154//    LLFilePicker::instance().reset();
155
156
157	LLUploadDialog::sDialog = NULL;
158}
159
160
161