1 | #include <Application.h>
|
---|
2 | #include <Window.h>
|
---|
3 | #include <View.h>
|
---|
4 | #include <Screen.h>
|
---|
5 | #include <TextControl.h>
|
---|
6 | #include <Rect.h>
|
---|
7 |
|
---|
8 |
|
---|
9 | class EditWindow: public BWindow
|
---|
10 | {
|
---|
11 | private:
|
---|
12 | BView *rootView;
|
---|
13 | BTextControl *nameView, *typeView, *valueView;
|
---|
14 |
|
---|
15 | public:
|
---|
16 | EditWindow(BRect frame): BWindow(frame, "Edit field", B_TITLED_WINDOW, B_ASYNCHRONOUS_CONTROLS)
|
---|
17 | {
|
---|
18 | BRect rect, rect2;
|
---|
19 |
|
---|
20 | rect = frame.OffsetToCopy(B_ORIGIN);
|
---|
21 |
|
---|
22 | this->rootView = new BView(rect, "root", B_FOLLOW_ALL, 0);
|
---|
23 | rootView->SetViewUIColor(B_PANEL_BACKGROUND_COLOR);
|
---|
24 | this->AddChild(this->rootView);
|
---|
25 |
|
---|
26 | rect2 = rect; rect2.bottom = rect2.top;
|
---|
27 | this->nameView = new BTextControl(rect2.InsetByCopy(4, 4), "name", "Name: ", "", NULL, B_FOLLOW_LEFT_RIGHT);
|
---|
28 | this->nameView->SetDivider(48);
|
---|
29 | this->rootView->AddChild(this->nameView);
|
---|
30 | rect.top += this->nameView->Frame().Height() + 8;
|
---|
31 |
|
---|
32 | rect2 = rect; rect2.bottom = rect2.top;
|
---|
33 | this->typeView = new BTextControl(rect2.InsetByCopy(4, 4), "type", "Type: ", "", NULL, B_FOLLOW_LEFT_RIGHT);
|
---|
34 | this->typeView->SetDivider(48);
|
---|
35 | this->rootView->AddChild(this->typeView);
|
---|
36 | rect.top += this->typeView->Frame().Height() + 8;
|
---|
37 |
|
---|
38 | rect2 = rect; rect2.bottom = rect2.top;
|
---|
39 | this->valueView = new BTextControl(rect2.InsetByCopy(4, 4), "value", "Value: ", "", NULL, B_FOLLOW_LEFT_RIGHT);
|
---|
40 | this->valueView->SetDivider(48);
|
---|
41 | this->rootView->AddChild(this->valueView);
|
---|
42 | this->valueView->MakeFocus(true);
|
---|
43 | rect.top += this->valueView->Frame().Height() + 8;
|
---|
44 |
|
---|
45 | rect.right -= 256;
|
---|
46 |
|
---|
47 | ResizeBy(-rect.Width(), -rect.Height());
|
---|
48 | MoveBy(rect.Width()/2, rect.Height()/2);
|
---|
49 |
|
---|
50 | this->nameView->SetText("This is a test");
|
---|
51 | this->typeView->SetText("This is a test");
|
---|
52 | this->valueView->SetText("This is a test");
|
---|
53 | }
|
---|
54 |
|
---|
55 | void Quit()
|
---|
56 | {
|
---|
57 | be_app_messenger.SendMessage(B_QUIT_REQUESTED);
|
---|
58 | BWindow::Quit();
|
---|
59 | }
|
---|
60 |
|
---|
61 | };
|
---|
62 |
|
---|
63 |
|
---|
64 |
|
---|
65 | class TestApplication: public BApplication
|
---|
66 | {
|
---|
67 | private:
|
---|
68 | EditWindow *fWnd;
|
---|
69 | public:
|
---|
70 | TestApplication(): BApplication("application/x-vnd.Test-App")
|
---|
71 | {
|
---|
72 | }
|
---|
73 |
|
---|
74 | void ReadyToRun() {
|
---|
75 | fWnd = new EditWindow(BScreen().Frame());
|
---|
76 | fWnd->SetFlags(fWnd->Flags() | B_QUIT_ON_WINDOW_CLOSE);
|
---|
77 | fWnd->Show();
|
---|
78 | }
|
---|
79 | };
|
---|
80 |
|
---|
81 |
|
---|
82 | int main()
|
---|
83 | {
|
---|
84 | TestApplication app;
|
---|
85 | app.Run();
|
---|
86 | return 0;
|
---|
87 | }
|
---|