Colour Swatches

Introduction and Overview

A colour swatch is a gadget used to display an example colour and allow the user to select another :

The Colour Swatch gadget
The Colour Swatch gadget

The colour swatch can display any 24bit RGB colour or a 'None' value. The gadget requires the Wimp 3.98 or later to function correctly.

A colour swatch has a pop-up colour menu placed 8 OS Units to the right of the display area. The display area will show the currently selected colour as its filled background. On selecting the pop-up menu icon, a ColourDBox will be displayed, allowing the selection of another colour. Once a selection has been made and confirmed, the display will be updated and a notification message sent to the application.

The application can decide whether a 'None' option is available on the colour selector. If the 'None' option is available and selected, the display icon will show the text 'None' and the user will be notified of this. Where possible, the interface has been kept similar to that of the ColourDBox.

Bits in the flags word for a colour swatch gadget have the following meanings:

Bit(s)Meaning
0Reserved, must be zero
2when set, include a None button in the dialogue box
3when set, select the None button when the dialogue box is created
4-31Reserved, must be zero

Colour Swatch templates

FieldSize in bytesType
colour4word
title4MsgReference

Toolbox methods

ColourSwatch_GetColourMethod &1403000
Read the colour of the Colour Swatch gadget
R0=flags
R1=Window object id
R2=&1403000
R3=Gadget component id
R0=Whether the 'None' option is selected :
ValueMeaning
0'None' is not selected
1'None' is selected
R1=Colour number in the form &BBGGRR00
R2 - R9preserved

This method is used to read the colour currently in use by the ColourSwatch gadget.

extern _kernel_oserror *colourswatch_get_colour ( unsigned int flags,
ObjectId window,
ComponentId swatch,
int *outflags,
unsigned long *colour
);
ColourSwatch_SetColourMethod &1403001
Set the colour of the Colour Swatch gadget
R0=flags :
Bit(s)Meaning
0Select the 'None' option
R1=Window object id
R2=&1403001
R3=Gadget component id
R4=Colour number in the form &BBGGRR00
R0 - R9preserved

This method is used to change the colour currently in use by the ColourSwatch gadget.

extern _kernel_oserror *colourswatch_set_colour ( unsigned int flags,
ObjectId window,
ComponentId swatch,
unsigned long colour
);
ColourSwatch_GetTitleMethod &1403002
Read the title of the colour selector used by the Colour Swatch gadget
R0=flags
R1=Window object id
R2=&1403002
R3=Gadget component id
R4=pointer to buffer
R5=size of buffer
R5=size of buffer required (if R4 was 0)
else buffer pointed at by R4 contains text
R5 holds number of bytes written to buffer

This method is used to read the title used on the ColourPicker dialogue which is displayed when the pop-up menu icon is selected.

extern _kernel_oserror *colourswatch_get_title ( unsigned int flags,
ObjectId window,
ComponentId swatch,
char *buffer,
int buff_size,
int *nbytes
);
ColourSwatch_SetTitleMethod &1403003
Change the title of the colour selector used by the Colour Swatch gadget
R0=flags
R1=Window object id
R2=&1403003
R3=Gadget component id
R4=pointer to string to use
None

This method is used to change the title used on the ColourPicker dialogue which is displayed when the pop-up menu icon is selected. Any active ColourPicker for this gadget will be closed when this method is used.

extern _kernel_oserror *colourswatch_set_title ( unsigned int flags,
ObjectId window,
ComponentId swatch,
char *title
);
ColourSwatch_GetNoneAvailableMethod &1403004
Read whether the 'None' option is available on the colour selector used by the ColourSwatch
R0=flags
R1=Window object id
R2=&1403004
R3=Gadget component id
R0=flags:
Bit(s)Meaning
0None is available

This method returns whether the None option appears in a colour selector window used when the pop-up menu is selected.

extern _kernel_oserror *colourswatch_get_none_available ( unsigned int flags,
ObjectId window,
ComponentId swatch,
int *out_flags
);
ColourSwatch_SetNoneAvailableMethod &1403005
Set whether the 'None' option is available on the colour window
R0=flags
R1=Window object id
R2=&1403005
R3=Gadget component id
R4=non-zero means None is available
R1 - RR9preserved

This method sets whether a None option appears in the colour selector displayed when .

extern _kernel_oserror *colourswatch_set_none_available ( unsigned int flags,
ObjectId window,
ComponentId swatch,
int none
);

Toolbox events

ColourSwatch_ColourChangedEvent &140300
Notification that the colour of the ColourSwatch has been changed
OffsetContents
8&140300
12flags :
Bit(s)Meaning
0the 'None' option was selected
16colour in the form &BBGGRR00

This Toolbox event is raised when the colour of the ColourSwatch has changed. If the 'None' option was available and selected, then bit 0 of the flags word is set.

typedef struct
{
ToolboxEventHeader hdr;
int new_colour;
} ColourSwatchColourChangedEvent;