home *** CD-ROM | disk | FTP | other *** search
/ Power GUI Programming with VisualAge C++ / powergui.iso / powergui / latour / shopping / puritem.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-10-29  |  3.5 KB  |  154 lines

  1. /************************************************************
  2. / Tour of the UICL - Shopping List Example Program
  3. /
  4. / Copyright (C) 1994, Law, Leong, Love, Olson, Tsuji.
  5. / Copyright (c) 1997 John Wiley & Sons, Inc. 
  6. / All Rights Reserved.
  7. ************************************************************/
  8. #include <ibase.hpp>
  9. #ifdef IC_PM
  10.   #define INCL_WINWORKPLACE   // For WinLoadFileIcon, WinFreeFileIcon.
  11.   #include <os2.h>
  12. #else
  13.   #include <windows.h>
  14. #endif
  15.  
  16. #include <icnrctl.hpp>
  17. #include <iexcept.hpp>
  18. #include <ihandle.hpp>
  19.  
  20. #include "puritem.hpp"
  21. #include "puritemv.hpp"
  22. #include "shopping.h"
  23.  
  24.  
  25. //======================= PurchaseItem ========================
  26.  
  27. PurchaseItem :: PurchaseItem ( const IString& name,
  28.                                const IString& quantity,
  29.                                const IString& manufacturer,
  30.                                double price,
  31.                                const IString& notes )
  32.   : IContainerObject( name,
  33.                       ISystemPointerHandle
  34.                         ( ISystemPointerHandle::question )),
  35.     fManufacturer( manufacturer ),
  36.     fNotes( notes ),
  37.     fQuantity( quantity ),
  38.     fPrice( price )
  39. {
  40.   IASSERTPARM( name != IString() )
  41. }
  42.  
  43. PurchaseItem :: PurchaseItem ( const PurchaseItem& purchaseItem )
  44.   : IContainerObject( purchaseItem ),
  45.     fManufacturer( purchaseItem.manufacturer() ),
  46.     fNotes( purchaseItem.notes() ),
  47.     fQuantity( purchaseItem.quantity() ),
  48.     fPrice( purchaseItem.price() )
  49. {        // Copy constructor for drag and drop.
  50. }
  51.  
  52. PurchaseItem :: ~PurchaseItem ( )
  53. {
  54. }
  55.  
  56. PurchaseItem& PurchaseItem :: setName ( const IString& name )
  57. {
  58.   IASSERTPARM( name != IString() )
  59.  
  60.   setIconText( name );
  61.   return *this;
  62. }
  63.  
  64. PurchaseItem&
  65.   PurchaseItem :: addNotes ( const IString& moreNotes )
  66. {
  67.   if (fNotes.length())
  68.   {
  69.      fNotes += "\r\n";
  70.   }
  71.   fNotes += moreNotes;
  72.   return *this;
  73. }
  74.  
  75.  
  76. PurchaseItem&
  77.   PurchaseItem :: setManufacturer
  78.                      ( const IString& manufacturer )
  79. {
  80.   fManufacturer = manufacturer;
  81.   return *this;
  82. }
  83.  
  84. PurchaseItem&
  85.   PurchaseItem :: setQuantity ( const IString& quantity )
  86. {
  87.   fQuantity = quantity;
  88.   return *this;
  89. }
  90.  
  91. PurchaseItem& PurchaseItem :: setPrice ( double price )
  92. {
  93.   fPrice = price;
  94.   return *this;
  95. }
  96.  
  97. PurchaseItem& PurchaseItem :: setNotes ( const IString& notes )
  98. {
  99.   fNotes = notes;
  100.   return *this;
  101. }
  102.  
  103. IString PurchaseItem :: name ( ) const
  104. {
  105.   return this->iconText();
  106. }
  107.  
  108. IString PurchaseItem :: manufacturer ( ) const
  109. {
  110.   return fManufacturer;
  111. }
  112.  
  113. IString PurchaseItem :: quantity ( ) const
  114. {
  115.   return fQuantity;
  116. }
  117.  
  118. IString PurchaseItem :: notes ( ) const
  119. {
  120.   return fNotes;
  121. }
  122.  
  123.  
  124. double PurchaseItem :: price ( ) const
  125. {
  126.   return fPrice;
  127. }
  128.  
  129. void
  130.   PurchaseItem :: handleOpen ( IContainerControl* container )
  131. {
  132.   // User has opened a PurchaseItem object.
  133.   // Create a secondary window with a settings view.
  134.   PurchaseItemView* secondary =
  135.     new PurchaseItemView( *this,
  136.                           ID_PURCHASEITEMVIEW,
  137.                           container->parent() );
  138.   secondary->setAutoDeleteObject();
  139.   (*secondary)
  140.    .setFocus()
  141.    .show();
  142. //  temporary until bug in ICnrCtl::setEmphasis is fixed
  143. #ifdef IC_PM
  144.   this->IContainerObject::handleOpen( container );
  145. #endif
  146. }
  147.  
  148. IContainerObject* PurchaseItem :: objectCopy ( )
  149. {
  150.   // Copy the object, for copy via drag and drop.
  151.   PurchaseItem *copy = new PurchaseItem( *this );
  152.   return (IContainerObject *)copy;
  153. }
  154.