home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / krcls012.zip / KrClass / doc / krclguid.INF (.txt) < prev    next >
OS/2 Help File  |  1997-02-25  |  20KB  |  474 lines

  1.  
  2. ΓòÉΓòÉΓòÉ 1. About this guide ΓòÉΓòÉΓòÉ
  3.  
  4. Kroni's Classes 
  5. Version 0.12
  6.  
  7. --  A class library for lazy PM programmers  --
  8.  
  9. User's Guide 
  10.  
  11.  
  12.  Software requirements:    OS/2 Warp and Visual Age C++.
  13.  
  14.  Hardware Requirements:    none (anything which runs Warp and VAC++ is good enough).
  15.  
  16. Please read the file readme.1st and the copyright notice before you go on! 
  17.  
  18.  
  19. ΓòÉΓòÉΓòÉ 1.1. Copyright notice ΓòÉΓòÉΓòÉ
  20.  
  21. Kroni's Classes -  License.
  22.  
  23. You may: 
  24.  
  25.      make and distribute as many copies of the complete archive as you want. 
  26.       When doing this, the archive must always stay complete and may not be 
  27.       changed in any way. 
  28.  
  29.      install the software on one computer and run all .exe files. 
  30.  
  31.  If you are not registered, you may not do anything else with the software, 
  32.  including studying of the source code. 
  33.  
  34.  To register, you must write your full name and the version number of Kroni's 
  35.  Classes on a postcard and mail it to the author. 
  36.  
  37.  If you are registered, you get the following additional rights:  You may 
  38.  
  39.      use the source codes for studying 
  40.  
  41.      use and change the software to write your own programs 
  42.  
  43.      distribute compiled versions of your own programs 
  44.  
  45.      distribute source codes of your programs that include parts or all of 
  46.       Kroni's Classes if you also include the copyright notices that are placed 
  47.       at the top of all original source code files of Kroni's Classes. 
  48.  
  49.  NOTE THE DISCLAIMERS. 
  50.  
  51.  
  52. ΓòÉΓòÉΓòÉ 1.2. DISCLAIMERS ΓòÉΓòÉΓòÉ
  53.  
  54. NOTE THESE DISCLAIMERS: 
  55.  
  56. I release this software "as is". Use it completely at your own risk. I can not 
  57. be hold responsible for any damage which is inflicted directly or indirectly to 
  58. you or other persons or objects in any way by bugs or unexpected behaviour of 
  59. Kroni's Classes. If you do not accept this, you are not allowed to use the 
  60. software at all. If these conditions are illegal in your country, it is not 
  61. allowed to use the software in your country at all. 
  62.  
  63. I wrote this software completely on my own. However, in some countries, even 
  64. simple algorithms might be copyrighted. This means that in some countries I 
  65. might not have the right to grant you the above rights. If this is indeed the 
  66. case in your country, it is not allowed to use the software in your country at 
  67. all. 
  68.  
  69.  
  70. ΓòÉΓòÉΓòÉ 1.3. Contacting the author ΓòÉΓòÉΓòÉ
  71.  
  72. The author's name and address are: 
  73.  
  74. Wolfgang Kronberg 
  75. Richard-Linde-Weg 16a 
  76. 21033 Hamburg 
  77. Germany 
  78.  
  79. Please send your registration to this address. 
  80.  
  81. Registered users may also contact the author using this e-mail address: 
  82.  
  83. vlk@amt.cmlink.de 
  84.  
  85. Please keep mails to this account small (<10k). 
  86.  
  87.  
  88. ΓòÉΓòÉΓòÉ 1.4. Where to get Kroni's Classes ΓòÉΓòÉΓòÉ
  89.  
  90. I will always upload the latest version of Kroni's Classes to 
  91.  
  92. ftp.leo.org/pub/comp/os/os2/leo/devtools/libraries , 
  93.  
  94. and I will use krclsxyz.zip as the filename, where x.yz is the version number. 
  95.  
  96. In addition, you'll most likely find Kroni's Classes at these places: 
  97.  
  98. hobbes.nmsu.edu  (ftp- and www-server)
  99. GfD-Net      (filenet based on fido technology)
  100. Bite Hamburg   (Mailbox, modem: +49-40-39901190)
  101. Amt Winsen    (Mailbox, modem: +49-4171-63429)
  102.  
  103. However, the latest version may take some more time to arrive there. 
  104.  
  105.  
  106. ΓòÉΓòÉΓòÉ 1.5. Introduction ΓòÉΓòÉΓòÉ
  107.  
  108. This class library is by no means professional software. I wrote it to suit my 
  109. own needs. I do hope, however, that some other people have at least partly the 
  110. same needs, and for those it is that I documented and released this software. I 
  111. don't want to have money for it, but I want your help in eliminating bugs and 
  112. flaws so that the whole community will benefit from it, and I want to know if 
  113. there are at all people needing this software, so please don't forget to send 
  114. me your postcard. I won't publish updates of this software if I don't get 
  115. enough of them. 
  116.  
  117. This guide should help you through some items, but it is by no means complete. 
  118. Use it together with the reference guide and the demo programs to find out all 
  119. about the use of Kroni's Classes. 
  120.  
  121. Now go write your programs and have fun! 
  122.  
  123.  
  124. ΓòÉΓòÉΓòÉ 2. Compiling and linking your programs using the IBM Workframe ΓòÉΓòÉΓòÉ
  125.  
  126. You can compile and link the programs that use Kroni's Classes just like any 
  127. other program, with the following exceptions: 
  128.  
  129.      Since Kroni's Classes are based on the UICL, you must activate 
  130.       multithreading, e.g. on Options/Compile/Object/Multithread. 
  131.  
  132.      Since your programs need the header files from Kroni's Classes, you must 
  133.       add a path to them (x:\...\KrClass\include) to your include path, e.g. on 
  134.       Options/Compile/File/Options/Command line include path. 
  135.  
  136.      Since the Linker must be able to find the library (in 
  137.       x:\...\KrClass\lib), you must tell it where to look for it, e.g. by 
  138.       adding the full name (e.g. x:\...\KrClass\lib\krclas.lib) to 
  139.       Options/Link/Filenames/Libraries to use. 
  140.  
  141.      Always use the correct version of the library! Depending on whether you 
  142.       use dynamic linkage and/or debugging information, the library must be 
  143.       recompiled using different options. For your convenience, the 
  144.       installation program creates libraries for all cases and gives them these 
  145.       names: 
  146.  
  147.         -  krclas.lib  (dynamic linkage, no debuging information) 
  148.  
  149.         -  krclasd.lib  (dynamic linkage, with debuging information) 
  150.  
  151.         -  skrclas.lib  (static linkage, no debuging information) 
  152.  
  153.         -  skrclasd.lib (static linkage, with debuging information) 
  154.  
  155.  Of course, all other settings must still make sense, e.g. you must link your 
  156.  program as a PM program. 
  157.  
  158.  Please remember that linkage and debugging settings have vast influence on the 
  159.  size of the generated code. When you write programs for yourself, you should 
  160.  use dynamic linkage. Even when you distribute your programs, you should 
  161.  consider dynamic linkage. See "Managing Libraries", "Packaging the Visual Age 
  162.  C++ Runtime Libraries" in the Visual Age C++ User's Guide and Reference for 
  163.  more information. 
  164.  
  165.  Also, consider using a make file like the one in the demo directory instead of 
  166.  or in addition to the Workframe, since this takes care of all the above. 
  167.  
  168.  
  169. ΓòÉΓòÉΓòÉ 3. Basic KrClass objects ΓòÉΓòÉΓòÉ
  170.  
  171. All public objects and include files are preceeded by "Kr" to show that they 
  172. belong to the KrClass library. Private symbols not intended to be of any 
  173. importance to the user start with "_Kr". I hope that this way, they don't 
  174. interfere with any other class libraries. 
  175.  
  176. The next few pages will explain some of the basic tasks that can be done using 
  177. Kroni's Classes. 
  178.  
  179.  
  180. ΓòÉΓòÉΓòÉ 3.1. The asynchronous main() function ΓòÉΓòÉΓòÉ
  181.  
  182. #include "krasyncm.hpp" 
  183.  
  184. One of the biggest problems for beginners in PM programming is the fact that 
  185. the programmer has to actively give OS/2 the chance to do even basic things 
  186. like drawing the application's windows. That means that you can't just wait for 
  187. user input in main() and then continue doing some work in main(). You have to 
  188. actively leave main() to draw the window which will let the user do some input. 
  189.  
  190. The KrAsyncMain class works around this problem by letting you define your own 
  191. main() function, which will then run in a seperate thread, while all the other 
  192. tasks are still taken care of. Since the asynchronous main() function runs in 
  193. idle priority, it will always give way to important things like screen 
  194. redrawing of your program (or of others), but it will also take all so-far 
  195. unused CPU time. 
  196.  
  197. Your main function will consist of a huge switch() construction, of which only 
  198. one branch leads to the "main() code" itself. The other ones give you the 
  199. chance to delay actions till the one you're just working at is done, and to 
  200. react to user input. 
  201.  
  202. To write your own asynchronous main() function, do the following: 
  203.  
  204.    1. Define a class which inherits from KrAsyncMain and forwards its 
  205.       constructor. 
  206.  
  207.    2. Define the virtual function main() of this class. 
  208.  
  209.    3. Put a switch() statement in there as shown in hello.cpp. 
  210.  
  211.    4. Add more case statements to be able to post commands from within your own 
  212.       main() function to make sure that other parts of it are executed later. 
  213.  
  214.    5. Add case statements for window IDs of controls like Menues and 
  215.       PushButtons to be able to react to user command input like shown in 
  216.       ini.cpp. 
  217.  
  218.    6. Create an instance of your new class directly before calling 
  219.       IApplication::current().run(). 
  220.  
  221.  
  222. ΓòÉΓòÉΓòÉ 3.2. The common text output window ΓòÉΓòÉΓòÉ
  223.  
  224. #include "krcto.hpp" 
  225.  
  226. Especially when writing software that is not supposed to be published, it comes 
  227. in extremely handy to use the common stream output mechanism to output text on 
  228. the screen. Unfortunately, this won't work in PM programs since they don't have 
  229. an appropriate text window by default. 
  230.  
  231. The KrCommonTextOutput class uses a multi line edit control for this purpose. 
  232. It inherits from IMultiLineEdit and can be treated exactly like other 
  233. IMultiLineEdit objects. It features an ostream object which can be used for 
  234. output in the very same way all other ostream objects (e.g. cout) can be used. 
  235.  
  236. To include a common text output window in your program, do the following: 
  237.  
  238.    1. Create the main window or the canvas you want to put the text output 
  239.       window into. 
  240.  
  241.    2. Create an instance of KrCommonTextOutput using the IWindow object you 
  242.       created in step 1. 
  243.  
  244.    3. The output stream can now be accessed using this instance's member 
  245.       function "stream()". 
  246.  
  247.  To assign the stream to any ostream_withassign object (e.g. cout), do the 
  248.  following: 
  249.  
  250.    4. Use the operator "=" to assign the stream. 
  251.  
  252.    5. Set the flag "ios::unitbuf" on your target stream using the member 
  253.       function "setf()" of the target stream. 
  254.  
  255.  Note:   This class is not suitable for large output or professional sorftware, 
  256.          since it is rather slow and produces flickering during output. This is 
  257.          a restriction of the class IMultiLineEdit this class is based on. 
  258.  
  259.  
  260. ΓòÉΓòÉΓòÉ 3.3. The windowed communication class ΓòÉΓòÉΓòÉ
  261.  
  262. #include "krwc.hpp" 
  263.  
  264. To implement user input turns out to be even more difficult than user output in 
  265. PM environments. The only acceptable way is to present the user a dialog window 
  266. in which he may enter the input. The class KrWinComm constructs such dialogs 
  267. from almost common stream input. 
  268.  
  269. To prepare your program for user input via KrWinComm, do the following: 
  270.  
  271.    1. Create an instance of KrWinComm. 
  272.  
  273.  This needs to be done only once in your program. 
  274.  
  275.  To prepare a variable for input from the user, do the following: 
  276.  
  277.    2. Optionally, use the << operator with the previously created KrWinComm 
  278.       object and a string to define a text which informs the user about what he 
  279.       is supposed to type in. 
  280.  
  281.    3. Use the >> operator with the previously created KrWinComm object and the 
  282.       variable, just as you would do if you were using cin instead of the 
  283.       KrWinComm object. 
  284.  
  285.  To actualy display the dialog with all previously defined variables and change 
  286.  their values if user leaves the dialog by pressing OK, do the following: 
  287.  
  288.    4. Use either the >> operator or the << operator with the previously created 
  289.       KrWinComm object and the manipulator display. 
  290.  
  291.  Note:   Step 3 works only with objects derived from one of these classes: 
  292.  
  293.      IString 
  294.  
  295.      double 
  296.  
  297.      unsigned long 
  298.  
  299.      signed long 
  300.  
  301.      KrBitfield 
  302.  
  303.      KrChoice 
  304.  
  305.      KrUserDataField 
  306.  
  307.  With some work, it is also possible to input variables of other types. 
  308.  
  309.  
  310. ΓòÉΓòÉΓòÉ 3.4. The printer class ΓòÉΓòÉΓòÉ
  311.  
  312. #include "krprint.hpp" 
  313.  
  314. Though the UICL provides some support to draw graphics on the screen, it does 
  315. nothing to help the user print his art. The KrPrinter class acts very similar 
  316. to the UICL class IDrawingCanvas, except that it does not show the contents of 
  317. its IGraphicList on the screen, but outputs it on a printer instead, thus 
  318. solving this problem. 
  319.  
  320. KrPrinter can use any printer installed in the OS/2 system. It also lets the 
  321. user both choose the printer he wants to print on and change its settings. 
  322.  
  323. To add printer support to your program, do the following: 
  324.  
  325.    1. Create an instance of the KrPrinter class. 
  326.  
  327.  Initially, all printer output will go to the system's default printer using 
  328.  its default settings. To present a dialog to the user so that he is able to 
  329.  change this, do the following: 
  330.  
  331.    2. Call the printDialog member function of the previously created KrPrinter 
  332.       object. You may call this function at any time and as often as you want 
  333.       to. 
  334.  
  335.  To actually print someting, do the following: 
  336.  
  337.    3. Create an IGList object holding all the graphics you want to print. 
  338.  
  339.    4. Select the IGList object into the KrPrinter object by calling the member 
  340.       function setList of your KrPrinter object. 
  341.  
  342.    5. Call your KrPrinter object's member function print. 
  343.  
  344.  
  345. ΓòÉΓòÉΓòÉ 3.5. Drawing bitmap cached ΓòÉΓòÉΓòÉ
  346.  
  347. #include "krbwin.hpp" 
  348.  
  349. If you have ever put a large IGList into your IDrawingCanvas, you will most 
  350. likely have hated the very long time the system needed for redrawing whenever 
  351. you moved any window in front of your graphics output window. You can now get 
  352. rid of this by drawing into a memory bitmap and then putting this memory bitmap 
  353. instead of all the time-consuming graphics primitives into your IDrawingCanvas. 
  354.  
  355. To create a memory bitmap, do the following: 
  356.  
  357.    1. Create an instance of KrMemoyBitmap. 
  358.  
  359.  To draw into the memory bitmap, do the following: 
  360.  
  361.    2. Create an IGList object holding all the graphics you want to display. 
  362.  
  363.    3. Select the IGList object into the KrMemoyBitmap object by calling the 
  364.       member function setList of your KrMemoyBitmap object. 
  365.  
  366.  To draw the memory bitmap's contents on the screen, do the following: 
  367.  
  368.    4. Create an IDrawingCanvas object. 
  369.  
  370.    5. Create an IGList object and add your KrMemoyBitmap object to it. 
  371.  
  372.    6. Select the IGList object into the IDrawingCanvas object. 
  373.  
  374.  
  375. ΓòÉΓòÉΓòÉ 3.6. Using your own coordinate systems ΓòÉΓòÉΓòÉ
  376.  
  377. possibly #include "krgobj.hpp" 
  378.  
  379. possibly #include "krbwin.hpp" 
  380.  
  381. #include "krcstran.hpp" if none of the above was included 
  382.  
  383. Drawing graphics in the system's coordinate system can sometimes be very 
  384. complicated, because (a) the window size and hence the coordinate system size 
  385. is usually unknown at compile time, (b) the need to use integer variables 
  386. sometimes prevents exact placement, and (c) there's no way to get a logarithmic 
  387. scale. 
  388.  
  389. While (a) may partly be solved by using a transformation matrix and (c) is most 
  390. likely interesting for scientists only, it would still be much more user 
  391. friendly if the programmer could place all items within the coordinate system 
  392. he chooses. 
  393.  
  394. To define a coordinate system, do the following: 
  395.  
  396.    1. Create an instance of KrCoordSystemTranslator. 
  397.  
  398.  You can use this coordinate system to create instances of all classes which 
  399.  are defined in krgobj.hpp. You may also define your own classes. In addition, 
  400.  you may assign a memory bitmap to the coordinate system. If you do the latter, 
  401.  be certain to not display the bitmap in any common IDrawingCanvas, but only in 
  402.  an KrDrawingCanvas, and be sure to insert it into a KrGraphicList instead of 
  403.  an IGList. 
  404.  
  405.  You may collect your graphics in a KrGraphicList object and display them in a 
  406.  KrDrawingCanvas or print them using a KrPrinter. This is done using the common 
  407.  UICL methods. Refer to demo.cpp and to the IBM open class library 
  408.  documentation for details. 
  409.  
  410.  
  411. ΓòÉΓòÉΓòÉ 4. Extensions ΓòÉΓòÉΓòÉ
  412.  
  413. This chapter will give a short glance at some non-basic classes and give hints 
  414. on how to extend Kroni's Classes to make them serve your needs better. 
  415.  
  416.  
  417. ΓòÉΓòÉΓòÉ 4.1. Using other than the predefined types for user input ΓòÉΓòÉΓòÉ
  418.  
  419. There are generally three ways to define input for other than the predefined 
  420. objects. 
  421.  
  422.    1. Create a subclass from KrUserDataField and wrap your input variable into 
  423.       an instance of that subclass. This is demonstrated in demo.cpp. 
  424.  
  425.    2. Write an overload for the >> operator for the type of your input 
  426.       variable. This is done the same way as for common text mode streams, 
  427.       except for the declaration of the operator itself, which must be: 
  428.  
  429.       KrWinComm & operator >> (KrWinComm & aWinComm, YourType & aObject); 
  430.  
  431.    3. Create a subclass from KrUserDataField and write a constructor for it 
  432.       which expects as its only argument a pointer to the structure you want to 
  433.       input. Then write an overload for the >> operator. This is demonstrated 
  434.       in dialog3.cpp. 
  435.  
  436.  Notes: 
  437.  
  438.    1. Method 1 and 3 are very flexible, because using this method you can 
  439.       create an arbitrary subwindow for the user input. Method 2 lets you only 
  440.       stack subwindows for already known input types. 
  441.  
  442.    2. Method 2 is very convenient, since there's no need to explicitly define a 
  443.       wrapper object when querying the user for input. Method 1 requires more 
  444.       work and Method 3 most work of all three methods. 
  445.  
  446.    3. Method 3 is most powerful, since it can be used to input arbitrary types 
  447.       (as opposed to method 1, which is restricted to classes inheriting from 
  448.       KrUserDataField), and the input can be done using arbitrary windows (as 
  449.       opposed to method 2). In most cases, it is a good idea to choose method 
  450.       3. 
  451.  
  452.  
  453. ΓòÉΓòÉΓòÉ 4.2. Using your own graphic classes with a KrCoordSystemTranslator ΓòÉΓòÉΓòÉ
  454.  
  455. To let your own graphic objects make use of you own coordinate system, have a 
  456. look at krgobj.hpp and krgobj.cpp and study the definition of KrGLine. If you 
  457. plan to make use of a logarithmic scale, please don't forget the additional 
  458. work this will need. 
  459.  
  460.  
  461. ΓòÉΓòÉΓòÉ 4.3. Frames ΓòÉΓòÉΓòÉ
  462.  
  463. Especially when printing, is is often convenient to use a rectangle within the 
  464. whole window for output, while the graphic objects that print their output into 
  465. that rectangle still think that the rectangle is the whole window. 
  466.  
  467. This can be achieved using frames. Have a look at demo.cpp for how to use them. 
  468.  
  469. Note:   Never forget to release each frame using a KrAntiFrame. If you fail to 
  470.         do so, repainting of your window will take place inside a frame instead 
  471.         of the whole window next time, and on the next redraws this will even 
  472.         become nastier. 
  473.  
  474.