]>
Commit | Line | Data |
---|---|---|
9a3a5e5e SN |
1 | /////////////////////////////////////////////////////////////////////////////// |
2 | // Name: src/os2/textentry.cpp | |
3 | // Purpose: wxTextEntry implementation for wxOS2 | |
4 | // Author: Stefan Neis | |
5 | // Created: 2007-11-18 | |
6 | // RCS-ID: $Id$ | |
7 | // Copyright: (c) 2007 Stefan Neis | |
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/arrstr.h" | |
28 | #include "wx/string.h" | |
29 | #endif // WX_PRECOMP | |
30 | ||
31 | #if wxUSE_TEXTCTRL || wxUSE_COMBOBOX | |
32 | ||
33 | #include "wx/textentry.h" | |
34 | #include "wx/dynlib.h" | |
35 | ||
36 | #include "wx/os2/private.h" | |
37 | ||
38 | #define GetEditHwnd() ((HWND)(GetEditHWND())) | |
39 | ||
40 | // ============================================================================ | |
41 | // wxTextEntry implementation | |
42 | // ============================================================================ | |
43 | ||
44 | // ---------------------------------------------------------------------------- | |
45 | // operations on text | |
46 | // ---------------------------------------------------------------------------- | |
47 | ||
48 | void wxTextEntry::WriteText(const wxString& text) | |
49 | { | |
50 | wxString newText = wxGetWindowText(GetEditHWND()); | |
51 | long from, to; | |
52 | GetSelection(&from, &to); | |
53 | if (from > to){ | |
54 | long swp = to; | |
55 | to = from; | |
56 | from = swp; | |
57 | } | |
58 | // Compose the new Text by replacing the selection of the old text | |
59 | newText.replace(from, to - from, text); | |
60 | // Set control to the new text | |
61 | ::WinSetWindowText(GetEditHwnd(), text.c_str()); | |
62 | } | |
63 | ||
64 | wxString wxTextEntry::GetValue() const | |
65 | { | |
66 | return wxGetWindowText(GetEditHWND()); | |
67 | } | |
68 | ||
69 | void wxTextEntry::Remove(long from, long to) | |
70 | { | |
71 | DoSetSelection(from, to, SetSel_NoScroll); | |
72 | WriteText(wxString()); | |
73 | } | |
74 | ||
75 | // ---------------------------------------------------------------------------- | |
76 | // clipboard operations | |
77 | // ---------------------------------------------------------------------------- | |
78 | ||
79 | void wxTextEntry::Copy() | |
80 | { | |
81 | ::WinSendMsg(GetEditHwnd(), EM_COPY, 0, 0); | |
82 | } | |
83 | ||
84 | void wxTextEntry::Cut() | |
85 | { | |
86 | ::WinSendMsg(GetEditHwnd(), EM_CUT, 0, 0); | |
87 | } | |
88 | ||
89 | void wxTextEntry::Paste() | |
90 | { | |
91 | ::WinSendMsg(GetEditHwnd(), EM_PASTE, 0, 0); | |
92 | } | |
93 | ||
94 | // ---------------------------------------------------------------------------- | |
95 | // undo/redo | |
96 | // ---------------------------------------------------------------------------- | |
97 | ||
98 | void wxTextEntry::Undo() | |
99 | { | |
100 | } | |
101 | ||
102 | void wxTextEntry::Redo() | |
103 | { | |
104 | // same as Undo, since Undo undoes the undo | |
105 | Undo(); | |
106 | return; | |
107 | } | |
108 | ||
109 | bool wxTextEntry::CanUndo() const | |
110 | { | |
111 | return false; | |
112 | } | |
113 | ||
114 | bool wxTextEntry::CanRedo() const | |
115 | { | |
116 | // see comment in Redo() | |
117 | return CanUndo(); | |
118 | } | |
119 | ||
120 | // ---------------------------------------------------------------------------- | |
121 | // insertion point and selection | |
122 | // ---------------------------------------------------------------------------- | |
123 | ||
124 | void wxTextEntry::SetInsertionPoint(long pos) | |
125 | { | |
126 | // be careful to call DoSetSelection() which is overridden in wxTextCtrl | |
127 | // and not just SetSelection() here | |
128 | DoSetSelection(pos, pos); | |
129 | } | |
130 | ||
131 | long wxTextEntry::GetInsertionPoint() const | |
132 | { | |
133 | long from; | |
134 | GetSelection(&from, NULL); | |
135 | return from; | |
136 | } | |
137 | ||
138 | long wxTextEntry::GetLastPosition() const | |
139 | { | |
140 | WNDPARAMS vParams; | |
141 | ||
142 | vParams.fsStatus = WPM_CCHTEXT; | |
143 | if (::WinSendMsg( GetEditHwnd() | |
144 | ,WM_QUERYWINDOWPARAMS | |
145 | ,&vParams | |
146 | ,0 | |
147 | )) | |
148 | { | |
149 | return vParams.cchText; | |
150 | } | |
151 | return 0; | |
152 | } | |
153 | ||
154 | void wxTextEntry::DoSetSelection(long from, long to, int WXUNUSED(flags)) | |
155 | { | |
156 | // if from and to are both -1, it means (in wxWidgets) that all text should | |
157 | // be selected, translate this into Windows convention | |
158 | if ( (from == -1) && (to == -1) ) | |
159 | { | |
160 | from = 0; | |
161 | } | |
162 | ||
163 | ::WinSendMsg(GetEditHwnd(), EM_SETSEL, MPFROM2SHORT((USHORT)from, (USHORT)to), 0); | |
164 | } | |
165 | ||
166 | void wxTextEntry::GetSelection(long *from, long *to) const | |
167 | { | |
168 | long dwPos; | |
169 | dwPos = (long)::WinSendMsg(GetEditHwnd(), EM_QUERYSEL, 0, 0); | |
170 | ||
171 | if ( from ) | |
172 | *from = SHORT1FROMMP((MPARAM)dwPos); | |
173 | if ( to ) | |
174 | *to = SHORT2FROMMP((MPARAM)dwPos); | |
175 | } | |
176 | ||
177 | // ---------------------------------------------------------------------------- | |
178 | // editable state | |
179 | // ---------------------------------------------------------------------------- | |
180 | ||
181 | bool wxTextEntry::IsEditable() const | |
182 | { | |
183 | return (bool)LONGFROMMR(::WinSendMsg(GetEditHwnd(), EM_QUERYREADONLY, 0, 0)); | |
184 | } | |
185 | ||
186 | void wxTextEntry::SetEditable(bool editable) | |
187 | { | |
188 | ::WinSendMsg(GetEditHwnd(), EM_SETREADONLY, MPFROMLONG(!editable), 0); | |
189 | } | |
190 | ||
191 | // ---------------------------------------------------------------------------- | |
192 | // max length | |
193 | // ---------------------------------------------------------------------------- | |
194 | ||
195 | void wxTextEntry::SetMaxLength(unsigned long len) | |
196 | { | |
197 | if ( len >= 0x7fff ) | |
198 | { | |
199 | // this will set it to a platform-specific maximum (32Kb under OS/2) | |
200 | len = 0x7fff; | |
201 | } | |
202 | ||
203 | ::WinSendMsg(GetEditHwnd(), EM_SETTEXTLIMIT, MPFROMSHORT(len), 0); | |
204 | } | |
205 | ||
206 | #endif // wxUSE_TEXTCTRL || wxUSE_COMBOBOX |