[2801] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[7259] | 3 | * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[2801] | 4 | *
|
---|
| 5 | * This file is part of HeuristicLab.
|
---|
| 6 | *
|
---|
| 7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
| 8 | * it under the terms of the GNU General Public License as published by
|
---|
| 9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
| 10 | * (at your option) any later version.
|
---|
| 11 | *
|
---|
| 12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 15 | * GNU General Public License for more details.
|
---|
| 16 | *
|
---|
| 17 | * You should have received a copy of the GNU General Public License
|
---|
| 18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 19 | */
|
---|
| 20 | #endregion
|
---|
| 21 |
|
---|
| 22 | using System;
|
---|
[2781] | 23 | using System.ComponentModel;
|
---|
| 24 | using System.Drawing;
|
---|
| 25 | using System.Windows.Forms;
|
---|
| 26 |
|
---|
| 27 | using Netron.Diagramming.Core;
|
---|
| 28 |
|
---|
| 29 | namespace HeuristicLab.Netron {
|
---|
| 30 | [ToolboxItem(true)]
|
---|
| 31 | public partial class NetronVisualization : DiagramControlBase {
|
---|
[2801] | 32 | private static Size INVALID_SIZE = new Size(-1, -1);
|
---|
[2782] | 33 | private Size oldSize;
|
---|
[2781] | 34 | public NetronVisualization()
|
---|
| 35 | : base() {
|
---|
| 36 | InitializeComponent();
|
---|
[2782] | 37 | this.oldSize = INVALID_SIZE;
|
---|
[2781] | 38 |
|
---|
| 39 | SetStyle(ControlStyles.AllPaintingInWmPaint, true);
|
---|
| 40 | SetStyle(ControlStyles.DoubleBuffer, true);
|
---|
| 41 | SetStyle(ControlStyles.UserPaint, true);
|
---|
| 42 | SetStyle(ControlStyles.ResizeRedraw, true);
|
---|
| 43 |
|
---|
| 44 | if (!DesignMode) {
|
---|
| 45 | this.Controller = new Controller(this);
|
---|
[2868] | 46 | this.Document = new Document();
|
---|
[2909] | 47 | this.Document.Model.Selection = new Selection(this.Controller, this.Document.Model);
|
---|
[2781] | 48 | this.View = new View(this);
|
---|
| 49 | this.AttachToDocument(Document);
|
---|
| 50 | this.Controller.View = View;
|
---|
| 51 | TextEditor.Init(this);
|
---|
| 52 |
|
---|
| 53 | View.OnCursorChange += new EventHandler<CursorEventArgs>(mView_OnCursorChange);
|
---|
| 54 | View.OnBackColorChange += new EventHandler<ColorEventArgs>(View_OnBackColorChange);
|
---|
| 55 |
|
---|
[2782] | 56 | this.SizeChanged += new EventHandler(NetronVisualization_SizeChanged);
|
---|
[2909] | 57 | this.UpdateView();
|
---|
[2781] | 58 | }
|
---|
| 59 | }
|
---|
| 60 |
|
---|
[2909] | 61 | public Size PageSize {
|
---|
| 62 | get { return this.View.PageSize; }
|
---|
| 63 | set {
|
---|
| 64 | this.View.PageSize = value;
|
---|
| 65 | this.UpdateView();
|
---|
| 66 | }
|
---|
| 67 | }
|
---|
| 68 |
|
---|
| 69 | private void UpdateView() {
|
---|
| 70 | //zoom in to show scrollbars - code taken from ControllerBase line 1082
|
---|
| 71 | SizeF s = this.View.Magnification;
|
---|
| 72 | float alpha = 1.1F;
|
---|
| 73 | View.Magnification = new SizeF(
|
---|
| 74 | s.Width * alpha,
|
---|
| 75 | s.Height * alpha);
|
---|
| 76 |
|
---|
| 77 | float w = (float)this.AutoScrollPosition.X /
|
---|
| 78 | (float)this.AutoScrollMinSize.Width;
|
---|
| 79 |
|
---|
| 80 | float h = (float)this.AutoScrollPosition.Y /
|
---|
| 81 | (float)this.AutoScrollMinSize.Height;
|
---|
| 82 |
|
---|
| 83 | RectangleF pageBounds = this.Controller.Model.CurrentPage.Bounds;
|
---|
| 84 | pageBounds.Inflate(s);
|
---|
| 85 | SizeF deltaSize = new SizeF(
|
---|
| 86 | pageBounds.Width - this.ClientRectangle.Width,
|
---|
| 87 | pageBounds.Height - this.ClientRectangle.Height);
|
---|
| 88 |
|
---|
| 89 | if ((deltaSize.Width > 0) && (deltaSize.Height > 0)) {
|
---|
| 90 | this.AutoScrollMinSize = Size.Round(deltaSize);
|
---|
| 91 | }
|
---|
| 92 | }
|
---|
| 93 |
|
---|
[2782] | 94 | private void NetronVisualization_SizeChanged(object sender, EventArgs e) {
|
---|
[2801] | 95 | //if (this.oldSize == INVALID_SIZE) {
|
---|
[2909] | 96 | //this.View.PageSize = new Size((int)(this.Size.Width * this.Magnification.Width), (int)(this.Size.Height * this.Magnification.Height));
|
---|
[2801] | 97 | // if (!this.DesignMode)
|
---|
| 98 | // oldSize = this.Size;
|
---|
| 99 | // return;
|
---|
| 100 | //}
|
---|
[2782] | 101 |
|
---|
[2801] | 102 | //SizeF magnificationChanges = new SizeF();
|
---|
| 103 | //magnificationChanges.Width = ((float)this.Size.Width) / oldSize.Width;
|
---|
| 104 | //magnificationChanges.Height = ((float)this.Size.Height) / oldSize.Height;
|
---|
[2782] | 105 |
|
---|
[2801] | 106 | //SizeF newMagnification = new SizeF();
|
---|
| 107 | //newMagnification.Width = this.View.Magnification.Width * magnificationChanges.Width;
|
---|
| 108 | //newMagnification.Height = this.View.Magnification.Height * magnificationChanges.Height;
|
---|
[2782] | 109 |
|
---|
[2801] | 110 | //this.Magnification = newMagnification;
|
---|
| 111 | //this.oldSize = this.Size;
|
---|
[2781] | 112 | }
|
---|
| 113 |
|
---|
[3167] | 114 |
|
---|
| 115 | protected override void OnMouseWheel(MouseEventArgs e) {
|
---|
| 116 | //inserted to disable scrolling by the mousewheel
|
---|
| 117 | //base.OnMouseWheel(e);
|
---|
| 118 | }
|
---|
| 119 |
|
---|
[2781] | 120 | protected override void OnScroll(ScrollEventArgs se) {
|
---|
| 121 | //base.OnScroll(se);
|
---|
| 122 | if (se.ScrollOrientation == ScrollOrientation.HorizontalScroll) {
|
---|
| 123 | Origin = new Point(se.NewValue, Origin.Y);
|
---|
| 124 | } else {
|
---|
| 125 | Origin = new Point(Origin.X, se.NewValue);
|
---|
[2782] | 126 | }
|
---|
[2781] | 127 | }
|
---|
| 128 |
|
---|
| 129 | private void mView_OnCursorChange(object sender, CursorEventArgs e) {
|
---|
| 130 | this.Cursor = e.Cursor;
|
---|
| 131 | }
|
---|
| 132 | }
|
---|
| 133 | }
|
---|