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