1 /*
2 * Copyright (c) 2007-2014, Haiku, Inc.
3 * Distributed under the terms of the MIT license.
4 *
5 * Author:
6 * Łukasz 'Sil2100' Zemczak <sil2100@vexillium.org>
7 * Stephan Aßmus <superstippi@gmx.de>
8 */
9
10
11 #include "PackageTextViewer.h"
12
13 #include <Button.h>
14 #include <Catalog.h>
15 #include <LayoutBuilder.h>
16 #include <Locale.h>
17 #include <ScrollView.h>
18
19
20 enum {
21 P_MSG_ACCEPT = 'pmac',
22 P_MSG_DECLINE
23 };
24
25 #undef B_TRANSLATION_CONTEXT
26 #define B_TRANSLATION_CONTEXT "PackageTextViewer"
27
28
PackageTextViewer(const char * text,bool disclaimer)29 PackageTextViewer::PackageTextViewer(const char *text, bool disclaimer)
30 :
31 BlockingWindow(BRect(125, 125, 675, 475), B_TRANSLATE("Disclaimer"),
32 B_AUTO_UPDATE_SIZE_LIMITS)
33 {
34 _InitView(text, disclaimer);
35 CenterOnScreen();
36 }
37
38
39 void
MessageReceived(BMessage * message)40 PackageTextViewer::MessageReceived(BMessage* message)
41 {
42 switch (message->what) {
43 case P_MSG_ACCEPT:
44 ReleaseSem(1);
45 break;
46
47 case P_MSG_DECLINE:
48 ReleaseSem(0);
49 break;
50
51 default:
52 BWindow::MessageReceived(message);
53 break;
54 }
55 }
56
57
58 // #pragma mark -
59
60
61 void
_InitView(const char * text,bool disclaimer)62 PackageTextViewer::_InitView(const char* text, bool disclaimer)
63 {
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);
71
72 BButton* defaultButton;
73
74 if (disclaimer) {
75 defaultButton = new BButton("accept", B_TRANSLATE("Accept"),
76 new BMessage(P_MSG_ACCEPT));
77
78 BButton* decline = new BButton("decline", B_TRANSLATE("Decline"),
79 new BMessage(P_MSG_DECLINE));
80
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)
89 ;
90 } else {
91 defaultButton = new BButton("accept", B_TRANSLATE("Continue"),
92 new BMessage(P_MSG_ACCEPT));
93
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)
101 ;
102 }
103
104 defaultButton->MakeDefault(true);
105
106 textView->SetText(text);
107 }
108
109