2 * Copyright 2003-2009, Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT license.
7 * Axel Dörfler, axeld@pinc-software.de
12 #include "PNGTranslator.h"
16 #include <LayoutBuilder.h>
17 #include <MenuField.h>
19 #include <PopUpMenu.h>
20 #include <StringView.h>
24 #define PNG_NO_PEDANTIC_WARNINGS
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
)
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
);
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
)),
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
)
86 .AddGroup(B_HORIZONTAL
)
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());
108 fSettings
->Release();
113 PNGView::_InterlaceMessage(int32 kind
)
115 BMessage
* message
= new BMessage(M_PNG_SET_INTERLACE
);
116 message
->AddInt32(PNG_SETTING_INTERLACE
, kind
);
123 PNGView::AttachedToWindow()
125 BView::AttachedToWindow();
127 // set target for interlace options menu items
128 fInterlaceMenu
->SetTargetForItems(this);
133 PNGView::FrameResized(float width
, float height
)
135 // This works around a flaw of BTextView
136 fCopyrightView
->SetTextRect(fCopyrightView
->Bounds());
141 PNGView::MessageReceived(BMessage
*message
)
143 if (message
->what
== M_PNG_SET_INTERLACE
) {
144 // change setting for interlace option
146 if (message
->FindInt32(PNG_SETTING_INTERLACE
, &option
) == B_OK
) {
147 fSettings
->SetGetInt32(PNG_SETTING_INTERLACE
, &option
);
148 fSettings
->SaveSettings();
151 BView::MessageReceived(message
);