5
// Lluis Sanchez <lluis@xamarin.com>
7
// Copyright (c) 2012 Xamarin Inc
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 MonoDevelop.Ide.Gui;
28
using System.Collections.Generic;
30
namespace MonoDevelop.Components
32
public class HPanedThin: Gtk.HPaned
34
static HashSet<int> stylesParsed = new HashSet<int> ();
36
CustomPanedHandle handle;
40
Mono.TextEditor.GtkWorkarounds.FixContainerLeak (this);
41
handle = new CustomPanedHandle (this);
45
public int GrabAreaSize {
46
get { return handle.GrabAreaSize; }
48
handle.GrabAreaSize = value;
53
public Gtk.Widget HandleWidget {
54
get { return handle.HandleWidget; }
55
set { handle.HandleWidget = value; }
58
internal static void InitStyle (Gtk.Paned paned, int size)
60
string id = "MonoDevelop.ThinPanedHandle.s" + size;
61
if (stylesParsed.Add (size)) {
62
Gtk.Rc.ParseString ("style \"" + id + "\" {\n GtkPaned::handle-size = " + size + "\n }\n");
63
Gtk.Rc.ParseString ("widget \"*." + id + "\" style \"" + id + "\"\n");
68
protected override void ForAll (bool include_internals, Gtk.Callback callback)
70
base.ForAll (include_internals, callback);
75
protected override bool OnExposeEvent (Gdk.EventExpose evnt)
77
base.OnExposeEvent (evnt);
79
if (Child1 != null && Child1.Visible && Child2 != null && Child2.Visible) {
80
var gc = new Gdk.GC (evnt.Window);
81
gc.RgbFgColor = (HslColor) Styles.ThinSplitterColor;
82
var x = Child1.Allocation.X + Child1.Allocation.Width;
83
evnt.Window.DrawLine (gc, x, Allocation.Y, x, Allocation.Y + Allocation.Height);
91
class CustomPanedHandle: Gtk.EventBox
93
static Gdk.Cursor resizeCursorW = new Gdk.Cursor (Gdk.CursorType.SbHDoubleArrow);
94
static Gdk.Cursor resizeCursorH = new Gdk.Cursor (Gdk.CursorType.SbVDoubleArrow);
95
internal const int HandleGrabWidth = 4;
103
public CustomPanedHandle (Gtk.Paned parent)
105
this.parent = parent;
106
this.horizontal = parent is HPanedThin;
107
GrabAreaSize = HandleGrabWidth;
108
Events |= Gdk.EventMask.EnterNotifyMask | Gdk.EventMask.LeaveNotifyMask | Gdk.EventMask.PointerMotionMask | Gdk.EventMask.ButtonPressMask | Gdk.EventMask.ButtonReleaseMask;
110
parent.SizeRequested += delegate {
113
parent.SizeAllocated += HandleSizeAllocated;
117
void HandleSizeAllocated (object o, Gtk.SizeAllocatedArgs args)
119
if (parent.Child1 != null && parent.Child1.Visible && parent.Child2 != null && parent.Child2.Visible) {
121
int centerSize = Child == null ? GrabAreaSize / 2 : 0;
123
SizeAllocate (new Gdk.Rectangle (parent.Child1.Allocation.X + parent.Child1.Allocation.Width - centerSize, args.Allocation.Y, GrabAreaSize, args.Allocation.Height));
125
SizeAllocate (new Gdk.Rectangle (args.Allocation.X, parent.Child1.Allocation.Y + parent.Child1.Allocation.Height - centerSize, args.Allocation.Width, GrabAreaSize));
130
public int GrabAreaSize {
133
return SizeRequest ().Width;
135
return SizeRequest ().Height;
139
WidthRequest = value;
141
HeightRequest = value;
145
public Gtk.Widget HandleWidget {
146
get { return Child; }
154
VisibleWindow = true;
155
WidthRequest = HeightRequest = -1;
156
HPanedThin.InitStyle (parent, GrabAreaSize);
158
VisibleWindow = false;
163
HPanedThin.InitStyle (parent, 1);
168
protected override bool OnEnterNotifyEvent (Gdk.EventCrossing evnt)
171
GdkWindow.Cursor = resizeCursorW;
173
GdkWindow.Cursor = resizeCursorH;
174
return base.OnEnterNotifyEvent (evnt);
177
protected override bool OnLeaveNotifyEvent (Gdk.EventCrossing evnt)
179
GdkWindow.Cursor = null;
180
return base.OnLeaveNotifyEvent (evnt);
183
protected override bool OnButtonPressEvent (Gdk.EventButton evnt)
186
initialPos = (int) evnt.XRoot;
188
initialPos = (int) evnt.YRoot;
189
initialPanedPos = parent.Position;
194
protected override bool OnButtonReleaseEvent (Gdk.EventButton evnt)
200
protected override bool OnMotionNotifyEvent (Gdk.EventMotion evnt)
204
int newpos = initialPanedPos + ((int) evnt.XRoot - initialPos);
205
parent.Position = newpos >= 10 ? newpos : 10;
208
int newpos = initialPanedPos + ((int) evnt.YRoot - initialPos);
209
parent.Position = newpos >= 10 ? newpos : 10;
212
return base.OnMotionNotifyEvent (evnt);