BTRFS: Implement BTree::Path and change _Find.
[haiku.git] / src / apps / packageinstaller / PackageTextViewer.cpp
blob6352d81fd81bcca2964ea1ac4c42e4a62fd36b9a
1 /*
2 * Copyright (c) 2007-2014, Haiku, Inc.
3 * Distributed under the terms of the MIT license.
5 * Author:
6 * Łukasz 'Sil2100' Zemczak <sil2100@vexillium.org>
7 * Stephan Aßmus <superstippi@gmx.de>
8 */
11 #include "PackageTextViewer.h"
13 #include <Button.h>
14 #include <Catalog.h>
15 #include <LayoutBuilder.h>
16 #include <Locale.h>
17 #include <ScrollView.h>
20 enum {
21 P_MSG_ACCEPT = 'pmac',
22 P_MSG_DECLINE
25 #undef B_TRANSLATION_CONTEXT
26 #define B_TRANSLATION_CONTEXT "PackageTextViewer"
29 PackageTextViewer::PackageTextViewer(const char *text, bool disclaimer)
31 BlockingWindow(BRect(125, 125, 675, 475), B_TRANSLATE("Disclaimer"),
32 B_AUTO_UPDATE_SIZE_LIMITS)
34 _InitView(text, disclaimer);
35 CenterOnScreen();
39 void
40 PackageTextViewer::MessageReceived(BMessage* message)
42 switch (message->what) {
43 case P_MSG_ACCEPT:
44 ReleaseSem(1);
45 break;
47 case P_MSG_DECLINE:
48 ReleaseSem(0);
49 break;
51 default:
52 BWindow::MessageReceived(message);
53 break;
58 // #pragma mark -
61 void
62 PackageTextViewer::_InitView(const char* text, bool disclaimer)
64 BTextView* textView = new BTextView("text_view");
65 textView->MakeEditable(false);
66 textView->MakeSelectable(true);
67 float margin = ceilf(be_plain_font->Size());
68 textView->SetInsets(margin, margin, margin, margin);
69 BScrollView* scrollView = new BScrollView("scroll_view", textView, 0, false,
70 true);
72 BButton* defaultButton;
74 if (disclaimer) {
75 defaultButton = new BButton("accept", B_TRANSLATE("Accept"),
76 new BMessage(P_MSG_ACCEPT));
78 BButton* decline = new BButton("decline", B_TRANSLATE("Decline"),
79 new BMessage(P_MSG_DECLINE));
81 BLayoutBuilder::Group<>(this, B_VERTICAL)
82 .Add(scrollView)
83 .AddGroup(B_HORIZONTAL)
84 .AddGlue()
85 .Add(defaultButton)
86 .Add(decline)
87 .End()
88 .SetInsets(B_USE_WINDOW_INSETS)
90 } else {
91 defaultButton = new BButton("accept", B_TRANSLATE("Continue"),
92 new BMessage(P_MSG_ACCEPT));
94 BLayoutBuilder::Group<>(this, B_VERTICAL)
95 .Add(scrollView)
96 .AddGroup(B_HORIZONTAL)
97 .AddGlue()
98 .Add(defaultButton)
99 .End()
100 .SetInsets(B_USE_WINDOW_INSETS)
104 defaultButton->MakeDefault(true);
106 textView->SetText(text);