2 * Copyright 2006 Haiku, Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
6 * Stephan Aßmus, superstippi@gmx.de
10 #include "InputTextView.h"
18 InputTextView::InputTextView(BRect frame
, const char* name
, BRect textRect
,
19 uint32 resizingMode
, uint32 flags
)
21 BTextView(frame
, name
, textRect
, resizingMode
, flags
),
28 InputTextView::~InputTextView()
34 InputTextView::MouseDown(BPoint where
)
36 // enforce the behaviour of a typical BTextControl
37 // only let the BTextView handle mouse up/down when
38 // it already had focus
39 fWasFocus
= IsFocus();
41 BTextView::MouseDown(where
);
44 if (BView
* view
= Parent()) {
45 view
->MouseDown(ConvertToParent(where
));
52 InputTextView::MouseUp(BPoint where
)
54 // enforce the behaviour of a typical BTextControl
55 // only let the BTextView handle mouse up/down when
56 // it already had focus
58 BTextView::MouseUp(where
);
63 InputTextView::KeyDown(const char* bytes
, int32 numBytes
)
69 // revert any typing changes
73 // skip BTextView implementation
74 BView::KeyDown(bytes
, numBytes
);
85 BTextView::KeyDown(bytes
, numBytes
);
90 InputTextView::MakeFocus(bool focus
)
92 if (focus
!= IsFocus()) {
93 if (BView
* view
= Parent())
95 BTextView::MakeFocus(focus
);
103 InputTextView::Invoke(BMessage
* message
)
109 BMessage
copy(*message
);
110 copy
.AddInt64("when", system_time());
111 copy
.AddPointer("source", (BView
*)this);
112 return BInvoker::Invoke(©
);
122 InputTextView::Select(int32 start
, int32 finish
)
124 BTextView::Select(start
, finish
);
131 InputTextView::InsertText(const char* inText
, int32 inLength
, int32 inOffset
,
132 const text_run_array
* inRuns
)
134 BTextView::InsertText(inText
, inLength
, inOffset
, inRuns
);
141 InputTextView::DeleteText(int32 fromOffset
, int32 toOffset
)
143 BTextView::DeleteText(fromOffset
, toOffset
);
153 InputTextView::_CheckTextRect()
155 // update text rect and make sure
156 // the cursor/selection is in view
157 BRect
textRect(TextRect());
158 float width
= ceilf(StringWidth(Text()) + 2.0);
159 if (textRect
.Width() < width
) {
160 textRect
.right
= textRect
.left
+ width
;
161 SetTextRect(textRect
);