Patch by mt. Localization and conversion to use the layout API with coding style

fixes along the way. Thanks a lot! Fixes #5563.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@35929 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stephan Aßmus 2010-03-22 14:46:01 +00:00
parent af3253dea5
commit 1ed4535f34
8 changed files with 280 additions and 277 deletions

View File

@ -17,7 +17,17 @@ Application ShowImage :
ProgressWindow.cpp
ResizerWindow.cpp
: libshared.a
be tracker translation $(TARGET_LIBSUPC++)
be tracker translation liblocale.so $(TARGET_LIBSUPC++)
: ShowImage.rdef
;
DoCatalogs ShowImage :
x-vnd.Haiku-ShowImage
:
PrintOptionsWindow.cpp
ResizerWindow.cpp
ShowImageApp.cpp
ShowImageWindow.cpp
: en.catalog
:
;

View File

@ -13,6 +13,12 @@
#include <Box.h>
#include <Button.h>
#include <Catalog.h>
#include <ControlLook.h>
#include <GroupLayoutBuilder.h>
#include <GridLayoutBuilder.h>
#include <Locale.h>
#include <LayoutBuilder.h>
#include <String.h>
#include "ShowImageConstants.h"
@ -68,12 +74,15 @@ PrintOptions::SetHeight(float h)
}
#undef TR_CONTEXT
#define TR_CONTEXT "PrintOptionsWindow"
PrintOptionsWindow::PrintOptionsWindow(BPoint at, PrintOptions* options,
BWindow* listener)
:
BWindow(BRect(at.x, at.y, at.x + 300, at.y + 200), "Print options",
BWindow(BRect(at.x, at.y, at.x + 300, at.y + 200), TR("Print options"),
B_TITLED_WINDOW_LOOK, B_MODAL_SUBSET_WINDOW_FEEL,
B_NOT_ZOOMABLE | B_NOT_RESIZABLE),
B_NOT_ZOOMABLE | B_NOT_RESIZABLE | B_AUTO_UPDATE_SIZE_LIMITS),
fPrintOptions(options),
fCurrentOptions(*options),
fListener(listener),
@ -94,35 +103,24 @@ PrintOptionsWindow::~PrintOptionsWindow()
BRadioButton*
PrintOptionsWindow::AddRadioButton(BView* view, BPoint& at, const char* name,
PrintOptionsWindow::AddRadioButton(const char* name,
const char* label, uint32 what, bool selected)
{
BRect rect(0, 0, 100, 20);
BRadioButton* button;
rect.OffsetBy(at);
button = new BRadioButton(rect, name, label, new BMessage(what));
view->AddChild(button);
button->ResizeToPreferred();
at.y += button->Bounds().Height() + kLineSkip;
button = new BRadioButton(name, label, new BMessage(what));
button->SetValue(selected ? B_CONTROL_ON : B_CONTROL_OFF);
return button;
}
BTextControl*
PrintOptionsWindow::AddTextControl(BView* view, BPoint& at, const char* name,
const char* label, float value, float divider, uint32 what)
PrintOptionsWindow::AddTextControl(const char* name,
const char* label, float value, uint32 what)
{
BRect rect(0, 0, divider + 45, 20);
BTextControl* text;
rect.OffsetBy(at);
text = new BTextControl(rect, name, label, "", new BMessage(what));
view->AddChild(text);
text = new BTextControl(name, label, "", new BMessage(what));
text->SetModificationMessage(new BMessage(what));
text->SetDivider(divider);
text->SetAlignment(B_ALIGN_LEFT, B_ALIGN_RIGHT);
SetValue(text, value);
at.y += text->Bounds().Height() + kLineSkip;
return text;
}
@ -130,68 +128,72 @@ PrintOptionsWindow::AddTextControl(BView* view, BPoint& at, const char* name,
void
PrintOptionsWindow::Setup()
{
BRect rect(Bounds());
BPoint at(kIndent, kIndent), textAt;
BString value;
enum PrintOptions::Option op = fCurrentOptions.Option();
BRadioButton* rb;
BRadioButton* rbFit;
BRadioButton* rbZoom;
BRadioButton* rbDpi;
BRadioButton* rbResize;
BBox* line;
BButton* button;
BBox *panel = new BBox(rect, "top_panel", B_FOLLOW_ALL,
B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE_JUMP,
B_PLAIN_BORDER);
AddChild(panel);
AddRadioButton(panel, at, "fit_to_page", "Fit image to page",
rbFit = AddRadioButton("fit_to_page", TR("Fit image to page"),
kMsgFitToPageSelected, op == PrintOptions::kFitToPage);
textAt = at;
rb = AddRadioButton(panel, at, "zoom_factor", "Zoom factor in %: ",
rbZoom = AddRadioButton("zoom_factor", TR("Zoom factor in %:"),
kMsgZoomFactorSelected, op == PrintOptions::kZoomFactor);
textAt.x = rb->Bounds().right + 5;
fZoomFactor = AddTextControl(panel, textAt, "zoom_factor_text", "",
fCurrentOptions.ZoomFactor()*100, 0, kMsgZoomFactorChanged);
textAt = at;
rb = AddRadioButton(panel, at, "dpi", "DPI: ", kMsgDPISelected,
fZoomFactor = AddTextControl("zoom_factor_text", "",
fCurrentOptions.ZoomFactor() * 100, kMsgZoomFactorChanged);
rbDpi = AddRadioButton("dpi", TR("DPI:"), kMsgDPISelected,
op == PrintOptions::kDPI);
textAt.x = rb->Bounds().right + 5;
fDPI = AddTextControl(panel, textAt, "dpi_text", "", fCurrentOptions.DPI(),
0, kMsgDPIChanged);
rb = AddRadioButton(panel, at, "width_and_height",
"Resize to (in 1/72 inches):", kMsgWidthAndHeightSelected,
fDPI = AddTextControl("dpi_text", "", fCurrentOptions.DPI(),
kMsgDPIChanged);
rbResize = AddRadioButton("width_and_height",
TR("Resize to (in 1/72 inches):"), kMsgWidthAndHeightSelected,
op == PrintOptions::kWidth || op == PrintOptions::kHeight);
at.x += 15;
textAt = at;
fWidth = AddTextControl(panel, textAt, "width", "Width: ",
fCurrentOptions.Width(), 40, kMsgWidthChanged);
textAt = at;
textAt.x += fWidth->Bounds().Width() + 5;
fHeight = AddTextControl(panel, textAt, "height", "Height: ",
fCurrentOptions.Height(), 40, kMsgHeightChanged);
at.x = 0;
at.y = textAt.y;
line = new BBox(BRect(rect.left+3, at.y, rect.right-3, at.y + 1), NULL,
B_FOLLOW_LEFT | B_FOLLOW_TOP);
panel->AddChild(line);
fWidth = AddTextControl("width", TR("Width:"),
fCurrentOptions.Width(), kMsgWidthChanged);
at.y += 10;
rect.OffsetBy(at);
button = new BButton(rect, "job setup", "Job setup",
fHeight = AddTextControl("height", TR("Height: "),
fCurrentOptions.Height(), kMsgHeightChanged);
line = new BBox(B_EMPTY_STRING, B_WILL_DRAW | B_FRAME_EVENTS,
B_FANCY_BORDER);
line->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, 1));
button = new BButton("job setup", TR("Job setup"),
new BMessage(kMsgJobSetup));
panel->AddChild(button);
button->ResizeToPreferred();
SetDefaultButton(button);
// resize window
ResizeTo(fHeight->Frame().right + kIndent, button->Frame().bottom + kIndent);
const float spacing = be_control_look->DefaultItemSpacing();
// center button
button->MoveTo((Bounds().Width()-button->Bounds().Width())/2,
button->Frame().top);
SetLayout(new BGroupLayout(B_HORIZONTAL));
AddChild(BGroupLayoutBuilder(B_VERTICAL, 0)
.Add(BGridLayoutBuilder()
.Add(rbFit, 0, 0)
.Add(rbZoom, 0, 1)
.Add(fZoomFactor, 1, 1)
.Add(rbDpi, 0, 2)
.Add(fDPI, 1, 2)
.Add(rbResize, 0, 3)
)
.AddGroup(B_HORIZONTAL, spacing)
.Add(fWidth)
.Add(fHeight)
.AddGlue()
.SetInsets(22, 0, 0, 0)
.End()
.Add(line)
.AddGroup(B_HORIZONTAL, 0)
.Add(button)
.End()
.SetInsets(spacing, spacing, spacing, spacing)
);
}

View File

@ -64,13 +64,11 @@ public:
void MessageReceived(BMessage* msg);
private:
BRadioButton* AddRadioButton(BView* view, BPoint& at,
const char* name, const char* label,
BRadioButton* AddRadioButton(const char* name, const char* label,
uint32 what, bool selected);
BTextControl* AddTextControl(BView* view, BPoint& at,
const char* name, const char* label,
float value, float divider, uint32 what);
BTextControl* AddTextControl(const char* name, const char* label,
float value, uint32 what);
void Setup();
enum PrintOptions::Option MsgToOption(uint32 what);

View File

@ -17,7 +17,13 @@
#include <Box.h>
#include <Button.h>
#include <Catalog.h>
#include <CheckBox.h>
#include <ControlLook.h>
#include <GroupLayoutBuilder.h>
#include <GridLayoutBuilder.h>
#include <Locale.h>
#include <LayoutBuilder.h>
#include <RadioButton.h>
#include <Rect.h>
#include <String.h>
@ -26,71 +32,56 @@
#include "ShowImageConstants.h"
static const char* kWidthLabel = "Width:";
static const char* kHeightLabel = "Height:";
static const char* kKeepAspectRatioLabel = "Keep original proportions";
static const char* kApplyLabel = "Apply";
static const float kLineDistance = 5;
static const float kHorizontalIndent = 10;
static const float kVerticalIndent = 10;
#undef TR_CONTEXT
#define TR_CONTEXT "ResizerWindow"
ResizerWindow::ResizerWindow(BMessenger target, int32 width, int32 height)
:
BWindow(BRect(100, 100, 300, 300), "Resize", B_FLOATING_WINDOW,
B_NOT_ZOOMABLE | B_NOT_RESIZABLE),
BWindow(BRect(100, 100, 300, 300), TR("Resize"), B_FLOATING_WINDOW,
B_NOT_ZOOMABLE | B_NOT_RESIZABLE | B_AUTO_UPDATE_SIZE_LIMITS),
fOriginalWidth(width),
fOriginalHeight(height),
fTarget(target)
{
BView* back_view = new BView(Bounds(), "", B_FOLLOW_ALL, B_WILL_DRAW);
back_view->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
AddChild(back_view);
const float widthLabelWidth = back_view->StringWidth(kWidthLabel);
const float heightLabelWidth = back_view->StringWidth(kHeightLabel);
const float column2 = max_c(widthLabelWidth, heightLabelWidth);
const float textControlWidth = column2 + back_view->StringWidth("999999");
const float keepAspectRatioLabelWidth = 20
+ back_view->StringWidth(kKeepAspectRatioLabel);
const float width2 = 2 * kHorizontalIndent
+ max_c(textControlWidth, keepAspectRatioLabelWidth);
ResizeTo(width2+1, Bounds().Height()+1);
const float top = kVerticalIndent;
const float left = kHorizontalIndent;
BRect rect(left, top, width2 - kHorizontalIndent, top + 10);
BString widthValue;
widthValue << width;
fWidth = new BTextControl(rect, "width", kWidthLabel, widthValue.String(),
NULL);
fWidth = new BTextControl("width", TR("Width:"), widthValue.String(), NULL);
fWidth->SetModificationMessage(new BMessage(kWidthModifiedMsg));
AddControl(back_view, fWidth, column2, rect);
BString heightValue;
heightValue << height;
fHeight = new BTextControl(rect, "height", kHeightLabel,
heightValue.String(), NULL);
fHeight = new BTextControl("height",
TR("Height:"), heightValue.String(), NULL);
fHeight->SetModificationMessage(new BMessage(kHeightModifiedMsg));
AddControl(back_view, fHeight, column2, rect);
fAspectRatio = new BCheckBox(rect, "Ratio", kKeepAspectRatioLabel,
new BMessage(kWidthModifiedMsg));
fAspectRatio = new BCheckBox("Ratio",
TR("Keep original proportions"), new BMessage(kWidthModifiedMsg));
fAspectRatio->SetValue(B_CONTROL_ON);
AddControl(back_view, fAspectRatio, column2, rect);
fApply = new BButton(rect, "apply", kApplyLabel, new BMessage(kApplyMsg));
fApply = new BButton("apply", TR("Apply"), new BMessage(kApplyMsg));
fApply->MakeDefault(true);
AddControl(back_view, fApply, column2, rect);
LeftAlign(fApply);
const float spacing = be_control_look->DefaultItemSpacing();
const float labelspacing = be_control_look->DefaultLabelSpacing();
SetLayout(new BGroupLayout(B_HORIZONTAL));
AddChild(BGroupLayoutBuilder(B_VERTICAL, 0)
.Add(BGridLayoutBuilder(labelspacing, 0)
.Add(fWidth->CreateLabelLayoutItem(), 0, 0)
.Add(fWidth->CreateTextViewLayoutItem(), 1, 0)
.Add(fHeight->CreateLabelLayoutItem(), 0, 1)
.Add(fHeight->CreateTextViewLayoutItem(), 1, 1)
)
.Add(fAspectRatio)
.AddGroup(B_HORIZONTAL, 0)
.AddGlue()
.Add(fApply)
.End()
.SetInsets(spacing, spacing, spacing, spacing)
);
fWidth->MakeFocus();
ResizeTo(width2, rect.top);
}
@ -99,52 +90,6 @@ ResizerWindow::~ResizerWindow()
}
void
ResizerWindow::AddControl(BView* view, BControl* control, float column2,
BRect& rect)
{
float width, height;
view->AddChild(control);
control->GetPreferredSize(&width, &height);
if (dynamic_cast<BButton*>(control) != NULL) {
control->ResizeTo(width, height);
} else {
control->ResizeTo(control->Bounds().Width(), height);
}
float top = control->Frame().bottom + kLineDistance;
rect.OffsetTo(rect.left, top);
if (dynamic_cast<BTextControl*>(control) != NULL) {
((BTextControl*)control)->SetDivider(column2);
}
}
void
ResizerWindow::AddSeparatorLine(BView* view, BRect& rect)
{
const float lineWidth = 3;
BRect line(Bounds());
line.left += 3;
line.right -= 3;
line.top = rect.top;
line.bottom = line.top + lineWidth - 1;
BBox* separatorLine = new BBox(line, "", B_FOLLOW_LEFT_RIGHT,
B_WILL_DRAW | B_FRAME_EVENTS, B_PLAIN_BORDER);
view->AddChild(separatorLine);
rect.OffsetBy(0, kLineDistance + lineWidth);
}
void
ResizerWindow::LeftAlign(BControl* control)
{
BRect frame = control->Frame();
float left = Bounds().Width() - frame.Width() - kHorizontalIndent;
control->MoveTo(left, frame.top);
}
void
ResizerWindow::MessageReceived(BMessage* message)
{

View File

@ -15,7 +15,6 @@
#include <Messenger.h>
#include <View.h>
#include <Window.h>
class BCheckBox;
@ -50,10 +49,6 @@ class ResizerWindow : public BWindow {
kApplyMsg,
};
void AddControl(BView* parent, BControl* control,
float column2, BRect& rect);
void AddSeparatorLine(BView* parent, BRect& rect);
void LeftAlign(BControl* control);
BTextControl* fWidth;
BTextControl* fHeight;

View File

@ -15,8 +15,10 @@
#include <AboutWindow.h>
#include <Alert.h>
#include <Catalog.h>
#include <Clipboard.h>
#include <FilePanel.h>
#include <Locale.h>
#include <Path.h>
#include <String.h>
@ -33,6 +35,8 @@ ShowImageApp::ShowImageApp()
:
BApplication(kApplicationSignature)
{
be_locale->GetAppCatalog(&fCatalog);
fPulseStarted = false;
fOpenPanel = new BFilePanel(B_OPEN_PANEL);
}
@ -43,6 +47,9 @@ ShowImageApp::~ShowImageApp()
}
#undef TR_CONTEXT
#define TR_CONTEXT "AboutWindow"
void
ShowImageApp::AboutRequested()
{
@ -53,7 +60,7 @@ ShowImageApp::AboutRequested()
"Ryan Leavengood",
NULL
};
BAboutWindow about("ShowImage", 2003, authors);
BAboutWindow about(TR("ShowImage"), 2003, authors);
about.Show();
}

View File

@ -14,6 +14,7 @@
#include "ShowImageSettings.h"
#include <Application.h>
#include <Catalog.h>
#include <FilePanel.h>
@ -42,6 +43,7 @@ private:
BFilePanel *fOpenPanel;
bool fPulseStarted;
ShowImageSettings fSettings;
BCatalog fCatalog;
};

View File

@ -21,10 +21,12 @@
#include <Application.h>
#include <Bitmap.h>
#include <BitmapStream.h>
#include <Catalog.h>
#include <Clipboard.h>
#include <Entry.h>
#include <File.h>
#include <FilePanel.h>
#include <Locale.h>
#include <Menu.h>
#include <MenuBar.h>
#include <MenuItem.h>
@ -38,6 +40,7 @@
#include <TranslationDefs.h>
#include <TranslationUtils.h>
#include <TranslatorRoster.h>
#include <stdlib.h> // for bs_printf()
#include "EntryMenuItem.h"
#include "ResizerWindow.h"
@ -180,11 +183,14 @@ ShowImageWindow::ShowImageWindow(const entry_ref *ref,
fImageView->SetImage(ref);
fImageView->SetTrackerMessenger(trackerMessenger);
#undef TR_CONTEXT
#define TR_CONTEXT "LoadAlerts"
if (InitCheck() != B_OK) {
BAlert* alert;
alert = new BAlert("ShowImage",
"Could not load image! Either the file or an image translator for "
"it does not exist.", "OK", NULL, NULL, B_WIDTH_AS_USUAL, B_INFO_ALERT);
alert = new BAlert(TR("ShowImage"),
TR("Could not load image! Either the file or an image translator for it does not exist."),
TR("OK"), NULL, NULL, B_WIDTH_AS_USUAL, B_INFO_ALERT);
alert->Go();
// quit if file could not be opened
@ -192,8 +198,11 @@ ShowImageWindow::ShowImageWindow(const entry_ref *ref,
return;
}
#undef TR_CONTEXT
#define TR_CONTEXT "Menus"
// add View menu here so it can access ShowImageView methods
BMenu* menu = new BMenu("View");
BMenu* menu = new BMenu(TR("View"));
_BuildViewMenu(menu, false);
fBar->AddItem(menu);
_MarkMenuItem(fBar, MSG_DITHER_IMAGE, fImageView->GetDither());
@ -244,12 +253,15 @@ ShowImageWindow::BuildContextMenu(BMenu *menu)
}
#undef TR_CONTEXT
#define TR_CONTEXT "Menus"
void
ShowImageWindow::_BuildViewMenu(BMenu* menu, bool popupMenu)
{
_AddItemMenu(menu, "Slide show", MSG_SLIDE_SHOW, 0, 0, this);
_AddItemMenu(menu, TR("Slide show"), MSG_SLIDE_SHOW, 0, 0, this);
_MarkMenuItem(menu, MSG_SLIDE_SHOW, fImageView->SlideShowStarted());
BMenu* delayMenu = new BMenu("Slide delay");
BMenu* delayMenu = new BMenu(TR("Slide delay"));
if (fSlideShowDelay == NULL)
fSlideShowDelay = delayMenu;
@ -258,38 +270,38 @@ ShowImageWindow::_BuildViewMenu(BMenu *menu, bool popupMenu)
// if slide show delay is too short! (Especially if loading the image
// takes as long as or longer than the slide show delay). Should load
// in background thread!
_AddDelayItem(delayMenu, "3 seconds", 3);
_AddDelayItem(delayMenu, "4 seconds", 4);
_AddDelayItem(delayMenu, "5 seconds", 5);
_AddDelayItem(delayMenu, "6 seconds", 6);
_AddDelayItem(delayMenu, "7 seconds", 7);
_AddDelayItem(delayMenu, "8 seconds", 8);
_AddDelayItem(delayMenu, "9 seconds", 9);
_AddDelayItem(delayMenu, "10 seconds", 10);
_AddDelayItem(delayMenu, "20 seconds", 20);
_AddDelayItem(delayMenu, TR("3 seconds"), 3);
_AddDelayItem(delayMenu, TR("4 seconds"), 4);
_AddDelayItem(delayMenu, TR("5 seconds"), 5);
_AddDelayItem(delayMenu, TR("6 seconds"), 6);
_AddDelayItem(delayMenu, TR("7 seconds"), 7);
_AddDelayItem(delayMenu, TR("8 seconds"), 8);
_AddDelayItem(delayMenu, TR("9 seconds"), 9);
_AddDelayItem(delayMenu, TR("10 seconds"), 10);
_AddDelayItem(delayMenu, TR("20 seconds"), 20);
menu->AddItem(delayMenu);
menu->AddSeparatorItem();
_AddItemMenu(menu, "Original size", MSG_ORIGINAL_SIZE, '1', 0, this);
_AddItemMenu(menu, "Zoom in", MSG_ZOOM_IN, '+', 0, this);
_AddItemMenu(menu, "Zoom out", MSG_ZOOM_OUT, '-', 0, this);
_AddItemMenu(menu, TR("Original size"), MSG_ORIGINAL_SIZE, '1', 0, this);
_AddItemMenu(menu, TR("Zoom in"), MSG_ZOOM_IN, '+', 0, this);
_AddItemMenu(menu, TR("Zoom out"), MSG_ZOOM_OUT, '-', 0, this);
menu->AddSeparatorItem();
_AddItemMenu(menu, "High-quality zooming", MSG_SCALE_BILINEAR, 0, 0, this);
_AddItemMenu(menu, TR("High-quality zooming"), MSG_SCALE_BILINEAR, 0, 0, this);
menu->AddSeparatorItem();
_AddItemMenu(menu, "Shrink to window", MSG_SHRINK_TO_WINDOW, 0, 0, this);
_AddItemMenu(menu, "Zoom to window", MSG_ZOOM_TO_WINDOW, 0, 0, this);
_AddItemMenu(menu, TR("Shrink to window"), MSG_SHRINK_TO_WINDOW, 0, 0, this);
_AddItemMenu(menu, TR("Zoom to window"), MSG_ZOOM_TO_WINDOW, 0, 0, this);
menu->AddSeparatorItem();
_AddItemMenu(menu, "Full screen", MSG_FULL_SCREEN, B_ENTER, 0, this);
_AddItemMenu(menu, TR("Full screen"), MSG_FULL_SCREEN, B_ENTER, 0, this);
_MarkMenuItem(menu, MSG_FULL_SCREEN, fFullScreen);
_AddItemMenu(menu, "Show caption in full screen mode", MSG_SHOW_CAPTION, 0,
_AddItemMenu(menu, TR("Show caption in full screen mode"), MSG_SHOW_CAPTION, 0,
0, this);
_MarkMenuItem(menu, MSG_SHOW_CAPTION, fShowCaption);
@ -309,8 +321,8 @@ ShowImageWindow::_BuildViewMenu(BMenu *menu, bool popupMenu)
if (popupMenu) {
menu->AddSeparatorItem();
_AddItemMenu(menu, "Use as background" B_UTF8_ELLIPSIS, MSG_DESKTOP_BACKGROUND, 0, 0,
this);
_AddItemMenu(menu, TR("Use as background" B_UTF8_ELLIPSIS),
MSG_DESKTOP_BACKGROUND, 0, 0, this);
}
}
@ -318,69 +330,77 @@ ShowImageWindow::_BuildViewMenu(BMenu *menu, bool popupMenu)
void
ShowImageWindow::AddMenus(BMenuBar* bar)
{
BMenu *menu = new BMenu("File");
fOpenMenu = new RecentDocumentsMenu("Open");
BMenu* menu = new BMenu(TR("File"));
fOpenMenu = new RecentDocumentsMenu(TR("Open"));
menu->AddItem(fOpenMenu);
fOpenMenu->Superitem()->SetTrigger('O');
fOpenMenu->Superitem()->SetMessage(new BMessage(MSG_FILE_OPEN));
fOpenMenu->Superitem()->SetTarget(be_app);
fOpenMenu->Superitem()->SetShortcut('O', 0);
menu->AddSeparatorItem();
BMenu *pmenuSaveAs = new BMenu("Save as" B_UTF8_ELLIPSIS, B_ITEMS_IN_COLUMN);
BMenu *pmenuSaveAs = new BMenu(TR("Save as" B_UTF8_ELLIPSIS),
B_ITEMS_IN_COLUMN);
BTranslationUtils::AddTranslationItems(pmenuSaveAs, B_TRANSLATOR_BITMAP);
// Fill Save As submenu with all types that can be converted
// to from the Be bitmap image format
menu->AddItem(pmenuSaveAs);
_AddItemMenu(menu, "Close", B_QUIT_REQUESTED, 'W', 0, this);
_AddItemMenu(menu, TR("Close"), B_QUIT_REQUESTED, 'W', 0, this);
menu->AddSeparatorItem();
_AddItemMenu(menu, "Page setup" B_UTF8_ELLIPSIS, MSG_PAGE_SETUP, 0, 0, this);
_AddItemMenu(menu, "Print" B_UTF8_ELLIPSIS, MSG_PREPARE_PRINT, 'P', 0, this);
_AddItemMenu(menu, TR("Page setup" B_UTF8_ELLIPSIS),
MSG_PAGE_SETUP, 0, 0, this);
_AddItemMenu(menu, TR("Print" B_UTF8_ELLIPSIS),
MSG_PREPARE_PRINT, 'P', 0, this);
menu->AddSeparatorItem();
_AddItemMenu(menu, "About ShowImage" B_UTF8_ELLIPSIS, B_ABOUT_REQUESTED, 0, 0,
be_app);
_AddItemMenu(menu, TR("About ShowImage" B_UTF8_ELLIPSIS),
B_ABOUT_REQUESTED, 0, 0, be_app);
menu->AddSeparatorItem();
_AddItemMenu(menu, "Quit", B_QUIT_REQUESTED, 'Q', 0, be_app);
_AddItemMenu(menu, TR("Quit"), B_QUIT_REQUESTED, 'Q', 0, be_app);
bar->AddItem(menu);
menu = new BMenu("Edit");
_AddItemMenu(menu, "Undo", B_UNDO, 'Z', 0, this, false);
menu = new BMenu(TR("Edit"));
_AddItemMenu(menu, TR("Undo"), B_UNDO, 'Z', 0, this, false);
menu->AddSeparatorItem();
_AddItemMenu(menu, "Cut", B_CUT, 'X', 0, this, false);
_AddItemMenu(menu, "Copy", B_COPY, 'C', 0, this, false);
_AddItemMenu(menu, "Paste", B_PASTE, 'V', 0, this, false);
_AddItemMenu(menu, "Clear", MSG_CLEAR_SELECT, 0, 0, this, false);
_AddItemMenu(menu, TR("Cut"), B_CUT, 'X', 0, this, false);
_AddItemMenu(menu, TR("Copy"), B_COPY, 'C', 0, this, false);
_AddItemMenu(menu, TR("Paste"), B_PASTE, 'V', 0, this, false);
_AddItemMenu(menu, TR("Clear"), MSG_CLEAR_SELECT, 0, 0, this, false);
menu->AddSeparatorItem();
_AddItemMenu(menu, "Select all", MSG_SELECT_ALL, 'A', 0, this);
_AddItemMenu(menu, TR("Select all"), MSG_SELECT_ALL, 'A', 0, this);
bar->AddItem(menu);
menu = fBrowseMenu = new BMenu("Browse");
_AddItemMenu(menu, "First page", MSG_PAGE_FIRST, B_LEFT_ARROW, B_SHIFT_KEY, this);
_AddItemMenu(menu, "Last page", MSG_PAGE_LAST, B_RIGHT_ARROW, B_SHIFT_KEY, this);
_AddItemMenu(menu, "Previous page", MSG_PAGE_PREV, B_LEFT_ARROW, 0, this);
_AddItemMenu(menu, "Next page", MSG_PAGE_NEXT, B_RIGHT_ARROW, 0, this);
fGoToPageMenu = new BMenu("Go to page");
menu = fBrowseMenu = new BMenu(TR("Browse"));
_AddItemMenu(menu, TR("First page"),
MSG_PAGE_FIRST, B_LEFT_ARROW, B_SHIFT_KEY, this);
_AddItemMenu(menu, TR("Last page"),
MSG_PAGE_LAST, B_RIGHT_ARROW, B_SHIFT_KEY, this);
_AddItemMenu(menu, TR("Previous page"), MSG_PAGE_PREV, B_LEFT_ARROW, 0, this);
_AddItemMenu(menu, TR("Next page"), MSG_PAGE_NEXT, B_RIGHT_ARROW, 0, this);
fGoToPageMenu = new BMenu(TR("Go to page"));
fGoToPageMenu->SetRadioMode(true);
menu->AddItem(fGoToPageMenu);
menu->AddSeparatorItem();
_AddItemMenu(menu, "Previous file", MSG_FILE_PREV, B_UP_ARROW, 0, this);
_AddItemMenu(menu, "Next file", MSG_FILE_NEXT, B_DOWN_ARROW, 0, this);
_AddItemMenu(menu, TR("Previous file"), MSG_FILE_PREV, B_UP_ARROW, 0, this);
_AddItemMenu(menu, TR("Next file"), MSG_FILE_NEXT, B_DOWN_ARROW, 0, this);
bar->AddItem(menu);
menu = new BMenu("Image");
_AddItemMenu(menu, "Rotate clockwise", MSG_ROTATE_90, 'R', 0, this);
_AddItemMenu(menu, "Rotate counterclockwise", MSG_ROTATE_270, 'R', B_SHIFT_KEY, this);
menu = new BMenu(TR("Image"));
_AddItemMenu(menu, TR("Rotate clockwise"), MSG_ROTATE_90, 'R', 0, this);
_AddItemMenu(menu, TR("Rotate counterclockwise"),
MSG_ROTATE_270, 'R', B_SHIFT_KEY, this);
menu->AddSeparatorItem();
_AddItemMenu(menu, "Flip left to right", MSG_FLIP_LEFT_TO_RIGHT, 0, 0, this);
_AddItemMenu(menu, "Flip top to bottom", MSG_FLIP_TOP_TO_BOTTOM, 0, 0, this);
_AddItemMenu(menu, TR("Flip left to right"),
MSG_FLIP_LEFT_TO_RIGHT, 0, 0, this);
_AddItemMenu(menu, TR("Flip top to bottom"),
MSG_FLIP_TOP_TO_BOTTOM, 0, 0, this);
menu->AddSeparatorItem();
_AddItemMenu(menu, "Invert colors", MSG_INVERT, 0, 0, this);
_AddItemMenu(menu, TR("Invert colors"), MSG_INVERT, 0, 0, this);
menu->AddSeparatorItem();
fResizeItem = _AddItemMenu(menu, "Resize" B_UTF8_ELLIPSIS,
fResizeItem = _AddItemMenu(menu, TR("Resize" B_UTF8_ELLIPSIS),
MSG_OPEN_RESIZER_WINDOW, 0, 0, this);
bar->AddItem(menu);
menu->AddSeparatorItem();
_AddItemMenu(menu, "Use as background" B_UTF8_ELLIPSIS, MSG_DESKTOP_BACKGROUND, 0, 0,
this);
_AddItemMenu(menu, TR("Use as background" B_UTF8_ELLIPSIS),
MSG_DESKTOP_BACKGROUND, 0, 0, this);
}
@ -966,6 +986,25 @@ ShowImageWindow::_SaveToFile(BMessage *message)
}
// This is temporary solution for building BString with printf like format.
// will be removed in the future.
static void
bs_printf(BString* string, const char* format, ...)
{
va_list ap;
char* buf;
va_start(ap, format);
vasprintf(&buf, format, ap);
string->SetTo(buf);
free(buf);
va_end(ap);
}
#undef TR_CONTEXT
#define TR_CONTEXT "ClosePrompt"
bool
ShowImageWindow::_ClosePrompt()
{
@ -977,14 +1016,19 @@ ShowImageWindow::_ClosePrompt()
page = fImageView->CurrentPage();
BString prompt, name;
fImageView->GetName(&name);
prompt << "The document '" << name << "'";
if (count > 1)
prompt << " (page " << page << ")";
prompt << " has been changed. "
<< "Do you want to close the document?";
BAlert *pAlert = new BAlert("Close document", prompt.String(),
"Cancel", "Close");
if (count > 1) {
bs_printf(&prompt,
TR("The document '%s' (page %d) has been changed. Do you want to close the document?"),
name.String(), page);
} else {
bs_printf(&prompt,
TR("The document '%s' has been changed. Do you want to close the document?"),
name.String());
}
BAlert* pAlert = new BAlert(TR("Close document"), prompt.String(),
TR("Cancel"), TR("Close"));
if (pAlert->Go() == 0) {
// Cancel
return false;