2017-04-15 10:32:05 +00:00
|
|
|
/*
|
|
|
|
* rofi
|
|
|
|
*
|
|
|
|
* MIT/X11 License
|
|
|
|
* Copyright © 2013-2017 Qball Cow <qball@gmpclient.org>
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining
|
|
|
|
* a copy of this software and associated documentation files (the
|
|
|
|
* "Software"), to deal in the Software without restriction, including
|
|
|
|
* without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
|
|
* permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
* the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be
|
|
|
|
* included in all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
|
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
|
|
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
|
|
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
|
|
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
|
|
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2016-10-08 16:57:59 +00:00
|
|
|
#ifndef ROFI_WIDGET_H
|
|
|
|
#define ROFI_WIDGET_H
|
|
|
|
#include <glib.h>
|
|
|
|
#include <cairo.h>
|
|
|
|
#include <xcb/xcb.h>
|
|
|
|
#include <xcb/xproto.h>
|
|
|
|
/**
|
2016-10-13 07:22:08 +00:00
|
|
|
* @defgroup widget widget
|
2016-10-08 16:57:59 +00:00
|
|
|
*
|
2016-10-09 07:40:21 +00:00
|
|
|
* Generic abstract widget class. Widgets should 'inherit' from this class (first structure in there structure should be
|
|
|
|
* widget).
|
|
|
|
* The generic widget implements generic functions like get_width, get_height, draw, resize, update, free and
|
|
|
|
* clicked.
|
|
|
|
* It also holds information about how the widget should be packed.
|
2016-10-08 16:57:59 +00:00
|
|
|
*
|
|
|
|
* @{
|
|
|
|
*/
|
2016-10-14 06:47:21 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Abstract structure holding internal state of a widget.
|
|
|
|
* Structure is elaborated in widget-internal.h
|
|
|
|
*/
|
2016-10-08 16:57:59 +00:00
|
|
|
typedef struct _widget widget;
|
2016-10-11 06:11:14 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Callback for when widget is clicked.
|
|
|
|
*/
|
2016-10-08 16:57:59 +00:00
|
|
|
typedef gboolean ( *widget_clicked_cb )( widget *, xcb_button_press_event_t *, void * );
|
|
|
|
|
|
|
|
/** Macro to get widget from an implementation (e.g. textbox/scrollbar) */
|
2016-10-18 11:49:24 +00:00
|
|
|
#define WIDGET( a ) ( (widget *) ( a ) )
|
2016-10-08 16:57:59 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param widget The widget to check
|
|
|
|
* @param x The X position relative to parent window
|
|
|
|
* @param y the Y position relative to parent window
|
|
|
|
*
|
|
|
|
* Check if x,y falls within the widget.
|
|
|
|
*
|
|
|
|
* @return TRUE if x,y falls within the widget
|
|
|
|
*/
|
|
|
|
int widget_intersect ( const widget *widget, int x, int y );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param widget The widget to move
|
|
|
|
* @param x The new X position relative to parent window
|
|
|
|
* @param y The new Y position relative to parent window
|
|
|
|
*
|
|
|
|
* Moves the widget.
|
|
|
|
*/
|
|
|
|
void widget_move ( widget *widget, short x, short y );
|
|
|
|
|
2016-10-11 06:11:14 +00:00
|
|
|
/**
|
|
|
|
* @param widget Handle to widget
|
|
|
|
*
|
|
|
|
* Check if widget is enabled.
|
|
|
|
* @returns TRUE when widget is enabled.
|
|
|
|
*/
|
2016-10-08 16:57:59 +00:00
|
|
|
gboolean widget_enabled ( widget *widget );
|
2016-10-11 06:11:14 +00:00
|
|
|
/**
|
|
|
|
* @param widget Handle to widget
|
|
|
|
*
|
|
|
|
* Disable the widget.
|
|
|
|
*/
|
2016-10-08 16:57:59 +00:00
|
|
|
void widget_disable ( widget *widget );
|
2016-10-11 06:11:14 +00:00
|
|
|
/**
|
|
|
|
* @param widget Handle to widget
|
|
|
|
*
|
|
|
|
* Enable the widget.
|
|
|
|
*/
|
2016-10-08 16:57:59 +00:00
|
|
|
void widget_enable ( widget *widget );
|
|
|
|
|
|
|
|
/**
|
2017-04-23 13:17:15 +00:00
|
|
|
* @param widget widget Handle to the widget
|
2016-11-15 20:54:31 +00:00
|
|
|
* @param d The cairo object used to draw itself.
|
2016-10-08 16:57:59 +00:00
|
|
|
*
|
|
|
|
* Render the textbox.
|
|
|
|
*/
|
|
|
|
void widget_draw ( widget *widget, cairo_t *d );
|
|
|
|
|
|
|
|
/**
|
2017-04-25 09:59:25 +00:00
|
|
|
* @param wid Handle to the widget
|
2016-10-08 16:57:59 +00:00
|
|
|
*
|
|
|
|
* Free the widget and all allocated memory.
|
|
|
|
*/
|
2017-04-23 13:17:15 +00:00
|
|
|
void widget_free ( widget *wid );
|
2016-10-08 16:57:59 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param widget The widget toresize
|
|
|
|
* @param w The new width
|
|
|
|
* @param h The new height
|
|
|
|
*
|
|
|
|
* Resizes the widget.
|
|
|
|
*/
|
|
|
|
void widget_resize ( widget *widget, short w, short h );
|
|
|
|
|
2016-10-13 07:22:08 +00:00
|
|
|
/**
|
|
|
|
* @param widget The widget handle
|
|
|
|
*
|
|
|
|
* @returns the height of the widget.
|
|
|
|
*/
|
2016-10-08 16:57:59 +00:00
|
|
|
int widget_get_height ( widget *widget );
|
2016-10-13 07:22:08 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param widget The widget handle
|
|
|
|
*
|
|
|
|
* @returns the width of the widget.
|
|
|
|
*/
|
2016-10-08 16:57:59 +00:00
|
|
|
int widget_get_width ( widget *widget );
|
|
|
|
|
2016-10-17 16:21:03 +00:00
|
|
|
/**
|
|
|
|
* @param widget The widget handle
|
|
|
|
*
|
|
|
|
* @returns the y postion of the widget relative to its parent.
|
|
|
|
*/
|
|
|
|
int widget_get_y_pos ( widget *widget );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param widget The widget handle
|
|
|
|
*
|
|
|
|
* @returns the x postion of the widget relative to its parent.
|
|
|
|
*/
|
|
|
|
int widget_get_x_pos ( widget *widget );
|
|
|
|
|
2016-10-13 07:22:08 +00:00
|
|
|
/**
|
|
|
|
* @param widget The widget handle
|
|
|
|
*
|
|
|
|
* Update the widget, and its parent recursively.
|
|
|
|
* This should be called when size of widget changes.
|
|
|
|
*/
|
2016-10-08 16:57:59 +00:00
|
|
|
void widget_update ( widget *widget );
|
2016-10-13 07:22:08 +00:00
|
|
|
/**
|
2017-04-23 13:17:15 +00:00
|
|
|
* @param wid The widget handle
|
2016-10-13 07:22:08 +00:00
|
|
|
*
|
|
|
|
* Indicate that the widget needs to be redrawn.
|
|
|
|
* This is done by setting the redraw flag on the toplevel widget.
|
|
|
|
*/
|
2017-04-23 13:17:15 +00:00
|
|
|
void widget_queue_redraw ( widget *wid );
|
2016-10-13 07:22:08 +00:00
|
|
|
/**
|
2016-11-15 20:54:31 +00:00
|
|
|
* @param wid The widget handle
|
2016-10-13 07:22:08 +00:00
|
|
|
*
|
|
|
|
* Check the flag indicating the widget needs to be redrawn.
|
|
|
|
*/
|
2016-10-08 16:57:59 +00:00
|
|
|
gboolean widget_need_redraw ( widget *wid );
|
|
|
|
|
2016-10-13 07:22:08 +00:00
|
|
|
/**
|
|
|
|
* @param wid The widget handle
|
|
|
|
* @param xbe The button press event
|
|
|
|
*
|
|
|
|
* Signal the widget that it has been clicked,
|
|
|
|
* The click should have happened within the region of the widget, check with
|
|
|
|
* ::widget_intersect.
|
|
|
|
*
|
|
|
|
* @returns returns TRUE if click is handled.
|
|
|
|
*/
|
2016-10-08 16:57:59 +00:00
|
|
|
gboolean widget_clicked ( widget *wid, xcb_button_press_event_t *xbe );
|
|
|
|
|
2016-10-13 07:22:08 +00:00
|
|
|
/**
|
|
|
|
* @param wid The widget handle
|
|
|
|
* @param cb The widget click callback
|
|
|
|
* @param udata the user data to pass to callback
|
|
|
|
*
|
|
|
|
* Override the widget clicked handler on widget.
|
|
|
|
*/
|
2016-10-08 16:57:59 +00:00
|
|
|
void widget_set_clicked_handler ( widget *wid, widget_clicked_cb cb, void *udata );
|
|
|
|
|
2016-10-25 19:19:39 +00:00
|
|
|
/**
|
|
|
|
* @param wid The widget handle
|
2016-11-15 20:54:31 +00:00
|
|
|
* @param xme The motion notify object.
|
2016-10-25 19:19:39 +00:00
|
|
|
*
|
|
|
|
* Motion notify.
|
2016-11-15 20:54:31 +00:00
|
|
|
* TODO make this like clicked with callback.
|
2016-10-25 19:19:39 +00:00
|
|
|
* returns TRUE when handled.
|
|
|
|
*/
|
|
|
|
gboolean widget_motion_notify ( widget *wid, xcb_motion_notify_event_t *xme );
|
2016-12-11 11:19:46 +00:00
|
|
|
|
2017-01-01 17:08:49 +00:00
|
|
|
/**
|
|
|
|
* @param wid The widget handle
|
|
|
|
*
|
|
|
|
* Get the desired height of this widget recursively.
|
|
|
|
*
|
|
|
|
* @returns the desired height of the widget in pixels.
|
|
|
|
*/
|
2016-12-30 17:31:30 +00:00
|
|
|
int widget_get_desired_height ( widget *wid );
|
2017-01-01 17:08:49 +00:00
|
|
|
|
2016-10-08 16:57:59 +00:00
|
|
|
/*@}*/
|
|
|
|
#endif // ROFI_WIDGET_H
|