private void Dispose(bool disposing) { if (disposing) { if (this.documentWorkspace != null) { this.documentWorkspace.PopNullTool(); this.documentWorkspace = null; } } }
public Image GetDocumentWorkspaceThumbnail(DocumentWorkspace dw) { this.toolBar.DocumentStrip.SyncThumbnails(); Image[] images = this.toolBar.DocumentStrip.DocumentThumbnails; DocumentWorkspace[] documents = this.toolBar.DocumentStrip.DocumentList; for (int i = 0; i < documents.Length; ++i) { if (documents[i] == dw) { return images[i]; } } throw new ArgumentException("The requested DocumentWorkspace doesn't exist in this AppWorkspace"); }
public DocumentWorkspace AddNewDocumentWorkspace() { if (this.initialWorkspace != null) { if (this.initialWorkspace.Document == null || !this.initialWorkspace.Document.Dirty) { this.globalToolTypeChoice = this.initialWorkspace.GetToolType(); RemoveDocumentWorkspace(this.initialWorkspace); this.initialWorkspace = null; } } DocumentWorkspace dw = new DocumentWorkspace(); dw.AppWorkspace = this; this.documentWorkspaces.Add(dw); this.toolBar.DocumentStrip.AddDocumentWorkspace(dw); return dw; }
/// <summary> /// Creates a blank document of the given size in a new workspace, and activates that workspace. /// </summary> /// <remarks> /// If isInitial=true, then last workspace added by this method is kept track of, and if it is not modified by /// the time the next workspace is added, then it will be removed. /// </remarks> /// <returns>true if everything was successful, false if there wasn't enough memory</returns> public bool CreateBlankDocumentInNewWorkspace(Size size, MeasurementUnit dpuUnit, double dpu, bool isInitial) { DocumentWorkspace dw1 = this.activeDocumentWorkspace; if (dw1 != null) { dw1.SuspendRefresh(); } try { Document untitled = new Document(size.Width, size.Height); untitled.DpuUnit = dpuUnit; untitled.DpuX = dpu; untitled.DpuY = dpu; BitmapLayer bitmapLayer; try { using (new WaitCursorChanger(this)) { bitmapLayer = Layer.CreateBackgroundLayer(size.Width, size.Height); } } catch (OutOfMemoryException) { Utility.ErrorBox(this, PdnResources.GetString("NewImageAction.Error.OutOfMemory")); return false; } using (new WaitCursorChanger(this)) { bool focused = false; if (this.ActiveDocumentWorkspace != null && this.ActiveDocumentWorkspace.Focused) { focused = true; } untitled.Layers.Add(bitmapLayer); DocumentWorkspace dw = this.AddNewDocumentWorkspace(); this.Widgets.DocumentStrip.LockDocumentWorkspaceDirtyValue(dw, false); dw.SuspendRefresh(); try { dw.Document = untitled; } catch (OutOfMemoryException) { Utility.ErrorBox(this, PdnResources.GetString("NewImageAction.Error.OutOfMemory")); RemoveDocumentWorkspace(dw); untitled.Dispose(); return false; } dw.ActiveLayer = (Layer)dw.Document.Layers[0]; this.ActiveDocumentWorkspace = dw; dw.SetDocumentSaveOptions(null, null, null); dw.History.ClearAll(); dw.History.PushNewMemento( new NullHistoryMemento(PdnResources.GetString("NewImageAction.Name"), this.FileNewIcon)); dw.Document.Dirty = false; dw.ResumeRefresh(); if (isInitial) { this.initialWorkspace = dw; } if (focused) { this.ActiveDocumentWorkspace.Focus(); } this.Widgets.DocumentStrip.UnlockDocumentWorkspaceDirtyValue(dw); } } finally { if (dw1 != null) { dw1.ResumeRefresh(); } } return true; }
public CloneStampTool(DocumentWorkspace documentWorkspace) : base(documentWorkspace, PdnResources.GetImageResource("Icons.CloneStampToolIcon.png"), PdnResources.GetString("CloneStampTool.Name"), PdnResources.GetString("CloneStampTool.HelpText"), 'l', false, ToolBarConfigItems.Pen | ToolBarConfigItems.Antialiasing) { }
protected virtual void OnDocumentClicked(DocumentWorkspace dw) { if (DocumentClicked != null) { DocumentClicked(this, new EventArgs<DocumentWorkspace>(dw)); } }
public HistoryStack(DocumentWorkspace documentWorkspace) { this.documentWorkspace = documentWorkspace; undoStack = new List<HistoryMemento>(); redoStack = new List<HistoryMemento>(); }
public void AddDocumentWorkspace(DocumentWorkspace addMe) { this.documents.Add(addMe); ImageStrip.Item docButton = new ImageStrip.Item(); docButton.Image = null; docButton.Tag = addMe; AddItem(docButton); this.documentButtons.Add(docButton); addMe.CompositionUpdated += Workspace_CompositionUpdated; this.dw2button.Add(addMe, docButton); if (addMe.Document != null) { QueueThumbnailUpdate(addMe); docButton.Dirty = addMe.Document.Dirty; addMe.Document.DirtyChanged += Document_DirtyChanged; } addMe.DocumentChanging += Workspace_DocumentChanging; addMe.DocumentChanged += Workspace_DocumentChanged; OnDocumentListChanged(); }
public void RemoveDocumentWorkspace(DocumentWorkspace removeMe) { removeMe.CompositionUpdated -= Workspace_CompositionUpdated; if (this.selectedDocument == removeMe) { this.selectedDocument = null; } removeMe.DocumentChanging -= Workspace_DocumentChanging; removeMe.DocumentChanged -= Workspace_DocumentChanged; if (removeMe.Document != null) { removeMe.Document.DirtyChanged -= Document_DirtyChanged; } this.documents.Remove(removeMe); this.thumbnailManager.RemoveFromQueue(removeMe); ImageStrip.Item docButton = this.dw2button[removeMe]; this.RemoveItem(docButton); this.dw2button.Remove(removeMe); this.documentButtons.Remove(docButton); if (this.thumbs.ContainsKey(removeMe)) { RenderArgs thumbRA = this.thumbs[removeMe]; Surface surface = thumbRA.Surface; thumbRA.Dispose(); this.thumbs.Remove(removeMe); surface.Dispose(); } OnDocumentListChanged(); }
public void UnlockDocumentWorkspaceDirtyValue(DocumentWorkspace unlockMe) { Item docItem = this.dw2button[unlockMe]; docItem.UnlockDirtyValue(); }
public void LockDocumentWorkspaceDirtyValue(DocumentWorkspace lockMe, bool forceDirtyValue) { Item docItem = this.dw2button[lockMe]; docItem.LockDirtyValue(forceDirtyValue); }
protected virtual void OnDocumentClicked(DocumentWorkspace dw, DocumentClickAction action) { if (DocumentClicked != null) { DocumentClicked(this, new EventArgs<Pair<DocumentWorkspace, DocumentClickAction>>( Pair.Create(dw, action))); } }
public override HistoryMemento PerformAction(DocumentWorkspace documentWorkspace) { int newWidth; int newHeight; double newDpu; MeasurementUnit newDpuUnit; string resamplingAlgorithm = Settings.CurrentUser.GetString(SettingNames.LastResamplingMethod, ResamplingAlgorithm.SuperSampling.ToString()); ResamplingAlgorithm alg; try { alg = (ResamplingAlgorithm)Enum.Parse(typeof(ResamplingAlgorithm), resamplingAlgorithm, true); } catch { alg = ResamplingAlgorithm.SuperSampling; } bool maintainAspect = Settings.CurrentUser.GetBoolean(SettingNames.LastMaintainAspectRatio, true); using (ResizeDialog rd = new ResizeDialog()) { rd.OriginalSize = documentWorkspace.Document.Size; rd.OriginalDpuUnit = documentWorkspace.Document.DpuUnit; rd.OriginalDpu = documentWorkspace.Document.DpuX; rd.ImageHeight = documentWorkspace.Document.Height; rd.ImageWidth = documentWorkspace.Document.Width; rd.ResamplingAlgorithm = alg; rd.LayerCount = documentWorkspace.Document.Layers.Count; rd.Units = rd.OriginalDpuUnit; rd.Resolution = documentWorkspace.Document.DpuX; rd.Units = SettingNames.GetLastNonPixelUnits(); rd.ConstrainToAspect = maintainAspect; DialogResult result = rd.ShowDialog(documentWorkspace); if (result == DialogResult.Cancel) { return null; } Settings.CurrentUser.SetString(SettingNames.LastResamplingMethod, rd.ResamplingAlgorithm.ToString()); Settings.CurrentUser.SetBoolean(SettingNames.LastMaintainAspectRatio, rd.ConstrainToAspect); newDpuUnit = rd.Units; newWidth = rd.ImageWidth; newHeight = rd.ImageHeight; newDpu = rd.Resolution; alg = rd.ResamplingAlgorithm; if (newDpuUnit != MeasurementUnit.Pixel) { Settings.CurrentUser.SetString(SettingNames.LastNonPixelUnits, newDpuUnit.ToString()); if (documentWorkspace.AppWorkspace.Units != MeasurementUnit.Pixel) { documentWorkspace.AppWorkspace.Units = newDpuUnit; } } // if the new size equals the old size, there's really no point in doing anything if (documentWorkspace.Document.Size == new Size(rd.ImageWidth, rd.ImageHeight) && documentWorkspace.Document.DpuX == newDpu && documentWorkspace.Document.DpuUnit == newDpuUnit) { return null; } } HistoryMemento ha; if (newWidth == documentWorkspace.Document.Width && newHeight == documentWorkspace.Document.Height) { // Only adjusting Dpu or DpuUnit ha = new MetaDataHistoryMemento(StaticName, StaticImage, documentWorkspace); documentWorkspace.Document.DpuUnit = newDpuUnit; documentWorkspace.Document.DpuX = newDpu; documentWorkspace.Document.DpuY = newDpu; } else { try { using (new WaitCursorChanger(documentWorkspace)) { ha = new ReplaceDocumentHistoryMemento(StaticName, StaticImage, documentWorkspace); } Document newDocument = new Document(newWidth, newHeight); newDocument.ReplaceMetaDataFrom(documentWorkspace.Document); newDocument.DpuUnit = newDpuUnit; newDocument.DpuX = newDpu; newDocument.DpuY = newDpu; ResizeProgressDialog rpd = new ResizeProgressDialog(documentWorkspace, newDocument, documentWorkspace.Document, new Size(newWidth, newHeight), alg); Utility.GCFullCollect(); bool result = rpd.DoResize(); if (!result) { return null; } documentWorkspace.Document = newDocument; } catch (WorkerThreadException ex) { if (ex.InnerException is OutOfMemoryException) { Utility.ErrorBox(documentWorkspace, PdnResources.GetString("ResizeAction.PerformAction.OutOfMemory")); return null; } else { throw; } } catch (OutOfMemoryException) { Utility.ErrorBox(documentWorkspace, PdnResources.GetString("ResizeAction.PerformAction.OutOfMemory")); return null; } } return ha; }
public GradientTool(DocumentWorkspace documentWorkspace) : base(documentWorkspace, StaticImage, StaticName, PdnResources.GetString("GradientTool.HelpText"), 'g', false, ToolBarConfigItems.Gradient | ToolBarConfigItems.AlphaBlending) { }
public void RemoveDocumentWorkspace(DocumentWorkspace documentWorkspace) { int dwIndex = this.documentWorkspaces.IndexOf(documentWorkspace); if (dwIndex == -1) { throw new ArgumentException("DocumentWorkspace was not created with AddNewDocumentWorkspace"); } bool removingCurrentDW; if (this.ActiveDocumentWorkspace == documentWorkspace) { removingCurrentDW = true; this.globalToolTypeChoice = documentWorkspace.GetToolType(); } else { removingCurrentDW = false; } documentWorkspace.SetTool(null); // Choose new active DW if removing the current DW if (removingCurrentDW) { if (this.documentWorkspaces.Count == 1) { this.ActiveDocumentWorkspace = null; } else if (dwIndex == 0) { this.ActiveDocumentWorkspace = this.documentWorkspaces[1]; } else { this.ActiveDocumentWorkspace = this.documentWorkspaces[dwIndex - 1]; } } this.documentWorkspaces.Remove(documentWorkspace); this.toolBar.DocumentStrip.RemoveDocumentWorkspace(documentWorkspace); if (this.initialWorkspace == documentWorkspace) { this.initialWorkspace = null; } // Clean up the DocumentWorkspace Document document = documentWorkspace.Document; documentWorkspace.Document = null; document.Dispose(); documentWorkspace.Dispose(); documentWorkspace = null; }
public void SelectDocumentWorkspace(DocumentWorkspace selectMe) { UI.SuspendControlPainting(this); this.selectedDocument = selectMe; if (this.thumbs.ContainsKey(selectMe)) { RenderArgs thumb = this.thumbs[selectMe]; Bitmap bitmap = thumb.Bitmap; } else { QueueThumbnailUpdate(selectMe); } foreach (ImageStrip.Item docItem in this.documentButtons) { if ((docItem.Tag as DocumentWorkspace) == selectMe) { EnsureItemFullyVisible(docItem); docItem.Checked = true; } else { docItem.Checked = false; } } UI.ResumeControlPainting(this); Invalidate(true); }
public PushNullToolMode(DocumentWorkspace documentWorkspace) { this.documentWorkspace = documentWorkspace; this.documentWorkspace.PushNullTool(); }
public void RefreshThumbnail(DocumentWorkspace dw) { if (this.documents.Contains(dw)) { QueueThumbnailUpdate(dw); } }
private static Tool CreateTool(Type toolType, DocumentWorkspace dc) { ConstructorInfo ci = toolType.GetConstructor(new Type[] { typeof(DocumentWorkspace) }); Tool tool = (Tool)ci.Invoke(new object[] { dc }); return tool; }
private void OnThumbnailUpdated(DocumentWorkspace dw) { // We must double check that the DW is still around, because there's a chance // that the DW was been removed while the thumbnail was being rendered. if (this.dw2button.ContainsKey(dw)) { ImageStrip.Item docButton = this.dw2button[dw]; RenderArgs docRA = this.thumbs[dw]; docButton.Image = docRA.Bitmap; docButton.Update(); } }
/// <summary> /// Implement this to provide an action. You must return a HistoryMemento so that you /// can be undone. However, you should return null if you didn't do anything that /// affected the document. /// </summary> /// <returns>A HistoryMemento object that will be placed onto the HistoryStack.</returns> public abstract HistoryMemento PerformAction(DocumentWorkspace documentWorkspace);
public void QueueThumbnailUpdate(DocumentWorkspace dw) { if (this.suspendThumbnailUpdates <= 0) { this.thumbnailManager.QueueThumbnailUpdate(dw, PreferredImageSize.Width - 2, OnThumbnailRendered); } }
// NOTE: Your constructor must be able to run successfully with a documentWorkspace // of null. This is sent in while the DocumentControl static constructor // class is building a list of ToolInfo instances, so that it may construct // the list without having to also construct a DocumentControl. public Tool(DocumentWorkspace documentWorkspace, ImageResource toolBarImage, string name, string helpText, char hotKey, bool skipIfActiveOnHotKey, ToolBarConfigItems toolBarConfigItems) { this.documentWorkspace = documentWorkspace; this.toolBarImage = toolBarImage; this.toolInfo = new ToolInfo(name, helpText, toolBarImage, hotKey, skipIfActiveOnHotKey, toolBarConfigItems, this.GetType()); if (this.documentWorkspace != null) { this.documentWorkspace.UpdateStatusBarToToolHelpText(this); } }
public TextTool(DocumentWorkspace documentWorkspace) : base(documentWorkspace, PdnResources.GetImageResource("Icons.TextToolIcon.png"), PdnResources.GetString("TextTool.Name"), PdnResources.GetString("TextTool.HelpText"), 't', false, ToolBarConfigItems.Brush | ToolBarConfigItems.Text | ToolBarConfigItems.AlphaBlending | ToolBarConfigItems.Antialiasing) { }