]> git.saurik.com Git - wxWidgets.git/blame_incremental - include/wx/caret.h
file used to generate setup.h.in
[wxWidgets.git] / include / wx / caret.h
... / ...
CommitLineData
1///////////////////////////////////////////////////////////////////////////////
2// Name: caret.h
3// Purpose: wxCaretBase class - the interface of wxCaret
4// Author: Vadim Zeitlin
5// Modified by:
6// Created: 23.05.99
7// RCS-ID: $Id$
8// Copyright: (c) wxWindows team
9// Licence: wxWindows licence
10///////////////////////////////////////////////////////////////////////////////
11
12#ifndef _WX_CARET_H_BASE_
13#define _WX_CARET_H_BASE_
14
15// ---------------------------------------------------------------------------
16// forward declarations
17// ---------------------------------------------------------------------------
18
19class WXDLLEXPORT wxWindow;
20class WXDLLEXPORT wxWindowBase;
21
22// ----------------------------------------------------------------------------
23// headers we have to include
24// ----------------------------------------------------------------------------
25
26#include "wx/gdicmn.h" // for wxPoint, wxSize
27
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// ----------------------------------------------------------------------------
32
33class WXDLLEXPORT wxCaretBase
34{
35public:
36 // ctors
37 // -----
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)
43 {
44 Init();
45
46 (void)Create(window, width, height);
47 }
48 // same as above
49 wxCaretBase(wxWindowBase *window, const wxSize& size)
50 {
51 Init();
52
53 (void)Create(window, size);
54 }
55
56 // Create() functions - same as ctor but returns the success code
57 // --------------------------------------------------------------
58
59 // same as ctor
60 bool Create(wxWindowBase *window, int width, int height)
61 { return DoCreate(window, width, height); }
62 // same as ctor
63 bool Create(wxWindowBase *window, const wxSize& size)
64 { return DoCreate(window, size.x, size.y); }
65
66 // accessors
67 // ---------
68
69 // is the caret valid?
70 bool IsOk() const { return m_width != 0 && m_height != 0; }
71
72 // is the caret currently shown?
73 bool IsVisible() const { return m_countVisible > 0; }
74
75 // get the caret position
76 void GetPosition(int *x, int *y) const
77 {
78 if ( x ) *x = m_x;
79 if ( y ) *y = m_y;
80 }
81 wxPoint GetPosition() const { return wxPoint(m_x, m_y); }
82
83 // get the caret size
84 void GetSize(int *width, int *height) const
85 {
86 if ( width ) *width = m_width;
87 if ( height ) *height = m_height;
88 }
89 wxSize GetSize() const { return wxSize(m_width, m_height); }
90
91 // get the window we're associated with
92 wxWindow *GetWindow() const { return (wxWindow *)m_window; }
93
94 // operations
95 // ----------
96
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(); }
100
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
103 // visible
104 virtual void Show(bool show = TRUE)
105 {
106 if ( show )
107 {
108 if ( m_countVisible++ == 0 )
109 DoShow();
110 }
111 else
112 {
113 if ( --m_countVisible == 0 )
114 DoHide();
115 }
116 }
117 virtual void Hide() { Show(FALSE); }
118
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);
124
125 // implementation from now on
126 // --------------------------
127
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() { }
132
133protected:
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)
137 {
138 m_window = window;
139 m_width = width;
140 m_height = height;
141
142 return TRUE;
143 }
144
145 // pure virtuals to implement in the derived class
146 virtual void DoShow() = 0;
147 virtual void DoHide() = 0;
148 virtual void DoMove() = 0;
149
150 // the common initialization
151 void Init()
152 {
153 m_window = (wxWindowBase *)NULL;
154 m_x = m_y = 0;
155 m_width = m_height = 0;
156 m_countVisible = 0;
157 }
158
159 // the size of the caret
160 int m_width, m_height;
161
162 // the position of the caret
163 int m_x, m_y;
164
165 // the window we're associated with
166 wxWindowBase *m_window;
167
168 // visibility count: the caret is visible only if it's positive
169 int m_countVisible;
170
171private:
172 DECLARE_NO_COPY_CLASS(wxCaretBase);
173};
174
175// ---------------------------------------------------------------------------
176// now include the real thing
177// ---------------------------------------------------------------------------
178
179#if defined(__WXMSW__)
180 #include "wx/msw/caret.h"
181#else
182 #include "wx/generic/caret.h"
183#endif // platform
184
185#endif // _WX_CARET_H_BASE_
186