vfs: check userland buffers before reading them.
[haiku.git] / headers / libs / print / libprint / MarginView.h
blob040394cb56e31fbe83ecd5bf32d0d9736a2dd338
1 /*
3 MarginView.h
5 Copyright (c) 2002 OpenBeOS.
7 Authors:
8 Philippe Houdoin
9 Simon Gauvin
10 Michael Pfeiffer
12 Permission is hereby granted, free of charge, to any person obtaining a copy of
13 this software and associated documentation files (the "Software"), to deal in
14 the Software without restriction, including without limitation the rights to
15 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
16 of the Software, and to permit persons to whom the Software is furnished to do
17 so, subject to the following conditions:
19 The above copyright notice and this permission notice shall be included in all
20 copies or substantial portions of the Software.
22 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
28 THE SOFTWARE.
30 Documentation:
32 The MarginView is designed to be a self contained component that manages
33 the display of a BBox control that shows a graphic of a page and its'
34 margings. The component also includes text fields that are used to mofify
35 the margin values and a popup to change the units used for the margins.
37 There are two interfaces for the MarginView component:
39 1) Set methods:
40 - page size
41 - orientation
43 Get methods to retrieve:
44 - margins
45 - page size
47 The method interface is available for the parent Component to call on
48 the MarginView in response to the Window receiveing messages from
49 other BControls that it contains, such as a Page Size popup. The
50 Get methods are used to extract the page size and margins so that
51 the printer driver may put these values into a BMessage for printing.
53 2) 'Optional' Message interface:
54 - Set Page Size
55 - Flip Orientation
57 The message interface is available for GUI Controls, BPopupMenu to send
58 messages to the MarginView if the parent Window is not used to handle
59 the messages.
61 General Use of MarginView component:
63 1) Simply construct a new MarginView object with the margins
64 you want as defaults and add this view to the parent view
65 of the dialog.
67 MarginView *mv;
68 mv = new MarginView(viewSizeRect, pageWidth, pageHeight);
69 parentView->AddChild(mv);
71 * you can also set the margins in the constructor, and the units:
73 mv = new MarginView(viewSizeRect, pageWidth, pageHeight
74 marginRect, kUnitPointS);
76 ! but remeber to have the marginRect values match the UNITS :-)
78 2) Set Page Size with methods:
80 mv-SetPageSize( pageWidth, pageHeight );
81 mv->UpdateView();
83 3) Set Page Size with BMessage:
85 BMessage* msg = new BMessage(CHANGE_PAGE_SIZE);
86 msg->AddFloat("width", pageWidth);
87 msg->AddFloat("height", pageHeight);
88 mv->PostMessage(msg);
90 4) Flip Page with methods:
92 mv-SetPageSize( pageHeight, pageWidth );
93 mv->UpdateView();
95 5) Flip Page with BMessage:
97 BMessage* msg = new BMessage(FLIP_PAGE);
98 mv->Looper()->PostMessage(msg);
100 Note: the MarginView DOES NOT keep track of the orientation. This
101 should be done by the code for the Page setup dialog.
103 6) Get Page Size
105 BPoint pageSize = mv->GetPageSize();
107 7) Get Margins
109 BRect margins = mv->GetMargins();
111 8) Get Units
113 uint32 units = mv->GetUnits();
115 where units is one of:
116 kUnitInch, 72 points/in
117 kUnitCM, 28.346 points/cm
118 kUnitPoint, 1 point/point
121 #ifndef _MARGIN_VIEW_H
122 #define _MARGIN_VIEW_H
124 #include <InterfaceKit.h>
125 #include <Looper.h>
127 class BTextControl;
128 class MarginManager;
130 // Messages that the MarginManager accepts
131 const uint32 TOP_MARGIN_CHANGED = 'tchg';
132 const uint32 RIGHT_MARGIN_CHANGED = 'rchg';
133 const uint32 LEFT_MARGIN_CHANGED = 'lchg';
134 const uint32 BOTTOM_MARGIN_CHANGED = 'bchg';
135 const uint32 MARGIN_CHANGED = 'mchg';
136 const uint32 CHANGE_PAGE_SIZE = 'chps';
137 const uint32 FLIP_PAGE = 'flip';
138 const uint32 MARGIN_UNIT_CHANGED = 'mucg';
140 enum MarginUnit {
141 kUnitInch = 0,
142 kUnitCM,
143 kUnitPoint
146 class PageView : public BView
148 public:
149 PageView();
151 void SetPageSize(float pageWidth, float pageHeight);
152 void SetMargins(BRect margins);
154 virtual void Draw(BRect bounds);
157 private:
158 float fPageWidth;
159 float fPageHeight;
161 BRect fMargins;
165 * Class MarginView
167 class MarginView : public BBox
169 friend class MarginManager;
171 public:
172 MarginView(int32 pageWidth = 0,
173 int32 pageHeight = 0,
174 BRect margins = BRect(1, 1, 1, 1), // 1 inch
175 MarginUnit unit = kUnitInch);
177 virtual ~MarginView();
179 virtual void AttachedToWindow();
180 virtual void MessageReceived(BMessage *msg);
182 // point.x = width, point.y = height
183 BPoint PageSize() const;
184 void SetPageSize(float pageWidth, float pageHeight);
186 // margin
187 BRect Margin() const;
189 // units
190 MarginUnit Unit() const;
192 // will cause a recalc and redraw
193 void UpdateView(uint32 msg);
195 private:
196 // all the GUI construction code
197 void _ConstructGUI();
199 // utility method
200 void _AllowOnlyNumbers(BTextControl *textControl,
201 int32 maxNum);
203 // performed internally using text fields
204 void _SetMargin(BRect margin);
206 // performed internally using the supplied popup
207 void _SetMarginUnit(MarginUnit unit);
209 private:
210 BTextControl* fTop;
211 BTextControl* fBottom;
212 BTextControl* fLeft;
213 BTextControl* fRight;
215 // the actual size of the page in points
216 float fPageHeight;
217 float fPageWidth;
219 // rect that holds the margins for the page as a set of point offsets
220 BRect fMargins;
222 // the units used to calculate the page size
223 MarginUnit fMarginUnit;
224 float fUnitValue;
226 PageView* fPage;
227 BStringView* fPageSize;
230 #endif // _MARGIN_VIEW_H