2
// DocumentTypeContainer.cs
5
// Mike KrĆ¼ger <mkrueger@xamarin.com>
7
// Copyright (c) 2011 Xamarin <http://xamarin.com>
9
// Permission is hereby granted, free of charge, to any person obtaining a copy
10
// of this software and associated documentation files (the "Software"), to deal
11
// in the Software without restriction, including without limitation the rights
12
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
// copies of the Software, and to permit persons to whom the Software is
14
// furnished to do so, subject to the following conditions:
16
// The above copyright notice and this permission notice shall be included in
17
// all copies or substantial portions of the Software.
19
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
27
using System.ComponentModel;
31
using Mono.TextEditor;
32
using MonoDevelop.Components;
33
using MonoDevelop.Core;
36
namespace MonoDevelop.MacDev.PlistEditor
39
public class MacExpander : VBox
41
ExpanderHeader header;
44
public string ContentLabel {
50
header.Label = !string.IsNullOrEmpty (value) ? value : GettextCatalog.GetString ("Untitled");
55
public bool Expanded {
60
contentBox.Visible = expanded = value;
61
header.StartTimeout ();
65
public bool Expandable {
70
public bool Closeable {
75
class Border : DrawingArea
77
protected override void OnSizeRequested (ref Requisition requisition)
79
base.OnSizeRequested (ref requisition);
80
requisition.Height = 1;
83
protected override bool OnExposeEvent (EventExpose evnt)
85
using (var cr = CairoHelper.Create (evnt.Window)) {
86
cr.Color = (Mono.TextEditor.HslColor)Style.Dark (StateType.Normal);
87
cr.Rectangle (0, 0, Allocation.Width, Allocation.Height);
94
class ExpanderHeader : DrawingArea
96
MacExpander container;
97
uint animationTimeout;
98
ExpanderStyle expanderStyle = ExpanderStyle.Expanded;
100
public string Label {
105
public void UpdateInitialExpanderState ()
107
expanderStyle = container.Expanded? ExpanderStyle.Expanded : ExpanderStyle.Collapsed;
110
public ExpanderHeader (MacExpander container)
112
this.container = container;
113
Events |= EventMask.AllEventsMask;
116
protected override void OnSizeRequested (ref Requisition requisition)
118
base.OnSizeRequested (ref requisition);
119
using (var layout = new Pango.Layout (PangoContext)) {
120
layout.SetMarkup ("<b>" + Label + "</b>");
122
layout.GetPixelSize (out w, out h);
123
requisition.Height = h + 4;
125
if (container.Closeable)
126
requisition.Height += 4;
129
void RemoveTimeout ()
131
if (animationTimeout != 0) {
132
GLib.Source.Remove (animationTimeout);
133
animationTimeout = 0;
137
public void StartTimeout ()
140
animationTimeout = GLib.Timeout.Add (50, delegate {
141
bool finished = false;
142
if (container.Expanded) {
143
if (expanderStyle == ExpanderStyle.Collapsed) {
144
expanderStyle = ExpanderStyle.SemiExpanded;
146
expanderStyle = ExpanderStyle.Expanded;
150
if (expanderStyle == ExpanderStyle.Expanded) {
151
expanderStyle = ExpanderStyle.SemiCollapsed;
153
expanderStyle = ExpanderStyle.Collapsed;
159
animationTimeout = 0;
164
protected override void OnDestroyed ()
171
protected override bool OnEnterNotifyEvent (EventCrossing evnt)
175
return base.OnEnterNotifyEvent (evnt);
178
protected override bool OnLeaveNotifyEvent (EventCrossing evnt)
182
return base.OnLeaveNotifyEvent (evnt);
186
protected override bool OnMotionNotifyEvent (EventMotion evnt)
192
return base.OnMotionNotifyEvent (evnt);
195
protected override bool OnButtonPressEvent (EventButton evnt)
197
return base.OnButtonPressEvent (evnt);
199
protected override bool OnButtonReleaseEvent (EventButton evnt)
201
if (container.Expandable && evnt.Button == 1)
202
container.Expanded = !container.Expanded;
203
return base.OnButtonReleaseEvent (evnt);
206
// constants taken from gtk
207
const int DEFAULT_EXPANDER_SIZE = 10;
208
const int DEFAULT_EXPANDER_SPACING = 2;
210
Rectangle GetExpanderBounds ()
212
return new Rectangle (DEFAULT_EXPANDER_SPACING, 1 + (Allocation.Height - DEFAULT_EXPANDER_SIZE) / 2, DEFAULT_EXPANDER_SIZE, DEFAULT_EXPANDER_SIZE);
215
protected override bool OnExposeEvent (EventExpose evnt)
217
var expanderBounds = GetExpanderBounds ();
218
using (var cr = CairoHelper.Create (evnt.Window)) {
219
cr.Rectangle (0, 0, Allocation.Width, Allocation.Height);
220
var lg = new Cairo.LinearGradient (0, 0, 0, Allocation.Height);
221
var state = mouseOver ? StateType.Prelight : StateType.Normal;
223
if (container.Closeable) {
224
lg.AddColorStop (0, (Mono.TextEditor.HslColor)Style.Mid (state));
225
lg.AddColorStop (1, (Mono.TextEditor.HslColor)Style.Dark (state));
227
lg.AddColorStop (0, (Mono.TextEditor.HslColor)Style.Light (state));
228
lg.AddColorStop (1, (Mono.TextEditor.HslColor)Style.Mid (state));
234
if (mouseOver && container.Expandable) {
235
cr.Rectangle (0, 0, Allocation.Width, Allocation.Height);
238
Cairo.RadialGradient gradient = new Cairo.RadialGradient (rx, ry, Allocation.Width * 2, rx, ry, 2);
239
gradient.AddColorStop (0, new Cairo.Color (0 ,0, 0, 0));
240
Cairo.Color color = (Mono.TextEditor.HslColor)Style.Light (StateType.Normal);
242
gradient.AddColorStop (1, color);
243
cr.Pattern = gradient;
247
cr.LineTo (0, Allocation.Height);
248
cr.LineTo (Allocation.Width, Allocation.Height);
249
cr.LineTo (Allocation.Width, 0);
250
if (!container.Expandable)
252
cr.Color = (Mono.TextEditor.HslColor)Style.Dark (StateType.Normal);
255
using (var layout = new Pango.Layout (PangoContext)) {
256
layout.SetMarkup ("<b>" + Label + "</b>");
258
layout.GetPixelSize (out w, out h);
260
const int padding = 4;
262
cr.MoveTo (container.Expandable ? expanderBounds.Right + padding : padding, (Allocation.Height - h) / 2);
263
cr.Color = new Cairo.Color (0, 0, 0);
264
cr.ShowLayout (layout);
268
if (container.Expandable) {
270
var state2 = mouseOver ? StateType.Prelight : StateType.Normal;
271
Style.PaintExpander (Style,
277
expanderBounds.X + expanderBounds.Width / 2, expanderBounds.Y + expanderBounds.Width / 2,
281
return base.OnExposeEvent (evnt);
285
Border border = new Border ();
286
public MacExpander ()
288
header = new ExpanderHeader (this);
289
PackStart (header, false, false, 0);
291
contentBox = new VBox ();
292
contentBox.PackEnd (border, false, false, 0);
295
PackStart (contentBox, true, true, 0);
299
public void SetWidget (Gtk.Widget widget)
301
contentBox.PackStart (widget, true, true, 0);
302
header.UpdateInitialExpanderState ();
305
protected override void OnRealized ()
312
protected override void OnUnrealized ()
314
base.OnUnrealized ();