2005-01-22 17:26:52 +03:00
|
|
|
/*
|
|
|
|
|
|
|
|
MarginView.h
|
|
|
|
|
|
|
|
Copyright (c) 2002 OpenBeOS.
|
|
|
|
|
2008-07-13 01:09:49 +04:00
|
|
|
Authors:
|
2005-01-22 17:26:52 +03:00
|
|
|
Philippe Houdoin
|
2008-07-13 01:09:49 +04:00
|
|
|
Simon Gauvin
|
2005-01-22 17:26:52 +03:00
|
|
|
Michael Pfeiffer
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
|
|
this software and associated documentation files (the "Software"), to deal in
|
|
|
|
the Software without restriction, including without limitation the rights to
|
|
|
|
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
|
|
|
of the Software, and to permit persons to whom the Software is furnished to do
|
|
|
|
so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in all
|
|
|
|
copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
|
|
|
|
Documentation:
|
2008-07-13 01:09:49 +04:00
|
|
|
|
2005-01-22 17:26:52 +03:00
|
|
|
The MarginView is designed to be a self contained component that manages
|
|
|
|
the display of a BBox control that shows a graphic of a page and its'
|
|
|
|
margings. The component also includes text fields that are used to mofify
|
|
|
|
the margin values and a popup to change the units used for the margins.
|
|
|
|
|
|
|
|
There are two interfaces for the MarginView component:
|
2008-07-13 01:09:49 +04:00
|
|
|
|
2005-01-22 17:26:52 +03:00
|
|
|
1) Set methods:
|
|
|
|
- page size
|
|
|
|
- orientation
|
2008-07-13 01:09:49 +04:00
|
|
|
|
2005-01-22 17:26:52 +03:00
|
|
|
Get methods to retrieve:
|
|
|
|
- margins
|
|
|
|
- page size
|
2008-07-13 01:09:49 +04:00
|
|
|
|
|
|
|
The method interface is available for the parent Component to call on
|
2005-01-22 17:26:52 +03:00
|
|
|
the MarginView in response to the Window receiveing messages from
|
|
|
|
other BControls that it contains, such as a Page Size popup. The
|
2008-07-13 01:09:49 +04:00
|
|
|
Get methods are used to extract the page size and margins so that
|
2005-01-22 17:26:52 +03:00
|
|
|
the printer driver may put these values into a BMessage for printing.
|
2008-07-13 01:09:49 +04:00
|
|
|
|
2005-01-22 17:26:52 +03:00
|
|
|
2) 'Optional' Message interface:
|
|
|
|
- Set Page Size
|
|
|
|
- Flip Orientation
|
2008-07-13 01:09:49 +04:00
|
|
|
|
|
|
|
The message interface is available for GUI Controls, BPopupMenu to send
|
2005-01-22 17:26:52 +03:00
|
|
|
messages to the MarginView if the parent Window is not used to handle
|
2008-07-13 01:09:49 +04:00
|
|
|
the messages.
|
2005-01-22 17:26:52 +03:00
|
|
|
|
|
|
|
General Use of MarginView component:
|
2008-07-13 01:09:49 +04:00
|
|
|
|
|
|
|
1) Simply construct a new MarginView object with the margins
|
|
|
|
you want as defaults and add this view to the parent view
|
2005-01-22 17:26:52 +03:00
|
|
|
of the dialog.
|
|
|
|
|
|
|
|
MarginView *mv;
|
|
|
|
mv = new MarginView(viewSizeRect, pageWidth, pageHeight);
|
|
|
|
parentView->AddChild(mv);
|
|
|
|
|
|
|
|
* you can also set the margins in the constructor, and the units:
|
2008-07-13 01:09:49 +04:00
|
|
|
|
2005-01-22 17:26:52 +03:00
|
|
|
mv = new MarginView(viewSizeRect, pageWidth, pageHeight
|
|
|
|
marginRect, kUnitPointS);
|
|
|
|
|
|
|
|
! but remeber to have the marginRect values match the UNITS :-)
|
2008-07-13 01:09:49 +04:00
|
|
|
|
2005-01-22 17:26:52 +03:00
|
|
|
2) Set Page Size with methods:
|
|
|
|
|
|
|
|
mv-SetPageSize( pageWidth, pageHeight );
|
|
|
|
mv->UpdateView();
|
2008-07-13 01:09:49 +04:00
|
|
|
|
2005-01-22 17:26:52 +03:00
|
|
|
3) Set Page Size with BMessage:
|
|
|
|
|
|
|
|
BMessage* msg = new BMessage(CHANGE_PAGE_SIZE);
|
|
|
|
msg->AddFloat("width", pageWidth);
|
|
|
|
msg->AddFloat("height", pageHeight);
|
|
|
|
mv->PostMessage(msg);
|
|
|
|
|
|
|
|
4) Flip Page with methods:
|
2008-07-13 01:09:49 +04:00
|
|
|
|
2005-01-22 17:26:52 +03:00
|
|
|
mv-SetPageSize( pageHeight, pageWidth );
|
|
|
|
mv->UpdateView();
|
2008-07-13 01:09:49 +04:00
|
|
|
|
|
|
|
5) Flip Page with BMessage:
|
|
|
|
|
2005-01-22 17:26:52 +03:00
|
|
|
BMessage* msg = new BMessage(FLIP_PAGE);
|
|
|
|
mv->Looper()->PostMessage(msg);
|
|
|
|
|
|
|
|
Note: the MarginView DOES NOT keep track of the orientation. This
|
|
|
|
should be done by the code for the Page setup dialog.
|
|
|
|
|
|
|
|
6) Get Page Size
|
|
|
|
|
|
|
|
BPoint pageSize = mv->GetPageSize();
|
2008-07-13 01:09:49 +04:00
|
|
|
|
2005-01-22 17:26:52 +03:00
|
|
|
7) Get Margins
|
|
|
|
|
|
|
|
BRect margins = mv->GetMargins();
|
2008-07-13 01:09:49 +04:00
|
|
|
|
2005-01-22 17:26:52 +03:00
|
|
|
8) Get Units
|
2008-07-13 01:09:49 +04:00
|
|
|
|
2005-01-22 17:26:52 +03:00
|
|
|
uint32 units = mv->GetUnits();
|
|
|
|
|
2008-07-13 01:09:49 +04:00
|
|
|
where units is one of:
|
2005-01-22 17:26:52 +03:00
|
|
|
kUnitInch, 72 points/in
|
|
|
|
kUnitCM, 28.346 points/cm
|
|
|
|
kUnitPoint, 1 point/point
|
|
|
|
*/
|
|
|
|
|
2007-01-20 18:52:37 +03:00
|
|
|
#ifndef _MARGIN_VIEW_H
|
|
|
|
#define _MARGIN_VIEW_H
|
2005-01-22 17:26:52 +03:00
|
|
|
|
|
|
|
#include <InterfaceKit.h>
|
|
|
|
#include <Looper.h>
|
|
|
|
|
2008-07-13 01:09:49 +04:00
|
|
|
class BTextControl;
|
2005-01-22 17:26:52 +03:00
|
|
|
class MarginManager;
|
|
|
|
|
|
|
|
// Messages that the MarginManager accepts
|
|
|
|
const uint32 TOP_MARGIN_CHANGED = 'tchg';
|
|
|
|
const uint32 RIGHT_MARGIN_CHANGED = 'rchg';
|
|
|
|
const uint32 LEFT_MARGIN_CHANGED = 'lchg';
|
|
|
|
const uint32 BOTTOM_MARGIN_CHANGED = 'bchg';
|
|
|
|
const uint32 MARGIN_CHANGED = 'mchg';
|
|
|
|
const uint32 CHANGE_PAGE_SIZE = 'chps';
|
|
|
|
const uint32 FLIP_PAGE = 'flip';
|
|
|
|
const uint32 MARGIN_UNIT_CHANGED = 'mucg';
|
|
|
|
|
|
|
|
enum MarginUnit {
|
|
|
|
kUnitInch = 0,
|
|
|
|
kUnitCM,
|
|
|
|
kUnitPoint
|
|
|
|
};
|
|
|
|
|
2010-10-16 23:56:34 +04:00
|
|
|
class PageView : public BView
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
PageView();
|
|
|
|
|
|
|
|
void SetPageSize(float pageWidth, float pageHeight);
|
|
|
|
void SetMargins(BRect margins);
|
|
|
|
|
|
|
|
virtual void Draw(BRect bounds);
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
float fPageWidth;
|
|
|
|
float fPageHeight;
|
|
|
|
|
|
|
|
BRect fMargins;
|
|
|
|
};
|
|
|
|
|
2005-01-22 17:26:52 +03:00
|
|
|
/**
|
|
|
|
* Class MarginView
|
|
|
|
*/
|
2008-07-13 01:09:49 +04:00
|
|
|
class MarginView : public BBox
|
2005-01-22 17:26:52 +03:00
|
|
|
{
|
2006-10-24 02:39:57 +04:00
|
|
|
friend class MarginManager;
|
2005-01-22 17:26:52 +03:00
|
|
|
|
2008-07-13 01:09:49 +04:00
|
|
|
public:
|
2010-10-16 23:56:34 +04:00
|
|
|
MarginView(int32 pageWidth = 0,
|
2008-07-13 01:09:49 +04:00
|
|
|
int32 pageHeight = 0,
|
|
|
|
BRect margins = BRect(1, 1, 1, 1), // 1 inch
|
|
|
|
MarginUnit unit = kUnitInch);
|
|
|
|
|
|
|
|
virtual ~MarginView();
|
|
|
|
|
|
|
|
virtual void AttachedToWindow();
|
|
|
|
virtual void MessageReceived(BMessage *msg);
|
|
|
|
|
|
|
|
// point.x = width, point.y = height
|
|
|
|
BPoint PageSize() const;
|
|
|
|
void SetPageSize(float pageWidth, float pageHeight);
|
|
|
|
|
|
|
|
// margin
|
|
|
|
BRect Margin() const;
|
|
|
|
|
|
|
|
// units
|
|
|
|
MarginUnit Unit() const;
|
|
|
|
|
|
|
|
// will cause a recalc and redraw
|
|
|
|
void UpdateView(uint32 msg);
|
|
|
|
|
2005-01-22 17:26:52 +03:00
|
|
|
private:
|
2008-07-13 01:09:49 +04:00
|
|
|
// all the GUI construction code
|
|
|
|
void _ConstructGUI();
|
2005-01-22 17:26:52 +03:00
|
|
|
|
2008-07-13 01:09:49 +04:00
|
|
|
// utility method
|
|
|
|
void _AllowOnlyNumbers(BTextControl *textControl,
|
|
|
|
int32 maxNum);
|
2005-01-22 17:26:52 +03:00
|
|
|
|
2008-07-13 01:09:49 +04:00
|
|
|
// performed internally using text fields
|
|
|
|
void _SetMargin(BRect margin);
|
2005-01-22 17:26:52 +03:00
|
|
|
|
2008-07-13 01:09:49 +04:00
|
|
|
// performed internally using the supplied popup
|
|
|
|
void _SetMarginUnit(MarginUnit unit);
|
2005-01-22 17:26:52 +03:00
|
|
|
|
2008-07-13 01:09:49 +04:00
|
|
|
private:
|
|
|
|
BTextControl* fTop;
|
|
|
|
BTextControl* fBottom;
|
|
|
|
BTextControl* fLeft;
|
|
|
|
BTextControl* fRight;
|
2005-01-22 17:26:52 +03:00
|
|
|
|
2008-07-13 01:09:49 +04:00
|
|
|
// the actual size of the page in points
|
|
|
|
float fPageHeight;
|
|
|
|
float fPageWidth;
|
2005-01-22 17:26:52 +03:00
|
|
|
|
2010-10-16 23:56:34 +04:00
|
|
|
// rect that holds the margins for the page as a set of point offsets
|
|
|
|
BRect fMargins;
|
|
|
|
|
2008-07-13 01:09:49 +04:00
|
|
|
// the units used to calculate the page size
|
|
|
|
MarginUnit fMarginUnit;
|
|
|
|
float fUnitValue;
|
2005-01-22 17:26:52 +03:00
|
|
|
|
2010-10-16 23:56:34 +04:00
|
|
|
PageView* fPage;
|
|
|
|
BStringView* fPageSize;
|
2005-01-22 17:26:52 +03:00
|
|
|
};
|
|
|
|
|
2007-01-20 18:52:37 +03:00
|
|
|
#endif // _MARGIN_VIEW_H
|