Opening the preferences window and hitting "cancel" would shrink the

window every time, without reason, since _Revert() was called even if no 
changes were made.
Build the list of window sizes dynamically, this way we get rid of some 
code duplication.
Removed implementation of TermWindow::QuitRequested(). The 
B_QUIT_ON_WINDOW close takes care of quitting the application.
Some cleanups.



git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@23860 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stefano Ceccherini 2008-02-04 09:43:16 +00:00
parent 7bf8652984
commit 56e415dda1
8 changed files with 110 additions and 120 deletions

View File

@ -26,7 +26,7 @@ PrefWindow::PrefWindow(BMessenger messenger)
: BWindow(_CenteredRect(BRect(0, 0, 350, 215)), "Terminal Settings",
B_TITLED_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
B_NOT_RESIZABLE|B_NOT_ZOOMABLE),
fPrefTemp(new PrefHandler(PrefHandler::Default())),
fPreviousPref(new PrefHandler(PrefHandler::Default())),
fSavePanel(NULL),
fDirty(false),
fPrefDlgMessenger(messenger)
@ -37,8 +37,8 @@ PrefWindow::PrefWindow(BMessenger messenger)
BRect rect = top->Bounds();
rect.bottom *= .75;
AppearancePrefView *prefView= new AppearancePrefView(rect, "Appearance",
fPrefDlgMessenger);
AppearancePrefView *prefView
= new AppearancePrefView(rect, "Appearance", fPrefDlgMessenger);
top->AddChild(prefView);
fSaveAsFileButton = new BButton(BRect(0, 0, 1, 1), "savebutton", "Save to File" B_UTF8_ELLIPSIS,
@ -80,7 +80,7 @@ void
PrefWindow::Quit()
{
fPrefDlgMessenger.SendMessage(MSG_PREF_CLOSED);
delete fPrefTemp;
delete fPreviousPref;
delete fSavePanel;
BWindow::Quit();
}
@ -140,8 +140,8 @@ PrefWindow::_SaveRequested(BMessage *msg)
void
PrefWindow::_Save()
{
delete fPrefTemp;
fPrefTemp = new PrefHandler(PrefHandler::Default());
delete fPreviousPref;
fPreviousPref = new PrefHandler(PrefHandler::Default());
BPath path;
if (PrefHandler::GetDefaultPath(path) == B_OK) {
@ -154,13 +154,15 @@ PrefWindow::_Save()
void
PrefWindow::_Revert()
{
PrefHandler::SetDefault(new PrefHandler(fPrefTemp));
if (fDirty) {
PrefHandler::SetDefault(new PrefHandler(fPreviousPref));
fPrefDlgMessenger.SendMessage(MSG_HALF_FONT_CHANGED);
fPrefDlgMessenger.SendMessage(MSG_COLOR_CHANGED);
fPrefDlgMessenger.SendMessage(MSG_INPUT_METHOD_CHANGED);
fDirty = false;
}
}

View File

@ -46,7 +46,7 @@ class PrefWindow : public BWindow
BRect _CenteredRect(BRect rect);
private:
PrefHandler *fPrefTemp;
PrefHandler *fPreviousPref;
BFilePanel *fSavePanel;
BButton *fSaveAsFileButton,

View File

@ -144,6 +144,7 @@ void
Shell::Close()
{
delete fTermParse;
fTermParse = NULL;
if (fFd >= 0) {
close(fFd);

View File

@ -106,7 +106,8 @@ SmartTabView::Select(int32 index)
BTabView::Select(index);
BView *view = ViewForTab(index);
if (view != NULL) {
view->ResizeTo(ContainerView()->Bounds().Width(), ContainerView()->Bounds().Height());
view->ResizeTo(ContainerView()->Bounds().Width(),
ContainerView()->Bounds().Height());
}
}
@ -121,8 +122,7 @@ SmartTabView::RemoveAndDeleteTab(int32 index)
else if (index < CountTabs())
Select(index + 1);
}
BTab *tab = RemoveTab(index);
delete tab;
delete RemoveTab(index);
}
@ -132,11 +132,20 @@ SmartTabView::AddTab(BView *target, BTab *tab)
if (target == NULL)
return;
BTabView::AddTab(target, tab);
if (CountTabs() == 1) {
// Call select on the tab, since
// we're resizing the contained view
// inside that function
Select(0);
} else if (CountTabs() == 2) {
// Need to resize the view, since we're
// switching from "normal" to tabbed mode
ContainerView()->ResizeBy(0, -TabHeight());
ContainerView()->MoveBy(0, TabHeight());
Window()->ResizeBy(0, TabHeight());
}
BTabView::AddTab(target, tab);
Invalidate(TabFrame(CountTabs() - 1).InsetByCopy(-2, -2));
}
@ -145,12 +154,13 @@ SmartTabView::AddTab(BView *target, BTab *tab)
BTab *
SmartTabView::RemoveTab(int32 index)
{
BTab *tab = BTabView::RemoveTab(index);
if (CountTabs() == 1) {
if (CountTabs() == 2) {
// see above
Window()->ResizeBy(0, -TabHeight());
ContainerView()->MoveBy(0, -TabHeight());
ContainerView()->ResizeBy(0, TabHeight());
}
return tab;
return BTabView::RemoveTab(index);
}
@ -175,5 +185,3 @@ SmartTabView::_ClickedTabIndex(const BPoint &point)
return -1;
}

View File

@ -1081,19 +1081,17 @@ void
TermView::_DrawLines(int x1, int y1, ushort attr, uchar *buf,
int width, int mouse, int cursor, BView *inView)
{
int x2, y2;
int forecolor, backcolor;
rgb_color rgb_fore = fTextForeColor, rgb_back = fTextBackColor, rgb_tmp;
rgb_color rgb_fore = fTextForeColor, rgb_back = fTextBackColor;
inView->SetFont(&fHalfFont);
// Set pen point
x2 = x1 + fFontWidth * width;
y2 = y1 + fFontHeight;
int x2 = x1 + fFontWidth * width;
int y2 = y1 + fFontHeight;
// color attribute
forecolor = IS_FORECOLOR(attr);
backcolor = IS_BACKCOLOR(attr);
int forecolor = IS_FORECOLOR(attr);
int backcolor = IS_BACKCOLOR(attr);
if (IS_FORESET(attr))
rgb_fore = kTermColorTable[forecolor];
@ -1105,13 +1103,13 @@ TermView::_DrawLines(int x1, int y1, ushort attr, uchar *buf,
if (cursor) {
rgb_fore = fCursorForeColor;
rgb_back = fCursorBackColor;
} else if (mouse){
} else if (mouse) {
rgb_fore = fSelectForeColor;
rgb_back = fSelectBackColor;
} else {
// Reverse attribute(If selected area, don't reverse color).
if (IS_INVERSE(attr)) {
rgb_tmp = rgb_fore;
rgb_color rgb_tmp = rgb_fore;
rgb_fore = rgb_back;
rgb_back = rgb_tmp;
}
@ -1154,7 +1152,7 @@ TermView::_ResizeScrBarRange()
return;
float viewheight = fTermRows * fFontHeight;
float start_pos = fTop -(fScrBufSize - fTermRows *2) * fFontHeight;
float start_pos = fTop -(fScrBufSize - fTermRows * 2) * fFontHeight;
if (start_pos > 0) {
fScrollBar->SetRange(start_pos, viewheight + fTop - fFontHeight);
@ -1263,7 +1261,6 @@ TermView::UpdateLine()
void
TermView::AttachedToWindow()
{
SetFont(&fHalfFont);
MakeFocus(true);
if (fScrollBar)
fScrollBar->SetSteps(fFontHeight, fFontHeight * fTermRows);

View File

@ -40,7 +40,6 @@
#include <time.h>
const static float kViewOffset = 3;
const static int32 kMaxTabs = 6;
// messages constants
@ -131,7 +130,7 @@ TermWindow::_SetupMenu()
{
PrefHandler menuText;
LoadLocaleFile (&menuText);
LoadLocaleFile(&menuText);
// Menu bar object.
fMenubar = new BMenuBar(Bounds(), "mbar");
@ -172,12 +171,7 @@ TermWindow::_SetupMenu()
// Make Help Menu.
fHelpmenu = new BMenu("Settings");
fWindowSizeMenu = new BMenu("Window Size");
fWindowSizeMenu->AddItem(new BMenuItem("80x24", new BMessage(EIGHTYTWENTYFOUR)));
fWindowSizeMenu->AddItem(new BMenuItem("80x25", new BMessage(EIGHTYTWENTYFIVE)));
fWindowSizeMenu->AddItem(new BMenuItem("80x40", new BMessage(EIGHTYFORTY)));
fWindowSizeMenu->AddItem(new BMenuItem("132x24", new BMessage(ONETHREETWOTWENTYFOUR)));
fWindowSizeMenu->AddItem(new BMenuItem("132x25", new BMessage(ONETHREETWOTWENTYFIVE)));
fWindowSizeMenu->AddItem(new BMenuItem("Fullscreen", new BMessage(FULLSCREEN), B_ENTER));
_BuildWindowSizeMenu(fWindowSizeMenu);
fEncodingmenu = new BMenu("Font Encoding");
fEncodingmenu->SetRadioMode(true);
@ -249,6 +243,7 @@ TermWindow::MessageReceived(BMessage *message)
be_roster->Launch(TERM_SIGNATURE);
break;
}
case MENU_PREF_OPEN:
if (!fPrefWindow)
fPrefWindow = new PrefWindow(this);
@ -336,15 +331,17 @@ TermWindow::MessageReceived(BMessage *message)
_ActiveTermView()->SetEncoding(encodingId);
break;
// Message from Preference panel.
case MSG_ROWS_CHANGED:
case MSG_COLS_CHANGED:
{
BRect rect = _ActiveTermView()->SetTermSize(PrefHandler::Default()->getInt32 (PREF_ROWS),
PrefHandler::Default()->getInt32 (PREF_COLS), 0);
int32 columns, rows;
message->FindInt32("columns", &columns);
message->FindInt32("rows", &rows);
PrefHandler::Default()->setInt32(PREF_COLS, columns);
PrefHandler::Default()->setInt32(PREF_ROWS, rows);
ResizeTo (rect.Width()+ B_V_SCROLL_BAR_WIDTH + kViewOffset * 2,
rect.Height()+fMenubar->Bounds().Height() + kViewOffset *2);
_ActiveTermView()->SetTermSize(rows, columns, 0);
_ResizeView(_ActiveTermView());
BPath path;
if (PrefHandler::GetDefaultPath(path) == B_OK)
@ -364,35 +361,6 @@ TermWindow::MessageReceived(BMessage *message)
break;
}
case EIGHTYTWENTYFOUR:
PrefHandler::Default()->setString(PREF_COLS, "80");
PrefHandler::Default()->setString(PREF_ROWS, "24");
PostMessage(MSG_COLS_CHANGED);
break;
case EIGHTYTWENTYFIVE:
PrefHandler::Default()->setString(PREF_COLS, "80");
PrefHandler::Default()->setString(PREF_ROWS, "25");
PostMessage(MSG_COLS_CHANGED);
break;
case EIGHTYFORTY:
PrefHandler::Default()->setString(PREF_COLS, "80");
PrefHandler::Default()->setString(PREF_ROWS, "40");
PostMessage(MSG_COLS_CHANGED);
break;
case ONETHREETWOTWENTYFOUR:
PrefHandler::Default()->setString(PREF_COLS, "132");
PrefHandler::Default()->setString(PREF_ROWS, "24");
PostMessage(MSG_COLS_CHANGED);
break;
case ONETHREETWOTWENTYFIVE:
PrefHandler::Default()->setString(PREF_COLS, "132");
PrefHandler::Default()->setString(PREF_ROWS, "25");
PostMessage(MSG_COLS_CHANGED);
break;
case FULLSCREEN:
if (!fSavedFrame.IsValid()) { // go fullscreen
@ -480,8 +448,8 @@ TermWindow::MessageReceived(BMessage *message)
size -= 1;
// limit the font size
if (size < 8)
size = 8;
if (size < 6)
size = 6;
else if (size > 20)
size = 20;
@ -506,14 +474,6 @@ TermWindow::WindowActivated(bool activated)
}
bool
TermWindow::QuitRequested()
{
be_app->PostMessage(B_QUIT_REQUESTED);
return BWindow::QuitRequested();
}
void
TermWindow::_SetTermColors(TermView *termView)
{
@ -648,10 +608,6 @@ TermWindow::_AddTab(Arguments *args)
// Resize Window
ResizeTo(viewWidth + B_V_SCROLL_BAR_WIDTH,
viewHeight + fMenubar->Bounds().Height());
// TODO: If I don't do this, the view won't show up.
// Bug in BTabView or in my code ?
fTabView->Select(0);
}
} catch (...) {
// most probably out of memory. That's bad.
@ -702,32 +658,6 @@ TermWindow::_IndexOfTermView(TermView* termView) const
}
void
TermWindow::_ResizeView(TermView *view)
{
int fontWidth, fontHeight;
view->GetFontSize(&fontWidth, &fontHeight);
float minimumHeight = 0;
if (fMenubar)
minimumHeight += fMenubar->Bounds().Height();
if (fTabView && fTabView->CountTabs() > 1)
minimumHeight += fTabView->TabHeight();
SetSizeLimits(MIN_COLS * fontWidth, MAX_COLS * fontWidth,
minimumHeight + MIN_ROWS * fontHeight,
minimumHeight + MAX_ROWS * fontHeight);
float width, height;
view->GetPreferredSize(&width, &height);
width += B_V_SCROLL_BAR_WIDTH + kViewOffset * 2;
height += fMenubar->Bounds().Height() + kViewOffset * 2;
ResizeTo(width, height);
view->Invalidate();
}
void
TermWindow::_CheckChildren()
{
@ -749,6 +679,59 @@ TermWindow::_CheckChildren()
}
void
TermWindow::_ResizeView(TermView *view)
{
int fontWidth, fontHeight;
view->GetFontSize(&fontWidth, &fontHeight);
float minimumHeight = 0;
if (fMenubar)
minimumHeight += fMenubar->Bounds().Height();
if (fTabView && fTabView->CountTabs() > 1)
minimumHeight += fTabView->TabHeight();
SetSizeLimits(MIN_COLS * fontWidth, MAX_COLS * fontWidth,
minimumHeight + MIN_ROWS * fontHeight,
minimumHeight + MAX_ROWS * fontHeight);
float width, height;
view->GetPreferredSize(&width, &height);
width += B_V_SCROLL_BAR_WIDTH;
height += fMenubar->Bounds().Height();
ResizeTo(width, height);
view->Invalidate();
}
void
TermWindow::_BuildWindowSizeMenu(BMenu *menu)
{
const int32 windowSizes[5][2] = {
{ 80, 24 },
{ 80, 25 },
{ 80, 40 },
{ 132, 24 },
{ 132, 25 }
};
const int32 sizeNum = sizeof(windowSizes) / sizeof(windowSizes[0]);
for (int32 i = 0; i < sizeNum; i++) {
char label[32];
int32 columns = windowSizes[i][0];
int32 rows = windowSizes[i][1];
snprintf(label, sizeof(label), "%ldx%ld", columns, rows);
BMessage *message = new BMessage(MSG_COLS_CHANGED);
message->AddInt32("columns", columns);
message->AddInt32("rows", rows);
menu->AddItem(new BMenuItem(label, message));
}
menu->AddItem(new BMenuItem("Fullscreen",
new BMessage(FULLSCREEN), B_ENTER));
}
// CustomTermView
CustomTermView::CustomTermView(int32 rows, int32 columns, int32 argc, const char **argv, int32 historySize)

View File

@ -54,8 +54,6 @@ protected:
virtual void MessageReceived(BMessage *message);
virtual void WindowActivated(bool);
virtual void MenusBeginning();
virtual bool QuitRequested();
private:
void _SetTermColors(TermView *termView);
@ -70,6 +68,7 @@ private:
int32 _IndexOfTermView(TermView* termView) const;
void _CheckChildren();
void _ResizeView(TermView *view);
void _BuildWindowSizeMenu(BMenu *menu);
SmartTabView *fTabView;
TermView *fTermView;