]>
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
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 #include "wx/textentry.h"
32 #include "wx/msw/private.h"
34 #define GetEditHwnd() ((HWND)(GetEditHWND()))
36 // ============================================================================
37 // wxTextEntry implementation
38 // ============================================================================
40 void wxTextEntry::WriteText(const wxString
& text
)
42 ::SendMessage(GetEditHwnd(), EM_REPLACESEL
, 0, (LPARAM
)text
.wx_str());
45 wxString
wxTextEntry::GetValue() const
47 return wxGetWindowText(GetEditHWND());
50 void wxTextEntry::Remove(long from
, long to
)
52 DoSetSelection(from
, to
, SetSel_NoScroll
);
53 WriteText(wxString());
56 void wxTextEntry::Copy()
58 ::SendMessage(GetEditHwnd(), WM_COPY
, 0, 0);
61 void wxTextEntry::Cut()
63 ::SendMessage(GetEditHwnd(), WM_CUT
, 0, 0);
66 void wxTextEntry::Paste()
68 ::SendMessage(GetEditHwnd(), WM_PASTE
, 0, 0);
71 void wxTextEntry::Undo()
73 ::SendMessage(GetEditHwnd(), EM_UNDO
, 0, 0);
76 void wxTextEntry::Redo()
78 // same as Undo, since Undo undoes the undo
83 bool wxTextEntry::CanUndo() const
85 return ::SendMessage(GetEditHwnd(), EM_CANUNDO
, 0, 0) != 0;
88 bool wxTextEntry::CanRedo() const
90 // see comment in Redo()
94 void wxTextEntry::SetInsertionPoint(long pos
)
96 // be careful to call DoSetSelection() which is overridden in wxTextCtrl
97 // and not just SetSelection() here
98 DoSetSelection(pos
, pos
);
101 long wxTextEntry::GetInsertionPoint() const
104 GetSelection(&from
, NULL
);
108 long wxTextEntry::GetLastPosition() const
110 return ::SendMessage(GetEditHwnd(), EM_LINELENGTH
, 0, 0);
113 void wxTextEntry::DoSetSelection(long from
, long to
, int WXUNUSED(flags
))
115 // if from and to are both -1, it means (in wxWidgets) that all text should
116 // be selected, translate this into Windows convention
117 if ( (from
== -1) && (to
== -1) )
122 ::SendMessage(GetEditHwnd(), EM_SETSEL
, from
, to
);
125 void wxTextEntry::GetSelection(long *from
, long *to
) const
127 DWORD dwStart
, dwEnd
;
128 ::SendMessage(GetEditHwnd(), EM_GETSEL
, (WPARAM
)&dwStart
, (LPARAM
)&dwEnd
);
136 bool wxTextEntry::IsEditable() const
138 return !(::GetWindowLong(GetEditHwnd(), GWL_STYLE
) & ES_READONLY
);
141 void wxTextEntry::SetEditable(bool editable
)
143 ::SendMessage(GetEditHwnd(), EM_SETREADONLY
, !editable
, 0);
146 void wxTextEntry::SetMaxLength(unsigned long len
)
150 // this will set it to a platform-dependent maximum (much more
151 // than 64Kb under NT)
155 ::SendMessage(GetEditHwnd(), EM_LIMITTEXT
, len
, 0);