correct properties were not set during initial add somehow
[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$
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 Undo();
79 return;
80 }
81
82 bool wxTextEntry::CanUndo() const
83 {
84 return ::SendMessage(GetEditHwnd(), EM_CANUNDO, 0, 0) != 0;
85 }
86
87 bool wxTextEntry::CanRedo() const
88 {
89 // see comment in Redo()
90 return CanUndo();
91 }
92
93 void wxTextEntry::SetInsertionPoint(long pos)
94 {
95 // be careful to call DoSetSelection() which is overridden in wxTextCtrl
96 // and not just SetSelection() here
97 DoSetSelection(pos, pos);
98 }
99
100 long wxTextEntry::GetInsertionPoint() const
101 {
102 long from;
103 GetSelection(&from, NULL);
104 return from;
105 }
106
107 long wxTextEntry::GetLastPosition() const
108 {
109 return ::SendMessage(GetEditHwnd(), EM_LINELENGTH, 0, 0);
110 }
111
112 void wxTextEntry::DoSetSelection(long from, long to, int WXUNUSED(flags))
113 {
114 // if from and to are both -1, it means (in wxWidgets) that all text should
115 // be selected, translate this into Windows convention
116 if ( (from == -1) && (to == -1) )
117 {
118 from = 0;
119 }
120
121 ::SendMessage(GetEditHwnd(), EM_SETSEL, from, to);
122 }
123
124 void wxTextEntry::GetSelection(long *from, long *to) const
125 {
126 DWORD dwStart, dwEnd;
127 ::SendMessage(GetEditHwnd(), EM_GETSEL, (WPARAM)&dwStart, (LPARAM)&dwEnd);
128
129 if ( from )
130 *from = dwStart;
131 if ( to )
132 *to = dwEnd;
133 }
134
135 bool wxTextEntry::IsEditable() const
136 {
137 return (::GetWindowLong(GetEditHwnd(), GWL_STYLE) & ES_READONLY) != 0;
138 }
139
140 void wxTextEntry::SetEditable(bool editable)
141 {
142 ::SendMessage(GetEditHwnd(), EM_SETREADONLY, !editable, 0);
143 }
144
145 void wxTextEntry::SetMaxLength(unsigned long len)
146 {
147 if ( len >= 0xffff )
148 {
149 // this will set it to a platform-dependent maximum (much more
150 // than 64Kb under NT)
151 len = 0;
152 }
153
154 ::SendMessage(GetEditHwnd(), EM_LIMITTEXT, len, 0);
155 }