]> git.saurik.com Git - wxWidgets.git/blame_incremental - include/wx/caret.h
Made listctrl header BG grey again
[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// 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// ---------------------------------------------------------------------------
26
27class WXDLLEXPORT wxCaretBase
28{
29public:
30 // ctors
31 // -----
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)
37 {
38 Init();
39
40 (void)Create(window, width, height);
41 }
42 // same as above
43 wxCaretBase(wxWindowBase *window, const wxSize& size)
44 {
45 Init();
46
47 (void)Create(window, size);
48 }
49
50 // Create() functions - same as ctor but returns the success code
51 // --------------------------------------------------------------
52
53 // same as ctor
54 bool Create(wxWindowBase *window, int width, int height)
55 { return DoCreate(window, width, height); }
56 // same as ctor
57 bool Create(wxWindowBase *window, const wxSize& size)
58 { return DoCreate(window, size.x, size.y); }
59
60 // accessors
61 // ---------
62
63 // is the caret valid?
64 bool IsOk() const { return m_width != 0 && m_height != 0; }
65
66 // get the caret position
67 void GetPosition(int *x, int *y) const
68 {
69 if ( x ) *x = m_x;
70 if ( y ) *y = m_y;
71 }
72 wxPoint GetPosition() const { return wxPoint(m_x, m_y); }
73
74 // get the caret size
75 void GetSize(int *width, int *height) const
76 {
77 if ( width ) *width = m_width;
78 if ( height ) *height = m_height;
79 }
80 wxSize GetSize() const { return wxSize(m_width, m_height); }
81
82 // get the window we're associated with
83 wxWindow *GetWindow() const { return (wxWindow *)m_window; }
84
85 // operations
86 // ----------
87
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(); }
91
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
94 // visible
95 virtual void Show(bool show = TRUE)
96 {
97 if ( show )
98 {
99 if ( m_countVisible++ == 0 )
100 DoShow();
101 }
102 else
103 {
104 if ( --m_countVisible == 0 )
105 DoHide();
106 }
107 }
108 virtual void Hide() { Show(FALSE); }
109
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);
115
116 // implementation from now on
117 // --------------------------
118
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() { }
123
124protected:
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)
128 {
129 m_window = window;
130 m_width = width;
131 m_height = height;
132
133 return TRUE;
134 }
135
136 // pure virtuals to implement in the derived class
137 virtual void DoShow() = 0;
138 virtual void DoHide() = 0;
139 virtual void DoMove() = 0;
140
141 // the common initialization
142 void Init()
143 {
144 m_window = (wxWindowBase *)NULL;
145 m_x = m_y = 0;
146 m_width = m_height = 0;
147 m_countVisible = 0;
148 }
149
150 // the size of the caret
151 int m_width, m_height;
152
153 // the position of the caret
154 int m_x, m_y;
155
156 // the window we're associated with
157 wxWindowBase *m_window;
158
159 // visibility count: the caret is visible only if it's positive
160 int m_countVisible;
161
162private:
163 DECLARE_NO_COPY_CLASS(wxCaretBase);
164};
165
166// ---------------------------------------------------------------------------
167// now include the real thing
168// ---------------------------------------------------------------------------
169
170#ifdef __WXMSW__
171 #include "wx/msw/caret.h"
172#else
173 // not implemented yet
174 typedef wxCaretBase wxCaret;
175#endif // platform
176
177#endif // _WX_CARET_H_BASE_
178