21 |
|
|
22 |
#include "arshell.h" |
#include "arshell.h" |
23 |
|
|
24 |
|
XmTextPosition |
25 |
|
arshell_end_of_word(XmTextPosition start) |
26 |
|
{ |
27 |
|
char *text=XmTextGetString(arshell.gui.widgets.work); |
28 |
|
XmTextPosition counter=start; |
29 |
|
XmTextPosition last=XmTextGetLastPosition(arshell.gui.widgets.work); |
30 |
|
while((text[counter]!=' ')&(counter<=last)) |
31 |
|
counter++; |
32 |
|
free(text); |
33 |
|
if(counter>last) |
34 |
|
return(start); |
35 |
|
else |
36 |
|
return(counter); |
37 |
|
} |
38 |
|
|
39 |
|
void |
40 |
|
arshell_find_selected() |
41 |
|
{ |
42 |
|
char *selection=XmTextGetSelection(arshell.gui.widgets.work); |
43 |
|
XmTextPosition left; |
44 |
|
XmTextPosition right; |
45 |
|
XmTextPosition position=XmTextGetSelectionPosition(arshell.gui.widgets.work, |
46 |
|
&left, &right); |
47 |
|
if(selection != NULL) |
48 |
|
{ |
49 |
|
Boolean found=XmTextFindString(arshell.gui.widgets.work, |
50 |
|
right, selection, |
51 |
|
XmTEXT_BACKWARD, &position); |
52 |
|
if(found) |
53 |
|
{ |
54 |
|
XmTextSetInsertionPosition(arshell.gui.widgets.work, position); |
55 |
|
XmTextSetSelection(arshell.gui.widgets.work, position, |
56 |
|
arshell_end_of_word(position), |
57 |
|
XtLastTimestampProcessed(antiright.display)); |
58 |
|
} |
59 |
|
else |
60 |
|
antiright_status("Not Found"); |
61 |
|
} |
62 |
|
|
63 |
|
XtFree(selection); |
64 |
|
} |
65 |
|
|
66 |
void |
void |
67 |
arshell_find_at_cursor_cb() |
arshell_find_at_cursor_cb() |
91 |
XtFree(buffer); |
XtFree(buffer); |
92 |
} |
} |
93 |
|
|
94 |
void |
void |
95 |
arshell_search_ok_cb(Widget widget, |
arshell_wrap_toggle_cb(Widget widget, XtPointer client_data, XtPointer call_data) |
|
XtPointer client_data, |
|
|
XtPointer call_data) |
|
96 |
{ |
{ |
97 |
XmTextPosition position; |
arshell.edit.search_options.wrap= |
98 |
XmSelectionBoxCallbackStruct *prompt_data; |
XmToggleButtonGetState(arshell.edit.search_options.wrap_toggle); |
99 |
char *search_string; |
XmToggleButtonSetState(arshell.edit.search_options.preserve_toggle, |
100 |
|
arshell.edit.search_options.wrap, True); |
|
assert(call_data != NULL); |
|
|
|
|
|
prompt_data=call_data; |
|
|
|
|
|
XmStringGetLtoR(prompt_data->value, |
|
|
XmSTRING_DEFAULT_CHARSET, |
|
|
&search_string); |
|
|
|
|
|
assert(search_string != NULL); |
|
|
|
|
|
XmTextFindString((Widget)client_data, |
|
|
XmTextGetInsertionPosition((Widget)client_data), |
|
|
search_string, |
|
|
XmTEXT_FORWARD, |
|
|
&position); |
|
|
|
|
|
XmTextSetInsertionPosition((Widget)client_data, |
|
|
position); |
|
|
|
|
|
XtFree(search_string); |
|
|
widget=NULL; |
|
|
call_data=NULL; |
|
101 |
} |
} |
102 |
|
void |
103 |
void |
arshell_preserve_toggle_cb(Widget widget, XtPointer client_data, XtPointer call_data) |
|
arshell_search_cb(Widget widget, |
|
|
XtPointer client_data, |
|
|
XtPointer call_data) |
|
104 |
{ |
{ |
105 |
Widget prompt; |
arshell.edit.search_options.preserve= |
106 |
|
XmToggleButtonGetState(arshell.edit.search_options.preserve_toggle); |
107 |
ARCLARG; |
} |
108 |
antiright_set(XmNtitle, (XtArgVal)"Search"); |
void |
109 |
|
arshell_replace_toggle_cb(Widget widget, XtPointer client_data, XtPointer call_data) |
110 |
prompt= |
{ |
111 |
XmCreatePromptDialog(antiright.parent_widget, |
arshell.edit.search_options.replace= |
112 |
"Search", |
XmToggleButtonGetState(arshell.edit.search_options.replace_toggle); |
113 |
antiright.arguments, |
ARBUG; |
114 |
antiright.arguments_int); |
if(arshell.edit.search_options.replace) |
115 |
XtAddCallback(prompt, |
{ |
116 |
XmNokCallback, |
ARBUG; |
117 |
arshell_search_ok_cb, |
ARCLARG; |
118 |
arshell.gui.widgets.work); |
antiright_set(XmNsensitive, True); |
119 |
XtAddCallback(prompt, |
antiright_set_values(arshell.edit.replace_widget); |
120 |
XmNhelpCallback, |
ARBUG; |
121 |
antiright_help_cb, |
antiright_set_values(arshell.edit.search_options.replace_label); |
122 |
"Enter the text that you want to find in the text field."); |
ARCLARG; |
123 |
XtManageChild(prompt); |
ARBUG; |
124 |
|
} |
125 |
widget=(Widget)NULL; |
else |
126 |
client_data=(XtPointer)NULL; |
{ |
127 |
call_data=(XtPointer)NULL; |
ARCLARG; |
128 |
|
antiright_set(XmNsensitive, False); |
129 |
|
antiright_set_values(arshell.edit.replace_widget); |
130 |
|
antiright_set_values(arshell.edit.search_options.replace_label); |
131 |
|
ARCLARG; |
132 |
|
} |
133 |
|
} |
134 |
|
void |
135 |
|
arshell_replace_all_toggle_cb(Widget widget, XtPointer client_data, XtPointer call_data) |
136 |
|
{ |
137 |
|
arshell.edit.search_options.replace_all= |
138 |
|
XmToggleButtonGetState(arshell.edit.search_options.replace_all_toggle); |
139 |
|
XmToggleButtonSetState(arshell.edit.search_options.replace_toggle, |
140 |
|
arshell.edit.search_options.replace_all, True); |
141 |
|
arshell_replace_toggle_cb(widget, client_data, call_data); |
142 |
} |
} |
143 |
|
|
144 |
void |
void |
145 |
arshell_replace_ok_cb(Widget widget, |
arshell_search_replace_ok_cb(Widget widget, |
146 |
XtPointer client_data, |
XtPointer client_data, |
147 |
XtPointer call_data) |
XtPointer call_data) |
148 |
{ |
{ |
149 |
XmTextPosition position; |
XmTextPosition position; |
|
XmTextPosition end_position; |
|
150 |
char *search_string; |
char *search_string; |
151 |
char *replacement_string; |
ARBUG; |
152 |
|
if(arshell.edit.search_options.replace) |
153 |
client_data=NULL; |
{ |
154 |
search_string=XmTextFieldGetString(arshell.edit.find_widget); |
XmTextPosition end_position; |
155 |
XmTextFindString(arshell.gui.widgets.work, |
char *replacement_string; |
156 |
XmTextGetInsertionPosition(arshell.gui.widgets.work), |
Boolean search_status; |
157 |
search_string, |
ARBUG; |
158 |
XmTEXT_FORWARD, |
search_string=XmTextFieldGetString(arshell.edit.find_widget); |
159 |
&position); |
ARBUG; |
160 |
XtFree(search_string); |
XmTextFindString(arshell.gui.widgets.work, |
161 |
XmTextFindString(arshell.gui.widgets.work, |
XmTextGetInsertionPosition(arshell.gui.widgets.work), |
162 |
position, |
search_string, |
163 |
" ", |
arshell.edit.search_options.direction, |
164 |
XmTEXT_FORWARD, |
&position); |
165 |
&end_position); |
ARBUG; |
166 |
replacement_string=XmTextFieldGetString(arshell.edit.replace_widget); |
XtFree(search_string); |
167 |
if(end_position>position) |
ARBUG; |
168 |
{ |
XmTextFindString(arshell.gui.widgets.work, |
169 |
XmTextReplace(arshell.gui.widgets.work, position, end_position, |
position, |
170 |
replacement_string); |
" ", |
171 |
} |
XmTEXT_FORWARD, |
172 |
XtFree(replacement_string); |
&end_position); |
173 |
XmTextSetInsertionPosition(arshell.gui.widgets.work, position); |
ARBUG; |
174 |
XtManageChild(widget); |
replacement_string=XmTextFieldGetString(arshell.edit.replace_widget); |
175 |
call_data=NULL; |
if(end_position>position) |
176 |
} |
{ |
177 |
void |
ARBUG; |
178 |
arshell_replace_cb(Widget widget, |
XmTextReplace(arshell.gui.widgets.work, position, end_position, |
179 |
XtPointer client_data, |
replacement_string); |
180 |
XtPointer call_data) |
ARBUG; |
181 |
|
} |
182 |
|
else |
183 |
|
{ |
184 |
|
ARBUG; |
185 |
|
if(arshell.edit.search_options.wrap && !arshell.edit.search_options.wrapped) |
186 |
|
{ |
187 |
|
ARBUG; |
188 |
|
arshell.edit.search_options.direction=XmTEXT_BACKWARD; |
189 |
|
arshell.edit.search_options.wrapped=True; |
190 |
|
ARBUG; |
191 |
|
} |
192 |
|
else |
193 |
|
{ |
194 |
|
arshell.edit.search_options.preserve=False; |
195 |
|
} |
196 |
|
ARBUG; |
197 |
|
} |
198 |
|
ARBUG; |
199 |
|
XtFree(replacement_string); |
200 |
|
XmTextSetInsertionPosition(arshell.gui.widgets.work, position); |
201 |
|
if(arshell.edit.search_options.preserve) |
202 |
|
XtManageChild(widget); |
203 |
|
call_data=NULL; |
204 |
|
ARBUG; |
205 |
|
} |
206 |
|
else |
207 |
|
{ |
208 |
|
XmSelectionBoxCallbackStruct *prompt_data; |
209 |
|
Boolean result; |
210 |
|
ARBUG; |
211 |
|
search_string=XmTextFieldGetString(arshell.edit.find_widget); |
212 |
|
assert(search_string != NULL); |
213 |
|
ARBUG; |
214 |
|
assert(arshell.gui.widgets.work != NULL); |
215 |
|
|
216 |
|
result=XmTextFindString(arshell.gui.widgets.work, |
217 |
|
XmTextGetInsertionPosition(arshell.gui.widgets.work), |
218 |
|
search_string, |
219 |
|
arshell.edit.search_options.direction, |
220 |
|
&position); |
221 |
|
ARBUG; |
222 |
|
if(result) |
223 |
|
{ |
224 |
|
ARBUG; |
225 |
|
XmTextSetInsertionPosition(arshell.gui.widgets.work, position); |
226 |
|
} |
227 |
|
else |
228 |
|
{ |
229 |
|
ARBUG; |
230 |
|
if(XmToggleButtonGetState(arshell.edit.search_options.wrap_toggle)) |
231 |
|
{ |
232 |
|
ARBUG; |
233 |
|
arshell.edit.search_options.direction=XmTEXT_BACKWARD; |
234 |
|
XmToggleButtonSetState(arshell.edit.search_options.preserve_toggle, |
235 |
|
True, False); |
236 |
|
XmToggleButtonSetState(arshell.edit.search_options.wrap_toggle, |
237 |
|
False, False); |
238 |
|
} |
239 |
|
ARBUG; |
240 |
|
} |
241 |
|
ARBUG; |
242 |
|
if(XmToggleButtonGetState(arshell.edit.search_options.preserve_toggle)) |
243 |
|
XtManageChild(widget); |
244 |
|
ARBUG; |
245 |
|
XtFree(search_string); |
246 |
|
ARBUG; |
247 |
|
} |
248 |
|
} |
249 |
|
|
250 |
|
|
251 |
|
void |
252 |
|
arshell_search_replace_cb(Widget widget, |
253 |
|
XtPointer client_data, |
254 |
|
XtPointer call_data) |
255 |
{ |
{ |
256 |
Widget prompt; |
Widget prompt; |
257 |
Widget form; |
Widget form; |
263 |
antiright.arguments, |
antiright.arguments, |
264 |
antiright.arguments_int); |
antiright.arguments_int); |
265 |
XtManageChild(prompt); |
XtManageChild(prompt); |
266 |
|
arshell.edit.search_options.direction=XmTEXT_FORWARD; |
267 |
ARCLARG; |
ARCLARG; |
268 |
form=antiright_form(prompt); |
form=antiright_form(prompt); |
269 |
ARCLARG; |
ARCLARG; |
270 |
antiright_form_positions(0, 50, 0, 25); |
antiright_form_positions(0, 25, 0, 25); |
271 |
antiright_set(XmNalignment, XmALIGNMENT_END); |
antiright_set(XmNalignment, XmALIGNMENT_END); |
272 |
antiright_label(form, "Find:"); |
antiright_label(form, "Find:"); |
273 |
ARCLARG; |
ARCLARG; |
274 |
antiright_form_positions(0, 50, 25, 100); |
antiright_form_positions(0, 25, 25, 100); |
275 |
arshell.edit.find_widget=XmCreateTextField(form, "find_widget", |
arshell.edit.find_widget=XmCreateTextField(form, "find_widget", |
276 |
antiright.arguments, |
antiright.arguments, |
277 |
antiright.arguments_int); |
antiright.arguments_int); |
279 |
"Enter the text that is to be found here."); |
"Enter the text that is to be found here."); |
280 |
XtManageChild(arshell.edit.find_widget); |
XtManageChild(arshell.edit.find_widget); |
281 |
ARCLARG; |
ARCLARG; |
282 |
antiright_form_positions(50, 100, 0, 25); |
antiright_form_positions(25, 50, 0, 25); |
283 |
antiright_set(XmNalignment, XmALIGNMENT_END); |
antiright_set(XmNalignment, XmALIGNMENT_END); |
284 |
antiright_label(form, "Replace:"); |
antiright_set(XmNsensitive, False); |
285 |
|
arshell.edit.search_options.replace_label=antiright_label(form, "Replace:"); |
286 |
ARCLARG; |
ARCLARG; |
287 |
antiright_form_positions(50, 100, 25, 100); |
antiright_form_positions(25, 50, 25, 100); |
288 |
|
antiright_set(XmNsensitive, False); |
289 |
arshell.edit.replace_widget=XmCreateTextField(form, "replace_widget", |
arshell.edit.replace_widget=XmCreateTextField(form, "replace_widget", |
290 |
antiright.arguments, |
antiright.arguments, |
291 |
antiright.arguments_int); |
antiright.arguments_int); |
292 |
antiright_set_tooltip(arshell.edit.replace_widget, |
antiright_set_tooltip(arshell.edit.replace_widget, |
293 |
"Enter the replacement text here."); |
"Enter the replacement text here."); |
294 |
XtManageChild(arshell.edit.replace_widget); |
XtManageChild(arshell.edit.replace_widget); |
295 |
|
ARCLARG; |
296 |
|
antiright_form_positions(50, 75, 0, 50); |
297 |
|
arshell.edit.search_options.replace_toggle= |
298 |
|
XmCreateToggleButton(form, "Replace", ARARGS); |
299 |
|
XtManageChild(arshell.edit.search_options.replace_toggle); |
300 |
|
XtAddCallback(arshell.edit.search_options.replace_toggle, XmNvalueChangedCallback, |
301 |
|
arshell_replace_toggle_cb, NULL); |
302 |
|
ARCLARG; |
303 |
|
antiright_form_positions(50, 75, 50, 100); |
304 |
|
arshell.edit.search_options.wrap_toggle=XmCreateToggleButton(form, "Wrap", ARARGS); |
305 |
|
XtManageChild(arshell.edit.search_options.wrap_toggle); |
306 |
|
XtAddCallback(arshell.edit.search_options.wrap_toggle, XmNvalueChangedCallback, |
307 |
|
arshell_wrap_toggle_cb, NULL); |
308 |
|
ARCLARG; |
309 |
|
antiright_form_positions(75, 100, 0, 50); |
310 |
|
arshell.edit.search_options.replace_all_toggle= |
311 |
|
XmCreateToggleButton(form, "Replace All", ARARGS); |
312 |
|
XtManageChild(arshell.edit.search_options.replace_all_toggle); |
313 |
|
XtAddCallback(arshell.edit.search_options.replace_all_toggle, XmNvalueChangedCallback, |
314 |
|
arshell_replace_all_toggle_cb, NULL); |
315 |
|
ARCLARG; |
316 |
|
antiright_form_positions(75, 100, 50, 100); |
317 |
|
arshell.edit.search_options.preserve_toggle= |
318 |
|
XmCreateToggleButton(form, "Preserve Dialog", ARARGS); |
319 |
|
XtManageChild(arshell.edit.search_options.preserve_toggle); |
320 |
|
XtAddCallback(arshell.edit.search_options.preserve_toggle, XmNvalueChangedCallback, |
321 |
|
arshell_preserve_toggle_cb, NULL); |
322 |
|
|
323 |
XtAddCallback(prompt, |
XtAddCallback(prompt, |
324 |
XmNokCallback, |
XmNokCallback, |
325 |
arshell_replace_ok_cb, |
arshell_search_replace_ok_cb, |
326 |
NULL); |
NULL); |
327 |
XtAddCallback(prompt, |
XtAddCallback(prompt, |
328 |
XmNhelpCallback, |
XmNhelpCallback, |
329 |
antiright_help_cb, |
antiright_help_cb, |
330 |
"Enter_the_text_that_you_want_to_find_and_replace_in_the_" |
"Enter_the_text_that_you_want_to_find_and/or_replace_in_the_" |
331 |
"appropriate_text_field."); |
"appropriate_text_field."); |
332 |
|
|
333 |
widget=(Widget)NULL; |
widget=(Widget)NULL; |