home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-01-19 | 7.7 KB | 364 lines | [TEXT/MMCC] |
- //
- // CTelnetSettingsDialog.cp
- //
- // MiniTelnet application
- // Telnet settings dialog director
- // PowerPlant version
- //
- // Copyright © 1993-95, FrostByte Design / Eric Scouten
- //
-
- #include "CTelnetSettingsDialog.h"
-
- #include <LEditField.h>
- #include <LStdControl.h>
- #include <PP_Messages.h>
-
-
- //***********************************************************
-
- /*______________________________________________________________________
- **
- ** DefaultSettings
- **
- ** Creates a new blank settings record and copies this to the dialog.
- **
- */
-
- void CTelnetSettingsDialog::DefaultSettings()
-
- {
- TelnetSettingsRec theSettings;
-
- theSettings.signature = kTSRsignature;
- theSettings.settingsVersion = kTSRversion;
- theSettings.settingsMinVersion = 0;
- theSettings.hostName[0] = '\0';
- ::BlockMoveData("UNKNOWN", &theSettings.termEmulation, 8);
- // theSettings.backspaceChar = charBS;
- theSettings.backspaceChar = 0x7F; // charDEL;
- theSettings.closeOnSessionEnd = false;
- theSettings.showDebug = false;
-
- PutSettings(theSettings);
- }
-
-
- //***********************************************************
-
- /*______________________________________________________________________
- **
- ** GrabSettings
- **
- ** Get the settings from the dialog box fields and put them into the
- ** settings record.
- **
- */
-
-
-
-
- //***********************************************************
-
- /*______________________________________________________________________
- **
- ** PutSettings
- **
- ** Copy the settings from the settings record to the dialog box fields.
- **
- */
-
-
-
-
- // —— dialog handling functions ——
-
- //***********************************************************
-
- /*______________________________________________________________________
- **
- ** DoCommand
- **
- ** Handle all commands that the dialog can understand.
- **
- ** theCommand (long): the command number which was issued
- **
- */
-
-
-
- //***********************************************************
-
- /*______________________________________________________________________
- **
- ** UpdateMenus
- **
- ** Enable Telnet-specific commands.
- **
- */
-
-
-
-
- // —— file interactions ——
-
- //***********************************************************
-
- /*______________________________________________________________________
- **
- ** DoSaveFile
- **
- ** Save a settings record to a file.
- **
- */
-
- void CTelnetSettingsDialog::DoSaveFile()
-
- {
- /*
- Point corner; // top left corner of dialog box
- Str255 origName; // default name for file
- short nameLength; // length of default name
- StringHandle prompt; // prompt string
- Boolean wasLocked;
-
- CDataFile* itsFile; // don’t keep the file around
- SFReply macSFReply; // reply from Std File
-
-
- // ask user for settings file name
-
- FindDlogPosition('DLOG', putDlgID, &corner);
- BlockMove(&r.hostName, &origName[1], 31);
- nameLength = cstrlen(r.hostName);
- origName[0] = (nameLength > 31 ? 31 : nameLength);
-
- prompt = GetString(STR_SettingsPrompt);
- FailNILRes(prompt);
-
- MoveHHi((Handle) prompt);
- HLock((Handle) prompt);
- SFPPutFile(corner, *prompt, origName, NULL, &macSFReply, putDlgID, NULL);
- ReleaseResource((Handle) prompt);
-
-
- // create the file
-
- TRY {
- itsFile = new CDataFile;
- itsFile->SFSpecify(&macSFReply);
-
- if (itsFile->ExistsOnDisk()) {
- itsFile->Open(fsRdWrPerm);
- itsFile->SetLength(0);
- // TEMPORARY: need to reset file type
- }
- else {
- itsFile->CreateNew(gSignature, kSettingsFileType);
- itsFile->Open(fsRdWrPerm);
- }
- itsFile->WriteSome((Ptr) &r, sizeof(TelnetSettingsRec));
- itsFile->Close();
- delete itsFile;
- }
-
- CATCH {
- ForgetObject(itsFile);
- }
- ENDTRY;
- */
- }
-
- CTelnetSettingsDialog* CTelnetSettingsDialog::CreateDialogBoxStream
- (LStream* inStream) // PPob stream describing the dialog box
-
- {
- return new CTelnetSettingsDialog(inStream);
- }
-
-
- CTelnetSettingsDialog::CTelnetSettingsDialog
- (LStream* inStream)
-
- : LDialogBox(inStream)
- {
- DefaultSettings();
- }
-
-
- void CTelnetSettingsDialog::GrabSettings
- (TelnetSettingsRec& outSettings) // where to put the settings
-
- // Get the settings from the dialog box.
-
- // virtual LPane* FindPaneByID(PaneIDT inPaneID);
- {
- /* TEMPORARY: not *absolutely* necessary…
-
- CCheckBox* theCheckBox;
- CEditText* theText;
- CRadioGroupPane* theRadios;
- CView* theView;
- short textSize;
- */
-
- // blank out the settings record
-
- char* p = (char*) &outSettings;
- for (int i = 0; i < sizeof (TelnetSettingsRec); i++)
- *p++ = 0;
-
-
- // recreate signature, version info
-
- outSettings.signature = kTSRsignature;
- outSettings.settingsVersion = kTSRversion;
- outSettings.settingsMinVersion = 0;
-
-
- // get host name
-
- Str255 theHostName;
- LEditField* theEditField = (LEditField*) FindPaneByID('HOST'); //! TEMPORARY: we’ll do constants later
- ThrowIfNil_(theEditField);
-
- theEditField->GetDescriptor(theHostName);
- ::BlockMoveData(&theHostName[1], &outSettings.hostName, theHostName[0]);
- outSettings.hostName[theHostName[0]] = '\0';
-
-
- // get terminal emulation
-
- ::BlockMoveData("UNKNOWN", &outSettings.termEmulation, 8);
-
-
- // get backspace/del configuration
-
- LStdRadioButton* theButton = (LStdRadioButton*) FindPaneByID('BS '); //! TEMPORARY: we’ll do constants later
- ThrowIfNil_(theButton);
- outSettings.backspaceChar = (theButton->GetValue() ? 0x08 : 0x7F); //! TEMPORARY: again, constants later
-
-
- // get window go away config
-
- LStdCheckBox* theCheckBox = (LStdCheckBox*) FindPaneByID('GOWY'); //! TEMPORARY: we’ll do constants later
- ThrowIfNil_(theCheckBox);
- outSettings.closeOnSessionEnd = theCheckBox->GetValue();
-
-
- // get show debug codes config
-
- theCheckBox = (LStdCheckBox*) FindPaneByID('DEBG'); //! TEMPORARY: we’ll do constants later
- ThrowIfNil_(theCheckBox);
- outSettings.showDebug = theCheckBox->GetValue();
-
- }
-
-
- void CTelnetSettingsDialog::PutSettings
- (TelnetSettingsRec& inSettings) // where to get settings from
-
- // Configure the dialog box to reflect the given settings record.
-
- {
- /* TEMPORARY: not *absolutely* necessary…
-
- CCheckBox* theCheckBox;
- CEditText* theText;
- CPane* thePane;
- CRadioGroupPane* theRadios;
- CView* theView;
-
-
- // get host name
-
- theView = itsWindow->FindViewByID(itemHostName);
- theText = TCL_DYNAMIC_CAST(CEditText, theView);
- if (theText)
- theText->SetTextPtr((char*) &r.hostName, cstrlen(r.hostName));
-
-
- // get backspace/del configuration
-
- theView = itsWindow->FindViewByID(itemBSPane);
- theRadios = TCL_DYNAMIC_CAST(CRadioGroupPane, theView);
- if (theRadios)
- theRadios->SetStationID((r.backspaceChar == charDEL) ? itemBS_DEL : itemBS_BS);
-
-
- // get window go away config
-
- theView = itsWindow->FindViewByID(itemGoAway);
- theCheckBox = TCL_DYNAMIC_CAST(CCheckBox, theView);
- if (theCheckBox)
- theCheckBox->SetValue(r.closeOnSessionEnd);
-
-
- // get show debug codes config
-
- theView = itsWindow->FindViewByID(itemShowDebug);
- theCheckBox = TCL_DYNAMIC_CAST(CCheckBox, theView);
- if (theCheckBox)
- theCheckBox->SetValue(r.showDebug);
-
-
- // ignore other parms
-
- // force redraw
-
- thePane = TCL_DYNAMIC_CAST(CPane, itsWindow);
- if (thePane)
- thePane->Refresh();
- */
- }
-
-
- void CTelnetSettingsDialog::ListenToMessage
- (MessageT inMessage, // message number
- void* ioParam) // optional extra info
-
- {
- switch (inMessage) {
-
- case msg_OpenSession:
- BroadcastMessage(msg_OpenSession, this);
- DoClose();
- break;
-
- case msg_Cancel:
- DoClose();
- break;
-
- default:
- LDialogBox::ListenToMessage(inMessage, ioParam);
- }
-
- }
-
-
- void CTelnetSettingsDialog::FindCommandStatus
- (CommandT inCommand,
- Boolean& outEnabled,
- Boolean& outUsesMark,
- Char16& outMark,
- Str255 outName)
-
- {
- /*
- CDLOGDirector::UpdateMenus();
- gBartender->EnableCmd(cmdSave);
- gBartender->EnableCmd(cmdSaveAs);
- */
- LDialogBox::FindCommandStatus(inCommand, outEnabled, outUsesMark, outMark, outName);
- }
-
-
- Boolean CTelnetSettingsDialog::ObeyCommand
- (CommandT inCommand, // the command number
- void* ioParam) // optional additional info
-
- {
- return LDialogBox::ObeyCommand(inCommand, ioParam);
- }
-
-