home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 5 / FreshFish_July-August1994.bin / bbs / gnu / aplusplus-1.01-src.lha / src / amiga / aplusplus-1.01 / testprgs / intuition / BoopsiGadget_test.cxx next >
C/C++ Source or Header  |  1994-05-09  |  6KB  |  232 lines

  1. /******************************************************************************
  2.  *
  3.  *    $Source: apphome:APlusPlus/RCS/TESTPRGS/intuition/BoopsiGadget_test.cxx,v $
  4.  *
  5.  *    Demo for the A++ Library
  6.  *    Copyright (C) 1994 by Armin Vogt, EMail: armin@uni-paderborn.de
  7.  *
  8.  *       $Revision: 1.5 $
  9.  *       $Date: 1994/05/09 21:27:51 $
  10.  *       $Author: Armin_Vogt $
  11.  *
  12.  ******************************************************************************/
  13.  
  14. #include <APlusPlus/exec/SignalResponder.h>
  15. #include <APlusPlus/intuition/GWindow.h>
  16. #include <APlusPlus/intuition/BoopsiGadget.h>
  17. #include <APlusPlus/intuition/StdGadget.h>
  18.  
  19. extern "C" {
  20. #include <dos/dos.h>
  21. }
  22.  
  23.  
  24. volatile static char rcs_id[] = "$Id: BoopsiGadget_test.cxx,v 1.5 1994/05/09 21:27:51 Armin_Vogt Exp Armin_Vogt $";
  25.  
  26.  
  27. class MyProp : public BoopsiGadget
  28. {
  29.    public:
  30.       MyProp(GOB_OWNER,AttrList& attrs)
  31.       : BoopsiGadget(gob_owner,(UBYTE*)"propgclass",attrs) {}
  32.        ~MyProp() {}
  33. };
  34.  
  35.  
  36.  
  37. BOOL running = TRUE;
  38. BOOL close2 = FALSE;
  39. GWindow *stop_window;
  40.  
  41.  
  42. class MySRSP : public SignalResponder
  43. {
  44.    public:
  45.       MySRSP(BYTE signal) : SignalResponder(signal,0) {}
  46.  
  47.       void actionCallback();
  48. };
  49.  
  50. // overload the virtual 'signal received' action callback method.
  51. void MySRSP::actionCallback()
  52. {
  53.    cout << "**Break\n";
  54.    running = FALSE;
  55. }
  56.  
  57. class MyWindow : public GWindow
  58. {
  59.    private:
  60.       void init();
  61.  
  62.    public:
  63.       MyWindow(OWNER,AttrList& attrs) : GWindow(owner,attrs) { init(); }
  64.       void On_CLOSEWINDOW(const IntuiMessageC *msg);
  65.       void On_ACTIVEWINDOW(const IntuiMessageC *msg);
  66.       void On_SIZEVERIFY(const IntuiMessageC *msg);
  67.       void handleIntuiMsg(const IntuiMessageC* imsg);
  68. };
  69.  
  70.  
  71. void MyWindow::init()
  72. {
  73.   modifyIDCMP(CLASS_NEWSIZE|CLASS_CLOSEWINDOW|CLASS_ACTIVEWINDOW|CLASS_SIZEVERIFY);
  74. }
  75.  
  76. void MyWindow::On_CLOSEWINDOW(const IntuiMessageC *msg)
  77.       {
  78.          cout << "CLOSEWINDOW.\n";
  79.          if (this == stop_window) running = FALSE;
  80.          delete this;
  81.       }
  82. void MyWindow::On_ACTIVEWINDOW(const IntuiMessageC *msg)
  83.       {
  84.          cout << title() << " is ACTIVE.\n";
  85.       }
  86. void MyWindow::On_SIZEVERIFY(const IntuiMessageC *msg)
  87.       {
  88.          cout << "SIZEVERIFY. \n";
  89.       }
  90. void MyWindow::handleIntuiMsg(const IntuiMessageC* imsg)
  91.       {
  92.          switch (imsg->getClass())
  93.          {
  94.             case CLASS_CLOSEWINDOW :
  95.                On_CLOSEWINDOW(imsg); break;
  96.             case CLASS_ACTIVEWINDOW :
  97.                On_ACTIVEWINDOW(imsg); break;
  98.             case CLASS_SIZEVERIFY :
  99.                On_SIZEVERIFY(imsg); break;
  100.          }
  101.          GWindow::handleIntuiMsg(imsg);
  102. }
  103.  
  104. // This ITransponder multiplies received PGA_Top values with a given factor.
  105. class PropScalarITP : public ITransponder
  106. {
  107.     private:
  108.         FLOAT factor;
  109.  
  110.         void sendNotification(AttrList& attrs)
  111.         {
  112.             AttrManipulator next(attrs);
  113.             _dout("MyITP :: received notification stream = "<<attrs<<endl);
  114.             if (next.findTagItem(PGA_Top) )
  115.             {
  116.                 next.writeData((LONG)((FLOAT)next.data()*factor));
  117.                _dout("forwarding n.s. = "<<attrs<<endl);
  118.                 if (APPOK(receiver1)) receiver1->setAttributes(attrs);
  119.             }
  120.         }
  121.     public:
  122.         PropScalarITP(FLOAT f,IntuiObject *receiver=NULL) { factor = f; receiver1 = receiver; }      
  123. };          
  124.  
  125.  
  126.  
  127. void APPmain()
  128. {
  129.     ULONG l=0;     // dummy variable needed for a getAttribute() call
  130.    MySRSP sr(SIGBREAKB_CTRL_C);
  131.    
  132.     PropScalarITP prop2to1_itp(0.5);
  133.    PropScalarITP prop1to2_itp(2);
  134.  
  135.     NeXTBorder border;
  136.  
  137.     
  138.    MyWindow *little = new MyWindow(OWNER_NULL,
  139.       AttrList( WA_Title,(ULONG)"Window - close this to stop.",
  140.         WA_Left,200,
  141.         WA_Top,50,
  142.       WA_Width,300,
  143.       WA_Height,150,
  144.       WA_MinHeight,100,
  145.         WA_MinWidth,100,
  146.       WA_MaxHeight,1600,
  147.       WA_MaxWidth,1600,
  148.       WA_DragBar,TRUE,
  149.       WA_SizeGadget,TRUE,
  150.       WA_DepthGadget,TRUE,
  151.       WA_CloseGadget,TRUE,
  152.       TAG_END) );
  153.  
  154.  
  155.    MyWindow *small = new MyWindow(little,
  156.       AttrList( WCV_SharePortWithWindowObj(little),
  157.       WA_Title,(ULONG)"Window sharing userport",
  158.       WA_Left,200,
  159.         WA_Top,200,
  160.       WA_Width,200,
  161.       WA_Height,150,
  162.       WA_MinHeight,100,
  163.         WA_MinWidth,100,
  164.         WA_MaxHeight,1600,
  165.       WA_MaxWidth,1600,
  166.       WA_DragBar,TRUE,
  167.         WA_SizeGadget,TRUE,
  168.         WA_DepthGadget,TRUE,
  169.       WA_CloseGadget,TRUE,
  170.       TAG_END) );
  171.  
  172.  
  173.    MyProp *prop1 = new MyProp(small,
  174.       AttrList( GOB_LeftFromRightOfParent,-30,
  175.       GOB_TopFromTopOfParent,0,
  176.       GOB_RightFromRightOfParent,-1,
  177.       GOB_BottomFromBottomOfParent,0,
  178.       GA_Immediate,TRUE,
  179.       GA_RelVerify,TRUE,
  180.       PGA_Freedom,FREEVERT,
  181.       PGA_Top,100,
  182.       PGA_Total,1000,
  183.       PGA_Visible,500,
  184.       ICA_TARGET,ICTARGET_IDCMP,
  185.       PGA_NewLook,TRUE,
  186.         ITRANSPONDER(&prop1to2_itp),
  187.         GOB_BorderObj(&border),
  188.       TAG_END) );
  189.  
  190.         
  191.    MyProp *prop2 = new MyProp(little,
  192.         AttrList(
  193.         GOB_LeftFromLeftOfParent,2,
  194.       GOB_TopFromTopOfParent,2,
  195.         GOB_RightFromLeftOfParent,35,
  196.       GOB_BottomFromBottomOfParent,-10,
  197.       GA_Immediate,TRUE,
  198.       GA_RelVerify,TRUE,
  199.       PGA_Freedom,FREEVERT,
  200.       PGA_Top, prop1->getAttribute(PGA_Top,l)*2,    // initialise from the ITP source
  201.       PGA_Total,2000,
  202.       PGA_Visible,1000,
  203.       ICA_TARGET,ICTARGET_IDCMP,
  204.       PGA_NewLook,TRUE,
  205.         GOB_BorderObj(&border),
  206.         ITRANSPONDER(&prop2to1_itp),
  207.       TAG_END) );
  208.  
  209.    if (! APPOK(prop2) )
  210.       cerr << " APPOK() on "<<(APTR)prop2<<" failed, status "<<(LONG)prop2->status()<<"\n";
  211.    if (! APPOK(prop1) )
  212.       cerr << "prop1 invalid\n";
  213.  
  214.    prop1to2_itp.setReceiver(prop2);
  215.    prop2to1_itp.setReceiver(prop1);
  216.     
  217.    cout << "ITransponders at "<<(APTR)&prop1to2_itp<<" and "<<(APTR)&prop2to1_itp<<endl;
  218.  
  219.    stop_window = little;
  220.    cout << little << endl;
  221.    cout << "sizeof( )"<<"\nBoopsigadget\t"<<sizeof(MyProp)<<endl<<"\nGWindow\t"<<sizeof(GWindow)<<endl;
  222.  
  223.     little->refreshGList();
  224.     small->refreshGList();
  225.  
  226.    while (running)
  227.    {
  228.       SignalResponder::WaitSignal();
  229.    }
  230.  
  231.    cout << "cleaned up. goodbye.\n";
  232. }