lluploaddialog.cpp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /**
  2. * @file lluploaddialog.cpp
  3. * @brief LLUploadDialog class implementation
  4. *
  5. * $LicenseInfo:firstyear=2001&license=viewergpl$
  6. *
  7. * Copyright (c) 2001-2009, 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
  21. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22. *
  23. * By copying, modifying or distributing this software, you acknowledge
  24. * that you have read and understood your obligations described above,
  25. * and agree to abide by those obligations.
  26. *
  27. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29. * COMPLETENESS OR PERFORMANCE.
  30. * $/LicenseInfo$
  31. */
  32. #include "linden_common.h"
  33. #include "lluploaddialog.h"
  34. #include "lltextbox.h"
  35. //static
  36. LLUploadDialog* LLUploadDialog::sDialog = NULL;
  37. //static
  38. LLUploadDialog* LLUploadDialog::modalUploadDialog(const std::string& msg)
  39. {
  40. // Note: object adds, removes, and destroys itself.
  41. return new LLUploadDialog(msg);
  42. }
  43. //static
  44. void LLUploadDialog::modalUploadFinished()
  45. {
  46. // Note: object adds, removes, and destroys itself.
  47. if (sDialog)
  48. {
  49. delete sDialog;
  50. sDialog = NULL;
  51. }
  52. }
  53. LLUploadDialog::LLUploadDialog(const std::string& msg)
  54. : LLPanel("upload_dialog", LLRect(0, 100, 100, 0))
  55. {
  56. mFont = LLFontGL::getFontSansSerif();
  57. setBackgroundVisible(true);
  58. if (sDialog)
  59. {
  60. delete sDialog;
  61. }
  62. sDialog = this;
  63. LLRect msg_rect;
  64. for (S32 line = 0; line < 16; ++line)
  65. {
  66. mLabelBox[line] = new LLTextBox(" ", msg_rect, " ", mFont);
  67. addChild(mLabelBox[line]);
  68. }
  69. setMessage(msg);
  70. // The dialog view is a root view
  71. gFocusMgr.setTopCtrl(this);
  72. }
  73. //virtual
  74. LLUploadDialog::~LLUploadDialog()
  75. {
  76. gFocusMgr.releaseFocusIfNeeded(this);
  77. LLUploadDialog::sDialog = NULL;
  78. }
  79. void LLUploadDialog::setMessage(const std::string& msg)
  80. {
  81. constexpr S32 VPAD = 16;
  82. constexpr S32 HPAD = 25;
  83. // Make the text boxes a little wider than the text
  84. constexpr S32 TEXT_PAD = 8;
  85. // Split message into lines, separated by '\n'
  86. S32 max_msg_width = 0;
  87. std::list<std::string> msg_lines;
  88. size_t size = msg.size() + 1;
  89. char* temp_msg = new (std::nothrow) char[size];
  90. if (!temp_msg)
  91. {
  92. llwarns << "Out of memory !" << llendl;
  93. return;
  94. }
  95. strcpy(temp_msg, msg.c_str());
  96. char* token = strtok(temp_msg, "\n");
  97. while (token)
  98. {
  99. std::string tokstr(token);
  100. S32 cur_width = S32(mFont->getWidth(tokstr) + 0.99f) + TEXT_PAD;
  101. max_msg_width = llmax(max_msg_width, cur_width);
  102. msg_lines.push_back(tokstr);
  103. token = strtok(NULL, "\n");
  104. }
  105. delete[] temp_msg;
  106. S32 line_height = S32(mFont->getLineHeight() + 0.99f);
  107. S32 dialog_width = max_msg_width + 2 * HPAD;
  108. S32 dialog_height = line_height * msg_lines.size() + 2 * VPAD;
  109. reshape(dialog_width, dialog_height, false);
  110. // Message
  111. S32 msg_x = (getRect().getWidth() - max_msg_width) / 2;
  112. S32 msg_y = getRect().getHeight() - VPAD - line_height;
  113. S32 line;
  114. for (line = 0; line < 16; ++line)
  115. {
  116. mLabelBox[line]->setVisible(false);
  117. }
  118. line = 0;
  119. for (std::list<std::string>::iterator iter = msg_lines.begin();
  120. iter != msg_lines.end(); ++iter)
  121. {
  122. std::string& cur_line = *iter;
  123. LLRect msg_rect;
  124. msg_rect.setOriginAndSize(msg_x, msg_y, max_msg_width, line_height);
  125. mLabelBox[line]->setRect(msg_rect);
  126. mLabelBox[line]->setText(cur_line);
  127. mLabelBox[line]->setColor(LLUI::sLabelTextColor);
  128. mLabelBox[line++]->setVisible(true);
  129. msg_y -= line_height;
  130. }
  131. LLVector2 window_size = LLUI::getWindowSize();
  132. centerWithin(LLRect(0, 0, ll_round(window_size.mV[VX]),
  133. ll_round(window_size.mV[VY])));
  134. }