00001
00032 #ifndef LL_LLNOTIFY_H
00033 #define LL_LLNOTIFY_H
00034
00035 #include "llfontgl.h"
00036 #include "llpanel.h"
00037 #include "lltimer.h"
00038 #include <vector>
00039
00040 class LLButton;
00041 class LLNotifyBoxTemplate;
00042
00043
00044 class LLNotifyBox : public LLPanel, public LLEventTimer
00045 {
00046 public:
00047 typedef void (*notify_callback_t)(S32 option, void* data);
00048 typedef std::vector<LLString> option_list_t;
00049
00050 static LLNotifyBox* showXml( const LLString& xml_desc,
00051 notify_callback_t callback = NULL, void *user_data = NULL);
00052 static LLNotifyBox* showXml( const LLString& xml_desc, const LLString::format_map_t& args, BOOL is_caution,
00053 notify_callback_t callback = NULL, void *user_data = NULL);
00054 static LLNotifyBox* showXml( const LLString& xml_desc, const LLString::format_map_t& args,
00055 notify_callback_t callback = NULL, void *user_data = NULL);
00056
00057 static LLNotifyBox* showXml( const LLString& xml_desc, const LLString::format_map_t& args,
00058 notify_callback_t callback, void *user_data,
00059 const option_list_t& options,
00060 BOOL layout_script_dialog = FALSE);
00061
00062 static bool parseNotify(const LLString& xml_filename);
00063 static const LLString getTemplateMessage(const LLString& xml_desc, const LLString::format_map_t& args);
00064 static const LLString getTemplateMessage(const LLString& xml_desc);
00065 static BOOL getTemplateIsCaution(const LLString& xml_desc);
00066
00067 BOOL isTip() const { return mIsTip; }
00068 BOOL isCaution() const { return mIsCaution; }
00069 void setVisible(BOOL visible);
00070 void stopAnimation() { mAnimating = FALSE; }
00071
00072 notify_callback_t getNotifyCallback() { return mBehavior->mCallback; }
00073 void* getUserData() { return mBehavior->mData; }
00074 void close();
00075
00076 static void cleanup();
00077 static void format(LLString& msg, const LLString::format_map_t& args);
00078
00079 protected:
00080 LLNotifyBox(LLPointer<LLNotifyBoxTemplate> notify_template, const LLString::format_map_t& args,
00081 notify_callback_t callback, void* user_data,
00082 BOOL is_caution = FALSE,
00083 const option_list_t& extra_options = option_list_t(),
00084 BOOL layout_script_dialog = FALSE);
00085 ~LLNotifyBox();
00086
00087
00088 BOOL handleMouseUp(S32 x, S32 y, MASK mask);
00089 BOOL handleRightMouseDown(S32 x, S32 y, MASK mask);
00090
00091
00092 void draw();
00093 BOOL tick();
00094
00095 void moveToBack(bool getfocus = false);
00096
00097
00098
00099 static LLRect getNotifyRect(S32 num_options, BOOL layout_script_dialog, BOOL is_caution);
00100 static LLRect getNotifyTipRect(const LLString &message);
00101
00102
00103 static void onClickButton(void* data);
00104
00105
00106 static void onClickNext(void* data);
00107
00108 static LLPointer<LLNotifyBoxTemplate> getTemplate(const LLString& xml_desc);
00109 static LLNotifyBox* findExistingNotify(LLPointer<LLNotifyBoxTemplate> notify_template, const LLString::format_map_t& args);
00110
00111 private:
00112 void drawBackground() const;
00113
00114 static LLPointer<LLNotifyBoxTemplate> sDefaultTemplate;
00115
00116 protected:
00117 LLString mMessage;
00118
00119 BOOL mIsTip;
00120 BOOL mIsCaution;
00121 BOOL mAnimating;
00122 BOOL mUnique;
00123
00124
00125
00126
00127 LLTimer mAnimateTimer;
00128
00129 LLButton* mNextBtn;
00130
00131
00132 struct LLNotifyBehavior
00133 {
00134 LLNotifyBehavior(notify_callback_t callback, void* data);
00135
00136 notify_callback_t mCallback;
00137 void* mData;
00138
00139 };
00140 LLNotifyBehavior* mBehavior;
00141
00142 S32 mNumOptions;
00143 S32 mDefaultOption;
00144
00145
00146 struct InstanceAndS32
00147 {
00148 LLNotifyBox* mSelf;
00149 S32 mButton;
00150 };
00151 std::vector<InstanceAndS32*> mBtnCallbackData;
00152
00153 typedef std::map<LLString, LLPointer<LLNotifyBoxTemplate> > template_map_t;
00154 static template_map_t sNotifyTemplates;
00155
00156 static S32 sNotifyBoxCount;
00157 static const LLFontGL* sFont;
00158 static const LLFontGL* sFontSmall;
00159
00160 typedef std::map<LLString, LLNotifyBox*> unique_map_t;
00161 static unique_map_t sOpenUniqueNotifyBoxes;
00162 };
00163
00164 class LLNotifyBoxView : public LLUICtrl
00165 {
00166 public:
00167 LLNotifyBoxView(const LLString& name, const LLRect& rect, BOOL mouse_opaque, U32 follows=FOLLOWS_NONE);
00168 void showOnly(LLView * ctrl);
00169 LLNotifyBox * getFirstNontipBox() const;
00170
00171
00172 class Matcher
00173 {
00174 public:
00175 Matcher(){}
00176 virtual ~Matcher() {}
00177 virtual BOOL matches(LLNotifyBox::notify_callback_t callback, void* cb_data) const = 0;
00178 };
00179
00180
00181 void purgeMessagesMatching(const Matcher& matcher);
00182 };
00183
00184
00185 extern LLNotifyBoxView* gNotifyBoxView;
00186
00187 class LLNotifyBoxTemplate : public LLRefCount
00188 {
00189 public:
00190 LLNotifyBoxTemplate(BOOL unique, F32 duration) :
00191 mIsTip(FALSE),
00192 mIsCaution(FALSE),
00193 mUnique(unique),
00194 mDuration(duration),
00195 mDefaultOption(0)
00196 {}
00197
00198 void setMessage(const LLString& message)
00199 {
00200 mMessage = message;
00201 }
00202
00203 void addOption(const LLString& label, BOOL is_default = FALSE)
00204 {
00205 if (is_default)
00206 {
00207 mDefaultOption = mOptions.size();
00208 }
00209 mOptions.push_back(label);
00210 }
00211
00212 public:
00213 LLString mLabel;
00214 LLString mMessage;
00215 BOOL mIsTip;
00216 BOOL mIsCaution;
00217 BOOL mUnique;
00218 F32 mDuration;
00219 LLNotifyBox::option_list_t mOptions;
00220 S32 mDefaultOption;
00221 };
00222
00223 #endif