1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/motif/textentry.cpp
3 // Purpose: implementation of wxTextEntry for wxMotif
4 // Author: Vadim Zeitlin
6 // Copyright: (c) 2007 Vadim Zeitlin <vadim@wxwindows.org>
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/string.h"
27 #include "wx/window.h"
30 #include "wx/textentry.h"
33 #pragma message disable nosimpint
37 #pragma message enable nosimpint
40 // return the text widget casted to the correct type
41 #define GetText() ((Widget)this->GetTextWidget())
43 // ============================================================================
44 // wxTextEntry implementation
45 // ============================================================================
47 // ----------------------------------------------------------------------------
49 // ----------------------------------------------------------------------------
51 long wxTextEntry::GetMotifPos(long pos
) const
53 // in wx API position -1 means "last one" but for Motif position must be
54 // positive, i.e. it doesn't have this convention, so translate
55 return pos
== -1 ? GetLastPosition() : pos
;
58 // ----------------------------------------------------------------------------
59 // operations on control text
60 // ----------------------------------------------------------------------------
62 wxString
wxTextEntry::DoGetValue() const
66 char * const s
= XmTextGetString(GetText());
76 void wxTextEntry::WriteText(const wxString
& text
)
78 long pos
= GetInsertionPoint();
80 XmTextInsert(GetText(), pos
, text
.char_str());
84 XtVaSetValues(GetText(), XmNcursorPosition
, pos
, NULL
);
85 SetInsertionPoint(pos
);
86 XmTextShowPosition(GetText(), pos
);
89 void wxTextEntry::Replace(long from
, long to
, const wxString
& value
)
91 XmTextReplace(GetText(), from
, GetMotifPos(to
), value
.char_str());
94 void wxTextEntry::Remove(long from
, long to
)
96 SetSelection(from
, to
);
97 XmTextRemove(GetText());
100 // ----------------------------------------------------------------------------
101 // clipboard operations
102 // ----------------------------------------------------------------------------
104 void wxTextEntry::Copy()
106 XmTextCopy(GetText(), CurrentTime
);
109 void wxTextEntry::Cut()
111 XmTextCut(GetText(), CurrentTime
);
114 void wxTextEntry::Paste()
116 XmTextPaste(GetText());
119 // ----------------------------------------------------------------------------
120 // undo/redo (not implemented)
121 // ----------------------------------------------------------------------------
123 void wxTextEntry::Undo()
127 void wxTextEntry::Redo()
131 bool wxTextEntry::CanUndo() const
136 bool wxTextEntry::CanRedo() const
141 // ----------------------------------------------------------------------------
143 // ----------------------------------------------------------------------------
145 void wxTextEntry::SetInsertionPoint(long pos
)
147 XmTextSetInsertionPosition(GetText(), GetMotifPos(pos
));
150 long wxTextEntry::GetInsertionPoint() const
152 return XmTextGetInsertionPosition(GetText());
155 wxTextPos
wxTextEntry::GetLastPosition() const
157 return XmTextGetLastPosition(GetText());
160 // ----------------------------------------------------------------------------
162 // ----------------------------------------------------------------------------
164 void wxTextEntry::GetSelection(long* from
, long* to
) const
166 XmTextPosition left
, right
;
167 if ( !XmTextGetSelectionPosition(GetText(), &left
, &right
) )
169 // no selection, for compatibility with wxMSW return empty range at
172 right
= GetInsertionPoint();
181 void wxTextEntry::SetSelection(long from
, long to
)
183 XmTextSetSelection(GetText(), from
, GetMotifPos(to
), CurrentTime
);
187 // ----------------------------------------------------------------------------
189 // ----------------------------------------------------------------------------
191 bool wxTextEntry::IsEditable() const
193 return XmTextGetEditable(GetText()) != 0;
196 void wxTextEntry::SetEditable(bool editable
)
198 XmTextSetEditable(GetText(), (Boolean
) editable
);