Hit.cs: Remove FIXME by using binary search while searching properties.
[beagle.git] / search / TileCategory.cs
blobc931504701e1094dd7064203a254f4c33d03defc
1 using Gtk;
2 using Gdk;
3 using System;
4 using System.Collections;
6 namespace Search {
8 public class TileCategory : Category {
10 Gtk.SizeGroup sizeGroup;
12 public TileCategory (string name, int rows, Gtk.SizeGroup sizeGroup) : base (name, rows, 2)
14 this.sizeGroup = sizeGroup;
17 protected override void OnAdded (Gtk.Widget widget)
19 sizeGroup.AddWidget (widget);
20 base.OnAdded (widget);
23 protected override void OnRemoved (Gtk.Widget widget)
25 base.OnRemoved (widget);
26 sizeGroup.RemoveWidget (widget);
29 protected override void OnSizeRequested (ref Requisition req)
31 Requisition headerReq, tileReq;
33 req.Height = req.Width = 0;
34 headerReq = header.SizeRequest ();
36 tileReq.Width = tileReq.Height = 0;
37 foreach (Widget w in AllTiles) {
38 tileReq = w.SizeRequest ();
39 req.Width = Math.Max (req.Width, tileReq.Width);
40 req.Height = Math.Max (req.Height, tileReq.Height);
43 // req is now the max width/height of a single tile. Indent
44 // req.Width, and use that as our width request, so that the
45 // minimum width you can resize the category to is wide enough to
46 // fit a whole column. But request a req.Height that is only tall
47 // enough to fit PageSize tiles if we get the number of columns
48 // we'd wanted. (OnSizeAllocated will force a recalculation with
49 // fewer columns if we don't get enough width.)
50 req.Width += 2 * headerReq.Height;
51 req.Height *= (PageSize + Columns - 1) / Columns;
53 // Add height for the header, and update the width if the header
54 // is wider than the tile area
55 req.Height += headerReq.Height;
56 req.Width = Math.Max (req.Width, headerReq.Width + headerReq.Height);
58 // Handle BorderWidth
59 req.Width += (int)(2 * BorderWidth);
60 req.Height += (int)(2 * BorderWidth);
63 protected override void OnSizeAllocated (Rectangle allocation)
65 Requisition headerReq, tileReq;
66 Rectangle childAlloc;
67 int col, i, tilesWidth, maxcols;
68 IList tiles = VisibleTiles;
70 base.OnSizeAllocated (allocation);
72 headerReq = header.ChildRequisition;
74 childAlloc.X = allocation.X + (int)BorderWidth + headerReq.Height;
75 childAlloc.Width = allocation.Width - (int)BorderWidth - headerReq.Height;
76 childAlloc.Y = allocation.Y + (int)BorderWidth;
77 childAlloc.Height = headerReq.Height;
78 header.Allocation = childAlloc;
80 if (tiles.Count == 0)
81 return;
83 tileReq = ((Gtk.Widget)tiles[0]).ChildRequisition;
84 if (tileReq.Width == 0)
85 return;
87 tilesWidth = allocation.Width - (int)(2 * BorderWidth) -
88 2 * headerReq.Height;
89 maxcols = tilesWidth / tileReq.Width;
90 if (maxcols != Columns) {
91 Columns = maxcols;
92 QueueResize ();
93 return;
96 childAlloc.X += headerReq.Height;
97 childAlloc.Y += childAlloc.Height;
98 childAlloc.Width = tileReq.Width;
99 childAlloc.Height = tileReq.Height;
101 for (i = col = 0; i < tiles.Count; i++) {
102 ((Gtk.Widget)tiles[i]).Allocation = childAlloc;
104 col = (col + 1) % Columns;
105 if (col == 0) {
106 childAlloc.X = (int)BorderWidth + 2 * headerReq.Height;
107 childAlloc.Y += childAlloc.Height;
108 } else
109 childAlloc.X += childAlloc.Width;