toolbox-programming with oslib

David J. Ruck druck at freeuk.com
Wed Oct 18 20:53:38 BST 2000


On 13 Oct 2000 "Jonathan Coxhead" <jonathan at doves.demon.co.uk> wrote:
> On 12 Oct 00, Tony van der Hoff wrote,
>  | The problem is that the dcs_obj and colourdbox_obj
>  | structures are not the entire template, but only the object-specific
>  | part. The toolbox requires a standard header to be prepended to make a
>  | complete template. Unfortunately, oslib currently does not appear to
>  | define such structures pre-built, so you have to fiddle around with your
>  | own.
> 
>    The reason it doesn't is precisely the same reason that we discussed a 
> while ago regarding the same situation for message types: it's better 
> design if the "base part" is included in only 1 place (wimp.h for messages, 
> toolbox.h for templates), and everything else extends it.

I've just ported a application which used a mixture of OSLib and tboxlibs
to pure OSLib, and I'be been bitten by the lacking of OSLib in this ara.
I needed to change sprite area of a toolbox window. I've ended up having
to define the following.

    typedef struct
    {
      toolbox_class       object_class;
      int                 flags;
      int                 version;
      char                name[MAX_OBJECT_NAME];
      int                 total_size;
      void                *body;
      int                 body_size;
    } toolbox_object_header;

    typedef struct
    {
        unsigned int            flags;
        char                    *help_message;
        int                     max_help;
        char                    *pointer_shape;
        int                     max_pointer_shape;
        int                     pointer_x_hot;
        int                     pointer_y_hot;
        char                    *menu;
        int                     num_keyboard_shortcuts;
        keyboardshortcut_object *keyboard_shortcuts;
        int                     num_gadgets;
        gadget_object           *gadgets;
        toolbox_c               default_focus;
        int                     show_event;
        int                     hide_event;
        char                    *toolbar_ibl;
        char                    *toolbar_itl;
        char                    *toolbar_ebl;
        char                    *toolbar_etl;
        wimp_window             window;
    } window_template;


And then use them as follows:-

    toolbox_object_header *object_header;
    window_template       *wtemplate;
    
    E_CHECK_ABORT(xtoolbox_template_look_up(0, "Main",
                                            (toolbox_id*)&object_header));

    wtemplate                     = (window_template)object_header->body;
    wtemplate->window.sprite_area = h->sprite_area;

    /* Main window initialisation */
    E_CHECK_ABORT(xtoolbox_create_object(toolbox_CREATE_GIVEN_OBJECT,
                                         (toolbox_id)object_header,
                                         &h->main_id));

The last call also could do with a specific type safe function when using
an object header.

While I'm at it i've also noticed a nane anomally in stringset.h

   xstringsetsetselected_string
   stringsetsetselected_string
   xstringsetsetselected_index
   stringsetsetselected_index
   xstringsetgetselected_index
   
shouldn't all these have an underscore after stringset? All the others do.

Cheers
---Dave

-- 
____________________________________________________________________________

  David J. Ruck    Phone: +44- (0)7974 108301    Email: druck at freeuk.com
____________________________________________________________________________




More information about the oslib-user mailing list