Update StyledEdit to use document background color. Style fixes.

See ticket #5293 Colors_picture2.png
This commit is contained in:
John Scipione
2013-04-04 21:00:28 -04:00
parent a37c845e52
commit 2cfeb3ca9c
3 changed files with 79 additions and 72 deletions
+45 -41
View File
@@ -32,9 +32,13 @@ using namespace BPrivate;
StyledEditView::StyledEditView(BRect viewFrame, BRect textBounds,
BHandler* handler)
: BTextView(viewFrame, "textview", textBounds,
B_FOLLOW_ALL, B_FRAME_EVENTS | B_WILL_DRAW)
:
BTextView(viewFrame, "textview", textBounds, B_FOLLOW_ALL,
B_FRAME_EVENTS | B_WILL_DRAW)
{
SetViewColor(ui_color(B_DOCUMENT_BACKGROUND_COLOR));
SetLowColor(ViewColor());
fMessenger = new BMessenger(handler);
fSuppressChanges = false;
}
@@ -46,6 +50,45 @@ StyledEditView::~StyledEditView()
}
void
StyledEditView::FrameResized(float width, float height)
{
BTextView::FrameResized(width, height);
if (DoesWordWrap()) {
BRect textRect;
textRect = Bounds();
textRect.OffsetTo(B_ORIGIN);
textRect.InsetBy(TEXT_INSET, TEXT_INSET);
SetTextRect(textRect);
}
}
void
StyledEditView::DeleteText(int32 start, int32 finish)
{
if (!fSuppressChanges)
fMessenger-> SendMessage(TEXT_CHANGED);
BTextView::DeleteText(start, finish);
_UpdateStatus();
}
void
StyledEditView::InsertText(const char* text, int32 length, int32 offset,
const text_run_array* runs)
{
if (!fSuppressChanges)
fMessenger->SendMessage(TEXT_CHANGED);
BTextView::InsertText(text, length, offset, runs);
_UpdateStatus();
}
void
StyledEditView::Select(int32 start, int32 finish)
{
@@ -174,44 +217,6 @@ StyledEditView::GetEncoding() const
}
void
StyledEditView::DeleteText(int32 start, int32 finish)
{
if (!fSuppressChanges)
fMessenger-> SendMessage(TEXT_CHANGED);
BTextView::DeleteText(start, finish);
_UpdateStatus();
}
void
StyledEditView::InsertText(const char* text, int32 length, int32 offset,
const text_run_array* runs)
{
if (!fSuppressChanges)
fMessenger->SendMessage(TEXT_CHANGED);
BTextView::InsertText(text, length, offset, runs);
_UpdateStatus();
}
void
StyledEditView::FrameResized(float width, float height)
{
BTextView::FrameResized(width, height);
if (DoesWordWrap()) {
BRect textRect;
textRect = Bounds();
textRect.OffsetTo(B_ORIGIN);
textRect.InsetBy(TEXT_INSET, TEXT_INSET);
SetTextRect(textRect);
}
}
void
StyledEditView::_UpdateStatus()
{
@@ -239,4 +244,3 @@ StyledEditView::_UpdateStatus()
message->AddString("encoding", fEncoding.String());
fMessenger->SendMessage(message);
}
+6 -5
View File
@@ -14,23 +14,24 @@
#include <String.h>
#include <TextView.h>
class BFile;
class BHandler;
class BMessenger;
class BPositionIO;
class StyledEditView : public BTextView {
public:
StyledEditView(BRect viewframe, BRect textframe,
BHandler* handler);
virtual ~StyledEditView();
virtual void Select(int32 start, int32 finish);
virtual void DeleteText(int32 start, int32 finish);
virtual void FrameResized(float width, float height);
virtual void InsertText(const char* text, int32 length, int32 offset,
virtual void DeleteText(int32 start, int32 finish);
virtual void InsertText(const char* text, int32 length,
int32 offset,
const text_run_array* runs = NULL);
virtual void Select(int32 start, int32 finish);
void Reset();
void SetSuppressChanges(bool suppressChanges);
@@ -49,5 +50,5 @@ class StyledEditView : public BTextView {
BString fEncoding;
};
#endif // STYLED_EDIT_VIEW_H
#endif // STYLED_EDIT_VIEW_H
+12 -10
View File
@@ -598,11 +598,10 @@ StyledEditWindow::MenusBeginning()
BMenu* menu = fCurrentFontItem->Submenu();
if (menu != NULL) {
BMenuItem* item = menu->FindMarked();
if (item != NULL) {
if (item != NULL)
item->SetMarked(false);
}
}
}
if (fCurrentStyleItem != NULL) {
fCurrentStyleItem->SetMarked(false);
@@ -622,9 +621,10 @@ StyledEditWindow::MenusBeginning()
rgb_color color = BLACK;
bool sameColor;
fTextView->GetFontAndColor(&font, &sameProperties, &color, &sameColor);
color.alpha = 255;
if (sameColor && color.alpha == 255) {
// select the current color
if (sameColor) {
// mark the menu according to the current color
if (color.red == 0) {
if (color.green == 0) {
if (color.blue == 0) {
@@ -1211,8 +1211,8 @@ StyledEditWindow::_InitWindow(uint32 encoding)
fFontColorMenu->SetRadioMode(true);
fFontMenu->AddItem(fFontColorMenu);
fFontColorMenu->AddItem(fBlackItem = new BMenuItem(B_TRANSLATE("Black"),
new BMessage(FONT_COLOR)));
fFontColorMenu->AddItem(fBlackItem = new ColorMenuItem(B_TRANSLATE("Black"),
BLACK, new BMessage(FONT_COLOR)));
fBlackItem->SetMarked(true);
fFontColorMenu->AddItem(fRedItem = new ColorMenuItem(B_TRANSLATE("Red"),
RED, new BMessage(FONT_COLOR)));
@@ -1222,10 +1222,12 @@ StyledEditWindow::_InitWindow(uint32 encoding)
BLUE, new BMessage(FONT_COLOR)));
fFontColorMenu->AddItem(fCyanItem = new ColorMenuItem(B_TRANSLATE("Cyan"),
CYAN, new BMessage(FONT_COLOR)));
fFontColorMenu->AddItem(fMagentaItem = new ColorMenuItem(B_TRANSLATE("Magenta"),
MAGENTA, new BMessage(FONT_COLOR)));
fFontColorMenu->AddItem(fYellowItem = new ColorMenuItem(B_TRANSLATE("Yellow"),
YELLOW, new BMessage(FONT_COLOR)));
fFontColorMenu->AddItem(fMagentaItem
= new ColorMenuItem(B_TRANSLATE("Magenta"), MAGENTA,
new BMessage(FONT_COLOR)));
fFontColorMenu->AddItem(fYellowItem
= new ColorMenuItem(B_TRANSLATE("Yellow"), YELLOW,
new BMessage(FONT_COLOR)));
fFontMenu->AddSeparatorItem();
// "Bold" & "Italic" menu items