コード例 #1
0
        protected unsafe override void OnDrawPacketEnd(bool auto_scroll, bool next_packet_exist)
        {
            /* 未出力データを表示 */
            DrawBufferFlush();

            /* 自動スクロールの場合はここでスクロール位置を取得。
             * テキストが追加されていれば、この時点でスクロール位置は
             * 終端になっている */
            if (auto_scroll)
            {
                view_line_number_scroll_ = WinAPI.SendMessage(TBox_Main.Handle, WinAPI.EM_GETFIRSTVISIBLELINE, 0, 0).ToInt32();
            }

            /* 選択状態を復元 */
            if (WINAPI_MODE)
            {
                WinAPI.SendMessage(TBox_Main.Handle, WinAPI.EM_SETSEL, select_pos_start_, select_pos_end_);
            }
            else
            {
                TBox_Main.SelectionStart  = select_pos_start_;
                TBox_Main.SelectionLength = select_pos_end_ - select_pos_start_;
            }

            /* スクロール位置を補正 */
            WinAPI.SendMessage(
                TBox_Main.Handle,
                WinAPI.EM_LINESCROLL,
                0,
                view_line_number_scroll_ - WinAPI.SendMessage(TBox_Main.Handle, WinAPI.EM_GETFIRSTVISIBLELINE, 0, 0).ToInt32());

            /* 表示量を制限 */
            if (VIEW_DATA_LIMIT)
            {
                var text_len     = TBox_Main.TextLength;
                var text_len_max = VIEW_DATA_LIMIT_SIZE;

                if (text_len > text_len_max)
                {
                    fixed(int *select_pos_start_p = &select_pos_start_)
                    {
                        fixed(int *select_pos_end_p = &select_pos_end_)
                        {
                            /* 選択状態をバックアップ */
                            WinAPI.SendMessage(TBox_Main.Handle, WinAPI.EM_GETSEL, select_pos_start_p, select_pos_end_p);

                            /* 削除対象を選択状態にする */
                            WinAPI.SendMessage(TBox_Main.Handle, WinAPI.EM_SETSEL, 0, text_len - text_len_max + text_len_max / 2);

                            /* 削除実行 */
                            WinAPI.SendMessage(TBox_Main.Handle, WinAPI.EM_REPLACESEL, 0, "");

                            /* 選択状態を戻す */
                            WinAPI.SendMessage(TBox_Main.Handle, WinAPI.EM_SETSEL, select_pos_start_, select_pos_end_);
                        }
                    }
                }
            }

            /* 描画を再開 */
            WinAPI.SendMessage(TBox_Main.Handle, WinAPI.WM_SETREDRAW, 1, 0);
            TBox_Main.Invalidate();
        }