xref: /haiku/src/add-ons/translators/ppm/PPMMain.cpp (revision 4466b89c65970de4c7236ac87faa2bee4589f413)
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 <Alert.h>
7 #include <Application.h>
8 #include <Catalog.h>
9 #include <GroupLayout.h>
10 #include <Screen.h>
11 #include <TranslatorAddOn.h>
12 #include <View.h>
13 #include <Window.h>
14 
15 
16 #include <stdio.h>
17 
18 #undef B_TRANSLATE_CONTEXT
19 #define B_TRANSLATE_CONTEXT "PPMMain"
20 
21 
22 BPoint get_window_origin();
23 void set_window_origin(BPoint pt);
24 
25 class PPMWindow :
26 	public BWindow
27 {
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)
32 		{
33 			SetLayout(new BGroupLayout(B_HORIZONTAL));
34 		}
35 	~PPMWindow()
36 		{
37 			BPoint pt(0,0);
38 			ConvertToScreen(&pt);
39 			set_window_origin(pt);
40 			be_app->PostMessage(B_QUIT_REQUESTED);
41 		}
42 };
43 
44 int
45 main()
46 {
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->Go();
55 		return 1;
56 	}
57 	PPMWindow *w = new PPMWindow(r);
58 	v->ResizeTo(r.Width(), r.Height());
59 	w->AddChild(v);
60 	BPoint o = get_window_origin();
61 	{
62 		BScreen scrn;
63 		BRect f = scrn.Frame();
64 		f.InsetBy(10,23);
65 		/* if not in a good place, start where the cursor is */
66 		if (!f.Contains(o)) {
67 			uint32 i;
68 			v->GetMouse(&o, &i, false);
69 			o.x -= r.Width()/2;
70 			o.y -= r.Height()/2;
71 			/* clamp location to screen */
72 			if (o.x < f.left) o.x = f.left;
73 			if (o.y < f.top) o.y = f.top;
74 			if (o.x > f.right) o.x = f.right;
75 			if (o.y > f.bottom) o.y = f.bottom;
76 		}
77 	}
78 	w->MoveTo(o);
79 	w->Show();
80 	app.Run();
81 	return 0;
82 }
83 
84