5 Copyright (c) 2002 OpenBeOS.
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
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:
43 Get methods to retrieve:
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:
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
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
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 );
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);
90 4) Flip Page with methods:
92 mv-SetPageSize( pageHeight, pageWidth );
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.
105 BPoint pageSize = mv->GetPageSize();
109 BRect margins = mv->GetMargins();
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>
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';
146 class PageView
: public BView
151 void SetPageSize(float pageWidth
, float pageHeight
);
152 void SetMargins(BRect margins
);
154 virtual void Draw(BRect bounds
);
167 class MarginView
: public BBox
169 friend class MarginManager
;
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
);
187 BRect
Margin() const;
190 MarginUnit
Unit() const;
192 // will cause a recalc and redraw
193 void UpdateView(uint32 msg
);
196 // all the GUI construction code
197 void _ConstructGUI();
200 void _AllowOnlyNumbers(BTextControl
*textControl
,
203 // performed internally using text fields
204 void _SetMargin(BRect margin
);
206 // performed internally using the supplied popup
207 void _SetMarginUnit(MarginUnit unit
);
211 BTextControl
* fBottom
;
213 BTextControl
* fRight
;
215 // the actual size of the page in points
219 // rect that holds the margins for the page as a set of point offsets
222 // the units used to calculate the page size
223 MarginUnit fMarginUnit
;
227 BStringView
* fPageSize
;
230 #endif // _MARGIN_VIEW_H