diff options
Diffstat (limited to 'linden/indra/llui/llalertdialog.cpp')
-rw-r--r-- | linden/indra/llui/llalertdialog.cpp | 94 |
1 files changed, 24 insertions, 70 deletions
diff --git a/linden/indra/llui/llalertdialog.cpp b/linden/indra/llui/llalertdialog.cpp index 8950fcd..0fa3585 100644 --- a/linden/indra/llui/llalertdialog.cpp +++ b/linden/indra/llui/llalertdialog.cpp | |||
@@ -2,6 +2,8 @@ | |||
2 | * @file llalertdialog.cpp | 2 | * @file llalertdialog.cpp |
3 | * @brief LLAlertDialog base class | 3 | * @brief LLAlertDialog base class |
4 | * | 4 | * |
5 | * $LicenseInfo:firstyear=2001&license=viewergpl$ | ||
6 | * | ||
5 | * Copyright (c) 2001-2007, Linden Research, Inc. | 7 | * Copyright (c) 2001-2007, Linden Research, Inc. |
6 | * | 8 | * |
7 | * Second Life Viewer Source Code | 9 | * Second Life Viewer Source Code |
@@ -24,6 +26,7 @@ | |||
24 | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | 26 | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO |
25 | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | 27 | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, |
26 | * COMPLETENESS OR PERFORMANCE. | 28 | * COMPLETENESS OR PERFORMANCE. |
29 | * $/LicenseInfo$ | ||
27 | */ | 30 | */ |
28 | 31 | ||
29 | #include "linden_common.h" | 32 | #include "linden_common.h" |
@@ -255,11 +258,9 @@ void LLAlertDialog::createDialog(const std::vector<LLString>* optionsp, S32 defa | |||
255 | const S32 LINE_HEIGHT = llfloor(font->getLineHeight() + 0.99f); | 258 | const S32 LINE_HEIGHT = llfloor(font->getLineHeight() + 0.99f); |
256 | const S32 EDITOR_HEIGHT = 20; | 259 | const S32 EDITOR_HEIGHT = 20; |
257 | 260 | ||
258 | // buttons | 261 | // Buttons |
259 | std::vector<LLString> default_option_list; | 262 | std::vector<LLString> default_option_list; |
260 | |||
261 | mNumOptions = optionsp->size(); | 263 | mNumOptions = optionsp->size(); |
262 | |||
263 | if( 0 == mNumOptions ) | 264 | if( 0 == mNumOptions ) |
264 | { | 265 | { |
265 | default_option_list.push_back("Close"); | 266 | default_option_list.push_back("Close"); |
@@ -269,7 +270,6 @@ void LLAlertDialog::createDialog(const std::vector<LLString>* optionsp, S32 defa | |||
269 | } | 270 | } |
270 | 271 | ||
271 | const std::vector<LLString>& options = *optionsp; | 272 | const std::vector<LLString>& options = *optionsp; |
272 | |||
273 | mButtonData = new ButtonData[mNumOptions]; | 273 | mButtonData = new ButtonData[mNumOptions]; |
274 | 274 | ||
275 | // Calc total width of buttons | 275 | // Calc total width of buttons |
@@ -286,55 +286,16 @@ void LLAlertDialog::createDialog(const std::vector<LLString>* optionsp, S32 defa | |||
286 | btn_total_width = (mNumOptions * button_width) + ((mNumOptions - 1) * BTN_HPAD); | 286 | btn_total_width = (mNumOptions * button_width) + ((mNumOptions - 1) * BTN_HPAD); |
287 | } | 287 | } |
288 | 288 | ||
289 | // Split message into lines, separated by '\n' | 289 | // Message: create text box using raw string, as text has been structure deliberately |
290 | // Use size of created text box to generate dialog box size | ||
290 | LLString msg = msg_in; | 291 | LLString msg = msg_in; |
291 | LLAlertDialog::format(msg, args); | 292 | LLAlertDialog::format( msg, args ); |
292 | |||
293 | llwarns << "Alert: " << msg << llendl; | 293 | llwarns << "Alert: " << msg << llendl; |
294 | LLTextBox* msg_box = new LLTextBox( "Alert message", msg, (F32)MAX_ALLOWED_MSG_WIDTH, font ); | ||
294 | 295 | ||
295 | S32 max_msg_width = 0; | 296 | const LLRect& text_rect = msg_box->getRect(); |
296 | std::vector<LLString> msg_lines; | 297 | S32 dialog_width = llmax( btn_total_width, text_rect.getWidth() ) + 2 * HPAD; |
297 | 298 | S32 dialog_height = text_rect.getHeight() + 3 * VPAD + BTN_HEIGHT; | |
298 | boost_tokenizer tokens(msg, boost::char_separator<char>("\n")); | ||
299 | for (boost_tokenizer::iterator token_iter = tokens.begin(); token_iter != tokens.end(); ++token_iter) | ||
300 | { | ||
301 | LLString line(*token_iter); | ||
302 | boost_tokenizer line_toks(line, boost::char_separator<char>(" \t")); | ||
303 | LLString cur_line; | ||
304 | S32 cur_line_width = 0; | ||
305 | for (boost_tokenizer::iterator token_iter2 = line_toks.begin(); token_iter2 != line_toks.end(); ++token_iter2) | ||
306 | { | ||
307 | LLString tok(*token_iter2); | ||
308 | LLString word; | ||
309 | if (cur_line_width > 0) | ||
310 | { | ||
311 | word = " "; | ||
312 | } | ||
313 | word += tok; | ||
314 | S32 word_width = S32(font->getWidth( word ) + 0.99f); | ||
315 | if (cur_line_width > 0 && cur_line_width + word_width > MAX_ALLOWED_MSG_WIDTH) | ||
316 | { | ||
317 | max_msg_width = llmax( max_msg_width, cur_line_width + MSG_PAD); | ||
318 | msg_lines.push_back( cur_line ); | ||
319 | cur_line.clear(); | ||
320 | cur_line_width = 0; | ||
321 | word = tok; // no ' ' | ||
322 | } | ||
323 | cur_line += word; | ||
324 | cur_line_width += word_width; | ||
325 | } | ||
326 | if (cur_line_width > 0) | ||
327 | { | ||
328 | max_msg_width = llmax( max_msg_width, cur_line_width ); | ||
329 | msg_lines.push_back( cur_line ); | ||
330 | } | ||
331 | } | ||
332 | |||
333 | // pad message box so we don't clip last character | ||
334 | max_msg_width += 2; | ||
335 | |||
336 | S32 dialog_width = llmax( btn_total_width, max_msg_width ) + 2 * HPAD; | ||
337 | S32 dialog_height = LINE_HEIGHT * msg_lines.size() + 3 * VPAD + BTN_HEIGHT; | ||
338 | 299 | ||
339 | if (hasTitleBar()) | 300 | if (hasTitleBar()) |
340 | { | 301 | { |
@@ -346,26 +307,20 @@ void LLAlertDialog::createDialog(const std::vector<LLString>* optionsp, S32 defa | |||
346 | dialog_width = llmax(dialog_width, S32(font->getWidth( edit_text ) + 0.99f)); | 307 | dialog_width = llmax(dialog_width, S32(font->getWidth( edit_text ) + 0.99f)); |
347 | dialog_height += EDITOR_HEIGHT; | 308 | dialog_height += EDITOR_HEIGHT; |
348 | } | 309 | } |
349 | 310 | ||
350 | reshape( dialog_width, dialog_height, FALSE ); | 311 | reshape( dialog_width, dialog_height, FALSE ); |
351 | 312 | ||
352 | // Message | 313 | S32 msg_y = mRect.getHeight() - VPAD; |
353 | S32 msg_x = (mRect.getWidth() - max_msg_width) / 2; | ||
354 | S32 msg_y = mRect.getHeight() - VPAD - LINE_HEIGHT; | ||
355 | if (hasTitleBar()) | 314 | if (hasTitleBar()) |
356 | { | 315 | { |
357 | msg_y -= LINE_HEIGHT; // room for title | 316 | msg_y -= LINE_HEIGHT; // room for title |
358 | } | 317 | } |
359 | 318 | ||
360 | for( std::vector<LLString>::iterator iter = msg_lines.begin(); iter != msg_lines.end(); ++iter ) | 319 | LLRect rect; |
361 | { | 320 | rect.setLeftTopAndSize( HPAD, msg_y, text_rect.getWidth(), text_rect.getHeight() ); |
362 | LLRect msg_rect; | 321 | msg_box->setRect( rect ); |
363 | msg_rect.setOriginAndSize( msg_x, msg_y, max_msg_width, LINE_HEIGHT ); | 322 | msg_box->setColor( LLUI::sColorsGroup->getColor( "LabelTextColor" ) ); |
364 | LLTextBox* label_box = new LLTextBox( "Alert message", msg_rect, iter->c_str(), font ); | 323 | addChild(msg_box); |
365 | label_box->setColor( LLUI::sColorsGroup->getColor( "LabelTextColor" ) ); | ||
366 | addChild(label_box); | ||
367 | msg_y -= LINE_HEIGHT; | ||
368 | } | ||
369 | 324 | ||
370 | // Buttons | 325 | // Buttons |
371 | S32 button_left = (mRect.getWidth() - btn_total_width) / 2; | 326 | S32 button_left = (mRect.getWidth() - btn_total_width) / 2; |
@@ -386,7 +341,7 @@ void LLAlertDialog::createDialog(const std::vector<LLString>* optionsp, S32 defa | |||
386 | mButtonData[i].mSelf = this; | 341 | mButtonData[i].mSelf = this; |
387 | mButtonData[i].mButton = btn; | 342 | mButtonData[i].mButton = btn; |
388 | mButtonData[i].mOption = i; | 343 | mButtonData[i].mOption = i; |
389 | 344 | ||
390 | addChild(btn); | 345 | addChild(btn); |
391 | 346 | ||
392 | if( i == default_option ) | 347 | if( i == default_option ) |
@@ -402,13 +357,12 @@ void LLAlertDialog::createDialog(const std::vector<LLString>* optionsp, S32 defa | |||
402 | { | 357 | { |
403 | S32 y = VPAD + BTN_HEIGHT + VPAD/2; | 358 | S32 y = VPAD + BTN_HEIGHT + VPAD/2; |
404 | mLineEditor = new LLLineEditor("lineeditor", | 359 | mLineEditor = new LLLineEditor("lineeditor", |
405 | LLRect( HPAD, y+EDITOR_HEIGHT, dialog_width-HPAD, y), | 360 | LLRect( HPAD, y+EDITOR_HEIGHT, dialog_width-HPAD, y), |
406 | edit_text, | 361 | edit_text, |
407 | LLFontGL::sSansSerif, | 362 | LLFontGL::sSansSerif, |
408 | STD_STRING_STR_LEN); | 363 | STD_STRING_STR_LEN); |
409 | addChild(mLineEditor); | 364 | addChild(mLineEditor); |
410 | } | 365 | } |
411 | |||
412 | } | 366 | } |
413 | 367 | ||
414 | bool LLAlertDialog::setCheckBox( const LLString& check_title, const LLString& check_control ) | 368 | bool LLAlertDialog::setCheckBox( const LLString& check_title, const LLString& check_control ) |