home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / strgen.zip / strgen.cpp < prev    next >
C/C++ Source or Header  |  1996-03-15  |  12KB  |  352 lines

  1. /*******************************************************************************
  2. * FILE NAME: strgen.cpp                                                        *
  3. *                                                                              *
  4. * DESCRIPTION:                                                                 *
  5. *   Class implementation of the class:                                         *
  6. *     strgen- Sample of using IStringGenerator class                           *
  7. * ---------------------------------------------------------------------------- *
  8. * Warning: This file was generated by the VisualAge C++ Visual Builder.        *
  9. * Modifications to this source file will be lost when the part is regenerated. *
  10. *******************************************************************************/
  11. #ifndef _IFRAME_
  12. #include <iframe.hpp>
  13. #endif
  14.  
  15. #ifndef _ICANVAS_
  16. #include <icanvas.hpp>
  17. #endif
  18.  
  19. #ifndef _ILISTCVW_
  20. #include <ilistcvw.hpp>
  21. #endif
  22.  
  23. #ifndef _MYSTRGEN_
  24. #include "mystrgen.hpp"
  25. #endif
  26.  
  27. #ifndef _IRECT_
  28. #include <irect.hpp>
  29. #endif
  30.  
  31. #ifndef _IPOINT_
  32. #include <ipoint.hpp>
  33. #endif
  34.  
  35. #ifndef _ISTATTXT_
  36. #include <istattxt.hpp>
  37. #endif
  38.  
  39. #ifndef _CUSTOMER_
  40. #include "Customer.hpp"
  41. #endif
  42.  
  43. #ifndef _IVSEQ_H_
  44. #include <ivseq.h>
  45. #endif
  46.  
  47. #ifndef _INOTIFEV_
  48. #include <inotifev.hpp>
  49. #endif
  50.  
  51. #ifndef _IOBSERVR_
  52. #include <iobservr.hpp>
  53. #endif
  54.  
  55. #ifndef _ISTDNTFY_
  56. #include <istdntfy.hpp>
  57. #endif
  58.  
  59. #ifndef _STRGEN_
  60. #include "strgen.hpp"
  61. #endif
  62.  
  63. #ifndef _IVBDEFS_
  64. #include <ivbdefs.h>
  65. #endif
  66.  
  67. #ifndef _ITRACE_
  68. #include <itrace.hpp>
  69. #endif
  70.  
  71.  
  72. //*****************************************************************************
  73. // Class definition for strgenConn0
  74. //*****************************************************************************
  75. class strgenConn0 : public IObserver {
  76. public:
  77.    virtual  ~strgenConn0(){};
  78.  
  79.    //---------------------------------------------------------------------------
  80.    // public member functions
  81.    //---------------------------------------------------------------------------
  82.    void initialize(IVSequence< Customer* > * aSource, ICollectionViewListBox< Customer*, IVSequence< Customer* > > * aTarget)
  83.       {source = aSource; target = aTarget; aligning = false; };
  84.    void setSource()
  85.       {      };
  86.    void setTarget()
  87.       {
  88.       if (aligning==false) {
  89.          IFUNCTRACE_DEVELOP();
  90.          ITRACE_DEVELOP(" firing connection : VSequence1(this) to CollectionViewListBox1(items))");
  91.          ITRACE_DEVELOP(" setting target from source ");
  92.          aligning = true;
  93.          try {target->setItems(source);}
  94.          catch (IException& exc) {};
  95.          aligning = false;
  96.          }
  97.       };
  98.  
  99. protected:
  100.    //---------------------------------------------------------------------------
  101.    // protected member functions
  102.    //---------------------------------------------------------------------------
  103.    virtual IObserver & dispatchNotificationEvent(const INotificationEvent & anEvent)
  104.       {
  105.       if (anEvent.notificationId() == VBINITIALIZEID) setTarget();
  106.       if ((anEvent.notificationId() == ICollectionViewListBox< Customer*, IVSequence< Customer* > >::itemsId) && (target == &anEvent.notifier()))
  107.          setSource();  /* set source to target value */
  108.       return(*this);
  109.       };
  110.  
  111. private:
  112.    //---------------------------------------------------------------------------
  113.    // private member data
  114.    //---------------------------------------------------------------------------
  115.    IVSequence< Customer* > * source;
  116.    ICollectionViewListBox< Customer*, IVSequence< Customer* > > * target;
  117.    Boolean aligning;
  118.  
  119.  
  120. };   //strgenConn0
  121.  
  122.  
  123. //*****************************************************************************
  124. // Class definition for strgenConn1
  125. //*****************************************************************************
  126. class strgenConn1 : public IObserver, public IStandardNotifier {
  127. public:
  128.    virtual  ~strgenConn1(){};
  129.  
  130.    //---------------------------------------------------------------------------
  131.    // public member functions
  132.    //---------------------------------------------------------------------------
  133.    void initialize(strgen * aSource, IVSequence< Customer* > * aTarget)
  134.       {source = aSource; target = aTarget; enableNotification(); };
  135.    strgenConn1 & setElement(Customer * aSelf) {iElement = aSelf; return *this;};
  136.  
  137. protected:
  138.    //---------------------------------------------------------------------------
  139.    // protected member functions
  140.    //---------------------------------------------------------------------------
  141.    virtual IObserver & dispatchNotificationEvent(const INotificationEvent & anEvent)
  142.       {
  143.       if (anEvent.notificationId() == strgen::readyId)
  144.          {
  145.          IFUNCTRACE_DEVELOP();
  146.          ITRACE_DEVELOP(" firing connection : (ready) to VSequence1(addAsLast))");
  147.          try {target->addAsLast(iElement);}
  148.          catch (IException& exc) {};
  149.          }
  150.       return(*this);
  151.       };
  152.  
  153. private:
  154.    //---------------------------------------------------------------------------
  155.    // private member data
  156.    //---------------------------------------------------------------------------
  157.    strgen * source;
  158.    IVSequence< Customer* > * target;
  159.    Customer * iElement;
  160.  
  161.  
  162. };   //strgenConn1
  163.  
  164.  
  165. //*****************************************************************************
  166. // Class definition for strgenConn2
  167. //*****************************************************************************
  168. class strgenConn2 : public IObserver, public IStandardNotifier {
  169. public:
  170.    virtual  ~strgenConn2(){};
  171.  
  172.    //---------------------------------------------------------------------------
  173.    // public member functions
  174.    //---------------------------------------------------------------------------
  175.    void initialize(strgen * aSource, IVSequence< Customer* > * aTarget)
  176.       {source = aSource; target = aTarget; enableNotification(); };
  177.    strgenConn2 & setElement(Customer * aSelf) {iElement = aSelf; return *this;};
  178.  
  179. protected:
  180.    //---------------------------------------------------------------------------
  181.    // protected member functions
  182.    //---------------------------------------------------------------------------
  183.    virtual IObserver & dispatchNotificationEvent(const INotificationEvent & anEvent)
  184.       {
  185.       if (anEvent.notificationId() == strgen::readyId)
  186.          {
  187.          IFUNCTRACE_DEVELOP();
  188.          ITRACE_DEVELOP(" firing connection : (ready) to VSequence1(addAsLast))");
  189.          try {target->addAsLast(iElement);}
  190.          catch (IException& exc) {};
  191.          }
  192.       return(*this);
  193.       };
  194.  
  195. private:
  196.    //---------------------------------------------------------------------------
  197.    // private member data
  198.    //---------------------------------------------------------------------------
  199.    strgen * source;
  200.    IVSequence< Customer* > * target;
  201.    Customer * iElement;
  202.  
  203.  
  204. };   //strgenConn2
  205.  
  206.  
  207. #pragma export (strgen::readyId)
  208. const INotificationId strgen::readyId = "strgen::readyId";
  209.  
  210. #pragma export (strgen::partWindowId)
  211. unsigned long strgen::partWindowId = 0;
  212.  
  213. //------------------------------------------------------------------------------
  214. // strgen :: defaultFramingSpec
  215. //------------------------------------------------------------------------------
  216. #pragma export (strgen::defaultFramingSpec())
  217. const IRectangle strgen::defaultFramingSpec()
  218. {
  219.    return(IRectangle(IPoint(30, IWindow::desktopWindow()->size().height() - 30 - 384),ISize(512, 384)));
  220. }
  221.  
  222.  
  223. //------------------------------------------------------------------------------
  224. // strgen :: defaultTitle
  225. //------------------------------------------------------------------------------
  226. #pragma export (strgen::defaultTitle())
  227. IString strgen::defaultTitle()
  228. {
  229.    return("IStringGenerator Sample");
  230. }
  231.  
  232.  
  233. //------------------------------------------------------------------------------
  234. // strgen :: strgen
  235. //------------------------------------------------------------------------------
  236. #pragma export (strgen::strgen(unsigned long, IWindow*, IWindow*, const IRectangle&, const IFrameWindow::Style&, const char*))
  237. strgen::strgen(
  238.       unsigned long id, 
  239.       IWindow* parent, 
  240.       IWindow* owner, 
  241.       const IRectangle& rect, 
  242.       const IFrameWindow::Style& style, 
  243.       const char* title)
  244.    : IFrameWindow((partWindowId) ? partWindowId : id, parent, owner, rect, style, title)
  245. {
  246.    partWindowId = (partWindowId) ? partWindowId : id;
  247.    iCanvas = new ICanvas(
  248.       IC_FRAME_CLIENT_ID, 
  249.       this, 
  250.       this, 
  251.       IRectangle());
  252.    iCollectionViewListBox1 = new ICollectionViewListBox< Customer*, IVSequence< Customer* > >(
  253.       partWindowId+WNDOFFSET_strgen_CollectionViewListBox1, 
  254.       iCanvas, 
  255.       iCanvas, 
  256.       IRectangle(IPoint(65,105),ISize(383, 183)), 
  257.       IBaseListBox::defaultStyle ( ), 
  258.       MyStringGen());
  259.    iStaticText1 = new IStaticText(
  260.       partWindowId+WNDOFFSET_strgen_StaticText1, 
  261.       iCanvas, 
  262.       iCanvas, 
  263.       IRectangle(IPoint(70,294),ISize(285, 25)));
  264.    iCustomer1 = new Customer();
  265.    iCustomer2 = new Customer();
  266.    iVSequence1 = new IVSequence< Customer* >();
  267.  
  268.    conn0 = new strgenConn0();
  269.    conn1 = new strgenConn1();
  270.    conn2 = new strgenConn2();
  271.  
  272.    this->setFocus();
  273.    this->setClient(iCanvas);
  274.    iStaticText1->setText("Customer - CollectionViewListBox");
  275.    iCustomer1->setName("John Smith");
  276.    iCustomer1->setStreet("123 42nd Street");
  277.    iCustomer1->setPhone("512-235-8212");
  278.    iCustomer1->setCity("NewYork");
  279.    iCustomer2->setName("Mike Lawrence");
  280.    iCustomer2->setStreet("88 Columbus Ave");
  281.    iCustomer2->setPhone("416-123-8888");
  282.    iCustomer2->setCity("Ajax");
  283. }     //end constructor
  284.  
  285.  
  286. //------------------------------------------------------------------------------
  287. // strgen :: ~strgen
  288. //------------------------------------------------------------------------------
  289. #pragma export (strgen::~strgen())
  290. strgen::~strgen()
  291. {
  292.    conn0->stopHandlingNotificationsFor(*iVSequence1);
  293.    conn0->stopHandlingNotificationsFor(*iCollectionViewListBox1);
  294.    conn1->stopHandlingNotificationsFor(*this);
  295.    conn2->stopHandlingNotificationsFor(*this);
  296.  
  297.    delete conn0;
  298.    delete conn1;
  299.    delete conn2;
  300.  
  301.  
  302.    delete iCanvas;
  303.    delete iCollectionViewListBox1;
  304.    delete iStaticText1;
  305.    delete iCustomer1;
  306.    delete iCustomer2;
  307.    delete iVSequence1;
  308. }
  309.  
  310. //------------------------------------------------------------------------------
  311. // strgen :: initializePart
  312. //------------------------------------------------------------------------------
  313. #pragma export (strgen::initializePart())
  314. strgen & strgen::initializePart()
  315. {
  316.    makeConnections();
  317.    notifyObservers(INotificationEvent(readyId, *this));
  318.    return *this;
  319. }
  320.  
  321.  
  322. //------------------------------------------------------------------------------
  323. // strgen :: makeConnections
  324. //------------------------------------------------------------------------------
  325. #pragma export (strgen::makeConnections())
  326. Boolean strgen::makeConnections()
  327. {
  328.    this->enableNotification();
  329.    iCanvas->enableNotification();
  330.    iCollectionViewListBox1->enableNotification();
  331.    iStaticText1->enableNotification();
  332.    iCustomer1->enableNotification();
  333.    iCustomer2->enableNotification();
  334.    iVSequence1->enableNotification();
  335.  
  336.    conn0->initialize(iVSequence1, iCollectionViewListBox1);
  337.    conn0->handleNotificationsFor(*iVSequence1);
  338.    conn0->handleNotificationsFor(*iCollectionViewListBox1);
  339.    conn1->initialize(this, iVSequence1);
  340.    conn1->handleNotificationsFor(*this);
  341.    conn2->initialize(this, iVSequence1);
  342.    conn2->handleNotificationsFor(*this);
  343.    conn1->setElement(iCustomer1);
  344.    conn2->setElement(iCustomer2);
  345.  
  346.    conn0->setTarget();
  347.    return true;
  348. }
  349.  
  350.  
  351.  
  352.