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