caret.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/generic/caret.h
  3. // Purpose: generic wxCaret class
  4. // Author: Vadim Zeitlin (original code by Robert Roebling)
  5. // Modified by:
  6. // Created: 25.05.99
  7. // Copyright: (c) wxWidgets team
  8. // Licence: wxWindows licence
  9. ///////////////////////////////////////////////////////////////////////////////
  10. #ifndef _WX_CARET_H_
  11. #define _WX_CARET_H_
  12. #include "wx/timer.h"
  13. #include "wx/dc.h"
  14. #include "wx/overlay.h"
  15. #ifdef wxHAS_NATIVE_OVERLAY
  16. #define wxHAS_CARET_USING_OVERLAYS
  17. #endif
  18. class WXDLLIMPEXP_FWD_CORE wxCaret;
  19. class WXDLLIMPEXP_CORE wxCaretTimer : public wxTimer
  20. {
  21. public:
  22. wxCaretTimer(wxCaret *caret);
  23. virtual void Notify();
  24. private:
  25. wxCaret *m_caret;
  26. };
  27. class WXDLLIMPEXP_CORE wxCaret : public wxCaretBase
  28. {
  29. public:
  30. // ctors
  31. // -----
  32. // default - use Create()
  33. wxCaret() : m_timer(this) { InitGeneric(); }
  34. // creates a block caret associated with the given window
  35. wxCaret(wxWindowBase *window, int width, int height)
  36. : wxCaretBase(window, width, height), m_timer(this) { InitGeneric(); }
  37. wxCaret(wxWindowBase *window, const wxSize& size)
  38. : wxCaretBase(window, size), m_timer(this) { InitGeneric(); }
  39. virtual ~wxCaret();
  40. // implementation
  41. // --------------
  42. // called by wxWindow (not using the event tables)
  43. virtual void OnSetFocus();
  44. virtual void OnKillFocus();
  45. // called by wxCaretTimer
  46. void OnTimer();
  47. protected:
  48. virtual void DoShow();
  49. virtual void DoHide();
  50. virtual void DoMove();
  51. virtual void DoSize();
  52. // blink the caret once
  53. void Blink();
  54. // refresh the caret
  55. void Refresh();
  56. // draw the caret on the given DC
  57. void DoDraw(wxDC *dc, wxWindow* win);
  58. private:
  59. // GTK specific initialization
  60. void InitGeneric();
  61. #ifdef wxHAS_CARET_USING_OVERLAYS
  62. // the overlay for displaying the caret
  63. wxOverlay m_overlay;
  64. #else
  65. // the bitmap holding the part of window hidden by the caret when it was
  66. // at (m_xOld, m_yOld)
  67. wxBitmap m_bmpUnderCaret;
  68. int m_xOld,
  69. m_yOld;
  70. #endif
  71. wxCaretTimer m_timer;
  72. bool m_blinkedOut, // true => caret hidden right now
  73. m_hasFocus; // true => our window has focus
  74. };
  75. #endif // _WX_CARET_H_