llalertdialog.h

Go to the documentation of this file.
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 class LLAlertDialog : public LLModalDialog
00046 {
00047 public:
00048         typedef void (*alert_callback_t)(S32 option, void* user_data);
00049         typedef void (*alert_text_callback_t)(S32 option, const LLString& text, void* user_data);
00050         typedef bool (*display_callback_t)(S32 modal);
00051         enum { IGNORE_USE_DEFAULT=1, IGNORE_USE_SAVED=2, IGNORE_SHOW_AGAIN=3 };
00052 
00053 protected:
00054         struct ButtonData
00055         {
00056                 LLAlertDialog* mSelf;
00057                 LLButton* mButton;
00058                 S32 mOption;
00059         };
00060         
00061 public:
00062         virtual BOOL    handleKeyHere(KEY key, MASK mask, BOOL called_from_parent );
00063 
00064         virtual void    draw();
00065         virtual void    setVisible( BOOL visible );
00066 
00067         bool                    setCheckBox( const LLString&, const LLString& );        
00068         void                    setOptionEnabled( S32 option, BOOL enable );
00069         // If mUnique==TRUE only one copy of this message should exist
00070         void                    setUnique(BOOL val = TRUE) { mUnique = val; }
00071         void                    setEditTextCallback(alert_text_callback_t callback, void *user_data);
00072         void                    setEditTextArgs(const LLString::format_map_t& edit_args);
00073         void                    setDrawAsterixes(BOOL enable);
00074         
00075         bool                    show(); // May instantly destroy the message if it is unique (returns false)
00076         
00077         //statics
00078         static void             onButtonPressed(void* userdata);
00079 
00080         static LLAlertDialog* createXml( const LLString& xml_desc,
00081                                                                          alert_callback_t callback = NULL, void *user_data = NULL);
00082         static LLAlertDialog* createXml( const LLString& xml_desc, const LLString::format_map_t& args,
00083                                                                          alert_callback_t callback = NULL, void *user_data = NULL);
00084         
00085         static LLAlertDialog*   showXml( const LLString& xml_desc,
00086                                                          alert_callback_t callback = NULL, void *user_data = NULL);
00087         static LLAlertDialog*   showXml( const LLString& xml_desc, const LLString::format_map_t& args,
00088                                                          alert_callback_t callback = NULL, void *user_data = NULL);
00089 
00090         static LLAlertDialog*   showCritical( const LLString& msg, alert_callback_t callback = NULL, void *user_data = NULL);
00091         
00092         static bool parseAlerts(const LLString& xml_filename, LLControlGroup* settings = NULL, BOOL settings_only = FALSE);
00093         static const LLString& getTemplateMessage(const LLString& xml_desc);
00094 
00095         static void setDisplayCallback(display_callback_t callback) { sDisplayCallback = callback; }
00096         
00097         // Must call show() after creating these
00098         LLAlertDialog( const LLAlertDialogTemplate* xml_template, const LLString::format_map_t& args,
00099                                    alert_callback_t callback = NULL, void *user_data = NULL);
00100 
00101         static void format(LLString& msg, const LLString::format_map_t& args);
00102         
00103 protected:
00104         void createDialog(const std::vector<LLString>* options, S32 default_option,
00105                                           const LLString& msg, const LLString::format_map_t& args,
00106                                           const LLString& edit_text);
00107         
00108         virtual ~LLAlertDialog();       // No you can't kill it.  It can only kill itself.
00109 
00110         // Does it have a readable title label, or minimize or close buttons?
00111         BOOL hasTitleBar() const;
00112 
00113 protected:
00114         alert_callback_t mCallback;
00115         void*   mUserData;
00116         S32             mNumOptions;
00117         S32             mDefaultOption;
00118         BOOL    mOptionChosen;
00119         LLCheckBoxCtrl* mCheck;
00120         BOOL    mUnique;
00121         S32             mIgnorable;
00122         LLString mLabel;
00123         LLString mIgnoreLabel;
00124         ButtonData* mButtonData;
00125         LLFrameTimer mDefaultBtnTimer;
00126         // For Dialogs that take a line as text as input:
00127         LLLineEditor* mLineEditor;
00128         alert_text_callback_t mTextCallback;
00129         
00130 public:
00131         // use LLPointer so they delete themselves when sTemplates is destroyed
00132         typedef std::map<LLString, LLPointer<LLAlertDialogTemplate> > template_map_t;
00133         static template_map_t sAlertTemplates; // by mLabel
00134         static template_map_t sIgnorableTemplates; // by mIgnoreLabel
00135         static LLControlGroup* sSettings;
00136         static std::map<LLString, LLAlertDialog*> sUniqueActiveMap;
00137         static display_callback_t sDisplayCallback;
00138 
00139         static LLString sStringSkipNextTime;
00140         static LLString sStringAlwaysChoose;
00141 };
00142 
00143 //============================================================================
00144 
00145 class LLAlertDialogTemplate : public LLRefCount
00146 {
00147 public:
00148         LLAlertDialogTemplate() : mTitle(), mModal(FALSE), mUnique(FALSE), mIgnorable(0), mDefaultOption(0) {}
00149         
00150         void addOption(const LLString& label, const LLString& ignore_text, BOOL is_default = FALSE)
00151         {
00152                 if (is_default)
00153                 {
00154                         mDefaultOption = mOptions.size();
00155                 }
00156                 mOptions.push_back(label);
00157                 mOptionDefaultText.push_back(ignore_text);
00158         }
00159 
00160         S32 getIgnore()
00161         {
00162                 if (mIgnorable)
00163                 {
00164                         return LLAlertDialog::sSettings->getWarning(mIgnoreLabel) ? FALSE : mIgnorable;
00165                 }
00166                 else
00167                 {
00168                         return FALSE;
00169                 }
00170         }
00171 
00172         void setIgnore(bool state)
00173         {
00174                 if (mIgnorable)
00175                 {
00176                         LLAlertDialog::sSettings->setWarning(mIgnoreLabel, !state);
00177                 }
00178         }
00179 
00180         
00181 public:
00182         LLString mLabel;                        // Handle for access from code, etc
00183         LLString mTitle;                        // (optional) text to display in title bar
00184         LLString mMessage;                      // Message to display
00185         LLString mIgnoreListText;       // Text to display in enable/disable dialog (if mIgnorable == TRUE)
00186         LLString mIgnoreLabel;          // Handle for ignore variable (may be shared by multiple templates)
00187         BOOL mModal;
00188         BOOL mUnique;
00189         S32 mIgnorable; // 0 = Never Ignore, 1 = Do default option, 2 = Do saved option
00190         std::vector<LLString> mOptions;
00191         std::vector<LLString> mOptionDefaultText;
00192         S32 mDefaultOption;
00193         LLString mEditLineText;
00194 };
00195 
00196 #endif  // LL_ALERTDIALOG_H

Generated on Thu Jul 1 06:08:18 2010 for Second Life Viewer by  doxygen 1.4.7