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

  1. //=======================================================================
  2. // vttogdlg.cxx - Source file for toggleDialog class
  3. //  Copyright (C) 1995,1996  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 "vttogdlg.h"
  23. #include <v/v_defs.h>
  24. #include <v/vapp.h>
  25. #include <v/vnotice.h>
  26.  
  27.     static CommandObject DefaultCmds[] =
  28.       {
  29.     // A label, then 3 toggle buttons to select toggle frames
  30.     {C_Label,490,0,"Tab Frame Demo",NoList,CA_None,isSens,NoFrame,0,0},
  31.  
  32.     // This borderless frame makes the toggle buttons tightly spaced
  33.     {C_Frame,400,0,"",NoList,CA_NoSpace | CA_NoBorder,isSens,NoFrame,0,490},
  34.     {C_ToggleButton,401,1,"Tab 1",NoList, CA_None, isSens, 400, 0, 0},
  35.     {C_ToggleButton,402,0,"Tab 2",NoList, CA_None, isSens, 400, 401, 0},
  36.     {C_ToggleButton,403,0,"Tab 3",NoList, CA_None, isSens, 400, 402, 0},
  37.  
  38.     // A Master frame to give uniform border to toggle frames
  39.     {C_Frame,409,0, "", NoList,CA_None,isSens,400,0,401},
  40.  
  41.     // Toggle Frame 1 - default off
  42.     {C_ToggleFrame, 410,1,"",NoList, CA_NoBorder,isSens,409,0,0},
  43.     {C_Button, 411, 0, "Button A   ",NoList, CA_None, isSens, 410,0,0},
  44.     {C_Button, 412, 0, "Button B(1)",NoList, CA_None, isSens, 410,0,411},
  45.  
  46.     // Toggle Frame 2 - default on
  47.     {C_ToggleFrame, 420,0,"",NoList, CA_NoBorder | CA_Hidden,isSens,409,0,0},
  48.     {C_Button, 421, 0, "Button A(2)",NoList, CA_Hidden, isSens, 420,0,0},
  49.     {C_Button, 422, 0, "Button B(2)",NoList, CA_Hidden, isSens, 420,421,0},
  50.  
  51.     // Toggle Frame 3 - default off
  52.     {C_ToggleFrame, 430,0,"",NoList, CA_NoBorder | CA_Hidden,isSens,409,0,0},
  53.     {C_Button, 431, 0, "Button A(3)",NoList, CA_Hidden, isSens, 430,0,0},
  54.     {C_Button, 432, 0, "Button B(3)",NoList, CA_Hidden, isSens, 430,431,431},
  55.  
  56.         {C_Button, 500, 500," ModalModal Test ",NoList,CA_None,isSens,NoFrame,0,400},
  57.         {C_Button, M_Cancel, M_Cancel," Cancel ",NoList,CA_None,isSens,NoFrame,0,500},
  58.         {C_Button, M_OK, M_OK, " OK ", NoList, CA_DefaultButton,
  59.                 isSens, NoFrame, M_Cancel, 500},
  60.  
  61.         {C_EndOfList,0,0,0,0,CA_None,0,0,0}
  62.       };
  63.  
  64.  
  65. //-------------------- list dialog
  66.     char* comboList[] =
  67.       {
  68.         "Bruce",
  69.         "Katrina",
  70.         "Risa",
  71.         "Van",
  72.         "Chaco and Sushi",
  73.         0
  74.       };
  75.  
  76.     char* testList[] =
  77.       {
  78.         "First 0", "Item 1", "Item 2", "Item 3", "Item 4", "Item 5",
  79.         "Item 6",  "Item 7", "Item 8", "Item 9", "Item 10", "Item 11",
  80.         "Item 12", "Item 13", "Item 14", "Item 15", "Item 16",
  81.         "Item 17", "Item 18", "Item 19", "Item 20", "Item 21",
  82.         "Item 22", "Item 23", "Item 24", "Item 25", "Item 26",
  83.         "Item 27", "Item 28", "Item 29", "Item 30", "Item 31",
  84.         "Item 32", "Item 33", "Item 34", "Item 35", "Item 36",
  85.         "Item 37", "Item 38", "Item 39", "Item 40", "Item 41 (last)",
  86.         0
  87.       };
  88.  
  89.     char* testList2[] =
  90.       {
  91.         "First A",
  92.         "Item B",
  93.         "Item C",
  94.         "Item D",
  95.         "Item E",
  96.         "Item F",
  97.         "Item G",
  98.         0
  99.       };
  100.  
  101.     char* wideList[] =
  102.       {
  103.     "This Tests",
  104.     "CA_ListWidth",
  105.     "A", "B", "C", "D", "E", "F", "G", 0
  106.       };
  107.  
  108.     static char* valList[] = {"Value A", "Value B", "A Long Value", "Last Value", 0};
  109.  
  110.     static int minMaxStep[3] = {-10, 110, 2};
  111.  
  112.     CommandObject ListList[] =
  113.       {
  114.         {C_Label, 210, 210, "List Test",
  115.                  NoList, CA_MainMsg, isSens, 0,0},
  116.  
  117. //V:1.14    {C_TextEdit,222,0,"Initial data.",NoList,
  118. //V:1.14                 CA_None,isSens,NoFrame,0,210},
  119.  
  120.         {C_List, 200, 0, "A List", (void*)testList,
  121.                  CA_Size,isSens,NoFrame,0,210,32},
  122.         {C_ComboBox,201,2,"ComboBox",(void*)comboList,
  123.                  CA_Simple,isSens,NoFrame,200,210},
  124.  
  125.         {C_Spinner, 50,0,"Spinner", (void*)valList,CA_Text,isSens,NoFrame,
  126.         200,201},
  127.  
  128.         {C_Spinner, 51,32, "Spinner", NoList,CA_None,isSens,NoFrame, 200,50},
  129.         {C_Spinner, 52,-2, "Spinner", (void*)minMaxStep,CA_None,isSens,NoFrame, 
  130.         51,50},
  131.  
  132.         {C_List, 220, 80, "Wide List", (void*)wideList,
  133.                  CA_Size|CA_ListWidth,isSens,NoFrame,200,52,4,"List Test"},
  134.  
  135.         {C_Button, M_OK, M_OK, " OK ", NoList,
  136.                 CA_DefaultButton, isSens, NoFrame, 0, 200},
  137.     {C_Button, 53,0,"Change Combo",NoList,CA_None,isSens,NoFrame,M_OK,200},
  138.     {C_Button, 54,0,"Change List",NoList,CA_None,isSens,NoFrame,53,200},
  139.         {C_EndOfList,0,0,0,0,CA_None,0,0,0}
  140.       };
  141.  
  142. static int whichList = 0;
  143.  
  144. //=========================>>> toggleDialog::toggleDialog <<<====================
  145.   toggleDialog::toggleDialog(vBaseWindow* bw) :
  146.     vModalDialog(bw,"V Toggle Dialog")
  147.   {
  148.     UserDebug(Constructor,"toggleDialog::toggleDialog()\n")
  149.  
  150.     AddDialogCmds(DefaultCmds);         // add the predefined commands
  151.   }
  152.  
  153. //========================>>> toggleDialog::~toggleDialog <<<====================
  154.   toggleDialog::~toggleDialog()
  155.   {
  156.     UserDebug(Destructor,"toggleDialog::~toggleDialog() destructor\n")
  157.   }
  158.  
  159. //========================>>> toggleDialog::ShowModalDialog <<<====================
  160.  ItemVal toggleDialog::ShowModalDialog(VCONST char* msg, ItemVal& rv)
  161.  {
  162.   
  163.    return vModalDialog::ShowModalDialog(msg,rv);
  164.  }
  165.  
  166. //====================>>> toggleDialog::DialogCommand <<<=======================
  167.   void toggleDialog::DialogDisplayed()
  168.   {
  169.     SetString(411,"Button A(1)");
  170.   }
  171.  
  172. //====================>>> toggleDialog::DialogCommand <<<=======================
  173.   void toggleDialog::DialogCommand(ItemVal id, ItemVal retval, CmdType ctype)
  174.   {
  175.     // After the user has selected a command from the dialog,
  176.     // this routine is called with the value.  This code would be generated
  177.     // by Vigr.
  178.  
  179.     ItemVal curval;
  180.  
  181.     UserDebug2(CmdEvents,"toggleDialog::DialogCommand(id:%d, val:%d)\n",id, retval)
  182.  
  183.     switch (id)         // We will do some things depending on value
  184.       {
  185.     case 4:
  186.       {
  187.         SetString(2,"This is new");
  188.         break;
  189.       }
  190.  
  191.     case 401:    // Always assume toggle to ON
  192.       {
  193.         SetValue(id,1,Value);    // turn on toggle button
  194.         SetValue(402,0,Value);
  195.         SetValue(403,0,Value);    // others off
  196.  
  197.         SetValue(420,0,Value);    // Toggle others off
  198.         SetValue(430,0,Value);    // Toggle others off
  199.         SetValue(410,1,Value);    // and ours on
  200.         break;
  201.       }
  202.  
  203.     case 402:    // Toggle 2
  204.       {
  205.         SetValue(id,1,Value);    // turn on toggle button
  206.         SetValue(401,0,Value);
  207.         SetValue(403,0,Value);    // others off
  208.  
  209.         SetValue(410,0,Value);    // Toggle others off
  210.         SetValue(430,0,Value);    // Toggle others off
  211.         SetValue(420,1,Value);    // and ours on
  212.         break;
  213.       }
  214.  
  215.     case 403:    // toggle 3
  216.       {
  217.         SetValue(id,1,Value);    // turn on toggle button
  218.         SetValue(402,0,Value);
  219.         SetValue(401,0,Value);    // others off
  220.  
  221.         SetValue(420,0,Value);    // Toggle others off
  222.         SetValue(410,0,Value);    // Toggle others off
  223.         SetValue(430,1,Value);    // and ours on
  224.         break;
  225.       }
  226.  
  227.         case 411: case 412: case 421: case 422: case 431: case 432:
  228.           {
  229.             vNoticeDialog note(this);
  230.             note.Notice("Button pressed.");
  231.             break;
  232.           }
  233.  
  234.     case 500:    // modal modal test
  235.       {
  236.         vNoticeDialog note(this);
  237.         note.Notice("This is a modal from a modal");
  238.         break;
  239.       }
  240.  
  241.       }
  242.     // All commands should also route through the parent handler
  243.     vDialog::DialogCommand(id,retval,ctype);
  244.   }
  245.  
  246. //=========================>>> listDialog::listDialog <<<====================
  247.   listDialog::listDialog(vBaseWindow* bw) :
  248.     vDialog(bw,0,"V List Dialog")
  249.   {
  250.     UserDebug(Constructor,"listDialog::listDialog()\n")
  251.  
  252.     AddDialogCmds(ListList);         // add the predefined commands
  253.   }
  254.  
  255. //========================>>> listDialog::~listDialog <<<====================
  256.   listDialog::~listDialog()
  257.   {
  258.     UserDebug(Destructor,"listDialog::~listDialog() destructor\n")
  259.   }
  260.  
  261. //====================>>> listDialog::DialogCommand <<<=======================
  262.   void listDialog::DialogCommand(ItemVal id, ItemVal retval, CmdType ctype)
  263.   {
  264.     // After the user has selected a command from the dialog,
  265.     // this routine is called with the value.  This code would be generated
  266.     // by Vigr.
  267.  
  268.     ItemVal curval;
  269.  
  270.     UserDebug2(CmdEvents,"listDialog::DialogCommand(id:%d, val:%d)\n",id, retval)
  271.  
  272.     switch (id)         // We will do some things depending on value
  273.       {
  274.     case 53:
  275.       {
  276.         if (*comboList[0] == 'b')
  277.         comboList[0] = "Bruce";
  278.         else
  279.         comboList[0] = "bruce";
  280.         SetValue(201,0,ChangeList);
  281.  
  282.         break;
  283.       }
  284.  
  285.     case 54:
  286.       {
  287.         if (whichList == 0)
  288.           {
  289.         whichList = 1;
  290.         ListList[1].itemList = (void*)testList2;
  291.           }
  292.         else
  293.           {
  294.         whichList = 0;
  295.         ListList[1].itemList = (void*)testList;
  296.           }
  297.         SetValue(200,3,ChangeListPtr);    // change the whole list!
  298.         break;
  299.       }
  300.  
  301.       }
  302.     // All commands should also route through the parent handler
  303.     vDialog::DialogCommand(id,retval,ctype);
  304.   }
  305.