public DictionaryConfigurationDlg(PropertyTable propertyTable) { m_propertyTable = propertyTable; InitializeComponent(); m_preview.Dock = DockStyle.Fill; m_preview.Location = new Point(0, 0); previewDetailSplit.Panel1.Controls.Add(m_preview); manageConfigs_treeDetailButton_split.IsSplitterFixed = true; treeDetail_Button_Split.IsSplitterFixed = true; this.MinimumSize = new Size(m_grpConfigurationManagement.Width + 3, manageConfigs_treeDetailButton_split.Height); m_helpTopicProvider = propertyTable.GetValue <IHelpTopicProvider>("HelpTopicProvider"); m_helpProvider = new HelpProvider { HelpNamespace = m_helpTopicProvider.HelpFile }; m_helpProvider.SetHelpKeyword(this, m_helpTopicProvider.GetHelpString(HelpTopic)); m_helpProvider.SetHelpNavigator(this, HelpNavigator.Topic); m_helpProvider.SetShowHelp(this, true); // Restore the location and size from last time we called this dialog. if (m_propertyTable != null) { object locWnd = m_propertyTable.GetValue <object>("DictionaryConfigurationDlg_Location"); object szWnd = m_propertyTable.GetValue <object>("DictionaryConfigurationDlg_Size"); if (locWnd != null && szWnd != null) { Rectangle rect = new Rectangle((Point)locWnd, (Size)szWnd); ScreenHelper.EnsureVisibleRect(ref rect); DesktopBounds = rect; StartPosition = FormStartPosition.Manual; } } }
///*********************************************************************************** /// <summary> /// Load the top, left, width, and height of the window from the registry, use default /// application parameters if not present in registry. This should be called from /// OnLayout; it takes effect in the first call AFTER EndInit. /// </summary> ///*********************************************************************************** public void LoadWindowPosition() { if (m_fInInit) { return; } if (m_fHaveLoadedPosition) { return; } m_fHaveLoadedPosition = true; CheckDisposed(); RegistryKey key = SettingsKey; int iLeft = (int)key.GetValue(Parent.GetType().Name + "Left", (Parent is Form ? ((Form)Parent).DesktopBounds.Left : Parent.Left)); int iTop = (int)key.GetValue(Parent.GetType().Name + "Top", (Parent is Form ? ((Form)Parent).DesktopBounds.Top : Parent.Top)); int iWidth = (int)key.GetValue(Parent.GetType().Name + "Width", (Parent is Form ? ((Form)Parent).DesktopBounds.Width : Parent.Width)); int iHeight = (int)key.GetValue(Parent.GetType().Name + "Height", (Parent is Form ? ((Form)Parent).DesktopBounds.Height : Parent.Height)); var rect = new Rectangle(iLeft, iTop, iWidth, iHeight); var parentForm = Parent as Form; if (parentForm != null) { ScreenHelper.EnsureVisibleRect(ref rect); if (rect != parentForm.DesktopBounds) { // this means we loaded values from the registry - or the form is to big parentForm.StartPosition = FormStartPosition.Manual; } parentForm.DesktopLocation = new Point(rect.X, rect.Y); // we can't set the width and height on the form yet - if we do it won't // resize our child controls m_normalLeft = rect.X; m_normalTop = rect.Y; parentForm.Width = m_normalWidth = rect.Width; parentForm.Height = m_normalHeight = rect.Height; parentForm.WindowState = (FormWindowState)SettingsKey.GetValue( parentForm.GetType().Name + sWindowState, parentForm.WindowState); } else { // Set parent dimensions based upon possible adjustments in EnsureVisibleRect Parent.Top = rect.Top; Parent.Left = rect.Left; Parent.Width = rect.Width; Parent.Height = rect.Height; } }
public UploadToWebonaryDlg(UploadToWebonaryController controller, UploadToWebonaryModel model, PropertyTable propertyTable) { InitializeComponent(); if (MiscUtils.IsUnix) { MinimumSize = new Size(MinimumSize.Width, MinimumSize.Height + m_additionalMinimumHeightForMono); } m_controller = controller; Model = model; LoadFromModel(); m_helpTopicProvider = propertyTable.GetValue <FwXApp>("App"); // When a link is clicked, open a web page to the URL. explanationLabel.LinkClicked += (sender, args) => { using (Process.Start(((LinkLabel)sender).Text.Substring(args.Link.Start, args.Link.Length))) {} }; // Restore the location and size from last time we called this dialog. if (PropertyTable != null) { object locWnd = PropertyTable.GetValue <object>("UploadToWebonaryDlg_Location"); object szWnd = PropertyTable.GetValue <object>("UploadToWebonaryDlg_Size"); if (locWnd != null && szWnd != null) { Rectangle rect = new Rectangle((Point)locWnd, (Size)szWnd); ScreenHelper.EnsureVisibleRect(ref rect); DesktopBounds = rect; StartPosition = FormStartPosition.Manual; } } // Start with output log area not shown by default // When a user clicks Publish, it is revealed. This is done within the context of having a resizable table of controls, and having // the output log area be the vertically growing control when a user increases the height of the dialog this.Shown += (sender, args) => { ValidateSortingOnAlphaHeaders(); this.Height = this.Height - outputLogTextbox.Height; }; // Handle localizable explanation area with link. var explanationText = xWorksStrings.toApplyForWebonaryAccountExplanation; var explanationTextLink = xWorksStrings.toApplyForWebonaryAccountLink; var explanationTextLinkStart = explanationText.IndexOf("{", StringComparison.Ordinal); var explanationTextLinkLength = explanationTextLink.Length; explanationLabel.Text = string.Format(explanationText, explanationTextLink); // Don't blow up if a localization didn't allow for the link. if (explanationTextLinkStart < 0) { explanationTextLinkStart = 0; explanationTextLinkLength = 0; } explanationLabel.LinkArea = new LinkArea(explanationTextLinkStart, explanationTextLinkLength); }
private void ResetWindowLocationAndSize() { // Get location to the stored values, if any. if (m_propertyTable.PropertyExists(m_sWindowKeyLocation) && m_propertyTable.PropertyExists(m_sWindowKeySize)) { var locWnd = m_propertyTable.GetValue <Point>(m_sWindowKeyLocation); var szWnd = m_propertyTable.GetValue <Size>(m_sWindowKeySize); Rectangle rect = new Rectangle(locWnd, szWnd); ScreenHelper.EnsureVisibleRect(ref rect); DesktopBounds = rect; StartPosition = FormStartPosition.Manual; } }
/// <summary/> public void SetDlginfo(ICmPossibilityList posList, Mediator mediator, XCore.PropertyTable propertyTable, bool launchedFromInsertMenu, IPartOfSpeech subItemOwner) { CheckDisposed(); m_subItemOwner = subItemOwner; // May be null, which is fine. m_posList = posList; m_launchedFromInsertMenu = launchedFromInsertMenu; m_mediator = mediator; m_propertyTable = propertyTable; if (m_propertyTable != null) { // Reset window location. // Get location to the stored values, if any. if (m_propertyTable.PropertyExists("masterCatListDlgLocation") && m_propertyTable.PropertyExists("masterCatListDlgSize")) { var locWnd = m_propertyTable.GetValue <Point>("masterCatListDlgLocation"); var szWnd = m_propertyTable.GetValue <Size>("masterCatListDlgSize"); Rectangle rect = new Rectangle(locWnd, szWnd); ScreenHelper.EnsureVisibleRect(ref rect); DesktopBounds = rect; StartPosition = FormStartPosition.Manual; } m_helpTopicProvider = m_propertyTable.GetValue <IHelpTopicProvider>("HelpTopicProvider"); if (m_helpTopicProvider != null) { helpProvider = new HelpProvider(); helpProvider.HelpNamespace = m_helpTopicProvider.HelpFile; helpProvider.SetHelpKeyword(this, m_helpTopicProvider.GetHelpString(s_helpTopic)); helpProvider.SetHelpNavigator(this, HelpNavigator.Topic); } } m_bnHelp.Enabled = (m_helpTopicProvider != null); Debug.Assert(posList != null); m_cache = posList.Cache; var posSet = new HashSet <IPartOfSpeech>(); foreach (IPartOfSpeech pos in posList.ReallyReallyAllPossibilities) { posSet.Add(pos); } LoadMasterCategories(posSet); }
private void MoveWindowToPreviousPosition() { // Get location to the stored values, if any. object locWnd = m_propertyTable.GetValue <object>("mergeDlgLocation"); // JohnT: this dialog can't be resized. So it doesn't make sense to // remember a size. If we do, we need to override OnLoad (as in SimpleListChooser) // to prevent the dialog growing every time at 120 dpi. But such an override // makes it too small to show all the controls at the default size. // It's better just to use the default size until it's resizeable for some reason. //m_mediator.PropertyTable.GetValue("msaCreatorDlgSize"); object szWnd = Size; if (locWnd != null) { Rectangle rect = new Rectangle((Point)locWnd, (Size)szWnd); ScreenHelper.EnsureVisibleRect(ref rect); DesktopBounds = rect; StartPosition = FormStartPosition.Manual; } }
private void SetDlgInfo(LcmCache cache, Mediator mediator, XCore.PropertyTable propertyTable, int hvoOwner, int owningFlid, IFsFeatStruc fs, IPhRegularRule rule, IPhSimpleContextNC ctxt) { m_fs = fs; m_owningFlid = owningFlid; m_hvoOwner = hvoOwner; m_rule = rule; m_ctxt = ctxt; m_mediator = mediator; m_propertyTable = propertyTable; if (m_propertyTable != null) { // Reset window location. // Get location to the stored values, if any. if (m_propertyTable.PropertyExists("phonFeatListDlgLocation") && m_propertyTable.PropertyExists("phonFeatListDlgSize")) { var locWnd = m_propertyTable.GetValue <Point>("phonFeatListDlgLocation"); var szWnd = m_propertyTable.GetValue <Size>("phonFeatListDlgSize"); var rect = new Rectangle(locWnd, szWnd); ScreenHelper.EnsureVisibleRect(ref rect); DesktopBounds = rect; StartPosition = FormStartPosition.Manual; } var helpTopicProvider = (m_propertyTable.GetValue <IHelpTopicProvider>("HelpTopicProvider")); if (helpTopicProvider != null) // Will be null when running tests { m_helpProvider.HelpNamespace = helpTopicProvider.HelpFile; m_helpProvider.SetHelpKeyword(this, helpTopicProvider.GetHelpString(m_helpTopic)); m_helpProvider.SetHelpNavigator(this, HelpNavigator.Topic); } } m_cache = cache; m_valuesCombo.WritingSystemFactory = m_cache.LanguageWritingSystemFactoryAccessor; m_valuesCombo.StyleSheet = FontHeightAdjuster.StyleSheetFromPropertyTable(m_propertyTable); LoadPhonFeats(m_fs); BuildInitialBrowseView(); }
public void RestoreWindowSettings(string id, Form form) { object state = Get(id, "windowState"); //don't bother restoring the program to the minimized state. if (state != null && ((FormWindowState)state) != FormWindowState.Minimized) { form.WindowState = (FormWindowState)state; } object location = Get(id, "windowLocation"); object size = Get(id, "windowSize"); if (location != null) { form.Location = (Point)location; // The location restoration only works if the window startposition is set to // "manual" because the window is not visible yet, and the location will be // changed when it is Show()n. form.StartPosition = FormStartPosition.Manual; } if (size != null) { form.Size = (Size)size; } // Fix the stored position in case it is off the screen. This can happen if the // user has removed a second monitor, or changed the screen resolution downward, // since the last time he ran the program. (See LT-1078.) Rectangle rcNewWnd = form.DesktopBounds; // Rectangle rcScrn = System.Windows.Forms.Screen.FromRectangle(rcNewWnd).WorkingArea; ScreenHelper.EnsureVisibleRect(ref rcNewWnd); form.DesktopBounds = rcNewWnd; }
public void EnsureVisibleRectTest() { foreach (Screen scrn in Screen.AllScreens) { // We want to skip a screen if it is vitual if (ScreenHelper.ScreenIsVirtual(scrn)) { continue; } Rectangle realScreenArea = ScreenHelper.AdjustedWorkingArea(scrn); // Make test rectangle half the height and width of the screen's working area. Rectangle rcAdjusted = scrn.WorkingArea; rcAdjusted.Width /= 2; rcAdjusted.Height /= 2; // Move rectangle so right edge is off the screen and test that our rectangle // comes back fully contained within the screen. rcAdjusted.X = scrn.WorkingArea.Right - rcAdjusted.Width + 15; ScreenHelper.EnsureVisibleRect(ref rcAdjusted); Assert.IsTrue(realScreenArea.Contains(rcAdjusted), "Right edge test failed:" + scrn.DeviceName); // Move rectangle so bottom edge is off the screen and test that our rectangle // comes back fully contained within the screen. rcAdjusted.Y = scrn.WorkingArea.Bottom - rcAdjusted.Height + 15; ScreenHelper.EnsureVisibleRect(ref rcAdjusted); Assert.IsTrue(realScreenArea.Contains(rcAdjusted), "Bottom edge test failed: " + scrn.DeviceName); // Move rectangle so right and bottom edges are off the screen and test that // our rectangle comes back fully contained within the screen. rcAdjusted.X = scrn.WorkingArea.Right - rcAdjusted.Width + 15; rcAdjusted.Y = scrn.WorkingArea.Bottom - rcAdjusted.Height + 15; ScreenHelper.EnsureVisibleRect(ref rcAdjusted); Assert.IsTrue(realScreenArea.Contains(rcAdjusted), "Right & bottom edge test failed: " + scrn.DeviceName); // Move rectangle so left edge is off the screen and test that // our rectangle comes back fully contained within the screen. rcAdjusted.X = scrn.Bounds.Left - 15; ScreenHelper.EnsureVisibleRect(ref rcAdjusted); Assert.IsTrue(realScreenArea.Contains(rcAdjusted), "Left edge test failed: " + scrn.DeviceName); // Move rectangle so top edge is off the screen and test that our // rectangle comes back fully contained within the screen. rcAdjusted.Y = scrn.Bounds.Top - 15; ScreenHelper.EnsureVisibleRect(ref rcAdjusted); Assert.IsTrue(realScreenArea.Contains(rcAdjusted), "Top edge test failed: " + scrn.DeviceName); // Move rectangle so left and top edges are off the screen and test that // our rectangle comes back fully contained within the screen. rcAdjusted.X = scrn.Bounds.Left - 15; rcAdjusted.Y = scrn.Bounds.Top - 15; ScreenHelper.EnsureVisibleRect(ref rcAdjusted); Assert.IsTrue(realScreenArea.Contains(rcAdjusted), "Left & top edge test failed: " + scrn.DeviceName); // Make rectangle larger than the screen and move it up and to the left of // the top, left corner. Then verify that it shrinks and gets moved to fit // exactly in the screen's working area. rcAdjusted = scrn.WorkingArea; rcAdjusted.Inflate(100, 100); ScreenHelper.EnsureVisibleRect(ref rcAdjusted); Assert.AreEqual(realScreenArea, rcAdjusted, "Shrink Rectangle to working area test failed: "); } }
protected virtual void SetDlgInfo(LcmCache cache, WindowParams wp, Mediator mediator, XCore.PropertyTable propertyTable, int ws) { CheckDisposed(); Debug.Assert(cache != null); m_cache = cache; m_mediator = mediator; m_propertyTable = propertyTable; if (m_propertyTable != null) { // Reset window location. // Get location to the stored values, if any. if (m_propertyTable.PropertyExists(PersistenceLabel + "DlgLocation") && m_propertyTable.PropertyExists(PersistenceLabel + "DlgSize")) { var locWnd = m_propertyTable.GetValue <Point>(PersistenceLabel + "DlgLocation"); var szWnd = m_propertyTable.GetValue <Size>(PersistenceLabel + "DlgSize"); var rect = new Rectangle(locWnd, szWnd); //grow it if it's too small. This will happen when we add new controls to the dialog box. if (rect.Width < m_btnHelp.Left + m_btnHelp.Width + 30) { rect.Width = m_btnHelp.Left + m_btnHelp.Width + 30; } if (rect.Height < m_btnHelp.Top + m_btnHelp.Height + 50) { rect.Height = m_btnHelp.Top + m_btnHelp.Height + 50; } ScreenHelper.EnsureVisibleRect(ref rect); DesktopBounds = rect; StartPosition = FormStartPosition.Manual; } m_helpTopicProvider = m_propertyTable.GetValue <IHelpTopicProvider>("HelpTopicProvider"); if (m_helpTopicProvider != null) { m_helpProvider.HelpNamespace = m_helpTopicProvider.HelpFile; SetHelpButtonEnabled(); } } SetupBasicTextProperties(wp); IVwStylesheet stylesheet = FontHeightAdjuster.StyleSheetFromPropertyTable(m_propertyTable); // Set font, writing system factory, and writing system code for the Lexical Form // edit box. Also set an empty string with the proper writing system. m_tbForm.Font = new Font(cache.ServiceLocator.WritingSystemManager.Get(ws).DefaultFontName, 10); m_tbForm.WritingSystemFactory = cache.WritingSystemFactory; m_tbForm.WritingSystemCode = ws; m_tbForm.AdjustStringHeight = false; m_tbForm.Tss = TsStringUtils.EmptyString(ws); m_tbForm.StyleSheet = stylesheet; // Setup the fancy message text box. // Note: at 120DPI (only), it seems to be essential to set at least the WSF of the // bottom message even if not using it. SetupBottomMsg(); SetBottomMessage(); m_fwTextBoxBottomMsg.BorderStyle = BorderStyle.None; m_analHvos.UnionWith(cache.ServiceLocator.WritingSystems.CurrentAnalysisWritingSystems.Select(wsObj => wsObj.Handle)); List <int> vernList = cache.ServiceLocator.WritingSystems.CurrentVernacularWritingSystems.Select(wsObj => wsObj.Handle).ToList(); m_vernHvos.UnionWith(vernList); LoadWritingSystemCombo(); int iWs = vernList.IndexOf(ws); CoreWritingSystemDefinition currentWs; if (iWs < 0) { List <int> analList = cache.ServiceLocator.WritingSystems.CurrentAnalysisWritingSystems.Select(wsObj => wsObj.Handle).ToList(); iWs = analList.IndexOf(ws); if (iWs < 0) { currentWs = cache.ServiceLocator.WritingSystemManager.Get(ws); m_cbWritingSystems.Items.Add(currentWs); SetCbWritingSystemsSize(); } else { currentWs = cache.ServiceLocator.WritingSystems.CurrentAnalysisWritingSystems[iWs]; } } else { currentWs = cache.ServiceLocator.WritingSystems.CurrentVernacularWritingSystems[iWs]; } Debug.Assert(currentWs != null && currentWs.Handle == ws); m_skipCheck = true; m_cbWritingSystems.SelectedItem = currentWs; m_skipCheck = false; // Don't hook this up until AFTER we've initialized it; otherwise, it can // modify the contents of the form as a side effect of initialization. // Also, doing that triggers laying out the dialog prematurely, before // we've set WSF on all the controls. m_cbWritingSystems.SelectedIndexChanged += m_cbWritingSystems_SelectedIndexChanged; InitializeMatchingObjects(cache); // Adjust things if the form box needs to grow to accommodate its style. int oldHeight = m_tbForm.Height; int newHeight = Math.Max(oldHeight, m_tbForm.PreferredHeight); int delta = newHeight - oldHeight; if (delta != 0) { m_tbForm.Height = newHeight; m_panel1.Height += delta; GrowDialogAndAdjustControls(delta, m_panel1); } }
/// <summary> /// Initialize the dialog before showing it. /// </summary> /// <param name="cache"></param> /// <param name="mediator"></param> /// <param name="propertyTable"></param> /// <param name="entry"></param> /// <param name="useForEdit"></param> /// <param name="titleForEdit">Edit title appropriate to the button's context.</param> /// <param name="persistProvider"></param> /// <param name="sandboxMsa"></param> /// <param name="hvoOriginalMsa"></param> public void SetDlgInfo(LcmCache cache, IPersistenceProvider persistProvider, Mediator mediator, XCore.PropertyTable propertyTable, ILexEntry entry, SandboxGenericMSA sandboxMsa, int hvoOriginalMsa, bool useForEdit, string titleForEdit) { CheckDisposed(); Debug.Assert(m_cache == null); MsaType msaType = sandboxMsa.MsaType; m_cache = cache; m_mediator = mediator; m_propertyTable = propertyTable; if (useForEdit) { // Change the window title and the OK button text. Text = titleForEdit; s_helpTopic = "khtpEditGrammaticalFunction"; btnOk.Text = LexText.Controls.LexTextControls.ks_OK; } var helpTopicProvider = m_propertyTable.GetValue <IHelpTopicProvider>("HelpTopicProvider"); helpProvider.HelpNamespace = helpTopicProvider.HelpFile; helpProvider.SetHelpKeyword(this, helpTopicProvider.GetHelpString(s_helpTopic)); helpProvider.SetHelpNavigator(this, HelpNavigator.Topic); // Set font, writing system factory, and code for the edit box. float fntSize = label1.Font.Size * 2.0F; CoreWritingSystemDefinition defVernWs = m_cache.ServiceLocator.WritingSystems.DefaultVernacularWritingSystem; m_fwtbCitationForm.Font = new Font(defVernWs.DefaultFontName, fntSize); m_fwtbCitationForm.WritingSystemFactory = m_cache.WritingSystemFactory; m_fwtbCitationForm.WritingSystemCode = defVernWs.Handle; m_fwtbCitationForm.AdjustForStyleSheet(this, null, m_propertyTable); m_fwtbCitationForm.AdjustStringHeight = false; m_fwtbCitationForm.Tss = entry.HeadWord; m_fwtbCitationForm.HasBorder = false; m_fwtbSenses.Font = new Font(defVernWs.DefaultFontName, fntSize); m_fwtbSenses.WritingSystemFactory = m_cache.WritingSystemFactory; m_fwtbSenses.WritingSystemCode = defVernWs.Handle; m_fwtbSenses.AdjustForStyleSheet(this, null, m_propertyTable); m_fwtbSenses.AdjustStringHeight = false; ITsIncStrBldr tisb = TsStringUtils.MakeIncStrBldr(); tisb.SetIntPropValues((int)FwTextPropType.ktptWs, 0, m_cache.DefaultAnalWs); var msaRepository = m_cache.ServiceLocator.GetInstance <IMoMorphSynAnalysisRepository>(); if (hvoOriginalMsa != 0) { foreach (var sense in entry.AllSenses) { if (sense.MorphoSyntaxAnalysisRA != null) { if (sense.MorphoSyntaxAnalysisRA == msaRepository.GetObject(hvoOriginalMsa)) { if (tisb.Text != null) { tisb.Append(", "); // REVIEW: IS LOCALIZATION NEEDED FOR BUILDING THIS LIST? } tisb.AppendTsString(sense.ShortNameTSS); } } } } m_fwtbSenses.Tss = tisb.GetString(); m_fwtbSenses.HasBorder = false; m_msaGroupBox.Initialize(m_cache, m_mediator, m_propertyTable, this, sandboxMsa); int oldHeight = m_msaGroupBox.Height; int newHeight = Math.Max(oldHeight, m_msaGroupBox.PreferredHeight); int delta = newHeight - oldHeight; if (delta > 0) { m_msaGroupBox.AdjustInternalControlsAndGrow(); Debug.Assert(m_msaGroupBox.Height == m_msaGroupBox.PreferredHeight); FontHeightAdjuster.GrowDialogAndAdjustControls(this, delta, m_msaGroupBox); } // Reset window location. // Get location to the stored values, if any. if (m_propertyTable.PropertyExists("msaCreatorDlgLocation")) { var locWnd = m_propertyTable.GetValue <Point>("msaCreatorDlgLocation"); // JohnT: this dialog can't be resized. So it doesn't make sense to // remember a size. If we do, we need to override OnLoad (as in SimpleListChooser) // to prevent the dialog growing every time at 120 dpi. But such an override // makes it too small to show all the controls at the default size. // It's better just to use the default size until it's resizeable for some reason. //m_mediator.XCore.PropertyTable.GetValue("msaCreatorDlgSize"); Rectangle rect = new Rectangle(locWnd, Size); ScreenHelper.EnsureVisibleRect(ref rect); DesktopBounds = rect; StartPosition = FormStartPosition.Manual; } }