178
195
data.ShowTimer = 0;
199
public static Gdk.Rectangle ToScreenCoordinates (Gtk.Widget widget, Gdk.Window w, Gdk.Rectangle rect)
201
return new Gdk.Rectangle (ToScreenCoordinates (widget, w, rect.X, rect.Y), rect.Size);
204
public static Gdk.Point ToScreenCoordinates (Gtk.Widget widget, Gdk.Window w, int x, int y)
207
w.GetOrigin (out ox, out oy);
208
ox += widget.Allocation.X;
209
oy += widget.Allocation.Y;
210
return new Gdk.Point (ox + x, oy + y);
213
public static Gdk.Rectangle ToWindowCoordinates (Gtk.Widget widget, Gdk.Window w, Gdk.Rectangle rect)
215
return new Gdk.Rectangle (ToWindowCoordinates (widget, w, rect.X, rect.Y), rect.Size);
218
public static Gdk.Point ToWindowCoordinates (Gtk.Widget widget, Gdk.Window w, int x, int y)
221
w.GetOrigin (out ox, out oy);
222
ox += widget.Allocation.X;
223
oy += widget.Allocation.Y;
224
return new Gdk.Point (x - ox, y - oy);
227
public static T ReplaceWithWidget<T> (this Gtk.Widget oldWidget, T newWidget, bool transferChildren = false) where T:Gtk.Widget
229
Gtk.Container parent = (Gtk.Container) oldWidget.Parent;
231
throw new InvalidOperationException ();
234
var box = (Box) parent;
235
var bc = (Gtk.Box.BoxChild) parent [oldWidget];
237
var nc = (Gtk.Box.BoxChild) parent [newWidget];
238
nc.Expand = bc.Expand;
240
nc.PackType = bc.PackType;
241
nc.Padding = bc.Padding;
242
nc.Position = bc.Position;
243
box.Remove (oldWidget);
245
else if (parent is Table) {
246
var table = (Table) parent;
247
var bc = (Gtk.Table.TableChild) parent [oldWidget];
248
table.Add (newWidget);
249
var nc = (Gtk.Table.TableChild) parent [newWidget];
250
nc.BottomAttach = bc.BottomAttach;
251
nc.LeftAttach = bc.LeftAttach;
252
nc.RightAttach = bc.RightAttach;
253
nc.TopAttach = bc.TopAttach;
254
nc.XOptions = bc.XOptions;
255
nc.XPadding = bc.XPadding;
256
nc.YOptions = bc.YOptions;
257
nc.YPadding = bc.YPadding;
258
table.Remove (oldWidget);
260
else if (parent is Paned) {
261
var paned = (Paned) parent;
262
var bc = (Gtk.Paned.PanedChild) parent [oldWidget];
263
var resize = bc.Resize;
264
var shrink = bc.Shrink;
265
if (oldWidget == paned.Child1) {
266
paned.Remove (oldWidget);
267
paned.Add1 (newWidget);
269
paned.Remove (oldWidget);
270
paned.Add2 (newWidget);
272
var nc = (Gtk.Paned.PanedChild) parent [newWidget];
277
throw new NotSupportedException ();
279
if (transferChildren) {
280
if (newWidget is Paned && oldWidget is Paned) {
281
var panedOld = (Paned) oldWidget;
282
var panedNew = (Paned) (object) newWidget;
283
if (panedOld.Child1 != null) {
284
var c = panedOld.Child1;
285
var bc = (Gtk.Paned.PanedChild) panedOld [c];
286
var resize = bc.Resize;
287
var shrink = bc.Shrink;
290
var nc = (Gtk.Paned.PanedChild) panedNew [c];
294
if (panedOld.Child2 != null) {
295
var c = panedOld.Child2;
296
var bc = (Gtk.Paned.PanedChild) panedOld [c];
297
var resize = bc.Resize;
298
var shrink = bc.Shrink;
301
var nc = (Gtk.Paned.PanedChild) panedNew [c];
307
throw new NotSupportedException ();
310
newWidget.Visible = oldWidget.Visible;
314
public static bool ScreenSupportsARGB ()
316
return Gdk.Screen.Default.IsComposited;
320
/// This method can be used to get a reliave Leave event for a widget, which
321
/// is not fired if the pointer leaves the widget to enter a child widget.
322
/// To ubsubscribe the event, dispose the object returned by the method.
324
public static IDisposable SubscribeLeaveEvent (this Gtk.Widget w, System.Action leaveHandler)
326
return new LeaveEventData (w, leaveHandler);
330
class LeaveEventData: IDisposable
332
public System.Action LeaveHandler;
333
public Gtk.Widget RootWidget;
336
public LeaveEventData (Gtk.Widget w, System.Action leaveHandler)
339
LeaveHandler = leaveHandler;
341
RootWidget.Unrealized += HandleUnrealized;
345
w.Realized += HandleRealized;
348
void HandleRealized (object sender, EventArgs e)
350
RootWidget.Realized -= HandleRealized;
351
RootWidget.Unrealized += HandleUnrealized;
352
TrackLeaveEvent (RootWidget);
355
void HandleUnrealized (object sender, EventArgs e)
357
RootWidget.Unrealized -= HandleUnrealized;
358
UntrackLeaveEvent (RootWidget);
359
RootWidget.Realized += HandleRealized;
366
public void Dispose ()
368
if (RootWidget.IsRealized) {
369
UntrackLeaveEvent (RootWidget);
370
RootWidget.Unrealized -= HandleUnrealized;
372
RootWidget.Realized -= HandleRealized;
376
public void TrackLeaveEvent (Gtk.Widget w)
378
w.LeaveNotifyEvent += HandleLeaveNotifyEvent;
379
w.EnterNotifyEvent += HandleEnterNotifyEvent;
380
if (w is Gtk.Container) {
381
((Gtk.Container)w).Added += HandleAdded;
382
((Gtk.Container)w).Removed += HandleRemoved;
383
foreach (var c in ((Gtk.Container)w).Children)
388
void UntrackLeaveEvent (Gtk.Widget w)
390
w.LeaveNotifyEvent -= HandleLeaveNotifyEvent;
391
w.EnterNotifyEvent -= HandleEnterNotifyEvent;
392
if (w is Gtk.Container) {
393
((Gtk.Container)w).Added -= HandleAdded;
394
((Gtk.Container)w).Removed -= HandleRemoved;
395
foreach (var c in ((Gtk.Container)w).Children)
396
UntrackLeaveEvent (c);
400
void HandleRemoved (object o, RemovedArgs args)
402
UntrackLeaveEvent (args.Widget);
405
void HandleAdded (object o, AddedArgs args)
407
TrackLeaveEvent (args.Widget);
410
void HandleEnterNotifyEvent (object o, EnterNotifyEventArgs args)
415
void HandleLeaveNotifyEvent (object o, LeaveNotifyEventArgs args)
419
// Delay the call to the leave handler since the pointer may be
420
// entering a child widget, in which case the event doesn't have to be fired
421
Gtk.Application.Invoke (delegate {
183
428
class TreeViewTooltipsData
234
479
protected override bool OnExposeEvent (Gdk.EventExpose evnt)
236
481
base.OnExposeEvent (evnt);
237
Gdk.Rectangle rect = Allocation;
238
col.CellSetCellData (tree.Model, iter, false, false);
483
Gdk.Rectangle expose = Allocation;
484
Gdk.Color save = Gdk.Color.Zero;
240
Gdk.Color save = Gdk.Color.Zero;
487
col.CellSetCellData (tree.Model, iter, false, false);
241
489
foreach (CellRenderer cr in col.CellRenderers) {
244
493
if (cr is CellRendererText) {
245
494
save = ((CellRendererText)cr).ForegroundGdk;
246
495
((CellRendererText)cr).ForegroundGdk = Style.Foreground (State);
248
498
int sp, wi, he, xo, yo;
249
499
col.CellGetPosition (cr, out sp, out wi);
250
Gdk.Rectangle colcrect = new Gdk.Rectangle (x, rect.Y, wi, rect.Height - 2);
251
cr.GetSize (tree, ref colcrect, out xo, out yo, out wi, out he);
252
int leftMargin = (int) ((colcrect.Width - wi) * cr.Xalign);
253
int rightMargin = (int) ((colcrect.Height - he) * cr.Yalign);
254
Gdk.Rectangle crect = new Gdk.Rectangle (colcrect.X + leftMargin, colcrect.Y + rightMargin + 1, wi, he);
255
cr.Render (this.GdkWindow, tree, colcrect, crect, rect, CellRendererState.Focused);
256
x += colcrect.Width + col.Spacing + 1;
500
Gdk.Rectangle bgrect = new Gdk.Rectangle (x, expose.Y, wi, expose.Height - 2);
501
cr.GetSize (tree, ref bgrect, out xo, out yo, out wi, out he);
502
int leftMargin = (int) ((bgrect.Width - wi) * cr.Xalign);
503
int topMargin = (int) ((bgrect.Height - he) * cr.Yalign);
504
Gdk.Rectangle cellrect = new Gdk.Rectangle (bgrect.X + leftMargin, bgrect.Y + topMargin + 1, wi, he);
505
cr.Render (this.GdkWindow, this, bgrect, cellrect, expose, CellRendererState.Focused);
506
x += bgrect.Width + col.Spacing + 1;
257
508
if (cr is CellRendererText) {
258
509
((CellRendererText)cr).ForegroundGdk = save;