Initial import of the CDE 2.1.30 sources from the Open Group.
[oweals/cde.git] / cde / lib / DtHelp / XUICreate.c
1 /* $TOG: XUICreate.c /main/22 1997/06/18 17:33:46 samborn $ */
2 /************************************<+>*************************************
3  ****************************************************************************
4  **
5  **   File:        XUICreate.c
6  **
7  **   Project:     Cde Help System
8  **
9  **   Description: Builds a GUI containing a Drawn Button with scroll
10  **                bars and wraps it around a canvas.
11  **
12  ****************************************************************************
13  ************************************<+>*************************************/
14 /*
15  * (c) Copyright 1996 Digital Equipment Corporation.
16  * (c) Copyright 1987, 1988, 1989, 1990, 1991, 1992,
17                  1993, 1994, 1996 Hewlett-Packard Company.
18  * (c) Copyright 1993, 1994, 1996 International Business Machines Corp.
19  * (c) Copyright 1993, 1994, 1996 Sun Microsystems, Inc.
20  * (c) Copyright 1993, 1994, 1996 Novell, Inc. 
21  * (c) Copyright 1996 FUJITSU LIMITED.
22  * (c) Copyright 1996 Hitachi.
23  */
24
25 /*
26  * system includes
27  */
28 #include <stdlib.h>
29 #include <string.h>
30 #include <Xm/Xm.h>
31 #include <Xm/XmP.h>
32 #include <Xm/AtomMgr.h>
33 #include <Xm/DrawnB.h>
34 #include <Xm/Form.h>
35 #include <Xm/ScrollBar.h>
36
37 /*
38  * Canvas Engine
39  */
40 #include "CanvasP.h"
41 #include "CanvasSegP.h"
42
43 /*
44  * private includes
45  */
46 #include "bufioI.h"
47 #include "DisplayAreaP.h"
48 #include "CallbacksI.h"
49 #include "XUICreateI.h"
50 #include "FontI.h"
51 #include "FontAttrI.h"
52 #include "DestroyI.h"
53 #include "FormatUtilI.h"
54 #include "SetListI.h"
55 #include "XInterfaceI.h"
56 #include "Lock.h"
57
58 #ifdef NLS16
59 #endif
60
61 /********    Private Function Declarations    ********/
62 static  Boolean    get_fontsetproperty(
63                         XFontSet        fontset,
64                         Atom            atom,
65                         unsigned long   *value_return);
66 /********    End Private Function Declarations    ********/
67
68 /********    Private Variables    ********/
69
70 static  _DtCvVirtualInfo DefVirtFunctions =
71   {
72         _DtHelpDAGetCvsMetrics,         /* void (*_DtCvGetMetrics)()     */
73         _DtHelpDARenderElem,            /* void (*_DtCvRenderElem)()     */
74         _DtHelpDAGetStrWidth,           /* _DtCvUnit (*_DtCvGetElemWidth)()  */
75         _DtHelpDAGetFontMetrics,        /* void (*_DtCvGetFontMetrics)() */
76         _DtHelpDABuildSelection,        /* void (*_DtCvBuildSelection)() */
77         NULL,                           /* _DtCvStatus (*_DtCvFilterExecCmd)()*/
78   };
79
80 /********    End Private Variables  ********/
81
82 /********    Semi-Private Variables    ********/
83 /********    End Semi-Private Variables  ********/
84
85 /******************************************************************************
86  *
87  * Here are the type and variable declarations for finding view subresources.
88  *
89  *****************************************************************************/
90
91 /*
92  * These are used to parse subresources for the text display areas.
93  */
94
95 typedef struct 
96   {
97     int    marginWidth;
98     int    marginHeight;
99     int    leading;
100     int    moveThreshold;
101     int    initialDelay;
102     int    repeatDelay;
103
104     XmFontList userFont;
105     Pixel  search_color;
106   }
107   DAArgs, *DAArgsPtr;
108
109 static XtResource Resources[] = {
110    {
111      "leading", "Leading", XmRInt, sizeof(int),
112      XtOffset(DAArgsPtr, leading), XmRImmediate, (XtPointer) 1
113    },
114     
115    {
116      XmNmarginWidth, XmCMarginWidth, XmRInt, sizeof(int),
117      XtOffset(DAArgsPtr, marginWidth), XmRImmediate, (XtPointer) 5
118    },
119     
120    {
121      XmNmarginHeight, XmCMarginHeight, XmRInt, sizeof(int),
122      XtOffset(DAArgsPtr, marginHeight), XmRImmediate, (XtPointer) 5
123    },
124
125    {
126      "moveThreshold", "MoveThreshold", XmRInt, sizeof(int),
127      XtOffset(DAArgsPtr, moveThreshold), XmRImmediate, (XtPointer) 10
128    },
129     
130    {
131      XmNinitialDelay, XmCInitialDelay, XmRInt, sizeof(int),
132      XtOffset(DAArgsPtr, initialDelay), XmRImmediate, (XtPointer) 250
133    },
134     
135    {
136      XmNrepeatDelay, XmCRepeatDelay, XmRInt, sizeof(int),
137      XtOffset(DAArgsPtr, repeatDelay), XmRImmediate, (XtPointer) 50
138    },
139     
140    {
141      "userFont", XmCFontList, XmRFontList, sizeof (XmFontList),
142      XtOffset(DAArgsPtr, userFont), XmRString, "Fixed"
143    },
144
145    {
146      "searchColor", "SearchColor", XtRPixel, sizeof (Pixel),
147      XtOffset(DAArgsPtr, search_color), XmRString, "blue"
148    },
149
150 };
151
152 static String       DrawnBTransTable = "\
153 ~s    ~m ~a <Key>Return:      ActivateLink()\n\
154 ~s  c ~m ~a <Key>backslash:   DeSelectAll()\n\
155 ~s  c ~m ~a <Key>slash:       SelectAll()\n\
156 ~s    ~m ~a <Key>space:       ActivateLink()\n\
157             <Key>osfActivate: ActivateLink()\n\
158             <Key>osfCopy:     CopyToClipboard()\n\
159    ~c       <Key>osfDown:     NextLink(1)\n\
160     c       <Key>osfDown:     PageUpOrDown(1)\n\
161 ~s  c ~m ~a <Key>osfInsert:   CopyToClipboard()\n\
162    ~c       <Key>osfLeft:      NextLink(0)\n\
163     c       <Key>osfLeft:      PageLeftOrRight(0)\n\
164    ~c       <Key>osfPageDown:  PageUpOrDown(1)\n\
165     c       <Key>osfPageDown:  PageLeftOrRight(1)\n\
166             <Key>osfPageLeft:  PageLeftOrRight(0)\n\
167             <Key>osfPageRight: PageLeftOrRight(1)\n\
168    ~c       <Key>osfPageUp:    PageUpOrDown(0)\n\
169     c       <Key>osfPageUp:    PageLeftOrRight(0)\n\
170    ~c       <Key>osfRight:     NextLink(1)\n\
171     c       <Key>osfRight:     PageLeftOrRight(1)\n\
172 ~s ~c       <Key>osfSelect:    ActivateLink()\n\
173    ~c       <Key>osfUp:        NextLink(0)\n\
174     c       <Key>osfUp:        PageUpOrDown(0)\n\
175     c       <Key>osfBeginLine: NextLink(2)\n\
176     c       <Key>osfEndLine:   NextLink(3)\
177 ";
178
179 static  XtTranslations  DrawnBTrans = NULL;
180
181 /*********************************************************************
182  *              Private Functions
183  *********************************************************************/
184 /* This function returns the max value of XGetFontProperty calls for each
185  * font in the fontset.
186  */
187 static Boolean
188 get_fontsetproperty(
189         XFontSet fontset,
190         Atom atom,
191         unsigned long *value_return)
192 {
193     int numfont;
194     XFontStruct **font_list;
195     char **name_list;
196     int i;
197     Bool ret = FALSE;
198     unsigned long value;
199
200     numfont=XFontsOfFontSet(fontset,&font_list,&name_list);
201     for(i = 0; i < numfont; i++) {
202         if(XGetFontProperty(font_list[i], atom, &value) == TRUE) {
203             if(ret == FALSE) {
204                 *value_return = value;
205                 ret = TRUE;
206             }
207             else {
208                 if(value > *value_return)
209                     *value_return = value;
210             }
211         }
212     }
213     return(ret);
214 }
215
216 /*
217  * This function returns the underline distance and size for the base
218  * font.
219  */
220 static  void
221 GetUnderLineInfo (
222         Display                 *dpy,
223         DtHelpDispAreaStruct    *pDAS,
224         int                     *ret_underThick )
225 {
226     int   idx;
227     XtPointer myFont;
228     XFontSetExtents *extents;
229
230     /*
231      * cast the parameter as a pointer to a long though the value
232      * returned is really a int.
233      */
234     idx = __DtHelpDefaultFontIndexGet(pDAS);
235     if (idx < 0)
236       {
237         myFont = (XtPointer)__DtHelpFontSetGet(pDAS->font_info, idx);
238         if (get_fontsetproperty((XFontSet)myFont, XA_UNDERLINE_POSITION,
239                 ((unsigned long *) &(pDAS->underLine))) == FALSE)
240           {
241             extents = XExtentsOfFontSet((XFontSet)myFont);
242             pDAS->underLine = ((int)(extents->max_ink_extent.height +
243                                extents->max_ink_extent.y)) / 2;
244           }
245       }
246     else
247       {
248         myFont = (XtPointer)__DtHelpFontStructGet(pDAS->font_info, idx);
249         if (XGetFontProperty((XFontStruct *)myFont, XA_UNDERLINE_POSITION, 
250                              ((unsigned long *) &(pDAS->underLine))) == FALSE)
251             pDAS->underLine = ((XFontStruct *)myFont)->max_bounds.descent / 2;
252       }
253
254     /*
255      * if we do not find an underline thickness for the font
256      * use 15% of the font height.
257      *
258      * cast the parameter to a pointer to a long though the value
259      * returned is really a unsigned int.
260      */
261     if (idx < 0)
262       {
263         if (get_fontsetproperty((XFontSet)myFont, XA_UNDERLINE_THICKNESS,
264                 ((unsigned long *) ret_underThick)) == FALSE)
265             *ret_underThick = pDAS->lineHeight * 15 / 100;
266       }
267     else
268       {
269         if (XGetFontProperty((XFontStruct *)myFont, XA_UNDERLINE_THICKNESS, 
270                              ((unsigned long *) ret_underThick)) == FALSE)
271             *ret_underThick = pDAS->lineHeight * 15 / 100;
272       }
273
274
275     /*
276      * now adjust the underline depth so that the when the underline is
277      * drawn the top of the line is UNDERLINE_POSITION pixels below
278      * the base line.
279      */
280 /*
281  * SYSTEM - ifdef this for other architectures.
282  * an example of Hewlett-Packard's implementation is given for reference.
283  */
284                 /* On Hewlett-Packard machines lines are */
285                 /* drawn like this:                      */
286                 /*                                       */
287                 /*  line width 1:  y-> ****************  */
288                 /*                                       */
289                 /*                     ****************  */
290                 /*  line width 2:  y-> ****************  */
291                 /*                                       */
292                 /*                     ****************  */
293                 /*  line width 3:  y-> ****************  */
294                 /*                     ****************  */
295                 /*                                       */
296                 /*                     ****************  */
297                 /*                     ****************  */
298                 /*  line width 4:  y-> ****************  */
299                 /*                     ****************  */
300                 /*                                       */
301                 /*                     ****************  */
302                 /*                     ****************  */
303                 /*  line width 5:  y-> ****************  */
304                 /*                     ****************  */
305                 /*                     ****************  */
306                 /* etc......                             */
307                 /*                                       */
308     pDAS->underLine = pDAS->underLine + (*ret_underThick) / 2;
309
310 }
311
312 /*********************************************************************
313  *              Public Functions
314  *********************************************************************/
315 /*********************************************************************
316  * Function: CreateDA
317  *
318  *    CreateDA creates a Text Graphic area with the appropriate scroll bars.
319  *
320  *********************************************************************/
321 static XtPointer
322 HelpCreateDA(
323     Widget       parent,
324     char        *name,
325     short        vert_flag,
326     short        horz_flag,
327     Boolean      traversal_flag,
328     _DtCvValue   honor_size,
329     _DtCvRenderType render_type,
330     int          rows,
331     int          columns,
332     unsigned short media_resolution,
333     void        (*hyperTextCB)(),
334     void        (*resizeCB)(),
335     int         (*exec_ok_routine)(),
336     XtPointer    client_data,
337     XmFontList   default_list )
338 {
339     DtHelpDispAreaStruct *pDAS;
340     DAArgs DA_args;
341     Arg args[20];
342     int n;
343     int maxFontAscent;
344     int maxFontDescent;
345     int maxFontCharWidth;
346   
347     short margin_width;
348     short margin_height;
349     short shadowThick, highThick;
350     Dimension hBarHeight = 0;
351     Dimension vBarWidth  = 0;
352     Dimension width;
353     Boolean   value;
354
355     Widget form;
356     Display *dpy = XtDisplay(parent);
357     Screen      *retScr = XtScreen(parent);
358     int          screen = XScreenNumberOfScreen(retScr);
359
360     Colormap colormap;
361
362     Pixmap               tile;
363     XGCValues            gcValues;
364     unsigned long        gcMask;
365
366     unsigned long char_width;
367
368     Atom xa_ave_width;
369
370     XFontStruct *tmpFont = NULL;
371     XtPointer    default_font = NULL;
372     XRectangle   rectangle[1];
373
374     XmFontContext       fontContext;
375     XmFontListEntry     fontEntry;
376     XmFontType          fontType;
377
378     /* Allocate the Display Area. */
379     pDAS = (DtHelpDispAreaStruct *) XtMalloc(sizeof(DtHelpDispAreaStruct));
380
381    /*
382      * get the resources
383      */
384     XtGetSubresources(parent, &DA_args, name, "XmDrawnButton",
385                     Resources, XtNumber(Resources), NULL, 0);
386
387     if (rows <= 0)
388         rows = 1;
389     if (columns <= 0)
390         columns = 1;
391
392     /*
393      * initialize the structure variables.
394      */
395     pDAS->text_selected = False;
396     pDAS->primary       = False;
397     pDAS->select_state  = _DtHelpNothingDoing;
398     pDAS->toc_y         = 0;
399     pDAS->toc_base      = 0;
400     pDAS->toc_flag      = 0;
401     if (traversal_flag)
402         pDAS->toc_flag  = _DT_HELP_SHADOW_TRAVERSAL | _DT_HELP_NOT_INITIALIZED;
403
404     pDAS->max_spc       = 0;
405     pDAS->cur_spc       = 0;
406     pDAS->maxX          = 0;
407     pDAS->virtualX      = 0;
408     pDAS->firstVisible  = 0;
409     pDAS->visibleCount  = rows;
410     pDAS->maxYpos       = 0;
411     pDAS->neededFlags   = 0;
412     pDAS->vert_init_scr = DA_args.initialDelay;
413     pDAS->vert_rep_scr  = DA_args.repeatDelay;
414     pDAS->horz_init_scr = DA_args.initialDelay;
415     pDAS->horz_rep_scr  = DA_args.repeatDelay;
416     pDAS->moveThreshold = DA_args.moveThreshold;
417     pDAS->marginWidth   = DA_args.marginWidth;
418     pDAS->marginHeight  = DA_args.marginHeight;
419     pDAS->searchColor   = DA_args.search_color;
420     pDAS->depth         = 0;
421     pDAS->spc_chars     = NULL;
422     pDAS->scr_timer_id  = NULL;
423     pDAS->def_pix       = NULL;
424     pDAS->context       = NULL;
425     pDAS->vertIsMapped  = False;
426     pDAS->horzIsMapped  = False;
427     pDAS->lst_topic     = NULL;
428     pDAS->nextNonVisible = 0;
429     pDAS->media_resolution = media_resolution;
430     pDAS->honor_size = honor_size;
431     pDAS->render_type = render_type;
432     pDAS->dtinfo = 0;
433     pDAS->stipple = None;
434
435     /*
436      * locale dependant information
437      */
438     pDAS->nl_to_space      = 1;
439     pDAS->cant_begin_chars = NULL;
440     pDAS->cant_end_chars   = NULL;
441     if (1 < MB_CUR_MAX)
442         _DtHelpLoadMultiInfo (&(pDAS->cant_begin_chars),
443                                 &(pDAS->cant_end_chars), &(pDAS->nl_to_space));
444
445     /*
446      * initialize the hypertext callback pointer
447      */
448     pDAS->exec_filter = exec_ok_routine;
449     pDAS->hyperCall   = hyperTextCB;
450     pDAS->resizeCall  = resizeCB;
451     pDAS->clientData  = client_data;
452
453     /*
454      * zero out other callback fields
455      */
456     pDAS->vScrollNotify = NULL ;
457     pDAS->armCallback = NULL ;
458
459     /*
460      * create the atoms needed
461      */
462     xa_ave_width = XmInternAtom(dpy, "AVERAGE_WIDTH"     , False);
463
464     /*
465      * Malloc for the default font.
466      */
467     (void) XmeRenderTableGetDefaultFont(DA_args.userFont, &tmpFont);
468     if (default_list != NULL &&
469                 XmFontListInitFontContext (&fontContext, default_list))
470       {
471         fontEntry = XmFontListNextEntry (fontContext);
472         if (fontEntry != NULL)
473             default_font = XmFontListEntryGetFont (fontEntry, &fontType);
474
475         XmFontListFreeFontContext (fontContext);
476       }
477
478     /*
479      * fake out the next call by using the parent as the display widget
480      */
481     pDAS->dispWid = parent;
482     __DtHelpFontDatabaseInit (pDAS, default_font, fontType, tmpFont);
483
484     /*
485      * Get the base font meterics.
486      */
487     __DtHelpFontMetrics (pDAS->font_info, __DtHelpDefaultFontIndexGet(pDAS),
488                         &maxFontAscent, &maxFontDescent, &maxFontCharWidth,
489                         NULL, NULL);
490
491     pDAS->leading    = DA_args.leading;
492     pDAS->fontAscent = maxFontAscent;
493     pDAS->lineHeight = maxFontAscent + maxFontDescent + pDAS->leading + 1;
494
495     n = __DtHelpDefaultFontIndexGet(pDAS);
496     if (n < 0)
497         value = get_fontsetproperty(__DtHelpFontSetGet(pDAS->font_info, n),
498                         xa_ave_width, ((unsigned long *) &(pDAS->charWidth)));
499     else
500         value = XGetFontProperty(__DtHelpFontStructGet(pDAS->font_info, n),
501                         xa_ave_width, ((unsigned long *) &(pDAS->charWidth)));
502
503     if (False == value || 0 == pDAS->charWidth)
504       {
505         int len = maxFontCharWidth;
506
507         if (n < 0)
508             len += XmbTextEscapement(
509                                 __DtHelpFontSetGet(pDAS->font_info,n),"1",1);
510         else
511             len += XTextWidth(__DtHelpFontStructGet(pDAS->font_info, n),"1",1);
512
513         pDAS->charWidth = 10 * len / 2;
514       }
515
516     /*
517      * Create the form to manage the window and scroll bars.
518      */
519     n = 0;
520     XtSetArg(args[n], XmNresizePolicy      , XmRESIZE_ANY);             ++n;
521     XtSetArg(args[n], XmNshadowType     , XmSHADOW_OUT);                ++n;
522     form = XmCreateForm(parent, "DisplayAreaForm", args, n);
523     XtManageChild(form);
524
525     /*
526      * force the shadowThickness to zero. The XmManager will try to set
527      * this to one.
528      */
529     n = 0;
530     XtSetArg(args[n], XmNshadowThickness   , 0);                        ++n;
531     XtSetArg(args[n], XmNhighlightThickness, 0);                        ++n;
532     XtSetValues (form, args, n);
533
534     /*
535      * get the colors and margin widths and heights
536      */
537     n = 0;
538     XtSetArg (args[n], XmNmarginWidth , &margin_width);         ++n;
539     XtSetArg (args[n], XmNmarginHeight, &margin_height);        ++n;
540     XtSetArg (args[n], XmNcolormap    , &colormap);             ++n;
541     XtGetValues(form, args, n);
542
543     /* Create the vertical scrollbar. */
544     pDAS->vertScrollWid = NULL;
545     if (vert_flag != _DtHelpNONE)
546       {
547         if (vert_flag == _DtHelpSTATIC)
548             pDAS->vertIsMapped = True;
549
550         n = 0;
551         XtSetArg(args[n], XmNtopAttachment     , XmATTACH_FORM);        ++n;
552         XtSetArg(args[n], XmNtopOffset         , 0);                    ++n;
553         XtSetArg(args[n], XmNbottomAttachment  , XmATTACH_FORM);        ++n;
554         XtSetArg(args[n], XmNbottomOffset      , margin_height);        ++n;
555         XtSetArg(args[n], XmNrightAttachment   , XmATTACH_FORM);        ++n;
556         XtSetArg(args[n], XmNrightOffset       , 0);                    ++n;
557         XtSetArg(args[n], XmNorientation       , XmVERTICAL);           ++n;
558         XtSetArg(args[n], XmNtraversalOn       , True);                 ++n;
559         XtSetArg(args[n], XmNhighlightThickness, 1);                    ++n;
560         XtSetArg(args[n], XmNshadowType        , XmSHADOW_IN);          ++n;
561         XtSetArg(args[n], XmNvalue             , 0);                    ++n;
562         XtSetArg(args[n], XmNminimum           , 0);                    ++n;
563         /* fake out the scrollbar manager, who will init dims to 100 */
564         XtSetArg(args[n], XmNheight            , 1);                    ++n;
565         XtSetArg(args[n], XmNmaximum           , 1);                    ++n;
566         XtSetArg(args[n], XmNincrement         , 1);                    ++n;
567         XtSetArg(args[n], XmNpageIncrement     , 1);                    ++n;
568         XtSetArg(args[n], XmNsliderSize        , 1);                    ++n;
569         XtSetArg(args[n], XtNmappedWhenManaged , pDAS->vertIsMapped);   ++n;
570         pDAS->vertScrollWid = XmCreateScrollBar(form,
571                                         "DisplayDtHelpVertScrollBar", args, n);
572
573         XtManageChild(pDAS->vertScrollWid);
574         if (vert_flag != _DtHelpSTATIC)
575             pDAS->neededFlags = _DtHelpSET_AS_NEEDED (pDAS->neededFlags,
576                                                 _DtHelpVERTICAL_SCROLLBAR);
577   
578         XtAddCallback(pDAS->vertScrollWid, XmNdragCallback,
579                                         _DtHelpVertScrollCB, (XtPointer) pDAS);
580         XtAddCallback(pDAS->vertScrollWid, XmNincrementCallback,
581                                         _DtHelpVertScrollCB, (XtPointer) pDAS);
582         XtAddCallback(pDAS->vertScrollWid, XmNdecrementCallback,
583                                         _DtHelpVertScrollCB, (XtPointer) pDAS);
584         XtAddCallback(pDAS->vertScrollWid, XmNpageIncrementCallback,
585                                         _DtHelpVertScrollCB, (XtPointer) pDAS);
586         XtAddCallback(pDAS->vertScrollWid, XmNpageDecrementCallback,
587                                         _DtHelpVertScrollCB, (XtPointer) pDAS);
588         XtAddCallback(pDAS->vertScrollWid, XmNtoBottomCallback,
589                                         _DtHelpVertScrollCB, (XtPointer) pDAS);
590         XtAddCallback(pDAS->vertScrollWid, XmNtoTopCallback,
591                                         _DtHelpVertScrollCB, (XtPointer) pDAS);
592         XtAddCallback(pDAS->vertScrollWid, XmNvalueChangedCallback,
593                                         _DtHelpVertScrollCB, (XtPointer) pDAS);
594
595         XtAddEventHandler (pDAS->vertScrollWid, ButtonPressMask, True,
596                         (XtEventHandler)_DtHelpMoveBtnFocusCB,(XtPointer) pDAS);
597
598       }
599
600     /* Create the horizontal scrollbar. */
601     pDAS->horzScrollWid = NULL;
602     if (horz_flag != _DtHelpNONE)
603       {
604         if (horz_flag == _DtHelpSTATIC)
605             pDAS->horzIsMapped = True;
606
607         n = 0;
608         XtSetArg(args[n], XmNbottomAttachment  , XmATTACH_FORM);        ++n;
609         XtSetArg(args[n], XmNbottomOffset      , 0);                    ++n;
610         XtSetArg(args[n], XmNrightAttachment   , XmATTACH_FORM);        ++n;
611         XtSetArg(args[n], XmNrightOffset       , margin_width);         ++n;
612         XtSetArg(args[n], XmNleftAttachment    , XmATTACH_FORM);        ++n;
613         XtSetArg(args[n], XmNleftOffset        , 0);                    ++n;
614         XtSetArg(args[n], XmNorientation       , XmHORIZONTAL);         ++n;
615         XtSetArg(args[n], XmNtraversalOn       , True);                 ++n;
616         XtSetArg(args[n], XmNhighlightThickness, 1);                    ++n;
617         XtSetArg(args[n], XmNshadowType        , XmSHADOW_IN);          ++n;
618         XtSetArg(args[n], XmNvalue             , 0);                    ++n;
619         XtSetArg(args[n], XmNminimum           , 0);                    ++n;
620         XtSetArg(args[n], XmNmaximum           , (pDAS->charWidth/10)); ++n;
621         /* fake out the scrollbar manager, who will init dims to 100 */
622         XtSetArg(args[n], XmNwidth             , 1);                    ++n;
623         XtSetArg(args[n], XmNincrement         , (pDAS->charWidth/10)); ++n;
624         XtSetArg(args[n], XmNpageIncrement     , (pDAS->charWidth/10)); ++n;
625         XtSetArg(args[n], XmNsliderSize        , (pDAS->charWidth/10)); ++n;
626         XtSetArg(args[n], XtNmappedWhenManaged , pDAS->horzIsMapped);   ++n;
627         pDAS->horzScrollWid = XmCreateScrollBar(form,
628                                         "DisplayHorzScrollBar", args, n);
629         XtManageChild(pDAS->horzScrollWid);
630         if (horz_flag != _DtHelpSTATIC)
631             pDAS->neededFlags = _DtHelpSET_AS_NEEDED (pDAS->neededFlags,
632                                                 _DtHelpHORIZONTAL_SCROLLBAR);
633   
634         XtAddCallback(pDAS->horzScrollWid, XmNdragCallback,
635                                         _DtHelpHorzScrollCB, (XtPointer) pDAS);
636         XtAddCallback(pDAS->horzScrollWid, XmNincrementCallback,
637                                         _DtHelpHorzScrollCB, (XtPointer) pDAS);
638         XtAddCallback(pDAS->horzScrollWid, XmNdecrementCallback,
639                                         _DtHelpHorzScrollCB, (XtPointer) pDAS);
640         XtAddCallback(pDAS->horzScrollWid, XmNpageIncrementCallback,
641                                         _DtHelpHorzScrollCB, (XtPointer) pDAS);
642         XtAddCallback(pDAS->horzScrollWid, XmNpageDecrementCallback,
643                                         _DtHelpHorzScrollCB, (XtPointer) pDAS);
644         XtAddCallback(pDAS->horzScrollWid, XmNtoBottomCallback,
645                                         _DtHelpHorzScrollCB, (XtPointer) pDAS);
646         XtAddCallback(pDAS->horzScrollWid, XmNtoTopCallback,
647                                         _DtHelpHorzScrollCB, (XtPointer) pDAS);
648         XtAddCallback(pDAS->horzScrollWid, XmNvalueChangedCallback,
649                                         _DtHelpHorzScrollCB, (XtPointer) pDAS);
650       }
651
652     /*
653      * check for the horizontal attachments
654      */
655     n = 0;
656     if (horz_flag == _DtHelpSTATIC)
657       {
658         XtSetArg(args[n], XmNbottomAttachment  , XmATTACH_WIDGET);      ++n;
659         XtSetArg(args[n], XmNbottomWidget      , pDAS->horzScrollWid);  ++n;
660       }
661     else
662       {
663         XtSetArg(args[n], XmNbottomAttachment  , XmATTACH_FORM);        ++n;
664       }
665
666     /*
667      * check for the vertical attachments
668      */
669     if (vert_flag == _DtHelpSTATIC)
670       {
671         XtSetArg(args[n], XmNrightAttachment   , XmATTACH_WIDGET);      ++n;
672         XtSetArg(args[n], XmNrightWidget       , pDAS->vertScrollWid);  ++n;
673       }
674     else
675       {
676         XtSetArg(args[n], XmNrightAttachment  , XmATTACH_FORM);         ++n;
677       }
678
679     /*
680      * do the rest of the arguments
681      */
682     XtSetArg(args[n], XmNbottomOffset      , margin_height);            ++n;
683     XtSetArg(args[n], XmNrightOffset       , margin_width);             ++n;
684     XtSetArg(args[n], XmNtopAttachment     , XmATTACH_FORM);            ++n;
685     XtSetArg(args[n], XmNtopOffset         , 0);                        ++n;
686     XtSetArg(args[n], XmNleftAttachment    , XmATTACH_FORM);            ++n;
687     XtSetArg(args[n], XmNleftOffset        , 0);                        ++n;
688     XtSetArg(args[n], XmNrecomputeSize     , False);                    ++n;
689     XtSetArg(args[n], XmNpushButtonEnabled , False);                    ++n;
690     XtSetArg(args[n], XmNtraversalOn       , True);                     ++n;
691     XtSetArg(args[n], XmNhighlightThickness, 1);                        ++n;
692     XtSetArg(args[n], XmNshadowType        , XmSHADOW_IN);              ++n;
693     XtSetArg(args[n], XmNmultiClick        , XmMULTICLICK_DISCARD);     ++n;
694     XtSetArg(args[n], XmNuserData          , pDAS);                     ++n;
695     pDAS->dispWid = XmCreateDrawnButton(form, name, args, n);
696     XtManageChild(pDAS->dispWid);
697   
698     XtAddCallback(pDAS->dispWid, XmNexposeCallback, _DtHelpExposeCB,
699                                                 (XtPointer) pDAS);
700     XtAddCallback(pDAS->dispWid, XmNresizeCallback, _DtHelpResizeCB,
701                                                 (XtPointer) pDAS);
702     XtAddCallback(pDAS->dispWid, XmNarmCallback, _DtHelpClickOrSelectCB,
703                                                 (XtPointer) pDAS);
704     XtAddCallback(pDAS->dispWid, XmNdisarmCallback, _DtHelpEndSelectionCB,
705                                                 (XtPointer) pDAS);
706
707     XtAddEventHandler (pDAS->dispWid, Button1MotionMask, True,
708                         (XtEventHandler)_DtHelpMouseMoveCB, (XtPointer) pDAS);
709
710     /*
711      * add my actions
712      * parse the translations.
713      */
714     _DtHelpProcessLock();
715     if (DrawnBTrans == NULL)
716         DrawnBTrans = XtParseTranslationTable(DrawnBTransTable);
717
718      /*
719      * override the translations
720     XtSetArg(args[n], XmNtranslations      , DrawnBTrans);              ++n;
721      */
722     if (DrawnBTrans != NULL)
723         XtOverrideTranslations(pDAS->dispWid, DrawnBTrans);
724     _DtHelpProcessUnlock();
725   
726     if (_XmGetFocusPolicy(parent) == XmPOINTER)
727       {
728         XtAddEventHandler (pDAS->dispWid, EnterWindowMask, True,
729                         (XtEventHandler)_DtHelpEnterLeaveCB, (XtPointer) pDAS);
730         XtAddEventHandler (pDAS->dispWid, LeaveWindowMask, True,
731                         (XtEventHandler)_DtHelpEnterLeaveCB, (XtPointer) pDAS);
732       }
733     else
734         XtAddEventHandler (pDAS->dispWid, FocusChangeMask, True,
735                         (XtEventHandler)_DtHelpFocusCB, (XtPointer) pDAS);
736
737     XtAddEventHandler (pDAS->dispWid, VisibilityChangeMask, True,
738                         (XtEventHandler)_DtHelpVisibilityCB, (XtPointer) pDAS);
739   
740
741     /* Add a destroy callback so that the display area can clean up prior to
742      * the help widget getting destroyed (e.g. display area's parent) 
743      */
744     XtAddCallback(pDAS->dispWid, XmNdestroyCallback,
745                                 _DtHelpDisplayAreaDestroyCB, (XtPointer) pDAS);
746   
747     n = 0;
748     XtSetArg(args[n], XmNshadowThickness   , &shadowThick);     ++n;
749     XtSetArg(args[n], XmNhighlightThickness, &highThick);       ++n;
750     XtSetArg(args[n], XmNforeground    , &(pDAS->foregroundColor)); ++n;
751     XtSetArg(args[n], XmNbackground    , &(pDAS->backgroundColor)); ++n;
752     XtSetArg(args[n], XmNhighlightColor, &(pDAS->traversalColor) ); ++n;
753     XtSetArg(args[n], XmNdepth         , &(pDAS->depth)          ); ++n;
754     XtGetValues(pDAS->dispWid, args, n);
755     pDAS->decorThickness = shadowThick + highThick;
756
757     /*
758      * Get the underline information
759      */
760     GetUnderLineInfo (dpy, pDAS, &(pDAS->lineThickness));
761
762     /*
763      * get the tiling pattern.
764      */
765     tile = XmGetPixmap (XtScreen(pDAS->dispWid), "50_foreground",
766                                 pDAS->foregroundColor, pDAS->backgroundColor);
767
768     /*
769      * Get the data for the graphics contexts and create the GC's.
770      */
771     gcMask = (GCFunction   | GCPlaneMask   | GCForeground  |
772                 GCBackground  | GCLineWidth   | GCLineStyle   |
773                 GCClipXOrigin | GCClipYOrigin | GCClipMask);
774
775     gcValues.function      = GXcopy;
776     gcValues.plane_mask    = AllPlanes;
777     gcValues.foreground    = pDAS->foregroundColor;
778     gcValues.background    = pDAS->backgroundColor;
779     gcValues.line_style    = LineSolid;
780     gcValues.line_width    = pDAS->lineThickness;
781     gcValues.clip_x_origin = 0;
782     gcValues.clip_y_origin = 0;
783     gcValues.clip_mask     = None;
784     if (tile)
785       {
786         gcMask |= GCTile;
787         gcValues.tile = tile;
788       }
789  
790     pDAS->normalGC = XCreateGC(dpy,
791                 RootWindowOfScreen(XtScreen(pDAS->dispWid)), gcMask, &gcValues);
792
793     gcMask &= (~GCTile);
794     pDAS->pixmapGC = XCreateGC(dpy,
795                 RootWindowOfScreen(XtScreen(pDAS->dispWid)), gcMask, &gcValues);
796   
797     gcValues.foreground = pDAS->backgroundColor;
798     gcValues.background = pDAS->foregroundColor;
799     pDAS->invertGC = XCreateGC(dpy,
800                 RootWindowOfScreen(XtScreen(pDAS->dispWid)), gcMask, &gcValues);
801   
802     /*
803      * Set the size of the text view area to the requested
804      * number of columns and lines.
805      */
806     char_width          = pDAS->charWidth * columns;
807
808     /*
809      * Make sure the margins include enough room for a traversal line
810      */
811     if (((int) pDAS->marginWidth) < pDAS->lineThickness)
812         pDAS->marginWidth = pDAS->lineThickness;
813     if (((int) pDAS->marginHeight) < pDAS->lineThickness)
814         pDAS->marginHeight = pDAS->lineThickness;
815     if (pDAS->leading < pDAS->lineThickness)
816         pDAS->leading = pDAS->lineThickness;
817
818     /*
819      * get the scrollbar widths.
820      */
821     if (NULL != pDAS->horzScrollWid)
822       {
823         n = 0;
824         XtSetArg(args[n], XmNheight      , &hBarHeight); n++;
825         XtSetArg(args[n], XmNinitialDelay, &(pDAS->horz_init_scr)); n++;
826         XtSetArg(args[n], XmNrepeatDelay , &(pDAS->horz_rep_scr));  n++;
827         XtGetValues(pDAS->horzScrollWid, args, n);
828       }
829
830     if (NULL != pDAS->vertScrollWid)
831       {
832         n = 0;
833         XtSetArg(args[n], XmNwidth       , &vBarWidth);             n++;
834         XtSetArg(args[n], XmNinitialDelay, &(pDAS->vert_init_scr)); n++;
835         XtSetArg(args[n], XmNrepeatDelay , &(pDAS->vert_rep_scr));  n++;
836         XtGetValues(pDAS->vertScrollWid, args, n);
837       }
838
839     /*
840      * calculate the display area height/width
841      */
842     pDAS->dispUseWidth  = ((int) (char_width / 10 + (char_width % 10 ? 1 : 0)))
843                                               + 2 * pDAS->marginWidth;
844     if (vert_flag != _DtHelpSTATIC && pDAS->dispUseWidth < vBarWidth)
845         pDAS->dispUseWidth = vBarWidth;
846     pDAS->dispWidth     = pDAS->dispUseWidth  + 2 * pDAS->decorThickness;
847
848     pDAS->dispUseHeight = pDAS->lineHeight * rows;
849     if (horz_flag != _DtHelpSTATIC && pDAS->dispUseHeight < hBarHeight)
850         pDAS->dispUseHeight = hBarHeight;
851     pDAS->dispHeight    = pDAS->dispUseHeight + 2 * pDAS->decorThickness;
852
853     /*
854      * Truncate the width and height to the size of the display.
855      * This will prevent an X protocal error when it is asked for
856      * a too large size. Besides, any decent window manager will
857      * force the overall size to the height and width of the display.
858      * This simply refines the size down to a closer (but not perfect)
859      * fit.
860      */
861     if (((int) pDAS->dispWidth) > XDisplayWidth (dpy, screen)) {
862         pDAS->dispWidth = XDisplayWidth (dpy, screen);
863     }
864     if (((int) pDAS->dispHeight) > XDisplayHeight (dpy, screen)) {
865         pDAS->dispHeight = XDisplayHeight (dpy, screen);
866     }
867
868     n = 0;
869     pDAS->formWidth  = 0;
870     pDAS->formHeight = 0;
871     XtSetArg(args[n], XmNwidth, pDAS->dispWidth);               ++n;
872     XtSetArg(args[n], XmNheight, pDAS->dispHeight);             ++n;
873     XtSetValues(pDAS->dispWid, args, n);
874
875     /*
876      * set the scroll bar values
877      */
878     if (pDAS->vertScrollWid != NULL)
879       {
880         n = 0;
881         XtSetArg(args[n], XmNmaximum           , pDAS->dispUseHeight);  ++n;
882         XtSetArg(args[n], XmNincrement         , pDAS->lineHeight);     ++n;
883         XtSetArg(args[n], XmNpageIncrement     , pDAS->lineHeight);     ++n;
884         XtSetArg(args[n], XmNsliderSize        , pDAS->dispUseHeight);  ++n;
885         XtSetValues(pDAS->vertScrollWid, args, n);
886       }
887   
888     if (pDAS->resizeCall)
889         (*(pDAS->resizeCall)) (pDAS->clientData);
890
891     /*
892      * calculate the offset for the right edge of the
893      * horizontal scrollbar.
894      */
895     if (vert_flag == _DtHelpSTATIC && pDAS->horzScrollWid)
896       {
897         width = vBarWidth + margin_width;
898
899         XtSetArg(args[0], XmNrightOffset , width);
900         XtSetValues(pDAS->horzScrollWid, args, 1);
901       }
902
903     /*
904      * calculate the offset for the bottom end of the
905      * vertical scrollbar.
906      */
907     if (horz_flag == _DtHelpSTATIC && pDAS->vertScrollWid)
908       {
909         width = hBarHeight + margin_height;
910
911         XtSetArg(args[0], XmNbottomOffset , width);
912         XtSetValues(pDAS->vertScrollWid, args, 1);
913       }
914
915     rectangle[0].x      = pDAS->decorThickness;
916     rectangle[0].y      = pDAS->decorThickness;
917     rectangle[0].width  = pDAS->dispUseWidth;
918     rectangle[0].height = pDAS->dispUseHeight;
919     XSetClipRectangles(XtDisplay(pDAS->dispWid), pDAS->normalGC, 0, 0,
920                                                 rectangle, 1, Unsorted);
921     XSetClipRectangles(XtDisplay(pDAS->dispWid), pDAS->invertGC, 0, 0,
922                                                 rectangle, 1, Unsorted);
923
924     /*
925      * get the colormap and the visual
926      */
927     if (!XtIsShell(parent) && XtParent(parent) != NULL)
928         parent = XtParent(parent);
929
930     pDAS->visual = NULL;
931
932     n = 0;
933     XtSetArg (args[n], XmNcolormap, &(pDAS->colormap)); n++;
934     XtSetArg (args[n], XmNvisual  , &(pDAS->visual  )); n++;
935     XtGetValues (parent, args, n);
936
937     if (pDAS->visual == NULL)
938         pDAS->visual = XDefaultVisualOfScreen(XtScreen(pDAS->dispWid));
939
940     /*
941      * set up the canvas
942      */
943     _DtHelpProcessLock();
944     DefVirtFunctions.exec_cmd_filter = exec_ok_routine;
945
946     pDAS->canvas = _DtCanvasCreate (DefVirtFunctions, (_DtCvPointer) pDAS);
947     _DtHelpProcessUnlock();
948
949     return (XtPointer) pDAS;
950
951 }  /* End _DtHelpCreateDA */
952
953
954 /*********************************************************************
955  * Function: CreateDisplayArea
956  *
957  *    Creates a Text Graphic area with the appropriate scroll bars.
958  *    specifying the size with rows and columns
959  *
960  *********************************************************************/
961 XtPointer
962 _DtHelpCreateDisplayArea(
963     Widget       parent,
964     char        *name,
965     short        vert_flag,
966     short        horz_flag,
967     Boolean      traversal_flag,
968     int          rows,
969     int          columns,
970     void        (*hyperTextCB)(),
971     void        (*resizeCB)(),
972     int         (*exec_ok_routine)(),
973     XtPointer    client_data,
974     XmFontList   default_list )
975 {
976     return HelpCreateDA(parent, name,
977                         vert_flag, horz_flag,
978                         traversal_flag,
979                         _DtCvIGNORE_BOUNDARY, _DtCvRENDER_PARTIAL,
980                         rows, columns, 100,
981                         hyperTextCB, resizeCB, exec_ok_routine,
982                         client_data, default_list);
983 }
984
985 /*********************************************************************
986  * Function: CreateOutputArea
987  *
988  *    Creates a Text Graphic area with the appropriate scroll bars.
989  *    specifying the size with width and height
990  *
991  *********************************************************************/
992 XtPointer
993 _DtHelpCreateOutputArea(
994     Widget       parent,
995     char        *name,
996     short        vert_flag,
997     short        horz_flag,
998     Boolean      traversal_flag,
999     _DtCvValue   honor_size,
1000     _DtCvRenderType render_type,
1001     Dimension    width,
1002     Dimension    height,
1003     unsigned short media_resolution,
1004     void        (*hyperTextCB)(),
1005     void        (*resizeCB)(),
1006     int         (*exec_ok_routine)(),
1007     XtPointer    client_data,
1008     XmFontList   default_list )
1009 {
1010     DtHelpDispAreaStruct *pDAS;
1011
1012     pDAS = HelpCreateDA(parent, name,
1013                         vert_flag, horz_flag,
1014                         traversal_flag, honor_size, render_type,
1015                         1, 1, media_resolution,
1016                         hyperTextCB, resizeCB, exec_ok_routine,
1017                         client_data, default_list);
1018     /* if area created successfully, then resize it to the given size */
1019     if (pDAS)
1020         _DtHelpSetScrollBars(pDAS, width, height);
1021
1022     return pDAS;
1023 }