source: trunk/third/mwm/WmIPlace.c @ 9757

Revision 9757, 19.8 KB checked in by ghudson, 28 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r9756, which included commits to RCS files with non-trunk default branches.
Line 
1/*
2 * (c) Copyright 1989, 1990, 1991, 1992 OPEN SOFTWARE FOUNDATION, INC.
3 * ALL RIGHTS RESERVED
4*/
5/*
6 * Motif Release 1.2.1
7*/
8#ifdef REV_INFO
9#ifndef lint
10static char rcsid[] = "$RCSfile: WmIPlace.c,v $ $Revision: 1.1.1.1 $ $Date: 1997-03-25 09:12:19 $"
11#endif
12#endif
13/*
14 * (c) Copyright 1987, 1988, 1989, 1990 HEWLETT-PACKARD COMPANY */
15
16/*
17 * Included Files:
18 */
19
20#include "WmGlobal.h"
21
22/*
23 * include extern functions
24 */
25
26#include "WmError.h"
27#include "WmIDecor.h"
28#include "WmIconBox.h"
29#include "WmWinConf.h"
30
31
32/*
33 * Function Declarations:
34 */
35
36#ifdef _NO_PROTO
37void    CvtIconPlaceToPosition ();
38int     CvtIconPositionToPlace ();
39int     FindIconPlace ();
40int     GetNextIconPlace ();
41void    InitIconPlacement ();
42void    MoveIconInfo ();
43void    PackRootIcons ();
44#else /* _NO_PROTO */
45void InitIconPlacement (WmWorkspaceData *pWS);
46int GetNextIconPlace (IconPlacementData *pIPD);
47void CvtIconPlaceToPosition (IconPlacementData *pIPD, int place, int *pX, int *pY);
48int FindIconPlace (ClientData *pCD, IconPlacementData *pIPD, int x, int y);
49int CvtIconPositionToPlace (IconPlacementData *pIPD, int x, int y);
50void PackRootIcons (void);
51void MoveIconInfo (IconPlacementData *pIPD, int p1, int p2);
52#endif /* _NO_PROTO */
53
54
55
56/*
57 * Global Variables:
58 */
59extern Dimension clipWidth;
60extern Dimension clipHeight;
61extern Position clipX;
62extern Position clipY;
63
64/*************************************<->*************************************
65 *
66 *  InitIconPlacement ()
67 *
68 *
69 *  Description:
70 *  -----------
71 *  This function intializes icon placement information.
72 *
73 *
74 *  Inputs:
75 *  ------
76 *  pWS = pointer to workspace data
77 *
78 *
79 *  Outputs:
80 *  -------
81 *  IconPlacmementData
82 *
83 *************************************<->***********************************/
84
85#ifdef _NO_PROTO
86void InitIconPlacement (pWS)
87
88    WmWorkspaceData *pWS;
89
90#else /* _NO_PROTO */
91void InitIconPlacement (WmWorkspaceData *pWS)
92#endif /* _NO_PROTO */
93{
94    Boolean useMargin;
95    int sW;
96    int sH;
97    int iSpaceX;
98    int iSpaceY;
99    int placementW;
100    int placementH;
101    int extraXSpace;
102    int extraYSpace;
103    int xMargin;
104    int yMargin;
105    int extraPX;
106    int extraPY;
107    int i;
108
109
110    xMargin = yMargin = extraPX = extraPY = 0;
111
112    sW = DisplayWidth (DISPLAY, pWS->pSD->screen);
113    sH = DisplayHeight (DISPLAY, pWS->pSD->screen);
114    useMargin = (pWS->pSD->iconPlacementMargin >= 0);
115    pWS->IPData.iconPlacement = pWS->pSD->iconPlacement;
116
117    if (useMargin)
118    {
119        pWS->IPData.placementCols =
120            (sW - (2 * pWS->pSD->iconPlacementMargin)) / pWS->pSD->iconWidth;
121        pWS->IPData.placementRows =
122            (sH - (2 * pWS->pSD->iconPlacementMargin)) / pWS->pSD->iconHeight;
123    }
124    else
125    {
126        pWS->IPData.placementCols = sW / pWS->pSD->iconWidth;
127        pWS->IPData.placementRows = sH / pWS->pSD->iconHeight;
128    }
129
130    if (pWS->IPData.iconPlacement & ICON_PLACE_TIGHT)
131    {
132        iSpaceX = 0;
133        iSpaceY = 0;
134        xMargin = 2;
135        yMargin = 2;
136    }
137    else
138    {
139        do
140        {
141            if (useMargin)
142            {
143                iSpaceX =
144                    (sW - (2 * pWS->pSD->iconPlacementMargin) -
145                          (pWS->IPData.placementCols * pWS->pSD->iconWidth)) /
146                              (pWS->IPData.placementCols - 1);
147            }
148            else
149            {
150                iSpaceX =
151                    (sW - (pWS->IPData.placementCols * pWS->pSD->iconWidth)) /
152                               pWS->IPData.placementCols;
153            }
154            if (iSpaceX < MINIMUM_ICON_SPACING)
155            {
156                pWS->IPData.placementCols--;
157            }
158        }
159        while (iSpaceX < MINIMUM_ICON_SPACING);
160
161        do
162        {
163            if (useMargin)
164            {
165                iSpaceY = (sH - (2 * pWS->pSD->iconPlacementMargin) -
166                       (pWS->IPData.placementRows * pWS->pSD->iconHeight)) /
167                                  (pWS->IPData.placementRows - 1);
168            }
169            else
170            {
171                iSpaceY =
172                    (sH - (pWS->IPData.placementRows * pWS->pSD->iconHeight)) /
173                                            pWS->IPData.placementRows;
174            }
175            if (iSpaceY < MINIMUM_ICON_SPACING)
176            {
177                pWS->IPData.placementRows--;
178            }
179        }
180        while (iSpaceY < MINIMUM_ICON_SPACING);
181    }
182
183    pWS->IPData.iPlaceW = pWS->pSD->iconWidth + iSpaceX;
184    pWS->IPData.iPlaceH = pWS->pSD->iconHeight + iSpaceY;
185
186    placementW = pWS->IPData.placementCols * pWS->IPData.iPlaceW;
187    placementH = pWS->IPData.placementRows * pWS->IPData.iPlaceH;
188
189    pWS->IPData.placeIconX =
190        ((pWS->IPData.iPlaceW - pWS->pSD->iconWidth) + 1) / 2;
191    pWS->IPData.placeIconY =
192        ((pWS->IPData.iPlaceH - pWS->pSD->iconHeight) + 1) / 2;
193
194    /*
195     * Special case margin handling for TIGHT icon placement
196     */
197    if (pWS->IPData.iconPlacement & ICON_PLACE_TIGHT)
198    {
199        if (useMargin)
200        {
201            xMargin = pWS->pSD->iconPlacementMargin;
202            yMargin = pWS->pSD->iconPlacementMargin;
203        }
204
205        extraXSpace = 0;
206        extraYSpace = 0;
207
208        if ((pWS->IPData.iconPlacement & ICON_PLACE_RIGHT_PRIMARY) ||
209           (pWS->IPData.iconPlacement & ICON_PLACE_RIGHT_SECONDARY))
210            xMargin = sW - placementW - xMargin;
211
212        if ((pWS->IPData.iconPlacement & ICON_PLACE_BOTTOM_PRIMARY) ||
213           (pWS->IPData.iconPlacement & ICON_PLACE_BOTTOM_SECONDARY))
214            yMargin = sH - placementH - yMargin;
215    }
216    else
217    {
218        if (useMargin)
219        {
220            xMargin = pWS->pSD->iconPlacementMargin - pWS->IPData.placeIconX;
221            extraXSpace = sW - (2 * pWS->pSD->iconPlacementMargin) -
222                          (placementW - iSpaceX);
223            extraPX = (pWS->IPData.iconPlacement & ICON_PLACE_RIGHT_PRIMARY) ?
224                                1 : (pWS->IPData.placementCols - extraXSpace);
225
226            yMargin = pWS->pSD->iconPlacementMargin - pWS->IPData.placeIconY;
227            extraYSpace = sH - (2 * pWS->pSD->iconPlacementMargin) -
228                          (placementH - iSpaceY);
229            extraPY = (pWS->IPData.iconPlacement & ICON_PLACE_BOTTOM_PRIMARY) ?
230                                1 : (pWS->IPData.placementRows - extraYSpace);
231        }
232        else
233        {
234            xMargin = (sW - placementW +
235                ((pWS->IPData.iPlaceW - pWS->pSD->iconWidth) & 1)) / 2;
236            extraXSpace = 0;
237            yMargin = (sH - placementH +
238                ((pWS->IPData.iPlaceH - pWS->pSD->iconHeight) & 1))/ 2;
239            extraYSpace = 0;
240
241            if (pWS->IPData.iconPlacement & ICON_PLACE_RIGHT_PRIMARY)
242            {
243                xMargin = sW - placementW - xMargin;
244                pWS->IPData.placeIconX = pWS->IPData.iPlaceW -
245                                         pWS->pSD->iconWidth -
246                                         pWS->IPData.placeIconX;
247            }
248            if (pWS->IPData.iconPlacement & ICON_PLACE_BOTTOM_PRIMARY)
249            {
250                yMargin = sH - placementH - yMargin;
251                pWS->IPData.placeIconY = pWS->IPData.iPlaceH -
252                                         pWS->pSD->iconHeight -
253                                         pWS->IPData.placeIconY;
254            }
255        }
256    }
257
258    /*
259     * Setup array of grid row positions and grid column positions:
260     */
261
262    if ((pWS->IPData.placementRowY =
263            (int *)XtMalloc ((pWS->IPData.placementRows+2) * sizeof (int)))
264        == NULL)
265    {
266        Warning ("Insufficient memory for icon placement");
267        wmGD.iconAutoPlace = False;
268        return;
269    }
270    else if ((pWS->IPData.placementColX =
271                (int *)XtMalloc ((pWS->IPData.placementCols+2) * sizeof (int)))
272             == NULL)
273    {
274        XtFree ((char *)pWS->IPData.placementRowY);
275        Warning ("Insufficient memory for icon placement");
276        wmGD.iconAutoPlace = False;
277        return;
278    }
279
280    pWS->IPData.placementRowY[0] = yMargin;
281    for (i = 1; i <= pWS->IPData.placementRows; i++)
282    {
283        pWS->IPData.placementRowY[i] = pWS->IPData.placementRowY[i - 1] +
284            pWS->IPData.iPlaceH;
285        if ((extraYSpace > 0) && (i >= extraPY))
286        {
287            (pWS->IPData.placementRowY[i])++;
288            extraYSpace--;
289        }
290    }
291
292    pWS->IPData.placementColX[0] = xMargin;
293    for (i = 1; i <= pWS->IPData.placementCols; i++)
294    {
295        pWS->IPData.placementColX[i] = pWS->IPData.placementColX[i - 1] +
296            pWS->IPData.iPlaceW;
297        if ((extraXSpace > 0) && (i >= extraPX))
298        {
299            (pWS->IPData.placementColX[i])++;
300            extraXSpace--;
301        }
302    }
303
304
305    /*
306     * Setup an array of icon places.
307     */
308
309    pWS->IPData.totalPlaces =
310        pWS->IPData.placementRows * pWS->IPData.placementCols;
311
312    if ((pWS->IPData.placeList =
313          (IconInfo *)XtMalloc (pWS->IPData.totalPlaces * sizeof (IconInfo)))
314        == NULL)
315    {
316        Warning ("Insufficient memory for icon placement");
317        XtFree ((char *)pWS->IPData.placementRowY);
318        XtFree ((char *)pWS->IPData.placementColX);
319        wmGD.iconAutoPlace = False;
320        return;
321    }
322
323    memset ((char *)pWS->IPData.placeList, 0,
324        pWS->IPData.totalPlaces * sizeof (IconInfo));
325
326    pWS->IPData.onRootWindow = True;
327
328
329} /* END OF FUNCTION InitIconPlacement */
330
331
332
333/*************************************<->*************************************
334 *
335 *  GetNextIconPlace (pIPD)
336 *
337 *
338 *  Description:
339 *  -----------
340 *  This function identifies and returns the next free icon grid place.
341 *
342 *
343 *  Outputs:
344 *  -------
345 *  Return = next free place (index)
346 *
347 *************************************<->***********************************/
348
349#ifdef _NO_PROTO
350int GetNextIconPlace (pIPD)
351
352    IconPlacementData *pIPD;
353#else /* _NO_PROTO */
354int GetNextIconPlace (IconPlacementData *pIPD)
355#endif /* _NO_PROTO */
356{
357    int i;
358
359
360    for (i = 0; i < pIPD->totalPlaces; i++)
361    {
362        if (pIPD->placeList[i].pCD == (ClientData *)NULL)
363        {
364            return (i);
365        }
366    }
367
368    /*
369     * All places are filled!  Find an alternative place.
370     */
371
372    return (NO_ICON_PLACE);
373
374} /* END OF FUNCTION GetNextIconPlace */
375
376
377
378/*************************************<->*************************************
379 *
380 *  CvtIconPlaceToPosition (pIPD, place, pX, pY)
381 *
382 *
383 *  Description:
384 *  -----------
385 *  This function converts an icon place (index) into an icon position.
386 *
387 *
388 *  Inputs:
389 *  ------
390 *  pIPD = ptr to icon placement data
391 *
392 *  place = place to be converted
393 *
394 *  wmGD = (iconPlacement ...)
395 *
396 *
397 *  Outputs:
398 *  -------
399 *  pX = pointer to icon place X location
400 *
401 *  pY = pointer to icon place Y location
402 *
403 *************************************<->***********************************/
404
405#ifdef _NO_PROTO
406void CvtIconPlaceToPosition (pIPD, place, pX, pY)
407    IconPlacementData *pIPD;
408    int place;
409    int *pX;
410    int *pY;
411
412#else /* _NO_PROTO */
413void CvtIconPlaceToPosition (IconPlacementData *pIPD, int place, int *pX, int *pY)
414#endif /* _NO_PROTO */
415{
416    int row;
417    int col;
418
419
420    if (pIPD->iconPlacement &
421        (ICON_PLACE_LEFT_PRIMARY | ICON_PLACE_RIGHT_PRIMARY))
422    {
423        col = place % pIPD->placementCols;
424        row = place / pIPD->placementCols;
425    }
426    else
427    {
428        col = place / pIPD->placementRows;
429        row = place % pIPD->placementRows;
430    }
431
432    if (pIPD->iconPlacement &
433        (ICON_PLACE_RIGHT_PRIMARY | ICON_PLACE_RIGHT_SECONDARY))
434    {
435        col = pIPD->placementCols - col - 1;
436    }
437    if (pIPD->iconPlacement &
438             (ICON_PLACE_BOTTOM_PRIMARY | ICON_PLACE_BOTTOM_SECONDARY))
439    {
440        row = pIPD->placementRows - row - 1;
441    }
442
443    if (pIPD->onRootWindow)
444    {
445        *pX = pIPD->placementColX[col] + pIPD->placeIconX;
446        *pY = pIPD->placementRowY[row] + pIPD->placeIconY;
447    }
448    else
449    {
450        *pX = col * pIPD->iPlaceW;
451        *pY = row * pIPD->iPlaceH;
452    }
453
454} /* END OF FUNCTION CvtIconPlaceToPosition */
455
456
457
458/*************************************<->*************************************
459 *
460 *  FindIconPlace (pCD, pIPD, x, y)
461 *
462 *
463 *  Description:
464 *  -----------
465 *  This function is used to find a free icon place in the proximity of the
466 *  specified position.
467 *
468 *
469 *  Inputs:
470 *  ------
471 *  pIPD = ptr to icon placement data
472 *
473 *  x = desired x location of icon place
474 *
475 *  y = desired y location of icon place
476 *
477 *
478 *  Outputs:
479 *  -------
480 *  Return = icon place (index)
481 *
482 *
483 *  Comments:
484 *  --------
485 *  Look first for a free icon place at the position passed in.  If that place
486 *  is taken then look at positions that are +- one half the icon width/height
487 *  from the postion passed in.  If those positions are taken look at
488 *  positions that are +- one half icon placement width/height from the
489 *  position passed in.
490 *
491 *************************************<->***********************************/
492
493#ifdef _NO_PROTO
494int FindIconPlace (pCD, pIPD, x, y)
495    ClientData *pCD;
496    IconPlacementData *pIPD;
497    int x;
498    int y;
499
500#else /* _NO_PROTO */
501int FindIconPlace (ClientData *pCD, IconPlacementData *pIPD, int x, int y)
502#endif /* _NO_PROTO */
503{
504    int place;
505    int i;
506    int j;
507    int diffX;
508    int diffY;
509    int altX;
510    int altY;
511    int amt;
512
513
514    place = CvtIconPositionToPlace (pIPD, x, y);
515
516    if (place < pIPD->totalPlaces)
517    {
518        if (pIPD->placeList[place].pCD == (ClientData *)NULL)
519        {
520        return (place);
521        }
522    }
523    else
524    {
525        if (pIPD->iconPlacement & ICON_PLACE_LEFT_PRIMARY)
526        {
527            amt = pIPD->placementCols;              /* add a new row */
528        }
529        else
530        {
531            amt = pIPD->placementRows;              /* add a new column */
532        }
533
534        if (!ExtendIconList (P_ICON_BOX(pCD), amt))
535        {
536            Warning ("Insufficient memory to create icon box data");
537            return (NO_ICON_PLACE);           
538        }
539    }
540    /*
541     * The place for the passed in position is in use, look at places for
542     * alternative positions.
543     */
544
545    for (i = 0; i < 2; i++)
546    {
547        switch (i)
548        {
549            case 0:
550            {
551                diffX = ICON_WIDTH(pCD) / 2;
552                diffY = ICON_HEIGHT(pCD) / 2;
553                break;
554            }
555
556            case 1:
557            {
558                diffX = pIPD->iPlaceW / 2;
559                diffY = pIPD->iPlaceH / 2;
560                break;
561            }
562        }
563
564
565        for (j = 0; j < 4; j++)
566        {
567            switch (j)
568            {
569                case 0:
570                {
571                    if (pIPD->iconPlacement & ICON_PLACE_LEFT_PRIMARY)
572                    {
573                        altX = x - diffX;
574                        altY = y;
575                    }
576                    else if (pIPD->iconPlacement & ICON_PLACE_RIGHT_PRIMARY)
577                    {
578                        altX = x + diffX;
579                        altY = y;
580                    }
581                    else if (pIPD->iconPlacement & ICON_PLACE_TOP_PRIMARY)
582                    {
583                        altX = x;
584                        altY = y - diffY;
585                    }
586                    else
587                    {
588                        altX = x;
589                        altY = y + diffY;
590                    }
591                    break;
592                }
593
594                case 1:
595                {
596                    if (pIPD->iconPlacement & ICON_PLACE_LEFT_PRIMARY)
597                    {
598                        altX = x + diffX;
599                        altY = y;
600                    }
601                    else if (pIPD->iconPlacement & ICON_PLACE_RIGHT_PRIMARY)
602                    {
603                        altX = x - diffX;
604                        altY = y;
605                    }
606                    else if (pIPD->iconPlacement & ICON_PLACE_TOP_PRIMARY)
607                    {
608                        altX = x;
609                        altY = y + diffY;
610                    }
611                    else
612                    {
613                        altX = x;
614                        altY = y - diffY;
615                    }
616                    break;
617                }
618
619                case 2:
620                {
621                    if (pIPD->iconPlacement & ICON_PLACE_LEFT_SECONDARY)
622                    {
623                        altX = x - diffX;
624                        altY = y;
625                    }
626                    else if (pIPD->iconPlacement & ICON_PLACE_RIGHT_SECONDARY)
627                    {
628                        altX = x + diffX;
629                        altY = y;
630                    }
631                    else if (pIPD->iconPlacement & ICON_PLACE_TOP_SECONDARY)
632                    {
633                        altX = x;
634                        altY = y + diffY;
635                    }
636                    else
637                    {
638                        altX = x;
639                        altY = y - diffY;
640                    }
641                    break;
642                }
643
644                case 3:
645                {
646                    if (pIPD->iconPlacement & ICON_PLACE_LEFT_SECONDARY)
647                    {
648                        altX = x + diffX;
649                        altY = y;
650                    }
651                    else if (pIPD->iconPlacement & ICON_PLACE_RIGHT_SECONDARY)
652                    {
653                        altX = x - diffX;
654                        altY = y;
655                    }
656                    else if (pIPD->iconPlacement & ICON_PLACE_TOP_SECONDARY)
657                    {
658                        altX = x;
659                        altY = y - diffY;
660                    }
661                    else
662                    {
663                        altX = x;
664                        altY = y + diffY;
665                    }
666                    break;
667                }
668            }
669
670            if (P_ICON_BOX(pCD))
671            {
672                GetClipDimensions(pCD, False);
673                if (altX < clipX)
674                {
675                    return (NO_ICON_PLACE);
676                }
677                if (altY < clipY)
678                {
679                    return (NO_ICON_PLACE);
680                }
681                if (((int)altX) > ((int)clipX +
682                        (int)clipWidth - ((int)ICON_WIDTH(pCD))))
683                {
684                    return (NO_ICON_PLACE);
685                }
686                if (((int)altY) > ((int)clipY +
687                        (int)clipHeight - ((int)ICON_HEIGHT(pCD))))
688                {
689                    return (NO_ICON_PLACE);
690                }
691            }
692
693            place = CvtIconPositionToPlace (pIPD, altX, altY);
694            if ((pIPD->placeList[place].pCD) == NULL)
695            {
696                return (place);
697            }
698
699        }
700    }
701
702    /*
703     * Couldn't find an unoccupied place in the proximity of the passed-in
704     * position.
705     */
706
707    return (NO_ICON_PLACE);
708
709
710} /* END OF FUNCTION FindIconPlace */
711
712
713
714/*************************************<->*************************************
715 *
716 *  CvtIconPostionToPlace (pIPD, x, y)
717 *
718 *
719 *  Description:
720 *  -----------
721 *  This function converts an icon position to an icon place.
722 *
723 *
724 *  Inputs:
725 *  ------
726 *  pIPD = ptr to icon placement data
727 *
728 *  x,y = location to be converted into an icon place
729 *
730 *
731 *  Outputs:
732 *  -------
733 *  Return = icon place (index)
734 *
735 *************************************<->***********************************/
736
737#ifdef _NO_PROTO
738int CvtIconPositionToPlace (pIPD, x, y)
739    IconPlacementData *pIPD;
740    int x;
741    int y;
742
743#else /* _NO_PROTO */
744int CvtIconPositionToPlace (IconPlacementData *pIPD, int x, int y)
745#endif /* _NO_PROTO */
746{
747    int row;
748    int col;
749
750
751    if (pIPD->onRootWindow)
752    {
753        /*
754         * Scan through the root window row/column arrays and find the
755         * placement position.
756         */
757
758        for (row = 1; row < pIPD->placementRows; row++)
759        {
760            if (y < pIPD->placementRowY[row])
761            {
762                break;
763            }
764        }
765        row--;
766
767        for (col = 1; col < pIPD->placementCols; col++)
768        {
769            if (x < pIPD->placementColX[col])
770            {
771                break;
772            }
773        }
774        col--;
775
776
777        if (pIPD->iconPlacement &
778            (ICON_PLACE_RIGHT_PRIMARY | ICON_PLACE_RIGHT_SECONDARY))
779        {
780            col = pIPD->placementCols - col - 1;
781        }
782        if (pIPD->iconPlacement &
783            (ICON_PLACE_BOTTOM_PRIMARY | ICON_PLACE_BOTTOM_SECONDARY))
784        {
785            row = pIPD->placementRows - row - 1;
786        }
787    }
788    else
789    {
790        /*
791         * convert icon box coords
792         */
793        col = x / pIPD->iPlaceW;
794        row = y / pIPD->iPlaceH;
795    }
796
797
798    if (pIPD->iconPlacement &
799        (ICON_PLACE_LEFT_PRIMARY | ICON_PLACE_RIGHT_PRIMARY))
800    {
801        return ((row * pIPD->placementCols) + col);
802    }
803    else
804    {
805        return ((col * pIPD->placementRows) + row);
806    }
807   
808
809} /* END OF FUNCTION CvtIconPositionToPlace */
810
811
812
813
814
815/*************************************<->*************************************
816 *
817 *  PackRootIcons ()
818 *
819 *
820 *  Description:
821 *  -----------
822 *  This function packs the icons on the root window
823 *
824 *
825 *  Inputs:
826 *  ------
827 *
828 *  Outputs:
829 *  -------
830 *
831 *  Comments:
832 *  ---------
833 *
834 *************************************<->***********************************/
835
836#ifdef _NO_PROTO
837void PackRootIcons ()
838
839#else /* _NO_PROTO */
840void PackRootIcons (void)
841#endif /* _NO_PROTO */
842{
843    int iOld, iNew;
844    ClientData *pCD;
845    ClientData *pCD_active;
846    int hasActiveText = 1;
847
848    /*
849     * find context of the activeIconTextWin to get pCD and then
850     * if it is the same as this client, hide it.
851     */
852
853    if (XFindContext (DISPLAY, ACTIVE_PSD->activeIconTextWin,
854                        wmGD.windowContextType, (caddr_t *)&pCD_active))
855    {
856        hasActiveText = 0;
857    }
858
859    /*
860     *  Traverse the list and pack them together
861     */
862
863    if (wmGD.iconAutoPlace)
864    {
865        for (iOld = iNew = 0; iOld < ACTIVE_WS->IPData.totalPlaces;
866            iOld++, iNew++)
867        {
868            if (ACTIVE_WS->IPData.placeList[iOld].pCD == NULL)
869            {
870                /* advance to next non-null entry */
871                while (++iOld < ACTIVE_WS->IPData.totalPlaces &&
872                       !ACTIVE_WS->IPData.placeList[iOld].pCD)
873                    ;
874            }
875
876            if (iOld < ACTIVE_WS->IPData.totalPlaces && iOld != iNew)
877            {
878                /* move the icon from its old place to the new place */
879
880                MoveIconInfo (&ACTIVE_WS->IPData, iOld, iNew);
881
882                pCD = ACTIVE_WS->IPData.placeList[iNew].pCD;
883                pCD->iconPlace = iNew;
884                CvtIconPlaceToPosition (&ACTIVE_WS->IPData,
885                    pCD->iconPlace, &pCD->iconX, &pCD->iconY);
886
887                if (hasActiveText && (pCD == pCD_active))
888                {
889                    /* hide activeIconTextWin first */
890                    HideActiveIconText ((WmScreenData *)NULL);
891                    XMoveWindow (DISPLAY, ICON_FRAME_WIN(pCD), pCD->iconX,
892                             pCD->iconY);
893                    ShowActiveIconText (pCD);
894                }
895                else
896                {
897                    XMoveWindow (DISPLAY, ICON_FRAME_WIN(pCD), pCD->iconX,
898                             pCD->iconY);
899                }
900            }
901        }
902    }
903} /* END OF FUNCTION PackRootIcons */
904
905
906
907/*************************************<->*************************************
908 *
909 *  MoveIconInfo (pIPD, p1, p2)
910 *
911 *
912 *  Description:
913 *  -----------
914 *  Move icon info from place 1 to place 2 in the placement list.
915 *
916 *
917 *  Inputs:
918 *  ------
919 *  pIPD        - ptr to icon placement data
920 *  p1          - placement index 1 (source)
921 *  p2          - placement index 2 (destination)
922 *
923 *  Outputs:
924 *  -------
925 *
926 *  Comments:
927 *  --------
928 *
929 *************************************<->***********************************/
930
931#ifdef _NO_PROTO
932void MoveIconInfo (pIPD, p1, p2)
933
934    IconPlacementData *pIPD;
935    int p1, p2;
936#else /* _NO_PROTO */
937void MoveIconInfo (IconPlacementData *pIPD, int p1, int p2)
938#endif /* _NO_PROTO */
939{
940
941    /* only move if destination is empty */
942    if (pIPD->placeList[p2].pCD == NULL)
943    {
944        pIPD->placeList[p2].pCD = pIPD->placeList[p1].pCD;
945        pIPD->placeList[p2].theWidget = pIPD->placeList[p1].theWidget;
946        pIPD->placeList[p2].pCD->iconPlace = p2;
947
948        pIPD->placeList[p1].pCD =  NULL;
949        pIPD->placeList[p1].theWidget = NULL;
950    }
951}
Note: See TracBrowser for help on using the repository browser.