[2801] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
| 3 | * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
| 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.Collections.Generic;
|
---|
| 24 | using System.ComponentModel;
|
---|
| 25 | using System.Drawing;
|
---|
| 26 | using System.Data;
|
---|
| 27 | using System.Linq;
|
---|
| 28 | using System.Text;
|
---|
| 29 | using System.Windows.Forms;
|
---|
| 30 |
|
---|
| 31 | using Netron.Diagramming.Core;
|
---|
| 32 |
|
---|
| 33 | namespace HeuristicLab.Netron {
|
---|
| 34 | [ToolboxItem(true)]
|
---|
| 35 | public partial class NetronVisualization : DiagramControlBase {
|
---|
[2801] | 36 | private static Size INVALID_SIZE = new Size(-1, -1);
|
---|
[2782] | 37 | private Size oldSize;
|
---|
[2781] | 38 | public NetronVisualization()
|
---|
| 39 | : base() {
|
---|
| 40 | InitializeComponent();
|
---|
[2782] | 41 | this.oldSize = INVALID_SIZE;
|
---|
[2781] | 42 |
|
---|
| 43 | SetStyle(ControlStyles.AllPaintingInWmPaint, true);
|
---|
| 44 | SetStyle(ControlStyles.DoubleBuffer, true);
|
---|
| 45 | SetStyle(ControlStyles.UserPaint, true);
|
---|
| 46 | SetStyle(ControlStyles.ResizeRedraw, true);
|
---|
| 47 |
|
---|
| 48 | if (!DesignMode) {
|
---|
| 49 | this.Controller = new Controller(this);
|
---|
[2868] | 50 | this.Document = new Document();
|
---|
[2909] | 51 | this.Document.Model.Selection = new Selection(this.Controller, this.Document.Model);
|
---|
[2781] | 52 | this.View = new View(this);
|
---|
| 53 | this.AttachToDocument(Document);
|
---|
| 54 | this.Controller.View = View;
|
---|
| 55 | TextEditor.Init(this);
|
---|
| 56 |
|
---|
| 57 | View.OnCursorChange += new EventHandler<CursorEventArgs>(mView_OnCursorChange);
|
---|
| 58 | View.OnBackColorChange += new EventHandler<ColorEventArgs>(View_OnBackColorChange);
|
---|
| 59 |
|
---|
[2782] | 60 | this.SizeChanged += new EventHandler(NetronVisualization_SizeChanged);
|
---|
[2909] | 61 | this.UpdateView();
|
---|
[2781] | 62 | }
|
---|
| 63 | }
|
---|
| 64 |
|
---|
[2909] | 65 | public Size PageSize {
|
---|
| 66 | get { return this.View.PageSize; }
|
---|
| 67 | set {
|
---|
| 68 | this.View.PageSize = value;
|
---|
| 69 | this.UpdateView();
|
---|
| 70 | }
|
---|
| 71 | }
|
---|
| 72 |
|
---|
| 73 | private void UpdateView() {
|
---|
| 74 | //zoom in to show scrollbars - code taken from ControllerBase line 1082
|
---|
| 75 | SizeF s = this.View.Magnification;
|
---|
| 76 | float alpha = 1.1F;
|
---|
| 77 | View.Magnification = new SizeF(
|
---|
| 78 | s.Width * alpha,
|
---|
| 79 | s.Height * alpha);
|
---|
| 80 |
|
---|
| 81 | float w = (float)this.AutoScrollPosition.X /
|
---|
| 82 | (float)this.AutoScrollMinSize.Width;
|
---|
| 83 |
|
---|
| 84 | float h = (float)this.AutoScrollPosition.Y /
|
---|
| 85 | (float)this.AutoScrollMinSize.Height;
|
---|
| 86 |
|
---|
| 87 | RectangleF pageBounds = this.Controller.Model.CurrentPage.Bounds;
|
---|
| 88 | pageBounds.Inflate(s);
|
---|
| 89 | SizeF deltaSize = new SizeF(
|
---|
| 90 | pageBounds.Width - this.ClientRectangle.Width,
|
---|
| 91 | pageBounds.Height - this.ClientRectangle.Height);
|
---|
| 92 |
|
---|
| 93 | if ((deltaSize.Width > 0) && (deltaSize.Height > 0)) {
|
---|
| 94 | this.AutoScrollMinSize = Size.Round(deltaSize);
|
---|
| 95 | }
|
---|
| 96 | }
|
---|
| 97 |
|
---|
[2782] | 98 | private void NetronVisualization_SizeChanged(object sender, EventArgs e) {
|
---|
[2801] | 99 | //if (this.oldSize == INVALID_SIZE) {
|
---|
[2909] | 100 | //this.View.PageSize = new Size((int)(this.Size.Width * this.Magnification.Width), (int)(this.Size.Height * this.Magnification.Height));
|
---|
[2801] | 101 | // if (!this.DesignMode)
|
---|
| 102 | // oldSize = this.Size;
|
---|
| 103 | // return;
|
---|
| 104 | //}
|
---|
[2782] | 105 |
|
---|
[2801] | 106 | //SizeF magnificationChanges = new SizeF();
|
---|
| 107 | //magnificationChanges.Width = ((float)this.Size.Width) / oldSize.Width;
|
---|
| 108 | //magnificationChanges.Height = ((float)this.Size.Height) / oldSize.Height;
|
---|
[2782] | 109 |
|
---|
[2801] | 110 | //SizeF newMagnification = new SizeF();
|
---|
| 111 | //newMagnification.Width = this.View.Magnification.Width * magnificationChanges.Width;
|
---|
| 112 | //newMagnification.Height = this.View.Magnification.Height * magnificationChanges.Height;
|
---|
[2782] | 113 |
|
---|
[2801] | 114 | //this.Magnification = newMagnification;
|
---|
| 115 | //this.oldSize = this.Size;
|
---|
[2781] | 116 | }
|
---|
| 117 |
|
---|
| 118 | protected override void OnScroll(ScrollEventArgs se) {
|
---|
| 119 | //base.OnScroll(se);
|
---|
| 120 | if (se.ScrollOrientation == ScrollOrientation.HorizontalScroll) {
|
---|
| 121 | Origin = new Point(se.NewValue, Origin.Y);
|
---|
| 122 | //System.Diagnostics.Trace.WriteLine(se.NewValue);
|
---|
| 123 | } else {
|
---|
| 124 | Origin = new Point(Origin.X, se.NewValue);
|
---|
| 125 | //System.Diagnostics.Trace.WriteLine(se.NewValue);
|
---|
[2782] | 126 | }
|
---|
[2781] | 127 | }
|
---|
| 128 |
|
---|
| 129 | private void mView_OnCursorChange(object sender, CursorEventArgs e) {
|
---|
| 130 | this.Cursor = e.Cursor;
|
---|
| 131 | }
|
---|
| 132 | }
|
---|
| 133 | }
|
---|