xref: /haiku/src/add-ons/translators/stxt/STXTView.cpp (revision 23d878482ed22e55dad6d1fca1df7bea42eb157c)
1 /*
2  * Copyright 2002-2011, Haiku, Inc. All rights reserved.
3  * Distributed under the terms of the MIT license.
4  *
5  * Authors:
6  *		Michael Wilber
7  *		Axel Dörfler, axeld@pinc-software.de
8  */
9 
10 /*! A view with information about the STXTTranslator. */
11 
12 
13 #include "STXTView.h"
14 #include "STXTTranslator.h"
15 
16 #include <Catalog.h>
17 #include <StringView.h>
18 
19 #include <stdio.h>
20 
21 
22 #undef B_TRANSLATION_CONTEXT
23 #define B_TRANSLATION_CONTEXT "STXTView"
24 
25 
26 STXTView::STXTView(const BRect &frame, const char *name, uint32 resizeMode,
27 		uint32 flags, TranslatorSettings *settings)
28 	: BView(frame, name, resizeMode, flags)
29 {
30 	fSettings = settings;
31 	SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
32 
33 	font_height fontHeight;
34 	be_bold_font->GetHeight(&fontHeight);
35 	float height = fontHeight.descent + fontHeight.ascent + fontHeight.leading;
36 
37 	BRect rect(10, 10, 200, 10 + height);
38 	BStringView *stringView = new BStringView(rect, "title",
39 		B_TRANSLATE("StyledEdit files translator"));
40 	stringView->SetFont(be_bold_font);
41 	stringView->ResizeToPreferred();
42 	AddChild(stringView);
43 
44 	float maxWidth = stringView->Bounds().Width();
45 
46 	rect.OffsetBy(0, height + 10);
47 	char version[256];
48 	snprintf(version, sizeof(version), "Version %d.%d.%d, %s",
49 		int(B_TRANSLATION_MAJOR_VERSION(STXT_TRANSLATOR_VERSION)),
50 		int(B_TRANSLATION_MINOR_VERSION(STXT_TRANSLATOR_VERSION)),
51 		int(B_TRANSLATION_REVISION_VERSION(STXT_TRANSLATOR_VERSION)),
52 		__DATE__);
53 	stringView = new BStringView(rect, "version", version);
54 	stringView->ResizeToPreferred();
55 	AddChild(stringView);
56 
57 	if (stringView->Bounds().Width() > maxWidth)
58 		maxWidth = stringView->Bounds().Width();
59 
60 	GetFontHeight(&fontHeight);
61 	height = fontHeight.descent + fontHeight.ascent + fontHeight.leading;
62 
63 	rect.OffsetBy(0, height + 5);
64 	stringView = new BStringView(rect, "Copyright",
65 		B_UTF8_COPYRIGHT "2002-2006 Haiku Inc.");
66 	stringView->ResizeToPreferred();
67 	AddChild(stringView);
68 
69 	if (maxWidth + 20 > Bounds().Width())
70 		ResizeTo(maxWidth + 20, Bounds().Height());
71 }
72 
73 
74 STXTView::~STXTView()
75 {
76 	fSettings->Release();
77 }
78