home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-01-19 | 8.3 KB | 348 lines | [TEXT/MMCC] |
- //
- // CMiniTelnetApp.cp
- //
- // MiniTelnet application
- // Application subclass
- // PowerPlant version
- //
- // Copyright © 1993-95, FrostByte Design / Eric Scouten
- //
-
- #include "CMiniTelnetApp.h"
-
- #include "CTelnetTerminal.h"
- #include "CTelnetSettingsDialog.h"
- #include "CTerminalPane.h"
-
- #include <LCaption.h>
- #include <LDialogBox.h>
- #include <LEditField.h>
- #include <LGrowZone.h>
- #include <LListBox.h>
- #include <LPicture.h>
- #include <LScroller.h>
- #include <LStdControl.h>
- #include <LWindow.h>
-
- #include <UDesktop.h>
- #include <UDrawingState.h>
- #include <UExtractFromAEDesc.h>
- #include <UMemoryMgr.h>
- #include <UPowerTools.h>
- #include <URegistrar.h>
-
- #include <PP_Messages.h>
-
-
- //***********************************************************
-
- void main()
-
- // The big one. Set up the OOP stuff and let it go.
-
- {
-
- // set debugging options
-
- #ifdef Debug_Throw
- gDebugThrow = debugAction_Alert;
- #endif
- #ifdef Debug_Signal
- gDebugSignal = debugAction_Alert;
- #endif
-
-
- // initialize Toolbox
-
- InitializeHeap(3); // parameter is number of master pointer blocks to allocate
- UQDGlobals::InitializeToolbox(&qd);
-
-
- // check for missing MBAR (probably means most resources are missing)
-
- #ifdef Debug_Signal
- CheckForInitialMBAR();
- #endif
-
-
- // install handler for low-memory situations
-
- new LGrowZone(20000); // parameter is size of reserve memory block to allocated
-
-
- // create the application & run it
-
- CMiniTelnetApp theApp;
- theApp.Run();
-
- }
-
-
- //***********************************************************
-
- CMiniTelnetApp::CMiniTelnetApp()
-
- : LDocApplication(),
- CTCPApplicationPP(this)
- {
-
- // register classes which will be created from 'PPob' resources
-
- URegistrar::RegisterClass(LCaption::class_ID, (ClassCreatorFunc) LCaption::CreateCaptionStream);
- URegistrar::RegisterClass(LDialogBox::class_ID, (ClassCreatorFunc) LDialogBox::CreateDialogBoxStream);
- URegistrar::RegisterClass(LEditField::class_ID, (ClassCreatorFunc) LEditField::CreateEditFieldStream);
- URegistrar::RegisterClass(LScroller::class_ID, (ClassCreatorFunc) LScroller::CreateScrollerStream);
- URegistrar::RegisterClass(LStdButton::class_ID, (ClassCreatorFunc) LStdButton::CreateStdButtonStream);
- URegistrar::RegisterClass(LStdCheckBox::class_ID, (ClassCreatorFunc) LStdCheckBox::CreateStdCheckBoxStream);
- URegistrar::RegisterClass(LStdPopupMenu::class_ID, (ClassCreatorFunc) LStdPopupMenu::CreateStdPopupMenuStream);
- URegistrar::RegisterClass(LStdRadioButton::class_ID, (ClassCreatorFunc) LStdRadioButton::CreateStdRadioButtonStream);
- URegistrar::RegisterClass(LView::class_ID, (ClassCreatorFunc) LView::CreateViewStream);
- URegistrar::RegisterClass(LWindow::class_ID, (ClassCreatorFunc) LWindow::CreateWindowStream);
-
- URegistrar::RegisterClass(CTelnetSettingsDialog::class_ID, (ClassCreatorFunc) CTelnetSettingsDialog::CreateDialogBoxStream);
- URegistrar::RegisterClass(CTerminalPane::class_ID, (ClassCreatorFunc) CTerminalPane::CreateTerminalPaneStream);
-
- }
-
-
- //***********************************************************
- //
- // creation of Telnet sessions (documents)
- //
-
- //***********************************************************
-
- LModelObject* CMiniTelnetApp::MakeNewDocument()
-
- // What happens to File->New Session from the menu. Creates a settings dialog rather
- // than a session document. The dialog will open a session if the user so desires.
-
- {
- CTelnetSettingsDialog* theDialog =
- (CTelnetSettingsDialog*) LWindow::CreateWindow(PPobTelnetSettings, this);
- if (theDialog)
- theDialog->AddListener(this);
- return nil;
- }
-
- //***********************************************************
-
- void CMiniTelnetApp::OpenDocument
- (FSSpec* inMacFSSpec) // the settings file document to open
-
- // The user chose Open… from the File menu. Creates a new session
- // with the contents of the settings file.
-
- {
- /*
- TelnetSettingsRec newSettings;
-
- if (macSFReply->fType == kSettingsFileType) {
- OpenSettingsFile(inMacFSSpec, &newSettings);
- NewSession(&newSettings);
- }
- */
- }
-
-
- //***********************************************************
-
- void CMiniTelnetApp::OpenSettings
- (FSSpec* inMacFSSpec) // the settings file document to open
-
- // What happens to File->Open Settings from the menu. Creates a new settings dialog with the
- // contents of the settings file.
-
- //! NOTE NEW parameters
-
- {
- /*
- CTelnetSettingsDialog* theDialog = nil;
- TelnetSettingsRec newSettings;
-
- OpenSettingsFile(inMacFSSpec, &newSettings);
-
- Try_ {
- theDialog = new CTelnetSettingsDialog(this);
- ::BlockMoveData(&newSettings, &(theDialog->r), sizeof (TelnetSettingsRec));
- theDialog->PutSettings();
- theDialog->BeginDialog();
- }
-
- Catch_(err) {
- if (theDialog)
- delete theDialog;
- }
- EndCatch_;
- */
- }
-
- //***********************************************************
-
- void CMiniTelnetApp::OpenSettingsFile
- (FSSpec* inMacFSSpec, // the settings file document to read
- TelnetSettingsRec* theSettings) // where to put the settings record
-
- // Read a Telnet settings document.
-
- {
- /*
- CDataFile* itsFile = nil; // don’t need to keep the file around
- volatile Handle tempHandle = nil;
-
-
- // read the file
-
- Try_ {
- itsFile = new LFile(inFileSpec);
- itsFile->OpenDataFork(fsRdPerm);
- tempHandle = itsFile->ReadDataFork();
- ::BlockMoveData(*tempHandle, theSettings, sizeof (TelnetSettingsRec));
- ::DisposeHandle(tempHandle);
- tempHandle = nil;
- delete itsFile;
- }
-
- Catch_(err) {
- if (itsFile)
- delete itsFile;
- if (tempHandle)
- ::DisposeHandle(tempHandle);
- tempHandle = nil;
- }
- EndCatch_;
- */
- }
-
- //***********************************************************
-
- void CMiniTelnetApp::NewSession
- (TelnetSettingsRec& newSettings) // the settings record which was opened
-
- // Create a new session from the settings record given.
-
- {
- CTelnetTerminal* newTerminal = new CTelnetTerminal(this, kTelnetPort, kTelnetRecBufferSize,
- kTelnetAutoRecSize, kTelnetAutoRecNum);
- newTerminal->NewSession(newSettings);
- // terminal session doc will dispose of itself if it fails
- }
-
-
- // -- menu/command handling --
-
- //***********************************************************
-
-
-
- Boolean CMiniTelnetApp::ObeyCommand
- (CommandT inCommand, // the command number
- void* ioParam) // optional additional info
-
- // Handle application-specific commands.
-
- {
- return LDocApplication::ObeyCommand(inCommand, ioParam);
-
- #if 0
- Point corner;
- SFTypeList fileTypes;
- SFReply macSFReply;
- /*
- CAboutDirector* theAboutDirector = NULL;
- */
-
- switch (theCommand) {
-
- /*
- // About… command
-
- case cmdAbout:
- theAboutDirector = new CAboutDirector(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;
- }
- #endif
- }
-
-
- void CMiniTelnetApp::ListenToMessage
- (MessageT inMessage, // message number
- void* ioParam) // optional extra info
-
- {
- switch (inMessage) {
- case msg_OpenSession:
- TelnetSettingsRec theSettings;
- CTelnetSettingsDialog* theDialog = (CTelnetSettingsDialog*) ioParam;
- theDialog->GrabSettings(theSettings);
- NewSession(theSettings);
- break;
-
- // no need for default clause: no other LListeners in inheritance chain
-
- }
- }
-
-
-
- //***********************************************************
-
- void CMiniTelnetApp::FindCommandStatus
- (CommandT inCommand,
- Boolean& outEnabled,
- Boolean& outUsesMark,
- Char16& outMark,
- Str255 outName)
-
- // Return the status of a command.
- // NOTE NEW parameters
-
- {
- LDocApplication::FindCommandStatus(inCommand, outEnabled, outUsesMark, outMark, outName);
- /*
- //! need to rewrite this for PP style
- CTCPApplication::SetUpMenus();
- gBartender->SetUnchecking(MENUTelnet, TRUE);
- CApplication::UpdateMenus();
- gBartender->EnableCmd(cmdOpenSettings);
- */
- }
-
- void CMiniTelnetApp::ChooseDocument()
-
- {
- StandardFileReply macFileReply;
- SFTypeList typeList;
-
- UDesktop::Deactivate();
- typeList[0] = kSettingsFileType;
- ::StandardGetFile(nil, 1, typeList, &macFileReply);
- UDesktop::Activate();
- if (macFileReply.sfGood)
- OpenDocument(&macFileReply.sfFile);
- }
-
-