Fix FreeBSD build.
[haiku.git] / src / tools / translation / inspector / ImageWindow.cpp
blob3ab8f73df7239d1e47bf12fce1c8e2c9c5a3f736
1 /*****************************************************************************/
2 // ImageWindow
3 // Written by Michael Wilber, OBOS Translation Kit Team
4 //
5 // ImageWindow.cpp
6 //
7 // BWindow class for displaying an image. Uses ImageView class for its
8 // view.
9 //
11 // Copyright (c) 2003 OpenBeOS Project
13 // Permission is hereby granted, free of charge, to any person obtaining a
14 // copy of this software and associated documentation files (the "Software"),
15 // to deal in the Software without restriction, including without limitation
16 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
17 // and/or sell copies of the Software, and to permit persons to whom the
18 // Software is furnished to do so, subject to the following conditions:
20 // The above copyright notice and this permission notice shall be included
21 // in all copies or substantial portions of the Software.
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29 // DEALINGS IN THE SOFTWARE.
30 /*****************************************************************************/
32 #include "ImageWindow.h"
33 #include "Constants.h"
34 #include <Application.h>
35 #include <Catalog.h>
36 #include <Locale.h>
37 #include <MenuBar.h>
38 #include <MenuItem.h>
39 #include <Menu.h>
40 #include <ScrollView.h>
41 #include <Alert.h>
43 #undef B_TRANSLATION_CONTEXT
44 #define B_TRANSLATION_CONTEXT "ImageWindow"
47 ImageWindow::ImageWindow(BRect rect, const char *name)
48 : BWindow(rect, name, B_DOCUMENT_WINDOW, 0)
50 // Setup menu bar
51 BRect rctbar(0, 0, 100, 10);
52 BMenuBar *pbar = new BMenuBar(rctbar, "MenuBar");
54 BMenu *pmnufile = new BMenu(B_TRANSLATE("File"));
55 BMenuItem *pitmopen = new BMenuItem(B_TRANSLATE("Open" B_UTF8_ELLIPSIS),
56 new BMessage(M_OPEN_IMAGE), 'O', 0);
58 BMenuItem *pitmsave = new BMenuItem(B_TRANSLATE("Save" B_UTF8_ELLIPSIS),
59 new BMessage(M_SAVE_IMAGE), 'S', 0);
61 BMenuItem *pitmquit = new BMenuItem(B_TRANSLATE("Quit"),
62 new BMessage(B_QUIT_REQUESTED), 'Q', 0);
64 pmnufile->AddItem(pitmopen);
65 pmnufile->AddItem(pitmsave);
66 pmnufile->AddSeparatorItem();
67 pmnufile->AddItem(pitmquit);
68 pbar->AddItem(pmnufile);
70 BMenu *pmnuview = new BMenu(B_TRANSLATE("View"));
71 BMenuItem *pitmfirst = new BMenuItem(B_TRANSLATE("First Page"),
72 new BMessage(M_VIEW_FIRST_PAGE), 'F', 0);
74 BMenuItem *pitmlast = new BMenuItem(B_TRANSLATE("Last Page"),
75 new BMessage(M_VIEW_LAST_PAGE), 'L', 0);
77 BMenuItem *pitmnext = new BMenuItem(B_TRANSLATE("Next Page"),
78 new BMessage(M_VIEW_NEXT_PAGE), 'N', 0);
80 BMenuItem *pitmprev = new BMenuItem(B_TRANSLATE("Previous Page"),
81 new BMessage(M_VIEW_PREV_PAGE), 'P', 0);
83 pmnuview->AddItem(pitmfirst);
84 pmnuview->AddItem(pitmlast);
85 pmnuview->AddItem(pitmnext);
86 pmnuview->AddItem(pitmprev);
87 pbar->AddItem(pmnuview);
90 BMenu *pmnuwindow = new BMenu(B_TRANSLATE("Window"));
91 BMenuItem *pitmactives = new BMenuItem(B_TRANSLATE("Active Translators"),
92 new BMessage(M_ACTIVE_TRANSLATORS_WINDOW), 'T', 0);
93 pitmactives->SetTarget(be_app);
95 BMenuItem *pitminfo = new BMenuItem(B_TRANSLATE("Info"),
96 new BMessage(M_INFO_WINDOW), 'I', 0);
97 pitminfo->SetTarget(be_app);
99 pmnuwindow->AddItem(pitmactives);
100 pmnuwindow->AddItem(pitminfo);
101 pbar->AddItem(pmnuwindow);
103 AddChild(pbar);
105 // Setup image view
106 BRect rctview = Bounds();
107 rctview.top = pbar->Frame().bottom + 1;
108 rctview.right -= B_V_SCROLL_BAR_WIDTH;
109 rctview.bottom -= B_H_SCROLL_BAR_HEIGHT;
111 fpimageView = new ImageView(rctview, "ImageView");
112 AddChild(new BScrollView("ImageScroll", fpimageView,
113 B_FOLLOW_ALL_SIDES, 0, true, true));
115 // Setup file open panel
116 BMessenger messenger(this);
117 BMessage message(M_OPEN_FILE_PANEL);
118 fpopenPanel = new BFilePanel(B_OPEN_PANEL, &messenger, NULL, 0L, false,
119 &message, NULL, false, true);
121 SetSizeLimits(200, 10000, 150, 10000);
124 ImageWindow::~ImageWindow()
126 delete fpopenPanel;
127 fpopenPanel = NULL;
130 void
131 ImageWindow::MessageReceived(BMessage *pmsg)
133 switch (pmsg->what) {
134 case M_OPEN_IMAGE:
135 fpopenPanel->Window()->SetWorkspaces(B_CURRENT_WORKSPACE);
136 fpopenPanel->Show();
137 break;
139 case M_SAVE_IMAGE:
140 if (fpimageView->HasImage()) {
141 BAlert *palert = new BAlert(NULL,
142 B_TRANSLATE("Save feature not implemented yet."),
143 B_TRANSLATE("Bummer"));
144 palert->Go();
145 } else {
146 BAlert *palert = new BAlert(NULL,
147 B_TRANSLATE("No image available to save."),
148 B_TRANSLATE("OK"));
149 palert->Go();
151 break;
153 case M_OPEN_FILE_PANEL:
154 case B_SIMPLE_DATA:
155 fpimageView->SetImage(pmsg);
156 break;
158 case M_VIEW_FIRST_PAGE:
159 fpimageView->FirstPage();
160 break;
161 case M_VIEW_LAST_PAGE:
162 fpimageView->LastPage();
163 break;
164 case M_VIEW_NEXT_PAGE:
165 fpimageView->NextPage();
166 break;
167 case M_VIEW_PREV_PAGE:
168 fpimageView->PrevPage();
169 break;
171 case B_CANCEL:
172 break;
174 default:
175 BWindow::MessageReceived(pmsg);
176 break;
180 bool
181 ImageWindow::QuitRequested()
183 be_app->PostMessage(B_QUIT_REQUESTED);
184 return true;