GFXprim
2D bitmap graphics library with emphasis on speed and correctness
Loading...
Searching...
No Matches
Data Structures | Macros | 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...
 

Macros

#define GP_WIDGET_EVENT_DEFAULT_MASK
 Default widget event mask.
 

Enumerations

enum  gp_widget_event_type {
  GP_WIDGET_EVENT_NEW , GP_WIDGET_EVENT_FREE , GP_WIDGET_EVENT_WIDGET , GP_WIDGET_EVENT_INPUT ,
  GP_WIDGET_EVENT_REDRAW , GP_WIDGET_EVENT_RESIZE , GP_WIDGET_EVENT_COLOR_SCHEME , GP_WIDGET_EVENT_MAX
}
 Widget event type. More...
 

Functions

void gp_widget_event_mask (gp_widget *self, enum gp_widget_event_type ev_type)
 Masks widget events.
 
void gp_widget_event_unmask (gp_widget *self, enum gp_widget_event_type ev_type)
 Unmasks widget events.
 
const char * gp_widget_event_type_name (enum gp_widget_event_type ev_type)
 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 usually has 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 

Send right after widget has been allocated and initalized.

GP_WIDGET_EVENT_FREE 

Send before widget is freed.

GP_WIDGET_EVENT_WIDGET 

Widget specific event e.g. button has been pressed, details in sub_type

GP_WIDGET_EVENT_INPUT 

Raw user input event such as mouse movement or keypress.

GP_WIDGET_EVENT_REDRAW 

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

GP_WIDGET_EVENT_RESIZE 

Send when widget was resized.

GP_WIDGET_EVENT_COLOR_SCHEME 

Color scheme has changed

GP_WIDGET_EVENT_MAX 

The number of events, i.e. last event + 1.

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_mask()

void gp_widget_event_mask ( gp_widget *  self,
enum gp_widget_event_type  ev_type 
)

Masks widget events.

Disables widget events.

Parameters
selfThe widget
ev_typeEvent type to disable

◆ gp_widget_event_type_name()

const char * gp_widget_event_type_name ( enum gp_widget_event_type  ev_type)

Returns string name for a given event type.

Parameters
ev_typeWidget event type.
Returns
Widget event type name.

◆ gp_widget_event_unmask()

void gp_widget_event_unmask ( gp_widget *  self,
enum gp_widget_event_type  ev_type 
)

Unmasks widget events.

Enables widget events.

Parameters
selfThe widget
ev_typeEvent type 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_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 121 of file gp_widget_event.h.

References GP_WIDGET_EVENT_COLOR_SCHEME, GP_WIDGET_EVENT_INPUT, GP_WIDGET_EVENT_REDRAW, GP_WIDGET_EVENT_RESIZE, and gp_widget_event::self.

◆ 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 to the widget.

Parameters
selfPointer to the widget sending this event.
typeEvent type as defined by a particular widget.
Returns
The return value from application event handler.

Definition at line 163 of file gp_widget_event.h.

References GP_WIDGET_EVENT_WIDGET, and gp_widget_event::self.