kent@ssbell.IMD.Sterling.COM (Kent Landfield) (01/15/90)
Submitted-by: wsl.dec.com!mikey (Mike Yang) Posting-number: Volume 5, Issue 60 Archive-name: xrooms/part10 #! /bin/sh # This is a shell archive. Remove anything before this line, then unpack # it by saving it into a file and typing "sh file". To overwrite existing # files, type "sh file -c". You can also feed this as standard input via # unshar, or by typing "sh <file", e.g.. If this archive is complete, you # will see the following message at the end: # "End of archive 10 (of 14)." # Contents: ./lib/room.c ./lib/room.h # Wrapped by kent@ssbell on Sun Jan 14 21:58:09 1990 PATH=/bin:/usr/bin:/usr/ucb ; export PATH if test -f './lib/room.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'./lib/room.c'\" else echo shar: Extracting \"'./lib/room.c'\" \(19920 characters\) sed "s/^X//" >'./lib/room.c' <<'END_OF_FILE' X X /*\ X * $Header: room.c,v 5.2 90/01/11 13:38:53 erik Exp $ X * X * COPYRIGHT 1990 X * DIGITAL EQUIPMENT CORPORATION X * MAYNARD, MASSACHUSETTS X * ALL RIGHTS RESERVED. X * X * THE INFORMATION IN THIS SOFTWARE IS SUBJECT TO CHANGE WITHOUT NOTICE AND X * SHOULD NOT BE CONSTRUED AS A COMMITMENT BY DIGITAL EQUIPMENT CORPORATION. X * DIGITAL MAKES NO REPRESENTATIONS ABOUT THE SUITABILITY OF THIS SOFTWARE X * FOR ANY PURPOSE. IT IS SUPPLIED "AS IS" WITHOUT EXPRESS OR IMPLIED X * WARRANTY. X * X * IF THE SOFTWARE IS MODIFIED IN A MANNER CREATING DERIVATIVE COPYRIGHT X * RIGHTS, APPROPRIATE LEGENDS MAY BE PLACED ON THE DERIVATIVE WORK IN X * ADDITION TO THAT SET FORTH ABOVE. X * X * Permission to use, copy, modify, and distribute this software and its X * documentation for any purpose and without fee is hereby granted, provided X * that the above copyright notice appear in all copies and that both that X * copyright notice and this permission notice appear in supporting X * documentation, and that the name of Digital Equipment Corporation not be X * used in advertising or publicity pertaining to distribution of the X * software without specific, written prior permission. X \*/ X X#define DEBUG_VAR roomDebug X#include "utils.h" X#include "app.h" X#include "roomstr.h" X Xunsigned roomDefaultAppSlots= ROOM_DEFAULT_APP_SLOTS; Xunsigned roomDefaultVisibility= ROOM_DEFAULT_VISIBILITY; XBoolean roomIconifyFirst= True; X X/***====================================================================***/ X/*** DEBUGGING FUNCTIONS ***/ X/***====================================================================***/ X Xchar * XroomText(pRoom) XRoomPtr pRoom; X{ X if ((pRoom==NullRoom)||(pRoom->name==NullStringToken)) X return("<NullRoom>"); X else return(stText(pRoom->name)); X} X X/***====================================================================***/ X Xvoid XroomDebugPrint(pRoom) XRoomPtr pRoom; X{ XOpaque lstate; XGenKey key; XGenData data; XRoomAppInfoPtr pAppInfo; X X if (pRoom!=NullRoom) { X uDebug("room %s (0x%x)\n",roomText(pRoom),pRoom); X uDebugIndent(1); X uDebug("name= %s\n",stText(pRoom->name)); X uDebug("active= %s\n",booleanText(pRoom->active)); X uDebug("visibility= 0x%x\n",pRoom->visibility); X uDebug("numApps= %d\n",pRoom->numApps); X uDebug("numLocalApps= %d\n",pRoom->numLocalApps); X uDebug("priv= 0x%x\n",pRoom->priv); X uDebug("feedback= 0x%x\n",pRoom->feedback); X uDebug("contents:\n"); X uDebugIndent(1); X lIterator(pRoom->contents,key,data,lstate) { X pAppInfo= (RoomAppInfoPtr)data; X uDebug("app %s (0x%x):\n",appText(pAppInfo->pApp),pAppInfo->pApp); X uDebugIndent(1); X uDebug("local= %s (0x%x)\n",asText(pAppInfo->pLocal), X pAppInfo->pLocal); X uDebug("default= %s (0x%x)\n",asText(pAppInfo->pDefault), X pAppInfo->pDefault); X uDebug("current= %s (0x%x)\n",asText(pAppInfo->pReal), X pAppInfo->pReal); X uDebugIndent(-1); X } X lEndIterator(pRoom->contents,lstate); X uDebugIndent(-2); X } X return; X} X X/***====================================================================***/ X X /*\ X * Private debuggging function. returns a string for X * a RoomAppInfo. Never returns NullString. X \*/ X Xstatic char * XroomAppInfoText(pAppInfo) XRoomAppInfoPtr pAppInfo; X{ X if ((pAppInfo==NullRoomAppInfo)||(pAppInfo->pApp==NullApp)) X return("<NullRoomAppInfoInfo>"); X else return(appText(pAppInfo->pApp)); X} X X/***====================================================================***/ X/*** FUNCTIONS TO CREATE AND DESTROY A ROOM ***/ X/***====================================================================***/ X XRoomPtr XroomCreate(name,priv,feedback) XStringToken name; XOpaque priv; XRoomFeedbackFunc feedback; X{ XRoomPtr pRoom; X X uENTRY3("roomCreate(%s,0x%x,0x%x)\n",stText(name),priv,feedback); X if (name==NullStringToken) { X uRETURN(NullRoom); X } X pRoom= uTypedAlloc(RoomRec); X if (pRoom!=NullRoom) { X pRoom->name= name; X pRoom->active= False; X pRoom->visibility= roomDefaultVisibility; X if (_Always(pRoom)) _SetVisible(pRoom); X pRoom->contents= lCreate(roomDefaultAppSlots,NullListSortFunc, X genIntegerKeyType, X genFreedPointerDataType); X if (pRoom->contents==NullList) { X (void)roomDestroy(pRoom); X uRETURN(NullRoom); X } X pRoom->numApps= 0; X pRoom->numLocalApps= 0; X pRoom->priv= (Opaque)priv; X pRoom->feedback= (RoomFeedbackFunc)feedback; X _Feedback(pRoom,roomFBCreated,NullApp); X if (_IsVisible(pRoom)) X _Feedback(pRoom,roomFBVisible,NullApp); X } X uRETURN(pRoom); X} X X/***====================================================================***/ X Xvoid XroomDestroy(pRoom) XRoomPtr pRoom; X{ X uENTRY1("roomDestroy(%s)\n",roomText(pRoom)); X if (pRoom!=NullRoom) { X if (_IsVisible(pRoom)) { X _SetHidden(pRoom); X _Feedback(pRoom,roomFBHidden,NullApp); X } X _Feedback(pRoom,roomFBDestroyed,NullApp); X if (pRoom->contents!=NullList) X (void)lDestroy(pRoom->contents); X pRoom->name= NullStringToken; X pRoom->contents= NullList; X pRoom->priv= (Opaque)NULL; X pRoom->numApps= 0; X pRoom->numLocalApps= 0; X pRoom->feedback= (RoomFeedbackFunc)NULL; X (void)uFree((Opaque)pRoom); X } X uVOIDRETURN; X} X X/***====================================================================***/ X/*** FUNCTIONS TO CHANGE OR QUERY THE SET OF MANAGED APPS IN A ROOM ***/ X/***====================================================================***/ X XBoolean XroomManageApp(pRoom,pApp) XRoomPtr pRoom; XAppPtr pApp; X{ XRoomAppInfoPtr pAppInfo; X X uENTRY2("roomManageApp(%s,%s)\n",roomText(pRoom),appText(pApp)); X if ((pRoom==NullRoom)||(pApp==NullApp)) { X uRETURN(False); X } X if (lLookup(pRoom->contents,(GenKey)appName(pApp),(GenData *)&pAppInfo)) { X uRETURN(False); /* already managed by this room */ X } X pAppInfo= uTypedAlloc(RoomAppInfoRec); X if (pAppInfo==NullRoomAppInfo) { X uRETURN(False); X } X pAppInfo->pApp= pApp; X pAppInfo->pDefault= appGetDefault(pApp); X pAppInfo->pReal= appGetCurrent(pApp); X pAppInfo->pLocal= appGetRoomState(pApp,pRoom->name); X if ((pAppInfo->pDefault==NullAppState)|| X (pAppInfo->pReal==NullAppState)) { X uFree((Opaque)pAppInfo); X uRETURN(False); X } X if (_HasLocalState(pRoom,pAppInfo)) { X if (asFullySame(pAppInfo->pLocal,pAppInfo->pDefault)) { X if (appRemoveRoomState(pApp,pRoom->name)) { X pAppInfo->pLocal= NullAppState; X } X } X } X (void)lStore(pRoom->contents,(GenKey)appName(pApp),(GenData)pAppInfo); X if (_HasLocalState(pRoom,pAppInfo)) { X _LocalAppAdded(pRoom); X } X pRoom->numApps++; X _CheckRealState(pRoom,pAppInfo); X _Feedback(pRoom,roomFBAppAdded,pApp); X uRETURN(True); X} X X/***====================================================================***/ X XBoolean XroomUnmanageApp(pRoom, pApp) XRoomPtr pRoom; XAppPtr pApp; X{ XRoomAppInfoPtr pAppInfo; X X uENTRY2("roomUnmanageApp(%s, %s)\n",roomText(pRoom),appText(pApp)); X if ((pRoom==NullRoom)||(pApp==NullApp)) { X uRETURN(False); X } X (void)lLookup(pRoom->contents,(GenKey)appName(pApp),(GenData *)&pAppInfo); X if (pAppInfo!=NullRoomAppInfo) { X _Feedback(pRoom,roomFBAppRemoved,pApp); X if (_HasLocalState(pRoom,pAppInfo)) { X _LocalAppGone(pRoom); X } X pRoom->numApps--; X (void)lRemove(pRoom->contents,(GenKey)appName(pApp)); X uRETURN(True); X } X uRETURN(False); X} X X/***====================================================================***/ X XAppPtr XroomLookupManagedApp(pRoom, appName) XRoomPtr pRoom; XStringToken appName; X{ XRoomAppInfoPtr pAppInfo; X X uENTRY2("roomLookupManagedApp(%s,%s)\n",roomText(pRoom),stText(appName)); X if ((pRoom==NullRoom)||(appName==NullStringToken)) { X uRETURN(NullApp); X } X if (lLookup(pRoom->contents,(GenKey)appName,(GenData *)&pAppInfo)) { X uRETURN(pAppInfo->pApp); X } X else { X uRETURN(NullApp); X } X} X X/***====================================================================***/ X/*** FUNCTIONS TO CHANGE, CHECK, OR QUERY THE STATE OF AN APP IN A ROOM ***/ X/***====================================================================***/ X XBoolean XroomAppRealStateChanged(pRoom, pApp, pReal) XRoomPtr pRoom; XAppPtr pApp; XAppStatePtr pReal; X{ XRoomAppInfoPtr pAppInfo; XAppStatePtr pVisible; X X uENTRY3("roomAppRealStateChanged(%s,%s,%s)\n",roomText(pRoom),appText(pApp), X asText(pReal)); X if ((pRoom==NullRoom)||(pApp==NullApp)||(!asLegalReal(pReal))) { X uRETURN(False); X } X if (!lLookup(pRoom->contents,(GenKey)appName(pApp),(GenData *)&pAppInfo)) { X uRETURN(False); X } X uASSERT("roomAppRealStateChanged", pApp==pAppInfo->pApp ); X X pVisible= _GetVisibleState(pRoom,pAppInfo); X if (!asProfileCorrectWRTReal(pVisible,pReal)) { X if (!_HasLocalState(pRoom,pAppInfo)) { X pAppInfo->pLocal= appSetRoomState(pApp,pRoom->name, X pAppInfo->pDefault, X False); X if (pAppInfo->pLocal==NullAppState) { X uRETURN(False); X } X asCopyFully(pReal,pAppInfo->pLocal); X _LocalAppAdded(pRoom); X } X else { X pAppInfo->pLocal= appSetRoomState(pApp,pRoom->name,pReal,True); X } X } X _CheckRealState(pRoom,pAppInfo); X if (_HasLocalState(pRoom,pAppInfo)) { X if (asFullySame(pAppInfo->pLocal,pAppInfo->pDefault)) { X if (appRemoveRoomState(pApp,pRoom->name)) { X pAppInfo->pLocal= NullAppState; X _LocalAppGone(pRoom); X } X else { X uWarning("room %s and app %s disagree about local state\n", X roomText(pRoom),appText(pApp)); X } X } X } X uRETURN(True); X} X X/***====================================================================***/ X XBoolean XroomChangeAppLocalState(pRoom, pApp, pProf) XRoomPtr pRoom; XAppPtr pApp; XAppStatePtr pProf; X{ XRoomAppInfoPtr pAppInfo; X X uENTRY3("roomChangeAppLocalState(%s,%s,%s)\n",roomText(pRoom),appText(pApp), X asText(pProf)); X if ((pRoom==NullRoom)||(pApp==NullApp)||(!asLegalProfile(pProf))) { X uRETURN(False); X } X if (!lLookup(pRoom->contents,(GenKey)appName(pApp),(GenData *)&pAppInfo)) { X uRETURN(False); X } X uASSERT("roomChangeAppLocalState", pApp==pAppInfo->pApp ); X X if (!_HasLocalState(pRoom,pAppInfo)) { X pAppInfo->pLocal= appSetRoomState(pApp,pRoom->name,pProf,False); X if (!_HasLocalState(pRoom,pAppInfo)) { X uRETURN(False); X } X _LocalAppAdded(pRoom); X } X else { X pAppInfo->pLocal= appSetRoomState(pApp,pRoom->name,pProf,False); X } X _CheckRealState(pRoom,pAppInfo); X uRETURN(True); X} X X/***====================================================================***/ X XBoolean XroomCheckAppStates(pRoom,pApp) XRoomPtr pRoom; XAppPtr pApp; X{ XRoomAppInfoPtr pAppInfo; XBoolean hadLocal,hasLocal; X X uENTRY2("roomCheckAppStates(%s,%s)\n",roomText(pRoom),appText(pApp)); X if ((pRoom==NullRoom)||(pApp==NullApp)) { X uRETURN(False); X } X if (lLookup(pRoom->contents,(GenKey)appName(pApp),(GenData *)&pAppInfo)) { X hadLocal= _HasLocalState(pRoom,pAppInfo); X pAppInfo->pLocal= appGetRoomState(pApp,pRoom->name); X pAppInfo->pDefault= appGetDefault(pApp); X pAppInfo->pReal= appGetCurrent(pApp); X if (_HasLocalState(pRoom,pAppInfo)) { X if (asFullySame(pAppInfo->pLocal,pAppInfo->pDefault)) { X if (appRemoveRoomState(pApp,pRoom->name)) { X pAppInfo->pLocal= NullAppState; X } X } X } X hasLocal= _HasLocalState(pRoom,pAppInfo); X if (hadLocal!=hasLocal) { X if (hadLocal) { _LocalAppGone(pRoom); } X else { _LocalAppAdded(pRoom); } X } X _CheckRealState(pRoom,pAppInfo); X uRETURN(True); X } X uRETURN(False); X} X X/***====================================================================***/ X XAppStatePtr XroomGetVisibleState(pRoom, pApp) XRoomPtr pRoom; XAppPtr pApp; X{ XRoomAppInfoPtr pAppInfo; XAppStatePtr pVisible; X X uENTRY2("roomGetVisibleState(%s,%s)\n",roomText(pRoom),appText(pApp)); X if ((pRoom==NullRoom)||(pApp==NullApp)) { X uRETURN(NullAppState); X } X if (lLookup(pRoom->contents,(GenKey)appName(pApp),(GenData *)&pAppInfo)) { X pVisible= _GetVisibleState(pRoom,pAppInfo); X uRETURN(pVisible); X } X uRETURN(NullAppState); X} X X/***====================================================================***/ X/*** FUNCTIONS TO CHANGE/QUERY ROOM VISIBILITY ***/ X/***====================================================================***/ X XBoolean XroomIsVisible(pRoom) XRoomPtr pRoom; X{ X uENTRY1("roomIsVisible(%s)\n",roomText(pRoom)); X uRETURN(_IsVisible(pRoom)); X} X X/***====================================================================***/ X XBoolean XroomSetVisibility(pRoom,visibility,check) XRoomPtr pRoom; Xunsigned visibility; XBoolean check; X{ XBoolean wasVisible; X X uENTRY3("roomSetVisibility(%s,0x%x,%s)\n",roomText(pRoom),visibility, X booleanText(check)); X if (pRoom!=NullRoom) { X wasVisible= _IsVisible(pRoom); X pRoom->visibility= visibility; X if (check&&(_Always(pRoom)||_WhenNonEmpty(pRoom)||_WhenActive(pRoom))) { X if (_Always(pRoom)) _SetVisible(pRoom); X else { X _SetHidden(pRoom); X if (_WhenNonEmpty(pRoom)&&_HasLocalApps(pRoom)) { X _SetVisible(pRoom); X } X else if (_WhenActive(pRoom)&&_IsActive(pRoom)) { X _SetVisible(pRoom); X } X } X } X if (_IsVisible(pRoom)!=wasVisible) { X _Feedback(pRoom,(wasVisible?roomFBHidden:roomFBVisible),NullApp); X } X } X uRETURN(False); X} X X/***====================================================================***/ X XBoolean XroomCheckVisibility(pRoom) XRoomPtr pRoom; X{ XBoolean shouldBeVisible; X X uENTRY1("roomCheckVisibility(%s)\n",pRoom); X if (pRoom!=NullRoom) { X if (_Always(pRoom)||_WhenActive(pRoom)||_WhenNonEmpty(pRoom)) { X if (_Always(pRoom)) shouldBeVisible= True; X else { X shouldBeVisible= ((_WhenActive(pRoom)&&_IsActive(pRoom))|| X (_WhenNonEmpty(pRoom)&&_HasLocalApps(pRoom))); X } X if (shouldBeVisible&&_IsHidden(pRoom)) { X _SetVisible(pRoom); X _Feedback(pRoom,roomFBVisible,NullApp); X } X else if ((!shouldBeVisible)&&_IsVisible(pRoom)) { X _SetHidden(pRoom); X _Feedback(pRoom,roomFBHidden,NullApp); X } X } X uRETURN(True); X } X uRETURN(False); X} X X/***====================================================================***/ X Xunsigned XroomGetVisibility(pRoom) XRoomPtr pRoom; X{ X uFLAG_ENTRY1(LOW_ENTRY_BIT,"roomGetVisibility(%s)\n",roomText(pRoom)); X if (pRoom!=NullRoom) { X uFLAG_RETURN(pRoom->visibility); X } X uFLAG_RETURN(roomHidden); X} X X/***====================================================================***/ X/*** FUNCTIONS TO ACTIVATE OR DEACTIVATE A ROOM ***/ X/***====================================================================***/ X XBoolean XroomActivate(pRoom) XRoomPtr pRoom; X{ XOpaque lstate; XGenKey key; XGenData data; XRoomAppInfoPtr pAppInfo; XAppStatePtr pState; XWinState firstPassState; X X uENTRY1("roomActivate(%s)\n",roomText(pRoom)); X if (pRoom==NullRoom) { X uRETURN(False); X } X if (!_IsActive(pRoom)) { X pRoom->active= True; X if (_WhenActive(pRoom)&&(!_IsVisible(pRoom))) { X _SetVisible(pRoom); X _Feedback(pRoom,roomFBVisible,NullApp); X } X _Feedback(pRoom,roomFBActivated,NullApp); X X if (roomIconifyFirst) firstPassState= asIconic; X else firstPassState= asNormal; X X lIterator(pRoom->contents,key,data,lstate) { X pAppInfo= (RoomAppInfoPtr)data; X pState= _GetVisibleState(pRoom,pAppInfo); X if (asWinState(pState)==firstPassState) { X _CheckRealState(pRoom,pAppInfo); X } X } X lEndIterator(pRoom->contents,lstate); X lIterator(pRoom->contents,key,data,lstate) { X pAppInfo= (RoomAppInfoPtr)data; X pState= _GetVisibleState(pRoom,pAppInfo); X if (asWinState(pState)!=firstPassState) { X _CheckRealState(pRoom,pAppInfo); X } X } X lEndIterator(pRoom->contents,lstate); X } X uRETURN(True); X} X X/***====================================================================***/ X XBoolean XroomDeactivate(pRoom) XRoomPtr pRoom; X{ X uENTRY1("roomDeactivate(%s)\n",roomText(pRoom)); X if (pRoom!=NullRoom) { X if (_IsActive(pRoom)) { X pRoom->active= False; X _Feedback(pRoom,roomFBDeactivated,NullApp); X if ((!_Always(pRoom))&&_WhenActive(pRoom)&&_IsVisible(pRoom)) { X if ((!_WhenNonEmpty(pRoom))||_NoLocalApps(pRoom)) { X _SetHidden(pRoom); X _Feedback(pRoom,roomFBHidden,NullApp); X } X } X } X uRETURN(True); X } X uRETURN(False); X} X X/***====================================================================***/ X/*** MISCELLANEOUS ACCESS FUNCTIONS ***/ X/***====================================================================***/ X XStringToken XroomName(pRoom) XRoomPtr pRoom; X{ X uFLAG_ENTRY1(LOW_ENTRY_BIT,"roomName(%s)\n",roomText(pRoom)); X if (pRoom==NullRoom) { X uFLAG_RETURN(NullStringToken); X } X uFLAG_RETURN(pRoom->name); X} X X/***====================================================================***/ X Xunsigned XroomNumApps(pRoom) XRoomPtr pRoom; X{ X uFLAG_ENTRY1(LOW_ENTRY_BIT,"roomNumApps(%s)\n",roomText(pRoom)); X uFLAG_RETURN(pRoom->numApps); X} X X/***====================================================================***/ X Xunsigned XroomNumLocalApps(pRoom) XRoomPtr pRoom; X{ X uFLAG_ENTRY1(LOW_ENTRY_BIT,"roomNumLocalApps(%s)\n",roomText(pRoom)); X uFLAG_RETURN(pRoom->numLocalApps); X} X X/***====================================================================***/ X Xvoid XroomSetFeedback(pRoom,func) XRoomPtr pRoom; XRoomFeedbackFunc func; X{ X uFLAG_ENTRY2(LOW_ENTRY_BIT,"roomSetFeedback(%s,0x%x)\n",roomText(pRoom), X func); X if (pRoom!=NullRoom) { X pRoom->feedback= func; X } X uFLAG_VOIDRETURN; X} X X/***====================================================================***/ X XRoomFeedbackFunc XroomGetFeedback(pRoom) XRoomPtr pRoom; X{ X uFLAG_ENTRY1(LOW_ENTRY_BIT,"roomSetFeedback(%s)\n",roomText(pRoom)); X if (pRoom!=NullRoom) { X uFLAG_RETURN(pRoom->feedback); X } X uFLAG_RETURN((RoomFeedbackFunc)NULL); X} X X/***====================================================================***/ X Xvoid XroomSetPrivate(pRoom,priv) XRoomPtr pRoom; XOpaque priv; X{ X X uFLAG_ENTRY2(LOW_ENTRY_BIT,"roomSetPrivate(%s,0x%x)\n",roomText(pRoom), X priv); X if (pRoom!=NullRoom) { X pRoom->priv= priv; X } X uFLAG_VOIDRETURN; X} X X/***====================================================================***/ X XOpaque XroomGetPrivate(pRoom) XRoomPtr pRoom; X{ X uFLAG_ENTRY1(LOW_ENTRY_BIT,"roomGetPriv(%s)\n",roomText(pRoom)); X if (pRoom!=NullRoom) { X uFLAG_RETURN(pRoom->priv); X } X uFLAG_RETURN((Opaque)NULL); X} X X/***====================================================================***/ X Xstruct roomIterArg { X Boolean localOnly; X RoomPtr pRoom; X RoomIterFunc pFunc; X Opaque arg; X}; X Xstatic Boolean X_roomIterator(keyIn,dataIn,argIn) XGenKey keyIn; XGenData dataIn; XOpaque argIn; X{ XStringToken key= (StringToken)keyIn; XRoomAppInfoPtr pAppInfo= (RoomAppInfoPtr)dataIn; Xstruct roomIterArg *pArg= (struct roomIterArg *)argIn; X X uENTRY3("_roomIterator(%s,%s,0x%x)\n",stText(key), X roomAppInfoText(pAppInfo),pArg); X if ((!pArg->localOnly)||(_HasLocalState(pArg->pRoom,pAppInfo))) { X uRETURN((*pArg->pFunc)(pAppInfo->pApp,pAppInfo->pLocal, X pAppInfo->pDefault, X pAppInfo->pReal,pArg->arg)); X } X uRETURN(True); X} X Xvoid XroomIterateApps(pRoom,pFunc,arg) XRoomPtr pRoom; XRoomIterFunc pFunc; XOpaque arg; X{ Xstruct roomIterArg iArg; X X uENTRY3("roomIterateApps(%s,0x%x,0x%x)\n",roomText(pRoom),pFunc,arg); X if ((pRoom!=NullRoom)&&(pFunc!=NULL)) { X iArg.localOnly= False; X iArg.pRoom= pRoom; X iArg.pFunc= pFunc; X iArg.arg= arg; X (void)lIterate(pRoom->contents,_roomIterator,(Opaque)&iArg); X } X uVOIDRETURN; X} X Xvoid XroomIterateLocalApps(pRoom,pFunc,arg) XRoomPtr pRoom; XRoomIterFunc pFunc; XOpaque arg; X{ Xstruct roomIterArg iArg; X X uENTRY3("roomIterateApps(%s,0x%x,0x%x)\n",roomText(pRoom),pFunc,arg); X if ((pRoom!=NullRoom)&&(pFunc!=NULL)) { X iArg.localOnly= True; X iArg.pRoom= pRoom; X iArg.pFunc= pFunc; X iArg.arg= arg; X (void)lIterate(pRoom->contents,_roomIterator,(Opaque)&iArg); X } X uVOIDRETURN; X} END_OF_FILE if test 19920 -ne `wc -c <'./lib/room.c'`; then echo shar: \"'./lib/room.c'\" unpacked with wrong size! fi # end of './lib/room.c' fi if test -f './lib/room.h' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'./lib/room.h'\" else echo shar: Extracting \"'./lib/room.h'\" \(17316 characters\) sed "s/^X//" >'./lib/room.h' <<'END_OF_FILE' X#ifndef ROOM_H X#define ROOM_H 1 X X /*\ X * $Header: room.h,v 5.1 90/01/11 13:39:18 erik Exp $ X * X * COPYRIGHT 1990 X * DIGITAL EQUIPMENT CORPORATION X * MAYNARD, MASSACHUSETTS X * ALL RIGHTS RESERVED. X * X * THE INFORMATION IN THIS SOFTWARE IS SUBJECT TO CHANGE WITHOUT NOTICE AND X * SHOULD NOT BE CONSTRUED AS A COMMITMENT BY DIGITAL EQUIPMENT CORPORATION. X * DIGITAL MAKES NO REPRESENTATIONS ABOUT THE SUITABILITY OF THIS SOFTWARE X * FOR ANY PURPOSE. IT IS SUPPLIED "AS IS" WITHOUT EXPRESS OR IMPLIED X * WARRANTY. X * X * IF THE SOFTWARE IS MODIFIED IN A MANNER CREATING DERIVATIVE COPYRIGHT X * RIGHTS, APPROPRIATE LEGENDS MAY BE PLACED ON THE DERIVATIVE WORK IN X * ADDITION TO THAT SET FORTH ABOVE. X * X * Permission to use, copy, modify, and distribute this software and its X * documentation for any purpose and without fee is hereby granted, provided X * that the above copyright notice appear in all copies and that both that X * copyright notice and this permission notice appear in supporting X * documentation, and that the name of Digital Equipment Corporation not be X * used in advertising or publicity pertaining to distribution of the X * software without specific, written prior permission. X \*/ X X /*\ X X \*/ X X /*\ X * Methods for manipulating a Room. A Room represents a single X * room, presumably in a rooms application. This package deals X * with rooms in isolation; it does not deal with interactions X * or between multiple rooms. X * X * A room has a set of Apps whose geometry it manages. An App is X * local to a Room if the App has a room state specific to that X * Room. A Room may manage Apps that are not local to the Room, X * in which case the Room should use the App default state. The X * "visible" state of an App in a Room is the state that the Room X * tries to maintain for that App (i.e. the local state of the App X * if the App is local to the Room, the default state of the App if X * the App is managed but not local, and NullAppState if the App is X * not managed by the room). X * X * An active room tries to change the current state of the Apps it X * manages whenever that current state is out of sync with the X * visible state of the App in the Room. An inactive Room allow X * the App's current state to diverge from the Room's visible X * state for that App. X * X * App's may be managed by multiple rooms, but no more than one X * of the managing rooms should be active at any time or chaos X * may result. X * X * A Room may exist without being visible to the user (of xrooms); X * such a Room is "hidden." Any Room that is visible to the user X * is said to be "visible." Note that it is quite confusing to the X * user for an active Room to be hidden. Room visibility may be X * controlled explicitly or automatically. X * The explicit visibility controls are: X * roomVisible -- Room is visible. X * roomHidden -- Room is hidden. X * The automatic visibility controls that this package provides are: X * roomAlways -- Room is always visible. X * roomWhenActive -- Room is visible whenever it is active. X * roomWhenNonEmpty -- Room is visible whenever it has at least X * one *local* App. X * Any combination of automatic controls can be specified. X * X * This package was written to support an implementation of rooms X * under X, but it doesn't know anything about X. I relies on X * the App package to shove applications around and calls a X * Feedback function supplied by xrooms whenever the state of the X * room changes. This function should provide any feedback xrooms X * wants to give the user (highlighting the button of the active room X * or adding the button of a newly visible room, for example). X * The types of feedback reported to xrooms are: X * roomCreated, roomDestroyed, roomActivated, roomDeactivated, X * roomHidden, roomVisible, roomAppAdded, roomAppRemoved X * X * PUBLIC PACKAGE GLOBAL VARIABLE -- X * unsigned roomDebug; X * Set of debugging flags. The only flags currently defined X * is ENTER (0x10) defined in ../utils/utils.h. Intial value X * is 0. X * unsigned roomDefaultAppSlots; X * The number of slots allocated for Apps in a Room by default. X * App slots are increased dynamically, so this value isn't X * too critical. It should be a reasonable guesstimate of the X * maximum number of Apps *active* at any one time to help X * minimize allocator overhead and fragmentation. Initial X * value is 17. X * unsigned roomDefaultVisibility; X * Default visibility of newly created Rooms. Initial value X * is (roomWhenActive|roomWhenNonEmpty). X * Boolean roomIconifyFirst; X * If True, iconify all applications that need to be iconified X * before moving or opening other applications. If False, X * order is undefined. Default is True. X * X * DEBUGGGING FUNCTIONS -- X * char * X * roomText(pRoom) X * RoomPtr pRoom; X * Returns the name of "pRoom" in a static buffer which may be X * clobbered by subsequent calls to roomText. Guaranteed not X * to return NullString. X * X * void X * roomDebugPrint(pRoom) X * Prints scads of useful debugging information about "pRoom" X * using uDebug (which usually writes to stderr). X * X * FUNCTIONS TO CREATE AND DESTROY ROOMS -- X * RoomPtr X * roomCreate(name,private,feedback) X * StringToken name; X * Opaque private; X * RoomFeedbackFunc feedback. X * Creates a room with the specified name, private field and X * feedback function. The new Room manages no applications X * and has default visibility. X * X * Calls "feedback" (if non-NULL) to note "roomCreated." X * X * Returns a pointer to the newly created Room or NullRoom X * if name is NullStringToken or there is an allocation failure. X * X * void X * roomDestroy(pRoom) X * RoomPtr pRoom; X * Destroys "pRoom" and frees any memory it uses. roomDestroy X * first deactivates the the Room if active, then hides the X * room if visible, and then finally destroys the room and X * frees any memory it uses. The feedback function is called X * separately for the deactivation, the hide and the destroy X * as appropriate. No return value. X * X * FUNCTIONS TO CHANGE OR QUERY THE SET OF MANAGED APPLICATIONS -- X * Boolean X * roomManageApp(pRoom,pApp) X * RoomPtr pRoom; X * AppPtr pApp; X * Start managing "pApp" in "pRoom." Queries "pApp" for X * local, default, and current state. X * X * May call the feedback function if "pRoom" becomes visible X * because it is no longer empty. X * X * Calls the feedback function to note "roomAppAdded" X * X * Returns True for success, False if "pRoom" is NullRoom, X * "pApp" is NullApp, or if "pApp" (or another App with the X * same name) is already managed in "pRoom." A Room may *not* X * manage multiple Apps with the same name. X * X * Boolean X * roomUnmanageApp(pRoom,pApp) X * RoomPtr pRoom; X * AppPtr pApp; X * Stop managing "pApp" in "pRoom." X * X * Calls the feedback function to note "roomAppRemoved" X * X * May call the feedback function if "pRoom" is hidden because X * the last local App is removed. X * X * Returns True for success, False if "pRoom" is NullRoom, X * "pApp" is NullApp, or "pApp" is not being managed by "pRoom." X * X * AppPtr X * roomLookupManagedApp(pRoom,appName) X * RoomPtr pRoom; X * StringToken appName; X * Returns a pointer to the App named "appName" being managed X * by "pRoom," or NullApp if "pRoom" is NullRoom, "appName" X * is NullStringToken, or "pRoom" does not manage an App named X * "appName." A Room may *not* manage more than one App with X * the same name. X * X * FUNCTIONS TO CHANGE, CHECK, OR QUERY THE STATE OF AN APP IN A ROOM X * Boolean X * roomAppRealStateChanged(pRoom,pApp,pReal) X * RoomPtr pRoom; X * AppPtr pApp; X * AppStatePtr pReal; X * Note that the real state of "pApp" has changed, and that the X * change should be reflected in "pRoom." If "pApp" has a state X * local to "pRoom", the local state is updated to reflect the X * changes in pReal. If "pApp" does not have a state local to X * "pRoom," roomAppRealStateChanged creates a new local state X * and modifies to reflect the values in "pReal." X * X * Note that any bolted values in the local or default state will X * *not* be changed to reflect "pReal." See appstate.h and app.h X * for a more complete discussion of copying or matching <real> X * and <profile> states and of bolts. X * X * If "pRoom's" visibility changes due to a change in the number X * of local apps, roomAppRealStateChanged calls the feedback X * function to note the change. X * X * If "pRoom" is active, and "pReal" does not match the new X * local state (i.e. if any fields in the local state are X * bolted and different than "pReal"), roomAppRealStateChanged X * (re)sets the current state of "pApp" to reflect the new X * local state. X * X * Returns True for success, False if "pRoom" is NullRoom, X * "pApp" is NullApp, "pReal" is not a legal <real> state, X * "pApp" is not managed in "pRoom," or if an allocation X * failure occurs. X * X * Boolean X * roomChangeAppLocalState(pRoom,pApp,pProf) X * RoomPtr pRoom; X * AppPtr pApp; X * AppStatePtr pProf; X * Change the local state of "pApp" to "pProf." If "pApp" X * does not have a state local to "pRoom," a new local state is X * created and "pProf" is copied into it. Note that X * roomChangeAppLocalState does *not* respect bolts. X * X * If "pRoom" is active, and the current real state of "pApp" X * does not match "pProf," roomChangeAppLocalState tries X * to reset the current state to match the new local state. X * X * If "pRoom's" visibility changes due to a change in the number X * of local apps, roomChangeAppLocalState calls the feedback X * function to note the change. X * X * Returns True for success, False if "pRoom" is NullRoom, X * "pApp" is NullApp, "pProf" is not a legal <profile> X * state, "pApp" is not managed in "pRoom," or an allocation X * fails. X * X * Boolean X * roomCheckAppStates(pRoom,pApp) X * RoomPtr pRoom; X * AppPtr pApp; X * Check the current, local, and default states of "pApp" in X * "pRoom" to make sure they are up to date. X * X * If "pRoom" is active and the re-synchronized current state X * does not match the visible state, roomCheckAppStates X * updates the current state. X * X * Use this function to update a Room whenever some other package X * has changed "pApp." X * X * If room visibility changes (due to a change in the number of X * local Apps), roomCheckAppState calls the feedback func. X * X * Returns True for success, False if "pRoom" is NullRoom, X * "pApp" is NullApp, or "pRoom" does not manage "pApp." X * X * AppStatePtr X * roomGetVisibleState(pRoom,pApp) X * RoomPtr pRoom; X * AppPtr pApp; X * Returns the visible state of "pApp" in "pRoom," or False X * if "pRoom" is NullRoom, "pApp" is NullApp, or "pApp" is X * not managed in "pRoom." X * X * FUNCTIONS TO CHANGE/QUERY ROOM VISIBILITY -- X * Boolean X * roomIsVisible(pRoom) X * RoomPtr pRoom; X * Returns True if "pRoom" is visible, False if "pRoom" is X * NullRoom or hidden. X * X * Boolean X * roomSetVisibility(pRoom,visibility,check) X * RoomPtr pRoom; X * Boolean visibility; X * Boolean check; X * Change the visibility of "pRoom" to "visibility." If X * "check" is True, roomSetVisibility checks for the X * automatic visibility controls roomAlways, roomWhenActive, X * and roomWhenNonEmpty and sets Visible/Hidden appropriately. X * Calls feedback if visibility changes. X * Returns True for success, False if "pRoom" if NullRoom. X * X * Boolean X * roomCheckVisibility(pRoom) X * RoomPtr pRoom; X * Check to make sure that the visibility of "pRoom" is X * correct with respect to any automatic visibility controls X * defined for "pRoom." If visibility is incorrect, X * roomCheckVisibility corrects visibility and calls the X * feedback function. X * X * Returns True for success, False if "pRoom" is NullRoom. X * X * unsigned X * roomGetVisibility(pRoom) X * RoomPtr pRoom; X * Returns the visibility of "pRoom," or roomHidden if "pRoom" X * is NullRoom. X * X * FUNCTIONS TO ACTIVATE/DEACTIVATE A ROOM -- X * Boolean X * roomIsActive(pRoom) X * RoomPtr pRoom; X * Returns True if "pRoom" is not NullRoom and is active, False X * otherwise. X * X * Boolean X * roomActivate(pRoom) X * RoomPtr pRoom; X * Activates "pRoom." If "pRoom" is inactive, roomActivate X * checks the current state of all Apps managed by "pRoom" and X * changes any that don't match their visible state in "pRoom." X * Calls the feedback function if visibility changes, and again X * if "pRoom" was not active. X * X * Returns True for success, False if "pRoom" is NullRoom. X * X * Boolean X * roomDeactivate(pRoom) X * RoomPtr pRoom; X * Deactivates "pRoom." Does not change the state of any X * Apps. Calls the feedback function if visibility changes and X * if "pRoom" was active. X * Returns True for success, False if "pRoom" is NullRoom. X * X * X * MISCELLANEOUS ACCESS FUNCTIONS -- X * StringToken X * roomName(pRoom) X * RoomPtr pRoom; X * Returns the name of "pRoom," or NullStringToken if "pRoom" X * is NullRoom. X * X * unsigned X * roomNumApps(pRoom) X * RoomPtr pRoom; X * Returns the number of Apps managed by "pRoom," or 0 if X * pRoom is NullRoom. X * X * unsigned X * roomNumLocalApps(pRoom); X * RoomPtr pRoom; X * Returns the number of managed Apps that have a state local to X * "pRoom," or 0 if pRoom is NullRoom. X * X * void X * roomSetFeedback(pRoom,pFunc) X * RoomPtr pRoom; X * RoomFeedbackFunc pFunc; X * Set the feedback function of "pRoom" to "pFunc." No X * return value. X * X * RoomFeedbackFunc X * roomGetFeedback(pRoom) X * RoomPtr pRoom; X * Returns the feedback function of "pRoom," or NULL if X * "pRoom" is NullRoom. X * X * void X * roomSetPrivate(pRoom,priv) X * RoomPtr pRoom; X * Opaque priv; X * Sets the private value associated with "pRoom" to X * "priv." No return value. X * X * Opaque X * roomGetPrivate(pRoom) X * RoomPtr pRoom; X * Returns the private value associated with "pRoom," or X * NULL if pRoom is NullRoom. X * X * ITERATORS X * void X * roomIterateApps(pRoom,pFunc,arg) X * RoomPtr pRoom; X * RoomIterFunc pFunc; X * Opaque arg; X * Calls "pFunc" with (pApp,pLocal,pDflt,pReal) for each of the X * Apps managed by "pRoom" in turn. Stops iterating if X * "pFunc" returns False. X * X * void X * roomIterateLocalApps(pRoom,pFunc,arg) X * RoomPtr pRoom; X * RoomIterFunc pFunc; X * Opaque arg; X * Calls "pFunc" with (pApp,pLocal,pDflt,pReal) for each of the X * Apps with a local state in "pRoom" in turn. Stops iterating X * if "pFunc" returns False. X * X \*/ X X#include "strtbl.h" X#include "app.h" X Xtypedef struct _RoomRec *RoomPtr; X#define NullRoom ((RoomPtr)NULL) X Xtypedef void (*RoomFeedbackFunc)(/* pRoom, newState, pApp */); Xtypedef Boolean (*RoomIterFunc)(/* pApp, pLocal, pDflt, pReal, arg */); X X /* X * Types of feedback X */ X#define roomFBCreated ((unsigned)1<<0) X#define roomFBDestroyed ((unsigned)1<<1) X#define roomFBActivated ((unsigned)1<<2) X#define roomFBDeactivated ((unsigned)1<<3) X#define roomFBHidden ((unsigned)1<<4) X#define roomFBVisible ((unsigned)1<<5) X#define roomFBAppAdded ((unsigned)1<<6) X#define roomFBAppRemoved ((unsigned)1<<7) X X /* X * Settings for Room visibility X */ X#define roomHidden ((unsigned)0) X#define roomVisible ((unsigned)1<<0) X#define roomWhenNonEmpty ((unsigned)1<<1) X#define roomWhenActive ((unsigned)1<<2) X#define roomAlways ((unsigned)1<<3) X X /* X * public package globals X */ X#define ROOM_DEFAULT_APP_SLOTS 17 X#define ROOM_DEFAULT_VISIBILITY (roomWhenActive|roomWhenNonEmpty) Xextern unsigned roomDebug; Xextern unsigned roomDefaultAppSlots; Xextern unsigned roomDefaultVisibility; Xextern Boolean roomIconifyFirst; X Xextern char *roomText(/* pRoom */); Xextern void roomDebugPrint(/* pRoom */); X Xextern RoomPtr roomCreate(/* name, priv, feedback */); Xextern void roomDestroy(/* pRoom */); X Xextern Boolean roomManageApp(/* pRoom, pApp */); Xextern Boolean roomUnmanageApp(/* pRoom,pApp */); Xextern AppPtr roomLookupManagedApp(/*pRoom,appName*/); X Xextern Boolean roomAppRealStateChanged(/* pRoom, pApp, pReal */); Xextern Boolean roomChangeAppLocalState(/* pRoom, pApp, pProf */); Xextern Boolean roomCheckAppStates(/* pRoom, pApp */); Xextern AppStatePtr roomGetVisibleState(/* pRoom, pApp */); X Xextern Boolean roomIsVisible(/* pRoom */); Xextern Boolean roomSetVisibility(/* pRoom, visibility, check */); Xextern unsigned roomGetVisibility(/* pRoom */); X Xextern Boolean roomIsActive(/* pRoom */); Xextern Boolean roomActivate(/* pRoom */); Xextern Boolean roomDeactivate(/* pRoom */); X Xextern StringToken roomName(/* pRoom */); Xextern unsigned roomNumApps(/* pRoom */); Xextern unsigned roomNumLocalApps(/* pRoom */); Xextern void roomSetFeedback(/* pRoom, pFunc */); Xextern RoomFeedbackFunc roomGetFeedback(/* pRoom */); Xextern void roomSetPrivate(/* pRoom, priv */); Xextern Opaque roomGetPrivate(/* pRoom */); X Xextern void roomIterateApps(/* pRoom, pFunc, arg */); Xextern void roomIterateLocalApps(/* pRoom, pFunc, arg */); X#endif /* ROOM_H */ END_OF_FILE if test 17316 -ne `wc -c <'./lib/room.h'`; then echo shar: \"'./lib/room.h'\" unpacked with wrong size! fi # end of './lib/room.h' fi echo shar: End of archive 10 \(of 14\). cp /dev/null ark10isdone MISSING="" for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 ; do if test ! -f ark${I}isdone ; then MISSING="${MISSING} ${I}" fi done if test "${MISSING}" = "" ; then echo You have unpacked all 14 archives. rm -f ark[1-9]isdone ark[1-9][0-9]isdone else echo You still need to unpack the following archives: echo " " ${MISSING} fi ## End of shell archive. exit 0