diff --git a/src/apps/stylededit/Constants.h b/src/apps/stylededit/Constants.h index b7a88f378b..a16940e7df 100644 --- a/src/apps/stylededit/Constants.h +++ b/src/apps/stylededit/Constants.h @@ -1,10 +1,11 @@ /* - * Copyright 2002-2010, Haiku, Inc. All Rights Reserved. + * Copyright 2002-2020, Haiku, Inc. All Rights Reserved. * Distributed under the terms of the MIT License. * * Authors: * Mattias Sundblad * Andrew Bachmann + * Pascal R. G. Abresch */ #ifndef CONSTANTS_H #define CONSTANTS_H @@ -53,6 +54,8 @@ const uint32 FONT_STYLE = 'FSch'; const uint32 FONT_COLOR = 'Fcol'; const uint32 kMsgSetItalic = 'Fita'; const uint32 kMsgSetBold = 'Fbld'; +const uint32 kMsgSetFontDown = 'Fsdw'; +const uint32 kMsgSetFontUp = 'Fsup'; const rgb_color palette[] = { { 220, 0, 0, 255 }, // red @@ -93,5 +96,8 @@ const uint32 UPDATE_STATUS_REF = 'UPSr'; const uint32 UNLOCK_FILE = 'UNLk'; const uint32 UPDATE_LINE_SELECTION = 'UPls'; +// fontSize constant +const int32 fontSizes[] = {9, 10, 11, 12, 14, 18, 24, 36, 48, 72}; + #endif // CONSTANTS_H diff --git a/src/apps/stylededit/StyledEditWindow.cpp b/src/apps/stylededit/StyledEditWindow.cpp index db7f5e0006..27e9ef3479 100644 --- a/src/apps/stylededit/StyledEditWindow.cpp +++ b/src/apps/stylededit/StyledEditWindow.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012, Haiku, Inc. All Rights Reserved. + * Copyright 2002-2020, Haiku, Inc. All Rights Reserved. * Distributed under the terms of the MIT License. * * Authors: @@ -10,6 +10,7 @@ * Ryan Leavengood * Vlad Slepukhin * Sarzhuk Zharski + * Pascal R. G. Abresch */ @@ -397,6 +398,42 @@ StyledEditWindow::MessageReceived(BMessage* message) _SetFontStyle(fontFamily, fontStyle); break; } + case kMsgSetFontUp: + { + uint32 sameProperties; + BFont font; + + fTextView->GetFontAndColor(&font, &sameProperties); + //GetFont seems to return a constant size for font.Size(), + //thus not used here (maybe that is a bug) + int32 cur_size = font.Size(); + + for (unsigned int a = 0; + a < sizeof(fontSizes)/sizeof(fontSizes[0]); a++) { + if (fontSizes[a] > cur_size) { + _SetFontSize(fontSizes[a]); + break; + } + } + break; + } + case kMsgSetFontDown: + { + uint32 sameProperties; + BFont font; + + fTextView->GetFontAndColor(&font, &sameProperties); + int32 cur_size = font.Size(); + + for (unsigned int a = 1; + a < sizeof(fontSizes)/sizeof(fontSizes[0]); a++) { + if (fontSizes[a] >= cur_size) { + _SetFontSize(fontSizes[a-1]); + break; + } + } + break; + } case kMsgSetItalic: { uint32 sameProperties; @@ -1212,7 +1249,6 @@ StyledEditWindow::_InitWindow(uint32 encoding) fFontSizeMenu->SetRadioMode(true); fFontMenu->AddItem(fFontSizeMenu); - const int32 fontSizes[] = {9, 10, 11, 12, 14, 18, 24, 36, 48, 72}; for (uint32 i = 0; i < sizeof(fontSizes) / sizeof(fontSizes[0]); i++) { BMessage* fontMessage = new BMessage(FONT_SIZE); fontMessage->AddFloat("size", fontSizes[i]); @@ -1234,6 +1270,15 @@ StyledEditWindow::_InitWindow(uint32 encoding) fFontMenu->AddSeparatorItem(); + BMenuItem* fontSizeUpItem = new BMenuItem(B_TRANSLATE("Increase size"), + new BMessage(kMsgSetFontUp)); + BMenuItem* fontSizeDownItem = new BMenuItem(B_TRANSLATE("Decrease size"), + new BMessage(kMsgSetFontDown)); + fFontMenu->AddItem(fontSizeUpItem); + fFontMenu->AddItem(fontSizeDownItem); + fontSizeUpItem->SetShortcut('+', 0); + fontSizeDownItem->SetShortcut('-', 0); + // "Bold" & "Italic" menu items fFontMenu->AddItem(fBoldItem = new BMenuItem(B_TRANSLATE("Bold"), new BMessage(kMsgSetBold)));