xref: /haiku/src/add-ons/translators/tiff/TIFFMain.cpp (revision cbe35e2031cb2bfb757422f35006bb9bd382bed1)
1 /*****************************************************************************/
2 // TIFFTranslator
3 // Written by Michael Wilber, OBOS Translation Kit Team
4 //
5 // Version:
6 //
7 // This translator opens and writes TIFF images.
8 //
9 //
10 // This application and all source files used in its construction, except
11 // where noted, are licensed under the MIT License, and have been written
12 // and are:
13 //
14 // Copyright (c) 2003 OpenBeOS Project
15 //
16 // Permission is hereby granted, free of charge, to any person obtaining a
17 // copy of this software and associated documentation files (the "Software"),
18 // to deal in the Software without restriction, including without limitation
19 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
20 // and/or sell copies of the Software, and to permit persons to whom the
21 // Software is furnished to do so, subject to the following conditions:
22 //
23 // The above copyright notice and this permission notice shall be included
24 // in all copies or substantial portions of the Software.
25 //
26 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
27 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
28 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
29 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
30 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
31 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
32 // DEALINGS IN THE SOFTWARE.
33 /*****************************************************************************/
34 
35 #include <Application.h>
36 #include <Screen.h>
37 #include <Alert.h>
38 #include "TIFFTranslator.h"
39 #include "TIFFWindow.h"
40 #include "TIFFView.h"
41 
42 // ---------------------------------------------------------------
43 // main
44 //
45 // Creates a BWindow for displaying info about the TIFFTranslator
46 //
47 // Preconditions:
48 //
49 // Parameters:
50 //
51 // Postconditions:
52 //
53 // Returns:
54 // ---------------------------------------------------------------
55 int
56 main()
57 {
58 	BApplication app("application/x-vnd.obos-tiff-translator");
59 	TIFFTranslator *ptranslator = new TIFFTranslator;
60 	BView *view = NULL;
61 	BRect rect(0, 0, 225, 175);
62 	if (ptranslator->MakeConfigurationView(NULL, &view, &rect)) {
63 		BAlert *err = new BAlert("Error",
64 			"Unable to create the TIFFTranslator view.", "OK");
65 		err->Go();
66 		return 1;
67 	}
68 	// release the translator even though I never really used it anyway
69 	ptranslator->Release();
70 	ptranslator = NULL;
71 
72 	TIFFWindow *wnd = new TIFFWindow(rect);
73 	view->ResizeTo(rect.Width(), rect.Height());
74 	wnd->AddChild(view);
75 	BPoint wndpt = B_ORIGIN;
76 	{
77 		BScreen scrn;
78 		BRect frame = scrn.Frame();
79 		frame.InsetBy(10, 23);
80 		// if the point is outside of the screen frame,
81 		// use the mouse location to find a better point
82 		if (!frame.Contains(wndpt)) {
83 			uint32 dummy;
84 			view->GetMouse(&wndpt, &dummy, false);
85 			wndpt.x -= rect.Width() / 2;
86 			wndpt.y -= rect.Height() / 2;
87 			// clamp location to screen
88 			if (wndpt.x < frame.left)
89 				wndpt.x = frame.left;
90 			if (wndpt.y < frame.top)
91 				wndpt.y = frame.top;
92 			if (wndpt.x > frame.right)
93 				wndpt.x = frame.right;
94 			if (wndpt.y > frame.bottom)
95 				wndpt.y = frame.bottom;
96 		}
97 	}
98 	wnd->MoveTo(wndpt);
99 	wnd->Show();
100 	app.Run();
101 
102 	return 0;
103 }
104