rofi  1.7.0
container.c
Go to the documentation of this file.
1 /*
2  * rofi
3  *
4  * MIT/X11 License
5  * Copyright © 2013-2021 Qball Cow <qball@gmpclient.org>
6  *
7  * Permission is hereby granted, free of charge, to any person obtaining
8  * a copy of this software and associated documentation files (the
9  * "Software"), to deal in the Software without restriction, including
10  * without limitation the rights to use, copy, modify, merge, publish,
11  * distribute, sublicense, and/or sell copies of the Software, and to
12  * permit persons to whom the Software is furnished to do so, subject to
13  * the following conditions:
14  *
15  * The above copyright notice and this permission notice shall be
16  * included in all copies or substantial portions of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
22  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25  *
26  */
27 
29 #define G_LOG_DOMAIN "Widgets.Container"
30 
31 #include "widgets/container.h"
32 #include "theme.h"
34 #include "widgets/widget.h"
35 #include <stdio.h>
36 
37 struct _container {
40 };
41 
42 static void container_update(widget *wid);
43 
45  container *b = (container *)widget;
46  int height = 0;
47  if (b->child) {
48  height += widget_get_desired_height(b->child);
49  }
51  return height;
52 }
53 
54 static void container_draw(widget *wid, cairo_t *draw) {
55  container *b = (container *)wid;
56 
57  widget_draw(b->child, draw);
58 }
59 
60 static void container_free(widget *wid) {
61  container *b = (container *)wid;
62 
63  widget_free(b->child);
64  g_free(b);
65 }
66 
68  if (container == NULL) {
69  return;
70  }
71  container->child = child;
72  g_assert(child->parent == WIDGET(container));
74 }
75 
76 static void container_resize(widget *widget, short w, short h) {
77  container *b = (container *)widget;
78  if (b->widget.w != w || b->widget.h != h) {
79  b->widget.w = w;
80  b->widget.h = h;
82  }
83 }
84 
86  gint y) {
87  container *b = (container *)wid;
88  if (!widget_intersect(b->child, x, y)) {
89  return NULL;
90  }
91 
92  x -= b->child->x;
93  y -= b->child->y;
94  return widget_find_mouse_target(b->child, type, x, y);
95 }
96 
97 static void container_set_state(widget *wid, const char *state) {
98  container *b = (container *)wid;
99  widget_set_state(b->child, state);
100 }
101 
102 container *container_create(widget *parent, const char *name) {
103  container *b = g_malloc0(sizeof(container));
104  // Initialize widget.
105  widget_init(WIDGET(b), parent, WIDGET_TYPE_UNKNOWN, name);
113  return b;
114 }
115 
116 static void container_update(widget *wid) {
117  container *b = (container *)wid;
118  if (b->child && b->child->enabled) {
124  }
125 }
static int container_get_desired_height(widget *widget)
Definition: container.c:44
static void container_resize(widget *widget, short w, short h)
Definition: container.c:76
static void container_set_state(widget *wid, const char *state)
Definition: container.c:97
static widget * container_find_mouse_target(widget *wid, WidgetType type, gint x, gint y)
Definition: container.c:85
static void container_draw(widget *wid, cairo_t *draw)
Definition: container.c:54
static void container_free(widget *wid)
Definition: container.c:60
static void container_update(widget *wid)
Definition: container.c:116
container * container_create(widget *parent, const char *name)
Definition: container.c:102
void container_add(container *container, widget *child)
Definition: container.c:67
int widget_get_desired_height(widget *wid)
Definition: widget.c:649
void widget_free(widget *wid)
Definition: widget.c:447
int widget_intersect(const widget *widget, int x, int y)
Definition: widget.c:90
void widget_resize(widget *widget, short w, short h)
Definition: widget.c:102
WidgetType
Definition: widget.h:56
void widget_update(widget *widget)
Definition: widget.c:499
void widget_move(widget *widget, short x, short y)
Definition: widget.c:117
void widget_draw(widget *widget, cairo_t *d)
Definition: widget.c:157
#define WIDGET(a)
Definition: widget.h:119
widget * widget_find_mouse_target(widget *wid, WidgetType type, gint x, gint y)
Definition: widget.c:532
@ WIDGET_TYPE_UNKNOWN
Definition: widget.h:58
widget * child
Definition: container.c:39
widget widget
Definition: container.c:38
void(* free)(struct _widget *widget)
void(* set_state)(struct _widget *, const char *)
widget_find_mouse_target_cb find_mouse_target
gboolean enabled
int(* get_desired_height)(struct _widget *)
struct _widget * parent
void(* update)(struct _widget *)
void(* draw)(struct _widget *widget, cairo_t *draw)
void(* resize)(struct _widget *, short, short)
int widget_padding_get_remaining_width(const widget *wid)
Definition: widget.c:624
void widget_init(widget *wid, widget *parent, WidgetType type, const char *name)
Definition: widget.c:44
void widget_set_state(widget *widget, const char *state)
Definition: widget.c:72
int widget_padding_get_left(const widget *wid)
Definition: widget.c:581
int widget_padding_get_padding_height(const widget *wid)
Definition: widget.c:636
int widget_padding_get_top(const widget *wid)
Definition: widget.c:603
int widget_padding_get_remaining_height(const widget *wid)
Definition: widget.c:630