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"
@ -23,8 +29,8 @@ PrintOptions::PrintOptions()
fOption(kFitToPage),
fZoomFactor(1.0),
fDPI(72.0),
fWidth(1024/72.0),
fHeight(768/72.0)
fWidth(1024 / 72.0),
fHeight(768 / 72.0)
{
}
@ -68,12 +74,15 @@ PrintOptions::SetHeight(float h)
}
PrintOptionsWindow::PrintOptionsWindow(BPoint at, PrintOptions *options,
#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);
// center button
button->MoveTo((Bounds().Width()-button->Bounds().Width())/2,
button->Frame().top);
const float spacing = be_control_look->DefaultItemSpacing();
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)
);
}
@ -245,14 +247,14 @@ PrintOptionsWindow::MessageReceived(BMessage* msg)
case kMsgZoomFactorChanged:
if (GetValue(fZoomFactor, &value)
&& fCurrentOptions.ZoomFactor() != value) {
fCurrentOptions.SetZoomFactor(value/100);
fCurrentOptions.SetZoomFactor(value / 100);
SetValue(fDPI, fCurrentOptions.DPI());
}
break;
case kMsgDPIChanged:
if (GetValue(fDPI, &value) && fCurrentOptions.DPI() != value) {
fCurrentOptions.SetDPI(value);
SetValue(fZoomFactor, 100*fCurrentOptions.ZoomFactor());
SetValue(fZoomFactor, 100 * fCurrentOptions.ZoomFactor());
}
break;
case kMsgWidthChanged:

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>
@ -26,13 +28,15 @@
#define WINDOWS_TO_IGNORE 1
extern const char *kApplicationSignature = "application/x-vnd.Haiku-ShowImage";
extern const char* kApplicationSignature = "application/x-vnd.Haiku-ShowImage";
ShowImageApp::ShowImageApp()
:
BApplication(kApplicationSignature)
{
be_locale->GetAppCatalog(&fCatalog);
fPulseStarted = false;
fOpenPanel = new BFilePanel(B_OPEN_PANEL);
}
@ -43,17 +47,20 @@ ShowImageApp::~ShowImageApp()
}
#undef TR_CONTEXT
#define TR_CONTEXT "AboutWindow"
void
ShowImageApp::AboutRequested()
{
const char *authors[] = {
const char* authors[] = {
"Fernando F. Oliveira",
"Michael Wilber",
"Michael Pfeiffer",
"Ryan Leavengood",
NULL
};
BAboutWindow about("ShowImage", 2003, authors);
BAboutWindow about(TR("ShowImage"), 2003, authors);
about.Show();
}
@ -109,7 +116,7 @@ ShowImageApp::ArgvReceived(int32 argc, char **argv)
bool hasRefs = false;
// get current working directory
const char *cwd;
const char* cwd;
if (CurrentMessage() == NULL
|| CurrentMessage()->FindString("cwd", &cwd) != B_OK)
cwd = "";
@ -139,7 +146,7 @@ ShowImageApp::ArgvReceived(int32 argc, char **argv)
void
ShowImageApp::MessageReceived(BMessage *message)
ShowImageApp::MessageReceived(BMessage* message)
{
switch (message->what) {
case MSG_FILE_OPEN:
@ -167,7 +174,7 @@ ShowImageApp::MessageReceived(BMessage *message)
void
ShowImageApp::RefsReceived(BMessage *message)
ShowImageApp::RefsReceived(BMessage* message)
{
// If a tracker window opened me, get a messenger from it.
if (message->HasMessenger("TrackerViewToken"))
@ -188,14 +195,14 @@ ShowImageApp::RefsReceived(BMessage *message)
void
ShowImageApp::Open(const entry_ref *ref)
ShowImageApp::Open(const entry_ref* ref)
{
new ShowImageWindow(ref, fTrackerMessenger);
}
void
ShowImageApp::BroadcastToWindows(BMessage *message)
ShowImageApp::BroadcastToWindows(BMessage* message)
{
const int32 count = CountWindows();
for (int32 i = 0; i < count; i ++) {
@ -217,7 +224,7 @@ ShowImageApp::CheckClipboard()
bool dataAvailable = false;
if (be_clipboard->Lock()) {
BMessage *clip = be_clipboard->Data();
BMessage* clip = be_clipboard->Data();
if (clip != NULL) {
BString className;
if (clip->FindString("class", &className) == B_OK) {

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"
@ -51,7 +54,7 @@
class ShowImageWindow::RecentDocumentsMenu : public BMenu {
public:
RecentDocumentsMenu(const char *title,
RecentDocumentsMenu(const char* title,
menu_layout layout = B_ITEMS_IN_COLUMN);
bool AddDynamicItem(add_state addState);
@ -60,7 +63,7 @@ private:
};
ShowImageWindow::RecentDocumentsMenu::RecentDocumentsMenu(const char *title,
ShowImageWindow::RecentDocumentsMenu::RecentDocumentsMenu(const char* title,
menu_layout layout)
:
BMenu(title, layout)
@ -77,7 +80,7 @@ ShowImageWindow::RecentDocumentsMenu::AddDynamicItem(add_state addState)
while (CountItems() > 0)
delete RemoveItem(0L);
BMenuItem *item;
BMenuItem* item;
BMessage list, *msg;
entry_ref ref;
char name[B_FILE_NAME_LENGTH];
@ -106,7 +109,7 @@ const char* kTypeField = "be:type";
const char* kTranslatorField = "be:translator";
ShowImageWindow::ShowImageWindow(const entry_ref *ref,
ShowImageWindow::ShowImageWindow(const entry_ref* ref,
const BMessenger& trackerMessenger)
:
BWindow(BRect(5, 24, 250, 100), "", B_DOCUMENT_WINDOW, 0),
@ -143,7 +146,7 @@ ShowImageWindow::ShowImageWindow(const entry_ref *ref,
fImageView = new ShowImageView(viewFrame, "image_view", B_FOLLOW_ALL,
B_WILL_DRAW | B_FRAME_EVENTS | B_FULL_UPDATE_ON_RESIZE | B_PULSE_NEEDED);
// wrap a scroll view around the view
BScrollView *scrollView = new BScrollView("image_scroller", fImageView,
BScrollView* scrollView = new BScrollView("image_scroller", fImageView,
B_FOLLOW_ALL, 0, false, false, B_PLAIN_BORDER);
AddChild(scrollView);
@ -154,7 +157,7 @@ ShowImageWindow::ShowImageWindow(const entry_ref *ref,
rect.left = viewFrame.left + kstatusWidth;
rect.right = viewFrame.right + 1;
rect.bottom += 1;
BScrollBar *horizontalScrollBar = new BScrollBar(rect, "hscroll",
BScrollBar* horizontalScrollBar = new BScrollBar(rect, "hscroll",
fImageView, 0, 150, B_HORIZONTAL);
AddChild(horizontalScrollBar);
@ -170,7 +173,7 @@ ShowImageWindow::ShowImageWindow(const entry_ref *ref,
rect.left = viewFrame.right + 1;
rect.bottom = viewFrame.bottom + 1;
rect.right += 1;
BScrollBar *verticalScrollBar = new BScrollBar(rect, "vscroll", fImageView,
BScrollBar* verticalScrollBar = new BScrollBar(rect, "vscroll", fImageView,
0, 150, B_VERTICAL);
AddChild(verticalScrollBar);
@ -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());
@ -238,18 +247,21 @@ ShowImageWindow::UpdateTitle()
void
ShowImageWindow::BuildContextMenu(BMenu *menu)
ShowImageWindow::BuildContextMenu(BMenu* menu)
{
_BuildViewMenu(menu, true);
}
#undef TR_CONTEXT
#define TR_CONTEXT "Menus"
void
ShowImageWindow::_BuildViewMenu(BMenu *menu, bool popupMenu)
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,84 +321,92 @@ 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);
}
}
void
ShowImageWindow::AddMenus(BMenuBar *bar)
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);
}
BMenuItem*
ShowImageWindow::_AddItemMenu(BMenu *menu, const char *label, uint32 what,
const char shortcut, uint32 modifier, const BHandler *target, bool enabled)
ShowImageWindow::_AddItemMenu(BMenu* menu, const char* label, uint32 what,
const char shortcut, uint32 modifier, const BHandler* target, bool enabled)
{
BMenuItem* item = new BMenuItem(label, new BMessage(what), shortcut, modifier);
menu->AddItem(item);
@ -399,7 +419,7 @@ ShowImageWindow::_AddItemMenu(BMenu *menu, const char *label, uint32 what,
BMenuItem*
ShowImageWindow::_AddDelayItem(BMenu *menu, const char *label, float value)
ShowImageWindow::_AddDelayItem(BMenu* menu, const char* label, float value)
{
BMessage* message = new BMessage(MSG_SLIDE_SHOW_DELAY);
message->AddFloat("value", value);
@ -417,7 +437,7 @@ ShowImageWindow::_AddDelayItem(BMenu *menu, const char *label, float value)
void
ShowImageWindow::WindowRedimension(BBitmap *pbitmap)
ShowImageWindow::WindowRedimension(BBitmap* pbitmap)
{
BScreen screen;
if (!screen.IsValid())
@ -468,7 +488,7 @@ bool
ShowImageWindow::_ToggleMenuItem(uint32 what)
{
bool marked = false;
BMenuItem *item = fBar->FindItem(what);
BMenuItem* item = fBar->FindItem(what);
if (item != NULL) {
marked = !item->IsMarked();
item->SetMarked(marked);
@ -478,7 +498,7 @@ ShowImageWindow::_ToggleMenuItem(uint32 what)
void
ShowImageWindow::_EnableMenuItem(BMenu *menu, uint32 what, bool enable)
ShowImageWindow::_EnableMenuItem(BMenu* menu, uint32 what, bool enable)
{
BMenuItem* item = menu->FindItem(what);
if (item && item->IsEnabled() != enable)
@ -487,7 +507,7 @@ ShowImageWindow::_EnableMenuItem(BMenu *menu, uint32 what, bool enable)
void
ShowImageWindow::_MarkMenuItem(BMenu *menu, uint32 what, bool marked)
ShowImageWindow::_MarkMenuItem(BMenu* menu, uint32 what, bool marked)
{
BMenuItem* item = menu->FindItem(what);
if (item && item->IsMarked() != marked)
@ -530,7 +550,7 @@ ShowImageWindow::_ResizeToWindow(bool shrink, uint32 what)
void
ShowImageWindow::MessageReceived(BMessage *message)
ShowImageWindow::MessageReceived(BMessage* message)
{
switch (message->what) {
case MSG_MODIFIED:
@ -578,7 +598,7 @@ ShowImageWindow::MessageReceived(BMessage *message)
for (int32 i = 1; i <= pages; i++) {
// Fill Go To page submenu with an entry for each page
BMessage *pgomsg = new BMessage(MSG_GOTO_PAGE);
BMessage* pgomsg = new BMessage(MSG_GOTO_PAGE);
pgomsg->AddInt32("page", i);
char shortcut = 0;
@ -591,7 +611,7 @@ ShowImageWindow::MessageReceived(BMessage *message)
BString strCaption;
strCaption << i;
BMenuItem *item = new BMenuItem(strCaption.String(), pgomsg,
BMenuItem* item = new BMenuItem(strCaption.String(), pgomsg,
shortcut);
if (curPage == i)
item->SetMarked(true);
@ -786,7 +806,7 @@ ShowImageWindow::MessageReceived(BMessage *message)
break;
case MSG_SLIDE_SHOW: {
BMenuItem *item = fBar->FindItem(message->what);
BMenuItem* item = fBar->FindItem(message->what);
if (!item)
break;
if (item->IsMarked()) {
@ -892,7 +912,7 @@ ShowImageWindow::MessageReceived(BMessage *message)
void
ShowImageWindow::_SaveAs(BMessage *message)
ShowImageWindow::_SaveAs(BMessage* message)
{
// Read the translator and output type the user chose
translator_id outTranslator;
@ -922,14 +942,14 @@ ShowImageWindow::_SaveAs(BMessage *message)
void
ShowImageWindow::_SaveToFile(BMessage *message)
ShowImageWindow::_SaveToFile(BMessage* message)
{
// Read in where the file should be saved
entry_ref dirRef;
if (message->FindRef("directory", &dirRef) != B_OK)
return;
const char *filename;
const char* filename;
if (message->FindString("name", &filename) != B_OK)
return;
@ -945,8 +965,8 @@ ShowImageWindow::_SaveToFile(BMessage *message)
// Find the translator_format information needed to
// write a MIME attribute for the image file
BTranslatorRoster *roster = BTranslatorRoster::Default();
const translation_format *outFormat = NULL;
BTranslatorRoster* roster = BTranslatorRoster::Default();
const translation_format* outFormat = NULL;
int32 outCount = 0;
if (roster->GetOutputFormats(outTranslator, &outFormat, &outCount) != B_OK
|| outCount < 1)
@ -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;
@ -1104,15 +1148,15 @@ ShowImageWindow::_PrepareForPrint()
}
fPrintOptions.SetBounds(fImageView->GetBitmap()->Bounds());
fPrintOptions.SetWidth(fImageView->GetBitmap()->Bounds().Width()+1);
fPrintOptions.SetWidth(fImageView->GetBitmap()->Bounds().Width() + 1);
new PrintOptionsWindow(BPoint(Frame().left+30, Frame().top+50),
new PrintOptionsWindow(BPoint(Frame().left + 30, Frame().top + 50),
&fPrintOptions, this);
}
void
ShowImageWindow::_Print(BMessage *msg)
ShowImageWindow::_Print(BMessage* msg)
{
status_t st;
if (msg->FindInt32("status", &st) != B_OK || st != B_OK)