1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
6  * These libraries and programs are free software; you can
7  * redistribute them and/or modify them under the terms of the GNU
8  * Lesser General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * These libraries and programs are distributed in the hope that
13  * they will be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these librararies and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 /* $XConsortium: Editor.h /main/3 1995/10/26 09:32:07 rswiston $ */
24 /*
25  *  (c) Copyright 1993, 1994 Hewlett-Packard Company
26  *  (c) Copyright 1993, 1994 International Business Machines Corp.
27  *  (c) Copyright 1993, 1994 Sun Microsystems, Inc.
28  *  (c) Copyright 1993, 1994 Novell, Inc.
29  */
30 
31 #ifndef _Dt_Editor_h
32 #define _Dt_Editor_h
33 
34 #include <Xm/Xm.h>
35 
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39 
40 
41 /*
42  * Constants
43  */
44 
45 /* Sources of Help requests */
46 /* Used with XmNhelpCallback */
47 
48 #define DtEDITOR_HELP_EDIT_WINDOW		1
49 #define DtEDITOR_HELP_STATUS_LINE		2
50 #define DtEDITOR_HELP_STATUS_CURRENT_LINE	3
51 #define DtEDITOR_HELP_STATUS_TOTAL_LINES	4
52 #define DtEDITOR_HELP_STATUS_MESSAGE		5
53 #define DtEDITOR_HELP_STATUS_OVERSTRIKE		6
54 #define DtEDITOR_HELP_FORMAT_DIALOG		7
55 #define DtEDITOR_HELP_FORMAT_LEFT_MARGIN	8
56 #define DtEDITOR_HELP_FORMAT_RIGHT_MARGIN	9
57 #define DtEDITOR_HELP_FORMAT_ALIGNMENT		10
58 #define DtEDITOR_HELP_CHANGE_DIALOG		11
59 #define DtEDITOR_HELP_CHANGE_FIND		12
60 #define DtEDITOR_HELP_CHANGE_CHANGE		13
61 #define DtEDITOR_HELP_SPELL_DIALOG		14
62 #define DtEDITOR_HELP_SPELL_MISSPELLED_WORDS	15
63 #define DtEDITOR_HELP_SPELL_CHANGE		16
64 
65 /* Specifies the last line in the edit area */
66 /* Used with DtEditorGoToLine */
67 #define DtEDITOR_LAST_LINE 		-999
68 
69 /* Resource constants */
70 
71 #ifndef DtNautoShowCursorPosition
72 #define DtNautoShowCursorPosition	XmNautoShowCursorPosition
73 #endif
74 #ifndef DtCAutoShowCursorPosition
75 #define DtCAutoShowCursorPosition	XmCAutoShowCursorPosition
76 #endif
77 #ifndef DtNblinkRate
78 #define DtNblinkRate            	XmNblinkRate
79 #endif
80 #ifndef DtCBlinkRate
81 #define DtCBlinkRate            	XmCBlinkRate
82 #endif
83 #ifndef DtNbuttonFontList
84 #define DtNbuttonFontList             	XmNbuttonFontList
85 #endif
86 #ifndef DtCFontList
87 #define DtCFontList             	XmCFontList
88 #endif
89 #ifndef DtNcenterToggleLabel
90 #define DtNcenterToggleLabel       	"centerToggleLabel"
91 #endif
92 #ifndef DtCCenterToggleLabel
93 #define DtCCenterToggleLabel       	"CenterToggleLabel"
94 #endif
95 #ifndef DtNchangeAllButtonLabel
96 #define DtNchangeAllButtonLabel       	"changeAllButtonLabel"
97 #endif
98 #ifndef DtCChangeAllButtonLabel
99 #define DtCChangeAllButtonLabel       	"ChangeAllButtonLabel"
100 #endif
101 #ifndef DtNchangeButtonLabel
102 #define DtNchangeButtonLabel       	"changeButtonLabel"
103 #endif
104 #ifndef DtCChangeButtonLabel
105 #define DtCChangeButtonLabel       	"ChangeButtonLabel"
106 #endif
107 #ifndef DtNchangeFieldLabel
108 #define DtNchangeFieldLabel       	"changeFieldLabel"
109 #endif
110 #ifndef DtCChangeFieldLabel
111 #define DtCChangeFieldLabel       	"ChangeFieldLabel"
112 #endif
113 #ifndef DtNcolumns
114 #define DtNcolumns		        XmNcolumns
115 #endif
116 #ifndef DtCColumns
117 #define DtCColumns		        XmCColumns
118 #endif
119 #ifndef DtNcurrentLineLabel
120 #define DtNcurrentLineLabel       	"currentLineLabel"
121 #endif
122 #ifndef DtCCurrentLineLabel
123 #define DtCCurrentLineLabel       	"CurrentLineLabel"
124 #endif
125 #ifndef DtNcursorPosition
126 #define DtNcursorPosition       	XmNcursorPosition
127 #endif
128 #ifndef DtCCursorPosition
129 #define DtCCursorPosition       	XmCCursorPosition
130 #endif
131 #ifndef DtNcursorPositionVisible
132 #define DtNcursorPositionVisible      	XmNcursorPositionVisible
133 #endif
134 #ifndef DtCCursorPositionVisible
135 #define DtCCursorPositionVisible       	XmCCursorPositionVisible
136 #endif
137 #ifndef DtNdialogTitle
138 #define DtNdialogTitle          	"dialogTitle"
139 #endif
140 #ifndef DtCDialogTitle
141 #define DtCDialogTitle          	XmCDialogTitle
142 #endif
143 #ifndef DtNeditable
144 #define DtNeditable             	XmNeditable
145 #endif
146 #ifndef DtCEditable
147 #define DtCEditable             	XmCEditable
148 #endif
149 #ifndef DtNfindButtonLabel
150 #define DtNfindButtonLabel       	"findButtonLabel"
151 #endif
152 #ifndef DtCFindButtonLabel
153 #define DtCFindButtonLabel       	"FindButtonLabel"
154 #endif
155 #ifndef DtNfindChangeDialogTitle
156 #define DtNfindChangeDialogTitle       	"findChangeDialogTitle"
157 #endif
158 #ifndef DtCFindChangeDialogTitle
159 #define DtCFindChangeDialogTitle       	"FindChangeDialogTitle"
160 #endif
161 #ifndef DtNfindFieldLabel
162 #define DtNfindFieldLabel       	"findFieldLabel"
163 #endif
164 #ifndef DtCFindFieldLabel
165 #define DtCFindFieldLabel       	"FindFieldLabel"
166 #endif
167 #ifndef DtNformatAllButtonLabel
168 #define DtNformatAllButtonLabel       	"formatAllButtonLabel"
169 #endif
170 #ifndef DtCFormatAllButtonLabel
171 #define DtCFormatAllButtonLabel       	"FormatAllButtonLabel"
172 #endif
173 #ifndef DtNformatParagraphButtonLabel
174 #define DtNformatParagraphButtonLabel	"formatParagraphButtonLabel"
175 #endif
176 #ifndef DtCFormatParagraphButtonLabel
177 #define DtCFormatParagraphButtonLabel	"FormatParagraphButtonLabel"
178 #endif
179 #ifndef DtNformatSettingsDialogTitle
180 #define DtNformatSettingsDialogTitle	"formatSettingsDialogTitle"
181 #endif
182 #ifndef DtCFormatSettingsDialogTitle
183 #define DtCFormatSettingsDialogTitle	"FormatSettingsDialogTitle"
184 #endif
185 #ifndef DtNinformationDialogTitle
186 #define DtNinformationDialogTitle	"informationDialogTitle"
187 #endif
188 #ifndef DtCInformationDialogTitle
189 #define DtCInformationDialogTitle	"InformationDialogTitle"
190 #endif
191 #ifndef DtNinsertLabel
192 #define DtNinsertLabel		       	"insertLabel"
193 #endif
194 #ifndef DtCInsertLabel
195 #define DtCInsertLabel       		"InsertLabel"
196 #endif
197 #ifndef DtNjustifyToggleLabel
198 #define DtNjustifyToggleLabel       	"justifyToggleLabel"
199 #endif
200 #ifndef DtCJustifyToggleLabel
201 #define DtCJustifyToggleLabel       	"JustifyToggleLabel"
202 #endif
203 #ifndef DtNlabelFontList
204 #define DtNlabelFontList             	XmNlabelFontList
205 #endif
206 #ifndef DtNleftAlignToggleLabel
207 #define DtNleftAlignToggleLabel       	"leftAlignToggleLabel"
208 #endif
209 #ifndef DtCLeftAlignToggleLabel
210 #define DtCLeftAlignToggleLabel       	"LeftAlignToggleLabel"
211 #endif
212 #ifndef DtNleftMarginFieldLabel
213 #define DtNleftMarginFieldLabel       	"leftMarginFieldLabel"
214 #endif
215 #ifndef DtCLeftMarginFieldLabel
216 #define DtCLeftMarginFieldLabel       	"LeftMarginFieldLabel"
217 #endif
218 #ifndef DtNmaxLength
219 #define DtNmaxLength             	XmNmaxLength
220 #endif
221 #ifndef DtCMaxLength
222 #define DtCMaxLength             	XmCMaxLength
223 #endif
224 #ifndef DtNmisspelledListLabel
225 #define DtNmisspelledListLabel       	"misspelledListLabel"
226 #endif
227 #ifndef DtCMisspelledListLabel
228 #define DtCMisspelledListLabel       	"MisspelledListLabel"
229 #endif
230 #ifndef DtNoverstrike
231 #define DtNoverstrike			"overstrike"
232 #endif
233 #ifndef DtCOverstrike
234 #define DtCOverstrike          		"Overstrike"
235 #endif
236 #ifndef DtNoverstrikeLabel
237 #define DtNoverstrikeLabel       	"overstrikeLabel"
238 #endif
239 #ifndef DtCOverstrikeLabel
240 #define DtCOverstrikeLabel       	"OverstrikeLabel"
241 #endif
242 #ifndef DtNrightAlignToggleLabel
243 #define DtNrightAlignToggleLabel       	"rightAlignToggleLabel"
244 #endif
245 #ifndef DtCRightAlignToggleLabel
246 #define DtCRightAlignToggleLabel       	"RightAlignToggleLabel"
247 #endif
248 #ifndef DtNrightMarginFieldLabel
249 #define DtNrightMarginFieldLabel       	"rightMarginFieldLabel"
250 #endif
251 #ifndef DtCRightMarginFieldLabel
252 #define DtCRightMarginFieldLabel       	"RightMarginFieldLabel"
253 #endif
254 #ifndef DtNrows
255 #define DtNrows            		XmNrows
256 #endif
257 #ifndef DtCRows
258 #define DtCRows  		        XmCRows
259 #endif
260 #ifndef DtNscrollHorizontal
261 #define DtNscrollHorizontal		XmNscrollHorizontal
262 #endif
263 #ifndef DtCScroll
264 #define DtCScroll          		XmCScroll
265 #endif
266 #ifndef DtNscrollLeftSide
267 #define DtNscrollLeftSide		XmNscrollLeftSide
268 #endif
269 #ifndef DtCScrollSide
270 #define DtCScrollSide          		XmCScrollSide
271 #endif
272 #ifndef DtNscrollTopSide
273 #define DtNscrollTopSide		XmNscrollTopSide
274 #endif
275 #ifndef DtNscrollVertical
276 #define DtNscrollVertical		XmNscrollVertical
277 #endif
278 #ifndef DtNshowStatusLine
279 #define DtNshowStatusLine		"showStatusLine"
280 #endif
281 #ifndef DtCShowStatusLine
282 #define DtCShowStatusLine		"ShowStatusLine"
283 #endif
284 #ifndef DtNspellDialogTitle
285 #define DtNspellDialogTitle		"spellDialogTitle"
286 #endif
287 #ifndef DtCSpellDialogTitle
288 #define DtCSpellDialogTitle		"SpellDialogTitle"
289 #endif
290 #ifndef DtNspellFilter
291 #define DtNspellFilter			"spellFilter"
292 #endif
293 #ifndef DtCSpellFilter
294 #define DtCSpellFilter			"SpellFilter"
295 #endif
296 #ifndef DtNtextBackground
297 #define DtNtextBackground   		"textBackground"
298 #endif
299 #ifndef DtCBackground
300 #define DtCBackground   		XmCBackground
301 #endif
302 #ifndef DtNtextDeselectCallback
303 #define DtNtextDeselectCallback 	"textDeselectCallback"
304 #endif
305 #ifndef DtNtextFontList
306 #define DtNtextFontList             	XmNtextFontList
307 #endif
308 #ifndef DtNtextForeground
309 #define DtNtextForeground   		"textForeground"
310 #endif
311 #ifndef DtCForeground
312 #define DtCForeground   		XmCForeground
313 #endif
314 #ifndef DtNtextSelectCallback
315 #define DtNtextSelectCallback   	"textSelectCallback"
316 #endif
317 #ifndef DtNtextTranslations
318 #define DtNtextTranslations   		XmNtextTranslations
319 #endif
320 #ifndef DtCTranslations
321 #define DtCTranslations   		XmCTranslations
322 #endif
323 #ifndef DtCCallback
324 #define DtCCallback   			XmCCallback
325 #endif
326 #ifndef DtNtopCharacter
327 #define DtNtopCharacter			XmNtopCharacter
328 #endif
329 #ifndef DtCTopCharacter
330 #define DtCTopCharacter			XmCTopCharacter
331 #endif
332 #ifndef DtNtotalLineCountLabel
333 #define DtNtotalLineCountLabel       	"totalLineCountLabel"
334 #endif
335 #ifndef DtCTotalLineCountLabel
336 #define DtCTotalLineCountLabel       	"TotalLineCountLabel"
337 #endif
338 #ifndef DtNwordWrap
339 #define DtNwordWrap			XmNwordWrap
340 #endif
341 #ifndef DtCWordWrap
342 #define DtCWordWrap			XmCWordWrap
343 #endif
344 
345 #ifndef DtEditorHelpCallbackStruct
346 #define DtEditorHelpCallbackStruct XmAnyCallbackStruct
347 #endif
348 #ifndef DtEditorSelectCallbackStruct
349 #define DtEditorSelectCallbackStruct	XmAnyCallbackStruct
350 #endif
351 #ifndef DtEditorDeselectCallbackStruct
352 #define DtEditorDeselectCallbackStruct	XmAnyCallbackStruct
353 #endif
354 
355 
356 /* Used with DtEditorChange() */
357 
358 enum {
359 	DtEDITOR_CURRENT_SELECTION,
360 	DtEDITOR_NEXT_OCCURRENCE,
361 	DtEDITOR_ALL_OCCURRENCES
362 };
363 
364 /* Used with DtEditorFormat() */
365 
366 enum {
367 	DtEDITOR_FORMAT_ALL,
368 	DtEDITOR_FORMAT_PARAGRAPH
369 };
370 
371 enum {
372 	DtEDITOR_ALIGN_CENTER,
373 	DtEDITOR_ALIGN_JUSTIFY,
374 	DtEDITOR_ALIGN_LEFT,
375 	DtEDITOR_ALIGN_RIGHT
376 };
377 
378 /* Used with DtNtextSelectCallback */
379 enum {
380         DtEDITOR_TEXT_SELECT,
381         DtEDITOR_TEXT_DESELECT
382 };
383 
384 /*
385  * Types
386  */
387 
388 typedef enum _DtEditorErrorCode{
389         DtEDITOR_NO_ERRORS,
390         DtEDITOR_INVALID_TYPE,
391         DtEDITOR_INVALID_RANGE,
392         DtEDITOR_NULL_ITEM,
393         DtEDITOR_ILLEGAL_SIZE,
394         DtEDITOR_SPELL_FILTER_FAILED,
395         DtEDITOR_NO_TMP_FILE,
396         DtEDITOR_INVALID_FILENAME,
397         DtEDITOR_NONEXISTENT_FILE,
398         DtEDITOR_UNREADABLE_FILE,
399         DtEDITOR_READ_ONLY_FILE,
400         DtEDITOR_NO_FILE_ACCESS,
401         DtEDITOR_DIRECTORY,
402         DtEDITOR_CHAR_SPECIAL_FILE,
403         DtEDITOR_BLOCK_MODE_FILE,
404         DtEDITOR_UNWRITABLE_FILE,
405         DtEDITOR_WRITABLE_FILE,
406         DtEDITOR_SAVE_FAILED,
407 	DtEDITOR_INSUFFICIENT_MEMORY,
408 	DtEDITOR_NULLS_REMOVED
409 } DtEditorErrorCode;
410 
411 
412 /* Used with DtEditorChange() to specify Find and Change To strings */
413 
414 typedef struct _DtEditorChangeValues {
415         char *find;
416         char *changeTo;
417 } DtEditorChangeValues;
418 
419 /* Used with DtEditorFormat() to specify left margin, right margin *
420  * and justification styles.					   */
421 
422 typedef struct _DtEditorFormatSettings {
423 	int		leftMargin;
424 	int		rightMargin;
425 	unsigned int	alignment;
426 } DtEditorFormatSettings;
427 
428 /* Types used to tag data to/from the editor widget */
429 
430 typedef enum _DtEditorDataFormat{
431         DtEDITOR_TEXT,
432         DtEDITOR_WCHAR,
433         DtEDITOR_DATA
434 } DtEditorDataFormat;
435 
436 
437 /* Types used to pass data to/from the editor widget */
438 
439 typedef struct _DtEditor_DataObj {
440         unsigned int    length;
441         void            *buf;
442 } DtEditor_DataObj;
443 
444 typedef struct _DtEditorContentRec {
445         DtEditorDataFormat type;
446         union   {
447                  char     *string;
448                  wchar_t  *wchar;
449 		 DtEditor_DataObj	data;
450         } value;
451 } DtEditorContentRec;
452 
453 
454 /* Widget class and instance */
455 
456 typedef struct	_DtEditorClassRec	*DtEditorClass;
457 typedef struct	_DtEditorRec		*DtEditorWidget;
458 
459 
460 /*
461  * Data
462  */
463 
464 /* Widget class */
465 
466 externalref	WidgetClass		dtEditorWidgetClass;
467 
468 
469 /*
470  * Functions
471  */
472 
473 extern Widget DtCreateEditor(
474 		Widget		parent,
475 		char		*name,
476 		ArgList		arglist,
477 		Cardinal	argcount);
478 
479 extern DtEditorErrorCode DtEditorAppend(
480 		Widget		widget,
481 		DtEditorContentRec *data);
482 
483 extern DtEditorErrorCode DtEditorAppendFromFile(
484 		Widget		widget,
485 		char		*fileName);
486 
487 extern Boolean DtEditorChange(
488 		Widget			widget,
489 		DtEditorChangeValues	*findChangeStrings,
490 		unsigned int		instanceToChange);
491 
492 extern Boolean DtEditorCheckForUnsavedChanges(
493 		Widget		widget);
494 
495 extern Boolean DtEditorClearSelection(
496 		Widget		widget);
497 
498 extern Boolean DtEditorCopyToClipboard(
499 		Widget		widget);
500 
501 extern Boolean DtEditorCutToClipboard(
502 		Widget		widget);
503 
504 extern Boolean DtEditorDeleteSelection(
505 		Widget		widget);
506 
507 extern Boolean DtEditorDeselect(
508 		Widget		widget);
509 
510 extern void DtEditorDisableRedisplay(
511 		Widget		widget);
512 
513 extern void DtEditorEnableRedisplay(
514 		Widget		widget);
515 
516 extern Boolean DtEditorFind(
517 		Widget		widget,
518 		char * 	find);
519 
520 extern DtEditorErrorCode DtEditorFormat(
521 		Widget		widget,
522 		DtEditorFormatSettings	*formatSettings,
523 		unsigned int	amountToFormat);
524 
525 extern DtEditorErrorCode DtEditorGetContents(
526 		Widget		widget,
527 		DtEditorContentRec *data,
528 		Boolean		hardCarriageReturns,
529 		Boolean		markContentsAsSaved);
530 
531 extern XmTextPosition DtEditorGetInsertionPosition(
532 		Widget		widget);
533 
534 extern XmTextPosition DtEditorGetLastPosition(
535 		Widget		widget);
536 
537 extern Widget DtEditorGetMessageTextFieldID(
538 		Widget		widget);
539 
540 extern void DtEditorGetSizeHints(
541 		Widget		widget,
542 		XSizeHints	*pHints);
543 
544 extern void DtEditorGoToLine(
545 		Widget		widget,
546 		int	lineNumber);
547 
548 extern DtEditorErrorCode DtEditorInsert(
549 		Widget		widget,
550 		DtEditorContentRec *data);
551 
552 extern DtEditorErrorCode DtEditorInsertFromFile(
553 		Widget		widget,
554 		char		*fileName);
555 
556 extern void DtEditorInvokeFindChangeDialog(
557 		Widget		widget);
558 
559 extern void DtEditorInvokeFormatDialog(
560 		Widget		widget);
561 
562 extern DtEditorErrorCode DtEditorInvokeSpellDialog(
563 		Widget		widget);
564 
565 extern Boolean DtEditorPasteFromClipboard(
566 		Widget		widget);
567 
568 extern DtEditorErrorCode DtEditorReplace(
569 		Widget			widget,
570 		XmTextPosition		startPos,
571 		XmTextPosition		endPos,
572 		DtEditorContentRec	*data);
573 
574 extern DtEditorErrorCode DtEditorReplaceFromFile(
575 		Widget			widget,
576 		XmTextPosition		startPos,
577 		XmTextPosition		endPos,
578 		char			*fileName);
579 
580 extern void DtEditorReset(
581 		Widget		widget);
582 
583 extern DtEditorErrorCode DtEditorSaveContentsToFile(
584 		Widget		widget,
585 		char		*fileName,
586 		Boolean		overwriteIfExists,
587 		Boolean		hardCarriageReturns,
588 		Boolean		markContentsAsSaved);
589 
590 extern Boolean DtEditorSelectAll(
591 		Widget		widget);
592 
593 extern DtEditorErrorCode DtEditorSetContents(
594 		Widget		widget,
595 		DtEditorContentRec *data);
596 
597 extern DtEditorErrorCode DtEditorSetContentsFromFile(
598 		Widget		widget,
599 		char		*fileName);
600 
601 extern void DtEditorSetInsertionPosition(
602 		Widget		widget,
603 		XmTextPosition	position);
604 
605 extern void DtEditorTraverseToEditor(
606 		Widget		widget);
607 
608 extern Boolean DtEditorUndoEdit(
609 		Widget		widget);
610 
611 
612 #ifdef __cplusplus
613 }
614 #endif
615 
616 #endif /* _Dt_Editor_h */
617