示例#1
0
        public static string?GetFormulaEditPrefix()
        {
            if (_shutdownStarted)
            {
                return(null);
            }

            try
            {
                var fmlaInfo = new FmlaInfo();
                var result   = LPenHelper(xlGetFmlaInfo, ref fmlaInfo);

                if (result != 0)
                {
                    Logger.WindowWatcher.Warn($"LPenHelper Failed. Result: {result}");

                    // This exception is poorly handled when it happens in the SyncMacro
                    // We only expect the error to happen during shutdown, in which case we might as well
                    // handle this as if no formula is being edited
                    // throw new InvalidOperationException("LPenHelper Failed. Result: " + result);
                    // -
                    return(null);
                }

                if (fmlaInfo.wPointMode == xlModeReady)
                {
                    Logger.WindowWatcher.Verbose($"LPenHelper PointMode Ready");
                    return(null);
                }

                // We seem to mis-track in the click case when wPointMode changed from xlModeEnter to xlModeEdit

                string fullFormula = Marshal.PtrToStringUni(fmlaInfo.lpch, fmlaInfo.cch);

                Logger.WindowWatcher.Verbose("LPenHelper Status: PointMode: {0}, Formula: {1}, First: {2}, Last: {3}, Caret: {4}",
                                             fmlaInfo.wPointMode, fullFormula, fmlaInfo.ichFirst, fmlaInfo.ichLast, fmlaInfo.ichCaret);

                var prefixLen = Math.Min(Math.Max(fmlaInfo.ichCaret, fmlaInfo.ichLast), fmlaInfo.cch);  // I've never seen ichLast > cch !?

                string formulaPrefix = Marshal.PtrToStringUni(fmlaInfo.lpch, prefixLen);

                IntelliSenseEvents.Instance.OnEditingFormula(fullFormula, formulaPrefix);

                return(formulaPrefix);
            }
            catch (AccessViolationException)
            {
                Logger.WindowWatcher.Warn("LPenHelper - Access Violation!");

                return(null);
            }
            catch (Exception ex)
            {
                // Some unexpected error - for now we log as an error and re-throw
                Logger.WindowWatcher.Error(ex, "LPenHelper - Unexpected Error");
                throw;
            }
        }
示例#2
0
        // Returns null if not in edit mode
        public static string GetFormulaEditPrefix()
        {
            var fmlaInfo = new FmlaInfo();
            var result = LPenHelper(xlGetFmlaInfo, ref fmlaInfo);
            if (result != 0)
            {
                throw new InvalidOperationException("LPenHelper failed. Result: " + result);
            }
            if (fmlaInfo.wPointMode == xlModeReady) return null;

            Debug.Print("LPenHelper Status: PointMode: {0}, Formula: {1}, First: {2}, Last: {3}, Caret: {4}",
                fmlaInfo.wPointMode, Marshal.PtrToStringUni(fmlaInfo.lpch, fmlaInfo.cch), fmlaInfo.ichFirst, fmlaInfo.ichLast, fmlaInfo.ichCaret);

            var prefixLen = Math.Min(Math.Max(fmlaInfo.ichCaret, fmlaInfo.ichLast), fmlaInfo.cch);  // I've never seen ichLast > cch !?
            return Marshal.PtrToStringUni(fmlaInfo.lpch, prefixLen);
        }
示例#3
0
        public static string GetFormulaEditPrefix()
        {
            if (_shutdownStarted)
                return null;

            try
            {
                var fmlaInfo = new FmlaInfo();
                var result = LPenHelper(xlGetFmlaInfo, ref fmlaInfo);
                if (result != 0)
                {
                    Logger.WindowWatcher.Warn($"LPenHelper Failed. Result: {result}");
                    // This exception is poorly handled when it happens in the SyncMacro
                    // We only expect the error to happen during shutdown, in which case we might as well
                    // handle this asif no formula is being edited
                    // throw new InvalidOperationException("LPenHelper Failed. Result: " + result);
                    return null;
                }
                if (fmlaInfo.wPointMode == xlModeReady)
                {
                    // Logger.WindowWatcher.Verbose($"LPenHelper PointMode Ready");
                    return null;
                }

                //Logger.WindowWatcher.Verbose("LPenHelper Status: PointMode: {0}, Formula: {1}, First: {2}, Last: {3}, Caret: {4}",
                //    fmlaInfo.wPointMode, Marshal.PtrToStringUni(fmlaInfo.lpch, fmlaInfo.cch), fmlaInfo.ichFirst, fmlaInfo.ichLast, fmlaInfo.ichCaret);

                var prefixLen = Math.Min(Math.Max(fmlaInfo.ichCaret, fmlaInfo.ichLast), fmlaInfo.cch);  // I've never seen ichLast > cch !?
                return Marshal.PtrToStringUni(fmlaInfo.lpch, prefixLen);
            }
            catch (AccessViolationException)
            {
                Logger.WindowWatcher.Warn("LPenHelper - Access Violation!");
                return null;
            }
            catch (Exception ex)
            {
                // Some unexpected error - for now we log as an error and re-throw
                Logger.WindowWatcher.Error(ex, "LPenHelper - Unexpected Error");
                throw;
            }
        }
示例#4
0
        // Returns null if not in edit mode
        public static string GetFormulaEditPrefix()
        {
            var fmlaInfo = new FmlaInfo();
            var result   = LPenHelper(xlGetFmlaInfo, ref fmlaInfo);

            if (result != 0)
            {
                throw new InvalidOperationException("LPenHelper failed. Result: " + result);
            }
            if (fmlaInfo.wPointMode == xlModeReady)
            {
                return(null);
            }

            Debug.Print("LPenHelper Status: PointMode: {0}, Formula: {1}, First: {2}, Last: {3}, Caret: {4}",
                        fmlaInfo.wPointMode, Marshal.PtrToStringUni(fmlaInfo.lpch, fmlaInfo.cch), fmlaInfo.ichFirst, fmlaInfo.ichLast, fmlaInfo.ichCaret);

            var prefixLen = Math.Min(Math.Max(fmlaInfo.ichCaret, fmlaInfo.ichLast), fmlaInfo.cch);  // I've never seen ichLast > cch !?

            return(Marshal.PtrToStringUni(fmlaInfo.lpch, prefixLen));
        }
示例#5
0
 internal static extern int LPenHelper(int wCode, ref FmlaInfo fmlaInfo); // 'long' return value means 'int' in C (so why different?)
示例#6
0
 static extern int LPenHelper(int wCode, ref FmlaInfo fmlaInfo); // 'long' return value means 'int' in C (so why different?)
示例#7
0
文件: XlCall.cs 项目: Ryknyk/ExcelDna
 internal static extern int LPenHelper(int wCode, ref FmlaInfo fmlaInfo);