lots of font related changes to reduce memory consumption and speed up initialization. also fixes for word wrapping screen width.
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@2062 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
0b46ec9848
commit
8f63353baf
@ -42,6 +42,7 @@ const uint32 MSG_REPLACE ='msre';
|
|||||||
const uint32 MSG_REPLACE_ALL ='mrea';
|
const uint32 MSG_REPLACE_ALL ='mrea';
|
||||||
//"Font"-menu
|
//"Font"-menu
|
||||||
const uint32 FONT_SIZE ='FMsi';
|
const uint32 FONT_SIZE ='FMsi';
|
||||||
|
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';
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#include <Message.h>
|
#include <Message.h>
|
||||||
#include <Messenger.h>
|
#include <Messenger.h>
|
||||||
#include <Rect.h>
|
#include <Rect.h>
|
||||||
|
#include <Region.h>
|
||||||
#include <TranslationUtils.h>
|
#include <TranslationUtils.h>
|
||||||
#include <Node.h>
|
#include <Node.h>
|
||||||
|
|
||||||
@ -25,13 +26,29 @@ StyledEditView::FrameResized(float width, float height)
|
|||||||
{
|
{
|
||||||
BTextView::FrameResized(width, height);
|
BTextView::FrameResized(width, height);
|
||||||
|
|
||||||
BRect textRect;
|
if (DoesWordWrap()) {
|
||||||
textRect = Bounds();
|
BRect textRect;
|
||||||
textRect.OffsetTo(B_ORIGIN);
|
textRect = Bounds();
|
||||||
textRect.InsetBy(TEXT_INSET,TEXT_INSET);
|
textRect.OffsetTo(B_ORIGIN);
|
||||||
if (DoesWordWrap() || (textRect.Width() > TextRect().Width())) {
|
textRect.InsetBy(TEXT_INSET,TEXT_INSET);
|
||||||
SetTextRect(textRect);
|
SetTextRect(textRect);
|
||||||
}
|
}
|
||||||
|
/* // I tried to do some sort of intelligent resize thing but it just doesn't work
|
||||||
|
// so we revert to the R5 stylededit yucky practice of setting the text rect to
|
||||||
|
// some crazy large number when word wrap is turned off :-(
|
||||||
|
else if (textRect.Width() > TextRect().Width()) {
|
||||||
|
SetTextRect(textRect);
|
||||||
|
}
|
||||||
|
|
||||||
|
BRegion region;
|
||||||
|
GetTextRegion(0,TextLength(),®ion);
|
||||||
|
float textWidth = region.Frame().Width();
|
||||||
|
if (textWidth < textRect.Width()) {
|
||||||
|
BRect textRect(B_ORIGIN,BPoint(textWidth+TEXT_INSET*2,Bounds().Height()));
|
||||||
|
textRect.InsetBy(TEXT_INSET,TEXT_INSET);
|
||||||
|
SetTextRect(textRect);
|
||||||
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
@ -56,8 +73,16 @@ StyledEditView::GetStyledText(BPositionIO * stream)
|
|||||||
if (bytesRead > 0) {
|
if (bytesRead > 0) {
|
||||||
SetWordWrap(wrap);
|
SetWordWrap(wrap);
|
||||||
}
|
}
|
||||||
|
if (wrap == false) {
|
||||||
|
BRect textRect;
|
||||||
|
textRect = Bounds();
|
||||||
|
textRect.OffsetTo(B_ORIGIN);
|
||||||
|
textRect.InsetBy(TEXT_INSET,TEXT_INSET);
|
||||||
|
// the width comes from stylededit R5. TODO: find a better way
|
||||||
|
textRect.SetRightBottom(BPoint(1500.0,textRect.RightBottom().y));
|
||||||
|
SetTextRect(textRect);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fSuppressChanges = false;
|
fSuppressChanges = false;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -235,6 +235,9 @@ StyledEditWindow::InitWindow()
|
|||||||
menu->AddSeparatorItem();
|
menu->AddSeparatorItem();
|
||||||
|
|
||||||
//Available fonts
|
//Available fonts
|
||||||
|
font_family plain_family;
|
||||||
|
font_style plain_style;
|
||||||
|
be_plain_font->GetFamilyAndStyle(&plain_family,&plain_style);
|
||||||
|
|
||||||
int32 numFamilies = count_font_families();
|
int32 numFamilies = count_font_families();
|
||||||
for ( int32 i = 0; i < numFamilies; i++ ) {
|
for ( int32 i = 0; i < numFamilies; i++ ) {
|
||||||
@ -242,16 +245,19 @@ StyledEditWindow::InitWindow()
|
|||||||
if ( get_font_family ( i, &localfamily ) == B_OK ) {
|
if ( get_font_family ( i, &localfamily ) == B_OK ) {
|
||||||
subMenu=new BMenu(localfamily);
|
subMenu=new BMenu(localfamily);
|
||||||
subMenu->SetRadioMode(true);
|
subMenu->SetRadioMode(true);
|
||||||
menu->AddItem(subMenu);
|
menu->AddItem(menuItem = new BMenuItem(subMenu, new BMessage(FONT_FAMILY)));
|
||||||
menu->SetRadioMode(true);
|
if (!strcmp(plain_family,localfamily)) {
|
||||||
|
menuItem->SetMarked(true);
|
||||||
|
}
|
||||||
int32 numStyles=count_font_styles(localfamily);
|
int32 numStyles=count_font_styles(localfamily);
|
||||||
for(int32 j = 0;j<numStyles;j++){
|
for(int32 j = 0;j<numStyles;j++){
|
||||||
font_style style;
|
font_style style;
|
||||||
uint32 flags;
|
uint32 flags;
|
||||||
if( get_font_style(localfamily,j,&style,&flags)==B_OK){
|
if( get_font_style(localfamily,j,&style,&flags)==B_OK){
|
||||||
subMenu->AddItem(menuItem= new BMenuItem(style, fontMessage= new BMessage(FONT_STYLE)));
|
subMenu->AddItem(menuItem = new BMenuItem(style, new BMessage(FONT_STYLE)));
|
||||||
fontMessage->AddString("FontFamily", localfamily);
|
if (!strcmp(plain_style,style)) {
|
||||||
fontMessage->AddString("FontStyle", style);
|
menuItem->SetMarked(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -277,7 +283,7 @@ StyledEditWindow::InitWindow()
|
|||||||
|
|
||||||
fSavePanel = 0; // build lazily
|
fSavePanel = 0; // build lazily
|
||||||
} /***StyledEditWindow::Initwindow()***/
|
} /***StyledEditWindow::Initwindow()***/
|
||||||
|
|
||||||
void
|
void
|
||||||
StyledEditWindow::MessageReceived(BMessage *message)
|
StyledEditWindow::MessageReceived(BMessage *message)
|
||||||
{
|
{
|
||||||
@ -424,11 +430,31 @@ StyledEditWindow::MessageReceived(BMessage *message)
|
|||||||
SetFontSize(fontSize);
|
SetFontSize(fontSize);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case FONT_FAMILY:
|
||||||
|
{
|
||||||
|
const char * fontFamily = 0, * fontStyle = 0;
|
||||||
|
void * ptr;
|
||||||
|
if (message->FindPointer("source",&ptr) == B_OK) {
|
||||||
|
fontFamily = static_cast<BMenuItem*>(ptr)->Label();
|
||||||
|
}
|
||||||
|
SetFontStyle(fontFamily, fontStyle);
|
||||||
|
}
|
||||||
|
break;
|
||||||
case FONT_STYLE:
|
case FONT_STYLE:
|
||||||
{
|
{
|
||||||
const char *fontFamily,*fontStyle;
|
const char * fontFamily = 0, * fontStyle = 0;
|
||||||
message->FindString("FontFamily",&fontFamily);
|
void * ptr;
|
||||||
message->FindString("FontStyle",&fontStyle);
|
if (message->FindPointer("source",&ptr) == B_OK) {
|
||||||
|
BMenuItem * item = static_cast<BMenuItem*>(ptr);
|
||||||
|
fontStyle = item->Label();
|
||||||
|
BMenu * menu = item->Menu();
|
||||||
|
if (menu != 0) {
|
||||||
|
BMenuItem * superitem = menu->Superitem();
|
||||||
|
if (superitem != 0) {
|
||||||
|
fontFamily = superitem->Label();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
SetFontStyle(fontFamily, fontStyle);
|
SetFontStyle(fontFamily, fontStyle);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -446,25 +472,50 @@ StyledEditWindow::MessageReceived(BMessage *message)
|
|||||||
case ALIGN_LEFT:
|
case ALIGN_LEFT:
|
||||||
fTextView->SetAlignment(B_ALIGN_LEFT);
|
fTextView->SetAlignment(B_ALIGN_LEFT);
|
||||||
fClean = false;
|
fClean = false;
|
||||||
|
fUndoCleans = false;
|
||||||
|
fRedoCleans = false;
|
||||||
fRevertItem->SetEnabled(fSaveMessage != NULL);
|
fRevertItem->SetEnabled(fSaveMessage != NULL);
|
||||||
fSaveItem->SetEnabled(true);
|
fSaveItem->SetEnabled(true);
|
||||||
|
fUndoItem->SetLabel("Can't Undo");
|
||||||
|
fUndoItem->SetEnabled(false);
|
||||||
|
fCanUndo = false;
|
||||||
|
fCanRedo = false;
|
||||||
break;
|
break;
|
||||||
case ALIGN_CENTER:
|
case ALIGN_CENTER:
|
||||||
fTextView->SetAlignment(B_ALIGN_CENTER);
|
fTextView->SetAlignment(B_ALIGN_CENTER);
|
||||||
fClean = false;
|
fClean = false;
|
||||||
|
fUndoCleans = false;
|
||||||
|
fRedoCleans = false;
|
||||||
fRevertItem->SetEnabled(fSaveMessage != NULL);
|
fRevertItem->SetEnabled(fSaveMessage != NULL);
|
||||||
fSaveItem->SetEnabled(true);
|
fSaveItem->SetEnabled(true);
|
||||||
|
fUndoItem->SetLabel("Can't Undo");
|
||||||
|
fUndoItem->SetEnabled(false);
|
||||||
|
fCanUndo = false;
|
||||||
|
fCanRedo = false;
|
||||||
break;
|
break;
|
||||||
case ALIGN_RIGHT:
|
case ALIGN_RIGHT:
|
||||||
fTextView->SetAlignment(B_ALIGN_RIGHT);
|
fTextView->SetAlignment(B_ALIGN_RIGHT);
|
||||||
fClean = false;
|
fClean = false;
|
||||||
|
fUndoCleans = false;
|
||||||
|
fRedoCleans = false;
|
||||||
fRevertItem->SetEnabled(fSaveMessage != NULL);
|
fRevertItem->SetEnabled(fSaveMessage != NULL);
|
||||||
fSaveItem->SetEnabled(true);
|
fSaveItem->SetEnabled(true);
|
||||||
|
fUndoItem->SetLabel("Can't Undo");
|
||||||
|
fUndoItem->SetEnabled(false);
|
||||||
|
fCanUndo = false;
|
||||||
|
fCanRedo = false;
|
||||||
break;
|
break;
|
||||||
case WRAP_LINES:
|
case WRAP_LINES:
|
||||||
if (fTextView->DoesWordWrap()) {
|
if (fTextView->DoesWordWrap()) {
|
||||||
fTextView->SetWordWrap(false);
|
fTextView->SetWordWrap(false);
|
||||||
fWrapItem->SetMarked(false);
|
fWrapItem->SetMarked(false);
|
||||||
|
BRect textRect;
|
||||||
|
textRect = fTextView->Bounds();
|
||||||
|
textRect.OffsetTo(B_ORIGIN);
|
||||||
|
textRect.InsetBy(TEXT_INSET,TEXT_INSET);
|
||||||
|
// the width comes from stylededit R5. TODO: find a better way
|
||||||
|
textRect.SetRightBottom(BPoint(1500.0,textRect.RightBottom().y));
|
||||||
|
fTextView->SetTextRect(textRect);
|
||||||
} else {
|
} else {
|
||||||
fTextView->SetWordWrap(true);
|
fTextView->SetWordWrap(true);
|
||||||
fWrapItem->SetMarked(true);
|
fWrapItem->SetMarked(true);
|
||||||
@ -475,8 +526,14 @@ StyledEditWindow::MessageReceived(BMessage *message)
|
|||||||
fTextView->SetTextRect(textRect);
|
fTextView->SetTextRect(textRect);
|
||||||
}
|
}
|
||||||
fClean = false;
|
fClean = false;
|
||||||
|
fUndoCleans = false;
|
||||||
|
fRedoCleans = false;
|
||||||
fRevertItem->SetEnabled(fSaveMessage != NULL);
|
fRevertItem->SetEnabled(fSaveMessage != NULL);
|
||||||
fSaveItem->SetEnabled(true);
|
fSaveItem->SetEnabled(true);
|
||||||
|
fUndoItem->SetLabel("Can't Undo");
|
||||||
|
fUndoItem->SetEnabled(false);
|
||||||
|
fCanUndo = false;
|
||||||
|
fCanRedo = false;
|
||||||
break;
|
break;
|
||||||
case ENABLE_ITEMS: {
|
case ENABLE_ITEMS: {
|
||||||
fCutItem->SetEnabled(true);
|
fCutItem->SetEnabled(true);
|
||||||
@ -1088,13 +1145,29 @@ StyledEditWindow::SetFontStyle(const char *fontFamily, const char *fontStyle)
|
|||||||
BFont font;
|
BFont font;
|
||||||
uint32 sameProperties;
|
uint32 sameProperties;
|
||||||
|
|
||||||
|
// find out what the old font was
|
||||||
|
font_family oldFamily;
|
||||||
|
font_style oldStyle;
|
||||||
fTextView->GetFontAndColor(&font,&sameProperties);
|
fTextView->GetFontAndColor(&font,&sameProperties);
|
||||||
|
font.GetFamilyAndStyle(&oldFamily,&oldStyle);
|
||||||
|
|
||||||
|
// clear that family's bit on the menu, if necessary
|
||||||
|
if (strcmp(oldFamily,fontFamily)) {
|
||||||
|
BMenuItem * oldItem = fMenuBar->FindItem(oldFamily);
|
||||||
|
if (oldItem != 0) {
|
||||||
|
oldItem->SetMarked(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
font.SetFamilyAndStyle(fontFamily,fontStyle);
|
font.SetFamilyAndStyle(fontFamily,fontStyle);
|
||||||
fTextView->SetFontAndColor(&font);
|
fTextView->SetFontAndColor(&font);
|
||||||
|
|
||||||
BMenuItem *superItem;
|
BMenuItem * superItem;
|
||||||
superItem= fMenuBar->FindItem(fontFamily);
|
superItem = fMenuBar->FindItem(fontFamily);
|
||||||
superItem->SetMarked(true);
|
if (superItem != 0) {
|
||||||
|
superItem->SetMarked(true);
|
||||||
|
}
|
||||||
|
|
||||||
fClean = false;
|
fClean = false;
|
||||||
fUndoCleans = false;
|
fUndoCleans = false;
|
||||||
fRedoCleans = false;
|
fRedoCleans = false;
|
||||||
|
Loading…
Reference in New Issue
Block a user