vfs: check userland buffers before reading them.
[haiku.git] / src / apps / serialconnect / CustomRateWindow.cpp
blob53eb5e422c98eba3f8a7b90e9302acf4db622d92
1 /*
2 * Copyright 2016, Adrien Destugues, pulkomandy@pulkomandy.tk
3 * Distributed under terms of the MIT license.
4 */
7 #include "CustomRateWindow.h"
9 #include "SerialApp.h"
11 #include <Button.h>
12 #include <Catalog.h>
13 #include <GroupLayoutBuilder.h>
14 #include <Spinner.h>
17 #define B_TRANSLATION_CONTEXT "Custom baudrate window"
20 static const uint32 kOkButtonMsg = 'ok';
22 CustomRateWindow::CustomRateWindow(int baudrate)
23 : BWindow(BRect(100, 100, 200, 150), B_TRANSLATE("Custom baudrate"),
24 B_FLOATING_WINDOW, B_NOT_ZOOMABLE | B_NOT_RESIZABLE | B_CLOSE_ON_ESCAPE
25 | B_AUTO_UPDATE_SIZE_LIMITS)
27 BGroupLayout* layout = new BGroupLayout(B_HORIZONTAL);
28 SetLayout(layout);
30 BGroupView* root = new BGroupView(B_VERTICAL);
31 AddChild(root);
33 BGroupLayoutBuilder(root)
34 .SetInsets(B_USE_WINDOW_SPACING, B_USE_WINDOW_SPACING,
35 B_USE_WINDOW_SPACING, B_USE_WINDOW_SPACING)
36 .AddGroup(B_HORIZONTAL)
37 .Add(fSpinner = new BSpinner("spin", B_TRANSLATE("Baudrate:"), NULL))
38 .End()
39 .AddGroup(B_HORIZONTAL)
40 .AddGlue()
41 .Add(new BButton("ok", B_TRANSLATE("Ok"), new BMessage(kOkButtonMsg)))
42 .Add(new BButton("cancel", B_TRANSLATE("Cancel"),
43 new BMessage(B_QUIT_REQUESTED)))
44 .End()
45 .End();
47 fSpinner->SetMinValue(50);
48 fSpinner->SetMaxValue(3000000);
49 fSpinner->SetValue(baudrate);
51 CenterOnScreen();
55 void
56 CustomRateWindow::MessageReceived(BMessage* message)
58 if (message->what == kOkButtonMsg)
60 BMessage* settings = new BMessage(kMsgSettings);
61 settings->AddInt32("baudrate", fSpinner->Value());
62 be_app->PostMessage(settings);
63 Quit();
64 return;
67 BWindow::MessageReceived(message);