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

View File

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

View File

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

View File

@ -106,7 +106,8 @@ SmartTabView::Select(int32 index)
BTabView::Select(index); BTabView::Select(index);
BView *view = ViewForTab(index); BView *view = ViewForTab(index);
if (view != NULL) { 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()) else if (index < CountTabs())
Select(index + 1); Select(index + 1);
} }
BTab *tab = RemoveTab(index); delete RemoveTab(index);
delete tab;
} }
@ -132,11 +132,20 @@ SmartTabView::AddTab(BView *target, BTab *tab)
if (target == NULL) if (target == NULL)
return; return;
BTabView::AddTab(target, tab);
if (CountTabs() == 1) { 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()->ResizeBy(0, -TabHeight());
ContainerView()->MoveBy(0, TabHeight()); ContainerView()->MoveBy(0, TabHeight());
Window()->ResizeBy(0, TabHeight());
} }
BTabView::AddTab(target, tab);
Invalidate(TabFrame(CountTabs() - 1).InsetByCopy(-2, -2)); Invalidate(TabFrame(CountTabs() - 1).InsetByCopy(-2, -2));
} }
@ -145,12 +154,13 @@ SmartTabView::AddTab(BView *target, BTab *tab)
BTab * BTab *
SmartTabView::RemoveTab(int32 index) SmartTabView::RemoveTab(int32 index)
{ {
BTab *tab = BTabView::RemoveTab(index); if (CountTabs() == 2) {
if (CountTabs() == 1) { // see above
Window()->ResizeBy(0, -TabHeight());
ContainerView()->MoveBy(0, -TabHeight()); ContainerView()->MoveBy(0, -TabHeight());
ContainerView()->ResizeBy(0, TabHeight()); ContainerView()->ResizeBy(0, TabHeight());
} }
return tab; return BTabView::RemoveTab(index);
} }
@ -175,5 +185,3 @@ SmartTabView::_ClickedTabIndex(const BPoint &point)
return -1; return -1;
} }

View File

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

View File

@ -40,7 +40,6 @@
#include <time.h> #include <time.h>
const static float kViewOffset = 3;
const static int32 kMaxTabs = 6; const static int32 kMaxTabs = 6;
// messages constants // messages constants
@ -131,7 +130,7 @@ TermWindow::_SetupMenu()
{ {
PrefHandler menuText; PrefHandler menuText;
LoadLocaleFile (&menuText); LoadLocaleFile(&menuText);
// Menu bar object. // Menu bar object.
fMenubar = new BMenuBar(Bounds(), "mbar"); fMenubar = new BMenuBar(Bounds(), "mbar");
@ -172,12 +171,7 @@ TermWindow::_SetupMenu()
// Make Help Menu. // Make Help Menu.
fHelpmenu = new BMenu("Settings"); fHelpmenu = new BMenu("Settings");
fWindowSizeMenu = new BMenu("Window Size"); fWindowSizeMenu = new BMenu("Window Size");
fWindowSizeMenu->AddItem(new BMenuItem("80x24", new BMessage(EIGHTYTWENTYFOUR))); _BuildWindowSizeMenu(fWindowSizeMenu);
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));
fEncodingmenu = new BMenu("Font Encoding"); fEncodingmenu = new BMenu("Font Encoding");
fEncodingmenu->SetRadioMode(true); fEncodingmenu->SetRadioMode(true);
@ -249,6 +243,7 @@ TermWindow::MessageReceived(BMessage *message)
be_roster->Launch(TERM_SIGNATURE); be_roster->Launch(TERM_SIGNATURE);
break; break;
} }
case MENU_PREF_OPEN: case MENU_PREF_OPEN:
if (!fPrefWindow) if (!fPrefWindow)
fPrefWindow = new PrefWindow(this); fPrefWindow = new PrefWindow(this);
@ -336,15 +331,17 @@ TermWindow::MessageReceived(BMessage *message)
_ActiveTermView()->SetEncoding(encodingId); _ActiveTermView()->SetEncoding(encodingId);
break; break;
// Message from Preference panel.
case MSG_ROWS_CHANGED:
case MSG_COLS_CHANGED: case MSG_COLS_CHANGED:
{ {
BRect rect = _ActiveTermView()->SetTermSize(PrefHandler::Default()->getInt32 (PREF_ROWS), int32 columns, rows;
PrefHandler::Default()->getInt32 (PREF_COLS), 0); 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, _ActiveTermView()->SetTermSize(rows, columns, 0);
rect.Height()+fMenubar->Bounds().Height() + kViewOffset *2);
_ResizeView(_ActiveTermView());
BPath path; BPath path;
if (PrefHandler::GetDefaultPath(path) == B_OK) if (PrefHandler::GetDefaultPath(path) == B_OK)
@ -364,35 +361,6 @@ TermWindow::MessageReceived(BMessage *message)
break; 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: case FULLSCREEN:
if (!fSavedFrame.IsValid()) { // go fullscreen if (!fSavedFrame.IsValid()) { // go fullscreen
@ -480,8 +448,8 @@ TermWindow::MessageReceived(BMessage *message)
size -= 1; size -= 1;
// limit the font size // limit the font size
if (size < 8) if (size < 6)
size = 8; size = 6;
else if (size > 20) else if (size > 20)
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 void
TermWindow::_SetTermColors(TermView *termView) TermWindow::_SetTermColors(TermView *termView)
{ {
@ -648,10 +608,6 @@ TermWindow::_AddTab(Arguments *args)
// Resize Window // Resize Window
ResizeTo(viewWidth + B_V_SCROLL_BAR_WIDTH, ResizeTo(viewWidth + B_V_SCROLL_BAR_WIDTH,
viewHeight + fMenubar->Bounds().Height()); 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 (...) { } catch (...) {
// most probably out of memory. That's bad. // 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 void
TermWindow::_CheckChildren() 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::CustomTermView(int32 rows, int32 columns, int32 argc, const char **argv, int32 historySize) 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 MessageReceived(BMessage *message);
virtual void WindowActivated(bool); virtual void WindowActivated(bool);
virtual void MenusBeginning(); virtual void MenusBeginning();
virtual bool QuitRequested();
private: private:
void _SetTermColors(TermView *termView); void _SetTermColors(TermView *termView);
@ -70,6 +68,7 @@ private:
int32 _IndexOfTermView(TermView* termView) const; int32 _IndexOfTermView(TermView* termView) const;
void _CheckChildren(); void _CheckChildren();
void _ResizeView(TermView *view); void _ResizeView(TermView *view);
void _BuildWindowSizeMenu(BMenu *menu);
SmartTabView *fTabView; SmartTabView *fTabView;
TermView *fTermView; TermView *fTermView;