home *** CD-ROM | disk | FTP | other *** search
/ Borland Programmer's Resource / Borland_Programmers_Resource_CD_1995.iso / code / bcpp / file18 / xpwindlg.doc < prev   
Encoding:
Text File  |  1995-05-19  |  16.4 KB  |  382 lines

  1.                TExplodeWindow and TExplodeDialog Classes
  2.  
  3.                              Eric Woodruff
  4.                           16719 Lakeside Drive
  5.                          Medical Lake WA 99022
  6.  
  7.                            CIS ID: 72134,1150
  8.  
  9.          Copyright (c) 1993, Eric Woodruff, All rights reserved
  10.  
  11.                          Released: Wed 08/25/93
  12. -------------------------------------------------------------------------------
  13.  
  14. Description
  15. ===========
  16.     These two classes will allow you to add exploding windows and dialog
  17. boxes to your applications.  They are used exactly like normal TWindow
  18. and TDialog objects at instantiation with the exception of their names:
  19. TExplodeWindow and TExplodeDialog.  Once inserted into the desktop, they
  20. will explode when opened (or shown with the show() function) and implode
  21. when closed (or hidden with the hide() function).  This is all done
  22. automatically by the required overridden functions within each class.
  23. Both classes are fully streamable and can reside in a resource file
  24. until needed if you want them to.
  25.  
  26.     IF YOU USE THESE CLASSES IN YOUR OWN PROGRAMS AND APPLICATIONS,
  27. PLEASE SEND $10 TO ERIC WOODRUFF AT THE ABOVE ADDRESS.  It would be very
  28. much appreciated and I'll try and keep you informed of any bug fixes or
  29. updates.
  30.     Feel free to distribute these files to anyone but, if you do, please
  31. distribute ALL files received in their original UNMODIFIED form
  32. including all source, documentation, executables, and copyright notices.
  33. You may distribute and/or sell any executable which results from using
  34. this code but you may NOT include any source code or library of this
  35. software in part on in whole with any product that is distributed and/or
  36. sold by you.
  37.     If you DO modify the source, make any interesting modifications or
  38. additions, or find any bugs, PLEASE notify me and let me know what you
  39. changed so that I can maintain these classes and distribute the updates.
  40. I can be reached by mail or on CompuServe at the above noted addresses.
  41. Again, if you distribute this set of files, please do so in their original,
  42. unmodified form including all source files and documentation.  Thank
  43. you.
  44.     THIS CODE IS PROVIDED AS-IS AND WITHOUT ANY WARRANTY.  I WILL NOT BE
  45. RESPONSIBLE FOR ANY DAMAGE OR LOSS YOU INCUR THROUGH USE OF THE CODE IN
  46. THESE CLASSES.
  47.  
  48. Files you should receive in XPWNDG.ZIP
  49. ======================================
  50. XPWINDLG.DOC        -  This document containing the instructions.
  51. BLDRSC.CPP          -  Source file for the demo program resource file builder.
  52. BLDRSC.PRJ          -  Project file for the demo program resource file builder.
  53. BLDRSC.EXE          -  Executable for BLDRSC.CPP.
  54. EXPDEMO.H           -  Header file for the demo.
  55. EXPDEMO.CPP         -  Source file for the demo program.
  56. EXPDEMO.PRJ         -  Project file for the demo.
  57. EXPDEMO.EXE         -  Executable for EXPDEMO.CPP.
  58. EXPDEMO.RSC         -  Resource file for the demo.
  59. TEXPLODE.H          -  Header file for TExplodeWindow and TExplodeDialog.
  60. TEXPWIN.CPP         -  Source file for TExplodeWindow.
  61. TEXPDLG.CPP         -  Source file for TExplodeDialog.
  62. TEXPLODE.PRJ        -  Project file used to make TEXPLODE.LIB.
  63. TEXPLODE.LIB        -  Library for inclusion in your Turbo Vision projects.
  64.  
  65.     If your copy is incomplete, you can find a full copy in the BCPPDOS
  66. forum on CompuServe in the Turbo Vision library section.
  67.  
  68. -------------------------------------------------------------------------------
  69.  
  70. Class Descriptions
  71. ==================
  72.     Both classes are basically the same and both have the same member
  73. functions.  The only differences are that one class is a window and the
  74. other is a dialog box, and the underlying code for each does differ
  75. slightly in some cases.  However, the member functions and variables are
  76. identical in usage so one description will do for both classes.
  77.  
  78.     The following section describes the constructors and inline
  79. functions used to instantiate and manipulate the exploding windows and
  80. dialog boxes.  These are the only functions you need to know about in
  81. order to use these classes.  As stated above, all the internal details
  82. automatically handle the explosion and implosion processes.
  83.  
  84.  
  85. TExplodeWindow(const TRect &r, const char *aTitle, short aNumber)
  86. TExplodeDialog(const TRect &r, const char *aTitle)
  87. =================================================================
  88.     These are the constructors for the exploding window and dialog
  89. classes respectively.  Each will invoke the constructor for its base
  90. classes with the given parameters and set themselves to explode and
  91. implode with a default rate of 20ms between draws.
  92.  
  93. inline void MakeItNormal(void)
  94. ==============================
  95.     Call this inline function to suppress the explode/implode process.
  96. If called before being inserted into the desktop or calling the show()
  97. function when hidden, the object will not explode into view and will not
  98. implode on closing.  If called before the window is closed or hidden,
  99. the window will not implode on closing (it won't explode if shown after
  100. a hide() either).  In either case, the window or dialog box will act
  101. like its base class again.
  102.  
  103. inline void MakeItExplode(short ms)
  104. ===================================
  105.     This function is the opposite of the MakeItNormal() function.  It
  106. also has the added feature of allowing you to change the default delay
  107. rate from 20ms to your own desired value.  A valid range is from 0 to
  108. 32767, but usually a number less than 100 will suffice.
  109.     By default, the windows and dialog boxes will explode and implode
  110. automatically with a default rate of 20ms.  If this is sufficient, you
  111. will not need to call this function at all.
  112.  
  113. inline short GetDelay(void)
  114. ===========================
  115.     As its name implies, this inline function returns the current draw
  116. delay rate.
  117.  
  118.  
  119.  
  120.     The following section describes the overridden functions that allow
  121. the the windows and dialog boxes to explode and implode correctly.  It
  122. is included for information only and none of the variables or functions
  123. should be used or called directly under normal circumstances with the
  124. exception of the setState(), sizeLimits(), and maybe the changeBounds()
  125. functions.
  126.  
  127. Private:
  128. ========
  129.  
  130. Boolean  WillExplode, WillImplode, Is_Exploding_Imploding
  131. =========================================================
  132.     These private variables indicate whether or not the window or dialog
  133. will explode or implode and also whether or not the object is currently
  134. in the process of doing one or the other.  They are all used internally
  135. by the classes.
  136.  
  137. short msDelay
  138. =============
  139.     This private variable controls the delay used between draws when the
  140. object explodes or implodes.  It is set in millisecond increments by the
  141. constructor or the MakeItExplode() member function.  The constructor
  142. defaults it to 20 ms.
  143.  
  144. void Explode(void)
  145. void Implode(void)
  146. void ExpImpDraw(void)
  147. =====================
  148.     These three private functions control the explode and implode process.
  149. They are controlled totally from within the class and will be invoked at
  150. the proper times when required.  They should never be called directly
  151. except ExpImpDraw() which has a special case described below.
  152.  
  153.  
  154. Public:
  155. =======
  156.  
  157. virtual void setState(ushort aState, Boolean enable)
  158. ====================================================
  159.     This virtual function is overridden to catch requests to hide the
  160. window or dialog box.  If such a request is received and the object is
  161. set to implode on closing, it will do so.  It is also set up to explode
  162. when shown again.
  163.     This function is not normally overridden in derived classes, but if
  164. you do derive your own specialized TExplodeWindow class with a new
  165. setState() function, you will at least need to call
  166. TExplodeWindow::setState() before leaving yours or base it on the
  167. existing code.
  168.  
  169. virtual void changeBounds(const TRect &bounds)
  170. ==============================================
  171.     This virtual function is overridden to catch requests to change the
  172. bounds of the object.  During explosion or implosion, this will prevent
  173. calls that would change the bounds of all sub-views.  If this were not
  174. done, their positions would be all messed up when the process finally
  175. completed (this is because their growMode flags may or may not be set).
  176. The only exception to this is the frame of the window or dialog box.
  177. Its size and position are adjusted and drawn along with the window or
  178. dialog.  The effect you get is that as it opens, all the sub-views are
  179. dragged into position.  It's pretty neat to watch.
  180.     This function is not normally overridden in derived classes, but if
  181. you do derive your own specialized TExplodeWindow class with a new
  182. changeBounds() function, you will at least need to call
  183. TExplodeWindow::changeBounds() before leaving yours or, more likely,
  184. base it on the existing code.
  185.  
  186. void sizeLimits(TPoint &min, TPoint &max)
  187. =========================================
  188.     This virtual function is overridden so that when the window or
  189. dialog box is in the process of exploding or imploding, size limits are
  190. suppressed.  If they were not, the object would never start exploding
  191. below or shrink beyond its minimum view size.
  192.  
  193. *** NOTE: If you derive a specialized TExplodeWindow class that requires
  194. it's own overridden sizeLimits() function, you *MUST* place your code in
  195. the "else" section of the "if(Is_Exploding_Imploding)" if() block.  If
  196. you don't, your derived exploding window will not work as it should!
  197. The same applies to TExplodeDialog, although overridden sizeLimits()
  198. functions in that case would be rare.
  199.  
  200. Example:
  201. void TMyOwnExplodeWindow::sizeLimits(TPoint &min, TPoint &max)
  202. {
  203.     // Ignore limits when imploding or exploding.
  204.     if(Is_Exploding_Imploding)
  205.     {
  206.         min.x = min.y = 0;
  207.         max.x = max.y = MAXINT;
  208.     }
  209.     else
  210.     {
  211.         Your size limit code here.
  212.         .
  213.         .
  214.         .
  215.     }
  216. }
  217.  
  218. virtual void draw(void)
  219. =======================
  220.     Upon opening, the first call to the overridden draw() function will
  221. check the WillExplode flag.  If set to True, the window or dialog box is
  222. exploded to its normal size before the draw resumes.
  223.  
  224. *** NOTE: If you derive a specialized TExplodeWindow class that requires
  225. it's own overridden draw() function, you *MUST* place your code in the
  226. "else" section of the "if(Is_Exploding_Imploding)" if() block. If you
  227. don't, your derived exploding window will not work as it should!
  228. Usually, it's better to leave the window's draw function alone and
  229. simply insert an interior object.  The same applies to TExplodeDialog,
  230. although overridden draw() functions in that case would be rare.
  231.  
  232. Example:
  233. void TMyOwnExplodeWindow::draw(void)
  234. {
  235.     // Check for the need to explode.  This will generally only be
  236.     // true just after construction when the window is inserted into
  237.     // the desktop.
  238.     if(WillExplode)
  239.         Explode();
  240.  
  241.     if(Is_Exploding_Imploding)
  242.         ExpImpDraw();           // Explode or implode draw.
  243.     else
  244.     {
  245.         Your draw code here.
  246.         .
  247.         .
  248.         .
  249.     }
  250. }
  251.  
  252. virtual void close(void)
  253. ========================
  254.     This virtual function is overridden to implode the window or dialog
  255. box upon closing.  If the object's valid() member function says it is
  256. okay to do so, the window or dialog box will implode and destroy itself.
  257.     This function is not normally overridden in derived classes, but if
  258. you do derive your own specialized TExplodeWindow class with a new
  259. close() function, you will at least need to call TExplodeWindow::close()
  260. before leaving yours or base it on the existing code.
  261.  
  262.  
  263. Streamable Options
  264. ==================
  265.     All of the necessary functions and variables are defined and/or
  266. overridden to allow both classes to be streamed.  When deriving your own
  267. specialize TExplodeWindow and TExplodeDialog classes, don't forget to
  268. override them if you need to save additional variables to the resource
  269. file.  The subject of streams and resource files is too complex to cover
  270. fully in this document.  Refer to the manuals and other tutorials for
  271. more information on them.
  272.  
  273. -------------------------------------------------------------------------------
  274.  
  275. Implementation
  276. ==============
  277.     To use the TExplodeWindow and TExplodeDialog classes in your own
  278. application, include the following lines at the top of your program
  279. source files where necessary (usually after #include <tv.h>):
  280.  
  281.     .
  282.     .
  283.     .
  284. #include <tv.h>
  285.  
  286. #define Uses_TExplodeWindow         // Define if using TExplodeWindow
  287. #define Uses_TExplodeDialog         // Define if using TExplodeDialog
  288. #include <texplode.h>               // Make sure it's in your #include
  289.                                     // path somethere!
  290.  
  291. // NOTE: Always be sure to include these two lines once somewhere in your
  292. //       program if you are using streamed TExplodeWindow and/or
  293. //       TExplodeDialog objects (i.e. loading them from a resource file)!
  294. __link(RExplodeWindow)
  295. __link(RExplodeDialog)
  296.  
  297.     If not using a TExplodeWindow or a TExplodeDialog in the current file,
  298. you may exclude the associated #define Uses_XXX line.
  299.  
  300.     You are then free to use the objects as needed.  Simply instantiate
  301. them as you would any other TWindow or TDialog object but use the
  302. appropriate TExplodeXXXX name instead.
  303.  
  304.     The last step is to insure that TEXPLODE.LIB is included in your
  305. project and can be found along the default search path for library
  306. files.  Once that's done, just compile your application.
  307.  
  308. IMPROVING SCREEN UPDATE SPEED
  309. =============================
  310.     This isn't a necessary change, but if you have the Turbo Vision
  311. source code and you haven't already done so, go into TSCREEN.CPP and
  312. change:
  313.  
  314. Boolean near TScreen::checkSnow = True;
  315.  
  316. to
  317.  
  318. Boolean near TScreen::checkSnow = False;
  319.  
  320.     Recompile this module and replace the TSCREEN.OBJ file in TV.LIB
  321. with the new one.  If you don't have the source or don't want to modify
  322. it, you can always put "TScreen::checkSnow = False" in your
  323. application's constructor so that it is turned off.
  324.     A TI document from Borland noted that this was left as True by
  325. accident and that it will improve screen update performance when set to
  326. False.  IT DOES.  The explode and implode processes are much smoother
  327. and quicker when snow checking is turned OFF.  Not only that, all other
  328. screen updates are faster and smoother too.  Normally, this only gets
  329. set to False if you change screen modes (i.e. to 43/50 line mode) or
  330. you have a monochrome monitor.
  331.     The demos are compiled with my copy of the library that contains
  332. this change.  If you haven't made the change and have an EGA/VGA
  333. monitor, recompile the demo programs, explode a few windows in 25 line
  334. mode, use the Toggle Screen Size option on the Window Menu to go into
  335. 43/50 line mode and back to 25 line mode, then explode some more.
  336. You'll see the speed difference the most when exploding the bigger
  337. windows and dialog boxes.
  338.  
  339. Modeless THelpWindow Fix
  340. ========================
  341.     While fixing a bug in the TExplodeWindow class being used as a base
  342. class for THelpWindow, I found the following bug in the Turbo Vision
  343. source code.  If created as a modeless window, THelpWindow can sometimes
  344. cause a program crash.  To fix it, make the following change:
  345.  
  346. In HELP.CPP around line 266 in THelpViewer::handleEvent() is the case:
  347.  
  348. case evCommand:
  349.     if ((event.message.command == cmClose) && (owner->state && sfModal != 0))
  350.         {
  351.         endModal(cmClose);
  352.         clearEvent(event);
  353.         }
  354.     break;
  355.  
  356. The if() statement incorrectly checks for a modal window.  Change it to:
  357.  
  358.     if((event.message.command == cmClose) && (owner->state & sfModal))
  359.                                                            |
  360.                                                            |
  361.                                                     USE ONLY 1 '&' HERE!!
  362.  
  363.     Recompile this module and replace the HELP.OBJ file in TV.LIB
  364. with the new one.
  365.  
  366. -------------------------------------------------------------------------------
  367.  
  368. Final Notes
  369. ===========
  370.     I have included a demo program that uses both the TExplodeWindow and
  371. TExplodeDialog classes in normal form and resource file form.  It's
  372. pretty simplistic, but should give you enough information on using these
  373. classes in an application.
  374.  
  375.     If you like these classes and have any comments, questions, or
  376. suggestions, I'd like to hear from you.  My mail and CompuServe
  377. addresses can be found at the top of this document.  Thanks for your
  378. interest.
  379.  
  380. Eric Woodruff,  CIS ID: 72134,1150
  381. Wed 08/25/93 20:21:20
  382.