2 * Copyright 2014 Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
6 * John Scipione, jscipione@gmail.com
9 * headers/os/interface/StringView.h hrev48439
10 * src/kits/interface/StringView.cpp hrev48439
18 \brief BStringView class definition.
26 \brief Draws a non-editable single-line text string,
27 most commonly used as a label.
34 \fn BStringView::BStringView(BRect frame, const char* name, const char* text,
35 uint32 resizingMode, uint32 flags)
36 \brief Creates a new BStringView object which displays the non-editable
37 \a text string in the plain system font (\c be_plain_font).
39 \param frame The frame rectangle to draw the string view into.
40 \param name The string view's \a name. Can be \c NULL.
41 \param text The string view's label \a text. Can be \c NULL.
42 \param resizingMode Sets the parameters by which the BStringView can be
43 resized. See BView for more information on resizing options.
44 \param flags The \a flags mask sets what notifications the BStringView can
45 receive. See BView for more information on \a flags.
46 \c B_FULL_UPDATE_ON_RESIZE is always set.
48 In order to prevent the string from being truncated the frame rectangle
49 must be large enough to display the entire string in the current font.
50 The string is drawn at the bottom of the frame rectangle and by default
51 is left-aligned, call SetAlignment() to set a different horizontal
54 You may also change the font variety used by calling SetFont().
64 \fn BStringView::BStringView(const char* name, const char* text, uint32 flags)
65 \brief Layout constructor.
67 \param name The string view's \a name. Can be \c NULL.
68 \param text The string view's label \a text. Can be \c NULL.
69 \param flags The \a flags mask sets what notifications the BStringView can
70 receive. See BView for more information on \a flags.
71 \c B_FULL_UPDATE_ON_RESIZE is always set.
73 The string is left-aligned by default. There are two ways to set the
74 horizontal alignment of the string view. The preferred method is to call
75 BLayoutItem::SetExplicitAlignment() or you may also call SetAlignment().
77 You may also change the font variety used by calling SetFont().
79 \see BLayoutItem::SetExplicitAlignment()
88 \fn BStringView::BStringView(BMessage* archive)
89 \brief Archive constructor.
91 \warning This method is usually not called directly. If you want to build
92 a string view from an archive message you should call
93 Instantiate() instead which can handle errors properly.
95 \param archive The message \a archive to construct the string view from.
102 \fn BStringView::~BStringView()
103 \brief Destructor method, frees the memory used by the string view.
118 \fn BArchivable* BStringView::Instantiate(BMessage* archive)
119 \brief Creates a new BStringView object from an \a archive message.
121 The string view's text, and alignment can be set using this method.
122 - The "_text" property is a \c B_STRING_TYPE containing the text of
124 - The "_align" property is a \c B_INT32_TYPE containing the string
125 view's alignment flag. This should be casted to an alignment type.
131 \return A newly created BStringView object or \c NULL if the message
132 doesn't contain an archived BStringView.
139 \fn status_t BStringView::Archive(BMessage* archive, bool deep) const
140 \brief Archives the the BStringView object into the \a archive message.
142 \param archive A pointer to the BMessage to archive the object into.
143 \param deep This parameter has no effect for this class.
145 \return A status code, \c B_OK if everything went well or an error code
147 \retval B_OK The object was archived successfully.
148 \retval B_NO_MEMORY Ran out of memory while archiving the object.
166 \fn void BStringView::AttachedToWindow()
167 \brief Hook method called when the BStringView is attached to a window.
169 The view color is set to either the parent's view color or
170 \c B_TRANSPARENT_COLOR if the string view isn't attached to a view.
172 \sa BView::AttachedToWindow()
179 \fn void BStringView::DetachedFromWindow()
180 \brief Hook method called when the BStringView is detached from a window.
182 \copydetails BView::DetachedFromWindow()
187 \fn void BStringView::AllAttached()
188 \brief Similar to AttachedToWindow() but this method is triggered after
189 all child views have already been attached to a window.
191 \copydetails BView::AllAttached()
196 \fn void BStringView::AllDetached()
197 \brief Similar to AttachedToWindow() but this method is triggered after
198 all child views have already been detached from a window.
200 \copydetails BView::AllDetached()
205 \fn void BStringView::Draw(BRect updateRect)
206 \brief Draws the area of the view that intersects \a updateRect.
208 \remark This is an hook method called by the Interface Kit, you don't have to
209 call it yourself. If you need to forcefully redraw the view consider
210 calling Invalidate() instead.
212 \param updateRect The rectangular area to be drawn.
221 \fn void BStringView::FrameMoved(BPoint newPosition)
222 \brief Hook method called when the string view is moved.
224 \copydetails BView::FrameMoved()
229 \fn void BStringView::FrameResized(float newWidth, float newHeight)
230 \brief Hook method called when the string view is resized.
232 \copydetails BView::FrameResized()
237 \fn void BStringView::MessageReceived(BMessage* message)
238 \brief Handle \a message received by the associated looper.
240 \copydetails BView::MessageReceived()
245 \fn void BStringView::MouseDown(BPoint where)
246 \brief Hook method called when a mouse button is pressed.
248 \copydetails BView::MouseDown()
253 \fn void BStringView::MouseMoved(BPoint where, uint32 code,
254 const BMessage* dragMessage)
255 \brief Hook method called when the mouse is moved.
257 \copydetails BView::MouseMoved()
262 \fn void BStringView::MouseUp(BPoint where)
263 \brief Hook method called when a mouse button is released.
265 \copydetails BView::MouseUp()
273 \fn void BStringView::MakeFocus(bool focus)
274 \brief Makes the string view the current focus view of the window or
275 gives up being the window's focus view.
277 \copydetails BView::MakeFocus()
282 \fn void BStringView::GetPreferredSize(float* _width, float* _height)
283 \brief Fills out the preferred width and height of the string view
284 into the \a _width and \a _height parameters respectively.
286 \copydetails BView::GetPreferredSize()
291 \fn BSize BStringView::MinSize()
292 \brief Returns the string view's minimum size.
294 \copydetails BView::MinSize()
299 \fn BSize BStringView::MaxSize()
300 \brief Returns the string view's maximum size.
302 \copydetails BView::MaxSize()
307 \fn BSize BStringView::PreferredSize()
308 \brief Returns the string view's preferred size.
310 \copydetails BView::PreferredSize()
315 \fn void BStringView::ResizeToPreferred()
316 \brief Resize the string view to its preferred size.
318 \copydetails BView::ResizeToPreferred()
323 \fn BAlignment BStringView::LayoutAlignment()
324 \brief Returns the alignment used by this view as part of a BLayout.
326 \return The alignment used by this view as a BAlignment.
341 \fn void BStringView::SetText(const char* text)
342 \brief Sets the \a text string displayed by the string view.
344 The \a text string is copied, BStringView does not take ownership
345 of the memory referenced by the pointer so you should free it yourself
346 afterwords. If a string has previously been set on the string view, the
347 memory used by the old string is freed before setting the new string.
349 \param text The \a text string to set.
356 \fn const char* BStringView::Text() const
357 \brief Returns the text currently set on the string view.
359 \returns The string view's text as a const char*.
369 \name Alignment methods
377 \fn void BStringView::SetAlignment(alignment flag)
378 \brief Sets the way text is aligned within the view's frame.
385 \remark For string views that are part of a BLayout consider
386 using BLayoutItem::SetExplicitAlignment() instead.
388 \param flag The text alignment to set.
395 \fn alignment BStringView::Alignment() const
396 \brief Returns the currently set text alignment flag.
398 \return The current alignment flag.
410 \fn BHandler* BStringView::ResolveSpecifier(BMessage* message, int32 index,
411 BMessage* specifier, int32 what, const char* property)
412 \copydoc BView::ResolveSpecifier()
417 \fn status_t BStringView::GetSupportedSuites(BMessage* message)
418 \copydoc BView::GetSupportedSuites()
423 \fn void BStringView::SetFont(const BFont* font, uint32 mask)
424 \brief Sets the font of the string view to \a font with the font
425 parameters set by \a mask.
427 \param font The \a font to set the string view to.
428 \param mask A \a mask indicating which properties of \a font to set.
430 \see BView::SetFont()
437 \fn void BStringView::LayoutInvalidated(bool descendants)
438 \brief Hook method called when the layout is invalidated.
440 The default implementation invalidates the cached preferred size.
442 \copydetails BView::LayoutInvalidated(bool descendants)
447 \fn status_t BStringView::Perform(perform_code code, void* _data)
448 \brief Perform some action. (Internal Method)