00001 00032 // Singleton that manages keyboard and mouse focus 00033 00034 #ifndef LL_LLFOCUSMGR_H 00035 #define LL_LLFOCUSMGR_H 00036 00037 #include "llstring.h" 00038 #include "llframetimer.h" 00039 #include "llview.h" 00040 00041 class LLUICtrl; 00042 class LLMouseHandler; 00043 00044 class LLFocusMgr 00045 { 00046 public: 00047 typedef void (*FocusLostCallback)(LLUICtrl*); 00048 00049 LLFocusMgr(); 00050 ~LLFocusMgr(); 00051 00052 // Mouse Captor 00053 void setMouseCapture(LLMouseHandler* new_captor); // new_captor = NULL to release the mouse. 00054 LLMouseHandler* getMouseCapture() { return mMouseCaptor; } 00055 void removeMouseCaptureWithoutCallback( LLMouseHandler* captor ); 00056 BOOL childHasMouseCapture( LLView* parent ); 00057 00058 // Keyboard Focus 00059 void setKeyboardFocus(LLUICtrl* new_focus, FocusLostCallback on_focus_lost, BOOL lock = FALSE); // new_focus = NULL to release the focus. 00060 LLUICtrl* getKeyboardFocus() const { return mKeyboardFocus; } 00061 BOOL childHasKeyboardFocus( const LLView* parent ) const; 00062 void removeKeyboardFocusWithoutCallback( LLView* focus ); 00063 FocusLostCallback getFocusCallback() { return mKeyboardFocusLostCallback; } 00064 F32 getFocusTime() const { return mFocusTimer.getElapsedTimeF32(); } 00065 F32 getFocusFlashAmt(); 00066 LLColor4 getFocusColor(); 00067 void triggerFocusFlash(); 00068 BOOL getAppHasFocus() { return mAppHasFocus; } 00069 void setAppHasFocus(BOOL focus); 00070 LLUICtrl* getLastFocusForGroup(LLView* subtree_root); 00071 void clearLastFocusForGroup(LLView* subtree_root); 00072 00073 // If setKeyboardFocus(NULL) is called, and there is a non-NULL default 00074 // keyboard focus view, focus goes there. JC 00075 void setDefaultKeyboardFocus(LLUICtrl* default_focus); 00076 LLUICtrl* getDefaultKeyboardFocus() const { return mDefaultKeyboardFocus; } 00077 00078 00079 // Top View 00080 void setTopCtrl(LLUICtrl* new_top); 00081 LLUICtrl* getTopCtrl() const { return mTopCtrl; } 00082 void removeTopCtrlWithoutCallback( LLUICtrl* top_view ); 00083 BOOL childIsTopCtrl( LLView* parent ); 00084 00085 // All Three 00086 void releaseFocusIfNeeded( LLView* top_view ); 00087 void lockFocus(); 00088 void unlockFocus(); 00089 BOOL focusLocked() { return mLockedView != NULL; } 00090 00091 protected: 00092 LLUICtrl* mLockedView; 00093 FocusLostCallback mKeyboardLockedFocusLostCallback; 00094 00095 // Mouse Captor 00096 LLMouseHandler* mMouseCaptor; // Mouse events are premptively routed to this object 00097 00098 // Keyboard Focus 00099 LLUICtrl* mKeyboardFocus; // Keyboard events are preemptively routed to this object 00100 LLUICtrl* mDefaultKeyboardFocus; 00101 FocusLostCallback mKeyboardFocusLostCallback; // The object to which keyboard events are routed is called before another object takes its place 00102 00103 // Top View 00104 LLUICtrl* mTopCtrl; 00105 00106 LLFrameTimer mFocusTimer; 00107 F32 mFocusWeight; 00108 00109 BOOL mAppHasFocus; 00110 00111 typedef std::map<LLViewHandle, LLViewHandle> focus_history_map_t; 00112 focus_history_map_t mFocusHistory; 00113 00114 #ifdef _DEBUG 00115 LLString mMouseCaptorName; 00116 LLString mKeyboardFocusName; 00117 LLString mTopCtrlName; 00118 #endif 00119 }; 00120 00121 extern LLFocusMgr gFocusMgr; 00122 00123 #endif // LL_LLFOCUSMGR_H 00124