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

  1. //========================================================================
  2. //  tdialog.cpp - Source file for tutorial tDialog class
  3. //
  4. //  Copyright 1995,1996 Bruce E. Wampler, All Rights Reserved
  5. //========================================================================
  6.  
  7. // #include the headers we need
  8. #include <v/vnotice.h>
  9. #include "tdialog.h"
  10.  
  11. // The structure of a derived dialog class is very similar to the
  12. // structure of a command window class. First we define IDs for the
  13. // various command objects used in the dialog. Then we declare the
  14. // static array that defines the dialog.
  15.  
  16. const ItemVal mdLbl1 = 200;
  17.  
  18. const ItemVal mdFrm1 = 201;  const ItemVal mdLbl2 = 202;
  19. const ItemVal mdCB1 = 203;   const ItemVal mdCB2 = 204;
  20. const ItemVal mdCB3 = 205;
  21.  
  22. const ItemVal mdFrmV1 = 206; const ItemVal mdLbl3 = 207;
  23. const ItemVal mdRB1 = 208;   const ItemVal mdRB2 = 209;
  24.  
  25. const ItemVal mdFrmV2 = 210; const ItemVal mdLbl4 = 211;
  26. const ItemVal mdBtn1 = 212;  const ItemVal mdBtn2 = 213;
  27.  
  28. const ItemVal mdBtnChange = 214;
  29.  
  30.     static char change_me[] = "Change Me A";    // a label to change
  31.  
  32. // This defines the dialog
  33.  
  34.     static CommandObject DefaultCmds[] =
  35.       {
  36.         {C_Label, mdLbl1, 0,"X",NoList,CA_MainMsg,isSens,NoFrame, 0, 0},
  37.  
  38.         {C_Frame,mdFrmV2,0,"",NoList,CA_None,isSens,NoFrame,0,mdLbl1},
  39.         {C_Label,mdLbl4,0,"Buttons",NoList,CA_None,isSens,mdFrmV2,0,0},
  40.         {C_Button,mdBtn1,mdBtn1,"Button 1",NoList,CA_None,
  41.                 isSens,mdFrmV2,0,mdLbl4},
  42.         {C_Button,mdBtn2,mdBtn2,"Button 2",NoList,CA_None,
  43.                 isSens,mdFrmV2,0,mdBtn1},
  44.  
  45.         {C_Frame,mdFrm1,0,"",NoList,CA_None,isSens,NoFrame,mdFrmV2,mdLbl1},
  46.         {C_Label,mdLbl2,0,"CheckBox",NoList,CA_None,isSens,mdFrm1,0,0},
  47.         {C_CheckBox,mdCB1,0,"Test A",NoList,CA_None,
  48.                 isSens,mdFrm1,0,mdLbl2},
  49.         {C_CheckBox,mdCB2,0,"Test B",NoList,CA_None,
  50.                 isSens,mdFrm1,mdCB1,mdLbl2},
  51.         {C_CheckBox,mdCB3,1,"Test C",NoList,CA_None,isSens,mdFrm1,0,mdCB1},
  52.  
  53.         {C_Frame,mdFrmV1,0,"",NoList,CA_None,isSens,NoFrame,mdFrm1,mdLbl1},
  54.         {C_Label,mdLbl3,0,"Radios",NoList,CA_None,isSens,mdFrmV1,0,0},
  55.         {C_RadioButton,mdRB1,1,"KOB",NoList,CA_None,
  56.                 isSens,mdFrmV1,0,mdLbl3},
  57.         {C_RadioButton,mdRB2,0,"KOAT",NoList,CA_None,
  58.                 isSens,mdFrmV1,0,mdRB1},
  59.  
  60.         {C_Button,mdBtnChange,0,change_me,NoList,CA_None,
  61.                 isSens,NoFrame,0,mdFrmV1},
  62.         {C_Button,M_Cancel,M_Cancel," Cancel ",NoList,CA_None,
  63.             isSens,NoFrame,mdBtnChange,mdFrmV1},
  64.         {C_Button,M_OK,M_OK," OK ",NoList,CA_DefaultButton,
  65.             isSens,NoFrame,M_Cancel,mdFrmV1},
  66.  
  67.         {C_EndOfList,0,0,0,0,CA_None,0,0,0}
  68.       };
  69.  
  70.  
  71. //==========================>>> tDialog::tDialog <<<======================
  72.   tDialog::tDialog(vBaseWindow* bw) :
  73.     vDialog(bw)
  74.   {
  75.     // The constructor for a derived dialog calls the superclass
  76.     // constructor, and then adds the command objects to the dialog
  77.     // by calling AddDialogCmds.
  78.  
  79.     UserDebug(Constructor,"tDialog::tDialog()\n")
  80.     AddDialogCmds(DefaultCmds);         // add the command objects
  81.   }
  82.  
  83. //=========================>>> tDialog::~tDialog <<<======================
  84.   tDialog::~tDialog()
  85.   {
  86.     // Destructor often doesn't need to do anything
  87.  
  88.     UserDebug(Destructor,"tDialog::~tDialog() destructor\n")
  89.   }
  90.  
  91. //====================>>> tDialog::DialogCommand <<<======================
  92.   void tDialog::DialogCommand(ItemVal id, ItemVal retval, CmdType ctype)
  93.   {
  94.     // After the user has selected a command from the dialog,
  95.     // this routine is called with the value.
  96.  
  97.     vNoticeDialog note(this);   // an instance we can use
  98.  
  99.     UserDebug1(CmdEvents,"tDialog::DialogCommand(id:%d)\n",id)
  100.  
  101.     switch (id)         // We will do some things depending on value
  102.       {
  103.         case mdCB1:             // CheckBox
  104.             note.Notice("Test A");
  105.             break;
  106.  
  107.         case mdCB2:             // CheckBox
  108.             note.Notice("Test B");
  109.             break;
  110.  
  111.         case mdCB3:             // CheckBox
  112.             note.Notice("Test C");
  113.             break;
  114.  
  115.         case mdRB1:             // Radio Button
  116.             note.Notice("KOB");
  117.             break;
  118.  
  119.         case mdRB2:             // Radio Button
  120.             note.Notice("KOAT");
  121.             break;
  122.  
  123.         case mdBtn1:            // Button
  124.             note.Notice("Button 1");
  125.             break;
  126.  
  127.         case mdBtn2:            // Button
  128.             note.Notice("Button 2");
  129.             break;
  130.  
  131.         case mdBtnChange:       // Example: change my own label
  132.             // We will change the label on this button
  133.             change_me[10]++;            // change the "A"
  134.             SetString(mdBtnChange, change_me);
  135.             break;
  136.       }
  137.     // All commands should also route through the parent handler
  138.     // which has useful default behaviors for Cancel and OK
  139.     vDialog::DialogCommand(id,retval,ctype);
  140.   }
  141.