home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / keysrt.zip / test.cpp < prev    next >
C/C++ Source or Header  |  1996-02-23  |  21KB  |  548 lines

  1. /*******************************************************************************
  2. * FILE NAME: test.cpp                                                          *
  3. *                                                                              *
  4. * DESCRIPTION:                                                                 *
  5. *   Class implementation of the class:                                         *
  6. *     test                                                                     *
  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 _IPUSHBUT_
  20. #include <ipushbut.hpp>
  21. #endif
  22.  
  23. #ifndef _IRECT_
  24. #include <irect.hpp>
  25. #endif
  26.  
  27. #ifndef _IPOINT_
  28. #include <ipoint.hpp>
  29. #endif
  30.  
  31. #ifndef _ICNRCOL_
  32. #include <icnrcol.hpp>
  33. #endif
  34.  
  35. #ifndef _IMYKYSRT_
  36. #include "imykysrt.h"
  37. #endif
  38.  
  39. #ifndef _INOTIFEV_
  40. #include <inotifev.hpp>
  41. #endif
  42.  
  43. #ifndef _IOBSERVR_
  44. #include <iobservr.hpp>
  45. #endif
  46.  
  47. #ifndef _ISTDNTFY_
  48. #include <istdntfy.hpp>
  49. #endif
  50.  
  51. #ifndef _TEST_
  52. #include "test.hpp"
  53. #endif
  54.  
  55. #ifndef _IVBDEFS_
  56. #include <ivbdefs.h>
  57. #endif
  58.  
  59. #ifndef _ITRACE_
  60. #include <itrace.hpp>
  61. #endif
  62.  
  63.  
  64. //*****************************************************************************
  65. // Class definition for testConn13
  66. //*****************************************************************************
  67. class testConn13 : public IObserver {
  68. public:
  69.    virtual  ~testConn13(){};
  70.  
  71.    //---------------------------------------------------------------------------
  72.    // public member functions
  73.    //---------------------------------------------------------------------------
  74.    void initialize(IMyKeySortedSet< APerson* > * aSource, IVBContainerControl< APerson*, IMyKeySortedSet<APerson*>, testVBContainerControl1CnrObj > * aTarget)
  75.       {source = aSource; target = aTarget; aligning = false; };
  76.    void setSource()
  77.       {      };
  78.    void setTarget()
  79.       {
  80.       if (aligning==false) {
  81.          IFUNCTRACE_DEVELOP();
  82.          ITRACE_DEVELOP(" firing connection : MyKeySortedSet1(this) to VBContainerControl1(items))");
  83.          ITRACE_DEVELOP(" setting target from source ");
  84.          aligning = true;
  85.          try {target->setItems(source);}
  86.          catch (IException& exc) {};
  87.          aligning = false;
  88.          }
  89.       };
  90.  
  91. protected:
  92.    //---------------------------------------------------------------------------
  93.    // protected member functions
  94.    //---------------------------------------------------------------------------
  95.    virtual IObserver & dispatchNotificationEvent(const INotificationEvent & anEvent)
  96.       {
  97.       if (anEvent.notificationId() == VBINITIALIZEID) setTarget();
  98.       if ((anEvent.notificationId() == IVBContainerControl< APerson*, IMyKeySortedSet<APerson*>, testVBContainerControl1CnrObj >::itemsId) && (target == &anEvent.notifier()))
  99.          setSource();  /* set source to target value */
  100.       return(*this);
  101.       };
  102.  
  103. private:
  104.    //---------------------------------------------------------------------------
  105.    // private member data
  106.    //---------------------------------------------------------------------------
  107.    IMyKeySortedSet< APerson* > * source;
  108.    IVBContainerControl< APerson*, IMyKeySortedSet<APerson*>, testVBContainerControl1CnrObj > * target;
  109.    Boolean aligning;
  110.  
  111.  
  112. };   //testConn13
  113.  
  114.  
  115. //*****************************************************************************
  116. // Class definition for testConn14
  117. //*****************************************************************************
  118. class testConn14 : public IObserver, public IStandardNotifier {
  119. public:
  120.    virtual  ~testConn14(){};
  121.  
  122.    //---------------------------------------------------------------------------
  123.    // public member functions
  124.    //---------------------------------------------------------------------------
  125.    void initialize(IPushButton * aSource, IMyKeySortedSet< APerson* > * aTarget)
  126.       {source = aSource; target = aTarget; enableNotification(); };
  127.  
  128. protected:
  129.    //---------------------------------------------------------------------------
  130.    // protected member functions
  131.    //---------------------------------------------------------------------------
  132.    virtual IObserver & dispatchNotificationEvent(const INotificationEvent & anEvent)
  133.       {
  134.       if (anEvent.notificationId() == IPushButton::buttonClickId)
  135.          {
  136.          IFUNCTRACE_DEVELOP();
  137.          ITRACE_DEVELOP(" firing connection : PushButton1(buttonClickEvent) to MyKeySortedSet1(customLogic, \"add an item to the collection\"))");
  138.          try {codeSnippet(&anEvent);}
  139.          catch (IException& exc) {};
  140.          }
  141.       return(*this);
  142.       };
  143.  
  144. private:
  145.    //---------------------------------------------------------------------------
  146.    // private member functions
  147.    //---------------------------------------------------------------------------
  148.    void codeSnippet(const INotificationEvent* event)
  149.       {
  150.       ITime time;
  151.       APerson* p = new APerson (time.asString(),"1222","2222");
  152.       target->add(p);
  153.       };
  154.  
  155.    //---------------------------------------------------------------------------
  156.    // private member data
  157.    //---------------------------------------------------------------------------
  158.    IPushButton * source;
  159.    IMyKeySortedSet< APerson* > * target;
  160.  
  161.  
  162. };   //testConn14
  163.  
  164.  
  165. //*****************************************************************************
  166. // Class definition for testConn2
  167. //*****************************************************************************
  168. class testConn2 : public IObserver, public IStandardNotifier {
  169. public:
  170.    virtual  ~testConn2(){};
  171.  
  172.    //---------------------------------------------------------------------------
  173.    // public member functions
  174.    //---------------------------------------------------------------------------
  175.    void initialize(IPushButton * aSource, IMyKeySortedSet< APerson* > * aTarget)
  176.       {source = aSource; target = aTarget; enableNotification(); };
  177.  
  178. protected:
  179.    //---------------------------------------------------------------------------
  180.    // protected member functions
  181.    //---------------------------------------------------------------------------
  182.    virtual IObserver & dispatchNotificationEvent(const INotificationEvent & anEvent)
  183.       {
  184.       if (anEvent.notificationId() == IPushButton::buttonClickId)
  185.          {
  186.          IFUNCTRACE_DEVELOP();
  187.          ITRACE_DEVELOP(" firing connection : PushButton2(buttonClickEvent) to MyKeySortedSet1(customLogic, \"remove all elements in the collection\"))");
  188.          try {codeSnippet(&anEvent);}
  189.          catch (IException& exc) {};
  190.          }
  191.       return(*this);
  192.       };
  193.  
  194. private:
  195.    //---------------------------------------------------------------------------
  196.    // private member functions
  197.    //---------------------------------------------------------------------------
  198.    void codeSnippet(const INotificationEvent* event)
  199.       {
  200.       while(!target->isEmpty()) {
  201.         APerson * elem = target->firstElement();
  202.         target->removeFirst();
  203.         elem->disableNotification();
  204.         delete elem;
  205.       }
  206.       };
  207.  
  208.    //---------------------------------------------------------------------------
  209.    // private member data
  210.    //---------------------------------------------------------------------------
  211.    IPushButton * source;
  212.    IMyKeySortedSet< APerson* > * target;
  213.  
  214.  
  215. };   //testConn2
  216.  
  217.  
  218. //*****************************************************************************
  219. // Class definition for testConn3
  220. //*****************************************************************************
  221. class testConn3 : public IObserver, public IStandardNotifier {
  222. public:
  223.    virtual  ~testConn3(){};
  224.  
  225.    //---------------------------------------------------------------------------
  226.    // public member functions
  227.    //---------------------------------------------------------------------------
  228.    void initialize(IPushButton * aSource, IFrameWindow * aTarget)
  229.       {source = aSource; target = aTarget; enableNotification(); };
  230.  
  231. protected:
  232.    //---------------------------------------------------------------------------
  233.    // protected member functions
  234.    //---------------------------------------------------------------------------
  235.    virtual IObserver & dispatchNotificationEvent(const INotificationEvent & anEvent)
  236.       {
  237.       if (anEvent.notificationId() == IPushButton::buttonClickId)
  238.          {
  239.          IFUNCTRACE_DEVELOP();
  240.          ITRACE_DEVELOP(" firing connection : PushButton2(buttonClickEvent) to FrameWindow(close))");
  241.          try {target->close();}
  242.          catch (IException& exc) {};
  243.          }
  244.       return(*this);
  245.       };
  246.  
  247. private:
  248.    //---------------------------------------------------------------------------
  249.    // private member data
  250.    //---------------------------------------------------------------------------
  251.    IPushButton * source;
  252.    IFrameWindow * target;
  253.  
  254.  
  255. };   //testConn3
  256.  
  257.  
  258. //*****************************************************************************
  259. // Class definition for testConn4
  260. //*****************************************************************************
  261. class testConn4 : public IObserver, public IStandardNotifier {
  262. public:
  263.    virtual  ~testConn4(){};
  264.  
  265.    //---------------------------------------------------------------------------
  266.    // public member functions
  267.    //---------------------------------------------------------------------------
  268.    void initialize(IPushButton * aSource, IMyKeySortedSet< APerson* > * aTarget)
  269.       {source = aSource; target = aTarget; enableNotification(); };
  270.  
  271. protected:
  272.    //---------------------------------------------------------------------------
  273.    // protected member functions
  274.    //---------------------------------------------------------------------------
  275.    virtual IObserver & dispatchNotificationEvent(const INotificationEvent & anEvent)
  276.       {
  277.       if (anEvent.notificationId() == IPushButton::buttonClickId)
  278.          {
  279.          IFUNCTRACE_DEVELOP();
  280.          ITRACE_DEVELOP(" firing connection : PushButton3(buttonClickEvent) to MyKeySortedSet1(customLogic, \"clear all items\"))");
  281.          try {codeSnippet(&anEvent);}
  282.          catch (IException& exc) {};
  283.          }
  284.       return(*this);
  285.       };
  286.  
  287. private:
  288.    //---------------------------------------------------------------------------
  289.    // private member functions
  290.    //---------------------------------------------------------------------------
  291.    void codeSnippet(const INotificationEvent* event)
  292.       {
  293.       while(!target->isEmpty()) {
  294.         APerson * elem = target->firstElement();
  295.         target->removeFirst();
  296.         elem->disableNotification();
  297.         delete elem;
  298.       }
  299.       };
  300.  
  301.    //---------------------------------------------------------------------------
  302.    // private member data
  303.    //---------------------------------------------------------------------------
  304.    IPushButton * source;
  305.    IMyKeySortedSet< APerson* > * target;
  306.  
  307.  
  308. };   //testConn4
  309.  
  310.  
  311. //------------------------------------------------------------------------------
  312. // testVBContainerControl1CnrObj :: testVBContainerControl1CnrObj
  313. //------------------------------------------------------------------------------
  314. #pragma export (testVBContainerControl1CnrObj::testVBContainerControl1CnrObj(APerson&))
  315. testVBContainerControl1CnrObj::testVBContainerControl1CnrObj(APerson& anObject)
  316.  :IVBContainerObject(anObject.asDebugInfo(), ISystemPointerHandle(ISystemPointerHandle::warning)),
  317.       Age(anObject.Age()), Name(anObject.Name()), pRealObject(anObject)
  318. {
  319.    enableDataUpdate();
  320.    handleNotificationsFor(pRealObject);
  321. }
  322.  
  323.  
  324. //------------------------------------------------------------------------------
  325. // testVBContainerControl1CnrObj :: testVBContainerControl1CnrObj
  326. //------------------------------------------------------------------------------
  327. #pragma export (testVBContainerControl1CnrObj::testVBContainerControl1CnrObj(testVBContainerControl1CnrObj&))
  328. testVBContainerControl1CnrObj::testVBContainerControl1CnrObj(testVBContainerControl1CnrObj& anObject)
  329.  :IVBContainerObject(anObject.iconText(), anObject.icon()),
  330.       Age(anObject.Age), Name(anObject.Name), pRealObject(anObject.pRealObject)
  331. {  }
  332.  
  333.  
  334. //------------------------------------------------------------------------------
  335. // testVBContainerControl1CnrObj :: ~testVBContainerControl1CnrObj
  336. //------------------------------------------------------------------------------
  337. #pragma export (testVBContainerControl1CnrObj::~testVBContainerControl1CnrObj())
  338. testVBContainerControl1CnrObj::~testVBContainerControl1CnrObj()
  339. {
  340.    this->stopHandlingNotificationsFor(pRealObject);
  341. }
  342.  
  343.  
  344. //------------------------------------------------------------------------------
  345. // testVBContainerControl1CnrObj :: refreshFromObject
  346. //------------------------------------------------------------------------------
  347. #pragma export (testVBContainerControl1CnrObj::refreshFromObject())
  348. IVBContainerObject & testVBContainerControl1CnrObj::refreshFromObject()
  349. {
  350.    setIconText(pRealObject.asDebugInfo());
  351.    setIcon(ISystemPointerHandle(ISystemPointerHandle::warning));
  352.    Age = pRealObject.Age();
  353.    Name = pRealObject.Name();
  354.    return *this;
  355. }
  356.  
  357.  
  358. //------------------------------------------------------------------------------
  359. // testVBContainerControl1CnrObj :: updateToObject
  360. //------------------------------------------------------------------------------
  361. IVBContainerObject & testVBContainerControl1CnrObj::updateToObject()
  362. {
  363.    pRealObject.setAge(Age);
  364.    pRealObject.setName(Name);
  365.    return *this;
  366. }
  367.  
  368.  
  369. //------------------------------------------------------------------------------
  370. // testVBContainerControl1CnrObj :: operator=
  371. //------------------------------------------------------------------------------
  372. testVBContainerControl1CnrObj& testVBContainerControl1CnrObj::operator=(const testVBContainerControl1CnrObj& anObject)
  373. {
  374.    if (this == &anObject) {
  375.       return *this;
  376.       }
  377.    IVBContainerObject::operator=(anObject);
  378.    Age = anObject.Age;
  379.    Name = anObject.Name;
  380.    return *this;
  381. }
  382.  
  383.  
  384.  
  385. #pragma export (test::readyId)
  386. const INotificationId test::readyId = "test::readyId";
  387.  
  388. #pragma export (test::partWindowId)
  389. unsigned long test::partWindowId = 0;
  390.  
  391. //------------------------------------------------------------------------------
  392. // test :: defaultFramingSpec
  393. //------------------------------------------------------------------------------
  394. #pragma export (test::defaultFramingSpec())
  395. const IRectangle test::defaultFramingSpec()
  396. {
  397.    return(IRectangle(IPoint(30, IWindow::desktopWindow()->size().height() - 30 - 423),ISize(555, 423)));
  398. }
  399.  
  400.  
  401. //------------------------------------------------------------------------------
  402. // test :: defaultTitle
  403. //------------------------------------------------------------------------------
  404. #pragma export (test::defaultTitle())
  405. IString test::defaultTitle()
  406. {
  407.    return("IVKeySortedSet");
  408. }
  409.  
  410.  
  411. //------------------------------------------------------------------------------
  412. // test :: test
  413. //------------------------------------------------------------------------------
  414. #pragma export (test::test(unsigned long, IWindow*, IWindow*, const IRectangle&, const IFrameWindow::Style&, const char*))
  415. test::test(
  416.       unsigned long id, 
  417.       IWindow* parent, 
  418.       IWindow* owner, 
  419.       const IRectangle& rect, 
  420.       const IFrameWindow::Style& style, 
  421.       const char* title)
  422.    : IFrameWindow((partWindowId) ? partWindowId : id, parent, owner, rect, style, title)
  423. {
  424.    partWindowId = (partWindowId) ? partWindowId : id;
  425.    iCanvas = new ICanvas(
  426.       IC_FRAME_CLIENT_ID, 
  427.       this, 
  428.       this, 
  429.       IRectangle());
  430.    iPushButton1 = new IPushButton(
  431.       partWindowId+WNDOFFSET_test_PushButton1, 
  432.       iCanvas, 
  433.       iCanvas, 
  434.       IRectangle(IPoint(383,78),ISize(57, 34)));
  435.    iVBContainerControl1 = new IVBContainerControl< APerson*, IMyKeySortedSet<APerson*>, testVBContainerControl1CnrObj >(
  436.       partWindowId+WNDOFFSET_test_VBContainerControl1, 
  437.       iCanvas, 
  438.       iCanvas, 
  439.       IRectangle(IPoint(80,165),ISize(380, 209)));
  440.    iContainerColumn1 = new IContainerColumn(offsetof(testVBContainerControl1CnrObj, Name), IContainerColumn::defaultHeadingStyle ( ), (IContainerColumn::defaultDataStyle ( )) & ~IContainerColumn::icon | IContainerColumn::string);
  441.    iContainerColumn2 = new IContainerColumn(offsetof(testVBContainerControl1CnrObj, Age), IContainerColumn::defaultHeadingStyle ( ), (IContainerColumn::defaultDataStyle ( )) & ~IContainerColumn::icon | IContainerColumn::string);
  442.    iPushButton2 = new IPushButton(
  443.       partWindowId+WNDOFFSET_test_PushButton2, 
  444.       iCanvas, 
  445.       iCanvas, 
  446.       IRectangle(IPoint(130,81),ISize(67, 34)));
  447.    iPushButton3 = new IPushButton(
  448.       partWindowId+WNDOFFSET_test_PushButton3, 
  449.       iCanvas, 
  450.       iCanvas, 
  451.       IRectangle(IPoint(260,79),ISize(66, 34)));
  452.    iMyKeySortedSet1 = new IMyKeySortedSet< APerson* >();
  453.  
  454.    conn13 = new testConn13();
  455.    conn14 = new testConn14();
  456.    conn2 = new testConn2();
  457.    conn3 = new testConn3();
  458.    conn4 = new testConn4();
  459.  
  460.    this->setFocus();
  461.    this->setClient(iCanvas);
  462.    iPushButton1->setText("add");
  463.    iVBContainerControl1->showDetailsView();
  464.    iVBContainerControl1->addColumn(iContainerColumn1);
  465.    iVBContainerControl1->addColumn(iContainerColumn2);
  466.    iContainerColumn1->setHeadingText("name");
  467.    iContainerColumn1->setDisplayWidth(125);
  468.    iContainerColumn2->setHeadingText("age");
  469.    iPushButton2->setText("close");
  470.    iPushButton3->setText("clear");
  471. }     //end constructor
  472.  
  473.  
  474. //------------------------------------------------------------------------------
  475. // test :: ~test
  476. //------------------------------------------------------------------------------
  477. #pragma export (test::~test())
  478. test::~test()
  479. {
  480.    conn13->stopHandlingNotificationsFor(*iMyKeySortedSet1);
  481.    conn13->stopHandlingNotificationsFor(*iVBContainerControl1);
  482.    conn14->stopHandlingNotificationsFor(*iPushButton1);
  483.    conn2->stopHandlingNotificationsFor(*iPushButton2);
  484.    conn3->stopHandlingNotificationsFor(*iPushButton2);
  485.    conn4->stopHandlingNotificationsFor(*iPushButton3);
  486.  
  487.    delete conn13;
  488.    delete conn14;
  489.    delete conn2;
  490.    delete conn3;
  491.    delete conn4;
  492.  
  493.  
  494.    delete iCanvas;
  495.    delete iPushButton1;
  496.    delete iVBContainerControl1;
  497.    delete iContainerColumn1;
  498.    delete iContainerColumn2;
  499.    delete iPushButton2;
  500.    delete iPushButton3;
  501.    delete iMyKeySortedSet1;
  502. }
  503.  
  504. //------------------------------------------------------------------------------
  505. // test :: initializePart
  506. //------------------------------------------------------------------------------
  507. #pragma export (test::initializePart())
  508. test & test::initializePart()
  509. {
  510.    makeConnections();
  511.    notifyObservers(INotificationEvent(readyId, *this));
  512.    return *this;
  513. }
  514.  
  515.  
  516. //------------------------------------------------------------------------------
  517. // test :: makeConnections
  518. //------------------------------------------------------------------------------
  519. #pragma export (test::makeConnections())
  520. Boolean test::makeConnections()
  521. {
  522.    this->enableNotification();
  523.    iCanvas->enableNotification();
  524.    iPushButton1->enableNotification();
  525.    iVBContainerControl1->enableNotification();
  526.    iPushButton2->enableNotification();
  527.    iPushButton3->enableNotification();
  528.    iMyKeySortedSet1->enableNotification();
  529.  
  530.    conn13->initialize(iMyKeySortedSet1, iVBContainerControl1);
  531.    conn13->handleNotificationsFor(*iMyKeySortedSet1);
  532.    conn13->handleNotificationsFor(*iVBContainerControl1);
  533.    conn14->initialize(iPushButton1, iMyKeySortedSet1);
  534.    conn14->handleNotificationsFor(*iPushButton1);
  535.    conn2->initialize(iPushButton2, iMyKeySortedSet1);
  536.    conn2->handleNotificationsFor(*iPushButton2);
  537.    conn3->initialize(iPushButton2, this);
  538.    conn3->handleNotificationsFor(*iPushButton2);
  539.    conn4->initialize(iPushButton3, iMyKeySortedSet1);
  540.    conn4->handleNotificationsFor(*iPushButton3);
  541.  
  542.    conn13->setTarget();
  543.    return true;
  544. }
  545.  
  546.  
  547.  
  548.