llalertdialog.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /**
  2. * @file llalertdialog.h
  3. * @brief LLAlertDialog base class
  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. #ifndef LL_ALERTDIALOG_H
  33. #define LL_ALERTDIALOG_H
  34. #include "llinitdestroyclass.h"
  35. #include "llpanel.h"
  36. #include "llmodaldialog.h"
  37. #include "llnotifications.h" // Also includes llinstancetracker.h and llui.h
  38. class LLAlertDialogTemplate;
  39. class LLButton;
  40. class LLCheckBoxCtrl;
  41. class LLFontGL;
  42. class LLLineEditor;
  43. class LLAlertDialog final : public LLModalDialog,
  44. public LLInitClass<LLAlertDialog>,
  45. public LLInstanceTracker<LLAlertDialog, LLUUID>
  46. {
  47. protected:
  48. LOG_CLASS(LLAlertDialog);
  49. public:
  50. typedef bool (*display_callback_t)(S32 modal);
  51. class URLLoader
  52. {
  53. public:
  54. virtual void load(const std::string& url) = 0;
  55. virtual ~URLLoader() = default;
  56. };
  57. static void setURLLoader(URLLoader* loader)
  58. {
  59. sURLLoader = loader;
  60. }
  61. public:
  62. // User's responsibility to call show() after creating these.
  63. LLAlertDialog(LLNotificationPtr notep, bool is_modal);
  64. private:
  65. // No you cannot kill it. It can only kill itself.
  66. ~LLAlertDialog() override = default;
  67. public:
  68. bool handleKeyHere(KEY key, MASK mask) override;
  69. void draw() override;
  70. void setVisible(bool visible) override;
  71. void onClose(bool app_quitting) override;
  72. LL_INLINE void setCaution(bool val = true) { mCaution = val; }
  73. // If mUnique == true only one copy of this message should exist
  74. LL_INLINE void setUnique(bool val = true) { mUnique = val; }
  75. bool setCheckBox(const std::string&, const std::string&);
  76. void setEditTextArgs(const LLSD& edit_args);
  77. // May instantly destroy the message if it is unique (returns false)
  78. bool show();
  79. // For Lua scripted automated responses. HB
  80. bool simulateClickButton(S32 i);
  81. static void initClass();
  82. static bool onNewNotification(const LLSD& notify, bool is_modal);
  83. static void onButtonPressed(void* userdata);
  84. static void onClickIgnore(LLUICtrl* ctrl, void* user_data);
  85. typedef void (*lua_alert_cb_t)(const std::string& name,
  86. const LLUUID& dialog_id,
  87. const std::string& message,
  88. const std::vector<std::string>& buttons);
  89. LL_INLINE static void setLuaCallback(lua_alert_cb_t fn)
  90. {
  91. sLuaCallback = fn;
  92. }
  93. private:
  94. // Does it have a readable title label, or minimize or close buttons ?
  95. bool hasTitleBar() const;
  96. private:
  97. LLNotificationPtr mNote;
  98. LLFontGL* mFont;
  99. static std::map<std::string, LLAlertDialog*> sUniqueActiveMap;
  100. static URLLoader* sURLLoader;
  101. static LLControlGroup* sSettings;
  102. struct ButtonData
  103. {
  104. ButtonData(LLAlertDialog* dialog, LLButton* button = NULL,
  105. const std::string& url = LLStringUtil::null)
  106. : mSelf(dialog),
  107. mButton(button),
  108. mURL(url)
  109. {
  110. }
  111. LLAlertDialog* mSelf;
  112. LLButton* mButton;
  113. std::string mURL;
  114. };
  115. std::vector<ButtonData> mButtonData;
  116. static lua_alert_cb_t sLuaCallback;
  117. std::string mLabel;
  118. LLCheckBoxCtrl* mCheck;
  119. LLLineEditor* mLineEditor;
  120. LLFrameTimer mDefaultBtnTimer;
  121. // For Dialogs that take a line as text as input:
  122. S32 mDefaultOption;
  123. bool mCaution;
  124. bool mUnique;
  125. };
  126. #endif // LL_ALERTDIALOG_H