144f919daSRyan Leavengood /*
265688206SStephan Aßmus * Copyright (c) 2007-2014, Haiku, Inc.
344f919daSRyan Leavengood * Distributed under the terms of the MIT license.
444f919daSRyan Leavengood *
544f919daSRyan Leavengood * Author:
644f919daSRyan Leavengood * Łukasz 'Sil2100' Zemczak <sil2100@vexillium.org>
765688206SStephan Aßmus * Stephan Aßmus <superstippi@gmx.de>
844f919daSRyan Leavengood */
944f919daSRyan Leavengood
10f51cdb44SStephan Aßmus
1144f919daSRyan Leavengood #include "PackageTextViewer.h"
1244f919daSRyan Leavengood
1344f919daSRyan Leavengood #include <Button.h>
14091440e0SStephan Aßmus #include <Catalog.h>
15*ad1c3c44SStephan Aßmus #include <LayoutBuilder.h>
16091440e0SStephan Aßmus #include <Locale.h>
1744f919daSRyan Leavengood #include <ScrollView.h>
1844f919daSRyan Leavengood
1944f919daSRyan Leavengood
2044f919daSRyan Leavengood enum {
2144f919daSRyan Leavengood P_MSG_ACCEPT = 'pmac',
2244f919daSRyan Leavengood P_MSG_DECLINE
2344f919daSRyan Leavengood };
2444f919daSRyan Leavengood
25546208a5SOliver Tappe #undef B_TRANSLATION_CONTEXT
26546208a5SOliver Tappe #define B_TRANSLATION_CONTEXT "PackageTextViewer"
2744f919daSRyan Leavengood
2844f919daSRyan Leavengood
PackageTextViewer(const char * text,bool disclaimer)2944f919daSRyan Leavengood PackageTextViewer::PackageTextViewer(const char *text, bool disclaimer)
30091440e0SStephan Aßmus :
3165688206SStephan Aßmus BlockingWindow(BRect(125, 125, 675, 475), B_TRANSLATE("Disclaimer"),
3265688206SStephan Aßmus B_AUTO_UPDATE_SIZE_LIMITS)
3344f919daSRyan Leavengood {
3444f919daSRyan Leavengood _InitView(text, disclaimer);
3565688206SStephan Aßmus CenterOnScreen();
3644f919daSRyan Leavengood }
3744f919daSRyan Leavengood
3844f919daSRyan Leavengood
3944f919daSRyan Leavengood void
MessageReceived(BMessage * message)4065688206SStephan Aßmus PackageTextViewer::MessageReceived(BMessage* message)
4144f919daSRyan Leavengood {
4265688206SStephan Aßmus switch (message->what) {
4365688206SStephan Aßmus case P_MSG_ACCEPT:
4465688206SStephan Aßmus ReleaseSem(1);
4565688206SStephan Aßmus break;
4665688206SStephan Aßmus
4765688206SStephan Aßmus case P_MSG_DECLINE:
4865688206SStephan Aßmus ReleaseSem(0);
4965688206SStephan Aßmus break;
5065688206SStephan Aßmus
5165688206SStephan Aßmus default:
5265688206SStephan Aßmus BWindow::MessageReceived(message);
5365688206SStephan Aßmus break;
5444f919daSRyan Leavengood }
5544f919daSRyan Leavengood }
5644f919daSRyan Leavengood
5744f919daSRyan Leavengood
5844f919daSRyan Leavengood // #pragma mark -
5944f919daSRyan Leavengood
6044f919daSRyan Leavengood
6144f919daSRyan Leavengood void
_InitView(const char * text,bool disclaimer)6244f919daSRyan Leavengood PackageTextViewer::_InitView(const char* text, bool disclaimer)
6344f919daSRyan Leavengood {
6465688206SStephan Aßmus BTextView* textView = new BTextView("text_view");
6565688206SStephan Aßmus textView->MakeEditable(false);
6665688206SStephan Aßmus textView->MakeSelectable(true);
6765688206SStephan Aßmus float margin = ceilf(be_plain_font->Size());
6865688206SStephan Aßmus textView->SetInsets(margin, margin, margin, margin);
6965688206SStephan Aßmus BScrollView* scrollView = new BScrollView("scroll_view", textView, 0, false,
7065688206SStephan Aßmus true);
7144f919daSRyan Leavengood
7265688206SStephan Aßmus BButton* defaultButton;
7344f919daSRyan Leavengood
7444f919daSRyan Leavengood if (disclaimer) {
7565688206SStephan Aßmus defaultButton = new BButton("accept", B_TRANSLATE("Accept"),
7644f919daSRyan Leavengood new BMessage(P_MSG_ACCEPT));
7744f919daSRyan Leavengood
78eef95624SMatt Madia BButton* decline = new BButton("decline", B_TRANSLATE("Decline"),
7944f919daSRyan Leavengood new BMessage(P_MSG_DECLINE));
8044f919daSRyan Leavengood
8165688206SStephan Aßmus BLayoutBuilder::Group<>(this, B_VERTICAL)
8265688206SStephan Aßmus .Add(scrollView)
8365688206SStephan Aßmus .AddGroup(B_HORIZONTAL)
8444f919daSRyan Leavengood .AddGlue()
8565688206SStephan Aßmus .Add(defaultButton)
8644f919daSRyan Leavengood .Add(decline)
8765688206SStephan Aßmus .End()
8865688206SStephan Aßmus .SetInsets(B_USE_WINDOW_INSETS)
8965688206SStephan Aßmus ;
9065688206SStephan Aßmus } else {
9165688206SStephan Aßmus defaultButton = new BButton("accept", B_TRANSLATE("Continue"),
9244f919daSRyan Leavengood new BMessage(P_MSG_ACCEPT));
9344f919daSRyan Leavengood
9465688206SStephan Aßmus BLayoutBuilder::Group<>(this, B_VERTICAL)
9565688206SStephan Aßmus .Add(scrollView)
9665688206SStephan Aßmus .AddGroup(B_HORIZONTAL)
9744f919daSRyan Leavengood .AddGlue()
9865688206SStephan Aßmus .Add(defaultButton)
9965688206SStephan Aßmus .End()
10065688206SStephan Aßmus .SetInsets(B_USE_WINDOW_INSETS)
10165688206SStephan Aßmus ;
10244f919daSRyan Leavengood }
10344f919daSRyan Leavengood
10465688206SStephan Aßmus defaultButton->MakeDefault(true);
10544f919daSRyan Leavengood
10665688206SStephan Aßmus textView->SetText(text);
10765688206SStephan Aßmus }
10844f919daSRyan Leavengood
109