SOL9 2.0 Class: DrawnButton

 SOL9 C++ Class Library  SOL9 Samples  SOL9 Tutorial  SOL9 FAQ  SOL9 ClassTree 

Source code

/*
 * DrawnButton.h 
 * Copyright (c) 2011 Antillia.com TOSHIYUKI ARAI. ALL RIGHTS RESERVED. 
 */


// SOL++2000
// 2000.02.18
#pragma once

#include <sol\Label.h>


namespace SOL {

class DrawnButton :public Label {
private:
    int          capturing;

protected:
    long leftButtonDown(Event& event)
    {
        capture();    

        capturing = TRUE;
        if(capturing == TRUE) {
            callCallback(XmNarmCallback, (Key)getWindow(), this, event);
        }
        return NULL;
    }


    long mouseMove(Event& event)
    {
        POINT p;

        RECT r;

        ::GetCursorPos(&p);
        ::GetWindowRect(getWindow(), &r);

        if(capturing == TRUE && ((p.x < r.left) || 
            (p.y < r.top) || (p.x > r.right) || (p.y > r.bottom))) {
            releaseCapture();
            capturing = FALSE;
        }
        return NULL;
    }

    long leftButtonUp(Event& event)
    {
        if(capturing == TRUE) {
            callCallback(XmNactivateCallback, 
                (Key)getWindow(), this, event);
            releaseCapture();
        }
        capturing = FALSE;
        return NULL;
    }


public:

    DrawnButton():Label() { }

public:
    DrawnButton(View* parent, const TCHAR* label, Args& args)
    :Label(parent, label, args)
    {
        addEventHandler(WM_LBUTTONDOWN, this,
            (Handler)&DrawnButton::leftButtonDown, NULL);
        addEventHandler(WM_MOUSEMOVE, this,
            (Handler)&DrawnButton::mouseMove, NULL);
        addEventHandler(WM_LBUTTONUP, this,
            (Handler)&DrawnButton::leftButtonUp, NULL);
    }


public:
    virtual Boolean create(View* parent, const TCHAR* label, Args& args)
    {    
        Boolean rc = False;
        rc = Label::create(parent, label, args);

        addEventHandler(WM_LBUTTONDOWN, this,
            (Handler)&DrawnButton::leftButtonDown, NULL);
        addEventHandler(WM_MOUSEMOVE, this,
            (Handler)&DrawnButton::mouseMove, NULL);
        addEventHandler(WM_LBUTTONUP, this,
            (Handler)&DrawnButton::leftButtonUp, NULL);
        return rc;
    }


public:
    void addCallback(const TCHAR* name, Object* object,
            Callback callback, void* data)
    {
        View::addCallback(name, (Key)getWindow(), object, 
            callback, data);
    }

};

}



Last modified: 1 Feb 2012

Copyright (c) 2009-2012 Antillia.com ALL RIGHTS RESERVED.