dtwm: Change to ANSI function definitions
[oweals/cde.git] / cde / programs / dtwm / WmIconBox.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 /* 
24  * (c) Copyright 1989, 1990, 1991, 1992, 1993, 1994 OPEN SOFTWARE FOUNDATION, INC. 
25  * ALL RIGHTS RESERVED 
26 */ 
27 /* 
28  * Motif Release 1.2.4
29 */
30 /*
31  * (c) Copyright 1987, 1988, 1989, 1990, 1993, 1994 Hewlett-Packard Company
32  * (c) Copyright 1993, 1994 International Business Machines Corp.
33  * (c) Copyright 1993, 1994 Sun Microsystems, Inc.
34  * (c) Copyright 1993, 1994 Novell, Inc.
35  */
36
37 /*
38  * Included Files:
39  */
40
41 #include "WmGlobal.h"
42 #include "WmHelp.h"
43 #include <X11/StringDefs.h>
44 #include <X11/Intrinsic.h>
45 #include <X11/Shell.h>
46 #include <X11/Xutil.h>
47 #include <X11/Vendor.h>
48
49 #include <X11/keysymdef.h>
50 #include <X11/keysym.h>
51
52
53 #include <Xm/Xm.h>
54 #include <Xm/DialogS.h>
55 #include <Xm/Frame.h>
56 #include <Xm/Label.h>
57 #include <Xm/PushB.h>
58 #include <Xm/DrawnB.h>
59 #include <Xm/ScrolledW.h>
60 #include <Xm/BulletinB.h>
61 #include <Xm/ToggleB.h>
62
63 #define MWM_NEED_IIMAGE
64 #define MWM_NEED_GREYED75
65 #define MWM_NEED_SLANT2
66 #include "WmIBitmap.h"
67
68 #include "WmResNames.h"
69
70 #include <stdio.h>
71
72 /*
73  * include extern functions
74  */
75
76 #include "WmIconBox.h"
77 #include "WmCDInfo.h"
78 #include "WmError.h"
79 #include "WmEvent.h"
80 #include "WmFunction.h"
81 #include "WmIDecor.h"
82 #include "WmIPlace.h"
83 #include "WmImage.h"
84 #include "WmPanelP.h"  /* for typedef in WmManage.h */
85 #include "WmManage.h"
86 #include "WmMenu.h"
87 #include "WmResParse.h"
88 #include "WmResource.h"
89 #include "WmWinInfo.h"
90 #include "WmWrkspace.h"
91
92 #ifndef MAX
93 #define MAX(a,b) ((a)>(b)?(a):(b))
94 #endif
95
96
97
98 /*
99  * Global Variables:
100  */
101
102
103 Pixel select_color;
104 Pixmap greyedPixmap;
105
106 int frameShadowThickness;
107 int firstTime = 1;
108 Cardinal insertPosition = 0;
109 #define    DEFAULT_ICON_BOX_TITLE "Icons"
110 Const char *szhorizontal = "horizontal";
111 Const char *szvertical = "vertical";
112
113 \f
114 /*************************************<->*************************************
115  *
116  *  InitIconBox (pSD)
117  *
118  *
119  *  Description:
120  *  -----------
121  *  This function controls creation of icon boxes
122  *
123  *
124  *************************************<->***********************************/
125 void InitIconBox (WmScreenData *pSD)
126
127 {
128     int iws;
129     /*
130      * Start the process of making the icon boxes
131      */
132
133
134
135     /*
136      * Manage a separate icon box in every workspace
137      * on this screen.
138      */
139     for (iws = 0; iws < pSD->numWorkspaces; iws++)
140     {
141         AddIconBoxForWorkspace (&pSD->pWS[iws]);
142     }
143
144     if (pSD->fadeNormalIcon)
145     {
146         MakeFadeIconGC (pSD);
147     }
148
149
150 } /* END OF FUNCTION InitIconBox */
151
152 /*************************************<->*************************************
153  *
154  *  AddIconBoxForWorkspace (pWS)
155  *
156  *
157  *  Description:
158  *  -----------
159  *  This function adds an iconbox to a workspace
160  *
161  *
162  *************************************<->***********************************/
163 void AddIconBoxForWorkspace (WmWorkspaceData *pWS)
164
165 {
166     extern WmWorkspaceData *pIconBoxInitialWS;
167
168     pIconBoxInitialWS = pWS;
169     ManageWindow (pWS->pSD, None, MANAGEW_ICON_BOX);
170
171 } /* END OF FUNCTION AddIconBoxForWorkspace */
172
173 /*************************************<->*************************************
174  *
175  *  MakeIconBox (pWS, pCD);
176  *
177  *
178  *  Description:
179  *  -----------
180  *  
181  *
182  *
183  *  Inputs:
184  *  ------
185  *  pWS     = pointer to workspace data
186  *  pCD     =  a pointer to ClientData
187  *
188  * 
189  *  Outputs:
190  *  -------
191  *  
192  *  Return =  (Boolean) True iff successful.
193  *
194  *
195  *  Comments:
196  *  --------
197  *  If fails, frees the ClientData structure pointed to by pCD.
198  * 
199  *************************************<->***********************************/
200
201 Boolean MakeIconBox (WmWorkspaceData *pWS, ClientData *pCD)
202 {
203     IconBoxData *pIBD;
204
205
206     /* 
207      * Make an icon box and return the pCD
208      */
209
210     if (pCD)
211     {
212         if (!(pIBD = (IconBoxData *)XtMalloc (sizeof (IconBoxData))))
213         {
214             /*
215              * We need a pointer to icon box data to add to the
216              * list of icon boxes linked to pWS->pIconBox. If
217              * we can't allocate space we need to free the space
218              * allocated for the ClientData structure 
219              */
220
221             Warning (((char *)GETMESSAGE(36, 1, "Insufficient memory to create icon box data")));
222             XtFree ((char *)pCD);  
223             return (FALSE);  
224         }
225
226         InitializeIconBoxData (pWS, pIBD);
227         InitializeClientData (pCD, pIBD);
228
229         if (!(pIBD->IPD.placeList = 
230             (IconInfo *)XtMalloc (pIBD->IPD.totalPlaces * sizeof (IconInfo))))
231         {
232             Warning (((char *)GETMESSAGE(36, 2, "Insufficient memory to create icon box data")));
233             XtFree ((char *)pIBD);
234             XtFree ((char *)pCD);  
235             return (FALSE);  
236         }
237         memset (pIBD->IPD.placeList, 0, 
238             pIBD->IPD.totalPlaces * sizeof (IconInfo));
239
240         /*
241          * Make  the top level shell for this icon box
242          */
243         MakeShell (pWS, pIBD);
244
245         /*
246          * Make  the scrolled window for this icon box
247          */
248
249         MakeScrolledWindow (pWS, pIBD);
250
251         /*
252          * Make  the row column manager for this icon box
253          */
254         MakeBulletinBoard (pWS, pIBD);
255
256         /*
257          * Realize the widget tree and set client data fields
258          */
259
260         RealizeIconBox (pWS, pIBD, pCD);
261
262         /*
263          * Link the new icon box to list of icon boxes
264          */
265         AddNewBox (pWS, pIBD);
266     }
267     
268     return (TRUE);  
269
270 } /* END OF FUNCTION MakeIconBox */
271
272 /*************************************<->*************************************
273  *
274  *  DestroyIconBox (pWS)
275  *
276  *
277  *  Description:
278  *  -----------
279  *  Destroys an icon box 
280  *
281  *
282  *  Inputs:
283  *  ------
284  *  pWS     = pointer to workspace data
285  *
286  * 
287  *  Outputs:
288  *  -------
289  *  
290  *  Return =  none
291  *
292  *
293  *  Comments:
294  *  --------
295  *  Used when deleting a workspace
296  *  Should be called AFTER all clients have been removed from the 
297  *  workspace -- there should be no icons in the icon box.
298  * 
299  *************************************<->***********************************/
300
301 void DestroyIconBox (WmWorkspaceData *pWS)
302 {
303     IconBoxData *pIBD;
304
305     pIBD = pWS->pIconBox;
306
307     XtDestroyWidget (pIBD->shellWidget);
308
309     UnManageWindow (pIBD->pCD_iconBox);
310
311     XtFree ((char *) pIBD);
312    
313 } /* END OF FUNCTION DestroyIconBox */
314
315 /*************************************<->*************************************
316  *
317  *  MakeShell (pWS, pIBD)
318  *
319  *
320  *  Description:
321  *  -----------
322  *  
323  *
324  *
325  *  Inputs:
326  *  ------
327  *  pWS = pointer to workspace data
328  *
329  *  pIBD  = pointer to IconBoxData
330  *
331  *  XXinput = ...
332  *
333  * 
334  *  Outputs:
335  *  -------
336  *  
337  *  pIBD->shellWidget 
338  *
339  *
340  *  Comments:
341  *  --------
342  *  XXComments ...
343  * 
344  *************************************<->***********************************/
345
346 void MakeShell (WmWorkspaceData *pWS, IconBoxData *pIBD)
347 {
348
349     Arg setArgs[20];
350     int i;
351     char *pchIBTitle = NULL;
352
353     /*
354      * Create top level application shell for icon box
355      */
356
357     i=0;
358
359     XtSetArg (setArgs[i], XmNallowShellResize, (XtArgVal)True); i++; 
360     
361     XtSetArg (setArgs[i], XmNborderWidth, (XtArgVal)0); i++; 
362
363     XtSetArg (setArgs[i], XmNkeyboardFocusPolicy, (XtArgVal)XmEXPLICIT); i++;
364
365     if (pWS->pSD->iconBoxTitle)
366     {
367         pchIBTitle = WmXmStringToString (pWS->pSD->iconBoxTitle);
368
369         XtSetArg (setArgs[i], XmNtitle, (XtArgVal)pchIBTitle); i++;
370         XtSetArg (setArgs[i], XmNiconName, (XtArgVal)pchIBTitle); i++;
371     }
372     XtSetArg (setArgs[i], XmNmappedWhenManaged, (XtArgVal)False); i++;
373     XtSetArg (setArgs[i], XmNdialogStyle, (XtArgVal)XmDIALOG_MODELESS); i++;
374     XtSetArg (setArgs[i], XmNdepth, 
375         (XtArgVal) DefaultDepth (DISPLAY, pWS->pSD->screen)); i++;
376     XtSetArg (setArgs[i], XmNscreen, 
377         (XtArgVal) ScreenOfDisplay (DISPLAY, pWS->pSD->screen)); i++;
378
379     pIBD->shellWidget = (Widget) XtCreatePopupShell (WmNclient, 
380                                         topLevelShellWidgetClass,
381                                         pWS->workspaceTopLevelW,
382                                         (ArgList)setArgs, i);
383
384     if (pchIBTitle != NULL) XtFree (pchIBTitle);
385
386 } /* END OF FUNCTION MakeShell */
387
388
389 \f
390 /*************************************<->*************************************
391  *
392  *  MakeScrolledWindow (pWS, pIBD)
393  *
394  *
395  *  Description:
396  *  -----------
397  *  
398  *
399  *
400  *  Inputs:
401  *  ------
402  *  pWS = pointer to workspace data
403  *  pIBD  = pointer to IconBoxData
404  *  XXinput = ...
405  *
406  * 
407  *  Outputs:
408  *  -------
409  *  
410  *  Return =  pIBD with the  pIBD->scrolledWidget set
411  *
412  *
413  *  Comments:
414  *  --------
415  *  XXComments ...
416  * 
417  *************************************<->***********************************/
418
419 void MakeScrolledWindow (WmWorkspaceData *pWS, IconBoxData *pIBD)
420 {
421
422     Arg setArgs[20]; 
423     int i;
424
425     /*
426      * Create frame widget to give the scrolled window 
427      * an external bevel
428      */
429
430     i=0;
431     XtSetArg (setArgs[i], XmNborderWidth,  (XtArgVal) 0 ); i++;
432     XtSetArg (setArgs[i], XmNmarginWidth,  (XtArgVal) 0 ); i++;
433     XtSetArg (setArgs[i], XmNmarginHeight, (XtArgVal) 0 ); i++;
434     XtSetArg (setArgs[i], XmNshadowType, (XtArgVal) XmSHADOW_OUT); i++;
435     XtSetArg (setArgs[i], XmNshadowThickness,
436                         (XtArgVal) frameShadowThickness); i++;
437     pIBD->frameWidget = XtCreateManagedWidget ("IBframe", 
438                                         xmFrameWidgetClass, 
439                                         pIBD->shellWidget,
440                                         (ArgList)setArgs, i);
441
442     XtAddCallback (pIBD->frameWidget, XmNhelpCallback,
443                    WmDtWmTopicHelpCB, WM_DT_ICONBOX_TOPIC);
444
445     /*
446      * Create scrolled window to hold row column manager 
447      */
448
449     i=0;
450
451     XtSetArg (setArgs[i], XmNscrollingPolicy , (XtArgVal) XmAUTOMATIC ); i++;
452
453     XtSetArg (setArgs[i], XmNborderWidth , (XtArgVal) 0 ); i++;
454     XtSetArg (setArgs[i], XmNspacing , (XtArgVal) IB_MARGIN_WIDTH ); i++;
455     /*
456      * do we want to get these from a resource or set it here
457      * to control the appearance of the iconBox
458      */
459
460     XtSetArg (setArgs[i], XmNscrolledWindowMarginWidth, (XtArgVal) 3); i++;
461     XtSetArg (setArgs[i], XmNscrolledWindowMarginHeight, (XtArgVal) 3); i++;
462     XtSetArg (setArgs[i], XmNshadowThickness,
463                         (XtArgVal) FRAME_EXTERNAL_SHADOW_WIDTH); i++;
464
465     XtSetArg (setArgs[i], XmNscrollBarDisplayPolicy,(XtArgVal) XmSTATIC ); i++;
466     XtSetArg (setArgs[i], XmNvisualPolicy, (XtArgVal) XmVARIABLE ); i++;
467
468     pIBD->scrolledWidget = XtCreateManagedWidget ("IBsWindow", 
469                                         xmScrolledWindowWidgetClass, 
470                                         pIBD->frameWidget,
471                                         (ArgList)setArgs, i);
472
473     XtAddCallback(pIBD->scrolledWidget, XmNtraverseObscuredCallback,
474                   (XtCallbackProc) IconScrollVisibleCallback, (caddr_t)NULL);
475
476     XtAddEventHandler(pIBD->scrolledWidget, 
477                         StructureNotifyMask, 
478                         False, 
479                         (XtEventHandler)UpdateIncrements, 
480                         (XtPointer) pIBD);
481
482
483
484 } /* END OF FUNCTION MakeScrolledWindow */
485
486
487 \f
488 /*************************************<->*************************************
489  *
490  *  MakeBulletinBoard (pWS, pIBD)
491  *
492  *
493  *  Description:
494  *  -----------
495  *  
496  *
497  *
498  *  Inputs:
499  *  ------
500  *  pWS = pointer to workspace data
501  *  pIBD  = pointer to IconBoxData
502  *
503  *  XXinput = ...
504  *
505  * 
506  *  Outputs:
507  *  -------
508  *  
509  *  Return =  pIBD with the  pIBD->bBoardWidget
510  *
511  *
512  *  Comments:
513  *  --------
514  *  XXComments ...
515  * 
516  *************************************<->***********************************/
517
518 void MakeBulletinBoard (WmWorkspaceData *pWS, IconBoxData *pIBD)
519 {
520
521     int i;
522     Arg setArgs[20];
523
524     /*
525      * Create bulletin board to hold icons
526      */
527
528     i=0;
529 #ifdef DEBUG_ICON_BOX
530     XtSetArg (setArgs[i], XmNborderWidth , 1); i++; 
531 #else
532     XtSetArg (setArgs[i], XmNborderWidth , 0); i++; 
533 #endif /* DEBUG_ICON_BOX */
534     
535     XtSetArg (setArgs[i], XmNshadowThickness,(XtArgVal) 0); i++;
536
537     XtSetArg (setArgs[i], XmNspacing , 0); i++; 
538     XtSetArg (setArgs[i], XmNmarginHeight , 0); i++;
539     XtSetArg (setArgs[i], XmNmarginWidth ,  0); i++;
540
541     XtSetArg (setArgs[i], XmNdialogStyle, (XtArgVal) XmDIALOG_WORK_AREA); i++;
542
543     XtSetArg (setArgs[i], XmNresizePolicy, (XtArgVal) XmRESIZE_NONE); i++;
544     XtSetArg (setArgs[i], XmNdefaultPosition , (XtArgVal) False); i++;
545
546     XtSetArg (setArgs[i], XtNinsertPosition , InsertPosition); i++;
547
548     pIBD->bBoardWidget = XtCreateManagedWidget ("IBbBoard", 
549                                         xmBulletinBoardWidgetClass,
550                                         pIBD->scrolledWidget,
551                                         (ArgList)setArgs, i);
552
553 } /* END OF FUNCTION MakeBulletinBoard */
554
555
556 \f
557 /*************************************<->*************************************
558  *
559  *  RealizeIconBox (pWS, pIBD, pCD)
560  *
561  *
562  *  Description:
563  *  -----------
564  *  
565  *
566  *
567  *  Inputs:
568  *  ------
569  *  pWS = pointer to workspace data 
570  *
571  *  pIBD  = pointer to IconBoxData
572  *
573  *  pCD   = pointer to ClientData
574  *
575  * 
576  *  Outputs:
577  *  -------
578  *  
579
580  *  Return =  pIBD with the  pIBD->shellWin set
581  *  Return =  pIBD with the  pIBD->scrolledWin set
582  *  Return =  pIBD with the  pIBD->bBoardWin set
583
584  *
585  *  Return =  pCD  with appropriate fields set
586  *
587  *
588  *  Comments:
589  *  --------
590  *  XXComments ...
591  * 
592  *************************************<->***********************************/
593
594 void RealizeIconBox (WmWorkspaceData *pWS, IconBoxData *pIBD, ClientData *pCD)
595 {
596
597     int i;
598     Arg getArgs[10]; 
599     Arg setArgs[2]; 
600     Widget clipWidget;
601     Pixmap  bgPixmap;
602     Pixmap defaultImage;
603     
604
605     XtRealizeWidget (pIBD->shellWidget);
606
607     pCD->client = XtWindow (pIBD->shellWidget);
608
609     /*
610      * This will set the scrolling granularity for the icon box
611      */
612
613     SetGeometry (pWS, pCD, pIBD);
614
615     /*
616      * Point to the iconBox 
617      */
618
619     pIBD->pCD_iconBox = pCD;
620     pCD->thisIconBox = pIBD;    
621     /*
622      * get the background color of the bulletin board for
623      * greyed icon work
624      */
625
626     i=0;
627     XtSetArg (setArgs[i], XmNbackground, (XtArgVal) select_color ); i++;
628     XtSetValues (pIBD->bBoardWidget, (ArgList) setArgs, i); 
629
630
631     i=0;
632     XtSetArg (getArgs[i], XmNbackgroundPixmap, (XtArgVal) &bgPixmap ); i++;
633     XtGetValues (pIBD->bBoardWidget, getArgs, i);
634
635     i=0;
636     XtSetArg (getArgs[i], XmNclipWindow, (XtArgVal) &clipWidget ); i++;
637     XtGetValues (pIBD->scrolledWidget, getArgs, i);
638
639     /*
640      * Set the background of the clip window for the scrolled 
641      * window so the default widget background doesn't flash
642      */
643
644     i = 0;
645     XtSetArg(setArgs[i], XmNbackground, (XtArgVal) select_color); i++;
646     XtSetValues (clipWidget, (ArgList) setArgs, i); 
647
648
649     /*
650      * Save the clipWidget id to use in constraining icon moves in box
651      */
652
653     pIBD->clipWidget = clipWidget; 
654
655     MakeShrinkWrapIconsGC (pWS->pSD, bgPixmap);
656
657     
658     if (pWS->pSD->iconDecoration & ICON_IMAGE_PART)
659     {
660         /*
661          * Make a pixmap to use when iconWindows are unmapped
662          */
663         defaultImage = XCreateBitmapFromData (DISPLAY, pWS->pSD->rootWindow,
664                                               (char*)iImage_bits, iImage_width, 
665                                               iImage_height);
666         
667         pWS->pSD->defaultPixmap = MakeIconPixmap (pCD,
668                                                   defaultImage,
669                                                   None, iImage_width,
670                                                   iImage_height, 1);
671     }
672     
673     
674 } /* END OF FUNCTION RealizeIconBox */
675
676
677 \f
678 /*************************************<->*************************************
679  *
680  *  AddNewBox (pWS, pIBD)
681  *
682  *
683  *  Description:
684  *  -----------
685  *  
686  *
687  *
688  *  Inputs:
689  *  ------
690  *  pWS = pointer to workspace data
691  *
692  *  pIBD  = pointer to IconBoxData
693  *
694  * 
695  *  Outputs:
696  *  -------
697  *  
698  *
699  *  Comments:
700  *  --------
701  *  Finds the last iconbox on the list starting at pWS->pIconBox and
702  *  adds the new icon box to the end of the list.
703  * 
704  *************************************<->***********************************/
705
706 void AddNewBox (WmWorkspaceData *pWS, IconBoxData *pIBD)
707 {
708  
709     IconBoxData *pibd;
710
711     if (pWS->pIconBox)
712     {
713         pibd = pWS->pIconBox;
714
715         while (pibd->pNextIconBox)
716         {
717             pibd = pibd->pNextIconBox;
718         }
719
720         pibd->pNextIconBox = pIBD;
721     }
722     else
723     {
724         pWS->pIconBox = pIBD;
725     }
726
727   
728 } /* END OF FUNCTION AddNewBox */
729
730
731 \f
732 /*************************************<->*************************************
733  *
734  *  InitializeIconBoxData (pWS, pIBD)
735  *
736  *
737  *  Description:
738  *  -----------
739  *  
740  *
741  *
742  *  Inputs:
743  *  ------
744  *  pWS = pointer to Workspace Data
745  *
746  *  pIBD  = pointer to IconBoxData
747  *
748  * 
749  *  Outputs:
750  *  -------
751  *  
752  *
753  *  Comments:
754  *  --------
755  *  Initializes all pIBD fields to NULL
756  * 
757  *************************************<->***********************************/
758
759 void InitializeIconBoxData (WmWorkspaceData *pWS, IconBoxData *pIBD)
760 {
761     int mask;
762     int X;
763     int Y;
764     unsigned int width;
765     unsigned int height;
766     int sW, sH;
767
768     frameShadowThickness = FRAME_INTERNAL_SHADOW_WIDTH;
769
770     pIBD->numberOfIcons = 0;
771     pIBD->currentRow = 0;
772     pIBD->currentCol = 0;
773     pIBD->lastRow = 0;
774     pIBD->lastCol = 0;
775     pIBD->IPD.placeList = NULL;
776
777     pIBD->scrolledWidget = NULL;
778     pIBD->bBoardWidget = NULL;
779     pIBD->clipWidget = NULL; 
780     pIBD->wsID = pWS->id;
781
782     ToLower (pWS->pSD->iconBoxSBDisplayPolicy);
783     
784     if (!((!strcmp(pWS->pSD->iconBoxSBDisplayPolicy , "all"))      ||
785           (!strcmp(pWS->pSD->iconBoxSBDisplayPolicy , szvertical)) ||
786           (!strcmp(pWS->pSD->iconBoxSBDisplayPolicy , szhorizontal))))
787     {
788         strcpy(pWS->pSD->iconBoxSBDisplayPolicy, "all");
789     }
790
791         
792
793     /*
794      * this will be set by the iconPlacement resource if
795      * iconBoxGeometry width and height are not specified
796      */
797
798     if (pWS->iconBoxGeometry == NULL) /* not set by user */
799     {
800         /*
801          * Use the iconPlacement resource 
802          */
803         
804         if (pWS->pSD->iconPlacement & 
805             (ICON_PLACE_TOP_PRIMARY | ICON_PLACE_BOTTOM_PRIMARY))
806         {
807             pIBD->IPD.iconPlacement = ICON_PLACE_TOP_PRIMARY;
808             pIBD->IPD.placementCols = 1;  
809             pIBD->IPD.placementRows = 6;
810         }
811         else
812         {
813             pIBD->IPD.iconPlacement = ICON_PLACE_LEFT_PRIMARY;
814             pIBD->IPD.placementCols = 6;  
815             pIBD->IPD.placementRows = 1;
816         }
817
818     }
819     else
820     {
821         mask = XParseGeometry(pWS->iconBoxGeometry, &X, &Y, 
822                               &width, &height);
823
824         if ((mask & WidthValue) && (width > 0))
825         {
826             pIBD->IPD.placementCols = (int)width; 
827         }
828         else
829         {
830             pIBD->IPD.placementCols = 6;   
831         }
832
833         if ((mask & HeightValue) && (height > 0))
834         {
835             pIBD->IPD.placementRows = (int)height; 
836         }
837         else
838         {
839             pIBD->IPD.placementRows = 1; 
840         }
841
842         /*
843          * Set orientation 
844          */
845
846         if (pIBD->IPD.placementRows <= pIBD->IPD.placementCols) 
847         {
848             pIBD->IPD.iconPlacement = ICON_PLACE_LEFT_PRIMARY;
849         }
850         else
851         {
852             pIBD->IPD.iconPlacement = ICON_PLACE_TOP_PRIMARY;
853         }
854     }
855
856
857     /*
858      * Override orientation if iconBoxSBDisplayPolicy is set to
859      * horizontal or vertical
860      */
861
862     if (!(strcmp(pWS->pSD->iconBoxSBDisplayPolicy , szvertical)))  
863     {
864         pIBD->IPD.iconPlacement = ICON_PLACE_LEFT_PRIMARY;          
865     }
866     else if (!(strcmp(pWS->pSD->iconBoxSBDisplayPolicy , szhorizontal)))
867     {
868         pIBD->IPD.iconPlacement = ICON_PLACE_TOP_PRIMARY;
869     }
870         
871
872     
873
874     /* 
875      * set initial size of placement space to size of screen 
876      */
877
878     sW = DisplayWidth (DISPLAY, pWS->pSD->screen) / pWS->pSD->iconWidth;
879     sH = DisplayHeight (DISPLAY, pWS->pSD->screen) / pWS->pSD->iconHeight;
880
881     pIBD->IPD.totalPlaces = sW * sH;
882
883     pIBD->IPD.onRootWindow = False;
884
885     /*
886      * The icon box does not live in an icon box in this version
887      */
888
889     pIBD->pNextIconBox =NULL;
890     
891
892 } /* END OF FUNCTION InitializeIconBoxData */   
893
894
895 \f
896 /*************************************<->*************************************
897  *
898  *  SetIconBoxInfo (pWS, pCD)
899  *
900  *
901  *  Description:
902  *  -----------
903  *
904  *  Inputs:
905  *  ------
906  *  pCD
907  *
908  * 
909  *  Comments:
910  *  --------
911  * 
912  *************************************<->***********************************/
913
914 void SetIconBoxInfo (WmWorkspaceData *pWS, ClientData *pCD)
915 {
916     pCD->clientClass = WmCIconBox;
917     pCD->clientName = pWS->pSD->iconBoxName;
918     ProcessClientResources (pCD); 
919
920 } /* END OF FUNCTION SetIconBoxInfo */
921
922
923 \f
924 /*************************************<->*************************************
925  *
926  *  InitializeClientData (pCD)
927  *
928  *
929  *  Description:
930  *  -----------
931  *  
932  *
933  *
934  *  Inputs:
935  *  ------
936  *  pCD
937  *
938  * 
939  *  Outputs:
940  *  -------
941  *  
942  *
943  *  Comments:
944  *  --------
945  *  Initializes geometry, etc. fields 
946  * 
947  *************************************<->***********************************/
948
949 void InitializeClientData (ClientData *pCD, IconBoxData *pIBD)
950 {
951     pCD->internalBevel = (wmGD.frameStyle == WmSLAB) ? 0 : 
952                                             FRAME_INTERNAL_SHADOW_WIDTH;
953
954     pCD->clientX = 0;
955     pCD->clientY = 0;
956
957     pCD->clientFlags |= ICON_BOX ;
958
959     pCD->widthInc = pIBD->IPD.iPlaceW = ICON_WIDTH(pCD)   
960         + IB_SPACING 
961         + (2 * IB_MARGIN_WIDTH); 
962
963     pCD->heightInc = pIBD->IPD.iPlaceH = ICON_HEIGHT(pCD) 
964         + IB_SPACING  
965         + (2 * IB_MARGIN_HEIGHT);
966
967     pCD->clientWidth = pIBD->IPD.placementCols * pCD->widthInc;
968     pCD->clientHeight = pIBD->IPD.placementRows * pCD->heightInc;
969     
970     if (!(pCD->pSD->iconBoxTitle))
971     {
972 #ifndef NO_MESSAGE_CATALOG
973         pCD->pSD->iconBoxTitle = 
974             XmStringCreateLocalized(wmNLS.default_icon_box_title);
975 #else
976         pCD->pSD->iconBoxTitle = 
977             XmStringCreateLocalized(DEFAULT_ICON_BOX_TITLE);
978 #endif
979     }
980
981     pCD->clientTitle = pCD->pSD->iconBoxTitle;
982     pCD->iconTitle   = pCD->pSD->iconBoxTitle;
983     
984 } /* END OF FUNCTION InitializeClientData */   
985
986
987 \f
988 /*************************************<->*************************************
989  *
990  *  MakeShrinkWrapIconsGC (pSD, bgPixmap)
991  *
992  *
993  *  Description:
994  *  -----------
995  *  Make an  graphic context to shrink the icons in the icon box
996  *      box that are not in the MINIMIZED_STATE.
997  *
998  *
999  *  Inputs:
1000  *  ------
1001  *  pSD         - pointer to screen data
1002  * 
1003  *  Outputs:
1004  *  -------
1005  *  Modifies global data
1006  *
1007  *  Comments:
1008  *  --------
1009  *  
1010  * 
1011  *************************************<->***********************************/
1012
1013 void MakeShrinkWrapIconsGC (WmScreenData *pSD, Pixmap bgPixmap)
1014 {
1015
1016     XtGCMask  copyMask;
1017    
1018
1019     if (!pSD->shrinkWrapGC)
1020     {
1021         pSD->shrinkWrapGC = XCreateGC (DISPLAY, pSD->rootWindow, 0, 
1022                 (XGCValues *) NULL);
1023
1024         copyMask = ~0L;
1025
1026         XCopyGC (DISPLAY, pSD->iconAppearance.inactiveGC,
1027                 copyMask, pSD->shrinkWrapGC);
1028
1029         if (bgPixmap != XmUNSPECIFIED_PIXMAP)
1030         {
1031             XSetTile (DISPLAY, pSD->shrinkWrapGC,  bgPixmap); 
1032             XSetFillStyle (DISPLAY, pSD->shrinkWrapGC, FillTiled);
1033             XSetBackground (DISPLAY, pSD->shrinkWrapGC, select_color);
1034         }
1035         else
1036         {
1037             XSetForeground (DISPLAY, pSD->shrinkWrapGC, select_color);
1038         }
1039     }
1040
1041 } /* END OF FUNCTION MakeShrinkWrapIconsGC */
1042
1043
1044 \f
1045 /*************************************<->*************************************
1046  *
1047  *  MakeFadeIconGC (pSD)
1048  *
1049  *
1050  *  Description:
1051  *  -----------
1052  *  Make an  graphic context for "greying" the icons in the icon
1053  *      box that are not in the MINIMIZED_STATE.
1054  *
1055  *
1056  *  Inputs:
1057  *  ------
1058  *  pSD = pointer to screen data
1059  * 
1060  *  Outputs:
1061  *  -------
1062  *  Modifies global data
1063  *
1064  *  Comments:
1065  *  --------
1066  *  
1067  * 
1068  *************************************<->***********************************/
1069
1070 void MakeFadeIconGC (WmScreenData *pSD)
1071 {
1072
1073     XtGCMask  copyMask;
1074     static    Pixmap tmpFontClipMask;
1075    
1076
1077     pSD->fadeIconGC = XCreateGC (DISPLAY, pSD->rootWindow, 0, 
1078                                 (XGCValues *) NULL);
1079     pSD->fadeIconTextGC = XCreateGC (DISPLAY, pSD->rootWindow, 0, 
1080                                 (XGCValues *) NULL);
1081
1082     copyMask = ~0L;
1083
1084     XCopyGC (DISPLAY, pSD->iconAppearance.inactiveGC,
1085                 copyMask, pSD->fadeIconGC);
1086
1087     XCopyGC (DISPLAY, pSD->iconAppearance.inactiveGC,
1088                 copyMask, pSD->fadeIconTextGC);
1089
1090     tmpFontClipMask = XCreateBitmapFromData (DISPLAY, pSD->rootWindow,
1091                         (char*)greyed75_bits, greyed75_width, greyed75_height);
1092
1093     greyedPixmap = XCreateBitmapFromData (DISPLAY, pSD->rootWindow,
1094                         (char*)slant2_bits, slant2_width, slant2_height);
1095
1096     XSetStipple (DISPLAY, pSD->fadeIconTextGC,  tmpFontClipMask); 
1097     XSetFillStyle (DISPLAY, pSD->fadeIconTextGC, FillStippled);
1098
1099     XSetStipple (DISPLAY, pSD->fadeIconGC,  greyedPixmap); 
1100     XSetFillStyle (DISPLAY, pSD->fadeIconGC, FillStippled);
1101     XSetForeground (DISPLAY, pSD->fadeIconGC, select_color);
1102
1103 } /* END OF FUNCTION MakeFadeIconGC */
1104
1105
1106 \f
1107 /*************************************<->*************************************
1108  *
1109  *  SetGeometry (pWS, pCD, pIBD)
1110  *
1111  *
1112  *  Description:
1113  *  -----------
1114  *  
1115  *
1116  *
1117  *  Inputs:
1118  *  ------
1119  *  pIBD  = pointer to IconBoxData
1120  *  pCD   = pointer to ClientData
1121  *  XXinput = ...
1122  *
1123  * 
1124  *  Outputs:
1125  *  -------
1126  *  
1127  *  
1128  *
1129  *
1130  *  Comments:
1131  *  --------
1132  *  XXComments ...
1133  * 
1134  *************************************<->***********************************/
1135
1136 void SetGeometry (WmWorkspaceData *pWS, ClientData *pCD, IconBoxData *pIBD)
1137 {
1138
1139     int i;
1140     Arg setArgs[10];
1141
1142     int mask;
1143     int X;
1144     int Y;
1145     unsigned int width;
1146     unsigned int height;
1147     unsigned int boxdim, tmpMin;
1148     int diff;
1149     unsigned long       decoration;
1150
1151     /*
1152      * Set horizontal and vertical scrolling granularity
1153      */
1154
1155     SetGranularity (pWS, pCD, pIBD );
1156
1157     /*
1158      * Set the initial width and height of the icon box bulletin board
1159      */
1160
1161     i=0; 
1162     XtSetArg (setArgs[i], XmNwidth, (XtArgVal) pCD->clientWidth); i++;
1163     XtSetArg (setArgs[i], XmNheight, (XtArgVal) pCD->clientHeight); i++;
1164     XtSetValues (pIBD->bBoardWidget, (ArgList) setArgs, i); 
1165
1166     /*
1167      * Adjust icon box window height for height of 
1168      * horizontal scroll bar etc.
1169      */
1170
1171     pCD->clientHeight = pCD->clientHeight + pCD->baseHeight;
1172     pCD->oldMaxHeight = pCD->maxHeight = pCD->clientHeight;
1173
1174     /*
1175      * Adjust iconbox window width for width of 
1176      * vertical scroll bar etc.
1177      */
1178
1179     pCD->clientWidth = pCD->clientWidth + pCD->baseWidth;
1180     pCD->oldMaxWidth = pCD->maxWidth = pCD->clientWidth;
1181
1182
1183     /* 
1184      * Check that minWidth is large enough to disallow overlap
1185      * of title bar gadgets
1186      */
1187
1188     /* compute for minimum frame size */
1189     if ((decoration = pCD->decor) & MWM_DECOR_TITLE)
1190     {
1191         boxdim = InitTitleBarHeight(pCD);   /* macro not valid yet */
1192         tmpMin = boxdim +
1193                  ((decoration & MWM_DECOR_MENU) ? boxdim : 0) +
1194                  ((decoration & MWM_DECOR_MINIMIZE) ? boxdim : 0) +
1195                  ((decoration & MWM_DECOR_MAXIMIZE) ? boxdim : 0) -
1196                  2*(pCD->matteWidth);
1197     }
1198     else {
1199         tmpMin = 0;
1200     }
1201
1202     /* Make: 
1203      *   minWidth >= tmpMin
1204      *   minWidth >= max (baseWidth, widthInc) > 0
1205      *     & an integral number of widthInc from baseWidth.
1206      */
1207
1208     if (pCD->minWidth < tmpMin)
1209     {
1210         if ((diff = ((tmpMin - pCD->baseWidth)%pCD->widthInc)) != 0)
1211         {
1212             pCD->minWidth = tmpMin + pCD->widthInc - diff;
1213         }
1214         else
1215         {
1216             pCD->minWidth = tmpMin;
1217         }
1218     }
1219
1220     if (pCD->minWidth < pCD->baseWidth)
1221     {
1222         pCD->minWidth = pCD->baseWidth;
1223     }
1224
1225     if (pCD->minWidth == 0)
1226     {
1227         pCD->minWidth = pCD->widthInc;
1228     }
1229     else if ((diff = ((pCD->minWidth - pCD->baseWidth)%pCD->widthInc)) != 0)
1230     {
1231         pCD->minWidth += pCD->widthInc - diff;
1232     }
1233
1234
1235
1236     if (pCD->clientWidth < pCD->minWidth)
1237     {
1238         pCD->clientWidth = pCD->minWidth;
1239     }
1240
1241     pIBD->IPD.placementCols = (int)((pCD->clientWidth - pCD->baseWidth)
1242                                     / pCD->widthInc);
1243
1244
1245     /*
1246      * Make:
1247      *
1248      *   maxWidth >= minWidth
1249      *     & an integral number of widthInc from baseWidth.
1250      */
1251
1252     if (pCD->maxWidth < pCD->minWidth)
1253     {
1254         pCD->maxWidth = pCD->minWidth;
1255     }
1256
1257     pCD->maxWidthLimit = pCD->maxWidth;
1258
1259     pCD->maxWidth -= ((pCD->maxWidth - pCD->baseWidth)% pCD->widthInc);
1260     pCD->oldMaxWidth = pCD->maxWidth;
1261
1262     pCD->maxHeightLimit = pCD->maxHeight;
1263
1264
1265     /*
1266      * Set the initial width and height of the icon box bulletin board
1267      */
1268
1269     i=0; 
1270     XtSetArg (setArgs[i], XmNwidth, (XtArgVal) pCD->clientWidth 
1271               - pCD->baseWidth ); i++;
1272     XtSetArg (setArgs[i], XmNheight, (XtArgVal) pCD->clientHeight 
1273               - pCD->baseHeight ); i++;
1274     XtSetValues (pIBD->bBoardWidget, (ArgList) setArgs, i); 
1275
1276
1277     /*
1278      * Set the initial width and height of the icon box scrolled Window
1279      */
1280
1281     i=0; 
1282     XtSetArg (setArgs[i], XmNwidth, (XtArgVal) 
1283                 (pCD->clientWidth - (2 * frameShadowThickness))); i++;
1284     XtSetArg (setArgs[i], XmNheight, (XtArgVal) 
1285                 (pCD->clientHeight - (2 * frameShadowThickness))); i++;
1286
1287     XtSetValues (pIBD->scrolledWidget, (ArgList) setArgs, i); 
1288
1289
1290              
1291     /*
1292      * Call SetFrameInfo with fake X and Y so we can get clientOffset
1293      */
1294
1295     pCD->xBorderWidth = 0;
1296     SetFrameInfo (pCD);
1297
1298
1299     /*
1300      * Set initial placement of icon box
1301      */
1302
1303     mask = XParseGeometry(pWS->iconBoxGeometry, &X, &Y, 
1304                               &width, &height);
1305     
1306     if (mask & XValue)
1307     {
1308         if (mask & XNegative)
1309         {
1310             pCD->clientX = X 
1311                            + DisplayWidth(DISPLAY, SCREEN_FOR_CLIENT(pCD)) 
1312                            - pCD->clientWidth
1313                            - pCD->clientOffset.x;
1314         }
1315         else 
1316         {
1317             pCD->clientX = X + pCD->clientOffset.x;
1318         }
1319     }
1320     else
1321     {
1322         pCD->clientX = pCD->clientOffset.x;
1323     }
1324
1325     if (mask & YValue)
1326     {
1327         if (mask & YNegative)
1328         {
1329             pCD->clientY = Y 
1330                            + DisplayHeight(DISPLAY, SCREEN_FOR_CLIENT(pCD)) 
1331                            - pCD->clientHeight
1332                            - pCD->clientOffset.x ;
1333         }
1334         else
1335         {
1336             pCD->clientY = Y + pCD->clientOffset.y;
1337         }
1338     }
1339     else
1340     {
1341         pCD->clientY =  pCD->clientOffset.x
1342                         + DisplayHeight(DISPLAY, SCREEN_FOR_CLIENT(pCD)) 
1343                         - pCD->clientHeight;
1344     }
1345
1346
1347     PlaceFrameOnScreen (pCD, &pCD->clientX, &pCD->clientY, pCD->clientWidth,
1348         pCD->clientHeight);
1349     pCD->clientX -= (wmGD.positionIsFrame
1350                         ? pCD->clientOffset.x
1351                         : 0);
1352                         
1353     pCD->clientY -=  (wmGD.positionIsFrame
1354                         ? pCD->clientOffset.y
1355                         : 0);
1356
1357
1358     i=0; 
1359
1360     XtSetArg (setArgs[i], XmNx, (XtArgVal) pCD->clientX); i++;
1361     XtSetArg (setArgs[i], XmNy, (XtArgVal) pCD->clientY); i++;
1362
1363     XtSetValues (pIBD->shellWidget, (ArgList) setArgs, i); 
1364
1365     pCD->maxX = pCD->clientX;
1366     pCD->maxY = pCD->clientY;
1367
1368
1369 } /* END OF FUNCTION SetGeometry */
1370
1371
1372 \f
1373 /*************************************<->*************************************
1374  *
1375  *  SetGranularity (pWS, pCD, pIBD )
1376  *
1377  *
1378  *  Description:
1379  *  -----------
1380  *  
1381  *
1382  *
1383  *  Inputs:
1384  *  ------
1385  *  pIBD  = pointer to IconBoxData
1386  *  pCD   = pointer to ClientData
1387  *  XXinput = ...
1388  *
1389  * 
1390  *  Outputs:
1391  *  -------
1392  *  
1393  *  
1394  *
1395  *
1396  *  Comments:
1397  *  --------
1398  *  XXComments ...
1399  * 
1400  *************************************<->***********************************/
1401
1402 void SetGranularity (WmWorkspaceData *pWS, ClientData *pCD, IconBoxData *pIBD)
1403 {
1404
1405     int i;
1406     Dimension hScrollBarHeight = 0;
1407     Dimension hBarHeight = 0;
1408     Dimension vScrollBarWidth = 0;
1409     Dimension vBarWidth = 0;
1410
1411     Dimension spacing;
1412     short shadowThickness;
1413     short marginWidth;
1414     short marginHeight;
1415
1416     short hShighlightThickness;
1417     short vShighlightThickness;
1418
1419     Arg setArgs[10];
1420     Arg getArgs[10]; 
1421
1422     i=0;
1423
1424
1425
1426     XtSetArg(getArgs[i], XmNspacing, (XtArgVal) &spacing ); i++;
1427     XtSetArg(getArgs[i], XmNshadowThickness, (XtArgVal) &shadowThickness); i++;
1428     XtSetArg(getArgs[i], XmNscrolledWindowMarginWidth, 
1429                                         (XtArgVal) &marginWidth); i++;
1430     XtSetArg(getArgs[i], XmNscrolledWindowMarginHeight, 
1431                                         (XtArgVal) &marginHeight); i++;
1432     XtSetArg (getArgs[i], XmNverticalScrollBar, 
1433                                         (XtArgVal) &pIBD->vScrollBar); i++;
1434     XtSetArg(getArgs[i], XmNhorizontalScrollBar, 
1435                                         (XtArgVal) &pIBD->hScrollBar); i++;
1436     XtGetValues (pIBD->scrolledWidget, getArgs, i);
1437
1438     
1439     if (strcmp(pWS->pSD->iconBoxSBDisplayPolicy , szvertical))
1440     {
1441         
1442         /*
1443          * Set horizontal scrolling granularity
1444          */
1445         i=0;
1446         XtSetArg (getArgs[i], XmNheight, (XtArgVal) &hBarHeight ); i++;
1447         XtSetArg (getArgs[i], XmNhighlightThickness,
1448                  (XtArgVal) &hShighlightThickness); i++;
1449         XtGetValues (pIBD->hScrollBar, getArgs, i);
1450
1451
1452         i=0; 
1453         XtSetArg(setArgs[i], XmNincrement, (XtArgVal) pCD->widthInc); i++;
1454         XtSetArg (setArgs[i], XmNhighlightThickness ,
1455                   IB_HIGHLIGHT_BORDER); i++;
1456         XtSetArg(setArgs[i], XmNheight,
1457                  (XtArgVal) (hBarHeight - (2 * hShighlightThickness)) +
1458                  (2 * IB_HIGHLIGHT_BORDER)); i++;
1459
1460         XtSetValues (pIBD->hScrollBar, (ArgList) setArgs, i); 
1461         
1462         /*
1463          * Get hScrollBarHeight and troughColor
1464          */
1465         
1466         i=0;
1467         XtSetArg (getArgs[i], XmNtroughColor, (XtArgVal) &select_color ); i++;
1468         XtSetArg (getArgs[i], XmNheight, (XtArgVal) &hScrollBarHeight ); i++;
1469         XtGetValues (pIBD->hScrollBar, getArgs, i);
1470
1471     }
1472     
1473     
1474     if (strcmp(pWS->pSD->iconBoxSBDisplayPolicy , szhorizontal))
1475     {
1476         
1477         /*
1478          * Set vertical scrolling granularity
1479          */
1480         i=0;
1481         XtSetArg (getArgs[i], XmNwidth, (XtArgVal) &vBarWidth ); i++;
1482         XtSetArg (getArgs[i], XmNhighlightThickness,
1483                  (XtArgVal) &vShighlightThickness); i++;
1484         XtGetValues (pIBD->vScrollBar, getArgs, i);
1485
1486
1487         i=0; 
1488         XtSetArg (setArgs[i], XmNincrement, (XtArgVal) pCD->heightInc); i++;
1489         XtSetArg (setArgs[i], XmNhighlightThickness ,
1490                         IB_HIGHLIGHT_BORDER); i++;
1491         XtSetArg(setArgs[i], XmNwidth,
1492                  (XtArgVal) (vBarWidth - (2 * vShighlightThickness)) +
1493                  (2 * IB_HIGHLIGHT_BORDER)); i++;
1494
1495         XtSetValues (pIBD->vScrollBar, (ArgList) setArgs, i); 
1496         
1497         /*
1498          * Get vScrollBarWidth
1499          */
1500         
1501         i=0;
1502         XtSetArg (getArgs[i], XmNtroughColor, (XtArgVal) &select_color ); i++;
1503         XtSetArg (getArgs[i], XmNwidth, (XtArgVal) &vScrollBarWidth ); i++;
1504         XtGetValues (pIBD->vScrollBar, getArgs, i);
1505     }
1506     
1507     
1508     
1509     if (!strcmp(pWS->pSD->iconBoxSBDisplayPolicy , szvertical))
1510     {
1511         XtUnmanageChild(pIBD->hScrollBar);
1512         hScrollBarHeight = 0;
1513         
1514         i=0;
1515         XtSetArg (setArgs[i], XmNscrollBarDisplayPolicy, 
1516                   (XtArgVal) XmAS_NEEDED ); i++;
1517         XtSetValues (pIBD->scrolledWidget, (ArgList) setArgs, i);
1518         
1519     }
1520     else if (!strcmp(pWS->pSD->iconBoxSBDisplayPolicy , szhorizontal))
1521     {
1522         XtUnmanageChild(pIBD->vScrollBar);
1523         vScrollBarWidth = 0;
1524         
1525         i=0;
1526         XtSetArg (setArgs[i], XmNscrollBarDisplayPolicy, 
1527                   (XtArgVal) XmAS_NEEDED ); i++;
1528         XtSetValues (pIBD->scrolledWidget, (ArgList) setArgs, i);
1529     }
1530     
1531     
1532     
1533     
1534     pCD->baseWidth =  IB_SPACING 
1535                        + 2 * IB_HIGHLIGHT_BORDER
1536 #ifdef DEBUG_ICON_BOX
1537                        + 2
1538                        + spacing
1539 #endif /* DEBUG_ICON_BOX */
1540                        + (int) vScrollBarWidth 
1541                        + 2 * frameShadowThickness
1542                        + (int) 2 * marginWidth
1543                        + (marginWidth > 0 
1544                                ? 2 * (int) shadowThickness 
1545                                : shadowThickness);
1546
1547                         
1548
1549     pCD->baseHeight =  IB_SPACING
1550                         + 2 * IB_HIGHLIGHT_BORDER
1551 #ifdef DEBUG_ICON_BOX
1552                         + 2
1553 #endif /* DEBUG_ICON_BOX */
1554                         + spacing
1555                         + (int) hScrollBarHeight 
1556                         + 2 * frameShadowThickness
1557                         + (int) 2 * marginHeight
1558                         + (marginHeight > 0 
1559                                 ? 2 * (int) shadowThickness 
1560                                 : shadowThickness);
1561
1562     pCD->minWidth = pCD->baseWidth + pCD->widthInc;
1563     pCD->minHeight = pCD->baseHeight + pCD->heightInc;
1564
1565     pCD->oldMaxWidth = pCD->maxWidth = pCD->minWidth;
1566
1567     pCD->oldMaxHeight = pCD->maxHeight = pCD->minHeight;
1568
1569 } /* END OF FUNCTION SetGranularity */
1570
1571
1572 \f
1573 /*************************************<->*************************************
1574  *
1575  * GetIconBoxMenuItems ()
1576  *
1577  *
1578  *  Description:
1579  *  -----------
1580  *  XXDescription ...
1581  * 
1582  *************************************<->***********************************/
1583
1584 MenuItem *GetIconBoxMenuItems (WmScreenData *pSD)
1585 {
1586
1587     return(ParseMwmMenuStr (pSD, 
1588         (unsigned char *)((char *)GETMESSAGE(36, 3, "\"Pack Icons\" _P  Alt Shift<Key>F7 f.pack_icons\n"))));
1589
1590 } /* END OF FUNCTION GetIconBoxMenuItems */
1591
1592
1593 \f
1594 /*************************************<->*************************************
1595  *
1596  *  MapIconBoxes ()
1597  *
1598  *
1599  *  Description:
1600  *  -----------
1601  *  
1602  *
1603  *
1604  *  Inputs:
1605  *  ------
1606  *
1607  * 
1608  *  Outputs:
1609  *  -------
1610  *  
1611  *
1612  *  Comments:
1613  *  --------
1614  *  Maps all iconboxes on the list starting at pWS->pIconBox 
1615  * 
1616  *************************************<->***********************************/
1617
1618 void MapIconBoxes (WmWorkspaceData *pWS)
1619 {
1620  
1621     IconBoxData *pibd;
1622
1623     if (pWS->pIconBox)
1624     {
1625         pibd = pWS->pIconBox;
1626
1627         while (pibd)
1628         {
1629             XtPopup(pibd->shellWidget, XtGrabNone);
1630             pibd = pibd->pNextIconBox;
1631         }
1632     }
1633
1634   
1635 } /* END OF FUNCTION MapIconBoxes */
1636
1637 /*************************************<->*************************************
1638  *
1639  *  UnmapIconBoxes (pWS)
1640  *
1641  *
1642  *  Description:
1643  *  -----------
1644  *  Unmaps all the iconboxes in the  specified workspace
1645  *
1646  *
1647  *  Inputs:
1648  *  ------
1649  *  pWS = pointer to workspace data
1650  * 
1651  *  Outputs:
1652  *  -------
1653  *  
1654  *
1655  *  Comments:
1656  *  --------
1657  *  Unmaps all iconboxes on the list starting at pWS->pIconBox 
1658  *  Does not do anything with icon windows.
1659  * 
1660  *************************************<->***********************************/
1661
1662 void UnmapIconBoxes (WmWorkspaceData *pWS)
1663 {
1664  
1665     IconBoxData *pibd;
1666
1667     if (pWS->pIconBox)
1668     {
1669         pibd = pWS->pIconBox;
1670
1671         while (pibd)
1672         {
1673             XUnmapWindow (DISPLAY, pibd->pCD_iconBox->clientFrameWin);
1674             pibd = pibd->pNextIconBox;
1675         }
1676     }
1677
1678 } /* END OF FUNCTION UnmapIconBoxes */
1679
1680 /******************************<->*************************************
1681  *
1682  *  IconBoxShowing ()
1683  *
1684  *  Description:
1685  *  -----------
1686  *  Returns True if an icon box tied to a front panel button is
1687  *  showing.
1688  *
1689  *  Inputs:
1690  *  ------
1691  *  pWS = pointer to workspace data
1692  *  pCW = pointer to control window data (for front panel button )
1693  * 
1694  *  Outputs:
1695  *  -------
1696  *  Return = True if icon box is up, False if it's invisible
1697  *
1698  *  Comments:
1699  *  --------
1700  * 
1701  ******************************<->***********************************/
1702
1703     
1704 Boolean
1705 IconBoxShowing (WmWorkspaceData *pWS)
1706 {
1707     Boolean rval = False;
1708     
1709     if (pWS->pIconBox &&
1710         ClientInWorkspace (pWS, pWS->pIconBox->pCD_iconBox))
1711     {
1712         rval = True;
1713     }
1714
1715     return (rval);
1716     
1717 } /* END OF FUNCTION IconBoxShowing */
1718
1719
1720 \f
1721 /******************************<->*************************************
1722  *
1723  *  IconBoxPopUp (pWS, pCW, up)
1724  *
1725  *  Description:
1726  *  -----------
1727  *  Sets the state of the icon box attached to a front panel control.
1728  *
1729  *  Inputs:
1730  *  ------
1731  *  pWS = pointer to workspace data
1732  *  pCW = pointer to control window data (for front panel button )
1733  *  up = flag, if True, pop the icon box up; if False, hide it.
1734  * 
1735  *  Outputs:
1736  *  -------
1737  *  None
1738  *
1739  *  Comments:
1740  *  --------
1741  * 
1742  ******************************<->***********************************/
1743     
1744 void
1745 IconBoxPopUp (WmWorkspaceData *pWS, Boolean up)
1746 {
1747     
1748     IconBoxData *pibd;
1749     
1750     if (pWS->pIconBox)
1751     {
1752         pibd = pWS->pIconBox;
1753         
1754         while (pibd)
1755         {
1756             if (up)
1757             {
1758                 if (ClientInWorkspace(pWS, pibd->pCD_iconBox))
1759                 {
1760                     F_Raise (NULL, pibd->pCD_iconBox, (XEvent *)NULL);
1761                 }
1762                 else
1763                 { 
1764                     AddClientToWorkspaces (pibd->pCD_iconBox, 
1765                                            &pWS->id, 1);
1766                     return;
1767                 }
1768             }
1769             else if (!up && ClientInWorkspace (pWS, pibd->pCD_iconBox))
1770             {
1771                 RemoveClientFromWorkspaces (pibd->pCD_iconBox,
1772                                             &pWS->id, 1);
1773                 return;
1774             }               
1775             pibd = pibd->pNextIconBox;
1776         }
1777         
1778     }
1779     
1780 } /* END OF FUNCTION IconBoxPopUp */
1781
1782
1783
1784 \f
1785 /******************************<->*************************************
1786  *
1787  *  InsertIconIntoBox
1788  *
1789  *  Inputs
1790  *  ------
1791  *  pCD         - pointer to data for client to insert
1792  *
1793  *  Description:
1794  *  -----------
1795  *  XXDescription ...
1796  * 
1797  *************************************<->***********************************/
1798
1799 Boolean InsertIconIntoBox (IconBoxData *pIBD, ClientData *pCD)
1800 {
1801
1802     Boolean rval = False;
1803     Arg setArgs[20]; 
1804     int i;
1805     int iconWidth, iconHeight;
1806     IconBoxData  *tmpPointerToIconBox;
1807     Widget iconWidget;
1808     IconInfo *pIconInfo;
1809     static XmString dummyString = NULL;
1810     WsClientData *pWsc;
1811     WmWorkspaceData *pWS = GetWorkspaceData (pCD->pSD, pIBD->wsID);
1812
1813     pWsc = GetWsClientData (pWS, pCD);
1814
1815     /*
1816      * If we go to multiple icon boxes, find the box this client
1817      * wants to live in.  For now, we only have one, so point to
1818      * the first one.
1819      */
1820
1821     tmpPointerToIconBox = pIBD;
1822     
1823     if (pCD->client)
1824     {
1825
1826         pWsc->pIconBox = tmpPointerToIconBox;
1827
1828         iconWidth = ICON_WIDTH(pCD)
1829                 + (2 * IB_MARGIN_WIDTH); 
1830
1831         iconHeight = ICON_HEIGHT(pCD) 
1832                 + (2 * IB_MARGIN_HEIGHT);
1833
1834         pIconInfo = InsertIconInfo  (pWsc->pIconBox, pCD, (Widget) NULL);
1835
1836         if (pIconInfo)
1837         {
1838             pWsc->pIconBox->numberOfIcons++;
1839
1840             i = 0;
1841             XtSetArg (setArgs[i], XmNbackground,  
1842                             (XtArgVal) ICON_APPEARANCE(pCD).background ); i++;
1843             XtSetArg (setArgs[i], XmNforeground,  
1844                             (XtArgVal) ICON_APPEARANCE(pCD).foreground ); i++;
1845
1846             XtSetArg (setArgs[i], XmNx ,  (XtArgVal) pWsc->iconX); i++;
1847             XtSetArg (setArgs[i], XmNy ,  (XtArgVal) pWsc->iconY); i++;
1848
1849             XtSetArg (setArgs[i], XmNwidth ,  (XtArgVal) iconWidth); i++;
1850             XtSetArg (setArgs[i], XmNheight ,  (XtArgVal) iconHeight); i++;
1851
1852             XtSetArg (setArgs[i], XmNborderWidth ,  (XtArgVal) 0); i++;
1853
1854             XtSetArg (setArgs[i], XmNhighlightThickness ,  
1855                             IB_HIGHLIGHT_BORDER); i++;
1856
1857             XtSetArg (setArgs[i], XmNmarginHeight , (XtArgVal) 0); i++;
1858             XtSetArg (setArgs[i], XmNmarginWidth ,      (XtArgVal) 0); i++;
1859             /* 
1860              * Use type XmString so we don't get a message from XmLabel
1861              */
1862             XtSetArg (setArgs[i], XmNlabelType, (XtArgVal) XmSTRING); i++;
1863
1864             XtSetArg (setArgs[i], XmNrecomputeSize, (XtArgVal) False); i++;
1865
1866             XtSetArg (setArgs[i], XmNtraversalOn, (XtArgVal) True); i++;
1867
1868             XtSetArg (setArgs[i], XmNpushButtonEnabled, (XtArgVal) False); i++;
1869
1870             XtSetArg (setArgs[i], XmNshadowThickness, (XtArgVal) 0); i++;
1871
1872             iconWidget =  XtCreateManagedWidget("iconInIconBox",
1873                                            xmDrawnButtonWidgetClass,
1874                                            pWsc->pIconBox->bBoardWidget,
1875                                            (ArgList)setArgs, i);
1876
1877             if (dummyString == NULL)
1878             {
1879                 dummyString = 
1880                     XmStringCreateLocalized("");
1881             }
1882
1883             i = 0;
1884             XtSetArg (setArgs[i], XmNlabelString, 
1885                                         (XtArgVal) dummyString); i++;
1886
1887             XtSetValues (iconWidget, setArgs, i);
1888
1889             pIconInfo->theWidget = iconWidget;
1890
1891             pWsc->iconFrameWin = XtWindow (iconWidget); 
1892
1893             XtAddCallback (iconWidget, XmNactivateCallback, 
1894                            (XtCallbackProc)IconActivateCallback, 
1895                            (XtPointer)NULL);
1896
1897             XtAddEventHandler(iconWidget, 
1898                               SELECT_BUTTON_MOTION_MASK, 
1899                               False, 
1900                               (XtEventHandler)HandleIconBoxButtonMotion, 
1901                               (XtPointer)NULL);
1902
1903             XtAddEventHandler(iconWidget, 
1904                               DMANIP_BUTTON_MOTION_MASK, 
1905                               False, 
1906                               (XtEventHandler)HandleIconBoxButtonMotion, 
1907                               (XtPointer)NULL);
1908
1909             XtAddEventHandler(iconWidget,
1910                               KeyPressMask,
1911                               False,
1912                               (XtEventHandler)HandleIconBoxIconKeyPress,
1913                               (XtPointer)NULL);
1914
1915             
1916             
1917             if (ICON_DECORATION(pCD) & ICON_ACTIVE_LABEL_PART)
1918             {
1919                 XtAddEventHandler(iconWidget, 
1920                                   FocusChangeMask, 
1921                                   False, 
1922                                   (XtEventHandler)ChangeActiveIconboxIconText, 
1923                                   (XtPointer)NULL);
1924
1925                 if (pCD->pSD->activeLabelParent != pCD->pSD->rootWindow)
1926                 {
1927                     XRaiseWindow (DISPLAY, pCD->pSD->activeIconTextWin);
1928                 }
1929             }
1930
1931             ResetIconBoxMaxSize(pWsc->pIconBox->pCD_iconBox, 
1932                                 pWsc->pIconBox->bBoardWidget);
1933
1934             ResetArrowButtonIncrements (pWsc->pIconBox->pCD_iconBox);
1935
1936             rval = True;
1937         }
1938     } 
1939     return(rval);
1940
1941 } /* END FUNCTION InsertIconIntoBox() */   
1942    
1943
1944 \f
1945 /*************************************<->*************************************
1946  *
1947  *  InsertIconInfo  (pIBD, pCD, theWidget)
1948  *
1949  *
1950  *  Description:
1951  *  -----------
1952  *  Finds next available spot and inserts the icon 
1953  *
1954  *
1955  *  Inputs:
1956  *  ------
1957  *  pIBD        - pointer to icon box data
1958  *  pCD         - pointer to client data for this client
1959  *  theWidget   - widget containing the icon (may be null)
1960  * 
1961  *  Outputs:
1962  *  -------
1963  *
1964  *  Comments:
1965  *  --------
1966  * 
1967  *************************************<->***********************************/
1968
1969 IconInfo *InsertIconInfo (IconBoxData *pIBD, ClientData *pCD, Widget theWidget)
1970 {
1971     IconInfo *pII;
1972     int place;
1973     int amt, i;
1974     Arg setArgs[3];
1975     Arg getArgs[4];
1976     Dimension clipWidth, clipHeight;
1977     WsClientData *pWsc;
1978
1979     place = GetNextIconPlace (&pIBD->IPD);
1980     if (place == NO_ICON_PLACE)
1981     {
1982         if (pIBD->IPD.iconPlacement & ICON_PLACE_LEFT_PRIMARY)
1983         {
1984             amt = pIBD->IPD.placementCols;              /* add a new row */
1985         }
1986         else
1987         {
1988             amt = pIBD->IPD.placementRows;              /* add a new column */
1989         }
1990
1991         if (!ExtendIconList (pIBD, amt))
1992         {
1993             Warning (((char *)GETMESSAGE(36, 4, "Insufficient memory to create icon box data")));
1994             return (NULL);
1995         }
1996
1997         if (pIBD->IPD.iconPlacement & ICON_PLACE_LEFT_PRIMARY)
1998         {
1999             pIBD->IPD.placementRows++;
2000         }
2001         else
2002         {
2003             pIBD->IPD.placementCols++;
2004         }
2005         place = GetNextIconPlace (&pIBD->IPD);
2006     }
2007
2008     insertPosition = place;
2009
2010     /*
2011      * Update icon info values
2012      */
2013
2014     pII = &pIBD->IPD.placeList[place];
2015     pII->theWidget = theWidget;
2016
2017     pII->pCD = pCD;
2018
2019     pWsc = GetWsClientData (GetWorkspaceData (pCD->pSD, pIBD->wsID), pCD);
2020     pWsc->iconPlace = place;
2021
2022     CvtIconPlaceToPosition (&pIBD->IPD, pWsc->iconPlace,
2023             &pWsc->iconX, &pWsc->iconY);
2024
2025
2026     /* update next free position */
2027
2028     pIBD->currentCol = pWsc->iconX / pIBD->pCD_iconBox->widthInc;
2029     pIBD->currentRow = pWsc->iconY / pIBD->pCD_iconBox->heightInc;
2030
2031
2032     /* 
2033      * Increase bboard size if necessary
2034      */
2035     i = 0;
2036     XtSetArg (getArgs[i], XmNwidth, (XtArgVal) &clipWidth ); i++;
2037     XtSetArg (getArgs[i], XmNheight, (XtArgVal) &clipHeight ); i++;
2038     XtGetValues (pIBD->clipWidget, getArgs, i);
2039
2040     i = 0;
2041     if (pIBD->IPD.iconPlacement & ICON_PLACE_LEFT_PRIMARY)
2042     {
2043         if (pIBD->currentCol > pIBD->lastCol)
2044         {
2045             pIBD->lastCol = pIBD->currentCol;
2046         }
2047
2048         if (pIBD->currentRow > pIBD->lastRow)
2049         {
2050             pIBD->lastRow = pIBD->currentRow;
2051             if (clipHeight <= (Dimension) (pWsc->iconY + 
2052                                            pIBD->pCD_iconBox->heightInc))
2053             {
2054                 /*
2055                  * Increase bulletin board height as needed.
2056                  */
2057                 XtSetArg (setArgs[i], XmNheight, (XtArgVal) 
2058                           pWsc->iconY + pIBD->pCD_iconBox->heightInc); i++;
2059             }
2060         }
2061     }
2062     else
2063     {
2064         if (pIBD->currentCol > pIBD->lastCol)
2065         {
2066             pIBD->lastCol = pIBD->currentCol;
2067             if (clipWidth <= (Dimension) 
2068                               (pWsc->iconX + pIBD->pCD_iconBox->widthInc))
2069             {
2070                 /*
2071                  * Increase bulletin board width as needed
2072                  */
2073                 XtSetArg (setArgs[i], XmNwidth, 
2074                 (XtArgVal) pWsc->iconX +
2075                            pIBD->pCD_iconBox->widthInc); i++;
2076             }
2077         }
2078
2079         if (pIBD->currentRow > pIBD->lastRow)
2080         {
2081             pIBD->lastRow = pIBD->currentRow;
2082         }
2083     }
2084
2085     if (i > 0)
2086     {
2087         XtSetValues (pIBD->bBoardWidget, setArgs, i);
2088     }
2089
2090     return(pII);
2091     
2092
2093
2094 } /* END OF FUNCTION InsertIconInfo */
2095
2096
2097 \f
2098 /*************************************<->*************************************
2099  *
2100  *  DeleteIconFromBox
2101  *
2102  *
2103  *  Description:
2104  *  -----------
2105  *  XXDescription ...
2106  * 
2107  *************************************<->***********************************/
2108
2109 void DeleteIconFromBox (IconBoxData *pIBD, ClientData *pCD)
2110 {
2111     Widget       theChild;
2112     ClientData  *pCD_tmp;
2113     Arg          args[4];
2114     Dimension    clipWidth, clipHeight;
2115     Dimension    oldWidth, oldHeight;
2116     int          newWidth, newHeight;
2117     int          i, newCols, newRows;
2118     WmWorkspaceData *pWS = GetWorkspaceData (pCD->pSD, pIBD->wsID);
2119     WsClientData *pWsc;
2120
2121     pWsc = GetWsClientData (pWS, pCD);
2122
2123     i = 0;
2124     XtSetArg (args[i], XmNwidth, (XtArgVal) &oldWidth ); i++;
2125     XtSetArg (args[i], XmNheight, (XtArgVal) &oldHeight ); i++;
2126     XtGetValues (pIBD->bBoardWidget, args, i);
2127
2128     i = 0;
2129     XtSetArg (args[i], XmNwidth, (XtArgVal) &clipWidth); i++;
2130     XtSetArg (args[i], XmNheight, (XtArgVal) &clipHeight ); i++;
2131     XtGetValues (pIBD->clipWidget, args, i);
2132
2133     clipHeight /= (Dimension) pIBD->pCD_iconBox->heightInc;
2134     clipWidth  /= (Dimension) pIBD->pCD_iconBox->widthInc;
2135
2136     /* 
2137      * find context of the activeIconTextWin to get pCD and then 
2138      * if it is the same as this client, hide it.
2139      */
2140
2141     if (!(XFindContext (DISPLAY, pCD->pSD->activeIconTextWin,
2142                         wmGD.windowContextType, (caddr_t *)&pCD_tmp)))
2143     {
2144         if (pCD == pCD_tmp)
2145         {
2146             /* hide activeIconTextWin */
2147             HideActiveIconText ((WmScreenData *)NULL);
2148         }
2149     }
2150
2151     DeleteIconInfo (pWsc->pIconBox, pCD);
2152
2153     pWsc->pIconBox->numberOfIcons--;
2154
2155     theChild = XtWindowToWidget (DISPLAY, pWsc->iconFrameWin);
2156
2157     pWsc->pIconBox = NULL;
2158     pWsc->iconPlace = NO_ICON_PLACE;
2159     XtUnmanageChild (theChild);
2160
2161     XtDestroyWidget (theChild);
2162
2163     /* update last row and col */
2164
2165     SetNewBounds (pIBD);
2166
2167     /* resize Bulletin board  (so scroll bars show correctly */
2168     i = 0;
2169
2170     if (clipWidth <= (Dimension) (pIBD->lastCol + 1))
2171     {
2172         newWidth = (pIBD->lastCol + 1) * pIBD->pCD_iconBox->widthInc;    
2173         XtSetArg (args[i], XmNwidth, (XtArgVal) newWidth); i++;
2174         newCols = newWidth / pIBD->pCD_iconBox->widthInc;
2175     }
2176     else
2177     {
2178         newWidth = clipWidth * pIBD->pCD_iconBox->widthInc;    
2179         XtSetArg (args[i], XmNwidth, (XtArgVal) newWidth); i++;
2180         newCols = newWidth / pIBD->pCD_iconBox->widthInc;
2181     }
2182
2183     if (clipHeight <= (Dimension) (pIBD->lastRow + 1))
2184     {
2185         /* set height of bboard */
2186         newHeight = (pIBD->lastRow + 1) * pIBD->pCD_iconBox->heightInc;
2187         XtSetArg (args[i], XmNheight, (XtArgVal) newHeight ); i++;
2188         newRows = newHeight / pIBD->pCD_iconBox->heightInc;
2189     }
2190     else
2191     {
2192         newHeight = clipHeight * pIBD->pCD_iconBox->heightInc;
2193         XtSetArg (args[i], XmNheight, (XtArgVal) newHeight ); i++;
2194         newRows = newHeight / pIBD->pCD_iconBox->heightInc;
2195     }
2196
2197     if (i > 0  &&  ExpandVirtualSpace(pIBD, newWidth, newHeight))
2198     {
2199         XtSetValues (pIBD->bBoardWidget, args, i);
2200         RealignIconList (pIBD, newCols, newRows);
2201         pIBD->IPD.placementCols = newCols;
2202         pIBD->IPD.placementRows = newRows;
2203     }
2204
2205
2206     /* reset max size for icon box */
2207     ResetIconBoxMaxSize(pIBD->pCD_iconBox, pIBD->bBoardWidget);
2208     
2209     ResetArrowButtonIncrements (pIBD->pCD_iconBox);    
2210
2211 } /* END FUNCTION DeleteIconFromBox */
2212
2213
2214 \f
2215 /*************************************<->*************************************
2216  *
2217  *  DeleteIconInfo (pIBD, pCD)
2218  *
2219  *
2220  *  Description:
2221  *  -----------
2222  *  Deletes an icon info record from the icon box list based on the 
2223  *  client data pointer.
2224  *
2225  *
2226  *  Inputs:
2227  *  ------
2228  *  pIBD        - pointer to icon box data
2229  *  pCD         - pointer to client data
2230  * 
2231  *  Outputs:
2232  *  -------
2233  *
2234  *
2235  *  Comments:
2236  *  --------
2237  *  o The deleted item is freed
2238  *  o Is pCD the correct key???? !!!
2239  * 
2240  *************************************<->***********************************/
2241 void DeleteIconInfo (IconBoxData *pIBD, ClientData *pCD)
2242 {
2243     int ix, count;
2244     IconInfo *pII;
2245
2246     /* find first matching entry in list */
2247
2248     pII = &pIBD->IPD.placeList[0]; 
2249     count = pIBD->IPD.totalPlaces;
2250
2251     for (ix = 0; ix < count && pII->pCD != pCD; ix++, pII++)
2252     {
2253     }
2254
2255     if (ix < count)
2256     {
2257         /* found it, zero the entry out */
2258         pII->theWidget = NULL;
2259         pII->pCD = NULL;
2260     }
2261
2262
2263 } /* END FUNCTION DeleteIconInfo */
2264
2265
2266 \f
2267 /*************************************<->*************************************
2268  *
2269  *  ResetIconBoxMaxSize(pCD, bBoardWidget)
2270  *
2271  *
2272  *  Description:
2273  *  -----------
2274  *  XXDescription ...
2275  * 
2276  *************************************<->***********************************/
2277
2278 void ResetIconBoxMaxSize (ClientData *pCD, Widget bBoardWidget)
2279 {
2280     int i;
2281     Arg getArgs[3]; 
2282     Dimension newWidth;
2283     Dimension newHeight;
2284
2285     i=0;
2286     XtSetArg (getArgs[i], XmNwidth, (XtArgVal) &newWidth ); i++;
2287     XtSetArg (getArgs[i], XmNheight, (XtArgVal) &newHeight ); i++;
2288     XtGetValues (bBoardWidget, getArgs, i);
2289
2290     pCD->oldMaxWidth = pCD->maxWidth = newWidth + pCD->baseWidth;
2291
2292     pCD->oldMaxHeight = pCD->maxHeight = newHeight + pCD->baseHeight;
2293
2294     pCD->maxX = pCD->clientX;
2295     pCD->maxY = pCD->clientY;
2296     PlaceFrameOnScreen (pCD, &pCD->maxX, &pCD->maxY, 
2297                         pCD->maxWidth, pCD->maxHeight);
2298
2299 } /* END OF FUNCTION    ResetIconBoxMaxSize */
2300
2301
2302 \f
2303 /*************************************<->*************************************
2304  *
2305  * CheckIconBoxSize(pIBD)
2306  *
2307  *
2308  *  Description:
2309  *  -----------
2310  *  XXDescription ...
2311  * 
2312  *************************************<->***********************************/
2313
2314 Boolean CheckIconBoxSize (IconBoxData *pIBD)
2315 {
2316     int i;
2317     Arg getArgs[3]; 
2318     Arg setArgs[3]; 
2319     Dimension oldWidth;
2320     Dimension oldHeight;
2321     Dimension newWidth;
2322     Dimension newHeight;
2323     int oldCol, oldRow;
2324     Boolean rval = True;
2325
2326     i=0;
2327     XtSetArg (getArgs[i], XmNwidth, (XtArgVal) &oldWidth ); i++;
2328     XtSetArg (getArgs[i], XmNheight, (XtArgVal) &oldHeight ); i++;
2329     XtGetValues (pIBD->bBoardWidget, getArgs, i);
2330
2331     newWidth = oldWidth;
2332     newHeight = oldHeight;
2333     oldCol = oldWidth / (Dimension) pIBD->pCD_iconBox->widthInc;
2334     oldRow = oldHeight / (Dimension) pIBD->pCD_iconBox->heightInc;
2335
2336     /* 
2337      * Increase bboard size if necessary
2338      */
2339
2340     i = 0;
2341     if (pIBD->IPD.iconPlacement & ICON_PLACE_LEFT_PRIMARY)
2342     {
2343         if (oldRow < pIBD->lastRow + 1)
2344         {
2345             /*
2346              * increase bulletin board height as needed
2347              */
2348             newHeight = (pIBD->lastRow * pIBD->pCD_iconBox->heightInc)
2349                          + pIBD->pCD_iconBox->heightInc;
2350
2351             XtSetArg (setArgs[i], XmNheight, (XtArgVal) newHeight); i++;
2352         }
2353     }
2354     else
2355     {
2356         if (oldCol  < pIBD->lastCol + 1)
2357         {
2358             /*
2359              * increase bulletin board width as needed
2360              */
2361             newWidth = (pIBD->lastCol * pIBD->pCD_iconBox->widthInc)
2362                             + pIBD->pCD_iconBox->widthInc;
2363
2364             XtSetArg (setArgs[i], XmNwidth, newWidth); i++;
2365         }
2366     }
2367
2368     if (i > 0)
2369     {
2370         if (! ExpandVirtualSpace(pIBD, newWidth, newHeight))
2371         {
2372             /*
2373              * The user has resized the iconbox larger than
2374              * memory will allow.  Don't honor the resize request
2375              */
2376             rval = False;
2377             return(rval);
2378         }
2379         XtSetValues (pIBD->bBoardWidget, setArgs, i);
2380     }
2381
2382     ResetIconBoxMaxSize(pIBD->pCD_iconBox, pIBD->bBoardWidget);
2383     
2384
2385     return(rval);
2386
2387 } /* END OF FUNCTION CheckIconBoxSize */
2388
2389
2390 \f
2391 /*************************************<->*************************************
2392  *
2393  * CheckIconBoxResize(pCD, changedValues)
2394  *
2395  *
2396  *  Description:
2397  *  -----------
2398  *  XXDescription ...
2399  * 
2400  *************************************<->***********************************/
2401
2402 void CheckIconBoxResize (ClientData *pCD, unsigned int changedValues, int newWidth, int newHeight)
2403 {
2404
2405     Boolean  packVert = False;
2406     Boolean  packHorz = False;
2407     WmScreenData *pSD;
2408
2409     IconBoxData *pIBD;
2410     IconPlacementData *pIPD;
2411     int i, newCols, newRows;
2412     Arg getArgs[3]; 
2413     Arg setArgs[3]; 
2414     Dimension oldWidth;
2415     Dimension oldHeight;
2416
2417     pIPD = &pCD->thisIconBox->IPD;
2418     pIBD = pCD->thisIconBox;
2419
2420     pSD = &(wmGD.Screens[SCREEN_FOR_CLIENT(pCD)]);
2421
2422     
2423     i=0;
2424     XtSetArg (getArgs[i], XmNwidth, (XtArgVal) &oldWidth ); i++;
2425     XtSetArg (getArgs[i], XmNheight, (XtArgVal) &oldHeight ); i++;
2426     XtGetValues (pIBD->bBoardWidget, getArgs, i);
2427     
2428     newCols = pIPD->placementCols;
2429     newRows = pIPD->placementRows;
2430     newWidth = newWidth - pCD->baseWidth;               
2431     newHeight = newHeight - pCD->baseHeight;
2432     
2433     i = 0;
2434     
2435     if (changedValues & CWWidth) 
2436     {
2437         /*
2438          * There was a change in Width, see if we need to change the
2439          * bulletin board
2440          */
2441         if (newWidth > (int) oldWidth)
2442         {
2443             newCols = newWidth / pCD->widthInc;
2444             XtSetArg (setArgs[i], XmNwidth, (XtArgVal) newWidth ); i++;
2445         }
2446         
2447         if (newWidth < (int) oldWidth)
2448         {
2449             if ((!strcmp(pSD->iconBoxSBDisplayPolicy, szvertical)) &&
2450                 (newWidth / pCD->widthInc < pIBD->lastCol + 1))
2451             {
2452                 XtSetArg (setArgs[i], XmNwidth, (XtArgVal) newWidth ); i++;
2453                 newCols = newWidth / pCD->widthInc;
2454                 packVert = True;
2455             }
2456             else if (newWidth / pCD->widthInc < pIBD->lastCol + 1)
2457             {
2458                 newWidth = (pIBD->lastCol +1) * pCD->widthInc;
2459                 XtSetArg (setArgs[i], XmNwidth, (XtArgVal) newWidth ); i++;
2460             }
2461             else
2462             {
2463                 newCols = newWidth / pCD->widthInc;
2464                 XtSetArg (setArgs[i], XmNwidth, (XtArgVal) newWidth ); i++;
2465             }
2466         }
2467     }
2468     else
2469     {
2470         newWidth = oldWidth;
2471     }
2472         
2473     if (changedValues & CWHeight) 
2474     {
2475         /*
2476          * There was a change in Height, see if we need to change the
2477          * bulletin board
2478          */
2479         if (newHeight > (int) oldHeight)
2480         {
2481             newRows = newHeight / pCD->heightInc;
2482             XtSetArg (setArgs[i], XmNheight, (XtArgVal) newHeight ); i++;
2483         }
2484
2485         if (newHeight < (int) oldHeight)
2486         {
2487             if ((!strcmp(pSD->iconBoxSBDisplayPolicy, szhorizontal)) &&
2488                 (newHeight / pCD->heightInc < pIBD->lastRow + 1))
2489             {
2490                 XtSetArg (setArgs[i], XmNheight, (XtArgVal) newHeight ); i++;
2491                 newRows = newHeight / pCD->heightInc;
2492                 packHorz = True;                
2493             }
2494             else if (newHeight / pCD->heightInc < pIBD->lastRow + 1)
2495             {
2496                 newHeight = (pIBD->lastRow + 1) * pCD->heightInc;
2497                 XtSetArg (setArgs[i], XmNheight, (XtArgVal) newHeight ); i++;
2498             }
2499             else
2500             {
2501                 newRows = newHeight / pCD->heightInc;
2502                 XtSetArg (setArgs[i], XmNheight, (XtArgVal) newHeight ); i++;
2503             }
2504         }
2505     }
2506     else
2507     {
2508         newHeight = oldHeight;
2509     }
2510     
2511     if ( i >0   &&   ExpandVirtualSpace(pIBD, newWidth, newHeight))
2512     {
2513         XtSetValues (pIBD->bBoardWidget, setArgs, i);
2514     }
2515
2516     RealignIconList (pIBD, newCols, newRows);
2517
2518     pIPD->placementCols = newCols;
2519     pIPD->placementRows = newRows;
2520     
2521     ResetIconBoxMaxSize(pCD, pIBD->bBoardWidget);
2522     
2523     /*
2524      * Pack the icon box if there are icons that can no longer
2525      * be scrolled to due to iconBoxSBDisplayPolicy.
2526      */
2527     if (packVert)
2528     {
2529         PackIconBox (pIBD, packVert, False , newWidth, 0);
2530     }
2531     else if (packHorz)
2532     {
2533         PackIconBox (pIBD, False, packHorz , 0, newHeight);
2534     }
2535
2536
2537 } /* END OF FUNCTION CheckIconBoxResize */
2538
2539
2540 \f
2541 /*************************************<->*************************************
2542  *
2543  *  ExpandVirtualSpace (pIBD, newWidth, newHeight)
2544  *
2545  *
2546  *  Description:
2547  *  -----------
2548  *  Add virtural space (really the icon list )
2549  *
2550  *
2551  *  Inputs:
2552  *  ------
2553  *  pIBD        - ptr to icon box data
2554  *
2555  * 
2556  *  Outputs:
2557  *  -------
2558  *  Return      - True if successful, False otherwise
2559  *
2560  *  Comments:
2561  *  --------
2562  * 
2563  *************************************<->***********************************/
2564
2565 Boolean ExpandVirtualSpace (IconBoxData *pIBD, int newWidth, int newHeight)
2566 {
2567     Boolean rval = True;
2568     int newSize;
2569     int increment;
2570
2571     newSize = (newWidth / pIBD->pCD_iconBox->widthInc) *
2572                 (newHeight / pIBD->pCD_iconBox->heightInc);
2573
2574     if (newSize > pIBD->IPD.totalPlaces )
2575     {
2576         increment = newSize - pIBD->IPD.totalPlaces;
2577         rval = ExtendIconList (pIBD, increment);
2578     }
2579
2580     return (rval);
2581
2582 } /* END OF FUNCTION ExpandVirtualSpace */
2583
2584
2585 \f
2586 /*************************************<->*************************************
2587  *
2588  *  ExtendIconList (pIBD, incr);
2589  *
2590  *
2591  *  Description:
2592  *  -----------
2593  *  Add space to the icon list
2594  *
2595  *
2596  *  Inputs:
2597  *  ------
2598  *  pIBD        - ptr to icon box data
2599  *  incr        - number of cells to add
2600  *
2601  * 
2602  *  Outputs:
2603  *  -------
2604  *  Return      - True if successful, False otherwise
2605  *
2606  *  Comments:
2607  *  --------
2608  * 
2609  *************************************<->***********************************/
2610
2611 Boolean ExtendIconList (IconBoxData *pIBD, int incr)
2612 {
2613     Boolean rval;
2614     int newSize;
2615     IconInfo *pTmp;
2616
2617     newSize = pIBD->IPD.totalPlaces + incr;
2618
2619     if ((pTmp = (IconInfo *) XtMalloc (newSize*sizeof(IconInfo))) != NULL)
2620     {
2621         /* copy data */
2622         memcpy (pTmp, pIBD->IPD.placeList, 
2623             pIBD->IPD.totalPlaces*sizeof(IconInfo));
2624         memset (&pTmp[pIBD->IPD.totalPlaces], 0, incr*sizeof(IconInfo));
2625
2626         /* out with the old, in with the new */
2627         XtFree ((char *)pIBD->IPD.placeList);
2628         pIBD->IPD.placeList = pTmp;
2629         pIBD->IPD.totalPlaces = newSize;
2630         rval = True;
2631     }
2632     else
2633     {
2634         rval = False;
2635     }
2636
2637     return (rval);
2638 } /* END OF FUNCTION ExtendIconList */
2639
2640
2641 \f
2642 /*************************************<->*************************************
2643  *
2644  *  PackIconBox(pIBD, packVert, packHorz, passedInWidth, passedInHeight)
2645  *
2646  *
2647  *  Description:
2648  *  -----------
2649  *  Packs the icons in the icon box
2650  *
2651  *
2652  *  Inputs:
2653  *  ------
2654  *  pIBD        - pointer to icon box data
2655  *
2656  * 
2657  *  Outputs:
2658  *  -------
2659  *
2660  *
2661  *  Comments:
2662  *  --------
2663  * 
2664  *************************************<->***********************************/
2665 void PackIconBox (IconBoxData *pIBD, Boolean packVert, Boolean packHorz, int passedInWidth, int passedInHeight)
2666 {
2667     IconInfo *pII_2, *pII_1;
2668     int ix1, ix2;
2669     int count;
2670     int newX, newY;
2671     ClientData *pCD_tmp = NULL, *pMyCD;
2672     int hasActiveText = 1;
2673     Arg args[4];
2674     Dimension majorDimension, minorDimension;
2675     Dimension oldWidth, oldHeight;
2676     int newWidth, newHeight;
2677     int i;
2678     Boolean rippling = False;
2679     WsClientData *pWsc;
2680     WmWorkspaceData *pWS;
2681
2682     i = 0;
2683     XtSetArg (args[i], XmNwidth, (XtArgVal) &oldWidth ); i++;
2684     XtSetArg (args[i], XmNheight, (XtArgVal) &oldHeight ); i++;
2685     XtGetValues (pIBD->bBoardWidget, args, i);
2686
2687     /*
2688      * packing to visual space, first update IconBoxData
2689      */
2690
2691     i = 0;
2692
2693     if (pIBD->IPD.iconPlacement & ICON_PLACE_LEFT_PRIMARY)
2694     {
2695         XtSetArg (args[i], XmNwidth, (XtArgVal) &majorDimension ); i++;
2696         XtSetArg (args[i], XmNheight, (XtArgVal) &minorDimension ); i++;
2697         XtGetValues (pIBD->clipWidget, args, i);
2698         if (packVert)
2699         {
2700             majorDimension = passedInWidth;
2701         }
2702         
2703         minorDimension /= (Dimension) pIBD->pCD_iconBox->heightInc;
2704         majorDimension /= (Dimension) pIBD->pCD_iconBox->widthInc;
2705         if (majorDimension != pIBD->IPD.placementCols)
2706         {
2707             pIBD->IPD.placementCols = majorDimension;
2708         }
2709     }
2710     else
2711     {
2712         XtSetArg (args[i], XmNheight, (XtArgVal) &majorDimension ); i++;
2713         XtSetArg (args[i], XmNwidth, (XtArgVal) &minorDimension ); i++;
2714         XtGetValues (pIBD->clipWidget, args, i);
2715         if (packHorz)
2716         {
2717             majorDimension = passedInHeight;
2718         }
2719
2720         minorDimension /= (Dimension) pIBD->pCD_iconBox->widthInc;
2721         majorDimension /= (Dimension) pIBD->pCD_iconBox->heightInc;
2722         if (majorDimension != pIBD->IPD.placementRows)
2723         {
2724             pIBD->IPD.placementRows = majorDimension;
2725         }
2726     }
2727
2728     /* 
2729      * find context of the activeIconTextWin to get pCD and then 
2730      * if it is the same as this client, hide it.
2731      */
2732
2733     pMyCD = pIBD->pCD_iconBox;
2734     if (ICON_DECORATION(pMyCD) & ICON_ACTIVE_LABEL_PART)
2735     {
2736         if (XFindContext (DISPLAY, pMyCD->pSD->activeIconTextWin,
2737                         wmGD.windowContextType, (caddr_t *)&pCD_tmp))
2738         {
2739             hasActiveText = 0;
2740         }
2741     }
2742
2743     pII_2 = pII_1 = pIBD->IPD.placeList;
2744     ix1 = ix2 = 0;
2745     count = pIBD->IPD.totalPlaces;
2746
2747     while (ix1 < count)
2748     {
2749         if (!rippling && (pII_2->pCD != NULL))
2750         {
2751             /* 
2752              * We need to start rippling the icons into new positions if
2753              * their (x,y) position changed 
2754              */
2755             pWS = GetWorkspaceData (pII_2->pCD->pSD, pIBD->wsID);
2756             pWsc = GetWsClientData (pWS, pII_2->pCD);
2757             CvtIconPlaceToPosition (&pIBD->IPD, pWsc->iconPlace,
2758                 &newX, &newY);
2759
2760             rippling = ((newX != pWsc->iconX) ||
2761                         (newY != pWsc->iconY));
2762         }
2763
2764         if ((pII_2->pCD == NULL) || rippling)
2765         {
2766             /* find next one to move */
2767             while ((ix1 < count) && (pII_1->pCD == NULL))
2768             {
2769                 ix1++;
2770                 pII_1++;
2771             }
2772
2773             if ((ix1 < count) && (pII_1->pCD != NULL))
2774             {
2775                 if (ix1 != ix2)
2776                 {
2777                     MoveIconInfo (&pIBD->IPD, ix1, ix2);
2778                 }
2779
2780                 CvtIconPlaceToPosition (&pIBD->IPD, ix2, &newX, &newY);
2781
2782                 pWS = GetWorkspaceData (pII_2->pCD->pSD, pIBD->wsID);
2783                 pWsc = GetWsClientData (pWS, pII_2->pCD);
2784                 pWsc->iconX = newX;
2785                 pWsc->iconY = newY;
2786
2787                 if (hasActiveText && (pII_2->pCD == pCD_tmp))
2788                 {
2789                     /* hide activeIconTextWin first */
2790                     HideActiveIconText ((WmScreenData *)NULL);
2791                     XtMoveWidget (pII_2->theWidget, newX, newY);
2792                     ShowActiveIconText (pII_2->pCD);
2793                 }
2794                 else
2795                 {
2796                     XtMoveWidget (pII_2->theWidget, newX, newY);
2797                 }
2798             }
2799         }
2800
2801         if (ix1 < count)
2802         {
2803             ix2++;
2804             pII_2++;
2805         }
2806
2807         ix1++;
2808         pII_1++;
2809     }
2810
2811     /* update last row and col */
2812
2813     SetNewBounds (pIBD);
2814
2815     /* resize Bulletin board  (so scroll bars show correctly */
2816     i = 0;
2817     if (pIBD->IPD.iconPlacement & ICON_PLACE_LEFT_PRIMARY)
2818     {
2819         if (majorDimension <= (Dimension) (pIBD->lastCol + 1))
2820         {
2821             newWidth = (pIBD->lastCol + 1) * pIBD->pCD_iconBox->widthInc;    
2822             XtSetArg (args[i], XmNwidth, (XtArgVal) newWidth); i++;
2823         }
2824         else
2825         {
2826             newWidth = oldWidth;
2827         }
2828
2829         if (minorDimension <= (Dimension) (pIBD->lastRow + 1))
2830         {
2831             /* set height of bboard */
2832             newHeight = (pIBD->lastRow + 1) * pIBD->pCD_iconBox->heightInc;
2833             XtSetArg (args[i], XmNheight, (XtArgVal) newHeight ); i++;
2834         }
2835         else
2836         {
2837             newHeight = minorDimension * pIBD->pCD_iconBox->heightInc;
2838             XtSetArg (args[i], XmNheight, (XtArgVal) newHeight ); i++;
2839         }
2840     }
2841     else
2842     {
2843         if (majorDimension <= (Dimension) (pIBD->lastRow + 1))
2844         {
2845             newHeight = (pIBD->lastRow + 1) * pIBD->pCD_iconBox->heightInc;
2846             XtSetArg (args[i], XmNheight, (XtArgVal) newHeight ); i++;
2847         }
2848         else
2849         {
2850             newHeight = oldHeight;
2851         }
2852
2853         if (minorDimension <= (Dimension) (pIBD->lastCol + 1))
2854         {
2855             /* set width of bboard */
2856             newWidth = (pIBD->lastCol + 1) * pIBD->pCD_iconBox->widthInc;    
2857             XtSetArg (args[i], XmNwidth, (XtArgVal) newWidth); i++;
2858         }
2859         else
2860         {
2861             newWidth = minorDimension * pIBD->pCD_iconBox->widthInc;    
2862             XtSetArg (args[i], XmNwidth, (XtArgVal) newWidth); i++;
2863         }
2864     }
2865
2866     if (i > 0  &&  ExpandVirtualSpace(pIBD, newWidth, newHeight))
2867     {
2868         XtSetValues (pIBD->bBoardWidget, args, i);
2869     }
2870
2871
2872     /* reset max size for icon box */
2873
2874     ResetIconBoxMaxSize (pIBD->pCD_iconBox, pIBD->bBoardWidget);
2875     
2876     ResetArrowButtonIncrements (pIBD->pCD_iconBox);    
2877
2878 } /* END FUNCTION PackIconBox */
2879
2880 \f
2881 /*************************************<->*************************************
2882  *
2883  *  RealignIconList (pIBD, newRows, newCols)
2884  *
2885  *
2886  *  Description:
2887  *  -----------
2888  *  Realigns the icon list according to the new virtual space dimensions 
2889  *
2890  *
2891  *  Inputs:
2892  *  ------
2893  *  pIBD        - ptr to icon box data
2894  *  newRows     - new number of rows
2895  *  newCols     - new number of columns
2896  *
2897  * 
2898  *  Outputs:
2899  *  -------
2900  *
2901  *  Comments:
2902  *  --------
2903  *  o The placement data structure contains the old values.
2904  * 
2905  *************************************<->***********************************/
2906
2907 void RealignIconList (IconBoxData *pIBD, int newCols, int newRows)
2908 {
2909     int c1, c2, ix1, ix2;
2910     int oldRows, oldCols;
2911     IconPlacementData  ipdNew;
2912     IconInfo *pII;
2913
2914     /* 
2915      * create new icon placement data for ease of calling conversion 
2916      * routines.
2917      */
2918     ipdNew.onRootWindow = pIBD->IPD.onRootWindow;
2919     ipdNew.iconPlacement = pIBD->IPD.iconPlacement;
2920     ipdNew.placementRows = newRows;
2921     ipdNew.placementCols = newCols;
2922     ipdNew.iPlaceW = pIBD->IPD.iPlaceW;
2923     ipdNew.iPlaceH = pIBD->IPD.iPlaceH;
2924     ipdNew.placeList = pIBD->IPD.placeList;
2925     ipdNew.totalPlaces = pIBD->IPD.totalPlaces;
2926
2927     oldRows = pIBD->IPD.placementRows;
2928     oldCols = pIBD->IPD.placementCols;
2929
2930     /*
2931      * Use the new organization and placement discipline to
2932      * determine how to move the icon info data around.
2933      */
2934     if (((oldRows < newRows) && 
2935          (pIBD->IPD.iconPlacement & ICON_PLACE_TOP_PRIMARY)) ||
2936         ((oldCols < newCols) && 
2937          (pIBD->IPD.iconPlacement & ICON_PLACE_LEFT_PRIMARY)))
2938     { 
2939     /* 
2940      * work backwards 
2941      */
2942         for (ix1 = pIBD->IPD.totalPlaces - 1, 
2943                  pII = &pIBD->IPD.placeList[ix1]; ix1 >= 0; ix1--, pII--)
2944         {
2945             if (pII->pCD != NULL)
2946             {
2947                 CvtIconPlaceToPosition (&pIBD->IPD, ix1, &c1, &c2);
2948                 ix2 = CvtIconPositionToPlace (&ipdNew, c1, c2);
2949                 if (ix1 != ix2)
2950                 { 
2951                     MoveIconInfo (&pIBD->IPD, ix1, ix2);
2952                 } 
2953             }
2954         }
2955     }
2956     else 
2957     if (((oldRows > newRows) && 
2958          (pIBD->IPD.iconPlacement & ICON_PLACE_TOP_PRIMARY)) ||
2959         ((oldCols > newCols) && 
2960          (pIBD->IPD.iconPlacement & ICON_PLACE_LEFT_PRIMARY)))
2961     {
2962         /* 
2963          * work forwards 
2964          */
2965         for (ix1 = 0, pII = &pIBD->IPD.placeList[ix1]; 
2966                 ix1 < pIBD->IPD.totalPlaces; ix1++, pII++)
2967         {
2968             if (pII->pCD != NULL)
2969             {
2970                 CvtIconPlaceToPosition (&pIBD->IPD, ix1, &c1, &c2);
2971                 ix2 = CvtIconPositionToPlace (&ipdNew, c1, c2);
2972                 if (ix1 != ix2)
2973                 {
2974                     MoveIconInfo (&pIBD->IPD, ix1, ix2);
2975                 }
2976             }
2977         }
2978     }
2979
2980     /* 
2981      * update info in placement structure to reflect new reality
2982      */
2983     pIBD->IPD.placementRows = newRows;
2984     pIBD->IPD.placementCols = newCols;
2985
2986 } /* END OF FUNCTION RealignIconList */
2987
2988
2989
2990 \f
2991 /*************************************<->*************************************
2992  *
2993  *  SetNewBounds (pIBD)
2994  *
2995  *
2996  *  Description:
2997  *  -----------
2998  *
2999  *
3000  *  Inputs:
3001  *  ------
3002  *
3003  * 
3004  *  Outputs:
3005  *  -------
3006  *
3007  *  Comments:
3008  *  --------
3009  * 
3010  *************************************<->***********************************/
3011
3012 void SetNewBounds (IconBoxData *pIBD)
3013 {
3014
3015     int i;
3016     int X = 0;
3017     int Y = 0; 
3018     CompositeWidget cw;
3019     WidgetList      children;
3020
3021     cw = (CompositeWidget) pIBD->bBoardWidget;
3022     children = cw->composite.children;
3023
3024     for (i = 0; i < cw->composite.num_children; i++)
3025     {
3026         if (children[i]->core.x > X)
3027         {
3028             X = children[i]->core.x;
3029         }
3030         if (children[i]->core.y > Y)
3031         {
3032             Y = children[i]->core.y;
3033         }
3034     }
3035
3036     pIBD->lastCol = X / pIBD->pCD_iconBox->widthInc;
3037     pIBD->lastRow = Y / pIBD->pCD_iconBox->heightInc;
3038
3039 } /* END OF FUNCTION SetNewBounds */
3040
3041
3042 \f
3043 /*************************************<->*************************************
3044  *
3045  *  InsertPosition (w)
3046  *
3047  *
3048  *  Description:
3049  *  -----------
3050  *  This procedure is passed to the bulletin board at create time
3051  *  to be used when a child is inserted into the bulletin board
3052  *  
3053  *
3054  *************************************<->***********************************/
3055 Cardinal InsertPosition (Widget w)
3056 {
3057     return (insertPosition);
3058
3059 } /* END OF FUNCTION InsertPosition */
3060
3061
3062 \f
3063 /*************************************<->*************************************
3064  *
3065  *  ShowClientIconState ();
3066  *
3067  *
3068  *  Description:
3069  *  -----------
3070  *  XXDescription ...
3071  *
3072  *************************************<->***********************************/
3073
3074 void ShowClientIconState (ClientData *pCD, int newState)
3075 {
3076
3077     /*
3078      * Changing the appearance of an icon window in the box to 
3079      * reflect the client's state
3080      */
3081
3082     if ((newState == MINIMIZED_STATE) && (pCD->iconWindow))
3083         XMapRaised (DISPLAY, pCD->iconWindow);
3084
3085     if (((newState == NORMAL_STATE) || (newState == MAXIMIZED_STATE )) 
3086                                                 && (pCD->iconWindow))
3087     {
3088         XUnmapWindow (DISPLAY, pCD->iconWindow);
3089     }
3090
3091 } /* END FUNCTION ShowClientIconState */
3092
3093
3094 /*************************************<->*************************************
3095  *
3096  *  IconScrollVisibleCallback
3097  *
3098  *
3099  *  Description:
3100  *  -----------
3101  *  for each icon in the icon box
3102  * 
3103  *************************************<->***********************************/
3104
3105 void IconScrollVisibleCallback (Widget w, caddr_t client_data, XmAnyCallbackStruct *call_data)
3106 {
3107     XmTraverseObscuredCallbackStruct *vis_data;
3108
3109     vis_data = (XmTraverseObscuredCallbackStruct *) call_data;
3110
3111     XmScrollVisible(ACTIVE_WS->pIconBox->scrolledWidget,
3112                     vis_data->traversal_destination,
3113                     0,0);
3114 /*
3115                     IB_MARGIN_WIDTH, IB_MARGIN_HEIGHT);
3116 */
3117 } /* END OF FUNCTION IconScrollVisibleCallback */
3118
3119
3120 /*************************************<->*************************************
3121  *
3122  *  IconActivateCallback
3123  *
3124  *
3125  *  Description:
3126  *  -----------
3127  *  for each icon in the icon box
3128  * 
3129  *************************************<->***********************************/
3130
3131 void IconActivateCallback (Widget w, caddr_t client_data, XmAnyCallbackStruct *call_data)
3132 {
3133     ClientData          *pCD;
3134     Window              theIcon;
3135
3136     theIcon = XtWindow(w);
3137
3138     /* 
3139      * find context to get pCD and then carry out
3140      * default action.
3141      */
3142
3143     if (!(XFindContext (DISPLAY, theIcon,
3144                         wmGD.windowContextType, (caddr_t *)&pCD)))
3145     {
3146         F_Restore_And_Raise ((String)NULL, pCD, (XEvent *)NULL );
3147 /*      F_Normalize_And_Raise ((String)NULL, pCD, (XEvent *)NULL );
3148 */    }
3149
3150 } /* END OF FUNCTION IconActivateCallback */
3151
3152
3153 \f
3154 /*************************************<->*************************************
3155  *
3156  *  UpdateIncrements
3157  *
3158  *
3159  *  Description:
3160  *  -----------
3161  *  XXDescription ...
3162  * 
3163  *************************************<->***********************************/
3164
3165 void UpdateIncrements (Widget sWidget, IconBoxData *pIBD, XConfigureEvent *event)
3166 {
3167     ResetArrowButtonIncrements (pIBD->pCD_iconBox);    
3168   
3169 } /* END OF FUNCTION UpdateIncrements */
3170
3171 \f
3172 /*************************************<->*************************************
3173  *
3174  *  ResetArrowButtonIncrements(pCD)
3175  *
3176  *************************************<->***********************************/
3177
3178 void ResetArrowButtonIncrements (ClientData *pCD)
3179 {
3180     int i;
3181     Arg setArgs[2]; 
3182         
3183     i=0;
3184     XtSetArg (setArgs[i], XmNincrement, (XtArgVal) pCD->heightInc); i++;    
3185     XtSetValues (pCD->thisIconBox->vScrollBar, (ArgList) setArgs, i); 
3186
3187     i=0;
3188     XtSetArg (setArgs[i], XmNincrement, (XtArgVal) pCD->widthInc); i++;    
3189     XtSetValues (pCD->thisIconBox->hScrollBar, (ArgList) setArgs, i);     
3190     
3191 } /* END OF FUNCTION ResetArrowButtonIncrements */    
3192
3193
3194 \f
3195 /*************************************<->*************************************
3196  *
3197  *  ChangeActiveIconboxIconText
3198  *
3199  *
3200  *  Description:
3201  *  -----------
3202  *  XXDescription ...
3203  * 
3204  *************************************<->***********************************/
3205
3206 void ChangeActiveIconboxIconText (Widget icon, caddr_t dummy, XFocusChangeEvent *event)
3207 {
3208
3209     ClientData          *pCD;
3210     Window              theIcon;
3211
3212     /* 
3213      * find context to get pCD and then hide or show active icon text. 
3214      * Show/hide the active icon text only if the icon box is not 
3215      * iconified.
3216      */
3217
3218     theIcon = XtWindow(icon);
3219
3220     if (!(XFindContext (DISPLAY, theIcon,
3221                         wmGD.windowContextType, (caddr_t *)&pCD)) &&
3222         P_ICON_BOX(pCD) &&
3223         P_ICON_BOX(pCD)->pCD_iconBox &&
3224         P_ICON_BOX(pCD)->pCD_iconBox->clientState !=  MINIMIZED_STATE)
3225     {
3226         if (event->type == FocusIn) 
3227         {
3228             if (event->send_event)
3229             {
3230                ShowActiveIconText (pCD);
3231             }
3232         }
3233         else
3234         {
3235             if (event->send_event)
3236             {
3237                 HideActiveIconText (pCD->pSD);
3238             }
3239         }
3240     }
3241
3242 } /* END OF FUNCTION ChangeActiveIconboxIconText */
3243
3244
3245 \f
3246 /*************************************<->*************************************
3247  *
3248  *  HandleIconBoxIconKeyPress
3249  *
3250  *
3251  *  Description:
3252  *  -----------
3253  *  This event handler catches keyevents for icons in the icon box and
3254  *  passes them on to the standard key handling routine for mwm.
3255  *
3256  *************************************<->***********************************/
3257
3258 void HandleIconBoxIconKeyPress (Widget icon, caddr_t dummy, XKeyEvent *keyEvent)
3259 {
3260     
3261     Context context; 
3262     ClientData          *pCD; 
3263     Window              theIcon;
3264
3265     /*
3266      * find context to get pCD and then post menu show active icon text.
3267      */
3268     
3269     theIcon = XtWindow(icon);
3270     if (!(XFindContext (DISPLAY, theIcon,
3271                         wmGD.windowContextType, (caddr_t *)&pCD)))
3272     {
3273         SetClientWsIndex (pCD);
3274         keyEvent->window = ICON_FRAME_WIN(pCD);
3275
3276         if (pCD->clientState == MINIMIZED_STATE)
3277         {
3278             context = F_SUBCONTEXT_IB_IICON;
3279             pCD->grabContext = F_SUBCONTEXT_IB_IICON;
3280         }
3281         else
3282         {
3283             context = F_SUBCONTEXT_IB_WICON;
3284             pCD->grabContext = F_SUBCONTEXT_IB_WICON;
3285         }
3286         
3287         if(!(HandleKeyPress (keyEvent, ACTIVE_PSD->keySpecs, 
3288                         True, context, False, pCD)))
3289         {
3290             keyEvent->window = 0;
3291             keyEvent->type = 0;
3292         }
3293
3294     }
3295         
3296 } /* END OF FUNCTION HandleIconBoxIconKeyPress */
3297
3298 \f
3299 /*************************************<->*************************************
3300  *
3301  *  HandleIconBoxButtonMotion
3302  *
3303  *
3304  *  Description:
3305  *  -----------
3306  *  Event handler for button motion events on icon frame window in 
3307  *  in icon box.
3308  *
3309  *
3310  *  Inputs:
3311  *  ------
3312  *  icon                - widget for icon frame 
3313  *  client_data         - extra client data
3314  *  pev                 - ptr to event
3315  *
3316  * 
3317  *  Outputs:
3318  *  -------
3319  *
3320  *
3321  *  Comments:
3322  *  --------
3323  *  o This is added to make sure that ButtonXMotion gets added to the 
3324  *    event mask for icons in the icon box.
3325  * 
3326  *************************************<->***********************************/
3327
3328 void HandleIconBoxButtonMotion (Widget icon, caddr_t client_data, XEvent *pev)
3329 {
3330
3331 } /* END OF FUNCTION HandleIconBoxButtonMotion */
3332
3333
3334 \f
3335 /*************************************<->*************************************
3336  *
3337  *  GetIconBoxIconRootXY (pCD, pX, pY)
3338  *
3339  *
3340  *  Description:
3341  *  -----------
3342  *
3343  *
3344  *  Inputs:
3345  *  ------
3346  *  pCD         - pointer to client data
3347  *  pX          - pointer to X return value
3348  *  pY          - pointer to Y return value
3349  *
3350  *  Outputs:
3351  *  -------
3352  *
3353  *
3354  *  Comments:
3355  *  --------
3356  *  o returns root-window coords
3357  *
3358  *************************************<->***********************************/
3359 void GetIconBoxIconRootXY (ClientData *pCD, int *pX, int *pY)
3360 {
3361
3362     Window child;
3363     WsClientData *pWsc = GetWsClientData (pCD->pSD->pActiveWS, pCD);
3364
3365     if (pCD->pSD->useIconBox && pWsc->pIconBox)
3366     {
3367         XTranslateCoordinates(DISPLAY,
3368                               XtWindow(pWsc->pIconBox->bBoardWidget),
3369                               ROOT_FOR_CLIENT(pCD),
3370                               pWsc->iconX + IB_MARGIN_WIDTH,
3371                               pWsc->iconY + IB_MARGIN_HEIGHT,
3372                               pX, pY, &child);
3373     }
3374     else
3375     {
3376         *pX = *pY = 0;
3377     }
3378 } /* END FUNCTION GetIconBoxIconRootXY */
3379
3380 \f
3381 /*************************************<->*************************************
3382  *
3383  *  IconVisible (pCD)
3384  *
3385  *
3386  *  Description:
3387  *  -----------
3388  *
3389  *  Inputs:
3390  *  ------
3391  *  pCD         - pointer to client data
3392  *
3393  *  Outputs:
3394  *  -------
3395  *
3396  *
3397  *  Comments:
3398  *  --------
3399  *
3400  *************************************<->***********************************/
3401 Boolean IconVisible (ClientData *pCD)
3402 {
3403
3404     /*
3405      * May use icon->core.visible field if that gets fixed and
3406      * we want to accept the Intrinsics idea of what is visible.
3407      */
3408
3409     Boolean rval = True;
3410     WsClientData *pWsc = GetWsClientData (pCD->pSD->pActiveWS, pCD);
3411
3412
3413     
3414     int i;
3415     Arg getArgs[5];
3416
3417     Dimension tmpWidth = 0;
3418     Dimension tmpHeight = 0;
3419     Position clipX = 0;
3420     Position clipY = 0;
3421     Position tmpX = 0;
3422     Position tmpY = 0;
3423     int iconX, iconY;
3424
3425     i=0;
3426     XtSetArg (getArgs[i], XmNwidth, (XtArgVal) &tmpWidth ); i++;
3427     XtSetArg (getArgs[i], XmNheight, (XtArgVal) &tmpHeight ); i++;
3428     XtSetArg (getArgs[i], XmNx, (XtArgVal) &tmpX ); i++;
3429     XtSetArg (getArgs[i], XmNy, (XtArgVal) &tmpY ); i++;
3430     XtGetValues (pWsc->pIconBox->clipWidget, getArgs, i);
3431     XtTranslateCoords(pWsc->pIconBox->scrolledWidget,
3432                         tmpX, tmpY,
3433                         &clipX, &clipY);
3434
3435     GetIconBoxIconRootXY(pCD, &iconX, &iconY);
3436
3437
3438     /* 
3439      * demand at least 2 pixels of the 
3440      * real icon (not drawnButton) be showing 
3441      */
3442        
3443     if (iconX + 2 > ((int)clipX + (int)tmpWidth))
3444     {
3445         return(False);
3446     }
3447     if (iconY + 2 > ((int)clipY + (int)tmpHeight))
3448     {
3449         return(False);
3450     }
3451
3452     if ((iconX + (ICON_WIDTH(pCD) -2)) < (int)clipX)
3453     {
3454         return(False);
3455     }
3456     if ((iconY + (ICON_HEIGHT(pCD) -2)) < (int)clipY)
3457     {
3458         return(False);
3459     }
3460
3461     return(rval);
3462
3463 } /* END OF FUNCTION IconVisible */
3464 \f
3465 /*************************************<->*************************************
3466  *
3467  *  WmXmStringToString (xmString
3468  *
3469  *
3470  *  Description:
3471  *  -----------
3472  *
3473  *
3474  *  Inputs:
3475  *  ------
3476  *
3477  *  Outputs:
3478  *  -------
3479  *
3480  *
3481  *  Comments:
3482  *  --------
3483  *  Return the ascii part of the first segment of an XmString 
3484  *  If xmString is NULL, then do nothing 
3485  *
3486  *************************************<->***********************************/
3487
3488 String WmXmStringToString (XmString xmString)
3489
3490     XmStringContext       xmStrContext;
3491     char                 *asciiString = NULL; 
3492     XmStringCharSet      ibTitleCharset; 
3493     XmStringDirection    ibTitleDirection; 
3494     Boolean              separator; 
3495     
3496     if (xmString)
3497     {
3498         XmStringInitContext (&xmStrContext, xmString);
3499     
3500         XmStringGetNextSegment (xmStrContext, &asciiString, 
3501                                 &ibTitleCharset, &ibTitleDirection, 
3502                                 &separator);
3503
3504         if (ibTitleCharset != NULL) 
3505         {
3506             XtFree ((char *)ibTitleCharset);
3507         }
3508
3509         XmStringFreeContext (xmStrContext);
3510     }
3511     
3512     return(asciiString);
3513     
3514 } /* END OF FUNCTION WmXmStringToString */