PopupMenu.c 54 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991
  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. *****************************************************************************
  25. **
  26. ** File: PopupMenu.c
  27. **
  28. ** Project: CDE
  29. **
  30. ** Description: This file contains the functions for creating and managing
  31. ** the main panel and subpanel popup menus.
  32. **
  33. **
  34. ****************************************************************************
  35. *****************************************************************************/
  36. #include <Xm/XmP.h>
  37. #include <Xm/ManagerP.h>
  38. #include <Xm/RowColumn.h>
  39. #include <Xm/LabelG.h>
  40. #include <Xm/PushBG.h>
  41. #include <Xm/SeparatoG.h>
  42. #include <Dt/SharedProcs.h>
  43. #include "DataBaseLoad.h"
  44. #include "WmGlobal.h"
  45. #include "UI.h"
  46. #define POPUP_CHILDREN 7
  47. extern void ToggleDefaultControl (ControlData *, SubpanelData *, ControlData *);
  48. extern void SwitchRenameLabel (Widget, BoxData *);
  49. extern Boolean CheckControlTypeFile (ControlData *);
  50. /************************************************************************
  51. *
  52. * ActionCB
  53. *
  54. ************************************************************************/
  55. void
  56. ActionCB (Widget w,
  57. XtPointer client_data,
  58. XtPointer call_data)
  59. {
  60. ControlData * control_data;
  61. long control_type;
  62. long indx = (long) client_data;
  63. Arg args[1];
  64. XtSetArg (args[0], XmNuserData, &control_data);
  65. XtGetValues(w, args, 1);
  66. if (CheckControlTypeFile (control_data) == False)
  67. return;
  68. control_type = (long) (control_data->element_values[CONTROL_TYPE].parsed_value);
  69. if (control_type == CONTROL_FILE && !control_data->is_action)
  70. {
  71. DtActionArg * aap;
  72. aap = (DtActionArg *) XtCalloc(1,sizeof(DtActionArg));
  73. aap->argClass = DtACTION_FILE;
  74. aap->u.file.name = (char *)
  75. control_data->element_values[CONTROL_FILE_NAME].parsed_value;
  76. DtActionInvoke (control_data->icon,
  77. control_data->actions[indx]->action_name,
  78. aap, 1, NULL, NULL, NULL, 1, NULL, NULL);
  79. XtFree ((char *) aap);
  80. }
  81. else
  82. {
  83. DtActionInvoke (control_data->icon,
  84. control_data->actions[indx]->action_name,
  85. control_data->actions[indx]->aap,
  86. control_data->actions[indx]->count,
  87. NULL, NULL, NULL, 1, NULL, NULL);
  88. }
  89. }
  90. /************************************************************************
  91. *
  92. * DeleteWorkspaceCB
  93. * The callback function is called off of a menu pick to delete
  94. * a specific workspace. The function identifies the index of the
  95. * workspace and calls the workspace manager API to perform the delete.
  96. * All frontpanel UI processing is performed through a notification
  97. * callback issued by the workspace manager after a successful delete.
  98. *
  99. ************************************************************************/
  100. void
  101. DeleteWorkspaceCB (Widget w,
  102. XtPointer client_data,
  103. XtPointer call_data)
  104. {
  105. long delete_workspace = (long) client_data;
  106. SwitchData * switch_data = NULL;
  107. int i;
  108. /* Look up the switch data to get the atom name of the workspace */
  109. /* to delete. */
  110. for (i = 0; i < panel.box_data_count; i++)
  111. {
  112. if (panel.box_data[i]->switch_data != NULL)
  113. {
  114. switch_data = panel.box_data[i]->switch_data;
  115. break;
  116. }
  117. }
  118. if(switch_data)
  119. {
  120. _DtWsmDeleteWorkspace (panel.shell,
  121. switch_data->atom_names[delete_workspace]);
  122. }
  123. }
  124. /************************************************************************
  125. *
  126. * RenameWorkspaceCB
  127. * The callback function is called off of a menu pick to rename
  128. * a specific workspace. The function identifies the index of the
  129. * workspace and calls SwitchRenameLabel() function to change the switch.
  130. * button to a text widget for typing the new workspace name and setting.
  131. * up the callback to accept the new name upon activation.
  132. *
  133. ************************************************************************/
  134. void
  135. RenameWorkspaceCB (Widget w,
  136. XtPointer client_data,
  137. XtPointer call_data)
  138. {
  139. long rename_ws = (long) client_data;
  140. SwitchData * switch_data = NULL;
  141. int i;
  142. /* Look up the switch data to get the atom name of the workspace */
  143. /* to delete. */
  144. for (i = 0; i < panel.box_data_count; i++)
  145. {
  146. if (panel.box_data[i]->switch_data != NULL)
  147. {
  148. switch_data = panel.box_data[i]->switch_data;
  149. break;
  150. }
  151. }
  152. if(switch_data) {
  153. SwitchRenameLabel (switch_data->buttons[rename_ws], panel.box_data[i]);
  154. }
  155. }
  156. /************************************************************************
  157. *
  158. * AddWorkspaceCB
  159. * The callback function is called off of a menu pick. It generates
  160. * a new workspace name and calls the workspace manager API to
  161. * create the new workspace. All frontpanel UI processing is
  162. * performed through a notification callback issued by the workspace
  163. * manager after a successful add.
  164. *
  165. ************************************************************************/
  166. void
  167. AddWorkspaceCB (Widget w,
  168. XtPointer client_data,
  169. XtPointer call_data)
  170. {
  171. SwitchData * switch_data = NULL;
  172. char * switch_name;
  173. char * temp_name;
  174. int append;
  175. int i;
  176. int slen;
  177. /* Get the beginning part of the new name */
  178. temp_name = FPGETMESSAGE (82, 35, "New");
  179. slen = strlen (temp_name) + 5 + 1;
  180. switch_name = XtCalloc(1, slen);
  181. strcpy (switch_name, temp_name);
  182. /* Look up the switch data to get the atom name of the workspace */
  183. /* to delete. */
  184. for (i = 0; i < panel.box_data_count; i++)
  185. {
  186. if (panel.box_data[i]->switch_data != NULL)
  187. {
  188. switch_data = panel.box_data[i]->switch_data;
  189. break;
  190. }
  191. }
  192. /* Generate a new title for the workspace. It should be unique */
  193. /* from the existing title. */
  194. append = 0;
  195. while (1)
  196. {
  197. Boolean good_name;
  198. good_name = True;
  199. append++;
  200. for (i = 0; i < switch_data->switch_count; i++)
  201. {
  202. if (strcmp (switch_name, switch_data->switch_names[i]) == 0)
  203. {
  204. good_name = False;
  205. snprintf (switch_name, slen - 1, "%s_%d", temp_name, append);
  206. continue;
  207. }
  208. }
  209. if (good_name)
  210. {
  211. _DtWsmCreateWorkspace (panel.shell, switch_name);
  212. break;
  213. }
  214. }
  215. XtFree(switch_name);
  216. }
  217. /************************************************************************
  218. *
  219. * DeleteCancelCB
  220. *
  221. ************************************************************************/
  222. static void
  223. DeleteCancelCB(
  224. Widget w,
  225. XtPointer client_data,
  226. XtPointer call_data )
  227. {
  228. XtUnmanageChild((Widget)client_data);
  229. XmUpdateDisplay((Widget)client_data);
  230. XtDestroyWidget((Widget)client_data);
  231. }
  232. /************************************************************************
  233. *
  234. * DeleteControlOkCB
  235. * Called from the Ok button on the confimation dialog when a
  236. * control deletion is seleted from the popup menu.
  237. *
  238. ************************************************************************/
  239. static void
  240. DeleteControlOkCB (Widget w,
  241. XtPointer client_data,
  242. XtPointer call_data)
  243. {
  244. ControlData * control_data;
  245. SubpanelData * subpanel_data;
  246. Arg args[1];
  247. /* Extract the control data from the user data field of the */
  248. /* widget pointed to by client data. */
  249. XtSetArg (args[0], XmNuserData, &control_data);
  250. XtGetValues((Widget) client_data, args, 1);
  251. /* Get the subpanel data for the control. Check to see if the */
  252. /* control is a real subpanel control or the main panel copy. */
  253. if (control_data->parent_type == SUBPANEL)
  254. subpanel_data = (SubpanelData *) control_data->parent_data;
  255. else
  256. subpanel_data = (SubpanelData *) control_data->subpanel_data;
  257. /* Get rid of the dialog and call the funtion to delete the control */
  258. XtUnmanageChild ((Widget) client_data);
  259. XmUpdateDisplay ((Widget) client_data);
  260. DeleteSubpanelControl (subpanel_data, control_data);
  261. XtDestroyWidget ((Widget) client_data);
  262. }
  263. /************************************************************************
  264. *
  265. * DeleteSubpanelOkCB
  266. *
  267. ************************************************************************/
  268. static void
  269. DeleteSubpanelOkCB(
  270. Widget w,
  271. XtPointer client_data,
  272. XtPointer call_data )
  273. {
  274. ControlData * control_data;
  275. Arg args[1];
  276. XtSetArg (args[0], XmNuserData, &control_data);
  277. XtGetValues((Widget)client_data, args, 1);
  278. XtUnmanageChild((Widget)client_data);
  279. XmUpdateDisplay((Widget)client_data);
  280. DeleteSubpanel(control_data);
  281. XtDestroyWidget((Widget)client_data);
  282. }
  283. /************************************************************************
  284. *
  285. * DeleteControlCB
  286. *
  287. ************************************************************************/
  288. void
  289. DeleteControlCB (Widget w,
  290. XtPointer client_data,
  291. XtPointer call_data)
  292. {
  293. ControlData * control_data;
  294. #ifndef IBM_163763
  295. SubpanelData *subpanel_data;
  296. #endif
  297. Widget dialog;
  298. String title, del_ctrl, ctrl_name, ctrl_label, del_msg, message;
  299. long indx = (long) client_data;
  300. Arg args[2];
  301. XtSetArg (args[0], XmNuserData, &control_data);
  302. XtGetValues (w, args, 1);
  303. del_ctrl = FPGETMESSAGE(82, 31, "Delete Control:");
  304. del_ctrl = XtNewString (del_ctrl);
  305. ctrl_label = (char *)
  306. control_data->element_values[CONTROL_LABEL].parsed_value;
  307. ctrl_name = (char *)
  308. control_data->element_values[CONTROL_NAME].parsed_value;
  309. if (ctrl_label == NULL)
  310. ctrl_label = ctrl_name;
  311. if (control_data->element_values[CONTROL_LOCKED].parsed_value)
  312. {
  313. title = FPGETMESSAGE(82,1, "Workspace Manager - Delete Locked Control Error");
  314. title = XtNewString (title);
  315. del_msg = FPGETMESSAGE(82,5, "This control cannot be deleted because it is locked.");
  316. del_msg = XtNewString (del_msg);
  317. message = XtMalloc (sizeof(char) *
  318. (strlen(del_ctrl) + strlen(ctrl_label) +
  319. strlen(del_msg) + 4));
  320. sprintf(message, "%s %s\n\n%s", del_ctrl, ctrl_label, del_msg);
  321. _DtMessage (XtParent(w), title, message, NULL, NULL);
  322. XtFree (title);
  323. XtFree (del_ctrl);
  324. XtFree (del_msg);
  325. XtFree (message);
  326. }
  327. else
  328. {
  329. title = FPGETMESSAGE(82,2, "Workspace Manager - Delete Control");
  330. title = XtNewString (title);
  331. if (SessionFileNameLookup (ctrl_name, CONTROL, (char *) control_data->element_values[CONTROL_CONTAINER_NAME].parsed_value, SUBPANEL) == NULL)
  332. del_msg = FPGETMESSAGE(82,32, "If you delete this control, you cannot restore it using\nthe \"Install Icon\" drop zone.\n\nYou can use \"RestorePanel\" in the Application Manager\nto put back this control at a later time.\n\nAre you sure you want to delete this control?");
  333. else
  334. del_msg = FPGETMESSAGE(82,6, "Are you sure you want to delete this control?");
  335. del_msg = XtNewString (del_msg);
  336. message = XtMalloc (sizeof(char) *
  337. (strlen(del_ctrl) + strlen(ctrl_label) +
  338. strlen(del_msg) + 4));
  339. sprintf(message, "%s %s\n\n%s", del_ctrl, ctrl_label, del_msg);
  340. #ifndef IBM_163763
  341. /* Get the subpanel data for the control. Check to see if the */
  342. /* control is a real subpanel control or the main panel copy. */
  343. if (control_data->parent_type == SUBPANEL)
  344. subpanel_data = (SubpanelData *) control_data->parent_data;
  345. else
  346. subpanel_data = (SubpanelData *) control_data->subpanel_data;
  347. dialog = _DtMessageDialog(subpanel_data->shell,title,message,NULL,TRUE,
  348. #else
  349. dialog = _DtMessageDialog(panel.shell, title, message, NULL, TRUE,
  350. #endif
  351. DeleteCancelCB, DeleteControlOkCB, NULL, NULL, False,
  352. QUESTION_DIALOG);
  353. XtSetArg (args[0], XmNuserData, control_data);
  354. XtSetArg (args[1], XmNdialogStyle, XmDIALOG_FULL_APPLICATION_MODAL);
  355. XtSetValues (dialog, args, 2);
  356. XtFree (title);
  357. XtFree (del_ctrl);
  358. XtFree (del_msg);
  359. XtFree (message);
  360. }
  361. }
  362. /************************************************************************
  363. *
  364. * ToggleControlCB
  365. * This callback initiates a subpanel control being toggled into
  366. * the main panel.
  367. *
  368. ************************************************************************/
  369. void
  370. ToggleControlCB (Widget w,
  371. XtPointer client_data,
  372. XtPointer call_data)
  373. {
  374. SubpanelData * subpanel_data = (SubpanelData *) client_data;
  375. ControlData * control_data;
  376. long indx = (long) client_data;
  377. Arg args[1];
  378. XtSetArg (args[0], XmNuserData, &control_data);
  379. XtGetValues(w, args, 1);
  380. ToggleDefaultControl (subpanel_data->parent_control_data,
  381. subpanel_data, control_data);
  382. }
  383. /************************************************************************
  384. *
  385. * AddSubpanelCB
  386. *
  387. ************************************************************************/
  388. void
  389. AddSubpanelCB (Widget w,
  390. XtPointer client_data,
  391. XtPointer call_data)
  392. {
  393. ControlData * control_data;
  394. long indx = (long) client_data;
  395. Arg args[1];
  396. XtSetArg (args[0], XmNuserData, &control_data);
  397. XtGetValues(w, args, 1);
  398. AddSubpanel(control_data);
  399. }
  400. /************************************************************************
  401. *
  402. * DeleteSubpanelCB
  403. *
  404. ************************************************************************/
  405. void
  406. DeleteSubpanelCB (Widget w,
  407. XtPointer client_data,
  408. XtPointer call_data)
  409. {
  410. ControlData * control_data;
  411. SubpanelData * subpanel_data;
  412. Widget dialog;
  413. String title, message, del_spanel, spanel_name, del_msg;
  414. Arg args[2];
  415. XtSetArg (args[0], XmNuserData, &control_data);
  416. XtGetValues(w, args, 1);
  417. subpanel_data = (SubpanelData *) control_data->subpanel_data;
  418. if (!subpanel_data)
  419. subpanel_data = (SubpanelData *) control_data->parent_data;
  420. del_spanel = FPGETMESSAGE(82, 33, "Delete Subpanel:");
  421. del_spanel = XtNewString (del_spanel);
  422. spanel_name = (char *)
  423. subpanel_data->element_values[SUBPANEL_NAME].parsed_value;
  424. if (subpanel_data->element_values[SUBPANEL_LOCKED].parsed_value)
  425. {
  426. title = FPGETMESSAGE(82,3, "Workspace Manager - Delete Locked Subpanel Error");
  427. title = XtNewString (title);
  428. del_msg = FPGETMESSAGE(82,7, "This subpanel cannot be deleted because it is locked.");
  429. del_msg = XtNewString (del_msg);
  430. message = XtMalloc (sizeof(char) *
  431. (strlen(del_spanel) + strlen(spanel_name) +
  432. strlen(del_msg) + 4));
  433. sprintf(message, "%s %s\n\n%s", del_spanel, spanel_name, del_msg);
  434. _DtMessage (XtParent(w), title, message, NULL, NULL);
  435. XtFree (title);
  436. XtFree (del_spanel);
  437. XtFree (del_msg);
  438. XtFree (message);
  439. }
  440. else
  441. {
  442. title = FPGETMESSAGE(82,4, "Workspace Manager - Delete Subpanel");
  443. title = XtNewString (title);
  444. if (subpanel_data->control_data_count > 0)
  445. {
  446. if (SessionFileNameLookup (spanel_name, SUBPANEL, (char *)
  447. subpanel_data->element_values[SUBPANEL_CONTAINER_NAME].parsed_value,
  448. CONTROL) == NULL)
  449. del_msg = FPGETMESSAGE(82,34,
  450. "If you delete this subpanel, you cannot restore all\nof the controls contained in the subpanel using the\n\"Install Icon\" drop zone.\n\nYou can use \"RestorePanel\" in the Application Manager\nto put back this subpanel and its controls at a later time.\n\nAre you sure you want to delete this subpanel?");
  451. else
  452. del_msg = FPGETMESSAGE(82,8, "This subpanel contains more than one control.\n\nAre you sure you want to delete this subpanel?");
  453. }
  454. else
  455. del_msg = FPGETMESSAGE(82,9, "Are you sure you want to delete this subpanel?");
  456. del_msg = XtNewString (del_msg);
  457. message = XtMalloc (sizeof(char) *
  458. (strlen(del_spanel) + strlen(spanel_name) +
  459. strlen(del_msg) + 4));
  460. sprintf(message, "%s %s\n\n%s", del_spanel, spanel_name, del_msg);
  461. #ifndef IBM_163763
  462. dialog = _DtMessageDialog(subpanel_data->shell,title,message,NULL,TRUE,
  463. #else
  464. dialog = _DtMessageDialog(panel.shell, title, message, NULL, TRUE,
  465. #endif
  466. DeleteCancelCB, DeleteSubpanelOkCB, NULL, NULL, False,
  467. QUESTION_DIALOG);
  468. XtSetArg (args[0], XmNuserData, control_data);
  469. XtSetArg (args[1], XmNdialogStyle, XmDIALOG_FULL_APPLICATION_MODAL);
  470. XtSetValues(dialog, args, 2);
  471. XtFree (title);
  472. XtFree (del_spanel);
  473. XtFree (del_msg);
  474. XtFree (message);
  475. }
  476. }
  477. /************************************************************************
  478. *
  479. * PostWorkspacePopupMenu
  480. *
  481. ************************************************************************/
  482. void
  483. PostWorkspacePopupMenu (Widget w,
  484. XtPointer client_data,
  485. XEvent * event)
  486. {
  487. int i;
  488. BoxData * box_data;
  489. SwitchData * switch_data = NULL;
  490. XButtonEvent * b_event = (XButtonEvent *) event;
  491. /* only use BMENU press events */
  492. if (b_event->button != wmGD.bMenuButton) return;
  493. for (i = 0; i < panel.box_data_count; i++)
  494. {
  495. box_data = panel.box_data[i];
  496. if (box_data->switch_data != NULL)
  497. switch_data = box_data->switch_data;
  498. }
  499. if (switch_data != NULL)
  500. XtManageChild(switch_data->popup_data->popup);
  501. }
  502. /************************************************************************
  503. *
  504. * PostPopupMenu
  505. *
  506. ************************************************************************/
  507. void
  508. PostPopupMenu (Widget w,
  509. XtPointer client_data,
  510. XEvent * event)
  511. {
  512. XButtonEvent * b_event = (XButtonEvent *) event;
  513. /* only use BMENU press events */
  514. if (b_event->button != wmGD.bMenuButton) return;
  515. XtManageChild(panel.popup_data->popup);
  516. }
  517. /************************************************************************
  518. *
  519. * GetBoxDataFromForm
  520. *
  521. ************************************************************************/
  522. static void
  523. GetBoxDataFromForm (Widget form,
  524. BoxData ** box_data_rtn)
  525. {
  526. BoxData * box_data;
  527. int i;
  528. for (i = 0; i < panel.box_data_count; i++)
  529. {
  530. box_data = panel.box_data[i];
  531. if (box_data == *box_data_rtn) continue;
  532. if (box_data->left_control_form == form ||
  533. box_data->right_control_form == form)
  534. {
  535. *box_data_rtn = box_data;
  536. break;
  537. }
  538. }
  539. }
  540. /************************************************************************
  541. *
  542. * GetSubpanelDataFromForm
  543. *
  544. ************************************************************************/
  545. static void
  546. GetSubpanelDataFromForm (Widget form,
  547. SubpanelData ** subpanel_data_rtn)
  548. {
  549. BoxData * box_data;
  550. ControlData * control_data;
  551. SubpanelData * subpanel_data;
  552. int i, j;
  553. for (i = 0; i < panel.box_data_count; i++)
  554. {
  555. box_data = panel.box_data[i];
  556. for (j = 0; j < box_data->control_data_count; j++)
  557. {
  558. control_data = box_data->control_data[j];
  559. if (control_data->subpanel_data != NULL)
  560. {
  561. subpanel_data = control_data->subpanel_data;
  562. if (subpanel_data == *subpanel_data_rtn) continue;
  563. if (subpanel_data->form == form)
  564. {
  565. *subpanel_data_rtn = subpanel_data;
  566. break;
  567. }
  568. }
  569. }
  570. }
  571. }
  572. /************************************************************************
  573. *
  574. * KeyMenuPosition
  575. *
  576. ************************************************************************/
  577. static void
  578. KeyMenuPosition (Widget popup, Widget focus_widget)
  579. {
  580. XButtonPressedEvent bevent; /* synthetic button press event */
  581. Widget parent;
  582. Position root_x, root_y;
  583. Position x, y;
  584. Arg args[2];
  585. /* get the gadget's x and y */
  586. XtSetArg (args[0], XmNx, &x);
  587. XtSetArg (args[1], XmNy, &y);
  588. XtGetValues (focus_widget, args, 2);
  589. /* get the focus widget's parent since the focus widget is a gadget */
  590. parent = XtParent (focus_widget);
  591. /* get the root coordinates of the gadget */
  592. XtTranslateCoords (parent, x, y, &root_x, &root_y);
  593. /* XmMenuPosition() only uses the root_x and root_y */
  594. /* of the event for positioning */
  595. bevent.x_root = root_x;
  596. bevent.y_root = root_y;
  597. /* set the menu positioning */
  598. XmMenuPosition (popup, &bevent);
  599. }
  600. /************************************************************************
  601. *
  602. * GetMainControlData
  603. *
  604. ************************************************************************/
  605. static ControlData *
  606. GetMainControlData (BoxData * box_data,
  607. Widget focus_widget)
  608. {
  609. int i;
  610. ControlData * control_data;
  611. Boolean found = False;
  612. for (i = 0; i < box_data->control_data_count; i++)
  613. {
  614. control_data = box_data->control_data[i];
  615. if (control_data->icon == focus_widget)
  616. {
  617. found = True;
  618. break;
  619. }
  620. }
  621. if (!found) return NULL;
  622. return (control_data);
  623. }
  624. /************************************************************************
  625. *
  626. * GetSubpanelControlData
  627. *
  628. ************************************************************************/
  629. static ControlData *
  630. GetSubpanelControlData (SubpanelData * subpanel_data,
  631. Widget focus_widget)
  632. {
  633. int i;
  634. ControlData * control_data;
  635. Boolean found = False;
  636. if ( subpanel_data->dropzone == focus_widget )
  637. return NULL;
  638. if (subpanel_data->main_panel_icon_copy == focus_widget ||
  639. subpanel_data->parent_control_data->indicator == focus_widget)
  640. {
  641. return (subpanel_data->parent_control_data);
  642. }
  643. for (i = 0; i < subpanel_data->control_data_count; i++)
  644. {
  645. control_data = subpanel_data->control_data[i];
  646. if (control_data->icon == focus_widget ||
  647. control_data->indicator == focus_widget)
  648. {
  649. found = True;
  650. break;
  651. }
  652. }
  653. if (!found) return NULL;
  654. return (control_data);
  655. }
  656. /************************************************************************
  657. *
  658. * SetupActionMenuItems
  659. * Set up the action list for display in the popup menu for a
  660. * control. This may require creating additional menu items is
  661. * the action list for this control is greater that previously
  662. * encountered or it may require umanaging menu item is there are
  663. * less actions.
  664. *
  665. * Inputs:
  666. * w: The parent of the menu items.
  667. * control_data: The control the menu is being set up for.
  668. * action_item: A pointer to the array of menu items for the actions.
  669. * action_count: A pointer to the total number of action items.
  670. *
  671. ************************************************************************/
  672. static void
  673. SetupActionMenuItems (Widget w,
  674. ControlData * control_data,
  675. PopupData * popup_data,
  676. Widget * action_item,
  677. long * action_count)
  678. {
  679. XmString label_string;
  680. long i;
  681. long num_actions = 0;
  682. long action_index = *action_count;
  683. Arg args[5];
  684. /* Count the action list for the control in order to adjust */
  685. /* the number of action menu items within the menu. */
  686. if (control_data != NULL)
  687. while (control_data->actions[num_actions] != NULL)
  688. num_actions++;
  689. if (num_actions > *action_count )
  690. {
  691. action_item = (Widget *) XtRealloc((char *) action_item,
  692. sizeof(Widget) * num_actions);
  693. for (i = 0; i < num_actions - *action_count; i++)
  694. {
  695. action_item[action_index] =
  696. XmCreatePushButtonGadget (w, "action_button", args, 0);
  697. (*action_count)++;
  698. XtManageChild (action_item[action_index]);
  699. XtAddCallback (action_item[action_index], XmNactivateCallback,
  700. ActionCB, (XtPointer)action_index);
  701. action_index++;
  702. }
  703. }
  704. else
  705. {
  706. for (i = 0; i < *action_count; i++)
  707. XtUnmanageChild (action_item[i]);
  708. }
  709. for (i = 0; i < num_actions ; i++)
  710. {
  711. XtSetArg (args[0], XmNuserData, control_data);
  712. XtSetValues (action_item[i], args, 1);
  713. }
  714. for (i = 0; i < num_actions; i++)
  715. {
  716. if (control_data->actions[i]->action_label != NULL)
  717. label_string =
  718. XmStringCreateLocalized (control_data->actions[i]->action_label);
  719. else
  720. label_string =
  721. XmStringCreateLocalized (control_data->actions[i]->action_name);
  722. XtSetArg (args[0], XmNlabelString, label_string);
  723. XtSetArg (args[1], XmNuserData, control_data);
  724. XtSetValues (action_item[i], args, 2);
  725. XmStringFree (label_string);
  726. }
  727. for (i = 0; i < num_actions; i++)
  728. {
  729. if (!XtIsManaged (action_item[i]))
  730. XtManageChild (action_item[i]);
  731. }
  732. if (num_actions > 0)
  733. XtManageChild(popup_data->separator1);
  734. else
  735. XtUnmanageChild(popup_data->separator1);
  736. }
  737. /************************************************************************
  738. *
  739. * UpdateMainControlMenu
  740. * Set up the label and the add/delete subpanel menu item for the
  741. * popup menu.
  742. *
  743. * Inputs:
  744. * control_data: The control overwhich the menu is being posted.
  745. *
  746. ************************************************************************/
  747. static void
  748. UpdateMainControlMenu (ControlData * control_data)
  749. {
  750. XmString label_string;
  751. char * mnemonic;
  752. char * control_label;
  753. long control_type;
  754. Arg args[5];
  755. ElementValue * old_element_values;
  756. /* Save element values of control then load values of default control */
  757. if (control_data->subpanel_data != NULL &&
  758. control_data != control_data->subpanel_data->default_control)
  759. {
  760. old_element_values = control_data->element_values;
  761. control_data->element_values =
  762. control_data->subpanel_data->default_control->element_values;
  763. }
  764. /* Set the title of the menu */
  765. control_label =
  766. (char *) control_data->element_values[CONTROL_LABEL].parsed_value;
  767. if (control_label == NULL)
  768. control_label =
  769. (char *) control_data->element_values[CONTROL_NAME].parsed_value;
  770. label_string = XmStringCreateLocalized (control_label);
  771. XtSetArg (args[0], XmNlabelString, label_string);
  772. XtSetValues (panel.popup_data->popup_title, args, 1);
  773. XmStringFree (label_string);
  774. /* If the control is blank, remove the add/delete subpanel item. */
  775. /* Otherwise, if there is a subpanel, activate the delete subpanel */
  776. /* item. Else activate the add subpanel item. */
  777. control_type = (long)control_data->element_values[CONTROL_TYPE].parsed_value;
  778. if (control_type != CONTROL_BLANK)
  779. {
  780. XtManageChild (panel.popup_data->modify_subpanel_item);
  781. if (control_data->subpanel_data == NULL)
  782. {
  783. if (panel.popup_data->subpanel_add_state != True)
  784. {
  785. label_string =
  786. XmStringCreateLocalized ((FPGETMESSAGE(82, 10, "Add Subpanel")));
  787. XtSetArg (args[0], XmNlabelString, label_string);
  788. mnemonic = ((char *)FPGETMESSAGE(82, 11, "A"));
  789. XtSetArg (args[1], XmNmnemonic, mnemonic[0]);
  790. XtSetArg (args[2], XmNuserData, control_data);
  791. XtSetValues (panel.popup_data->modify_subpanel_item, args, 3);
  792. XmStringFree (label_string);
  793. XtRemoveCallback (panel.popup_data->modify_subpanel_item,
  794. XmNactivateCallback, DeleteSubpanelCB, NULL);
  795. XtAddCallback (panel.popup_data->modify_subpanel_item,
  796. XmNactivateCallback, AddSubpanelCB, NULL);
  797. panel.popup_data->subpanel_add_state = True;
  798. }
  799. else
  800. {
  801. XtSetArg (args[0], XmNuserData, control_data);
  802. XtSetValues (panel.popup_data->modify_subpanel_item, args, 1);
  803. }
  804. }
  805. else
  806. {
  807. if (panel.popup_data->subpanel_add_state == True)
  808. {
  809. label_string =
  810. XmStringCreateLocalized ((FPGETMESSAGE(82, 12, "Delete Subpanel")));
  811. XtSetArg (args[0], XmNlabelString, label_string);
  812. mnemonic = ((char *)FPGETMESSAGE(82, 13, "D"));
  813. XtSetArg (args[1], XmNmnemonic, mnemonic[0]);
  814. XtSetArg (args[2], XmNuserData, control_data);
  815. XtSetValues (panel.popup_data->modify_subpanel_item, args, 3);
  816. XmStringFree (label_string);
  817. XtRemoveCallback (panel.popup_data->modify_subpanel_item,
  818. XmNactivateCallback, AddSubpanelCB, NULL);
  819. XtAddCallback (panel.popup_data->modify_subpanel_item,
  820. XmNactivateCallback, DeleteSubpanelCB, NULL);
  821. panel.popup_data->subpanel_add_state = False;
  822. }
  823. else
  824. {
  825. XtSetArg (args[0], XmNuserData, control_data);
  826. XtSetValues (panel.popup_data->modify_subpanel_item, args, 1);
  827. }
  828. }
  829. }
  830. else
  831. {
  832. XtUnmanageChild (panel.popup_data->modify_subpanel_item);
  833. }
  834. XtRemoveAllCallbacks (panel.popup_data->help_item, XmNactivateCallback);
  835. XtAddCallback(panel.popup_data->help_item, XmNactivateCallback,
  836. ControlTopicHelpCB, (XtPointer)control_data);
  837. XtUnmanageChild (panel.popup_data->deinstall_item);
  838. XtUnmanageChild (panel.popup_data->toggle_item);
  839. /* Restore element values to control. */
  840. if (control_data->subpanel_data != NULL &&
  841. control_data != control_data->subpanel_data->default_control)
  842. {
  843. control_data->element_values = old_element_values;
  844. }
  845. }
  846. /************************************************************************
  847. *
  848. * UpdateSubpanelControlMenu
  849. * Set the elements of the popup menu for a subpanel control
  850. * item to its proper values before it is made visible.
  851. *
  852. * Inputs:
  853. * subpanel_data: The subpanel in which the menu is to be
  854. * posted.
  855. *
  856. * control_data: The control that the menu is being brought up for.
  857. *
  858. ************************************************************************/
  859. static void
  860. UpdateSubpanelControlMenu (SubpanelData * subpanel_data,
  861. ControlData * control_data)
  862. {
  863. XmString label_string;
  864. Arg args[5];
  865. char * control_label = NULL;
  866. /* Set the title of the menu */
  867. if (control_data)
  868. {
  869. control_label =
  870. (char *) control_data->element_values[CONTROL_LABEL].parsed_value;
  871. if (control_label == NULL)
  872. control_label =
  873. (char *) control_data->element_values[CONTROL_NAME].parsed_value;
  874. }
  875. else
  876. {
  877. control_label = FPGETMESSAGE(82, 36, "Install Icon");
  878. }
  879. label_string = XmStringCreateLocalized (control_label);
  880. XtSetArg (args[0], XmNlabelString, label_string);
  881. XtSetValues (panel.popup_data->popup_title, args, 1);
  882. XmStringFree (label_string);
  883. /* Set the sensitivity of the control deinstall and toggle menu item */
  884. if (control_data == NULL)
  885. {
  886. XtSetSensitive (panel.popup_data->deinstall_item, False);
  887. XtSetSensitive (panel.popup_data->toggle_item, False);
  888. XtRemoveAllCallbacks (panel.popup_data->help_item, XmNactivateCallback);
  889. XtAddCallback(panel.popup_data->help_item, XmNactivateCallback,
  890. GeneralTopicHelpCB, (XtPointer)INSTALL_ZONE);
  891. }
  892. else
  893. {
  894. XtSetSensitive (panel.popup_data->deinstall_item, True);
  895. XtSetArg (args[0], XmNuserData, control_data);
  896. XtSetValues(panel.popup_data->deinstall_item, args, 1);
  897. XtRemoveAllCallbacks (panel.popup_data->deinstall_item,
  898. XmNactivateCallback);
  899. XtAddCallback (panel.popup_data->deinstall_item, XmNactivateCallback,
  900. DeleteControlCB, (XtPointer) NULL);
  901. if ( control_data == subpanel_data->default_control)
  902. XtSetSensitive (panel.popup_data->toggle_item, False);
  903. else
  904. XtSetSensitive (panel.popup_data->toggle_item, True);
  905. XtSetArg (args[0], XmNuserData, control_data);
  906. XtSetValues(panel.popup_data->toggle_item, args, 1);
  907. XtRemoveAllCallbacks (panel.popup_data->toggle_item,
  908. XmNactivateCallback);
  909. XtAddCallback (panel.popup_data->toggle_item, XmNactivateCallback,
  910. ToggleControlCB, (XtPointer) subpanel_data);
  911. XtRemoveAllCallbacks (panel.popup_data->help_item, XmNactivateCallback);
  912. XtAddCallback(panel.popup_data->help_item, XmNactivateCallback,
  913. ControlTopicHelpCB, (XtPointer)control_data);
  914. }
  915. XtManageChild (panel.popup_data->deinstall_item);
  916. if (! (subpanel_data->parent_control_data->
  917. element_values[CONTROL_LOCKED].parsed_value))
  918. XtManageChild (panel.popup_data->toggle_item);
  919. else
  920. XtUnmanageChild (panel.popup_data->toggle_item);
  921. XtUnmanageChild (panel.popup_data->modify_subpanel_item);
  922. }
  923. /************************************************************************
  924. *
  925. * PopupMenu
  926. * Callback function which updates the popup menu for main panel
  927. * and subpanel controls before the menu is posted.
  928. *
  929. ************************************************************************/
  930. static void
  931. PopupMenu (Widget w,
  932. XtPointer client_data,
  933. XtPointer call_data)
  934. {
  935. XmAnyCallbackStruct * callback;
  936. XEvent * event;
  937. Widget form, focus_widget;
  938. XmManagerWidget mgr;
  939. SubpanelData * subpanel_data = NULL;
  940. ControlData * control_data;
  941. BoxData * box_data = NULL;
  942. XmString label_string;
  943. Arg args[5];
  944. long control_type, action_count = panel.popup_data->action_count;
  945. callback = (XmAnyCallbackStruct *) call_data;
  946. event = (XEvent *) callback->event;
  947. /* Get the form where the menu was posted from. */
  948. form = XmGetPostedFromWidget(w);
  949. XtSetArg (args[0], XmNuserData, &control_type);
  950. XtGetValues (form, args, 1);
  951. if (control_type == CONTROL)
  952. {
  953. GetBoxDataFromForm (form, &box_data);
  954. subpanel_data = NULL;
  955. }
  956. else if (control_type == SUBPANEL)
  957. {
  958. GetSubpanelDataFromForm (form, &subpanel_data);
  959. box_data = NULL;
  960. }
  961. if (event->type == ButtonPress)
  962. {
  963. /* Change to use new Xme function when porting to Motif 2.0 */
  964. /* Get gadget at x, y position */
  965. focus_widget = (Widget) XmObjectAtPoint (form, event->xbutton.x,
  966. event->xbutton.y);
  967. if (focus_widget == NULL)
  968. return;
  969. /* set the menu positioning */
  970. XmMenuPosition (panel.popup_data->popup, (XButtonPressedEvent *)event);
  971. }
  972. else
  973. {
  974. /* get the widget that has the traversal focus */
  975. focus_widget = XmGetFocusWidget (form);
  976. /* set the menu positioning for non button events */
  977. KeyMenuPosition (panel.popup_data->popup, focus_widget);
  978. }
  979. if (control_type == CONTROL)
  980. {
  981. control_data = GetMainControlData (box_data, focus_widget);
  982. /* Find the right subpanel data if main control is not default */
  983. /* control. */
  984. UpdateMainControlMenu (control_data);
  985. if (control_data->subpanel_data != NULL &&
  986. control_data != control_data->subpanel_data->default_control)
  987. {
  988. subpanel_data = control_data->subpanel_data;
  989. control_data = control_data->subpanel_data->default_control;
  990. control_data->subpanel_data = subpanel_data;
  991. UpdateMainControlMenu (control_data);
  992. }
  993. SetupActionMenuItems (w, control_data, panel.popup_data,
  994. panel.popup_data->action_item, &action_count);
  995. }
  996. else if (control_type == SUBPANEL)
  997. {
  998. control_data = GetSubpanelControlData (subpanel_data, focus_widget);
  999. UpdateSubpanelControlMenu (subpanel_data, control_data);
  1000. SetupActionMenuItems (w, control_data, panel.popup_data,
  1001. panel.popup_data->action_item, &action_count);
  1002. }
  1003. panel.popup_data->action_count = action_count;
  1004. }
  1005. /************************************************************************
  1006. *
  1007. * CreatePopupMenu
  1008. *
  1009. ************************************************************************/
  1010. void
  1011. CreatePopupMenu (Widget w)
  1012. {
  1013. Widget children[20];
  1014. char * mnemonic;
  1015. Arg args[5];
  1016. PopupData * popup_data;
  1017. long i, child_num = 0;
  1018. XmString label_string;
  1019. popup_data = panel.popup_data = (PopupData *) XtMalloc(sizeof(PopupData));
  1020. i = 0;
  1021. XtSetArg (args[i], XmNwhichButton, wmGD.bMenuButton); i++;
  1022. popup_data->popup = XmCreatePopupMenu(w, "FPPopup", args, i);
  1023. popup_data->add_ws_item = NULL;
  1024. XtAddCallback (popup_data->popup, XmNmapCallback, PopupMenu,
  1025. (XtPointer) NULL);
  1026. popup_data->popup_title = children[child_num++] =
  1027. XmCreateLabelGadget(popup_data->popup, "title", NULL, 0);
  1028. children[child_num++] = XmCreateSeparatorGadget(popup_data->popup,
  1029. "sep1", NULL, 0);
  1030. children[child_num++] = XmCreateSeparatorGadget(popup_data->popup,
  1031. "sep2", NULL, 0);
  1032. popup_data->action_item = (Widget *) XtMalloc(sizeof(Widget) * 5);
  1033. popup_data->action_count = 0;
  1034. for (i = 0; i < 5; i++)
  1035. {
  1036. children[child_num] = popup_data->action_item[i] =
  1037. XmCreatePushButtonGadget(popup_data->popup, "action_button", args, 0);
  1038. popup_data->action_count++;
  1039. XtManageChild (popup_data->action_item[i]);
  1040. XtAddCallback (children[child_num++], XmNactivateCallback,
  1041. ActionCB, (XtPointer) i);
  1042. }
  1043. popup_data->separator1 = children[child_num++] =
  1044. XmCreateSeparatorGadget (popup_data->popup, "sep3", NULL, 0);
  1045. label_string =
  1046. XmStringCreateLocalized((FPGETMESSAGE(82, 14, "Copy To Main Panel")));
  1047. XtSetArg (args[0], XmNlabelString, label_string);
  1048. mnemonic = ((char *)FPGETMESSAGE(82, 15, "C"));
  1049. XtSetArg (args[1], XmNmnemonic, mnemonic[0]);
  1050. popup_data->toggle_item = children[child_num] =
  1051. XmCreatePushButtonGadget (popup_data->popup, "Toggle_Control", args, 2);
  1052. XmStringFree (label_string);
  1053. label_string = XmStringCreateLocalized((FPGETMESSAGE(82, 16, "Delete")));
  1054. XtSetArg (args[0], XmNlabelString, label_string);
  1055. mnemonic = ((char *)FPGETMESSAGE(82, 17, "D"));
  1056. XtSetArg (args[1], XmNmnemonic, mnemonic[0]);
  1057. popup_data->deinstall_item = children[child_num] =
  1058. XmCreatePushButtonGadget(popup_data->popup, "Delete_Control",
  1059. args, 2);
  1060. XmStringFree (label_string);
  1061. label_string =
  1062. XmStringCreateLocalized ((FPGETMESSAGE(82, 10, "Add Subpanel")));
  1063. XtSetArg (args[0], XmNlabelString, label_string);
  1064. mnemonic = ((char *)FPGETMESSAGE(82, 11, "A"));
  1065. XtSetArg (args[1], XmNmnemonic, mnemonic[0]);
  1066. popup_data->modify_subpanel_item = children[child_num] =
  1067. XmCreatePushButtonGadget (popup_data->popup, "Add_Subpanel", args, 2);
  1068. XmStringFree (label_string);
  1069. XtAddCallback(children[child_num++], XmNactivateCallback, AddSubpanelCB,
  1070. (XtPointer)NULL);
  1071. popup_data->subpanel_add_state = True;
  1072. popup_data->separator2 = children[child_num++] =
  1073. XmCreateSeparatorGadget(popup_data->popup, "sep4", NULL, 0);
  1074. label_string = XmStringCreateLocalized ((FPGETMESSAGE(82, 18, "Help")));
  1075. XtSetArg (args[0], XmNlabelString, label_string);
  1076. mnemonic = ((char *)FPGETMESSAGE(82, 19, "H"));
  1077. XtSetArg (args[1], XmNmnemonic, mnemonic[0]);
  1078. popup_data->help_item = children[child_num++] =
  1079. XmCreatePushButtonGadget (popup_data->popup, "Help", args, 2);
  1080. XmStringFree (label_string);
  1081. XtManageChildren(children, child_num);
  1082. }
  1083. /************************************************************************
  1084. *
  1085. * CreateActionButtons
  1086. * Show the the action menu items and hide workspace menu items since
  1087. * we are over a control.
  1088. *
  1089. *
  1090. ************************************************************************/
  1091. static void
  1092. CreateActionButtons (Widget w,
  1093. SwitchData * switch_data,
  1094. ControlData * control_data)
  1095. {
  1096. PopupData * popup_data = switch_data->popup_data;
  1097. long action_count = popup_data->action_count;
  1098. Arg args[1];
  1099. XmString label_string;
  1100. char * control_label;
  1101. /* Set the title of the menu */
  1102. control_label =
  1103. (char *) control_data->element_values[CONTROL_LABEL].parsed_value;
  1104. if (control_label == NULL)
  1105. control_label =
  1106. (char *) control_data->element_values[CONTROL_NAME].parsed_value;
  1107. label_string = XmStringCreateLocalized (control_label);
  1108. XtSetArg (args[0], XmNlabelString, label_string);
  1109. XtSetValues (popup_data->popup_title, args, 1);
  1110. XmStringFree (label_string);
  1111. /* show actions items */
  1112. SetupActionMenuItems(w, control_data, popup_data,
  1113. popup_data->action_item, &action_count);
  1114. popup_data->action_count = action_count;
  1115. /* hide add and delete workspace items */
  1116. XtUnmanageChild(popup_data->add_ws_item);
  1117. XtUnmanageChild(popup_data->delete_ws_item);
  1118. XtUnmanageChild(popup_data->rename_ws_item);
  1119. /* reset the help callback to reflect switch control help */
  1120. XtRemoveAllCallbacks (popup_data->help_item, XmNactivateCallback);
  1121. XtAddCallback(popup_data->help_item, XmNactivateCallback,
  1122. ControlTopicHelpCB, control_data);
  1123. }
  1124. /************************************************************************
  1125. *
  1126. * ShowWorkspaceItems
  1127. * Don't show the the action menu items since we are not over a control.
  1128. * Reset the activate callbacks with the latest data.
  1129. *
  1130. ************************************************************************/
  1131. static void
  1132. ShowWorkspaceItems (SwitchData * switch_data,
  1133. Widget focus_widget)
  1134. {
  1135. PopupData * popup_data = switch_data->popup_data;
  1136. long i;
  1137. Arg args[1];
  1138. XmString label_string;
  1139. char * control_label;
  1140. char * ws;
  1141. char * ws_name;
  1142. char * format;
  1143. /* hide actions items */
  1144. for (i = 0; i < popup_data->action_count; i++)
  1145. XtUnmanageChild (popup_data->action_item[i]);
  1146. /* show add and delete workspace items */
  1147. XtManageChild (popup_data->add_ws_item);
  1148. XtManageChild (popup_data->delete_ws_item);
  1149. XtManageChild (popup_data->rename_ws_item);
  1150. /* reset the activate callback to reflect current button index */
  1151. XtRemoveAllCallbacks (popup_data->delete_ws_item, XmNactivateCallback);
  1152. for (i = 0; i < switch_data->switch_count &&
  1153. switch_data->buttons[i] != NULL; i++)
  1154. {
  1155. if (switch_data->buttons[i] == focus_widget) break;
  1156. }
  1157. /* If we didn't find the switch button to post the menu for, it */
  1158. /* must be in edit mode so the correct menu is the active switch */
  1159. if (i >= switch_data->switch_count)
  1160. i = switch_data->active_switch;
  1161. /* Set the title of the menu */
  1162. format = strdup (FPGETMESSAGE(82, 20, "%1$s %2$s"));
  1163. ws = strdup (FPGETMESSAGE(82, 21, "Workspace"));
  1164. ws_name = switch_data->switch_names[i];
  1165. control_label = XtMalloc (sizeof(char) * (strlen(ws) + strlen(ws_name) + 4));
  1166. sprintf (control_label, format, ws, ws_name);
  1167. free (format);
  1168. free (ws);
  1169. label_string = XmStringCreateLocalized (control_label);
  1170. XtSetArg (args[0], XmNlabelString, label_string);
  1171. XtSetValues (popup_data->popup_title, args, 1);
  1172. XmStringFree (label_string);
  1173. XtFree(control_label);
  1174. XtAddCallback (popup_data->delete_ws_item, XmNactivateCallback,
  1175. DeleteWorkspaceCB, (XtPointer) i);
  1176. /* reset the activate callback to reflect current button index */
  1177. XtRemoveAllCallbacks (popup_data->rename_ws_item, XmNactivateCallback);
  1178. XtAddCallback (popup_data->rename_ws_item, XmNactivateCallback,
  1179. RenameWorkspaceCB, (XtPointer) i);
  1180. /* reset the help callback to reflect switch button help */
  1181. XtRemoveAllCallbacks (popup_data->help_item, XmNactivateCallback);
  1182. XtAddCallback(popup_data->help_item, XmNactivateCallback,
  1183. GeneralTopicHelpCB, (XtPointer) SWITCH_BUTTON);
  1184. XtManageChild(popup_data->separator1);
  1185. }
  1186. /************************************************************************
  1187. *
  1188. * ShowPartialWorkspaceItems
  1189. * Don't show the delete workspace item since we are not over
  1190. * a workspace button and don't show the action menu items since we are
  1191. * not over a control. Reset the activate callback with the latest data.
  1192. *
  1193. ************************************************************************/
  1194. static void
  1195. ShowPartialWorkspaceItems(SwitchData * switch_data)
  1196. {
  1197. PopupData * popup_data = switch_data->popup_data;
  1198. int i;
  1199. Arg args[1];
  1200. XmString label_string;
  1201. label_string = XmStringCreateLocalized((FPGETMESSAGE(82, 22, "Switch Area")));
  1202. XtSetArg (args[0], XmNlabelString, label_string);
  1203. XtSetValues (popup_data->popup_title, args, 1);
  1204. XmStringFree (label_string);
  1205. /* hide actions items */
  1206. for (i = 0; i < popup_data->action_count; i++)
  1207. XtUnmanageChild (popup_data->action_item[i]);
  1208. /* show add workspace item */
  1209. XtManageChild (popup_data->add_ws_item);
  1210. /* hide delete and rename workspace items */
  1211. XtUnmanageChild (popup_data->delete_ws_item);
  1212. XtUnmanageChild (popup_data->rename_ws_item);
  1213. /* reset the help callback to reflect switch area help */
  1214. XtRemoveAllCallbacks (popup_data->help_item, XmNactivateCallback);
  1215. XtAddCallback(popup_data->help_item, XmNactivateCallback,
  1216. SwitchTopicHelpCB, (XtPointer)switch_data);
  1217. XtManageChild(popup_data->separator1);
  1218. }
  1219. /************************************************************************
  1220. *
  1221. * GetSwitchDataFromForm
  1222. *
  1223. ************************************************************************/
  1224. static void
  1225. GetSwitchDataFromForm (Widget form,
  1226. SwitchData ** switch_data_rtn)
  1227. {
  1228. BoxData * box_data;
  1229. int i;
  1230. for (i = 0; i < panel.box_data_count; i++)
  1231. {
  1232. box_data = panel.box_data[i];
  1233. if (box_data->switch_form == form)
  1234. {
  1235. *switch_data_rtn = box_data->switch_data;
  1236. break;
  1237. }
  1238. }
  1239. }
  1240. /************************************************************************
  1241. *
  1242. * GetSwtichControlData
  1243. *
  1244. ************************************************************************/
  1245. static ControlData *
  1246. GetSwitchControlData (SwitchData * switch_data,
  1247. Widget focus_widget)
  1248. {
  1249. int i;
  1250. ControlData * control_data;
  1251. Boolean found = False;
  1252. for (i = 0; i < switch_data->control_data_count; i++)
  1253. {
  1254. control_data = switch_data->control_data[i];
  1255. if (control_data->icon == focus_widget)
  1256. {
  1257. found = True;
  1258. break;
  1259. }
  1260. }
  1261. if (!found) return NULL;
  1262. return (control_data);
  1263. }
  1264. /************************************************************************
  1265. *
  1266. * WSPopupMenu
  1267. *
  1268. ************************************************************************/
  1269. static void
  1270. WSPopupMenu (Widget w,
  1271. XtPointer client_data,
  1272. XtPointer call_data)
  1273. {
  1274. XmManagerWidget mgr = (XmManagerWidget) w;
  1275. int num_children = mgr->composite.num_children;
  1276. XmAnyCallbackStruct * callback;
  1277. XEvent * event;
  1278. Widget form, focus_widget;
  1279. SwitchData * switch_data;
  1280. ControlData * control_data = NULL;
  1281. Boolean is_button = False;
  1282. Position x, y;
  1283. Arg args[2];
  1284. long control_type;
  1285. callback = (XmAnyCallbackStruct *) call_data;
  1286. event = (XEvent *) callback->event;
  1287. /* get the form where the menu was posted from */
  1288. form = XmGetPostedFromWidget (w);
  1289. GetSwitchDataFromForm (form, &switch_data);
  1290. if (event->type == ButtonPress)
  1291. {
  1292. /* Change to use new Xme function when porting to Motif 2.0 */
  1293. /* Get gadget at x, y position */
  1294. focus_widget = (Widget) XmObjectAtPoint (form, event->xbutton.x,
  1295. event->xbutton.y);
  1296. if (focus_widget == NULL)
  1297. {
  1298. XtSetArg (args[0], XmNx, &x);
  1299. XtSetArg (args[1], XmNy, &y);
  1300. XtGetValues(switch_data->rc, args, 2);
  1301. focus_widget = (Widget) XmObjectAtPoint (switch_data->rc,
  1302. event->xbutton.x - x,
  1303. event->xbutton.y - y);
  1304. is_button = True;
  1305. }
  1306. else
  1307. control_data = GetSwitchControlData (switch_data, focus_widget);
  1308. /* set the menu positioning */
  1309. XmMenuPosition (switch_data->popup_data->popup,
  1310. (XButtonPressedEvent *) event);
  1311. }
  1312. else
  1313. {
  1314. /* get the widget that has the traversal focus */
  1315. focus_widget = XmGetFocusWidget (form);
  1316. control_data = GetSwitchControlData (switch_data, focus_widget);
  1317. if (control_data == NULL)
  1318. is_button = True;
  1319. /* set the menu positioning for non button events */
  1320. KeyMenuPosition (switch_data->popup_data->popup, focus_widget);
  1321. }
  1322. if (focus_widget != NULL)
  1323. {
  1324. if (is_button)
  1325. /* The mouse is over a button in the switch area */
  1326. ShowWorkspaceItems (switch_data, focus_widget);
  1327. else
  1328. {
  1329. if (control_data != NULL)
  1330. {
  1331. control_type =
  1332. (long) control_data->element_values[CONTROL_TYPE].parsed_value;
  1333. if (control_type != CONTROL_BLANK)
  1334. /* The mouse is over a control in the switch area */
  1335. CreateActionButtons (w, switch_data, control_data);
  1336. else
  1337. /* The mouse is over a blank control in the switch area */
  1338. ShowPartialWorkspaceItems (switch_data);
  1339. }
  1340. else
  1341. {
  1342. /*
  1343. * The mouse is over area other than the buttons and control
  1344. * in the switch area
  1345. */
  1346. ShowPartialWorkspaceItems (switch_data);
  1347. }
  1348. }
  1349. }
  1350. else
  1351. /*
  1352. * The mouse is over area other than the buttons and control
  1353. * in the switch area
  1354. */
  1355. ShowPartialWorkspaceItems (switch_data);
  1356. }
  1357. /************************************************************************
  1358. *
  1359. * CreateWorkspacePopupMenu
  1360. *
  1361. ************************************************************************/
  1362. void
  1363. CreateWorkspacePopupMenu (Widget w,
  1364. SwitchData * switch_data)
  1365. {
  1366. Widget children[20];
  1367. XmString label_string;
  1368. char * mnemonic;
  1369. Arg args[5];
  1370. long i, child_num = 0;
  1371. PopupData * popup_data;
  1372. popup_data = (PopupData *) XtMalloc(sizeof(PopupData));
  1373. i = 0;
  1374. XtSetArg (args[i], XmNwhichButton, wmGD.bMenuButton); i++;
  1375. popup_data->popup = XmCreatePopupMenu(w, "WSPopup", args, i);
  1376. popup_data->deinstall_item = NULL;
  1377. popup_data->toggle_item = NULL;
  1378. popup_data->modify_subpanel_item = NULL;
  1379. popup_data->subpanel_add_state = True;
  1380. XtAddCallback(popup_data->popup, XmNmapCallback, WSPopupMenu,
  1381. (XtPointer) switch_data);
  1382. label_string = XmStringCreateLocalized((FPGETMESSAGE(82, 22, "Switch Area")));
  1383. XtSetArg (args[0], XmNlabelString, label_string);
  1384. popup_data->popup_title = children[child_num++] =
  1385. XmCreateLabelGadget (popup_data->popup, "title", args, 1);
  1386. XmStringFree (label_string);
  1387. children[child_num++] = XmCreateSeparatorGadget (popup_data->popup, "sep1",
  1388. NULL, 0);
  1389. children[child_num++] = XmCreateSeparatorGadget (popup_data->popup, "sep2",
  1390. NULL, 0);
  1391. popup_data->action_item = (Widget *) XtMalloc(sizeof(Widget) * 5);
  1392. popup_data->action_count = 0;
  1393. for (i = 0; i < 5; i++)
  1394. {
  1395. children[child_num] = popup_data->action_item[i] =
  1396. XmCreatePushButtonGadget (popup_data->popup, "action_button", args, 0);
  1397. popup_data->action_count++;
  1398. XtManageChild (popup_data->action_item[i]);
  1399. XtAddCallback (children[child_num++], XmNactivateCallback,
  1400. ActionCB, (XtPointer) i);
  1401. }
  1402. label_string =
  1403. XmStringCreateLocalized ((FPGETMESSAGE(82, 23, "Add Workspace")));
  1404. XtSetArg (args[0], XmNlabelString, label_string);
  1405. mnemonic = ((char *)FPGETMESSAGE(82, 24, "A"));
  1406. XtSetArg (args[1], XmNmnemonic, mnemonic[0]);
  1407. popup_data->add_ws_item = children[child_num] =
  1408. XmCreatePushButtonGadget (popup_data->popup, "Add_Workspace", args, 2);
  1409. XmStringFree (label_string);
  1410. XtAddCallback(children[child_num++], XmNactivateCallback, AddWorkspaceCB,
  1411. (XtPointer)NULL);
  1412. label_string = XmStringCreateLocalized((FPGETMESSAGE(82, 25, "Delete")));
  1413. XtSetArg (args[0], XmNlabelString, label_string);
  1414. mnemonic = ((char *)FPGETMESSAGE(82, 26, "D"));
  1415. XtSetArg (args[1], XmNmnemonic, mnemonic[0]);
  1416. popup_data->delete_ws_item = children[child_num] =
  1417. XmCreatePushButtonGadget (popup_data->popup,
  1418. "Delete_Workspace", args, 2);
  1419. XmStringFree (label_string);
  1420. XtAddCallback(children[child_num++], XmNactivateCallback,
  1421. DeleteWorkspaceCB, (XtPointer) 0);
  1422. label_string = XmStringCreateLocalized((FPGETMESSAGE(82, 27, "Rename")));
  1423. XtSetArg (args[0], XmNlabelString, label_string);
  1424. mnemonic = ((char *)FPGETMESSAGE(82, 28, "R"));
  1425. XtSetArg (args[1], XmNmnemonic, mnemonic[0]);
  1426. popup_data->rename_ws_item = children[child_num] =
  1427. XmCreatePushButtonGadget (popup_data->popup,
  1428. "Rename_Workspace", args, 2);
  1429. XmStringFree (label_string);
  1430. XtAddCallback(children[child_num++], XmNactivateCallback,
  1431. RenameWorkspaceCB, (XtPointer) 0);
  1432. popup_data->separator1 = children[child_num++] =
  1433. XmCreateSeparatorGadget (popup_data->popup, "sep3", NULL, 0);
  1434. popup_data->separator2 = NULL;
  1435. label_string = XmStringCreateLocalized((FPGETMESSAGE(82, 29, "Help")));
  1436. XtSetArg (args[0], XmNlabelString, label_string);
  1437. mnemonic = ((char *)FPGETMESSAGE(82, 30, "H"));
  1438. XtSetArg (args[1], XmNmnemonic, mnemonic[0]);
  1439. popup_data->help_item = children[child_num++] =
  1440. XmCreatePushButtonGadget (popup_data->popup, "Help", args, 2);
  1441. XmStringFree (label_string);
  1442. XtManageChildren(children, child_num);
  1443. switch_data->popup_data = popup_data;
  1444. }