]> git.saurik.com Git - wxWidgets.git/blob - src/motif/textentry.cpp
Implement support for button mnemonics in wxOSX/Cocoa.
[wxWidgets.git] / src / motif / textentry.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/motif/textentry.cpp
3 // Purpose: implementation of wxTextEntry for wxMotif
4 // Author: Vadim Zeitlin
5 // Created: 2007-11-05
6 // RCS-ID: $Id$
7 // Copyright: (c) 2007 Vadim Zeitlin <vadim@wxwindows.org>
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/string.h"
28 #include "wx/window.h"
29 #endif //WX_PRECOMP
30
31 #include "wx/textentry.h"
32
33 #ifdef __VMS__
34 #pragma message disable nosimpint
35 #endif
36 #include <Xm/Text.h>
37 #ifdef __VMS__
38 #pragma message enable nosimpint
39 #endif
40
41 // return the text widget casted to the correct type
42 #define GetText() ((Widget)this->GetTextWidget())
43
44 // ============================================================================
45 // wxTextEntry implementation
46 // ============================================================================
47
48 // ----------------------------------------------------------------------------
49 // helpers
50 // ----------------------------------------------------------------------------
51
52 long wxTextEntry::GetMotifPos(long pos) const
53 {
54 // in wx API position -1 means "last one" but for Motif position must be
55 // positive, i.e. it doesn't have this convention, so translate
56 return pos == -1 ? GetLastPosition() : pos;
57 }
58
59 // ----------------------------------------------------------------------------
60 // operations on control text
61 // ----------------------------------------------------------------------------
62
63 wxString wxTextEntry::DoGetValue() const
64 {
65 wxString str;
66
67 char * const s = XmTextGetString(GetText());
68 if ( s )
69 {
70 str = s;
71 XtFree(s);
72 }
73
74 return str;
75 }
76
77 void wxTextEntry::WriteText(const wxString& text)
78 {
79 long pos = GetInsertionPoint();
80
81 XmTextInsert(GetText(), pos, text.char_str());
82
83 pos += text.length();
84
85 XtVaSetValues(GetText(), XmNcursorPosition, pos, NULL);
86 SetInsertionPoint(pos);
87 XmTextShowPosition(GetText(), pos);
88 }
89
90 void wxTextEntry::Replace(long from, long to, const wxString& value)
91 {
92 XmTextReplace(GetText(), from, GetMotifPos(to), value.char_str());
93 }
94
95 void wxTextEntry::Remove(long from, long to)
96 {
97 SetSelection(from, to);
98 XmTextRemove(GetText());
99 }
100
101 // ----------------------------------------------------------------------------
102 // clipboard operations
103 // ----------------------------------------------------------------------------
104
105 void wxTextEntry::Copy()
106 {
107 XmTextCopy(GetText(), CurrentTime);
108 }
109
110 void wxTextEntry::Cut()
111 {
112 XmTextCut(GetText(), CurrentTime);
113 }
114
115 void wxTextEntry::Paste()
116 {
117 XmTextPaste(GetText());
118 }
119
120 // ----------------------------------------------------------------------------
121 // undo/redo (not implemented)
122 // ----------------------------------------------------------------------------
123
124 void wxTextEntry::Undo()
125 {
126 }
127
128 void wxTextEntry::Redo()
129 {
130 }
131
132 bool wxTextEntry::CanUndo() const
133 {
134 return false;
135 }
136
137 bool wxTextEntry::CanRedo() const
138 {
139 return false;
140 }
141
142 // ----------------------------------------------------------------------------
143 // insertion point
144 // ----------------------------------------------------------------------------
145
146 void wxTextEntry::SetInsertionPoint(long pos)
147 {
148 XmTextSetInsertionPosition(GetText(), GetMotifPos(pos));
149 }
150
151 long wxTextEntry::GetInsertionPoint() const
152 {
153 return XmTextGetInsertionPosition(GetText());
154 }
155
156 wxTextPos wxTextEntry::GetLastPosition() const
157 {
158 return XmTextGetLastPosition(GetText());
159 }
160
161 // ----------------------------------------------------------------------------
162 // selection
163 // ----------------------------------------------------------------------------
164
165 void wxTextEntry::GetSelection(long* from, long* to) const
166 {
167 XmTextPosition left, right;
168 if ( !XmTextGetSelectionPosition(GetText(), &left, &right) )
169 {
170 // no selection, for compatibility with wxMSW return empty range at
171 // cursor position
172 left =
173 right = GetInsertionPoint();
174 }
175
176 if ( from )
177 *from = left;
178 if ( to )
179 *to = right;
180 }
181
182 void wxTextEntry::SetSelection(long from, long to)
183 {
184 XmTextSetSelection(GetText(), from, GetMotifPos(to), CurrentTime);
185 }
186
187
188 // ----------------------------------------------------------------------------
189 // editable state
190 // ----------------------------------------------------------------------------
191
192 bool wxTextEntry::IsEditable() const
193 {
194 return XmTextGetEditable(GetText()) != 0;
195 }
196
197 void wxTextEntry::SetEditable(bool editable)
198 {
199 XmTextSetEditable(GetText(), (Boolean) editable);
200 }
201