Пример #1
0
        /// <summary>
        /// Informs any Form that is registered in TFormsList about a specific 'Forms Message'
        /// that is being 'broadcasted'.
        /// </summary>
        /// <remarks>The individual Form can choose to 'listen' to such 'Forms Message' broadcasts
        /// by implementing the Method 'ProcessFormsMessage'. Once this is done, the Forms'
        /// 'ProcessFormsMessage' Method will be called each time a 'Forms Message' broadcast occurs.
        /// </remarks>
        /// <param name="AFormsMessage">An instance of a 'Forms Message'. This can be inspected
        /// for parameters in the Method Body of a Forms' 'ProcessFormsMessage' Method and
        /// the Form can use those to choose whether to react on the Message, or not.</param>
        /// <returns>The Number of Forms that reacted on the 'Forms Message'.</returns>
        public int BroadcastFormMessage(TFormsMessage AFormsMessage)
        {
            System.Windows.Forms.Form FormInstance;
            IDictionaryEnumerator     DictEnum;
            int FormsThatReacted = 0;

            DictEnum = this.GetEnumerator();

            while (DictEnum.MoveNext())
            {
                FormInstance = (System.Windows.Forms.Form)DictEnum.Value;

                var        Type   = FormInstance.GetType();
                MethodInfo Method = Type.GetMethod("ProcessFormsMessage");

                // Does form contain the method "ProcessFormsMessage"?
                // If so, call it.
                if ((Method != null) && ((bool)Method.Invoke(FormInstance, new object[] { AFormsMessage }) == true))
                {
//                    MessageBox.Show("BroadcastFormMessage: FormInstance = " + FormInstance.Name);
                    FormsThatReacted++;
                }
            }

//            MessageBox.Show("FormsThatListened: " + FormsThatListened.ToString());
            return(FormsThatReacted);
        }
Пример #2
0
        /// <summary>
        /// todoComment
        /// </summary>
        /// <returns></returns>
        public String OpenForms()
        {
            String ReturnValue = "";

            System.Windows.Forms.Form FormInstance;
            IDictionaryEnumerator     DictEnum;

            DictEnum = GetEnumerator();

            while (DictEnum.MoveNext())
            {
                FormInstance = (System.Windows.Forms.Form)DictEnum.Value;
                ReturnValue += String.Format(StrPrintFormat, new Object[] { FormInstance.Name, FormInstance.Text }) + "\r\n";
            }

            return(ReturnValue);
        }
Пример #3
0
        /// <summary>
        /// todoComment
        /// </summary>
        /// <param name="AValue"></param>
        /// <returns></returns>
        public Boolean Contains(System.Windows.Forms.Form AValue)
        {
            System.Windows.Forms.Form FormInstance;
            IDictionaryEnumerator     DictEnum;

            DictEnum = GetEnumerator();

            while (DictEnum.MoveNext())
            {
                FormInstance = (System.Windows.Forms.Form)DictEnum.Value;

                if (FormInstance.GetType().ToString().StartsWith(AValue.Text))
                {
                    return(true);
                }
            }

            return(false);
        }
Пример #4
0
        /// <summary>
        /// todoComment
        /// </summary>
        /// <param name="ADontCloseForm"></param>
        /// <returns></returns>
        public Boolean CloseAllExceptOne(System.Windows.Forms.Form ADontCloseForm)
        {
            System.Windows.Forms.Form FormInstance;
            IDictionaryEnumerator     DictEnum;

            System.Object OldKey;
            try
            {
                DictEnum = GetEnumerator();

                while (DictEnum.MoveNext())
                {
                    FormInstance = (System.Windows.Forms.Form)DictEnum.Value;
                    OldKey       = DictEnum.Key;

                    if ((ADontCloseForm == null) || (FormInstance.GetType() != ADontCloseForm.GetType()))
                    {
                        // MessageBox.Show('ADontCloseForm.GetType: ' + ADontCloseForm.GetType().ToString);
                        // MessageBox.Show('About to close Form: ' + FormInstance.GetType().ToString + '; Title: ' + FormInstance.Text);
                        FormInstance.Close();

                        // make sure the form really has been removed; otherwise it could be an endless loop
                        if (Dictionary.Contains(OldKey) == true)
                        {
                            Dictionary.Remove(OldKey);
                        }

                        /*
                         * Need to go back to the beginning of the enumerator because the Enumerator won't work
                         * anymore after a Form has been closed (when a Form closes it removes
                         * itself from the FormsList)!
                         */
                        DictEnum = GetEnumerator();
                    }
                }
            }
            catch (Exception Exp)
            {
                MessageBox.Show("TFormsList.CloseAll: Exception occured while trying to close forms: " + Exp.ToString());
                return(false);
            }
            return(true);
        }
Пример #5
0
        /// <summary>
        /// todoComment
        /// </summary>
        /// <param name="ATitle"></param>
        /// <returns></returns>
        private System.Windows.Forms.Form GetFormByTitle(String ATitle)
        {
            System.Windows.Forms.Form FormInstance;
            IDictionaryEnumerator     DictEnum;

            DictEnum = GetEnumerator();

            while (DictEnum.MoveNext())
            {
                FormInstance = (System.Windows.Forms.Form)DictEnum.Value;

                // MessageBox.Show('GetForm: FormInstance: ' + FormInstance.GetType().ToString);
                if (FormInstance.Text.StartsWith(ATitle))
                {
                    return(FormInstance);
                }
            }

            return(null);
        }
Пример #6
0
        /// <summary>
        /// todoComment
        /// </summary>
        /// <param name="AWindowHandle"></param>
        /// <returns></returns>
        public System.Windows.Forms.Form GetFormByHandle(IntPtr AWindowHandle)
        {
            System.Windows.Forms.Form FormInstance;
            IDictionaryEnumerator     DictEnum;

            DictEnum = GetEnumerator();

            while (DictEnum.MoveNext())
            {
                FormInstance = (System.Windows.Forms.Form)DictEnum.Value;

                if (!FormInstance.IsDisposed)
                {
                    if (FormInstance.Handle == AWindowHandle)
                    {
                        return(FormInstance);
                    }
                }
            }

            return(null);
        }
Пример #7
0
        /// <summary>todoComment</summary>
        public System.Windows.Forms.Form this[string AKey]
        {
            get
            {
                System.Windows.Forms.Form ReturnValue;
                IDictionaryEnumerator     DictEnum;
                ReturnValue = null;
                DictEnum    = GetEnumerator();

                while (DictEnum.MoveNext())
                {
                    // MessageBox.Show('GetForm: DictEnum.Key: ' + DictEnum.Key.ToString);
                    if (DictEnum.Key.ToString().StartsWith(AKey))
                    {
                        ReturnValue = (System.Windows.Forms.Form)DictEnum.Value;
                        return(ReturnValue);
                    }
                }

                return(ReturnValue);
            }

            set
            {
                IDictionaryEnumerator DictEnum;
                DictEnum = GetEnumerator();

                while (DictEnum.MoveNext())
                {
                    // MessageBox.Show('GetForm: DictEnum.Key: ' + DictEnum.Key.ToString);
                    if (DictEnum.Key.ToString().StartsWith(AKey))
                    {
                        Dictionary[DictEnum.Value] = value;
                        return;
                    }
                }
            }
        }
Пример #8
0
        /// <summary>
        /// todoComment
        /// </summary>
        /// <param name="ANonClosableForms"></param>
        /// <param name="AFirstNonCloseableFormKey"></param>
        /// <returns></returns>
        public Boolean CanCloseAll(out StringCollection ANonClosableForms, out String AFirstNonCloseableFormKey)
        {
            System.Windows.Forms.Form FormInstance;
            IDictionaryEnumerator     DictEnum;
            String NonCloseableForm;

            ANonClosableForms         = new StringCollection();
            AFirstNonCloseableFormKey = "";
            DictEnum = GetEnumerator();

            while (DictEnum.MoveNext())
            {
                FormInstance = (System.Windows.Forms.Form)DictEnum.Value;

                if (FormInstance is IFrmPetraEdit)
                {
                    if (!((IFrmPetraEdit)FormInstance).CanClose())
                    {
                        NonCloseableForm = FormInstance.Text;

                        if (((TFrmPetraEditUtils)((IFrmPetraEdit)FormInstance).GetPetraUtilsObject()).HasChanges)
                        {
                            NonCloseableForm = NonCloseableForm + PetraEditForm.FORM_CHANGEDDATAINDICATOR;
                        }

                        ANonClosableForms.Add(NonCloseableForm);

                        if (ANonClosableForms.Count == 1)
                        {
                            AFirstNonCloseableFormKey = DictEnum.Key.ToString();
                        }
                    }
                }
            }

            return(ANonClosableForms.Count == 0);
        }
Пример #9
0
        private static void ProtocolReaderLine()
        {
            if (LineText == "")
            {
                return;
            }
            if (LineText[0] == '$')
            {
                if (LineText.Length >= 2)
                {
                    if (LineText[1] == '$')
                    {
                        MMode2 = LineText.TrimStart('$');
                    }
                    else
                    {
                        MMode1 = LineText.TrimStart('$');
                    }
                }
                return;
            }
            if (LineText[0] == '@')
            {
                ClassDesc = LineText.TrimStart('@');
                return;
            }
            LineText.Trim();
            ProtocolReaderLineAnalyze();

            if (LineContect.Count <= 0)
            {
                return;
            }
            if (LineContect[0] == "enums")
            {
                BodyType    = EBodyType.eBodyTypeEnum;
                EnumCurrent = new CEnum(LineContect[1], ClassDesc);
                CEnumId     = 0;
            }
            else if (LineContect[0] == "enume")
            {
                DictEnum.Add(EnumCurrent.Name, EnumCurrent);
            }
            else if (LineContect[0] == "msgs")
            {
                BodyType = EBodyType.eBodyTypeClass;
                if (LineContect.Count > 2)
                {
                    ClassCurrent = new CClass(0, LineContect[1], ClassDesc, S2I(LineContect[2]));
                }
                else
                {
                    ClassCurrent = new CClass(0, LineContect[1], ClassDesc);
                }
            }
            else if (LineContect[0] == "msge")
            {
                DictClass.Add(ClassCurrent.Name, ClassCurrent);
            }
            else if (LineContect[0] == "pubs")
            {
                BodyType = EBodyType.eBodyTypeClass;
                if (LineContect.Count > 2)
                {
                    ClassCurrent = new CClass(1, LineContect[1], ClassDesc, S2I(LineContect[2]));
                }
                else
                {
                    ClassCurrent = new CClass(1, LineContect[1], ClassDesc);
                }
            }
            else if (LineContect[0] == "pube")
            {
                DictClass.Add(ClassCurrent.Name, ClassCurrent);
            }
            else
            {
                if (BodyType == EBodyType.eBodyTypeEnum)
                {
                    var node = new CEnum.Node()
                    {
                        Line = LineCount,
                        Body = LineContect[0],
                    };
                    if (LineContect.Count > 1)
                    {
                        CEnumId    = S2I(LineContect[1]);
                        node.Value = CEnumId;
                    }
                    else
                    {
                        CEnumId++;
                        node.Value = CEnumId;
                    }
                    node.Desc = LineDesc;
                    EnumCurrent.DictBody.Add(LineCount, node);
                }
                else if (BodyType == EBodyType.eBodyTypeClass)
                {
                    var node = new CClassNode();
                    GetNodeFromLine(ref node);
                    ClassCurrent.DictBody.Add(LineCount, node);
                }
            }
        }