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