PageRenderTime 38ms CodeModel.GetById 16ms RepoModel.GetById 0ms 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
Possible License(s): LGPL-2.1
  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. #include "llviewerprecompiledheaders.h"
  27. #include "lluploaddialog.h"
  28. #include "llviewerwindow.h"
  29. #include "llfontgl.h"
  30. #include "llresmgr.h"
  31. #include "lltextbox.h"
  32. #include "llbutton.h"
  33. #include "llkeyboard.h"
  34. #include "llfocusmgr.h"
  35. #include "llviewercontrol.h"
  36. #include "llrootview.h"
  37. // static
  38. LLUploadDialog* LLUploadDialog::sDialog = NULL;
  39. // static
  40. LLUploadDialog* LLUploadDialog::modalUploadDialog(const std::string& msg)
  41. {
  42. // Note: object adds, removes, and destroys itself.
  43. return new LLUploadDialog(msg);
  44. }
  45. // static
  46. void LLUploadDialog::modalUploadFinished()
  47. {
  48. // Note: object adds, removes, and destroys itself.
  49. delete LLUploadDialog::sDialog;
  50. LLUploadDialog::sDialog = NULL;
  51. }
  52. ////////////////////////////////////////////////////////////
  53. // Private methods
  54. LLUploadDialog::LLUploadDialog( const std::string& msg)
  55. : LLPanel()
  56. {
  57. setBackgroundVisible( TRUE );
  58. if( LLUploadDialog::sDialog )
  59. {
  60. delete LLUploadDialog::sDialog;
  61. }
  62. LLUploadDialog::sDialog = this;
  63. const LLFontGL* font = LLFontGL::getFontSansSerif();
  64. LLRect msg_rect;
  65. for (int line_num=0; line_num<16; ++line_num)
  66. {
  67. LLTextBox::Params params;
  68. params.name("Filename");
  69. params.rect(msg_rect);
  70. params.initial_value("Filename");
  71. params.font(font);
  72. mLabelBox[line_num] = LLUICtrlFactory::create<LLTextBox> (params);
  73. addChild(mLabelBox[line_num]);
  74. }
  75. setMessage(msg);
  76. // The dialog view is a root view
  77. gViewerWindow->addPopup(this);
  78. }
  79. void LLUploadDialog::setMessage( const std::string& msg)
  80. {
  81. const LLFontGL* font = LLFontGL::getFontSansSerif();
  82. const S32 VPAD = 16;
  83. const S32 HPAD = 25;
  84. // Make the text boxes a little wider than the text
  85. const S32 TEXT_PAD = 8;
  86. // Split message into lines, separated by '\n'
  87. S32 max_msg_width = 0;
  88. std::list<std::string> msg_lines;
  89. S32 size = msg.size() + 1;
  90. std::vector<char> temp_msg(size); // non-const copy to make strtok happy
  91. strcpy( &temp_msg[0], msg.c_str());
  92. char* token = strtok( &temp_msg[0], "\n" );
  93. while( token )
  94. {
  95. std::string tokstr(token);
  96. S32 cur_width = S32(font->getWidth(tokstr) + 0.99f) + TEXT_PAD;
  97. max_msg_width = llmax( max_msg_width, cur_width );
  98. msg_lines.push_back( tokstr );
  99. token = strtok( NULL, "\n" );
  100. }
  101. S32 line_height = S32( font->getLineHeight() + 0.99f );
  102. S32 dialog_width = max_msg_width + 2 * HPAD;
  103. S32 dialog_height = line_height * msg_lines.size() + 2 * VPAD;
  104. reshape( dialog_width, dialog_height, FALSE );
  105. // Message
  106. S32 msg_x = (getRect().getWidth() - max_msg_width) / 2;
  107. S32 msg_y = getRect().getHeight() - VPAD - line_height;
  108. int line_num;
  109. for (line_num=0; line_num<16; ++line_num)
  110. {
  111. mLabelBox[line_num]->setVisible(FALSE);
  112. }
  113. line_num = 0;
  114. for (std::list<std::string>::iterator iter = msg_lines.begin();
  115. iter != msg_lines.end(); ++iter)
  116. {
  117. std::string& cur_line = *iter;
  118. LLRect msg_rect;
  119. msg_rect.setOriginAndSize( msg_x, msg_y, max_msg_width, line_height );
  120. mLabelBox[line_num]->setRect(msg_rect);
  121. mLabelBox[line_num]->setText(cur_line);
  122. mLabelBox[line_num]->setColor( LLUIColorTable::instance().getColor( "LabelTextColor" ) );
  123. mLabelBox[line_num]->setVisible(TRUE);
  124. msg_y -= line_height;
  125. ++line_num;
  126. }
  127. centerWithin(gViewerWindow->getRootView()->getRect());
  128. }
  129. LLUploadDialog::~LLUploadDialog()
  130. {
  131. gFocusMgr.releaseFocusIfNeeded( this );
  132. // LLFilePicker::instance().reset();
  133. LLUploadDialog::sDialog = NULL;
  134. }