* 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:
@@ -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.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
@@ -48,6 +48,8 @@ const uint32 FONT_SIZE = 'FMsi';
|
|||||||
const uint32 FONT_FAMILY = 'FFch';
|
const uint32 FONT_FAMILY = 'FFch';
|
||||||
const uint32 FONT_STYLE = 'FSch';
|
const uint32 FONT_STYLE = 'FSch';
|
||||||
const uint32 FONT_COLOR = 'Fcol';
|
const uint32 FONT_COLOR = 'Fcol';
|
||||||
|
const uint32 kMsgSetItalic = 'Fita';
|
||||||
|
const uint32 kMsgSetBold = 'Fbld';
|
||||||
|
|
||||||
// fontcolors
|
// fontcolors
|
||||||
const rgb_color BLACK = {0, 0, 0, 255};
|
const rgb_color BLACK = {0, 0, 0, 255};
|
||||||
|
|||||||
@@ -311,6 +311,12 @@ StyledEditWindow::MessageReceived(BMessage* message)
|
|||||||
BMenuItem* item = static_cast<BMenuItem*>(ptr);
|
BMenuItem* item = static_cast<BMenuItem*>(ptr);
|
||||||
fontFamily = item->Label();
|
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);
|
_SetFontStyle(fontFamily, fontStyle);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -329,9 +335,49 @@ StyledEditWindow::MessageReceived(BMessage* message)
|
|||||||
fontFamily = super_item->Label();
|
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);
|
_SetFontStyle(fontFamily, fontStyle);
|
||||||
break;
|
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:
|
case FONT_COLOR:
|
||||||
{
|
{
|
||||||
void* ptr;
|
void* ptr;
|
||||||
@@ -581,12 +627,14 @@ StyledEditWindow::MenusBeginning()
|
|||||||
if (menu != NULL) {
|
if (menu != NULL) {
|
||||||
BMenuItem* item = menu->FindItem(style);
|
BMenuItem* item = menu->FindItem(style);
|
||||||
fCurrentStyleItem = item;
|
fCurrentStyleItem = item;
|
||||||
if (fCurrentStyleItem != NULL) {
|
if (fCurrentStyleItem != NULL)
|
||||||
item->SetMarked(true);
|
item->SetMarked(true);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fBoldItem->SetMarked((font.Face() & B_BOLD_FACE) != 0);
|
||||||
|
fItalicItem->SetMarked((font.Face() & B_ITALIC_FACE) != 0);
|
||||||
|
|
||||||
switch (fTextView->Alignment()) {
|
switch (fTextView->Alignment()) {
|
||||||
case B_ALIGN_LEFT:
|
case B_ALIGN_LEFT:
|
||||||
default:
|
default:
|
||||||
@@ -1106,6 +1154,15 @@ StyledEditWindow::_InitWindow(uint32 encoding)
|
|||||||
YELLOW, new BMessage(FONT_COLOR)));
|
YELLOW, new BMessage(FONT_COLOR)));
|
||||||
fFontMenu->AddSeparatorItem();
|
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
|
// Available fonts
|
||||||
|
|
||||||
fCurrentFontItem = 0;
|
fCurrentFontItem = 0;
|
||||||
@@ -1522,6 +1579,20 @@ StyledEditWindow::_SetFontStyle(const char* fontFamily, const char* fontStyle)
|
|||||||
}
|
}
|
||||||
|
|
||||||
font.SetFamilyAndStyle(fontFamily, 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);
|
fTextView->SetFontAndColor(&font);
|
||||||
|
|
||||||
BMenuItem* superItem;
|
BMenuItem* superItem;
|
||||||
|
|||||||
@@ -106,6 +106,9 @@ private:
|
|||||||
BMenuItem* fMagentaItem;
|
BMenuItem* fMagentaItem;
|
||||||
BMenuItem* fYellowItem;
|
BMenuItem* fYellowItem;
|
||||||
|
|
||||||
|
BMenuItem* fBoldItem;
|
||||||
|
BMenuItem* fItalicItem;
|
||||||
|
|
||||||
BMenuItem* fWrapItem;
|
BMenuItem* fWrapItem;
|
||||||
BMenuItem* fAlignLeft;
|
BMenuItem* fAlignLeft;
|
||||||
BMenuItem* fAlignCenter;
|
BMenuItem* fAlignCenter;
|
||||||
|
|||||||
Reference in New Issue
Block a user