4
using System.Collections;
5
using System.Collections.Generic;
7
using Beagle.Search.Tiles;
9
namespace Beagle.Search {
11
public class TileCategory : Category {
13
Gtk.SizeGroup size_group;
15
public TileCategory (Tiles.TileGroupInfo info, Gtk.SizeGroup size_group) : base (info, 2)
17
this.size_group = size_group;
20
protected override void OnAdded (Gtk.Widget widget)
22
size_group.AddWidget (widget);
23
base.OnAdded (widget);
26
protected override void OnRemoved (Gtk.Widget widget)
28
base.OnRemoved (widget);
29
size_group.RemoveWidget (widget);
32
protected override void OnSizeRequested (ref Requisition req)
34
Requisition headerReq, tileReq;
36
req.Height = req.Width = 0;
37
headerReq = header.SizeRequest ();
39
tileReq.Width = tileReq.Height = 0;
40
foreach (Widget w in AllTiles) {
41
tileReq = w.SizeRequest ();
42
req.Width = Math.Max (req.Width, tileReq.Width);
43
req.Height = Math.Max (req.Height, tileReq.Height);
46
// req is now the max width/height of a single tile. Indent
47
// req.Width, and use that as our width request, so that the
48
// minimum width you can resize the category to is wide enough to
49
// fit a whole column. But request a req.Height that is only tall
50
// enough to fit PageSize tiles if we get the number of columns
51
// we'd wanted. (OnSizeAllocated will force a recalculation with
52
// fewer columns if we don't get enough width.)
53
req.Width += 2 * headerReq.Height;
54
req.Height *= (PageSize + Columns - 1) / Columns;
57
req.Height = 2; // keep a thin line of background.
59
// Add height for the header, and update the width if the header
60
// is wider than the tile area
62
req.Height += headerReq.Height;
63
req.Width = Math.Max (req.Width, headerReq.Width);
66
req.Width += (int)(2 * BorderWidth);
67
req.Height += (int)(2 * BorderWidth);
70
protected override void OnSizeAllocated (Rectangle allocation)
72
Requisition headerReq, tileReq;
74
int col, i, tilesWidth, maxcols;
75
IList<Tile> tiles = VisibleTiles;
77
base.OnSizeAllocated (allocation);
79
headerReq = header.ChildRequisition;
81
childAlloc.X = allocation.X + (int)BorderWidth;
82
childAlloc.Width = allocation.Width - (int)BorderWidth;
83
childAlloc.Y = allocation.Y + (int)BorderWidth;
84
childAlloc.Height = headerReq.Height;
85
header.Allocation = childAlloc;
90
tileReq = ((Gtk.Widget)tiles[0]).ChildRequisition;
91
if (tileReq.Width == 0)
94
tilesWidth = allocation.Width - (int)(2 * BorderWidth) - headerReq.Height;
95
maxcols = tilesWidth / tileReq.Width;
96
if (maxcols != Columns) {
102
childAlloc.X += headerReq.Height;
103
childAlloc.Y += childAlloc.Height;
104
childAlloc.Width = tileReq.Width;
105
childAlloc.Height = tileReq.Height;
107
for (i = col = 0; i < tiles.Count; i++) {
108
((Gtk.Widget)tiles[i]).Allocation = childAlloc;
110
col = (col + 1) % Columns;
112
childAlloc.X = (int)BorderWidth + headerReq.Height;
113
childAlloc.Y += childAlloc.Height;
115
childAlloc.X += childAlloc.Width;