1 /* 2 Copyright 1999, Be Incorporated. All Rights Reserved. 3 This file may be used under the terms of the Be Sample Code License. 4 */ 5 6 #include <TranslatorAddOn.h> 7 #include <View.h> 8 #include <Window.h> 9 #include <Application.h> 10 #include <Alert.h> 11 #include <Screen.h> 12 13 #include <stdio.h> 14 15 16 BPoint get_window_origin(); 17 void set_window_origin(BPoint pt); 18 19 class PPMWindow : 20 public BWindow 21 { 22 public: 23 PPMWindow( 24 BRect area) : 25 BWindow(area, "PPM Settings", B_TITLED_WINDOW, B_NOT_RESIZABLE | B_NOT_ZOOMABLE) 26 { 27 } 28 ~PPMWindow() 29 { 30 BPoint pt(0,0); 31 ConvertToScreen(&pt); 32 set_window_origin(pt); 33 be_app->PostMessage(B_QUIT_REQUESTED); 34 } 35 }; 36 37 int 38 main() 39 { 40 BApplication app("application/x-vnd.hplus-ppm-translator"); 41 BView * v = NULL; 42 BRect r(0,0,225,175); 43 if (MakeConfig(NULL, &v, &r)) { 44 BAlert * err = new BAlert("Error", "Something is wrong with the PPMTranslator!", "OK"); 45 err->Go(); 46 return 1; 47 } 48 PPMWindow *w = new PPMWindow(r); 49 v->ResizeTo(r.Width(), r.Height()); 50 w->AddChild(v); 51 BPoint o = get_window_origin(); 52 { 53 BScreen scrn; 54 BRect f = scrn.Frame(); 55 f.InsetBy(10,23); 56 /* if not in a good place, start where the cursor is */ 57 if (!f.Contains(o)) { 58 uint32 i; 59 v->GetMouse(&o, &i, false); 60 o.x -= r.Width()/2; 61 o.y -= r.Height()/2; 62 /* clamp location to screen */ 63 if (o.x < f.left) o.x = f.left; 64 if (o.y < f.top) o.y = f.top; 65 if (o.x > f.right) o.x = f.right; 66 if (o.y > f.bottom) o.y = f.bottom; 67 } 68 } 69 w->MoveTo(o); 70 w->Show(); 71 app.Run(); 72 return 0; 73 } 74 75