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 // 10 // 11 // Copyright (c) 2004 OpenBeOS Project 12 // 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: 19 // 20 // The above copyright notice and this permission notice shall be included 21 // in all copies or substantial portions of the Software. 22 // 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 /*****************************************************************************/ 31 32 #include <Screen.h> 33 #include <Alert.h> 34 #include "TranslatorWindow.h" 35 36 // --------------------------------------------------------------- 37 // Constructor 38 // 39 // Sets up the BWindow for holding a Translator's BView object 40 // 41 // Preconditions: 42 // 43 // Parameters: area, The bounds of the window 44 // 45 // Postconditions: 46 // 47 // Returns: 48 // --------------------------------------------------------------- 49 TranslatorWindow::TranslatorWindow(BRect area, const char *title) 50 : BWindow(area, title, B_TITLED_WINDOW, 51 B_NOT_RESIZABLE | B_NOT_ZOOMABLE) 52 { 53 } 54 55 // --------------------------------------------------------------- 56 // Destructor 57 // 58 // Posts a quit message so that the application is close properly 59 // 60 // Preconditions: 61 // 62 // Parameters: 63 // 64 // Postconditions: 65 // 66 // Returns: 67 // --------------------------------------------------------------- 68 TranslatorWindow::~TranslatorWindow() 69 { 70 be_app->PostMessage(B_QUIT_REQUESTED); 71 } 72 73 status_t 74 LaunchTranslatorWindow(BTranslator *translator, const char *title, BRect rect) 75 { 76 BView *view = NULL; 77 if (translator->MakeConfigurationView(NULL, &view, &rect)) { 78 BAlert *err = new BAlert("Error", 79 "Unable to create the view.", "OK"); 80 err->Go(); 81 return B_ERROR; 82 } 83 // release the translator even though I never really used it anyway 84 translator->Release(); 85 translator = NULL; 86 87 TranslatorWindow *wnd = new TranslatorWindow(rect, title); 88 view->ResizeTo(rect.Width(), rect.Height()); 89 wnd->AddChild(view); 90 BPoint wndpt = B_ORIGIN; 91 { 92 BScreen scrn; 93 BRect frame = scrn.Frame(); 94 frame.InsetBy(10, 23); 95 // if the point is outside of the screen frame, 96 // use the mouse location to find a better point 97 if (!frame.Contains(wndpt)) { 98 uint32 dummy; 99 view->GetMouse(&wndpt, &dummy, false); 100 wndpt.x -= rect.Width() / 2; 101 wndpt.y -= rect.Height() / 2; 102 // clamp location to screen 103 if (wndpt.x < frame.left) 104 wndpt.x = frame.left; 105 if (wndpt.y < frame.top) 106 wndpt.y = frame.top; 107 if (wndpt.x > frame.right) 108 wndpt.x = frame.right; 109 if (wndpt.y > frame.bottom) 110 wndpt.y = frame.bottom; 111 } 112 } 113 wnd->MoveTo(wndpt); 114 wnd->Show(); 115 116 return B_OK; 117 } 118 119