]> git.saurik.com Git - wxWidgets.git/commitdiff
refactor wxMSW code to extract parts common to wxTextCtrl and wxComboBox into wxTextEntry
authorVadim Zeitlin <vadim@wxwidgets.org>
Wed, 26 Sep 2007 16:48:46 +0000 (16:48 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Wed, 26 Sep 2007 16:48:46 +0000 (16:48 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@48952 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/msw/textctrl.h
include/wx/msw/textentry.h [new file with mode: 0644]
include/wx/textctrl.h
include/wx/textentry.h
src/common/textcmn.cpp
src/common/textentrycmn.cpp
src/msw/combobox.cpp
src/msw/textctrl.cpp
src/msw/textentry.cpp [new file with mode: 0644]

index a56a3ff7d67cf95f69daee965203fb10283f2b84..f5fc2fb35be64b87b195751a0bc71fcf5061644e 100644 (file)
@@ -41,45 +41,42 @@ public:
                 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__
@@ -107,33 +104,7 @@ public:
         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); }
 
@@ -172,7 +143,7 @@ public:
 
     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;
@@ -227,6 +198,10 @@ protected:
 
     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;
@@ -252,8 +227,8 @@ protected:
     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;
@@ -278,6 +253,11 @@ protected:
     // 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)
@@ -292,5 +272,4 @@ private:
 
 };
 
-#endif
-    // _WX_TEXTCTRL_H_
+#endif // _WX_TEXTCTRL_H_
diff --git a/include/wx/msw/textentry.h b/include/wx/msw/textentry.h
new file mode 100644 (file)
index 0000000..a39139d
--- /dev/null
@@ -0,0 +1,67 @@
+///////////////////////////////////////////////////////////////////////////////\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
index 7bdf27a74b8377565bc36d3bfbfca0aa9ca4b3d9..7c8be5172060e9651b8927b1f5dda6e1debf5fb2 100644 (file)
@@ -411,9 +411,10 @@ public:
     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);
index d7ba22c10b506f4116eadd92e40852ccabf89425..3050074282ff5956915399bbd65d3930b2cc8c2b 100644 (file)
@@ -180,6 +180,8 @@ private:
 
 #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
index 0e7f869b633d161319aa2b27d63efd40787e13be..8fa4ad28c9dda3ea74d2636f1a9cf148ff7c97c3 100644 (file)
@@ -468,7 +468,7 @@ wxTextAreaBase::HitTest(const wxPoint& WXUNUSED(pt), long * WXUNUSED(pos)) const
 // ----------------------------------------------------------------------------
 
 /* static */
-void wxTextCtrlBase::SendTextUpdatedEvent(wxWindow *win)
+bool wxTextCtrlBase::SendTextUpdatedEvent(wxWindow *win)
 {
     wxCommandEvent event(wxEVT_COMMAND_TEXT_UPDATED, win->GetId());
 
@@ -479,7 +479,7 @@ void wxTextCtrlBase::SendTextUpdatedEvent(wxWindow *win)
     //event.SetString(win->GetValue());
 
     event.SetEventObject(win);
-    win->GetEventHandler()->ProcessEvent(event);
+    return win->GetEventHandler()->ProcessEvent(event);
 }
 
 #else // !wxUSE_TEXTCTRL
index 67443dcdad8e91dfa18cd1784f1a2e8c6f3bf2bf..956d5d591407408e4b8e0809341c050ef612d05a 100644 (file)
@@ -29,6 +29,7 @@
 #endif //WX_PRECOMP
 
 #include "wx/textentry.h"
+#include "wx/clipbrd.h"
 
 // ============================================================================
 // wxTextEntryBase implementation
@@ -97,7 +98,16 @@ bool wxTextEntryBase::CanCut() const
 
 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
index 60aa76a568826112c587dbe196a0e0e4755b89a7..5b1fc638681a464f4785d3a59cd1397be4268614 100644 (file)
@@ -395,7 +395,7 @@ WXHWND wxComboBox::GetEditHWND() const
 {
     // 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;
@@ -403,7 +403,7 @@ WXHWND wxComboBox::GetEditHWND() const
     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;
@@ -502,232 +502,17 @@ WXDWORD wxComboBox::MSWGetStyle(long style, WXDWORD *exstyle) const
 // 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();
 }
 
 // ----------------------------------------------------------------------------
index 7218b339f28ffd8134854c5fcea875219cafff7c..d57e3eca0bde4bb9ae83a3465b8e5c88ed9d38e6 100644 (file)
@@ -590,7 +590,7 @@ WXDWORD wxTextCtrl::MSWGetStyle(long style, WXDWORD *exstyle) const
 {
     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;
@@ -1172,9 +1172,7 @@ void wxTextCtrl::DoWriteText(const wxString& value, int flags)
 
 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
@@ -1191,18 +1189,12 @@ void wxTextCtrl::Clear()
 {
     ::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();
     }
 }
 
@@ -1225,91 +1217,10 @@ bool wxTextCtrl::EmulateKeyPress(const wxKeyEvent& event)
 
 #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
@@ -1323,21 +1234,7 @@ void wxTextCtrl::SetInsertionPointEnd()
         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
@@ -1353,23 +1250,27 @@ 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() )
@@ -1383,45 +1284,15 @@ void wxTextCtrl::GetSelection(long* from, long* to) const
     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();
 
@@ -1431,15 +1302,15 @@ void wxTextCtrl::DoSetSelection(long from, long to, bool scrollCaret)
         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
@@ -1473,7 +1344,7 @@ void wxTextCtrl::DoSetSelection(long from, long to, bool scrollCaret)
         }
 #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
@@ -1506,22 +1377,9 @@ bool wxTextCtrl::DoLoadFile(const wxString& file, int fileType)
 }
 
 // ----------------------------------------------------------------------------
-// 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;
@@ -1529,27 +1387,27 @@ bool wxTextCtrl::IsModified() const
 
 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;
 }
@@ -1563,12 +1421,12 @@ bool wxTextCtrl::PositionToXY(long pos, long *x, long *y) const
 #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 )
@@ -1578,7 +1436,7 @@ bool wxTextCtrl::PositionToXY(long pos, long *x, long *y) const
     }
 
     // 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;
@@ -1696,21 +1554,21 @@ void wxTextCtrl::ShowPosition(long pos)
 
     // 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
@@ -1780,14 +1638,7 @@ void wxTextCtrl::SetMaxLength(unsigned long len)
     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);
     }
 }
 
@@ -1795,41 +1646,27 @@ void wxTextCtrl::SetMaxLength(unsigned long 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();
 }
 
 // ----------------------------------------------------------------------------
@@ -1843,7 +1680,7 @@ bool wxTextCtrl::ShowNativeCaret(bool show)
         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;
         }
 
@@ -1854,7 +1691,7 @@ bool wxTextCtrl::ShowNativeCaret(bool show)
 }
 
 // ----------------------------------------------------------------------------
-// implemenation details
+// implementation details
 // ----------------------------------------------------------------------------
 
 void wxTextCtrl::Command(wxCommandEvent & event)
@@ -2084,10 +1921,7 @@ bool wxTextCtrl::SendUpdateEvent()
             return false;
     }
 
-    wxCommandEvent event(wxEVT_COMMAND_TEXT_UPDATED, GetId());
-    InitCommandEvent(event);
-
-    return ProcessCommand(event);
+    return SendTextUpdatedEvent();
 }
 
 bool wxTextCtrl::MSWCommand(WXUINT param, WXWORD WXUNUSED(id))
@@ -2173,7 +2007,7 @@ bool wxTextCtrl::AdjustSpaceLimit()
     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
@@ -2500,8 +2334,6 @@ bool wxTextCtrl::SetForegroundColour(const wxColour& colour)
 // styling support for rich edit controls
 // ----------------------------------------------------------------------------
 
-#if wxUSE_RICHEDIT
-
 bool wxTextCtrl::SetStyle(long start, long end, const wxTextAttr& style)
 {
     if ( !IsRich() )
@@ -2539,7 +2371,7 @@ bool wxTextCtrl::SetStyle(long start, long end, const wxTextAttr& style)
 
     if ( changeSel )
     {
-        DoSetSelection(start, end, false /* don't scroll caret into view */);
+        DoSetSelection(start, end, SetSel_NoScroll);
     }
 
     // initialize CHARFORMAT struct
@@ -2717,7 +2549,7 @@ bool wxTextCtrl::SetStyle(long start, long end, const wxTextAttr& style)
     if ( changeSel )
     {
         // restore the original selection
-        DoSetSelection(startOld, endOld, false);
+        DoSetSelection(startOld, endOld, SetSel_NoScroll);
     }
 
     return ok;
@@ -2780,7 +2612,7 @@ bool wxTextCtrl::GetStyle(long position, wxTextAttr& style)
 
     if ( changeSel )
     {
-        DoSetSelection(position, position+1, false /* don't scroll caret into view */);
+        DoSetSelection(position, position + 1, SetSel_NoScroll);
     }
 
     // get the selection formatting
@@ -2880,14 +2712,12 @@ bool wxTextCtrl::GetStyle(long position, wxTextAttr& style)
     if ( changeSel )
     {
         // restore the original selection
-        DoSetSelection(startOld, endOld, false);
+        DoSetSelection(startOld, endOld, SetSel_NoScroll);
     }
 
     return true;
 }
 
-#endif
-
 // ----------------------------------------------------------------------------
 // wxRichEditModule
 // ----------------------------------------------------------------------------
@@ -2967,7 +2797,7 @@ bool wxRichEditModule::LoadInkEdit()
     wxLogNull logNull;
     return ms_inkEditLib.Load(wxT("inked"));
 }
-#endif
+#endif // wxUSE_INKEDIT
 
 
 #endif // wxUSE_RICHEDIT
diff --git a/src/msw/textentry.cpp b/src/msw/textentry.cpp
new file mode 100644 (file)
index 0000000..152098e
--- /dev/null
@@ -0,0 +1,154 @@
+///////////////////////////////////////////////////////////////////////////////\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