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 virtual status_t AllArchived(BMessage* into) const; 40 virtual status_t AllUnarchived(const BMessage* from); 41 42 virtual void SetText(const char* text); 43 const char* Text() const; 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 enabled); 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 point); 78 virtual void MouseMoved(BPoint point, 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 91 virtual void InvalidateLayout(bool descendants = false); 92 93 BLayoutItem* CreateLabelLayoutItem(); 94 BLayoutItem* CreateTextViewLayoutItem(); 95 96 protected: 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