]>
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 // headers we have to include
24 // ----------------------------------------------------------------------------
26 #include "wx/gdicmn.h" // for wxPoint, wxSize
28 // ----------------------------------------------------------------------------
29 // A caret is a blinking cursor showing the position where the typed text will
30 // appear. It can be either a solid block or a custom bitmap (TODO)
31 // ----------------------------------------------------------------------------
33 class WXDLLEXPORT wxCaretBase
38 // default - use Create
39 wxCaretBase() { Init(); }
40 // create the caret of given (in pixels) width and height and associate
41 // with the given window
42 wxCaretBase(wxWindowBase
*window
, int width
, int height
)
46 (void)Create(window
, width
, height
);
49 wxCaretBase(wxWindowBase
*window
, const wxSize
& size
)
53 (void)Create(window
, size
);
56 // Create() functions - same as ctor but returns the success code
57 // --------------------------------------------------------------
60 bool Create(wxWindowBase
*window
, int width
, int height
)
61 { return DoCreate(window
, width
, height
); }
63 bool Create(wxWindowBase
*window
, const wxSize
& size
)
64 { return DoCreate(window
, size
.x
, size
.y
); }
69 // is the caret valid?
70 bool IsOk() const { return m_width
!= 0 && m_height
!= 0; }
72 // is the caret currently shown?
73 bool IsVisible() const { return m_countVisible
> 0; }
75 // get the caret position
76 void GetPosition(int *x
, int *y
) const
81 wxPoint
GetPosition() const { return wxPoint(m_x
, m_y
); }
84 void GetSize(int *width
, int *height
) const
86 if ( width
) *width
= m_width
;
87 if ( height
) *height
= m_height
;
89 wxSize
GetSize() const { return wxSize(m_width
, m_height
); }
91 // get the window we're associated with
92 wxWindow
*GetWindow() const { return (wxWindow
*)m_window
; }
97 // move the caret to given position (in logical coords)
98 void Move(int x
, int y
) { m_x
= x
; m_y
= y
; DoMove(); }
99 void Move(const wxPoint
& pt
) { m_x
= pt
.x
; m_y
= pt
.y
; DoMove(); }
101 // show/hide the caret (should be called by wxWindow when needed):
102 // Show() must be called as many times as Hide() + 1 to make the caret
104 virtual void Show(bool show
= TRUE
)
108 if ( m_countVisible
++ == 0 )
113 if ( --m_countVisible
== 0 )
117 virtual void Hide() { Show(FALSE
); }
119 // blink time is measured in milliseconds and is the time elapsed
120 // between 2 inversions of the caret (blink time of the caret is common
121 // to all carets in the Universe, so these functions are static)
122 static int GetBlinkTime();
123 static void SetBlinkTime(int milliseconds
);
125 // implementation from now on
126 // --------------------------
128 // these functions should be called by wxWindow when the window gets/loses
129 // the focus - we create/show and hide/destroy the caret here
130 virtual void OnSetFocus() { }
131 virtual void OnKillFocus() { }
134 // these functions may be overriden in the derived classes, but they
135 // should call the base class version first
136 virtual bool DoCreate(wxWindowBase
*window
, int width
, int height
)
145 // pure virtuals to implement in the derived class
146 virtual void DoShow() = 0;
147 virtual void DoHide() = 0;
148 virtual void DoMove() = 0;
150 // the common initialization
153 m_window
= (wxWindowBase
*)NULL
;
155 m_width
= m_height
= 0;
159 // the size of the caret
160 int m_width
, m_height
;
162 // the position of the caret
165 // the window we're associated with
166 wxWindowBase
*m_window
;
168 // visibility count: the caret is visible only if it's positive
172 DECLARE_NO_COPY_CLASS(wxCaretBase
);
175 // ---------------------------------------------------------------------------
176 // now include the real thing
177 // ---------------------------------------------------------------------------
179 #if defined(__WXMSW__)
180 #include "wx/msw/caret.h"
182 #include "wx/generic/caret.h"
185 #endif // _WX_CARET_H_BASE_