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 }
WIDGET
#define WIDGET(a)
Definition: widget.h:115
WidgetType
WidgetType
Definition: widget.h:57
container_update
static void container_update(widget *wid)
Definition: container.c:118
_widget::enabled
gboolean enabled
Definition: widget-internal.h:58
WIDGET_TYPE_UNKNOWN
@ WIDGET_TYPE_UNKNOWN
Definition: widget.h:59
_window::child
widget * child
Definition: container.c:41
container_create
container * container_create(widget *parent, const char *name)
Definition: container.c:104
_window::widget
widget widget
Definition: container.c:40
_widget::get_desired_height
int(* get_desired_height)(struct _widget *)
Definition: widget-internal.h:81
_window
Definition: container.c:39
widget_find_mouse_target
widget * widget_find_mouse_target(widget *wid, WidgetType type, gint x, gint y)
Definition: widget.c:453
widget_padding_get_remaining_height
int widget_padding_get_remaining_height(const widget *wid)
Definition: widget.c:545
widget_update
void widget_update(widget *widget)
Definition: widget.c:422
widget_padding_get_remaining_width
int widget_padding_get_remaining_width(const widget *wid)
Definition: widget.c:538
_widget::draw
void(* draw)(struct _widget *widget, cairo_t *draw)
Definition: widget-internal.h:72
theme.h
container_resize
static void container_resize(widget *widget, short w, short h)
Definition: container.c:82
widget_free
void widget_free(widget *wid)
Definition: widget.c:365
_widget::free
void(* free)(struct _widget *widget)
Definition: widget-internal.h:92
_widget::y
short y
Definition: widget-internal.h:42
container.h
widget.h
_widget::x
short x
Definition: widget-internal.h:40
container_draw
static void container_draw(widget *wid, cairo_t *draw)
Definition: container.c:57
widget_padding_get_top
int widget_padding_get_top(const widget *wid)
Definition: widget.c:517
_widget::parent
struct _widget * parent
Definition: widget-internal.h:64
widget_intersect
int widget_intersect(const widget *widget, int x, int y)
Definition: widget.c:70
widget_move
void widget_move(widget *widget, short x, short y)
Definition: widget.c:100
container_add
void container_add(container *container, widget *child)
Definition: container.c:72
_widget::h
short h
Definition: widget-internal.h:46
container_free
static void container_free(widget *wid)
Definition: container.c:64
widget_init
void widget_init(widget *wid, widget *parent, WidgetType type, const char *name)
Definition: widget.c:37
container_get_desired_height
static int container_get_desired_height(widget *widget)
Definition: container.c:46
_widget::w
short w
Definition: widget-internal.h:44
widget-internal.h
widget_draw
void widget_draw(widget *widget, cairo_t *d)
Definition: widget.c:142
_widget::find_mouse_target
widget_find_mouse_target_cb find_mouse_target
Definition: widget-internal.h:85
widget_padding_get_left
int widget_padding_get_left(const widget *wid)
Definition: widget.c:497
_widget::resize
void(* resize)(struct _widget *, short, short)
Definition: widget-internal.h:74
widget_get_desired_height
int widget_get_desired_height(widget *wid)
Definition: widget.c:567
container_find_mouse_target
static widget * container_find_mouse_target(widget *wid, WidgetType type, gint x, gint y)
Definition: container.c:92
widget_resize
void widget_resize(widget *widget, short w, short h)
Definition: widget.c:84
_widget::update
void(* update)(struct _widget *)
Definition: widget-internal.h:76
widget_padding_get_padding_height
int widget_padding_get_padding_height(const widget *wid)
Definition: widget.c:552
_widget
Definition: widget-internal.h:36