2
// Copyright (C) 2009 GNOME Do
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;
28
using Docky.Interface;
29
using Docky.Utilities;
31
namespace Docky.Interface.Painters
35
public abstract class AbstractIntegratedPainter : IDockPainter
37
protected int BorderSize { get { return 10; } }
38
int buffer_height = 0;
40
Surface icon_surface, buffer;
41
AbstractDockItem dock_item;
43
protected abstract int PainterWidth { get; }
45
protected virtual bool NeedsRepaint {
49
protected abstract void PaintArea (Cairo.Context context, Gdk.Rectangle paintableArea);
51
protected virtual bool ReceiveClick (Gdk.Rectangle paintArea, Gdk.Point cursor)
56
public virtual void Scrolled (Gdk.ScrollDirection direction)
60
#region IDockPainter implementation
62
public event EventHandler HideRequested;
64
public event EventHandler<PaintNeededArgs> PaintNeeded;
66
public event EventHandler ShowRequested;
68
public void Clicked (Gdk.Rectangle dockArea, Gdk.Point cursor)
70
Gdk.Rectangle paintArea = new Gdk.Rectangle (0, 0, Width, dockArea.Height);
71
Gdk.Point paintAreaCursor = new Gdk.Point (cursor.X - dockArea.Left - DockPreferences.FullIconSize - BorderSize,
72
cursor.Y - dockArea.Top);
74
if (!paintArea.Contains (paintAreaCursor) || ReceiveClick (paintArea, paintAreaCursor))
78
public virtual bool DoubleBuffer {
82
public virtual bool Interruptable {
88
return PainterWidth + DockPreferences.FullIconSize + 2 * BorderSize;
92
public AbstractIntegratedPainter (AbstractDockItem dockItem)
95
DockPreferences.IconSizeChanged +=HandleIconSizeChanged;
96
dockItem.UpdateNeeded +=HandleUpdateNeeded;
99
void HandleUpdateNeeded(object sender, UpdateRequestArgs args)
101
if (icon_surface != null)
102
icon_surface.Destroy ();
105
OnPaintNeeded (new PaintNeededArgs ());
108
void HandleIconSizeChanged()
110
if (icon_surface != null)
111
icon_surface.Destroy ();
115
public virtual void Interrupt ()
120
public void Paint (Cairo.Context cr, Gdk.Rectangle dockArea, Gdk.Point cursor)
122
if (buffer == null || buffer_height != dockArea.Height || NeedsRepaint) {
126
buffer = cr.Target.CreateSimilar (cr.Target.Content, PainterWidth, dockArea.Height);
127
using (Cairo.Context context = new Cairo.Context (buffer)) {
128
PaintArea (context, new Gdk.Rectangle (0, 0, PainterWidth, dockArea.Height));
130
buffer_height = dockArea.Height;
133
PaintIcon (cr, dockArea);
135
cr.Rectangle (dockArea.X, dockArea.Y, dockArea.Width, dockArea.Height);
138
int x = dockArea.X + DockPreferences.FullIconSize + BorderSize;
139
buffer.Show (cr, x, dockArea.Y);
145
void PaintIcon (Cairo.Context cr, Gdk.Rectangle dockArea)
147
if (icon_surface == null)
148
icon_surface = CreateIconSurface (cr.Target);
150
switch (DockPreferences.Orientation) {
151
case DockOrientation.Top:
152
icon_surface.Show (cr, dockArea.X + BorderSize, dockArea.Y + 5);
154
case DockOrientation.Bottom:
155
icon_surface.Show (cr, dockArea.X + BorderSize, dockArea.Y + dockArea.Height - 5 - DockPreferences.FullIconSize);
160
protected virtual Surface CreateIconSurface (Surface similar)
162
Surface surface = similar.CreateSimilar (similar.Content,
163
DockPreferences.FullIconSize,
164
DockPreferences.FullIconSize);
167
Surface icon_surface = dock_item.GetIconSurface (similar, DockPreferences.FullIconSize, out actual_size);
169
using (Context context = new Context (surface)) {
170
int offset = (DockPreferences.FullIconSize - actual_size) / 2;
171
icon_surface.Show (context, offset, offset);
177
protected void OnPaintNeeded (PaintNeededArgs args)
179
if (PaintNeeded != null)
180
PaintNeeded (this, args);
183
protected void OnShowRequested ()
185
if (ShowRequested != null)
186
ShowRequested (this, EventArgs.Empty);
189
protected void OnHideRequested ()
191
if (HideRequested != null)
192
HideRequested (this, EventArgs.Empty);
195
#region IDisposable implementation
197
public virtual void Dispose ()