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