Link with C++ linker
[oweals/cde.git] / cde / programs / dtfile / IconWindow.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: IconWindow.c /main/13 1996/10/15 10:07:48 mustafa $ */
24 /************************************<+>*************************************
25  ****************************************************************************
26  *
27  *   FILE:           IconWindow.c
28  *
29  *   COMPONENT_NAME: Desktop File Manager (dtfile)
30  *
31  *   Description:    Processing functions for callbacks from the
32  *                   icon display area.
33  *
34  *   FUNCTIONS: CheckForBtnUp
35  *              DrawHighlight
36  *              DrawRectangle
37  *              DrawShadowTh
38  *              DrawUnhighlight
39  *              FM_XmHighlightBorder
40  *              FM_XmUnhighlightBorder
41  *              FileWindowExposeCallback
42  *              FileWindowInputCallback
43  *              FileWindowMapCallback
44  *              FileWindowResizeCallback
45  *              GetSelectionRectangle
46  *              ProcessSelection
47  *              WidgetRectToRegion
48  *
49  *   (c) Copyright 1993, 1994, 1995 Hewlett-Packard Company
50  *   (c) Copyright 1993, 1994, 1995 International Business Machines Corp.
51  *   (c) Copyright 1993, 1994, 1995 Sun Microsystems, Inc.
52  *   (c) Copyright 1993, 1994, 1995 Novell, Inc.
53  *
54  ****************************************************************************
55  ************************************<+>*************************************/
56
57 #include <Xm/Xm.h>
58 #include <Xm/XmP.h>
59 #include <Xm/TextF.h>
60 #include <Xm/VirtKeys.h>
61
62 #include <sys/types.h>
63 #include <sys/stat.h>
64
65 #include <Dt/Icon.h>
66 #include <Dt/IconP.h>
67 #include <Dt/Connect.h>
68 #include <Dt/DtNlUtils.h>
69 #include <Dt/Action.h>
70
71 #include <X11/cursorfont.h>
72 #include <X11/Xutil.h>
73 #include <X11/keysymdef.h>
74 #include <Xm/PrimitiveP.h>  /* For HighlightBorder & UnhighlightBorder */
75
76 #include "Encaps.h"
77 #include "FileMgr.h"
78 #include "Desktop.h"
79 #include "Main.h"
80 #include "Prefs.h"
81 #include "Common.h"
82 #include "Filter.h"
83
84                            /* For HightlightBorder & UnhighlightBorder */
85 externalref XmPrimitiveClassRec xmPrimitiveClassRec;
86
87 Boolean TurnOnTextName;
88
89 /********    Static Function Declarations    ********/
90
91 static Boolean CheckForBtnUp(
92                         Display *display,
93                         XEvent *event,
94                         XtPointer arg) ;
95 static void GetSelectionRectangle(
96                         Display *display,
97                         Window window,
98                         XButtonEvent *event,
99                         FileMgrRec *file_mgr_rec,
100                         FileMgrData *file_mgr_data,
101                         Boolean toggleSelect) ;
102 static void DrawRectangle(
103                         Display *display,
104                         Window window,
105                         GC gc,
106                         int x1,
107                         int y1,
108                         int x2,
109                         int y2) ;
110 static void ProcessSelection(
111                         FileMgrData * file_mgr_data,
112                         Widget icon,
113                         Boolean toggleSelect,
114                         XButtonEvent *event) ;
115
116 static void FM_XmHighlightBorder(Widget w);
117 static void FM_XmUnhighlightBorder(Widget w);
118
119 static XmGadget InputForGadget(
120                         Widget wid,
121                         int x,
122                         int y ) ;
123
124
125 /********    End Static Function Declarations    ********/
126
127
128 /************************************************************************
129  *
130  *  FileWindowExposeCallback
131  *      Callback function invoked upon an exposure event occuring
132  *      in the file display area.
133  *
134  ************************************************************************/
135
136 void
137 FileWindowExposeCallback(
138         Widget w,
139         XtPointer client_data,
140         XtPointer call_data )
141 {
142    FileMgrRec  * file_mgr_rec;
143    DialogData  * dialog_data;
144    FileMgrData * file_mgr_data;
145    XmDrawingAreaCallbackStruct * da_cbs;
146    register int i;
147
148    file_mgr_rec = (FileMgrRec *) client_data;
149    dialog_data = _DtGetInstanceData ((XtPointer)file_mgr_rec);
150
151    /*  Check for the view already being closed  */
152
153    if (dialog_data == NULL) return;
154
155    file_mgr_data = (FileMgrData *) dialog_data->data;
156    da_cbs = (XmDrawingAreaCallbackStruct * )call_data;
157
158    /* if necessary, redraw tree lines */
159    if (da_cbs->reason == XmCR_EXPOSE &&
160        file_mgr_data->show_type == MULTIPLE_DIRECTORY)
161    {
162      XExposeEvent *event = (XExposeEvent *)da_cbs->event;
163      if (event && event->type == Expose)
164        RedrawTreeLines(w, event->x, event->y, event->width, event->height,
165                        event->count, file_mgr_rec, file_mgr_data);
166      else
167        RedrawTreeLines(w, 0, 0, 999999, 999999, 0, file_mgr_rec, file_mgr_data);
168    }
169
170 }
171
172
173
174
175 /************************************************************************
176  *
177  *  FileWindowResizeCallback
178  *      Callback function invoked upon a resize of the  file display area.
179  *
180  ************************************************************************/
181
182 void
183 FileWindowResizeCallback(
184         Widget w,
185         XtPointer client_data,
186         XEvent *event )
187 {
188    FileMgrRec  * file_mgr_rec;
189    DialogData  * dialog_data;
190    FileMgrData * file_mgr_data;
191
192    if (event->type == ConfigureNotify)
193    {
194       XConfigureEvent * cevent = (XConfigureEvent *) event;
195
196       file_mgr_rec = (FileMgrRec *) client_data;
197
198       /*
199        * If the incoming size is different than the current size of the
200        * scrolled window, then ignore this event, since it means that our
201        * size has changed since this configure notify event was generated;
202        * we'll wait for the next one to arrive, and try again.
203        */
204       if ((file_mgr_rec->scroll_window->core.height != cevent->height) ||
205           (file_mgr_rec->scroll_window->core.width != cevent->width))
206       {
207          return;
208       }
209
210       dialog_data = _DtGetInstanceData ((XtPointer)file_mgr_rec);
211       if(dialog_data != NULL)
212       {
213          file_mgr_data = (FileMgrData *) dialog_data->data;
214
215          LayoutFileIcons (file_mgr_rec, file_mgr_data, False, False);
216       }
217    }
218 }
219
220
221 /************************************************************************
222  *
223  *  FileWindowMapCallback
224  *      Callback function invoked upon a map or unmap of a file
225  *      manager window.
226  *
227  ************************************************************************/
228
229 void
230 FileWindowMapCallback(
231         Widget w,
232         XtPointer client_data,
233         XEvent *event )
234 {
235    FileMgrRec  * file_mgr_rec;
236    DialogData  * dialog_data;
237    FileMgrData * file_mgr_data;
238
239    file_mgr_rec = (FileMgrRec *) client_data;
240    dialog_data = _DtGetInstanceData ((XtPointer)file_mgr_rec);
241    if(dialog_data != NULL)
242    {
243       file_mgr_data = (FileMgrData *) dialog_data->data;
244
245       if (event->type == MapNotify)
246       {
247          file_mgr_data->mapped = True;
248          FileWindowMapUnmap( file_mgr_data );
249       }
250       else if (event->type == UnmapNotify)
251       {
252          file_mgr_data->mapped = False;
253          FileWindowMapUnmap( file_mgr_data );
254       }
255    }
256 }
257
258
259
260 /************************************************************************
261  *
262  *  FileWindowInputCallback
263  *      Callback function invoked upon input occuring in the 
264  *      file display area, file icon, or within a desktop icon.
265  *
266  ************************************************************************/
267
268 void
269 FileWindowInputCallback(
270         Widget w,
271         XtPointer client_data,
272         XtPointer call_data)
273 {
274    static Boolean first = True;
275    static KeySym PlusKeysym, MinusKeySym;
276    static KeySym ActivateKeysym, SpaceKeysym;
277    static XmKeyBinding SelectBindings;
278    static int NumSelectKeys = 0;
279
280    FileMgrRec  * file_mgr_rec;
281    XmAnyCallbackStruct * callback;
282    DialogData  * dialog_data;
283    FileMgrData * file_mgr_data;
284    DirectorySet * directoryData;
285    XEvent *new_event;
286    XButtonPressedEvent *event;
287    XKeyEvent *kevent;
288    Widget eventIcon;
289    int i, j;
290    FileViewData * fileViewData = NULL;
291    Arg args[10];
292    DesktopRec * desktopRec;
293    KeySym keysym;
294    Modifiers modif;
295    int offset;
296    Boolean found;
297
298    /* Do nothing if a Button 2 drag is already ramping up */
299    if (B2DragPossible)
300       return;
301
302    /* Determine if this is a desktop icon or a regular icon */
303    file_mgr_rec = NULL;
304    desktopRec = NULL;
305    for (i = 0; i < desktop_data->numIconsUsed; i++)
306    {
307       if (desktop_data->desktopWindows[i] == (DesktopRec *)client_data)
308       {
309          desktopRec = (DesktopRec *)client_data;
310          break;
311       }
312    }
313    if (desktopRec == NULL)
314    {
315       file_mgr_rec = (FileMgrRec *) client_data;
316       dialog_data = _DtGetInstanceData ((XtPointer)file_mgr_rec);
317       file_mgr_data = (FileMgrData *) dialog_data->data;
318    }
319    else
320      file_mgr_data = NULL;
321    
322    callback = (XmAnyCallbackStruct *) call_data;
323    new_event = (XEvent *)callback->event;
324
325    if (new_event->type == ButtonPress)
326    {
327       XButtonEvent *bevent = (XButtonEvent *)new_event;
328       desktop_data->event = *bevent;
329    }
330    else if (new_event->type == KeyPress || new_event->type == KeyRelease)
331    {
332       if(first)
333       {
334          /* set up the the keysyms we are looking for */
335          PlusKeysym = XStringToKeysym("plus");
336          MinusKeySym = XStringToKeysym("minus");
337
338          NumSelectKeys = XmeVirtualToActualKeysyms(XtDisplay(w), 
339                                                    osfXK_Select, 
340                                                    &SelectBindings);
341
342          ActivateKeysym = XK_Return;
343          SpaceKeysym = XStringToKeysym("space");
344          first = False;
345       }
346
347       kevent = (XKeyEvent *)new_event;
348       if (kevent->state & ShiftMask)
349          offset = 1;
350       else
351          offset = 0;
352
353       /*
354       keysym = XLookupKeysym(kevent, offset);
355       */
356       XmTranslateKey( kevent->display, kevent->keycode, offset?ShiftMask:0,
357                       &modif, &keysym);
358    }
359
360    /* in tree mode '+' and '-' keys expand and collaps tree branches */
361    if (!desktopRec && new_event->type == KeyPress &&
362         (keysym == PlusKeysym || keysym == MinusKeySym))
363    {
364       /* ignore +/- keys if not in tree mode */
365       if (file_mgr_data->show_type != MULTIPLE_DIRECTORY)
366          return;
367
368       /* get the gadget that received the input */
369       if (keybdFocusPolicy == XmEXPLICIT)
370          eventIcon = (Widget) XmGetFocusWidget(w);
371       else
372          eventIcon = (Widget) InputForGadget(w, kevent->x, kevent->y);
373       if (eventIcon == NULL)
374          return;
375
376       /* find the widget in the file_list */
377       found = False;
378       for (i = -1; i < file_mgr_data->directory_count && !found; i++)
379       {
380          for (j = 0; j < file_mgr_data->directory_set[i]->file_count; j++)
381          {
382             fileViewData = file_mgr_data->directory_set[i]->file_view_data[j];
383             if (fileViewData->widget == eventIcon ||
384                 fileViewData->treebtn == eventIcon)
385             {
386                found = True;
387                break;
388             }
389          }
390       }
391
392       /* if found, expand the branch */
393       if (found && fileViewData->file_data->is_subdir)
394       {
395          XmDropSiteStartUpdate(w);
396          DirTreeExpand(file_mgr_data, fileViewData, (keysym == PlusKeysym));
397          DrawCurrentDirectory (file_mgr_rec->current_directory,
398                                file_mgr_rec, file_mgr_data);
399          LayoutFileIcons(file_mgr_rec, file_mgr_data, False, True);
400          XmDropSiteEndUpdate(w);
401          RedrawTreeLines(w, -w->core.x, -w->core.y,
402                          XtParent(w)->core.width, XtParent(w)->core.height,
403                          0, file_mgr_rec, file_mgr_data);
404       }
405    }
406
407    else if (new_event->type == ButtonPress || (new_event->type == KeyPress &&
408                                              keybdFocusPolicy == XmEXPLICIT))
409    {
410       /* Any button event unposts the rename text field */
411       if (desktopRec)
412          UnpostDTTextField();
413       else if( file_mgr_data )
414       {
415         if( file_mgr_data->fast_cd_enabled )
416           UnpostTextPath( file_mgr_data );
417
418         UnpostTextField( file_mgr_data );
419       }
420
421       if (new_event->type == KeyPress)
422       {
423          /* We have a KeyPress: need to check to see if the press is
424             "return", "space", "select". If it is, need to select the Icon
425             the focus is in. */
426
427          if (keysym == XK_Escape)
428          {
429             /* an escape unposts the name change text widget */
430             if(desktopRec)
431                UnpostDTTextField();
432             else
433                UnpostTextField(file_mgr_data);
434             return;
435          }
436          else if (    keysym != ActivateKeysym
437                    && keysym != SpaceKeysym
438                    && keysym != osfXK_Delete
439                    && keysym != osfXK_EndLine
440                    && keysym != osfXK_BeginLine
441                    && keysym != osfXK_PageLeft
442                    && keysym != osfXK_PageUp
443                    && keysym != osfXK_PageDown
444                    && keysym != osfXK_PageRight
445                    && keysym != osfXK_Menu )
446          {
447            Boolean select = FALSE;
448            int i;
449
450            for (i = 0; !select && (i < NumSelectKeys); i++)
451              select = (keysym == SelectBindings[i].keysym);
452
453            if (!select)
454              return;
455          }
456     
457          if (desktopRec)
458             eventIcon = desktopRec->iconGadget;
459          else
460             eventIcon = (Widget) XmGetFocusWidget(file_mgr_rec->file_window);
461          event = (XButtonPressedEvent *)new_event;
462       }
463       else 
464       {
465          event = (XButtonPressedEvent *)new_event;
466          if(event->button != Button1)
467          {
468             if(event->button == bMenuButton && desktopRec == NULL)
469                FmPopup (NULL, NULL, (XEvent *)event, file_mgr_data);
470             return;
471          }
472          eventIcon = (Widget) InputForGadget(w, event->x, event->y);
473       }
474
475       /*
476        * If the event occurred in an icon, then we are either doing
477        * a selection or a drag.  If it started in the file window, then
478        * we can only be doing a region selection.
479        */
480       if (eventIcon != NULL)
481       {
482          /*
483           * If this icon is currently selected, then we can't yet tell
484           * whether the user is starting a drag operation, or simply
485           * redoing the icon selection; we must wait for either the
486           * drag threshold to be surpassed, or the button up event.
487           */
488
489          /* Map the icon into its fileViewData structure */
490          /* Check for desktop icon first */
491          if (desktopRec)
492          {
493             for (i = 0; i<desktop_data->numIconsUsed; i++)
494             {
495                if (desktop_data->desktopWindows[i]->iconGadget == eventIcon)
496                {
497                  fileViewData = desktop_data->desktopWindows[i]->file_view_data;
498                  break;
499                }
500             }
501          }
502          else
503          {
504             /* Not a desktop icon */
505             XtSetArg(args[0], XmNuserData, (XtPointer) &directoryData);
506             XtGetValues(eventIcon, args, 1);
507             if( directoryData != NULL )
508             { 
509               for (i = 0; i < directoryData->file_count; i++)
510               {
511                 if (directoryData->file_view_data[i]->widget == eventIcon &&
512                     directoryData->file_view_data[i]->displayed)
513                 {
514                   fileViewData = directoryData->file_view_data[i];
515                   break;
516                 }
517               }
518             }
519          }
520
521          if (((file_mgr_rec && FileIsSelected(file_mgr_data, fileViewData)) ||
522              (desktopRec && DTFileIsSelected(desktopRec, fileViewData))) &&
523              event->type == ButtonPress)
524          {
525             /* Need to wait to determine what to do */
526             ProcessBtnUp = True;
527             B1DragPossible = True;
528             initialDragX = event->x;
529             initialDragY = event->y;
530
531             if((file_mgr_rec && FileIsSelected(file_mgr_data, fileViewData)) &&
532                                         file_mgr_data->selected_file_count > 1)
533             {
534                if (PositioningEnabledInView(file_mgr_data))
535                {
536                  ObjectPtr top;
537                  FileViewData ** selection_list;
538
539                   top = GetTopOfStack(file_mgr_data);
540                   if(top != NULL && top->file_view_data != fileViewData)
541                   {
542                      ObjectPtr savetop, next, prev;
543          
544                      savetop = top;
545                      while(top != NULL && top->file_view_data != fileViewData)
546                         top = top->next;
547
548                      if(top != NULL)
549                      {
550                         prev = top->prev;
551                         next = top->next;
552                         if (prev)
553                            prev->next = next;
554                         if (next)
555                            next->prev = prev;
556                         top->prev = NULL;
557                         top->next = savetop;
558                         top->stacking_order = 1;
559                         savetop->prev = top;
560                         top = savetop;
561                         for(i = 2; top->prev != NULL; i++)
562                         {
563                            top->stacking_order = i;
564                            if(top->next == NULL)
565                               break;
566                            top = top->next;
567                         }
568
569                         top = GetTopOfStack(file_mgr_data);
570                         RedrawOneGadget(top->file_view_data->widget,NULL,NULL);
571                      }
572                   }
573
574                         /* now make it the top of the selection list */
575                   /* Force selection list order to match stacking order */
576                   selection_list = (FileViewData **)XtMalloc(
577                                     sizeof(FileViewData *) * 
578                                     (file_mgr_data->selected_file_count + 1));
579
580                   i = 0;
581                   if(top->file_view_data != NULL)
582                      selection_list[i++] = top->file_view_data;
583                   for(j = 0;i < file_mgr_data->selected_file_count; j++,i++)
584                   {
585                       if(top->file_view_data != 
586                                         file_mgr_data->selection_list[j])
587                          selection_list[i] = file_mgr_data->selection_list[j];
588                       else
589                          i--;
590                   }
591                   selection_list[i] = NULL;
592                   XtFree((char *)file_mgr_data->selection_list);
593                   file_mgr_data->selection_list = selection_list;
594                }
595             }
596          }
597          else
598          {
599             /*
600              * The icon is not currently selected, so we will select it.
601              * It is still possible that the user may initiate a drag.
602              */
603             ProcessBtnUp = False;
604             if (event->type == ButtonPress)
605             {
606                B1DragPossible = True;
607                initialDragX = event->x;
608                initialDragY = event->y;
609             } 
610             else
611             {
612                B1DragPossible = False;
613                initialDragX = -1;
614                initialDragY = -1;
615             }
616
617             switch( keysym )
618             {
619               case osfXK_Delete:
620                 {
621                   DtActionArg * action_args;
622                   int arg_count;
623
624                   if( desktopRec == NULL
625                       && file_mgr_rec != NULL )
626                   {
627                     if( file_mgr_data->selected_file_count
628                         && fileViewData
629                         && FileIsSelected(file_mgr_data, fileViewData) )
630                     {
631                       _DtBuildActionArgsWithSelectedFiles(
632                                 file_mgr_data->selection_list,
633                                 file_mgr_data->selected_file_count,
634                                 &action_args, &arg_count );
635                     }
636                     else
637                     {
638                       _DtBuildActionArgsWithSelectedFiles( &fileViewData, 1,
639                                                            &action_args,
640                                                            &arg_count );
641                     }
642                     DtActionInvoke( file_mgr_rec->shell, TRASH_ACTION,
643                                     action_args, arg_count, NULL, NULL,
644                                     trash_dir, True, NULL, NULL );
645                   }
646                   else if( desktopRec != NULL )
647                   {
648                     int selectedCount = desktop_data->workspaceData[desktopRec->workspace_num - 1]->files_selected;
649                     if( selectedCount )
650                     {
651                       _DtBuildActionArgsWithDTSelectedFiles(
652                            desktop_data->workspaceData[desktopRec->workspace_num - 1]->selectedDTWindows,
653                            selectedCount,
654                            &action_args, &arg_count );
655                     }
656                     else
657                     {
658                       _DtBuildActionArgsWithSelectedFiles( &fileViewData, 1,
659                                                            &action_args,
660                                                            &arg_count );
661                     }
662                     DtActionInvoke( desktopRec->shell, TRASH_ACTION,
663                                     action_args, arg_count, NULL, NULL,
664                                     trash_dir, True, NULL, NULL );
665                   }
666                   _DtFreeActionArgs( action_args, arg_count );
667                 }
668                 break;
669               case osfXK_Menu:
670                 if(file_mgr_data)  /* if not, then it is a desktop object */
671                   FmPopup( NULL, (XtPointer)fileViewData,
672                           (XEvent *)event, file_mgr_data );
673                 break;
674               case osfXK_EndLine:
675                 if( !desktopRec
676                     && file_mgr_data->show_type != MULTIPLE_DIRECTORY )
677                 {
678                   Widget child = NULL;
679
680                   child = XmGetFocusWidget(file_mgr_rec->file_window);
681                   if( child )
682                   {
683                     FileViewData * focusIcon = NULL;
684                     FileViewData **order_list;
685                     int order_count;
686
687                     order_list = ((IconLayoutData *)file_mgr_data->layout_data)->order_list;
688                     order_count = ((IconLayoutData *)file_mgr_data->layout_data)->order_count;
689
690                     for (i = 0; i < order_count; ++i)
691                     {
692                       if (order_list[i]->filtered)
693                         continue;
694
695                       if( order_list[i]->widget == child
696                           && !order_list[i]->need_update )
697                       {
698                         int j;
699                         int y = order_list[i]->y;
700
701                         focusIcon = order_list[i];
702
703                         for( j = i+1; j < order_count; ++j )
704                         {
705                           if (order_list[j]->filtered)
706                             continue;
707
708                           if( order_list[j]->y == y )
709                             focusIcon = order_list[j];
710                           else
711                             break;
712                         }
713                         break;
714                       }
715                     }
716                     XmProcessTraversal( focusIcon->widget, XmTRAVERSE_CURRENT );
717                   }
718                 }
719                 break;
720               case osfXK_BeginLine:
721                   if( !desktopRec
722                       && file_mgr_data->show_type != MULTIPLE_DIRECTORY )
723                 {
724                   Widget child = NULL;
725
726                   child = XmGetFocusWidget(file_mgr_rec->file_window);
727                   if( child )
728                   {
729                     FileViewData * focusIcon = NULL;
730                     FileViewData **order_list;
731                     int order_count;
732
733                     order_list = ((IconLayoutData *)file_mgr_data->layout_data)->order_list;
734                     order_count = ((IconLayoutData *)file_mgr_data->layout_data)->order_count;
735
736                     for (i = 0; i < order_count; ++i)
737                     {
738                       if (order_list[i]->filtered)
739                         continue;
740
741                       if( order_list[i]->widget == child
742                           && !order_list[i]->need_update )
743                       {
744                         int j;
745                         int y = order_list[i]->y;
746
747                         focusIcon = order_list[i];
748
749                         for( j = i-1; j >= 0; --j )
750                         {
751                           if (order_list[j]->filtered)
752                             continue;
753
754                           if( order_list[j]->y == y )
755                             focusIcon = order_list[j];
756                           else
757                             break;
758                         }
759                         break;
760                       }
761                     }
762                     XmProcessTraversal( focusIcon->widget, XmTRAVERSE_CURRENT );
763                   }
764                 }
765                 break;
766               case osfXK_PageUp:
767                 if( !desktopRec )
768                 {
769                   if( VerticalScrollbarIsVisible(
770                               file_mgr_rec->vertical_scroll_bar,
771                               file_mgr_rec->scroll_window))
772                   {
773                     String p;
774  
775                     p = (String) XtMalloc(sizeof(char *));
776                     *p = (char) 0;
777                     XtCallActionProc( file_mgr_rec->vertical_scroll_bar,
778                                       "PageUpOrLeft", new_event,
779                                       (char **) &p, 1 );
780                     XtFree(p);
781                   }
782                 }
783                 break;
784               case osfXK_PageDown:
785                 if( !desktopRec )
786                 {
787                   if( VerticalScrollbarIsVisible(
788                               file_mgr_rec->vertical_scroll_bar,
789                               file_mgr_rec->scroll_window))
790                   {
791                     String p;
792  
793                     p = (String) XtMalloc(sizeof(char *));
794                     *p = (char)0;
795                     XtCallActionProc( file_mgr_rec->vertical_scroll_bar,
796                                       "PageDownOrRight", new_event, &p, 1 );
797                     XtFree(p);
798                   }
799                 }
800                 break;
801               default:
802                 if (desktopRec)
803                   ProcessDTSelection(desktopRec, (XButtonEvent *)event);
804                 else
805                   ProcessSelection( file_mgr_data, eventIcon,
806                                     ((event->state & ControlMask) != 0),
807                                     (XButtonEvent *)event);
808                 break;
809             }
810          }
811       }
812       else
813       {
814          /* In file window - start region select */
815          /* There are no region selects for desktop icons */
816          ProcessBtnUp = False;
817          B1DragPossible = False;
818          initialDragX = -1;
819          initialDragY = -1;
820          if (desktopRec == NULL)
821          {
822             ProcessSelection(file_mgr_data, NULL,
823                              ((event->state & ControlMask) != 0),
824                              (XButtonEvent *)event);
825          }
826       }
827    }
828    else if(new_event->type == ButtonRelease || (new_event->type == KeyRelease &&
829                                              keybdFocusPolicy == XmEXPLICIT))
830    {
831       if(new_event->type == KeyRelease)
832       {
833          if (keysym != osfXK_Select)
834             return;
835
836          event = (XButtonPressedEvent *)new_event;
837       }
838       else
839       {
840          event = (XButtonPressedEvent *)new_event;
841          if(event->button != Button1)
842             return;
843       }
844       /*
845        * When a button 1 up event is received, we will first see if the
846        * select occurred in the icon's title; if so, then we will post
847        * the rename text field.  If the icon in which the button down
848        * occurred was not already selected, then all of the selection
849        * work was done at button 1 down time, so there is nothing left
850        * for us to do but return.  However, if the icon was already
851        * selected, then we could not do any select processing at button
852        * down time, because the user may have been trying to initate
853        * a drag request; this can't be determined until either the drag
854        * threshold is surpassed, or the button up occurs.
855        */
856       if (((initialDragX >= 0) && (initialDragY >= 0)) &&
857          (eventIcon = (Widget) InputForGadget(w, initialDragX, 
858                                               initialDragY)))
859       {
860          /*
861           * If processing was postponed until the button up, then do it now.
862           */
863          B1DragPossible = False;
864          if (ProcessBtnUp)
865          {
866             XEvent tmpEvent;
867             
868             tmpEvent.xbutton = *event;
869             tmpEvent.xbutton.x = initialDragX;
870             tmpEvent.xbutton.y = initialDragY;
871
872             if (desktopRec)
873             {
874                ProcessDTSelection(desktopRec, (XButtonEvent *)&tmpEvent);
875             }
876             else
877             {
878                ProcessSelection(file_mgr_data, eventIcon,
879                                 ((event->state & ControlMask) != 0),
880                                 (XButtonEvent *)&tmpEvent);
881             }
882          }
883
884
885          /*
886           * If the select occurred in the title portion of the icon, then
887           * put up a text edit field, which can be used to change the name
888           * of the icon.  The last field '0' means its not on the Desktop.
889           */
890          if (_DtIconSelectInTitle(eventIcon, (Position)initialDragX, 
891                                   (Position)initialDragY) && ProcessBtnUpCD)
892          {
893             /* Map the icon into its fileViewData structure */
894             /* Check for desktop icon first */
895             if (desktopRec)
896             {
897                for (i = 0; i<desktop_data->numIconsUsed; i++)
898                {
899                   if (desktop_data->desktopWindows[i]->iconGadget == eventIcon)
900                   {
901                     fileViewData = 
902                          desktop_data->desktopWindows[i]->file_view_data;
903                     break;
904                   }
905                }
906             }
907             else
908             {
909                /* Not a desktop icon */
910                XtSetArg(args[0], XmNuserData, (XtPointer) &directoryData);
911                XtGetValues(eventIcon, args, 1);
912                for (i = 0; i < directoryData->file_count; i++)
913                {
914                   if (directoryData->file_view_data[i]->widget == eventIcon &&
915                       directoryData->file_view_data[i]->displayed)
916                   {
917                      fileViewData = directoryData->file_view_data[i];
918                      break;
919                   }
920                }
921             }
922
923             if (desktopRec)
924             {
925                CreateNameChangeDialog(eventIcon, fileViewData,
926                                       (XtPointer)desktopRec, DESKTOP);
927             }
928             else if( file_mgr_data->view != BY_NAME )
929             {
930                /* We don't allow users to rename when they are viewing a
931                   directory in 'By Name Only' mode.
932                   Because clicking on the label is the only way for them
933                   to select a file. Popup a text widget to allow rename 
934                   would be very confusing
935                */
936                if( file_mgr_data->view != BY_ATTRIBUTES
937                    || ( file_mgr_data->view == BY_ATTRIBUTES
938                         && TurnOnTextName ) )
939                  CreateNameChangeDialog(eventIcon, fileViewData,
940                                         (XtPointer)file_mgr_data, NOT_DESKTOP);
941             }
942          }
943
944       }
945       else
946       {
947          /* Clean up */
948          B1DragPossible = False;
949          B2DragPossible = False;
950          ProcessBtnUp = False;
951       }
952       ProcessBtnUpCD = True;
953    }
954    else if(new_event->type == KeyPress)
955    {
956       if (keysym == XK_Escape)
957       {
958          /* an escape unposts the name change text widget */
959          if(desktopRec)
960             UnpostDTTextField();
961          else
962             UnpostTextField(file_mgr_data);
963          return;
964       }
965    }
966 }
967
968
969 /*
970  * When a select operation terminates, we need to find the real button
971  * up event, so that we can get the correct (x,y) for where the select
972  * operation ended.
973  */
974
975 static Boolean
976 CheckForBtnUp(
977         Display *display,
978         XEvent *event,
979         XtPointer arg )
980 {
981    if ((event->type == ButtonRelease) && (event->xbutton.button == Button1))
982       return(True);
983
984    return(False);
985 }
986
987
988 /************************************************************************
989  *
990  *  GetSelectionRectangle
991  *
992  ************************************************************************/
993
994 static void
995 GetSelectionRectangle(
996         Display *display,
997         Window window,
998         XButtonEvent *event,
999         FileMgrRec *file_mgr_rec,
1000         FileMgrData *file_mgr_data, 
1001         Boolean toggleSelect)
1002 {
1003    Screen * screen;
1004    static GC draw_gc = 0;
1005    XGCValues gc_values;
1006    Region region;
1007    Region widget_region;
1008    Region intersect_region;
1009    Region redraw_region;
1010
1011    static XRectangle return_rect;
1012
1013    int virt_x, virt_y;
1014    int virt_width, virt_height;
1015    int x1, y1;
1016    int x2, y2;
1017    int x3, y3;
1018    int x4, y4;
1019    int old_x, old_y;
1020    int temp, j, i;
1021    int pixmap_x, pixmap_y, pixmap_x1, pixmap_y1;
1022    int directory_count;
1023     
1024    Window root, sub_win;
1025    int  win_x, win_y;
1026    unsigned int mask;
1027    XEvent btnUpEvent;
1028    XmManagerWidget file_window;
1029    Dimension current_file_window_width, sw_width;
1030    Dimension current_file_window_height, sw_height;
1031    Dimension file_window_width, file_window_height;
1032    Dimension max_width, max_height;
1033    Dimension min_width, min_height;
1034    Widget hb, vb;
1035    int vb_val_ret = 0;
1036    int vb_slide_size = 0;
1037    int vb_inc_ret = 0;
1038    int vb_pg_inc_ret = 0;
1039    int hb_val_ret = 0;
1040    int hb_slide_size = 0;
1041    int hb_inc_ret = 0;
1042    int hb_pg_inc_ret = 0;
1043    Boolean vsbVisible = False;
1044    Boolean hsbVisible = False;
1045    DirectorySet ** directory_set;
1046    FileViewData *file_view_data;
1047    
1048    Position x,y;
1049    Dimension highlightThickness, shadowThickness;
1050    Dimension width, height;
1051    Dimension marginWidth, marginHeight;
1052    Dimension pixmapWidth, pixmapHeight;
1053    Dimension stringWidth, stringHeight;
1054    unsigned char pixmapPosition;
1055    unsigned char alignment;
1056
1057    Arg args[10];
1058     
1059    /*  Get the horizontal and vertical scrollbars.  */
1060    XtSetArg (args[0], XmNhorizontalScrollBar, &hb);
1061    XtSetArg (args[1], XmNverticalScrollBar, &vb);
1062    XtSetArg (args[2], XmNwidth, &sw_width);
1063    XtSetArg (args[3], XmNheight, &sw_height);
1064    XtGetValues (file_mgr_rec->scroll_window, args, 4);
1065
1066    file_window = (XmManagerWidget)file_mgr_rec->file_window;
1067    XtSetArg (args[0], XmNwidth, &file_window_width);
1068    XtSetArg (args[1], XmNheight, &file_window_height);
1069    XtGetValues ((Widget)file_window, args, 2);
1070    file_window_width--;
1071    file_window_height--;
1072
1073    if (VerticalScrollbarIsVisible(vb, file_mgr_rec->scroll_window))
1074    {
1075        vsbVisible = True;
1076        current_file_window_width = sw_width - vb->core.width - 12;
1077    }
1078    else
1079    {
1080        current_file_window_width = sw_width - 9;
1081    }
1082
1083    if (HorizontalScrollbarIsVisible(hb, file_mgr_rec->scroll_window))
1084    {
1085        hsbVisible = True;
1086        current_file_window_height = sw_height - hb->core.height - 12;
1087    }
1088    else
1089    {
1090        current_file_window_height = sw_height - 9;
1091    }
1092
1093    if(vsbVisible)
1094    {
1095        XmScrollBarGetValues(vb, &vb_val_ret, &vb_slide_size,
1096                                           &vb_inc_ret, &vb_pg_inc_ret);
1097        min_height = vb_val_ret;
1098        max_height = current_file_window_height + min_height;
1099    }
1100    else
1101    {
1102        max_height = current_file_window_height;
1103        min_height = 0;
1104    }
1105
1106    if(hsbVisible)
1107    {
1108        XmScrollBarGetValues(hb, &hb_val_ret, &hb_slide_size,
1109                                           &hb_inc_ret, &hb_pg_inc_ret);
1110        min_width = hb_val_ret;
1111        max_width = current_file_window_width + min_width;
1112    }
1113    else
1114    {
1115        max_width = current_file_window_width;
1116        min_width = 0;
1117    }
1118
1119    /*  Get the gc to be used to draw the bounding rectangle  */
1120
1121    if (!draw_gc)
1122    {
1123      unsigned int white_pixel;
1124
1125      screen = XDefaultScreenOfDisplay (display);
1126      gc_values.function = GXxor;
1127
1128      white_pixel = WhitePixelOfScreen (screen);
1129      if( white_pixel )
1130      {
1131        gc_values.foreground = white_pixel;
1132        gc_values.background = BlackPixelOfScreen (screen);
1133      }
1134      else
1135      {
1136        gc_values.background = white_pixel;
1137        gc_values.foreground = BlackPixelOfScreen (screen);
1138      }
1139
1140      draw_gc = 
1141        XCreateGC (display, window,
1142                   GCForeground | GCBackground | GCFunction, &gc_values);
1143    }
1144
1145    widget_region = XCreateRegion();
1146    intersect_region = XCreateRegion();
1147    redraw_region = XCreateRegion();
1148
1149    x1 = x2 = old_x = event->x;
1150    y1 = y2 = old_y = event->y;
1151
1152    DrawRectangle (display, window, draw_gc, x1, y1, x2, y2);
1153
1154    while (1)            /*  Set up a loop to catch the select up point.  */
1155    {
1156       XQueryPointer (display,  window, &root, &sub_win,
1157                       &win_x, &win_y, &x2, &y2, &mask);
1158
1159       if ((mask & Button1Mask) == 0)
1160       {
1161          /* Undraw the last rectangle we drew */
1162          x2 = old_x;
1163          y2 = old_y;
1164          DrawRectangle (display, window, draw_gc, x1, y1, x2, y2);
1165
1166          /*
1167           * The real bound of the rectangle is contained in the button up
1168           * event; you can't use the pointer position, because if the system
1169           * is slow, then by the time we query the mouse, the button may have
1170           * been long ago release, and the pointer subsequently moved.
1171           */
1172          if (XPeekIfEvent(display, &btnUpEvent,(Bool (*)())CheckForBtnUp, NULL))
1173          {
1174             x2 = btnUpEvent.xbutton.x;
1175             y2 = btnUpEvent.xbutton.y;
1176          }
1177          break;
1178       }
1179
1180       if( x2 < 0 ) x2 = 0;
1181       if( y2 < 0 ) y2 = 0;
1182
1183       if ((x2 > old_x && !hsbVisible && (Dimension)old_x < file_window_width) || 
1184           (x2 > old_x && hsbVisible && (Dimension)(hb_val_ret + 
1185                                  hb_slide_size) < (Dimension)(file_window_width + 1)) || 
1186           (x2 < old_x && !hsbVisible && old_x > 0) || 
1187                      (x2 < old_x && hsbVisible && hb_val_ret >= 0) ||
1188           (y2 > old_y && !vsbVisible && (Dimension)old_y < file_window_height) || 
1189           (y2 > old_y && vsbVisible && (Dimension)(vb_val_ret + 
1190                                 vb_slide_size) < (Dimension)(file_window_height + 1)) ||
1191           (y2 < old_y && !vsbVisible && old_y > 0) || 
1192                      (y2 < old_y && vsbVisible && vb_val_ret >= 0))
1193       {
1194          DrawRectangle (display, window, draw_gc, x1, y1, old_x, old_y);
1195          if((Dimension)x2 >= max_width)
1196          {
1197             if(hsbVisible)
1198             {
1199                hb_val_ret += (x2 - max_width);
1200                if((Dimension)(hb_val_ret + hb_slide_size) <= (Dimension)(file_window_width + 1))
1201                {
1202                   XmScrollBarSetValues(hb, hb_val_ret, hb_slide_size,
1203                                              hb_inc_ret, hb_pg_inc_ret, True);
1204                   min_width = (x2 - max_width) + min_width;
1205                   max_width = x2;
1206                   XmUpdateDisplay ((Widget)file_window);
1207                }
1208                else if((Dimension)(hb_val_ret + hb_slide_size) > (Dimension)(file_window_width + 1) && 
1209                     (Dimension)(hb_val_ret - (x2 - max_width)) < 
1210                                          (Dimension)(file_window_width - hb_slide_size)) 
1211                {
1212                   XmScrollBarSetValues(hb, 
1213                                file_window_width - hb_slide_size + 1, 
1214                                hb_slide_size, hb_inc_ret, hb_pg_inc_ret, True);
1215                   temp = (file_window_width - hb_slide_size + 1) - hb_val_ret; 
1216                   hb_val_ret = file_window_width - hb_slide_size + 1;
1217                   min_width = temp + min_width;
1218                   max_width = temp + max_width;
1219                   XmUpdateDisplay ((Widget)file_window);
1220                   x2 = file_window_width;
1221                }
1222                else
1223                {
1224                   hb_val_ret = file_window_width - hb_slide_size + 1;
1225                   x2 = max_width = file_window_width;
1226                   min_width = max_width - current_file_window_width;
1227                }
1228             }
1229             else
1230             {
1231                if(vsbVisible)
1232                {
1233                   if((Dimension)x2 > current_file_window_width)
1234                      x2 = current_file_window_width; 
1235                }
1236                else
1237                {
1238                   if((Dimension)x2 > file_window_width)
1239                      x2 = file_window_width; 
1240                }
1241             }
1242          }
1243          else if((Dimension)x2 < min_width)
1244          {
1245             if(hsbVisible)
1246             {
1247                if(min_width > 0)
1248                {
1249                   hb_val_ret -= (min_width - x2);
1250                   if(hb_val_ret >= 0)
1251                   {
1252                      XmScrollBarSetValues(hb, hb_val_ret, hb_slide_size,
1253                                           hb_inc_ret, hb_pg_inc_ret, True);
1254                      max_width = max_width - (min_width - x2);
1255                      min_width = x2;
1256                      XmUpdateDisplay (file_mgr_rec->file_window);
1257                   }
1258                   else if((hb_val_ret < 0) &&
1259                        ((int)(hb_val_ret + (min_width - x2)) >= (int)0))
1260                   {
1261                      XmScrollBarSetValues(hb, 0, hb_slide_size, 
1262                                          hb_inc_ret, hb_pg_inc_ret, True);
1263                      max_width = current_file_window_width;
1264                      XmUpdateDisplay ((Widget)file_window);
1265                      x2 = hb_val_ret = min_width = 0;
1266                   }
1267                   else
1268                   {
1269                      hb_val_ret = min_width = x2 = 0;
1270                      max_width = current_file_window_width;
1271                   }
1272                }
1273                else
1274                {
1275                   if(x2 < 0)
1276                      x2 = 0;
1277                }
1278             }
1279             else
1280             {
1281                if(x2 < 0)
1282                   x2 = 0;
1283             }
1284          }
1285
1286          if((Dimension)y2 > max_height)
1287          {
1288             if(vsbVisible)
1289             {
1290                vb_val_ret += (y2 - max_height);
1291                if((Dimension)(vb_val_ret + vb_slide_size) <= (Dimension)(file_window_height + 1))
1292                {
1293                   XmScrollBarSetValues(vb, vb_val_ret, vb_slide_size,
1294                                              vb_inc_ret, vb_pg_inc_ret, True);
1295                   min_height = (y2 - max_height) + min_height;
1296                   max_height = y2;
1297                   XmUpdateDisplay ((Widget)file_window);
1298                }
1299                else if((Dimension)(vb_val_ret + vb_slide_size) > (Dimension)(file_window_height + 1) &&
1300                     (Dimension)(vb_val_ret - (y2 - max_height)) < 
1301                                        (Dimension)(file_window_height + 1 - vb_slide_size))
1302                {
1303                   XmScrollBarSetValues(vb, 
1304                                file_window_height + 1 - vb_slide_size,
1305                                vb_slide_size, vb_inc_ret, vb_pg_inc_ret, True);
1306                   temp = (file_window_height + 1 - vb_slide_size) - vb_val_ret;
1307                   vb_val_ret = file_window_height + 1 - vb_slide_size;
1308                   min_height = temp + min_height;
1309                   max_height = temp + max_height;
1310                   XmUpdateDisplay ((Widget)file_window);
1311                   y2 = file_window_height;
1312                }
1313                else
1314                {
1315                   vb_val_ret = file_window_height + 1 - vb_slide_size;
1316                   y2 = max_height = file_window_height;
1317                   min_height = max_height - current_file_window_height;
1318                }
1319             }
1320             else
1321             {
1322                if(hsbVisible)
1323                {
1324                   if((Dimension)y2 > current_file_window_height)
1325                      y2 = current_file_window_height; 
1326                }
1327                else
1328                {
1329                   if((Dimension)y2 > file_window_height)
1330                      y2 = file_window_height; 
1331                }
1332             }
1333          }
1334          else if((Dimension)y2 < min_height)
1335          {
1336             if(vsbVisible)
1337             {
1338                if(min_height > 0)
1339                {
1340                   vb_val_ret -= (min_height - y2);
1341                   if(vb_val_ret >= 0)
1342                   {
1343                      XmScrollBarSetValues(vb, vb_val_ret, vb_slide_size,
1344                                           vb_inc_ret, vb_pg_inc_ret, True);
1345                      max_height = max_height - (min_height - y2);
1346                      min_height = y2;
1347                      XmUpdateDisplay (file_mgr_rec->file_window);
1348                   }
1349                   else if(vb_val_ret < 0 &&
1350                        ((int)(vb_val_ret + (min_height - y2)) >= (int)0))
1351                   {
1352                      XmScrollBarSetValues(vb, 0, vb_slide_size,
1353                                          vb_inc_ret, vb_pg_inc_ret, True);
1354                      max_height = current_file_window_height;
1355                      XmUpdateDisplay ((Widget)file_window);
1356                      y2 = vb_val_ret = min_height = 0;
1357                   }
1358                   else
1359                   {
1360                      vb_val_ret = min_height = y2 = 0;
1361                      max_height = current_file_window_height;
1362                   }
1363                }
1364                else
1365                {
1366                   if(y2 < 0)
1367                      y2 = 0;
1368                }
1369             }
1370             else
1371             {
1372                if(y2 < 0)
1373                   y2 = 0;
1374             }
1375          }
1376          old_x = x2;
1377          old_y = y2;
1378          x3 = x1;
1379          x4 = x2;
1380          y3 = y1;
1381          y4 = y2;
1382          if (x4 < x3)
1383          {
1384             temp = x3;
1385             x3 = x4;
1386             x4 = temp;
1387          }
1388
1389          if (y4 < y3)
1390          {
1391             temp = y3;
1392             y3 = y4;
1393             y4 = temp;
1394          }
1395       
1396          virt_x = x3;
1397          virt_y = y3;
1398          virt_width = x4 - x3 + 1;
1399          virt_height = y4 - y3 + 1;
1400
1401
1402          return_rect.x = (short)virt_x;
1403          return_rect.y = (short)virt_y;
1404          return_rect.width = (unsigned short)virt_width;
1405          return_rect.height = (unsigned short)virt_height;
1406          region = XCreateRegion();
1407          XUnionRectWithRegion (&return_rect, region, region);
1408
1409          /*  Run through the gadget set to cause each icon within the  */
1410          /*  rectangle to be selected.                                 */
1411
1412          if (file_mgr_data->show_type == SINGLE_DIRECTORY)
1413             directory_count = 1;
1414          else
1415             directory_count = file_mgr_data->directory_count;
1416    
1417          directory_set = file_mgr_data->directory_set;
1418
1419
1420          for (i = 0; i < directory_count; i++)
1421          {
1422             for (j = 0; j < directory_set[i]->file_count; j++)
1423             {
1424                DtIconGadget  g;
1425    
1426                file_view_data = directory_set[i]->order_list[j];
1427       
1428                if (!file_view_data->displayed || file_view_data->need_update)
1429                   continue;
1430
1431                g = (DtIconGadget) file_view_data->widget;
1432
1433                highlightThickness = g->gadget.highlight_thickness;
1434                shadowThickness = g->gadget.shadow_thickness;
1435
1436                x = g->rectangle.x;
1437                y = g->rectangle.y;
1438       
1439                marginWidth = g->icon.cache->margin_width;
1440                marginHeight = g->icon.cache->margin_height;
1441                pixmapPosition = g->icon.cache->pixmap_position;
1442                alignment = g->icon.cache->alignment;
1443
1444                pixmapWidth = g->icon.pixmap_width;
1445                pixmapHeight = g->icon.pixmap_height;
1446                stringWidth = g->icon.string_width;
1447                stringHeight = g->icon.cache->string_height;
1448
1449                switch ((int) pixmapPosition)
1450                {
1451                   case XmPIXMAP_TOP:
1452                      if (alignment == XmALIGNMENT_BEGINNING)
1453                         pixmap_x = x + highlightThickness;
1454                      else if(alignment == XmALIGNMENT_CENTER)
1455                      {
1456                         if(stringWidth >= pixmapWidth)
1457                            pixmap_x = x + highlightThickness + 
1458                                               ((Dimension)(stringWidth - pixmapWidth)/(Dimension)2);
1459                         else
1460                            pixmap_x = x + highlightThickness;
1461                      }
1462                      break;
1463                   case XmPIXMAP_LEFT:
1464                   default:
1465                      pixmap_x = x + highlightThickness;
1466                      break;
1467                }
1468                pixmap_y = y + pixmapHeight;
1469                pixmap_x = pixmap_x + pixmapWidth;
1470 /*
1471                pixmap_x1 = pixmap_x + pixmapWidth;
1472                pixmap_y1 = pixmap_y + pixmapHeight;
1473 */
1474
1475                if(XPointInRegion(region, pixmap_x, pixmap_y)
1476 /*
1477                    && XPointInRegion(region, pixmap_x1, pixmap_y1)
1478 */
1479                   )
1480                {
1481                   if (toggleSelect == True &&
1482                       FileIsSelected (file_mgr_data, file_view_data))
1483                      DeselectFile (file_mgr_data, file_view_data, True);
1484                   else
1485                   {
1486                      if(!FileIsSelected (file_mgr_data, file_view_data))
1487                         SelectFile (file_mgr_data, file_view_data);
1488                   }
1489                }
1490                else if (FileIsSelected (file_mgr_data, file_view_data))
1491                   DeselectFile (file_mgr_data, file_view_data, True);
1492             }
1493          }
1494          DrawRectangle (display, window, draw_gc, x1, y1, x2, y2);
1495          XDestroyRegion (region);
1496       }
1497    }
1498
1499    XDestroyRegion (widget_region);
1500    XDestroyRegion (intersect_region);
1501    XDestroyRegion (redraw_region);
1502
1503    XSync (display, 0);
1504    return;
1505 }
1506
1507
1508 /************************************************************************
1509  *
1510  *  DrawRectangle
1511  *      DrawRectangle takes two points as input and draws a rectangle with
1512  *      a line width and height of 1 around the rectangle generated
1513  *      by the two points.  The rectangle is drawn XOR so that it
1514  *      can be erased.
1515  *
1516  ************************************************************************/
1517
1518 static void
1519 DrawRectangle(
1520         Display *display,
1521         Window window,
1522         GC gc,
1523         int x1,
1524         int y1,
1525         int x2,
1526         int y2 )
1527 {
1528    int x;
1529    int y;
1530    unsigned int width;
1531    unsigned int height;
1532
1533    if (x2 >= x1) 
1534    {
1535       x = x1;
1536       width = x2 - x1;
1537    }
1538    else
1539    {
1540       x = x2;
1541       width = x1 - x2;
1542    }
1543
1544    if (y2 >= y1)
1545    {
1546       y = y1;
1547       height = y2 - y1;
1548    }
1549    else
1550    {
1551       y = y2;
1552       height = y1 - y2;
1553    }
1554
1555    XDrawRectangle (display, window, gc, x, y, width, height);
1556
1557    if (width > 2 && height > 2)
1558       XDrawRectangle (display, window, gc, x + 1, y + 1, width - 2, height - 2);
1559 }
1560
1561
1562 /*
1563  * Given a widget, create a region describing the area occupied by the
1564  * widget; it may be a simple rectangle, or a compound region composed
1565  * of two rectangles (the pixmap and the label).
1566  */
1567
1568 void 
1569 WidgetRectToRegion (
1570    FileMgrData * file_mgr_data,
1571    Widget w,
1572    Region region)
1573 {
1574    XRectangle widget_rect;
1575    XRectangle pRect, lRect;
1576    unsigned char flags;
1577    static Region temp_region = NULL;
1578
1579    /* Empty the region */
1580    if (temp_region == NULL)
1581       temp_region = XCreateRegion();
1582    XSubtractRegion(temp_region, temp_region, region);
1583
1584    if (w == NULL)
1585       return;
1586
1587    /* Tree mode and attribute views do not support compound icons */
1588    if ((file_mgr_data->show_type != SINGLE_DIRECTORY) ||
1589        (file_mgr_data->view == BY_ATTRIBUTES))
1590    {
1591       widget_rect.x = (short)w->core.x;
1592       widget_rect.y = (short)w->core.y;
1593       widget_rect.width = (unsigned short)w->core.width;
1594       widget_rect.height = (unsigned short)w->core.height;
1595
1596       XUnionRectWithRegion(&widget_rect, region, region);
1597    }
1598    else
1599    {
1600       _DtIconGetIconRects((DtIconGadget)w, &flags, &pRect, &lRect);
1601
1602       if (flags & XmPIXMAP_RECT)
1603          XUnionRectWithRegion(&pRect, region, region);
1604
1605       if (flags & XmLABEL_RECT)
1606          XUnionRectWithRegion(&lRect, region, region);
1607    }
1608 }
1609
1610
1611 static void 
1612 ProcessSelection (
1613    FileMgrData * file_mgr_data,
1614    Widget icon,
1615    Boolean toggleSelect,
1616    XButtonEvent * event)
1617 {
1618    XRectangle * selection_rect;
1619    XRectangle   widget_rect;
1620    DirectorySet ** directory_set;
1621    int directory_count;
1622    register int i, j;
1623    Region region;
1624    Region widget_region;
1625    Region intersect_region;
1626    Region redraw_region;
1627    FileMgrRec * file_mgr_rec;
1628    FileViewData * file_view_data;
1629
1630    file_mgr_rec = (FileMgrRec *)file_mgr_data->file_mgr_rec;
1631
1632    /* User is starting a new selection; clear all old ones */
1633    if (!toggleSelect)
1634    {
1635       DeselectAllFiles (file_mgr_data);
1636       file_mgr_data->selected_file_count = 0;
1637
1638       XFlush (XtDisplay (file_mgr_rec->file_window));
1639       XmUpdateDisplay (file_mgr_rec->file_window);
1640    }
1641
1642    /*  Get the rectangle to be used as the selection area  */
1643    if (icon == NULL && event->type == ButtonPress)
1644    {
1645       /* User is starting a region select */
1646       GetSelectionRectangle (XtDisplay(file_mgr_rec->file_window), 
1647                                 (Window) XtWindow(file_mgr_rec->file_window), 
1648                                 event, file_mgr_rec, file_mgr_data, 
1649                                 toggleSelect);
1650    }
1651    else
1652    {
1653       /* User did a single select either through keyboard or mouse */
1654       if(event->type == KeyPress)
1655       {
1656          widget_rect.x = (short)icon->core.x;
1657          widget_rect.y = (short)icon->core.y;
1658          widget_rect.width = (short)icon->core.width;
1659          widget_rect.height = (short)icon->core.height;
1660       }
1661       else
1662       {
1663          widget_rect.x = (short)event->x;
1664          widget_rect.y = (short)event->y;
1665          widget_rect.width = 1;
1666          widget_rect.height = 1;
1667       } 
1668       selection_rect = &widget_rect;
1669
1670       region = XCreateRegion();
1671       widget_region = XCreateRegion();
1672       intersect_region = XCreateRegion();
1673       redraw_region = XCreateRegion();
1674
1675       XUnionRectWithRegion (selection_rect, region, region);
1676
1677
1678       /*  Run through the gadget set to cause each icon within the  */
1679       /*  rectangle to be selected.                                 */
1680
1681       if (file_mgr_data->show_type == SINGLE_DIRECTORY)
1682       {
1683          i = 0;
1684          directory_count = 1;
1685       }
1686       else
1687       {
1688          directory_count = file_mgr_data->directory_count;
1689          i = -1;
1690       }
1691
1692       directory_set = file_mgr_data->directory_set;
1693
1694
1695       for (; i < directory_count; i++)
1696       {
1697          if (PositioningEnabledInView(file_mgr_data))
1698          {
1699             ObjectPtr top = GetTopOfStack(file_mgr_data);
1700             int next_position = 0;
1701    
1702             /*
1703              * Stacking order requires us to handle this specially.  Objects
1704              * must be searched in top to bottom order when determining if
1705              * they are in the selection rectangle, but they must be drawn
1706              * bottom to top, to guarantee that the visuals are correct.
1707              */
1708    
1709             /* Find set of selected objects */
1710             while (top)
1711             {
1712                if(top->file_view_data == NULL)
1713                {
1714                   top = top->next;
1715                   continue;
1716                }
1717    
1718                if (!top->file_view_data->displayed)
1719                {
1720                   top = top->next;
1721                   continue;
1722                }
1723    
1724                WidgetRectToRegion(file_mgr_data, top->file_view_data->widget, 
1725                                   widget_region);
1726                XIntersectRegion(region, widget_region, intersect_region);
1727    
1728                if (!XEmptyRegion(intersect_region))
1729                {
1730                   if (toggleSelect && 
1731                       FileIsSelected (file_mgr_data, top->file_view_data))
1732                   {
1733                      DeselectFile(file_mgr_data, top->file_view_data, True);
1734    
1735                      XUnionRegion(widget_region, redraw_region, redraw_region);
1736                   }
1737                   else
1738                   {
1739                      /*
1740                       * We don't want to change the icon yet, because we
1741                       * need to do it in bottom to top order.
1742                       */
1743                      next_position++;
1744                      RepositionUpInStack(file_mgr_data, top->stacking_order,
1745                                          next_position);
1746                   }
1747    
1748                   /* Higher item 'cover' lower ones */
1749                   XSubtractRegion(region, widget_region, region);
1750                }
1751    
1752                top = top->next;
1753             }
1754    
1755             /* Now, select any newly selected files */
1756             if (next_position > 0)
1757             {
1758                /* Find where to start the redraw from */
1759                top = GetTopOfStack(file_mgr_data);
1760                while (next_position - 1 > 0)
1761                {
1762                   top = top->next;
1763                   next_position--;
1764                }
1765    
1766                while(top)
1767                {
1768                   if(top->file_view_data != NULL)
1769                      SelectFile(file_mgr_data, top->file_view_data);
1770                   top = top->prev;
1771                }
1772             }
1773    
1774             if (!XEmptyRegion(redraw_region))
1775                RepaintDesktop(file_mgr_data, NULL, redraw_region);
1776    
1777             RegisterDesktopHotspots(file_mgr_data, file_mgr_rec);
1778    
1779          }
1780          else
1781          {
1782             for (j = 0; j < directory_set[i]->file_count; j++)
1783             {
1784                file_view_data = directory_set[i]->order_list[j];
1785    
1786                if (!file_view_data->displayed)
1787                   continue;
1788    
1789                WidgetRectToRegion(file_mgr_data, file_view_data->widget,
1790                                   widget_region);
1791                XIntersectRegion (region, widget_region, intersect_region);
1792         
1793                if (!XEmptyRegion (intersect_region))
1794                {
1795                   if (toggleSelect == True && 
1796                       FileIsSelected (file_mgr_data, file_view_data))
1797                      DeselectFile (file_mgr_data, file_view_data, True);
1798                   else
1799                   {
1800                      SelectFile (file_mgr_data, file_view_data);
1801                      if(file_mgr_data->view == BY_ATTRIBUTES)
1802                      {
1803                         /* 
1804                          * Need to determine whether the click was in the
1805                          *  file or before.
1806                          */
1807                         XRectangle textExtent;
1808                         Region tmp_region;
1809                         XmFontList fontList;
1810                         XmString fileNameString;
1811                         DtIconGadget g = (DtIconGadget)file_view_data->widget;
1812
1813                         _DtIconGetTextExtent_r(file_view_data->widget,
1814                                                &textExtent);
1815    
1816                         XtVaGetValues( file_view_data->widget,
1817                                        XmNfontList,
1818                                        &fontList,
1819                                        NULL );
1820
1821                         fileNameString = XmStringCreateLocalized( file_view_data->file_data->file_name );
1822                         textExtent.width = XmStringWidth( fontList, fileNameString );
1823                         XmStringFree( fileNameString );
1824                         textExtent.height =
1825                           (unsigned short)file_view_data->widget->core.height;
1826
1827                         textExtent.x = (short)file_view_data->widget->core.x
1828                           + g->icon.pixmap_width
1829                           + g->icon.cache->margin_width
1830                           + g->icon.cache->spacing;
1831
1832                         textExtent.y = (short)file_view_data->widget->core.y;
1833    
1834                         tmp_region = XCreateRegion();
1835                         XUnionRectWithRegion (&textExtent, 
1836                                                  tmp_region, tmp_region); 
1837    
1838                         XSubtractRegion (widget_region, tmp_region, tmp_region);
1839    
1840                         XIntersectRegion (region, tmp_region, intersect_region);
1841                         if (XEmptyRegion (intersect_region))
1842                            TurnOnTextName = True; 
1843                         else
1844                            TurnOnTextName = False;
1845                         XDestroyRegion (tmp_region);
1846                      }
1847                   }
1848                }
1849             }
1850          }
1851       }
1852    
1853       XDestroyRegion (region);
1854       XDestroyRegion (widget_region);
1855       XDestroyRegion (intersect_region);
1856       XDestroyRegion (redraw_region);
1857    }
1858
1859   
1860    if(file_mgr_data != trashFileMgrData)
1861    {
1862       if (file_mgr_data->selected_file_count == 0)
1863          ActivateNoSelect (file_mgr_rec);
1864       else if (file_mgr_data->selected_file_count == 1)
1865       {
1866          ActivateSingleSelect (file_mgr_rec,
1867             file_mgr_data->selection_list[0]->file_data->logical_type);
1868       }
1869       else
1870          ActivateMultipleSelect (file_mgr_rec);
1871    }
1872    else
1873       SensitizeTrashBtns();
1874
1875    ProcessBtnUp = False;
1876 }
1877
1878
1879 void
1880 DrawHighlight (
1881       Widget w,
1882       FileViewData *file_view_data,
1883       FileMgrData *file_mgr_data,
1884       int type)
1885 {
1886    int n, num_rectangles;
1887    Position x,y;
1888    Dimension highlightThickness, shadowThickness;
1889    Dimension half_shadowThickness;
1890    Dimension marginWidth, marginHeight;
1891    Dimension pixmapWidth, pixmapHeight;
1892    Dimension stringWidth, stringHeight;
1893    Dimension spacing;
1894    XRectangle rect[10];
1895    unsigned char pixmapPosition;
1896    unsigned char alignment;
1897    Position        adj_x, adj_y;
1898    GC gc ;
1899    Arg args[20];
1900    DtIconGadget  g = (DtIconGadget)w;
1901    ObjectPtr top;
1902
1903    gc = ((XmManagerWidget)(g->object.parent))->manager.highlight_GC;
1904 #ifdef SHAPE
1905    if(shapeExtension)
1906       if(type == DESKTOP)
1907       {
1908          DrawShadowTh(w, gc, DESKTOP);
1909          return;
1910       }
1911 #endif
1912
1913    /* in in as placed mode need to cycle the icons so the traversal
1914       box doesn't chop up the icons */ 
1915    if(type == NOT_DESKTOP && file_view_data != NULL)
1916    {
1917       if (PositioningEnabledInView(file_mgr_data))
1918       {
1919          top = GetTopOfStack(file_mgr_data);
1920          if(top != NULL && top->file_view_data != file_view_data)
1921          {
1922             ObjectPtr savetop, next, prev;
1923             int i;
1924
1925             savetop = top;
1926             while(top != NULL && top->file_view_data != file_view_data)
1927                top = top->next;
1928
1929             if(top != NULL)
1930             {
1931                prev = top->prev;
1932                next = top->next;
1933                if (prev)
1934                   prev->next = next;
1935                if (next)
1936                   next->prev = prev;
1937                top->prev = NULL;
1938                top->next = savetop;
1939                top->stacking_order = 1;
1940                savetop->prev = top;
1941                top = savetop;
1942                for(i = 2; top->prev != NULL; i++)
1943                {
1944                   top->stacking_order = i;
1945                   if(top->next == NULL)
1946                      break;
1947                   top = top->next;
1948                }
1949
1950                RedrawOneGadget(w, NULL, NULL);
1951             }
1952          }
1953       }
1954    }
1955
1956    n = 0;
1957    XtSetArg (args[n], XmNhighlightThickness, &highlightThickness);      n++;
1958    XtSetArg (args[n], XmNshadowThickness, &shadowThickness);      n++;
1959    XtSetArg (args[n], XmNx, &x);      n++;
1960    XtSetArg (args[n], XmNy, &y);      n++;
1961    XtSetArg (args[n], XmNmarginWidth, &marginWidth);      n++;
1962    XtSetArg (args[n], XmNmarginHeight, &marginHeight);      n++;
1963    XtSetArg (args[n], XmNpixmapPosition, &pixmapPosition);      n++;
1964    XtSetArg (args[n], XmNalignment, &alignment);      n++;
1965    XtGetValues (w, args, n);
1966    
1967    spacing = (((DtIconGadget)(g)) -> icon.cache -> spacing);
1968    pixmapWidth = g->icon.pixmap_width;
1969    pixmapHeight = g->icon.pixmap_height;
1970    stringWidth = g->icon.string_width;
1971    stringHeight = g->icon.cache->string_height;
1972
1973    adj_x = shadowThickness + highlightThickness + marginWidth;
1974    adj_y = shadowThickness + highlightThickness + marginHeight;
1975    
1976    if(shadowThickness != 0)
1977      half_shadowThickness = shadowThickness/2;
1978    else
1979      half_shadowThickness = 0;
1980
1981    num_rectangles = 0;
1982    switch ((int) pixmapPosition)
1983    {
1984       case XmPIXMAP_TOP:
1985          if (alignment == XmALIGNMENT_BEGINNING)
1986          {
1987            /* 1 */
1988             rect[num_rectangles].x = x;
1989             rect[num_rectangles].y = y;
1990             rect[num_rectangles].width = pixmapWidth + (2 * adj_x);
1991             rect[num_rectangles++].height = highlightThickness;
1992
1993             if(stringWidth >  pixmapWidth)
1994             {
1995               /* 2 */
1996                rect[num_rectangles].x = x + pixmapWidth +
1997                                             (2 * adj_x) - highlightThickness;
1998                rect[num_rectangles].y = y;
1999                rect[num_rectangles].width = highlightThickness;
2000                rect[num_rectangles++].height = pixmapHeight + spacing;
2001
2002               /* 3 */
2003                rect[num_rectangles].x = x + pixmapWidth +
2004                                               (2 * adj_x) - highlightThickness;
2005                rect[num_rectangles].y = y + pixmapHeight + spacing;
2006                rect[num_rectangles].width = stringWidth -
2007                                            pixmapWidth + highlightThickness;
2008                rect[num_rectangles++].height = highlightThickness;
2009
2010               /* 4 */
2011                rect[num_rectangles].x = x + stringWidth + (2 * adj_x)
2012                                                           - highlightThickness;
2013                rect[num_rectangles].y = y + pixmapHeight + spacing;
2014                rect[num_rectangles].width = highlightThickness;
2015                rect[num_rectangles++].height = stringHeight + (2 * adj_y);
2016             }
2017             else
2018             {
2019               /* 2 */
2020                rect[num_rectangles].x = x + pixmapWidth +
2021                                             (2 * adj_x) - highlightThickness;
2022                rect[num_rectangles].y = y;
2023                rect[num_rectangles].width = highlightThickness;
2024                rect[num_rectangles++].height = pixmapHeight + (2 * adj_y) -
2025                                                   highlightThickness;
2026
2027               /* 3 */
2028                rect[num_rectangles].x = x + stringWidth +
2029                                               (2 * adj_x) - highlightThickness;
2030                rect[num_rectangles].y = y + pixmapHeight + (2 * adj_y) - 
2031                                                          highlightThickness;
2032                rect[num_rectangles].width = pixmapWidth -
2033                                            stringWidth + highlightThickness;
2034                rect[num_rectangles++].height = highlightThickness;
2035
2036
2037               /* 4 */
2038                rect[num_rectangles].x = x + stringWidth + (2 * adj_x)
2039                                                           - highlightThickness;
2040                rect[num_rectangles].y = y + pixmapHeight + (2 * adj_y) - 
2041                                                          highlightThickness;
2042                rect[num_rectangles].width = highlightThickness;
2043                rect[num_rectangles++].height = spacing + stringHeight + 
2044                                                            highlightThickness; 
2045             }
2046
2047            /* 5 */
2048             rect[num_rectangles].x = x;
2049             rect[num_rectangles].y = y + pixmapHeight + stringHeight +
2050                                 spacing + (2 * adj_y) - highlightThickness;
2051             rect[num_rectangles].width = stringWidth + (2 * adj_y);
2052             rect[num_rectangles++].height = highlightThickness;
2053
2054            /* 6 */
2055             rect[num_rectangles].x = x;
2056             rect[num_rectangles].y = y;
2057             rect[num_rectangles].width = highlightThickness;
2058             rect[num_rectangles++].height = pixmapHeight +
2059                                    stringHeight + spacing + (2 * adj_y);
2060
2061          }
2062          else if (alignment == XmALIGNMENT_CENTER)
2063          {
2064             if(stringWidth >  pixmapWidth)
2065             {
2066               /* 1 */
2067                rect[num_rectangles].x = x
2068                                       + (Dimension)(stringWidth - pixmapWidth)/(Dimension)2;
2069                rect[num_rectangles].y = y;
2070                rect[num_rectangles].width = pixmapWidth + (2 * adj_x);
2071                rect[num_rectangles++].height = highlightThickness;
2072
2073               /* 2 */
2074                rect[num_rectangles].x = x
2075                                         + (Dimension)(stringWidth - pixmapWidth)/(Dimension)2
2076                                         +  pixmapWidth
2077                                         + (2 * adj_x)
2078                                         - highlightThickness;
2079                rect[num_rectangles].y = y;
2080                rect[num_rectangles].width = highlightThickness;
2081                rect[num_rectangles++].height = pixmapHeight + spacing;
2082
2083               /* 3 */
2084                rect[num_rectangles].x = x
2085                                         + (Dimension)(stringWidth - pixmapWidth)/(Dimension)2
2086                                         +  pixmapWidth
2087                                         + (2 * adj_x)
2088                                         - highlightThickness;
2089                rect[num_rectangles].y = y + pixmapHeight + spacing;
2090                rect[num_rectangles].width = (Dimension)(stringWidth - pixmapWidth)/(Dimension)2
2091                                             + (Dimension)(stringWidth - pixmapWidth)%(Dimension)2; 
2092                rect[num_rectangles++].height = highlightThickness;
2093    
2094               /* 4 */
2095                rect[num_rectangles].x = x + stringWidth + (2 * adj_x)
2096                                                         - highlightThickness;
2097                rect[num_rectangles].y = y + pixmapHeight + spacing;
2098                rect[num_rectangles].width = highlightThickness;
2099                rect[num_rectangles++].height = stringHeight + (2 * adj_y);
2100    
2101               /* 5 */
2102                rect[num_rectangles].x = x;
2103                rect[num_rectangles].y = y + pixmapHeight + stringHeight +
2104                                    spacing + (2 * adj_y) - highlightThickness;
2105                rect[num_rectangles].width = stringWidth + (2 * adj_y);
2106                rect[num_rectangles++].height = highlightThickness;
2107    
2108               /* 6 */
2109                rect[num_rectangles].x = x;
2110                rect[num_rectangles].y = y + pixmapHeight + spacing;
2111                rect[num_rectangles].width = highlightThickness;
2112                rect[num_rectangles++].height = stringHeight + (2 * adj_y);
2113    
2114               /* 7 */
2115                rect[num_rectangles].x = x;
2116                rect[num_rectangles].y = y + pixmapHeight + spacing;
2117                rect[num_rectangles].width = (Dimension)(stringWidth - pixmapWidth)/(Dimension)2
2118                                             + highlightThickness;
2119                rect[num_rectangles++].height = highlightThickness;
2120    
2121               /* 8 */
2122                rect[num_rectangles].x = x + (Dimension)(stringWidth - pixmapWidth)/(Dimension)2;
2123                rect[num_rectangles].y = y;
2124                rect[num_rectangles].width = highlightThickness;
2125                rect[num_rectangles++].height = pixmapHeight + spacing;
2126             }
2127             else
2128             {
2129               /* 1 */
2130                rect[num_rectangles].x = x;
2131                rect[num_rectangles].y = y;
2132                rect[num_rectangles].width = pixmapWidth + (2 * adj_x);
2133                rect[num_rectangles++].height = highlightThickness;
2134
2135               /* 2 */
2136                rect[num_rectangles].x = x + pixmapWidth + (2 * adj_x) - 
2137                                                            highlightThickness;
2138                rect[num_rectangles].y = y;
2139                rect[num_rectangles].width = highlightThickness;
2140                rect[num_rectangles++].height = pixmapHeight + spacing + 
2141                                                         2 * highlightThickness;
2142
2143               /* 3 */
2144                rect[num_rectangles].x = x +  pixmapWidth + adj_x - 
2145                             (Dimension)(pixmapWidth - stringWidth)/(Dimension)2 + highlightThickness;
2146                rect[num_rectangles].y = y + pixmapHeight + spacing +
2147                                                         highlightThickness + 1;
2148                rect[num_rectangles].width = (Dimension)(pixmapWidth - stringWidth)/(Dimension)2 +
2149                                                           highlightThickness;
2150                rect[num_rectangles++].height = highlightThickness;
2151
2152               /* 4 */
2153                rect[num_rectangles].x = x  + stringWidth + adj_x +
2154                            (Dimension)(pixmapWidth - stringWidth)/(Dimension)2 + highlightThickness;
2155                rect[num_rectangles].y = y + pixmapHeight + spacing
2156                                                       + highlightThickness + 1;
2157                rect[num_rectangles].width = highlightThickness;
2158                rect[num_rectangles++].height = stringHeight + (2 * adj_y) 
2159                                                        - highlightThickness - 1;
2160
2161               /* 5 */
2162                rect[num_rectangles].x = x + (Dimension)(pixmapWidth - stringWidth)/(Dimension)2;
2163                rect[num_rectangles].y = y + pixmapHeight + stringHeight +
2164                                    spacing + (2 * adj_y) - highlightThickness;
2165                rect[num_rectangles].width = stringWidth + (2 * adj_y);
2166                rect[num_rectangles++].height = highlightThickness;
2167
2168               /* 6 */
2169                rect[num_rectangles].x = x + (Dimension)(pixmapWidth - stringWidth)/(Dimension)2;
2170                rect[num_rectangles].y = y + pixmapHeight + spacing +
2171                                                         highlightThickness + 1;
2172                rect[num_rectangles].width = highlightThickness;
2173                rect[num_rectangles++].height = stringHeight + (2 * adj_y) 
2174                                                        - highlightThickness - 1;
2175  
2176               /* 7 */
2177                rect[num_rectangles].x = x;
2178                rect[num_rectangles].y = y + pixmapHeight + spacing +
2179                                                         highlightThickness + 1;
2180                rect[num_rectangles].width = (Dimension)(pixmapWidth - stringWidth)/(Dimension)2 +
2181                                                             highlightThickness;
2182                rect[num_rectangles++].height = highlightThickness;
2183
2184               /* 8 */
2185                rect[num_rectangles].x = x;
2186                rect[num_rectangles].y = y;
2187                rect[num_rectangles].width = highlightThickness;
2188                rect[num_rectangles++].height = pixmapHeight + spacing + 
2189                                                         2 * highlightThickness;
2190             }
2191          }
2192          else 
2193             FM_XmHighlightBorder ((Widget)w);
2194          break;
2195       case XmPIXMAP_LEFT:
2196          if((Dimension)(stringHeight + 4) >= pixmapHeight)
2197             FM_XmHighlightBorder ((Widget)w);
2198          else
2199          {
2200            /* 1 */
2201             rect[num_rectangles].x = x;
2202             rect[num_rectangles].y = y;
2203             rect[num_rectangles].width = adj_x + pixmapWidth + (Dimension)(spacing+1)/(Dimension)2;
2204             rect[num_rectangles++].height = highlightThickness;
2205
2206            /* 2 */
2207             rect[num_rectangles].x = x + adj_x + pixmapWidth + (Dimension)(spacing+1)/(Dimension)2;
2208             rect[num_rectangles].y = y;
2209             rect[num_rectangles].width = highlightThickness;
2210             rect[num_rectangles++].height = (Dimension)(pixmapHeight - stringHeight)/(Dimension)2;
2211
2212            /* 3 */
2213             rect[num_rectangles].x = x + adj_x + pixmapWidth + (Dimension)(spacing+1)/(Dimension)2;
2214             rect[num_rectangles].y = y + (Dimension)(pixmapHeight - stringHeight)/(Dimension)2;
2215             rect[num_rectangles].width = spacing/2 + stringWidth + adj_x;
2216             rect[num_rectangles++].height = highlightThickness;
2217
2218            /* 4 */
2219             rect[num_rectangles].x = x + adj_x + pixmapWidth + spacing +
2220                                       stringWidth + adj_x - highlightThickness;
2221             rect[num_rectangles].y = y + (Dimension)(pixmapHeight - stringHeight)/(Dimension)2;
2222             rect[num_rectangles].width = highlightThickness;
2223             rect[num_rectangles++].height = stringHeight + 2*adj_y;
2224
2225            /* 5 */
2226             rect[num_rectangles].x = x + adj_x + pixmapWidth + (Dimension)(spacing+1)/(Dimension)2;
2227             rect[num_rectangles].y = y + (Dimension)(pixmapHeight - stringHeight)/(Dimension)2 +
2228                                stringHeight + 2*adj_y - highlightThickness;
2229             rect[num_rectangles].width = spacing/2 + stringWidth + adj_x;
2230             rect[num_rectangles++].height = highlightThickness;
2231
2232            /* 6 */
2233             rect[num_rectangles].x = x + adj_x + pixmapWidth + (Dimension)(spacing+1)/(Dimension)2;
2234             rect[num_rectangles].y = y + (Dimension)(pixmapHeight - stringHeight)/(Dimension)2 +
2235                                          stringHeight + 2*adj_y;
2236             rect[num_rectangles].width = highlightThickness;
2237             rect[num_rectangles++].height = pixmapHeight - stringHeight -
2238                                             (Dimension)(pixmapHeight - stringHeight)/(Dimension)2;
2239
2240            /* 7 */
2241             rect[num_rectangles].x = x;
2242             rect[num_rectangles].y = y + pixmapHeight + 2*adj_y -
2243                                                            highlightThickness;
2244             rect[num_rectangles].width = adj_x + pixmapWidth + (Dimension)(spacing+1)/(Dimension)2;
2245             rect[num_rectangles++].height = highlightThickness;
2246
2247            /* 8 */
2248             rect[num_rectangles].x = x;
2249             rect[num_rectangles].y = y;
2250             rect[num_rectangles].width = highlightThickness;
2251             rect[num_rectangles++].height = pixmapHeight + 2*adj_y;
2252          }
2253          break;
2254       case XmPIXMAP_BOTTOM:
2255       case XmPIXMAP_RIGHT:
2256          FM_XmHighlightBorder ((Widget)w);
2257          break;
2258       default:
2259          break;
2260    }
2261   
2262    XFillRectangles (XtDisplay (w), XtWindow (w), gc, &rect[0], num_rectangles);
2263 }
2264
2265 void
2266 DrawUnhighlight ( 
2267       Widget w,
2268       int type)
2269 {
2270    int n;
2271    Position x,y;
2272    Dimension highlightThickness, shadowThickness;
2273    Dimension half_shadowThickness;
2274    Dimension marginWidth, marginHeight;
2275    Dimension pixmapWidth, pixmapHeight;
2276    Dimension stringWidth, stringHeight;
2277    Dimension spacing;
2278    unsigned char pixmapPosition;
2279    unsigned char alignment;
2280    Position        adj_x, adj_y;
2281    Arg args[20];
2282    DtIconGadget g = (DtIconGadget)w;
2283
2284 #ifdef SHAPE
2285    if(shapeExtension)
2286       if(type == DESKTOP)
2287       {
2288          DrawShadowTh(w, NULL, DESKTOP);
2289          return;
2290       }
2291 #endif
2292
2293    n = 0;
2294    XtSetArg (args[n], XmNhighlightThickness, &highlightThickness);      n++;
2295    XtSetArg (args[n], XmNshadowThickness, &shadowThickness);      n++;
2296    XtSetArg (args[n], XmNx, &x);      n++;
2297    XtSetArg (args[n], XmNy, &y);      n++;
2298    XtSetArg (args[n], XmNmarginWidth, &marginWidth);      n++;
2299    XtSetArg (args[n], XmNmarginHeight, &marginHeight);      n++;
2300    XtSetArg (args[n], XmNpixmapPosition, &pixmapPosition);      n++;
2301    XtSetArg (args[n], XmNalignment, &alignment);      n++;
2302    XtGetValues (w, args, n);
2303
2304    spacing = (((DtIconGadget)(g)) -> icon.cache -> spacing);
2305    pixmapWidth = g->icon.pixmap_width;
2306    pixmapHeight = g->icon.pixmap_height;
2307    stringWidth = g->icon.string_width;
2308    stringHeight = g->icon.cache->string_height;
2309
2310    adj_x = shadowThickness + highlightThickness + marginWidth;
2311    adj_y = shadowThickness + highlightThickness + marginHeight;
2312
2313    if(shadowThickness != 0)
2314      half_shadowThickness = shadowThickness/2;
2315    else
2316      half_shadowThickness = 0;
2317
2318    switch ((int) pixmapPosition)
2319    {
2320       case XmPIXMAP_TOP:
2321          if (alignment == XmALIGNMENT_BEGINNING)
2322          {
2323            /* 1 */
2324             XClearArea (XtDisplay (w), XtWindow (w), x, y, 
2325                        pixmapWidth + (2 * adj_x), highlightThickness, False);
2326
2327             if(stringWidth >  pixmapWidth)
2328             {
2329               /* 2 */
2330                XClearArea (XtDisplay (w), XtWindow (w), 
2331                            x + pixmapWidth + (2 * adj_x) - highlightThickness,
2332                            y, highlightThickness, 
2333                            pixmapHeight + spacing,
2334                            False);
2335
2336               /* 3 */
2337                XClearArea (XtDisplay (w), XtWindow (w), 
2338                            x + pixmapWidth + (2 * adj_x) - highlightThickness,
2339                            y + pixmapHeight + spacing,
2340                            stringWidth - pixmapWidth + highlightThickness, 
2341                            highlightThickness, 
2342                            False);
2343
2344               /* 4 */
2345                XClearArea (XtDisplay (w), XtWindow (w), 
2346                            x + stringWidth + (2 * adj_x) - highlightThickness,
2347                            y + pixmapHeight + spacing,
2348                            highlightThickness, 
2349                            stringHeight + (2 * adj_y),
2350                            False);
2351             }
2352             else
2353             {
2354               /* 2 */
2355                XClearArea (XtDisplay (w), XtWindow (w),
2356                            x + pixmapWidth + (2 * adj_x) - highlightThickness,
2357                            y, highlightThickness,
2358                            pixmapHeight + (2 * adj_y) - half_shadowThickness,
2359                            False);
2360
2361               /* 3 */
2362                XClearArea (XtDisplay (w), XtWindow (w),
2363                            x + stringWidth + (2 * adj_x) - highlightThickness,
2364                            y + pixmapHeight + (2 * adj_y) - highlightThickness,
2365                            pixmapWidth - stringWidth + highlightThickness,
2366                            highlightThickness,
2367                            False);
2368
2369               /* 4 */
2370                XClearArea (XtDisplay (w), XtWindow (w),
2371                            x + stringWidth + (2 * adj_x) - highlightThickness,
2372                            y + pixmapHeight + (2 * adj_y) -
2373                                                          half_shadowThickness,
2374                            highlightThickness,
2375                            spacing + stringHeight + highlightThickness,
2376                            False);
2377             }
2378
2379            /* 5 */
2380             XClearArea (XtDisplay (w), XtWindow (w), x, 
2381                            y + pixmapHeight + stringHeight +
2382                                 spacing + (2 * adj_y) - highlightThickness,
2383                            stringWidth + (2 * adj_y),
2384                            highlightThickness, 
2385                            False);
2386
2387            /* 6 */
2388             XClearArea (XtDisplay (w), XtWindow (w), x, y,
2389                            highlightThickness, 
2390                            pixmapHeight + stringHeight + spacing + (2 * adj_y),
2391                            False);
2392
2393          }
2394          else if (alignment == XmALIGNMENT_CENTER)
2395          {
2396             if(stringWidth >  pixmapWidth)
2397             {
2398               /* 1 */
2399                XClearArea (XtDisplay (w), XtWindow (w), 
2400                            x + (Dimension)(stringWidth - pixmapWidth)/(Dimension)2, y,
2401                            pixmapWidth + (2 * adj_x),
2402                            highlightThickness, 
2403                            False);
2404
2405               /* 2 */
2406                XClearArea (XtDisplay (w), XtWindow (w), 
2407                           x + (Dimension)(stringWidth - pixmapWidth)/(Dimension)2 + pixmapWidth +
2408                                             (2 * adj_x) - highlightThickness,
2409                           y, highlightThickness, pixmapHeight + spacing,
2410                           False);
2411
2412               /* 3 */
2413                XClearArea (XtDisplay (w), XtWindow (w), 
2414                           x + (Dimension)(stringWidth - pixmapWidth)/(Dimension)2 + pixmapWidth + 
2415                                             (2 * adj_x) - highlightThickness,
2416                           y + pixmapHeight + spacing,
2417                           (Dimension)(stringWidth - pixmapWidth)/(Dimension)2 + 
2418                                       (Dimension)(stringWidth - pixmapWidth)%(Dimension)2, 
2419                           highlightThickness,
2420                           False);
2421
2422               /* 4 */
2423                XClearArea (XtDisplay (w), XtWindow (w), 
2424                           x + stringWidth + (2 * adj_x) - highlightThickness,
2425                           y + pixmapHeight + spacing, highlightThickness,
2426                           stringHeight + (2 * adj_y),
2427                           False);
2428
2429               /* 5 */
2430                XClearArea (XtDisplay (w), XtWindow (w), x,
2431                           y + pixmapHeight + stringHeight +
2432                                 spacing + (2 * adj_y) - highlightThickness,
2433                           stringWidth + (2 * adj_y), highlightThickness,
2434                           False);
2435
2436               /* 6 */
2437                XClearArea (XtDisplay (w), XtWindow (w), x,
2438                           y + pixmapHeight + spacing, highlightThickness,
2439                           stringHeight + (2 * adj_y),
2440                           False);
2441
2442               /* 7 */
2443                XClearArea (XtDisplay (w), XtWindow (w), x,
2444                           y + pixmapHeight + spacing, 
2445                           (Dimension)(stringWidth - pixmapWidth)/(Dimension)2 + highlightThickness, 
2446                           highlightThickness,
2447                           False);
2448
2449               /* 8 */
2450                XClearArea (XtDisplay (w), XtWindow (w),
2451                           x + (Dimension)(stringWidth - pixmapWidth)/(Dimension)2,
2452                           y, highlightThickness, pixmapHeight + spacing,
2453                           False);
2454             }
2455             else
2456             {
2457               /* 1 */
2458                XClearArea (XtDisplay (w), XtWindow (w), x, y,
2459                           pixmapWidth + (2 * adj_x), highlightThickness,
2460                           False);
2461
2462               /* 2 */
2463                XClearArea (XtDisplay (w), XtWindow (w),
2464                           x + pixmapWidth + (2 * adj_x) - highlightThickness,
2465                           y, highlightThickness, 
2466                           pixmapHeight + spacing + 2 *  highlightThickness,
2467                           False);
2468
2469               /* 3 */
2470                XClearArea (XtDisplay (w), XtWindow (w),
2471                           x +  pixmapWidth + adj_x + highlightThickness - 
2472                                        (Dimension)(pixmapWidth - stringWidth)/(Dimension)2,
2473                           y + pixmapHeight + spacing + highlightThickness + 1,
2474                           (Dimension)(pixmapWidth - stringWidth)/(Dimension)2 + highlightThickness,
2475                           highlightThickness,
2476                           False);
2477
2478               /* 4 */
2479                XClearArea (XtDisplay (w), XtWindow (w),
2480                           x  + stringWidth + (Dimension)(pixmapWidth - stringWidth)/(Dimension)2 +
2481                                                     adj_x + highlightThickness,
2482                           y + pixmapHeight + spacing + highlightThickness + 1,
2483                           highlightThickness,
2484                           stringHeight + (2 * adj_y) - highlightThickness -1,
2485                           False);
2486
2487               /* 5 */
2488                XClearArea (XtDisplay (w), XtWindow (w),
2489                           x + (Dimension)(pixmapWidth - stringWidth)/(Dimension)2,
2490                           y + pixmapHeight + stringHeight +
2491                                    spacing + (2 * adj_y) - highlightThickness,
2492                           stringWidth + (2 * adj_y),
2493                           highlightThickness,
2494                           False);
2495
2496               /* 6 */
2497                XClearArea (XtDisplay (w), XtWindow (w),
2498                           x + (Dimension)(pixmapWidth - stringWidth)/(Dimension)2,
2499                           y + pixmapHeight + spacing + highlightThickness + 1,
2500                           highlightThickness,
2501                           stringHeight + (2 * adj_y) - highlightThickness - 1,
2502                           False);
2503
2504               /* 7 */
2505                XClearArea (XtDisplay (w), XtWindow (w), x,
2506                           y + pixmapHeight + spacing + highlightThickness + 1,
2507                           (Dimension)(pixmapWidth - stringWidth)/(Dimension)2 + highlightThickness,
2508                           highlightThickness,
2509                           False);
2510
2511               /* 8 */
2512                XClearArea (XtDisplay (w), XtWindow (w), x, y,
2513                           highlightThickness, 
2514                           pixmapHeight + spacing + 2 * highlightThickness,
2515                           False);
2516
2517             }
2518          }
2519          else
2520             FM_XmUnhighlightBorder ((Widget)w);
2521          break;
2522       case XmPIXMAP_LEFT:
2523          if((Dimension)(stringHeight + 4) >= pixmapHeight)
2524             FM_XmUnhighlightBorder ((Widget)w);
2525          else
2526          {
2527            /* 1 */
2528             XClearArea (XtDisplay (w), XtWindow (w), x, y,
2529                            adj_x + pixmapWidth + (Dimension)(spacing+1)/(Dimension)2,
2530                            highlightThickness,
2531                            False);
2532
2533            /* 2 */
2534             XClearArea (XtDisplay (w), XtWindow (w),
2535                            x + adj_x + pixmapWidth + (Dimension)(spacing+1)/(Dimension)2,
2536                            y,
2537                            highlightThickness,
2538                            (Dimension)(pixmapHeight - stringHeight)/(Dimension)2,
2539                            False);
2540
2541            /* 3 */
2542             XClearArea (XtDisplay (w), XtWindow (w),
2543                            x + adj_x + pixmapWidth + (Dimension)(spacing+1)/(Dimension)2,
2544                            y + (Dimension)(pixmapHeight - stringHeight)/(Dimension)2,
2545                            spacing/2 + stringWidth + adj_x,
2546                            highlightThickness,
2547                            False);
2548
2549            /* 4 */
2550             XClearArea (XtDisplay (w), XtWindow (w),
2551                            x + adj_x + pixmapWidth + spacing +
2552                                       stringWidth + adj_x - highlightThickness,
2553                            y + (Dimension)(pixmapHeight - stringHeight)/(Dimension)2,
2554                            highlightThickness,
2555                            stringHeight + 2*adj_y,
2556                            False);
2557
2558            /* 5 */
2559             XClearArea (XtDisplay (w), XtWindow (w),
2560                            x + adj_x + pixmapWidth + (Dimension)(spacing+1)/(Dimension)2,
2561                            y + (Dimension)(pixmapHeight - stringHeight)/(Dimension)2 +
2562                                stringHeight + 2*adj_y - highlightThickness,
2563                            spacing/2 + stringWidth + adj_x,
2564                            highlightThickness,
2565                            False);
2566
2567            /* 6 */
2568             XClearArea (XtDisplay (w), XtWindow (w),
2569                            x + adj_x + pixmapWidth + (Dimension)(spacing+1)/(Dimension)2,
2570                            y + (Dimension)(pixmapHeight - stringHeight)/(Dimension)2 +
2571                                          stringHeight + 2*adj_y,
2572                            highlightThickness,
2573                            pixmapHeight - stringHeight -
2574                                             (Dimension)(pixmapHeight - stringHeight)/(Dimension)2,
2575                            False);
2576
2577            /* 7 */
2578             XClearArea (XtDisplay (w), XtWindow (w), x,
2579                            y + pixmapHeight + 2*adj_y - highlightThickness,
2580                            adj_x + pixmapWidth + (Dimension)(spacing+1)/(Dimension)2,
2581                            highlightThickness,
2582                            False);
2583
2584            /* 8 */
2585             XClearArea (XtDisplay (w), XtWindow (w), x, y,
2586                            highlightThickness,
2587                            pixmapHeight + 2*adj_y,
2588                            False);
2589          }
2590          break;
2591       case XmPIXMAP_BOTTOM:
2592       case XmPIXMAP_RIGHT:
2593          FM_XmUnhighlightBorder ((Widget)w);
2594          break;
2595       default:
2596          break;
2597    }
2598 }
2599 void
2600 DrawShadowTh (
2601       Widget w,
2602       GC gc,
2603       int type)
2604 {
2605    int n;
2606    Position x,y;
2607    Dimension highlightThickness, shadowThickness;
2608    Dimension width, height;
2609    Dimension marginWidth, marginHeight;
2610    Dimension pixmapWidth, pixmapHeight;
2611    Dimension stringWidth, stringHeight;
2612    Dimension spacing;
2613    unsigned char pixmapPosition;
2614    unsigned char alignment;
2615    unsigned char shadowType;
2616    GC top_gc, bottom_gc ;
2617    Arg args[20];
2618    XRectangle rect[10];
2619    DtIconGadget g = (DtIconGadget)w;
2620    XmManagerWidget mgr = (XmManagerWidget)XtParent(w);
2621    Boolean         s_out = NULL,
2622                    s_etched =      NULL;
2623
2624
2625
2626    n = 0;
2627    XtSetArg (args[n], XmNhighlightThickness, &highlightThickness);      n++;
2628    XtSetArg (args[n], XmNshadowThickness, &shadowThickness);      n++;
2629    XtSetArg (args[n], XmNx, &x);      n++;
2630    XtSetArg (args[n], XmNy, &y);      n++;
2631    XtSetArg (args[n], XmNwidth, &width);      n++;
2632    XtSetArg (args[n], XmNheight, &height);      n++;
2633    XtSetArg (args[n], XmNmarginWidth, &marginWidth);      n++;
2634    XtSetArg (args[n], XmNmarginHeight, &marginHeight);      n++;
2635    XtSetArg (args[n], XmNpixmapPosition, &pixmapPosition);      n++;
2636    XtSetArg (args[n], XmNalignment, &alignment);      n++;
2637    XtSetArg (args[n], XmNshadowType, &shadowType);      n++;
2638    XtGetValues (w, args, n);
2639
2640    spacing = (((DtIconGadget)(g)) -> icon.cache -> spacing);
2641    pixmapWidth = g->icon.pixmap_width;
2642    pixmapHeight = g->icon.pixmap_height;
2643    stringWidth = g->icon.string_width;
2644    stringHeight = g->icon.cache->string_height;
2645
2646 /*      Get shadow attributes.
2647 */
2648    s_out = (shadowType == XmSHADOW_OUT || shadowType == XmSHADOW_ETCHED_OUT)
2649                 ? True : False;
2650    s_etched = (shadowType == XmSHADOW_ETCHED_IN ||
2651                                           shadowType == XmSHADOW_ETCHED_OUT)
2652                 ? True : False;
2653
2654    if(gc == NULL)
2655    {
2656       if(shadowType == XmSHADOW_ETCHED_OUT)
2657       {
2658          top_gc = (s_out)
2659                 ? mgr->manager.top_shadow_GC : mgr->manager.bottom_shadow_GC;
2660          bottom_gc = (s_out)
2661                 ? mgr->manager.bottom_shadow_GC : mgr->manager.top_shadow_GC;
2662       }
2663       else
2664       {
2665          bottom_gc = (s_out)
2666                 ? mgr->manager.top_shadow_GC : mgr->manager.bottom_shadow_GC;
2667          top_gc = (s_out)
2668                 ? mgr->manager.bottom_shadow_GC : mgr->manager.top_shadow_GC;
2669       }
2670    }
2671    else
2672       top_gc = bottom_gc = gc;
2673
2674 /*      Draw shadow.
2675 */
2676    if (!s_etched)
2677    {
2678       XmeDrawShadows (XtDisplay(w), XtWindow(w), top_gc, bottom_gc,
2679                       x + highlightThickness, 
2680                       y + highlightThickness, 
2681                       width - 2*highlightThickness,
2682                       height - 2*highlightThickness,
2683                       shadowThickness, XmSHADOW_IN);
2684    }
2685    else
2686    {
2687       int half_shadowThickness;
2688       int num_rects;
2689
2690       if (shadowThickness <= 0) return;
2691       if (shadowThickness > (Dimension)(width / 2)) shadowThickness = width / 2;
2692       if (shadowThickness > (Dimension)(height / 2)) shadowThickness = height / 2;
2693       if (shadowThickness <= 0) return;
2694
2695       shadowThickness = (shadowThickness % 2) ? 
2696                                     (shadowThickness-1) : (shadowThickness);
2697
2698       half_shadowThickness = shadowThickness / 2;
2699       switch ((int) pixmapPosition)
2700       {
2701          case XmPIXMAP_TOP:
2702             if (alignment == XmALIGNMENT_BEGINNING)
2703             {
2704                if(type == NOT_DESKTOP)
2705                {
2706                   num_rects = 0;
2707                  /* 1 */
2708                   rect[num_rects].x = x + highlightThickness;
2709                   rect[num_rects].y = y + highlightThickness;
2710                   rect[num_rects].width = pixmapWidth + (2 * shadowThickness) +
2711                                        (2 * marginWidth) - half_shadowThickness;
2712                   rect[num_rects++].height = half_shadowThickness;
2713
2714                  /* 2 */
2715                   rect[num_rects].x = x + highlightThickness + pixmapWidth +
2716                                         (2 * marginWidth) + shadowThickness;
2717                   rect[num_rects].y = y + highlightThickness;
2718                   rect[num_rects].width = half_shadowThickness;
2719                   rect[num_rects++].height = pixmapHeight + marginHeight + 
2720                                                 spacing/2 + shadowThickness +
2721                                                 half_shadowThickness;
2722
2723                   if(stringWidth >  pixmapWidth)
2724                   {
2725                     /* 3 */
2726                      rect[num_rects].x = x + highlightThickness + 
2727                                          shadowThickness +
2728                                          pixmapWidth + (2 * marginWidth);
2729                      rect[num_rects].y = y + pixmapHeight + 2*marginHeight +
2730                                                           shadowThickness;
2731                      rect[num_rects].width = stringWidth - pixmapWidth +
2732                                           marginWidth - half_shadowThickness;
2733                      rect[num_rects++].height = half_shadowThickness;
2734
2735                     /* 4 */
2736                      rect[num_rects].x = x + stringWidth + (2 * marginWidth)
2737                                     + shadowThickness + highlightThickness;
2738                      rect[num_rects].y = y + pixmapHeight + 2*marginHeight +
2739                                                           shadowThickness;
2740                      rect[num_rects].width = half_shadowThickness;
2741                      rect[num_rects++].height = stringHeight + 
2742                                  (2*marginHeight) + half_shadowThickness;
2743                   }
2744                   else
2745                   {
2746                     /* 3 */
2747                      rect[num_rects].x = x + highlightThickness + stringWidth +
2748                                       (2 * marginWidth) + shadowThickness;
2749                      rect[num_rects].y = y + pixmapHeight + 2*marginHeight +
2750                                          shadowThickness + half_shadowThickness;
2751                      rect[num_rects].width = pixmapWidth - stringWidth + 
2752                                            marginHeight - half_shadowThickness;
2753                      rect[num_rects++].height = half_shadowThickness;
2754
2755                     /* 4 */
2756                      rect[num_rects].x = x + highlightThickness + stringWidth +
2757                                       (2 * marginWidth) + shadowThickness;
2758                      rect[num_rects].y = y + pixmapHeight + 2*marginHeight +
2759                                         shadowThickness + half_shadowThickness;
2760                      rect[num_rects].width = half_shadowThickness;
2761                      rect[num_rects++].height = stringHeight + 
2762                                        (2*marginHeight); 
2763
2764                   }
2765                  /* 5 */
2766                   rect[num_rects].x = x + highlightThickness;
2767                   rect[num_rects].y = y + highlightThickness + pixmapHeight +
2768                     stringHeight + spacing + (2*marginHeight) + shadowThickness;
2769                   if(stringWidth >  pixmapWidth)
2770                      rect[num_rects].width = stringWidth + (2 * marginWidth) +
2771                                          shadowThickness + half_shadowThickness;
2772                   else
2773                      rect[num_rects].width = stringWidth + (2 * marginWidth) +
2774                                          shadowThickness + half_shadowThickness;
2775                   rect[num_rects++].height = half_shadowThickness;
2776
2777                  /* 6 */
2778                   rect[num_rects].x = x + highlightThickness;
2779                   rect[num_rects].y = y + highlightThickness;
2780                   rect[num_rects].width = half_shadowThickness;
2781                   rect[num_rects++].height = pixmapHeight + stringHeight +
2782                           spacing + (2 * marginHeight) + shadowThickness;
2783    
2784                   XFillRectangles (XtDisplay (w), XtWindow (w), top_gc,
2785                                                         &rect[0], num_rects);
2786
2787                   num_rects = 0;
2788                  /* 1 */
2789                   rect[num_rects].x = x + highlightThickness +
2790                                                           half_shadowThickness;
2791                   rect[num_rects].y = y + highlightThickness +
2792                                                           half_shadowThickness;
2793                   rect[num_rects].width = pixmapWidth + (2 * marginWidth) +
2794                                                           half_shadowThickness;
2795                   rect[num_rects++].height = half_shadowThickness;
2796
2797                   if(stringWidth >  pixmapWidth)
2798                   {
2799                     /* 2 */
2800                      rect[num_rects].x = x + highlightThickness + pixmapWidth +
2801                                          shadowThickness + (2 * marginWidth) +
2802                                          half_shadowThickness;
2803                      rect[num_rects].y = y + highlightThickness;
2804                      rect[num_rects].width = half_shadowThickness;
2805                      if(highlightThickness == 0)
2806                         rect[num_rects++].height = pixmapHeight + marginHeight+ 
2807                                        shadowThickness + (spacing/2)
2808                                        + half_shadowThickness;
2809                      else
2810                         rect[num_rects++].height = pixmapHeight + marginHeight+ 
2811                                        shadowThickness;
2812
2813                     /* 3 */
2814                      rect[num_rects].x = x + highlightThickness + 
2815                                          shadowThickness +
2816                                          pixmapWidth + (2 * marginWidth);
2817                      rect[num_rects].y = y + pixmapHeight + 2*marginHeight +
2818                                          shadowThickness + half_shadowThickness;
2819                      rect[num_rects].width = stringWidth - pixmapWidth +
2820                                            marginWidth - shadowThickness;
2821                      rect[num_rects++].height = half_shadowThickness;
2822
2823                     /* 4 */
2824                      rect[num_rects].x = x + stringWidth + (2 * marginWidth) +
2825                                          shadowThickness + half_shadowThickness
2826                                          + highlightThickness;
2827                      rect[num_rects].y = y + pixmapHeight + 2*marginHeight +
2828                                                           shadowThickness;
2829                      rect[num_rects].width = half_shadowThickness;
2830                      if(highlightThickness == 0)
2831                         rect[num_rects++].height = stringHeight + 
2832                                        (2*marginHeight) + half_shadowThickness;
2833                      else
2834                         rect[num_rects++].height = stringHeight + 
2835                                          (2*marginHeight) + shadowThickness 
2836                                          + half_shadowThickness;
2837                               
2838                   }
2839                   else
2840                   {
2841                     /* 2 */
2842                      rect[num_rects].x = x + highlightThickness + pixmapWidth +
2843                                          shadowThickness + (2 * marginWidth) +
2844                                          half_shadowThickness;
2845                      rect[num_rects].y = y + highlightThickness;
2846                      rect[num_rects].width = half_shadowThickness;
2847                      rect[num_rects++].height = pixmapHeight + marginHeight + 
2848                                        shadowThickness + (spacing/2) 
2849                                        + half_shadowThickness;
2850                     /* 3 */
2851                      rect[num_rects].x = x + highlightThickness + stringWidth +
2852                                  (2 * marginWidth) + shadowThickness +
2853                                   half_shadowThickness;
2854                      rect[num_rects].y = y + pixmapHeight + 2*marginHeight +
2855                                        2*shadowThickness;
2856                      rect[num_rects].width = pixmapWidth - stringWidth + 
2857                                            marginHeight - half_shadowThickness;
2858                      rect[num_rects++].height = half_shadowThickness;
2859
2860                     /* 4 */
2861                      rect[num_rects].x = x + highlightThickness + stringWidth +
2862                                       (2 * marginWidth) + shadowThickness +
2863                                       half_shadowThickness;
2864                      rect[num_rects].y = y + pixmapHeight + 2*marginHeight +
2865                                                          2*shadowThickness;
2866                      rect[num_rects].width = half_shadowThickness;
2867                      rect[num_rects++].height = stringHeight + 
2868                                        (2*marginHeight) + half_shadowThickness;
2869                   }
2870
2871                 /* 5 */
2872                   rect[num_rects].x = x + highlightThickness;
2873                   rect[num_rects].y = y + highlightThickness + pixmapHeight +
2874                                   stringHeight + spacing + (2*marginHeight) +
2875                                   shadowThickness + half_shadowThickness;
2876                   if(stringWidth >  pixmapWidth)
2877                      rect[num_rects].width = stringWidth + (2 * marginWidth) +
2878                                         half_shadowThickness + shadowThickness;
2879                   else
2880                      rect[num_rects].width = stringWidth + (2 * marginWidth) +
2881                                                            (2*shadowThickness);
2882                   rect[num_rects++].height = half_shadowThickness;
2883
2884                  /* 6 */
2885                   rect[num_rects].x = x + highlightThickness +
2886                                                           half_shadowThickness;
2887                   rect[num_rects].y = y + highlightThickness +
2888                                                           half_shadowThickness;
2889                   rect[num_rects].width = half_shadowThickness;
2890                   rect[num_rects++].height = pixmapHeight + stringHeight +
2891                            spacing + (2 * marginHeight) + half_shadowThickness;
2892    
2893                   XFillRectangles (XtDisplay (w), XtWindow (w), bottom_gc,
2894                                                           &rect[0], num_rects);
2895                }
2896                else
2897                {
2898                   num_rects = 0;
2899                  /* 1 */
2900                   rect[num_rects].x = x + highlightThickness;
2901                   rect[num_rects].y = y + highlightThickness;
2902                   rect[num_rects].width = pixmapWidth + (2 * shadowThickness) +
2903                                        (2 * marginWidth) + half_shadowThickness;
2904                   rect[num_rects++].height = half_shadowThickness;
2905
2906                  /* 2 */
2907                   rect[num_rects].x = x + highlightThickness +
2908                                                           half_shadowThickness;
2909                   rect[num_rects].y = y + highlightThickness +
2910                                                           half_shadowThickness;
2911                   rect[num_rects].width = pixmapWidth + (2 * marginWidth) +
2912                                                           shadowThickness;
2913                   rect[num_rects++].height = half_shadowThickness;
2914
2915                   if(stringWidth >  pixmapWidth)
2916                   {
2917                      /* 3 */
2918                      rect[num_rects].x = x + highlightThickness + 
2919                                          shadowThickness +
2920                                          pixmapWidth + (2 * marginWidth);
2921                      rect[num_rects].y = y + highlightThickness +
2922                                          pixmapHeight + marginHeight + 
2923                                          half_shadowThickness;
2924                      rect[num_rects].width = stringWidth - pixmapWidth +
2925                                          marginWidth + half_shadowThickness;
2926                      rect[num_rects++].height = half_shadowThickness;
2927
2928                     /* 4 */
2929                      rect[num_rects].x = x + highlightThickness + 
2930                                          shadowThickness +
2931                                          pixmapWidth + (2 * marginWidth);
2932                      rect[num_rects].y = y + highlightThickness +
2933                                          pixmapHeight + marginHeight
2934                                          + shadowThickness;
2935                      rect[num_rects].width = stringWidth - pixmapWidth +
2936                                                              marginWidth;
2937                      rect[num_rects++].height = half_shadowThickness;
2938                   }
2939
2940                  /* 5 */
2941                   rect[num_rects].x = x + highlightThickness;
2942                   rect[num_rects].y = y + highlightThickness;
2943                   rect[num_rects].width = half_shadowThickness;
2944                   rect[num_rects++].height = pixmapHeight + stringHeight +
2945                           spacing + (2 * marginHeight) + shadowThickness +
2946                           half_shadowThickness;
2947    
2948                  /* 6 */
2949                   rect[num_rects].x = x + highlightThickness +
2950                                                           half_shadowThickness;
2951                   rect[num_rects].y = y + highlightThickness +
2952                                                           half_shadowThickness;
2953                   rect[num_rects].width = half_shadowThickness;
2954                   rect[num_rects++].height = pixmapHeight + stringHeight +
2955                            spacing + (2 * marginHeight) + half_shadowThickness;
2956    
2957                   XFillRectangles (XtDisplay (w), XtWindow (w), top_gc,
2958                                                         &rect[0], num_rects);
2959
2960                   num_rects = 0;
2961                  /* 1 */
2962                   rect[num_rects].x = x + highlightThickness + pixmapWidth +
2963                                         (2 * marginWidth) + shadowThickness;
2964                   rect[num_rects].y = y + highlightThickness +
2965                                                    half_shadowThickness;
2966                   rect[num_rects].width = half_shadowThickness;
2967                   if(stringWidth >  pixmapWidth)
2968                   {
2969                      if(highlightThickness == 0)
2970                         rect[num_rects++].height = pixmapHeight + marginHeight
2971                                         + spacing/2;
2972                      else
2973                         rect[num_rects++].height = pixmapHeight + marginHeight
2974                                                                    + spacing/2;
2975                   }
2976                   else
2977                   {
2978                      if(highlightThickness == 0)
2979                         rect[num_rects++].height = pixmapHeight + marginHeight
2980                           + spacing/2 + half_shadowThickness + shadowThickness;
2981                      else
2982                         rect[num_rects++].height = pixmapHeight + marginHeight
2983                                             + spacing/2 + half_shadowThickness;
2984                   }
2985
2986                  /* 2 */
2987                   rect[num_rects].x = x + highlightThickness + pixmapWidth +
2988                     shadowThickness + (2 * marginWidth) + half_shadowThickness;
2989                   rect[num_rects].y = y + highlightThickness;
2990                   rect[num_rects].width = half_shadowThickness;
2991                   if(stringWidth >  pixmapWidth)
2992                   {
2993                      if(highlightThickness == 0)
2994                         rect[num_rects++].height = pixmapHeight + marginHeight +
2995                                                  (spacing/2);
2996                      else
2997                         rect[num_rects++].height = pixmapHeight + marginHeight +
2998                                                          half_shadowThickness;
2999                   }
3000                   else
3001                   {
3002                      if(highlightThickness == 0)
3003                         rect[num_rects++].height = pixmapHeight + marginHeight +
3004                                                  shadowThickness + (spacing/2) 
3005                                                  + half_shadowThickness;
3006                      else
3007                         rect[num_rects++].height = pixmapHeight + marginHeight +
3008                                         shadowThickness + shadowThickness;
3009                   }
3010
3011                  /* 3 */
3012                   if(stringWidth >  pixmapWidth)
3013                   {
3014                      rect[num_rects].x = x + stringWidth + (2 * marginWidth)
3015                                     + shadowThickness + highlightThickness;
3016                   }
3017                   else
3018                   {
3019                      rect[num_rects].x = x + highlightThickness + pixmapWidth +
3020                                         (2 * marginWidth) + shadowThickness;
3021                   }
3022                   rect[num_rects].y = y + highlightThickness +
3023                                       pixmapHeight + 2*marginHeight +
3024                                       half_shadowThickness;
3025                   rect[num_rects].width = half_shadowThickness;
3026                   rect[num_rects++].height = stringHeight + highlightThickness +
3027                                          (2*marginHeight) + 2*shadowThickness;
3028
3029                  /* 4 */
3030                   if(stringWidth >  pixmapWidth)
3031                   {
3032                      rect[num_rects].x = x + stringWidth + (2 * marginWidth) +
3033                     shadowThickness + half_shadowThickness + highlightThickness;
3034                   }
3035                   else
3036                   {
3037                      rect[num_rects].x = x + highlightThickness + pixmapWidth +
3038                     shadowThickness + (2 * marginWidth) + half_shadowThickness;
3039                   }
3040                   rect[num_rects].y = y + highlightThickness +
3041                                       pixmapHeight + 2*marginHeight;
3042                   rect[num_rects].width = half_shadowThickness;
3043                   rect[num_rects++].height = stringHeight +
3044                                          highlightThickness + 
3045                                          (2*marginHeight) + shadowThickness +
3046                                          half_shadowThickness;
3047
3048                  /* 5 */
3049                   rect[num_rects].x = x + highlightThickness +
3050                                                    half_shadowThickness;
3051                   rect[num_rects].y = y + highlightThickness + pixmapHeight +
3052                     stringHeight + spacing + (2*marginHeight) + shadowThickness;
3053                   if(stringWidth >  pixmapWidth)
3054                      rect[num_rects].width = stringWidth + (2 * marginWidth) +
3055                                          shadowThickness;
3056                   else
3057                      rect[num_rects].width = pixmapWidth + (2 * marginWidth) +
3058                                          shadowThickness;
3059                   rect[num_rects++].height = half_shadowThickness;
3060
3061                   rect[num_rects].x = x + highlightThickness;
3062                   rect[num_rects].y = y + highlightThickness + pixmapHeight +
3063                                   stringHeight + spacing + (2*marginHeight) +
3064                                   shadowThickness + half_shadowThickness;
3065                   if(stringWidth >  pixmapWidth)
3066                      rect[num_rects].width = stringWidth + (2 * marginWidth) +
3067                                         half_shadowThickness + shadowThickness;
3068                   else
3069                      rect[num_rects].width = pixmapWidth + (2 * marginWidth) +
3070                                                            (2*shadowThickness);
3071                   rect[num_rects++].height = half_shadowThickness;
3072
3073                   XFillRectangles (XtDisplay (w), XtWindow (w), bottom_gc,
3074                                                           &rect[0], num_rects);
3075
3076                }
3077             }
3078             else if (alignment == XmALIGNMENT_CENTER && type == DESKTOP)
3079             {
3080                if(stringWidth >  pixmapWidth)
3081                {
3082                   num_rects = 0;
3083
3084                  /* 1 */
3085                   rect[num_rects].x = x + (Dimension)(stringWidth - pixmapWidth)/(Dimension)2 +
3086                                                            highlightThickness;
3087                   rect[num_rects].y = y + highlightThickness;
3088                   rect[num_rects].width = pixmapWidth + (2 * shadowThickness) +
3089                                        (2 * marginWidth) + half_shadowThickness;
3090                   rect[num_rects++].height = half_shadowThickness;
3091
3092                  /* 2 */
3093                   rect[num_rects].x = x + highlightThickness + 
3094                             (Dimension)(stringWidth -pixmapWidth)/(Dimension)2 + half_shadowThickness;
3095                   rect[num_rects].y = y + highlightThickness +
3096                                                           half_shadowThickness;
3097                   rect[num_rects].width = pixmapWidth + (2 * marginWidth) +
3098                                                           shadowThickness;
3099                   rect[num_rects++].height = half_shadowThickness;
3100
3101                  /* 3 */
3102                   rect[num_rects].x = x + (Dimension)(stringWidth - pixmapWidth)/(Dimension)2 +
3103                                       highlightThickness + shadowThickness +
3104                                       pixmapWidth + (2 * marginWidth);
3105                   rect[num_rects].y = y + highlightThickness +
3106                                          pixmapHeight + marginHeight +
3107                                          half_shadowThickness;
3108                   rect[num_rects].width = (Dimension)(stringWidth - pixmapWidth)/(Dimension)2 +
3109                                           (Dimension)(stringWidth - pixmapWidth)%(Dimension)2 +
3110                                           marginWidth + half_shadowThickness;
3111                   rect[num_rects++].height = half_shadowThickness;
3112
3113                  /* 4 */
3114                   rect[num_rects].x = x +  (Dimension)(stringWidth - pixmapWidth)/(Dimension)2 + 
3115                                       highlightThickness + shadowThickness +
3116                                       pixmapWidth + (2 * marginWidth);
3117                   rect[num_rects].y = y + highlightThickness +
3118                                          pixmapHeight + marginHeight
3119                                          + shadowThickness;
3120                   rect[num_rects].width = (Dimension)(stringWidth - pixmapWidth)/(Dimension)2 +
3121                                           (Dimension)(stringWidth - pixmapWidth)%(Dimension)2 +
3122                                           marginWidth;
3123                   rect[num_rects++].height = half_shadowThickness;
3124
3125                  /* 5 */
3126                   rect[num_rects].x = x + highlightThickness;
3127                   rect[num_rects].y = y + highlightThickness +
3128                                       pixmapHeight + 2*marginHeight +
3129                                       half_shadowThickness;
3130                   rect[num_rects].width = half_shadowThickness;
3131                   rect[num_rects++].height = stringHeight + highlightThickness +
3132                                          (2*marginHeight) + 2*shadowThickness;
3133
3134                  /* 6 */ rect[num_rects].x = x + highlightThickness + 
3135                                                   half_shadowThickness; 
3136                   rect[num_rects].y = y + highlightThickness + pixmapHeight +
3137                                                                2*marginHeight;
3138                   rect[num_rects].width = half_shadowThickness;
3139                   rect[num_rects++].height = stringHeight +
3140                                          highlightThickness +
3141                                          (2*marginHeight) + shadowThickness +
3142                                          half_shadowThickness;
3143
3144                  /* 7 */
3145                   rect[num_rects].x = x + highlightThickness;
3146                   rect[num_rects].y = y + highlightThickness +
3147                                       pixmapHeight + marginHeight +
3148                                       half_shadowThickness;
3149                   rect[num_rects].width = (Dimension)(stringWidth - pixmapWidth)/(Dimension)2 + 
3150                                                        half_shadowThickness;
3151                   rect[num_rects++].height = half_shadowThickness;
3152
3153                  /* 8 */
3154                   rect[num_rects].x = x + highlightThickness;
3155                   rect[num_rects].y = y + highlightThickness +
3156                                       pixmapHeight + marginHeight +
3157                                       shadowThickness;
3158                   rect[num_rects].width = (Dimension)(stringWidth - pixmapWidth)/(Dimension)2 + 
3159                                                        shadowThickness;
3160
3161                   rect[num_rects++].height = half_shadowThickness;
3162
3163                  /* 9 */
3164                   rect[num_rects].x = x + (Dimension)(stringWidth - pixmapWidth)/(Dimension)2 +
3165                                                            highlightThickness;
3166                   rect[num_rects].y = y + highlightThickness;
3167                   rect[num_rects].width = half_shadowThickness;
3168                   if(highlightThickness == 0)
3169                      rect[num_rects++].height = pixmapHeight + marginHeight
3170                                         + spacing/2;
3171                   else
3172                      rect[num_rects++].height = pixmapHeight + marginHeight
3173                                                                    + spacing/2;
3174
3175                  /* 10 */
3176                   rect[num_rects].x = x + highlightThickness +
3177                             (Dimension)(stringWidth -pixmapWidth)/(Dimension)2 + half_shadowThickness;
3178                   rect[num_rects].y = y + highlightThickness +
3179                                                           half_shadowThickness;
3180                   rect[num_rects].width = half_shadowThickness;
3181                   if(highlightThickness == 0)
3182                      rect[num_rects++].height = pixmapHeight + marginHeight +
3183                                                  (spacing/2);
3184                   else
3185                      rect[num_rects++].height = pixmapHeight + marginHeight +
3186                                                          half_shadowThickness;
3187
3188                   XFillRectangles (XtDisplay (w), XtWindow (w), top_gc,
3189                                                         &rect[0], num_rects);
3190
3191                   num_rects = 0;
3192                  /* 1 */
3193                   rect[num_rects].x = x + highlightThickness + pixmapWidth +
3194                                         (Dimension)(stringWidth - pixmapWidth)/(Dimension)2 + 
3195                                         (2 * marginWidth) + shadowThickness;
3196                   rect[num_rects].y = y + highlightThickness 
3197                                                  + half_shadowThickness;
3198                   rect[num_rects].width = half_shadowThickness;
3199                   if(highlightThickness == 0)
3200                      rect[num_rects++].height = pixmapHeight + marginHeight
3201                                         + spacing/2;
3202                   else
3203                      rect[num_rects++].height = pixmapHeight + marginHeight
3204                                                                    + spacing/2;
3205
3206                  /* 2 */
3207                   rect[num_rects].x = x + highlightThickness + pixmapWidth +
3208                     shadowThickness + (2 * marginWidth) + half_shadowThickness +
3209                     (Dimension)(stringWidth - pixmapWidth)/(Dimension)2;
3210                   rect[num_rects].y = y + highlightThickness;
3211                   rect[num_rects].width = half_shadowThickness;
3212                   if(highlightThickness == 0)
3213                      rect[num_rects++].height = pixmapHeight + marginHeight +
3214                                                  (spacing/2);
3215                   else
3216                      rect[num_rects++].height = pixmapHeight + marginHeight +
3217                                                          half_shadowThickness;
3218
3219                  /* 3 */
3220                   rect[num_rects].x = x + stringWidth + (2 * marginWidth)
3221                                     + shadowThickness + highlightThickness;
3222                   rect[num_rects].y = y + highlightThickness +
3223                                       pixmapHeight + 2*marginHeight +
3224                                       half_shadowThickness;
3225                   rect[num_rects].width = half_shadowThickness;
3226                   rect[num_rects++].height = stringHeight + highlightThickness +
3227                                          (2*marginHeight) + 2*shadowThickness;
3228
3229                  /* 4 */
3230                   rect[num_rects].x = x + stringWidth + (2 * marginWidth) +
3231                     shadowThickness + half_shadowThickness + highlightThickness;
3232                   rect[num_rects].y = y + highlightThickness +
3233                                       pixmapHeight + 2*marginHeight;
3234                   rect[num_rects].width = half_shadowThickness;
3235                   rect[num_rects++].height = stringHeight +
3236                                          highlightThickness +
3237                                          (2*marginHeight) + shadowThickness +
3238                                          half_shadowThickness;
3239
3240                  /* 5 */
3241                   rect[num_rects].x = x + highlightThickness +
3242                                                    half_shadowThickness;
3243                   rect[num_rects].y = y + highlightThickness + pixmapHeight +
3244                     stringHeight + spacing + (2*marginHeight) + shadowThickness;
3245                   rect[num_rects].width = stringWidth + (2 * marginWidth) +
3246                                          shadowThickness;
3247                   rect[num_rects++].height = half_shadowThickness;
3248
3249                   rect[num_rects].x = x + highlightThickness;
3250                   rect[num_rects].y = y + highlightThickness + pixmapHeight +
3251                                   stringHeight + spacing + (2*marginHeight) +
3252                                   shadowThickness + half_shadowThickness;
3253                   rect[num_rects].width = stringWidth + (2 * marginWidth) +
3254                                         half_shadowThickness + shadowThickness;
3255                   rect[num_rects++].height = half_shadowThickness;
3256
3257                   XFillRectangles (XtDisplay (w), XtWindow (w), bottom_gc,
3258                                                           &rect[0], num_rects);
3259
3260               }
3261               else
3262               {
3263                   num_rects = 0;
3264                  /* 1 */
3265                   rect[num_rects].x = x + highlightThickness;
3266                   rect[num_rects].y = y + highlightThickness;
3267                   rect[num_rects].width = pixmapWidth + (2 * shadowThickness) +
3268                                        (2 * marginWidth) + half_shadowThickness;
3269                   rect[num_rects++].height = half_shadowThickness;
3270
3271                  /* 2 */
3272                   rect[num_rects].x = x + highlightThickness + 
3273                                                           half_shadowThickness;
3274                   rect[num_rects].y = y + highlightThickness +
3275                                                           half_shadowThickness;
3276                   rect[num_rects].width = pixmapWidth + (2 * marginWidth) +
3277                                                           shadowThickness;
3278                   rect[num_rects++].height = half_shadowThickness;
3279
3280                  /* 3 */
3281                   rect[num_rects].x = x + highlightThickness;
3282                   rect[num_rects].y = y + highlightThickness;
3283                   rect[num_rects].width = half_shadowThickness;
3284                   rect[num_rects++].height = 2 * highlightThickness + 
3285                             pixmapHeight + stringHeight + 2 * marginWidth +
3286                             spacing;
3287
3288                  /* 4 */
3289                   rect[num_rects].x = x + highlightThickness +
3290                                                           half_shadowThickness;
3291                   rect[num_rects].y = y + highlightThickness +
3292                                                           half_shadowThickness;
3293                   rect[num_rects].width = half_shadowThickness;
3294                   rect[num_rects++].height = 2 * highlightThickness + 
3295                                             pixmapHeight + stringHeight + 
3296                                             2 * marginWidth + spacing -   
3297                                             half_shadowThickness; 
3298
3299                   XFillRectangles (XtDisplay (w), XtWindow (w), top_gc,
3300                                                         &rect[0], num_rects);
3301
3302                   num_rects = 0;
3303                  /* 1 */
3304                   rect[num_rects].x = x + highlightThickness + pixmapWidth +
3305                                         (2 * marginWidth) + shadowThickness;
3306                   rect[num_rects].y = y + highlightThickness
3307                                                  + half_shadowThickness;
3308                   rect[num_rects].width = half_shadowThickness;
3309                   rect[num_rects++].height = 2 * highlightThickness + 
3310                             pixmapHeight + stringHeight + 2 * marginWidth +
3311                             spacing - half_shadowThickness;
3312
3313                  /* 2 */
3314                   rect[num_rects].x = x + highlightThickness + pixmapWidth +
3315                     shadowThickness + (2 * marginWidth) + half_shadowThickness;
3316                     
3317                   rect[num_rects].y = y + highlightThickness;
3318                   rect[num_rects].width = half_shadowThickness;
3319                   rect[num_rects++].height = 2 * highlightThickness + 
3320                                             pixmapHeight + stringHeight + 
3321                                             2 * marginWidth + spacing; 
3322
3323                  /* 3 */
3324                   rect[num_rects].x = x + highlightThickness +
3325                                                           half_shadowThickness;
3326                   rect[num_rects].y = y + 2 * highlightThickness + 
3327                           pixmapHeight + stringHeight + spacing + 
3328                           2 * marginHeight; 
3329                   rect[num_rects].width = pixmapWidth + (2 * shadowThickness) +
3330                                        (2 * marginWidth) + half_shadowThickness;
3331                   rect[num_rects++].height = half_shadowThickness;
3332
3333                  /* 4 */
3334                   rect[num_rects].x = x + highlightThickness;
3335                   rect[num_rects].y = y + 2 * highlightThickness + 
3336                           pixmapHeight + stringHeight + spacing + 
3337                           2 * marginHeight + half_shadowThickness;
3338                   rect[num_rects].width = pixmapWidth + (2 * marginWidth) +
3339                                                           shadowThickness;
3340                   rect[num_rects++].height = half_shadowThickness;
3341                   XFillRectangles (XtDisplay (w), XtWindow (w), bottom_gc,
3342                                                           &rect[0], num_rects);
3343               }
3344             }
3345             else
3346                XmeDrawShadows (XtDisplay(w), XtWindow(w), top_gc, bottom_gc,
3347                                x + highlightThickness, 
3348                                y + highlightThickness, 
3349                                width - 2*highlightThickness,
3350                                height - 2*highlightThickness,
3351                                shadowThickness, XmSHADOW_IN);
3352             break;
3353          case XmPIXMAP_LEFT:
3354             if(type == NOT_DESKTOP)
3355             {
3356                if((Dimension)(stringHeight+5) >= (Dimension)pixmapHeight)    
3357                {
3358                   num_rects = 0;
3359                  /* 1 */
3360                   rect[num_rects].x = x + highlightThickness;
3361                   rect[num_rects].y = y + highlightThickness;
3362                   rect[num_rects].width = pixmapWidth + stringWidth + spacing + 
3363                                        shadowThickness + 2*marginWidth;
3364                   rect[num_rects++].height = half_shadowThickness;
3365
3366                  /* 2 */
3367                   rect[num_rects].x = x + pixmapWidth + stringWidth + spacing + 
3368                                        shadowThickness + 2*marginWidth + 
3369                                        highlightThickness;
3370                   rect[num_rects].y = y + highlightThickness;
3371                   rect[num_rects].width = half_shadowThickness;
3372                   rect[num_rects++].height = stringHeight + 2*marginHeight +
3373                                         shadowThickness + half_shadowThickness;
3374
3375                  /* 3 */
3376                   rect[num_rects].x = x + highlightThickness;
3377                   rect[num_rects].y = y + highlightThickness + stringHeight +
3378                                    2*marginHeight + shadowThickness;
3379                   rect[num_rects].width = pixmapWidth + stringWidth + spacing + 
3380                                        shadowThickness + 2*marginWidth;
3381                   rect[num_rects++].height = half_shadowThickness;
3382
3383                  /* 4 */
3384                   rect[num_rects].x = x + highlightThickness;
3385                   rect[num_rects].y = y + highlightThickness;
3386                   rect[num_rects].width = half_shadowThickness;
3387                   rect[num_rects++].height = stringHeight + 2*marginHeight +
3388                                         shadowThickness + half_shadowThickness;
3389
3390                   XFillRectangles (XtDisplay (w), XtWindow (w), top_gc,
3391                                                         &rect[0], num_rects);
3392
3393                   num_rects = 0;
3394                  /* 1 */
3395                   rect[num_rects].x = x + highlightThickness +
3396                                                       half_shadowThickness;
3397                   rect[num_rects].y = y + highlightThickness +
3398                                                       half_shadowThickness;
3399                   rect[num_rects].width = pixmapWidth + stringWidth + spacing +
3400                                        half_shadowThickness + 2*marginWidth;
3401                   rect[num_rects++].height = half_shadowThickness;
3402
3403                  /* 2 */
3404                   rect[num_rects].x = x + highlightThickness + 
3405                                    half_shadowThickness + pixmapWidth + 
3406                                    stringWidth + spacing + shadowThickness + 
3407                                    2*marginWidth;
3408                   rect[num_rects].y = y + highlightThickness;
3409                   rect[num_rects].width = half_shadowThickness;
3410                   rect[num_rects++].height = stringHeight + 2*marginHeight + 
3411                                                         2*shadowThickness;
3412
3413                  /* 3 */
3414                   rect[num_rects].x = x + highlightThickness;
3415                
3416                   rect[num_rects].y = y + highlightThickness + stringHeight +
3417                                   2*marginHeight + shadowThickness +
3418                                   half_shadowThickness;
3419                   rect[num_rects].width = pixmapWidth + stringWidth + spacing +
3420                                        2*shadowThickness + 2*marginWidth;
3421                   rect[num_rects++].height = half_shadowThickness;
3422
3423                  /* 4 */
3424                   rect[num_rects].x = x + highlightThickness +
3425                                                       half_shadowThickness;
3426                   rect[num_rects].y = y + highlightThickness +
3427                                                       half_shadowThickness;
3428                   rect[num_rects].width = half_shadowThickness;
3429                   rect[num_rects++].height = stringHeight + 2*marginHeight + 
3430                                                         half_shadowThickness;
3431
3432                   XFillRectangles (XtDisplay (w), XtWindow (w), bottom_gc,
3433                                                        &rect[0], num_rects);
3434
3435                }
3436                else
3437                {
3438                   num_rects = 0;
3439                  /* 1 */
3440                   rect[num_rects].x = x + highlightThickness;
3441                   rect[num_rects].y = y + highlightThickness;
3442                   rect[num_rects].width = pixmapWidth + (2 * shadowThickness) +
3443                                        (2 * marginWidth) - half_shadowThickness;
3444                   rect[num_rects++].height = half_shadowThickness;
3445
3446                  /* 2 */
3447                   rect[num_rects].x = x + highlightThickness + pixmapWidth + 
3448                                       2*shadowThickness + 2*marginWidth -
3449                                       shadowThickness;
3450                   rect[num_rects].y = y + highlightThickness;
3451                   rect[num_rects].width = half_shadowThickness;
3452                   rect[num_rects++].height = ((Dimension)(pixmapHeight - stringHeight)/(Dimension)2) +
3453                                           marginHeight - half_shadowThickness;
3454                                        
3455                  /* 3 */
3456                   rect[num_rects].x = x + highlightThickness + pixmapWidth + 
3457                                    2*shadowThickness + 2*marginWidth -
3458                                    shadowThickness;
3459                   rect[num_rects].y = y + highlightThickness + 
3460                                    ((Dimension)(pixmapHeight - stringHeight)/(Dimension)2) +
3461                                    marginHeight -shadowThickness;
3462                   rect[num_rects].width = stringWidth + marginWidth + 
3463                                                            shadowThickness;
3464                   rect[num_rects++].height = half_shadowThickness;
3465
3466                  /* 4 */
3467                   rect[num_rects].x = x + highlightThickness + pixmapWidth + 
3468                                    2*shadowThickness + 3*marginWidth 
3469                                    + stringWidth - half_shadowThickness;
3470                   rect[num_rects].y = y + highlightThickness +
3471                                      ((Dimension)(pixmapHeight - stringHeight)/(Dimension)2) +
3472                                             half_shadowThickness;
3473                   rect[num_rects].width = half_shadowThickness;
3474                   rect[num_rects++].height = stringHeight + 2*marginHeight +
3475                                                           half_shadowThickness;
3476
3477                  /* 5 */
3478                   rect[num_rects].x = x + highlightThickness + pixmapWidth + 
3479                                    2*shadowThickness + 2*marginWidth -
3480                                    shadowThickness;
3481                   rect[num_rects].y = y + highlightThickness +
3482                                    ((Dimension)(pixmapHeight - stringHeight)/(Dimension)2) +
3483                                    stringHeight + 2*marginHeight +
3484                                    shadowThickness;
3485                   rect[num_rects].width = stringWidth + marginWidth + 
3486                                    shadowThickness;
3487                   rect[num_rects++].height = half_shadowThickness;
3488
3489                  /* 6 */
3490                   rect[num_rects].x = x + highlightThickness + pixmapWidth + 
3491                                    2*shadowThickness + 2*marginWidth -
3492                                    shadowThickness;
3493                   rect[num_rects].y = y + highlightThickness +
3494                                    ((Dimension)(pixmapHeight - stringHeight)/(Dimension)2) +
3495                                    stringHeight + 2*marginHeight +
3496                                    shadowThickness;
3497                   rect[num_rects].width = half_shadowThickness;
3498                   rect[num_rects++].height = ((Dimension)(pixmapHeight - stringHeight)/(Dimension)2) +
3499                                           marginHeight;
3500
3501                  /* 7 */
3502                   rect[num_rects].x = x + highlightThickness;
3503                   rect[num_rects].y = y + highlightThickness +
3504                                pixmapHeight + 2*marginHeight + shadowThickness;
3505                   rect[num_rects].width = pixmapWidth + (2 * shadowThickness) +
3506                                        (2 * marginWidth) - half_shadowThickness;
3507                   rect[num_rects++].height = half_shadowThickness;
3508
3509                  /* 8 */
3510                   rect[num_rects].x = x + highlightThickness;
3511                   rect[num_rects].y = y + highlightThickness;
3512                   rect[num_rects].width = half_shadowThickness;
3513                   rect[num_rects++].height = pixmapHeight + 2*marginHeight +
3514                                                               shadowThickness;
3515    
3516                   XFillRectangles (XtDisplay (w), XtWindow (w), top_gc,
3517                                                         &rect[0], num_rects);
3518
3519                   num_rects = 0;
3520                  /* 1 */
3521                   rect[num_rects].x = x + highlightThickness + 
3522                                                       half_shadowThickness;
3523                   rect[num_rects].y = y + highlightThickness +
3524                                                          half_shadowThickness;
3525                   rect[num_rects].width = pixmapWidth + (2 * marginWidth) +
3526                                                           half_shadowThickness;
3527                   rect[num_rects++].height = half_shadowThickness;
3528
3529                  /* 2 */
3530                   rect[num_rects].x = x + highlightThickness + pixmapWidth + 
3531                                    2*marginWidth + shadowThickness + 
3532                                    half_shadowThickness;
3533                   rect[num_rects].y = y + highlightThickness;
3534                   rect[num_rects].width = half_shadowThickness;
3535                   rect[num_rects++].height = ((Dimension)(pixmapHeight - stringHeight)/(Dimension)2) +
3536                                           marginHeight - shadowThickness;
3537
3538                  /* 3 */
3539                   rect[num_rects].x = x + highlightThickness + pixmapWidth + 
3540                                    2*marginWidth + shadowThickness;
3541                   rect[num_rects].y = y + highlightThickness +
3542                                   ((Dimension)(pixmapHeight - stringHeight)/(Dimension)2) +
3543                                    half_shadowThickness;
3544                   rect[num_rects].width = stringWidth + marginWidth +
3545                                                    half_shadowThickness;
3546                   rect[num_rects++].height = half_shadowThickness;
3547
3548                  /* 4 */
3549                   rect[num_rects].x = x + highlightThickness + pixmapWidth + 
3550                                    3*marginWidth + 2*shadowThickness +
3551                                    stringWidth;
3552                   rect[num_rects].y = y + highlightThickness +
3553                                    ((Dimension)(pixmapHeight - stringHeight)/(Dimension)2);
3554                                     
3555                   rect[num_rects].width = half_shadowThickness;
3556                   rect[num_rects++].height = stringHeight + 2*marginHeight +
3557                                                          2*shadowThickness;
3558                                                           
3559                  /* 5 */
3560                   rect[num_rects].x = x + highlightThickness + pixmapWidth + 
3561                                    2*marginWidth + shadowThickness +
3562                                    half_shadowThickness;
3563                   rect[num_rects].y = y + highlightThickness +
3564                                          ((Dimension)(pixmapHeight - stringHeight)/(Dimension)2) +
3565                                          2*marginHeight + shadowThickness +
3566                                          stringHeight + half_shadowThickness;
3567                   rect[num_rects].width = stringWidth + marginWidth +
3568                                                      shadowThickness;
3569                   rect[num_rects++].height = half_shadowThickness;
3570
3571                  /* 6 */
3572                   rect[num_rects].x = x + highlightThickness + pixmapWidth + 
3573                                    2*marginWidth + shadowThickness +
3574                                    half_shadowThickness;
3575                   rect[num_rects].y = y + highlightThickness + 
3576                                          ((Dimension)(pixmapHeight - stringHeight)/(Dimension)2) +
3577                                          2*marginHeight + shadowThickness +
3578                                          stringHeight + half_shadowThickness;
3579                   rect[num_rects].width = half_shadowThickness;
3580                   rect[num_rects++].height = ((Dimension)(pixmapHeight - stringHeight)/(Dimension)2) +
3581                                           marginHeight;
3582                  /* 7 */
3583                   rect[num_rects].x = x + highlightThickness;
3584                   rect[num_rects].y = y + highlightThickness + pixmapHeight + 
3585                                           2*marginHeight + shadowThickness +
3586                                           half_shadowThickness;
3587                   rect[num_rects].width = pixmapWidth + 2*marginWidth + 
3588                                                          2*shadowThickness;
3589                   rect[num_rects++].height = half_shadowThickness;
3590
3591                  /* 8 */
3592                   rect[num_rects].x = x + highlightThickness + 
3593                                                       half_shadowThickness;
3594                   rect[num_rects].y = y + highlightThickness +
3595                                                       half_shadowThickness;
3596                   rect[num_rects].width = half_shadowThickness;
3597                   rect[num_rects++].height = pixmapHeight + 2*marginHeight + 
3598                                              half_shadowThickness;
3599
3600                   XFillRectangles (XtDisplay (w), XtWindow (w), bottom_gc,
3601                                                        &rect[0], num_rects);
3602
3603                }
3604             }
3605             else
3606             {
3607                if((Dimension)(stringHeight+5) >= pixmapHeight)    
3608                {
3609                   num_rects = 0;
3610                  /* 1 */
3611                   rect[num_rects].x = x + highlightThickness;
3612                   rect[num_rects].y = y + highlightThickness;
3613                   rect[num_rects].width = pixmapWidth + stringWidth + spacing + 
3614                                        2*shadowThickness + 2*marginWidth;
3615                   rect[num_rects++].height = half_shadowThickness;
3616
3617                  /* 2 */
3618                   rect[num_rects].x = x + highlightThickness +
3619                                                       half_shadowThickness;
3620                   rect[num_rects].y = y + highlightThickness +
3621                                                       half_shadowThickness;
3622                   rect[num_rects].width = pixmapWidth + stringWidth + spacing +
3623                                        shadowThickness + 2*marginWidth;
3624                   rect[num_rects++].height = half_shadowThickness;
3625
3626                  /* 3 */
3627                   rect[num_rects].x = x + highlightThickness;
3628                   rect[num_rects].y = y + highlightThickness;
3629                   rect[num_rects].width = half_shadowThickness;
3630                   if(pixmapHeight > stringHeight)
3631                      rect[num_rects++].height = pixmapHeight + 2*marginHeight +
3632                                                               2*shadowThickness;
3633                   else
3634                      rect[num_rects++].height = stringHeight + 2*marginHeight +
3635                                                               2*shadowThickness;
3636
3637                  /* 4 */
3638                   rect[num_rects].x = x + highlightThickness +
3639                                                       half_shadowThickness;
3640                   rect[num_rects].y = y + highlightThickness +
3641                                                       half_shadowThickness;
3642                   rect[num_rects].width = half_shadowThickness;
3643                   if(pixmapHeight > stringHeight)
3644                      rect[num_rects++].height = pixmapHeight + 2*marginHeight + 
3645                                                      half_shadowThickness;
3646                   else
3647                      rect[num_rects++].height = stringHeight + 2*marginHeight + 
3648                                                      half_shadowThickness;
3649
3650                   XFillRectangles (XtDisplay (w), XtWindow (w), top_gc,
3651                                                        &rect[0], num_rects);
3652
3653                   num_rects = 0;
3654                  /* 1 */
3655                   rect[num_rects].x = x + pixmapWidth + stringWidth + spacing + 
3656                                        shadowThickness + 2*marginWidth + 
3657                                        highlightThickness;
3658                   rect[num_rects].y = y + highlightThickness +
3659                                                         shadowThickness;
3660                   rect[num_rects].width = half_shadowThickness;
3661                   if(pixmapHeight > stringHeight)
3662                      rect[num_rects++].height = pixmapHeight + 2*marginHeight +
3663                                         shadowThickness;
3664                   else
3665                      rect[num_rects++].height = stringHeight + 2*marginHeight +
3666                                         shadowThickness;
3667
3668                  /* 2 */
3669                   rect[num_rects].x = x + highlightThickness + 
3670                                    half_shadowThickness + pixmapWidth + 
3671                                    stringWidth + spacing + shadowThickness + 
3672                                    2*marginWidth;
3673                   rect[num_rects].y = y + highlightThickness + 
3674                                                    half_shadowThickness;
3675                   rect[num_rects].width = half_shadowThickness;
3676                   if(pixmapHeight > stringHeight)
3677                      rect[num_rects++].height = pixmapHeight + 2*marginHeight + 
3678                                                         shadowThickness;
3679                   else
3680                      rect[num_rects++].height = stringHeight + 2*marginHeight + 
3681                                                         shadowThickness;
3682
3683                  /* 3 */
3684                   rect[num_rects].x = x + highlightThickness + 
3685                                                      half_shadowThickness;
3686                   if(pixmapHeight > stringHeight)
3687                      rect[num_rects].y = y + highlightThickness + pixmapHeight +
3688                                    2*marginHeight + shadowThickness;
3689                   else
3690                      rect[num_rects].y = y + highlightThickness + stringHeight +
3691                                    2*marginHeight + shadowThickness;
3692                   rect[num_rects].width = pixmapWidth + stringWidth + spacing + 
3693                                        shadowThickness + 2*marginWidth -
3694                                        half_shadowThickness;
3695                   rect[num_rects++].height = half_shadowThickness;
3696
3697                 /* 4 */
3698                   rect[num_rects].x = x + highlightThickness;
3699
3700                   if(pixmapHeight > stringHeight)
3701                      rect[num_rects].y = y + highlightThickness + pixmapHeight +
3702                                   2*marginHeight + shadowThickness +
3703                                   half_shadowThickness;
3704                   else
3705                      rect[num_rects].y = y + highlightThickness + stringHeight +
3706                                   2*marginHeight + shadowThickness +
3707                                   half_shadowThickness;
3708                   rect[num_rects].width = pixmapWidth + stringWidth + spacing +
3709                                        2*shadowThickness + 2*marginWidth;
3710                   rect[num_rects++].height = half_shadowThickness;
3711
3712                   XFillRectangles (XtDisplay (w), XtWindow (w), bottom_gc,
3713                                                        &rect[0], num_rects);
3714                }
3715                else
3716                {
3717                   num_rects = 0;
3718                  /* 1 */
3719                   rect[num_rects].x = x + highlightThickness;
3720                   rect[num_rects].y = y + highlightThickness;
3721                   rect[num_rects].width = pixmapWidth + (2 * shadowThickness) +
3722                                        (2 * marginWidth) + half_shadowThickness;
3723                   rect[num_rects++].height = half_shadowThickness;
3724
3725                  /* 2 */
3726                   rect[num_rects].x = x + highlightThickness +
3727                                                       half_shadowThickness;
3728                   rect[num_rects].y = y + highlightThickness +
3729                                                          half_shadowThickness;
3730                   rect[num_rects].width = pixmapWidth + (2 * marginWidth) +
3731                                                           shadowThickness;
3732                   rect[num_rects++].height = half_shadowThickness;
3733
3734                  /* 3 */
3735                   rect[num_rects].x = x + highlightThickness + pixmapWidth + 
3736                                    2*shadowThickness + 2*marginWidth -
3737                                    shadowThickness;
3738                   rect[num_rects].y = y + highlightThickness + 
3739                                    ((Dimension)(pixmapHeight - stringHeight)/(Dimension)2) +
3740                                    marginHeight -shadowThickness;
3741                   rect[num_rects].width = stringWidth + marginWidth + 
3742                                                            shadowThickness;
3743                   rect[num_rects++].height = half_shadowThickness;
3744
3745                  /* 4 */
3746                   rect[num_rects].x = x + highlightThickness + pixmapWidth +
3747                                    2*marginWidth + shadowThickness;
3748                   rect[num_rects].y = y + highlightThickness +
3749                                   ((Dimension)(pixmapHeight - stringHeight)/(Dimension)2) +
3750                                    half_shadowThickness;
3751                   rect[num_rects].width = stringWidth + marginWidth +
3752                                                    half_shadowThickness;
3753                   rect[num_rects++].height = half_shadowThickness;
3754
3755                  /* 5 */
3756                   rect[num_rects].x = x + highlightThickness;
3757                   rect[num_rects].y = y + highlightThickness;
3758                   rect[num_rects].width = half_shadowThickness;
3759                   rect[num_rects++].height = pixmapHeight + 2*marginHeight +
3760                                                               2*shadowThickness;
3761
3762                  /* 6 */
3763                   rect[num_rects].x = x + highlightThickness + 
3764                                                       half_shadowThickness;
3765                   rect[num_rects].y = y + highlightThickness +
3766                                                       half_shadowThickness;
3767                   rect[num_rects].width = half_shadowThickness;
3768                   rect[num_rects++].height = pixmapHeight + 2*marginHeight + 
3769                                              shadowThickness;
3770
3771                   XFillRectangles (XtDisplay (w), XtWindow (w), top_gc,
3772                                                         &rect[0], num_rects);
3773
3774                   num_rects = 0;
3775                  /* 1 */
3776                   rect[num_rects].x = x + highlightThickness + pixmapWidth + 
3777                                       2*shadowThickness + 2*marginWidth -
3778                                       shadowThickness;
3779                   rect[num_rects].y = y + highlightThickness + shadowThickness;
3780                   rect[num_rects].width = half_shadowThickness;
3781                   rect[num_rects++].height = ((Dimension)(pixmapHeight - stringHeight)/(Dimension)2) +
3782                                           marginHeight - half_shadowThickness -
3783                                           shadowThickness;
3784
3785                  /* 2 */
3786                   rect[num_rects].x = x + highlightThickness + pixmapWidth + 
3787                                    2*marginWidth + shadowThickness + 
3788                                    half_shadowThickness;
3789                   rect[num_rects].y = y + highlightThickness +
3790                                                      half_shadowThickness;
3791                   rect[num_rects].width = half_shadowThickness;
3792                   rect[num_rects++].height = ((Dimension)(pixmapHeight - stringHeight)/(Dimension)2) +
3793                                           marginHeight - half_shadowThickness -
3794                                           shadowThickness;
3795
3796                  /* 3 */
3797                   rect[num_rects].x = x + highlightThickness + pixmapWidth +
3798                                    2*shadowThickness + 3*marginWidth
3799                                    + stringWidth - half_shadowThickness;
3800                   rect[num_rects].y = y + highlightThickness +
3801                                      ((Dimension)(pixmapHeight - stringHeight)/(Dimension)2) +
3802                                             half_shadowThickness;
3803                   rect[num_rects].width = half_shadowThickness;
3804                   rect[num_rects++].height = stringHeight + 2*marginHeight +
3805                                                           half_shadowThickness;
3806
3807                  /* 4 */
3808                   rect[num_rects].x = x + highlightThickness + pixmapWidth +
3809                                    3*marginWidth + 2*shadowThickness +
3810                                    stringWidth;
3811                   rect[num_rects].y = y + highlightThickness +
3812                                    ((Dimension)(pixmapHeight - stringHeight)/(Dimension)2);
3813
3814                   rect[num_rects].width = half_shadowThickness;
3815                   rect[num_rects++].height = stringHeight + 2*marginHeight +
3816                                                          2*shadowThickness;
3817
3818                  /* 5 */
3819                   rect[num_rects].x = x + highlightThickness + pixmapWidth +
3820                                    2*shadowThickness + 2*marginWidth -
3821                                    shadowThickness;
3822                   rect[num_rects].y = y + highlightThickness +
3823                                    ((Dimension)(pixmapHeight - stringHeight)/(Dimension)2) +
3824                                    stringHeight + 2*marginHeight +
3825                                    shadowThickness;
3826                   rect[num_rects].width = stringWidth + marginWidth +
3827                                    shadowThickness;
3828                   rect[num_rects++].height = half_shadowThickness;
3829
3830                 /* 6 */
3831                   rect[num_rects].x = x + highlightThickness + pixmapWidth +
3832                                    2*marginWidth + shadowThickness +
3833                                    half_shadowThickness;
3834                   rect[num_rects].y = y + highlightThickness +
3835                                          ((Dimension)(pixmapHeight - stringHeight)/(Dimension)2) +
3836                                          2*marginHeight + shadowThickness +
3837                                          stringHeight + half_shadowThickness;
3838                   rect[num_rects].width = stringWidth + marginWidth +
3839                                                      shadowThickness;
3840                   rect[num_rects++].height = half_shadowThickness;
3841
3842                  /* 7 */
3843                   rect[num_rects].x = x + highlightThickness + pixmapWidth +
3844                                    2*shadowThickness + 2*marginWidth -
3845                                    shadowThickness;
3846                   rect[num_rects].y = y + highlightThickness +
3847                                    ((Dimension)(pixmapHeight - stringHeight)/(Dimension)2) +
3848                                    stringHeight + 2*marginHeight +
3849                                    shadowThickness;
3850                   rect[num_rects].width = half_shadowThickness;
3851                   rect[num_rects++].height = ((Dimension)(pixmapHeight - stringHeight)/(Dimension)2) +
3852                                           marginHeight;
3853
3854                  /* 8 */
3855                   rect[num_rects].x = x + highlightThickness + pixmapWidth +
3856                                    2*marginWidth + shadowThickness +
3857                                    half_shadowThickness;
3858                   rect[num_rects].y = y + highlightThickness +
3859                                          ((Dimension)(pixmapHeight - stringHeight)/(Dimension)2) +
3860                                          2*marginHeight + shadowThickness +
3861                                          stringHeight + half_shadowThickness;
3862                   rect[num_rects].width = half_shadowThickness;
3863                   rect[num_rects++].height = ((Dimension)(pixmapHeight - stringHeight)/(Dimension)2) +
3864                                           marginHeight;
3865
3866                  /* 9 */
3867                   rect[num_rects].x = x + highlightThickness + shadowThickness;
3868                   rect[num_rects].y = y + highlightThickness +
3869                                pixmapHeight + 2*marginHeight + shadowThickness;
3870                   rect[num_rects].width = pixmapWidth + shadowThickness +
3871                                        (2 * marginWidth) - half_shadowThickness;
3872                   rect[num_rects++].height = half_shadowThickness;
3873
3874                  /* 10 */
3875                   rect[num_rects].x = x + highlightThickness + 
3876                                                           half_shadowThickness;
3877                   rect[num_rects].y = y + highlightThickness + pixmapHeight +
3878                                           2*marginHeight + shadowThickness +
3879                                           half_shadowThickness;
3880                   rect[num_rects].width = pixmapWidth + 2*marginWidth +
3881                                         shadowThickness + half_shadowThickness;
3882                   rect[num_rects++].height = half_shadowThickness;
3883
3884                   XFillRectangles (XtDisplay (w), XtWindow (w), bottom_gc,
3885                                                        &rect[0], num_rects);
3886                }
3887             }
3888             break;
3889          case XmPIXMAP_BOTTOM:
3890          case XmPIXMAP_RIGHT:
3891             XmeDrawShadows (XtDisplay(w), XtWindow(w), top_gc, bottom_gc,
3892                             x + highlightThickness, 
3893                             y + highlightThickness, 
3894                             width - 2*highlightThickness,
3895                             height - 2*highlightThickness,
3896                             shadowThickness, XmSHADOW_IN);
3897             break;
3898          default:
3899             break;
3900       }
3901    }
3902 }
3903
3904 static void
3905 FM_XmHighlightBorder(
3906         Widget w )
3907 {
3908     if(    XmIsPrimitive( w)    ) {
3909         (*(xmPrimitiveClassRec.primitive_class.border_highlight))( w) ;
3910     }  else  {
3911         if(    XmIsGadget( w)    ) {
3912             (*(xmGadgetClassRec.gadget_class.border_highlight))( w) ;
3913         }
3914     }
3915     return ;
3916 }
3917
3918 static void
3919 FM_XmUnhighlightBorder(
3920         Widget w )
3921 {
3922     if(    XmIsPrimitive( w)    )
3923     {  
3924         (*(xmPrimitiveClassRec.primitive_class.border_unhighlight))( w) ;
3925     }
3926     else
3927     {   if(    XmIsGadget( w)    )
3928         {
3929             (*(xmGadgetClassRec.gadget_class.border_unhighlight))( w) ;
3930         }
3931     }
3932     return ;
3933 }
3934
3935 static XmGadget 
3936 InputForGadget(
3937         Widget wid,
3938         int x,
3939         int y )
3940 {
3941     Widget widget;
3942
3943     widget = XmObjectAtPoint (wid, x, y);
3944
3945     if (!widget  ||  !XtIsSensitive (widget))
3946         return ((XmGadget) NULL);
3947
3948    return ((XmGadget) widget);
3949 }