/***************************************************************************** * * 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. */ #ifndef STRICT #define STRICT #endif #include #include #include "olch2d.h" #include "flashlbl.h" #define MAXFLOATSTRLEN 13 /* Max length of an object of type float when represented as a string. */ #define BLACK ((COLORREF)0x00000000) #define WHITE ((COLORREF)0x00FFFFFF) static XrtTextHandle FlashLabel; static int Set; static int Pt; static HXRT2D Creator; void DisplayFlashLabel(HXRT2D hChart,int set,int pt); void RemoveFlashLabel(); BOOL FlashLabelOn(); /***************************************************************************************************************************/ void DisplayFlashLabel(HXRT2D hChart,int set,int pt){ XrtDataHandle hXrtData; char str[MAXFLOATSTRLEN + 2]; /* $ sign + max length of a float represented as a string + terminator. */ char* strs[] = {str,NULL}; /* We need only one line for a flash label. */ XrtPickResult pick; HFONT font; /* If we have a flash label up, but it's not for this point turn it off. */ if(FlashLabel && (pt != Pt || set != Set || hChart != Creator)) RemoveFlashLabel(); /* If we have no flash label up for this point, put one up. */ if(!FlashLabel){ /* Attach by pixel so not clipped on graph area. Find the pixel coords of the data point. */ XrtUnpick(hChart,XRT_DATASET1,set,pt,&pick); if(pick.pix_x == -1 || pick.pix_y == -1) return; /* Construct the text in the form "$1234.56". */ XrtGetValues( hChart, XRT_DATA, &hXrtData, NULL); if(!hXrtData || set > XrtDataGetLastSet(hXrtData) || pt > XrtDataGetLastPoint(hXrtData, set)) { return; } sprintf(str,"$%.2f", XrtDataGetYElement(hXrtData, set, pt)); if(!(font = CreateFont(-12,0,0,0,0,0,0,0,0,0,0,0,0,NULL))){ MessageBox(NULL,"Unable to create font.","CashFlow - CreateFlashLabels()",MB_OK|MB_ICONEXCLAMATION); return; } /* Create (and show) the text area. */ if(!(FlashLabel = XrtTextAreaCreate(hChart))){ DeleteObject(font); return; } XrtTextAreaSetValues(FlashLabel, XRT_TEXT_ANCHOR, XRT_ANCHOR_NORTHEAST, XRT_TEXT_ATTACH_PIXEL_X, pick.pix_x, XRT_TEXT_ATTACH_PIXEL_Y, pick.pix_y, XRT_TEXT_OFFSET, 0, XRT_TEXT_IS_CONNECTED, FALSE, XRT_TEXT_ATTACH_TYPE, XRT_TEXT_ATTACH_PIXEL, XRT_TEXT_ADJUST, XRT_ADJUST_CENTER, XRT_TEXT_BACKGROUND_COLOR, RGB(0xCC,0xCC,0xFF), XRT_TEXT_FOREGROUND_COLOR, BLACK, XRT_TEXT_BORDER, XRT_BORDER_SHADOW, XRT_TEXT_BORDER_WIDTH, 4, #if defined(STRICT) && defined( _WIN16) XRT_TEXT_FONT, (WORD)font, #else XRT_TEXT_FONT, font, #endif XRT_TEXT_STRINGS, strs, XRT_TEXT_IS_SHOWING, TRUE, NULL); DeleteObject(font); /* Save new state. */ Set = set; Pt = pt; Creator = hChart; } } /***************************************************************************************************************************/ void RemoveFlashLabel(){ if(FlashLabel){ XrtTextAreaDestroy(FlashLabel); FlashLabel = NULL; } } /***************************************************************************************************************************/ BOOL FlashLabelOn(){ return FlashLabel ? TRUE : FALSE; } /***************************************************************************************************************************/