xref: /haiku/src/apps/showimage/PrintOptionsWindow.h (revision 9563f44bfd75799f67201067483694e82b5779b9)
1 /*
2  * Copyright 2003-2009 Haiku Inc. All rights reserved.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  *		Michael Pfeiffer, laplace@haiku-os.org
7  */
8 #ifndef PRINT_OPTIONS_WINDOW_H
9 #define PRINT_OPTIONS_WINDOW_H
10 
11 
12 #include <Messenger.h>
13 #include <RadioButton.h>
14 #include <Rect.h>
15 #include <TextControl.h>
16 #include <Window.h>
17 
18 
19 class PrintOptions {
20 public:
21 					PrintOptions();
22 
23 	// bounds of the image
24 	BRect 			Bounds() const { return fBounds; }
25 	void 			SetBounds(BRect bounds);
26 
27 	enum Option {
28 		kFitToPage,
29 		kZoomFactor,
30 		kDPI,
31 		kWidth,
32 		kHeight,
33 		kNumberOfOptions
34 	};
35 	enum Option		Option() const { return fOption; }
36 	void 			SetOption(enum Option op) { fOption = op; }
37 
38 	// ZoomFactor = 72.0 / dpi
39 	float 			ZoomFactor() const { return fZoomFactor; }
40 	void 			SetZoomFactor(float z);
41 	float 			DPI() const { return fDPI; }
42 	void 			SetDPI(float dpi);
43 
44 	// Setting width/height updates height/width to keep aspect ratio
45 	float 			Width() const { return fWidth; }
46 	float 			Height() const { return fHeight; }
47 	void 			SetWidth(float width);
48 	void 			SetHeight(float height);
49 
50 private:
51 	BRect 			fBounds;
52 	enum Option		fOption;
53 	float 			fZoomFactor;
54 	float 			fDPI;
55 	float 			fWidth, fHeight; // 1/72 Inches
56 };
57 
58 class PrintOptionsWindow : public BWindow {
59 public:
60 								PrintOptionsWindow(BPoint at,
61 									PrintOptions* options, BWindow* listener);
62 								~PrintOptionsWindow();
63 
64 	void 			MessageReceived(BMessage* msg);
65 
66 private:
67 	BRadioButton* 				AddRadioButton(BView* view, BPoint& at,
68 									const char* name, const char* label,
69 									uint32 what, bool selected);
70 
71 	BTextControl* 				AddTextControl(BView* view, BPoint& at,
72 									const char* name, const char* label,
73 									float value, float divider, uint32 what);
74 
75 	void						Setup();
76 	enum PrintOptions::Option	MsgToOption(uint32 what);
77 	bool						GetValue(BTextControl* text, float* value);
78 	void						SetValue(BTextControl* text, float value);
79 
80 	PrintOptions* 				fPrintOptions;
81 	PrintOptions 				fCurrentOptions;
82 	BMessenger 					fListener;
83 	status_t 					fStatus;
84 	BTextControl* 				fZoomFactor;
85 	BTextControl* 				fDPI;
86 	BTextControl* 				fWidth;
87 	BTextControl* 				fHeight;
88 
89 	enum {
90 		kMsgOK = 'mPOW',
91 		kMsgFitToPageSelected,
92 		kMsgZoomFactorSelected,
93 		kMsgDPISelected,
94 		kMsgWidthAndHeightSelected,
95 
96 		kMsgZoomFactorChanged,
97 		kMsgDPIChanged,
98 		kMsgWidthChanged,
99 		kMsgHeightChanged,
100 
101 		kMsgJobSetup,
102 
103 		kIndent = 5,
104 		kLineSkip = 5,
105 	};
106 };
107 
108 
109 #endif
110 
111