00001
00032 #ifndef LL_ALERTDIALOG_H
00033 #define LL_ALERTDIALOG_H
00034
00035 #include "llpanel.h"
00036 #include "llmodaldialog.h"
00037 #include "llmemory.h"
00038 #include "llui.h"
00039
00040 class LLButton;
00041 class LLCheckBoxCtrl;
00042 class LLAlertDialogTemplate;
00043 class LLLineEditor;
00044
00045
00046 class LLAlertDialog : public LLModalDialog
00047 {
00048 public:
00049 typedef void (*alert_callback_t)(S32 option, void* user_data);
00050 typedef void (*alert_text_callback_t)(S32 option, const LLString& text, void* user_data);
00051 typedef bool (*display_callback_t)(S32 modal);
00052 enum { IGNORE_USE_DEFAULT=1, IGNORE_USE_SAVED=2, IGNORE_SHOW_AGAIN=3 };
00053
00054 class URLLoader
00055 {
00056 public:
00057 virtual void load(const std::string& url) = 0;
00058 virtual ~URLLoader() {}
00059 };
00060
00061 static void setURLLoader(URLLoader* loader)
00062 {
00063 sURLLoader = loader;
00064 }
00065
00066 public:
00067
00068 LLAlertDialog( const LLAlertDialogTemplate* xml_template, const LLString::format_map_t& args,
00069 alert_callback_t callback = NULL, void *user_data = NULL);
00070
00071 virtual BOOL handleKeyHere(KEY key, MASK mask );
00072
00073 virtual void draw();
00074 virtual void setVisible( BOOL visible );
00075 virtual void onClose(bool app_quitting);
00076
00077 bool setCheckBox( const LLString&, const LLString& );
00078 void setOptionEnabled( S32 option, BOOL enable );
00079 void setCaution(BOOL val = TRUE) { mCaution = val; }
00080
00081 void setUnique(BOOL val = TRUE) { mUnique = val; }
00082 void setEditTextCallback(alert_text_callback_t callback, void *user_data);
00083 void setEditTextArgs(const LLString::format_map_t& edit_args);
00084 void setDrawAsterixes(BOOL enable);
00085
00086 bool show();
00087
00088
00089 static void onButtonPressed(void* userdata);
00090
00091 static LLAlertDialog* createXml( const LLString& xml_desc,
00092 alert_callback_t callback = NULL, void *user_data = NULL);
00093 static LLAlertDialog* createXml( const LLString& xml_desc, const LLString::format_map_t& args,
00094 alert_callback_t callback = NULL, void *user_data = NULL);
00095
00096 static LLAlertDialog* showXml( const LLString& xml_desc,
00097 alert_callback_t callback = NULL, void *user_data = NULL);
00098 static LLAlertDialog* showXml( const LLString& xml_desc, const LLString::format_map_t& args,
00099 alert_callback_t callback = NULL, void *user_data = NULL);
00100
00101 static LLAlertDialog* showCritical( const LLString& msg, alert_callback_t callback = NULL, void *user_data = NULL);
00102
00103 static bool parseAlerts(const LLString& xml_filename, LLControlGroup* settings = NULL, BOOL settings_only = FALSE);
00104 static const LLString& getTemplateMessage(const LLString& xml_desc);
00105
00106 static void setDisplayCallback(display_callback_t callback) { sDisplayCallback = callback; }
00107
00108 void format(LLString& msg, const LLString::format_map_t& args);
00109
00110 static LLControlGroup* sSettings;
00111
00112
00113 typedef std::map<LLString, LLPointer<LLAlertDialogTemplate> > template_map_t;
00114 static template_map_t sAlertTemplates;
00115 static template_map_t sIgnorableTemplates;
00116
00117
00118 private:
00119
00120 static std::map<LLString, LLAlertDialog*> sUniqueActiveMap;
00121 static display_callback_t sDisplayCallback;
00122
00123 static LLString sStringSkipNextTime;
00124 static LLString sStringAlwaysChoose;
00125
00126 void createDialog(const std::vector<LLString>* options, S32 default_option,
00127 const LLString& msg, const LLString::format_map_t& args,
00128 const LLString& edit_text);
00129
00130 virtual ~LLAlertDialog();
00131 void handleCallbacks();
00132
00133
00134
00135 BOOL hasTitleBar() const;
00136
00137 struct ButtonData
00138 {
00139 LLAlertDialog* mSelf;
00140 LLButton* mButton;
00141 S32 mOption;
00142 } * mButtonData;
00143
00144 alert_callback_t mCallback;
00145 void* mUserData;
00146 S32 mNumOptions;
00147 S32 mDefaultOption;
00148 BOOL mOptionChosen;
00149 LLCheckBoxCtrl* mCheck;
00150 BOOL mCaution;
00151 BOOL mUnique;
00152 S32 mIgnorable;
00153 LLString mLabel;
00154 LLString mIgnoreLabel;
00155 LLFrameTimer mDefaultBtnTimer;
00156
00157 LLLineEditor* mLineEditor;
00158 alert_text_callback_t mTextCallback;
00159
00160 LLString mURL;
00161 S32 mURLOption;
00162
00163 private:
00164 static URLLoader* sURLLoader;
00165 };
00166
00167
00168
00169 class LLAlertDialogTemplate : public LLRefCount
00170 {
00171 public:
00172 LLAlertDialogTemplate() : mTitle(), mURLOption(0), mModal(FALSE), mCaution(FALSE), mUnique(FALSE), mIgnorable(0), mDefaultOption(0) {}
00173
00174 void addOption(const LLString& label, const LLString& ignore_text, BOOL is_default = FALSE)
00175 {
00176 if (is_default)
00177 {
00178 mDefaultOption = mOptions.size();
00179 }
00180 mOptions.push_back(label);
00181 mOptionDefaultText.push_back(ignore_text);
00182 }
00183
00184 S32 getIgnore()
00185 {
00186 if (mIgnorable)
00187 {
00188 return LLAlertDialog::sSettings->getWarning(mIgnoreLabel) ? FALSE : mIgnorable;
00189 }
00190 else
00191 {
00192 return FALSE;
00193 }
00194 }
00195
00196 void setIgnore(bool state)
00197 {
00198 if (mIgnorable)
00199 {
00200 LLAlertDialog::sSettings->setWarning(mIgnoreLabel, !state);
00201 }
00202 }
00203
00204
00205 public:
00206 LLString mLabel;
00207 LLString mTitle;
00208 LLString mMessage;
00209 LLString mIgnoreListText;
00210 LLString mIgnoreLabel;
00211 LLString mURL;
00212 S32 mURLOption;
00213 BOOL mModal;
00214 BOOL mCaution;
00215 BOOL mUnique;
00216 S32 mIgnorable;
00217 std::vector<LLString> mOptions;
00218 std::vector<LLString> mOptionDefaultText;
00219 S32 mDefaultOption;
00220 LLString mEditLineText;
00221 };
00222
00223 #endif // LL_ALERTDIALOG_H