vfs: check userland buffers before reading them.
[haiku.git] / src / apps / resedit / InlineEditor.cpp
blobbc7313bff60eacfaf286cb3462613f5f5a05cf1b
1 /*
2 * Copyright (c) 2005-2010, Haiku, Inc.
3 * Distributed under the terms of the MIT license.
5 * Author:
6 * DarkWyrm <darkwyrm@gmail.com>
7 */
8 #include "InlineEditor.h"
10 #include <Handler.h>
11 #include <MessageFilter.h>
13 class EditFilter : public BMessageFilter
15 public:
16 EditFilter(BTextControl *textbox)
17 : BMessageFilter(B_PROGRAMMED_DELIVERY, B_ANY_SOURCE, B_KEY_DOWN)
19 fTextBox = textbox;
22 ~EditFilter(void)
26 filter_result Filter(BMessage *msg, BHandler **target)
28 int32 rawchar;
29 msg->FindInt32("raw_char", &rawchar);
31 if (rawchar == B_ESCAPE) {
32 BLooper *loop = (*target)->Looper();
33 if (loop) {
34 BMessenger msgr(loop);
35 msgr.SendMessage(B_QUIT_REQUESTED);
36 return B_SKIP_MESSAGE;
38 } else if (rawchar == B_ENTER) {
39 fTextBox->Invoke();
40 return B_SKIP_MESSAGE;
42 return B_DISPATCH_MESSAGE;
45 private:
46 BTextControl *fTextBox;
50 InlineEditor::InlineEditor(BMessenger target, const BRect &frame,
51 const char *text)
52 : BWindow(frame, "InlineEditor", B_NO_BORDER_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
53 B_ASYNCHRONOUS_CONTROLS),
54 fMessenger(target),
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);
59 AddChild(fTextBox);
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));
71 bool
72 InlineEditor::QuitRequested(void)
74 return true;
78 void
79 InlineEditor::SetMessage(BMessage *msg)
81 fCommand = msg ? msg->what : 0;
82 fTextBox->SetMessage(msg);
86 void
87 InlineEditor::MessageReceived(BMessage *msg)
89 if (msg->what == fCommand) {
90 fMessenger.SendMessage(msg);
91 PostMessage(B_QUIT_REQUESTED);
95 void
96 InlineEditor::WindowActivated(bool active)
98 if (!active)
99 PostMessage(B_QUIT_REQUESTED);