protected override void OnLoad(EventArgs e) { base.OnLoad(e); // Show thumbnails panel initially, focus in preview pane, and ensure consistent UI state: dtpPages.Show(); PreviewPane.Focus(); RefreshUI(); }
protected override void OnPreviewMouseLeftButtonDown(MouseButtonEventArgs e) { base.OnPreviewMouseLeftButtonDown(e); if (PreviewPane != null) // && !PreviewPane.IsOpen) { PreviewPane.FastClose(); } }
protected override void OnMouseLeave(MouseEventArgs e) { base.OnMouseLeave(e); if (PreviewPane != null) { PreviewPane.Close(); } }
protected override void OnClick() { base.OnClick(); if (PreviewPane != null) { PreviewPane.FastClose(); } }
/// <summary> /// Adjusts the visual cues and state of the controls associated with the find text functionality /// depending on whether a search was successful or not. /// </summary> /// <param name="success">True for successful search, false otherwise.</param> private void FindAdjustDisplay(bool success) { if (success) { this.rtbFindText.ForeColorTextBox = SystemColors.ControlText; } else { this.rtbFindText.ForeColorTextBox = Color.Red; PreviewPane.SelectionClear(); } FindSetButtonsState(true, success); }
private void C1RibbonPrintPreviewForm_KeyDown(object sender, KeyEventArgs e) { if (!PreviewPane.Focused) { if (e.KeyCode == Keys.Escape && e.Modifiers == Keys.None) { PreviewPane.Focus(); } else if (e.KeyCode == Keys.Add && e.Modifiers == Keys.Control) { cmdZoomIn.PerformClick(); } else if (e.KeyCode == Keys.Subtract && e.Modifiers == Keys.Control) { cmdZoomOut.PerformClick(); } } }
/// <summary> /// Searches for all occurrences of a text in the preview pane. /// Highlights the first occurrence and ensures that it is shown in the preview. /// </summary> /// <param name="text">The search text.</param> /// <param name="matchCase">Indicates whether to perform a case-sensitive search.</param> /// <returns>True if at least one occurrence was found, false otherwise.</returns> public bool Find(string text, bool matchCase) { if (string.IsNullOrEmpty(text)) { return(false); } _findArgs = new C1TextSearchArgs(); _findArgs.Text = text; _findArgs.IgnoreCase = !matchCase; _finds = PreviewPane.TextSearchAll(_findArgs); _findCurrent = _finds != null && _finds.Length > 0 ? 0 : -1; if (_findCurrent != -1) { PreviewPane.SelectTextFragment(_finds[_findCurrent]); PreviewPane.GoToSelection(); return(true); } else { return(false); } }
/// <summary> /// Searches for the next occurrence of a text in the preview pane. /// Highlights the found occurrence and ensures that it is shown in the preview. /// If there are no more occurrences of the search text in the specified direction, /// wraps to the beginning or end of the document. /// </summary> /// <param name="text">The search text.</param> /// <param name="matchCase">Indicates whether to perform a case-sensitive search.</param> /// <param name="up">Indicates whether to search up or down in the document.</param> /// <returns>True if the next occurrence was found, false otherwise.</returns> public bool FindNext(string text, bool matchCase, bool up) { if (_finds == null || _finds.Length == 0) { return(Find(text, matchCase)); } else { if (!up) { ++_findCurrent; if (_findCurrent >= _finds.Length) { _findCurrent = 0; } } else { --_findCurrent; if (_findCurrent < 0) { _findCurrent = _finds.Length - 1; } } if (_findCurrent >= 0 && _findCurrent < _finds.Length) { PreviewPane.SelectTextFragment(_finds[_findCurrent]); PreviewPane.GoToSelection(); return(true); } else { return(false); } } }
private void ApplyChanges(object sender, EventArgs e) { if (PreviewPane.BackgroundImage == null) { MessageBox.Show("No changes were made.", "Operation Aborted"); return; } ACResult result = ApplyConfirmation.ShowConfirmation(); if (result == ACResult.IGNORE) { return; } StartProgress(); int width = int.Parse(tbCWidth.Text); int height = int.Parse(tbCHeight.Text); if (width < 640 || width > 7680) { width = 800; } if (height < 480 || height > 4320) { height = 600; } string newBGPath = PreviewPane.BackgroundLocation + "\\background"; ChangeProgress(loaddlg, 25); if (!Directory.Exists(newBGPath)) { Directory.CreateDirectory(newBGPath); } newBGPath += "\\HLBC"; if (!Directory.Exists(newBGPath)) { Directory.CreateDirectory(newBGPath); } Bitmap[,] newBmps = PreviewPane.ChopNewImage(width, height); ChangeProgress(loaddlg, 50); string[] newBmpsLocations = PreviewPane.NewBitmapLocations; ChangeProgress(loaddlg, 75); int bmpWCount = newBmps.GetLength(0); int bmpHCount = newBmps.Length; int x = 0; int y = 0; string backgroundLayoutContents = "resolution\t" + width + "\t" + height + "\n"; string errorMsg = string.Empty; foreach (var bmpLoc in newBmpsLocations) { string bmpRelPath = PreviewPanel.RemoveExtraSpaces(bmpLoc).Split()[0]; string bmpPath = PreviewPane.BackgroundLocation.Remove(PreviewPane.BackgroundLocation.Length - 9, 9) + "\\" + bmpRelPath; backgroundLayoutContents += bmpLoc + "\n"; try { newBmps[x, y].Save(bmpPath + ".bmp"); Surface surf = Surface.LoadFromFile(bmpPath + ".bmp", ImageLoadFlags.TARGA_LoadRGB888); surf.SaveToFile(ImageFormat.TARGA, bmpPath, ImageSaveFlags.Default); } catch { errorMsg += "File has been probably corrupted: " + bmpPath + "\n"; } // cleanup!!! File.Delete(bmpPath + ".bmp"); if (++x >= bmpWCount) { x = 0; if (++y >= bmpHCount) { break; } } } ChangeProgress(loaddlg, 100); if (errorMsg.Length > 0) { Activate(); MessageBox.Show("Background Change Failed! Permission to write to file was denied.\n" + errorMsg, "File IO Error"); return; } switch (result) { case ACResult.BACKUP: if (File.Exists(PreviewPane.BackgroundLocation + "\\BackgroundLayout.txt")) { int cr = 1; while (File.Exists(PreviewPane.BackgroundLocation + "\\BackgroundLayout_v" + cr + ".txt")) { cr++; } string bgLines = File.ReadAllText(PreviewPane.BackgroundLocation + "\\BackgroundLayout.txt"); File.WriteAllText(PreviewPane.BackgroundLocation + "\\BackgroundLayout_v" + cr + ".txt", bgLines); MessageBox.Show("Backup saved as: BackgroundLayout_v" + cr + ".txt", "Backup Saved"); } else { MessageBox.Show("BackgroundLayout.txt was not found inside the resources folder. Backup is unnecessary.", "Backup Skipped"); } File.WriteAllText(PreviewPane.BackgroundLocation + "\\BackgroundLayout.txt", backgroundLayoutContents); break; case ACResult.OVERWRITE: File.WriteAllText(PreviewPane.BackgroundLocation + "\\BackgroundLayout.txt", backgroundLayoutContents); break; } MessageBox.Show("Successfully Changed Background Layout!\r\nDon't forget to match the in-game resolution with your newly created background.", "Changes Saved"); Activate(); }
private void Show_Preview(object sender, RoutedEventArgs e) { PreviewPane.Show(); }
/// <summary> /// Wires up user commands controlling the preview (file operations, zoom and so on), /// and performs a few other initialization actions. /// </summary> /// <remarks> /// Most user actions are wired up via C1Command "commands" (components of type C1.Win.C1Command.C1Command), /// in the following manner: /// <para> /// The C1CommandHolder contains the list of all supported commands, such as 'open', /// 'save', 'zoom in' and so on, with self-explanatory names (e.g. cmdFileOpen). /// Most commands perform a single action without any parameters. /// The few that do perform parameterized actions use C1Command.UserData property /// to accept the parameters. For instance cmdFileOpen command optionally accepts /// a fileName/reportName pair. /// </para> /// <para> /// For each ribbon button, its Click event is bound to the appropriate command's PerformClick method. /// The actual action is then bound to the command's Click event. /// On most commands, two other events are also bound: /// - CommandStateQuery updates the command's enabled state; /// - EnabledChanged (invoked only when the enabled state of the command actually changes) /// updates the button's enabled state. This event is not bound for commands that do not /// have associated buttons (e.g. cmdZoomIn/cmdZoomOut are only bound to keys). /// </para> /// <para> /// Some buttons (such as 'portrait orientation') have a pressed state, which reflects the current /// state of the preview. The pressed state of buttons is updated by the PreviewPane.PropertyChanged /// event handler, which minimizes overhead. /// </para> /// </remarks> protected void InitPreviewCommands() { // Hide the search tab in the left tab control (it is not used, and is here only for // backwards compatibility - FindHelper and status bar search controls are used instead): this.dtpSearch.TabVisible = false; this.ptspMain.Visible = false; // Ensure command holder uses ribbon's visual style: C1.Win.C1Command.VisualStyle vs; if (Enum.TryParse <C1.Win.C1Command.VisualStyle>(this.rbnMain.VisualStyle.ToString(), true, out vs)) { this._cmdHolder.VisualStyle = vs; } this.ZoomSliderScale = new ZoomSliderScale( PreviewPane.MinZoomFactor, PreviewPane.MaxZoomFactor, (int)(PreviewPane.MinZoomFactor * 100), (int)(PreviewPane.MaxZoomFactor * 100)); this.rtbZoom.TickFrequency = ZoomSliderScale.SliderValue(1); this.KeyPreview = true; this.KeyDown += new KeyEventHandler(C1RibbonPrintPreviewForm_KeyDown); this.rbnProgress.Visible = false; this.PreviewPane.LongOperation += new C1.C1Preview.LongOperationEventHandler(PreviewPane_LongOperation); this.PreviewPane.PropertyChanged += new PropertyChangedEventHandler(PreviewPane_PropertyChanged); // connect toolbar buttons to commands: this.rbtnAbout.Click += (s, e) => this.cmdAbout.PerformClick(); this.rbtnOpen.Click += (s, e) => this.cmdFileOpen.PerformClick(); this.rbtnOpen2.Click += (s, e) => this.cmdFileOpen.PerformClick(); this.rbtnSave.Click += (s, e) => this.cmdFileSave.PerformClick(); this.rbtnSave2.Click += (s, e) => this.cmdFileSave.PerformClick(); this.rbtnClose2.Click += (s, e) => this.cmdFileClose.PerformClick(); this.rbtnNew2.Click += (s, e) => this.cmdFileNew.PerformClick(); this.rbtnExit.Click += (s, e) => this.cmdExit.PerformClick(); this.rbtnPrint.Click += (s, e) => this.cmdPrint.PerformClick(); this.rbtnPrint2.Click += (s, e) => this.cmdPrint.PerformClick(); this.rbtnRefresh.Click += (s, e) => this.cmdRefresh.PerformClick(); this.rbtnPageSetup.Click += (s, e) => this.cmdPageSetup.PerformClick(); this.rbtnPageSetup2.Click += (s, e) => this.cmdPageSetup.PerformClick(); this.rbtnPageLandscape.Click += (s, e) => this.cmdPageLandscape.PerformClick(); this.rbtnPagePortrait.Click += (s, e) => this.cmdPagePortrait.PerformClick(); this.rbtnZoom100.Click += (s, e) => this.cmdZoom100.PerformClick(); this.rbtnZoomFitPage.Click += (s, e) => cmdZoomFitPage.PerformClick(); this.rbtnZoomFitWidth.Click += (s, e) => cmdZoomFitWidth.PerformClick(); this.rbtnFirstPage.Click += (s, e) => this.cmdGoFirst.PerformClick(); this.rbtnLastPage.Click += (s, e) => this.cmdGoLast.PerformClick(); this.rbtnPreviousPage.Click += (s, e) => this.cmdGoPrev.PerformClick(); this.rbtnNextPage.Click += (s, e) => this.cmdGoNext.PerformClick(); this.rbtnHistoryBack.Click += (s, e) => this.cmdHistoryPrev.PerformClick(); this.rbtnHistoryNext.Click += (s, e) => this.cmdHistoryNext.PerformClick(); this.rbtnHandTool.Click += (s, e) => this.cmdMouseModeHand.PerformClick(); this.rbtnTextSelectTool.Click += (s, e) => this.cmdMouseModeSelect.PerformClick(); this.rbtnZoomInTool.Click += (s, e) => this.cmdMouseModeZoomIn.PerformClick(); this.rbtnZoomOutTool.Click += (s, e) => this.cmdMouseModeZoomOut.PerformClick(); this.rbtnViewSinglePage.Click += (s, e) => this.cmdPageViewSingle.PerformClick(); this.rbtnViewContinuous.Click += (s, e) => this.cmdPageViewContinuous.PerformClick(); this.rbtnViewPagesFacing.Click += (s, e) => this.cmdPageViewTwoUp.PerformClick(); this.rbtnViewPagesFacingContinuous.Click += (s, e) => this.cmdPageViewTwoUpContinuous.PerformClick(); this.rbtnFind.Click += (s, e) => this.cmdFind.PerformClick(); this.rbtnFindAgain.Click += (s, e) => this.cmdFindNext.PerformClick(); this.rgZoom.DialogLauncherClick += (s, e) => this.cmdZoomDialog.PerformClick(); this.rbtnZoom.Click += (s, e) => this.cmdZoomDialog.PerformClick(); // commands: #if C1DVIEW_APP this.cmdAbout.Click += (s, e) => (new AboutForm()).ShowDialog(this); // this.cmdHelp.Click += (s, e) => (new AboutForm()).ShowDialog(this); #endif this.cmdFileOpen.CommandStateQuery += (s, e) => e.Enabled = !PreviewPane.Busy; this.cmdFileOpen.EnabledChanged += (s, e) => this.rbtnOpen.Enabled = this.rbtnOpen2.Enabled = ((C1Command)s).Enabled; this.cmdFileOpen.Click += (s, e) => { FileOpen((C1Command)s); PreviewPane.Focus(); }; this.cmdFileSave.CommandStateQuery += (s, e) => e.Enabled = !PreviewPane.Busy && PreviewPane.Document != null; this.cmdFileSave.EnabledChanged += (s, e) => this.rbtnSave.Enabled = this.rbtnSave2.Enabled = ((C1Command)s).Enabled; this.cmdFileSave.Click += (s, e) => PreviewPane.FileSave(); this.cmdFileClose.CommandStateQuery += (s, e) => e.Enabled = !PreviewPane.Busy && (s_openWindows.Count > 1 || PreviewPane.Document != null); this.cmdFileClose.EnabledChanged += (s, e) => rbtnClose2.Enabled = ((C1Command)s).Enabled; this.cmdFileClose.Click += (s, e) => FileClose(); this.cmdFileNew.CommandStateQuery += (s, e) => e.Enabled = true; this.cmdFileNew.EnabledChanged += (s, e) => rbtnNew2.Enabled = ((C1Command)s).Enabled; this.cmdFileNew.Click += (s, e) => FileNew(null); this.cmdExit.Click += (s, e) => FileExit(); this.cmdPrint.CommandStateQuery += (s, e) => e.Enabled = !PreviewPane.Busy && (s_openWindows.Count > 1 || PreviewPane.Document != null); this.cmdPrint.EnabledChanged += (s, e) => this.rbtnPrint.Enabled = this.rbtnPrint2.Enabled = ((C1Command)s).Enabled; this.cmdPrint.Click += (s, e) => PreviewPane.Print(); this.cmdRefresh.CommandStateQuery += (s, e) => e.Enabled = !PreviewPane.Busy && PreviewPane.Document != null && PreviewPane.Reflowable; this.cmdRefresh.EnabledChanged += (s, e) => this.rbtnRefresh.Enabled = ((C1Command)s).Enabled; this.cmdRefresh.Click += (s, e) => PreviewPane.Reflow(); this.cmdPageSetup.CommandStateQuery += (s, e) => e.Enabled = !PreviewPane.Busy && PreviewPane.Document != null && PreviewPane.Reflowable && PreviewPane.CanSetPageSettings; this.cmdPageSetup.EnabledChanged += (s, e) => this.rbtnPageSetup.Enabled = this.rbtnPageSetup2.Enabled = ((C1Command)s).Enabled; this.cmdPageSetup.Click += (s, e) => PreviewPane.PageSetup(); this.cmdPageLandscape.CommandStateQuery += (s, e) => e.Enabled = !PreviewPane.Busy && PreviewPane.Document != null && PreviewPane.Reflowable && PreviewPane.CanSetPageSettings; this.cmdPageLandscape.EnabledChanged += (s, e) => this.rbtnPageLandscape.Enabled = ((C1Command)s).Enabled; this.cmdPageLandscape.PressedChanged += (s, e) => this.rbtnPageLandscape.Pressed = ((C1Command)s).Pressed; this.cmdPageLandscape.Click += (s, e) => SetPageOrientation(true); this.cmdPagePortrait.CommandStateQuery += (s, e) => e.Enabled = !PreviewPane.Busy && PreviewPane.Document != null && PreviewPane.Reflowable && PreviewPane.CanSetPageSettings; this.cmdPagePortrait.EnabledChanged += (s, e) => this.rbtnPagePortrait.Enabled = ((C1Command)s).Enabled; this.cmdPagePortrait.PressedChanged += (s, e) => this.rbtnPagePortrait.Pressed = ((C1Command)s).Pressed; this.cmdPagePortrait.Click += (s, e) => SetPageOrientation(false); this.cmdZoom100.CommandStateQuery += (s, e) => e.Enabled = Document != null && !PreviewPane.Busy; this.cmdZoom100.EnabledChanged += (s, e) => this.rbtnZoom100.Enabled = ((C1Command)s).Enabled; this.cmdZoom100.Click += (s, e) => { PreviewPane.PageLayout = C1.Win.C1Preview.PageLayoutEnum.Normal; PreviewPane.ZoomMode = ZoomModeEnum.ActualSize; }; this.cmdZoomFitPage.CommandStateQuery += (s, e) => e.Enabled = Document != null && !PreviewPane.Busy; this.cmdZoomFitPage.EnabledChanged += (s, e) => this.rbtnZoomFitPage.Enabled = ((C1Command)s).Enabled; this.cmdZoomFitPage.Click += (s, e) => PreviewPane.ZoomMode = ZoomModeEnum.WholePage; this.cmdZoomFitWidth.CommandStateQuery += (s, e) => e.Enabled = Document != null && !PreviewPane.Busy; this.cmdZoomFitWidth.EnabledChanged += (s, e) => this.rbtnZoomFitWidth.Enabled = ((C1Command)s).Enabled; this.cmdZoomFitWidth.Click += (s, e) => PreviewPane.ZoomMode = ZoomModeEnum.PageWidth; this.cmdZoomIn.Click += (s, e) => PreviewPane.DoZoomIn(); this.cmdZoomIn.CommandStateQuery += (s, e) => e.Enabled = Math.Round(PreviewPane.ZoomFactor, 2) < PreviewPane.MaxZoomFactor; // this.cmdZoomIn.EnabledChanged += (s, e) => rbtnZoomIn.Enabled = cmdZoomIn.Enabled; this.cmdZoomOut.Click += (s, e) => PreviewPane.DoZoomOut(); this.cmdZoomOut.CommandStateQuery += (s, e) => e.Enabled = Math.Round(PreviewPane.ZoomFactor, 2) > PreviewPane.MinZoomFactor; // this.cmdZoomOut.EnabledChanged += (s, e) => rbtnZoomOut.Enabled = cmdZoomOut.Enabled; this.cmdGoFirst.CommandStateQuery += (s, e) => e.Enabled = PreviewPane.StartPageIdx > 0; this.cmdGoFirst.EnabledChanged += (s, e) => this.rbtnFirstPage.Enabled = ((C1Command)s).Enabled; this.cmdGoFirst.Click += (s, e) => PreviewPane.StartPageIdx = 0; this.cmdGoLast.CommandStateQuery += (s, e) => e.Enabled = PreviewPane.StartPageIdx < PreviewPane.Pages.Count - 1; this.cmdGoLast.EnabledChanged += (s, e) => this.rbtnLastPage.Enabled = ((C1Command)s).Enabled; this.cmdGoLast.Click += (s, e) => PreviewPane.StartPageIdx = int.MaxValue; this.cmdGoPrev.CommandStateQuery += (s, e) => e.Enabled = PreviewPane.StartPageIdx > 0; this.cmdGoPrev.EnabledChanged += (s, e) => this.rbtnPreviousPage.Enabled = ((C1Command)s).Enabled; this.cmdGoPrev.Click += (s, e) => -- PreviewPane.StartPageIdx; this.cmdGoNext.CommandStateQuery += (s, e) => e.Enabled = PreviewPane.StartPageIdx < PreviewPane.Pages.Count - 1; this.cmdGoNext.EnabledChanged += (s, e) => this.rbtnNextPage.Enabled = ((C1Command)s).Enabled; this.cmdGoNext.Click += (s, e) => ++ PreviewPane.StartPageIdx; this.cmdGoPageNo.CommandStateQuery += (s, e) => e.Enabled = PreviewPane.Pages.Count > 0; this.cmdGoPageNo.EnabledChanged += (s, e) => rebPageNo.Enabled = ((C1Command)s).Enabled; this.cmdGoPageNo.Click += (s, e) => GoToPage(); this.cmdHistoryPrev.CommandStateQuery += (s, e) => e.Enabled = !PreviewPane.Busy && PreviewPane.CurrentHistoryEntryIndex > 0; this.cmdHistoryPrev.EnabledChanged += (s, e) => this.rbtnHistoryBack.Enabled = ((C1Command)s).Enabled; this.cmdHistoryPrev.Click += (s, e) => PreviewPane.HistoryBack(); this.cmdHistoryNext.CommandStateQuery += (s, e) => e.Enabled = !PreviewPane.Busy && PreviewPane.CurrentHistoryEntryIndex < PreviewPane.ViewHistory.Count - 1; this.cmdHistoryNext.EnabledChanged += (s, e) => this.rbtnHistoryNext.Enabled = ((C1Command)s).Enabled; this.cmdHistoryNext.Click += (s, e) => PreviewPane.HistoryForward(); this.cmdMouseModeHand.Click += (s, e) => PreviewPane.MouseMode = MouseModeEnum.Hand; this.cmdMouseModeSelect.Click += (s, e) => PreviewPane.MouseMode = MouseModeEnum.Select; this.cmdMouseModeZoomIn.Click += (s, e) => PreviewPane.MouseMode = MouseModeEnum.Zoom; this.cmdMouseModeZoomOut.Click += (s, e) => PreviewPane.MouseMode = MouseModeEnum.ZoomOut; this.cmdPageViewSingle.EnabledChanged += (s, e) => this.rbtnViewSinglePage.Enabled = ((C1Command)s).Enabled; this.cmdPageViewSingle.CommandStateQuery += (s, e) => e.Enabled = !PreviewPane.Busy; this.cmdPageViewSingle.Click += (s, e) => pageView_Click(s, e); this.cmdPageViewContinuous.EnabledChanged += (s, e) => this.rbtnViewContinuous.Enabled = ((C1Command)s).Enabled; this.cmdPageViewContinuous.CommandStateQuery += (s, e) => e.Enabled = !PreviewPane.Busy; this.cmdPageViewContinuous.Click += (s, e) => pageView_Click(s, e); this.cmdPageViewTwoUp.EnabledChanged += (s, e) => this.rbtnViewPagesFacing.Enabled = ((C1Command)s).Enabled; this.cmdPageViewTwoUp.CommandStateQuery += (s, e) => e.Enabled = !PreviewPane.Busy; this.cmdPageViewTwoUp.Click += (s, e) => pageView_Click(s, e); this.cmdPageViewTwoUpContinuous.EnabledChanged += (s, e) => this.rbtnViewPagesFacingContinuous.Enabled = ((C1Command)s).Enabled; this.cmdPageViewTwoUpContinuous.CommandStateQuery += (s, e) => e.Enabled = !PreviewPane.Busy; this.cmdPageViewTwoUpContinuous.Click += (s, e) => pageView_Click(s, e); this.cmdZoomDialog.EnabledChanged += (s, e) => this.rbtnZoom.Enabled = ((C1Command)s).Enabled; this.cmdZoomDialog.CommandStateQuery += (s, e) => e.Enabled = !PreviewPane.Busy; this.cmdZoomDialog.Click += (s, e) => ShowZoomDialog(); }