1 | /*
|
---|
2 | * IdentityWindow.cpp
|
---|
3 | * Copyright (C) 2024 pulkomandy <pulkomandy@kitt>
|
---|
4 | *
|
---|
5 | * Distributed under terms of the MIT license.
|
---|
6 | */
|
---|
7 |
|
---|
8 | #include "IdentityWindow.h"
|
---|
9 |
|
---|
10 | #include <Application.h>
|
---|
11 | #include <Button.h>
|
---|
12 | #include <GridView.h>
|
---|
13 | #include <GroupLayout.h>
|
---|
14 | #include <LayoutBuilder.h>
|
---|
15 | #include <RadioButton.h>
|
---|
16 | #include <StringView.h>
|
---|
17 |
|
---|
18 | extern bool gGender;
|
---|
19 | extern BString gFirstName;
|
---|
20 | extern BString gLastName;
|
---|
21 |
|
---|
22 | IdentityWindow::IdentityWindow()
|
---|
23 | : BWindow(BRect(0, 0, 100, 100), "Who are you?", B_TITLED_WINDOW, B_NOT_RESIZABLE | B_AUTO_UPDATE_SIZE_LIMITS)
|
---|
24 | {
|
---|
25 | BGridView* gv = new BGridView();
|
---|
26 |
|
---|
27 | BMessage* male = new BMessage('GEND');
|
---|
28 | male->AddBool("gender", 0);
|
---|
29 |
|
---|
30 | BMessage* female = new BMessage('GEND');
|
---|
31 | female->AddBool("gender", 1);
|
---|
32 |
|
---|
33 | BTextControl* firstName = new BTextControl("first name", "First name", "", NULL);
|
---|
34 | BTextControl* lastName = new BTextControl("last name", "Last name", "", NULL);
|
---|
35 |
|
---|
36 | firstName->SetModificationMessage(new BMessage('FRST'));
|
---|
37 | lastName->SetModificationMessage(new BMessage('LAST'));
|
---|
38 |
|
---|
39 | BLayoutBuilder::Grid<>(gv, B_VERTICAL)
|
---|
40 | .SetInsets(B_USE_WINDOW_SPACING)
|
---|
41 | .AddTextControl(firstName, 0, 0, B_ALIGN_HORIZONTAL_UNSET, 1, 2)
|
---|
42 | .AddTextControl(lastName, 0, 1, B_ALIGN_HORIZONTAL_UNSET, 1, 2)
|
---|
43 | .Add(new BStringView("gender", "Gender"), 0, 2)
|
---|
44 | .Add(new BRadioButton("male", "Male", male), 1, 2)
|
---|
45 | .Add(new BRadioButton("female", "Female", female), 2, 2)
|
---|
46 | .Add(new BButton("ok", "Ok", new BMessage(B_QUIT_REQUESTED)), 1, 3)
|
---|
47 | .End();
|
---|
48 |
|
---|
49 | SetLayout(new BGroupLayout(B_VERTICAL));
|
---|
50 | AddChild(gv);
|
---|
51 | }
|
---|
52 |
|
---|
53 | bool IdentityWindow::QuitRequested()
|
---|
54 | {
|
---|
55 | be_app->PostMessage('STRT');
|
---|
56 |
|
---|
57 | return BWindow::QuitRequested();
|
---|
58 | }
|
---|
59 |
|
---|
60 | void IdentityWindow::MessageReceived(BMessage* message)
|
---|
61 | {
|
---|
62 | switch (message->what)
|
---|
63 | {
|
---|
64 | case 'GEND':
|
---|
65 | gGender = message->FindBool("gender");
|
---|
66 | return;
|
---|
67 | case 'FRST':
|
---|
68 | {
|
---|
69 | BTextControl* tc;
|
---|
70 | message->FindPointer("source", (void**)&tc);
|
---|
71 | gFirstName = tc->Text();
|
---|
72 | return;
|
---|
73 | }
|
---|
74 | case 'LAST':
|
---|
75 | {
|
---|
76 | BTextControl* tc;
|
---|
77 | message->FindPointer("source", (void**)&tc);
|
---|
78 | gLastName = tc->Text();
|
---|
79 | return;
|
---|
80 | }
|
---|
81 | }
|
---|
82 | BWindow::MessageReceived(message);
|
---|
83 | }
|
---|