Displaying more information

The OnChartEvent callback returns a number of parameters. I wrote another small utility class to display the details of these parameters.

struct ChartEvent
{
    static string ToString(int id)
    {
        switch (id)
        {
            case CHARTEVENT_KEYDOWN:       return "keystroke";
            case CHARTEVENT_MOUSE_MOVE:    return "mouse event (move or click)";
            case CHARTEVENT_OBJECT_CREATE: return "graphical object creation";
            case CHARTEVENT_OBJECT_CHANGE: return "object property change via the properties dialog";
            case CHARTEVENT_OBJECT_DELETE: return "graphical object deletion";
            case CHARTEVENT_CLICK:         return "mouse click";
            case CHARTEVENT_OBJECT_CLICK:  return "graphical object mouse click";
            case CHARTEVENT_OBJECT_DRAG:   return "graphical object mouse drag";
            case CHARTEVENT_OBJECT_ENDEDIT:return "text box entry complete";
            case CHARTEVENT_CHART_CHANGE:  return "chart change";
            case CHARTEVENT_CUSTOM_LAST:   return "custom id max";
            default:                       return "custom id " + IntegerToString(id);
        }
        return "unknown";
    }
    
    static string DisplayInfo(int id, long l, double d, const string& s)
    {
        string ret = ToString(id) + " ";
        switch (id)
        {
            case CHARTEVENT_KEYDOWN:       ret += KeyEvent(l);                   break;
            case CHARTEVENT_MOUSE_MOVE:    ret += MouseMove(l,(long)d,s);        break;
            case CHARTEVENT_OBJECT_CREATE: ret += ObjectCreated(s);              break;
            case CHARTEVENT_OBJECT_CHANGE: ret += ObjectChanged(s);              break;
            case CHARTEVENT_OBJECT_DELETE: ret += ObjectDeleted(s);              break;
            case CHARTEVENT_CLICK:         ret += ChartClick(l,(long)d);         break;
            case CHARTEVENT_OBJECT_CLICK:  ret += ChartObjectClick(l,(long)d,s); break;
            case CHARTEVENT_OBJECT_DRAG:   ret += ObjectDragged(s);              break;
            case CHARTEVENT_OBJECT_ENDEDIT:ret += ObjectEndEdit(s);              break;
            case CHARTEVENT_CHART_CHANGE:                                        break;
            case CHARTEVENT_CUSTOM_LAST:                                         break;
            default:                                                             break;
        }
        return ret;
    }
    
    static string KeyEvent(long l)
    {
        return "key_code=" + IntegerToString(l);
    }
    
    static string MouseMove(long x, long y, const string& s)
    {
        return "x=" + IntegerToString(x) + ", y=" + IntegerToString(y) + ", status=" + s;
    }
    
    static string ObjectCreated(const string& s)
    {
        return "object=" + s;
    }
    
    static string ObjectChanged(const string& s)
    {
        return "object=" + s;
    }
    
    static string ObjectDeleted(const string& s)
    {
        return "object=" + s;
    }
    
    static string ChartClick(long x, long y)
    {
        return "x=" + IntegerToString(x) + ", y=" + IntegerToString(y);
    }
    
    static string ChartObjectClick(long x, long y, const string& s)
    {
        return "x=" + IntegerToString(x) + ", y=" + IntegerToString(y) + ", object=" + s;
    }
    
    static string ObjectDragged(const string& s)
    {
        return "object=" + s;
    }
    
    static string ObjectEndEdit(const string& s)
    {
        return "object=" + s;
    }
};        

I then display the details information in my callback:

void OnChartEvent(const int     id, // Event ID
                  const long&   l,  // Parameter of type long event
                  const double& d,  // Parameter of type double event
                  const string& s)  // Parameter of type string event
{
    Print(__FUNCTION__ + " " + ChartEvent::DisplayInfo(id, l, d, s));
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s