
/*------------------1. Listing------------------------------------*/

#include <X11/Intrinsic.h>
#include <Xm/Xm.h>
#include <stdio.h>

#include <Xm/PushB.h>

void quit(widget, client, call)

Widget  widget;
caddr_t client;
caddr_t call;
{
        exit(1);
}


int main(argc, argv)

int     argc;
char**  argv;
{

        Widget          top, push;
        unsigned int    width, height, frame;
        int             x, y, count;
        Arg             arglist[5];

        top     = XtInitialize("my_world","MyWorld",NULL,NULL,&argc,argv);
        width   = 100;
        height  = 50;
        frame   = 5;
        x       = y = 0;
        count   = 0;


	/* Eigenschaften des Buttons spezifizieren */

        XtSetArg(arglist[count], XmNx, x);
        count++;
        XtSetArg(arglist[count], XmNy, y);
        count++;
        XtSetArg(arglist[count], XmNwidth, width);
        count++;
        XtSetArg(arglist[count], XmNheight, height);
        count++;
        XtSetArg(arglist[count], XmNborderWidth, frame);


	/* Button erzeugen, ActionCallback (quit) zuordnen */

        push    = XmCreatePushButton(top, "Hello World", arglist, count);
        XtAddCallback(push, XmNactivateCallback, quit, NULL);
        XtManageChild(push);

        XtRealizeWidget(top);
        XtMainLoop();
}



/*----------------------2. Listing---------------------------*/

#include <IV-look/kit.h>
#include <IV-look/button.h>

#include <InterViews/background.h>
#include <InterViews/margin.h>
#include <InterViews/window.h>
#include <InterViews/style.h>
#include <InterViews/session.h>


int main(int argc, char** argv){

        Session* session = new Session("my_world", argc, argv);

        // Verwenden des Default Styles und Kits (= Motif)
        //
        Style* style = session->style();
        Kit* kit = Kit::instance();

        Glyph* root_glyph = new Background(   // Hintergrund zeichnen
           new Margin(             // Rand zwischen Button und Window
               kit->simple_push_button("Hello World",style,kit->quit()),
               20
           ),
           style->background()
        );

        session->run_window(
           new ApplicationWindow(root_glyph)
	);
}


/*------------------3. Listing------------------------------------*/


#include "candle.h"
#include <InterViews/brush.h>
#include <InterViews/canvas.h>
#include <InterViews/color.h>
#include <InterViews/session.h>
#include <InterViews/display.h>
#include <InterViews/geometry.h>
#include <InterViews/transformer.h>

Candle::Candle()
{
	// set required space
	//
        const Requirement  rx( 80,200,40,0.5 );   // x= 80 (+200/-40)
        const Requirement  ry(150,200,40,0.6 );   // y=150 (+200/-40)

        req.require( Dimension_X, rx );
        req.require( Dimension_Y, ry );

        // get colors and brush
        //
        Display*        dsp = Session::instance()->default_display();

        brush = new Brush(2);                    brush->ref();
        yellow = Color::lookup( dsp, "yellow" ); yellow->ref();
        black = new Color(0,0,0);                black->ref();
        red = Color::lookup( dsp, "red" );       red->ref();

        ColorIntensity  r,g,b;
        red->intensities( dsp, r,g,b );
        r*=0.8; g*=0.8; b*=0.8;
        red2 = new Color(r,g,b);                 red2->ref();
}

Candle::~Candle()
{
        red->unref();
        red2->unref();
        yellow->unref();
        black->unref();
        brush->unref();
}
        
void Candle::request(Requisition& r) const { r = req; }

void Candle::allocate(Canvas*,const Allocation& a, Extension& e)
        { e.extend(a); }     // I need the full canvas area

void Candle::draw(Canvas* dest,  const Allocation& alloc) const
{
        Coord           x_begin= alloc.allotment(Dimension_X).begin();
        Coord           x_span = alloc.allotment(Dimension_X).span();
        Coord           y_begin= alloc.allotment(Dimension_Y).begin();
        Coord           y_span = alloc.allotment(Dimension_Y).span();

        // my own space is (-25..25, -50..50)
        // .. translate (0,0) to the center of allocated canvas area
        //
        Transformer     trans;      // 1:1
        trans.translate( x_begin+x_span/2, y_begin+y_span/2 );

        dest -> push_transform();
        dest -> transform(trans);

        // I set my clipping rectangle depending on allocated canvas area
        // ... simply by "inverse translating" canvas coordinates.
        //
        Coord   left, right, lower, upper;

        trans.inverse_transform( x_begin,       y_begin,       left, lower );
        trans.inverse_transform( x_begin+x_span,y_begin+y_span,right,upper );

        dest -> push_clipping();
        dest -> clip_rect( left, lower, right, upper );

        // here I draw the candle
        //
        dest -> new_path();
        dest -> move_to( -15,-50 );
        dest -> curve_to( -19,-3, -15,-40, -15,-10  );  // up
        dest -> curve_to(  16,0,   -8,-10,  16,-5   );  // right
        dest -> curve_to(  15,-50,  16,-10,  16,-40 );  // down
        dest -> curve_to( -15,-50,   8,-56,  -8,-56 );  // left
        dest -> close_path();
        dest -> fill( red );

        dest -> new_path();
        dest -> move_to( -19,-3 );
        dest -> curve_to(  16,0,   -8,-10,  16,-5   );  // right
        dest -> curve_to( -19,-3,  16,5,    -8,0    );  // left
        dest -> close_path();
        dest -> fill( red2 );

        dest -> new_path();
        dest -> move_to( 1,7 );
        dest -> curve_to(  6,37,  -11,12,    1,22   );  // up
        dest -> curve_to(  3,4,    12,24,    18,11  );  // down
        dest -> close_path();
        dest -> fill( yellow );

        dest -> new_path();
        dest -> move_to( 0,-3 );
        dest -> curve_to( 5,17,    0,5,   3,13   );     // up-right
        dest -> stroke( black, brush );

        // re-install the old transformer and old clipping rectangle
        //
        dest -> pop_clipping();
        dest -> pop_transform();
}
/*---------------------Headerdatei-----------------------------*/



#include <InterViews/glyph.h>

class Requisition;
class Allocation;
class Extension;
class Canvas;
class Color;
class Brush;

class Candle: public Glyph {
private:
        Requisition     req;
        const Color     *red, *red2, *yellow, *black;
        const Brush     *brush;
public:
        Candle();
        ~Candle();
        void    request(Requisition&) const;
        void    allocate(Canvas*,const Allocation&, Extension&);
        void    draw(Canvas*, const Allocation&) const;
};
