home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / VSCPPv8.zip / VACPP / IBMCPP / samples / IOC / CNR / ACNR.CPP next >
Text File  |  1995-05-01  |  14KB  |  382 lines

  1. /******************************************************************************/
  2. /* Container Sample Program - C++ Source Code (ACNR.CPP)                      */
  3. /*                                                                            */
  4. /* COPYRIGHT: Copyright (C) International Business Machines Corp., 1992,1993. */
  5. /*                                                                            */
  6. /* DISCLAIMER OF WARRANTIES:                                                  */
  7. /*   The following [enclosed] code is sample code created by IBM              */
  8. /*   Corporation.  This sample code is not part of any standard IBM product   */
  9. /*   and is provided to you solely for the purpose of assisting you in the    */
  10. /*   development of your applications.  The code is provided "AS IS",         */
  11. /*   without warranty of any kind.  IBM shall not be liable for any damages   */
  12. /*   arising out of your use of the sample code, even if they have been       */
  13. /*   advised of the possibility of such damages.                              */
  14. /******************************************************************************/
  15. /* NOTE: WE RECOMMEND USING A FIXED SPACE FONT TO LOOK AT THE SOURCE          */
  16. /******************************************************************************/
  17.  
  18. #ifndef _IBASE_                         //Make sure ibase.hpp is included
  19.   #include <ibase.hpp>                  //  since that is where IC_<environ>
  20. #endif                                  //  is defined.
  21. #include <iapp.hpp>                     //IApplication Class
  22. #include <icolor.hpp>                   //IColor Class
  23. #include <istattxt.hpp>                 //IStaticText Class
  24. #include <ipopmenu.hpp>                 //Popup Menu Classes
  25. #include <imenubar.hpp>                 //IMenuBar Class
  26. #include <imenuhdr.hpp>                 //IMenuHandler Class
  27. #include <icnr.hpp>                     //Containers Classes
  28. #include <ireslib.hpp>                  //Resource Classes
  29. #include <imle.hpp>                     //IMultiLineEdit Class
  30. #include <istring.hpp>                  //IString Class
  31. #include <imsgbox.hpp>                  //IMessageBox Class
  32. #include <iframe.hpp>                   //Include IFrameWindow Class Header
  33.  
  34. #include "acnr.hpp"                     //Include ACnrexWindow Class headers
  35. #include "acnr.h"                       //Include our Symbolic definitions
  36.  
  37. //*************************************************************************
  38. // main  - Application entry point                                        *
  39. //*************************************************************************
  40. int main()                              //Main Procedure with no parameters
  41. {
  42.   ACnrexWindow mainWindow (WND_MAIN);   //Create our main window
  43.   IApplication::current().run();        //Get the current application and run
  44.   return 0;
  45. } /* end main */
  46.  
  47. //**************************************************************************
  48. // ACnrexWindow :: ACnrexWindow - Constructor for our main window          *
  49. //**************************************************************************
  50.  
  51. ACnrexWindow :: ACnrexWindow(unsigned long windowId)
  52.   : IFrameWindow (                      //Call IFrameWindow constructor
  53.     IFrameWindow::defaultStyle()        //  Use default plus
  54.     | IFrameWindow::minimizedIcon,      //  Get Minimized Icon from  RC file
  55.     windowId)                           //  Main Window ID
  56. {
  57.   menuBar=new IMenuBar(WND_MAIN, this);
  58.  
  59.   cnrCtl=new IContainerControl(CNR_RESID, this, this);
  60.  
  61.   _pcnrEdit=new CnrEditHandler();       //Create Container Edit Handler
  62.   _pcnrEdit->handleEventsFor(cnrCtl);
  63.  
  64.   ICommandHandler::handleEventsFor(this);
  65.   ICnrHandler::handleEventsFor(cnrCtl); //Set Container Handler for handleOpen
  66.  
  67.   Chdr.handleEventsFor(cnrCtl);
  68.   Chdr.setCnr(cnrCtl);
  69.   _pcnrEdit->handleEventsFor(cnrCtl);
  70.  
  71.   cnrCtl->setExtendedSelection();       //Allow Extended Selection
  72.  
  73.   colIcon=new IContainerColumn (IContainerColumn::isIcon);
  74.  
  75.   colName=new IContainerColumn (IContainerColumn::isIconViewText);
  76.   colName->enableDataUpdate();
  77.   colCode=new IContainerColumn (offsetof(Department, strCode));
  78.   colCode->enableDataUpdate();
  79.   colAddress=new IContainerColumn (offsetof(Department, strAddress));
  80.   colAddress->enableDataUpdate();
  81.  
  82.   setClient(cnrCtl);
  83.   setFocus();
  84.  
  85.   dept1=new Department(                 //Create Department 1
  86.     "OS/2 Development",
  87.     IApplication::current().userResourceLibrary().loadIcon(IBMLOGO),
  88.     "TWPD",
  89.     "Building 71");
  90.   dept1->enableDataUpdate();
  91.  
  92.   dept2=new Department(                 //Create Department 2
  93.     "Code Development",
  94.     IApplication::current().userResourceLibrary().loadIcon(CLOGO),
  95.     "TUID",
  96.     "Building 71");
  97.   dept2->enableDataUpdate();
  98.  
  99.   dept3=new Department(                 //Create Department 3
  100.     "Information Development",
  101.     IApplication::current().userResourceLibrary().loadIcon(WLOGO),
  102.     "TP1D",
  103.     "Building 71");
  104.   dept3->enableDataUpdate();
  105.  
  106.   dept4=new Department(                 //Create Department 4
  107.     "Quality Assurance",
  108.     IApplication::current().userResourceLibrary().loadIcon(OSLOGO),
  109.     "TECD",
  110.     "Building 71");
  111.   dept4->enableDataUpdate();
  112.  
  113.   dept5=new Department(                 //Create Department 5
  114.     "AIX Development",
  115.     IApplication::current().userResourceLibrary().loadIcon(IBMLOGO),
  116.     "TAIX",
  117.     "Building 71");
  118.   dept5->enableDataUpdate();
  119.  
  120.   dept6=new Department(                 //Create Department 6
  121.     "Windows Development",
  122.     IApplication::current().userResourceLibrary().loadIcon(IBMLOGO),
  123.     "TWIN",
  124.     "Building 71");
  125.   dept6->enableDataUpdate();
  126.  
  127.   cnrCtl->addObject(dept1);             //Add Department 1 to container
  128.   cnrCtl->addObject(dept2,dept1);       //Add Department 2 to container under 1
  129.   cnrCtl->addObject(dept3,dept1);       //Add Department 3 to container under 1
  130.   cnrCtl->addObject(dept4,dept1);       //Add Department 4 to container under 1
  131.   cnrCtl->addObject(dept5);             //Add Department 5 to container
  132.   cnrCtl->addObject(dept6);             //Add Department 6 to container
  133.  
  134.   /* set the title data for details view  */
  135.   colIcon->setHeadingText("Icon");
  136.   colName->setHeadingText("Department Name");
  137.   colCode->setHeadingText("Code");
  138.   colAddress->setHeadingText("Address ");
  139.  
  140.   /* add column separators */
  141.   colIcon->showSeparators(IContainerColumn::horizontalSeparator);
  142.   colName->showSeparators(IContainerColumn::verticalSeparator);
  143.   colCode->showSeparators();
  144.   colAddress->showSeparators();
  145.  
  146.   /* add the columns to the container */
  147.   cnrCtl->addColumn(colIcon);
  148.   cnrCtl->addColumn(colName);
  149.   cnrCtl->addColumn(colCode);
  150.   cnrCtl->addColumn(colAddress);
  151.  
  152.   cnrCtl->setDetailsViewSplit(colName, 350);
  153.   cnrCtl->setDeleteObjectsOnClose();
  154.  
  155.   /*-----------------------------------------------------*/
  156.   /* End of Details View setup                           */
  157.   /*-----------------------------------------------------*/
  158.  
  159.   cnrCtl->arrangeIconView();
  160.   cnrCtl->showTreeLine();
  161.   cnrCtl->showTitle();
  162.   cnrCtl->enableDrawItem();
  163.   cnrCtl->showTreeIconView();
  164.   cnrCtl->setMixedTargetEmphasis();
  165.   menuBar->disableItem(ID_MARKALL);     //Disable Mark All Menu Item
  166.   menuBar->disableItem(ID_UNMARKALL);   //Disable Mark All Menu Item
  167.  
  168.   show();
  169.   cnrCtl->show();
  170.  
  171. } /* end ACnrexWindow :: ACnrexWindow(...) */
  172.  
  173. Department :: Department(const IString& Name, //Department Constructor
  174.                 const IPointerHandle& Icon,
  175.                 const IString& Code,
  176.                 const IString& Address) :
  177.        IContainerObject(Name, Icon),    //Call IContainerObject Constructor
  178.        strCode (Code),                  //Set Code
  179.        strAddress (Address)             //Set Address
  180.        {}
  181.  
  182. void Department :: handleOpen (IContainerControl* container)
  183. {
  184.   new ADepartmentView(this, container); //  Pass in our Object and Window
  185. }
  186.  
  187. ADepartmentView :: ADepartmentView (Department * aDept, IContainerControl* anOwner)
  188.                         : IFrameWindow(WND_DEPT, 0, anOwner)
  189. {
  190.   aDept->setOpen();
  191.   saveDept=aDept;
  192.   setAutoDeleteObject();                //Delete C++ Obj, if PM Obj is deleted
  193.  
  194.   IStaticText * stext=new IStaticText(  //Create static text control with
  195.     0x1010, this, this);                //  this as owner & parent
  196.   stext->setText(aDept->iconText());    //Set text in Static Text Control
  197.   stext->setAlignment(                  //Set Alignment to Center in both
  198.     IStaticText::centerCenter);         //  directions
  199.   stext->setAutoDeleteObject();         //Delete C++ Obj, if PM Obj is deleted
  200.  
  201.   setClient(stext);                     //Set static text control as Client
  202.   sizeTo(ISize(400,300));               //Set the pixel size of main window
  203.   setFocus();                           //Set focus to window
  204.   show();                               //Set to show window
  205. }
  206.  
  207. ADepartmentView :: ~ADepartmentView ()
  208. {
  209.   saveDept->setClosed();                //Set Closed
  210. }
  211.  
  212.  
  213. IBase::Boolean ACnrexWindow :: command(ICommandEvent& cmdevt) {
  214.  
  215.   switch(cmdevt.commandId()) {
  216.  
  217.     case ID_VTEXT: {
  218.       menuBar->enableItem(ID_MARKALL);  //Enable Mark All Menu Item
  219.       menuBar->enableItem(ID_UNMARKALL);//Enable Mark All Menu Item
  220.       cnrCtl->showTextView();
  221.       }
  222.       break;
  223.  
  224.     case ID_VFTEXT: {
  225.       menuBar->enableItem(ID_MARKALL);  //Enable Mark All Menu Item
  226.       menuBar->enableItem(ID_UNMARKALL);//Enable Mark All Menu Item
  227.       cnrCtl->showFlowedTextView();
  228.       }
  229.       break;
  230.  
  231.     case ID_VNAME: {
  232.       menuBar->enableItem(ID_MARKALL);  //Enable Mark All Menu Item
  233.       menuBar->enableItem(ID_UNMARKALL);//Enable Mark All Menu Item
  234.       cnrCtl->showNameView();
  235.       }
  236.       break;
  237.  
  238.     case ID_VFNAME: {
  239.       menuBar->enableItem(ID_MARKALL);  //Enable Mark All Menu Item
  240.       menuBar->enableItem(ID_UNMARKALL);//Enable Mark All Menu Item
  241.       cnrCtl->showFlowedNameView();
  242.       }
  243.       break;
  244.  
  245.     case ID_VDETAILS: {
  246.       menuBar->enableItem(ID_MARKALL);  //Enable Mark All Menu Item
  247.       menuBar->enableItem(ID_UNMARKALL);//Enable Mark All Menu Item
  248.       cnrCtl->showDetailsView();
  249.       }
  250.       break;
  251.  
  252.     case ID_FILTER1: {                  //Handle Show Only level Selected
  253.       SelectedObjectsFilter selObjects;
  254.       cnrCtl->filter( selObjects );
  255.       }
  256.       break;
  257.  
  258.     case ID_FILTER2: {                  //Handle Show all
  259.       AllObjectsFilter allObjects;
  260.       cnrCtl->filter( allObjects );
  261.       }
  262.       break;
  263.  
  264.     case ID_VTICON: {
  265.       menuBar->disableItem(ID_MARKALL);  //Disable Mark All Menu Item
  266.       menuBar->disableItem(ID_UNMARKALL);//Disable Mark All Menu Item
  267.       cnrCtl->showTreeIconView();
  268.       }
  269.       break;
  270.  
  271.     case ID_VTTEXT: {
  272.       menuBar->disableItem(ID_MARKALL);  //Disable Mark All Menu Item
  273.       menuBar->disableItem(ID_UNMARKALL);//Disable Mark All Menu Item
  274.       cnrCtl->showTreeTextView();
  275.       }
  276.       break;
  277.  
  278.     case ID_VTNAME: {
  279.       menuBar->disableItem(ID_MARKALL);  //Disable Mark All Menu Item
  280.       menuBar->disableItem(ID_UNMARKALL);//Disable Mark All Menu Item
  281.       cnrCtl->showTreeNameView();
  282.       }
  283.       break;
  284.  
  285.     case ID_VICON: {
  286.       menuBar->enableItem(ID_MARKALL);  //Enable Mark All Menu Item
  287.       menuBar->enableItem(ID_UNMARKALL);//Enable Mark All Menu Item
  288.       cnrCtl->showIconView();
  289.       }
  290.       break;
  291.  
  292.     case ID_VARRANGE: {
  293.       menuBar->enableItem(ID_MARKALL);  //Enable Mark All Menu Item
  294.       menuBar->enableItem(ID_UNMARKALL);//Enable Mark All Menu Item
  295.       cnrCtl->arrangeIconView();
  296.       }
  297.       break;
  298.  
  299.     case ID_MARKALL: {
  300.       IContainerControl::ObjectCursor CO1 (*cnrCtl);
  301.       for (CO1.setToFirst(); CO1.isValid(); CO1.setToNext())
  302.         {
  303.         try
  304.         {
  305.           cnrCtl->setSelected(cnrCtl->objectAt(CO1));
  306.         }
  307.         catch (IException& exc) {}
  308.         }
  309.       }
  310.       break;
  311.  
  312.     case ID_UNMARKALL: {
  313.       IContainerControl::ObjectCursor CO2 (*cnrCtl);
  314.       for (CO2.setToFirst(); CO2.isValid(); CO2.setToNext())
  315.         {
  316.         try
  317.         {
  318.           cnrCtl->removeSelected(cnrCtl->objectAt(CO2));
  319.         }
  320.         catch (IException& exc) {}
  321.         }
  322.       }
  323.       break;
  324.  
  325.     case MI_EDRECORD: {
  326.       IContainerControl::ObjectCursor CO3 (*cnrCtl, IContainerObject::cursored);
  327.       CO3.setToFirst();
  328.       IContainerObject * CurObj = CO3.current();
  329.       cnrCtl->editObject(CurObj);
  330.       }
  331.       break;
  332.  
  333.     case MI_EDNAME: {
  334.       IContainerControl::ObjectCursor CO3 (*cnrCtl, IContainerObject::cursored);
  335.       CO3.setToFirst();
  336.       IContainerObject * CurObj2 = cnrCtl->objectAt(CO3);
  337.       cnrCtl->editObject(CurObj2, colName );
  338.       }
  339.       break;
  340.  
  341.     case MI_EDCODE: {
  342.       IContainerControl::ObjectCursor CO3 (*cnrCtl, IContainerObject::cursored);
  343.       CO3.setToFirst();
  344.       cnrCtl->editObject(CO3.current(),colCode);
  345.       }
  346.       break;
  347.  
  348.     case MI_EDADDRESS: {
  349.       IContainerControl::ObjectCursor CO3 (*cnrCtl, IContainerObject::cursored);
  350.       CO3.setToFirst();
  351.       cnrCtl->editObject(CO3.current(),colAddress);
  352.       }
  353.       break;
  354.   }
  355.   return(false);
  356. }
  357.  
  358. IBase::Boolean ACnrMenuHandler :: makePopUpMenu(IMenuEvent& cnEvt) //
  359. {                                       //
  360.   IPopUpMenu * popUp;                   //Define popUp variable
  361.   if (popupMenuObject()) {
  362.     popUp=new IPopUpMenu(ID_POPMENU,    //Create PopUp Menu
  363.               cnEvt.window());          //
  364.     if (!pcnrCtl->isDetailsView())      //Details View is only way to edit
  365.     {                                   //  Name, Code and Address so
  366.       popUp->disableItem(MI_EDNAME);    //  Disable these items if not
  367.       popUp->disableItem(MI_EDCODE);    //  details view.
  368.       popUp->disableItem(MI_EDADDRESS); //
  369.     }
  370.     else
  371.     {
  372.       popUp->disableItem(MI_EDRECORD);  //
  373.     }
  374.     popUp->setAutoDeleteObject();       //
  375.     popUp->show(cnEvt.mousePosition()); //Show PopUp Menu
  376.     pcnrCtl->showSourceEmphasis(popupMenuObject());
  377.     pcnrCtl->setCursor(popupMenuObject());
  378.     return true;                        //Return PopUp Menu
  379.   }
  380.   return false;
  381. };
  382.