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/TextControl.h hrev48527
10 * src/kits/interface/TextControl.cpp hrev48527
18 \brief Provides the BTextControl class.
26 \brief Displays a labeled text view control.
33 \fn BTextControl::BTextControl(BRect frame, const char* name, const char* label,
34 const char* text, BMessage* message, uint32 resizeMask, uint32 flags)
35 \brief Creates a new BTextControl object.
37 \param frame The frame rectangle of the control.
38 \param name The (internal) name of the control.
39 \param label The control's \a label text.
40 \param text The initial \a text content of the control.
41 \param message The \a message to send to the control's target in response
43 \param resizeMask Resizing mask, passed to BView.
44 \param flags \a flags passed to BView.
51 \fn BTextControl::BTextControl(const char* name, const char* label,
52 const char* text, BMessage* message, uint32 flags)
53 \brief Creates a new BTextControl object for use in a BLayout.
55 \param name The name of the object.
56 \param label The control's \a label text.
57 \param text The initial \a text content of the control.
58 \param message The \a message to send to the control's target in response
60 \param flags \a flags passed to BView.
67 \fn BTextControl::BTextControl(const char* label, const char* text,
69 \brief Creates a new BTextControl object, dynamic layout version.
71 \param label The control's \a label text.
72 \param text The initial \a text content of the control.
73 \param message The \a message to send to the control's target in response
81 \fn BTextControl::BTextControl(BMessage* archive)
82 \brief Creates a BTextControl object from the passed in \a archive.
84 \param archive The BMessage object from which the object is created.
91 \fn BTextControl::~BTextControl()
92 \brief Frees the memory allocated and destroys the object.
107 \fn BArchivable* BTextControl::Instantiate(BMessage* archive)
108 \brief Instantiates a BTextControl object from the passed in \a archive.
110 \param archive The BMessage object that the object is created from.
112 \return A new BTextControl object as a BArchivable.
119 \fn status_t BTextControl::Archive(BMessage* data, bool deep) const
120 \brief Archives the object into the \a data message.
122 - The label is stored in \c _a_label
123 - The text is stored in \c _a_text
124 - The current divider position is stored in \c _divide
125 (ignored in the BLayout version)
126 - The modification message is stored in \c _mod_msg
128 \param data A pointer to the BMessage object to archive the object into.
129 \param deep Whether or not to archive child controls as well.
131 \return A status code, \c B_OK if everything went well or an error code
133 \retval B_OK The object was archived.
134 \retval B_NO_MEMORY Ran out of memory while archiving the object.
141 \fn status_t BTextControl::AllArchived(BMessage* into) const
142 \brief Hook method called when all views have been archived.
144 \copydetails BView::AllArchived()
149 \fn status_t BTextControl::AllUnarchived(const BMessage* from)
150 \brief Hook method called when all views have been unarchived.
152 \copydetails BView::AllUnarchived()
168 \fn void BTextControl::AllAttached()
169 \brief Similar to AttachedToWindow() but this method is triggered after
170 all child views have already been attached to a window.
177 \fn void BTextControl::AllDetached()
178 \brief Similar to AttachedToWindow() but this method is triggered after
179 all child views have already been detached from a window.
186 \fn void BTextControl::AttachedToWindow()
187 \brief Sets the font color to \c B_DOCUMENT_TEXT_COLOR and the view and
188 low colors to \c B_DOCUMENT_BACKGROUND_COLOR.
190 If the control is disabled, the font, view, and low colors are set to
191 \c B_PANEL_BACKGROUND_COLOR is tinted to show a disabled text color and
199 \fn void BTextControl::DetachedFromWindow()
200 \brief Hook method called when the object is detached from a window.
207 \fn void BTextControl::Draw(BRect updateRect)
208 \brief Hook method called to draw the contents of the text control.
210 \param updateRect The rectangular area to draw.
217 \fn void BTextControl::FrameMoved(BPoint newPosition)
218 \brief Hook method called when the control position is moved.
220 \param newPosition The point of the top left corner of the frame
221 that the view has been moved to.
228 \fn void BTextControl::FrameResized(float newWidth, float newHeight)
229 \brief Hook method that is called when the control position is resized.
231 This method updates only the parts of the frame that changed.
233 \param newWidth The new width of the control.
234 \param newHeight The new height of the control.
241 \fn status_t BTextControl::Invoke(BMessage* message)
242 \brief Sends a copy of the model \a message to the designated target.
244 \copydetails BControl::Invoke()
249 \fn void BTextControl::LayoutInvalidated(bool descendants)
250 \brief Hook method called when the layout is invalidated.
252 \param descendants Whether or not child views have also been invalidated.
259 \fn void BTextControl::MessageReceived(BMessage* message)
260 \brief Handle \a message received by the associated looper.
262 \copydetails BView::MessageReceived()
267 \fn void BTextControl::MouseDown(BPoint where)
268 \brief Hook method that is called when a mouse text control is pushed down while
269 the cursor is contained in the control.
271 Focuses the text control.
278 \fn void BTextControl::MouseMoved(BPoint where, uint32 code,
279 const BMessage* dragMessage)
280 \brief Hook method called when the mouse is moved.
282 \copydetails BControl::MouseMoved()
287 \fn void BTextControl::MouseUp(BPoint where)
288 \brief Hook method called when a mouse button is released.
290 \copydetails BControl::MouseUp()
295 \fn void BTextControl::WindowActivated(bool active)
296 \brief Hook method that is called when the window becomes the active window
297 or gives up that status.
299 Redraw focus indicator and notify the text view.
301 \copydetails BView::WindowActivated()
309 \fn void BTextControl::SetText(const char* text)
310 \brief Sets the text displayed by the BTextControl.
317 \fn const char* BTextControl::Text() const
318 \brief Returns the text displayed by the BTextControl.
325 \fn void BTextControl::MarkAsInvalid(bool invalid)
326 \brief Sets or removes the invalid flag.
333 \fn void BTextControl::SetValue(int32 value)
334 \brief Calls BControl::SetValue(). This isn't particularly useful.
336 \copydetails BControl::SetValue()
341 \fn BTextView* BTextControl::TextView() const
342 \brief Returns a pointer to the TextView object.
349 \fn void BTextControl::SetModificationMessage(BMessage* message)
350 \brief Assigns \a message to the control, freeing the previously
353 Passing NULL deletes the current modification message without replacing it.
360 \fn BMessage* BTextControl::ModificationMessage() const
361 \brief Returns the control's modification message.
366 \fn void BTextControl::SetAlignment(alignment labelAlignment,
367 alignment textAlignment)
368 \brief Set the alignment of the label and the text within the control.
370 The default is \c B_ALIGN_LEFT for both label and text.
377 \fn void BTextControl::GetAlignment(alignment* _label,
378 alignment* _text) const
379 \brief Fills out the label and text alignments into \a _label and \a text.
386 \fn void BTextControl::SetDivider(float position)
387 \brief Sets the horizontal \a position of the divider that separates the
388 label from the text view.
390 \remark It is not recommended to use this method for text control that are
391 part of a BLayout. Instead split the label and text view into
392 separate layout items using CreateLabelLayoutItem() and
393 CreateTextViewLayoutItem(). This allows you to have better control
394 over the position of the label and text view portions of your
397 \param position The divider \a position to set, should be an integral value.
404 \fn float BTextControl::Divider() const
405 \brief Returns the current divider position.
412 \fn void BTextControl::MakeFocus(bool focus)
413 \brief Passes MakeFocus() to the child BTextView.
420 \fn void BTextControl::SetEnabled(bool enable)
421 \brief Enables or disables the text control.
423 \param enable \c true to enable the control, \c false to disable it.
430 \fn void BTextControl::GetPreferredSize(float* _width, float* _height)
431 \brief Fills out \a _width and \a _height with the optimal width and
432 height of the text control to display the label and the text
440 \fn void BTextControl::ResizeToPreferred()
441 \brief Resizes the text control to its preferred size, keeping its left
442 and top sides constant while adjusting the width and height of
445 \warning It is not recommended to use this method for text control that
446 are part of a BLayout.
453 \fn void BTextControl::SetFlags(uint32 flags)
454 \brief Sets the control flags according to the \a flags mask.
456 Passes the \c B_NAVIGABLE to the BTextView.
463 \fn BHandler* BTextControl::ResolveSpecifier(BMessage* message, int32 index,
464 BMessage* specifier, int32 what, const char* property)
465 \copydoc BHandler::ResolveSpecifier()
470 \fn status_t BTextControl::GetSupportedSuites(BMessage* data)
471 \copydoc BHandler::GetSupportedSuites()
476 \fn BSize BTextControl::MinSize()
477 \brief Returns the text control's minimum size.
479 \return The text control's minimum size as a BSize.
486 \fn BSize BTextControl::MaxSize()
487 \brief Returns the text control's maximum size.
489 \return The text control's maximum size as a BSize.
496 \fn BSize BTextControl::PreferredSize()
497 \brief Returns the text control's preferred size.
499 \return The text control's preferred size as a BSize.
506 \fn BAlignment BTextControl::LayoutAlignment()
507 \brief Returns the alignment used by this control in a layout.
515 \fn BLayoutItem* BTextControl::CreateLabelLayoutItem()
516 \brief Creates a label layout item and returns a pointer to it
517 (Layout constructor only).
519 \sa CreateTextViewLayoutItem()
526 \fn BLayoutItem* BTextControl::CreateTextViewLayoutItem()
527 \brief Creates a text view layout item and returns a pointer to it.
529 \sa CreateLabelLayoutItem()
536 \fn void BTextControl::DoLayout()
537 \brief Layout view within the layout context.
539 \remark This is only meaningful if the view is part of a BLayout.
546 status_t BTextControl::SetIcon(const BBitmap* icon, uint32 flags)
547 \copydoc BControl::SetIcon()