rofi  1.5.4
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 
29 #define G_LOG_DOMAIN "Widgets.Window"
30 
31 #include <config.h>
32 #include <stdio.h>
33 #include "widgets/widget.h"
35 #include "widgets/container.h"
36 #include "theme.h"
37 
38 struct _window
39 {
42 };
43 
44 static void container_update ( widget *wid );
45 
47 {
48  container *b = (container *) widget;
49  int height = 0;
50  if ( b->child ) {
51  height += widget_get_desired_height ( b->child );
52  }
54  return height;
55 }
56 
57 static void container_draw ( widget *wid, cairo_t *draw )
58 {
59  container *b = (container *) wid;
60 
61  widget_draw ( b->child, draw );
62 }
63 
64 static void container_free ( widget *wid )
65 {
66  container *b = (container *) wid;
67 
68  widget_free ( b->child );
69  g_free ( b );
70 }
71 
73 {
74  if ( container == NULL ) {
75  return;
76  }
77  container->child = child;
78  g_assert ( child->parent == WIDGET ( container ) );
80 }
81 
82 static void container_resize ( widget *widget, short w, short h )
83 {
84  container *b = (container *) widget;
85  if ( b->widget.w != w || b->widget.h != h ) {
86  b->widget.w = w;
87  b->widget.h = h;
89  }
90 }
91 
92 static widget *container_find_mouse_target ( widget *wid, WidgetType type, gint x, gint y )
93 {
94  container *b = (container *) wid;
95  if ( !widget_intersect ( b->child, x, y ) ) {
96  return NULL;
97  }
98 
99  x -= b->child->x;
100  y -= b->child->y;
101  return widget_find_mouse_target ( b->child, type, x, y );
102 }
103 
104 container * container_create ( widget *parent, const char *name )
105 {
106  container *b = g_malloc0 ( sizeof ( container ) );
107  // Initialize widget.
108  widget_init ( WIDGET ( b ), parent, WIDGET_TYPE_UNKNOWN, name );
115  return b;
116 }
117 
118 static void container_update ( widget *wid )
119 {
120  container *b = (container *) wid;
121  if ( b->child && b->child->enabled ) {
122  widget_resize ( WIDGET ( b->child ),
125  );
126  widget_move ( WIDGET ( b->child ),
129  );
130  }
131 }
static widget * container_find_mouse_target(widget *wid, WidgetType type, gint x, gint y)
Definition: container.c:92
static int container_get_desired_height(widget *widget)
Definition: container.c:46
static void container_draw(widget *wid, cairo_t *draw)
Definition: container.c:57
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:82
void widget_update(widget *widget)
Definition: widget.c:422
static void container_update(widget *wid)
Definition: container.c:118
void(* resize)(struct _widget *, short, short)
int widget_padding_get_top(const widget *wid)
Definition: widget.c:517
struct _widget * parent
void widget_free(widget *wid)
Definition: widget.c:365
widget widget
Definition: container.c:40
void(* draw)(struct _widget *widget, cairo_t *draw)
void widget_draw(widget *widget, cairo_t *d)
Definition: widget.c:142
int widget_intersect(const widget *widget, int x, int y)
Definition: widget.c:70
gboolean enabled
void widget_move(widget *widget, short x, short y)
Definition: widget.c:100
void widget_resize(widget *widget, short w, short h)
Definition: widget.c:84
int widget_padding_get_remaining_height(const widget *wid)
Definition: widget.c:545
void(* free)(struct _widget *widget)
widget * child
Definition: container.c:41
#define WIDGET(a)
Definition: widget.h:115
int widget_padding_get_remaining_width(const widget *wid)
Definition: widget.c:538
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:64
int(* get_desired_height)(struct _widget *)
int widget_get_desired_height(widget *wid)
Definition: widget.c:567
widget * widget_find_mouse_target(widget *wid, WidgetType type, gint x, gint y)
Definition: widget.c:453
int widget_padding_get_padding_height(const widget *wid)
Definition: widget.c:552
void(* update)(struct _widget *)
void container_add(container *container, widget *child)
Definition: container.c:72
int widget_padding_get_left(const widget *wid)
Definition: widget.c:497
container * container_create(widget *parent, const char *name)
Definition: container.c:104