TextDocumentView::TextDocumentView(const char* name) : BView(name, B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE | B_FRAME_EVENTS | B_PULSE_NEEDED), fInsetLeft(0.0f), fInsetTop(0.0f), fInsetRight(0.0f), fInsetBottom(0.0f), fCaretBounds(), fSelectionEnabled(true), fShowCaret(false), fMouseDown(false) { fTextDocumentLayout.SetWidth(_TextLayoutWidth(Bounds().Width())); // Set default TextEditor SetTextEditor(TextEditorRef(new(std::nothrow) TextEditor(), true)); SetViewColor(B_TRANSPARENT_COLOR); SetLowColor(255, 255, 255, 255); }
RatePackageWindow::RatePackageWindow(BWindow* parent, BRect frame) : BWindow(frame, B_TRANSLATE_SYSTEM_NAME("Your rating"), B_FLOATING_WINDOW_LOOK, B_FLOATING_SUBSET_WINDOW_FEEL, B_ASYNCHRONOUS_CONTROLS | B_AUTO_UPDATE_SIZE_LIMITS), fRatingText() { AddToSubset(parent); CenterIn(parent->Frame()); TextDocumentView* textView = new TextDocumentView(); ScrollView* textScrollView = new ScrollView( "rating scroll view", textView); MarkupParser parser; fRatingText = parser.CreateDocumentFromMarkup( "Here is where you ''could'' type your awesome rating comment, " "if only this were already implemented."); textView->SetInsets(10.0f); textView->SetTextDocument(fRatingText); textView->SetTextEditor(TextEditorRef(new TextEditor(), true)); fSendButton = new BButton("send", B_TRANSLATE("Send"), new BMessage(MSG_SEND)); // Build layout BLayoutBuilder::Group<>(this, B_VERTICAL) .Add(textScrollView) .AddGroup(B_HORIZONTAL) .AddGlue() .Add(fSendButton) .End() .SetInsets(B_USE_DEFAULT_SPACING) ; }
TextDocumentView::~TextDocumentView() { // Don't forget to remove listeners SetTextEditor(TextEditorRef()); }
void TextDocumentTest::ReadyToRun() { BRect frame(50.0, 50.0, 749.0, 549.0); BWindow* window = new BWindow(frame, "Text document test", B_TITLED_WINDOW, B_QUIT_ON_WINDOW_CLOSE | B_AUTO_UPDATE_SIZE_LIMITS); TextDocumentView* documentView = new TextDocumentView("text document view"); BScrollView* scrollView = new BScrollView("text scroll view", documentView, false, true, B_NO_BORDER); BLayoutBuilder::Group<>(window, B_VERTICAL) .Add(scrollView) ; CharacterStyle regularStyle; float fontSize = regularStyle.Font().Size(); ParagraphStyle paragraphStyle; paragraphStyle.SetJustify(true); paragraphStyle.SetSpacingTop(ceilf(fontSize * 0.6f)); paragraphStyle.SetLineSpacing(ceilf(fontSize * 0.2f)); // CharacterStyle boldStyle(regularStyle); // boldStyle.SetBold(true); // // CharacterStyle italicStyle(regularStyle); // italicStyle.SetItalic(true); // // CharacterStyle italicAndBoldStyle(boldStyle); // italicAndBoldStyle.SetItalic(true); // // CharacterStyle bigStyle(regularStyle); // bigStyle.SetFontSize(24); // bigStyle.SetForegroundColor(255, 50, 50); // // TextDocumentRef document(new TextDocument(), true); // // Paragraph paragraph(paragraphStyle); // paragraph.Append(TextSpan("This is a", regularStyle)); // paragraph.Append(TextSpan(" test ", bigStyle)); // paragraph.Append(TextSpan("to see if ", regularStyle)); // paragraph.Append(TextSpan("different", boldStyle)); // paragraph.Append(TextSpan(" character styles already work.", regularStyle)); // document->Append(paragraph); // // paragraphStyle.SetSpacingTop(8.0f); // paragraphStyle.SetAlignment(ALIGN_CENTER); // paragraphStyle.SetJustify(false); // // paragraph = Paragraph(paragraphStyle); // paragraph.Append(TextSpan("Different alignment styles ", regularStyle)); // paragraph.Append(TextSpan("are", boldStyle)); // paragraph.Append(TextSpan(" supported as of now!", regularStyle)); // document->Append(paragraph); // // // Test a bullet list // paragraphStyle.SetSpacingTop(8.0f); // paragraphStyle.SetAlignment(ALIGN_LEFT); // paragraphStyle.SetJustify(true); // paragraphStyle.SetBullet(Bullet("•", 12.0f)); // paragraphStyle.SetLineInset(10.0f); // // paragraph = Paragraph(paragraphStyle); // paragraph.Append(TextSpan("Even bullet lists are supported.", regularStyle)); // document->Append(paragraph); // // paragraph = Paragraph(paragraphStyle); // paragraph.Append(TextSpan("The wrapping in ", regularStyle)); // paragraph.Append(TextSpan("this", italicStyle)); // // paragraph.Append(TextSpan(" bullet item should look visually " // "pleasing. And ", regularStyle)); // paragraph.Append(TextSpan("why", italicAndBoldStyle)); // paragraph.Append(TextSpan(" should it not?", regularStyle)); // document->Append(paragraph); MarkupParser parser(regularStyle, paragraphStyle); TextDocumentRef document = parser.CreateDocumentFromMarkup( "== Text document test ==\n" "This is a test to see if '''different''' " "character styles already work.\n" "Different alignment styles '''are''' supported as of now!\n" " * Even bullet lists are supported.\n" " * The wrapping in ''this'' bullet item should look visually " "pleasing. And ''why'' should it not?\n" ); documentView->SetTextDocument(document); documentView->SetTextEditor(TextEditorRef(new TextEditor(), true)); documentView->MakeFocus(); window->Show(); }