diff --git a/src/apps/stylededit/Constants.h b/src/apps/stylededit/Constants.h index 2879620851..b1526d665b 100644 --- a/src/apps/stylededit/Constants.h +++ b/src/apps/stylededit/Constants.h @@ -42,6 +42,7 @@ const uint32 MSG_REPLACE ='msre'; const uint32 MSG_REPLACE_ALL ='mrea'; //"Font"-menu const uint32 FONT_SIZE ='FMsi'; +const uint32 FONT_FAMILY ='FFch'; const uint32 FONT_STYLE ='FSch'; const uint32 FONT_COLOR ='Fcol'; diff --git a/src/apps/stylededit/StyledEditView.cpp b/src/apps/stylededit/StyledEditView.cpp index 90d4b8823e..ac6eab9850 100644 --- a/src/apps/stylededit/StyledEditView.cpp +++ b/src/apps/stylededit/StyledEditView.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include @@ -25,13 +26,29 @@ StyledEditView::FrameResized(float width, float height) { BTextView::FrameResized(width, height); - BRect textRect; - textRect = Bounds(); - textRect.OffsetTo(B_ORIGIN); - textRect.InsetBy(TEXT_INSET,TEXT_INSET); - if (DoesWordWrap() || (textRect.Width() > TextRect().Width())) { + if (DoesWordWrap()) { + BRect textRect; + textRect = Bounds(); + textRect.OffsetTo(B_ORIGIN); + textRect.InsetBy(TEXT_INSET,TEXT_INSET); 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 @@ -56,8 +73,16 @@ StyledEditView::GetStyledText(BPositionIO * stream) if (bytesRead > 0) { 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; return result; } diff --git a/src/apps/stylededit/StyledEditWindow.cpp b/src/apps/stylededit/StyledEditWindow.cpp index dd5284fe10..b12d87d339 100644 --- a/src/apps/stylededit/StyledEditWindow.cpp +++ b/src/apps/stylededit/StyledEditWindow.cpp @@ -235,6 +235,9 @@ StyledEditWindow::InitWindow() menu->AddSeparatorItem(); //Available fonts + font_family plain_family; + font_style plain_style; + be_plain_font->GetFamilyAndStyle(&plain_family,&plain_style); int32 numFamilies = count_font_families(); for ( int32 i = 0; i < numFamilies; i++ ) { @@ -242,16 +245,19 @@ StyledEditWindow::InitWindow() if ( get_font_family ( i, &localfamily ) == B_OK ) { subMenu=new BMenu(localfamily); subMenu->SetRadioMode(true); - menu->AddItem(subMenu); - menu->SetRadioMode(true); + menu->AddItem(menuItem = new BMenuItem(subMenu, new BMessage(FONT_FAMILY))); + if (!strcmp(plain_family,localfamily)) { + menuItem->SetMarked(true); + } int32 numStyles=count_font_styles(localfamily); for(int32 j = 0;jAddItem(menuItem= new BMenuItem(style, fontMessage= new BMessage(FONT_STYLE))); - fontMessage->AddString("FontFamily", localfamily); - fontMessage->AddString("FontStyle", style); + subMenu->AddItem(menuItem = new BMenuItem(style, new BMessage(FONT_STYLE))); + if (!strcmp(plain_style,style)) { + menuItem->SetMarked(true); + } } } } @@ -277,7 +283,7 @@ StyledEditWindow::InitWindow() fSavePanel = 0; // build lazily } /***StyledEditWindow::Initwindow()***/ - + void StyledEditWindow::MessageReceived(BMessage *message) { @@ -424,11 +430,31 @@ StyledEditWindow::MessageReceived(BMessage *message) SetFontSize(fontSize); } break; + case FONT_FAMILY: + { + const char * fontFamily = 0, * fontStyle = 0; + void * ptr; + if (message->FindPointer("source",&ptr) == B_OK) { + fontFamily = static_cast(ptr)->Label(); + } + SetFontStyle(fontFamily, fontStyle); + } + break; case FONT_STYLE: { - const char *fontFamily,*fontStyle; - message->FindString("FontFamily",&fontFamily); - message->FindString("FontStyle",&fontStyle); + const char * fontFamily = 0, * fontStyle = 0; + void * ptr; + if (message->FindPointer("source",&ptr) == B_OK) { + BMenuItem * item = static_cast(ptr); + fontStyle = item->Label(); + BMenu * menu = item->Menu(); + if (menu != 0) { + BMenuItem * superitem = menu->Superitem(); + if (superitem != 0) { + fontFamily = superitem->Label(); + } + } + } SetFontStyle(fontFamily, fontStyle); } break; @@ -446,25 +472,50 @@ StyledEditWindow::MessageReceived(BMessage *message) case ALIGN_LEFT: fTextView->SetAlignment(B_ALIGN_LEFT); fClean = false; + fUndoCleans = false; + fRedoCleans = false; fRevertItem->SetEnabled(fSaveMessage != NULL); fSaveItem->SetEnabled(true); + fUndoItem->SetLabel("Can't Undo"); + fUndoItem->SetEnabled(false); + fCanUndo = false; + fCanRedo = false; break; case ALIGN_CENTER: fTextView->SetAlignment(B_ALIGN_CENTER); fClean = false; + fUndoCleans = false; + fRedoCleans = false; fRevertItem->SetEnabled(fSaveMessage != NULL); fSaveItem->SetEnabled(true); + fUndoItem->SetLabel("Can't Undo"); + fUndoItem->SetEnabled(false); + fCanUndo = false; + fCanRedo = false; break; case ALIGN_RIGHT: fTextView->SetAlignment(B_ALIGN_RIGHT); fClean = false; + fUndoCleans = false; + fRedoCleans = false; fRevertItem->SetEnabled(fSaveMessage != NULL); fSaveItem->SetEnabled(true); + fUndoItem->SetLabel("Can't Undo"); + fUndoItem->SetEnabled(false); + fCanUndo = false; + fCanRedo = false; break; case WRAP_LINES: if (fTextView->DoesWordWrap()) { fTextView->SetWordWrap(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 { fTextView->SetWordWrap(true); fWrapItem->SetMarked(true); @@ -475,8 +526,14 @@ StyledEditWindow::MessageReceived(BMessage *message) fTextView->SetTextRect(textRect); } fClean = false; + fUndoCleans = false; + fRedoCleans = false; fRevertItem->SetEnabled(fSaveMessage != NULL); fSaveItem->SetEnabled(true); + fUndoItem->SetLabel("Can't Undo"); + fUndoItem->SetEnabled(false); + fCanUndo = false; + fCanRedo = false; break; case ENABLE_ITEMS: { fCutItem->SetEnabled(true); @@ -1088,13 +1145,29 @@ StyledEditWindow::SetFontStyle(const char *fontFamily, const char *fontStyle) BFont font; uint32 sameProperties; + // find out what the old font was + font_family oldFamily; + font_style oldStyle; 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); fTextView->SetFontAndColor(&font); - BMenuItem *superItem; - superItem= fMenuBar->FindItem(fontFamily); - superItem->SetMarked(true); + BMenuItem * superItem; + superItem = fMenuBar->FindItem(fontFamily); + if (superItem != 0) { + superItem->SetMarked(true); + } + fClean = false; fUndoCleans = false; fRedoCleans = false;