]>
git.saurik.com Git - wxWidgets.git/blob - src/os2/textentry.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/os2/textentry.cpp
3 // Purpose: wxTextEntry implementation for wxOS2
6 // Copyright: (c) 2007 Stefan Neis
7 // Licence: wxWindows licence
8 ///////////////////////////////////////////////////////////////////////////////
10 // ============================================================================
12 // ============================================================================
14 // ----------------------------------------------------------------------------
16 // ----------------------------------------------------------------------------
18 // for compilers that support precompilation, includes "wx.h".
19 #include "wx/wxprec.h"
26 #include "wx/arrstr.h"
27 #include "wx/string.h"
30 #if wxUSE_TEXTCTRL || wxUSE_COMBOBOX
32 #include "wx/textentry.h"
33 #include "wx/dynlib.h"
35 #include "wx/os2/private.h"
37 #define GetEditHwnd() ((HWND)(GetEditHWND()))
39 // ============================================================================
40 // wxTextEntry implementation
41 // ============================================================================
43 // ----------------------------------------------------------------------------
45 // ----------------------------------------------------------------------------
47 void wxTextEntry::WriteText(const wxString
& text
)
49 wxString newText
= wxGetWindowText(GetEditHWND());
51 GetSelection(&from
, &to
);
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());
63 wxString
wxTextEntry::DoGetValue() const
65 return wxGetWindowText(GetEditHWND());
68 void wxTextEntry::Remove(long from
, long to
)
70 DoSetSelection(from
, to
, SetSel_NoScroll
);
71 WriteText(wxString());
74 // ----------------------------------------------------------------------------
75 // clipboard operations
76 // ----------------------------------------------------------------------------
78 void wxTextEntry::Copy()
80 ::WinSendMsg(GetEditHwnd(), EM_COPY
, 0, 0);
83 void wxTextEntry::Cut()
85 ::WinSendMsg(GetEditHwnd(), EM_CUT
, 0, 0);
88 void wxTextEntry::Paste()
90 ::WinSendMsg(GetEditHwnd(), EM_PASTE
, 0, 0);
93 // ----------------------------------------------------------------------------
95 // ----------------------------------------------------------------------------
97 void wxTextEntry::Undo()
101 void wxTextEntry::Redo()
103 // same as Undo, since Undo undoes the undo
108 bool wxTextEntry::CanUndo() const
113 bool wxTextEntry::CanRedo() const
115 // see comment in Redo()
119 // ----------------------------------------------------------------------------
120 // insertion point and selection
121 // ----------------------------------------------------------------------------
123 void wxTextEntry::SetInsertionPoint(long pos
)
125 // be careful to call DoSetSelection() which is overridden in wxTextCtrl
126 // and not just SetSelection() here
127 DoSetSelection(pos
, pos
);
130 long wxTextEntry::GetInsertionPoint() const
133 GetSelection(&from
, NULL
);
137 long wxTextEntry::GetLastPosition() const
141 vParams
.fsStatus
= WPM_CCHTEXT
;
142 if (::WinSendMsg( GetEditHwnd()
143 ,WM_QUERYWINDOWPARAMS
148 return vParams
.cchText
;
153 void wxTextEntry::DoSetSelection(long from
, long to
, int WXUNUSED(flags
))
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) )
162 ::WinSendMsg(GetEditHwnd(), EM_SETSEL
, MPFROM2SHORT((USHORT
)from
, (USHORT
)to
), 0);
165 void wxTextEntry::GetSelection(long *from
, long *to
) const
168 dwPos
= (long)::WinSendMsg(GetEditHwnd(), EM_QUERYSEL
, 0, 0);
171 *from
= SHORT1FROMMP((MPARAM
)dwPos
);
173 *to
= SHORT2FROMMP((MPARAM
)dwPos
);
176 // ----------------------------------------------------------------------------
178 // ----------------------------------------------------------------------------
180 bool wxTextEntry::IsEditable() const
182 return (bool)LONGFROMMR(::WinSendMsg(GetEditHwnd(), EM_QUERYREADONLY
, 0, 0));
185 void wxTextEntry::SetEditable(bool editable
)
187 ::WinSendMsg(GetEditHwnd(), EM_SETREADONLY
, MPFROMLONG(!editable
), 0);
190 // ----------------------------------------------------------------------------
192 // ----------------------------------------------------------------------------
194 void wxTextEntry::SetMaxLength(unsigned long len
)
198 // this will set it to a platform-specific maximum (32Kb under OS/2)
202 ::WinSendMsg(GetEditHwnd(), EM_SETTEXTLIMIT
, MPFROMSHORT(len
), 0);
205 #endif // wxUSE_TEXTCTRL || wxUSE_COMBOBOX