1 //
2 // DockItemToolbar.cs
3 //
4 // Author:
5 //       Lluis Sanchez Gual <lluis@novell.com>
6 //
7 // Copyright (c) 2010 Novell, Inc (http://www.novell.com)
8 //
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:
15 //
16 // The above copyright notice and this permission notice shall be included in
17 // all copies or substantial portions of the Software.
18 //
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
25 // THE SOFTWARE.
26 
27 using System;
28 using Gtk;
29 
30 namespace Pinta.Docking
31 {
32 	public class DockItemToolbar
33 	{
34 		DockItem parentItem;
35 		Gtk.Widget frame;
36 		Box box;
37 		PositionType position;
38 		bool empty = true;
39 		CustomFrame topFrame;
40 
DockItemToolbar(DockItem parentItem, PositionType position)41 		internal DockItemToolbar (DockItem parentItem, PositionType position)
42 		{
43 			this.parentItem = parentItem;
44 
45 			topFrame = new CustomFrame ();
46 			topFrame.SetPadding (3,3,3,3);
47 
48 /*			switch (position) {
49 				case PositionType.Top:
50 					frame.SetMargins (0, 0, 1, 1);
51 					frame.SetPadding (0, 2, 2, 0);
52 					break;
53 				case PositionType.Bottom:
54 					frame.SetMargins (0, 1, 1, 1);
55 					frame.SetPadding (2, 2, 2, 0);
56 					break;
57 				case PositionType.Left:
58 					frame.SetMargins (0, 1, 1, 0);
59 					frame.SetPadding (0, 0, 2, 2);
60 					break;
61 				case PositionType.Right:
62 					frame.SetMargins (0, 1, 0, 1);
63 					frame.SetPadding (0, 0, 2, 2);
64 					break;
65 			}*/
66 
67 			this.position = position;
68 			if (position == PositionType.Top || position == PositionType.Bottom)
69 				box = new HBox (false, 3);
70 			else
71 				box = new VBox (false, 3);
72 			box.Show ();
73 //			frame = box;
74 			frame = topFrame;
75 			topFrame.Add (box);
76 
77 //			topFrame.GradientBackround = true;
78 		}
79 
SetStyle(DockVisualStyle style)80 		internal void SetStyle (DockVisualStyle style)
81 		{
82 			topFrame.BackgroundColor = style.PadBackgroundColor.Value;
83 		}
84 
85 		public DockItem DockItem {
86 			get { return parentItem; }
87 		}
88 
89 		internal Widget Container {
90 			get { return frame; }
91 		}
92 
93 		public PositionType Position {
94 			get { return this.position; }
95 		}
96 
Add(Widget widget)97 		public void Add (Widget widget)
98 		{
99 			Add (widget, false);
100 		}
101 
Add(Widget widget, bool fill)102 		public void Add (Widget widget, bool fill)
103 		{
104 			Add (widget, fill, -1);
105 		}
106 
Add(Widget widget, bool fill, int padding)107 		public void Add (Widget widget, bool fill, int padding)
108 		{
109 			Add (widget, fill, padding, -1);
110 		}
111 
Add(Widget widget, bool fill, int padding, int index)112 		void Add (Widget widget, bool fill, int padding, int index)
113 		{
114 			int defaultPadding = 3;
115 
116 			if (widget is Button) {
117 				((Button)widget).Relief = ReliefStyle.None;
118 				((Button)widget).FocusOnClick = false;
119 				defaultPadding = 0;
120 			}
121 			else if (widget is Entry) {
122 				((Entry)widget).HasFrame = false;
123 			}
124 			else if (widget is ComboBox) {
125 				((ComboBox)widget).HasFrame = false;
126 			}
127 			else if (widget is VSeparator)
128 				((VSeparator)widget).HeightRequest = 10;
129 
130 			if (padding == -1)
131 				padding = defaultPadding;
132 
133 			box.PackStart (widget, fill, fill, (uint)padding);
134 			if (empty) {
135 				empty = false;
136 				frame.Show ();
137 			}
138 			if (index != -1) {
139 				Box.BoxChild bc = (Box.BoxChild) box [widget];
140 				bc.Position = index;
141 			}
142 		}
143 
Insert(Widget w, int index)144 		public void Insert (Widget w, int index)
145 		{
146 			Add (w, false, 0, index);
147 		}
148 
Remove(Widget widget)149 		public void Remove (Widget widget)
150 		{
151 			box.Remove (widget);
152 		}
153 
154 		public bool Visible {
155 			get {
156 				return empty || frame.Visible;
157 			}
158 			set {
159 				frame.Visible = value;
160 			}
161 		}
162 
163 		public bool Sensitive {
164 			get { return frame.Sensitive; }
165 			set { frame.Sensitive = value; }
166 		}
167 
ShowAll()168 		public void ShowAll ()
169 		{
170 			frame.ShowAll ();
171 		}
172 
173 		public Widget[] Children {
174 			get { return box.Children; }
175 		}
176 	}
177 
178 	public class DockToolButton: Gtk.Button
179 	{
DockToolButton(string stockId)180 		public DockToolButton (string stockId)
181 		{
182 			Image = new Gtk.Image (stockId, IconSize.Menu);
183 			Image.Show ();
184 		}
185 
DockToolButton(string stockId, string label)186 		public DockToolButton (string stockId, string label)
187 		{
188 			Label = label;
189 			Image = new Gtk.Image (stockId, IconSize.Menu);
190 			Image.Show ();
191 		}
192 	}
193 }
194 
195