improved soft wrapping, now saves alignment and wrapping states

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@2061 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
shatty
2002-11-22 05:53:58 +00:00
parent fea5713c6d
commit 0b46ec9848
4 changed files with 171 additions and 79 deletions
+40 -6
View File
@@ -2,6 +2,7 @@
#include <Messenger.h>
#include <Rect.h>
#include <TranslationUtils.h>
#include <Node.h>
#include "StyledEditView.h"
#include "Constants.h"
@@ -24,12 +25,12 @@ 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);
BRect textRect;
textRect = Bounds();
textRect.OffsetTo(B_ORIGIN);
textRect.InsetBy(TEXT_INSET,TEXT_INSET);
if (DoesWordWrap() || (textRect.Width() > TextRect().Width())) {
SetTextRect(textRect);
}
}
@@ -39,10 +40,43 @@ StyledEditView::GetStyledText(BPositionIO * stream)
status_t result = B_OK;
fSuppressChanges = true;
result = BTranslationUtils::GetStyledText(stream, this, NULL);
BNode * node = dynamic_cast<BNode*>(stream);
if (node != 0) {
ssize_t bytesRead;
// restore alignment
alignment align;
bytesRead = node->ReadAttr("alignment",0,0,&align,sizeof(align));
if (bytesRead > 0) {
SetAlignment(align);
}
// restore wrapping
bool wrap;
bytesRead = node->ReadAttr("wrap",0,0,&wrap,sizeof(wrap));
if (bytesRead > 0) {
SetWordWrap(wrap);
}
}
fSuppressChanges = false;
return result;
}
status_t
StyledEditView::WriteStyledEditFile(BFile * file)
{
status_t result = B_OK;
result = BTranslationUtils::WriteStyledEditFile(this,file);
if (result != B_OK) {
return result;
}
alignment align = Alignment();
file->WriteAttr("alignment",B_INT32_TYPE,0,&align,sizeof(align));
bool wrap = DoesWordWrap();
file->WriteAttr("wrap",B_BOOL_TYPE,0,&wrap,sizeof(wrap));
return result;
}
void
StyledEditView::Reset()
{