WmPresence.c 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762
  1. /*
  2. * CDE - Common Desktop Environment
  3. *
  4. * Copyright (c) 1993-2012, The Open Group. All rights reserved.
  5. *
  6. * These libraries and programs are free software; you can
  7. * redistribute them and/or modify them under the terms of the GNU
  8. * Lesser General Public License as published by the Free Software
  9. * Foundation; either version 2 of the License, or (at your option)
  10. * any later version.
  11. *
  12. * These libraries and programs are distributed in the hope that
  13. * they will be useful, but WITHOUT ANY WARRANTY; without even the
  14. * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  15. * PURPOSE. See the GNU Lesser General Public License for more
  16. * details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with these libraries and programs; if not, write
  20. * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
  21. * Floor, Boston, MA 02110-1301 USA
  22. */
  23. /*
  24. * (c) Copyright 1987, 1988, 1989, 1990, 1992 HEWLETT-PACKARD COMPANY
  25. * ALL RIGHTS RESERVED
  26. */
  27. /*
  28. * Included Files:
  29. */
  30. #include "WmGlobal.h"
  31. #include "WmResNames.h"
  32. #include "WmHelp.h"
  33. #include "WmError.h"
  34. #include <X11/Core.h>
  35. #include <X11/StringDefs.h>
  36. #include <X11/Intrinsic.h>
  37. #include <X11/Xatom.h>
  38. #include <X11/Shell.h>
  39. #include <Xm/Xm.h>
  40. #include <Xm/Form.h>
  41. #include <Xm/PushBG.h>
  42. #include <Xm/PushB.h>
  43. #include <Xm/LabelG.h>
  44. #include <Xm/List.h>
  45. #include <Xm/SeparatoG.h>
  46. #include <Xm/ToggleB.h>
  47. #include <errno.h>
  48. #include <signal.h>
  49. #include <stdio.h>
  50. /*
  51. * Function Declarations:
  52. */
  53. #include "WmPresence.h"
  54. /******** Static Function Declarations ********/
  55. static void wspSetWindowName(
  56. PtrWsPresenceData pPres) ;
  57. static Boolean wspCreateWidgets(
  58. WmScreenData *pSD) ;
  59. static Widget wspCreateShell(
  60. WmScreenData *pSD) ;
  61. static Widget wspCreateManager(
  62. Widget shellW) ;
  63. static Widget wspCreateLabel(
  64. Widget mgrW,
  65. unsigned char *pchName,
  66. unsigned char *pchString) ;
  67. static Widget wspCreateSeparator(
  68. Widget mgrW) ;
  69. static Widget wspCreateWorkspaceList(
  70. Widget mgrW,
  71. PtrWsPresenceData pPres,
  72. WmScreenData *pSD) ;
  73. static void wspUpdateWorkspaceList(
  74. PtrWsPresenceData pPres) ;
  75. static Widget wspCreateToggleButton(
  76. Widget mgrW,
  77. unsigned char *pch) ;
  78. static Widget wspCreatePushButton(
  79. Widget mgrW,
  80. char *name,
  81. XmString label) ;
  82. static void wspSetPosition(
  83. PtrWsPresenceData pPres) ;
  84. static void wspLayout(
  85. PtrWsPresenceData pPres) ;
  86. static void wspOkCB(
  87. Widget buttonW,
  88. WmScreenData *pSD,
  89. XtPointer call_data) ;
  90. static void wspHelpCB(
  91. Widget buttonW,
  92. XtPointer client_data,
  93. XtPointer call_data) ;
  94. static void wspAllWsCB(
  95. Widget buttonW,
  96. WmScreenData *pSD,
  97. XmToggleButtonCallbackStruct *xmTbcs) ;
  98. static void wspCancelCB(
  99. Widget buttonW,
  100. XtPointer client_data,
  101. XtPointer call_data) ;
  102. static void wspExtendedSelectCB(
  103. Widget w,
  104. XtPointer client_data,
  105. XmListCallbackStruct *cb );
  106. static Dimension wspCharWidth (
  107. XmFontList xmfl);
  108. /******** End Static Function Declarations ********/
  109. /*
  110. * External references
  111. */
  112. #include "WmCDecor.h"
  113. #include "WmCDInfo.h"
  114. #include "WmIconBox.h"
  115. #include "WmPanelP.h" /* for typedef in WmManage.h */
  116. #include "WmManage.h"
  117. #include "WmResParse.h"
  118. #include "WmResource.h"
  119. #include "WmWinInfo.h"
  120. #include "WmWrkspace.h"
  121. /*
  122. * Global Variables:
  123. */
  124. /*
  125. * These two XmStrings are used in the workspace
  126. * presence box to indicate the name of the current
  127. * window for whice the presence box is active. If the
  128. * window is iconified, the title will be "Icon: <iconName>",
  129. * otherwise the title wil be "Window: <windowName>
  130. */
  131. XmString windowLabelString = (XmString)NULL;
  132. XmString iconLabelString = (XmString)NULL;
  133. /*************************************<->*************************************
  134. *
  135. * Boolean
  136. * MakePresenceBox (pSD)
  137. *
  138. *
  139. * Description:
  140. * -----------
  141. *
  142. *
  143. * Inputs:
  144. * ------
  145. * pSD = pointer to screen data
  146. *
  147. *
  148. * Outputs:
  149. * -------
  150. * Return = (Boolean) True if successful
  151. *
  152. *
  153. * Comments:
  154. * --------
  155. *
  156. ******************************<->***********************************/
  157. Boolean
  158. MakePresenceBox(
  159. WmScreenData *pSD )
  160. {
  161. PtrWsPresenceData pPres = &pSD->presence;
  162. Boolean rval;
  163. /*
  164. * Create the widgets for the workspace presence dialog
  165. */
  166. pPres->onScreen = False;
  167. if (wspCreateWidgets (pSD))
  168. {
  169. /*
  170. * lay out the form
  171. */
  172. wspLayout (pPres);
  173. /*
  174. * Set the ClientData fields.
  175. */
  176. XtRealizeWidget (pPres->shellW);
  177. DtWsmRemoveWorkspaceFunctions (DISPLAY1, XtWindow(pPres->shellW));
  178. ProcessPresenceResources (pSD);
  179. rval = True;
  180. }
  181. else
  182. {
  183. Warning(((char *)GETMESSAGE(52, 1, "Unable to create Occupy Workspace dialog.")));
  184. rval = False;
  185. }
  186. return (rval);
  187. } /* END OF FUNCTION MakePresenceBox */
  188. /*************************************<->*************************************
  189. *
  190. * void
  191. * ShowPresenceBox (pClient, wsContext)
  192. *
  193. *
  194. * Description:
  195. * -----------
  196. * Pops up (shows) the workspace presence dialog
  197. *
  198. * Inputs:
  199. * ------
  200. * pClient = pointer to client data which needs a presence dialog
  201. * up. (This is not the presence dialog's client data!!!)
  202. *
  203. * wsContext = context to post dialog for
  204. *
  205. *
  206. * Outputs:
  207. * -------
  208. * Return = none
  209. *
  210. *
  211. * Comments:
  212. * --------
  213. *
  214. ******************************<->***********************************/
  215. void
  216. ShowPresenceBox(
  217. ClientData *pClient,
  218. Context wsContext )
  219. {
  220. PtrWsPresenceData pPres;
  221. WmScreenData *pSD;
  222. pPres = &pClient->pSD->presence;
  223. pSD = pClient->pSD;
  224. pPres->pCDforClient = pClient;
  225. pPres->contextForClient = wsContext;
  226. /*
  227. * Create the presence dialog if not done yet.
  228. */
  229. if (!pSD->presence.shellW)
  230. {
  231. pPres->ItemSelected = NULL;
  232. pPres->ItemStrings = NULL;
  233. pPres->currentWsItem = 0;
  234. MakePresenceBox (pSD);
  235. }
  236. if (pPres->onScreen)
  237. {
  238. HidePresenceBox (pSD, True);
  239. }
  240. /* update workspace list */
  241. wspUpdateWorkspaceList (pPres);
  242. /* set position of dialog relative to client window */
  243. wspSetPosition (pPres);
  244. /*
  245. * pop it up
  246. */
  247. XtPopup (pPres->shellW, XtGrabNone);
  248. pPres->onScreen = True;
  249. } /* END OF FUNCTION ShowPresenceBox */
  250. /*************************************<->*************************************
  251. *
  252. * static void
  253. * wspSetWindowName (pPres)
  254. *
  255. *
  256. * Description:
  257. * -----------
  258. * Sets the name of the current window in the presence dialog
  259. *
  260. * Inputs:
  261. * ------
  262. * pPres = ptr to workspace presence dialog data
  263. *
  264. * Outputs:
  265. * -------
  266. * Return = none
  267. *
  268. *
  269. * Comments:
  270. * --------
  271. *
  272. ******************************<->***********************************/
  273. static void
  274. wspSetWindowName(
  275. PtrWsPresenceData pPres )
  276. {
  277. int nameN, labelN;
  278. Arg nameArgs[1];
  279. Arg labelArgs[1];
  280. /*
  281. * Set the name of the current window
  282. */
  283. nameN = 0;
  284. labelN = 0;
  285. if (pPres->contextForClient == F_CONTEXT_ICON)
  286. {
  287. XtSetArg (nameArgs[nameN], XmNlabelString,
  288. ICON_DISPLAY_TITLE(pPres->pCDforClient)); nameN++;
  289. XtSetArg (labelArgs[labelN], XmNlabelString,
  290. iconLabelString); labelN++;
  291. }
  292. else
  293. {
  294. XtSetArg (nameArgs[nameN], XmNlabelString,
  295. CLIENT_DISPLAY_TITLE(pPres->pCDforClient)); nameN++;
  296. XtSetArg (labelArgs[labelN], XmNlabelString,
  297. windowLabelString); labelN++;
  298. }
  299. XtSetValues (pPres->windowNameW, nameArgs, nameN);
  300. XtSetValues (pPres->windowLabelW, labelArgs, labelN);
  301. } /* END OF FUNCTION wspSetWindowName */
  302. /*************************************<->*************************************
  303. *
  304. * void
  305. * HidePresenceBox (pSD, userDismissed)
  306. *
  307. *
  308. * Description:
  309. * -----------
  310. * Pops down (hides) the workspace presence dialog
  311. *
  312. * Inputs:
  313. * ------
  314. * pSD = pointer to screen data
  315. * userDismissed = did the user dismiss or did workspace switching
  316. * unpost the workspace presence box ?
  317. *
  318. * Outputs:
  319. * -------
  320. * Return = none
  321. *
  322. *
  323. * Comments:
  324. * --------
  325. *
  326. ******************************<->***********************************/
  327. void
  328. HidePresenceBox(
  329. WmScreenData *pSD,
  330. Boolean userDismissed )
  331. {
  332. if (pSD->presence.onScreen)
  333. {
  334. /* Pop down the shell */
  335. XtPopdown (pSD->presence.shellW);
  336. /*
  337. * Do a withdraw to make sure window gets unmanaged
  338. * (popdown does nothing if its unmapped)
  339. */
  340. XWithdrawWindow (DISPLAY, XtWindow (pSD->presence.shellW),
  341. pSD->screen);
  342. /* must sync to insure event order */
  343. XSync (DISPLAY, False);
  344. pSD->presence.onScreen = False;
  345. pSD->presence.userDismissed = userDismissed;
  346. }
  347. } /* END OF FUNCTION */
  348. /*************************************<->*************************************
  349. *
  350. * wspCreateWidgets (pSD)
  351. *
  352. *
  353. * Description:
  354. * -----------
  355. * Creates all the widgets for the workspace presence dialog box
  356. *
  357. * Inputs:
  358. * ------
  359. * pSD = pointer to screen data
  360. *
  361. * Outputs:
  362. * -------
  363. * Return = false on any failure
  364. *
  365. * Comments:
  366. * ---------
  367. * Only creates widgets
  368. ******************************<->***********************************/
  369. static Boolean
  370. wspCreateWidgets(
  371. WmScreenData *pSD )
  372. {
  373. PtrWsPresenceData pPres = &pSD->presence;
  374. Arg args [5];
  375. int n;
  376. Boolean rval /* = True */;
  377. #ifdef NO_MESSAGE_CATALOG
  378. XmString tmpXmString;
  379. #endif /* NO_MESSAGE_CATALOG */
  380. rval = ((pPres->shellW = wspCreateShell (pSD)) != NULL);
  381. if (rval)
  382. {
  383. rval = ((pPres->formW = wspCreateManager (pPres->shellW)) != NULL);
  384. }
  385. if (rval)
  386. {
  387. rval = ((pPres->windowLabelW = wspCreateLabel (pPres->formW,
  388. (unsigned char *)"window",
  389. NULL)) != NULL);
  390. }
  391. if (rval)
  392. {
  393. rval = ((pPres->windowNameW = wspCreateLabel (pPres->formW,
  394. (unsigned char *)"windowName",
  395. (unsigned char *)" ")) != NULL);
  396. }
  397. if (rval)
  398. {
  399. rval = ((pPres->workspaceLabelW =
  400. wspCreateLabel (pPres->formW, (unsigned char *)"workspaces",
  401. ((unsigned char *)GETMESSAGE(52, 3, "Workspaces: ")))) != NULL);
  402. }
  403. if (rval)
  404. {
  405. rval = ((pPres->workspaceListW =
  406. wspCreateWorkspaceList (pPres->formW, pPres, pSD)) != NULL);
  407. pPres->workspaceScrolledListW = XtParent (pPres->workspaceListW);
  408. }
  409. if (rval)
  410. {
  411. rval = ((pPres->allWsW = wspCreateToggleButton (pPres->formW,
  412. ((unsigned char *)GETMESSAGE(52, 4, "All Workspaces"))))
  413. != NULL);
  414. XtAddCallback (pPres->allWsW, XmNvalueChangedCallback,
  415. (XtCallbackProc)wspAllWsCB, (XtPointer)pSD);
  416. }
  417. if (rval)
  418. {
  419. rval = ((pPres->sepW = wspCreateSeparator (pPres->formW)) != NULL);
  420. }
  421. if (rval)
  422. {
  423. #ifndef NO_MESSAGE_CATALOG
  424. rval = ((pPres->OkW =
  425. wspCreatePushButton (pPres->formW, "ok", wmGD.okLabel))
  426. != NULL);
  427. #else
  428. tmpXmString = XmStringCreateLocalized ("OK");
  429. rval = ((pPres->OkW =
  430. wspCreatePushButton (pPres->formW, "ok", tmpXmString))
  431. != NULL);
  432. XmStringFree(tmpXmString);
  433. #endif
  434. /* set the default action */
  435. n = 0;
  436. XtSetArg (args[n], XmNdefaultButton, pPres->OkW); n++;
  437. XtSetValues (pPres->formW, args, n);
  438. XtAddCallback (pPres->OkW, XmNactivateCallback,
  439. (XtCallbackProc) wspOkCB, (XtPointer)pSD);
  440. }
  441. if (rval)
  442. {
  443. #ifndef NO_MESSAGE_CATALOG
  444. rval = ((pPres->CancelW = wspCreatePushButton (pPres->formW,
  445. "cancel", wmGD.cancelLabel)) != NULL);
  446. #else
  447. tmpXmString = XmStringCreateLocalized ("Cancel");
  448. rval = ((pPres->CancelW =
  449. wspCreatePushButton (pPres->formW, "cancel", tmpXmString))
  450. != NULL);
  451. XmStringFree(tmpXmString);
  452. #endif
  453. XtAddCallback (pPres->CancelW, XmNactivateCallback,
  454. (XtCallbackProc) wspCancelCB, (XtPointer)pSD);
  455. /* set the cancel button (for KCancel) */
  456. n = 0;
  457. XtSetArg (args[n], XmNcancelButton, pPres->CancelW); n++;
  458. XtSetValues (pPres->formW, args, n);
  459. }
  460. if (rval)
  461. {
  462. #ifndef NO_MESSAGE_CATALOG
  463. rval = ((pPres->HelpW =
  464. wspCreatePushButton (pPres->formW, "help", wmGD.helpLabel))
  465. != NULL);
  466. #else
  467. tmpXmString = XmStringCreateLocalized ("Help");
  468. rval = ((pPres->HelpW =
  469. wspCreatePushButton (pPres->formW, "help", tmpXmString))
  470. != NULL);
  471. XmStringFree(tmpXmString);
  472. #endif
  473. XtAddCallback (pPres->HelpW, XmNactivateCallback,
  474. WmDtWmTopicHelpCB,
  475. WM_DT_WSPRESENCE_TOPIC);
  476. }
  477. return(rval);
  478. } /* END OF FUNCTION */
  479. /*************************************<->*************************************
  480. *
  481. * Widget
  482. * wspCreateShell (pSD)
  483. *
  484. *
  485. * Description:
  486. * -----------
  487. * Creates the shell widget for the workspace presence dialog
  488. *
  489. *
  490. * Inputs:
  491. * ------
  492. * psD = pointer to screen data
  493. *
  494. * Outputs:
  495. * -------
  496. * Return = shell widget created
  497. *
  498. ******************************<->***********************************/
  499. static Widget
  500. wspCreateShell(
  501. WmScreenData *pSD )
  502. {
  503. Arg setArgs[20];
  504. int i;
  505. Widget shellW;
  506. /*
  507. * Create top level shell for workspace presence dialog
  508. */
  509. i=0;
  510. XtSetArg (setArgs[i], XmNallowShellResize, (XtArgVal)True); i++;
  511. XtSetArg (setArgs[i], XmNborderWidth, (XtArgVal)0); i++;
  512. XtSetArg (setArgs[i], XmNkeyboardFocusPolicy,
  513. (XtArgVal)XmEXPLICIT); i++;
  514. XtSetArg (setArgs[i], XmNmappedWhenManaged,
  515. (XtArgVal)False); i++;
  516. XtSetArg (setArgs[i], XmNmwmFunctions,
  517. PRESENCE_BOX_FUNCTIONS); i++;
  518. XtSetArg (setArgs[i], XmNmwmDecorations,
  519. (MWM_DECOR_TITLE|MWM_DECOR_BORDER)); i++;
  520. XtSetArg (setArgs[i], XmNdepth,
  521. (XtArgVal) DefaultDepth (DISPLAY1, pSD->screen)); i++;
  522. XtSetArg (setArgs[i], XmNscreen, (XtArgVal)
  523. ScreenOfDisplay (DISPLAY1, pSD->screen)); i++;
  524. XtSetArg (setArgs[i], XtNcolormap,
  525. (XtArgVal )DefaultColormap(DISPLAY1, pSD->screen)); i++;
  526. shellW = (Widget) XtCreatePopupShell (WmNfeedback,
  527. transientShellWidgetClass,
  528. pSD->screenTopLevelW1,
  529. (ArgList)setArgs, i);
  530. return (shellW);
  531. } /* END OF FUNCTION wspCreateShell */
  532. /*************************************<->*************************************
  533. *
  534. * wspCreateManager (shellW)
  535. *
  536. *
  537. * Description:
  538. * -----------
  539. * Creates the manager widget for the workspace presence dialog
  540. *
  541. * Inputs:
  542. * ------
  543. *
  544. * Outputs:
  545. * -------
  546. *
  547. * Comments:
  548. * ---------
  549. * Creates a form widget
  550. ******************************<->***********************************/
  551. static Widget
  552. wspCreateManager(
  553. Widget shellW )
  554. {
  555. Arg setArgs[20];
  556. Widget formW;
  557. /* !!! set colors? !!! */
  558. formW = (Widget) XmCreateForm (shellW, "form", (ArgList) setArgs, 0);
  559. XtAddCallback (formW, XmNhelpCallback,
  560. WmDtWmTopicHelpCB, WM_DT_WSPRESENCE_TOPIC);
  561. XtManageChild (formW);
  562. return (formW);
  563. } /* END OF FUNCTION */
  564. /*************************************<->*************************************
  565. *
  566. * wspCreateLabel (mgrW, pchName, pchString)
  567. *
  568. *
  569. * Description:
  570. * -----------
  571. * Creates a label widget as a child of the passed in manager
  572. *
  573. * Inputs:
  574. * ------
  575. * mgrW = manager widget (parent of this label)
  576. * pchName = name of the widget
  577. * pchString = string that is to be in label
  578. *
  579. * Outputs:
  580. * -------
  581. * Return = Widget created.
  582. *
  583. * Comments:
  584. * ---------
  585. ******************************<->***********************************/
  586. static Widget
  587. wspCreateLabel(
  588. Widget mgrW,
  589. unsigned char *pchName,
  590. unsigned char *pchString )
  591. {
  592. Arg setArgs[20];
  593. int i;
  594. Widget labelW;
  595. XmString tmpXmString = (XmString)NULL;
  596. i = 0;
  597. if (!strcmp((char *)pchName, "window"))
  598. {
  599. if (windowLabelString != (XmString)NULL)
  600. XmStringFree(windowLabelString);
  601. if (iconLabelString != (XmString)NULL)
  602. XmStringFree(iconLabelString);
  603. windowLabelString =
  604. XmStringCreateLocalized ((char *)GETMESSAGE(52, 2, "Window: "));
  605. /*
  606. * If we do this, USE the message catalog for iconLabelString
  607. * just as we do for windowLabelString !!!
  608. */
  609. iconLabelString =
  610. XmStringCreateLocalized ((char *)GETMESSAGE(52, 6, "Icon: "));
  611. XtSetArg (setArgs[i], XmNlabelString, windowLabelString ); i++;
  612. }
  613. else
  614. {
  615. tmpXmString = XmStringCreateLocalized ((char *)pchString);
  616. XtSetArg (setArgs[i], XmNlabelString, tmpXmString); i++;
  617. }
  618. labelW = XmCreateLabelGadget (mgrW, (char *)pchName, setArgs, i);
  619. XtManageChild (labelW);
  620. if (tmpXmString != (XmString)NULL)
  621. XmStringFree(tmpXmString);
  622. return (labelW);
  623. } /* END OF FUNCTION */
  624. /*************************************<->*************************************
  625. *
  626. * wspCreateSeparator (mgrW)
  627. *
  628. *
  629. * Description:
  630. * -----------
  631. * Creates a separator widget as a child of the passed in manager
  632. *
  633. * Inputs:
  634. * ------
  635. * mgrW = manager widget (parent of this label)
  636. *
  637. * Outputs:
  638. * -------
  639. * Return = Widget created.
  640. *
  641. * Comments:
  642. * ---------
  643. ******************************<->***********************************/
  644. static Widget
  645. wspCreateSeparator(
  646. Widget mgrW )
  647. {
  648. Arg setArgs[10];
  649. int i;
  650. Widget sepW;
  651. i = 0;
  652. sepW = XmCreateSeparatorGadget (mgrW, "separator", setArgs, i);
  653. XtManageChild (sepW);
  654. return (sepW);
  655. } /* END OF FUNCTION */
  656. /*************************************<->*************************************
  657. *
  658. * wspCreateWorkspaceList (mgrW, pPres, pSD)
  659. *
  660. *
  661. * Description:
  662. * -----------
  663. * Creates a list widget containing all the workspaces defined for a
  664. * screen.
  665. *
  666. * Inputs:
  667. * ------
  668. * mgrW = manager widget (parent of this child)
  669. * pPres = pointer to presence data
  670. * pSD = ptr to screen data
  671. *
  672. * Outputs:
  673. * -------
  674. * Return = widget created.
  675. *
  676. * Comments:
  677. * ---------
  678. ******************************<->***********************************/
  679. static Widget
  680. wspCreateWorkspaceList(
  681. Widget mgrW,
  682. PtrWsPresenceData pPres,
  683. WmScreenData *pSD )
  684. {
  685. Arg setArgs[20];
  686. int i;
  687. Widget listW;
  688. int numVisible;
  689. #define MIN_VISIBLE 6
  690. /*
  691. * Create the array of strings that will go into the list.
  692. */
  693. if (((pPres->ItemStrings = (XmStringTable) XtMalloc
  694. (pSD->numWorkspaces * sizeof(XmString *))) == NULL) ||
  695. ((pPres->ItemSelected = (Boolean *) XtMalloc
  696. (pSD->numWorkspaces * sizeof(Boolean))) == NULL))
  697. {
  698. Warning (((char *)GETMESSAGE(52, 5, "Insufficient memory to create Occupy Workspace dialog.")));
  699. return (NULL);
  700. }
  701. pPres->numWorkspaces = pSD->numWorkspaces;
  702. for (i = 0; i < pSD->numWorkspaces; i++)
  703. {
  704. pPres->ItemStrings[i] = XmStringCopy (pSD->pWS[i].title);
  705. if (pSD->pWS[i].id == pSD->pActiveWS->id)
  706. {
  707. pPres->currentWsItem = 1+i;
  708. }
  709. }
  710. /*
  711. * Create the widget
  712. */
  713. i = 0;
  714. XtSetArg (setArgs[i], XmNitemCount, pSD->numWorkspaces); i++;
  715. XtSetArg (setArgs[i], XmNitems, pPres->ItemStrings); i++;
  716. XtSetArg (setArgs[i], XmNselectionPolicy, XmEXTENDED_SELECT); i++;
  717. XtSetArg (setArgs[i], XmNlistSizePolicy, XmRESIZE_IF_POSSIBLE); i++;
  718. listW = XmCreateScrolledList (mgrW, "list", setArgs, i);
  719. XtManageChild (listW);
  720. if (pPres->pCDforClient)
  721. {
  722. /*
  723. * Highlight the workspaces this client resides in
  724. */
  725. for (i = 0; i < pPres->pCDforClient->pSD->numWorkspaces; i++)
  726. {
  727. if (ClientInWorkspace (&pPres->pCDforClient->pSD->pWS[i],
  728. pPres->pCDforClient))
  729. {
  730. XmListSelectPos (listW, i+1, TRUE);
  731. pPres->ItemSelected[i] = True;
  732. }
  733. else
  734. {
  735. pPres->ItemSelected[i] = False;
  736. }
  737. }
  738. }
  739. /*
  740. * Insure a minimum number are visible.
  741. */
  742. i = 0;
  743. XtSetArg (setArgs[i], XmNvisibleItemCount, &numVisible); i++;
  744. XtGetValues (listW, setArgs, i);
  745. if (numVisible < MIN_VISIBLE)
  746. {
  747. i = 0;
  748. XtSetArg (setArgs[i], XmNvisibleItemCount, MIN_VISIBLE);i++;
  749. XtSetValues (listW, setArgs, i);
  750. }
  751. XtAddCallback (listW, XmNextendedSelectionCallback,
  752. (XtCallbackProc) wspExtendedSelectCB, (XtPointer)pSD);
  753. /* Handle the double-click just like if the Ok button was pressed */
  754. XtAddCallback (listW, XmNdefaultActionCallback,
  755. (XtCallbackProc) wspOkCB, (XtPointer)pSD);
  756. return (listW);
  757. } /* END OF FUNCTION */
  758. /*************************************<->*************************************
  759. *
  760. * wspUpdateWorkspaceList (pPres)
  761. *
  762. *
  763. * Description:
  764. * -----------
  765. * Updates the list widget containing all the workspaces.
  766. * Sets the ones for this client.
  767. *
  768. * Inputs:
  769. * ------
  770. * pPres = ptr to presence dialog data
  771. *
  772. * Outputs:
  773. * -------
  774. * none
  775. *
  776. * Comments:
  777. * ---------
  778. ******************************<->***********************************/
  779. static void
  780. wspUpdateWorkspaceList(
  781. PtrWsPresenceData pPres )
  782. {
  783. int n;
  784. XmString xmsTmp, *pxmsSelected;
  785. WmScreenData *pSD;
  786. Arg args[5];
  787. int wsnum, numSelected;
  788. /*
  789. * Update the list of workspaces to -- one may have been
  790. * renamed since the last time we were up.
  791. */
  792. pSD = pPres->pCDforClient->pSD;
  793. for (wsnum = 0; wsnum < pSD->numWorkspaces; wsnum++)
  794. {
  795. xmsTmp = XmStringCopy (pSD->pWS[wsnum].title);
  796. if (!XmStringCompare (xmsTmp, pPres->ItemStrings[wsnum]))
  797. {
  798. /*
  799. * Replace the string in our local list
  800. */
  801. XmStringFree (pPres->ItemStrings[wsnum]);
  802. pPres->ItemStrings[wsnum] = xmsTmp;
  803. /*
  804. * Replace the item in the scrolled list.
  805. */
  806. XmListDeletePos (pPres->workspaceListW, 1+wsnum);
  807. XmListAddItem (pPres->workspaceListW, xmsTmp, 1+wsnum);
  808. }
  809. else
  810. {
  811. XmStringFree (xmsTmp);
  812. }
  813. }
  814. /*
  815. * Highlight the workspaces this client resides in
  816. */
  817. XmListDeselectAllItems (pPres->workspaceListW);
  818. pxmsSelected = (XmString *)
  819. XtMalloc (pPres->pCDforClient->pSD->numWorkspaces * sizeof (XmString));
  820. numSelected = 0;
  821. for (wsnum = 0; wsnum < pPres->pCDforClient->pSD->numWorkspaces; wsnum++)
  822. {
  823. if (ClientInWorkspace (&pPres->pCDforClient->pSD->pWS[wsnum],
  824. pPres->pCDforClient))
  825. {
  826. pxmsSelected[numSelected++] = pPres->ItemStrings[wsnum];
  827. pPres->ItemSelected[wsnum] = True;
  828. }
  829. else
  830. {
  831. pPres->ItemSelected[wsnum] = False;
  832. pPres->pCDforClient->putInAll = False;
  833. }
  834. if (pPres->pCDforClient->pSD->pActiveWS->id ==
  835. pPres->pCDforClient->pSD->pWS[wsnum].id)
  836. {
  837. /* save item number of current workspace */
  838. pPres->currentWsItem = 1+wsnum;
  839. }
  840. }
  841. /* set the selected items */
  842. n = 0;
  843. XtSetArg (args[n], XmNselectedItems, pxmsSelected); n++;
  844. XtSetArg (args[n], XmNselectedItemCount, numSelected); n++;
  845. XtSetValues (pPres->workspaceListW, args, n);
  846. /* set state of all workspaces button */
  847. n = 0;
  848. XtSetArg (args[n], XmNset, pPres->pCDforClient->putInAll); n++;
  849. XtSetValues (pPres->allWsW, args, n);
  850. /* set name of window we're popped up for */
  851. wspSetWindowName (pPres);
  852. XtFree ((char *) pxmsSelected);
  853. } /* END OF FUNCTION */
  854. /*************************************<->*************************************
  855. *
  856. * wspCreateToggleButton (mgrW, pch)
  857. *
  858. *
  859. * Description:
  860. * -----------
  861. * Creates a toggle button as a child of mgrW with the string pch.
  862. *
  863. * Inputs:
  864. * ------
  865. * mgrW = parent widget
  866. * pch = string to use for toggle button
  867. *
  868. * Outputs:
  869. * -------
  870. * Return = widget created
  871. *
  872. * Comments:
  873. * ---------
  874. ******************************<->***********************************/
  875. static Widget
  876. wspCreateToggleButton(
  877. Widget mgrW,
  878. unsigned char *pch )
  879. {
  880. Arg setArgs[20];
  881. int i;
  882. Widget toggleW;
  883. XmString labelString;
  884. i = 0;
  885. labelString = XmStringCreateLocalized ((char *)pch);
  886. XtSetArg (setArgs[i], XmNlabelString, labelString); i++;
  887. toggleW = XmCreateToggleButton (mgrW, (char *)pch, setArgs, i);
  888. XmStringFree(labelString);
  889. XtManageChild (toggleW);
  890. return (toggleW);
  891. } /* END OF FUNCTION wspCreateToggleButton */
  892. /*************************************<->*************************************
  893. *
  894. * wspCreatePushButton (mgrW, label)
  895. *
  896. *
  897. * Description:
  898. * -----------
  899. * Creates a push button as a child of mgrW with the string pch.
  900. *
  901. * Inputs:
  902. * ------
  903. * mgrW = parent widget
  904. * label = XmString to use for button label
  905. *
  906. * Outputs:
  907. * -------
  908. * Return = widget created
  909. *
  910. * Comments:
  911. * ---------
  912. ******************************<->***********************************/
  913. static Widget
  914. wspCreatePushButton(
  915. Widget mgrW,
  916. char *name,
  917. XmString label )
  918. {
  919. Arg setArgs[20];
  920. int i;
  921. Widget pushW;
  922. i = 0;
  923. XtSetArg (setArgs[i], XmNlabelString, label); i++;
  924. pushW = (Widget) XmCreatePushButton (mgrW, name, setArgs, i);
  925. XtManageChild (pushW);
  926. return (pushW);
  927. } /* END OF FUNCTION wspCreatePushButton */
  928. /*************************************<->*************************************
  929. *
  930. * wspSetPosition (pPres)
  931. *
  932. *
  933. * Description:
  934. * -----------
  935. * Sets the position of the workspace presence dialog
  936. *
  937. * Inputs:
  938. * ------
  939. * pPres = pointer to workspace presence data
  940. *
  941. * Outputs:
  942. * --------
  943. *
  944. ******************************<->***********************************/
  945. static void
  946. wspSetPosition(
  947. PtrWsPresenceData pPres )
  948. {
  949. WmScreenData *pSD = pPres->pCDforClient->pSD;
  950. Arg args[10];
  951. int n;
  952. XFontStruct *font;
  953. Dimension height;
  954. int x, y;
  955. /*
  956. * Get size of this dialog
  957. */
  958. n = 0;
  959. XtSetArg (args[n], XmNheight, &height); n++;
  960. XtGetValues (pPres->shellW, args, n);
  961. if (wmGD.positionIsFrame)
  962. {
  963. if (pSD->decoupleTitleAppearance)
  964. {
  965. font = pSD->clientTitleAppearance.font;
  966. }
  967. else
  968. {
  969. font = pSD->clientAppearance.font;
  970. }
  971. height += TEXT_HEIGHT(font) + (2 * pSD->frameBorderWidth);
  972. }
  973. /*
  974. * set position of dialog relative to client window
  975. * (use system menu position)
  976. * set this dialog to be transient for the client
  977. * for which it is posted.
  978. */
  979. GetSystemMenuPosition (pPres->pCDforClient,
  980. &x, &y, height,
  981. pPres->contextForClient);
  982. n = 0;
  983. XtSetArg (args[n], XmNx, x); n++;
  984. XtSetArg (args[n], XmNy, y); n++;
  985. XtSetArg (args[n], XmNtransientFor, NULL); n++;
  986. if (pPres->contextForClient != F_CONTEXT_ICON)
  987. {
  988. XtSetArg (args[n], XmNwindowGroup, pPres->pCDforClient->client); n++;
  989. }
  990. else if (pSD->useIconBox && P_ICON_BOX(pPres->pCDforClient))
  991. {
  992. XtSetArg (args[n], XmNwindowGroup,
  993. P_ICON_BOX(pPres->pCDforClient)->pCD_iconBox->client); n++;
  994. }
  995. else
  996. {
  997. XtSetArg (args[n], XmNwindowGroup, 0); n++;
  998. }
  999. XtSetArg (args[n], XmNwaitForWm, False); n++;
  1000. XtSetValues (pPres->shellW, args, n);
  1001. } /* END OF FUNCTION wspSetPosition */
  1002. /*************************************<->*************************************
  1003. *
  1004. * wspCharWidth (xmfl)
  1005. *
  1006. *
  1007. * Description:
  1008. * -----------
  1009. * Returns the max logical character width for this fontList
  1010. *
  1011. *
  1012. * Inputs:
  1013. * ------
  1014. * xmfl - XmFontList
  1015. *
  1016. * Returns:
  1017. * -------
  1018. * max logical character width
  1019. *
  1020. * Comments:
  1021. * ---------
  1022. ******************************<->***********************************/
  1023. static Dimension
  1024. wspCharWidth(
  1025. XmFontList xmfl )
  1026. {
  1027. XmFontContext fc;
  1028. XmFontListEntry entry;
  1029. Dimension dWidth, dTmpWidth;
  1030. XtPointer pFont;
  1031. XmFontType type;
  1032. XFontSetExtents *pExtents;
  1033. XmFontListInitFontContext ( &fc, xmfl);
  1034. dWidth = 0;
  1035. entry = XmFontListNextEntry (fc);
  1036. while (entry)
  1037. {
  1038. pFont = XmFontListEntryGetFont (entry, &type);
  1039. switch (type)
  1040. {
  1041. case XmFONT_IS_FONT:
  1042. dTmpWidth = ((XFontStruct *)pFont)->max_bounds.rbearing -
  1043. ((XFontStruct *)pFont)->min_bounds.lbearing;
  1044. break;
  1045. case XmFONT_IS_FONTSET:
  1046. pExtents = XExtentsOfFontSet ((XFontSet) pFont);
  1047. dTmpWidth = pExtents->max_logical_extent.width;
  1048. break;
  1049. default:
  1050. dTmpWidth = 0;
  1051. break;
  1052. }
  1053. if (dTmpWidth > dWidth)
  1054. dWidth = dTmpWidth;
  1055. entry = XmFontListNextEntry (fc);
  1056. }
  1057. XmFontListFreeFontContext (fc);
  1058. return (dWidth);
  1059. }
  1060. /*************************************<->*************************************
  1061. *
  1062. * wspLayout (pPres)
  1063. *
  1064. *
  1065. * Description:
  1066. * -----------
  1067. * Lays out the workspace presence dialog
  1068. *
  1069. *
  1070. * Inputs:
  1071. * ------
  1072. * pPres = pointer to workspace presence data
  1073. *
  1074. * Outputs:
  1075. * -------
  1076. * none
  1077. *
  1078. * Comments:
  1079. * ---------
  1080. ******************************<->***********************************/
  1081. static void
  1082. wspLayout(
  1083. PtrWsPresenceData pPres )
  1084. {
  1085. Arg args[20];
  1086. int n;
  1087. #define SEP_OFFSET 10
  1088. #define IW_OFFSET_1 8
  1089. #define IW_OFFSET_0 4
  1090. n = 0;
  1091. XtSetArg (args[n], XmNtopAttachment, XmATTACH_POSITION); n++;
  1092. XtSetArg (args[n], XmNtopPosition, 5); n++;
  1093. XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); n++;
  1094. XtSetArg (args[n], XmNleftOffset, 5); n++;
  1095. XtSetArg (args[n], XmNrightAttachment, XmATTACH_NONE); n++;
  1096. XtSetArg (args[n], XmNbottomAttachment, XmATTACH_NONE); n++;
  1097. XtSetValues (pPres->windowLabelW, args, n);
  1098. n = 0;
  1099. XtSetArg (args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
  1100. XtSetArg (args[n], XmNtopWidget, pPres->windowLabelW); n++;
  1101. XtSetArg (args[n], XmNtopOffset, IW_OFFSET_0); n++;
  1102. XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); n++;
  1103. XtSetArg (args[n], XmNleftOffset, 5); n++;
  1104. XtSetArg (args[n], XmNrightAttachment, XmATTACH_NONE); n++;
  1105. XtSetArg (args[n], XmNbottomAttachment, XmATTACH_NONE); n++;
  1106. XtSetArg (args[n], XmNbottomOffset, 0); n++;
  1107. XtSetValues (pPres->workspaceLabelW, args, n);
  1108. n = 0;
  1109. XtSetArg (args[n], XmNtopAttachment, XmATTACH_POSITION); n++;
  1110. XtSetArg (args[n], XmNtopPosition, 5); n++;
  1111. XtSetArg (args[n], XmNleftAttachment, XmATTACH_WIDGET); n++;
  1112. XtSetArg (args[n], XmNleftWidget, pPres->workspaceLabelW); n++;
  1113. XtSetArg (args[n], XmNleftOffset, 5); n++;
  1114. XtSetArg (args[n], XmNrightAttachment, XmATTACH_FORM); n++;
  1115. XtSetArg (args[n], XmNrightOffset, 5); n++;
  1116. XtSetArg (args[n], XmNbottomAttachment, XmATTACH_NONE); n++;
  1117. XtSetArg (args[n], XmNbottomOffset, 0); n++;
  1118. XtSetArg (args[n], XmNalignment, XmALIGNMENT_BEGINNING); n++;
  1119. XtSetValues (pPres->windowNameW, args, n);
  1120. n = 0;
  1121. XtSetArg (args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
  1122. XtSetArg (args[n], XmNtopWidget, pPres->windowNameW); n++;
  1123. XtSetArg (args[n], XmNtopOffset, IW_OFFSET_0); n++;
  1124. XtSetArg (args[n], XmNleftAttachment, XmATTACH_WIDGET); n++;
  1125. XtSetArg (args[n], XmNleftWidget, pPres->workspaceLabelW); n++;
  1126. XtSetArg (args[n], XmNleftOffset, 5); n++;
  1127. XtSetArg (args[n], XmNrightAttachment, XmATTACH_FORM); n++;
  1128. XtSetArg (args[n], XmNrightOffset, 5); n++;
  1129. XtSetArg (args[n], XmNbottomAttachment, XmATTACH_NONE); n++;
  1130. XtSetArg (args[n], XmNbottomOffset, 0); n++;
  1131. XtSetValues (pPres->workspaceScrolledListW, args, n);
  1132. n = 0;
  1133. XtSetArg (args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
  1134. XtSetArg (args[n], XmNtopWidget, pPres->workspaceScrolledListW); n++;
  1135. XtSetArg (args[n], XmNtopOffset, IW_OFFSET_1); n++;
  1136. XtSetArg (args[n], XmNleftAttachment, XmATTACH_WIDGET); n++;
  1137. XtSetArg (args[n], XmNleftWidget, pPres->workspaceLabelW); n++;
  1138. XtSetArg (args[n], XmNleftOffset, 5); n++;
  1139. XtSetArg (args[n], XmNrightAttachment, XmATTACH_FORM); n++;
  1140. XtSetArg (args[n], XmNrightOffset, 5); n++;
  1141. XtSetArg (args[n], XmNalignment, XmALIGNMENT_BEGINNING); n++;
  1142. XtSetArg (args[n], XmNmarginRight, 5); n++;
  1143. XtSetArg (args[n], XmNbottomAttachment, XmATTACH_NONE); n++;
  1144. XtSetArg (args[n], XmNbottomOffset, 0); n++;
  1145. XtSetValues (pPres->allWsW, args, n);
  1146. n = 0;
  1147. XtSetArg (args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
  1148. XtSetArg (args[n], XmNtopWidget, pPres->allWsW); n++;
  1149. XtSetArg (args[n], XmNtopOffset, SEP_OFFSET); n++;
  1150. XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); n++;
  1151. XtSetArg (args[n], XmNleftOffset, 0); n++;
  1152. XtSetArg (args[n], XmNrightAttachment, XmATTACH_FORM); n++;
  1153. XtSetArg (args[n], XmNrightOffset, 0); n++;
  1154. XtSetArg (args[n], XmNbottomAttachment, XmATTACH_NONE); n++;
  1155. XtSetArg (args[n], XmNbottomOffset, 0); n++;
  1156. XtSetValues (pPres->sepW, args, n);
  1157. n = 0;
  1158. XtSetArg (args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
  1159. XtSetArg (args[n], XmNtopWidget, pPres->sepW); n++;
  1160. XtSetArg (args[n], XmNtopOffset, SEP_OFFSET); n++;
  1161. XtSetArg (args[n], XmNleftAttachment, XmATTACH_POSITION); n++;
  1162. XtSetArg (args[n], XmNleftPosition, 5); n++;
  1163. XtSetArg (args[n], XmNrightAttachment, XmATTACH_POSITION); n++;
  1164. XtSetArg (args[n], XmNrightPosition, 30); n++;
  1165. XtSetArg (args[n], XmNbottomAttachment, XmATTACH_POSITION); n++;
  1166. XtSetArg (args[n], XmNbottomPosition, 95); n++;
  1167. XtSetValues (pPres->OkW, args, n);
  1168. n = 0;
  1169. XtSetArg (args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
  1170. XtSetArg (args[n], XmNtopWidget, pPres->sepW); n++;
  1171. XtSetArg (args[n], XmNtopOffset, SEP_OFFSET); n++;
  1172. XtSetArg (args[n], XmNleftAttachment, XmATTACH_POSITION); n++;
  1173. XtSetArg (args[n], XmNleftPosition, 36); n++;
  1174. XtSetArg (args[n], XmNrightAttachment, XmATTACH_POSITION); n++;
  1175. XtSetArg (args[n], XmNrightPosition, 66); n++;
  1176. XtSetArg (args[n], XmNbottomAttachment, XmATTACH_POSITION); n++;
  1177. XtSetArg (args[n], XmNbottomPosition, 95); n++;
  1178. XtSetValues (pPres->CancelW, args, n);
  1179. n = 0;
  1180. XtSetArg (args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
  1181. XtSetArg (args[n], XmNtopWidget, pPres->sepW); n++;
  1182. XtSetArg (args[n], XmNtopOffset, SEP_OFFSET); n++;
  1183. XtSetArg (args[n], XmNleftAttachment, XmATTACH_POSITION); n++;
  1184. XtSetArg (args[n], XmNleftPosition, 71); n++;
  1185. XtSetArg (args[n], XmNrightAttachment, XmATTACH_POSITION); n++;
  1186. XtSetArg (args[n], XmNrightPosition, 95); n++;
  1187. XtSetArg (args[n], XmNbottomAttachment, XmATTACH_POSITION); n++;
  1188. XtSetArg (args[n], XmNbottomPosition, 95); n++;
  1189. XtSetValues (pPres->HelpW, args, n);
  1190. } /* END OF FUNCTION */
  1191. /*************************************<->*************************************
  1192. *
  1193. * static void
  1194. * wspOkCB (w, client_data, call_data)
  1195. *
  1196. *
  1197. * Description:
  1198. * -----------
  1199. * OK callback.
  1200. *
  1201. *
  1202. * Inputs:
  1203. * ------
  1204. * pSD = pointer to screen data
  1205. *
  1206. *
  1207. * Outputs:
  1208. * -------
  1209. * None.
  1210. *
  1211. *
  1212. * Comments:
  1213. * --------
  1214. * None.
  1215. *
  1216. *************************************<->***********************************/
  1217. static void
  1218. wspOkCB(
  1219. Widget buttonW,
  1220. WmScreenData *pSD,
  1221. XtPointer call_data )
  1222. {
  1223. Arg args[20];
  1224. int n, j;
  1225. int selectedItemCount;
  1226. XmStringTable selectedItems;
  1227. PtrWsPresenceData pPres = &pSD->presence;
  1228. Boolean bAllSelected;
  1229. /* find the selected workspaces */
  1230. n = 0;
  1231. XtSetArg (args[n], XmNselectedItemCount, &selectedItemCount); n++;
  1232. XtSetArg (args[n], XmNselectedItems, &selectedItems); n++;
  1233. XtGetValues (pPres->workspaceListW, args, n);
  1234. /* find the state of all workspaces button */
  1235. n = 0;
  1236. XtSetArg (args[n], XmNset, &bAllSelected); n++;
  1237. XtGetValues (pPres->allWsW, args, n);
  1238. if (bAllSelected)
  1239. {
  1240. F_AddToAllWorkspaces(NULL, pPres->pCDforClient, NULL);
  1241. }
  1242. else if (selectedItemCount)
  1243. {
  1244. for (n = 0; n < pSD->numWorkspaces; n++)
  1245. {
  1246. pPres->ItemSelected[n] = False;
  1247. for (j = 0; j < selectedItemCount; j++)
  1248. {
  1249. if (XmStringCompare (selectedItems[j],
  1250. pPres->ItemStrings[n]))
  1251. {
  1252. pPres->ItemSelected[n] = True;
  1253. }
  1254. }
  1255. if (!pPres->ItemSelected[n] &&
  1256. ClientInWorkspace (&pSD->pWS[n], pPres->pCDforClient))
  1257. {
  1258. RemoveClientFromWorkspaces (pPres->pCDforClient,
  1259. &pSD->pWS[n].id, 1);
  1260. }
  1261. if (pPres->ItemSelected[n] &&
  1262. !ClientInWorkspace (&pSD->pWS[n], pPres->pCDforClient))
  1263. {
  1264. AddClientToWorkspaces (pPres->pCDforClient,
  1265. &pSD->pWS[n].id, 1);
  1266. }
  1267. }
  1268. }
  1269. /* withdraw the dialog */
  1270. wspCancelCB (buttonW, (XtPointer)pSD, call_data);
  1271. } /* END OF FUNCTION */
  1272. /*************************************<->*************************************
  1273. *
  1274. * static void
  1275. * wspAllWsCB (w, client_data, call_data)
  1276. *
  1277. *
  1278. * Description:
  1279. * -----------
  1280. * All Workspace toggle button callback.
  1281. *
  1282. *
  1283. * Inputs:
  1284. * ------
  1285. * None.
  1286. *
  1287. *
  1288. * Outputs:
  1289. * -------
  1290. * None.
  1291. *
  1292. *
  1293. * Comments:
  1294. * --------
  1295. * None.
  1296. *
  1297. *************************************<->***********************************/
  1298. static void
  1299. wspAllWsCB(
  1300. Widget buttonW,
  1301. WmScreenData *pSD,
  1302. XmToggleButtonCallbackStruct *xmTbcs )
  1303. {
  1304. PtrWsPresenceData pPres = &pSD->presence;
  1305. int wsnum;
  1306. XmString *pxmsSelected;
  1307. Arg args[5];
  1308. int n;
  1309. if (xmTbcs->reason == XmCR_VALUE_CHANGED)
  1310. {
  1311. if (xmTbcs->set)
  1312. {
  1313. pxmsSelected = (XmString *)
  1314. XtMalloc (pSD->numWorkspaces * sizeof (XmString));
  1315. for (wsnum = 0; wsnum < pSD->numWorkspaces; wsnum++)
  1316. {
  1317. pxmsSelected[wsnum] = pPres->ItemStrings[wsnum];
  1318. }
  1319. /* set the selected items */
  1320. n = 0;
  1321. XtSetArg (args[n], XmNselectedItems, pxmsSelected); n++;
  1322. XtSetArg (args[n], XmNselectedItemCount, pSD->numWorkspaces); n++;
  1323. XtSetValues (pPres->workspaceListW, args, n);
  1324. XtFree ((char *) pxmsSelected);
  1325. }
  1326. else
  1327. {
  1328. /* select current workspace */
  1329. XmListDeselectAllItems (pPres->workspaceListW);
  1330. XmListSelectPos (pPres->workspaceListW, pPres->currentWsItem, TRUE);
  1331. }
  1332. }
  1333. } /* END OF FUNCTION */
  1334. /*************************************<->*************************************
  1335. *
  1336. * static void
  1337. * wspExtendedSelectCB (w, client_data, cb)
  1338. *
  1339. *
  1340. * Description:
  1341. * -----------
  1342. * Cancel callback.
  1343. *
  1344. *
  1345. * Inputs:
  1346. * ------
  1347. * None.
  1348. *
  1349. *
  1350. * Outputs:
  1351. * -------
  1352. * None.
  1353. *
  1354. *
  1355. * Comments:
  1356. * --------
  1357. * None.
  1358. *
  1359. *************************************<->***********************************/
  1360. static void
  1361. wspExtendedSelectCB(
  1362. Widget w,
  1363. XtPointer client_data,
  1364. XmListCallbackStruct *cb )
  1365. {
  1366. WmScreenData *pSD = (WmScreenData *) client_data;
  1367. PtrWsPresenceData pPres = &pSD->presence;
  1368. int n;
  1369. Arg args[5];
  1370. if (cb->reason == XmCR_EXTENDED_SELECT)
  1371. {
  1372. if ((cb->selected_item_count < pSD->numWorkspaces) &&
  1373. (cb->event != None))
  1374. {
  1375. n = 0;
  1376. XtSetArg (args[n], XmNset, False); n++;
  1377. XtSetValues (pPres->allWsW, args, n);
  1378. }
  1379. }
  1380. } /* END OF FUNCTION wspExtendedSelectCB */
  1381. /*************************************<->*************************************
  1382. *
  1383. * static void
  1384. * wspCancelCB (w, client_data, call_data)
  1385. *
  1386. *
  1387. * Description:
  1388. * -----------
  1389. * Cancel callback.
  1390. *
  1391. *
  1392. * Inputs:
  1393. * ------
  1394. * None.
  1395. *
  1396. *
  1397. * Outputs:
  1398. * -------
  1399. * None.
  1400. *
  1401. *
  1402. * Comments:
  1403. * --------
  1404. * None.
  1405. *
  1406. *************************************<->***********************************/
  1407. static void
  1408. wspCancelCB(
  1409. Widget buttonW,
  1410. XtPointer client_data,
  1411. XtPointer call_data )
  1412. {
  1413. WmScreenData *pSD = (WmScreenData *) client_data;
  1414. XtPopdown (pSD->presence.shellW);
  1415. pSD->presence.onScreen = False;
  1416. } /* END OF FUNCTION wspCancelCB */
  1417. /*************************************<->*************************************
  1418. *
  1419. * GetPresenceBoxMenuItems (pSD)
  1420. *
  1421. *
  1422. * Description:
  1423. * -----------
  1424. * XXDescription ...
  1425. *
  1426. *************************************<->***********************************/
  1427. MenuItem *
  1428. GetPresenceBoxMenuItems(
  1429. WmScreenData *pSD )
  1430. {
  1431. return(NULL);
  1432. } /* END OF FUNCTION GetPresenceBoxMenuItems */
  1433. /*************************************<->*************************************
  1434. *
  1435. * UpdatePresenceWorkspaces (pSD)
  1436. *
  1437. *
  1438. * Description:
  1439. * -----------
  1440. * Update the presence dialog when the number of workspaces changes.
  1441. *
  1442. *************************************<->***********************************/
  1443. void
  1444. UpdatePresenceWorkspaces(
  1445. WmScreenData *pSD )
  1446. {
  1447. PtrWsPresenceData pPres = &pSD->presence;
  1448. int wsnum;
  1449. XmString xmsTmp;
  1450. if (pPres->shellW)
  1451. {
  1452. if (pPres->numWorkspaces < pSD->numWorkspaces)
  1453. {
  1454. if (((pPres->ItemStrings = (XmStringTable) XtRealloc
  1455. ((char *)pPres->ItemStrings,
  1456. (pSD->numWorkspaces * sizeof(XmString *)))) == NULL) ||
  1457. ((pPres->ItemSelected = (Boolean *) XtRealloc
  1458. ((char *)pPres->ItemSelected,
  1459. (pSD->numWorkspaces * sizeof(Boolean)))) == NULL))
  1460. {
  1461. Warning (((char *)GETMESSAGE(52, 5, "Insufficient memory to create Occupy Workspace dialog.")));
  1462. pPres->shellW = NULL;
  1463. return;
  1464. }
  1465. }
  1466. /*
  1467. * Replace the names in the dialog's list
  1468. */
  1469. for (wsnum = 0; wsnum < pPres->numWorkspaces; wsnum++)
  1470. {
  1471. if (wsnum < pSD->numWorkspaces)
  1472. {
  1473. xmsTmp = XmStringCopy (pSD->pWS[wsnum].title);
  1474. if (!XmStringCompare (xmsTmp, pPres->ItemStrings[wsnum]))
  1475. {
  1476. /*
  1477. * Replace the string in our local list
  1478. */
  1479. XmStringFree (pPres->ItemStrings[wsnum]);
  1480. pPres->ItemStrings[wsnum] = xmsTmp;
  1481. /*
  1482. * Replace the item in the scrolled list.
  1483. */
  1484. XmListDeletePos (pPres->workspaceListW, 1+wsnum);
  1485. XmListAddItem (pPres->workspaceListW, xmsTmp, 1+wsnum);
  1486. }
  1487. else
  1488. {
  1489. XmStringFree (xmsTmp);
  1490. }
  1491. }
  1492. else
  1493. {
  1494. /*
  1495. * Delete this workspace from the list
  1496. */
  1497. XmStringFree (pPres->ItemStrings[wsnum]);
  1498. pPres->ItemStrings[wsnum] = NULL;
  1499. XmListDeletePos (pPres->workspaceListW, 1+wsnum);
  1500. }
  1501. }
  1502. for (; wsnum < pSD->numWorkspaces; wsnum++)
  1503. {
  1504. /*
  1505. * Add these workspaces to the list.
  1506. */
  1507. xmsTmp = XmStringCopy (pSD->pWS[wsnum].title);
  1508. pPres->ItemStrings[wsnum] = xmsTmp;
  1509. XmListAddItem (pPres->workspaceListW, xmsTmp, 1+wsnum);
  1510. if (pPres->pCDforClient &&
  1511. (ClientInWorkspace (&pPres->pCDforClient->pSD->pWS[wsnum],
  1512. pPres->pCDforClient)))
  1513. {
  1514. XmListSelectPos (pPres->workspaceListW, 1+wsnum, TRUE);
  1515. pPres->ItemSelected[wsnum] = True;
  1516. }
  1517. else
  1518. {
  1519. pPres->ItemSelected[wsnum] = False;
  1520. }
  1521. }
  1522. pPres->numWorkspaces = pSD->numWorkspaces;
  1523. }
  1524. } /* END OF FUNCTION UpdatePresenceWorkspaces */
  1525. /**************************** eof ***************************/