4 using System
.Collections
;
8 public class TileCategory
: Category
{
10 Gtk
.SizeGroup sizeGroup
;
12 public TileCategory (Tiles
.TileGroupInfo info
, Gtk
.SizeGroup sizeGroup
) : base (info
, 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
;
54 req
.Height
= 2; //keep a thin line of background.
56 // Add height for the header, and update the width if the header
57 // is wider than the tile area
59 req
.Height
+= headerReq
.Height
;
60 req
.Width
= Math
.Max (req
.Width
, headerReq
.Width
+ headerReq
.Height
);
63 req
.Width
+= (int)(2 * BorderWidth
);
64 req
.Height
+= (int)(2 * BorderWidth
);
67 protected override void OnSizeAllocated (Rectangle allocation
)
69 Requisition headerReq
, tileReq
;
71 int col
, i
, tilesWidth
, maxcols
;
72 IList tiles
= VisibleTiles
;
74 base.OnSizeAllocated (allocation
);
76 headerReq
= header
.ChildRequisition
;
78 childAlloc
.X
= allocation
.X
+ (int)BorderWidth
+ headerReq
.Height
;
79 childAlloc
.Width
= allocation
.Width
- (int)BorderWidth
- headerReq
.Height
;
80 childAlloc
.Y
= allocation
.Y
+ (int)BorderWidth
;
81 childAlloc
.Height
= headerReq
.Height
;
82 header
.Allocation
= childAlloc
;
87 tileReq
= ((Gtk
.Widget
)tiles
[0]).ChildRequisition
;
88 if (tileReq
.Width
== 0)
91 tilesWidth
= allocation
.Width
- (int)(2 * BorderWidth
) -
93 maxcols
= tilesWidth
/ tileReq
.Width
;
94 if (maxcols
!= Columns
) {
100 childAlloc
.X
+= headerReq
.Height
;
101 childAlloc
.Y
+= childAlloc
.Height
;
102 childAlloc
.Width
= tileReq
.Width
;
103 childAlloc
.Height
= tileReq
.Height
;
105 for (i
= col
= 0; i
< tiles
.Count
; i
++) {
106 ((Gtk
.Widget
)tiles
[i
]).Allocation
= childAlloc
;
108 col
= (col
+ 1) % Columns
;
110 childAlloc
.X
= (int)BorderWidth
+ 2 * headerReq
.Height
;
111 childAlloc
.Y
+= childAlloc
.Height
;
113 childAlloc
.X
+= childAlloc
.Width
;