/// <summary> /// If the form doesn't have a panel name, call this in the /// constructor of the form /// </summary> /// <returns>true on success</returns> public bool Initialize(StartupArg startupArg) { _panelName = startupArg.PanelClass; var panelConfigMapEntry = PanelConfigMap.GetPanelConfigMapEntry(startupArg.PanelClass); if (panelConfigMapEntry == null) // did not find the panel { return(false); } bool retVal = initWidgetManager(panelConfigMapEntry); if (retVal) { retVal = initAnimationManager(panelConfigMapEntry); } Windows.SetTopMost(_form); PanelManager.Instance.EvtScannerShow += Instance_EvtScannerShow; Windows.EvtWindowPositionChanged += Windows_EvtWindowPositionChanged; Windows.SetWindowPositionAndNotify(_form, Windows.WindowPosition.CenterScreen); _windowOverlapWatchdog = new WindowOverlapWatchdog(_form); return(retVal); }
/// <summary> /// Performs initialization. Reads the config file for the form, creates /// the animation manager, widget manager, loads in all the widgets, /// subscribes to events /// Call this function in the Initialize() function in the scanner. /// </summary> /// <param name="startupArg"></param> /// <returns></returns> public bool Initialize(StartupArg startupArg) { Log.Debug("Entered from Initialize"); Glass.Enable = CoreGlobals.AppPreferences.EnableGlass; Glass.EvtShowGlass += Glass_EvtShowGlass; StartupArg = startupArg; ScannerForm.AutoScaleMode = AutoScaleMode.None; ScannerForm.TopMost = true; Windows.ShowWindowBorder(ScannerForm, CoreGlobals.AppPreferences.ScannerShowBorder, CoreGlobals.AppPreferences.ScannerShowTitleBar ? ScannerForm.Text : String.Empty); Windows.EvtWindowPositionChanged += Windows_EvtWindowPositionChanged; ScannerForm.SizeChanged += ScannerForm_SizeChanged; subscribeTalkWindowManager(); ScannerForm.Shown += form_Shown; ScannerForm.VisibleChanged += form_VisibleChanged; _dialogMode = startupArg.DialogMode; var configFile = startupArg.ConfigFileName; if (String.IsNullOrEmpty(configFile)) { configFile = PanelConfigMap.GetConfigFileForScreen(ScannerForm.GetType()); } bool retVal = initWidgetManager(configFile); if (retVal) { retVal = initAnimationManager(configFile); } if (retVal) { createIdleTimer(); } PositionSizeController.Initialize(); PositionSizeController.AutoSetPosition(); _windowOverlapWatchdog = new WindowOverlapWatchdog(ScannerForm); WindowActivityMonitor.EvtWindowMonitorHeartbeat += WindowActivityMonitor_EvtWindowMonitorHeartbeat; Log.Debug("Returning from Initialize"); return(retVal); }
/// <summary> /// Event handler for when the default culture chnages /// </summary> /// <param name="sender">event sender</param> /// <param name="arg">event arg</param> private void Context_EvtCultureChanged(object sender, CultureChangedEventArg arg) { getTopOfStack().CurrentForm.Invoke(new MethodInvoker(delegate { ClearStack(); PanelConfigMap.Reset(); Init(Context.ExtensionDirs); })); }
/// <summary> /// Creates the panel with the specified panel class /// </summary> /// <param name="panelClass">the panel class</param> /// <param name="title">title of the panel</param> /// <returns>the form for the panel</returns> public Form CreatePanel(String panelClass, String title) { var startupArg = new StartupArg(panelClass) { ConfigFileName = PanelConfigMap.GetConfigFileForPanel(panelClass) }; return(CreatePanel(panelClass, title, startupArg)); }
/// <summary> /// Initialzies the specified scanner panel /// </summary> /// <param name="scannerPanel">panel to initialize</param> /// <param name="arg">panel arguments</param> /// <returns>true on success</returns> private bool initializePanel(IScannerPanel scannerPanel, PanelRequestEventArgs arg) { var startupArg = new StartupArg { FocusedElement = arg.MonitorInfo.FocusedElement, PanelClass = arg.PanelClass, ConfigFileName = PanelConfigMap.GetConfigFileForPanel(arg.PanelClass), Arg = arg.RequestArg }; Log.Debug("panelClass: " + arg.PanelClass + ", ConfigFIle: " + startupArg.ConfigFileName); return(scannerPanel.Initialize(startupArg)); }
/// <summary> /// Initialzies the specified scanner panel /// </summary> /// <param name="scannerPanel">panel to initialize</param> /// <param name="arg">panel arguments</param> /// <returns>true on success</returns> private bool initializePanel(IScannerPanel scannerPanel, PanelRequestEventArgs arg) { var startupArg = new StartupArg { FocusedElement = arg.MonitorInfo.FocusedElement, PanelClass = arg.PanelClass, Arg = arg.RequestArg }; var panelConfigMapEntry = PanelConfigMap.GetPanelConfigMapEntry(arg.PanelClass); Log.Debug("panelClass: " + arg.PanelClass + ", ConfigFIle: " + ((panelConfigMapEntry != null) ? panelConfigMapEntry.ConfigFileName : String.Empty)); return(scannerPanel.Initialize(startupArg)); }
/// <summary> /// Performs initialization. Walks the extension /// dirs and caches the Types of all the scanner/dialogs and menus. /// The Type will be used to create an instance using .NET /// relection. /// </summary> /// <param name="extensionDirs">extension dirs to walk</param> /// <returns>true on success</returns> public bool Init(IEnumerable <String> extensionDirs) { var retVal = PanelConfigMap.Load(extensionDirs); PanelConfigMap.Load(Preferences.ApplicationAssembly); if (EvtStartupAddForms != null) { EvtStartupAddForms(this, new EventArgs()); } PanelConfigMap.CleanupOrphans(); var configNames = CoreGlobals.AppPreferences.PreferredPanelConfigNames.Split(';'); PreferredPanelConfigNames = configNames; return(retVal); }
/// <summary> /// Creates the panel with the specified panel class /// </summary> /// <param name="panelClass">the panel class</param> /// <param name="panelTitle">panel title</param> /// <param name="winHandle">target window handle</param> /// <param name="focusedElement">currently focused element</param> /// <returns>the form for the panel</returns> public Form CreatePanel( ref String panelClass, String panelTitle, IntPtr winHandle, AutomationElement focusedElement) { Log.Debug("panelClass: " + panelClass); var panelConfigMapEntry = PanelConfigMap.GetPanelConfigMapEntry(panelClass); if (panelConfigMapEntry == null) { Log.Debug("Could not find panel for " + panelClass + ". Using default "); panelClass = PanelClasses.Alphabet; panelConfigMapEntry = PanelConfigMap.GetPanelConfigMapEntry(PanelClasses.Alphabet); Log.Debug("Could not find panel for " + panelClass + ". Using default " + panelConfigMapEntry.FormType.Name); } Log.Debug("panel: " + panelConfigMapEntry.FormType.Name); return(createPanel(panelClass, panelTitle, panelConfigMapEntry.FormType, winHandle, focusedElement)); }
/// <summary> /// Creates the panel with the specified panel class /// </summary> /// <param name="panelClass">the panel class</param> /// <param name="panelTitle">panel title</param> /// <param name="startupArg">statrtup arg for the panel</param> /// <returns>the form for the panel</returns> public Form CreatePanel(String panelClass, String panelTitle, StartupArg startupArg) { Log.Debug("panelClass: " + panelClass); Form form = CreatePanel(ref panelClass, panelTitle, IntPtr.Zero, null); Log.IsNull("Form for this panel ", form); if (form is IScannerPanel) { var scannerPanel = form as IScannerPanel; if (String.IsNullOrEmpty(startupArg.ConfigFileName)) { startupArg.ConfigFileName = PanelConfigMap.GetConfigFileForPanel(panelClass); } scannerPanel.Initialize(startupArg); } Log.Debug("Returning form from createPanel"); return(form); }
/// <summary> /// Performs initialization. Walks the extension /// dirs and caches the Types of all the scanner/dialogs and menus. /// The Type will be used to create an instance using .NET /// relection. /// </summary> /// <param name="extensionDirs">extension dirs to walk</param> /// <returns>true on success</returns> public bool Init(IEnumerable <String> extensionDirs) { PanelConfigMap.Reset(); var retVal = PanelConfigMap.Load(extensionDirs); PanelConfigMap.Load(Preferences.ApplicationAssembly); if (EvtStartupAddForms != null) { EvtStartupAddForms(this, new EventArgs()); } PanelConfigMap.CleanupOrphans(); if (!String.IsNullOrEmpty(CoreGlobals.AppPreferences.PreferredPanelConfigNames)) { PanelConfigMap.SetDefaultPanelConfig(CoreGlobals.AppPreferences.PreferredPanelConfigNames.Trim()); } return(retVal); }
/// <summary> /// Returns the config file for this form. /// </summary> /// <returns></returns> private String getConfigFile() { return(!String.IsNullOrEmpty(_panelName) ? PanelConfigMap.GetConfigFileForPanel(_panelName) : PanelConfigMap.GetConfigFileForScreen(_form.GetType())); }
/// <summary> /// A scanner closed. If this panel has child windows (scanners) /// close them as well. If there is a parent, Resume it. /// </summary> /// <param name="sender">event sender</param> /// <param name="e">event args</param> private void panel_FormClosed(object sender, FormClosedEventArgs e) { var form = (Form)sender; Log.Debug("Enter (" + form.Name + ")"); IPanel panel = form as IPanel; if (panel.SyncObj.Status == SyncLock.StatusValues.Closed) { Log.Debug("Form is already closed. Returning " + form.Name); return; } Log.Debug("Setting CLOSED for " + form.Name); (form as IPanel).SyncObj.Status = SyncLock.StatusValues.Closed; form.FormClosed -= panel_FormClosed; Form parentForm = form.Owner; Form[] array = form.OwnedForms; auditLogScannerEvent(form, "close"); Log.Debug("number of owned forms: " + array.Length); // close all the forms this panel owns while (true) { Form[] ownedForms = form.OwnedForms; if (ownedForms.Length == 0) { Log.Debug(form.Name + ": No more owned forms. Breaking"); break; } Log.Debug("Removing owned form from list. " + ownedForms[0].Name); form.RemoveOwnedForm(ownedForms[0]); Log.Debug("Calling close on " + ownedForms[0].Name); Windows.CloseForm(ownedForms[0]); } Log.Debug("form Name: " + form.Name + ", type: " + form.GetType()); // Exit the application if instructed to do so. if (Context.AppQuit) { if (!_appCloseNotifed) { _appCloseNotifed = true; Context.AppPanelManager.NotifyQuitApplication(); Application.ExitThread(); } } else if (parentForm != null) { // Resume the parent if it is prudent to do so. Log.Debug("parent Form is " + parentForm.Name); IPanel parentPanel = (IPanel)parentForm; if (parentPanel.SyncObj.IsClosing()) { Log.Debug("*** Parent is closing. Will not call OnResume"); } else { Log.Debug("parentform is not closing. Setting _currentPanel to " + parentForm.Name + ", type: " + parentForm.GetType()); _currentPanel = parentForm; _currentForm = parentForm; Log.Debug("Calling OnResume on parentForm " + parentForm.Name); parentPanel.OnResume(); //_currentPanel = parentForm; // moved up //_currentForm = parentForm; // moved up auditLogScannerEvent(parentForm, "show"); } } else { Log.Debug("parentform is null"); _currentPanel = null; _currentForm = null; } var panelClass = (form is IScannerPanel) ? ((IScannerPanel)form).PanelClass : PanelClasses.None; if (!PanelConfigMap.AreEqual(panelClass, PanelClasses.None)) { Log.Debug("Calling AppAgentMgr.OnPanelClosed for " + panelClass); Context.AppAgentMgr.OnPanelClosed(panelClass); } if (EvtScannerClosed != null) { Log.Debug("Calling evetscannerclosed for " + form.Name); EvtScannerClosed(this, new ScannerCloseEventArg(form as IPanel)); } else { Log.Debug("EvtScannerClosed is NULL"); } // (form as IPanel).SyncObj.Status = SyncLock.StatusValues.Closed; // moved this up Log.Debug("Exit " + form.Name); }
/// <summary> /// Event handler for request to display a scanner. The /// arg parameter contains information about which scanner /// to display /// </summary> /// <param name="sender">event sender</param> /// <param name="arg">event arg</param> public void AppAgent_EvtPanelRequest(object sender, PanelRequestEventArgs arg) { Log.Debug("A request came in for panel " + arg.PanelClass + ". NewWindow is " + arg.MonitorInfo.IsNewWindow); if (_currentForm != null) { Log.Debug("_currentForm is " + _currentForm.Name + ", type: " + _currentForm.GetType() + ", IsModal: " + _currentForm.Modal); Form owner = _currentForm.Owner; if (owner != null) { Log.Debug("owner is : " + owner.Name + ", type: " + owner.GetType() + ", is owner ipanel? " + (_currentForm.Owner is IPanel)); } else { Log.Debug("_currentForm.Owner is null"); } // if a modal dialog is currently open, don't honor the request. // the modal dialog has to be closed first. if (arg.TargetPanel == null || arg.TargetPanel != _currentForm) { if (_currentForm.Modal || (_currentForm.Owner != null && _currentForm.Owner.Modal)) { Log.Debug("A modal dialog is open. Will not honor panel request"); return; } } } // if no panel type, use the alphabet scanner as the String requestedPanelClass = arg.PanelClass; if (PanelConfigMap.AreEqual(arg.PanelClass, PanelClasses.None)) { requestedPanelClass = PanelClasses.Alphabet; } IScannerPanel currentScanner = _currentPanel as IScannerPanel; if (arg.MonitorInfo.IsNewWindow) { Log.Debug("This is a new window. winHandle: " + arg.MonitorInfo.FgHwnd); if (currentScanner != null) { Log.Debug("currentpanel: " + currentScanner.PanelClass + ", requested: " + requestedPanelClass); } else { Log.Debug("_currentPanel is null or not IScannerPanel. Activate alphabet scanner"); requestedPanelClass = PanelClasses.Alphabet; } // if the current scanner is the same as the requested one, just show it if (currentScanner != null && PanelConfigMap.AreEqual(currentScanner.PanelClass, requestedPanelClass) && _currentPanel.Owner == null) { Log.Debug("Current panel is already " + requestedPanelClass + ", calling Show()"); _currentPanel.TopMost = true; if (_currentPanel is MenuPanelBase) { (_currentPanel as MenuPanelBase).SetTitle(arg.Title); } Show(null, (IPanel)_currentPanel); } else { // check with the agent if it is OK to switch panels. if ((currentScanner == null) || currentScanner.OnQueryPanelChange(arg)) { switchCurrentPanel(arg); } } } else { if (currentScanner == null) { Log.Debug("_currentPanel is null. returning"); return; } Log.Debug("Not a new window. _currentPanel is " + currentScanner.PanelClass + " requested panel is " + requestedPanelClass); // if the current panel is not the same as the requested one, query the // agent if it is OK to switch and then do the switch if (!PanelConfigMap.AreEqual(currentScanner.PanelClass, requestedPanelClass) && currentScanner.OnQueryPanelChange(arg)) { switchCurrentPanel(arg); } else { Log.Debug("Will not switch panels. Current: " + currentScanner.PanelClass + ", requested: " + requestedPanelClass); if (currentScanner is MenuPanelBase) { (currentScanner as MenuPanelBase).SetTitle(arg.Title); } } } }
/// <summary> /// Add the form of the specified type to the form cache. /// </summary> /// <param name="type">the .NET type</param> public void AddFormToCache(Type type) { var guid = PanelConfigMap.GetFormId(type); PanelConfigMap.AddFormToCache(guid, type); }
/// <summary> /// A scanner closed. If this panel has child windows (scanners) /// close them as well. If there is a parent, Resume it. /// </summary> /// <param name="sender">event sender</param> /// <param name="e">event args</param> private void panel_FormClosed(object sender, FormClosedEventArgs e) { var form = (Form)sender; Log.Debug("Enter (" + form.Name + ")"); IPanel panel = form as IPanel; if (panel.SyncObj.Status == SyncLock.StatusValues.Closed) { Log.Debug("Form is already closed. Returning " + form.Name); return; } form.FormClosed -= panel_FormClosed; Form parentForm = form.Owner; String panelClass = PanelClasses.None; Form[] array = form.OwnedForms; auditLogScannerEvent(form, "close"); Log.Debug("number of owned forms: " + array.Length); // close all the forms this panel owns while (true) { Form[] a = form.OwnedForms; if (a.Length == 0) { Log.Debug(form.Name + ": No more owned forms. Breaking"); break; } Log.Debug("Removing owned form from list. " + a[0].Name); form.RemoveOwnedForm(a[0]); Log.Debug("Calling close on " + a[0].Name); Windows.CloseForm(a[0]); } Log.Debug("form Name: " + form.Name + ", type: " + form.GetType()); if (_currentPanel is IScannerPanel) { panelClass = ((IScannerPanel)_currentPanel).PanelClass; } // Exit the application if instructed to do so. if (Context.AppQuit) { Application.ExitThread(); } else if (parentForm != null) { // Resume the parent if it is prudent to do so. Log.Debug("parent Form is " + parentForm.Name); IPanel parentPanel = (IPanel)parentForm; if (parentPanel.SyncObj.IsClosing()) { Log.Debug("*** Parent is closing. Will not call OnResume"); } else { Log.Debug("Calling OnResume on parentForm " + parentForm.Name); parentPanel.OnResume(); Log.Debug("parentform is not null. Setting _currentPanel to " + parentForm.Name + ", type: " + parentForm.GetType()); _currentPanel = parentForm; _currentForm = parentForm; auditLogScannerEvent(parentForm, "show"); } } else { Log.Debug("parentform is null"); } // Inform the AgentManager that a scanner just closed if (!PanelConfigMap.AreEqual(panelClass, PanelClasses.None)) { Log.Debug("Calling OnPanelClosed for " + panelClass); Context.AppAgentMgr.OnPanelClosed(panelClass); } Log.Debug("Setting CLOSED for " + form.Name); (form as IPanel).SyncObj.Status = SyncLock.StatusValues.Closed; Log.Debug("Exit " + form.Name); }