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 libraries and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
24 * (c) Copyright 1987, 1988, 1989, 1990, 1992 HEWLETT-PACKARD COMPANY
33 #include "WmResNames.h"
38 #include <X11/StringDefs.h>
39 #include <X11/Intrinsic.h>
40 #include <X11/Xatom.h>
41 #include <X11/Shell.h>
44 #include <Xm/PushBG.h>
46 #include <Xm/LabelG.h>
48 #include <Xm/SeparatoG.h>
49 #include <Xm/ToggleB.h>
55 * Function Declarations:
58 #include "WmPresence.h"
60 /******** Static Function Declarations ********/
62 static void wspSetWindowName(
63 PtrWsPresenceData pPres) ;
64 static Boolean wspCreateWidgets(
66 static Widget wspCreateShell(
68 static Widget wspCreateManager(
70 static Widget wspCreateLabel(
72 unsigned char *pchName,
73 unsigned char *pchString) ;
74 static Widget wspCreateSeparator(
76 static Widget wspCreateWorkspaceList(
78 PtrWsPresenceData pPres,
80 static void wspUpdateWorkspaceList(
81 PtrWsPresenceData pPres) ;
82 static Widget wspCreateToggleButton(
85 static Widget wspCreatePushButton(
89 static void wspSetPosition(
90 PtrWsPresenceData pPres) ;
91 static void wspLayout(
92 PtrWsPresenceData pPres) ;
96 XtPointer call_data) ;
97 static void wspHelpCB(
99 XtPointer client_data,
100 XtPointer call_data) ;
101 static void wspAllWsCB(
104 XmToggleButtonCallbackStruct *xmTbcs) ;
105 static void wspCancelCB(
107 XtPointer client_data,
108 XtPointer call_data) ;
109 static void wspExtendedSelectCB(
111 XtPointer client_data,
112 XmListCallbackStruct *cb );
113 static Dimension wspCharWidth (
116 /******** End Static Function Declarations ********/
119 * External references
121 #include "WmCDecor.h"
122 #include "WmCDInfo.h"
123 #include "WmIconBox.h"
124 #include "WmPanelP.h" /* for typedef in WmManage.h */
125 #include "WmManage.h"
126 #include "WmResParse.h"
127 #include "WmResource.h"
128 #include "WmWinInfo.h"
129 #include "WmWrkspace.h"
136 * These two XmStrings are used in the workspace
137 * presence box to indicate the name of the current
138 * window for whice the presence box is active. If the
139 * window is iconified, the title will be "Icon: <iconName>",
140 * otherwise the title wil be "Window: <windowName>
142 XmString windowLabelString = (XmString)NULL;
143 XmString iconLabelString = (XmString)NULL;
145 /*************************************<->*************************************
148 * MakePresenceBox (pSD)
157 * pSD = pointer to screen data
162 * Return = (Boolean) True if successful
168 ******************************<->***********************************/
175 PtrWsPresenceData pPres = &pSD->presence;
179 * Create the widgets for the workspace presence dialog
182 pPres->onScreen = False;
184 if (wspCreateWidgets (pSD))
192 * Set the ClientData fields.
194 XtRealizeWidget (pPres->shellW);
195 DtWsmRemoveWorkspaceFunctions (DISPLAY1, XtWindow(pPres->shellW));
197 ProcessPresenceResources (pSD);
203 Warning(((char *)GETMESSAGE(52, 1, "Unable to create Occupy Workspace dialog.")));
209 } /* END OF FUNCTION MakePresenceBox */
212 /*************************************<->*************************************
215 * ShowPresenceBox (pClient, wsContext)
220 * Pops up (shows) the workspace presence dialog
224 * pClient = pointer to client data which needs a presence dialog
225 * up. (This is not the presence dialog's client data!!!)
227 * wsContext = context to post dialog for
238 ******************************<->***********************************/
245 PtrWsPresenceData pPres;
248 pPres = &pClient->pSD->presence;
250 pPres->pCDforClient = pClient;
251 pPres->contextForClient = wsContext;
254 * Create the presence dialog if not done yet.
256 if (!pSD->presence.shellW)
258 pPres->ItemSelected = NULL;
259 pPres->ItemStrings = NULL;
260 pPres->currentWsItem = 0;
262 MakePresenceBox (pSD);
267 HidePresenceBox (pSD, True);
270 /* update workspace list */
271 wspUpdateWorkspaceList (pPres);
273 /* set position of dialog relative to client window */
274 wspSetPosition (pPres);
279 XtPopup (pPres->shellW, XtGrabNone);
280 pPres->onScreen = True;
281 } /* END OF FUNCTION ShowPresenceBox */
284 /*************************************<->*************************************
287 * wspSetWindowName (pPres)
292 * Sets the name of the current window in the presence dialog
296 * pPres = ptr to workspace presence dialog data
306 ******************************<->***********************************/
310 PtrWsPresenceData pPres )
318 * Set the name of the current window
323 if (pPres->contextForClient == F_CONTEXT_ICON)
325 XtSetArg (nameArgs[nameN], XmNlabelString,
326 pPres->pCDforClient->iconTitle); nameN++;
327 XtSetArg (labelArgs[labelN], XmNlabelString,
328 iconLabelString); labelN++;
332 XtSetArg (nameArgs[nameN], XmNlabelString,
333 pPres->pCDforClient->clientTitle); nameN++;
334 XtSetArg (labelArgs[labelN], XmNlabelString,
335 windowLabelString); labelN++;
338 XtSetValues (pPres->windowNameW, nameArgs, nameN);
339 XtSetValues (pPres->windowLabelW, labelArgs, labelN);
341 } /* END OF FUNCTION wspSetWindowName */
344 /*************************************<->*************************************
347 * HidePresenceBox (pSD, userDismissed)
352 * Pops down (hides) the workspace presence dialog
356 * pSD = pointer to screen data
357 * userDismissed = did the user dismiss or did workspace switching
358 * unpost the workspace presence box ?
368 ******************************<->***********************************/
373 Boolean userDismissed )
376 if (pSD->presence.onScreen)
378 /* Pop down the shell */
379 XtPopdown (pSD->presence.shellW);
382 * Do a withdraw to make sure window gets unmanaged
383 * (popdown does nothing if its unmapped)
385 XWithdrawWindow (DISPLAY, XtWindow (pSD->presence.shellW),
387 /* must sync to insure event order */
388 XSync (DISPLAY, False);
391 pSD->presence.onScreen = False;
392 pSD->presence.userDismissed = userDismissed;
394 } /* END OF FUNCTION */
397 /*************************************<->*************************************
399 * wspCreateWidgets (pSD)
404 * Creates all the widgets for the workspace presence dialog box
408 * pSD = pointer to screen data
412 * Return = false on any failure
416 * Only creates widgets
417 ******************************<->***********************************/
422 PtrWsPresenceData pPres = &pSD->presence;
425 Boolean rval /* = True */;
426 #ifdef NO_MESSAGE_CATALOG
427 XmString tmpXmString;
428 #endif /* NO_MESSAGE_CATALOG */
430 rval = ((pPres->shellW = wspCreateShell (pSD)) != NULL);
434 rval = ((pPres->formW = wspCreateManager (pPres->shellW)) != NULL);
439 rval = ((pPres->windowLabelW = wspCreateLabel (pPres->formW,
440 (unsigned char *)"window",
446 rval = ((pPres->windowNameW = wspCreateLabel (pPres->formW,
447 (unsigned char *)"windowName",
448 (unsigned char *)" ")) != NULL);
453 rval = ((pPres->workspaceLabelW =
454 wspCreateLabel (pPres->formW, (unsigned char *)"workspaces",
455 ((unsigned char *)GETMESSAGE(52, 3, "Workspaces: ")))) != NULL);
460 rval = ((pPres->workspaceListW =
461 wspCreateWorkspaceList (pPres->formW, pPres, pSD)) != NULL);
462 pPres->workspaceScrolledListW = XtParent (pPres->workspaceListW);
467 rval = ((pPres->allWsW = wspCreateToggleButton (pPres->formW,
468 ((unsigned char *)GETMESSAGE(52, 4, "All Workspaces"))))
470 XtAddCallback (pPres->allWsW, XmNvalueChangedCallback,
471 (XtCallbackProc)wspAllWsCB, (XtPointer)pSD);
476 rval = ((pPres->sepW = wspCreateSeparator (pPres->formW)) != NULL);
481 #ifndef NO_MESSAGE_CATALOG
482 rval = ((pPres->OkW =
483 wspCreatePushButton (pPres->formW, "ok", wmGD.okLabel))
486 tmpXmString = XmStringCreateLocalized ("OK");
487 rval = ((pPres->OkW =
488 wspCreatePushButton (pPres->formW, "ok", tmpXmString))
490 XmStringFree(tmpXmString);
493 /* set the default action */
495 XtSetArg (args[n], XmNdefaultButton, pPres->OkW); n++;
496 XtSetValues (pPres->formW, args, n);
498 XtAddCallback (pPres->OkW, XmNactivateCallback,
499 (XtCallbackProc) wspOkCB, (XtPointer)pSD);
504 #ifndef NO_MESSAGE_CATALOG
505 rval = ((pPres->CancelW = wspCreatePushButton (pPres->formW,
506 "cancel", wmGD.cancelLabel)) != NULL);
508 tmpXmString = XmStringCreateLocalized ("Cancel");
509 rval = ((pPres->CancelW =
510 wspCreatePushButton (pPres->formW, "cancel", tmpXmString))
512 XmStringFree(tmpXmString);
514 XtAddCallback (pPres->CancelW, XmNactivateCallback,
515 (XtCallbackProc) wspCancelCB, (XtPointer)pSD);
517 /* set the cancel button (for KCancel) */
519 XtSetArg (args[n], XmNcancelButton, pPres->CancelW); n++;
520 XtSetValues (pPres->formW, args, n);
525 #ifndef NO_MESSAGE_CATALOG
526 rval = ((pPres->HelpW =
527 wspCreatePushButton (pPres->formW, "help", wmGD.helpLabel))
530 tmpXmString = XmStringCreateLocalized ("Help");
531 rval = ((pPres->HelpW =
532 wspCreatePushButton (pPres->formW, "help", tmpXmString))
534 XmStringFree(tmpXmString);
537 XtAddCallback (pPres->HelpW, XmNactivateCallback,
539 WM_DT_WSPRESENCE_TOPIC);
543 } /* END OF FUNCTION */
547 /*************************************<->*************************************
550 * wspCreateShell (pSD)
555 * Creates the shell widget for the workspace presence dialog
560 * psD = pointer to screen data
564 * Return = shell widget created
566 ******************************<->***********************************/
576 * Create top level shell for workspace presence dialog
581 XtSetArg (setArgs[i], XmNallowShellResize, (XtArgVal)True); i++;
583 XtSetArg (setArgs[i], XmNborderWidth, (XtArgVal)0); i++;
585 XtSetArg (setArgs[i], XmNkeyboardFocusPolicy,
586 (XtArgVal)XmEXPLICIT); i++;
588 XtSetArg (setArgs[i], XmNmappedWhenManaged,
589 (XtArgVal)False); i++;
591 XtSetArg (setArgs[i], XmNmwmFunctions,
592 PRESENCE_BOX_FUNCTIONS); i++;
594 XtSetArg (setArgs[i], XmNmwmDecorations,
595 (MWM_DECOR_TITLE|MWM_DECOR_BORDER)); i++;
597 XtSetArg (setArgs[i], XmNdepth,
598 (XtArgVal) DefaultDepth (DISPLAY1, pSD->screen)); i++;
600 XtSetArg (setArgs[i], XmNscreen, (XtArgVal)
601 ScreenOfDisplay (DISPLAY1, pSD->screen)); i++;
603 XtSetArg (setArgs[i], XtNcolormap,
604 (XtArgVal )DefaultColormap(DISPLAY1, pSD->screen)); i++;
606 shellW = (Widget) XtCreatePopupShell (WmNfeedback,
607 transientShellWidgetClass,
608 pSD->screenTopLevelW1,
609 (ArgList)setArgs, i);
613 } /* END OF FUNCTION wspCreateShell */
616 /*************************************<->*************************************
618 * wspCreateManager (shellW)
623 * Creates the manager widget for the workspace presence dialog
633 * Creates a form widget
634 ******************************<->***********************************/
643 /* !!! set colors? !!! */
645 formW = (Widget) XmCreateForm (shellW, "form", (ArgList) setArgs, 0);
647 XtAddCallback (formW, XmNhelpCallback,
648 WmDtWmTopicHelpCB, WM_DT_WSPRESENCE_TOPIC);
650 XtManageChild (formW);
653 } /* END OF FUNCTION */
657 /*************************************<->*************************************
659 * wspCreateLabel (mgrW, pchName, pchString)
664 * Creates a label widget as a child of the passed in manager
668 * mgrW = manager widget (parent of this label)
669 * pchName = name of the widget
670 * pchString = string that is to be in label
674 * Return = Widget created.
678 ******************************<->***********************************/
682 unsigned char *pchName,
683 unsigned char *pchString )
688 XmString tmpXmString = (XmString)NULL;
692 if (!strcmp((char *)pchName, "window"))
694 if (windowLabelString != (XmString)NULL)
695 XmStringFree(windowLabelString);
696 if (iconLabelString != (XmString)NULL)
697 XmStringFree(iconLabelString);
700 XmStringCreateLocalized ((char *)GETMESSAGE(52, 2, "Window: "));
702 * If we do this, USE the message catalog for iconLabelString
703 * just as we do for windowLabelString !!!
706 XmStringCreateLocalized ((char *)GETMESSAGE(52, 6, "Icon: "));
708 XtSetArg (setArgs[i], XmNlabelString, windowLabelString ); i++;
712 tmpXmString = XmStringCreateLocalized ((char *)pchString);
713 XtSetArg (setArgs[i], XmNlabelString, tmpXmString); i++;
716 labelW = XmCreateLabelGadget (mgrW, (char *)pchName, setArgs, i);
717 XtManageChild (labelW);
719 if (tmpXmString != (XmString)NULL)
720 XmStringFree(tmpXmString);
723 } /* END OF FUNCTION */
726 /*************************************<->*************************************
728 * wspCreateSeparator (mgrW)
733 * Creates a separator widget as a child of the passed in manager
737 * mgrW = manager widget (parent of this label)
741 * Return = Widget created.
745 ******************************<->***********************************/
756 sepW = XmCreateSeparatorGadget (mgrW, "separator", setArgs, i);
757 XtManageChild (sepW);
760 } /* END OF FUNCTION */
764 /*************************************<->*************************************
766 * wspCreateWorkspaceList (mgrW, pPres, pSD)
771 * Creates a list widget containing all the workspaces defined for a
776 * mgrW = manager widget (parent of this child)
777 * pPres = pointer to presence data
778 * pSD = ptr to screen data
782 * Return = widget created.
786 ******************************<->***********************************/
788 wspCreateWorkspaceList(
790 PtrWsPresenceData pPres,
798 #define MIN_VISIBLE 6
801 * Create the array of strings that will go into the list.
803 if (((pPres->ItemStrings = (XmStringTable) XtMalloc
804 (pSD->numWorkspaces * sizeof(XmString *))) == NULL) ||
805 ((pPres->ItemSelected = (Boolean *) XtMalloc
806 (pSD->numWorkspaces * sizeof(Boolean))) == NULL))
808 Warning (((char *)GETMESSAGE(52, 5, "Insufficient memory to create Occupy Workspace dialog.")));
812 pPres->numWorkspaces = pSD->numWorkspaces;
814 for (i = 0; i < pSD->numWorkspaces; i++)
816 pPres->ItemStrings[i] = XmStringCopy (pSD->pWS[i].title);
818 if (pSD->pWS[i].id == pSD->pActiveWS->id)
820 pPres->currentWsItem = 1+i;
830 XtSetArg (setArgs[i], XmNitemCount, pSD->numWorkspaces); i++;
832 XtSetArg (setArgs[i], XmNitems, pPres->ItemStrings); i++;
834 XtSetArg (setArgs[i], XmNselectionPolicy, XmEXTENDED_SELECT); i++;
836 XtSetArg (setArgs[i], XmNlistSizePolicy, XmRESIZE_IF_POSSIBLE); i++;
838 listW = XmCreateScrolledList (mgrW, "list", setArgs, i);
839 XtManageChild (listW);
841 if (pPres->pCDforClient)
844 * Highlight the workspaces this client resides in
846 for (i = 0; i < pPres->pCDforClient->pSD->numWorkspaces; i++)
848 if (ClientInWorkspace (&pPres->pCDforClient->pSD->pWS[i],
849 pPres->pCDforClient))
851 XmListSelectPos (listW, i+1, TRUE);
852 pPres->ItemSelected[i] = True;
856 pPres->ItemSelected[i] = False;
862 * Insure a minimum number are visible.
865 XtSetArg (setArgs[i], XmNvisibleItemCount, &numVisible); i++;
866 XtGetValues (listW, setArgs, i);
868 if (numVisible < MIN_VISIBLE)
871 XtSetArg (setArgs[i], XmNvisibleItemCount, MIN_VISIBLE);i++;
872 XtSetValues (listW, setArgs, i);
875 XtAddCallback (listW, XmNextendedSelectionCallback,
876 (XtCallbackProc) wspExtendedSelectCB, (XtPointer)pSD);
877 /* Handle the double-click just like if the Ok button was pressed */
878 XtAddCallback (listW, XmNdefaultActionCallback,
879 (XtCallbackProc) wspOkCB, (XtPointer)pSD);
883 } /* END OF FUNCTION */
886 /*************************************<->*************************************
888 * wspUpdateWorkspaceList (pPres)
893 * Updates the list widget containing all the workspaces.
894 * Sets the ones for this client.
898 * pPres = ptr to presence dialog data
906 ******************************<->***********************************/
908 wspUpdateWorkspaceList(
909 PtrWsPresenceData pPres )
912 XmString xmsTmp, *pxmsSelected;
915 int wsnum, numSelected;
918 * Update the list of workspaces to -- one may have been
919 * renamed since the last time we were up.
921 pSD = pPres->pCDforClient->pSD;
922 for (wsnum = 0; wsnum < pSD->numWorkspaces; wsnum++)
924 xmsTmp = XmStringCopy (pSD->pWS[wsnum].title);
926 if (!XmStringCompare (xmsTmp, pPres->ItemStrings[wsnum]))
929 * Replace the string in our local list
931 XmStringFree (pPres->ItemStrings[wsnum]);
932 pPres->ItemStrings[wsnum] = xmsTmp;
935 * Replace the item in the scrolled list.
937 XmListDeletePos (pPres->workspaceListW, 1+wsnum);
938 XmListAddItem (pPres->workspaceListW, xmsTmp, 1+wsnum);
942 XmStringFree (xmsTmp);
947 * Highlight the workspaces this client resides in
949 XmListDeselectAllItems (pPres->workspaceListW);
950 pxmsSelected = (XmString *)
951 XtMalloc (pPres->pCDforClient->pSD->numWorkspaces * sizeof (XmString));
953 for (wsnum = 0; wsnum < pPres->pCDforClient->pSD->numWorkspaces; wsnum++)
955 if (ClientInWorkspace (&pPres->pCDforClient->pSD->pWS[wsnum],
956 pPres->pCDforClient))
958 pxmsSelected[numSelected++] = pPres->ItemStrings[wsnum];
959 pPres->ItemSelected[wsnum] = True;
963 pPres->ItemSelected[wsnum] = False;
964 pPres->pCDforClient->putInAll = False;
967 if (pPres->pCDforClient->pSD->pActiveWS->id ==
968 pPres->pCDforClient->pSD->pWS[wsnum].id)
970 /* save item number of current workspace */
971 pPres->currentWsItem = 1+wsnum;
975 /* set the selected items */
977 XtSetArg (args[n], XmNselectedItems, pxmsSelected); n++;
978 XtSetArg (args[n], XmNselectedItemCount, numSelected); n++;
979 XtSetValues (pPres->workspaceListW, args, n);
981 /* set state of all workspaces button */
983 XtSetArg (args[n], XmNset, pPres->pCDforClient->putInAll); n++;
984 XtSetValues (pPres->allWsW, args, n);
986 /* set name of window we're popped up for */
987 wspSetWindowName (pPres);
989 XtFree ((char *) pxmsSelected);
991 } /* END OF FUNCTION */
994 /*************************************<->*************************************
996 * wspCreateToggleButton (mgrW, pch)
1001 * Creates a toggle button as a child of mgrW with the string pch.
1005 * mgrW = parent widget
1006 * pch = string to use for toggle button
1010 * Return = widget created
1014 ******************************<->***********************************/
1016 wspCreateToggleButton(
1018 unsigned char *pch )
1023 XmString labelString;
1027 labelString = XmStringCreateLocalized ((char *)pch);
1028 XtSetArg (setArgs[i], XmNlabelString, labelString); i++;
1030 toggleW = XmCreateToggleButton (mgrW, (char *)pch, setArgs, i);
1032 XmStringFree(labelString);
1034 XtManageChild (toggleW);
1038 } /* END OF FUNCTION wspCreateToggleButton */
1041 /*************************************<->*************************************
1043 * wspCreatePushButton (mgrW, label)
1048 * Creates a push button as a child of mgrW with the string pch.
1052 * mgrW = parent widget
1053 * label = XmString to use for button label
1057 * Return = widget created
1061 ******************************<->***********************************/
1063 wspCreatePushButton(
1075 XtSetArg (setArgs[i], XmNlabelString, label); i++;
1077 pushW = (Widget) XmCreatePushButton (mgrW, name, setArgs, i);
1079 XtManageChild (pushW);
1083 } /* END OF FUNCTION wspCreatePushButton */
1086 /*************************************<->*************************************
1088 * wspSetPosition (pPres)
1093 * Sets the position of the workspace presence dialog
1097 * pPres = pointer to workspace presence data
1102 ******************************<->***********************************/
1105 PtrWsPresenceData pPres )
1107 WmScreenData *pSD = pPres->pCDforClient->pSD;
1115 * Get size of this dialog
1118 XtSetArg (args[n], XmNheight, &height); n++;
1119 XtGetValues (pPres->shellW, args, n);
1121 if (wmGD.positionIsFrame)
1123 if (pSD->decoupleTitleAppearance)
1125 font = pSD->clientTitleAppearance.font;
1129 font = pSD->clientAppearance.font;
1132 height += TEXT_HEIGHT(font) + (2 * pSD->frameBorderWidth);
1137 * set position of dialog relative to client window
1138 * (use system menu position)
1139 * set this dialog to be transient for the client
1140 * for which it is posted.
1142 GetSystemMenuPosition (pPres->pCDforClient,
1144 pPres->contextForClient);
1147 XtSetArg (args[n], XmNx, x); n++;
1148 XtSetArg (args[n], XmNy, y); n++;
1149 XtSetArg (args[n], XmNtransientFor, NULL); n++;
1150 if (pPres->contextForClient != F_CONTEXT_ICON)
1152 XtSetArg (args[n], XmNwindowGroup, pPres->pCDforClient->client); n++;
1154 else if (pSD->useIconBox && P_ICON_BOX(pPres->pCDforClient))
1156 XtSetArg (args[n], XmNwindowGroup,
1157 P_ICON_BOX(pPres->pCDforClient)->pCD_iconBox->client); n++;
1161 XtSetArg (args[n], XmNwindowGroup, 0); n++;
1163 XtSetArg (args[n], XmNwaitForWm, False); n++;
1165 XtSetValues (pPres->shellW, args, n);
1167 } /* END OF FUNCTION wspSetPosition */
1170 /*************************************<->*************************************
1172 * wspCharWidth (xmfl)
1177 * Returns the max logical character width for this fontList
1186 * max logical character width
1190 ******************************<->***********************************/
1196 XmFontListEntry entry;
1197 Dimension dWidth, dTmpWidth;
1200 XFontSetExtents *pExtents;
1202 XmFontListInitFontContext ( &fc, xmfl);
1206 entry = XmFontListNextEntry (fc);
1209 pFont = XmFontListEntryGetFont (entry, &type);
1213 case XmFONT_IS_FONT:
1214 dTmpWidth = ((XFontStruct *)pFont)->max_bounds.rbearing -
1215 ((XFontStruct *)pFont)->min_bounds.lbearing;
1218 case XmFONT_IS_FONTSET:
1219 pExtents = XExtentsOfFontSet ((XFontSet) pFont);
1220 dTmpWidth = pExtents->max_logical_extent.width;
1228 if (dTmpWidth > dWidth)
1231 entry = XmFontListNextEntry (fc);
1234 XmFontListFreeFontContext (fc);
1240 /*************************************<->*************************************
1247 * Lays out the workspace presence dialog
1252 * pPres = pointer to workspace presence data
1260 ******************************<->***********************************/
1263 PtrWsPresenceData pPres )
1268 #define SEP_OFFSET 10
1269 #define IW_OFFSET_1 8
1270 #define IW_OFFSET_0 4
1274 XtSetArg (args[n], XmNtopAttachment, XmATTACH_POSITION); n++;
1275 XtSetArg (args[n], XmNtopPosition, 5); n++;
1276 XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); n++;
1277 XtSetArg (args[n], XmNleftOffset, 5); n++;
1278 XtSetArg (args[n], XmNrightAttachment, XmATTACH_NONE); n++;
1279 XtSetArg (args[n], XmNbottomAttachment, XmATTACH_NONE); n++;
1280 XtSetValues (pPres->windowLabelW, args, n);
1283 XtSetArg (args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
1284 XtSetArg (args[n], XmNtopWidget, pPres->windowLabelW); n++;
1285 XtSetArg (args[n], XmNtopOffset, IW_OFFSET_0); n++;
1286 XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); n++;
1287 XtSetArg (args[n], XmNleftOffset, 5); n++;
1288 XtSetArg (args[n], XmNrightAttachment, XmATTACH_NONE); n++;
1289 XtSetArg (args[n], XmNbottomAttachment, XmATTACH_NONE); n++;
1290 XtSetArg (args[n], XmNbottomOffset, 0); n++;
1291 XtSetValues (pPres->workspaceLabelW, args, n);
1294 XtSetArg (args[n], XmNtopAttachment, XmATTACH_POSITION); n++;
1295 XtSetArg (args[n], XmNtopPosition, 5); n++;
1296 XtSetArg (args[n], XmNleftAttachment, XmATTACH_WIDGET); n++;
1297 XtSetArg (args[n], XmNleftWidget, pPres->workspaceLabelW); n++;
1298 XtSetArg (args[n], XmNleftOffset, 5); n++;
1299 XtSetArg (args[n], XmNrightAttachment, XmATTACH_FORM); n++;
1300 XtSetArg (args[n], XmNrightOffset, 5); n++;
1301 XtSetArg (args[n], XmNbottomAttachment, XmATTACH_NONE); n++;
1302 XtSetArg (args[n], XmNbottomOffset, 0); n++;
1303 XtSetArg (args[n], XmNalignment, XmALIGNMENT_BEGINNING); n++;
1304 XtSetValues (pPres->windowNameW, args, n);
1307 XtSetArg (args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
1308 XtSetArg (args[n], XmNtopWidget, pPres->windowNameW); n++;
1309 XtSetArg (args[n], XmNtopOffset, IW_OFFSET_0); n++;
1310 XtSetArg (args[n], XmNleftAttachment, XmATTACH_WIDGET); n++;
1311 XtSetArg (args[n], XmNleftWidget, pPres->workspaceLabelW); n++;
1312 XtSetArg (args[n], XmNleftOffset, 5); n++;
1313 XtSetArg (args[n], XmNrightAttachment, XmATTACH_FORM); n++;
1314 XtSetArg (args[n], XmNrightOffset, 5); n++;
1315 XtSetArg (args[n], XmNbottomAttachment, XmATTACH_NONE); n++;
1316 XtSetArg (args[n], XmNbottomOffset, 0); n++;
1317 XtSetValues (pPres->workspaceScrolledListW, args, n);
1320 XtSetArg (args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
1321 XtSetArg (args[n], XmNtopWidget, pPres->workspaceScrolledListW); n++;
1322 XtSetArg (args[n], XmNtopOffset, IW_OFFSET_1); n++;
1323 XtSetArg (args[n], XmNleftAttachment, XmATTACH_WIDGET); n++;
1324 XtSetArg (args[n], XmNleftWidget, pPres->workspaceLabelW); n++;
1325 XtSetArg (args[n], XmNleftOffset, 5); n++;
1326 XtSetArg (args[n], XmNrightAttachment, XmATTACH_FORM); n++;
1327 XtSetArg (args[n], XmNrightOffset, 5); n++;
1328 XtSetArg (args[n], XmNalignment, XmALIGNMENT_BEGINNING); n++;
1329 XtSetArg (args[n], XmNmarginRight, 5); n++;
1330 XtSetArg (args[n], XmNbottomAttachment, XmATTACH_NONE); n++;
1331 XtSetArg (args[n], XmNbottomOffset, 0); n++;
1332 XtSetValues (pPres->allWsW, args, n);
1335 XtSetArg (args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
1336 XtSetArg (args[n], XmNtopWidget, pPres->allWsW); n++;
1337 XtSetArg (args[n], XmNtopOffset, SEP_OFFSET); n++;
1338 XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); n++;
1339 XtSetArg (args[n], XmNleftOffset, 0); n++;
1340 XtSetArg (args[n], XmNrightAttachment, XmATTACH_FORM); n++;
1341 XtSetArg (args[n], XmNrightOffset, 0); n++;
1342 XtSetArg (args[n], XmNbottomAttachment, XmATTACH_NONE); n++;
1343 XtSetArg (args[n], XmNbottomOffset, 0); n++;
1344 XtSetValues (pPres->sepW, args, n);
1347 XtSetArg (args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
1348 XtSetArg (args[n], XmNtopWidget, pPres->sepW); n++;
1349 XtSetArg (args[n], XmNtopOffset, SEP_OFFSET); n++;
1350 XtSetArg (args[n], XmNleftAttachment, XmATTACH_POSITION); n++;
1351 XtSetArg (args[n], XmNleftPosition, 5); n++;
1352 XtSetArg (args[n], XmNrightAttachment, XmATTACH_POSITION); n++;
1353 XtSetArg (args[n], XmNrightPosition, 30); n++;
1354 XtSetArg (args[n], XmNbottomAttachment, XmATTACH_POSITION); n++;
1355 XtSetArg (args[n], XmNbottomPosition, 95); n++;
1356 XtSetValues (pPres->OkW, args, n);
1359 XtSetArg (args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
1360 XtSetArg (args[n], XmNtopWidget, pPres->sepW); n++;
1361 XtSetArg (args[n], XmNtopOffset, SEP_OFFSET); n++;
1362 XtSetArg (args[n], XmNleftAttachment, XmATTACH_POSITION); n++;
1363 XtSetArg (args[n], XmNleftPosition, 36); n++;
1364 XtSetArg (args[n], XmNrightAttachment, XmATTACH_POSITION); n++;
1365 XtSetArg (args[n], XmNrightPosition, 66); n++;
1366 XtSetArg (args[n], XmNbottomAttachment, XmATTACH_POSITION); n++;
1367 XtSetArg (args[n], XmNbottomPosition, 95); n++;
1368 XtSetValues (pPres->CancelW, args, n);
1371 XtSetArg (args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
1372 XtSetArg (args[n], XmNtopWidget, pPres->sepW); n++;
1373 XtSetArg (args[n], XmNtopOffset, SEP_OFFSET); n++;
1374 XtSetArg (args[n], XmNleftAttachment, XmATTACH_POSITION); n++;
1375 XtSetArg (args[n], XmNleftPosition, 71); n++;
1376 XtSetArg (args[n], XmNrightAttachment, XmATTACH_POSITION); n++;
1377 XtSetArg (args[n], XmNrightPosition, 95); n++;
1378 XtSetArg (args[n], XmNbottomAttachment, XmATTACH_POSITION); n++;
1379 XtSetArg (args[n], XmNbottomPosition, 95); n++;
1380 XtSetValues (pPres->HelpW, args, n);
1381 } /* END OF FUNCTION */
1385 /*************************************<->*************************************
1388 * wspOkCB (w, client_data, call_data)
1398 * pSD = pointer to screen data
1410 *************************************<->***********************************/
1416 XtPointer call_data )
1420 int selectedItemCount;
1421 XmStringTable selectedItems;
1422 PtrWsPresenceData pPres = &pSD->presence;
1423 Boolean bAllSelected;
1426 /* find the selected workspaces */
1428 XtSetArg (args[n], XmNselectedItemCount, &selectedItemCount); n++;
1429 XtSetArg (args[n], XmNselectedItems, &selectedItems); n++;
1430 XtGetValues (pPres->workspaceListW, args, n);
1432 /* find the state of all workspaces button */
1434 XtSetArg (args[n], XmNset, &bAllSelected); n++;
1435 XtGetValues (pPres->allWsW, args, n);
1439 F_AddToAllWorkspaces(NULL, pPres->pCDforClient, NULL);
1441 else if (selectedItemCount)
1443 for (n = 0; n < pSD->numWorkspaces; n++)
1445 pPres->ItemSelected[n] = False;
1446 for (j = 0; j < selectedItemCount; j++)
1448 if (XmStringCompare (selectedItems[j],
1449 pPres->ItemStrings[n]))
1451 pPres->ItemSelected[n] = True;
1455 if (!pPres->ItemSelected[n] &&
1456 ClientInWorkspace (&pSD->pWS[n], pPres->pCDforClient))
1458 RemoveClientFromWorkspaces (pPres->pCDforClient,
1459 &pSD->pWS[n].id, 1);
1462 if (pPres->ItemSelected[n] &&
1463 !ClientInWorkspace (&pSD->pWS[n], pPres->pCDforClient))
1465 AddClientToWorkspaces (pPres->pCDforClient,
1466 &pSD->pWS[n].id, 1);
1471 /* withdraw the dialog */
1472 wspCancelCB (buttonW, (XtPointer)pSD, call_data);
1473 } /* END OF FUNCTION */
1475 /*************************************<->*************************************
1478 * wspAllWsCB (w, client_data, call_data)
1483 * All Workspace toggle button callback.
1500 *************************************<->***********************************/
1506 XmToggleButtonCallbackStruct *xmTbcs )
1508 PtrWsPresenceData pPres = &pSD->presence;
1510 XmString *pxmsSelected;
1514 if (xmTbcs->reason == XmCR_VALUE_CHANGED)
1518 pxmsSelected = (XmString *)
1519 XtMalloc (pSD->numWorkspaces * sizeof (XmString));
1521 for (wsnum = 0; wsnum < pSD->numWorkspaces; wsnum++)
1523 pxmsSelected[wsnum] = pPres->ItemStrings[wsnum];
1526 /* set the selected items */
1528 XtSetArg (args[n], XmNselectedItems, pxmsSelected); n++;
1529 XtSetArg (args[n], XmNselectedItemCount, pSD->numWorkspaces); n++;
1530 XtSetValues (pPres->workspaceListW, args, n);
1532 XtFree ((char *) pxmsSelected);
1536 /* select current workspace */
1537 XmListDeselectAllItems (pPres->workspaceListW);
1538 XmListSelectPos (pPres->workspaceListW, pPres->currentWsItem, TRUE);
1541 } /* END OF FUNCTION */
1546 /*************************************<->*************************************
1549 * wspExtendedSelectCB (w, client_data, cb)
1571 *************************************<->***********************************/
1574 wspExtendedSelectCB(
1576 XtPointer client_data,
1577 XmListCallbackStruct *cb )
1579 WmScreenData *pSD = (WmScreenData *) client_data;
1580 PtrWsPresenceData pPres = &pSD->presence;
1584 if (cb->reason == XmCR_EXTENDED_SELECT)
1586 if ((cb->selected_item_count < pSD->numWorkspaces) &&
1587 (cb->event != None))
1590 XtSetArg (args[n], XmNset, False); n++;
1591 XtSetValues (pPres->allWsW, args, n);
1595 } /* END OF FUNCTION wspExtendedSelectCB */
1599 /*************************************<->*************************************
1602 * wspCancelCB (w, client_data, call_data)
1624 *************************************<->***********************************/
1629 XtPointer client_data,
1630 XtPointer call_data )
1632 WmScreenData *pSD = (WmScreenData *) client_data;
1634 XtPopdown (pSD->presence.shellW);
1635 pSD->presence.onScreen = False;
1637 } /* END OF FUNCTION wspCancelCB */
1640 /*************************************<->*************************************
1642 * GetPresenceBoxMenuItems (pSD)
1649 *************************************<->***********************************/
1652 GetPresenceBoxMenuItems(
1658 } /* END OF FUNCTION GetPresenceBoxMenuItems */
1661 /*************************************<->*************************************
1663 * UpdatePresenceWorkspaces (pSD)
1668 * Update the presence dialog when the number of workspaces changes.
1670 *************************************<->***********************************/
1673 UpdatePresenceWorkspaces(
1676 PtrWsPresenceData pPres = &pSD->presence;
1682 if (pPres->numWorkspaces < pSD->numWorkspaces)
1684 if (((pPres->ItemStrings = (XmStringTable) XtRealloc
1685 ((char *)pPres->ItemStrings,
1686 (pSD->numWorkspaces * sizeof(XmString *)))) == NULL) ||
1687 ((pPres->ItemSelected = (Boolean *) XtRealloc
1688 ((char *)pPres->ItemSelected,
1689 (pSD->numWorkspaces * sizeof(Boolean)))) == NULL))
1691 Warning (((char *)GETMESSAGE(52, 5, "Insufficient memory to create Occupy Workspace dialog.")));
1692 pPres->shellW = NULL;
1698 * Replace the names in the dialog's list
1700 for (wsnum = 0; wsnum < pPres->numWorkspaces; wsnum++)
1702 if (wsnum < pSD->numWorkspaces)
1704 xmsTmp = XmStringCopy (pSD->pWS[wsnum].title);
1706 if (!XmStringCompare (xmsTmp, pPres->ItemStrings[wsnum]))
1709 * Replace the string in our local list
1711 XmStringFree (pPres->ItemStrings[wsnum]);
1712 pPres->ItemStrings[wsnum] = xmsTmp;
1715 * Replace the item in the scrolled list.
1717 XmListDeletePos (pPres->workspaceListW, 1+wsnum);
1718 XmListAddItem (pPres->workspaceListW, xmsTmp, 1+wsnum);
1722 XmStringFree (xmsTmp);
1728 * Delete this workspace from the list
1730 XmStringFree (pPres->ItemStrings[wsnum]);
1731 pPres->ItemStrings[wsnum] = NULL;
1732 XmListDeletePos (pPres->workspaceListW, 1+wsnum);
1735 for (; wsnum < pSD->numWorkspaces; wsnum++)
1738 * Add these workspaces to the list.
1740 xmsTmp = XmStringCopy (pSD->pWS[wsnum].title);
1741 pPres->ItemStrings[wsnum] = xmsTmp;
1742 XmListAddItem (pPres->workspaceListW, xmsTmp, 1+wsnum);
1744 if (pPres->pCDforClient &&
1745 (ClientInWorkspace (&pPres->pCDforClient->pSD->pWS[wsnum],
1746 pPres->pCDforClient)))
1748 XmListSelectPos (pPres->workspaceListW, 1+wsnum, TRUE);
1749 pPres->ItemSelected[wsnum] = True;
1753 pPres->ItemSelected[wsnum] = False;
1757 pPres->numWorkspaces = pSD->numWorkspaces;
1760 } /* END OF FUNCTION UpdatePresenceWorkspaces */
1762 /**************************** eof ***************************/