llfocusmgr.h
上传用户:king477883
上传日期:2021-03-01
资源大小:9553k
文件大小:6k
源码类别:

游戏引擎

开发平台:

C++ Builder

  1. /** 
  2.  * @file llfocusmgr.h
  3.  * @brief LLFocusMgr base class
  4.  *
  5.  * $LicenseInfo:firstyear=2002&license=viewergpl$
  6.  * 
  7.  * Copyright (c) 2002-2010, Linden Research, Inc.
  8.  * 
  9.  * Second Life Viewer Source Code
  10.  * The source code in this file ("Source Code") is provided by Linden Lab
  11.  * to you under the terms of the GNU General Public License, version 2.0
  12.  * ("GPL"), unless you have obtained a separate licensing agreement
  13.  * ("Other License"), formally executed by you and Linden Lab.  Terms of
  14.  * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15.  * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16.  * 
  17.  * There are special exceptions to the terms and conditions of the GPL as
  18.  * it is applied to this Source Code. View the full text of the exception
  19.  * in the file doc/FLOSS-exception.txt in this software distribution, or
  20.  * online at
  21.  * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22.  * 
  23.  * By copying, modifying or distributing this software, you acknowledge
  24.  * that you have read and understood your obligations described above,
  25.  * and agree to abide by those obligations.
  26.  * 
  27.  * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28.  * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29.  * COMPLETENESS OR PERFORMANCE.
  30.  * $/LicenseInfo$
  31.  */
  32. // Singleton that manages keyboard and mouse focus
  33. #ifndef LL_LLFOCUSMGR_H
  34. #define LL_LLFOCUSMGR_H
  35. #include "llstring.h"
  36. #include "llframetimer.h"
  37. #include "llui.h"
  38. class LLUICtrl;
  39. class LLMouseHandler;
  40. class LLView;
  41. // NOTE: the LLFocusableElement class declaration has been moved here from lluictrl.h.
  42. class LLFocusableElement
  43. {
  44. friend class LLFocusMgr; // allow access to focus change handlers
  45. public:
  46. LLFocusableElement();
  47. virtual ~LLFocusableElement();
  48. virtual void setFocus( BOOL b );
  49. virtual BOOL hasFocus() const;
  50. typedef boost::signals2::signal<void(LLFocusableElement*)> focus_signal_t;
  51. boost::signals2::connection setFocusLostCallback( const focus_signal_t::slot_type& cb);
  52. boost::signals2::connection setFocusReceivedCallback(const focus_signal_t::slot_type& cb);
  53. boost::signals2::connection setFocusChangedCallback(const focus_signal_t::slot_type& cb);
  54. boost::signals2::connection setTopLostCallback(const focus_signal_t::slot_type& cb);
  55. // These were brought up the hierarchy from LLView so that we don't have to use dynamic_cast when dealing with keyboard focus.
  56. virtual BOOL handleKey(KEY key, MASK mask, BOOL called_from_parent);
  57. virtual BOOL handleUnicodeChar(llwchar uni_char, BOOL called_from_parent);
  58. protected:
  59. virtual void onFocusReceived();
  60. virtual void onFocusLost();
  61. virtual void onTopLost(); // called when registered as top ctrl and user clicks elsewhere
  62. focus_signal_t*  mFocusLostCallback;
  63. focus_signal_t*  mFocusReceivedCallback;
  64. focus_signal_t*  mFocusChangedCallback;
  65. focus_signal_t*  mTopLostCallback;
  66. };
  67. class LLFocusMgr
  68. {
  69. public:
  70. LLFocusMgr();
  71. ~LLFocusMgr() { mFocusHistory.clear(); }
  72. // Mouse Captor
  73. void setMouseCapture(LLMouseHandler* new_captor); // new_captor = NULL to release the mouse.
  74. LLMouseHandler* getMouseCapture() const { return mMouseCaptor; } 
  75. void removeMouseCaptureWithoutCallback( const LLMouseHandler* captor );
  76. BOOL childHasMouseCapture( const LLView* parent ) const;
  77. // Keyboard Focus
  78. void setKeyboardFocus(LLFocusableElement* new_focus, BOOL lock = FALSE, BOOL keystrokes_only = FALSE); // new_focus = NULL to release the focus.
  79. LLFocusableElement* getKeyboardFocus() const { return mKeyboardFocus; }  
  80. LLFocusableElement* getLastKeyboardFocus() const { return mLastKeyboardFocus; }  
  81. BOOL childHasKeyboardFocus( const LLView* parent ) const;
  82. void removeKeyboardFocusWithoutCallback( const LLFocusableElement* focus );
  83. BOOL getKeystrokesOnly() { return mKeystrokesOnly; }
  84. void setKeystrokesOnly(BOOL keystrokes_only) { mKeystrokesOnly = keystrokes_only; }
  85. F32 getFocusFlashAmt() const;
  86. S32 getFocusFlashWidth() const { return llround(lerp(1.f, 3.f, getFocusFlashAmt())); }
  87. LLColor4 getFocusColor() const;
  88. void triggerFocusFlash();
  89. BOOL getAppHasFocus() const { return mAppHasFocus; }
  90. void setAppHasFocus(BOOL focus);
  91. LLUICtrl* getLastFocusForGroup(LLView* subtree_root) const;
  92. void clearLastFocusForGroup(LLView* subtree_root);
  93. // If setKeyboardFocus(NULL) is called, and there is a non-NULL default
  94. // keyboard focus view, focus goes there. JC
  95. void setDefaultKeyboardFocus(LLFocusableElement* default_focus) { mDefaultKeyboardFocus = default_focus; }
  96. LLFocusableElement* getDefaultKeyboardFocus() const { return mDefaultKeyboardFocus; }
  97. // Top View
  98. void setTopCtrl(LLUICtrl* new_top);
  99. LLUICtrl* getTopCtrl() const { return mTopCtrl; }
  100. void removeTopCtrlWithoutCallback( const LLUICtrl* top_view );
  101. BOOL childIsTopCtrl( const LLView* parent ) const;
  102. // All Three
  103. void releaseFocusIfNeeded( const LLView* top_view );
  104. void lockFocus();
  105. void unlockFocus();
  106. BOOL focusLocked() const { return mLockedView != NULL; }
  107. private:
  108. LLUICtrl* mLockedView;
  109. // Mouse Captor
  110. LLMouseHandler* mMouseCaptor; // Mouse events are premptively routed to this object
  111. // Keyboard Focus
  112. LLFocusableElement* mKeyboardFocus; // Keyboard events are preemptively routed to this object
  113. LLFocusableElement* mLastKeyboardFocus; // who last had focus
  114. LLFocusableElement* mDefaultKeyboardFocus;
  115. BOOL mKeystrokesOnly;
  116. // caching list of keyboard focus ancestors for calling onFocusReceived and onFocusLost
  117. typedef std::list<LLHandle<LLView> > view_handle_list_t;
  118. view_handle_list_t mCachedKeyboardFocusList;
  119. // Top View
  120. LLUICtrl* mTopCtrl;
  121. LLFrameTimer mFocusFlashTimer;
  122. BOOL mAppHasFocus;
  123. typedef std::map<LLHandle<LLView>, LLHandle<LLView> > focus_history_map_t;
  124. focus_history_map_t mFocusHistory;
  125. #ifdef _DEBUG
  126. std::string mMouseCaptorName;
  127. std::string mKeyboardFocusName;
  128. std::string mTopCtrlName;
  129. #endif
  130. };
  131. extern LLFocusMgr gFocusMgr;
  132. #endif  // LL_LLFOCUSMGR_H