]>
git.saurik.com Git - wxWidgets.git/blob - src/msw/textentry.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/textentry.cpp
3 // Purpose: wxTextEntry implementation for wxMSW
4 // Author: Vadim Zeitlin
6 // RCS-ID: $Id: wxhead.cpp,v 1.7 2007/01/09 16:22:45 zeitlin Exp $
7 // Copyright: (c) 2007 Vadim Zeitlin <vadim@wxwindows.org>
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
11 // ============================================================================
13 // ============================================================================
15 // ----------------------------------------------------------------------------
17 // ----------------------------------------------------------------------------
19 // for compilers that support precompilation, includes "wx.h".
20 #include "wx/wxprec.h"
29 #include "wx/textentry.h"
31 #include "wx/msw/private.h"
33 #define GetEditHwnd() ((HWND)(GetEditHWND()))
35 // ============================================================================
36 // wxTextEntry implementation
37 // ============================================================================
39 void wxTextEntry::WriteText(const wxString
& text
)
41 ::SendMessage(GetEditHwnd(), EM_REPLACESEL
, 0, (LPARAM
)text
.wx_str());
44 wxString
wxTextEntry::GetValue() const
46 return wxGetWindowText(GetEditHWND());
49 void wxTextEntry::Remove(long from
, long to
)
51 DoSetSelection(from
, to
, SetSel_NoScroll
);
52 WriteText(wxString());
55 void wxTextEntry::Copy()
57 ::SendMessage(GetEditHwnd(), WM_COPY
, 0, 0);
60 void wxTextEntry::Cut()
62 ::SendMessage(GetEditHwnd(), WM_CUT
, 0, 0);
65 void wxTextEntry::Paste()
67 ::SendMessage(GetEditHwnd(), WM_PASTE
, 0, 0);
70 void wxTextEntry::Undo()
72 ::SendMessage(GetEditHwnd(), EM_UNDO
, 0, 0);
75 void wxTextEntry::Redo()
77 // same as Undo, since Undo undoes the undo
81 bool wxTextEntry::CanUndo() const
83 return ::SendMessage(GetEditHwnd(), EM_CANUNDO
, 0, 0) != 0;
86 bool wxTextEntry::CanRedo() const
88 // see comment in Redo()
92 void wxTextEntry::SetInsertionPoint(long pos
)
94 // be careful to call DoSetSelection() which is overridden in wxTextCtrl
95 // and not just SetSelection() here
96 DoSetSelection(pos
, pos
);
99 long wxTextEntry::GetInsertionPoint() const
102 GetSelection(&from
, NULL
);
106 long wxTextEntry::GetLastPosition() const
108 return ::SendMessage(GetEditHwnd(), EM_LINELENGTH
, 0, 0);
111 void wxTextEntry::DoSetSelection(long from
, long to
, int WXUNUSED(flags
))
113 // if from and to are both -1, it means (in wxWidgets) that all text should
114 // be selected, translate this into Windows convention
115 if ( (from
== -1) && (to
== -1) )
120 ::SendMessage(GetEditHwnd(), EM_SETSEL
, from
, to
);
123 void wxTextEntry::GetSelection(long *from
, long *to
) const
125 DWORD dwStart
, dwEnd
;
126 ::SendMessage(GetEditHwnd(), EM_GETSEL
, (WPARAM
)&dwStart
, (LPARAM
)&dwEnd
);
134 bool wxTextEntry::IsEditable() const
136 return (::GetWindowLong(GetEditHwnd(), GWL_STYLE
) & ES_READONLY
) != 0;
139 void wxTextEntry::SetEditable(bool editable
)
141 ::SendMessage(GetEditHwnd(), EM_SETREADONLY
, !editable
, 0);
144 void wxTextEntry::SetMaxLength(unsigned long len
)
148 // this will set it to a platform-dependent maximum (much more
149 // than 64Kb under NT)
153 ::SendMessage(GetEditHwnd(), EM_LIMITTEXT
, len
, 0);