From d2ff9616c8a53f5b786d35a7a9b820267c4a39b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Mon, 29 Nov 2010 21:44:38 +0000 Subject: [PATCH] * Applied patch by negusnyul that closes ticket #4689 by adding bold/italic shortcuts to StyledEdit - thanks a lot! * Minor style changes. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@39680 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/stylededit/Constants.h | 8 ++- src/apps/stylededit/StyledEditWindow.cpp | 75 +++++++++++++++++++++++- src/apps/stylededit/StyledEditWindow.h | 3 + 3 files changed, 81 insertions(+), 5 deletions(-) diff --git a/src/apps/stylededit/Constants.h b/src/apps/stylededit/Constants.h index 5ca7b94f85..cbd4776a0d 100644 --- a/src/apps/stylededit/Constants.h +++ b/src/apps/stylededit/Constants.h @@ -1,5 +1,5 @@ /* - * Copyright 2002-2006, Haiku, Inc. All Rights Reserved. + * Copyright 2002-2010, Haiku, Inc. All Rights Reserved. * Distributed under the terms of the MIT License. * * Authors: @@ -25,7 +25,7 @@ const uint32 MENU_NEW = 'MFnw'; const uint32 MENU_OPEN = 'MFop'; const uint32 MENU_SAVE = 'MSav'; const uint32 MENU_SAVEAS = 'MEsa'; -const uint32 MENU_REVERT = 'MFre'; +const uint32 MENU_REVERT = 'MFre'; const uint32 MENU_CLOSE = 'MFcl'; const uint32 MENU_PAGESETUP = 'MFps'; const uint32 MENU_PRINT = 'MFpr'; @@ -48,6 +48,8 @@ const uint32 FONT_SIZE = 'FMsi'; const uint32 FONT_FAMILY = 'FFch'; const uint32 FONT_STYLE = 'FSch'; const uint32 FONT_COLOR = 'Fcol'; +const uint32 kMsgSetItalic = 'Fita'; +const uint32 kMsgSetBold = 'Fbld'; // fontcolors const rgb_color BLACK = {0, 0, 0, 255}; @@ -68,7 +70,7 @@ const uint32 SHOW_STATISTICS = 'MDss'; // enables "edit" menuitems const uint32 ENABLE_ITEMS = 'ENit'; const uint32 DISABLE_ITEMS = 'DIit'; -const uint32 CHANGE_WINDOW = 'CHwi'; +const uint32 CHANGE_WINDOW = 'CHwi'; const uint32 TEXT_CHANGED = 'TEch'; // file panel constants diff --git a/src/apps/stylededit/StyledEditWindow.cpp b/src/apps/stylededit/StyledEditWindow.cpp index da02e0d7cd..5fc84b9f46 100644 --- a/src/apps/stylededit/StyledEditWindow.cpp +++ b/src/apps/stylededit/StyledEditWindow.cpp @@ -311,6 +311,12 @@ StyledEditWindow::MessageReceived(BMessage* message) BMenuItem* item = static_cast(ptr); fontFamily = item->Label(); } + + BFont font; + font.SetFamilyAndStyle(fontFamily, fontStyle); + fItalicItem->SetMarked((font.Face() & B_ITALIC_FACE) != 0); + fBoldItem->SetMarked((font.Face() & B_BOLD_FACE) != 0); + _SetFontStyle(fontFamily, fontStyle); break; } @@ -329,9 +335,49 @@ StyledEditWindow::MessageReceived(BMessage* message) fontFamily = super_item->Label(); } } + + BFont font; + font.SetFamilyAndStyle(fontFamily, fontStyle); + fItalicItem->SetMarked((font.Face() & B_ITALIC_FACE) != 0); + fBoldItem->SetMarked((font.Face() & B_BOLD_FACE) != 0); + _SetFontStyle(fontFamily, fontStyle); break; } + case kMsgSetItalic: + { + uint32 sameProperties; + BFont font; + fTextView->GetFontAndColor(&font, &sameProperties); + + if (fItalicItem->IsMarked()) + font.SetFace(B_REGULAR_FACE); + fItalicItem->SetMarked(!fItalicItem->IsMarked()); + + font_family family; + font_style style; + font.GetFamilyAndStyle(&family, &style); + + _SetFontStyle(family, style); + break; + } + case kMsgSetBold: + { + uint32 sameProperties; + BFont font; + fTextView->GetFontAndColor(&font, &sameProperties); + + if (fBoldItem->IsMarked()) + font.SetFace(B_REGULAR_FACE); + fBoldItem->SetMarked(!fBoldItem->IsMarked()); + + font_family family; + font_style style; + font.GetFamilyAndStyle(&family, &style); + + _SetFontStyle(family, style); + break; + } case FONT_COLOR: { void* ptr; @@ -581,12 +627,14 @@ StyledEditWindow::MenusBeginning() if (menu != NULL) { BMenuItem* item = menu->FindItem(style); fCurrentStyleItem = item; - if (fCurrentStyleItem != NULL) { + if (fCurrentStyleItem != NULL) item->SetMarked(true); - } } } + fBoldItem->SetMarked((font.Face() & B_BOLD_FACE) != 0); + fItalicItem->SetMarked((font.Face() & B_ITALIC_FACE) != 0); + switch (fTextView->Alignment()) { case B_ALIGN_LEFT: default: @@ -1106,6 +1154,15 @@ StyledEditWindow::_InitWindow(uint32 encoding) YELLOW, new BMessage(FONT_COLOR))); fFontMenu->AddSeparatorItem(); + // "Bold" & "Italic" menu items + fFontMenu->AddItem(fBoldItem = new BMenuItem(B_TRANSLATE("Bold"), + new BMessage(kMsgSetBold))); + fFontMenu->AddItem(fItalicItem = new BMenuItem(B_TRANSLATE("Italic"), + new BMessage(kMsgSetItalic))); + fBoldItem->SetShortcut('B', 0); + fItalicItem->SetShortcut('I', 0); + fFontMenu->AddSeparatorItem(); + // Available fonts fCurrentFontItem = 0; @@ -1522,6 +1579,20 @@ StyledEditWindow::_SetFontStyle(const char* fontFamily, const char* fontStyle) } font.SetFamilyAndStyle(fontFamily, fontStyle); + + uint16 face = 0; + + if (!(font.Face() & B_REGULAR_FACE)) + face = font.Face(); + + if (fBoldItem->IsMarked()) + face |= B_BOLD_FACE; + + if (fItalicItem->IsMarked()) + face |= B_ITALIC_FACE; + + font.SetFace(face); + fTextView->SetFontAndColor(&font); BMenuItem* superItem; diff --git a/src/apps/stylededit/StyledEditWindow.h b/src/apps/stylededit/StyledEditWindow.h index f36b74b23d..8ac99bc51c 100644 --- a/src/apps/stylededit/StyledEditWindow.h +++ b/src/apps/stylededit/StyledEditWindow.h @@ -106,6 +106,9 @@ private: BMenuItem* fMagentaItem; BMenuItem* fYellowItem; + BMenuItem* fBoldItem; + BMenuItem* fItalicItem; + BMenuItem* fWrapItem; BMenuItem* fAlignLeft; BMenuItem* fAlignCenter;