home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Utilities / Ph 1.1.1 / PhClient / wstm.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-09-04  |  4.3 KB  |  142 lines  |  [TEXT/MPS ]

  1. /*______________________________________________________________________
  2.  
  3.     wstm.c - Window State Module
  4. _____________________________________________________________________*/
  5.  
  6.  
  7. #pragma load "precompile"
  8. #include "utl.h"
  9. #include "glob.h"
  10. #include "wstm.h"
  11. #include "oop.h"
  12.  
  13. #pragma segment wstm
  14.  
  15. /*______________________________________________________________________
  16.  
  17.     wstm_Save - Save Window State.
  18.     
  19.     Entry:    theWindow = window pointer.
  20.                 windState = pointer to WindState struct.
  21.                     
  22.     Exit:        window state information saved in WindState structure.
  23. _____________________________________________________________________*/
  24.  
  25. void wstm_Save (WindowPtr theWindow, WindState *windState)
  26.  
  27. {
  28.     if (!windState->moved) windState->moved = oop_Moved(theWindow);
  29.     if (windState->moved) {
  30.         utl_SaveWindowPos(theWindow, &windState->userState, &windState->zoomed);
  31.     }
  32. }
  33.  
  34. /*______________________________________________________________________
  35.  
  36.     wstm_ComputeStd - Compute a Window's Standard State.
  37.     
  38.     Entry:    theWindow = pointer to window.
  39.     
  40.     Exit:        computed standard state stored in state data block.
  41.     
  42.     See TN 79.
  43. _____________________________________________________________________*/
  44.  
  45. void wstm_ComputeStd (WindowPtr theWindow)
  46.  
  47. {
  48.     WindowPeek        w;                    /* window pointer */
  49.     WStateData        **stateData;    /* handle to zoom state data */
  50.     GDHandle            gd;                /* handle to gdevice containing window */
  51.     Rect                zoomRect;        /* rect to zoom to */
  52.     Rect                windRect;        /* window rect in global coords */
  53.     Boolean            hasMB;            /* true if window contains menu bar */
  54.     short                windWidth;        /* width of window */
  55.     
  56.     w = (WindowPeek)theWindow;
  57.     if (!(w->dataHandle && w->spareFlag)) return;
  58.     utl_GetWindGD(theWindow, &gd, &zoomRect, &windRect, &hasMB);
  59.     zoomRect.top += titleBarHeight + zoomSlop + 
  60.         (hasMB ? utl_GetMBarHeight() : 0);
  61.     zoomRect.bottom -= 3;
  62.     stateData = (WStateData**)w->dataHandle;
  63.     windWidth = windRect.right - windRect.left;
  64.     if (zoomRect.left <= windRect.left &&
  65.         windRect.right <= zoomRect.right) {
  66.         zoomRect.left = (**stateData).userState.left;
  67.         zoomRect.right = zoomRect.left + windWidth;
  68.     } else if (windRect.right > zoomRect.right) {
  69.         zoomRect.right -= 3;
  70.         zoomRect.left = zoomRect.right - windWidth;
  71.     } else {
  72.         zoomRect.left += 3;
  73.         zoomRect.right = zoomRect.left + windWidth;
  74.     }
  75.     (**stateData).stdState = zoomRect;
  76. }
  77.  
  78. /*______________________________________________________________________
  79.  
  80.     ComputeDef - Compute a Window's Default State.
  81.     
  82.     Entry:    theWindow = pointer to window.
  83.     
  84.     Exit:        userState = computed state rectangle (location and size).
  85. _____________________________________________________________________*/
  86.  
  87. static void ComputeDef (WindowPtr theWindow, Rect *userState)
  88.  
  89. {
  90.     Point            pos;            /* window position */
  91.     
  92.     *userState = theWindow->portRect;
  93.     if (((WindowPeek)theWindow)->spareFlag) {
  94.         utl_StaggerWindow(userState, staggerInitial, staggerOffset, &pos);
  95.         OffsetRect(userState, pos.h, pos.v);
  96.     } else {
  97.         userState->top -= titleBarHeight;
  98.         utl_CenterDlogRect(userState, true);
  99.         userState->top += titleBarHeight;
  100.     }
  101. }
  102.  
  103. /*______________________________________________________________________
  104.  
  105.     wstm_Restore - Restore Window State.
  106.     
  107.     Entry:    dlog = true if dialog window, false if regular window.
  108.                 windID = resource ID of window template.
  109.                 wStorage = pointer to window storage, or nil.
  110.                 windState = pointer to saved window state.
  111.                     
  112.     Exit:        function result = pointer to window, positioned and sized.
  113. _____________________________________________________________________*/
  114.  
  115. WindowPtr wstm_Restore (Boolean dlog, short windID, Ptr wStorage,
  116.     WindState *windState)
  117.  
  118. {
  119.     WindowPtr        theWindow;            /* pointer to window */
  120.     Rect                userState;            /* user state rectangle */
  121.     
  122.     theWindow = dlog ?
  123.         GetNewDialog(windID, wStorage, (WindowPtr)-1) :
  124.         utl_GetNewWindow(windID, wStorage, (WindowPtr)-1);
  125.     if (!windState->moved) {
  126.         ComputeDef(theWindow, &userState);
  127.         MoveWindow(theWindow, userState.left, userState.top, false);
  128.         SizeWindow(theWindow, userState.right-userState.left,
  129.             userState.bottom-userState.top, true);
  130.     } else {
  131.         if (!((WindowPeek)theWindow)->spareFlag) {
  132.             windState->userState.right = windState->userState.left +
  133.                 theWindow->portRect.right;
  134.             windState->userState.bottom = windState->userState.top +
  135.                 theWindow->portRect.bottom;
  136.         }
  137.         utl_RestoreWindowPos(theWindow, &windState->userState, windState->zoomed,
  138.             dragSlop, wstm_ComputeStd, ComputeDef);
  139.     }
  140.     return theWindow;
  141. }
  142.