1 /*****************************************************************************/ 2 // TIFFView 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. 6 // 7 // TIFFView.cpp 8 // 9 // This BView based object displays information about the TIFFTranslator. 10 // 11 // 12 // Copyright (c) 2003 OpenBeOS 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 #include <stdio.h> 34 #include <string.h> 35 36 #include <Catalog.h> 37 #include <GridLayoutBuilder.h> 38 #include <GroupLayout.h> 39 #include <GroupLayoutBuilder.h> 40 #include <MenuBar.h> 41 #include <MenuField.h> 42 #include <MenuItem.h> 43 #include <PopUpMenu.h> 44 45 #include "tiff.h" 46 #include "tiffvers.h" 47 48 #include "TIFFTranslator.h" 49 #include "TranslatorSettings.h" 50 51 #include "TIFFView.h" 52 53 #undef B_TRANSLATE_CONTEXT 54 #define B_TRANSLATE_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 // Constructor 73 // 74 // Sets up the view settings 75 // 76 // Preconditions: 77 // 78 // Parameters: 79 // 80 // Postconditions: 81 // 82 // Returns: 83 // --------------------------------------------------------------- 84 TIFFView::TIFFView(const char *name, uint32 flags, 85 TranslatorSettings *settings) 86 : BView(name, flags) 87 { 88 fSettings = settings; 89 90 SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); 91 SetLowColor(ViewColor()); 92 93 fTitle = new BStringView("title", B_TRANSLATE("TIFF Image Translator")); 94 fTitle->SetFont(be_bold_font); 95 96 char detail[100]; 97 sprintf(detail, B_TRANSLATE("Version %d.%d.%d %s"), 98 static_cast<int>(B_TRANSLATION_MAJOR_VERSION(TIFF_TRANSLATOR_VERSION)), 99 static_cast<int>(B_TRANSLATION_MINOR_VERSION(TIFF_TRANSLATOR_VERSION)), 100 static_cast<int>(B_TRANSLATION_REVISION_VERSION( 101 TIFF_TRANSLATOR_VERSION)), __DATE__); 102 fDetail = new BStringView("detail", detail); 103 104 int16 i = 1; 105 fLibTIFF[0] = new BStringView(NULL, B_TRANSLATE("TIFF Library:")); 106 char libtiff[] = TIFFLIB_VERSION_STR; 107 char *tok = strtok(libtiff, "\n"); 108 while (i < 5 && tok) { 109 fLibTIFF[i] = new BStringView(NULL, tok); 110 tok = strtok(NULL, "\n"); 111 i++; 112 } 113 114 BPopUpMenu* menu = new BPopUpMenu("pick compression"); 115 116 uint32 currentCompression = fSettings->SetGetInt32(TIFF_SETTING_COMPRESSION); 117 // create the menu items with the various compression methods 118 add_menu_item(menu, COMPRESSION_NONE, B_TRANSLATE("None"), 119 currentCompression); 120 menu->AddSeparatorItem(); 121 add_menu_item(menu, COMPRESSION_PACKBITS, B_TRANSLATE("RLE (Packbits)"), 122 currentCompression); 123 add_menu_item(menu, COMPRESSION_DEFLATE, B_TRANSLATE("ZIP (Deflate)"), 124 currentCompression); 125 add_menu_item(menu, COMPRESSION_LZW, B_TRANSLATE("LZW"), 126 currentCompression); 127 128 // TODO: the disabled compression modes are not configured in libTIFF 129 // menu->AddSeparatorItem(); 130 // add_menu_item(menu, COMPRESSION_JPEG, "JPEG", currentCompression); 131 // TODO ? - strip encoding is not implemented in libTIFF for this compression 132 // add_menu_item(menu, COMPRESSION_JP2000, "JPEG2000", currentCompression); 133 134 fCompressionMF = new BMenuField(B_TRANSLATE("Use Compression:"), menu); 135 136 // Build the layout 137 SetLayout(new BGroupLayout(B_VERTICAL)); 138 139 i = 0; 140 AddChild(BGroupLayoutBuilder(B_VERTICAL, 7) 141 .Add(fTitle) 142 .Add(fDetail) 143 .AddGlue() 144 .Add(fCompressionMF) 145 .AddGlue() 146 .Add(fLibTIFF[0]) 147 .Add(fLibTIFF[1]) 148 .Add(fLibTIFF[2]) 149 .Add(fLibTIFF[3]) 150 // Theses 4 adding above work because we know there are 4 strings 151 // but it's fragile: one string less in the library version and the application breaks 152 .AddGlue() 153 .SetInsets(5, 5, 5, 5) 154 ); 155 156 BFont font; 157 GetFont(&font); 158 SetExplicitPreferredSize(BSize((font.Size() * 350)/12, (font.Size() * 200)/12)); 159 } 160 161 // --------------------------------------------------------------- 162 // Destructor 163 // 164 // Does nothing 165 // 166 // Preconditions: 167 // 168 // Parameters: 169 // 170 // Postconditions: 171 // 172 // Returns: 173 // --------------------------------------------------------------- 174 TIFFView::~TIFFView() 175 { 176 fSettings->Release(); 177 } 178 179 // --------------------------------------------------------------- 180 // MessageReceived 181 // 182 // Handles state changes of the Compression menu field 183 // 184 // Preconditions: 185 // 186 // Parameters: area, not used 187 // 188 // Postconditions: 189 // 190 // Returns: 191 // --------------------------------------------------------------- 192 void 193 TIFFView::MessageReceived(BMessage* message) 194 { 195 switch (message->what) { 196 case MSG_COMPRESSION_CHANGED: { 197 int32 value; 198 if (message->FindInt32("value", &value) >= B_OK) { 199 fSettings->SetGetInt32(TIFF_SETTING_COMPRESSION, &value); 200 fSettings->SaveSettings(); 201 } 202 break; 203 } 204 default: 205 BView::MessageReceived(message); 206 } 207 } 208 209 // --------------------------------------------------------------- 210 // AllAttached 211 // 212 // sets the target for the controls controlling the configuration 213 // 214 // Preconditions: 215 // 216 // Parameters: area, not used 217 // 218 // Postconditions: 219 // 220 // Returns: 221 // --------------------------------------------------------------- 222 void 223 TIFFView::AllAttached() 224 { 225 fCompressionMF->Menu()->SetTargetForItems(this); 226 fCompressionMF->SetDivider(fCompressionMF->StringWidth(fCompressionMF->Label()) + 3); 227 fCompressionMF->ResizeToPreferred(); 228 } 229 230 231