Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

193 lines
7.5 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //===========================================================================//
  7. #ifndef VGUI_IINPUT_H
  8. #define VGUI_IINPUT_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include <vgui/VGUI.h>
  13. #include "tier1/interface.h"
  14. #include "vgui/MouseCode.h"
  15. #include "vgui/KeyCode.h"
  16. namespace vgui
  17. {
  18. class Cursor;
  19. typedef unsigned long HCursor;
  20. #define VGUI_GCS_COMPREADSTR 0x0001
  21. #define VGUI_GCS_COMPREADATTR 0x0002
  22. #define VGUI_GCS_COMPREADCLAUSE 0x0004
  23. #define VGUI_GCS_COMPSTR 0x0008
  24. #define VGUI_GCS_COMPATTR 0x0010
  25. #define VGUI_GCS_COMPCLAUSE 0x0020
  26. #define VGUI_GCS_CURSORPOS 0x0080
  27. #define VGUI_GCS_DELTASTART 0x0100
  28. #define VGUI_GCS_RESULTREADSTR 0x0200
  29. #define VGUI_GCS_RESULTREADCLAUSE 0x0400
  30. #define VGUI_GCS_RESULTSTR 0x0800
  31. #define VGUI_GCS_RESULTCLAUSE 0x1000
  32. // style bit flags for WM_IME_COMPOSITION
  33. #define VGUI_CS_INSERTCHAR 0x2000
  34. #define VGUI_CS_NOMOVECARET 0x4000
  35. #define MESSAGE_CURSOR_POS -1
  36. #define MESSAGE_CURRENT_KEYFOCUS -2
  37. class IInput : public IBaseInterface
  38. {
  39. public:
  40. virtual void SetMouseFocus(VPANEL newMouseFocus) = 0;
  41. virtual void SetMouseCapture(VPANEL panel) = 0;
  42. // returns the string name of a scan code
  43. virtual void GetKeyCodeText(KeyCode code, OUT_Z_BYTECAP(buflen) char *buf, int buflen) = 0;
  44. // focus
  45. virtual VPANEL GetFocus() = 0;
  46. virtual VPANEL GetCalculatedFocus() = 0;// to handle cases where the focus changes inside a frame.
  47. virtual VPANEL GetMouseOver() = 0; // returns the panel the mouse is currently over, ignoring mouse capture
  48. // mouse state
  49. virtual void SetCursorPos(int x, int y) = 0;
  50. virtual void GetCursorPos(int &x, int &y) = 0;
  51. virtual bool WasMousePressed(MouseCode code) = 0;
  52. virtual bool WasMouseDoublePressed(MouseCode code) = 0;
  53. virtual bool IsMouseDown(MouseCode code) = 0;
  54. // cursor override
  55. virtual void SetCursorOveride(HCursor cursor) = 0;
  56. virtual HCursor GetCursorOveride() = 0;
  57. // key state
  58. virtual bool WasMouseReleased(MouseCode code) = 0;
  59. virtual bool WasKeyPressed(KeyCode code) = 0;
  60. virtual bool IsKeyDown(KeyCode code) = 0;
  61. virtual bool WasKeyTyped(KeyCode code) = 0;
  62. virtual bool WasKeyReleased(KeyCode code) = 0;
  63. virtual VPANEL GetAppModalSurface() = 0;
  64. // set the modal dialog panel.
  65. // all events will go only to this panel and its children.
  66. virtual void SetAppModalSurface(VPANEL panel) = 0;
  67. // release the modal dialog panel
  68. // do this when your modal dialog finishes.
  69. virtual void ReleaseAppModalSurface() = 0;
  70. virtual void GetCursorPosition( int &x, int &y ) = 0;
  71. virtual void SetIMEWindow( void *hwnd ) = 0;
  72. virtual void *GetIMEWindow() = 0;
  73. virtual void OnChangeIME( bool forward ) = 0;
  74. virtual int GetCurrentIMEHandle() = 0;
  75. virtual int GetEnglishIMEHandle() = 0;
  76. // Returns the Language Bar label (Chinese, Korean, Japanese, Russion, Thai, etc.)
  77. virtual void GetIMELanguageName( OUT_Z_BYTECAP(unicodeBufferSizeInBytes) wchar_t *buf, int unicodeBufferSizeInBytes ) = 0;
  78. // Returns the short code for the language (EN, CH, KO, JP, RU, TH, etc. ).
  79. virtual void GetIMELanguageShortCode( OUT_Z_BYTECAP(unicodeBufferSizeInBytes) wchar_t *buf, int unicodeBufferSizeInBytes ) = 0;
  80. struct LanguageItem
  81. {
  82. wchar_t shortname[ 4 ];
  83. wchar_t menuname[ 128 ];
  84. int handleValue;
  85. bool active; // true if this is the active language
  86. };
  87. struct ConversionModeItem
  88. {
  89. wchar_t menuname[ 128 ];
  90. int handleValue;
  91. bool active; // true if this is the active conversion mode
  92. };
  93. struct SentenceModeItem
  94. {
  95. wchar_t menuname[ 128 ];
  96. int handleValue;
  97. bool active; // true if this is the active sentence mode
  98. };
  99. // Call with NULL dest to get item count
  100. virtual int GetIMELanguageList( LanguageItem *dest, int destcount ) = 0;
  101. virtual int GetIMEConversionModes( ConversionModeItem *dest, int destcount ) = 0;
  102. virtual int GetIMESentenceModes( SentenceModeItem *dest, int destcount ) = 0;
  103. virtual void OnChangeIMEByHandle( int handleValue ) = 0;
  104. virtual void OnChangeIMEConversionModeByHandle( int handleValue ) = 0;
  105. virtual void OnChangeIMESentenceModeByHandle( int handleValue ) = 0;
  106. virtual void OnInputLanguageChanged() = 0;
  107. virtual void OnIMEStartComposition() = 0;
  108. virtual void OnIMEComposition( int flags ) = 0;
  109. virtual void OnIMEEndComposition() = 0;
  110. virtual void OnIMEShowCandidates() = 0;
  111. virtual void OnIMEChangeCandidates() = 0;
  112. virtual void OnIMECloseCandidates() = 0;
  113. virtual void OnIMERecomputeModes() = 0;
  114. virtual int GetCandidateListCount() = 0;
  115. virtual void GetCandidate( int num, OUT_Z_BYTECAP(destSizeBytes) wchar_t *dest, int destSizeBytes ) = 0;
  116. virtual int GetCandidateListSelectedItem() = 0;
  117. virtual int GetCandidateListPageSize() = 0;
  118. virtual int GetCandidateListPageStart() = 0;
  119. //NOTE: We render our own candidate lists most of the time...
  120. virtual void SetCandidateWindowPos( int x, int y ) = 0;
  121. virtual bool GetShouldInvertCompositionString() = 0;
  122. virtual bool CandidateListStartsAtOne() = 0;
  123. virtual void SetCandidateListPageStart( int start ) = 0;
  124. // Passes in a keycode which allows hitting other mouse buttons w/o cancelling capture mode
  125. virtual void SetMouseCaptureEx(VPANEL panel, MouseCode captureStartMouseCode ) = 0;
  126. // Because OnKeyCodeTyped uses CallParentFunction and is therefore message based, there's no way
  127. // to know if handler actually swallowed the specified keycode. To get around this, I set a global before calling the
  128. // kb focus OnKeyCodeTyped function and if we ever get to a Panel::OnKeyCodeTypes we know that nobody handled the message
  129. // and in that case we can post a message to any "unhandled keycode" listeners
  130. // This will generate an MESSAGE_FUNC_INT( "KeyCodeUnhandled" "code" code ) message to each such listener
  131. virtual void RegisterKeyCodeUnhandledListener( VPANEL panel ) = 0;
  132. virtual void UnregisterKeyCodeUnhandledListener( VPANEL panel ) = 0;
  133. // Posts unhandled message to all interested panels
  134. virtual void OnKeyCodeUnhandled( int keyCode ) = 0;
  135. // Assumes subTree is a child panel of the root panel for the vgui contect
  136. // if restrictMessagesToSubTree is true, then mouse and kb messages are only routed to the subTree and it's children and mouse/kb focus
  137. // can only be on one of the subTree children, if a mouse click occurs outside of the subtree, and "UnhandledMouseClick" message is sent to unhandledMouseClickListener panel
  138. // if it's set
  139. // if restrictMessagesToSubTree is false, then mouse and kb messages are routed as normal except that they are not routed down into the subtree
  140. // however, if a mouse click occurs outside of the subtree, and "UnhandleMouseClick" message is sent to unhandledMouseClickListener panel
  141. // if it's set
  142. virtual void SetModalSubTree( VPANEL subTree, VPANEL unhandledMouseClickListener, bool restrictMessagesToSubTree = true ) = 0;
  143. virtual void ReleaseModalSubTree() = 0;
  144. virtual VPANEL GetModalSubTree() = 0;
  145. // These toggle whether the modal subtree is exclusively receiving messages or conversely whether it's being excluded from receiving messages
  146. // Sends a "ModalSubTree", state message
  147. virtual void SetModalSubTreeReceiveMessages( bool state ) = 0;
  148. virtual bool ShouldModalSubTreeReceiveMessages() const = 0;
  149. virtual VPANEL GetMouseCapture() = 0;
  150. };
  151. #define VGUI_INPUT_INTERFACE_VERSION "VGUI_Input005"
  152. } // namespace vgui
  153. #endif // VGUI_IINPUT_H