home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional Developers Kit 1992 November / Disc01 / Disc01.mdf / cppbeta / clsam1i / win.cp_ / WIN.CPP
Encoding:
C/C++ Source or Header  |  1992-10-17  |  9.7 KB  |  336 lines

  1. /**************************************************************/
  2. /* Sample Program for IBMCLASS                                */
  3. /*                                                            */
  4. /* CHANGE ACTIVITY:                                           */
  5. /*   DATE:     INITIAL:        DESCRIPTION                    */
  6. /*                                                            */
  7. /*   123091    KKL             Modify for V2.0 classes        */
  8. /**************************************************************/
  9. #include <iframe.hpp>
  10. #include <iapp.hpp>
  11. #include <irect.hpp>
  12. #include <ievtres.hpp>
  13. #include <ievent.hpp>
  14. #include <ihandler.hpp>
  15. #include <ientryfd.hpp>
  16. #include <istattxt.hpp>
  17. #include <idrgsrch.hpp>
  18. #include <idrgtgth.hpp>
  19. #include <idrgtxt.hpp>
  20. #include <idrgstr.hpp>
  21. #include <icmdhdr.hpp>          // ITheCommand, ICommandHandler
  22. #include <iabmenu.hpp>          // IActionBarMenu
  23.  
  24. #include <istream.hpp>
  25.  
  26. #include <itrace.hpp>
  27.  
  28. #include "win.h"
  29.  
  30. extern "C" {
  31.   #define INCL_WIN
  32.   #include <os2.h>
  33. }
  34.  
  35.  
  36. #define DDEFSRC
  37. #define DDEFTGT
  38.  
  39. //#define MYEFSRC
  40. //#define MYEFTGT
  41.  
  42. class MyEFHandler : public IDragSourceHandler
  43. {
  44.   public:
  45.     MyEFHandler(IEntryField* pef);
  46.  
  47.   protected:
  48.     virtual Boolean dispatchHandlerEvent(IEvent& evt);
  49.  
  50. };
  51.  
  52. class MyWindow : public IFrameWindow, public ICommandHandler
  53. {
  54.   public:
  55.     MyWindow(unsigned long windowId, const IWindow* parentWindow,
  56.              const IWindow* ownerWindow, const IRectangle& initialSize);
  57.  
  58.   protected:
  59.     virtual Boolean command(ICommandEvent& cmdevt);
  60.  
  61.   private:
  62.     IEntryField* pef;
  63.     IStaticText* psttxtSrc1;
  64.     IStaticText* psttxtSrc2;
  65.     IStaticText* psttxtTgt;
  66.     IDragSourceHandler* psrch1;
  67.     IDragSourceHandler* psrch2;
  68.     IDragTargetHandler* ptgth;
  69.     IDropCatcher* pdrpcatch;
  70.     IResourceLibrary reslib;
  71.  
  72.     IEntryField* pefSrc;
  73. #ifdef DDEFSRC
  74.     IDragDropEFHandler* pddefhSrc;
  75. #else
  76.   #ifdef MYEFSRC
  77.     MyEFHandler* pmyefhSrc;
  78.   #else
  79.     IDragSourceHandler* psrchText;
  80.     IDragWinTextItem* pdrgitmSrc;
  81.   #endif
  82. #endif
  83.     IEntryField* pefTgt;
  84. #ifdef DDEFTGT
  85.     IDragDropEFHandler* pddefhTgt;
  86. #else
  87.   #ifdef MYEFTGT
  88.     MyEFHandler* pmyefhTgt;
  89.   #else
  90.     IDragTargetHandler* ptgthText;
  91.     IDropWinTextCatcher* pdrpctchTgt;
  92.   #endif
  93. #endif
  94.  
  95.     ITypesString* pstrtyp;
  96.     IRMFsString* pstrrmf;
  97. };
  98.  
  99. /**************************************************************/
  100. /* main() program entry point                                 */
  101. /**************************************************************/
  102. void main()
  103. {
  104.    MyWindow m(WND_MAIN,
  105.               IWindow::desktopWindow(),
  106.               IWindow::desktopWindow(),
  107.               IRectangle());
  108.  
  109.    IApplication::current.run();
  110. }
  111.  
  112. MyWindow::MyWindow( unsigned long windowId, const IWindow* parentWindow,
  113.        const IWindow* ownerWindow, const IRectangle& initialSize)
  114.  : IFrameWindow(windowId, parentWindow, ownerWindow, initialSize),
  115.    reslib()
  116. {
  117.  
  118.   IMODTRACE_DEVELOP("MyWindow :: MyWindow");
  119.  
  120.    // set ourselves as event handler, since we multiple-inherit
  121.    addHandler((IHandler *)this);
  122.  
  123.    // set main menu
  124.    IActionBarMenu* pabmnMain=new IActionBarMenu(WND_MAIN,this);
  125.  
  126.    IResourceId resid100=IResourceId(100,reslib);
  127.    IResourceId resid200=IResourceId(100,reslib);
  128.  
  129.    static const char* pszTyp= "DRGWIN_Test";
  130.  
  131.    IRMFsString strRMF=IRMFsString("DRM_DUMMY","DRF_DUMMY");
  132.  
  133.    ITRACE_DEVELOP(IString("strRMF=") + (IString)strRMF);
  134.  
  135.    pef = new IEntryField(1, this, this, IRectangle(50,50,550,90));
  136.  
  137.    // set source items
  138.    psttxtSrc1= new IStaticText(2, this, this, IRectangle(50,100,550,140));
  139.    psttxtSrc1->setText("This is a Drag Source - Single");
  140.    psttxtSrc2= new IStaticText(3, this, this, IRectangle(50,150,550,190));
  141.    psttxtSrc2->setText("This is a Drag Source - Double");
  142.  
  143.    // now set a source drag handler for this text
  144.    psrch1=new IDragSourceHandler();
  145.    psrch2=new IDragSourceHandler();
  146.  
  147.    // add an item to the set
  148.    IDragImage* pdrgimage100=new IDragImage(resid100,ISize(0,0));
  149.    IDragImage* pdrgimage200=new IDragImage(resid200,ISize(20,20));
  150.  
  151.    ITRACE_DEVELOP("Drag Images created");
  152.  
  153.    IDragItem* pdrgitem11= new IDragItem(psttxtSrc1,
  154.                                         0L,
  155.                                         pszTyp, strRMF,
  156.                                         IDragItem::copyable);
  157.    pdrgitem11->setDragImage(pdrgimage100);
  158.    psrch1->dragItemList().add(pdrgitem11);
  159.  
  160.    IDragItem* pdrgitem21= new IDragItem(psttxtSrc2,
  161.                                         0L,
  162.                                         pszTyp, strRMF,
  163.                                         IDragItem::copyable |
  164.                                         IDragItem::moveable);
  165.    IDragItem* pdrgitem22= new IDragItem(psttxtSrc2,
  166.                                         0L,
  167.                                         pszTyp, strRMF,
  168.                                         IDragItem::copyable |
  169.                                         IDragItem::moveable);
  170.  
  171.    ITRACE_DEVELOP("Drag Items created");
  172.  
  173.    pdrgitem21->setDragImage(pdrgimage100);
  174.    pdrgitem22->setDragImage(pdrgimage200);
  175.  
  176.    psrch2->dragItemList().add(pdrgitem21);
  177.    psrch2->dragItemList().add(pdrgitem22);
  178.  
  179.    // set the handlers
  180.    psttxtSrc1->addHandler(psrch1);
  181.    psttxtSrc2->addHandler(psrch2);
  182.  
  183.    // create drop target
  184.    psttxtTgt= new IStaticText(4, this, this, IRectangle(50,200,550,240));
  185.    psttxtTgt->setText("This is a Drag Target for RMF="+IString(strRMF));
  186.  
  187.    ptgth= new IDragTargetHandler();
  188.  
  189.    // create drop catcher
  190.    pdrpcatch= new IDropCatcher(pszTyp,strRMF);
  191.    ptgth->dropCatcherList().add(pdrpcatch);
  192.  
  193.    // set the handler on the static text
  194.    psttxtTgt->addHandler(ptgth);
  195.  
  196.    IEntryField* pefSrc=new IEntryField(1000, this, this, IRectangle(50,250,550,290));
  197. #ifdef DDEFSRC
  198.    pefSrc->setText("Source & Target");
  199.    IDragDropEFHandler* pddefhSrc = new IDragDropEFHandler(pefSrc);
  200. #else
  201.    pefSrc->setText("Source Only");
  202.    IDragSourceHandler* psrchText= new IDragSourceHandler(IDragSourceHandler::systemIcons);
  203.  
  204.    IDragWinTextItem* pdrgitmSrc= new IDragWinTextItem(pefSrc);
  205.    psrchText->dragItemList().add(pdrgitmSrc);
  206.    pefSrc->addHandler(psrchText);
  207. #endif
  208.    ITRACE_DEVELOP(IString("(ul)pefSrc->handle()=") + IString((unsigned long)pefSrc->handle()));
  209.    ITRACE_DEVELOP(IString("(ul)pefSrc=") + IString((unsigned long)pefSrc));
  210.    ITRACE_DEVELOP(IString("pefSrc->text()") + pefSrc->text());
  211.    ITextControl* ptxtctl=(ITextControl*)pefSrc;
  212.    ITRACE_DEVELOP(IString("(ul)ptxtctl") + IString((unsigned long)ptxtctl));
  213.    ITRACE_DEVELOP(IString("ptxtctl->text()") + ptxtctl->text());
  214.  
  215.    IEntryField* pefTgt=new IEntryField(1001, this, this, IRectangle(50,300,550,340));
  216. #ifdef DDEFTGT
  217.    pefTgt->setText("Source & Target");
  218.    IDragDropEFHandler* pddefhTgt = new IDragDropEFHandler(pefTgt);
  219. #else
  220.    pefTgt->setText("Target Only");
  221.    IDragTargetHandler* ptgthText= new IDragTargetHandler();
  222.  
  223.    IDropWinTextCatcher* pdrpctchTgt= new IDropWinTextCatcher(pefTgt);
  224.    pefTgt->addHandler(ptgthText);
  225.    ptgthText->dropCatcherList().add(pdrpctchTgt);
  226. #endif
  227.  
  228.    pstrtyp=0;
  229.  
  230.    // show our frame
  231.    show();
  232. }
  233.  
  234. /**************************************************************************/
  235. /* MyWindow :: command                                          PHG 10/09 */
  236. /*   Handle menu commands                                                 */
  237. /**************************************************************************/
  238. Boolean MyWindow :: command(ICommandEvent& cmdevt)
  239. {
  240.   switch(cmdevt.commandId()) {
  241.     case MI_DRGSTR_TYP_CT:
  242.       {IString strEF=pef->text();
  243.  
  244.         ITypesString strtyp(strEF);
  245.  
  246.         psttxtSrc1->setText((IString)strtyp);
  247.       }
  248.       break;
  249.  
  250.     case MI_DRGSTR_TYP_CNT:
  251.       if(pstrtyp!=0) {
  252.         psttxtSrc2->setText(IString(pstrtyp->count()));
  253.       } else {
  254.         psttxtSrc2->setText("?");
  255.       }
  256.       break;
  257.  
  258.     case MI_DRGSTR_TYP_IDX:
  259.       if(pstrtyp!=0) {
  260.         unsigned uEF=(pef->text()).asUnsigned();
  261.         psttxtSrc2->setText(pstrtyp->type(uEF));
  262.       } else {
  263.         psttxtSrc2->setText("?");
  264.       }
  265.       break;
  266.  
  267.     case MI_DRGSTR_TYP_TRUE:
  268.       if(pstrtyp!=0) {
  269.         psttxtSrc2->setText(pstrtyp->trueType());
  270.       } else {
  271.         psttxtSrc2->setText("?");
  272.       }
  273.       break;
  274.  
  275.     case MI_DRGSTR_TYP_VERT:
  276.       if(pstrtyp!=0) {
  277.        IString strEF=pef->text();
  278.  
  279.         ITypesString strtyp=ITypesString(strEF);
  280.         psttxtSrc2->setText(IString(pstrtyp->verifyTrueType(strtyp)));
  281.       } else {
  282.         psttxtSrc2->setText("?");
  283.       }
  284.       break;
  285.  
  286.     case MI_DRGSTR_RMF_CT:
  287.       {IString strEF=pef->text();
  288.  
  289.         IRMFsString strrmf(strEF);
  290.  
  291.         psttxtSrc1->setText((IString)strrmf);
  292.       }
  293.       break;
  294.  
  295.     case MI_DRGSTR_RMF_CNT:
  296.       if(pstrrmf!=0) {
  297.         psttxtSrc2->setText(IString(pstrrmf->count()));
  298.       } else {
  299.         psttxtSrc2->setText("?");
  300.       }
  301.       break;
  302.  
  303.     case MI_DRGSTR_RMF_IDX:
  304.       if(pstrrmf!=0) {
  305.         unsigned uEF=(pef->text()).asUnsigned();
  306.         psttxtSrc2->setText(pstrrmf->RMF(uEF));
  307.       } else {
  308.         psttxtSrc2->setText("?");
  309.       }
  310.       break;
  311.  
  312.     case MI_DRGSTR_RMF_NATV:
  313.       if(pstrrmf!=0) {
  314.         psttxtSrc2->setText(pstrrmf->nativeRMF());
  315.       } else {
  316.         psttxtSrc2->setText("?");
  317.       }
  318.       break;
  319.  
  320.     case MI_DRGSTR_RMF_VERN:
  321.       if(pstrrmf!=0) {
  322.        IString strEF=pef->text();
  323.  
  324.         IRMFsString strrmf=IRMFsString(strEF);
  325.         psttxtSrc2->setText(IString(pstrrmf->verifyNativeRMF(strrmf)));
  326.       } else {
  327.         psttxtSrc2->setText("?");
  328.       }
  329.       break;
  330.  
  331.  
  332.   }/* end switch */
  333.  
  334.   return(0);
  335. }/* end MyWindow :: command(...) */
  336.