5
// Jonathan Pobst <monkey@jpobst.com>
7
// Copyright (c) 2010 Jonathan Pobst
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
33
public abstract class BaseTool
35
protected ToggleToolButton tool_item;
36
protected ToolItem tool_label;
37
protected ToolItem tool_image;
38
protected ToolItem tool_sep;
44
public virtual string Name { get { throw new ApplicationException ("Tool didn't override Name"); } }
45
public virtual string Icon { get { throw new ApplicationException ("Tool didn't override Icon"); } }
46
public virtual string ToolTip { get { throw new ApplicationException ("Tool didn't override ToolTip"); } }
47
public virtual string StatusBarText { get { return string.Empty; } }
48
public virtual ToggleToolButton ToolItem { get { if (tool_item == null) tool_item = CreateToolButton (); return tool_item; } }
49
public virtual bool Enabled { get { return false; } }
51
#region Public Methods
52
public void DoMouseMove (object o, MotionNotifyEventArgs args, Cairo.PointD point)
54
OnMouseMove (o, args, point);
57
public void DoBuildToolBar (Toolbar tb)
62
public void DoClearToolBar (Toolbar tb)
67
public void DoMouseDown (DrawingArea canvas, ButtonPressEventArgs args, Cairo.PointD point)
69
OnMouseDown (canvas, args, point);
72
public void DoMouseUp (DrawingArea canvas, ButtonReleaseEventArgs args, Cairo.PointD point)
74
OnMouseUp (canvas, args, point);
77
public void DoDeactivated ()
83
#region Protected Methods
84
protected virtual void OnMouseMove (object o, Gtk.MotionNotifyEventArgs args, Cairo.PointD point)
88
protected virtual void OnBuildToolBar (Toolbar tb)
90
if (tool_label == null)
91
tool_label = new ToolBarLabel (" Tool: ");
93
tb.AppendItem (tool_label);
95
if (tool_image == null)
96
tool_image = new ToolBarImage (Icon);
98
tb.AppendItem (tool_image);
100
if (tool_sep == null)
101
tool_sep = new SeparatorToolItem ();
103
tb.AppendItem (tool_sep);
106
protected virtual void OnClearToolBar (Toolbar tb)
108
while (tb.NItems > 0)
109
tb.Remove (tb.Children[tb.NItems - 1]);
112
protected virtual void OnMouseDown (DrawingArea canvas, Gtk.ButtonPressEventArgs args, Cairo.PointD point)
116
protected virtual void OnMouseUp (DrawingArea canvas, Gtk.ButtonReleaseEventArgs args, Cairo.PointD point)
120
protected virtual void OnDeactivated ()
124
protected virtual ToggleToolButton CreateToolButton ()
126
Image i2 = new Image (PintaCore.Resources.GetIcon (Icon));
129
ToggleToolButton tool_item = new ToggleToolButton ();
130
tool_item.IconWidget = i2;
132
tool_item.Label = Name;
133
tool_item.TooltipText = Name;