2
// Copyright (C) 2009 Jason Smith
4
// This program is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
9
// This program is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
// GNU General Public License for more details.
14
// You should have received a copy of the GNU General Public License
15
// along with this program. If not, see <http://www.gnu.org/licenses/>.
19
using System.Collections.Generic;
20
using System.Collections.ObjectModel;
28
using Docky.Interface;
34
public class DockPlacementWidget : Gtk.DrawingArea
36
const int Width = 260;
37
const int Height = 175;
39
const int DockSize = 30;
41
Gdk.Rectangle allocation;
42
IEnumerable<Dock> docks;
44
public event EventHandler ActiveDockChanged;
47
get { return (allocation.Width - Width) / 2; }
51
get { return (allocation.Height - Height) / 2; }
55
public Dock ActiveDock {
56
get { return activeDock; }
58
if (!docks.Contains (value))
62
OnActiveDockChanged ();
66
public DockPlacementWidget (IEnumerable<Dock> docks)
70
ActiveDock = docks.First ();
71
SetSizeRequest (Width, Height);
73
AddEvents ((int) Gdk.EventMask.AllEventsMask);
76
public void SetDocks (IEnumerable<Dock> docks)
82
ActiveDock = docks.First ();
87
foreach (Dock dock in docks) {
88
dock.Preferences.PositionChanged += DockPreferencesPositionChanged;
92
void DockPreferencesPositionChanged (object sender, EventArgs e)
97
void UnregisterDocks ()
99
foreach (Dock dock in docks) {
100
dock.Preferences.PositionChanged -= DockPreferencesPositionChanged;
104
// Is there really not an easier way to get this?
105
protected override void OnSizeAllocated (Gdk.Rectangle allocation)
107
this.allocation = allocation;
109
base.OnSizeAllocated (allocation);
112
protected override bool OnButtonReleaseEvent (EventButton evnt)
114
foreach (Dock dock in docks) {
115
Gdk.Rectangle area = DockRenderArea (dock.Preferences.Position);
116
if (area.Contains ((int) evnt.X, (int) evnt.Y)) {
118
OnActiveDockChanged ();
123
return base.OnButtonReleaseEvent (evnt);
127
Gdk.Rectangle DockRenderArea (DockPosition position)
133
case DockPosition.Top:
134
return new Gdk.Rectangle (x + (DockSize + 5), y + 1, Width - 2 * (DockSize + 5), DockSize);
135
case DockPosition.Left:
136
return new Gdk.Rectangle (x + 1, y + (DockSize + 5), DockSize, Height - 2 * (DockSize + 5));
137
case DockPosition.Right:
138
return new Gdk.Rectangle (x + Width - DockSize - 1, y + (DockSize + 5), DockSize, Height - 2 * (DockSize + 5));
140
case DockPosition.Bottom:
141
return new Gdk.Rectangle (x + (DockSize + 5), y + Height - DockSize - 1, Width - 2 * (DockSize + 5), DockSize);
145
protected override bool OnExposeEvent (EventExpose evnt)
150
bool result = base.OnExposeEvent (evnt);
155
using (Cairo.Context cr = Gdk.CairoHelper.Create (evnt.Window)) {
156
cr.RoundedRectangle (x + .5,
162
LinearGradient lg = new LinearGradient (x, y, x + Width, y + Width);
163
lg.AddColorStop (0, new Cairo.Color (0.6, 0.9, 1.0, 0.7));
164
lg.AddColorStop (1, new Cairo.Color (0.3, 0.6, 0.9, 0.7));
170
cr.Color = new Cairo.Color (0, 0, 0);
174
foreach (Dock dock in docks) {
175
Gdk.Rectangle area = DockRenderArea (dock.Preferences.Position);
176
cr.Rectangle (area.X, area.Y, area.Width, area.Height);
178
if (ActiveDock == dock)
179
cr.Color = new Cairo.Color (1, 1, 1, .9);
181
cr.Color = new Cairo.Color (1, 1, 1, .35);
190
void OnActiveDockChanged ()
193
if (ActiveDockChanged != null)
194
ActiveDockChanged (this, EventArgs.Empty);