home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / sompar.zip / SOMPARTS.CPP < prev    next >
C/C++ Source or Header  |  1994-01-10  |  12KB  |  396 lines

  1. //
  2. // Project: Digitalk Parts like Toolbar and SOMObjects Demo
  3. // File:    Somparts.cpp
  4. // Author:  Stewart Hyde
  5. // Created: Dec   17, 1993
  6. // Updated: Jan   10, 1994
  7. //
  8. // Description:
  9. //
  10.  
  11. #include <iapp.hpp>
  12. #include <icolor.hpp>
  13. #include <istring.hpp>
  14. #include <imsgbox.hpp>
  15. #include "somparts.hpp"
  16. #include "somparts.h"
  17. #include "parts.hpp"
  18. #include "listbox.hpp"
  19. #include "infodlg.hpp"
  20.   
  21.  
  22. // ------------------------------------------------------------------------
  23. //  Class:                N/A
  24. //  Function:            main
  25. //                
  26. //  Description:        main program entry point
  27. //       
  28. //  Input:                int argc      - no of command line arguments
  29. //                            char **argv - pointer to arguments
  30. //
  31. //  Output:
  32. //
  33. //  Notes:
  34. //
  35. // ------------------------------------------------------------------------
  36.  
  37. int main(int argc, char **argv)
  38. {
  39.       PartsWindow    *pPartsWindow;
  40.     int result = 0;
  41.  
  42.     // --------------------------------------------------------------------  
  43.       // Create the main application's window for this demo program
  44.     // --------------------------------------------------------------------  
  45.  
  46.       try
  47.       {
  48.         // -----------------------------------------------------------------
  49.         // create an instance of the PartsWindow window class
  50.         // -----------------------------------------------------------------
  51.  
  52.         pPartsWindow = new PartsWindow(IFrameWindow::desktopWindow(), 0);
  53.  
  54.         // -----------------------------------------------------------------
  55.         // tell the object to delete itself when its window is destroyed.
  56.         // -----------------------------------------------------------------
  57.  
  58.         pPartsWindow->setAutoDeleteObject();
  59.  
  60.         // -----------------------------------------------------------------
  61.         // set the input focus to the object's window and display it.
  62.         // -----------------------------------------------------------------
  63.  
  64.         pPartsWindow->setFocus();
  65.         pPartsWindow->show();
  66.                                          
  67.         // -----------------------------------------------------------------
  68.         // execute the application, processing its events
  69.         // -----------------------------------------------------------------
  70.  
  71.         IApplication::current().run();
  72.     }
  73.       catch (IException &exc)
  74.       {
  75.         result = -1;
  76.       }
  77.  
  78.     return (result);
  79. }
  80.  
  81. // ------------------------------------------------------------------------
  82. //  Class:                PartsWindow                
  83. //  Function:            PartsWindow (constructor)
  84. //                
  85. //  Description:        This is contructor for the main parts window
  86. //       
  87. //  Input:                IWindow *parentWin - parent Window
  88. //                            IWindow *ownerWin  - owner Window
  89. //
  90. //  Output:
  91. //
  92. //  Notes:
  93. //
  94. // ------------------------------------------------------------------------
  95.  
  96.  
  97. PartsWindow::PartsWindow(IWindow *parentWin, IWindow *ownerWin)
  98.   : IFrameWindow(WND_PARTS_WINDOW, 
  99.                    parentWin, ownerWin,
  100.                    IRectangle(),
  101.                          IFrameWindow::defaultStyle() | shellPosition),
  102.        clientWin(WND_PARTS_WINDOW, this, this),
  103.        menuBar(WND_PARTS_WINDOW, this),
  104.        title(this, WND_PARTS_WINDOW)
  105. {
  106.     // ---------------------------------------------------------------------
  107.     // Handle command events
  108.     // ---------------------------------------------------------------------
  109.  
  110.       ICommandHandler::handleEventsFor(this);
  111.   
  112.     // ---------------------------------------------------------------------
  113.       // Set up the client window
  114.     // ---------------------------------------------------------------------
  115.  
  116.       setClient(&clientWin);
  117.   
  118.       setExceptionFunction(&excHandler);
  119.  
  120.     somAction = new SomAction();
  121.  
  122.     // ---------------------------------------------------------------------
  123.    // Initial debuging to false and setup menus approviately
  124.     // ---------------------------------------------------------------------
  125.  
  126.     DebugStatus=true;
  127.     DSOM_DebugMessage(false);
  128. }                             
  129.  
  130. // ------------------------------------------------------------------------
  131. //  Class:                PartsWindow
  132. //  Function:            DoPartsNoteBook
  133. //                
  134. //  Description:        process parts notebook
  135. //       
  136. //  Input:                N/A
  137. //
  138. //  Output:                N/A
  139. //
  140. //  Notes:
  141. //
  142. // ------------------------------------------------------------------------
  143.  
  144. void PartsWindow::DoPartsNoteBook()
  145. {
  146.    // ---------------------------------------------------------------------
  147.     //  Create a frame window to wrap around our Parts NoteBook 
  148.    // ---------------------------------------------------------------------
  149.       
  150.    IFrameWindow *frameWin = 
  151.           new IFrameWindow(WND_PARTS_NOTE_BOOK, 
  152.                            desktopWindow(), 
  153.                            this, 
  154.                            IRectangle(),
  155.                                     IFrameWindow::dialogBorder |
  156.                            IFrameWindow::defaultStyle() &
  157.                            ~IFrameWindow::shellPosition &
  158.                                     ~IFrameWindow::sizingBorder &
  159.                            ~IFrameWindow::windowList);
  160.    frameWin->setAutoDeleteObject();
  161.  
  162.     // ---------------------------------------------------------------------
  163.     // Create a PartsNoteTool notebook
  164.     // ---------------------------------------------------------------------
  165.     
  166.    PartsNoteTool *notebk = new PartsNoteTool(frameWin, frameWin, somAction);
  167.    notebk->setAutoDeleteObject();
  168.  
  169.     // ---------------------------------------------------------------------
  170.    // Set the notebook as the client window for the frame window
  171.     // ---------------------------------------------------------------------
  172.  
  173.    frameWin->setClient(notebk);
  174.  
  175.     // ---------------------------------------------------------------------
  176.    // size the window to the notebook and display it
  177.     // ---------------------------------------------------------------------
  178.  
  179.    frameWin->sizeTo(frameWin->frameRectFor(notebk->rect()).size());
  180.    frameWin->setFocus();
  181.    frameWin->show();
  182. }
  183.  
  184.  
  185. // ------------------------------------------------------------------------
  186. //  Class:                PartsWindow
  187. //  Function:            DoPartsListBox
  188. //                
  189. //  Description:        process parts notebook
  190. //       
  191. //  Input:                N/A
  192. //
  193. //  Output:                N/A
  194. //
  195. //  Notes:
  196. //
  197. // ------------------------------------------------------------------------
  198.  
  199. void PartsWindow::DoPartsListBox()
  200. {
  201.    // ---------------------------------------------------------------------
  202.     //  Create a frame window to wrap around our Parts Listbox dialog 
  203.    // ---------------------------------------------------------------------
  204.  
  205.    IFrameWindow *frameWin = new IFrameWindow(WND_PARTS_LISTBOX, 
  206.              desktopWindow(), this,
  207.              IRectangle(),
  208.              IFrameWindow::shellPosition | IFrameWindow::systemMenu |
  209.                  IFrameWindow::titleBar| IWindow::clipSiblings |
  210.              IFrameWindow::dialogBorder| IWindow::clipChildren);
  211.  
  212.    // ---------------------------------------------------------------------
  213.     //  Create a PartListBoxObject
  214.    // ---------------------------------------------------------------------
  215.  
  216.    PartsListbox *listbox = new PartsListbox(frameWin, frameWin, somAction);
  217.    frameWin->setClient(listbox);
  218.  
  219.     // ---------------------------------------------------------------------
  220.    // size the dialog to the notebook and display it
  221.     // ---------------------------------------------------------------------
  222.  
  223.    frameWin->sizeTo(frameWin->frameRectFor(listbox->rect()).size());
  224.    listbox->setColor(listbox->background, IGUIColor(IGUIColor::dialogBgnd));
  225.     frameWin->setAutoDeleteObject();
  226.     listbox->setAutoDeleteObject();
  227.    frameWin->setFocus();
  228.     frameWin->show();
  229. }
  230.  
  231. // ------------------------------------------------------------------------
  232. //  Class:                PartsWindow
  233. //  Function:            DoProdInformation
  234. //                
  235. //  Description:        Display information about this program
  236. //       
  237. //  Input:                N/A
  238. //
  239. //  Output:                N/A
  240. //
  241. //  Notes:
  242. //
  243. // ------------------------------------------------------------------------
  244.  
  245. void PartsWindow::DoProdInformation()
  246. {
  247.     InfoDialog ProdInfo(WND_PROD_INFORMATION,desktopWindow(),this);
  248.  
  249.     ProdInfo.DisplayDialog();
  250. }
  251.  
  252.  
  253. // ------------------------------------------------------------------------
  254. //  Class:                PartsWindow
  255. //  Function:            DSOM_DebugMessage
  256. //                
  257. //  Description:        Enable or Disable DSOM debug messages which are sent
  258. //                            to the server's window
  259. //       
  260. //  Input:                Boolean Status - Enable or Disable flag
  261. //
  262. //  Output:                N/A
  263. //
  264. //  Notes:
  265. //
  266. // ------------------------------------------------------------------------
  267.  
  268. void PartsWindow::DSOM_DebugMessage(Boolean Status)
  269. {
  270.     // --------------------------------------------------------------------
  271.     //  Save status for later
  272.     // --------------------------------------------------------------------
  273.  
  274.     DebugStatus = Status;
  275.  
  276.  
  277.     // --------------------------------------------------------------------
  278.     //  Set up menus approviately
  279.     // --------------------------------------------------------------------
  280.  
  281.     if (Status)
  282.     {
  283.        menuBar.enableItem(MI_DISABLE_DEBUG);     
  284.        menuBar.disableItem(MI_ENABLE_DEBUG);     
  285.     }
  286.     else
  287.     {
  288.        menuBar.enableItem(MI_ENABLE_DEBUG);     
  289.        menuBar.disableItem(MI_DISABLE_DEBUG);     
  290.     }
  291.  
  292.     // --------------------------------------------------------------------
  293.     //  Change state via SomAction (DSOM)
  294.     // --------------------------------------------------------------------
  295.     
  296.     somAction->DebugMessage(Status);    
  297. }
  298.  
  299. // ------------------------------------------------------------------------
  300. //  Class:                PartsWindow
  301. //  Function:            command
  302. //                
  303. //  Description:        Main applications windows command event handler
  304. //       
  305. //  Input:                ICommandEvent &evt - command event
  306. //
  307. //  Output:                Boolean - result
  308. //
  309. //  Notes:
  310. //
  311. // ------------------------------------------------------------------------
  312.  
  313. Boolean PartsWindow::command(ICommandEvent &evt)
  314. {
  315.       switch(evt.commandId())
  316.       {
  317.          
  318.         case MI_PARTS_NOTEBOOK:  
  319.             DoPartsNoteBook();
  320.             break;
  321.  
  322.         case MI_PARTS_LISTBOX:  
  323.             DoPartsListBox();
  324.             break;
  325.  
  326.         case MI_PROD_INFORMATION:  
  327.             DoProdInformation();
  328.             break;
  329.  
  330.         case MI_DISABLE_DEBUG:
  331.             DSOM_DebugMessage(false);
  332.             break;
  333.  
  334.         case MI_ENABLE_DEBUG:
  335.             DSOM_DebugMessage(true);
  336.             break;
  337.  
  338.         default:
  339.             return false;
  340.   }
  341.   return true;
  342. }
  343.  
  344. // ------------------------------------------------------------------------
  345. //  Class:                PartsWindow
  346. //  Function:             handleException
  347. //                
  348. //  Description:        nested ExceptionHandler function to intercept 
  349. //                            uncaught exceptions while windows is dispatching
  350. //                            events
  351. //       
  352. //  Input:                IException &exception - exception 
  353. //                            IEvent     &event         - event that cause this exception        
  354. //
  355. //  Output:
  356. //
  357. //  Notes:
  358. //
  359. // ------------------------------------------------------------------------
  360.  
  361. Boolean PartsWindow::ExceptionHandler::handleException(IException &exception, 
  362.                                                        IEvent     &event)
  363. {
  364.  
  365.     // ---------------------------------------------------------------------
  366.     // Create text to display in message box
  367.     // ---------------------------------------------------------------------
  368.       IString str("SOMPARTS Exception:\n\n");
  369.       if (exception.textCount() == 0)
  370.         str += "undefined exception";
  371.       else
  372.         str += exception.text(exception.textCount()-1);
  373.  
  374.  
  375.     // ---------------------------------------------------------------------
  376.     // Create and display a message box to user for exception
  377.     // ---------------------------------------------------------------------
  378.  
  379.       IMessageBox msgBox(event.window());
  380.       msgBox.setTitle(exception.name());
  381.       IMessageBox::Response result = 
  382.          msgBox.show(str, IMessageBox::okCancelButton   |
  383.                        IMessageBox::informationIcon  |
  384.                        IMessageBox::applicationModal |
  385.                        IMessageBox::moveable);
  386.  
  387.     // ---------------------------------------------------------------------
  388.     // if user press ok, return true otherwise false
  389.     // ---------------------------------------------------------------------
  390.  
  391.       if (result == IMessageBox::ok)
  392.         return true;
  393.       else
  394.         return false;
  395. }
  396.