home *** CD-ROM | disk | FTP | other *** search
/ Mac Expert 1995 Winter / Mac Expert - Winter 95.iso / Les fichiers / Communications / Internet / TurboTCP 2.1 ƒ / PP MiniTelnet source / CMiniTelnetApp.cp next >
Encoding:
Text File  |  1995-01-19  |  8.3 KB  |  348 lines  |  [TEXT/MMCC]

  1. //
  2. // CMiniTelnetApp.cp
  3. //
  4. //    MiniTelnet application
  5. //    Application subclass
  6. //    PowerPlant version
  7. //
  8. //    Copyright © 1993-95, FrostByte Design / Eric Scouten
  9. //
  10.  
  11. #include "CMiniTelnetApp.h"
  12.  
  13. #include "CTelnetTerminal.h"
  14. #include "CTelnetSettingsDialog.h"
  15. #include "CTerminalPane.h"
  16.  
  17. #include <LCaption.h>
  18. #include <LDialogBox.h>
  19. #include <LEditField.h>
  20. #include <LGrowZone.h>
  21. #include <LListBox.h>
  22. #include <LPicture.h>
  23. #include <LScroller.h>
  24. #include <LStdControl.h>
  25. #include <LWindow.h>
  26.  
  27. #include <UDesktop.h>
  28. #include <UDrawingState.h>
  29. #include <UExtractFromAEDesc.h>
  30. #include <UMemoryMgr.h>
  31. #include <UPowerTools.h>
  32. #include <URegistrar.h>
  33.  
  34. #include <PP_Messages.h>
  35.  
  36.  
  37. //***********************************************************
  38.  
  39. void main()
  40.  
  41.     // The big one. Set up the OOP stuff and let it go.
  42.  
  43. {
  44.  
  45.     // set debugging options
  46.  
  47.     #ifdef Debug_Throw
  48.         gDebugThrow = debugAction_Alert;
  49.     #endif
  50.     #ifdef Debug_Signal
  51.         gDebugSignal = debugAction_Alert;
  52.     #endif
  53.  
  54.  
  55.     // initialize Toolbox
  56.  
  57.     InitializeHeap(3);                    // parameter is number of master pointer blocks to allocate
  58.     UQDGlobals::InitializeToolbox(&qd);
  59.  
  60.     
  61.     // check for missing MBAR (probably means most resources are missing)
  62.     
  63.     #ifdef Debug_Signal
  64.         CheckForInitialMBAR();
  65.     #endif
  66.     
  67.  
  68.     // install handler for low-memory situations
  69.     
  70.     new LGrowZone(20000);                // parameter is size of reserve memory block to allocated
  71.  
  72.  
  73.     // create the application & run it
  74.     
  75.     CMiniTelnetApp theApp;
  76.     theApp.Run();
  77.  
  78. }
  79.  
  80.  
  81. //***********************************************************
  82.  
  83. CMiniTelnetApp::CMiniTelnetApp()
  84.  
  85. : LDocApplication(),
  86.   CTCPApplicationPP(this)
  87. {
  88.  
  89.     // register classes which will be created from 'PPob' resources
  90.  
  91.     URegistrar::RegisterClass(LCaption::class_ID, (ClassCreatorFunc) LCaption::CreateCaptionStream);
  92.     URegistrar::RegisterClass(LDialogBox::class_ID, (ClassCreatorFunc) LDialogBox::CreateDialogBoxStream);
  93.     URegistrar::RegisterClass(LEditField::class_ID, (ClassCreatorFunc) LEditField::CreateEditFieldStream);
  94.     URegistrar::RegisterClass(LScroller::class_ID, (ClassCreatorFunc) LScroller::CreateScrollerStream);
  95.     URegistrar::RegisterClass(LStdButton::class_ID, (ClassCreatorFunc) LStdButton::CreateStdButtonStream);
  96.     URegistrar::RegisterClass(LStdCheckBox::class_ID, (ClassCreatorFunc) LStdCheckBox::CreateStdCheckBoxStream);
  97.     URegistrar::RegisterClass(LStdPopupMenu::class_ID, (ClassCreatorFunc) LStdPopupMenu::CreateStdPopupMenuStream);
  98.     URegistrar::RegisterClass(LStdRadioButton::class_ID, (ClassCreatorFunc) LStdRadioButton::CreateStdRadioButtonStream);
  99.     URegistrar::RegisterClass(LView::class_ID, (ClassCreatorFunc) LView::CreateViewStream);
  100.     URegistrar::RegisterClass(LWindow::class_ID, (ClassCreatorFunc) LWindow::CreateWindowStream);
  101.  
  102.     URegistrar::RegisterClass(CTelnetSettingsDialog::class_ID, (ClassCreatorFunc) CTelnetSettingsDialog::CreateDialogBoxStream);
  103.     URegistrar::RegisterClass(CTerminalPane::class_ID, (ClassCreatorFunc) CTerminalPane::CreateTerminalPaneStream);
  104.  
  105. }
  106.  
  107.  
  108. //***********************************************************
  109. //
  110. // creation of Telnet sessions (documents)
  111. //
  112.  
  113. //***********************************************************
  114.  
  115. LModelObject* CMiniTelnetApp::MakeNewDocument()
  116.  
  117.     // What happens to File->New Session from the menu. Creates a settings dialog rather
  118.     // than a session document. The dialog will open a session if the user so desires.
  119.  
  120. {
  121.     CTelnetSettingsDialog* theDialog =
  122.         (CTelnetSettingsDialog*) LWindow::CreateWindow(PPobTelnetSettings, this);
  123.     if (theDialog)
  124.         theDialog->AddListener(this);
  125.     return nil;
  126. }
  127.  
  128. //***********************************************************
  129.  
  130. void CMiniTelnetApp::OpenDocument
  131.     (FSSpec* inMacFSSpec)                // the settings file document to open
  132.  
  133.     // The user chose Open… from the File menu. Creates a new session
  134.     // with the contents of the settings file.
  135.  
  136. {
  137. /*
  138.     TelnetSettingsRec newSettings;
  139.  
  140.     if (macSFReply->fType == kSettingsFileType) {
  141.         OpenSettingsFile(inMacFSSpec, &newSettings);
  142.         NewSession(&newSettings);
  143.     }
  144. */
  145. }
  146.  
  147.  
  148. //***********************************************************
  149.  
  150. void CMiniTelnetApp::OpenSettings
  151.     (FSSpec* inMacFSSpec)            // the settings file document to open
  152.  
  153.     // What happens to File->Open Settings from the menu. Creates a new settings dialog with the
  154.     // contents of the settings file.
  155.     
  156.     //! NOTE NEW parameters
  157.  
  158. {
  159. /*
  160.     CTelnetSettingsDialog*    theDialog = nil;
  161.     TelnetSettingsRec        newSettings;
  162.     
  163.     OpenSettingsFile(inMacFSSpec, &newSettings);
  164.  
  165.     Try_ {
  166.         theDialog = new CTelnetSettingsDialog(this);
  167.         ::BlockMoveData(&newSettings, &(theDialog->r), sizeof (TelnetSettingsRec));
  168.         theDialog->PutSettings();
  169.         theDialog->BeginDialog();
  170.     }
  171.     
  172.     Catch_(err) {
  173.         if (theDialog)
  174.             delete theDialog;
  175.     }
  176.     EndCatch_;
  177. */
  178. }
  179.  
  180. //***********************************************************
  181.  
  182. void CMiniTelnetApp::OpenSettingsFile
  183.     (FSSpec*            inMacFSSpec,        // the settings file document to read
  184.     TelnetSettingsRec*    theSettings)        // where to put the settings record
  185.  
  186.     // Read a Telnet settings document.
  187.  
  188. {
  189. /*
  190.     CDataFile*    itsFile = nil;                // don’t need to keep the file around
  191.     volatile Handle    tempHandle = nil;
  192.  
  193.  
  194.     // read the file
  195.     
  196.     Try_ {
  197.         itsFile = new LFile(inFileSpec);
  198.         itsFile->OpenDataFork(fsRdPerm);
  199.         tempHandle = itsFile->ReadDataFork();
  200.         ::BlockMoveData(*tempHandle, theSettings, sizeof (TelnetSettingsRec));
  201.         ::DisposeHandle(tempHandle);
  202.         tempHandle = nil;
  203.         delete itsFile;
  204.     }
  205.     
  206.     Catch_(err) {
  207.         if (itsFile)
  208.             delete itsFile;
  209.         if (tempHandle)
  210.             ::DisposeHandle(tempHandle);
  211.         tempHandle = nil;
  212.     }
  213.     EndCatch_;
  214. */
  215. }
  216.  
  217. //***********************************************************
  218.  
  219. void CMiniTelnetApp::NewSession
  220.     (TelnetSettingsRec& newSettings)        // the settings record which was opened
  221.  
  222.     // Create a new session from the settings record given.
  223.  
  224. {
  225.     CTelnetTerminal* newTerminal = new CTelnetTerminal(this, kTelnetPort, kTelnetRecBufferSize,
  226.                                                 kTelnetAutoRecSize, kTelnetAutoRecNum);
  227.     newTerminal->NewSession(newSettings);
  228.             // terminal session doc will dispose of itself if it fails
  229. }
  230.  
  231.  
  232. // -- menu/command handling --
  233.  
  234. //***********************************************************
  235.  
  236.  
  237.  
  238. Boolean CMiniTelnetApp::ObeyCommand
  239.     (CommandT    inCommand,            // the command number
  240.     void*        ioParam)                // optional additional info
  241.  
  242.     // Handle application-specific commands.
  243.  
  244. {
  245. return LDocApplication::ObeyCommand(inCommand, ioParam);
  246.  
  247. #if 0
  248.     Point                corner;
  249.     SFTypeList        fileTypes;
  250.     SFReply            macSFReply;
  251. /*
  252.     CAboutDirector*    theAboutDirector = NULL;
  253. */
  254.  
  255.     switch (theCommand) {
  256.  
  257. /*
  258.         // About… command
  259.  
  260.         case cmdAbout:
  261.             theAboutDirector = new CAboutDirector(DLOGAboutBox, this);
  262.             theAboutDirector->DoAbout(FALSE, 0);
  263.             break;
  264. */        
  265.  
  266.  
  267.         // open settings file
  268.  
  269.         case cmdOpenSettings:
  270.                                 // can’t use ChooseFile since subclass might
  271.                                 // have specified additional file types
  272.             fileTypes[0] = kSettingsFileType;
  273.             FindDlogPosition('DLOG', sfGetDLOGid, &corner);
  274.             SFPGetFile(corner, "\p", sfFileFilter, 1, fileTypes,
  275.                         sfGetDLOGHook, &macSFReply, sfGetDLOGid, sfGetDLOGFilter);
  276.  
  277.             if (macSFReply.good) {
  278.                 SetCursor(*gWatchCursor);
  279.                 OpenSettings(&macSFReply);
  280.             }
  281.             break;
  282.         
  283.         default:
  284.             CTCPApplication::DoCommand(theCommand);
  285.             break;
  286.     }
  287. #endif
  288. }
  289.  
  290.  
  291. void CMiniTelnetApp::ListenToMessage
  292.     (MessageT    inMessage,            // message number
  293.     void*        ioParam)                 // optional extra info
  294.  
  295. {
  296.     switch (inMessage) {
  297.         case msg_OpenSession:
  298.             TelnetSettingsRec theSettings;
  299.             CTelnetSettingsDialog* theDialog = (CTelnetSettingsDialog*) ioParam;
  300.             theDialog->GrabSettings(theSettings);
  301.             NewSession(theSettings);
  302.             break;
  303.  
  304.         // no need for default clause: no other LListeners in inheritance chain
  305.         
  306.     }
  307. }
  308.  
  309.  
  310.  
  311. //***********************************************************
  312.  
  313. void CMiniTelnetApp::FindCommandStatus
  314.     (CommandT    inCommand,
  315.     Boolean&        outEnabled,
  316.     Boolean&        outUsesMark,
  317.     Char16&        outMark,
  318.     Str255        outName)
  319.  
  320.     // Return the status of a command.
  321.     // NOTE NEW parameters
  322.  
  323. {
  324. LDocApplication::FindCommandStatus(inCommand, outEnabled, outUsesMark, outMark, outName);
  325. /*
  326.     //! need to rewrite this for PP style
  327.     CTCPApplication::SetUpMenus();
  328.     gBartender->SetUnchecking(MENUTelnet, TRUE);
  329.     CApplication::UpdateMenus();
  330.     gBartender->EnableCmd(cmdOpenSettings);
  331. */
  332. }
  333.  
  334. void CMiniTelnetApp::ChooseDocument()
  335.  
  336. {
  337.     StandardFileReply    macFileReply;
  338.     SFTypeList        typeList;
  339.     
  340.     UDesktop::Deactivate();
  341.      typeList[0] = kSettingsFileType;
  342.     ::StandardGetFile(nil, 1, typeList, &macFileReply);
  343.     UDesktop::Activate();
  344.     if (macFileReply.sfGood)
  345.         OpenDocument(&macFileReply.sfFile);
  346. }
  347.  
  348.