/***************************************************************************** * * Copyright (c) 1999, KL GROUP INC. All Rights Reserved. * http://www.klgroup.com * * This file is provided for demonstration and educational uses only. * Permission to use, copy, modify and distribute this file for * any purpose and without fee is hereby granted, provided that the * above copyright notice and this permission notice appear in all * copies, and that the name of KL Group not be used in advertising * or publicity pertaining to this material without the specific, * prior written permission of an authorized representative of * KL Group. * * KL GROUP MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY * OF THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR * PURPOSE, OR NON-INFRINGEMENT. KL GROUP SHALL NOT BE LIABLE FOR ANY * DAMAGES SUFFERED BY USERS AS A RESULT OF USING, MODIFYING OR * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. * *****************************************************************************/ //--------------------------------------------------------------------------- #include #pragma hdrstop #include "actions1.h" #include "oc_color.h" //--------------------------------------------------------------------------- #pragma link "OlectraChart2D_TLB" #pragma resource "*.dfm" TfrmActions *frmActions; //--------------------------------------------------------------------------- __fastcall TfrmActions::TfrmActions(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- // End the program //--------------------------------------------------------------------------- void __fastcall TfrmActions::mnuExitClick(TObject *Sender) { exit(0); } //--------------------------------------------------------------------------- // Setup the form and the Chart during the form creation process //--------------------------------------------------------------------------- void __fastcall TfrmActions::FormCreate(TObject *Sender) { //Start with the form in the Top Left Corner Top = 5; Left = 5; } //--------------------------------------------------------------------------- // Do some final setup items once the form is finished being created //--------------------------------------------------------------------------- void __fastcall TfrmActions::FormActivate(TObject *Sender) { int HoldLeft; int HoldWidth; int HoldTop; int HoldHeight; //Batch all the updates to the Chart so all the changes occur at once Chart2D1->IsBatched = true; //Remove all the currently defined events ClearEvents(); //Don't allow the user to make changes to the Chart at run-time Chart2D1->AllowUserChanges = true; //Set a global variable to reflect the current action CurrentAction = oc2dActionNone; //Set the Chart to a Bar Chart Variant vCG = Chart2D1->ChartGroups; Variant vCG1 = vCG.OlePropertyGet("Item", 1); vCG1.OlePropertySet("ChartType", oc2dTypeBar); //Setup how much data to show Variant vCG1Data = vCG1.OlePropertyGet("Data"); vCG1Data.OlePropertySet("NumSeries", 4); vCG1Data.OlePropertySet("NumPoints", 1, 2); //Add a couple of labels Variant vPLabels = vCG1.OlePropertyGet("PointLabels"); vPLabels.OleFunction("Add", "Group 1", 1); vPLabels.OleFunction("Add", "Group 2", 2); //Set the Axis to show Point Labels Variant vCArea = Chart2D1->ChartArea_; Variant vAxes = vCArea.OlePropertyGet("Axes"); Variant vXAxis = vAxes.OlePropertyGet("Item", "X"); vXAxis.OlePropertySet("AnnotationMethod", oc2dAnnotatePointLabels); //Give the Chart a 3D look Variant vView3D = vCArea.OlePropertyGet("View3D"); vView3D.OlePropertySet("Depth", 10); vView3D.OlePropertySet("Elevation", 10); vView3D.OlePropertySet("Rotation", 10); //Give the Chart some color Variant vInterior = Chart2D1->Interior_; vInterior.OlePropertySet("BackgroundColor", (int)ocColorLightGoldenrodYellow); vInterior.OlePropertySet("ForegroundColor", (int)ocColorBlack); Variant vPlotArea = vCArea.OlePropertyGet("PlotArea"); vInterior = vPlotArea.OlePropertyGet("Interior"); vInterior.OlePropertySet("BackgroundColor", (int)ocColorTan); //Resume regular updates to the Chart Chart2D1->IsBatched = false; //Setup the Horizontal ScrollBar Variant vLocation = vCArea.OlePropertyGet("Location"); Variant vLocationLeft = vLocation.OlePropertyGet("Left"); HoldLeft = vLocationLeft.OlePropertyGet("Value"); HScroll->Min = HoldLeft; Variant vLocationWidth = vLocation.OlePropertyGet("Width"); HoldWidth = vLocationWidth.OlePropertyGet("Value"); HScroll->Max = HoldLeft + HoldWidth - 1; HScroll->Position = (HScroll->Max - HScroll->Min) / 2; HScrollValue = Position; HScroll->SmallChange = 5; HScroll->LargeChange = 30; HScroll->Enabled = false; //Setup the Vertical ScrollBar Variant vLocationTop = vLocation.OlePropertyGet("Top"); HoldTop = vLocationTop.OlePropertyGet("Value"); VScroll->Min = HoldTop; Variant vLocationHeight = vLocation.OlePropertyGet("Height"); HoldHeight = vLocationHeight.OlePropertyGet("Value"); VScroll->Max = HoldTop + HoldHeight - 1; VScroll->Position = (VScroll->Max - VScroll->Min) / 2; VScrollValue = Position; VScroll->SmallChange = 5; VScroll->LargeChange = 30; VScroll->Enabled = false; //Setup the starting state of the form rbNoneClick(rbNone); cmdReset->SetFocus(); } //--------------------------------------------------------------------------- // Clear all the previously defined Actions //--------------------------------------------------------------------------- void TfrmActions::ClearEvents() { //Remove all currently defined action events Variant vActions = Chart2D1->ActionMaps; vActions.OleFunction("RemoveAll"); } //--------------------------------------------------------------------------- // Enable/Disable the Depth Group Box //--------------------------------------------------------------------------- void TfrmActions::EnableDepthSetting(bool Flag) { //Enable/Disable the Depth setting gbDepth->Enabled = Flag; edDepth->Enabled = Flag; udDepth->Enabled = Flag; } //--------------------------------------------------------------------------- // Enable/Disable the Zoom Type Group Box //--------------------------------------------------------------------------- void TfrmActions::EnableZoomType(bool Flag) { //Enable/Disable Zoom Type gbZoomType->Enabled = Flag; rbAxis->Enabled = Flag; rbGraphic->Enabled = Flag; } //--------------------------------------------------------------------------- // Reset the Scrollbars //--------------------------------------------------------------------------- void TfrmActions::ResetScrollBars(bool hFlag, bool vFlag) { //Reset the Horizontal Scrollbar if (hFlag) { HScrollValue = (HScroll->Max - HScroll->Min) / 2; HScroll->Position = HScrollValue; HScroll->Enabled = hFlag; } else { HScroll->Enabled = hFlag; } //Reset the Vertical Scrollbar if (vFlag) { VScrollValue = (VScroll->Max - VScroll->Min) / 2; VScroll->Position = VScrollValue; VScroll->Enabled = vFlag; } else { VScroll->Enabled = vFlag; } } //--------------------------------------------------------------------------- // Reset the Chart to its default state //--------------------------------------------------------------------------- void __fastcall TfrmActions::cmdResetClick(TObject *Sender) { //The user wants to reset the Chart to its default state Chart2D1->CallAction(oc2dActionReset, 0, 0); ResetScrollBars(HScroll->Enabled, VScroll->Enabled); } //--------------------------------------------------------------------------- // Respond to a change of the Horizontal Scrollbar //--------------------------------------------------------------------------- void __fastcall TfrmActions::HScrollChange(TObject *Sender) { //Update the Chart based on the user Scrolling the Scrollbar HoldHScroll = HScroll->Position; HoldVScroll = VScroll->Position; if (HoldHScroll != HScrollValue) { Chart2D1->CallAction(oc2dActionModifyStart, HScrollValue, HoldVScroll); Chart2D1->CallAction(CurrentAction, HScrollValue, HoldVScroll); Chart2D1->CallAction(CurrentAction, HoldHScroll, HoldVScroll); Chart2D1->CallAction(oc2dActionModifyEnd, HoldHScroll, HoldVScroll); HScrollValue = HoldHScroll; } } //--------------------------------------------------------------------------- // Respond to a change of the Vertical Scrollbar //--------------------------------------------------------------------------- void __fastcall TfrmActions::VScrollChange(TObject *Sender) { //Update the Chart based on the user Scrolling the Scrollbar HoldHScroll = HScroll->Position; HoldVScroll = VScroll->Position; if (HoldVScroll != VScrollValue) { Chart2D1->CallAction(oc2dActionModifyStart, HoldHScroll, VScrollValue); Chart2D1->CallAction(CurrentAction, HoldHScroll, VScrollValue); Chart2D1->CallAction(CurrentAction, HoldHScroll, HoldVScroll); Chart2D1->CallAction(oc2dActionModifyEnd, HoldHScroll, HoldVScroll); VScrollValue = HoldVScroll; } } //--------------------------------------------------------------------------- // The user has selected the 'None' Radio Button //--------------------------------------------------------------------------- void __fastcall TfrmActions::rbNoneClick(TObject *Sender) { ClearEvents(); EnableDepthSetting(false); EnableZoomType(false); ResetScrollBars(false, false); CurrentAction = oc2dActionNone; } //--------------------------------------------------------------------------- // The user has selected the 'Move' Radio Button //--------------------------------------------------------------------------- void __fastcall TfrmActions::rbMoveClick(TObject *Sender) { if (rbMove->Checked) { ClearEvents(); Variant vActions = Chart2D1->ActionMaps; vActions.OleFunction("Add", WM_LBUTTONDOWN, 0, 0, oc2dActionModifyStart); vActions.OleFunction("Add", WM_MOUSEMOVE, MK_LBUTTON, 0, oc2dActionTranslate); vActions.OleFunction("Add", WM_LBUTTONUP, 0, 0, oc2dActionModifyEnd); EnableDepthSetting(false); EnableZoomType(false); ResetScrollBars(true, true); CurrentAction = oc2dActionTranslate; } } //--------------------------------------------------------------------------- // The user has selected the 'Scale' Radio Button //--------------------------------------------------------------------------- void __fastcall TfrmActions::rbScaleClick(TObject *Sender) { if (rbScale->Checked) { ClearEvents(); Variant vActions = Chart2D1->ActionMaps; vActions.OleFunction("Add", WM_LBUTTONDOWN, 0, 0, oc2dActionModifyStart); vActions.OleFunction("Add", WM_MOUSEMOVE, MK_LBUTTON, 0, oc2dActionScale); vActions.OleFunction("Add", WM_LBUTTONUP, 0, 0, oc2dActionModifyEnd); EnableDepthSetting(false); EnableZoomType(false); ResetScrollBars(false, true); CurrentAction = oc2dActionScale; } } //--------------------------------------------------------------------------- // The user has selected the 'Zoom' Radio Button //--------------------------------------------------------------------------- void __fastcall TfrmActions::rbZoomClick(TObject *Sender) { if (rbZoom->Checked) { ClearEvents(); Variant vActions = Chart2D1->ActionMaps; vActions.OleFunction("Add", WM_LBUTTONDOWN, 0, 0, oc2dActionZoomStart); vActions.OleFunction("Add", WM_MOUSEMOVE, MK_LBUTTON, 0, oc2dActionZoomUpdate); vActions.OleFunction("Add", WM_LBUTTONUP, 0, 0, oc2dActionZoomEnd); vActions.OleFunction("Add", WM_KEYDOWN, MK_LBUTTON, VK_ESCAPE, oc2dActionZoomCancel); EnableDepthSetting(false); EnableZoomType(true); ResetScrollBars(false, false); CurrentAction = oc2dActionZoomStart; } } //--------------------------------------------------------------------------- // The user has selected the 'Rotate' Radio Button //--------------------------------------------------------------------------- void __fastcall TfrmActions::rbRotateClick(TObject *Sender) { if (rbRotate->Checked) { ClearEvents(); Variant vActions = Chart2D1->ActionMaps; vActions.OleFunction("Add", WM_LBUTTONDOWN, 0, 0, oc2dActionModifyStart); vActions.OleFunction("Add", WM_MOUSEMOVE, MK_LBUTTON, 0, oc2dActionRotate); vActions.OleFunction("Add", WM_LBUTTONUP, 0, 0, oc2dActionModifyEnd); EnableDepthSetting(true); EnableZoomType(false); ResetScrollBars(true, true); CurrentAction = oc2dActionRotate; } } //--------------------------------------------------------------------------- // Limit the types of key presses allowed during the Depth entry process //--------------------------------------------------------------------------- void __fastcall TfrmActions::edDepthKeyPress(TObject *Sender, char &Key) { //Limit the entered keys to 0-9, tab, backspace and Enter if (((Key < '0') || (Key > '9')) && (Key != 8) && (Key != 9) && (Key != 13)) { Key = 0; } if (Key == 13) { Key = 0; cmdReset->SetFocus(); } } //--------------------------------------------------------------------------- // Validate the results of the Depth entry process //--------------------------------------------------------------------------- void __fastcall TfrmActions::edDepthExit(TObject *Sender) { //Validate the number entered, and adjust it if necessary int edValue; Variant vCArea = Chart2D1->ChartArea_; Variant vView3D = vCArea.OlePropertyGet("View3D"); edValue = edDepth->Text.ToInt(); if (edValue > 100) { vView3D.OlePropertySet("Depth", 100); edDepth->Text = "100"; edValue = 100; } if (edValue < 0) { vView3D.OlePropertySet("Depth", 0); edDepth->Text = "0"; edValue = 0; } vView3D.OlePropertySet("Depth", edValue); } //--------------------------------------------------------------------------- // Change the Zoom to Axis Zoom //--------------------------------------------------------------------------- void __fastcall TfrmActions::rbAxisClick(TObject *Sender) { Variant vActions = Chart2D1->ActionMaps; vActions.OleFunction("Remove", WM_LBUTTONUP, 0, 0); //oc2dActionZoomEnd vActions.OleFunction("Add", WM_LBUTTONUP, 0, 0, oc2dActionZoomAxisEnd); } //--------------------------------------------------------------------------- //Change the Graphic to Axis Zoom //--------------------------------------------------------------------------- void __fastcall TfrmActions::rbGraphicClick(TObject *Sender) { Variant vActions = Chart2D1->ActionMaps; vActions.OleFunction("Remove", WM_LBUTTONUP, 0, 0); //oc2dActionZoomEnd vActions.OleFunction("Add", WM_LBUTTONUP, 0, 0, oc2dActionZoomEnd); } //--------------------------------------------------------------------------- // Update the Chart with the new Depth Value //--------------------------------------------------------------------------- void __fastcall TfrmActions::udDepthChanging(TObject *Sender, bool &AllowChange) { Variant vCArea = Chart2D1->ChartArea_; Variant vView3D = vCArea.OlePropertyGet("View3D"); vView3D.OlePropertySet("Depth", udDepth->Position); } //--------------------------------------------------------------------------- // Show the 'About This Demo' Help Page //--------------------------------------------------------------------------- void __fastcall TfrmActions::mnuAboutThisDemoClick(TObject *Sender) { Application->HelpContext(20); } //--------------------------------------------------------------------------- // Show the 'About Olectra Chart' Help Page //--------------------------------------------------------------------------- void __fastcall TfrmActions::mnuAboutOlectraChartClick(TObject *Sender) { Application->HelpContext(19); } //---------------------------------------------------------------------------