UAEDocument.cp

//  UAEDocument.cp 
//  Copyright © 1991-92 by Apple Computer, Inc. All rights reserved.
//  Kent Sandvik DTS
//  This file contains the basic TAEDocument member functions
//
//  <1>     khs     1.0     First final version
 
 
// INCLUDES
#ifndef __UAEDOCUMENT__
#include "UAEDocument.h"                                        
#endif
 
 
//  CLASS METHODS 
//  Empty constructor - for avoiding ptabs in global data space
 
#undef Inherited
#define Inherited TDocument
 
#pragma segment ARes
DefineClass(TAEDocument, TDocument);
 
TAEDocument::TAEDocument()
{
}
 
//  Create TAEDocument
#pragma segment AInit
void TAEDocument::IAEDocument()
{
    Inherited::IDocument();
    
    // initialize handle to AE
    fAEGestaltAddress.descriptorType = typeNull;
    fAEGestaltAddress.dataHandle = NULL;
    fConfigurationInfo = NULL;
    fOKNode = FALSE;
}
 
 
//  Create any needed TDocument Views
#pragma segment AOpen
void TAEDocument::DoMakeViews(Boolean   /*forPrinting*/)
{
    TWindow * aWindow = NULL;
    FailInfo fi;
    
    Try(fi)
    {
        // create Main Information Window   
        aWindow = (TWindow *)gViewServer->NewTemplateWindow(kMainWindow, this);
 
        // find text views
        fInfoField = (TStaticText *)aWindow->FindSubView('info');
        fLabelView = (TLabelView *)aWindow->FindSubView('VIW1');
        fInfoView   = (TInformationView *)aWindow->FindSubView('VIW2');
 
        // find buttons
        fFindButton = (TButton *)aWindow->FindSubView('find');
        fReportButton = (TButton *)aWindow->FindSubView('repo');
 
 
//  Add Adorners to various views - yes this would be far better to do
//  from the resource file itself, but as long as there's no ViewEdit 3.0
//  which handles the new format, I'm hesitant to hack in by hand these
//  values, because it's a tidy exersize.
 
        // add window adorners, fill gray background
        aWindow->AddAdorner(NewStdAdorner('gray',"",'gray', kFreeOnDeletion), 
                                            kAdornBefore, kRedraw);
                                            
        // add view adorners, frame second view
        fInfoView->AddAdorner(NewStdAdorner('fram', "", 'fram', kFreeOnDeletion),
                                            kDrawView, kRedraw);
        fInfoView->AddAdorner(NewStdAdorner('eras', "", 'eras', kFreeOnDeletion),
                                            kDrawView, kRedraw);
        
        // add static text adorner, erase background
        fInfoField->AddAdorner(NewStdAdorner('eras', "", 'eras', kFreeOnDeletion),
                                                kDrawView, kRedraw);
        fi.Success();
    }
    else
        fi.ReSignal();
}
 
 
//  Handle Events passed to TDocument, like the find button event
#pragma segment AMain
void TAEDocument::DoEvent(EventNumber eventNumber,
                                 TEventHandler* source,
                                 TEvent* event)
{
    if (eventNumber == mButtonHit)
    {
        // were any of the buttons pressed?
        if (source->fIdentifier == 'find')
        {
            // find button? 
            // post a menu command which translates to the FindÉ menu entry 
            this->HandleMenuCommand(cFindAEGestalt);
        }
 
        else if (source->fIdentifier == 'repo')
        {
            // report button & we have valid node?
            if (fOKNode)
            // post a menu command which translates to the ReportÉ menu entry   
                this->HandleMenuCommand(cCreateReport);
        }
    }
    else
        Inherited::DoEvent(eventNumber, source, event);
}
 
 
//  Free any resources attached to the TDocument, take also care of AE resources
#pragma segment AClose
void TAEDocument::Free()
{
    AEAddressDesc aDesc = fAEGestaltAddress;
    // dispose the descriptor!
    AEDisposeDesc(&aDesc);
 
    Inherited::Free();
}
 
 
//  Setup menus when TDocument is created
#pragma segment ARes
void TAEDocument::DoSetupMenus()
{
    Inherited::DoSetupMenus();
 
    // we assume that we are starting from a Find command
    Enable(cFindAEGestalt, TRUE);
 
    // we can't report anything until we have information
    Enable(cCreateReport, fAEGestaltAddress.dataHandle != NULL);
    fReportButton->DimState(!(fAEGestaltAddress.dataHandle != NULL), TRUE);
}
 
 
//  Handle menu commands assigned to the TDocument controlled menus
#pragma segment ASelCommand
void TAEDocument::DoMenuCommand(CommandNumber theNumber)
{
    TCommand * cmdToPost = NULL;
    TAEClientCommand * AEcmd = NULL;
    TLookupCommand * aLookup = NULL;
 
 
    switch (theNumber)
    {
        case cFindAEGestalt:
            aLookup = new TLookupCommand;
            aLookup->ILookupCommand(cFindAEGestalt, this);
            cmdToPost = aLookup;
            fInfoField->SetText("Look for node to examine...", TRUE);
            break;
 
        case cCreateReport:
            AEcmd = new TAEClientCommand;
            AEcmd->IAEClientCommand(cCreateReport, this, kAEGetConfig);
            cmdToPost = AEcmd;
            fInfoField->SetText("Report node information...", TRUE);
            break;
 
        default:
            Inherited::DoMenuCommand(theNumber);
    }
    if (cmdToPost != NULL)
        this->PostAnEvent(cmdToPost);
}
 
 
//  Return the AppleEvents address stored in TAEDocument
#pragma segment ARes
void TAEDocument::GetAEGestaltAddress(AEAddressDesc& theAddress)
{
    theAddress = fAEGestaltAddress;
}
 
 
//  Read the Configuration information
#pragma segment Main
void TAEDocument::ReadConfiguration(Configuration* theConfig)
{
    BlockMove(&theConfig, &fConfigurationInfo, sizeof(theConfig));
}
 
 
//  Process the information we got from the AE for the View class for
//  later display
#pragma segment Main
void TAEDocument::ProcessAEInformation()
{
    switch (fConfigurationInfo->machineType)
    {                                           // Label1 - Machine Type
        case 1:
            fInfoView->fLabel1 = "Classic";
            break;
        case 2:
            fInfoView->fLabel1 = "MacXL";
            break;
        case 3:
            fInfoView->fLabel1 = "Mac512KE";
            break;
        case 4:
            fInfoView->fLabel1 = "Mac Plus";
            break;
        case 5:
            fInfoView->fLabel1 = "MacSE";
            break;
        case 6:
            fInfoView->fLabel1 = "MacII";
            break;
        case 7:
            fInfoView->fLabel1 = "MacIIx";
            break;
        case 8:
            fInfoView->fLabel1 = "MacIIcx";
            break;
        case 9:
            fInfoView->fLabel1 = "MacSe030";
            break;
        case 10:
            fInfoView->fLabel1 = "Portable";
            break;
        case 11:
            fInfoView->fLabel1 = "MacIIci";
            break;
        case 13:
            fInfoView->fLabel1 = "MacIIfx";
            break;
        case 17:
            fInfoView->fLabel1 = "Mac Classic";
            break;
        case 18:
            fInfoView->fLabel1 = "MacIIsi";
            break;
        case 19:
            fInfoView->fLabel1 = "MacLC";
            break;
        case 20:
            fInfoView->fLabel1 = "Quadra 900";
            break;
        case 21:
            fInfoView->fLabel1 = "PowerBook 140";
            break;
        case 22:
            fInfoView->fLabel1 = "Quadra 700";
            break;
        case 23:
            fInfoView->fLabel1 = "Classic II";
            break;
        case 24:
            fInfoView->fLabel1 = "PowerBook 100";
            break;
        case 25:
            fInfoView->fLabel1 = "PowerBook 140";
            break;
        default:
            fInfoView->fLabel1 = "Unknown type";
            break;
    }
 
    if (fConfigurationInfo->systemVersion == 0x700)// Label2 - System Version
        fInfoView->fLabel2 = "System 7.0";
    else if (fConfigurationInfo->systemVersion == 0x701)
        fInfoView->fLabel2 = "System 7.0.1";
    else if (fConfigurationInfo->systemVersion == 0x602)
        fInfoView->fLabel2 = "System 6.0.2";
    else if (fConfigurationInfo->systemVersion == 0x603)
        fInfoView->fLabel2 = "System 6.0.3";
    else if (fConfigurationInfo->systemVersion == 0x604)
        fInfoView->fLabel2 = "System 6.0.4";
    else if (fConfigurationInfo->systemVersion == 0x605)
        fInfoView->fLabel2 = "System 6.0.5";
    else if (fConfigurationInfo->systemVersion == 0x607)
        fInfoView->fLabel2 = "System 6.0.7";
    else if (fConfigurationInfo->systemVersion < 0x600)
        fInfoView->fLabel2 = "Pre 6.0.x System";
    else if (fConfigurationInfo->systemVersion > 0x701)
        fInfoView->fLabel2 = "Post 7.0.1 System";
 
    switch (fConfigurationInfo->processor)
    {                                           // Label3 - Processor Type
        case 1:
            fInfoView->fLabel3 = "68000";
            break;
        case 2:
            fInfoView->fLabel3 = "68010";
            break;
        case 3:
            fInfoView->fLabel3 = "68020";
            break;
        case 4:
            fInfoView->fLabel3 = "68030";
            break;
        case 5:
            fInfoView->fLabel3 = "68040";
            break;
        default:
            fInfoView->fLabel3 = "Unknown CPU";
            break;
    }
 
    if (fConfigurationInfo->hasFPU)             // Label4 - Has FPU?
        fInfoView->fLabel4 = "TRUE";
    else
        fInfoView->fLabel4 = "FALSE";
 
    if (fConfigurationInfo->hasColorQD)         // Label5 - Has Color QD?
        fInfoView->fLabel5 = "TRUE";
    else
        fInfoView->fLabel5 = "FALSE";
 
    if (fConfigurationInfo->has32BitQD)         // Label6 - Has 32-bit QD?
        fInfoView->fLabel6 = "TRUE";
    else
        fInfoView->fLabel6 = "FALSE";
 
    if (fConfigurationInfo->hasSCSI)            // Label7 - Has SCSI?
        fInfoView->fLabel7 = "TRUE";
    else
        fInfoView->fLabel7 = "FALSE";
 
    if (fConfigurationInfo->hasAppleEventMgr)   // Label8 - Has AppleEvent Mgr?
        fInfoView->fLabel8 = "TRUE";
    else
        fInfoView->fLabel8 = "FALSE";
 
    if (fConfigurationInfo->hasEditionMgr)      // Label9 - Has Edition Mgr?
        fInfoView->fLabel9 = "TRUE";
    else
        fInfoView->fLabel9 = "FALSE";
 
    if (fConfigurationInfo->hasAUX)             // Label10 - Is A/UX System?
        fInfoView->fLabel10 = "TRUE";
    else
        fInfoView->fLabel10 = "FALSE";
 
    if (fConfigurationInfo->hasTrueType)        // Label11 - Has TrueType?
        fInfoView->fLabel11 = "TRUE";
    else
        fInfoView->fLabel11 = "FALSE";
 
    CStr255 tempString;                         // Label12 - AppleTalk version
    NumToString(long(fConfigurationInfo-> atDrvrVersNum), tempString);
    fInfoView->fLabel12 = tempString;
 
    fInfoView->fHasGestaltInfo = TRUE;          // report for view to draw
    fInfoView->ForceRedraw();                   // redraw the view
}