2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
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)
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
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
25 * (c) Copyright 1987, 1988, 1989, 1990, 1992 HEWLETT-PACKARD COMPANY
30 static char rcsid[] = "$XConsortium: WmPresence.c /main/7 1996/10/23 17:24:56 rswiston $"
39 #include "WmResNames.h"
44 #include <X11/StringDefs.h>
45 #include <X11/Intrinsic.h>
46 #include <X11/Xatom.h>
47 #include <X11/Shell.h>
50 #include <Xm/PushBG.h>
52 #include <Xm/LabelG.h>
54 #include <Xm/SeparatoG.h>
55 #include <Xm/ToggleB.h>
64 * Function Declarations:
67 #include "WmPresence.h"
69 /******** Static Function Declarations ********/
71 static void wspSetWindowName(
72 PtrWsPresenceData pPres) ;
73 static Boolean wspCreateWidgets(
75 static Widget wspCreateShell(
77 static Widget wspCreateManager(
79 static Widget wspCreateLabel(
81 unsigned char *pchName,
82 unsigned char *pchString) ;
83 static Widget wspCreateSeparator(
85 static Widget wspCreateWorkspaceList(
87 PtrWsPresenceData pPres,
89 static void wspUpdateWorkspaceList(
90 PtrWsPresenceData pPres) ;
91 static Widget wspCreateToggleButton(
94 static Widget wspCreatePushButton(
98 static void wspSetPosition(
99 PtrWsPresenceData pPres) ;
100 static void wspLayout(
101 PtrWsPresenceData pPres) ;
105 XtPointer call_data) ;
106 static void wspHelpCB(
108 XtPointer client_data,
109 XtPointer call_data) ;
110 static void wspAllWsCB(
113 XmToggleButtonCallbackStruct *xmTbcs) ;
114 static void wspCancelCB(
116 XtPointer client_data,
117 XtPointer call_data) ;
118 static void wspExtendedSelectCB(
120 XtPointer client_data,
121 XmListCallbackStruct *cb );
122 static Dimension wspCharWidth (
125 /******** End Static Function Declarations ********/
128 * External references
130 #include "WmCDecor.h"
131 #include "WmCDInfo.h"
132 #include "WmIconBox.h"
134 #include "WmPanelP.h" /* for typedef in WmManage.h */
135 #endif /* PANELIST */
136 #include "WmManage.h"
137 #include "WmResParse.h"
138 #include "WmResource.h"
139 #include "WmWinInfo.h"
140 #include "WmWrkspace.h"
147 * These two XmStrings are used in the workspace
148 * presence box to indicate the name of the current
149 * window for whice the presence box is active. If the
150 * window is iconified, the title will be "Icon: <iconName>",
151 * otherwise the title wil be "Window: <windowName>
153 XmString windowLabelString = (XmString)NULL;
154 XmString iconLabelString = (XmString)NULL;
156 /*************************************<->*************************************
159 * MakePresenceBox (pSD)
168 * pSD = pointer to screen data
173 * Return = (Boolean) True if successful
179 ******************************<->***********************************/
186 PtrWsPresenceData pPres = &pSD->presence;
190 * Create the widgets for the workspace presence dialog
193 pPres->onScreen = False;
195 if (wspCreateWidgets (pSD))
203 * Set the ClientData fields.
205 XtRealizeWidget (pPres->shellW);
207 DtWsmRemoveWorkspaceFunctions (DISPLAY1, XtWindow(pPres->shellW));
208 #endif /* PANELIST */
210 ProcessPresenceResources (pSD);
216 Warning(((char *)GETMESSAGE(52, 1, "Unable to create Occupy Workspace dialog.")));
222 } /* END OF FUNCTION MakePresenceBox */
225 /*************************************<->*************************************
228 * ShowPresenceBox (pClient, wsContext)
233 * Pops up (shows) the workspace presence dialog
237 * pClient = pointer to client data which needs a presence dialog
238 * up. (This is not the presence dialog's client data!!!)
240 * wsContext = context to post dialog for
251 ******************************<->***********************************/
258 PtrWsPresenceData pPres;
261 pPres = &pClient->pSD->presence;
263 pPres->pCDforClient = pClient;
264 pPres->contextForClient = wsContext;
267 * Create the presence dialog if not done yet.
269 if (!pSD->presence.shellW)
271 pPres->ItemSelected = NULL;
272 pPres->ItemStrings = NULL;
273 pPres->currentWsItem = 0;
275 MakePresenceBox (pSD);
280 HidePresenceBox (pSD, True);
283 /* update workspace list */
284 wspUpdateWorkspaceList (pPres);
286 /* set position of dialog relative to client window */
287 wspSetPosition (pPres);
292 XtPopup (pPres->shellW, XtGrabNone);
293 pPres->onScreen = True;
294 } /* END OF FUNCTION ShowPresenceBox */
297 /*************************************<->*************************************
300 * wspSetWindowName (pPres)
305 * Sets the name of the current window in the presence dialog
309 * pPres = ptr to workspace presence dialog data
319 ******************************<->***********************************/
323 PtrWsPresenceData pPres )
331 * Set the name of the current window
336 if (pPres->contextForClient == F_CONTEXT_ICON)
338 XtSetArg (nameArgs[nameN], XmNlabelString,
339 pPres->pCDforClient->iconTitle); nameN++;
340 XtSetArg (labelArgs[labelN], XmNlabelString,
341 iconLabelString); labelN++;
345 XtSetArg (nameArgs[nameN], XmNlabelString,
346 pPres->pCDforClient->clientTitle); nameN++;
347 XtSetArg (labelArgs[labelN], XmNlabelString,
348 windowLabelString); labelN++;
351 XtSetValues (pPres->windowNameW, nameArgs, nameN);
352 XtSetValues (pPres->windowLabelW, labelArgs, labelN);
354 } /* END OF FUNCTION wspSetWindowName */
357 /*************************************<->*************************************
360 * HidePresenceBox (pSD, userDismissed)
365 * Pops down (hides) the workspace presence dialog
369 * pSD = pointer to screen data
370 * userDismissed = did the user dismiss or did workspace switching
371 * unpost the workspace presence box ?
381 ******************************<->***********************************/
386 Boolean userDismissed )
389 if (pSD->presence.onScreen)
391 /* Pop down the shell */
392 XtPopdown (pSD->presence.shellW);
395 * Do a withdraw to make sure window gets unmanaged
396 * (popdown does nothing if its unmapped)
398 XWithdrawWindow (DISPLAY, XtWindow (pSD->presence.shellW),
400 /* must sync to insure event order */
401 XSync (DISPLAY, False);
404 pSD->presence.onScreen = False;
405 pSD->presence.userDismissed = userDismissed;
407 } /* END OF FUNCTION */
410 /*************************************<->*************************************
412 * wspCreateWidgets (pSD)
417 * Creates all the widgets for the workspace presence dialog box
421 * pSD = pointer to screen data
425 * Return = false on any failure
429 * Only creates widgets
430 ******************************<->***********************************/
435 PtrWsPresenceData pPres = &pSD->presence;
438 Boolean rval /* = True */;
439 #ifdef NO_MESSAGE_CATALOG
440 XmString tmpXmString;
441 #endif /* NO_MESSAGE_CATALOG */
443 rval = ((pPres->shellW = wspCreateShell (pSD)) != NULL);
447 rval = ((pPres->formW = wspCreateManager (pPres->shellW)) != NULL);
452 rval = ((pPres->windowLabelW = wspCreateLabel (pPres->formW,
453 (unsigned char *)"window",
459 rval = ((pPres->windowNameW = wspCreateLabel (pPres->formW,
460 (unsigned char *)"windowName",
461 (unsigned char *)" ")) != NULL);
466 rval = ((pPres->workspaceLabelW =
467 wspCreateLabel (pPres->formW, (unsigned char *)"workspaces",
468 ((unsigned char *)GETMESSAGE(52, 3, "Workspaces: ")))) != NULL);
473 rval = ((pPres->workspaceListW =
474 wspCreateWorkspaceList (pPres->formW, pPres, pSD)) != NULL);
475 pPres->workspaceScrolledListW = XtParent (pPres->workspaceListW);
480 rval = ((pPres->allWsW = wspCreateToggleButton (pPres->formW,
481 ((unsigned char *)GETMESSAGE(52, 4, "All Workspaces"))))
483 XtAddCallback (pPres->allWsW, XmNvalueChangedCallback,
484 (XtCallbackProc)wspAllWsCB, (XtPointer)pSD);
489 rval = ((pPres->sepW = wspCreateSeparator (pPres->formW)) != NULL);
494 #ifndef NO_MESSAGE_CATALOG
495 rval = ((pPres->OkW =
496 wspCreatePushButton (pPres->formW, "ok", wmGD.okLabel))
499 tmpXmString = XmStringCreateLocalized ("OK");
500 rval = ((pPres->OkW =
501 wspCreatePushButton (pPres->formW, "ok", tmpXmString))
503 XmStringFree(tmpXmString);
506 /* set the default action */
508 XtSetArg (args[n], XmNdefaultButton, pPres->OkW); n++;
509 XtSetValues (pPres->formW, args, n);
511 XtAddCallback (pPres->OkW, XmNactivateCallback,
512 (XtCallbackProc) wspOkCB, (XtPointer)pSD);
517 #ifndef NO_MESSAGE_CATALOG
518 rval = ((pPres->CancelW = wspCreatePushButton (pPres->formW,
519 "cancel", wmGD.cancelLabel)) != NULL);
521 tmpXmString = XmStringCreateLocalized ("Cancel");
522 rval = ((pPres->CancelW =
523 wspCreatePushButton (pPres->formW, "cancel", tmpXmString))
525 XmStringFree(tmpXmString);
527 XtAddCallback (pPres->CancelW, XmNactivateCallback,
528 (XtCallbackProc) wspCancelCB, (XtPointer)pSD);
530 /* set the cancel button (for KCancel) */
532 XtSetArg (args[n], XmNcancelButton, pPres->CancelW); n++;
533 XtSetValues (pPres->formW, args, n);
538 #ifndef NO_MESSAGE_CATALOG
539 rval = ((pPres->HelpW =
540 wspCreatePushButton (pPres->formW, "help", wmGD.helpLabel))
543 tmpXmString = XmStringCreateLocalized ("Help");
544 rval = ((pPres->HelpW =
545 wspCreatePushButton (pPres->formW, "help", tmpXmString))
547 XmStringFree(tmpXmString);
551 XtAddCallback (pPres->HelpW, XmNactivateCallback,
553 WM_DT_WSPRESENCE_TOPIC);
555 XtAddCallback (pPres->HelpW, XmNactivateCallback,
556 (XtCallbackProc) wspHelpCB, (XtPointer)pSD);
557 #endif /* PANELIST */
561 } /* END OF FUNCTION */
565 /*************************************<->*************************************
568 * wspCreateShell (pSD)
573 * Creates the shell widget for the workspace presence dialog
578 * psD = pointer to screen data
582 * Return = shell widget created
584 ******************************<->***********************************/
594 * Create top level shell for workspace presence dialog
599 XtSetArg (setArgs[i], XmNallowShellResize, (XtArgVal)True); i++;
601 XtSetArg (setArgs[i], XmNborderWidth, (XtArgVal)0); i++;
603 XtSetArg (setArgs[i], XmNkeyboardFocusPolicy,
604 (XtArgVal)XmEXPLICIT); i++;
606 XtSetArg (setArgs[i], XmNmappedWhenManaged,
607 (XtArgVal)False); i++;
609 XtSetArg (setArgs[i], XmNmwmFunctions,
610 PRESENCE_BOX_FUNCTIONS); i++;
612 XtSetArg (setArgs[i], XmNmwmDecorations,
613 (MWM_DECOR_TITLE|MWM_DECOR_BORDER)); i++;
615 XtSetArg (setArgs[i], XmNdepth,
616 (XtArgVal) DefaultDepth (DISPLAY1, pSD->screen)); i++;
618 XtSetArg (setArgs[i], XmNscreen, (XtArgVal)
619 ScreenOfDisplay (DISPLAY1, pSD->screen)); i++;
621 XtSetArg (setArgs[i], XtNcolormap,
622 (XtArgVal )DefaultColormap(DISPLAY1, pSD->screen)); i++;
624 shellW = (Widget) XtCreatePopupShell (WmNfeedback,
625 transientShellWidgetClass,
626 pSD->screenTopLevelW1,
627 (ArgList)setArgs, i);
631 } /* END OF FUNCTION wspCreateShell */
634 /*************************************<->*************************************
636 * wspCreateManager (shellW)
641 * Creates the manager widget for the workspace presence dialog
651 * Creates a form widget
652 ******************************<->***********************************/
661 /* !!! set colors? !!! */
663 formW = (Widget) XmCreateForm (shellW, "form", (ArgList) setArgs, 0);
665 XtAddCallback (formW, XmNhelpCallback,
666 WmDtWmTopicHelpCB, WM_DT_WSPRESENCE_TOPIC);
668 XtManageChild (formW);
671 } /* END OF FUNCTION */
675 /*************************************<->*************************************
677 * wspCreateLabel (mgrW, pchName, pchString)
682 * Creates a label widget as a child of the passed in manager
686 * mgrW = manager widget (parent of this label)
687 * pchName = name of the widget
688 * pchString = string that is to be in label
692 * Return = Widget created.
696 ******************************<->***********************************/
700 unsigned char *pchName,
701 unsigned char *pchString )
706 XmString tmpXmString = (XmString)NULL;
710 if (!strcmp((char *)pchName, "window"))
712 if (windowLabelString != (XmString)NULL)
713 XmStringFree(windowLabelString);
714 if (iconLabelString != (XmString)NULL)
715 XmStringFree(iconLabelString);
718 XmStringCreateLocalized ((char *)GETMESSAGE(52, 2, "Window: "));
720 * If we do this, USE the message catalog for iconLabelString
721 * just as we do for windowLabelString !!!
724 XmStringCreateLocalized ((char *)GETMESSAGE(52, 6, "Icon: "));
726 XtSetArg (setArgs[i], XmNlabelString, windowLabelString ); i++;
730 tmpXmString = XmStringCreateLocalized ((char *)pchString);
731 XtSetArg (setArgs[i], XmNlabelString, tmpXmString); i++;
734 labelW = XmCreateLabelGadget (mgrW, (char *)pchName, setArgs, i);
735 XtManageChild (labelW);
737 if (tmpXmString != (XmString)NULL)
738 XmStringFree(tmpXmString);
741 } /* END OF FUNCTION */
744 /*************************************<->*************************************
746 * wspCreateSeparator (mgrW)
751 * Creates a separator widget as a child of the passed in manager
755 * mgrW = manager widget (parent of this label)
759 * Return = Widget created.
763 ******************************<->***********************************/
774 sepW = XmCreateSeparatorGadget (mgrW, "separator", setArgs, i);
775 XtManageChild (sepW);
778 } /* END OF FUNCTION */
782 /*************************************<->*************************************
784 * wspCreateWorkspaceList (mgrW, pPres, pSD)
789 * Creates a list widget containing all the workspaces defined for a
794 * mgrW = manager widget (parent of this child)
795 * pPres = pointer to presence data
796 * pSD = ptr to screen data
800 * Return = widget created.
804 ******************************<->***********************************/
806 wspCreateWorkspaceList(
808 PtrWsPresenceData pPres,
816 #define MIN_VISIBLE 6
819 * Create the array of strings that will go into the list.
821 if (((pPres->ItemStrings = (XmStringTable) XtMalloc
822 (pSD->numWorkspaces * sizeof(XmString *))) == NULL) ||
823 ((pPres->ItemSelected = (Boolean *) XtMalloc
824 (pSD->numWorkspaces * sizeof(Boolean))) == NULL))
826 Warning (((char *)GETMESSAGE(52, 5, "Insufficient memory to create Occupy Workspace dialog.")));
830 pPres->numWorkspaces = pSD->numWorkspaces;
832 for (i = 0; i < pSD->numWorkspaces; i++)
834 pPres->ItemStrings[i] = XmStringCopy (pSD->pWS[i].title);
836 if (pSD->pWS[i].id == pSD->pActiveWS->id)
838 pPres->currentWsItem = 1+i;
848 XtSetArg (setArgs[i], XmNitemCount, pSD->numWorkspaces); i++;
850 XtSetArg (setArgs[i], XmNitems, pPres->ItemStrings); i++;
852 XtSetArg (setArgs[i], XmNselectionPolicy, XmEXTENDED_SELECT); i++;
854 XtSetArg (setArgs[i], XmNlistSizePolicy, XmRESIZE_IF_POSSIBLE); i++;
856 listW = XmCreateScrolledList (mgrW, "list", setArgs, i);
857 XtManageChild (listW);
859 if (pPres->pCDforClient)
862 * Highlight the workspaces this client resides in
864 for (i = 0; i < pPres->pCDforClient->pSD->numWorkspaces; i++)
866 if (ClientInWorkspace (&pPres->pCDforClient->pSD->pWS[i],
867 pPres->pCDforClient))
869 XmListSelectPos (listW, i+1, TRUE);
870 pPres->ItemSelected[i] = True;
874 pPres->ItemSelected[i] = False;
880 * Insure a minimum number are visible.
883 XtSetArg (setArgs[i], XmNvisibleItemCount, &numVisible); i++;
884 XtGetValues (listW, setArgs, i);
886 if (numVisible < MIN_VISIBLE)
889 XtSetArg (setArgs[i], XmNvisibleItemCount, MIN_VISIBLE);i++;
890 XtSetValues (listW, setArgs, i);
893 XtAddCallback (listW, XmNextendedSelectionCallback,
894 (XtCallbackProc) wspExtendedSelectCB, (XtPointer)pSD);
895 /* Handle the double-click just like if the Ok button was pressed */
896 XtAddCallback (listW, XmNdefaultActionCallback,
897 (XtCallbackProc) wspOkCB, (XtPointer)pSD);
901 } /* END OF FUNCTION */
904 /*************************************<->*************************************
906 * wspUpdateWorkspaceList (pPres)
911 * Updates the list widget containing all the workspaces.
912 * Sets the ones for this client.
916 * pPres = ptr to presence dialog data
924 ******************************<->***********************************/
926 wspUpdateWorkspaceList(
927 PtrWsPresenceData pPres )
930 XmString xmsTmp, *pxmsSelected;
933 int wsnum, numSelected;
936 * Update the list of workspaces to -- one may have been
937 * renamed since the last time we were up.
939 pSD = pPres->pCDforClient->pSD;
940 for (wsnum = 0; wsnum < pSD->numWorkspaces; wsnum++)
942 xmsTmp = XmStringCopy (pSD->pWS[wsnum].title);
944 if (!XmStringCompare (xmsTmp, pPres->ItemStrings[wsnum]))
947 * Replace the string in our local list
949 XmStringFree (pPres->ItemStrings[wsnum]);
950 pPres->ItemStrings[wsnum] = xmsTmp;
953 * Replace the item in the scrolled list.
955 XmListDeletePos (pPres->workspaceListW, 1+wsnum);
956 XmListAddItem (pPres->workspaceListW, xmsTmp, 1+wsnum);
960 XmStringFree (xmsTmp);
965 * Highlight the workspaces this client resides in
967 XmListDeselectAllItems (pPres->workspaceListW);
968 pxmsSelected = (XmString *)
969 XtMalloc (pPres->pCDforClient->pSD->numWorkspaces * sizeof (XmString));
971 for (wsnum = 0; wsnum < pPres->pCDforClient->pSD->numWorkspaces; wsnum++)
973 if (ClientInWorkspace (&pPres->pCDforClient->pSD->pWS[wsnum],
974 pPres->pCDforClient))
976 pxmsSelected[numSelected++] = pPres->ItemStrings[wsnum];
977 pPres->ItemSelected[wsnum] = True;
981 pPres->ItemSelected[wsnum] = False;
982 pPres->pCDforClient->putInAll = False;
985 if (pPres->pCDforClient->pSD->pActiveWS->id ==
986 pPres->pCDforClient->pSD->pWS[wsnum].id)
988 /* save item number of current workspace */
989 pPres->currentWsItem = 1+wsnum;
993 /* set the selected items */
995 XtSetArg (args[n], XmNselectedItems, pxmsSelected); n++;
996 XtSetArg (args[n], XmNselectedItemCount, numSelected); n++;
997 XtSetValues (pPres->workspaceListW, args, n);
999 /* set state of all workspaces button */
1001 XtSetArg (args[n], XmNset, pPres->pCDforClient->putInAll); n++;
1002 XtSetValues (pPres->allWsW, args, n);
1004 /* set name of window we're popped up for */
1005 wspSetWindowName (pPres);
1007 XtFree ((char *) pxmsSelected);
1009 } /* END OF FUNCTION */
1012 /*************************************<->*************************************
1014 * wspCreateToggleButton (mgrW, pch)
1019 * Creates a toggle button as a child of mgrW with the string pch.
1023 * mgrW = parent widget
1024 * pch = string to use for toggle button
1028 * Return = widget created
1032 ******************************<->***********************************/
1034 wspCreateToggleButton(
1036 unsigned char *pch )
1041 XmString labelString;
1045 labelString = XmStringCreateLocalized ((char *)pch);
1046 XtSetArg (setArgs[i], XmNlabelString, labelString); i++;
1048 toggleW = XmCreateToggleButton (mgrW, (char *)pch, setArgs, i);
1050 XmStringFree(labelString);
1052 XtManageChild (toggleW);
1056 } /* END OF FUNCTION wspCreateToggleButton */
1059 /*************************************<->*************************************
1061 * wspCreatePushButton (mgrW, label)
1066 * Creates a push button as a child of mgrW with the string pch.
1070 * mgrW = parent widget
1071 * label = XmString to use for button label
1075 * Return = widget created
1079 ******************************<->***********************************/
1081 wspCreatePushButton(
1093 XtSetArg (setArgs[i], XmNlabelString, label); i++;
1095 pushW = (Widget) XmCreatePushButton (mgrW, name, setArgs, i);
1097 XtManageChild (pushW);
1101 } /* END OF FUNCTION wspCreatePushButton */
1104 /*************************************<->*************************************
1106 * wspSetPosition (pPres)
1111 * Sets the position of the workspace presence dialog
1115 * pPres = pointer to workspace presence data
1120 ******************************<->***********************************/
1123 PtrWsPresenceData pPres )
1125 WmScreenData *pSD = pPres->pCDforClient->pSD;
1133 * Get size of this dialog
1136 XtSetArg (args[n], XmNheight, &height); n++;
1137 XtGetValues (pPres->shellW, args, n);
1139 if (wmGD.positionIsFrame)
1141 if (pSD->decoupleTitleAppearance)
1143 font = pSD->clientTitleAppearance.font;
1147 font = pSD->clientAppearance.font;
1150 height += TEXT_HEIGHT(font) + (2 * pSD->frameBorderWidth);
1155 * set position of dialog relative to client window
1156 * (use system menu position)
1157 * set this dialog to be transient for the client
1158 * for which it is posted.
1160 GetSystemMenuPosition (pPres->pCDforClient,
1162 pPres->contextForClient);
1165 XtSetArg (args[n], XmNx, x); n++;
1166 XtSetArg (args[n], XmNy, y); n++;
1167 XtSetArg (args[n], XmNtransientFor, NULL); n++;
1168 if (pPres->contextForClient != F_CONTEXT_ICON)
1170 XtSetArg (args[n], XmNwindowGroup, pPres->pCDforClient->client); n++;
1172 else if (pSD->useIconBox && P_ICON_BOX(pPres->pCDforClient))
1174 XtSetArg (args[n], XmNwindowGroup,
1175 P_ICON_BOX(pPres->pCDforClient)->pCD_iconBox->client); n++;
1179 XtSetArg (args[n], XmNwindowGroup, 0); n++;
1181 XtSetArg (args[n], XmNwaitForWm, False); n++;
1183 XtSetValues (pPres->shellW, args, n);
1185 } /* END OF FUNCTION wspSetPosition */
1188 /*************************************<->*************************************
1190 * wspCharWidth (xmfl)
1195 * Returns the max logical character width for this fontList
1204 * max logical character width
1208 ******************************<->***********************************/
1214 XmFontListEntry entry;
1215 Dimension dWidth, dTmpWidth;
1218 XFontSetExtents *pExtents;
1220 XmFontListInitFontContext ( &fc, xmfl);
1224 entry = XmFontListNextEntry (fc);
1227 pFont = XmFontListEntryGetFont (entry, &type);
1231 case XmFONT_IS_FONT:
1232 dTmpWidth = ((XFontStruct *)pFont)->max_bounds.rbearing -
1233 ((XFontStruct *)pFont)->min_bounds.lbearing;
1236 case XmFONT_IS_FONTSET:
1237 pExtents = XExtentsOfFontSet ((XFontSet) pFont);
1238 dTmpWidth = pExtents->max_logical_extent.width;
1246 if (dTmpWidth > dWidth)
1249 entry = XmFontListNextEntry (fc);
1252 XmFontListFreeFontContext (fc);
1258 /*************************************<->*************************************
1265 * Lays out the workspace presence dialog
1270 * pPres = pointer to workspace presence data
1278 ******************************<->***********************************/
1281 PtrWsPresenceData pPres )
1286 #define SEP_OFFSET 10
1287 #define IW_OFFSET_1 8
1288 #define IW_OFFSET_0 4
1292 XtSetArg (args[n], XmNtopAttachment, XmATTACH_POSITION); n++;
1293 XtSetArg (args[n], XmNtopPosition, 5); n++;
1294 XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); n++;
1295 XtSetArg (args[n], XmNleftOffset, 5); n++;
1296 XtSetArg (args[n], XmNrightAttachment, XmATTACH_NONE); n++;
1297 XtSetArg (args[n], XmNbottomAttachment, XmATTACH_NONE); n++;
1298 XtSetValues (pPres->windowLabelW, args, n);
1301 XtSetArg (args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
1302 XtSetArg (args[n], XmNtopWidget, pPres->windowLabelW); n++;
1303 XtSetArg (args[n], XmNtopOffset, IW_OFFSET_0); n++;
1304 XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); n++;
1305 XtSetArg (args[n], XmNleftOffset, 5); n++;
1306 XtSetArg (args[n], XmNrightAttachment, XmATTACH_NONE); n++;
1307 XtSetArg (args[n], XmNbottomAttachment, XmATTACH_NONE); n++;
1308 XtSetArg (args[n], XmNbottomOffset, 0); n++;
1309 XtSetValues (pPres->workspaceLabelW, args, n);
1312 XtSetArg (args[n], XmNtopAttachment, XmATTACH_POSITION); n++;
1313 XtSetArg (args[n], XmNtopPosition, 5); n++;
1314 XtSetArg (args[n], XmNleftAttachment, XmATTACH_WIDGET); n++;
1315 XtSetArg (args[n], XmNleftWidget, pPres->workspaceLabelW); n++;
1316 XtSetArg (args[n], XmNleftOffset, 5); n++;
1317 XtSetArg (args[n], XmNrightAttachment, XmATTACH_FORM); n++;
1318 XtSetArg (args[n], XmNrightOffset, 5); n++;
1319 XtSetArg (args[n], XmNbottomAttachment, XmATTACH_NONE); n++;
1320 XtSetArg (args[n], XmNbottomOffset, 0); n++;
1321 XtSetArg (args[n], XmNalignment, XmALIGNMENT_BEGINNING); n++;
1322 XtSetValues (pPres->windowNameW, args, n);
1325 XtSetArg (args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
1326 XtSetArg (args[n], XmNtopWidget, pPres->windowNameW); n++;
1327 XtSetArg (args[n], XmNtopOffset, IW_OFFSET_0); n++;
1328 XtSetArg (args[n], XmNleftAttachment, XmATTACH_WIDGET); n++;
1329 XtSetArg (args[n], XmNleftWidget, pPres->workspaceLabelW); n++;
1330 XtSetArg (args[n], XmNleftOffset, 5); n++;
1331 XtSetArg (args[n], XmNrightAttachment, XmATTACH_FORM); n++;
1332 XtSetArg (args[n], XmNrightOffset, 5); n++;
1333 XtSetArg (args[n], XmNbottomAttachment, XmATTACH_NONE); n++;
1334 XtSetArg (args[n], XmNbottomOffset, 0); n++;
1335 XtSetValues (pPres->workspaceScrolledListW, args, n);
1338 XtSetArg (args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
1339 XtSetArg (args[n], XmNtopWidget, pPres->workspaceScrolledListW); n++;
1340 XtSetArg (args[n], XmNtopOffset, IW_OFFSET_1); n++;
1341 XtSetArg (args[n], XmNleftAttachment, XmATTACH_WIDGET); n++;
1342 XtSetArg (args[n], XmNleftWidget, pPres->workspaceLabelW); n++;
1343 XtSetArg (args[n], XmNleftOffset, 5); n++;
1344 XtSetArg (args[n], XmNrightAttachment, XmATTACH_FORM); n++;
1345 XtSetArg (args[n], XmNrightOffset, 5); n++;
1346 XtSetArg (args[n], XmNalignment, XmALIGNMENT_BEGINNING); n++;
1347 XtSetArg (args[n], XmNmarginRight, 5); n++;
1348 XtSetArg (args[n], XmNbottomAttachment, XmATTACH_NONE); n++;
1349 XtSetArg (args[n], XmNbottomOffset, 0); n++;
1350 XtSetValues (pPres->allWsW, args, n);
1353 XtSetArg (args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
1354 XtSetArg (args[n], XmNtopWidget, pPres->allWsW); n++;
1355 XtSetArg (args[n], XmNtopOffset, SEP_OFFSET); n++;
1356 XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); n++;
1357 XtSetArg (args[n], XmNleftOffset, 0); n++;
1358 XtSetArg (args[n], XmNrightAttachment, XmATTACH_FORM); n++;
1359 XtSetArg (args[n], XmNrightOffset, 0); n++;
1360 XtSetArg (args[n], XmNbottomAttachment, XmATTACH_NONE); n++;
1361 XtSetArg (args[n], XmNbottomOffset, 0); n++;
1362 XtSetValues (pPres->sepW, 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, 5); n++;
1370 XtSetArg (args[n], XmNrightAttachment, XmATTACH_POSITION); n++;
1371 XtSetArg (args[n], XmNrightPosition, 30); n++;
1372 XtSetArg (args[n], XmNbottomAttachment, XmATTACH_POSITION); n++;
1373 XtSetArg (args[n], XmNbottomPosition, 95); n++;
1374 XtSetValues (pPres->OkW, args, n);
1377 XtSetArg (args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
1378 XtSetArg (args[n], XmNtopWidget, pPres->sepW); n++;
1379 XtSetArg (args[n], XmNtopOffset, SEP_OFFSET); n++;
1380 XtSetArg (args[n], XmNleftAttachment, XmATTACH_POSITION); n++;
1381 XtSetArg (args[n], XmNleftPosition, 36); n++;
1382 XtSetArg (args[n], XmNrightAttachment, XmATTACH_POSITION); n++;
1383 XtSetArg (args[n], XmNrightPosition, 66); n++;
1384 XtSetArg (args[n], XmNbottomAttachment, XmATTACH_POSITION); n++;
1385 XtSetArg (args[n], XmNbottomPosition, 95); n++;
1386 XtSetValues (pPres->CancelW, args, n);
1389 XtSetArg (args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
1390 XtSetArg (args[n], XmNtopWidget, pPres->sepW); n++;
1391 XtSetArg (args[n], XmNtopOffset, SEP_OFFSET); n++;
1392 XtSetArg (args[n], XmNleftAttachment, XmATTACH_POSITION); n++;
1393 XtSetArg (args[n], XmNleftPosition, 71); n++;
1394 XtSetArg (args[n], XmNrightAttachment, XmATTACH_POSITION); n++;
1395 XtSetArg (args[n], XmNrightPosition, 95); n++;
1396 XtSetArg (args[n], XmNbottomAttachment, XmATTACH_POSITION); n++;
1397 XtSetArg (args[n], XmNbottomPosition, 95); n++;
1398 XtSetValues (pPres->HelpW, args, n);
1399 } /* END OF FUNCTION */
1403 /*************************************<->*************************************
1406 * wspOkCB (w, client_data, call_data)
1416 * pSD = pointer to screen data
1428 *************************************<->***********************************/
1434 XtPointer call_data )
1438 int selectedItemCount;
1439 XmStringTable selectedItems;
1440 PtrWsPresenceData pPres = &pSD->presence;
1441 Boolean bAllSelected;
1444 /* find the selected workspaces */
1446 XtSetArg (args[n], XmNselectedItemCount, &selectedItemCount); n++;
1447 XtSetArg (args[n], XmNselectedItems, &selectedItems); n++;
1448 XtGetValues (pPres->workspaceListW, args, n);
1450 /* find the state of all workspaces button */
1452 XtSetArg (args[n], XmNset, &bAllSelected); n++;
1453 XtGetValues (pPres->allWsW, args, n);
1457 F_AddToAllWorkspaces(NULL, pPres->pCDforClient, NULL);
1459 else if (selectedItemCount)
1461 for (n = 0; n < pSD->numWorkspaces; n++)
1463 pPres->ItemSelected[n] = False;
1464 for (j = 0; j < selectedItemCount; j++)
1466 if (XmStringCompare (selectedItems[j],
1467 pPres->ItemStrings[n]))
1469 pPres->ItemSelected[n] = True;
1473 if (!pPres->ItemSelected[n] &&
1474 ClientInWorkspace (&pSD->pWS[n], pPres->pCDforClient))
1476 RemoveClientFromWorkspaces (pPres->pCDforClient,
1477 &pSD->pWS[n].id, 1);
1480 if (pPres->ItemSelected[n] &&
1481 !ClientInWorkspace (&pSD->pWS[n], pPres->pCDforClient))
1483 AddClientToWorkspaces (pPres->pCDforClient,
1484 &pSD->pWS[n].id, 1);
1489 /* withdraw the dialog */
1490 wspCancelCB (buttonW, (XtPointer)pSD, call_data);
1491 } /* END OF FUNCTION */
1494 /*************************************<->*************************************
1497 * wspHelpCB (w, client_data, call_data)
1519 *************************************<->***********************************/
1525 XtPointer client_data,
1526 XtPointer call_data )
1529 DtHelpOnTopic (XtParent(buttonW), "vw_pres");
1530 } /* END OF FUNCTION */
1531 #endif /* PANELIST */
1533 /*************************************<->*************************************
1536 * wspAllWsCB (w, client_data, call_data)
1541 * All Workspace toggle button callback.
1558 *************************************<->***********************************/
1564 XmToggleButtonCallbackStruct *xmTbcs )
1566 PtrWsPresenceData pPres = &pSD->presence;
1568 XmString *pxmsSelected;
1572 if (xmTbcs->reason == XmCR_VALUE_CHANGED)
1576 pxmsSelected = (XmString *)
1577 XtMalloc (pSD->numWorkspaces * sizeof (XmString));
1579 for (wsnum = 0; wsnum < pSD->numWorkspaces; wsnum++)
1581 pxmsSelected[wsnum] = pPres->ItemStrings[wsnum];
1584 /* set the selected items */
1586 XtSetArg (args[n], XmNselectedItems, pxmsSelected); n++;
1587 XtSetArg (args[n], XmNselectedItemCount, pSD->numWorkspaces); n++;
1588 XtSetValues (pPres->workspaceListW, args, n);
1590 XtFree ((char *) pxmsSelected);
1594 /* select current workspace */
1595 XmListDeselectAllItems (pPres->workspaceListW);
1596 XmListSelectPos (pPres->workspaceListW, pPres->currentWsItem, TRUE);
1599 } /* END OF FUNCTION */
1604 /*************************************<->*************************************
1607 * wspExtendedSelectCB (w, client_data, cb)
1629 *************************************<->***********************************/
1632 wspExtendedSelectCB(
1634 XtPointer client_data,
1635 XmListCallbackStruct *cb )
1637 WmScreenData *pSD = (WmScreenData *) client_data;
1638 PtrWsPresenceData pPres = &pSD->presence;
1642 if (cb->reason == XmCR_EXTENDED_SELECT)
1644 if ((cb->selected_item_count < pSD->numWorkspaces) &&
1645 (cb->event != None))
1648 XtSetArg (args[n], XmNset, False); n++;
1649 XtSetValues (pPres->allWsW, args, n);
1653 } /* END OF FUNCTION wspExtendedSelectCB */
1657 /*************************************<->*************************************
1660 * wspCancelCB (w, client_data, call_data)
1682 *************************************<->***********************************/
1687 XtPointer client_data,
1688 XtPointer call_data )
1690 WmScreenData *pSD = (WmScreenData *) client_data;
1692 XtPopdown (pSD->presence.shellW);
1693 pSD->presence.onScreen = False;
1695 } /* END OF FUNCTION wspCancelCB */
1698 /*************************************<->*************************************
1700 * GetPresenceBoxMenuItems (pSD)
1707 *************************************<->***********************************/
1710 GetPresenceBoxMenuItems(
1716 } /* END OF FUNCTION GetPresenceBoxMenuItems */
1719 /*************************************<->*************************************
1721 * UpdatePresenceWorkspaces (pSD)
1726 * Update the presence dialog when the number of workspaces changes.
1728 *************************************<->***********************************/
1731 UpdatePresenceWorkspaces(
1734 PtrWsPresenceData pPres = &pSD->presence;
1740 if (pPres->numWorkspaces < pSD->numWorkspaces)
1742 if (((pPres->ItemStrings = (XmStringTable) XtRealloc
1743 ((char *)pPres->ItemStrings,
1744 (pSD->numWorkspaces * sizeof(XmString *)))) == NULL) ||
1745 ((pPres->ItemSelected = (Boolean *) XtRealloc
1746 ((char *)pPres->ItemSelected,
1747 (pSD->numWorkspaces * sizeof(Boolean)))) == NULL))
1749 Warning (((char *)GETMESSAGE(52, 5, "Insufficient memory to create Occupy Workspace dialog.")));
1750 pPres->shellW = NULL;
1756 * Replace the names in the dialog's list
1758 for (wsnum = 0; wsnum < pPres->numWorkspaces; wsnum++)
1760 if (wsnum < pSD->numWorkspaces)
1762 xmsTmp = XmStringCopy (pSD->pWS[wsnum].title);
1764 if (!XmStringCompare (xmsTmp, pPres->ItemStrings[wsnum]))
1767 * Replace the string in our local list
1769 XmStringFree (pPres->ItemStrings[wsnum]);
1770 pPres->ItemStrings[wsnum] = xmsTmp;
1773 * Replace the item in the scrolled list.
1775 XmListDeletePos (pPres->workspaceListW, 1+wsnum);
1776 XmListAddItem (pPres->workspaceListW, xmsTmp, 1+wsnum);
1780 XmStringFree (xmsTmp);
1786 * Delete this workspace from the list
1788 XmStringFree (pPres->ItemStrings[wsnum]);
1789 pPres->ItemStrings[wsnum] = NULL;
1790 XmListDeletePos (pPres->workspaceListW, 1+wsnum);
1793 for (; wsnum < pSD->numWorkspaces; wsnum++)
1796 * Add these workspaces to the list.
1798 xmsTmp = XmStringCopy (pSD->pWS[wsnum].title);
1799 pPres->ItemStrings[wsnum] = xmsTmp;
1800 XmListAddItem (pPres->workspaceListW, xmsTmp, 1+wsnum);
1802 if (pPres->pCDforClient &&
1803 (ClientInWorkspace (&pPres->pCDforClient->pSD->pWS[wsnum],
1804 pPres->pCDforClient)))
1806 XmListSelectPos (pPres->workspaceListW, 1+wsnum, TRUE);
1807 pPres->ItemSelected[wsnum] = True;
1811 pPres->ItemSelected[wsnum] = False;
1815 pPres->numWorkspaces = pSD->numWorkspaces;
1818 } /* END OF FUNCTION UpdatePresenceWorkspaces */
1820 /* DO NOT ADD ANYTHING AFTER THIS ENDIF */
1822 /**************************** eof ***************************/