diff --git a/src/apps/terminal/TermView.cpp b/src/apps/terminal/TermView.cpp index d0b2a4ceac..00ac99c56f 100644 --- a/src/apps/terminal/TermView.cpp +++ b/src/apps/terminal/TermView.cpp @@ -406,6 +406,14 @@ TermView::SetEncoding(int encoding) } +void +TermView::GetTermFont(BFont *font) const +{ + if (font != NULL) + *font = fHalfFont; +} + + //! Sets font for terminal void TermView::SetTermFont(const BFont *font) diff --git a/src/apps/terminal/TermView.h b/src/apps/terminal/TermView.h index accc69976b..1860dae0de 100644 --- a/src/apps/terminal/TermView.h +++ b/src/apps/terminal/TermView.h @@ -40,7 +40,9 @@ public: const char *TerminalName() const; + void GetTermFont(BFont *font) const; void SetTermFont(const BFont *font); + void GetFontSize(int *width, int *height); BRect SetTermSize(int rows, int cols, bool resize); diff --git a/src/apps/terminal/TermWindow.cpp b/src/apps/terminal/TermWindow.cpp index 791f9611e9..769dd097dd 100644 --- a/src/apps/terminal/TermWindow.cpp +++ b/src/apps/terminal/TermWindow.cpp @@ -41,9 +41,13 @@ const static float kViewOffset = 3; +const static int32 kMaxTabs = 6; + +// messages constants const static uint32 kNewTab = 'NTab'; const static uint32 kCloseView = 'ClVw'; -const static int32 kMaxTabs = 6; +const static uint32 kIncreaseFontSize = 'InFs'; +const static uint32 kDecreaseFontSize = 'DcFs'; class CustomTermView : public TermView { @@ -100,6 +104,9 @@ TermWindow::_InitWindow() // make menu bar _SetupMenu(); + AddShortcut('+', B_COMMAND_KEY, new BMessage(kIncreaseFontSize)); + AddShortcut('-', B_COMMAND_KEY, new BMessage(kDecreaseFontSize)); + BRect textFrame = Bounds(); textFrame.top = fMenubar->Bounds().bottom + 1.0; @@ -220,6 +227,10 @@ TermWindow::MessageReceived(BMessage *message) _ActiveTermView()->SelectAll(); break; + case B_ABOUT_REQUESTED: + be_app->PostMessage(B_ABOUT_REQUESTED); + break; + case MENU_CLEAR_ALL: _ActiveTermView()->Clear(); break; @@ -228,22 +239,6 @@ TermWindow::MessageReceived(BMessage *message) be_app->PostMessage(MENU_SWITCH_TERM); break; - case kNewTab: - if (fTabView->CountTabs() < kMaxTabs) - _AddTab(NULL); - break; - - case kCloseView: - { - TermView* termView; - if (message->FindPointer("termView", (void**)&termView) == B_OK) { - int32 index = _IndexOfTermView(termView); - if (index >= 0) - _RemoveTab(index); - } - break; - } - case MENU_NEW_TERM: { app_info info; @@ -364,27 +359,9 @@ TermWindow::MessageReceived(BMessage *message) BFont font; _GetPreferredFont(font); _ActiveTermView()->SetTermFont(&font); - - int fontWidth, fontHeight; - _ActiveTermView()->GetFontSize(&fontWidth, &fontHeight); - float minimumHeight = 0; - if (fMenubar) - minimumHeight += fMenubar->Bounds().Height(); - if (fTabView && fTabView->CountTabs() > 1) - minimumHeight += fTabView->TabHeight(); + _ResizeView(_ActiveTermView()); - SetSizeLimits(MIN_COLS * fontWidth, MAX_COLS * fontWidth, - minimumHeight + MIN_ROWS * fontHeight, - minimumHeight + MAX_ROWS * fontHeight); - - float width, height; - _ActiveTermView()->GetPreferredSize(&width, &height); - width += B_V_SCROLL_BAR_WIDTH + kViewOffset * 2; - height += fMenubar->Bounds().Height() + kViewOffset * 2; - ResizeTo(width, height); - - _ActiveTermView()->Invalidate(); break; } case EIGHTYTWENTYFOUR: @@ -472,10 +449,49 @@ TermWindow::MessageReceived(BMessage *message) _CheckChildren(); break; - case B_ABOUT_REQUESTED: - be_app->PostMessage(B_ABOUT_REQUESTED); + case kNewTab: + if (fTabView->CountTabs() < kMaxTabs) + _AddTab(NULL); break; - + + case kCloseView: + { + TermView* termView; + if (message->FindPointer("termView", (void**)&termView) == B_OK) { + int32 index = _IndexOfTermView(termView); + if (index >= 0) + _RemoveTab(index); + } + break; + } + + case kIncreaseFontSize: + case kDecreaseFontSize: + { + message->PrintToStream(); + TermView *view = _ActiveTermView(); + BFont font; + view->GetTermFont(&font); + + float size = font.Size(); + if (message->what == kIncreaseFontSize) + size += 1; + else + size -= 1; + + // limit the font size + if (size < 8) + size = 8; + else if (size > 20) + size = 20; + + font.SetSize(size); + view->SetTermFont(&font); + + _ResizeView(view); + break; + } + default: BWindow::MessageReceived(message); break; @@ -686,6 +702,32 @@ 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() { diff --git a/src/apps/terminal/TermWindow.h b/src/apps/terminal/TermWindow.h index 5b401783f8..d1334b9264 100644 --- a/src/apps/terminal/TermWindow.h +++ b/src/apps/terminal/TermWindow.h @@ -69,6 +69,7 @@ private: TermView* _ActiveTermView(); int32 _IndexOfTermView(TermView* termView) const; void _CheckChildren(); + void _ResizeView(TermView *view); SmartTabView *fTabView; TermView *fTermView;