1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515 |
- /*
- * CDE - Common Desktop Environment
- *
- * Copyright (c) 1993-2012, The Open Group. All rights reserved.
- *
- * These libraries and programs are free software; you can
- * redistribute them and/or modify them under the terms of the GNU
- * Lesser General Public License as published by the Free Software
- * Foundation; either version 2 of the License, or (at your option)
- * any later version.
- *
- * These libraries and programs are distributed in the hope that
- * they will be useful, but WITHOUT ANY WARRANTY; without even the
- * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- * PURPOSE. See the GNU Lesser General Public License for more
- * details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with these libraries and programs; if not, write
- * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
- * Floor, Boston, MA 02110-1301 USA
- */
- /* $XConsortium: Encaps.c /main/10 1996/10/30 11:10:16 drk $ */
- /************************************<+>*************************************
- ****************************************************************************
- *
- * FILE: Encaps.c
- *
- * COMPONENT_NAME: Desktop File Manager (dtfile)
- *
- * Description: Source file for the dialog encapsulation functions.
- *
- * FUNCTIONS: DataChangeCallback
- * DataCloseCallback
- * DialogStructureNotifyHandler
- * IntDialogGetResources
- * IntDialogPutResources
- * SetIconifyState
- * TimerEvent
- * _DtBooleanToString
- * _DtBuildDialog
- * _DtChildPosition
- * _DtDialogGetResources
- * _DtDialogPutResources
- * _DtDimensionToString
- * _DtEncapSetWorkSpaceHints
- * _DtFreeDialogData
- * _DtGetDefaultDialogData
- * _DtGetDialogData
- * _DtGetDialogInstance
- * _DtGetDialogShell
- * _DtGetInstanceData
- * _DtGetResourceDialogData
- * _DtHideDialog
- * _DtInitializeEncapsulation
- * _DtInstallDialog
- * _DtIntToString
- * _DtIsDialogShowing
- * _DtPositionToString
- * _DtShortToString
- * _DtShowBuiltDialog
- * _DtShowDialog
- * _DtStringToString
- * _DtWriteDialogData
- * _DtXmStringTableToString
- * _DtXmStringToString
- * _DtmapCB
- * _DtChangeTo
- *
- * (c) Copyright 1993, 1994, 1995 Hewlett-Packard Company
- * (c) Copyright 1993, 1994, 1995 International Business Machines Corp.
- * (c) Copyright 1993, 1994, 1995 Sun Microsystems, Inc.
- * (c) Copyright 1993, 1994, 1995 Novell, Inc.
- *
- ****************************************************************************
- ************************************<+>*************************************/
- #include <string.h>
- #include <Xm/XmP.h>
- #include <Xm/Xm.h>
- #include <Xm/BulletinB.h>
- #include <Xm/AtomMgr.h>
- #include <Xm/MwmUtil.h>
- #include <Xm/VendorSEP.h>
- #include <Xm/XmPrivate.h> /* _XmStringUngenerate, _XmGetWidgetExtData */
- #include <X11/ShellP.h>
- #include <X11/Shell.h>
- #include <X11/Xutil.h>
- #include <X11/Xatom.h>
- #include <X11/Intrinsic.h>
- #include <Dt/Wsm.h>
- #include <Dt/DtNlUtils.h>
- #include "Encaps.h"
- #include "Desktop.h"
- #include "Filter.h"
- #include "FileMgr.h"
- #include "Main.h"
- #include "ModAttr.h"
- #ifdef USE_XINERAMA
- #include <DtXinerama.h>
- #endif
- #define MAX_NAME_LIST_SIZE 25
- #define MAX_RESOURCE_LENGTH 256
- /* Cache array handling defines, structure, and global statics */
- #define INCREMENT_SIZE 10
- typedef struct _Dialog
- {
- Boolean in_use;
- Widget dialog_widget;
- XtPointer dialog;
- DialogData * dialog_data;
- DialogChangedProc change;
- XtPointer change_client_data;
- DialogClosedProc close;
- XtPointer close_client_data;
- struct _Dialog * next;
- } Dialog;
- typedef struct
- {
- DialogClass * class;
- Dialog * dialog_list;
- Boolean cache;
- Boolean destroyPopups;
- } ClassSet;
- extern int filter_dialog,mod_attr_dialog;
- static ClassSet * class_set = NULL;
- static int class_set_size = 0;
- static int num_classes = 0;
- static int NumberOfDialogMapped = 0;
- static char * resourceBuf = NULL;
- static int commonResourceCount = 5;
- static DialogResource commonResources[] =
- {
- { "displayed", XmRBoolean, sizeof(Boolean),
- XtOffset(DialogInstanceDataPtr, displayed),
- (caddr_t) False, _DtBooleanToString },
- { "x", XmRPosition, sizeof(Position),
- XtOffset(DialogInstanceDataPtr, x),
- (caddr_t) 0, _DtPositionToString},
- { "y", XmRPosition, sizeof(Position),
- XtOffset(DialogInstanceDataPtr, y),
- (caddr_t) 0, _DtPositionToString },
- { "width", XmRHorizontalDimension, sizeof(Dimension),
- XtOffset(DialogInstanceDataPtr, width),
- (caddr_t) 0, _DtDimensionToString },
- { "height", XmRVerticalDimension, sizeof(Dimension),
- XtOffset(DialogInstanceDataPtr, height),
- (caddr_t) 0, _DtDimensionToString },
- };
- static Widget encap_parent_shell;
- extern int file_mgr_dialog;
- /* Timer globals */
- /*
- * initialTimeoutLength is used to specify how long to wait before initially
- * kicking of the building of the dialog cache.
- * activeTimeoutLength is used to specify how long to wait after adding
- * a dialog to the cache, before adding the next dialog.
- * idleTimeoutLength is used to specify how long to wait after all dialogs
- * have been built, and the cache is full.
- */
- int initialTimeoutLength = 180000; /* 3 minutes, in milliseconds */
- int activeTimeoutLength = 30000; /* 30 seconds, in milliseconds */
- int idleTimeoutLength = 900000; /* 15 minutes, in milliseconds */
- #define TIMER_STARTUP_STATE 0
- #define TIMER_ACTIVE_STATE 1
- #define TIMER_IDLE_STATE 2
- static int timerState = TIMER_STARTUP_STATE;
- static XtIntervalId timerId = 0;
- /*
- * This global is used when positioning a dialog ABOVE (not below) its
- * parent window. The 'y' position is defined to be the 'y' position
- * of the parent, minus the 'height' of the dialog, minus the value
- * assigned to 'topPositionOffset'; this allows the application to control
- * how much, if any, of the parent's title bar is covered.
- */
- int topPositionOffset = 20;
- /******** Static Function Declarations ********/
- static void DialogStructureNotifyHandler(
- Widget w,
- XtPointer client_data,
- XEvent *event );
- static void SetIconifyState(
- Widget shell,
- Boolean iconify) ;
- static void DataChangeCallback(
- Widget widget,
- XtPointer client_data,
- XtPointer call_data) ;
- static void DataCloseCallback(
- Widget widget,
- XtPointer client_data,
- XtPointer call_data) ;
- static void TimerEvent(
- Widget widget,
- XtIntervalId *id) ;
- static void IntDialogGetResources(
- XrmDatabase database,
- char *base,
- DialogResource *resource,
- XrmName *xrmName,
- int nameCount,
- XrmQuark stringQuark) ;
- static void IntDialogPutResources(
- int fd,
- char **nameList,
- char *dialogName,
- char *base,
- DialogResource *resource) ;
- #ifdef USE_XINERAMA
- static Boolean GetXineramaScreenDimensions(
- Widget w,int *xorg, int *yorg, int *width,int *height);
- #endif /* USE_XINERAMA */
- /******** End Static Function Declarations ********/
- /************************************************************************
- *
- * _DtInitializeEncapsulation
- * This function is used to initialize the dialog encapsulation.
- *
- ************************************************************************/
- void
- _DtInitializeEncapsulation(
- Display *display,
- char *name,
- char *class )
- {
- Arg args[5];
- /* Create an application shell that will never be */
- /* displayed that is used as a parent of all of the */
- /* dialog created. */
- encap_parent_shell = XtAppCreateShell (name, class,
- applicationShellWidgetClass,
- display, NULL, 0);
- /* Supposedly required to be ICCCM complient */
- XtSetArg(args[0], XmNmappedWhenManaged, False);
- XtSetArg(args[1], XmNwidth, 1);
- XtSetArg(args[2], XmNheight, 1);
- XtSetValues(encap_parent_shell, args, 3);
- XtRealizeWidget(encap_parent_shell);
- /* Get a timer going that is used for auto creation of dialogs. */
- timerState = TIMER_STARTUP_STATE;
- timerId = XtAppAddTimeOut(XtWidgetToApplicationContext(encap_parent_shell),
- initialTimeoutLength, (XtTimerCallbackProc)
- TimerEvent, (caddr_t) encap_parent_shell);
- /* Allocate a buffer for writing out resource values */
- resourceBuf = XtMalloc(20);
- }
- /************************************************************************
- *
- * _DtInstallDialog
- * This function is used to register a dialog class with the
- * encapsulation functions.
- *
- ************************************************************************/
- int
- _DtInstallDialog(
- DialogClass *dialog_class,
- Boolean cache,
- Boolean destroyPopups )
- {
- /* Allocate additional dialog cache space if needed */
- if (num_classes == class_set_size)
- {
- class_set_size += INCREMENT_SIZE;
- class_set =
- (ClassSet *) XtRealloc ((char *)class_set,
- sizeof (ClassSet) * class_set_size);
- }
- class_set[num_classes].class = dialog_class;
- class_set[num_classes].dialog_list = NULL;
- class_set[num_classes].cache = cache;
- class_set[num_classes].destroyPopups = destroyPopups;
- num_classes++;
- return (num_classes - 1);
- }
- /************************************************************************
- *
- * _DtGetDialogData
- * This function is used to get a structure containing the
- * current dialog data for a particular dialog instance.
- *
- ************************************************************************/
- DialogData *
- _DtGetDialogData(
- DialogData *dialog_data )
- {
- Dialog * dialog;
- DialogData * new_data;
- dialog = class_set[dialog_data->type].dialog_list;
- while (dialog != NULL)
- {
- if (dialog->dialog_data == dialog_data)
- {
- new_data = (DialogData *) XtMalloc (sizeof (DialogData));
- new_data->type = dialog->dialog_data->type;
- new_data->data = NULL;
- if (class_set[new_data->type].class->get_values)
- {
- new_data->data =
- (*(class_set[new_data->type].class->get_values)) (dialog->dialog);
- }
- return (new_data);
- }
- dialog = dialog->next;
- }
- return (NULL);
- }
- /************************************************************************
- *
- * _DtGetDefaultDialogData
- * This function is used to get a structure containing the
- * default data for a particular dialog type.
- *
- ************************************************************************/
- DialogData *
- _DtGetDefaultDialogData(
- int dialog_type )
- {
- DialogData * dialog_data;
- dialog_data = (DialogData *) XtMalloc (sizeof (DialogData));
- dialog_data->type = dialog_type;
- dialog_data->data = (*(class_set[dialog_type].class->get_default_values))();
- return (dialog_data);
- }
- /************************************************************************
- *
- * _DtGetResourceDialogData
- * This function is used to get a structure containing the
- * data for a particular dialog type from a resource data base.
- *
- ************************************************************************/
- DialogData *
- _DtGetResourceDialogData(
- int dialog_type,
- XrmDatabase data_base,
- char **name_list )
- {
- DialogData * dialog_data;
- dialog_data = (DialogData *) XtMalloc (sizeof (DialogData));
- dialog_data->type = dialog_type;
- dialog_data->data = (*(class_set[dialog_type].class->get_resource_values))
- (data_base, name_list);
- return (dialog_data);
- }
- /************************************************************************
- *
- * _DtShowDialog
- * This functions is used to display an instance of a dialog with
- * the provided data. The functions and data to be set back to
- * the application upon change or close of the dialog is also
- * provided as parameters.
- *
- ************************************************************************/
- void
- _DtShowDialog(
- Widget parent,
- Widget map_parent,
- XtPointer top_rec,
- DialogData *dialog_data,
- DialogChangedProc change_proc,
- XtPointer change_data,
- DialogClosedProc close_proc,
- XtPointer close_data,
- char *workspaces,
- Boolean iconify_state,
- Boolean ignoreCache,
- char * title,
- XClassHint * classHints )
- {
- Dialog * dialog;
- int dialog_type, n;
- DialogInstanceData * instance_data;
- char geometry[40];
- Arg args[5];
- Boolean doCenter = False;
- Boolean doParentRelativePositioning = False;
- int availableDialogCount;
- /* See if there is a cached, unused dialog of the correct type. */
- dialog_type = dialog_data->type;
- dialog = NULL;
- if (!ignoreCache)
- {
- Dialog * availableDialog;
- availableDialog = class_set[dialog_type].dialog_list;
- availableDialogCount = 0;
- /*
- * In addition to looking for an available dialog in the cache to use,
- * we also want to count up the number of unused dialogs in the cache.
- * This lets us know it we need to restart the timer, to again build
- * up the cache.
- */
- while (availableDialog != NULL)
- {
- if (availableDialog->in_use == False)
- {
- if (dialog == NULL)
- dialog = availableDialog;
- else
- availableDialogCount++;
- }
- availableDialog = availableDialog->next;
- }
- }
- if (dialog == NULL)
- {
- dialog = (Dialog *) XtMalloc (sizeof (Dialog));
- (*(class_set[dialog_type].class->create))
- (XtDisplay (encap_parent_shell), encap_parent_shell,
- &(dialog->dialog_widget), &dialog->dialog);
- /* if this is a File Manager view we want to update the headers
- * (i.e icon_path, current_directory, status_line), now so that they
- * don't get managed up front. This is to make the Application
- * Manager (toolbox) happy.
- */
- if(dialog_type == file_mgr_dialog)
- UpdateHeaders(dialog->dialog, dialog_data->data, False);
- /* Add the change and close callbacks into the dialog */
- if (class_set[dialog_type].class->install_change_callback)
- (*(class_set[dialog_type].class->install_change_callback))
- (dialog->dialog, DataChangeCallback, (XtPointer)dialog);
- if (class_set[dialog_type].class->install_close_callback)
- (*(class_set[dialog_type].class->install_close_callback))
- (dialog->dialog, DataCloseCallback, (XtPointer)dialog);
- dialog->next = class_set[dialog_type].dialog_list;
- class_set[dialog_type].dialog_list = dialog;
- }
- else
- {
- if(dialog_type == mod_attr_dialog)
- {
- ModAttrRec *mr = (ModAttrRec *)dialog->dialog;
- ResetFlag(NULL,mr->ok);
- ResetFlag(NULL,mr->cancel);
- }
- else if(dialog_type == filter_dialog)
- {
- FilterRec *fr = (FilterRec *)dialog->dialog;
- ResetFlag(NULL,fr->ok);
- ResetFlag(NULL,fr->close);
- }
- }
- if ((!ignoreCache) && (class_set[dialog_type].cache) &&
- (availableDialogCount < 1) && (timerState == TIMER_IDLE_STATE))
- {
- /*
- * We need to reset the cache building timer, so that it gets kicked
- * off quickly, instead of after the longer idle delay.
- */
- if (timerId)
- XtRemoveTimeOut(timerId);
- timerState = TIMER_ACTIVE_STATE;
- timerId = XtAppAddTimeOut(
- XtWidgetToApplicationContext(encap_parent_shell),
- activeTimeoutLength, (XtTimerCallbackProc) TimerEvent,
- (XtPointer) encap_parent_shell);
- }
- /*
- * Set pointer to top dialog data in child of the shell.
- * This is needed to get help to work.
- */
- if (top_rec == NULL)
- top_rec = dialog->dialog;
- XtSetArg(args[0], XmNuserData, top_rec);
- XtSetValues(dialog->dialog_widget, args, 1);
- /* Need to add the map callback in relation to the parent */
- if (class_set[dialog_type].class->map)
- {
- /*
- * The map_parent parameter gives us the ability to position
- * the dialog relative to a window which is not the transientFor
- * parent. This is used for the audio preview dialog.
- */
- if (map_parent == NULL)
- map_parent = parent;
- (*(class_set[dialog_type].class->map)) (map_parent, dialog->dialog);
- }
- /* Set the dialog structure fields to the parameter data. */
- dialog->in_use = True;
- dialog->dialog_data = dialog_data;
- dialog->change = change_proc;
- dialog->change_client_data = change_data;
- dialog->close = close_proc;
- dialog->close_client_data = close_data;
- instance_data = (DialogInstanceData *) dialog_data->data;
- /* If a special title has been specified, we need to set it now */
- if (title)
- {
- XtSetArg(args[0], XmNtitle, title);
- XtSetValues(XtParent(dialog->dialog_widget), args, 1);
- }
- /* If this is a top level shell, get it realized */
- if (XtIsSubclass (XtParent (dialog->dialog_widget),
- applicationShellWidgetClass))
- {
- if (XtIsRealized (XtParent (dialog->dialog_widget)) == False)
- {
- if (instance_data->displayed == True)
- {
- (void) sprintf (geometry, "=%dx%d+%d+%d",
- instance_data->width, instance_data->height,
- instance_data->x, instance_data->y);
- XtSetArg (args[0], XmNgeometry, geometry);
- XtSetValues (XtParent (dialog->dialog_widget), args, 1);
- }
- else if ((instance_data->width != 0) && (instance_data->height != 0))
- {
- n=0;
- XtSetArg (args[n], XmNwidth, instance_data->width); n++;
- XtSetArg (args[n], XmNheight, instance_data->height); n++;
- XtSetValues (XtParent (dialog->dialog_widget), args, n);
- }
- /* Toggle mappedWhenManaged to false */
- XtSetMappedWhenManaged(XtParent (dialog->dialog_widget), False);
- XtRealizeWidget (XtParent(dialog->dialog_widget));
- /* Set the proper workspaces if needed */
- _DtEncapSetWorkSpaceHints(XtParent(dialog->dialog_widget), workspaces);
- /* Set any application-specified class hints for the window */
- if (classHints)
- {
- XSetClassHint(XtDisplay(dialog->dialog_widget),
- XtWindow(XtParent(dialog->dialog_widget)),
- classHints);
- }
- /* Set the iconify state */
- SetIconifyState(XtParent(dialog->dialog_widget), iconify_state);
- /* Map the window */
- XtSetMappedWhenManaged(XtParent (dialog->dialog_widget), True);
- XtPopup (XtParent (dialog->dialog_widget), XtGrabNone);
- XSync(XtDisplay(dialog->dialog_widget), False);
- }
- else
- {
- if (instance_data->displayed == True)
- {
- WMShellWidget wm = (WMShellWidget)XtParent(dialog->dialog_widget);
- wm->wm.size_hints.flags |= USPosition;
- XtSetArg (args[0], XmNx, instance_data->x);
- XtSetArg (args[1], XmNy, instance_data->y);
- XtSetArg (args[2], XmNwidth, instance_data->width);
- XtSetArg (args[3], XmNheight, instance_data->height);
- XtSetValues (XtParent (dialog->dialog_widget), args, 4);
- }
- else if ((instance_data->width != 0) && (instance_data->height != 0))
- {
- n=0;
- XtSetArg (args[n], XmNwidth, instance_data->width); n++;
- XtSetArg (args[n], XmNheight, instance_data->height); n++;
- XtSetValues (XtParent (dialog->dialog_widget), args, n);
- }
- /* Set the proper workspaces if needed */
- _DtEncapSetWorkSpaceHints(XtParent(dialog->dialog_widget), workspaces);
- /* Set any application-specified class hints for the window */
- if (classHints)
- {
- XSetClassHint(XtDisplay(dialog->dialog_widget),
- XtWindow(XtParent(dialog->dialog_widget)),
- classHints);
- }
- /* Set the iconify state */
- SetIconifyState(XtParent(dialog->dialog_widget), iconify_state);
- /* Map the window */
- XtPopup (XtParent (dialog->dialog_widget), XtGrabNone);
- }
- }
- else
- {
- if (instance_data->displayed == True)
- {
- XtSetArg (args[0], XmNx, instance_data->x);
- XtSetArg (args[1], XmNy, instance_data->y);
- XtSetArg (args[2], XmNwidth, instance_data->width);
- XtSetArg (args[3], XmNheight, instance_data->height);
- XtSetArg (args[4], XmNdefaultPosition, False);
- XtSetValues (dialog->dialog_widget, args, 5);
- XtRealizeWidget (dialog->dialog_widget);
- }
- else
- {
- XtSetArg (args[0], XmNdefaultPosition, False);
- XtSetValues (dialog->dialog_widget, args, 1);
- XtRealizeWidget (dialog->dialog_widget);
- if (parent)
- {
- /* Position relative to the parent dialog */
- /*
- * Must be done after the set_values call, since the dialog
- * may get forced to a different size.
- */
- doParentRelativePositioning = True;
- }
- else
- {
- /* Center in the display */
- /*
- * Must be done after the set_values call, since the dialog
- * may get forced to a different size.
- */
- doCenter = True;
- }
- }
- /*
- * Dialogs with no controlling parent window, need to have their
- * own workspace perperty set, if some workspaces have been requested.
- */
- if ((parent == NULL) && workspaces)
- _DtEncapSetWorkSpaceHints(XtParent(dialog->dialog_widget), workspaces);
- }
- /* Set Values onto the dialog to set it to the correct data. */
- (*(class_set[dialog_data->type].class->set_values))
- (dialog->dialog, dialog_data->data);
- /*
- * These two adjustments MUST be done AFTER the dialog's SetValues()
- * procedure is called. This is due to the fact that the setvalues
- * may cause the dialog size to change, and since both of the following
- * positioning algorithms are dependent upon the dialog size, we want
- * to make sure that the correct size is used.
- */
- if (doCenter)
- {
- XtSetArg (args[0], XmNx,
- (Dimension)(WidthOfScreen(XtScreen(dialog->dialog_widget)) -
- dialog->dialog_widget->core.width) / (Dimension)2);
- XtSetArg (args[1], XmNy,
- (Dimension)(HeightOfScreen(XtScreen(dialog->dialog_widget)) -
- dialog->dialog_widget->core.height) / (Dimension)2);
- XtSetValues (dialog->dialog_widget, args, 2);
- }
- else if (doParentRelativePositioning)
- {
- XtSetArg (args[0], XmNx,
- parent->core.x +
- (Dimension)(parent->core.width - dialog->dialog_widget->core.width) / (Dimension)2);
- XtSetArg (args[1], XmNy,
- parent->core.y +
- (Dimension)(parent->core.height - dialog->dialog_widget->core.height) / (Dimension)2);
- XtSetValues (XtParent(dialog->dialog_widget), args, 2);
- }
- /* Fix up the transient-for windowing information so that */
- /* the window manager will shuffle and iconify as a group */
- if (parent != NULL)
- {
- if (XtIsRealized(parent))
- {
- XSetTransientForHint (XtDisplay (parent),
- XtWindow (XtParent (dialog->dialog_widget)),
- XtWindow (parent));
- }
- }
- else
- {
- if (!XtIsSubclass (XtParent (dialog->dialog_widget),
- applicationShellWidgetClass))
- {
- XSetTransientForHint (XtDisplay (encap_parent_shell),
- XtWindow (XtParent (dialog->dialog_widget)),
- XtWindow (encap_parent_shell));
- }
- }
- /* Display the dialogs, application shells are displayed above. */
- if (!(XtIsSubclass (XtParent (dialog->dialog_widget),
- applicationShellWidgetClass)))
- {
- XtManageChild (dialog->dialog_widget);
- }
- /* Set the dialog instance data to indicate that the dialog */
- /* is displayed. */
- ((DialogInstanceData *) (dialog_data->data))->displayed = True;
- /* Give the dialog a chance to set its focus widget, if necessary */
- if (class_set[dialog_data->type].class->set_focus)
- {
- (*(class_set[dialog_data->type].class->set_focus))
- (dialog->dialog, dialog_data->data);
- }
- XtAddEventHandler( XtParent( dialog->dialog_widget ),
- StructureNotifyMask,
- False,
- (XtEventHandler)DialogStructureNotifyHandler,
- NULL );
- }
- /************************************************************************
- *
- * _DtHideDialog
- * This function is used to undisplay a dialog.
- *
- ************************************************************************/
- void
- _DtHideDialog(
- DialogData *dialog_data,
- Boolean call_callbacks )
- {
- Dialog * dialog;
- DialogData * new_data;
- CorePart * core;
- int i;
- /* Find the dialog and then hide it. */
- dialog = class_set[dialog_data->type].dialog_list;
- while (dialog != NULL)
- {
- if ((dialog->dialog_data &&
- dialog->dialog_data == dialog_data) && dialog->in_use == True)
- {
- /* Free up any dialogs attached to the dialog widget */
- if(class_set[dialog_data->type].destroyPopups)
- {
- core = (CorePart *) (XtParent (dialog->dialog_widget));
- for (i = core->num_popups - 1; i >= 0; i--)
- XtDestroyWidget (core->popup_list[i]);
- }
- /* Get the dialog down, invoke the close callbacks, and */
- /* take it out of use. */
- if (XtIsSubclass (XtParent (dialog->dialog_widget),
- applicationShellWidgetClass))
- {
- ShellWidget shell_widget;
- /*
- * If we had been iconified, then our popped_up flag will
- * have been cleared by the vendor shell. When we call
- * XtPopdown(), it will see that we are no longer popped
- * up, and will not notify the window manager that our
- * icon should be removed; this can cause a subsequent
- * core dump if the user later tries to deiconify the window.
- * This fix should not be necessary once the toolkit is
- * fixed to properly track the shell's state.
- */
- shell_widget = (ShellWidget) XtParent(dialog->dialog_widget);
- shell_widget->shell.popped_up = True;
- XtPopdown ((Widget)shell_widget);
- }
- else
- {
- /*
- * The following is for the condition described above. However,
- * for a dialog shell, what happens it that the 'managed' flag
- * was set to 'False' when the windows were iconified (apparently
- * by the dialog shell), and when we tell the intrinsics to
- * really unmanage the child, it thinks it already has, so
- * nothing happens; as a result, the dialog shell is left with
- * its 'popped_up' flag set to 'True'. The next time we try
- * to post this dialog, the intrinsics think that it is already
- * up, so it does nothing.
- */
- dialog->dialog_widget->core.managed = True;
- XtUnmanageChild (dialog->dialog_widget);
- }
- /* Set the dialog data to hidden */
- ((DialogInstanceData *) (dialog->dialog_data->data))->displayed = False;
- if (call_callbacks && dialog->close)
- {
- new_data = (DialogData *) XtMalloc (sizeof (DialogData));
- new_data->type = dialog->dialog_data->type;
- new_data->data = NULL;
- if (class_set[new_data->type].class->get_values)
- {
- new_data->data =
- (*(class_set[new_data->type].class->get_values))(dialog->dialog);
- }
- dialog->in_use = False;
- if (new_data->data)
- ((DialogInstanceData *) (new_data->data))->displayed = False;
- (*(dialog->close))
- (dialog->close_client_data, dialog->dialog_data, new_data);
- }
- else
- {
- dialog->in_use = False;
- ((DialogInstanceData *) (dialog->dialog_data->data))->displayed = False;
- }
- break;
- }
- dialog = dialog->next;
- }
- }
- /************************************************************************
- *
- * _DtGetDialogShell
- * This function is used return the shell widget of a dialog that
- * is currently displayed.
- *
- ************************************************************************/
- Widget
- _DtGetDialogShell(
- DialogData *dialog_data )
- {
- Dialog * dialog;
- /* Find the dialog and then return the shell. */
- dialog = class_set[dialog_data->type].dialog_list;
- while (dialog != NULL)
- {
- if (dialog->dialog_data == dialog_data)
- return (dialog->dialog_widget);
- else
- dialog = dialog->next;
- }
- return (NULL);
- }
- /************************************************************************
- *
- * _DtGetDialogInstance
- * This function is used return the dialog instance structure
- * of a currently in use dialog.
- *
- ************************************************************************/
- XtPointer
- _DtGetDialogInstance(
- DialogData *dialog_data )
- {
- Dialog * dialog;
- /* Find the dialog and then return the instance */
- dialog = class_set[dialog_data->type].dialog_list;
- while (dialog != NULL)
- {
- if (dialog->dialog_data && dialog->dialog_data == dialog_data)
- return (dialog->dialog);
- else
- dialog = dialog->next;
- }
- return (NULL);
- }
- /************************************************************************
- *
- * _DtGetInstanceData
- * This function is used return the dialog data structure contained
- * within the cache structure referenced by instance.
- *
- ************************************************************************/
- DialogData *
- _DtGetInstanceData(
- XtPointer instance )
- {
- int i;
- Dialog * dialog;
- /* Find the dialog and then return the instance */
- for (i = 0; i < num_classes; i++)
- {
- dialog = class_set[i].dialog_list;
- while (dialog != NULL)
- {
- if (dialog->dialog == instance && dialog->in_use == True)
- return (dialog->dialog_data);
- else
- dialog = dialog->next;
- }
- }
- return (NULL);
- }
- /************************************************************************
- *
- * _DtIsDialogShowing
- * This function is used return a boolean indicating whether the
- * a dialog is displayed which contains the dialog data.
- * of a currently in use dialog.
- *
- ************************************************************************/
- Boolean
- _DtIsDialogShowing(
- DialogData *dialog_data )
- {
- Dialog * dialog;
- /* Find the dialog and then return the instance */
- dialog = class_set[dialog_data->type].dialog_list;
- while (dialog != NULL)
- {
- if (dialog->in_use && dialog->dialog_data == dialog_data)
- return (True);
- else
- dialog = dialog->next;
- }
- return (False);
- }
- /************************************************************************
- *
- * _DtWriteDialogData
- * This function is used to write, as resources, the data
- * for a dialog contained in dialog_data to the open file fd.
- *
- ************************************************************************/
- void
- _DtWriteDialogData(
- DialogData *dialog_data,
- int fd,
- char **name_list )
- {
- if (dialog_data != NULL)
- (*(class_set[dialog_data->type].class->write_resource_values))
- (dialog_data, fd, name_list);
- }
- /************************************************************************
- *
- * _DtFreeDialogData
- * This function is used to free up the data space allocated
- * by a dialog.
- *
- ************************************************************************/
- void
- _DtFreeDialogData(
- DialogData *dialog_data )
- {
- if (dialog_data != NULL)
- {
- (*(class_set[dialog_data->type].class->free_values)) (dialog_data->data);
- XtFree ((char *) dialog_data);
- dialog_data = NULL;
- }
- }
- /************************************************************************
- *
- * _DtDialogGetResources
- * This function accesses data_base to extract the resource set
- * described by the resoruces array. Resources values are
- * converted to the proper type and defaults are used if not
- * data is found in the resource data base.
- *
- ************************************************************************/
- void
- _DtDialogGetResources(
- XrmDatabase database,
- char **name_list,
- char *dialog_name,
- char *base,
- DialogResource *resources,
- int resource_count )
- {
- XrmName xrmName[MAX_NAME_LIST_SIZE];
- XrmQuark stringQuark;
- int nameCount;
- int i;
- /* Build the quarkified name list from name_list and dialog_name */
- /* provided by the calling procedure. */
- nameCount = 0;
- if (name_list != NULL)
- {
- while (name_list[nameCount] != NULL)
- {
- xrmName[nameCount] = XrmStringToQuark (name_list[nameCount]);
- nameCount++;
- }
- }
- if (dialog_name)
- xrmName[nameCount] = XrmStringToQuark (dialog_name);
- else
- nameCount--;
- xrmName[nameCount + 2] = 0;
- stringQuark = XrmStringToQuark (XmRString);
- /* Load the common dialog size/position resources */
- for (i = 0; i < resource_count; i++)
- {
- IntDialogGetResources(database, base, resources + i, xrmName, nameCount,
- stringQuark);
- }
- /*
- * Load the dialog specific resources. If no value found, use the default.
- */
- for (i = 0; i < commonResourceCount; i++)
- {
- IntDialogGetResources(database, base, commonResources + i, xrmName,
- nameCount, stringQuark);
- }
- }
- /*
- * This internal function does the real work of loading a single resource
- * value. If the value is not found in the resource database, then the
- * specified default value is used.
- */
- static void
- IntDialogGetResources(
- XrmDatabase database,
- char *base,
- DialogResource *resource,
- XrmName *xrmName,
- int nameCount,
- XrmQuark stringQuark )
- {
- XrmRepresentation repType;
- XrmValue value;
- XrmValue convertedValue;
- char charVal;
- short shortVal;
- int intVal;
- long longVal;
- {
- xrmName[nameCount + 1] = XrmStringToQuark (resource->name);
- if (XrmQGetResource (database, xrmName, xrmName, &repType, &value))
- {
- if (repType == stringQuark)
- if (strcmp (resource->type, XmRString) != 0)
- {
- XtConvert (encap_parent_shell, XmRString, &value,
- resource->type, &convertedValue);
- }
- else
- {
- *((char **)(base + resource->offset)) = (char *)value.addr;
- return;
- }
- else
- convertedValue.addr = NULL;
- }
- else
- convertedValue.addr = NULL;
- /* Set the converted value address pointer and value to */
- /* the proper default value if the addr is NULL. */
- if (convertedValue.addr == NULL)
- {
- if (resource->size == sizeof(char))
- {
- charVal = (char)(XtArgVal)resource->default_value;
- convertedValue.addr = (caddr_t) &charVal;
- }
- else if (resource->size == sizeof(short))
- {
- shortVal = (short)(XtArgVal)resource->default_value;
- convertedValue.addr = (caddr_t) &shortVal;
- }
- else if (resource->size == sizeof(int))
- {
- intVal = (int)(XtArgVal)resource->default_value;
- convertedValue.addr = (caddr_t) &intVal;
- }
- else
- {
- longVal = (long)(XtArgVal)resource->default_value;
- convertedValue.addr = (caddr_t) &longVal;
- }
- }
- /* Stuff the converted value into the calling functions */
- /* structure according to the size of the piece of data. */
- if (resource->size == sizeof(char))
- *((char *)(base + resource->offset)) = *((char *)convertedValue.addr);
- else if (resource->size == sizeof(short))
- *((short *)(base + resource->offset))= *((short *)convertedValue.addr);
- else if (resource->size == sizeof(int))
- *((int *)(base + resource->offset))= *((int *)convertedValue.addr);
- else
- *((long *)(base + resource->offset)) = *((long *)convertedValue.addr);
- }
- }
- /************************************************************************
- *
- * _DtDialogPutResources
- * This function writes a resource set to a file.
- *
- ************************************************************************/
- void
- _DtDialogPutResources(
- int fd,
- char **nameList,
- char *dialogName,
- char *base,
- DialogResource *resources,
- int resourceCount )
- {
- int i;
- DialogInstanceData * dialogInstanceData;
- /*
- * Write out the common dialog size/position resources, only if the
- * dialog is currently displayed.
- */
- dialogInstanceData = (DialogInstanceData *)base;
- if (dialogInstanceData->displayed)
- {
- for (i = 0; i < commonResourceCount; i++)
- {
- IntDialogPutResources(fd, nameList, dialogName, base,
- commonResources + i);
- }
- }
- /*
- * Loop through the dialog specific resources, write the name list and
- * resource name.
- */
- for (i = 0; i < resourceCount; i++)
- IntDialogPutResources( fd, nameList, dialogName, base, resources + i);
- }
- /*
- * This internal function does the real work involved in writing a single
- * resource out to a session file.
- */
- static void
- IntDialogPutResources(
- int fd,
- char **nameList,
- char *dialogName,
- char *base,
- DialogResource *resource )
- {
- static char outBuf[MAX_RESOURCE_LENGTH];
- int nameCount;
- outBuf[0] = '\0';
- (void) strcat (outBuf, "*");
- nameCount = 0;
- if (nameList != NULL)
- {
- while (nameList[nameCount] != NULL)
- {
- (void) strcat (outBuf, nameList[nameCount]);
- (void) strcat (outBuf, ".");
- nameCount++;
- }
- }
- if (dialogName != NULL)
- {
- (void) strcat (outBuf, dialogName);
- (void) strcat (outBuf, ".");
- }
- (void) strcat (outBuf, resource->name);
- (void) strcat (outBuf, ": ");
- (*(resource->write_resource))
- (fd, (XtPointer) (base + resource->offset), outBuf);
- }
- /************************************************************************
- ************************************************************************
- *
- * Internal functions
- *
- ************************************************************************
- ************************************************************************/
- /************************************************************************
- *
- * _DtEncapSetWorkSpaceHints
- * This function sets a given shell to a given set(s) of
- * workspaces.
- *
- ************************************************************************/
- void
- _DtEncapSetWorkSpaceHints(
- Widget shell,
- char *workspaces )
- {
- char * ptr;
- Atom * workspace_atoms = NULL;
- int num_workspaces=0;
- if (workspaces)
- {
- do
- {
- ptr = DtStrchr (workspaces, '*');
- if (ptr != NULL) *ptr = '\0';
- workspace_atoms = (Atom *) XtRealloc ((char *)workspace_atoms,
- sizeof (Atom) * (num_workspaces + 1));
- workspace_atoms[num_workspaces] =
- XmInternAtom (XtDisplay(shell), workspaces, True);
- num_workspaces++;
- if (ptr != NULL)
- {
- *ptr = '*';
- workspaces = ptr + 1;
- }
- } while (ptr != NULL);
- DtWsmSetWorkspacesOccupied (XtDisplay(shell), XtWindow (shell), workspace_atoms,
- num_workspaces);
- XtFree ((char *) workspace_atoms);
- workspace_atoms = NULL;
- }
- else
- {
- Window rootWindow;
- Atom pCurrent;
- Screen *currentScreen;
- int screen;
- char *workspace_name;
- /*
- * Since no specific workspaces were specified, we will force the
- * dialog to the current workspace.
- */
- screen = XDefaultScreen(XtDisplay(shell));
- currentScreen = XScreenOfDisplay(XtDisplay(shell), screen);
- rootWindow = RootWindowOfScreen(currentScreen);
- if(DtWsmGetCurrentWorkspace(XtDisplay(shell), rootWindow, &pCurrent) ==
- Success)
- {
- DtWsmSetWorkspacesOccupied(XtDisplay(shell), XtWindow (shell), &pCurrent, 1);
- }
- }
- }
- /************************************************************************
- *
- * SetIconifyState
- * This function sets a given shell to a given iconify state.
- * (e.g. Mapped or iconified)
- *
- ************************************************************************/
- static void
- SetIconifyState(
- Widget shell,
- Boolean iconify )
- {
- Arg args[1];
- XWMHints *wmhints;
- if (iconify)
- {
- /* add the iconify hint to the current shell */
- XtSetArg(args[0], XmNinitialState, IconicState);
- XtSetValues(shell, args, 1);
- }
- else
- {
- /* Remove the iconify hint from the current shell */
- wmhints = XGetWMHints(XtDisplay(shell), XtWindow(shell));
- wmhints->flags |= IconWindowHint;
- wmhints->initial_state = NormalState;
- XSetWMHints(XtDisplay(shell), XtWindow(shell), wmhints);
- XFree(wmhints);
- }
- }
- /************************************************************************
- *
- * DataChangeCallback
- * This callback is invoked from a dialog upon an action on the
- * dialog that means that the data within the dialog has been
- * changed.
- *
- ************************************************************************/
- /*ARGSUSED*/
- static void
- DataChangeCallback(
- Widget widget,
- XtPointer client_data,
- XtPointer call_data )
- {
- Dialog * dialog = (Dialog *) client_data;
- DialogData * new_data;
- new_data = (DialogData *) XtMalloc (sizeof (DialogData));
- new_data->type = dialog->dialog_data->type;
- new_data->data = NULL;
- if (class_set[new_data->type].class->get_values)
- {
- new_data->data = (*(class_set[new_data->type].class->get_values))
- (dialog->dialog);
- }
- if (dialog->change)
- (*(dialog->change))
- (dialog->change_client_data, dialog->dialog_data, new_data, call_data);
- }
- /************************************************************************
- *
- * DataCloseCallback
- * This callback is invoked from a dialog upon an action on the
- * dialog that means the dialog has been closed.
- *
- ************************************************************************/
- /*ARGSUSED*/
- static void
- DataCloseCallback(
- Widget widget,
- XtPointer client_data,
- XtPointer call_data )
- {
- Dialog * dialog = (Dialog *) client_data;
- if(RecheckFlag(NULL,widget)) /* cancel flag already set, just return */
- return;
- _DtHideDialog (dialog->dialog_data, True);
- }
- /************************************************************************
- *
- * TimerEvent
- * This action function is called upon the encapsulations
- * timeout going off. Its function is to precreate and destroy
- * extra dialogs.
- *
- ************************************************************************/
- /* ARGSUSED */
- static void
- TimerEvent(
- Widget widget,
- XtIntervalId *id )
- {
- int i;
- Dialog * dialog;
- Dialog * prev_dialog;
- int count;
- /* First pass through the dialog set to see if any */
- /* need to be created. This is based on having 0 */
- /* not in use dialogs of each type. */
- for (i = 0; i < num_classes; i++)
- {
- dialog = class_set[i].dialog_list;
- /* Only attempt to cache dialogs requesting this feature */
- if (!class_set[i].cache)
- continue;
- while (dialog != NULL)
- if (dialog->in_use == False)
- break;
- else
- dialog = dialog->next;
- if (dialog == NULL)
- {
- dialog = (Dialog *) XtMalloc (sizeof (Dialog));
- (*(class_set[i].class->create))
- (XtDisplay (encap_parent_shell), encap_parent_shell,
- &(dialog->dialog_widget), &dialog->dialog);
- /* Add the change and close callbacks into the dialog */
- if (class_set[i].class->install_change_callback)
- (*(class_set[i].class->install_change_callback))
- (dialog->dialog, DataChangeCallback, (XtPointer)dialog);
- if (class_set[i].class->install_close_callback)
- (*(class_set[i].class->install_close_callback))
- (dialog->dialog, DataCloseCallback, (XtPointer)dialog);
- dialog->next = class_set[i].dialog_list;
- class_set[i].dialog_list = dialog;
- dialog->in_use = False;
- timerState = TIMER_ACTIVE_STATE;
- timerId = XtAppAddTimeOut(XtWidgetToApplicationContext(widget),
- activeTimeoutLength,
- (XtTimerCallbackProc) TimerEvent,
- (XtPointer) widget);
- return;
- }
- }
- /* Pass through the dialog set to see if any need to be destroyed */
- /* This is based on having more than 1 not in use dialog of a type. */
- for (i = 0; i < num_classes; i++)
- {
- dialog = class_set[i].dialog_list;
- count = 0;
- while (dialog != NULL)
- {
- if (dialog->in_use == False)
- count++;
- dialog = dialog->next;
- }
- if (count > 1)
- {
- dialog = class_set[i].dialog_list;
- if (dialog->in_use == False)
- class_set[i].dialog_list = dialog->next;
- else
- {
- prev_dialog = class_set[i].dialog_list;
- dialog = dialog->next;
- while (dialog->in_use == True)
- {
- prev_dialog = dialog;
- dialog = dialog->next;
- }
- prev_dialog->next = dialog->next;
- }
- (*(class_set[i].class->destroy)) (dialog->dialog);
- XtFree ((char *) dialog);
- dialog = NULL;
- break;
- }
- }
- timerState = TIMER_IDLE_STATE;
- timerId = XtAppAddTimeOut(XtWidgetToApplicationContext(widget),
- idleTimeoutLength,
- (XtTimerCallbackProc)TimerEvent,
- (XtPointer)widget);
- }
- /************************************************************************
- ************************************************************************
- *
- * Externed Type to String Converters and writers
- *
- ************************************************************************
- ************************************************************************/
- void
- _DtIntToString(
- int fd,
- int *value,
- char *out_buf )
- {
- (void) sprintf (resourceBuf, "%d", *value);
- _DtStringToString( fd, &resourceBuf, out_buf );
- }
- void
- _DtShortToString(
- int fd,
- short *value,
- char *out_buf )
- {
- (void) sprintf (resourceBuf, "%d", *value);
- _DtStringToString( fd, &resourceBuf, out_buf );
- }
- void
- _DtPositionToString(
- int fd,
- Position *value,
- char *out_buf )
- {
- (void) sprintf (resourceBuf, "%d", *value);
- _DtStringToString( fd, &resourceBuf, out_buf );
- }
- void
- _DtDimensionToString(
- int fd,
- Dimension *value,
- char *out_buf )
- {
- (void) sprintf (resourceBuf, "%d", *value);
- _DtStringToString( fd, &resourceBuf, out_buf );
- }
- void
- _DtBooleanToString(
- int fd,
- Boolean *value,
- char *out_buf )
- {
- char * buf;
- if (*value == True)
- buf = "True";
- else
- buf = "False";
- _DtStringToString( fd, (char **)&buf, out_buf );
- }
- void
- _DtXmStringToString(
- int fd,
- XmString *value,
- char *out_buf )
- {
- char *out_value = NULL;
- if (*value != NULL)
- {
- out_value = (char *) _XmStringUngenerate(*value, XmFONTLIST_DEFAULT_TAG,
- XmCHARSET_TEXT, XmCHARSET_TEXT);
- if ( out_value != NULL)
- {
- if (strlen (out_value) != 0)
- {
- (void) write (fd, out_value, strlen (out_value));
- _DtStringToString( fd, &out_value, out_buf );
- XtFree ((char *) out_value);
- }
- }
- }
- }
- void
- _DtXmStringTableToString(
- int fd,
- XmStringTable *value,
- char *out_buf )
- {
- int i;
- char *out_value = NULL;
- Boolean first = True;
- if ((value != NULL) && (*value != NULL))
- {
- i = 0;
- while ((*value)[i] != NULL)
- {
- out_value = (char *)_XmStringUngenerate((*value)[i],
- XmFONTLIST_DEFAULT_TAG,
- XmCHARSET_TEXT, XmCHARSET_TEXT);
- if ( out_value != NULL)
- {
- if (first)
- {
- (void) write (fd, out_buf, strlen (out_buf));
- first = False;
- }
- else
- (void) write (fd, ", ", strlen (", "));
- (void) write (fd, out_value, strlen (out_value));
- XtFree ((char *) out_value);
- out_value = NULL;
- }
- i++;
- }
- if (first == False)
- (void) write (fd, "\n", strlen ("\n"));
- }
- }
- void
- _DtStringToString(
- int fd,
- char **value,
- char *out_buf )
- {
- if (*value == NULL || strlen (*value) == 0)
- ;
- else
- {
- (void) write (fd, out_buf, strlen (out_buf));
- (void) write (fd, *value, strlen (*value));
- (void) write (fd, "\n", strlen ("\n"));
- }
- }
- /*
- * _DtChildPosition:
- * Choose a position for a popup window ("child") so that the main
- * window ("parent") is not obscured. The child will be positioned
- * to the right, below, left, or above the parent, depending on where
- * there is the most space.
- */
- void
- _DtChildPosition(
- Widget w,
- Widget parent,
- Position *newX,
- Position *newY)
- {
- Position pY, pX;
- XmVendorShellExtObject vendorExt;
- XmWidgetExtData extData;
- int xOffset, yOffset;
- int pHeight, myHeight, sHeight;
- int pWidth, myWidth, sWidth;
- enum { posRight, posBelow, posLeft, posAbove } pos;
- int space;
- int xOrg=0, yOrg=0; /* Xinerama screen origin */
- /* get x, y offsets for the parent's window frame */
- extData = _XmGetWidgetExtData(parent, XmSHELL_EXTENSION);
- if (extData)
- {
- vendorExt = (XmVendorShellExtObject)extData->widget;
- xOffset = vendorExt->vendor.xOffset;
- yOffset = vendorExt->vendor.yOffset;
- }
- else
- xOffset = yOffset = 0;
- #ifdef USE_XINERAMA
- if(!GetXineramaScreenDimensions(parent,&xOrg,&yOrg,&sWidth,&sHeight)){
- sHeight = HeightOfScreen(XtScreen(parent));
- sWidth = WidthOfScreen(XtScreen(parent));
- }
- #else
- /* get size/position of screen, parent, and widget */
- sHeight = HeightOfScreen(XtScreen(parent));
- sWidth = WidthOfScreen(XtScreen(parent));
- #endif /* USE_XINERAMA */
- pX = XtX(parent) - xOffset - xOrg;
- pY = XtY(parent) - yOffset - yOrg;
- pHeight = XtHeight(parent) + yOffset + xOffset;
- pWidth = XtWidth(parent) + 2*xOffset;
- myHeight = XtHeight(w) + yOffset + xOffset;
- myWidth = XtWidth(w) + 2*xOffset;
- /*
- * Determine how much space would be left if the child was positioned
- * to the right, below, left, or above the parent. Choose the child
- * positioning so that the maximum space is left.
- */
- pos = posRight;
- space = sWidth - (pX + pWidth + myWidth);
- if (sHeight - (pY + pHeight + myHeight) > space)
- {
- pos = posBelow;
- space = sHeight - (pY + pHeight + myHeight);
- }
- if (pX - myWidth > space)
- {
- pos = posLeft;
- space = pX - myWidth;
- }
- if (pY - myHeight > space)
- {
- pos = posAbove;
- space = pY - myHeight;
- }
- /* Given relative positioning, determine x, y coordinates for the child */
- switch (pos)
- {
- case posRight:
- *newX = pX + pWidth + 5;
- *newY = pY + (pHeight - myHeight)/2;
- break;
- case posBelow:
- *newX = pX + (pWidth - myWidth)/2;
- *newY = pY + pHeight + 5;
- break;
- case posLeft:
- *newX = pX - myWidth - 5;
- *newY = pY + (pHeight - myHeight)/2;
- break;
- case posAbove:
- *newX = pX + (pWidth - myWidth)/2;
- *newY = pY - myHeight - 5;
- break;
- }
- /*
- * The above calculations may put the dialog offscreen so one
- * last check must be made. One way this can happen is if the
- * parent has been resized to fill almost the entire screen.
- * This can also happen if the parent has been maximized
- * and the window manager has its 'positionOnScreen' resource
- * set to False.
- */
- if ((*newX >= (sWidth - 10)) || (*newX < 0))
- *newX = sWidth - myWidth + 5;
- if ((*newY >= (sHeight - 10)) || (*newY < 0))
- *newY = (sHeight - myHeight) / 2;
- *newX+=xOrg;
- *newY+=yOrg;
- }
- /* ARGSUSED */
- void
- _DtmapCB(
- Widget w,
- XtPointer client_data,
- XtPointer call_data )
- {
- Arg args[2];
- Widget parent;
- Position newX, newY;
- parent = (Widget)client_data;
- if (parent)
- {
- _DtChildPosition(w, parent, &newX, &newY);
- XtSetArg(args[0], XmNx, newX);
- XtSetArg(args[1], XmNy, newY);
- XtSetValues(w, args, 2);
- }
- }
- /************************************************************************
- *
- * _DtBuildDialog
- * This functions is used to build an instance of a dialog with
- * the provided data but not display it. The functions and data
- * to be set back to the application upon change or close of the
- * dialog is also provided as parameters.
- *
- ************************************************************************/
- void
- _DtBuildDialog(
- Widget parent,
- Widget map_parent,
- XtPointer top_rec,
- DialogData *dialog_data,
- DialogChangedProc change_proc,
- XtPointer change_data,
- DialogClosedProc close_proc,
- XtPointer close_data,
- char *workspaces,
- Boolean iconify_state,
- Boolean ignoreCache,
- char * title,
- XClassHint * classHints )
- {
- Dialog * dialog;
- int dialog_type, n;
- DialogInstanceData * instance_data;
- char geometry[40];
- Arg args[5];
- Boolean doCenter = False;
- Boolean doParentRelativePositioning = False;
- int availableDialogCount;
- /* See if there is a cached, unused dialog of the correct type. */
- dialog_type = dialog_data->type;
- dialog = NULL;
- if (!ignoreCache)
- {
- Dialog * availableDialog;
- availableDialog = class_set[dialog_type].dialog_list;
- availableDialogCount = 0;
- /*
- * In addition to looking for an available dialog in the cache to use,
- * we also want to count up the number of unused dialogs in the cache.
- * This lets us know it we need to restart the timer, to again build
- * up the cache.
- */
- while (availableDialog != NULL)
- {
- if (availableDialog->in_use == False)
- {
- if (dialog == NULL)
- dialog = availableDialog;
- else
- availableDialogCount++;
- }
- availableDialog = availableDialog->next;
- }
- }
- if (dialog == NULL)
- {
- dialog = (Dialog *) XtMalloc (sizeof (Dialog));
- (*(class_set[dialog_type].class->create))
- (XtDisplay (encap_parent_shell), encap_parent_shell,
- &(dialog->dialog_widget), &dialog->dialog);
- /* Add the change and close callbacks into the dialog */
- if (class_set[dialog_type].class->install_change_callback)
- (*(class_set[dialog_type].class->install_change_callback))
- (dialog->dialog, DataChangeCallback, (XtPointer)dialog);
- if (class_set[dialog_type].class->install_close_callback)
- (*(class_set[dialog_type].class->install_close_callback))
- (dialog->dialog, DataCloseCallback, (XtPointer)dialog);
- dialog->next = class_set[dialog_type].dialog_list;
- class_set[dialog_type].dialog_list = dialog;
- }
- /*
- * Set pointer to top dialog data in child of the shell.
- * This is needed to get help to work.
- */
- if (top_rec == NULL)
- top_rec = dialog->dialog;
- XtSetArg(args[0], XmNuserData, top_rec);
- XtSetValues(dialog->dialog_widget, args, 1);
- /* Set the dialog structure fields to the parameter data. */
- dialog->in_use = True;
- dialog->dialog_data = dialog_data;
- dialog->change = change_proc;
- dialog->change_client_data = change_data;
- dialog->close = close_proc;
- dialog->close_client_data = close_data;
- /* If a special title has been specified, we need to set it now */
- if (title)
- {
- XtSetArg(args[0], XmNtitle, title);
- XtSetValues(XtParent(dialog->dialog_widget), args, 1);
- }
- }
- /************************************************************************
- *
- * _DtShowBuiltDialog
- * This functions is used to display an instance of a dialog which
- * has already been built with _DtBuildDialog.
- *
- ************************************************************************/
- void
- _DtShowBuiltDialog(
- Widget parent,
- Widget map_parent,
- DialogData *dialog_data,
- char *workspaces,
- Boolean iconify_state,
- XClassHint * classHints )
- {
- Dialog * dialog;
- int dialog_type, n;
- DialogInstanceData * instance_data;
- char geometry[40];
- Arg args[5];
- Boolean doCenter = False;
- Boolean doParentRelativePositioning = False;
- int availableDialogCount;
- dialog_type = dialog_data->type;
- /* Find the dialog */
- dialog = class_set[dialog_data->type].dialog_list;
- while (dialog != NULL)
- {
- if (dialog->dialog_data == dialog_data)
- break;
- else
- dialog = dialog->next;
- }
- /* Need to add the map callback in relation to the parent */
- if (class_set[dialog_type].class->map)
- {
- /*
- * The map_parent parameter gives us the ability to position
- * the dialog relative to a window which is not the transientFor
- * parent. This is used for the audio preview dialog.
- */
- if (map_parent == NULL)
- map_parent = parent;
- (*(class_set[dialog_type].class->map)) (map_parent, dialog->dialog);
- }
- instance_data = (DialogInstanceData *) dialog_data->data;
- /* If this is a top level shell, get it realized */
- if (XtIsSubclass (XtParent (dialog->dialog_widget),
- applicationShellWidgetClass))
- {
- if (XtIsRealized (XtParent (dialog->dialog_widget)) == False)
- {
- if (instance_data->displayed == True)
- {
- (void) sprintf (geometry, "=%dx%d+%d+%d",
- instance_data->width, instance_data->height,
- instance_data->x, instance_data->y);
- XtSetArg (args[0], XmNgeometry, geometry);
- XtSetValues (XtParent (dialog->dialog_widget), args, 1);
- }
- else if ((instance_data->width != 0) && (instance_data->height != 0))
- {
- n=0;
- XtSetArg (args[n], XmNwidth, instance_data->width); n++;
- XtSetArg (args[n], XmNheight, instance_data->height); n++;
- XtSetValues (XtParent (dialog->dialog_widget), args, n);
- }
- /* Toggle mappedWhenManaged to false */
- XtSetMappedWhenManaged(XtParent (dialog->dialog_widget), False);
- XtRealizeWidget (XtParent(dialog->dialog_widget));
- /* Set the proper workspaces if needed */
- _DtEncapSetWorkSpaceHints(XtParent(dialog->dialog_widget), workspaces);
- /* Set any application-specified class hints for the window */
- if (classHints)
- {
- XSetClassHint(XtDisplay(dialog->dialog_widget),
- XtWindow(XtParent(dialog->dialog_widget)),
- classHints);
- }
- /* Set the iconify state */
- SetIconifyState(XtParent(dialog->dialog_widget), iconify_state);
- /* Map the window */
- XtSetMappedWhenManaged(XtParent (dialog->dialog_widget), True);
- XtPopup (XtParent (dialog->dialog_widget), XtGrabNone);
- XSync(XtDisplay(dialog->dialog_widget), False);
- }
- else
- {
- if (instance_data->displayed == True)
- {
- WMShellWidget wm = (WMShellWidget)XtParent(dialog->dialog_widget);
- wm->wm.size_hints.flags |= USPosition;
- XtSetArg (args[0], XmNx, instance_data->x);
- XtSetArg (args[1], XmNy, instance_data->y);
- XtSetArg (args[2], XmNwidth, instance_data->width);
- XtSetArg (args[3], XmNheight, instance_data->height);
- XtSetValues (XtParent (dialog->dialog_widget), args, 4);
- }
- else if ((instance_data->width != 0) && (instance_data->height != 0))
- {
- n=0;
- XtSetArg (args[n], XmNwidth, instance_data->width); n++;
- XtSetArg (args[n], XmNheight, instance_data->height); n++;
- XtSetValues (XtParent (dialog->dialog_widget), args, n);
- }
- /* Set the proper workspaces if needed */
- _DtEncapSetWorkSpaceHints(XtParent(dialog->dialog_widget), workspaces);
- /* Set any application-specified class hints for the window */
- if (classHints)
- {
- XSetClassHint(XtDisplay(dialog->dialog_widget),
- XtWindow(XtParent(dialog->dialog_widget)),
- classHints);
- }
- /* Set the iconify state */
- SetIconifyState(XtParent(dialog->dialog_widget), iconify_state);
- /* Map the window */
- XtPopup (XtParent (dialog->dialog_widget), XtGrabNone);
- }
- }
- else
- {
- if (instance_data->displayed == True)
- {
- XtSetArg (args[0], XmNx, instance_data->x);
- XtSetArg (args[1], XmNy, instance_data->y);
- XtSetArg (args[2], XmNwidth, instance_data->width);
- XtSetArg (args[3], XmNheight, instance_data->height);
- XtSetArg (args[4], XmNdefaultPosition, False);
- XtSetValues (dialog->dialog_widget, args, 5);
- XtRealizeWidget (dialog->dialog_widget);
- }
- else
- {
- XtSetArg (args[0], XmNdefaultPosition, False);
- XtSetValues (dialog->dialog_widget, args, 1);
- XtRealizeWidget (dialog->dialog_widget);
- if (parent)
- {
- /* Position relative to the parent dialog */
- /*
- * Must be done after the set_values call, since the dialog
- * may get forced to a different size.
- */
- doParentRelativePositioning = True;
- }
- else
- {
- /* Center in the display */
- /*
- * Must be done after the set_values call, since the dialog
- * may get forced to a different size.
- */
- doCenter = True;
- }
- }
- /*
- * Dialogs with no controlling parent window, need to have their
- * own workspace perperty set, if some workspaces have been requested.
- */
- if ((parent == NULL) && workspaces)
- _DtEncapSetWorkSpaceHints(XtParent(dialog->dialog_widget), workspaces);
- }
- /* Set Values onto the dialog to set it to the correct data. */
- (*(class_set[dialog_data->type].class->set_values))
- (dialog->dialog, dialog_data->data);
- /*
- * These two adjustments MUST be done AFTER the dialog's SetValues()
- * procedure is called. This is due to the fact that the setvalues
- * may cause the dialog size to change, and since both of the following
- * positioning algorithms are dependent upon the dialog size, we want
- * to make sure that the correct size is used.
- */
- if (doCenter)
- {
- XtSetArg (args[0], XmNx,
- (Dimension)(WidthOfScreen(XtScreen(dialog->dialog_widget)) -
- dialog->dialog_widget->core.width) / (Dimension)2);
- XtSetArg (args[1], XmNy,
- (Dimension)(HeightOfScreen(XtScreen(dialog->dialog_widget)) -
- dialog->dialog_widget->core.height) / (Dimension)2);
- XtSetValues (dialog->dialog_widget, args, 2);
- }
- else if (doParentRelativePositioning)
- {
- XtSetArg (args[0], XmNx,
- parent->core.x +
- (Dimension)(parent->core.width - dialog->dialog_widget->core.width) / (Dimension)2);
- XtSetArg (args[1], XmNy,
- parent->core.y +
- (Dimension)(parent->core.height - dialog->dialog_widget->core.height) / (Dimension)2);
- XtSetValues (XtParent(dialog->dialog_widget), args, 2);
- }
- /* Fix up the transient-for windowing information so that */
- /* the window manager will shuffle and iconify as a group */
- if (parent != NULL)
- {
- if (XtIsRealized(parent))
- {
- XSetTransientForHint (XtDisplay (parent),
- XtWindow (XtParent (dialog->dialog_widget)),
- XtWindow (parent));
- }
- }
- else
- {
- if (!XtIsSubclass (XtParent (dialog->dialog_widget),
- applicationShellWidgetClass))
- {
- XSetTransientForHint (XtDisplay (encap_parent_shell),
- XtWindow (XtParent (dialog->dialog_widget)),
- XtWindow (encap_parent_shell));
- }
- }
- /* Display the dialogs, application shells are displayed above. */
- if (!(XtIsSubclass (XtParent (dialog->dialog_widget),
- applicationShellWidgetClass)))
- {
- XtManageChild (dialog->dialog_widget);
- }
- /* Set the dialog instance data to indicate that the dialog */
- /* is displayed. */
- ((DialogInstanceData *) (dialog_data->data))->displayed = True;
- /* Give the dialog a chance to set its focus widget, if necessary */
- if (class_set[dialog_data->type].class->set_focus)
- {
- (*(class_set[dialog_data->type].class->set_focus))
- (dialog->dialog, dialog_data->data);
- }
- }
- static void
- DialogStructureNotifyHandler(
- Widget w,
- XtPointer client_data,
- XEvent *event )
- {
- if( event->type == MapNotify )
- {
- if( NumberOfDialogMapped == 0 )
- {
- int timeOut;
- if( timerState == TIMER_STARTUP_STATE )
- timeOut = initialTimeoutLength;
- else if( timerState == TIMER_ACTIVE_STATE )
- timeOut = activeTimeoutLength;
- else if( timerState == TIMER_IDLE_STATE )
- timeOut = idleTimeoutLength;
- else
- timeOut = 0;
- if( timeOut )
- {
- if( timerId )
- XtRemoveTimeOut( timerId );
- timerId = XtAppAddTimeOut( XtWidgetToApplicationContext( w ),
- timeOut,
- (XtTimerCallbackProc)TimerEvent,
- (XtPointer)w );
- }
- }
- ++NumberOfDialogMapped;
- }
- else if( event->type == UnmapNotify )
- {
- if( NumberOfDialogMapped )
- --NumberOfDialogMapped;
- if( NumberOfDialogMapped == 0 )
- {
- if( timerId )
- {
- XtRemoveTimeOut( timerId );
- timerId = 0;
- }
- }
- }
- }
- void
- _DtChangeTo(
- XtPointer client_data,
- char *directory)
- {
- Dialog * dialog = (Dialog *) client_data;
- ChangeDirectoryToParent(dialog->change_client_data, directory);
- }
- void
- _DtFreeDialog(
- DialogData *dialog_data)
- {
- Dialog *dialog,**headptr;
- headptr = &class_set[dialog_data->type].dialog_list;
- dialog = *headptr;
- while (dialog != NULL)
- {
- if (dialog->dialog_data == dialog_data)
- {
- *headptr = dialog->next;
- XtFree((char *) dialog);
- break;
- }
- headptr = &(dialog->next);
- dialog = *headptr;
- }
- }
- #ifdef USE_XINERAMA
- /*
- * Retrieve dimensions of the Xinerama screen the given widget resides on.
- * Returns True on success, False otherwise.
- */
- static Boolean GetXineramaScreenDimensions(
- Widget w, int *org_x, int *org_y, int *s_width, int *s_height)
- {
- DtXineramaInfo_t *dt_xi;
- unsigned int wx, wy;
- unsigned int i, sx, sy, sw, sh;
- while (w && !XtIsShell(w))
- w=XtParent (w);
- wx=XtX(w);
- wy=XtY(w);
- if (!(dt_xi=_DtXineramaInit(XtDisplay(w)))) return False;
- for (i=0; i<dt_xi->numscreens; i++){
- if (!_DtXineramaGetScreen(dt_xi,i,&sw,&sh,&sx,&sy))
- break;
- if (wx>=sx && wx<(sx+sw) && wy>=sy && wy<(sy+sh))
- {
- *s_width=(int)sw;
- *s_height=(int)sh;
- *org_x=(int)sx;
- *org_y=(int)sy;
- free(dt_xi);
- return True;
- }
- }
- free(dt_xi);
- return False;
- }
- #endif /* USE_XINERAMA */
|