]>
git.saurik.com Git - wxWidgets.git/blob - src/os2/textentry.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/os2/textentry.cpp
3 // Purpose: wxTextEntry implementation for wxOS2
7 // Copyright: (c) 2007 Stefan Neis
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
11 // ============================================================================
13 // ============================================================================
15 // ----------------------------------------------------------------------------
17 // ----------------------------------------------------------------------------
19 // for compilers that support precompilation, includes "wx.h".
20 #include "wx/wxprec.h"
27 #include "wx/arrstr.h"
28 #include "wx/string.h"
31 #if wxUSE_TEXTCTRL || wxUSE_COMBOBOX
33 #include "wx/textentry.h"
34 #include "wx/dynlib.h"
36 #include "wx/os2/private.h"
38 #define GetEditHwnd() ((HWND)(GetEditHWND()))
40 // ============================================================================
41 // wxTextEntry implementation
42 // ============================================================================
44 // ----------------------------------------------------------------------------
46 // ----------------------------------------------------------------------------
48 void wxTextEntry::WriteText(const wxString
& text
)
50 wxString newText
= wxGetWindowText(GetEditHWND());
52 GetSelection(&from
, &to
);
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());
64 wxString
wxTextEntry::DoGetValue() const
66 return wxGetWindowText(GetEditHWND());
69 void wxTextEntry::Remove(long from
, long to
)
71 DoSetSelection(from
, to
, SetSel_NoScroll
);
72 WriteText(wxString());
75 // ----------------------------------------------------------------------------
76 // clipboard operations
77 // ----------------------------------------------------------------------------
79 void wxTextEntry::Copy()
81 ::WinSendMsg(GetEditHwnd(), EM_COPY
, 0, 0);
84 void wxTextEntry::Cut()
86 ::WinSendMsg(GetEditHwnd(), EM_CUT
, 0, 0);
89 void wxTextEntry::Paste()
91 ::WinSendMsg(GetEditHwnd(), EM_PASTE
, 0, 0);
94 // ----------------------------------------------------------------------------
96 // ----------------------------------------------------------------------------
98 void wxTextEntry::Undo()
102 void wxTextEntry::Redo()
104 // same as Undo, since Undo undoes the undo
109 bool wxTextEntry::CanUndo() const
114 bool wxTextEntry::CanRedo() const
116 // see comment in Redo()
120 // ----------------------------------------------------------------------------
121 // insertion point and selection
122 // ----------------------------------------------------------------------------
124 void wxTextEntry::SetInsertionPoint(long pos
)
126 // be careful to call DoSetSelection() which is overridden in wxTextCtrl
127 // and not just SetSelection() here
128 DoSetSelection(pos
, pos
);
131 long wxTextEntry::GetInsertionPoint() const
134 GetSelection(&from
, NULL
);
138 long wxTextEntry::GetLastPosition() const
142 vParams
.fsStatus
= WPM_CCHTEXT
;
143 if (::WinSendMsg( GetEditHwnd()
144 ,WM_QUERYWINDOWPARAMS
149 return vParams
.cchText
;
154 void wxTextEntry::DoSetSelection(long from
, long to
, int WXUNUSED(flags
))
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) )
163 ::WinSendMsg(GetEditHwnd(), EM_SETSEL
, MPFROM2SHORT((USHORT
)from
, (USHORT
)to
), 0);
166 void wxTextEntry::GetSelection(long *from
, long *to
) const
169 dwPos
= (long)::WinSendMsg(GetEditHwnd(), EM_QUERYSEL
, 0, 0);
172 *from
= SHORT1FROMMP((MPARAM
)dwPos
);
174 *to
= SHORT2FROMMP((MPARAM
)dwPos
);
177 // ----------------------------------------------------------------------------
179 // ----------------------------------------------------------------------------
181 bool wxTextEntry::IsEditable() const
183 return (bool)LONGFROMMR(::WinSendMsg(GetEditHwnd(), EM_QUERYREADONLY
, 0, 0));
186 void wxTextEntry::SetEditable(bool editable
)
188 ::WinSendMsg(GetEditHwnd(), EM_SETREADONLY
, MPFROMLONG(!editable
), 0);
191 // ----------------------------------------------------------------------------
193 // ----------------------------------------------------------------------------
195 void wxTextEntry::SetMaxLength(unsigned long len
)
199 // this will set it to a platform-specific maximum (32Kb under OS/2)
203 ::WinSendMsg(GetEditHwnd(), EM_SETTEXTLIMIT
, MPFROMSHORT(len
), 0);
206 #endif // wxUSE_TEXTCTRL || wxUSE_COMBOBOX