1 /* This file is part of Cinaest.
3 * Copyright (C) 2009 Philipp Zabel
5 * Cinaest is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * Cinaest is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with Cinaest. If not, see <http://www.gnu.org/licenses/>.
21 class CellRendererVBox : CellRenderer {
22 private List<CellRenderer> children;
24 public CellRendererVBox () {
31 public void append (CellRenderer cell, bool expand) {
32 children.append (cell);
33 cell.set_data ("box-expand", (void*) (long) expand);
36 public override void get_size (Widget widget, Gdk.Rectangle? rectangle, out int x_offset, out int y_offset, out int width, out int height) {
40 foreach (CellRenderer child in children) {
41 int renderer_width, renderer_height;
43 child.get_size (widget, null, null, null, out renderer_width, out renderer_height);
44 if ((renderer_width > 0) && (renderer_height > 0)) {
45 calc_width = int.max (calc_width, renderer_width);
46 calc_height += renderer_height;
50 int full_width = (int) xpad * 2 + calc_width;
51 int full_height = (int) ypad * 2 + calc_height;
53 if ((rectangle != null) && calc_width > 0 && calc_height > 0) {
54 if (&x_offset != null) {
55 x_offset = (int) (((widget.get_direction () == TextDirection.RTL) ? (1.0 - xalign) : xalign) * (rectangle.width - full_width));
56 x_offset = int.max (x_offset, 0);
58 if (&y_offset != null) {
59 y_offset = (int) (yalign * (rectangle.height - full_height));
60 y_offset = int.max (y_offset, 0);
63 if (&x_offset != null)
65 if (&y_offset != null)
75 public override void render (Gdk.Window window, Widget widget, Gdk.Rectangle background_area, Gdk.Rectangle cell_area, Gdk.Rectangle expose_area, CellRendererState flags) {
76 int nvis_children = 0;
77 int nexpand_children = 0;
80 // Counts visible and expandable children cell renderers
81 foreach (CellRenderer child in children) {
84 child.get ("visible", out visible);
85 expand = (bool) (long) child.get_data ("box-expand");
90 nexpand_children += 1;
94 if (nvis_children > 0) {
97 var child_alloc = Gdk.Rectangle ();
99 if (nexpand_children > 0) {
100 var req = Requisition ();
102 get_size (widget, null, null, null, out req.width, out req.height);
103 height = cell_area.height - req.height;
104 extra = height / nexpand_children;
110 get ("xpad", out x_pad, "ypad", out y_pad);
111 y = cell_area.y + y_pad;
112 child_alloc.x = cell_area.x + x_pad;
113 child_alloc.width = int.max (1, cell_area.width - x_pad * 2);
115 foreach (CellRenderer child in children) {
116 bool visible, expand;
118 child.get ("visible", out visible);
119 expand = (bool) (long) child.get_data ("box-expand");
122 var child_req = Requisition ();
123 int child_xpad, child_ypad;
124 var child_expose_area = Gdk.Rectangle ();
126 child.get_size (widget, null, null, null, out child_req.width, out child_req.height);
127 child.get ("xpad", out child_xpad, "ypad", out child_ypad);
130 if (nexpand_children == 1)
131 child_req.height += height;
133 child_req.height += extra;
134 nexpand_children -= 1;
138 child_alloc.height = int.max (1, child_req.height);
141 if (child_alloc.intersect (expose_area, child_expose_area)) {
142 child.render (window, widget, background_area, child_alloc, child_expose_area, flags);
144 y += child_req.height;