[2801] | 1 | #region License Information
|
---|
| 2 | //This end-user license agreement applies to the following software;
|
---|
| 3 |
|
---|
| 4 | //The Netron Diagramming Library
|
---|
| 5 | //Cobalt.IDE
|
---|
| 6 | //Xeon webserver
|
---|
| 7 | //Neon UI Library
|
---|
| 8 |
|
---|
| 9 | //Copyright (C) 2007, Francois M.Vanderseypen, The Netron Project & The Orbifold
|
---|
| 10 |
|
---|
| 11 | //This program is free software; you can redistribute it and/or
|
---|
| 12 | //modify it under the terms of the GNU General Public License
|
---|
| 13 | //as published by the Free Software Foundation; either version 2
|
---|
| 14 | //of the License, or (at your option) any later version.
|
---|
| 15 |
|
---|
| 16 | //This program is distributed in the hope that it will be useful,
|
---|
| 17 | //but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 18 | //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 19 | //GNU General Public License for more details.
|
---|
| 20 |
|
---|
| 21 | //You should have received a copy of the GNU General Public License
|
---|
| 22 | //along with this program; if not, write to the Free Software
|
---|
| 23 | //Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
---|
| 24 |
|
---|
| 25 |
|
---|
| 26 | //http://www.fsf.org/licensing/licenses/gpl.html
|
---|
| 27 |
|
---|
| 28 | //http://www.fsf.org/licensing/licenses/gpl-faq.html
|
---|
| 29 | #endregion
|
---|
| 30 |
|
---|
| 31 | using System;
|
---|
[2781] | 32 | using System.Collections.Generic;
|
---|
| 33 | using System.Linq;
|
---|
| 34 | using System.Text;
|
---|
| 35 | using Netron.Diagramming.Core;
|
---|
| 36 | using System.Windows.Forms;
|
---|
| 37 | using System.Drawing;
|
---|
| 38 |
|
---|
| 39 | namespace HeuristicLab.Netron {
|
---|
| 40 | public static class TextEditor {
|
---|
| 41 |
|
---|
| 42 | private static TextEditorControl editor = null;
|
---|
| 43 | private static ITextProvider myTextProvider;
|
---|
| 44 | private static IDiagramControl diagramControl;
|
---|
| 45 |
|
---|
| 46 | private static EventHandler<MouseEventArgs> onescape =
|
---|
| 47 | new EventHandler<MouseEventArgs>(Controller_OnMouseDown);
|
---|
| 48 |
|
---|
| 49 | private static ITextProvider TextProvider {
|
---|
| 50 | get { return myTextProvider; }
|
---|
| 51 | }
|
---|
| 52 |
|
---|
| 53 | private static TextEditorControl Editor {
|
---|
| 54 | get {
|
---|
| 55 | if (editor == null)
|
---|
| 56 | editor = new TextEditorControl();
|
---|
| 57 | return editor;
|
---|
| 58 | }
|
---|
| 59 | }
|
---|
| 60 |
|
---|
| 61 | public static void Init(DiagramControlBase parent) {
|
---|
| 62 | diagramControl = parent;
|
---|
| 63 | parent.Controls.Add(Editor);
|
---|
| 64 | Editor.Visible = false;
|
---|
| 65 | Editor.BackColor = Color.White;
|
---|
| 66 | }
|
---|
| 67 |
|
---|
| 68 | public static TextEditorControl GetEditor(ITextProvider textProvider) {
|
---|
| 69 | if (textProvider == null) {
|
---|
| 70 | throw new InconsistencyException(
|
---|
| 71 | "Cannot assign an editor to a 'null' text provider.");
|
---|
| 72 | }
|
---|
| 73 |
|
---|
| 74 | // Adjust the editor's location and size by the current scroll
|
---|
| 75 | // position and zoom factor.
|
---|
| 76 | Point location = Point.Round(diagramControl.View.WorldToView(
|
---|
| 77 | textProvider.TextArea.Location));
|
---|
| 78 |
|
---|
| 79 | Size size = Size.Round(diagramControl.View.WorldToView(
|
---|
| 80 | textProvider.TextArea.Size));
|
---|
| 81 |
|
---|
| 82 | myTextProvider = textProvider;
|
---|
| 83 | Editor.Location = location;
|
---|
| 84 | Editor.Width = size.Width;
|
---|
| 85 | Editor.Height = size.Height;
|
---|
| 86 | Editor.Font = textProvider.TextStyle.Font;
|
---|
| 87 | Editor.Visible = false;
|
---|
| 88 | return Editor;
|
---|
| 89 | }
|
---|
| 90 |
|
---|
| 91 | public static void Show() {
|
---|
| 92 | if (myTextProvider == null)
|
---|
| 93 | return;
|
---|
| 94 | Selection.Clear();
|
---|
| 95 | diagramControl.View.ResetTracker();
|
---|
| 96 | diagramControl.Controller.SuspendAllTools();
|
---|
| 97 | diagramControl.Controller.Enabled = false;
|
---|
| 98 | diagramControl.Controller.OnMouseDown += onescape;
|
---|
| 99 | Editor.Visible = true;
|
---|
| 100 | Editor.Text = myTextProvider.Text;
|
---|
| 101 |
|
---|
| 102 | if (myTextProvider.TextStyle.HorizontalAlignment == StringAlignment.Center)
|
---|
| 103 | Editor.TextAlign = HorizontalAlignment.Center;
|
---|
| 104 | else if (myTextProvider.TextStyle.HorizontalAlignment == StringAlignment.Far)
|
---|
| 105 | Editor.TextAlign = HorizontalAlignment.Right;
|
---|
| 106 | else
|
---|
| 107 | Editor.TextAlign = HorizontalAlignment.Left;
|
---|
| 108 |
|
---|
| 109 | Editor.SelectionLength = Editor.Text.Length;
|
---|
| 110 | Editor.ScrollToCaret();
|
---|
| 111 | Editor.Focus();
|
---|
| 112 | }
|
---|
| 113 |
|
---|
| 114 | static void Controller_OnMouseDown(object sender, MouseEventArgs e) {
|
---|
| 115 | Hide();
|
---|
| 116 | diagramControl.Controller.OnMouseDown -= onescape;
|
---|
| 117 | }
|
---|
| 118 |
|
---|
| 119 | public static void Hide() {
|
---|
| 120 | if (myTextProvider == null)
|
---|
| 121 | return;
|
---|
| 122 | diagramControl.Controller.Enabled = true;
|
---|
| 123 | diagramControl.Focus();
|
---|
| 124 | Editor.Visible = false;
|
---|
| 125 | myTextProvider.Text = Editor.Text;
|
---|
| 126 | diagramControl.Controller.UnsuspendAllTools();
|
---|
| 127 | myTextProvider = null;
|
---|
| 128 | }
|
---|
| 129 |
|
---|
| 130 | public class TextEditorControl : TextBox {
|
---|
| 131 | public TextEditorControl()
|
---|
| 132 | : base() {
|
---|
| 133 | this.BorderStyle = BorderStyle.FixedSingle;
|
---|
| 134 | this.Multiline = true;
|
---|
| 135 | this.ScrollBars = ScrollBars.None;
|
---|
| 136 | this.WordWrap = true;
|
---|
| 137 | this.BackColor = Color.White;
|
---|
| 138 | }
|
---|
| 139 |
|
---|
| 140 | }
|
---|
| 141 |
|
---|
| 142 | }
|
---|
| 143 | }
|
---|