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