* 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
This commit is contained in:
Axel Dörfler 2010-11-29 21:44:38 +00:00
parent e7de22dcff
commit d2ff9616c8
3 changed files with 81 additions and 5 deletions

View File

@ -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

View File

@ -311,6 +311,12 @@ StyledEditWindow::MessageReceived(BMessage* message)
BMenuItem* item = static_cast<BMenuItem*>(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;

View File

@ -106,6 +106,9 @@ private:
BMenuItem* fMagentaItem;
BMenuItem* fYellowItem;
BMenuItem* fBoldItem;
BMenuItem* fItalicItem;
BMenuItem* fWrapItem;
BMenuItem* fAlignLeft;
BMenuItem* fAlignCenter;