added wxTextEntry common base class for both wxTextCtrl and wxComboBox; refactor wxGTK code to put common parts of these classes in the base class; fixed some inconsistencies in the text control behaviour between platforms

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@48944 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2007-09-26 00:30:22 +00:00
parent c0d9b217a7
commit 0ec1179b86
33 changed files with 1224 additions and 862 deletions

View File

@@ -22,51 +22,33 @@ extern WXDLLEXPORT_DATA(const wxChar) wxComboBoxNameStr[];
// wxComboBoxBase: this interface defines the methods wxComboBox must implement
// ----------------------------------------------------------------------------
#include "wx/textctrl.h"
#include "wx/ctrlsub.h"
#include "wx/textentry.h"
class WXDLLEXPORT wxComboBoxBase : public wxItemContainer
class WXDLLEXPORT wxComboBoxBase : public wxItemContainer,
public wxTextEntry
{
public:
// wxTextCtrl-like methods wxComboBox must implement
virtual wxString GetValue() const = 0;
virtual void SetValue(const wxString& value) = 0;
// override this to disambiguate between two base classes versions
virtual void Clear()
{
wxTextEntry::Clear();
wxItemContainer::Clear();
}
virtual void Copy() = 0;
virtual void Cut() = 0;
virtual void Paste() = 0;
virtual void SetInsertionPoint(long pos) = 0;
virtual long GetInsertionPoint() const = 0;
virtual wxTextPos GetLastPosition() const = 0;
virtual void Replace(long from, long to, const wxString& value) = 0;
virtual void SetSelection(long from, long to) = 0;
virtual void SetEditable(bool editable) = 0;
virtual void SetInsertionPointEnd()
{ SetInsertionPoint(GetLastPosition()); }
virtual void Remove(long from, long to)
{ Replace(from, to, wxEmptyString); }
virtual bool IsEditable() const = 0;
virtual void Undo() = 0;
virtual void Redo() = 0;
virtual void SelectAll() = 0;
virtual bool CanCopy() const = 0;
virtual bool CanCut() const = 0;
virtual bool CanPaste() const = 0;
virtual bool CanUndo() const = 0;
virtual bool CanRedo() const = 0;
// also bring in GetSelection() versions of both base classes in scope
//
// NB: GetSelection(from, to) could be already implemented in wxTextEntry
// but still make it pure virtual because for some platforms it's not
// implemented there and also because the derived class has to override
// it anyhow to avoid ambiguity with the other GetSelection()
virtual int GetSelection() const = 0;
virtual void GetSelection(long *from, long *to) const = 0;
// may return value different from GetSelection() when the combobox
// dropdown is shown and the user selected, but not yet accepted, a value
// different from the old one in it
virtual int GetCurrentSelection() const { return GetSelection(); }
// redeclare inherited SetSelection() overload here as well to avoid
// virtual function hiding
virtual void SetSelection(int n) = 0;
};
// ----------------------------------------------------------------------------
@@ -93,5 +75,4 @@ public:
#endif // wxUSE_COMBOBOX
#endif
// _WX_COMBOBOX_H_BASE_
#endif // _WX_COMBOBOX_H_BASE_

View File

@@ -73,7 +73,7 @@ public:
bool SetStringSelection(const wxString& s);
// return the selected string or empty string if none
wxString GetStringSelection() const;
virtual wxString GetStringSelection() const;
// this is the same as SetSelection( for single-selection controls but
// reads better for multi-selection ones

View File

@@ -203,7 +203,9 @@ public:
#endif // wxUSE_MENUS
protected:
virtual void DoSetValue(const wxString& value, int flags = 0);
virtual void DoSetValue(const wxString& value, int flags);
virtual bool DoLoadFile(const wxString& file, int fileType);
virtual bool DoSaveFile(const wxString& file, int fileType);
// override the base class virtuals involved into geometry calculations
virtual wxSize DoGetBestSize() const;

View File

@@ -15,29 +15,32 @@
// wxComboBox
//-----------------------------------------------------------------------------
class WXDLLIMPEXP_CORE wxComboBox : public wxControl, public wxComboBoxBase
class WXDLLIMPEXP_CORE wxComboBox : public wxControl,
public wxComboBoxBase
{
public:
inline wxComboBox() { m_strings = NULL; }
inline wxComboBox(wxWindow *parent, wxWindowID id,
const wxString& value = wxEmptyString,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
int n = 0, const wxString choices[] = (const wxString *) NULL,
long style = 0,
const wxValidator& validator = wxDefaultValidator,
const wxString& name = wxComboBoxNameStr)
wxComboBox() { m_strings = NULL; }
wxComboBox(wxWindow *parent,
wxWindowID id,
const wxString& value = wxEmptyString,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
int n = 0, const wxString choices[] = NULL,
long style = 0,
const wxValidator& validator = wxDefaultValidator,
const wxString& name = wxComboBoxNameStr)
{
Create(parent, id, value, pos, size, n, choices, style, validator, name);
}
inline wxComboBox(wxWindow *parent, wxWindowID id,
const wxString& value,
const wxPoint& pos,
const wxSize& size,
const wxArrayString& choices,
long style = 0,
const wxValidator& validator = wxDefaultValidator,
const wxString& name = wxComboBoxNameStr)
wxComboBox(wxWindow *parent, wxWindowID id,
const wxString& value,
const wxPoint& pos,
const wxSize& size,
const wxArrayString& choices,
long style = 0,
const wxValidator& validator = wxDefaultValidator,
const wxString& name = wxComboBoxNameStr)
{
Create(parent, id, value, pos, size, choices, style, validator, name);
}
@@ -45,21 +48,21 @@ public:
virtual ~wxComboBox();
bool Create(wxWindow *parent, wxWindowID id,
const wxString& value = wxEmptyString,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
int n = 0, const wxString choices[] = (const wxString *) NULL,
long style = 0,
const wxValidator& validator = wxDefaultValidator,
const wxString& name = wxComboBoxNameStr);
const wxString& value = wxEmptyString,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
int n = 0, const wxString choices[] = (const wxString *) NULL,
long style = 0,
const wxValidator& validator = wxDefaultValidator,
const wxString& name = wxComboBoxNameStr);
bool Create(wxWindow *parent, wxWindowID id,
const wxString& value,
const wxPoint& pos,
const wxSize& size,
const wxArrayString& choices,
long style = 0,
const wxValidator& validator = wxDefaultValidator,
const wxString& name = wxComboBoxNameStr);
const wxString& value,
const wxPoint& pos,
const wxSize& size,
const wxArrayString& choices,
long style = 0,
const wxValidator& validator = wxDefaultValidator,
const wxString& name = wxComboBoxNameStr);
// From wxItemContainerImmutable:
virtual unsigned int GetCount() const;
@@ -68,40 +71,26 @@ public:
virtual int FindString(const wxString& s, bool bCase = false) const;
virtual void SetSelection(int n);
virtual int GetSelection() const;
wxString GetStringSelection() const; // not a virtual in parent class
// From wxItemContainer:
virtual void DoClear();
virtual void DoDeleteOneItem(unsigned int n);
// from wxTextEntry: we need to override them to avoid virtual function
// hiding
virtual void SetSelection(long from, long to)
{
wxTextEntry::SetSelection(from, to);
}
// From wxBomboBoxBase:
virtual wxString GetValue() const;
virtual void SetValue(const wxString& value);
virtual void Copy();
virtual void Cut();
virtual void Paste();
virtual void SetInsertionPoint( long pos );
virtual long GetInsertionPoint() const;
virtual wxTextPos GetLastPosition() const;
virtual void Replace( long from, long to, const wxString& value );
virtual void SetSelection( long from, long to );
virtual void SetEditable( bool editable );
virtual void SetInsertionPointEnd() { SetInsertionPoint( -1 ); }
virtual void Remove(long from, long to) { Replace(from, to, wxEmptyString); }
virtual bool IsEditable() const;
virtual void Undo();
virtual void Redo();
virtual void SelectAll();
virtual bool CanCopy() const;
virtual bool CanCut() const;
virtual bool CanPaste() const;
virtual bool CanUndo() const;
virtual bool CanRedo() const;
virtual void GetSelection(long *from, long *to) const
{
return wxTextEntry::GetSelection(from, to);
}
// implementation
bool HasSelection() const;
void GetSelection( long* from, long* to ) const;
int GetCurrentSelection() const;
virtual wxString GetStringSelection() const
{
return wxItemContainer::GetStringSelection();
}
// From wxComboBoxBase:
virtual int GetCurrentSelection() const;
virtual void SetFocus();
@@ -150,10 +139,23 @@ protected:
virtual void DoSetItemClientData(unsigned int n, void* clientData);
virtual void* DoGetItemClientData(unsigned int n) const;
virtual bool IsSorted() const { return HasFlag(wxCB_SORT); }
virtual void DoClear();
virtual void DoDeleteOneItem(unsigned int n);
// From wxControl:
virtual wxSize DoGetBestSize() const;
// From wxTextEntry:
virtual const wxWindow *GetEditableWindow() const { return this; }
virtual GtkEditable *GetEditable() const;
virtual void EnableTextChangedEvents(bool enable)
{
if ( enable )
EnableEvents();
else
DisableEvents();
}
// Widgets that use the style->base colour for the BG colour should
// override this and return true.
virtual bool UseGTKStyleBase() const { return true; }

View File

@@ -44,6 +44,7 @@ public:
// implement base class pure virtuals
// ----------------------------------
virtual void WriteText(const wxString& text);
virtual wxString GetValue() const;
virtual bool IsEmpty() const;
@@ -54,30 +55,13 @@ public:
virtual bool IsModified() const;
virtual bool IsEditable() const;
// If the return values from and to are the same, there is no selection.
virtual void GetSelection(long* from, long* to) const;
// operations
// ----------
// editing
virtual void Clear();
virtual void Replace(long from, long to, const wxString& value);
virtual void Remove(long from, long to);
// sets/clears the dirty flag
virtual void MarkDirty();
virtual void DiscardEdits();
virtual void SetMaxLength(unsigned long len);
// writing text inserts it at the current position, appending always
// inserts it at the end
virtual void WriteText(const wxString& text);
virtual void AppendText(const wxString& text);
// apply text attribute to the range of text (only works with richedit
// controls)
virtual bool SetStyle(long start, long end, const wxTextAttr& style);
// translate between the position (which is just an index in the text ctrl
@@ -101,16 +85,8 @@ public:
virtual void Cut();
virtual void Paste();
// Undo/redo
virtual void Undo();
virtual void Redo();
virtual bool CanUndo() const;
virtual bool CanRedo() const;
// Insertion point
virtual void SetInsertionPoint(long pos);
virtual void SetInsertionPointEnd();
virtual long GetInsertionPoint() const;
virtual wxTextPos GetLastPosition() const;
@@ -181,10 +157,16 @@ public:
bool IsFrozen() const { return m_freezeCount > 0; }
protected:
// overridden wxWindow virtual methods
virtual wxSize DoGetBestSize() const;
virtual void DoApplyWidgetStyle(GtkRcStyle *style);
virtual GdkWindow *GTKGetWindow(wxArrayGdkWindows& windows) const;
// overridden wxTextEntry virtual methods
virtual const wxWindow *GetEditableWindow() const { return this; }
virtual GtkEditable *GetEditable() const;
virtual void EnableTextChangedEvents(bool enable);
// common part of all ctors
void Init();

View File

@@ -0,0 +1,69 @@
///////////////////////////////////////////////////////////////////////////////
// Name: wx/gtk/textentry.h
// Purpose: wxGTK-specific wxTextEntry implementation
// Author: Vadim Zeitlin
// Created: 2007-09-24
// RCS-ID: $Id$
// Copyright: (c) 2007 Vadim Zeitlin <vadim@wxwindows.org>
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
#ifndef _WX_GTK_TEXTENTRY_H_
#define _WX_GTK_TEXTENTRY_H_
typedef struct _GtkEditable GtkEditable;
// ----------------------------------------------------------------------------
// wxTextEntry: roughly corresponds to GtkEditable
// ----------------------------------------------------------------------------
class WXDLLIMPEXP_CORE wxTextEntry : public wxTextEntryBase
{
public:
wxTextEntry() { }
// implement wxTextEntryBase pure virtual methods
virtual void WriteText(const wxString& text);
virtual wxString GetValue() const;
virtual void Remove(long from, long to);
virtual void Copy();
virtual void Cut();
virtual void Paste();
virtual void Undo();
virtual void Redo();
virtual bool CanUndo() const;
virtual bool CanRedo() const;
virtual void SetInsertionPoint(long pos);
virtual long GetInsertionPoint() const;
virtual long GetLastPosition() const;
virtual void SetSelection(long from, long to);
virtual void GetSelection(long *from, long *to) const;
// status
virtual bool IsEditable() const;
virtual void SetEditable(bool editable);
// set the max number of characters which may be entered in a single line
// text control
virtual void SetMaxLength(unsigned long len);
// implementation only from now on
void SendMaxLenEvent();
private:
// implement this to return the associated window, it will be used for
// event generation
virtual const wxWindow *GetEditableWindow() const = 0;
// implement this to return the associated GtkEntry or another widget
// implementing GtkEditable
virtual GtkEditable *GetEditable() const = 0;
};
#endif // _WX_GTK_TEXTENTRY_H_

View File

@@ -96,8 +96,10 @@ class WXDLLEXPORT wxComboBox : public wxControl, public wxComboBoxBase
virtual void SetString(unsigned int n, const wxString& s);
// Text field functions
virtual wxString GetValue() const;
virtual void SetValue(const wxString& value);
virtual wxString GetValue() const;
virtual void WriteText(const wxString& text);
virtual void GetSelection(long *from, long *to) const;
// Clipboard operations
virtual void Copy();

View File

@@ -84,7 +84,8 @@ class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextStyleDefinition;
* wxRichTextCtrl class declaration
*/
class WXDLLIMPEXP_RICHTEXT wxRichTextCtrl : public wxTextCtrlBase,
class WXDLLIMPEXP_RICHTEXT wxRichTextCtrl : public wxControl,
public wxTextCtrlIface,
public wxScrollHelper
{
DECLARE_CLASS( wxRichTextCtrl )

View File

@@ -27,6 +27,9 @@
////@begin forward declarations
class wxSymbolListCtrl;
class WXDLLIMPEXP_CORE wxTextCtrl;
////@end forward declarations
// __UNICODE__ is a symbol used by DialogBlocks-generated code.

View File

@@ -27,7 +27,10 @@
// no native version, use the generic one
#define wxUSE_NATIVE_SEARCH_CONTROL 0
#define wxSearchCtrlBaseBaseClass wxTextCtrlBase
class WXDLLIMPEXP_CORE wxSearchCtrlBaseBaseClass : public wxControl,
public wxTextCtrlIface
{
};
#endif
// ----------------------------------------------------------------------------

View File

@@ -21,6 +21,7 @@
#if wxUSE_TEXTCTRL
#include "wx/control.h" // the base class
#include "wx/textentry.h" // single-line text entry interface
#include "wx/dynarray.h" // wxArrayInt
#include "wx/gdicmn.h" // wxPoint
@@ -46,9 +47,6 @@ class WXDLLIMPEXP_FWD_CORE wxTextCtrlBase;
// wxTextCtrl types
// ----------------------------------------------------------------------------
// wxTextPos is the position in the text
typedef long wxTextPos;
// wxTextCoord is the line or row number (which should have been unsigned but
// is long for backwards compatibility)
typedef long wxTextCoord;
@@ -272,69 +270,35 @@ private:
};
// ----------------------------------------------------------------------------
// wxTextCtrl: a single or multiple line text zone where user can enter and
// edit text
// wxTextAreaBase: multiline text control specific methods
// ----------------------------------------------------------------------------
class WXDLLEXPORT wxTextCtrlBase : public wxControl
#if wxHAS_TEXT_WINDOW_STREAM
, public wxSTD streambuf
#endif
class WXDLLIMPEXP_CORE wxTextAreaBase
{
public:
// creation
// --------
wxTextAreaBase() { }
virtual ~wxTextAreaBase() { }
wxTextCtrlBase(){}
virtual ~wxTextCtrlBase(){}
// accessors
// ---------
virtual wxString GetValue() const = 0;
virtual bool IsEmpty() const { return GetValue().empty(); }
virtual void SetValue(const wxString& value)
{ DoSetValue(value, SetValue_SendEvent); }
virtual void ChangeValue(const wxString& value)
{ DoSetValue(value); }
virtual wxString GetRange(long from, long to) const;
// lines access
// ------------
virtual int GetLineLength(long lineNo) const = 0;
virtual wxString GetLineText(long lineNo) const = 0;
virtual int GetNumberOfLines() const = 0;
// file IO
// -------
bool LoadFile(const wxString& file, int fileType = wxTEXT_TYPE_ANY)
{ return DoLoadFile(file, fileType); }
bool SaveFile(const wxString& file = wxEmptyString,
int fileType = wxTEXT_TYPE_ANY);
// dirty flag handling
// -------------------
virtual bool IsModified() const = 0;
virtual bool IsEditable() const = 0;
// more readable flag testing methods
bool IsSingleLine() const { return !HasFlag(wxTE_MULTILINE); }
bool IsMultiLine() const { return !IsSingleLine(); }
// If the return values from and to are the same, there is no selection.
virtual void GetSelection(long* from, long* to) const = 0;
virtual wxString GetStringSelection() const;
// operations
// ----------
// editing
virtual void Clear() = 0;
virtual void Replace(long from, long to, const wxString& value) = 0;
virtual void Remove(long from, long to) = 0;
// load/save the control's contents from/to a file
bool LoadFile(const wxString& file, int fileType = wxTEXT_TYPE_ANY) { return DoLoadFile(file, fileType); }
bool SaveFile(const wxString& file = wxEmptyString, int fileType = wxTEXT_TYPE_ANY);
// implementation for loading/saving
virtual bool DoLoadFile(const wxString& file, int fileType);
virtual bool DoSaveFile(const wxString& file, int fileType);
// sets/clears the dirty flag
virtual void MarkDirty() = 0;
virtual void DiscardEdits() = 0;
void SetModified(bool modified)
@@ -345,26 +309,21 @@ public:
DiscardEdits();
}
// set the max number of characters which may be entered in a single line
// text control
virtual void SetMaxLength(unsigned long WXUNUSED(len)) { }
// writing text inserts it at the current position, appending always
// inserts it at the end
virtual void WriteText(const wxString& text) = 0;
virtual void AppendText(const wxString& text) = 0;
// insert the character which would have resulted from this key event,
// return true if anything has been inserted
virtual bool EmulateKeyPress(const wxKeyEvent& event);
// styles handling
// ---------------
// text control under some platforms supports the text styles: these
// methods allow to apply the given text style to the given selection or to
// set/get the style which will be used for all appended text
virtual bool SetStyle(long start, long end, const wxTextAttr& style);
virtual bool GetStyle(long position, wxTextAttr& style);
virtual bool SetDefaultStyle(const wxTextAttr& style);
virtual const wxTextAttr& GetDefaultStyle() const;
virtual bool SetStyle(long start, long end, const wxTextAttr& style) = 0;
virtual bool GetStyle(long position, wxTextAttr& style) = 0;
virtual bool SetDefaultStyle(const wxTextAttr& style) = 0;
virtual const wxTextAttr& GetDefaultStyle() const { return m_defaultStyle; }
// coordinates translation
// -----------------------
// translate between the position (which is just an index in the text ctrl
// considering all its contents as a single strings) and (x, y) coordinates
@@ -383,31 +342,60 @@ public:
wxTextCoord *col,
wxTextCoord *row) const;
// Clipboard operations
virtual void Copy() = 0;
virtual void Cut() = 0;
virtual void Paste() = 0;
protected:
// implementation of loading/saving
virtual bool DoLoadFile(const wxString& file, int fileType) = 0;
virtual bool DoSaveFile(const wxString& file, int fileType) = 0;
virtual bool CanCopy() const;
virtual bool CanCut() const;
virtual bool CanPaste() const;
// Undo/redo
virtual void Undo() = 0;
virtual void Redo() = 0;
// the name of the last file loaded with LoadFile() which will be used by
// SaveFile() by default
wxString m_filename;
virtual bool CanUndo() const = 0;
virtual bool CanRedo() const = 0;
// the text style which will be used for any new text added to the control
wxTextAttr m_defaultStyle;
// Insertion point
virtual void SetInsertionPoint(long pos) = 0;
virtual void SetInsertionPointEnd() = 0;
virtual long GetInsertionPoint() const = 0;
virtual wxTextPos GetLastPosition() const = 0;
virtual void SetSelection(long from, long to) = 0;
virtual void SelectAll();
virtual void SetEditable(bool editable) = 0;
DECLARE_NO_COPY_CLASS(wxTextAreaBase)
};
// this class defines wxTextCtrl interface, wxTextCtrlBase actually implements
// too much things because it derives from wxTextEntry and not wxTextEntryBase
// and so any classes which "look like" wxTextCtrl (such as wxRichTextCtrl)
// but don't need the (native) implementation bits from wxTextEntry should
// actually derive from this one and not wxTextCtrlBase
class WXDLLIMPEXP_CORE wxTextCtrlIface : public wxTextAreaBase,
public wxTextEntryBase
{
public:
wxTextCtrlIface() { }
private:
DECLARE_NO_COPY_CLASS(wxTextCtrlIface)
};
// ----------------------------------------------------------------------------
// wxTextCtrl: a single or multiple line text zone where user can edit text
// ----------------------------------------------------------------------------
class WXDLLEXPORT wxTextCtrlBase : public wxControl,
#if wxHAS_TEXT_WINDOW_STREAM
public wxSTD streambuf,
#endif
public wxTextAreaBase,
public wxTextEntry
{
public:
// creation
// --------
wxTextCtrlBase() { }
virtual ~wxTextCtrlBase() { }
// more readable flag testing methods
bool IsSingleLine() const { return !HasFlag(wxTE_MULTILINE); }
bool IsMultiLine() const { return !IsSingleLine(); }
// stream-like insertion operators: these are always available, whether we
// were, or not, compiled with streambuf support
@@ -418,37 +406,49 @@ public:
wxTextCtrl& operator<<(double d);
wxTextCtrl& operator<<(const wxChar c);
// insert the character which would have resulted from this key event,
// return true if anything has been inserted
virtual bool EmulateKeyPress(const wxKeyEvent& event);
// generate the wxEVT_COMMAND_TEXT_UPDATED event, like SetValue() does
void SendTextUpdatedEvent();
static void SendTextUpdatedEvent(wxWindow *win);
void SendTextUpdatedEvent() { SendTextUpdatedEvent(this); }
// do the window-specific processing after processing the update event
virtual void DoUpdateWindowUI(wxUpdateUIEvent& event);
virtual bool ShouldInheritColours() const { return false; }
// work around the problem with having HitTest() both in wxControl and
// wxTextAreaBase base classes
virtual wxTextCtrlHitTestResult HitTest(const wxPoint& pt, long *pos) const
{
return wxTextAreaBase::HitTest(pt, pos);
}
virtual wxTextCtrlHitTestResult HitTest(const wxPoint& pt,
wxTextCoord *col,
wxTextCoord *row) const
{
return wxTextAreaBase::HitTest(pt, col, row);
}
// we provide stubs for these functions as not all platforms have styles
// support, but we really should leave them pure virtual here
virtual bool SetStyle(long start, long end, const wxTextAttr& style);
virtual bool GetStyle(long position, wxTextAttr& style);
virtual bool SetDefaultStyle(const wxTextAttr& style);
protected:
// override streambuf method
#if wxHAS_TEXT_WINDOW_STREAM
int overflow(int i);
#endif // wxHAS_TEXT_WINDOW_STREAM
// flags for DoSetValue(): common part of SetValue() and ChangeValue() and
// also used to implement WriteText() in wxMSW
enum
{
SetValue_SendEvent = 1,
SetValue_SelectionOnly = 2
};
virtual bool DoLoadFile(const wxString& file, int fileType);
virtual bool DoSaveFile(const wxString& file, int fileType);
virtual void DoSetValue(const wxString& value, int flags = 0) = 0;
// the name of the last file loaded with LoadFile() which will be used by
// SaveFile() by default
wxString m_filename;
// the text style which will be used for any new text added to the control
wxTextAttr m_defaultStyle;
DECLARE_NO_COPY_CLASS(wxTextCtrlBase)
DECLARE_ABSTRACT_CLASS(wxTextCtrlBase)

191
include/wx/textentry.h Normal file
View File

@@ -0,0 +1,191 @@
///////////////////////////////////////////////////////////////////////////////
// Name: wx/textentry.h
// Purpose: declares wxTextEntry interface defining a simple text entry
// Author: Vadim Zeitlin
// Created: 2007-09-24
// RCS-ID: $Id$
// Copyright: (c) 2007 Vadim Zeitlin <vadim@wxwindows.org>
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
#ifndef _WX_TEXTENTRY_H_
#define _WX_TEXTENTRY_H_
// wxTextPos is the position in the text (currently it's hardly used anywhere
// and should probably be replaced with int anyhow)
typedef long wxTextPos;
// ----------------------------------------------------------------------------
// wxTextEntryBase
// ----------------------------------------------------------------------------
class WXDLLIMPEXP_CORE wxTextEntryBase
{
public:
wxTextEntryBase() { m_eventsBlock = 0; }
virtual ~wxTextEntryBase() { }
// accessing the value
// -------------------
// SetValue() generates a text change event, ChangeValue() doesn't
virtual void SetValue(const wxString& value)
{ DoSetValue(value, SetValue_SendEvent); }
virtual void ChangeValue(const wxString& value)
{ DoSetValue(value, SetValue_NoEvent); }
// writing text inserts it at the current position replacing any current
// selection, appending always inserts it at the end and doesn't remove any
// existing text (but it will reset the selection if there is any)
virtual void WriteText(const wxString& text) = 0;
virtual void AppendText(const wxString& text);
virtual wxString GetValue() const = 0;
virtual wxString GetRange(long from, long to) const;
bool IsEmpty() const { return GetValue().empty(); }
// editing operations
// ------------------
virtual void Replace(long from, long to, const wxString& value);
virtual void Remove(long from, long to) = 0;
virtual void Clear() { SetValue(wxString()); }
// clipboard operations
// --------------------
virtual void Copy() = 0;
virtual void Cut() = 0;
virtual void Paste() = 0;
virtual bool CanCopy() const;
virtual bool CanCut() const;
virtual bool CanPaste() const;
// undo/redo
// ---------
virtual void Undo() = 0;
virtual void Redo() = 0;
virtual bool CanUndo() const = 0;
virtual bool CanRedo() const = 0;
// insertion point
// ---------------
// note that moving insertion point removes any current selection
virtual void SetInsertionPoint(long pos) = 0;
virtual void SetInsertionPointEnd() { SetInsertionPoint(-1); }
virtual long GetInsertionPoint() const = 0;
virtual long GetLastPosition() const = 0;
// selection
// ---------
virtual void SetSelection(long from, long to) = 0;
virtual void SelectAll() { SetSelection(0, GetLastPosition()); }
virtual void GetSelection(long *from, long *to) const = 0;
bool HasSelection() const;
virtual wxString GetStringSelection() const;
// status
// ------
virtual bool IsEditable() const = 0;
virtual void SetEditable(bool editable) = 0;
// set the max number of characters which may be entered in a single line
// text control
virtual void SetMaxLength(unsigned long WXUNUSED(len)) { }
protected:
// flags for DoSetValue(): common part of SetValue() and ChangeValue() and
// also used to implement WriteText() in wxMSW
enum
{
SetValue_NoEvent = 0,
SetValue_SendEvent = 1,
SetValue_SelectionOnly = 2
};
virtual void DoSetValue(const wxString& value, int flags);
// class which should be used to temporarily disable text change events
//
// if suppress argument in ctor is false, nothing is done
class EventsSuppressor
{
public:
EventsSuppressor(wxTextEntryBase *text, bool suppress = true)
{
m_suppress = suppress;
if ( m_suppress )
{
m_text = text;
m_text->SuppressTextChangedEvents();
}
}
~EventsSuppressor()
{
if ( m_suppress )
m_text->ResumeTextChangedEvents();
}
private:
wxTextEntryBase *m_text;
bool m_suppress;
};
// return true if the events are currently not suppressed
bool EventsAllowed() const { return m_eventsBlock == 0; }
private:
// suppress or resume the text changed events generation: don't use these
// functions directly, use EventsSuppressor class above instead
void SuppressTextChangedEvents()
{
if ( !m_eventsBlock++ )
EnableTextChangedEvents(false);
}
void ResumeTextChangedEvents()
{
if ( !--m_eventsBlock )
EnableTextChangedEvents(true);
}
// this must be overridden in the derived classes if our implementation of
// SetValue() or Replace() is used to disable (and enable back) generation
// of the text changed events
//
// initially the generation of the events is enabled
virtual void EnableTextChangedEvents(bool WXUNUSED(enable)) { }
friend class EventsSuppressor;
// if this counter is non-null, events are blocked
unsigned m_eventsBlock;
};
#ifdef __WXGTK20__
#include "wx/gtk/textentry.h"
#else
// no platform-specific implementation of wxTextEntry yet
class WXDLLIMPEXP_CORE wxTextEntry : public wxTextEntryBase
{
};
#endif
#endif // _WX_TEXTENTRY_H_

View File

@@ -93,6 +93,7 @@ public:
// wxTextCtrl methods
virtual wxString GetValue() const;
virtual void SetValue(const wxString& value);
virtual void WriteText(const wxString& value);
virtual void Copy();
virtual void Cut();
virtual void Paste();
@@ -103,6 +104,7 @@ public:
virtual void Replace(long from, long to, const wxString& value);
virtual void Remove(long from, long to);
virtual void SetSelection(long from, long to);
virtual void GetSelection(long *from, long *to) const;
virtual void SetEditable(bool editable);
virtual bool IsEditable() const;
@@ -125,6 +127,7 @@ public:
virtual int FindString(const wxString& s, bool bCase = false) const;
virtual void SetSelection(int n);
virtual int GetSelection() const;
virtual wxString GetStringSelection() const;
wxCONTROL_ITEMCONTAINER_CLIENTDATAOBJECT_RECAST