* reordered MarinView.h, MarginView.cpp
* rename private functions to use underscore * rename some public functions to match the usual style * adjust pdf/ preview driver to use the renamed functions * we where leaking a single message in _ConstructGui, otherwise no functional change git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@26396 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -4,9 +4,9 @@ MarginView.h
|
|||||||
|
|
||||||
Copyright (c) 2002 OpenBeOS.
|
Copyright (c) 2002 OpenBeOS.
|
||||||
|
|
||||||
Authors:
|
Authors:
|
||||||
Philippe Houdoin
|
Philippe Houdoin
|
||||||
Simon Gauvin
|
Simon Gauvin
|
||||||
Michael Pfeiffer
|
Michael Pfeiffer
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
@@ -28,40 +28,40 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|||||||
THE SOFTWARE.
|
THE SOFTWARE.
|
||||||
|
|
||||||
Documentation:
|
Documentation:
|
||||||
|
|
||||||
The MarginView is designed to be a self contained component that manages
|
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'
|
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
|
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.
|
the margin values and a popup to change the units used for the margins.
|
||||||
|
|
||||||
There are two interfaces for the MarginView component:
|
There are two interfaces for the MarginView component:
|
||||||
|
|
||||||
1) Set methods:
|
1) Set methods:
|
||||||
- page size
|
- page size
|
||||||
- orientation
|
- orientation
|
||||||
|
|
||||||
Get methods to retrieve:
|
Get methods to retrieve:
|
||||||
- margins
|
- margins
|
||||||
- page size
|
- page size
|
||||||
|
|
||||||
The method interface is available for the parent Component to call on
|
The method interface is available for the parent Component to call on
|
||||||
the MarginView in response to the Window receiveing messages from
|
the MarginView in response to the Window receiveing messages from
|
||||||
other BControls that it contains, such as a Page Size popup. The
|
other BControls that it contains, such as a Page Size popup. The
|
||||||
Get methods are used to extract the page size and margins so that
|
Get methods are used to extract the page size and margins so that
|
||||||
the printer driver may put these values into a BMessage for printing.
|
the printer driver may put these values into a BMessage for printing.
|
||||||
|
|
||||||
2) 'Optional' Message interface:
|
2) 'Optional' Message interface:
|
||||||
- Set Page Size
|
- Set Page Size
|
||||||
- Flip Orientation
|
- Flip Orientation
|
||||||
|
|
||||||
The message interface is available for GUI Controls, BPopupMenu to send
|
The message interface is available for GUI Controls, BPopupMenu to send
|
||||||
messages to the MarginView if the parent Window is not used to handle
|
messages to the MarginView if the parent Window is not used to handle
|
||||||
the messages.
|
the messages.
|
||||||
|
|
||||||
General Use of MarginView component:
|
General Use of MarginView component:
|
||||||
|
|
||||||
1) Simply construct a new MarginView object with the margins
|
1) Simply construct a new MarginView object with the margins
|
||||||
you want as defaults and add this view to the parent view
|
you want as defaults and add this view to the parent view
|
||||||
of the dialog.
|
of the dialog.
|
||||||
|
|
||||||
MarginView *mv;
|
MarginView *mv;
|
||||||
@@ -69,17 +69,17 @@ THE SOFTWARE.
|
|||||||
parentView->AddChild(mv);
|
parentView->AddChild(mv);
|
||||||
|
|
||||||
* you can also set the margins in the constructor, and the units:
|
* you can also set the margins in the constructor, and the units:
|
||||||
|
|
||||||
mv = new MarginView(viewSizeRect, pageWidth, pageHeight
|
mv = new MarginView(viewSizeRect, pageWidth, pageHeight
|
||||||
marginRect, kUnitPointS);
|
marginRect, kUnitPointS);
|
||||||
|
|
||||||
! but remeber to have the marginRect values match the UNITS :-)
|
! but remeber to have the marginRect values match the UNITS :-)
|
||||||
|
|
||||||
2) Set Page Size with methods:
|
2) Set Page Size with methods:
|
||||||
|
|
||||||
mv-SetPageSize( pageWidth, pageHeight );
|
mv-SetPageSize( pageWidth, pageHeight );
|
||||||
mv->UpdateView();
|
mv->UpdateView();
|
||||||
|
|
||||||
3) Set Page Size with BMessage:
|
3) Set Page Size with BMessage:
|
||||||
|
|
||||||
BMessage* msg = new BMessage(CHANGE_PAGE_SIZE);
|
BMessage* msg = new BMessage(CHANGE_PAGE_SIZE);
|
||||||
@@ -88,12 +88,12 @@ THE SOFTWARE.
|
|||||||
mv->PostMessage(msg);
|
mv->PostMessage(msg);
|
||||||
|
|
||||||
4) Flip Page with methods:
|
4) Flip Page with methods:
|
||||||
|
|
||||||
mv-SetPageSize( pageHeight, pageWidth );
|
mv-SetPageSize( pageHeight, pageWidth );
|
||||||
mv->UpdateView();
|
mv->UpdateView();
|
||||||
|
|
||||||
5) Flip Page with BMessage:
|
5) Flip Page with BMessage:
|
||||||
|
|
||||||
BMessage* msg = new BMessage(FLIP_PAGE);
|
BMessage* msg = new BMessage(FLIP_PAGE);
|
||||||
mv->Looper()->PostMessage(msg);
|
mv->Looper()->PostMessage(msg);
|
||||||
|
|
||||||
@@ -103,16 +103,16 @@ THE SOFTWARE.
|
|||||||
6) Get Page Size
|
6) Get Page Size
|
||||||
|
|
||||||
BPoint pageSize = mv->GetPageSize();
|
BPoint pageSize = mv->GetPageSize();
|
||||||
|
|
||||||
7) Get Margins
|
7) Get Margins
|
||||||
|
|
||||||
BRect margins = mv->GetMargins();
|
BRect margins = mv->GetMargins();
|
||||||
|
|
||||||
8) Get Units
|
8) Get Units
|
||||||
|
|
||||||
uint32 units = mv->GetUnits();
|
uint32 units = mv->GetUnits();
|
||||||
|
|
||||||
where units is one of:
|
where units is one of:
|
||||||
kUnitInch, 72 points/in
|
kUnitInch, 72 points/in
|
||||||
kUnitCM, 28.346 points/cm
|
kUnitCM, 28.346 points/cm
|
||||||
kUnitPoint, 1 point/point
|
kUnitPoint, 1 point/point
|
||||||
@@ -124,6 +124,7 @@ THE SOFTWARE.
|
|||||||
#include <InterfaceKit.h>
|
#include <InterfaceKit.h>
|
||||||
#include <Looper.h>
|
#include <Looper.h>
|
||||||
|
|
||||||
|
class BTextControl;
|
||||||
class MarginManager;
|
class MarginManager;
|
||||||
|
|
||||||
// Messages that the MarginManager accepts
|
// Messages that the MarginManager accepts
|
||||||
@@ -145,81 +146,77 @@ enum MarginUnit {
|
|||||||
/**
|
/**
|
||||||
* Class MarginView
|
* Class MarginView
|
||||||
*/
|
*/
|
||||||
class MarginView : public BBox
|
class MarginView : public BBox
|
||||||
{
|
{
|
||||||
friend class MarginManager;
|
friend class MarginManager;
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
// GUI components
|
|
||||||
BTextControl *fTop, *fBottom, *fLeft, *fRight;
|
|
||||||
|
|
||||||
// rect that holds the margins for the page as a set of point offsets
|
|
||||||
BRect fMargins;
|
|
||||||
|
|
||||||
// the maximum size of the page view calculated from the view size
|
|
||||||
float fMaxPageWidth;
|
|
||||||
float fMaxPageHeight;
|
|
||||||
|
|
||||||
// the actual size of the page in points
|
|
||||||
float fPageHeight;
|
|
||||||
float fPageWidth;
|
|
||||||
|
|
||||||
// the units used to calculate the page size
|
|
||||||
MarginUnit fMarginUnit;
|
|
||||||
float fUnitValue;
|
|
||||||
|
|
||||||
// the size of the drawing area we have to draw the view in pixels
|
|
||||||
float fViewHeight;
|
|
||||||
float fViewWidth;
|
|
||||||
|
|
||||||
// Calculate the view size for the margins
|
|
||||||
void CalculateViewSize(uint32 msg);
|
|
||||||
|
|
||||||
// performed internally using the supplied popup
|
|
||||||
void SetMarginUnit(MarginUnit unit);
|
|
||||||
|
|
||||||
// performed internally using text fields
|
|
||||||
void SetMargin(BRect margin);
|
|
||||||
|
|
||||||
// utility method
|
|
||||||
void AllowOnlyNumbers(BTextControl *textControl, int maxNum);
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MarginView(BRect rect,
|
MarginView(BRect rect, int32 pageWidth = 0,
|
||||||
int32 pageWidth = 0,
|
int32 pageHeight = 0,
|
||||||
int32 pageHeight = 0,
|
BRect margins = BRect(1, 1, 1, 1), // 1 inch
|
||||||
BRect margins = BRect(1, 1, 1, 1), // default to 1 inch
|
MarginUnit unit = kUnitInch);
|
||||||
MarginUnit unit = kUnitInch);
|
|
||||||
|
|
||||||
~MarginView();
|
virtual ~MarginView();
|
||||||
|
|
||||||
/// all the GUI construction code
|
virtual void AttachedToWindow();
|
||||||
void ConstructGUI();
|
virtual void Draw(BRect rect);
|
||||||
|
virtual void FrameResized(float width, float height);
|
||||||
// page size
|
virtual void MessageReceived(BMessage *msg);
|
||||||
void SetPageSize(float pageWidth, float pageHeight);
|
|
||||||
// point.x = width, point.y = height
|
|
||||||
BPoint GetPageSize(void);
|
|
||||||
|
|
||||||
// margin
|
// point.x = width, point.y = height
|
||||||
BRect GetMargin(void);
|
BPoint PageSize() const;
|
||||||
|
void SetPageSize(float pageWidth, float pageHeight);
|
||||||
|
|
||||||
// orientation
|
// margin
|
||||||
// None, this state should be saved elsewhere in the page setup code
|
BRect Margin() const;
|
||||||
// and not here. See the FLIP_PAGE message to perform this function.
|
|
||||||
|
|
||||||
// units
|
|
||||||
MarginUnit GetMarginUnit(void);
|
|
||||||
|
|
||||||
// will cause a recalc and redraw
|
// units
|
||||||
void UpdateView(uint32 msg);
|
MarginUnit Unit() const;
|
||||||
|
|
||||||
// BeOS Hook methods
|
// will cause a recalc and redraw
|
||||||
virtual void AttachedToWindow(void);
|
void UpdateView(uint32 msg);
|
||||||
void Draw(BRect rect);
|
|
||||||
void FrameResized(float width, float height);
|
private:
|
||||||
void MessageReceived(BMessage *msg);
|
// all the GUI construction code
|
||||||
|
void _ConstructGUI();
|
||||||
|
|
||||||
|
// utility method
|
||||||
|
void _AllowOnlyNumbers(BTextControl *textControl,
|
||||||
|
int32 maxNum);
|
||||||
|
|
||||||
|
// performed internally using text fields
|
||||||
|
void _SetMargin(BRect margin);
|
||||||
|
|
||||||
|
// performed internally using the supplied popup
|
||||||
|
void _SetMarginUnit(MarginUnit unit);
|
||||||
|
|
||||||
|
// Calculate the view size for the margins
|
||||||
|
void _CalculateViewSize(uint32 msg);
|
||||||
|
|
||||||
|
private:
|
||||||
|
BTextControl* fTop;
|
||||||
|
BTextControl* fBottom;
|
||||||
|
BTextControl* fLeft;
|
||||||
|
BTextControl* fRight;
|
||||||
|
|
||||||
|
// rect that holds the margins for the page as a set of point offsets
|
||||||
|
BRect fMargins;
|
||||||
|
|
||||||
|
// the maximum size of the page view calculated from the view size
|
||||||
|
float fMaxPageWidth;
|
||||||
|
float fMaxPageHeight;
|
||||||
|
|
||||||
|
// the actual size of the page in points
|
||||||
|
float fPageHeight;
|
||||||
|
float fPageWidth;
|
||||||
|
|
||||||
|
// the units used to calculate the page size
|
||||||
|
MarginUnit fMarginUnit;
|
||||||
|
float fUnitValue;
|
||||||
|
|
||||||
|
// the size of the drawing area we have to draw the view in pixels
|
||||||
|
float fViewHeight;
|
||||||
|
float fViewWidth;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // _MARGIN_VIEW_H
|
#endif // _MARGIN_VIEW_H
|
||||||
|
|||||||
@@ -4,11 +4,11 @@ PDF Writer printer driver.
|
|||||||
|
|
||||||
Version: 12.19.2000
|
Version: 12.19.2000
|
||||||
|
|
||||||
Copyright (c) 2001 OpenBeOS.
|
Copyright (c) 2001 OpenBeOS.
|
||||||
|
|
||||||
Authors:
|
Authors:
|
||||||
Philippe Houdoin
|
Philippe Houdoin
|
||||||
Simon Gauvin
|
Simon Gauvin
|
||||||
Michael Pfeiffer
|
Michael Pfeiffer
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
@@ -33,7 +33,7 @@ THE SOFTWARE.
|
|||||||
|
|
||||||
#include <InterfaceKit.h>
|
#include <InterfaceKit.h>
|
||||||
#include <SupportKit.h>
|
#include <SupportKit.h>
|
||||||
#include "pdflib.h" // for pageFormat constants
|
#include "pdflib.h" // for pageFormat constants
|
||||||
#include "PrinterDriver.h"
|
#include "PrinterDriver.h"
|
||||||
#include "PageSetupWindow.h"
|
#include "PageSetupWindow.h"
|
||||||
|
|
||||||
@@ -42,12 +42,12 @@ THE SOFTWARE.
|
|||||||
#include "AdvancedSettingsWindow.h"
|
#include "AdvancedSettingsWindow.h"
|
||||||
|
|
||||||
// static global variables
|
// static global variables
|
||||||
static struct
|
static struct
|
||||||
{
|
{
|
||||||
char *label;
|
char *label;
|
||||||
float width;
|
float width;
|
||||||
float height;
|
float height;
|
||||||
} pageFormat[] =
|
} pageFormat[] =
|
||||||
{
|
{
|
||||||
{"Letter", letter_width, letter_height },
|
{"Letter", letter_width, letter_height },
|
||||||
{"Legal", legal_width, legal_height },
|
{"Legal", legal_width, legal_height },
|
||||||
@@ -65,11 +65,11 @@ static struct
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
static struct
|
static struct
|
||||||
{
|
{
|
||||||
char *label;
|
char *label;
|
||||||
int32 orientation;
|
int32 orientation;
|
||||||
} orientation[] =
|
} orientation[] =
|
||||||
{
|
{
|
||||||
{"Portrait", PrinterDriver::PORTRAIT_ORIENTATION},
|
{"Portrait", PrinterDriver::PORTRAIT_ORIENTATION},
|
||||||
{"Landscape", PrinterDriver::LANDSCAPE_ORIENTATION},
|
{"Landscape", PrinterDriver::LANDSCAPE_ORIENTATION},
|
||||||
@@ -82,7 +82,7 @@ static const char *pdf_compatibility[] = {"1.3", "1.4", NULL};
|
|||||||
/**
|
/**
|
||||||
* Constuctor
|
* Constuctor
|
||||||
*
|
*
|
||||||
* @param
|
* @param
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
PageSetupWindow::PageSetupWindow(BMessage *msg, const char *printerName)
|
PageSetupWindow::PageSetupWindow(BMessage *msg, const char *printerName)
|
||||||
@@ -94,10 +94,10 @@ PageSetupWindow::PageSetupWindow(BMessage *msg, const char *printerName)
|
|||||||
fExitSem = create_sem(0, "PageSetup");
|
fExitSem = create_sem(0, "PageSetup");
|
||||||
fResult = B_ERROR;
|
fResult = B_ERROR;
|
||||||
fAdvancedSettings = *msg;
|
fAdvancedSettings = *msg;
|
||||||
|
|
||||||
if ( printerName ) {
|
if ( printerName ) {
|
||||||
BString title;
|
BString title;
|
||||||
|
|
||||||
title << printerName << " Page Setup";
|
title << printerName << " Page Setup";
|
||||||
SetTitle( title.String() );
|
SetTitle( title.String() );
|
||||||
|
|
||||||
@@ -122,23 +122,23 @@ PageSetupWindow::PageSetupWindow(BMessage *msg, const char *printerName)
|
|||||||
|
|
||||||
// load orientation
|
// load orientation
|
||||||
fSetupMsg->FindInt32("orientation", &orient);
|
fSetupMsg->FindInt32("orientation", &orient);
|
||||||
// (new BAlert("", "orientation not in msg", "Shit"))->Go();
|
// (new BAlert("", "orientation not in msg", "Shit"))->Go();
|
||||||
|
|
||||||
// load page rect
|
// load page rect
|
||||||
fSetupMsg->FindRect("paper_rect", &r);
|
fSetupMsg->FindRect("paper_rect", &r);
|
||||||
width = r.Width();
|
width = r.Width();
|
||||||
height = r.Height();
|
height = r.Height();
|
||||||
page = r;
|
page = r;
|
||||||
|
|
||||||
// Load compression
|
// Load compression
|
||||||
fSetupMsg->FindInt32("pdf_compression", &compression);
|
fSetupMsg->FindInt32("pdf_compression", &compression);
|
||||||
|
|
||||||
// Load units
|
// Load units
|
||||||
fSetupMsg->FindInt32("units", &units);
|
fSetupMsg->FindInt32("units", &units);
|
||||||
|
|
||||||
// Load printable rect
|
// Load printable rect
|
||||||
fSetupMsg->FindRect("printable_rect", &margin);
|
fSetupMsg->FindRect("printable_rect", &margin);
|
||||||
|
|
||||||
// Load pdf compatability
|
// Load pdf compatability
|
||||||
fSetupMsg->FindString("pdf_compatibility", &setting_value);
|
fSetupMsg->FindString("pdf_compatibility", &setting_value);
|
||||||
|
|
||||||
@@ -149,15 +149,15 @@ PageSetupWindow::PageSetupWindow(BMessage *msg, const char *printerName)
|
|||||||
if (fSetupMsg->FindMessage("fonts", &fonts) == B_OK) {
|
if (fSetupMsg->FindMessage("fonts", &fonts) == B_OK) {
|
||||||
fFonts->SetTo(&fonts);
|
fFonts->SetTo(&fonts);
|
||||||
}
|
}
|
||||||
|
|
||||||
// add a *dialog* background
|
// add a *dialog* background
|
||||||
r = Bounds();
|
r = Bounds();
|
||||||
panel = new BBox(r, "top_panel", B_FOLLOW_ALL,
|
panel = new BBox(r, "top_panel", B_FOLLOW_ALL,
|
||||||
B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE_JUMP,
|
B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE_JUMP,
|
||||||
B_PLAIN_BORDER);
|
B_PLAIN_BORDER);
|
||||||
|
|
||||||
////////////// Create the margin view //////////////////////
|
////////////// Create the margin view //////////////////////
|
||||||
|
|
||||||
// re-calculate the margin from the printable rect in points
|
// re-calculate the margin from the printable rect in points
|
||||||
margin.top -= page.top;
|
margin.top -= page.top;
|
||||||
margin.left -= page.left;
|
margin.left -= page.left;
|
||||||
@@ -167,7 +167,7 @@ PageSetupWindow::PageSetupWindow(BMessage *msg, const char *printerName)
|
|||||||
fMarginView = new MarginView(BRect(20,20,200,160), (int32)width, (int32)height,
|
fMarginView = new MarginView(BRect(20,20,200,160), (int32)width, (int32)height,
|
||||||
margin, (MarginUnit)units);
|
margin, (MarginUnit)units);
|
||||||
panel->AddChild(fMarginView);
|
panel->AddChild(fMarginView);
|
||||||
|
|
||||||
// add page format menu
|
// add page format menu
|
||||||
// Simon Changed to OFFSET popups
|
// Simon Changed to OFFSET popups
|
||||||
x = r.left + kMargin * 2 + kOffset; y = r.top + kMargin * 2;
|
x = r.left + kMargin * 2 + kOffset; y = r.top + kMargin * 2;
|
||||||
@@ -176,7 +176,7 @@ PageSetupWindow::PageSetupWindow(BMessage *msg, const char *printerName)
|
|||||||
m->SetRadioMode(true);
|
m->SetRadioMode(true);
|
||||||
|
|
||||||
// Simon changed width 200->140
|
// Simon changed width 200->140
|
||||||
BMenuField *mf = new BMenuField(BRect(x, y, x + 140, y + 20), "page_size",
|
BMenuField *mf = new BMenuField(BRect(x, y, x + 140, y + 20), "page_size",
|
||||||
"Page Size:", m);
|
"Page Size:", m);
|
||||||
fPageSizeMenu = mf;
|
fPageSizeMenu = mf;
|
||||||
mf->ResizeToPreferred();
|
mf->ResizeToPreferred();
|
||||||
@@ -188,19 +188,19 @@ PageSetupWindow::PageSetupWindow(BMessage *msg, const char *printerName)
|
|||||||
panel->AddChild(mf);
|
panel->AddChild(mf);
|
||||||
|
|
||||||
item = NULL;
|
item = NULL;
|
||||||
for (i = 0; pageFormat[i].label != NULL; i++)
|
for (i = 0; pageFormat[i].label != NULL; i++)
|
||||||
{
|
{
|
||||||
BMessage* msg = new BMessage('pgsz');
|
BMessage* msg = new BMessage('pgsz');
|
||||||
msg->AddFloat("width", pageFormat[i].width);
|
msg->AddFloat("width", pageFormat[i].width);
|
||||||
msg->AddFloat("height", pageFormat[i].height);
|
msg->AddFloat("height", pageFormat[i].height);
|
||||||
BMenuItem* mi = new BMenuItem(pageFormat[i].label, msg);
|
BMenuItem* mi = new BMenuItem(pageFormat[i].label, msg);
|
||||||
m->AddItem(mi);
|
m->AddItem(mi);
|
||||||
|
|
||||||
if (width == pageFormat[i].width && height == pageFormat[i].height) {
|
if (width == pageFormat[i].width && height == pageFormat[i].height) {
|
||||||
item = mi;
|
item = mi;
|
||||||
}
|
}
|
||||||
if (height == pageFormat[i].width && width == pageFormat[i].height) {
|
if (height == pageFormat[i].width && width == pageFormat[i].height) {
|
||||||
item = mi;
|
item = mi;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mf->Menu()->SetLabelFromMarked(true);
|
mf->Menu()->SetLabelFromMarked(true);
|
||||||
@@ -212,28 +212,28 @@ PageSetupWindow::PageSetupWindow(BMessage *msg, const char *printerName)
|
|||||||
|
|
||||||
// add orientation menu
|
// add orientation menu
|
||||||
y += h + kMargin;
|
y += h + kMargin;
|
||||||
|
|
||||||
m = new BPopUpMenu("orientation");
|
m = new BPopUpMenu("orientation");
|
||||||
m->SetRadioMode(true);
|
m->SetRadioMode(true);
|
||||||
|
|
||||||
// Simon changed 200->140
|
// Simon changed 200->140
|
||||||
mf = new BMenuField(BRect(x, y, x + 140, y + 20), "orientation", "Orientation:", m);
|
mf = new BMenuField(BRect(x, y, x + 140, y + 20), "orientation", "Orientation:", m);
|
||||||
|
|
||||||
// Simon added: SetDivider
|
// Simon added: SetDivider
|
||||||
mf->SetDivider(be_plain_font->StringWidth("Orientation#"));
|
mf->SetDivider(be_plain_font->StringWidth("Orientation#"));
|
||||||
|
|
||||||
fOrientationMenu = mf;
|
fOrientationMenu = mf;
|
||||||
mf->ResizeToPreferred();
|
mf->ResizeToPreferred();
|
||||||
panel->AddChild(mf);
|
panel->AddChild(mf);
|
||||||
r.top += h;
|
r.top += h;
|
||||||
item = NULL;
|
item = NULL;
|
||||||
for (int i = 0; orientation[i].label != NULL; i++)
|
for (int i = 0; orientation[i].label != NULL; i++)
|
||||||
{
|
{
|
||||||
BMessage* msg = new BMessage('ornt');
|
BMessage* msg = new BMessage('ornt');
|
||||||
msg->AddInt32("orientation", orientation[i].orientation);
|
msg->AddInt32("orientation", orientation[i].orientation);
|
||||||
BMenuItem* mi = new BMenuItem(orientation[i].label, msg);
|
BMenuItem* mi = new BMenuItem(orientation[i].label, msg);
|
||||||
m->AddItem(mi);
|
m->AddItem(mi);
|
||||||
|
|
||||||
if (orient == orientation[i].orientation) {
|
if (orient == orientation[i].orientation) {
|
||||||
item = mi;
|
item = mi;
|
||||||
}
|
}
|
||||||
@@ -249,7 +249,7 @@ PageSetupWindow::PageSetupWindow(BMessage *msg, const char *printerName)
|
|||||||
|
|
||||||
// add PDF comptibility menu
|
// add PDF comptibility menu
|
||||||
y += h + kMargin;
|
y += h + kMargin;
|
||||||
|
|
||||||
m = new BPopUpMenu("pdf_compatibility");
|
m = new BPopUpMenu("pdf_compatibility");
|
||||||
m->SetRadioMode(true);
|
m->SetRadioMode(true);
|
||||||
mf = new BMenuField(BRect(x, y, x + 200, y + 20), "pdf_compatibility", "PDF Compatibility:", m);
|
mf = new BMenuField(BRect(x, y, x + 200, y + 20), "pdf_compatibility", "PDF Compatibility:", m);
|
||||||
@@ -259,12 +259,12 @@ PageSetupWindow::PageSetupWindow(BMessage *msg, const char *printerName)
|
|||||||
r.top += h;
|
r.top += h;
|
||||||
|
|
||||||
item = NULL;
|
item = NULL;
|
||||||
for (int i = 0; pdf_compatibility[i] != NULL; i++)
|
for (int i = 0; pdf_compatibility[i] != NULL; i++)
|
||||||
{
|
{
|
||||||
BMenuItem* mi = new BMenuItem(pdf_compatibility[i], NULL);
|
BMenuItem* mi = new BMenuItem(pdf_compatibility[i], NULL);
|
||||||
m->AddItem(mi);
|
m->AddItem(mi);
|
||||||
|
|
||||||
//(new BAlert("", setting_value.String(), pdf_compatibility[i]))->Go();
|
//(new BAlert("", setting_value.String(), pdf_compatibility[i]))->Go();
|
||||||
if (setting_value == pdf_compatibility[i]) {
|
if (setting_value == pdf_compatibility[i]) {
|
||||||
item = mi;
|
item = mi;
|
||||||
}
|
}
|
||||||
@@ -290,16 +290,16 @@ PageSetupWindow::PageSetupWindow(BMessage *msg, const char *printerName)
|
|||||||
fPDFCompressionSlider = slider;
|
fPDFCompressionSlider = slider;
|
||||||
|
|
||||||
panel->AddChild(slider);
|
panel->AddChild(slider);
|
||||||
|
|
||||||
slider->SetLimitLabels("None", "Best");
|
slider->SetLimitLabels("None", "Best");
|
||||||
slider->SetHashMarks(B_HASH_MARKS_BOTTOM);
|
slider->SetHashMarks(B_HASH_MARKS_BOTTOM);
|
||||||
slider->ResizeToPreferred();
|
slider->ResizeToPreferred();
|
||||||
slider->GetPreferredSize(&w, &h);
|
slider->GetPreferredSize(&w, &h);
|
||||||
|
|
||||||
slider->SetValue(compression);
|
slider->SetValue(compression);
|
||||||
|
|
||||||
// add a "OK" button, and make it default
|
// add a "OK" button, and make it default
|
||||||
button = new BButton(r, NULL, "OK", new BMessage(OK_MSG),
|
button = new BButton(r, NULL, "OK", new BMessage(OK_MSG),
|
||||||
B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM);
|
B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM);
|
||||||
button->ResizeToPreferred();
|
button->ResizeToPreferred();
|
||||||
button->GetPreferredSize(&w, &h);
|
button->GetPreferredSize(&w, &h);
|
||||||
@@ -309,25 +309,25 @@ PageSetupWindow::PageSetupWindow(BMessage *msg, const char *printerName)
|
|||||||
panel->AddChild(button);
|
panel->AddChild(button);
|
||||||
button->MakeDefault(true);
|
button->MakeDefault(true);
|
||||||
|
|
||||||
// add a "Cancel button
|
// add a "Cancel button
|
||||||
button = new BButton(r, NULL, "Cancel", new BMessage(CANCEL_MSG),
|
button = new BButton(r, NULL, "Cancel", new BMessage(CANCEL_MSG),
|
||||||
B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM);
|
B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM);
|
||||||
button->GetPreferredSize(&w, &h);
|
button->GetPreferredSize(&w, &h);
|
||||||
button->ResizeToPreferred();
|
button->ResizeToPreferred();
|
||||||
button->MoveTo(x - w - 8, y);
|
button->MoveTo(x - w - 8, y);
|
||||||
panel->AddChild(button);
|
panel->AddChild(button);
|
||||||
|
|
||||||
// add a "Fonts" button
|
// add a "Fonts" button
|
||||||
button = new BButton(r, NULL, "Fonts" B_UTF8_ELLIPSIS, new BMessage(FONTS_MSG),
|
button = new BButton(r, NULL, "Fonts" B_UTF8_ELLIPSIS, new BMessage(FONTS_MSG),
|
||||||
B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM);
|
B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM);
|
||||||
button->GetPreferredSize(&w, &h);
|
button->GetPreferredSize(&w, &h);
|
||||||
button->ResizeToPreferred();
|
button->ResizeToPreferred();
|
||||||
button->MoveTo(r.left + 8, y);
|
button->MoveTo(r.left + 8, y);
|
||||||
panel->AddChild(button);
|
panel->AddChild(button);
|
||||||
|
|
||||||
// add a "Fonts" button
|
// add a "Fonts" button
|
||||||
BButton* font = button;
|
BButton* font = button;
|
||||||
button = new BButton(r, NULL, "Advanced" B_UTF8_ELLIPSIS, new BMessage(ADVANCED_MSG),
|
button = new BButton(r, NULL, "Advanced" B_UTF8_ELLIPSIS, new BMessage(ADVANCED_MSG),
|
||||||
B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM);
|
B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM);
|
||||||
button->GetPreferredSize(&w, &h);
|
button->GetPreferredSize(&w, &h);
|
||||||
button->ResizeToPreferred();
|
button->ResizeToPreferred();
|
||||||
@@ -353,7 +353,7 @@ PageSetupWindow::~PageSetupWindow()
|
|||||||
|
|
||||||
|
|
||||||
// --------------------------------------------------
|
// --------------------------------------------------
|
||||||
bool
|
bool
|
||||||
PageSetupWindow::QuitRequested()
|
PageSetupWindow::QuitRequested()
|
||||||
{
|
{
|
||||||
release_sem(fExitSem);
|
release_sem(fExitSem);
|
||||||
@@ -362,8 +362,8 @@ PageSetupWindow::QuitRequested()
|
|||||||
|
|
||||||
|
|
||||||
// --------------------------------------------------
|
// --------------------------------------------------
|
||||||
void
|
void
|
||||||
PageSetupWindow::UpdateSetupMessage()
|
PageSetupWindow::UpdateSetupMessage()
|
||||||
{
|
{
|
||||||
BMenuItem *item;
|
BMenuItem *item;
|
||||||
int32 orientation = 0;
|
int32 orientation = 0;
|
||||||
@@ -382,7 +382,7 @@ PageSetupWindow::UpdateSetupMessage()
|
|||||||
else
|
else
|
||||||
fSetupMsg->AddString("pdf_compatibility", item->Label());
|
fSetupMsg->AddString("pdf_compatibility", item->Label());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fSetupMsg->HasInt32("pdf_compression")) {
|
if (fSetupMsg->HasInt32("pdf_compression")) {
|
||||||
fSetupMsg->ReplaceInt32("pdf_compression", fPDFCompressionSlider->Value());
|
fSetupMsg->ReplaceInt32("pdf_compression", fPDFCompressionSlider->Value());
|
||||||
} else {
|
} else {
|
||||||
@@ -396,14 +396,14 @@ PageSetupWindow::UpdateSetupMessage()
|
|||||||
msg->FindFloat("width", &w);
|
msg->FindFloat("width", &w);
|
||||||
msg->FindFloat("height", &h);
|
msg->FindFloat("height", &h);
|
||||||
BRect r;
|
BRect r;
|
||||||
if (orientation == 0)
|
if (orientation == 0)
|
||||||
r.Set(0, 0, w, h);
|
r.Set(0, 0, w, h);
|
||||||
else
|
else
|
||||||
r.Set(0, 0, h, w);
|
r.Set(0, 0, h, w);
|
||||||
fSetupMsg->ReplaceRect("paper_rect", r);
|
fSetupMsg->ReplaceRect("paper_rect", r);
|
||||||
|
|
||||||
// Save the printable_rect
|
// Save the printable_rect
|
||||||
BRect margin = fMarginView->GetMargin();
|
BRect margin = fMarginView->Margin();
|
||||||
if (orientation == 0) {
|
if (orientation == 0) {
|
||||||
margin.right = w - margin.right;
|
margin.right = w - margin.right;
|
||||||
margin.bottom = h - margin.bottom;
|
margin.bottom = h - margin.bottom;
|
||||||
@@ -414,12 +414,12 @@ PageSetupWindow::UpdateSetupMessage()
|
|||||||
fSetupMsg->ReplaceRect("printable_rect", margin);
|
fSetupMsg->ReplaceRect("printable_rect", margin);
|
||||||
|
|
||||||
// save the units used
|
// save the units used
|
||||||
int32 units = fMarginView->GetMarginUnit();
|
int32 units = fMarginView->Unit();
|
||||||
if (fSetupMsg->HasInt32("units")) {
|
if (fSetupMsg->HasInt32("units")) {
|
||||||
fSetupMsg->ReplaceInt32("units", units);
|
fSetupMsg->ReplaceInt32("units", units);
|
||||||
} else {
|
} else {
|
||||||
fSetupMsg->AddInt32("units", units);
|
fSetupMsg->AddInt32("units", units);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BMessage fonts;
|
BMessage fonts;
|
||||||
@@ -436,8 +436,8 @@ PageSetupWindow::UpdateSetupMessage()
|
|||||||
float f;
|
float f;
|
||||||
BString s;
|
BString s;
|
||||||
int32 i;
|
int32 i;
|
||||||
|
|
||||||
|
|
||||||
if (fAdvancedSettings.FindString("pdflib_license_key", &s) == B_OK) {
|
if (fAdvancedSettings.FindString("pdflib_license_key", &s) == B_OK) {
|
||||||
if (fSetupMsg->HasString("pdflib_license_key")) {
|
if (fSetupMsg->HasString("pdflib_license_key")) {
|
||||||
fSetupMsg->ReplaceString("pdflib_license_key", s.String());
|
fSetupMsg->ReplaceString("pdflib_license_key", s.String());
|
||||||
@@ -505,7 +505,7 @@ PageSetupWindow::UpdateSetupMessage()
|
|||||||
|
|
||||||
|
|
||||||
// --------------------------------------------------
|
// --------------------------------------------------
|
||||||
void
|
void
|
||||||
PageSetupWindow::MessageReceived(BMessage *msg)
|
PageSetupWindow::MessageReceived(BMessage *msg)
|
||||||
{
|
{
|
||||||
switch (msg->what){
|
switch (msg->what){
|
||||||
@@ -514,7 +514,7 @@ PageSetupWindow::MessageReceived(BMessage *msg)
|
|||||||
fResult = B_OK;
|
fResult = B_OK;
|
||||||
release_sem(fExitSem);
|
release_sem(fExitSem);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CANCEL_MSG:
|
case CANCEL_MSG:
|
||||||
fResult = B_ERROR;
|
fResult = B_ERROR;
|
||||||
release_sem(fExitSem);
|
release_sem(fExitSem);
|
||||||
@@ -543,12 +543,12 @@ PageSetupWindow::MessageReceived(BMessage *msg)
|
|||||||
|
|
||||||
// Simon added
|
// Simon added
|
||||||
case 'ornt':
|
case 'ornt':
|
||||||
{
|
{
|
||||||
BPoint p = fMarginView->GetPageSize();
|
BPoint p = fMarginView->PageSize();
|
||||||
int32 orientation;
|
int32 orientation;
|
||||||
msg->FindInt32("orientation", &orientation);
|
msg->FindInt32("orientation", &orientation);
|
||||||
if (orientation == PrinterDriver::LANDSCAPE_ORIENTATION
|
if (orientation == PrinterDriver::LANDSCAPE_ORIENTATION
|
||||||
&& p.y > p.x) {
|
&& p.y > p.x) {
|
||||||
fMarginView->SetPageSize(p.y, p.x);
|
fMarginView->SetPageSize(p.y, p.x);
|
||||||
fMarginView->UpdateView(MARGIN_CHANGED);
|
fMarginView->UpdateView(MARGIN_CHANGED);
|
||||||
}
|
}
|
||||||
@@ -563,20 +563,20 @@ PageSetupWindow::MessageReceived(BMessage *msg)
|
|||||||
case FONTS_MSG:
|
case FONTS_MSG:
|
||||||
(new FontsWindow(fFonts))->Show();
|
(new FontsWindow(fFonts))->Show();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ADVANCED_MSG:
|
case ADVANCED_MSG:
|
||||||
(new AdvancedSettingsWindow(&fAdvancedSettings))->Show();
|
(new AdvancedSettingsWindow(&fAdvancedSettings))->Show();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
inherited::MessageReceived(msg);
|
inherited::MessageReceived(msg);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// --------------------------------------------------
|
// --------------------------------------------------
|
||||||
status_t
|
status_t
|
||||||
PageSetupWindow::Go()
|
PageSetupWindow::Go()
|
||||||
{
|
{
|
||||||
MoveTo(300,300);
|
MoveTo(300,300);
|
||||||
|
|||||||
@@ -276,7 +276,7 @@ PageSetupWindow::UpdateSetupMessage()
|
|||||||
AddString(fSetupMsg, "preview:paper_size", item->Label());
|
AddString(fSetupMsg, "preview:paper_size", item->Label());
|
||||||
|
|
||||||
// Save the printable_rect
|
// Save the printable_rect
|
||||||
BRect margin = fMarginView->GetMargin();
|
BRect margin = fMarginView->Margin();
|
||||||
if (fCurrentOrientation == PrinterDriver::PORTRAIT_ORIENTATION) {
|
if (fCurrentOrientation == PrinterDriver::PORTRAIT_ORIENTATION) {
|
||||||
margin.right = w - margin.right;
|
margin.right = w - margin.right;
|
||||||
margin.bottom = h - margin.bottom;
|
margin.bottom = h - margin.bottom;
|
||||||
@@ -287,7 +287,7 @@ PageSetupWindow::UpdateSetupMessage()
|
|||||||
SetRect(fSetupMsg, "preview:printable_rect", margin);
|
SetRect(fSetupMsg, "preview:printable_rect", margin);
|
||||||
SetRect(fSetupMsg, "printable_rect", ScaleRect(margin, scaleR));
|
SetRect(fSetupMsg, "printable_rect", ScaleRect(margin, scaleR));
|
||||||
|
|
||||||
SetInt32(fSetupMsg, "units", fMarginView->GetMarginUnit());
|
SetInt32(fSetupMsg, "units", fMarginView->Unit());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -323,7 +323,7 @@ PageSetupWindow::MessageReceived(BMessage *msg)
|
|||||||
|
|
||||||
if (fCurrentOrientation != orientation) {
|
if (fCurrentOrientation != orientation) {
|
||||||
fCurrentOrientation = orientation;
|
fCurrentOrientation = orientation;
|
||||||
BPoint p = fMarginView->GetPageSize();
|
BPoint p = fMarginView->PageSize();
|
||||||
fMarginView->SetPageSize(p.y, p.x);
|
fMarginView->SetPageSize(p.y, p.x);
|
||||||
fMarginView->UpdateView(MARGIN_CHANGED);
|
fMarginView->UpdateView(MARGIN_CHANGED);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,11 +2,11 @@
|
|||||||
* PageSetupDlg.cpp
|
* PageSetupDlg.cpp
|
||||||
* Copyright 1999-2000 Y.Takagi. All Rights Reserved.
|
* Copyright 1999-2000 Y.Takagi. All Rights Reserved.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
|
||||||
@@ -40,7 +40,7 @@
|
|||||||
|
|
||||||
#if (!__MWERKS__ || defined(MSIPL_USING_NAMESPACE))
|
#if (!__MWERKS__ || defined(MSIPL_USING_NAMESPACE))
|
||||||
using namespace std;
|
using namespace std;
|
||||||
#else
|
#else
|
||||||
#define std
|
#define std
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -159,7 +159,7 @@ PageSetupView::AddOrientationItem(const char* name, JobData::Orientation orienta
|
|||||||
BMessage *msg = new BMessage(kMsgOrientationChanged);
|
BMessage *msg = new BMessage(kMsgOrientationChanged);
|
||||||
msg->AddInt32("orientation", orientation);
|
msg->AddInt32("orientation", orientation);
|
||||||
BMenuItem *item = new BMenuItem(name, msg);
|
BMenuItem *item = new BMenuItem(name, msg);
|
||||||
|
|
||||||
fOrientation->AddItem(item);
|
fOrientation->AddItem(item);
|
||||||
item->SetTarget(this);
|
item->SetTarget(this);
|
||||||
if (fJobData->getOrientation() == orientation) {
|
if (fJobData->getOrientation() == orientation) {
|
||||||
@@ -169,7 +169,7 @@ PageSetupView::AddOrientationItem(const char* name, JobData::Orientation orienta
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
PageSetupView::AttachedToWindow()
|
PageSetupView::AttachedToWindow()
|
||||||
{
|
{
|
||||||
BMenuItem *item = NULL;
|
BMenuItem *item = NULL;
|
||||||
@@ -189,8 +189,8 @@ PageSetupView::AttachedToWindow()
|
|||||||
margin.right = paper.right - margin.right;
|
margin.right = paper.right - margin.right;
|
||||||
margin.bottom = paper.bottom - margin.bottom;
|
margin.bottom = paper.bottom - margin.bottom;
|
||||||
|
|
||||||
fMarginView = new MarginView(MARGIN_RECT,
|
fMarginView = new MarginView(MARGIN_RECT,
|
||||||
paper.IntegerWidth(),
|
paper.IntegerWidth(),
|
||||||
paper.IntegerHeight(),
|
paper.IntegerHeight(),
|
||||||
margin, units);
|
margin, units);
|
||||||
AddChild(fMarginView);
|
AddChild(fMarginView);
|
||||||
@@ -224,10 +224,10 @@ PageSetupView::AttachedToWindow()
|
|||||||
/* orientaion */
|
/* orientaion */
|
||||||
fOrientation = new BPopUpMenu("orientation");
|
fOrientation = new BPopUpMenu("orientation");
|
||||||
fOrientation->SetRadioMode(true);
|
fOrientation->SetRadioMode(true);
|
||||||
|
|
||||||
menuField = new BMenuField(ORIENTATION_RECT, "orientation", ORIENTATION_TEXT, fOrientation);
|
menuField = new BMenuField(ORIENTATION_RECT, "orientation", ORIENTATION_TEXT, fOrientation);
|
||||||
menuField->SetDivider(width);
|
menuField->SetDivider(width);
|
||||||
|
|
||||||
count = fPrinterCap->countCap(PrinterCap::kOrientation);
|
count = fPrinterCap->countCap(PrinterCap::kOrientation);
|
||||||
if (count == 0) {
|
if (count == 0) {
|
||||||
AddOrientationItem(PORTRAIT_TEXT, JobData::kPortrait);
|
AddOrientationItem(PORTRAIT_TEXT, JobData::kPortrait);
|
||||||
@@ -240,7 +240,7 @@ PageSetupView::AttachedToWindow()
|
|||||||
orientation_cap++;
|
orientation_cap++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
AddChild(menuField);
|
AddChild(menuField);
|
||||||
|
|
||||||
/* resolution */
|
/* resolution */
|
||||||
@@ -269,7 +269,7 @@ PageSetupView::AttachedToWindow()
|
|||||||
/* scale */
|
/* scale */
|
||||||
BString scale;
|
BString scale;
|
||||||
scale << (int)fJobData->getScaling();
|
scale << (int)fJobData->getScaling();
|
||||||
fScaling = new BTextControl(SCALE_RECT, "scale", "Scale [%]:",
|
fScaling = new BTextControl(SCALE_RECT, "scale", "Scale [%]:",
|
||||||
scale.String(),
|
scale.String(),
|
||||||
NULL, B_FOLLOW_RIGHT);
|
NULL, B_FOLLOW_RIGHT);
|
||||||
int num;
|
int num;
|
||||||
@@ -282,7 +282,7 @@ PageSetupView::AttachedToWindow()
|
|||||||
fScaling->TextView()->SetMaxBytes(3);
|
fScaling->TextView()->SetMaxBytes(3);
|
||||||
fScaling->SetDivider(width);
|
fScaling->SetDivider(width);
|
||||||
|
|
||||||
AddChild(fScaling);
|
AddChild(fScaling);
|
||||||
|
|
||||||
/* cancel */
|
/* cancel */
|
||||||
|
|
||||||
@@ -296,7 +296,7 @@ PageSetupView::AttachedToWindow()
|
|||||||
button->MakeDefault(true);
|
button->MakeDefault(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void
|
inline void
|
||||||
swap(float *e1, float *e2)
|
swap(float *e1, float *e2)
|
||||||
{
|
{
|
||||||
float e = *e1;
|
float e = *e1;
|
||||||
@@ -304,7 +304,7 @@ swap(float *e1, float *e2)
|
|||||||
*e2 = e;
|
*e2 = e;
|
||||||
}
|
}
|
||||||
|
|
||||||
JobData::Orientation
|
JobData::Orientation
|
||||||
PageSetupView::GetOrientation()
|
PageSetupView::GetOrientation()
|
||||||
{
|
{
|
||||||
BMenuItem *item = fOrientation->FindMarked();
|
BMenuItem *item = fOrientation->FindMarked();
|
||||||
@@ -330,12 +330,12 @@ PageSetupView::GetPaperCap()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
PageSetupView::UpdateJobData()
|
PageSetupView::UpdateJobData()
|
||||||
{
|
{
|
||||||
fJobData->setOrientation(GetOrientation());
|
fJobData->setOrientation(GetOrientation());
|
||||||
|
|
||||||
PaperCap *paperCap = GetPaperCap();
|
PaperCap *paperCap = GetPaperCap();
|
||||||
BRect paper_rect = paperCap->paper_rect;
|
BRect paper_rect = paperCap->paper_rect;
|
||||||
BRect physical_rect = paperCap->physical_rect;
|
BRect physical_rect = paperCap->physical_rect;
|
||||||
fJobData->setPaper(paperCap->paper);
|
fJobData->setPaper(paperCap->paper);
|
||||||
@@ -363,8 +363,8 @@ PageSetupView::UpdateJobData()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// adjust printable rect by margin
|
// adjust printable rect by margin
|
||||||
fJobData->setMarginUnit(fMarginView->GetMarginUnit());
|
fJobData->setMarginUnit(fMarginView->Unit());
|
||||||
BRect margin = fMarginView->GetMargin();
|
BRect margin = fMarginView->Margin();
|
||||||
BRect printable_rect;
|
BRect printable_rect;
|
||||||
printable_rect.left = paper_rect.left + margin.left;
|
printable_rect.left = paper_rect.left + margin.left;
|
||||||
printable_rect.top = paper_rect.top + margin.top;
|
printable_rect.top = paper_rect.top + margin.top;
|
||||||
@@ -392,13 +392,13 @@ PageSetupView::UpdateJobData()
|
|||||||
fJobData->setPrintableRect(printable_rect);
|
fJobData->setPrintableRect(printable_rect);
|
||||||
fJobData->setScaledPrintableRect(ScaleRect(printable_rect, scalingR));
|
fJobData->setScaledPrintableRect(ScaleRect(printable_rect, scalingR));
|
||||||
fJobData->setPhysicalRect(physical_rect);
|
fJobData->setPhysicalRect(physical_rect);
|
||||||
fJobData->setScaledPhysicalRect(ScaleRect(physical_rect, scalingR));
|
fJobData->setScaledPhysicalRect(ScaleRect(physical_rect, scalingR));
|
||||||
|
|
||||||
fJobData->save();
|
fJobData->save();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
PageSetupView::MessageReceived(BMessage *msg)
|
PageSetupView::MessageReceived(BMessage *msg)
|
||||||
{
|
{
|
||||||
switch (msg->what) {
|
switch (msg->what) {
|
||||||
@@ -414,7 +414,7 @@ PageSetupView::MessageReceived(BMessage *msg)
|
|||||||
}
|
}
|
||||||
fMarginView->SetPageSize(width, height);
|
fMarginView->SetPageSize(width, height);
|
||||||
fMarginView->UpdateView(MARGIN_CHANGED);
|
fMarginView->UpdateView(MARGIN_CHANGED);
|
||||||
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -431,11 +431,11 @@ PageSetupDlg::PageSetupDlg(JobData *job_data, PrinterData *printer_data, const P
|
|||||||
|
|
||||||
PageSetupView *view = new PageSetupView(Bounds(), job_data, printer_data, printer_cap);
|
PageSetupView *view = new PageSetupView(Bounds(), job_data, printer_data, printer_cap);
|
||||||
AddChild(view);
|
AddChild(view);
|
||||||
|
|
||||||
SetResult(B_ERROR);
|
SetResult(B_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
PageSetupDlg::MessageReceived(BMessage *msg)
|
PageSetupDlg::MessageReceived(BMessage *msg)
|
||||||
{
|
{
|
||||||
switch (msg->what) {
|
switch (msg->what) {
|
||||||
|
|||||||
@@ -4,9 +4,9 @@ MarginView.cpp
|
|||||||
|
|
||||||
Copyright (c) 2002 OpenBeOS.
|
Copyright (c) 2002 OpenBeOS.
|
||||||
|
|
||||||
Authors:
|
Authors:
|
||||||
Philippe Houdoin
|
Philippe Houdoin
|
||||||
Simon Gauvin
|
Simon Gauvin
|
||||||
Michael Pfeiffer
|
Michael Pfeiffer
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
@@ -30,17 +30,21 @@ THE SOFTWARE.
|
|||||||
Todo:
|
Todo:
|
||||||
|
|
||||||
2 Make Strings constants or UI resources
|
2 Make Strings constants or UI resources
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "MarginView.h"
|
#include "MarginView.h"
|
||||||
|
|
||||||
|
|
||||||
#include <AppKit.h>
|
#include <AppKit.h>
|
||||||
#include <SupportKit.h>
|
#include <SupportKit.h>
|
||||||
|
#include <TextControl.h>
|
||||||
|
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
|
||||||
/*----------------- MarginView Private Constants --------------------*/
|
/*----------------- MarginView Private Constants --------------------*/
|
||||||
|
|
||||||
const int kOffsetY = 20;
|
const int kOffsetY = 20;
|
||||||
@@ -49,18 +53,16 @@ const int kStringSize = 50;
|
|||||||
const int kWidth = 50;
|
const int kWidth = 50;
|
||||||
const int kNumCount = 10;
|
const int kNumCount = 10;
|
||||||
|
|
||||||
const static float kPointUnits = 1; // 1 point = 1 point
|
const static float kPointUnits = 1; // 1 point = 1 point
|
||||||
const static float kInchUnits = 72; // 1" = 72 points
|
const static float kInchUnits = 72; // 1" = 72 points
|
||||||
const static float kCMUnits = 28.346; // 72/2.54 1cm = 28.346 points
|
const static float kCMUnits = 28.346; // 72/2.54 1cm = 28.346 points
|
||||||
|
|
||||||
const static float kMinFieldWidth = 100; // pixels
|
const static float kMinFieldWidth = 100; // pixels
|
||||||
const static float kMinUnitHeight = 30; // pixels
|
const static float kMinUnitHeight = 30; // pixels
|
||||||
|
|
||||||
const static float kUnitFormat[] = { kInchUnits, kCMUnits, kPointUnits };
|
const static float kUnitFormat[] = { kInchUnits, kCMUnits, kPointUnits };
|
||||||
const static char *kUnitNames[] = { "Inch", "cm", "Points", NULL };
|
const static char *kUnitNames[] = { "Inch", "cm", "Points", NULL };
|
||||||
const static MarginUnit kUnitMsg[] = { kUnitInch,
|
const static MarginUnit kUnitMsg[] = { kUnitInch, kUnitCM, kUnitPoint };
|
||||||
kUnitCM,
|
|
||||||
kUnitPoint };
|
|
||||||
|
|
||||||
const pattern kDots = {{ 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55 }};
|
const pattern kDots = {{ 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55 }};
|
||||||
|
|
||||||
@@ -69,7 +71,6 @@ const rgb_color kRed = { 255,0,0,0 };
|
|||||||
const rgb_color kWhite = { 255,255,255,0 };
|
const rgb_color kWhite = { 255,255,255,0 };
|
||||||
const rgb_color kGray = { 220,220,220,0 };
|
const rgb_color kGray = { 220,220,220,0 };
|
||||||
|
|
||||||
/*----------------- MarginView Public Methods --------------------*/
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
@@ -81,38 +82,51 @@ const rgb_color kGray = { 220,220,220,0 };
|
|||||||
* @param units, unit32 enum for units used in view
|
* @param units, unit32 enum for units used in view
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
MarginView::MarginView(BRect frame,
|
MarginView::MarginView(BRect frame, int32 pageWidth, int32 pageHeight,
|
||||||
int32 pageWidth,
|
BRect margins, MarginUnit units)
|
||||||
int32 pageHeight,
|
: BBox(frame, NULL, B_FOLLOW_ALL)
|
||||||
BRect margins,
|
|
||||||
MarginUnit units)
|
|
||||||
|
|
||||||
:BBox(frame, NULL, B_FOLLOW_ALL)
|
|
||||||
{
|
{
|
||||||
fMarginUnit = units;
|
fMarginUnit = units;
|
||||||
fUnitValue = kUnitFormat[units];
|
fUnitValue = kUnitFormat[units];
|
||||||
|
|
||||||
SetLabel("Margins");
|
SetLabel("Margins");
|
||||||
|
|
||||||
fMaxPageHeight = frame.Height() - kMinUnitHeight - kOffsetY;
|
fMaxPageHeight = frame.Height() - kMinUnitHeight - kOffsetY;
|
||||||
fMaxPageWidth = frame.Width() - kMinFieldWidth - kOffsetX;
|
fMaxPageWidth = frame.Width() - kMinFieldWidth - kOffsetX;
|
||||||
|
|
||||||
fMargins = margins;
|
fMargins = margins;
|
||||||
|
|
||||||
fPageWidth = pageWidth;
|
fPageWidth = pageWidth;
|
||||||
fPageHeight = pageHeight;
|
fPageHeight = pageHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Destructor
|
* Destructor
|
||||||
*
|
*
|
||||||
* @param none
|
* @param none
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
MarginView::~MarginView() {
|
MarginView::~MarginView()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* AttachToWindow
|
||||||
|
*
|
||||||
|
* @param none
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
MarginView::AttachedToWindow()
|
||||||
|
{
|
||||||
|
if (Parent())
|
||||||
|
SetViewColor(Parent()->ViewColor());
|
||||||
|
|
||||||
|
_ConstructGUI();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*----------------- MarginView Public BeOS Hook Methods --------------------*/
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Draw
|
* Draw
|
||||||
@@ -120,7 +134,7 @@ MarginView::~MarginView() {
|
|||||||
* @param BRect, the draw bounds
|
* @param BRect, the draw bounds
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
MarginView::Draw(BRect rect)
|
MarginView::Draw(BRect rect)
|
||||||
{
|
{
|
||||||
BBox::Draw(rect);
|
BBox::Draw(rect);
|
||||||
@@ -135,7 +149,7 @@ MarginView::Draw(BRect rect)
|
|||||||
} else { // landscape
|
} else { // landscape
|
||||||
y_offset = (fMaxPageHeight/2 + kOffsetY) - fViewHeight/2;
|
y_offset = (fMaxPageHeight/2 + kOffsetY) - fViewHeight/2;
|
||||||
}
|
}
|
||||||
|
|
||||||
// draw the page
|
// draw the page
|
||||||
SetHighColor(kWhite);
|
SetHighColor(kWhite);
|
||||||
r = BRect(0, 0, fViewWidth, fViewHeight);
|
r = BRect(0, 0, fViewWidth, fViewHeight);
|
||||||
@@ -157,7 +171,7 @@ MarginView::Draw(BRect rect)
|
|||||||
SetHighColor(kBlack);
|
SetHighColor(kBlack);
|
||||||
SetLowColor(kGray);
|
SetLowColor(kGray);
|
||||||
char str[kStringSize];
|
char str[kStringSize];
|
||||||
sprintf(str, "%2.1f x %2.1f", fPageWidth/fUnitValue, fPageHeight/fUnitValue);
|
sprintf(str, "%2.1f x %2.1f", fPageWidth/fUnitValue, fPageHeight/fUnitValue);
|
||||||
SetFontSize(10);
|
SetFontSize(10);
|
||||||
DrawString((const char *)str, BPoint(x_offset, fMaxPageHeight + 40));
|
DrawString((const char *)str, BPoint(x_offset, fMaxPageHeight + 40));
|
||||||
}
|
}
|
||||||
@@ -170,59 +184,91 @@ MarginView::Draw(BRect rect)
|
|||||||
* @param height the page
|
* @param height the page
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
MarginView::FrameResized(float width, float height)
|
MarginView::FrameResized(float width, float height)
|
||||||
{
|
{
|
||||||
fMaxPageHeight = height - kMinUnitHeight - kOffsetX;
|
fMaxPageHeight = height - kMinUnitHeight - kOffsetX;
|
||||||
fMaxPageWidth = width - kMinFieldWidth - kOffsetY;
|
fMaxPageWidth = width - kMinFieldWidth - kOffsetY;
|
||||||
|
|
||||||
CalculateViewSize(MARGIN_CHANGED);
|
_CalculateViewSize(MARGIN_CHANGED);
|
||||||
Invalidate();
|
Invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* AttachToWindow
|
* MesssageReceived()
|
||||||
*
|
*
|
||||||
* @param none
|
* Receive messages for the view
|
||||||
|
*
|
||||||
|
* @param BMessage* , the message being received
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
MarginView::AttachedToWindow()
|
MarginView::MessageReceived(BMessage *msg)
|
||||||
{
|
{
|
||||||
if (Parent()) {
|
switch (msg->what) {
|
||||||
SetViewColor(Parent()->ViewColor());
|
case CHANGE_PAGE_SIZE: {
|
||||||
|
float w;
|
||||||
|
float h;
|
||||||
|
msg->FindFloat("width", &w);
|
||||||
|
msg->FindFloat("height", &h);
|
||||||
|
SetPageSize(w, h);
|
||||||
|
UpdateView(MARGIN_CHANGED);
|
||||||
|
} break;
|
||||||
|
|
||||||
|
case FLIP_PAGE: {
|
||||||
|
BPoint p = PageSize();
|
||||||
|
SetPageSize(p.y, p.x);
|
||||||
|
UpdateView(MARGIN_CHANGED);
|
||||||
|
} break;
|
||||||
|
|
||||||
|
case MARGIN_CHANGED:
|
||||||
|
UpdateView(MARGIN_CHANGED);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case TOP_MARGIN_CHANGED:
|
||||||
|
UpdateView(TOP_MARGIN_CHANGED);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case LEFT_MARGIN_CHANGED:
|
||||||
|
UpdateView(LEFT_MARGIN_CHANGED);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case RIGHT_MARGIN_CHANGED:
|
||||||
|
UpdateView(RIGHT_MARGIN_CHANGED);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case BOTTOM_MARGIN_CHANGED:
|
||||||
|
UpdateView(BOTTOM_MARGIN_CHANGED);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case MARGIN_UNIT_CHANGED: {
|
||||||
|
int32 marginUnit;
|
||||||
|
if (msg->FindInt32("marginUnit", &marginUnit) == B_OK)
|
||||||
|
_SetMarginUnit((MarginUnit)marginUnit);
|
||||||
|
} break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
BView::MessageReceived(msg);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
ConstructGUI();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*----------------- MarginView Public Methods --------------------*/
|
/*----------------- MarginView Public Methods --------------------*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* GetUnits
|
* PageSize
|
||||||
*
|
*
|
||||||
* @param none
|
* @param none
|
||||||
* @return uint32 enum, units in inches, cm, points
|
* @return BPoint, contains actual point values of page in x, y of point
|
||||||
*/
|
*/
|
||||||
MarginUnit
|
BPoint
|
||||||
MarginView::GetMarginUnit(void) {
|
MarginView::PageSize() const
|
||||||
return fMarginUnit;
|
{
|
||||||
|
return BPoint(fPageWidth, fPageHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* UpdateView, recalculate and redraw the view
|
|
||||||
*
|
|
||||||
* @param msg is a message to the calculate size to tell which field caused
|
|
||||||
* the update to occur, or it is a general update.
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
MarginView::UpdateView(uint32 msg)
|
|
||||||
{
|
|
||||||
Window()->Lock();
|
|
||||||
CalculateViewSize(msg); // nur Preview in Margins BBox!
|
|
||||||
Invalidate();
|
|
||||||
Window()->Unlock();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SetPageSize
|
* SetPageSize
|
||||||
@@ -231,32 +277,22 @@ MarginView::UpdateView(uint32 msg)
|
|||||||
* @param pageHeight, float that is the unit value of the page height
|
* @param pageHeight, float that is the unit value of the page height
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
MarginView::SetPageSize(float pageWidth, float pageHeight)
|
MarginView::SetPageSize(float pageWidth, float pageHeight)
|
||||||
{
|
{
|
||||||
fPageWidth = pageWidth;
|
fPageWidth = pageWidth;
|
||||||
fPageHeight = pageHeight;
|
fPageHeight = pageHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* GetPageSize
|
|
||||||
*
|
|
||||||
* @param none
|
|
||||||
* @return BPoint, contains actual point values of page in x, y of point
|
|
||||||
*/
|
|
||||||
BPoint
|
|
||||||
MarginView::GetPageSize(void) {
|
|
||||||
return BPoint(fPageWidth, fPageHeight);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* GetMargin
|
* Margin
|
||||||
*
|
*
|
||||||
* @param none
|
* @param none
|
||||||
* @return rect, return margin values always in points
|
* @return rect, return margin values always in points
|
||||||
*/
|
*/
|
||||||
BRect
|
BRect
|
||||||
MarginView::GetMargin(void)
|
MarginView::Margin() const
|
||||||
{
|
{
|
||||||
BRect margin;
|
BRect margin;
|
||||||
|
|
||||||
@@ -267,8 +303,7 @@ MarginView::GetMargin(void)
|
|||||||
float fbottom = atof(fBottom->Text());
|
float fbottom = atof(fBottom->Text());
|
||||||
|
|
||||||
// convert to units to points
|
// convert to units to points
|
||||||
switch (fMarginUnit)
|
switch (fMarginUnit) {
|
||||||
{
|
|
||||||
case kUnitInch:
|
case kUnitInch:
|
||||||
// convert to points
|
// convert to points
|
||||||
ftop *= kInchUnits;
|
ftop *= kInchUnits;
|
||||||
@@ -286,81 +321,48 @@ MarginView::GetMargin(void)
|
|||||||
case kUnitPoint:
|
case kUnitPoint:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
margin.Set(fleft, ftop, fright, fbottom);
|
margin.Set(fleft, ftop, fright, fbottom);
|
||||||
|
|
||||||
return margin;
|
return margin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* MesssageReceived()
|
* Unit
|
||||||
*
|
*
|
||||||
* Receive messages for the view
|
* @param none
|
||||||
|
* @return uint32 enum, units in inches, cm, points
|
||||||
|
*/
|
||||||
|
MarginUnit
|
||||||
|
MarginView::Unit() const
|
||||||
|
{
|
||||||
|
return fMarginUnit;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* UpdateView, recalculate and redraw the view
|
||||||
*
|
*
|
||||||
* @param BMessage* , the message being received
|
* @param msg is a message to the calculate size to tell which field caused
|
||||||
|
* the update to occur, or it is a general update.
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
MarginView::MessageReceived(BMessage *msg)
|
MarginView::UpdateView(uint32 msg)
|
||||||
{
|
{
|
||||||
switch (msg->what)
|
Window()->Lock();
|
||||||
{
|
_CalculateViewSize(msg); // only Preview in Margins BBox!
|
||||||
case CHANGE_PAGE_SIZE: {
|
Invalidate();
|
||||||
float w;
|
Window()->Unlock();
|
||||||
float h;
|
|
||||||
msg->FindFloat("width", &w);
|
|
||||||
msg->FindFloat("height", &h);
|
|
||||||
SetPageSize(w, h);
|
|
||||||
UpdateView(MARGIN_CHANGED);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case FLIP_PAGE: {
|
|
||||||
BPoint p;
|
|
||||||
p = GetPageSize();
|
|
||||||
SetPageSize(p.y, p.x);
|
|
||||||
UpdateView(MARGIN_CHANGED);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case MARGIN_CHANGED:
|
|
||||||
UpdateView(MARGIN_CHANGED);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case TOP_MARGIN_CHANGED:
|
|
||||||
UpdateView(TOP_MARGIN_CHANGED);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case LEFT_MARGIN_CHANGED:
|
|
||||||
UpdateView(LEFT_MARGIN_CHANGED);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case RIGHT_MARGIN_CHANGED:
|
|
||||||
UpdateView(RIGHT_MARGIN_CHANGED);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case BOTTOM_MARGIN_CHANGED:
|
|
||||||
UpdateView(BOTTOM_MARGIN_CHANGED);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case MARGIN_UNIT_CHANGED:
|
|
||||||
{
|
|
||||||
int32 marginUnit;
|
|
||||||
if (msg->FindInt32("marginUnit", &marginUnit) == B_OK) {
|
|
||||||
SetMarginUnit((MarginUnit)marginUnit);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
BView::MessageReceived(msg);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*----------------- MarginView Private Methods --------------------*/
|
/*----------------- MarginView Private Methods --------------------*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ConstructGUI()
|
* _ConstructGUI()
|
||||||
*
|
*
|
||||||
* Creates the GUI for the View. MUST be called AFTER the View is attached to
|
* Creates the GUI for the View. MUST be called AFTER the View is attached to
|
||||||
* the Window, or will crash and/or create strange behaviour
|
* the Window, or will crash and/or create strange behaviour
|
||||||
@@ -368,81 +370,75 @@ MarginView::MessageReceived(BMessage *msg)
|
|||||||
* @param none
|
* @param none
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
MarginView::ConstructGUI()
|
MarginView::_ConstructGUI()
|
||||||
{
|
{
|
||||||
BMessage *msg;
|
|
||||||
BString str;
|
BString str;
|
||||||
BMenuItem *item;
|
// Create text fields
|
||||||
BMenuField *mf;
|
BRect r(Frame().Width() - be_plain_font->StringWidth("Top#") - kWidth,
|
||||||
BPopUpMenu *menu;
|
|
||||||
|
|
||||||
// Create text fields
|
|
||||||
msg = new BMessage(MARGIN_CHANGED);
|
|
||||||
BRect r(Frame().Width() - be_plain_font->StringWidth("Top#") - kWidth,
|
|
||||||
kOffsetY, Frame().Width() - kOffsetX, kWidth);
|
kOffsetY, Frame().Width() - kOffsetX, kWidth);
|
||||||
|
|
||||||
// top
|
// top
|
||||||
str << fMargins.top/fUnitValue;
|
str << fMargins.top/fUnitValue;
|
||||||
fTop = new BTextControl( r, "top", "Top:", str.String(), NULL,
|
fTop = new BTextControl( r, "top", "Top:", str.String(), NULL,
|
||||||
B_FOLLOW_RIGHT);
|
B_FOLLOW_RIGHT);
|
||||||
|
|
||||||
fTop->SetModificationMessage(new BMessage(TOP_MARGIN_CHANGED));
|
fTop->SetModificationMessage(new BMessage(TOP_MARGIN_CHANGED));
|
||||||
fTop->SetDivider(be_plain_font->StringWidth("Top#"));
|
fTop->SetDivider(be_plain_font->StringWidth("Top#"));
|
||||||
fTop->SetTarget(this);
|
fTop->SetTarget(this);
|
||||||
AllowOnlyNumbers(fTop, kNumCount);
|
_AllowOnlyNumbers(fTop, kNumCount);
|
||||||
AddChild(fTop);
|
AddChild(fTop);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//left
|
//left
|
||||||
r.OffsetBy(0, kOffsetY);
|
r.OffsetBy(0, kOffsetY);
|
||||||
r.left = Frame().Width() - be_plain_font->StringWidth("Left#") - kWidth;
|
r.left = Frame().Width() - be_plain_font->StringWidth("Left#") - kWidth;
|
||||||
str = "";
|
str = "";
|
||||||
str << fMargins.left/fUnitValue;
|
str << fMargins.left/fUnitValue;
|
||||||
fLeft = new BTextControl( r, "left", "Left:", str.String(), NULL,
|
fLeft = new BTextControl( r, "left", "Left:", str.String(), NULL,
|
||||||
B_FOLLOW_RIGHT);
|
B_FOLLOW_RIGHT);
|
||||||
|
|
||||||
fLeft->SetModificationMessage(new BMessage(LEFT_MARGIN_CHANGED));
|
fLeft->SetModificationMessage(new BMessage(LEFT_MARGIN_CHANGED));
|
||||||
fLeft->SetDivider(be_plain_font->StringWidth("Left#"));
|
fLeft->SetDivider(be_plain_font->StringWidth("Left#"));
|
||||||
fLeft->SetTarget(this);
|
fLeft->SetTarget(this);
|
||||||
AllowOnlyNumbers(fLeft, kNumCount);
|
_AllowOnlyNumbers(fLeft, kNumCount);
|
||||||
AddChild(fLeft);
|
AddChild(fLeft);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//bottom
|
//bottom
|
||||||
r.OffsetBy(0, kOffsetY);
|
r.OffsetBy(0, kOffsetY);
|
||||||
r.left = Frame().Width() - be_plain_font->StringWidth("Bottom#") - kWidth;
|
r.left = Frame().Width() - be_plain_font->StringWidth("Bottom#") - kWidth;
|
||||||
str = "";
|
str = "";
|
||||||
str << fMargins.bottom/fUnitValue;
|
str << fMargins.bottom/fUnitValue;
|
||||||
fBottom = new BTextControl( r, "bottom", "Bottom:", str.String(), NULL,
|
fBottom = new BTextControl( r, "bottom", "Bottom:", str.String(), NULL,
|
||||||
B_FOLLOW_RIGHT);
|
B_FOLLOW_RIGHT);
|
||||||
|
|
||||||
fBottom->SetModificationMessage(new BMessage(BOTTOM_MARGIN_CHANGED));
|
fBottom->SetModificationMessage(new BMessage(BOTTOM_MARGIN_CHANGED));
|
||||||
fBottom->SetDivider(be_plain_font->StringWidth("Bottom#"));
|
fBottom->SetDivider(be_plain_font->StringWidth("Bottom#"));
|
||||||
fBottom->SetTarget(this);
|
fBottom->SetTarget(this);
|
||||||
|
|
||||||
AllowOnlyNumbers(fBottom, kNumCount);
|
_AllowOnlyNumbers(fBottom, kNumCount);
|
||||||
AddChild(fBottom);
|
AddChild(fBottom);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//right
|
//right
|
||||||
r.OffsetBy(0, kOffsetY);
|
r.OffsetBy(0, kOffsetY);
|
||||||
r.left = Frame().Width() - be_plain_font->StringWidth("Right#") - kWidth;
|
r.left = Frame().Width() - be_plain_font->StringWidth("Right#") - kWidth;
|
||||||
str = "";
|
str = "";
|
||||||
str << fMargins.right/fUnitValue;
|
str << fMargins.right/fUnitValue;
|
||||||
fRight = new BTextControl( r, "right", "Right:", str.String(), NULL,
|
fRight = new BTextControl( r, "right", "Right:", str.String(), NULL,
|
||||||
B_FOLLOW_RIGHT);
|
B_FOLLOW_RIGHT);
|
||||||
|
|
||||||
fRight->SetModificationMessage(new BMessage(RIGHT_MARGIN_CHANGED));
|
fRight->SetModificationMessage(new BMessage(RIGHT_MARGIN_CHANGED));
|
||||||
fRight->SetDivider(be_plain_font->StringWidth("Right#"));
|
fRight->SetDivider(be_plain_font->StringWidth("Right#"));
|
||||||
fRight->SetTarget(this);
|
fRight->SetTarget(this);
|
||||||
AllowOnlyNumbers(fRight, kNumCount);
|
_AllowOnlyNumbers(fRight, kNumCount);
|
||||||
AddChild(fRight);
|
AddChild(fRight);
|
||||||
|
|
||||||
|
|
||||||
@@ -451,27 +447,26 @@ MarginView::ConstructGUI()
|
|||||||
r.OffsetBy(-kOffsetX, kOffsetY);
|
r.OffsetBy(-kOffsetX, kOffsetY);
|
||||||
r.right += kOffsetY;
|
r.right += kOffsetY;
|
||||||
|
|
||||||
menu = new BPopUpMenu("units");
|
BPopUpMenu *menu = new BPopUpMenu("units");
|
||||||
mf = new BMenuField(r, "units", "Units", menu,
|
BMenuField *mf = new BMenuField(r, "units", "Units", menu,
|
||||||
B_FOLLOW_BOTTOM|B_FOLLOW_RIGHT);
|
B_FOLLOW_BOTTOM | B_FOLLOW_RIGHT);
|
||||||
mf->ResizeToPreferred();
|
mf->ResizeToPreferred();
|
||||||
mf->SetDivider(be_plain_font->StringWidth("Units#"));
|
mf->SetDivider(be_plain_font->StringWidth("Units#"));
|
||||||
|
|
||||||
// Construct menu items
|
BMenuItem *item;
|
||||||
for (int i=0; kUnitNames[i] != NULL; i++ )
|
// Construct menu items
|
||||||
{
|
for (int32 i = 0; kUnitNames[i] != NULL; i++) {
|
||||||
msg = new BMessage(MARGIN_UNIT_CHANGED);
|
BMessage *msg = new BMessage(MARGIN_UNIT_CHANGED);
|
||||||
msg->AddInt32("marginUnit", kUnitMsg[i]);
|
msg->AddInt32("marginUnit", kUnitMsg[i]);
|
||||||
menu->AddItem(item = new BMenuItem(kUnitNames[i], msg));
|
menu->AddItem(item = new BMenuItem(kUnitNames[i], msg));
|
||||||
item->SetTarget(this);
|
item->SetTarget(this);
|
||||||
if (fMarginUnit == kUnitMsg[i]) {
|
if (fMarginUnit == kUnitMsg[i])
|
||||||
item->SetMarked(true);
|
item->SetMarked(true);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
AddChild(mf);
|
AddChild(mf);
|
||||||
|
|
||||||
// calculate the sizes for drawing page view
|
// calculate the sizes for drawing page view
|
||||||
CalculateViewSize(MARGIN_CHANGED);
|
_CalculateViewSize(MARGIN_CHANGED);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -482,17 +477,17 @@ MarginView::ConstructGUI()
|
|||||||
* @param maxNum, the maximun number of characters allowed
|
* @param maxNum, the maximun number of characters allowed
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
MarginView::AllowOnlyNumbers(BTextControl *textControl, int maxNum)
|
MarginView::_AllowOnlyNumbers(BTextControl *textControl, int32 maxNum)
|
||||||
{
|
{
|
||||||
BTextView *tv = textControl->TextView();
|
BTextView *tv = textControl->TextView();
|
||||||
|
|
||||||
for (long i = 0; i < 256; i++) {
|
for (int32 i = 0; i < 256; i++)
|
||||||
tv->DisallowChar(i);
|
tv->DisallowChar(i);
|
||||||
}
|
|
||||||
for (long i = '0'; i <= '9'; i++) {
|
for (int32 i = '0'; i <= '9'; i++)
|
||||||
tv->AllowChar(i);
|
tv->AllowChar(i);
|
||||||
}
|
|
||||||
tv->AllowChar(B_BACKSPACE);
|
tv->AllowChar(B_BACKSPACE);
|
||||||
tv->AllowChar('.');
|
tv->AllowChar('.');
|
||||||
tv->SetMaxBytes(maxNum);
|
tv->SetMaxBytes(maxNum);
|
||||||
@@ -504,25 +499,27 @@ MarginView::AllowOnlyNumbers(BTextControl *textControl, int maxNum)
|
|||||||
* @param brect, margin values in rect
|
* @param brect, margin values in rect
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
MarginView::SetMargin(BRect margin) {
|
MarginView::_SetMargin(BRect margin)
|
||||||
|
{
|
||||||
fMargins = margin;
|
fMargins = margin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SetUnits, called by the MarginMgr when the units popup is selected
|
* SetUnits, called by the MarginMgr when the units popup is selected
|
||||||
*
|
*
|
||||||
* @param uint32, the enum that identifies the units requested to change to.
|
* @param uint32, the enum that identifies the units requested to change to.
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
MarginView::SetMarginUnit(MarginUnit unit)
|
MarginView::_SetMarginUnit(MarginUnit unit)
|
||||||
{
|
{
|
||||||
// do nothing if the current units are the same as requested
|
// do nothing if the current units are the same as requested
|
||||||
if (unit == fMarginUnit) {
|
if (unit == fMarginUnit) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// set the units Format
|
// set the units Format
|
||||||
fUnitValue = kUnitFormat[unit];
|
fUnitValue = kUnitFormat[unit];
|
||||||
|
|
||||||
@@ -533,8 +530,8 @@ MarginView::SetMarginUnit(MarginUnit unit)
|
|||||||
float fbottom = atof(fBottom->Text());
|
float fbottom = atof(fBottom->Text());
|
||||||
|
|
||||||
// convert to target units
|
// convert to target units
|
||||||
switch (fMarginUnit)
|
switch (fMarginUnit)
|
||||||
{
|
{
|
||||||
case kUnitInch:
|
case kUnitInch:
|
||||||
// convert to points
|
// convert to points
|
||||||
ftop *= kInchUnits;
|
ftop *= kInchUnits;
|
||||||
@@ -581,49 +578,50 @@ MarginView::SetMarginUnit(MarginUnit unit)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
fMarginUnit = unit;
|
fMarginUnit = unit;
|
||||||
|
|
||||||
// lock Window since these changes are from another thread
|
// lock Window since these changes are from another thread
|
||||||
Window()->Lock();
|
Window()->Lock();
|
||||||
|
|
||||||
// set the fields to new units
|
// set the fields to new units
|
||||||
BString str;
|
BString str;
|
||||||
str << ftop;
|
str << ftop;
|
||||||
fTop->SetText(str.String());
|
fTop->SetText(str.String());
|
||||||
|
|
||||||
str = "";
|
str = "";
|
||||||
str << fleft;
|
str << fleft;
|
||||||
fLeft->SetText(str.String());
|
fLeft->SetText(str.String());
|
||||||
|
|
||||||
str = "";
|
str = "";
|
||||||
str << fright;
|
str << fright;
|
||||||
fRight->SetText(str.String());
|
fRight->SetText(str.String());
|
||||||
|
|
||||||
str = "";
|
str = "";
|
||||||
str << fbottom;
|
str << fbottom;
|
||||||
fBottom->SetText(str.String());
|
fBottom->SetText(str.String());
|
||||||
|
|
||||||
// update UI
|
// update UI
|
||||||
CalculateViewSize(MARGIN_CHANGED);
|
_CalculateViewSize(MARGIN_CHANGED);
|
||||||
Invalidate();
|
Invalidate();
|
||||||
|
|
||||||
Window()->Unlock();
|
Window()->Unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* CalculateViewSize
|
* CalculateViewSize
|
||||||
*
|
*
|
||||||
* calculate the size of the view that is used
|
* calculate the size of the view that is used
|
||||||
* to show the page inside the margin box. This is dependent
|
* to show the page inside the margin box. This is dependent
|
||||||
* on the size of the box and the room we have to show it and
|
* on the size of the box and the room we have to show it and
|
||||||
* the units that we are using and the orientation of the page.
|
* the units that we are using and the orientation of the page.
|
||||||
*
|
*
|
||||||
* @param msg, the message for which field changed to check value bounds
|
* @param msg, the message for which field changed to check value bounds
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
MarginView::CalculateViewSize(uint32 msg)
|
MarginView::_CalculateViewSize(uint32 msg)
|
||||||
{
|
{
|
||||||
// determine page orientation
|
// determine page orientation
|
||||||
if (fPageHeight < fPageWidth) { // LANDSCAPE
|
if (fPageHeight < fPageWidth) { // LANDSCAPE
|
||||||
fViewWidth = fMaxPageWidth;
|
fViewWidth = fMaxPageWidth;
|
||||||
fViewHeight = fPageHeight * (fViewWidth/fPageWidth);
|
fViewHeight = fPageHeight * (fViewWidth/fPageWidth);
|
||||||
@@ -643,11 +641,11 @@ MarginView::CalculateViewSize(uint32 msg)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// calculate margins based on view size
|
// calculate margins based on view size
|
||||||
|
|
||||||
// find the length of 1 pixel in points
|
// find the length of 1 pixel in points
|
||||||
// ex: 80px/800pt = 0.1px/pt
|
// ex: 80px/800pt = 0.1px/pt
|
||||||
float pixelLength = fViewHeight/fPageHeight;
|
float pixelLength = fViewHeight/fPageHeight;
|
||||||
|
|
||||||
// convert the margins to points
|
// convert the margins to points
|
||||||
// The text field will have a number that us in the current unit
|
// The text field will have a number that us in the current unit
|
||||||
// ex 0.2" * 72pt = 14.4pts
|
// ex 0.2" * 72pt = 14.4pts
|
||||||
@@ -657,66 +655,62 @@ MarginView::CalculateViewSize(uint32 msg)
|
|||||||
float fleft = atof(fLeft->Text()) * fUnitValue;
|
float fleft = atof(fLeft->Text()) * fUnitValue;
|
||||||
|
|
||||||
// Check that the margins don't overlap each other...
|
// Check that the margins don't overlap each other...
|
||||||
float delta = 72.0;
|
float delta = 72.0;
|
||||||
// minimum printable rect = 1 inch * 1 inch
|
// minimum printable rect = 1 inch * 1 inch
|
||||||
float ph = fPageHeight-delta;
|
float ph = fPageHeight-delta;
|
||||||
float pw = fPageWidth-delta;
|
float pw = fPageWidth-delta;
|
||||||
BString str;
|
BString str;
|
||||||
|
|
||||||
// Bounds calculation rules:
|
// Bounds calculation rules:
|
||||||
if (msg == TOP_MARGIN_CHANGED)
|
if (msg == TOP_MARGIN_CHANGED) {
|
||||||
{
|
|
||||||
// top must be <= bottom
|
// top must be <= bottom
|
||||||
if (ftop > (ph - fbottom)) {
|
if (ftop > (ph - fbottom)) {
|
||||||
ftop = ph - fbottom;
|
ftop = ph - fbottom;
|
||||||
str = "";
|
str = "";
|
||||||
str << ftop / fUnitValue;
|
str << ftop / fUnitValue;
|
||||||
Window()->Lock();
|
Window()->Lock();
|
||||||
fTop->SetText(str.String());
|
fTop->SetText(str.String());
|
||||||
Window()->Unlock();
|
Window()->Unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (msg == BOTTOM_MARGIN_CHANGED)
|
if (msg == BOTTOM_MARGIN_CHANGED) {
|
||||||
{
|
// bottom must be <= pageHeight
|
||||||
// bottom must be <= pageHeight
|
|
||||||
if (fbottom > (ph - ftop)) {
|
if (fbottom > (ph - ftop)) {
|
||||||
fbottom = ph - ftop;
|
fbottom = ph - ftop;
|
||||||
str = "";
|
str = "";
|
||||||
str << fbottom / fUnitValue;
|
str << fbottom / fUnitValue;
|
||||||
Window()->Lock();
|
Window()->Lock();
|
||||||
fBottom->SetText(str.String());
|
fBottom->SetText(str.String());
|
||||||
Window()->Unlock();
|
Window()->Unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (msg == LEFT_MARGIN_CHANGED)
|
if (msg == LEFT_MARGIN_CHANGED) {
|
||||||
{
|
// left must be <= right
|
||||||
// left must be <= right
|
|
||||||
if (fleft > (pw - fright)) {
|
if (fleft > (pw - fright)) {
|
||||||
fleft = pw - fright;
|
fleft = pw - fright;
|
||||||
str = "";
|
str = "";
|
||||||
str << fleft / fUnitValue;
|
str << fleft / fUnitValue;
|
||||||
Window()->Lock();
|
Window()->Lock();
|
||||||
fLeft->SetText(str.String());
|
fLeft->SetText(str.String());
|
||||||
Window()->Unlock();
|
Window()->Unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (msg == RIGHT_MARGIN_CHANGED)
|
if (msg == RIGHT_MARGIN_CHANGED) {
|
||||||
{
|
// right must be <= fPageWidth
|
||||||
// right must be <= fPageWidth
|
|
||||||
if (fright > (pw - fleft)) {
|
if (fright > (pw - fleft)) {
|
||||||
fright = pw - fleft;
|
fright = pw - fleft;
|
||||||
str = "";
|
str = "";
|
||||||
str << fright / fUnitValue;
|
str << fright / fUnitValue;
|
||||||
Window()->Lock();
|
Window()->Lock();
|
||||||
fRight->SetText(str.String());
|
fRight->SetText(str.String());
|
||||||
Window()->Unlock();
|
Window()->Unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// convert the unit value to pixels
|
// convert the unit value to pixels
|
||||||
// ex: 14.4pt * 0.1px/pt = 1.44px
|
// ex: 14.4pt * 0.1px/pt = 1.44px
|
||||||
fMargins.top = ftop * pixelLength;
|
fMargins.top = ftop * pixelLength;
|
||||||
@@ -724,5 +718,3 @@ MarginView::CalculateViewSize(uint32 msg)
|
|||||||
fMargins.bottom = fbottom * pixelLength;
|
fMargins.bottom = fbottom * pixelLength;
|
||||||
fMargins.left = fleft * pixelLength;
|
fMargins.left = fleft * pixelLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user