rofi  1.5.1
container.c
Go to the documentation of this file.
1 /*
2  * rofi
3  *
4  * MIT/X11 License
5  * Copyright © 2013-2017 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 
28 #define G_LOG_DOMAIN "Widgets.Window"
29 
30 #include <config.h>
31 #include <stdio.h>
32 #include "widgets/widget.h"
34 #include "widgets/container.h"
35 #include "theme.h"
36 
37 struct _window
38 {
41 };
42 
43 static void container_update ( widget *wid );
44 
46 {
47  container *b = (container *) widget;
48  int height = 0;
49  if ( b->child ) {
50  height += widget_get_desired_height ( b->child );
51  }
53  return height;
54 }
55 
56 static void container_draw ( widget *wid, cairo_t *draw )
57 {
58  container *b = (container *) wid;
59 
60  widget_draw ( b->child, draw );
61 }
62 
63 static void container_free ( widget *wid )
64 {
65  container *b = (container *) wid;
66 
67  widget_free ( b->child );
68  g_free ( b );
69 }
70 
72 {
73  if ( container == NULL ) {
74  return;
75  }
76  container->child = child;
77  g_assert ( child->parent == WIDGET ( container ) );
79 }
80 
81 static void container_resize ( widget *widget, short w, short h )
82 {
83  container *b = (container *) widget;
84  if ( b->widget.w != w || b->widget.h != h ) {
85  b->widget.w = w;
86  b->widget.h = h;
88  }
89 }
90 
91 static widget *container_find_mouse_target ( widget *wid, WidgetType type, gint x, gint y )
92 {
93  container *b = (container *) wid;
94  if ( !widget_intersect ( b->child, x, y ) ) {
95  return NULL;
96  }
97 
98  x -= b->child->x;
99  y -= b->child->y;
100  return widget_find_mouse_target ( b->child, type, x, y );
101 }
102 
103 container * container_create ( widget *parent, const char *name )
104 {
105  container *b = g_malloc0 ( sizeof ( container ) );
106  // Initialize widget.
107  widget_init ( WIDGET ( b ), parent, WIDGET_TYPE_UNKNOWN, name );
114  return b;
115 }
116 
117 static void container_update ( widget *wid )
118 {
119  container *b = (container *) wid;
120  if ( b->child && b->child->enabled ) {
121  widget_resize ( WIDGET ( b->child ),
124  );
125  widget_move ( WIDGET ( b->child ),
128  );
129  }
130 }
static widget * container_find_mouse_target(widget *wid, WidgetType type, gint x, gint y)
Definition: container.c:91
static int container_get_desired_height(widget *widget)
Definition: container.c:45
static void container_draw(widget *wid, cairo_t *draw)
Definition: container.c:56
WidgetType
Definition: widget.h:56
widget_find_mouse_target_cb find_mouse_target
static void container_resize(widget *widget, short w, short h)
Definition: container.c:81
void widget_update(widget *widget)
Definition: widget.c:411
static void container_update(widget *wid)
Definition: container.c:117
void(* resize)(struct _widget *, short, short)
int widget_padding_get_top(const widget *wid)
Definition: widget.c:506
struct _widget * parent
void widget_free(widget *wid)
Definition: widget.c:355
widget widget
Definition: container.c:39
void(* draw)(struct _widget *widget, cairo_t *draw)
void widget_draw(widget *widget, cairo_t *d)
Definition: widget.c:140
int widget_intersect(const widget *widget, int x, int y)
Definition: widget.c:68
gboolean enabled
void widget_move(widget *widget, short x, short y)
Definition: widget.c:98
void widget_resize(widget *widget, short w, short h)
Definition: widget.c:82
int widget_padding_get_remaining_height(const widget *wid)
Definition: widget.c:534
void(* free)(struct _widget *widget)
widget * child
Definition: container.c:40
#define WIDGET(a)
Definition: widget.h:115
int widget_padding_get_remaining_width(const widget *wid)
Definition: widget.c:527
void widget_init(widget *wid, widget *parent, WidgetType type, const char *name)
Definition: widget.c:37
static void container_free(widget *wid)
Definition: container.c:63
int(* get_desired_height)(struct _widget *)
int widget_get_desired_height(widget *wid)
Definition: widget.c:556
widget * widget_find_mouse_target(widget *wid, WidgetType type, gint x, gint y)
Definition: widget.c:442
int widget_padding_get_padding_height(const widget *wid)
Definition: widget.c:541
void(* update)(struct _widget *)
void container_add(container *container, widget *child)
Definition: container.c:71
int widget_padding_get_left(const widget *wid)
Definition: widget.c:486
container * container_create(widget *parent, const char *name)
Definition: container.c:103