Add GNU LGPL headers to all .c .C and .h files
[oweals/cde.git] / cde / lib / DtHelp / PathArea.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: PathArea.c /main/7 1996/08/28 16:47:42 drk $ */
24 /************************************<+>*************************************
25  ****************************************************************************
26  **
27  **   File:        PathArea.c
28  **
29  **   Project:     Cache Creek (Rivers) Project
30  **
31  **   Description: Routines to create & process the Path area portion of our
32  **                help dialog.
33  ** 
34  **
35  **  (c) Copyright 1987, 1988, 1989, 1990, 1991, 1992 Hewlett-Packard Company
36  **
37  **  (c) Copyright 1993, 1994 Hewlett-Packard Company
38  **  (c) Copyright 1993, 1994 International Business Machines Corp.
39  **  (c) Copyright 1993, 1994 Sun Microsystems, Inc.
40  **  (c) Copyright 1993, 1994 Novell, Inc.
41  **
42  ****************************************************************************
43  ************************************<+>*************************************/
44 #include <sys/param.h>
45 #include <stdio.h>
46 #include <string.h>
47
48 #include <Xm/Xm.h>
49 #include <Xm/XmP.h>
50 #include <Xm/ScrolledW.h>
51 #include <Xm/List.h>
52 #include <Xm/Form.h>
53 #include <Xm/LabelG.h>
54 #include <Xm/Frame.h>
55 #include <Xm/RowColumn.h>
56 #include <Xm/PushBG.h>
57
58 #include <X11/Intrinsic.h>
59 #include <X11/Shell.h>
60
61 #include <Dt/Help.h>
62
63 /*
64  * private includes
65  */
66 #include "DisplayAreaI.h"
67 #include "StringFuncsI.h"
68 #include "HelposI.h"
69 #include "HelpDialogI.h"
70 #include "HelpDialogP.h"
71 #include "HelpUtilI.h"
72 #include "PathAreaI.h"
73 #include "DestroyI.h"
74 #include "XUICreateI.h"
75
76 /*
77  * Local Includes
78  */
79
80
81 \f
82 /*****************************************************************************
83  * Function:        void _DtHelpBuildPathArea(Widget parent,
84  *                                 DtHelpDialogWidget nw);  
85  *
86  *
87  * Parameters:      parent      Specifies the widget ID of the help dialog you
88  *                              want to set the topic in.
89  *                  nw          Specifies the current help dialog widget.
90  *
91  * Return Value:    Void.
92  *
93  * Purpose:         Creates/updates the Path Display area on top of the help 
94  *                  dialog.
95  *
96  *****************************************************************************/
97 void _DtHelpBuildPathArea(
98     Widget parent,
99     DtHelpDialogWidget nw)
100 {
101
102   Arg           args[20];
103   int           n;      
104   Widget pathForm, pathLabel, btnBox, tocFrame;
105   Widget _pathForm;
106   XmString labelString;
107   XmFontList  defaultList;
108   DtHelpDialogWidget hw = (DtHelpDialogWidget) nw ;
109
110   Dimension button1, button2, button3, button4;
111   Dimension maxBtnWidth;
112
113  
114   /* Create a form to  hold the topic map stuff */
115   n = 0;
116   XtSetArg (args[n], XmNmarginWidth, 1);                                n++;
117   XtSetArg (args[n], XmNmarginHeight, 1);                               n++;
118   XtSetArg (args[n], XmNshadowType, XmSHADOW_OUT);                      n++;
119   XtSetArg (args[n], XmNautoUnmanage, False);                           n++;
120   pathForm = XmCreateForm (parent, "pathForm", args, n);
121
122   n = 0;
123   XtSetArg (args[n], XmNmarginWidth, 1);                                n++;
124   XtSetArg (args[n], XmNmarginHeight, 1);                               n++;
125   XtSetArg (args[n], XmNshadowType, XmSHADOW_OUT);                      n++;
126   XtSetArg (args[n], XmNautoUnmanage, False);                           n++;
127   _pathForm = XmCreateForm (pathForm, "_pathForm", args, n);
128
129   labelString = XmStringCreateLocalized(((char *)_DTGETMESSAGE
130                           (9, 1,"Volume: ")));
131   n = 0;
132   XtSetArg (args[n], XmNlabelString, labelString);                      n++;
133   XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM);                 n++;
134   XtSetArg (args[n], XmNleftOffset, 0);                                 n++;
135   XtSetArg (args[n], XmNtopAttachment, XmATTACH_FORM);                  n++;
136   XtSetArg (args[n], XmNtopOffset, 0);                                  n++;
137   XtSetArg (args[n], XmNtraversalOn, FALSE);                            n++;
138   pathLabel = 
139          XmCreateLabelGadget (_pathForm, "pathLabel", args, n);
140   XtManageChild (pathLabel);
141   XmStringFree (labelString);
142
143
144   /* Create a label for our volume title. We fill it out later 
145    * bacause at this point we may not have yet opened the volume.
146    */
147
148   n = 0;
149   XtSetArg (args[n], XmNleftAttachment, XmATTACH_WIDGET);               n++;
150   XtSetArg (args[n], XmNleftWidget, pathLabel);                         n++;
151   XtSetArg (args[n], XmNleftOffset, 1);                                 n++;
152   XtSetArg (args[n], XmNtopAttachment, XmATTACH_FORM);                  n++;
153   XtSetArg (args[n], XmNtopOffset, 0);                                  n++;
154   XtSetArg (args[n], XmNalignment, XmALIGNMENT_BEGINNING);              n++;
155   hw->help_dialog.browser.volumeLabel = 
156          XmCreateLabelGadget (_pathForm, "volumeLabel", args, n);
157   XtManageChild (hw->help_dialog.browser.volumeLabel);
158
159
160   /* Build a container for our toc to sit in.  We do this because we cannot
161   * set form constraints on our toc, but can on the container.
162   */
163   
164   n = 0;
165   XtSetArg(args[n],  XmNshadowThickness, 0);                            n++;
166   XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM);                 n++;
167   XtSetArg (args[n], XmNleftOffset, 0);                                 n++;
168   XtSetArg (args[n], XmNbottomAttachment, XmATTACH_FORM);               n++;
169   XtSetArg (args[n], XmNbottomOffset, 0);                               n++;
170   XtSetArg (args[n], XmNtopAttachment, XmATTACH_WIDGET);                n++;
171   XtSetArg (args[n], XmNtopOffset, 0);                                  n++;
172   XtSetArg (args[n], XmNtopWidget, _pathForm);n++;
173   tocFrame =  XmCreateFrame (pathForm, "tocFrame", args, n);
174   XtManageChild (tocFrame);
175
176
177   /* Build our button box rowcol widget container */
178   n = 0;
179   XtSetArg (args[n], XmNleftAttachment, XmATTACH_WIDGET);               n++;
180   XtSetArg (args[n], XmNleftOffset,3);                                  n++;
181   XtSetArg (args[n], XmNleftWidget, tocFrame);                          n++;
182   XtSetArg (args[n], XmNbottomAttachment, XmATTACH_FORM);               n++;
183   XtSetArg (args[n], XmNbottomOffset, 2);                               n++;
184   XtSetArg (args[n], XmNtopAttachment, XmATTACH_OPPOSITE_WIDGET);       n++;
185   XtSetArg (args[n], XmNtopOffset, 2);                                  n++;
186   XtSetArg (args[n], XmNtopWidget, tocFrame);                           n++;
187   XtSetArg (args[n], XmNrightAttachment, XmATTACH_FORM);                n++;
188   XtSetArg (args[n], XmNrightOffset, 1);                                n++;
189   XtSetArg (args[n], XmNspacing, 5);                                    n++;
190   XtSetArg (args[n], XmNentryVerticalAlignment, XmALIGNMENT_CENTER);    n++;
191   XtSetArg (args[n], XmNpacking, XmPACK_COLUMN);                        n++;
192   XtSetArg (args[n], XmNorientation, XmVERTICAL);                       n++;
193   btnBox = XmCreateRowColumn (pathForm, "BtnBox", args, n);
194   XtManageChild (btnBox);
195
196   
197   /* Backtrack button */
198   labelString = XmStringCreateLocalized(((char *)_DTGETMESSAGE(9, 2,"Backtrack")));
199   n = 0; 
200   XtSetArg(args[n], XmNlabelString, labelString); n++;
201   hw->help_dialog.browser.btnBoxBackBtn  = XmCreatePushButtonGadget(btnBox,
202                                             "btnBoxBackBtn", args, n);
203   XtManageChild (hw->help_dialog.browser.btnBoxBackBtn);
204   XmStringFree(labelString); 
205   XtAddCallback(hw->help_dialog.browser.btnBoxBackBtn,XmNactivateCallback, 
206                  _DtHelpDisplayBackCB, (XtPointer) hw); 
207   XtSetSensitive(hw->help_dialog.browser.btnBoxBackBtn, FALSE);
208
209
210   /* History Button */
211   labelString = XmStringCreateLocalized(((char *)_DTGETMESSAGE(9, 3,"History...")));
212   n = 0;
213   XtSetArg(args[n], XmNlabelString, labelString); n++;
214   hw->help_dialog.browser.btnBoxHistoryBtn = XmCreatePushButtonGadget(btnBox,
215                                           "btnBoxHistoryBtn",args, n);
216   XtManageChild (hw->help_dialog.browser.btnBoxHistoryBtn);
217   XmStringFree(labelString); 
218   XtAddCallback(hw->help_dialog.browser.btnBoxHistoryBtn,XmNactivateCallback, 
219                  _DtHelpDisplayHistoryCB, (XtPointer) hw); 
220    
221
222   /* Index  button */
223   labelString = 
224   XmStringCreateLocalized(((char *)_DTGETMESSAGE(9, 4,"Index...")));
225   n = 0;
226   XtSetArg(args[n], XmNlabelString, labelString); n++;
227   hw->help_dialog.browser.btnBoxIndexBtn = XmCreatePushButtonGadget(btnBox,
228                                   "btnBoxIndexBtn",args, n);
229   XtManageChild (hw->help_dialog.browser.btnBoxIndexBtn);
230   XmStringFree(labelString); 
231   XtAddCallback(hw->help_dialog.browser.btnBoxIndexBtn,XmNactivateCallback, 
232                 _DtHelpDisplayIndexCB, (XtPointer) hw); 
233
234
235   /* Top Level Browser Button */
236  
237   if (hw->help_dialog.browser.showTopLevelBtn == TRUE)
238     {
239       labelString = 
240       XmStringCreateLocalized(((char *)_DTGETMESSAGE(9, 5,"Top Level")));
241       n = 0;
242       XtSetArg(args[n], XmNlabelString, labelString); n++;
243       hw->help_dialog.browser.btnBoxTopLevelBtn = XmCreatePushButtonGadget(btnBox,
244                                   "btnBoxTopLevelBtn",args, n);
245       XtManageChild (hw->help_dialog.browser.btnBoxTopLevelBtn);
246       XmStringFree(labelString); 
247       XtAddCallback(hw->help_dialog.browser.btnBoxTopLevelBtn,XmNactivateCallback, 
248                     _DtHelpDisplayBrowserHomeCB, (XtPointer) hw); 
249
250     }
251
252   /* Get our current fontlist value */
253   n = 0;
254   XtSetArg (args[n], XmNfontList, &(defaultList));  ++n;
255   XtGetValues (hw->help_dialog.menu.topBtn, args, n);
256
257
258   /* Build the Display Area */
259
260   hw->help_dialog.browser.pTocArea = _DtHelpCreateDisplayArea(tocFrame,
261                                    "TocArea",
262                                     ((short) hw->help_dialog.display.scrollBarPolicy),
263                                     ((short) hw->help_dialog.display.scrollBarPolicy),
264                                     True,
265                                     ((int) hw->help_dialog.browser.visiblePathCount),
266                                     1,
267                                     _DtHelpDialogHypertextCB,
268                                     NULL /*ResizeHelpDialogCB*/,
269                                     _DtHelpFilterExecCmdCB,
270                                     (XtPointer) hw,
271                                     defaultList);
272  
273
274   /* We build a blank toc at first, it gets filled in later when 
275    * updatePathArea gets called.
276    */
277    
278
279   XtManageChild(_pathForm);
280   XtManageChild(pathForm);
281
282
283   /* Perform some sizing stuff here to ensure that we layout our UI 
284    * per the current fonts.
285    */
286
287    /* Get the size of each button */
288    n = 0;
289    XtSetArg(args[n], XmNwidth, &button1);   ++n;
290    XtGetValues(hw->help_dialog.browser.btnBoxBackBtn, args, n);
291    n = 0;
292    XtSetArg(args[n], XmNwidth, &button2);   ++n;
293    XtGetValues(hw->help_dialog.browser.btnBoxHistoryBtn, args, n);
294  
295    n = 0;
296    XtSetArg(args[n], XmNwidth, &button3);   ++n;
297    XtGetValues(hw->help_dialog.browser.btnBoxIndexBtn, args, n);
298
299    if (hw->help_dialog.browser.showTopLevelBtn == True)
300     {
301       n = 0;
302       XtSetArg(args[n], XmNwidth, &button4);   ++n;
303       XtGetValues(hw->help_dialog.browser.btnBoxTopLevelBtn, args, n);
304     }
305    else
306      button4 = 0;
307
308    if (button1 >= button2)
309      maxBtnWidth = button1;
310    else
311      maxBtnWidth = button2;
312
313    if (button3 >= maxBtnWidth)
314      maxBtnWidth = button3;
315    
316    if (hw->help_dialog.browser.showTopLevelBtn == True)
317      if (button4 >= maxBtnWidth)
318        maxBtnWidth = button4;
319
320    /* Set our toc right hand attachments */
321    n = 0;
322    XtSetArg (args[n], XmNrightAttachment, XmATTACH_FORM);               n++;
323    XtSetArg (args[n], XmNrightOffset, maxBtnWidth +10);                 n++;
324    XtSetValues (tocFrame, args, n);
325
326
327 }
328
329
330 \f
331 /*****************************************************************************
332  * Function:        void _DtHelpUpdatePathArea(char *locationId,
333  *                                 DtHelpDialogWidget nw);  
334  *
335  *
336  * Parameters:      locationId Specifies the ID string for the new topic we
337  *                              are going to display in the HelpDialog widget.
338  *
339  *                  helpDialogWidget  Specifies the current help dialog widget.
340  *
341  * Return Value:    Void.
342  *
343  * Purpose:         Updates the Path Display area on top of the help
344  *                  dialog.
345  *
346  *****************************************************************************/
347 void _DtHelpUpdatePathArea(
348     char *locationId,
349     DtHelpDialogWidget nw)
350 {
351   DtHelpDialogWidget hw = (DtHelpDialogWidget) nw ;
352   int retState=-1;
353
354
355   if (locationId != NULL)
356     {
357       retState = _DtHelpUpdatePath (hw->help_dialog.browser.pTocArea,
358                                         hw->help_dialog.display.volumeHandle,
359                                         locationId);
360
361       if (retState == -1) 
362         {
363
364           /* Some error occured while processing the new toc, 
365            * error out or something ??? 
366            */
367         }
368     }
369   else if (locationId == NULL)
370     { 
371       /* We have most likely entered an error state and must set our path 
372        * area to NULL values while we display and error message in the 
373        * display area 
374        */   
375       _DtHelpDisplayAreaClean(hw->help_dialog.browser.pTocArea);
376  
377       /* We set our volumeFlag back to false so we are sure to create a new
378        * toc next time we enter this function (i.e. recovering from our
379        * error state.
380        */
381       hw->help_dialog.ghelp.volumeFlag  = FALSE; 
382     }
383 }
384
385
386
387
388
389
390
391