vfs: check userland buffers before reading them.
[haiku.git] / src / apps / haikudepot / textview / TextView.cpp
blobe4eb46c7e0a7a89886dea28b297ac7003301dd2a
1 /*
2 * Copyright 2013, Stephan Aßmus <superstippi@gmx.de>.
3 * All rights reserved. Distributed under the terms of the MIT License.
4 */
6 #include "TextView.h"
9 TextView::TextView(const char* name)
11 BView(name, B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE | B_FRAME_EVENTS)
13 BFont font;
14 GetFont(&font);
16 ::ParagraphStyle style;
17 style.SetLineSpacing(ceilf(font.Size() * 0.2));
19 SetParagraphStyle(style);
23 TextView::~TextView()
28 void
29 TextView::Draw(BRect updateRect)
31 FillRect(updateRect, B_SOLID_LOW);
33 fTextLayout.SetWidth(Bounds().Width());
34 fTextLayout.Draw(this, B_ORIGIN);
38 void
39 TextView::AttachedToWindow()
41 AdoptParentColors();
45 void
46 TextView::FrameResized(float width, float height)
48 fTextLayout.SetWidth(width);
52 BSize
53 TextView::MinSize()
55 return BSize(50.0f, 0.0f);
59 BSize
60 TextView::MaxSize()
62 return BSize(B_SIZE_UNLIMITED, B_SIZE_UNLIMITED);
66 BSize
67 TextView::PreferredSize()
69 return BSize(B_SIZE_UNLIMITED, B_SIZE_UNLIMITED);
73 bool
74 TextView::HasHeightForWidth()
76 return true;
80 void
81 TextView::GetHeightForWidth(float width, float* min, float* max,
82 float* preferred)
84 ParagraphLayout layout(fTextLayout);
85 layout.SetWidth(width);
87 float height = layout.Height() + 1;
89 if (min != NULL)
90 *min = height;
91 if (max != NULL)
92 *max = height;
93 if (preferred != NULL)
94 *preferred = height;
98 void
99 TextView::SetText(const BString& text)
101 fText.Clear();
103 CharacterStyle regularStyle;
104 fText.Append(TextSpan(text, regularStyle));
106 fTextLayout.SetParagraph(fText);
108 InvalidateLayout();
109 Invalidate();
113 void
114 TextView::SetParagraphStyle(const ::ParagraphStyle& style)
116 fText.SetStyle(style);
117 fTextLayout.SetParagraph(fText);
119 InvalidateLayout();
120 Invalidate();