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