2016-10-08 12:57:59 -04:00
|
|
|
#include <glib.h>
|
|
|
|
#include "widgets/widget.h"
|
2016-10-09 04:13:15 -04:00
|
|
|
#include "widgets/widget-internal.h"
|
2016-10-08 12:57:59 -04:00
|
|
|
|
|
|
|
int widget_intersect ( const widget *widget, int x, int y )
|
|
|
|
{
|
|
|
|
if ( widget == NULL ) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( x >= ( widget->x ) && x < ( widget->x + widget->w ) ) {
|
|
|
|
if ( y >= ( widget->y ) && y < ( widget->y + widget->h ) ) {
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void widget_resize ( widget *widget, short w, short h )
|
|
|
|
{
|
|
|
|
if ( widget != NULL ) {
|
|
|
|
if ( widget->resize != NULL ) {
|
|
|
|
widget->resize ( widget, w, h );
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
widget->w = w;
|
|
|
|
widget->h = h;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void widget_move ( widget *widget, short x, short y )
|
|
|
|
{
|
|
|
|
if ( widget != NULL ) {
|
|
|
|
widget->x = x;
|
|
|
|
widget->y = y;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean widget_enabled ( widget *widget )
|
|
|
|
{
|
|
|
|
if ( widget != NULL ) {
|
|
|
|
return widget->enabled;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void widget_enable ( widget *widget )
|
|
|
|
{
|
|
|
|
if ( widget && !widget->enabled ) {
|
|
|
|
widget->enabled = TRUE;
|
|
|
|
widget_update ( widget );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void widget_disable ( widget *widget )
|
|
|
|
{
|
|
|
|
if ( widget && widget->enabled ) {
|
|
|
|
widget->enabled = FALSE;
|
|
|
|
widget_update ( widget );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void widget_draw ( widget *widget, cairo_t *d )
|
|
|
|
{
|
|
|
|
// Check if enabled and if draw is implemented.
|
|
|
|
if ( widget && widget->enabled && widget->draw ) {
|
|
|
|
widget->draw ( widget, d );
|
|
|
|
widget->need_redraw = FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void widget_free ( widget *widget )
|
|
|
|
{
|
2016-10-13 11:54:52 -04:00
|
|
|
if ( widget && widget->free ) {
|
2016-10-08 12:57:59 -04:00
|
|
|
widget->free ( widget );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int widget_get_height ( widget *widget )
|
|
|
|
{
|
|
|
|
if ( widget ) {
|
|
|
|
if ( widget->get_height ) {
|
|
|
|
return widget->get_height ( widget );
|
|
|
|
}
|
|
|
|
return widget->h;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
int widget_get_width ( widget *widget )
|
|
|
|
{
|
|
|
|
if ( widget ) {
|
|
|
|
if ( widget->get_width ) {
|
|
|
|
return widget->get_width ( widget );
|
|
|
|
}
|
|
|
|
return widget->w;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2016-10-17 12:21:03 -04:00
|
|
|
int widget_get_x_pos ( widget *widget )
|
|
|
|
{
|
|
|
|
if ( widget ) {
|
|
|
|
return widget->x;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
int widget_get_y_pos ( widget *widget )
|
|
|
|
{
|
|
|
|
if ( widget ) {
|
|
|
|
return widget->y;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2016-10-08 12:57:59 -04:00
|
|
|
|
|
|
|
void widget_update ( widget *widget )
|
|
|
|
{
|
|
|
|
// When (desired )size of widget changes.
|
|
|
|
if ( widget ) {
|
|
|
|
if ( widget->update ) {
|
|
|
|
widget->update ( widget );
|
|
|
|
}
|
|
|
|
// Recurse back.
|
2016-10-11 02:11:14 -04:00
|
|
|
widget_update ( widget->parent );
|
2016-10-08 12:57:59 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void widget_queue_redraw ( widget *wid )
|
|
|
|
{
|
|
|
|
if ( wid ) {
|
|
|
|
widget *iter = wid;
|
|
|
|
// Find toplevel widget.
|
|
|
|
while ( iter->parent != NULL ) {
|
2016-10-13 03:22:08 -04:00
|
|
|
iter->need_redraw = TRUE;
|
2016-10-14 10:46:54 -04:00
|
|
|
iter = iter->parent;
|
2016-10-08 12:57:59 -04:00
|
|
|
}
|
|
|
|
iter->need_redraw = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean widget_need_redraw ( widget *wid )
|
|
|
|
{
|
|
|
|
if ( wid ) {
|
|
|
|
return wid->need_redraw;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
gboolean widget_clicked ( widget *wid, xcb_button_press_event_t *xbe )
|
|
|
|
{
|
|
|
|
if ( wid && wid->clicked ) {
|
|
|
|
return wid->clicked ( wid, xbe, wid->clicked_cb_data );
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
void widget_set_clicked_handler ( widget *wid, widget_clicked_cb cb, void *udata )
|
|
|
|
{
|
|
|
|
if ( wid ) {
|
|
|
|
wid->clicked = cb;
|
|
|
|
wid->clicked_cb_data = udata;
|
|
|
|
}
|
|
|
|
}
|