home *** CD-ROM | disk | FTP | other *** search
Text File | 1993-12-10 | 6.5 KB | 331 lines | [TEXT/KAHL] |
- /*
- ** CMiniTelnetApp.cp
- **
- ** MiniTelnet application
- ** Application subclass
- **
- ** Copyright © 1993, FrostByte Design / Eric Scouten
- **
- */
-
-
- #include "CMiniTelnetApp.h"
-
- #ifndef TurboTCPHeaders
- #include <Global.h>
- #include <Commands.h>
- #include <TBUtilities.h>
- #include <CApplication.h>
- #include <CBartender.h>
- #endif
-
- #include <CDataFile.h>
- #include "CAboutDirector.h"
- #include "CTelnetTerminal.h"
- #include "CTelnetSettingsDLOG.h"
-
-
- // global TCL objects
-
- extern CApplication *gApplication;
- extern CBartender *gBartender;
- extern OSType gSignature;
- extern CursHandle gWatchCursor;
- extern OSType gSignature;
-
-
- // —— initialization ——
-
- /*______________________________________________________________________
- **
- ** IMiniTelnetApp
- **
- ** Initialize the application.
- **
- */
-
- void CMiniTelnetApp::IMiniTelnetApp (void)
-
- {
- CTCPApplication::ITCPApplication(kExtraMasters, kRainyDayFund, kCriticalBalance,
- kToolboxBalance);
- gSignature = kAppSignature;
- }
-
-
- /*______________________________________________________________________
- **
- ** SetUpFileParameters
- **
- ** What kind of files can we handle?
- **
- */
-
- void CMiniTelnetApp::SetUpFileParameters (void)
-
- {
- CApplication::SetUpFileParameters();
-
- sfNumTypes = 1;
- sfFileTypes[0] = kSettingsFileType;
- gSignature = kAppSignature;
- }
-
-
- // —— creation of Telnet sessions (documents) ——
-
- /*______________________________________________________________________
- **
- ** CreateDocument
- **
- ** What happens to File->New from the menu. Creates a settings dialog rather than a session
- ** document. The dialog will open a session if the user so desires.
- **
- */
-
- void CMiniTelnetApp::CreateDocument (void)
-
- {
- CTelnetSettingsDLOG *theDialog = NULL;
-
- TRY {
- theDialog = new (CTelnetSettingsDLOG);
- theDialog->ITelnetSettingsDLOG(this);
- theDialog->DefaultSettings();
- theDialog->BeginDialog();
- }
-
- CATCH {
- ForgetObject(theDialog);
- }
- ENDTRY;
- }
-
-
- /*______________________________________________________________________
- **
- ** OpenDocument
- **
- ** The user chose Open… from the File menu. Creates a new session
- ** with the contents of the settings file.
- **
- ** input: 1: (...) the settings file document to open
- **
- */
-
- void CMiniTelnetApp::OpenDocument (SFReply *macSFReply)
-
- {
- TelnetSettingsRec newSettings;
-
- if (macSFReply->fType == kSettingsFileType) {
- OpenSettingsFile(macSFReply, &newSettings);
- NewSession(&newSettings);
- }
- }
-
-
- /*______________________________________________________________________
- **
- ** OpenSettings
- **
- ** What happens to File->Open Settings from the menu. Creates a new settings dialog with the
- ** contents of the settings file.
- **
- ** macSFReply (SFReply *): the settings file document to open
- **
- */
-
- void CMiniTelnetApp::OpenSettings (SFReply *macSFReply)
-
- {
- CTelnetSettingsDLOG *theDialog = NULL;
- TelnetSettingsRec newSettings;
-
- OpenSettingsFile(macSFReply, &newSettings);
-
- TRY {
- theDialog = new(CTelnetSettingsDLOG);
- theDialog->ITelnetSettingsDLOG(this);
- BlockMove(&newSettings, &(theDialog->r), sizeof(TelnetSettingsRec));
- theDialog->PutSettings();
- theDialog->BeginDialog();
- }
-
- CATCH {
- ForgetObject(theDialog);
- }
- ENDTRY;
-
- }
-
-
- /*______________________________________________________________________
- **
- ** OpenSettingsFile
- **
- ** Read a Telnet settings document.
- **
- ** macSFReply (SFReply *): the settings file document to read
- ** theSettings (TelnetSettingsRec *): where to put the settings record
- **
- */
-
- void CMiniTelnetApp::OpenSettingsFile (SFReply *macSFReply, TelnetSettingsRec *theSettings)
-
- {
- CDataFile *itsFile = NULL; // don’t need to keep the file around
-
-
- // read the file
-
- TRY {
- itsFile = new(CDataFile);
- itsFile->IDataFile();
- itsFile->SFSpecify(macSFReply);
- itsFile->Open(fsRdPerm);
-
- itsFile->ReadSome((Ptr) theSettings, sizeof(TelnetSettingsRec));
- itsFile->Close();
- itsFile->Dispose();
- }
-
- CATCH {
- ForgetObject(itsFile);
- }
- ENDTRY;
- }
-
-
- /*______________________________________________________________________
- **
- ** NewSession
- **
- ** Create a new session from the settings record given.
- **
- ** newSettings (TelnetSettingsRec *): the settings record which was opened
- **
- */
-
- void CMiniTelnetApp::NewSession (TelnetSettingsRec *newSettings)
-
- {
- CTelnetTerminal *newTerminal;
-
- newTerminal = new (CTelnetTerminal);
- newTerminal->ITelnetTerminal(gApplication, kTelnetRecBufferSize, TRUE, kTelnetPort,
- kTelnetAutoRecSize, kTelnetAutoRecNum);
- newTerminal->NewSession(newSettings);
- // terminal session doc will dispose of itself if it fails
- }
-
-
- // —— menu/command handling ——
-
- /*______________________________________________________________________
- **
- ** DoCommand
- **
- ** Handle application-specific commands.
- **
- ** theCommand (long): the command number which was issued
- **
- */
-
- void CMiniTelnetApp::DoCommand (long theCommand)
-
- {
- Point corner;
- SFTypeList fileTypes;
- SFReply macSFReply;
- CAboutDirector *theAboutDirector = NULL;
-
- switch (theCommand) {
-
- // About… command
-
- case cmdAbout:
- theAboutDirector = new (CAboutDirector);
- theAboutDirector->IAboutDirector(DLOGAboutBox, this);
- theAboutDirector->DoAbout(FALSE, 0);
- break;
-
-
- // open settings file
-
- case cmdOpenSettings:
- // can’t use ChooseFile since subclass might
- // have specified additional file types
- fileTypes[0] = kSettingsFileType;
- FindDlogPosition('DLOG', sfGetDLOGid, &corner);
- SFPGetFile(corner, "\p", sfFileFilter, 1, fileTypes,
- sfGetDLOGHook, &macSFReply, sfGetDLOGid, sfGetDLOGFilter);
-
- if (macSFReply.good) {
- SetCursor(*gWatchCursor);
- OpenSettings(&macSFReply);
- }
- break;
-
- default:
- CTCPApplication::DoCommand(theCommand);
- break;
- }
- }
-
-
- /*______________________________________________________________________
- **
- ** SetUpMenus
- **
- ** Set up menus which must be created at run time (e.g. Font menu).
- **
- */
-
- void CMiniTelnetApp::SetUpMenus (void)
-
- {
- CApplication::SetUpMenus();
- gBartender->SetUnchecking(MENUTelnet, TRUE);
- }
-
-
- /*______________________________________________________________________
- **
- ** UpdateMenus
- **
- ** Adjust menus on mouse-down event.
- **
- */
-
- void CMiniTelnetApp::UpdateMenus (void)
-
- {
- CApplication::UpdateMenus();
- gBartender->EnableCmd(cmdOpenSettings);
- }
-
-
- /*______________________________________________________________________
- **
- ** Run
- **
- ** Run the application. Overriden to provide splash screen.
- **
- */
-
- void CMiniTelnetApp::Run (void)
-
- {
- CAboutDirector *theAboutDirector = NULL;
-
-
- // show a splash screen (modified about… box), then run the app
-
- theAboutDirector = new (CAboutDirector);
- theAboutDirector->IAboutDirector(DLOGAboutBox, this);
- theAboutDirector->DoAbout(TRUE, kSplashScreenTicks);
-
- CApplication::Run();
-
- }