Aug 05 2006

On the road again

Categories: Life, Work

Well, this is shaping up to be a hectic week. I’m heading over to Waterloo in a few hours for my bachelour party. Which, knowing my friends could be interesting so we’ll see how that goes.

I’m going to have to fight them tooth and nail to keep from getting really drunk as I have to catch a plan on Sunday at 1730hrs to fly to Ohio for work.

I’ll be spending the week in Ohio doing various Solaris 10ie things which should be fun. Playing with processor sets, zones maybe some DTrace, we’ll have to see.

I then fly back at 1035hr on Friday, jump in a rental car (probably not till around 1500 or 1600hrs) and drive to Fergus to hopefully catch the Tattoo at the highland games, and maybe look at some of the kilts and other cool shit their usually selling. Then back in the car and on up to Owen Sound as Stacy has a hair apointment at 0800hrs on Saturday to try out the person that’s doing her hair for the wedding.

Afterwhich one of my moms sisters is throwing her a bridal shower. Then on Sunday is a Sinclair family picnic / happy engagement celebration somewhere.

At which point I can drive back to Toronto and passout from exhaustion.

Anyway, if you don’t see me around me it’s because I’m out and about, passed out from the demon alcohol or passed out from exhaustion.

Later.


Aug 02 2006

Small as small can be

Categories: Programming
Tags: ,

What’s the minimum amount of work you need to do to create your own EWL widget? Just want something you can build on but don’t know where to start?

Well, hopefully this should give you the base for starting your widget. Assuming you’re creating a widget called My_Widget, the EWL convention is to have a my_widget.c and my_widget.h files. There are only a couple things you need to implement to get a working widget.

First, my_widget.h.

    #ifndef MY_WIDGET_H
    #define MY_WIDGET_H

    #include 

    #define MY_WIDGET(w) ((My_Widget *)w)
    #define MY_WIDGET_TYPE "my_widget"

    typedef struct My_Widget My_Widget;
    struct My_Widget
    {
        Ewl_Widget widget;
    };

    Ewl_Widget *my_widget_new(void);
    int my_widget_init(My_Widget *w);

    #endif

That wasn’t so bad. What have we got? Well, the MY_WIDGET(w) define gives us a simple macro to cast other widgets to our widget. The second define, MY_WIDGET_TYPE, is a simple macro containing the type name of the widget. We’ll use that a bit later (and in any type checking we add to our widget.)

We then create the widget structure. In this case we’re inheriting from Ewl_Widget so it’s the first item in our struct (and not a pointer, that’s important). This is how EWLs inhertiance works. The widget you’re inheriting from is the first item in the struct and not a pointer. You will now be able to call any of the methods of the inherited class on the new class.

We then declare two methods. The convention in EWL is that the _new() function always takes no parameters (void). There is also always a _init() function that takes the widget as its only parameter and returns an int, if the initialization succeeded or failed.

With that out of the way, lets take a look at my_widget.c.

    #include "my_widget.h"

    Ewl_Widget *
    my_widget_new(void)
    {
        Ewl_Widget *w;

        w = calloc(1, sizeof(My_Widget)));
        if (!w) return NULL;

        if (!my_widget_init(MY_WIDGET(w)))
        {
                free(w);
                return NULL;
        }
        return w;
    }

    int
    my_widget_init(My_Widget *w)
    {
         if (!ewl_widget_init(EWL_WIDGET(w)))
                return 0;

        ewl_widget_appearance_set(EWL_WIDGET(w), MY_WIDGET_TYPE);
        ewl_widget_inherit(EWL_WIDGET(w), MY_WIDGET_TYPE);

        return 1;
    }

That’s pretty simple. We create a new widget, initialize it and thats about it. In my_widget_init() we make sure we call ewl_widget_init() as that’s the widget we are inheriting from and we then set our inheritance and appearance strings (notice the use of our type define from earlier).

With that you’ve got a simple widget. It doesn’t do much, but it exists. Build on as you will.


« Previous Page