Update StyledEdit to use document background color. Style fixes.
See ticket #5293 Colors_picture2.png
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -14,40 +14,41 @@
|
||||
#include <String.h>
|
||||
#include <TextView.h>
|
||||
|
||||
|
||||
class BFile;
|
||||
class BHandler;
|
||||
class BMessenger;
|
||||
class BPositionIO;
|
||||
|
||||
|
||||
class StyledEditView : public BTextView {
|
||||
public:
|
||||
public:
|
||||
StyledEditView(BRect viewframe, BRect textframe,
|
||||
BHandler* handler);
|
||||
virtual ~StyledEditView();
|
||||
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 FrameResized(float width, float height);
|
||||
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);
|
||||
status_t GetStyledText(BPositionIO* stream,
|
||||
void Reset();
|
||||
void SetSuppressChanges(bool suppressChanges);
|
||||
status_t GetStyledText(BPositionIO* stream,
|
||||
const char* forceEncoding = NULL);
|
||||
status_t WriteStyledEditFile(BFile* file);
|
||||
status_t WriteStyledEditFile(BFile* file);
|
||||
|
||||
void SetEncoding(uint32 encoding);
|
||||
uint32 GetEncoding() const;
|
||||
void SetEncoding(uint32 encoding);
|
||||
uint32 GetEncoding() const;
|
||||
|
||||
private:
|
||||
void _UpdateStatus();
|
||||
private:
|
||||
void _UpdateStatus();
|
||||
|
||||
BMessenger *fMessenger;
|
||||
bool fSuppressChanges;
|
||||
BString fEncoding;
|
||||
BMessenger* fMessenger;
|
||||
bool fSuppressChanges;
|
||||
BString fEncoding;
|
||||
};
|
||||
|
||||
#endif // STYLED_EDIT_VIEW_H
|
||||
|
||||
#endif // STYLED_EDIT_VIEW_H
|
||||
|
||||
@@ -598,9 +598,8 @@ StyledEditWindow::MenusBeginning()
|
||||
BMenu* menu = fCurrentFontItem->Submenu();
|
||||
if (menu != NULL) {
|
||||
BMenuItem* item = menu->FindMarked();
|
||||
if (item != NULL) {
|
||||
if (item != NULL)
|
||||
item->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) {
|
||||
@@ -1086,7 +1086,7 @@ StyledEditWindow::_InitWindow(uint32 encoding)
|
||||
textBounds.OffsetTo(B_ORIGIN);
|
||||
textBounds.InsetBy(TEXT_INSET, TEXT_INSET);
|
||||
|
||||
fTextView= new StyledEditView(viewFrame, textBounds, this);
|
||||
fTextView = new StyledEditView(viewFrame, textBounds, this);
|
||||
fTextView->SetDoesUndo(true);
|
||||
fTextView->SetStylable(true);
|
||||
fTextView->SetEncoding(encoding);
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user