public void MousePosToTextPos(int mouseX, int mouseY, out int textX, out int textY)
        {
            SizeF pitch = GetRenderProfile().Pitch;

            textX = RuntimeUtil.AdjustIntRange((int)Math.Floor((mouseX - CharacterDocumentViewer.BORDER) / pitch.Width), 0, Int32.MaxValue);
            textY = RuntimeUtil.AdjustIntRange((int)Math.Floor((mouseY - CharacterDocumentViewer.BORDER) / (pitch.Height + GetRenderProfile().LineSpacing)), 0, Int32.MaxValue);
        }
        public void OnNewItem(IPoderosaLogItem item)
        {
            //カテゴリ分けなどあるかもしれないが...
            String text  = String.Format("[{0}] {1}", item.Category.Name, item.Text);
            int    width = PoderosaLogDocument.DefaultWidth;

            //width文字ごとに切り取り。日本語文字があるケースは未サポート
            int offset = 0;

            while (offset < text.Length)
            {
                int   next = RuntimeUtil.AdjustIntRange(offset + width, 0, text.Length);
                GLine line = new GLine(text.Substring(offset, next - offset).ToCharArray(), new GWord(TextDecoration.ClonedDefault(), 0, CharGroup.Hankaku));
                line.EOLType = next < text.Length? EOLType.Continue : EOLType.CRLF;
                Append(line);
                offset = next;
            }

            PoderosaLogViewControl vc = _session.CurrentView;

            if (vc != null)
            {
                if (vc.InvokeRequired)
                {
                    vc.Invoke(vc.UpdateDocumentDelegate);
                }
                else
                {
                    vc.UpdateDocument();
                }
            }
        }
예제 #3
0
        //選択モードに応じて範囲を定める。マウスでドラッグすることもあるので、column<0のケースも存在する
        public TextPoint ConvertSelectionPosition(GLine line, int column)
        {
            TextPoint result = new TextPoint(line.ID, column);

            int line_length = line.DisplayLength;

            if (_pivotType == RangeType.Line)
            {
                //行選択のときは、選択開始点以前のであったらその行の先頭、そうでないならその行のラスト。
                //言い換えると(Pivot-Destination)を行頭・行末方向に拡大したものになるように
                if (result.Line <= _forwardPivot.Line)
                {
                    result.Column = 0;
                }
                else
                {
                    result.Column = line.DisplayLength;
                }
            }
            else //Word,Char選択
            {
                if (result.Line < _forwardPivot.Line) //開始点より前のときは
                {
                    if (result.Column < 0)
                    {
                        result.Column = 0;                 //行頭まで。
                    }
                    else if (result.Column >= line_length) //行の右端の右まで選択しているときは、次行の先頭まで
                    {
                        result.Line++;
                        result.Column = 0;
                    }
                }
                else if (result.Line == _forwardPivot.Line) //同一行内選択.その行におさまるように
                {
                    result.Column = RuntimeUtil.AdjustIntRange(result.Column, 0, line_length);
                }
                else //開始点の後方への選択
                {
                    if (result.Column < 0)
                    {
                        result.Line--;
                        result.Column = line.PrevLine == null? 0 : line.PrevLine.DisplayLength;
                    }
                    else if (result.Column >= line_length)
                    {
                        //result.Column = line_length;

                        /* KM 2012/10/07 22:36:28
                         *  矩形選択で文字のない場所を矩形の端点にする為コメントアウト。
                         *  最終的に文字列をコピーする時に、再度同様のチェックを行うので問題は生じない様だ。
                         */
                    }
                }
            }

            return(result);
        }
예제 #4
0
 //更新 最終行が見えるように
 public void UpdateDocument() {
     PoderosaLogDocument doc = _session.Document;
     int newtop = RuntimeUtil.AdjustIntRange(doc.Size - this.GetHeightInLines(), 0, doc.Size - 1);
     AdjustScrollBar();
     if (_VScrollBar.Enabled)
         _VScrollBar.Value = newtop;
     else
         Invalidate();
 }
예제 #5
0
        private static void SessionEntryPoint(AbstractTerminal terminal, CommandResultDocument document)
        {
            try {
                TerminalControl tc = terminal.TerminalHost.TerminalControl;
                Debug.Assert(tc != null);
                RenderProfile          rp          = (RenderProfile)tc.GetRenderProfile().Clone();
                CommandResultSession   session     = new CommandResultSession(document, rp); //現在のRenderProfileを使ってセッションを作る
                TerminalDocument       terminaldoc = terminal.GetDocument();
                PopupViewCreationParam cp          = new PopupViewCreationParam(_viewFactory);
                //結果のサイズに合わせる。ただし高さは20行を上限とする
                cp.InitialSize = new Size(tc.ClientSize.Width, (int)(RuntimeUtil.AdjustIntRange(document.Size, 0, 20) * rp.Pitch.Height) + 2);
                cp.OwnedByCommandTargetWindow = GEnv.Options.CommandPopupAlwaysOnTop;
                cp.ShowInTaskBar = GEnv.Options.CommandPopupInTaskBar;

                IWindowManager       wm     = TerminalEmulatorPlugin.Instance.GetWindowManager();
                ISessionManager      sm     = TerminalEmulatorPlugin.Instance.GetSessionManager();
                IPoderosaPopupWindow window = wm.CreatePopupView(cp);
                sm.StartNewSession(session, window.InternalView);
                sm.ActivateDocument(session.Document, ActivateReason.InternalAction);
            }
            catch (Exception ex) {
                RuntimeUtil.ReportException(ex);
            }
        }
        public override UIHandleResult OnMouseMove(MouseEventArgs args)
        {
            if (args.Button != MouseButtons.Left)
            {
                return(UIHandleResult.Pass);
            }
            TextSelection sel = _viewer.TextSelection;

            if (sel.State == SelectionState.Fixed || sel.State == SelectionState.Empty)
            {
                return(UIHandleResult.Pass);
            }
            //クリックだけでもなぜかMouseDownの直後にMouseMoveイベントが来るのでこのようにしてガード。でないと単発クリックでも選択状態になってしまう
            if (sel.StartX == args.X && sel.StartY == args.Y)
            {
                return(UIHandleResult.Capture);
            }

            CharacterDocument document = _viewer.CharacterDocument;

            lock (document) {
                int   topline_id = _viewer.GetTopLine().ID;
                SizeF pitch = _viewer.GetRenderProfile().Pitch;
                int   row, col;
                _viewer.MousePosToTextPos_AllowNegative(args.X, args.Y, out col, out row);
                int viewheight = (int)Math.Floor(_viewer.ClientSize.Height / pitch.Width);
                int target_id  = topline_id + row;

                GLine target_line             = document.FindLineOrEdge(target_id);
                TextSelection.TextPoint point = sel.ConvertSelectionPosition(target_line, col);

                point.Line = RuntimeUtil.AdjustIntRange(point.Line, document.FirstLineNumber, document.LastLineNumber);

                if (_viewer.VScrollBar.Enabled)   //スクロール可能なときは
                {
                    VScrollBar vsc = _viewer.VScrollBar;
                    if (target_id < topline_id) //前方スクロール
                    {
                        vsc.Value = point.Line - document.FirstLineNumber;
                    }
                    else if (point.Line >= topline_id + vsc.LargeChange)   //後方スクロール
                    {
                        int newval = point.Line - document.FirstLineNumber - vsc.LargeChange + 1;
                        if (newval < 0)
                        {
                            newval = 0;
                        }
                        if (newval > vsc.Maximum - vsc.LargeChange)
                        {
                            newval = vsc.Maximum - vsc.LargeChange + 1;
                        }
                        vsc.Value = newval;
                    }
                }
                else   //スクロール不可能なときは見えている範囲で
                {
                    point.Line = RuntimeUtil.AdjustIntRange(point.Line, topline_id, topline_id + viewheight - 1);
                } //ここさぼっている
                //Debug.WriteLine(String.Format("MouseMove {0} {1} {2}", sel.State, sel.PivotType, args.X));
                RangeType rt = sel.PivotType;
                if ((Control.ModifierKeys & Keys.Control) != Keys.None)
                {
                    rt = RangeType.Word;
                }
                else if ((Control.ModifierKeys & Keys.Shift) != Keys.None)
                {
                    rt = RangeType.Line;
                }

                GLine tl = document.FindLine(point.Line);
                sel.ExpandTo(tl, point.Column, rt);
            }
            _viewer.Invalidate(); //TODO 選択状態に変化のあった行のみ更新するようにすればなおよし
            return(UIHandleResult.Capture);
        }