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, StyledEditView::StyledEditView(BRect viewFrame, BRect textBounds,
BHandler* handler) 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); fMessenger = new BMessenger(handler);
fSuppressChanges = false; 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 void
StyledEditView::Select(int32 start, int32 finish) 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 void
StyledEditView::_UpdateStatus() StyledEditView::_UpdateStatus()
{ {
@@ -239,4 +244,3 @@ StyledEditView::_UpdateStatus()
message->AddString("encoding", fEncoding.String()); message->AddString("encoding", fEncoding.String());
fMessenger->SendMessage(message); fMessenger->SendMessage(message);
} }
+20 -19
View File
@@ -14,40 +14,41 @@
#include <String.h> #include <String.h>
#include <TextView.h> #include <TextView.h>
class BFile; class BFile;
class BHandler; class BHandler;
class BMessenger; class BMessenger;
class BPositionIO; class BPositionIO;
class StyledEditView : public BTextView { class StyledEditView : public BTextView {
public: public:
StyledEditView(BRect viewframe, BRect textframe, StyledEditView(BRect viewframe, BRect textframe,
BHandler* handler); BHandler* handler);
virtual ~StyledEditView(); virtual ~StyledEditView();
virtual void Select(int32 start, int32 finish); virtual void FrameResized(float width, float height);
virtual void DeleteText(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,
virtual void InsertText(const char* text, int32 length, int32 offset, int32 offset,
const text_run_array* runs = NULL); const text_run_array* runs = NULL);
virtual void Select(int32 start, int32 finish);
void Reset(); void Reset();
void SetSuppressChanges(bool suppressChanges); void SetSuppressChanges(bool suppressChanges);
status_t GetStyledText(BPositionIO* stream, status_t GetStyledText(BPositionIO* stream,
const char* forceEncoding = NULL); const char* forceEncoding = NULL);
status_t WriteStyledEditFile(BFile* file); status_t WriteStyledEditFile(BFile* file);
void SetEncoding(uint32 encoding); void SetEncoding(uint32 encoding);
uint32 GetEncoding() const; uint32 GetEncoding() const;
private: private:
void _UpdateStatus(); void _UpdateStatus();
BMessenger *fMessenger; BMessenger* fMessenger;
bool fSuppressChanges; bool fSuppressChanges;
BString fEncoding; BString fEncoding;
}; };
#endif // STYLED_EDIT_VIEW_H
#endif // STYLED_EDIT_VIEW_H
+13 -11
View File
@@ -598,9 +598,8 @@ StyledEditWindow::MenusBeginning()
BMenu* menu = fCurrentFontItem->Submenu(); BMenu* menu = fCurrentFontItem->Submenu();
if (menu != NULL) { if (menu != NULL) {
BMenuItem* item = menu->FindMarked(); BMenuItem* item = menu->FindMarked();
if (item != NULL) { if (item != NULL)
item->SetMarked(false); item->SetMarked(false);
}
} }
} }
@@ -622,9 +621,10 @@ StyledEditWindow::MenusBeginning()
rgb_color color = BLACK; rgb_color color = BLACK;
bool sameColor; bool sameColor;
fTextView->GetFontAndColor(&font, &sameProperties, &color, &sameColor); fTextView->GetFontAndColor(&font, &sameProperties, &color, &sameColor);
color.alpha = 255;
if (sameColor && color.alpha == 255) { if (sameColor) {
// select the current color // mark the menu according to the current color
if (color.red == 0) { if (color.red == 0) {
if (color.green == 0) { if (color.green == 0) {
if (color.blue == 0) { if (color.blue == 0) {
@@ -1086,7 +1086,7 @@ StyledEditWindow::_InitWindow(uint32 encoding)
textBounds.OffsetTo(B_ORIGIN); textBounds.OffsetTo(B_ORIGIN);
textBounds.InsetBy(TEXT_INSET, TEXT_INSET); textBounds.InsetBy(TEXT_INSET, TEXT_INSET);
fTextView= new StyledEditView(viewFrame, textBounds, this); fTextView = new StyledEditView(viewFrame, textBounds, this);
fTextView->SetDoesUndo(true); fTextView->SetDoesUndo(true);
fTextView->SetStylable(true); fTextView->SetStylable(true);
fTextView->SetEncoding(encoding); fTextView->SetEncoding(encoding);
@@ -1211,8 +1211,8 @@ StyledEditWindow::_InitWindow(uint32 encoding)
fFontColorMenu->SetRadioMode(true); fFontColorMenu->SetRadioMode(true);
fFontMenu->AddItem(fFontColorMenu); fFontMenu->AddItem(fFontColorMenu);
fFontColorMenu->AddItem(fBlackItem = new BMenuItem(B_TRANSLATE("Black"), fFontColorMenu->AddItem(fBlackItem = new ColorMenuItem(B_TRANSLATE("Black"),
new BMessage(FONT_COLOR))); BLACK, new BMessage(FONT_COLOR)));
fBlackItem->SetMarked(true); fBlackItem->SetMarked(true);
fFontColorMenu->AddItem(fRedItem = new ColorMenuItem(B_TRANSLATE("Red"), fFontColorMenu->AddItem(fRedItem = new ColorMenuItem(B_TRANSLATE("Red"),
RED, new BMessage(FONT_COLOR))); RED, new BMessage(FONT_COLOR)));
@@ -1222,10 +1222,12 @@ StyledEditWindow::_InitWindow(uint32 encoding)
BLUE, new BMessage(FONT_COLOR))); BLUE, new BMessage(FONT_COLOR)));
fFontColorMenu->AddItem(fCyanItem = new ColorMenuItem(B_TRANSLATE("Cyan"), fFontColorMenu->AddItem(fCyanItem = new ColorMenuItem(B_TRANSLATE("Cyan"),
CYAN, new BMessage(FONT_COLOR))); CYAN, new BMessage(FONT_COLOR)));
fFontColorMenu->AddItem(fMagentaItem = new ColorMenuItem(B_TRANSLATE("Magenta"), fFontColorMenu->AddItem(fMagentaItem
MAGENTA, new BMessage(FONT_COLOR))); = new ColorMenuItem(B_TRANSLATE("Magenta"), MAGENTA,
fFontColorMenu->AddItem(fYellowItem = new ColorMenuItem(B_TRANSLATE("Yellow"), new BMessage(FONT_COLOR)));
YELLOW, new BMessage(FONT_COLOR))); fFontColorMenu->AddItem(fYellowItem
= new ColorMenuItem(B_TRANSLATE("Yellow"), YELLOW,
new BMessage(FONT_COLOR)));
fFontMenu->AddSeparatorItem(); fFontMenu->AddSeparatorItem();
// "Bold" & "Italic" menu items // "Bold" & "Italic" menu items