void makeFloating(TabView tv) { lock (IFace.UpdateMutex) { ImageSurface di = new ImageSurface(Format.Argb32, dis, dis); IFace.DragImageHeight = dis; IFace.DragImageWidth = dis; using (Context ctx = new Context(di)) { double div = Math.Max(LastPaintedSlot.Width, LastPaintedSlot.Height); double s = (double)dis / div; ctx.Scale(s, s); if (bmp == null) { this.onDraw(ctx); } else { if (LastPaintedSlot.Width > LastPaintedSlot.Height) { ctx.SetSourceSurface(bmp, 0, (LastPaintedSlot.Width - LastPaintedSlot.Height) / 2); } else { ctx.SetSourceSurface(bmp, (LastPaintedSlot.Height - LastPaintedSlot.Width) / 2, 0); } ctx.Paint(); } } IFace.DragImage = di; } tv.RemoveChild(this); savedParent = tv; }
protected override void onDraw(Context gr) { gr.Save(); TabView tv = Parent as TabView; Rectangle r = TabTitle.Slot; r.Width = TabWidth; gr.MoveTo(0.5, r.Bottom - 0.5); gr.LineTo(r.Left - tv.LeftSlope, r.Bottom - 0.5); gr.CurveTo( r.Left - tv.LeftSlope / 2, r.Bottom - 0.5, r.Left - tv.LeftSlope / 2, 0.5, r.Left, 0.5); gr.LineTo(r.Right, 0.5); gr.CurveTo( r.Right + tv.RightSlope / 2, 0.5, r.Right + tv.RightSlope / 2, r.Bottom - 0.5, r.Right + tv.RightSlope, r.Bottom - 0.5); gr.LineTo(Slot.Width - 0.5, r.Bottom - 0.5); gr.LineTo(Slot.Width - 0.5, Slot.Height - 0.5); gr.LineTo(0.5, Slot.Height - 0.5); gr.ClosePath(); gr.LineWidth = 1; Foreground.SetAsSource(gr); gr.StrokePreserve(); gr.Clip(); base.onDraw(gr); gr.Restore(); }
public override void onMouseMove(object sender, MouseMoveEventArgs e) { base.onMouseMove(sender, e); if (!(HasFocus && holdCursor)) { return; } TabView tv = Parent as TabView; TabItem previous = null, next = null; int tmp = TabOffset + e.XDelta; if (tmp < tv.Spacing) { TabOffset = tv.Spacing; } else if (tmp > Parent.getSlot().Width - TabTitle.Slot.Width - tv.Spacing) { TabOffset = Parent.getSlot().Width - TabTitle.Slot.Width - tv.Spacing; } else { int idx = tv.Children.IndexOf(this); if (idx > 0 && e.XDelta < 0) { previous = tv.Children [idx - 1] as TabItem; if (tmp < previous.TabOffset + previous.TabTitle.Slot.Width / 2) { tv.Children.RemoveAt(idx); tv.Children.Insert(idx - 1, this); tv.SelectedTab = idx - 1; tv.UpdateLayout(LayoutingType.ArrangeChildren); } } else if (idx < tv.Children.Count - 1 && e.XDelta > 0) { next = tv.Children [idx + 1] as TabItem; if (tmp > next.TabOffset - next.TabTitle.Slot.Width / 2) { tv.Children.RemoveAt(idx); tv.Children.Insert(idx + 1, this); tv.SelectedTab = idx + 1; tv.UpdateLayout(LayoutingType.ArrangeChildren); } } TabOffset = tmp; } }
protected override void onDrop(object sender, DragDropEventArgs e) { base.onDrop(sender, e); if (Parent != null) { return; } TabView tv = e.DropTarget as TabView; if (tv == null) { return; } IFace.ClearDragImage(); tv.AddChild(this); }
public override void onMouseMove(object sender, MouseMoveEventArgs e) { base.onMouseMove(sender, e); if (Parent == null) { return; } if (!IsDragged) { return; } TabView tv = Parent as TabView; if (Math.Abs(e.Position.Y - dragStartPoint.Y) > dragThreshold || Math.Abs(e.Position.X - dragStartPoint.X) > dragThreshold) { makeFloating(tv); return; } Rectangle cb = ClientRectangle; int tmp = TabOffset + e.XDelta; if (tmp < tview.LeftSlope) { TabOffset = tview.LeftSlope; } else if (tmp > cb.Width - tv.RightSlope - tv.TabWidth) { TabOffset = cb.Width - tv.RightSlope - tv.TabWidth; } else { dragStartPoint.X = e.Position.X; TabItem[] tabItms = tv.Children.Cast <TabItem>().OrderBy(t => t.ViewIndex).ToArray(); if (ViewIndex > 0 && e.XDelta < 0) { TabItem previous = tabItms [ViewIndex - 1]; if (tmp < previous.TabOffset + tview.TabWidth / 2) { previous.ViewIndex = ViewIndex; ViewIndex--; tv.UpdateLayout(LayoutingType.ArrangeChildren); } } else if (ViewIndex < tabItms.Length - 1 && e.XDelta > 0) { TabItem next = tabItms [ViewIndex + 1]; if (tmp > next.TabOffset - tview.TabWidth / 2) { next.ViewIndex = ViewIndex; ViewIndex++; tv.UpdateLayout(LayoutingType.ArrangeChildren); } } TabOffset = tmp; } }