Initial import of the CDE 2.1.30 sources from the Open Group.
[oweals/cde.git] / cde / programs / dtpad / editCB.c
1 /* $XConsortium: editCB.c /main/3 1995/11/01 10:35:26 rswiston $ */
2 /**********************************<+>*************************************
3 ***************************************************************************
4 **
5 **  File:        editCB.c
6 **
7 **  Project:     DT dtpad, a memo maker type editor based on the Dt Editor
8 **               widget.
9 **
10 **  Description:
11 **  -----------
12 **
13 **      This file contains the callbacks for the [Edit] menu items.
14 **
15 *******************************************************************
16 **  (c) Copyright Hewlett-Packard Company, 1991, 1992.  All rights are
17 **  reserved.  Copying or other reproduction of this program
18 **  except for archival purposes is prohibited without prior
19 **  written consent of Hewlett-Packard Company.
20 ********************************************************************
21 **
22 ********************************************************************
23 **  (c) Copyright 1993, 1994 Hewlett-Packard Company
24 **  (c) Copyright 1993, 1994 International Business Machines Corp.
25 **  (c) Copyright 1993, 1994 Sun Microsystems, Inc.
26 **  (c) Copyright 1993, 1994 Novell, Inc.
27 ********************************************************************
28 **
29 **
30 **************************************************************************
31 **********************************<+>*************************************/
32 #include "dtpad.h"
33 #include <Dt/HourGlass.h>
34
35
36 /************************************************************************
37  * EditUndoCB - [Edit] menu, [Undo] button.
38  *      Undoes the last edit.
39  ************************************************************************/
40 /* ARGSUSED */
41 void
42 EditUndoCB(
43         Widget w,
44         caddr_t client_data,
45         caddr_t call_data )
46 {
47     Editor *pPad = (Editor *)client_data;
48     DtEditorUndoEdit(pPad->editor);
49 }
50
51
52 /************************************************************************
53  * EditCutCB - [Edit] menu, [Cut] button.
54  *      Cuts the current selection to the Motif clipboard.
55  ************************************************************************/
56 /* ARGSUSED */
57 void
58 EditCutCB(
59         Widget w,
60         caddr_t client_data,
61         caddr_t call_data )
62 {
63     Editor *pPad = (Editor *)client_data;
64     DtEditorCutToClipboard(pPad->editor);
65 }
66
67
68 /************************************************************************
69  * EditCopyCB - [Edit] menu, [Copy] button.
70  *      Copies the current selection to the Motif clipboard.
71  ************************************************************************/
72 /* ARGSUSED */
73 void
74 EditCopyCB(
75         Widget w,
76         caddr_t client_data,
77         caddr_t call_data )
78 {
79     Editor *pPad = (Editor *)client_data;
80     DtEditorCopyToClipboard(pPad->editor);
81 }
82
83
84 /************************************************************************
85  * EditPasteCB - [Edit] menu, [Paste] button.
86  *      Pastes from the Motif clipboard.
87  ************************************************************************/
88 /* ARGSUSED */
89 void
90 EditPasteCB(
91         Widget w,
92         caddr_t client_data,
93         caddr_t call_data )
94 {
95     Editor *pPad = (Editor *)client_data;
96     DtEditorPasteFromClipboard(pPad->editor);
97
98     /* XXX - Do DtEditorGetInsertPosition & DtEditorSetInsertionPosition
99      *       need to be executed here??
100      * XmTextPosition cursorPos;
101      * cursorPos = XmTextGetInsertionPosition(pPad->text);
102      * XmTextShowPosition(pPad->text, cursorPos);
103      */
104 }
105
106
107 /************************************************************************
108  * EditClearCB - [Edit] menu, [Replace] button
109  *      Replaces the current selection with blanks.
110  ************************************************************************/
111 /* ARGSUSED */
112 void
113 EditClearCB(
114         Widget w,
115         caddr_t client_data,
116         caddr_t call_data )
117 {
118     Editor *pPad = (Editor *)client_data;
119     DtEditorClearSelection(pPad->editor);
120 }
121
122
123 /************************************************************************
124  * EditDeleteCB - [Edit] menu, [Delete] button.
125  *      Deletes the current selection.
126  ************************************************************************/
127 /* ARGSUSED */
128 void
129 EditDeleteCB(
130         Widget w,
131         caddr_t client_data,
132         caddr_t call_data )
133 {
134     Editor *pPad = (Editor *)client_data;
135     DtEditorDeleteSelection(pPad->editor);
136 }
137
138
139 /************************************************************************
140  * SelectAllCB - [Edit] menu, [Select All] button.
141  *      Selects all text.
142  ************************************************************************/
143 /* ARGSUSED */
144 void
145 SelectAllCB(
146         Widget w,
147         caddr_t client_data,
148         caddr_t call_data )
149 {
150     Editor *pPad = (Editor *)client_data;
151     DtEditorSelectAll(pPad->editor);
152 }
153
154
155 /************************************************************************
156  * FindChangeCB - [Edit] menu, [Find/Change...] button.
157  *      Invokes the Dt Editor widget search dialog.
158  ************************************************************************/
159 /* ARGSUSED */
160 void
161 FindChangeCB(
162         Widget w,
163         caddr_t client_data,
164         caddr_t call_data )
165 {
166     Editor *pPad = (Editor *)client_data;
167     DtEditorInvokeFindChangeDialog(pPad->editor);
168 }
169
170
171 /************************************************************************
172  * CheckSpellingCB - [Edit] menu, [Check Spelling...] button.
173  *      Invokes the Dt Editor widget spell dialog.
174  ************************************************************************/
175 /* ARGSUSED */
176 void
177 CheckSpellingCB(
178         Widget w,
179         caddr_t client_data,
180         caddr_t call_data )
181 {
182     Editor *pPad = (Editor *)client_data;
183     DtEditorInvokeSpellDialog(pPad->editor);
184 }
185
186
187 /************************************************************************
188  * SetSelectionMenuItems - Sets the sensitivity of [Edit] menu items
189  *      that deal with the current selection in the edit window - allowing
190  *      for viewOnly mode.
191  ************************************************************************/
192 /* ARGSUSED */
193 void
194 SetSelectionMenuItems(
195         Editor *pPad,
196         Boolean sensitivity)
197 {
198     XtSetSensitive(pPad->editStuff.widgets.cutBtn,
199       sensitivity && ! pPad->xrdb.viewOnly);
200     XtSetSensitive(pPad->editStuff.widgets.copyBtn,
201       sensitivity);                     /* Copy can be done in viewOnly mode */
202     XtSetSensitive(pPad->editStuff.widgets.clearBtn,
203       sensitivity && ! pPad->xrdb.viewOnly);
204     XtSetSensitive(pPad->editStuff.widgets.deleteBtn,
205       sensitivity && ! pPad->xrdb.viewOnly);
206 }
207
208
209 /************************************************************************
210  * TextSelectedCB - DtEditor widget DtNtextSelectCallback called when
211  *      text in the editor window is selected.
212  *      Makes [Edit] menu items related to a selection sensitive.
213  ************************************************************************/
214 /* ARGSUSED */
215 void
216 TextSelectedCB(
217         Widget w,
218         caddr_t client_data,
219         caddr_t call_data)
220 {
221     Editor *pPad = (Editor *)client_data;
222     SetSelectionMenuItems(pPad, True);
223 }
224
225
226 /************************************************************************
227  * TextDeselectedCB - DtEditor widget DtNtextSelectCallback called when
228  *      text in the editor window is deselected.
229  *      Makes [Edit] menu items related to a selection insensitive.
230  ************************************************************************/
231 /* ARGSUSED */
232 void
233 TextDeselectedCB(
234         Widget w,
235         caddr_t client_data,
236         caddr_t call_data)
237 {
238     Editor *pPad = (Editor *)client_data;
239     SetSelectionMenuItems(pPad, False);
240 }