home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / vos2-121.zip / v / icons / icondemo.cpp < prev    next >
C/C++ Source or Header  |  1998-11-09  |  13KB  |  344 lines

  1. //=======================================================================
  2. //  icondemo.cpp:     Source file for icon demo
  3. //  Copyright (C) 1995  Bruce E. Wampler
  4. //
  5. //  This program is part of the V C++ GUI Framework example programs.
  6. //
  7. //  This program is free software; you can redistribute it and/or modify
  8. //  it under the terms of the GNU General Public License as published by
  9. //  the Free Software Foundation; either version 2 of the License, or
  10. //  (at your option) any later version.
  11. //
  12. //  This program is distributed in the hope that it will be useful,
  13. //  but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. //  GNU General Public License for more details.
  16. //
  17. //  You should have received a copy of the GNU General Public License
  18. //  (see COPYING) along with this program; if not, write to the Free
  19. //  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20. //=======================================================================
  21.  
  22. #include "icondemo.h"    // our header
  23. #include <v/vicon.h>
  24.  
  25. // This program is used to show the sample 16x16 icons provided with the V
  26. // distribution. It doesn't do anything else.
  27.  
  28. //****************************************************************************
  29.  
  30.     // Define a  menu and some command bars
  31.  
  32.     static vMenu ShortFile[] =
  33.       {
  34.         {"E&xit", M_Exit, isSens, notChk, noKeyLbl, noKey, noSub},
  35.         {NULL}
  36.       };
  37.  
  38. #include "bold.vbm"
  39.     static vIcon boldI(&bold_bits[0],bold_height,bold_width);
  40. #include "brush.vbm"
  41.     static vIcon brushI(&brush_bits[0],brush_height,brush_width);
  42. #include "check.vbm"
  43.     static vIcon checkI(&check_bits[0],check_height,check_width);
  44. #include "copy.vbm"
  45.     static vIcon copyI(©_bits[0],copy_height,copy_width);
  46. #include "cut.vbm"
  47.     static vIcon cutI(&cut_bits[0],cut_height,cut_width);
  48. #include "draw.vbm"
  49.     static vIcon drawI(&draw_bits[0],draw_height,draw_width);
  50. #include "ellip.vbm"
  51.     static vIcon ellipI(&ellip_bits[0],ellip_height,ellip_width);
  52. #include "help.vbm"
  53.     static vIcon helpI(&help_bits[0],help_height,help_width);
  54. #include "italic.vbm"
  55.     static vIcon italicI(&italic_bits[0],italic_height,italic_width);
  56. #include "line.vbm"
  57.     static vIcon lineI(&line_bits[0],line_height,line_width);
  58. #include "new.vbm"
  59.     static vIcon newI(&new_bits[0],new_height,new_width);
  60. #include "open.vbm"
  61.     static vIcon openI(&open_bits[0],open_height,open_width);
  62. #include "paste.vbm"
  63.     static vIcon pasteI(&paste_bits[0],paste_height,paste_width);
  64. #include "pencil.vbm"
  65.     static vIcon pencilI(&pencil_bits[0],pencil_height,pencil_width);
  66. #include "poly.vbm"
  67.     static vIcon polyI(&poly_bits[0],poly_height,poly_width);
  68. #include "preview.vbm"
  69.     static vIcon previewI(&preview_bits[0],preview_height,preview_width);
  70. #include "print.vbm"
  71.     static vIcon printI(&print_bits[0],print_height,print_width);
  72. #include "rect.vbm"
  73.     static vIcon rectI(&rect_bits[0],rect_height,rect_width);
  74. #include "redo.vbm"
  75.     static vIcon redoI(&redo_bits[0],redo_height,redo_width);
  76. #include "save.vbm"
  77.     static vIcon saveI(&save_bits[0],save_height,save_width);
  78. #include "underln.vbm"
  79.     static vIcon underlnI(&underln_bits[0],underln_height,underln_width);
  80. #include "undo.vbm"
  81.     static vIcon undoI(&undo_bits[0],undo_height,undo_width);
  82. #include "zoom.vbm"
  83.     static vIcon zoomI(&zoom_bits[0],zoom_height,zoom_width);
  84.  
  85. #include "alpha.vbm"
  86.     static vIcon alphaI(&alpha_bits[0],alpha_height,alpha_width);
  87. #include "back.vbm"
  88.     static vIcon backI(&back_bits[0],back_height,back_width);
  89. #include "book.vbm"
  90.     static vIcon bookI(&book_bits[0],book_height,book_width);
  91. #include "cursor.vbm"
  92.     static vIcon cursorI(&cursor_bits[0],cursor_height,cursor_width);
  93. #include "down.vbm"
  94.     static vIcon downI(&down_bits[0],down_height,down_width);
  95. #include "drawline.vbm"
  96.     static vIcon drawlineI(&drawline_bits[0],drawline_height,drawline_width);
  97. #include "fill.vbm"
  98.     static vIcon fillI(&fill_bits[0],fill_height,fill_width);
  99. #include "find.vbm"
  100.     static vIcon findI(&find_bits[0],find_height,find_width);
  101. #include "findagn.vbm"
  102.     static vIcon findagnI(&findagn_bits[0],findagn_height,findagn_width);
  103. #include "forward.vbm"
  104.     static vIcon forwardI(&forward_bits[0],forward_height,forward_width);
  105. #include "left.vbm"
  106.     static vIcon leftI(&left_bits[0],left_height,left_width);
  107. #include "page.vbm"
  108.     static vIcon pageI(&page_bits[0],page_height,page_width);
  109. #include "right.vbm"
  110.     static vIcon rightI(&right_bits[0],right_height,right_width);
  111. #include "up.vbm"
  112.     static vIcon upI(&up_bits[0],up_height,up_width);
  113.  
  114.     static CommandObject CommandBar[] =
  115.       {
  116.     {C_Button, M_Exit, 1, "Exit", NoList,CA_None, isSens, 0, 0, 0},
  117.     {C_IconButton,20,20,"",&newI,CA_None,isSens,0,0,0,0,"new.vbm"},
  118.     {C_IconButton,21,21,"",&openI,CA_None,isSens,0,0,0,0,"open.vbm"},
  119.     {C_IconButton,29,29,"",&saveI,CA_None,isSens,0,0,0,0,"save.vbm"},
  120.     {C_IconButton,14,14,"",&cutI,CA_None,isSens,0,0,0,0,"cut.vbm"},
  121.     {C_IconButton,13,13,"",©I,CA_None,isSens,0,0,0,0,"copy.vbm"},
  122.     {C_IconButton,22,22,"",&pasteI,CA_None,isSens,0,0,0,0,"paste.vbm"},
  123.     {C_IconButton,31,31,"",&undoI,CA_None,isSens,0,0,0,0,"undo.vbm"},
  124.     {C_IconButton,28,28,"",&redoI,CA_None,isSens,0,0,0,0,"redo.vbm"},
  125.     {C_IconButton,26,26,"",&printI,CA_None,isSens,0,0,0,0,"print.vbm"},
  126.     {C_IconButton,25,25,"",&previewI,CA_None,isSens,0,0,0,0,"preview.vbm"},
  127.     {C_IconButton,44,44,"",&pageI,CA_None,isSens,0,0,0,0,"page.vbm"},
  128.         {C_EndOfList,0,0,0,0,CA_None,0,0,0}
  129.       };
  130.  
  131.     static CommandObject CommandBar2[] =
  132.       {
  133.     {C_IconButton,33,33,"",&alphaI,CA_None,isSens,0,0,0},
  134.     {C_Frame,90,0,"",NoList,CA_NoSpace | CA_NoBorder,isSens,0,0,0},
  135.     {C_ToggleIconButton,10,0,"",&boldI,CA_None,isSens,90,0,0,0,"bold.vbm"},
  136.     {C_ToggleIconButton,18,0,"",&italicI,CA_None,isSens,90,10,0,0,"italic.vbm"},
  137.     {C_ToggleIconButton,30,0,"",&underlnI,CA_None,isSens,90,18,0,0,"underln.vbm"},
  138.     {C_IconButton,15,15,"",&drawI,CA_None,isSens,0,0,0,0,"draw.vbm"},
  139.     {C_IconButton,11,11,"",&brushI,CA_None,isSens,0,0,0,0,"brush.vbm"},
  140.     {C_IconButton,23,23,"",&pencilI,CA_None,isSens,0,0,0,0,"pencil.vbm"},
  141.     {C_IconButton,38,38,"",&drawlineI,CA_None,isSens,0,0,0,0,"drawline.vbm"},
  142.     {C_IconButton,39,39,"",&fillI,CA_None,isSens,0,0,0,0,"fill.vbm"},
  143.     {C_IconButton,19,19,"",&lineI,CA_None,isSens,0,0,0,0,"line.vbm"},
  144.     {C_IconButton,27,27,"",&rectI,CA_None,isSens,0,0,0,0,"rect.vbm"},
  145.     {C_IconButton,16,16,"",&ellipI,CA_None,isSens,0,0,0,0,"ellip.vbm"},
  146.     {C_IconButton,24,24,"",&polyI,CA_None,isSens,0,0,0,0,"poly.vbm"},
  147.         {C_EndOfList,0,0,0,0,CA_None,0,0,0}
  148.       };
  149.  
  150.     static CommandObject CommandBar3[] =
  151.       {
  152.     {C_IconButton,40,40,"",&findI,CA_None,isSens,0,0,0,0,"find.vbm"},
  153.     {C_IconButton,41,41,"",&findagnI,CA_None,isSens,0,0,0,0,"findagn.vbm"},
  154.     {C_IconButton,34,34,"",&backI,CA_None,isSens,0,0,0,0,"back.vbm"},
  155.     {C_IconButton,42,42,"",&forwardI,CA_None,isSens,0,0,0,0,"forward.vbm"},
  156.     {C_IconButton,46,46,"",&upI,CA_None,isSens,0,0,0,0,"up.vbm"},
  157.     {C_IconButton,37,37,"",&downI,CA_None,isSens,0,0,0,0,"down.vbm"},
  158.     {C_IconButton,43,43,"",&leftI,CA_None,isSens,0,0,0,0,"left.vbm"},
  159.     {C_IconButton,45,45,"",&rightI,CA_None,isSens,0,0,0,0,"right.vbm"},
  160.     {C_IconButton,36,36,"",&cursorI,CA_None,isSens,0,0,0,0,"cursor.vbm"},
  161.     {C_IconButton,35,35,"",&bookI,CA_None,isSens,0,0,0,0,"book.vbm"},
  162.     {C_IconButton,12,12,"",&checkI,CA_None,isSens,0,0,0,0,"check.vbm"},
  163.     {C_IconButton,32,32,"",&zoomI,CA_None,isSens,0,0,0,0,"zoom.vbm"},
  164.     {C_IconButton,17,17,"",&helpI,CA_None,isSens,0,0,0,0,"help.vbm"},
  165.         {C_EndOfList,0,0,0,0,CA_None,0,0,0}
  166.       };
  167.  
  168.     static vMenu StandardMenu[] =
  169.       {
  170.     {"&File", M_File, isSens, notUsed, notUsed, noKey, &ShortFile[0]},
  171.     {NULL}
  172.       };
  173.  
  174.  
  175. //====================>>> iconCmdWindow::iconCmdWindow <<<====================
  176.   iconCmdWindow::iconCmdWindow(char* name, int width, int height) :
  177.     vCmdWindow(name, width, height)
  178.   {
  179.  
  180.     // The "Standard" window will consist of a menubar, a canvas,
  181.     // an optional button bar, and an optional status bar.
  182.  
  183.     // First, create and add the proper panes to the CmdWindow
  184.     // Note: there must be a correspondint delete in the destructor
  185.  
  186.     // The Menu Bar
  187.     myMenu = new vMenuPane(StandardMenu);        // A short menu
  188.     AddPane(myMenu);                            // add pane to window
  189.  
  190.     // The command pane
  191.     myCmdPane = new vCommandPane(CommandBar);
  192.     AddPane(myCmdPane);
  193.  
  194.     // The command pane (2)
  195.     myCmdPane2 = new vCommandPane(CommandBar2);
  196.     AddPane(myCmdPane2);
  197.  
  198.     // The command pane (3)
  199.     myCmdPane3 = new vCommandPane(CommandBar3);
  200.     AddPane(myCmdPane3);
  201.  
  202.     // The Canvas
  203.     myCanvas = new vCanvasPane;              // a new canvas pane
  204.     AddPane(myCanvas);                          // add the pane to window
  205.  
  206.     ShowWindow();
  207.  
  208.   }
  209.  
  210. //====================>>> testCmdWindow::~testCmdWindow <<<====================
  211.   iconCmdWindow::~iconCmdWindow()
  212.   {
  213.     UserDebug(Destructor,"iconCmdWindow::~iconCmdWindow() destructor\n")
  214.  
  215.     delete myMenu;
  216.     delete myCanvas;
  217.     delete myCmdPane;
  218.     delete myCmdPane2;
  219.     delete myCmdPane3;
  220.   }
  221.  
  222. //====================>>> testCmdWindow::WindowCommand <<<====================
  223.   void iconCmdWindow::WindowCommand(ItemVal id, ItemVal val, CmdType cType)
  224.   {
  225.  
  226.     // route all commands through here - menus and buttons
  227.     char buff[20];
  228.  
  229.     switch (id)
  230.       {
  231.         case M_Exit:
  232.           {
  233.             theApp->Exit();
  234.             break;
  235.           }
  236.  
  237.       }
  238.   }
  239. //****************************************************************************
  240. //=========================>>> iconApp::NewAppWin <<<==========================
  241.   vWindow* iconApp::NewAppWin(vWindow* win, char* name, int w, int h, 
  242.                   vAppWinInfo* winInfo)
  243.   {
  244.     // This version of NewAppWin is provided with the information
  245.     // required to name and size a window.
  246.  
  247.     // Typically, these would get a file name or other information
  248.     // that will setup the AppWinInfo class for information
  249.     // specific to the application. Thus, each open window
  250.     // usually represents a view of a file or data object.
  251.  
  252.     vWindow* thisWin = win;        // local copy to use
  253.     vAppWinInfo* awinfo = winInfo;
  254.  
  255.     char *myname = name;
  256.  
  257.     if (!*name)
  258.       {
  259.     myname = "Icon Demo";        // make up a name
  260.       }
  261.     
  262.     UserDebug1(Build,"iconApp::NewAppWin(%s)\n",myname);
  263.  
  264.     if (!thisWin)            // need to new a window
  265.       {
  266.     thisWin = new iconCmdWindow(myname, w, h);
  267.       }
  268.  
  269.     // The real app will no doubt have its own AppWinInfo class.
  270.  
  271.     if (!awinfo)
  272.     awinfo = new vAppWinInfo(myname);
  273.  
  274.     return vApp::NewAppWin(thisWin, myname, w, h, awinfo);
  275.   }
  276.  
  277. //========================>>> iconApp::Exit <<<======================
  278.   void iconApp::Exit(void)
  279.   {
  280.     // This is called to close all windows. If the app needs to
  281.     // do something special, it can. Otherwise, it can call the
  282.     // general vApp::Exit method, which will generate
  283.     // appropriate calls the the specialized iconApp::CloseAppWin
  284.  
  285.     UserDebug(Build,"iconApp::Exit()\n");
  286.  
  287.     vApp::Exit();    // easy default behavior
  288.   }
  289.  
  290. //=======================>>> iconApp::CloseAppWin <<<===========================
  291.   int iconApp::CloseAppWin(vWindow* win)
  292.   {
  293.     // This will be called BEFORE a window has been unregistered or
  294.     // closed.  The app can do whatever it needs to to close down
  295.     // the data associated with this window. Then it can call the
  296.     // general vApp::CloseAppWin to unregister and close this window.
  297.     // Note that the win gives a handle that can be used with
  298.     // vApp::getAppWinInfo to retrieve the AppWinInfo class.
  299.  
  300.     // Code to handle close of window (such as saving/closing a file)
  301.     // would go here...
  302.  
  303.     // Now unregister and close the window.
  304.  
  305.     UserDebug(Build,"iconApp::CloseAppWin()\n");
  306.  
  307.     return vApp::CloseAppWin(win);
  308.   }
  309.  
  310. //========================>>> iconApp::AppCommand <<<==============================
  311.   void iconApp::AppCommand(vWindow* win, ItemVal id, ItemVal val, CmdType cType)
  312.   {
  313.     // Any commands not processed by the window will be passed
  314.     // along to here for default treatment.
  315.  
  316.     UserDebug1(Build,"iconApp::AppCmd(ID: %d)\n",id);
  317.     vApp::AppCommand(win, id, val, cType);
  318.   }
  319.  
  320. //=========================>>> iconApp::KeyIn <<<==============================
  321.   void iconApp::KeyIn(vWindow* win, vKey key, unsigned int shift)
  322.   {
  323.     // Any key strokes not processed by the window will be passed
  324.     // along to here for default treatment.
  325.  
  326.     vApp::KeyIn(win, key, shift);
  327.   }
  328.  
  329. //###########################################################################
  330.  
  331.   // EVERY V application needs the equivalent of the following line
  332.  
  333.   static iconApp icon_App("Icon Demo App");    // The instance of the app
  334.  
  335. //============================>>> AppMain <<<==============================
  336.   int AppMain(int argc, char** argv)
  337.   {
  338.     // Use AppMain to create the main window
  339.  
  340.     (void) theApp->NewAppWin(0, "Icon Demo", 450, 50);
  341.  
  342.     return 0;
  343.   }
  344.