home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / vos2-121.zip / v / drawex / drawcmdw.cpp < prev    next >
C/C++ Source or Header  |  1998-07-03  |  5KB  |  198 lines

  1. //================================================================
  2. //  drawcmdw.cxx:     Source file for drawApp cmdwin class
  3. //  Copyright (C) 1995  Bruce E. Wampler
  4. //================================================================
  5. #include <v/vnotice.h>    // so we can use notice
  6. #include <v/vpen.h>    // for drawing pen
  7. #include <v/vfilesel.h>    // for file selection
  8.  
  9. #include "drawcmdw.h"    // our header
  10.  
  11. //    Start defines for the main window with 100
  12.  
  13.   const ItemVal m_Clear = 100;
  14.   const ItemVal m_LineWidth = 101;
  15.   const ItemVal m_ChangePen = 102;
  16.   const ItemVal m_ColorBtn = 103;
  17.  
  18.     // Define the File and Edit pulldown menus
  19.     static vMenu FileMenu[] =
  20.       {
  21.     {"New", M_New, isSens, notChk, noKeyLbl, noKey, noSub},
  22.     {"Open", M_Open, isSens, notChk, noKeyLbl, noKey, noSub},
  23.     {"Save", M_Save, isSens, notChk, noKeyLbl, noKey, noSub},
  24.     {"Save As", M_SaveAs, isSens,notChk,noKeyLbl,noKey,noSub},
  25.     {"-", M_Line, notSens, notChk, noKeyLbl, noKey, noSub},
  26.     {"Exit", M_Exit, isSens, notChk, noKeyLbl, noKey, noSub},
  27.     {NULL}
  28.       };
  29.  
  30.     static vMenu EditMenu[] =
  31.       {
  32.     {"Clear", m_Clear, isSens, notChk, noKeyLbl, noKey,noSub},
  33.     {NULL}
  34.       };
  35.  
  36.     // Define the main menu
  37.     vMenu MainMenu[] =
  38.       {
  39.     {"File",M_File,isSens,notUsed,notUsed,noKey,&FileMenu[0]},
  40.     {"Edit",M_Edit,isSens,notUsed,notUsed,noKey,&EditMenu[0]},
  41.     {NULL}
  42.       };
  43.  
  44.     // Define the command bar
  45.     static int minMaxStep[3] = {1, 20, 1};    // for line width
  46.     static vColor btnColor(0,0,0);
  47.     static CommandObject CommandBar[] =
  48.       {
  49.     {C_Button, m_Clear, m_Clear, "Clear", NoList,
  50.         CA_None,isSens,NoFrame,0,0},
  51.     {C_Label, 999, 0 ," Pen Width: ", NoList,
  52.         CA_None, isSens, NoFrame,0,0},
  53.     {C_Spinner,m_LineWidth,1,"",(void*)&minMaxStep[0],
  54.         CA_None,isSens,NoFrame,0,0},
  55.     {C_Label, 999, 0, " Pen Color: ",NoList,
  56.         CA_None,isSens,NoFrame,0,0},
  57.     {C_ColorButton, m_ColorBtn, 0, "", (void*)&btnColor,
  58.         CA_None,isSens,NoFrame,0,0,12},
  59. #define vC_Size 12            // size of color buttons
  60. #include<v/vcb2x8.h>    // define a color selection box
  61.     {C_EndOfList,0,0,0,0,CA_None,0,0,0}
  62.       };
  63.  
  64. //================>>> myCmdWindow::myCmdWindow <<<================
  65.   myCmdWindow::myCmdWindow(char* name, int width, int height) :
  66.     vCmdWindow(name, width, height)
  67.   {
  68.     // Create and add the proper panes to the CmdWindow
  69.  
  70.     *_fname = 0;            // no name
  71.  
  72.     myMenu = new vMenuPane(MainMenu);    // Add the main menu
  73.     AddPane(myMenu);
  74.  
  75.     myCmdPane = new vCommandPane(CommandBar); // Add command pane
  76.     AddPane(myCmdPane);
  77.  
  78.     myCanvas = new myCanvasPane;    // Add the canvas pane
  79.     AddPane(myCanvas);
  80.  
  81.     ShowWindow();        // FINALLY, we must show the window!
  82.   }
  83.  
  84. //===============>>> myCmdWindow::~myCmdWindow <<<================
  85.   myCmdWindow::~myCmdWindow()
  86.   {
  87.     delete myMenu;    // Delete everything new'ed in
  88.     delete myCanvas;    //   the constructor
  89.     delete myCmdPane;
  90.   }
  91.  
  92. //==============>>> myCmdWindow::WindowCommand <<<================
  93.   void myCmdWindow::WindowCommand(ItemVal id, ItemVal val,
  94.     CmdType cType)
  95.   {
  96.     // route all commands through here - menus and buttons
  97.  
  98.     static char* filter[] = {"*.drw","*", 0};    // file filter
  99.     static int fi = 0;
  100.     vNoticeDialog note(this);    // for user notification
  101.  
  102.     switch (id)        // switch on id of commands
  103.       {
  104.     case M_New:
  105.       {
  106.         // call our NewAppWin method
  107.         theApp->NewAppWin(0,"V Draw - No Name",500,250,0);
  108.         break;
  109.       }
  110.  
  111.     case M_Open:
  112.       {
  113.         if (*_fname)
  114.           {
  115.         note.Notice("Create a New window first.");
  116.         break;
  117.           }
  118.  
  119.             vFileSelect fsel(this);     // V file select dialog
  120.  
  121.             if (!fsel.FileSelect("Open V Draw File",
  122.           _fname,99,filter,fi) || !*_fname)
  123.         break;            // ignore if no selection
  124.  
  125.         if (!myCanvas->Read(_fname))    // Save in _fname
  126.           {
  127.         note.Notice("Unable to read file");
  128.         break;
  129.           }
  130.         SetTitle(_fname);        // show on title bar
  131.         myCanvas->Redraw(0,0,0,0);    // paint it
  132.         break;
  133.       }
  134.  
  135.     case M_Save:
  136.       {
  137.         if (*_fname)            // have a name
  138.           {
  139.         if (!myCanvas->Save(_fname))    // Save in _fname
  140.             note.Notice("Unable to save file");
  141.         break;
  142.           }
  143.         // else fall through to SaveAs
  144.       }
  145.  
  146.     case M_SaveAs:
  147.       {
  148.             vFileSelect fsel(this);     // V file select dialog
  149.  
  150.             if (!fsel.FileSelectSave("Save V Draw File As",
  151.           _fname,99,filter,fi) || !*_fname)
  152.         break;            // ignore if no selection
  153.  
  154.         if (!myCanvas->Save(_fname))    // Save in _fname
  155.           {
  156.         note.Notice("Unable to read file");
  157.         break;
  158.           }
  159.         SetTitle(_fname);
  160.         break;
  161.       }
  162.  
  163.     case M_Exit:
  164.       {
  165.         theApp->Exit();    // Standard action for Exit
  166.         break;
  167.       }
  168.  
  169.     case m_LineWidth:
  170.       {
  171.         _pen.SetWidth(val);    // set new pen width
  172.         myCanvas->SetPen(_pen);
  173.         break;
  174.       }
  175.  
  176.     case m_Clear:            // clear the screen
  177.       {
  178.         myCanvas->Clear();
  179.         break;
  180.       }
  181.  
  182.     default:            // change pen color?
  183.       {
  184.         if (id >= M_Black && id <= M_White)  // color button
  185.           {
  186.         _pen.SetColor(vStdColors[val]);
  187.         myCanvas->SetPen(_pen);
  188.         SetValue(m_ColorBtn,(ItemVal)_pen.GetColor().r(),Red);
  189.         SetValue(m_ColorBtn,(ItemVal)_pen.GetColor().g(),Green);
  190.         SetValue(m_ColorBtn,(ItemVal)_pen.GetColor().b(),Blue);
  191.           }
  192.         else        // pass up hierarchy
  193.         vCmdWindow::WindowCommand(id, val, cType);
  194.         break;
  195.       }
  196.       }
  197.   }
  198.