/////////////////////////////////////////
// START of File: C2_CVIEW.CPP
/////////////////////////////////////////

//-------------------------------------------------------------------
// COPYRIGHT NOTICE:  This code is protected by Copyright!
//
// Copyright (c) 1994 through 1997 by DPC Technology Corporation.
// All rights reserved.
//
// See files "cf_copyr.h" and "cf_licen.h" for details of
// copyright and license specifications, and contact information.
//-------------------------------------------------------------------

#include    <cf_api/c4_cview.hpp>

//--------------------------------------------------------------------
// We will need to include the class specifications of the various
// chart-engines (which are version dependent) that this chart-view
// object might create during its scope-of-operation...
//--------------------------------------------------------------------
class       cf_eng_Pie2D;
#include    <cf_api/ce2_pie.hpp>

class       cf_eng_Bar2D;
#include    <cf_api/ce2_bar.hpp>

class       cf_eng_Col2D;
#include    <cf_api/ce2_colm.hpp>

class       cf_eng_Stack2D;
#include    <cf_api/ce2_stac.hpp>

class       cf_eng_PointSer2D;
#include    <cf_api/ce2_pser.hpp>

class       cf_eng_Line2D;
#include    <cf_api/ce2_line.hpp>

class       cf_eng_Area2D;
#include    <cf_api/ce2_area.hpp>

//-----------------------------------------------------------------
// Implement the Chart-View's "Set-Engine-by-Type-Spec" Method(s):
//----------------------------------------------------------------
BOOL
cf_ChartView::activeEngine
            (   cf_ChartType    enumChartType,
                cf_DispMode     enumDispMode,
                BOOL            bDeleteOldEngine )
//***************************************************
// Note these VERY IMPORTANT side-effects!
//  bWasViewsEngineNewed_ = TRUE;
//  p_ViewsModel_->activeEngine( p_ViewsEngine );
//***************************************************
{
    BOOL    bStatus = FALSE;

    // IF requested (and by default) if there was a previous
    // engine already allocated, we will need get rid of it:
    if( bDeleteOldEngine == TRUE )
        if ( bWasViewsEngineNewed_ == TRUE )
            delete p_ViewsEngine_;

    if ( ( enumDispMode == CF_DISP_2D ) || ( enumDispMode == CF_DISP_3D ) )
    {
        switch ( enumChartType )
        {
            // Note that 3D Chart-Types are not
            // implemented for this 2D-only version:
            case CF_TYPE_AREA:
                p_ViewsEngine_ = new cf_eng_Area2D();
                bStatus = TRUE;
                break;

            case CF_TYPE_BAR:
                p_ViewsEngine_ = new cf_eng_Bar2D();
                bStatus = TRUE;
                break;

            case CF_TYPE_COLUMN:
                p_ViewsEngine_ = new cf_eng_Col2D();
                bStatus = TRUE;
                break;

            case CF_TYPE_LINE:
                p_ViewsEngine_ = new cf_eng_Line2D();
                bStatus = TRUE;
                break;

            case CF_TYPE_PIE:
                p_ViewsEngine_ = new cf_eng_Pie2D();
                bStatus = TRUE;
                break;

            case CF_TYPE_PSER:
                p_ViewsEngine_ = new cf_eng_PointSer2D();
                bStatus = TRUE;
                break;

            case CF_TYPE_STACK:
                p_ViewsEngine_ = new cf_eng_Stack2D();
                bStatus = TRUE;
                break;

            default:
                bStatus = FALSE;
                break;
        }
    }

    // Paranoid (but healthy!) compensatation for erroneous enum params!
    if ( bStatus == FALSE )
    {
        p_ViewsEngine_ = new cf_eng_PointSer2D();
        bStatus = TRUE;
    }

    // Keep track of what we did w.r.t. new()-ing, etc:
    bWasViewsEngineNewed_ = TRUE;

    // Let the chart-model know which engine to notify on data-state changes:
    p_ViewsModel_->activeEngine( p_ViewsEngine_ );

    // Make sure this new chart-engine will get re-synchronized to the
    // parent chart-control's display upon the first re-draw operation...
    bIsActivatedForControlsDisplay_ = FALSE;

    return( bStatus );

}   // end of cf_ChartView::activeEngine( cf_ChartEngine*, BOOL )


//--------------------------------------------
// See file c4_cview.cpp for the rest of
// the implementation of class cf_ChartView
//--------------------------------------------


/////////////////////////////////////////
// END of File: C2_CVIEW.CPP
/////////////////////////////////////////

