home *** CD-ROM | disk | FTP | other *** search
/ Power GUI Programming with VisualAge C++ / powergui.iso / trialva / ibmcppw / samples / ioc / drag3 / dmsamp3.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-02-22  |  10.5 KB  |  206 lines

  1. /******************************************************************************
  2. * .FILE:         dmsamp3.cpp                                                  *
  3. *                                                                             *
  4. * .DESCRIPTION:  Direct Manipulation Sample Program 3: Class Implementation   *
  5. *                                                                             *
  6. * .CLASSES:      MyWindow                                                     *
  7. *                MySourceWin                                                  *
  8. *                MyTargetWin                                                  *
  9. *                Customer                                                     *
  10. *                                                                             *
  11. * .COPYRIGHT:                                                                 *
  12. *    Licensed Material - Program-Property of IBM                              *
  13. *    (C) Copyright IBM Corp. 1992, 1996 - All Rights Reserved                 *
  14. *                                                                             *
  15. * .DISCLAIMER:                                                                *
  16. *   The following [enclosed] code is sample code created by IBM               *
  17. *   Corporation.  This sample code is not part of any standard IBM product    *
  18. *   and is provided to you solely for the purpose of assisting you in the     *
  19. *   development of your applications.  The code is provided 'AS IS',          *
  20. *   without warranty of any kind.  IBM shall not be liable for any damages    *
  21. *   arising out of your use of the sample code, even if they have been        *
  22. *   advised of the possibility of such damages.                               *
  23. *                                                                             *
  24. * .NOTE: WE RECOMMEND USING A FIXED SPACE FONT TO LOOK AT THE SOURCE          *
  25. *                                                                             *
  26. ******************************************************************************/
  27. #include <ibase.hpp>                  //  since that is where IC_<environ>
  28. #include <icoordsy.hpp>
  29. #include "dmsamp3.hpp"
  30.  
  31. /*------------------------------------------------------------------------------
  32. | main                                                                         |
  33. ------------------------------------------------------------------------------*/
  34. int main()
  35. {
  36.   ICoordinateSystem::setApplicationOrientation(
  37.           ICoordinateSystem::originLowerLeft );
  38.    MySourceWin sourceWin (WND_SOURCE);
  39.    MyTargetWin targetWin (WND_TARGET);
  40.    IApplication::current().run();
  41.    return 0;
  42. }
  43.  
  44.  
  45. /*------------------------------------------------------------------------------
  46. | MyWindow::MyWindow                                                           |
  47. |                                                                              |
  48. | Constructor.                                                                 |
  49. ------------------------------------------------------------------------------*/
  50. MyWindow :: MyWindow ( unsigned long windowId ) :
  51.             IFrameWindow ( windowId ),
  52.  
  53.             cnrCtl (new ICnrCtl (windowId + 20, this, this, IRectangle()
  54.               ,ICnrCtl::classDefaultStyle
  55.               ,ICnrCtl::classDefaultAttribute | ICnrCtl::treeView)),
  56.  
  57.             car ((Customer *) 0),
  58.             space ((Customer *) 0),
  59.             bolt ((Customer *) 0),
  60.             starfleet ((Customer *) 0),
  61.  
  62.             reslib()
  63. {
  64.   /***********************************************************************/
  65.   /* Set the frame icon                                                  */
  66.   /* Set the container as the frame client.                              */
  67.   /***********************************************************************/
  68.   setIcon( id() );
  69.   setClient(cnrCtl);
  70.  
  71.   /***********************************************************************/
  72.   /* Create the container objects ...                                    */
  73.   /***********************************************************************/
  74.   car =       new Customer (reslib.loadString(STR_ITEM_11)
  75.                            , CAR
  76.                            ,reslib.loadString(STR_ITEM_12)
  77.                            ,reslib.loadString(STR_ITEM_13)
  78.                            ,reslib.loadString(STR_ITEM_14)
  79.                            ,this);
  80.   space =     new Customer (reslib.loadString(STR_ITEM_21)
  81.                            , SPACE
  82.                            ,reslib.loadString(STR_ITEM_22)
  83.                            ,reslib.loadString(STR_ITEM_23)
  84.                            ,reslib.loadString(STR_ITEM_24)
  85.                            ,this);
  86.   bolt =      new Customer (reslib.loadString(STR_ITEM_31)
  87.                            , BOLT
  88.                            ,reslib.loadString(STR_ITEM_32)
  89.                            ,reslib.loadString(STR_ITEM_33)
  90.                            ,reslib.loadString(STR_ITEM_34)
  91.                            ,this);
  92.   starfleet = new Customer (reslib.loadString(STR_ITEM_41)
  93.                            , STARFLEET
  94.                            ,reslib.loadString(STR_ITEM_42)
  95.                            ,reslib.loadString(STR_ITEM_43)
  96.                            ,reslib.loadString(STR_ITEM_44)
  97.                            ,this);
  98.   /***********************************************************************/
  99.   /* and add them to the container.                                      */
  100.   /***********************************************************************/
  101.   cnrCtl->addObject(car);
  102.   cnrCtl->addObject(space);
  103.   cnrCtl->addObject(bolt);
  104.   cnrCtl->addObject(starfleet, space);
  105.  
  106.   /***********************************************************************/
  107.   /* Set the container's attributes.                                     */
  108.   /***********************************************************************/
  109.   cnrCtl->setDeleteObjectsOnClose();
  110.   cnrCtl->showTreeLine();
  111.   cnrCtl->showTitle();
  112.   cnrCtl->enableDrawItem();
  113.  
  114.   /***********************************************************************/
  115.   /* Container view will be tree icon view.                              */
  116.   /***********************************************************************/
  117.   cnrCtl->showTreeIconView();
  118.  
  119.   /***********************************************************************/
  120.   /* Show it ...                                                         */
  121.   /***********************************************************************/
  122.   show();
  123.   cnrCtl->show();
  124. }
  125.  
  126. /*------------------------------------------------------------------------------
  127. | MySourceWin::MySourceWin                                                     |
  128. |                                                                              |
  129. | Constructor.                                                                 |
  130. ------------------------------------------------------------------------------*/
  131. MySourceWin :: MySourceWin ( unsigned long windowId ) :
  132.                MyWindow ( windowId )
  133. {
  134.   ITitle title (this,TITLE_SOURCE  );
  135.  
  136.   /***********************************************************************/
  137.   /* Enable the source for dragging from (only).                         */
  138.   /***********************************************************************/
  139.   IDMHandler::enableDragFrom( cnrCtl );
  140. };
  141.  
  142. /*------------------------------------------------------------------------------
  143. | MyTargetWin::MyTargetWin                                                     |
  144. |                                                                              |
  145. | Constructor.                                                                 |
  146. ------------------------------------------------------------------------------*/
  147. MyTargetWin :: MyTargetWin ( unsigned long windowId ) :
  148.                MyWindow ( windowId )
  149. {
  150.   ITitle title (this, TITLE_TARGET );
  151.  
  152.   /***********************************************************************/
  153.   /* Enable the target for dropping on (only).                           */
  154.   /***********************************************************************/
  155.   IDMHandler::enableDropOn( cnrCtl );
  156. }
  157.  
  158. /*------------------------------------------------------------------------------
  159. | Custoner::Customer                                                           |
  160. |                                                                              |
  161. | Copy constructor.                                                            |
  162. ------------------------------------------------------------------------------*/
  163. Customer :: Customer ( const Customer &cnrobj )  :
  164.             IContainerObject ( (const IContainerObject &)cnrobj ),
  165.             strName ( cnrobj.name() ),
  166.             strAddress ( cnrobj.address() ),
  167.             strPhone ( cnrobj.phone() ),
  168.             myWin ( cnrobj.myWin )
  169. {
  170. }
  171.  
  172. /*------------------------------------------------------------------------------
  173. | Custoner::Customer                                                           |
  174. |                                                                              |
  175. | Constructor.                                                                 |
  176. ------------------------------------------------------------------------------*/
  177. Customer :: Customer ( const IString &Text,
  178.                        unsigned long Icon,
  179.                        const IString &Name,
  180.                        const IString &Address,
  181.                        const IString &Phone,
  182.                        MyWindow* win )  :
  183.                        IContainerObject ( Text, Icon ),
  184.                        strName ( Name ),
  185.                        strAddress ( Address ),
  186.                        strPhone ( Phone ),
  187.                        myWin ( win )
  188. {
  189. }
  190.  
  191. /*------------------------------------------------------------------------------
  192. | Customer::objectCopy                                                         |
  193. |                                                                              |
  194. | Make a copy of the Customer object.  Called by                               |
  195. | IContainerObject::copyObjectTo().                                            |
  196. ------------------------------------------------------------------------------*/
  197. IContainerObject* Customer :: objectCopy()
  198. {
  199.   /***********************************************************************/
  200.   /* Use Customer copy constructor to make a copy of the object.         */
  201.   /***********************************************************************/
  202.   Customer *copy = new Customer(*this);
  203.   return((IContainerObject *)copy);
  204. }
  205.  
  206.