Ticket #5563: ShowImage.patch
File ShowImage.patch, 34.1 KB (added by , 14 years ago) |
---|
-
PrintOptionsWindow.cpp
13 13 14 14 #include <Box.h> 15 15 #include <Button.h> 16 #include <Catalog.h> 17 #include <GroupLayoutBuilder.h> 18 #include <GridLayoutBuilder.h> 19 #include <Locale.h> 20 #include <LayoutBuilder.h> 16 21 #include <String.h> 17 22 18 23 #include "ShowImageConstants.h" … … 23 28 fOption(kFitToPage), 24 29 fZoomFactor(1.0), 25 30 fDPI(72.0), 26 fWidth(1024 /72.0),27 fHeight(768 /72.0)31 fWidth(1024 / 72.0), 32 fHeight(768 / 72.0) 28 33 { 29 34 } 30 35 … … 68 73 } 69 74 70 75 71 PrintOptionsWindow::PrintOptionsWindow(BPoint at, PrintOptions *options, 76 #undef TR_CONTEXT 77 #define TR_CONTEXT "PrintOptionsWindow" 78 79 PrintOptionsWindow::PrintOptionsWindow(BPoint at, PrintOptions* options, 72 80 BWindow* listener) 73 81 : 74 BWindow(BRect(at.x, at.y, at.x + 300, at.y + 200), "Print options",82 BWindow(BRect(at.x, at.y, at.x + 300, at.y + 200), TR("Print options"), 75 83 B_TITLED_WINDOW_LOOK, B_MODAL_SUBSET_WINDOW_FEEL, 76 B_NOT_ZOOMABLE | B_NOT_RESIZABLE ),84 B_NOT_ZOOMABLE | B_NOT_RESIZABLE | B_AUTO_UPDATE_SIZE_LIMITS), 77 85 fPrintOptions(options), 78 86 fCurrentOptions(*options), 79 87 fListener(listener), … … 94 102 95 103 96 104 BRadioButton* 97 PrintOptionsWindow::AddRadioButton( BView* view, BPoint& at,const char* name,105 PrintOptionsWindow::AddRadioButton(const char* name, 98 106 const char* label, uint32 what, bool selected) 99 107 { 100 BRect rect(0, 0, 100, 20);101 108 BRadioButton* button; 102 rect.OffsetBy(at); 103 button = new BRadioButton(rect, name, label, new BMessage(what)); 104 view->AddChild(button); 105 button->ResizeToPreferred(); 106 at.y += button->Bounds().Height() + kLineSkip; 109 button = new BRadioButton(name, label, new BMessage(what)); 107 110 button->SetValue(selected ? B_CONTROL_ON : B_CONTROL_OFF); 108 111 return button; 109 112 } 110 113 111 114 112 115 BTextControl* 113 PrintOptionsWindow::AddTextControl( BView* view, BPoint& at,const char* name,114 const char* label, float value, float divider,uint32 what)116 PrintOptionsWindow::AddTextControl(const char* name, 117 const char* label, float value, uint32 what) 115 118 { 116 BRect rect(0, 0, divider + 45, 20);117 119 BTextControl* text; 118 rect.OffsetBy(at); 119 text = new BTextControl(rect, name, label, "", new BMessage(what)); 120 view->AddChild(text); 120 text = new BTextControl(name, label, "", new BMessage(what)); 121 121 text->SetModificationMessage(new BMessage(what)); 122 text->SetDivider(divider);123 text->SetAlignment(B_ALIGN_LEFT, B_ALIGN_RIGHT);124 122 SetValue(text, value); 125 at.y += text->Bounds().Height() + kLineSkip;126 123 return text; 127 124 } 128 125 … … 134 131 BPoint at(kIndent, kIndent), textAt; 135 132 BString value; 136 133 enum PrintOptions::Option op = fCurrentOptions.Option(); 137 BRadioButton* rb; 134 BRadioButton* rbFit; 135 BRadioButton* rbZoom; 136 BRadioButton* rbDpi; 137 BRadioButton* rbResize; 138 138 BBox* line; 139 139 BButton* button; 140 140 141 BBox *panel = new BBox(rect, "top_panel", B_FOLLOW_ALL, 142 B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE_JUMP, 143 B_PLAIN_BORDER); 144 AddChild(panel); 141 rbFit = AddRadioButton("fit_to_page", TR("Fit image to page"), 142 kMsgFitToPageSelected, op == PrintOptions::kFitToPage); 145 143 146 AddRadioButton(panel, at, "fit_to_page", "Fit image to page", 147 kMsgFitToPageSelected, op == PrintOptions::kFitToPage); 148 textAt = at; 149 rb = AddRadioButton(panel, at, "zoom_factor", "Zoom factor in %: ", 144 rbZoom = AddRadioButton("zoom_factor", TR("Zoom factor in %:"), 150 145 kMsgZoomFactorSelected, op == PrintOptions::kZoomFactor); 151 textAt.x = rb->Bounds().right + 5;152 fZoomFactor = AddTextControl(panel, textAt, "zoom_factor_text", "",153 fCurrentOptions.ZoomFactor()*100, 0, kMsgZoomFactorChanged);154 146 155 textAt = at; 156 rb = AddRadioButton(panel, at, "dpi", "DPI: ", kMsgDPISelected, 147 fZoomFactor = AddTextControl("zoom_factor_text", "", 148 fCurrentOptions.ZoomFactor()*100, kMsgZoomFactorChanged); 149 150 rbDpi = AddRadioButton("dpi", TR("DPI:"), kMsgDPISelected, 157 151 op == PrintOptions::kDPI); 158 textAt.x = rb->Bounds().right + 5;159 fDPI = AddTextControl(panel, textAt, "dpi_text", "", fCurrentOptions.DPI(),160 0, kMsgDPIChanged);161 152 162 rb = AddRadioButton(panel, at, "width_and_height", 163 "Resize to (in 1/72 inches):", kMsgWidthAndHeightSelected, 153 fDPI = AddTextControl("dpi_text", "", fCurrentOptions.DPI(), 154 kMsgDPIChanged); 155 156 rbResize = AddRadioButton("width_and_height", 157 TR("Resize to (in 1/72 inches):"), kMsgWidthAndHeightSelected, 164 158 op == PrintOptions::kWidth || op == PrintOptions::kHeight); 165 at.x += 15;166 textAt = at;167 fWidth = AddTextControl(panel, textAt, "width", "Width: ",168 fCurrentOptions.Width(), 40, kMsgWidthChanged);169 textAt = at;170 textAt.x += fWidth->Bounds().Width() + 5;171 fHeight = AddTextControl(panel, textAt, "height", "Height: ",172 fCurrentOptions.Height(), 40, kMsgHeightChanged);173 159 174 at.x = 0; 175 at.y = textAt.y; 176 line = new BBox(BRect(rect.left+3, at.y, rect.right-3, at.y + 1), NULL, 177 B_FOLLOW_LEFT | B_FOLLOW_TOP); 178 panel->AddChild(line); 160 fWidth = AddTextControl("width", TR("Width:"), 161 fCurrentOptions.Width(), kMsgWidthChanged); 179 162 180 at.y += 10; 181 rect.OffsetBy(at); 182 button = new BButton(rect, "job setup", "Job setup", 163 fHeight = AddTextControl("height", TR("Height: "), 164 fCurrentOptions.Height(), kMsgHeightChanged); 165 166 line = new BBox(B_EMPTY_STRING, B_WILL_DRAW | B_FRAME_EVENTS, 167 B_FANCY_BORDER); 168 line->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, 1)); 169 170 button = new BButton("job setup", TR("Job setup"), 183 171 new BMessage(kMsgJobSetup)); 184 panel->AddChild(button);185 button->ResizeToPreferred();186 187 172 SetDefaultButton(button); 188 173 189 // resize window 190 ResizeTo(fHeight->Frame().right + kIndent, button->Frame().bottom + kIndent); 191 192 // center button 193 button->MoveTo((Bounds().Width()-button->Bounds().Width())/2, 194 button->Frame().top); 174 SetLayout(new BGroupLayout(B_HORIZONTAL)); 175 AddChild(BGroupLayoutBuilder(B_VERTICAL, 5) 176 .Add(BGridLayoutBuilder() 177 .Add(rbFit, 0, 0) 178 .Add(rbZoom, 0, 1) 179 .Add(fZoomFactor, 1, 1) 180 .Add(rbDpi, 0, 2) 181 .Add(fDPI, 1, 2) 182 .Add(rbResize, 0, 3) 183 ) 184 .AddGroup(B_HORIZONTAL, 5) 185 .Add(fWidth) 186 .Add(fHeight) 187 .AddGlue() 188 .SetInsets(22, 0, 0, 0) 189 .End() 190 .Add(line) 191 .AddGroup(B_HORIZONTAL, 0) 192 .Add(button) 193 .End() 194 .SetInsets(5, 5, 5, 5) 195 ); 195 196 } 196 197 197 198 … … 245 246 case kMsgZoomFactorChanged: 246 247 if (GetValue(fZoomFactor, &value) 247 248 && fCurrentOptions.ZoomFactor() != value) { 248 fCurrentOptions.SetZoomFactor(value /100);249 fCurrentOptions.SetZoomFactor(value / 100); 249 250 SetValue(fDPI, fCurrentOptions.DPI()); 250 251 } 251 252 break; 252 253 case kMsgDPIChanged: 253 254 if (GetValue(fDPI, &value) && fCurrentOptions.DPI() != value) { 254 255 fCurrentOptions.SetDPI(value); 255 SetValue(fZoomFactor, 100 *fCurrentOptions.ZoomFactor());256 SetValue(fZoomFactor, 100 * fCurrentOptions.ZoomFactor()); 256 257 } 257 258 break; 258 259 case kMsgWidthChanged: -
PrintOptionsWindow.h
64 64 void MessageReceived(BMessage* msg); 65 65 66 66 private: 67 BRadioButton* AddRadioButton(BView* view, BPoint& at, 68 const char* name, const char* label, 67 BRadioButton* AddRadioButton(const char* name, const char* label, 69 68 uint32 what, bool selected); 70 69 71 BTextControl* AddTextControl(BView* view, BPoint& at, 72 const char* name, const char* label, 73 float value, float divider, uint32 what); 70 BTextControl* AddTextControl(const char* name, const char* label, 71 float value, uint32 what); 74 72 75 73 void Setup(); 76 74 enum PrintOptions::Option MsgToOption(uint32 what); -
ShowImageWindow.cpp
21 21 #include <Application.h> 22 22 #include <Bitmap.h> 23 23 #include <BitmapStream.h> 24 #include <Catalog.h> 24 25 #include <Clipboard.h> 25 26 #include <Entry.h> 26 27 #include <File.h> 27 28 #include <FilePanel.h> 29 #include <Locale.h> 28 30 #include <Menu.h> 29 31 #include <MenuBar.h> 30 32 #include <MenuItem.h> … … 38 40 #include <TranslationDefs.h> 39 41 #include <TranslationUtils.h> 40 42 #include <TranslatorRoster.h> 43 #include <stdlib.h> // for bs_printf() 41 44 42 45 #include "EntryMenuItem.h" 43 46 #include "ResizerWindow.h" … … 51 54 52 55 class ShowImageWindow::RecentDocumentsMenu : public BMenu { 53 56 public: 54 RecentDocumentsMenu(const char *title,57 RecentDocumentsMenu(const char* title, 55 58 menu_layout layout = B_ITEMS_IN_COLUMN); 56 59 bool AddDynamicItem(add_state addState); 57 60 … … 60 63 }; 61 64 62 65 63 ShowImageWindow::RecentDocumentsMenu::RecentDocumentsMenu(const char *title,66 ShowImageWindow::RecentDocumentsMenu::RecentDocumentsMenu(const char* title, 64 67 menu_layout layout) 65 68 : 66 69 BMenu(title, layout) … … 77 80 while (CountItems() > 0) 78 81 delete RemoveItem(0L); 79 82 80 BMenuItem *item;83 BMenuItem* item; 81 84 BMessage list, *msg; 82 85 entry_ref ref; 83 86 char name[B_FILE_NAME_LENGTH]; … … 106 109 const char* kTranslatorField = "be:translator"; 107 110 108 111 109 ShowImageWindow::ShowImageWindow(const entry_ref *ref,112 ShowImageWindow::ShowImageWindow(const entry_ref* ref, 110 113 const BMessenger& trackerMessenger) 111 114 : 112 115 BWindow(BRect(5, 24, 250, 100), "", B_DOCUMENT_WINDOW, 0), … … 143 146 fImageView = new ShowImageView(viewFrame, "image_view", B_FOLLOW_ALL, 144 147 B_WILL_DRAW | B_FRAME_EVENTS | B_FULL_UPDATE_ON_RESIZE | B_PULSE_NEEDED); 145 148 // wrap a scroll view around the view 146 BScrollView *scrollView = new BScrollView("image_scroller", fImageView,149 BScrollView* scrollView = new BScrollView("image_scroller", fImageView, 147 150 B_FOLLOW_ALL, 0, false, false, B_PLAIN_BORDER); 148 151 AddChild(scrollView); 149 152 … … 154 157 rect.left = viewFrame.left + kstatusWidth; 155 158 rect.right = viewFrame.right + 1; 156 159 rect.bottom += 1; 157 BScrollBar *horizontalScrollBar = new BScrollBar(rect, "hscroll",160 BScrollBar* horizontalScrollBar = new BScrollBar(rect, "hscroll", 158 161 fImageView, 0, 150, B_HORIZONTAL); 159 162 AddChild(horizontalScrollBar); 160 163 … … 170 173 rect.left = viewFrame.right + 1; 171 174 rect.bottom = viewFrame.bottom + 1; 172 175 rect.right += 1; 173 BScrollBar *verticalScrollBar = new BScrollBar(rect, "vscroll", fImageView,176 BScrollBar* verticalScrollBar = new BScrollBar(rect, "vscroll", fImageView, 174 177 0, 150, B_VERTICAL); 175 178 AddChild(verticalScrollBar); 176 179 … … 180 183 fImageView->SetImage(ref); 181 184 fImageView->SetTrackerMessenger(trackerMessenger); 182 185 186 #undef TR_CONTEXT 187 #define TR_CONTEXT "LoadAlerts" 188 183 189 if (InitCheck() != B_OK) { 184 190 BAlert* alert; 185 alert = new BAlert( "ShowImage",186 "Could not load image! Either the file or an image translator for "187 "it does not exist.", "OK", NULL, NULL, B_WIDTH_AS_USUAL, B_INFO_ALERT);191 alert = new BAlert(TR("ShowImage"), 192 TR("Could not load image! Either the file or an image translator for it does not exist."), 193 TR("OK"), NULL, NULL, B_WIDTH_AS_USUAL, B_INFO_ALERT); 188 194 alert->Go(); 189 195 190 196 // quit if file could not be opened … … 192 198 return; 193 199 } 194 200 201 #undef TR_CONTEXT 202 #define TR_CONTEXT "Menus" 203 195 204 // add View menu here so it can access ShowImageView methods 196 BMenu* menu = new BMenu( "View");205 BMenu* menu = new BMenu(TR("View")); 197 206 _BuildViewMenu(menu, false); 198 207 fBar->AddItem(menu); 199 208 _MarkMenuItem(fBar, MSG_DITHER_IMAGE, fImageView->GetDither()); … … 238 247 239 248 240 249 void 241 ShowImageWindow::BuildContextMenu(BMenu *menu)250 ShowImageWindow::BuildContextMenu(BMenu* menu) 242 251 { 243 252 _BuildViewMenu(menu, true); 244 253 } 245 254 246 255 256 #undef TR_CONTEXT 257 #define TR_CONTEXT "Menus" 258 247 259 void 248 ShowImageWindow::_BuildViewMenu(BMenu *menu, bool popupMenu)260 ShowImageWindow::_BuildViewMenu(BMenu* menu, bool popupMenu) 249 261 { 250 _AddItemMenu(menu, "Slide show", MSG_SLIDE_SHOW, 0, 0, this);262 _AddItemMenu(menu, TR("Slide show"), MSG_SLIDE_SHOW, 0, 0, this); 251 263 _MarkMenuItem(menu, MSG_SLIDE_SHOW, fImageView->SlideShowStarted()); 252 BMenu* delayMenu = new BMenu( "Slide delay");264 BMenu* delayMenu = new BMenu(TR("Slide delay")); 253 265 if (fSlideShowDelay == NULL) 254 266 fSlideShowDelay = delayMenu; 255 267 … … 258 270 // if slide show delay is too short! (Especially if loading the image 259 271 // takes as long as or longer than the slide show delay). Should load 260 272 // in background thread! 261 _AddDelayItem(delayMenu, "3 seconds", 3);262 _AddDelayItem(delayMenu, "4 seconds", 4);263 _AddDelayItem(delayMenu, "5 seconds", 5);264 _AddDelayItem(delayMenu, "6 seconds", 6);265 _AddDelayItem(delayMenu, "7 seconds", 7);266 _AddDelayItem(delayMenu, "8 seconds", 8);267 _AddDelayItem(delayMenu, "9 seconds", 9);268 _AddDelayItem(delayMenu, "10 seconds", 10);269 _AddDelayItem(delayMenu, "20 seconds", 20);273 _AddDelayItem(delayMenu, TR("3 seconds"), 3); 274 _AddDelayItem(delayMenu, TR("4 seconds"), 4); 275 _AddDelayItem(delayMenu, TR("5 seconds"), 5); 276 _AddDelayItem(delayMenu, TR("6 seconds"), 6); 277 _AddDelayItem(delayMenu, TR("7 seconds"), 7); 278 _AddDelayItem(delayMenu, TR("8 seconds"), 8); 279 _AddDelayItem(delayMenu, TR("9 seconds"), 9); 280 _AddDelayItem(delayMenu, TR("10 seconds"), 10); 281 _AddDelayItem(delayMenu, TR("20 seconds"), 20); 270 282 menu->AddItem(delayMenu); 271 283 272 284 menu->AddSeparatorItem(); 273 285 274 _AddItemMenu(menu, "Original size", MSG_ORIGINAL_SIZE, '1', 0, this);275 _AddItemMenu(menu, "Zoom in", MSG_ZOOM_IN, '+', 0, this);276 _AddItemMenu(menu, "Zoom out", MSG_ZOOM_OUT, '-', 0, this);286 _AddItemMenu(menu, TR("Original size"), MSG_ORIGINAL_SIZE, '1', 0, this); 287 _AddItemMenu(menu, TR("Zoom in"), MSG_ZOOM_IN, '+', 0, this); 288 _AddItemMenu(menu, TR("Zoom out"), MSG_ZOOM_OUT, '-', 0, this); 277 289 278 290 menu->AddSeparatorItem(); 279 291 280 _AddItemMenu(menu, "High-quality zooming", MSG_SCALE_BILINEAR, 0, 0, this);292 _AddItemMenu(menu, TR("High-quality zooming"), MSG_SCALE_BILINEAR, 0, 0, this); 281 293 282 294 menu->AddSeparatorItem(); 283 295 284 _AddItemMenu(menu, "Shrink to window", MSG_SHRINK_TO_WINDOW, 0, 0, this);285 _AddItemMenu(menu, "Zoom to window", MSG_ZOOM_TO_WINDOW, 0, 0, this);296 _AddItemMenu(menu, TR("Shrink to window"), MSG_SHRINK_TO_WINDOW, 0, 0, this); 297 _AddItemMenu(menu, TR("Zoom to window"), MSG_ZOOM_TO_WINDOW, 0, 0, this); 286 298 287 299 menu->AddSeparatorItem(); 288 300 289 _AddItemMenu(menu, "Full screen", MSG_FULL_SCREEN, B_ENTER, 0, this);301 _AddItemMenu(menu, TR("Full screen"), MSG_FULL_SCREEN, B_ENTER, 0, this); 290 302 _MarkMenuItem(menu, MSG_FULL_SCREEN, fFullScreen); 291 303 292 _AddItemMenu(menu, "Show caption in full screen mode", MSG_SHOW_CAPTION, 0,304 _AddItemMenu(menu, TR("Show caption in full screen mode"), MSG_SHOW_CAPTION, 0, 293 305 0, this); 294 306 _MarkMenuItem(menu, MSG_SHOW_CAPTION, fShowCaption); 295 307 … … 309 321 310 322 if (popupMenu) { 311 323 menu->AddSeparatorItem(); 312 _AddItemMenu(menu, "Use as background" B_UTF8_ELLIPSIS, MSG_DESKTOP_BACKGROUND, 0, 0,313 this);324 _AddItemMenu(menu, TR("Use as background" B_UTF8_ELLIPSIS), 325 MSG_DESKTOP_BACKGROUND, 0, 0, this); 314 326 } 315 327 } 316 328 317 329 318 330 void 319 ShowImageWindow::AddMenus(BMenuBar *bar)331 ShowImageWindow::AddMenus(BMenuBar* bar) 320 332 { 321 BMenu *menu = new BMenu("File");322 fOpenMenu = new RecentDocumentsMenu( "Open");333 BMenu* menu = new BMenu(TR("File")); 334 fOpenMenu = new RecentDocumentsMenu(TR("Open")); 323 335 menu->AddItem(fOpenMenu); 324 336 fOpenMenu->Superitem()->SetTrigger('O'); 325 337 fOpenMenu->Superitem()->SetMessage(new BMessage(MSG_FILE_OPEN)); 326 338 fOpenMenu->Superitem()->SetTarget(be_app); 327 339 fOpenMenu->Superitem()->SetShortcut('O', 0); 328 340 menu->AddSeparatorItem(); 329 BMenu *pmenuSaveAs = new BMenu("Save as" B_UTF8_ELLIPSIS, B_ITEMS_IN_COLUMN); 341 BMenu *pmenuSaveAs = new BMenu(TR("Save as" B_UTF8_ELLIPSIS), 342 B_ITEMS_IN_COLUMN); 330 343 BTranslationUtils::AddTranslationItems(pmenuSaveAs, B_TRANSLATOR_BITMAP); 331 344 // Fill Save As submenu with all types that can be converted 332 345 // to from the Be bitmap image format 333 346 menu->AddItem(pmenuSaveAs); 334 _AddItemMenu(menu, "Close", B_QUIT_REQUESTED, 'W', 0, this);347 _AddItemMenu(menu, TR("Close"), B_QUIT_REQUESTED, 'W', 0, this); 335 348 menu->AddSeparatorItem(); 336 _AddItemMenu(menu, "Page setup" B_UTF8_ELLIPSIS, MSG_PAGE_SETUP, 0, 0, this); 337 _AddItemMenu(menu, "Print" B_UTF8_ELLIPSIS, MSG_PREPARE_PRINT, 'P', 0, this); 349 _AddItemMenu(menu, TR("Page setup" B_UTF8_ELLIPSIS), 350 MSG_PAGE_SETUP, 0, 0, this); 351 _AddItemMenu(menu, TR("Print" B_UTF8_ELLIPSIS), 352 MSG_PREPARE_PRINT, 'P', 0, this); 338 353 menu->AddSeparatorItem(); 339 _AddItemMenu(menu, "About ShowImage" B_UTF8_ELLIPSIS, B_ABOUT_REQUESTED, 0, 0,340 be_app);354 _AddItemMenu(menu, TR("About ShowImage" B_UTF8_ELLIPSIS), 355 B_ABOUT_REQUESTED, 0, 0, be_app); 341 356 menu->AddSeparatorItem(); 342 _AddItemMenu(menu, "Quit", B_QUIT_REQUESTED, 'Q', 0, be_app);357 _AddItemMenu(menu, TR("Quit"), B_QUIT_REQUESTED, 'Q', 0, be_app); 343 358 bar->AddItem(menu); 344 359 345 menu = new BMenu( "Edit");346 _AddItemMenu(menu, "Undo", B_UNDO, 'Z', 0, this, false);360 menu = new BMenu(TR("Edit")); 361 _AddItemMenu(menu, TR("Undo"), B_UNDO, 'Z', 0, this, false); 347 362 menu->AddSeparatorItem(); 348 _AddItemMenu(menu, "Cut", B_CUT, 'X', 0, this, false);349 _AddItemMenu(menu, "Copy", B_COPY, 'C', 0, this, false);350 _AddItemMenu(menu, "Paste", B_PASTE, 'V', 0, this, false);351 _AddItemMenu(menu, "Clear", MSG_CLEAR_SELECT, 0, 0, this, false);363 _AddItemMenu(menu, TR("Cut"), B_CUT, 'X', 0, this, false); 364 _AddItemMenu(menu, TR("Copy"), B_COPY, 'C', 0, this, false); 365 _AddItemMenu(menu, TR("Paste"), B_PASTE, 'V', 0, this, false); 366 _AddItemMenu(menu, TR("Clear"), MSG_CLEAR_SELECT, 0, 0, this, false); 352 367 menu->AddSeparatorItem(); 353 _AddItemMenu(menu, "Select all", MSG_SELECT_ALL, 'A', 0, this);368 _AddItemMenu(menu, TR("Select all"), MSG_SELECT_ALL, 'A', 0, this); 354 369 bar->AddItem(menu); 355 370 356 menu = fBrowseMenu = new BMenu("Browse"); 357 _AddItemMenu(menu, "First page", MSG_PAGE_FIRST, B_LEFT_ARROW, B_SHIFT_KEY, this); 358 _AddItemMenu(menu, "Last page", MSG_PAGE_LAST, B_RIGHT_ARROW, B_SHIFT_KEY, this); 359 _AddItemMenu(menu, "Previous page", MSG_PAGE_PREV, B_LEFT_ARROW, 0, this); 360 _AddItemMenu(menu, "Next page", MSG_PAGE_NEXT, B_RIGHT_ARROW, 0, this); 361 fGoToPageMenu = new BMenu("Go to page"); 371 menu = fBrowseMenu = new BMenu(TR("Browse")); 372 _AddItemMenu(menu, TR("First page"), 373 MSG_PAGE_FIRST, B_LEFT_ARROW, B_SHIFT_KEY, this); 374 _AddItemMenu(menu, TR("Last page"), 375 MSG_PAGE_LAST, B_RIGHT_ARROW, B_SHIFT_KEY, this); 376 _AddItemMenu(menu, TR("Previous page"), MSG_PAGE_PREV, B_LEFT_ARROW, 0, this); 377 _AddItemMenu(menu, TR("Next page"), MSG_PAGE_NEXT, B_RIGHT_ARROW, 0, this); 378 fGoToPageMenu = new BMenu(TR("Go to page")); 362 379 fGoToPageMenu->SetRadioMode(true); 363 380 menu->AddItem(fGoToPageMenu); 364 381 menu->AddSeparatorItem(); 365 _AddItemMenu(menu, "Previous file", MSG_FILE_PREV, B_UP_ARROW, 0, this);366 _AddItemMenu(menu, "Next file", MSG_FILE_NEXT, B_DOWN_ARROW, 0, this);382 _AddItemMenu(menu, TR("Previous file"), MSG_FILE_PREV, B_UP_ARROW, 0, this); 383 _AddItemMenu(menu, TR("Next file"), MSG_FILE_NEXT, B_DOWN_ARROW, 0, this); 367 384 bar->AddItem(menu); 368 385 369 menu = new BMenu("Image"); 370 _AddItemMenu(menu, "Rotate clockwise", MSG_ROTATE_90, 'R', 0, this); 371 _AddItemMenu(menu, "Rotate counterclockwise", MSG_ROTATE_270, 'R', B_SHIFT_KEY, this); 386 menu = new BMenu(TR("Image")); 387 _AddItemMenu(menu, TR("Rotate clockwise"), MSG_ROTATE_90, 'R', 0, this); 388 _AddItemMenu(menu, TR("Rotate counterclockwise"), 389 MSG_ROTATE_270, 'R', B_SHIFT_KEY, this); 372 390 menu->AddSeparatorItem(); 373 _AddItemMenu(menu, "Flip left to right", MSG_FLIP_LEFT_TO_RIGHT, 0, 0, this); 374 _AddItemMenu(menu, "Flip top to bottom", MSG_FLIP_TOP_TO_BOTTOM, 0, 0, this); 391 _AddItemMenu(menu, TR("Flip left to right"), 392 MSG_FLIP_LEFT_TO_RIGHT, 0, 0, this); 393 _AddItemMenu(menu, TR("Flip top to bottom"), 394 MSG_FLIP_TOP_TO_BOTTOM, 0, 0, this); 375 395 menu->AddSeparatorItem(); 376 _AddItemMenu(menu, "Invert colors", MSG_INVERT, 0, 0, this);396 _AddItemMenu(menu, TR("Invert colors"), MSG_INVERT, 0, 0, this); 377 397 menu->AddSeparatorItem(); 378 fResizeItem = _AddItemMenu(menu, "Resize" B_UTF8_ELLIPSIS,398 fResizeItem = _AddItemMenu(menu, TR("Resize" B_UTF8_ELLIPSIS), 379 399 MSG_OPEN_RESIZER_WINDOW, 0, 0, this); 380 400 bar->AddItem(menu); 381 401 menu->AddSeparatorItem(); 382 _AddItemMenu(menu, "Use as background" B_UTF8_ELLIPSIS, MSG_DESKTOP_BACKGROUND, 0, 0,383 this);402 _AddItemMenu(menu, TR("Use as background" B_UTF8_ELLIPSIS), 403 MSG_DESKTOP_BACKGROUND, 0, 0, this); 384 404 } 385 405 386 406 387 407 BMenuItem* 388 ShowImageWindow::_AddItemMenu(BMenu *menu, const char *label, uint32 what,389 const char shortcut, uint32 modifier, const BHandler *target, bool enabled)408 ShowImageWindow::_AddItemMenu(BMenu* menu, const char* label, uint32 what, 409 const char shortcut, uint32 modifier, const BHandler* target, bool enabled) 390 410 { 391 411 BMenuItem* item = new BMenuItem(label, new BMessage(what), shortcut, modifier); 392 412 menu->AddItem(item); … … 399 419 400 420 401 421 BMenuItem* 402 ShowImageWindow::_AddDelayItem(BMenu *menu, const char *label, float value)422 ShowImageWindow::_AddDelayItem(BMenu* menu, const char* label, float value) 403 423 { 404 424 BMessage* message = new BMessage(MSG_SLIDE_SHOW_DELAY); 405 425 message->AddFloat("value", value); … … 417 437 418 438 419 439 void 420 ShowImageWindow::WindowRedimension(BBitmap *pbitmap)440 ShowImageWindow::WindowRedimension(BBitmap* pbitmap) 421 441 { 422 442 BScreen screen; 423 443 if (!screen.IsValid()) … … 468 488 ShowImageWindow::_ToggleMenuItem(uint32 what) 469 489 { 470 490 bool marked = false; 471 BMenuItem *item = fBar->FindItem(what);491 BMenuItem* item = fBar->FindItem(what); 472 492 if (item != NULL) { 473 493 marked = !item->IsMarked(); 474 494 item->SetMarked(marked); … … 478 498 479 499 480 500 void 481 ShowImageWindow::_EnableMenuItem(BMenu *menu, uint32 what, bool enable)501 ShowImageWindow::_EnableMenuItem(BMenu* menu, uint32 what, bool enable) 482 502 { 483 503 BMenuItem* item = menu->FindItem(what); 484 504 if (item && item->IsEnabled() != enable) … … 487 507 488 508 489 509 void 490 ShowImageWindow::_MarkMenuItem(BMenu *menu, uint32 what, bool marked)510 ShowImageWindow::_MarkMenuItem(BMenu* menu, uint32 what, bool marked) 491 511 { 492 512 BMenuItem* item = menu->FindItem(what); 493 513 if (item && item->IsMarked() != marked) … … 530 550 531 551 532 552 void 533 ShowImageWindow::MessageReceived(BMessage *message)553 ShowImageWindow::MessageReceived(BMessage* message) 534 554 { 535 555 switch (message->what) { 536 556 case MSG_MODIFIED: … … 578 598 579 599 for (int32 i = 1; i <= pages; i++) { 580 600 // Fill Go To page submenu with an entry for each page 581 BMessage *pgomsg = new BMessage(MSG_GOTO_PAGE);601 BMessage* pgomsg = new BMessage(MSG_GOTO_PAGE); 582 602 pgomsg->AddInt32("page", i); 583 603 584 604 char shortcut = 0; … … 591 611 BString strCaption; 592 612 strCaption << i; 593 613 594 BMenuItem *item = new BMenuItem(strCaption.String(), pgomsg,614 BMenuItem* item = new BMenuItem(strCaption.String(), pgomsg, 595 615 shortcut); 596 616 if (curPage == i) 597 617 item->SetMarked(true); … … 786 806 break; 787 807 788 808 case MSG_SLIDE_SHOW: { 789 BMenuItem *item = fBar->FindItem(message->what);809 BMenuItem* item = fBar->FindItem(message->what); 790 810 if (!item) 791 811 break; 792 812 if (item->IsMarked()) { … … 892 912 893 913 894 914 void 895 ShowImageWindow::_SaveAs(BMessage *message)915 ShowImageWindow::_SaveAs(BMessage* message) 896 916 { 897 917 // Read the translator and output type the user chose 898 918 translator_id outTranslator; … … 922 942 923 943 924 944 void 925 ShowImageWindow::_SaveToFile(BMessage *message)945 ShowImageWindow::_SaveToFile(BMessage* message) 926 946 { 927 947 // Read in where the file should be saved 928 948 entry_ref dirRef; 929 949 if (message->FindRef("directory", &dirRef) != B_OK) 930 950 return; 931 951 932 const char *filename;952 const char* filename; 933 953 if (message->FindString("name", &filename) != B_OK) 934 954 return; 935 955 … … 945 965 946 966 // Find the translator_format information needed to 947 967 // write a MIME attribute for the image file 948 BTranslatorRoster *roster = BTranslatorRoster::Default();949 const translation_format *outFormat = NULL;968 BTranslatorRoster* roster = BTranslatorRoster::Default(); 969 const translation_format* outFormat = NULL; 950 970 int32 outCount = 0; 951 971 if (roster->GetOutputFormats(outTranslator, &outFormat, &outCount) != B_OK 952 972 || outCount < 1) … … 966 986 } 967 987 968 988 989 // This is temporary solution for building BString with printf like format. 990 // will be removed in the future. 991 static void 992 bs_printf(BString* string, const char* format, ...) 993 { 994 va_list ap; 995 va_start(ap, format); 996 char* buf; 997 vasprintf(&buf, format, ap); 998 string->SetTo(buf); 999 free(buf); 1000 va_end(ap); 1001 } 1002 1003 1004 #undef TR_CONTEXT 1005 #define TR_CONTEXT "ClosePrompt" 1006 969 1007 bool 970 1008 ShowImageWindow::_ClosePrompt() 971 1009 { … … 977 1015 page = fImageView->CurrentPage(); 978 1016 BString prompt, name; 979 1017 fImageView->GetName(&name); 980 prompt << "The document '" << name << "'";981 if (count > 1)982 prompt << " (page " << page << ")";983 1018 984 prompt << " has been changed. " 985 << "Do you want to close the document?"; 986 BAlert *pAlert = new BAlert("Close document", prompt.String(), 987 "Cancel", "Close"); 1019 if (count > 1) { 1020 bs_printf(&prompt, 1021 TR("The document '%s' (page %d) has been changed. Do you want to close the document?"), 1022 name.String(), page); 1023 } else { 1024 bs_printf(&prompt, 1025 TR("The document '%s' has been changed. Do you want to close the document?"), 1026 name.String()); 1027 } 1028 1029 BAlert* pAlert = new BAlert(TR("Close document"), prompt.String(), 1030 TR("Cancel"), TR("Close")); 988 1031 if (pAlert->Go() == 0) { 989 1032 // Cancel 990 1033 return false; … … 1104 1147 } 1105 1148 1106 1149 fPrintOptions.SetBounds(fImageView->GetBitmap()->Bounds()); 1107 fPrintOptions.SetWidth(fImageView->GetBitmap()->Bounds().Width() +1);1150 fPrintOptions.SetWidth(fImageView->GetBitmap()->Bounds().Width() + 1); 1108 1151 1109 new PrintOptionsWindow(BPoint(Frame().left +30, Frame().top+50),1152 new PrintOptionsWindow(BPoint(Frame().left + 30, Frame().top + 50), 1110 1153 &fPrintOptions, this); 1111 1154 } 1112 1155 1113 1156 1114 1157 void 1115 ShowImageWindow::_Print(BMessage *msg)1158 ShowImageWindow::_Print(BMessage* msg) 1116 1159 { 1117 1160 status_t st; 1118 1161 if (msg->FindInt32("status", &st) != B_OK || st != B_OK) -
ResizerWindow.cpp
17 17 18 18 #include <Box.h> 19 19 #include <Button.h> 20 #include <Catalog.h> 20 21 #include <CheckBox.h> 22 #include <GroupLayoutBuilder.h> 23 #include <GridLayoutBuilder.h> 24 #include <Locale.h> 25 #include <LayoutBuilder.h> 21 26 #include <RadioButton.h> 22 27 #include <Rect.h> 23 28 #include <String.h> … … 26 31 #include "ShowImageConstants.h" 27 32 28 33 29 static const char* kWidthLabel = "Width:"; 30 static const char* kHeightLabel = "Height:"; 31 static const char* kKeepAspectRatioLabel = "Keep original proportions"; 32 static const char* kApplyLabel = "Apply"; 34 #undef TR_CONTEXT 35 #define TR_CONTEXT "ResizerWindow" 33 36 34 static const float kLineDistance = 5;35 static const float kHorizontalIndent = 10;36 static const float kVerticalIndent = 10;37 38 39 37 ResizerWindow::ResizerWindow(BMessenger target, int32 width, int32 height) 40 38 : 41 BWindow(BRect(100, 100, 300, 300), "Resize", B_FLOATING_WINDOW,42 B_NOT_ZOOMABLE | B_NOT_RESIZABLE ),39 BWindow(BRect(100, 100, 300, 300), TR("Resize"), B_FLOATING_WINDOW, 40 B_NOT_ZOOMABLE | B_NOT_RESIZABLE | B_AUTO_UPDATE_SIZE_LIMITS), 43 41 fOriginalWidth(width), 44 42 fOriginalHeight(height), 45 43 fTarget(target) 46 44 { 47 BView* back_view = new BView(Bounds(), "", B_FOLLOW_ALL, B_WILL_DRAW);48 back_view->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));49 AddChild(back_view);50 51 const float widthLabelWidth = back_view->StringWidth(kWidthLabel);52 const float heightLabelWidth = back_view->StringWidth(kHeightLabel);53 const float column2 = max_c(widthLabelWidth, heightLabelWidth);54 55 const float textControlWidth = column2 + back_view->StringWidth("999999");56 const float keepAspectRatioLabelWidth = 2057 + back_view->StringWidth(kKeepAspectRatioLabel);58 const float width2 = 2 * kHorizontalIndent59 + max_c(textControlWidth, keepAspectRatioLabelWidth);60 61 ResizeTo(width2+1, Bounds().Height()+1);62 63 const float top = kVerticalIndent;64 const float left = kHorizontalIndent;65 BRect rect(left, top, width2 - kHorizontalIndent, top + 10);66 67 45 BString widthValue; 68 46 widthValue << width; 69 fWidth = new BTextControl(rect, "width", kWidthLabel, widthValue.String(), 70 NULL); 47 fWidth = new BTextControl("width", TR("Width:"), widthValue.String(), NULL); 71 48 fWidth->SetModificationMessage(new BMessage(kWidthModifiedMsg)); 72 AddControl(back_view, fWidth, column2, rect); 73 49 74 50 BString heightValue; 75 51 heightValue << height; 76 fHeight = new BTextControl( rect, "height", kHeightLabel,77 heightValue.String(), NULL);52 fHeight = new BTextControl("height", 53 TR("Height:"), heightValue.String(), NULL); 78 54 fHeight->SetModificationMessage(new BMessage(kHeightModifiedMsg)); 79 AddControl(back_view, fHeight, column2, rect); 80 81 fAspectRatio = new BCheckBox(rect, "Ratio", kKeepAspectRatioLabel, 82 new BMessage(kWidthModifiedMsg)); 55 56 fAspectRatio = new BCheckBox("Ratio", 57 TR("Keep original proportions"), new BMessage(kWidthModifiedMsg)); 83 58 fAspectRatio->SetValue(B_CONTROL_ON); 84 AddControl(back_view, fAspectRatio, column2, rect); 85 86 fApply = new BButton(rect, "apply", kApplyLabel, new BMessage(kApplyMsg)); 59 60 fApply = new BButton("apply", TR("Apply"), new BMessage(kApplyMsg)); 87 61 fApply->MakeDefault(true); 88 AddControl(back_view, fApply, column2, rect); 89 LeftAlign(fApply); 62 63 SetLayout(new BGroupLayout(B_HORIZONTAL)); 64 AddChild(BGroupLayoutBuilder(B_VERTICAL, 5) 65 .Add(BGridLayoutBuilder(4, 4) 66 .Add(fWidth->CreateLabelLayoutItem(), 0, 0) 67 .Add(fWidth->CreateTextViewLayoutItem(), 1, 0) 68 .Add(fHeight->CreateLabelLayoutItem(), 0, 1) 69 .Add(fHeight->CreateTextViewLayoutItem(), 1, 1) 70 ) 71 .Add(fAspectRatio) 72 .AddGroup(B_HORIZONTAL, 0) 73 .AddGlue() 74 .Add(fApply) 75 .End() 76 .SetInsets(10, 10, 10, 10) 77 ); 90 78 91 79 fWidth->MakeFocus(); 92 93 ResizeTo(width2, rect.top); 80 94 81 } 95 82 96 83 … … 99 86 } 100 87 101 88 102 void103 ResizerWindow::AddControl(BView* view, BControl* control, float column2,104 BRect& rect)105 {106 float width, height;107 view->AddChild(control);108 control->GetPreferredSize(&width, &height);109 if (dynamic_cast<BButton*>(control) != NULL) {110 control->ResizeTo(width, height);111 } else {112 control->ResizeTo(control->Bounds().Width(), height);113 }114 float top = control->Frame().bottom + kLineDistance;115 rect.OffsetTo(rect.left, top);116 117 if (dynamic_cast<BTextControl*>(control) != NULL) {118 ((BTextControl*)control)->SetDivider(column2);119 }120 }121 122 123 void124 ResizerWindow::AddSeparatorLine(BView* view, BRect& rect)125 {126 const float lineWidth = 3;127 BRect line(Bounds());128 line.left += 3;129 line.right -= 3;130 line.top = rect.top;131 line.bottom = line.top + lineWidth - 1;132 BBox* separatorLine = new BBox(line, "", B_FOLLOW_LEFT_RIGHT,133 B_WILL_DRAW | B_FRAME_EVENTS, B_PLAIN_BORDER);134 view->AddChild(separatorLine);135 rect.OffsetBy(0, kLineDistance + lineWidth);136 }137 138 139 void140 ResizerWindow::LeftAlign(BControl* control)141 {142 BRect frame = control->Frame();143 float left = Bounds().Width() - frame.Width() - kHorizontalIndent;144 control->MoveTo(left, frame.top);145 }146 147 148 89 void 149 90 ResizerWindow::MessageReceived(BMessage* message) 150 91 { -
ResizerWindow.h
15 15 16 16 17 17 #include <Messenger.h> 18 #include <View.h>19 18 #include <Window.h> 20 19 21 20 class BCheckBox; … … 50 49 kApplyMsg, 51 50 }; 52 51 53 void AddControl(BView* parent, BControl* control,54 float column2, BRect& rect);55 void AddSeparatorLine(BView* parent, BRect& rect);56 void LeftAlign(BControl* control);57 52 58 53 BTextControl* fWidth; 59 54 BTextControl* fHeight; -
ShowImageApp.cpp
15 15 16 16 #include <AboutWindow.h> 17 17 #include <Alert.h> 18 #include <Catalog.h> 18 19 #include <Clipboard.h> 19 20 #include <FilePanel.h> 21 #include <Locale.h> 20 22 #include <Path.h> 21 23 #include <String.h> 22 24 … … 26 28 27 29 #define WINDOWS_TO_IGNORE 1 28 30 29 extern const char *kApplicationSignature = "application/x-vnd.Haiku-ShowImage";31 extern const char* kApplicationSignature = "application/x-vnd.Haiku-ShowImage"; 30 32 31 33 32 34 ShowImageApp::ShowImageApp() 33 35 : 34 36 BApplication(kApplicationSignature) 35 37 { 38 be_locale->GetAppCatalog(&fCatalog); 39 36 40 fPulseStarted = false; 37 41 fOpenPanel = new BFilePanel(B_OPEN_PANEL); 38 42 } … … 43 47 } 44 48 45 49 50 #undef TR_CONTEXT 51 #define TR_CONTEXT "AboutWindow" 52 46 53 void 47 54 ShowImageApp::AboutRequested() 48 55 { 49 const char *authors[] = {56 const char* authors[] = { 50 57 "Fernando F. Oliveira", 51 58 "Michael Wilber", 52 59 "Michael Pfeiffer", 53 60 "Ryan Leavengood", 54 61 NULL 55 62 }; 56 BAboutWindow about( "ShowImage", 2003, authors);63 BAboutWindow about(TR("ShowImage"), 2003, authors); 57 64 about.Show(); 58 65 } 59 66 … … 109 116 bool hasRefs = false; 110 117 111 118 // get current working directory 112 const char *cwd;119 const char* cwd; 113 120 if (CurrentMessage() == NULL 114 121 || CurrentMessage()->FindString("cwd", &cwd) != B_OK) 115 122 cwd = ""; … … 139 146 140 147 141 148 void 142 ShowImageApp::MessageReceived(BMessage *message)149 ShowImageApp::MessageReceived(BMessage* message) 143 150 { 144 151 switch (message->what) { 145 152 case MSG_FILE_OPEN: … … 167 174 168 175 169 176 void 170 ShowImageApp::RefsReceived(BMessage *message)177 ShowImageApp::RefsReceived(BMessage* message) 171 178 { 172 179 // If a tracker window opened me, get a messenger from it. 173 180 if (message->HasMessenger("TrackerViewToken")) … … 188 195 189 196 190 197 void 191 ShowImageApp::Open(const entry_ref *ref)198 ShowImageApp::Open(const entry_ref* ref) 192 199 { 193 200 new ShowImageWindow(ref, fTrackerMessenger); 194 201 } 195 202 196 203 197 204 void 198 ShowImageApp::BroadcastToWindows(BMessage *message)205 ShowImageApp::BroadcastToWindows(BMessage* message) 199 206 { 200 207 const int32 count = CountWindows(); 201 208 for (int32 i = 0; i < count; i ++) { … … 217 224 bool dataAvailable = false; 218 225 219 226 if (be_clipboard->Lock()) { 220 BMessage *clip = be_clipboard->Data();227 BMessage* clip = be_clipboard->Data(); 221 228 if (clip != NULL) { 222 229 BString className; 223 230 if (clip->FindString("class", &className) == B_OK) { -
Jamfile
17 17 ProgressWindow.cpp 18 18 ResizerWindow.cpp 19 19 : libshared.a 20 be tracker translation $(TARGET_LIBSUPC++)20 be tracker translation liblocale.so $(TARGET_LIBSUPC++) 21 21 : ShowImage.rdef 22 22 ; 23 23 24 DoCatalogs ShowImage : 25 x-vnd.Haiku-ShowImage 26 : 27 PrintOptionsWindow.cpp 28 ResizerWindow.cpp 29 ShowImageApp.cpp 30 ShowImageWindow.cpp 31 : en.catalog 32 : 33 ; -
ShowImageApp.h
14 14 #include "ShowImageSettings.h" 15 15 16 16 #include <Application.h> 17 #include <Catalog.h> 17 18 #include <FilePanel.h> 18 19 19 20 … … 42 43 BFilePanel *fOpenPanel; 43 44 bool fPulseStarted; 44 45 ShowImageSettings fSettings; 46 BCatalog fCatalog; 45 47 }; 46 48 47 49