protected override void OnWindowlessNavigatingTo(WindowlessControlHost sender, WindowlessNavigateEventArgs e) { base.OnWindowlessNavigatingTo(sender, e); if (sender != this) { return; } // if we have a selection already, just leave it if (myCurrentSelection != null) { return; } if (Items.Count == 0) { return; } Point me = WindowlessPointToForm(this, Point.Empty); Point other = WindowlessPointToForm(e.Source, Point.Empty); Rectangle otherRect = e.SourceRectangle; otherRect.X += other.X; otherRect.Y += other.Y; Rectangle rect = new Rectangle(otherRect.X - me.X, otherRect.Y - me.Y, otherRect.Width, otherRect.Height); NavigateSelection(rect, e.Key); }
public void Connect(IWindowlessControl control) { Type type = GetType(); WindowlessControlHost.RecurseWindowlessControls(control, (current) => { if (string.IsNullOrEmpty(current.Name)) { return(true); } PropertyInfo prop = type.GetProperty(current.Name, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance); if (prop != null) { if (prop.GetValue(this, null) != null) { throw new InvalidOperationException(string.Format("Unable to connect to property {0}. The value is non-null", current.Name)); } prop.SetValue(this, current, null); return(true); } FieldInfo field = type.GetField(current.Name, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance); if (field != null) { if (field.GetValue(this) != null) { throw new InvalidOperationException(string.Format("Unable to connect to field {0}. The value is non-null", current.Name)); } field.SetValue(this, current); } return(true); }, null); }
public virtual void Measure(Size bounds) { myNeedsMeasure = false; // cap a control's dimensions if desired bounds.Width = Math.Min(bounds.Width, myMaxWidth); bounds.Height = Math.Min(bounds.Height, myMaxHeight); Size newBounds = bounds; if (bounds.Width != Int32.MaxValue) { newBounds.Width = bounds.Width - myMargin.Value.Left - myMargin.Value.Right; } if (bounds.Height != Int32.MaxValue) { newBounds.Height = bounds.Height - myMargin.Value.Top - myMargin.Value.Bottom; } bool boundsChange = myLastMeasureBounds != newBounds; myLastMeasureBounds = newBounds; if (MeasureUnpadded(newBounds, boundsChange)) { WindowlessControlHost.WindowlessInvalidate(this); } }
protected virtual void OnWindowlessNavigatingTo(WindowlessControlHost sender, WindowlessNavigateEventArgs e) { if (WindowlessNavigatingTo != null) { WindowlessNavigatingTo(sender, e); } }
protected virtual void OnWindowlessDoubleClick(WindowlessControlHost sender, WindowlessMouseEventArgs e) { if (WindowlessDoubleClick != null) { WindowlessDoubleClick(sender, e); } }
public static WindowlessControlHost CreateHostControl(Control control, bool matchHeight, bool matchWidth) { WindowlessControlHost ret = new WindowlessControlHost(); ret.HostControl(control, matchHeight, matchWidth); return(ret); }
protected virtual void OnWindowlessLostFocus(WindowlessControlHost sender, EventArgs e) { if (WindowlessLostFocus != null) { WindowlessLostFocus(sender); } }
void WindowlessInvalidate(Rectangle rect) { PrepareDirtyRegion(); myDirtyRegion.Union(rect); Invalidate(rect); // tell all child controls that are transparent and in this rect that they need to repaint foreach (Control control in Controls) { WindowlessControlHost wc = control as WindowlessControlHost; if (wc == null || wc.BackColor != Color.Transparent) { continue; } Rectangle intersect = new Rectangle(wc.Left, wc.Top, wc.Width, wc.Height); intersect.Intersect(rect); if (intersect.Width == 0 || intersect.Height == 0) { continue; } intersect.X -= wc.Left; intersect.Y -= wc.Top; wc.WindowlessInvalidate(intersect); } }
protected virtual void OnWindowlessGotFocus(WindowlessControlHost sender, EventArgs e) { if (WindowlessGotFocus != null) { WindowlessGotFocus(sender); } if (sender != this) { return; } // if we have focus and are unfocusable, lets just give it to the first focusable control we can find // this scenario can happen cause a common control passes focus // or the form gives the main host focus at start if (!Focusable) { Control control = FindFocusable(this); if (control != null) { control.Focus(); } // this control got focus from the form most likely during startup // now that it has delegated focus, set its tabstop to false. TabStop = false; } }
protected override void OnWindowlessLostFocus(WindowlessControlHost sender, EventArgs e) { if (myDeselectOnFocusLost && sender == this) { ChangeSelection(null); } base.OnWindowlessLostFocus(sender, e); }
void BottomRightColorChanged(object sender, DependencyPropertyEventArgs e) { myVertices[1].Red = (ushort)(myBottomRightColor.Value.R << 8); myVertices[1].Green = (ushort)(myBottomRightColor.Value.G << 8); myVertices[1].Blue = (ushort)(myBottomRightColor.Value.B << 8); myVertices[1].Alpha = (ushort)(myBottomRightColor.Value.A << 8); WindowlessControlHost.WindowlessInvalidate(this); }
void RectangleWidthChanged(object sender, DependencyPropertyEventArgs e) { myPen.Width = (float)myRectangleWidth.Value; if (!myFilled.Value) { WindowlessControlHost.WindowlessInvalidate(this); } }
protected override void OnWindowlessMouseUp(WindowlessControlHost sender, WindowlessMouseEventArgs e) { if (sender == this) { OnClickUp(); } base.OnWindowlessMouseUp(sender, e); }
static bool IsFocusable(Control control) { WindowlessControlHost host = control as WindowlessControlHost; if (host != null && host.Focusable) { return(true); } return(control.TabStop); }
protected override void OnKeyPress(KeyPressEventArgs e) { WindowlessControlHost host = this; while (host != null) { host.OnWindowlessKeyPress(this, e); host = host.Parent as WindowlessControlHost; } base.OnKeyPress(e); }
public static WindowlessControlHost GetRoot(WindowlessControlHost host) { WindowlessControlHost last; do { last = host; host = host.Parent as WindowlessControlHost; }while (host != null); return(last); }
protected override void OnKeyDown(KeyEventArgs e) { WindowlessControlHost host = this; while (host != null) { host.OnWindowlessKeyDown(this, e); host = host.Parent as WindowlessControlHost; } OnWindowlessUnhandledKeyDown(this, e); base.OnKeyDown(e); }
protected override void OnWindowlessMouseDown(WindowlessControlHost sender, WindowlessMouseEventArgs e) { base.OnWindowlessMouseDown(sender, e); IWindowlessControl control = FindControlAtPoint(new Point(e.X, e.Y)); if (control == null && control != myCurrentSelection) { return; } e.Handled = true; ChangeSelection(control as IInteractiveContentPresenter); OnClickDown(); }
protected void PrepareControl() { Control host = WindowlessControlHost.GetHost(this); if (host == null) { return; } if (Parent != host) { Parent = host; } }
protected override void OnWindowlessGotFocus(WindowlessControlHost sender, EventArgs e) { if (CurrentSelection == null && Items.Count > 0) { CurrentSelection = Items[0]; } int index = Items.IndexOf(CurrentSelection); if (index != -1) { WindowlessBringIntoView(Control.Controls[index]); } base.OnWindowlessGotFocus(sender, e); }
protected override void OnMouseDown(MouseEventArgs e) { if (Focusable && !Focused) { WindowlessControlHost control = this; while (control != null) { control.OnWindowlessMouseFocus(this, e); control = control.Parent as WindowlessControlHost; } Focus(); } OnWindowlessMouseDown(this, new WindowlessMouseEventArgs(e)); base.OnMouseDown(e); }
protected override void OnWindowlessMouseFocus(WindowlessControlHost sender, MouseEventArgs e) { base.OnWindowlessMouseFocus(sender, e); if (sender != this) { return; } IWindowlessControl control = FindControlAtPoint(new Point(e.X, e.Y)); if (control == null && control != myCurrentSelection) { return; } ChangeSelection(control as IInteractiveContentPresenter); }
public static void WindowlessInvalidate(IWindowlessControl sender) { Point origin = Point.Empty; IWindowlessControl parent = sender; while (!(parent is WindowlessControlHost) && parent != null) { origin.X += parent.Left; origin.Y += parent.Top; parent = parent.Parent; } WindowlessControlHost host = parent as WindowlessControlHost; if (host != null) { host.WindowlessInvalidate(new Rectangle(origin.X, origin.Y, sender.Width, sender.Height)); } }
public static Point WindowlessPointToHost(IWindowlessControl control, Point point) { Point ret = point; if (control.Parent == null) { return(point); } IWindowlessControl host = WindowlessControlHost.GetHost(control); while (control != host) { ret.X += control.Left; ret.Y += control.Top; control = control.Parent; } return(ret); }
protected override void OnDoubleClick(EventArgs e) { Point p = PointToClient(new Point(MousePosition.X, MousePosition.Y)); Control parent = this; WindowlessMouseEventArgs we = new WindowlessMouseEventArgs(MouseButtons.Left, 1, p.X, p.Y, 0, false); while (parent != null) { WindowlessControlHost parentHost = parent as WindowlessControlHost; if (parentHost != null) { parentHost.OnWindowlessDoubleClick(this, we); } we = new WindowlessMouseEventArgs(MouseButtons.Left, 1, p.X + Left, p.Y + Top, 0, we.Handled); parent = parent.Parent; } base.OnDoubleClick(e); }
public DropdownControl(WindowlessControlHost dropdownSource, IWindowlessControl dropdownContent) { AutoScroll = true; Orientation = Orientation.Vertical; myDropdownSource = dropdownSource; OverlayPanel overlay = new OverlayPanel(); WindowlessRectangle rectangle = new WindowlessRectangle(); rectangle.Color = SystemColors.ControlDarkDark; rectangle.Filled = false; overlay.Controls.Add(rectangle); OverlayPanel inner = new OverlayPanel(); inner.Margin = new Thickness(1, 1, 1, 1); inner.Controls.Add(dropdownContent); overlay.Controls.Add(inner); overlay.FitHeightControl = overlay.FitWidthControl = inner; Control = overlay; }
public static void WindowlessBringIntoView(IWindowlessControl control) { WindowlessControlHost host = GetHost(control); host.SyncWindows(); Point p = WindowlessPointToHost(control, Point.Empty); Rectangle rect = new Rectangle(p.X, p.Y, control.Width, control.Height); while (host != null) { if (host.AutoScroll) { Point newScroll = host.AutoScrollPosition; // we favor top and left over bottom and right if (rect.Top < 0) { newScroll.Y -= rect.Top; } else if (rect.Bottom > host.Height && rect.Height <= host.Height) { newScroll.Y += (host.Height - rect.Bottom); } if (rect.Left < 0) { newScroll.X -= rect.Left; } else if (rect.Right > host.Width && rect.Width <= host.Width) { newScroll.Y += (host.Width - rect.Right); } // for some reason you need to pass in positive values to autoscroll, and it converts them to negative values... if (newScroll != host.AutoScrollPosition) { host.AutoScrollPosition = new Point(Math.Abs(newScroll.X), Math.Abs(newScroll.Y)); host.SyncWindows(); } } rect.X += host.Left; rect.Y += host.Top; host = host.Parent as WindowlessControlHost; } }
static void Control_KeyPress(object sender, KeyPressEventArgs e) { Control control = FindFocusedControl(sender as Control); if (control is WindowlessControlHost) { return; } Control parent = control; while (parent != null) { WindowlessControlHost host = parent as WindowlessControlHost; if (host != null) { host.OnWindowlessKeyPress(control, e); } parent = parent.Parent; } }
void BitmapChanged(object sender, DependencyPropertyEventArgs e) { PlatformBitmap oldBitmap = e.OldValue as PlatformBitmap; PlatformBitmap newBitmap = e.NewValue as PlatformBitmap; Size originalSize = Size.Empty; if (oldBitmap != null) { originalSize = new Size(oldBitmap.Width, oldBitmap.Height); } Size newSize = Size.Empty; if (newBitmap != null) { newSize = new Size(newBitmap.Width, newBitmap.Height); } if (originalSize != newSize) { Remeasure(); } WindowlessControlHost.WindowlessInvalidate(this); }
static void Control_KeyDown(object sender, KeyEventArgs e) { Control control = FindFocusedControl(sender as Control); if (control is WindowlessControlHost) { return; } Control parent = control; while (parent != null) { WindowlessControlHost parentHost = parent as WindowlessControlHost; if (parentHost != null) { parentHost.OnWindowlessKeyDown(control, e); } parent = parent.Parent; } OnWindowlessUnhandledKeyDown(control, e); }
static Control FindFocusable(Control control) { WindowlessControlHost host = control as WindowlessControlHost; if (host != null && host.Focusable) { return(control); } foreach (Control child in control.Controls) { // todo: add more common controls here if (IsFocusable(child)) { return(child); } Control childControl = FindFocusable(child); if (childControl != null) { return(childControl); } } return(null); }
void myDropdown_WindowlessClick(WindowlessControlHost sender, WindowlessMouseEventArgs e) { Content = myItemsControl.CurrentSelection; IsEditing = false; }
protected void OnWindowlessPaint(WindowlessControlHost sender, Graphics graphics, Point origin, Rectangle clipRectangle) { SyncWindows(); Rectangle rect = clipRectangle; Graphics g = graphics; Point o = origin; Bitmap backBuffer = null; Region oldClip = null; if (DoubleBuffer || sender == this) { PrepareBackBuffer(clipRectangle); o = Point.Empty; if (DoubleBuffer) { g = myGraphics; backBuffer = myBackBuffer; PrepareDirtyRegion(); if (myDirtyRegion.IsVisible(clipRectangle)) { RectangleF regionBounds = myDirtyRegion.GetBounds(myGraphics); rect = new Rectangle((int)Math.Round(regionBounds.X, 0), (int)Math.Round(regionBounds.Y, 0), (int)Math.Round(regionBounds.Width, 0), (int)Math.Round(regionBounds.Height, 0)); rect.Intersect(clipRectangle); myDirtyRegion.Exclude(rect); } else rect = Rectangle.Empty; } else { o = new Point(-clipRectangle.X, -clipRectangle.Y); clipRectangle.X = 0; clipRectangle.Y = 0; g = ourGraphics; backBuffer = ourBackBuffer; } oldClip = g.Clip; g.Clip = myDummyRegion; oldClip.MakeEmpty(); oldClip.Union(clipRectangle); if (DoubleBuffer) oldClip.Intersect(myDirtyRegion); g.Clip = oldClip; } if (rect.Width != 0 && rect.Height != 0) { if (BackColor == Color.Transparent) { WindowlessControlHost host = Parent as WindowlessControlHost; if (host != null) { Rectangle parentRect = rect; parentRect.X += Left; parentRect.Y += Top; host.OnWindowlessPaint(sender, g, new Point(o.X - Left, o.Y - Top), parentRect); } else g.FillRectangle(PlatformBitmap.TransparentBrush, origin.X + clipRectangle.X, origin.Y + clipRectangle.Y, clipRectangle.Width, clipRectangle.Height); } WindowlessPaintHost(this, g, o, rect); } if (DoubleBuffer || sender == this) { Rectangle sourceRectangle = clipRectangle; if (sender == this) { clipRectangle.X = -o.X; clipRectangle.Y = -o.Y; sourceRectangle.X = 0; sourceRectangle.Y = 0; } g.Clip = oldClip; if (graphics != null) graphics.DrawImage(backBuffer, new Rectangle(origin.X + clipRectangle.Left, origin.Y + clipRectangle.Top, clipRectangle.Width, clipRectangle.Height), sourceRectangle, GraphicsUnit.Pixel); } }
protected override void OnWindowlessLostFocus(WindowlessControlHost sender, EventArgs e) { if (myDeselectOnFocusLost && sender == this) ChangeSelection(null); base.OnWindowlessLostFocus(sender, e); }
protected override void OnWindowlessGotFocus(WindowlessControlHost sender, EventArgs e) { if (CurrentSelection == null && Items.Count > 0) { CurrentSelection = Items[0]; } int index = Items.IndexOf(CurrentSelection); if (index != -1) WindowlessBringIntoView(Control.Controls[index]); base.OnWindowlessGotFocus(sender, e); }
protected override void OnWindowlessMouseFocus(WindowlessControlHost sender, MouseEventArgs e) { base.OnWindowlessMouseFocus(sender, e); if (sender != this) return; IWindowlessControl control = FindControlAtPoint(new Point(e.X, e.Y)); if (control == null && control != myCurrentSelection) return; ChangeSelection(control as IInteractiveContentPresenter); }
protected override void OnWindowlessMouseDown(WindowlessControlHost sender, WindowlessMouseEventArgs e) { base.OnWindowlessMouseDown(sender, e); IWindowlessControl control = FindControlAtPoint(new Point(e.X, e.Y)); if (control == null && control != myCurrentSelection) return; e.Handled = true; ChangeSelection(control as IInteractiveContentPresenter); OnClickDown(); }
protected override void OnWindowlessNavigatingTo(WindowlessControlHost sender, WindowlessNavigateEventArgs e) { base.OnWindowlessNavigatingTo(sender, e); if (sender != this) return; // if we have a selection already, just leave it if (myCurrentSelection != null) return; if (Items.Count == 0) return; Point me = WindowlessPointToForm(this, Point.Empty); Point other = WindowlessPointToForm(e.Source, Point.Empty); Rectangle otherRect = e.SourceRectangle; otherRect.X += other.X; otherRect.Y += other.Y; Rectangle rect = new Rectangle(otherRect.X - me.X, otherRect.Y - me.Y, otherRect.Width, otherRect.Height); NavigateSelection(rect, e.Key); }
protected override void OnWindowlessMouseUp(WindowlessControlHost sender, WindowlessMouseEventArgs e) { if (sender == this) OnClickUp(); base.OnWindowlessMouseUp(sender, e); }
protected virtual void OnWindowlessDoubleClick(WindowlessControlHost sender, WindowlessMouseEventArgs e) { if (WindowlessDoubleClick != null) WindowlessDoubleClick(sender, e); }
protected virtual void OnWindowlessMouseUp(WindowlessControlHost sender, WindowlessMouseEventArgs e) { }
protected virtual void OnWindowlessGotFocus(WindowlessControlHost sender, EventArgs e) { if (WindowlessGotFocus != null) WindowlessGotFocus(sender); if (sender != this) return; // if we have focus and are unfocusable, lets just give it to the first focusable control we can find // this scenario can happen cause a common control passes focus // or the form gives the main host focus at start if (!Focusable) { Control control = FindFocusable(this); if (control != null) control.Focus(); // this control got focus from the form most likely during startup // now that it has delegated focus, set its tabstop to false. TabStop = false; } }
protected virtual void OnWindowlessLostFocus(WindowlessControlHost sender, EventArgs e) { if (WindowlessLostFocus != null) WindowlessLostFocus(sender); }
protected virtual void OnWindowlessNavigatingTo(WindowlessControlHost sender, WindowlessNavigateEventArgs e) { if (WindowlessNavigatingTo != null) WindowlessNavigatingTo(sender, e); }