2017-04-15 06:32:05 -04:00
|
|
|
/*
|
2016-12-28 13:42:14 -05:00
|
|
|
* rofi
|
|
|
|
*
|
|
|
|
* MIT/X11 License
|
2021-06-09 08:50:39 -04:00
|
|
|
* Copyright © 2013-2021 Qball Cow <qball@gmpclient.org>
|
2016-12-28 13:42:14 -05:00
|
|
|
*
|
|
|
|
* 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.
|
2017-04-15 06:32:05 -04:00
|
|
|
*
|
2016-12-28 13:42:14 -05:00
|
|
|
*/
|
|
|
|
|
2018-06-12 05:45:42 -04:00
|
|
|
/** The log domain of this widget. */
|
2021-02-03 16:03:29 -05:00
|
|
|
#define G_LOG_DOMAIN "Widgets.Container"
|
2017-04-15 05:58:49 -04:00
|
|
|
|
2016-12-28 13:42:14 -05:00
|
|
|
#include <config.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include "widgets/widget.h"
|
|
|
|
#include "widgets/widget-internal.h"
|
2017-01-05 12:33:57 -05:00
|
|
|
#include "widgets/container.h"
|
2016-12-28 13:42:14 -05:00
|
|
|
#include "theme.h"
|
|
|
|
|
2021-02-03 16:03:29 -05:00
|
|
|
struct _container
|
2016-12-28 13:42:14 -05:00
|
|
|
{
|
2017-01-08 15:36:06 -05:00
|
|
|
widget widget;
|
2016-12-28 13:42:14 -05:00
|
|
|
widget *child;
|
|
|
|
};
|
|
|
|
|
2017-01-05 12:33:57 -05:00
|
|
|
static void container_update ( widget *wid );
|
2016-12-28 13:42:14 -05:00
|
|
|
|
2017-01-05 12:33:57 -05:00
|
|
|
static int container_get_desired_height ( widget *widget )
|
2016-12-30 12:31:30 -05:00
|
|
|
{
|
2017-01-08 15:36:06 -05:00
|
|
|
container *b = (container *) widget;
|
|
|
|
int height = 0;
|
2016-12-30 12:31:30 -05:00
|
|
|
if ( b->child ) {
|
|
|
|
height += widget_get_desired_height ( b->child );
|
|
|
|
}
|
2016-12-30 13:59:45 -05:00
|
|
|
height += widget_padding_get_padding_height ( widget );
|
2016-12-30 12:31:30 -05:00
|
|
|
return height;
|
|
|
|
}
|
|
|
|
|
2017-01-05 12:33:57 -05:00
|
|
|
static void container_draw ( widget *wid, cairo_t *draw )
|
2016-12-28 13:42:14 -05:00
|
|
|
{
|
2017-01-05 12:33:57 -05:00
|
|
|
container *b = (container *) wid;
|
2016-12-28 13:42:14 -05:00
|
|
|
|
|
|
|
widget_draw ( b->child, draw );
|
|
|
|
}
|
|
|
|
|
2017-01-05 12:33:57 -05:00
|
|
|
static void container_free ( widget *wid )
|
2016-12-28 13:42:14 -05:00
|
|
|
{
|
2017-01-05 12:33:57 -05:00
|
|
|
container *b = (container *) wid;
|
2016-12-28 13:42:14 -05:00
|
|
|
|
|
|
|
widget_free ( b->child );
|
|
|
|
g_free ( b );
|
|
|
|
}
|
|
|
|
|
2017-01-05 12:33:57 -05:00
|
|
|
void container_add ( container *container, widget *child )
|
2016-12-28 13:42:14 -05:00
|
|
|
{
|
2017-01-05 12:33:57 -05:00
|
|
|
if ( container == NULL ) {
|
2016-12-28 13:42:14 -05:00
|
|
|
return;
|
|
|
|
}
|
2017-01-05 12:33:57 -05:00
|
|
|
container->child = child;
|
2017-10-05 11:45:50 -04:00
|
|
|
g_assert ( child->parent == WIDGET ( container ) );
|
2017-01-05 12:33:57 -05:00
|
|
|
widget_update ( WIDGET ( container ) );
|
2016-12-28 13:42:14 -05:00
|
|
|
}
|
|
|
|
|
2017-01-05 12:33:57 -05:00
|
|
|
static void container_resize ( widget *widget, short w, short h )
|
2016-12-28 13:42:14 -05:00
|
|
|
{
|
2017-01-05 12:33:57 -05:00
|
|
|
container *b = (container *) widget;
|
2016-12-28 13:42:14 -05:00
|
|
|
if ( b->widget.w != w || b->widget.h != h ) {
|
|
|
|
b->widget.w = w;
|
|
|
|
b->widget.h = h;
|
|
|
|
widget_update ( widget );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-30 06:37:11 -04:00
|
|
|
static widget *container_find_mouse_target ( widget *wid, WidgetType type, gint x, gint y )
|
2016-12-28 13:42:14 -05:00
|
|
|
{
|
2017-01-05 12:33:57 -05:00
|
|
|
container *b = (container *) wid;
|
2017-05-30 06:37:11 -04:00
|
|
|
if ( !widget_intersect ( b->child, x, y ) ) {
|
2017-05-27 20:18:09 -04:00
|
|
|
return NULL;
|
2016-12-28 13:42:14 -05:00
|
|
|
}
|
2017-05-27 20:18:09 -04:00
|
|
|
|
2017-05-30 06:37:11 -04:00
|
|
|
x -= b->child->x;
|
|
|
|
y -= b->child->y;
|
|
|
|
return widget_find_mouse_target ( b->child, type, x, y );
|
2016-12-28 13:42:14 -05:00
|
|
|
}
|
2017-05-30 06:37:11 -04:00
|
|
|
|
2020-05-13 10:25:12 -04:00
|
|
|
static void container_set_state ( widget *wid, const char *state )
|
|
|
|
{
|
|
|
|
container *b = (container *) wid;
|
|
|
|
widget_set_state ( b->child, state );
|
|
|
|
}
|
|
|
|
|
2017-09-07 07:46:09 -04:00
|
|
|
container * container_create ( widget *parent, const char *name )
|
2016-12-28 13:42:14 -05:00
|
|
|
{
|
2017-01-05 12:33:57 -05:00
|
|
|
container *b = g_malloc0 ( sizeof ( container ) );
|
2016-12-28 13:42:14 -05:00
|
|
|
// Initialize widget.
|
2017-09-07 07:46:09 -04:00
|
|
|
widget_init ( WIDGET ( b ), parent, WIDGET_TYPE_UNKNOWN, name );
|
2017-01-05 12:33:57 -05:00
|
|
|
b->widget.draw = container_draw;
|
|
|
|
b->widget.free = container_free;
|
|
|
|
b->widget.resize = container_resize;
|
|
|
|
b->widget.update = container_update;
|
2017-05-27 20:18:09 -04:00
|
|
|
b->widget.find_mouse_target = container_find_mouse_target;
|
2017-01-05 12:33:57 -05:00
|
|
|
b->widget.get_desired_height = container_get_desired_height;
|
2020-05-13 10:25:12 -04:00
|
|
|
b->widget.set_state = container_set_state;
|
2016-12-28 13:42:14 -05:00
|
|
|
return b;
|
|
|
|
}
|
|
|
|
|
2017-01-05 12:33:57 -05:00
|
|
|
static void container_update ( widget *wid )
|
2016-12-28 13:42:14 -05:00
|
|
|
{
|
2017-01-05 12:33:57 -05:00
|
|
|
container *b = (container *) wid;
|
2017-01-08 15:36:06 -05:00
|
|
|
if ( b->child && b->child->enabled ) {
|
2016-12-28 13:42:14 -05:00
|
|
|
widget_resize ( WIDGET ( b->child ),
|
2017-01-08 15:36:06 -05:00
|
|
|
widget_padding_get_remaining_width ( WIDGET ( b ) ),
|
|
|
|
widget_padding_get_remaining_height ( WIDGET ( b ) )
|
|
|
|
);
|
2016-12-28 13:42:14 -05:00
|
|
|
widget_move ( WIDGET ( b->child ),
|
2017-01-08 15:36:06 -05:00
|
|
|
widget_padding_get_left ( WIDGET ( b ) ),
|
|
|
|
widget_padding_get_top ( WIDGET ( b ) )
|
|
|
|
);
|
2016-12-28 13:42:14 -05:00
|
|
|
}
|
|
|
|
}
|