GFXprim
2D bitmap graphics library with emphasis on speed and correctness
Loading...
Searching...
No Matches
Data Structures | Enumerations | Functions
gp_widget_event.h File Reference

Widget event handling. More...

#include <stdarg.h>
#include <widgets/gp_widget_types.h>

Go to the source code of this file.

Data Structures

struct  gp_widget_event
 Event structure passed to widget event handler. More...
 

Enumerations

enum  gp_widget_event_type {
  GP_WIDGET_EVENT_NEW = 0x01 , GP_WIDGET_EVENT_FREE = 0x02 , GP_WIDGET_EVENT_WIDGET = 0x04 , GP_WIDGET_EVENT_INPUT = 0x08 ,
  GP_WIDGET_EVENT_REDRAW = 0x10 , GP_WIDGET_EVENT_RESIZE = 0x20 , GP_WIDGET_EVENT_COLOR_SCHEME = 0x40 , GP_WIDGET_EVENT_DEFAULT_MASK = GP_WIDGET_EVENT_NEW | GP_WIDGET_EVENT_FREE | GP_WIDGET_EVENT_WIDGET
}
 Widget event type. More...
 

Functions

void gp_widget_on_event_set (gp_widget *self, int(*on_event)(gp_widget_event *), void *priv)
 Sets a widget event handler.
 
void gp_widget_events_mask (gp_widget *self, enum gp_widget_event_type evs)
 Masks widget event.
 
void gp_widget_events_unmask (gp_widget *self, enum gp_widget_event_type evs)
 Unmasks widget event.
 
const char * gp_widget_event_type_name (enum gp_widget_event_type ev)
 Returns string name for a given event type.
 
void gp_widget_event_dump (gp_widget_event *ev)
 Prints event details into stdout.
 
static int gp_widget_send_event (gp_widget *self, enum gp_widget_event_type type,...)
 Helper function to send a widget library event to application.
 
static int gp_widget_send_widget_event (gp_widget *self, unsigned int sub_type,...)
 Helper function to send a widget specific event to application.
 
int gp_widget_input_inject (gp_widget *self, gp_widget_event *ev)
 A helper function to inject key and utf input events to a widget.
 

Detailed Description

Widget event handling.

Widget events is an interface between the application and the widget toolkit, typical event is a button press or a text edit. Each widget can have only one event callback and sends a subset of event types.

Definition in file gp_widget_event.h.

Enumeration Type Documentation

◆ gp_widget_event_type

Widget event type.

We have 32bit mask so the maximal number of possible events is 32.

Enumerator
GP_WIDGET_EVENT_NEW 

Widget was created and initialized.

This event is send right after widget has been allocated and initalized in the JSON parser. The intended purpose is to be able to be able to check parameters or finish initialization of widgets loaded from a JSON layout.

GP_WIDGET_EVENT_FREE 

Widget is about to be freed.

See gp_widget_free() for details.

GP_WIDGET_EVENT_WIDGET 

Widget specific event.

E.g. button has been pressed, each widget defines its enum of events and these are passed in the gp_widget_event::sub_type.

GP_WIDGET_EVENT_INPUT 

An input event.

Raw gp_event input event such as mouse movement or keypress.

Attention
The gp_event::st cursor position is normalized so that 0,0 is top left corner of the widget.

The event handler must return non-zero if the event was used and non-zero otherwise.

GP_WIDGET_EVENT_REDRAW 

Pixmap redraw event.

TODO: Move to pixmap specific event?

Send by pixmap widget when pixmap has has to be redrawn.

GP_WIDGET_EVENT_RESIZE 

Widget was resized.

Send when widget was resized.

GP_WIDGET_EVENT_COLOR_SCHEME 

A color scheme has changed.

See gp_widgets_color_scheme and gp_widgets_color_scheme_set() for details.

GP_WIDGET_EVENT_DEFAULT_MASK 

Default widget event mask.

This is the default mask for newly created widgets.

Definition at line 29 of file gp_widget_event.h.

Function Documentation

◆ gp_widget_event_dump()

void gp_widget_event_dump ( gp_widget_event ev)

Prints event details into stdout.

Parameters
evPointer to a widget event.

◆ gp_widget_event_type_name()

const char * gp_widget_event_type_name ( enum gp_widget_event_type  ev)

Returns string name for a given event type.

Parameters
evWidget event type.
Returns
Widget event type name.

◆ gp_widget_events_mask()

void gp_widget_events_mask ( gp_widget self,
enum gp_widget_event_type  evs 
)

Masks widget event.

Disables a widget event(s).

Parameters
selfA widget.
evsA bitmask of events to disable.

◆ gp_widget_events_unmask()

void gp_widget_events_unmask ( gp_widget self,
enum gp_widget_event_type  evs 
)

Unmasks widget event.

Enables a widget event(s).

Parameters
selfA widget.
evsA bitmask of events to enable.

◆ gp_widget_input_inject()

int gp_widget_input_inject ( gp_widget self,
gp_widget_event ev 
)

A helper function to inject key and utf input events to a widget.

Internal function used in widget tests.

This function takes a widget event and if the event type is GP_WIDGET_EVENT_INPUT the input event is injected to the widget input event handler, i.e. the widget will get the input as if it was focused.

This of course works only for key presses and unicode input events as relative or absolute coordinates are normalized as events pass down the widget tree, i.e. for any event widget receives the widget top level corner has coordinate [0,0]. Hence these kinds of events are not injected.

Parameters
selfA widget to inject the input event to.
evA widget event.
Returns
Non-zero if the event was handled, zero otherwise.

◆ gp_widget_on_event_set()

void gp_widget_on_event_set ( gp_widget self,
int(*)(gp_widget_event *)  on_event,
void *  priv 
)

Sets a widget event handler.

Note that even after setting event handler certain widget events has to be unmasked with gp_widget_event_unmask() in order to receive them.

Parameters
selfA widget.
on_eventAn widget event handler.
privAn user pointer stored in the widget.

Referenced by gp_widget_button_new2(), and gp_widget_checkbox_new2().

◆ gp_widget_send_event()

static int gp_widget_send_event ( gp_widget self,
enum gp_widget_event_type  type,
  ... 
)
inlinestatic

Helper function to send a widget library event to application.

This is called by the widget library when event should be send to the widget.

Parameters
selfPointer to the widget sending this event.
typeEvent type see gp_widget_event_type enum.
Returns
The return value from application event handler.

Definition at line 205 of file gp_widget_event.h.

References gp_widget::event_mask, GP_WIDGET_EVENT_COLOR_SCHEME, GP_WIDGET_EVENT_INPUT, GP_WIDGET_EVENT_REDRAW, GP_WIDGET_EVENT_RESIZE, gp_widget::on_event, gp_widget_event::self, gp_event::type, and gp_widget::type.

◆ gp_widget_send_widget_event()

static int gp_widget_send_widget_event ( gp_widget self,
unsigned int  sub_type,
  ... 
)
inlinestatic

Helper function to send a widget specific event to application.

This is called by the widget library when event should be send from a widget to the application. This function fills in the gp_widget_event structure and then calls the gp_widget::on_event() function.

Parameters
selfPointer to the widget sending this event.
sub_typeEvent subtype as defined by a particular widget e.g. gp_widget_tbox_event_type.
...An optional pointer or long integer value.
Returns
The return value from application event handler.

Definition at line 252 of file gp_widget_event.h.

References GP_WIDGET_EVENT_WIDGET, gp_widget::on_event, gp_widget_event::self, and gp_widget::type.