Moved cursor blinking functionality from TermParse into TermView (and

from a BMessageRunner into Pulse()). Removed more unused stuff. 
Moved around some constants and definitions. Many style changes. Sorry, 
I know the two should be separated, but I had already done so many changes...


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@21695 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stefano Ceccherini
2007-07-24 12:18:24 +00:00
parent 40ba6c7004
commit abc4720231
9 changed files with 380 additions and 387 deletions
+16 -27
View File
@@ -1,4 +1,5 @@
/*
* Copyright 2007 Haiku
* Copyright (c) 2003-4 Kian Duffy <[email protected]>
* Parts Copyright (C) 1998,99 Kazuho Okui and Takashi Murai.
*
@@ -28,35 +29,23 @@
*
*/
#include <Box.h>
#include <Button.h>
#include <RadioButton.h>
#include <ColorControl.h>
#include <StringView.h>
#include <TextControl.h>
#include <CheckBox.h>
#include <MenuField.h>
#include <Message.h>
#include <String.h>
#include <Window.h>
#include "PrefView.h"
#include "PrefHandler.h"
#include "TermConst.h"
#include "PrefView.h"
#include "TTextControl.h"
/************************************************************************
*
* PUBLIC MEMBER FUNCTIONS.
*
***********************************************************************/
#include <ColorControl.h>
#include <Message.h>
#include <String.h>
////////////////////////////////////////////////////////////////////////////
// PrefView ()
// Constructor.
////////////////////////////////////////////////////////////////////////////
PrefView::PrefView (BRect frame, const char *name)
:BView (frame, name, B_FOLLOW_ALL_SIDES, B_WILL_DRAW)
PrefView::PrefView(BRect frame, const char *name)
:BView(frame, name, B_FOLLOW_ALL_SIDES, B_WILL_DRAW)
{
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
fLabel.SetTo(name);
@@ -73,18 +62,18 @@ PrefView::~PrefView()
const char *
PrefView::ViewLabel (void) const
PrefView::ViewLabel() const
{
return fLabel.String();
return fLabel.String();
}
////////////////////////////////////////////////////////////////////////////
// CanApply()
// Determines whether view can respont Apply command or not.
// Determines whether view can reply to Apply command or not.
////////////////////////////////////////////////////////////////////////////
bool
PrefView::CanApply ()
PrefView::CanApply()
{
return true;
}
@@ -115,10 +104,10 @@ PrefView::MessageReceived(BMessage* msg)
// Make BColorControl.
//////////////////////////////////////////////////////////////////////////////
BColorControl *
PrefView::SetupBColorControl(BPoint p, color_control_layout layout, float cell_size, ulong msg)
PrefView::SetupBColorControl(BPoint point, color_control_layout layout, float cellSize, ulong message)
{
BColorControl *col = new BColorControl( p, layout, cell_size, "", new BMessage(msg));
AddChild(col);
return col;
BColorControl *control = new BColorControl(point, layout, cellSize, "", new BMessage(message));
AddChild(control);
return control;
}
+10 -11
View File
@@ -107,12 +107,10 @@ typedef struct
#define PTY_WS 2 /* pty need WINSIZE (row and col ) */
static pid_t sShPid;
Shell::Shell()
:
fFd(-1),
fProcessID(-1),
fTermParse(NULL),
fAttached(false)
{
@@ -152,7 +150,8 @@ Shell::Close()
if (fFd >= 0) {
close(fFd);
kill(-sShPid, SIGHUP);
kill(-fProcessID, SIGHUP);
fProcessID = -1;
int status;
wait(&status);
fFd = -1;
@@ -187,21 +186,21 @@ Shell::Write(const void *buffer, size_t numBytes)
}
void
status_t
Shell::UpdateWindowSize(int rows, int columns)
{
struct winsize winSize;
winSize.ws_row = rows;
winSize.ws_col = columns;
ioctl(fFd, TIOCSWINSZ, &winSize);
Signal(SIGWINCH);
return Signal(SIGWINCH);
}
void
status_t
Shell::Signal(int signal)
{
kill(-sShPid, signal);
return send_signal(-fProcessID, signal);
}
@@ -316,7 +315,7 @@ Shell::_Spawn(int row, int col, const char *command, const char *coding)
thread_id terminalThread = find_thread(NULL);
/* Fork a child process. */
if ((sShPid = fork()) < 0) {
if ((fProcessID = fork()) < 0) {
close(master);
return B_ERROR;
}
@@ -324,7 +323,7 @@ Shell::_Spawn(int row, int col, const char *command, const char *coding)
handshake_t handshake;
if (sShPid == 0) {
if (fProcessID == 0) {
// Now in child process.
/*
@@ -583,7 +582,7 @@ Shell::_Spawn(int row, int col, const char *command, const char *coding)
handshake.row = row;
handshake.col = col;
handshake.status = PTY_WS;
send_handshake_message(sShPid, handshake);
send_handshake_message(fProcessID, handshake);
break;
}
}
+3 -2
View File
@@ -97,8 +97,8 @@ public:
ssize_t Read(void *buffer, size_t numBytes);
ssize_t Write(const void *buffer, size_t numBytes);
void UpdateWindowSize(int row, int columns);
void Signal(int signal);
status_t UpdateWindowSize(int row, int columns);
status_t Signal(int signal);
status_t GetAttr(struct termios &attr);
status_t SetAttr(struct termios &attr);
@@ -110,6 +110,7 @@ public:
private:
int fFd;
pid_t fProcessID;
TermParse *fTermParse;
bool fAttached;
+3 -12
View File
@@ -40,6 +40,9 @@
// Message constants for menu items
#include <SupportDefs.h>
// Menu Message
const uint32 MENU_SWITCH_TERM = 'MSWT';
const uint32 MENU_NEW_TERM = 'MNTE';
@@ -59,7 +62,6 @@ const uint32 MENU_SHOW_COLOR = 'Mcol';
const uint32 M_GET_DEVICE_NUM = 'Mgdn';
// Message Runner
const uint32 MSGRUN_CURSOR = 'Rcur';
const uint32 MSGRUN_WINDOW = 'Rwin';
// Preference Message
@@ -144,14 +146,6 @@ enum{
#define MODE_OVER 0
#define MODE_INSERT 1
const float VIEW_OFFSET = 3;
#define CURSOR_RECT \
BRect r (fFontWidth * fCurPos.x, \
fFontHeight * fCurPos.y + fTop, \
fFontWidth * (fCurPos.x + 1) - 1, \
fFontHeight * fCurPos.y + fTop + fCursorHeight - 1)
// Define TermBuffer internal code
#define NO_CHAR 0x00
#define A_CHAR 0x01
@@ -186,8 +180,5 @@ const float VIEW_OFFSET = 3;
#define FORECOLORED(x) ((x) << 3)
#define BACKCOLORED(x) ((x) << 0)
// TypeDefs
typedef unsigned short ushort;
#endif // TERMCONST_H_INCLUDED
+78 -66
View File
@@ -4,6 +4,13 @@
* Parts Copyright (C) 1998,99 Kazuho Okui and Takashi Murai.
* Distributed under the terms of the MIT license.
*/
#include "TermParse.h"
#include "CodeConv.h"
#include "TermConst.h"
#include "TermView.h"
#include "VTparse.h"
#include <ctype.h>
#include <errno.h>
#include <stdio.h>
@@ -13,13 +20,7 @@
#include <Application.h>
#include <Beep.h>
#include <Message.h>
#include <MessageRunner.h>
#include "TermParse.h"
#include "TermView.h"
#include "VTparse.h"
#include "TermConst.h"
#include "CodeConv.h"
//////////////////////////////////////////////////////////////////////////////
// EscParse ... Escape sequence parse and character encoding.
@@ -50,16 +51,14 @@ extern int mbcstable[]; /* ESC $ */
TermParse::TermParse(int fd)
:
fFd(fd),
fViewObj(NULL),
fParseThread(-1),
fParseSem(-1),
fReaderThread(-1),
fReaderSem(-1),
fReaderLocker(-1),
fCursorUpdate(NULL),
fParser_p(0),
fBufferPosition(0),
fLockFlag(0),
fQuitting(false)
fView(NULL),
fQuitting(true)
{
}
@@ -73,16 +72,27 @@ TermParse::~TermParse()
status_t
TermParse::StartThreads(TermView *view)
{
fViewObj = view;
if (fView != NULL)
return B_ERROR;
fQuitting = false;
fView = view;
status_t status = InitPtyReader();
if (status < B_OK)
if (status < B_OK) {
fView = NULL;
return status;
}
status = InitTermParse();
if (status < B_OK) {
//AbortPtyReader();
delete_sem(fReaderSem);
delete_sem(fReaderLocker);
fQuitting = true;
status_t dummy;
wait_for_thread(fReaderThread, &dummy);
fView = NULL;
return status;
}
@@ -93,19 +103,26 @@ TermParse::StartThreads(TermView *view)
status_t
TermParse::StopThreads()
{
if (fView == NULL)
return B_ERROR;
fQuitting = true;
delete_sem(fReaderSem);
fReaderSem = -1;
delete_sem(fReaderLocker);
fReaderSem = -1;
//suspend_thread(fReaderThread);
// TODO: interrupt read() - doesn't work for whatever reason
status_t dummy;
wait_for_thread(fReaderThread, &dummy);
wait_for_thread(fReaderThread, &dummy);
fReaderThread = -1;
wait_for_thread(fParseThread, &dummy);
fViewObj = NULL;
fReaderThread = -1;
fView = NULL;
return B_OK;
}
@@ -118,7 +135,7 @@ TermParse::PtyReader()
uint read_p = 0;
while (!fQuitting) {
// If Pty Buffer nearly full, snooze this thread, and continue.
if ((read_p - fParser_p) > READ_BUF_SIZE - 16) {
if ((read_p - fBufferPosition) > READ_BUF_SIZE - 16) {
fLockFlag = READ_BUF_SIZE / 2;
status_t status;
do {
@@ -130,7 +147,7 @@ TermParse::PtyReader()
// Read PTY
uchar buf[READ_BUF_SIZE];
int nread = read(fFd, buf, READ_BUF_SIZE - (read_p - fParser_p));
int nread = read(fFd, buf, READ_BUF_SIZE - (read_p - fBufferPosition));
if (nread <= 0) {
be_app->PostMessage(B_QUIT_REQUESTED);
exit_thread(B_ERROR);
@@ -142,10 +159,10 @@ TermParse::PtyReader()
int mod = read_p % READ_BUF_SIZE;
if (nread >= left) {
memcpy(fReadBuf + mod, buf, left);
memcpy(fReadBuf, buf + left, nread - left);
memcpy(fReadBuffer + mod, buf, left);
memcpy(fReadBuffer, buf + left, nread - left);
} else
memcpy(fReadBuf + mod, buf, nread);
memcpy(fReadBuffer + mod, buf, nread);
read_p += nread;
@@ -168,12 +185,11 @@ TermParse::GetReaderBuf(uchar &c)
} while (status == B_INTERRUPTED);
if (status == B_TIMED_OUT) {
fViewObj->ScrollAtCursor();
fViewObj->UpdateLine();
fView->ScrollAtCursor();
fView->UpdateLine();
// Reset cursor blinking time and turn on cursor blinking.
fCursorUpdate->SetInterval (1000000);
fViewObj->SetCurDraw (CURON);
fView->SetCurDraw(CURON);
// wait new input from pty.
do {
@@ -186,15 +202,15 @@ TermParse::GetReaderBuf(uchar &c)
} else
return status;
c = fReadBuf[fParser_p % READ_BUF_SIZE];
fParser_p++;
c = fReadBuffer[fBufferPosition % READ_BUF_SIZE];
fBufferPosition++;
// If PtyReader thread locked, decrement counter and unlock thread.
if (fLockFlag != 0) {
if (--fLockFlag == 0)
release_sem(fReaderLocker);
}
fViewObj->SetCurDraw(CUROFF);
fView->SetCurDraw(CUROFF);
return B_OK;
}
@@ -206,10 +222,6 @@ TermParse::InitTermParse()
if (fParseThread >= 0)
return B_ERROR; // we might want to return B_OK instead ?
BMessage cursor(MSGRUN_CURSOR);
fCursorUpdate = new BMessageRunner(BMessenger(fViewObj),
&cursor, 1000000);
fParseThread = spawn_thread(_escparse_thread, "EscParse",
B_DISPLAY_PRIORITY, this);
@@ -314,7 +326,7 @@ TermParse::EscParse()
cbuf[0] = c;
cbuf[1] = '\0';
width = HALF_WIDTH;
fViewObj->PutChar(cbuf, attr, width);
fView->PutChar(cbuf, attr, width);
break;
case CASE_PRINT_GR:
@@ -359,7 +371,7 @@ TermParse::EscParse()
else
CodeConv::ConvertToInternal((char*)cbuf, -1, (char*)dstbuf, M_EUC_JP);
fViewObj->PutChar(dstbuf, attr, width);
fView->PutChar(dstbuf, attr, width);
break;
case CASE_PRINT_CS96:
@@ -369,15 +381,15 @@ TermParse::EscParse()
cbuf[2] = 0;
width = 2;
CodeConv::ConvertToInternal((char*)cbuf, 2, (char*)dstbuf, M_EUC_JP);
fViewObj->PutChar(dstbuf, attr, width);
fView->PutChar(dstbuf, attr, width);
break;
case CASE_LF:
fViewObj->PutLF();
fView->PutLF();
break;
case CASE_CR:
fViewObj->PutCR();
fView->PutCR();
break;
case CASE_SJIS_KANA:
@@ -385,7 +397,7 @@ TermParse::EscParse()
cbuf[1] = '\0';
CodeConv::ConvertToInternal((char*)cbuf, 1, (char*)dstbuf, now_coding);
width = 1;
fViewObj->PutChar(dstbuf, attr, width);
fView->PutChar(dstbuf, attr, width);
break;
case CASE_SJIS_INSTRING:
@@ -394,7 +406,7 @@ TermParse::EscParse()
cbuf[2] = '\0';
CodeConv::ConvertToInternal((char*)cbuf, 2, (char*)dstbuf, now_coding);
width = 2;
fViewObj->PutChar(dstbuf, attr, width);
fView->PutChar(dstbuf, attr, width);
break;
case CASE_UTF8_2BYTE:
@@ -405,7 +417,7 @@ TermParse::EscParse()
cbuf[1] = (uchar)c;
cbuf[2] = '\0';
width = CodeConv::UTF8GetFontWidth((char*)cbuf);
fViewObj->PutChar(cbuf, attr, width);
fView->PutChar(cbuf, attr, width);
break;
case CASE_UTF8_3BYTE:
@@ -421,7 +433,7 @@ TermParse::EscParse()
cbuf[2] = c;
cbuf[3] = '\0';
width = CodeConv::UTF8GetFontWidth((char*)cbuf);
fViewObj->PutChar (cbuf, attr, width);
fView->PutChar (cbuf, attr, width);
break;
case CASE_MBCS:
@@ -453,13 +465,13 @@ TermParse::EscParse()
break;
case CASE_BS:
fViewObj->MoveCurLeft(1);
fView->MoveCurLeft(1);
break;
case CASE_TAB:
tmp = fViewObj->GetCurX();
tmp = fView->GetCurX();
tmp %= 8;
fViewObj->MoveCurRight(8 - tmp);
fView->MoveCurRight(8 - tmp);
break;
case CASE_ESC:
@@ -519,7 +531,7 @@ TermParse::EscParse()
/* ICH */
if ((row = param[0]) < 1)
row = 1;
fViewObj->InsertSpace(row);
fView->InsertSpace(row);
parsestate = groundtable;
break;
@@ -527,7 +539,7 @@ TermParse::EscParse()
/* CUU */
if ((row = param[0]) < 1)
row = 1;
fViewObj->MoveCurUp(row);
fView->MoveCurUp(row);
parsestate = groundtable;
break;
@@ -535,7 +547,7 @@ TermParse::EscParse()
/* CUD */
if ((row = param[0]) < 1)
row = 1;
fViewObj->MoveCurDown(row);
fView->MoveCurDown(row);
parsestate = groundtable;
break;
@@ -543,7 +555,7 @@ TermParse::EscParse()
/* CUF */
if ((row = param[0]) < 1)
row = 1;
fViewObj->MoveCurRight(row);
fView->MoveCurRight(row);
parsestate = groundtable;
break;
@@ -551,7 +563,7 @@ TermParse::EscParse()
/* CUB */
if ((row = param[0]) < 1)
row = 1;
fViewObj->MoveCurLeft(row);
fView->MoveCurLeft(row);
parsestate = groundtable;
break;
@@ -562,7 +574,7 @@ TermParse::EscParse()
if (nparam < 2 || (col = param[1]) < 1)
col = 1;
fViewObj->SetCurPos(col - 1, row - 1 );
fView->SetCurPos(col - 1, row - 1 );
parsestate = groundtable;
break;
@@ -571,15 +583,15 @@ TermParse::EscParse()
switch (param[0]) {
case DEFAULT:
case 0:
fViewObj->EraseBelow();
fView->EraseBelow();
break;
case 1:
break;
case 2:
fViewObj->SetCurPos(0, 0);
fViewObj->EraseBelow();
fView->SetCurPos(0, 0);
fView->EraseBelow();
break;
}
parsestate = groundtable;
@@ -587,7 +599,7 @@ TermParse::EscParse()
case CASE_EL: // delete line
/* EL */
fViewObj->DeleteColumns();
fView->DeleteColumns();
parsestate = groundtable;
break;
@@ -595,7 +607,7 @@ TermParse::EscParse()
/* IL */
if ((row = param[0]) < 1)
row = 1;
fViewObj->PutNL(row);
fView->PutNL(row);
parsestate = groundtable;
break;
@@ -603,7 +615,7 @@ TermParse::EscParse()
/* DL */
if ((row = param[0]) < 1)
row = 1;
fViewObj->DeleteLine(row);
fView->DeleteLine(row);
parsestate = groundtable;
break;
@@ -611,19 +623,19 @@ TermParse::EscParse()
/* DCH */
if ((row = param[0]) < 1)
row = 1;
fViewObj->DeleteChar(row);
fView->DeleteChar(row);
parsestate = groundtable;
break;
case CASE_SET:
/* SET */
fViewObj->SetInsertMode(MODE_INSERT);
fView->SetInsertMode(MODE_INSERT);
parsestate = groundtable;
break;
case CASE_RST:
/* RST */
fViewObj->SetInsertMode(MODE_OVER);
fView->SetInsertMode(MODE_OVER);
parsestate = groundtable;
break;
@@ -690,7 +702,7 @@ TermParse::EscParse()
case CASE_CPR:
// Q & D hack by Y.Hayakawa ([email protected])
// 21-JUL-99
fViewObj->DeviceStatusReport(param[0]);
fView->DeviceStatusReport(param[0]);
parsestate = groundtable;
break;
@@ -709,7 +721,7 @@ TermParse::EscParse()
bot--;
if (bot > top)
fViewObj->SetScrollRegion(top, bot);
fView->SetScrollRegion(top, bot);
parsestate = groundtable;
break;
@@ -746,13 +758,13 @@ TermParse::EscParse()
case CASE_DECSC:
/* DECSC */
fViewObj->SaveCursor();
fView->SaveCursor();
parsestate = groundtable;
break;
case CASE_DECRC:
/* DECRC */
fViewObj->RestoreCursor();
fView->RestoreCursor();
parsestate = groundtable;
break;
@@ -764,7 +776,7 @@ TermParse::EscParse()
case CASE_RI:
/* RI */
fViewObj->ScrollRegion(-1, -1, SCRDOWN, 1);
fView->ScrollRegion(-1, -1, SCRDOWN, 1);
parsestate = groundtable;
break;
@@ -814,7 +826,7 @@ TermParse::EscParse()
switch (mode_char) {
case '0':
case '2':
fViewObj->Window()->SetTitle(string);
fView->Window()->SetTitle(string);
break;
case '1':
break;
+8 -16
View File
@@ -33,9 +33,9 @@
#include "TermConst.h"
#include <OS.h>
#include <Handler.h>
#include <MessageRunner.h>
#include <OS.h>
//PtyReader buffer size.
#define READ_BUF_SIZE 2048
@@ -54,10 +54,6 @@ private:
status_t InitTermParse();
status_t InitPtyReader();
// Delete TermParse and PtyReader thread.
status_t AbortTermParse();
status_t AbortPtyReader();
int32 EscParse();
int32 PtyReader();
@@ -69,23 +65,19 @@ private:
int fFd;
TermView *fViewObj;
thread_id fParseThread;
sem_id fParseSem;
thread_id fReaderThread;
sem_id fReaderSem;
sem_id fReaderLocker;
BMessageRunner *fCursorUpdate;
uint fBufferPosition;
uchar fReadBuffer[READ_BUF_SIZE];
int fLockFlag;
uint fParser_p; /* EscParse reading buffer pointer */
int fLockFlag; /* PtyReader lock flag */
bool fQuitting;
TermView *fView;
uchar fReadBuf[READ_BUF_SIZE]; /* Reading buffer */
bool fQuitting;
};
#endif // TERMPARSE_H
+74 -20
View File
@@ -12,17 +12,17 @@
#include "TermView.h"
#include "TermWindow.h"
#include "TermApp.h"
#include "TermParse.h"
#include "TermBuffer.h"
#include "CodeConv.h"
#include "VTkeymap.h"
#include "TermConst.h"
#include "PrefHandler.h"
#include "MenuUtil.h"
#include "PrefHandler.h"
#include "PrefView.h"
#include "Shell.h"
#include "TermApp.h"
#include "TermBuffer.h"
#include "TermConst.h"
#include "TermParse.h"
#include "TermWindow.h"
#include "VTkeymap.h"
#include <Autolock.h>
#include <Beep.h>
@@ -61,8 +61,54 @@ const static rgb_color kTermColorTable[16] = {
};
const unsigned char M_ADD_CURSOR[] = {
16, // Size
1, // Color depth
0, // Hot spot y
1, // Hot spot x
// Cursor image
0x70, 0x00,
0x48, 0x00,
0x48, 0x00,
0x27, 0xc0,
0x24, 0xb8,
0x12, 0x54,
0x10, 0x02,
0x78, 0x02,
0x98, 0x02,
0x84, 0x02,
0x60, 0x02,
0x18, 0x12,
0x04, 0x10,
0x02, 0x7c,
0x00, 0x10,
0x00, 0x10,
// Mask image
0x70, 0x00,
0x78, 0x00,
0x78, 0x00,
0x3f, 0xc0,
0x3f, 0xf8,
0x1f, 0xfc,
0x1f, 0xfe,
0x7f, 0xfe,
0xff, 0xfe,
0xff, 0xfe,
0x7f, 0xfe,
0x1f, 0xfe,
0x07, 0xfc,
0x03, 0xfc,
0x00, 0x10,
0x00, 0x10,
};
#define MOUSE_THR_CODE 'mtcd'
TermView::TermView(BRect frame, const char *command)
: BView(frame, "termview", B_FOLLOW_ALL, B_WILL_DRAW | B_FRAME_EVENTS),
: BView(frame, "termview", B_FOLLOW_ALL, B_WILL_DRAW | B_FRAME_EVENTS | B_PULSE_NEEDED),
fShell(NULL),
fFontWidth(0),
fFontHeight(0),
@@ -72,6 +118,7 @@ TermView::TermView(BRect frame, const char *command)
fScrollUpCount(0),
fScrollBarRange(0),
fFrameResized(false),
fLastCursorTime(0),
fCursorDrawFlag(CURON),
fCursorStatus(CURON),
fCursorBlinkingFlag(CURON),
@@ -379,9 +426,9 @@ TermView::TermDraw(const CurPos &start, const CurPos &end)
int x2 = end.x;
int y2 = end.y;
// Send Draw Rectangle data to Draw Engine thread.
Redraw(x1, y1 + fTop / fFontHeight,
x2, y2 + fTop / fFontHeight);
return 0;
}
@@ -442,8 +489,7 @@ TermView::TermDrawRegion(CurPos start, CurPos end)
Redraw(0, start.y + 1,
fTermColumns - 1, end.y - 1);
}
Redraw(0, end.y,
end.x, end.y);
Redraw(0, end.y, end.x, end.y);
}
return 0;
@@ -624,18 +670,18 @@ TermView::MoveCurDown(int num)
}
// TODO: Cleanup the next 3 functions!!!
void
TermView::DrawCursor()
{
CURSOR_RECT;
BRect rect(fFontWidth * fCurPos.x, fFontHeight * fCurPos.y + fTop,
fFontWidth * (fCurPos.x + 1) - 1, fFontHeight * fCurPos.y + fTop + fCursorHeight - 1);
uchar buf[4];
ushort attr;
int top = fTop / fFontHeight;
int m_flag = false;
m_flag = CheckSelectedRegion(CurPos(fCurPos.x,
fCurPos.y + fTop / fFontHeight));
bool m_flag = CheckSelectedRegion(CurPos(fCurPos.x, fCurPos.y + fTop / fFontHeight));
if (fTextBuffer->GetChar(fCurPos.y + top, fCurPos.x, buf, &attr) == A_CHAR) {
int width;
if (IS_WIDTH(attr))
@@ -652,7 +698,7 @@ TermView::DrawCursor()
else
SetHighColor(fCursorBackColor);
FillRect(r);
FillRect(rect);
}
Sync();
@@ -671,6 +717,7 @@ TermView::BlinkCursor()
DrawCursor();
fCursorStatus = fCursorStatus == CURON ? CUROFF : CURON;
fLastCursorTime = system_time();
}
}
@@ -1107,6 +1154,16 @@ TermView::AttachedToWindow()
SetFont(&fHalfFont);
MakeFocus(true);
fScrollBar->SetSteps(fFontHeight, fFontHeight * fTermRows);
Window()->SetPulseRate(1000000);
}
void
TermView::Pulse()
{
//if (system_time() > fLastCursorTime + 1000000)
BlinkCursor();
}
@@ -1470,9 +1527,6 @@ TermView::MessageReceived(BMessage *msg)
fShell->Write(ctrl_l, 1);
break;
case MSGRUN_CURSOR:
BlinkCursor();
break;
// case B_INPUT_METHOD_EVENT:
// {
+180 -228
View File
@@ -36,295 +36,247 @@
#include "TermConst.h"
#include "TermWindow.h"
#include <View.h>
#include <Messenger.h>
#include <String.h>
#include <MessageRunner.h>
#include <View.h>
/* Cursor Blinking flag */
#define CUROFF 0
#define CURON 1
#define MOUSE_THR_CODE 'mtcd'
#define RECT_BUF_SIZE 32
const unsigned char M_ADD_CURSOR [] = {
16, // Size
1, // Color depth
0, // Hot spot y
1, // Hot spot x
// Cursor image
0x70, 0x00,
0x48, 0x00,
0x48, 0x00,
0x27, 0xc0,
0x24, 0xb8,
0x12, 0x54,
0x10, 0x02,
0x78, 0x02,
0x98, 0x02,
0x84, 0x02,
0x60, 0x02,
0x18, 0x12,
0x04, 0x10,
0x02, 0x7c,
0x00, 0x10,
0x00, 0x10,
// Mask image
0x70, 0x00,
0x78, 0x00,
0x78, 0x00,
0x3f, 0xc0,
0x3f, 0xf8,
0x1f, 0xfc,
0x1f, 0xfe,
0x7f, 0xfe,
0xff, 0xfe,
0xff, 0xfe,
0x7f, 0xfe,
0x1f, 0xfe,
0x07, 0xfc,
0x03, 0xfc,
0x00, 0x10,
0x00, 0x10,
};
class BPopUpMenu;
class BScrollBar;
class BString;
class Shell;
class TermBuffer;
class TermView : public BView {
public:
TermView(BRect frame, const char *command);
~TermView();
public:
TermView(BRect frame, const char *command);
~TermView();
status_t AttachShell(Shell *shell);
void DetachShell();
status_t AttachShell(Shell *shell);
void DetachShell();
const char *TerminalName() const;
const char *TerminalName() const;
void SetTermFont(const BFont *halfFont, const BFont *fullFont);
void GetFontSize(int *width, int *height);
BRect SetTermSize(int rows, int cols, bool flag);
void SetTermColor();
void SetMouseCursor();
// void SetIMAware (bool);
void SetScrollBar(BScrollBar *scrbar);
BScrollBar *ScrollBar() const { return fScrollBar; };
// Output Charactor
void PutChar(uchar *string, ushort attr, int width);
void PutCR(void);
void PutLF(void);
void PutNL(int num);
void SetInsertMode(int flag);
void InsertSpace(int num);
int TermDraw(const CurPos &start, const CurPos &end);
int TermDrawRegion(CurPos start, CurPos end);
int TermDrawSelectedRegion(CurPos start, CurPos end);
void SetTermFont(const BFont *halfFont, const BFont *fullFont);
void GetFontSize(int *width, int *height);
BRect SetTermSize(int rows, int cols, bool flag);
void SetTermColor();
void SetMouseCursor();
// void SetIMAware (bool);
void SetScrollBar(BScrollBar *scrbar);
BScrollBar *ScrollBar() const { return fScrollBar; };
// Output Charactor
void PutChar(uchar *string, ushort attr, int width);
void PutCR(void);
void PutLF(void);
void PutNL(int num);
void SetInsertMode(int flag);
void InsertSpace(int num);
int TermDraw(const CurPos &start, const CurPos &end);
int TermDrawRegion(CurPos start, CurPos end);
int TermDrawSelectedRegion(CurPos start, CurPos end);
// Delete Charactor
void EraseBelow();
void DeleteChar(int num);
void DeleteColumns();
void DeleteLine(int num);
void EraseBelow();
void DeleteChar(int num);
void DeleteColumns();
void DeleteLine(int num);
// Get and Set Cursor position
void SetCurPos(int x, int y);
void SetCurX(int x);
void SetCurY(int y);
// Get and Set Cursor position
void SetCurPos(int x, int y);
void SetCurX(int x);
void SetCurY(int y);
void GetCurPos(CurPos *inCurPos);
int GetCurX();
int GetCurY();
void SaveCursor();
void RestoreCursor();
void GetCurPos(CurPos *inCurPos);
int GetCurX();
int GetCurY();
// Move Cursor
void MoveCurRight(int num);
void MoveCurLeft(int num);
void MoveCurUp(int num);
void MoveCurDown(int num);
void SaveCursor();
void RestoreCursor();
// Cursor setting
void DrawCursor();
void BlinkCursor();
void SetCurDraw(bool flag);
void SetCurBlinking(bool flag);
// Move Cursor
void MoveCurRight(int num);
void MoveCurLeft(int num);
void MoveCurUp(int num);
void MoveCurDown(int num);
// Scroll region
void ScrollRegion(int top, int bot, int dir, int num);
void SetScrollRegion(int top, int bot);
void ScrollAtCursor();
// Cursor setting
void DrawCursor();
void BlinkCursor();
void SetCurDraw(bool flag);
void SetCurBlinking(bool flag);
// Other
void UpdateSIGWINCH();
void DeviceStatusReport(int);
void UpdateLine();
void ScrollScreen();
void ScrollScreenDraw();
void GetFrameSize(float *width, float *height);
void GetFontInfo(int *, int*);
bool Find(const BString &str, bool forwardSearch, bool matchCase, bool matchWord);
void GetSelection(BString &str);
// Scroll region
void ScrollRegion(int top, int bot, int dir, int num);
void SetScrollRegion(int top, int bot);
void ScrollAtCursor();
protected:
virtual void AttachedToWindow();
virtual void Pulse();
virtual void Draw(BRect updateRect);
virtual void WindowActivated(bool active);
virtual void KeyDown(const char*, int32);
virtual void MouseDown(BPoint where);
virtual void MouseMoved(BPoint, uint32, const BMessage *);
// Other
void UpdateSIGWINCH();
void DeviceStatusReport(int);
void UpdateLine();
void ScrollScreen();
void ScrollScreenDraw();
void GetFrameSize(float *width, float *height);
void GetFontInfo(int *, int*);
bool Find(const BString &str, bool forwardSearch, bool matchCase, bool matchWord);
void GetSelection(BString &str);
virtual void FrameResized(float width, float height);
virtual void MessageReceived(BMessage* message);
protected:
virtual void AttachedToWindow(void);
virtual void Draw(BRect updateRect);
virtual void WindowActivated(bool active);
virtual void KeyDown(const char*, int32);
virtual void MouseDown(BPoint where);
virtual void MouseMoved(BPoint, uint32, const BMessage *);
private:
static int32 MouseTracking(void *);
virtual void FrameResized(float width, float height);
virtual void MessageReceived(BMessage* message);
status_t _InitMouseThread(void);
void DrawLines(int , int, ushort, uchar *, int, int, int, BView *);
void DoPrint(BRect updateRect);
void ResizeScrBarRange (void);
void DoFileDrop(entry_ref &ref);
private:
static int32 MouseTracking(void *);
// edit menu function.
void DoCopy();
void DoPaste();
void DoSelectAll();
void DoClearAll();
status_t _InitMouseThread(void);
void DrawLines(int , int, ushort, uchar *, int, int, int, BView *);
void DoPrint(BRect updateRect);
void ResizeScrBarRange (void);
void DoFileDrop(entry_ref &ref);
void WritePTY (const uchar *text, int num_byteses);
// edit menu function.
void DoCopy();
void DoPaste();
void DoSelectAll();
void DoClearAll();
// Comunicate Input Method
// void DoIMStart (BMessage* message);
// void DoIMStop (BMessage* message);
// void DoIMChange (BMessage* message);
// void DoIMLocation (BMessage* message);
// void DoIMConfirm (void);
void ConfirmString (const char *, int32);
int32 GetCharFromUTF8String (const char *, char *);
int32 GetWidthFromUTF8String (const char *);
void WritePTY (const uchar *text, int num_byteses);
// Mouse select
void Select(CurPos start, CurPos end);
void AddSelectRegion(CurPos);
void ResizeSelectRegion(CurPos);
// Comunicate Input Method
// void DoIMStart (BMessage* message);
// void DoIMStop (BMessage* message);
// void DoIMChange (BMessage* message);
// void DoIMLocation (BMessage* message);
// void DoIMConfirm (void);
void ConfirmString (const char *, int32);
int32 GetCharFromUTF8String (const char *, char *);
int32 GetWidthFromUTF8String (const char *);
void DeSelect();
bool HasSelection() const;
// Mouse select
void Select(CurPos start, CurPos end);
void AddSelectRegion(CurPos);
void ResizeSelectRegion(CurPos);
// select word function
void SelectWord(BPoint where, int mod);
void SelectLine(BPoint where, int mod);
void DeSelect();
bool HasSelection() const;
// point and text offset conversion.
CurPos BPointToCurPos(const BPoint &p);
BPoint CurPosToBPoint(const CurPos &pos);
// select word function
void SelectWord(BPoint where, int mod);
void SelectLine(BPoint where, int mod);
bool CheckSelectedRegion(const CurPos &pos);
inline void Redraw(int, int, int, int);
// point and text offset conversion.
CurPos BPointToCurPos(const BPoint &p);
BPoint CurPosToBPoint(const CurPos &pos);
Shell *fShell;
bool CheckSelectedRegion(const CurPos &pos);
inline void Redraw(int, int, int, int);
// Font and Width
BFont fHalfFont;
BFont fFullFont;
int fFontWidth;
int fFontHeight;
int fFontAscent;
struct escapement_delta fEscapement;
Shell *fShell;
// Flags
// Font and Width
BFont fHalfFont;
BFont fFullFont;
int fFontWidth;
int fFontHeight;
int fFontAscent;
struct escapement_delta fEscapement;
// Update flag (Set on PutChar).
bool fUpdateFlag;
// Flags
// Terminal insertmode flag (use PutChar).
bool fInsertModeFlag;
// Update flag (Set on PutChar).
bool fUpdateFlag;
// Scroll count, range.
int fScrollUpCount;
int fScrollBarRange;
// Terminal insertmode flag (use PutChar).
bool fInsertModeFlag;
// Frame Resized flag.
bool fFrameResized;
// Scroll count, range.
int fScrollUpCount;
int fScrollBarRange;
// Cursor Blinking, draw flag.
bigtime_t fLastCursorTime;
bool fCursorDrawFlag;
bool fCursorStatus;
bool fCursorBlinkingFlag;
bool fCursorRedrawFlag;
// Frame Resized flag.
bool fFrameResized;
int fCursorHeight;
// Cursor Blinking, draw flag.
bool fCursorDrawFlag;
bool fCursorStatus;
bool fCursorBlinkingFlag;
bool fCursorRedrawFlag;
// terminal text attribute flag.
bool fInverseFlag;
bool fBoldFlag;
bool fUnderlineFlag;
int fCursorHeight;
// Cursor position.
CurPos fCurPos;
CurPos fCurStack;
// terminal text attribute flag.
bool fInverseFlag;
bool fBoldFlag;
bool fUnderlineFlag;
int fBufferStartPos;
// Cursor position.
CurPos fCurPos;
CurPos fCurStack;
// Terminal rows and columns.
int fTermRows;
int fTermColumns;
int fBufferStartPos;
// Terminal view pointer.
int fTop;
// Terminal rows and columns.
int fTermRows;
int fTermColumns;
// Object pointer.
// Terminal view pointer.
int fTop;
TermBuffer *fTextBuffer;
BScrollBar *fScrollBar;
// Object pointer.
// Offscreen Bitmap and View.
TermBuffer *fTextBuffer;
BScrollBar *fScrollBar;
BRect fSrcRect;
BRect fDstRect;
// Offscreen Bitmap and View.
// Color and Attribute.
BRect fSrcRect;
BRect fDstRect;
rgb_color fTextForeColor, fTextBackColor;
rgb_color fCursorForeColor, fCursorBackColor;
rgb_color fSelectForeColor, fSelectBackColor;
uchar fTermAttr;
// Color and Attribute.
// Scroll Region
int fScrTop;
int fScrBot;
int fScrBufSize;
bool fScrRegionSet;
rgb_color fTextForeColor, fTextBackColor;
rgb_color fCursorForeColor, fCursorBackColor;
rgb_color fSelectForeColor, fSelectBackColor;
uchar fTermAttr;
bool fMouseImage;
// Scroll Region
int fScrTop;
int fScrBot;
int fScrBufSize;
bool fScrRegionSet;
BPoint fPreviousMousePoint;
bool fMouseImage;
// view selection
CurPos fSelStart;
CurPos fSelEnd;
bool fMouseTracking;
BPoint fPreviousMousePoint;
// thread ID / flags.
thread_id fMouseThread;
bool fQuitting;
// view selection
CurPos fSelStart;
CurPos fSelEnd;
bool fMouseTracking;
// Input Method parameter.
int fIMViewPtr;
CurPos fIMStartPos;
CurPos fIMEndPos;
BString fIMString;
bool fIMflag;
BMessenger fIMMessenger;
// thread ID / flags.
thread_id fMouseThread;
bool fQuitting;
// Input Method parameter.
int fIMViewPtr;
CurPos fIMStartPos;
CurPos fIMEndPos;
BString fIMString;
bool fIMflag;
BMessenger fIMMessenger;
int32 fImCodeState;
int32 fImCodeState;
};
+8 -5
View File
@@ -50,6 +50,9 @@
//#define CHLP_FILE "file:///boot/beos/documentation/Shell%20Tools/index.html"
const static float kViewOffset = 3;
TermWindow::TermWindow(BRect frame, const char* title, const char *command)
: BWindow(frame, title, B_DOCUMENT_WINDOW, B_CURRENT_WORKSPACE|B_QUIT_ON_WINDOW_CLOSE),
fMenubar(NULL),
@@ -147,7 +150,7 @@ TermWindow::_InitWindow(const char *command)
fTermView->SetTermColor();
// Add offset to baseview.
rect.InsetBy(-VIEW_OFFSET, -VIEW_OFFSET);
rect.InsetBy(-kViewOffset, -kViewOffset);
// Resize Window
ResizeTo(rect.Width()+ B_V_SCROLL_BAR_WIDTH,
@@ -425,8 +428,8 @@ TermWindow::MessageReceived(BMessage *message)
r = fTermView->SetTermSize (PrefHandler::Default()->getInt32 (PREF_ROWS),
PrefHandler::Default()->getInt32 (PREF_COLS), 0);
ResizeTo (r.Width()+ B_V_SCROLL_BAR_WIDTH + VIEW_OFFSET * 2,
r.Height()+fMenubar->Bounds().Height() + VIEW_OFFSET *2);
ResizeTo (r.Width()+ B_V_SCROLL_BAR_WIDTH + kViewOffset * 2,
r.Height()+fMenubar->Bounds().Height() + kViewOffset *2);
BPath path;
if (PrefHandler::GetDefaultPath(path) == B_OK)
@@ -456,8 +459,8 @@ TermWindow::MessageReceived(BMessage *message)
SetSizeLimits (MIN_COLS * width, MAX_COLS * width,
MIN_COLS * height, MAX_COLS * height);
ResizeTo (r.Width()+ B_V_SCROLL_BAR_WIDTH + VIEW_OFFSET * 2,
r.Height()+fMenubar->Bounds().Height() + VIEW_OFFSET * 2);
ResizeTo (r.Width()+ B_V_SCROLL_BAR_WIDTH + kViewOffset * 2,
r.Height()+fMenubar->Bounds().Height() + kViewOffset * 2);
fTermView->Invalidate();
break;