[haiku-commits] r35929 - haiku/trunk/src/apps/showimage

  • From: superstippi@xxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Mon, 22 Mar 2010 15:46:01 +0100 (CET)

Author: stippi
Date: 2010-03-22 15:46:01 +0100 (Mon, 22 Mar 2010)
New Revision: 35929
Changeset: http://dev.haiku-os.org/changeset/35929/haiku
Ticket: http://dev.haiku-os.org/ticket/5563

Modified:
   haiku/trunk/src/apps/showimage/Jamfile
   haiku/trunk/src/apps/showimage/PrintOptionsWindow.cpp
   haiku/trunk/src/apps/showimage/PrintOptionsWindow.h
   haiku/trunk/src/apps/showimage/ResizerWindow.cpp
   haiku/trunk/src/apps/showimage/ResizerWindow.h
   haiku/trunk/src/apps/showimage/ShowImageApp.cpp
   haiku/trunk/src/apps/showimage/ShowImageApp.h
   haiku/trunk/src/apps/showimage/ShowImageWindow.cpp
Log:
Patch by mt. Localization and conversion to use the layout API with coding style
fixes along the way. Thanks a lot! Fixes #5563.


Modified: haiku/trunk/src/apps/showimage/Jamfile
===================================================================
--- haiku/trunk/src/apps/showimage/Jamfile      2010-03-21 18:19:56 UTC (rev 
35928)
+++ haiku/trunk/src/apps/showimage/Jamfile      2010-03-22 14:46:01 UTC (rev 
35929)
@@ -17,7 +17,17 @@
        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
+       :
+;

Modified: haiku/trunk/src/apps/showimage/PrintOptionsWindow.cpp
===================================================================
--- haiku/trunk/src/apps/showimage/PrintOptionsWindow.cpp       2010-03-21 
18:19:56 UTC (rev 35928)
+++ haiku/trunk/src/apps/showimage/PrintOptionsWindow.cpp       2010-03-22 
14:46:01 UTC (rev 35929)
@@ -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 @@
        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 @@
 }
 
 
-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 @@
 
 
 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 @@
 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);
+       rbFit = AddRadioButton("fit_to_page", TR("Fit image to page"),
+               kMsgFitToPageSelected, op == PrintOptions::kFitToPage);
 
-       AddRadioButton(panel, at, "fit_to_page", "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 @@
                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:

Modified: haiku/trunk/src/apps/showimage/PrintOptionsWindow.h
===================================================================
--- haiku/trunk/src/apps/showimage/PrintOptionsWindow.h 2010-03-21 18:19:56 UTC 
(rev 35928)
+++ haiku/trunk/src/apps/showimage/PrintOptionsWindow.h 2010-03-22 14:46:01 UTC 
(rev 35929)
@@ -64,13 +64,11 @@
        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);

Modified: haiku/trunk/src/apps/showimage/ResizerWindow.cpp
===================================================================
--- haiku/trunk/src/apps/showimage/ResizerWindow.cpp    2010-03-21 18:19:56 UTC 
(rev 35928)
+++ haiku/trunk/src/apps/showimage/ResizerWindow.cpp    2010-03-22 14:46:01 UTC 
(rev 35929)
@@ -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";
+#undef TR_CONTEXT
+#define TR_CONTEXT "ResizerWindow"
 
-static const float kLineDistance = 5;
-static const float kHorizontalIndent = 10;
-static const float kVerticalIndent = 10;
-
-
 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();
        
-       fWidth->MakeFocus();
+       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) 
+       ); 
        
-       ResizeTo(width2, rect.top);
+       fWidth->MakeFocus();
+
 }
 
 
@@ -99,52 +90,6 @@
 }
 
 
-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)
 {

Modified: haiku/trunk/src/apps/showimage/ResizerWindow.h
===================================================================
--- haiku/trunk/src/apps/showimage/ResizerWindow.h      2010-03-21 18:19:56 UTC 
(rev 35928)
+++ haiku/trunk/src/apps/showimage/ResizerWindow.h      2010-03-22 14:46:01 UTC 
(rev 35929)
@@ -15,7 +15,6 @@
 
 
 #include <Messenger.h>
-#include <View.h>
 #include <Window.h>
 
 class BCheckBox;
@@ -50,10 +49,6 @@
                        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;

Modified: haiku/trunk/src/apps/showimage/ShowImageApp.cpp
===================================================================
--- haiku/trunk/src/apps/showimage/ShowImageApp.cpp     2010-03-21 18:19:56 UTC 
(rev 35928)
+++ haiku/trunk/src/apps/showimage/ShowImageApp.cpp     2010-03-22 14:46:01 UTC 
(rev 35929)
@@ -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 @@
 }
 
 
+#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 @@
        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 @@
 
 
 void
-ShowImageApp::MessageReceived(BMessage *message)
+ShowImageApp::MessageReceived(BMessage* message)
 {
        switch (message->what) {
                case MSG_FILE_OPEN:
@@ -167,7 +174,7 @@
 
 
 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 @@
 
 
 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 @@
        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) {

Modified: haiku/trunk/src/apps/showimage/ShowImageApp.h
===================================================================
--- haiku/trunk/src/apps/showimage/ShowImageApp.h       2010-03-21 18:19:56 UTC 
(rev 35928)
+++ haiku/trunk/src/apps/showimage/ShowImageApp.h       2010-03-22 14:46:01 UTC 
(rev 35929)
@@ -14,6 +14,7 @@
 #include "ShowImageSettings.h"
 
 #include <Application.h>
+#include <Catalog.h>
 #include <FilePanel.h>
 
 
@@ -42,6 +43,7 @@
                        BFilePanel                      *fOpenPanel;
                        bool                            fPulseStarted;
                        ShowImageSettings       fSettings;
+                       BCatalog                fCatalog;
 };
 
 

Modified: haiku/trunk/src/apps/showimage/ShowImageWindow.cpp
===================================================================
--- haiku/trunk/src/apps/showimage/ShowImageWindow.cpp  2010-03-21 18:19:56 UTC 
(rev 35928)
+++ haiku/trunk/src/apps/showimage/ShowImageWindow.cpp  2010-03-22 14:46:01 UTC 
(rev 35929)
@@ -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 @@
 };
 
 
-ShowImageWindow::RecentDocumentsMenu::RecentDocumentsMenu(const char *title,
+ShowImageWindow::RecentDocumentsMenu::RecentDocumentsMenu(const char* title,
        menu_layout layout)
        :
        BMenu(title, layout)
@@ -77,7 +80,7 @@
        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* 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 @@
        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 @@
        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 @@
        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 @@
        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 @@
                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 @@
 
 
 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 @@
        //               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 @@
 
        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 @@
 
 
 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 @@
 
 
 void
-ShowImageWindow::WindowRedimension(BBitmap *pbitmap)
+ShowImageWindow::WindowRedimension(BBitmap* pbitmap)
 {
        BScreen screen;
        if (!screen.IsValid())
@@ -468,7 +488,7 @@
 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 @@
 
 
 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 @@
 
 
 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 @@
 
 
 void
-ShowImageWindow::MessageReceived(BMessage *message)
+ShowImageWindow::MessageReceived(BMessage* message)
 {
        switch (message->what) {
                case MSG_MODIFIED:
@@ -578,7 +598,7 @@
 
                                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 @@
                                        BString strCaption;
                                        strCaption << i;

[... truncated: 125 lines follow ...]

Other related posts:

  • » [haiku-commits] r35929 - haiku/trunk/src/apps/showimage - superstippi