1 /*
2  * Motif
3  *
4  * Copyright (c) 1987-2012, The Open Group. All rights reserved.
5  *
6  * These libraries and programs are free software; you can
7  * redistribute them and/or modify them under the terms of the GNU
8  * Lesser General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * These libraries and programs are distributed in the hope that
13  * they will be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these librararies and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 
24 #ifdef HAVE_CONFIG_H
25 #include <config.h>
26 #endif
27 
28 
29 #include <Xm/Xm.h>
30 #include <Xm/ScrollBarP.h>
31 #include "./WmWsmLib/utm_send.h"
32 #include "./WmWsmLib/wsm_proto.h"
33 #include "WmGlobal.h"
34 #include "WmFunction.h"
35 #include "WmCmd.h"
36 #include "WmMenu.h"
37 #include "WmResParse.h"
38 #include "WmWsm.h"
39 #include "WmDebug.h"
40 #include "WmWinConf.h"
41 #include "WmFeedback.h"
42 
43 
44 
45 #define MAX_CLIENT_CMDS 1000
46 
47 
48 
49 
50 
51 static CARD32 cmdKillList[MAX_CLIENT_CMDS];
52 static unsigned long cmdKillListIndex;
53 
54 #define ScrNum(w) (XScreenNumberOfScreen(XtScreen(w)))
55 #define CCI_TREE(w) (wmGD.Screens[ScrNum(w)].cciTree)
56 #define CCI_TREE_OF_SCR(scr) (wmGD.Screens[(scr)].cciTree)
57 
58 
59 
60 
61 /*----------------------------------------------------------------------*
62  |                              NewCommand                              |
63  *----------------------------------------------------------------------*/
64 CmdTree *
NewCommand(CARD32 commandID,CARD32 notifyWindow,char * name,char * defaultName)65 NewCommand (
66      CARD32  commandID,
67      CARD32  notifyWindow,
68      char   *name,
69      char   *defaultName)
70 
71 {
72   CmdTree *ptr = (CmdTree *) XtMalloc(sizeof(CmdTree));
73 
74   ptr->commandID    = commandID;
75   ptr->notifyWindow = notifyWindow;
76 
77   if (name != NULL) ptr->name = XtNewString(name);
78   else              ptr->name = XtNewString("");
79 
80   if (defaultName != NULL) ptr->defaultName = XtNewString(defaultName);
81   else                     ptr->defaultName = NULL;
82 
83   ptr->subTrees = NULL;
84 
85   ptr->next     = NULL;
86 
87   return(ptr);
88 }
89 
90 /*---------------------------------------------------------------------------*
91  |                                  FindCmd                                  |
92  *---------------------------------------------------------------------------*/
93 CmdTree *
FindCmd(CARD32 commandID,CmdTree * menuTree)94 FindCmd(
95      CARD32    commandID,
96      CmdTree  *menuTree)
97 {
98   CmdTree *pCmd;
99 
100   if (menuTree != NULL) PRINT("-> %s\n", menuTree->name);
101 
102   if (menuTree == NULL)
103     {
104       PRINT("<- NULL\n");
105       return(NULL);
106     }
107 
108   if (menuTree->commandID == commandID)
109     {
110       PRINT("<- %d, %s\n", commandID, menuTree->name);
111       return(menuTree);
112     }
113 
114   if ((pCmd = FindCmd(commandID, menuTree->next)) != NULL)
115     return(pCmd);
116 
117   return(FindCmd(commandID, menuTree->subTrees));
118 }
119 
120 /*---------------------------------------------------------------------------*
121  |                             FindDuplicateName                             |
122  | Scan through commandTree for another defined command with the same name.  |
123  | Once found, return the ID of the duplicate.  Note that at most one match  |
124  | can be found. If no match is found, 0 is returned.  This should NEVER be  |
125  | the value of a command defined by a client.                               |
126  *---------------------------------------------------------------------------*/
127 CARD32
FindDuplicateName(CmdTree * menuTree,char * name)128 FindDuplicateName(
129      CmdTree  *menuTree,
130      char     *name)
131 {
132   CmdTree *tmp;
133   CARD32  duplicateID;
134 
135   if (menuTree == NULL)
136     return(0);
137 
138   else if ((menuTree->name != NULL) && (strcmp(menuTree->name, name) == 0))
139     return(menuTree->commandID);
140 
141   else if ((duplicateID = FindDuplicateName(menuTree->subTrees, name)) != 0)
142     return(duplicateID);
143 
144   else
145     return(FindDuplicateName(menuTree->next, name));
146 }
147 
148 
149 /*----------------------------------------------------------------------*
150  |                              AddCommand                              |
151  | Returns true if the commandSet was found and a new command was added.|
152  | Note that toplevel commands have 0 as their commandSet.  This will   |
153  | always match the top entry in the command tree since it is 0.        |
154  *----------------------------------------------------------------------*/
155 Boolean
AddCommand(int scr,CARD32 commandSet,CARD32 commandID,CARD32 notifyWindow,char * name,char * defaultName,CmdTree * ptr)156 AddCommand (
157      int      scr,
158      CARD32   commandSet,
159      CARD32   commandID,
160      CARD32   notifyWindow,
161      char    *name,
162      char    *defaultName,
163      CmdTree *ptr)
164 {
165   /*
166    *  For each subtree of the cmdtree, look for the commandset.
167    *  If found, add the element there else keep looking.
168    */
169 
170   CmdTree *tmp;
171   CARD32 duplicateID;
172 
173   if (ptr == NULL) return (False);
174 
175   else if (ptr->commandID == commandSet)
176     /* FOUND IT */
177     {
178       if ((duplicateID = FindDuplicateName(CCI_TREE_OF_SCR(scr), name)) != 0)
179 	{
180 	  /* a duplicate menu item already exists here, remove it first.
181 	   */
182 	  if (ptr->subTrees != NULL)
183 	    DestroyMenuSpec (&(wmGD.Screens[scr]), commandID);
184 	  DeleteCommand(commandID, &CCI_TREE_OF_SCR(scr));
185 	}
186 
187       tmp = ptr->subTrees;
188       ptr->subTrees = NewCommand(commandID, notifyWindow, name, defaultName);
189       ptr->subTrees->next = tmp;
190 
191       return(True);
192     }
193 
194   else
195     {
196       Boolean found;
197 
198       found = AddCommand(scr, commandSet, commandID, notifyWindow,
199 			 name, defaultName, ptr->next);
200       if (!found)
201 	found = AddCommand(scr, commandSet, commandID, notifyWindow,
202 			   name, defaultName, ptr->subTrees);
203 
204       return (found);
205     }
206 }
207 
208 
209 /*---------------------------------------------------------------------------*
210  |                          RemoveCommandBranch                              |
211  | This routine all commands at the specified node in the command tree.      |
212  *---------------------------------------------------------------------------*/
213 void
RemoveCommandBranch(CmdTree * menuTree)214 RemoveCommandBranch (CmdTree *menuTree)
215 {
216   CmdTree *tmp = menuTree;
217 
218   while (menuTree != NULL)
219     {
220       if (menuTree->subTrees != (CmdTree*)NULL)
221 	RemoveCommandBranch(menuTree->subTrees);
222 
223       menuTree = menuTree->next;
224       if (tmp->name != NULL)
225 	XtFree((char*)tmp->name);
226       XtFree((char*)tmp);
227     }
228 }
229 
230 
231 /*---------------------------------------------------------------------------*
232  |                              DeleteCommand                                |
233  | This routine deletes any matching command entries in the Command Tree.    |
234  *---------------------------------------------------------------------------*/
235 void
DeleteCommand(long commandID,CmdTree ** pmenuTree)236 DeleteCommand (
237      long      commandID,
238      CmdTree **pmenuTree)
239 {
240   if ((pmenuTree == NULL) || (*pmenuTree == NULL))
241     return;
242 
243   else
244     {
245       CmdTree *tmp  = *pmenuTree;
246       CmdTree *prev = NULL;
247 
248       while (tmp != (CmdTree *)NULL)
249 
250 	if (tmp->commandID == commandID)
251 	  {
252 	    RemoveCommandBranch(tmp->subTrees); /* remove all sub-commands. */
253 	    if (prev == (CmdTree *)NULL)
254 	      *pmenuTree = tmp->next;
255 	    else
256 	      prev->next = tmp->next;
257 
258 	    if (tmp->name != NULL)
259 	      XtFree((char*)tmp->name);
260 	    XtFree((char *)tmp);
261 	    tmp = prev;
262 	  }
263 
264 	else
265 	  {
266 	    if (tmp->subTrees != (CmdTree *)NULL)
267 	      DeleteCommand(commandID, &tmp->subTrees);
268 	    prev = tmp;
269 	    tmp = tmp->next;
270 	  }
271     }
272 }
273 
274 
275 /*----------------------------------------------------------------------*
276  |                            DefineCommand                             |
277  | hack version - restriction: no spaces allowed in names.              |
278  *----------------------------------------------------------------------*/
279 /*ARGSUSED*/
280 void
DefineCommand(Widget w,Atom target,MessageData data,unsigned long len,int fmt)281 DefineCommand (
282      Widget         w,
283      Atom           target,
284      MessageData    data,
285      unsigned long  len,
286      int            fmt)
287 {
288   CARD32  commandID, commandSet, selection, duplicateID;
289   String  name, defaultLabel;
290   Boolean found = False;
291   Window  owner;
292   XWindowAttributes attr;
293 
294   /*
295    * check data to make sure somethings there.
296    */
297   if ((data == NULL) || (len == 0))
298     {
299       PRINT("Bad data passed to DefineCommand.\n");
300       return;
301     }
302 
303   commandID    = UnpackCARD32(&data);
304   selection    = UnpackCARD32(&data); /* selection to use for invoke cmd */
305   commandSet   = UnpackCARD32(&data);
306   name         = UnpackString(&data);
307   defaultLabel = UnpackString(&data);
308 
309   PRINT("Define command: %d, %d, '%s', '%s'\n",
310 	commandID, commandSet, name, defaultLabel);
311 
312   /*
313    *  Add command to menu structure.
314    */
315 
316   if (CCI_TREE(w) == NULL)
317     {
318       CCI_TREE(w) = NewCommand(0, 0, NULL, NULL);
319     }
320 
321 
322   if (commandSet != 0)
323     {
324       found = AddCommand(ScrNum(w), commandSet, commandID, selection, name,
325 			 defaultLabel, CCI_TREE(w));
326     }
327   else
328     /*
329      * A leaf is being added to the command tree. There should not
330      * be any other entries with the same name since matching with
331      * the mwm resource file is done on names.  If a duplicate is
332      * found, remove it first and any menu spec if it is a command
333      * set.
334      */
335     if ((duplicateID = FindDuplicateName(CCI_TREE(w), name)) != 0)
336       {
337 	/* a duplicate menu item already exists here, remove it first.
338 	 */
339 	DestroyMenuSpec (&(wmGD.Screens[ScrNum(w)]), duplicateID);
340 	DeleteCommand(duplicateID, &CCI_TREE(w));
341       }
342 
343   if (!found || commandSet == 0)
344     {
345       CmdTree *tmp;
346 
347       tmp = NewCommand(commandID, selection, name, defaultLabel);
348       tmp->next = CCI_TREE(w)->next;
349       CCI_TREE(w)->next = tmp;
350     }
351 }
352 
353 
354 
355 /*----------------------------------------------------------------------*
356  |                            IncludeCommand                            |
357  *----------------------------------------------------------------------*/
358 /*ARGSUSED*/
359 void
IncludeCommand(Widget w,Atom target,MessageData data,unsigned long len,int fmt)360 IncludeCommand (
361      Widget         w,
362      Atom           target,
363      MessageData    data,
364      unsigned long  len,
365      int            fmt)
366 {
367   CARD32         inLine, commandID, selection, count;
368   Window        *windowIDs = NULL;
369   CmdTree       *tPtr, *pNext;
370   int            i, win;
371   unsigned long  activeContext = 0L;
372 
373   /*
374    * check data to make sure somethings there.
375    */
376   if ((data == NULL) || (len == 0))
377     {
378       PRINT("Bad data passed to IncludeCommand.\n");
379       return;
380     }
381 
382   inLine    = UnpackCARD32(&data);
383   commandID = UnpackCARD32(&data);
384   selection = UnpackCARD32(&data);
385   count     = UnpackCARD32(&data);
386 
387   if (count > 0) windowIDs = (Window *) XtMalloc(sizeof(Window)*count);
388   for (win=0; win<count; win++)
389   {
390       windowIDs[win] = UnpackCARD32(&data);
391       PRINT("Got window ID %d.\n", windowIDs[win]);
392   }
393 
394   /*
395    *  Insert on root menu
396    */
397   if ((windowIDs[0] & WINDOW_MASK) == 0L)
398     {
399       ShowWaitState (TRUE);
400 	tPtr = FindCmd (commandID, CCI_TREE(w));
401 	if (tPtr != NULL)
402 	{
403 	    activeContext = F_CONTEXT_ROOT;
404 	    pNext = tPtr->next;
405 	    tPtr->next = NULL;
406 	    InsertTreeOnRootMenu(ACTIVE_PSD, tPtr, selection, inLine);
407 	    tPtr->next = pNext;
408 	}
409       ShowWaitState (FALSE);
410     }
411 
412   /*
413    * Insert on all clients
414    */
415   else if ((windowIDs[0] & WINDOW_MASK) == ALL_WINDOWS)
416     {
417       tPtr = FindCmd (commandID, CCI_TREE(w));
418       if (tPtr != NULL)
419 	{
420 	  ShowWaitState (TRUE);
421 
422 	  activeContext = 0L;
423 	  if (windowIDs[0] &   ICON_ONLY) activeContext |= F_CONTEXT_ICON;
424 	  if (windowIDs[0] & WINDOW_ONLY) activeContext |= F_CONTEXT_WINDOW;
425 
426 	  pNext = tPtr->next;
427 	  tPtr->next = NULL;
428 	  InsertTreeOnAllClients (ACTIVE_PSD, tPtr, selection,
429 				  activeContext, inLine);
430 	  tPtr->next = pNext;
431 
432 	  PRINT("Inserted commandID %d on all windows.\n", commandID);
433 
434 	  ShowWaitState (FALSE);
435 	}
436       else
437 	PRINT("ERROR - commandID %d not found in command tree.\n", commandID);
438     }
439 
440   /*
441    * Insert on specified clients
442    */
443   else
444     {
445       tPtr = FindCmd (commandID, CCI_TREE(w));
446       if (tPtr != NULL)
447 	{
448 	  ShowWaitState (TRUE);
449 
450 	  for (i=0; i<count; i++)
451 	    {
452 	      ClientData *pCD;
453 
454 	      activeContext = 0L;
455 	      if (windowIDs[i] &   ICON_ONLY)
456 		activeContext |= F_CONTEXT_ICON;
457 	      if (windowIDs[i] & WINDOW_ONLY)
458 		activeContext |= F_CONTEXT_WINDOW;
459 	      pCD = GetPCD(ScrNum(w), windowIDs[i] & WINDOW_MASK);
460 	      if (pCD != NULL)
461 	      {
462 		  pNext = tPtr->next;
463 		  tPtr->next = NULL;
464 		  InsertTreeOnSingleClient (pCD->pSD, pCD, tPtr, selection,
465 					    activeContext, inLine);
466 		  tPtr->next = pNext;
467 	      }
468 	    }
469 
470 	  ShowWaitState (FALSE);
471 	}
472       else
473 	PRINT("ERROR - commandID %d not found in command tree.\n", commandID);
474     }
475 
476   if (count > 0)
477     XtFree((char*)windowIDs);
478 }
479 
480 
481 
482 /*----------------------------------------------------------------------*
483  |                             EnableCommand                            |
484  *----------------------------------------------------------------------*/
485 /*ARGSUSED*/
486 void
EnableCommand(Widget w,Atom target,MessageData data,unsigned long len,int fmt)487 EnableCommand (
488      Widget         w,
489      Atom           target,
490      MessageData    data,
491      unsigned long  len,
492      int            fmt)
493 {
494   CARD32         commandID, count;
495   Window        *windowIDs = NULL;
496   CmdTree       *tPtr, *pNext;
497   int            i, win;
498   unsigned long  activeContext = 0L;
499 
500   /*
501    * check data to make sure somethings there.
502    */
503   if ((data == NULL) || (len == 0))
504     {
505       PRINT("Bad data passed to EnableCommand.\n");
506       return;
507     }
508 
509   commandID = UnpackCARD32(&data);
510   count     = UnpackCARD32(&data);
511 
512   if (count > 0) windowIDs = (Window *) XtMalloc(sizeof(Window)*count);
513   for (win=0; win<count; win++)
514     {
515       windowIDs[win] = UnpackCARD32(&data);
516       PRINT("Got window ID %d.\n", windowIDs[win]);
517     }
518 
519   /*
520    *  Enable on root menu
521    */
522   if ((windowIDs[0] & WINDOW_MASK) == 0L)
523     {
524       tPtr = FindCmd (commandID, CCI_TREE(w));
525       if (tPtr != NULL)
526 	{
527 	  for (i=0; i<count; i++)
528 	  {
529 	      activeContext = F_CONTEXT_ROOT;
530 	      pNext = tPtr->next;
531 	      tPtr->next = NULL;
532 	      ModifyClientCommandTree (ACTIVE_PSD, NULL, ROOT, tPtr,
533 				       ENABLE, activeContext, NULL);
534 	      tPtr->next = pNext;
535 	  }
536 	}
537       else
538 	PRINT("ERROR - commandID %d not found in command tree.\n", commandID);
539     }
540 
541   /*
542    * Enable on all clients
543    */
544   else if ((windowIDs[0] & WINDOW_MASK) == ALL_WINDOWS)
545     {
546       tPtr = FindCmd (commandID, CCI_TREE(w));
547       if (tPtr != NULL)
548 	{
549 	  activeContext = 0L;
550 	  if (windowIDs[0] &   ICON_ONLY) activeContext |= F_CONTEXT_ICON;
551 	  if (windowIDs[0] & WINDOW_ONLY) activeContext |= F_CONTEXT_WINDOW;
552 
553 	  pNext = tPtr->next;
554 	  tPtr->next = NULL;
555 	  ModifyClientCommandTree (ACTIVE_PSD, NULL, ALL, tPtr, ENABLE,
556 				   activeContext, NULL);
557 	  tPtr->next = pNext;
558 
559 	  PRINT("Enabled commandID %d on all windows.\n", commandID);
560 	}
561       else
562 	PRINT("ERROR - commandID %d not found in command tree.\n", commandID);
563     }
564 
565   /*
566    * Enable on specified clients
567    */
568   else
569     {
570       tPtr = FindCmd (commandID, CCI_TREE(w));
571       if (tPtr != NULL)
572 	{
573 	  for (i=0; i<count; i++)
574 	    {
575 	      ClientData *pCD;
576 
577 	      activeContext = 0L;
578 	      if (windowIDs[i] &   ICON_ONLY)
579 		activeContext |= F_CONTEXT_ICON;
580 	      if (windowIDs[i] & WINDOW_ONLY)
581 		activeContext |= F_CONTEXT_WINDOW;
582 
583 	      pCD = GetPCD(ScrNum(w), windowIDs[i] & WINDOW_MASK);
584 	      if (pCD != NULL)
585 	      {
586 		  pNext = tPtr->next;
587 		  tPtr->next = NULL;
588 		  ModifyClientCommandTree (pCD->pSD, pCD, SINGLE, tPtr,
589 					   ENABLE, activeContext, NULL);
590 		  tPtr->next = pNext;
591 	      }
592 	    }
593 	}
594       else
595 	PRINT("ERROR - commandID %d not found in command tree.\n", commandID);
596     }
597 
598   if (count > 0)
599     XtFree((char*)windowIDs);
600 }
601 
602 
603 
604 /*----------------------------------------------------------------------*
605  |                             DisableCommand                            |
606  *----------------------------------------------------------------------*/
607 /*ARGSUSED*/
608 void
DisableCommand(Widget w,Atom target,MessageData data,unsigned long len,int fmt)609 DisableCommand (
610      Widget         w,
611      Atom           target,
612      MessageData    data,
613      unsigned long  len,
614      int            fmt)
615 {
616   CARD32         commandID, count;
617   Window        *windowIDs = NULL;
618   CmdTree       *tPtr, *pNext;
619   int            i, win;
620   unsigned long  activeContext = 0L;
621 
622   /*
623    * check data to make sure somethings there.
624    */
625   if ((data == NULL) || (len == 0))
626     {
627       PRINT("Bad data passed to DisableCommand.\n");
628       return;
629     }
630 
631   commandID = UnpackCARD32(&data);
632   count     = UnpackCARD32(&data);
633 
634   if (count > 0) windowIDs = (Window *) XtMalloc(sizeof(Window)*count);
635   for (win=0; win<count; win++)
636     {
637       windowIDs[win] = UnpackCARD32(&data);
638       PRINT("Got window ID %d.\n", windowIDs[win]);
639     }
640 
641   /*
642    *  Disable on root menu
643    */
644   if ((windowIDs[0] & WINDOW_MASK) == 0L)
645     {
646       tPtr = FindCmd (commandID, CCI_TREE(w));
647       if (tPtr != NULL)
648 	{
649 	  for (i=0; i<count; i++)
650 	  {
651 	      activeContext = F_CONTEXT_ROOT;
652 	      pNext = tPtr->next;
653 	      tPtr->next = NULL;
654 	      ModifyClientCommandTree (ACTIVE_PSD, NULL, ROOT, tPtr,
655 				       DISABLE, activeContext, NULL);
656 	      tPtr->next = pNext;
657 	  }
658 	}
659       else
660 	PRINT("ERROR - commandID %d not found in command tree.\n", commandID);
661     }
662 
663   /*
664    * Disable on all clients
665    */
666   else if ((windowIDs[0] & WINDOW_MASK) == ALL_WINDOWS)
667     {
668       tPtr = FindCmd (commandID, CCI_TREE(w));
669       if (tPtr != NULL)
670 	{
671 	  activeContext = 0L;
672 	  if (windowIDs[0] &   ICON_ONLY) activeContext |= F_CONTEXT_ICON;
673 	  if (windowIDs[0] & WINDOW_ONLY) activeContext |= F_CONTEXT_WINDOW;
674 
675 	  pNext = tPtr->next;
676 	  tPtr->next = NULL;
677 	  ModifyClientCommandTree (ACTIVE_PSD, NULL, ALL, tPtr,
678 				   DISABLE, activeContext, NULL);
679 	  tPtr->next = pNext;
680 
681 	  PRINT("Disabled commandID %d on all windows.\n", commandID);
682 	}
683       else
684 	PRINT("ERROR - commandID %d not found in command tree.\n", commandID);
685     }
686 
687   /*
688    * Disable on specified clients
689    */
690   else
691     {
692       tPtr = FindCmd (commandID, CCI_TREE(w));
693       if (tPtr != NULL)
694 	{
695 	  for (i=0; i<count; i++)
696 	    {
697 	      ClientData *pCD;
698 
699 	      activeContext = 0L;
700 	      if (windowIDs[i] &   ICON_ONLY)
701 		activeContext |= F_CONTEXT_ICON;
702 	      if (windowIDs[i] & WINDOW_ONLY)
703 		activeContext |= F_CONTEXT_WINDOW;
704 
705 	      pCD = GetPCD(ScrNum(w), windowIDs[i] & WINDOW_MASK);
706 	      if (pCD != NULL)
707 	      {
708 		  pNext = tPtr->next;
709 		  tPtr->next = NULL;
710 		  ModifyClientCommandTree (pCD->pSD, pCD, SINGLE, tPtr,
711 					   DISABLE, activeContext, NULL);
712 		  tPtr->next = pNext;
713 	      }
714 	    }
715 	}
716       else
717 	PRINT("ERROR - commandID %d not found in command tree.\n", commandID);
718     }
719 
720   if (count > 0)
721     XtFree((char*)windowIDs);
722 }
723 
724 
725 
726 /*----------------------------------------------------------------------*
727  |                             RenameCommand                            |
728  *----------------------------------------------------------------------*/
729 /*ARGSUSED*/
730 void
RenameCommand(Widget w,Atom target,MessageData data,unsigned long len,int fmt)731 RenameCommand (
732      Widget         w,
733      Atom           target,
734      MessageData    data,
735      unsigned long  len,
736      int            fmt)
737 {
738   CARD32         commandID, count;
739   Window        *windowIDs = NULL;
740   CmdTree       *tPtr, *pNext;
741   int            i, win;
742   unsigned long  activeContext = 0L;
743   String	 newname;
744 
745   /*
746    * check data to make sure somethings there.
747    */
748   if ((data == NULL) || (len == 0))
749     {
750       PRINT("Bad data passed to RenameCommand.\n");
751       return;
752     }
753 
754   commandID = UnpackCARD32(&data);
755   newname   = UnpackString(&data);
756   count     = UnpackCARD32(&data);
757 
758   if (count > 0) windowIDs = (Window *) XtMalloc(sizeof(Window)*count);
759   for (win=0; win<count; win++)
760     {
761       windowIDs[win] = UnpackCARD32(&data);
762       PRINT("Got window ID %d.\n", windowIDs[win]);
763     }
764 
765   /*
766    *  Rename on root menu
767    */
768   if ((windowIDs[0] & WINDOW_MASK) == 0L)
769     {
770       tPtr = FindCmd (commandID, CCI_TREE(w));
771       if (tPtr != NULL)
772 	{
773 	  for (i=0; i<count; i++)
774 	  {
775 	      activeContext = F_CONTEXT_ROOT;
776 	      pNext = tPtr->next;
777 	      tPtr->next = NULL;
778 	      ModifyClientCommandTree (ACTIVE_PSD, NULL, ROOT, tPtr,
779 				       RENAME, activeContext, newname);
780 	      tPtr->next = pNext;
781 	  }
782 	}
783       else
784 	PRINT("ERROR - commandID %d not found in command tree.\n", commandID);
785     }
786 
787   /*
788    * Rename on all clients
789    */
790   else if ((windowIDs[0] & WINDOW_MASK) == ALL_WINDOWS)
791     {
792       tPtr = FindCmd (commandID, CCI_TREE(w));
793       if (tPtr != NULL)
794 	{
795 	  activeContext = 0L;
796 	  if (windowIDs[0] &   ICON_ONLY) activeContext |= F_CONTEXT_ICON;
797 	  if (windowIDs[0] & WINDOW_ONLY) activeContext |= F_CONTEXT_WINDOW;
798 
799 	  pNext = tPtr->next;
800 	  tPtr->next = NULL;
801 	  ModifyClientCommandTree (ACTIVE_PSD, NULL, ALL, tPtr,
802 				   RENAME, activeContext, newname);
803 	  tPtr->next = pNext;
804 
805 	  PRINT("Renamed commandID %d on all windows.\n", commandID);
806 	}
807       else
808 	PRINT("ERROR - commandID %d not found in command tree.\n", commandID);
809     }
810 
811   /*
812    * Rename on specified clients
813    */
814   else
815     {
816       tPtr = FindCmd (commandID, CCI_TREE(w));
817       if (tPtr != NULL)
818 	{
819 	  for (i=0; i<count; i++)
820 	    {
821 	      ClientData *pCD;
822 
823 	      activeContext = 0L;
824 	      if (windowIDs[i] &   ICON_ONLY)
825 		activeContext |= F_CONTEXT_ICON;
826 	      if (windowIDs[i] & WINDOW_ONLY)
827 		activeContext |= F_CONTEXT_WINDOW;
828 
829 	      pCD = GetPCD(ScrNum(w), windowIDs[i] & WINDOW_MASK);
830 	      if (pCD != NULL)
831 	      {
832 		  pNext = tPtr->next;
833 		  tPtr->next = NULL;
834 		  ModifyClientCommandTree (pCD->pSD, pCD, SINGLE, tPtr,
835 					   RENAME, activeContext, newname);
836 		  tPtr->next = pNext;
837 	      }
838 	    }
839 	}
840       else
841 	PRINT("ERROR - commandID %d not found in command tree.\n", commandID);
842     }
843 
844   if (count > 0)
845     XtFree((char*)windowIDs);
846 }
847 
848 
849 
850 /*----------------------------------------------------------------------*
851  |                             RemoveCommand                            |
852  *----------------------------------------------------------------------*/
853 /*ARGSUSED*/
854 void
RemoveCommand(Widget w,Atom target,MessageData data,unsigned long len,int fmt)855 RemoveCommand (
856      Widget         w,
857      Atom           target,
858      MessageData    data,
859      unsigned long  len,
860      int            fmt)
861 {
862   CARD32         commandID, count;
863   Window        *windowIDs = NULL;
864   CmdTree       *tPtr, *pNext;
865   int            i, win;
866   unsigned long  activeContext = 0L;
867 
868   /*
869    * check data to make sure somethings there.
870    */
871   if ((data == NULL) || (len == 0))
872     {
873       PRINT("Bad data passed to RemoveCommand.\n");
874       return;
875     }
876 
877   commandID = UnpackCARD32(&data);
878   count     = UnpackCARD32(&data);
879 
880   if (count > 0) windowIDs = (Window *) XtMalloc(sizeof(Window)*count);
881   for (win=0; win<count; win++)
882     {
883       windowIDs[win] = UnpackCARD32(&data);
884       PRINT("Got window ID %d.\n", windowIDs[win]);
885     }
886 
887   /*
888    *  Remove on root menu
889    */
890   if ((windowIDs[0] & WINDOW_MASK) == 0L)
891     {
892       tPtr = FindCmd (commandID, CCI_TREE(w));
893       if (tPtr != NULL)
894 	{
895 	  for (i=0; i<count; i++)
896 	  {
897 	      activeContext = F_CONTEXT_ROOT;
898 	      pNext = tPtr->next;
899 	      tPtr->next = NULL;
900 	      ModifyClientCommandTree (ACTIVE_PSD, NULL, ROOT, tPtr,
901 				       REMOVE, activeContext, NULL);
902 	      tPtr->next = pNext;
903 	  }
904 	}
905       else
906 	PRINT("ERROR - commandID %d not found in command tree.\n", commandID);
907     }
908 
909   /*
910    * Remove on all clients
911    */
912   else if ((windowIDs[0] & WINDOW_MASK) == ALL_WINDOWS)
913     {
914       tPtr = FindCmd (commandID, CCI_TREE(w));
915       if (tPtr != NULL)
916 	{
917 	  activeContext = 0L;
918 	  if (windowIDs[0] &   ICON_ONLY) activeContext |= F_CONTEXT_ICON;
919 	  if (windowIDs[0] & WINDOW_ONLY) activeContext |= F_CONTEXT_WINDOW;
920 
921 	  pNext = tPtr->next;
922 	  tPtr->next = NULL;
923 	  ModifyClientCommandTree (ACTIVE_PSD, NULL, ALL, tPtr, REMOVE,
924 				   activeContext, NULL);
925 	  tPtr->next = pNext;
926 
927 	  PRINT("Removed commandID %d on all windows.\n", commandID);
928 	}
929       else
930 	PRINT("ERROR - commandID %d not found in command tree.\n", commandID);
931     }
932 
933   /*
934    * Remove on specified clients
935    */
936   else
937     {
938       tPtr = FindCmd (commandID, CCI_TREE(w));
939       if (tPtr != NULL)
940 	{
941 	  for (i=0; i<count; i++)
942 	  {
943 	      ClientData *pCD;
944 
945 	      activeContext = 0L;
946 	      if (windowIDs[i] &   ICON_ONLY)
947 		activeContext |= F_CONTEXT_ICON;
948 	      if (windowIDs[i] & WINDOW_ONLY)
949 		activeContext |= F_CONTEXT_WINDOW;
950 
951 	      pCD = GetPCD(ScrNum(w), windowIDs[i] & WINDOW_MASK);
952 	      if (pCD != NULL)
953 	      {
954 		  pNext = tPtr->next;
955 		  tPtr->next = NULL;
956 		  ModifyClientCommandTree (pCD->pSD, pCD, SINGLE, tPtr,
957 					   REMOVE, activeContext, NULL);
958 		  tPtr->next = pNext;
959 	      }
960 	    }
961 	}
962       else
963 	PRINT("ERROR - commandID %d not found in command tree.\n", commandID);
964     }
965 
966   if (count > 0)
967     XtFree((char*)windowIDs);
968 }
969 
970 
971 
972 /*---------------------------------------------------------------------------*
973  |                           RemoveMatchingCommands                          |
974  | Recursively removes commands that match a given window in the specified   |
975  | command tree.                                                             |
976  *---------------------------------------------------------------------------*/
977 /*ARGSUSED*/
978 void
RemoveMatchingCommands(int scr,Window clientWindow,CmdTree * tree)979 RemoveMatchingCommands (
980      int    scr,
981      Window clientWindow,
982      CmdTree *tree)
983 {
984   if (tree == NULL)
985     return;
986 
987   if (tree->subTrees != NULL)
988     RemoveMatchingCommands(scr, clientWindow, tree->subTrees);
989 
990   if (tree->notifyWindow == clientWindow)
991     {
992       cmdKillList[ cmdKillListIndex++ ] = tree->commandID;
993     }
994 
995   if (tree->next != NULL)
996     RemoveMatchingCommands(scr, clientWindow, tree->next);
997 }
998 
999 
1000 
1001 /*---------------------------------------------------------------------------*
1002  |                           RemoveCommandsForClient                         |
1003  | This function will remove any command that was inserted by this client.   |
1004  *---------------------------------------------------------------------------*/
1005 void
RemoveCommandsForClient(int scr,Window clientWindow)1006 RemoveCommandsForClient (
1007      int    scr,
1008      Window clientWindow)
1009 {
1010   int i;
1011 
1012   ShowWaitState (TRUE);
1013 
1014   cmdKillListIndex = 0;
1015   RemoveMatchingCommands(scr, clientWindow, CCI_TREE_OF_SCR(scr));
1016 
1017   /*
1018    * Remove any matching commands on the root menu.
1019    */
1020   for (i = 0;  i < cmdKillListIndex;  i++)
1021     {
1022       CmdTree *tPtr, *pNext;
1023       MenuSpec *pMS;
1024       WmScreenData *pSD = ACTIVE_PSD;
1025 
1026       while ((tPtr = FindCmd (cmdKillList[ i ], CCI_TREE_OF_SCR(scr))))
1027 	{
1028 	  /* make sure ModifyClientCommandTree can't muck with cmdTree. */
1029 	  pNext = tPtr->next;
1030 	  tPtr->next = NULL;
1031 
1032 	  ModifyClientCommandTree (pSD, NULL, ALL, tPtr,
1033 				   REMOVE, F_CONTEXT_ALL, NULL);
1034 	  /* restore tree. */
1035 	  tPtr->next = pNext;
1036 
1037 	  /*
1038 	   * if this command caused a menu spec to be created, remove it.
1039 	   */
1040 	  DestroyMenuSpec(pSD, cmdKillList[i]);
1041 
1042 	  /*
1043 	   * Now delete the matching entry in the command tree.
1044 	   */
1045 	  DeleteCommand(cmdKillList[ i ], &CCI_TREE_OF_SCR(scr));
1046 	}
1047     }
1048 
1049   ShowWaitState (FALSE);
1050 }
1051 
1052 
1053 /*---------------------------------------------------------------------------*
1054  |                            InvokeMessageReply                             |
1055  *---------------------------------------------------------------------------*/
1056 /*ARGSUSED*/
1057 void
InvokeMessageReply(Widget w,XtPointer clientData,XtPointer callData)1058 InvokeMessageReply (Widget w, XtPointer clientData, XtPointer callData)
1059 {
1060   PRINT("Invoke message reply received.\n");
1061 }
1062 
1063 
1064 
1065 /*---------------------------------------------------------------------------*
1066  |                            SendInvokeMessage                              |
1067  | Send a convert request to the client that owns the menu command.          |
1068  *---------------------------------------------------------------------------*/
1069 void
SendInvokeMessage(CARD32 commandID,CARD32 clientWindow,Atom selection,Time time)1070 SendInvokeMessage (
1071      CARD32 commandID,
1072      CARD32 clientWindow,
1073      Atom   selection,
1074      Time   time)
1075 {
1076   MessageData  msg, fulldata;
1077   unsigned long size;
1078 
1079   size = (unsigned long)(sizeof(CARD32) + sizeof(CARD32));
1080   msg = fulldata = (MessageData)XtMalloc(sizeof(CARD8) * size);
1081   msg = PackCARD32(msg, commandID);
1082   msg = PackCARD32(msg, clientWindow);
1083 
1084   UTMSendMessage(ACTIVE_PSD->utmShell,
1085 		 selection,
1086 		 wmGD._MOTIF_WM_INVOKE_COMMAND,
1087 		 (XtPointer)fulldata, size, WSM_PROTO_FMT,
1088 		 InvokeMessageReply, NULL, /* no client data */
1089 		 time);
1090 }
1091 
1092 /*----------------------------------------------------------------------*
1093  |                             CopyMwmGadget
1094  *----------------------------------------------------------------------*/
1095 
1096 static void
CopyMwmGadget(GadgetRectangle * mwm_gadget,GadgetRectangle * auto_gadget)1097 CopyMwmGadget(GadgetRectangle *mwm_gadget, GadgetRectangle *auto_gadget)
1098 {
1099 	auto_gadget->id = mwm_gadget->id;
1100 	auto_gadget->rect.x = mwm_gadget->rect.x;
1101 	auto_gadget->rect.y = mwm_gadget->rect.y;
1102 	auto_gadget->rect.width = mwm_gadget->rect.width;
1103 	auto_gadget->rect.height = mwm_gadget->rect.height;
1104 }
1105 
1106 
1107 /*----------------------------------------------------------------------*
1108  |                             FillInvalidInfo
1109  *----------------------------------------------------------------------*/
1110 
1111 static void
FillInvalidInfo(GadgetRectangle * auto_gadget)1112 FillInvalidInfo(GadgetRectangle *auto_gadget)
1113 {
1114 	auto_gadget->id = INVALID;
1115 	auto_gadget->rect.x = auto_gadget->rect.y = auto_gadget->rect.width =
1116 	auto_gadget->rect.height = INVALID;
1117 }
1118 
1119 
1120 /*----------------------------------------------------------------------*
1121  |                             GetMinimizeInfo
1122  *----------------------------------------------------------------------*/
1123 
1124 static void
GetMinimizeInfo(ClientData * pcd,XtPointer reply)1125 GetMinimizeInfo(ClientData *pcd, XtPointer reply)
1126 {
1127   /*
1128    * This function packs data about the minimize button in the following
1129    * order : 1. gadget count 2. id  3. x position 4. y position 5. width
1130    *         6. height
1131    */
1132 
1133 
1134   GadgetRectangle minimize_button;
1135   CARD32 filledCount;
1136   int i;
1137   Window frameWin;
1138   Boolean minFound = False;
1139 
1140 
1141 
1142 
1143 
1144 
1145    filledCount = pcd->cTitleGadgets;
1146    frameWin = pcd->clientFrameWin;
1147 
1148 
1149    for (i=0; i < filledCount; i++)
1150  	if (pcd->pTitleGadgets[i].id == FRAME_MINIMIZE)
1151 	   {
1152 	        CopyMwmGadget (&(pcd->pTitleGadgets[i]), &minimize_button);
1153 		minFound = True;
1154 	   }
1155 
1156    if (minFound == False)
1157 	FillInvalidInfo (&minimize_button);
1158 
1159 
1160 
1161       reply = PackCARD32 (reply, (CARD32)filledCount);
1162       reply = PackCARD32(reply, (CARD32)minimize_button.id);
1163       reply = PackCARD32 (reply, (CARD32)minimize_button.rect.x);
1164       reply = PackCARD32 (reply, (CARD32)minimize_button.rect.y);
1165       reply = PackCARD32 (reply, (CARD32)minimize_button.rect.width);
1166       reply = PackCARD32 (reply, (CARD32)minimize_button.rect.height);
1167       reply = PackCARD32 (reply, (CARD32)frameWin);
1168 
1169 }
1170 
1171 /*----------------------------------------------------------------------*
1172  |                             GetMaximizeInfo
1173  *----------------------------------------------------------------------*/
1174 
1175 static void
GetMaximizeInfo(ClientData * pcd,XtPointer reply)1176 GetMaximizeInfo(ClientData *pcd, XtPointer reply)
1177 {
1178 
1179   /*
1180    * This function packs data about the maximize button in the following
1181    * order : 1. gadget count 2. id  3. x position 4. y position 5. width
1182    *         6. height 7. event window
1183    */
1184 
1185       int i;
1186       GadgetRectangle maximize_button;
1187       CARD32 filledCount;
1188       Window frameWin;
1189       Boolean maxFound = False;
1190 
1191 
1192       filledCount = pcd->cTitleGadgets;
1193       frameWin = pcd->clientFrameWin;
1194 
1195 
1196       for (i=0; i < filledCount; i++)
1197 	{
1198 
1199         if (pcd->pTitleGadgets[i].id == FRAME_MAXIMIZE)
1200 	  {
1201 	    CopyMwmGadget (&(pcd->pTitleGadgets[i]),&maximize_button);
1202 	    maxFound = True;
1203           }
1204 
1205       	}
1206 
1207       if (maxFound == False)
1208 	FillInvalidInfo (&maximize_button);
1209 
1210 
1211 
1212 	reply = PackCARD32 (reply, (CARD32)filledCount);
1213 	reply = PackCARD32 (reply, (CARD32)maximize_button.id);
1214 	reply = PackCARD32 (reply, (CARD32)maximize_button.rect.x);
1215 	reply = PackCARD32 (reply, (CARD32)maximize_button.rect.y);
1216 	reply = PackCARD32 (reply, (CARD32)maximize_button.rect.width);
1217 	reply = PackCARD32 (reply, (CARD32)maximize_button.rect.height);
1218 	reply = PackCARD32 (reply, (CARD32)frameWin);
1219 }
1220 
1221 
1222 /*----------------------------------------------------------------------*
1223  |                             GetIconInfo
1224  *----------------------------------------------------------------------*/
1225 
1226 static void
GetIconInfo(ClientData * pcd,XtPointer reply,Boolean use_icon_box)1227 GetIconInfo(ClientData *pcd, XtPointer reply, Boolean use_icon_box)
1228 {
1229 
1230    IconBoxData *icon_box;
1231    XmScrollBarWidget  hScrollBar, vScrollBar;
1232    Widget frameWidget, scrollWidget, shellWidget;
1233 
1234 
1235 
1236    CARD32 iconX, iconY, iconWidth, iconHeight ;
1237    CARD32 hMin, hMax, hSliderAreaWidth, hSliderX, hSliderAreaX,
1238           vMin, vMax, vSliderAreaHeight, vSliderY, vSliderAreaY;
1239    CARD32 rightArrowX, rightArrowY, leftArrowX, leftArrowY,
1240           topArrowX, topArrowY, bottomArrowX, bottomArrowY;
1241    CARD32 iconBoxX, iconBoxY, iconBoxWidth, iconBoxHeight;
1242    Window frameWin, scrollWin, hScrollWin, vScrollWin, iconShellWin, iconFrameWin;
1243    CARD32 lastRow, lastCol;
1244    CARD32 iPlaceW, iPlaceH;
1245    CARD32 useIconBox;
1246 
1247 
1248    icon_box = pcd->pIconBox;
1249    useIconBox = pcd->pSD->useIconBox;
1250 
1251 
1252 
1253 
1254        /*
1255 	* IconBox info
1256 	*/
1257        if (use_icon_box == True)
1258 	 {
1259 	   hScrollBar =  (XmScrollBarWidget)icon_box->hScrollBar;
1260 
1261 	   hMin = hScrollBar->scrollBar.minimum;
1262 	   hMax = hScrollBar->scrollBar.maximum;
1263 	   hSliderAreaWidth = hScrollBar->scrollBar.slider_area_width;
1264 	   hSliderX = hScrollBar->scrollBar.slider_x;
1265 	   hSliderAreaX = hScrollBar->scrollBar.slider_area_x;
1266 	   leftArrowX = hScrollBar->core.x +
1267 	                  hScrollBar->scrollBar.arrow1_x +
1268 	                  (hScrollBar->scrollBar.arrow_width/2);
1269 	   leftArrowY = hScrollBar->core.y +
1270 	                  hScrollBar->scrollBar.arrow1_y +
1271 	                  (hScrollBar->scrollBar.arrow_height/2);
1272 
1273 	   rightArrowX = hScrollBar->core.x + hScrollBar->scrollBar.arrow2_x
1274 	                  + (hScrollBar->scrollBar.arrow_width/2);
1275 	   rightArrowY = hScrollBar->core.y + hScrollBar->scrollBar.arrow2_y
1276 	                  + (hScrollBar->scrollBar.arrow_height/2);
1277 
1278 	   vScrollBar =  (XmScrollBarWidget)icon_box->vScrollBar;
1279 
1280 	   vMin = vScrollBar->scrollBar.minimum;
1281 	   vMax = vScrollBar->scrollBar.maximum;
1282 	   vSliderAreaHeight = vScrollBar->scrollBar.slider_area_height;
1283 	   vSliderY = vScrollBar->scrollBar.slider_y;
1284 	   vSliderAreaY = vScrollBar->scrollBar.slider_area_y;
1285 
1286 	   topArrowX = vScrollBar->core.x + vScrollBar->scrollBar.arrow1_x
1287 	                  + (vScrollBar->scrollBar.arrow_width/2);
1288 	   topArrowY = vScrollBar->core.y + vScrollBar->scrollBar.arrow1_y
1289 	                  + (vScrollBar->scrollBar.arrow_height/2);
1290 
1291 	   bottomArrowX = vScrollBar->core.x + vScrollBar->scrollBar.arrow2_x
1292 	                  + (vScrollBar->scrollBar.arrow_width/2);
1293 	   bottomArrowY = hScrollBar->core.y + hScrollBar->scrollBar.arrow2_y
1294 	                  + (hScrollBar->scrollBar.arrow_height/2);
1295 
1296 
1297 
1298 
1299 	   shellWidget = icon_box->shellWidget;
1300 
1301 
1302 	   iconBoxX = shellWidget->core.x;
1303 	   iconBoxY = shellWidget->core.y;
1304 	   iconBoxWidth = shellWidget->core.width;
1305 	   iconBoxHeight = shellWidget->core.height;
1306 	   iconShellWin = XtWindow (shellWidget);
1307 
1308 
1309 	   frameWidget = icon_box->frameWidget;
1310 	   frameWin = XtWindow (frameWidget);
1311 
1312 	   scrollWidget = icon_box->scrolledWidget;
1313 	   scrollWin = XtWindow (scrollWidget);
1314 
1315 	   hScrollWin = XtWindow (hScrollBar);
1316 	   vScrollWin = XtWindow (vScrollBar);
1317 
1318 	   lastCol = icon_box->lastCol;
1319 	   lastRow = icon_box->lastRow;
1320 	   iPlaceW = icon_box->IPD.iPlaceW;
1321 	   iPlaceH = icon_box->IPD.iPlaceH;
1322 	}
1323 
1324 
1325        /*
1326 	* icon info
1327 	*/
1328 
1329        iconX = pcd->iconX;
1330        iconY = pcd->iconY;
1331        iconWidth = pcd->pSD->iconWidth;
1332 
1333 
1334        iconHeight = pcd->pSD->iconHeight;
1335        iconFrameWin = pcd->iconFrameWin;
1336 
1337 
1338 
1339        reply = PackCARD32 (reply,(CARD32)useIconBox);
1340        reply = PackCARD32 (reply,(CARD32)iconX);
1341        reply = PackCARD32 (reply,(CARD32)iconY);
1342        reply = PackCARD32 (reply,(CARD32)iconWidth);
1343        reply = PackCARD32 (reply,(CARD32)iconHeight);
1344        reply = PackCARD32 (reply,(CARD32)iconFrameWin);
1345 
1346        if (use_icon_box == True)
1347 	 {
1348 	   reply = PackCARD32 (reply,(CARD32)hMin);
1349 	   reply = PackCARD32 (reply,(CARD32)hMax);
1350 	   reply = PackCARD32 (reply,(CARD32)hSliderAreaWidth);
1351 	   reply = PackCARD32 (reply,(CARD32)hSliderX);
1352 	   reply = PackCARD32 (reply,(CARD32)hSliderAreaX);
1353 	   reply = PackCARD32 (reply,(CARD32)vMin);
1354 	   reply = PackCARD32 (reply,(CARD32)vMax);
1355 	   reply = PackCARD32 (reply,(CARD32)vSliderAreaHeight);
1356 	   reply = PackCARD32 (reply,(CARD32)vSliderY);
1357 	   reply = PackCARD32 (reply,(CARD32)vSliderAreaY);
1358 	   reply = PackCARD32 (reply,(CARD32)rightArrowX);
1359 	   reply = PackCARD32 (reply,(CARD32)rightArrowY);
1360 	   reply = PackCARD32 (reply,(CARD32)leftArrowX);
1361 	   reply = PackCARD32 (reply,(CARD32)leftArrowY);
1362 	   reply = PackCARD32 (reply,(CARD32)topArrowX);
1363 	   reply = PackCARD32 (reply,(CARD32)topArrowY);
1364 	   reply = PackCARD32 (reply,(CARD32)bottomArrowX);
1365 	   reply = PackCARD32 (reply,(CARD32)bottomArrowY);
1366 	   reply = PackCARD32 (reply,(CARD32)iconBoxX);
1367 	   reply = PackCARD32 (reply,(CARD32)iconBoxY);
1368 	   reply = PackCARD32 (reply,(CARD32)iconBoxWidth);
1369 	   reply = PackCARD32 (reply,(CARD32)iconBoxHeight);
1370 	   reply = PackCARD32 (reply,(CARD32)iconShellWin);
1371 	   reply = PackCARD32 (reply,(CARD32)frameWin);
1372 	   reply = PackCARD32 (reply,(CARD32)scrollWin);
1373 	   reply = PackCARD32 (reply,(CARD32)hScrollWin);
1374 	   reply = PackCARD32 (reply,(CARD32)vScrollWin);
1375 	   reply = PackCARD32 (reply,(CARD32)lastCol);
1376 	   reply = PackCARD32 (reply,(CARD32)lastRow);
1377 	   reply = PackCARD32 (reply,(CARD32)iPlaceH);
1378 	   reply = PackCARD32 (reply,(CARD32)iPlaceW);
1379 
1380 	}
1381 
1382 }
1383 
1384 /*----------------------------------------------------------------------*
1385  |                             GetMoveInfo
1386  *----------------------------------------------------------------------*/
1387 
1388 static void
GetMoveInfo(ClientData * pcd,XtPointer reply)1389 GetMoveInfo(ClientData *pcd, XtPointer reply)
1390 
1391 {
1392       int i;
1393       GadgetRectangle title;
1394       GadgetRectangle menu;
1395       CARD32 filledCount;
1396       CARD32 upperBorderWidth, lowerBorderWidth;
1397       CARD32 windowX, windowY;
1398       Window frameWin;
1399 
1400       Boolean titleFound = False;
1401       Boolean system_found = False;
1402 
1403 
1404       filledCount = pcd->cTitleGadgets;
1405       upperBorderWidth = pcd->frameInfo.upperBorderWidth;
1406       lowerBorderWidth = pcd->frameInfo.lowerBorderWidth;
1407       windowX = pcd->clientX;
1408       windowY = pcd->clientY;
1409       frameWin = pcd->clientFrameWin;
1410 
1411       for (i=0; i < filledCount; i++)
1412 	{
1413 	  if (pcd->pTitleGadgets[i].id == FRAME_TITLE)
1414 	    {
1415 		CopyMwmGadget (&(pcd->pTitleGadgets[i]), &title);
1416 		titleFound = True;
1417 	    }
1418 
1419 	  if (pcd->pTitleGadgets[i].id == FRAME_SYSTEM)
1420 	    {
1421 	      CopyMwmGadget (&(pcd->pTitleGadgets[i]), &menu);
1422 	      system_found = True;
1423 	    }
1424 
1425         }
1426 
1427         if (titleFound == False)
1428 	 FillInvalidInfo (&title);
1429 
1430         if (system_found == False)
1431 	 FillInvalidInfo (&menu);
1432 
1433 
1434 	 reply = PackCARD32 (reply, (CARD32)filledCount);
1435 	 reply = PackCARD32 (reply, (CARD32)title.id);
1436 	 reply = PackCARD32 (reply, (CARD32)title.rect.x);
1437 	 reply = PackCARD32 (reply, (CARD32)title.rect.y);
1438 	 reply = PackCARD32 (reply, (CARD32)title.rect.width);
1439 	 reply = PackCARD32 (reply, (CARD32)title.rect.height);
1440        	 reply = PackCARD32 (reply, (CARD32)menu.id);
1441 	 reply = PackCARD32 (reply, (CARD32)menu.rect.x);
1442 	 reply = PackCARD32 (reply, (CARD32)menu.rect.y);
1443 	 reply = PackCARD32 (reply, (CARD32)menu.rect.width);
1444 	 reply = PackCARD32 (reply, (CARD32)menu.rect.height);
1445 	 reply = PackCARD32 (reply, (CARD32)upperBorderWidth);
1446 	 reply = PackCARD32 (reply, (CARD32)lowerBorderWidth);
1447 	 reply = PackCARD32 (reply, (CARD32)windowX);
1448 	 reply = PackCARD32 (reply, (CARD32)windowY);
1449 	 reply = PackCARD32 (reply, (CARD32)frameWin);
1450 
1451     }
1452 
1453 
1454 
1455 
1456 /*----------------------------------------------------------------------*
1457  |                             GetResizeInfo
1458  *----------------------------------------------------------------------*/
1459 
1460 static void
GetResizeInfo(ClientData * pcd,XtPointer reply,int dir)1461 GetResizeInfo(ClientData *pcd, XtPointer reply, int dir)
1462 {
1463       int i;
1464       GadgetRectangle east_resize = {0, {0, 0, 0, 0}}, west_resize = {0, {0, 0, 0, 0}}, gravity_resize, title;
1465       CARD32  upperBorderWidth, lowerBorderWidth;
1466       Window frameWin;
1467       int filledCount;
1468       Boolean titleFound = False;
1469 
1470 
1471 
1472       filledCount = pcd->cTitleGadgets;
1473 
1474       if (!(pcd->decor & MWM_DECOR_RESIZEH))
1475       	FillInvalidInfo (&gravity_resize);
1476       else
1477 	{
1478 		CopyMwmGadget (&pcd->pResizeGadgets[dir], &gravity_resize);
1479 		CopyMwmGadget (&pcd->pResizeGadgets[WM_WEST], &west_resize);
1480 		CopyMwmGadget (&pcd->pResizeGadgets[WM_EAST], &east_resize);
1481 	}
1482 
1483 
1484        for (i=0; i < filledCount; i++)
1485 	if (pcd->pTitleGadgets[i].id == FRAME_TITLE)
1486 	   {
1487 	      CopyMwmGadget (&(pcd->pTitleGadgets[i]), &title);
1488               titleFound = True;
1489 	   }
1490 
1491 	if (titleFound == False)
1492 	   FillInvalidInfo (&title);
1493 
1494 
1495 
1496 
1497 
1498         upperBorderWidth = pcd->frameInfo.upperBorderWidth;
1499         lowerBorderWidth = pcd->frameInfo.lowerBorderWidth;
1500 	frameWin = pcd->clientFrameWin;
1501 
1502 
1503 
1504 
1505 	 reply = PackCARD32 (reply, (CARD32)east_resize.id);
1506 	 reply = PackCARD32 (reply, (CARD32)east_resize.rect.width);
1507 	 reply = PackCARD32 (reply, (CARD32)west_resize.id);
1508 	 reply = PackCARD32 (reply, (CARD32)west_resize.rect.width);
1509 	 reply = PackCARD32 (reply, (CARD32)gravity_resize.id);
1510 	 reply = PackCARD32 (reply, (CARD32)gravity_resize.rect.x);
1511 	 reply = PackCARD32 (reply, (CARD32)gravity_resize.rect.y);
1512 	 reply = PackCARD32 (reply, (CARD32)gravity_resize.rect.width);
1513 	 reply = PackCARD32 (reply, (CARD32)gravity_resize.rect.height);
1514 	 reply = PackCARD32 (reply, (CARD32)title.id);
1515 	 reply = PackCARD32 (reply, (CARD32)title.rect.x);
1516 	 reply = PackCARD32 (reply, (CARD32)title.rect.y);
1517 	 reply = PackCARD32 (reply, (CARD32)title.rect.width);
1518 	 reply = PackCARD32 (reply, (CARD32)title.rect.height);
1519 	 reply = PackCARD32 (reply, (CARD32)upperBorderWidth);
1520 	 reply = PackCARD32 (reply, (CARD32)lowerBorderWidth);
1521 	 reply = PackCARD32 (reply, (CARD32)frameWin);
1522 }
1523 
1524 
1525 /*----------------------------------------------------------------------*
1526  |                             GetWindowMenuUnpostInfo
1527  *----------------------------------------------------------------------*/
1528 
1529 static void
GetWindowMenuUnpostInfo(ClientData * pcd,XtPointer reply)1530 GetWindowMenuUnpostInfo(ClientData *pcd, XtPointer reply)
1531 {
1532 
1533     MenuSpec *menuSpec;
1534 
1535     CARD32 clientState;
1536     CARD32 menuWin;
1537     CARD32 frameWin;
1538 
1539     menuSpec = pcd->systemMenuSpec;
1540 
1541 
1542     clientState = pcd->clientState;
1543     menuWin = XtWindow (menuSpec->menuWidget);
1544     frameWin = pcd->clientFrameWin;
1545 
1546     reply = PackCARD32 (reply,clientState);
1547     reply = PackCARD32 (reply,menuWin);
1548     reply = PackCARD32 (reply,frameWin);
1549 
1550 }
1551 
1552 /*----------------------------------------------------------------------*
1553  |                             GetFocusInfo
1554  *----------------------------------------------------------------------*/
1555 
1556 static void
GetFocusInfo(ClientData * pcd,XtPointer reply)1557 GetFocusInfo(ClientData *pcd, XtPointer reply)
1558 {
1559 
1560 
1561   GadgetRectangle title;
1562   CARD32 filledCount;
1563   int i;
1564   Window frameWin;
1565   Boolean titleFound = False;
1566 
1567 
1568 
1569       filledCount = pcd->cTitleGadgets;
1570       frameWin = pcd->clientFrameWin;
1571 
1572       for (i=0; i < filledCount; i++)
1573         {
1574           if (pcd->pTitleGadgets[i].id == FRAME_TITLE)
1575             {
1576 	      CopyMwmGadget (&(pcd->pTitleGadgets[i]), &title);
1577               titleFound = True;
1578 
1579             }
1580 	}
1581 
1582 
1583    if (titleFound == False)
1584 	FillInvalidInfo (&title);
1585 
1586 
1587 
1588       reply = PackCARD32 (reply, (CARD32)filledCount);
1589       reply = PackCARD32(reply, (CARD32)title.id);
1590       reply = PackCARD32 (reply, (CARD32)title.rect.x);
1591       reply = PackCARD32 (reply, (CARD32)title.rect.y);
1592       reply = PackCARD32 (reply, (CARD32)title.rect.width);
1593       reply = PackCARD32 (reply, (CARD32)title.rect.height);
1594       reply = PackCARD32 (reply, (CARD32)frameWin);
1595 
1596 }
1597 
1598 /*----------------------------------------------------------------------*
1599  |                             GetWindowMenuPostInfo
1600  *----------------------------------------------------------------------*/
1601 
1602 static void
GetWindowMenuPostInfo(ClientData * pcd,XtPointer reply)1603 GetWindowMenuPostInfo(ClientData *pcd, XtPointer reply)
1604 {
1605       int i;
1606       GadgetRectangle title;
1607       GadgetRectangle menu;
1608       CARD32 filledCount;
1609       Window frameWin;
1610 
1611 
1612       Boolean titleFound = False;
1613       Boolean systemFound = False;
1614 
1615 
1616       filledCount = pcd->cTitleGadgets;
1617       frameWin = pcd->clientFrameWin;
1618 
1619       for (i=0; i < filledCount; i++)
1620         {
1621           if (pcd->pTitleGadgets[i].id == FRAME_TITLE)
1622             {
1623 	      CopyMwmGadget (&(pcd->pTitleGadgets[i]), &title);
1624               titleFound = True;
1625 
1626             }
1627 
1628           if (pcd->pTitleGadgets[i].id == FRAME_SYSTEM)
1629             {
1630 	      CopyMwmGadget (&(pcd->pTitleGadgets[i]), &menu);
1631               systemFound = True;
1632             }
1633 
1634         }
1635 
1636 
1637         if (titleFound == False)
1638 		FillInvalidInfo (&title);
1639 
1640         if (systemFound == False)
1641           	FillInvalidInfo (&menu);
1642 
1643 
1644         reply = PackCARD32 (reply, (CARD32)filledCount);
1645 	reply = PackCARD32 (reply, (CARD32)title.id);
1646         reply = PackCARD32 (reply, (CARD32)title.rect.x);
1647         reply = PackCARD32 (reply, (CARD32)title.rect.y);
1648         reply = PackCARD32 (reply, (CARD32)title.rect.width);
1649         reply = PackCARD32 (reply, (CARD32)title.rect.height);
1650 	reply = PackCARD32 (reply, (CARD32)menu.id);
1651         reply = PackCARD32 (reply, (CARD32)menu.rect.x);
1652         reply = PackCARD32 (reply, (CARD32)menu.rect.y);
1653         reply = PackCARD32 (reply, (CARD32)menu.rect.width);
1654         reply = PackCARD32 (reply, (CARD32)menu.rect.height);
1655         reply = PackCARD32 (reply, (CARD32)frameWin);
1656 }
1657 
1658 
1659 /*----------------------------------------------------------------------*
1660  |                             GetIconMenuItemSelectInfo
1661  *----------------------------------------------------------------------*/
1662 
1663 static void
GetIconMenuItemSelectInfo(ClientData * pcd,XtPointer reply,Boolean use_icon_box)1664 GetIconMenuItemSelectInfo(ClientData *pcd, XtPointer reply, Boolean use_icon_box)
1665 {
1666   MenuSpec *menuSpec;
1667   int menuItemCount,sensitiveCount;
1668   Window menuWin, frameWin;
1669   int sensitive[MAX_MENU_ITEMS];
1670   int itemY[MAX_MENU_ITEMS];
1671   char itemName[MAX_MENU_ITEMS][25];
1672 
1673 
1674    IconBoxData *icon_box;
1675    XmScrollBarWidget  hScrollBar, vScrollBar;
1676    Widget frameWidget, scrollWidget, shellWidget;
1677 
1678   MenuButton              *NewMenuButton;
1679   MenuItem                *NewMenuItem;
1680   int n;
1681   CARD32 iconX, iconY, iconWidth, iconHeight;
1682   CARD32 hMin, hMax, hSliderAreaWidth, hSliderX, hSliderAreaX,
1683           vMin, vMax, vSliderAreaHeight, vSliderY, vSliderAreaY;
1684   CARD32 rightArrowX, rightArrowY, leftArrowX, leftArrowY,
1685           topArrowX, topArrowY, bottomArrowX, bottomArrowY;
1686   CARD32 iconBoxX, iconBoxY, iconBoxWidth, iconBoxHeight;
1687   Window scrollWin, hScrollWin, vScrollWin, iconShellWin, iconFrameWin;
1688   CARD32 lastRow, lastCol;
1689   CARD32 iPlaceW, iPlaceH;
1690   CARD32 clientState;
1691   CARD32 useIconBox;
1692 
1693 
1694 
1695   useIconBox = pcd->pSD->useIconBox;
1696 
1697   icon_box = pcd->pIconBox;
1698 
1699   menuSpec = pcd->systemMenuSpec;
1700 
1701   if (menuSpec == NULL)
1702     return;
1703 
1704   menuItemCount = menuSpec->menuButtonCount;
1705 
1706   for (n = 0; n < menuItemCount && n < MAX_MENU_ITEMS; n++)
1707     {
1708       itemName[n][0] = '\0';
1709       sensitive[n] = FALSE;
1710     }
1711 
1712   menuWin = XtWindow (menuSpec->menuWidget);
1713   frameWin = pcd->clientFrameWin;
1714   clientState = pcd->clientState;
1715 
1716       sensitiveCount = 0;
1717 
1718       for (n = 0, NewMenuButton = menuSpec->menuButtons;
1719 	   n < menuSpec->menuButtonCount;
1720 	   n++, NewMenuButton++)
1721 	{
1722 	  if (NewMenuButton->managed == FALSE)
1723             continue;
1724 
1725 	  NewMenuItem = NewMenuButton->menuItem;
1726 	  sensitive[n] = NewMenuButton->buttonWidget->core.sensitive;
1727 	  itemY[n] = NewMenuButton->buttonWidget->core.y +
1728                             (NewMenuButton->buttonWidget->core.height / 2);
1729 	  strcpy(itemName[n], NewMenuItem->label);
1730 
1731 	  if (sensitive[n] == TRUE)
1732             sensitiveCount++;
1733 	}
1734 
1735 
1736 
1737 
1738 
1739        if (use_icon_box == True)
1740 	 {
1741 	   hScrollBar =  (XmScrollBarWidget)icon_box->hScrollBar;
1742 	   hMin = hScrollBar->scrollBar.minimum;
1743 	   hMax = hScrollBar->scrollBar.maximum;
1744 	   hSliderAreaWidth = hScrollBar->scrollBar.slider_area_width;
1745 	   hSliderX = hScrollBar->scrollBar.slider_x;
1746 	   hSliderAreaX = hScrollBar->scrollBar.slider_area_x;
1747 	   leftArrowX = hScrollBar->core.x +
1748 	                  hScrollBar->scrollBar.arrow1_x +
1749 	                  (hScrollBar->scrollBar.arrow_width/2);
1750 	   leftArrowY = hScrollBar->core.y +
1751 	                  hScrollBar->scrollBar.arrow1_y +
1752 	                  (hScrollBar->scrollBar.arrow_height/2);
1753 
1754 	   rightArrowX = hScrollBar->core.x + hScrollBar->scrollBar.arrow2_x
1755 	                  + (hScrollBar->scrollBar.arrow_width/2);
1756 	   rightArrowY = hScrollBar->core.y + hScrollBar->scrollBar.arrow2_y
1757 	                  + (hScrollBar->scrollBar.arrow_height/2);
1758 
1759 	   vScrollBar =  (XmScrollBarWidget)icon_box->vScrollBar;
1760 
1761 	   vMin = vScrollBar->scrollBar.minimum;
1762 	   vMax = vScrollBar->scrollBar.maximum;
1763 	   vSliderAreaHeight = vScrollBar->scrollBar.slider_area_height;
1764 	   vSliderY = vScrollBar->scrollBar.slider_y;
1765 	   vSliderAreaY = vScrollBar->scrollBar.slider_area_y;
1766 
1767 	   topArrowX = vScrollBar->core.x + vScrollBar->scrollBar.arrow1_x
1768 	                  + (vScrollBar->scrollBar.arrow_width/2);
1769 	   topArrowY = vScrollBar->core.y + vScrollBar->scrollBar.arrow1_y
1770 	                  + (vScrollBar->scrollBar.arrow_height/2);
1771 
1772 	   bottomArrowX = vScrollBar->core.x + vScrollBar->scrollBar.arrow2_x
1773 	                  + (vScrollBar->scrollBar.arrow_width/2);
1774 	   bottomArrowY = hScrollBar->core.y + hScrollBar->scrollBar.arrow2_y
1775 	                  + (hScrollBar->scrollBar.arrow_height/2);
1776 
1777 
1778 
1779 
1780 	   shellWidget = icon_box->shellWidget;
1781 
1782 
1783 	   iconBoxX = shellWidget->core.x;
1784 	   iconBoxY = shellWidget->core.y;
1785 	   iconBoxWidth = shellWidget->core.width;
1786 	   iconBoxHeight = shellWidget->core.height;
1787 	   iconShellWin = XtWindow (shellWidget);
1788 
1789 
1790 	   frameWidget = icon_box->frameWidget;
1791 	   frameWin = XtWindow (frameWidget);
1792 
1793 	   scrollWidget = icon_box->scrolledWidget;
1794 	   scrollWin = XtWindow (scrollWidget);
1795 
1796 	   hScrollWin = XtWindow (hScrollBar);
1797 	   vScrollWin = XtWindow (vScrollBar);
1798 
1799 	   lastCol = icon_box->lastCol;
1800 	   lastRow = icon_box->lastRow;
1801 	   iPlaceW = icon_box->IPD.iPlaceW;
1802 	   iPlaceH = icon_box->IPD.iPlaceH;
1803 	}
1804 
1805 
1806        /*
1807 	* icon info
1808 	*/
1809 
1810        iconX = pcd->iconX;
1811        iconY = pcd->iconY;
1812        iconWidth = pcd->pSD->iconWidth;
1813        iconHeight = pcd->pSD->iconHeight;
1814        iconFrameWin = pcd->iconFrameWin;
1815 
1816 
1817 
1818       reply = PackCARD32 (reply, (CARD32)clientState);
1819       reply = PackCARD32 (reply, (CARD32)menuItemCount);
1820       reply = PackCARD32 (reply, (CARD32)sensitiveCount);
1821       reply = PackCARD32 (reply, (CARD32)menuWin);
1822       reply = PackCARD32 (reply, (CARD32)frameWin);
1823       for (n=0; n < menuItemCount && n < MAX_MENU_ITEMS; n++)
1824 	{
1825 	  reply = PackCARD32 (reply, (CARD32)sensitive[n]);
1826 	  reply = PackCARD32 (reply, (CARD32)itemY[n]);
1827 	  reply = PackString (reply, (String)itemName[n]);
1828 	}
1829 
1830        reply = PackCARD32 (reply,(CARD32)use_icon_box);
1831        reply = PackCARD32 (reply,(CARD32)iconX);
1832        reply = PackCARD32 (reply,(CARD32)iconY);
1833        reply = PackCARD32 (reply,(CARD32)iconWidth);
1834        reply = PackCARD32 (reply,(CARD32)iconHeight);
1835        reply = PackCARD32 (reply,(CARD32)iconFrameWin);
1836 
1837        if (use_icon_box == True)
1838 	 {
1839 	   reply = PackCARD32 (reply,(CARD32)hMin);
1840 	   reply = PackCARD32 (reply,(CARD32)hMax);
1841 	   reply = PackCARD32 (reply,(CARD32)hSliderAreaWidth);
1842 	   reply = PackCARD32 (reply,(CARD32)hSliderX);
1843 	   reply = PackCARD32 (reply,(CARD32)hSliderAreaX);
1844 	   reply = PackCARD32 (reply,(CARD32)vMin);
1845 	   reply = PackCARD32 (reply,(CARD32)vMax);
1846 	   reply = PackCARD32 (reply,(CARD32)vSliderAreaHeight);
1847 	   reply = PackCARD32 (reply,(CARD32)vSliderY);
1848 	   reply = PackCARD32 (reply,(CARD32)vSliderAreaY);
1849 	   reply = PackCARD32 (reply,(CARD32)rightArrowX);
1850 	   reply = PackCARD32 (reply,(CARD32)rightArrowY);
1851 	   reply = PackCARD32 (reply,(CARD32)leftArrowX);
1852 	   reply = PackCARD32 (reply,(CARD32)leftArrowY);
1853 	   reply = PackCARD32 (reply,(CARD32)topArrowX);
1854 	   reply = PackCARD32 (reply,(CARD32)topArrowY);
1855 	   reply = PackCARD32 (reply,(CARD32)bottomArrowX);
1856 	   reply = PackCARD32 (reply,(CARD32)bottomArrowY);
1857 	   reply = PackCARD32 (reply,(CARD32)iconBoxX);
1858 	   reply = PackCARD32 (reply,(CARD32)iconBoxY);
1859 	   reply = PackCARD32 (reply,(CARD32)iconBoxWidth);
1860 	   reply = PackCARD32 (reply,(CARD32)iconBoxHeight);
1861 	   reply = PackCARD32 (reply,(CARD32)iconShellWin);
1862 	   reply = PackCARD32 (reply,(CARD32)frameWin);
1863 	   reply = PackCARD32 (reply,(CARD32)scrollWin);
1864 	   reply = PackCARD32 (reply,(CARD32)hScrollWin);
1865 	   reply = PackCARD32 (reply,(CARD32)vScrollWin);
1866 	   reply = PackCARD32 (reply,(CARD32)lastCol);
1867 	   reply = PackCARD32 (reply,(CARD32)lastRow);
1868 	   reply = PackCARD32 (reply,(CARD32)iPlaceH);
1869 	   reply = PackCARD32 (reply,(CARD32)iPlaceW);
1870 
1871 	}
1872 
1873 }
1874 
1875 
1876 
1877 
1878 /*----------------------------------------------------------------------*
1879  |                             GetItemSelectInfo
1880  *----------------------------------------------------------------------*/
1881 
1882 static void
GetWindowItemSelectInfo(ClientData * pcd,XtPointer reply)1883 GetWindowItemSelectInfo(ClientData *pcd, XtPointer reply)
1884 {
1885   MenuSpec *menuSpec;
1886   CARD32 menuItemCount,sensitiveCount;
1887   Window menuWin, frameWin;
1888   CARD32 sensitive[MAX_MENU_ITEMS];
1889   CARD32 itemY[MAX_MENU_ITEMS];
1890   char itemName[MAX_MENU_ITEMS][MAX_NAME_LEN + 1];
1891 
1892   MenuButton              *NewMenuButton;
1893   MenuItem                *NewMenuItem;
1894   int n;
1895 
1896 
1897   menuSpec = pcd->systemMenuSpec;
1898 
1899   if (menuSpec == NULL)
1900     return;
1901 
1902   menuItemCount = menuSpec->menuButtonCount;
1903 
1904   for (n = 0; n < menuItemCount && n < MAX_MENU_ITEMS; n++)
1905     {
1906       itemName[n][0] = '\0';
1907       sensitive[n] = FALSE;
1908     }
1909 
1910   menuWin = XtWindow (menuSpec->menuWidget);
1911   frameWin = pcd->clientFrameWin;
1912 
1913    sensitiveCount = 0;
1914 
1915       for (n = 0, NewMenuButton = menuSpec->menuButtons;
1916 	   n < menuSpec->menuButtonCount;
1917 	   n++, NewMenuButton++)
1918 	{
1919 	  if (NewMenuButton->managed == FALSE)
1920             continue;
1921 
1922 	  NewMenuItem = NewMenuButton->menuItem;
1923 	  sensitive[n] = NewMenuButton->buttonWidget->core.sensitive;
1924 	  itemY[n] = NewMenuButton->buttonWidget->core.y +
1925                             (NewMenuButton->buttonWidget->core.height / 2);
1926 	  strcpy(itemName[n], NewMenuItem->label);
1927 
1928 	  if (sensitive[n] == TRUE)
1929             sensitiveCount++;
1930 	}
1931 
1932       reply = PackCARD32 (reply, (CARD32)menuItemCount);
1933       reply = PackCARD32 (reply, (CARD32)sensitiveCount);
1934       reply = PackCARD32 (reply, (CARD32)menuWin);
1935       reply = PackCARD32 (reply, (CARD32)frameWin);
1936       for (n=0; n < menuItemCount && n < MAX_MENU_ITEMS; n++)
1937 	{
1938 	  reply = PackCARD32 (reply, (CARD32)sensitive[n]);
1939 	  reply = PackCARD32 (reply, (CARD32)itemY[n]);
1940 	  reply = PackString (reply, (String)itemName[n]);
1941 	}
1942 
1943 }
1944 
1945 
1946 /*----------------------------------------------------------------------*
1947  |                             GetItemCheckInfo
1948  *----------------------------------------------------------------------*/
1949 
1950 static void
GetItemCheckInfo(ClientData * pcd,XtPointer reply)1951 GetItemCheckInfo(ClientData *pcd, XtPointer reply)
1952 {
1953   MenuSpec *menuSpec;
1954   int menuItemCount;
1955   int clientState;
1956   int titleGadgetCount;
1957   int titleId, systemId, minimizeId, maximizeId, northwestId;
1958   int upperBorderWidth, lowerBorderWidth;
1959   Window menuWin;
1960   char itemName[MAX_MENU_ITEMS][MAX_NAME_LEN + 1];
1961 
1962   MenuButton              *NewMenuButton;
1963   MenuItem                *NewMenuItem;
1964   int i,filledCount;
1965   Boolean titleFound, systemFound, minimizeFound, maximizeFound = False;
1966 
1967   menuSpec = pcd->systemMenuSpec;
1968 
1969   if (menuSpec == NULL)
1970     return;
1971 
1972   menuItemCount = menuSpec->menuButtonCount;
1973 
1974   for (i = 0; i < menuItemCount && i < MAX_MENU_ITEMS; i++)
1975       itemName[i][0] = '\0';
1976 
1977   menuWin = XtWindow (menuSpec->menuWidget);
1978 
1979       for (i = 0, NewMenuButton = menuSpec->menuButtons;
1980 	   i < menuSpec->menuButtonCount;
1981 	   i++, NewMenuButton++)
1982 	{
1983 	  if (NewMenuButton->managed == FALSE)
1984             continue;
1985 
1986 	  NewMenuItem = NewMenuButton->menuItem;
1987 	  strcpy (itemName[i],NewMenuItem->label);
1988 
1989 	}
1990 
1991       filledCount = pcd->cTitleGadgets;
1992 
1993       for (i=0; i < filledCount; i++)
1994         {
1995           if (pcd->pTitleGadgets[i].id == FRAME_TITLE)
1996 	      {
1997 		  titleId = FRAME_TITLE;
1998 		  titleFound = True;
1999 	      }
2000 	  else
2001           if (pcd->pTitleGadgets[i].id == FRAME_SYSTEM)
2002 	      {
2003 		  systemId = FRAME_SYSTEM;
2004 		  systemFound = True;
2005 	      }
2006 
2007 	  else
2008           if (pcd->pTitleGadgets[i].id == FRAME_MINIMIZE)
2009 	      {
2010 		  minimizeId = FRAME_MINIMIZE;
2011 		  minimizeFound = True;
2012 	      }
2013 	  else
2014           if (pcd->pTitleGadgets[i].id == FRAME_MAXIMIZE)
2015 	      {
2016 		  maximizeId = FRAME_MAXIMIZE;
2017 		  maximizeFound = True;
2018 	      }
2019 
2020 
2021         }
2022 
2023    if (titleFound == False)
2024        titleId = INVALID;
2025    if (systemFound == False)
2026        systemId = INVALID;
2027    if (minimizeFound == False)
2028        minimizeId = INVALID;
2029    if (maximizeFound == False)
2030        maximizeId = INVALID;
2031 
2032    if (!(pcd->decor & MWM_DECOR_RESIZEH))
2033        northwestId = INVALID;
2034    else
2035        northwestId = pcd->pResizeGadgets[WM_NORTHWEST].id;
2036 
2037   upperBorderWidth = pcd->frameInfo.upperBorderWidth;
2038   lowerBorderWidth = pcd->frameInfo.lowerBorderWidth;
2039 
2040 
2041 
2042 
2043   clientState = pcd->clientState;
2044 
2045   reply = PackCARD32 (reply, (CARD32)clientState);
2046   reply = PackCARD32 (reply, (CARD32)menuWin);
2047   reply = PackCARD32 (reply, (CARD32)menuItemCount);
2048   for (i=0; i < menuItemCount && i < MAX_MENU_ITEMS; i++)
2049       reply = PackString (reply, (String)itemName[i]);
2050   reply = PackCARD32 (reply, (CARD32)filledCount);
2051   reply = PackCARD32 (reply, (CARD32)titleId);
2052   reply = PackCARD32 (reply, (CARD32)systemId);
2053   reply = PackCARD32 (reply, (CARD32)minimizeId);
2054   reply = PackCARD32 (reply, (CARD32)maximizeId);
2055   reply = PackCARD32 (reply, (CARD32)northwestId);
2056   reply = PackCARD32 (reply, (CARD32)upperBorderWidth);
2057   reply = PackCARD32 (reply, (CARD32)lowerBorderWidth);
2058 }
2059 
2060 
2061 /*----------------------------------------------------------------------*
2062  |                             GetRaiseInfo
2063  *----------------------------------------------------------------------*/
2064 
2065 static void
GetRaiseInfo(ClientData * pcd,XtPointer reply)2066 GetRaiseInfo(ClientData *pcd, XtPointer reply)
2067 {
2068 
2069   CARD32 state = pcd->clientState;
2070   reply = PackCARD32 (reply, (CARD32)state);
2071 }
2072 
2073 
2074 /*----------------------------------------------------------------------*
2075  |                             GetAutomationData
2076  *----------------------------------------------------------------------*/
2077 void
GetAutomationData(XtPointer input,Atom * outputType,XtPointer * output,unsigned long * outputLen,int * outputFmt)2078 GetAutomationData (XtPointer input, Atom *outputType, XtPointer *output, unsigned long *outputLen, int *outputFmt)
2079 {
2080   ClientData *pcd;
2081   CARD32 infoWanted;
2082 
2083   Window winId;
2084   XtPointer reply;
2085   int size;
2086 
2087   int i, n, menuItemCount = 0;
2088   MenuItem *menu_item;
2089 
2090 
2091 
2092 
2093 
2094   winId        = UnpackCARD32(&input);
2095   infoWanted    = UnpackCARD32(&input);
2096 
2097 
2098 
2099   /*
2100    * Get client data associated with window if the widget making the request.
2101    */
2102 
2103   if ((pcd = GetPCD (0,winId)) == NULL)
2104     {
2105 
2106       PRINT ("Can't get client data\n");
2107       return;
2108     }
2109 
2110 
2111   size = 0;
2112 
2113   switch (infoWanted)
2114       {
2115 	case WINDOW_MINIMIZE_INFO:
2116 	  size += sizeof(CARD32) * 7;
2117 	  *output = (XtPointer)XtMalloc(sizeof(CARD8) * size);
2118 	  GetMinimizeInfo (pcd,*output);
2119           break;
2120 
2121 	case WINDOW_MAXIMIZE_INFO:
2122 	  size += sizeof (CARD32) * 7;
2123 	  *output = (XtPointer)XtMalloc(sizeof(CARD8) * size);
2124 	  GetMaximizeInfo(pcd,*output);
2125           break;
2126 
2127         case WINDOW_RAISE_INFO:
2128 	  size += sizeof (CARD32);
2129 	  *output = (XtPointer)XtMalloc(sizeof(CARD8) * size);
2130 	  GetRaiseInfo(pcd, *output);
2131 	  break;
2132 
2133         case WINDOW_MOVE_INFO:
2134 	   SetGrabServer();    /* tell mwm not to grab server */
2135 	   size += sizeof (CARD32) * 16;
2136 	    *output = (XtPointer)XtMalloc(sizeof(CARD8) * size);
2137 	   GetMoveInfo(pcd,*output);
2138 	   break;
2139 
2140 	case WINDOW_RESIZE_NORTH_INFO:
2141 	  SetGrabServer();    /* tell mwm not to grab server */
2142 	  size += sizeof (CARD32) * 17;
2143 	  *output = (XtPointer)XtMalloc(sizeof(CARD8) * size);
2144 	  GetResizeInfo(pcd,*output,WM_NORTH);
2145 	  break;
2146 
2147 	case WINDOW_RESIZE_SOUTH_INFO:
2148 	  SetGrabServer();    /* tell mwm not to grab server */
2149 	  size += sizeof (CARD32) * 17;
2150 	  *output = (XtPointer)XtMalloc(sizeof(CARD8) * size);
2151 	  GetResizeInfo(pcd,*output,WM_SOUTH);
2152 	  break;
2153 
2154 	case WINDOW_RESIZE_EAST_INFO:
2155 	  SetGrabServer();    /* tell mwm not to grab server */
2156 	  size += sizeof (CARD32) * 17;
2157 	  *output = (XtPointer)XtMalloc(sizeof(CARD8) * size);
2158 	  GetResizeInfo(pcd,*output,WM_EAST);
2159 	  break;
2160 
2161 	case WINDOW_RESIZE_WEST_INFO:
2162 	  SetGrabServer();    /* tell mwm not to grab server */
2163 	  size += sizeof (CARD32) * 17;
2164 	  *output = (XtPointer)XtMalloc(sizeof(CARD8) * size);
2165 	  GetResizeInfo(pcd,*output,WM_WEST);
2166 	  break;
2167 
2168 	case WINDOW_RESIZE_NORTHEAST_INFO:
2169 	  SetGrabServer();    /* tell mwm not to grab server */
2170 	  size += sizeof (CARD32) * 17;
2171 	  *output = (XtPointer)XtMalloc(sizeof(CARD8) * size);
2172 	  GetResizeInfo(pcd,*output,WM_NORTHEAST);
2173 	  break;
2174 
2175 
2176 	case WINDOW_RESIZE_NORTHWEST_INFO:
2177 	  SetGrabServer();    /* tell mwm not to grab server */
2178 	  size += sizeof (CARD32) * 17;
2179 	  *output = (XtPointer)XtMalloc(sizeof(CARD8) * size);
2180 	  GetResizeInfo(pcd,*output,WM_NORTHWEST);
2181 	  break;
2182 
2183 
2184 	case WINDOW_RESIZE_SOUTHEAST_INFO:
2185 	  SetGrabServer();    /* tell mwm not to grab server */
2186 	  size += sizeof (CARD32) * 17;
2187 	  *output = (XtPointer)XtMalloc(sizeof(CARD8) * size);
2188 	  GetResizeInfo(pcd,*output,WM_SOUTHEAST);
2189 	  break;
2190 
2191 
2192 	case WINDOW_RESIZE_SOUTHWEST_INFO:
2193 	  SetGrabServer();    /* tell mwm not to grab server */
2194 	  size += sizeof (CARD32) * 17;
2195 	  *output = (XtPointer)XtMalloc(sizeof(CARD8) * size);
2196 	  GetResizeInfo(pcd,*output,WM_SOUTHWEST);
2197 	  break;
2198 
2199 
2200 	case WINDOW_MENU_ITEM_SELECT_INFO:
2201 	  if (pcd->systemMenuSpec)
2202 	      menuItemCount = pcd->systemMenuSpec->menuButtonCount;
2203 	  size += sizeof(CARD32) * 4;
2204 	  for (n=0; n < menuItemCount && n < MAX_MENU_ITEMS; n++)
2205 	      {
2206 		  menu_item = pcd->systemMenuSpec->menuButtons->menuItem;
2207 		  size += sizeof (CARD32);    /* sensitive */
2208 		  size += sizeof (CARD32);    /* itemY */
2209 		  size += sizeof (CARD16) + ((strlen(menu_item->label) + 1) * sizeof(CARD8)); /*itemName */
2210 	      }
2211 	 *output = (XtPointer)XtMalloc(sizeof(CARD8) * size);
2212 	  GetWindowItemSelectInfo(pcd,*output);
2213 	  break;
2214 
2215 	case WINDOW_DEICONIFY_INFO:
2216 	  if (pcd->pSD->useIconBox == True)
2217 	      {
2218 		  size += sizeof (CARD32) * 37;
2219 		  *output = (XtPointer)XtMalloc(sizeof(CARD8) * size);
2220 		  GetIconInfo(pcd,*output,True);
2221 	      }
2222 	  else
2223 	      {
2224 		  size += sizeof (CARD32) * 6;
2225 		  *output = (XtPointer)XtMalloc(sizeof(CARD8) * size);
2226 		  GetIconInfo(pcd,*output,False);
2227 	      }
2228 	  break;
2229 
2230 
2231 	case WINDOW_MENU_POST_INFO:
2232 	   size += sizeof (CARD32) * 12;
2233 	   *output = (XtPointer)XtMalloc(sizeof(CARD8) * size);
2234 	   GetWindowMenuPostInfo(pcd,*output);
2235 	   break;
2236 
2237 	case WINDOW_FOCUS_INFO:
2238 	   size += sizeof (CARD32) * 7;
2239 	   *output = (XtPointer)XtMalloc(sizeof(CARD8) * size);
2240 	   GetFocusInfo(pcd,*output);
2241 	   break;
2242 
2243 
2244 	case WINDOW_MENU_UNPOST_INFO:
2245 	   size += sizeof (CARD32) * 3;
2246 	   *output = (XtPointer)XtMalloc(sizeof(CARD8) * size);
2247 	   GetWindowMenuUnpostInfo(pcd,*output);
2248 	   break;
2249 
2250 	case WINDOW_MENU_ITEM_CHECK_INFO:
2251 	  if (pcd->systemMenuSpec)
2252 	      menuItemCount = pcd->systemMenuSpec->menuButtonCount;
2253 	  size += sizeof(CARD32) * 11;
2254 	  for (n=0; n < menuItemCount && n < MAX_MENU_ITEMS; n++)
2255 	      {
2256 		  menu_item = pcd->systemMenuSpec->menuButtons->menuItem;
2257 		  size += sizeof (CARD16) + (strlen(menu_item->label + 1) * sizeof(CARD8)); /*itemName */
2258 	      }
2259 	 *output = (XtPointer)XtMalloc(sizeof(CARD8) * size);
2260 	  GetItemCheckInfo(pcd, *output);
2261 	  break;
2262 
2263 	case ICON_MOVE_INFO:
2264 	  {
2265 	      SetGrabServer();    /* tell mwm not to grab server */
2266 	      size += sizeof (CARD32) * 6;
2267 	      *output = (XtPointer)XtMalloc(sizeof(CARD8) * size);
2268 	      GetIconInfo(pcd,*output,False);
2269 	      break;
2270 	  }
2271 
2272 	case ICON_MENU_POST_INFO:
2273 	  if (pcd->pSD->useIconBox == True)
2274 	      {
2275 		  size += sizeof (CARD32) * 37;
2276 		  *output = (XtPointer)XtMalloc(sizeof(CARD8) * size);
2277 		  GetIconInfo(pcd,*output,True);
2278 	      }
2279 	  else
2280 	      {
2281 		  size += sizeof (CARD32) * 6;
2282 		  *output = (XtPointer)XtMalloc(sizeof(CARD8) * size);
2283 		  GetIconInfo(pcd,*output,False);
2284 	      }
2285 	  break;
2286 
2287 	case ICON_MENU_UNPOST_INFO:
2288 	  if (pcd->pSD->useIconBox == True)
2289 	      {
2290 		  size += sizeof (CARD32) * 37;
2291 		  *output = (XtPointer)XtMalloc(sizeof(CARD8) * size);
2292 		  GetIconInfo(pcd,*output,True);
2293 
2294 	      }
2295 	  else
2296 	      {
2297 		  size += sizeof (CARD32) * 6;
2298 		  *output = (XtPointer)XtMalloc(sizeof(CARD8) * size);
2299 		  GetIconInfo(pcd,*output,False);
2300 	      }
2301 	  break;
2302 
2303 	case ICON_MENU_ITEM_SELECT_INFO:
2304 	  if (pcd->systemMenuSpec)
2305 	      menuItemCount = pcd->systemMenuSpec->menuButtonCount;
2306 	  size += sizeof(CARD32) * 11;
2307 	  for (n=0; n < menuItemCount && n < MAX_MENU_ITEMS; n++)
2308 	      {
2309 		  size += sizeof (CARD32);    /* sensitive */
2310 		  size += sizeof (CARD32);    /* itemY */
2311 		  menu_item = pcd->systemMenuSpec->menuButtons->menuItem;
2312 		  size += sizeof (CARD16) + ((strlen(menu_item->label) + 1) * sizeof(CARD8)); /*itemName */
2313 	      }
2314 	  if (pcd->pSD->useIconBox == True)
2315 		  size += sizeof (CARD32) * 37;
2316 	  else
2317 	  	  size += sizeof (CARD32) * 6;
2318 	  *output = (XtPointer)XtMalloc(sizeof(CARD8) * size);
2319 	  GetIconMenuItemSelectInfo (pcd,*output,pcd->pSD->useIconBox);
2320 	  break;
2321 
2322 
2323 	default:
2324 	  PRINT ("Illegal operation from Automation");
2325 	  break;
2326       }
2327 
2328 	*outputLen = (unsigned long)size;
2329 	*outputFmt = WSM_PROTO_FMT;
2330 
2331 }
2332 
2333