1. some minor but nasty bugs fixed (see post to the list)

2. new wxCaret class (MSW only so far)


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@2547 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
1999-05-23 23:48:12 +00:00
parent c52d95b412
commit 789295bf7b
21 changed files with 746 additions and 292 deletions

178
include/wx/caret.h Normal file
View File

@@ -0,0 +1,178 @@
///////////////////////////////////////////////////////////////////////////////
// Name: caret.h
// Purpose: wxCaretBase class - the interface of wxCaret
// Author: Vadim Zeitlin
// Modified by:
// Created: 23.05.99
// RCS-ID: $Id$
// Copyright: (c) wxWindows team
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
#ifndef _WX_CARET_H_BASE_
#define _WX_CARET_H_BASE_
// ---------------------------------------------------------------------------
// forward declarations
// ---------------------------------------------------------------------------
class WXDLLEXPORT wxWindow;
class WXDLLEXPORT wxWindowBase;
// ---------------------------------------------------------------------------
// 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)
// ---------------------------------------------------------------------------
class WXDLLEXPORT wxCaretBase
{
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);
}
// 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; }
// 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; }
// 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
virtual void Show(bool show = TRUE)
{
if ( show )
{
if ( ++m_countVisible > 0 )
DoShow();
}
else
{
if ( --m_countVisible < 1 )
DoHide();
}
}
virtual void Hide() { Show(FALSE); }
// 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;
return TRUE;
}
// pure virtuals to implement in the derived class
virtual void DoShow() = 0;
virtual void DoHide() = 0;
virtual void DoMove() = 0;
// the common initialization
void Init()
{
m_window = (wxWindowBase *)NULL;
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:
DECLARE_NO_COPY_CLASS(wxCaretBase);
};
// ---------------------------------------------------------------------------
// now include the real thing
// ---------------------------------------------------------------------------
#ifdef __WXMSW__
#include "wx/msw/caret.h"
#else
// not implemented yet
typedef wxCaretBase wxCaret;
#endif // platform
#endif // _WX_CARET_H_BASE_

65
include/wx/msw/caret.h Normal file
View File

@@ -0,0 +1,65 @@
///////////////////////////////////////////////////////////////////////////////
// Name: msw/caret.h
// Purpose: wxCaret class - the MSW implementation of wxCaret
// Author: Vadim Zeitlin
// Modified by:
// Created: 23.05.99
// RCS-ID: $Id$
// Copyright: (c) wxWindows team
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
#ifndef _WX_CARET_H_
#define _WX_CARET_H_
#ifdef __GNUG__
#pragma interface "caret.h"
#endif
class WXDLLEXPORT wxCaret : public wxCaretBase
{
public:
wxCaret() { Init(); }
// create the caret of given (in pixels) width and height and associate
// with the given window
wxCaret(wxWindow *window, int width, int height)
{
Init();
(void)Create(window, width, height);
}
// same as above
wxCaret(wxWindowBase *window, const wxSize& size)
{
wxCaretBase::Init();
(void)Create(window, size);
}
// process wxWindow notifications
virtual void OnSetFocus();
virtual void OnKillFocus();
protected:
void Init()
{
wxCaretBase::Init();
m_hasCaret = FALSE;
}
// override base class virtuals
virtual void DoMove();
virtual void DoShow();
virtual void DoHide();
// helper function which creates the system caret
bool MSWCreateCaret();
private:
bool m_hasCaret;
};
#endif // _WX_CARET_H_

View File

@@ -71,6 +71,8 @@
#define wxUSE_SCROLLBAR 1
// Define 1 to compile contributed wxScrollBar class
#define wxUSE_CARET 1
// Define 1 to use wxCaret class
#define wxUSE_XPM_IN_MSW 1
// Define 1 to support the XPM package in wxBitmap.
#define wxUSE_IMAGE_LOADING_IN_MSW 1

View File

@@ -190,9 +190,13 @@ protected:
wxString m_fileName;
// call this to increase the size limit (will do nothing if the current
// limit is big enough)
void AdjustSpaceLimit();
virtual void DoSetSize(int x, int y,
int width, int height,
int sizeFlags = wxSIZE_AUTO);
int width, int height,
int sizeFlags = wxSIZE_AUTO);
private:
DECLARE_EVENT_TABLE()

View File

@@ -144,13 +144,16 @@ public:
virtual void OnDefaultAction(wxControl * WXUNUSED(initiatingItem)) { }
#endif // WXWIN_COMPATIBILITY
// caret manipulation (MSW only)
virtual void CreateCaret(int w, int h);
virtual void CreateCaret(const wxBitmap *bitmap);
virtual void DestroyCaret();
virtual void ShowCaret(bool show);
virtual void SetCaretPos(int x, int y);
virtual void GetCaretPos(int *x, int *y) const;
#if wxUSE_CARET
// caret manipulation (old MSW only functions, see wxCaret class for the
// new API)
void CreateCaret(int w, int h);
void CreateCaret(const wxBitmap *bitmap);
void DestroyCaret();
void ShowCaret(bool show);
void SetCaretPos(int x, int y);
void GetCaretPos(int *x, int *y) const;
#endif // wxUSE_CARET
// Native resource loading (implemented in src/msw/nativdlg.cpp)
// FIXME: should they really be all virtual?
@@ -374,12 +377,6 @@ protected:
bool m_doubleClickAllowed:1;
bool m_winCaptured:1;
// Caret data
bool m_caretEnabled:1;
bool m_caretShown:1;
int m_caretWidth;
int m_caretHeight;
// the size of one page for scrolling
int m_xThumbSize;
int m_yThumbSize;

View File

@@ -1,6 +1,6 @@
///////////////////////////////////////////////////////////////////////////////
// Name: window.h
// Purpose: wxWindowBase class - the interface of wxWindowBase
// Purpose: wxWindowBase class - the interface of wxWindow
// Author: Vadim Zeitlin
// Modified by:
// Created: 01/02/97
@@ -34,6 +34,7 @@
// forward declarations
// ----------------------------------------------------------------------------
class WXDLLEXPORT wxCaret;
class WXDLLEXPORT wxClientData;
class WXDLLEXPORT wxControl;
class WXDLLEXPORT wxCursor;
@@ -475,6 +476,13 @@ public:
const wxFont& GetFont() const { return m_font; }
wxFont& GetFont() { return m_font; }
#if wxUSE_CARET
// associate a caret with the window
void SetCaret(wxCaret *caret);
// get the current caret (may be NULL)
wxCaret *GetCaret() const { return m_caret; }
#endif // wxUSE_CARET
// get the (average) character size for the current font
virtual int GetCharHeight() const = 0;
virtual int GetCharWidth() const = 0;
@@ -658,6 +666,10 @@ protected:
wxFont m_font;
wxColour m_backgroundColour, m_foregroundColour;
#if wxUSE_CARET
wxCaret *m_caret;
#endif // wxUSE_CARET
// the region which should be repainted in response to paint event
wxRegion m_updateRegion;