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 #include <GroupLayout.h> 13 14 #include <stdio.h> 15 16 17 BPoint get_window_origin(); 18 void set_window_origin(BPoint pt); 19 20 class PPMWindow : 21 public BWindow 22 { 23 public: 24 PPMWindow(BRect area) : 25 BWindow(area, "PPM Settings", B_TITLED_WINDOW, 26 B_NOT_RESIZABLE | B_NOT_ZOOMABLE | B_AUTO_UPDATE_SIZE_LIMITS) 27 { 28 SetLayout(new BGroupLayout(B_HORIZONTAL)); 29 } 30 ~PPMWindow() 31 { 32 BPoint pt(0,0); 33 ConvertToScreen(&pt); 34 set_window_origin(pt); 35 be_app->PostMessage(B_QUIT_REQUESTED); 36 } 37 }; 38 39 int 40 main() 41 { 42 BApplication app("application/x-vnd.Haiku-PPMTranslator"); 43 BView * v = NULL; 44 BRect r(0, 0, 1, 1); 45 if (MakeConfig(NULL, &v, &r)) { 46 BAlert * err = new BAlert("Error", "Something is wrong with the PPMTranslator!", "OK"); 47 err->Go(); 48 return 1; 49 } 50 PPMWindow *w = new PPMWindow(r); 51 v->ResizeTo(r.Width(), r.Height()); 52 w->AddChild(v); 53 BPoint o = get_window_origin(); 54 { 55 BScreen scrn; 56 BRect f = scrn.Frame(); 57 f.InsetBy(10,23); 58 /* if not in a good place, start where the cursor is */ 59 if (!f.Contains(o)) { 60 uint32 i; 61 v->GetMouse(&o, &i, false); 62 o.x -= r.Width()/2; 63 o.y -= r.Height()/2; 64 /* clamp location to screen */ 65 if (o.x < f.left) o.x = f.left; 66 if (o.y < f.top) o.y = f.top; 67 if (o.x > f.right) o.x = f.right; 68 if (o.y > f.bottom) o.y = f.bottom; 69 } 70 } 71 w->MoveTo(o); 72 w->Show(); 73 app.Run(); 74 return 0; 75 } 76 77