caret.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: caret.h
  3. // Purpose: interface of wxCaret
  4. // Author: wxWidgets team
  5. // Licence: wxWindows licence
  6. /////////////////////////////////////////////////////////////////////////////
  7. /**
  8. @class wxCaret
  9. A caret is a blinking cursor showing the position where the typed text will
  10. appear. Text controls usually have their own caret but wxCaret provides a
  11. way to use a caret in other windows.
  12. Currently, the caret appears as a rectangle of the given size. In the
  13. future, it will be possible to specify a bitmap to be used for the caret
  14. shape.
  15. A caret is always associated with a window and the current caret can be
  16. retrieved using wxWindow::GetCaret(). The same caret can't be reused in two
  17. different windows.
  18. @library{wxcore}
  19. @category{misc}
  20. */
  21. class wxCaret
  22. {
  23. public:
  24. /**
  25. Default constructor.
  26. */
  27. wxCaret();
  28. //@{
  29. /**
  30. Creates a caret with the given size (in pixels) and associates it with
  31. the @a window.
  32. */
  33. wxCaret(wxWindow* window, int width, int height);
  34. wxCaret(wxWindow* window, const wxSize& size);
  35. //@}
  36. //@{
  37. /**
  38. Creates a caret with the given size (in pixels) and associates it with
  39. the @a window (same as the equivalent constructors).
  40. */
  41. bool Create(wxWindow* window, int width, int height);
  42. bool Create(wxWindow* window, const wxSize& size);
  43. //@}
  44. /**
  45. Returns the blink time which is measured in milliseconds and is the
  46. time elapsed between 2 inversions of the caret (blink time of the caret
  47. is the same for all carets, so this functions is static).
  48. */
  49. static int GetBlinkTime();
  50. //@{
  51. /**
  52. Get the caret position (in pixels).
  53. @beginWxPerlOnly
  54. In wxPerl there are two methods instead of a single overloaded
  55. method:
  56. - GetPosition(): returns a Wx::Point object.
  57. - GetPositionXY(): returns a 2-element list (x, y).
  58. @endWxPerlOnly
  59. */
  60. void GetPosition(int* x, int* y) const;
  61. wxPoint GetPosition() const;
  62. //@}
  63. //@{
  64. /**
  65. Get the caret size.
  66. @beginWxPerlOnly
  67. In wxPerl there are two methods instead of a single overloaded
  68. method:
  69. - GetSize(): returns a Wx::Size object.
  70. - GetSizeWH(): returns a 2-element list (width, height).
  71. @endWxPerlOnly
  72. */
  73. void GetSize(int* width, int* height) const;
  74. wxSize GetSize() const;
  75. //@}
  76. /**
  77. Get the window the caret is associated with.
  78. */
  79. wxWindow* GetWindow() const;
  80. /**
  81. Hides the caret, same as Show(@false).
  82. */
  83. virtual void Hide();
  84. /**
  85. Returns @true if the caret was created successfully.
  86. */
  87. bool IsOk() const;
  88. /**
  89. Returns @true if the caret is visible and @false if it is permanently
  90. hidden (if it is blinking and not shown currently but will be after
  91. the next blink, this method still returns @true).
  92. */
  93. bool IsVisible() const;
  94. //@{
  95. /**
  96. Move the caret to given position (in logical coordinates).
  97. */
  98. void Move(int x, int y);
  99. void Move(const wxPoint& pt);
  100. //@}
  101. /**
  102. Sets the blink time for all the carets.
  103. @warning Under Windows, this function will change the blink time for
  104. all carets permanently (until the next time it is called),
  105. even for carets in other applications.
  106. @see GetBlinkTime()
  107. */
  108. static void SetBlinkTime(int milliseconds);
  109. //@{
  110. /**
  111. Changes the size of the caret.
  112. */
  113. void SetSize(int width, int height);
  114. void SetSize(const wxSize& size);
  115. //@}
  116. /**
  117. Shows or hides the caret. Notice that if the caret was hidden N times,
  118. it must be shown N times as well to reappear on the screen.
  119. */
  120. virtual void Show(bool show = true);
  121. };