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 virtual status_t SetIcon(const BBitmap* icon, uint32 flags = 0); 102 103 private: 104 // FBC padding and forbidden methods 105 virtual status_t Perform(perform_code d, void* arg); 106 107 virtual void _ReservedTextControl1(); 108 virtual void _ReservedTextControl2(); 109 virtual void _ReservedTextControl3(); 110 virtual void _ReservedTextControl4(); 111 112 BTextControl& operator=(const BTextControl& other); 113 114 private: 115 class LabelLayoutItem; 116 class TextViewLayoutItem; 117 struct LayoutData; 118 119 friend class _BTextInput_; 120 friend class LabelLayoutItem; 121 friend class TextViewLayoutItem; 122 123 void _CommitValue(); 124 void _UpdateTextViewColors(bool enabled); 125 void _InitData(const char* label, 126 const BMessage* archive = NULL); 127 void _InitText(const char* initialText, 128 const BMessage* archive = NULL); 129 void _ValidateLayout(); 130 void _LayoutTextView(); 131 void _UpdateFrame(); 132 133 void _ValidateLayoutData(); 134 135 private: 136 BPrivate::_BTextInput_* fText; 137 BMessage* fModificationMessage; 138 alignment fLabelAlign; 139 float fDivider; 140 141 LayoutData* fLayoutData; 142 143 uint32 _reserved[9]; 144 }; 145 146 #endif // _TEXT_CONTROL_H 147