PageRenderTime 32ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/llui/llfocusmgr.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 151 lines | 82 code | 32 blank | 37 comment | 1 complexity | 1c39eaa647300a6f13628b51d138a700 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llfocusmgr.h
  3. * @brief LLFocusMgr base class
  4. *
  5. * $LicenseInfo:firstyear=2002&license=viewerlgpl$
  6. * Second Life Viewer Source Code
  7. * Copyright (C) 2010, Linden Research, Inc.
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation;
  12. * version 2.1 of the License only.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. *
  23. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  24. * $/LicenseInfo$
  25. */
  26. // Singleton that manages keyboard and mouse focus
  27. #ifndef LL_LLFOCUSMGR_H
  28. #define LL_LLFOCUSMGR_H
  29. #include "llstring.h"
  30. #include "llframetimer.h"
  31. #include "llui.h"
  32. class LLUICtrl;
  33. class LLMouseHandler;
  34. class LLView;
  35. // NOTE: the LLFocusableElement class declaration has been moved here from lluictrl.h.
  36. class LLFocusableElement
  37. {
  38. friend class LLFocusMgr; // allow access to focus change handlers
  39. public:
  40. LLFocusableElement();
  41. virtual ~LLFocusableElement();
  42. virtual void setFocus( BOOL b );
  43. virtual BOOL hasFocus() const;
  44. typedef boost::signals2::signal<void(LLFocusableElement*)> focus_signal_t;
  45. boost::signals2::connection setFocusLostCallback( const focus_signal_t::slot_type& cb);
  46. boost::signals2::connection setFocusReceivedCallback(const focus_signal_t::slot_type& cb);
  47. boost::signals2::connection setFocusChangedCallback(const focus_signal_t::slot_type& cb);
  48. boost::signals2::connection setTopLostCallback(const focus_signal_t::slot_type& cb);
  49. // These were brought up the hierarchy from LLView so that we don't have to use dynamic_cast when dealing with keyboard focus.
  50. virtual BOOL handleKey(KEY key, MASK mask, BOOL called_from_parent);
  51. virtual BOOL handleUnicodeChar(llwchar uni_char, BOOL called_from_parent);
  52. virtual void onTopLost(); // called when registered as top ctrl and user clicks elsewhere
  53. protected:
  54. virtual void onFocusReceived();
  55. virtual void onFocusLost();
  56. focus_signal_t* mFocusLostCallback;
  57. focus_signal_t* mFocusReceivedCallback;
  58. focus_signal_t* mFocusChangedCallback;
  59. focus_signal_t* mTopLostCallback;
  60. };
  61. class LLFocusMgr
  62. {
  63. public:
  64. LLFocusMgr();
  65. ~LLFocusMgr();
  66. // Mouse Captor
  67. void setMouseCapture(LLMouseHandler* new_captor); // new_captor = NULL to release the mouse.
  68. LLMouseHandler* getMouseCapture() const { return mMouseCaptor; }
  69. void removeMouseCaptureWithoutCallback( const LLMouseHandler* captor );
  70. BOOL childHasMouseCapture( const LLView* parent ) const;
  71. // Keyboard Focus
  72. void setKeyboardFocus(LLFocusableElement* new_focus, BOOL lock = FALSE, BOOL keystrokes_only = FALSE); // new_focus = NULL to release the focus.
  73. LLFocusableElement* getKeyboardFocus() const { return mKeyboardFocus; }
  74. LLFocusableElement* getLastKeyboardFocus() const { return mLastKeyboardFocus; }
  75. BOOL childHasKeyboardFocus( const LLView* parent ) const;
  76. void removeKeyboardFocusWithoutCallback( const LLFocusableElement* focus );
  77. BOOL getKeystrokesOnly() { return mKeystrokesOnly; }
  78. void setKeystrokesOnly(BOOL keystrokes_only) { mKeystrokesOnly = keystrokes_only; }
  79. F32 getFocusFlashAmt() const;
  80. S32 getFocusFlashWidth() const { return llround(lerp(1.f, 3.f, getFocusFlashAmt())); }
  81. LLColor4 getFocusColor() const;
  82. void triggerFocusFlash();
  83. BOOL getAppHasFocus() const { return mAppHasFocus; }
  84. void setAppHasFocus(BOOL focus);
  85. LLUICtrl* getLastFocusForGroup(LLView* subtree_root) const;
  86. void clearLastFocusForGroup(LLView* subtree_root);
  87. // If setKeyboardFocus(NULL) is called, and there is a non-NULL default
  88. // keyboard focus view, focus goes there. JC
  89. void setDefaultKeyboardFocus(LLFocusableElement* default_focus) { mDefaultKeyboardFocus = default_focus; }
  90. LLFocusableElement* getDefaultKeyboardFocus() const { return mDefaultKeyboardFocus; }
  91. // Top View
  92. void setTopCtrl(LLUICtrl* new_top);
  93. LLUICtrl* getTopCtrl() const { return mTopCtrl; }
  94. void removeTopCtrlWithoutCallback( const LLUICtrl* top_view );
  95. BOOL childIsTopCtrl( const LLView* parent ) const;
  96. // All Three
  97. void releaseFocusIfNeeded( LLView* top_view );
  98. void lockFocus();
  99. void unlockFocus();
  100. BOOL focusLocked() const { return mLockedView != NULL; }
  101. bool keyboardFocusHasAccelerators() const;
  102. struct Impl;
  103. private:
  104. LLUICtrl* mLockedView;
  105. // Mouse Captor
  106. LLMouseHandler* mMouseCaptor; // Mouse events are premptively routed to this object
  107. // Keyboard Focus
  108. LLFocusableElement* mKeyboardFocus; // Keyboard events are preemptively routed to this object
  109. LLFocusableElement* mLastKeyboardFocus; // who last had focus
  110. LLFocusableElement* mDefaultKeyboardFocus;
  111. BOOL mKeystrokesOnly;
  112. // Top View
  113. LLUICtrl* mTopCtrl;
  114. LLFrameTimer mFocusFlashTimer;
  115. BOOL mAppHasFocus;
  116. Impl * mImpl;
  117. };
  118. extern LLFocusMgr gFocusMgr;
  119. #endif // LL_LLFOCUSMGR_H