SOL9 2.0 Class: Gadget

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

Source code

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


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

#include <sol\View.h>
#include <sol\DC.h>

#include <sol\Layoutable.h>


namespace SOL {

class Gadget :public Object, public Layoutable {
private:
    int    x;
    int    y;
    int    width;
    int    height;
    View*    parent;
    int    margin;

public:
    Gadget() { }
/*
    //Gadget(View* view, const TCHAR* label, Args& args);

    //~Gadget();
    
    virtual Boolean create(View* view, const TCHAR* label, Args& args);

    void    reshape(int x, int y, int width, int height);

    virtual void draw(DC* dc);

    virtual void draw(DC* dc, int x, int y);


    void    getRect(RECT* r);

    virtual void layout(int x, int y, int w, int h);

    void    setRect(RECT* r);
*/

public:
    Gadget(View* view, const TCHAR* label, Args& args)
    {
        parent  = view;
        x         = (int) args.get(XmNx);
        y         = (int) args.get(XmNy);
        width    = (int) args.get(XmNwidth);
        height    = (int) args.get(XmNheight);
    }


public:
    ~Gadget()
    {
    //
    }

public:
    virtual Boolean create(View* view, const TCHAR* label, Args& args)
    {
        Boolean rc = False;
        if (view) {
            rc = True;
        }
        parent  = view;
        x         = (int) args.get(XmNx);
        y         = (int) args.get(XmNy);
        width    = (int) args.get(XmNwidth);
        height    = (int) args.get(XmNheight);
        return rc;
    }


public:
    virtual void draw(DC* dc)
    {
        // Do nothing here.
    }

public:
    virtual void draw(DC* dc, int x, int y)
    {
        // Do nothing here.
    }


public:
    virtual void layout(int x, int y, int w, int h)
    {
        reshape(x, y, w, h);
    }


public:
    void reshape(int x1, int y1, int width1, int height1)
    {
        x     = x1;
        y     = y1;
        width    = width1;
        height    = height1;
        RECT r;
        ::SetRect(&r, x, y, width, height);
        if(parent) {
            parent -> update(&r);
        }    
    }


public:
    void getRect(RECT* r) 
    {
        r->left = x; 
        r->top  = y;
        r ->right  = x + width;
        r ->bottom = y + height;
    }


public:
    void setRect(RECT* r) 
    {
        x = r->left; 
        y = r->top;
        width  = r->right  - r->left;
        height = r->bottom - r->top;
    }


public:
    View*    getParent() { 
        return parent; 
    }

public:
    void    getLocation(int& x1, int& y1) {
            x1 = this->x;
            y1 = this->y;
    }

public:
    void    getSize(int& w, int& h) { 
        w = this->width; 
        h = this->height;
    }

public:
    void    setLocation(int x1, int y1) {
        this->x = x1;
        this->y = y1;
    }

public:
    void    setSize(int w, int h) { 
        this->width = w; 
        this->height = h;
    }

public:
    void    setMargin(int m) {
        this->margin = m;
    }

public:
    int        getMargin() {
        return this->margin;
    }

};

}


Last modified: 1 Feb 2012

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