2
// BaseWidgetAccessible.cs
5
// Gabriel Burt <gburt@novell.com>
7
// Copyright (C) 2009 Novell, Inc.
9
// Permission is hereby granted, free of charge, to any person obtaining
10
// a copy of this software and associated documentation files (the
11
// "Software"), to deal in the Software without restriction, including
12
// without limitation the rights to use, copy, modify, merge, publish,
13
// distribute, sublicense, and/or sell copies of the Software, and to
14
// permit persons to whom the Software is furnished to do so, subject to
15
// the following conditions:
17
// The above copyright notice and this permission notice shall be
18
// included in all copies or substantial portions of the Software.
20
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31
using System.Collections.Generic;
38
public class BaseWidgetAccessible : Gtk.Accessible, Atk.ComponentImplementor
40
private Gtk.Widget widget;
41
private uint focus_id = 0;
42
private Dictionary<uint, Atk.FocusHandler> focus_handlers = new Dictionary<uint, Atk.FocusHandler> ();
44
public BaseWidgetAccessible (Gtk.Widget widget)
47
widget.SizeAllocated += OnAllocated;
48
widget.Mapped += OnMap;
49
widget.Unmapped += OnMap;
50
widget.FocusInEvent += OnFocus;
51
widget.FocusOutEvent += OnFocus;
52
widget.AddNotification ("sensitive", (o, a) => NotifyStateChange (StateType.Sensitive, widget.Sensitive));
53
widget.AddNotification ("visible", (o, a) => NotifyStateChange (StateType.Visible, widget.Visible));
56
public virtual new Atk.Layer Layer {
57
get { return Layer.Widget; }
60
protected override Atk.StateSet OnRefStateSet ()
62
var s = base.OnRefStateSet ();
64
AddStateIf (s, widget.CanFocus, StateType.Focusable);
65
AddStateIf (s, widget.HasFocus, StateType.Focused);
66
AddStateIf (s, widget.Sensitive, StateType.Sensitive);
67
AddStateIf (s, widget.Sensitive, StateType.Enabled);
68
AddStateIf (s, widget.HasDefault, StateType.Default);
69
AddStateIf (s, widget.Visible, StateType.Visible);
70
AddStateIf (s, widget.Visible && widget.IsMapped, StateType.Showing);
75
private static void AddStateIf (StateSet s, bool condition, StateType t)
82
private void OnFocus (object o, EventArgs args)
84
NotifyStateChange (StateType.Focused, widget.HasFocus);
85
var handler = FocusChanged;
86
if (handler != null) {
87
handler (this, widget.HasFocus);
91
private void OnMap (object o, EventArgs args)
93
NotifyStateChange (StateType.Showing, widget.Visible && widget.IsMapped);
96
private void OnAllocated (object o, EventArgs args)
98
var a = widget.Allocation;
99
var bounds = new Atk.Rectangle () { X = a.X, Y = a.Y, Width = a.Width, Height = a.Height };
100
GLib.Signal.Emit (this, "bounds_changed", bounds);
101
/*var handler = BoundsChanged;
102
if (handler != null) {
103
handler (this, new BoundsChangedArgs () { Args = new object [] { bounds } });
107
private event FocusHandler FocusChanged;
109
#region Atk.Component
111
public uint AddFocusHandler (Atk.FocusHandler handler)
113
if (!focus_handlers.ContainsValue (handler)) {
114
FocusChanged += handler;
115
focus_handlers[++focus_id] = handler;
121
public bool Contains (int x, int y, Atk.CoordType coordType)
123
int x_extents, y_extents, w, h;
124
GetExtents (out x_extents, out y_extents, out w, out h, coordType);
125
Gdk.Rectangle extents = new Gdk.Rectangle (x_extents, y_extents, w, h);
126
return extents.Contains (x, y);
129
public virtual Atk.Object RefAccessibleAtPoint (int x, int y, Atk.CoordType coordType)
131
return new NoOpObject (widget);
134
public void GetExtents (out int x, out int y, out int w, out int h, Atk.CoordType coordType)
136
w = widget.Allocation.Width;
137
h = widget.Allocation.Height;
139
GetPosition (out x, out y, coordType);
142
public void GetPosition (out int x, out int y, Atk.CoordType coordType)
144
Gdk.Window window = null;
146
if (!widget.IsDrawable) {
147
x = y = Int32.MinValue;
151
if (widget.Parent != null) {
152
x = widget.Allocation.X;
153
y = widget.Allocation.Y;
154
window = widget.ParentWindow;
158
window = widget.GdkWindow;
161
int x_window, y_window;
162
window.GetOrigin (out x_window, out y_window);
166
if (coordType == Atk.CoordType.Window) {
167
window = widget.GdkWindow.Toplevel;
168
int x_toplevel, y_toplevel;
169
window.GetOrigin (out x_toplevel, out y_toplevel);
176
public void GetSize (out int w, out int h)
178
w = widget.Allocation.Width;
179
h = widget.Allocation.Height;
182
public bool GrabFocus ()
184
if (!widget.CanFocus) {
190
var toplevel_window = widget.Toplevel as Gtk.Window;
191
if (toplevel_window != null) {
192
toplevel_window.Present ();
198
public void RemoveFocusHandler (uint handlerId)
200
if (focus_handlers.ContainsKey (handlerId)) {
201
FocusChanged -= focus_handlers[handlerId];
202
focus_handlers.Remove (handlerId);
206
public bool SetExtents (int x, int y, int w, int h, Atk.CoordType coordType)
208
return SetSizeAndPosition (x, y, w, h, coordType, true);
211
public bool SetPosition (int x, int y, Atk.CoordType coordType)
213
return SetSizeAndPosition (x, y, 0, 0, coordType, false);
216
private bool SetSizeAndPosition (int x, int y, int w, int h, Atk.CoordType coordType, bool setSize)
218
if (!widget.IsTopLevel) {
222
if (coordType == CoordType.Window) {
224
widget.GdkWindow.GetOrigin (out x_off, out y_off);
228
if (x < 0 || y < 0) {
233
#pragma warning disable 0612
234
widget.SetUposition (x, y);
235
#pragma warning restore 0612
238
widget.SetSizeRequest (w, h);
244
public bool SetSize (int w, int h)
246
if (widget.IsTopLevel) {
247
widget.SetSizeRequest (w, h);
254
public double Alpha {
258
#endregion Atk.Component