1 /* 2 * Copyright 2006-2015, Haiku, Inc. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef _TEXT_CONTROL_H 6 #define _TEXT_CONTROL_H 7 8 9 #include <Control.h> 10 #include <TextView.h> 11 12 13 class BLayoutItem; 14 namespace BPrivate { 15 class _BTextInput_; 16 } 17 18 19 class BTextControl : public BControl { 20 public: 21 BTextControl(BRect frame, const char* name, 22 const char* label, const char* initialText, 23 BMessage* message, 24 uint32 resizeMask = B_FOLLOW_LEFT_TOP, 25 uint32 flags = B_WILL_DRAW | B_NAVIGABLE); 26 BTextControl(const char* name, 27 const char* label, const char* initialText, 28 BMessage* message, 29 uint32 flags = B_WILL_DRAW | B_NAVIGABLE); 30 BTextControl(const char* label, 31 const char* initialText, 32 BMessage* message); 33 virtual ~BTextControl(); 34 35 BTextControl(BMessage* archive); 36 static BArchivable* Instantiate(BMessage* archive); 37 virtual status_t Archive(BMessage* archive, 38 bool deep = true) const; 39 40 virtual void SetText(const char* text); 41 const char* Text() const; 42 int32 TextLength() const; 43 void MarkAsInvalid(bool invalid); 44 45 virtual void SetValue(int32 value); 46 virtual status_t Invoke(BMessage* message = NULL); 47 48 BTextView* TextView() const; 49 50 virtual void SetModificationMessage(BMessage* message); 51 BMessage* ModificationMessage() const; 52 53 virtual void SetAlignment(alignment label, alignment text); 54 void GetAlignment(alignment* _label, 55 alignment* _text) const; 56 virtual void SetDivider(float position); 57 float Divider() const; 58 59 virtual void Draw(BRect updateRect); 60 virtual void MouseDown(BPoint where); 61 virtual void AttachedToWindow(); 62 virtual void MakeFocus(bool focus = true); 63 virtual void SetEnabled(bool enable); 64 virtual void FrameMoved(BPoint newPosition); 65 virtual void FrameResized(float newWidth, float newHeight); 66 virtual void WindowActivated(bool active); 67 68 virtual void GetPreferredSize(float* _width, 69 float* _height); 70 virtual void ResizeToPreferred(); 71 72 virtual void MessageReceived(BMessage* message); 73 virtual BHandler* ResolveSpecifier(BMessage* message, 74 int32 index, BMessage* specifier, 75 int32 what, const char* property); 76 77 virtual void MouseUp(BPoint where); 78 virtual void MouseMoved(BPoint where, uint32 transit, 79 const BMessage* dragMessage); 80 virtual void DetachedFromWindow(); 81 82 virtual void AllAttached(); 83 virtual void AllDetached(); 84 virtual status_t GetSupportedSuites(BMessage* data); 85 virtual void SetFlags(uint32 flags); 86 87 virtual BSize MinSize(); 88 virtual BSize MaxSize(); 89 virtual BSize PreferredSize(); 90 virtual BAlignment LayoutAlignment(); 91 92 BLayoutItem* CreateLabelLayoutItem(); 93 BLayoutItem* CreateTextViewLayoutItem(); 94 95 protected: 96 virtual status_t AllArchived(BMessage* into) const; 97 virtual status_t AllUnarchived(const BMessage* from); 98 99 virtual void LayoutInvalidated(bool descendants); 100 virtual void DoLayout(); 101 102 virtual status_t SetIcon(const BBitmap* icon, uint32 flags = 0); 103 104 private: 105 // FBC padding and forbidden methods 106 virtual status_t Perform(perform_code d, void* arg); 107 108 virtual void _ReservedTextControl1(); 109 virtual void _ReservedTextControl2(); 110 virtual void _ReservedTextControl3(); 111 virtual void _ReservedTextControl4(); 112 113 BTextControl& operator=(const BTextControl& other); 114 115 private: 116 class LabelLayoutItem; 117 class TextViewLayoutItem; 118 struct LayoutData; 119 120 friend class _BTextInput_; 121 friend class LabelLayoutItem; 122 friend class TextViewLayoutItem; 123 124 void _CommitValue(); 125 void _UpdateTextViewColors(bool enable); 126 void _InitData(const char* label, 127 const BMessage* archive = NULL); 128 void _InitText(const char* initialText, 129 const BMessage* archive = NULL); 130 void _ValidateLayout(); 131 void _LayoutTextView(); 132 void _UpdateFrame(); 133 134 void _ValidateLayoutData(); 135 136 private: 137 BPrivate::_BTextInput_* fText; 138 BMessage* fModificationMessage; 139 alignment fLabelAlign; 140 float fDivider; 141 142 LayoutData* fLayoutData; 143 uint32 fLook; 144 145 uint32 _reserved[8]; 146 }; 147 148 149 #endif // _TEXT_CONTROL_H 150