3 * (c) Copyright 1987, 1988, 1989, 1990, 1992 HEWLETT-PACKARD COMPANY
8 static char rcsid[] = "$XConsortium: WmPresence.c /main/7 1996/10/23 17:24:56 rswiston $"
17 #include "WmResNames.h"
21 #include <X11/StringDefs.h>
22 #include <X11/Intrinsic.h>
23 #include <X11/Xatom.h>
24 #include <X11/Shell.h>
27 #include <Xm/PushBG.h>
28 #include <Xm/LabelG.h>
30 #include <Xm/SeparatoG.h>
31 #include <Xm/ToggleB.h>
40 * Function Declarations:
43 #include "WmPresence.h"
45 /******** Static Function Declarations ********/
47 static void wspSetWindowName(
48 PtrWsPresenceData pPres) ;
49 static Boolean wspCreateWidgets(
51 static Widget wspCreateShell(
53 static Widget wspCreateManager(
55 static Widget wspCreateLabel(
57 unsigned char *pchName,
58 unsigned char *pchString) ;
59 static Widget wspCreateSeparator(
61 static Widget wspCreateWorkspaceList(
63 PtrWsPresenceData pPres,
65 static void wspUpdateWorkspaceList(
66 PtrWsPresenceData pPres) ;
67 static Widget wspCreateToggleButton(
70 static Widget wspCreatePushButton(
74 static void wspSetPosition(
75 PtrWsPresenceData pPres) ;
76 static void wspLayout(
77 PtrWsPresenceData pPres) ;
81 XtPointer call_data) ;
82 static void wspHelpCB(
84 XtPointer client_data,
85 XtPointer call_data) ;
86 static void wspAllWsCB(
89 XmToggleButtonCallbackStruct *xmTbcs) ;
90 static void wspCancelCB(
92 XtPointer client_data,
93 XtPointer call_data) ;
94 static void wspExtendedSelectCB(
96 XtPointer client_data,
97 XmListCallbackStruct *cb );
98 static Dimension wspCharWidth (
101 /******** End Static Function Declarations ********/
104 * External references
106 #include "WmCDecor.h"
107 #include "WmCDInfo.h"
108 #include "WmIconBox.h"
110 #include "WmPanelP.h" /* for typedef in WmManage.h */
111 #endif /* PANELIST */
112 #include "WmManage.h"
113 #include "WmResParse.h"
114 #include "WmResource.h"
115 #include "WmWinInfo.h"
116 #include "WmWrkspace.h"
123 * These two XmStrings are used in the workspace
124 * presence box to indicate the name of the current
125 * window for whice the presence box is active. If the
126 * window is iconified, the title will be "Icon: <iconName>",
127 * otherwise the title wil be "Window: <windowName>
129 XmString windowLabelString = (XmString)NULL;
130 XmString iconLabelString = (XmString)NULL;
132 /*************************************<->*************************************
135 * MakePresenceBox (pSD)
144 * pSD = pointer to screen data
149 * Return = (Boolean) True if successful
155 ******************************<->***********************************/
162 PtrWsPresenceData pPres = &pSD->presence;
166 * Create the widgets for the workspace presence dialog
169 pPres->onScreen = False;
171 if (wspCreateWidgets (pSD))
179 * Set the ClientData fields.
181 XtRealizeWidget (pPres->shellW);
183 DtWsmRemoveWorkspaceFunctions (DISPLAY1, XtWindow(pPres->shellW));
184 #endif /* PANELIST */
186 ProcessPresenceResources (pSD);
192 Warning(((char *)GETMESSAGE(52, 1, "Unable to create Occupy Workspace dialog.")));
198 } /* END OF FUNCTION MakePresenceBox */
201 /*************************************<->*************************************
204 * ShowPresenceBox (pClient, wsContext)
209 * Pops up (shows) the workspace presence dialog
213 * pClient = pointer to client data which needs a presence dialog
214 * up. (This is not the presence dialog's client data!!!)
216 * wsContext = context to post dialog for
227 ******************************<->***********************************/
234 PtrWsPresenceData pPres;
237 pPres = &pClient->pSD->presence;
239 pPres->pCDforClient = pClient;
240 pPres->contextForClient = wsContext;
243 * Create the presence dialog if not done yet.
245 if (!pSD->presence.shellW)
247 pPres->ItemSelected = NULL;
248 pPres->ItemStrings = NULL;
249 pPres->currentWsItem = 0;
251 MakePresenceBox (pSD);
256 HidePresenceBox (pSD, True);
259 /* update workspace list */
260 wspUpdateWorkspaceList (pPres);
262 /* set position of dialog relative to client window */
263 wspSetPosition (pPres);
268 XtPopup (pPres->shellW, XtGrabNone);
269 pPres->onScreen = True;
270 } /* END OF FUNCTION ShowPresenceBox */
273 /*************************************<->*************************************
276 * wspSetWindowName (pPres)
281 * Sets the name of the current window in the presence dialog
285 * pPres = ptr to workspace presence dialog data
295 ******************************<->***********************************/
299 PtrWsPresenceData pPres )
307 * Set the name of the current window
312 if (pPres->contextForClient == F_CONTEXT_ICON)
314 XtSetArg (nameArgs[nameN], XmNlabelString,
315 pPres->pCDforClient->iconTitle); nameN++;
316 XtSetArg (labelArgs[labelN], XmNlabelString,
317 iconLabelString); labelN++;
321 XtSetArg (nameArgs[nameN], XmNlabelString,
322 pPres->pCDforClient->clientTitle); nameN++;
323 XtSetArg (labelArgs[labelN], XmNlabelString,
324 windowLabelString); labelN++;
327 XtSetValues (pPres->windowNameW, nameArgs, nameN);
328 XtSetValues (pPres->windowLabelW, labelArgs, labelN);
330 } /* END OF FUNCTION wspSetWindowName */
333 /*************************************<->*************************************
336 * HidePresenceBox (pSD, userDismissed)
341 * Pops down (hides) the workspace presence dialog
345 * pSD = pointer to screen data
346 * userDismissed = did the user dismiss or did workspace switching
347 * unpost the workspace presence box ?
357 ******************************<->***********************************/
362 Boolean userDismissed )
365 if (pSD->presence.onScreen)
367 /* Pop down the shell */
368 XtPopdown (pSD->presence.shellW);
371 * Do a withdraw to make sure window gets unmanaged
372 * (popdown does nothing if its unmapped)
374 XWithdrawWindow (DISPLAY, XtWindow (pSD->presence.shellW),
376 /* must sync to insure event order */
377 XSync (DISPLAY, False);
380 pSD->presence.onScreen = False;
381 pSD->presence.userDismissed = userDismissed;
383 } /* END OF FUNCTION */
386 /*************************************<->*************************************
388 * wspCreateWidgets (pSD)
393 * Creates all the widgets for the workspace presence dialog box
397 * pSD = pointer to screen data
401 * Return = false on any failure
405 * Only creates widgets
406 ******************************<->***********************************/
411 PtrWsPresenceData pPres = &pSD->presence;
414 Boolean rval /* = True */;
415 #ifdef NO_MESSAGE_CATALOG
416 XmString tmpXmString;
417 #endif /* NO_MESSAGE_CATALOG */
419 rval = ((pPres->shellW = wspCreateShell (pSD)) != NULL);
423 rval = ((pPres->formW = wspCreateManager (pPres->shellW)) != NULL);
428 rval = ((pPres->windowLabelW = wspCreateLabel (pPres->formW,
429 (unsigned char *)"window",
435 rval = ((pPres->windowNameW = wspCreateLabel (pPres->formW,
436 (unsigned char *)"windowName",
437 (unsigned char *)" ")) != NULL);
442 rval = ((pPres->workspaceLabelW =
443 wspCreateLabel (pPres->formW, (unsigned char *)"workspaces",
444 ((unsigned char *)GETMESSAGE(52, 3, "Workspaces: ")))) != NULL);
449 rval = ((pPres->workspaceListW =
450 wspCreateWorkspaceList (pPres->formW, pPres, pSD)) != NULL);
451 pPres->workspaceScrolledListW = XtParent (pPres->workspaceListW);
456 rval = ((pPres->allWsW = wspCreateToggleButton (pPres->formW,
457 ((unsigned char *)GETMESSAGE(52, 4, "All Workspaces"))))
459 XtAddCallback (pPres->allWsW, XmNvalueChangedCallback,
460 (XtCallbackProc)wspAllWsCB, (XtPointer)pSD);
465 rval = ((pPres->sepW = wspCreateSeparator (pPres->formW)) != NULL);
470 #ifndef NO_MESSAGE_CATALOG
471 rval = ((pPres->OkW =
472 wspCreatePushButton (pPres->formW, "ok", wmGD.okLabel))
475 tmpXmString = XmStringCreateLocalized ("OK");
476 rval = ((pPres->OkW =
477 wspCreatePushButton (pPres->formW, "ok", tmpXmString))
479 XmStringFree(tmpXmString);
482 /* set the default action */
484 XtSetArg (args[n], XmNdefaultButton, pPres->OkW); n++;
485 XtSetValues (pPres->formW, args, n);
487 XtAddCallback (pPres->OkW, XmNactivateCallback,
488 (XtCallbackProc) wspOkCB, (XtPointer)pSD);
493 #ifndef NO_MESSAGE_CATALOG
494 rval = ((pPres->CancelW = wspCreatePushButton (pPres->formW,
495 "cancel", wmGD.cancelLabel)) != NULL);
497 tmpXmString = XmStringCreateLocalized ("Cancel");
498 rval = ((pPres->CancelW =
499 wspCreatePushButton (pPres->formW, "cancel", tmpXmString))
501 XmStringFree(tmpXmString);
503 XtAddCallback (pPres->CancelW, XmNactivateCallback,
504 (XtCallbackProc) wspCancelCB, (XtPointer)pSD);
506 /* set the cancel button (for KCancel) */
508 XtSetArg (args[n], XmNcancelButton, pPres->CancelW); n++;
509 XtSetValues (pPres->formW, args, n);
514 #ifndef NO_MESSAGE_CATALOG
515 rval = ((pPres->HelpW =
516 wspCreatePushButton (pPres->formW, "help", wmGD.helpLabel))
519 tmpXmString = XmStringCreateLocalized ("Help");
520 rval = ((pPres->HelpW =
521 wspCreatePushButton (pPres->formW, "help", tmpXmString))
523 XmStringFree(tmpXmString);
527 XtAddCallback (pPres->HelpW, XmNactivateCallback,
529 WM_DT_WSPRESENCE_TOPIC);
531 XtAddCallback (pPres->HelpW, XmNactivateCallback,
532 (XtCallbackProc) wspHelpCB, (XtPointer)pSD);
533 #endif /* PANELIST */
537 } /* END OF FUNCTION */
541 /*************************************<->*************************************
544 * wspCreateShell (pSD)
549 * Creates the shell widget for the workspace presence dialog
554 * psD = pointer to screen data
558 * Return = shell widget created
560 ******************************<->***********************************/
570 * Create top level shell for workspace presence dialog
575 XtSetArg (setArgs[i], XmNallowShellResize, (XtArgVal)True); i++;
577 XtSetArg (setArgs[i], XmNborderWidth, (XtArgVal)0); i++;
579 XtSetArg (setArgs[i], XmNkeyboardFocusPolicy,
580 (XtArgVal)XmEXPLICIT); i++;
582 XtSetArg (setArgs[i], XmNmappedWhenManaged,
583 (XtArgVal)False); i++;
585 XtSetArg (setArgs[i], XmNmwmFunctions,
586 PRESENCE_BOX_FUNCTIONS); i++;
588 XtSetArg (setArgs[i], XmNmwmDecorations,
589 (MWM_DECOR_TITLE|MWM_DECOR_BORDER)); i++;
591 XtSetArg (setArgs[i], XmNdepth,
592 (XtArgVal) DefaultDepth (DISPLAY1, pSD->screen)); i++;
594 XtSetArg (setArgs[i], XmNscreen, (XtArgVal)
595 ScreenOfDisplay (DISPLAY1, pSD->screen)); i++;
597 XtSetArg (setArgs[i], XtNcolormap,
598 (XtArgVal )DefaultColormap(DISPLAY1, pSD->screen)); i++;
600 shellW = (Widget) XtCreatePopupShell (WmNfeedback,
601 transientShellWidgetClass,
602 pSD->screenTopLevelW1,
603 (ArgList)setArgs, i);
607 } /* END OF FUNCTION wspCreateShell */
610 /*************************************<->*************************************
612 * wspCreateManager (shellW)
617 * Creates the manager widget for the workspace presence dialog
627 * Creates a form widget
628 ******************************<->***********************************/
637 /* !!! set colors? !!! */
639 formW = (Widget) XmCreateForm (shellW, "form", (ArgList) setArgs, 0);
641 XtAddCallback (formW, XmNhelpCallback,
642 WmDtWmTopicHelpCB, WM_DT_WSPRESENCE_TOPIC);
644 XtManageChild (formW);
647 } /* END OF FUNCTION */
651 /*************************************<->*************************************
653 * wspCreateLabel (mgrW, pchName, pchString)
658 * Creates a label widget as a child of the passed in manager
662 * mgrW = manager widget (parent of this label)
663 * pchName = name of the widget
664 * pchString = string that is to be in label
668 * Return = Widget created.
672 ******************************<->***********************************/
676 unsigned char *pchName,
677 unsigned char *pchString )
682 XmString tmpXmString = (XmString)NULL;
686 if (!strcmp((char *)pchName, "window"))
688 if (windowLabelString != (XmString)NULL)
689 XmStringFree(windowLabelString);
690 if (iconLabelString != (XmString)NULL)
691 XmStringFree(iconLabelString);
694 XmStringCreateLocalized ((char *)GETMESSAGE(52, 2, "Window: "));
696 * If we do this, USE the message catalog for iconLabelString
697 * just as we do for windowLabelString !!!
700 XmStringCreateLocalized ((char *)GETMESSAGE(52, 6, "Icon: "));
702 XtSetArg (setArgs[i], XmNlabelString, windowLabelString ); i++;
706 tmpXmString = XmStringCreateLocalized ((char *)pchString);
707 XtSetArg (setArgs[i], XmNlabelString, tmpXmString); i++;
710 labelW = XmCreateLabelGadget (mgrW, (char *)pchName, setArgs, i);
711 XtManageChild (labelW);
713 if (tmpXmString != (XmString)NULL)
714 XmStringFree(tmpXmString);
717 } /* END OF FUNCTION */
720 /*************************************<->*************************************
722 * wspCreateSeparator (mgrW)
727 * Creates a separator widget as a child of the passed in manager
731 * mgrW = manager widget (parent of this label)
735 * Return = Widget created.
739 ******************************<->***********************************/
750 sepW = XmCreateSeparatorGadget (mgrW, "separator", setArgs, i);
751 XtManageChild (sepW);
754 } /* END OF FUNCTION */
758 /*************************************<->*************************************
760 * wspCreateWorkspaceList (mgrW, pPres, pSD)
765 * Creates a list widget containing all the workspaces defined for a
770 * mgrW = manager widget (parent of this child)
771 * pPres = pointer to presence data
772 * pSD = ptr to screen data
776 * Return = widget created.
780 ******************************<->***********************************/
782 wspCreateWorkspaceList(
784 PtrWsPresenceData pPres,
792 #define MIN_VISIBLE 6
795 * Create the array of strings that will go into the list.
797 if (((pPres->ItemStrings = (XmStringTable) XtMalloc
798 (pSD->numWorkspaces * sizeof(XmString *))) == NULL) ||
799 ((pPres->ItemSelected = (Boolean *) XtMalloc
800 (pSD->numWorkspaces * sizeof(Boolean))) == NULL))
802 Warning (((char *)GETMESSAGE(52, 5, "Insufficient memory to create Occupy Workspace dialog.")));
806 pPres->numWorkspaces = pSD->numWorkspaces;
808 for (i = 0; i < pSD->numWorkspaces; i++)
810 pPres->ItemStrings[i] = XmStringCopy (pSD->pWS[i].title);
812 if (pSD->pWS[i].id == pSD->pActiveWS->id)
814 pPres->currentWsItem = 1+i;
824 XtSetArg (setArgs[i], XmNitemCount, pSD->numWorkspaces); i++;
826 XtSetArg (setArgs[i], XmNitems, pPres->ItemStrings); i++;
828 XtSetArg (setArgs[i], XmNselectionPolicy, XmEXTENDED_SELECT); i++;
830 XtSetArg (setArgs[i], XmNlistSizePolicy, XmRESIZE_IF_POSSIBLE); i++;
832 listW = XmCreateScrolledList (mgrW, "list", setArgs, i);
833 XtManageChild (listW);
835 if (pPres->pCDforClient)
838 * Highlight the workspaces this client resides in
840 for (i = 0; i < pPres->pCDforClient->pSD->numWorkspaces; i++)
842 if (ClientInWorkspace (&pPres->pCDforClient->pSD->pWS[i],
843 pPres->pCDforClient))
845 XmListSelectPos (listW, i+1, TRUE);
846 pPres->ItemSelected[i] = True;
850 pPres->ItemSelected[i] = False;
856 * Insure a minimum number are visible.
859 XtSetArg (setArgs[i], XmNvisibleItemCount, &numVisible); i++;
860 XtGetValues (listW, setArgs, i);
862 if (numVisible < MIN_VISIBLE)
865 XtSetArg (setArgs[i], XmNvisibleItemCount, MIN_VISIBLE);i++;
866 XtSetValues (listW, setArgs, i);
869 XtAddCallback (listW, XmNextendedSelectionCallback,
870 (XtCallbackProc) wspExtendedSelectCB, (XtPointer)pSD);
871 /* Handle the double-click just like if the Ok button was pressed */
872 XtAddCallback (listW, XmNdefaultActionCallback,
873 (XtCallbackProc) wspOkCB, (XtPointer)pSD);
877 } /* END OF FUNCTION */
880 /*************************************<->*************************************
882 * wspUpdateWorkspaceList (pPres)
887 * Updates the list widget containing all the workspaces.
888 * Sets the ones for this client.
892 * pPres = ptr to presence dialog data
900 ******************************<->***********************************/
902 wspUpdateWorkspaceList(
903 PtrWsPresenceData pPres )
906 XmString xmsTmp, *pxmsSelected;
909 int wsnum, numSelected;
912 * Update the list of workspaces to -- one may have been
913 * renamed since the last time we were up.
915 pSD = pPres->pCDforClient->pSD;
916 for (wsnum = 0; wsnum < pSD->numWorkspaces; wsnum++)
918 xmsTmp = XmStringCopy (pSD->pWS[wsnum].title);
920 if (!XmStringCompare (xmsTmp, pPres->ItemStrings[wsnum]))
923 * Replace the string in our local list
925 XmStringFree (pPres->ItemStrings[wsnum]);
926 pPres->ItemStrings[wsnum] = xmsTmp;
929 * Replace the item in the scrolled list.
931 XmListDeletePos (pPres->workspaceListW, 1+wsnum);
932 XmListAddItem (pPres->workspaceListW, xmsTmp, 1+wsnum);
936 XmStringFree (xmsTmp);
941 * Highlight the workspaces this client resides in
943 XmListDeselectAllItems (pPres->workspaceListW);
944 pxmsSelected = (XmString *)
945 XtMalloc (pPres->pCDforClient->pSD->numWorkspaces * sizeof (XmString));
947 for (wsnum = 0; wsnum < pPres->pCDforClient->pSD->numWorkspaces; wsnum++)
949 if (ClientInWorkspace (&pPres->pCDforClient->pSD->pWS[wsnum],
950 pPres->pCDforClient))
952 pxmsSelected[numSelected++] = pPres->ItemStrings[wsnum];
953 pPres->ItemSelected[wsnum] = True;
957 pPres->ItemSelected[wsnum] = False;
958 pPres->pCDforClient->putInAll = False;
961 if (pPres->pCDforClient->pSD->pActiveWS->id ==
962 pPres->pCDforClient->pSD->pWS[wsnum].id)
964 /* save item number of current workspace */
965 pPres->currentWsItem = 1+wsnum;
969 /* set the selected items */
971 XtSetArg (args[n], XmNselectedItems, pxmsSelected); n++;
972 XtSetArg (args[n], XmNselectedItemCount, numSelected); n++;
973 XtSetValues (pPres->workspaceListW, args, n);
975 /* set state of all workspaces button */
977 XtSetArg (args[n], XmNset, pPres->pCDforClient->putInAll); n++;
978 XtSetValues (pPres->allWsW, args, n);
980 /* set name of window we're popped up for */
981 wspSetWindowName (pPres);
983 XtFree ((char *) pxmsSelected);
985 } /* END OF FUNCTION */
988 /*************************************<->*************************************
990 * wspCreateToggleButton (mgrW, pch)
995 * Creates a toggle button as a child of mgrW with the string pch.
999 * mgrW = parent widget
1000 * pch = string to use for toggle button
1004 * Return = widget created
1008 ******************************<->***********************************/
1010 wspCreateToggleButton(
1012 unsigned char *pch )
1017 XmString labelString;
1021 labelString = XmStringCreateLocalized ((char *)pch);
1022 XtSetArg (setArgs[i], XmNlabelString, labelString); i++;
1024 toggleW = XmCreateToggleButton (mgrW, (char *)pch, setArgs, i);
1026 XmStringFree(labelString);
1028 XtManageChild (toggleW);
1032 } /* END OF FUNCTION wspCreateToggleButton */
1035 /*************************************<->*************************************
1037 * wspCreatePushButton (mgrW, label)
1042 * Creates a push button as a child of mgrW with the string pch.
1046 * mgrW = parent widget
1047 * label = XmString to use for button label
1051 * Return = widget created
1055 ******************************<->***********************************/
1057 wspCreatePushButton(
1069 XtSetArg (setArgs[i], XmNlabelString, label); i++;
1071 pushW = (Widget) XmCreatePushButton (mgrW, name, setArgs, i);
1073 XtManageChild (pushW);
1077 } /* END OF FUNCTION wspCreatePushButton */
1080 /*************************************<->*************************************
1082 * wspSetPosition (pPres)
1087 * Sets the position of the workspace presence dialog
1091 * pPres = pointer to workspace presence data
1096 ******************************<->***********************************/
1099 PtrWsPresenceData pPres )
1101 WmScreenData *pSD = pPres->pCDforClient->pSD;
1109 * Get size of this dialog
1112 XtSetArg (args[n], XmNheight, &height); n++;
1113 XtGetValues (pPres->shellW, args, n);
1115 if (wmGD.positionIsFrame)
1117 if (pSD->decoupleTitleAppearance)
1119 font = pSD->clientTitleAppearance.font;
1123 font = pSD->clientAppearance.font;
1126 height += TEXT_HEIGHT(font) + (2 * pSD->frameBorderWidth);
1131 * set position of dialog relative to client window
1132 * (use system menu position)
1133 * set this dialog to be transient for the client
1134 * for which it is posted.
1136 GetSystemMenuPosition (pPres->pCDforClient,
1138 pPres->contextForClient);
1141 XtSetArg (args[n], XmNx, x); n++;
1142 XtSetArg (args[n], XmNy, y); n++;
1143 XtSetArg (args[n], XmNtransientFor, NULL); n++;
1144 if (pPres->contextForClient != F_CONTEXT_ICON)
1146 XtSetArg (args[n], XmNwindowGroup, pPres->pCDforClient->client); n++;
1148 else if (pSD->useIconBox && P_ICON_BOX(pPres->pCDforClient))
1150 XtSetArg (args[n], XmNwindowGroup,
1151 P_ICON_BOX(pPres->pCDforClient)->pCD_iconBox->client); n++;
1155 XtSetArg (args[n], XmNwindowGroup, 0); n++;
1157 XtSetArg (args[n], XmNwaitForWm, False); n++;
1159 XtSetValues (pPres->shellW, args, n);
1161 } /* END OF FUNCTION wspSetPosition */
1164 /*************************************<->*************************************
1166 * wspCharWidth (xmfl)
1171 * Returns the max logical character width for this fontList
1180 * max logical character width
1184 ******************************<->***********************************/
1190 XmFontListEntry entry;
1191 Dimension dWidth, dTmpWidth;
1194 XFontSetExtents *pExtents;
1196 XmFontListInitFontContext ( &fc, xmfl);
1200 entry = XmFontListNextEntry (fc);
1203 pFont = XmFontListEntryGetFont (entry, &type);
1207 case XmFONT_IS_FONT:
1208 dTmpWidth = ((XFontStruct *)pFont)->max_bounds.rbearing -
1209 ((XFontStruct *)pFont)->min_bounds.lbearing;
1212 case XmFONT_IS_FONTSET:
1213 pExtents = XExtentsOfFontSet ((XFontSet) pFont);
1214 dTmpWidth = pExtents->max_logical_extent.width;
1222 if (dTmpWidth > dWidth)
1225 entry = XmFontListNextEntry (fc);
1228 XmFontListFreeFontContext (fc);
1234 /*************************************<->*************************************
1241 * Lays out the workspace presence dialog
1246 * pPres = pointer to workspace presence data
1254 ******************************<->***********************************/
1257 PtrWsPresenceData pPres )
1262 #define SEP_OFFSET 10
1263 #define IW_OFFSET_1 8
1264 #define IW_OFFSET_0 4
1268 XtSetArg (args[n], XmNtopAttachment, XmATTACH_POSITION); n++;
1269 XtSetArg (args[n], XmNtopPosition, 5); n++;
1270 XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); n++;
1271 XtSetArg (args[n], XmNleftOffset, 5); n++;
1272 XtSetArg (args[n], XmNrightAttachment, XmATTACH_NONE); n++;
1273 XtSetArg (args[n], XmNbottomAttachment, XmATTACH_NONE); n++;
1274 XtSetValues (pPres->windowLabelW, args, n);
1277 XtSetArg (args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
1278 XtSetArg (args[n], XmNtopWidget, pPres->windowLabelW); n++;
1279 XtSetArg (args[n], XmNtopOffset, IW_OFFSET_0); n++;
1280 XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); n++;
1281 XtSetArg (args[n], XmNleftOffset, 5); n++;
1282 XtSetArg (args[n], XmNrightAttachment, XmATTACH_NONE); n++;
1283 XtSetArg (args[n], XmNbottomAttachment, XmATTACH_NONE); n++;
1284 XtSetArg (args[n], XmNbottomOffset, 0); n++;
1285 XtSetValues (pPres->workspaceLabelW, args, n);
1288 XtSetArg (args[n], XmNtopAttachment, XmATTACH_POSITION); n++;
1289 XtSetArg (args[n], XmNtopPosition, 5); n++;
1290 XtSetArg (args[n], XmNleftAttachment, XmATTACH_WIDGET); n++;
1291 XtSetArg (args[n], XmNleftWidget, pPres->workspaceLabelW); n++;
1292 XtSetArg (args[n], XmNleftOffset, 5); n++;
1293 XtSetArg (args[n], XmNrightAttachment, XmATTACH_FORM); n++;
1294 XtSetArg (args[n], XmNrightOffset, 5); n++;
1295 XtSetArg (args[n], XmNbottomAttachment, XmATTACH_NONE); n++;
1296 XtSetArg (args[n], XmNbottomOffset, 0); n++;
1297 XtSetArg (args[n], XmNalignment, XmALIGNMENT_BEGINNING); n++;
1298 XtSetValues (pPres->windowNameW, args, n);
1301 XtSetArg (args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
1302 XtSetArg (args[n], XmNtopWidget, pPres->windowNameW); n++;
1303 XtSetArg (args[n], XmNtopOffset, IW_OFFSET_0); n++;
1304 XtSetArg (args[n], XmNleftAttachment, XmATTACH_WIDGET); n++;
1305 XtSetArg (args[n], XmNleftWidget, pPres->workspaceLabelW); n++;
1306 XtSetArg (args[n], XmNleftOffset, 5); n++;
1307 XtSetArg (args[n], XmNrightAttachment, XmATTACH_FORM); n++;
1308 XtSetArg (args[n], XmNrightOffset, 5); n++;
1309 XtSetArg (args[n], XmNbottomAttachment, XmATTACH_NONE); n++;
1310 XtSetArg (args[n], XmNbottomOffset, 0); n++;
1311 XtSetValues (pPres->workspaceScrolledListW, args, n);
1314 XtSetArg (args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
1315 XtSetArg (args[n], XmNtopWidget, pPres->workspaceScrolledListW); n++;
1316 XtSetArg (args[n], XmNtopOffset, IW_OFFSET_1); n++;
1317 XtSetArg (args[n], XmNleftAttachment, XmATTACH_WIDGET); n++;
1318 XtSetArg (args[n], XmNleftWidget, pPres->workspaceLabelW); n++;
1319 XtSetArg (args[n], XmNleftOffset, 5); n++;
1320 XtSetArg (args[n], XmNrightAttachment, XmATTACH_FORM); n++;
1321 XtSetArg (args[n], XmNrightOffset, 5); n++;
1322 XtSetArg (args[n], XmNalignment, XmALIGNMENT_BEGINNING); n++;
1323 XtSetArg (args[n], XmNmarginRight, 5); n++;
1324 XtSetArg (args[n], XmNbottomAttachment, XmATTACH_NONE); n++;
1325 XtSetArg (args[n], XmNbottomOffset, 0); n++;
1326 XtSetValues (pPres->allWsW, args, n);
1329 XtSetArg (args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
1330 XtSetArg (args[n], XmNtopWidget, pPres->allWsW); n++;
1331 XtSetArg (args[n], XmNtopOffset, SEP_OFFSET); n++;
1332 XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); n++;
1333 XtSetArg (args[n], XmNleftOffset, 0); n++;
1334 XtSetArg (args[n], XmNrightAttachment, XmATTACH_FORM); n++;
1335 XtSetArg (args[n], XmNrightOffset, 0); n++;
1336 XtSetArg (args[n], XmNbottomAttachment, XmATTACH_NONE); n++;
1337 XtSetArg (args[n], XmNbottomOffset, 0); n++;
1338 XtSetValues (pPres->sepW, args, n);
1341 XtSetArg (args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
1342 XtSetArg (args[n], XmNtopWidget, pPres->sepW); n++;
1343 XtSetArg (args[n], XmNtopOffset, SEP_OFFSET); n++;
1344 XtSetArg (args[n], XmNleftAttachment, XmATTACH_POSITION); n++;
1345 XtSetArg (args[n], XmNleftPosition, 5); n++;
1346 XtSetArg (args[n], XmNrightAttachment, XmATTACH_POSITION); n++;
1347 XtSetArg (args[n], XmNrightPosition, 30); n++;
1348 XtSetArg (args[n], XmNbottomAttachment, XmATTACH_POSITION); n++;
1349 XtSetArg (args[n], XmNbottomPosition, 95); n++;
1350 XtSetValues (pPres->OkW, args, n);
1353 XtSetArg (args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
1354 XtSetArg (args[n], XmNtopWidget, pPres->sepW); n++;
1355 XtSetArg (args[n], XmNtopOffset, SEP_OFFSET); n++;
1356 XtSetArg (args[n], XmNleftAttachment, XmATTACH_POSITION); n++;
1357 XtSetArg (args[n], XmNleftPosition, 36); n++;
1358 XtSetArg (args[n], XmNrightAttachment, XmATTACH_POSITION); n++;
1359 XtSetArg (args[n], XmNrightPosition, 66); n++;
1360 XtSetArg (args[n], XmNbottomAttachment, XmATTACH_POSITION); n++;
1361 XtSetArg (args[n], XmNbottomPosition, 95); n++;
1362 XtSetValues (pPres->CancelW, args, n);
1365 XtSetArg (args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
1366 XtSetArg (args[n], XmNtopWidget, pPres->sepW); n++;
1367 XtSetArg (args[n], XmNtopOffset, SEP_OFFSET); n++;
1368 XtSetArg (args[n], XmNleftAttachment, XmATTACH_POSITION); n++;
1369 XtSetArg (args[n], XmNleftPosition, 71); n++;
1370 XtSetArg (args[n], XmNrightAttachment, XmATTACH_POSITION); n++;
1371 XtSetArg (args[n], XmNrightPosition, 95); n++;
1372 XtSetArg (args[n], XmNbottomAttachment, XmATTACH_POSITION); n++;
1373 XtSetArg (args[n], XmNbottomPosition, 95); n++;
1374 XtSetValues (pPres->HelpW, args, n);
1375 } /* END OF FUNCTION */
1379 /*************************************<->*************************************
1382 * wspOkCB (w, client_data, call_data)
1392 * pSD = pointer to screen data
1404 *************************************<->***********************************/
1410 XtPointer call_data )
1414 int selectedItemCount;
1415 XmStringTable selectedItems;
1416 PtrWsPresenceData pPres = &pSD->presence;
1417 Boolean bAllSelected;
1420 /* find the selected workspaces */
1422 XtSetArg (args[n], XmNselectedItemCount, &selectedItemCount); n++;
1423 XtSetArg (args[n], XmNselectedItems, &selectedItems); n++;
1424 XtGetValues (pPres->workspaceListW, args, n);
1426 /* find the state of all workspaces button */
1428 XtSetArg (args[n], XmNset, &bAllSelected); n++;
1429 XtGetValues (pPres->allWsW, args, n);
1433 F_AddToAllWorkspaces(NULL, pPres->pCDforClient, NULL);
1435 else if (selectedItemCount)
1437 for (n = 0; n < pSD->numWorkspaces; n++)
1439 pPres->ItemSelected[n] = False;
1440 for (j = 0; j < selectedItemCount; j++)
1442 if (XmStringCompare (selectedItems[j],
1443 pPres->ItemStrings[n]))
1445 pPres->ItemSelected[n] = True;
1449 if (!pPres->ItemSelected[n] &&
1450 ClientInWorkspace (&pSD->pWS[n], pPres->pCDforClient))
1452 RemoveClientFromWorkspaces (pPres->pCDforClient,
1453 &pSD->pWS[n].id, 1);
1456 if (pPres->ItemSelected[n] &&
1457 !ClientInWorkspace (&pSD->pWS[n], pPres->pCDforClient))
1459 AddClientToWorkspaces (pPres->pCDforClient,
1460 &pSD->pWS[n].id, 1);
1465 /* withdraw the dialog */
1466 wspCancelCB (buttonW, (XtPointer)pSD, call_data);
1467 } /* END OF FUNCTION */
1470 /*************************************<->*************************************
1473 * wspHelpCB (w, client_data, call_data)
1495 *************************************<->***********************************/
1501 XtPointer client_data,
1502 XtPointer call_data )
1505 DtHelpOnTopic (XtParent(buttonW), "vw_pres");
1506 } /* END OF FUNCTION */
1507 #endif /* PANELIST */
1509 /*************************************<->*************************************
1512 * wspAllWsCB (w, client_data, call_data)
1517 * All Workspace toggle button callback.
1534 *************************************<->***********************************/
1540 XmToggleButtonCallbackStruct *xmTbcs )
1542 PtrWsPresenceData pPres = &pSD->presence;
1544 XmString *pxmsSelected;
1548 if (xmTbcs->reason == XmCR_VALUE_CHANGED)
1552 pxmsSelected = (XmString *)
1553 XtMalloc (pSD->numWorkspaces * sizeof (XmString));
1555 for (wsnum = 0; wsnum < pSD->numWorkspaces; wsnum++)
1557 pxmsSelected[wsnum] = pPres->ItemStrings[wsnum];
1560 /* set the selected items */
1562 XtSetArg (args[n], XmNselectedItems, pxmsSelected); n++;
1563 XtSetArg (args[n], XmNselectedItemCount, pSD->numWorkspaces); n++;
1564 XtSetValues (pPres->workspaceListW, args, n);
1566 XtFree ((char *) pxmsSelected);
1570 /* select current workspace */
1571 XmListDeselectAllItems (pPres->workspaceListW);
1572 XmListSelectPos (pPres->workspaceListW, pPres->currentWsItem, TRUE);
1575 } /* END OF FUNCTION */
1580 /*************************************<->*************************************
1583 * wspExtendedSelectCB (w, client_data, cb)
1605 *************************************<->***********************************/
1608 wspExtendedSelectCB(
1610 XtPointer client_data,
1611 XmListCallbackStruct *cb )
1613 WmScreenData *pSD = (WmScreenData *) client_data;
1614 PtrWsPresenceData pPres = &pSD->presence;
1618 if (cb->reason == XmCR_EXTENDED_SELECT)
1620 if ((cb->selected_item_count < pSD->numWorkspaces) &&
1621 (cb->event != None))
1624 XtSetArg (args[n], XmNset, False); n++;
1625 XtSetValues (pPres->allWsW, args, n);
1629 } /* END OF FUNCTION wspExtendedSelectCB */
1633 /*************************************<->*************************************
1636 * wspCancelCB (w, client_data, call_data)
1658 *************************************<->***********************************/
1663 XtPointer client_data,
1664 XtPointer call_data )
1666 WmScreenData *pSD = (WmScreenData *) client_data;
1668 XtPopdown (pSD->presence.shellW);
1669 pSD->presence.onScreen = False;
1671 } /* END OF FUNCTION wspCancelCB */
1674 /*************************************<->*************************************
1676 * GetPresenceBoxMenuItems (pSD)
1683 *************************************<->***********************************/
1686 GetPresenceBoxMenuItems(
1692 } /* END OF FUNCTION GetPresenceBoxMenuItems */
1695 /*************************************<->*************************************
1697 * UpdatePresenceWorkspaces (pSD)
1702 * Update the presence dialog when the number of workspaces changes.
1704 *************************************<->***********************************/
1707 UpdatePresenceWorkspaces(
1710 PtrWsPresenceData pPres = &pSD->presence;
1716 if (pPres->numWorkspaces < pSD->numWorkspaces)
1718 if (((pPres->ItemStrings = (XmStringTable) XtRealloc
1719 ((char *)pPres->ItemStrings,
1720 (pSD->numWorkspaces * sizeof(XmString *)))) == NULL) ||
1721 ((pPres->ItemSelected = (Boolean *) XtRealloc
1722 ((char *)pPres->ItemSelected,
1723 (pSD->numWorkspaces * sizeof(Boolean)))) == NULL))
1725 Warning (((char *)GETMESSAGE(52, 5, "Insufficient memory to create Occupy Workspace dialog.")));
1726 pPres->shellW = NULL;
1732 * Replace the names in the dialog's list
1734 for (wsnum = 0; wsnum < pPres->numWorkspaces; wsnum++)
1736 if (wsnum < pSD->numWorkspaces)
1738 xmsTmp = XmStringCopy (pSD->pWS[wsnum].title);
1740 if (!XmStringCompare (xmsTmp, pPres->ItemStrings[wsnum]))
1743 * Replace the string in our local list
1745 XmStringFree (pPres->ItemStrings[wsnum]);
1746 pPres->ItemStrings[wsnum] = xmsTmp;
1749 * Replace the item in the scrolled list.
1751 XmListDeletePos (pPres->workspaceListW, 1+wsnum);
1752 XmListAddItem (pPres->workspaceListW, xmsTmp, 1+wsnum);
1756 XmStringFree (xmsTmp);
1762 * Delete this workspace from the list
1764 XmStringFree (pPres->ItemStrings[wsnum]);
1765 pPres->ItemStrings[wsnum] = NULL;
1766 XmListDeletePos (pPres->workspaceListW, 1+wsnum);
1769 for (; wsnum < pSD->numWorkspaces; wsnum++)
1772 * Add these workspaces to the list.
1774 xmsTmp = XmStringCopy (pSD->pWS[wsnum].title);
1775 pPres->ItemStrings[wsnum] = xmsTmp;
1776 XmListAddItem (pPres->workspaceListW, xmsTmp, 1+wsnum);
1778 if (pPres->pCDforClient &&
1779 (ClientInWorkspace (&pPres->pCDforClient->pSD->pWS[wsnum],
1780 pPres->pCDforClient)))
1782 XmListSelectPos (pPres->workspaceListW, 1+wsnum, TRUE);
1783 pPres->ItemSelected[wsnum] = True;
1787 pPres->ItemSelected[wsnum] = False;
1791 pPres->numWorkspaces = pSD->numWorkspaces;
1794 } /* END OF FUNCTION UpdatePresenceWorkspaces */
1796 /* DO NOT ADD ANYTHING AFTER THIS ENDIF */
1798 /**************************** eof ***************************/