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"
43 #include <X11/StringDefs.h>
44 #include <X11/Intrinsic.h>
45 #include <X11/Xatom.h>
46 #include <X11/Shell.h>
49 #include <Xm/PushBG.h>
50 #include <Xm/LabelG.h>
52 #include <Xm/SeparatoG.h>
53 #include <Xm/ToggleB.h>
62 * Function Declarations:
65 #include "WmPresence.h"
67 /******** Static Function Declarations ********/
69 static void wspSetWindowName(
70 PtrWsPresenceData pPres) ;
71 static Boolean wspCreateWidgets(
73 static Widget wspCreateShell(
75 static Widget wspCreateManager(
77 static Widget wspCreateLabel(
79 unsigned char *pchName,
80 unsigned char *pchString) ;
81 static Widget wspCreateSeparator(
83 static Widget wspCreateWorkspaceList(
85 PtrWsPresenceData pPres,
87 static void wspUpdateWorkspaceList(
88 PtrWsPresenceData pPres) ;
89 static Widget wspCreateToggleButton(
92 static Widget wspCreatePushButton(
96 static void wspSetPosition(
97 PtrWsPresenceData pPres) ;
98 static void wspLayout(
99 PtrWsPresenceData pPres) ;
103 XtPointer call_data) ;
104 static void wspHelpCB(
106 XtPointer client_data,
107 XtPointer call_data) ;
108 static void wspAllWsCB(
111 XmToggleButtonCallbackStruct *xmTbcs) ;
112 static void wspCancelCB(
114 XtPointer client_data,
115 XtPointer call_data) ;
116 static void wspExtendedSelectCB(
118 XtPointer client_data,
119 XmListCallbackStruct *cb );
120 static Dimension wspCharWidth (
123 /******** End Static Function Declarations ********/
126 * External references
128 #include "WmCDecor.h"
129 #include "WmCDInfo.h"
130 #include "WmIconBox.h"
132 #include "WmPanelP.h" /* for typedef in WmManage.h */
133 #endif /* PANELIST */
134 #include "WmManage.h"
135 #include "WmResParse.h"
136 #include "WmResource.h"
137 #include "WmWinInfo.h"
138 #include "WmWrkspace.h"
145 * These two XmStrings are used in the workspace
146 * presence box to indicate the name of the current
147 * window for whice the presence box is active. If the
148 * window is iconified, the title will be "Icon: <iconName>",
149 * otherwise the title wil be "Window: <windowName>
151 XmString windowLabelString = (XmString)NULL;
152 XmString iconLabelString = (XmString)NULL;
154 /*************************************<->*************************************
157 * MakePresenceBox (pSD)
166 * pSD = pointer to screen data
171 * Return = (Boolean) True if successful
177 ******************************<->***********************************/
184 PtrWsPresenceData pPres = &pSD->presence;
188 * Create the widgets for the workspace presence dialog
191 pPres->onScreen = False;
193 if (wspCreateWidgets (pSD))
201 * Set the ClientData fields.
203 XtRealizeWidget (pPres->shellW);
205 DtWsmRemoveWorkspaceFunctions (DISPLAY1, XtWindow(pPres->shellW));
206 #endif /* PANELIST */
208 ProcessPresenceResources (pSD);
214 Warning(((char *)GETMESSAGE(52, 1, "Unable to create Occupy Workspace dialog.")));
220 } /* END OF FUNCTION MakePresenceBox */
223 /*************************************<->*************************************
226 * ShowPresenceBox (pClient, wsContext)
231 * Pops up (shows) the workspace presence dialog
235 * pClient = pointer to client data which needs a presence dialog
236 * up. (This is not the presence dialog's client data!!!)
238 * wsContext = context to post dialog for
249 ******************************<->***********************************/
256 PtrWsPresenceData pPres;
259 pPres = &pClient->pSD->presence;
261 pPres->pCDforClient = pClient;
262 pPres->contextForClient = wsContext;
265 * Create the presence dialog if not done yet.
267 if (!pSD->presence.shellW)
269 pPres->ItemSelected = NULL;
270 pPres->ItemStrings = NULL;
271 pPres->currentWsItem = 0;
273 MakePresenceBox (pSD);
278 HidePresenceBox (pSD, True);
281 /* update workspace list */
282 wspUpdateWorkspaceList (pPres);
284 /* set position of dialog relative to client window */
285 wspSetPosition (pPres);
290 XtPopup (pPres->shellW, XtGrabNone);
291 pPres->onScreen = True;
292 } /* END OF FUNCTION ShowPresenceBox */
295 /*************************************<->*************************************
298 * wspSetWindowName (pPres)
303 * Sets the name of the current window in the presence dialog
307 * pPres = ptr to workspace presence dialog data
317 ******************************<->***********************************/
321 PtrWsPresenceData pPres )
329 * Set the name of the current window
334 if (pPres->contextForClient == F_CONTEXT_ICON)
336 XtSetArg (nameArgs[nameN], XmNlabelString,
337 pPres->pCDforClient->iconTitle); nameN++;
338 XtSetArg (labelArgs[labelN], XmNlabelString,
339 iconLabelString); labelN++;
343 XtSetArg (nameArgs[nameN], XmNlabelString,
344 pPres->pCDforClient->clientTitle); nameN++;
345 XtSetArg (labelArgs[labelN], XmNlabelString,
346 windowLabelString); labelN++;
349 XtSetValues (pPres->windowNameW, nameArgs, nameN);
350 XtSetValues (pPres->windowLabelW, labelArgs, labelN);
352 } /* END OF FUNCTION wspSetWindowName */
355 /*************************************<->*************************************
358 * HidePresenceBox (pSD, userDismissed)
363 * Pops down (hides) the workspace presence dialog
367 * pSD = pointer to screen data
368 * userDismissed = did the user dismiss or did workspace switching
369 * unpost the workspace presence box ?
379 ******************************<->***********************************/
384 Boolean userDismissed )
387 if (pSD->presence.onScreen)
389 /* Pop down the shell */
390 XtPopdown (pSD->presence.shellW);
393 * Do a withdraw to make sure window gets unmanaged
394 * (popdown does nothing if its unmapped)
396 XWithdrawWindow (DISPLAY, XtWindow (pSD->presence.shellW),
398 /* must sync to insure event order */
399 XSync (DISPLAY, False);
402 pSD->presence.onScreen = False;
403 pSD->presence.userDismissed = userDismissed;
405 } /* END OF FUNCTION */
408 /*************************************<->*************************************
410 * wspCreateWidgets (pSD)
415 * Creates all the widgets for the workspace presence dialog box
419 * pSD = pointer to screen data
423 * Return = false on any failure
427 * Only creates widgets
428 ******************************<->***********************************/
433 PtrWsPresenceData pPres = &pSD->presence;
436 Boolean rval /* = True */;
437 #ifdef NO_MESSAGE_CATALOG
438 XmString tmpXmString;
439 #endif /* NO_MESSAGE_CATALOG */
441 rval = ((pPres->shellW = wspCreateShell (pSD)) != NULL);
445 rval = ((pPres->formW = wspCreateManager (pPres->shellW)) != NULL);
450 rval = ((pPres->windowLabelW = wspCreateLabel (pPres->formW,
451 (unsigned char *)"window",
457 rval = ((pPres->windowNameW = wspCreateLabel (pPres->formW,
458 (unsigned char *)"windowName",
459 (unsigned char *)" ")) != NULL);
464 rval = ((pPres->workspaceLabelW =
465 wspCreateLabel (pPres->formW, (unsigned char *)"workspaces",
466 ((unsigned char *)GETMESSAGE(52, 3, "Workspaces: ")))) != NULL);
471 rval = ((pPres->workspaceListW =
472 wspCreateWorkspaceList (pPres->formW, pPres, pSD)) != NULL);
473 pPres->workspaceScrolledListW = XtParent (pPres->workspaceListW);
478 rval = ((pPres->allWsW = wspCreateToggleButton (pPres->formW,
479 ((unsigned char *)GETMESSAGE(52, 4, "All Workspaces"))))
481 XtAddCallback (pPres->allWsW, XmNvalueChangedCallback,
482 (XtCallbackProc)wspAllWsCB, (XtPointer)pSD);
487 rval = ((pPres->sepW = wspCreateSeparator (pPres->formW)) != NULL);
492 #ifndef NO_MESSAGE_CATALOG
493 rval = ((pPres->OkW =
494 wspCreatePushButton (pPres->formW, "ok", wmGD.okLabel))
497 tmpXmString = XmStringCreateLocalized ("OK");
498 rval = ((pPres->OkW =
499 wspCreatePushButton (pPres->formW, "ok", tmpXmString))
501 XmStringFree(tmpXmString);
504 /* set the default action */
506 XtSetArg (args[n], XmNdefaultButton, pPres->OkW); n++;
507 XtSetValues (pPres->formW, args, n);
509 XtAddCallback (pPres->OkW, XmNactivateCallback,
510 (XtCallbackProc) wspOkCB, (XtPointer)pSD);
515 #ifndef NO_MESSAGE_CATALOG
516 rval = ((pPres->CancelW = wspCreatePushButton (pPres->formW,
517 "cancel", wmGD.cancelLabel)) != NULL);
519 tmpXmString = XmStringCreateLocalized ("Cancel");
520 rval = ((pPres->CancelW =
521 wspCreatePushButton (pPres->formW, "cancel", tmpXmString))
523 XmStringFree(tmpXmString);
525 XtAddCallback (pPres->CancelW, XmNactivateCallback,
526 (XtCallbackProc) wspCancelCB, (XtPointer)pSD);
528 /* set the cancel button (for KCancel) */
530 XtSetArg (args[n], XmNcancelButton, pPres->CancelW); n++;
531 XtSetValues (pPres->formW, args, n);
536 #ifndef NO_MESSAGE_CATALOG
537 rval = ((pPres->HelpW =
538 wspCreatePushButton (pPres->formW, "help", wmGD.helpLabel))
541 tmpXmString = XmStringCreateLocalized ("Help");
542 rval = ((pPres->HelpW =
543 wspCreatePushButton (pPres->formW, "help", tmpXmString))
545 XmStringFree(tmpXmString);
549 XtAddCallback (pPres->HelpW, XmNactivateCallback,
551 WM_DT_WSPRESENCE_TOPIC);
553 XtAddCallback (pPres->HelpW, XmNactivateCallback,
554 (XtCallbackProc) wspHelpCB, (XtPointer)pSD);
555 #endif /* PANELIST */
559 } /* END OF FUNCTION */
563 /*************************************<->*************************************
566 * wspCreateShell (pSD)
571 * Creates the shell widget for the workspace presence dialog
576 * psD = pointer to screen data
580 * Return = shell widget created
582 ******************************<->***********************************/
592 * Create top level shell for workspace presence dialog
597 XtSetArg (setArgs[i], XmNallowShellResize, (XtArgVal)True); i++;
599 XtSetArg (setArgs[i], XmNborderWidth, (XtArgVal)0); i++;
601 XtSetArg (setArgs[i], XmNkeyboardFocusPolicy,
602 (XtArgVal)XmEXPLICIT); i++;
604 XtSetArg (setArgs[i], XmNmappedWhenManaged,
605 (XtArgVal)False); i++;
607 XtSetArg (setArgs[i], XmNmwmFunctions,
608 PRESENCE_BOX_FUNCTIONS); i++;
610 XtSetArg (setArgs[i], XmNmwmDecorations,
611 (MWM_DECOR_TITLE|MWM_DECOR_BORDER)); i++;
613 XtSetArg (setArgs[i], XmNdepth,
614 (XtArgVal) DefaultDepth (DISPLAY1, pSD->screen)); i++;
616 XtSetArg (setArgs[i], XmNscreen, (XtArgVal)
617 ScreenOfDisplay (DISPLAY1, pSD->screen)); i++;
619 XtSetArg (setArgs[i], XtNcolormap,
620 (XtArgVal )DefaultColormap(DISPLAY1, pSD->screen)); i++;
622 shellW = (Widget) XtCreatePopupShell (WmNfeedback,
623 transientShellWidgetClass,
624 pSD->screenTopLevelW1,
625 (ArgList)setArgs, i);
629 } /* END OF FUNCTION wspCreateShell */
632 /*************************************<->*************************************
634 * wspCreateManager (shellW)
639 * Creates the manager widget for the workspace presence dialog
649 * Creates a form widget
650 ******************************<->***********************************/
659 /* !!! set colors? !!! */
661 formW = (Widget) XmCreateForm (shellW, "form", (ArgList) setArgs, 0);
663 XtAddCallback (formW, XmNhelpCallback,
664 WmDtWmTopicHelpCB, WM_DT_WSPRESENCE_TOPIC);
666 XtManageChild (formW);
669 } /* END OF FUNCTION */
673 /*************************************<->*************************************
675 * wspCreateLabel (mgrW, pchName, pchString)
680 * Creates a label widget as a child of the passed in manager
684 * mgrW = manager widget (parent of this label)
685 * pchName = name of the widget
686 * pchString = string that is to be in label
690 * Return = Widget created.
694 ******************************<->***********************************/
698 unsigned char *pchName,
699 unsigned char *pchString )
704 XmString tmpXmString = (XmString)NULL;
708 if (!strcmp((char *)pchName, "window"))
710 if (windowLabelString != (XmString)NULL)
711 XmStringFree(windowLabelString);
712 if (iconLabelString != (XmString)NULL)
713 XmStringFree(iconLabelString);
716 XmStringCreateLocalized ((char *)GETMESSAGE(52, 2, "Window: "));
718 * If we do this, USE the message catalog for iconLabelString
719 * just as we do for windowLabelString !!!
722 XmStringCreateLocalized ((char *)GETMESSAGE(52, 6, "Icon: "));
724 XtSetArg (setArgs[i], XmNlabelString, windowLabelString ); i++;
728 tmpXmString = XmStringCreateLocalized ((char *)pchString);
729 XtSetArg (setArgs[i], XmNlabelString, tmpXmString); i++;
732 labelW = XmCreateLabelGadget (mgrW, (char *)pchName, setArgs, i);
733 XtManageChild (labelW);
735 if (tmpXmString != (XmString)NULL)
736 XmStringFree(tmpXmString);
739 } /* END OF FUNCTION */
742 /*************************************<->*************************************
744 * wspCreateSeparator (mgrW)
749 * Creates a separator widget as a child of the passed in manager
753 * mgrW = manager widget (parent of this label)
757 * Return = Widget created.
761 ******************************<->***********************************/
772 sepW = XmCreateSeparatorGadget (mgrW, "separator", setArgs, i);
773 XtManageChild (sepW);
776 } /* END OF FUNCTION */
780 /*************************************<->*************************************
782 * wspCreateWorkspaceList (mgrW, pPres, pSD)
787 * Creates a list widget containing all the workspaces defined for a
792 * mgrW = manager widget (parent of this child)
793 * pPres = pointer to presence data
794 * pSD = ptr to screen data
798 * Return = widget created.
802 ******************************<->***********************************/
804 wspCreateWorkspaceList(
806 PtrWsPresenceData pPres,
814 #define MIN_VISIBLE 6
817 * Create the array of strings that will go into the list.
819 if (((pPres->ItemStrings = (XmStringTable) XtMalloc
820 (pSD->numWorkspaces * sizeof(XmString *))) == NULL) ||
821 ((pPres->ItemSelected = (Boolean *) XtMalloc
822 (pSD->numWorkspaces * sizeof(Boolean))) == NULL))
824 Warning (((char *)GETMESSAGE(52, 5, "Insufficient memory to create Occupy Workspace dialog.")));
828 pPres->numWorkspaces = pSD->numWorkspaces;
830 for (i = 0; i < pSD->numWorkspaces; i++)
832 pPres->ItemStrings[i] = XmStringCopy (pSD->pWS[i].title);
834 if (pSD->pWS[i].id == pSD->pActiveWS->id)
836 pPres->currentWsItem = 1+i;
846 XtSetArg (setArgs[i], XmNitemCount, pSD->numWorkspaces); i++;
848 XtSetArg (setArgs[i], XmNitems, pPres->ItemStrings); i++;
850 XtSetArg (setArgs[i], XmNselectionPolicy, XmEXTENDED_SELECT); i++;
852 XtSetArg (setArgs[i], XmNlistSizePolicy, XmRESIZE_IF_POSSIBLE); i++;
854 listW = XmCreateScrolledList (mgrW, "list", setArgs, i);
855 XtManageChild (listW);
857 if (pPres->pCDforClient)
860 * Highlight the workspaces this client resides in
862 for (i = 0; i < pPres->pCDforClient->pSD->numWorkspaces; i++)
864 if (ClientInWorkspace (&pPres->pCDforClient->pSD->pWS[i],
865 pPres->pCDforClient))
867 XmListSelectPos (listW, i+1, TRUE);
868 pPres->ItemSelected[i] = True;
872 pPres->ItemSelected[i] = False;
878 * Insure a minimum number are visible.
881 XtSetArg (setArgs[i], XmNvisibleItemCount, &numVisible); i++;
882 XtGetValues (listW, setArgs, i);
884 if (numVisible < MIN_VISIBLE)
887 XtSetArg (setArgs[i], XmNvisibleItemCount, MIN_VISIBLE);i++;
888 XtSetValues (listW, setArgs, i);
891 XtAddCallback (listW, XmNextendedSelectionCallback,
892 (XtCallbackProc) wspExtendedSelectCB, (XtPointer)pSD);
893 /* Handle the double-click just like if the Ok button was pressed */
894 XtAddCallback (listW, XmNdefaultActionCallback,
895 (XtCallbackProc) wspOkCB, (XtPointer)pSD);
899 } /* END OF FUNCTION */
902 /*************************************<->*************************************
904 * wspUpdateWorkspaceList (pPres)
909 * Updates the list widget containing all the workspaces.
910 * Sets the ones for this client.
914 * pPres = ptr to presence dialog data
922 ******************************<->***********************************/
924 wspUpdateWorkspaceList(
925 PtrWsPresenceData pPres )
928 XmString xmsTmp, *pxmsSelected;
931 int wsnum, numSelected;
934 * Update the list of workspaces to -- one may have been
935 * renamed since the last time we were up.
937 pSD = pPres->pCDforClient->pSD;
938 for (wsnum = 0; wsnum < pSD->numWorkspaces; wsnum++)
940 xmsTmp = XmStringCopy (pSD->pWS[wsnum].title);
942 if (!XmStringCompare (xmsTmp, pPres->ItemStrings[wsnum]))
945 * Replace the string in our local list
947 XmStringFree (pPres->ItemStrings[wsnum]);
948 pPres->ItemStrings[wsnum] = xmsTmp;
951 * Replace the item in the scrolled list.
953 XmListDeletePos (pPres->workspaceListW, 1+wsnum);
954 XmListAddItem (pPres->workspaceListW, xmsTmp, 1+wsnum);
958 XmStringFree (xmsTmp);
963 * Highlight the workspaces this client resides in
965 XmListDeselectAllItems (pPres->workspaceListW);
966 pxmsSelected = (XmString *)
967 XtMalloc (pPres->pCDforClient->pSD->numWorkspaces * sizeof (XmString));
969 for (wsnum = 0; wsnum < pPres->pCDforClient->pSD->numWorkspaces; wsnum++)
971 if (ClientInWorkspace (&pPres->pCDforClient->pSD->pWS[wsnum],
972 pPres->pCDforClient))
974 pxmsSelected[numSelected++] = pPres->ItemStrings[wsnum];
975 pPres->ItemSelected[wsnum] = True;
979 pPres->ItemSelected[wsnum] = False;
980 pPres->pCDforClient->putInAll = False;
983 if (pPres->pCDforClient->pSD->pActiveWS->id ==
984 pPres->pCDforClient->pSD->pWS[wsnum].id)
986 /* save item number of current workspace */
987 pPres->currentWsItem = 1+wsnum;
991 /* set the selected items */
993 XtSetArg (args[n], XmNselectedItems, pxmsSelected); n++;
994 XtSetArg (args[n], XmNselectedItemCount, numSelected); n++;
995 XtSetValues (pPres->workspaceListW, args, n);
997 /* set state of all workspaces button */
999 XtSetArg (args[n], XmNset, pPres->pCDforClient->putInAll); n++;
1000 XtSetValues (pPres->allWsW, args, n);
1002 /* set name of window we're popped up for */
1003 wspSetWindowName (pPres);
1005 XtFree ((char *) pxmsSelected);
1007 } /* END OF FUNCTION */
1010 /*************************************<->*************************************
1012 * wspCreateToggleButton (mgrW, pch)
1017 * Creates a toggle button as a child of mgrW with the string pch.
1021 * mgrW = parent widget
1022 * pch = string to use for toggle button
1026 * Return = widget created
1030 ******************************<->***********************************/
1032 wspCreateToggleButton(
1034 unsigned char *pch )
1039 XmString labelString;
1043 labelString = XmStringCreateLocalized ((char *)pch);
1044 XtSetArg (setArgs[i], XmNlabelString, labelString); i++;
1046 toggleW = XmCreateToggleButton (mgrW, (char *)pch, setArgs, i);
1048 XmStringFree(labelString);
1050 XtManageChild (toggleW);
1054 } /* END OF FUNCTION wspCreateToggleButton */
1057 /*************************************<->*************************************
1059 * wspCreatePushButton (mgrW, label)
1064 * Creates a push button as a child of mgrW with the string pch.
1068 * mgrW = parent widget
1069 * label = XmString to use for button label
1073 * Return = widget created
1077 ******************************<->***********************************/
1079 wspCreatePushButton(
1091 XtSetArg (setArgs[i], XmNlabelString, label); i++;
1093 pushW = (Widget) XmCreatePushButton (mgrW, name, setArgs, i);
1095 XtManageChild (pushW);
1099 } /* END OF FUNCTION wspCreatePushButton */
1102 /*************************************<->*************************************
1104 * wspSetPosition (pPres)
1109 * Sets the position of the workspace presence dialog
1113 * pPres = pointer to workspace presence data
1118 ******************************<->***********************************/
1121 PtrWsPresenceData pPres )
1123 WmScreenData *pSD = pPres->pCDforClient->pSD;
1131 * Get size of this dialog
1134 XtSetArg (args[n], XmNheight, &height); n++;
1135 XtGetValues (pPres->shellW, args, n);
1137 if (wmGD.positionIsFrame)
1139 if (pSD->decoupleTitleAppearance)
1141 font = pSD->clientTitleAppearance.font;
1145 font = pSD->clientAppearance.font;
1148 height += TEXT_HEIGHT(font) + (2 * pSD->frameBorderWidth);
1153 * set position of dialog relative to client window
1154 * (use system menu position)
1155 * set this dialog to be transient for the client
1156 * for which it is posted.
1158 GetSystemMenuPosition (pPres->pCDforClient,
1160 pPres->contextForClient);
1163 XtSetArg (args[n], XmNx, x); n++;
1164 XtSetArg (args[n], XmNy, y); n++;
1165 XtSetArg (args[n], XmNtransientFor, NULL); n++;
1166 if (pPres->contextForClient != F_CONTEXT_ICON)
1168 XtSetArg (args[n], XmNwindowGroup, pPres->pCDforClient->client); n++;
1170 else if (pSD->useIconBox && P_ICON_BOX(pPres->pCDforClient))
1172 XtSetArg (args[n], XmNwindowGroup,
1173 P_ICON_BOX(pPres->pCDforClient)->pCD_iconBox->client); n++;
1177 XtSetArg (args[n], XmNwindowGroup, 0); n++;
1179 XtSetArg (args[n], XmNwaitForWm, False); n++;
1181 XtSetValues (pPres->shellW, args, n);
1183 } /* END OF FUNCTION wspSetPosition */
1186 /*************************************<->*************************************
1188 * wspCharWidth (xmfl)
1193 * Returns the max logical character width for this fontList
1202 * max logical character width
1206 ******************************<->***********************************/
1212 XmFontListEntry entry;
1213 Dimension dWidth, dTmpWidth;
1216 XFontSetExtents *pExtents;
1218 XmFontListInitFontContext ( &fc, xmfl);
1222 entry = XmFontListNextEntry (fc);
1225 pFont = XmFontListEntryGetFont (entry, &type);
1229 case XmFONT_IS_FONT:
1230 dTmpWidth = ((XFontStruct *)pFont)->max_bounds.rbearing -
1231 ((XFontStruct *)pFont)->min_bounds.lbearing;
1234 case XmFONT_IS_FONTSET:
1235 pExtents = XExtentsOfFontSet ((XFontSet) pFont);
1236 dTmpWidth = pExtents->max_logical_extent.width;
1244 if (dTmpWidth > dWidth)
1247 entry = XmFontListNextEntry (fc);
1250 XmFontListFreeFontContext (fc);
1256 /*************************************<->*************************************
1263 * Lays out the workspace presence dialog
1268 * pPres = pointer to workspace presence data
1276 ******************************<->***********************************/
1279 PtrWsPresenceData pPres )
1284 #define SEP_OFFSET 10
1285 #define IW_OFFSET_1 8
1286 #define IW_OFFSET_0 4
1290 XtSetArg (args[n], XmNtopAttachment, XmATTACH_POSITION); n++;
1291 XtSetArg (args[n], XmNtopPosition, 5); n++;
1292 XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); n++;
1293 XtSetArg (args[n], XmNleftOffset, 5); n++;
1294 XtSetArg (args[n], XmNrightAttachment, XmATTACH_NONE); n++;
1295 XtSetArg (args[n], XmNbottomAttachment, XmATTACH_NONE); n++;
1296 XtSetValues (pPres->windowLabelW, args, n);
1299 XtSetArg (args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
1300 XtSetArg (args[n], XmNtopWidget, pPres->windowLabelW); n++;
1301 XtSetArg (args[n], XmNtopOffset, IW_OFFSET_0); n++;
1302 XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); n++;
1303 XtSetArg (args[n], XmNleftOffset, 5); n++;
1304 XtSetArg (args[n], XmNrightAttachment, XmATTACH_NONE); n++;
1305 XtSetArg (args[n], XmNbottomAttachment, XmATTACH_NONE); n++;
1306 XtSetArg (args[n], XmNbottomOffset, 0); n++;
1307 XtSetValues (pPres->workspaceLabelW, args, n);
1310 XtSetArg (args[n], XmNtopAttachment, XmATTACH_POSITION); n++;
1311 XtSetArg (args[n], XmNtopPosition, 5); n++;
1312 XtSetArg (args[n], XmNleftAttachment, XmATTACH_WIDGET); n++;
1313 XtSetArg (args[n], XmNleftWidget, pPres->workspaceLabelW); n++;
1314 XtSetArg (args[n], XmNleftOffset, 5); n++;
1315 XtSetArg (args[n], XmNrightAttachment, XmATTACH_FORM); n++;
1316 XtSetArg (args[n], XmNrightOffset, 5); n++;
1317 XtSetArg (args[n], XmNbottomAttachment, XmATTACH_NONE); n++;
1318 XtSetArg (args[n], XmNbottomOffset, 0); n++;
1319 XtSetArg (args[n], XmNalignment, XmALIGNMENT_BEGINNING); n++;
1320 XtSetValues (pPres->windowNameW, args, n);
1323 XtSetArg (args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
1324 XtSetArg (args[n], XmNtopWidget, pPres->windowNameW); n++;
1325 XtSetArg (args[n], XmNtopOffset, IW_OFFSET_0); n++;
1326 XtSetArg (args[n], XmNleftAttachment, XmATTACH_WIDGET); n++;
1327 XtSetArg (args[n], XmNleftWidget, pPres->workspaceLabelW); n++;
1328 XtSetArg (args[n], XmNleftOffset, 5); n++;
1329 XtSetArg (args[n], XmNrightAttachment, XmATTACH_FORM); n++;
1330 XtSetArg (args[n], XmNrightOffset, 5); n++;
1331 XtSetArg (args[n], XmNbottomAttachment, XmATTACH_NONE); n++;
1332 XtSetArg (args[n], XmNbottomOffset, 0); n++;
1333 XtSetValues (pPres->workspaceScrolledListW, args, n);
1336 XtSetArg (args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
1337 XtSetArg (args[n], XmNtopWidget, pPres->workspaceScrolledListW); n++;
1338 XtSetArg (args[n], XmNtopOffset, IW_OFFSET_1); n++;
1339 XtSetArg (args[n], XmNleftAttachment, XmATTACH_WIDGET); n++;
1340 XtSetArg (args[n], XmNleftWidget, pPres->workspaceLabelW); n++;
1341 XtSetArg (args[n], XmNleftOffset, 5); n++;
1342 XtSetArg (args[n], XmNrightAttachment, XmATTACH_FORM); n++;
1343 XtSetArg (args[n], XmNrightOffset, 5); n++;
1344 XtSetArg (args[n], XmNalignment, XmALIGNMENT_BEGINNING); n++;
1345 XtSetArg (args[n], XmNmarginRight, 5); n++;
1346 XtSetArg (args[n], XmNbottomAttachment, XmATTACH_NONE); n++;
1347 XtSetArg (args[n], XmNbottomOffset, 0); n++;
1348 XtSetValues (pPres->allWsW, args, n);
1351 XtSetArg (args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
1352 XtSetArg (args[n], XmNtopWidget, pPres->allWsW); n++;
1353 XtSetArg (args[n], XmNtopOffset, SEP_OFFSET); n++;
1354 XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); n++;
1355 XtSetArg (args[n], XmNleftOffset, 0); n++;
1356 XtSetArg (args[n], XmNrightAttachment, XmATTACH_FORM); n++;
1357 XtSetArg (args[n], XmNrightOffset, 0); n++;
1358 XtSetArg (args[n], XmNbottomAttachment, XmATTACH_NONE); n++;
1359 XtSetArg (args[n], XmNbottomOffset, 0); n++;
1360 XtSetValues (pPres->sepW, args, n);
1363 XtSetArg (args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
1364 XtSetArg (args[n], XmNtopWidget, pPres->sepW); n++;
1365 XtSetArg (args[n], XmNtopOffset, SEP_OFFSET); n++;
1366 XtSetArg (args[n], XmNleftAttachment, XmATTACH_POSITION); n++;
1367 XtSetArg (args[n], XmNleftPosition, 5); n++;
1368 XtSetArg (args[n], XmNrightAttachment, XmATTACH_POSITION); n++;
1369 XtSetArg (args[n], XmNrightPosition, 30); n++;
1370 XtSetArg (args[n], XmNbottomAttachment, XmATTACH_POSITION); n++;
1371 XtSetArg (args[n], XmNbottomPosition, 95); n++;
1372 XtSetValues (pPres->OkW, args, n);
1375 XtSetArg (args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
1376 XtSetArg (args[n], XmNtopWidget, pPres->sepW); n++;
1377 XtSetArg (args[n], XmNtopOffset, SEP_OFFSET); n++;
1378 XtSetArg (args[n], XmNleftAttachment, XmATTACH_POSITION); n++;
1379 XtSetArg (args[n], XmNleftPosition, 36); n++;
1380 XtSetArg (args[n], XmNrightAttachment, XmATTACH_POSITION); n++;
1381 XtSetArg (args[n], XmNrightPosition, 66); n++;
1382 XtSetArg (args[n], XmNbottomAttachment, XmATTACH_POSITION); n++;
1383 XtSetArg (args[n], XmNbottomPosition, 95); n++;
1384 XtSetValues (pPres->CancelW, args, n);
1387 XtSetArg (args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
1388 XtSetArg (args[n], XmNtopWidget, pPres->sepW); n++;
1389 XtSetArg (args[n], XmNtopOffset, SEP_OFFSET); n++;
1390 XtSetArg (args[n], XmNleftAttachment, XmATTACH_POSITION); n++;
1391 XtSetArg (args[n], XmNleftPosition, 71); n++;
1392 XtSetArg (args[n], XmNrightAttachment, XmATTACH_POSITION); n++;
1393 XtSetArg (args[n], XmNrightPosition, 95); n++;
1394 XtSetArg (args[n], XmNbottomAttachment, XmATTACH_POSITION); n++;
1395 XtSetArg (args[n], XmNbottomPosition, 95); n++;
1396 XtSetValues (pPres->HelpW, args, n);
1397 } /* END OF FUNCTION */
1401 /*************************************<->*************************************
1404 * wspOkCB (w, client_data, call_data)
1414 * pSD = pointer to screen data
1426 *************************************<->***********************************/
1432 XtPointer call_data )
1436 int selectedItemCount;
1437 XmStringTable selectedItems;
1438 PtrWsPresenceData pPres = &pSD->presence;
1439 Boolean bAllSelected;
1442 /* find the selected workspaces */
1444 XtSetArg (args[n], XmNselectedItemCount, &selectedItemCount); n++;
1445 XtSetArg (args[n], XmNselectedItems, &selectedItems); n++;
1446 XtGetValues (pPres->workspaceListW, args, n);
1448 /* find the state of all workspaces button */
1450 XtSetArg (args[n], XmNset, &bAllSelected); n++;
1451 XtGetValues (pPres->allWsW, args, n);
1455 F_AddToAllWorkspaces(NULL, pPres->pCDforClient, NULL);
1457 else if (selectedItemCount)
1459 for (n = 0; n < pSD->numWorkspaces; n++)
1461 pPres->ItemSelected[n] = False;
1462 for (j = 0; j < selectedItemCount; j++)
1464 if (XmStringCompare (selectedItems[j],
1465 pPres->ItemStrings[n]))
1467 pPres->ItemSelected[n] = True;
1471 if (!pPres->ItemSelected[n] &&
1472 ClientInWorkspace (&pSD->pWS[n], pPres->pCDforClient))
1474 RemoveClientFromWorkspaces (pPres->pCDforClient,
1475 &pSD->pWS[n].id, 1);
1478 if (pPres->ItemSelected[n] &&
1479 !ClientInWorkspace (&pSD->pWS[n], pPres->pCDforClient))
1481 AddClientToWorkspaces (pPres->pCDforClient,
1482 &pSD->pWS[n].id, 1);
1487 /* withdraw the dialog */
1488 wspCancelCB (buttonW, (XtPointer)pSD, call_data);
1489 } /* END OF FUNCTION */
1492 /*************************************<->*************************************
1495 * wspHelpCB (w, client_data, call_data)
1517 *************************************<->***********************************/
1523 XtPointer client_data,
1524 XtPointer call_data )
1527 DtHelpOnTopic (XtParent(buttonW), "vw_pres");
1528 } /* END OF FUNCTION */
1529 #endif /* PANELIST */
1531 /*************************************<->*************************************
1534 * wspAllWsCB (w, client_data, call_data)
1539 * All Workspace toggle button callback.
1556 *************************************<->***********************************/
1562 XmToggleButtonCallbackStruct *xmTbcs )
1564 PtrWsPresenceData pPres = &pSD->presence;
1566 XmString *pxmsSelected;
1570 if (xmTbcs->reason == XmCR_VALUE_CHANGED)
1574 pxmsSelected = (XmString *)
1575 XtMalloc (pSD->numWorkspaces * sizeof (XmString));
1577 for (wsnum = 0; wsnum < pSD->numWorkspaces; wsnum++)
1579 pxmsSelected[wsnum] = pPres->ItemStrings[wsnum];
1582 /* set the selected items */
1584 XtSetArg (args[n], XmNselectedItems, pxmsSelected); n++;
1585 XtSetArg (args[n], XmNselectedItemCount, pSD->numWorkspaces); n++;
1586 XtSetValues (pPres->workspaceListW, args, n);
1588 XtFree ((char *) pxmsSelected);
1592 /* select current workspace */
1593 XmListDeselectAllItems (pPres->workspaceListW);
1594 XmListSelectPos (pPres->workspaceListW, pPres->currentWsItem, TRUE);
1597 } /* END OF FUNCTION */
1602 /*************************************<->*************************************
1605 * wspExtendedSelectCB (w, client_data, cb)
1627 *************************************<->***********************************/
1630 wspExtendedSelectCB(
1632 XtPointer client_data,
1633 XmListCallbackStruct *cb )
1635 WmScreenData *pSD = (WmScreenData *) client_data;
1636 PtrWsPresenceData pPres = &pSD->presence;
1640 if (cb->reason == XmCR_EXTENDED_SELECT)
1642 if ((cb->selected_item_count < pSD->numWorkspaces) &&
1643 (cb->event != None))
1646 XtSetArg (args[n], XmNset, False); n++;
1647 XtSetValues (pPres->allWsW, args, n);
1651 } /* END OF FUNCTION wspExtendedSelectCB */
1655 /*************************************<->*************************************
1658 * wspCancelCB (w, client_data, call_data)
1680 *************************************<->***********************************/
1685 XtPointer client_data,
1686 XtPointer call_data )
1688 WmScreenData *pSD = (WmScreenData *) client_data;
1690 XtPopdown (pSD->presence.shellW);
1691 pSD->presence.onScreen = False;
1693 } /* END OF FUNCTION wspCancelCB */
1696 /*************************************<->*************************************
1698 * GetPresenceBoxMenuItems (pSD)
1705 *************************************<->***********************************/
1708 GetPresenceBoxMenuItems(
1714 } /* END OF FUNCTION GetPresenceBoxMenuItems */
1717 /*************************************<->*************************************
1719 * UpdatePresenceWorkspaces (pSD)
1724 * Update the presence dialog when the number of workspaces changes.
1726 *************************************<->***********************************/
1729 UpdatePresenceWorkspaces(
1732 PtrWsPresenceData pPres = &pSD->presence;
1738 if (pPres->numWorkspaces < pSD->numWorkspaces)
1740 if (((pPres->ItemStrings = (XmStringTable) XtRealloc
1741 ((char *)pPres->ItemStrings,
1742 (pSD->numWorkspaces * sizeof(XmString *)))) == NULL) ||
1743 ((pPres->ItemSelected = (Boolean *) XtRealloc
1744 ((char *)pPres->ItemSelected,
1745 (pSD->numWorkspaces * sizeof(Boolean)))) == NULL))
1747 Warning (((char *)GETMESSAGE(52, 5, "Insufficient memory to create Occupy Workspace dialog.")));
1748 pPres->shellW = NULL;
1754 * Replace the names in the dialog's list
1756 for (wsnum = 0; wsnum < pPres->numWorkspaces; wsnum++)
1758 if (wsnum < pSD->numWorkspaces)
1760 xmsTmp = XmStringCopy (pSD->pWS[wsnum].title);
1762 if (!XmStringCompare (xmsTmp, pPres->ItemStrings[wsnum]))
1765 * Replace the string in our local list
1767 XmStringFree (pPres->ItemStrings[wsnum]);
1768 pPres->ItemStrings[wsnum] = xmsTmp;
1771 * Replace the item in the scrolled list.
1773 XmListDeletePos (pPres->workspaceListW, 1+wsnum);
1774 XmListAddItem (pPres->workspaceListW, xmsTmp, 1+wsnum);
1778 XmStringFree (xmsTmp);
1784 * Delete this workspace from the list
1786 XmStringFree (pPres->ItemStrings[wsnum]);
1787 pPres->ItemStrings[wsnum] = NULL;
1788 XmListDeletePos (pPres->workspaceListW, 1+wsnum);
1791 for (; wsnum < pSD->numWorkspaces; wsnum++)
1794 * Add these workspaces to the list.
1796 xmsTmp = XmStringCopy (pSD->pWS[wsnum].title);
1797 pPres->ItemStrings[wsnum] = xmsTmp;
1798 XmListAddItem (pPres->workspaceListW, xmsTmp, 1+wsnum);
1800 if (pPres->pCDforClient &&
1801 (ClientInWorkspace (&pPres->pCDforClient->pSD->pWS[wsnum],
1802 pPres->pCDforClient)))
1804 XmListSelectPos (pPres->workspaceListW, 1+wsnum, TRUE);
1805 pPres->ItemSelected[wsnum] = True;
1809 pPres->ItemSelected[wsnum] = False;
1813 pPres->numWorkspaces = pSD->numWorkspaces;
1816 } /* END OF FUNCTION UpdatePresenceWorkspaces */
1818 /* DO NOT ADD ANYTHING AFTER THIS ENDIF */
1820 /**************************** eof ***************************/