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