//=======================================================================
//@V@:Note: This file generated by vappgen V 1.00.
//	vgdlmdlg.cpp:	Source for vgdlgModalDialog class
//=======================================================================

#include "vgdlmdlg.h"
#include <v/vnotice.h>
#include <v/vfilesel.h>

//@V@:BeginIDs
    enum {
    lblMainMsg = 1000,

    frmNames,
    lblAppName,			// App name
    txiAppName,
    lblFileName,		// file base name
    txiFileName,
    lblTitle,			// app title
    txiTitle,

    frmOther,			// frame for other options
    lblOther,
    blkOther,
    rdbModeless,		// Modeless
    rdbModal,			// Text Canvas

    btnSetPath,

    blkLast
  };
//@V@:EndIds

//@V@:BeginDialogCmd DefaultCmds
    static DialogCmd DefaultCmds[] =
      {
	{C_Label, lblMainMsg, 0,"X",NoList,CA_MainMsg,isSens,NoFrame, 0, 0},

	{C_Frame, frmNames, 0, "",NoList,CA_NoBorder,isSens,NoFrame, 0,lblMainMsg},
	{C_Label, lblAppName, 0,"Dialog Class Base Name:",
	    NoList, CA_None, isSens,frmNames,0, 0, 0,
	    "Specify base part of dialog class name"},
	{C_TextIn, txiAppName, 0,"x",
	    NoList, CA_None, isSens,frmNames,lblAppName, 0,0,
	    "Specify base part of dialog class name"},
	{C_Label, lblFileName, 0," Dialog File Base Name:",
	    NoList, CA_None, isSens,frmNames,0, txiAppName,0,
		"Specify base part of generated file names"},
	{C_TextIn, txiFileName, 0,"x",
	    NoList, CA_None, isSens,frmNames,lblFileName, txiAppName, 0,
		"Specify base part of generated file names"},
	{C_Label, lblTitle, 0,  "          Dialog Title:",
	    NoList, CA_None, isSens,frmNames,0, txiFileName,0,
		"Specify title for dialog box"},
	{C_TextIn, txiTitle, 0,"x",
	    NoList, CA_None, isSens,frmNames,lblTitle, txiFileName,0,
		"Specify title for dialog box"},


	{C_Frame, frmOther, 0, "",NoList,CA_NoBorder,isSens,NoFrame, 0,frmNames},
	{C_Label, lblOther, 0, "Dialog type",
	    NoList, CA_None, isSens,frmOther,0, 0},
	{C_Blank, blkOther, 0, " ",
	    NoList, CA_None, isSens,frmOther,0, lblOther},
	{C_RadioButton, rdbModeless, 1, "Modeless ",
	    NoList, CA_None, isSens,frmOther,blkOther,lblOther,0,
		"Generate a modeless dialog"},
	{C_RadioButton, rdbModal, 0, "Modal ",
	    NoList, CA_None, isSens,frmOther,rdbModeless, lblOther,0,
		"Generate a Modal dialog"},

	{C_Button, btnSetPath, 0, " Set Save Path ",NoList,CA_None,
	    isSens,NoFrame,0, frmOther,0,
		"Specify path to save generated code"},
	{C_Blank, blkLast, 0, "           ",
	    NoList,CA_None, isSens,NoFrame,btnSetPath, frmOther},
	{C_Button, M_Cancel, 0, " Cancel ",NoList,CA_None,
	    isSens,NoFrame,blkLast, frmOther},
	{C_Button, M_OK, 0, " Generate ", NoList, CA_DefaultButton, 
	    isSens, NoFrame, M_Cancel, frmOther,0,
		"Generate code for dialog"},

	{C_EndOfList,0,0,0,0,CA_None,0,0,0}
    };
//@V@:EndDialogCmd

  extern void SetCmdObjTitle(CommandObject* cList, ItemVal id, char* newtitle);

//======================>>> vgdlgModalDialog::vgdlgModalDialog <<<==================
  vgdlgModalDialog::vgdlgModalDialog(vBaseWindow* bw, char* title) :
    vModalDialog(bw,title)
  {
    UserDebug(Constructor,"vgdlgModalDialog::vgdlgModalDialog()\n")
  }

//===================>>> vgdlgModalDialog::~vgdlgModalDialog <<<====================
  vgdlgModalDialog::~vgdlgModalDialog()
  {
    UserDebug(Destructor,"vgdlgModalDialog::~vgdlgModalDialog() destructor\n")
  }

//====================>>> vgdlgModalDialog::vgdlgAction <<<====================
  int vgdlgModalDialog::vgdlgAction(char* msg, vgOptions& op)
  {
    ItemVal ans,rval;

    SetCmdObjTitle(DefaultCmds,txiAppName,op.appName);
    SetCmdObjTitle(DefaultCmds,txiFileName,op.fileName);
    SetCmdObjTitle(DefaultCmds,txiTitle,op.title);

    AddDialogCmds(DefaultCmds);		// add the predefined commands

    ans = ShowModalDialog(msg,rval);
    if (ans == M_Cancel)
	return 0;

    (void) GetTextIn(txiAppName,op.appName,99);
    (void) GetTextIn(txiFileName,op.fileName,99);
    (void) GetTextIn(txiTitle,op.title,99);

    op.addDialog = GetValue(rdbModeless);
    op.addModal = GetValue(rdbModal);

    return ans == M_OK;
  }

//====================>>> vgdlgModalDialog::DialogCommand <<<====================
  void vgdlgModalDialog::DialogCommand(ItemVal id, ItemVal retval, CmdType ctype)
  {
    UserDebug2(CmdEvents,"vgdlgModalDialog::DialogCommand(id:%d, val:%d)\n",id, retval)

    switch (id)		// We will do some things depending on value
      {
	case btnSetPath:		// set path to save in
	  {
	    char path[100];
	    int tmp = 0;
	    (void) GetTextIn(txiFileName,path,99);
	    strcat(path,"app.cpp");	// use xxapp.cpp as default name
	    vFileSelect fsel(this);

	    int oans = fsel.FileSelectSave("Generate code to directory",
		path,99,NULL,tmp);
	    break;
	  }

      }

    vModalDialog::DialogCommand(id,retval,ctype);
  }
