llnotify.h

Go to the documentation of this file.
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 // NotifyBox - for notifications that require a response from the user.  
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         // For script notifications:
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         /*virtual*/ 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 
00078 protected:
00079         LLNotifyBox(LLPointer<LLNotifyBoxTemplate> notify_template, const LLString::format_map_t& args,
00080                                                          notify_callback_t callback, void* user_data,
00081                                                          BOOL is_caution = FALSE,
00082                                                          const option_list_t& extra_options = option_list_t(),
00083                                                          BOOL layout_script_dialog = FALSE);
00084         /*virtual*/ ~LLNotifyBox();
00085 
00086         
00087         /*virtual*/ BOOL handleMouseUp(S32 x, S32 y, MASK mask);
00088         /*virtual*/ BOOL handleRightMouseDown(S32 x, S32 y, MASK mask);
00089 
00090         // Animate as sliding onto the screen.
00091         /*virtual*/ void draw();
00092         /*virtual*/ BOOL tick();
00093 
00094         void moveToBack();
00095 
00096         // Returns the rect, relative to gNotifyView, where this
00097         // notify box should be placed.
00098         static LLRect getNotifyRect(S32 num_options, BOOL layout_script_dialog, BOOL is_caution);
00099         static LLRect getNotifyTipRect(const LLString &message);
00100 
00101         // internal handler for button being clicked
00102         static void onClickButton(void* data);
00103 
00104         // for "next" button
00105         static void onClickNext(void* data);
00106 
00107         static LLPointer<LLNotifyBoxTemplate> getTemplate(const LLString& xml_desc);
00108         static LLNotifyBox* findExistingNotify(LLPointer<LLNotifyBoxTemplate> notify_template, const LLString::format_map_t& args);
00109 
00110 private:
00111         void drawBackground() const;
00112 
00113         static LLPointer<LLNotifyBoxTemplate> sDefaultTemplate;
00114 
00115 protected:
00116         LLString mMessage;
00117 
00118         BOOL mIsTip;
00119         BOOL mIsCaution; // is this a caution notification?
00120         BOOL mAnimating; // Are we sliding onscreen?
00121         BOOL mUnique;
00122 
00123         // Time since this notification was displayed.
00124         // This is an LLTimer not a frame timer because I am concerned
00125         // that I could be out-of-sync by one frame in the animation.
00126         LLTimer mAnimateTimer;
00127 
00128         LLButton* mNextBtn;
00129 
00130         // keep response behavior isolated here
00131         struct LLNotifyBehavior
00132         {
00133                 LLNotifyBehavior(notify_callback_t callback, void* data);
00134 
00135                 notify_callback_t mCallback;
00136                 void* mData;
00137 
00138         };
00139         LLNotifyBehavior* mBehavior;
00140 
00141         S32 mNumOptions;
00142         S32 mDefaultOption;
00143 
00144         // Used for callbacks
00145         struct InstanceAndS32
00146         {
00147                 LLNotifyBox* mSelf;
00148                 S32                     mButton;
00149         };
00150         std::vector<InstanceAndS32*> mBtnCallbackData;
00151 
00152         typedef std::map<LLString, LLPointer<LLNotifyBoxTemplate> > template_map_t;
00153         static template_map_t sNotifyTemplates; // by mLabel
00154         
00155         static S32 sNotifyBoxCount;
00156         static const LLFontGL* sFont;
00157         static const LLFontGL* sFontSmall;
00158 
00159         typedef std::map<LLString, LLNotifyBox*> unique_map_t;
00160         static unique_map_t sOpenUniqueNotifyBoxes;
00161 };
00162 
00163 class LLNotifyBoxView : public LLUICtrl
00164 {
00165 public:
00166         LLNotifyBoxView(const LLString& name, const LLRect& rect, BOOL mouse_opaque, U32 follows=FOLLOWS_NONE);
00167         void showOnly(LLView * ctrl);
00168         LLNotifyBox * getFirstNontipBox() const;
00169 
00170         virtual EWidgetType getWidgetType() const { return WIDGET_TYPE_VIEW; };
00171         virtual LLString getWidgetTag() const { return LLString(); }
00172 };
00173 
00174 // This view contains the stack of notification windows.
00175 extern LLNotifyBoxView* gNotifyBoxView;
00176 
00177 class LLNotifyBoxTemplate : public LLRefCount
00178 {
00179 public:
00180         LLNotifyBoxTemplate(BOOL unique, F32 duration) :
00181                 mIsTip(FALSE),
00182                 mIsCaution(FALSE),
00183                 mUnique(unique),
00184                 mDuration(duration),
00185                 mDefaultOption(0)
00186         {}
00187 
00188         void setMessage(const LLString& message)
00189         {
00190                 mMessage = message;
00191         }
00192         
00193         void addOption(const LLString& label, BOOL is_default = FALSE)
00194         {
00195                 if (is_default)
00196                 {
00197                         mDefaultOption = mOptions.size();
00198                 }
00199                 mOptions.push_back(label);
00200         }
00201 
00202 public:
00203         LLString mLabel;                        // Handle for access from code, etc
00204         LLString mMessage;                      // Message to display
00205         BOOL mIsTip;
00206         BOOL mIsCaution;
00207         BOOL mUnique;
00208         F32      mDuration;
00209         LLNotifyBox::option_list_t mOptions;
00210         S32 mDefaultOption;
00211 };
00212 
00213 #endif

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