1 /*****************************************************************************/ 2 // TIFFView 3 // Written by Michael Wilber, Haiku 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. 6 // 7 // TIFFView.cpp 8 // 9 // This BView based object displays information about the TIFFTranslator. 10 // 11 // 12 // Copyright (c) 2003 Haiku Project 13 // 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: 20 // 21 // The above copyright notice and this permission notice shall be included 22 // in all copies or substantial portions of the Software. 23 // 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 /*****************************************************************************/ 32 33 34 #include "TIFFView.h" 35 36 #include <stdio.h> 37 #include <string.h> 38 39 #include <Catalog.h> 40 #include <LayoutBuilder.h> 41 #include <MenuBar.h> 42 #include <MenuField.h> 43 #include <MenuItem.h> 44 #include <PopUpMenu.h> 45 46 #include "tiff.h" 47 #include "tiffvers.h" 48 49 #include "TIFFTranslator.h" 50 #include "TranslatorSettings.h" 51 52 53 #undef B_TRANSLATION_CONTEXT 54 #define B_TRANSLATION_CONTEXT "TIFFView" 55 56 // add_menu_item 57 void 58 add_menu_item(BMenu* menu, 59 uint32 compression, 60 const char* label, 61 uint32 currentCompression) 62 { 63 // COMPRESSION_NONE 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); 68 menu->AddItem(item); 69 } 70 71 72 TIFFView::TIFFView(const char* name, uint32 flags, 73 TranslatorSettings* settings) 74 : 75 BView(name, flags) 76 { 77 fSettings = settings; 78 79 SetViewUIColor(B_PANEL_BACKGROUND_COLOR); 80 SetLowUIColor(ViewUIColor()); 81 82 fTitle = new BStringView("title", B_TRANSLATE("TIFF image translator")); 83 fTitle->SetFont(be_bold_font); 84 85 char detail[100]; 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); 92 93 int16 i = 1; 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"); 100 i++; 101 } 102 103 BPopUpMenu* menu = new BPopUpMenu("pick compression"); 104 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"), 108 currentCompression); 109 menu->AddSeparatorItem(); 110 add_menu_item(menu, COMPRESSION_PACKBITS, B_TRANSLATE("RLE (Packbits)"), 111 currentCompression); 112 add_menu_item(menu, COMPRESSION_DEFLATE, B_TRANSLATE("ZIP (Deflate)"), 113 currentCompression); 114 add_menu_item(menu, COMPRESSION_LZW, B_TRANSLATE("LZW"), 115 currentCompression); 116 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); 122 123 fCompressionMF = new BMenuField(B_TRANSLATE("Use compression:"), menu); 124 125 // Build the layout 126 BLayoutBuilder::Group<>(this, B_VERTICAL, 0) 127 .SetInsets(B_USE_DEFAULT_SPACING) 128 .Add(fTitle) 129 .Add(fDetail) 130 .AddGlue() 131 .AddGroup(B_HORIZONTAL) 132 .Add(fCompressionMF) 133 .AddGlue() 134 .End() 135 .AddGlue() 136 .Add(fLibTIFF[0]) 137 .Add(fLibTIFF[1]) 138 .Add(fLibTIFF[2]) 139 .Add(fLibTIFF[3]); 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 143 144 BFont font; 145 GetFont(&font); 146 SetExplicitPreferredSize( 147 BSize((font.Size() * 350)/12, (font.Size() * 200)/12)); 148 } 149 150 151 TIFFView::~TIFFView() 152 { 153 fSettings->Release(); 154 } 155 156 157 void 158 TIFFView::AllAttached() 159 { 160 fCompressionMF->Menu()->SetTargetForItems(this); 161 } 162 163 164 void 165 TIFFView::MessageReceived(BMessage* message) 166 { 167 switch (message->what) { 168 case MSG_COMPRESSION_CHANGED: { 169 int32 value; 170 if (message->FindInt32("value", &value) >= B_OK) { 171 fSettings->SetGetInt32(TIFF_SETTING_COMPRESSION, &value); 172 fSettings->SaveSettings(); 173 } 174 break; 175 } 176 default: 177 BView::MessageReceived(message); 178 } 179 } 180