xref: /haiku/src/apps/packageinstaller/PackageTextViewer.cpp (revision 65688206345d2a67d38526281db9a0f50941b508)
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 <Locale.h>
16 #include <ScrollView.h>
17 
18 #include <LayoutBuilder.h>
19 
20 
21 enum {
22 	P_MSG_ACCEPT = 'pmac',
23 	P_MSG_DECLINE
24 };
25 
26 #undef B_TRANSLATION_CONTEXT
27 #define B_TRANSLATION_CONTEXT "PackageTextViewer"
28 
29 
30 PackageTextViewer::PackageTextViewer(const char *text, bool disclaimer)
31 	:
32 	BlockingWindow(BRect(125, 125, 675, 475), B_TRANSLATE("Disclaimer"),
33 		B_AUTO_UPDATE_SIZE_LIMITS)
34 {
35 	_InitView(text, disclaimer);
36 	CenterOnScreen();
37 }
38 
39 
40 void
41 PackageTextViewer::MessageReceived(BMessage* message)
42 {
43 	switch (message->what) {
44 		case P_MSG_ACCEPT:
45 			ReleaseSem(1);
46 			break;
47 
48 		case P_MSG_DECLINE:
49 			ReleaseSem(0);
50 			break;
51 
52 		default:
53 			BWindow::MessageReceived(message);
54 			break;
55 	}
56 }
57 
58 
59 // #pragma mark -
60 
61 
62 void
63 PackageTextViewer::_InitView(const char* text, bool disclaimer)
64 {
65 	BTextView* textView = new BTextView("text_view");
66 	textView->MakeEditable(false);
67 	textView->MakeSelectable(true);
68 	float margin = ceilf(be_plain_font->Size());
69 	textView->SetInsets(margin, margin, margin, margin);
70 	BScrollView* scrollView = new BScrollView("scroll_view", textView, 0, false,
71 		true);
72 
73 	BButton* defaultButton;
74 
75 	if (disclaimer) {
76 		defaultButton = new BButton("accept", B_TRANSLATE("Accept"),
77 			new BMessage(P_MSG_ACCEPT));
78 
79 		BButton* decline = new BButton("decline", B_TRANSLATE("Decline"),
80 			new BMessage(P_MSG_DECLINE));
81 
82 		BLayoutBuilder::Group<>(this, B_VERTICAL)
83 			.Add(scrollView)
84 			.AddGroup(B_HORIZONTAL)
85 				.AddGlue()
86 				.Add(defaultButton)
87 				.Add(decline)
88 			.End()
89 			.SetInsets(B_USE_WINDOW_INSETS)
90 		;
91 	} else {
92 		defaultButton = new BButton("accept", B_TRANSLATE("Continue"),
93 			new BMessage(P_MSG_ACCEPT));
94 
95 		BLayoutBuilder::Group<>(this, B_VERTICAL)
96 			.Add(scrollView)
97 			.AddGroup(B_HORIZONTAL)
98 				.AddGlue()
99 				.Add(defaultButton)
100 			.End()
101 			.SetInsets(B_USE_WINDOW_INSETS)
102 		;
103 	}
104 
105 	defaultButton->MakeDefault(true);
106 
107 	textView->SetText(text);
108 }
109 
110