BPicture: Fix archive constructor.
[haiku.git] / src / add-ons / translators / ppm / PPMMain.cpp
blob7a226055ce7be869b91f6206be4eda35253a1d35
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 */
6 #include <Alert.h>
7 #include <Application.h>
8 #include <Catalog.h>
9 #include <LayoutBuilder.h>
10 #include <Screen.h>
11 #include <TranslatorAddOn.h>
12 #include <View.h>
13 #include <Window.h>
16 #include <stdio.h>
18 #undef B_TRANSLATION_CONTEXT
19 #define B_TRANSLATION_CONTEXT "PPMMain"
22 BPoint get_window_origin();
23 void set_window_origin(BPoint pt);
25 class PPMWindow :
26 public BWindow
28 public:
29 PPMWindow(BRect area) :
30 BWindow(area, B_TRANSLATE("PPM Settings"), B_TITLED_WINDOW,
31 B_NOT_RESIZABLE | B_NOT_ZOOMABLE | B_AUTO_UPDATE_SIZE_LIMITS)
33 BLayoutBuilder::Group<>(this, B_HORIZONTAL);
35 ~PPMWindow()
37 BPoint pt(0,0);
38 ConvertToScreen(&pt);
39 set_window_origin(pt);
40 be_app->PostMessage(B_QUIT_REQUESTED);
44 int
45 main()
47 BApplication app("application/x-vnd.Haiku-PPMTranslator");
48 BView * v = NULL;
49 BRect r(0, 0, 1, 1);
50 if (MakeConfig(NULL, &v, &r)) {
51 BAlert * err = new BAlert("Error",
52 B_TRANSLATE("Something is wrong with the PPMTranslator!"),
53 B_TRANSLATE("OK"));
54 err->SetFlags(err->Flags() | B_CLOSE_ON_ESCAPE);
55 err->Go();
56 return 1;
58 PPMWindow *w = new PPMWindow(r);
59 v->ResizeTo(r.Width(), r.Height());
60 w->AddChild(v);
61 BPoint o = get_window_origin();
63 BScreen scrn;
64 BRect f = scrn.Frame();
65 f.InsetBy(10,23);
66 /* if not in a good place, start where the cursor is */
67 if (!f.Contains(o)) {
68 uint32 i;
69 v->GetMouse(&o, &i, false);
70 o.x -= r.Width()/2;
71 o.y -= r.Height()/2;
72 /* clamp location to screen */
73 if (o.x < f.left) o.x = f.left;
74 if (o.y < f.top) o.y = f.top;
75 if (o.x > f.right) o.x = f.right;
76 if (o.y > f.bottom) o.y = f.bottom;
79 w->MoveTo(o);
80 w->Show();
81 app.Run();
82 return 0;