xref: /haiku/src/apps/serialconnect/CustomRateWindow.cpp (revision 1f52c921e27aa442370e1bd4adc021acf2b78b64)
1 /*
2  * Copyright 2016, Adrien Destugues, pulkomandy@pulkomandy.tk
3  * Distributed under terms of the MIT license.
4  */
5 
6 
7 #include "CustomRateWindow.h"
8 
9 #include "SerialApp.h"
10 
11 #include <Button.h>
12 #include <Catalog.h>
13 #include <GroupLayoutBuilder.h>
14 #include <Spinner.h>
15 
16 
17 #define B_TRANSLATION_CONTEXT "Custom baudrate window"
18 
19 
20 static const uint32 kOkButtonMsg = 'ok';
21 
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)
26 {
27 	BGroupLayout* layout = new BGroupLayout(B_HORIZONTAL);
28 	SetLayout(layout);
29 
30 	BGroupView* root = new BGroupView(B_VERTICAL);
31 	AddChild(root);
32 
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();
46 
47 	fSpinner->SetMinValue(50);
48 	fSpinner->SetMaxValue(3000000);
49 	fSpinner->SetValue(baudrate);
50 
51 	CenterOnScreen();
52 }
53 
54 
55 void
56 CustomRateWindow::MessageReceived(BMessage* message)
57 {
58 	if (message->what == kOkButtonMsg)
59 	{
60 		BMessage* settings = new BMessage(kMsgSettings);
61 		settings->AddInt32("baudrate", fSpinner->Value());
62 		be_app->PostMessage(settings);
63 		Quit();
64 		return;
65 	}
66 
67 	BWindow::MessageReceived(message);
68 }
69