use the same #if wxUSE_XXX checks in platform-specific files as around wxTextEntryBas...
[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 #include "wx/string.h"
28 #endif // WX_PRECOMP
29
30 #if wxUSE_TEXTCTRL || wxUSE_COMBOBOX
31
32 #include "wx/textentry.h"
33
34 #include "wx/msw/private.h"
35
36 #define GetEditHwnd() ((HWND)(GetEditHWND()))
37
38 // ============================================================================
39 // wxTextEntry implementation
40 // ============================================================================
41
42 void wxTextEntry::WriteText(const wxString& text)
43 {
44 ::SendMessage(GetEditHwnd(), EM_REPLACESEL, 0, (LPARAM)text.wx_str());
45 }
46
47 wxString wxTextEntry::GetValue() const
48 {
49 return wxGetWindowText(GetEditHWND());
50 }
51
52 void wxTextEntry::Remove(long from, long to)
53 {
54 DoSetSelection(from, to, SetSel_NoScroll);
55 WriteText(wxString());
56 }
57
58 void wxTextEntry::Copy()
59 {
60 ::SendMessage(GetEditHwnd(), WM_COPY, 0, 0);
61 }
62
63 void wxTextEntry::Cut()
64 {
65 ::SendMessage(GetEditHwnd(), WM_CUT, 0, 0);
66 }
67
68 void wxTextEntry::Paste()
69 {
70 ::SendMessage(GetEditHwnd(), WM_PASTE, 0, 0);
71 }
72
73 void wxTextEntry::Undo()
74 {
75 ::SendMessage(GetEditHwnd(), EM_UNDO, 0, 0);
76 }
77
78 void wxTextEntry::Redo()
79 {
80 // same as Undo, since Undo undoes the undo
81 Undo();
82 return;
83 }
84
85 bool wxTextEntry::CanUndo() const
86 {
87 return ::SendMessage(GetEditHwnd(), EM_CANUNDO, 0, 0) != 0;
88 }
89
90 bool wxTextEntry::CanRedo() const
91 {
92 // see comment in Redo()
93 return CanUndo();
94 }
95
96 void wxTextEntry::SetInsertionPoint(long pos)
97 {
98 // be careful to call DoSetSelection() which is overridden in wxTextCtrl
99 // and not just SetSelection() here
100 DoSetSelection(pos, pos);
101 }
102
103 long wxTextEntry::GetInsertionPoint() const
104 {
105 long from;
106 GetSelection(&from, NULL);
107 return from;
108 }
109
110 long wxTextEntry::GetLastPosition() const
111 {
112 return ::SendMessage(GetEditHwnd(), EM_LINELENGTH, 0, 0);
113 }
114
115 void wxTextEntry::DoSetSelection(long from, long to, int WXUNUSED(flags))
116 {
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) )
120 {
121 from = 0;
122 }
123
124 ::SendMessage(GetEditHwnd(), EM_SETSEL, from, to);
125 }
126
127 void wxTextEntry::GetSelection(long *from, long *to) const
128 {
129 DWORD dwStart, dwEnd;
130 ::SendMessage(GetEditHwnd(), EM_GETSEL, (WPARAM)&dwStart, (LPARAM)&dwEnd);
131
132 if ( from )
133 *from = dwStart;
134 if ( to )
135 *to = dwEnd;
136 }
137
138 bool wxTextEntry::IsEditable() const
139 {
140 return !(::GetWindowLong(GetEditHwnd(), GWL_STYLE) & ES_READONLY);
141 }
142
143 void wxTextEntry::SetEditable(bool editable)
144 {
145 ::SendMessage(GetEditHwnd(), EM_SETREADONLY, !editable, 0);
146 }
147
148 void wxTextEntry::SetMaxLength(unsigned long len)
149 {
150 if ( len >= 0xffff )
151 {
152 // this will set it to a platform-dependent maximum (much more
153 // than 64Kb under NT)
154 len = 0;
155 }
156
157 ::SendMessage(GetEditHwnd(), EM_LIMITTEXT, len, 0);
158 }
159
160 #endif // wxUSE_TEXTCTRL || wxUSE_COMBOBOX