BPicture: Fix archive constructor.
[haiku.git] / src / add-ons / translators / png / PNGView.cpp
blobad5af2e359d7c73fe63b6520128383e65d2a1edc
1 /*
2 * Copyright 2003-2009, Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT license.
5 * Authors:
6 * Michael Wilber
7 * Axel Dörfler, axeld@pinc-software.de
8 */
11 #include "PNGView.h"
12 #include "PNGTranslator.h"
14 #include <Alert.h>
15 #include <Catalog.h>
16 #include <LayoutBuilder.h>
17 #include <MenuField.h>
18 #include <MenuItem.h>
19 #include <PopUpMenu.h>
20 #include <StringView.h>
21 #include <TextView.h>
23 #include <stdio.h>
24 #define PNG_NO_PEDANTIC_WARNINGS
25 #include <png.h>
27 #undef B_TRANSLATION_CONTEXT
28 #define B_TRANSLATION_CONTEXT "PNGTranslator"
30 PNGView::PNGView(const BRect &frame, const char *name, uint32 resizeMode,
31 uint32 flags, TranslatorSettings *settings)
32 : BView(frame, name, resizeMode, flags | B_FRAME_EVENTS)
34 fSettings = settings;
35 SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
37 BStringView *titleView = new BStringView("title",
38 B_TRANSLATE("PNG image translator"));
39 titleView->SetFont(be_bold_font);
41 char version[256];
42 snprintf(version, sizeof(version), B_TRANSLATE("Version %d.%d.%d, %s"),
43 int(B_TRANSLATION_MAJOR_VERSION(PNG_TRANSLATOR_VERSION)),
44 int(B_TRANSLATION_MINOR_VERSION(PNG_TRANSLATOR_VERSION)),
45 int(B_TRANSLATION_REVISION_VERSION(PNG_TRANSLATOR_VERSION)),
46 __DATE__);
47 BStringView *versionView = new BStringView("version", version);
49 BStringView *copyrightView = new BStringView(
50 "Copyright", B_UTF8_COPYRIGHT "2003-2006 Haiku Inc.");
52 // setup PNG interlace options
54 fInterlaceMenu = new BPopUpMenu(B_TRANSLATE("Interlace Option"));
55 BMenuItem* item = new BMenuItem(B_TRANSLATE("None"),
56 _InterlaceMessage(PNG_INTERLACE_NONE));
57 if (fSettings->SetGetInt32(PNG_SETTING_INTERLACE) == PNG_INTERLACE_NONE)
58 item->SetMarked(true);
59 fInterlaceMenu->AddItem(item);
61 item = new BMenuItem("Adam7", _InterlaceMessage(PNG_INTERLACE_ADAM7));
62 if (fSettings->SetGetInt32(PNG_SETTING_INTERLACE) == PNG_INTERLACE_ADAM7)
63 item->SetMarked(true);
64 fInterlaceMenu->AddItem(item);
66 BMenuField* menuField = new BMenuField(
67 B_TRANSLATE("PNG Interlace Menu"),
68 B_TRANSLATE("Interlacing type:"), fInterlaceMenu);
69 menuField->SetDivider(menuField->StringWidth(menuField->Label()) + 7.0f);
70 menuField->ResizeToPreferred();
72 fCopyrightView = new BTextView("PNG copyright");
73 fCopyrightView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
74 fCopyrightView->SetLowColor(fCopyrightView->ViewColor());
75 fCopyrightView->MakeEditable(false);
76 fCopyrightView->SetWordWrap(false);
77 fCopyrightView->MakeResizable(true);
78 fCopyrightView->SetText(png_get_copyright(NULL));
80 BLayoutBuilder::Group<>(this, B_VERTICAL, 0)
81 .SetInsets(B_USE_DEFAULT_SPACING)
82 .Add(titleView)
83 .Add(versionView)
84 .Add(copyrightView)
85 .AddGlue()
86 .AddGroup(B_HORIZONTAL)
87 .Add(menuField)
88 .AddGlue()
89 .End()
90 .AddGlue()
91 .Add(fCopyrightView);
93 BFont font;
94 GetFont(&font);
95 SetExplicitPreferredSize(BSize((font.Size() * 390) / 12,
96 (font.Size() * 180) / 12));
98 // TODO: remove this workaround for ticket #4217
99 fCopyrightView->SetExplicitPreferredSize(
100 BSize(fCopyrightView->LineWidth(4), fCopyrightView->TextHeight(0, 80)));
101 fCopyrightView->SetExplicitMaxSize(fCopyrightView->ExplicitPreferredSize());
102 fCopyrightView->SetExplicitMinSize(fCopyrightView->ExplicitPreferredSize());
106 PNGView::~PNGView()
108 fSettings->Release();
112 BMessage *
113 PNGView::_InterlaceMessage(int32 kind)
115 BMessage* message = new BMessage(M_PNG_SET_INTERLACE);
116 message->AddInt32(PNG_SETTING_INTERLACE, kind);
118 return message;
122 void
123 PNGView::AttachedToWindow()
125 BView::AttachedToWindow();
127 // set target for interlace options menu items
128 fInterlaceMenu->SetTargetForItems(this);
132 void
133 PNGView::FrameResized(float width, float height)
135 // This works around a flaw of BTextView
136 fCopyrightView->SetTextRect(fCopyrightView->Bounds());
140 void
141 PNGView::MessageReceived(BMessage *message)
143 if (message->what == M_PNG_SET_INTERLACE) {
144 // change setting for interlace option
145 int32 option;
146 if (message->FindInt32(PNG_SETTING_INTERLACE, &option) == B_OK) {
147 fSettings->SetGetInt32(PNG_SETTING_INTERLACE, &option);
148 fSettings->SaveSettings();
150 } else
151 BView::MessageReceived(message);