]>
git.saurik.com Git - wxWidgets.git/blob - src/msw/textentry.cpp
e08b413d17fcfc2d7d2144d8c70459987c2ee4f0
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/textentry.cpp
3 // Purpose: wxTextEntry implementation for wxMSW
4 // Author: Vadim Zeitlin
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"
27 #include "wx/string.h"
30 #if wxUSE_TEXTCTRL || wxUSE_COMBOBOX
32 #include "wx/textentry.h"
34 #include "wx/msw/private.h"
36 #define GetEditHwnd() ((HWND)(GetEditHWND()))
38 // ============================================================================
39 // wxTextEntry implementation
40 // ============================================================================
42 void wxTextEntry::WriteText(const wxString
& text
)
44 ::SendMessage(GetEditHwnd(), EM_REPLACESEL
, 0, (LPARAM
)text
.wx_str());
47 wxString
wxTextEntry::GetValue() const
49 return wxGetWindowText(GetEditHWND());
52 void wxTextEntry::Remove(long from
, long to
)
54 DoSetSelection(from
, to
, SetSel_NoScroll
);
55 WriteText(wxString());
58 void wxTextEntry::Copy()
60 ::SendMessage(GetEditHwnd(), WM_COPY
, 0, 0);
63 void wxTextEntry::Cut()
65 ::SendMessage(GetEditHwnd(), WM_CUT
, 0, 0);
68 void wxTextEntry::Paste()
70 ::SendMessage(GetEditHwnd(), WM_PASTE
, 0, 0);
73 void wxTextEntry::Undo()
75 ::SendMessage(GetEditHwnd(), EM_UNDO
, 0, 0);
78 void wxTextEntry::Redo()
80 // same as Undo, since Undo undoes the undo
85 bool wxTextEntry::CanUndo() const
87 return ::SendMessage(GetEditHwnd(), EM_CANUNDO
, 0, 0) != 0;
90 bool wxTextEntry::CanRedo() const
92 // see comment in Redo()
96 void wxTextEntry::SetInsertionPoint(long pos
)
98 // be careful to call DoSetSelection() which is overridden in wxTextCtrl
99 // and not just SetSelection() here
100 DoSetSelection(pos
, pos
);
103 long wxTextEntry::GetInsertionPoint() const
106 GetSelection(&from
, NULL
);
110 long wxTextEntry::GetLastPosition() const
112 return ::SendMessage(GetEditHwnd(), EM_LINELENGTH
, 0, 0);
115 void wxTextEntry::DoSetSelection(long from
, long to
, int WXUNUSED(flags
))
117 // if from and to are both -1, it means (in wxWidgets) that all text should
118 // be selected, translate this into Windows convention
119 if ( (from
== -1) && (to
== -1) )
124 ::SendMessage(GetEditHwnd(), EM_SETSEL
, from
, to
);
127 void wxTextEntry::GetSelection(long *from
, long *to
) const
129 DWORD dwStart
, dwEnd
;
130 ::SendMessage(GetEditHwnd(), EM_GETSEL
, (WPARAM
)&dwStart
, (LPARAM
)&dwEnd
);
138 bool wxTextEntry::IsEditable() const
140 return !(::GetWindowLong(GetEditHwnd(), GWL_STYLE
) & ES_READONLY
);
143 void wxTextEntry::SetEditable(bool editable
)
145 ::SendMessage(GetEditHwnd(), EM_SETREADONLY
, !editable
, 0);
148 void wxTextEntry::SetMaxLength(unsigned long len
)
152 // this will set it to a platform-dependent maximum (much more
153 // than 64Kb under NT)
157 ::SendMessage(GetEditHwnd(), EM_LIMITTEXT
, len
, 0);
160 #endif // wxUSE_TEXTCTRL || wxUSE_COMBOBOX