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