]>
git.saurik.com Git - wxWidgets.git/blob - include/wx/caret.h
1 ///////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxCaretBase class - the interface of wxCaret
4 // Author: Vadim Zeitlin
8 // Copyright: (c) wxWindows team
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_CARET_H_BASE_
13 #define _WX_CARET_H_BASE_
15 // ---------------------------------------------------------------------------
16 // forward declarations
17 // ---------------------------------------------------------------------------
19 class WXDLLEXPORT wxWindow
;
20 class WXDLLEXPORT wxWindowBase
;
22 // ---------------------------------------------------------------------------
23 // A caret is a blinking cursor showing the position where the typed text will
24 // appear. It can be either a solid block or a custom bitmap (TODO)
25 // ---------------------------------------------------------------------------
27 class WXDLLEXPORT wxCaretBase
32 // default - use Create
33 wxCaretBase() { Init(); }
34 // create the caret of given (in pixels) width and height and associate
35 // with the given window
36 wxCaretBase(wxWindowBase
*window
, int width
, int height
)
40 (void)Create(window
, width
, height
);
43 wxCaretBase(wxWindowBase
*window
, const wxSize
& size
)
47 (void)Create(window
, size
);
50 // Create() functions - same as ctor but returns the success code
51 // --------------------------------------------------------------
54 bool Create(wxWindowBase
*window
, int width
, int height
)
55 { return DoCreate(window
, width
, height
); }
57 bool Create(wxWindowBase
*window
, const wxSize
& size
)
58 { return DoCreate(window
, size
.x
, size
.y
); }
63 // is the caret valid?
64 bool IsOk() const { return m_width
!= 0 && m_height
!= 0; }
66 // get the caret position
67 void GetPosition(int *x
, int *y
) const
72 wxPoint
GetPosition() const { return wxPoint(m_x
, m_y
); }
75 void GetSize(int *width
, int *height
) const
77 if ( width
) *width
= m_width
;
78 if ( height
) *height
= m_height
;
80 wxSize
GetSize() const { return wxSize(m_width
, m_height
); }
82 // get the window we're associated with
83 wxWindow
*GetWindow() const { return (wxWindow
*)m_window
; }
88 // move the caret to given position (in logical coords)
89 void Move(int x
, int y
) { m_x
= x
; m_y
= y
; DoMove(); }
90 void Move(const wxPoint
& pt
) { m_x
= pt
.x
; m_y
= pt
.y
; DoMove(); }
92 // show/hide the caret (should be called by wxWindow when needed):
93 // Show() must be called as many times as Hide() + 1 to make the caret
95 virtual void Show(bool show
= TRUE
)
99 if ( m_countVisible
++ == 0 )
104 if ( --m_countVisible
== 0 )
108 virtual void Hide() { Show(FALSE
); }
110 // blink time is measured in milliseconds and is the time elapsed
111 // between 2 inversions of the caret (blink time of the caret is common
112 // to all carets in the Universe, so these functions are static)
113 static int GetBlinkTime();
114 static void SetBlinkTime(int milliseconds
);
116 // implementation from now on
117 // --------------------------
119 // these functions should be called by wxWindow when the window gets/loses
120 // the focus - we create/show and hide/destroy the caret here
121 virtual void OnSetFocus() { }
122 virtual void OnKillFocus() { }
125 // these functions may be overriden in the derived classes, but they
126 // should call the base class version first
127 virtual bool DoCreate(wxWindowBase
*window
, int width
, int height
)
136 // pure virtuals to implement in the derived class
137 virtual void DoShow() = 0;
138 virtual void DoHide() = 0;
139 virtual void DoMove() = 0;
141 // the common initialization
144 m_window
= (wxWindowBase
*)NULL
;
146 m_width
= m_height
= 0;
150 // the size of the caret
151 int m_width
, m_height
;
153 // the position of the caret
156 // the window we're associated with
157 wxWindowBase
*m_window
;
159 // visibility count: the caret is visible only if it's positive
163 DECLARE_NO_COPY_CLASS(wxCaretBase
);
166 // ---------------------------------------------------------------------------
167 // now include the real thing
168 // ---------------------------------------------------------------------------
171 #include "wx/msw/caret.h"
173 // not implemented yet
174 typedef wxCaretBase wxCaret
;
177 #endif // _WX_CARET_H_BASE_