// Created: 15.09.00
// RCS-ID: $Id$
// Copyright: (c) 2000 SciTech Software, Inc. (www.scitechsoft.com)
-// Licence: wxWindows license
+// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
/*
// headers
// ----------------------------------------------------------------------------
-#ifdef __GNUG__
- #pragma implementation "textctrl.h"
+#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
+ #pragma implementation "univtextctrl.h"
#endif
#include "wx/wxprec.h"
#if wxUSE_TEXTCTRL
+#include <ctype.h>
+
#ifndef WX_PRECOMP
#include "wx/log.h"
#include "wx/cmdproc.h"
+#if wxUSE_CLIPBOARD
+#include "wx/dataobj.h"
+#endif
+
// turn extra wxTextCtrl-specific debugging on/off
#define WXDEBUG_TEXT
virtual bool CanUndo() const;
virtual bool Do(wxTextCtrl *text);
+ virtual bool Do() { return wxTextCtrlCommand::Do(); }
+ virtual bool Undo() { return wxTextCtrlCommand::Undo(); }
virtual bool Undo(wxTextCtrl *text);
private:
virtual bool CanUndo() const;
virtual bool Do(wxTextCtrl *text);
+ virtual bool Do() { return wxTextCtrlCommand::Do(); }
+ virtual bool Undo() { return wxTextCtrlCommand::Undo(); }
virtual bool Undo(wxTextCtrl *text);
private:
EVT_CHAR(wxTextCtrl::OnChar)
EVT_SIZE(wxTextCtrl::OnSize)
-
- EVT_IDLE(wxTextCtrl::OnIdle)
END_EVENT_TABLE()
IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl, wxControl)
style |= wxALWAYS_SHOW_SB;
}
+ // wxTE_WORDWRAP is 0 for now so we don't need the code below
+#if 0
if ( style & wxTE_WORDWRAP )
{
// wrapping words means wrapping, hence no horz scrollbar
style &= ~wxHSCROLL;
}
+#endif // 0
// TODO: support wxTE_NO_VSCROLL (?)
// create data object for single line controls
m_data.sdata = new wxTextSingleLineData;
}
+
+#if wxUSE_TWO_WINDOWS
+ if ((style & wxBORDER_MASK) == 0)
+ style |= wxBORDER_SUNKEN;
+#endif
if ( !wxControl::Create(parent, id, pos, size, style,
validator, name) )
CreateInputHandler(wxINP_HANDLER_TEXTCTRL);
+ wxSizeEvent sizeEvent(GetSize(), GetId());
+ GetEventHandler()->ProcessEvent(sizeEvent);
+
return TRUE;
}
}
else // valid sel range
{
+ // remember the 'to' position as the current position, used to move the
+ // caret there later
+ wxTextPos toOrig = to;
+
OrderPositions(from, to);
wxCHECK_RET( to <= GetLastPosition(),
}
//else: nothing to do
- // the insertion point is put at the end of selection
- DoSetInsertionPoint(to);
+ // the insertion point is put at the location where the caret was moved
+ DoSetInsertionPoint(toOrig);
}
}
return m_isEditable && IsEnabled();
}
+void wxTextCtrl::MarkDirty()
+{
+ m_isModified = TRUE;
+}
+
void wxTextCtrl::DiscardEdits()
{
m_isModified = FALSE;
// pos may be -1 to show the current position
void wxTextCtrl::ShowPosition(wxTextPos pos)
{
- HideCaret();
+ bool showCaret = GetCaret() && GetCaret()->IsVisible();
+ if (showCaret)
+ HideCaret();
if ( IsSingleLine() )
{
}
//else: multiline but no scrollbars, hence nothing to do
- ShowCaret();
+ if (showCaret)
+ ShowCaret();
}
// ----------------------------------------------------------------------------
lines = 5;
else if ( lines > 10 )
lines = 10;
- h *= 10;
+ h *= lines;
}
wxRect rectText;
SData().m_colLastVisible += SData().m_colStart;
wxLogTrace(_T("text"), _T("Last visible column/position is %d/%ld"),
- SData().m_colLastVisible, SData().m_posLastVisible);
+ (int) SData().m_colLastVisible, (long) SData().m_posLastVisible);
}
void wxTextCtrl::OnSize(wxSizeEvent& event)
MData().m_updateScrollbarY = FALSE;
}
-void wxTextCtrl::OnIdle(wxIdleEvent& event)
+void wxTextCtrl::OnInternalIdle()
{
// notice that single line text control never has scrollbars
if ( !IsSingleLine() &&
{
UpdateScrollbars();
}
-
- event.Skip();
+ wxControl::OnInternalIdle();
}
bool wxTextCtrl::SendAutoScrollEvents(wxScrollWinEvent& event) const
// the update region is in window coords and text area is in the client
// ones, so it must be shifted before computing intersection
wxRegion rgnUpdate = GetUpdateRegion();
+
wxRect rectTextArea = GetRealTextArea();
wxPoint pt = GetClientAreaOrigin();
wxRect rectTextAreaAdjusted = rectTextArea;
// show caret first time only: we must show it after drawing the text or
// the display can be corrupted when it's hidden
- if ( !m_hasCaret && GetCaret() )
+ if ( !m_hasCaret && GetCaret() && (FindFocus() == this) )
{
ShowCaret();
if ( !wxTextCtrlBase::Enable(enable) )
return FALSE;
- ShowCaret(enable);
+ if (FindFocus() == this && GetCaret() &&
+ ((enable && !GetCaret()->IsVisible()) ||
+ (!enable && GetCaret()->IsVisible())))
+ ShowCaret(enable);
return TRUE;
}
caret->Move(GetCaretPosition());
// and show it there
- caret->Show(show);
+ if ((show && !caret->IsVisible()) ||
+ (!show && caret->IsVisible()))
+ caret->Show(show);
}
}
return pos;
}
-bool wxStdTextCtrlInputHandler::HandleKey(wxControl *control,
+bool wxStdTextCtrlInputHandler::HandleKey(wxInputConsumer *consumer,
const wxKeyEvent& event,
bool pressed)
{
if ( (action != wxACTION_NONE) && (action != wxACTION_TEXT_PREFIX_SEL) )
{
- control->PerformAction(action, -1, str);
+ consumer->PerformAction(action, -1, str);
return TRUE;
}
- return wxStdInputHandler::HandleKey(control, event, pressed);
+ return wxStdInputHandler::HandleKey(consumer, event, pressed);
}
-bool wxStdTextCtrlInputHandler::HandleMouse(wxControl *control,
+bool wxStdTextCtrlInputHandler::HandleMouse(wxInputConsumer *consumer,
const wxMouseEvent& event)
{
if ( event.LeftDown() )
{
wxASSERT_MSG( !m_winCapture, _T("left button going down twice?") );
- wxTextCtrl *text = wxStaticCast(control, wxTextCtrl);
+ wxTextCtrl *text = wxStaticCast(consumer->GetInputWindow(), wxTextCtrl);
m_winCapture = text;
m_winCapture->CaptureMouse();
else if ( event.LeftDClick() )
{
// select the word the cursor is on
- control->PerformAction(wxACTION_TEXT_SEL_WORD);
+ consumer->PerformAction(wxACTION_TEXT_SEL_WORD);
}
else if ( event.LeftUp() )
{
}
}
- return wxStdInputHandler::HandleMouse(control, event);
+ return wxStdInputHandler::HandleMouse(consumer, event);
}
-bool wxStdTextCtrlInputHandler::HandleMouseMove(wxControl *control,
+bool wxStdTextCtrlInputHandler::HandleMouseMove(wxInputConsumer *consumer,
const wxMouseEvent& event)
{
if ( m_winCapture )
}
}
- return wxStdInputHandler::HandleMouseMove(control, event);
+ return wxStdInputHandler::HandleMouseMove(consumer, event);
}
-bool wxStdTextCtrlInputHandler::HandleFocus(wxControl *control,
- const wxFocusEvent& event)
+bool
+wxStdTextCtrlInputHandler::HandleFocus(wxInputConsumer *consumer,
+ const wxFocusEvent& event)
{
- wxTextCtrl *text = wxStaticCast(control, wxTextCtrl);
+ wxTextCtrl *text = wxStaticCast(consumer->GetInputWindow(), wxTextCtrl);
// the selection appearance changes depending on whether we have the focus
text->RefreshSelection();
+ if (event.GetEventType() == wxEVT_SET_FOCUS)
+ {
+ if (text->GetCaret() && !text->GetCaret()->IsVisible())
+ text->ShowCaret();
+ }
+ else
+ {
+ if (text->GetCaret() && text->GetCaret()->IsVisible())
+ text->HideCaret();
+ }
+
// never refresh entirely
return FALSE;
}