1 /*****************************************************************************/
3 // Written by Michael Wilber, OBOS Translation Kit Team
4 // Picking the compression method added by Stephan Aßmus, <stippi@yellowbites.com>
5 // Use of Layout API added by Maxime Simon, maxime.simon@gmail.com, 2009.
9 // This BView based object displays information about the TIFFTranslator.
12 // Copyright (c) 2003 OpenBeOS Project
14 // Permission is hereby granted, free of charge, to any person obtaining a
15 // copy of this software and associated documentation files (the "Software"),
16 // to deal in the Software without restriction, including without limitation
17 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
18 // and/or sell copies of the Software, and to permit persons to whom the
19 // Software is furnished to do so, subject to the following conditions:
21 // The above copyright notice and this permission notice shall be included
22 // in all copies or substantial portions of the Software.
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
25 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
27 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
29 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
30 // DEALINGS IN THE SOFTWARE.
31 /*****************************************************************************/
40 #include <LayoutBuilder.h>
42 #include <MenuField.h>
44 #include <PopUpMenu.h>
49 #include "TIFFTranslator.h"
50 #include "TranslatorSettings.h"
53 #undef B_TRANSLATION_CONTEXT
54 #define B_TRANSLATION_CONTEXT "TIFFView"
58 add_menu_item(BMenu
* menu
,
61 uint32 currentCompression
)
64 BMessage
* message
= new BMessage(TIFFView::MSG_COMPRESSION_CHANGED
);
65 message
->AddInt32("value", compression
);
66 BMenuItem
* item
= new BMenuItem(label
, message
);
67 item
->SetMarked(currentCompression
== compression
);
72 TIFFView::TIFFView(const char* name
, uint32 flags
,
73 TranslatorSettings
* settings
)
79 SetViewUIColor(B_PANEL_BACKGROUND_COLOR
);
80 SetLowUIColor(ViewUIColor());
82 fTitle
= new BStringView("title", B_TRANSLATE("TIFF image translator"));
83 fTitle
->SetFont(be_bold_font
);
86 sprintf(detail
, B_TRANSLATE("Version %d.%d.%d, %s"),
87 static_cast<int>(B_TRANSLATION_MAJOR_VERSION(TIFF_TRANSLATOR_VERSION
)),
88 static_cast<int>(B_TRANSLATION_MINOR_VERSION(TIFF_TRANSLATOR_VERSION
)),
89 static_cast<int>(B_TRANSLATION_REVISION_VERSION(
90 TIFF_TRANSLATOR_VERSION
)), __DATE__
);
91 fDetail
= new BStringView("detail", detail
);
94 fLibTIFF
[0] = new BStringView(NULL
, B_TRANSLATE("TIFF Library:"));
95 char libtiff
[] = TIFFLIB_VERSION_STR
;
96 char* tok
= strtok(libtiff
, "\n");
97 while (i
< 5 && tok
) {
98 fLibTIFF
[i
] = new BStringView(NULL
, tok
);
99 tok
= strtok(NULL
, "\n");
103 BPopUpMenu
* menu
= new BPopUpMenu("pick compression");
105 uint32 currentCompression
= fSettings
->SetGetInt32(TIFF_SETTING_COMPRESSION
);
106 // create the menu items with the various compression methods
107 add_menu_item(menu
, COMPRESSION_NONE
, B_TRANSLATE("None"),
109 menu
->AddSeparatorItem();
110 add_menu_item(menu
, COMPRESSION_PACKBITS
, B_TRANSLATE("RLE (Packbits)"),
112 add_menu_item(menu
, COMPRESSION_DEFLATE
, B_TRANSLATE("ZIP (Deflate)"),
114 add_menu_item(menu
, COMPRESSION_LZW
, B_TRANSLATE("LZW"),
117 // TODO: the disabled compression modes are not configured in libTIFF
118 // menu->AddSeparatorItem();
119 // add_menu_item(menu, COMPRESSION_JPEG, "JPEG", currentCompression);
120 // TODO ? - strip encoding is not implemented in libTIFF for this compression
121 // add_menu_item(menu, COMPRESSION_JP2000, "JPEG2000", currentCompression);
123 fCompressionMF
= new BMenuField(B_TRANSLATE("Use compression:"), menu
);
126 BLayoutBuilder::Group
<>(this, B_VERTICAL
, 0)
127 .SetInsets(B_USE_DEFAULT_SPACING
)
131 .AddGroup(B_HORIZONTAL
)
140 // Theses 4 adding above work because we know there are 4 strings
141 // but it's fragile: one string less in the library version and the
142 // application breaks
146 SetExplicitPreferredSize(
147 BSize((font
.Size() * 350)/12, (font
.Size() * 200)/12));
151 TIFFView::~TIFFView()
153 fSettings
->Release();
158 TIFFView::AllAttached()
160 fCompressionMF
->Menu()->SetTargetForItems(this);
165 TIFFView::MessageReceived(BMessage
* message
)
167 switch (message
->what
) {
168 case MSG_COMPRESSION_CHANGED
: {
170 if (message
->FindInt32("value", &value
) >= B_OK
) {
171 fSettings
->SetGetInt32(TIFF_SETTING_COMPRESSION
, &value
);
172 fSettings
->SaveSettings();
177 BView::MessageReceived(message
);