Add GNU LGPL headers to all .c .C and .h files
[oweals/cde.git] / cde / lib / DtHelp / Actions.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: Actions.c /main/8 1996/10/30 10:03:40 pascale $ */
24 /************************************<+>*************************************
25  ****************************************************************************
26  **
27  **   File:        Actions.c
28  **
29  **   Project:     Display Area Library
30  **
31  **   Description: This body of code handles the actions for the
32  **                Display Area.
33  **
34  **  (c) Copyright 1987, 1988, 1989, 1990, 1991, 1992 Hewlett-Packard Company
35  **
36  **  (c) Copyright 1993, 1994 Hewlett-Packard Company
37  **  (c) Copyright 1993, 1994 International Business Machines Corp.
38  **  (c) Copyright 1993, 1994 Sun Microsystems, Inc.
39  **  (c) Copyright 1993, 1994 Novell, Inc.
40  **
41  **
42  ****************************************************************************
43  ************************************<+>*************************************/
44
45 /*
46  * system includes
47  */
48 #include <Xm/Xm.h>
49
50 /*
51  * CanvasEngine
52  */
53 #include "CanvasP.h"
54
55 /*
56  * private includes
57  */
58 #include "DisplayAreaP.h"
59 #include "DisplayAreaI.h"
60 #include "ActionsI.h"
61 #include "CallbacksI.h"
62
63 #ifdef NLS16
64 #endif
65
66 /********    Private Function Declarations    ********/
67 /********    End Private Function Declarations    ********/
68
69 /********    End Private Defines             ********/
70
71 /********    Private Variable Declarations    ********/
72
73 /********    End Private Variable Declarations    ********/
74
75 /******************************************************************************
76  *                             Private Functions
77  ******************************************************************************/
78 /******************************************************************************
79  *                          Semi Public Functions
80  *****************************************************************************/
81 /*****************************************************************************
82  * Function: _DtHelpCopyAction
83  *
84  *    _DtHelpCopyAction - Copy the current info to the clipboard
85  *
86  *****************************************************************************/
87 void
88 _DtHelpCopyAction (
89     Widget          widget,
90     XEvent          *event,
91     String          *params,
92     Cardinal        *num_params)
93 {
94     Arg    args[2];
95     XtPointer userData;
96
97     XtSetArg(args[0], XmNuserData, &userData);
98     XtGetValues(widget, args, 1);
99
100     _DtHelpInitiateClipboard(userData);;
101
102 }  /* End _DtHelpCopyAction */
103
104 /*****************************************************************************
105  * Function: _DtHelpDeSelectAll
106  *
107  *    _DtHelpDeSelectAll - Deselects the information in the widget.
108  *
109  *****************************************************************************/
110 void
111 _DtHelpDeSelectAll (
112     Widget          widget,
113     XEvent          *event,
114     String          *params,
115     Cardinal        *num_params)
116 {
117     Arg    args[2];
118     XtPointer userData;
119
120     XtSetArg(args[0], XmNuserData, &userData);
121     XtGetValues(widget, args, 1);
122
123     if (userData != NULL)
124         _DtHelpClearSelection (userData);
125
126 }  /* End _DtHelpDeSelectAll */
127
128 /*****************************************************************************
129  * Function: _DtHelpSelectAll
130  *
131  *    _DtHelpSelectAll - Selects all the information in the widget.
132  *
133  *****************************************************************************/
134 void
135 _DtHelpSelectAll (
136     Widget          widget,
137     XEvent          *event,
138     String          *params,
139     Cardinal        *num_params)
140 {
141     Arg    args[2];
142     XtPointer userData;
143
144     XtSetArg(args[0], XmNuserData, &userData);
145     XtGetValues(widget, args, 1);
146
147     if (userData != NULL)
148       {
149         DtHelpDispAreaStruct *pDAS = (DtHelpDispAreaStruct *) userData;
150
151         _DtCanvasMoveTraversal(pDAS->canvas, _DtCvTRAVERSAL_OFF, False, True,
152                                                 NULL, NULL, NULL, NULL, NULL);
153         _DtHelpGetClearSelection (widget, userData);
154         _DtCanvasProcessSelection(pDAS->canvas, 0, 0, _DtCvSELECTION_START);
155         _DtCanvasProcessSelection(pDAS->canvas, pDAS->dispUseWidth,
156                                         pDAS->maxYpos, _DtCvSELECTION_END);
157         _DtCanvasMoveTraversal(pDAS->canvas, _DtCvTRAVERSAL_ON, False, True,
158                                                 NULL, NULL, NULL, NULL, NULL);
159         pDAS->text_selected = True;
160       }
161
162 }  /* End _DtHelpSelectAll */
163
164 /*****************************************************************************
165  * Function: _DtHelpActivateLink
166  *
167  *    _DtHelpSelectAll - Selects all the information in the widget.
168  *
169  *****************************************************************************/
170 void
171 _DtHelpActivateLink (
172     Widget          widget,
173     XEvent          *event,
174     String          *params,
175     Cardinal        *num_params)
176 {
177     Arg    args[2];
178     DtHelpDispAreaStruct *pDAS;
179     _DtCvLinkInfo           ceHyper;
180     DtHelpHyperTextStruct   callData;
181
182     XtSetArg(args[0], XmNuserData, &pDAS);
183     XtGetValues(widget, args, 1);
184
185     if (pDAS == NULL)
186         return;
187
188     if (! pDAS->dtinfo)
189       {
190         if (_DtCvSTATUS_OK == _DtCanvasGetCurLink(pDAS->canvas, &ceHyper))
191           {
192             callData.reason        = XmCR_ACTIVATE;
193             callData.event         = event;
194             callData.window        = XtWindow (pDAS->dispWid);
195             callData.specification = ceHyper.specification;
196             callData.hyper_type    = ceHyper.hyper_type;
197             callData.window_hint   = ceHyper.win_hint;
198             (*(pDAS->hyperCall)) (pDAS, pDAS->clientData, &callData);
199           }
200       }
201     else /* dtinfo context */
202       {
203         _DtCvPointer mark_enclosure = NULL;
204
205         _DtCvStatus status;
206
207         status = _DtCanvasGetCurTraversal(pDAS->canvas, &ceHyper,
208                                                         &mark_enclosure);
209
210         if (status == _DtCvSTATUS_LINK)
211           {
212             callData.reason        = XmCR_ACTIVATE;
213             callData.event         = event;
214             callData.window        = XtWindow (pDAS->dispWid);
215             callData.specification = ceHyper.specification;
216             callData.hyper_type    = ceHyper.hyper_type;
217             callData.window_hint   = ceHyper.win_hint;
218             (*(pDAS->hyperCall)) (pDAS, pDAS->clientData, &callData);
219           }
220         else if (status == _DtCvSTATUS_MARK)
221           {
222             callData.reason        = XmCR_ACTIVATE;
223             callData.event         = event;
224             callData.window        = XtWindow (pDAS->dispWid);
225             callData.specification = mark_enclosure;
226             callData.hyper_type    = -1; /* signifies it's a mark */
227             callData.window_hint   = 0;
228             (*(pDAS->hyperCall)) (pDAS, pDAS->clientData, &callData);
229           }
230
231         /* otherwise do nothing */
232       }
233
234 }  /* End _DtHelpActivateLink */
235
236 /*****************************************************************************
237  * Function: _DtHelpPageUpOrDown
238  *
239  *    _DtHelpPageUpOrDown - Selects all the information in the widget.
240  *
241  *****************************************************************************/
242 void
243 _DtHelpPageUpOrDown (
244     Widget          widget,
245     XEvent          *event,
246     String          *params,
247     Cardinal        *num_params)
248 {
249     int        keyPressed;
250     _DtCvUnit  newY;
251     _DtCvUnit  diff;
252     Arg        args[2];
253     XtPointer  userData;
254
255     XtSetArg(args[0], XmNuserData, &userData);
256     XtGetValues(widget, args, 1);
257
258     if (userData != NULL)
259       {
260         DtHelpDispAreaStruct *pDAS = (DtHelpDispAreaStruct *) userData;
261
262         diff = pDAS->dispUseHeight - pDAS->lineHeight;
263
264         keyPressed = atoi(*params);
265         if (keyPressed == 0)
266             diff = -diff;
267
268         newY = pDAS->firstVisible + diff;
269
270         /*
271          * Is the new Y position too large?
272          * If so, adjust.
273          */
274         if (newY + ((int)pDAS->dispUseHeight) > pDAS->maxYpos)
275             newY = pDAS->maxYpos - pDAS->dispUseHeight;
276
277         /*
278          * Is the new Y before the begining?
279          * If so, zero it.
280          */
281         if (newY < 0)
282             newY = 0;
283
284         if (newY != pDAS->firstVisible)
285           {
286             pDAS->firstVisible = newY;
287             XtSetArg(args[0], XmNvalue, newY);
288             XtSetValues (pDAS->vertScrollWid, args, 1);
289
290             if (pDAS->vScrollNotify)
291               (pDAS->vScrollNotify)(pDAS->clientData, pDAS->firstVisible);
292
293             _DtHelpCleanAndDrawWholeCanvas (userData);
294           }
295       }
296
297 }  /* End _DtHelpPageUpOrDown */
298
299 /*****************************************************************************
300  * Function: _DtHelpPageLeftOrRight
301  *
302  *    _DtHelpPageLeftOrRight - Selects all the information in the widget.
303  *
304  *****************************************************************************/
305 void
306 _DtHelpPageLeftOrRight (
307     Widget          widget,
308     XEvent          *event,
309     String          *params,
310     Cardinal        *num_params)
311 {
312     int        keyPressed;
313     _DtCvUnit  newX;
314     _DtCvUnit  diff;
315     Arg        args[2];
316     XtPointer  userData;
317
318     XtSetArg(args[0], XmNuserData, &userData);
319     XtGetValues(widget, args, 1);
320
321     if (userData != NULL)
322       {
323         DtHelpDispAreaStruct *pDAS = (DtHelpDispAreaStruct *) userData;
324
325         diff = pDAS->dispUseWidth - ((int) pDAS->charWidth / 10);
326
327         keyPressed = atoi(*params);
328         if (keyPressed == 0)
329             diff = -diff;
330
331         newX = pDAS->virtualX + diff;
332
333         /*
334          * Is the new X position too large?
335          * If so, adjust.
336          */
337         if (newX + ((int)pDAS->dispUseWidth) > pDAS->maxX)
338             newX = pDAS->maxX - pDAS->dispUseWidth;
339
340         /*
341          * Is the new X before the begining?
342          * If so, zero it.
343          */
344         if (newX < 0)
345             newX = 0;
346
347         if (newX != pDAS->virtualX)
348           {
349             pDAS->virtualX = newX;
350             XtSetArg(args[0], XmNvalue, newX);
351             XtSetValues (pDAS->horzScrollWid, args, 1);
352
353             _DtHelpCleanAndDrawWholeCanvas (userData);
354           }
355       }
356
357 }  /* End _DtHelpPageLeftOrRight */
358
359 /*****************************************************************************
360  * Function: _DtHelpNextLink
361  *
362  *    _DtHelpNextLink - Moves the traversal to the requested hypertext link.
363  *
364  *****************************************************************************/
365 void
366 _DtHelpNextLink (
367     Widget          widget,
368     XEvent          *event,
369     String          *params,
370     Cardinal        *num_params)
371 {
372     _DtCvTraversalCmd cmd = _DtCvTRAVERSAL_NEXT;
373     _DtCvUnit  diff;
374     _DtCvUnit  newY;
375     _DtCvUnit  newX;
376     _DtCvUnit  height;
377     _DtCvUnit  top;
378     Arg        args[2];
379     XtPointer  userData;
380
381     XtSetArg(args[0], XmNuserData, &userData);
382     XtGetValues(widget, args, 1);
383
384     if (userData != NULL)
385       {
386         DtHelpDispAreaStruct *pDAS = (DtHelpDispAreaStruct *) userData;
387
388         switch(atoi(*params))
389           {
390             case 0: cmd = _DtCvTRAVERSAL_PREV;
391                     break;
392             case 2: cmd = _DtCvTRAVERSAL_TOP;
393                     break;
394             case 3: cmd = _DtCvTRAVERSAL_BOTTOM;
395                     break;
396           }
397
398         if (_DtCvSTATUS_OK == _DtCanvasMoveTraversal(pDAS->canvas, cmd, False,
399                                 (XtIsRealized(pDAS->dispWid) ? True : False),
400                                 NULL, &newX, &newY, NULL, &height))
401           {
402             /*
403              * take into account our traversal indicator
404              */
405             newY   -= pDAS->lineThickness;
406             height += (2 * pDAS->lineThickness);
407     
408             top  = pDAS->firstVisible;
409             diff = ((int) pDAS->dispUseHeight) * 2 / 3;
410             if (newY < top)
411               {
412                 top = newY;
413                 if (cmd == _DtCvTRAVERSAL_TOP && newY <= diff)
414                     top = 0;
415               }
416             else if (newY + height > top + ((int) pDAS->dispUseHeight))
417               {
418                 top = newY + height - ((int) pDAS->dispUseHeight);
419                 if (cmd == _DtCvTRAVERSAL_BOTTOM &&
420                                                 newY >= (pDAS->maxYpos - diff))
421                     top = pDAS->maxYpos - pDAS->dispUseHeight;
422               }
423     
424             if (top != pDAS->firstVisible)
425               {
426                 pDAS->firstVisible = top;
427     
428                 if (top + ((int)pDAS->dispUseHeight) > pDAS->maxYpos)
429                   {
430                     pDAS->firstVisible = pDAS->maxYpos - pDAS->dispUseHeight;
431                     if (pDAS->firstVisible < 0)
432                         pDAS->firstVisible = 0;
433                   }
434     
435                 XtSetArg (args[0], XmNvalue, pDAS->firstVisible);
436                 XtSetValues (pDAS->vertScrollWid, args, 1);
437     
438                 if (pDAS->vScrollNotify)
439                   (pDAS->vScrollNotify)(pDAS->clientData, pDAS->firstVisible);
440
441                 /*
442                  * re-draw the information
443                  */
444                 _DtHelpCleanAndDrawWholeCanvas (userData);
445               }
446           }
447       }
448
449 }  /* End _DtHelpNextLink */