]>
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_
16 #pragma interface "caret.h"
19 // ---------------------------------------------------------------------------
20 // forward declarations
21 // ---------------------------------------------------------------------------
23 class WXDLLEXPORT wxWindow
;
24 class WXDLLEXPORT wxWindowBase
;
26 // ----------------------------------------------------------------------------
27 // headers we have to include
28 // ----------------------------------------------------------------------------
30 #include "wx/gdicmn.h" // for wxPoint, wxSize
32 // ----------------------------------------------------------------------------
33 // A caret is a blinking cursor showing the position where the typed text will
34 // appear. It can be either a solid block or a custom bitmap (TODO)
35 // ----------------------------------------------------------------------------
37 class WXDLLEXPORT wxCaretBase
42 // default - use Create
43 wxCaretBase() { Init(); }
44 // create the caret of given (in pixels) width and height and associate
45 // with the given window
46 wxCaretBase(wxWindowBase
*window
, int width
, int height
)
50 (void)Create(window
, width
, height
);
53 wxCaretBase(wxWindowBase
*window
, const wxSize
& size
)
57 (void)Create(window
, size
);
60 // Create() functions - same as ctor but returns the success code
61 // --------------------------------------------------------------
64 bool Create(wxWindowBase
*window
, int width
, int height
)
65 { return DoCreate(window
, width
, height
); }
67 bool Create(wxWindowBase
*window
, const wxSize
& size
)
68 { return DoCreate(window
, size
.x
, size
.y
); }
73 // is the caret valid?
74 bool IsOk() const { return m_width
!= 0 && m_height
!= 0; }
76 // is the caret currently shown?
77 bool IsVisible() const { return m_countVisible
> 0; }
79 // get the caret position
80 void GetPosition(int *x
, int *y
) const
85 wxPoint
GetPosition() const { return wxPoint(m_x
, m_y
); }
88 void GetSize(int *width
, int *height
) const
90 if ( width
) *width
= m_width
;
91 if ( height
) *height
= m_height
;
93 wxSize
GetSize() const { return wxSize(m_width
, m_height
); }
95 // get the window we're associated with
96 wxWindow
*GetWindow() const { return (wxWindow
*)m_window
; }
98 // change the size of the caret
99 void SetSize(int width
, int height
) { m_width
= width
; m_height
= height
; }
100 void SetSize(const wxSize
& size
) { SetSize(size
.x
, size
.y
); }
106 // move the caret to given position (in logical coords)
107 void Move(int x
, int y
) { m_x
= x
; m_y
= y
; DoMove(); }
108 void Move(const wxPoint
& pt
) { m_x
= pt
.x
; m_y
= pt
.y
; DoMove(); }
110 // show/hide the caret (should be called by wxWindow when needed):
111 // Show() must be called as many times as Hide() + 1 to make the caret
113 virtual void Show(bool show
= TRUE
)
117 if ( m_countVisible
++ == 0 )
122 if ( --m_countVisible
== 0 )
126 virtual void Hide() { Show(FALSE
); }
128 // blink time is measured in milliseconds and is the time elapsed
129 // between 2 inversions of the caret (blink time of the caret is common
130 // to all carets in the Universe, so these functions are static)
131 static int GetBlinkTime();
132 static void SetBlinkTime(int milliseconds
);
134 // implementation from now on
135 // --------------------------
137 // these functions should be called by wxWindow when the window gets/loses
138 // the focus - we create/show and hide/destroy the caret here
139 virtual void OnSetFocus() { }
140 virtual void OnKillFocus() { }
143 // these functions may be overriden in the derived classes, but they
144 // should call the base class version first
145 virtual bool DoCreate(wxWindowBase
*window
, int width
, int height
)
154 // pure virtuals to implement in the derived class
155 virtual void DoShow() = 0;
156 virtual void DoHide() = 0;
157 virtual void DoMove() = 0;
159 // the common initialization
162 m_window
= (wxWindowBase
*)NULL
;
164 m_width
= m_height
= 0;
168 // the size of the caret
169 int m_width
, m_height
;
171 // the position of the caret
174 // the window we're associated with
175 wxWindowBase
*m_window
;
177 // visibility count: the caret is visible only if it's positive
181 DECLARE_NO_COPY_CLASS(wxCaretBase
);
184 // ---------------------------------------------------------------------------
185 // now include the real thing
186 // ---------------------------------------------------------------------------
188 #if defined(__WXMSW__)
189 #include "wx/msw/caret.h"
191 #include "wx/generic/caret.h"
194 #endif // _WX_CARET_H_BASE_