2 * Copyright (c) 2005-2010, Haiku, Inc.
3 * Distributed under the terms of the MIT license.
6 * DarkWyrm <darkwyrm@gmail.com>
8 #include "InlineEditor.h"
11 #include <MessageFilter.h>
13 class EditFilter
: public BMessageFilter
16 EditFilter(BTextControl
*textbox
)
17 : BMessageFilter(B_PROGRAMMED_DELIVERY
, B_ANY_SOURCE
, B_KEY_DOWN
)
26 filter_result
Filter(BMessage
*msg
, BHandler
**target
)
29 msg
->FindInt32("raw_char", &rawchar
);
31 if (rawchar
== B_ESCAPE
) {
32 BLooper
*loop
= (*target
)->Looper();
34 BMessenger
msgr(loop
);
35 msgr
.SendMessage(B_QUIT_REQUESTED
);
36 return B_SKIP_MESSAGE
;
38 } else if (rawchar
== B_ENTER
) {
40 return B_SKIP_MESSAGE
;
42 return B_DISPATCH_MESSAGE
;
46 BTextControl
*fTextBox
;
50 InlineEditor::InlineEditor(BMessenger target
, const BRect
&frame
,
52 : BWindow(frame
, "InlineEditor", B_NO_BORDER_WINDOW_LOOK
, B_NORMAL_WINDOW_FEEL
,
53 B_ASYNCHRONOUS_CONTROLS
),
55 fCommand(M_INLINE_TEXT
)
57 fTextBox
= new BTextControl(BRect(0, 0, 1, 1), "inlinebox", NULL
, text
,
58 new BMessage(fCommand
), B_FOLLOW_ALL
, B_WILL_DRAW
);
60 fTextBox
->SetDivider(0);
61 fTextBox
->MakeFocus(true);
63 fTextBox
->ResizeToPreferred();
64 fTextBox
->ResizeTo(Bounds().Width(), fTextBox
->Bounds().Height());
65 ResizeTo(Bounds().Width(), fTextBox
->Bounds().Height());
67 AddCommonFilter(new EditFilter(fTextBox
));
72 InlineEditor::QuitRequested(void)
79 InlineEditor::SetMessage(BMessage
*msg
)
81 fCommand
= msg
? msg
->what
: 0;
82 fTextBox
->SetMessage(msg
);
87 InlineEditor::MessageReceived(BMessage
*msg
)
89 if (msg
->what
== fCommand
) {
90 fMessenger
.SendMessage(msg
);
91 PostMessage(B_QUIT_REQUESTED
);
96 InlineEditor::WindowActivated(bool active
)
99 PostMessage(B_QUIT_REQUESTED
);