home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c016 / 3.ddi / COMMEX.PAK / TERMCHLD.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-08  |  4.8 KB  |  187 lines

  1. //----------------------------------------------------------------------------
  2. // Borland Visual Solutions Pack
  3. // (C) Copyright 1993 by Borland International
  4. //----------------------------------------------------------------------------
  5. #include <owl\owlpch.h>
  6. #include <owl\applicat.h>
  7. #include <owl\opensave.h>
  8. #include "termchld.h"
  9. #include "settings.h"
  10. #include "termapp.rh"            // Definition of all resources.
  11. #include <stdio.h>
  12. #include <dir.h>
  13.  
  14. static char *Session = "Session";
  15.  
  16. //
  17. // Build a response table for all messages/commands handled
  18. // by SaxTermChild derived from TMDIClient.
  19. //
  20. DEFINE_RESPONSE_TABLE1(SaxTermChild, TVbxsaxComm)
  21.     EV_COMMAND(CM_FILESAVE, CmFileSave),
  22.     EV_COMMAND(CM_FILESAVEAS, CmFileSaveAs),
  23.     EV_COMMAND(CM_FILEDOWNLOAD, CmFileDownload),
  24.     EV_COMMAND(CM_FILEUPLOAD, CmFileUpload),
  25.     EV_COMMAND_ENABLE(CM_FILEDOWNLOAD, CmPortOpenEnable),
  26.     EV_COMMAND_ENABLE(CM_FILEUPLOAD, CmPortOpenEnable),
  27.     EV_COMMAND(CM_PHONEDISCONNECT, CmPhoneDisconnect),
  28.     EV_COMMAND_ENABLE(CM_PHONEDISCONNECT, CmPortOpenEnable),
  29.     EV_COMMAND(CM_PHONESETTINGS, CmPhoneSettings),
  30. END_RESPONSE_TABLE;
  31.  
  32.  
  33. //////////////////////////////////////////////////////////
  34. // SaxTermChild
  35. // ==========
  36. // Constuction/Destruction handling.
  37. SaxTermChild::SaxTermChild(TWindow* parent, const char far* title, TModule* module)
  38.     : TVbxsaxComm(parent, 100, title, 0, 0, 1, 1, 0, 0, module)
  39. {
  40.   Filename = title;
  41. }
  42.  
  43. SaxTermChild::~SaxTermChild()
  44. {
  45.   Destroy();
  46. }
  47.  
  48. void SaxTermChild::SetupWindow()
  49. {
  50.   string title;
  51.   if (!Filename.length()) {
  52.     char  t[128];
  53.     GetApplication()->LoadString(IDS_UNTITLED, t, sizeof t);
  54.     title = t;
  55.   } else
  56.     title = Filename;
  57.  
  58.   string newCaption;
  59.   if (Parent->Title && *Parent->Title) {
  60.     newCaption = Parent->Title;
  61.     newCaption += " - ";
  62.   }
  63.   newCaption += title;
  64.   Parent->SetWindowText(newCaption.c_str());
  65.  
  66.   LoadTextProp("Port");
  67.   LoadNumProp("Parity");
  68.   LoadNumProp("StopBits");
  69.   LoadNumProp("DataBits");
  70.   LoadNumProp("CtsRts");
  71.   LoadNumProp("XonXoff");
  72.   LoadNumProp("Speed");
  73. }
  74.  
  75. void SaxTermChild::CmPhoneSettings()
  76. {
  77.   SaxTermSettingsDlg(this).Execute();
  78. }
  79.  
  80. void SaxTermChild::CmFileUpload()
  81. {
  82.   static TOpenSaveDialog::TData  fileData;
  83.  
  84.   *fileData.FileName = 0;
  85.   fileData.Flags = OFN_HIDEREADONLY;
  86.   fileData.SetFilter("All Files (*.*)|*.*|");
  87.   fileData.DefExt = "";
  88.   if (TFileOpenDialog(this, fileData, 0, "File to upload").Execute() == IDOK)
  89.     SetProp("Upload", fileData.FileName);
  90. }
  91.  
  92. void SaxTermChild::CmFileDownload()
  93. {
  94.   static TOpenSaveDialog::TData  fileData;
  95.  
  96.   *fileData.FileName = 0;
  97.   fileData.Flags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
  98.   fileData.SetFilter("All Files (*.*)|*.*|");
  99.   fileData.DefExt = "";
  100.   if (TFileSaveDialog(this, fileData, 0, "File to download").Execute() == IDOK)
  101.     SetProp("Download", fileData.FileName);
  102. }
  103.  
  104. void SaxTermChild::CmPortOpenEnable(TCommandEnabler& ce)
  105. {
  106.   ce.Enable(IsPortOpen());
  107. }
  108.  
  109. BOOL SaxTermChild::IsPortOpen()
  110. {
  111.   string s;
  112.   GetProp("Port", s);
  113.   return s.length();
  114. }
  115.  
  116. void SaxTermChild::CmPhoneDisconnect()
  117. {
  118.   SetProp("Send", "+++");
  119.   // Switch modem to command mode
  120.   for (DWORD dwTicks = GetTickCount() ; dwTicks + 1000 > GetTickCount(); )
  121.     ;
  122.   SetProp("Send", "ATH\r"); // Hang up
  123. }
  124.  
  125. void SaxTermChild::SaveTextProp(char* name)
  126. {
  127.   string value;
  128.   GetProp(name, value);
  129.   WritePrivateProfileString(Session, name, value.c_str(), Filename.c_str());
  130. }
  131.  
  132. void SaxTermChild::SaveNumProp(char* name)
  133. {
  134.   long value;
  135.   GetProp(name, value);
  136.   value &= 0xFFFF;
  137.   char text[30];
  138.   wsprintf(text, "%ld", value);
  139.   WritePrivateProfileString(Session, name, text, Filename.c_str());
  140. }
  141.  
  142. void SaxTermChild::LoadTextProp(char* name)
  143. {
  144.   static char text[100];
  145.   GetPrivateProfileString(Session, name, "", text, sizeof text, Filename.c_str());
  146.   if (*text)
  147.     SetProp(name, text);
  148. }
  149.  
  150. void SaxTermChild::LoadNumProp(char* name)
  151. {
  152.    UINT value = GetPrivateProfileInt(Session, name, (UINT)0xFFFE, Filename.c_str());
  153.    if (value != 0xFFFE)
  154.       SetProp(name, (long)value);
  155. }
  156.  
  157. void SaxTermChild::CmFileSave()
  158. {
  159.   if (!Filename.length()) {
  160.     CmFileSaveAs();
  161.     return;
  162.   }
  163.   SaveTextProp("Port");
  164.   SaveNumProp("Parity");
  165.   SaveNumProp("StopBits");
  166.   SaveNumProp("DataBits");
  167.   SaveNumProp("CtsRts");
  168.   SaveNumProp("XonXoff");
  169.   SaveNumProp("Speed");
  170. }
  171.  
  172. void SaxTermChild::CmFileSaveAs()
  173. {
  174.   TOpenSaveDialog::TData  fileData;
  175.  
  176.   *fileData.FileName = 0;
  177.   fileData.Flags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
  178.   fileData.SetFilter("Comm Session Files (*.ses)|*.ses|All Files (*.*)|*.*|");
  179.   fileData.DefExt = "SES";
  180.   if (TFileSaveDialog(this, fileData).Execute() == IDOK) {
  181.     Filename = fileData.FileName;
  182.     SetCaption(fileData.FileName);
  183.     CmFileSave();
  184.   }
  185. }
  186.  
  187.