const wxValidator& validator = wxDefaultValidator,
const wxString& name = wxTextCtrlNameStr);
- // implement base class pure virtuals
- // ----------------------------------
+ // overridden wxTextEntry methods
+ // ------------------------------
virtual wxString GetValue() const;
+ virtual wxString GetRange(long from, long to) const;
+
virtual bool IsEmpty() const;
- virtual wxString GetRange(long from, long to) const;
+ virtual void WriteText(const wxString& text);
+ virtual void AppendText(const wxString& text);
+ virtual void Clear();
virtual int GetLineLength(long lineNo) const;
virtual wxString GetLineText(long lineNo) const;
virtual int GetNumberOfLines() const;
- virtual bool IsModified() const;
- virtual bool IsEditable() const;
+ virtual void SetMaxLength(unsigned long len);
- virtual void GetSelection(long* from, long* to) const;
+ virtual void GetSelection(long *from, long *to) const;
- // operations
- // ----------
+ virtual void Redo();
+ virtual bool CanRedo() const;
- // editing
- virtual void Clear();
- virtual void Replace(long from, long to, const wxString& value);
- virtual void Remove(long from, long to);
+ virtual void SetInsertionPointEnd();
+ virtual long GetInsertionPoint() const;
+ virtual wxTextPos GetLastPosition() const;
+
+ // implement base class pure virtuals
+ // ----------------------------------
- // load the control's contents from the file
virtual bool DoLoadFile(const wxString& file, int fileType);
- // clears the dirty flag
+ virtual bool IsModified() const;
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);
-
#ifdef __WIN32__
virtual bool EmulateKeyPress(const wxKeyEvent& event);
#endif // __WIN32__
return wxTextCtrlBase::HitTest(pt, col, row);
}
- // Clipboard operations
- virtual void Copy();
- virtual void Cut();
- virtual void Paste();
-
- virtual bool CanCopy() const;
- virtual bool CanCut() const;
- virtual bool CanPaste() const;
-
- // 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;
-
- virtual void SetSelection(long from, long to);
- virtual void SetEditable(bool editable);
-
// Caret handling (Windows only)
-
bool ShowNativeCaret(bool show = true);
bool HideNativeCaret() { return ShowNativeCaret(false); }
virtual void AdoptAttributesFromHWND();
- virtual bool AcceptsFocus() const;
+ virtual bool AcceptsFocusFromKeyboard() const;
// returns true if the platform should explicitly apply a theme border
virtual bool CanApplyThemeBorder() const;
virtual void DoSetValue(const wxString &value, int flags = 0);
+ // implement wxTextEntry pure virtual: it implements all the operations for
+ // the simple EDIT controls
+ virtual WXHWND GetEditHWND() const { return m_hWnd; }
+
// return true if this control has a user-set limit on amount of text (i.e.
// the limit is due to a previous call to SetMaxLength() and not built in)
bool HasSpaceLimit(unsigned int *len) const;
void DoWriteText(const wxString& text,
int flags = SetValue_SendEvent | SetValue_SelectionOnly);
- // set the selection possibly without scrolling the caret into view
- void DoSetSelection(long from, long to, bool scrollCaret = true);
+ // set the selection (possibly without scrolling the caret into view)
+ void DoSetSelection(long from, long to, int flags);
// return true if there is a non empty selection in the control
bool HasSelection() const;
// text ourselves: we want this to be exactly 1
int m_updatesCount;
+ virtual void EnableTextChangedEvents(bool enable)
+ {
+ m_updatesCount = enable ? -1 : -2;
+ }
+
private:
DECLARE_EVENT_TABLE()
DECLARE_DYNAMIC_CLASS_NO_COPY(wxTextCtrl)
};
-#endif
- // _WX_TEXTCTRL_H_
+#endif // _WX_TEXTCTRL_H_
--- /dev/null
+///////////////////////////////////////////////////////////////////////////////\r
+// Name: wx/msw/textentry.h\r
+// Purpose: wxMSW-specific wxTextEntry implementation\r
+// Author: Vadim Zeitlin\r
+// Created: 2007-09-26\r
+// RCS-ID: $Id: textentry.h 48944 2007-09-26 00:30:22Z VZ $\r
+// Copyright: (c) 2007 Vadim Zeitlin <vadim@wxwindows.org>\r
+// Licence: wxWindows licence\r
+///////////////////////////////////////////////////////////////////////////////\r
+\r
+#ifndef _WX_MSW_TEXTENTRY_H_\r
+#define _WX_MSW_TEXTENTRY_H_\r
+\r
+// ----------------------------------------------------------------------------\r
+// wxTextEntry: common part of wxComboBox and (single line) wxTextCtrl\r
+// ----------------------------------------------------------------------------\r
+\r
+class WXDLLIMPEXP_CORE wxTextEntry : public wxTextEntryBase\r
+{\r
+public:\r
+ wxTextEntry() { }\r
+\r
+ // implement wxTextEntryBase pure virtual methods\r
+ virtual void WriteText(const wxString& text);\r
+ virtual wxString GetValue() const;\r
+ virtual void Remove(long from, long to);\r
+\r
+ virtual void Copy();\r
+ virtual void Cut();\r
+ virtual void Paste();\r
+\r
+ virtual void Undo();\r
+ virtual void Redo();\r
+ virtual bool CanUndo() const;\r
+ virtual bool CanRedo() const;\r
+\r
+ virtual void SetInsertionPoint(long pos);\r
+ virtual long GetInsertionPoint() const;\r
+ virtual long GetLastPosition() const;\r
+\r
+ virtual void SetSelection(long from, long to)\r
+ { DoSetSelection(from, to); }\r
+ virtual void GetSelection(long *from, long *to) const;\r
+\r
+ virtual bool IsEditable() const;\r
+ virtual void SetEditable(bool editable);\r
+\r
+ virtual void SetMaxLength(unsigned long len);\r
+\r
+protected:\r
+ // this is really a hook for multiline text controls as the single line\r
+ // ones don't need to ever scroll to show the selection but having it here\r
+ // allows us to put Remove() in the base class\r
+ enum\r
+ {\r
+ SetSel_NoScroll = 0, // don't do anything special\r
+ SetSel_Scroll = 1 // default: scroll to make the selection visible\r
+ };\r
+ virtual void DoSetSelection(long from, long to, int flags = SetSel_Scroll);\r
+\r
+private:\r
+ // implement this to return the HWND of the EDIT control\r
+ virtual WXHWND GetEditHWND() const = 0;\r
+};\r
+\r
+#endif // _WX_MSW_TEXTENTRY_H_\r
+\r
virtual bool EmulateKeyPress(const wxKeyEvent& event);
- // generate the wxEVT_COMMAND_TEXT_UPDATED event, like SetValue() does
- static void SendTextUpdatedEvent(wxWindow *win);
- void SendTextUpdatedEvent() { SendTextUpdatedEvent(this); }
+ // generate the wxEVT_COMMAND_TEXT_UPDATED event, like SetValue() does and
+ // return true if the event was processed
+ static bool SendTextUpdatedEvent(wxWindow *win);
+ bool SendTextUpdatedEvent() { return SendTextUpdatedEvent(this); }
// do the window-specific processing after processing the update event
virtual void DoUpdateWindowUI(wxUpdateUIEvent& event);
#ifdef __WXGTK20__
#include "wx/gtk/textentry.h"
+#elif defined(__WXMSW__)
+ #include "wx/msw/textentry.h"
#else
// no platform-specific implementation of wxTextEntry yet
class WXDLLIMPEXP_CORE wxTextEntry : public wxTextEntryBase
// ----------------------------------------------------------------------------
/* static */
-void wxTextCtrlBase::SendTextUpdatedEvent(wxWindow *win)
+bool wxTextCtrlBase::SendTextUpdatedEvent(wxWindow *win)
{
wxCommandEvent event(wxEVT_COMMAND_TEXT_UPDATED, win->GetId());
//event.SetString(win->GetValue());
event.SetEventObject(win);
- win->GetEventHandler()->ProcessEvent(event);
+ return win->GetEventHandler()->ProcessEvent(event);
}
#else // !wxUSE_TEXTCTRL
#endif //WX_PRECOMP
#include "wx/textentry.h"
+#include "wx/clipbrd.h"
// ============================================================================
// wxTextEntryBase implementation
bool wxTextEntryBase::CanPaste() const
{
- return IsEditable();
+ if ( IsEditable() )
+ {
+#if wxUSE_CLIPBOARD
+ // check if there is any text on the clipboard
+ if ( wxTheClipboard->IsSupported(wxDF_TEXT) )
+ return true;
+#endif // wxUSE_CLIPBOARD
+ }
+
+ return false;
}
#endif // wxUSE_TEXTCTRL || wxUSE_COMBOBOX
{
// this function should not be called for wxCB_READONLY controls, it is
// the callers responsability to check this
- wxASSERT_MSG( !(GetWindowStyle() & wxCB_READONLY),
+ wxASSERT_MSG( !HasFlag(wxCB_READONLY),
_T("read-only combobox doesn't have any edit control") );
POINT pt;
HWND hwndEdit = ::ChildWindowFromPoint(GetHwnd(), pt);
if ( !hwndEdit || hwndEdit == GetHwnd() )
{
- wxFAIL_MSG(_T("not read only combobox without edit control?"));
+ wxFAIL_MSG(_T("combobox without edit control?"));
}
return (WXHWND)hwndEdit;
// wxComboBox text control-like methods
// ----------------------------------------------------------------------------
-wxString wxComboBox::GetValue() const
-{
- return wxGetWindowText(m_hWnd);
-}
-
void wxComboBox::SetValue(const wxString& value)
{
if ( HasFlag(wxCB_READONLY) )
SetStringSelection(value);
else
- SetWindowText(GetHwnd(), value.c_str());
-}
-
-// Clipboard operations
-void wxComboBox::Copy()
-{
- SendMessage(GetHwnd(), WM_COPY, 0, 0L);
-}
-
-void wxComboBox::Cut()
-{
- SendMessage(GetHwnd(), WM_CUT, 0, 0L);
-}
-
-void wxComboBox::Paste()
-{
- SendMessage(GetHwnd(), WM_PASTE, 0, 0L);
-}
-
-void wxComboBox::Undo()
-{
- if (CanUndo())
- {
- HWND hEditWnd = (HWND) GetEditHWND();
- if ( hEditWnd )
- ::SendMessage(hEditWnd, EM_UNDO, 0, 0);
- }
-}
-
-void wxComboBox::Redo()
-{
- if (CanUndo())
- {
- // Same as Undo, since Undo undoes the undo, i.e. a redo.
- HWND hEditWnd = (HWND) GetEditHWND();
- if ( hEditWnd )
- ::SendMessage(hEditWnd, EM_UNDO, 0, 0);
- }
-}
-
-void wxComboBox::SelectAll()
-{
- SetSelection(0, GetLastPosition());
-}
-
-bool wxComboBox::CanUndo() const
-{
- if (!IsEditable())
- return false;
-
- HWND hEditWnd = (HWND) GetEditHWND();
- if ( hEditWnd )
- return ::SendMessage(hEditWnd, EM_CANUNDO, 0, 0) != 0;
- else
- return false;
-}
-
-bool wxComboBox::CanRedo() const
-{
- if (!IsEditable())
- return false;
-
- HWND hEditWnd = (HWND) GetEditHWND();
- if ( hEditWnd )
- return ::SendMessage(hEditWnd, EM_CANUNDO, 0, 0) != 0;
- else
- return false;
-}
-
-bool wxComboBox::HasSelection() const
-{
- long from, to;
- GetSelection(&from, &to);
- return from != to;
-}
-
-bool wxComboBox::CanCopy() const
-{
- // Can copy if there's a selection
- return HasSelection();
-}
-
-bool wxComboBox::CanCut() const
-{
- return IsEditable() && CanCopy();
-}
-
-bool wxComboBox::CanPaste() const
-{
- if ( !IsEditable() )
- return false;
-
- // Standard edit control: check for straight text on clipboard
- if ( !::OpenClipboard(GetHwndOf(wxTheApp->GetTopWindow())) )
- return false;
-
- bool isTextAvailable = ::IsClipboardFormatAvailable(CF_TEXT) != 0;
- ::CloseClipboard();
-
- return isTextAvailable;
+ wxTextEntry::SetValue(value);
}
bool wxComboBox::IsEditable() const
{
- return !HasFlag(wxCB_READONLY);
-}
-
-void wxComboBox::SetEditable(bool editable)
-{
- HWND hWnd = (HWND)GetEditHWND();
- if ( !::SendMessage(hWnd, EM_SETREADONLY, !editable, 0) )
- {
- wxLogLastError(_T("SendMessage(EM_SETREADONLY)"));
- }
-}
-
-void wxComboBox::SetInsertionPoint(long pos)
-{
- if ( GetWindowStyle() & wxCB_READONLY )
- return;
-
- HWND hWnd = GetHwnd();
- ::SendMessage(hWnd, CB_SETEDITSEL, 0, MAKELPARAM(pos, pos));
- HWND hEditWnd = (HWND) GetEditHWND();
- if ( hEditWnd )
- {
- // Scroll insertion point into view
- SendMessage(hEditWnd, EM_SCROLLCARET, (WPARAM)0, (LPARAM)0);
- // Why is this necessary? (Copied from wxTextCtrl::SetInsertionPoint)
- SendMessage(hEditWnd, EM_REPLACESEL, 0, (LPARAM) wxEmptyString);
- }
-}
-
-void wxComboBox::SetInsertionPointEnd()
-{
- // setting insertion point doesn't make sense for read only comboboxes
- if ( !(GetWindowStyle() & wxCB_READONLY) )
- {
- wxTextPos pos = GetLastPosition();
- SetInsertionPoint(pos);
- }
-}
-
-long wxComboBox::GetInsertionPoint() const
-{
- // CB_GETEDITSEL returns the index of the first character of the selection in
- // its low-order word
- DWORD pos= (DWORD)::SendMessage(GetHwnd(), CB_GETEDITSEL, 0, 0L);
- return LOWORD(pos);
-}
-
-wxTextPos wxComboBox::GetLastPosition() const
-{
- HWND hEditWnd = (HWND) GetEditHWND();
-
- // Get number of characters in the last (only) line. We'll add this to the character
- // index for the last line, 1st position.
- wxTextPos lineLength = (wxTextPos)SendMessage(hEditWnd, EM_LINELENGTH, (WPARAM) 0, (LPARAM)0L);
-
- return lineLength;
-}
-
-void wxComboBox::Replace(long from, long to, const wxString& value)
-{
-#if wxUSE_CLIPBOARD
- Remove(from, to);
-
- // Now replace with 'value', by pasting.
- wxSetClipboardData(wxDF_TEXT, (wxObject *)value.wx_str(), 0, 0);
-
- // Paste into edit control
- SendMessage(GetHwnd(), WM_PASTE, (WPARAM)0, (LPARAM)0L);
-#else
- wxUnusedVar(from);
- wxUnusedVar(to);
- wxUnusedVar(value);
-#endif
-}
-
-void wxComboBox::Remove(long from, long to)
-{
- // Set selection and remove it
- SetSelection(from, to);
- SendMessage(GetHwnd(), WM_CUT, (WPARAM)0, (LPARAM)0);
-}
-
-void wxComboBox::SetSelection(long from, long to)
-{
- // if from and to are both -1, it means (in wxWidgets) that all text should
- // be selected, translate this into Windows convention
- if ( (from == -1) && (to == -1) )
- {
- from = 0;
- }
-
- if ( SendMessage(GetHwnd(), CB_SETEDITSEL,
- 0, (LPARAM)MAKELONG(from, to)) == CB_ERR )
- {
- wxLogDebug(_T("CB_SETEDITSEL failed"));
- }
-}
-
-void wxComboBox::GetSelection(long* from, long* to) const
-{
- DWORD dwStart, dwEnd;
- if ( ::SendMessage(GetHwnd(), CB_GETEDITSEL,
- (WPARAM)&dwStart, (LPARAM)&dwEnd) == CB_ERR )
- {
- *from =
- *to = 0;
- }
- else
- {
- *from = dwStart;
- *to = dwEnd;
- }
+ return !HasFlag(wxCB_READONLY) && wxTextEntry::IsEditable();
}
// ----------------------------------------------------------------------------
{
long msStyle = wxControl::MSWGetStyle(style, exstyle);
- // styles which we alaways add by default
+ // styles which we always add by default
if ( style & wxTE_MULTILINE )
{
msStyle |= ES_MULTILINE | ES_WANTRETURN;
void wxTextCtrl::AppendText(const wxString& text)
{
- SetInsertionPointEnd();
-
- WriteText(text);
+ wxTextEntry::AppendText(text);
#if wxUSE_RICHEDIT
// don't do this if we're frozen, saves some time
{
::SetWindowText(GetHwnd(), wxEmptyString);
-#if wxUSE_RICHEDIT
- if ( !IsRich() )
-#endif // wxUSE_RICHEDIT
+ if ( IsMultiLine() && !IsRich() )
{
// rich edit controls send EN_UPDATE from WM_SETTEXT handler themselves
// but the normal ones don't -- make Clear() behaviour consistent by
// always sending this event
-
- // Windows already sends an update event for single-line
- // controls.
- if ( m_windowStyle & wxTE_MULTILINE )
- SendUpdateEvent();
+ SendUpdateEvent();
}
}
#endif // __WIN32__
-// ----------------------------------------------------------------------------
-// Clipboard operations
-// ----------------------------------------------------------------------------
-
-void wxTextCtrl::Copy()
-{
- if (CanCopy())
- {
- ::SendMessage(GetHwnd(), WM_COPY, 0, 0L);
- }
-}
-
-void wxTextCtrl::Cut()
-{
- if (CanCut())
- {
- ::SendMessage(GetHwnd(), WM_CUT, 0, 0L);
- }
-}
-
-void wxTextCtrl::Paste()
-{
- if (CanPaste())
- {
- ::SendMessage(GetHwnd(), WM_PASTE, 0, 0L);
- }
-}
-
-bool wxTextCtrl::HasSelection() const
-{
- long from, to;
- GetSelection(&from, &to);
- return from != to;
-}
-
-bool wxTextCtrl::CanCopy() const
-{
- // Can copy if there's a selection
- return HasSelection();
-}
-
-bool wxTextCtrl::CanCut() const
-{
- return CanCopy() && IsEditable();
-}
-
-bool wxTextCtrl::CanPaste() const
-{
- if ( !IsEditable() )
- return false;
-
-#if wxUSE_RICHEDIT
- if ( IsRich() )
- {
- UINT cf = 0; // 0 == any format
-
- return ::SendMessage(GetHwnd(), EM_CANPASTE, cf, 0) != 0;
- }
-#endif // wxUSE_RICHEDIT
-
- // Standard edit control: check for straight text on clipboard
- if ( !::OpenClipboard(GetHwndOf(wxTheApp->GetTopWindow())) )
- return false;
-
- bool isTextAvailable = ::IsClipboardFormatAvailable(CF_TEXT) != 0;
- ::CloseClipboard();
-
- return isTextAvailable;
-}
-
// ----------------------------------------------------------------------------
// Accessors
// ----------------------------------------------------------------------------
-void wxTextCtrl::SetEditable(bool editable)
-{
- HWND hWnd = GetHwnd();
- ::SendMessage(hWnd, EM_SETREADONLY, (WPARAM)!editable, (LPARAM)0L);
-}
-
-void wxTextCtrl::SetInsertionPoint(long pos)
-{
- DoSetSelection(pos, pos);
-}
-
void wxTextCtrl::SetInsertionPointEnd()
{
// we must not do anything if the caret is already there because calling
return;
}
- long pos;
-
-#if wxUSE_RICHEDIT
- if ( m_verRichEdit == 1 )
- {
- // we don't have to waste time calling GetLastPosition() in this case
- pos = -1;
- }
- else // !RichEdit 1.0
-#endif // wxUSE_RICHEDIT
- {
- pos = lastPosition;
- }
-
- SetInsertionPoint(pos);
+ SetInsertionPoint(lastPosition);
}
long wxTextCtrl::GetInsertionPoint() const
}
#endif // wxUSE_RICHEDIT
- DWORD Pos = (DWORD)::SendMessage(GetHwnd(), EM_GETSEL, 0, 0L);
- return Pos & 0xFFFF;
+ return wxTextEntry::GetInsertionPoint();
}
wxTextPos wxTextCtrl::GetLastPosition() const
{
- int numLines = GetNumberOfLines();
- long posStartLastLine = XYToPosition(0, numLines - 1);
+ if ( IsMultiLine() )
+ {
+ int numLines = GetNumberOfLines();
+ long posStartLastLine = XYToPosition(0, numLines - 1);
- long lenLastLine = GetLengthOfLineContainingPos(posStartLastLine);
+ long lenLastLine = GetLengthOfLineContainingPos(posStartLastLine);
- return posStartLastLine + lenLastLine;
+ return posStartLastLine + lenLastLine;
+ }
+
+ return wxTextEntry::GetLastPosition();
}
// If the return values from and to are the same, there is no
// selection.
-void wxTextCtrl::GetSelection(long* from, long* to) const
+void wxTextCtrl::GetSelection(long *from, long *to) const
{
#if wxUSE_RICHEDIT
if ( IsRich() )
else
#endif // !wxUSE_RICHEDIT
{
- DWORD dwStart, dwEnd;
- ::SendMessage(GetHwnd(), EM_GETSEL, (WPARAM)&dwStart, (LPARAM)&dwEnd);
-
- *from = dwStart;
- *to = dwEnd;
+ wxTextEntry::GetSelection(from, to);
}
}
-bool wxTextCtrl::IsEditable() const
-{
- // strangely enough, we may be called before the control is created: our
- // own Create() calls MSWGetStyle() which calls AcceptsFocus() which calls
- // us
- if ( !m_hWnd )
- return true;
-
- long style = ::GetWindowLong(GetHwnd(), GWL_STYLE);
-
- return (style & ES_READONLY) == 0;
-}
-
// ----------------------------------------------------------------------------
// selection
// ----------------------------------------------------------------------------
-void wxTextCtrl::SetSelection(long from, long to)
-{
- // if from and to are both -1, it means (in wxWidgets) that all text should
- // be selected - translate into Windows convention
- if ( (from == -1) && (to == -1) )
- {
- from = 0;
- to = -1;
- }
-
- DoSetSelection(from, to);
-}
-
-void wxTextCtrl::DoSetSelection(long from, long to, bool scrollCaret)
+void wxTextCtrl::DoSetSelection(long from, long to, int flags)
{
HWND hWnd = GetHwnd();
CHARRANGE range;
range.cpMin = from;
range.cpMax = to;
- ::SendMessage(hWnd, EM_EXSETSEL, 0, (LPARAM) &range);
+ ::SendMessage(hWnd, EM_EXSETSEL, 0, (LPARAM)&range);
}
else
#endif // wxUSE_RICHEDIT
{
- ::SendMessage(hWnd, EM_SETSEL, (WPARAM)from, (LPARAM)to);
+ ::SendMessage(hWnd, EM_SETSEL, from, to);
}
- if ( scrollCaret && !IsFrozen() )
+ if ( (flags & SetSel_Scroll) && !IsFrozen() )
{
#if wxUSE_RICHEDIT
// richedit 3.0 (i.e. the version living in riched20.dll distributed
}
#endif // wxUSE_RICHEDIT
- ::SendMessage(hWnd, EM_SCROLLCARET, (WPARAM)0, (LPARAM)0);
+ ::SendMessage(hWnd, EM_SCROLLCARET, 0, (LPARAM)0);
#if wxUSE_RICHEDIT
// restore ECO_NOHIDESEL if we changed it
}
// ----------------------------------------------------------------------------
-// Editing
+// dirty status
// ----------------------------------------------------------------------------
-void wxTextCtrl::Replace(long from, long to, const wxString& value)
-{
- // Set selection and remove it
- DoSetSelection(from, to, false /* don't scroll caret into view */);
-
- DoWriteText(value);
-}
-
-void wxTextCtrl::Remove(long from, long to)
-{
- Replace(from, to, wxEmptyString);
-}
-
bool wxTextCtrl::IsModified() const
{
return ::SendMessage(GetHwnd(), EM_GETMODIFY, 0, 0) != 0;
void wxTextCtrl::MarkDirty()
{
- ::SendMessage(GetHwnd(), EM_SETMODIFY, TRUE, 0L);
+ ::SendMessage(GetHwnd(), EM_SETMODIFY, TRUE, 0);
}
void wxTextCtrl::DiscardEdits()
{
- ::SendMessage(GetHwnd(), EM_SETMODIFY, FALSE, 0L);
-}
-
-int wxTextCtrl::GetNumberOfLines() const
-{
- return (int)::SendMessage(GetHwnd(), EM_GETLINECOUNT, (WPARAM)0, (LPARAM)0);
+ ::SendMessage(GetHwnd(), EM_SETMODIFY, FALSE, 0);
}
// ----------------------------------------------------------------------------
// Positions <-> coords
// ----------------------------------------------------------------------------
+int wxTextCtrl::GetNumberOfLines() const
+{
+ return (int)::SendMessage(GetHwnd(), EM_GETLINECOUNT, 0, 0);
+}
+
long wxTextCtrl::XYToPosition(long x, long y) const
{
// This gets the char index for the _beginning_ of this line
- long charIndex = ::SendMessage(GetHwnd(), EM_LINEINDEX, (WPARAM)y, (LPARAM)0);
+ long charIndex = ::SendMessage(GetHwnd(), EM_LINEINDEX, y, 0);
return charIndex + x;
}
#if wxUSE_RICHEDIT
if ( IsRich() )
{
- lineNo = ::SendMessage(hWnd, EM_EXLINEFROMCHAR, 0, (LPARAM)pos);
+ lineNo = ::SendMessage(hWnd, EM_EXLINEFROMCHAR, 0, pos);
}
else
#endif // wxUSE_RICHEDIT
{
- lineNo = ::SendMessage(hWnd, EM_LINEFROMCHAR, (WPARAM)pos, 0);
+ lineNo = ::SendMessage(hWnd, EM_LINEFROMCHAR, pos, 0);
}
if ( lineNo == -1 )
}
// This gets the char index for the _beginning_ of this line
- long charIndex = ::SendMessage(hWnd, EM_LINEINDEX, (WPARAM)lineNo, (LPARAM)0);
+ long charIndex = ::SendMessage(hWnd, EM_LINEINDEX, lineNo, 0);
if ( charIndex == -1 )
{
return false;
// Is this where scrolling is relative to - the line containing the caret?
// Or is the first visible line??? Try first visible line.
-// int currentLineLineNo1 = (int)::SendMessage(hWnd, EM_LINEFROMCHAR, (WPARAM)-1, (LPARAM)0L);
+// int currentLineLineNo1 = (int)::SendMessage(hWnd, EM_LINEFROMCHAR, -1, 0L);
- int currentLineLineNo = (int)::SendMessage(hWnd, EM_GETFIRSTVISIBLELINE, (WPARAM)0, (LPARAM)0L);
+ int currentLineLineNo = (int)::SendMessage(hWnd, EM_GETFIRSTVISIBLELINE, 0, 0);
- int specifiedLineLineNo = (int)::SendMessage(hWnd, EM_LINEFROMCHAR, (WPARAM)pos, (LPARAM)0L);
+ int specifiedLineLineNo = (int)::SendMessage(hWnd, EM_LINEFROMCHAR, pos, 0);
int linesToScroll = specifiedLineLineNo - currentLineLineNo;
if (linesToScroll != 0)
- (void)::SendMessage(hWnd, EM_LINESCROLL, (WPARAM)0, (LPARAM)linesToScroll);
+ ::SendMessage(hWnd, EM_LINESCROLL, 0, linesToScroll);
}
long wxTextCtrl::GetLengthOfLineContainingPos(long pos) const
{
- return ::SendMessage(GetHwnd(), EM_LINELENGTH, (WPARAM)pos, 0);
+ return ::SendMessage(GetHwnd(), EM_LINELENGTH, pos, 0);
}
int wxTextCtrl::GetLineLength(long lineNo) const
else
#endif // wxUSE_RICHEDIT
{
- if ( len >= 0xffff )
- {
- // this will set it to a platform-dependent maximum (much more
- // than 64Kb under NT)
- len = 0;
- }
-
- ::SendMessage(GetHwnd(), EM_LIMITTEXT, len, 0);
+ wxTextEntry::SetMaxLength(len);
}
}
// Undo/redo
// ----------------------------------------------------------------------------
-void wxTextCtrl::Undo()
-{
- if (CanUndo())
- {
- ::SendMessage(GetHwnd(), EM_UNDO, 0, 0);
- }
-}
-
void wxTextCtrl::Redo()
{
- if (CanRedo())
- {
#if wxUSE_RICHEDIT
- if (GetRichVersion() > 1)
- ::SendMessage(GetHwnd(), EM_REDO, 0, 0);
- else
-#endif
- // Same as Undo, since Undo undoes the undo, i.e. a redo.
- ::SendMessage(GetHwnd(), EM_UNDO, 0, 0);
+ if ( GetRichVersion() > 1 )
+ {
+ ::SendMessage(GetHwnd(), EM_REDO, 0, 0);
+ return;
}
-}
+#endif // wxUSE_RICHEDIT
-bool wxTextCtrl::CanUndo() const
-{
- return ::SendMessage(GetHwnd(), EM_CANUNDO, 0, 0) != 0;
+ wxTextEntry::Redo();
}
bool wxTextCtrl::CanRedo() const
{
#if wxUSE_RICHEDIT
- if (GetRichVersion() > 1)
+ if ( GetRichVersion() > 1 )
return ::SendMessage(GetHwnd(), EM_CANREDO, 0, 0) != 0;
- else
-#endif
- return ::SendMessage(GetHwnd(), EM_CANUNDO, 0, 0) != 0;
+#endif // wxUSE_RICHEDIT
+
+ return wxTextEntry::CanRedo();
}
// ----------------------------------------------------------------------------
if ( !(show ? ::ShowCaret(GetHwnd()) : ::HideCaret(GetHwnd())) )
{
// not an error, may simply indicate that it's not shown/hidden
- // yet (i.e. it had been hidden/showh 2 times before)
+ // yet (i.e. it had been hidden/shown 2 times before)
return false;
}
}
// ----------------------------------------------------------------------------
-// implemenation details
+// implementation details
// ----------------------------------------------------------------------------
void wxTextCtrl::Command(wxCommandEvent & event)
return false;
}
- wxCommandEvent event(wxEVT_COMMAND_TEXT_UPDATED, GetId());
- InitCommandEvent(event);
-
- return ProcessCommand(event);
+ return SendTextUpdatedEvent();
}
bool wxTextCtrl::MSWCommand(WXUINT param, WXWORD WXUNUSED(id))
return true;
}
-bool wxTextCtrl::AcceptsFocus() const
+bool wxTextCtrl::AcceptsFocusFromKeyboard() const
{
// we don't want focus if we can't be edited unless we're a multiline
// control because then it might be still nice to get focus from keyboard
// styling support for rich edit controls
// ----------------------------------------------------------------------------
-#if wxUSE_RICHEDIT
-
bool wxTextCtrl::SetStyle(long start, long end, const wxTextAttr& style)
{
if ( !IsRich() )
if ( changeSel )
{
- DoSetSelection(start, end, false /* don't scroll caret into view */);
+ DoSetSelection(start, end, SetSel_NoScroll);
}
// initialize CHARFORMAT struct
if ( changeSel )
{
// restore the original selection
- DoSetSelection(startOld, endOld, false);
+ DoSetSelection(startOld, endOld, SetSel_NoScroll);
}
return ok;
if ( changeSel )
{
- DoSetSelection(position, position+1, false /* don't scroll caret into view */);
+ DoSetSelection(position, position + 1, SetSel_NoScroll);
}
// get the selection formatting
if ( changeSel )
{
// restore the original selection
- DoSetSelection(startOld, endOld, false);
+ DoSetSelection(startOld, endOld, SetSel_NoScroll);
}
return true;
}
-#endif
-
// ----------------------------------------------------------------------------
// wxRichEditModule
// ----------------------------------------------------------------------------
wxLogNull logNull;
return ms_inkEditLib.Load(wxT("inked"));
}
-#endif
+#endif // wxUSE_INKEDIT
#endif // wxUSE_RICHEDIT
--- /dev/null
+///////////////////////////////////////////////////////////////////////////////\r
+// Name: src/msw/textentry.cpp\r
+// Purpose: wxTextEntry implementation for wxMSW\r
+// Author: Vadim Zeitlin\r
+// Created: 2007-09-26\r
+// RCS-ID: $Id: wxhead.cpp,v 1.7 2007/01/09 16:22:45 zeitlin Exp $\r
+// Copyright: (c) 2007 Vadim Zeitlin <vadim@wxwindows.org>\r
+// Licence: wxWindows licence\r
+///////////////////////////////////////////////////////////////////////////////\r
+\r
+// ============================================================================\r
+// declarations\r
+// ============================================================================\r
+\r
+// ----------------------------------------------------------------------------\r
+// headers\r
+// ----------------------------------------------------------------------------\r
+\r
+// for compilers that support precompilation, includes "wx.h".\r
+#include "wx/wxprec.h"\r
+\r
+#ifdef __BORLANDC__\r
+ #pragma hdrstop\r
+#endif\r
+\r
+#ifndef WX_PRECOMP\r
+#endif // WX_PRECOMP\r
+\r
+#include "wx/textentry.h"\r
+\r
+#include "wx/msw/private.h"\r
+\r
+#define GetEditHwnd() ((HWND)(GetEditHWND()))\r
+\r
+// ============================================================================\r
+// wxTextEntry implementation\r
+// ============================================================================\r
+\r
+void wxTextEntry::WriteText(const wxString& text)\r
+{\r
+ ::SendMessage(GetEditHwnd(), EM_REPLACESEL, 0, (LPARAM)text.wx_str());\r
+}\r
+\r
+wxString wxTextEntry::GetValue() const\r
+{\r
+ return wxGetWindowText(GetEditHWND());\r
+}\r
+\r
+void wxTextEntry::Remove(long from, long to)\r
+{\r
+ DoSetSelection(from, to, SetSel_NoScroll);\r
+ WriteText(wxString());\r
+}\r
+\r
+void wxTextEntry::Copy()\r
+{\r
+ ::SendMessage(GetEditHwnd(), WM_COPY, 0, 0);\r
+}\r
+\r
+void wxTextEntry::Cut()\r
+{\r
+ ::SendMessage(GetEditHwnd(), WM_CUT, 0, 0);\r
+}\r
+\r
+void wxTextEntry::Paste()\r
+{\r
+ ::SendMessage(GetEditHwnd(), WM_PASTE, 0, 0);\r
+}\r
+\r
+void wxTextEntry::Undo()\r
+{\r
+ ::SendMessage(GetEditHwnd(), EM_UNDO, 0, 0);\r
+}\r
+\r
+void wxTextEntry::Redo()\r
+{\r
+ // same as Undo, since Undo undoes the undo\r
+ return Undo();\r
+}\r
+\r
+bool wxTextEntry::CanUndo() const\r
+{\r
+ return ::SendMessage(GetEditHwnd(), EM_CANUNDO, 0, 0) != 0;\r
+}\r
+\r
+bool wxTextEntry::CanRedo() const\r
+{\r
+ // see comment in Redo()\r
+ return CanUndo();\r
+}\r
+\r
+void wxTextEntry::SetInsertionPoint(long pos)\r
+{\r
+ // be careful to call DoSetSelection() which is overridden in wxTextCtrl\r
+ // and not just SetSelection() here\r
+ DoSetSelection(pos, pos);\r
+}\r
+\r
+long wxTextEntry::GetInsertionPoint() const\r
+{\r
+ long from;\r
+ GetSelection(&from, NULL);\r
+ return from;\r
+}\r
+\r
+long wxTextEntry::GetLastPosition() const\r
+{\r
+ return ::SendMessage(GetEditHwnd(), EM_LINELENGTH, 0, 0);\r
+}\r
+\r
+void wxTextEntry::DoSetSelection(long from, long to, int WXUNUSED(flags))\r
+{\r
+ // if from and to are both -1, it means (in wxWidgets) that all text should\r
+ // be selected, translate this into Windows convention\r
+ if ( (from == -1) && (to == -1) )\r
+ {\r
+ from = 0;\r
+ }\r
+\r
+ ::SendMessage(GetEditHwnd(), EM_SETSEL, from, to);\r
+}\r
+\r
+void wxTextEntry::GetSelection(long *from, long *to) const\r
+{\r
+ DWORD dwStart, dwEnd;\r
+ ::SendMessage(GetEditHwnd(), EM_GETSEL, (WPARAM)&dwStart, (LPARAM)&dwEnd);\r
+\r
+ if ( from )\r
+ *from = dwStart;\r
+ if ( to )\r
+ *to = dwEnd;\r
+}\r
+\r
+bool wxTextEntry::IsEditable() const\r
+{\r
+ return (::GetWindowLong(GetEditHwnd(), GWL_STYLE) & ES_READONLY) != 0;\r
+}\r
+\r
+void wxTextEntry::SetEditable(bool editable)\r
+{\r
+ ::SendMessage(GetEditHwnd(), EM_SETREADONLY, !editable, 0);\r
+}\r
+\r
+void wxTextEntry::SetMaxLength(unsigned long len)\r
+{\r
+ if ( len >= 0xffff )\r
+ {\r
+ // this will set it to a platform-dependent maximum (much more\r
+ // than 64Kb under NT)\r
+ len = 0;\r
+ }\r
+\r
+ ::SendMessage(GetEditHwnd(), EM_LIMITTEXT, len, 0);\r
+}\r