]> git.saurik.com Git - wxWidgets.git/blob - src/msw/textentry.cpp
added disambiguation for Clear() too
[wxWidgets.git] / src / msw / textentry.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/textentry.cpp
3 // Purpose: wxTextEntry implementation for wxMSW
4 // Author: Vadim Zeitlin
5 // Created: 2007-09-26
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 ///////////////////////////////////////////////////////////////////////////////
10
11 // ============================================================================
12 // declarations
13 // ============================================================================
14
15 // ----------------------------------------------------------------------------
16 // headers
17 // ----------------------------------------------------------------------------
18
19 // for compilers that support precompilation, includes "wx.h".
20 #include "wx/wxprec.h"
21
22 #ifdef __BORLANDC__
23 #pragma hdrstop
24 #endif
25
26 #ifndef WX_PRECOMP
27 #endif // WX_PRECOMP
28
29 #include "wx/textentry.h"
30
31 #include "wx/msw/private.h"
32
33 #define GetEditHwnd() ((HWND)(GetEditHWND()))
34
35 // ============================================================================
36 // wxTextEntry implementation
37 // ============================================================================
38
39 void wxTextEntry::WriteText(const wxString& text)
40 {
41 ::SendMessage(GetEditHwnd(), EM_REPLACESEL, 0, (LPARAM)text.wx_str());
42 }
43
44 wxString wxTextEntry::GetValue() const
45 {
46 return wxGetWindowText(GetEditHWND());
47 }
48
49 void wxTextEntry::Remove(long from, long to)
50 {
51 DoSetSelection(from, to, SetSel_NoScroll);
52 WriteText(wxString());
53 }
54
55 void wxTextEntry::Copy()
56 {
57 ::SendMessage(GetEditHwnd(), WM_COPY, 0, 0);
58 }
59
60 void wxTextEntry::Cut()
61 {
62 ::SendMessage(GetEditHwnd(), WM_CUT, 0, 0);
63 }
64
65 void wxTextEntry::Paste()
66 {
67 ::SendMessage(GetEditHwnd(), WM_PASTE, 0, 0);
68 }
69
70 void wxTextEntry::Undo()
71 {
72 ::SendMessage(GetEditHwnd(), EM_UNDO, 0, 0);
73 }
74
75 void wxTextEntry::Redo()
76 {
77 // same as Undo, since Undo undoes the undo
78 return Undo();
79 }
80
81 bool wxTextEntry::CanUndo() const
82 {
83 return ::SendMessage(GetEditHwnd(), EM_CANUNDO, 0, 0) != 0;
84 }
85
86 bool wxTextEntry::CanRedo() const
87 {
88 // see comment in Redo()
89 return CanUndo();
90 }
91
92 void wxTextEntry::SetInsertionPoint(long pos)
93 {
94 // be careful to call DoSetSelection() which is overridden in wxTextCtrl
95 // and not just SetSelection() here
96 DoSetSelection(pos, pos);
97 }
98
99 long wxTextEntry::GetInsertionPoint() const
100 {
101 long from;
102 GetSelection(&from, NULL);
103 return from;
104 }
105
106 long wxTextEntry::GetLastPosition() const
107 {
108 return ::SendMessage(GetEditHwnd(), EM_LINELENGTH, 0, 0);
109 }
110
111 void wxTextEntry::DoSetSelection(long from, long to, int WXUNUSED(flags))
112 {
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) )
116 {
117 from = 0;
118 }
119
120 ::SendMessage(GetEditHwnd(), EM_SETSEL, from, to);
121 }
122
123 void wxTextEntry::GetSelection(long *from, long *to) const
124 {
125 DWORD dwStart, dwEnd;
126 ::SendMessage(GetEditHwnd(), EM_GETSEL, (WPARAM)&dwStart, (LPARAM)&dwEnd);
127
128 if ( from )
129 *from = dwStart;
130 if ( to )
131 *to = dwEnd;
132 }
133
134 bool wxTextEntry::IsEditable() const
135 {
136 return (::GetWindowLong(GetEditHwnd(), GWL_STYLE) & ES_READONLY) != 0;
137 }
138
139 void wxTextEntry::SetEditable(bool editable)
140 {
141 ::SendMessage(GetEditHwnd(), EM_SETREADONLY, !editable, 0);
142 }
143
144 void wxTextEntry::SetMaxLength(unsigned long len)
145 {
146 if ( len >= 0xffff )
147 {
148 // this will set it to a platform-dependent maximum (much more
149 // than 64Kb under NT)
150 len = 0;
151 }
152
153 ::SendMessage(GetEditHwnd(), EM_LIMITTEXT, len, 0);
154 }