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

  1. //=======================================================================
  2. //  mydialog.cxx - Source file for myDialog class
  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 "mydialog.h"
  23. #include <v/vnotice.h>
  24.  
  25. //    The following would be automatically generated by Vigr.  There
  26. //    should be some regular algroithm for generating the #defines -
  27. //    e.g., 2 letters from class name (md), something from the Cmd type (CB),
  28. //    and a value to distinguish each label from aother.  The user should
  29. //    also be able to override the default generated name.  There can be
  30. //    some standard names such as xxBtnOK, etc.  The idea is to get some
  31. //    good compromise for uniqueness, ease of generation, and readability.
  32. //    Each module should have labels starting at the next 100, with the
  33. //    top level window starting with 100.
  34.  
  35. const ItemVal mdLbl1 = 200;
  36.  
  37. const ItemVal mdFrm1 = 201;
  38. const ItemVal mdLbl2 = 202;
  39. const ItemVal mdCB1 = 203;
  40. const ItemVal mdCB2 = 204;
  41. const ItemVal mdCB3 = 205;
  42. const ItemVal mdCB4 = 206;
  43.  
  44. const ItemVal mdFrmV1 = 207;
  45. const ItemVal mdLbl3 = 208;
  46. const ItemVal mdRB1 = 209;
  47. const ItemVal mdRB2 = 210;
  48. const ItemVal mdRB3 = 211;
  49.  
  50. const ItemVal mdFrmV2 = 212;
  51. const ItemVal mdLbl4 = 213;
  52. const ItemVal mdBtn1 = 214;
  53. const ItemVal mdBtn2 = 215;
  54. const ItemVal mdBtn3 = 216;
  55.  
  56. const ItemVal mdBtnTog = 217;
  57. const ItemVal mdBtnChange = 218;
  58.  
  59.     static char change_me[] = "Change Me A";    // a label to change
  60.  
  61. // This would also be automatically generated by Vigr. One of the functions
  62. // of Vigr is to allow the user to specify types and positions of Cmds in the
  63. // dialogs.
  64. //
  65.     static DialogCmd DefaultCmds[] =
  66.       {
  67.     {C_Label, mdLbl1, 0,"X",NoList,CA_MainMsg,isSens,NoFrame, 0, 0},
  68.  
  69.     // This demonstrates an alternate way to label a frame
  70.     {C_Frame, mdFrm1, 0, "", NoList, CA_None, isSens, NoFrame, 0, mdLbl1},
  71.     {C_Label, mdLbl2, 0, "CheckBox", NoList, CA_None, isSens, mdFrm1, 0, 0},
  72.     {C_CheckBox, mdCB1, 0, "Test A", NoList, CA_None, isSens, mdFrm1, 0, mdLbl2},
  73.     {C_CheckBox, mdCB2, 0, "Test B", NoList, CA_None, isSens, mdFrm1, mdCB1, mdLbl2},
  74.     {C_CheckBox, mdCB3, 1, "Test C", NoList, CA_None, isSens, mdFrm1, 0, mdCB1},
  75.     {C_CheckBox, mdCB4, 1, "Test D", NoList, CA_None, isSens, mdFrm1, 0, mdCB3},
  76.  
  77.     {C_Frame, mdFrmV1, 0, "", NoList,CA_None,isSens,NoFrame, mdFrm1, mdLbl1},
  78.     {C_Label, mdLbl3, 0, "Radios", NoList, CA_None, isSens, mdFrmV1, 0, 0},
  79.     {C_RadioButton, mdRB1, 1, "KOB", NoList,CA_None,isSens, mdFrmV1, 0, mdLbl3},
  80.     {C_RadioButton, mdRB2, 0, "KOAT", NoList, CA_None, isSens, mdFrmV1, 0, mdRB1},
  81.     {C_RadioButton, mdRB3, 0, "KRQE", NoList, CA_None, isSens, mdFrmV1, 0, mdRB2},
  82.  
  83.     {C_Frame, mdFrmV2, 0, "", NoList,CA_None,isSens,NoFrame, mdFrmV1, mdLbl1},
  84.     {C_Label, mdLbl4, 0, "Buttons", NoList, CA_None, isSens, mdFrmV2, 0, 0},
  85.     {C_Button, mdBtn1, mdBtn1, "Button 1", NoList, CA_None, isSens, mdFrmV2, 0, mdLbl4},
  86.     {C_Button, mdBtn2, mdBtn2, "Button 2", NoList, CA_None, isSens, mdFrmV2, 0, mdBtn1},
  87.     {C_Button, mdBtn3, mdBtn3, "Button 3", NoList, CA_None, isSens, mdFrmV2, 0, mdBtn2},
  88.  
  89.     {C_Button, mdBtnTog, 0, "Toggle Sensitive", NoList, CA_None,
  90.         isSens, NoFrame, 0, mdFrmV1},
  91.     {C_Button, mdBtnChange, 0, change_me, NoList, CA_None,
  92.         isSens, NoFrame, mdBtnTog, mdFrmV1},
  93.     {C_Button, M_Cancel, M_Cancel," Cancel ",NoList,CA_None,
  94.         isSens,NoFrame,mdBtnChange, mdFrmV1},
  95.     {C_Button, M_OK, M_OK, " OK ", NoList, CA_DefaultButton, 
  96.         isSens, NoFrame, M_Cancel, mdFrmV1},
  97.  
  98.     {C_EndOfList,0,0,0,0,CA_None,0,0,0}
  99.       };
  100.  
  101.  
  102. //=========================>>> myDialog::myDialog <<<====================
  103.   myDialog::myDialog(vBaseWindow* bw) :
  104.     vDialog(bw)
  105.   {
  106.     UserDebug(Constructor,"myDialog::myDialog()\n")
  107.  
  108.     _toggleId = mdFrm1;        // Start with first item
  109.  
  110.     AddDialogCmds(DefaultCmds);        // add the predefined commands
  111.   }
  112.  
  113. //========================>>> myDialog::~myDialog <<<====================
  114.   myDialog::~myDialog()
  115.   {
  116.     UserDebug(Destructor,"myDialog::~myDialog() destructor\n")
  117.   }
  118.  
  119. //====================>>> myDialog::DialogCommand <<<=======================
  120.   void myDialog::DialogCommand(ItemVal id, ItemVal retval, CmdType ctype)
  121.   {
  122.     // After the user has selected a command from the dialog,
  123.     // this routine is called with the value.  This code would be generated
  124.     // by Vigr.
  125.  
  126.     vNoticeDialog note(this);
  127.  
  128.     UserDebug2(CmdEvents,"myDialog::DialogCommand(id:%d, val:%d)\n",id, retval)
  129.  
  130.     switch (id)        // We will do some things depending on value
  131.       {
  132.     case mdCB1:        // CheckBox
  133.       {
  134.         note.Notice("Test A");
  135.         break;
  136.       }
  137.  
  138.     case mdCB2:        // CheckBox
  139.       {
  140.         note.Notice("Test B");
  141.         break;
  142.       }
  143.  
  144.     case mdCB3:        // CheckBox
  145.       {
  146.         note.Notice("Test C");
  147.         break;
  148.       }
  149.  
  150.     case mdRB1:        // Radio Button
  151.       {
  152.         note.Notice("KOB");
  153.         break;
  154.       }
  155.  
  156.     case mdRB2:        // Radio Button
  157.       {
  158.         note.Notice("KOAT");
  159.         break;
  160.       }
  161.  
  162.     case mdRB3:        // Radio Button
  163.       {
  164.         note.Notice("KRQE");
  165.         break;
  166.       }
  167.  
  168.     case mdBtn1:        // Button
  169.       {
  170.         note.Notice("Button 1");
  171.         break;
  172.       }
  173.  
  174.     case mdBtn2:        // Button
  175.       {
  176.         note.Notice("Button 2");
  177.         break;
  178.       }
  179.  
  180.     case mdBtn3:        // Button
  181.       {
  182.         note.Notice("Button 3");
  183.         break;
  184.       }
  185.  
  186.     case mdBtnTog:        // Toggle sensitive of some objects
  187.       {
  188. //        note.Notice("Toggle Button");
  189.  
  190.         // We will toggle the sensitive of each item in the dialog
  191.         SetValue(_toggleId, 1, Sensitive);
  192.  
  193.         // First, set the current item to 0
  194.  
  195.         // up the counter for the next item
  196.         if (++_toggleId > mdBtn3)
  197.         _toggleId  = mdFrm1;        // reStart with first item
  198.  
  199.         // Now, set the new current item insensitive
  200.         SetValue(_toggleId, 0, Sensitive);
  201.  
  202.         break;
  203.       }
  204.  
  205.     case mdBtnChange:        // Change my own label
  206.       {
  207. //        note.Notice("Change Me A");
  208.  
  209.         // We will change the label on this button
  210.         change_me[10]++;        // change the "A"
  211.         SetString(mdBtnChange, change_me);
  212.         break;
  213.       }
  214.  
  215.       }
  216.     // All commands should also route through the parent handler
  217.     vDialog::DialogCommand(id,retval,ctype);
  218.   }
  219.