1999-05-23 19:48:12 -04:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2006-10-30 06:56:12 -05:00
|
|
|
// Name: wx/caret.h
|
1999-05-23 19:48:12 -04:00
|
|
|
// Purpose: wxCaretBase class - the interface of wxCaret
|
|
|
|
// Author: Vadim Zeitlin
|
|
|
|
// Modified by:
|
|
|
|
// Created: 23.05.99
|
|
|
|
// RCS-ID: $Id$
|
2004-05-23 10:56:36 -04:00
|
|
|
// Copyright: (c) wxWidgets team
|
2004-05-23 16:53:33 -04:00
|
|
|
// Licence: wxWindows licence
|
1999-05-23 19:48:12 -04:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#ifndef _WX_CARET_H_BASE_
|
|
|
|
#define _WX_CARET_H_BASE_
|
|
|
|
|
2001-06-26 16:59:19 -04:00
|
|
|
#include "wx/defs.h"
|
|
|
|
|
|
|
|
#if wxUSE_CARET
|
|
|
|
|
1999-05-23 19:48:12 -04:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
// forward declarations
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2007-07-09 06:09:52 -04:00
|
|
|
class WXDLLIMPEXP_FWD_CORE wxWindow;
|
|
|
|
class WXDLLIMPEXP_FWD_CORE wxWindowBase;
|
1999-05-23 19:48:12 -04:00
|
|
|
|
1999-05-25 14:01:48 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// headers we have to include
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#include "wx/gdicmn.h" // for wxPoint, wxSize
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
1999-05-23 19:48:12 -04:00
|
|
|
// A caret is a blinking cursor showing the position where the typed text will
|
|
|
|
// appear. It can be either a solid block or a custom bitmap (TODO)
|
1999-05-25 14:01:48 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
1999-05-23 19:48:12 -04:00
|
|
|
|
2008-03-26 11:06:00 -04:00
|
|
|
class WXDLLIMPEXP_CORE wxCaretBase
|
1999-05-23 19:48:12 -04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
// ctors
|
|
|
|
// -----
|
|
|
|
// default - use Create
|
|
|
|
wxCaretBase() { Init(); }
|
|
|
|
// create the caret of given (in pixels) width and height and associate
|
|
|
|
// with the given window
|
|
|
|
wxCaretBase(wxWindowBase *window, int width, int height)
|
|
|
|
{
|
|
|
|
Init();
|
|
|
|
|
|
|
|
(void)Create(window, width, height);
|
|
|
|
}
|
|
|
|
// same as above
|
|
|
|
wxCaretBase(wxWindowBase *window, const wxSize& size)
|
|
|
|
{
|
|
|
|
Init();
|
|
|
|
|
|
|
|
(void)Create(window, size);
|
|
|
|
}
|
|
|
|
|
2005-02-24 09:33:32 -05:00
|
|
|
// a virtual dtor has been provided since this class has virtual members
|
|
|
|
virtual ~wxCaretBase() { }
|
|
|
|
|
1999-05-23 19:48:12 -04:00
|
|
|
// Create() functions - same as ctor but returns the success code
|
|
|
|
// --------------------------------------------------------------
|
|
|
|
|
|
|
|
// same as ctor
|
|
|
|
bool Create(wxWindowBase *window, int width, int height)
|
|
|
|
{ return DoCreate(window, width, height); }
|
|
|
|
// same as ctor
|
|
|
|
bool Create(wxWindowBase *window, const wxSize& size)
|
|
|
|
{ return DoCreate(window, size.x, size.y); }
|
|
|
|
|
|
|
|
// accessors
|
|
|
|
// ---------
|
|
|
|
|
|
|
|
// is the caret valid?
|
|
|
|
bool IsOk() const { return m_width != 0 && m_height != 0; }
|
|
|
|
|
1999-05-25 14:01:48 -04:00
|
|
|
// is the caret currently shown?
|
|
|
|
bool IsVisible() const { return m_countVisible > 0; }
|
|
|
|
|
1999-05-23 19:48:12 -04:00
|
|
|
// get the caret position
|
|
|
|
void GetPosition(int *x, int *y) const
|
|
|
|
{
|
|
|
|
if ( x ) *x = m_x;
|
|
|
|
if ( y ) *y = m_y;
|
|
|
|
}
|
|
|
|
wxPoint GetPosition() const { return wxPoint(m_x, m_y); }
|
|
|
|
|
|
|
|
// get the caret size
|
|
|
|
void GetSize(int *width, int *height) const
|
|
|
|
{
|
|
|
|
if ( width ) *width = m_width;
|
|
|
|
if ( height ) *height = m_height;
|
|
|
|
}
|
|
|
|
wxSize GetSize() const { return wxSize(m_width, m_height); }
|
|
|
|
|
|
|
|
// get the window we're associated with
|
|
|
|
wxWindow *GetWindow() const { return (wxWindow *)m_window; }
|
|
|
|
|
2000-01-07 00:42:30 -05:00
|
|
|
// change the size of the caret
|
2000-01-10 18:01:19 -05:00
|
|
|
void SetSize(int width, int height) {
|
|
|
|
m_width = width;
|
|
|
|
m_height = height;
|
|
|
|
DoSize();
|
|
|
|
}
|
2000-01-07 00:42:30 -05:00
|
|
|
void SetSize(const wxSize& size) { SetSize(size.x, size.y); }
|
|
|
|
|
|
|
|
|
1999-05-23 19:48:12 -04:00
|
|
|
// operations
|
|
|
|
// ----------
|
|
|
|
|
|
|
|
// move the caret to given position (in logical coords)
|
|
|
|
void Move(int x, int y) { m_x = x; m_y = y; DoMove(); }
|
|
|
|
void Move(const wxPoint& pt) { m_x = pt.x; m_y = pt.y; DoMove(); }
|
|
|
|
|
|
|
|
// show/hide the caret (should be called by wxWindow when needed):
|
|
|
|
// Show() must be called as many times as Hide() + 1 to make the caret
|
|
|
|
// visible
|
2004-09-10 08:56:07 -04:00
|
|
|
virtual void Show(bool show = true)
|
1999-05-23 19:48:12 -04:00
|
|
|
{
|
|
|
|
if ( show )
|
|
|
|
{
|
1999-05-24 17:12:37 -04:00
|
|
|
if ( m_countVisible++ == 0 )
|
1999-05-23 19:48:12 -04:00
|
|
|
DoShow();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
1999-05-24 17:12:37 -04:00
|
|
|
if ( --m_countVisible == 0 )
|
1999-05-23 19:48:12 -04:00
|
|
|
DoHide();
|
|
|
|
}
|
|
|
|
}
|
2004-09-10 08:56:07 -04:00
|
|
|
virtual void Hide() { Show(false); }
|
1999-05-23 19:48:12 -04:00
|
|
|
|
|
|
|
// blink time is measured in milliseconds and is the time elapsed
|
|
|
|
// between 2 inversions of the caret (blink time of the caret is common
|
|
|
|
// to all carets in the Universe, so these functions are static)
|
|
|
|
static int GetBlinkTime();
|
|
|
|
static void SetBlinkTime(int milliseconds);
|
|
|
|
|
|
|
|
// implementation from now on
|
|
|
|
// --------------------------
|
|
|
|
|
|
|
|
// these functions should be called by wxWindow when the window gets/loses
|
|
|
|
// the focus - we create/show and hide/destroy the caret here
|
|
|
|
virtual void OnSetFocus() { }
|
|
|
|
virtual void OnKillFocus() { }
|
|
|
|
|
|
|
|
protected:
|
|
|
|
// these functions may be overriden in the derived classes, but they
|
|
|
|
// should call the base class version first
|
|
|
|
virtual bool DoCreate(wxWindowBase *window, int width, int height)
|
|
|
|
{
|
|
|
|
m_window = window;
|
|
|
|
m_width = width;
|
|
|
|
m_height = height;
|
|
|
|
|
2004-09-10 08:56:07 -04:00
|
|
|
return true;
|
1999-05-23 19:48:12 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// pure virtuals to implement in the derived class
|
|
|
|
virtual void DoShow() = 0;
|
|
|
|
virtual void DoHide() = 0;
|
|
|
|
virtual void DoMove() = 0;
|
2000-01-10 18:01:19 -05:00
|
|
|
virtual void DoSize() { }
|
1999-05-23 19:48:12 -04:00
|
|
|
|
|
|
|
// the common initialization
|
|
|
|
void Init()
|
|
|
|
{
|
2009-01-19 08:55:27 -05:00
|
|
|
m_window = NULL;
|
1999-05-23 19:48:12 -04:00
|
|
|
m_x = m_y = 0;
|
|
|
|
m_width = m_height = 0;
|
|
|
|
m_countVisible = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// the size of the caret
|
|
|
|
int m_width, m_height;
|
|
|
|
|
|
|
|
// the position of the caret
|
|
|
|
int m_x, m_y;
|
|
|
|
|
|
|
|
// the window we're associated with
|
|
|
|
wxWindowBase *m_window;
|
|
|
|
|
|
|
|
// visibility count: the caret is visible only if it's positive
|
|
|
|
int m_countVisible;
|
|
|
|
|
|
|
|
private:
|
2009-02-08 06:45:59 -05:00
|
|
|
wxDECLARE_NO_COPY_CLASS(wxCaretBase);
|
1999-05-23 19:48:12 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
// now include the real thing
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
1999-05-25 14:01:48 -04:00
|
|
|
#if defined(__WXMSW__)
|
1999-05-23 19:48:12 -04:00
|
|
|
#include "wx/msw/caret.h"
|
|
|
|
#else
|
1999-05-25 14:01:48 -04:00
|
|
|
#include "wx/generic/caret.h"
|
1999-05-23 19:48:12 -04:00
|
|
|
#endif // platform
|
|
|
|
|
2000-09-22 18:44:34 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// wxCaretSuspend: a simple class which hides the caret in its ctor and
|
|
|
|
// restores it in the dtor, this should be used when drawing on the screen to
|
|
|
|
// avoid overdrawing the caret
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2006-10-25 08:12:56 -04:00
|
|
|
#ifdef wxHAS_CARET_USING_OVERLAYS
|
2006-10-24 08:29:14 -04:00
|
|
|
|
|
|
|
// we don't need to hide the caret if it's rendered using overlays
|
2008-03-26 11:06:00 -04:00
|
|
|
class WXDLLIMPEXP_CORE wxCaretSuspend
|
2006-10-24 08:29:14 -04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
wxCaretSuspend(wxWindow *WXUNUSED(win)) {}
|
|
|
|
|
2009-02-08 06:45:59 -05:00
|
|
|
wxDECLARE_NO_COPY_CLASS(wxCaretSuspend);
|
2006-10-24 08:29:14 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
#else // !wxHAS_CARET_USING_OVERLAYS
|
|
|
|
|
2008-03-26 11:06:00 -04:00
|
|
|
class WXDLLIMPEXP_CORE wxCaretSuspend
|
2000-09-22 18:44:34 -04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
wxCaretSuspend(wxWindow *win)
|
|
|
|
{
|
|
|
|
m_caret = win->GetCaret();
|
2004-09-10 08:56:07 -04:00
|
|
|
m_show = false;
|
2003-08-11 12:33:56 -04:00
|
|
|
if ( m_caret && m_caret->IsVisible() )
|
|
|
|
{
|
2000-09-22 18:44:34 -04:00
|
|
|
m_caret->Hide();
|
2004-09-10 08:56:07 -04:00
|
|
|
m_show = true;
|
2003-08-11 12:33:56 -04:00
|
|
|
}
|
2000-09-22 18:44:34 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
~wxCaretSuspend()
|
|
|
|
{
|
2003-08-11 12:33:56 -04:00
|
|
|
if ( m_caret && m_show )
|
2000-09-22 18:44:34 -04:00
|
|
|
m_caret->Show();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
wxCaret *m_caret;
|
2003-08-11 12:33:56 -04:00
|
|
|
bool m_show;
|
2003-01-02 18:38:11 -05:00
|
|
|
|
2009-02-08 06:45:59 -05:00
|
|
|
wxDECLARE_NO_COPY_CLASS(wxCaretSuspend);
|
2000-09-22 18:44:34 -04:00
|
|
|
};
|
|
|
|
|
2006-10-24 08:29:14 -04:00
|
|
|
#endif // wxHAS_CARET_USING_OVERLAYS/!wxHAS_CARET_USING_OVERLAYS
|
|
|
|
|
2001-06-26 16:59:19 -04:00
|
|
|
#endif // wxUSE_CARET
|
|
|
|
|
1999-05-23 19:48:12 -04:00
|
|
|
#endif // _WX_CARET_H_BASE_
|