2
0

Encaps.c 69 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515
  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. /* $XConsortium: Encaps.c /main/10 1996/10/30 11:10:16 drk $ */
  24. /************************************<+>*************************************
  25. ****************************************************************************
  26. *
  27. * FILE: Encaps.c
  28. *
  29. * COMPONENT_NAME: Desktop File Manager (dtfile)
  30. *
  31. * Description: Source file for the dialog encapsulation functions.
  32. *
  33. * FUNCTIONS: DataChangeCallback
  34. * DataCloseCallback
  35. * DialogStructureNotifyHandler
  36. * IntDialogGetResources
  37. * IntDialogPutResources
  38. * SetIconifyState
  39. * TimerEvent
  40. * _DtBooleanToString
  41. * _DtBuildDialog
  42. * _DtChildPosition
  43. * _DtDialogGetResources
  44. * _DtDialogPutResources
  45. * _DtDimensionToString
  46. * _DtEncapSetWorkSpaceHints
  47. * _DtFreeDialogData
  48. * _DtGetDefaultDialogData
  49. * _DtGetDialogData
  50. * _DtGetDialogInstance
  51. * _DtGetDialogShell
  52. * _DtGetInstanceData
  53. * _DtGetResourceDialogData
  54. * _DtHideDialog
  55. * _DtInitializeEncapsulation
  56. * _DtInstallDialog
  57. * _DtIntToString
  58. * _DtIsDialogShowing
  59. * _DtPositionToString
  60. * _DtShortToString
  61. * _DtShowBuiltDialog
  62. * _DtShowDialog
  63. * _DtStringToString
  64. * _DtWriteDialogData
  65. * _DtXmStringTableToString
  66. * _DtXmStringToString
  67. * _DtmapCB
  68. * _DtChangeTo
  69. *
  70. * (c) Copyright 1993, 1994, 1995 Hewlett-Packard Company
  71. * (c) Copyright 1993, 1994, 1995 International Business Machines Corp.
  72. * (c) Copyright 1993, 1994, 1995 Sun Microsystems, Inc.
  73. * (c) Copyright 1993, 1994, 1995 Novell, Inc.
  74. *
  75. ****************************************************************************
  76. ************************************<+>*************************************/
  77. #include <string.h>
  78. #include <Xm/XmP.h>
  79. #include <Xm/Xm.h>
  80. #include <Xm/BulletinB.h>
  81. #include <Xm/AtomMgr.h>
  82. #include <Xm/MwmUtil.h>
  83. #include <Xm/VendorSEP.h>
  84. #include <Xm/XmPrivate.h> /* _XmStringUngenerate, _XmGetWidgetExtData */
  85. #include <X11/ShellP.h>
  86. #include <X11/Shell.h>
  87. #include <X11/Xutil.h>
  88. #include <X11/Xatom.h>
  89. #include <X11/Intrinsic.h>
  90. #include <Dt/Wsm.h>
  91. #include <Dt/DtNlUtils.h>
  92. #include "Encaps.h"
  93. #include "Desktop.h"
  94. #include "Filter.h"
  95. #include "FileMgr.h"
  96. #include "Main.h"
  97. #include "ModAttr.h"
  98. #ifdef USE_XINERAMA
  99. #include <DtXinerama.h>
  100. #endif
  101. #define MAX_NAME_LIST_SIZE 25
  102. #define MAX_RESOURCE_LENGTH 256
  103. /* Cache array handling defines, structure, and global statics */
  104. #define INCREMENT_SIZE 10
  105. typedef struct _Dialog
  106. {
  107. Boolean in_use;
  108. Widget dialog_widget;
  109. XtPointer dialog;
  110. DialogData * dialog_data;
  111. DialogChangedProc change;
  112. XtPointer change_client_data;
  113. DialogClosedProc close;
  114. XtPointer close_client_data;
  115. struct _Dialog * next;
  116. } Dialog;
  117. typedef struct
  118. {
  119. DialogClass * class;
  120. Dialog * dialog_list;
  121. Boolean cache;
  122. Boolean destroyPopups;
  123. } ClassSet;
  124. extern int filter_dialog,mod_attr_dialog;
  125. static ClassSet * class_set = NULL;
  126. static int class_set_size = 0;
  127. static int num_classes = 0;
  128. static int NumberOfDialogMapped = 0;
  129. static char * resourceBuf = NULL;
  130. static int commonResourceCount = 5;
  131. static DialogResource commonResources[] =
  132. {
  133. { "displayed", XmRBoolean, sizeof(Boolean),
  134. XtOffset(DialogInstanceDataPtr, displayed),
  135. (caddr_t) False, _DtBooleanToString },
  136. { "x", XmRPosition, sizeof(Position),
  137. XtOffset(DialogInstanceDataPtr, x),
  138. (caddr_t) 0, _DtPositionToString},
  139. { "y", XmRPosition, sizeof(Position),
  140. XtOffset(DialogInstanceDataPtr, y),
  141. (caddr_t) 0, _DtPositionToString },
  142. { "width", XmRHorizontalDimension, sizeof(Dimension),
  143. XtOffset(DialogInstanceDataPtr, width),
  144. (caddr_t) 0, _DtDimensionToString },
  145. { "height", XmRVerticalDimension, sizeof(Dimension),
  146. XtOffset(DialogInstanceDataPtr, height),
  147. (caddr_t) 0, _DtDimensionToString },
  148. };
  149. static Widget encap_parent_shell;
  150. extern int file_mgr_dialog;
  151. /* Timer globals */
  152. /*
  153. * initialTimeoutLength is used to specify how long to wait before initially
  154. * kicking of the building of the dialog cache.
  155. * activeTimeoutLength is used to specify how long to wait after adding
  156. * a dialog to the cache, before adding the next dialog.
  157. * idleTimeoutLength is used to specify how long to wait after all dialogs
  158. * have been built, and the cache is full.
  159. */
  160. int initialTimeoutLength = 180000; /* 3 minutes, in milliseconds */
  161. int activeTimeoutLength = 30000; /* 30 seconds, in milliseconds */
  162. int idleTimeoutLength = 900000; /* 15 minutes, in milliseconds */
  163. #define TIMER_STARTUP_STATE 0
  164. #define TIMER_ACTIVE_STATE 1
  165. #define TIMER_IDLE_STATE 2
  166. static int timerState = TIMER_STARTUP_STATE;
  167. static XtIntervalId timerId = 0;
  168. /*
  169. * This global is used when positioning a dialog ABOVE (not below) its
  170. * parent window. The 'y' position is defined to be the 'y' position
  171. * of the parent, minus the 'height' of the dialog, minus the value
  172. * assigned to 'topPositionOffset'; this allows the application to control
  173. * how much, if any, of the parent's title bar is covered.
  174. */
  175. int topPositionOffset = 20;
  176. /******** Static Function Declarations ********/
  177. static void DialogStructureNotifyHandler(
  178. Widget w,
  179. XtPointer client_data,
  180. XEvent *event );
  181. static void SetIconifyState(
  182. Widget shell,
  183. Boolean iconify) ;
  184. static void DataChangeCallback(
  185. Widget widget,
  186. XtPointer client_data,
  187. XtPointer call_data) ;
  188. static void DataCloseCallback(
  189. Widget widget,
  190. XtPointer client_data,
  191. XtPointer call_data) ;
  192. static void TimerEvent(
  193. Widget widget,
  194. XtIntervalId *id) ;
  195. static void IntDialogGetResources(
  196. XrmDatabase database,
  197. char *base,
  198. DialogResource *resource,
  199. XrmName *xrmName,
  200. int nameCount,
  201. XrmQuark stringQuark) ;
  202. static void IntDialogPutResources(
  203. int fd,
  204. char **nameList,
  205. char *dialogName,
  206. char *base,
  207. DialogResource *resource) ;
  208. #ifdef USE_XINERAMA
  209. static Boolean GetXineramaScreenDimensions(
  210. Widget w,int *xorg, int *yorg, int *width,int *height);
  211. #endif /* USE_XINERAMA */
  212. /******** End Static Function Declarations ********/
  213. /************************************************************************
  214. *
  215. * _DtInitializeEncapsulation
  216. * This function is used to initialize the dialog encapsulation.
  217. *
  218. ************************************************************************/
  219. void
  220. _DtInitializeEncapsulation(
  221. Display *display,
  222. char *name,
  223. char *class )
  224. {
  225. Arg args[5];
  226. /* Create an application shell that will never be */
  227. /* displayed that is used as a parent of all of the */
  228. /* dialog created. */
  229. encap_parent_shell = XtAppCreateShell (name, class,
  230. applicationShellWidgetClass,
  231. display, NULL, 0);
  232. /* Supposedly required to be ICCCM complient */
  233. XtSetArg(args[0], XmNmappedWhenManaged, False);
  234. XtSetArg(args[1], XmNwidth, 1);
  235. XtSetArg(args[2], XmNheight, 1);
  236. XtSetValues(encap_parent_shell, args, 3);
  237. XtRealizeWidget(encap_parent_shell);
  238. /* Get a timer going that is used for auto creation of dialogs. */
  239. timerState = TIMER_STARTUP_STATE;
  240. timerId = XtAppAddTimeOut(XtWidgetToApplicationContext(encap_parent_shell),
  241. initialTimeoutLength, (XtTimerCallbackProc)
  242. TimerEvent, (caddr_t) encap_parent_shell);
  243. /* Allocate a buffer for writing out resource values */
  244. resourceBuf = XtMalloc(20);
  245. }
  246. /************************************************************************
  247. *
  248. * _DtInstallDialog
  249. * This function is used to register a dialog class with the
  250. * encapsulation functions.
  251. *
  252. ************************************************************************/
  253. int
  254. _DtInstallDialog(
  255. DialogClass *dialog_class,
  256. Boolean cache,
  257. Boolean destroyPopups )
  258. {
  259. /* Allocate additional dialog cache space if needed */
  260. if (num_classes == class_set_size)
  261. {
  262. class_set_size += INCREMENT_SIZE;
  263. class_set =
  264. (ClassSet *) XtRealloc ((char *)class_set,
  265. sizeof (ClassSet) * class_set_size);
  266. }
  267. class_set[num_classes].class = dialog_class;
  268. class_set[num_classes].dialog_list = NULL;
  269. class_set[num_classes].cache = cache;
  270. class_set[num_classes].destroyPopups = destroyPopups;
  271. num_classes++;
  272. return (num_classes - 1);
  273. }
  274. /************************************************************************
  275. *
  276. * _DtGetDialogData
  277. * This function is used to get a structure containing the
  278. * current dialog data for a particular dialog instance.
  279. *
  280. ************************************************************************/
  281. DialogData *
  282. _DtGetDialogData(
  283. DialogData *dialog_data )
  284. {
  285. Dialog * dialog;
  286. DialogData * new_data;
  287. dialog = class_set[dialog_data->type].dialog_list;
  288. while (dialog != NULL)
  289. {
  290. if (dialog->dialog_data == dialog_data)
  291. {
  292. new_data = (DialogData *) XtMalloc (sizeof (DialogData));
  293. new_data->type = dialog->dialog_data->type;
  294. new_data->data = NULL;
  295. if (class_set[new_data->type].class->get_values)
  296. {
  297. new_data->data =
  298. (*(class_set[new_data->type].class->get_values)) (dialog->dialog);
  299. }
  300. return (new_data);
  301. }
  302. dialog = dialog->next;
  303. }
  304. return (NULL);
  305. }
  306. /************************************************************************
  307. *
  308. * _DtGetDefaultDialogData
  309. * This function is used to get a structure containing the
  310. * default data for a particular dialog type.
  311. *
  312. ************************************************************************/
  313. DialogData *
  314. _DtGetDefaultDialogData(
  315. int dialog_type )
  316. {
  317. DialogData * dialog_data;
  318. dialog_data = (DialogData *) XtMalloc (sizeof (DialogData));
  319. dialog_data->type = dialog_type;
  320. dialog_data->data = (*(class_set[dialog_type].class->get_default_values))();
  321. return (dialog_data);
  322. }
  323. /************************************************************************
  324. *
  325. * _DtGetResourceDialogData
  326. * This function is used to get a structure containing the
  327. * data for a particular dialog type from a resource data base.
  328. *
  329. ************************************************************************/
  330. DialogData *
  331. _DtGetResourceDialogData(
  332. int dialog_type,
  333. XrmDatabase data_base,
  334. char **name_list )
  335. {
  336. DialogData * dialog_data;
  337. dialog_data = (DialogData *) XtMalloc (sizeof (DialogData));
  338. dialog_data->type = dialog_type;
  339. dialog_data->data = (*(class_set[dialog_type].class->get_resource_values))
  340. (data_base, name_list);
  341. return (dialog_data);
  342. }
  343. /************************************************************************
  344. *
  345. * _DtShowDialog
  346. * This functions is used to display an instance of a dialog with
  347. * the provided data. The functions and data to be set back to
  348. * the application upon change or close of the dialog is also
  349. * provided as parameters.
  350. *
  351. ************************************************************************/
  352. void
  353. _DtShowDialog(
  354. Widget parent,
  355. Widget map_parent,
  356. XtPointer top_rec,
  357. DialogData *dialog_data,
  358. DialogChangedProc change_proc,
  359. XtPointer change_data,
  360. DialogClosedProc close_proc,
  361. XtPointer close_data,
  362. char *workspaces,
  363. Boolean iconify_state,
  364. Boolean ignoreCache,
  365. char * title,
  366. XClassHint * classHints )
  367. {
  368. Dialog * dialog;
  369. int dialog_type, n;
  370. DialogInstanceData * instance_data;
  371. char geometry[40];
  372. Arg args[5];
  373. Boolean doCenter = False;
  374. Boolean doParentRelativePositioning = False;
  375. int availableDialogCount;
  376. /* See if there is a cached, unused dialog of the correct type. */
  377. dialog_type = dialog_data->type;
  378. dialog = NULL;
  379. if (!ignoreCache)
  380. {
  381. Dialog * availableDialog;
  382. availableDialog = class_set[dialog_type].dialog_list;
  383. availableDialogCount = 0;
  384. /*
  385. * In addition to looking for an available dialog in the cache to use,
  386. * we also want to count up the number of unused dialogs in the cache.
  387. * This lets us know it we need to restart the timer, to again build
  388. * up the cache.
  389. */
  390. while (availableDialog != NULL)
  391. {
  392. if (availableDialog->in_use == False)
  393. {
  394. if (dialog == NULL)
  395. dialog = availableDialog;
  396. else
  397. availableDialogCount++;
  398. }
  399. availableDialog = availableDialog->next;
  400. }
  401. }
  402. if (dialog == NULL)
  403. {
  404. dialog = (Dialog *) XtMalloc (sizeof (Dialog));
  405. (*(class_set[dialog_type].class->create))
  406. (XtDisplay (encap_parent_shell), encap_parent_shell,
  407. &(dialog->dialog_widget), &dialog->dialog);
  408. /* if this is a File Manager view we want to update the headers
  409. * (i.e icon_path, current_directory, status_line), now so that they
  410. * don't get managed up front. This is to make the Application
  411. * Manager (toolbox) happy.
  412. */
  413. if(dialog_type == file_mgr_dialog)
  414. UpdateHeaders(dialog->dialog, dialog_data->data, False);
  415. /* Add the change and close callbacks into the dialog */
  416. if (class_set[dialog_type].class->install_change_callback)
  417. (*(class_set[dialog_type].class->install_change_callback))
  418. (dialog->dialog, DataChangeCallback, (XtPointer)dialog);
  419. if (class_set[dialog_type].class->install_close_callback)
  420. (*(class_set[dialog_type].class->install_close_callback))
  421. (dialog->dialog, DataCloseCallback, (XtPointer)dialog);
  422. dialog->next = class_set[dialog_type].dialog_list;
  423. class_set[dialog_type].dialog_list = dialog;
  424. }
  425. else
  426. {
  427. if(dialog_type == mod_attr_dialog)
  428. {
  429. ModAttrRec *mr = (ModAttrRec *)dialog->dialog;
  430. ResetFlag(NULL,mr->ok);
  431. ResetFlag(NULL,mr->cancel);
  432. }
  433. else if(dialog_type == filter_dialog)
  434. {
  435. FilterRec *fr = (FilterRec *)dialog->dialog;
  436. ResetFlag(NULL,fr->ok);
  437. ResetFlag(NULL,fr->close);
  438. }
  439. }
  440. if ((!ignoreCache) && (class_set[dialog_type].cache) &&
  441. (availableDialogCount < 1) && (timerState == TIMER_IDLE_STATE))
  442. {
  443. /*
  444. * We need to reset the cache building timer, so that it gets kicked
  445. * off quickly, instead of after the longer idle delay.
  446. */
  447. if (timerId)
  448. XtRemoveTimeOut(timerId);
  449. timerState = TIMER_ACTIVE_STATE;
  450. timerId = XtAppAddTimeOut(
  451. XtWidgetToApplicationContext(encap_parent_shell),
  452. activeTimeoutLength, (XtTimerCallbackProc) TimerEvent,
  453. (XtPointer) encap_parent_shell);
  454. }
  455. /*
  456. * Set pointer to top dialog data in child of the shell.
  457. * This is needed to get help to work.
  458. */
  459. if (top_rec == NULL)
  460. top_rec = dialog->dialog;
  461. XtSetArg(args[0], XmNuserData, top_rec);
  462. XtSetValues(dialog->dialog_widget, args, 1);
  463. /* Need to add the map callback in relation to the parent */
  464. if (class_set[dialog_type].class->map)
  465. {
  466. /*
  467. * The map_parent parameter gives us the ability to position
  468. * the dialog relative to a window which is not the transientFor
  469. * parent. This is used for the audio preview dialog.
  470. */
  471. if (map_parent == NULL)
  472. map_parent = parent;
  473. (*(class_set[dialog_type].class->map)) (map_parent, dialog->dialog);
  474. }
  475. /* Set the dialog structure fields to the parameter data. */
  476. dialog->in_use = True;
  477. dialog->dialog_data = dialog_data;
  478. dialog->change = change_proc;
  479. dialog->change_client_data = change_data;
  480. dialog->close = close_proc;
  481. dialog->close_client_data = close_data;
  482. instance_data = (DialogInstanceData *) dialog_data->data;
  483. /* If a special title has been specified, we need to set it now */
  484. if (title)
  485. {
  486. XtSetArg(args[0], XmNtitle, title);
  487. XtSetValues(XtParent(dialog->dialog_widget), args, 1);
  488. }
  489. /* If this is a top level shell, get it realized */
  490. if (XtIsSubclass (XtParent (dialog->dialog_widget),
  491. applicationShellWidgetClass))
  492. {
  493. if (XtIsRealized (XtParent (dialog->dialog_widget)) == False)
  494. {
  495. if (instance_data->displayed == True)
  496. {
  497. (void) sprintf (geometry, "=%dx%d+%d+%d",
  498. instance_data->width, instance_data->height,
  499. instance_data->x, instance_data->y);
  500. XtSetArg (args[0], XmNgeometry, geometry);
  501. XtSetValues (XtParent (dialog->dialog_widget), args, 1);
  502. }
  503. else if ((instance_data->width != 0) && (instance_data->height != 0))
  504. {
  505. n=0;
  506. XtSetArg (args[n], XmNwidth, instance_data->width); n++;
  507. XtSetArg (args[n], XmNheight, instance_data->height); n++;
  508. XtSetValues (XtParent (dialog->dialog_widget), args, n);
  509. }
  510. /* Toggle mappedWhenManaged to false */
  511. XtSetMappedWhenManaged(XtParent (dialog->dialog_widget), False);
  512. XtRealizeWidget (XtParent(dialog->dialog_widget));
  513. /* Set the proper workspaces if needed */
  514. _DtEncapSetWorkSpaceHints(XtParent(dialog->dialog_widget), workspaces);
  515. /* Set any application-specified class hints for the window */
  516. if (classHints)
  517. {
  518. XSetClassHint(XtDisplay(dialog->dialog_widget),
  519. XtWindow(XtParent(dialog->dialog_widget)),
  520. classHints);
  521. }
  522. /* Set the iconify state */
  523. SetIconifyState(XtParent(dialog->dialog_widget), iconify_state);
  524. /* Map the window */
  525. XtSetMappedWhenManaged(XtParent (dialog->dialog_widget), True);
  526. XtPopup (XtParent (dialog->dialog_widget), XtGrabNone);
  527. XSync(XtDisplay(dialog->dialog_widget), False);
  528. }
  529. else
  530. {
  531. if (instance_data->displayed == True)
  532. {
  533. WMShellWidget wm = (WMShellWidget)XtParent(dialog->dialog_widget);
  534. wm->wm.size_hints.flags |= USPosition;
  535. XtSetArg (args[0], XmNx, instance_data->x);
  536. XtSetArg (args[1], XmNy, instance_data->y);
  537. XtSetArg (args[2], XmNwidth, instance_data->width);
  538. XtSetArg (args[3], XmNheight, instance_data->height);
  539. XtSetValues (XtParent (dialog->dialog_widget), args, 4);
  540. }
  541. else if ((instance_data->width != 0) && (instance_data->height != 0))
  542. {
  543. n=0;
  544. XtSetArg (args[n], XmNwidth, instance_data->width); n++;
  545. XtSetArg (args[n], XmNheight, instance_data->height); n++;
  546. XtSetValues (XtParent (dialog->dialog_widget), args, n);
  547. }
  548. /* Set the proper workspaces if needed */
  549. _DtEncapSetWorkSpaceHints(XtParent(dialog->dialog_widget), workspaces);
  550. /* Set any application-specified class hints for the window */
  551. if (classHints)
  552. {
  553. XSetClassHint(XtDisplay(dialog->dialog_widget),
  554. XtWindow(XtParent(dialog->dialog_widget)),
  555. classHints);
  556. }
  557. /* Set the iconify state */
  558. SetIconifyState(XtParent(dialog->dialog_widget), iconify_state);
  559. /* Map the window */
  560. XtPopup (XtParent (dialog->dialog_widget), XtGrabNone);
  561. }
  562. }
  563. else
  564. {
  565. if (instance_data->displayed == True)
  566. {
  567. XtSetArg (args[0], XmNx, instance_data->x);
  568. XtSetArg (args[1], XmNy, instance_data->y);
  569. XtSetArg (args[2], XmNwidth, instance_data->width);
  570. XtSetArg (args[3], XmNheight, instance_data->height);
  571. XtSetArg (args[4], XmNdefaultPosition, False);
  572. XtSetValues (dialog->dialog_widget, args, 5);
  573. XtRealizeWidget (dialog->dialog_widget);
  574. }
  575. else
  576. {
  577. XtSetArg (args[0], XmNdefaultPosition, False);
  578. XtSetValues (dialog->dialog_widget, args, 1);
  579. XtRealizeWidget (dialog->dialog_widget);
  580. if (parent)
  581. {
  582. /* Position relative to the parent dialog */
  583. /*
  584. * Must be done after the set_values call, since the dialog
  585. * may get forced to a different size.
  586. */
  587. doParentRelativePositioning = True;
  588. }
  589. else
  590. {
  591. /* Center in the display */
  592. /*
  593. * Must be done after the set_values call, since the dialog
  594. * may get forced to a different size.
  595. */
  596. doCenter = True;
  597. }
  598. }
  599. /*
  600. * Dialogs with no controlling parent window, need to have their
  601. * own workspace perperty set, if some workspaces have been requested.
  602. */
  603. if ((parent == NULL) && workspaces)
  604. _DtEncapSetWorkSpaceHints(XtParent(dialog->dialog_widget), workspaces);
  605. }
  606. /* Set Values onto the dialog to set it to the correct data. */
  607. (*(class_set[dialog_data->type].class->set_values))
  608. (dialog->dialog, dialog_data->data);
  609. /*
  610. * These two adjustments MUST be done AFTER the dialog's SetValues()
  611. * procedure is called. This is due to the fact that the setvalues
  612. * may cause the dialog size to change, and since both of the following
  613. * positioning algorithms are dependent upon the dialog size, we want
  614. * to make sure that the correct size is used.
  615. */
  616. if (doCenter)
  617. {
  618. XtSetArg (args[0], XmNx,
  619. (Dimension)(WidthOfScreen(XtScreen(dialog->dialog_widget)) -
  620. dialog->dialog_widget->core.width) / (Dimension)2);
  621. XtSetArg (args[1], XmNy,
  622. (Dimension)(HeightOfScreen(XtScreen(dialog->dialog_widget)) -
  623. dialog->dialog_widget->core.height) / (Dimension)2);
  624. XtSetValues (dialog->dialog_widget, args, 2);
  625. }
  626. else if (doParentRelativePositioning)
  627. {
  628. XtSetArg (args[0], XmNx,
  629. parent->core.x +
  630. (Dimension)(parent->core.width - dialog->dialog_widget->core.width) / (Dimension)2);
  631. XtSetArg (args[1], XmNy,
  632. parent->core.y +
  633. (Dimension)(parent->core.height - dialog->dialog_widget->core.height) / (Dimension)2);
  634. XtSetValues (XtParent(dialog->dialog_widget), args, 2);
  635. }
  636. /* Fix up the transient-for windowing information so that */
  637. /* the window manager will shuffle and iconify as a group */
  638. if (parent != NULL)
  639. {
  640. if (XtIsRealized(parent))
  641. {
  642. XSetTransientForHint (XtDisplay (parent),
  643. XtWindow (XtParent (dialog->dialog_widget)),
  644. XtWindow (parent));
  645. }
  646. }
  647. else
  648. {
  649. if (!XtIsSubclass (XtParent (dialog->dialog_widget),
  650. applicationShellWidgetClass))
  651. {
  652. XSetTransientForHint (XtDisplay (encap_parent_shell),
  653. XtWindow (XtParent (dialog->dialog_widget)),
  654. XtWindow (encap_parent_shell));
  655. }
  656. }
  657. /* Display the dialogs, application shells are displayed above. */
  658. if (!(XtIsSubclass (XtParent (dialog->dialog_widget),
  659. applicationShellWidgetClass)))
  660. {
  661. XtManageChild (dialog->dialog_widget);
  662. }
  663. /* Set the dialog instance data to indicate that the dialog */
  664. /* is displayed. */
  665. ((DialogInstanceData *) (dialog_data->data))->displayed = True;
  666. /* Give the dialog a chance to set its focus widget, if necessary */
  667. if (class_set[dialog_data->type].class->set_focus)
  668. {
  669. (*(class_set[dialog_data->type].class->set_focus))
  670. (dialog->dialog, dialog_data->data);
  671. }
  672. XtAddEventHandler( XtParent( dialog->dialog_widget ),
  673. StructureNotifyMask,
  674. False,
  675. (XtEventHandler)DialogStructureNotifyHandler,
  676. NULL );
  677. }
  678. /************************************************************************
  679. *
  680. * _DtHideDialog
  681. * This function is used to undisplay a dialog.
  682. *
  683. ************************************************************************/
  684. void
  685. _DtHideDialog(
  686. DialogData *dialog_data,
  687. Boolean call_callbacks )
  688. {
  689. Dialog * dialog;
  690. DialogData * new_data;
  691. CorePart * core;
  692. int i;
  693. /* Find the dialog and then hide it. */
  694. dialog = class_set[dialog_data->type].dialog_list;
  695. while (dialog != NULL)
  696. {
  697. if ((dialog->dialog_data &&
  698. dialog->dialog_data == dialog_data) && dialog->in_use == True)
  699. {
  700. /* Free up any dialogs attached to the dialog widget */
  701. if(class_set[dialog_data->type].destroyPopups)
  702. {
  703. core = (CorePart *) (XtParent (dialog->dialog_widget));
  704. for (i = core->num_popups - 1; i >= 0; i--)
  705. XtDestroyWidget (core->popup_list[i]);
  706. }
  707. /* Get the dialog down, invoke the close callbacks, and */
  708. /* take it out of use. */
  709. if (XtIsSubclass (XtParent (dialog->dialog_widget),
  710. applicationShellWidgetClass))
  711. {
  712. ShellWidget shell_widget;
  713. /*
  714. * If we had been iconified, then our popped_up flag will
  715. * have been cleared by the vendor shell. When we call
  716. * XtPopdown(), it will see that we are no longer popped
  717. * up, and will not notify the window manager that our
  718. * icon should be removed; this can cause a subsequent
  719. * core dump if the user later tries to deiconify the window.
  720. * This fix should not be necessary once the toolkit is
  721. * fixed to properly track the shell's state.
  722. */
  723. shell_widget = (ShellWidget) XtParent(dialog->dialog_widget);
  724. shell_widget->shell.popped_up = True;
  725. XtPopdown ((Widget)shell_widget);
  726. }
  727. else
  728. {
  729. /*
  730. * The following is for the condition described above. However,
  731. * for a dialog shell, what happens it that the 'managed' flag
  732. * was set to 'False' when the windows were iconified (apparently
  733. * by the dialog shell), and when we tell the intrinsics to
  734. * really unmanage the child, it thinks it already has, so
  735. * nothing happens; as a result, the dialog shell is left with
  736. * its 'popped_up' flag set to 'True'. The next time we try
  737. * to post this dialog, the intrinsics think that it is already
  738. * up, so it does nothing.
  739. */
  740. dialog->dialog_widget->core.managed = True;
  741. XtUnmanageChild (dialog->dialog_widget);
  742. }
  743. /* Set the dialog data to hidden */
  744. ((DialogInstanceData *) (dialog->dialog_data->data))->displayed = False;
  745. if (call_callbacks && dialog->close)
  746. {
  747. new_data = (DialogData *) XtMalloc (sizeof (DialogData));
  748. new_data->type = dialog->dialog_data->type;
  749. new_data->data = NULL;
  750. if (class_set[new_data->type].class->get_values)
  751. {
  752. new_data->data =
  753. (*(class_set[new_data->type].class->get_values))(dialog->dialog);
  754. }
  755. dialog->in_use = False;
  756. if (new_data->data)
  757. ((DialogInstanceData *) (new_data->data))->displayed = False;
  758. (*(dialog->close))
  759. (dialog->close_client_data, dialog->dialog_data, new_data);
  760. }
  761. else
  762. {
  763. dialog->in_use = False;
  764. ((DialogInstanceData *) (dialog->dialog_data->data))->displayed = False;
  765. }
  766. break;
  767. }
  768. dialog = dialog->next;
  769. }
  770. }
  771. /************************************************************************
  772. *
  773. * _DtGetDialogShell
  774. * This function is used return the shell widget of a dialog that
  775. * is currently displayed.
  776. *
  777. ************************************************************************/
  778. Widget
  779. _DtGetDialogShell(
  780. DialogData *dialog_data )
  781. {
  782. Dialog * dialog;
  783. /* Find the dialog and then return the shell. */
  784. dialog = class_set[dialog_data->type].dialog_list;
  785. while (dialog != NULL)
  786. {
  787. if (dialog->dialog_data == dialog_data)
  788. return (dialog->dialog_widget);
  789. else
  790. dialog = dialog->next;
  791. }
  792. return (NULL);
  793. }
  794. /************************************************************************
  795. *
  796. * _DtGetDialogInstance
  797. * This function is used return the dialog instance structure
  798. * of a currently in use dialog.
  799. *
  800. ************************************************************************/
  801. XtPointer
  802. _DtGetDialogInstance(
  803. DialogData *dialog_data )
  804. {
  805. Dialog * dialog;
  806. /* Find the dialog and then return the instance */
  807. dialog = class_set[dialog_data->type].dialog_list;
  808. while (dialog != NULL)
  809. {
  810. if (dialog->dialog_data && dialog->dialog_data == dialog_data)
  811. return (dialog->dialog);
  812. else
  813. dialog = dialog->next;
  814. }
  815. return (NULL);
  816. }
  817. /************************************************************************
  818. *
  819. * _DtGetInstanceData
  820. * This function is used return the dialog data structure contained
  821. * within the cache structure referenced by instance.
  822. *
  823. ************************************************************************/
  824. DialogData *
  825. _DtGetInstanceData(
  826. XtPointer instance )
  827. {
  828. int i;
  829. Dialog * dialog;
  830. /* Find the dialog and then return the instance */
  831. for (i = 0; i < num_classes; i++)
  832. {
  833. dialog = class_set[i].dialog_list;
  834. while (dialog != NULL)
  835. {
  836. if (dialog->dialog == instance && dialog->in_use == True)
  837. return (dialog->dialog_data);
  838. else
  839. dialog = dialog->next;
  840. }
  841. }
  842. return (NULL);
  843. }
  844. /************************************************************************
  845. *
  846. * _DtIsDialogShowing
  847. * This function is used return a boolean indicating whether the
  848. * a dialog is displayed which contains the dialog data.
  849. * of a currently in use dialog.
  850. *
  851. ************************************************************************/
  852. Boolean
  853. _DtIsDialogShowing(
  854. DialogData *dialog_data )
  855. {
  856. Dialog * dialog;
  857. /* Find the dialog and then return the instance */
  858. dialog = class_set[dialog_data->type].dialog_list;
  859. while (dialog != NULL)
  860. {
  861. if (dialog->in_use && dialog->dialog_data == dialog_data)
  862. return (True);
  863. else
  864. dialog = dialog->next;
  865. }
  866. return (False);
  867. }
  868. /************************************************************************
  869. *
  870. * _DtWriteDialogData
  871. * This function is used to write, as resources, the data
  872. * for a dialog contained in dialog_data to the open file fd.
  873. *
  874. ************************************************************************/
  875. void
  876. _DtWriteDialogData(
  877. DialogData *dialog_data,
  878. int fd,
  879. char **name_list )
  880. {
  881. if (dialog_data != NULL)
  882. (*(class_set[dialog_data->type].class->write_resource_values))
  883. (dialog_data, fd, name_list);
  884. }
  885. /************************************************************************
  886. *
  887. * _DtFreeDialogData
  888. * This function is used to free up the data space allocated
  889. * by a dialog.
  890. *
  891. ************************************************************************/
  892. void
  893. _DtFreeDialogData(
  894. DialogData *dialog_data )
  895. {
  896. if (dialog_data != NULL)
  897. {
  898. (*(class_set[dialog_data->type].class->free_values)) (dialog_data->data);
  899. XtFree ((char *) dialog_data);
  900. dialog_data = NULL;
  901. }
  902. }
  903. /************************************************************************
  904. *
  905. * _DtDialogGetResources
  906. * This function accesses data_base to extract the resource set
  907. * described by the resoruces array. Resources values are
  908. * converted to the proper type and defaults are used if not
  909. * data is found in the resource data base.
  910. *
  911. ************************************************************************/
  912. void
  913. _DtDialogGetResources(
  914. XrmDatabase database,
  915. char **name_list,
  916. char *dialog_name,
  917. char *base,
  918. DialogResource *resources,
  919. int resource_count )
  920. {
  921. XrmName xrmName[MAX_NAME_LIST_SIZE];
  922. XrmQuark stringQuark;
  923. int nameCount;
  924. int i;
  925. /* Build the quarkified name list from name_list and dialog_name */
  926. /* provided by the calling procedure. */
  927. nameCount = 0;
  928. if (name_list != NULL)
  929. {
  930. while (name_list[nameCount] != NULL)
  931. {
  932. xrmName[nameCount] = XrmStringToQuark (name_list[nameCount]);
  933. nameCount++;
  934. }
  935. }
  936. if (dialog_name)
  937. xrmName[nameCount] = XrmStringToQuark (dialog_name);
  938. else
  939. nameCount--;
  940. xrmName[nameCount + 2] = 0;
  941. stringQuark = XrmStringToQuark (XmRString);
  942. /* Load the common dialog size/position resources */
  943. for (i = 0; i < resource_count; i++)
  944. {
  945. IntDialogGetResources(database, base, resources + i, xrmName, nameCount,
  946. stringQuark);
  947. }
  948. /*
  949. * Load the dialog specific resources. If no value found, use the default.
  950. */
  951. for (i = 0; i < commonResourceCount; i++)
  952. {
  953. IntDialogGetResources(database, base, commonResources + i, xrmName,
  954. nameCount, stringQuark);
  955. }
  956. }
  957. /*
  958. * This internal function does the real work of loading a single resource
  959. * value. If the value is not found in the resource database, then the
  960. * specified default value is used.
  961. */
  962. static void
  963. IntDialogGetResources(
  964. XrmDatabase database,
  965. char *base,
  966. DialogResource *resource,
  967. XrmName *xrmName,
  968. int nameCount,
  969. XrmQuark stringQuark )
  970. {
  971. XrmRepresentation repType;
  972. XrmValue value;
  973. XrmValue convertedValue;
  974. char charVal;
  975. short shortVal;
  976. int intVal;
  977. long longVal;
  978. {
  979. xrmName[nameCount + 1] = XrmStringToQuark (resource->name);
  980. if (XrmQGetResource (database, xrmName, xrmName, &repType, &value))
  981. {
  982. if (repType == stringQuark)
  983. if (strcmp (resource->type, XmRString) != 0)
  984. {
  985. XtConvert (encap_parent_shell, XmRString, &value,
  986. resource->type, &convertedValue);
  987. }
  988. else
  989. {
  990. *((char **)(base + resource->offset)) = (char *)value.addr;
  991. return;
  992. }
  993. else
  994. convertedValue.addr = NULL;
  995. }
  996. else
  997. convertedValue.addr = NULL;
  998. /* Set the converted value address pointer and value to */
  999. /* the proper default value if the addr is NULL. */
  1000. if (convertedValue.addr == NULL)
  1001. {
  1002. if (resource->size == sizeof(char))
  1003. {
  1004. charVal = (char)(XtArgVal)resource->default_value;
  1005. convertedValue.addr = (caddr_t) &charVal;
  1006. }
  1007. else if (resource->size == sizeof(short))
  1008. {
  1009. shortVal = (short)(XtArgVal)resource->default_value;
  1010. convertedValue.addr = (caddr_t) &shortVal;
  1011. }
  1012. else if (resource->size == sizeof(int))
  1013. {
  1014. intVal = (int)(XtArgVal)resource->default_value;
  1015. convertedValue.addr = (caddr_t) &intVal;
  1016. }
  1017. else
  1018. {
  1019. longVal = (long)(XtArgVal)resource->default_value;
  1020. convertedValue.addr = (caddr_t) &longVal;
  1021. }
  1022. }
  1023. /* Stuff the converted value into the calling functions */
  1024. /* structure according to the size of the piece of data. */
  1025. if (resource->size == sizeof(char))
  1026. *((char *)(base + resource->offset)) = *((char *)convertedValue.addr);
  1027. else if (resource->size == sizeof(short))
  1028. *((short *)(base + resource->offset))= *((short *)convertedValue.addr);
  1029. else if (resource->size == sizeof(int))
  1030. *((int *)(base + resource->offset))= *((int *)convertedValue.addr);
  1031. else
  1032. *((long *)(base + resource->offset)) = *((long *)convertedValue.addr);
  1033. }
  1034. }
  1035. /************************************************************************
  1036. *
  1037. * _DtDialogPutResources
  1038. * This function writes a resource set to a file.
  1039. *
  1040. ************************************************************************/
  1041. void
  1042. _DtDialogPutResources(
  1043. int fd,
  1044. char **nameList,
  1045. char *dialogName,
  1046. char *base,
  1047. DialogResource *resources,
  1048. int resourceCount )
  1049. {
  1050. int i;
  1051. DialogInstanceData * dialogInstanceData;
  1052. /*
  1053. * Write out the common dialog size/position resources, only if the
  1054. * dialog is currently displayed.
  1055. */
  1056. dialogInstanceData = (DialogInstanceData *)base;
  1057. if (dialogInstanceData->displayed)
  1058. {
  1059. for (i = 0; i < commonResourceCount; i++)
  1060. {
  1061. IntDialogPutResources(fd, nameList, dialogName, base,
  1062. commonResources + i);
  1063. }
  1064. }
  1065. /*
  1066. * Loop through the dialog specific resources, write the name list and
  1067. * resource name.
  1068. */
  1069. for (i = 0; i < resourceCount; i++)
  1070. IntDialogPutResources( fd, nameList, dialogName, base, resources + i);
  1071. }
  1072. /*
  1073. * This internal function does the real work involved in writing a single
  1074. * resource out to a session file.
  1075. */
  1076. static void
  1077. IntDialogPutResources(
  1078. int fd,
  1079. char **nameList,
  1080. char *dialogName,
  1081. char *base,
  1082. DialogResource *resource )
  1083. {
  1084. static char outBuf[MAX_RESOURCE_LENGTH];
  1085. int nameCount;
  1086. outBuf[0] = '\0';
  1087. (void) strcat (outBuf, "*");
  1088. nameCount = 0;
  1089. if (nameList != NULL)
  1090. {
  1091. while (nameList[nameCount] != NULL)
  1092. {
  1093. (void) strcat (outBuf, nameList[nameCount]);
  1094. (void) strcat (outBuf, ".");
  1095. nameCount++;
  1096. }
  1097. }
  1098. if (dialogName != NULL)
  1099. {
  1100. (void) strcat (outBuf, dialogName);
  1101. (void) strcat (outBuf, ".");
  1102. }
  1103. (void) strcat (outBuf, resource->name);
  1104. (void) strcat (outBuf, ": ");
  1105. (*(resource->write_resource))
  1106. (fd, (XtPointer) (base + resource->offset), outBuf);
  1107. }
  1108. /************************************************************************
  1109. ************************************************************************
  1110. *
  1111. * Internal functions
  1112. *
  1113. ************************************************************************
  1114. ************************************************************************/
  1115. /************************************************************************
  1116. *
  1117. * _DtEncapSetWorkSpaceHints
  1118. * This function sets a given shell to a given set(s) of
  1119. * workspaces.
  1120. *
  1121. ************************************************************************/
  1122. void
  1123. _DtEncapSetWorkSpaceHints(
  1124. Widget shell,
  1125. char *workspaces )
  1126. {
  1127. char * ptr;
  1128. Atom * workspace_atoms = NULL;
  1129. int num_workspaces=0;
  1130. if (workspaces)
  1131. {
  1132. do
  1133. {
  1134. ptr = DtStrchr (workspaces, '*');
  1135. if (ptr != NULL) *ptr = '\0';
  1136. workspace_atoms = (Atom *) XtRealloc ((char *)workspace_atoms,
  1137. sizeof (Atom) * (num_workspaces + 1));
  1138. workspace_atoms[num_workspaces] =
  1139. XmInternAtom (XtDisplay(shell), workspaces, True);
  1140. num_workspaces++;
  1141. if (ptr != NULL)
  1142. {
  1143. *ptr = '*';
  1144. workspaces = ptr + 1;
  1145. }
  1146. } while (ptr != NULL);
  1147. DtWsmSetWorkspacesOccupied (XtDisplay(shell), XtWindow (shell), workspace_atoms,
  1148. num_workspaces);
  1149. XtFree ((char *) workspace_atoms);
  1150. workspace_atoms = NULL;
  1151. }
  1152. else
  1153. {
  1154. Window rootWindow;
  1155. Atom pCurrent;
  1156. Screen *currentScreen;
  1157. int screen;
  1158. char *workspace_name;
  1159. /*
  1160. * Since no specific workspaces were specified, we will force the
  1161. * dialog to the current workspace.
  1162. */
  1163. screen = XDefaultScreen(XtDisplay(shell));
  1164. currentScreen = XScreenOfDisplay(XtDisplay(shell), screen);
  1165. rootWindow = RootWindowOfScreen(currentScreen);
  1166. if(DtWsmGetCurrentWorkspace(XtDisplay(shell), rootWindow, &pCurrent) ==
  1167. Success)
  1168. {
  1169. DtWsmSetWorkspacesOccupied(XtDisplay(shell), XtWindow (shell), &pCurrent, 1);
  1170. }
  1171. }
  1172. }
  1173. /************************************************************************
  1174. *
  1175. * SetIconifyState
  1176. * This function sets a given shell to a given iconify state.
  1177. * (e.g. Mapped or iconified)
  1178. *
  1179. ************************************************************************/
  1180. static void
  1181. SetIconifyState(
  1182. Widget shell,
  1183. Boolean iconify )
  1184. {
  1185. Arg args[1];
  1186. XWMHints *wmhints;
  1187. if (iconify)
  1188. {
  1189. /* add the iconify hint to the current shell */
  1190. XtSetArg(args[0], XmNinitialState, IconicState);
  1191. XtSetValues(shell, args, 1);
  1192. }
  1193. else
  1194. {
  1195. /* Remove the iconify hint from the current shell */
  1196. wmhints = XGetWMHints(XtDisplay(shell), XtWindow(shell));
  1197. wmhints->flags |= IconWindowHint;
  1198. wmhints->initial_state = NormalState;
  1199. XSetWMHints(XtDisplay(shell), XtWindow(shell), wmhints);
  1200. XFree(wmhints);
  1201. }
  1202. }
  1203. /************************************************************************
  1204. *
  1205. * DataChangeCallback
  1206. * This callback is invoked from a dialog upon an action on the
  1207. * dialog that means that the data within the dialog has been
  1208. * changed.
  1209. *
  1210. ************************************************************************/
  1211. /*ARGSUSED*/
  1212. static void
  1213. DataChangeCallback(
  1214. Widget widget,
  1215. XtPointer client_data,
  1216. XtPointer call_data )
  1217. {
  1218. Dialog * dialog = (Dialog *) client_data;
  1219. DialogData * new_data;
  1220. new_data = (DialogData *) XtMalloc (sizeof (DialogData));
  1221. new_data->type = dialog->dialog_data->type;
  1222. new_data->data = NULL;
  1223. if (class_set[new_data->type].class->get_values)
  1224. {
  1225. new_data->data = (*(class_set[new_data->type].class->get_values))
  1226. (dialog->dialog);
  1227. }
  1228. if (dialog->change)
  1229. (*(dialog->change))
  1230. (dialog->change_client_data, dialog->dialog_data, new_data, call_data);
  1231. }
  1232. /************************************************************************
  1233. *
  1234. * DataCloseCallback
  1235. * This callback is invoked from a dialog upon an action on the
  1236. * dialog that means the dialog has been closed.
  1237. *
  1238. ************************************************************************/
  1239. /*ARGSUSED*/
  1240. static void
  1241. DataCloseCallback(
  1242. Widget widget,
  1243. XtPointer client_data,
  1244. XtPointer call_data )
  1245. {
  1246. Dialog * dialog = (Dialog *) client_data;
  1247. if(RecheckFlag(NULL,widget)) /* cancel flag already set, just return */
  1248. return;
  1249. _DtHideDialog (dialog->dialog_data, True);
  1250. }
  1251. /************************************************************************
  1252. *
  1253. * TimerEvent
  1254. * This action function is called upon the encapsulations
  1255. * timeout going off. Its function is to precreate and destroy
  1256. * extra dialogs.
  1257. *
  1258. ************************************************************************/
  1259. /* ARGSUSED */
  1260. static void
  1261. TimerEvent(
  1262. Widget widget,
  1263. XtIntervalId *id )
  1264. {
  1265. int i;
  1266. Dialog * dialog;
  1267. Dialog * prev_dialog;
  1268. int count;
  1269. /* First pass through the dialog set to see if any */
  1270. /* need to be created. This is based on having 0 */
  1271. /* not in use dialogs of each type. */
  1272. for (i = 0; i < num_classes; i++)
  1273. {
  1274. dialog = class_set[i].dialog_list;
  1275. /* Only attempt to cache dialogs requesting this feature */
  1276. if (!class_set[i].cache)
  1277. continue;
  1278. while (dialog != NULL)
  1279. if (dialog->in_use == False)
  1280. break;
  1281. else
  1282. dialog = dialog->next;
  1283. if (dialog == NULL)
  1284. {
  1285. dialog = (Dialog *) XtMalloc (sizeof (Dialog));
  1286. (*(class_set[i].class->create))
  1287. (XtDisplay (encap_parent_shell), encap_parent_shell,
  1288. &(dialog->dialog_widget), &dialog->dialog);
  1289. /* Add the change and close callbacks into the dialog */
  1290. if (class_set[i].class->install_change_callback)
  1291. (*(class_set[i].class->install_change_callback))
  1292. (dialog->dialog, DataChangeCallback, (XtPointer)dialog);
  1293. if (class_set[i].class->install_close_callback)
  1294. (*(class_set[i].class->install_close_callback))
  1295. (dialog->dialog, DataCloseCallback, (XtPointer)dialog);
  1296. dialog->next = class_set[i].dialog_list;
  1297. class_set[i].dialog_list = dialog;
  1298. dialog->in_use = False;
  1299. timerState = TIMER_ACTIVE_STATE;
  1300. timerId = XtAppAddTimeOut(XtWidgetToApplicationContext(widget),
  1301. activeTimeoutLength,
  1302. (XtTimerCallbackProc) TimerEvent,
  1303. (XtPointer) widget);
  1304. return;
  1305. }
  1306. }
  1307. /* Pass through the dialog set to see if any need to be destroyed */
  1308. /* This is based on having more than 1 not in use dialog of a type. */
  1309. for (i = 0; i < num_classes; i++)
  1310. {
  1311. dialog = class_set[i].dialog_list;
  1312. count = 0;
  1313. while (dialog != NULL)
  1314. {
  1315. if (dialog->in_use == False)
  1316. count++;
  1317. dialog = dialog->next;
  1318. }
  1319. if (count > 1)
  1320. {
  1321. dialog = class_set[i].dialog_list;
  1322. if (dialog->in_use == False)
  1323. class_set[i].dialog_list = dialog->next;
  1324. else
  1325. {
  1326. prev_dialog = class_set[i].dialog_list;
  1327. dialog = dialog->next;
  1328. while (dialog->in_use == True)
  1329. {
  1330. prev_dialog = dialog;
  1331. dialog = dialog->next;
  1332. }
  1333. prev_dialog->next = dialog->next;
  1334. }
  1335. (*(class_set[i].class->destroy)) (dialog->dialog);
  1336. XtFree ((char *) dialog);
  1337. dialog = NULL;
  1338. break;
  1339. }
  1340. }
  1341. timerState = TIMER_IDLE_STATE;
  1342. timerId = XtAppAddTimeOut(XtWidgetToApplicationContext(widget),
  1343. idleTimeoutLength,
  1344. (XtTimerCallbackProc)TimerEvent,
  1345. (XtPointer)widget);
  1346. }
  1347. /************************************************************************
  1348. ************************************************************************
  1349. *
  1350. * Externed Type to String Converters and writers
  1351. *
  1352. ************************************************************************
  1353. ************************************************************************/
  1354. void
  1355. _DtIntToString(
  1356. int fd,
  1357. int *value,
  1358. char *out_buf )
  1359. {
  1360. (void) sprintf (resourceBuf, "%d", *value);
  1361. _DtStringToString( fd, &resourceBuf, out_buf );
  1362. }
  1363. void
  1364. _DtShortToString(
  1365. int fd,
  1366. short *value,
  1367. char *out_buf )
  1368. {
  1369. (void) sprintf (resourceBuf, "%d", *value);
  1370. _DtStringToString( fd, &resourceBuf, out_buf );
  1371. }
  1372. void
  1373. _DtPositionToString(
  1374. int fd,
  1375. Position *value,
  1376. char *out_buf )
  1377. {
  1378. (void) sprintf (resourceBuf, "%d", *value);
  1379. _DtStringToString( fd, &resourceBuf, out_buf );
  1380. }
  1381. void
  1382. _DtDimensionToString(
  1383. int fd,
  1384. Dimension *value,
  1385. char *out_buf )
  1386. {
  1387. (void) sprintf (resourceBuf, "%d", *value);
  1388. _DtStringToString( fd, &resourceBuf, out_buf );
  1389. }
  1390. void
  1391. _DtBooleanToString(
  1392. int fd,
  1393. Boolean *value,
  1394. char *out_buf )
  1395. {
  1396. char * buf;
  1397. if (*value == True)
  1398. buf = "True";
  1399. else
  1400. buf = "False";
  1401. _DtStringToString( fd, (char **)&buf, out_buf );
  1402. }
  1403. void
  1404. _DtXmStringToString(
  1405. int fd,
  1406. XmString *value,
  1407. char *out_buf )
  1408. {
  1409. char *out_value = NULL;
  1410. if (*value != NULL)
  1411. {
  1412. out_value = (char *) _XmStringUngenerate(*value, XmFONTLIST_DEFAULT_TAG,
  1413. XmCHARSET_TEXT, XmCHARSET_TEXT);
  1414. if ( out_value != NULL)
  1415. {
  1416. if (strlen (out_value) != 0)
  1417. {
  1418. (void) write (fd, out_value, strlen (out_value));
  1419. _DtStringToString( fd, &out_value, out_buf );
  1420. XtFree ((char *) out_value);
  1421. }
  1422. }
  1423. }
  1424. }
  1425. void
  1426. _DtXmStringTableToString(
  1427. int fd,
  1428. XmStringTable *value,
  1429. char *out_buf )
  1430. {
  1431. int i;
  1432. char *out_value = NULL;
  1433. Boolean first = True;
  1434. if ((value != NULL) && (*value != NULL))
  1435. {
  1436. i = 0;
  1437. while ((*value)[i] != NULL)
  1438. {
  1439. out_value = (char *)_XmStringUngenerate((*value)[i],
  1440. XmFONTLIST_DEFAULT_TAG,
  1441. XmCHARSET_TEXT, XmCHARSET_TEXT);
  1442. if ( out_value != NULL)
  1443. {
  1444. if (first)
  1445. {
  1446. (void) write (fd, out_buf, strlen (out_buf));
  1447. first = False;
  1448. }
  1449. else
  1450. (void) write (fd, ", ", strlen (", "));
  1451. (void) write (fd, out_value, strlen (out_value));
  1452. XtFree ((char *) out_value);
  1453. out_value = NULL;
  1454. }
  1455. i++;
  1456. }
  1457. if (first == False)
  1458. (void) write (fd, "\n", strlen ("\n"));
  1459. }
  1460. }
  1461. void
  1462. _DtStringToString(
  1463. int fd,
  1464. char **value,
  1465. char *out_buf )
  1466. {
  1467. if (*value == NULL || strlen (*value) == 0)
  1468. ;
  1469. else
  1470. {
  1471. (void) write (fd, out_buf, strlen (out_buf));
  1472. (void) write (fd, *value, strlen (*value));
  1473. (void) write (fd, "\n", strlen ("\n"));
  1474. }
  1475. }
  1476. /*
  1477. * _DtChildPosition:
  1478. * Choose a position for a popup window ("child") so that the main
  1479. * window ("parent") is not obscured. The child will be positioned
  1480. * to the right, below, left, or above the parent, depending on where
  1481. * there is the most space.
  1482. */
  1483. void
  1484. _DtChildPosition(
  1485. Widget w,
  1486. Widget parent,
  1487. Position *newX,
  1488. Position *newY)
  1489. {
  1490. Position pY, pX;
  1491. XmVendorShellExtObject vendorExt;
  1492. XmWidgetExtData extData;
  1493. int xOffset, yOffset;
  1494. int pHeight, myHeight, sHeight;
  1495. int pWidth, myWidth, sWidth;
  1496. enum { posRight, posBelow, posLeft, posAbove } pos;
  1497. int space;
  1498. int xOrg=0, yOrg=0; /* Xinerama screen origin */
  1499. /* get x, y offsets for the parent's window frame */
  1500. extData = _XmGetWidgetExtData(parent, XmSHELL_EXTENSION);
  1501. if (extData)
  1502. {
  1503. vendorExt = (XmVendorShellExtObject)extData->widget;
  1504. xOffset = vendorExt->vendor.xOffset;
  1505. yOffset = vendorExt->vendor.yOffset;
  1506. }
  1507. else
  1508. xOffset = yOffset = 0;
  1509. #ifdef USE_XINERAMA
  1510. if(!GetXineramaScreenDimensions(parent,&xOrg,&yOrg,&sWidth,&sHeight)){
  1511. sHeight = HeightOfScreen(XtScreen(parent));
  1512. sWidth = WidthOfScreen(XtScreen(parent));
  1513. }
  1514. #else
  1515. /* get size/position of screen, parent, and widget */
  1516. sHeight = HeightOfScreen(XtScreen(parent));
  1517. sWidth = WidthOfScreen(XtScreen(parent));
  1518. #endif /* USE_XINERAMA */
  1519. pX = XtX(parent) - xOffset - xOrg;
  1520. pY = XtY(parent) - yOffset - yOrg;
  1521. pHeight = XtHeight(parent) + yOffset + xOffset;
  1522. pWidth = XtWidth(parent) + 2*xOffset;
  1523. myHeight = XtHeight(w) + yOffset + xOffset;
  1524. myWidth = XtWidth(w) + 2*xOffset;
  1525. /*
  1526. * Determine how much space would be left if the child was positioned
  1527. * to the right, below, left, or above the parent. Choose the child
  1528. * positioning so that the maximum space is left.
  1529. */
  1530. pos = posRight;
  1531. space = sWidth - (pX + pWidth + myWidth);
  1532. if (sHeight - (pY + pHeight + myHeight) > space)
  1533. {
  1534. pos = posBelow;
  1535. space = sHeight - (pY + pHeight + myHeight);
  1536. }
  1537. if (pX - myWidth > space)
  1538. {
  1539. pos = posLeft;
  1540. space = pX - myWidth;
  1541. }
  1542. if (pY - myHeight > space)
  1543. {
  1544. pos = posAbove;
  1545. space = pY - myHeight;
  1546. }
  1547. /* Given relative positioning, determine x, y coordinates for the child */
  1548. switch (pos)
  1549. {
  1550. case posRight:
  1551. *newX = pX + pWidth + 5;
  1552. *newY = pY + (pHeight - myHeight)/2;
  1553. break;
  1554. case posBelow:
  1555. *newX = pX + (pWidth - myWidth)/2;
  1556. *newY = pY + pHeight + 5;
  1557. break;
  1558. case posLeft:
  1559. *newX = pX - myWidth - 5;
  1560. *newY = pY + (pHeight - myHeight)/2;
  1561. break;
  1562. case posAbove:
  1563. *newX = pX + (pWidth - myWidth)/2;
  1564. *newY = pY - myHeight - 5;
  1565. break;
  1566. }
  1567. /*
  1568. * The above calculations may put the dialog offscreen so one
  1569. * last check must be made. One way this can happen is if the
  1570. * parent has been resized to fill almost the entire screen.
  1571. * This can also happen if the parent has been maximized
  1572. * and the window manager has its 'positionOnScreen' resource
  1573. * set to False.
  1574. */
  1575. if ((*newX >= (sWidth - 10)) || (*newX < 0))
  1576. *newX = sWidth - myWidth + 5;
  1577. if ((*newY >= (sHeight - 10)) || (*newY < 0))
  1578. *newY = (sHeight - myHeight) / 2;
  1579. *newX+=xOrg;
  1580. *newY+=yOrg;
  1581. }
  1582. /* ARGSUSED */
  1583. void
  1584. _DtmapCB(
  1585. Widget w,
  1586. XtPointer client_data,
  1587. XtPointer call_data )
  1588. {
  1589. Arg args[2];
  1590. Widget parent;
  1591. Position newX, newY;
  1592. parent = (Widget)client_data;
  1593. if (parent)
  1594. {
  1595. _DtChildPosition(w, parent, &newX, &newY);
  1596. XtSetArg(args[0], XmNx, newX);
  1597. XtSetArg(args[1], XmNy, newY);
  1598. XtSetValues(w, args, 2);
  1599. }
  1600. }
  1601. /************************************************************************
  1602. *
  1603. * _DtBuildDialog
  1604. * This functions is used to build an instance of a dialog with
  1605. * the provided data but not display it. The functions and data
  1606. * to be set back to the application upon change or close of the
  1607. * dialog is also provided as parameters.
  1608. *
  1609. ************************************************************************/
  1610. void
  1611. _DtBuildDialog(
  1612. Widget parent,
  1613. Widget map_parent,
  1614. XtPointer top_rec,
  1615. DialogData *dialog_data,
  1616. DialogChangedProc change_proc,
  1617. XtPointer change_data,
  1618. DialogClosedProc close_proc,
  1619. XtPointer close_data,
  1620. char *workspaces,
  1621. Boolean iconify_state,
  1622. Boolean ignoreCache,
  1623. char * title,
  1624. XClassHint * classHints )
  1625. {
  1626. Dialog * dialog;
  1627. int dialog_type, n;
  1628. DialogInstanceData * instance_data;
  1629. char geometry[40];
  1630. Arg args[5];
  1631. Boolean doCenter = False;
  1632. Boolean doParentRelativePositioning = False;
  1633. int availableDialogCount;
  1634. /* See if there is a cached, unused dialog of the correct type. */
  1635. dialog_type = dialog_data->type;
  1636. dialog = NULL;
  1637. if (!ignoreCache)
  1638. {
  1639. Dialog * availableDialog;
  1640. availableDialog = class_set[dialog_type].dialog_list;
  1641. availableDialogCount = 0;
  1642. /*
  1643. * In addition to looking for an available dialog in the cache to use,
  1644. * we also want to count up the number of unused dialogs in the cache.
  1645. * This lets us know it we need to restart the timer, to again build
  1646. * up the cache.
  1647. */
  1648. while (availableDialog != NULL)
  1649. {
  1650. if (availableDialog->in_use == False)
  1651. {
  1652. if (dialog == NULL)
  1653. dialog = availableDialog;
  1654. else
  1655. availableDialogCount++;
  1656. }
  1657. availableDialog = availableDialog->next;
  1658. }
  1659. }
  1660. if (dialog == NULL)
  1661. {
  1662. dialog = (Dialog *) XtMalloc (sizeof (Dialog));
  1663. (*(class_set[dialog_type].class->create))
  1664. (XtDisplay (encap_parent_shell), encap_parent_shell,
  1665. &(dialog->dialog_widget), &dialog->dialog);
  1666. /* Add the change and close callbacks into the dialog */
  1667. if (class_set[dialog_type].class->install_change_callback)
  1668. (*(class_set[dialog_type].class->install_change_callback))
  1669. (dialog->dialog, DataChangeCallback, (XtPointer)dialog);
  1670. if (class_set[dialog_type].class->install_close_callback)
  1671. (*(class_set[dialog_type].class->install_close_callback))
  1672. (dialog->dialog, DataCloseCallback, (XtPointer)dialog);
  1673. dialog->next = class_set[dialog_type].dialog_list;
  1674. class_set[dialog_type].dialog_list = dialog;
  1675. }
  1676. /*
  1677. * Set pointer to top dialog data in child of the shell.
  1678. * This is needed to get help to work.
  1679. */
  1680. if (top_rec == NULL)
  1681. top_rec = dialog->dialog;
  1682. XtSetArg(args[0], XmNuserData, top_rec);
  1683. XtSetValues(dialog->dialog_widget, args, 1);
  1684. /* Set the dialog structure fields to the parameter data. */
  1685. dialog->in_use = True;
  1686. dialog->dialog_data = dialog_data;
  1687. dialog->change = change_proc;
  1688. dialog->change_client_data = change_data;
  1689. dialog->close = close_proc;
  1690. dialog->close_client_data = close_data;
  1691. /* If a special title has been specified, we need to set it now */
  1692. if (title)
  1693. {
  1694. XtSetArg(args[0], XmNtitle, title);
  1695. XtSetValues(XtParent(dialog->dialog_widget), args, 1);
  1696. }
  1697. }
  1698. /************************************************************************
  1699. *
  1700. * _DtShowBuiltDialog
  1701. * This functions is used to display an instance of a dialog which
  1702. * has already been built with _DtBuildDialog.
  1703. *
  1704. ************************************************************************/
  1705. void
  1706. _DtShowBuiltDialog(
  1707. Widget parent,
  1708. Widget map_parent,
  1709. DialogData *dialog_data,
  1710. char *workspaces,
  1711. Boolean iconify_state,
  1712. XClassHint * classHints )
  1713. {
  1714. Dialog * dialog;
  1715. int dialog_type, n;
  1716. DialogInstanceData * instance_data;
  1717. char geometry[40];
  1718. Arg args[5];
  1719. Boolean doCenter = False;
  1720. Boolean doParentRelativePositioning = False;
  1721. int availableDialogCount;
  1722. dialog_type = dialog_data->type;
  1723. /* Find the dialog */
  1724. dialog = class_set[dialog_data->type].dialog_list;
  1725. while (dialog != NULL)
  1726. {
  1727. if (dialog->dialog_data == dialog_data)
  1728. break;
  1729. else
  1730. dialog = dialog->next;
  1731. }
  1732. /* Need to add the map callback in relation to the parent */
  1733. if (class_set[dialog_type].class->map)
  1734. {
  1735. /*
  1736. * The map_parent parameter gives us the ability to position
  1737. * the dialog relative to a window which is not the transientFor
  1738. * parent. This is used for the audio preview dialog.
  1739. */
  1740. if (map_parent == NULL)
  1741. map_parent = parent;
  1742. (*(class_set[dialog_type].class->map)) (map_parent, dialog->dialog);
  1743. }
  1744. instance_data = (DialogInstanceData *) dialog_data->data;
  1745. /* If this is a top level shell, get it realized */
  1746. if (XtIsSubclass (XtParent (dialog->dialog_widget),
  1747. applicationShellWidgetClass))
  1748. {
  1749. if (XtIsRealized (XtParent (dialog->dialog_widget)) == False)
  1750. {
  1751. if (instance_data->displayed == True)
  1752. {
  1753. (void) sprintf (geometry, "=%dx%d+%d+%d",
  1754. instance_data->width, instance_data->height,
  1755. instance_data->x, instance_data->y);
  1756. XtSetArg (args[0], XmNgeometry, geometry);
  1757. XtSetValues (XtParent (dialog->dialog_widget), args, 1);
  1758. }
  1759. else if ((instance_data->width != 0) && (instance_data->height != 0))
  1760. {
  1761. n=0;
  1762. XtSetArg (args[n], XmNwidth, instance_data->width); n++;
  1763. XtSetArg (args[n], XmNheight, instance_data->height); n++;
  1764. XtSetValues (XtParent (dialog->dialog_widget), args, n);
  1765. }
  1766. /* Toggle mappedWhenManaged to false */
  1767. XtSetMappedWhenManaged(XtParent (dialog->dialog_widget), False);
  1768. XtRealizeWidget (XtParent(dialog->dialog_widget));
  1769. /* Set the proper workspaces if needed */
  1770. _DtEncapSetWorkSpaceHints(XtParent(dialog->dialog_widget), workspaces);
  1771. /* Set any application-specified class hints for the window */
  1772. if (classHints)
  1773. {
  1774. XSetClassHint(XtDisplay(dialog->dialog_widget),
  1775. XtWindow(XtParent(dialog->dialog_widget)),
  1776. classHints);
  1777. }
  1778. /* Set the iconify state */
  1779. SetIconifyState(XtParent(dialog->dialog_widget), iconify_state);
  1780. /* Map the window */
  1781. XtSetMappedWhenManaged(XtParent (dialog->dialog_widget), True);
  1782. XtPopup (XtParent (dialog->dialog_widget), XtGrabNone);
  1783. XSync(XtDisplay(dialog->dialog_widget), False);
  1784. }
  1785. else
  1786. {
  1787. if (instance_data->displayed == True)
  1788. {
  1789. WMShellWidget wm = (WMShellWidget)XtParent(dialog->dialog_widget);
  1790. wm->wm.size_hints.flags |= USPosition;
  1791. XtSetArg (args[0], XmNx, instance_data->x);
  1792. XtSetArg (args[1], XmNy, instance_data->y);
  1793. XtSetArg (args[2], XmNwidth, instance_data->width);
  1794. XtSetArg (args[3], XmNheight, instance_data->height);
  1795. XtSetValues (XtParent (dialog->dialog_widget), args, 4);
  1796. }
  1797. else if ((instance_data->width != 0) && (instance_data->height != 0))
  1798. {
  1799. n=0;
  1800. XtSetArg (args[n], XmNwidth, instance_data->width); n++;
  1801. XtSetArg (args[n], XmNheight, instance_data->height); n++;
  1802. XtSetValues (XtParent (dialog->dialog_widget), args, n);
  1803. }
  1804. /* Set the proper workspaces if needed */
  1805. _DtEncapSetWorkSpaceHints(XtParent(dialog->dialog_widget), workspaces);
  1806. /* Set any application-specified class hints for the window */
  1807. if (classHints)
  1808. {
  1809. XSetClassHint(XtDisplay(dialog->dialog_widget),
  1810. XtWindow(XtParent(dialog->dialog_widget)),
  1811. classHints);
  1812. }
  1813. /* Set the iconify state */
  1814. SetIconifyState(XtParent(dialog->dialog_widget), iconify_state);
  1815. /* Map the window */
  1816. XtPopup (XtParent (dialog->dialog_widget), XtGrabNone);
  1817. }
  1818. }
  1819. else
  1820. {
  1821. if (instance_data->displayed == True)
  1822. {
  1823. XtSetArg (args[0], XmNx, instance_data->x);
  1824. XtSetArg (args[1], XmNy, instance_data->y);
  1825. XtSetArg (args[2], XmNwidth, instance_data->width);
  1826. XtSetArg (args[3], XmNheight, instance_data->height);
  1827. XtSetArg (args[4], XmNdefaultPosition, False);
  1828. XtSetValues (dialog->dialog_widget, args, 5);
  1829. XtRealizeWidget (dialog->dialog_widget);
  1830. }
  1831. else
  1832. {
  1833. XtSetArg (args[0], XmNdefaultPosition, False);
  1834. XtSetValues (dialog->dialog_widget, args, 1);
  1835. XtRealizeWidget (dialog->dialog_widget);
  1836. if (parent)
  1837. {
  1838. /* Position relative to the parent dialog */
  1839. /*
  1840. * Must be done after the set_values call, since the dialog
  1841. * may get forced to a different size.
  1842. */
  1843. doParentRelativePositioning = True;
  1844. }
  1845. else
  1846. {
  1847. /* Center in the display */
  1848. /*
  1849. * Must be done after the set_values call, since the dialog
  1850. * may get forced to a different size.
  1851. */
  1852. doCenter = True;
  1853. }
  1854. }
  1855. /*
  1856. * Dialogs with no controlling parent window, need to have their
  1857. * own workspace perperty set, if some workspaces have been requested.
  1858. */
  1859. if ((parent == NULL) && workspaces)
  1860. _DtEncapSetWorkSpaceHints(XtParent(dialog->dialog_widget), workspaces);
  1861. }
  1862. /* Set Values onto the dialog to set it to the correct data. */
  1863. (*(class_set[dialog_data->type].class->set_values))
  1864. (dialog->dialog, dialog_data->data);
  1865. /*
  1866. * These two adjustments MUST be done AFTER the dialog's SetValues()
  1867. * procedure is called. This is due to the fact that the setvalues
  1868. * may cause the dialog size to change, and since both of the following
  1869. * positioning algorithms are dependent upon the dialog size, we want
  1870. * to make sure that the correct size is used.
  1871. */
  1872. if (doCenter)
  1873. {
  1874. XtSetArg (args[0], XmNx,
  1875. (Dimension)(WidthOfScreen(XtScreen(dialog->dialog_widget)) -
  1876. dialog->dialog_widget->core.width) / (Dimension)2);
  1877. XtSetArg (args[1], XmNy,
  1878. (Dimension)(HeightOfScreen(XtScreen(dialog->dialog_widget)) -
  1879. dialog->dialog_widget->core.height) / (Dimension)2);
  1880. XtSetValues (dialog->dialog_widget, args, 2);
  1881. }
  1882. else if (doParentRelativePositioning)
  1883. {
  1884. XtSetArg (args[0], XmNx,
  1885. parent->core.x +
  1886. (Dimension)(parent->core.width - dialog->dialog_widget->core.width) / (Dimension)2);
  1887. XtSetArg (args[1], XmNy,
  1888. parent->core.y +
  1889. (Dimension)(parent->core.height - dialog->dialog_widget->core.height) / (Dimension)2);
  1890. XtSetValues (XtParent(dialog->dialog_widget), args, 2);
  1891. }
  1892. /* Fix up the transient-for windowing information so that */
  1893. /* the window manager will shuffle and iconify as a group */
  1894. if (parent != NULL)
  1895. {
  1896. if (XtIsRealized(parent))
  1897. {
  1898. XSetTransientForHint (XtDisplay (parent),
  1899. XtWindow (XtParent (dialog->dialog_widget)),
  1900. XtWindow (parent));
  1901. }
  1902. }
  1903. else
  1904. {
  1905. if (!XtIsSubclass (XtParent (dialog->dialog_widget),
  1906. applicationShellWidgetClass))
  1907. {
  1908. XSetTransientForHint (XtDisplay (encap_parent_shell),
  1909. XtWindow (XtParent (dialog->dialog_widget)),
  1910. XtWindow (encap_parent_shell));
  1911. }
  1912. }
  1913. /* Display the dialogs, application shells are displayed above. */
  1914. if (!(XtIsSubclass (XtParent (dialog->dialog_widget),
  1915. applicationShellWidgetClass)))
  1916. {
  1917. XtManageChild (dialog->dialog_widget);
  1918. }
  1919. /* Set the dialog instance data to indicate that the dialog */
  1920. /* is displayed. */
  1921. ((DialogInstanceData *) (dialog_data->data))->displayed = True;
  1922. /* Give the dialog a chance to set its focus widget, if necessary */
  1923. if (class_set[dialog_data->type].class->set_focus)
  1924. {
  1925. (*(class_set[dialog_data->type].class->set_focus))
  1926. (dialog->dialog, dialog_data->data);
  1927. }
  1928. }
  1929. static void
  1930. DialogStructureNotifyHandler(
  1931. Widget w,
  1932. XtPointer client_data,
  1933. XEvent *event )
  1934. {
  1935. if( event->type == MapNotify )
  1936. {
  1937. if( NumberOfDialogMapped == 0 )
  1938. {
  1939. int timeOut;
  1940. if( timerState == TIMER_STARTUP_STATE )
  1941. timeOut = initialTimeoutLength;
  1942. else if( timerState == TIMER_ACTIVE_STATE )
  1943. timeOut = activeTimeoutLength;
  1944. else if( timerState == TIMER_IDLE_STATE )
  1945. timeOut = idleTimeoutLength;
  1946. else
  1947. timeOut = 0;
  1948. if( timeOut )
  1949. {
  1950. if( timerId )
  1951. XtRemoveTimeOut( timerId );
  1952. timerId = XtAppAddTimeOut( XtWidgetToApplicationContext( w ),
  1953. timeOut,
  1954. (XtTimerCallbackProc)TimerEvent,
  1955. (XtPointer)w );
  1956. }
  1957. }
  1958. ++NumberOfDialogMapped;
  1959. }
  1960. else if( event->type == UnmapNotify )
  1961. {
  1962. if( NumberOfDialogMapped )
  1963. --NumberOfDialogMapped;
  1964. if( NumberOfDialogMapped == 0 )
  1965. {
  1966. if( timerId )
  1967. {
  1968. XtRemoveTimeOut( timerId );
  1969. timerId = 0;
  1970. }
  1971. }
  1972. }
  1973. }
  1974. void
  1975. _DtChangeTo(
  1976. XtPointer client_data,
  1977. char *directory)
  1978. {
  1979. Dialog * dialog = (Dialog *) client_data;
  1980. ChangeDirectoryToParent(dialog->change_client_data, directory);
  1981. }
  1982. void
  1983. _DtFreeDialog(
  1984. DialogData *dialog_data)
  1985. {
  1986. Dialog *dialog,**headptr;
  1987. headptr = &class_set[dialog_data->type].dialog_list;
  1988. dialog = *headptr;
  1989. while (dialog != NULL)
  1990. {
  1991. if (dialog->dialog_data == dialog_data)
  1992. {
  1993. *headptr = dialog->next;
  1994. XtFree((char *) dialog);
  1995. break;
  1996. }
  1997. headptr = &(dialog->next);
  1998. dialog = *headptr;
  1999. }
  2000. }
  2001. #ifdef USE_XINERAMA
  2002. /*
  2003. * Retrieve dimensions of the Xinerama screen the given widget resides on.
  2004. * Returns True on success, False otherwise.
  2005. */
  2006. static Boolean GetXineramaScreenDimensions(
  2007. Widget w, int *org_x, int *org_y, int *s_width, int *s_height)
  2008. {
  2009. DtXineramaInfo_t *dt_xi;
  2010. unsigned int wx, wy;
  2011. unsigned int i, sx, sy, sw, sh;
  2012. while (w && !XtIsShell(w))
  2013. w=XtParent (w);
  2014. wx=XtX(w);
  2015. wy=XtY(w);
  2016. if (!(dt_xi=_DtXineramaInit(XtDisplay(w)))) return False;
  2017. for (i=0; i<dt_xi->numscreens; i++){
  2018. if (!_DtXineramaGetScreen(dt_xi,i,&sw,&sh,&sx,&sy))
  2019. break;
  2020. if (wx>=sx && wx<(sx+sw) && wy>=sy && wy<(sy+sh))
  2021. {
  2022. *s_width=(int)sw;
  2023. *s_height=(int)sh;
  2024. *org_x=(int)sx;
  2025. *org_y=(int)sy;
  2026. free(dt_xi);
  2027. return True;
  2028. }
  2029. }
  2030. free(dt_xi);
  2031. return False;
  2032. }
  2033. #endif /* USE_XINERAMA */