tcp: Add APICall trace entry and move TRACEs into locked parts.
[haiku.git] / src / add-ons / translators / shared / TranslatorWindow.cpp
blob824dcb4f5c299350bc5a93605155a9104f298d51
1 /*****************************************************************************/
2 // TranslatorWindow
3 // Written by Michael Wilber, OBOS Translation Kit Team
4 //
5 // TranslatorWindow.cpp
6 //
7 // This BWindow based object is used to hold the Translator's BView object
8 // when the user runs the Translator as an application.
9 //
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 /*****************************************************************************/
32 #include <Screen.h>
33 #include <Alert.h>
34 #include <GroupLayout.h>
35 #include "TranslatorWindow.h"
38 #undef B_TRANSLATION_CONTEXT
39 #define B_TRANSLATION_CONTEXT "TranslatorWindow"
42 // ---------------------------------------------------------------
43 // Constructor
45 // Sets up the BWindow for holding a Translator's BView object
47 // Preconditions:
49 // Parameters: area, The bounds of the window
51 // Postconditions:
53 // Returns:
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 // ---------------------------------------------------------------
66 // Destructor
68 // Posts a quit message so that the application is close properly
70 // Preconditions:
72 // Parameters:
74 // Postconditions:
76 // Returns:
77 // ---------------------------------------------------------------
78 TranslatorWindow::~TranslatorWindow()
80 be_app->PostMessage(B_QUIT_REQUESTED);
84 status_t
85 LaunchTranslatorWindow(BTranslator *translator, const char *title, BRect rect)
87 BView *view = NULL;
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);
92 err->Go();
93 return B_ERROR;
95 // release the translator even though I never really used it anyway
96 translator->Release();
97 translator = NULL;
99 TranslatorWindow *wnd = new TranslatorWindow(rect, title);
100 wnd->AddChild(view);
101 BPoint wndpt = B_ORIGIN;
103 BScreen scrn;
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)) {
109 uint32 dummy;
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)
117 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;
124 wnd->MoveTo(wndpt);
125 wnd->Show();
127 return B_OK;