[2768] | 1 | using System;
|
---|
| 2 | using System.Drawing;
|
---|
| 3 | using System.Windows.Forms;
|
---|
[3167] | 4 | namespace Netron.Diagramming.Core {
|
---|
| 5 | // ----------------------------------------------------------------------
|
---|
| 6 | /// <summary>
|
---|
| 7 | /// Abstract base implementation of the <see cref="IController"/>
|
---|
| 8 | /// interface.
|
---|
| 9 | /// </summary>
|
---|
| 10 | // ----------------------------------------------------------------------
|
---|
| 11 | public abstract class ControllerBase : IUndoSupport, IController {
|
---|
| 12 | #region Events
|
---|
| 13 |
|
---|
| 14 | // ------------------------------------------------------------------
|
---|
[2768] | 15 | /// <summary>
|
---|
[3167] | 16 | /// Occurs when the context menu is shown.
|
---|
[2768] | 17 | /// </summary>
|
---|
[3167] | 18 | // ------------------------------------------------------------------
|
---|
| 19 | public event EventHandler<EntityMenuEventArgs> OnShowContextMenu;
|
---|
[2768] | 20 |
|
---|
[3167] | 21 | // ------------------------------------------------------------------
|
---|
| 22 | /// <summary>
|
---|
| 23 | /// Occurs when a tool is asked to be deactivated.
|
---|
| 24 | /// </summary>
|
---|
| 25 | // ------------------------------------------------------------------
|
---|
| 26 | public event EventHandler<ToolEventArgs> OnToolDeactivate;
|
---|
[2768] | 27 |
|
---|
[3167] | 28 | // ------------------------------------------------------------------
|
---|
| 29 | /// <summary>
|
---|
| 30 | /// Occurs when a tool is asked to be activated.
|
---|
| 31 | /// </summary>
|
---|
| 32 | // ------------------------------------------------------------------
|
---|
| 33 | public event EventHandler<ToolEventArgs> OnToolActivate;
|
---|
[2768] | 34 |
|
---|
[3167] | 35 | // ------------------------------------------------------------------
|
---|
| 36 | /// <summary>
|
---|
| 37 | /// Occurs when the history has changed in the undo/redo mechanism.
|
---|
| 38 | /// </summary>
|
---|
| 39 | // ------------------------------------------------------------------
|
---|
| 40 | public event EventHandler<HistoryChangeEventArgs> OnHistoryChange;
|
---|
[2768] | 41 |
|
---|
[3167] | 42 | // ------------------------------------------------------------------
|
---|
| 43 | /// <summary>
|
---|
| 44 | /// Occurs when the something got selected and the properties of it
|
---|
| 45 | /// can/should be shown.
|
---|
| 46 | /// </summary>
|
---|
| 47 | // ------------------------------------------------------------------
|
---|
| 48 | public event EventHandler<SelectionEventArgs> OnShowSelectionProperties;
|
---|
[2768] | 49 |
|
---|
[3167] | 50 | // ------------------------------------------------------------------
|
---|
| 51 | /// <summary>
|
---|
| 52 | /// Occurs when an entity is added.
|
---|
| 53 | /// <remarks>This event usually is bubbled from one of the
|
---|
| 54 | /// layers.</remarks>
|
---|
| 55 | /// </summary>
|
---|
| 56 | // ------------------------------------------------------------------
|
---|
| 57 | public event EventHandler<EntityEventArgs> OnEntityAdded;
|
---|
[2768] | 58 |
|
---|
[3167] | 59 | // ------------------------------------------------------------------
|
---|
| 60 | /// <summary>
|
---|
| 61 | /// Occurs when an entity is removed.
|
---|
| 62 | /// <remarks>This event usually is bubbled from one of the
|
---|
| 63 | /// layers.</remarks>
|
---|
| 64 | /// </summary>
|
---|
| 65 | // ------------------------------------------------------------------
|
---|
| 66 | public event EventHandler<EntityEventArgs> OnEntityRemoved;
|
---|
[2768] | 67 |
|
---|
[3167] | 68 | // ------------------------------------------------------------------
|
---|
| 69 | /// <summary>
|
---|
| 70 | /// Occurs when the controller receives a mouse-down notification of
|
---|
| 71 | /// the surface. This event is raised before the
|
---|
| 72 | /// event is broadcasted down to the tools.
|
---|
| 73 | /// </summary>
|
---|
| 74 | // ------------------------------------------------------------------
|
---|
| 75 | public event EventHandler<MouseEventArgs> OnMouseDown;
|
---|
[2768] | 76 |
|
---|
[3167] | 77 | // ------------------------------------------------------------------
|
---|
| 78 | /// <summary>
|
---|
| 79 | /// Occurs when the Ambience has changed.
|
---|
| 80 | /// </summary>
|
---|
| 81 | // ------------------------------------------------------------------
|
---|
| 82 | public event EventHandler<AmbienceEventArgs> OnAmbienceChanged;
|
---|
[2768] | 83 |
|
---|
| 84 |
|
---|
[3167] | 85 | #endregion
|
---|
[2768] | 86 |
|
---|
[3167] | 87 | #region Tool Names
|
---|
[2768] | 88 |
|
---|
[3167] | 89 | public const string AlignBottomEdgesToolName =
|
---|
| 90 | "Align Bottom Edges Tool";
|
---|
[2768] | 91 |
|
---|
[3167] | 92 | public const string AlignCentersHorizToolName =
|
---|
| 93 | "Align Centers Horizontally";
|
---|
[2768] | 94 |
|
---|
[3167] | 95 | public const string AlignCentersVertToolName =
|
---|
| 96 | "Align Centers Vertically";
|
---|
[2768] | 97 |
|
---|
[3167] | 98 | public const string AlignLeftEdgesToolName =
|
---|
| 99 | "Align Left Edges Tool";
|
---|
[2768] | 100 |
|
---|
[3167] | 101 | public const string AlignRightEdgesToolName =
|
---|
| 102 | "Align Right Edges Tool";
|
---|
[2768] | 103 |
|
---|
[3167] | 104 | public const string AlignTopEdgesToolName =
|
---|
| 105 | "Align Top Edges Tool";
|
---|
[2768] | 106 |
|
---|
[3167] | 107 | public const string ComplexRectangleToolName = "ComplexRectangle Tool";
|
---|
| 108 | public const string ConnectionToolName = "Connection Tool";
|
---|
| 109 | public const string ConnectorMoverToolName = "Connector Mover Tool";
|
---|
| 110 | public const string ContextToolName = "Context Tool";
|
---|
| 111 | public const string CopyToolName = "Copy Tool";
|
---|
| 112 | public const string CutToolName = "Cut Tool";
|
---|
| 113 | public const string DeleteToolName = "Delete Tool";
|
---|
| 114 | public const string DragDropToolName = "DragDrop Tool";
|
---|
| 115 | public const string EllipseToolName = "Ellipse Tool";
|
---|
| 116 | public const string GroupToolName = "Group Tool";
|
---|
| 117 | public const string HitToolName = "Hit Tool";
|
---|
| 118 | public const string HoverToolName = "Hover Tool";
|
---|
| 119 | public const string ImageExportToolName = "Image Export Tool";
|
---|
| 120 | public const string MoveToolName = "Move Tool";
|
---|
| 121 | public const string MultiLineToolName = "MultiLine Tool";
|
---|
| 122 | public const string PanToolName = "Pan Tool";
|
---|
| 123 | public const string PasteToolName = "Paste Tool";
|
---|
| 124 | public const string PolygonToolName = "Polygon Tool";
|
---|
| 125 | public const string RectangleToolName = "Rectangle Tool";
|
---|
| 126 | public const string ScribbleToolName = "Scribble Tool";
|
---|
| 127 | public const string SelectionToolName = "Selection Tool";
|
---|
| 128 | public const string SendBackwardsToolName = "SendBackwards Tool";
|
---|
| 129 | public const string SendForwardsToolName = "SendForwards Tool";
|
---|
| 130 | public const string SendToBackToolName = "SendToBack Tool";
|
---|
| 131 | public const string SendToFrontToolName = "SendToFront Tool";
|
---|
| 132 | public const string TransformToolName = "Transform Tool";
|
---|
| 133 | public const string UngroupToolName = "Ungroup Tool";
|
---|
| 134 | public const string ZoomAreaToolName = "Zoom Area Tool";
|
---|
| 135 | public const string ZoomInToolName = "Zoom In Tool";
|
---|
| 136 | public const string ZoomOutToolName = "Zoom Out Tool";
|
---|
[2768] | 137 |
|
---|
[3167] | 138 | #endregion
|
---|
[2768] | 139 |
|
---|
[3167] | 140 | #region Fields
|
---|
[2768] | 141 |
|
---|
[3167] | 142 | private bool eventsEnabled = true;
|
---|
| 143 | private bool controllerEnabled = true;
|
---|
[2768] | 144 |
|
---|
[3167] | 145 | private IModel mModel;
|
---|
| 146 | private UndoManager mUndoManager;
|
---|
| 147 | ITool activeTool;
|
---|
[2768] | 148 |
|
---|
[3167] | 149 | /// <summary>
|
---|
| 150 | /// the View field
|
---|
| 151 | /// </summary>
|
---|
| 152 | private IView mView;
|
---|
[3355] | 153 | protected CollectionBase<IMouseListener> mouseListeners;
|
---|
| 154 | protected CollectionBase<IKeyboardListener> keyboardListeners;
|
---|
| 155 | protected CollectionBase<IDragDropListener> dragdropListeners;
|
---|
| 156 | protected IDiagramControl parentControl;
|
---|
| 157 | protected CollectionBase<ITool> registeredTools;
|
---|
| 158 | protected CollectionBase<IActivity> registeredActivity;
|
---|
[2768] | 159 |
|
---|
[3167] | 160 | #endregion
|
---|
[2768] | 161 |
|
---|
[3167] | 162 | #region Properties
|
---|
[2768] | 163 |
|
---|
[3167] | 164 | /// <summary>
|
---|
| 165 | /// Gets or sets a value indicating whether this <see cref="T:ControllerBase"/> is enabled.
|
---|
| 166 | /// </summary>
|
---|
| 167 | /// <value><c>true</c> if enabled; otherwise, <c>false</c>.</value>
|
---|
| 168 | public bool Enabled {
|
---|
| 169 | get {
|
---|
| 170 | return controllerEnabled;
|
---|
| 171 | }
|
---|
| 172 | set {
|
---|
| 173 | controllerEnabled = value;
|
---|
| 174 | }
|
---|
| 175 | }
|
---|
[2768] | 176 |
|
---|
[3167] | 177 | // ------------------------------------------------------------------
|
---|
| 178 | /// <summary>
|
---|
| 179 | /// Gets the currently active tool. This can be 'null'!!!
|
---|
| 180 | /// </summary>
|
---|
| 181 | // ------------------------------------------------------------------
|
---|
| 182 | public ITool ActiveTool {
|
---|
| 183 | get {
|
---|
| 184 | return this.activeTool;
|
---|
| 185 | }
|
---|
| 186 | }
|
---|
[2768] | 187 |
|
---|
[3167] | 188 | /// <summary>
|
---|
| 189 | /// Gets or sets the parent control.
|
---|
| 190 | /// </summary>
|
---|
| 191 | /// <value>The parent control.</value>
|
---|
| 192 | public IDiagramControl ParentControl {
|
---|
| 193 | get { return parentControl; }
|
---|
| 194 | internal set { parentControl = value; }
|
---|
| 195 | }
|
---|
| 196 | /// <summary>
|
---|
| 197 | /// Gets the registered tools.
|
---|
| 198 | /// </summary>
|
---|
| 199 | /// <value>The tools.</value>
|
---|
| 200 | public CollectionBase<ITool> Tools {
|
---|
| 201 | get { return registeredTools; }
|
---|
| 202 | }
|
---|
[2768] | 203 |
|
---|
| 204 |
|
---|
| 205 |
|
---|
[3167] | 206 | /// <summary>
|
---|
| 207 | /// Gets the undo manager.
|
---|
| 208 | /// </summary>
|
---|
| 209 | /// <value>The undo manager.</value>
|
---|
| 210 | public UndoManager UndoManager {
|
---|
| 211 | get {
|
---|
| 212 | return mUndoManager;
|
---|
| 213 | }
|
---|
[2768] | 214 |
|
---|
[3167] | 215 | }
|
---|
[2768] | 216 |
|
---|
[3167] | 217 | /// <summary>
|
---|
| 218 | /// Gets or sets the model
|
---|
| 219 | /// </summary>
|
---|
| 220 | /// <value></value>
|
---|
| 221 | public IModel Model {
|
---|
| 222 | get {
|
---|
| 223 | return mModel;
|
---|
| 224 | }
|
---|
| 225 | set {
|
---|
| 226 | AttachToModel(value);
|
---|
| 227 | }
|
---|
| 228 | }
|
---|
[2768] | 229 |
|
---|
[3167] | 230 | /// <summary>
|
---|
| 231 | /// Gets or sets the view.
|
---|
| 232 | /// </summary>
|
---|
| 233 | /// <value>The view.</value>
|
---|
| 234 | public IView View {
|
---|
| 235 | get {
|
---|
| 236 | return mView;
|
---|
| 237 | }
|
---|
| 238 | set {
|
---|
| 239 | AttachToView(value);
|
---|
| 240 | }
|
---|
| 241 | }
|
---|
[2768] | 242 |
|
---|
[3167] | 243 | /// <summary>
|
---|
| 244 | /// Attaches to the given view.
|
---|
| 245 | /// </summary>
|
---|
| 246 | /// <param name="view">The view.</param>
|
---|
| 247 | private void AttachToView(IView view) {
|
---|
| 248 | if (view == null)
|
---|
| 249 | throw new ArgumentNullException();
|
---|
[2768] | 250 |
|
---|
[3167] | 251 | mView = view;
|
---|
| 252 | }
|
---|
| 253 | #endregion
|
---|
[2768] | 254 |
|
---|
[3167] | 255 | #region Constructor
|
---|
[2768] | 256 |
|
---|
[3167] | 257 | // ------------------------------------------------------------------
|
---|
| 258 | /// <summary>
|
---|
| 259 | /// Default constructor.
|
---|
| 260 | /// </summary>
|
---|
| 261 | // ------------------------------------------------------------------
|
---|
| 262 | protected ControllerBase(IDiagramControl surface) {
|
---|
| 263 | //doesn't work if you supply a null reference
|
---|
| 264 | if (surface == null) {
|
---|
| 265 | throw new NullReferenceException(
|
---|
| 266 | "The diagram control assigned to the controller " +
|
---|
| 267 | "cannot be 'null'");
|
---|
| 268 | }
|
---|
[2768] | 269 |
|
---|
[3167] | 270 | //create the undo/redo manager
|
---|
| 271 | mUndoManager = new UndoManager(15);
|
---|
| 272 | mUndoManager.OnHistoryChange += new EventHandler(
|
---|
| 273 | mUndoManager_OnHistoryChange);
|
---|
[2768] | 274 |
|
---|
[3167] | 275 | #region Instantiation of listeners
|
---|
| 276 | mouseListeners = new CollectionBase<IMouseListener>();
|
---|
| 277 | keyboardListeners = new CollectionBase<IKeyboardListener>();
|
---|
| 278 | dragdropListeners = new CollectionBase<IDragDropListener>();
|
---|
| 279 | #endregion
|
---|
[2768] | 280 |
|
---|
[3167] | 281 | //keep a reference to the parent control
|
---|
| 282 | parentControl = surface;
|
---|
| 283 |
|
---|
| 284 | AttachToSurface(parentControl);
|
---|
| 285 |
|
---|
| 286 |
|
---|
| 287 |
|
---|
| 288 | //Initialize the colorscheme
|
---|
| 289 | ArtPalette.Init();
|
---|
| 290 |
|
---|
| 291 | #region Tools: the registration order matters!
|
---|
| 292 | /*
|
---|
[2768] | 293 | The order in in which the tools are added matters, at least
|
---|
| 294 | some of them.
|
---|
| 295 | * The TransformTool should come before the HitTool and the
|
---|
| 296 | MoveTool after the HitTool.
|
---|
| 297 | * The order of the drawing tools does not matter.
|
---|
| 298 | * It's also important to remark that the tools do not depend
|
---|
| 299 | on the Model.
|
---|
| 300 | */
|
---|
| 301 |
|
---|
[3167] | 302 | registeredTools = new CollectionBase<ITool>();
|
---|
[2768] | 303 |
|
---|
[3167] | 304 | this.AddTool(new TransformTool(TransformToolName));
|
---|
[2768] | 305 |
|
---|
[3167] | 306 | this.AddTool(new HitTool(HitToolName));
|
---|
[2768] | 307 |
|
---|
[3167] | 308 | this.AddTool(new MoveTool(MoveToolName));
|
---|
[2768] | 309 |
|
---|
[3167] | 310 | this.AddTool(new RectangleTool(RectangleToolName));
|
---|
[2768] | 311 |
|
---|
[3167] | 312 | this.AddTool(new ComplexRectangleTool(ComplexRectangleToolName));
|
---|
[2768] | 313 |
|
---|
[3167] | 314 | this.AddTool(new EllipseTool(EllipseToolName));
|
---|
[2768] | 315 |
|
---|
[3167] | 316 | this.AddTool(new SelectionTool(SelectionToolName));
|
---|
[2768] | 317 |
|
---|
[3167] | 318 | this.AddTool(new DragDropTool(DragDropToolName));
|
---|
[2768] | 319 |
|
---|
[3167] | 320 | this.AddTool(new ConnectionTool(ConnectionToolName));
|
---|
[2768] | 321 |
|
---|
[3167] | 322 | this.AddTool(new ConnectorMoverTool(ConnectorMoverToolName));
|
---|
[2768] | 323 |
|
---|
[3167] | 324 | this.AddTool(new GroupTool(GroupToolName));
|
---|
[2768] | 325 |
|
---|
[3167] | 326 | this.AddTool(new UngroupTool(UngroupToolName));
|
---|
[2768] | 327 |
|
---|
[3167] | 328 | this.AddTool(new SendToBackTool(SendToBackToolName));
|
---|
[2768] | 329 |
|
---|
[3167] | 330 | this.AddTool(new SendBackwardsTool(SendBackwardsToolName));
|
---|
[2768] | 331 |
|
---|
[3167] | 332 | this.AddTool(new SendForwardsTool(SendForwardsToolName));
|
---|
[2768] | 333 |
|
---|
[3167] | 334 | this.AddTool(new SendToFrontTool(SendToFrontToolName));
|
---|
[2768] | 335 |
|
---|
[3167] | 336 | this.AddTool(new HoverTool(HoverToolName));
|
---|
[2768] | 337 |
|
---|
[3167] | 338 | this.AddTool(new ContextTool(ContextToolName));
|
---|
[2768] | 339 |
|
---|
[3167] | 340 | this.AddTool(new CopyTool(CopyToolName));
|
---|
[2768] | 341 |
|
---|
[3167] | 342 | this.AddTool(new CutTool(CutToolName));
|
---|
[2768] | 343 |
|
---|
[3167] | 344 | this.AddTool(new PasteTool(PasteToolName));
|
---|
[2768] | 345 |
|
---|
[3167] | 346 | this.AddTool(new DeleteTool(DeleteToolName));
|
---|
[2768] | 347 |
|
---|
[3167] | 348 | this.AddTool(new ScribbleTool(ScribbleToolName));
|
---|
[2768] | 349 |
|
---|
[3167] | 350 | this.AddTool(new PolygonTool(PolygonToolName));
|
---|
[2768] | 351 |
|
---|
[3167] | 352 | this.AddTool(new MultiLineTool(MultiLineToolName));
|
---|
[2768] | 353 |
|
---|
[3167] | 354 | this.AddTool(new AlignBottomEdgesTool(AlignBottomEdgesToolName));
|
---|
[2768] | 355 |
|
---|
[3167] | 356 | this.AddTool(
|
---|
| 357 | new AlignCentersHorizontallyTool(AlignCentersHorizToolName));
|
---|
[2768] | 358 |
|
---|
[3167] | 359 | this.AddTool(
|
---|
| 360 | new AlignCentersVerticallyTool(AlignCentersVertToolName));
|
---|
[2768] | 361 |
|
---|
[3167] | 362 | this.AddTool(new AlignLeftEdgesTool(AlignLeftEdgesToolName));
|
---|
[2768] | 363 |
|
---|
[3167] | 364 | this.AddTool(new AlignRightEdgesTool(AlignRightEdgesToolName));
|
---|
[2768] | 365 |
|
---|
[3167] | 366 | this.AddTool(new AlignTopEdgesTool(AlignTopEdgesToolName));
|
---|
[2768] | 367 |
|
---|
[3167] | 368 | this.AddTool(new ZoomAreaTool(ZoomAreaToolName));
|
---|
[2768] | 369 |
|
---|
[3167] | 370 | this.AddTool(new ZoomInTool(ZoomInToolName));
|
---|
[2768] | 371 |
|
---|
[3167] | 372 | this.AddTool(new ZoomOutTool(ZoomOutToolName));
|
---|
[2768] | 373 |
|
---|
[3167] | 374 | this.AddTool(new PanTool(PanToolName));
|
---|
[2768] | 375 |
|
---|
[3167] | 376 | this.AddTool(new ImageExportTool(ImageExportToolName));
|
---|
[2768] | 377 |
|
---|
[3167] | 378 | #endregion
|
---|
[2768] | 379 |
|
---|
[3167] | 380 | #region Hotkeys
|
---|
| 381 | HotKeys keys = new HotKeys(this);
|
---|
| 382 | this.keyboardListeners.Add(keys);
|
---|
| 383 | #endregion
|
---|
[2768] | 384 |
|
---|
[3167] | 385 | #region Activities
|
---|
| 386 | // This is in a way a waste of memory; the layouts should not
|
---|
| 387 | // necessarily be loaded before they are actually requested.
|
---|
| 388 | // You could register only the (string) names instead.
|
---|
| 389 | // But for just a few algorithms this is OK and the advantage
|
---|
| 390 | // of this registration is that one can register actions from
|
---|
| 391 | // outside the library, in the hosting form for example.
|
---|
| 392 | registeredActivity = new CollectionBase<IActivity>();
|
---|
| 393 | AddActivity(new RandomLayout(this));
|
---|
| 394 | AddActivity(new FruchtermanReingoldLayout(this));
|
---|
| 395 | AddActivity(new StandardTreeLayout(this));
|
---|
| 396 | AddActivity(new RadialTreeLayout(this));
|
---|
| 397 | AddActivity(new BalloonTreeLayout(this));
|
---|
| 398 | AddActivity(new ForceDirectedLayout(this));
|
---|
| 399 | #endregion
|
---|
| 400 | }
|
---|
[2768] | 401 |
|
---|
[3167] | 402 | #endregion
|
---|
[2768] | 403 |
|
---|
[3167] | 404 | // ------------------------------------------------------------------
|
---|
| 405 | /// <summary>
|
---|
| 406 | /// Attaches the given model to the controller.
|
---|
| 407 | /// </summary>
|
---|
| 408 | /// <param name="model">IModel</param>
|
---|
| 409 | // ------------------------------------------------------------------
|
---|
| 410 | protected virtual void AttachToModel(IModel model) {
|
---|
| 411 | if (model == null)
|
---|
| 412 | throw new ArgumentNullException();
|
---|
[2768] | 413 |
|
---|
[3167] | 414 | mModel = model;
|
---|
| 415 | mModel.OnEntityAdded +=
|
---|
| 416 | new EventHandler<EntityEventArgs>(mModel_OnEntityAdded);
|
---|
| 417 | mModel.OnEntityRemoved +=
|
---|
| 418 | new EventHandler<EntityEventArgs>(mModel_OnEntityRemoved);
|
---|
| 419 | mModel.OnAmbienceChanged +=
|
---|
| 420 | new EventHandler<AmbienceEventArgs>(mModel_OnAmbienceChanged);
|
---|
| 421 | }
|
---|
[2768] | 422 |
|
---|
[3167] | 423 | // ------------------------------------------------------------------
|
---|
| 424 | /// <summary>
|
---|
| 425 | /// Passes the OnAmbienceChanged event on.
|
---|
| 426 | /// </summary>
|
---|
| 427 | /// <param name="sender">object</param>
|
---|
| 428 | /// <param name="e">AmbienceEventArgs</param>
|
---|
| 429 | // ------------------------------------------------------------------
|
---|
| 430 | void mModel_OnAmbienceChanged(
|
---|
| 431 | object sender,
|
---|
| 432 | AmbienceEventArgs e) {
|
---|
| 433 | RaiseOnAmbienceChanged(e);
|
---|
| 434 | }
|
---|
[2768] | 435 |
|
---|
[3167] | 436 | // ------------------------------------------------------------------
|
---|
| 437 | /// <summary>
|
---|
| 438 | /// Passes the OnEntityRemoved event on.
|
---|
| 439 | /// </summary>
|
---|
| 440 | /// <param name="sender">object</param>
|
---|
| 441 | /// <param name="e">EntityEventArgs</param>
|
---|
| 442 | // ------------------------------------------------------------------
|
---|
| 443 | void mModel_OnEntityRemoved(
|
---|
| 444 | object sender,
|
---|
| 445 | EntityEventArgs e) {
|
---|
| 446 | RaiseOnEntityRemoved(e);
|
---|
| 447 | }
|
---|
[2768] | 448 |
|
---|
[3167] | 449 | // ------------------------------------------------------------------
|
---|
| 450 | /// <summary>
|
---|
| 451 | /// Passes the OnEntityAdded event on.
|
---|
| 452 | /// </summary>
|
---|
| 453 | /// <param name="sender">object</param>
|
---|
| 454 | /// <param name="e">EntityEventArgs</param>
|
---|
| 455 | // ------------------------------------------------------------------
|
---|
| 456 | void mModel_OnEntityAdded(
|
---|
| 457 | object sender,
|
---|
| 458 | EntityEventArgs e) {
|
---|
| 459 | RaiseOnEntityAdded(e);
|
---|
| 460 | }
|
---|
[2768] | 461 |
|
---|
[3167] | 462 | // ------------------------------------------------------------------
|
---|
| 463 | /// <summary>
|
---|
| 464 | /// Bubbles the OnHistoryChange event.
|
---|
| 465 | /// </summary>
|
---|
| 466 | /// <param name="sender">The source of the event.</param>
|
---|
| 467 | /// <param name="e">The <see cref="T:System.EventArgs"/> instance
|
---|
| 468 | /// containing the event data.</param>
|
---|
| 469 | // ------------------------------------------------------------------
|
---|
| 470 | void mUndoManager_OnHistoryChange(object sender, EventArgs e) {
|
---|
| 471 | RaiseOnHistoryChange();
|
---|
| 472 | }
|
---|
[2768] | 473 |
|
---|
[3167] | 474 | #region Methods
|
---|
[2768] | 475 |
|
---|
[3167] | 476 | // ------------------------------------------------------------------
|
---|
| 477 | /// <summary>
|
---|
| 478 | /// Activates the text editor for the given text provider.
|
---|
| 479 | /// </summary>
|
---|
| 480 | /// <param name="textProvider">ITextProvider</param>
|
---|
| 481 | /// <returns>bool: True if sucessful, false if not.</returns>
|
---|
| 482 | // ------------------------------------------------------------------
|
---|
| 483 | public abstract bool ActivateTextEditor(ITextProvider textProvider);
|
---|
[2768] | 484 |
|
---|
[3167] | 485 | // ------------------------------------------------------------------
|
---|
| 486 | /// <summary>
|
---|
| 487 | /// Changes the paint style of the selected entities.
|
---|
| 488 | /// </summary>
|
---|
| 489 | /// <param name="paintStyle">IPaintStyle</param>
|
---|
| 490 | // ------------------------------------------------------------------
|
---|
| 491 | public void ChangeStyle(IPaintStyle paintStyle) {
|
---|
[2768] | 492 |
|
---|
[3167] | 493 | // Note that you need a copy of the selected item otherwise the
|
---|
| 494 | // undo/redo will fail once the selection has changed
|
---|
| 495 | FillStyleCommand cmd = new FillStyleCommand(
|
---|
| 496 | this,
|
---|
| 497 | this.Model.Selection.SelectedItems.Copy(),
|
---|
| 498 | paintStyle);
|
---|
[2768] | 499 |
|
---|
[3167] | 500 | this.UndoManager.AddUndoCommand(cmd);
|
---|
| 501 | cmd.Redo();
|
---|
| 502 | }
|
---|
[2768] | 503 |
|
---|
[3167] | 504 | // ------------------------------------------------------------------
|
---|
| 505 | /// <summary>
|
---|
| 506 | /// Changes the pen style of the selected entities.
|
---|
| 507 | /// </summary>
|
---|
| 508 | /// <param name="penStyle">The pen style.</param>
|
---|
| 509 | // ------------------------------------------------------------------
|
---|
| 510 | public void ChangeStyle(IPenStyle penStyle) {
|
---|
| 511 | PenStyleCommand cmd = new PenStyleCommand(
|
---|
| 512 | this,
|
---|
| 513 | this.Model.Selection.SelectedItems.Copy(),
|
---|
| 514 | penStyle);
|
---|
[2768] | 515 |
|
---|
[3167] | 516 | this.UndoManager.AddUndoCommand(cmd);
|
---|
[2768] | 517 |
|
---|
[3167] | 518 | cmd.Redo();
|
---|
| 519 | }
|
---|
[2768] | 520 |
|
---|
[3167] | 521 | #region Event Raisers
|
---|
[2768] | 522 |
|
---|
[3167] | 523 | // ------------------------------------------------------------------
|
---|
| 524 | /// <summary>
|
---|
| 525 | /// Raises the OnShowContextMenu event
|
---|
| 526 | /// </summary>
|
---|
| 527 | /// <param name="e">EntityMenuEventArgs</param>
|
---|
| 528 | // ------------------------------------------------------------------
|
---|
| 529 | public virtual void RaiseOnShowContextMenu(EntityMenuEventArgs e) {
|
---|
| 530 | EventHandler<EntityMenuEventArgs> handler = OnShowContextMenu;
|
---|
| 531 | if (handler != null) {
|
---|
| 532 | handler(this, e);
|
---|
| 533 | }
|
---|
| 534 | }
|
---|
[2768] | 535 |
|
---|
[3167] | 536 | // ------------------------------------------------------------------
|
---|
| 537 | /// <summary>
|
---|
| 538 | /// Raises the OnHistory change.
|
---|
| 539 | /// </summary>
|
---|
| 540 | // ------------------------------------------------------------------
|
---|
| 541 | public virtual void RaiseOnHistoryChange() {
|
---|
| 542 | EventHandler<HistoryChangeEventArgs> handler = OnHistoryChange;
|
---|
| 543 | if (handler != null) {
|
---|
| 544 | handler(this, new HistoryChangeEventArgs(
|
---|
| 545 | this.UndoManager.RedoText,
|
---|
| 546 | this.UndoManager.UndoText));
|
---|
| 547 | }
|
---|
| 548 | }
|
---|
[2768] | 549 |
|
---|
[3167] | 550 | // ------------------------------------------------------------------
|
---|
| 551 | /// <summary>
|
---|
| 552 | /// Raises the <see cref="OnToolDeactivate"/> event.
|
---|
| 553 | /// </summary>
|
---|
| 554 | /// <param name="e">ConnectionCollection event argument</param>
|
---|
| 555 | // ------------------------------------------------------------------
|
---|
| 556 | public virtual void RaiseOnToolDeactivate(ToolEventArgs e) {
|
---|
| 557 | EventHandler<ToolEventArgs> handler = OnToolDeactivate;
|
---|
| 558 | if (handler != null) {
|
---|
| 559 | handler(this, e);
|
---|
| 560 | }
|
---|
| 561 | }
|
---|
[2768] | 562 |
|
---|
[3167] | 563 | // ------------------------------------------------------------------
|
---|
| 564 | /// <summary>
|
---|
| 565 | /// Raises the <see cref="OnToolActivate"/> event
|
---|
| 566 | /// </summary>
|
---|
| 567 | /// <param name="e">ConnectionCollection event argument</param>
|
---|
| 568 | // ------------------------------------------------------------------
|
---|
| 569 | public virtual void RaiseOnToolActivate(ToolEventArgs e) {
|
---|
| 570 | EventHandler<ToolEventArgs> handler = OnToolActivate;
|
---|
| 571 | if (handler != null) {
|
---|
| 572 | handler(this, e);
|
---|
| 573 | }
|
---|
| 574 | }
|
---|
[2768] | 575 |
|
---|
[3167] | 576 | // ------------------------------------------------------------------
|
---|
| 577 | /// <summary>
|
---|
| 578 | /// Raises the OnShowSelectionProperties event.
|
---|
| 579 | /// </summary>
|
---|
| 580 | /// <param name="e">The
|
---|
| 581 | /// <see cref="T:Netron.Diagramming.Core.SelectionEventArgs"/>
|
---|
| 582 | /// instance containing the event data.</param>
|
---|
| 583 | // ------------------------------------------------------------------
|
---|
| 584 | public virtual void RaiseOnShowSelectionProperties(SelectionEventArgs e) {
|
---|
| 585 | EventHandler<SelectionEventArgs> handler = OnShowSelectionProperties;
|
---|
| 586 | if (handler != null) {
|
---|
| 587 | handler(this, e);
|
---|
| 588 | }
|
---|
| 589 | }
|
---|
[2768] | 590 |
|
---|
[3167] | 591 | // ------------------------------------------------------------------
|
---|
| 592 | /// <summary>
|
---|
| 593 | /// Raises the <see cref="OnMouseDown "/> event.
|
---|
| 594 | /// </summary>
|
---|
| 595 | /// <param name="e">The
|
---|
| 596 | /// <see cref="T:System.Windows.Forms.MouseEventArgs"/> instance
|
---|
| 597 | /// containing the event data.</param>
|
---|
| 598 | // ------------------------------------------------------------------
|
---|
| 599 | protected virtual void RaiseOnMouseDown(MouseEventArgs e) {
|
---|
| 600 | if (OnMouseDown != null)
|
---|
| 601 | OnMouseDown(this, e);
|
---|
| 602 | }
|
---|
[2768] | 603 |
|
---|
[3167] | 604 | // ------------------------------------------------------------------
|
---|
| 605 | /// <summary>
|
---|
| 606 | /// Raises the <see cref="OnEntityAdded"/> event.
|
---|
| 607 | /// </summary>
|
---|
| 608 | /// <param name="e">The
|
---|
| 609 | /// <see cref="T:Netron.Diagramming.Core.EntityEventArgs"/> instance
|
---|
| 610 | /// containing the event data.</param>
|
---|
| 611 | // ------------------------------------------------------------------
|
---|
| 612 | protected virtual void RaiseOnEntityAdded(EntityEventArgs e) {
|
---|
| 613 | EventHandler<EntityEventArgs> handler = OnEntityAdded;
|
---|
| 614 | if (handler != null) {
|
---|
| 615 | handler(this, e);
|
---|
| 616 | }
|
---|
| 617 | }
|
---|
[2768] | 618 |
|
---|
[3167] | 619 | // ------------------------------------------------------------------
|
---|
| 620 | /// <summary>
|
---|
| 621 | /// Raises the <see cref="OnEntityRemoved"/> event.
|
---|
| 622 | /// </summary>
|
---|
| 623 | /// <param name="e">The
|
---|
| 624 | /// <see cref="T:Netron.Diagramming.Core.EntityEventArgs"/> instance
|
---|
| 625 | /// containing the event data.</param>
|
---|
| 626 | // ------------------------------------------------------------------
|
---|
| 627 | protected virtual void RaiseOnEntityRemoved(EntityEventArgs e) {
|
---|
| 628 | EventHandler<EntityEventArgs> handler = OnEntityRemoved;
|
---|
| 629 | if (handler != null) {
|
---|
| 630 | handler(this, e);
|
---|
| 631 | }
|
---|
| 632 | }
|
---|
[2768] | 633 |
|
---|
[3167] | 634 | // ------------------------------------------------------------------
|
---|
| 635 | /// <summary>
|
---|
| 636 | /// Raises the <see cref="OnAmbienceChanged"/> event.
|
---|
| 637 | /// </summary>
|
---|
| 638 | /// <param name="e">AmbienceEventArgs</param>
|
---|
| 639 | // ------------------------------------------------------------------
|
---|
| 640 | protected virtual void RaiseOnAmbienceChanged(AmbienceEventArgs e) {
|
---|
| 641 | EventHandler<AmbienceEventArgs> handler = OnAmbienceChanged;
|
---|
| 642 | if (handler != null) {
|
---|
| 643 | handler(this, e);
|
---|
| 644 | }
|
---|
| 645 | }
|
---|
[2768] | 646 |
|
---|
[3167] | 647 | #endregion
|
---|
[2768] | 648 |
|
---|
[3167] | 649 | #region Tool (de)activation methods
|
---|
[2768] | 650 |
|
---|
[3167] | 651 | // ------------------------------------------------------------------
|
---|
| 652 | /// <summary>
|
---|
| 653 | /// Deactivates the given tool.
|
---|
| 654 | /// </summary>
|
---|
| 655 | /// <param name="tool">a registered ITool</param>
|
---|
| 656 | /// <returns>bool: True if successful.</returns>
|
---|
| 657 | // ------------------------------------------------------------------
|
---|
| 658 | public bool DeactivateTool(ITool tool) {
|
---|
| 659 | bool flag = false;
|
---|
| 660 | if (tool != null && tool.Enabled && tool.IsActive) {
|
---|
| 661 | //IEnumerator iEnumerator = tools.GetEnumerator();
|
---|
| 662 | //Tool tool2 = null;
|
---|
| 663 | //while (iEnumerator.MoveNext())
|
---|
| 664 | //{
|
---|
| 665 | // tool2 = iEnumerator.Current is Tool;
|
---|
| 666 | // if (tool2 != null && tool2 != tool)
|
---|
| 667 | // {
|
---|
| 668 | // tool2.ToolDeactivating(tool);
|
---|
| 669 | // }
|
---|
| 670 | //}
|
---|
| 671 | flag = tool.DeactivateTool();
|
---|
| 672 | if (flag && eventsEnabled) {
|
---|
| 673 | RaiseOnToolDeactivate(new ToolEventArgs(tool));
|
---|
[2768] | 674 | }
|
---|
[3167] | 675 | }
|
---|
| 676 | return flag;
|
---|
| 677 | }
|
---|
[2768] | 678 |
|
---|
[3167] | 679 | // ------------------------------------------------------------------
|
---|
| 680 | /// <summary>
|
---|
| 681 | /// Deactivates all tools.
|
---|
| 682 | /// </summary>
|
---|
| 683 | /// <returns>bool: True if successful.</returns>
|
---|
| 684 | // ------------------------------------------------------------------
|
---|
| 685 | public bool DeactivateAllTools() {
|
---|
| 686 | bool successful = true;
|
---|
[2768] | 687 |
|
---|
[3167] | 688 | // If the deactivation of any tool returns false, then we will
|
---|
| 689 | // return false.
|
---|
| 690 | foreach (ITool tool in this.Tools) {
|
---|
| 691 | successful = successful & this.DeactivateTool(tool);
|
---|
| 692 | }
|
---|
| 693 | this.activeTool = null;
|
---|
| 694 | return successful;
|
---|
| 695 | }
|
---|
[2768] | 696 |
|
---|
[3167] | 697 | // ------------------------------------------------------------------
|
---|
| 698 | /// <summary>
|
---|
| 699 | /// Activates the tool with the given name
|
---|
| 700 | /// </summary>
|
---|
| 701 | /// <param name="toolName"></param>
|
---|
| 702 | // ------------------------------------------------------------------
|
---|
| 703 | public void ActivateTool(string toolName) {
|
---|
| 704 | if (!controllerEnabled)
|
---|
| 705 | return;
|
---|
[2768] | 706 |
|
---|
[3167] | 707 | //using anonymous method here
|
---|
| 708 | Predicate<ITool> predicate = delegate(ITool tool) {
|
---|
| 709 | if (tool.Name.ToLower() == toolName.ToLower())//not case sensitive
|
---|
| 710 | return true;
|
---|
| 711 | else
|
---|
| 712 | return false;
|
---|
| 713 | };
|
---|
[2768] | 714 |
|
---|
[3167] | 715 | // First deactivate the current tool.
|
---|
| 716 | if (this.activeTool != null) {
|
---|
| 717 | this.activeTool.DeactivateTool();
|
---|
| 718 | }
|
---|
| 719 | ITool foundTool = this.registeredTools.Find(predicate);
|
---|
| 720 | ActivateTool(foundTool);
|
---|
| 721 | }
|
---|
[2768] | 722 |
|
---|
[3167] | 723 | // ------------------------------------------------------------------
|
---|
| 724 | /// <summary>
|
---|
| 725 | /// Suspends all tools
|
---|
| 726 | /// </summary>
|
---|
| 727 | // ------------------------------------------------------------------
|
---|
| 728 | public void SuspendAllTools() {
|
---|
| 729 | foreach (ITool tool in this.Tools) {
|
---|
| 730 | tool.IsSuspended = true;
|
---|
| 731 | }
|
---|
| 732 | }
|
---|
[2768] | 733 |
|
---|
[3167] | 734 | // ------------------------------------------------------------------
|
---|
| 735 | /// <summary>
|
---|
| 736 | /// Unsuspends all tools.
|
---|
| 737 | /// </summary>
|
---|
| 738 | // ------------------------------------------------------------------
|
---|
| 739 | public void UnsuspendAllTools() {
|
---|
| 740 | foreach (ITool tool in this.Tools) {
|
---|
| 741 | tool.IsSuspended = false;
|
---|
| 742 | }
|
---|
| 743 | }
|
---|
| 744 |
|
---|
| 745 | // ------------------------------------------------------------------
|
---|
| 746 | /// <summary>
|
---|
| 747 | /// Activates a registered tool
|
---|
| 748 | /// </summary>
|
---|
| 749 | /// <param name="tool">a registered ITool</param>
|
---|
| 750 | /// <returns>bool: Returns if the activation was successful. True is
|
---|
| 751 | /// returned if it was, false if not.</returns>
|
---|
| 752 | // ------------------------------------------------------------------
|
---|
| 753 | private bool ActivateTool(ITool tool) {
|
---|
| 754 | if (!controllerEnabled)
|
---|
| 755 | return false;
|
---|
| 756 | bool flag = false;
|
---|
| 757 | if (tool != null && tool.CanActivate) {
|
---|
| 758 | flag = tool.ActivateTool();
|
---|
| 759 | this.activeTool = tool;
|
---|
| 760 | if (flag && eventsEnabled) {
|
---|
| 761 | RaiseOnToolActivate(new ToolEventArgs(tool));
|
---|
[2768] | 762 | }
|
---|
[3167] | 763 | }
|
---|
| 764 | return flag;
|
---|
| 765 | }
|
---|
[2768] | 766 |
|
---|
[3167] | 767 | #endregion
|
---|
[2768] | 768 |
|
---|
[3167] | 769 | // ------------------------------------------------------------------
|
---|
| 770 | /// <summary>
|
---|
| 771 | /// Adds the given tool.
|
---|
| 772 | /// </summary>
|
---|
| 773 | /// <param name="tool">The tool.</param>
|
---|
| 774 | // ------------------------------------------------------------------
|
---|
| 775 | public void AddTool(ITool tool) {
|
---|
| 776 | tool.Controller = this;
|
---|
| 777 | // Add the tool to the collection even if it doesn't attach to
|
---|
| 778 | // anything (yet)
|
---|
| 779 | registeredTools.Add(tool);
|
---|
[2768] | 780 |
|
---|
[3167] | 781 | IMouseListener mouseTool = null;
|
---|
| 782 | if ((mouseTool = tool as IMouseListener) != null)
|
---|
| 783 | mouseListeners.Add(mouseTool);
|
---|
[2768] | 784 |
|
---|
[3167] | 785 | IKeyboardListener keyboardTool = null;
|
---|
| 786 | if ((keyboardTool = tool as IKeyboardListener) != null)
|
---|
| 787 | keyboardListeners.Add(keyboardTool);
|
---|
[2768] | 788 |
|
---|
[3167] | 789 | IDragDropListener dragdropTool = null;
|
---|
| 790 | if ((dragdropTool = tool as IDragDropListener) != null)
|
---|
| 791 | dragdropListeners.Add(dragdropTool);
|
---|
[2768] | 792 |
|
---|
[3167] | 793 | // Watch when the tool is (de)activated so we can pass it on.
|
---|
| 794 | tool.OnToolActivate +=
|
---|
| 795 | new EventHandler<ToolEventArgs>(AddedTool_OnToolActivate);
|
---|
[2768] | 796 |
|
---|
[3167] | 797 | tool.OnToolDeactivate +=
|
---|
| 798 | new EventHandler<ToolEventArgs>(AddedTool_OnToolDeactivate);
|
---|
| 799 | }
|
---|
[2768] | 800 |
|
---|
[3167] | 801 | // ------------------------------------------------------------------
|
---|
| 802 | /// <summary>
|
---|
| 803 | /// Called when an added tool is deactivated. The event is passed on
|
---|
| 804 | /// by calling RaiseOnToolDeactivate.
|
---|
| 805 | /// </summary>
|
---|
| 806 | /// <param name="sender">object</param>
|
---|
| 807 | /// <param name="e">ToolEventArgs</param>
|
---|
| 808 | // ------------------------------------------------------------------
|
---|
[3355] | 809 | protected void AddedTool_OnToolDeactivate(object sender, ToolEventArgs e) {
|
---|
[3167] | 810 | ITool nextActiveToolInList = null;
|
---|
| 811 | if (this.activeTool == e.Properties) {
|
---|
| 812 | foreach (ITool tool in this.Tools) {
|
---|
| 813 | if (tool.IsActive) {
|
---|
| 814 | nextActiveToolInList = tool;
|
---|
| 815 | break;
|
---|
| 816 | }
|
---|
[2768] | 817 | }
|
---|
[3167] | 818 | activeTool = nextActiveToolInList;
|
---|
| 819 | }
|
---|
| 820 | this.RaiseOnToolDeactivate(e);
|
---|
| 821 | }
|
---|
[2768] | 822 |
|
---|
[3167] | 823 | // ------------------------------------------------------------------
|
---|
| 824 | /// <summary>
|
---|
| 825 | /// Called when an added tool is activated. The event is passed on
|
---|
| 826 | /// by calling RaiseOnToolActivate.
|
---|
| 827 | /// </summary>
|
---|
| 828 | /// <param name="sender">object</param>
|
---|
| 829 | /// <param name="e">ToolEventArgs</param>
|
---|
| 830 | // ------------------------------------------------------------------
|
---|
[3355] | 831 | protected void AddedTool_OnToolActivate(object sender, ToolEventArgs e) {
|
---|
[3167] | 832 | this.RaiseOnToolActivate(e);
|
---|
| 833 | }
|
---|
[2768] | 834 |
|
---|
[3167] | 835 | #region Activity
|
---|
[2768] | 836 |
|
---|
[3167] | 837 | // ------------------------------------------------------------------
|
---|
| 838 | /// <summary>
|
---|
| 839 | /// Adds the given activity to the controller.
|
---|
| 840 | /// </summary>
|
---|
| 841 | /// <param name="activity">The activity.</param>
|
---|
| 842 | // ------------------------------------------------------------------
|
---|
| 843 | public void AddActivity(IActivity activity) {
|
---|
[2768] | 844 |
|
---|
[3167] | 845 | registeredActivity.Add(activity);
|
---|
| 846 | }
|
---|
[2768] | 847 |
|
---|
[3167] | 848 | // ------------------------------------------------------------------
|
---|
| 849 | /// <summary>
|
---|
| 850 | /// Runs the given activity.
|
---|
| 851 | /// </summary>
|
---|
| 852 | /// <param name="activity">The activity.</param>
|
---|
| 853 | // ------------------------------------------------------------------
|
---|
| 854 | protected void RunActivity(IActivity activity) {
|
---|
| 855 | if (activity == null) return;
|
---|
| 856 | PrepareActivity(activity);
|
---|
[2768] | 857 |
|
---|
[3167] | 858 | activity.Run();
|
---|
[2768] | 859 |
|
---|
[3167] | 860 | }
|
---|
[2768] | 861 |
|
---|
[3167] | 862 | // ------------------------------------------------------------------
|
---|
| 863 | /// <summary>
|
---|
| 864 | /// Runs the given activity.
|
---|
| 865 | /// </summary>
|
---|
| 866 | /// <param name="activity">The activity.</param>
|
---|
| 867 | /// <param name="milliseconds">The milliseconds.</param>
|
---|
| 868 | // ------------------------------------------------------------------
|
---|
| 869 | protected void RunActivity(IActivity activity, int milliseconds) {
|
---|
| 870 | if (activity == null) return;
|
---|
| 871 | PrepareActivity(activity);
|
---|
| 872 | activity.Run(milliseconds);
|
---|
| 873 | }
|
---|
[2768] | 874 |
|
---|
[3167] | 875 | // ------------------------------------------------------------------
|
---|
| 876 | /// <summary>
|
---|
| 877 | /// Prepares the activity.
|
---|
| 878 | /// </summary>
|
---|
| 879 | /// <param name="activity">The activity.</param>
|
---|
| 880 | // ------------------------------------------------------------------
|
---|
| 881 | private void PrepareActivity(IActivity activity) {
|
---|
| 882 | if (activity is IAction)
|
---|
| 883 | (activity as IAction).Model = this.Model;
|
---|
| 884 | if (activity is ILayout) {
|
---|
| 885 | (activity as ILayout).Bounds = parentControl.ClientRectangle;
|
---|
| 886 | (activity as ILayout).Center = new PointF(parentControl.ClientRectangle.Width / 2, parentControl.ClientRectangle.Height / 2);
|
---|
| 887 | }
|
---|
| 888 | }
|
---|
[2768] | 889 |
|
---|
[3167] | 890 | // ------------------------------------------------------------------
|
---|
| 891 | /// <summary>
|
---|
| 892 | /// Runs the activity with the name specified. If no activity could
|
---|
| 893 | /// by found with the given name then an exception is thrown.
|
---|
| 894 | /// </summary>
|
---|
| 895 | /// <param name="activityName">string: The name of the
|
---|
| 896 | /// activity to run.</param>
|
---|
| 897 | // ------------------------------------------------------------------
|
---|
| 898 | public void RunActivity(string activityName) {
|
---|
| 899 | if (!controllerEnabled)
|
---|
| 900 | return;
|
---|
[2768] | 901 |
|
---|
[3167] | 902 | this.View.CurrentCursor = Cursors.WaitCursor;
|
---|
| 903 | controllerEnabled = false;
|
---|
[2768] | 904 |
|
---|
[3167] | 905 | IActivity foundActivity = FindActivity(activityName);
|
---|
| 906 | if (foundActivity != null) {
|
---|
| 907 | RunActivity(foundActivity);
|
---|
| 908 | }
|
---|
[2768] | 909 |
|
---|
[3167] | 910 | controllerEnabled = true;
|
---|
| 911 | this.View.CurrentCursor = Cursors.Default;
|
---|
[2768] | 912 |
|
---|
[3167] | 913 | // After returning the canvas back to "normal", if the activity
|
---|
| 914 | // wasn't found throw an exception (as specified by IController).
|
---|
| 915 | if (foundActivity == null) {
|
---|
| 916 | throw new Exception("Activity '" + activityName +
|
---|
| 917 | "' could not be found.");
|
---|
| 918 | }
|
---|
| 919 | }
|
---|
[2768] | 920 |
|
---|
[3167] | 921 | // ------------------------------------------------------------------
|
---|
| 922 | /// <summary>
|
---|
| 923 | /// Finds the activity with the given name.
|
---|
| 924 | /// </summary>
|
---|
| 925 | /// <param name="name">The name.</param>
|
---|
| 926 | /// <returns>IActivity</returns>
|
---|
| 927 | // ------------------------------------------------------------------
|
---|
| 928 | protected IActivity FindActivity(string name) {
|
---|
| 929 | //using anonymous method here
|
---|
| 930 | Predicate<IActivity> predicate = delegate(IActivity activity) {
|
---|
| 931 | if (activity.Name.ToLower() == name.ToLower())//not case sensitive
|
---|
| 932 | return true;
|
---|
| 933 | else
|
---|
| 934 | return false;
|
---|
| 935 | };
|
---|
| 936 | return this.registeredActivity.Find(predicate);
|
---|
[2768] | 937 |
|
---|
[3167] | 938 | }
|
---|
[2768] | 939 |
|
---|
[3167] | 940 | // ------------------------------------------------------------------
|
---|
| 941 | /// <summary>
|
---|
| 942 | /// Runs the given activity for the specified time span.
|
---|
| 943 | /// </summary>
|
---|
| 944 | /// <param name="name">The name.</param>
|
---|
| 945 | /// <param name="milliseconds">The milliseconds.</param>
|
---|
| 946 | // ------------------------------------------------------------------
|
---|
| 947 | public void RunActivity(string name, int milliseconds) {
|
---|
| 948 | if (!controllerEnabled)
|
---|
| 949 | return;
|
---|
[2768] | 950 |
|
---|
[3167] | 951 | IActivity foundActivity = FindActivity(name);
|
---|
| 952 | if (foundActivity != null)
|
---|
| 953 | RunActivity(foundActivity, milliseconds);
|
---|
| 954 | }
|
---|
[2768] | 955 |
|
---|
[3167] | 956 | #endregion
|
---|
[2768] | 957 |
|
---|
[3167] | 958 | // ------------------------------------------------------------------
|
---|
| 959 | /// <summary>
|
---|
| 960 | /// Attaches this controller to the surface.
|
---|
| 961 | /// </summary>
|
---|
| 962 | /// <param name="surface">The surface.</param>
|
---|
| 963 | // ------------------------------------------------------------------
|
---|
| 964 | protected virtual void AttachToSurface(IDiagramControl surface) {
|
---|
| 965 | #region Mouse events
|
---|
| 966 | surface.MouseDown += new MouseEventHandler(OnSurfaceMouseDown);
|
---|
| 967 | surface.MouseUp += new MouseEventHandler(OnSurfaceMouseUp);
|
---|
| 968 | surface.MouseMove += new MouseEventHandler(OnSurfaceMouseMove);
|
---|
| 969 | surface.MouseHover += new EventHandler(OnSurfaceMouseHover);
|
---|
| 970 | surface.MouseWheel += new MouseEventHandler(surface_MouseWheel);
|
---|
| 971 | #endregion
|
---|
[2768] | 972 |
|
---|
[3167] | 973 | #region Keyboard events
|
---|
| 974 | surface.KeyDown += new KeyEventHandler(surface_KeyDown);
|
---|
| 975 | surface.KeyUp += new KeyEventHandler(surface_KeyUp);
|
---|
| 976 | surface.KeyPress += new KeyPressEventHandler(surface_KeyPress);
|
---|
| 977 | #endregion
|
---|
[2768] | 978 |
|
---|
[3167] | 979 | #region Dragdrop events
|
---|
| 980 | surface.DragDrop += new DragEventHandler(surface_DragDrop);
|
---|
| 981 | surface.DragEnter += new DragEventHandler(surface_DragEnter);
|
---|
| 982 | surface.DragLeave += new EventHandler(surface_DragLeave);
|
---|
| 983 | surface.DragOver += new DragEventHandler(surface_DragOver);
|
---|
| 984 | surface.GiveFeedback +=
|
---|
| 985 | new GiveFeedbackEventHandler(surface_GiveFeedback);
|
---|
| 986 | #endregion
|
---|
| 987 | }
|
---|
[2768] | 988 |
|
---|
[3167] | 989 | // ------------------------------------------------------------------
|
---|
| 990 | /// <summary>
|
---|
| 991 | /// Handles the MouseWheel event of the surface control.
|
---|
| 992 | /// <remarks>In the WinForm implementation this routine is not called
|
---|
| 993 | /// because it gives some flickering effects; the hotkeys are
|
---|
| 994 | /// implemented in the overriden OnMouseWheel method instead.</remarks>
|
---|
| 995 | /// </summary>
|
---|
| 996 | /// <param name="sender">The source of the event.</param>
|
---|
| 997 | /// <param name="e">The
|
---|
| 998 | /// <see cref="T:System.Windows.Forms.MouseEventArgs"/> instance
|
---|
| 999 | /// containing the event data.</param>
|
---|
| 1000 | // ------------------------------------------------------------------
|
---|
| 1001 | void surface_MouseWheel(object sender, MouseEventArgs e) {
|
---|
| 1002 | Point p = View.Origin;
|
---|
| 1003 | SizeF magnification = View.Magnification;
|
---|
| 1004 | int newValue = 0;
|
---|
[2768] | 1005 |
|
---|
[3167] | 1006 | if ((Control.ModifierKeys & Keys.Control) == Keys.Control) {
|
---|
| 1007 | #region Zooming
|
---|
[2768] | 1008 |
|
---|
[3167] | 1009 | SizeF s = magnification;
|
---|
[2768] | 1010 |
|
---|
[3167] | 1011 | // If zooming in, e.Delta is < 0 so a value of 1.1 is used to
|
---|
| 1012 | // offset the current magnification by. One mouse wheel
|
---|
| 1013 | // position on my PC corresponds to a delta of 120 (positive
|
---|
| 1014 | // for zooming out, neg for zooming in).
|
---|
| 1015 | float alpha = e.Delta > 0 ? 1.1F : 0.9F;
|
---|
| 1016 | View.Magnification = new SizeF(
|
---|
| 1017 | s.Width * alpha,
|
---|
| 1018 | s.Height * alpha);
|
---|
[2768] | 1019 |
|
---|
[3167] | 1020 | float w = (float)parentControl.AutoScrollPosition.X /
|
---|
| 1021 | (float)parentControl.AutoScrollMinSize.Width;
|
---|
[2768] | 1022 |
|
---|
[3167] | 1023 | float h = (float)parentControl.AutoScrollPosition.Y /
|
---|
| 1024 | (float)parentControl.AutoScrollMinSize.Height;
|
---|
[2768] | 1025 |
|
---|
[3167] | 1026 | // Resize the scrollbars proportionally to keep the actual
|
---|
| 1027 | // canvas constant.
|
---|
| 1028 | //s = new SizeF(
|
---|
| 1029 | // parentControl.AutoScrollMinSize.Width * alpha,
|
---|
| 1030 | // parentControl.AutoScrollMinSize.Height * alpha);
|
---|
[2768] | 1031 |
|
---|
[3167] | 1032 | //parentControl.AutoScrollMinSize = Size.Round(s);
|
---|
| 1033 | RectangleF pageBounds = Model.CurrentPage.Bounds;
|
---|
| 1034 | pageBounds.Inflate(s);
|
---|
| 1035 | SizeF deltaSize = new SizeF(
|
---|
| 1036 | pageBounds.Width - parentControl.ClientRectangle.Width,
|
---|
| 1037 | pageBounds.Height - parentControl.ClientRectangle.Height);
|
---|
[2768] | 1038 |
|
---|
[3167] | 1039 | if ((deltaSize.Width > 0) && (deltaSize.Height > 0)) {
|
---|
| 1040 | parentControl.AutoScrollMinSize = Size.Round(deltaSize);
|
---|
| 1041 | }
|
---|
[2768] | 1042 |
|
---|
[3167] | 1043 | //Point v = Origin;
|
---|
| 1044 | //v.Offset(
|
---|
| 1045 | // Convert.ToInt32((alpha - 1) * v.X),
|
---|
| 1046 | // Convert.ToInt32((alpha - 1) * v.Y));
|
---|
| 1047 | //v.X = (int)Math.Round((double)(v.X - alpha));
|
---|
| 1048 | //v.Y = (int)Math.Round((double)(v.Y - alpha));
|
---|
| 1049 | //Origin = v;
|
---|
[2768] | 1050 |
|
---|
[3167] | 1051 | #endregion
|
---|
| 1052 | } else if ((Control.ModifierKeys & Keys.Shift) == Keys.Shift) {
|
---|
| 1053 | #region Pan horizontal
|
---|
| 1054 | newValue = p.X - Math.Sign(e.Delta) * 20;
|
---|
| 1055 | if (newValue > 0)
|
---|
| 1056 | View.Origin = new Point(newValue, p.Y);
|
---|
| 1057 | else
|
---|
| 1058 | View.Origin = new Point(0, p.Y);
|
---|
[2768] | 1059 |
|
---|
[3167] | 1060 | #endregion
|
---|
| 1061 | } else {
|
---|
| 1062 | #region Default vertical scroll
|
---|
| 1063 | newValue = View.Origin.Y -
|
---|
| 1064 | Math.Sign(e.Delta) * 20;
|
---|
[2768] | 1065 |
|
---|
[3167] | 1066 | if (newValue > 0)
|
---|
| 1067 | View.Origin = new Point(
|
---|
| 1068 | View.Origin.X,
|
---|
| 1069 | newValue);
|
---|
| 1070 | else
|
---|
| 1071 | View.Origin = new Point(
|
---|
| 1072 | View.Origin.X,
|
---|
| 1073 | 0);
|
---|
| 1074 | #endregion
|
---|
| 1075 | }
|
---|
[2768] | 1076 |
|
---|
[3167] | 1077 | this.parentControl.AutoScrollPosition = View.Origin;
|
---|
| 1078 | HandledMouseEventArgs eventargs = e as HandledMouseEventArgs;
|
---|
| 1079 | if (eventargs != null)
|
---|
| 1080 | eventargs.Handled = true;
|
---|
| 1081 | View.Invalidate();
|
---|
| 1082 | }
|
---|
[2768] | 1083 |
|
---|
[3167] | 1084 | #region DragDrop event handlers
|
---|
[2768] | 1085 |
|
---|
[3167] | 1086 | /// <summary>
|
---|
| 1087 | /// Handles the GiveFeedback event of the surface control.
|
---|
| 1088 | /// </summary>
|
---|
| 1089 | /// <param name="sender">The source of the event.</param>
|
---|
| 1090 | /// <param name="e">The <see cref="T:System.Windows.Forms.GiveFeedbackEventArgs"/> instance containing the event data.</param>
|
---|
| 1091 | void surface_GiveFeedback(object sender, GiveFeedbackEventArgs e) {
|
---|
| 1092 | if (!controllerEnabled) {
|
---|
| 1093 | return;
|
---|
| 1094 | }
|
---|
[2768] | 1095 |
|
---|
[3167] | 1096 | foreach (IDragDropListener listener in dragdropListeners) {
|
---|
| 1097 | listener.GiveFeedback(e);
|
---|
| 1098 | }
|
---|
| 1099 | }
|
---|
| 1100 | /// <summary>
|
---|
| 1101 | /// Handles the DragOver event of the surface control.
|
---|
| 1102 | /// </summary>
|
---|
| 1103 | /// <param name="sender">The source of the event.</param>
|
---|
| 1104 | /// <param name="e">The <see cref="T:System.Windows.Forms.DragEventArgs"/> instance containing the event data.</param>
|
---|
| 1105 | void surface_DragOver(object sender, DragEventArgs e) {
|
---|
| 1106 | if (!controllerEnabled) {
|
---|
| 1107 | return;
|
---|
| 1108 | }
|
---|
[2768] | 1109 |
|
---|
[3167] | 1110 | foreach (IDragDropListener listener in dragdropListeners) {
|
---|
| 1111 | listener.OnDragOver(e);
|
---|
| 1112 | }
|
---|
| 1113 | }
|
---|
[2768] | 1114 |
|
---|
[3167] | 1115 | /// <summary>
|
---|
| 1116 | /// Handles the DragLeave event of the surface control.
|
---|
| 1117 | /// </summary>
|
---|
| 1118 | /// <param name="sender">The source of the event.</param>
|
---|
| 1119 | /// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param>
|
---|
| 1120 | void surface_DragLeave(object sender, EventArgs e) {
|
---|
| 1121 | if (!controllerEnabled) {
|
---|
| 1122 | return;
|
---|
| 1123 | }
|
---|
[2768] | 1124 |
|
---|
[3167] | 1125 | foreach (IDragDropListener listener in dragdropListeners) {
|
---|
| 1126 | listener.OnDragLeave(e);
|
---|
| 1127 | }
|
---|
| 1128 | }
|
---|
[2768] | 1129 |
|
---|
[3167] | 1130 | /// <summary>
|
---|
| 1131 | /// Handles the DragEnter event of the surface control.
|
---|
| 1132 | /// </summary>
|
---|
| 1133 | /// <param name="sender">The source of the event.</param>
|
---|
| 1134 | /// <param name="e">The <see cref="T:System.Windows.Forms.DragEventArgs"/> instance containing the event data.</param>
|
---|
| 1135 | void surface_DragEnter(object sender, DragEventArgs e) {
|
---|
| 1136 | if (!controllerEnabled) {
|
---|
| 1137 | return;
|
---|
| 1138 | }
|
---|
[2768] | 1139 |
|
---|
[3167] | 1140 | foreach (IDragDropListener listener in dragdropListeners) {
|
---|
| 1141 | listener.OnDragEnter(e);
|
---|
| 1142 | }
|
---|
| 1143 | }
|
---|
[2768] | 1144 |
|
---|
[3167] | 1145 | /// <summary>
|
---|
| 1146 | /// Handles the DragDrop event of the surface control.
|
---|
| 1147 | /// </summary>
|
---|
| 1148 | /// <param name="sender">The source of the event.</param>
|
---|
| 1149 | /// <param name="e">The <see cref="T:System.Windows.Forms.DragEventArgs"/> instance containing the event data.</param>
|
---|
| 1150 | void surface_DragDrop(object sender, DragEventArgs e) {
|
---|
| 1151 | if (!controllerEnabled) {
|
---|
| 1152 | return;
|
---|
| 1153 | }
|
---|
[2768] | 1154 |
|
---|
[3167] | 1155 | foreach (IDragDropListener listener in dragdropListeners) {
|
---|
| 1156 | listener.OnDragDrop(e);
|
---|
| 1157 | }
|
---|
| 1158 | }
|
---|
| 1159 | #endregion
|
---|
[2768] | 1160 |
|
---|
[3167] | 1161 | #region Keyboard event handlers
|
---|
| 1162 | void surface_KeyPress(object sender, KeyPressEventArgs e) {
|
---|
| 1163 |
|
---|
| 1164 | foreach (IKeyboardListener listener in keyboardListeners) {
|
---|
| 1165 | listener.KeyPress(e);
|
---|
| 1166 | }
|
---|
| 1167 |
|
---|
| 1168 | foreach (IDiagramEntity entity in this.Model.Selection.SelectedItems) {
|
---|
| 1169 | if (entity is IKeyboardListener) {
|
---|
| 1170 | (entity as IKeyboardListener).KeyPress(e);
|
---|
[2768] | 1171 | }
|
---|
[3167] | 1172 | }
|
---|
| 1173 | }
|
---|
[2768] | 1174 |
|
---|
[3167] | 1175 | void surface_KeyUp(object sender, KeyEventArgs e) {
|
---|
[2768] | 1176 |
|
---|
[3167] | 1177 | foreach (IKeyboardListener listener in keyboardListeners) {
|
---|
| 1178 | listener.KeyUp(e);
|
---|
| 1179 | }
|
---|
| 1180 |
|
---|
| 1181 | foreach (IDiagramEntity entity in this.Model.Selection.SelectedItems) {
|
---|
| 1182 | if (entity is IKeyboardListener) {
|
---|
| 1183 | (entity as IKeyboardListener).KeyUp(e);
|
---|
[2768] | 1184 | }
|
---|
[3167] | 1185 | }
|
---|
| 1186 | }
|
---|
[2768] | 1187 |
|
---|
[3167] | 1188 | void surface_KeyDown(object sender, KeyEventArgs e) {
|
---|
| 1189 | foreach (IKeyboardListener listener in keyboardListeners) {
|
---|
| 1190 | listener.KeyDown(e);
|
---|
| 1191 | }
|
---|
| 1192 |
|
---|
| 1193 | foreach (IDiagramEntity entity in this.Model.Selection.SelectedItems) {
|
---|
| 1194 | if (entity is IKeyboardListener) {
|
---|
| 1195 | (entity as IKeyboardListener).KeyDown(e);
|
---|
[2768] | 1196 | }
|
---|
[3167] | 1197 | }
|
---|
| 1198 | }
|
---|
[2768] | 1199 |
|
---|
[3167] | 1200 | #endregion
|
---|
[2768] | 1201 |
|
---|
[3167] | 1202 | #region Mouse event handlers
|
---|
| 1203 | /// <summary>
|
---|
| 1204 | /// Implements the observer pattern for the mouse hover event,
|
---|
| 1205 | /// communicating the event to all listeners implementing the
|
---|
| 1206 | /// necessary interface.
|
---|
| 1207 | /// </summary>
|
---|
| 1208 | /// <param name="sender">The source of the event.</param>
|
---|
| 1209 | /// <param name="e">The <see cref="T:System.EventArgs"/> instance
|
---|
| 1210 | /// containing the event data.</param>
|
---|
| 1211 | protected virtual void OnSurfaceMouseHover(object sender, EventArgs e) {
|
---|
| 1212 | //if (eventsEnabled)
|
---|
| 1213 | // RaiseOnMouseHover(e);
|
---|
| 1214 | //if (!controllerEnabled)
|
---|
| 1215 | // return;
|
---|
| 1216 | }
|
---|
| 1217 | /// <summary>
|
---|
| 1218 | /// Implements the observer pattern for the mouse down event,
|
---|
| 1219 | /// communicating the event to all listeners implementing the
|
---|
| 1220 | /// necessary interface.
|
---|
| 1221 | /// </summary>
|
---|
| 1222 | /// <param name="sender">The source of the event.</param>
|
---|
| 1223 | /// <param name="e">The
|
---|
| 1224 | /// <see cref="T:System.Windows.Forms.MouseEventArgs"/> instance
|
---|
| 1225 | /// containing the event data.</param>
|
---|
| 1226 | protected virtual void OnSurfaceMouseDown(
|
---|
| 1227 | object sender,
|
---|
| 1228 | MouseEventArgs e) {
|
---|
| 1229 | #region Coordinates logic
|
---|
| 1230 | // Get a point adjusted by the current scroll position and zoom factor
|
---|
| 1231 | Point p = Point.Round(
|
---|
| 1232 | this.View.ViewToWorld(this.View.DeviceToView(e.Location)));
|
---|
[2768] | 1233 |
|
---|
[3184] | 1234 | HandledMouseEventArgs ce =
|
---|
| 1235 | new HandledMouseEventArgs(
|
---|
[3167] | 1236 | e.Button,
|
---|
| 1237 | e.Clicks,
|
---|
| 1238 | p.X,
|
---|
| 1239 | p.Y,
|
---|
| 1240 | e.Delta);
|
---|
| 1241 | #endregion
|
---|
[2768] | 1242 |
|
---|
[3167] | 1243 | if (eventsEnabled)
|
---|
| 1244 | RaiseOnMouseDown(ce);
|
---|
[3184] | 1245 | if (!controllerEnabled || ce.Handled)
|
---|
[3167] | 1246 | return;
|
---|
| 1247 | this.parentControl.Focus();
|
---|
[2768] | 1248 |
|
---|
[3167] | 1249 | //(parentControl as Win.DiagramControl).toolTip.Show("Yihaaa", parentControl as Win.DiagramControl, ce.Location);
|
---|
[2768] | 1250 |
|
---|
[3167] | 1251 | //this selection process will work independently of the tools because
|
---|
| 1252 | //some tools need the current selection or hit entity
|
---|
| 1253 | //On the other hand, when drawing a simple rectangle for example the selection
|
---|
| 1254 | //should be off, so there is an overhead.
|
---|
| 1255 | //Selection.CollectEntitiesAt(e.Location);
|
---|
[2768] | 1256 |
|
---|
[3167] | 1257 | //raise the event to give the host the opportunity to show the properties of the selected item(s)
|
---|
| 1258 | //Note that if the selection is empty the property grid will show 'nothing'.
|
---|
| 1259 | RaiseOnShowSelectionProperties(new SelectionEventArgs(this.Model.Selection.SelectedItems.ToArray()));
|
---|
[2768] | 1260 |
|
---|
[3167] | 1261 | foreach (IMouseListener listener in mouseListeners) {
|
---|
| 1262 | if (listener.MouseDown(ce))
|
---|
| 1263 | break;
|
---|
| 1264 | }
|
---|
| 1265 | }
|
---|
| 1266 | /// <summary>
|
---|
| 1267 | /// Handles the MouseMove event of the surface control.
|
---|
| 1268 | /// </summary>
|
---|
| 1269 | /// <param name="sender">The source of the event.</param>
|
---|
| 1270 | /// <param name="e">The
|
---|
| 1271 | /// <see cref="T:System.Windows.Forms.MouseEventArgs"/> instance
|
---|
| 1272 | /// containing the event data.</param>
|
---|
| 1273 | protected virtual void OnSurfaceMouseMove(object sender, MouseEventArgs e) {
|
---|
| 1274 | if (!controllerEnabled)
|
---|
| 1275 | return;
|
---|
[2768] | 1276 |
|
---|
[3167] | 1277 | #region Coordinates logic
|
---|
| 1278 | // Get a point adjusted by the current scroll position and zoom
|
---|
| 1279 | // factor.
|
---|
| 1280 | //Point p = new Point(e.X - parentControl.AutoScrollPosition.X, e.Y - parentControl.AutoScrollPosition.Y);
|
---|
| 1281 | Point p = Point.Round(this.View.ViewToWorld(
|
---|
| 1282 | this.View.DeviceToView(e.Location)));
|
---|
[2768] | 1283 |
|
---|
[3167] | 1284 | MouseEventArgs ce = new MouseEventArgs(
|
---|
| 1285 | e.Button,
|
---|
| 1286 | e.Clicks,
|
---|
| 1287 | p.X,
|
---|
| 1288 | p.Y,
|
---|
| 1289 | e.Delta);
|
---|
[2768] | 1290 |
|
---|
[3167] | 1291 | #endregion
|
---|
| 1292 | foreach (IMouseListener listener in mouseListeners) {
|
---|
| 1293 | listener.MouseMove(ce);
|
---|
| 1294 | }
|
---|
| 1295 | }
|
---|
[2768] | 1296 |
|
---|
[3167] | 1297 | /// <summary>
|
---|
| 1298 | /// Handles the MouseUp event of the surface control.
|
---|
| 1299 | /// </summary>
|
---|
| 1300 | /// <param name="sender">The source of the event.</param>
|
---|
| 1301 | /// <param name="e">The <see cref="T:System.Windows.Forms.MouseEventArgs"/> instance containing the event data.</param>
|
---|
| 1302 | protected virtual void OnSurfaceMouseUp(object sender, System.Windows.Forms.MouseEventArgs e) {
|
---|
| 1303 | if (!controllerEnabled)
|
---|
| 1304 | return;
|
---|
| 1305 | #region Coordinates logic
|
---|
| 1306 | // Get a point adjusted by the current scroll position and zoom factor
|
---|
| 1307 | //Point p = new Point(e.X - parentControl.AutoScrollPosition.X, e.Y - parentControl.AutoScrollPosition.Y);
|
---|
| 1308 | Point p = Point.Round(this.View.ViewToWorld(this.View.DeviceToView(e.Location)));
|
---|
| 1309 | MouseEventArgs ce = new MouseEventArgs(e.Button, e.Clicks, p.X, p.Y, e.Delta);
|
---|
| 1310 | #endregion
|
---|
| 1311 | foreach (IMouseListener listener in mouseListeners) {
|
---|
| 1312 | listener.MouseUp(ce);
|
---|
| 1313 | }
|
---|
| 1314 | }
|
---|
[2768] | 1315 |
|
---|
| 1316 |
|
---|
[3167] | 1317 | #endregion
|
---|
[2768] | 1318 |
|
---|
[3167] | 1319 | // ------------------------------------------------------------------
|
---|
| 1320 | /// <summary>
|
---|
| 1321 | /// Undo of the last action
|
---|
| 1322 | /// </summary>
|
---|
| 1323 | /// <remarks>Calling this on a class level will call the Undo method
|
---|
| 1324 | /// of the last ICommand in the stack.</remarks>
|
---|
| 1325 | // ------------------------------------------------------------------
|
---|
| 1326 | public void Undo() {
|
---|
| 1327 | // Reset the tracker or show the tracker after the undo operation
|
---|
| 1328 | // since the undo does not take care of it
|
---|
| 1329 | this.View.ResetTracker();
|
---|
| 1330 | mUndoManager.Undo();
|
---|
| 1331 | this.View.ShowTracker();
|
---|
| 1332 | this.View.Invalidate();
|
---|
| 1333 | }
|
---|
[2768] | 1334 |
|
---|
[3167] | 1335 | // ------------------------------------------------------------------
|
---|
| 1336 | /// <summary>
|
---|
| 1337 | /// Performs the actual action or redo in case the actions was undone
|
---|
| 1338 | /// before.
|
---|
| 1339 | /// </summary>
|
---|
| 1340 | /// <remarks>Calling this on a class level will call the Redo method
|
---|
| 1341 | /// of the last ICommand in the stack.</remarks>
|
---|
| 1342 | // ------------------------------------------------------------------
|
---|
| 1343 | public void Redo() {
|
---|
| 1344 | mUndoManager.Redo();
|
---|
| 1345 | this.View.ShowTracker();
|
---|
| 1346 | }
|
---|
[2768] | 1347 |
|
---|
[3167] | 1348 | // ------------------------------------------------------------------
|
---|
| 1349 | /// <summary>
|
---|
| 1350 | /// Selects all entities on the current page. The selection is
|
---|
| 1351 | /// cleared first.
|
---|
| 1352 | /// </summary>
|
---|
| 1353 | // ------------------------------------------------------------------
|
---|
| 1354 | public void SelectAll() {
|
---|
| 1355 | this.View.ResetTracker();
|
---|
| 1356 | this.Model.Selection.Clear();
|
---|
| 1357 | this.Model.Selection.SelectedItems = this.Model.CurrentPage.Entities;
|
---|
| 1358 | this.View.ShowTracker();
|
---|
| 1359 | this.View.Invalidate();
|
---|
| 1360 | }
|
---|
[2768] | 1361 |
|
---|
[3167] | 1362 | // ------------------------------------------------------------------
|
---|
| 1363 | /// <summary>
|
---|
| 1364 | /// Navigates to the next page. Nothing is performed if the last page
|
---|
| 1365 | /// is currently selected and 'wrap' is false. If 'wrap' is true,
|
---|
| 1366 | /// then the first page is selected.
|
---|
| 1367 | /// </summary>
|
---|
| 1368 | /// <param name="wrap">bool: Specifies if the collection is wrapped
|
---|
| 1369 | /// when the end is reached.</param>
|
---|
| 1370 | // ------------------------------------------------------------------
|
---|
| 1371 | public void GoForward(bool wrap) {
|
---|
| 1372 | // We can't go anywhere if there's only one page!
|
---|
| 1373 | if (Model.Pages.Count == 1) {
|
---|
| 1374 | return;
|
---|
| 1375 | }
|
---|
[2768] | 1376 |
|
---|
[3167] | 1377 | int index = Model.Pages.IndexOf(Model.CurrentPage);
|
---|
| 1378 |
|
---|
| 1379 | int newIndex = 0; // The index of the page to select.
|
---|
| 1380 |
|
---|
| 1381 | if (index >= (Model.Pages.Count - 1)) {
|
---|
| 1382 | // The last page is currently active, so if 'wrap' is
|
---|
| 1383 | // false then just return.
|
---|
| 1384 | if (wrap == false) {
|
---|
| 1385 | return;
|
---|
[2768] | 1386 | }
|
---|
| 1387 |
|
---|
[3167] | 1388 | // Otherwise, if 'wrap' is true then we want the first page
|
---|
| 1389 | // in the collection to be active.
|
---|
| 1390 | newIndex = 0;
|
---|
| 1391 | } else {
|
---|
| 1392 | newIndex = index + 1;
|
---|
| 1393 | }
|
---|
[2768] | 1394 |
|
---|
[3167] | 1395 | DeactivateAllTools();
|
---|
| 1396 | View.HideTracker(); // Just in case there are selected items.
|
---|
| 1397 | Model.SetCurrentPage(Model.Pages[newIndex]);
|
---|
| 1398 | View.Invalidate();
|
---|
| 1399 | }
|
---|
[2768] | 1400 |
|
---|
[3167] | 1401 | // ------------------------------------------------------------------
|
---|
| 1402 | /// <summary>
|
---|
| 1403 | /// Navigates to the previous page. Nothing is performed if the first
|
---|
| 1404 | /// page is currently selected and 'wrap' is false. If 'wrap' is
|
---|
| 1405 | /// true, then the last page is selected if the current page is the
|
---|
| 1406 | /// first page.
|
---|
| 1407 | /// </summary>
|
---|
| 1408 | /// <param name="wrap">bool: Specifies if the collection is wrapped
|
---|
| 1409 | /// when the start is reached.</param>
|
---|
| 1410 | // ------------------------------------------------------------------
|
---|
| 1411 | public void GoBack(bool wrap) {
|
---|
| 1412 | // We can't go anywhere if there's only one page!
|
---|
| 1413 | if (Model.Pages.Count == 1) {
|
---|
| 1414 | return;
|
---|
| 1415 | }
|
---|
[2768] | 1416 |
|
---|
[3167] | 1417 | int index = Model.Pages.IndexOf(Model.CurrentPage);
|
---|
[2768] | 1418 |
|
---|
[3167] | 1419 | int newIndex = 0; // The index of the page to select.
|
---|
[2768] | 1420 |
|
---|
[3167] | 1421 | if (index == 0) {
|
---|
| 1422 | // The first page is currently active, so if 'wrap' is
|
---|
| 1423 | // false then just return.
|
---|
| 1424 | if (wrap == false) {
|
---|
| 1425 | return;
|
---|
[2768] | 1426 | }
|
---|
[3167] | 1427 |
|
---|
| 1428 | // Otherwise, since 'wrap' is true then we want the last page
|
---|
| 1429 | // in the collection to be active.
|
---|
| 1430 | newIndex = Model.Pages.Count - 1;
|
---|
| 1431 | } else {
|
---|
| 1432 | newIndex = index - 1;
|
---|
| 1433 | }
|
---|
| 1434 |
|
---|
| 1435 | DeactivateAllTools();
|
---|
| 1436 | View.HideTracker(); // Just in case there are selected items.
|
---|
| 1437 | Model.SetCurrentPage(Model.Pages[newIndex]);
|
---|
| 1438 | View.Invalidate();
|
---|
[2768] | 1439 | }
|
---|
[3167] | 1440 | #endregion
|
---|
| 1441 |
|
---|
| 1442 | }
|
---|
[2768] | 1443 | }
|
---|