X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/fa2f57be4db838388659fe48dbf5546daf5364f8..52e750fc75020aa412fc85623d2b3cf91f9b0b33:/src/msw/textentry.cpp?ds=sidebyside diff --git a/src/msw/textentry.cpp b/src/msw/textentry.cpp index 152098e35b..d07b8a93c2 100644 --- a/src/msw/textentry.cpp +++ b/src/msw/textentry.cpp @@ -1,154 +1,156 @@ -/////////////////////////////////////////////////////////////////////////////// -// Name: src/msw/textentry.cpp -// Purpose: wxTextEntry implementation for wxMSW -// Author: Vadim Zeitlin -// Created: 2007-09-26 -// RCS-ID: $Id: wxhead.cpp,v 1.7 2007/01/09 16:22:45 zeitlin Exp $ -// Copyright: (c) 2007 Vadim Zeitlin -// Licence: wxWindows licence -/////////////////////////////////////////////////////////////////////////////// - -// ============================================================================ -// declarations -// ============================================================================ - -// ---------------------------------------------------------------------------- -// headers -// ---------------------------------------------------------------------------- - -// for compilers that support precompilation, includes "wx.h". -#include "wx/wxprec.h" - -#ifdef __BORLANDC__ - #pragma hdrstop -#endif - -#ifndef WX_PRECOMP -#endif // WX_PRECOMP - -#include "wx/textentry.h" - -#include "wx/msw/private.h" - -#define GetEditHwnd() ((HWND)(GetEditHWND())) - -// ============================================================================ -// wxTextEntry implementation -// ============================================================================ - -void wxTextEntry::WriteText(const wxString& text) -{ - ::SendMessage(GetEditHwnd(), EM_REPLACESEL, 0, (LPARAM)text.wx_str()); -} - -wxString wxTextEntry::GetValue() const -{ - return wxGetWindowText(GetEditHWND()); -} - -void wxTextEntry::Remove(long from, long to) -{ - DoSetSelection(from, to, SetSel_NoScroll); - WriteText(wxString()); -} - -void wxTextEntry::Copy() -{ - ::SendMessage(GetEditHwnd(), WM_COPY, 0, 0); -} - -void wxTextEntry::Cut() -{ - ::SendMessage(GetEditHwnd(), WM_CUT, 0, 0); -} - -void wxTextEntry::Paste() -{ - ::SendMessage(GetEditHwnd(), WM_PASTE, 0, 0); -} - -void wxTextEntry::Undo() -{ - ::SendMessage(GetEditHwnd(), EM_UNDO, 0, 0); -} - -void wxTextEntry::Redo() -{ - // same as Undo, since Undo undoes the undo - return Undo(); -} - -bool wxTextEntry::CanUndo() const -{ - return ::SendMessage(GetEditHwnd(), EM_CANUNDO, 0, 0) != 0; -} - -bool wxTextEntry::CanRedo() const -{ - // see comment in Redo() - return CanUndo(); -} - -void wxTextEntry::SetInsertionPoint(long pos) -{ - // be careful to call DoSetSelection() which is overridden in wxTextCtrl - // and not just SetSelection() here - DoSetSelection(pos, pos); -} - -long wxTextEntry::GetInsertionPoint() const -{ - long from; - GetSelection(&from, NULL); - return from; -} - -long wxTextEntry::GetLastPosition() const -{ - return ::SendMessage(GetEditHwnd(), EM_LINELENGTH, 0, 0); -} - -void wxTextEntry::DoSetSelection(long from, long to, int WXUNUSED(flags)) -{ - // 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; - } - - ::SendMessage(GetEditHwnd(), EM_SETSEL, from, to); -} - -void wxTextEntry::GetSelection(long *from, long *to) const -{ - DWORD dwStart, dwEnd; - ::SendMessage(GetEditHwnd(), EM_GETSEL, (WPARAM)&dwStart, (LPARAM)&dwEnd); - - if ( from ) - *from = dwStart; - if ( to ) - *to = dwEnd; -} - -bool wxTextEntry::IsEditable() const -{ - return (::GetWindowLong(GetEditHwnd(), GWL_STYLE) & ES_READONLY) != 0; -} - -void wxTextEntry::SetEditable(bool editable) -{ - ::SendMessage(GetEditHwnd(), EM_SETREADONLY, !editable, 0); -} - -void wxTextEntry::SetMaxLength(unsigned long len) -{ - if ( len >= 0xffff ) - { - // this will set it to a platform-dependent maximum (much more - // than 64Kb under NT) - len = 0; - } - - ::SendMessage(GetEditHwnd(), EM_LIMITTEXT, len, 0); -} +/////////////////////////////////////////////////////////////////////////////// +// Name: src/msw/textentry.cpp +// Purpose: wxTextEntry implementation for wxMSW +// Author: Vadim Zeitlin +// Created: 2007-09-26 +// RCS-ID: $Id$ +// Copyright: (c) 2007 Vadim Zeitlin +// Licence: wxWindows licence +/////////////////////////////////////////////////////////////////////////////// + +// ============================================================================ +// declarations +// ============================================================================ + +// ---------------------------------------------------------------------------- +// headers +// ---------------------------------------------------------------------------- + +// for compilers that support precompilation, includes "wx.h". +#include "wx/wxprec.h" + +#ifdef __BORLANDC__ + #pragma hdrstop +#endif + +#ifndef WX_PRECOMP + #include "wx/string.h" +#endif // WX_PRECOMP + +#include "wx/textentry.h" + +#include "wx/msw/private.h" + +#define GetEditHwnd() ((HWND)(GetEditHWND())) + +// ============================================================================ +// wxTextEntry implementation +// ============================================================================ + +void wxTextEntry::WriteText(const wxString& text) +{ + ::SendMessage(GetEditHwnd(), EM_REPLACESEL, 0, (LPARAM)text.wx_str()); +} + +wxString wxTextEntry::GetValue() const +{ + return wxGetWindowText(GetEditHWND()); +} + +void wxTextEntry::Remove(long from, long to) +{ + DoSetSelection(from, to, SetSel_NoScroll); + WriteText(wxString()); +} + +void wxTextEntry::Copy() +{ + ::SendMessage(GetEditHwnd(), WM_COPY, 0, 0); +} + +void wxTextEntry::Cut() +{ + ::SendMessage(GetEditHwnd(), WM_CUT, 0, 0); +} + +void wxTextEntry::Paste() +{ + ::SendMessage(GetEditHwnd(), WM_PASTE, 0, 0); +} + +void wxTextEntry::Undo() +{ + ::SendMessage(GetEditHwnd(), EM_UNDO, 0, 0); +} + +void wxTextEntry::Redo() +{ + // same as Undo, since Undo undoes the undo + Undo(); + return; +} + +bool wxTextEntry::CanUndo() const +{ + return ::SendMessage(GetEditHwnd(), EM_CANUNDO, 0, 0) != 0; +} + +bool wxTextEntry::CanRedo() const +{ + // see comment in Redo() + return CanUndo(); +} + +void wxTextEntry::SetInsertionPoint(long pos) +{ + // be careful to call DoSetSelection() which is overridden in wxTextCtrl + // and not just SetSelection() here + DoSetSelection(pos, pos); +} + +long wxTextEntry::GetInsertionPoint() const +{ + long from; + GetSelection(&from, NULL); + return from; +} + +long wxTextEntry::GetLastPosition() const +{ + return ::SendMessage(GetEditHwnd(), EM_LINELENGTH, 0, 0); +} + +void wxTextEntry::DoSetSelection(long from, long to, int WXUNUSED(flags)) +{ + // 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; + } + + ::SendMessage(GetEditHwnd(), EM_SETSEL, from, to); +} + +void wxTextEntry::GetSelection(long *from, long *to) const +{ + DWORD dwStart, dwEnd; + ::SendMessage(GetEditHwnd(), EM_GETSEL, (WPARAM)&dwStart, (LPARAM)&dwEnd); + + if ( from ) + *from = dwStart; + if ( to ) + *to = dwEnd; +} + +bool wxTextEntry::IsEditable() const +{ + return !(::GetWindowLong(GetEditHwnd(), GWL_STYLE) & ES_READONLY); +} + +void wxTextEntry::SetEditable(bool editable) +{ + ::SendMessage(GetEditHwnd(), EM_SETREADONLY, !editable, 0); +} + +void wxTextEntry::SetMaxLength(unsigned long len) +{ + if ( len >= 0xffff ) + { + // this will set it to a platform-dependent maximum (much more + // than 64Kb under NT) + len = 0; + } + + ::SendMessage(GetEditHwnd(), EM_LIMITTEXT, len, 0); +}