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