uiscrn.c
上传用户:xiaoan1112
上传日期:2013-04-11
资源大小:19621k
文件大小:9k
源码类别:

操作系统开发

开发平台:

Visual C++

  1. /*** 
  2. *uiscrn.c - screen management functions.
  3. *
  4. * Copyright <C> 1985-1988, Microsoft Corporation
  5. *
  6. *Purpose:
  7. * Miscellaneous procedures to interface QB with CW screen operations.
  8. *
  9. *******************************************************************************/
  10. /* First, include version definition header */
  11. #include <version.h>
  12. /* Next, include TextWin's interface headers */
  13. #include <cw/version.h>
  14. #include <cw/windows.h>
  15. #include <cw/edityp.h>
  16. /* Next, include QBI's headers */
  17. #ifndef QBIMSGS_H
  18. #include <qbimsgs.h>
  19. #endif
  20. #ifndef UI_H
  21. #include <ui.h>
  22. #endif
  23. #ifndef UIINT_H
  24. #include <uiint.h>
  25. #endif
  26. #ifndef HEAP_H
  27. #include <heap.h>
  28. #endif
  29. void far EnsShowDebugScrFar(void);
  30. void far ShowOutScr(void);
  31. void far EnsMouseOff(void);
  32. void far TossOutputScreen(void);
  33. void near Cls (void);
  34. void near SaveUserMouse(void);
  35. void near RestoreUserMouse(void);
  36. extern bool FAR PASCAL FInitMouse(void); //[17]
  37. extern void FAR PASCAL EndMouse(void); //[17]
  38. extern void FAR PASCAL SetBlinkBit(ushort);
  39. bool fDebugScr = FALSE;             /* TRUE if debug screen is visible,
  40.        FALSE if Output Screen is visible */
  41. extern WORD iModeCurrent;
  42. bd bdVids = {0, NULL, 0};
  43. bd bdVidsDebug = {0, NULL, 0};
  44. bdl bdlVidData = {0, NOT_OWNER, 0, 0};
  45. bdl bdlUserMouse = {0, NOT_OWNER, 0, 0}; //[17]
  46. /*** 
  47. *void near Cls ()
  48. *Purpose:
  49. * Clear the output screen.  This is used if we couldn't restore the
  50. * output screen.
  51. *
  52. *Entry:
  53. * None.
  54. *
  55. *Exit:
  56. * None.
  57. *
  58. *Exceptions:
  59. * None.
  60. *******************************************************************************/
  61. void near Cls ()
  62. {
  63.     RRC rrc;
  64.     rrc.rxLeft = rrc.ryTop = 0;
  65.     rrc.rxRight = axMac;
  66.     rrc.ryBottom = ayMac;
  67.     FillRrc (NULL, &rrc, ' ', isaBackground);
  68. }
  69. /*** 
  70. *void near SaveUserMouse
  71. *Purpose:
  72. * Saves the mouse state of the User's mouse
  73. *
  74. * New for revision [17]
  75. *
  76. *Entry:
  77. *
  78. *Exit:
  79. *
  80. *Exceptions:
  81. * None.
  82. *******************************************************************************/
  83. void near SaveUserMouse()
  84. {
  85.     WORD cbMouse;
  86.     BdlFree(&bdlUserMouse);
  87.     cbMouse = CbSizeMouseState();
  88.     if (cbMouse && BdlAlloc (&bdlUserMouse, cbMouse)) {
  89.        SaveMouseState((void FAR *) MAKELONG (0, GETSEG (bdlUserMouse.seg)));
  90.     }
  91. }
  92. /*** 
  93. *void near RestoreUserMouse
  94. *Purpose:
  95. * Restores the mouse state of the user's mouse
  96. *
  97. * New for revision [17]
  98. *
  99. *Entry:
  100. *
  101. *Exit:
  102. *
  103. *Exceptions:
  104. * None.
  105. *******************************************************************************/
  106. void near RestoreUserMouse()
  107. {
  108.     if (bdlUserMouse.seg != NOT_OWNER) {
  109.        RestoreMouseState((void FAR *) MAKELONG (0, GETSEG (bdlUserMouse.seg)));
  110.        BdlFree(&bdlUserMouse);
  111.     }
  112. }
  113. /*** 
  114. *void near SaveUserScreen ()
  115. *Purpose:
  116. * Save the contents of the output screen.
  117. *
  118. * If we don't have enough room for the screen data, we still save the
  119. * mode information so we can at least change modes and clear the screen
  120. * properly.
  121. *
  122. *Entry:
  123. * bdVids Is a bd to be used for the mode structure data.
  124. * bdlVidData Is a bdl to be used for the screen contents.
  125. *
  126. *Exit:
  127. * bdVids and bdlVidData contain the information from the output
  128. * screen if there is room to store them.
  129. *
  130. *Exceptions:
  131. * None.
  132. *******************************************************************************/
  133. void near SaveUserScreen ()
  134. {
  135.     INST inst;
  136.     WORD cbVids;
  137.     if ((cbVids = CbSizeVids ()) == 0)
  138. return; //[17]
  139.     if (!BdAlloc (&bdVids, cbVids, IT_NO_OWNERS))
  140. return; //[17]
  141.     if (!FQueryInst (&inst, iModeCurrent)) /* [3] */
  142. DbAssert (FALSE);
  143.     if (!FSaveVids ((VIDS *)bdVids.pb, &inst)) { //[12]
  144. DbAssert (FALSE);
  145.     }
  146.     if (BdlAlloc (&bdlVidData, ((VIDS *)bdVids.pb)->cwVidData * sizeof (WORD))) //[12]
  147. SaveVidData ((VIDS *)bdVids.pb, (WORD FAR *) MAKELONG (0, GETSEG (bdlVidData.seg))); //[12]
  148.     else
  149. // Must free, as FRestoreVids doesn't clear and leaves junk on screen.
  150. BdFree (&bdVids);
  151.     if (bdVidsDebug.pb != NULL)  // [6]
  152. if (!FRestoreVids ((VIDS *) bdVidsDebug.pb)) // [6]
  153.     DbAssert (FALSE); // [6]
  154.     
  155.     SetBlinkBit(0);
  156. }
  157. /*** 
  158. *void near RestoreUserScreen ()
  159. *Purpose:
  160. * Restore the output screen from previously stored data in
  161. * SaveUserScreen.
  162. *
  163. *Entry:
  164. * bdVids Global data pertaining to the mode and screen overhead.
  165. * bdVidData Global data containing the screen contents.
  166. *
  167. *Exit:
  168. * None.
  169. *
  170. *Exceptions:
  171. * None.
  172. *******************************************************************************/
  173. void near RestoreUserScreen ()
  174. {
  175.     INST inst;
  176.     WORD cbVids;
  177.     BdFree (&bdVidsDebug); // [6]
  178.     if ((cbVids = CbSizeVids ()) == 0) // [6]
  179. goto FailRestore; // [6]
  180.     if (!BdAlloc (&bdVidsDebug, cbVids, IT_NO_OWNERS)) // [6]
  181. goto FailRestore; // [6]
  182.     if (!FQueryInst (&inst, iModeCurrent)) // [6]
  183. DbAssert (FALSE); // [6]
  184.     if (!FSaveVids ((VIDS *) bdVidsDebug.pb, &inst)) // [6]
  185. DbAssert (FALSE); // [6]
  186.     if (bdVids.pb == NULL) { //[12]
  187. FailRestore: // [6]
  188. Cls ();
  189. return;
  190.     }
  191.     if (!FRestoreVids ((VIDS *) bdVids.pb)) { //[12]
  192. DbAssert (FALSE);
  193.     }
  194.     // [5] May not have data, but restored mode if possible.
  195.     else if (bdlVidData.seg != NOT_OWNER) {
  196. RestoreVidData ((VIDS *)bdVids.pb, //[12]
  197. (WORD FAR *) MAKELONG (0, GETSEG (bdlVidData.seg)));
  198.     }
  199.     TossUserScreen();
  200. }
  201. void near TossUserScreen ()
  202. {
  203.     BdFree (&bdVids);
  204.     BdlFree (&bdlVidData);
  205. }
  206. void far EnsShowDebugScrFar ()
  207. {
  208.     EnsShowDebugScr ();
  209.     FEnableMouse(TRUE); //[17]
  210. }
  211. /*** 
  212. *void near EnsShowDebugScr ()
  213. *Purpose:
  214. * If the debug screen is not already visible, save the user screen.
  215. *
  216. *Entry:
  217. * None.
  218. *
  219. *Exit:
  220. * None.
  221. *
  222. *Exceptions:
  223. * None.
  224. *******************************************************************************/
  225. void near EnsShowDebugScr ()
  226. {
  227.     if (!fDebugScr) {
  228. /* Output screen is currently visible */
  229. fDebugScr = TRUE;
  230.       
  231. /* put screen in User Interface compatible (text) mode.
  232.  * User's screen may have been in high or low-res graphics mode.
  233.  * Don't save user's screen image if memory is so low that
  234.  * there's not enough to execute a SYSTEM, CLEAR, or SETMEM statement.
  235.  * This is ensured by calling UiGrabSpace first.
  236.  */
  237. UiGrabSpace();
  238. SaveUserMouse(); //[17]
  239. EndMouse(); //[17] This will turn off the user's mouse so
  240. //[17] it won't get saved by SaveUserScreen
  241. SaveUserScreen ();
  242. UiReleaseSpace();
  243. FInitMouse(); //[17]
  244. DrawDebugScr (); //[16]
  245.     }
  246. }
  247. /**************************************************************************
  248. * void near EnsShowOutSaveRs()
  249. * Purpose:
  250. *  If the output screen is not already
  251. *  visible, switch  to saved  output screen mode and copy
  252. *  the buffer saved by EnsShowDebugScr() to video ram.
  253. *  Unlike EnsShowOutputScr, this function DOES NOT flush the edit manager's
  254. *  buffer, and thus, perserves the caller's register set.
  255. *
  256. **************************************************************************/
  257. void near EnsShowOutSaveRs()
  258. {
  259.     if (fDebugScr) {
  260. fDebugScr = FALSE;
  261. /* Restore the user screen */
  262. RestoreUserScreen ();
  263. RestoreUserMouse(); //[17]
  264.     }
  265. }
  266. /**************************************************************************
  267. * ShowOutScr
  268. * Purpose:
  269. *  called by PRINT, CALL executors that want to force the user's screen
  270. *  to be restored.
  271. *
  272. **************************************************************************/
  273. void far ShowOutScr ()
  274. {
  275.     EnsShowOutSaveRs ();
  276. }
  277. /**************************************************************************
  278. * EnsMouseOff
  279. * Purpose:
  280. *  Called by runtime initialization code just before a call to B$RUNINI
  281. *  to turn the mouse off so it won't leave a ghost cursor when it clears
  282. *  the screen.
  283. *
  284. **************************************************************************/
  285. void far EnsMouseOff ()
  286. {
  287.     FEnableMouse(FALSE); //[17]
  288. }
  289. /**************************************************************************
  290. * TossOutScreen()
  291. * Purpose:
  292. *  The runtime has changed screen modes while the debug screen was active.
  293. *  We need to change state to be consistent with the output screen being active.
  294. *  Output screen and mouse will be resaved by the next call to EnsShowDebugScr.
  295. *
  296. **************************************************************************/
  297. void far TossOutputScreen ()
  298. {
  299.     TossUserScreen (); /* release memory used to save output scr */
  300.     fDebugScr = FALSE;
  301. }
  302. /**************************************************************************
  303. * void near EnsShowOutputScr()
  304. * Purpose:
  305. *  If the output screen is not already
  306. *  visible, switch  to saved  output screen mode and copy
  307. *  the buffer saved by EnsShowDebugScr() to video ram.
  308. *  Unlike EnsShowOutSaveRs, this function flushes the edit manager's
  309. *  buffer, and thus, may alter caller's register set.
  310. *
  311. **************************************************************************/
  312. void near EnsShowOutputScr ()
  313. {
  314.     EditMgrFlush ();
  315.     /* so dirty buffer can never be written to user's screen by edit mgr */
  316.     EnsShowOutSaveRs ();
  317. }