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