1 /*****************************************************************************/
3 // Written by Michael Wilber, OBOS Translation Kit Team
5 // TranslatorWindow.cpp
7 // This BWindow based object is used to hold the Translator's BView object
8 // when the user runs the Translator as an application.
11 // Copyright (c) 2004 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 /*****************************************************************************/
34 #include <GroupLayout.h>
35 #include "TranslatorWindow.h"
38 #undef B_TRANSLATION_CONTEXT
39 #define B_TRANSLATION_CONTEXT "TranslatorWindow"
42 // ---------------------------------------------------------------
45 // Sets up the BWindow for holding a Translator's BView object
49 // Parameters: area, The bounds of the window
54 // ---------------------------------------------------------------
55 TranslatorWindow::TranslatorWindow(BRect area
, const char *title
)
56 : BWindow(area
, title
, B_TITLED_WINDOW
,
57 B_NOT_RESIZABLE
| B_NOT_ZOOMABLE
| B_AUTO_UPDATE_SIZE_LIMITS
)
59 SetLayout(new BGroupLayout(B_HORIZONTAL
));
60 // Set the layout on layout window
61 // Do nothing for a non-layout window
65 // ---------------------------------------------------------------
68 // Posts a quit message so that the application is close properly
77 // ---------------------------------------------------------------
78 TranslatorWindow::~TranslatorWindow()
80 be_app
->PostMessage(B_QUIT_REQUESTED
);
85 LaunchTranslatorWindow(BTranslator
*translator
, const char *title
, BRect rect
)
88 if (translator
->MakeConfigurationView(NULL
, &view
, &rect
)) {
89 BAlert
*err
= new BAlert(B_TRANSLATE("Error"),
90 B_TRANSLATE("Unable to create the view."), B_TRANSLATE("OK"));
91 err
->SetFlags(err
->Flags() | B_CLOSE_ON_ESCAPE
);
95 // release the translator even though I never really used it anyway
96 translator
->Release();
99 TranslatorWindow
*wnd
= new TranslatorWindow(rect
, title
);
101 BPoint wndpt
= B_ORIGIN
;
104 BRect frame
= scrn
.Frame();
105 frame
.InsetBy(10, 23);
106 // if the point is outside of the screen frame,
107 // use the mouse location to find a better point
108 if (!frame
.Contains(wndpt
)) {
110 view
->GetMouse(&wndpt
, &dummy
, false);
111 wndpt
.x
-= rect
.Width() / 2;
112 wndpt
.y
-= rect
.Height() / 2;
113 // clamp location to screen
114 if (wndpt
.x
< frame
.left
)
115 wndpt
.x
= frame
.left
;
116 if (wndpt
.y
< frame
.top
)
118 if (wndpt
.x
> frame
.right
)
119 wndpt
.x
= frame
.right
;
120 if (wndpt
.y
> frame
.bottom
)
121 wndpt
.y
= frame
.bottom
;