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